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