1
2
3
4
5
6 #include <cmajor/symbols/GlobalFlags.hpp>
7 #include <set>
8
9 namespace cmajor { namespace symbols {
10
11 BackEnd backend = BackEnd::llvm;
12 GlobalFlags globalFlags = GlobalFlags::none;
13 int optimizationLevel = -1;
14 int numBuildThreads = -1;
15
16 void SetBackEnd(BackEnd backend_)
17 {
18 backend = backend_;
19 }
20
21 BackEnd GetBackEnd()
22 {
23 return backend;
24 }
25
26 inline GlobalFlags operator|(GlobalFlags flags, GlobalFlags flag)
27 {
28 return GlobalFlags(uint64_t(flags) | uint64_t(flag));
29 }
30
31 inline GlobalFlags operator&(GlobalFlags flags, GlobalFlags flag)
32 {
33 return GlobalFlags(uint64_t(flags) & uint64_t(flag));
34 }
35
36 inline GlobalFlags operator~(GlobalFlags flags)
37 {
38 return GlobalFlags(~uint64_t(flags));
39 }
40
41 void SetGlobalFlag(GlobalFlags flag)
42 {
43 globalFlags = globalFlags | flag;
44 }
45
46 void ResetGlobalFlag(GlobalFlags flag)
47 {
48 globalFlags = globalFlags & ~flag;
49 }
50
51 bool GetGlobalFlag(GlobalFlags flag)
52 {
53 return (globalFlags & flag) != GlobalFlags::none;
54 }
55
56 std::string GetConfig()
57 {
58 std::string config = "debug";
59 if (GetGlobalFlag(GlobalFlags::release))
60 {
61 if (GetGlobalFlag(GlobalFlags::profile))
62 {
63 config = "profile";
64 }
65 else
66 {
67 config = "release";
68 }
69 }
70 else if (GetGlobalFlag(GlobalFlags::trace))
71 {
72 config = "trace";
73 }
74 return config;
75 }
76
77 int GetOptimizationLevel()
78 {
79 if (optimizationLevel == -1)
80 {
81 if (GetGlobalFlag(GlobalFlags::release))
82 {
83 return 2;
84 }
85 else
86 {
87 return 0;
88 }
89 }
90 else
91 {
92 return optimizationLevel;
93 }
94 }
95
96 void SetOptimizationLevel(int optimizationLevel_)
97 {
98 optimizationLevel = optimizationLevel_;
99 }
100
101 int GetNumBuildThreads()
102 {
103 return numBuildThreads;
104 }
105
106 void SetNumBuildThreads(int numBuildThreads_)
107 {
108 numBuildThreads = numBuildThreads_;
109 }
110
111 std::set<std::u32string> commandLineDefines;
112
113 void DefineCommandLineConditionalSymbol(const std::u32string& symbol)
114 {
115 commandLineDefines.insert(symbol);
116 }
117
118 std::std::set<std::u32string>GetCommandLineDefines()
119 {
120 return commandLineDefines;
121 }
122
123 std::string compilerVersion;
124
125 void SetCompilerVersion(const std::string& compilerVersion_)
126 {
127 compilerVersion = compilerVersion_;
128 }
129
130 std::string GetCompilerVersion()
131 {
132 return compilerVersion;
133 }
134
135 bool inUnitTest = false;
136
137 bool BeginUnitTest()
138 {
139 bool prevUnitTest = inUnitTest;
140 inUnitTest = true;
141 return prevUnitTest;
142 }
143
144 bool InUnitTest()
145 {
146 return inUnitTest;
147 }
148
149 int32_t unitTestAssertionNumber = 0;
150
151 void ResetUnitTestAssertionNumber()
152 {
153 unitTestAssertionNumber = 0;
154 }
155
156 int32_t GetNextUnitTestAssertionNumber()
157 {
158 return unitTestAssertionNumber++;
159 }
160
161 int32_t GetNumUnitTestAssertions()
162 {
163 return unitTestAssertionNumber;
164 }
165
166 void EndUnitTest(bool prevUnitTest)
167 {
168 inUnitTest = prevUnitTest;
169 }
170
171 std::std::vector<int32_t>*assertionLineNumberVector=nullptr;
172
173 void SetAssertionLineNumberVector(std::std::vector<int32_t>*assertionLineNumberVector_)
174 {
175 assertionLineNumberVector = assertionLineNumberVector_;
176 }
177
178 void AddAssertionLineNumber(int32_t lineNumber)
179 {
180 if (assertionLineNumberVector)
181 {
182 assertionLineNumberVector->push_back(lineNumber);
183 }
184 }
185
186 void ResetGlobalFlags()
187 {
188 backend = BackEnd::llvm;
189 globalFlags = GlobalFlags::none;
190 optimizationLevel = -1;
191 numBuildThreads = -1;
192 commandLineDefines.clear();
193 compilerVersion.clear();
194 inUnitTest = false;
195 unitTestAssertionNumber = 0;
196 assertionLineNumberVector = nullptr;
197 }
198
199 } }