GCC Code Coverage Report


Directory: ../
File: src/driver/Driver.h
Date: 2025-03-05 01:50:32
Exec Total Coverage
Lines: 1 2 50.0%
Functions: 1 2 50.0%
Branches: 3 12 25.0%

Line Branch Exec Source
1 // Copyright (c) 2021-2025 ChilliBits. All rights reserved.
2
3 #pragma once
4
5 #include "../../lib/cli11/CLI11.hpp"
6
7 namespace spice::compiler {
8
9 const char *const TARGET_UNKNOWN = "unknown";
10 const char *const TARGET_WASM32 = "wasm32";
11 const char *const TARGET_WASM64 = "wasm64";
12 const char *const ENV_VAR_DOCKERIZED = "SPICE_DOCKERIZED";
13
14 enum OptLevel : uint8_t {
15 O0 = 0, // No optimization
16 O1 = 1, // Only basic optimizations
17 O2 = 2, // Default optimization level
18 O3 = 3, // Aggressively optimize for performance
19 Os = 4, // Optimize for code size
20 Oz = 5, // Aggressively optimize for code size
21 };
22
23 enum BuildMode : uint8_t {
24 DEBUG = 0, // Default build mode, uses -O0 per default
25 RELEASE = 1, // Build without debug information and with -O2 per default
26 TEST = 2, // Build with test main function and always emit assertions
27 };
28 const char *const BUILD_MODE_DEBUG = "debug";
29 const char *const BUILD_MODE_RELEASE = "release";
30 const char *const BUILD_MODE_TEST = "test";
31
32 /**
33 * Representation of the various cli options
34 */
35 struct CliOptions {
36 std::filesystem::path mainSourceFile; // e.g. ./main.spice
37 std::string targetTriple; // In format: <arch><sub>-<vendor>-<sys>-<abi>
38 std::string targetArch = TARGET_UNKNOWN;
39 std::string targetVendor = TARGET_UNKNOWN;
40 std::string targetOs = TARGET_UNKNOWN;
41 bool isNativeTarget = true;
42 bool useCPUFeatures = true;
43 bool execute = false;
44 std::filesystem::path cacheDir; // Where the cache files go. Should always be a temp directory
45 std::filesystem::path outputDir = "./"; // Where the object files go. Should always be a temp directory
46 std::filesystem::path outputPath; // Where the output binary goes.
47 BuildMode buildMode = DEBUG; // Default build mode is debug
48 unsigned short compileJobCount = 0; // 0 for auto
49 bool ignoreCache = false;
50 std::string llvmArgs;
51 bool printDebugOutput = false;
52 struct DumpSettings {
53 bool dumpCST = false;
54 bool dumpAST = false;
55 bool dumpSymbolTable = false;
56 bool dumpTypes = false;
57 bool dumpCacheStats = false;
58 bool dumpDependencyGraph = false;
59 bool dumpIR = false;
60 bool dumpAssembly = false;
61 bool dumpObjectFile = false;
62 bool dumpToFiles = false;
63 bool abortAfterDump = false;
64 } dumpSettings;
65 bool namesForIRValues = false;
66 bool useLifetimeMarkers = false;
67 OptLevel optLevel = O0; // Default optimization level for debug build mode is O0
68 bool useLTO = false;
69 bool noEntryFct = false;
70 bool generateTestMain = false;
71 bool staticLinking = false;
72 bool generateDebugInfo = false;
73 bool disableVerifier = false;
74 bool testMode = false;
75 bool comparableOutput = false;
76 };
77
78 /**
79 * Helper class to set up the driver and command line parser
80 */
81 class Driver {
82 public:
83 // Constructors
84 Driver() = default;
85
3/6
✓ Branch 0 (5→6) taken 8 times.
✗ Branch 1 (5→23) not taken.
✓ Branch 2 (8→9) taken 8 times.
✗ Branch 3 (8→17) not taken.
✓ Branch 4 (9→10) taken 8 times.
✗ Branch 5 (9→15) not taken.
40 explicit Driver(bool dryRun) : dryRun(dryRun) {}
86 Driver(const Driver &) = delete;
87
88 // Public methods
89 void init();
90 int parse(int argc, const char *argv[]);
91 void enrich();
92 void runBinary() const;
93
94 // Public members
95 CliOptions cliOptions;
96 bool shouldCompile = false;
97 bool shouldInstall = false;
98 bool shouldUninstall = false;
99 bool shouldExecute = false;
100 bool dryRun = false; // For unit testing purposes
101
102 private:
103 // Private methods
104 void addBuildSubcommand();
105 void addRunSubcommand();
106 void addTestSubcommand();
107 void addInstallSubcommand();
108 void addUninstallSubcommand();
109 void addCompileSubcommandOptions(CLI::App *subCmd);
110 static void ensureNotDockerized();
111
112 // Members
113 CLI::App app = CLI::App{"Spice Programming Language", "spice"};
114 };
115
116 } // namespace spice::compiler
117