cc1as.h raw
1 // Source: https://github.com/llvm/llvm-project/blob/main/clang/tools/driver/cc1as_main.cpp
2 // See cc1as.cpp for details.
3
4 //===-- cc1as.h - Clang Assembler ----------------------------------------===//
5 //
6 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7 // See https://llvm.org/LICENSE.txt for license information.
8 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //
10 //===----------------------------------------------------------------------===//
11 //
12 // This is the entry point to the clang -cc1as functionality, which implements
13 // the direct interface to the LLVM MC based assembler.
14 //
15 //===----------------------------------------------------------------------===//
16
17 /// Helper class for representing a single invocation of the assembler.
18 struct AssemblerInvocation {
19 /// @name Target Options
20 /// @{
21
22 /// The name of the target triple to assemble for.
23 std::string Triple;
24
25 /// If given, the name of the target CPU to determine which instructions
26 /// are legal.
27 std::string CPU;
28
29 /// The list of target specific features to enable or disable -- this should
30 /// be a list of strings starting with '+' or '-'.
31 std::vector<std::string> Features;
32
33 /// The list of symbol definitions.
34 std::vector<std::string> SymbolDefs;
35
36 /// @}
37 /// @name Language Options
38 /// @{
39
40 std::vector<std::string> IncludePaths;
41 LLVM_PREFERRED_TYPE(bool)
42 unsigned NoInitialTextSection : 1;
43 LLVM_PREFERRED_TYPE(bool)
44 unsigned SaveTemporaryLabels : 1;
45 LLVM_PREFERRED_TYPE(bool)
46 unsigned GenDwarfForAssembly : 1;
47 LLVM_PREFERRED_TYPE(bool)
48 unsigned Dwarf64 : 1;
49 unsigned DwarfVersion;
50 std::string DwarfDebugFlags;
51 std::string DwarfDebugProducer;
52 std::string DebugCompilationDir;
53 llvm::SmallVector<std::pair<std::string, std::string>, 0> DebugPrefixMap;
54 llvm::DebugCompressionType CompressDebugSections =
55 llvm::DebugCompressionType::None;
56 std::string MainFileName;
57 std::string SplitDwarfOutput;
58
59 /// @}
60 /// @name Frontend Options
61 /// @{
62
63 std::string InputFile;
64 std::vector<std::string> LLVMArgs;
65 std::string OutputPath;
66 enum FileType {
67 FT_Asm, ///< Assembly (.s) output, transliterate mode.
68 FT_Null, ///< No output, for timing purposes.
69 FT_Obj ///< Object file output.
70 };
71 FileType OutputType;
72 LLVM_PREFERRED_TYPE(bool)
73 unsigned ShowHelp : 1;
74 LLVM_PREFERRED_TYPE(bool)
75 unsigned ShowVersion : 1;
76
77 /// @}
78 /// @name Transliterate Options
79 /// @{
80
81 unsigned OutputAsmVariant;
82 LLVM_PREFERRED_TYPE(bool)
83 unsigned ShowEncoding : 1;
84 LLVM_PREFERRED_TYPE(bool)
85 unsigned ShowInst : 1;
86
87 /// @}
88 /// @name Assembler Options
89 /// @{
90
91 LLVM_PREFERRED_TYPE(bool)
92 unsigned RelaxAll : 1;
93 LLVM_PREFERRED_TYPE(bool)
94 unsigned NoExecStack : 1;
95 LLVM_PREFERRED_TYPE(bool)
96 unsigned FatalWarnings : 1;
97 LLVM_PREFERRED_TYPE(bool)
98 unsigned NoWarn : 1;
99 LLVM_PREFERRED_TYPE(bool)
100 unsigned NoTypeCheck : 1;
101 LLVM_PREFERRED_TYPE(bool)
102 unsigned IncrementalLinkerCompatible : 1;
103 LLVM_PREFERRED_TYPE(bool)
104 unsigned EmbedBitcode : 1;
105
106 /// Whether to emit DWARF unwind info.
107 EmitDwarfUnwindType EmitDwarfUnwind;
108
109 // Whether to emit compact-unwind for non-canonical entries.
110 // Note: maybe overriden by other constraints.
111 LLVM_PREFERRED_TYPE(bool)
112 unsigned EmitCompactUnwindNonCanonical : 1;
113
114 LLVM_PREFERRED_TYPE(bool)
115 unsigned Crel : 1;
116 LLVM_PREFERRED_TYPE(bool)
117 unsigned ImplicitMapsyms : 1;
118
119 LLVM_PREFERRED_TYPE(bool)
120 unsigned X86RelaxRelocations : 1;
121 LLVM_PREFERRED_TYPE(bool)
122 unsigned X86Sse2Avx : 1;
123
124 /// The name of the relocation model to use.
125 std::string RelocationModel;
126
127 /// The ABI targeted by the backend. Specified using -target-abi. Empty
128 /// otherwise.
129 std::string TargetABI;
130
131 /// Darwin target variant triple, the variant of the deployment target
132 /// for which the code is being compiled.
133 std::optional<llvm::Triple> DarwinTargetVariantTriple;
134
135 /// The version of the darwin target variant SDK which was used during the
136 /// compilation
137 llvm::VersionTuple DarwinTargetVariantSDKVersion;
138
139 /// The name of a file to use with \c .secure_log_unique directives.
140 std::string AsSecureLogFile;
141 /// @}
142
143 public:
144 AssemblerInvocation() {
145 Triple = "";
146 NoInitialTextSection = 0;
147 InputFile = "-";
148 OutputPath = "-";
149 OutputType = FT_Asm;
150 OutputAsmVariant = 0;
151 ShowInst = 0;
152 ShowEncoding = 0;
153 RelaxAll = 0;
154 NoExecStack = 0;
155 FatalWarnings = 0;
156 NoWarn = 0;
157 NoTypeCheck = 0;
158 IncrementalLinkerCompatible = 0;
159 Dwarf64 = 0;
160 DwarfVersion = 0;
161 EmbedBitcode = 0;
162 EmitDwarfUnwind = EmitDwarfUnwindType::Default;
163 EmitCompactUnwindNonCanonical = false;
164 Crel = false;
165 ImplicitMapsyms = 0;
166 X86RelaxRelocations = 0;
167 X86Sse2Avx = 0;
168 }
169
170 static bool CreateFromArgs(AssemblerInvocation &Res,
171 ArrayRef<const char *> Argv,
172 DiagnosticsEngine &Diags);
173 };
174
175 bool ExecuteAssembler(AssemblerInvocation &Opts, DiagnosticsEngine &Diags);
176