UNPKG

p5

Version:

[![npm version](https://badge.fury.io/js/p5.svg)](https://www.npmjs.com/package/p5)

34 lines (33 loc) • 1.54 kB
import { BaseType, NodeType } from "./ir_types.js"; import { getNodeDataFromID, getOrCreateNode, propagateTypeToAssignOnUse } from "./ir_dag.js"; import { recordInBasicBlock } from "./ir_cfg.js"; //#region src/strands/strands_phi_utils.js function createPhiNode(strandsContext, phiInputs, varName) { const validInputs = phiInputs.filter((input) => input.value.id !== null); if (validInputs.length === 0) throw new Error(`No valid inputs for phi node for variable ${varName}`); const inputNodes = validInputs.map((input) => getNodeDataFromID(strandsContext.dag, input.value.id)); let typeSource = inputNodes.find((input) => input.baseType !== BaseType.ASSIGN_ON_USE && input.dimension) ?? inputNodes.find((input) => input.baseType !== BaseType.ASSIGN_ON_USE); if (!typeSource) typeSource = inputNodes[0]; const dimension = typeSource.dimension; const baseType = typeSource.baseType; if (baseType !== BaseType.ASSIGN_ON_USE) { for (const input of inputNodes) if (input.baseType === BaseType.ASSIGN_ON_USE) propagateTypeToAssignOnUse(strandsContext.dag, input.id, baseType, dimension); } const nodeData = { nodeType: NodeType.PHI, dimension, baseType, dependsOn: phiInputs.map((input) => input.value.id).filter((id) => id !== null), phiBlocks: phiInputs.map((input) => input.blockId), phiInputs }; const id = getOrCreateNode(strandsContext.dag, nodeData); recordInBasicBlock(strandsContext.cfg, strandsContext.cfg.currentBlock, id); return { id, dimension, baseType }; } //#endregion export { createPhiNode };