public static VariableType GetNodeDestType(CodeGenContext context, IAstNode node) { if (node is AstOperation operation) { // Load attribute basically just returns the attribute value. // Some built-in attributes may have different types, so we need // to return the type based on the attribute that is being read. if (operation.Inst == Instruction.LoadAttribute) { return(GetOperandVarType((AstOperand)operation.GetSource(0))); } else if (operation.Inst == Instruction.Call) { AstOperand funcId = (AstOperand)operation.GetSource(0); Debug.Assert(funcId.Type == OperandType.Constant); return(context.GetFunction(funcId.Value).ReturnType); } else if (operation is AstTextureOperation texOp && (texOp.Inst == Instruction.ImageLoad || texOp.Inst == Instruction.ImageStore)) { return(texOp.Format.GetComponentType()); } return(GetDestVarType(operation.Inst)); } else if (node is AstOperand operand) { if (operand.Type == OperandType.Argument) { int argIndex = operand.Value; return(context.CurrentFunction.GetArgumentType(argIndex)); } return(GetOperandVarType(operand)); } else { throw new ArgumentException($"Invalid node type \"{node?.GetType().Name ?? "null"}\"."); } }