src/driver/Driver.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "Driver.h" | ||
| 4 | |||
| 5 | #include <exception/CliError.h> | ||
| 6 | #include <util/CommonUtil.h> | ||
| 7 | #include <util/CompilerWarning.h> | ||
| 8 | #include <util/SystemUtil.h> | ||
| 9 | |||
| 10 | #include <llvm/Support/CommandLine.h> | ||
| 11 | #include <llvm/TargetParser/Host.h> | ||
| 12 | #include <llvm/TargetParser/Triple.h> | ||
| 13 | |||
| 14 | namespace spice::compiler { | ||
| 15 | |||
| 16 |
3/6✓ Branch 4 → 5 taken 581 times.
✗ Branch 4 → 51 not taken.
✓ Branch 7 → 8 taken 581 times.
✗ Branch 7 → 45 not taken.
✓ Branch 8 → 9 taken 581 times.
✗ Branch 8 → 43 not taken.
|
2324 | Driver::Driver(CliOptions &foreignCliOptions, bool dryRun) : cliOptions(foreignCliOptions), performDryRun(dryRun) { |
| 17 | // Allow positional args | ||
| 18 | 581 | app.positionals_at_end(); | |
| 19 | 581 | app.allow_extras(false); | |
| 20 |
2/4✓ Branch 15 → 16 taken 581 times.
✗ Branch 15 → 57 not taken.
✓ Branch 17 → 18 taken 581 times.
✗ Branch 17 → 55 not taken.
|
581 | app.footer("(c) Marc Auberer 2021-" + std::to_string(CommonUtil::getCurrentYear())); |
| 21 | |||
| 22 | // Add version flag | ||
| 23 |
3/6✓ Branch 24 → 25 taken 581 times.
✗ Branch 24 → 67 not taken.
✓ Branch 27 → 28 taken 581 times.
✗ Branch 27 → 61 not taken.
✓ Branch 28 → 29 taken 581 times.
✗ Branch 28 → 59 not taken.
|
2324 | app.set_version_flag("--version,-v", CommonUtil::buildVersionInfo()); |
| 24 | |||
| 25 | // Create sub-commands | ||
| 26 |
1/2✓ Branch 34 → 35 taken 581 times.
✗ Branch 34 → 74 not taken.
|
581 | addBuildSubcommand(); |
| 27 |
1/2✓ Branch 35 → 36 taken 581 times.
✗ Branch 35 → 74 not taken.
|
581 | addRunSubcommand(); |
| 28 |
1/2✓ Branch 36 → 37 taken 581 times.
✗ Branch 36 → 74 not taken.
|
581 | addTestSubcommand(); |
| 29 |
1/2✓ Branch 37 → 38 taken 581 times.
✗ Branch 37 → 74 not taken.
|
581 | addInstallSubcommand(); |
| 30 |
1/2✓ Branch 38 → 39 taken 581 times.
✗ Branch 38 → 74 not taken.
|
581 | addUninstallSubcommand(); |
| 31 | |||
| 32 | 581 | app.final_callback([&] { | |
| 33 | // Print help text for the root command if no sub-command was given | ||
| 34 |
2/4✓ Branch 2 → 3 taken 576 times.
✗ Branch 2 → 124 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 15 taken 576 times.
|
576 | if (app.get_subcommands().empty()) { |
| 35 | ✗ | std::cout << app.help(); | |
| 36 | ✗ | return; | |
| 37 | } | ||
| 38 | |||
| 39 |
4/4✓ Branch 15 → 16 taken 575 times.
✓ Branch 15 → 17 taken 1 time.
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 52 taken 574 times.
|
576 | if (shouldInstall || shouldUninstall) { |
| 40 | // Prepare the installation path | ||
| 41 |
1/2✓ Branch 17 → 18 taken 2 times.
✗ Branch 17 → 152 not taken.
|
2 | std::filesystem::path installPath = SystemUtil::getSpiceBinDir(); |
| 42 |
2/4✓ Branch 18 → 19 taken 2 times.
✗ Branch 18 → 136 not taken.
✓ Branch 19 → 20 taken 2 times.
✗ Branch 19 → 134 not taken.
|
2 | installPath /= cliOptions.mainSourceFile.stem(); |
| 43 |
1/2✗ Branch 21 → 22 not taken.
✓ Branch 21 → 23 taken 2 times.
|
2 | if (!performDryRun) |
| 44 | ✗ | create_directories(installPath); | |
| 45 |
1/2✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 2 times.
|
2 | assert(cliOptions.outputContainer == OutputContainer::EXECUTABLE); |
| 46 |
3/6✓ Branch 25 → 26 taken 2 times.
✗ Branch 25 → 139 not taken.
✓ Branch 26 → 27 taken 2 times.
✗ Branch 26 → 139 not taken.
✓ Branch 27 → 28 taken 2 times.
✗ Branch 27 → 137 not taken.
|
2 | installPath.replace_extension(SystemUtil::getOutputFileExtension(cliOptions, OutputContainer::EXECUTABLE)); |
| 47 | |||
| 48 | // If the binary should be installed, set the output path to the Spice bin directory | ||
| 49 |
2/2✓ Branch 29 → 30 taken 1 time.
✓ Branch 29 → 31 taken 1 time.
|
2 | if (shouldInstall) |
| 50 |
1/2✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 150 not taken.
|
1 | cliOptions.outputPath = installPath; |
| 51 | |||
| 52 | // If the binary should be uninstalled, check if the executable exists and uninstall it | ||
| 53 |
3/4✓ Branch 31 → 32 taken 1 time.
✓ Branch 31 → 50 taken 1 time.
✗ Branch 32 → 33 not taken.
✓ Branch 32 → 50 taken 1 time.
|
2 | if (shouldUninstall && !performDryRun) { |
| 54 | ✗ | if (exists(installPath) && std::filesystem::remove(installPath)) | |
| 55 | ✗ | std::cout << "Successfully uninstalled.\n"; | |
| 56 | else | ||
| 57 | ✗ | CompilerWarning(UNINSTALL_FAILED, "The executable was not found at the expected location").print(); | |
| 58 | } | ||
| 59 | 2 | } | |
| 60 | |||
| 61 | // Abort here if we do not need to compile | ||
| 62 |
2/2✓ Branch 52 → 53 taken 1 time.
✓ Branch 52 → 54 taken 575 times.
|
576 | if (!shouldCompile) |
| 63 | 1 | return; | |
| 64 | |||
| 65 | // Set output path and dir | ||
| 66 |
2/2✓ Branch 54 → 55 taken 4 times.
✓ Branch 54 → 82 taken 571 times.
|
575 | if (shouldExecute) { |
| 67 | 4 | cliOptions.execute = true; | |
| 68 | const uint64_t millis = | ||
| 69 |
1/2✓ Branch 57 → 58 taken 4 times.
✗ Branch 57 → 153 not taken.
|
4 | duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); |
| 70 |
8/16✓ Branch 59 → 60 taken 4 times.
✗ Branch 59 → 175 not taken.
✓ Branch 60 → 61 taken 4 times.
✗ Branch 60 → 173 not taken.
✓ Branch 61 → 62 taken 4 times.
✗ Branch 61 → 169 not taken.
✓ Branch 62 → 63 taken 4 times.
✗ Branch 62 → 165 not taken.
✓ Branch 63 → 64 taken 4 times.
✗ Branch 63 → 162 not taken.
✓ Branch 64 → 65 taken 4 times.
✗ Branch 64 → 160 not taken.
✓ Branch 65 → 66 taken 4 times.
✗ Branch 65 → 158 not taken.
✓ Branch 66 → 67 taken 4 times.
✗ Branch 66 → 156 not taken.
|
4 | cliOptions.outputDir = std::filesystem::temp_directory_path() / "spice" / "output" / std::to_string(millis); |
| 71 |
2/4✓ Branch 76 → 77 taken 4 times.
✗ Branch 76 → 180 not taken.
✓ Branch 77 → 78 taken 4 times.
✗ Branch 77 → 178 not taken.
|
4 | cliOptions.outputPath = cliOptions.outputDir / cliOptions.mainSourceFile.filename(); |
| 72 |
2/2✓ Branch 83 → 84 taken 1 time.
✓ Branch 83 → 99 taken 570 times.
|
571 | } else if (!cliOptions.outputPath.empty()) { |
| 73 |
1/2✗ Branch 85 → 86 not taken.
✓ Branch 85 → 93 taken 1 time.
|
1 | if (is_directory(cliOptions.outputPath)) { |
| 74 | ✗ | cliOptions.outputDir = cliOptions.outputPath; | |
| 75 | ✗ | cliOptions.outputPath = cliOptions.outputDir / cliOptions.mainSourceFile.filename(); | |
| 76 |
1/2✓ Branch 94 → 95 taken 1 time.
✗ Branch 94 → 106 not taken.
|
1 | } else if (cliOptions.outputPath.has_parent_path()) { |
| 77 |
1/2✓ Branch 95 → 96 taken 1 time.
✗ Branch 95 → 186 not taken.
|
1 | cliOptions.outputDir = cliOptions.outputPath.parent_path(); |
| 78 | } | ||
| 79 | } else { | ||
| 80 | 570 | cliOptions.outputDir = "./"; | |
| 81 |
2/4✓ Branch 100 → 101 taken 570 times.
✗ Branch 100 → 189 not taken.
✓ Branch 101 → 102 taken 570 times.
✗ Branch 101 → 187 not taken.
|
570 | cliOptions.outputPath = cliOptions.outputDir / cliOptions.mainSourceFile.filename(); |
| 82 | } | ||
| 83 | |||
| 84 | // Set output file extension | ||
| 85 |
3/6✓ Branch 106 → 107 taken 575 times.
✗ Branch 106 → 193 not taken.
✓ Branch 107 → 108 taken 575 times.
✗ Branch 107 → 193 not taken.
✓ Branch 108 → 109 taken 575 times.
✗ Branch 108 → 191 not taken.
|
575 | cliOptions.outputPath.replace_extension(SystemUtil::getOutputFileExtension(cliOptions, cliOptions.outputContainer)); |
| 86 | |||
| 87 | // Set cache dir | ||
| 88 |
5/10✓ Branch 110 → 111 taken 575 times.
✗ Branch 110 → 206 not taken.
✓ Branch 111 → 112 taken 575 times.
✗ Branch 111 → 202 not taken.
✓ Branch 112 → 113 taken 575 times.
✗ Branch 112 → 199 not taken.
✓ Branch 113 → 114 taken 575 times.
✗ Branch 113 → 197 not taken.
✓ Branch 114 → 115 taken 575 times.
✗ Branch 114 → 195 not taken.
|
575 | cliOptions.cacheDir = std::filesystem::temp_directory_path() / "spice" / "cache"; |
| 89 | |||
| 90 | // Create directories in case they not exist yet | ||
| 91 | 575 | create_directories(cliOptions.cacheDir); | |
| 92 | 575 | create_directories(cliOptions.outputDir); | |
| 93 | }); | ||
| 94 | 581 | } | |
| 95 | |||
| 96 | /** | ||
| 97 | * Start the parsing process | ||
| 98 | * | ||
| 99 | * @param argc Argument count | ||
| 100 | * @param argv Argument vector | ||
| 101 | * @return Return code | ||
| 102 | */ | ||
| 103 | 581 | int Driver::parse(int argc, const char *argv[]) { | |
| 104 | try { | ||
| 105 |
2/2✓ Branch 2 → 3 taken 576 times.
✓ Branch 2 → 5 taken 1 time.
|
581 | app.parse(argc, argv); |
| 106 | 576 | return EXIT_SUCCESS; | |
| 107 |
1/2✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 1 time.
|
1 | } catch (const CLI::ParseError &parseError) { |
| 108 |
1/2✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 11 not taken.
|
1 | return app.exit(parseError); |
| 109 | 1 | } | |
| 110 | } | ||
| 111 | |||
| 112 | /** | ||
| 113 | * Initialize the cli options based on the input of the user | ||
| 114 | */ | ||
| 115 | 577 | void Driver::enrich() const { | |
| 116 | // Make path of given main source file canonical and relative | ||
| 117 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 9 taken 577 times.
|
577 | if (!performDryRun) |
| 118 | ✗ | cliOptions.mainSourceFile = relative(cliOptions.mainSourceFile); | |
| 119 | |||
| 120 | // Propagate llvm args to llvm | ||
| 121 |
1/2✗ Branch 10 → 11 not taken.
✓ Branch 10 → 39 taken 577 times.
|
577 | if (!cliOptions.llvmArgs.empty()) { |
| 122 | ✗ | const std::vector<std::string> result = CommonUtil::split("llvm " + cliOptions.llvmArgs); | |
| 123 | ✗ | std::vector<const char *> resultCStr; | |
| 124 | ✗ | resultCStr.reserve(result.size()); | |
| 125 | ✗ | for (const std::string &str : result) | |
| 126 | ✗ | resultCStr.push_back(str.c_str()); | |
| 127 | ✗ | llvm::cl::ParseCommandLineOptions(static_cast<int>(result.size()), resultCStr.data()); | |
| 128 | ✗ | } | |
| 129 | |||
| 130 | // Propagate target information | ||
| 131 |
3/6✓ Branch 39 → 40 taken 577 times.
✗ Branch 39 → 222 not taken.
✓ Branch 41 → 42 taken 577 times.
✗ Branch 41 → 220 not taken.
✓ Branch 42 → 43 taken 577 times.
✗ Branch 42 → 218 not taken.
|
577 | const llvm::Triple defaultTriple(llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple())); |
| 132 |
2/2✓ Branch 46 → 47 taken 570 times.
✓ Branch 46 → 65 taken 7 times.
|
577 | if (cliOptions.targetTriple.empty()) { |
| 133 |
2/4✓ Branch 47 → 48 taken 570 times.
✗ Branch 47 → 328 not taken.
✓ Branch 48 → 49 taken 570 times.
✗ Branch 48 → 57 not taken.
|
570 | if (cliOptions.targetArch == TARGET_UNKNOWN) { // We have nothing -> obtain native triplet |
| 134 |
1/2✓ Branch 49 → 50 taken 570 times.
✗ Branch 49 → 328 not taken.
|
570 | cliOptions.targetTriple = defaultTriple; |
| 135 |
2/4✓ Branch 50 → 51 taken 570 times.
✗ Branch 50 → 225 not taken.
✓ Branch 51 → 52 taken 570 times.
✗ Branch 51 → 225 not taken.
|
570 | cliOptions.targetArch = defaultTriple.getArchName(); |
| 136 |
2/4✓ Branch 52 → 53 taken 570 times.
✗ Branch 52 → 226 not taken.
✓ Branch 53 → 54 taken 570 times.
✗ Branch 53 → 226 not taken.
|
570 | cliOptions.targetVendor = defaultTriple.getVendorName(); |
| 137 |
2/4✓ Branch 54 → 55 taken 570 times.
✗ Branch 54 → 227 not taken.
✓ Branch 55 → 56 taken 570 times.
✗ Branch 55 → 227 not taken.
|
570 | cliOptions.targetOs = defaultTriple.getOSName(); |
| 138 | 570 | cliOptions.isNativeTarget = true; | |
| 139 | } else { // We have arch, vendor and os -> obtain triplet | ||
| 140 | ✗ | cliOptions.targetTriple = llvm::Triple(cliOptions.targetArch, cliOptions.targetVendor, cliOptions.targetOs); | |
| 141 | ✗ | cliOptions.isNativeTarget = cliOptions.targetTriple == defaultTriple; | |
| 142 | } | ||
| 143 | } else { // Obtain arch, vendor and os by the triplet | ||
| 144 |
2/4✓ Branch 65 → 66 taken 7 times.
✗ Branch 65 → 234 not taken.
✓ Branch 66 → 67 taken 7 times.
✗ Branch 66 → 232 not taken.
|
7 | const llvm::Triple triple(cliOptions.targetTriple.normalize()); |
| 145 |
2/4✓ Branch 68 → 69 taken 7 times.
✗ Branch 68 → 235 not taken.
✓ Branch 69 → 70 taken 7 times.
✗ Branch 69 → 235 not taken.
|
7 | cliOptions.targetArch = triple.getArchName(); |
| 146 |
2/4✓ Branch 70 → 71 taken 7 times.
✗ Branch 70 → 236 not taken.
✓ Branch 71 → 72 taken 7 times.
✗ Branch 71 → 236 not taken.
|
7 | cliOptions.targetVendor = triple.getVendorName(); |
| 147 |
2/4✓ Branch 72 → 73 taken 7 times.
✗ Branch 72 → 237 not taken.
✓ Branch 73 → 74 taken 7 times.
✗ Branch 73 → 237 not taken.
|
7 | cliOptions.targetOs = triple.getOSName(); |
| 148 | 7 | cliOptions.isNativeTarget = triple == defaultTriple; | |
| 149 | 7 | } | |
| 150 | |||
| 151 | // Always preserve IR value names when dumping IR | ||
| 152 |
2/2✓ Branch 77 → 78 taken 1 time.
✓ Branch 77 → 79 taken 576 times.
|
577 | if (cliOptions.dump.dumpIR) |
| 153 | 1 | cliOptions.namesForIRValues = true; | |
| 154 | |||
| 155 | // Enable test mode when test mode was selected | ||
| 156 |
2/2✓ Branch 79 → 80 taken 2 times.
✓ Branch 79 → 81 taken 575 times.
|
577 | if (cliOptions.buildMode == BuildMode::TEST) { |
| 157 | 2 | cliOptions.noEntryFct = true; | |
| 158 | 2 | cliOptions.generateTestMain = true; | |
| 159 | } | ||
| 160 | |||
| 161 | 577 | const Sanitizer sanitizer = cliOptions.instrumentation.sanitizer; | |
| 162 | // Memory sanitizer is only supported on Linux | ||
| 163 |
4/6✓ Branch 82 → 83 taken 4 times.
✓ Branch 82 → 85 taken 573 times.
✗ Branch 83 → 84 not taken.
✓ Branch 83 → 85 taken 4 times.
✗ Branch 86 → 87 not taken.
✓ Branch 86 → 95 taken 577 times.
|
577 | if (!cliOptions.targetTriple.isOSLinux() && sanitizer == Sanitizer::MEMORY) |
| 164 | ✗ | throw CliError(FEATURE_NOT_SUPPORTED_FOR_TARGET, "Memory sanitizer is only supported for Linux targets"); | |
| 165 | // Some sanitizers need lifetime markers to work properly | ||
| 166 |
4/4✓ Branch 95 → 96 taken 574 times.
✓ Branch 95 → 97 taken 3 times.
✓ Branch 96 → 97 taken 3 times.
✓ Branch 96 → 98 taken 571 times.
|
577 | if (sanitizer == Sanitizer::ADDRESS || sanitizer == Sanitizer::MEMORY) |
| 167 | 6 | cliOptions.useLifetimeMarkers = true; | |
| 168 | // Type sanitizer needs TBAA metadata to work properly | ||
| 169 |
2/2✓ Branch 98 → 99 taken 2 times.
✓ Branch 98 → 100 taken 575 times.
|
577 | if (sanitizer == Sanitizer::TYPE) |
| 170 | 2 | cliOptions.useTBAAMetadata = true; | |
| 171 | |||
| 172 | // Infer build vars from other options | ||
| 173 |
2/2✓ Branch 2 → 3 taken 1149 times.
✓ Branch 2 → 4 taken 1736 times.
|
2885 | const auto boolToString = [](bool input) { return input ? "true" : "false"; }; |
| 174 |
3/6✓ Branch 103 → 104 taken 577 times.
✗ Branch 103 → 252 not taken.
✓ Branch 104 → 105 taken 577 times.
✗ Branch 104 → 250 not taken.
✓ Branch 105 → 106 taken 577 times.
✗ Branch 105 → 250 not taken.
|
1154 | cliOptions.buildVars["spice.is_debug"] = boolToString(cliOptions.buildMode == BuildMode::DEBUG); |
| 175 |
3/6✓ Branch 111 → 112 taken 577 times.
✗ Branch 111 → 258 not taken.
✓ Branch 112 → 113 taken 577 times.
✗ Branch 112 → 256 not taken.
✓ Branch 113 → 114 taken 577 times.
✗ Branch 113 → 256 not taken.
|
1154 | cliOptions.buildVars["spice.is_release"] = boolToString(cliOptions.buildMode == BuildMode::RELEASE); |
| 176 |
3/6✓ Branch 119 → 120 taken 577 times.
✗ Branch 119 → 264 not taken.
✓ Branch 120 → 121 taken 577 times.
✗ Branch 120 → 262 not taken.
✓ Branch 121 → 122 taken 577 times.
✗ Branch 121 → 262 not taken.
|
1154 | cliOptions.buildVars["spice.is_test"] = boolToString(cliOptions.buildMode == BuildMode::TEST); |
| 177 |
3/6✓ Branch 127 → 128 taken 577 times.
✗ Branch 127 → 270 not taken.
✓ Branch 128 → 129 taken 577 times.
✗ Branch 128 → 268 not taken.
✓ Branch 129 → 130 taken 577 times.
✗ Branch 129 → 268 not taken.
|
1154 | cliOptions.buildVars["spice.link_static"] = boolToString(cliOptions.staticLinking); |
| 178 |
3/6✓ Branch 135 → 136 taken 577 times.
✗ Branch 135 → 276 not taken.
✓ Branch 136 → 137 taken 577 times.
✗ Branch 136 → 274 not taken.
✓ Branch 137 → 138 taken 577 times.
✗ Branch 137 → 274 not taken.
|
1154 | cliOptions.buildVars["spice.is_native_target"] = boolToString(cliOptions.isNativeTarget); |
| 179 |
3/6✓ Branch 143 → 144 taken 577 times.
✗ Branch 143 → 282 not taken.
✓ Branch 144 → 145 taken 577 times.
✗ Branch 144 → 280 not taken.
✓ Branch 145 → 146 taken 577 times.
✗ Branch 145 → 280 not taken.
|
1154 | cliOptions.buildVars["spice.target_triple"] = cliOptions.targetTriple.str(); |
| 180 |
5/8✓ Branch 148 → 149 taken 4 times.
✓ Branch 148 → 150 taken 573 times.
✓ Branch 153 → 154 taken 577 times.
✗ Branch 153 → 288 not taken.
✓ Branch 154 → 155 taken 577 times.
✗ Branch 154 → 286 not taken.
✓ Branch 155 → 156 taken 577 times.
✗ Branch 155 → 286 not taken.
|
1154 | cliOptions.buildVars["spice.backend"] = cliOptions.backend == Backend::TPDE ? BACKEND_TPDE : BACKEND_LLVM; |
| 181 | |||
| 182 | // Prevent incompatible option combinations | ||
| 183 |
3/4✓ Branch 158 → 159 taken 1 time.
✓ Branch 158 → 168 taken 576 times.
✓ Branch 159 → 160 taken 1 time.
✗ Branch 159 → 168 not taken.
|
577 | if (cliOptions.staticLinking && cliOptions.outputContainer == OutputContainer::SHARED_LIBRARY) |
| 184 |
2/4✓ Branch 163 → 164 taken 1 time.
✗ Branch 163 → 295 not taken.
✓ Branch 164 → 165 taken 1 time.
✗ Branch 164 → 292 not taken.
|
3 | throw CliError(INCOMPATIBLE_OPTIONS, "Cannot link statically if compiling shared library"); |
| 185 | |||
| 186 | // Guards for the experimental TPDE backend — ELF only, x86_64/aarch64 only, no LTO | ||
| 187 |
2/2✓ Branch 168 → 169 taken 4 times.
✓ Branch 168 → 201 taken 572 times.
|
576 | if (cliOptions.backend == Backend::TPDE) { |
| 188 |
2/2✓ Branch 169 → 170 taken 1 time.
✓ Branch 169 → 178 taken 3 times.
|
4 | if (cliOptions.useLTO) |
| 189 |
2/4✓ Branch 173 → 174 taken 1 time.
✗ Branch 173 → 304 not taken.
✓ Branch 174 → 175 taken 1 time.
✗ Branch 174 → 301 not taken.
|
3 | throw CliError(INCOMPATIBLE_OPTIONS, "The TPDE backend does not support LTO"); |
| 190 |
2/2✓ Branch 179 → 180 taken 1 time.
✓ Branch 179 → 188 taken 2 times.
|
3 | if (!cliOptions.targetTriple.isOSLinux()) |
| 191 |
2/4✓ Branch 183 → 184 taken 1 time.
✗ Branch 183 → 313 not taken.
✓ Branch 184 → 185 taken 1 time.
✗ Branch 184 → 310 not taken.
|
3 | throw CliError(FEATURE_NOT_SUPPORTED_FOR_TARGET, "The TPDE backend only supports ELF targets (Linux)"); |
| 192 | 2 | const llvm::Triple::ArchType arch = cliOptions.targetTriple.getArch(); | |
| 193 |
3/4✓ Branch 189 → 190 taken 1 time.
✓ Branch 189 → 199 taken 1 time.
✓ Branch 190 → 191 taken 1 time.
✗ Branch 190 → 199 not taken.
|
2 | if (arch != llvm::Triple::x86_64 && arch != llvm::Triple::aarch64) |
| 194 |
2/4✓ Branch 194 → 195 taken 1 time.
✗ Branch 194 → 322 not taken.
✓ Branch 195 → 196 taken 1 time.
✗ Branch 195 → 319 not taken.
|
3 | throw CliError(FEATURE_NOT_SUPPORTED_FOR_TARGET, "The TPDE backend only supports x86_64 and aarch64"); |
| 195 |
1/2✗ Branch 199 → 200 not taken.
✓ Branch 199 → 201 taken 1 time.
|
1 | if (cliOptions.optLevel != OptLevel::O0) |
| 196 | ✗ | std::cout << "\033[33mWarning: the TPDE backend does not optimize; -O flag will be ignored\033[0m\n"; | |
| 197 | } | ||
| 198 | 577 | } | |
| 199 | |||
| 200 | /** | ||
| 201 | * Executes the built executable | ||
| 202 | */ | ||
| 203 | ✗ | void Driver::runBinary() const { | |
| 204 | // Print status message | ||
| 205 | ✗ | if (cliOptions.printDebugOutput) | |
| 206 | ✗ | std::cout << "Running executable ...\n\n"; | |
| 207 | |||
| 208 | // Run executable, inheriting our standard streams so its output goes straight to the terminal | ||
| 209 | ✗ | std::filesystem::path executablePath = cliOptions.outputPath; | |
| 210 | ✗ | executablePath.make_preferred(); | |
| 211 | ✗ | const int exitCode = SystemUtil::run(executablePath.string()); | |
| 212 | ✗ | if (exitCode != EXIT_SUCCESS) | |
| 213 | ✗ | throw CliError(NON_ZERO_EXIT_CODE, "Your Spice executable exited with non-zero exit code " + std::to_string(exitCode)); | |
| 214 | ✗ | } | |
| 215 | |||
| 216 | /** | ||
| 217 | * Add build subcommand to cli interface | ||
| 218 | */ | ||
| 219 | 581 | void Driver::addBuildSubcommand() { | |
| 220 | // Create sub-command itself | ||
| 221 |
3/6✓ Branch 4 → 5 taken 581 times.
✗ Branch 4 → 160 not taken.
✓ Branch 7 → 8 taken 581 times.
✗ Branch 7 → 154 not taken.
✓ Branch 8 → 9 taken 581 times.
✗ Branch 8 → 152 not taken.
|
2324 | CLI::App *subCmd = app.add_subcommand("build", "Builds your Spice program and emits an executable"); |
| 222 |
2/4✓ Branch 15 → 16 taken 581 times.
✗ Branch 15 → 166 not taken.
✓ Branch 16 → 17 taken 581 times.
✗ Branch 16 → 164 not taken.
|
1162 | subCmd->alias("b"); |
| 223 | 581 | subCmd->allow_non_standard_option_names(); | |
| 224 | 581 | subCmd->configurable(); | |
| 225 | 581 | subCmd->callback([&] { | |
| 226 | 570 | shouldCompile = true; | |
| 227 | 570 | }); | |
| 228 | |||
| 229 |
1/2✓ Branch 24 → 25 taken 581 times.
✗ Branch 24 → 308 not taken.
|
581 | addCompileSubcommandOptions(subCmd); |
| 230 |
1/2✓ Branch 25 → 26 taken 581 times.
✗ Branch 25 → 308 not taken.
|
581 | addInstrumentationOptions(subCmd); |
| 231 | |||
| 232 | 588 | const auto outputContainerCallback = [&](const CLI::results_t &results) { | |
| 233 |
1/2✓ Branch 3 → 4 taken 7 times.
✗ Branch 3 → 29 not taken.
|
7 | std::string inputString = results.front(); |
| 234 |
1/2✓ Branch 5 → 6 taken 7 times.
✗ Branch 5 → 27 not taken.
|
7 | std::ranges::transform(inputString, inputString.begin(), tolower); |
| 235 | |||
| 236 |
3/4✓ Branch 6 → 7 taken 7 times.
✗ Branch 6 → 27 not taken.
✓ Branch 7 → 8 taken 2 times.
✓ Branch 7 → 9 taken 5 times.
|
7 | if (inputString == OUTPUT_CONTAINER_EXECUTABLE) |
| 237 | 2 | cliOptions.outputContainer = OutputContainer::EXECUTABLE; | |
| 238 |
3/4✓ Branch 9 → 10 taken 5 times.
✗ Branch 9 → 27 not taken.
✓ Branch 10 → 11 taken 1 time.
✓ Branch 10 → 12 taken 4 times.
|
5 | else if (inputString == OUTPUT_CONTAINER_OBJECT_FILE) |
| 239 | 1 | cliOptions.outputContainer = OutputContainer::OBJECT_FILE; | |
| 240 |
3/4✓ Branch 12 → 13 taken 4 times.
✗ Branch 12 → 27 not taken.
✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 15 taken 3 times.
|
4 | else if (inputString == OUTPUT_CONTAINER_STATIC_LIBRARY) |
| 241 | 1 | cliOptions.outputContainer = OutputContainer::STATIC_LIBRARY; | |
| 242 |
3/4✓ Branch 15 → 16 taken 3 times.
✗ Branch 15 → 27 not taken.
✓ Branch 16 → 17 taken 2 times.
✓ Branch 16 → 18 taken 1 time.
|
3 | else if (inputString == OUTPUT_CONTAINER_SHARED_LIBRARY) |
| 243 | 2 | cliOptions.outputContainer = OutputContainer::SHARED_LIBRARY; | |
| 244 | else | ||
| 245 |
1/2✓ Branch 19 → 20 taken 1 time.
✗ Branch 19 → 24 not taken.
|
1 | throw CliError(INVALID_OUTPUT_CONTAINER, inputString); |
| 246 | |||
| 247 | 6 | return true; | |
| 248 | 7 | }; | |
| 249 | |||
| 250 | // --output-container | ||
| 251 |
2/4✓ Branch 33 → 34 taken 581 times.
✗ Branch 33 → 172 not taken.
✓ Branch 34 → 35 taken 581 times.
✗ Branch 34 → 170 not taken.
|
2324 | subCmd->add_option("--output-container", outputContainerCallback, |
| 252 |
1/2✓ Branch 29 → 30 taken 581 times.
✗ Branch 29 → 181 not taken.
|
1743 | "Format of the compilation output container: exec (default), obj, lib, dylib)"); |
| 253 | // --target-triple | ||
| 254 |
2/4✓ Branch 46 → 47 taken 581 times.
✗ Branch 46 → 190 not taken.
✓ Branch 47 → 48 taken 581 times.
✗ Branch 47 → 188 not taken.
|
1743 | subCmd->add_option<llvm::Triple>("--target,--target-triple,-t", cliOptions.targetTriple, |
| 255 |
1/2✓ Branch 43 → 44 taken 581 times.
✗ Branch 43 → 196 not taken.
|
1162 | "Target triple for the emitted executable (for cross-compiling)"); |
| 256 | // --target-arch | ||
| 257 |
2/4✓ Branch 57 → 58 taken 581 times.
✗ Branch 57 → 202 not taken.
✓ Branch 58 → 59 taken 581 times.
✗ Branch 58 → 200 not taken.
|
1743 | subCmd->add_option<std::string>("--target-arch", cliOptions.targetArch, |
| 258 |
1/2✓ Branch 54 → 55 taken 581 times.
✗ Branch 54 → 208 not taken.
|
1162 | "Target arch for emitted executable (for cross-compiling)"); |
| 259 | // --target-vendor | ||
| 260 |
2/4✓ Branch 68 → 69 taken 581 times.
✗ Branch 68 → 214 not taken.
✓ Branch 69 → 70 taken 581 times.
✗ Branch 69 → 212 not taken.
|
1743 | subCmd->add_option<std::string>("--target-vendor", cliOptions.targetVendor, |
| 261 |
1/2✓ Branch 65 → 66 taken 581 times.
✗ Branch 65 → 220 not taken.
|
1162 | "Target vendor for emitted executable (for cross-compiling)"); |
| 262 | // --target-os | ||
| 263 |
3/6✓ Branch 76 → 77 taken 581 times.
✗ Branch 76 → 232 not taken.
✓ Branch 79 → 80 taken 581 times.
✗ Branch 79 → 226 not taken.
✓ Branch 80 → 81 taken 581 times.
✗ Branch 80 → 224 not taken.
|
2324 | subCmd->add_option<std::string>("--target-os", cliOptions.targetOs, "Target os for emitted executable (for cross-compiling)"); |
| 264 | // --output | ||
| 265 |
3/6✓ Branch 87 → 88 taken 581 times.
✗ Branch 87 → 244 not taken.
✓ Branch 90 → 91 taken 581 times.
✗ Branch 90 → 238 not taken.
✓ Branch 91 → 92 taken 581 times.
✗ Branch 91 → 236 not taken.
|
2324 | subCmd->add_option<std::filesystem::path>("--output,-o", cliOptions.outputPath, "Set the output file path"); |
| 266 | // --disable-verifier | ||
| 267 |
3/6✓ Branch 98 → 99 taken 581 times.
✗ Branch 98 → 256 not taken.
✓ Branch 101 → 102 taken 581 times.
✗ Branch 101 → 250 not taken.
✓ Branch 102 → 103 taken 581 times.
✗ Branch 102 → 248 not taken.
|
2324 | subCmd->add_flag<bool>("--disable-verifier", cliOptions.disableVerifier, "Disable LLVM module and function verification"); |
| 268 | // --no-entry | ||
| 269 |
3/6✓ Branch 109 → 110 taken 581 times.
✗ Branch 109 → 268 not taken.
✓ Branch 112 → 113 taken 581 times.
✗ Branch 112 → 262 not taken.
✓ Branch 113 → 114 taken 581 times.
✗ Branch 113 → 260 not taken.
|
2324 | subCmd->add_flag<bool>("--no-entry", cliOptions.noEntryFct, "Do not generate main function"); |
| 270 | // --static | ||
| 271 |
3/6✓ Branch 120 → 121 taken 581 times.
✗ Branch 120 → 280 not taken.
✓ Branch 123 → 124 taken 581 times.
✗ Branch 123 → 274 not taken.
✓ Branch 124 → 125 taken 581 times.
✗ Branch 124 → 272 not taken.
|
2324 | subCmd->add_flag<bool>("--static", cliOptions.staticLinking, "Link statically"); |
| 272 | // --dump-to-files | ||
| 273 |
3/6✓ Branch 131 → 132 taken 581 times.
✗ Branch 131 → 292 not taken.
✓ Branch 134 → 135 taken 581 times.
✗ Branch 134 → 286 not taken.
✓ Branch 135 → 136 taken 581 times.
✗ Branch 135 → 284 not taken.
|
2324 | subCmd->add_flag<bool>("--dump-to-files", cliOptions.dump.dumpToFiles, "Redirect dumps to files instead of printing"); |
| 274 | // --abort-after-dump | ||
| 275 |
2/4✓ Branch 145 → 146 taken 581 times.
✗ Branch 145 → 298 not taken.
✓ Branch 146 → 147 taken 581 times.
✗ Branch 146 → 296 not taken.
|
1743 | subCmd->add_flag<bool>("--abort-after-dump", cliOptions.dump.abortAfterDump, |
| 276 |
1/2✓ Branch 142 → 143 taken 581 times.
✗ Branch 142 → 304 not taken.
|
1162 | "Abort the compilation process after dumping the first requested resource"); |
| 277 | 581 | } | |
| 278 | |||
| 279 | /** | ||
| 280 | * Add run subcommand to cli interface | ||
| 281 | */ | ||
| 282 | 581 | void Driver::addRunSubcommand() { | |
| 283 | // Create sub-command itself | ||
| 284 |
3/6✓ Branch 4 → 5 taken 581 times.
✗ Branch 4 → 45 not taken.
✓ Branch 7 → 8 taken 581 times.
✗ Branch 7 → 39 not taken.
✓ Branch 8 → 9 taken 581 times.
✗ Branch 8 → 37 not taken.
|
2324 | CLI::App *subCmd = app.add_subcommand("run", "Builds your Spice program and runs it immediately"); |
| 285 |
2/4✓ Branch 15 → 16 taken 581 times.
✗ Branch 15 → 51 not taken.
✓ Branch 16 → 17 taken 581 times.
✗ Branch 16 → 49 not taken.
|
1162 | subCmd->alias("r"); |
| 286 | 581 | subCmd->allow_non_standard_option_names(); | |
| 287 | 581 | subCmd->callback([&] { | |
| 288 | 2 | shouldCompile = shouldExecute = true; | |
| 289 | 2 | }); | |
| 290 | |||
| 291 | 581 | addCompileSubcommandOptions(subCmd); | |
| 292 | 581 | addInstrumentationOptions(subCmd); | |
| 293 | |||
| 294 | // --disable-verifier | ||
| 295 |
3/6✓ Branch 27 → 28 taken 581 times.
✗ Branch 27 → 63 not taken.
✓ Branch 30 → 31 taken 581 times.
✗ Branch 30 → 57 not taken.
✓ Branch 31 → 32 taken 581 times.
✗ Branch 31 → 55 not taken.
|
2324 | subCmd->add_flag<bool>("--disable-verifier", cliOptions.disableVerifier, "Disable LLVM module and function verification"); |
| 296 | 581 | } | |
| 297 | |||
| 298 | /** | ||
| 299 | * Add test subcommand to cli interface | ||
| 300 | */ | ||
| 301 | 581 | void Driver::addTestSubcommand() { | |
| 302 | // Create sub-command itself | ||
| 303 |
3/6✓ Branch 4 → 5 taken 581 times.
✗ Branch 4 → 45 not taken.
✓ Branch 7 → 8 taken 581 times.
✗ Branch 7 → 39 not taken.
✓ Branch 8 → 9 taken 581 times.
✗ Branch 8 → 37 not taken.
|
2324 | CLI::App *subCmd = app.add_subcommand("test", "Builds your Spice program and runs all enclosed tests"); |
| 304 |
2/4✓ Branch 15 → 16 taken 581 times.
✗ Branch 15 → 51 not taken.
✓ Branch 16 → 17 taken 581 times.
✗ Branch 16 → 49 not taken.
|
1162 | subCmd->alias("t"); |
| 305 | 581 | subCmd->allow_non_standard_option_names(); | |
| 306 | 581 | subCmd->callback([&] { | |
| 307 | 2 | shouldCompile = shouldExecute = true; | |
| 308 | 2 | cliOptions.buildMode = BuildMode::TEST; | |
| 309 | 2 | cliOptions.generateTestMain = true; // An alternative entry function is generated | |
| 310 | 2 | cliOptions.noEntryFct = true; // To not have two main functions, disable normal main | |
| 311 | 2 | }); | |
| 312 | |||
| 313 | 581 | addCompileSubcommandOptions(subCmd); | |
| 314 | 581 | addInstrumentationOptions(subCmd); | |
| 315 | |||
| 316 | // --disable-verifier | ||
| 317 |
3/6✓ Branch 27 → 28 taken 581 times.
✗ Branch 27 → 63 not taken.
✓ Branch 30 → 31 taken 581 times.
✗ Branch 30 → 57 not taken.
✓ Branch 31 → 32 taken 581 times.
✗ Branch 31 → 55 not taken.
|
2324 | subCmd->add_flag<bool>("--disable-verifier", cliOptions.disableVerifier, "Disable LLVM module and function verification"); |
| 318 | 581 | } | |
| 319 | |||
| 320 | /** | ||
| 321 | * Add install subcommand to cli interface | ||
| 322 | */ | ||
| 323 | 581 | void Driver::addInstallSubcommand() { | |
| 324 | // Create sub-command itself | ||
| 325 |
3/6✓ Branch 4 → 5 taken 581 times.
✗ Branch 4 → 33 not taken.
✓ Branch 7 → 8 taken 581 times.
✗ Branch 7 → 27 not taken.
✓ Branch 8 → 9 taken 581 times.
✗ Branch 8 → 25 not taken.
|
2324 | CLI::App *subCmd = app.add_subcommand("install", "Builds your Spice program and installs it to a directory in the PATH"); |
| 326 |
2/4✓ Branch 15 → 16 taken 581 times.
✗ Branch 15 → 39 not taken.
✓ Branch 16 → 17 taken 581 times.
✗ Branch 16 → 37 not taken.
|
1162 | subCmd->alias("i"); |
| 327 | 581 | subCmd->allow_non_standard_option_names(); | |
| 328 | 581 | subCmd->callback([&] { | |
| 329 | 1 | shouldCompile = true; | |
| 330 | 1 | shouldInstall = true; | |
| 331 | 1 | ensureNotDockerized(); | |
| 332 | 1 | }); | |
| 333 | |||
| 334 | 581 | addCompileSubcommandOptions(subCmd); | |
| 335 | 581 | } | |
| 336 | |||
| 337 | /** | ||
| 338 | * Add uninstall subcommand to cli interface | ||
| 339 | */ | ||
| 340 | 581 | void Driver::addUninstallSubcommand() { | |
| 341 | // Create sub-command itself | ||
| 342 |
3/6✓ Branch 4 → 5 taken 581 times.
✗ Branch 4 → 52 not taken.
✓ Branch 7 → 8 taken 581 times.
✗ Branch 7 → 46 not taken.
✓ Branch 8 → 9 taken 581 times.
✗ Branch 8 → 44 not taken.
|
2324 | CLI::App *subCmd = app.add_subcommand("uninstall", "Uninstalls a Spice program from the system"); |
| 343 |
2/4✓ Branch 15 → 16 taken 581 times.
✗ Branch 15 → 58 not taken.
✓ Branch 16 → 17 taken 581 times.
✗ Branch 16 → 56 not taken.
|
1162 | subCmd->alias("u"); |
| 344 | 581 | subCmd->allow_non_standard_option_names(); | |
| 345 | 581 | subCmd->callback([&] { | |
| 346 | 1 | shouldUninstall = true; | |
| 347 | 1 | ensureNotDockerized(); | |
| 348 | 1 | }); | |
| 349 | |||
| 350 | // Source file | ||
| 351 |
2/4✓ Branch 25 → 26 taken 581 times.
✗ Branch 25 → 79 not taken.
✓ Branch 28 → 29 taken 581 times.
✗ Branch 28 → 73 not taken.
|
2324 | subCmd->add_option<std::filesystem::path>("<main-source-file>", cliOptions.mainSourceFile, "Main source file") |
| 352 |
3/6✓ Branch 29 → 30 taken 581 times.
✗ Branch 29 → 71 not taken.
✓ Branch 33 → 34 taken 581 times.
✗ Branch 33 → 64 not taken.
✓ Branch 34 → 35 taken 581 times.
✗ Branch 34 → 62 not taken.
|
2324 | ->check(CLI::ExistingFile) |
| 353 | 581 | ->required(); | |
| 354 | 581 | } | |
| 355 | |||
| 356 | 2324 | void Driver::addCompileSubcommandOptions(CLI::App *subCmd) const { | |
| 357 | 2328 | const auto buildModeCallback = [&](const CLI::results_t &results) { | |
| 358 |
1/2✓ Branch 3 → 4 taken 4 times.
✗ Branch 3 → 26 not taken.
|
4 | std::string inputString = results.front(); |
| 359 |
1/2✓ Branch 5 → 6 taken 4 times.
✗ Branch 5 → 24 not taken.
|
4 | std::ranges::transform(inputString, inputString.begin(), tolower); |
| 360 | |||
| 361 |
2/4✓ Branch 6 → 7 taken 4 times.
✗ Branch 6 → 24 not taken.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 4 times.
|
4 | if (inputString == BUILD_MODE_DEBUG) |
| 362 | ✗ | cliOptions.buildMode = BuildMode::DEBUG; | |
| 363 |
3/4✓ Branch 9 → 10 taken 4 times.
✗ Branch 9 → 24 not taken.
✓ Branch 10 → 11 taken 3 times.
✓ Branch 10 → 12 taken 1 time.
|
4 | else if (inputString == BUILD_MODE_RELEASE) |
| 364 | 3 | cliOptions.buildMode = BuildMode::RELEASE; | |
| 365 |
2/4✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 24 not taken.
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 1 time.
|
1 | else if (inputString == BUILD_MODE_TEST) |
| 366 | ✗ | cliOptions.buildMode = BuildMode::TEST; | |
| 367 | else | ||
| 368 |
1/2✓ Branch 16 → 17 taken 1 time.
✗ Branch 16 → 21 not taken.
|
1 | throw CliError(INVALID_BUILD_MODE, inputString); |
| 369 | |||
| 370 | 3 | return true; | |
| 371 | 4 | }; | |
| 372 | 2327 | const auto buildVarCallback = [&](const std::vector<std::string> &inputs) { | |
| 373 |
2/2✓ Branch 29 → 4 taken 17 times.
✓ Branch 29 → 30 taken 3 times.
|
23 | for (const std::string &input : inputs) { |
| 374 | // Skip empty inputs | ||
| 375 |
1/2✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 17 times.
|
17 | if (input.empty()) |
| 376 | ✗ | continue; | |
| 377 | |||
| 378 | // Parse structure: "key=value". If no value given, save "true" as value. | ||
| 379 | 17 | const size_t splitPos = input.find_first_of('='); | |
| 380 |
2/2✓ Branch 10 → 11 taken 12 times.
✓ Branch 10 → 18 taken 5 times.
|
17 | if (splitPos != std::string::npos) { |
| 381 |
1/2✓ Branch 11 → 12 taken 12 times.
✗ Branch 11 → 36 not taken.
|
12 | const std::string key = input.substr(0, splitPos); |
| 382 |
1/2✓ Branch 12 → 13 taken 12 times.
✗ Branch 12 → 34 not taken.
|
12 | const std::string value = input.substr(splitPos + 1); |
| 383 |
2/4✓ Branch 13 → 14 taken 12 times.
✗ Branch 13 → 32 not taken.
✓ Branch 14 → 15 taken 12 times.
✗ Branch 14 → 32 not taken.
|
12 | cliOptions.buildVars[key] = value; |
| 384 | 12 | } else { | |
| 385 |
2/4✓ Branch 18 → 19 taken 5 times.
✗ Branch 18 → 37 not taken.
✓ Branch 19 → 20 taken 5 times.
✗ Branch 19 → 37 not taken.
|
5 | cliOptions.buildVars[input] = "true"; |
| 386 | } | ||
| 387 | } | ||
| 388 | 3 | return true; | |
| 389 | 2324 | }; | |
| 390 | |||
| 391 | // --build-mode | ||
| 392 |
3/6✓ Branch 5 → 6 taken 2324 times.
✗ Branch 5 → 333 not taken.
✓ Branch 9 → 10 taken 2324 times.
✗ Branch 9 → 324 not taken.
✓ Branch 10 → 11 taken 2324 times.
✗ Branch 10 → 322 not taken.
|
11620 | subCmd->add_option("--build-mode,-m", buildModeCallback, "Build mode: debug (default), release, test"); |
| 393 | // --llvm-args | ||
| 394 |
3/6✓ Branch 19 → 20 taken 2324 times.
✗ Branch 19 → 348 not taken.
✓ Branch 22 → 23 taken 2324 times.
✗ Branch 22 → 342 not taken.
✓ Branch 23 → 24 taken 2324 times.
✗ Branch 23 → 340 not taken.
|
9296 | subCmd->add_option<std::string>("--llvm-args,-llvm", cliOptions.llvmArgs, "Additional arguments for LLVM")->join(' '); |
| 395 | // --jobs | ||
| 396 |
3/6✓ Branch 31 → 32 taken 2324 times.
✗ Branch 31 → 360 not taken.
✓ Branch 34 → 35 taken 2324 times.
✗ Branch 34 → 354 not taken.
✓ Branch 35 → 36 taken 2324 times.
✗ Branch 35 → 352 not taken.
|
9296 | subCmd->add_option<unsigned short>("--jobs,-j", cliOptions.compileJobCount, "Compile jobs (threads), used for compilation"); |
| 397 | // --build-var | ||
| 398 |
1/2✓ Branch 47 → 48 taken 2324 times.
✗ Branch 47 → 364 not taken.
|
4648 | CLI::Option *buildVarOption = subCmd->add_option_function<std::vector<std::string>>( |
| 399 |
2/4✓ Branch 42 → 43 taken 2324 times.
✗ Branch 42 → 375 not taken.
✓ Branch 46 → 47 taken 2324 times.
✗ Branch 46 → 366 not taken.
|
9296 | "--build-var,-b", buildVarCallback, "Add build variable to parametrize the compiled program (e.g. -v key=value)"); |
| 400 | 2324 | buildVarOption->multi_option_policy(CLI::MultiOptionPolicy::TakeAll); | |
| 401 | // --ignore-cache | ||
| 402 |
3/6✓ Branch 56 → 57 taken 2324 times.
✗ Branch 56 → 387 not taken.
✓ Branch 59 → 60 taken 2324 times.
✗ Branch 59 → 381 not taken.
✓ Branch 60 → 61 taken 2324 times.
✗ Branch 60 → 379 not taken.
|
9296 | subCmd->add_flag<bool>("--ignore-cache", cliOptions.ignoreCache, "Force re-compilation of all source files"); |
| 403 | // --use-lifetime-markers | ||
| 404 |
2/4✓ Branch 70 → 71 taken 2324 times.
✗ Branch 70 → 393 not taken.
✓ Branch 71 → 72 taken 2324 times.
✗ Branch 71 → 391 not taken.
|
6972 | subCmd->add_flag<bool>("--use-lifetime-markers", cliOptions.useLifetimeMarkers, |
| 405 |
1/2✓ Branch 67 → 68 taken 2324 times.
✗ Branch 67 → 399 not taken.
|
4648 | "Generate lifetime markers to enhance optimizations"); |
| 406 | // --use-tbaa-metadata | ||
| 407 |
2/4✓ Branch 81 → 82 taken 2324 times.
✗ Branch 81 → 405 not taken.
✓ Branch 82 → 83 taken 2324 times.
✗ Branch 82 → 403 not taken.
|
6972 | subCmd->add_flag<bool>("--use-tbaa-metadata", cliOptions.useTBAAMetadata, |
| 408 |
1/2✓ Branch 78 → 79 taken 2324 times.
✗ Branch 78 → 411 not taken.
|
4648 | "Generate metadata for type-based alias analysis to enhance optimizations"); |
| 409 | |||
| 410 | // Opt levels | ||
| 411 |
3/6✓ Branch 89 → 90 taken 2324 times.
✗ Branch 89 → 427 not taken.
✓ Branch 93 → 94 taken 2324 times.
✗ Branch 93 → 417 not taken.
✓ Branch 94 → 95 taken 2324 times.
✗ Branch 94 → 415 not taken.
|
9296 | subCmd->add_flag_callback("-O0", [&] { cliOptions.optLevel = OptLevel::O0; }, "Disable optimization."); |
| 412 |
3/6✓ Branch 102 → 103 taken 2324 times.
✗ Branch 102 → 443 not taken.
✓ Branch 106 → 107 taken 2324 times.
✗ Branch 106 → 433 not taken.
✓ Branch 107 → 108 taken 2324 times.
✗ Branch 107 → 431 not taken.
|
9296 | subCmd->add_flag_callback("-O1", [&] { cliOptions.optLevel = OptLevel::O1; }, "Only basic optimization is applied."); |
| 413 |
3/6✓ Branch 115 → 116 taken 2324 times.
✗ Branch 115 → 459 not taken.
✓ Branch 119 → 120 taken 2324 times.
✗ Branch 119 → 449 not taken.
✓ Branch 120 → 121 taken 2324 times.
✗ Branch 120 → 447 not taken.
|
9296 | subCmd->add_flag_callback("-O2", [&] { cliOptions.optLevel = OptLevel::O2; }, "More advanced optimization is applied."); |
| 414 |
3/6✓ Branch 128 → 129 taken 2324 times.
✗ Branch 128 → 475 not taken.
✓ Branch 132 → 133 taken 2324 times.
✗ Branch 132 → 465 not taken.
✓ Branch 133 → 134 taken 2324 times.
✗ Branch 133 → 463 not taken.
|
9296 | subCmd->add_flag_callback("-O3", [&] { cliOptions.optLevel = OptLevel::O3; }, "Aggressive optimization for best performance."); |
| 415 |
3/6✓ Branch 141 → 142 taken 2324 times.
✗ Branch 141 → 491 not taken.
✓ Branch 145 → 146 taken 2324 times.
✗ Branch 145 → 481 not taken.
✓ Branch 146 → 147 taken 2324 times.
✗ Branch 146 → 479 not taken.
|
9296 | subCmd->add_flag_callback("-Os", [&] { cliOptions.optLevel = OptLevel::Os; }, "Size optimization for output executable."); |
| 416 |
3/6✓ Branch 154 → 155 taken 2324 times.
✗ Branch 154 → 507 not taken.
✓ Branch 158 → 159 taken 2324 times.
✗ Branch 158 → 497 not taken.
✓ Branch 159 → 160 taken 2324 times.
✗ Branch 159 → 495 not taken.
|
9296 | subCmd->add_flag_callback("-Oz", [&] { cliOptions.optLevel = OptLevel::Oz; }, "Aggressive optimization for best size."); |
| 417 |
3/6✓ Branch 167 → 168 taken 2324 times.
✗ Branch 167 → 519 not taken.
✓ Branch 170 → 171 taken 2324 times.
✗ Branch 170 → 513 not taken.
✓ Branch 171 → 172 taken 2324 times.
✗ Branch 171 → 511 not taken.
|
9296 | subCmd->add_flag<bool>("-lto", cliOptions.useLTO, "Enable link time optimization (LTO)"); |
| 418 | |||
| 419 | // --backend | ||
| 420 | 2330 | const auto backendCallback = [&](const CLI::results_t &results) { | |
| 421 |
1/2✓ Branch 3 → 4 taken 6 times.
✗ Branch 3 → 23 not taken.
|
6 | std::string inputString = results.front(); |
| 422 |
1/2✓ Branch 5 → 6 taken 6 times.
✗ Branch 5 → 21 not taken.
|
6 | std::ranges::transform(inputString, inputString.begin(), tolower); |
| 423 | |||
| 424 |
3/4✓ Branch 6 → 7 taken 6 times.
✗ Branch 6 → 21 not taken.
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 9 taken 5 times.
|
6 | if (inputString == BACKEND_LLVM) { |
| 425 | 1 | cliOptions.backend = Backend::LLVM; | |
| 426 |
3/4✓ Branch 9 → 10 taken 5 times.
✗ Branch 9 → 21 not taken.
✓ Branch 10 → 11 taken 4 times.
✓ Branch 10 → 12 taken 1 time.
|
5 | } else if (inputString == BACKEND_TPDE) { |
| 427 | #ifdef SPICE_ENABLE_TPDE | ||
| 428 | 4 | cliOptions.backend = Backend::TPDE; | |
| 429 | #else | ||
| 430 | throw CliError(FEATURE_NOT_SUPPORTED_FOR_TARGET, | ||
| 431 | "The TPDE backend is not available in this build. Rebuild the compiler with " | ||
| 432 | "-DSPICE_ENABLE_TPDE=ON."); | ||
| 433 | #endif | ||
| 434 | } else { | ||
| 435 |
1/2✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 18 not taken.
|
1 | throw CliError(INVALID_BACKEND, inputString); |
| 436 | } | ||
| 437 | |||
| 438 | 5 | return true; | |
| 439 | 6 | }; | |
| 440 |
2/4✓ Branch 183 → 184 taken 2324 times.
✗ Branch 183 → 525 not taken.
✓ Branch 184 → 185 taken 2324 times.
✗ Branch 184 → 523 not taken.
|
9296 | subCmd->add_option("--backend", backendCallback, |
| 441 |
1/2✓ Branch 179 → 180 taken 2324 times.
✗ Branch 179 → 534 not taken.
|
6972 | "Codegen backend: llvm (default), tpde (experimental — fast, unoptimized; requires opt-in build)"); |
| 442 | |||
| 443 | // --debug-output | ||
| 444 |
3/6✓ Branch 193 → 194 taken 2324 times.
✗ Branch 193 → 549 not taken.
✓ Branch 196 → 197 taken 2324 times.
✗ Branch 196 → 543 not taken.
✓ Branch 197 → 198 taken 2324 times.
✗ Branch 197 → 541 not taken.
|
9296 | subCmd->add_flag<bool>("--debug-output,-d", cliOptions.printDebugOutput, "Enable debug output"); |
| 445 | // --dump-cst | ||
| 446 |
3/6✓ Branch 204 → 205 taken 2324 times.
✗ Branch 204 → 561 not taken.
✓ Branch 207 → 208 taken 2324 times.
✗ Branch 207 → 555 not taken.
✓ Branch 208 → 209 taken 2324 times.
✗ Branch 208 → 553 not taken.
|
9296 | subCmd->add_flag<bool>("--dump-cst,-cst", cliOptions.dump.dumpCST, "Dump CST as serialized string and SVG image"); |
| 447 | // --dump-ast | ||
| 448 |
3/6✓ Branch 215 → 216 taken 2324 times.
✗ Branch 215 → 573 not taken.
✓ Branch 218 → 219 taken 2324 times.
✗ Branch 218 → 567 not taken.
✓ Branch 219 → 220 taken 2324 times.
✗ Branch 219 → 565 not taken.
|
9296 | subCmd->add_flag<bool>("--dump-ast,-ast", cliOptions.dump.dumpAST, "Dump AST as serialized string and SVG image"); |
| 449 | // --dump-symtab | ||
| 450 |
3/6✓ Branch 226 → 227 taken 2324 times.
✗ Branch 226 → 585 not taken.
✓ Branch 229 → 230 taken 2324 times.
✗ Branch 229 → 579 not taken.
✓ Branch 230 → 231 taken 2324 times.
✗ Branch 230 → 577 not taken.
|
9296 | subCmd->add_flag<bool>("--dump-symtab", cliOptions.dump.dumpSymbolTable, "Dump serialized symbol tables"); |
| 451 | // --dump-types | ||
| 452 |
3/6✓ Branch 237 → 238 taken 2324 times.
✗ Branch 237 → 597 not taken.
✓ Branch 240 → 241 taken 2324 times.
✗ Branch 240 → 591 not taken.
✓ Branch 241 → 242 taken 2324 times.
✗ Branch 241 → 589 not taken.
|
9296 | subCmd->add_flag<bool>("--dump-types", cliOptions.dump.dumpTypes, "Dump all used types"); |
| 453 | // --dump-cache-stats | ||
| 454 |
3/6✓ Branch 248 → 249 taken 2324 times.
✗ Branch 248 → 609 not taken.
✓ Branch 251 → 252 taken 2324 times.
✗ Branch 251 → 603 not taken.
✓ Branch 252 → 253 taken 2324 times.
✗ Branch 252 → 601 not taken.
|
9296 | subCmd->add_flag<bool>("--dump-cache-stats", cliOptions.dump.dumpCacheStats, "Dump stats for compiler-internal lookup caches"); |
| 455 | // --dump-ir | ||
| 456 |
3/6✓ Branch 259 → 260 taken 2324 times.
✗ Branch 259 → 621 not taken.
✓ Branch 262 → 263 taken 2324 times.
✗ Branch 262 → 615 not taken.
✓ Branch 263 → 264 taken 2324 times.
✗ Branch 263 → 613 not taken.
|
9296 | subCmd->add_flag<bool>("--dump-ir,-ir", cliOptions.dump.dumpIR, "Dump LLVM-IR"); |
| 457 | // --dump-assembly | ||
| 458 |
3/6✓ Branch 270 → 271 taken 2324 times.
✗ Branch 270 → 633 not taken.
✓ Branch 273 → 274 taken 2324 times.
✗ Branch 273 → 627 not taken.
✓ Branch 274 → 275 taken 2324 times.
✗ Branch 274 → 625 not taken.
|
9296 | subCmd->add_flag<bool>("--dump-assembly,-asm,-s", cliOptions.dump.dumpAssembly, "Dump Assembly code"); |
| 459 | // --dump-object-file | ||
| 460 |
3/6✓ Branch 281 → 282 taken 2324 times.
✗ Branch 281 → 645 not taken.
✓ Branch 284 → 285 taken 2324 times.
✗ Branch 284 → 639 not taken.
✓ Branch 285 → 286 taken 2324 times.
✗ Branch 285 → 637 not taken.
|
9296 | subCmd->add_flag<bool>("--dump-object-file", cliOptions.dump.dumpObjectFiles, "Dump object files"); |
| 461 | // --dump-dependency-graph | ||
| 462 |
3/6✓ Branch 292 → 293 taken 2324 times.
✗ Branch 292 → 657 not taken.
✓ Branch 295 → 296 taken 2324 times.
✗ Branch 295 → 651 not taken.
✓ Branch 296 → 297 taken 2324 times.
✗ Branch 296 → 649 not taken.
|
9296 | subCmd->add_flag<bool>("--dump-dependency-graph", cliOptions.dump.dumpDependencyGraph, "Dump compile unit dependency graph"); |
| 463 | |||
| 464 | // Source file | ||
| 465 |
2/4✓ Branch 303 → 304 taken 2324 times.
✗ Branch 303 → 678 not taken.
✓ Branch 306 → 307 taken 2324 times.
✗ Branch 306 → 672 not taken.
|
9296 | subCmd->add_option<std::filesystem::path>("<main-source-file>", cliOptions.mainSourceFile, "Main source file") |
| 466 |
3/6✓ Branch 307 → 308 taken 2324 times.
✗ Branch 307 → 670 not taken.
✓ Branch 311 → 312 taken 2324 times.
✗ Branch 311 → 663 not taken.
✓ Branch 312 → 313 taken 2324 times.
✗ Branch 312 → 661 not taken.
|
9296 | ->check(CLI::ExistingFile) |
| 467 | 2324 | ->required(); | |
| 468 | 2324 | } | |
| 469 | |||
| 470 | 1743 | void Driver::addInstrumentationOptions(CLI::App *subCmd) const { | |
| 471 | 1755 | const auto sanitizerCallback = [&](const CLI::results_t &results) { | |
| 472 |
1/2✓ Branch 3 → 4 taken 12 times.
✗ Branch 3 → 32 not taken.
|
12 | std::string inputString = results.front(); |
| 473 |
1/2✓ Branch 5 → 6 taken 12 times.
✗ Branch 5 → 30 not taken.
|
12 | std::ranges::transform(inputString, inputString.begin(), tolower); |
| 474 | |||
| 475 |
2/4✓ Branch 6 → 7 taken 12 times.
✗ Branch 6 → 30 not taken.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 12 times.
|
12 | if (inputString == SANITIZER_NONE) |
| 476 | ✗ | cliOptions.instrumentation.sanitizer = Sanitizer::NONE; | |
| 477 |
3/4✓ Branch 9 → 10 taken 12 times.
✗ Branch 9 → 30 not taken.
✓ Branch 10 → 11 taken 3 times.
✓ Branch 10 → 12 taken 9 times.
|
12 | else if (inputString == SANITIZER_ADDRESS) |
| 478 | 3 | cliOptions.instrumentation.sanitizer = Sanitizer::ADDRESS; | |
| 479 |
3/4✓ Branch 12 → 13 taken 9 times.
✗ Branch 12 → 30 not taken.
✓ Branch 13 → 14 taken 3 times.
✓ Branch 13 → 15 taken 6 times.
|
9 | else if (inputString == SANITIZER_THREAD) |
| 480 | 3 | cliOptions.instrumentation.sanitizer = Sanitizer::THREAD; | |
| 481 |
3/4✓ Branch 15 → 16 taken 6 times.
✗ Branch 15 → 30 not taken.
✓ Branch 16 → 17 taken 3 times.
✓ Branch 16 → 18 taken 3 times.
|
6 | else if (inputString == SANITIZER_MEMORY) |
| 482 | 3 | cliOptions.instrumentation.sanitizer = Sanitizer::MEMORY; | |
| 483 |
3/4✓ Branch 18 → 19 taken 3 times.
✗ Branch 18 → 30 not taken.
✓ Branch 19 → 20 taken 2 times.
✓ Branch 19 → 21 taken 1 time.
|
3 | else if (inputString == SANITIZER_TYPE) |
| 484 | 2 | cliOptions.instrumentation.sanitizer = Sanitizer::TYPE; | |
| 485 | else | ||
| 486 |
1/2✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 27 not taken.
|
1 | throw CliError(INVALID_SANITIZER, inputString); |
| 487 | |||
| 488 | 11 | return true; | |
| 489 | 12 | }; | |
| 490 | |||
| 491 | // --debug-info | ||
| 492 |
3/6✓ Branch 4 → 5 taken 1743 times.
✗ Branch 4 → 37 not taken.
✓ Branch 7 → 8 taken 1743 times.
✗ Branch 7 → 31 not taken.
✓ Branch 8 → 9 taken 1743 times.
✗ Branch 8 → 29 not taken.
|
6972 | subCmd->add_flag<bool>("--debug-info,-g", cliOptions.instrumentation.generateDebugInfo, "Generate debug info"); |
| 493 | // --sanitizer | ||
| 494 |
3/6✓ Branch 16 → 17 taken 1743 times.
✗ Branch 16 → 52 not taken.
✓ Branch 20 → 21 taken 1743 times.
✗ Branch 20 → 43 not taken.
✓ Branch 21 → 22 taken 1743 times.
✗ Branch 21 → 41 not taken.
|
8715 | subCmd->add_option("--sanitizer", sanitizerCallback, "Enable sanitizer: none (default), address, thread, memory, type"); |
| 495 | 1743 | } | |
| 496 | |||
| 497 | /** | ||
| 498 | * Ensure that the compiler is not running in a Docker container | ||
| 499 | */ | ||
| 500 | 2 | void Driver::ensureNotDockerized() { | |
| 501 | 2 | const char *envValue = std::getenv(ENV_VAR_DOCKERIZED); | |
| 502 | − | if (envValue != nullptr && std::strcmp(envValue, "true") == 0) { // LCOV_EXCL_START | |
| 503 | − | const auto msg = "This feature is not supported in a containerized environment. Please use the standalone version of Spice."; | |
| 504 | − | throw CliError(FEATURE_NOT_SUPPORTED_WHEN_DOCKERIZED, msg); | |
| 505 | } // LCOV_EXCL_STOP | ||
| 506 | 2 | } | |
| 507 | |||
| 508 | } // namespace spice::compiler | ||
| 509 |