Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
            public void Dispose()
            {
                watch.Stop();
                string msg = string.Format("{0}: {1} {2} {3}", DateTime.Now.ToShortTimeString(), watch.Elapsed.ToString(), operation, message);

                Log.WriteMessage(msg, SeverityKind.Info);
            }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
 public bool Link(ICompilerOutput log, CommandLineOptions options)
 {
     log.WriteMessage("Linking not yet implemented in Antlr toolchain.", SeverityKind.Info);
     return(true);
 }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
 public void PrintFlag(Flag f, ICompilerOutput Log, CommandLineOptions Options)
 {
     Log.WriteMessage(FormatError(f, Options), f.Severity);
 }