예제 #1
0
파일: Compiler.cs 프로젝트: tushetodorov/P
        public void Compile(ICompilationJob job)
        {
            // Run parser on every input file
            var trees = job.InputFiles.Select(file =>
            {
                var tree = Parse(job, file);
                job.LocationResolver.RegisterRoot(tree, file);
                return(tree);
            }).ToArray();

            // Run typechecker and produce AST
            var scope = Analyzer.AnalyzeCompilationUnit(job.Handler, trees);

            // Convert functions to lowered SSA form with explicit cloning
            foreach (var fun in scope.GetAllMethods())
            {
                IRTransformer.SimplifyMethod(fun);
            }

            // Run the selected backend on the project and write the files.
            var compiledFiles = job.Backend.GenerateCode(job, scope);

            foreach (var file in compiledFiles)
            {
                job.Output.WriteMessage($"Writing {file.FileName}...", SeverityKind.Info);
                job.Output.WriteFile(file);
            }
        }
예제 #2
0
        public void Compile(ICompilationJob job)
        {
            // Run parser on every input file
            PParser.ProgramContext[] trees = job.InputFiles.Select(file =>
            {
                PParser.ProgramContext tree = Parse(job, file);
                job.LocationResolver.RegisterRoot(tree, file);
                return(tree);
            }).ToArray();

            // Run typechecker and produce AST
            Scope scope = Analyzer.AnalyzeCompilationUnit(job.Handler, trees);

            // Convert functions to lowered SSA form with explicit cloning
            foreach (TypeChecker.AST.Declarations.Function fun in scope.GetAllMethods())
            {
                IRTransformer.SimplifyMethod(fun);
            }

            // Run the selected backend on the project and write the files.
            System.Collections.Generic.IEnumerable <CompiledFile> compiledFiles = job.Backend.GenerateCode(job, scope);
            foreach (CompiledFile file in compiledFiles)
            {
                job.Output.WriteMessage($"Generated {file.FileName}...", SeverityKind.Info);
                job.Output.WriteFile(file);
            }
        }
예제 #3
0
        public void Compile(ICompilationJob job)
        {
            job.Output.WriteInfo($"----------------------------------------");
            job.Output.WriteInfo($"Parsing ..");
            // Run parser on every input file
            PParser.ProgramContext[] trees = job.InputFiles.Select(file =>
            {
                PParser.ProgramContext tree = Parse(job, file);
                job.LocationResolver.RegisterRoot(tree, file);
                return(tree);
            }).ToArray();

            job.Output.WriteInfo($"Type checking ...");
            // Run typechecker and produce AST
            Scope scope = Analyzer.AnalyzeCompilationUnit(job.Handler, trees);

            // Convert functions to lowered SSA form with explicit cloning
            foreach (TypeChecker.AST.Declarations.Function fun in scope.GetAllMethods())
            {
                IRTransformer.SimplifyMethod(fun);
            }
            job.Output.WriteInfo($"Code generation ....");
            // Run the selected backend on the project and write the files.
            System.Collections.Generic.IEnumerable <CompiledFile> compiledFiles = job.Backend.GenerateCode(job, scope);
            foreach (CompiledFile file in compiledFiles)
            {
                job.Output.WriteInfo($"Generated {file.FileName}");
                job.Output.WriteFile(file);
            }
            job.Output.WriteInfo($"----------------------------------------");

            // Compiling the generated C# code
            // TODO: This is a special case right now but needs to be factored in after the Java code path is available
            if (job.OutputLanguage == CompilerOutput.CSharp)
            {
                job.Output.WriteInfo($"Compiling {job.ProjectName}.csproj ..\n");
                CSharpCodeCompiler.Compile(job);
                job.Output.WriteInfo($"----------------------------------------");
            }
        }