1
2
3
4
5
6 #ifndef CMAJOR_IR_EMITTER_INCLUDED
7 #define CMAJOR_IR_EMITTER_INCLUDED
8 #include <cmajor/ir/IrApi.hpp>
9 #include <cmajor/ir/ValueStack.hpp>
10 #include <cmajor/common/Common.hpp>
11 #include <soulng/lexer/Span.hpp>
12 #include <boost/uuid/uuid.hpp>
13 #include <boost/uuid/nil_generator.hpp>
14 #include <vector>
15 #include <string>
16
17 namespace cmajor { namespace ir {
18
19 using soulng::lexer::Span;
20
21 struct Pad
22 {
23 Pad() : parent(nullptr), value(nullptr) {}
24 Pad* parent;
25 void* value;
26 };
27
28 class EmittingDelegate
29 {
30 public:
31 virtual void* GetGlobalStringPtr(int stringId) = 0;
32 virtual void* GetGlobalWStringConstant(int stringId) = 0;
33 virtual void* GetGlobalUStringConstant(int stringId) = 0;
34 virtual void* GetGlobalUuidConstant(int uuidId) = 0;
35 virtual void SetLineNumber(int32_t lineNumber) {}
36 virtual void* HandlerBlock() { return nullptr; }
37 virtual void* CleanupBlock() { return nullptr; }
38 virtual bool NewCleanupNeeded() { return false; }
39 virtual bool InTryBlock() const { return false; }
40 virtual int CurrentTryBlockId() const { return 0; }
41 virtual void CreateCleanup() { }
42 virtual std::string GetSourceFilePath(const Span& span, const boost::uuids::uuid& moduleId) { return std::string(); }
43 virtual cmajor::ir::Pad* CurrentPad() { return nullptr; }
44 virtual void* CreateClassDIType(void* classPtr) { return nullptr; }
45 virtual int Install(const std::string& str) = 0;
46 virtual int Install(const std::u16string& str) = 0;
47 virtual int Install(const std::u32string& str) = 0;
48 };
49
50 class Emitter
51 {
52 public:
53 Emitter(ValueStack* stack_);
54 virtual ~Emitter();
55 ValueStack& Stack() { return *stack; }
56 virtual void SetEmittingDelegate(EmittingDelegate* emittingDelegate_) = 0;
57 virtual void* GetIrTypeForBool() = 0;
58 virtual void* GetIrTypeForSByte() = 0;
59 virtual void* GetIrTypeForByte() = 0;
60 virtual void* GetIrTypeForShort() = 0;
61 virtual void* GetIrTypeForUShort() = 0;
62 virtual void* GetIrTypeForInt() = 0;
63 virtual void* GetIrTypeForUInt() = 0;
64 virtual void* GetIrTypeForLong() = 0;
65 virtual void* GetIrTypeForULong() = 0;
66 virtual void* GetIrTypeForFloat() = 0;
67 virtual void* GetIrTypeForDouble() = 0;
68 virtual void* GetIrTypeForChar() = 0;
69 virtual void* GetIrTypeForWChar() = 0;
70 virtual void* GetIrTypeForUChar() = 0;
71 virtual void* GetIrTypeForVoid() = 0;
72 virtual void* GetIrTypeForFunction(void* retType, const std::std::vector<void*>¶mTypes) = 0;
73 virtual void* GetIrTypeForVariableParamFunction(void* retType) = 0;
74 virtual void* GetIrTypeByTypeId(const boost::uuids::uuid& typeId) = 0;
75 virtual void SetIrTypeByTypeId(const boost::uuids::uuid& typeId, void* irType) = 0;
76 virtual void* GetIrTypeForArrayType(void* elementType, int64_t size) = 0;
77 virtual void* GetIrTypeForClassType(const std::std::vector<void*>&elementTypes) = 0;
78 virtual void* CreateFwdIrTypeForClassType() = 0;
79 virtual void SetFwdIrTypeBody(void* forwardDeclaredType, const std::std::vector<void*>&elementTypes) = 0;
80 virtual void* GetIrTypeForDelegateType(void* retType, const std::std::vector<void*>¶mTypes) = 0;
81 virtual void* GetIrTypeForVoidPtrType() = 0;
82 virtual void* GetIrTypeForStructType(const std::std::vector<void*>&elementTypes) = 0;
83 virtual void* GetIrTypeForPtrType(void* baseIrType) = 0;
84 virtual std::string GetIrTypeName(void* irType) = 0;
85 virtual std::string MakeVmtVariableName(const std::string& vmtObjectName) = 0;
86 virtual void* CreateDefaultIrValueForArrayType(void* arrayIrType, const std::std::vector<void*>&arrayOfDefaults) = 0;
87 virtual void* CreateDefaultIrValueForBool() = 0;
88 virtual void* CreateDefaultIrValueForSByte() = 0;
89 virtual void* CreateDefaultIrValueForByte() = 0;
90 virtual void* CreateDefaultIrValueForShort() = 0;
91 virtual void* CreateDefaultIrValueForUShort() = 0;
92 virtual void* CreateDefaultIrValueForInt() = 0;
93 virtual void* CreateDefaultIrValueForUInt() = 0;
94 virtual void* CreateDefaultIrValueForLong() = 0;
95 virtual void* CreateDefaultIrValueForULong() = 0;
96 virtual void* CreateDefaultIrValueForFloat() = 0;
97 virtual void* CreateDefaultIrValueForDouble() = 0;
98 virtual void* CreateDefaultIrValueForChar() = 0;
99 virtual void* CreateDefaultIrValueForWChar() = 0;
100 virtual void* CreateDefaultIrValueForUChar() = 0;
101 virtual void* CreateDefaultIrValueForStruct(void* irType, const std::std::vector<void*>&defaultMembers) = 0;
102 virtual void* CreateDefaultIrValueForDelegateType(void* irType) = 0;
103 virtual void* CreateDefaultIrValueForVoidPtrType() = 0;
104 virtual void* CreateDefaultIrValueForDerivedType(void* irType) = 0;
105 virtual void* CreateDefaultIrValueForPtrType(void* irType) = 0;
106 virtual void* CreateIrValueForBool(bool value) = 0;
107 virtual void* CreateIrValueForSByte(int8_t value) = 0;
108 virtual void* CreateIrValueForByte(uint8_t value) = 0;
109 virtual void* CreateIrValueForShort(int16_t value) = 0;
110 virtual void* CreateIrValueForUShort(uint16_t value) = 0;
111 virtual void* CreateIrValueForInt(int32_t value) = 0;
112 virtual void* CreateIrValueForUInt(uint32_t value) = 0;
113 virtual void* CreateIrValueForLong(int64_t value) = 0;
114 virtual void* CreateIrValueForULong(uint64_t value) = 0;
115 virtual void* CreateIrValueForFloat(float value) = 0;
116 virtual void* CreateIrValueForDouble(double value) = 0;
117 virtual void* CreateIrValueForChar(uint8_t value) = 0;
118 virtual void* CreateIrValueForWChar(uint16_t value) = 0;
119 virtual void* CreateIrValueForUChar(uint32_t value) = 0;
120 virtual void* CreateIrValueForWString(void* wstringConstant) = 0;
121 virtual void* CreateIrValueForUString(void* ustringConstant) = 0;
122 virtual void* CreateIrValueForConstantArray(void* arrayIrType, const std::std::vector<void*>&elementConstants, conststd::string&prefix) = 0;
123 virtual void* CreateIrValueForConstantStruct(void* structIrType, const std::std::vector<void*>&elementConstants) = 0;
124 virtual void* CreateIrValueForUuid(void* uuidConstant) = 0;
125 virtual void* GetConversionValue(void* type, void* from) = 0;
126 virtual void* CreateGlobalStringPtr(const std::string& name) = 0;
127 virtual void* CreateGlobalWStringPtr(const std::u16string& name) = 0;
128 virtual void* CreateGlobalUStringPtr(const std::u32string& name) = 0;
129 virtual void* GetGlobalStringPtr(int stringId) = 0;
130 virtual void* GetGlobalWStringConstant(int stringId) = 0;
131 virtual void* GetGlobalUStringConstant(int stringId) = 0;
132 virtual void* GetGlobalUuidConstant(int uuidId) = 0;
133 virtual void* CreateDITypeForBool() = 0;
134 virtual void* CreateDITypeForSByte() = 0;
135 virtual void* CreateDITypeForByte() = 0;
136 virtual void* CreateDITypeForShort() = 0;
137 virtual void* CreateDITypeForUShort() = 0;
138 virtual void* CreateDITypeForInt() = 0;
139 virtual void* CreateDITypeForUInt() = 0;
140 virtual void* CreateDITypeForLong() = 0;
141 virtual void* CreateDITypeForULong() = 0;
142 virtual void* CreateDITypeForFloat() = 0;
143 virtual void* CreateDITypeForDouble() = 0;
144 virtual void* CreateDITypeForChar() = 0;
145 virtual void* CreateDITypeForWChar() = 0;
146 virtual void* CreateDITypeForUChar() = 0;
147 virtual void* CreateDITypeForVoid() = 0;
148 virtual void* CreateDITypeForArray(void* elementDIType, const std::std::vector<void*>&elements) = 0;
149 virtual void* CreateDITypeForEnumConstant(const std::string& name, int64_t value) = 0;
150 virtual void* CreateDITypeForEnumType(const std::string& name, const std::string& mangledName, const Span& span, const boost::uuids::uuid& moduleId, const std::std::vector<void*>&enumConstantElements,
151 uint64_t sizeInBits, uint32_t alignInBits, void* underlyingDIType) = 0;
152 virtual void* CreateIrDIForwardDeclaration(void* irType, const std::string& name, const std::string& mangledName, const Span& span, const boost::uuids::uuid& moduleId) = 0;
153 virtual uint64_t GetOffsetInBits(void* classIrType, int layoutIndex) = 0;
154 virtual void* CreateDITypeForClassType(void* irType, const std::std::vector<void*>&memberVariableElements, constSpan&classSpan, constboost::uuids::uuid&moduleId, const std::string& name, void* vtableHolderClass,
155 const std::string& mangledName, void* baseClassDIType) = 0;
156 virtual void MapFwdDeclaration(void* fwdDeclaration, const boost::uuids::uuid& typeId) = 0;
157 virtual void* GetDITypeByTypeId(const boost::uuids::uuid& typeId) const = 0;
158 virtual void SetDITypeByTypeId(const boost::uuids::uuid& typeId, void* diType, const std::string& typeName) = 0;
159 virtual void* GetDIMemberType(const std::std::pair<boost::uuids::uuid, int32_t>&memberVariableId) = 0;
160 virtual void SetDIMemberType(const std::std::pair<boost::uuids::uuid, int32_t>&memberVariableId, void*diType) = 0;
161 virtual void* CreateDIMemberType(void* scope, const std::string& name, const Span& span, const boost::uuids::uuid& moduleId, uint64_t sizeInBits, uint64_t alignInBits, uint64_t offsetInBits, void* diType) = 0;
162 virtual void* CreateConstDIType(void* diType) = 0;
163 virtual void* CreateLValueRefDIType(void* diType) = 0;
164 virtual void* CreateRValueRefDIType(void* diType) = 0;
165 virtual void* CreatePointerDIType(void* diType) = 0;
166 virtual void* CreateUnspecifiedDIType(const std::string& name) = 0;
167 virtual void MapClassPtr(const boost::uuids::uuid& typeId, void* classPtr, const std::string& className) = 0;
168 virtual uint64_t GetSizeInBits(void* irType) = 0;
169 virtual uint64_t GetAlignmentInBits(void* irType) = 0;
170 virtual void SetCurrentDebugLocation(const Span& span) = 0;
171 virtual void* GetArrayBeginAddress(void* arrayPtr) = 0;
172 virtual void* GetArrayEndAddress(void* arrayPtr, uint64_t size) = 0;
173 virtual void* CreateBasicBlock(const std::string& name) = 0;
174 virtual void* CreateIncludeBasicBlockInstruction(void* basicBlock) = 0;
175 virtual void PushParentBlock() = 0;
176 virtual void PopParentBlock() = 0;
177 virtual void SetHandlerBlock(void* tryBlock, void* catchBlock) = 0;
178 virtual void SetCleanupBlock(void* cleanupBlock) = 0;
179 virtual int GetBasicBlockId(void* basicBlock) = 0;
180 virtual void CreateBr(void* targetBasicBlock) = 0;
181 virtual void* CurrentBasicBlock() const = 0;
182 virtual void SetCurrentBasicBlock(void* basicBlock) = 0;
183 virtual void CreateCondBr(void* cond, void* trueBasicBlock, void* falseBasicBlock) = 0;
184 virtual void* CreateArrayIndexAddress(void* arrayPtr, void* index) = 0;
185 virtual void CreateStore(void* value, void* ptr) = 0;
186 virtual void* CreateLoad(void* ptr) = 0;
187 virtual void* CreateAdd(void* left, void* right) = 0;
188 virtual void* CreateFAdd(void* left, void* right) = 0;
189 virtual void* CreateSub(void* left, void* right) = 0;
190 virtual void* CreateFSub(void* left, void* right) = 0;
191 virtual void* CreateMul(void* left, void* right) = 0;
192 virtual void* CreateFMul(void* left, void* right) = 0;
193 virtual void* CreateUDiv(void* left, void* right) = 0;
194 virtual void* CreateSDiv(void* left, void* right) = 0;
195 virtual void* CreateFDiv(void* left, void* right) = 0;
196 virtual void* CreateURem(void* left, void* right) = 0;
197 virtual void* CreateSRem(void* left, void* right) = 0;
198 virtual void* CreateAnd(void* left, void* right) = 0;
199 virtual void* CreateOr(void* left, void* right) = 0;
200 virtual void* CreateXor(void* left, void* right) = 0;
201 virtual void* CreateShl(void* left, void* right) = 0;
202 virtual void* CreateAShr(void* left, void* right) = 0;
203 virtual void* CreateLShr(void* left, void* right) = 0;
204 virtual void* CreateICmpEQ(void* left, void* right) = 0;
205 virtual void* CreateFCmpOEQ(void* left, void* right) = 0;
206 virtual void* CreateICmpULT(void* leftValue, void* rightValue) = 0;
207 virtual void* CreateICmpSLT(void* leftValue, void* rightValue) = 0;
208 virtual void* CreateFCmpOLT(void* leftValue, void* rightValue) = 0;
209 virtual void* CreateSExt(void* operand, void* destinationType) = 0;
210 virtual void* CreateZExt(void* operand, void* destinationType) = 0;
211 virtual void* CreateFPExt(void* operand, void* destinationType) = 0;
212 virtual void* CreateTrunc(void* operand, void* destinationType) = 0;
213 virtual void* CreateFPTrunc(void* operand, void* destinationType) = 0;
214 virtual void* CreateBitCast(void* operand, void* destinationType) = 0;
215 virtual void* CreateUIToFP(void* operand, void* destinationType) = 0;
216 virtual void* CreateSIToFP(void* operand, void* destinationType) = 0;
217 virtual void* CreateFPToUI(void* operand, void* destinationType) = 0;
218 virtual void* CreateFPToSI(void* operand, void* destinationType) = 0;
219 virtual void* CreateIntToPtr(void* intValue, void* destinationType) = 0;
220 virtual void* CreatePtrToInt(void* ptrValue, void* destinationType) = 0;
221 virtual void* CreateNot(void* value) = 0;
222 virtual void* CreateNeg(void* value) = 0;
223 virtual void* CreateFNeg(void* value) = 0;
224 virtual void* CreateNop() = 0;
225 virtual void* CreateSave() = 0;
226 virtual void* CreateBeginTry() = 0;
227 virtual void* CreateEndTry(void* nextDest) = 0;
228 virtual void* CreateBeginCatch() = 0;
229 virtual void* CreateEndCatch(void* nextDest) = 0;
230 virtual std::string GetVmtObjectName(void* symbol) const = 0;
231 virtual void SetVmtObjectName(void* symbol, const std::string& vmtObjectName) = 0;
232 virtual std::string GetImtArrayObjectName(void* symbol) const = 0;
233 virtual void SetImtArrayObjectName(void* symbol, const std::string& imtArrayObjectName) = 0;
234 virtual void* GetVmtObjectType(void* symbol) const = 0;
235 virtual void SetVmtObjectType(void* symbol, void* vmtObjectType) = 0;
236 virtual void* GetStaticObjectType(void* symbol) const = 0;
237 virtual void SetStaticObjectType(void* symbol, void* type) = 0;
238 virtual std::string GetStaticObjectName(void* symbol) const = 0;
239 virtual void SetStaticObjectName(void* symbol, const std::string& staticObjectName) = 0;
240 virtual void* GetOrInsertGlobal(const std::string& name, void* type) = 0;
241 virtual void* GetOrInsertAnyComdat(const std::string& name, void* global) = 0;
242 virtual void* GetOrInsertAnyFunctionComdat(const std::string& name, void* function) = 0;
243 virtual void* GetOrInsertFunction(const std::string& name, void* type, bool nothrow) = 0;
244 virtual void SetInitializer(void* global, void* initializer) = 0;
245 virtual void SetPrivateLinkage(void* global) = 0;
246 virtual bool IsVmtObjectCreated(void* symbol) const = 0;
247 virtual void SetVmtObjectCreated(void* symbol) = 0;
248 virtual bool IsStaticObjectCreated(void* symbol) const = 0;
249 virtual void SetStaticObjectCreated(void* symbol) = 0;
250 virtual void* HandlerBlock() = 0;
251 virtual void* CleanupBlock() = 0;
252 virtual bool NewCleanupNeeded() = 0;
253 virtual void CreateCleanup() = 0;
254 virtual Pad* CurrentPad() = 0;
255 virtual void* CreateCleanupPadWithParent(void* parentPad, const std::std::vector<void*>&args) = 0;
256 virtual void* CreateCleanupPad(const std::std::vector<void*>&args) = 0;
257 virtual void* CreateCleanupRet(void* cleanupPad, void* unwindTarget) = 0;
258 virtual void* CreateCatchRet(void* catchPad, void* returnTarget) = 0;
259 virtual void* CreateCatchSwitch(void* unwindBlock) = 0;
260 virtual void* CreateCatchSwitchWithParent(void* parentPad, void* unwindBlock) = 0;
261 virtual void AddHandlerToCatchSwitch(void* catchSwitch, void* target) = 0;
262 virtual void* CreateCatchPad(void* parentPad, const std::std::vector<void*>&args) = 0;
263 virtual void* CreateClassDIType(void* classPtr) = 0;
264 virtual void* CreateCall(void* callee, const std::std::vector<void*>&args) = 0;
265 virtual void* CreateCallInst(void* callee, const std::std::vector<void*>&args, conststd::std::vector<void*>&bundles, constSpan&span) = 0;
266 virtual void* CreateCallInstToBasicBlock(void* callee, const std::std::vector<void*>&args, conststd::std::vector<void*>&bundles, void*basicBlock, constSpan&span) = 0;
267 virtual void* CreateInvoke(void* callee, void* normalBlock, void* unwindBlock, const std::std::vector<void*>&args) = 0;
268 virtual void* CreateInvokeInst(void* callee, void* normalBlock, void* unwindBlock, const std::std::vector<void*>&args, conststd::std::vector<void*>&bundles, constSpan&span) = 0;
269 virtual void* DIBuilder() = 0;
270 virtual void SetCurrentDIBuilder(void* diBuilder_) = 0;
271 virtual void* GetObjectFromClassDelegate(void* classDelegatePtr) = 0;
272 virtual void* GetDelegateFromClassDelegate(void* classDelegatePtr) = 0;
273 virtual void* GetObjectFromInterface(void* interfaceTypePtr) = 0;
274 virtual void* GetObjectPtrFromInterface(void* interfaceTypePtr) = 0;
275 virtual void* GetImtPtrFromInterface(void* interfaceTypePtr) = 0;
276 virtual void* GetInterfaceMethod(void* imtPtr, int32_t methodIndex, void* interfaceMethodType) = 0;
277 virtual void* GetFunctionIrType(void* functionSymbol) const = 0;
278 virtual void SetFunctionIrType(void* symbol, void* irType) = 0;
279 virtual void* GetVmtPtr(void* thisPtr, int32_t vmtPtrIndex, void* vmtPtrType) = 0;
280 virtual void* GetMethodPtr(void* vmtPtr, int32_t vmtIndex) = 0;
281 virtual void* GetImtArray(void* vmtObjectPtr, int32_t imtsVmtIndexOffset) = 0;
282 virtual void* GetImt(void* imtArray, int32_t interfaceIndex) = 0;
283 virtual void* GetIrObject(void* symbol) const = 0;
284 virtual void SetIrObject(void* symbol, void* irObject) = 0;
285 virtual void* GetMemberVariablePtr(void* classPtr, int32_t memberVariableLayoutIndex) = 0;
286 virtual void* SizeOf(void* ptrType) = 0;
287 virtual void SetLineNumber(int32_t lineNumber) = 0;
288 virtual void SaveObjectPointer(void* objectPointer_) = 0;
289 virtual void SetObjectPointer(void* objectPointer_) = 0;
290 virtual void* GetObjectPointer() = 0;
291 virtual void* GetClassIdPtr(void* vmtPtr, int32_t classIdVmtIndexOffset) = 0;
292 virtual void* GetClassName(void* vmtPtr, int32_t classNameVmtIndexOffset) = 0;
293 virtual void* ComputeAddress(void* ptr, void* index) = 0;
294 virtual void* CreatePtrDiff(void* left, void* right) = 0;
295 virtual uint32_t GetPrivateFlag() = 0;
296 virtual uint32_t GetProtectedFlag() = 0;
297 virtual uint32_t GetPublicFlag() = 0;
298 virtual uint32_t GetNoFlags() = 0;
299 virtual void* CreateModule(const std::string& moduleName) = 0;
300 virtual void DestroyModule(void* module) = 0;
301 virtual void SetModule(void* module_) = 0;
302 virtual void SetTargetTriple(const std::string& targetTriple) = 0;
303 virtual void SetDataLayout(void* dataLayout_) = 0;
304 virtual void SetSourceFileName(const std::string& sourceFileName) = 0;
305 virtual void SetDICompileUnit(void* diCompileUnit_) = 0;
306 virtual void SetDIFile(void* diFile_) = 0;
307 virtual void SetColumnSpanProvider(cmajor::common::ColumnSpanProvider* columnSpanProvider_) = 0;
308 virtual void ResetCurrentDebugLocation() = 0;
309 virtual void StartDebugInfo(const std::string& sourceFilePath, const std::string& compilerVersion, bool optimized, cmajor::common::ColumnSpanProvider* columnSpanProvider_) = 0;
310 virtual void FinalizeDebugInfo() = 0;
311 virtual void EndDebugInfo() = 0;
312 virtual void EmitIrText(const std::string& filePath) = 0;
313 virtual void EmitIrFile(const std::string& filePath) = 0;
314 virtual void Optimize(const std::string& bcFilePath, const std::string& opBCFilePath, const std::string& optimizationFlags) = 0;
315 virtual void Disassemble(const std::string& bcFilePath, const std::string& llFilePath) = 0;
316 virtual void Compile(const std::string& bcFilePath, const std::string& objectFilePath, int optimizationLevel) = 0;
317 virtual void VerifyModule() = 0;
318 virtual void EmitObjectCodeFile(const std::string& objectFilePath) = 0;
319 virtual void* CreateDebugInfoForNamespace(void* scope, const std::string& name) = 0;
320 virtual void* GetDebugInfoForFile(const Span& span, const boost::uuids::uuid& moduleId) = 0;
321 virtual void PushScope(void* scope) = 0;
322 virtual void PopScope() = 0;
323 virtual void* CurrentScope() = 0;
324 virtual uint64_t GetClassTypeSizeInBits(void* classIrType) = 0;
325 virtual uint64_t GetClassTypeAlignmentInBits(void* classIrType) = 0;
326 virtual void AddInlineFunctionAttribute(void* function) = 0;
327 virtual void SetFunctionLinkage(void* function, bool setInline) = 0;
328 virtual void SetFunctionLinkageToLinkOnceODRLinkage(void* function) = 0;
329 virtual void SetFunctionCallConventionToStdCall(void* function) = 0;
330 virtual void SetFunction(void* function_, int32_t fileIndex, const boost::uuids::uuid& sourceModuleId, const boost::uuids::uuid& functionId) = 0;
331 virtual void SetFunctionName(const std::string& functionName) = 0;
332 virtual void BeginScope() = 0;
333 virtual void EndScope() = 0;
334 virtual int16_t GetCurrentScopeId() const = 0;
335 virtual void SetCurrentScopeId(int16_t scopeId) = 0;
336 virtual int32_t AddControlFlowGraphNode() = 0;
337 virtual void SetCurrentControlFlowGraphNodeId(int32_t controlFlowGraphNodeId) = 0;
338 virtual void AddControlFlowGraphEdge(int32_t startNodeId, int32_t endNodeId) = 0;
339 virtual void AddLocalVariable(const std::string& localVariableName, const boost::uuids::uuid& typeId, void* irObject) = 0;
340 virtual void BeginInstructionFlag(int16_t flag) = 0;
341 virtual void EndInstructionFlag(int16_t flag) = 0;
342 virtual void SetInPrologue(bool inPrologue_) = 0;
343 virtual void* CreateSubroutineType(const std::std::vector<void*>&elementTypes) = 0;
344 virtual unsigned GetPureVirtualVirtuality() = 0;
345 virtual unsigned GetVirtualVirtuality() = 0;
346 virtual unsigned GetFunctionFlags(bool isStatic, unsigned accessFlags, bool isExplicit) = 0;
347 virtual void* CreateDIMethod(const std::string& name, const std::string& mangledName, const Span& span, const boost::uuids::uuid& moduleId, void* subroutineType, unsigned virtuality, unsigned vtableIndex, void* vtableHolder,
348 unsigned flags) = 0;
349 virtual void* CreateDIFunction(const std::string& name, const std::string& mangledName, const Span& span, const boost::uuids::uuid& moduleId, void* subroutineType, unsigned flags) = 0;
350 virtual void SetDISubprogram(void* function, void* subprogram) = 0;
351 virtual void* CreateAlloca(void* irType) = 0;
352 virtual void* CreateDIParameterVariable(const std::string& name, int index, const Span& span, const boost::uuids::uuid& moduleId, void* irType, void* allocaInst) = 0;
353 virtual void* CreateDIAutoVariable(const std::string& name, const Span& span, const boost::uuids::uuid& moduleId, void* irType, void* allocaInst) = 0;
354 virtual void* GetFunctionArgument(void* function, int argumentIndex) = 0;
355 virtual void SetDebugLoc(void* callInst) = 0;
356 virtual void* CreateRet(void* value) = 0;
357 virtual void* CreateRetVoid() = 0;
358 virtual void SetPersonalityFunction(void* function, void* personalityFunction) = 0;
359 virtual void AddNoUnwindAttribute(void* function) = 0;
360 virtual void AddUWTableAttribute(void* function) = 0;
361 virtual void* CreateLexicalBlock(const Span& span, const boost::uuids::uuid& moduleId) = 0;
362 virtual void* CreateSwitch(void* condition, void* defaultDest, unsigned numCases) = 0;
363 virtual void AddCase(void* switchInst, void* caseValue, void* caseDest) = 0;
364 virtual void* GenerateTrap(const std::std::vector<void*>&args) = 0;
365 virtual void SetCompileUnitId(const std::string& compileUnitId) = 0;
366 virtual void* GetClsIdValue(const std::string& typeId) = 0;
367 virtual void* CreateMDBool(bool value) = 0;
368 virtual void* CreateMDLong(int64_t value) = 0;
369 virtual void* CreateMDString(const std::string& value) = 0;
370 virtual void* CreateMDStructRef(int id) = 0;
371 virtual void* CreateMDStruct() = 0;
372 virtual void* CreateMDBasicBlockRef(void* bb) = 0;
373 virtual int GetMDStructId(void* mdStruct) = 0;
374 virtual void AddMDItem(void* mdStruct, const std::string& fieldName, void* mdItem) = 0;
375 virtual void SetFunctionMdId(void* function, int mdId) = 0;
376 virtual void* GetMDStructRefForSourceFile(const std::string& sourceFileName) = 0;
377 virtual void SetCurrentSourceSpan(int32_t lineNumber, int16_t scol, int16_t ecol) = 0;
378 virtual void SetMetadataRef(void* inst, void* mdStructRef) = 0;
379 virtual void FinalizeFunction(void* function, bool hasCleanup) = 0;
380 virtual int Install(const std::string& str) = 0;
381 virtual int Install(const std::u16string& str) = 0;
382 virtual int Install(const std::u32string& str) = 0;
383 virtual void* CreateLandingPad(void* lpType) = 0;
384 virtual void SetLandindPadAsCleanup(void* landingPad) = 0;
385 virtual void MoveAllocaIntoBasicBlock(void* allocaInst, void* lastAlloca, void* basicBlock) = 0;
386 virtual void AddClauseToLangdingPad(void* landingPad, void* exceptionTypeId) = 0;
387 virtual void* CreateExtractValue(void* aggregate, const std::std::vector<unsigned int>&indeces) = 0;
388 virtual void* CreateInsertValue(void* aggregate, void* value, const std::std::vector<unsigned int>&indeces) = 0;
389 virtual void* CreateUndefValue(void* type) = 0;
390 virtual void CreateResume(void* exception) = 0;
391 virtual void DebugPrintDebugInfo(const std::string& filePath) = 0;
392 virtual void BeginSubstituteLineNumber(int32_t lineNumber) = 0;
393 virtual void EndSubstituteLineNumber() = 0;
394 virtual void SetBoundCompileUnit(void* boundCompileUnit) = 0;
395 virtual void* GetBoundCompileUnit() const = 0;
396 private:
397 ValueStack* stack;
398 };
399
400 } }
401
402 #endif // CMAJOR_IR_EMITTER_INCLUDED