/// <summary> /// Converts a function into a dot file /// </summary> /// <returns>The dot data to write into a file</returns> public string ToDotFile() { //unique identifier for a declared node int node_id = 0; //stack of graph instructions => for graph exploration Stack <Execution.ExecutionRefreshInstruction> instr = new Stack <Execution.ExecutionRefreshInstruction>(); //Dictionarry of declared nodes that associates a reference of an instruction to its name in the dot file Dictionary <Execution.Instruction, string> declared = new Dictionary <Execution.Instruction, string>(); //data that will contain dot file text and that will be returned string text = "digraph G {\r\n"; instr.Push(entrypoint); while (instr.Count > 0) { //current instruction to process Execution.ExecutionRefreshInstruction toprocess = instr.Pop(); //Checks if the instruction need to be declared if (!declared.ContainsKey(toprocess)) { text += DeclareNode(toprocess, ref node_id, declared); } //current instruction declaration name string decname = declared[toprocess]; //Add each instruction linked to the current one foreach (Execution.ExecutionRefreshInstruction curr in toprocess.ExecutionPins) { if (curr == null) { continue; } //declare it if needed if (!declared.ContainsKey(curr)) { text += DeclareNode(curr, ref node_id, declared); //in case the instruction is not declared, push it in the stack to process it instr.Push(curr); } //add the link between current node and its linked one text += decname + ":" + decname + "_exec -> " + declared[curr] + ":" + declared[curr] + "_exec [color=red];\r\n"; } } //end the file text += "}"; return(text); }
public void Call() { if (entrypoint == null) { throw new InvalidOperationException("Function entry point has not been defined yet"); } Stack <Execution.ExecutionRefreshInstruction> instructions = new Stack <Execution.ExecutionRefreshInstruction>(); ResetReturnsValue(); instructions.Push(entrypoint); while (instructions.Count > 0) { Execution.ExecutionRefreshInstruction toexecute = instructions.Pop(); toexecute.Execute(); Execution.ExecutionRefreshInstruction[] nexts = toexecute.GetNextInstructions(); if (nexts.Count() == 0) { if (toexecute.GetType() == typeof(Execution.Break)) { Execution.ExecutionRefreshInstruction nxt = instructions.Peek(); if (typeof(Execution.Loop).IsAssignableFrom(nxt.GetType())) //check if the next instruction is a loop instruction { instructions.Pop(); Execution.ExecutionRefreshInstruction done = ((Execution.Loop)nxt).GetDoneInstruction(); if (done != null) { instructions.Push(done); } } } else if (toexecute.GetType() == typeof(Execution.Return)) { return; } } else { foreach (Execution.ExecutionRefreshInstruction curr in nexts) { if (curr != null) { instructions.Push(curr); } } } } }
/// <summary> /// Allow user to remove an instruction from its uid /// </summary> /// <param name="instructionID">Indentifier of the instruction to remove</param> public void removeInstruction(UInt32 instructionID) { if (!instructions.ContainsKey(instructionID)) { throw new Error.NotFoundException("No such instruction with the given id"); } if (instructions[instructionID] == entrypoint) { entrypoint = null; } instructions.Remove(instructionID); }
/// <summary> /// Allow user to set function entry point from internal instruction identifier /// </summary> /// <param name="instructionID">Indentifier of the instruction to set as entry point</param> public void setEntryPoint(UInt32 instructionID) { entrypoint = findInstruction <Execution.ExecutionRefreshInstruction>(instructionID); //Console.Write(ToDotFile()); }