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 | 364 | 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 364 times.
|
364 | 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 363 times.
|
364 | 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 | 363 | currentScope = node->bodyScope; | |
| 28 |
1/2✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 363 times.
|
363 | assert(currentScope != nullptr); |
| 29 | |||
| 30 | // Visit parameters | ||
| 31 | 363 | std::vector<std::pair<std::string, const SymbolTableEntry *>> paramInfoList; | |
| 32 | 363 | QualTypeList paramSymbolTypes; | |
| 33 | 363 | std::vector<llvm::Type *> paramTypes; | |
| 34 |
2/2✓ Branch 12 → 13 taken 7 times.
✓ Branch 12 → 44 taken 356 times.
|
363 | if (node->takesArgs) { |
| 35 | 7 | const size_t numOfParams = node->paramLst->params.size(); | |
| 36 |
1/2✓ Branch 14 → 15 taken 7 times.
✗ Branch 14 → 202 not taken.
|
7 | paramInfoList.reserve(numOfParams); |
| 37 |
1/2✓ Branch 15 → 16 taken 7 times.
✗ Branch 15 → 202 not taken.
|
7 | paramSymbolTypes.reserve(numOfParams); |
| 38 |
1/2✓ Branch 16 → 17 taken 7 times.
✗ Branch 16 → 202 not taken.
|
7 | paramTypes.reserve(numOfParams); |
| 39 |
2/2✓ Branch 42 → 19 taken 14 times.
✓ Branch 42 → 43 taken 7 times.
|
28 | for (DeclStmtNode *param : node->paramLst->params) { |
| 40 | // Get symbol table entry of param | ||
| 41 |
1/2✓ Branch 21 → 22 taken 14 times.
✗ Branch 21 → 153 not taken.
|
14 | const SymbolTableEntry *paramSymbol = node->bodyScope->lookupStrict(param->varName); |
| 42 |
1/2✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 14 times.
|
14 | assert(paramSymbol != nullptr); |
| 43 | // Retrieve type of param | ||
| 44 |
2/4✓ Branch 26 → 27 taken 14 times.
✗ Branch 26 → 152 not taken.
✓ Branch 27 → 28 taken 14 times.
✗ Branch 27 → 150 not taken.
|
14 | auto paramType = any_cast<llvm::Type *>(visit(param->dataType)); |
| 45 | // Add it to the lists | ||
| 46 |
1/2✓ Branch 29 → 30 taken 14 times.
✗ Branch 29 → 153 not taken.
|
14 | paramInfoList.emplace_back(param->varName, paramSymbol); |
| 47 |
2/4✓ Branch 30 → 31 taken 14 times.
✗ Branch 30 → 153 not taken.
✓ Branch 31 → 32 taken 14 times.
✗ Branch 31 → 153 not taken.
|
14 | paramSymbolTypes.push_back(paramSymbol->getQualType()); |
| 48 |
1/2✓ Branch 32 → 33 taken 14 times.
✗ Branch 32 → 153 not taken.
|
14 | paramTypes.push_back(paramType); |
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | // Build the function | ||
| 53 |
1/2✓ Branch 44 → 45 taken 363 times.
✗ Branch 44 → 202 not taken.
|
363 | llvm::Type *returnType = builder.getInt32Ty(); |
| 54 |
1/2✓ Branch 46 → 47 taken 363 times.
✗ Branch 46 → 155 not taken.
|
363 | llvm::FunctionType *fctType = llvm::FunctionType::get(returnType, paramTypes, false); |
| 55 |
2/4✓ Branch 47 → 48 taken 363 times.
✗ Branch 47 → 156 not taken.
✓ Branch 48 → 49 taken 363 times.
✗ Branch 48 → 156 not taken.
|
363 | llvm::Function *fct = llvm::Function::Create(fctType, llvm::Function::ExternalLinkage, MAIN_FUNCTION_NAME, module); |
| 56 | 363 | fct->setDSOLocal(true); | |
| 57 | |||
| 58 | // Add function attributes | ||
| 59 |
1/2✓ Branch 50 → 51 taken 363 times.
✗ Branch 50 → 202 not taken.
|
363 | fct->addFnAttr(llvm::Attribute::MustProgress); |
| 60 |
1/2✓ Branch 51 → 52 taken 363 times.
✗ Branch 51 → 202 not taken.
|
363 | fct->addFnAttr(llvm::Attribute::NoInline); |
| 61 |
1/2✓ Branch 52 → 53 taken 363 times.
✗ Branch 52 → 202 not taken.
|
363 | fct->addFnAttr(llvm::Attribute::NoRecurse); |
| 62 |
1/2✓ Branch 53 → 54 taken 363 times.
✗ Branch 53 → 202 not taken.
|
363 | fct->addFnAttr(llvm::Attribute::NoUnwind); |
| 63 |
1/2✓ Branch 54 → 55 taken 363 times.
✗ Branch 54 → 56 not taken.
|
363 | if (cliOptions.optLevel == OptLevel::O0) |
| 64 |
1/2✓ Branch 55 → 58 taken 363 times.
✗ Branch 55 → 202 not taken.
|
363 | 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 363 times.
✗ Branch 58 → 202 not taken.
✓ Branch 59 → 60 taken 363 times.
✗ Branch 59 → 202 not taken.
|
363 | fct->addFnAttr(llvm::Attribute::getWithUWTableKind(context, llvm::UWTableKind::Default)); |
| 68 |
1/2✓ Branch 60 → 61 taken 363 times.
✗ Branch 60 → 202 not taken.
|
363 | enableFunctionInstrumentation(fct); |
| 69 | |||
| 70 | // Add return value attributes | ||
| 71 |
1/2✓ Branch 61 → 62 taken 363 times.
✗ Branch 61 → 202 not taken.
|
363 | fct->addRetAttr(llvm::Attribute::NoUndef); |
| 72 | |||
| 73 | // Add return value attributes | ||
| 74 |
1/2✓ Branch 62 → 63 taken 363 times.
✗ Branch 62 → 202 not taken.
|
363 | fct->addRetAttr(llvm::Attribute::NoUndef); |
| 75 | |||
| 76 | // Add debug info | ||
| 77 |
2/2✓ Branch 63 → 64 taken 6 times.
✓ Branch 63 → 69 taken 357 times.
|
363 | 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 363 times.
✗ Branch 72 → 160 not taken.
|
363 | llvm::BasicBlock *bEntry = createBlock(); |
| 86 |
1/2✓ Branch 75 → 76 taken 363 times.
✗ Branch 75 → 202 not taken.
|
363 | switchToBlock(bEntry, fct); |
| 87 | |||
| 88 | // Reset alloca insert markers to this block | ||
| 89 | 363 | allocaInsertBlock = bEntry; | |
| 90 | 363 | allocaInsertInst = nullptr; | |
| 91 | |||
| 92 | // Allocate result variable | ||
| 93 |
3/6✓ Branch 78 → 79 taken 363 times.
✗ Branch 78 → 169 not taken.
✓ Branch 79 → 80 taken 363 times.
✗ Branch 79 → 166 not taken.
✓ Branch 80 → 81 taken 363 times.
✗ Branch 80 → 166 not taken.
|
363 | llvm::Value *resultAddress = insertAlloca(QualType(TY_INT), RETURN_VARIABLE_NAME); |
| 94 | // Update the symbol table entry | ||
| 95 |
1/2✓ Branch 85 → 86 taken 363 times.
✗ Branch 85 → 175 not taken.
|
1089 | const SymbolTableEntry *resultEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME); |
| 96 |
1/2✗ Branch 91 → 92 not taken.
✓ Branch 91 → 93 taken 363 times.
|
363 | assert(resultEntry != nullptr); |
| 97 |
1/2✓ Branch 93 → 94 taken 363 times.
✗ Branch 93 → 202 not taken.
|
363 | updateAddress(resultEntry, resultAddress); |
| 98 | // Generate debug info | ||
| 99 |
2/4✓ Branch 96 → 97 taken 363 times.
✗ Branch 96 → 181 not taken.
✓ Branch 97 → 98 taken 363 times.
✗ Branch 97 → 179 not taken.
|
726 | diGenerator.generateLocalVarDebugInfo(RETURN_VARIABLE_NAME, resultAddress); |
| 100 | // Store the default result value | ||
| 101 |
3/6✓ Branch 100 → 101 taken 363 times.
✗ Branch 100 → 185 not taken.
✓ Branch 101 → 102 taken 363 times.
✗ Branch 101 → 185 not taken.
✓ Branch 102 → 103 taken 363 times.
✗ Branch 102 → 185 not taken.
|
363 | insertStore(builder.getInt32(0), resultAddress, QualType(TY_INT)); |
| 102 | |||
| 103 | // Store function argument values | ||
| 104 |
3/4✓ Branch 103 → 104 taken 363 times.
✗ Branch 103 → 193 not taken.
✓ Branch 124 → 106 taken 14 times.
✓ Branch 124 → 125 taken 363 times.
|
377 | for (auto &arg : fct->args()) { |
| 105 | // Get information about the parameter | ||
| 106 | 14 | const size_t argNumber = arg.getArgNo(); | |
| 107 |
2/4✓ Branch 107 → 108 taken 14 times.
✗ Branch 107 → 186 not taken.
✓ Branch 108 → 109 taken 14 times.
✗ Branch 108 → 186 not taken.
|
14 | auto [paramName, paramSymbol] = paramInfoList.at(argNumber); |
| 108 |
1/2✗ Branch 111 → 112 not taken.
✓ Branch 111 → 113 taken 14 times.
|
14 | assert(paramSymbol != nullptr); |
| 109 | // Allocate space for it | ||
| 110 |
2/4✓ Branch 113 → 114 taken 14 times.
✗ Branch 113 → 186 not taken.
✓ Branch 114 → 115 taken 14 times.
✗ Branch 114 → 186 not taken.
|
14 | llvm::Value *paramAddress = insertAlloca(paramSymbol->getQualType(), paramName); |
| 111 | // Update the symbol table entry | ||
| 112 |
1/2✓ Branch 115 → 116 taken 14 times.
✗ Branch 115 → 186 not taken.
|
14 | updateAddress(paramSymbol, paramAddress); |
| 113 | // Generate debug info | ||
| 114 |
1/2✓ Branch 116 → 117 taken 14 times.
✗ Branch 116 → 186 not taken.
|
14 | diGenerator.generateLocalVarDebugInfo(paramName, paramAddress, argNumber + 1); |
| 115 | // Store the value at the new address | ||
| 116 |
1/2✓ Branch 117 → 118 taken 14 times.
✗ Branch 117 → 186 not taken.
|
14 | insertStore(&arg, paramAddress); |
| 117 |
1/4✗ Branch 118 → 119 not taken.
✓ Branch 118 → 120 taken 14 times.
✗ Branch 186 → 187 not taken.
✗ Branch 186 → 188 not taken.
|
28 | } |
| 118 | |||
| 119 | // Visit function body | ||
| 120 |
1/2✓ Branch 125 → 126 taken 363 times.
✗ Branch 125 → 194 not taken.
|
363 | visit(node->body); |
| 121 | |||
| 122 | // Create return statement if the block is not terminated yet | ||
| 123 |
2/2✓ Branch 127 → 128 taken 340 times.
✓ Branch 127 → 137 taken 23 times.
|
363 | if (!blockAlreadyTerminated) { |
| 124 |
3/6✓ Branch 131 → 132 taken 340 times.
✗ Branch 131 → 195 not taken.
✓ Branch 132 → 133 taken 340 times.
✗ Branch 132 → 195 not taken.
✓ Branch 133 → 134 taken 340 times.
✗ Branch 133 → 195 not taken.
|
340 | llvm::Value *result = insertLoad(fct->getReturnType(), getAddress(resultEntry)); |
| 125 |
1/2✓ Branch 136 → 137 taken 340 times.
✗ Branch 136 → 202 not taken.
|
340 | builder.CreateRet(result); |
| 126 | } | ||
| 127 | |||
| 128 | // Conclude debug info for function | ||
| 129 |
1/2✓ Branch 137 → 138 taken 363 times.
✗ Branch 137 → 202 not taken.
|
363 | diGenerator.concludeFunctionDebugInfo(); |
| 130 | |||
| 131 | // Verify function | ||
| 132 |
1/2✓ Branch 138 → 139 taken 363 times.
✗ Branch 138 → 202 not taken.
|
363 | verifyFunction(fct, node->codeLoc); |
| 133 | |||
| 134 | // Change back to root scope | ||
| 135 | 363 | currentScope = rootScope; | |
| 136 |
1/2✗ Branch 139 → 140 not taken.
✓ Branch 139 → 141 taken 363 times.
|
363 | assert(currentScope != nullptr); |
| 137 | |||
| 138 |
1/2✓ Branch 141 → 142 taken 363 times.
✗ Branch 141 → 201 not taken.
|
363 | return nullptr; |
| 139 | 363 | } | |
| 140 | |||
| 141 | 19722 | std::any IRGenerator::visitFctDef(const FctDefNode *node) { | |
| 142 | // Loop through manifestations | ||
| 143 | 19722 | manIdx = 0; // Reset the symbolTypeIndex | |
| 144 |
2/2✓ Branch 212 → 4 taken 26727 times.
✓ Branch 212 → 213 taken 19722 times.
|
66171 | for (const Function *manifestation : node->manifestations) { |
| 145 |
1/2✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 26727 times.
|
26727 | 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 26727 times.
✗ Branch 8 → 304 not taken.
✓ Branch 9 → 10 taken 26727 times.
✗ Branch 9 → 304 not taken.
|
26727 | const bool isPublic = manifestation->entry->getQualType().isPublic(); |
| 149 |
9/10✓ Branch 10 → 11 taken 26727 times.
✗ Branch 10 → 304 not taken.
✓ Branch 11 → 12 taken 21960 times.
✓ Branch 11 → 14 taken 4767 times.
✓ Branch 12 → 13 taken 1118 times.
✓ Branch 12 → 15 taken 20842 times.
✓ Branch 13 → 14 taken 23 times.
✓ Branch 13 → 15 taken 1095 times.
✓ Branch 16 → 17 taken 4790 times.
✓ Branch 16 → 18 taken 21937 times.
|
26727 | if (!manifestation->isFullySubstantiated() || (!isPublic && !manifestation->used)) { |
| 150 | 4790 | manIdx++; // Increment symbolTypeIndex | |
| 151 | 4790 | continue; | |
| 152 | } | ||
| 153 | |||
| 154 | // Change to struct scope | ||
| 155 |
2/2✓ Branch 21 → 22 taken 12930 times.
✓ Branch 21 → 30 taken 9007 times.
|
21937 | if (manifestation->isMethod()) { |
| 156 | 12930 | const QualType &thisType = manifestation->thisType; | |
| 157 |
3/6✓ Branch 22 → 23 taken 12930 times.
✗ Branch 22 → 221 not taken.
✓ Branch 23 → 24 taken 12930 times.
✗ Branch 23 → 221 not taken.
✓ Branch 24 → 25 taken 12930 times.
✗ Branch 24 → 221 not taken.
|
12930 | const std::string scopeName = Struct::getScopeName(thisType.getSubType(), thisType.getTemplateTypes()); |
| 158 |
1/2✓ Branch 25 → 26 taken 12930 times.
✗ Branch 25 → 219 not taken.
|
12930 | currentScope = currentScope->getChildScope(scopeName); |
| 159 |
1/2✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 12930 times.
|
12930 | assert(currentScope != nullptr); |
| 160 | 12930 | } | |
| 161 | |||
| 162 | // Change scope | ||
| 163 |
2/4✓ Branch 30 → 31 taken 21937 times.
✗ Branch 30 → 224 not taken.
✓ Branch 31 → 32 taken 21937 times.
✗ Branch 31 → 222 not taken.
|
21937 | currentScope = currentScope->getChildScope(manifestation->getScopeName()); |
| 164 |
1/2✗ Branch 33 → 34 not taken.
✓ Branch 33 → 35 taken 21937 times.
|
21937 | assert(currentScope != nullptr); |
| 165 | |||
| 166 | // Get 'this' entry | ||
| 167 | 21937 | std::vector<std::pair<std::string, const SymbolTableEntry *>> paramInfoList; | |
| 168 |
1/2✓ Branch 35 → 36 taken 21937 times.
✗ Branch 35 → 300 not taken.
|
21937 | std::vector<llvm::Type *> paramTypes; |
| 169 |
2/2✓ Branch 38 → 39 taken 12930 times.
✓ Branch 38 → 53 taken 9007 times.
|
21937 | if (manifestation->isMethod()) { |
| 170 |
1/2✓ Branch 41 → 42 taken 12930 times.
✗ Branch 41 → 227 not taken.
|
38790 | const SymbolTableEntry *thisEntry = currentScope->lookupStrict(THIS_VARIABLE_NAME); |
| 171 |
1/2✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 12930 times.
|
12930 | assert(thisEntry != nullptr); |
| 172 |
1/2✓ Branch 49 → 50 taken 12930 times.
✗ Branch 49 → 232 not taken.
|
12930 | paramInfoList.emplace_back(THIS_VARIABLE_NAME, thisEntry); |
| 173 |
2/4✓ Branch 50 → 51 taken 12930 times.
✗ Branch 50 → 231 not taken.
✓ Branch 51 → 52 taken 12930 times.
✗ Branch 51 → 231 not taken.
|
12930 | paramTypes.push_back(builder.getPtrTy()); |
| 174 | } | ||
| 175 | |||
| 176 | // Visit parameters | ||
| 177 | 21937 | size_t argIdx = 0; | |
| 178 |
2/2✓ Branch 53 → 54 taken 15481 times.
✓ Branch 53 → 72 taken 6456 times.
|
21937 | if (node->hasParams) { |
| 179 | 15481 | const size_t numOfParams = manifestation->paramList.size(); | |
| 180 |
1/2✓ Branch 55 → 56 taken 15481 times.
✗ Branch 55 → 300 not taken.
|
15481 | paramInfoList.reserve(numOfParams); |
| 181 |
1/2✓ Branch 56 → 57 taken 15481 times.
✗ Branch 56 → 300 not taken.
|
15481 | paramTypes.reserve(numOfParams); |
| 182 |
2/2✓ Branch 71 → 58 taken 22569 times.
✓ Branch 71 → 72 taken 15481 times.
|
38050 | for (; argIdx < numOfParams; argIdx++) { |
| 183 |
1/2✓ Branch 58 → 59 taken 22569 times.
✗ Branch 58 → 236 not taken.
|
22569 | const DeclStmtNode *param = node->paramLst->params.at(argIdx); |
| 184 | // Get symbol table entry of param | ||
| 185 |
1/2✓ Branch 59 → 60 taken 22569 times.
✗ Branch 59 → 236 not taken.
|
22569 | const SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName); |
| 186 |
1/2✗ Branch 62 → 63 not taken.
✓ Branch 62 → 64 taken 22569 times.
|
22569 | assert(paramSymbol != nullptr); |
| 187 |
2/4✓ Branch 64 → 65 taken 22569 times.
✗ Branch 64 → 235 not taken.
✓ Branch 65 → 66 taken 22569 times.
✗ Branch 65 → 233 not taken.
|
22569 | const QualType paramSymbolType = manifestation->getParamTypes().at(argIdx); |
| 188 | // Retrieve type of param | ||
| 189 |
1/2✓ Branch 67 → 68 taken 22569 times.
✗ Branch 67 → 236 not taken.
|
22569 | llvm::Type *paramType = paramSymbolType.toLLVMType(sourceFile); |
| 190 | // Add it to the lists | ||
| 191 |
1/2✓ Branch 68 → 69 taken 22569 times.
✗ Branch 68 → 236 not taken.
|
22569 | paramInfoList.emplace_back(param->varName, paramSymbol); |
| 192 |
1/2✓ Branch 69 → 70 taken 22569 times.
✗ Branch 69 → 236 not taken.
|
22569 | paramTypes.push_back(paramType); |
| 193 | } | ||
| 194 | } | ||
| 195 | |||
| 196 | // Get return type | ||
| 197 |
1/2✓ Branch 72 → 73 taken 21937 times.
✗ Branch 72 → 300 not taken.
|
21937 | llvm::Type *returnType = manifestation->returnType.toLLVMType(sourceFile); |
| 198 | |||
| 199 | // Get function linkage | ||
| 200 | 21937 | bool externalLinkage = isPublic; | |
| 201 |
12/18✓ Branch 73 → 74 taken 803 times.
✓ Branch 73 → 80 taken 21134 times.
✓ Branch 76 → 77 taken 803 times.
✗ Branch 76 → 237 not taken.
✓ Branch 77 → 78 taken 803 times.
✗ Branch 77 → 237 not taken.
✓ Branch 78 → 79 taken 109 times.
✓ Branch 78 → 80 taken 694 times.
✓ Branch 81 → 82 taken 803 times.
✓ Branch 81 → 83 taken 21134 times.
✓ Branch 83 → 84 taken 803 times.
✓ Branch 83 → 86 taken 21134 times.
✓ Branch 86 → 87 taken 109 times.
✓ Branch 86 → 94 taken 21828 times.
✗ Branch 237 → 238 not taken.
✗ Branch 237 → 239 not taken.
✗ Branch 241 → 242 not taken.
✗ Branch 241 → 244 not taken.
|
23543 | if (node->attrs && node->attrs->attrLst->hasAttr(ATTR_TEST)) |
| 202 |
2/4✓ Branch 89 → 90 taken 109 times.
✗ Branch 89 → 248 not taken.
✓ Branch 90 → 91 taken 109 times.
✗ Branch 90 → 246 not taken.
|
327 | externalLinkage |= node->attrs->attrLst->getAttrValueByName(ATTR_TEST)->boolValue; |
| 203 |
2/2✓ Branch 94 → 95 taken 20852 times.
✓ Branch 94 → 96 taken 1085 times.
|
21937 | const auto linkage = externalLinkage ? llvm::Function::ExternalLinkage : llvm::Function::PrivateLinkage; |
| 204 | |||
| 205 | // Create function or implement declared function | ||
| 206 |
1/2✓ Branch 97 → 98 taken 21937 times.
✗ Branch 97 → 300 not taken.
|
21937 | const std::string mangledName = manifestation->getMangledName(); |
| 207 |
1/2✓ Branch 99 → 100 taken 21937 times.
✗ Branch 99 → 252 not taken.
|
21937 | llvm::FunctionType *funcType = llvm::FunctionType::get(returnType, paramTypes, false); |
| 208 |
1/2✓ Branch 101 → 102 taken 21937 times.
✗ Branch 101 → 253 not taken.
|
21937 | module->getOrInsertFunction(mangledName, funcType); |
| 209 |
1/2✓ Branch 103 → 104 taken 21937 times.
✗ Branch 103 → 254 not taken.
|
21937 | llvm::Function *func = module->getFunction(mangledName); |
| 210 |
1/2✓ Branch 104 → 105 taken 21937 times.
✗ Branch 104 → 298 not taken.
|
21937 | updateAddress(node->entry, func); |
| 211 |
1/2✓ Branch 105 → 106 taken 21937 times.
✗ Branch 105 → 298 not taken.
|
21937 | setLLVMFunction(manifestation, func); |
| 212 |
2/4✓ Branch 106 → 107 taken 21937 times.
✗ Branch 106 → 298 not taken.
✗ Branch 107 → 108 not taken.
✓ Branch 107 → 109 taken 21937 times.
|
21937 | assert(func->empty()); |
| 213 | |||
| 214 | // Set attributes to function | ||
| 215 |
1/2✓ Branch 109 → 110 taken 21937 times.
✗ Branch 109 → 298 not taken.
|
21937 | func->setDSOLocal(isSymbolDSOLocal(isPublic)); |
| 216 |
1/2✓ Branch 111 → 112 taken 21937 times.
✗ Branch 111 → 298 not taken.
|
21937 | func->setLinkage(linkage); |
| 217 |
4/6✓ Branch 112 → 113 taken 21937 times.
✗ Branch 112 → 298 not taken.
✓ Branch 113 → 114 taken 21937 times.
✗ Branch 113 → 298 not taken.
✓ Branch 114 → 115 taken 5805 times.
✓ Branch 114 → 116 taken 16132 times.
|
21937 | if (manifestation->entry->getQualType().isInline()) |
| 218 |
1/2✓ Branch 115 → 116 taken 5805 times.
✗ Branch 115 → 298 not taken.
|
5805 | func->addFnAttr(llvm::Attribute::AlwaysInline); |
| 219 |
1/2✓ Branch 116 → 117 taken 21937 times.
✗ Branch 116 → 298 not taken.
|
21937 | enableFunctionInstrumentation(func); |
| 220 | // Set attributes to function parameters and return value | ||
| 221 |
1/2✓ Branch 117 → 118 taken 21937 times.
✗ Branch 117 → 298 not taken.
|
21937 | setParamAttrs(func, paramInfoList); |
| 222 |
1/2✓ Branch 118 → 119 taken 21937 times.
✗ Branch 118 → 298 not taken.
|
21937 | setFunctionReturnValAttrs(func, manifestation->returnType); |
| 223 | |||
| 224 | // Add debug info | ||
| 225 |
1/2✓ Branch 119 → 120 taken 21937 times.
✗ Branch 119 → 298 not taken.
|
21937 | diGenerator.generateFunctionDebugInfo(func, manifestation); |
| 226 |
1/2✓ Branch 120 → 121 taken 21937 times.
✗ Branch 120 → 298 not taken.
|
21937 | diGenerator.setSourceLocation(node); |
| 227 | |||
| 228 | // Create entry block | ||
| 229 |
1/2✓ Branch 124 → 125 taken 21937 times.
✗ Branch 124 → 255 not taken.
|
21937 | llvm::BasicBlock *bEntry = createBlock(); |
| 230 |
1/2✓ Branch 127 → 128 taken 21937 times.
✗ Branch 127 → 298 not taken.
|
21937 | switchToBlock(bEntry, func); |
| 231 | |||
| 232 | // Reset alloca insert markers to this block | ||
| 233 | 21937 | allocaInsertBlock = bEntry; | |
| 234 | 21937 | allocaInsertInst = nullptr; | |
| 235 | |||
| 236 | // Declare result variable | ||
| 237 |
2/4✓ Branch 130 → 131 taken 21937 times.
✗ Branch 130 → 263 not taken.
✓ Branch 131 → 132 taken 21937 times.
✗ Branch 131 → 261 not taken.
|
21937 | llvm::Value *resultAddr = insertAlloca(manifestation->returnType, RETURN_VARIABLE_NAME); |
| 238 |
1/2✓ Branch 136 → 137 taken 21937 times.
✗ Branch 136 → 269 not taken.
|
65811 | const SymbolTableEntry *resultEntry = currentScope->lookupStrict(RETURN_VARIABLE_NAME); |
| 239 |
1/2✗ Branch 142 → 143 not taken.
✓ Branch 142 → 144 taken 21937 times.
|
21937 | assert(resultEntry != nullptr); |
| 240 |
1/2✓ Branch 144 → 145 taken 21937 times.
✗ Branch 144 → 298 not taken.
|
21937 | updateAddress(resultEntry, resultAddr); |
| 241 | // Generate debug info | ||
| 242 |
2/4✓ Branch 147 → 148 taken 21937 times.
✗ Branch 147 → 275 not taken.
✓ Branch 148 → 149 taken 21937 times.
✗ Branch 148 → 273 not taken.
|
43874 | diGenerator.generateLocalVarDebugInfo(RETURN_VARIABLE_NAME, resultAddr); |
| 243 | |||
| 244 | // Store function argument values | ||
| 245 |
3/4✓ Branch 151 → 152 taken 21937 times.
✗ Branch 151 → 286 not taken.
✓ Branch 173 → 154 taken 35499 times.
✓ Branch 173 → 174 taken 21937 times.
|
57436 | for (auto &arg : func->args()) { |
| 246 | // Get information about the parameter | ||
| 247 | 35499 | const size_t argNumber = arg.getArgNo(); | |
| 248 |
2/4✓ Branch 155 → 156 taken 35499 times.
✗ Branch 155 → 279 not taken.
✓ Branch 156 → 157 taken 35499 times.
✗ Branch 156 → 279 not taken.
|
35499 | auto [paramName, paramSymbol] = paramInfoList.at(argNumber); |
| 249 |
1/2✗ Branch 159 → 160 not taken.
✓ Branch 159 → 161 taken 35499 times.
|
35499 | assert(paramSymbol != nullptr); |
| 250 | // Allocate space for it | ||
| 251 |
2/4✓ Branch 161 → 162 taken 35499 times.
✗ Branch 161 → 279 not taken.
✓ Branch 162 → 163 taken 35499 times.
✗ Branch 162 → 279 not taken.
|
35499 | llvm::Value *paramAddress = insertAlloca(paramSymbol->getQualType(), paramName); |
| 252 | // Update the symbol table entry | ||
| 253 |
1/2✓ Branch 163 → 164 taken 35499 times.
✗ Branch 163 → 279 not taken.
|
35499 | updateAddress(paramSymbol, paramAddress); |
| 254 | // Set source location | ||
| 255 |
1/2✓ Branch 164 → 165 taken 35499 times.
✗ Branch 164 → 279 not taken.
|
35499 | diGenerator.setSourceLocation(paramSymbol->declNode); |
| 256 | // Generate debug info to declare variable | ||
| 257 |
1/2✓ Branch 165 → 166 taken 35499 times.
✗ Branch 165 → 279 not taken.
|
35499 | diGenerator.generateLocalVarDebugInfo(paramName, paramAddress, argNumber + 1); |
| 258 | // Store the value at the new address | ||
| 259 |
1/2✓ Branch 166 → 167 taken 35499 times.
✗ Branch 166 → 279 not taken.
|
35499 | insertStore(&arg, paramAddress); |
| 260 |
1/4✗ Branch 167 → 168 not taken.
✓ Branch 167 → 169 taken 35499 times.
✗ Branch 279 → 280 not taken.
✗ Branch 279 → 281 not taken.
|
70998 | } |
| 261 | |||
| 262 | // Store the default values for optional function args | ||
| 263 |
2/2✓ Branch 174 → 175 taken 15481 times.
✓ Branch 174 → 185 taken 6456 times.
|
21937 | if (node->paramLst) { |
| 264 |
1/2✓ Branch 175 → 176 taken 15481 times.
✗ Branch 175 → 290 not taken.
|
15481 | const std::vector<DeclStmtNode *> params = node->paramLst->params; |
| 265 |
2/2✓ Branch 182 → 177 taken 1613 times.
✓ Branch 182 → 183 taken 15481 times.
|
17094 | for (; argIdx < params.size(); argIdx++) |
| 266 |
2/4✓ Branch 177 → 178 taken 1613 times.
✗ Branch 177 → 287 not taken.
✓ Branch 178 → 179 taken 1613 times.
✗ Branch 178 → 287 not taken.
|
1613 | visit(params.at(argIdx)); |
| 267 | 15481 | } | |
| 268 | |||
| 269 | // Visit function body | ||
| 270 |
1/2✓ Branch 185 → 186 taken 21937 times.
✗ Branch 185 → 291 not taken.
|
21937 | visit(node->body); |
| 271 | |||
| 272 | // Create return statement if the block is not terminated yet | ||
| 273 |
2/2✓ Branch 187 → 188 taken 946 times.
✓ Branch 187 → 196 taken 20991 times.
|
21937 | if (!blockAlreadyTerminated) { |
| 274 |
2/4✓ Branch 191 → 192 taken 946 times.
✗ Branch 191 → 292 not taken.
✓ Branch 192 → 193 taken 946 times.
✗ Branch 192 → 292 not taken.
|
946 | llvm::Value *result = insertLoad(returnType, getAddress(resultEntry)); |
| 275 |
1/2✓ Branch 195 → 196 taken 946 times.
✗ Branch 195 → 298 not taken.
|
946 | builder.CreateRet(result); |
| 276 | } | ||
| 277 | |||
| 278 | // Conclude debug info for function | ||
| 279 |
1/2✓ Branch 196 → 197 taken 21937 times.
✗ Branch 196 → 298 not taken.
|
21937 | diGenerator.concludeFunctionDebugInfo(); |
| 280 | |||
| 281 | // Verify function | ||
| 282 |
1/2✓ Branch 197 → 198 taken 21937 times.
✗ Branch 197 → 298 not taken.
|
21937 | verifyFunction(func, node->codeLoc); |
| 283 | |||
| 284 | // Change to root scope | ||
| 285 | 21937 | currentScope = rootScope; | |
| 286 | |||
| 287 | 21937 | manIdx++; // Increment symbolTypeIndex | |
| 288 | 21937 | } | |
| 289 | 19722 | manIdx = 0; // Reset the symbolTypeIndex | |
| 290 | |||
| 291 | // Ensure that we are at the root scope again | ||
| 292 |
1/2✗ Branch 213 → 214 not taken.
✓ Branch 213 → 215 taken 19722 times.
|
19722 | assert(currentScope == rootScope); |
| 293 | |||
| 294 |
1/2✓ Branch 215 → 216 taken 19722 times.
✗ Branch 215 → 306 not taken.
|
39444 | return nullptr; |
| 295 | } | ||
| 296 | |||
| 297 | 10534 | std::any IRGenerator::visitProcDef(const ProcDefNode *node) { | |
| 298 | // Loop through manifestations | ||
| 299 | 10534 | manIdx = 0; // Reset the symbolTypeIndex | |
| 300 |
2/2✓ Branch 164 → 4 taken 15867 times.
✓ Branch 164 → 165 taken 10534 times.
|
36935 | for (const Function *manifestation : node->manifestations) { |
| 301 |
1/2✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 15867 times.
|
15867 | assert(manifestation->entry != nullptr); |
| 302 | |||
| 303 | // Check if the manifestation is substantiated or not public and not used by anybody | ||
| 304 |
2/4✓ Branch 8 → 9 taken 15867 times.
✗ Branch 8 → 217 not taken.
✓ Branch 9 → 10 taken 15867 times.
✗ Branch 9 → 217 not taken.
|
15867 | const bool isPublic = manifestation->entry->getQualType().isPublic(); |
| 305 |
9/10✓ Branch 10 → 11 taken 15867 times.
✗ Branch 10 → 217 not taken.
✓ Branch 11 → 12 taken 11261 times.
✓ Branch 11 → 14 taken 4606 times.
✓ Branch 12 → 13 taken 1622 times.
✓ Branch 12 → 15 taken 9639 times.
✓ Branch 13 → 14 taken 18 times.
✓ Branch 13 → 15 taken 1604 times.
✓ Branch 16 → 17 taken 4624 times.
✓ Branch 16 → 18 taken 11243 times.
|
15867 | if (!manifestation->isFullySubstantiated() || (!isPublic && !manifestation->used)) { |
| 306 | 4624 | manIdx++; // Increment symbolTypeIndex | |
| 307 | 4624 | continue; | |
| 308 | } | ||
| 309 |
1/2✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 11243 times.
|
11243 | assert(manifestation->alreadyTypeChecked); |
| 310 | |||
| 311 | // Change to struct scope | ||
| 312 |
2/2✓ Branch 23 → 24 taken 9578 times.
✓ Branch 23 → 32 taken 1665 times.
|
11243 | if (manifestation->isMethod()) { |
| 313 | 9578 | const QualType &thisType = manifestation->thisType; | |
| 314 |
3/6✓ Branch 24 → 25 taken 9578 times.
✗ Branch 24 → 173 not taken.
✓ Branch 25 → 26 taken 9578 times.
✗ Branch 25 → 173 not taken.
✓ Branch 26 → 27 taken 9578 times.
✗ Branch 26 → 173 not taken.
|
9578 | const std::string scopeName = Struct::getScopeName(thisType.getSubType(), thisType.getTemplateTypes()); |
| 315 |
1/2✓ Branch 27 → 28 taken 9578 times.
✗ Branch 27 → 171 not taken.
|
9578 | currentScope = currentScope->getChildScope(scopeName); |
| 316 |
1/2✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 9578 times.
|
9578 | assert(currentScope != nullptr); |
| 317 | 9578 | } | |
| 318 | |||
| 319 | // Change scope | ||
| 320 |
2/4✓ Branch 32 → 33 taken 11243 times.
✗ Branch 32 → 176 not taken.
✓ Branch 33 → 34 taken 11243 times.
✗ Branch 33 → 174 not taken.
|
11243 | currentScope = currentScope->getChildScope(manifestation->getScopeName()); |
| 321 |
1/2✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 11243 times.
|
11243 | assert(currentScope != nullptr); |
| 322 | |||
| 323 | // Get 'this' entry | ||
| 324 | 11243 | std::vector<std::pair<std::string, const SymbolTableEntry *>> paramInfoList; | |
| 325 |
1/2✓ Branch 37 → 38 taken 11243 times.
✗ Branch 37 → 213 not taken.
|
11243 | std::vector<llvm::Type *> paramTypes; |
| 326 |
2/2✓ Branch 40 → 41 taken 9578 times.
✓ Branch 40 → 55 taken 1665 times.
|
11243 | if (manifestation->isMethod()) { |
| 327 |
1/2✓ Branch 43 → 44 taken 9578 times.
✗ Branch 43 → 179 not taken.
|
28734 | const SymbolTableEntry *thisEntry = currentScope->lookupStrict(THIS_VARIABLE_NAME); |
| 328 |
1/2✗ Branch 49 → 50 not taken.
✓ Branch 49 → 51 taken 9578 times.
|
9578 | assert(thisEntry != nullptr); |
| 329 |
1/2✓ Branch 51 → 52 taken 9578 times.
✗ Branch 51 → 184 not taken.
|
9578 | paramInfoList.emplace_back(THIS_VARIABLE_NAME, thisEntry); |
| 330 |
2/4✓ Branch 52 → 53 taken 9578 times.
✗ Branch 52 → 183 not taken.
✓ Branch 53 → 54 taken 9578 times.
✗ Branch 53 → 183 not taken.
|
9578 | paramTypes.push_back(builder.getPtrTy()); |
| 331 | } | ||
| 332 | |||
| 333 | // Visit parameters | ||
| 334 | 11243 | size_t argIdx = 0; | |
| 335 |
2/2✓ Branch 55 → 56 taken 8682 times.
✓ Branch 55 → 74 taken 2561 times.
|
11243 | if (node->hasParams) { |
| 336 | 8682 | const size_t numOfParams = manifestation->paramList.size(); | |
| 337 |
1/2✓ Branch 57 → 58 taken 8682 times.
✗ Branch 57 → 213 not taken.
|
8682 | paramInfoList.reserve(numOfParams); |
| 338 |
1/2✓ Branch 58 → 59 taken 8682 times.
✗ Branch 58 → 213 not taken.
|
8682 | paramTypes.reserve(numOfParams); |
| 339 |
2/2✓ Branch 73 → 60 taken 12338 times.
✓ Branch 73 → 74 taken 8682 times.
|
21020 | for (; argIdx < numOfParams; argIdx++) { |
| 340 |
1/2✓ Branch 60 → 61 taken 12338 times.
✗ Branch 60 → 188 not taken.
|
12338 | const DeclStmtNode *param = node->paramLst->params.at(argIdx); |
| 341 | // Get symbol table entry of param | ||
| 342 |
1/2✓ Branch 61 → 62 taken 12338 times.
✗ Branch 61 → 188 not taken.
|
12338 | const SymbolTableEntry *paramSymbol = currentScope->lookupStrict(param->varName); |
| 343 |
1/2✗ Branch 64 → 65 not taken.
✓ Branch 64 → 66 taken 12338 times.
|
12338 | assert(paramSymbol != nullptr); |
| 344 |
2/4✓ Branch 66 → 67 taken 12338 times.
✗ Branch 66 → 187 not taken.
✓ Branch 67 → 68 taken 12338 times.
✗ Branch 67 → 185 not taken.
|
12338 | const QualType paramSymbolType = manifestation->getParamTypes().at(argIdx); |
| 345 | // Retrieve type of param | ||
| 346 |
1/2✓ Branch 69 → 70 taken 12338 times.
✗ Branch 69 → 188 not taken.
|
12338 | llvm::Type *paramType = paramSymbolType.toLLVMType(sourceFile); |
| 347 | // Add it to the lists | ||
| 348 |
1/2✓ Branch 70 → 71 taken 12338 times.
✗ Branch 70 → 188 not taken.
|
12338 | paramInfoList.emplace_back(param->varName, paramSymbol); |
| 349 |
1/2✓ Branch 71 → 72 taken 12338 times.
✗ Branch 71 → 188 not taken.
|
12338 | paramTypes.push_back(paramType); |
| 350 | } | ||
| 351 | } | ||
| 352 | |||
| 353 | // Get return type | ||
| 354 |
1/2✓ Branch 74 → 75 taken 11243 times.
✗ Branch 74 → 213 not taken.
|
11243 | llvm::Type *returnType = builder.getVoidTy(); |
| 355 | |||
| 356 | // Create procedure or implement declared procedure | ||
| 357 |
1/2✓ Branch 75 → 76 taken 11243 times.
✗ Branch 75 → 213 not taken.
|
11243 | const std::string mangledName = manifestation->getMangledName(); |
| 358 |
1/2✓ Branch 77 → 78 taken 11243 times.
✗ Branch 77 → 189 not taken.
|
11243 | llvm::FunctionType *procType = llvm::FunctionType::get(returnType, paramTypes, false); |
| 359 |
1/2✓ Branch 79 → 80 taken 11243 times.
✗ Branch 79 → 190 not taken.
|
11243 | module->getOrInsertFunction(mangledName, procType); |
| 360 |
1/2✓ Branch 81 → 82 taken 11243 times.
✗ Branch 81 → 191 not taken.
|
11243 | llvm::Function *proc = module->getFunction(mangledName); |
| 361 |
1/2✓ Branch 82 → 83 taken 11243 times.
✗ Branch 82 → 211 not taken.
|
11243 | updateAddress(node->entry, proc); |
| 362 |
1/2✓ Branch 83 → 84 taken 11243 times.
✗ Branch 83 → 211 not taken.
|
11243 | setLLVMFunction(manifestation, proc); |
| 363 |
2/4✓ Branch 84 → 85 taken 11243 times.
✗ Branch 84 → 211 not taken.
✗ Branch 85 → 86 not taken.
✓ Branch 85 → 87 taken 11243 times.
|
11243 | assert(proc->empty()); |
| 364 | |||
| 365 | // Set attributes to procedure | ||
| 366 |
2/4✓ Branch 87 → 88 taken 11243 times.
✗ Branch 87 → 211 not taken.
✓ Branch 88 → 89 taken 11243 times.
✗ Branch 88 → 211 not taken.
|
11243 | proc->setLinkage(getSymbolLinkageType(isPublic)); |
| 367 |
1/2✓ Branch 89 → 90 taken 11243 times.
✗ Branch 89 → 211 not taken.
|
11243 | proc->setDSOLocal(isSymbolDSOLocal(isPublic)); |
| 368 |
4/6✓ Branch 91 → 92 taken 11243 times.
✗ Branch 91 → 211 not taken.
✓ Branch 92 → 93 taken 11243 times.
✗ Branch 92 → 211 not taken.
✓ Branch 93 → 94 taken 1204 times.
✓ Branch 93 → 95 taken 10039 times.
|
11243 | if (manifestation->entry->getQualType().isInline()) |
| 369 |
1/2✓ Branch 94 → 95 taken 1204 times.
✗ Branch 94 → 211 not taken.
|
1204 | proc->addFnAttr(llvm::Attribute::AlwaysInline); |
| 370 |
1/2✓ Branch 95 → 96 taken 11243 times.
✗ Branch 95 → 211 not taken.
|
11243 | enableFunctionInstrumentation(proc); |
| 371 | |||
| 372 | // Set attributes to function parameters | ||
| 373 |
1/2✓ Branch 96 → 97 taken 11243 times.
✗ Branch 96 → 211 not taken.
|
11243 | setParamAttrs(proc, paramInfoList); |
| 374 | |||
| 375 | // Add debug info | ||
| 376 |
1/2✓ Branch 97 → 98 taken 11243 times.
✗ Branch 97 → 211 not taken.
|
11243 | diGenerator.generateFunctionDebugInfo(proc, manifestation); |
| 377 |
1/2✓ Branch 98 → 99 taken 11243 times.
✗ Branch 98 → 211 not taken.
|
11243 | diGenerator.setSourceLocation(node); |
| 378 | |||
| 379 | // Create entry block | ||
| 380 |
1/2✓ Branch 102 → 103 taken 11243 times.
✗ Branch 102 → 192 not taken.
|
11243 | llvm::BasicBlock *bEntry = createBlock(); |
| 381 |
1/2✓ Branch 105 → 106 taken 11243 times.
✗ Branch 105 → 211 not taken.
|
11243 | switchToBlock(bEntry, proc); |
| 382 | |||
| 383 | // Reset alloca insert markers to this block | ||
| 384 | 11243 | allocaInsertBlock = bEntry; | |
| 385 | 11243 | allocaInsertInst = nullptr; | |
| 386 | |||
| 387 | // Store procedure argument values | ||
| 388 |
3/4✓ Branch 106 → 107 taken 11243 times.
✗ Branch 106 → 205 not taken.
✓ Branch 128 → 109 taken 21916 times.
✓ Branch 128 → 129 taken 11243 times.
|
33159 | for (auto &arg : proc->args()) { |
| 389 | // Get information about the parameter | ||
| 390 | 21916 | const size_t argNumber = arg.getArgNo(); | |
| 391 |
2/4✓ Branch 110 → 111 taken 21916 times.
✗ Branch 110 → 198 not taken.
✓ Branch 111 → 112 taken 21916 times.
✗ Branch 111 → 198 not taken.
|
21916 | auto [paramName, paramSymbol] = paramInfoList.at(argNumber); |
| 392 |
1/2✗ Branch 114 → 115 not taken.
✓ Branch 114 → 116 taken 21916 times.
|
21916 | assert(paramSymbol != nullptr); |
| 393 | // Allocate space for it | ||
| 394 |
2/4✓ Branch 116 → 117 taken 21916 times.
✗ Branch 116 → 198 not taken.
✓ Branch 117 → 118 taken 21916 times.
✗ Branch 117 → 198 not taken.
|
21916 | llvm::Value *paramAddress = insertAlloca(paramSymbol->getQualType(), paramName); |
| 395 | // Update the symbol table entry | ||
| 396 |
1/2✓ Branch 118 → 119 taken 21916 times.
✗ Branch 118 → 198 not taken.
|
21916 | updateAddress(paramSymbol, paramAddress); |
| 397 | // Set source location | ||
| 398 |
1/2✓ Branch 119 → 120 taken 21916 times.
✗ Branch 119 → 198 not taken.
|
21916 | diGenerator.setSourceLocation(paramSymbol->declNode); |
| 399 | // Generate debug info to declare variable | ||
| 400 |
1/2✓ Branch 120 → 121 taken 21916 times.
✗ Branch 120 → 198 not taken.
|
21916 | diGenerator.generateLocalVarDebugInfo(paramName, paramAddress, argNumber + 1); |
| 401 | // Store the value at the new address | ||
| 402 |
1/2✓ Branch 121 → 122 taken 21916 times.
✗ Branch 121 → 198 not taken.
|
21916 | insertStore(&arg, paramAddress); |
| 403 |
1/4✗ Branch 122 → 123 not taken.
✓ Branch 122 → 124 taken 21916 times.
✗ Branch 198 → 199 not taken.
✗ Branch 198 → 200 not taken.
|
43832 | } |
| 404 | |||
| 405 | // Store the default values for optional procedure args | ||
| 406 |
2/2✓ Branch 129 → 130 taken 8682 times.
✓ Branch 129 → 140 taken 2561 times.
|
11243 | if (node->paramLst) { |
| 407 |
1/2✓ Branch 130 → 131 taken 8682 times.
✗ Branch 130 → 209 not taken.
|
8682 | const std::vector<DeclStmtNode *> params = node->paramLst->params; |
| 408 |
2/2✓ Branch 137 → 132 taken 686 times.
✓ Branch 137 → 138 taken 8682 times.
|
9368 | for (; argIdx < params.size(); argIdx++) |
| 409 |
2/4✓ Branch 132 → 133 taken 686 times.
✗ Branch 132 → 206 not taken.
✓ Branch 133 → 134 taken 686 times.
✗ Branch 133 → 206 not taken.
|
686 | visit(params.at(argIdx)); |
| 410 | 8682 | } | |
| 411 | |||
| 412 | // Generate special ctor preamble before generating the body to store VTable, default field values, etc. if required | ||
| 413 |
2/2✓ Branch 140 → 141 taken 5392 times.
✓ Branch 140 → 142 taken 5851 times.
|
11243 | if (node->isCtor) { |
| 414 | 5392 | isInCtorBody = true; | |
| 415 |
1/2✓ Branch 141 → 142 taken 5392 times.
✗ Branch 141 → 211 not taken.
|
5392 | generateCtorBodyPreamble(currentScope); |
| 416 | } | ||
| 417 | |||
| 418 | // Visit procedure body | ||
| 419 |
1/2✓ Branch 142 → 143 taken 11243 times.
✗ Branch 142 → 210 not taken.
|
11243 | visit(node->body); |
| 420 | |||
| 421 |
2/2✓ Branch 144 → 145 taken 5392 times.
✓ Branch 144 → 146 taken 5851 times.
|
11243 | if (node->isCtor) |
| 422 | 5392 | isInCtorBody = false; | |
| 423 | |||
| 424 | // Create return statement if the block is not terminated yet | ||
| 425 |
2/2✓ Branch 146 → 147 taken 11061 times.
✓ Branch 146 → 148 taken 182 times.
|
11243 | if (!blockAlreadyTerminated) |
| 426 |
1/2✓ Branch 147 → 148 taken 11061 times.
✗ Branch 147 → 211 not taken.
|
11061 | builder.CreateRetVoid(); |
| 427 | |||
| 428 | // Conclude debug info for procedure | ||
| 429 |
1/2✓ Branch 148 → 149 taken 11243 times.
✗ Branch 148 → 211 not taken.
|
11243 | diGenerator.concludeFunctionDebugInfo(); |
| 430 | |||
| 431 | // Verify procedure | ||
| 432 |
1/2✓ Branch 149 → 150 taken 11243 times.
✗ Branch 149 → 211 not taken.
|
11243 | verifyFunction(proc, node->codeLoc); |
| 433 | |||
| 434 | // Change to root scope | ||
| 435 | 11243 | currentScope = rootScope; | |
| 436 | |||
| 437 | 11243 | manIdx++; // Increment symbolTypeIndex | |
| 438 | 11243 | } | |
| 439 | 10534 | manIdx = 0; // Reset the symbolTypeIndex | |
| 440 | |||
| 441 | // Ensure that we are at the root scope again | ||
| 442 |
1/2✗ Branch 165 → 166 not taken.
✓ Branch 165 → 167 taken 10534 times.
|
10534 | assert(currentScope == rootScope); |
| 443 | |||
| 444 |
1/2✓ Branch 167 → 168 taken 10534 times.
✗ Branch 167 → 219 not taken.
|
21068 | return nullptr; |
| 445 | } | ||
| 446 | |||
| 447 | 33180 | void IRGenerator::setParamAttrs(llvm::Function *function, const ParamInfoList ¶mInfo) const { | |
| 448 |
1/2✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 33180 times.
|
33180 | assert(function->arg_size() == paramInfo.size()); |
| 449 |
2/2✓ Branch 30 → 7 taken 57415 times.
✓ Branch 30 → 31 taken 33180 times.
|
90595 | for (size_t i = 0; i < paramInfo.size(); i++) { |
| 450 | 57415 | const QualType ¶mType = paramInfo.at(i).second->getQualType(); | |
| 451 | |||
| 452 | // NoUndef attribute | ||
| 453 | 57415 | function->addParamAttr(i, llvm::Attribute::NoUndef); | |
| 454 | |||
| 455 |
2/2✓ Branch 11 → 12 taken 25319 times.
✓ Branch 11 → 25 taken 32096 times.
|
57415 | if (paramType.isPtr()) { |
| 456 | // NonNull attribute | ||
| 457 | 25319 | function->addParamAttr(i, llvm::Attribute::NonNull); | |
| 458 | // Dereferenceable attribute | ||
| 459 |
2/4✓ Branch 13 → 14 taken 25319 times.
✗ Branch 13 → 32 not taken.
✓ Branch 14 → 15 taken 25319 times.
✗ Branch 14 → 32 not taken.
|
25319 | llvm::Type *pointeeType = paramType.getContained().toLLVMType(sourceFile); |
| 460 |
1/2✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 25319 times.
|
25319 | assert(pointeeType != nullptr); |
| 461 |
3/6✓ Branch 18 → 19 taken 25319 times.
✗ Branch 18 → 33 not taken.
✓ Branch 19 → 20 taken 25319 times.
✗ Branch 19 → 33 not taken.
✓ Branch 20 → 21 taken 25319 times.
✗ Branch 20 → 33 not taken.
|
25319 | function->addDereferenceableParamAttr(i, module->getDataLayout().getTypeStoreSize(pointeeType)); |
| 462 | // Alignment attribute | ||
| 463 | 25319 | function->addParamAttr(i, llvm::Attribute::getWithAlignment(context, module->getDataLayout().getABITypeAlign(pointeeType))); | |
| 464 | } | ||
| 465 | |||
| 466 | // ZExt or SExt attribute | ||
| 467 |
2/2✓ Branch 26 → 27 taken 6861 times.
✓ Branch 26 → 28 taken 50554 times.
|
57415 | if (const llvm::Attribute::AttrKind extAttrKind = getExtAttrKindForType(paramType); extAttrKind != llvm::Attribute::None) |
| 468 | 6861 | function->addParamAttr(i, extAttrKind); | |
| 469 | } | ||
| 470 | 33180 | } | |
| 471 | |||
| 472 | 21937 | void IRGenerator::setFunctionReturnValAttrs(llvm::Function *function, const QualType &returnType) const { | |
| 473 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 21937 times.
|
21937 | if (returnType.is(TY_DYN)) |
| 474 | ✗ | return; | |
| 475 | |||
| 476 | // NoUndef attribute | ||
| 477 | 21937 | function->addRetAttr(llvm::Attribute::NoUndef); | |
| 478 | // ZExt or SExt attribute | ||
| 479 |
2/2✓ Branch 7 → 8 taken 7819 times.
✓ Branch 7 → 9 taken 14118 times.
|
21937 | if (const llvm::Attribute::AttrKind extAttrKind = getExtAttrKindForType(returnType); extAttrKind != llvm::Attribute::None) |
| 480 | 7819 | function->addRetAttr(extAttrKind); | |
| 481 | } | ||
| 482 | |||
| 483 | 211145 | llvm::Attribute::AttrKind IRGenerator::getExtAttrKindForType(const QualType &type) const { | |
| 484 |
1/2✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 211145 times.
|
211145 | if (type.is(TY_DYN)) |
| 485 | ✗ | return llvm::Attribute::None; | |
| 486 | |||
| 487 | 211145 | const llvm::Type *llvmType = type.toLLVMType(sourceFile); | |
| 488 |
1/2✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 211145 times.
|
211145 | const unsigned int maxExtWidth = cliOptions.targetTriple.isPPC() ? 64 : 32; |
| 489 |
6/6✓ Branch 11 → 12 taken 70064 times.
✓ Branch 11 → 15 taken 141081 times.
✓ Branch 13 → 14 taken 33314 times.
✓ Branch 13 → 15 taken 36750 times.
✓ Branch 16 → 17 taken 33314 times.
✓ Branch 16 → 22 taken 177831 times.
|
211145 | if (llvmType->isIntegerTy() && llvmType->getIntegerBitWidth() < maxExtWidth) |
| 490 |
2/2✓ Branch 18 → 19 taken 2232 times.
✓ Branch 18 → 20 taken 31082 times.
|
33314 | return type.isSigned() ? llvm::Attribute::SExt : llvm::Attribute::ZExt; |
| 491 | 177831 | return llvm::Attribute::None; | |
| 492 | } | ||
| 493 | |||
| 494 | 2886 | std::any IRGenerator::visitStructDef(const StructDefNode *node) { | |
| 495 | // Get all substantiated structs which result from this struct def | ||
| 496 |
1/2✓ Branch 2 → 3 taken 2886 times.
✗ Branch 2 → 128 not taken.
|
2886 | std::vector<Struct *> manifestations = node->structManifestations; |
| 497 | |||
| 498 | // Sort the manifestations to prevent generating the struct types in the wrong order (in case of dependencies between structs) | ||
| 499 | 5171 | const auto comp = [](const Struct *lhs, const Struct *rhs) { return lhs->manifestationIndex < rhs->manifestationIndex; }; | |
| 500 |
1/2✓ Branch 3 → 4 taken 2886 times.
✗ Branch 3 → 126 not taken.
|
2886 | std::ranges::sort(manifestations, comp); |
| 501 | |||
| 502 |
2/2✓ Branch 83 → 6 taken 4912 times.
✓ Branch 83 → 84 taken 2886 times.
|
10684 | for (Struct *spiceStruct : manifestations) { |
| 503 | // Skip structs, that are not fully substantiated | ||
| 504 |
3/4✓ Branch 8 → 9 taken 4912 times.
✗ Branch 8 → 123 not taken.
✓ Branch 9 → 10 taken 733 times.
✓ Branch 9 → 11 taken 4179 times.
|
4912 | if (!spiceStruct->isFullySubstantiated()) |
| 505 | 734 | continue; | |
| 506 | |||
| 507 | // Do not generate this struct if it is private and used by nobody | ||
| 508 |
8/10✓ Branch 11 → 12 taken 845 times.
✓ Branch 11 → 16 taken 3334 times.
✓ Branch 12 → 13 taken 845 times.
✗ Branch 12 → 123 not taken.
✓ Branch 13 → 14 taken 845 times.
✗ Branch 13 → 123 not taken.
✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 16 taken 844 times.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 19 taken 4178 times.
|
4179 | if (!spiceStruct->used && !spiceStruct->entry->getQualType().isPublic()) |
| 509 | 1 | continue; | |
| 510 | |||
| 511 | // Change scope to struct scope, specific to substantiation | ||
| 512 | 4178 | currentScope = spiceStruct->scope; | |
| 513 |
1/2✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 4178 times.
|
4178 | assert(currentScope); |
| 514 | |||
| 515 | // Set LLVM type to the struct entry | ||
| 516 | 4178 | const SymbolTableEntry *structEntry = spiceStruct->entry; | |
| 517 |
1/2✗ Branch 21 → 22 not taken.
✓ Branch 21 → 23 taken 4178 times.
|
4178 | assert(structEntry != nullptr); |
| 518 | |||
| 519 | // Generate VTable if required | ||
| 520 |
2/2✓ Branch 23 → 24 taken 1112 times.
✓ Branch 23 → 27 taken 3066 times.
|
4178 | if (node->emitVTable) { |
| 521 |
1/2✓ Branch 24 → 25 taken 1112 times.
✗ Branch 24 → 123 not taken.
|
1112 | generateVTable(spiceStruct); |
| 522 |
1/2✓ Branch 25 → 26 taken 1112 times.
✗ Branch 25 → 89 not taken.
|
2224 | deferredVTableInitializations.emplace_back([=, this]() { generateVTableInitializer(spiceStruct); }, false); |
| 523 | } | ||
| 524 | |||
| 525 | // Generate default ctor if required | ||
| 526 |
1/2✓ Branch 27 → 28 taken 4178 times.
✗ Branch 27 → 123 not taken.
|
4178 | const QualType &thisType = structEntry->getQualType(); |
| 527 |
2/4✓ Branch 31 → 32 taken 4178 times.
✗ Branch 31 → 93 not taken.
✓ Branch 32 → 33 taken 4178 times.
✗ Branch 32 → 91 not taken.
|
12534 | const Function *ctorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, thisType, {}, true); |
| 528 |
4/4✓ Branch 36 → 37 taken 933 times.
✓ Branch 36 → 39 taken 3245 times.
✓ Branch 37 → 38 taken 154 times.
✓ Branch 37 → 39 taken 779 times.
|
4178 | if (ctorFunc != nullptr && ctorFunc->implicitDefault) |
| 529 |
1/2✓ Branch 38 → 39 taken 154 times.
✗ Branch 38 → 123 not taken.
|
154 | generateDefaultCtor(ctorFunc); |
| 530 | |||
| 531 | // Generate default copy ctor if required | ||
| 532 |
2/4✓ Branch 39 → 40 taken 4178 times.
✗ Branch 39 → 104 not taken.
✓ Branch 43 → 44 taken 4178 times.
✗ Branch 43 → 100 not taken.
|
12534 | const ArgList args = {{thisType.toConstRef(node), false /* always non-temporary */}}; |
| 533 |
2/4✓ Branch 47 → 48 taken 4178 times.
✗ Branch 47 → 108 not taken.
✓ Branch 48 → 49 taken 4178 times.
✗ Branch 48 → 106 not taken.
|
4178 | const Function *copyCtorFunc = FunctionManager::lookup(currentScope, CTOR_FUNCTION_NAME, thisType, args, true); |
| 534 |
4/4✓ Branch 51 → 52 taken 2054 times.
✓ Branch 51 → 54 taken 2124 times.
✓ Branch 52 → 53 taken 1637 times.
✓ Branch 52 → 54 taken 417 times.
|
4178 | if (copyCtorFunc != nullptr && copyCtorFunc->implicitDefault) |
| 535 |
1/2✓ Branch 53 → 54 taken 1637 times.
✗ Branch 53 → 121 not taken.
|
1637 | generateDefaultCopyCtor(copyCtorFunc); |
| 536 | |||
| 537 | // Generate default move ctor if required. We can't use FunctionManager::lookup with a non-const ref arg | ||
| 538 | // here, because the lookup permits const-param-to-non-const-arg matching ("constify") and may return the | ||
| 539 | // copy ctor as a false positive. findMoveCtor scans the manifestations directly and only matches the | ||
| 540 | // strict move ctor signature. | ||
| 541 |
5/6✓ Branch 54 → 55 taken 4178 times.
✗ Branch 54 → 121 not taken.
✓ Branch 55 → 56 taken 14 times.
✓ Branch 55 → 58 taken 4164 times.
✓ Branch 56 → 57 taken 10 times.
✓ Branch 56 → 58 taken 4 times.
|
4178 | if (const Function *moveCtorFunc = FunctionManager::findMoveCtor(currentScope); moveCtorFunc && moveCtorFunc->implicitDefault) |
| 542 |
1/2✓ Branch 57 → 58 taken 10 times.
✗ Branch 57 → 121 not taken.
|
10 | generateDefaultMoveCtor(moveCtorFunc); |
| 543 | |||
| 544 | // Generate default dtor if required | ||
| 545 |
2/4✓ Branch 61 → 62 taken 4178 times.
✗ Branch 61 → 114 not taken.
✓ Branch 62 → 63 taken 4178 times.
✗ Branch 62 → 112 not taken.
|
12534 | const Function *dtorFunc = FunctionManager::lookup(currentScope, DTOR_FUNCTION_NAME, thisType, {}, true); |
| 546 |
4/4✓ Branch 66 → 67 taken 2099 times.
✓ Branch 66 → 69 taken 2079 times.
✓ Branch 67 → 68 taken 1777 times.
✓ Branch 67 → 69 taken 322 times.
|
4178 | if (dtorFunc != nullptr && dtorFunc->implicitDefault) |
| 547 |
1/2✓ Branch 68 → 69 taken 1777 times.
✗ Branch 68 → 121 not taken.
|
1777 | generateDefaultDtor(dtorFunc); |
| 548 | |||
| 549 | // Return to root scope | ||
| 550 | 4178 | currentScope = rootScope; | |
| 551 |
1/2✗ Branch 69 → 70 not taken.
✓ Branch 69 → 71 taken 4178 times.
|
4178 | assert(currentScope); |
| 552 | 4178 | } | |
| 553 | |||
| 554 |
1/2✓ Branch 84 → 85 taken 2886 times.
✗ Branch 84 → 125 not taken.
|
5772 | return nullptr; |
| 555 | 2886 | } | |
| 556 | |||
| 557 | 350 | std::any IRGenerator::visitInterfaceDef(const InterfaceDefNode *node) { | |
| 558 | // Get all substantiated structs which result from this struct def | ||
| 559 |
1/2✓ Branch 2 → 3 taken 350 times.
✗ Branch 2 → 43 not taken.
|
350 | std::vector<Interface *> manifestations = node->interfaceManifestations; |
| 560 | |||
| 561 | // Sort the manifestations to prevent generating the struct types in the wrong order (in case of dependencies between structs) | ||
| 562 | 2600 | const auto comp = [](const Interface *lhs, const Interface *rhs) { return lhs->manifestationIndex < rhs->manifestationIndex; }; | |
| 563 |
1/2✓ Branch 3 → 4 taken 350 times.
✗ Branch 3 → 41 not taken.
|
350 | std::ranges::sort(manifestations, comp); |
| 564 | |||
| 565 |
2/2✓ Branch 31 → 6 taken 1288 times.
✓ Branch 31 → 32 taken 350 times.
|
1988 | for (Interface *spiceInterface : manifestations) { |
| 566 | // Skip interfaces, that are not fully substantiated | ||
| 567 |
3/4✓ Branch 8 → 9 taken 1288 times.
✗ Branch 8 → 39 not taken.
✓ Branch 9 → 10 taken 149 times.
✓ Branch 9 → 11 taken 1139 times.
|
1288 | if (!spiceInterface->isFullySubstantiated()) |
| 568 | 149 | continue; | |
| 569 | |||
| 570 | // Do not generate this interface if it is private and used by nobody | ||
| 571 |
8/10✓ Branch 11 → 12 taken 21 times.
✓ Branch 11 → 16 taken 1118 times.
✓ Branch 12 → 13 taken 21 times.
✗ Branch 12 → 39 not taken.
✓ Branch 13 → 14 taken 21 times.
✗ Branch 13 → 39 not taken.
✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 16 taken 20 times.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 19 taken 1138 times.
|
1139 | if (!spiceInterface->used && !spiceInterface->entry->getQualType().isPublic()) |
| 572 | 1 | continue; | |
| 573 | |||
| 574 | // Generate VTable information | ||
| 575 |
1/2✓ Branch 19 → 20 taken 1138 times.
✗ Branch 19 → 39 not taken.
|
1138 | generateVTable(spiceInterface); |
| 576 |
1/2✓ Branch 20 → 21 taken 1138 times.
✗ Branch 20 → 37 not taken.
|
2276 | deferredVTableInitializations.emplace_back([=, this]() { generateVTableInitializer(spiceInterface); }, false); |
| 577 | } | ||
| 578 | |||
| 579 |
1/2✓ Branch 32 → 33 taken 350 times.
✗ Branch 32 → 40 not taken.
|
700 | return nullptr; |
| 580 | 350 | } | |
| 581 | |||
| 582 | 368 | std::any IRGenerator::visitEnumDef(const EnumDefNode *node) { | |
| 583 |
1/2✓ Branch 2 → 3 taken 368 times.
✗ Branch 2 → 6 not taken.
|
736 | return nullptr; // Noop (enums are high-level semantic-only structures) |
| 584 | } | ||
| 585 | |||
| 586 | 1865 | std::any IRGenerator::visitGenericTypeDef(const GenericTypeDefNode *node) { | |
| 587 |
1/2✓ Branch 2 → 3 taken 1865 times.
✗ Branch 2 → 6 not taken.
|
3730 | return nullptr; // Noop (generic types are high-level semantic-only structures) |
| 588 | } | ||
| 589 | |||
| 590 | 340 | std::any IRGenerator::visitAliasDef(const AliasDefNode *node) { | |
| 591 |
1/2✓ Branch 2 → 3 taken 340 times.
✗ Branch 2 → 6 not taken.
|
680 | return nullptr; // Noop (alias definitions are high-level semantic-only structures) |
| 592 | } | ||
| 593 | |||
| 594 | 2370 | std::any IRGenerator::visitGlobalVarDef(const GlobalVarDefNode *node) { | |
| 595 | // Retrieve some information about the variable | ||
| 596 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 2370 times.
|
2370 | assert(node->entry != nullptr); |
| 597 | 2370 | const QualType &entryType = node->entry->getQualType(); | |
| 598 | 2370 | const bool isPublic = entryType.isPublic(); | |
| 599 | 2370 | const bool isConst = entryType.isConst(); | |
| 600 | |||
| 601 | // Get correct type and linkage type | ||
| 602 |
2/4✓ Branch 7 → 8 taken 2370 times.
✗ Branch 7 → 39 not taken.
✓ Branch 8 → 9 taken 2370 times.
✗ Branch 8 → 37 not taken.
|
2370 | const auto varType = std::any_cast<llvm::Type *>(visit(node->dataType)); |
| 603 | |||
| 604 | // Create global var | ||
| 605 |
1/2✓ Branch 11 → 12 taken 2370 times.
✗ Branch 11 → 40 not taken.
|
2370 | llvm::Value *varAddress = module->getOrInsertGlobal(node->varName, varType); |
| 606 |
1/2✓ Branch 13 → 14 taken 2370 times.
✗ Branch 13 → 41 not taken.
|
2370 | llvm::GlobalVariable *var = module->getNamedGlobal(node->varName); |
| 607 | // Set some attributes, based on the given information | ||
| 608 | 2370 | var->setConstant(isConst); | |
| 609 | 2370 | var->setLinkage(getSymbolLinkageType(isPublic)); | |
| 610 | 2370 | var->setDSOLocal(isSymbolDSOLocal(isPublic)); | |
| 611 | |||
| 612 | // Set initializer | ||
| 613 |
1/2✓ Branch 19 → 20 taken 2370 times.
✗ Branch 19 → 24 not taken.
|
2370 | if (node->hasValue) { // Set the constant value as variable initializer |
| 614 |
2/4✓ Branch 20 → 21 taken 2370 times.
✗ Branch 20 → 44 not taken.
✓ Branch 21 → 22 taken 2370 times.
✗ Branch 21 → 42 not taken.
|
2370 | const auto constantValue = std::any_cast<llvm::Constant *>(visit(node->constant)); |
| 615 | 2370 | var->setInitializer(constantValue); | |
| 616 | ✗ | } else if (cliOptions.buildMode != BuildMode::RELEASE) { // Set the default value as variable initializer | |
| 617 | ✗ | assert(cliOptions.buildMode == BuildMode::DEBUG || cliOptions.buildMode == BuildMode::TEST); | |
| 618 | ✗ | llvm::Constant *constantValue = getDefaultValueForSymbolType(node->entry->getQualType()); | |
| 619 | ✗ | var->setInitializer(constantValue); | |
| 620 | } | ||
| 621 | |||
| 622 | 2370 | updateAddress(node->entry, varAddress); | |
| 623 | |||
| 624 | // Add debug info | ||
| 625 | 2370 | diGenerator.generateGlobalVarDebugInfo(var, node->entry); | |
| 626 | |||
| 627 |
1/2✓ Branch 33 → 34 taken 2370 times.
✗ Branch 33 → 45 not taken.
|
4740 | return nullptr; |
| 628 | } | ||
| 629 | |||
| 630 | 2939 | std::any IRGenerator::visitExtDecl(const ExtDeclNode *node) { | |
| 631 | // Get return type | ||
| 632 | 2939 | const Function *spiceFunc = node->extFunction; | |
| 633 |
1/2✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 2939 times.
|
2939 | assert(spiceFunc != nullptr); |
| 634 |
1/2✓ Branch 4 → 5 taken 2939 times.
✗ Branch 4 → 100 not taken.
|
2939 | llvm::Type *returnType = builder.getVoidTy(); |
| 635 |
3/4✓ Branch 5 → 6 taken 2939 times.
✗ Branch 5 → 100 not taken.
✓ Branch 6 → 7 taken 1953 times.
✓ Branch 6 → 9 taken 986 times.
|
2939 | if (!spiceFunc->returnType.is(TY_DYN)) |
| 636 |
1/2✓ Branch 7 → 8 taken 1953 times.
✗ Branch 7 → 100 not taken.
|
1953 | returnType = spiceFunc->returnType.toLLVMType(sourceFile); |
| 637 | |||
| 638 | // Get arg types | ||
| 639 | 2939 | std::vector<llvm::Type *> argTypes; | |
| 640 |
1/2✓ Branch 10 → 11 taken 2939 times.
✗ Branch 10 → 98 not taken.
|
2939 | argTypes.reserve(spiceFunc->paramList.size()); |
| 641 |
3/4✓ Branch 11 → 12 taken 2939 times.
✗ Branch 11 → 76 not taken.
✓ Branch 27 → 14 taken 6071 times.
✓ Branch 27 → 28 taken 2939 times.
|
11949 | for (const QualType ¶mType : spiceFunc->getParamTypes()) |
| 642 |
2/4✓ Branch 16 → 17 taken 6071 times.
✗ Branch 16 → 73 not taken.
✓ Branch 17 → 18 taken 6071 times.
✗ Branch 17 → 73 not taken.
|
9010 | argTypes.push_back(paramType.toLLVMType(sourceFile)); |
| 643 | |||
| 644 | // Declare function | ||
| 645 |
4/4✓ Branch 29 → 30 taken 2733 times.
✓ Branch 29 → 32 taken 206 times.
✓ Branch 30 → 31 taken 58 times.
✓ Branch 30 → 32 taken 2675 times.
|
2939 | const bool isVarArg = node->argTypeLst && node->argTypeLst->hasEllipsis; |
| 646 |
1/2✓ Branch 34 → 35 taken 2939 times.
✗ Branch 34 → 77 not taken.
|
2939 | llvm::FunctionType *functionType = llvm::FunctionType::get(returnType, argTypes, isVarArg); |
| 647 |
1/2✓ Branch 35 → 36 taken 2939 times.
✗ Branch 35 → 98 not taken.
|
2939 | const std::string mangledName = spiceFunc->getMangledName(); |
| 648 |
1/2✓ Branch 37 → 38 taken 2939 times.
✗ Branch 37 → 78 not taken.
|
2939 | module->getOrInsertFunction(mangledName, functionType); |
| 649 |
1/2✓ Branch 39 → 40 taken 2939 times.
✗ Branch 39 → 79 not taken.
|
2939 | llvm::Function *fct = module->getFunction(mangledName); |
| 650 | |||
| 651 | // Add noundef attribute to all parameters | ||
| 652 |
2/2✓ Branch 44 → 41 taken 6071 times.
✓ Branch 44 → 45 taken 2939 times.
|
9010 | for (size_t i = 0; i < argTypes.size(); i++) |
| 653 |
1/2✓ Branch 41 → 42 taken 6071 times.
✗ Branch 41 → 96 not taken.
|
6071 | fct->addParamAttr(i, llvm::Attribute::NoUndef); |
| 654 | |||
| 655 | // If the function should be imported as dll, add the dll attribute | ||
| 656 |
10/18✓ Branch 45 → 46 taken 1 time.
✓ Branch 45 → 52 taken 2938 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 2938 times.
✓ Branch 55 → 56 taken 1 time.
✓ Branch 55 → 58 taken 2938 times.
✗ Branch 58 → 59 not taken.
✓ Branch 58 → 67 taken 2939 times.
✗ Branch 80 → 81 not taken.
✗ Branch 80 → 82 not taken.
✗ Branch 84 → 85 not taken.
✗ Branch 84 → 87 not taken.
|
2941 | if (node->attrs && node->attrs->attrLst->hasAttr(ATTR_CORE_LINKER_DLL)) |
| 657 | ✗ | if (node->attrs->attrLst->getAttrValueByName(ATTR_CORE_LINKER_DLL)->boolValue) | |
| 658 | ✗ | fct->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); | |
| 659 | |||
| 660 |
1/2✓ Branch 67 → 68 taken 2939 times.
✗ Branch 67 → 95 not taken.
|
5878 | return nullptr; |
| 661 | 2939 | } | |
| 662 | |||
| 663 | } // namespace spice::compiler | ||
| 664 |