private void WriteAst(HlslAst ast) { var compiler = new NodeCompiler(_registers); var rootGroups = ast.Roots.GroupBy(r => r.Key.RegisterKey); if (_registers.MethodOutputRegisters.Count == 1) { var rootGroup = rootGroups.Single(); var registerKey = rootGroup.Key; var roots = rootGroup.OrderBy(r => r.Key.ComponentIndex).Select(r => r.Value).ToList(); string statement = compiler.Compile(roots, 4); WriteLine($"return {statement};"); } else { foreach (var rootGroup in rootGroups) { var registerKey = rootGroup.Key; var roots = rootGroup.OrderBy(r => r.Key.ComponentIndex).Select(r => r.Value).ToList(); RegisterDeclaration outputRegister = _registers.MethodOutputRegisters[registerKey]; string statement = compiler.Compile(roots, roots.Count); WriteLine($"o.{outputRegister.Name} = {statement};"); } WriteLine(); WriteLine($"return o;"); } }
private void WriteAst(HlslAst ast) { var compiler = new NodeCompiler(_registers); foreach (var rootGroup in ast.NoOutputInstructions) { string statement = compiler.Compile(rootGroup.Value); WriteLine($"{statement};"); } if (ast.Roots.Count == 1) { string statement = compiler.Compile(ast.Roots.Single().Value); WriteLine($"return {statement};"); } else { foreach (var rootGroup in ast.Roots) { RegisterDeclaration outputRegister = _registers.MethodOutputRegisters[rootGroup.Key]; string statement = compiler.Compile(rootGroup.Value); WriteLine($"o.{outputRegister.Name} = {statement};"); } WriteLine(); WriteLine($"return o;"); } }
public string Compile(MatrixMultiplicationContext context) { string matrixName = context.MatrixDeclaration.Name; string vector = nodeCompiler.Compile(context.Vector); return(context.IsMatrixByVector ? $"mul({matrixName}, {vector})" : $"mul({vector}, {matrixName})"); }
public string Compile(MatrixMultiplicationContext context) { string matrixName = context.MatrixDeclaration.Name; if (context.Vector.Length != context.MatrixRowCount) { matrixName = $"(float{context.MatrixDeclaration.Columns}x{context.Vector.Length}){matrixName}"; } string vector = nodeCompiler.Compile(context.Vector.Inputs); return(context.IsMatrixByVector ? $"mul({matrixName}, {vector})" : $"mul({vector}, {matrixName})"); }
public IList<Instruction> Compile(Workflow workflow) { NodeCompiler nc = new NodeCompiler(); nc.Compile(workflow); return nc.Instructions; }