} // Take care of one extra conj. private static Ast.expr DisjunctAll(List <Ast.expr> transitions) { Ast.expr[] disjunctions = transitions.ToArray(); Ast.expr alldisjuncted = disjunctions[0]; for (int i = 1; i < disjunctions.Length; i++) { alldisjuncted = Ast.expr.NewOr(alldisjuncted, disjunctions[i]); } return(alldisjuncted); }
private static Ast.expr ConjuctAll(List <Ast.expr> transitions) { Ast.expr[] conjuctions = transitions.ToArray(); Ast.expr allconjucted = conjuctions[0]; for (int i = 1; i < conjuctions.Length; i++) { allconjucted = Ast.expr.NewAnd(allconjucted, conjuctions[i]); } return(allconjucted); } // Take care of one extra conj.
private static Ast.smv_module CreateTimeModule(string name) { List <Tuple <string, Tuple <Int64, Int64> > > vars; List <Tuple <string, Ast.types> > varwithtpyes; Ast.expr init; Ast.expr transrel; Ast.expr resetident = Ast.expr.NewIdent("reset"); List <string> parameters = new List <string>(); List <Ast.section> secs = new List <Ast.section>(); // vars = TimerVars(); varwithtpyes = ConvertRngTupleToTypes(vars); init = TimerInit(vars); transrel = TimerTransitions(vars, resetident); Debug.Assert(transrel != null); // Create sections Ast.section trans = Ast.section.NewTrans(transrel); Ast.section inits = Ast.section.NewInit(init); Ast.section varbls = Ast.section.NewVar(FSharpInteropExtensions.ToFSharplist <Tuple <string, Ast.types> >(varwithtpyes)); // Dirty conversions Microsoft.FSharp.Collections.FSharpList <Ast.section> sections = FSharpInteropExtensions.ToFSharplist <Ast.section>(secs); Microsoft.FSharp.Collections.FSharpList <string> pars = FSharpInteropExtensions.ToFSharplist <string>(parameters); // Create module Ast.smv_module timermodule = new Ast.smv_module(name, pars, sections); //Fill memory representation //Trans List <Ast.expr> transrels = new List <Ast.expr>(); transrels.Add(transrel); _trans.Add(timermodule, transrels); //init List <Ast.expr> initials = new List <Ast.expr>(); initials.Add(init); _init.Add(timermodule, initials); //params _params.Add(timermodule, parameters); //vars _rvars.Add(timermodule, vars); //_mvars _mvars.Add(timermodule, new List <Tuple <string, Tuple <string, List <List <string> > > > >()); //_svars _svars.Add(timermodule, new List <Tuple <string, List <string> > >()); //iassigns _iassigns.Add(timermodule, new List <Tuple <string, Ast.expr> >()); //nassigns _nassigns.Add(timermodule, new List <Tuple <string, Ast.expr> >()); return(timermodule); }
private static Ast.expr TimerInit(List <Tuple <string, Tuple <Int64, Int64> > > variables) { List <Ast.expr> identifiers = new List <Ast.expr>(); foreach (var v in variables) { Ast.expr varident = Ast.expr.NewIdent(v.Item1); Ast.expr valident = Ast.expr.NewInt(v.Item2.Item1); Ast.expr valvareqident = Ast.expr.NewEq(varident, valident); identifiers.Add(valvareqident); } return(ConjuctAll(identifiers)); //return identifiers; }
private static Tuple <Ast.section, Tuple <List <Tuple <string, Ast.expr> >, List <Tuple <string, Ast.expr> > > > ClockAssigns(List <Tuple <string, Tuple <Int64, Int64> > > variables) { List <Tuple <string, Ast.expr> > stringexprlstinit = new List <Tuple <string, Ast.expr> >(); List <Tuple <string, Ast.expr> > stringexprlstnext = new List <Tuple <string, Ast.expr> >(); Ast.expr clockindent = Ast.expr.NewInt(_clockbound); Ast.expr timerident = Ast.expr.NewIdent("time"); Ast.expr inctimerident = Ast.expr.NewAdd(timerident, Ast.expr.NewInt(1)); Ast.expr truident = Ast.expr.NewIdent("TRUE"); Ast.expr zeroident = Ast.expr.NewInt(0); Ast.expr guard = Ast.expr.NewLt(timerident, Ast.expr.NewInt(_clockbound)); // init Ast.assign initident = Ast.assign.NewInitAssign("time", zeroident); // next List <Tuple <Ast.expr, Ast.expr> > caseslst = new List <Tuple <Ast.expr, Ast.expr> >(); Tuple <Ast.expr, Ast.expr> guardcs = new Tuple <Ast.expr, Ast.expr>(guard, inctimerident); caseslst.Add(guardcs); stringexprlstinit.Add(new Tuple <string, Ast.expr>("time", zeroident)); Tuple <Ast.expr, Ast.expr> trucs = new Tuple <Ast.expr, Ast.expr>(truident, timerident); caseslst.Add(trucs); Ast.expr caseident = Ast.expr.NewCases(FSharpInteropExtensions.ToFSharplist <Tuple <Ast.expr, Ast.expr> >(caseslst)); Ast.assign nextident = Ast.assign.NewNextAssign("time", caseident); stringexprlstnext.Add(new Tuple <string, Ast.expr>("time", caseident)); List <Ast.assign> assignlst = new List <Ast.assign>(); assignlst.Add(initident); assignlst.Add(nextident); Ast.section assignsec = Ast.section.NewAssigns(FSharpInteropExtensions.ToFSharplist <Ast.assign>(assignlst)); Tuple <Ast.section, Tuple <List <Tuple <string, Ast.expr> >, List <Tuple <string, Ast.expr> > > > sectionwithmemoryvalues = new Tuple <Ast.section, Tuple <List <Tuple <string, Ast.expr> >, List <Tuple <string, Ast.expr> > > > (assignsec, new Tuple <List <Tuple <string, Ast.expr> >, List <Tuple <string, Ast.expr> > >(stringexprlstinit, stringexprlstnext)); return(sectionwithmemoryvalues); }
private static void IntroduceAsyncBound() { int counter = 0; foreach (var modl in _modules) { if (_bmodules.ContainsKey(modl)) { if (modl.name == "main") { // foreach variable in bounded variable set of this module is constructor and needs to be introduced with parameter List <List <string> > timervarlist = new List <List <string> >(); Tuple <string, List <List <string> > > timerconstvartupl = new Tuple <string, List <List <string> > >("timer", timervarlist); Tuple <string, Tuple <string, List <List <string> > > > timerident = new Tuple <string, Tuple <string, List <List <string> > > >("t", timerconstvartupl); _mvars[modl].Add(timerident); List <List <string> > clockvarlist = new List <List <string> >(); Tuple <string, List <List <string> > > clockconstvartupl = new Tuple <string, List <List <string> > >("clock", clockvarlist); Tuple <string, Tuple <string, List <List <string> > > > clockident = new Tuple <string, Tuple <string, List <List <string> > > >("c", clockconstvartupl); _mvars[modl].Add(clockident); foreach (var boundvar in _bmodules[modl]) { foreach (var mvar in _mvars[modl]) { if (boundvar == mvar.Item1) { if (mvar.Item2.Item1 == "clock") { List <string> mtimervar = new List <string>(); mtimervar.Add("t"); mtimervar.Add("reset"); mvar.Item2.Item2.Add(mtimervar); } else { if (mvar.Item2.Item1 == "Anchorcell") { List <string> mtimervar = new List <string>(); mtimervar.Add("t"); mtimervar.Add("reset"); mvar.Item2.Item2.Add(mtimervar); } else { if (mvar.Item2.Item1 == "VPC") { List <string> mtimervar = new List <string>(); List <string> clockvar = new List <string>(); Debug.Assert(counter < _nthread); clockvar.Add("c"); clockvar.Add("time"); mvar.Item2.Item2.Add(clockvar); mtimervar.Add("t"); mtimervar.Add("var" + counter.ToString()); mvar.Item2.Item2.Add(mtimervar); counter++; } } } } } } } else { //Modify clock // put timerparameter to module's declaration if (modl.name == "clock") { _params[modl].Add("reset"); Ast.expr rst = Ast.expr.NewIdent("reset"); Ast.expr resetident = Ast.expr.NewEq(rst, Ast.expr.NewInt(1)); //Ast.expr resetnident = Ast.expr.NewNext(rst); //Ast.expr resetnidenttru = Ast.expr.NewEq(resetnident, Ast.expr.NewInt(1)); //Ast.expr takestep = Ast.expr.NewAnd(resetident, resetnidenttru); for (int i = 0; i < _nassigns[modl].Count; i++) { Ast.expr.Cases nassign = _nassigns[modl][i].Item2 as Ast.expr.Cases; Debug.Assert(nassign.IsCases); List <Tuple <Ast.expr, Ast.expr> > caselist = new List <Tuple <Ast.expr, Ast.expr> >(); for (int j = 0; j < nassign.Item.Length; j++) { if (nassign.Item[j].Item1.ToString() != "TRUE") { Ast.expr asyncupdated = Ast.expr.NewAnd(resetident, nassign.Item[j].Item1); FSharpList <Tuple <Ast.expr, Ast.expr> > exprlst = FSharpInteropExtensions.ToFSharplist <Tuple <Ast.expr, Ast.expr> >(nassign.Item); caselist.Add(new Tuple <Ast.expr, Ast.expr>(asyncupdated, exprlst[j].Item2)); } else { Ast.expr asyncupdated = nassign.Item[j].Item1; FSharpList <Tuple <Ast.expr, Ast.expr> > exprlst = FSharpInteropExtensions.ToFSharplist <Tuple <Ast.expr, Ast.expr> >(nassign.Item); caselist.Add(new Tuple <Ast.expr, Ast.expr>(asyncupdated, exprlst[j].Item2)); } } Tuple <string, Ast.expr> asyncupdatedassign = new Tuple <string, Ast.expr>(_nassigns[modl][i].Item1, Ast.expr.NewCases(FSharpInteropExtensions.ToFSharplist <Tuple <Ast.expr, Ast.expr> >(caselist))); _nassigns[modl][i] = asyncupdatedassign; } } else { if (modl.name == "Anchorcell") { _params[modl].Add("reset"); Ast.expr rst = Ast.expr.NewIdent("reset"); Ast.expr resetident = Ast.expr.NewEq(rst, Ast.expr.NewInt(0)); Ast.expr resetnident = Ast.expr.NewNext(rst); Ast.expr resetnidenttru = Ast.expr.NewEq(resetnident, Ast.expr.NewInt(1)); Ast.expr takestep = Ast.expr.NewAnd(resetident, resetnidenttru); for (int i = 0; i < _nassigns[modl].Count; i++) { Ast.expr.Cases nassign = _nassigns[modl][i].Item2 as Ast.expr.Cases; Debug.Assert(nassign.IsCases); List <Tuple <Ast.expr, Ast.expr> > caselist = new List <Tuple <Ast.expr, Ast.expr> >(); for (int j = 0; j < nassign.Item.Length; j++) { if (nassign.Item[j].Item1.ToString() != "TRUE") { Ast.expr asyncupdated = Ast.expr.NewAnd(takestep, nassign.Item[j].Item1); FSharpList <Tuple <Ast.expr, Ast.expr> > exprlst = FSharpInteropExtensions.ToFSharplist <Tuple <Ast.expr, Ast.expr> >(nassign.Item); caselist.Add(new Tuple <Ast.expr, Ast.expr>(asyncupdated, exprlst[j].Item2)); } else { Ast.expr asyncupdated = nassign.Item[j].Item1; FSharpList <Tuple <Ast.expr, Ast.expr> > exprlst = FSharpInteropExtensions.ToFSharplist <Tuple <Ast.expr, Ast.expr> >(nassign.Item); caselist.Add(new Tuple <Ast.expr, Ast.expr>(asyncupdated, exprlst[j].Item2)); } } Tuple <string, Ast.expr> asyncupdatedassign = new Tuple <string, Ast.expr>(_nassigns[modl][i].Item1, Ast.expr.NewCases(FSharpInteropExtensions.ToFSharplist <Tuple <Ast.expr, Ast.expr> >(caselist))); _nassigns[modl][i] = asyncupdatedassign; } } else { _params[modl].Add("time"); _params[modl].Add("t"); string asyncboundparam = _params[modl][_params[modl].Count - 1]; Ast.expr asyncident = Ast.expr.NewIdent(asyncboundparam); Ast.expr nasyncindent = Ast.expr.NewNext(asyncident); Ast.expr takestep = Ast.expr.NewLt(asyncident, nasyncindent); // foreach bounded variable belongs to this module need to be introduce with async bound in their next assignments for (int i = 0; i < _nassigns[modl].Count; i++) { Ast.expr.Cases nassign = _nassigns[modl][i].Item2 as Ast.expr.Cases; Debug.Assert(nassign.IsCases); List <Tuple <Ast.expr, Ast.expr> > caselist = new List <Tuple <Ast.expr, Ast.expr> >(); for (int j = 0; j < nassign.Item.Length; j++) { if (nassign.Item[j].Item1.ToString() != "TRUE") { Ast.expr asyncupdated = Ast.expr.NewAnd(takestep, nassign.Item[j].Item1); FSharpList <Tuple <Ast.expr, Ast.expr> > exprlst = FSharpInteropExtensions.ToFSharplist <Tuple <Ast.expr, Ast.expr> >(nassign.Item); caselist.Add(new Tuple <Ast.expr, Ast.expr>(asyncupdated, exprlst[j].Item2)); } else { Ast.expr asyncupdated = nassign.Item[j].Item1; FSharpList <Tuple <Ast.expr, Ast.expr> > exprlst = FSharpInteropExtensions.ToFSharplist <Tuple <Ast.expr, Ast.expr> >(nassign.Item); caselist.Add(new Tuple <Ast.expr, Ast.expr>(asyncupdated, exprlst[j].Item2)); } } Tuple <string, Ast.expr> asyncupdatedassign = new Tuple <string, Ast.expr>(_nassigns[modl][i].Item1, Ast.expr.NewCases(FSharpInteropExtensions.ToFSharplist <Tuple <Ast.expr, Ast.expr> >(caselist))); _nassigns[modl][i] = asyncupdatedassign; } } } } } } }
/*Framework: * //TR1. forall var:variable :: var == asyncbound && !reset --> next(var) == var * //TR2. forall var:variable :: var == asyncbound && reset --> next(var)=0 * //TR3. forall var:variable :: next(var) == asyncbound --> next(reset) * //TR4. exists var:variable :: next(var) != asyncbound --> !next(reset) * //TR5. forall var: variables : next(var) != var * //TR6. forall var:variables :: var < asyncbound --> next(var) = var+1 | next(var) = var */ private static Ast.expr TimerTransitions(List <Tuple <string, Tuple <Int64, Int64> > > variables, Ast.expr resetident) { List <Ast.expr> transrel = new List <Ast.expr>(); List <Ast.expr> transrel1 = new List <Ast.expr>(); List <Ast.expr> transrel2 = new List <Ast.expr>(); List <Ast.expr> transrel3 = new List <Ast.expr>(); List <Ast.expr> transrel4 = new List <Ast.expr>(); List <Ast.expr> transrel5 = new List <Ast.expr>(); List <Ast.expr> transrel6 = new List <Ast.expr>(); List <Ast.expr> varident = new List <Ast.expr>(); List <Ast.expr> resetidents = new List <Ast.expr>(); Ast.expr asyncbndident = Ast.expr.NewInt(_asyncbound); foreach (var v in variables) { if (v.Item1 != "reset") { varident.Add(Ast.expr.NewIdent(v.Item1)); } else { resetident = Ast.expr.NewIdent(v.Item1); } } //TR1 foreach (Ast.expr vident in varident) { transrel1.Add(Ast.expr.NewImp(Ast.expr.NewAnd(Ast.expr.NewEq(vident, asyncbndident), Ast.expr.NewEq(resetident, Ast.expr.NewInt(0))), Ast.expr.NewEq(vident, Ast.expr.NewNext(vident)))); } transrel.Add(ConjuctAll(transrel1)); // transrel.Add(transrel1); //TR2 foreach (Ast.expr vident in varident) { transrel2.Add(Ast.expr.NewImp(Ast.expr.NewAnd(Ast.expr.NewEq(vident, asyncbndident), Ast.expr.NewEq(resetident, Ast.expr.NewInt(1))), Ast.expr.NewEq(Ast.expr.NewNext(vident), Ast.expr.NewInt(0)))); } transrel.Add(ConjuctAll(transrel2)); //TR3 // transrel.Add(transrel2); // collect all variables = asyncbound List <Ast.expr> allvreachedbound = new List <Ast.expr>(); foreach (Ast.expr vident in varident) { allvreachedbound.Add(Ast.expr.NewEq(Ast.expr.NewNext(vident), asyncbndident)); } Ast.expr allconjucted = ConjuctAll(allvreachedbound); //foreach (Ast.expr vident in varident) //{ transrel3.Add(Ast.expr.NewImp(allconjucted, Ast.expr.NewEq(Ast.expr.NewNext(resetident), Ast.expr.NewInt(1)))); //} transrel.Add(ConjuctAll(transrel3)); // transrel.Add(transrel3); //TR4 List <Ast.expr> allvnotreachedbound = new List <Ast.expr>(); foreach (Ast.expr vident in varident) { allvnotreachedbound.Add(Ast.expr.NewEq(Ast.expr.NewNext(vident), asyncbndident)); } Ast.expr allnconjucted = ConjuctAll(allvnotreachedbound); Ast.expr notreached = Ast.expr.NewNot(allnconjucted); //foreach (Ast.expr vident in varident) //{ transrel4.Add(Ast.expr.NewImp(notreached, Ast.expr.NewEq(Ast.expr.NewNext(resetident), Ast.expr.NewInt(0)))); //} transrel.Add(ConjuctAll(transrel4)); //TR5 foreach (Ast.expr vident in varident) { transrel5.Add(Ast.expr.NewNeq(Ast.expr.NewNext(vident), vident)); } transrel.Add(DisjunctAll(transrel5)); //TR6 foreach (Ast.expr vident in varident) { transrel6.Add(Ast.expr.NewImp(Ast.expr.NewLt(vident, asyncbndident), Ast.expr.NewOr(Ast.expr.NewEq(Ast.expr.NewNext(vident), Ast.expr.NewAdd(vident, Ast.expr.NewInt(1))), Ast.expr.NewEq(Ast.expr.NewNext(vident), vident)))); } transrel.Add(ConjuctAll(transrel6)); return(ConjuctAll(transrel)); }