private Dictionary <string, CILantroType> RegisterCustomTypes(CILProgram program) { var result = new Dictionary <string, CILantroType>(); var runtimeTypeFactory = new RuntimeTypeFactory(Program.Assemblies.SingleOrDefault(), program.Modules.SingleOrDefault()); foreach (var cilClass in program.Classes) { Type runtimeType = null; var customType = new CILantroType(cilClass, this); if (RuntimeTypeHelper.GetRuntimeType(cilClass.Extends) == typeof(Enum)) { runtimeType = runtimeTypeFactory.RegisterEnumType(cilClass); } else if (RuntimeTypeHelper.GetRuntimeType(cilClass.Extends) != null) { runtimeType = runtimeTypeFactory.RegisterType(cilClass, this, customType); } cilClass.RuntimeType = runtimeType; customType._runtimeType = runtimeType; result.Add(cilClass.ClassName.UniqueName, customType); } return(result); }
public void StartInterpreter(CILProgram cilProgram, StreamReader reader, StreamWriter writer) { State = new CILProgramState(); Program = cilProgram; StreamReader = reader; StreamWriter = writer; Interpret(); }
public override CILInstruction Execute(CILProgram program, CILProgramState state) { var argument = state.Stack.Pop(); state.Stack.Push(argument); state.Stack.Push(argument); return(Method.GetNextInstruction(this)); }
public override CILInstruction Execute(CILProgram program, CILProgramState state) { var value = (int)state.Stack.Pop(); if (value == 0) { return(Method.GetInstructionByBranchTarget(this, Target)); } return(Method.GetNextInstruction(this)); }
public override CILInstruction Execute(CILProgram program, CILProgramState state) { var argument1 = (int)state.Stack.Pop(); var argument2 = (int)state.Stack.Pop(); var result = argument1 + argument2; state.Stack.Push(result); return(Method.GetNextInstruction(this)); }
public override CILInstruction Execute(CILProgram program, CILProgramState state) { var value1 = state.Stack.Pop(); var value2 = state.Stack.Pop(); if (!value1.Equals(value2)) { return(Method.GetInstructionByBranchTarget(this, Target)); } return(Method.GetNextInstruction(this)); }
public override CILInstruction Execute(CILProgram program, CILProgramState state) { var reflectedAssembly = Assembly.Load(AssemblyName); var reflectedClass = reflectedAssembly.GetType(ClassName); var reflectedMethod = reflectedClass.GetMethod(MethodName, ArgumentsTypes); var argumentsList = new List <object>(); for (int i = 0; i < ArgumentsTypes.Length; i++) { var argument = state.Stack.Pop(); argumentsList.Add(argument); } var result = reflectedMethod.Invoke(null, argumentsList.ToArray()); if (reflectedMethod.ReturnType != typeof(void)) { state.Stack.Push(result); } return(Method.GetNextInstruction(this)); }
public override CILInstruction Execute(CILProgram program, CILProgramState state) { return(Method.GetInstructionByBranchTarget(this, Target)); }
public abstract CILInstruction Execute(CILProgram program, CILProgramState state);
public static State MakeInitialState(CILProgram program) { State state = new State(); state.values = new VMValueManager(); state.heap = new VMGlobalVariables(state); state.program = program; VMValue_ftn ftn = state.Values.MakeFtnValue(program.EntryPoint); ftn.IsConcrete = true; VMValue_object obj = (VMValue_object)state.Values.MakeValue(new CILVar_object("", program.GetClass("[mscorlib]System.Object"))); obj.IsConcrete = true; VMValue_threadstart ts = state.Values.MakeThreadStartValue(obj, ftn); ts.IsConcrete = true; VMValue_thread threadobj = state.Values.MakeThreadValue(ts); threadobj.IsConcrete = true; ThreadState initThread = new ThreadState(state, threadobj); state.AddThread(initThread); state.TakeSnapshot(); return state; }
public override CILInstruction Execute(CILProgram program, CILProgramState state) { state.Stack.Push(4); return(Method.GetNextInstruction(this)); }
public CILProgramInstance(CILProgram program) { Program = program; CustomTypes = RegisterCustomTypes(program); }
public static void GoTrace(CILProgram program) { State state = State.MakeInitialState(program); bool quit = false; int idx = -1; int fwd = -1; while(quit == false) { Console.Write(">"); string command = Console.ReadLine(); string[] st = command.Split(' '); switch(st[0]) { case "h": case "help": PrintHelp(); break; case "restart": state = State.MakeInitialState(program); Console.WriteLine("Restarted from initial state"); break; case "view": case "v": Console.Write(state.ToString()); break; case "thread": case "t": idx = -1; try { idx = Int32.Parse(st[1]);}catch(Exception){} if((idx >= 0) && (idx < state.ThreadCount)) { Console.WriteLine("Forward state count: {0}", state.GetThreadByIndex(idx).GetForwardStateCount()); Console.WriteLine("Next instruction: {0}", state.GetThreadByIndex(idx).PC); Console.WriteLine(state.GetThreadByIndex(idx).ToString()); }else Console.WriteLine("Please specify a thread"); break; case "c": case "trace": idx = -1; fwd = -1; try { idx = Int32.Parse(st[1]);}catch(Exception){} try { fwd = Int32.Parse(st[2]);}catch(Exception){} if((idx >= 0) && (idx < state.ThreadCount) && (fwd >= 0) && (fwd < state.GetThreadByIndex(idx).GetForwardStateCount())) { int tmp = 0; for(int i = 0; i < idx; i++) tmp += state.GetThreadByIndex(i).GetForwardStateCount(); state.Forward(tmp + fwd); Console.Write(state.ToString()); } else Console.WriteLine("trace thread_index forward_choice"); break; case "forward": case "f": int j; for(j = 1; j < st.Length; j++) { fwd = -1; try { fwd = Int32.Parse(st[1]);} catch(Exception){} if((fwd >= 0) && (fwd < state.GetForwardStateCount())) { state.Forward(fwd); } else { if(j == 1) Console.WriteLine("forward [choice]*"); break; } } break; case "q": case "quit": case "exit": quit = true; break; default: Console.WriteLine("Unknown command, please type command help"); break; } PrintSeparator(); } }