private void AddCoStates(int issuePoint, LocalVariableState lvState, IEnumerable <TAVerb> states) { Contract.Requires(states != null); TAVerb first = states.First(); CoFSMInfo cfi = _coFSMs[first.Target]; if (cfi.AddVerbs(issuePoint, lvState, states)) { foreach (var tup in cfi.GetVerbs(issuePoint, lvState)) { TAVerb tav = tup.Item1; CoStateInfo csi = tup.Item2; if (csi.StateAction == null) { InitCoState(tav, csi); if (tav.During != null) { foreach (AbstractEvent ev in tav.During.Sensitivity) { cfi.Sensitivity.Add(((SignalBase)ev.Owner).Descriptor); } } } } } }
public void ImplementCoState(int issuePoint, IEnumerable <TAVerb> states, int step, IFunctionBuilder builder) { LocalVariableState lvState = _templ.ExportLocalVariableState(); AddCoStates(issuePoint, lvState, states); TAVerb first = states.First(); CoFSMInfo cfi = _coFSMs[first.Target]; var tup = cfi.GetVerbs(issuePoint, lvState).ElementAt(step); CoStateInfo csi = tup.Item2; ImplementCoStateAction(cfi, csi, builder); }
private void ImplementCoStateAction(CoFSMInfo cfi, CoStateInfo csi, IFunctionBuilder builder) { builder.InlineCall(csi.StateAction, new Expression[0], new Variable[0], true); builder.Store(cfi.NextCoState, csi.StateExpr); /* * CoStateInfo next = csi.Next; * if (next == null && cfi.HasNeutralTA) * next = cfi.FirstNeutral; * if (next != null) * { * builder.Store(cfi.NextCoState, next.StateExpr); * } * */ }
private void InitCoState(TAVerb tav, CoStateInfo csi) { MethodCode csc = MethodCode.Create(tav.Op.Method); MethodDescriptor md = new MethodDescriptor(tav.Op.Method, new object[0], new EVariability[0]); MSILDecompiler decomp = new MSILDecompiler(md, csc, tav.Op.Target); decomp.Template.DisallowReturnStatements = true; decomp.Template.NestLoopsDeeply = true; decomp.Template.TryToEliminateLoops = true; decomp.Template.DisallowConditionals = true; IDecompilationResult result = decomp.Decompile(); csi.StateAction = result.Decompiled; csi.DuringAction = tav.During; }
protected override void DeclareAlgorithm() { SignalRef curState = new SignalRef(_cfi.CoStateSignal.Desc, SignalRef.EReferencedProperty.Cur); CaseStatement cs = Switch(curState); { for (int i = 0; i < _cfi.TotalStates; i++) { CoStateInfo csi = _cfi.StateInfos[i]; object stateValue = csi.StateValue; Case(LiteralReference.CreateConstant(stateValue)); { if (csi.DuringAction != null) { csi.DuringAction.Implement(this); } } Break(cs); } } EndSwitch(); }
private IEnumerable <Tuple <TAVerb, CoStateInfo> > CreateCoStateList(IEnumerable <TAVerb> verbs) { CoStateInfo prev = null; foreach (TAVerb coState in verbs) { CoStateInfo next = new CoStateInfo(); if (prev != null) { prev.Next = next; } else { FirstStateInfos.Add(next); } StateInfos.Add(next); prev = next; next.StateIndex = TotalStates++; next.StateExpr = new LazyExpression(); yield return(Tuple.Create(coState, next)); } }
protected override void DeclareAlgorithm() { Dissect(); Initialize(); InitializeCoFSMs(); DecompileStates(); CreateStateValues(); CreateCoStateValues(); SignalRef curState = new SignalRef(_stateSignal.Desc, SignalRef.EReferencedProperty.Cur); ProcessDescriptor pd = (ProcessDescriptor)_code; Func <bool> predFunc = pd.Instance.Predicate; LiteralReference predInstRef = LiteralReference.CreateConstant(predFunc.Target); StackElement arg = new StackElement(predInstRef, predFunc.Target, EVariability.ExternVariable); Expression cond = _templ.GetCallExpression(predFunc.Method, arg).Expr; Expression[] e0 = new Expression[0]; Variable[] v0 = new Variable[0]; If(cond); { foreach (var kvp in _coFSMs) { CoFSMInfo cfi = kvp.Value; SignalRef srCor = new SignalRef(cfi.CoStateSignal.Desc, SignalRef.EReferencedProperty.Cur); Expression lrCo = new LiteralReference(srCor); CaseStatement csc = Switch(lrCo); { for (int i = 0; i < cfi.TotalStates; i++) { CoStateInfo csi = cfi.StateInfos[i]; Expression stateValue = LiteralReference.CreateConstant(csi.StateValue); CoStateInfo csin = csi.Next; if (csin == null && cfi.HasNeutralTA) { csin = cfi.FirstNeutral; } Case(stateValue); { if (csin != null) { ImplementCoStateAction(cfi, csin, this); } Break(csc); } EndCase(); } } EndSwitch(); } CaseStatement cs = Switch(curState); { IEnumerable <StateInfo> states = _stateLookup.Values.OrderBy(si => si.StateIndex); foreach (StateInfo state in states) { Case(state.StateExpr.PlaceHolder); { InlineCall(state.StateFun, e0, v0, true); Break(cs); } EndCase(); } } EndSwitch(); } EndIf(); }