public override CILInstruction Execute(ThreadState threadState) { // correctness check, only needed in debug if (CanExecute(threadState) == false) throw new Exception("This ceq instruction is not ready to execute"); // gets the two values and compare them VMValue topOfStack = threadState.GetValue(threadState.ThreadStack.Peek()); VMValue_int32 ret = (VMValue_int32)threadState.SystemState.Values.MakeValue(new CILVar_int32("")); if (topOfStack is VMValue_int32) { VMValue_int32 value2 = (VMValue_int32)threadState.GetValue(threadState.ThreadStack.Pop()); VMValue_int32 value1 = (VMValue_int32)threadState.GetValue(threadState.ThreadStack.Pop()); if (value1.Value > value2.Value) ret.Value = 1; else ret.Value = 0; } else throw new Exception("Unsupported data type for instruction cgt"); ret.IsThreadLocal = true; ret.IsConcrete = true; threadState.ThreadStack.Push(ret.GUID); return threadState.CurrentMethod.GetNextInstruction(this); }
public override CILInstruction Execute(ThreadState threadState) { if(CanExecute(threadState) == false) throw new Exception("FATAL: Calling execute on an unexecutable instruction state"); // thread special data type // .ThreadStart // .Thread if(classType.Name == "[mscorlib]System.Threading.ThreadStart") { VMValue_ftn method = (VMValue_ftn)threadState.GetValue(threadState.ThreadStack.Pop()); VMValue_object theobj = (VMValue_object)threadState.GetValue(threadState.ThreadStack.Pop()); VMValue_threadstart ts = threadState.SystemState.Values.MakeThreadStartValue(theobj, method); ts.IsConcrete = true; VMValue_object ret = (VMValue_object)threadState.SystemState.Values.MakeValue(new CILVar_object("", new CILClass("[mscorlib]System.Threading.ThreadStart"))); ret.ValueGUID = ts.GUID; ret.IsThreadLocal = true; ret.IsConcrete = true; threadState.ThreadStack.Push(ret.GUID); } else if(classType.Name == "[mscorlib]System.Threading.Thread") { VMValue_object o = (VMValue_object)threadState.GetValue(threadState.ThreadStack.Pop()); VMValue_thread thethread = threadState.SystemState.Values.MakeThreadValue((VMValue_threadstart)threadState.GetValue(o.ValueGUID)); thethread.IsConcrete = true; VMValue_object ret = (VMValue_object)threadState.SystemState.Values.MakeValue(new CILVar_object("", new CILClass("[mscorlib]System.Threading.Thread"))); ret.ValueGUID = thethread.GUID; ret.IsThreadLocal = true; ret.IsConcrete = true; // TODO: be careful if we support enumeration of threads // then created threads are not local, maybe not here // because the thread has not started and cannot be // enumerated but it may have connection. threadState.ThreadStack.Push(ret.GUID); } else { // TODONOW: call the constructor function // right now we only make the data for the object instance and clean the stack, put the new obj on if(ctorSig.Equals("()") == false) { int counter = 1; int i; for(i = 0; i < ctorSig.Length; i++) if(ctorSig[i] == ',') counter++; for(i = 0; i < counter; i++) threadState.ThreadStack.Pop(); } VMValue_object obj = (VMValue_object)threadState.SystemState.Values.MakeValue(new CILVar_object("", classType)); VMValue_objectinst objinst = (VMValue_objectinst)threadState.SystemState.Values.MakeObjectInstance(new CILVar_object("", classType)); objinst.IsConcrete = true; obj.ValueGUID = objinst.GUID; obj.IsThreadLocal = true; obj.IsConcrete = true; threadState.ThreadStack.Push(obj.GUID); return threadState.CallFunction(classType.GetMethod(".ctor", "()")); } return threadState.CurrentMethod.GetNextInstruction(this); }
public override bool CanExecute(ThreadState threadState) { // this can be considered as an "arithmetic operation", so can't be executed // until both necessary values are ready VMValue v1 = threadState.GetValue(threadState.ThreadStack.Peek()); VMValue v2 = threadState.GetValue(threadState.ThreadStack.Peek(1)); return (v1.IsConcrete && v2.IsConcrete); }
public override CILInstruction Execute(ThreadState threadState) { if(CanExecute(threadState) == false) throw new Exception("This add instruction is not ready to execute"); VMValue_int32 value2 = (VMValue_int32)threadState.GetValue(threadState.ThreadStack.Pop()); VMValue_int32 value1 = (VMValue_int32)threadState.GetValue(threadState.ThreadStack.Pop()); VMValue_int32 sum = (VMValue_int32)threadState.SystemState.Values.MakeValue(new CILVar_int32("")); sum.Value = value1.Value % value2.Value; sum.IsThreadLocal = true; sum.IsConcrete = true; threadState.ThreadStack.Push(sum.GUID); return threadState.CurrentMethod.GetNextInstruction(this); }
/// <summary> /// Execute a stloc /// It will initiate a write and schedule it to the thread's queue /// </summary> /// <param name="threadState"></param> /// <returns></returns> public override CILInstruction Execute(ThreadState threadState) { if(CanExecute(threadState) == false) throw new Exception("Can't execute this stloc now"); VMValue source = threadState.GetValue((int)threadState.ThreadStack.Pop()); VMValue target = threadState.GetLocalVariable(localVarIndex); DelayedWrite dw = new DelayedWrite(target.GUID, source.GUID, this); dw.SourceInstruction = this; threadState.AddPendingAction(dw); return threadState.CurrentMethod.GetNextInstruction(this); }
public override CILInstruction Execute(ThreadState threadState) { if(CanExecute(threadState) == false) throw new Exception("This add instruction is not ready to execute"); if(threadState.GetValue(threadState.ThreadStack.Peek()) is VMValue_int32) { VMValue_int32 value1 = (VMValue_int32)threadState.GetValue(threadState.ThreadStack.Pop()); VMValue_int32 neg = (VMValue_int32)threadState.SystemState.Values.MakeValue(new CILVar_int32("")); neg.Value = -value1.Value; neg.IsThreadLocal = true; neg.IsConcrete = true; threadState.ThreadStack.Push(neg.GUID); } else if(threadState.GetValue(threadState.ThreadStack.Peek()) is VMValue_double) { VMValue_double value1 = (VMValue_double)threadState.GetValue(threadState.ThreadStack.Pop()); VMValue_double neg = (VMValue_double)threadState.SystemState.Values.MakeValue(new CILVar_double("")); neg.Value = -value1.Value; neg.IsThreadLocal = true; neg.IsConcrete = true; threadState.ThreadStack.Push(neg.GUID); } else if(threadState.GetValue(threadState.ThreadStack.Peek()) is VMValue_int64) { VMValue_int64 value1 = (VMValue_int64)threadState.GetValue(threadState.ThreadStack.Pop()); VMValue_int64 neg = (VMValue_int64)threadState.SystemState.Values.MakeValue(new CILVar_int64("")); neg.Value = -value1.Value; neg.IsThreadLocal = true; neg.IsConcrete = true; threadState.ThreadStack.Push(neg.GUID); } else throw new Exception("Unknown data type on stack for add"); return threadState.CurrentMethod.GetNextInstruction(this); }
public override CILInstruction Execute(ThreadState threadState) { if(CanExecute(threadState) == false) throw new Exception("This add instruction is not ready to execute"); VMValue_int32 value1 = (VMValue_int32)threadState.GetValue(threadState.ThreadStack.Pop()); VMValue_arrayinst arrayInst = threadState.SystemState.Values.MakeArrayInst(value1.Value, elementType); VMValue_array arr = threadState.SystemState.Values.MakeArray(); arr.ArrayInstGuid = arrayInst.GUID; arr.IsConcrete = true; arr.IsThreadLocal = true; threadState.ThreadStack.Push(arr.GUID); return threadState.CurrentMethod.GetNextInstruction(this); }
public override bool CanExecute(ThreadState threadState) { if(ctorSig.Equals("()")) return true; else { int counter = 1; for(int i = 0; i < ctorSig.Length; i++) if(ctorSig[i] == ',') counter++; FreeStack<int> fs = threadState.ThreadStack; for(int i = 1; i <= counter; i++) if(((VMValue)threadState.GetValue(fs[fs.Count - i])).IsConcrete == false) return false; return true; } }
public override bool CanExecute(ThreadState threadState) { VMValue v1 = threadState.GetValue(threadState.ThreadStack.Peek()); return v1.IsConcrete; }
public override bool CanExecute(ThreadState threadState) { // TODO: Can be more relaxed but not important now, check semantic later VMValue v1 = threadState.GetValue(threadState.ThreadStack.Peek()); return v1.IsConcrete; }