コード例 #1
0
ファイル: Program.cs プロジェクト: vrajeshbhavsar/mcjs
 void DoAll(mjr.JSFunctionMetadata func, ProgramConfiguration config)
 {
     if (config.DumpIRGraph)
     {
         func.Analyze();
         IRGraphWriter.Execute(func);
     }
     else
     if (config.OnlyJit)
     {
         func.JitSpeculatively(ref mdr.DFunctionSignature.EmptySignature);
     }
     else if (config.OnlyAnalyze)
     {
         func.Analyze();
     }
     else if (config.OnlyParse)
     {
         // Already parsed everything during load.
     }
     else if (config.OnlyLex)
     {
         // Already lexed everything during load.
     }
     foreach (var f in func.SubFunctions)
     {
         DoAll(f, config);
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: vrajeshbhavsar/mcjs
        public int Run(params string[] args)
        {
            var config = new ProgramConfiguration(args);
            var engine = new mwr.HTMLEngine(config);
            int result;

            if (config.EnableReplay)
            {
                result = mwr.RecordReplayManager.RunReplay(config.ReplayFilename, config.ReplayParams);
            }
            else
            if (config.DumpJSOnly || !string.IsNullOrEmpty(config.InstJSPrefix))
            {
                LoadRuntime(config);

                foreach (var pair in _scripts)
                {
                    var Filename = System.IO.Path.GetFullPath(System.IO.Path.Combine(config.OutputDir, System.IO.Path.GetFileNameWithoutExtension(pair.Key) + "_inst.js"));
                    var output   = new System.IO.StreamWriter(Filename);
                    //mjr.AstWriter writer;
                    //if (config.DumpJSOnly)
                    //    writer = new mjr.AstWriter(output);
                    //else
                    //    writer = new mjr.CodeGen.JSIntrumentor(output);
                    //writer.Execute(_runtime.Scripts.GetOrAdd(pair.Value, pair.Key, _runtime));
                    output.Close();
                }
                result = 0;
            }
            else if (config.OnlyLex || config.OnlyParse || config.OnlyAnalyze || config.OnlyJit || config.DumpIRGraph)
            {
                LoadRuntime(config);
                foreach (var pair in _scripts)
                {
                    DoAll(_runtime.Scripts.GetOrAdd(pair.Value, pair.Key, _runtime), config);
                }
                _runtime.ShutDown();
                result = 0;
            }
            else
            {
                result = Run(null, config);
            }
            engine.ShutDown();
            return(result);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: vrajeshbhavsar/mcjs
        public int Run(Initializer initializer, ProgramConfiguration config)
        {
            var errorCount = 0;
            //var color = ConsoleColor.Blue;
            const int Repeats = 5;

            for (var i = 1; i < Repeats; ++i)
            {
                if (config.MeasureTime)
                {
                    //var t = Util.Timers.Start("Write header");
                    //if (++color == ConsoleColor.White)
                    //    color = ConsoleColor.Blue;
                    //Console.ForegroundColor = color;
                    Debug.WriteLine("------- Running #{0} -------\n", i);
                    //Console.ResetColor();
                    //Timers.Stop(t);
                }
                else
                {
                    i = Repeats; //One iteration is enough!
                }
                LoadRuntime(config);

                if (initializer != null)
                {
                    //This means we are being called from the source code debugger. That will rely on the fact that all scripts are already parsed
                    foreach (var pair in _scripts)
                    {
                        _runtime.Scripts.GetOrAdd(pair.Value, pair.Key, _runtime);
                    }

                    initializer(_runtime);
                }

                foreach (var pair in _scripts)
                {
                    errorCount += _runtime.RunScriptString(pair.Value, pair.Key);
                }

                _runtime.ShutDown();
            }
            return(errorCount);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: vrajeshbhavsar/mcjs
        void LoadRuntime(ProgramConfiguration config)
        {
            _runtime = new mjr.JSRuntime(config);

            var globalContext = new mdr.DObject();

            _runtime.InitGlobalContext(globalContext);
            _runtime.SetGlobalContext(globalContext);

            _scripts = new LinkedList <KeyValuePair <string, string> >();

            foreach (var s in config.ScriptFileNames)
            {
                _scripts.AddLast(new KeyValuePair <string, string>(s, _runtime.ReadAllScript(s)));
            }

            foreach (var s in config.ScriptStrings)
            {
                var MD5 = new MD5CryptoServiceProvider();
                var key = BitConverter.ToString(MD5.ComputeHash(Encoding.UTF8.GetBytes(s)));
                _scripts.AddLast(new KeyValuePair <string, string>(key, s));
            }
        }