public ShaderOp GenerateFunctionCall(ShaderFunction shaderFunction, IShaderIR selfOp, List <IShaderIR> arguments, FrontEndContext context) { var argumentOps = new List <IShaderIR>(); argumentOps.Add(shaderFunction); if (!shaderFunction.IsStatic || selfOp != null) { argumentOps.Add(selfOp); } if (arguments != null) { for (var i = 0; i < arguments.Count; ++i) { var argument = arguments[i]; var paramIR = GetFunctionParameter(shaderFunction, i, argument, context); argumentOps.Add(paramIR); } } var fnShaderReturnType = shaderFunction.GetReturnType(); var functionCallOp = CreateOp(context.mCurrentBlock, OpInstructionType.OpFunctionCall, fnShaderReturnType, argumentOps); return(functionCallOp); }
public void FixupBlockTerminators(ShaderFunction shaderFunction) { if (shaderFunction.mBlocks.Count == 0) { shaderFunction.mBlocks.Add(new ShaderBlock()); } var lastBlock = shaderFunction.mBlocks[shaderFunction.mBlocks.Count - 1]; if (lastBlock.mTerminatorOp == null) { if (shaderFunction.GetReturnType() != FindType(typeof(void))) { lastBlock.mTerminatorOp = CreateOp(lastBlock, OpInstructionType.OpUnreachable, null, null); } else { lastBlock.mTerminatorOp = CreateOp(lastBlock, OpInstructionType.OpReturn, null, null); } } foreach (var block in shaderFunction.mBlocks) { if (block.mTerminatorOp == null) { continue; } for (var i = 0; i < block.mOps.Count; ++i) { var op = block.mOps[i] as ShaderOp; if (op != null && (op.mOpType == OpInstructionType.OpReturn || op.mOpType == OpInstructionType.OpReturnValue || op.mOpType == OpInstructionType.OpBranch || op.mOpType == OpInstructionType.OpBranchConditional || op.mOpType == OpInstructionType.OpKill || op.mOpType == OpInstructionType.OpSwitch)) { var nextOpIndex = i + 1; block.mOps.RemoveRange(nextOpIndex, block.mOps.Count - nextOpIndex); break; } } } }
public void GenerateFunctionCall(ShaderFunction shaderFunction, IShaderIR selfOp, List <CSharpSyntaxNode> arguments) { var argumentOps = new List <IShaderIR>(); argumentOps.Add(shaderFunction); if (!shaderFunction.IsStatic) { argumentOps.Add(selfOp); } for (var i = 0; i < arguments.Count; ++i) { var argument = arguments[i]; var paramIR = GetFunctionParameter(shaderFunction, i, argument); argumentOps.Add(paramIR); } var fnShaderReturnType = shaderFunction.GetReturnType(); var functionCallOp = mFrontEnd.CreateOp(mContext.mCurrentBlock, OpInstructionType.OpFunctionCall, fnShaderReturnType, argumentOps); mContext.Push(functionCallOp); }