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 MatrixMultiplicationCompiler(NodeCompiler nodeCompiler)
 {
     this.nodeCompiler = nodeCompiler;
 }
Exemple #4
0
 public IList<Instruction> Compile(Workflow workflow)
 {
     NodeCompiler nc = new NodeCompiler();
     nc.Compile(workflow);
     return nc.Instructions;
 }