예제 #1
0
        public void Test()
        {
            new TestCase("", Inp, Epc, delegate(TestCase c_)
            {
                PlatformID pfm = (PlatformID)Enum.Parse(typeof(PlatformID), c_.Input);
                Version ver;
                OperatingSystem os;
                try
                {
                    ver = new Version();
                    os = new OperatingSystem(pfm, ver);
                }
                catch (Exception exver)
                {
                    c_.Expected = exver.Message;
                    return exver.Message;
                }

                ILASMRunner r = new ILASMRunner();
                string act = "";
                try
                {
                    r.DetectILASM(os);
                    act = r.ILASMpath;
                }
                catch (Exception ex)
                {
                    c_.Expected = ex.Message;
                    act = ex.Message;
                }
                return act;
            })
            .Run();
        }
예제 #2
0
파일: Ctrl.cs 프로젝트: quwahara/Nana
        public int StartCompile(string[] args)
        {
            UTF8Encoding utf8 = new UTF8Encoding(false /* no byte order mark */);
            Action<string> prt = delegate(string s) { StdOut(s + Environment.NewLine); };
            string nl = Environment.NewLine;
            string ilpath;
            string code;
            Token root = null;
            try
            {
                root = CmdLnArgs.GetCmdLnArgs(args);
                root.Group = "Root";

                if (args.Length == 0 || root.Contains("CompileOptions/help"))
                {
                    foreach (string opt in CmdLnArgs.Options)
                    { StdErr(opt + nl); }
                    return 0;
                }

                if (root.Contains("CompileOptions/verbose"))
                {
                    prt("Specified options:");
                    foreach (Token t in root.Find("CompileOptions").Follows)
                    { prt(t.Group + (string.IsNullOrEmpty(t.Value) ? "" : ":" + t.Value)); }
                }

                Ctrl.Check(root);
                Ctrl c = new Ctrl();

                if (root.Contains("CompileOptions/xxxsyntax"))
                {
                    c.AfterSyntaxAnalyze = delegate(Token root_)
                    {
                        foreach (Token t in root_.Select("Syntax/@0Source"))
                        {
                            StdOut(TokenEx.ToTree(t));
                        }
                    };
                }

                c.Compile(root);

                if (root.Contains("CompileOptions/xxxil"))
                {
                    StdOut(root.Find("Code").Value);
                }

                ilpath = root.Find("CompileOptions/out").Value;
                ilpath = Path.ChangeExtension(ilpath, ".il");
                code = root.Find("Code").Value;
                File.WriteAllText(ilpath, code, utf8);

                ILASMRunner r = new ILASMRunner();
                r.DetectILASM();
                r.Run(ilpath);
                return 0;
            }
            catch (Exception e)
            {
                StdErr("Error:" + nl);
                StringBuilder b = new StringBuilder();
                if (e is SemanticError)
                {
                    SemanticError se = e as SemanticError;
                    b.Append(se.Path)
                        .Append(":").Append(se.Row).Append(",").Append(se.Col)
                        .Append(":");
                }
                b.Append(e.Message);

                if (e is FileNotFoundException)
                {
                    FileNotFoundException ffx = e as FileNotFoundException;
                    b.Append(", Filename: ").Append(ffx.FileName);
                }

                b.AppendLine();
                StdErr(b.ToString());
                if (null != root && root.Contains("CompileOptions/xxxtrace"))
                { StdErr(e.StackTrace); }
                return -1;
            }
        }