| 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 |
1/2✓ Branch 93 → 94 taken 5 times.
✗ Branch 93 → 223 not taken.
|
5 | llvm::Type *pairTy = node->getIdxFct->returnType.toLLVMType(sourceFile); |
| 168 |
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(pairTy, "pair.addr"); |
| 169 | // Call .getIdx() on iterator | ||
| 170 |
1/2✗ Branch 100 → 101 not taken.
✓ Branch 100 → 102 taken 5 times.
|
5 | assert(node->getIdxFct); |
| 171 |
1/2✓ Branch 102 → 103 taken 5 times.
✗ Branch 102 → 223 not taken.
|
5 | llvm::Function *getIdxFct = stdFunctionManager.getIteratorGetIdxFct(node->getIdxFct); |
| 172 |
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); |
| 173 |
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"); |
| 174 |
1/2✓ Branch 109 → 110 taken 5 times.
✗ Branch 109 → 223 not taken.
|
5 | insertStore(pair, pairPtr); |
| 175 | // Store idx to idx var | ||
| 176 |
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"); |
| 177 | 5 | LLVMExprResult idxResult = {.ptr = idxAddrInPair}; | |
| 178 |
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); |
| 179 |
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); |
| 180 | // Store item to item var | ||
| 181 |
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"); |
| 182 | 5 | LLVMExprResult itemResult = {.refPtr = itemAddrInPair}; | |
| 183 |
1/2✓ Branch 128 → 129 taken 5 times.
✗ Branch 128 → 222 not taken.
|
5 | doAssignment(itemAddress, itemEntry, itemResult, itemRefSTy, node, true); |
| 184 | } else { | ||
| 185 | // Call .get() on iterator | ||
| 186 |
1/2✗ Branch 130 → 131 not taken.
✓ Branch 130 → 132 taken 105 times.
|
105 | assert(node->getFct); |
| 187 |
1/2✓ Branch 132 → 133 taken 105 times.
✗ Branch 132 → 228 not taken.
|
105 | llvm::Function *getFct = stdFunctionManager.getIteratorGetFct(node->getFct); |
| 188 |
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); |
| 189 | 105 | LLVMExprResult getResult = {.ptr = getItemPtr}; | |
| 190 |
1/2✓ Branch 137 → 138 taken 105 times.
✗ Branch 137 → 227 not taken.
|
105 | doAssignment(itemAddress, itemEntry, getResult, itemRefSTy, node, true); |
| 191 | } | ||
| 192 | // Visit body | ||
| 193 |
1/2✓ Branch 139 → 140 taken 110 times.
✗ Branch 139 → 229 not taken.
|
110 | visit(node->body); |
| 194 | // Create jump from body to tail block | ||
| 195 |
1/2✓ Branch 141 → 142 taken 110 times.
✗ Branch 141 → 234 not taken.
|
110 | insertJump(bTail); |
| 196 | |||
| 197 | // Switch to tail block | ||
| 198 |
1/2✓ Branch 142 → 143 taken 110 times.
✗ Branch 142 → 234 not taken.
|
110 | switchToBlock(bTail); |
| 199 | // Call .next() on iterator | ||
| 200 |
1/2✗ Branch 143 → 144 not taken.
✓ Branch 143 → 145 taken 110 times.
|
110 | assert(node->nextFct); |
| 201 |
1/2✓ Branch 145 → 146 taken 110 times.
✗ Branch 145 → 234 not taken.
|
110 | llvm::Function *nextFct = stdFunctionManager.getIteratorNextFct(node->nextFct); |
| 202 |
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); |
| 203 | // Create jump from tail to head block | ||
| 204 |
1/2✓ Branch 150 → 151 taken 110 times.
✗ Branch 150 → 234 not taken.
|
110 | insertJump(bHead); |
| 205 | |||
| 206 | // Switch to exit block | ||
| 207 |
1/2✓ Branch 151 → 152 taken 110 times.
✗ Branch 151 → 234 not taken.
|
110 | switchToBlock(bExit); |
| 208 | |||
| 209 | // Pop basic blocks from break and continue stacks | ||
| 210 |
1/2✗ Branch 153 → 154 not taken.
✓ Branch 153 → 155 taken 110 times.
|
110 | assert(breakBlocks.back() == bExit); |
| 211 | 110 | breakBlocks.pop_back(); | |
| 212 |
1/2✗ Branch 157 → 158 not taken.
✓ Branch 157 → 159 taken 110 times.
|
110 | assert(continueBlocks.back() == bTail); |
| 213 | 110 | continueBlocks.pop_back(); | |
| 214 | |||
| 215 |
1/2✓ Branch 160 → 161 taken 110 times.
✗ Branch 160 → 233 not taken.
|
220 | return nullptr; |
| 216 | 110 | } | |
| 217 | |||
| 218 | 671 | std::any IRGenerator::visitWhileLoop(const WhileLoopNode *node) { | |
| 219 |
1/2✓ Branch 2 → 3 taken 671 times.
✗ Branch 2 → 59 not taken.
|
671 | diGenerator.setSourceLocation(node); |
| 220 | |||
| 221 | // Create blocks | ||
| 222 |
1/2✓ Branch 3 → 4 taken 671 times.
✗ Branch 3 → 59 not taken.
|
671 | const std::string codeLine = node->codeLoc.toPrettyLine(); |
| 223 |
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); |
| 224 |
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); |
| 225 |
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); |
| 226 | |||
| 227 | // Change scope | ||
| 228 |
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); |
| 229 | |||
| 230 | // Save the blocks for break and continue | ||
| 231 |
1/2✓ Branch 16 → 17 taken 671 times.
✗ Branch 16 → 55 not taken.
|
671 | breakBlocks.push_back(bExit); |
| 232 |
1/2✓ Branch 17 → 18 taken 671 times.
✗ Branch 17 → 55 not taken.
|
671 | continueBlocks.push_back(bHead); |
| 233 | |||
| 234 | // Jump to head block | ||
| 235 |
1/2✓ Branch 18 → 19 taken 671 times.
✗ Branch 18 → 55 not taken.
|
671 | insertJump(bHead); |
| 236 | |||
| 237 | // Switch to head block | ||
| 238 |
1/2✓ Branch 19 → 20 taken 671 times.
✗ Branch 19 → 55 not taken.
|
671 | switchToBlock(bHead); |
| 239 | // Evaluate condition | ||
| 240 |
1/2✓ Branch 20 → 21 taken 671 times.
✗ Branch 20 → 55 not taken.
|
671 | llvm::Value *condValue = resolveValue(node->condition); |
| 241 | // Jump to body or exit block, depending on the condition | ||
| 242 |
1/2✓ Branch 21 → 22 taken 671 times.
✗ Branch 21 → 55 not taken.
|
671 | insertCondJump(condValue, bBody, bExit); |
| 243 | |||
| 244 | // Switch to body block | ||
| 245 |
1/2✓ Branch 22 → 23 taken 671 times.
✗ Branch 22 → 55 not taken.
|
671 | switchToBlock(bBody); |
| 246 | // Visit body | ||
| 247 |
1/2✓ Branch 23 → 24 taken 671 times.
✗ Branch 23 → 53 not taken.
|
671 | visit(node->body); |
| 248 | // Create jump to head block | ||
| 249 |
1/2✓ Branch 25 → 26 taken 671 times.
✗ Branch 25 → 55 not taken.
|
671 | insertJump(bHead); |
| 250 | |||
| 251 | // Switch to exit block | ||
| 252 |
1/2✓ Branch 26 → 27 taken 671 times.
✗ Branch 26 → 55 not taken.
|
671 | switchToBlock(bExit); |
| 253 | |||
| 254 | // Pop basic blocks from break and continue stacks | ||
| 255 |
1/2✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 671 times.
|
671 | assert(breakBlocks.back() == bExit); |
| 256 | 671 | breakBlocks.pop_back(); | |
| 257 |
1/2✗ Branch 32 → 33 not taken.
✓ Branch 32 → 34 taken 671 times.
|
671 | assert(continueBlocks.back() == bHead); |
| 258 | 671 | continueBlocks.pop_back(); | |
| 259 | |||
| 260 |
1/2✓ Branch 35 → 36 taken 671 times.
✗ Branch 35 → 54 not taken.
|
1342 | return nullptr; |
| 261 | 671 | } | |
| 262 | |||
| 263 | 8 | std::any IRGenerator::visitDoWhileLoop(const DoWhileLoopNode *node) { | |
| 264 |
1/2✓ Branch 2 → 3 taken 8 times.
✗ Branch 2 → 59 not taken.
|
8 | diGenerator.setSourceLocation(node); |
| 265 | |||
| 266 | // Create blocks | ||
| 267 |
1/2✓ Branch 3 → 4 taken 8 times.
✗ Branch 3 → 59 not taken.
|
8 | const std::string codeLine = node->codeLoc.toPrettyLine(); |
| 268 |
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); |
| 269 |
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); |
| 270 |
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); |
| 271 | |||
| 272 | // Change scope | ||
| 273 |
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); |
| 274 | |||
| 275 | // Save the blocks for break and continue | ||
| 276 |
1/2✓ Branch 16 → 17 taken 8 times.
✗ Branch 16 → 55 not taken.
|
8 | breakBlocks.push_back(bExit); |
| 277 |
1/2✓ Branch 17 → 18 taken 8 times.
✗ Branch 17 → 55 not taken.
|
8 | continueBlocks.push_back(bFoot); |
| 278 | |||
| 279 | // Jump to body block | ||
| 280 |
1/2✓ Branch 18 → 19 taken 8 times.
✗ Branch 18 → 55 not taken.
|
8 | insertJump(bBody); |
| 281 | |||
| 282 | // Switch to body block | ||
| 283 |
1/2✓ Branch 19 → 20 taken 8 times.
✗ Branch 19 → 55 not taken.
|
8 | switchToBlock(bBody); |
| 284 | // Visit body | ||
| 285 |
1/2✓ Branch 20 → 21 taken 8 times.
✗ Branch 20 → 53 not taken.
|
8 | visit(node->body); |
| 286 | // Create jump to foot block | ||
| 287 |
1/2✓ Branch 22 → 23 taken 8 times.
✗ Branch 22 → 55 not taken.
|
8 | insertJump(bFoot); |
| 288 | |||
| 289 | // Switch to head block | ||
| 290 |
1/2✓ Branch 23 → 24 taken 8 times.
✗ Branch 23 → 55 not taken.
|
8 | switchToBlock(bFoot); |
| 291 | // Evaluate condition | ||
| 292 |
1/2✓ Branch 24 → 25 taken 8 times.
✗ Branch 24 → 55 not taken.
|
8 | llvm::Value *condValue = resolveValue(node->condition); |
| 293 | // Jump to body or exit block, depending on the condition | ||
| 294 |
1/2✓ Branch 25 → 26 taken 8 times.
✗ Branch 25 → 55 not taken.
|
8 | insertCondJump(condValue, bBody, bExit); |
| 295 | |||
| 296 | // Switch to exit block | ||
| 297 |
1/2✓ Branch 26 → 27 taken 8 times.
✗ Branch 26 → 55 not taken.
|
8 | switchToBlock(bExit); |
| 298 | |||
| 299 | // Pop basic blocks from break and continue stacks | ||
| 300 |
1/2✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 8 times.
|
8 | assert(breakBlocks.back() == bExit); |
| 301 | 8 | breakBlocks.pop_back(); | |
| 302 |
1/2✗ Branch 32 → 33 not taken.
✓ Branch 32 → 34 taken 8 times.
|
8 | assert(continueBlocks.back() == bFoot); |
| 303 | 8 | continueBlocks.pop_back(); | |
| 304 | |||
| 305 |
1/2✓ Branch 35 → 36 taken 8 times.
✗ Branch 35 → 54 not taken.
|
16 | return nullptr; |
| 306 | 8 | } | |
| 307 | |||
| 308 | 4018 | std::any IRGenerator::visitIfStmt(const IfStmtNode *node) { | |
| 309 |
1/2✓ Branch 2 → 3 taken 4018 times.
✗ Branch 2 → 62 not taken.
|
4018 | diGenerator.setSourceLocation(node); |
| 310 | |||
| 311 | // Create blocks | ||
| 312 |
1/2✓ Branch 3 → 4 taken 4018 times.
✗ Branch 3 → 62 not taken.
|
4018 | const std::string codeLine = node->codeLoc.toPrettyLine(); |
| 313 |
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); |
| 314 |
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; |
| 315 |
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); |
| 316 | |||
| 317 | // Change scope | ||
| 318 |
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); |
| 319 | |||
| 320 | // Retrieve condition value | ||
| 321 |
1/2✓ Branch 20 → 21 taken 4018 times.
✗ Branch 20 → 58 not taken.
|
4018 | llvm::Value *condValue = resolveValue(node->condition); |
| 322 | // Check if condition is fulfilled | ||
| 323 |
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); |
| 324 | |||
| 325 | // Switch to then block | ||
| 326 |
1/2✓ Branch 25 → 26 taken 4018 times.
✗ Branch 25 → 58 not taken.
|
4018 | switchToBlock(bThen); |
| 327 | // Visit then body | ||
| 328 |
1/2✓ Branch 26 → 27 taken 4018 times.
✗ Branch 26 → 56 not taken.
|
4018 | visit(node->thenBody); |
| 329 | // Create jump from then to end block | ||
| 330 |
1/2✓ Branch 28 → 29 taken 4018 times.
✗ Branch 28 → 58 not taken.
|
4018 | insertJump(bExit); |
| 331 | |||
| 332 | // Change scope back | ||
| 333 |
1/2✓ Branch 29 → 30 taken 4018 times.
✗ Branch 29 → 58 not taken.
|
4018 | scopeHandle.leaveScopeEarly(); |
| 334 | |||
| 335 |
2/2✓ Branch 30 → 31 taken 185 times.
✓ Branch 30 → 35 taken 3833 times.
|
4018 | if (node->elseStmt) { |
| 336 | // Switch to else block | ||
| 337 |
1/2✓ Branch 31 → 32 taken 185 times.
✗ Branch 31 → 58 not taken.
|
185 | switchToBlock(bElse); |
| 338 | // Visit else block | ||
| 339 |
1/2✓ Branch 32 → 33 taken 185 times.
✗ Branch 32 → 57 not taken.
|
185 | visit(node->elseStmt); |
| 340 | // Create jump from else to end block | ||
| 341 |
1/2✓ Branch 34 → 35 taken 185 times.
✗ Branch 34 → 58 not taken.
|
185 | insertJump(bExit); |
| 342 | } | ||
| 343 | |||
| 344 | // Switch to exit block | ||
| 345 |
1/2✓ Branch 35 → 36 taken 4018 times.
✗ Branch 35 → 58 not taken.
|
4018 | switchToBlock(bExit); |
| 346 | |||
| 347 | // Return conditional value as result for the 'if' stmt | ||
| 348 |
1/2✓ Branch 36 → 37 taken 4018 times.
✗ Branch 36 → 58 not taken.
|
8036 | return condValue; |
| 349 | 4018 | } | |
| 350 | |||
| 351 | 185 | std::any IRGenerator::visitElseStmt(const ElseStmtNode *node) { | |
| 352 | 185 | diGenerator.setSourceLocation(node); | |
| 353 | |||
| 354 |
2/2✓ Branch 3 → 4 taken 52 times.
✓ Branch 3 → 7 taken 133 times.
|
185 | if (node->ifStmt) { // It is an else if branch |
| 355 |
1/2✓ Branch 4 → 5 taken 52 times.
✗ Branch 4 → 17 not taken.
|
52 | visit(node->ifStmt); |
| 356 | } else { // It is an else branch | ||
| 357 | // Change scope | ||
| 358 |
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); |
| 359 | |||
| 360 | // Generate IR for nested statements | ||
| 361 |
1/2✓ Branch 10 → 11 taken 133 times.
✗ Branch 10 → 22 not taken.
|
133 | visit(node->body); |
| 362 | 133 | } | |
| 363 | |||
| 364 |
1/2✓ Branch 14 → 15 taken 185 times.
✗ Branch 14 → 26 not taken.
|
185 | return nullptr; |
| 365 | } | ||
| 366 | |||
| 367 | 8 | std::any IRGenerator::visitSwitchStmt(const SwitchStmtNode *node) { | |
| 368 |
1/2✓ Branch 2 → 3 taken 8 times.
✗ Branch 2 → 107 not taken.
|
8 | diGenerator.setSourceLocation(node); |
| 369 | |||
| 370 | // Create blocks | ||
| 371 | 8 | std::vector<llvm::BasicBlock *> bCases; | |
| 372 |
1/2✓ Branch 4 → 5 taken 8 times.
✗ Branch 4 → 105 not taken.
|
8 | bCases.reserve(node->caseBranches.size()); |
| 373 |
2/2✓ Branch 16 → 7 taken 49 times.
✓ Branch 16 → 17 taken 8 times.
|
57 | for (const auto caseBranch : node->caseBranches) |
| 374 |
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())); |
| 375 | 8 | llvm::BasicBlock *bDefault = nullptr; | |
| 376 |
2/2✓ Branch 17 → 18 taken 4 times.
✓ Branch 17 → 24 taken 4 times.
|
8 | if (node->hasDefaultBranch) |
| 377 |
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()); |
| 378 |
1/2✓ Branch 24 → 25 taken 8 times.
✗ Branch 24 → 105 not taken.
|
8 | const std::string codeLine = node->codeLoc.toPrettyLine(); |
| 379 |
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); |
| 380 | |||
| 381 | // Save the blocks for break and continue | ||
| 382 |
1/2✓ Branch 28 → 29 taken 8 times.
✗ Branch 28 → 103 not taken.
|
8 | breakBlocks.push_back(bExit); |
| 383 | |||
| 384 | // Visit switch expression | ||
| 385 |
1/2✓ Branch 29 → 30 taken 8 times.
✗ Branch 29 → 103 not taken.
|
8 | llvm::Value *exprValue = resolveValue(node->assignExpr); |
| 386 | |||
| 387 | // Generate switch instruction | ||
| 388 |
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()); |
| 389 | |||
| 390 | // Generate case branches | ||
| 391 |
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++) { |
| 392 |
1/2✓ Branch 36 → 37 taken 49 times.
✗ Branch 36 → 100 not taken.
|
49 | const CaseBranchNode *caseBranch = node->caseBranches.at(i); |
| 393 | |||
| 394 | // Push fallthrough block | ||
| 395 | 49 | llvm::BasicBlock *bFallthrough = bDefault; | |
| 396 |
2/2✓ Branch 38 → 39 taken 41 times.
✓ Branch 38 → 41 taken 8 times.
|
49 | if (i + 1 < node->caseBranches.size()) |
| 397 |
1/2✓ Branch 39 → 40 taken 41 times.
✗ Branch 39 → 100 not taken.
|
41 | bFallthrough = bCases.at(i + 1); |
| 398 |
1/2✓ Branch 41 → 42 taken 49 times.
✗ Branch 41 → 100 not taken.
|
49 | fallthroughBlocks.push(bFallthrough); |
| 399 | |||
| 400 | // Switch to case block | ||
| 401 |
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)); |
| 402 | |||
| 403 | // Visit case body | ||
| 404 |
1/2✓ Branch 44 → 45 taken 49 times.
✗ Branch 44 → 95 not taken.
|
49 | visit(caseBranch); |
| 405 | |||
| 406 | // Create jump from case to exit block | ||
| 407 |
1/2✓ Branch 46 → 47 taken 49 times.
✗ Branch 46 → 100 not taken.
|
49 | insertJump(bExit); |
| 408 | |||
| 409 | // Pop fallthrough block | ||
| 410 | 49 | fallthroughBlocks.pop(); | |
| 411 | |||
| 412 | // Add case to switch instruction | ||
| 413 |
2/2✓ Branch 59 → 50 taken 66 times.
✓ Branch 59 → 60 taken 49 times.
|
115 | for (const CaseConstantNode *caseConstantNode : caseBranch->caseConstants) { |
| 414 |
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)); |
| 415 |
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)); |
| 416 | } | ||
| 417 | } | ||
| 418 | |||
| 419 | // Generate default branch | ||
| 420 |
2/2✓ Branch 63 → 64 taken 4 times.
✓ Branch 63 → 68 taken 4 times.
|
8 | if (node->hasDefaultBranch) { |
| 421 | // Switch to default block | ||
| 422 |
1/2✓ Branch 64 → 65 taken 4 times.
✗ Branch 64 → 103 not taken.
|
4 | switchToBlock(bDefault); |
| 423 | |||
| 424 | // Visit default body | ||
| 425 |
1/2✓ Branch 65 → 66 taken 4 times.
✗ Branch 65 → 101 not taken.
|
4 | visit(node->defaultBranch); |
| 426 | |||
| 427 | // Create jump from default to exit block | ||
| 428 |
1/2✓ Branch 67 → 68 taken 4 times.
✗ Branch 67 → 103 not taken.
|
4 | insertJump(bExit); |
| 429 | } | ||
| 430 | |||
| 431 | // Switch to exit block | ||
| 432 |
1/2✓ Branch 68 → 69 taken 8 times.
✗ Branch 68 → 103 not taken.
|
8 | switchToBlock(bExit); |
| 433 | |||
| 434 | // Pop basic blocks from break stack | ||
| 435 |
1/2✗ Branch 70 → 71 not taken.
✓ Branch 70 → 72 taken 8 times.
|
8 | assert(breakBlocks.back() == bExit); |
| 436 | 8 | breakBlocks.pop_back(); | |
| 437 | |||
| 438 |
1/2✓ Branch 73 → 74 taken 8 times.
✗ Branch 73 → 102 not taken.
|
16 | return nullptr; |
| 439 | 8 | } | |
| 440 | |||
| 441 | 49 | std::any IRGenerator::visitCaseBranch(const CaseBranchNode *node) { | |
| 442 |
1/2✓ Branch 2 → 3 taken 49 times.
✗ Branch 2 → 20 not taken.
|
49 | diGenerator.setSourceLocation(node); |
| 443 | |||
| 444 | // Change to case body scope | ||
| 445 |
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); |
| 446 | |||
| 447 | // Visit case body | ||
| 448 |
1/2✓ Branch 6 → 7 taken 49 times.
✗ Branch 6 → 16 not taken.
|
49 | visit(node->body); |
| 449 | |||
| 450 |
1/2✓ Branch 8 → 9 taken 49 times.
✗ Branch 8 → 17 not taken.
|
98 | return nullptr; |
| 451 | 49 | } | |
| 452 | |||
| 453 | 4 | std::any IRGenerator::visitDefaultBranch(const DefaultBranchNode *node) { | |
| 454 |
1/2✓ Branch 2 → 3 taken 4 times.
✗ Branch 2 → 20 not taken.
|
4 | diGenerator.setSourceLocation(node); |
| 455 | |||
| 456 | // Change to default body scope | ||
| 457 |
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); |
| 458 | |||
| 459 | // Visit case body | ||
| 460 |
1/2✓ Branch 6 → 7 taken 4 times.
✗ Branch 6 → 16 not taken.
|
4 | visit(node->body); |
| 461 | |||
| 462 |
1/2✓ Branch 8 → 9 taken 4 times.
✗ Branch 8 → 17 not taken.
|
8 | return nullptr; |
| 463 | 4 | } | |
| 464 | |||
| 465 | 30 | std::any IRGenerator::visitAnonymousBlockStmt(const AnonymousBlockStmtNode *node) { | |
| 466 |
1/2✓ Branch 2 → 3 taken 30 times.
✗ Branch 2 → 20 not taken.
|
30 | diGenerator.setSourceLocation(node); |
| 467 | |||
| 468 | // Change scope | ||
| 469 | 30 | node->bodyScope->parent = currentScope; // Needed for nested scopes in generic functions | |
| 470 | 30 | node->bodyScope->symbolTable.parent = ¤tScope->symbolTable; // Needed for nested scopes in generic functions | |
| 471 |
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); |
| 472 | |||
| 473 | // Visit instructions in the block | ||
| 474 |
1/2✓ Branch 6 → 7 taken 30 times.
✗ Branch 6 → 16 not taken.
|
30 | visit(node->body); |
| 475 | |||
| 476 |
1/2✓ Branch 8 → 9 taken 30 times.
✗ Branch 8 → 17 not taken.
|
60 | return nullptr; |
| 477 | 30 | } | |
| 478 | |||
| 479 | } // namespace spice::compiler | ||
| 480 |