src/irgenerator/GenTopLevelDefinitions.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "IRGenerator.h" | ||
| 4 | |||
| 5 | #include <SourceFile.h> | ||
| 6 | #include <ast/ASTNodes.h> | ||
| 7 | #include <ast/Attributes.h> | ||
| 8 | #include <driver/Driver.h> | ||
| 9 | #include <symboltablebuilder/SymbolTableBuilder.h> | ||
| 10 | #include <typechecker/FunctionManager.h> | ||
| 11 | |||
| 12 | #include <llvm/IR/Module.h> | ||
| 13 | #include <llvm/Target/TargetLoweringObjectFile.h> | ||
| 14 | |||
| 15 | namespace spice::compiler { | ||
| 16 | |||
| 17 | 272 | std::any IRGenerator::visitMainFctDef(const MainFctDefNode *node) { | |
| 18 | // Ignore main function definitions if this is not the main source file | ||
| 19 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 6 taken 272 times.
|
272 | if (!sourceFile->isMainFile) |
| 20 | ✗ | return nullptr; | |
| 21 | |||
| 22 | // Do not generate main function if it is explicitly specified | ||
| 23 |
2/2✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 10 taken 271 times.
|
272 | if (cliOptions.noEntryFct) |
| 24 |
1/2✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 149 not taken.
|
2 | return nullptr; |
| 25 | |||
| 26 | // Change scope to function scope | ||
| 27 | 271 | currentScope = node->bodyScope; | |
| 28 |
1/2✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 271 times.
|
271 | assert(currentScope != nullptr); |
| 29 | |||
| 30 | // Visit parameters | ||
| 31 | 271 | std::vector<std::pair<std::string, SymbolTableEntry *>> paramInfoList; | |
| 32 | 271 | QualTypeList paramSymbolTypes; | |
| 33 | 271 | std::vector<llvm::Type *> paramTypes; | |
| 34 |
2/2✓ Branch 12 → 13 taken 6 times.
✓ Branch 12 → 44 taken 265 times.
|
271 | if (node->takesArgs) { |
| 35 | 6 | const size_t numOfParams = node->paramLst->params.size(); | |
| 36 |
1/2✓ Branch 14 → 15 taken 6 times.
✗ Branch 14 → 202 not taken.
|
6 | paramInfoList.reserve(numOfParams); |
| 37 |
1/2✓ Branch 15 → 16 taken 6 times.
✗ Branch 15 → 202 not taken.
|
6 | paramSymbolTypes.reserve(numOfParams); |
| 38 |
1/2✓ Branch 16 → 17 taken 6 times.
✗ Branch 16 → 202 not taken.
|
6 | paramTypes.reserve(numOfParams); |
| 39 |
2/2✓ Branch 42 → 19 taken 12 times.
✓ Branch 42 → 43 taken 6 times.
|
24 | for (DeclStmtNode *param : node->paramLst->params) { |
| 40 | // Get symbol table entry of param | ||
| 41 |
1/2✓ Branch 21 → 22 taken 12 times.
✗ Branch 21 → 153 not taken.
|
12 | SymbolTableEntry *paramSymbol = node->bodyScope->lookupStrict(param->varName); |
| 42 |
1/2✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 12 times.
|
12 | assert(paramSymbol != nullptr); |
| 43 | // Retrieve type of param | ||
| 44 |
2/4✓ Branch 26 → 27 taken 12 times.
✗ Branch 26 → 152 not taken.
✓ Branch 27 → 28 taken 12 times.
✗ Branch 27 → 150 not taken.
|
12 | auto paramType = any_cast<llvm::Type *>(visit(param->dataType)); |
| 45 | // Add it to the lists | ||
| 46 |
1/2✓ Branch 29 → 30 taken 12 times.
✗ Branch 29 → 153 not taken.
|
12 | paramInfoList.emplace_back(param->varName, paramSymbol); |
| 47 |
2/4✓ Branch 30 → 31 taken 12 times.
✗ Branch 30 → 153 not taken.
✓ Branch 31 → 32 taken 12 times.
✗ Branch 31 → 153 not taken.
|
12 | paramSymbolTypes.push_back(paramSymbol->getQualType()); |
| 48 |
1/2✓ Branch 32 → 33 taken 12 times.
✗ Branch 32 → 153 not taken.
|
12 | paramTypes.push_back(paramType); |
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | // Build the function | ||
| 53 |
1/2✓ Branch 44 → 45 taken 271 times.
✗ Branch 44 → 202 not taken.
|
271 | llvm::Type *returnType = builder.getInt32Ty(); |
| 54 |
1/2✓ Branch 46 → 47 taken 271 times.
✗ Branch 46 → 155 not taken.
|
271 | llvm::FunctionType *fctType = llvm::FunctionType::get(returnType, paramTypes, false); |
| 55 |
2/4✓ Branch 47 → 48 taken 271 times.
✗ Branch 47 → 156 not taken.
✓ Branch 48 → 49 taken 271 times.
✗ Branch 48 → 156 not taken.
|
271 | llvm::Function *fct = llvm::Function::Create(fctType, llvm::Function::ExternalLinkage, MAIN_FUNCTION_NAME, module); |
| 56 | 271 | fct->setDSOLocal(true); | |
| 57 | |||
| 58 | // Add function attributes | ||
| 59 |
1/2✓ Branch 50 → 51 taken 271 times.
✗ Branch 50 → 202 not taken.
|
271 | fct->addFnAttr(llvm::Attribute::MustProgress); |
| 60 |
1/2✓ Branch 51 → 52 taken 271 times.
✗ Branch 51 → 202 not taken.
|
271 | fct->addFnAttr(llvm::Attribute::NoInline); |
| 61 |
1/2✓ Branch 52 → 53 taken 271 times.
✗ Branch 52 → 202 not taken.
|
271 | fct->addFnAttr(llvm::Attribute::NoRecurse); |
| 62 |
1/2✓ Branch 53 → 54 taken 271 times.
✗ Branch 53 → 202 not taken.
|
271 | fct->addFnAttr(llvm::Attribute::NoUnwind); |
| 63 |
1/2✓ Branch 54 → 55 taken 271 times.
✗ Branch 54 → 56 not taken.
|
271 | if (cliOptions.optLevel == OptLevel::O0) |
| 64 |
1/2✓ Branch 55 → 58 taken 271 times.
✗ Branch 55 → 202 not taken.
|
271 | fct->addFnAttr(llvm::Attribute::OptimizeNone); |
| 65 | ✗ | else if (cliOptions.optLevel >= OptLevel::Os) | |
| 66 | ✗ | fct->addFnAttr(llvm::Attribute::OptimizeForSize); | |
| 67 |
2/4✓ Branch 58 → 59 taken 271 times.
✗ Branch 58 → 202 not taken.
✓ Branch 59 → 60 taken 271 times.
✗ Branch 59 → 202 not taken.
|
271 | fct->addFnAttr(llvm::Attribute::getWithUWTableKind(context, llvm::UWTableKind::Default)); |
| 68 |
1/2✓ Branch 60 → 61 taken 271 times.
✗ Branch 60 → 202 not taken.
|
271 | enableFunctionInstrumentation(fct); |
| 69 | |||
| 70 | // Add return value attributes | ||
| 71 |
1/2✓ Branch 61 → 62 taken 271 times.
✗ Branch 61 → 202 not taken.
|
271 | fct->addRetAttr(llvm::Attribute::NoUndef); |
| 72 | |||
| 73 | // Add return value attributes | ||
| 74 |
1/2✓ Branch 62 → 63 taken 271 times.
✗ Branch 62 → 202 not taken.
|
271 | fct->addRetAttr(llvm::Attribute::NoUndef); |
| 75 | |||
| 76 | // Add debug info | ||
| 77 |
2/2✓ Branch 63 → 64 taken 6 times.
✓ Branch 63 → 69 taken 265 times.
|
271 | if (cliOptions.instrumentation.generateDebugInfo) { |
| 78 | 6 | const auto nonConstNode = const_cast<MainFctDefNode *>(node); | |
| 79 |
1/2✓ Branch 64 → 65 taken 6 times.
✗ Branch 64 → 159 not taken.
|
6 | const Function spiceFunc = FunctionManager::createMainFunction(node->entry, paramSymbolTypes, nonConstNode); |
| 80 |
1/2✓ Branch 65 → 66 taken 6 times.
✗ Branch 65 → 157 not taken.
|
6 | diGenerator.generateFunctionDebugInfo(fct, &spiceFunc); |
| 81 |
1/2✓ Branch 66 → 67 taken 6 times.
✗ Branch 66 → 157 not taken.
|
6 | diGenerator.setSourceLocation(node); |
| 82 | 6 | } | |
| 83 | |||
| 84 | // Create entry block | ||
| 85 |
1/2✓ Branch 72 → 73 taken 271 times.
✗ Branch 72 → 160 not taken.
|
271 | llvm::BasicBlock *bEntry = createBlock(); |
| 86 |
1/2✓ Branch 75 → 76 taken 271 times.
✗ Branch 75 → 202 not taken.
|
271 | switchToBlock(bEntry, fct); |
| 87 | |||
| 88 | // Reset alloca insert markers to this block | ||
| 89 | 271 | allocaInsertBlock = bEntry; | |
| 90 | 271 | allocaInsertInst = nullptr; | |
| 91 | |||
| 92 | // Allocate result variable | ||
| 93 |
3/6✓ Branch 78 → 79 taken 271 times.
✗ Branch 78 → 169 not taken.
✓ Branch 79 → 80 taken 271 times.
✗ Branch 79 → 166 not taken.
✓ Branch 80 → 81 taken 271 times.
✗ Branch 80 → 166 not taken.
|
271 | llvm::Value *resultAddress = insertAlloca(QualType(TY_INT), RETURN_VARIABLE_NAME); |
| 94 | // Update the symbol table entry | ||
| 95 |
1/2✓ Branch 85 → 86 taken 271 times.
✗ Branch 85 → 175 not taken.
|
813 | SymbolTableEntry *resultEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME); |
| 96 |
1/2✗ Branch 91 → 92 not taken.
✓ Branch 91 → 93 taken 271 times.
|
271 | assert(resultEntry != nullptr); |
| 97 |
1/2✓ Branch 93 → 94 taken 271 times.
✗ Branch 93 → 202 not taken.
|
271 | resultEntry->updateAddress(resultAddress); |
| 98 | // Generate debug info | ||
| 99 |
2/4✓ Branch 96 → 97 taken 271 times.
✗ Branch 96 → 181 not taken.
✓ Branch 97 → 98 taken 271 times.
✗ Branch 97 → 179 not taken.
|
542 | diGenerator.generateLocalVarDebugInfo(RETURN_VARIABLE_NAME, resultAddress); |
| 100 | // Store the default result value | ||
| 101 |
3/6✓ Branch 100 → 101 taken 271 times.
✗ Branch 100 → 185 not taken.
✓ Branch 101 → 102 taken 271 times.
✗ Branch 101 → 185 not taken.
✓ Branch 102 → 103 taken 271 times.
✗ Branch 102 → 185 not taken.
|
271 | insertStore(builder.getInt32(0), resultAddress, QualType(TY_INT)); |
| 102 | |||
| 103 | // Store function argument values | ||
| 104 |
3/4✓ Branch 103 → 104 taken 271 times.
✗ Branch 103 → 193 not taken.
✓ Branch 124 → 106 taken 12 times.
✓ Branch 124 → 125 taken 271 times.
|
283 | for (auto &arg : fct->args()) { |
| 105 | // Get information about the parameter | ||
| 106 | 12 | const size_t argNumber = arg.getArgNo(); | |
| 107 |
2/4✓ Branch 107 → 108 taken 12 times.
✗ Branch 107 → 186 not taken.
✓ Branch 108 → 109 taken 12 times.
✗ Branch 108 → 186 not taken.
|
12 | auto [paramName, paramSymbol] = paramInfoList.at(argNumber); |
| 108 |
1/2✗ Branch 111 → 112 not taken.
✓ Branch 111 → 113 taken 12 times.
|
12 | assert(paramSymbol != nullptr); |
| 109 | // Allocate space for it | ||
| 110 |
2/4✓ Branch 113 → 114 taken 12 times.
✗ Branch 113 → 186 not taken.
✓ Branch 114 → 115 taken 12 times.
✗ Branch 114 → 186 not taken.
|
12 | llvm::Value *paramAddress = insertAlloca(paramSymbol->getQualType(), paramName); |
| 111 | // Update the symbol table entry | ||
| 112 |
1/2✓ Branch 115 → 116 taken 12 times.
✗ Branch 115 → 186 not taken.
|
12 | paramSymbol->updateAddress(paramAddress); |
| 113 | // Store the value at the new address | ||
| 114 |
1/2✓ Branch 116 → 117 taken 12 times.
✗ Branch 116 → 186 not taken.
|
12 | insertStore(&arg, paramAddress); |
| 115 | // Generate debug info | ||
| 116 |
1/2✓ Branch 117 → 118 taken 12 times.
✗ Branch 117 → 186 not taken.
|
12 | diGenerator.generateLocalVarDebugInfo(paramName, paramAddress, argNumber + 1); |
| 117 |
1/4✗ Branch 118 → 119 not taken.
✓ Branch 118 → 120 taken 12 times.
✗ Branch 186 → 187 not taken.
✗ Branch 186 → 188 not taken.
|
24 | } |
| 118 | |||
| 119 | // Visit function body | ||
| 120 |
1/2✓ Branch 125 → 126 taken 271 times.
✗ Branch 125 → 194 not taken.
|
271 | visit(node->body); |
| 121 | |||
| 122 | // Create return statement if the block is not terminated yet | ||
| 123 |
2/2✓ Branch 127 → 128 taken 265 times.
✓ Branch 127 → 137 taken 6 times.
|
271 | if (!blockAlreadyTerminated) { |
| 124 |
3/6✓ Branch 131 → 132 taken 265 times.
✗ Branch 131 → 195 not taken.
✓ Branch 132 → 133 taken 265 times.
✗ Branch 132 → 195 not taken.
✓ Branch 133 → 134 taken 265 times.
✗ Branch 133 → 195 not taken.
|
265 | llvm::Value *result = insertLoad(fct->getReturnType(), resultEntry->getAddress()); |
| 125 |
1/2✓ Branch 136 → 137 taken 265 times.
✗ Branch 136 → 202 not taken.
|
265 | builder.CreateRet(result); |
| 126 | } | ||
| 127 | |||
| 128 | // Conclude debug info for function | ||
| 129 |
1/2✓ Branch 137 → 138 taken 271 times.
✗ Branch 137 → 202 not taken.
|
271 | diGenerator.concludeFunctionDebugInfo(); |
| 130 | |||
| 131 | // Verify function | ||
| 132 |
1/2✓ Branch 138 → 139 taken 271 times.
✗ Branch 138 → 202 not taken.
|
271 | verifyFunction(fct, node->codeLoc); |
| 133 | |||
| 134 | // Change back to root scope | ||
| 135 | 271 | currentScope = rootScope; | |
| 136 |
1/2✗ Branch 139 → 140 not taken.
✓ Branch 139 → 141 taken 271 times.
|
271 | assert(currentScope != nullptr); |
| 137 | |||
| 138 |
1/2✓ Branch 141 → 142 taken 271 times.
✗ Branch 141 → 201 not taken.
|
271 | return nullptr; |
| 139 | 271 | } | |
| 140 | |||
| 141 | 8287 | std::any IRGenerator::visitFctDef(const FctDefNode *node) { | |
| 142 | // Loop through manifestations | ||
| 143 | 8287 | manIdx = 0; // Reset the symbolTypeIndex | |
| 144 |
2/2✓ Branch 222 → 4 taken 10320 times.
✓ Branch 222 → 223 taken 8287 times.
|
26894 | for (Function *manifestation : node->manifestations) { |
| 145 |
1/2✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 10320 times.
|
10320 | assert(manifestation->entry != nullptr); |
| 146 | |||
| 147 | // Check if the manifestation is substantiated or not public and not used by anybody | ||
| 148 |
2/4✓ Branch 8 → 9 taken 10320 times.
✗ Branch 8 → 316 not taken.
✓ Branch 9 → 10 taken 10320 times.
✗ Branch 9 → 316 not taken.
|
10320 | const bool isPublic = manifestation->entry->getQualType().isPublic(); |
| 149 |
9/10✓ Branch 10 → 11 taken 10320 times.
✗ Branch 10 → 316 not taken.
✓ Branch 11 → 12 taken 8083 times.
✓ Branch 11 → 14 taken 2237 times.
✓ Branch 12 → 13 taken 217 times.
✓ Branch 12 → 15 taken 7866 times.
✓ Branch 13 → 14 taken 10 times.
✓ Branch 13 → 15 taken 207 times.
✓ Branch 16 → 17 taken 2247 times.
✓ Branch 16 → 18 taken 8073 times.
|
10320 | if (!manifestation->isFullySubstantiated() || (!isPublic && !manifestation->used)) { |
| 150 | 2247 | manIdx++; // Increment symbolTypeIndex | |
| 151 | 2247 | continue; | |
| 152 | } | ||
| 153 | |||
| 154 | // Change to struct scope | ||
| 155 |
2/2✓ Branch 21 → 22 taken 3667 times.
✓ Branch 21 → 30 taken 4406 times.
|
8073 | if (manifestation->isMethod()) { |
| 156 | 3667 | const QualType &thisType = manifestation->thisType; | |
| 157 |
3/6✓ Branch 22 → 23 taken 3667 times.
✗ Branch 22 → 231 not taken.
✓ Branch 23 → 24 taken 3667 times.
✗ Branch 23 → 231 not taken.
✓ Branch 24 → 25 taken 3667 times.
✗ Branch 24 → 231 not taken.
|
3667 | const std::string scopeName = Struct::getScopeName(thisType.getSubType(), thisType.getTemplateTypes()); |
| 158 |
1/2✓ Branch 25 → 26 taken 3667 times.
✗ Branch 25 → 229 not taken.
|
3667 | currentScope = currentScope->getChildScope(scopeName); |
| 159 |
1/2✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 3667 times.
|
3667 | assert(currentScope != nullptr); |
| 160 | 3667 | } | |
| 161 | |||
| 162 | // Change scope | ||
| 163 |
2/4✓ Branch 30 → 31 taken 8073 times.
✗ Branch 30 → 234 not taken.
✓ Branch 31 → 32 taken 8073 times.
✗ Branch 31 → 232 not taken.
|
8073 | currentScope = currentScope->getChildScope(manifestation->getScopeName()); |
| 164 |
1/2✗ Branch 33 → 34 not taken.
✓ Branch 33 → 35 taken 8073 times.
|
8073 | assert(currentScope != nullptr); |
| 165 | |||
| 166 | // Get 'this' entry | ||
| 167 | 8073 | std::vector<std::pair<std::string, SymbolTableEntry *>> paramInfoList; | |
| 168 |
1/2✓ Branch 35 → 36 taken 8073 times.
✗ Branch 35 → 312 not taken.
|
8073 | std::vector<llvm::Type *> paramTypes; |
| 169 |
2/2✓ Branch 38 → 39 taken 3667 times.
✓ Branch 38 → 53 taken 4406 times.
|
8073 | if (manifestation->isMethod()) { |
| 170 |
1/2✓ Branch 41 → 42 taken 3667 times.
✗ Branch 41 → 237 not taken.
|
11001 | SymbolTableEntry *thisEntry = currentScope->lookupStrict(THIS_VARIABLE_NAME); |
| 171 |
1/2✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 3667 times.
|
3667 | assert(thisEntry != nullptr); |
| 172 |
1/2✓ Branch 49 → 50 taken 3667 times.
✗ Branch 49 → 242 not taken.
|
3667 | paramInfoList.emplace_back(THIS_VARIABLE_NAME, thisEntry); |
| 173 |
2/4✓ Branch 50 → 51 taken 3667 times.
✗ Branch 50 → 241 not taken.
✓ Branch 51 → 52 taken 3667 times.
✗ Branch 51 → 241 not taken.
|
3667 | paramTypes.push_back(builder.getPtrTy()); |
| 174 | } | ||
| 175 | |||
| 176 | // Visit parameters | ||
| 177 | 8073 | size_t argIdx = 0; | |
| 178 |
2/2✓ Branch 53 → 54 taken 6382 times.
✓ Branch 53 → 83 taken 1691 times.
|
8073 | if (node->hasParams) { |
| 179 | 6382 | const size_t numOfParams = manifestation->paramList.size(); | |
| 180 |
1/2✓ Branch 55 → 56 taken 6382 times.
✗ Branch 55 → 312 not taken.
|
6382 | paramInfoList.reserve(numOfParams); |
| 181 |
1/2✓ Branch 56 → 57 taken 6382 times.
✗ Branch 56 → 312 not taken.
|
6382 | paramTypes.reserve(numOfParams); |
| 182 |
2/2✓ Branch 82 → 58 taken 9595 times.
✓ Branch 82 → 83 taken 6382 times.
|
15977 | for (; argIdx < numOfParams; argIdx++) { |
| 183 |
1/2✓ Branch 58 → 59 taken 9595 times.
✗ Branch 58 → 248 not taken.
|
9595 | const DeclStmtNode *param = node->paramLst->params.at(argIdx); |
| 184 | // Get symbol table entry of param | ||
| 185 |
1/2✓ Branch 59 → 60 taken 9595 times.
✗ Branch 59 → 248 not taken.
|
9595 | SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName); |
| 186 |
1/2✗ Branch 62 → 63 not taken.
✓ Branch 62 → 64 taken 9595 times.
|
9595 | assert(paramSymbol != nullptr); |
| 187 |
2/4✓ Branch 64 → 65 taken 9595 times.
✗ Branch 64 → 245 not taken.
✓ Branch 65 → 66 taken 9595 times.
✗ Branch 65 → 243 not taken.
|
9595 | const QualType paramSymbolType = manifestation->getParamTypes().at(argIdx); |
| 188 | // Pass the information if captures are taken for function/procedure types | ||
| 189 |
6/10✓ Branch 67 → 68 taken 9595 times.
✗ Branch 67 → 246 not taken.
✓ Branch 68 → 69 taken 3 times.
✓ Branch 68 → 72 taken 9592 times.
✓ Branch 69 → 70 taken 3 times.
✗ Branch 69 → 246 not taken.
✗ Branch 70 → 71 not taken.
✓ Branch 70 → 72 taken 3 times.
✗ Branch 73 → 74 not taken.
✓ Branch 73 → 78 taken 9595 times.
|
9595 | if (paramSymbolType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && paramSymbolType.hasLambdaCaptures()) |
| 190 | ✗ | paramSymbol->updateType(paramSymbol->getQualType().getWithLambdaCaptures(), true); | |
| 191 | // Retrieve type of param | ||
| 192 |
1/2✓ Branch 78 → 79 taken 9595 times.
✗ Branch 78 → 248 not taken.
|
9595 | llvm::Type *paramType = paramSymbolType.toLLVMType(sourceFile); |
| 193 | // Add it to the lists | ||
| 194 |
1/2✓ Branch 79 → 80 taken 9595 times.
✗ Branch 79 → 248 not taken.
|
9595 | paramInfoList.emplace_back(param->varName, paramSymbol); |
| 195 |
1/2✓ Branch 80 → 81 taken 9595 times.
✗ Branch 80 → 248 not taken.
|
9595 | paramTypes.push_back(paramType); |
| 196 | } | ||
| 197 | } | ||
| 198 | |||
| 199 | // Get return type | ||
| 200 |
1/2✓ Branch 83 → 84 taken 8073 times.
✗ Branch 83 → 312 not taken.
|
8073 | llvm::Type *returnType = manifestation->returnType.toLLVMType(sourceFile); |
| 201 | |||
| 202 | // Get function linkage | ||
| 203 | 8073 | bool externalLinkage = isPublic; | |
| 204 |
12/18✓ Branch 84 → 85 taken 414 times.
✓ Branch 84 → 91 taken 7659 times.
✓ Branch 87 → 88 taken 414 times.
✗ Branch 87 → 249 not taken.
✓ Branch 88 → 89 taken 414 times.
✗ Branch 88 → 249 not taken.
✓ Branch 89 → 90 taken 12 times.
✓ Branch 89 → 91 taken 402 times.
✓ Branch 92 → 93 taken 414 times.
✓ Branch 92 → 94 taken 7659 times.
✓ Branch 94 → 95 taken 414 times.
✓ Branch 94 → 97 taken 7659 times.
✓ Branch 97 → 98 taken 12 times.
✓ Branch 97 → 105 taken 8061 times.
✗ Branch 249 → 250 not taken.
✗ Branch 249 → 251 not taken.
✗ Branch 253 → 254 not taken.
✗ Branch 253 → 256 not taken.
|
8901 | if (node->attrs && node->attrs->attrLst->hasAttr(ATTR_TEST)) |
| 205 |
2/4✓ Branch 100 → 101 taken 12 times.
✗ Branch 100 → 260 not taken.
✓ Branch 101 → 102 taken 12 times.
✗ Branch 101 → 258 not taken.
|
36 | externalLinkage |= node->attrs->attrLst->getAttrValueByName(ATTR_TEST)->boolValue; |
| 206 |
2/2✓ Branch 105 → 106 taken 7876 times.
✓ Branch 105 → 107 taken 197 times.
|
8073 | const auto linkage = externalLinkage ? llvm::Function::ExternalLinkage : llvm::Function::PrivateLinkage; |
| 207 | |||
| 208 | // Create function or implement declared function | ||
| 209 |
1/2✓ Branch 108 → 109 taken 8073 times.
✗ Branch 108 → 312 not taken.
|
8073 | const std::string mangledName = manifestation->getMangledName(); |
| 210 |
1/2✓ Branch 110 → 111 taken 8073 times.
✗ Branch 110 → 264 not taken.
|
8073 | llvm::FunctionType *funcType = llvm::FunctionType::get(returnType, paramTypes, false); |
| 211 |
1/2✓ Branch 112 → 113 taken 8073 times.
✗ Branch 112 → 265 not taken.
|
8073 | module->getOrInsertFunction(mangledName, funcType); |
| 212 |
1/2✓ Branch 114 → 115 taken 8073 times.
✗ Branch 114 → 266 not taken.
|
8073 | llvm::Function *func = module->getFunction(mangledName); |
| 213 |
1/2✓ Branch 115 → 116 taken 8073 times.
✗ Branch 115 → 310 not taken.
|
8073 | node->entry->updateAddress(func); |
| 214 | 8073 | manifestation->llvmFunction = func; | |
| 215 |
2/4✓ Branch 116 → 117 taken 8073 times.
✗ Branch 116 → 310 not taken.
✗ Branch 117 → 118 not taken.
✓ Branch 117 → 119 taken 8073 times.
|
8073 | assert(func->empty()); |
| 216 | |||
| 217 | // Set attributes to function | ||
| 218 |
1/2✓ Branch 119 → 120 taken 8073 times.
✗ Branch 119 → 310 not taken.
|
8073 | func->setDSOLocal(isSymbolDSOLocal(isPublic)); |
| 219 |
1/2✓ Branch 121 → 122 taken 8073 times.
✗ Branch 121 → 310 not taken.
|
8073 | func->setLinkage(linkage); |
| 220 |
4/6✓ Branch 122 → 123 taken 8073 times.
✗ Branch 122 → 310 not taken.
✓ Branch 123 → 124 taken 8073 times.
✗ Branch 123 → 310 not taken.
✓ Branch 124 → 125 taken 2744 times.
✓ Branch 124 → 126 taken 5329 times.
|
8073 | if (manifestation->entry->getQualType().isInline()) |
| 221 |
1/2✓ Branch 125 → 126 taken 2744 times.
✗ Branch 125 → 310 not taken.
|
2744 | func->addFnAttr(llvm::Attribute::AlwaysInline); |
| 222 |
1/2✓ Branch 126 → 127 taken 8073 times.
✗ Branch 126 → 310 not taken.
|
8073 | enableFunctionInstrumentation(func); |
| 223 | // Set attributes to function parameters and return value | ||
| 224 |
1/2✓ Branch 127 → 128 taken 8073 times.
✗ Branch 127 → 310 not taken.
|
8073 | setParamAttrs(func, paramInfoList); |
| 225 |
1/2✓ Branch 128 → 129 taken 8073 times.
✗ Branch 128 → 310 not taken.
|
8073 | setFunctionReturnValAttrs(func, manifestation->returnType); |
| 226 | |||
| 227 | // Add debug info | ||
| 228 |
1/2✓ Branch 129 → 130 taken 8073 times.
✗ Branch 129 → 310 not taken.
|
8073 | diGenerator.generateFunctionDebugInfo(func, manifestation); |
| 229 |
1/2✓ Branch 130 → 131 taken 8073 times.
✗ Branch 130 → 310 not taken.
|
8073 | diGenerator.setSourceLocation(node); |
| 230 | |||
| 231 | // Create entry block | ||
| 232 |
1/2✓ Branch 134 → 135 taken 8073 times.
✗ Branch 134 → 267 not taken.
|
8073 | llvm::BasicBlock *bEntry = createBlock(); |
| 233 |
1/2✓ Branch 137 → 138 taken 8073 times.
✗ Branch 137 → 310 not taken.
|
8073 | switchToBlock(bEntry, func); |
| 234 | |||
| 235 | // Reset alloca insert markers to this block | ||
| 236 | 8073 | allocaInsertBlock = bEntry; | |
| 237 | 8073 | allocaInsertInst = nullptr; | |
| 238 | |||
| 239 | // Declare result variable | ||
| 240 |
2/4✓ Branch 140 → 141 taken 8073 times.
✗ Branch 140 → 275 not taken.
✓ Branch 141 → 142 taken 8073 times.
✗ Branch 141 → 273 not taken.
|
8073 | llvm::Value *resultAddr = insertAlloca(manifestation->returnType, RETURN_VARIABLE_NAME); |
| 241 |
1/2✓ Branch 146 → 147 taken 8073 times.
✗ Branch 146 → 281 not taken.
|
24219 | SymbolTableEntry *resultEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME); |
| 242 |
1/2✗ Branch 152 → 153 not taken.
✓ Branch 152 → 154 taken 8073 times.
|
8073 | assert(resultEntry != nullptr); |
| 243 |
1/2✓ Branch 154 → 155 taken 8073 times.
✗ Branch 154 → 310 not taken.
|
8073 | resultEntry->updateAddress(resultAddr); |
| 244 | // Generate debug info | ||
| 245 |
2/4✓ Branch 157 → 158 taken 8073 times.
✗ Branch 157 → 287 not taken.
✓ Branch 158 → 159 taken 8073 times.
✗ Branch 158 → 285 not taken.
|
16146 | diGenerator.generateLocalVarDebugInfo(RETURN_VARIABLE_NAME, resultAddr); |
| 246 | |||
| 247 | // Store function argument values | ||
| 248 |
3/4✓ Branch 161 → 162 taken 8073 times.
✗ Branch 161 → 298 not taken.
✓ Branch 183 → 164 taken 13262 times.
✓ Branch 183 → 184 taken 8073 times.
|
21335 | for (auto &arg : func->args()) { |
| 249 | // Get information about the parameter | ||
| 250 | 13262 | const size_t argNumber = arg.getArgNo(); | |
| 251 |
2/4✓ Branch 165 → 166 taken 13262 times.
✗ Branch 165 → 291 not taken.
✓ Branch 166 → 167 taken 13262 times.
✗ Branch 166 → 291 not taken.
|
13262 | auto [paramName, paramSymbol] = paramInfoList.at(argNumber); |
| 252 |
1/2✗ Branch 169 → 170 not taken.
✓ Branch 169 → 171 taken 13262 times.
|
13262 | assert(paramSymbol != nullptr); |
| 253 | // Allocate space for it | ||
| 254 |
2/4✓ Branch 171 → 172 taken 13262 times.
✗ Branch 171 → 291 not taken.
✓ Branch 172 → 173 taken 13262 times.
✗ Branch 172 → 291 not taken.
|
13262 | llvm::Value *paramAddress = insertAlloca(paramSymbol->getQualType(), paramName); |
| 255 | // Update the symbol table entry | ||
| 256 |
1/2✓ Branch 173 → 174 taken 13262 times.
✗ Branch 173 → 291 not taken.
|
13262 | paramSymbol->updateAddress(paramAddress); |
| 257 | // Set source location | ||
| 258 |
1/2✓ Branch 174 → 175 taken 13262 times.
✗ Branch 174 → 291 not taken.
|
13262 | diGenerator.setSourceLocation(paramSymbol->declNode); |
| 259 | // Store the value at the new address | ||
| 260 |
1/2✓ Branch 175 → 176 taken 13262 times.
✗ Branch 175 → 291 not taken.
|
13262 | insertStore(&arg, paramAddress); |
| 261 | // Generate debug info to declare variable | ||
| 262 |
1/2✓ Branch 176 → 177 taken 13262 times.
✗ Branch 176 → 291 not taken.
|
13262 | diGenerator.generateLocalVarDebugInfo(paramName, paramAddress, argNumber + 1); |
| 263 |
1/4✗ Branch 177 → 178 not taken.
✓ Branch 177 → 179 taken 13262 times.
✗ Branch 291 → 292 not taken.
✗ Branch 291 → 293 not taken.
|
26524 | } |
| 264 | |||
| 265 | // Store the default values for optional function args | ||
| 266 |
2/2✓ Branch 184 → 185 taken 6382 times.
✓ Branch 184 → 195 taken 1691 times.
|
8073 | if (node->paramLst) { |
| 267 |
1/2✓ Branch 185 → 186 taken 6382 times.
✗ Branch 185 → 302 not taken.
|
6382 | const std::vector<DeclStmtNode *> params = node->paramLst->params; |
| 268 |
2/2✓ Branch 192 → 187 taken 662 times.
✓ Branch 192 → 193 taken 6382 times.
|
7044 | for (; argIdx < params.size(); argIdx++) |
| 269 |
2/4✓ Branch 187 → 188 taken 662 times.
✗ Branch 187 → 299 not taken.
✓ Branch 188 → 189 taken 662 times.
✗ Branch 188 → 299 not taken.
|
662 | visit(params.at(argIdx)); |
| 270 | 6382 | } | |
| 271 | |||
| 272 | // Visit function body | ||
| 273 |
1/2✓ Branch 195 → 196 taken 8073 times.
✗ Branch 195 → 303 not taken.
|
8073 | visit(node->body); |
| 274 | |||
| 275 | // Create return statement if the block is not terminated yet | ||
| 276 |
2/2✓ Branch 197 → 198 taken 356 times.
✓ Branch 197 → 206 taken 7717 times.
|
8073 | if (!blockAlreadyTerminated) { |
| 277 |
2/4✓ Branch 201 → 202 taken 356 times.
✗ Branch 201 → 304 not taken.
✓ Branch 202 → 203 taken 356 times.
✗ Branch 202 → 304 not taken.
|
356 | llvm::Value *result = insertLoad(returnType, resultEntry->getAddress()); |
| 278 |
1/2✓ Branch 205 → 206 taken 356 times.
✗ Branch 205 → 310 not taken.
|
356 | builder.CreateRet(result); |
| 279 | } | ||
| 280 | |||
| 281 | // Conclude debug info for function | ||
| 282 |
1/2✓ Branch 206 → 207 taken 8073 times.
✗ Branch 206 → 310 not taken.
|
8073 | diGenerator.concludeFunctionDebugInfo(); |
| 283 | |||
| 284 | // Verify function | ||
| 285 |
1/2✓ Branch 207 → 208 taken 8073 times.
✗ Branch 207 → 310 not taken.
|
8073 | verifyFunction(func, node->codeLoc); |
| 286 | |||
| 287 | // Change to root scope | ||
| 288 | 8073 | currentScope = rootScope; | |
| 289 | |||
| 290 | 8073 | manIdx++; // Increment symbolTypeIndex | |
| 291 | 8073 | } | |
| 292 | 8287 | manIdx = 0; // Reset the symbolTypeIndex | |
| 293 | |||
| 294 | // Ensure that we are at the root scope again | ||
| 295 |
1/2✗ Branch 223 → 224 not taken.
✓ Branch 223 → 225 taken 8287 times.
|
8287 | assert(currentScope == rootScope); |
| 296 | |||
| 297 |
1/2✓ Branch 225 → 226 taken 8287 times.
✗ Branch 225 → 318 not taken.
|
16574 | return nullptr; |
| 298 | } | ||
| 299 | |||
| 300 | 4443 | std::any IRGenerator::visitProcDef(const ProcDefNode *node) { | |
| 301 | // Loop through manifestations | ||
| 302 | 4443 | manIdx = 0; // Reset the symbolTypeIndex | |
| 303 |
2/2✓ Branch 174 → 4 taken 6438 times.
✓ Branch 174 → 175 taken 4443 times.
|
15324 | for (Function *manifestation : node->manifestations) { |
| 304 |
1/2✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 6438 times.
|
6438 | assert(manifestation->entry != nullptr); |
| 305 | |||
| 306 | // Check if the manifestation is substantiated or not public and not used by anybody | ||
| 307 |
2/4✓ Branch 8 → 9 taken 6438 times.
✗ Branch 8 → 229 not taken.
✓ Branch 9 → 10 taken 6438 times.
✗ Branch 9 → 229 not taken.
|
6438 | const bool isPublic = manifestation->entry->getQualType().isPublic(); |
| 308 |
9/10✓ Branch 10 → 11 taken 6438 times.
✗ Branch 10 → 229 not taken.
✓ Branch 11 → 12 taken 4249 times.
✓ Branch 11 → 14 taken 2189 times.
✓ Branch 12 → 13 taken 1109 times.
✓ Branch 12 → 15 taken 3140 times.
✓ Branch 13 → 14 taken 8 times.
✓ Branch 13 → 15 taken 1101 times.
✓ Branch 16 → 17 taken 2197 times.
✓ Branch 16 → 18 taken 4241 times.
|
6438 | if (!manifestation->isFullySubstantiated() || (!isPublic && !manifestation->used)) { |
| 309 | 2197 | manIdx++; // Increment symbolTypeIndex | |
| 310 | 2197 | continue; | |
| 311 | } | ||
| 312 |
1/2✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 4241 times.
|
4241 | assert(manifestation->alreadyTypeChecked); |
| 313 | |||
| 314 | // Change to struct scope | ||
| 315 |
2/2✓ Branch 23 → 24 taken 3098 times.
✓ Branch 23 → 32 taken 1143 times.
|
4241 | if (manifestation->isMethod()) { |
| 316 | 3098 | const QualType &thisType = manifestation->thisType; | |
| 317 |
3/6✓ Branch 24 → 25 taken 3098 times.
✗ Branch 24 → 183 not taken.
✓ Branch 25 → 26 taken 3098 times.
✗ Branch 25 → 183 not taken.
✓ Branch 26 → 27 taken 3098 times.
✗ Branch 26 → 183 not taken.
|
3098 | const std::string scopeName = Struct::getScopeName(thisType.getSubType(), thisType.getTemplateTypes()); |
| 318 |
1/2✓ Branch 27 → 28 taken 3098 times.
✗ Branch 27 → 181 not taken.
|
3098 | currentScope = currentScope->getChildScope(scopeName); |
| 319 |
1/2✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 3098 times.
|
3098 | assert(currentScope != nullptr); |
| 320 | 3098 | } | |
| 321 | |||
| 322 | // Change scope | ||
| 323 |
2/4✓ Branch 32 → 33 taken 4241 times.
✗ Branch 32 → 186 not taken.
✓ Branch 33 → 34 taken 4241 times.
✗ Branch 33 → 184 not taken.
|
4241 | currentScope = currentScope->getChildScope(manifestation->getScopeName()); |
| 324 |
1/2✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 4241 times.
|
4241 | assert(currentScope != nullptr); |
| 325 | |||
| 326 | // Get 'this' entry | ||
| 327 | 4241 | std::vector<std::pair<std::string, SymbolTableEntry *>> paramInfoList; | |
| 328 |
1/2✓ Branch 37 → 38 taken 4241 times.
✗ Branch 37 → 225 not taken.
|
4241 | std::vector<llvm::Type *> paramTypes; |
| 329 |
2/2✓ Branch 40 → 41 taken 3098 times.
✓ Branch 40 → 55 taken 1143 times.
|
4241 | if (manifestation->isMethod()) { |
| 330 |
1/2✓ Branch 43 → 44 taken 3098 times.
✗ Branch 43 → 189 not taken.
|
9294 | SymbolTableEntry *thisEntry = currentScope->lookupStrict(THIS_VARIABLE_NAME); |
| 331 |
1/2✗ Branch 49 → 50 not taken.
✓ Branch 49 → 51 taken 3098 times.
|
3098 | assert(thisEntry != nullptr); |
| 332 |
1/2✓ Branch 51 → 52 taken 3098 times.
✗ Branch 51 → 194 not taken.
|
3098 | paramInfoList.emplace_back(THIS_VARIABLE_NAME, thisEntry); |
| 333 |
2/4✓ Branch 52 → 53 taken 3098 times.
✗ Branch 52 → 193 not taken.
✓ Branch 53 → 54 taken 3098 times.
✗ Branch 53 → 193 not taken.
|
3098 | paramTypes.push_back(builder.getPtrTy()); |
| 334 | } | ||
| 335 | |||
| 336 | // Visit parameters | ||
| 337 | 4241 | size_t argIdx = 0; | |
| 338 |
2/2✓ Branch 55 → 56 taken 3186 times.
✓ Branch 55 → 85 taken 1055 times.
|
4241 | if (node->hasParams) { |
| 339 | 3186 | const size_t numOfParams = manifestation->paramList.size(); | |
| 340 |
1/2✓ Branch 57 → 58 taken 3186 times.
✗ Branch 57 → 225 not taken.
|
3186 | paramInfoList.reserve(numOfParams); |
| 341 |
1/2✓ Branch 58 → 59 taken 3186 times.
✗ Branch 58 → 225 not taken.
|
3186 | paramTypes.reserve(numOfParams); |
| 342 |
2/2✓ Branch 84 → 60 taken 5647 times.
✓ Branch 84 → 85 taken 3186 times.
|
8833 | for (; argIdx < numOfParams; argIdx++) { |
| 343 |
1/2✓ Branch 60 → 61 taken 5647 times.
✗ Branch 60 → 200 not taken.
|
5647 | const DeclStmtNode *param = node->paramLst->params.at(argIdx); |
| 344 | // Get symbol table entry of param | ||
| 345 |
1/2✓ Branch 61 → 62 taken 5647 times.
✗ Branch 61 → 200 not taken.
|
5647 | SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName); |
| 346 |
1/2✗ Branch 64 → 65 not taken.
✓ Branch 64 → 66 taken 5647 times.
|
5647 | assert(paramSymbol != nullptr); |
| 347 |
2/4✓ Branch 66 → 67 taken 5647 times.
✗ Branch 66 → 197 not taken.
✓ Branch 67 → 68 taken 5647 times.
✗ Branch 67 → 195 not taken.
|
5647 | const QualType paramSymbolType = manifestation->getParamTypes().at(argIdx); |
| 348 | // Pass the information if captures are taken for function/procedure types | ||
| 349 |
8/10✓ Branch 69 → 70 taken 5647 times.
✗ Branch 69 → 198 not taken.
✓ Branch 70 → 71 taken 29 times.
✓ Branch 70 → 74 taken 5618 times.
✓ Branch 71 → 72 taken 29 times.
✗ Branch 71 → 198 not taken.
✓ Branch 72 → 73 taken 3 times.
✓ Branch 72 → 74 taken 26 times.
✓ Branch 75 → 76 taken 3 times.
✓ Branch 75 → 80 taken 5644 times.
|
5647 | if (paramSymbolType.isOneOf({TY_FUNCTION, TY_PROCEDURE}) && paramSymbolType.hasLambdaCaptures()) |
| 350 |
3/6✓ Branch 76 → 77 taken 3 times.
✗ Branch 76 → 199 not taken.
✓ Branch 77 → 78 taken 3 times.
✗ Branch 77 → 199 not taken.
✓ Branch 78 → 79 taken 3 times.
✗ Branch 78 → 199 not taken.
|
3 | paramSymbol->updateType(paramSymbol->getQualType().getWithLambdaCaptures(), true); |
| 351 | // Retrieve type of param | ||
| 352 |
1/2✓ Branch 80 → 81 taken 5647 times.
✗ Branch 80 → 200 not taken.
|
5647 | llvm::Type *paramType = paramSymbolType.toLLVMType(sourceFile); |
| 353 | // Add it to the lists | ||
| 354 |
1/2✓ Branch 81 → 82 taken 5647 times.
✗ Branch 81 → 200 not taken.
|
5647 | paramInfoList.emplace_back(param->varName, paramSymbol); |
| 355 |
1/2✓ Branch 82 → 83 taken 5647 times.
✗ Branch 82 → 200 not taken.
|
5647 | paramTypes.push_back(paramType); |
| 356 | } | ||
| 357 | } | ||
| 358 | |||
| 359 | // Get return type | ||
| 360 |
1/2✓ Branch 85 → 86 taken 4241 times.
✗ Branch 85 → 225 not taken.
|
4241 | llvm::Type *returnType = builder.getVoidTy(); |
| 361 | |||
| 362 | // Create procedure or implement declared procedure | ||
| 363 |
1/2✓ Branch 86 → 87 taken 4241 times.
✗ Branch 86 → 225 not taken.
|
4241 | const std::string mangledName = manifestation->getMangledName(); |
| 364 |
1/2✓ Branch 88 → 89 taken 4241 times.
✗ Branch 88 → 201 not taken.
|
4241 | llvm::FunctionType *procType = llvm::FunctionType::get(returnType, paramTypes, false); |
| 365 |
1/2✓ Branch 90 → 91 taken 4241 times.
✗ Branch 90 → 202 not taken.
|
4241 | module->getOrInsertFunction(mangledName, procType); |
| 366 |
1/2✓ Branch 92 → 93 taken 4241 times.
✗ Branch 92 → 203 not taken.
|
4241 | llvm::Function *proc = module->getFunction(mangledName); |
| 367 |
1/2✓ Branch 93 → 94 taken 4241 times.
✗ Branch 93 → 223 not taken.
|
4241 | node->entry->updateAddress(proc); |
| 368 | 4241 | manifestation->llvmFunction = proc; | |
| 369 |
2/4✓ Branch 94 → 95 taken 4241 times.
✗ Branch 94 → 223 not taken.
✗ Branch 95 → 96 not taken.
✓ Branch 95 → 97 taken 4241 times.
|
4241 | assert(proc->empty()); |
| 370 | |||
| 371 | // Set attributes to procedure | ||
| 372 |
2/4✓ Branch 97 → 98 taken 4241 times.
✗ Branch 97 → 223 not taken.
✓ Branch 98 → 99 taken 4241 times.
✗ Branch 98 → 223 not taken.
|
4241 | proc->setLinkage(getSymbolLinkageType(isPublic)); |
| 373 |
1/2✓ Branch 99 → 100 taken 4241 times.
✗ Branch 99 → 223 not taken.
|
4241 | proc->setDSOLocal(isSymbolDSOLocal(isPublic)); |
| 374 |
4/6✓ Branch 101 → 102 taken 4241 times.
✗ Branch 101 → 223 not taken.
✓ Branch 102 → 103 taken 4241 times.
✗ Branch 102 → 223 not taken.
✓ Branch 103 → 104 taken 333 times.
✓ Branch 103 → 105 taken 3908 times.
|
4241 | if (manifestation->entry->getQualType().isInline()) |
| 375 |
1/2✓ Branch 104 → 105 taken 333 times.
✗ Branch 104 → 223 not taken.
|
333 | proc->addFnAttr(llvm::Attribute::AlwaysInline); |
| 376 |
1/2✓ Branch 105 → 106 taken 4241 times.
✗ Branch 105 → 223 not taken.
|
4241 | enableFunctionInstrumentation(proc); |
| 377 | |||
| 378 | // Set attributes to function parameters | ||
| 379 |
1/2✓ Branch 106 → 107 taken 4241 times.
✗ Branch 106 → 223 not taken.
|
4241 | setParamAttrs(proc, paramInfoList); |
| 380 | |||
| 381 | // Add debug info | ||
| 382 |
1/2✓ Branch 107 → 108 taken 4241 times.
✗ Branch 107 → 223 not taken.
|
4241 | diGenerator.generateFunctionDebugInfo(proc, manifestation); |
| 383 |
1/2✓ Branch 108 → 109 taken 4241 times.
✗ Branch 108 → 223 not taken.
|
4241 | diGenerator.setSourceLocation(node); |
| 384 | |||
| 385 | // Create entry block | ||
| 386 |
1/2✓ Branch 112 → 113 taken 4241 times.
✗ Branch 112 → 204 not taken.
|
4241 | llvm::BasicBlock *bEntry = createBlock(); |
| 387 |
1/2✓ Branch 115 → 116 taken 4241 times.
✗ Branch 115 → 223 not taken.
|
4241 | switchToBlock(bEntry, proc); |
| 388 | |||
| 389 | // Reset alloca insert markers to this block | ||
| 390 | 4241 | allocaInsertBlock = bEntry; | |
| 391 | 4241 | allocaInsertInst = nullptr; | |
| 392 | |||
| 393 | // Store procedure argument values | ||
| 394 |
3/4✓ Branch 116 → 117 taken 4241 times.
✗ Branch 116 → 217 not taken.
✓ Branch 138 → 119 taken 8745 times.
✓ Branch 138 → 139 taken 4241 times.
|
12986 | for (auto &arg : proc->args()) { |
| 395 | // Get information about the parameter | ||
| 396 | 8745 | const size_t argNumber = arg.getArgNo(); | |
| 397 |
2/4✓ Branch 120 → 121 taken 8745 times.
✗ Branch 120 → 210 not taken.
✓ Branch 121 → 122 taken 8745 times.
✗ Branch 121 → 210 not taken.
|
8745 | auto [paramName, paramSymbol] = paramInfoList.at(argNumber); |
| 398 |
1/2✗ Branch 124 → 125 not taken.
✓ Branch 124 → 126 taken 8745 times.
|
8745 | assert(paramSymbol != nullptr); |
| 399 | // Allocate space for it | ||
| 400 |
2/4✓ Branch 126 → 127 taken 8745 times.
✗ Branch 126 → 210 not taken.
✓ Branch 127 → 128 taken 8745 times.
✗ Branch 127 → 210 not taken.
|
8745 | llvm::Value *paramAddress = insertAlloca(paramSymbol->getQualType(), paramName); |
| 401 | // Update the symbol table entry | ||
| 402 |
1/2✓ Branch 128 → 129 taken 8745 times.
✗ Branch 128 → 210 not taken.
|
8745 | paramSymbol->updateAddress(paramAddress); |
| 403 | // Set source location | ||
| 404 |
1/2✓ Branch 129 → 130 taken 8745 times.
✗ Branch 129 → 210 not taken.
|
8745 | diGenerator.setSourceLocation(paramSymbol->declNode); |
| 405 | // Store the value at the new address | ||
| 406 |
1/2✓ Branch 130 → 131 taken 8745 times.
✗ Branch 130 → 210 not taken.
|
8745 | insertStore(&arg, paramAddress); |
| 407 | // Generate debug info to declare variable | ||
| 408 |
1/2✓ Branch 131 → 132 taken 8745 times.
✗ Branch 131 → 210 not taken.
|
8745 | diGenerator.generateLocalVarDebugInfo(paramName, paramAddress, argNumber + 1); |
| 409 |
1/4✗ Branch 132 → 133 not taken.
✓ Branch 132 → 134 taken 8745 times.
✗ Branch 210 → 211 not taken.
✗ Branch 210 → 212 not taken.
|
17490 | } |
| 410 | |||
| 411 | // Store the default values for optional procedure args | ||
| 412 |
2/2✓ Branch 139 → 140 taken 3186 times.
✓ Branch 139 → 150 taken 1055 times.
|
4241 | if (node->paramLst) { |
| 413 |
1/2✓ Branch 140 → 141 taken 3186 times.
✗ Branch 140 → 221 not taken.
|
3186 | const std::vector<DeclStmtNode *> params = node->paramLst->params; |
| 414 |
2/2✓ Branch 147 → 142 taken 233 times.
✓ Branch 147 → 148 taken 3186 times.
|
3419 | for (; argIdx < params.size(); argIdx++) |
| 415 |
2/4✓ Branch 142 → 143 taken 233 times.
✗ Branch 142 → 218 not taken.
✓ Branch 143 → 144 taken 233 times.
✗ Branch 143 → 218 not taken.
|
233 | visit(params.at(argIdx)); |
| 416 | 3186 | } | |
| 417 | |||
| 418 | // Generate special ctor preamble before generating the body to store VTable, default field values, etc. if required | ||
| 419 |
2/2✓ Branch 150 → 151 taken 1458 times.
✓ Branch 150 → 152 taken 2783 times.
|
4241 | if (node->isCtor) { |
| 420 | 1458 | isInCtorBody = true; | |
| 421 |
1/2✓ Branch 151 → 152 taken 1458 times.
✗ Branch 151 → 223 not taken.
|
1458 | generateCtorBodyPreamble(currentScope); |
| 422 | } | ||
| 423 | |||
| 424 | // Visit procedure body | ||
| 425 |
1/2✓ Branch 152 → 153 taken 4241 times.
✗ Branch 152 → 222 not taken.
|
4241 | visit(node->body); |
| 426 | |||
| 427 |
2/2✓ Branch 154 → 155 taken 1458 times.
✓ Branch 154 → 156 taken 2783 times.
|
4241 | if (node->isCtor) |
| 428 | 1458 | isInCtorBody = false; | |
| 429 | |||
| 430 | // Create return statement if the block is not terminated yet | ||
| 431 |
2/2✓ Branch 156 → 157 taken 4128 times.
✓ Branch 156 → 158 taken 113 times.
|
4241 | if (!blockAlreadyTerminated) |
| 432 |
1/2✓ Branch 157 → 158 taken 4128 times.
✗ Branch 157 → 223 not taken.
|
4128 | builder.CreateRetVoid(); |
| 433 | |||
| 434 | // Conclude debug info for procedure | ||
| 435 |
1/2✓ Branch 158 → 159 taken 4241 times.
✗ Branch 158 → 223 not taken.
|
4241 | diGenerator.concludeFunctionDebugInfo(); |
| 436 | |||
| 437 | // Verify procedure | ||
| 438 |
1/2✓ Branch 159 → 160 taken 4241 times.
✗ Branch 159 → 223 not taken.
|
4241 | verifyFunction(proc, node->codeLoc); |
| 439 | |||
| 440 | // Change to root scope | ||
| 441 | 4241 | currentScope = rootScope; | |
| 442 | |||
| 443 | 4241 | manIdx++; // Increment symbolTypeIndex | |
| 444 | 4241 | } | |
| 445 | 4443 | manIdx = 0; // Reset the symbolTypeIndex | |
| 446 | |||
| 447 | // Ensure that we are at the root scope again | ||
| 448 |
1/2✗ Branch 175 → 176 not taken.
✓ Branch 175 → 177 taken 4443 times.
|
4443 | assert(currentScope == rootScope); |
| 449 | |||
| 450 |
1/2✓ Branch 177 → 178 taken 4443 times.
✗ Branch 177 → 231 not taken.
|
8886 | return nullptr; |
| 451 | } | ||
| 452 | |||
| 453 | 12314 | void IRGenerator::setParamAttrs(llvm::Function *function, const ParamInfoList ¶mInfo) const { | |
| 454 |
1/2✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 12314 times.
|
12314 | assert(function->arg_size() == paramInfo.size()); |
| 455 |
2/2✓ Branch 30 → 7 taken 22007 times.
✓ Branch 30 → 31 taken 12314 times.
|
34321 | for (size_t i = 0; i < paramInfo.size(); i++) { |
| 456 | 22007 | const QualType ¶mType = paramInfo.at(i).second->getQualType(); | |
| 457 | |||
| 458 | // NoUndef attribute | ||
| 459 | 22007 | function->addParamAttr(i, llvm::Attribute::NoUndef); | |
| 460 | |||
| 461 |
2/2✓ Branch 11 → 12 taken 7189 times.
✓ Branch 11 → 25 taken 14818 times.
|
22007 | if (paramType.isPtr()) { |
| 462 | // NonNull attribute | ||
| 463 | 7189 | function->addParamAttr(i, llvm::Attribute::NonNull); | |
| 464 | // Dereferenceable attribute | ||
| 465 |
2/4✓ Branch 13 → 14 taken 7189 times.
✗ Branch 13 → 32 not taken.
✓ Branch 14 → 15 taken 7189 times.
✗ Branch 14 → 32 not taken.
|
7189 | llvm::Type *pointeeType = paramType.getContained().toLLVMType(sourceFile); |
| 466 |
1/2✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 7189 times.
|
7189 | assert(pointeeType != nullptr); |
| 467 |
3/6✓ Branch 18 → 19 taken 7189 times.
✗ Branch 18 → 33 not taken.
✓ Branch 19 → 20 taken 7189 times.
✗ Branch 19 → 33 not taken.
✓ Branch 20 → 21 taken 7189 times.
✗ Branch 20 → 33 not taken.
|
7189 | function->addDereferenceableParamAttr(i, module->getDataLayout().getTypeStoreSize(pointeeType)); |
| 468 | // Alignment attribute | ||
| 469 | 7189 | function->addParamAttr(i, llvm::Attribute::getWithAlignment(context, module->getDataLayout().getABITypeAlign(pointeeType))); | |
| 470 | } | ||
| 471 | |||
| 472 | // ZExt or SExt attribute | ||
| 473 |
2/2✓ Branch 26 → 27 taken 4099 times.
✓ Branch 26 → 28 taken 17908 times.
|
22007 | if (const llvm::Attribute::AttrKind extAttrKind = getExtAttrKindForType(paramType); extAttrKind != llvm::Attribute::None) |
| 474 | 4099 | function->addParamAttr(i, extAttrKind); | |
| 475 | } | ||
| 476 | 12314 | } | |
| 477 | |||
| 478 | 8073 | void IRGenerator::setFunctionReturnValAttrs(llvm::Function *function, const QualType &returnType) const { | |
| 479 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 8073 times.
|
8073 | if (returnType.is(TY_DYN)) |
| 480 | ✗ | return; | |
| 481 | |||
| 482 | // NoUndef attribute | ||
| 483 | 8073 | function->addRetAttr(llvm::Attribute::NoUndef); | |
| 484 | // ZExt or SExt attribute | ||
| 485 |
2/2✓ Branch 7 → 8 taken 3716 times.
✓ Branch 7 → 9 taken 4357 times.
|
8073 | if (const llvm::Attribute::AttrKind extAttrKind = getExtAttrKindForType(returnType); extAttrKind != llvm::Attribute::None) |
| 486 | 3716 | function->addRetAttr(extAttrKind); | |
| 487 | } | ||
| 488 | |||
| 489 | 75967 | llvm::Attribute::AttrKind IRGenerator::getExtAttrKindForType(const QualType &type) const { | |
| 490 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 75967 times.
|
75967 | if (type.is(TY_DYN)) |
| 491 | ✗ | return llvm::Attribute::None; | |
| 492 | |||
| 493 | 75967 | const llvm::Type *llvmType = type.toLLVMType(sourceFile); | |
| 494 |
1/2✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 75967 times.
|
75967 | const unsigned int maxExtWidth = cliOptions.targetTriple.isPPC() ? 64 : 32; |
| 495 |
6/6✓ Branch 11 → 12 taken 33795 times.
✓ Branch 11 → 15 taken 42172 times.
✓ Branch 13 → 14 taken 17213 times.
✓ Branch 13 → 15 taken 16582 times.
✓ Branch 16 → 17 taken 17213 times.
✓ Branch 16 → 22 taken 58754 times.
|
75967 | if (llvmType->isIntegerTy() && llvmType->getIntegerBitWidth() < maxExtWidth) |
| 496 |
2/2✓ Branch 18 → 19 taken 1744 times.
✓ Branch 18 → 20 taken 15469 times.
|
17213 | return type.isSigned() ? llvm::Attribute::SExt : llvm::Attribute::ZExt; |
| 497 | 58754 | return llvm::Attribute::None; | |
| 498 | } | ||
| 499 | |||
| 500 | 709 | std::any IRGenerator::visitStructDef(const StructDefNode *node) { | |
| 501 | // Get all substantiated structs which result from this struct def | ||
| 502 |
1/2✓ Branch 2 → 3 taken 709 times.
✗ Branch 2 → 124 not taken.
|
709 | std::vector<Struct *> manifestations = node->structManifestations; |
| 503 | |||
| 504 | // Sort the manifestations to prevent generating the struct types in the wrong order (in case of dependencies between structs) | ||
| 505 | 1030 | const auto comp = [](const Struct *lhs, const Struct *rhs) { return lhs->manifestationIndex < rhs->manifestationIndex; }; | |
| 506 |
1/2✓ Branch 3 → 4 taken 709 times.
✗ Branch 3 → 122 not taken.
|
709 | std::ranges::sort(manifestations, comp); |
| 507 | |||
| 508 |
2/2✓ Branch 79 → 6 taken 1224 times.
✓ Branch 79 → 80 taken 709 times.
|
2642 | for (Struct *spiceStruct : manifestations) { |
| 509 | // Skip structs, that are not fully substantiated | ||
| 510 |
3/4✓ Branch 8 → 9 taken 1224 times.
✗ Branch 8 → 119 not taken.
✓ Branch 9 → 10 taken 335 times.
✓ Branch 9 → 11 taken 889 times.
|
1224 | if (!spiceStruct->isFullySubstantiated()) |
| 511 | 336 | continue; | |
| 512 | |||
| 513 | // Do not generate this struct if it is private and used by nobody | ||
| 514 |
8/10✓ Branch 11 → 12 taken 6 times.
✓ Branch 11 → 16 taken 883 times.
✓ Branch 12 → 13 taken 6 times.
✗ Branch 12 → 119 not taken.
✓ Branch 13 → 14 taken 6 times.
✗ Branch 13 → 119 not taken.
✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 16 taken 5 times.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 19 taken 888 times.
|
889 | if (!spiceStruct->used && !spiceStruct->entry->getQualType().isPublic()) |
| 515 | 1 | continue; | |
| 516 | |||
| 517 | // Change scope to struct scope, specific to substantiation | ||
| 518 | 888 | currentScope = spiceStruct->scope; | |
| 519 |
1/2✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 888 times.
|
888 | assert(currentScope); |
| 520 | |||
| 521 | // Set LLVM type to the struct entry | ||
| 522 | 888 | const SymbolTableEntry *structEntry = spiceStruct->entry; | |
| 523 |
1/2✗ Branch 21 → 22 not taken.
✓ Branch 21 → 23 taken 888 times.
|
888 | assert(structEntry != nullptr); |
| 524 | |||
| 525 | // Generate VTable if required | ||
| 526 |
2/2✓ Branch 23 → 24 taken 241 times.
✓ Branch 23 → 27 taken 647 times.
|
888 | if (node->emitVTable) { |
| 527 |
1/2✓ Branch 24 → 25 taken 241 times.
✗ Branch 24 → 119 not taken.
|
241 | generateVTable(spiceStruct); |
| 528 |
1/2✓ Branch 25 → 26 taken 241 times.
✗ Branch 25 → 85 not taken.
|
482 | deferredVTableInitializations.emplace_back([=, this]() { generateVTableInitializer(spiceStruct); }, false); |
| 529 | } | ||
| 530 | |||
| 531 | // Generate default ctor if required | ||
| 532 |
1/2✓ Branch 27 → 28 taken 888 times.
✗ Branch 27 → 119 not taken.
|
888 | const QualType &thisType = structEntry->getQualType(); |
| 533 |
2/4✓ Branch 31 → 32 taken 888 times.
✗ Branch 31 → 89 not taken.
✓ Branch 32 → 33 taken 888 times.
✗ Branch 32 → 87 not taken.
|
2664 | const Function *ctorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, thisType, {}, true); |
| 534 |
4/4✓ Branch 36 → 37 taken 356 times.
✓ Branch 36 → 39 taken 532 times.
✓ Branch 37 → 38 taken 48 times.
✓ Branch 37 → 39 taken 308 times.
|
888 | if (ctorFunc != nullptr && ctorFunc->implicitDefault) |
| 535 |
1/2✓ Branch 38 → 39 taken 48 times.
✗ Branch 38 → 119 not taken.
|
48 | generateDefaultCtor(ctorFunc); |
| 536 | |||
| 537 | // Generate default copy ctor if required | ||
| 538 |
2/4✓ Branch 39 → 40 taken 888 times.
✗ Branch 39 → 100 not taken.
✓ Branch 43 → 44 taken 888 times.
✗ Branch 43 → 96 not taken.
|
2664 | const ArgList args = {{thisType.toConstRef(node), false /* always non-temporary */}}; |
| 539 |
2/4✓ Branch 47 → 48 taken 888 times.
✗ Branch 47 → 104 not taken.
✓ Branch 48 → 49 taken 888 times.
✗ Branch 48 → 102 not taken.
|
888 | const Function *copyCtorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, thisType, args, true); |
| 540 |
4/4✓ Branch 51 → 52 taken 236 times.
✓ Branch 51 → 54 taken 652 times.
✓ Branch 52 → 53 taken 108 times.
✓ Branch 52 → 54 taken 128 times.
|
888 | if (copyCtorFunc != nullptr && copyCtorFunc->implicitDefault) |
| 541 |
1/2✓ Branch 53 → 54 taken 108 times.
✗ Branch 53 → 117 not taken.
|
108 | generateDefaultCopyCtor(copyCtorFunc); |
| 542 | |||
| 543 | // Generate default dtor if required | ||
| 544 |
2/4✓ Branch 57 → 58 taken 888 times.
✗ Branch 57 → 110 not taken.
✓ Branch 58 → 59 taken 888 times.
✗ Branch 58 → 108 not taken.
|
2664 | const Function *dtorFunc = FunctionManager::lookup(currentScope, DTOR_FUNCTION_NAME, thisType, {}, true); |
| 545 |
4/4✓ Branch 62 → 63 taken 252 times.
✓ Branch 62 → 65 taken 636 times.
✓ Branch 63 → 64 taken 127 times.
✓ Branch 63 → 65 taken 125 times.
|
888 | if (dtorFunc != nullptr && dtorFunc->implicitDefault) |
| 546 |
1/2✓ Branch 64 → 65 taken 127 times.
✗ Branch 64 → 117 not taken.
|
127 | generateDefaultDtor(dtorFunc); |
| 547 | |||
| 548 | // Return to root scope | ||
| 549 | 888 | currentScope = rootScope; | |
| 550 |
1/2✗ Branch 65 → 66 not taken.
✓ Branch 65 → 67 taken 888 times.
|
888 | assert(currentScope); |
| 551 | 888 | } | |
| 552 | |||
| 553 |
1/2✓ Branch 80 → 81 taken 709 times.
✗ Branch 80 → 121 not taken.
|
1418 | return nullptr; |
| 554 | 709 | } | |
| 555 | |||
| 556 | 94 | std::any IRGenerator::visitInterfaceDef(const InterfaceDefNode *node) { | |
| 557 | // Get all substantiated structs which result from this struct def | ||
| 558 |
1/2✓ Branch 2 → 3 taken 94 times.
✗ Branch 2 → 43 not taken.
|
94 | std::vector<Interface *> manifestations = node->interfaceManifestations; |
| 559 | |||
| 560 | // Sort the manifestations to prevent generating the struct types in the wrong order (in case of dependencies between structs) | ||
| 561 | 362 | const auto comp = [](const Interface *lhs, const Interface *rhs) { return lhs->manifestationIndex < rhs->manifestationIndex; }; | |
| 562 |
1/2✓ Branch 3 → 4 taken 94 times.
✗ Branch 3 → 41 not taken.
|
94 | std::ranges::sort(manifestations, comp); |
| 563 | |||
| 564 |
2/2✓ Branch 31 → 6 taken 275 times.
✓ Branch 31 → 32 taken 94 times.
|
463 | for (Interface *spiceInterface : manifestations) { |
| 565 | // Skip interfaces, that are not fully substantiated | ||
| 566 |
3/4✓ Branch 8 → 9 taken 275 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 75 times.
✓ Branch 9 → 11 taken 200 times.
|
275 | if (!spiceInterface->isFullySubstantiated()) |
| 567 | 75 | continue; | |
| 568 | |||
| 569 | // Do not generate this interface if it is private and used by nobody | ||
| 570 |
7/10✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 16 taken 199 times.
✓ Branch 12 → 13 taken 1 time.
✗ Branch 12 → 39 not taken.
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 39 not taken.
✓ Branch 14 → 15 taken 1 time.
✗ Branch 14 → 16 not taken.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 19 taken 199 times.
|
200 | if (!spiceInterface->used && !spiceInterface->entry->getQualType().isPublic()) |
| 571 | 1 | continue; | |
| 572 | |||
| 573 | // Generate VTable information | ||
| 574 |
1/2✓ Branch 19 → 20 taken 199 times.
✗ Branch 19 → 39 not taken.
|
199 | generateVTable(spiceInterface); |
| 575 |
1/2✓ Branch 20 → 21 taken 199 times.
✗ Branch 20 → 37 not taken.
|
398 | deferredVTableInitializations.emplace_back([=, this]() { generateVTableInitializer(spiceInterface); }, false); |
| 576 | } | ||
| 577 | |||
| 578 |
1/2✓ Branch 32 → 33 taken 94 times.
✗ Branch 32 → 40 not taken.
|
188 | return nullptr; |
| 579 | 94 | } | |
| 580 | |||
| 581 | 74 | std::any IRGenerator::visitEnumDef(const EnumDefNode *node) { | |
| 582 |
1/2✓ Branch 2 → 3 taken 74 times.
✗ Branch 2 → 6 not taken.
|
148 | return nullptr; // Noop (enums are high-level semantic-only structures) |
| 583 | } | ||
| 584 | |||
| 585 | 982 | std::any IRGenerator::visitGenericTypeDef(const GenericTypeDefNode *node) { | |
| 586 |
1/2✓ Branch 2 → 3 taken 982 times.
✗ Branch 2 → 6 not taken.
|
1964 | return nullptr; // Noop (generic types are high-level semantic-only structures) |
| 587 | } | ||
| 588 | |||
| 589 | 108 | std::any IRGenerator::visitAliasDef(const AliasDefNode *node) { | |
| 590 |
1/2✓ Branch 2 → 3 taken 108 times.
✗ Branch 2 → 6 not taken.
|
216 | return nullptr; // Noop (alias definitions are high-level semantic-only structures) |
| 591 | } | ||
| 592 | |||
| 593 | 1247 | std::any IRGenerator::visitGlobalVarDef(const GlobalVarDefNode *node) { | |
| 594 | // Retrieve some information about the variable | ||
| 595 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 1247 times.
|
1247 | assert(node->entry != nullptr); |
| 596 | 1247 | const QualType &entryType = node->entry->getQualType(); | |
| 597 | 1247 | const bool isPublic = entryType.isPublic(); | |
| 598 | 1247 | const bool isConst = entryType.isConst(); | |
| 599 | |||
| 600 | // Get correct type and linkage type | ||
| 601 |
2/4✓ Branch 7 → 8 taken 1247 times.
✗ Branch 7 → 39 not taken.
✓ Branch 8 → 9 taken 1247 times.
✗ Branch 8 → 37 not taken.
|
1247 | const auto varType = std::any_cast<llvm::Type *>(visit(node->dataType)); |
| 602 | |||
| 603 | // Create global var | ||
| 604 |
1/2✓ Branch 11 → 12 taken 1247 times.
✗ Branch 11 → 40 not taken.
|
1247 | llvm::Value *varAddress = module->getOrInsertGlobal(node->varName, varType); |
| 605 |
1/2✓ Branch 13 → 14 taken 1247 times.
✗ Branch 13 → 41 not taken.
|
1247 | llvm::GlobalVariable *var = module->getNamedGlobal(node->varName); |
| 606 | // Set some attributes, based on the given information | ||
| 607 | 1247 | var->setConstant(isConst); | |
| 608 | 1247 | var->setLinkage(getSymbolLinkageType(isPublic)); | |
| 609 | 1247 | var->setDSOLocal(isSymbolDSOLocal(isPublic)); | |
| 610 | |||
| 611 | // Set initializer | ||
| 612 |
1/2✓ Branch 19 → 20 taken 1247 times.
✗ Branch 19 → 24 not taken.
|
1247 | if (node->hasValue) { // Set the constant value as variable initializer |
| 613 |
2/4✓ Branch 20 → 21 taken 1247 times.
✗ Branch 20 → 44 not taken.
✓ Branch 21 → 22 taken 1247 times.
✗ Branch 21 → 42 not taken.
|
1247 | const auto constantValue = std::any_cast<llvm::Constant *>(visit(node->constant)); |
| 614 | 1247 | var->setInitializer(constantValue); | |
| 615 | ✗ | } else if (cliOptions.buildMode != BuildMode::RELEASE) { // Set the default value as variable initializer | |
| 616 | ✗ | assert(cliOptions.buildMode == BuildMode::DEBUG || cliOptions.buildMode == BuildMode::TEST); | |
| 617 | ✗ | llvm::Constant *constantValue = getDefaultValueForSymbolType(node->entry->getQualType()); | |
| 618 | ✗ | var->setInitializer(constantValue); | |
| 619 | } | ||
| 620 | |||
| 621 | 1247 | node->entry->updateAddress(varAddress); | |
| 622 | |||
| 623 | // Add debug info | ||
| 624 | 1247 | diGenerator.generateGlobalVarDebugInfo(var, node->entry); | |
| 625 | |||
| 626 |
1/2✓ Branch 33 → 34 taken 1247 times.
✗ Branch 33 → 45 not taken.
|
2494 | return nullptr; |
| 627 | } | ||
| 628 | |||
| 629 | 1131 | std::any IRGenerator::visitExtDecl(const ExtDeclNode *node) { | |
| 630 | // Get return type | ||
| 631 | 1131 | const Function *spiceFunc = node->extFunction; | |
| 632 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 1131 times.
|
1131 | assert(spiceFunc != nullptr); |
| 633 |
1/2✓ Branch 4 → 5 taken 1131 times.
✗ Branch 4 → 100 not taken.
|
1131 | llvm::Type *returnType = builder.getVoidTy(); |
| 634 |
3/4✓ Branch 5 → 6 taken 1131 times.
✗ Branch 5 → 100 not taken.
✓ Branch 6 → 7 taken 733 times.
✓ Branch 6 → 9 taken 398 times.
|
1131 | if (!spiceFunc->returnType.is(TY_DYN)) |
| 635 |
1/2✓ Branch 7 → 8 taken 733 times.
✗ Branch 7 → 100 not taken.
|
733 | returnType = spiceFunc->returnType.toLLVMType(sourceFile); |
| 636 | |||
| 637 | // Get arg types | ||
| 638 | 1131 | std::vector<llvm::Type *> argTypes; | |
| 639 |
1/2✓ Branch 10 → 11 taken 1131 times.
✗ Branch 10 → 98 not taken.
|
1131 | argTypes.reserve(spiceFunc->paramList.size()); |
| 640 |
3/4✓ Branch 11 → 12 taken 1131 times.
✗ Branch 11 → 76 not taken.
✓ Branch 27 → 14 taken 2208 times.
✓ Branch 27 → 28 taken 1131 times.
|
4470 | for (const QualType ¶mType : spiceFunc->getParamTypes()) |
| 641 |
2/4✓ Branch 16 → 17 taken 2208 times.
✗ Branch 16 → 73 not taken.
✓ Branch 17 → 18 taken 2208 times.
✗ Branch 17 → 73 not taken.
|
3339 | argTypes.push_back(paramType.toLLVMType(sourceFile)); |
| 642 | |||
| 643 | // Declare function | ||
| 644 |
4/4✓ Branch 29 → 30 taken 1089 times.
✓ Branch 29 → 32 taken 42 times.
✓ Branch 30 → 31 taken 20 times.
✓ Branch 30 → 32 taken 1069 times.
|
1131 | const bool isVarArg = node->argTypeLst && node->argTypeLst->hasEllipsis; |
| 645 |
1/2✓ Branch 34 → 35 taken 1131 times.
✗ Branch 34 → 77 not taken.
|
1131 | llvm::FunctionType *functionType = llvm::FunctionType::get(returnType, argTypes, isVarArg); |
| 646 |
1/2✓ Branch 35 → 36 taken 1131 times.
✗ Branch 35 → 98 not taken.
|
1131 | const std::string mangledName = spiceFunc->getMangledName(); |
| 647 |
1/2✓ Branch 37 → 38 taken 1131 times.
✗ Branch 37 → 78 not taken.
|
1131 | module->getOrInsertFunction(mangledName, functionType); |
| 648 |
1/2✓ Branch 39 → 40 taken 1131 times.
✗ Branch 39 → 79 not taken.
|
1131 | llvm::Function *fct = module->getFunction(mangledName); |
| 649 | |||
| 650 | // Add noundef attribute to all parameters | ||
| 651 |
2/2✓ Branch 44 → 41 taken 2208 times.
✓ Branch 44 → 45 taken 1131 times.
|
3339 | for (size_t i = 0; i < argTypes.size(); i++) |
| 652 |
1/2✓ Branch 41 → 42 taken 2208 times.
✗ Branch 41 → 96 not taken.
|
2208 | fct->addParamAttr(i, llvm::Attribute::NoUndef); |
| 653 | |||
| 654 | // If the function should be imported as dll, add the dll attribute | ||
| 655 |
10/18✓ Branch 45 → 46 taken 1 time.
✓ Branch 45 → 52 taken 1130 times.
✓ Branch 48 → 49 taken 1 time.
✗ Branch 48 → 80 not taken.
✓ Branch 49 → 50 taken 1 time.
✗ Branch 49 → 80 not taken.
✗ Branch 50 → 51 not taken.
✓ Branch 50 → 52 taken 1 time.
✓ Branch 53 → 54 taken 1 time.
✓ Branch 53 → 55 taken 1130 times.
✓ Branch 55 → 56 taken 1 time.
✓ Branch 55 → 58 taken 1130 times.
✗ Branch 58 → 59 not taken.
✓ Branch 58 → 67 taken 1131 times.
✗ Branch 80 → 81 not taken.
✗ Branch 80 → 82 not taken.
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 87 not taken.
|
1133 | if (node->attrs && node->attrs->attrLst->hasAttr(ATTR_CORE_LINKER_DLL)) |
| 656 | ✗ | if (node->attrs->attrLst->getAttrValueByName(ATTR_CORE_LINKER_DLL)->boolValue) | |
| 657 | ✗ | fct->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); | |
| 658 | |||
| 659 |
1/2✓ Branch 67 → 68 taken 1131 times.
✗ Branch 67 → 95 not taken.
|
2262 | return nullptr; |
| 660 | 1131 | } | |
| 661 | |||
| 662 | } // namespace spice::compiler | ||
| 663 |