Exemplo n.º 1
0
        static int Main(string[] args)
        {
            bool result = false;
            CommandLineOptions options;

            if (CommandLineOptions.ParseLinkString(args, out options))
            {
                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.Link(options, Console.Out);
                }
                else
                {
                    Compiler compiler = new Compiler(true);
                    result = compiler.Link(new StandardOutput(), options);
                }
            }
            else
            {
                Console.WriteLine("USAGE: Plink.exe file.4ml [file2.4ml ...] [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 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");
                result = false;
            }
            return(result ? 0 : -1);
        }
Exemplo n.º 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;
            }
        }