예제 #1
0
        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);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        private void DecompileStates()
        {
            ProcessDescriptor pd = (ProcessDescriptor)_code;

            _templ = new MSILDecompilerTemplate()
            {
                Instance                 = pd.Instance.Owner,
                ArgumentValues           = new object[0],
                Decompilee               = _code,
                Method                   = _code.Method,
                Code                     = MethodCode.Create(_code.Method),
                DisallowReturnStatements = true,
                NestLoopsDeeply          = true,
                TryToEliminateLoops      = true,
                DisallowConditionals     = true
            };
            LocalVariableState initialState = _templ.ExportLocalVariableState();

            GetStateInfo(_dissectionPoints[0], initialState);

            while (_stateWorkQueue.Any())
            {
                StateInfo      si     = _stateWorkQueue.Dequeue();
                MSILDecompiler decomp = new MSILDecompiler(_code, si.CFG, _instance)
                {
                    Template = _templ
                };
                _templ.AddAttribute(this);
                _templ.ImportLocalVariableState(si.LVState);
                IDecompilationResult result = decomp.Decompile();
                si.StateFun = result.Decompiled;
                _calledMethods.AddRange(result.CalledMethods);
                _referencedFields.AddRange(result.ReferencedFields);
            }
        }
예제 #3
0
        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);
        }
예제 #4
0
        public bool AddVerbs(int issuePoint, LocalVariableState lvState, IEnumerable <TAVerb> verbs)
        {
            IEnumerable <Tuple <TAVerb, CoStateInfo> > result;
            var key = Tuple.Create(issuePoint, lvState);

            if (Verbs.TryGetValue(key, out result))
            {
                return(false);
            }

            Verbs[key] = CreateCoStateList(verbs).ToArray();
            return(true);
        }
예제 #5
0
        private StateInfo GetStateInfo(int dissectionPoint, LocalVariableState lvState)
        {
            var       key = Tuple.Create(dissectionPoint, lvState);
            StateInfo result;

            if (!_stateLookup.TryGetValue(key, out result))
            {
                result = new StateInfo()
                {
                    DissectionPoint = dissectionPoint,
                    LVState         = lvState,
                    CFG             = _cfgLookup[dissectionPoint].Single(),
                    StateIndex      = _stateLookup.Keys.Count,
                    StateExpr       = new LazyExpression()
                };
                _stateWorkQueue.Enqueue(result);
                _stateLookup[key] = result;
            }
            return(result);
        }
예제 #6
0
        public Expression GetStateExpression(int ilIndex)
        {
            LocalVariableState lvState = _templ.ExportLocalVariableState();

            return(GetStateInfo(ilIndex, lvState).StateExpr);
        }
예제 #7
0
 public IEnumerable <Tuple <TAVerb, CoStateInfo> > GetVerbs(int issuePoint, LocalVariableState lvState)
 {
     return(Verbs[Tuple.Create(issuePoint, lvState)]);
 }