(strandsContext, bufferNode, indexNode, valueNode)
| 752 | } |
| 753 | |
| 754 | export function arrayAssignmentNode(strandsContext, bufferNode, indexNode, valueNode) { |
| 755 | const { dag, cfg } = strandsContext; |
| 756 | |
| 757 | // Ensure index is a StrandsNode |
| 758 | let index; |
| 759 | if (indexNode instanceof StrandsNode) { |
| 760 | index = indexNode; |
| 761 | } else { |
| 762 | const { id, dimension } = primitiveConstructorNode( |
| 763 | strandsContext, |
| 764 | { baseType: BaseType.INT, dimension: 1 }, |
| 765 | indexNode |
| 766 | ); |
| 767 | index = createStrandsNode(id, dimension, strandsContext); |
| 768 | } |
| 769 | |
| 770 | // Ensure value is a StrandsNode |
| 771 | let value; |
| 772 | if (valueNode instanceof StrandsNode) { |
| 773 | value = valueNode; |
| 774 | } else { |
| 775 | const { id, dimension } = primitiveConstructorNode( |
| 776 | strandsContext, |
| 777 | { baseType: BaseType.FLOAT, dimension: 1 }, |
| 778 | valueNode |
| 779 | ); |
| 780 | value = createStrandsNode(id, dimension, strandsContext); |
| 781 | } |
| 782 | |
| 783 | // Create array access node as the assignment target |
| 784 | const arrayAccessData = DAG.createNodeData({ |
| 785 | nodeType: NodeType.OPERATION, |
| 786 | opCode: OpCode.Binary.ARRAY_ACCESS, |
| 787 | dependsOn: [bufferNode.id, index.id], |
| 788 | dimension: 1, |
| 789 | baseType: BaseType.FLOAT |
| 790 | }); |
| 791 | const arrayAccessID = DAG.getOrCreateNode(dag, arrayAccessData); |
| 792 | |
| 793 | // Create assignment node: buffer[index] = value |
| 794 | const assignmentData = DAG.createNodeData({ |
| 795 | nodeType: NodeType.ASSIGNMENT, |
| 796 | dependsOn: [arrayAccessID, value.id], |
| 797 | phiBlocks: [] |
| 798 | }); |
| 799 | const assignmentID = DAG.getOrCreateNode(dag, assignmentData); |
| 800 | |
| 801 | // CRITICAL: Record in CFG to preserve sequential ordering |
| 802 | CFG.recordInBasicBlock(cfg, cfg.currentBlock, assignmentID); |
| 803 | |
| 804 | return { id: assignmentID }; |
| 805 | } |
no test coverage detected