src/irgenerator/IRGenerator.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include <CompilerPass.h> | ||
| 6 | #include <ast/ASTNodes.h> | ||
| 7 | #include <ast/ParallelizableASTVisitor.h> | ||
| 8 | #include <irgenerator/DebugInfoGenerator.h> | ||
| 9 | #include <irgenerator/MetadataGenerator.h> | ||
| 10 | #include <irgenerator/OpRuleConversionManager.h> | ||
| 11 | #include <irgenerator/StdFunctionManager.h> | ||
| 12 | #include <model/StructBase.h> | ||
| 13 | #include <symboltablebuilder/Scope.h> | ||
| 14 | #include <util/DeferredLogic.h> | ||
| 15 | |||
| 16 | namespace spice::compiler { | ||
| 17 | |||
| 18 | // Forward declarations | ||
| 19 | class ExprNode; | ||
| 20 | |||
| 21 | const char *const ANON_GLOBAL_STRING_NAME = "anon.string."; | ||
| 22 | const char *const ANON_GLOBAL_ARRAY_NAME = "anon.array."; | ||
| 23 | const char *const CAPTURES_PARAM_NAME = "captures"; | ||
| 24 | static const std::string PRODUCER_STRING = | ||
| 25 | "spice version " + std::string(SPICE_VERSION) + " (https://github.com/spicelang/spice)"; | ||
| 26 | |||
| 27 | enum class Likelihood : uint8_t { | ||
| 28 | UNSPECIFIED, | ||
| 29 | LIKELY, | ||
| 30 | UNLIKELY, | ||
| 31 | }; | ||
| 32 | |||
| 33 | // Forward declarations | ||
| 34 | class SourceFile; | ||
| 35 | |||
| 36 | class IRGenerator final : CompilerPass, public ParallelizableASTVisitor { | ||
| 37 | public: | ||
| 38 | // Type definitions | ||
| 39 | using ParamInfoList = std::vector<std::pair<std::string, SymbolTableEntry *>>; | ||
| 40 | |||
| 41 | // Constructors | ||
| 42 | IRGenerator(GlobalResourceManager &resourceManager, SourceFile *sourceFile); | ||
| 43 | |||
| 44 | // Friend classes | ||
| 45 | friend class StdFunctionManager; | ||
| 46 | friend class OpRuleConversionManager; | ||
| 47 | friend class DebugInfoGenerator; | ||
| 48 | friend class MetadataGenerator; | ||
| 49 | friend class ScopeHandle; | ||
| 50 | |||
| 51 | // Visitor methods | ||
| 52 | // Top level definitions | ||
| 53 | std::any visitEntry(const EntryNode *node) override; | ||
| 54 | std::any visitMainFctDef(const MainFctDefNode *node) override; | ||
| 55 | std::any visitFctDef(const FctDefNode *node) override; | ||
| 56 | std::any visitProcDef(const ProcDefNode *node) override; | ||
| 57 | std::any visitStructDef(const StructDefNode *node) override; | ||
| 58 | std::any visitInterfaceDef(const InterfaceDefNode *node) override; | ||
| 59 | std::any visitEnumDef(const EnumDefNode *node) override; | ||
| 60 | std::any visitGenericTypeDef(const GenericTypeDefNode *node) override; | ||
| 61 | std::any visitAliasDef(const AliasDefNode *node) override; | ||
| 62 | std::any visitGlobalVarDef(const GlobalVarDefNode *node) override; | ||
| 63 | std::any visitExtDecl(const ExtDeclNode *node) override; | ||
| 64 | // Control structures | ||
| 65 | std::any visitUnsafeBlockDef(const UnsafeBlockNode *node) override; | ||
| 66 | std::any visitForLoop(const ForLoopNode *node) override; | ||
| 67 | std::any visitForeachLoop(const ForeachLoopNode *node) override; | ||
| 68 | std::any visitWhileLoop(const WhileLoopNode *node) override; | ||
| 69 | std::any visitDoWhileLoop(const DoWhileLoopNode *node) override; | ||
| 70 | std::any visitIfStmt(const IfStmtNode *node) override; | ||
| 71 | std::any visitElseStmt(const ElseStmtNode *node) override; | ||
| 72 | std::any visitSwitchStmt(const SwitchStmtNode *node) override; | ||
| 73 | std::any visitCaseBranch(const CaseBranchNode *node) override; | ||
| 74 | std::any visitDefaultBranch(const DefaultBranchNode *node) override; | ||
| 75 | std::any visitAssertStmt(const AssertStmtNode *node) override; | ||
| 76 | std::any visitAnonymousBlockStmt(const AnonymousBlockStmtNode *node) override; | ||
| 77 | // Statements | ||
| 78 | std::any visitStmtLst(const StmtLstNode *node) override; | ||
| 79 | std::any visitTypeAltsLst(const TypeAltsLstNode *node) override; | ||
| 80 | std::any visitDeclStmt(const DeclStmtNode *node) override; | ||
| 81 | std::any visitQualifierLst(const QualifierLstNode *node) override; | ||
| 82 | std::any visitModAttr(const ModAttrNode *node) override; | ||
| 83 | std::any visitTopLevelDefinitionAttr(const TopLevelDefAttrNode *node) override; | ||
| 84 | std::any visitCaseConstant(const CaseConstantNode *node) override; | ||
| 85 | std::any visitReturnStmt(const ReturnStmtNode *node) override; | ||
| 86 | std::any visitBreakStmt(const BreakStmtNode *node) override; | ||
| 87 | std::any visitContinueStmt(const ContinueStmtNode *node) override; | ||
| 88 | std::any visitFallthroughStmt(const FallthroughStmtNode *node) override; | ||
| 89 | // Expressions | ||
| 90 | std::any visitAssignExpr(const AssignExprNode *node) override; | ||
| 91 | std::any visitTernaryExpr(const TernaryExprNode *node) override; | ||
| 92 | std::any visitLogicalOrExpr(const LogicalOrExprNode *node) override; | ||
| 93 | std::any visitLogicalAndExpr(const LogicalAndExprNode *node) override; | ||
| 94 | std::any visitBitwiseOrExpr(const BitwiseOrExprNode *node) override; | ||
| 95 | std::any visitBitwiseXorExpr(const BitwiseXorExprNode *node) override; | ||
| 96 | std::any visitBitwiseAndExpr(const BitwiseAndExprNode *node) override; | ||
| 97 | std::any visitEqualityExpr(const EqualityExprNode *node) override; | ||
| 98 | std::any visitRelationalExpr(const RelationalExprNode *node) override; | ||
| 99 | std::any visitShiftExpr(const ShiftExprNode *node) override; | ||
| 100 | std::any visitAdditiveExpr(const AdditiveExprNode *node) override; | ||
| 101 | std::any visitMultiplicativeExpr(const MultiplicativeExprNode *node) override; | ||
| 102 | std::any visitCastExpr(const CastExprNode *node) override; | ||
| 103 | std::any visitPrefixUnaryExpr(const PrefixUnaryExprNode *node) override; | ||
| 104 | std::any visitPostfixUnaryExpr(const PostfixUnaryExprNode *node) override; | ||
| 105 | std::any visitAtomicExpr(const AtomicExprNode *node) override; | ||
| 106 | // Values and types | ||
| 107 | std::any visitValue(const ValueNode *node) override; | ||
| 108 | std::any visitConstant(const ConstantNode *node) override; | ||
| 109 | std::any visitFctCall(const FctCallNode *node) override; | ||
| 110 | std::any visitArrayInitialization(const ArrayInitializationNode *node) override; | ||
| 111 | std::any visitStructInstantiation(const StructInstantiationNode *node) override; | ||
| 112 | std::any visitLambdaFunc(const LambdaFuncNode *node) override; | ||
| 113 | std::any visitLambdaProc(const LambdaProcNode *node) override; | ||
| 114 | std::any visitLambdaExpr(const LambdaExprNode *node) override; | ||
| 115 | std::any visitDataType(const DataTypeNode *node) override; | ||
| 116 | |||
| 117 | // Public methods | ||
| 118 |
20/44✓ Branch 9 → 10 taken 139 times.
✗ Branch 9 → 62 not taken.
✓ Branch 12 → 13 taken 212 times.
✗ Branch 12 → 66 not taken.
✓ Branch 14 → 15 taken 991 times.
✗ Branch 14 → 90 not taken.
✓ Branch 16 → 17 taken 212 times.
✗ Branch 16 → 89 not taken.
✓ Branch 19 → 20 taken 991 times.
✗ Branch 19 → 117 not taken.
✓ Branch 25 → 26 taken 1620 times.
✗ Branch 25 → 250 not taken.
✓ Branch 28 → 29 taken 1 time.
✗ Branch 28 → 97 not taken.
✓ Branch 35 → 36 taken 1686 times.
✗ Branch 35 → 80 not taken.
✓ Branch 39 → 40 taken 1686 times.
✗ Branch 39 → 89 not taken.
✓ Branch 43 → 44 taken 1 time.
✗ Branch 43 → 104 not taken.
✓ Branch 68 → 69 taken 2 times.
✗ Branch 68 → 127 not taken.
✓ Branch 78 → 79 taken 1203 times.
✗ Branch 78 → 143 not taken.
✓ Branch 84 → 85 taken 7935 times.
✗ Branch 84 → 417 not taken.
✓ Branch 88 → 89 taken 7935 times.
✗ Branch 88 → 536 not taken.
✗ Branch 89 → 90 not taken.
✗ Branch 89 → 120 not taken.
✗ Branch 94 → 95 not taken.
✗ Branch 94 → 124 not taken.
✓ Branch 98 → 99 taken 254 times.
✗ Branch 98 → 129 not taken.
✓ Branch 103 → 104 taken 254 times.
✗ Branch 103 → 133 not taken.
✓ Branch 113 → 114 taken 2 times.
✗ Branch 113 → 223 not taken.
✓ Branch 137 → 138 taken 2 times.
✗ Branch 137 → 230 not taken.
✓ Branch 374 → 375 taken 686 times.
✗ Branch 374 → 527 not taken.
✓ Branch 379 → 380 taken 686 times.
✗ Branch 379 → 534 not taken.
|
44202 | llvm::AllocaInst *insertAlloca(llvm::Type *llvmType, const std::string &varName = ""); |
| 119 |
3/13✓ Branch 46 → 47 taken 2 times.
✗ Branch 46 → 159 not taken.
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 82 not taken.
✓ Branch 75 → 76 taken 16948 times.
✗ Branch 75 → 172 not taken.
✗ Branch 75 → 262 not taken.
✓ Branch 108 → 109 taken 6 times.
✗ Branch 108 → 186 not taken.
✗ Branch 134 → 135 not taken.
✗ Branch 134 → 200 not taken.
✗ Branch 139 → 140 not taken.
✗ Branch 139 → 204 not taken.
|
50868 | llvm::AllocaInst *insertAlloca(const QualType &qualType, const std::string &varName = ""); |
| 120 | llvm::LoadInst *insertLoad(llvm::Type *llvmType, llvm::Value *ptr, bool isVolatile = false, | ||
| 121 |
25/57✓ Branch 12 → 13 taken 12580 times.
✗ Branch 12 → 37 not taken.
✓ Branch 18 → 19 taken 1519 times.
✗ Branch 18 → 36 not taken.
✗ Branch 18 → 97 not taken.
✓ Branch 21 → 22 taken 139 times.
✗ Branch 21 → 75 not taken.
✓ Branch 24 → 25 taken 12 times.
✗ Branch 24 → 54 not taken.
✓ Branch 28 → 29 taken 1864 times.
✗ Branch 28 → 58 not taken.
✗ Branch 28 → 136 not taken.
✓ Branch 30 → 31 taken 2078 times.
✗ Branch 30 → 106 not taken.
✓ Branch 33 → 34 taken 1223 times.
✗ Branch 33 → 147 not taken.
✓ Branch 46 → 47 taken 37 times.
✗ Branch 46 → 87 not taken.
✗ Branch 46 → 109 not taken.
✓ Branch 51 → 52 taken 274 times.
✗ Branch 51 → 256 not taken.
✓ Branch 53 → 54 taken 81 times.
✗ Branch 53 → 116 not taken.
✓ Branch 55 → 56 taken 283 times.
✗ Branch 55 → 92 not taken.
✓ Branch 73 → 74 taken 2088 times.
✗ Branch 73 → 142 not taken.
✓ Branch 76 → 77 taken 67 times.
✗ Branch 76 → 176 not taken.
✓ Branch 77 → 78 taken 2088 times.
✗ Branch 77 → 155 not taken.
✓ Branch 82 → 83 taken 291 times.
✗ Branch 82 → 159 not taken.
✗ Branch 82 → 160 not taken.
✓ Branch 97 → 98 taken 36 times.
✗ Branch 97 → 189 not taken.
✓ Branch 101 → 102 taken 3 times.
✗ Branch 101 → 172 not taken.
✓ Branch 104 → 105 taken 2440 times.
✗ Branch 104 → 174 not taken.
✓ Branch 121 → 122 taken 8 times.
✗ Branch 121 → 166 not taken.
✓ Branch 130 → 131 taken 327 times.
✗ Branch 130 → 197 not taken.
✓ Branch 136 → 137 taken 327 times.
✗ Branch 136 → 202 not taken.
✗ Branch 136 → 221 not taken.
✗ Branch 141 → 142 not taken.
✗ Branch 141 → 227 not taken.
✓ Branch 166 → 167 taken 47 times.
✗ Branch 166 → 459 not taken.
✓ Branch 170 → 171 taken 47 times.
✗ Branch 170 → 463 not taken.
✓ Branch 200 → 201 taken 886 times.
✗ Branch 200 → 306 not taken.
✓ Branch 205 → 206 taken 886 times.
✗ Branch 205 → 310 not taken.
|
75180 | const std::string &varName = "") const; |
| 122 | llvm::LoadInst *insertLoad(const QualType &qualType, llvm::Value *ptr, bool isVolatile = false, | ||
| 123 |
3/14✓ Branch 5 → 6 taken 55760 times.
✗ Branch 5 → 21 not taken.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 59 not taken.
✓ Branch 9 → 10 taken 55760 times.
✗ Branch 9 → 25 not taken.
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 63 not taken.
✓ Branch 27 → 28 taken 113502 times.
✗ Branch 27 → 42 not taken.
✗ Branch 37 → 38 not taken.
✗ Branch 37 → 75 not taken.
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 79 not taken.
|
507786 | const std::string &varName = ""); |
| 124 | llvm::StoreInst *insertStore(llvm::Value *val, llvm::Value *ptr, bool isVolatile = false) const; | ||
| 125 | void insertStore(llvm::Value *val, llvm::Value *ptr, const QualType &qualType, bool isVolatile = false); | ||
| 126 | llvm::Value *insertInBoundsGEP(llvm::Type *type, llvm::Value *basePtr, llvm::ArrayRef<llvm::Value *> indices, | ||
| 127 |
8/19✓ Branch 28 → 29 taken 227 times.
✗ Branch 28 → 68 not taken.
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 101 not taken.
✓ Branch 38 → 39 taken 1223 times.
✗ Branch 38 → 143 not taken.
✓ Branch 43 → 44 taken 1400 times.
✗ Branch 43 → 147 not taken.
✗ Branch 43 → 192 not taken.
✓ Branch 54 → 55 taken 5557 times.
✗ Branch 54 → 201 not taken.
✓ Branch 74 → 75 taken 2 times.
✗ Branch 74 → 135 not taken.
✓ Branch 86 → 87 taken 3 times.
✗ Branch 86 → 143 not taken.
✓ Branch 100 → 101 taken 2 times.
✗ Branch 100 → 269 not taken.
✓ Branch 105 → 106 taken 2 times.
✗ Branch 105 → 273 not taken.
|
21573 | const std::string &varName = "") const; |
| 128 |
22/47✓ Branch 36 → 37 taken 641 times.
✗ Branch 36 → 64 not taken.
✓ Branch 37 → 38 taken 312 times.
✗ Branch 37 → 125 not taken.
✗ Branch 37 → 148 not taken.
✓ Branch 47 → 48 taken 81 times.
✗ Branch 47 → 110 not taken.
✓ Branch 53 → 54 taken 33 times.
✗ Branch 53 → 115 not taken.
✓ Branch 57 → 58 taken 33 times.
✗ Branch 57 → 119 not taken.
✓ Branch 63 → 64 taken 7528 times.
✗ Branch 63 → 98 not taken.
✗ Branch 63 → 406 not taken.
✓ Branch 67 → 68 taken 9328 times.
✗ Branch 67 → 136 not taken.
✗ Branch 67 → 411 not taken.
✓ Branch 76 → 77 taken 65 times.
✗ Branch 76 → 130 not taken.
✓ Branch 83 → 84 taken 65 times.
✗ Branch 83 → 136 not taken.
✓ Branch 84 → 85 taken 197 times.
✗ Branch 84 → 182 not taken.
✓ Branch 87 → 88 taken 36 times.
✓ Branch 87 → 91 taken 29 times.
✗ Branch 89 → 90 not taken.
✗ Branch 89 → 149 not taken.
✓ Branch 90 → 91 taken 1289 times.
✗ Branch 90 → 165 not taken.
✗ Branch 90 → 166 not taken.
✗ Branch 93 → 94 not taken.
✗ Branch 93 → 160 not taken.
✓ Branch 98 → 99 taken 62 times.
✗ Branch 98 → 425 not taken.
✓ Branch 102 → 103 taken 62 times.
✗ Branch 102 → 536 not taken.
✓ Branch 107 → 108 taken 1351 times.
✗ Branch 107 → 155 not taken.
✗ Branch 107 → 431 not taken.
✓ Branch 111 → 112 taken 368 times.
✓ Branch 111 → 114 taken 967 times.
✓ Branch 112 → 113 taken 8136 times.
✗ Branch 112 → 180 not taken.
✓ Branch 114 → 115 taken 8 times.
✗ Branch 114 → 160 not taken.
✓ Branch 116 → 117 taken 1915 times.
✓ Branch 116 → 119 taken 6221 times.
|
65568 | llvm::Value *insertStructGEP(llvm::Type *type, llvm::Value *basePtr, unsigned index, const std::string &varName = "") const; |
| 129 | llvm::Value *resolveValue(const ExprNode *node); | ||
| 130 | llvm::Value *resolveValue(const ExprNode *node, LLVMExprResult &exprResult); | ||
| 131 | llvm::Value *resolveValue(const QualType &qualType, LLVMExprResult &exprResult); | ||
| 132 | llvm::Value *resolveAddress(const ASTNode *node); | ||
| 133 | llvm::Value *resolveAddress(LLVMExprResult &exprResult); | ||
| 134 | [[nodiscard]] llvm::Constant *getDefaultValueForSymbolType(const QualType &symbolType); | ||
| 135 | [[nodiscard]] static std::string getIRString(llvm::Module *llvmModule, const CliOptions &cliOptions); | ||
| 136 | |||
| 137 | // Builtin function handlers | ||
| 138 | std::any visitBuiltinCall(const FctCallNode *node); | ||
| 139 | std::any visitBuiltinPrintfCall(const FctCallNode *node); | ||
| 140 | std::any visitBuiltinLenCall(const FctCallNode *node); | ||
| 141 | std::any visitBuiltinPanicCall(const FctCallNode *node); | ||
| 142 | std::any visitBuiltinSyscallCall(const FctCallNode *node); | ||
| 143 | std::any visitBuiltinNewCall(const FctCallNode *node); | ||
| 144 | std::any visitBuiltinPlacementNewCall(const FctCallNode *node); | ||
| 145 | |||
| 146 | private: | ||
| 147 | // Private methods | ||
| 148 | llvm::Constant *getConst(const CompileTimeValue &compileTimeValue, const QualType &type, const ASTNode *node) const; | ||
| 149 |
12/28✓ Branch 60 → 61 taken 50 times.
✗ Branch 60 → 147 not taken.
✗ Branch 60 → 154 not taken.
✗ Branch 60 → 184 not taken.
✓ Branch 64 → 65 taken 50 times.
✗ Branch 64 → 165 not taken.
✗ Branch 64 → 173 not taken.
✗ Branch 64 → 227 not taken.
✓ Branch 71 → 72 taken 338 times.
✗ Branch 71 → 162 not taken.
✓ Branch 75 → 76 taken 338 times.
✗ Branch 75 → 202 not taken.
✓ Branch 91 → 92 taken 4 times.
✗ Branch 91 → 148 not taken.
✓ Branch 92 → 93 taken 839 times.
✗ Branch 92 → 147 not taken.
✓ Branch 95 → 96 taken 4 times.
✗ Branch 95 → 164 not taken.
✓ Branch 96 → 97 taken 839 times.
✗ Branch 96 → 163 not taken.
✓ Branch 111 → 112 taken 10172 times.
✗ Branch 111 → 206 not taken.
✓ Branch 115 → 116 taken 10172 times.
✗ Branch 115 → 223 not taken.
✓ Branch 133 → 134 taken 19442 times.
✗ Branch 133 → 269 not taken.
✓ Branch 137 → 138 taken 19442 times.
✗ Branch 137 → 310 not taken.
|
92535 | llvm::BasicBlock *createBlock(const std::string &blockName = "") const; |
| 150 | void switchToBlock(llvm::BasicBlock *block, llvm::Function *parentFct = nullptr); | ||
| 151 | void terminateBlock(const StmtLstNode *stmtLstNode); | ||
| 152 | void insertJump(llvm::BasicBlock *targetBlock); | ||
| 153 | void insertCondJump(llvm::Value *condition, llvm::BasicBlock *trueBlock, llvm::BasicBlock *falseBlock, | ||
| 154 | Likelihood likelihood = Likelihood::UNSPECIFIED); | ||
| 155 | void verifyFunction(const llvm::Function *fct, const CodeLoc &codeLoc) const; | ||
| 156 | void verifyModule(const CodeLoc &codeLoc) const; | ||
| 157 | LLVMExprResult doAssignment(const ASTNode *lhsNode, const ExprNode *rhsNode, const ASTNode *node); | ||
| 158 | LLVMExprResult doAssignment(llvm::Value *lhsAddress, SymbolTableEntry *lhsEntry, const ExprNode *rhsNode, const ASTNode *node, | ||
| 159 | bool isDecl = false); | ||
| 160 | LLVMExprResult doAssignment(llvm::Value *lhsAddress, SymbolTableEntry *lhsEntry, LLVMExprResult &rhs, const QualType &rhsSType, | ||
| 161 | const ASTNode *node, bool isDecl); | ||
| 162 | void generateShallowCopy(llvm::Value *oldAddress, llvm::Type *varType, llvm::Value *targetAddress, bool isVolatile) const; | ||
| 163 | void autoDeReferencePtr(llvm::Value *&ptr, QualType &symbolType); | ||
| 164 | llvm::GlobalVariable *createGlobalConst(const std::string &baseName, llvm::Constant *constant) const; | ||
| 165 | llvm::GlobalVariable *createGlobalStringConst(const std::string &baseName, const std::string &value) const; | ||
| 166 | llvm::GlobalVariable *createGlobalStringConst(const std::string &baseName, const std::string &value, | ||
| 167 | const CodeLoc &codeLoc) const; | ||
| 168 | [[nodiscard]] std::string getUnusedGlobalName(const std::string &baseName) const; | ||
| 169 | static void materializeConstant(LLVMExprResult &exprResult); | ||
| 170 | const std::vector<const Function *> &getOpFctPointers(const ASTNode *node) const; | ||
| 171 | llvm::Value *buildFatFctPtr(Scope *bodyScope, llvm::Type *capturesStructType, llvm::Value *lambda); | ||
| 172 | llvm::Type *buildCapturesContainerType(const CaptureMap &captures) const; | ||
| 173 | void unpackCapturesToLocalVariables(const CaptureMap &captures, llvm::Value *val, llvm::Type *structType); | ||
| 174 | void setParamAttrs(llvm::Function *function, const ParamInfoList ¶mInfo) const; | ||
| 175 | void setFunctionReturnValAttrs(llvm::Function *function, const QualType &returnType) const; | ||
| 176 | void setCallArgAttrs(llvm::CallInst *callInst, const Function *spiceFunc, const QualTypeList ¶mSTypes) const; | ||
| 177 | void setCallReturnValAttrs(llvm::CallInst *callInst, const QualType &returnType) const; | ||
| 178 | llvm::Attribute::AttrKind getExtAttrKindForType(const QualType &type) const; | ||
| 179 | bool isSymbolDSOLocal(bool isPublic) const; | ||
| 180 | llvm::GlobalValue::LinkageTypes getSymbolLinkageType(bool isPublic) const; | ||
| 181 | void attachComdatToSymbol(llvm::GlobalVariable *global, const std::string &comdatName, bool isPublic) const; | ||
| 182 | |||
| 183 | // Generate implicit | ||
| 184 | llvm::Value *doImplicitCast(llvm::Value *src, QualType dstSTy, QualType srcSTy); | ||
| 185 | void generateScopeCleanup(const StmtLstNode *node) const; | ||
| 186 | void generateFctDecl(const Function *fct, const std::vector<llvm::Value *> &args) const; | ||
| 187 | llvm::CallInst *generateFctCall(const Function *fct, const std::vector<llvm::Value *> &args) const; | ||
| 188 | llvm::Value *generateFctDeclAndCall(const Function *fct, const std::vector<llvm::Value *> &args) const; | ||
| 189 | void generateProcDeclAndCall(const Function *proc, const std::vector<llvm::Value *> &args) const; | ||
| 190 | void generateCtorOrDtorCall(const SymbolTableEntry *entry, const Function *ctorOrDtor, | ||
| 191 | const std::vector<llvm::Value *> &args) const; | ||
| 192 | void generateCtorOrDtorCall(llvm::Value *structAddr, const Function *ctorOrDtor, const std::vector<llvm::Value *> &args) const; | ||
| 193 | void generateDeallocCall(llvm::Value *variableAddress) const; | ||
| 194 | llvm::Function *generateImplicitFunction(const std::function<void(void)> &generateBody, const Function *spiceFunc); | ||
| 195 | llvm::Function *generateImplicitProcedure(const std::function<void(void)> &generateBody, const Function *spiceProc); | ||
| 196 | void generateCtorBodyPreamble(Scope *bodyScope); | ||
| 197 | void generateDefaultCtor(const Function *ctorFunction); | ||
| 198 | void generateCopyCtorBodyPreamble(const Function *copyCtorFunction); | ||
| 199 | void generateDefaultCopyCtor(const Function *copyCtorFunction); | ||
| 200 | void generateMoveCtorBodyPreamble(const Function *moveCtorFunction); | ||
| 201 | void generateDefaultMoveCtor(const Function *moveCtorFunction); | ||
| 202 | void generateDtorBodyPreamble(const Function *dtorFunction) const; | ||
| 203 | void generateDefaultDtor(const Function *dtorFunction); | ||
| 204 | void generateTestMain(); | ||
| 205 | |||
| 206 | // Generate target dependent | ||
| 207 | std::string getSysCallAsmString(uint8_t numRegs) const; | ||
| 208 | std::string getSysCallConstraintString(uint8_t numRegs) const; | ||
| 209 | |||
| 210 | // Generate VTable | ||
| 211 | llvm::Constant *generateTypeInfoName(StructBase *spiceStruct) const; | ||
| 212 | llvm::Constant *generateTypeInfo(StructBase *spiceStruct) const; | ||
| 213 | llvm::Constant *generateVTable(StructBase *spiceStruct) const; | ||
| 214 | void generateVTableInitializer(const StructBase *spiceStruct) const; | ||
| 215 | |||
| 216 | // Generate code instrumentation | ||
| 217 | void enableFunctionInstrumentation(llvm::Function *function) const; | ||
| 218 | |||
| 219 | // Private members | ||
| 220 | llvm::LLVMContext &context; | ||
| 221 | llvm::IRBuilder<> &builder; | ||
| 222 | llvm::Module *module; | ||
| 223 | OpRuleConversionManager conversionManager; | ||
| 224 | const StdFunctionManager stdFunctionManager; | ||
| 225 | DebugInfoGenerator diGenerator = DebugInfoGenerator(this); | ||
| 226 | MetadataGenerator mdGenerator = MetadataGenerator(this); | ||
| 227 | struct CommonLLVMTypes { | ||
| 228 | llvm::StructType *fatPtrType = nullptr; | ||
| 229 | } llvmTypes; | ||
| 230 | std::vector<llvm::BasicBlock *> breakBlocks; | ||
| 231 | std::vector<llvm::BasicBlock *> continueBlocks; | ||
| 232 | std::stack<llvm::BasicBlock *> fallthroughBlocks; | ||
| 233 | llvm::BasicBlock *allocaInsertBlock = nullptr; | ||
| 234 | llvm::AllocaInst *allocaInsertInst = nullptr; | ||
| 235 | bool blockAlreadyTerminated = false; | ||
| 236 | bool isInCtorBody = false; | ||
| 237 | std::vector<DeferredLogic> deferredVTableInitializations; | ||
| 238 | }; | ||
| 239 | |||
| 240 | } // namespace spice::compiler | ||
| 241 |