MCPcopy Index your code
hub / github.com/processing/p5.js / createPhiNode

Function createPhiNode

src/strands/strands_phi_utils.js:5–51  ·  view source on GitHub ↗
(strandsContext, phiInputs, varName)

Source from the content-addressed store, hash-verified

3import { NodeType, BaseType } from './ir_types';
4
5export function createPhiNode(strandsContext, phiInputs, varName) {
6 // Determine the proper dimension and baseType from the inputs
7 const validInputs = phiInputs.filter(input => input.value.id !== null);
8 if (validInputs.length === 0) {
9 throw new Error(`No valid inputs for phi node for variable ${varName}`);
10 }
11
12 // Get dimension and baseType from first valid input, skipping ASSIGN_ON_USE nodes
13 const inputNodes = validInputs.map((input) => DAG.getNodeDataFromID(strandsContext.dag, input.value.id));
14
15 // Find first non-ASSIGN_ON_USE input to determine type
16 let typeSource = inputNodes.find((input) => input.baseType !== BaseType.ASSIGN_ON_USE && input.dimension) ??
17 inputNodes.find((input) => input.baseType !== BaseType.ASSIGN_ON_USE);
18
19 // If all are ASSIGN_ON_USE, fall back to first input
20 if (!typeSource) {
21 typeSource = inputNodes[0];
22 }
23
24 const dimension = typeSource.dimension;
25 const baseType = typeSource.baseType;
26
27 // Propagate the type to all ASSIGN_ON_USE inputs
28 if (baseType !== BaseType.ASSIGN_ON_USE) {
29 for (const input of inputNodes) {
30 if (input.baseType === BaseType.ASSIGN_ON_USE) {
31 DAG.propagateTypeToAssignOnUse(strandsContext.dag, input.id, baseType, dimension);
32 }
33 }
34 }
35
36 const nodeData = {
37 nodeType: NodeType.PHI,
38 dimension,
39 baseType,
40 dependsOn: phiInputs.map(input => input.value.id).filter(id => id !== null),
41 phiBlocks: phiInputs.map(input => input.blockId),
42 phiInputs // Store the full phi input information
43 };
44 const id = DAG.getOrCreateNode(strandsContext.dag, nodeData);
45 CFG.recordInBasicBlock(strandsContext.cfg, strandsContext.cfg.currentBlock, id);
46 return {
47 id,
48 dimension,
49 baseType
50 };
51}

Callers 3

buildConditionalFunction · 0.90
executeBodyCallbackMethod · 0.90

Calls 1

filterMethod · 0.45

Tested by

no test coverage detected