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