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(); }
public static void Execute(JSFunctionMetadata funcMetadata) { var validator = new IRValidator(); validator.Visit(funcMetadata.FunctionIR.Statement); foreach (var f in funcMetadata.SubFunctions) Execute(f); }
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); }
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); } }
public void Execute(JSFunctionMetadata funcImp) { Reset(); // Process AST Visit(funcImp); // Emit epilogue //outStream.WriteLine(); }
public virtual void Visit(JSFunctionMetadata funcImp) { // Ensure AST is available funcImp.Parse(); // Process AST enteringMethodDefinition = false; funcImp.AST.Accept(this); }
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; }
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); }
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); } }
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); }
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); }
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); } } }
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); } } }
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); }
public FunctionInfo(JSFunctionMetadata func_, bool isMethod_) { Func = func_; IsMethod = isMethod_; }
public static void Execute(JSFunctionMetadata funcMetadata) { new IRGraphWriter().Visit(funcMetadata); }
public JSSourceLocation(JSFunctionMetadata metadata, int offset) { functionMetadata = metadata; Offset = offset; prettified = null; }
public JSFunctionCode(JSFunctionMetadata funcMetadata, ref mdr.DFunctionSignature signature) : base(ref signature) { Metadata = funcMetadata; }
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) { }
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); }
public string GetScriptKey(JSFunctionMetadata funcMetadata) { var info = GetScriptInfo(funcMetadata); return((info != null) ? info.Key : null); }
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); }
public string GetScriptString(JSFunctionMetadata funcMetadata) { return(null); }
public static void PushLocation(JSFunctionMetadata funcMetadata, int sourceOffset) { }
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; }