Exemple #1
0
        private void Visit(JSFunctionMetadata node)
        {
            OpenOutput(node.FullName);
            _writingTopStatements = true;
            _currFuncMetadata     = node;
            _output.WriteLine("  label = \"GRAPH FOR FUNCTION: {0}\"", node.Declaration);

            StartSubgraph("Symbols");
            foreach (var symbol in node.Scope.Symbols)
            {
                WriteNode(symbol, symbol.Name);
            }
            EndSubgraph();
            foreach (var symbol in node.Scope.Symbols)
            {
                VisitNodes(symbol.Readers);
                WriteNodes(symbol.Readers);
                WriteEdges(symbol, symbol.Readers, "Reader");
            }

            VisitNode(node.FunctionIR);


            CloseOutput();
        }
Exemple #2
0
 public static void Execute(JSFunctionMetadata funcMetadata)
 {
   var validator = new IRValidator();
   validator.Visit(funcMetadata.FunctionIR.Statement);
   foreach (var f in funcMetadata.SubFunctions)
     Execute(f);
 }
Exemple #3
0
        public int RunScriptProgram(JSFunctionMetadata prgMetadata)
        {
            try
            {
                //TODO: It should be checked later. This situation should not happen

                if (prgMetadata == null)
                {
                    return(0);
                }
                var prgFunc = new mdr.DFunction(prgMetadata, null);

                mdr.CallFrame callFrame = new mdr.CallFrame();
                callFrame.Function  = prgFunc;
                callFrame.Signature = mdr.DFunctionSignature.EmptySignature;
                callFrame.This      = (GlobalContext);
                prgFunc.Call(ref callFrame);
                return(0);
            }
            catch (mjr.JSException e)
            {
                WriteJSException(e);
            }
            catch (Exception e)
            {
                Diagnostics.WriteException(e);
            }
            return(1);
        }
Exemple #4
0
 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);
     }
 }
Exemple #5
0
 public void Execute(JSFunctionMetadata funcImp)
 {
     Reset();
     // Process AST
     Visit(funcImp);
     // Emit epilogue
     //outStream.WriteLine();
 }
Exemple #6
0
 public void Execute(JSFunctionMetadata funcImp)
 {
     Reset();
     // Process AST
     Visit(funcImp);
     // Emit epilogue
     //outStream.WriteLine();
 }
Exemple #7
0
        public virtual void Visit(JSFunctionMetadata funcImp)
        {
            // Ensure AST is available
            funcImp.Parse();

            // Process AST
            enteringMethodDefinition = false;
            funcImp.AST.Accept(this);
        }
Exemple #8
0
        public virtual void Visit(JSFunctionMetadata funcImp)
        {
            // Ensure AST is available
            funcImp.Parse();

            // Process AST
            enteringMethodDefinition = false;
            funcImp.AST.Accept(this);
        }
Exemple #9
0
        public static void Execute(JSFunctionMetadata funcMetadata)
        {
            var validator = new IRValidator();

            validator.Visit(funcMetadata.FunctionIR.Statement);
            foreach (var f in funcMetadata.SubFunctions)
            {
                Execute(f);
            }
        }
 public JSFunctionMetadata(FunctionExpression functionIR, JSFunctionMetadata parent = null)
     : base()
 {
     Execute      = FirstExecute;
     SubFunctions = new List <JSFunctionMetadata>();
     FunctionIR   = functionIR;
     FunctionIR.Scope.SetContainer(this);
     ParentFunction   = parent;
     GuardProfileSize = 0;
     MapProfileSize   = 0;
     CallProfileSize  = 0;
 }
Exemple #11
0
            public void Add(string key, JSFunctionMetadata func)
            {
                //TODO: can we make this call async?
                Debug.Assert(func != null, "Cannot add null function for {0}", key);
                LinkedList <JSFunctionMetadata> funcs = null;

                if (!_map.TryGetValue(key, out funcs))
                {
                    funcs = _map.GetOrAdd(key, k => new LinkedList <JSFunctionMetadata>());
                }
                funcs.AddLast(func);
            }
Exemple #12
0
 public void AddSubFunction(JSFunctionMetadata subFunc)
 {
     if (ContainerFunction != null)
     {
         Debug.Assert(_subFunctions == null, "Invalid situation!");
         subFunc.ParentFunction = ContainerFunction;
     }
     else
     {
         Debug.Assert(_subFunctions != null, "Invalid situation!");
         _subFunctions.Add(subFunc);
     }
 }
Exemple #13
0
            private ScriptInfo GetScriptInfo(JSFunctionMetadata funcMetadata)
            {
                var f = funcMetadata;

                while (f.ParentFunction != null)
                {
                    f = f.ParentFunction;
                }
                foreach (var v in Scripts.Values)
                {
                    if (v.Metadata == f)
                    {
                        return(v);
                    }
                }

                return(null);
            }
Exemple #14
0
        private JSFunctionMetadata LoadScriptStringMetadata(string scriptString)
        {
            JSFunctionMetadata program = null;
            var timer = StartTimer(Configuration.ProfileLexTime, "JS/Parse");

            try
            {
                program = JSParser.ParseScript(scriptString).Expression.Metadata;
            }
            catch (Exception e)
            {
                Diagnostics.WriteException(e);
            }
            finally
            {
                StopTimer(timer);
            }
            return(program);
        }
Exemple #15
0
        public void SetContainer(JSFunctionMetadata container)
        {
            Debug.Assert(ContainerFunction == null, "Scope already has a container function");
            ContainerFunction = container;
            Debug.Assert(_subFunctions != null, "Invalid situation!");
            foreach (var f in _subFunctions)
            {
                f.ParentFunction = ContainerFunction; //This will set everything up!
            }
            _subFunctions = null;                     //From now on, we don't need to keep the list in this object!

            foreach (var s in InnerScopes)
            {
                if (!s.IsFunction)
                {
                    s.SetContainer(container);
                }
            }
        }
Exemple #16
0
        private void PrintProfileInfo(JSFunctionMetadata metaData)
        {
            Console.WriteLine("###########################################");
            Console.WriteLine("Profile Info of function: {0}", metaData.Declaration);
            var cachedCodes = metaData.Cache.Items;

            foreach (var code in cachedCodes)
            {
                Console.WriteLine("Signature {0}", code.Signature);
                Console.Write("{0}", code.Profiler);
            }
            Console.WriteLine("###########################################\n");
            foreach (var subFunc in metaData.SubFunctions)
            {
                if (subFunc != null)
                {
                    PrintProfileInfo(subFunc);
                }
            }
        }
Exemple #17
0
 public JSFunctionMetadata GetSubFunction(int index) { return SubFunctions[index]; } //This is to simplify code generation
 void AddSubFunction(JSFunctionMetadata subFunc)
 {
   Debug.Assert(subFunc.FuncDefinitionIndex == mdr.Runtime.InvalidIndex || SubFunctions[subFunc.FuncDefinitionIndex] == subFunc, "Opps! Invalid situation in function tree!");
   subFunc.FuncDefinitionIndex = this.SubFunctions.Count;
   this.SubFunctions.Add(subFunc);
 }
Exemple #18
0
 public FunctionInfo(JSFunctionMetadata func_, bool isMethod_)
 {
     Func     = func_;
     IsMethod = isMethod_;
 }
Exemple #19
0
 public static void Execute(JSFunctionMetadata funcMetadata)
 {
     new IRGraphWriter().Visit(funcMetadata);
 }
Exemple #20
0
 public JSSourceLocation(JSFunctionMetadata metadata, int offset)
 {
     functionMetadata = metadata;
     Offset           = offset;
     prettified       = null;
 }
Exemple #21
0
 public FunctionInfo(JSFunctionMetadata func_, bool isMethod_)
 {
     Func = func_;
     IsMethod = isMethod_;
 }
Exemple #22
0
 public JSFunctionCode(JSFunctionMetadata funcMetadata, ref mdr.DFunctionSignature signature)
   : base(ref signature)
 {
   Metadata = funcMetadata;
 }
Exemple #23
0
        private string prettified;  // Serves dual roles: holds prettified string, and null-ness indicates if lazy properties have been evaluated

        public JSSourceLocation(JSFunctionMetadata metadata, Node node) : this(metadata, node.SourceOffset)
        {
        }
Exemple #24
0
    public void SetContainer(JSFunctionMetadata container)
    {
      Debug.Assert(ContainerFunction == null, "Scope already has a container function");
      ContainerFunction = container;
      Debug.Assert(_subFunctions != null, "Invalid situation!");
      foreach (var f in _subFunctions)
      {
        f.ParentFunction = ContainerFunction; //This will set everything up!
      }
      _subFunctions = null; //From now on, we don't need to keep the list in this object!

      foreach (var s in InnerScopes)
        if (!s.IsFunction)
          s.SetContainer(container);
    }
Exemple #25
0
 public void AddSubFunction(JSFunctionMetadata subFunc)
 {
   if (ContainerFunction != null)
   {
     Debug.Assert(_subFunctions == null, "Invalid situation!");
     subFunc.ParentFunction = ContainerFunction;
   }
   else
   {
     Debug.Assert(_subFunctions != null, "Invalid situation!");
     _subFunctions.Add(subFunc);
   }
 }
Exemple #26
0
            public string GetScriptKey(JSFunctionMetadata funcMetadata)
            {
                var info = GetScriptInfo(funcMetadata);

                return((info != null) ? info.Key : null);
            }
Exemple #27
0
 public JSFunctionCode(JSFunctionMetadata funcMetadata, ref mdr.DFunctionSignature signature)
     : base(ref signature)
 {
     Metadata = funcMetadata;
 }
Exemple #28
0
 public static void PushLocation(JSFunctionMetadata funcMetadata, int sourceOffset)
 {
     lock (Instance._locations)
         Instance._locations.AddLast(new JSSourceLocation(funcMetadata, sourceOffset));
 }
        }                                                                               //This is to simplify code generation

        void AddSubFunction(JSFunctionMetadata subFunc)
        {
            Debug.Assert(subFunc.FuncDefinitionIndex == mdr.Runtime.InvalidIndex || SubFunctions[subFunc.FuncDefinitionIndex] == subFunc, "Opps! Invalid situation in function tree!");
            subFunc.FuncDefinitionIndex = this.SubFunctions.Count;
            this.SubFunctions.Add(subFunc);
        }
Exemple #30
0
 public string GetScriptString(JSFunctionMetadata funcMetadata)
 {
     return(null);
 }
Exemple #31
0
 public static void PushLocation(JSFunctionMetadata funcMetadata, int sourceOffset)
 {
 }
Exemple #32
0
 public JSFunctionMetadata(FunctionExpression functionIR, JSFunctionMetadata parent = null)
   : base()
 {
   Execute = FirstExecute;
   SubFunctions = new List<JSFunctionMetadata>();
   FunctionIR = functionIR;
   FunctionIR.Scope.SetContainer(this);
   ParentFunction = parent;
   GuardProfileSize = 0;
   MapProfileSize = 0;
   CallProfileSize = 0;
 }