(cfg, branchBlock, mergeBlock, initialVar, phiNode, conditionNode, updateResult)
| 115 | } |
| 116 | |
| 117 | buildBoundedLoop(cfg, branchBlock, mergeBlock, initialVar, phiNode, conditionNode, updateResult) { |
| 118 | // For bounded loops, create FOR block with three statements: init, condition, update |
| 119 | const forBlock = CFG.createBasicBlock(cfg, BlockType.FOR); |
| 120 | CFG.addEdge(cfg, branchBlock, forBlock); |
| 121 | |
| 122 | // Now add only the specific nodes we need to the FOR block |
| 123 | CFG.pushBlock(cfg, forBlock); |
| 124 | |
| 125 | // 1. Init statement - assign initial value to phi node (or empty if no initializer) |
| 126 | if (initialVar) { |
| 127 | const initAssignmentNode = DAG.createNodeData({ |
| 128 | nodeType: NodeType.ASSIGNMENT, |
| 129 | dependsOn: [phiNode.id, initialVar.id], |
| 130 | phiBlocks: [] |
| 131 | }); |
| 132 | const initAssignmentID = DAG.getOrCreateNode(this.strandsContext.dag, initAssignmentNode); |
| 133 | CFG.recordInBasicBlock(cfg, forBlock, initAssignmentID); |
| 134 | } |
| 135 | |
| 136 | // 2. Condition statement - wrap in ExpressionStatement to force generation |
| 137 | const conditionStatementNode = DAG.createNodeData({ |
| 138 | nodeType: NodeType.STATEMENT, |
| 139 | statementType: StatementType.EXPRESSION, |
| 140 | dependsOn: [conditionNode.id], |
| 141 | phiBlocks: [] |
| 142 | }); |
| 143 | const conditionStatementID = DAG.getOrCreateNode(this.strandsContext.dag, conditionStatementNode); |
| 144 | CFG.recordInBasicBlock(cfg, forBlock, conditionStatementID); |
| 145 | |
| 146 | // 3. Update statement - create assignment of update result to phi node |
| 147 | const updateAssignmentNode = DAG.createNodeData({ |
| 148 | nodeType: NodeType.ASSIGNMENT, |
| 149 | dependsOn: [phiNode.id, updateResult.id], |
| 150 | phiBlocks: [] |
| 151 | }); |
| 152 | const updateAssignmentID = DAG.getOrCreateNode(this.strandsContext.dag, updateAssignmentNode); |
| 153 | CFG.recordInBasicBlock(cfg, forBlock, updateAssignmentID); |
| 154 | |
| 155 | CFG.popBlock(cfg); |
| 156 | |
| 157 | // Verify we have the right number of statements (2 or 3 depending on initializer) |
| 158 | const instructions = cfg.blockInstructions[forBlock] || []; |
| 159 | const expectedLength = initialVar ? 3 : 2; |
| 160 | if (instructions.length !== expectedLength) { |
| 161 | throw new Error(`FOR block must have exactly ${expectedLength} statements, got ${instructions.length}`); |
| 162 | } |
| 163 | |
| 164 | const scopeStartBlock = CFG.createBasicBlock(cfg, BlockType.SCOPE_START); |
| 165 | CFG.addEdge(cfg, forBlock, scopeStartBlock); |
| 166 | |
| 167 | const bodyBlock = CFG.createBasicBlock(cfg, BlockType.DEFAULT); |
| 168 | this.bodyBlock = bodyBlock; |
| 169 | CFG.addEdge(cfg, scopeStartBlock, bodyBlock); |
| 170 | |
| 171 | this.executeBodyCallback(cfg, branchBlock, bodyBlock, phiNode); |
| 172 | |
| 173 | const scopeEndBlock = CFG.createBasicBlock(cfg, BlockType.SCOPE_END); |
| 174 | CFG.addEdge(cfg, bodyBlock, scopeEndBlock); |
no test coverage detected