コード例 #1
0
        public void Synthesize(ProgramAnalysis sourceProgramAnalysis, TextWriter outputStream)
        {
            LivenessVisitor liveness = new LivenessVisitor(sourceProgramAnalysis);

            liveness.Visit(sourceProgramAnalysis.AST);

            Out = outputStream;
            GenText(".386");
            GenText(".model flat,c");
            GenText("public asm_main");
            GenText("extern put:near,memalloc:near;");
            CodeGeneratorVisitor        CGVisitor  = new CodeGeneratorVisitor(sourceProgramAnalysis, outputStream);
            MethodTableGeneratorVisitor MTGVisitor = new MethodTableGeneratorVisitor(sourceProgramAnalysis, outputStream);
            SymbolPreprocessorVisitor   SPVisitor  = new SymbolPreprocessorVisitor(sourceProgramAnalysis);

            MTGVisitor.Visit(sourceProgramAnalysis.AST);
            SPVisitor.Visit(sourceProgramAnalysis.AST);
            CGVisitor.Visit(sourceProgramAnalysis.AST);
            GenText("end");
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: AsBeeb/P4-FastPrototyping
        private static void Main(string[] args)
        {
            Queue <Token> tokenQueue = new Queue <Token>();

            string filePath = Directory.GetCurrentDirectory();

            // Check for args
            if (args.Length > 0)
            {
                string fileName = args[0];
                filePath += "\\" + fileName;
                if (!File.Exists(filePath))
                {
                    Console.WriteLine("File not found.");
                    return;
                }
            }
            else
            {
                // If no arguments are given (filename, save option) end
                Console.WriteLine("Error: missing arguments(filename)");
                Console.ReadKey();
                return;
            }

            // Scanner
            using (StreamReaderExpanded reader = new StreamReaderExpanded(filePath))
            {
                do
                {
                    Token tempToken = Scanner.Scan(reader);
                    if (tempToken != null)
                    {
                        tokenQueue.Enqueue(tempToken);
                    }
                } while (tokenQueue.Count == 0 || tokenQueue.Last().Type != TokenType.eof_token);
            }

            // Parser
            Parser   parser = new Parser(tokenQueue);
            ProgNode AST    = parser.StartParse();

            // Pretty printer
            //PrettyPrintVisitor vis = new PrettyPrintVisitor();
            //vis.Visit(AST);

            // Semantics
            SymbolTable symbolTable = new SymbolTable();

            SemanticsVisitor typeVisitor = new SemanticsVisitor(symbolTable);

            typeVisitor.Visit(AST);

            // Codegeneration
            CodeGeneratorVisitor codeGeneratorVisitor = new CodeGeneratorVisitor(symbolTable);

            codeGeneratorVisitor.Visit(AST);

            // If -s parameter is set, save the .cs code
            if (args.Length > 1 && args[1] == "-s")
            {
                SaveProgram(codeGeneratorVisitor.CSharpString.ToString(), filePath);
            }

            // After .cs code is generated, run Roslyn compiler
            CSharpCompiler.CompileAndStartConsole(codeGeneratorVisitor.CSharpString);
        }