예제 #1
0
 public ConsoleProfileWatcher(ICompilerOutput log, string operation, string message)
 {
     this.Log       = log;
     this.operation = operation;
     this.message   = message;
     watch.Start();
 }
예제 #2
0
 public void PrintErrors(ICompilerOutput Log, CommandLineOptions Options)
 {
     foreach (var f in errors)
     {
         PrintFlag(f, Log, Options);
     }
 }
예제 #3
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);
            }
        }
예제 #4
0
 public PToCSharpLinker(ICompilerOutput log, AST <Program> linkerModel, List <string> inputFilesNames)
 {
     this.inputFiles = inputFilesNames.ToList();
     Log             = log;
     allTests        = new Dictionary <string, TestCaseInfo>();
     dependsOn       = new Dictionary <string, List <string> >();
     GenerateLinkerInfo(linkerModel);
 }
예제 #5
0
        public bool Compile(ICompilerOutput log, CommandLineOptions options)
        {
            var finished = false;
            var result   = false;

            NamedPipe service = Connect(log);

            options.compilerId = id;
            var writer     = new StringWriter();
            var serializer = new XmlSerializer(typeof(CommandLineOptions));

            serializer.Serialize(writer, options);
            service.WriteMessage(writer.ToString());

            try
            {
                while (!finished && !service.IsClosed)
                {
                    string msg = service.ReadMessage();
                    DebugWriteLine(msg);
                    int i = msg.IndexOf(':');
                    if (i > 0)
                    {
                        string       sev = msg.Substring(0, i);
                        SeverityKind severity;
                        Enum.TryParse(sev, out severity);
                        msg = msg.Substring(i + 2);

                        if (msg.StartsWith(JobFinishedMessage))
                        {
                            string tail = msg.Substring(JobFinishedMessage.Length);
                            finished = true;
                            bool.TryParse(tail, out result);
                        }
                        else
                        {
                            log.WriteMessage(msg, severity);
                        }
                    }
                    else
                    {
                        log.WriteMessage(msg, SeverityKind.Info);
                    }
                }
            }
            catch (Exception)
            {
                result = false;
                log.WriteMessage(
                    "PCompilerService is gone, did someone kill it?  Perhaps the P build is happening in parallel?",
                    SeverityKind.Error);
            }

            return(result);
        }
예제 #6
0
    public ICompilerOutput <Solution> Compile(Solution solution, StandardOutputCallback standardOutput)
    {
        /*This is only temporary code until we have an actual build config system*/
        string finalOutput = solution.BuildDirectory + "\\disk.iso";

        if (File.Exists(finalOutput))
        {
            File.Delete(finalOutput);
        }
        string bootsect = "";
        StandardCompileOutput <Solution> output = new StandardCompileOutput <Solution>(finalOutput, solution);

        foreach (Project p in solution.Projects)
        {
            ICompilerOutput <Project> projOut = CompileProject(p, standardOutput);
            foreach (ICompileOutputEntry e in projOut.Errors)
            {
                output.addError(
                    e.File,
                    e.Line,
                    e.Column,
                    e.Message);
            }
            foreach (ICompileOutputEntry w in projOut.Warnings)
            {
                output.addWarning(
                    w.File,
                    w.Line,
                    w.Column,
                    w.Message);
            }

            if (projOut.Errors.Length != 0)
            {
                continue;
            }
            bootsect = projOut.OutputFile;
        }

        if (File.Exists(bootsect))
        {
            generateISO(
                "OS Test",
                bootsect,
                solution.BuildDirectory + "\\disk",
                finalOutput,
                standardOutput,
                new string[0]);
        }

        return(output);
    }
        public int Compile(
            ICompilerOutput output,
            string[] sourceFiles,
            string[] headerSearchPaths,
            string outputPath)
        {
            // used to have: -Wno-incompatible-pointer-types
            var options = "-std=c11 -fsanitize=undefined -fsanitize=integer -fsanitize=nullability -Wall -Wno-unused-label";

            // Next thing is needed for windows
            options += " -Xclang -flto-visibility-public-std";
            if (Path.GetExtension(outputPath) == ".dll") // TODO take this as an argument or something
            {
                options += " --shared";
            }
            var sources   = string.Join(' ', sourceFiles);
            var headers   = string.Join(' ', headerSearchPaths.Select(h => "--include-directory " + h));
            var arguments = $"{sources} -o {outputPath} {headers} {options}";

            output.WriteLine("clang arguments:");
            output.WriteLine(arguments);
            var startInfo = new ProcessStartInfo("clang", arguments)
            {
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                CreateNoWindow         = true,
                UseShellExecute        = false,
            };
            var process = new Process()
            {
                StartInfo = startInfo
            };

            // To prevent blocking on a full buffer, we have to process output as it happens
            process.OutputDataReceived += ProcessOutput;
            process.ErrorDataReceived  += ProcessOutput;
            output.WriteLine("clang output:");
            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            process.WaitForExit();
            return(process.ExitCode);

            void ProcessOutput(object s, DataReceivedEventArgs e)
            {
                output.WriteLine(e.Data);
            }
        }
예제 #8
0
        public CompilationJob(ICompilerOutput output, CompilerOutput outputLanguage, IReadOnlyList <FileInfo> inputFiles,
                              string projectName = null, bool generateSourceMaps = false)
        {
            if (!inputFiles.Any())
            {
                throw new ArgumentException("Must supply at least one input file", nameof(inputFiles));
            }

            Output             = output;
            InputFiles         = inputFiles;
            ProjectName        = projectName ?? Path.GetFileNameWithoutExtension(inputFiles[0].FullName);
            LocationResolver   = new DefaultLocationResolver();
            Handler            = new DefaultTranslationErrorHandler(LocationResolver);
            Backend            = TargetLanguage.GetCodeGenerator(outputLanguage);
            GenerateSourceMaps = generateSourceMaps;
        }
예제 #9
0
        private NamedPipe Connect(ICompilerOutput log)
        {
            var processLock = new Mutex(false, "PCompilerService");

            processLock.WaitOne();
            try
            {
                if (service == null)
                {
                    service = new NamedPipe(ServerPipeName);

                    if (!service.Connect())
                    {
                        Process.Start(new ProcessStartInfo
                        {
                            FileName    = typeof(CompilerServiceClient).Assembly.Location,
                            WindowStyle = ProcessWindowStyle.Hidden
                        });
                        if (!service.Connect())
                        {
                            log.WriteMessage("Cannot start the CompilerService?", SeverityKind.Error);
                            service = null;
                            return(null);
                        }
                        else
                        {
                            // now lock a Compiler object until we re disposed so we can get better
                            // performance by sharing the same Compiler across compile, link and test.
                            service.WriteMessage(CompilerLockMessage);
                            id = service.ReadMessage();
                        }
                    }
                }
            }
            finally
            {
                processLock.ReleaseMutex();
            }

            return(service);
        }
예제 #10
0
        public CompilationJob(ICompilerOutput output, DirectoryInfo outputDir, CompilerOutput outputLanguage, IReadOnlyList <FileInfo> inputFiles,
                              string projectName, DirectoryInfo projectRoot = null, bool generateSourceMaps = false, IReadOnlyList <string> projectDependencies = null,
                              DirectoryInfo aspectjOutputDir = null)
        {
            if (!inputFiles.Any())
            {
                throw new ArgumentException("Must supply at least one input file", nameof(inputFiles));
            }

            Output                 = output;
            OutputDirectory        = outputDir;
            AspectjOutputDirectory = aspectjOutputDir;
            InputFiles             = inputFiles;
            ProjectName            = projectName ?? Path.GetFileNameWithoutExtension(inputFiles[0].FullName);
            ProjectRootPath        = projectRoot;
            LocationResolver       = new DefaultLocationResolver();
            Handler                = new DefaultTranslationErrorHandler(LocationResolver);
            OutputLanguage         = outputLanguage;
            Backend                = TargetLanguage.GetCodeGenerator(outputLanguage);
            GenerateSourceMaps     = generateSourceMaps;
            ProjectDependencies    = projectDependencies ?? new List <string>();
        }
예제 #11
0
 public ConsoleProfiler(ICompilerOutput log)
 {
     this.Log = log;
 }
예제 #12
0
 public bool Link(ICompilerOutput log, CommandLineOptions options)
 {
     log.WriteMessage("Linking not yet implemented in Antlr toolchain.", SeverityKind.Info);
     return(true);
 }
예제 #13
0
        private bool ProcessJob(string msg, ICompilerOutput output)
        {
            var                result       = false;
            Compiler           compiler     = null;
            CommandLineOptions options      = null;
            var                freeCompiler = false;
            string             compilerId   = null;

            try
            {
                var s = new XmlSerializer(typeof(CommandLineOptions));
                options = (CommandLineOptions)s.Deserialize(new StringReader(msg));

                var retry         = true;
                var masterCreated = false;

                if (options.compilerId == null)
                {
                    Tuple <string, Compiler> pair = GetFreeCompiler();
                    compiler     = pair.Item2;
                    compilerId   = pair.Item1;
                    freeCompiler = true;
                }
                else
                {
                    // the givein compilerId belongs to our client, so we can safely use it.
                    lock (compilerlock)
                    {
                        compilerId = options.compilerId;
                        compiler   = compilerBusy[options.compilerId];
                    }
                }

                while (retry)
                {
                    retry = false;
                    try
                    {
                        if (options.inputFileNames == null)
                        {
                            // this is odd, compile will fail, but this stops the Debug output from crashing.
                            options.inputFileNames = new List <string>();
                        }

                        if (options.isLinkerPhase)
                        {
                            DebugWriteLine("Linking: " + string.Join(", ", options.inputFileNames));
                            result = compiler.Link(output, options);
                        }
                        else
                        {
                            DebugWriteLine("Compiling: " + options.compilerOutput + ", " + string.Join(", ", options.inputFileNames));
                            result = compiler.Compile(output, options);
                        }
                    }
                    catch (Exception ex)
                    {
                        result = false;
                        if (!masterCreated)
                        {
                            // sometimes the compiler gets out of whack, and rebuilding it solves the problem.
                            masterCreated = true;
                            compiler      = RebuildCompiler(compiler, compilerId);
                            retry         = true;
                        }
                        else
                        {
                            output.WriteMessage("Compile failed: " + ex, SeverityKind.Error);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
                if (output != null)
                {
                    output.WriteMessage("internal error: " + ex, SeverityKind.Error);
                }
            }
            finally
            {
                if (freeCompiler)
                {
                    if (compiler != null)
                    {
                        FreeCompiler(compiler, compilerId);
                    }
                }
            }

            try
            {
                if (options != null)
                {
                    DebugWriteLine(
                        "Finished: " + options.compilerOutput + ", " + string.Join(", ", options.inputFileNames) + ", result=" + result);
                }
            }
            catch (Exception ex)
            {
                DebugWriteLine("Internal Error: " + ex);
            }
            return(result);
        }
예제 #14
0
 public void PrintFlag(Flag f, ICompilerOutput Log, CommandLineOptions Options)
 {
     Log.WriteMessage(FormatError(f, Options), f.Severity);
 }
 public DefaultTranslationErrorHandler(ParseTreeProperty <FileInfo> originalFiles, ICompilerOutput compilerOutput)
 {
     this.originalFiles  = originalFiles;
     this.compilerOutput = compilerOutput;
 }
예제 #16
0
 public bool Link(ICompilerOutput log, CommandLineOptions options)
 {
     options.isLinkerPhase = true;
     return(Compile(log, options));
 }