Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            bool   shortFileNames        = false;
            bool   server                = false;
            string compileErrorMsgString = "USAGE: compile file.p [/shortFileNames] [/dumpFormulaModel] [/outputDir:<dir>] [/generate[:C,:Zing, C#]] [/liveness[:sampling]] [/profile]";
            string linkErrorMsgString    = "USAGE: link file_1.4ml ... file_n.4ml [file.p]";

            for (int i = 0; i < args.Length; i++)
            {
                var arg = args[i];
                if (arg[0] == '-' || arg[0] == '/')
                {
                    switch (arg.Substring(1).ToLowerInvariant())
                    {
                    case "shortfilenames":
                        shortFileNames = true;
                        break;

                    case "server":
                        server = true;
                        break;

                    default:
                        Console.WriteLine("Pci: unexpected command line argument: {0}", arg);
                        goto error;
                    }
                }
                else
                {
                    Console.WriteLine("Pci: unexpected command line argument: {0}", arg);
                    goto error;
                }
            }
            DateTime currTime = DateTime.UtcNow;
            Compiler compiler;

            if (shortFileNames)
            {
                compiler = new Compiler(true);
            }
            else
            {
                compiler = new Compiler(false);
            }
            if (server)
            {
                Console.WriteLine("Pci: initialization succeeded");
            }
            while (true)
            {
                if (!server)
                {
                    Console.WriteLine("{0}s", DateTime.UtcNow.Subtract(currTime).TotalSeconds);
                    Console.Write(">> ");
                }
                var input = Console.ReadLine();
                currTime = DateTime.UtcNow;
                var inputArgs = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (inputArgs.Length == 0)
                {
                    continue;
                }
                if (inputArgs[0] == "exit")
                {
                    Console.WriteLine("Pci: exiting");
                    return;
                }
                else if (inputArgs[0] == "compile")
                {
                    try
                    {
                        CommandLineOptions compilerOptions = new CommandLineOptions();
                        var success = compilerOptions.ParseArguments(inputArgs.Skip(1));
                        if (!success || compilerOptions.compilerService)
                        {
                            Console.WriteLine(compileErrorMsgString);
                            continue;
                        }
                        compilerOptions.shortFileNames = shortFileNames;
                        var result = compiler.Compile(new StandardOutput(), compilerOptions);
                        if (server)
                        {
                            if (!result)
                            {
                                Console.WriteLine("Pci: command failed");
                            }
                            else
                            {
                                Console.WriteLine("Pci: command done");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Console.WriteLine("Pci: command failed");
                    }
                }
                else if (inputArgs[0] == "link")
                {
                    try
                    {
                        CommandLineOptions options = new CommandLineOptions();
                        if (!options.ParseArguments(inputArgs.Skip(1)))
                        {
                            Console.WriteLine(linkErrorMsgString);
                            continue;
                        }
                        var b = compiler.Link(new StandardOutput(), options);
                        if (server)
                        {
                            if (b)
                            {
                                Console.WriteLine("Pci: command done");
                            }
                            else
                            {
                                Console.WriteLine("Pci: command failed");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        Console.WriteLine("Pci: command failed");
                    }
                }
                else
                {
                    Console.WriteLine("Unexpected input");
                }
            }

error:
            {
                Console.WriteLine("USAGE: Pci.exe [/shortFileNames] [/server]");
                return;
            }
        }
Ejemplo n.º 2
0
        private static int Main(string[] args)
        {
            CommandLineOptions options = new CommandLineOptions();

            if (!options.ParseArguments(args))
            {
                goto error;
            }
            bool result;

            if (options.compilerService)
            {
                // use separate process that contains pre-compiled P compiler.
                CompilerServiceClient svc = new CompilerServiceClient();
                if (options.compilerOutput != CompilerOutput.Link)
                {
                    result = svc.Compile(options, Console.Out);
                }
                else
                {
                    result = svc.Link(options, Console.Out);
                }
            }
            else
            {
                var compiler = new Compiler(options.shortFileNames);
                if (options.compilerOutput != CompilerOutput.Link)
                {
                    result = compiler.Compile(new StandardOutput(), options);
                }
                else
                {
                    result = compiler.Link(new StandardOutput(), options);
                }
            }
            if (!result)
            {
                return(-1);
            }
            return(0);

error:
            {
                Console.WriteLine(" ------------ Compiler Phase ------------");
                Console.WriteLine("USAGE: Pc.exe file1.p [file2.p ...] [/t:tfile.4ml] [/r:rfile.4ml ...] [options]");
                Console.WriteLine("Compiles *.p programs and produces .4ml summary file which can then be passed to PLink.exe");
                Console.WriteLine("/t:file.4ml             -- name of summary file produced for this compilation unit; if not supplied then file1.4ml");
                Console.WriteLine("/r:file.4ml             -- refer to another summary file");
                Console.WriteLine("/outputDir:path         -- where to write the generated files");
                Console.WriteLine("/shared                 -- use the compiler service)");
                Console.WriteLine("/profile                -- print detailed timing information");
                Console.WriteLine("/generate:[C0,C#,Zing]");
                Console.WriteLine("    C0  : generate C without model functions");
                Console.WriteLine("    C#  : generate C# (and C) with model functions");
                Console.WriteLine("    Zing: generate Zing");
                Console.WriteLine("/liveness[:sampling]    -- controls compilation for Zinger");
                Console.WriteLine("/shortFileNames         -- print only file names in error messages");
                Console.WriteLine("/dumpFormulaModel       -- write the entire formula model to a file named 'output.4ml'");
                Console.WriteLine(" ------------ Linker Phase ------------");
                Console.WriteLine("USAGE: Pc.exe [linkfile.p] /link /r:file1.4ml [/r:file2.4ml ...] [options]");
                Console.WriteLine("Links *.4ml summary files against an optional linkfile.p and generates linker.{h,c,dll}");
                Console.WriteLine("/outputDir:path  -- where to write the generated files");
                Console.WriteLine("/shared          -- use the compiler service");
                Console.WriteLine("/profile         -- print detailed timing information");
                Console.WriteLine("Profiling can also be enabled by setting the environment variable PCOMPILE_PROFILE=1");
                return(-1);
            }
        }
Ejemplo n.º 3
0
Archivo: CommandLine.cs Proyecto: up1/P
        private static int Main(string[] args)
        {
            CommandLineOptions options = new CommandLineOptions();

            if (!options.ParseArguments(args))
            {
                goto error;
            }
            bool result;

            if (options.compilerService)
            {
                // use separate process that contains pre-compiled P compiler.
                CompilerServiceClient svc = new CompilerServiceClient();
                if (string.IsNullOrEmpty(options.outputDir))
                {
                    options.outputDir = Directory.GetCurrentDirectory();
                }
                if (!options.isLinkerPhase)
                {
                    result = svc.Compile(options, Console.Out);
                }
                else
                {
                    result = svc.Link(options, Console.Out);
                }
            }
            else
            {
                var compiler = new Compiler(options.shortFileNames);
                if (!options.isLinkerPhase)
                {
                    result = compiler.Compile(new StandardOutput(), options);
                }
                else
                {
                    result = compiler.Link(new StandardOutput(), options);
                }
            }
            if (!result)
            {
                return(-1);
            }
            return(0);

error:
            {
                Console.WriteLine(" ------------ Compiler Phase ------------");
                Console.WriteLine("USAGE: Pc.exe file.p [options]");
                Console.WriteLine("Compiles *.p programs and produces *.4ml intermediate output which can then be passed to PLink.exe");
                Console.WriteLine("/outputDir:path         -- where to write the generated *.c, *.h and *.4ml files");
                Console.WriteLine("/liveness[:sampling]    -- these control what the Zing program is looking for");
                Console.WriteLine("/shortFileNames         -- print only file names in error messages");
                Console.WriteLine("/printTypeInference     -- dumps compiler type inference information (in formula)");
                Console.WriteLine("/dumpFormulaModel       -- write the entire formula model to a file named 'output.4ml'");
                Console.WriteLine("/profile                -- print detailed timing information");
                Console.WriteLine("/rebuild                -- rebuild all the P files");
                Console.WriteLine("/generate:[C0,C,Zing,C#]");
                Console.WriteLine("    C0  : generate C without model functions");
                Console.WriteLine("    C   : generate C with model functions");
                Console.WriteLine("    Zing: generate Zing");
                Console.WriteLine("    C#  : generate C# code");
                Console.WriteLine("/shared                 -- use the compiler service)");
                Console.WriteLine(" ------------ Linker Phase ------------");
                Console.WriteLine("USAGE: Pc.exe /link file1.4ml [file2.4ml ...] linkfile.p [options]");
                Console.WriteLine("Takes the *.4ml output from pc.exe and generates the combined linker.c linker.h output from them");
                Console.WriteLine("/outputDir:path  -- where to write the generated linker.c and linker.h files");
                Console.WriteLine("/shared          -- use the compiler service");
                Console.WriteLine("/parallel        -- run multiple tests in parallel for quicker overall test run times");
                Console.WriteLine("/profile         -- print detailed timing information");
                Console.WriteLine("Profiling can also be enabled by setting the environment variable PCOMPILE_PROFILE=1");
                return(-1);
            }
        }