示例#1
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);
            }
        }
示例#2
0
        public bool Compile(ICompilerOutput log, CommandLineOptions options)
        {
            try
            {
                var inputFiles    = options.inputFileNames.Select(name => new FileInfo(name)).ToArray();
                var trees         = new PParser.ProgramContext[inputFiles.Length];
                var originalFiles = new ParseTreeProperty <FileInfo>();
                ITranslationErrorHandler handler = new DefaultTranslationErrorHandler(originalFiles);

                for (var i = 0; i < inputFiles.Length; i++)
                {
                    FileInfo inputFile = inputFiles[i];
                    trees[i] = Parse(handler, inputFile);
                    originalFiles.Put(trees[i], inputFile);
                }

                Analyzer.AnalyzeCompilationUnit(handler, trees);
                log.WriteMessage("Program valid. Code generation not implemented.", SeverityKind.Info);
                return(true);
            }
            catch (TranslationException e)
            {
                log.WriteMessage(e.Message, SeverityKind.Error);
                return(false);
            }
        }
示例#3
0
        public static void PopulateStubs(
            Scope globalScope,
            PParser.ProgramContext context,
            ParseTreeProperty <IPDecl> nodesToDeclarations)
        {
            DeclarationStubVisitor visitor = new DeclarationStubVisitor(globalScope, nodesToDeclarations);

            visitor.Visit(context);
        }
示例#4
0
        public static void PopulateDeclarations(
            ITranslationErrorHandler handler,
            Scope topLevelScope,
            PParser.ProgramContext context,
            ParseTreeProperty <IPDecl> nodesToDeclarations)
        {
            var visitor = new DeclarationVisitor(handler, topLevelScope, nodesToDeclarations);

            visitor.Visit(context);
        }
示例#5
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($"----------------------------------------");
            }
        }