1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | #ifndef LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H |
10 | #define LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H |
11 | |
12 | #include "clang/Frontend/CommandLineSourceLoc.h" |
13 | #include "clang/Serialization/ModuleFileExtension.h" |
14 | #include "clang/Sema/CodeCompleteOptions.h" |
15 | #include "llvm/ADT/StringRef.h" |
16 | #include <cassert> |
17 | #include <memory> |
18 | #include <string> |
19 | #include <vector> |
20 | #include <unordered_map> |
21 | |
22 | namespace llvm { |
23 | |
24 | class MemoryBuffer; |
25 | |
26 | } |
27 | |
28 | namespace clang { |
29 | |
30 | namespace frontend { |
31 | |
32 | enum ActionKind { |
33 | |
34 | ASTDeclList, |
35 | |
36 | |
37 | ASTDump, |
38 | |
39 | |
40 | ASTPrint, |
41 | |
42 | |
43 | ASTView, |
44 | |
45 | |
46 | DumpCompilerOptions, |
47 | |
48 | |
49 | DumpRawTokens, |
50 | |
51 | |
52 | DumpTokens, |
53 | |
54 | |
55 | EmitAssembly, |
56 | |
57 | |
58 | EmitBC, |
59 | |
60 | |
61 | EmitHTML, |
62 | |
63 | |
64 | EmitLLVM, |
65 | |
66 | |
67 | EmitLLVMOnly, |
68 | |
69 | |
70 | EmitCodeGenOnly, |
71 | |
72 | |
73 | EmitObj, |
74 | |
75 | |
76 | FixIt, |
77 | |
78 | |
79 | GenerateModule, |
80 | |
81 | |
82 | GenerateModuleInterface, |
83 | |
84 | |
85 | , |
86 | |
87 | |
88 | GeneratePCH, |
89 | |
90 | |
91 | InitOnly, |
92 | |
93 | |
94 | ModuleFileInfo, |
95 | |
96 | |
97 | VerifyPCH, |
98 | |
99 | |
100 | ParseSyntaxOnly, |
101 | |
102 | |
103 | PluginAction, |
104 | |
105 | |
106 | PrintPreamble, |
107 | |
108 | |
109 | PrintPreprocessedInput, |
110 | |
111 | |
112 | RewriteMacros, |
113 | |
114 | |
115 | RewriteObjC, |
116 | |
117 | |
118 | RewriteTest, |
119 | |
120 | |
121 | RunAnalysis, |
122 | |
123 | |
124 | TemplightDump, |
125 | |
126 | |
127 | MigrateSource, |
128 | |
129 | |
130 | RunPreprocessorOnly |
131 | }; |
132 | |
133 | } |
134 | |
135 | |
136 | class InputKind { |
137 | private: |
138 | unsigned Lang : 4; |
139 | unsigned Fmt : 3; |
140 | unsigned Preprocessed : 1; |
141 | |
142 | public: |
143 | |
144 | |
145 | enum Language { |
146 | Unknown, |
147 | |
148 | |
149 | Asm, |
150 | |
151 | |
152 | |
153 | LLVM_IR, |
154 | |
155 | |
156 | C, |
157 | CXX, |
158 | ObjC, |
159 | ObjCXX, |
160 | OpenCL, |
161 | CUDA, |
162 | RenderScript, |
163 | HIP, |
164 | |
165 | }; |
166 | |
167 | |
168 | enum Format { |
169 | Source, |
170 | ModuleMap, |
171 | Precompiled |
172 | }; |
173 | |
174 | constexpr InputKind(Language L = Unknown, Format F = Source, |
175 | bool PP = false) |
176 | : Lang(L), Fmt(F), Preprocessed(PP) {} |
177 | |
178 | Language getLanguage() const { return static_cast<Language>(Lang); } |
179 | Format getFormat() const { return static_cast<Format>(Fmt); } |
180 | bool isPreprocessed() const { return Preprocessed; } |
181 | |
182 | |
183 | bool isUnknown() const { return Lang == Unknown && Fmt == Source; } |
184 | |
185 | |
186 | bool isObjectiveC() const { return Lang == ObjC || Lang == ObjCXX; } |
187 | |
188 | InputKind getPreprocessed() const { |
189 | return InputKind(getLanguage(), getFormat(), true); |
190 | } |
191 | |
192 | InputKind withFormat(Format F) const { |
193 | return InputKind(getLanguage(), F, isPreprocessed()); |
194 | } |
195 | }; |
196 | |
197 | |
198 | class FrontendInputFile { |
199 | |
200 | std::string File; |
201 | |
202 | |
203 | |
204 | |
205 | llvm::MemoryBuffer *Buffer = nullptr; |
206 | |
207 | |
208 | InputKind Kind; |
209 | |
210 | |
211 | bool IsSystem = false; |
212 | |
213 | public: |
214 | FrontendInputFile() = default; |
215 | FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false) |
216 | : File(File.str()), Kind(Kind), IsSystem(IsSystem) {} |
217 | FrontendInputFile(llvm::MemoryBuffer *Buffer, InputKind Kind, |
218 | bool IsSystem = false) |
219 | : Buffer(Buffer), Kind(Kind), IsSystem(IsSystem) {} |
220 | |
221 | InputKind getKind() const { return Kind; } |
222 | bool isSystem() const { return IsSystem; } |
223 | |
224 | bool isEmpty() const { return File.empty() && Buffer == nullptr; } |
225 | bool isFile() const { return !isBuffer(); } |
226 | bool isBuffer() const { return Buffer != nullptr; } |
227 | bool isPreprocessed() const { return Kind.isPreprocessed(); } |
228 | |
229 | StringRef getFile() const { |
230 | assert(isFile()); |
231 | return File; |
232 | } |
233 | |
234 | llvm::MemoryBuffer *getBuffer() const { |
235 | assert(isBuffer()); |
236 | return Buffer; |
237 | } |
238 | }; |
239 | |
240 | |
241 | class FrontendOptions { |
242 | public: |
243 | |
244 | unsigned DisableFree : 1; |
245 | |
246 | |
247 | |
248 | unsigned RelocatablePCH : 1; |
249 | |
250 | |
251 | unsigned ShowHelp : 1; |
252 | |
253 | |
254 | unsigned ShowStats : 1; |
255 | |
256 | |
257 | unsigned ShowTimers : 1; |
258 | |
259 | |
260 | unsigned ShowVersion : 1; |
261 | |
262 | |
263 | unsigned FixWhatYouCan : 1; |
264 | |
265 | |
266 | unsigned FixOnlyWarnings : 1; |
267 | |
268 | |
269 | unsigned FixAndRecompile : 1; |
270 | |
271 | |
272 | unsigned FixToTemporaries : 1; |
273 | |
274 | |
275 | unsigned ARCMTMigrateEmitARCErrors : 1; |
276 | |
277 | |
278 | |
279 | unsigned SkipFunctionBodies : 1; |
280 | |
281 | |
282 | unsigned UseGlobalModuleIndex : 1; |
283 | |
284 | |
285 | unsigned GenerateGlobalModuleIndex : 1; |
286 | |
287 | |
288 | unsigned ASTDumpDecls : 1; |
289 | |
290 | |
291 | unsigned ASTDumpAll : 1; |
292 | |
293 | |
294 | unsigned ASTDumpLookups : 1; |
295 | |
296 | |
297 | unsigned BuildingImplicitModule : 1; |
298 | |
299 | |
300 | unsigned ModulesEmbedAllFiles : 1; |
301 | |
302 | |
303 | unsigned IncludeTimestamps : 1; |
304 | |
305 | CodeCompleteOptions CodeCompleteOpts; |
306 | |
307 | enum { |
308 | ARCMT_None, |
309 | ARCMT_Check, |
310 | ARCMT_Modify, |
311 | ARCMT_Migrate |
312 | } ARCMTAction = ARCMT_None; |
313 | |
314 | enum { |
315 | ObjCMT_None = 0, |
316 | |
317 | |
318 | ObjCMT_Literals = 0x1, |
319 | |
320 | |
321 | ObjCMT_Subscripting = 0x2, |
322 | |
323 | |
324 | ObjCMT_ReadonlyProperty = 0x4, |
325 | |
326 | |
327 | ObjCMT_ReadwriteProperty = 0x8, |
328 | |
329 | |
330 | ObjCMT_Property = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty), |
331 | |
332 | |
333 | ObjCMT_Annotation = 0x10, |
334 | |
335 | |
336 | ObjCMT_Instancetype = 0x20, |
337 | |
338 | |
339 | ObjCMT_NsMacros = 0x40, |
340 | |
341 | |
342 | ObjCMT_ProtocolConformance = 0x80, |
343 | |
344 | |
345 | ObjCMT_AtomicProperty = 0x100, |
346 | |
347 | |
348 | ObjCMT_ReturnsInnerPointerProperty = 0x200, |
349 | |
350 | |
351 | ObjCMT_NsAtomicIOSOnlyProperty = 0x400, |
352 | |
353 | |
354 | ObjCMT_DesignatedInitializer = 0x800, |
355 | |
356 | |
357 | ObjCMT_PropertyDotSyntax = 0x1000, |
358 | |
359 | ObjCMT_MigrateDecls = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty | |
360 | ObjCMT_Annotation | ObjCMT_Instancetype | |
361 | ObjCMT_NsMacros | ObjCMT_ProtocolConformance | |
362 | ObjCMT_NsAtomicIOSOnlyProperty | |
363 | ObjCMT_DesignatedInitializer), |
364 | ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting | |
365 | ObjCMT_MigrateDecls | ObjCMT_PropertyDotSyntax) |
366 | }; |
367 | unsigned ObjCMTAction = ObjCMT_None; |
368 | std::string ObjCMTWhiteListPath; |
369 | |
370 | std::string MTMigrateDir; |
371 | std::string ARCMTMigrateReportOut; |
372 | |
373 | |
374 | std::vector<FrontendInputFile> Inputs; |
375 | |
376 | |
377 | |
378 | std::string OriginalModuleMap; |
379 | |
380 | |
381 | std::string OutputFile; |
382 | |
383 | |
384 | std::string FixItSuffix; |
385 | |
386 | |
387 | std::string ASTDumpFilter; |
388 | |
389 | |
390 | ParsedSourceLocation CodeCompletionAt; |
391 | |
392 | |
393 | frontend::ActionKind ProgramAction = frontend::ParseSyntaxOnly; |
394 | |
395 | |
396 | std::string ActionName; |
397 | |
398 | |
399 | std::unordered_map<std::string,std::vector<std::string>> PluginArgs; |
400 | |
401 | |
402 | std::vector<std::string> AddPluginActions; |
403 | |
404 | |
405 | std::vector<std::string> Plugins; |
406 | |
407 | |
408 | std::vector<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions; |
409 | |
410 | |
411 | std::vector<std::string> ModuleMapFiles; |
412 | |
413 | |
414 | |
415 | std::vector<std::string> ModuleFiles; |
416 | |
417 | |
418 | std::vector<std::string> ModulesEmbedFiles; |
419 | |
420 | |
421 | std::vector<std::string> ASTMergeFiles; |
422 | |
423 | |
424 | |
425 | std::vector<std::string> LLVMArgs; |
426 | |
427 | |
428 | |
429 | std::string OverrideRecordLayoutsFile; |
430 | |
431 | |
432 | std::string AuxTriple; |
433 | |
434 | |
435 | std::string StatsFile; |
436 | |
437 | public: |
438 | FrontendOptions() |
439 | : DisableFree(false), RelocatablePCH(false), ShowHelp(false), |
440 | ShowStats(false), ShowTimers(false), ShowVersion(false), |
441 | FixWhatYouCan(false), FixOnlyWarnings(false), FixAndRecompile(false), |
442 | FixToTemporaries(false), ARCMTMigrateEmitARCErrors(false), |
443 | SkipFunctionBodies(false), UseGlobalModuleIndex(true), |
444 | GenerateGlobalModuleIndex(true), ASTDumpDecls(false), |
445 | ASTDumpLookups(false), BuildingImplicitModule(false), |
446 | ModulesEmbedAllFiles(false), IncludeTimestamps(true) {} |
447 | |
448 | |
449 | |
450 | |
451 | |
452 | |
453 | static InputKind getInputKindForExtension(StringRef Extension); |
454 | }; |
455 | |
456 | } |
457 | |
458 | #endif |
459 | |