public PrtInterfaceValue CreateInterfaceOrMachine(string currMachRenameName, string interfaceOrMachineName, PrtValue payload) { //add visible action to trace if (visibleInterfaces.Contains(interfaceOrMachineName)) { currentVisibleTrace.AddAction(interfaceOrMachineName, payload.ToString()); } var renamedImpMachine = linkMap[currMachRenameName][interfaceOrMachineName]; var impMachineName = renameMap[renamedImpMachine]; var machine = createMachineMap[impMachineName](this, payload); machine.isSafe = isSafeMap[renamedImpMachine]; machine.renamedName = renamedImpMachine; AddImplMachineToStateImpl(machine); CreateMachineCallback?.Invoke(machine); if (interfaceMap.ContainsKey(interfaceOrMachineName)) { return(new PrtInterfaceValue(machine, interfaceMap[interfaceOrMachineName])); } else { return(new PrtInterfaceValue(machine, machine.self.permissions)); } }
public PrtInterfaceValue CreateInterface(PrtImplMachine currMach, string interfaceOrMachineName, PrtValue payload) { //add visible action to trace if (visibleInterfaces.Contains(interfaceOrMachineName)) { currentVisibleTrace.AddAction(interfaceOrMachineName, payload.ToString()); } var renamedImpMachine = linkMap[currMach.renamedName][interfaceOrMachineName]; var impMachineName = machineDefMap[renamedImpMachine]; var machine = createMachineMap[impMachineName](this, payload); machine.isSafe = isSafeMap[renamedImpMachine]; machine.renamedName = renamedImpMachine; AddImplMachineToStateImpl(machine); CreateMachineCallback?.Invoke(machine); //TraceLine("<CreateLog> Machine {0}-{1} was created by machine {2}-{3}", currMach.renamedName, currMach.instanceNumber, machine.renamedName, machine.instanceNumber); TraceLine("<CreateLog> Machine {0}-{1} was created by machine {2}-{3}", machine.renamedName, machine.instanceNumber, currMach.renamedName, currMach.instanceNumber); if (interfaceMap.ContainsKey(interfaceOrMachineName)) { return(new PrtInterfaceValue(machine, interfaceMap[interfaceOrMachineName])); } else { return(new PrtInterfaceValue(machine, machine.self.permissions)); } }
public string ToPrettyString(string indent = "") { string result = ""; result += indent + "renamedName: " + renamedName + "\n"; result += indent + "isSafe: " + isSafe.ToString() + "\n"; result += indent + "instanceNumber: " + instanceNumber.ToString() + "\n"; result += indent + "fields: " + (fields.Count == 0 ? "null" : fields.Select(v => v.ToString()).Aggregate((s1, s2) => s1 + "," + s2)) + "\n"; result += indent + "eventValue: " + eventValue.ToString() + "\n"; result += indent + "stateStack: " + stateStack.ToString() + "\n"; result += indent + "invertedFunStack: " + invertedFunStack.ToString() + "\n"; result += indent + "continuation: " + continuation.ToString() + "\n"; result += indent + "currentStatus: " + currentStatus.ToString() + "\n"; result += indent + "nextSMOperation: " + nextSMOperation.ToString() + "\n"; result += indent + "stateExitReason: " + stateExitReason.ToString() + "\n"; result += indent + "currentTrigger: " + currentTrigger.ToString() + "\n"; result += indent + "currentPayload: " + currentPayload.ToString() + "\n"; result += indent + "destOfGoto: " + (destOfGoto == null ? "null" : destOfGoto.ToString()) + "\n"; return(result); }
public override void PrtEnqueueEvent(PrtValue e, PrtValue arg, PrtMachine source, PrtMachineValue target = null) { PrtEventValue ev = e as PrtEventValue; if (ev.evt.name == "null") { throw new PrtIllegalEnqueueException("Enqueued event must not be null"); } //check if the sent event is in source send set if (!source.sends.Contains(e as PrtEventValue)) { throw new PrtIllegalEnqueueException(String.Format("Machine <0> cannot send event {1}", source.Name, e.ToString())); } //check if the sent event is in target permissions if (target is PrtInterfaceValue) { if (!(target as PrtInterfaceValue).permissions.Contains(e as PrtEventValue)) { throw new PrtIllegalEnqueueException(String.Format("Event {1} is not in the permission set of the target", e.ToString())); } } PrtType prtType = ev.evt.payloadType; //assertion to check if argument passed inhabits the payload type. if (prtType is PrtNullType) { if (!arg.Equals(PrtValue.@null)) { throw new PrtIllegalEnqueueException("Did not expect a payload value"); } } else if (!PrtValue.PrtInhabitsType(arg, prtType)) { throw new PrtInhabitsTypeException(String.Format("Payload <{0}> does not match the expected type <{1}> with event <{2}>", arg.ToString(), prtType.ToString(), ev.evt.name)); } //check if the event sent is in the permissions if (currentStatus == PrtMachineStatus.Halted) { stateImpl.Trace( @"<EnqueueLog> {0}-{1} Machine has been halted and Event {2} is dropped", this.Name, this.instanceNumber, ev.evt.name); } else { stateImpl.Trace( @"<EnqueueLog> Enqueued Event <{0}, {1}> in {2}-{3} by {4}-{5}", ev.evt.name, arg.ToString(), this.Name, this.instanceNumber, source.Name, source.instanceNumber); this.eventQueue.EnqueueEvent(e, arg); if (this.maxBufferSize != DefaultMaxBufferSize && this.eventQueue.Size() > this.maxBufferSize) { if (this.doAssume) { throw new PrtAssumeFailureException(); } else { throw new PrtMaxBufferSizeExceededException( String.Format(@"<EXCEPTION> Event Buffer Size Exceeded {0} in Machine {1}-{2}", this.maxBufferSize, this.Name, this.instanceNumber)); } } if (currentStatus == PrtMachineStatus.Blocked && this.eventQueue.IsEnabled(this)) { currentStatus = PrtMachineStatus.Enabled; } } //Announce it to all the spec machines stateImpl.Announce(e as PrtEventValue, arg, source); }
public void Announce(PrtEventValue ev, PrtValue payload, PrtMachine parent) { if (ev.Equals(PrtValue.@null)) { throw new PrtIllegalEnqueueException("Enqueued event must not be null"); } PrtType prtType = ev.evt.payloadType; //assertion to check if argument passed inhabits the payload type. if (prtType is PrtNullType) { if (!payload.Equals(PrtValue.@null)) { throw new PrtIllegalEnqueueException("Did not expect a payload value"); } } else if (!PrtValue.PrtInhabitsType(payload, prtType)) { throw new PrtInhabitsTypeException(String.Format("Payload <{0}> does not match the expected type <{1}> with event <{2}>", payload.ToString(), prtType.ToString(), ev.evt.name)); } var allSpecMachines = GetSpecMachines(parent.renamedName); foreach (var mon in allSpecMachines) { if (mon.observes.Contains(ev)) { TraceLine("<AnnounceLog> Enqueued Event <{0}, {1}> to Spec Machine {2}", ev, payload, mon.Name); mon.PrtEnqueueEvent(ev, payload, parent); } } }
public SendAction(Tuple <string, int> t, string e, PrtValue v) { target = new Tuple <string, int>(t.Item1, t.Item2); ev = e; payload = v.ToString(); }
public PrtValue Lookup(PrtValue key) { if (!Contains(key)) { throw new PrtAssertFailureException(string.Format("Illegal key ({0}) in Lookup", key.ToString())); } return(keyToValueMap[new PrtMapKey(key, 0)]); }
public static PrtValue PrtCastValue(PrtValue value, PrtType type) { if (!PrtInhabitsType(value, type)) { throw new PrtInhabitsTypeException(String.Format("value {0} is not a member of type {1}", value.ToString(), type.ToString())); } return(value.Clone()); }
public static PrtValue PrtCastValue(PrtValue value, PrtType type) { //cast for interface types is implemented as reduce. if (type is PrtInterfaceType) { return((type as PrtInterfaceType).PrtReduceValue(value)); } else { if (!PrtInhabitsType(value, type)) { throw new PrtInhabitsTypeException(String.Format("value {0} is not a member of type {1}", value.ToString(), type.ToString())); } return(value.Clone()); } }
public bool PrtPopState(bool isPopStatement) { Debug.Assert(stateStack.TopOfStack != null); //pop stack stateStack.PopStackFrame(); if (stateStack.TopOfStack == null) { if (isPopStatement) { throw new PrtInvalidPopStatement(); } //TODO : Handle the spec machine case separately for the halt event else if (!eventValue.Equals(PrtValue.halt)) { throw new PrtUnhandledEventException(string.Format("{0} failed to handle {1}", Name, eventValue.ToString())); } else { stateImpl.TraceLine("<HaltLog> Machine {0}-{1} HALTED", this.Name, this.instanceNumber); currentStatus = PrtMachineStatus.Halted; } } return(currentStatus == PrtMachineStatus.Halted); }
public override string ToString() { return("(" + ev.ToString() + "," + arg.ToString() + ")"); // not including senderMachine data since the image (successor) relation doesn't depend on them }
// I Print the Boolean nondet before the List retLocals (easier since list length varies) public override string ToString() { return(reason.ToString() + "," + retVal.ToString() + "," + nondet.ToString() + "," + (retLocals.Count == 0 ? "null" : retLocals.Select(v => v.ToString()).Aggregate((s1, s2) => s1 + s2))); }
public PrtValue PrtReduceValue(PrtValue value) { if (value == PrtValue.@null) { return(value.Clone()); } else if (value is PrtMachineValue) { return(new PrtInterfaceValue(((PrtMachineValue)value).mach, permissions)); } else if (value is PrtInterfaceValue) { if (permissions == null) { throw new PrtInternalException("Unexpected value of permissions in Interface Type"); } var iVal = value as PrtInterfaceValue; //permissions in iVal is all events if (iVal.permissions == null) { return(new PrtInterfaceValue(iVal.mach, permissions)); } //type_permissions is subset of value_permissions if (permissions.Where(ev => !iVal.permissions.Contains(ev)).Count() > 0) { throw new PrtInhabitsTypeException(String.Format("value {0} cannot be reduced to value of type {1}", value.ToString(), this.ToString())); } else { return(new PrtInterfaceValue(iVal.mach, permissions)); } } else { throw new PrtInhabitsTypeException(String.Format("value {0} cannot be reduced to value of type {1}", value.ToString(), this.ToString())); } }
public bool PrtPopState(bool isPopStatement) { Debug.Assert(stateStack.TopOfStack != null); //pop stack stateStack.PopStackFrame(); if (stateStack.TopOfStack == null) { if (isPopStatement) { throw new PrtInvalidPopStatement(); } //TODO : Handle the spec machine case separately for the halt event else if (!eventValue.Equals(PrtValue.halt)) { throw new PrtUnhandledEventException(string.Format("{0} failed to handle event {1}", Name, eventValue.ToString())); } else { if (this as PrtImplMachine != null) { stateImpl.TraceLine("<HaltLog> Machine {0}-{1} HALTED with {2} events in the queue", this.Name, this.instanceNumber, (((PrtImplMachine)this).eventQueue).Size()); } else { //SpecMachine case: //TODO: is it possible to send "halt" event to a spec machine? stateImpl.TraceLine("<HaltLog> Machine {0}-{1} HALTED", this.Name, this.instanceNumber); } currentStatus = PrtMachineStatus.Halted; } } return(currentStatus == PrtMachineStatus.Halted); }