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