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