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