| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2025 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "IRGenerator.h" | ||
| 4 | |||
| 5 | #include <ast/ASTNodes.h> | ||
| 6 | #include <symboltablebuilder/ScopeHandle.h> | ||
| 7 | |||
| 8 | namespace spice::compiler { | ||
| 9 | |||
| 10 | 1996 | std::any IRGenerator::visitUnsafeBlockDef(const UnsafeBlockNode *node) { | |
| 11 |
1/2✓ Branch 2 → 3 taken 1996 times.
✗ Branch 2 → 20 not taken.
|
1996 | diGenerator.setSourceLocation(node); |
| 12 | |||
| 13 | // Change scope | ||
| 14 |
2/4✓ Branch 3 → 4 taken 1996 times.
✗ Branch 3 → 14 not taken.
✓ Branch 4 → 5 taken 1996 times.
✗ Branch 4 → 12 not taken.
|
1996 | ScopeHandle scopeHandle(this, node->getScopeId(), ScopeType::UNSAFE_BODY, node); |
| 15 | |||
| 16 | // Visit instructions in the block | ||
| 17 |
1/2✓ Branch 6 → 7 taken 1996 times.
✗ Branch 6 → 16 not taken.
|
1996 | visit(node->body); |
| 18 | |||
| 19 |
1/2✓ Branch 8 → 9 taken 1996 times.
✗ Branch 8 → 17 not taken.
|
3992 | return nullptr; |
| 20 | 1996 | } | |
| 21 | |||
| 22 | 1175 | std::any IRGenerator::visitForLoop(const ForLoopNode *node) { | |
| 23 |
1/2✓ Branch 2 → 3 taken 1175 times.
✗ Branch 2 → 73 not taken.
|
1175 | diGenerator.setSourceLocation(node); |
| 24 | |||
| 25 | // Create blocks | ||
| 26 |
1/2✓ Branch 3 → 4 taken 1175 times.
✗ Branch 3 → 73 not taken.
|
1175 | const std::string codeLine = node->codeLoc.toPrettyLine(); |
| 27 |
2/4✓ Branch 4 → 5 taken 1175 times.
✗ Branch 4 → 51 not taken.
✓ Branch 5 → 6 taken 1175 times.
✗ Branch 5 → 49 not taken.
|
1175 | llvm::BasicBlock *bHead = createBlock("for.head." + codeLine); |
| 28 |
2/4✓ Branch 7 → 8 taken 1175 times.
✗ Branch 7 → 54 not taken.
✓ Branch 8 → 9 taken 1175 times.
✗ Branch 8 → 52 not taken.
|
1175 | llvm::BasicBlock *bBody = createBlock("for.body." + codeLine); |
| 29 |
2/4✓ Branch 10 → 11 taken 1175 times.
✗ Branch 10 → 57 not taken.
✓ Branch 11 → 12 taken 1175 times.
✗ Branch 11 → 55 not taken.
|
1175 | llvm::BasicBlock *bTail = createBlock("for.tail." + codeLine); |
| 30 |
2/4✓ Branch 13 → 14 taken 1175 times.
✗ Branch 13 → 60 not taken.
✓ Branch 14 → 15 taken 1175 times.
✗ Branch 14 → 58 not taken.
|
1175 | llvm::BasicBlock *bExit = createBlock("for.exit." + codeLine); |
| 31 | |||
| 32 | // Change scope | ||
| 33 |
2/4✓ Branch 16 → 17 taken 1175 times.
✗ Branch 16 → 63 not taken.
✓ Branch 17 → 18 taken 1175 times.
✗ Branch 17 → 61 not taken.
|
1175 | ScopeHandle scopeHandle(this, node->getScopeId(), ScopeType::FOR_BODY, node); |
| 34 | |||
| 35 | // Save the blocks for break and continue | ||
| 36 |
1/2✓ Branch 19 → 20 taken 1175 times.
✗ Branch 19 → 69 not taken.
|
1175 | breakBlocks.push_back(bExit); |
| 37 |
1/2✓ Branch 20 → 21 taken 1175 times.
✗ Branch 20 → 69 not taken.
|
1175 | continueBlocks.push_back(bTail); |
| 38 | |||
| 39 | // Init statement | ||
| 40 |
1/2✓ Branch 21 → 22 taken 1175 times.
✗ Branch 21 → 65 not taken.
|
1175 | visit(node->initDecl); |
| 41 | // Create jump from original to head block | ||
| 42 |
1/2✓ Branch 23 → 24 taken 1175 times.
✗ Branch 23 → 69 not taken.
|
1175 | insertJump(bHead); |
| 43 | |||
| 44 | // Switch to head block | ||
| 45 |
1/2✓ Branch 24 → 25 taken 1175 times.
✗ Branch 24 → 69 not taken.
|
1175 | switchToBlock(bHead); |
| 46 | // Condition evaluation | ||
| 47 |
1/2✓ Branch 25 → 26 taken 1175 times.
✗ Branch 25 → 69 not taken.
|
1175 | llvm::Value *condValue = resolveValue(node->condAssign); |
| 48 | // Create conditional jump from head to body or exit block | ||
| 49 |
1/2✓ Branch 26 → 27 taken 1175 times.
✗ Branch 26 → 69 not taken.
|
1175 | insertCondJump(condValue, bBody, bExit); |
| 50 | |||
| 51 | // Switch to body block | ||
| 52 |
1/2✓ Branch 27 → 28 taken 1175 times.
✗ Branch 27 → 69 not taken.
|
1175 | switchToBlock(bBody); |
| 53 | // Visit body | ||
| 54 |
1/2✓ Branch 28 → 29 taken 1175 times.
✗ Branch 28 → 66 not taken.
|
1175 | visit(node->body); |
| 55 | // Create jump from body to tail block | ||
| 56 |
1/2✓ Branch 30 → 31 taken 1175 times.
✗ Branch 30 → 69 not taken.
|
1175 | insertJump(bTail); |
| 57 | |||
| 58 | // Switch to tail block | ||
| 59 |
1/2✓ Branch 31 → 32 taken 1175 times.
✗ Branch 31 → 69 not taken.
|
1175 | switchToBlock(bTail); |
| 60 | // Inc statement | ||
| 61 |
1/2✓ Branch 32 → 33 taken 1175 times.
✗ Branch 32 → 67 not taken.
|
1175 | visit(node->incAssign); |
| 62 | // Create jump from tail to head | ||
| 63 |
1/2✓ Branch 34 → 35 taken 1175 times.
✗ Branch 34 → 69 not taken.
|
1175 | insertJump(bHead); |
| 64 | |||
| 65 | // Switch to exit block | ||
| 66 |
1/2✓ Branch 35 → 36 taken 1175 times.
✗ Branch 35 → 69 not taken.
|
1175 | switchToBlock(bExit); |
| 67 | |||
| 68 | // Pop basic blocks from break and continue stacks | ||
| 69 |
1/2✗ Branch 37 → 38 not taken.
✓ Branch 37 → 39 taken 1175 times.
|
1175 | assert(breakBlocks.back() == bExit); |
| 70 | 1175 | breakBlocks.pop_back(); | |
| 71 |
1/2✗ Branch 41 → 42 not taken.
✓ Branch 41 → 43 taken 1175 times.
|
1175 | assert(continueBlocks.back() == bTail); |
| 72 | 1175 | continueBlocks.pop_back(); | |
| 73 | |||
| 74 |
1/2✓ Branch 44 → 45 taken 1175 times.
✗ Branch 44 → 68 not taken.
|
2350 | return nullptr; |
| 75 | 1175 | } | |
| 76 | |||
| 77 | 110 | std::any IRGenerator::visitForeachLoop(const ForeachLoopNode *node) { | |
| 78 |
1/2✓ Branch 2 → 3 taken 110 times.
✗ Branch 2 → 238 not taken.
|
110 | diGenerator.setSourceLocation(node); |
| 79 | |||
| 80 | // Create blocks | ||
| 81 |
1/2✓ Branch 3 → 4 taken 110 times.
✗ Branch 3 → 238 not taken.
|
110 | const std::string codeLine = node->codeLoc.toPrettyLine(); |
| 82 |
2/4✓ Branch 4 → 5 taken 110 times.
✗ Branch 4 → 167 not taken.
✓ Branch 5 → 6 taken 110 times.
✗ Branch 5 → 165 not taken.
|
110 | llvm::BasicBlock *bHead = createBlock("foreach.head." + codeLine); |
| 83 |
2/4✓ Branch 7 → 8 taken 110 times.
✗ Branch 7 → 170 not taken.
✓ Branch 8 → 9 taken 110 times.
✗ Branch 8 → 168 not taken.
|
110 | llvm::BasicBlock *bBody = createBlock("foreach.body." + codeLine); |
| 84 |
2/4✓ Branch 10 → 11 taken 110 times.
✗ Branch 10 → 173 not taken.
✓ Branch 11 → 12 taken 110 times.
✗ Branch 11 → 171 not taken.
|
110 | llvm::BasicBlock *bTail = createBlock("foreach.tail." + codeLine); |
| 85 |
2/4✓ Branch 13 → 14 taken 110 times.
✗ Branch 13 → 176 not taken.
✓ Branch 14 → 15 taken 110 times.
✗ Branch 14 → 174 not taken.
|
110 | llvm::BasicBlock *bExit = createBlock("foreach.exit." + codeLine); |
| 86 | |||
| 87 | // Change scope | ||
| 88 |
2/4✓ Branch 16 → 17 taken 110 times.
✗ Branch 16 → 179 not taken.
✓ Branch 17 → 18 taken 110 times.
✗ Branch 17 → 177 not taken.
|
110 | ScopeHandle scopeHandle(this, node->getScopeId(), ScopeType::FOREACH_BODY, node); |
| 89 | |||
| 90 | // Save the blocks for break and continue | ||
| 91 |
1/2✓ Branch 19 → 20 taken 110 times.
✗ Branch 19 → 234 not taken.
|
110 | breakBlocks.push_back(bExit); |
| 92 |
1/2✓ Branch 20 → 21 taken 110 times.
✗ Branch 20 → 234 not taken.
|
110 | continueBlocks.push_back(bTail); |
| 93 | |||
| 94 | // Resolve iterator | ||
| 95 | 110 | AssignExprNode *iteratorAssignNode = node->iteratorAssign; | |
| 96 | llvm::Value *iteratorPtr; | ||
| 97 |
2/2✓ Branch 21 → 22 taken 95 times.
✓ Branch 21 → 58 taken 15 times.
|
110 | if (node->getIteratorFct != nullptr) { // The iteratorAssignExpr is of type Iterable |
| 98 |
1/2✓ Branch 22 → 23 taken 95 times.
✗ Branch 22 → 192 not taken.
|
95 | llvm::Value *iterablePtr = resolveAddress(iteratorAssignNode); |
| 99 | |||
| 100 | llvm::Value *iterator; | ||
| 101 |
10/16✓ Branch 23 → 24 taken 95 times.
✗ Branch 23 → 181 not taken.
✓ Branch 26 → 27 taken 7 times.
✓ Branch 26 → 32 taken 88 times.
✓ Branch 27 → 28 taken 7 times.
✗ Branch 27 → 181 not taken.
✓ Branch 29 → 30 taken 7 times.
✗ Branch 29 → 181 not taken.
✓ Branch 30 → 31 taken 7 times.
✗ Branch 30 → 32 not taken.
✓ Branch 33 → 34 taken 7 times.
✓ Branch 33 → 35 taken 88 times.
✓ Branch 35 → 36 taken 7 times.
✓ Branch 35 → 47 taken 88 times.
✗ Branch 181 → 182 not taken.
✗ Branch 181 → 183 not taken.
|
190 | if (!node->getIteratorFct->isMethod() && node->getIteratorFct->getParamTypes().front().isArray()) { // Array as iterable |
| 102 | // Call iterate() function from std/iterator/array-iterator | ||
| 103 |
1/2✓ Branch 36 → 37 taken 7 times.
✗ Branch 36 → 192 not taken.
|
7 | llvm::Function *iterateFct = stdFunctionManager.getIterateFct(node->getIteratorFct); |
| 104 |
2/4✓ Branch 37 → 38 taken 7 times.
✗ Branch 37 → 192 not taken.
✓ Branch 38 → 39 taken 7 times.
✗ Branch 38 → 192 not taken.
|
7 | const size_t arraySize = iteratorAssignNode->getEvaluatedSymbolType(manIdx).getArraySize(); |
| 105 |
1/2✗ Branch 39 → 40 not taken.
✓ Branch 39 → 41 taken 7 times.
|
7 | assert(arraySize > 0); |
| 106 |
4/8✓ Branch 41 → 42 taken 7 times.
✗ Branch 41 → 188 not taken.
✓ Branch 42 → 43 taken 7 times.
✗ Branch 42 → 186 not taken.
✓ Branch 44 → 45 taken 7 times.
✗ Branch 44 → 185 not taken.
✓ Branch 45 → 46 taken 7 times.
✗ Branch 45 → 185 not taken.
|
7 | iterator = builder.CreateCall(iterateFct, {iterablePtr, builder.getInt64(arraySize)}); |
| 107 | } else { // Struct as iterable | ||
| 108 | // Call .getIterator() on iterable | ||
| 109 |
1/2✓ Branch 47 → 48 taken 88 times.
✗ Branch 47 → 192 not taken.
|
88 | llvm::Function *getIteratorFct = stdFunctionManager.getIteratorFct(node->getIteratorFct); |
| 110 |
3/6✓ Branch 48 → 49 taken 88 times.
✗ Branch 48 → 191 not taken.
✓ Branch 50 → 51 taken 88 times.
✗ Branch 50 → 189 not taken.
✓ Branch 51 → 52 taken 88 times.
✗ Branch 51 → 189 not taken.
|
88 | iterator = builder.CreateCall(getIteratorFct, iterablePtr); |
| 111 | } | ||
| 112 | |||
| 113 | // Resolve address of iterator | ||
| 114 | 95 | LLVMExprResult callResult = {.value = iterator, .node = iteratorAssignNode}; | |
| 115 |
1/2✓ Branch 53 → 54 taken 95 times.
✗ Branch 53 → 192 not taken.
|
95 | iteratorPtr = resolveAddress(callResult); |
| 116 | |||
| 117 | // If an anonymous symbol exists, set its address | ||
| 118 |
2/4✓ Branch 54 → 55 taken 95 times.
✗ Branch 54 → 192 not taken.
✗ Branch 55 → 56 not taken.
✓ Branch 55 → 57 taken 95 times.
|
95 | if (SymbolTableEntry *returnSymbol = currentScope->symbolTable.lookupAnonymous(iteratorAssignNode->codeLoc)) |
| 119 | ✗ | returnSymbol->updateAddress(iteratorPtr); | |
| 120 | } else { // The iteratorAssignExpr is of type Iterator | ||
| 121 |
1/2✓ Branch 58 → 59 taken 15 times.
✗ Branch 58 → 234 not taken.
|
15 | iteratorPtr = resolveAddress(iteratorAssignNode); |
| 122 | } | ||
| 123 | |||
| 124 | // Check we have an idx | ||
| 125 | 110 | const DeclStmtNode *idxDeclNode = node->idxVarDecl; | |
| 126 | 110 | const bool hasIdx = idxDeclNode != nullptr; | |
| 127 | // Retrieve item ref type | ||
| 128 |
3/4✓ Branch 60 → 61 taken 5 times.
✓ Branch 60 → 62 taken 105 times.
✗ Branch 63 → 64 not taken.
✓ Branch 63 → 65 taken 110 times.
|
110 | assert(hasIdx ? node->getIdxFct != nullptr : node->getFct != nullptr); |
| 129 |
2/2✓ Branch 65 → 66 taken 5 times.
✓ Branch 65 → 67 taken 105 times.
|
110 | const QualType itemRefSTy = hasIdx ? node->getIdxFct->returnType : node->getFct->returnType; |
| 130 | |||
| 131 | // Visit idx variable declaration if required | ||
| 132 | 110 | SymbolTableEntry *idxEntry = nullptr; | |
| 133 | 110 | llvm::Value *idxAddress = nullptr; | |
| 134 |
2/2✓ Branch 68 → 69 taken 5 times.
✓ Branch 68 → 75 taken 105 times.
|
110 | if (hasIdx) { |
| 135 |
1/2✓ Branch 69 → 70 taken 5 times.
✗ Branch 69 → 193 not taken.
|
5 | visit(idxDeclNode); |
| 136 | // Get address of idx variable | ||
| 137 |
1/2✓ Branch 71 → 72 taken 5 times.
✗ Branch 71 → 234 not taken.
|
5 | idxEntry = idxDeclNode->entries.at(manIdx); |
| 138 |
1/2✓ Branch 72 → 73 taken 5 times.
✗ Branch 72 → 234 not taken.
|
5 | idxAddress = idxEntry->getAddress(); |
| 139 |
1/2✗ Branch 73 → 74 not taken.
✓ Branch 73 → 75 taken 5 times.
|
5 | assert(idxAddress != nullptr); |
| 140 | } | ||
| 141 | |||
| 142 | // Visit item variable declaration | ||
| 143 | 110 | const DeclStmtNode *itemDeclNode = node->itemVarDecl; | |
| 144 |
1/2✓ Branch 75 → 76 taken 110 times.
✗ Branch 75 → 194 not taken.
|
110 | visit(itemDeclNode); |
| 145 | // Get address of item variable | ||
| 146 |
1/2✓ Branch 77 → 78 taken 110 times.
✗ Branch 77 → 234 not taken.
|
110 | SymbolTableEntry *itemEntry = itemDeclNode->entries.at(manIdx); |
| 147 |
1/2✓ Branch 78 → 79 taken 110 times.
✗ Branch 78 → 234 not taken.
|
110 | llvm::Value *itemAddress = itemEntry->getAddress(); |
| 148 |
1/2✗ Branch 79 → 80 not taken.
✓ Branch 79 → 81 taken 110 times.
|
110 | assert(itemAddress != nullptr); |
| 149 | |||
| 150 | // Create jump from original to head block | ||
| 151 |
1/2✓ Branch 81 → 82 taken 110 times.
✗ Branch 81 → 234 not taken.
|
110 | insertJump(bHead); |
| 152 | |||
| 153 | // Switch to head block | ||
| 154 |
1/2✓ Branch 82 → 83 taken 110 times.
✗ Branch 82 → 234 not taken.
|
110 | switchToBlock(bHead); |
| 155 | // Call .isValid() on iterator | ||
| 156 |
1/2✗ Branch 83 → 84 not taken.
✓ Branch 83 → 85 taken 110 times.
|
110 | assert(node->isValidFct); |
| 157 |
1/2✓ Branch 85 → 86 taken 110 times.
✗ Branch 85 → 234 not taken.
|
110 | llvm::Function *isValidFct = stdFunctionManager.getIteratorIsValidFct(node->isValidFct); |
| 158 |
3/6✓ Branch 86 → 87 taken 110 times.
✗ Branch 86 → 197 not taken.
✓ Branch 88 → 89 taken 110 times.
✗ Branch 88 → 195 not taken.
✓ Branch 89 → 90 taken 110 times.
✗ Branch 89 → 195 not taken.
|
110 | llvm::Value *isValid = builder.CreateCall(isValidFct, iteratorPtr); |
| 159 | // Create conditional jump from head to body or exit block | ||
| 160 |
1/2✓ Branch 90 → 91 taken 110 times.
✗ Branch 90 → 234 not taken.
|
110 | insertCondJump(isValid, bBody, bExit); |
| 161 | |||
| 162 | // Switch to body block | ||
| 163 |
1/2✓ Branch 91 → 92 taken 110 times.
✗ Branch 91 → 234 not taken.
|
110 | switchToBlock(bBody); |
| 164 | // Get the current iterator values | ||
| 165 |
2/2✓ Branch 92 → 93 taken 5 times.
✓ Branch 92 → 130 taken 105 times.
|
110 | if (hasIdx) { |
| 166 | // Allocate space to save pair | ||
| 167 | 5 | const QualType& pairSTy = node->getIdxFct->returnType; | |
| 168 |
1/2✓ Branch 93 → 94 taken 5 times.
✗ Branch 93 → 223 not taken.
|
5 | llvm::Type *pairTy = pairSTy.toLLVMType(sourceFile); |
| 169 |
2/4✓ Branch 96 → 97 taken 5 times.
✗ Branch 96 → 200 not taken.
✓ Branch 97 → 98 taken 5 times.
✗ Branch 97 → 198 not taken.
|
5 | llvm::Value *pairPtr = insertAlloca(pairSTy, "pair.addr"); |
| 170 | // Call .getIdx() on iterator | ||
| 171 |
1/2✗ Branch 100 → 101 not taken.
✓ Branch 100 → 102 taken 5 times.
|
5 | assert(node->getIdxFct); |
| 172 |
1/2✓ Branch 102 → 103 taken 5 times.
✗ Branch 102 → 223 not taken.
|
5 | llvm::Function *getIdxFct = stdFunctionManager.getIteratorGetIdxFct(node->getIdxFct); |
| 173 |
3/6✓ Branch 103 → 104 taken 5 times.
✗ Branch 103 → 206 not taken.
✓ Branch 105 → 106 taken 5 times.
✗ Branch 105 → 204 not taken.
✓ Branch 106 → 107 taken 5 times.
✗ Branch 106 → 204 not taken.
|
5 | llvm::Value *pair = builder.CreateCall(getIdxFct, iteratorPtr); |
| 174 |
2/4✓ Branch 107 → 108 taken 5 times.
✗ Branch 107 → 207 not taken.
✓ Branch 108 → 109 taken 5 times.
✗ Branch 108 → 207 not taken.
|
5 | pair->setName("pair"); |
| 175 |
1/2✓ Branch 109 → 110 taken 5 times.
✗ Branch 109 → 223 not taken.
|
5 | insertStore(pair, pairPtr); |
| 176 | // Store idx to idx var | ||
| 177 |
2/4✓ Branch 112 → 113 taken 5 times.
✗ Branch 112 → 210 not taken.
✓ Branch 113 → 114 taken 5 times.
✗ Branch 113 → 208 not taken.
|
5 | llvm::Value *idxAddrInPair = insertStructGEP(pairTy, pairPtr, 0, "idx.addr"); |
| 178 | 5 | LLVMExprResult idxResult = {.ptr = idxAddrInPair}; | |
| 179 |
2/4✓ Branch 116 → 117 taken 5 times.
✗ Branch 116 → 119 not taken.
✓ Branch 117 → 118 taken 5 times.
✗ Branch 117 → 119 not taken.
|
5 | assert(idxAddress != nullptr && idxEntry != nullptr); |
| 180 |
2/4✓ Branch 120 → 121 taken 5 times.
✗ Branch 120 → 214 not taken.
✓ Branch 121 → 122 taken 5 times.
✗ Branch 121 → 214 not taken.
|
5 | doAssignment(idxAddress, idxEntry, idxResult, QualType(TY_LONG), node, true); |
| 181 | // Store item to item var | ||
| 182 |
2/4✓ Branch 124 → 125 taken 5 times.
✗ Branch 124 → 218 not taken.
✓ Branch 125 → 126 taken 5 times.
✗ Branch 125 → 216 not taken.
|
5 | llvm::Value *itemAddrInPair = insertStructGEP(pairTy, pairPtr, 1, "item.addr"); |
| 183 | 5 | LLVMExprResult itemResult = {.refPtr = itemAddrInPair}; | |
| 184 |
1/2✓ Branch 128 → 129 taken 5 times.
✗ Branch 128 → 222 not taken.
|
5 | doAssignment(itemAddress, itemEntry, itemResult, itemRefSTy, node, true); |
| 185 | } else { | ||
| 186 | // Call .get() on iterator | ||
| 187 |
1/2✗ Branch 130 → 131 not taken.
✓ Branch 130 → 132 taken 105 times.
|
105 | assert(node->getFct); |
| 188 |
1/2✓ Branch 132 → 133 taken 105 times.
✗ Branch 132 → 228 not taken.
|
105 | llvm::Function *getFct = stdFunctionManager.getIteratorGetFct(node->getFct); |
| 189 |
3/6✓ Branch 133 → 134 taken 105 times.
✗ Branch 133 → 226 not taken.
✓ Branch 135 → 136 taken 105 times.
✗ Branch 135 → 224 not taken.
✓ Branch 136 → 137 taken 105 times.
✗ Branch 136 → 224 not taken.
|
105 | llvm::Value *getItemPtr = builder.CreateCall(getFct, iteratorPtr); |
| 190 | 105 | LLVMExprResult getResult = {.ptr = getItemPtr}; | |
| 191 |
1/2✓ Branch 137 → 138 taken 105 times.
✗ Branch 137 → 227 not taken.
|
105 | doAssignment(itemAddress, itemEntry, getResult, itemRefSTy, node, true); |
| 192 | } | ||
| 193 | // Visit body | ||
| 194 |
1/2✓ Branch 139 → 140 taken 110 times.
✗ Branch 139 → 229 not taken.
|
110 | visit(node->body); |
| 195 | // Create jump from body to tail block | ||
| 196 |
1/2✓ Branch 141 → 142 taken 110 times.
✗ Branch 141 → 234 not taken.
|
110 | insertJump(bTail); |
| 197 | |||
| 198 | // Switch to tail block | ||
| 199 |
1/2✓ Branch 142 → 143 taken 110 times.
✗ Branch 142 → 234 not taken.
|
110 | switchToBlock(bTail); |
| 200 | // Call .next() on iterator | ||
| 201 |
1/2✗ Branch 143 → 144 not taken.
✓ Branch 143 → 145 taken 110 times.
|
110 | assert(node->nextFct); |
| 202 |
1/2✓ Branch 145 → 146 taken 110 times.
✗ Branch 145 → 234 not taken.
|
110 | llvm::Function *nextFct = stdFunctionManager.getIteratorNextFct(node->nextFct); |
| 203 |
3/6✓ Branch 146 → 147 taken 110 times.
✗ Branch 146 → 232 not taken.
✓ Branch 148 → 149 taken 110 times.
✗ Branch 148 → 230 not taken.
✓ Branch 149 → 150 taken 110 times.
✗ Branch 149 → 230 not taken.
|
110 | builder.CreateCall(nextFct, iteratorPtr); |
| 204 | // Create jump from tail to head block | ||
| 205 |
1/2✓ Branch 150 → 151 taken 110 times.
✗ Branch 150 → 234 not taken.
|
110 | insertJump(bHead); |
| 206 | |||
| 207 | // Switch to exit block | ||
| 208 |
1/2✓ Branch 151 → 152 taken 110 times.
✗ Branch 151 → 234 not taken.
|
110 | switchToBlock(bExit); |
| 209 | |||
| 210 | // Pop basic blocks from break and continue stacks | ||
| 211 |
1/2✗ Branch 153 → 154 not taken.
✓ Branch 153 → 155 taken 110 times.
|
110 | assert(breakBlocks.back() == bExit); |
| 212 | 110 | breakBlocks.pop_back(); | |
| 213 |
1/2✗ Branch 157 → 158 not taken.
✓ Branch 157 → 159 taken 110 times.
|
110 | assert(continueBlocks.back() == bTail); |
| 214 | 110 | continueBlocks.pop_back(); | |
| 215 | |||
| 216 |
1/2✓ Branch 160 → 161 taken 110 times.
✗ Branch 160 → 233 not taken.
|
220 | return nullptr; |
| 217 | 110 | } | |
| 218 | |||
| 219 | 671 | std::any IRGenerator::visitWhileLoop(const WhileLoopNode *node) { | |
| 220 |
1/2✓ Branch 2 → 3 taken 671 times.
✗ Branch 2 → 59 not taken.
|
671 | diGenerator.setSourceLocation(node); |
| 221 | |||
| 222 | // Create blocks | ||
| 223 |
1/2✓ Branch 3 → 4 taken 671 times.
✗ Branch 3 → 59 not taken.
|
671 | const std::string codeLine = node->codeLoc.toPrettyLine(); |
| 224 |
2/4✓ Branch 4 → 5 taken 671 times.
✗ Branch 4 → 42 not taken.
✓ Branch 5 → 6 taken 671 times.
✗ Branch 5 → 40 not taken.
|
671 | llvm::BasicBlock *bHead = createBlock("while.head." + codeLine); |
| 225 |
2/4✓ Branch 7 → 8 taken 671 times.
✗ Branch 7 → 45 not taken.
✓ Branch 8 → 9 taken 671 times.
✗ Branch 8 → 43 not taken.
|
671 | llvm::BasicBlock *bBody = createBlock("while.body." + codeLine); |
| 226 |
2/4✓ Branch 10 → 11 taken 671 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 671 times.
✗ Branch 11 → 46 not taken.
|
671 | llvm::BasicBlock *bExit = createBlock("while.exit." + codeLine); |
| 227 | |||
| 228 | // Change scope | ||
| 229 |
2/4✓ Branch 13 → 14 taken 671 times.
✗ Branch 13 → 51 not taken.
✓ Branch 14 → 15 taken 671 times.
✗ Branch 14 → 49 not taken.
|
671 | ScopeHandle scopeHandle(this, node->getScopeId(), ScopeType::WHILE_BODY, node); |
| 230 | |||
| 231 | // Save the blocks for break and continue | ||
| 232 |
1/2✓ Branch 16 → 17 taken 671 times.
✗ Branch 16 → 55 not taken.
|
671 | breakBlocks.push_back(bExit); |
| 233 |
1/2✓ Branch 17 → 18 taken 671 times.
✗ Branch 17 → 55 not taken.
|
671 | continueBlocks.push_back(bHead); |
| 234 | |||
| 235 | // Jump to head block | ||
| 236 |
1/2✓ Branch 18 → 19 taken 671 times.
✗ Branch 18 → 55 not taken.
|
671 | insertJump(bHead); |
| 237 | |||
| 238 | // Switch to head block | ||
| 239 |
1/2✓ Branch 19 → 20 taken 671 times.
✗ Branch 19 → 55 not taken.
|
671 | switchToBlock(bHead); |
| 240 | // Evaluate condition | ||
| 241 |
1/2✓ Branch 20 → 21 taken 671 times.
✗ Branch 20 → 55 not taken.
|
671 | llvm::Value *condValue = resolveValue(node->condition); |
| 242 | // Jump to body or exit block, depending on the condition | ||
| 243 |
1/2✓ Branch 21 → 22 taken 671 times.
✗ Branch 21 → 55 not taken.
|
671 | insertCondJump(condValue, bBody, bExit); |
| 244 | |||
| 245 | // Switch to body block | ||
| 246 |
1/2✓ Branch 22 → 23 taken 671 times.
✗ Branch 22 → 55 not taken.
|
671 | switchToBlock(bBody); |
| 247 | // Visit body | ||
| 248 |
1/2✓ Branch 23 → 24 taken 671 times.
✗ Branch 23 → 53 not taken.
|
671 | visit(node->body); |
| 249 | // Create jump to head block | ||
| 250 |
1/2✓ Branch 25 → 26 taken 671 times.
✗ Branch 25 → 55 not taken.
|
671 | insertJump(bHead); |
| 251 | |||
| 252 | // Switch to exit block | ||
| 253 |
1/2✓ Branch 26 → 27 taken 671 times.
✗ Branch 26 → 55 not taken.
|
671 | switchToBlock(bExit); |
| 254 | |||
| 255 | // Pop basic blocks from break and continue stacks | ||
| 256 |
1/2✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 671 times.
|
671 | assert(breakBlocks.back() == bExit); |
| 257 | 671 | breakBlocks.pop_back(); | |
| 258 |
1/2✗ Branch 32 → 33 not taken.
✓ Branch 32 → 34 taken 671 times.
|
671 | assert(continueBlocks.back() == bHead); |
| 259 | 671 | continueBlocks.pop_back(); | |
| 260 | |||
| 261 |
1/2✓ Branch 35 → 36 taken 671 times.
✗ Branch 35 → 54 not taken.
|
1342 | return nullptr; |
| 262 | 671 | } | |
| 263 | |||
| 264 | 8 | std::any IRGenerator::visitDoWhileLoop(const DoWhileLoopNode *node) { | |
| 265 |
1/2✓ Branch 2 → 3 taken 8 times.
✗ Branch 2 → 59 not taken.
|
8 | diGenerator.setSourceLocation(node); |
| 266 | |||
| 267 | // Create blocks | ||
| 268 |
1/2✓ Branch 3 → 4 taken 8 times.
✗ Branch 3 → 59 not taken.
|
8 | const std::string codeLine = node->codeLoc.toPrettyLine(); |
| 269 |
2/4✓ Branch 4 → 5 taken 8 times.
✗ Branch 4 → 42 not taken.
✓ Branch 5 → 6 taken 8 times.
✗ Branch 5 → 40 not taken.
|
8 | llvm::BasicBlock *bBody = createBlock("dowhile.body." + codeLine); |
| 270 |
2/4✓ Branch 7 → 8 taken 8 times.
✗ Branch 7 → 45 not taken.
✓ Branch 8 → 9 taken 8 times.
✗ Branch 8 → 43 not taken.
|
8 | llvm::BasicBlock *bFoot = createBlock("dowhile.foot." + codeLine); |
| 271 |
2/4✓ Branch 10 → 11 taken 8 times.
✗ Branch 10 → 48 not taken.
✓ Branch 11 → 12 taken 8 times.
✗ Branch 11 → 46 not taken.
|
8 | llvm::BasicBlock *bExit = createBlock("dowhile.exit." + codeLine); |
| 272 | |||
| 273 | // Change scope | ||
| 274 |
2/4✓ Branch 13 → 14 taken 8 times.
✗ Branch 13 → 51 not taken.
✓ Branch 14 → 15 taken 8 times.
✗ Branch 14 → 49 not taken.
|
8 | ScopeHandle scopeHandle(this, node->getScopeId(), ScopeType::WHILE_BODY, node); |
| 275 | |||
| 276 | // Save the blocks for break and continue | ||
| 277 |
1/2✓ Branch 16 → 17 taken 8 times.
✗ Branch 16 → 55 not taken.
|
8 | breakBlocks.push_back(bExit); |
| 278 |
1/2✓ Branch 17 → 18 taken 8 times.
✗ Branch 17 → 55 not taken.
|
8 | continueBlocks.push_back(bFoot); |
| 279 | |||
| 280 | // Jump to body block | ||
| 281 |
1/2✓ Branch 18 → 19 taken 8 times.
✗ Branch 18 → 55 not taken.
|
8 | insertJump(bBody); |
| 282 | |||
| 283 | // Switch to body block | ||
| 284 |
1/2✓ Branch 19 → 20 taken 8 times.
✗ Branch 19 → 55 not taken.
|
8 | switchToBlock(bBody); |
| 285 | // Visit body | ||
| 286 |
1/2✓ Branch 20 → 21 taken 8 times.
✗ Branch 20 → 53 not taken.
|
8 | visit(node->body); |
| 287 | // Create jump to foot block | ||
| 288 |
1/2✓ Branch 22 → 23 taken 8 times.
✗ Branch 22 → 55 not taken.
|
8 | insertJump(bFoot); |
| 289 | |||
| 290 | // Switch to head block | ||
| 291 |
1/2✓ Branch 23 → 24 taken 8 times.
✗ Branch 23 → 55 not taken.
|
8 | switchToBlock(bFoot); |
| 292 | // Evaluate condition | ||
| 293 |
1/2✓ Branch 24 → 25 taken 8 times.
✗ Branch 24 → 55 not taken.
|
8 | llvm::Value *condValue = resolveValue(node->condition); |
| 294 | // Jump to body or exit block, depending on the condition | ||
| 295 |
1/2✓ Branch 25 → 26 taken 8 times.
✗ Branch 25 → 55 not taken.
|
8 | insertCondJump(condValue, bBody, bExit); |
| 296 | |||
| 297 | // Switch to exit block | ||
| 298 |
1/2✓ Branch 26 → 27 taken 8 times.
✗ Branch 26 → 55 not taken.
|
8 | switchToBlock(bExit); |
| 299 | |||
| 300 | // Pop basic blocks from break and continue stacks | ||
| 301 |
1/2✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 8 times.
|
8 | assert(breakBlocks.back() == bExit); |
| 302 | 8 | breakBlocks.pop_back(); | |
| 303 |
1/2✗ Branch 32 → 33 not taken.
✓ Branch 32 → 34 taken 8 times.
|
8 | assert(continueBlocks.back() == bFoot); |
| 304 | 8 | continueBlocks.pop_back(); | |
| 305 | |||
| 306 |
1/2✓ Branch 35 → 36 taken 8 times.
✗ Branch 35 → 54 not taken.
|
16 | return nullptr; |
| 307 | 8 | } | |
| 308 | |||
| 309 | 4018 | std::any IRGenerator::visitIfStmt(const IfStmtNode *node) { | |
| 310 |
1/2✓ Branch 2 → 3 taken 4018 times.
✗ Branch 2 → 62 not taken.
|
4018 | diGenerator.setSourceLocation(node); |
| 311 | |||
| 312 | // Create blocks | ||
| 313 |
1/2✓ Branch 3 → 4 taken 4018 times.
✗ Branch 3 → 62 not taken.
|
4018 | const std::string codeLine = node->codeLoc.toPrettyLine(); |
| 314 |
2/4✓ Branch 4 → 5 taken 4018 times.
✗ Branch 4 → 44 not taken.
✓ Branch 5 → 6 taken 4018 times.
✗ Branch 5 → 42 not taken.
|
4018 | llvm::BasicBlock *bThen = createBlock("if.then." + codeLine); |
| 315 |
6/10✓ Branch 7 → 8 taken 185 times.
✓ Branch 7 → 11 taken 3833 times.
✓ Branch 8 → 9 taken 185 times.
✗ Branch 8 → 45 not taken.
✓ Branch 9 → 10 taken 185 times.
✗ Branch 9 → 45 not taken.
✓ Branch 12 → 13 taken 185 times.
✓ Branch 12 → 14 taken 3833 times.
✗ Branch 45 → 46 not taken.
✗ Branch 45 → 47 not taken.
|
4018 | llvm::BasicBlock *bElse = node->elseStmt ? createBlock("if.else." + codeLine) : nullptr; |
| 316 |
2/4✓ Branch 14 → 15 taken 4018 times.
✗ Branch 14 → 51 not taken.
✓ Branch 15 → 16 taken 4018 times.
✗ Branch 15 → 49 not taken.
|
4018 | llvm::BasicBlock *bExit = createBlock("if.exit." + codeLine); |
| 317 | |||
| 318 | // Change scope | ||
| 319 |
2/4✓ Branch 17 → 18 taken 4018 times.
✗ Branch 17 → 54 not taken.
✓ Branch 18 → 19 taken 4018 times.
✗ Branch 18 → 52 not taken.
|
4018 | ScopeHandle scopeHandle(this, node->getScopeId(), ScopeType::IF_ELSE_BODY, node); |
| 320 | |||
| 321 | // Retrieve condition value | ||
| 322 |
1/2✓ Branch 20 → 21 taken 4018 times.
✗ Branch 20 → 58 not taken.
|
4018 | llvm::Value *condValue = resolveValue(node->condition); |
| 323 | // Check if condition is fulfilled | ||
| 324 |
3/4✓ Branch 21 → 22 taken 185 times.
✓ Branch 21 → 23 taken 3833 times.
✓ Branch 24 → 25 taken 4018 times.
✗ Branch 24 → 58 not taken.
|
4018 | insertCondJump(condValue, bThen, node->elseStmt ? bElse : bExit); |
| 325 | |||
| 326 | // Switch to then block | ||
| 327 |
1/2✓ Branch 25 → 26 taken 4018 times.
✗ Branch 25 → 58 not taken.
|
4018 | switchToBlock(bThen); |
| 328 | // Visit then body | ||
| 329 |
1/2✓ Branch 26 → 27 taken 4018 times.
✗ Branch 26 → 56 not taken.
|
4018 | visit(node->thenBody); |
| 330 | // Create jump from then to end block | ||
| 331 |
1/2✓ Branch 28 → 29 taken 4018 times.
✗ Branch 28 → 58 not taken.
|
4018 | insertJump(bExit); |
| 332 | |||
| 333 | // Change scope back | ||
| 334 |
1/2✓ Branch 29 → 30 taken 4018 times.
✗ Branch 29 → 58 not taken.
|
4018 | scopeHandle.leaveScopeEarly(); |
| 335 | |||
| 336 |
2/2✓ Branch 30 → 31 taken 185 times.
✓ Branch 30 → 35 taken 3833 times.
|
4018 | if (node->elseStmt) { |
| 337 | // Switch to else block | ||
| 338 |
1/2✓ Branch 31 → 32 taken 185 times.
✗ Branch 31 → 58 not taken.
|
185 | switchToBlock(bElse); |
| 339 | // Visit else block | ||
| 340 |
1/2✓ Branch 32 → 33 taken 185 times.
✗ Branch 32 → 57 not taken.
|
185 | visit(node->elseStmt); |
| 341 | // Create jump from else to end block | ||
| 342 |
1/2✓ Branch 34 → 35 taken 185 times.
✗ Branch 34 → 58 not taken.
|
185 | insertJump(bExit); |
| 343 | } | ||
| 344 | |||
| 345 | // Switch to exit block | ||
| 346 |
1/2✓ Branch 35 → 36 taken 4018 times.
✗ Branch 35 → 58 not taken.
|
4018 | switchToBlock(bExit); |
| 347 | |||
| 348 | // Return conditional value as result for the 'if' stmt | ||
| 349 |
1/2✓ Branch 36 → 37 taken 4018 times.
✗ Branch 36 → 58 not taken.
|
8036 | return condValue; |
| 350 | 4018 | } | |
| 351 | |||
| 352 | 185 | std::any IRGenerator::visitElseStmt(const ElseStmtNode *node) { | |
| 353 | 185 | diGenerator.setSourceLocation(node); | |
| 354 | |||
| 355 |
2/2✓ Branch 3 → 4 taken 52 times.
✓ Branch 3 → 7 taken 133 times.
|
185 | if (node->ifStmt) { // It is an else if branch |
| 356 |
1/2✓ Branch 4 → 5 taken 52 times.
✗ Branch 4 → 17 not taken.
|
52 | visit(node->ifStmt); |
| 357 | } else { // It is an else branch | ||
| 358 | // Change scope | ||
| 359 |
2/4✓ Branch 7 → 8 taken 133 times.
✗ Branch 7 → 20 not taken.
✓ Branch 8 → 9 taken 133 times.
✗ Branch 8 → 18 not taken.
|
133 | ScopeHandle scopeHandle(this, node->getScopeId(), ScopeType::IF_ELSE_BODY, node); |
| 360 | |||
| 361 | // Generate IR for nested statements | ||
| 362 |
1/2✓ Branch 10 → 11 taken 133 times.
✗ Branch 10 → 22 not taken.
|
133 | visit(node->body); |
| 363 | 133 | } | |
| 364 | |||
| 365 |
1/2✓ Branch 14 → 15 taken 185 times.
✗ Branch 14 → 26 not taken.
|
185 | return nullptr; |
| 366 | } | ||
| 367 | |||
| 368 | 8 | std::any IRGenerator::visitSwitchStmt(const SwitchStmtNode *node) { | |
| 369 |
1/2✓ Branch 2 → 3 taken 8 times.
✗ Branch 2 → 107 not taken.
|
8 | diGenerator.setSourceLocation(node); |
| 370 | |||
| 371 | // Create blocks | ||
| 372 | 8 | std::vector<llvm::BasicBlock *> bCases; | |
| 373 |
1/2✓ Branch 4 → 5 taken 8 times.
✗ Branch 4 → 105 not taken.
|
8 | bCases.reserve(node->caseBranches.size()); |
| 374 |
2/2✓ Branch 16 → 7 taken 49 times.
✓ Branch 16 → 17 taken 8 times.
|
57 | for (const auto caseBranch : node->caseBranches) |
| 375 |
4/8✓ Branch 8 → 9 taken 49 times.
✗ Branch 8 → 82 not taken.
✓ Branch 9 → 10 taken 49 times.
✗ Branch 9 → 80 not taken.
✓ Branch 10 → 11 taken 49 times.
✗ Branch 10 → 78 not taken.
✓ Branch 11 → 12 taken 49 times.
✗ Branch 11 → 78 not taken.
|
49 | bCases.push_back(createBlock("switch.case." + caseBranch->codeLoc.toPrettyLine())); |
| 376 | 8 | llvm::BasicBlock *bDefault = nullptr; | |
| 377 |
2/2✓ Branch 17 → 18 taken 4 times.
✓ Branch 17 → 24 taken 4 times.
|
8 | if (node->hasDefaultBranch) |
| 378 |
3/6✓ Branch 18 → 19 taken 4 times.
✗ Branch 18 → 90 not taken.
✓ Branch 19 → 20 taken 4 times.
✗ Branch 19 → 88 not taken.
✓ Branch 20 → 21 taken 4 times.
✗ Branch 20 → 86 not taken.
|
4 | bDefault = createBlock("switch.default." + node->defaultBranch->codeLoc.toPrettyLine()); |
| 379 |
1/2✓ Branch 24 → 25 taken 8 times.
✗ Branch 24 → 105 not taken.
|
8 | const std::string codeLine = node->codeLoc.toPrettyLine(); |
| 380 |
2/4✓ Branch 25 → 26 taken 8 times.
✗ Branch 25 → 94 not taken.
✓ Branch 26 → 27 taken 8 times.
✗ Branch 26 → 92 not taken.
|
8 | llvm::BasicBlock *bExit = createBlock("switch.exit." + codeLine); |
| 381 | |||
| 382 | // Save the blocks for break and continue | ||
| 383 |
1/2✓ Branch 28 → 29 taken 8 times.
✗ Branch 28 → 103 not taken.
|
8 | breakBlocks.push_back(bExit); |
| 384 | |||
| 385 | // Visit switch expression | ||
| 386 |
1/2✓ Branch 29 → 30 taken 8 times.
✗ Branch 29 → 103 not taken.
|
8 | llvm::Value *exprValue = resolveValue(node->assignExpr); |
| 387 | |||
| 388 | // Generate switch instruction | ||
| 389 |
3/4✓ Branch 31 → 32 taken 4 times.
✓ Branch 31 → 33 taken 4 times.
✓ Branch 34 → 35 taken 8 times.
✗ Branch 34 → 103 not taken.
|
8 | llvm::SwitchInst *switchInst = builder.CreateSwitch(exprValue, bDefault ? bDefault : bExit, node->caseBranches.size()); |
| 390 | |||
| 391 | // Generate case branches | ||
| 392 |
2/2✓ Branch 62 → 36 taken 49 times.
✓ Branch 62 → 63 taken 8 times.
|
57 | for (size_t i = 0; i < node->caseBranches.size(); i++) { |
| 393 |
1/2✓ Branch 36 → 37 taken 49 times.
✗ Branch 36 → 100 not taken.
|
49 | const CaseBranchNode *caseBranch = node->caseBranches.at(i); |
| 394 | |||
| 395 | // Push fallthrough block | ||
| 396 | 49 | llvm::BasicBlock *bFallthrough = bDefault; | |
| 397 |
2/2✓ Branch 38 → 39 taken 41 times.
✓ Branch 38 → 41 taken 8 times.
|
49 | if (i + 1 < node->caseBranches.size()) |
| 398 |
1/2✓ Branch 39 → 40 taken 41 times.
✗ Branch 39 → 100 not taken.
|
41 | bFallthrough = bCases.at(i + 1); |
| 399 |
1/2✓ Branch 41 → 42 taken 49 times.
✗ Branch 41 → 100 not taken.
|
49 | fallthroughBlocks.push(bFallthrough); |
| 400 | |||
| 401 | // Switch to case block | ||
| 402 |
2/4✓ Branch 42 → 43 taken 49 times.
✗ Branch 42 → 100 not taken.
✓ Branch 43 → 44 taken 49 times.
✗ Branch 43 → 100 not taken.
|
49 | switchToBlock(bCases.at(i)); |
| 403 | |||
| 404 | // Visit case body | ||
| 405 |
1/2✓ Branch 44 → 45 taken 49 times.
✗ Branch 44 → 95 not taken.
|
49 | visit(caseBranch); |
| 406 | |||
| 407 | // Create jump from case to exit block | ||
| 408 |
1/2✓ Branch 46 → 47 taken 49 times.
✗ Branch 46 → 100 not taken.
|
49 | insertJump(bExit); |
| 409 | |||
| 410 | // Pop fallthrough block | ||
| 411 | 49 | fallthroughBlocks.pop(); | |
| 412 | |||
| 413 | // Add case to switch instruction | ||
| 414 |
2/2✓ Branch 59 → 50 taken 66 times.
✓ Branch 59 → 60 taken 49 times.
|
115 | for (const CaseConstantNode *caseConstantNode : caseBranch->caseConstants) { |
| 415 |
2/4✓ Branch 51 → 52 taken 66 times.
✗ Branch 51 → 98 not taken.
✓ Branch 52 → 53 taken 66 times.
✗ Branch 52 → 96 not taken.
|
66 | const auto caseValue = std::any_cast<llvm::Constant *>(visit(caseConstantNode)); |
| 416 |
3/6✓ Branch 54 → 55 taken 66 times.
✗ Branch 54 → 99 not taken.
✓ Branch 55 → 56 taken 66 times.
✗ Branch 55 → 99 not taken.
✓ Branch 56 → 57 taken 66 times.
✗ Branch 56 → 99 not taken.
|
66 | switchInst->addCase(llvm::cast<llvm::ConstantInt>(caseValue), bCases.at(i)); |
| 417 | } | ||
| 418 | } | ||
| 419 | |||
| 420 | // Generate default branch | ||
| 421 |
2/2✓ Branch 63 → 64 taken 4 times.
✓ Branch 63 → 68 taken 4 times.
|
8 | if (node->hasDefaultBranch) { |
| 422 | // Switch to default block | ||
| 423 |
1/2✓ Branch 64 → 65 taken 4 times.
✗ Branch 64 → 103 not taken.
|
4 | switchToBlock(bDefault); |
| 424 | |||
| 425 | // Visit default body | ||
| 426 |
1/2✓ Branch 65 → 66 taken 4 times.
✗ Branch 65 → 101 not taken.
|
4 | visit(node->defaultBranch); |
| 427 | |||
| 428 | // Create jump from default to exit block | ||
| 429 |
1/2✓ Branch 67 → 68 taken 4 times.
✗ Branch 67 → 103 not taken.
|
4 | insertJump(bExit); |
| 430 | } | ||
| 431 | |||
| 432 | // Switch to exit block | ||
| 433 |
1/2✓ Branch 68 → 69 taken 8 times.
✗ Branch 68 → 103 not taken.
|
8 | switchToBlock(bExit); |
| 434 | |||
| 435 | // Pop basic blocks from break stack | ||
| 436 |
1/2✗ Branch 70 → 71 not taken.
✓ Branch 70 → 72 taken 8 times.
|
8 | assert(breakBlocks.back() == bExit); |
| 437 | 8 | breakBlocks.pop_back(); | |
| 438 | |||
| 439 |
1/2✓ Branch 73 → 74 taken 8 times.
✗ Branch 73 → 102 not taken.
|
16 | return nullptr; |
| 440 | 8 | } | |
| 441 | |||
| 442 | 49 | std::any IRGenerator::visitCaseBranch(const CaseBranchNode *node) { | |
| 443 |
1/2✓ Branch 2 → 3 taken 49 times.
✗ Branch 2 → 20 not taken.
|
49 | diGenerator.setSourceLocation(node); |
| 444 | |||
| 445 | // Change to case body scope | ||
| 446 |
2/4✓ Branch 3 → 4 taken 49 times.
✗ Branch 3 → 14 not taken.
✓ Branch 4 → 5 taken 49 times.
✗ Branch 4 → 12 not taken.
|
49 | ScopeHandle scopeHandle(this, node->getScopeId(), ScopeType::CASE_BODY); |
| 447 | |||
| 448 | // Visit case body | ||
| 449 |
1/2✓ Branch 6 → 7 taken 49 times.
✗ Branch 6 → 16 not taken.
|
49 | visit(node->body); |
| 450 | |||
| 451 |
1/2✓ Branch 8 → 9 taken 49 times.
✗ Branch 8 → 17 not taken.
|
98 | return nullptr; |
| 452 | 49 | } | |
| 453 | |||
| 454 | 4 | std::any IRGenerator::visitDefaultBranch(const DefaultBranchNode *node) { | |
| 455 |
1/2✓ Branch 2 → 3 taken 4 times.
✗ Branch 2 → 20 not taken.
|
4 | diGenerator.setSourceLocation(node); |
| 456 | |||
| 457 | // Change to default body scope | ||
| 458 |
2/4✓ Branch 3 → 4 taken 4 times.
✗ Branch 3 → 14 not taken.
✓ Branch 4 → 5 taken 4 times.
✗ Branch 4 → 12 not taken.
|
4 | ScopeHandle scopeHandle(this, node->getScopeId(), ScopeType::DEFAULT_BODY); |
| 459 | |||
| 460 | // Visit case body | ||
| 461 |
1/2✓ Branch 6 → 7 taken 4 times.
✗ Branch 6 → 16 not taken.
|
4 | visit(node->body); |
| 462 | |||
| 463 |
1/2✓ Branch 8 → 9 taken 4 times.
✗ Branch 8 → 17 not taken.
|
8 | return nullptr; |
| 464 | 4 | } | |
| 465 | |||
| 466 | 30 | std::any IRGenerator::visitAnonymousBlockStmt(const AnonymousBlockStmtNode *node) { | |
| 467 |
1/2✓ Branch 2 → 3 taken 30 times.
✗ Branch 2 → 20 not taken.
|
30 | diGenerator.setSourceLocation(node); |
| 468 | |||
| 469 | // Change scope | ||
| 470 | 30 | node->bodyScope->parent = currentScope; // Needed for nested scopes in generic functions | |
| 471 | 30 | node->bodyScope->symbolTable.parent = ¤tScope->symbolTable; // Needed for nested scopes in generic functions | |
| 472 |
2/4✓ Branch 3 → 4 taken 30 times.
✗ Branch 3 → 14 not taken.
✓ Branch 4 → 5 taken 30 times.
✗ Branch 4 → 12 not taken.
|
30 | ScopeHandle scopeHandle(this, node->getScopeId(), ScopeType::ANONYMOUS_BLOCK_BODY, node); |
| 473 | |||
| 474 | // Visit instructions in the block | ||
| 475 |
1/2✓ Branch 6 → 7 taken 30 times.
✗ Branch 6 → 16 not taken.
|
30 | visit(node->body); |
| 476 | |||
| 477 |
1/2✓ Branch 8 → 9 taken 30 times.
✗ Branch 8 → 17 not taken.
|
60 | return nullptr; |
| 478 | 30 | } | |
| 479 | |||
| 480 | } // namespace spice::compiler | ||
| 481 |