コード例 #1
0
ファイル: CommandLine.cs プロジェクト: vincentjzimmer/P
        private static int Main(string[] args)
        {
            CommandLineOptions options;

            if (!CommandLineOptions.ParseCompileString(args, out options))
            {
                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();
                }
                result = svc.Compile(options, Console.Out);
            }
            else
            {
                var compiler = new Compiler(options.shortFileNames);
                result = compiler.Compile(new StandardOutput(), options);
            }
            if (!result)
            {
                return(-1);
            }
            return(0);

error:
            {
                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 linker.c and linker.h files");
                Console.WriteLine("/liveness[:mace]        -- 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("/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)");
                return(-1);
            }
        }
コード例 #2
0
        private static void Main(string[] args)
        {
            bool   shortFileNames        = false;
            bool   server                = false;
            string compileErrorMsgString = "USAGE: compile file.p [/shortFileNames] [/printTypeInference] [/dumpFormulaModel] [/outputDir:<dir>] [/generate[:C,:Zing, C#]] [/liveness[:mace]] [/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;
                        var success = CommandLineOptions.ParseCompileString(inputArgs.Skip(1), out compilerOptions);
                        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;
                        if (!CommandLineOptions.ParseLinkString(inputArgs.Skip(1), out options))
                        {
                            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;
            }
        }