GCC Code Coverage Report


Directory: ../
File: src/driver/Driver.h
Date: 2025-02-05 01:09:36
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 dumpDependencyGraph = false;
58 bool dumpIR = false;
59 bool dumpAssembly = false;
60 bool dumpObjectFile = false;
61 bool dumpToFiles = false;
62 bool abortAfterDump = false;
63 } dumpSettings;
64 bool namesForIRValues = false;
65 bool useLifetimeMarkers = false;
66 OptLevel optLevel = O0; // Default optimization level for debug build mode is O0
67 bool useLTO = false;
68 bool noEntryFct = false;
69 bool generateTestMain = false;
70 bool staticLinking = false;
71 bool generateDebugInfo = false;
72 bool disableVerifier = false;
73 bool testMode = false;
74 };
75
76 /**
77 * Helper class to setup the driver and command line parser
78 */
79 class Driver {
80 public:
81 // Constructors
82 Driver() = default;
83
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) {}
84 Driver(const Driver &) = delete;
85
86 // Public methods
87 void init();
88 int parse(int argc, const char *argv[]);
89 void enrich();
90 void runBinary() const;
91
92 // Public members
93 CliOptions cliOptions;
94 bool shouldCompile = false;
95 bool shouldInstall = false;
96 bool shouldUninstall = false;
97 bool shouldExecute = false;
98 bool dryRun = false; // For unit testing purposes
99
100 private:
101 // Private methods
102 void addBuildSubcommand();
103 void addRunSubcommand();
104 void addTestSubcommand();
105 void addInstallSubcommand();
106 void addUninstallSubcommand();
107 void addCompileSubcommandOptions(CLI::App *subCmd);
108 static void ensureNotDockerized();
109
110 // Members
111 CLI::App app = CLI::App{"Spice Programming Language", "spice"};
112 };
113
114 } // namespace spice::compiler
115