/// <summary> /// Retrieves an existing instance of a callsite associated with a UID /// It creates a new callsite if non was found /// </summary> /// <param name="core"></param> /// <param name="uid"></param> /// <returns></returns> public CallSite GetCallSite(GraphNode graphNode, int classScope, string methodName, Executable executable, int runningBlock, Options options, RuntimeStatus runtimeStatus ) { Validity.Assert(null != executable.FunctionTable); CallSite csInstance = null; // TODO Jun: Currently generates a new callsite for imperative and // internally generated functions. // Fix the issues that cause the cache to go out of sync when // attempting to cache internal functions. This may require a // secondary callsite cache for internal functions so they dont // clash with the graphNode UID key var language = executable.instrStreamList[runningBlock].language; bool isImperative = language == Language.kImperative; bool isInternalFunction = CoreUtils.IsInternalFunction(methodName); if (isInternalFunction || isImperative) { csInstance = new CallSite(classScope, methodName, executable.FunctionTable, options.ExecutionMode); } else if (!CallsiteCache.TryGetValue(graphNode.CallsiteIdentifier, out csInstance)) { // Attempt to retrieve a preloaded callsite data (optional). var traceData = GetAndRemoveTraceDataForNode(graphNode.guid); csInstance = new CallSite(classScope, methodName, executable.FunctionTable, options.ExecutionMode, traceData); CallsiteCache[graphNode.CallsiteIdentifier] = csInstance; CallSiteToNodeMap[csInstance.CallSiteID] = graphNode.guid; ASTToCallSiteMap[graphNode.AstID] = csInstance; } if (graphNode != null && !CoreUtils.IsDisposeMethod(methodName)) { csInstance.UpdateCallSite(classScope, methodName); if (options.IsDeltaExecution) { runtimeStatus.ClearWarningForExpression(graphNode.exprUID); } } return csInstance; }
/// <summary> /// Gets the number of dirty VM graphnodes at the global scope /// </summary> /// <param name="exe"></param> /// <returns></returns> public static int GetDirtyNodeCountAtGlobalScope(Executable exe) { Validity.Assert(exe != null); int dirtyNodes = 0; var graph = exe.instrStreamList[0].dependencyGraph; var graphNodes = graph.GetGraphNodesAtScope(Constants.kInvalidIndex, Constants.kGlobalScope); foreach (AssociativeGraph.GraphNode graphNode in graphNodes) { if (graphNode.isDirty) { ++dirtyNodes; } } return dirtyNodes; }
public RuntimeCore(Heap heap, Options options = null, Executable executable = null) { // The heap is initialized by the core and is used to allocate strings // Use the that heap for runtime Validity.Assert(heap != null); this.Heap = heap; RuntimeMemory = new RuntimeMemory(Heap); this.Options = options; InterpreterProps = new Stack<InterpreterProperties>(); ReplicationGuides = new List<List<ReplicationGuide>>(); AtLevels = new List<AtLevel>(); executedAstGuids = new HashSet<Guid>(); RunningBlock = 0; ExecutionState = (int)ExecutionStateEventArgs.State.Invalid; //not yet started ContinuationStruct = new ContinuationStructure(); watchStack = new List<StackValue>(); watchFramePointer = Constants.kInvalidIndex; WatchSymbolList = new List<SymbolNode>(); FunctionCallDepth = 0; cancellationPending = false; watchClassScope = Constants.kInvalidIndex; ExecutionInstance = CurrentExecutive = new Executive(this); ExecutiveProvider = new ExecutiveProvider(); RuntimeStatus = new ProtoCore.RuntimeStatus(this); StartPC = Constants.kInvalidPC; RuntimeData = new ProtoCore.RuntimeData(); DSExecutable = executable; Mirror = null; }
GetCallsitesForNodes(IEnumerable<Guid> nodeGuids, Executable executable) { if (nodeGuids == null) throw new ArgumentNullException("nodeGuids"); var nodeMap = new Dictionary<Guid, List<CallSite>>(); if (!nodeGuids.Any()) // Nothing to persist now. return nodeMap; // Attempt to get the list of graph node if one exists. IEnumerable<GraphNode> graphNodes = null; { if (executable != null) { var stream = executable.instrStreamList; if (stream != null && (stream.Length > 0)) { var graph = stream[0].dependencyGraph; if (graph != null) graphNodes = graph.GraphList; } } if (graphNodes == null) // No execution has taken place. return nodeMap; } foreach (Guid nodeGuid in nodeGuids) { // Get a list of GraphNode objects that correspond to this node. var matchingGraphNodes = graphNodes.Where(gn => gn.guid == nodeGuid); if (!matchingGraphNodes.Any()) continue; // Get all callsites that match the graph node ids. var matchingCallSites = (from cs in CallsiteCache from gn in matchingGraphNodes where string.Equals(cs.Key, gn.CallsiteIdentifier) select cs.Value); // Append each callsite element under node element. nodeMap[nodeGuid] = matchingCallSites.ToList(); } return nodeMap; }
GetTraceDataForNodes(IEnumerable<Guid> nodeGuids, Executable executable) { if (nodeGuids == null) throw new ArgumentNullException("nodeGuids"); var nodeDataPairs = new Dictionary<Guid, List<string>>(); if (!nodeGuids.Any()) // Nothing to persist now. return nodeDataPairs; // Attempt to get the list of graph node if one exists. IEnumerable<GraphNode> graphNodes = null; { if (executable != null) { var stream = executable.instrStreamList; if (stream != null && (stream.Length > 0)) { var graph = stream[0].dependencyGraph; if (graph != null) graphNodes = graph.GraphList; } } if (graphNodes == null) // No execution has taken place. return nodeDataPairs; } foreach (Guid nodeGuid in nodeGuids) { // Get a list of GraphNode objects that correspond to this node. var graphNodeIds = graphNodes. Where(gn => gn.guid == nodeGuid). Select(gn => gn.CallsiteIdentifier); if (!graphNodeIds.Any()) continue; // Get all callsites that match the graph node ids. var matchingCallSites = (from cs in CallsiteCache from gn in graphNodeIds where cs.Key == gn select cs.Value); // Append each callsite element under node element. var serializedCallsites = matchingCallSites.Select(callSite => callSite.GetTraceDataToSave()) .Where(traceDataToSave => !String.IsNullOrEmpty(traceDataToSave)) .ToList(); // No point adding serialized callsite data if it's empty. if (serializedCallsites.Count > 0) nodeDataPairs.Add(nodeGuid, serializedCallsites); } return nodeDataPairs; }
public void SetProperties(Options runtimeOptions, Executable executable, DebugProperties debugProps = null, ProtoCore.Runtime.Context context = null, Executable exprInterpreterExe = null) { this.Context = context; this.DSExecutable = executable; this.Options = runtimeOptions; this.DebugProps = debugProps; this.ExprInterpreterExe = exprInterpreterExe; }
public void GenerateExprExe() { // TODO Jun: Determine if we really need another executable for the expression interpreter Validity.Assert(null == ExprInterpreterExe); ExprInterpreterExe = new DSASM.Executable(); // Copy all tables ExprInterpreterExe.classTable = DSExecutable.classTable; ExprInterpreterExe.procedureTable = DSExecutable.procedureTable; ExprInterpreterExe.runtimeSymbols = DSExecutable.runtimeSymbols; ExprInterpreterExe.isSingleAssocBlock = DSExecutable.isSingleAssocBlock; // Copy all instruction streams // TODO Jun: What method to copy all? Use that ExprInterpreterExe.instrStreamList = new InstructionStream[DSExecutable.instrStreamList.Length]; for (int i = 0; i < DSExecutable.instrStreamList.Length; ++i) { if (null != DSExecutable.instrStreamList[i]) { ExprInterpreterExe.instrStreamList[i] = new InstructionStream(DSExecutable.instrStreamList[i].language, this); //ExprInterpreterExe.instrStreamList[i] = new InstructionStream(DSExecutable.instrStreamList[i].language, DSExecutable.instrStreamList[i].dependencyGraph, this); for (int j = 0; j < DSExecutable.instrStreamList[i].instrList.Count; ++j) { ExprInterpreterExe.instrStreamList[i].instrList.Add(DSExecutable.instrStreamList[i].instrList[j]); } } } }
/// <summary> /// Determines if at least one graphnode in the glboal scope is dirty /// </summary> /// <param name="exe"></param> /// <returns></returns> public static bool IsGlobalScopeDirty(Executable exe) { Validity.Assert(exe != null); var graph = exe.instrStreamList[0].dependencyGraph; var graphNodes = graph.GetGraphNodesAtScope(Constants.kInvalidIndex, Constants.kGlobalScope); if (graphNodes != null) { foreach (AssociativeGraph.GraphNode graphNode in graphNodes) { if (graphNode.isDirty) { return true; } } } return false; }
public void GenerateExprExe() { // TODO Jun: Determine if we really need another executable for the expression interpreter Validity.Assert(null == ExprInterpreterExe); ExprInterpreterExe = new Executable(); ExprInterpreterExe.FunctionTable = FunctionTable; ExprInterpreterExe.DynamicVarTable = DynamicVariableTable; ExprInterpreterExe.FuncPointerTable = FunctionPointerTable; ExprInterpreterExe.DynamicFuncTable = DynamicFunctionTable; ExprInterpreterExe.ContextDataMngr = ContextDataManager; ExprInterpreterExe.Configurations = Configurations; ExprInterpreterExe.CodeToLocation = CodeToLocation; ExprInterpreterExe.CurrentDSFileName = CurrentDSFileName; // Copy all tables ExprInterpreterExe.classTable = DSExecutable.classTable; ExprInterpreterExe.procedureTable = DSExecutable.procedureTable; ExprInterpreterExe.runtimeSymbols = DSExecutable.runtimeSymbols; ExprInterpreterExe.TypeSystem = TypeSystem; // Copy all instruction streams // TODO Jun: What method to copy all? Use that ExprInterpreterExe.instrStreamList = new InstructionStream[DSExecutable.instrStreamList.Length]; for (int i = 0; i < DSExecutable.instrStreamList.Length; ++i) { if (null != DSExecutable.instrStreamList[i]) { ExprInterpreterExe.instrStreamList[i] = new InstructionStream(DSExecutable.instrStreamList[i].language, this); //ExprInterpreterExe.instrStreamList[i] = new InstructionStream(DSExecutable.instrStreamList[i].language, DSExecutable.instrStreamList[i].dependencyGraph, this); for (int j = 0; j < DSExecutable.instrStreamList[i].instrList.Count; ++j) { ExprInterpreterExe.instrStreamList[i].instrList.Add(DSExecutable.instrStreamList[i].instrList[j]); } } } }
private void ResetAll(Options options) { ProtoCore.Utils.Validity.AssertExpiry(); Options = options; Executives = new Dictionary<ProtoCore.Language, ProtoCore.Executive>(); FunctionTable = new Lang.FunctionTable(); ClassIndex = ProtoCore.DSASM.Constants.kInvalidIndex; Heap = new DSASM.Heap(); Rmem = new ProtoCore.Runtime.RuntimeMemory(Heap); watchClassScope = ProtoCore.DSASM.Constants.kInvalidIndex; watchFunctionScope = ProtoCore.DSASM.Constants.kInvalidIndex; watchBaseOffset = 0; watchStack = new List<StackValue>(); watchSymbolList = new List<SymbolNode>(); watchFramePointer = ProtoCore.DSASM.Constants.kInvalidIndex; ID = FIRST_CORE_ID; //recurtion recursivePoint = new List<FunctionCounter>(); funcCounterTable = new List<FunctionCounter>(); calledInFunction = false; GlobOffset = 0; GlobHeapOffset = 0; BaseOffset = 0; GraphNodeUID = 0; RunningBlock = 0; CodeBlockIndex = 0; RuntimeTableIndex = 0; CodeBlockList = new List<DSASM.CodeBlock>(); CompleteCodeBlockList = new List<DSASM.CodeBlock>(); DSExecutable = new ProtoCore.DSASM.Executable(); AssocNode = null; // TODO Jun/Luke type system refactoring // Initialize the globalClass table and type system ClassTable = new DSASM.ClassTable(); TypeSystem = new TypeSystem(); TypeSystem.SetClassTable(ClassTable); ProcNode = null; ProcTable = new DSASM.ProcedureTable(ProtoCore.DSASM.Constants.kGlobalScope); //Initialize the function pointer table FunctionPointerTable = new DSASM.FunctionPointerTable(); //Initialize the dynamic string table and dynamic function table DynamicVariableTable = new DSASM.DynamicVariableTable(); DynamicFunctionTable = new DSASM.DynamicFunctionTable(); replicationGuides = new List<List<int>>(); ExceptionHandlingManager = new ExceptionHandlingManager(); startPC = ProtoCore.DSASM.Constants.kInvalidIndex; deltaCompileStartPC = ProtoCore.DSASM.Constants.kInvalidIndex; RuntimeStatus = new RuntimeStatus(this); SSASubscript = 0; ExpressionUID = 0; ModifierBlockUID = 0; ModifierStateSubscript = 0; ExprInterpreterExe = null; ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal; assocCodegen = null; FunctionCallDepth = 0; // Default execution log is Console.Out. this.ExecutionLog = Console.Out; ExecutionState = (int)ExecutionStateEventArgs.State.kInvalid; //not yet started DebugProps = new DebugProperties(); //stackNodeExecutedSameTimes = new Stack<List<AssociativeGraph.GraphNode>>(); //stackExecutingGraphNodes = new Stack<AssociativeGraph.GraphNode>(); InterpreterProps = new Stack<InterpreterProperties>(); stackActiveExceptionRegistration = new Stack<ExceptionRegistration>(); ExecutiveProvider = new ExecutiveProvider(); Configurations = new Dictionary<string, object>(); ContinuationStruct = new Lang.ContinuationStructure(); ParsingMode = ProtoCore.ParseMode.Normal; IsParsingPreloadedAssembly = false; IsParsingCodeBlockNode = false; ImportHandler = null; deltaCompileStartPC = 0; builtInsLoaded = false; FFIPropertyChangedMonitor = new FFIPropertyChangedMonitor(this); }
// Comment Jun: // The core is reused on delta execution // These are properties that need to be reset on subsequent executions // All properties require reset except for the runtime memory public void ResetForDeltaExecution() { ClassIndex = ProtoCore.DSASM.Constants.kInvalidIndex; watchClassScope = ProtoCore.DSASM.Constants.kInvalidIndex; watchFunctionScope = ProtoCore.DSASM.Constants.kInvalidIndex; watchBaseOffset = 0; watchStack = new List<StackValue>(); watchSymbolList = new List<SymbolNode>(); watchFramePointer = ProtoCore.DSASM.Constants.kInvalidIndex; ID = FIRST_CORE_ID; //recurtion recursivePoint = new List<FunctionCounter>(); funcCounterTable = new List<FunctionCounter>(); calledInFunction = false; //GlobOffset = 0; GlobHeapOffset = 0; BaseOffset = 0; GraphNodeUID = 0; RunningBlock = 0; //CodeBlockList = new List<DSASM.CodeBlock>(); CompleteCodeBlockList = new List<DSASM.CodeBlock>(); DSExecutable = new ProtoCore.DSASM.Executable(); AssocNode = null; //Initialize the function pointer table FunctionPointerTable = new DSASM.FunctionPointerTable(); //Initialize the dynamic string table and dynamic function table DynamicVariableTable = new DSASM.DynamicVariableTable(); DynamicFunctionTable = new DSASM.DynamicFunctionTable(); replicationGuides = new List<List<int>>(); ExceptionHandlingManager = new ExceptionHandlingManager(); startPC = ProtoCore.DSASM.Constants.kInvalidIndex; RuntimeStatus = new RuntimeStatus(this); SSASubscript = 0; ExpressionUID = 0; ModifierBlockUID = 0; ModifierStateSubscript = 0; ExprInterpreterExe = null; ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal; assocCodegen = null; FunctionCallDepth = 0; // Default execution log is Console.Out. this.ExecutionLog = Console.Out; ExecutionState = (int)ExecutionStateEventArgs.State.kInvalid; //not yet started DebugProps = new DebugProperties(); InterpreterProps = new Stack<InterpreterProperties>(); stackActiveExceptionRegistration = new Stack<ExceptionRegistration>(); ExecutiveProvider = new ExecutiveProvider(); ParsingMode = ProtoCore.ParseMode.Normal; // Reset PC dictionary containing PC to line/col map if (codeToLocation != null) codeToLocation.Clear(); if (LocationErrorMap != null) LocationErrorMap.Clear(); if (AstNodeList != null) AstNodeList.Clear(); ResetDeltaCompile(); }
public StackValue GetMemberData(int symbolindex, int scope, Executable exe) { StackValue thisptr = CurrentStackFrame.ThisPtr; // Get the heapstck offset int offset = exe.classTable.ClassNodes[scope].symbols.symbolList[symbolindex].index; var heapElement = Heap.GetHeapElement(thisptr); if (null == heapElement.Stack || heapElement.Stack.Length == 0) return StackValue.Null; StackValue sv = heapElement.Stack[offset]; Validity.Assert(sv.IsPointer || sv.IsArray|| sv.IsInvalid); // Not initialized yet if (sv.IsInvalid) { return StackValue.Null; } else if (sv.IsArray) { return sv; } StackValue nextPtr = sv; Validity.Assert(nextPtr.opdata >= 0); heapElement = Heap.GetHeapElement(nextPtr); if (null != heapElement.Stack && heapElement.Stack.Length > 0) { StackValue data = heapElement.Stack[0]; bool isActualData = !data.IsPointer && !data.IsArray && !data.IsInvalid; if (isActualData) { return data; } } return sv; }
public StackValue GetMemberData(int symbolindex, int scope, Executable exe) { StackValue thisptr = CurrentStackFrame.ThisPtr; // Get the heapstck offset int offset = exe.classTable.ClassNodes[scope].Symbols.symbolList[symbolindex].index; var obj = Heap.ToHeapObject<DSObject>(thisptr); if (!obj.Values.Any()) return StackValue.Null; StackValue sv = obj.GetValueFromIndex(offset, null); Validity.Assert(sv.IsPointer || sv.IsArray|| sv.IsInvalid); // Not initialized yet if (sv.IsInvalid) { return StackValue.Null; } else if (sv.IsArray) { return sv; } StackValue nextPtr = sv; obj = Heap.ToHeapObject<DSObject>(nextPtr); if (obj.Values.Any()) { StackValue data = obj.GetValueFromIndex(0, null); bool isActualData = !data.IsPointer && !data.IsArray && !data.IsInvalid; if (isActualData) { return data; } } return sv; }
/// <summary> /// The public method to compile DS code /// </summary> /// <param name="sourcecode"></param> /// <param name="compileCore"></param> /// <param name="dsExecutable"></param> /// <returns></returns> public bool CompileMe(string sourcecode, ProtoCore.Core compileCore, out Executable dsExecutable) { int blockID = 0; bool succeeded = Compile(sourcecode, compileCore, out blockID); compileCore.GenerateExecutable(); dsExecutable = compileCore.DSExecutable; return succeeded; }
GetTraceDataForNodes(IEnumerable<Guid> nodeGuids, Executable executable) { if (nodeGuids == null) throw new ArgumentNullException("nodeGuids"); var nodeDataPairs = new Dictionary<Guid, List<CallSite.RawTraceData>>(); if (!nodeGuids.Any()) // Nothing to persist now. return nodeDataPairs; // Attempt to get the list of graph node if one exists. IEnumerable<GraphNode> graphNodes = null; { if (executable != null) { var stream = executable.instrStreamList; if (stream != null && (stream.Length > 0)) { var graph = stream[0].dependencyGraph; if (graph != null) graphNodes = graph.GraphList; } } if (graphNodes == null) // No execution has taken place. return nodeDataPairs; } foreach (Guid nodeGuid in nodeGuids) { // Get a list of GraphNode objects that correspond to this node. var graphNodeIds = graphNodes. Where(gn => gn.guid == nodeGuid). Select(gn => gn.CallsiteIdentifier); if (!graphNodeIds.Any()) continue; // Get all callsites that match the graph node ids. // // Note we assume the graph node is the top-level graph node here. // The callsite id is the concatenation of all graphnodes' callsite // identifier along the nested function call. var matchingCallSites = (from cs in CallsiteCache from gn in graphNodeIds where !string.IsNullOrEmpty(gn) && cs.Key.StartsWith(gn) select new { cs.Key, cs.Value }); // Append each callsite element under node element. var serializedCallsites = new List<CallSite.RawTraceData>(); foreach (var site in matchingCallSites) { var traceData = site.Value.GetTraceDataToSave(); if (!string.IsNullOrEmpty(traceData)) { serializedCallsites.Add(new CallSite.RawTraceData(site.Key, traceData)); } } // No point adding serialized callsite data if it's empty. if (serializedCallsites.Any()) { nodeDataPairs.Add(nodeGuid, serializedCallsites); } } return nodeDataPairs; }
/// <summary> /// Retrieves an existing instance of a callsite associated with a UID /// It creates a new callsite if non was found /// </summary> /// <param name="core"></param> /// <param name="uid"></param> /// <returns></returns> public CallSite GetCallSite(int classScope, string methodName, Executable executable, RuntimeCore runtimeCore) { Validity.Assert(null != executable.FunctionTable); CallSite csInstance = null; var graphNode = executable.ExecutingGraphnode; var topGraphNode = graphNode; // If it is a nested function call, append all callsite ids List<string> callsiteIdentifiers = new List<string>(); foreach (var prop in runtimeCore.InterpreterProps) { if (prop != null && prop.executingGraphNode != null && graphNode != prop.executingGraphNode) { topGraphNode = prop.executingGraphNode; if (!string.IsNullOrEmpty(topGraphNode.CallsiteIdentifier)) { callsiteIdentifiers.Add(topGraphNode.CallsiteIdentifier); } } } if (graphNode != null) { callsiteIdentifiers.Add(graphNode.CallsiteIdentifier); } var callsiteID = string.Join(";", callsiteIdentifiers.ToArray()); // TODO Jun: Currently generates a new callsite for imperative and // internally generated functions. // Fix the issues that cause the cache to go out of sync when // attempting to cache internal functions. This may require a // secondary callsite cache for internal functions so they dont // clash with the graphNode UID key var language = executable.instrStreamList[runtimeCore.RunningBlock].language; bool isImperative = language == Language.Imperative; bool isInternalFunction = CoreUtils.IsInternalFunction(methodName); if (isInternalFunction || isImperative) { csInstance = new CallSite(classScope, methodName, executable.FunctionTable, runtimeCore.Options.ExecutionMode); } else if (!CallsiteCache.TryGetValue(callsiteID, out csInstance)) { // Attempt to retrieve a preloaded callsite data (optional). var traceData = GetAndRemoveTraceDataForNode(topGraphNode.guid, callsiteID); csInstance = new CallSite(classScope, methodName, executable.FunctionTable, runtimeCore.Options.ExecutionMode, traceData); CallsiteCache[callsiteID] = csInstance; CallSiteToNodeMap[csInstance.CallSiteID] = topGraphNode.guid; } if (graphNode != null && !CoreUtils.IsDisposeMethod(methodName)) { csInstance.UpdateCallSite(classScope, methodName); if (runtimeCore.Options.IsDeltaExecution) { runtimeCore.RuntimeStatus.ClearWarningForExpression(graphNode.exprUID); } } return csInstance; }
// Comment Jun: // The core is reused on delta execution // These are properties that need to be reset on subsequent executions // All properties require reset except for the runtime memory public void ResetForDeltaExecution() { ClassIndex = ProtoCore.DSASM.Constants.kInvalidIndex; watchClassScope = ProtoCore.DSASM.Constants.kInvalidIndex; watchFunctionScope = ProtoCore.DSASM.Constants.kInvalidIndex; watchBaseOffset = 0; watchStack = new List<StackValue>(); watchSymbolList = new List<SymbolNode>(); watchFramePointer = ProtoCore.DSASM.Constants.kInvalidIndex; ID = FIRST_CORE_ID; //recurtion recursivePoint = new List<FunctionCounter>(); funcCounterTable = new List<FunctionCounter>(); calledInFunction = false; //GlobOffset = 0; GlobHeapOffset = 0; BaseOffset = 0; GraphNodeUID = 0; RunningBlock = 0; //CodeBlockList = new List<DSASM.CodeBlock>(); CompleteCodeBlockList = new List<DSASM.CodeBlock>(); DSExecutable = new ProtoCore.DSASM.Executable(); AssocNode = null; // // // Comment Jun: Delta execution should not reset the class tables as they are preserved // // FunctionTable = new Lang.FunctionTable(); // ClassTable = new DSASM.ClassTable(); // TypeSystem = new TypeSystem(); // TypeSystem.SetClassTable(ClassTable); // ProcNode = null; // ProcTable = new DSASM.ProcedureTable(ProtoCore.DSASM.Constants.kGlobalScope); // // CodeBlockList = new List<DSASM.CodeBlock>(); // // // CodeBlockIndex = 0; // RuntimeTableIndex = 0; // // Comment Jun: // Disable SSA for the previous graphcompiler as it clashes with the way code recompilation behaves // SSA is enabled for the new graph strategy of delta compilation and execution Options.GenerateSSA = false; //Initialize the function pointer table FunctionPointerTable = new DSASM.FunctionPointerTable(); //Initialize the dynamic string table and dynamic function table DynamicVariableTable = new DSASM.DynamicVariableTable(); DynamicFunctionTable = new DSASM.DynamicFunctionTable(); replicationGuides = new List<List<ProtoCore.ReplicationGuide>>(); ExceptionHandlingManager = new ExceptionHandlingManager(); startPC = ProtoCore.DSASM.Constants.kInvalidIndex; if (Options.SuppressBuildOutput) { // don't log any of the build related messages // just accumulate them in relevant containers with // BuildStatus object // BuildStatus = new BuildStatus(this, false, false, false); } else { BuildStatus = new BuildStatus(this, Options.BuildOptWarningAsError, null, Options.BuildOptErrorAsWarning); } RuntimeStatus = new RuntimeStatus(this); //SSASubscript = 0; ExpressionUID = 0; ModifierBlockUID = 0; ModifierStateSubscript = 0; ExprInterpreterExe = null; ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal; assocCodegen = null; FunctionCallDepth = 0; // Default execution log is Console.Out. this.ExecutionLog = Console.Out; ExecutionState = (int)ExecutionStateEventArgs.State.kInvalid; //not yet started DebugProps = new DebugProperties(); InterpreterProps = new Stack<InterpreterProperties>(); stackActiveExceptionRegistration = new Stack<ExceptionRegistration>(); ExecutiveProvider = new ExecutiveProvider(); ParsingMode = ProtoCore.ParseMode.Normal; // Reset PC dictionary containing PC to line/col map if (codeToLocation != null) codeToLocation.Clear(); if (LocationErrorMap != null) LocationErrorMap.Clear(); if (AstNodeList != null) AstNodeList.Clear(); ResetDeltaCompile(); DeltaCodeBlockIndex = 0; ForLoopBlockIndex = ProtoCore.DSASM.Constants.kInvalidIndex; }
public void GenerateExecutable() { Validity.Assert(CodeBlockList.Count >= 0); DSExecutable = new Executable(); // Create the code block list data DSExecutable.CodeBlocks = new List<CodeBlock>(); DSExecutable.CodeBlocks.AddRange(CodeBlockList); DSExecutable.CompleteCodeBlocks = new List<CodeBlock>(); DSExecutable.CompleteCodeBlocks.AddRange(CompleteCodeBlockList); // Retrieve the class table directly since it is a global table DSExecutable.classTable = ClassTable; // The TypeSystem is a record of all primitive and compiler generated types DSExecutable.TypeSystem = TypeSystem; RuntimeTableIndex = CompleteCodeBlockList.Count; // Build the runtime symbols DSExecutable.runtimeSymbols = new SymbolTable[RuntimeTableIndex]; for (int n = 0; n < CodeBlockList.Count; ++n) { BfsBuildSequenceTable(CodeBlockList[n], DSExecutable.runtimeSymbols); } // Build the runtime procedure table DSExecutable.procedureTable = new ProcedureTable[RuntimeTableIndex]; for (int n = 0; n < CodeBlockList.Count; ++n) { BfsBuildProcedureTable(CodeBlockList[n], DSExecutable.procedureTable); } // Build the executable instruction streams DSExecutable.instrStreamList = new InstructionStream[RuntimeTableIndex]; for (int n = 0; n < CodeBlockList.Count; ++n) { BfsBuildInstructionStreams(CodeBlockList[n], DSExecutable.instrStreamList); } GenerateExprExe(); DSExecutable.FunctionTable = FunctionTable; DSExecutable.DynamicVarTable = DynamicVariableTable; DSExecutable.DynamicFuncTable = DynamicFunctionTable; DSExecutable.FuncPointerTable = FunctionPointerTable; DSExecutable.ContextDataMngr = ContextDataManager; DSExecutable.Configurations = Configurations; DSExecutable.CodeToLocation = CodeToLocation; DSExecutable.CurrentDSFileName = CurrentDSFileName; }
private void ResetAll(Options options) { ProtoCore.Utils.Validity.AssertExpiry(); Options = options; Executives = new Dictionary<ProtoCore.Language, ProtoCore.Executive>(); FunctionTable = new Lang.FunctionTable(); ClassIndex = ProtoCore.DSASM.Constants.kInvalidIndex; Heap = new DSASM.Heap(); Rmem = new ProtoCore.Runtime.RuntimeMemory(Heap); watchClassScope = ProtoCore.DSASM.Constants.kInvalidIndex; watchFunctionScope = ProtoCore.DSASM.Constants.kInvalidIndex; watchBaseOffset = 0; watchStack = new List<StackValue>(); watchSymbolList = new List<SymbolNode>(); watchFramePointer = ProtoCore.DSASM.Constants.kInvalidIndex; ID = FIRST_CORE_ID; //recurtion recursivePoint = new List<FunctionCounter>(); funcCounterTable = new List<FunctionCounter>(); calledInFunction = false; GlobOffset = 0; GlobHeapOffset = 0; BaseOffset = 0; GraphNodeUID = 0; RunningBlock = 0; CodeBlockIndex = 0; RuntimeTableIndex = 0; CodeBlockList = new List<DSASM.CodeBlock>(); CompleteCodeBlockList = new List<DSASM.CodeBlock>(); DSExecutable = new ProtoCore.DSASM.Executable(); AssocNode = null; // TODO Jun/Luke type system refactoring // Initialize the globalClass table and type system ClassTable = new DSASM.ClassTable(); TypeSystem = new TypeSystem(); TypeSystem.SetClassTable(ClassTable); ProcNode = null; ProcTable = new DSASM.ProcedureTable(ProtoCore.DSASM.Constants.kGlobalScope); //Initialize the function pointer table FunctionPointerTable = new DSASM.FunctionPointerTable(); //Initialize the dynamic string table and dynamic function table DynamicVariableTable = new DSASM.DynamicVariableTable(); DynamicFunctionTable = new DSASM.DynamicFunctionTable(); replicationGuides = new List<List<ProtoCore.ReplicationGuide>>(); ExceptionHandlingManager = new ExceptionHandlingManager(); startPC = ProtoCore.DSASM.Constants.kInvalidIndex; deltaCompileStartPC = ProtoCore.DSASM.Constants.kInvalidIndex; if (options.SuppressBuildOutput) { // don't log any of the build related messages // just accumulate them in relevant containers with // BuildStatus object // BuildStatus = new BuildStatus(this, false, false, false); } else { BuildStatus = new BuildStatus(this, Options.BuildOptWarningAsError, null, Options.BuildOptErrorAsWarning); } RuntimeStatus = new RuntimeStatus(this); SSASubscript = 0; SSASubscript_GUID = System.Guid.NewGuid(); ExpressionUID = 0; ModifierBlockUID = 0; ModifierStateSubscript = 0; ExprInterpreterExe = null; ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal; assocCodegen = null; FunctionCallDepth = 0; // Default execution log is Console.Out. this.ExecutionLog = Console.Out; ExecutionState = (int)ExecutionStateEventArgs.State.kInvalid; //not yet started DebugProps = new DebugProperties(); //stackNodeExecutedSameTimes = new Stack<List<AssociativeGraph.GraphNode>>(); //stackExecutingGraphNodes = new Stack<AssociativeGraph.GraphNode>(); InterpreterProps = new Stack<InterpreterProperties>(); stackActiveExceptionRegistration = new Stack<ExceptionRegistration>(); ExecutiveProvider = new ExecutiveProvider(); Configurations = new Dictionary<string, object>(); ContinuationStruct = new Lang.ContinuationStructure(); ParsingMode = ProtoCore.ParseMode.Normal; IsParsingPreloadedAssembly = false; IsParsingCodeBlockNode = false; ImportHandler = null; deltaCompileStartPC = 0; builtInsLoaded = false; FFIPropertyChangedMonitor = new FFIPropertyChangedMonitor(this); csExecutionState = null; EnableCallsiteExecutionState = false; // TODO: Remove check once fully implemeted if (EnableCallsiteExecutionState) { csExecutionState = CallsiteExecutionState.LoadState(); } else { csExecutionState = new CallsiteExecutionState(); } CallsiteCache = new Dictionary<int, CallSite>(); CachedSSANodes = new List<AssociativeNode>(); CallSiteToNodeMap = new Dictionary<Guid, Guid>(); ASTToCallSiteMap = new Dictionary<int, CallSite>(); ForLoopBlockIndex = ProtoCore.DSASM.Constants.kInvalidIndex; GraphNodeCallList = new List<GraphNode>(); newEntryPoint = ProtoCore.DSASM.Constants.kInvalidIndex; }