GCC Code Coverage Report


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