public static void DoSplitBlocksIntoAssignmentsAndPredicates(ControlFlowGraph cfg)
        {
            cfg.Vertices.ForEach(v =>
            {
                if (v.BalancedCode.IsEmpty() || v.Residue.IsEmpty()) return;

                var ass = (v.BalancedCode.Last() is Assign) ? v.BalancedCode.Last().AssertCast<Assign>() : null;
                var lhs = ass == null ? null : ass.Lhs.AssertCast<Ref>().Sym;
                var @ref = v.Residue.AssertSingle() is Ref ? v.Residue.AssertSingle().AssertCast<Ref>().Sym : null;
                if (lhs != null && @ref != null && lhs.ProtoId == @ref.ProtoId)
                {
                    // todo. this introduces a nasty bug if assigned variable is reused later
                    v.BalancedCode.RemoveLast();
                    v.Residue.SetElements(ass.Rhs);
                }

                if (v.BalancedCode.IsEmpty() || v.Residue.IsEmpty()) return;

                var v_test = new ControlFlowBlock();
                v_test.Residue.Add(v.Residue.AssertSingle());
                v.Residue.RemoveElements();

                var outEdges = cfg.Vedges(v, null);
                cfg.RemoveEdges(outEdges);

                cfg.AddVertex(v_test);
                cfg.AddEdge(new ControlFlowEdge(v, v_test));
                outEdges.ForEach(e => cfg.AddEdge(new ControlFlowEdge(v_test, e.Target, e.Tag)));
            });
        }
Exemple #2
0
        public ViewOfControlFlowGraph CreateEigenFinish()
        {
            _finish.AssertNull();
            var eigenFinish = new ControlFlowBlock().SetName("finish");

            AddEigenVertex(eigenFinish);
            _finish = eigenFinish;
            return(this);
        }
Exemple #3
0
        public Offspring(IScope neighborScope, ControlFlowBlock root, ControlFlowBlock head)
        {
            Scope = neighborScope;
            Root = root;
            Head = head;

            CalculateBodyAndPivots();
            InitializeControlFlowGraph();
        }
Exemple #4
0
        public ViewOfControlFlowGraph CreateEigenStart()
        {
            _start.AssertNull();
            var eigenStart = new ControlFlowBlock().SetName("start");

            AddEigenVertex(eigenStart);
            _start = eigenStart;
            return(this);
        }
Exemple #5
0
 public ViewOfControlFlowGraph InheritFinish(ControlFlowBlock finish)
 {
     _finish.AssertNull();
     if (!_vertices.Contains(finish))
     {
         AddEigenVertex(finish);
     }
     _finish = finish.AssertNotNull();
     return(this);
 }
Exemple #6
0
 public ViewOfControlFlowGraph InheritStart(ControlFlowBlock start)
 {
     _start.AssertNull();
     if (!_vertices.Contains(start))
     {
         AddEigenVertex(start);
     }
     _start = start.AssertNotNull();
     return(this);
 }
        public ControlFlowGraph(BaseControlFlowGraph proto, bool deep)
            : base(proto, deep)
        {
            _start = proto.Start;
            _finish = proto.Finish;

            _allTimeVertexCounter = __vertices.Count();
            if (_start == null) _allTimeVertexCounter++;
            if (_finish == null) _allTimeVertexCounter++;
            HookUpVertexPostprocessors();
        }
Exemple #8
0
 public bool AddEigenVertex(ControlFlowBlock v)
 {
     if (_vertices.Contains(v))
     {
         _eigenVertices.Contains(v).AssertTrue();
         return(false);
     }
     else
     {
         _eigenVertices.Add(v);
         OnVertexAdded(v);
         return(true);
     }
 }
        public ControlFlowGraph(BaseControlFlowGraph proto, bool deep)
            : base(proto, deep)
        {
            _start  = proto.Start;
            _finish = proto.Finish;

            _allTimeVertexCounter = __vertices.Count();
            if (_start == null)
            {
                _allTimeVertexCounter++;
            }
            if (_finish == null)
            {
                _allTimeVertexCounter++;
            }
            HookUpVertexPostprocessors();
        }
 public bool AddEigenVertex(ControlFlowBlock v)
 {
     if (_vertices.Contains(v))
     {
         _eigenVertices.Contains(v).AssertTrue();
         return false;
     }
     else
     {
         _eigenVertices.Add(v);
         OnVertexAdded(v);
         return true;
     }
 }
 public ControlFlowGraph()
 {
     HookUpVertexPostprocessors();
     AddVertex(_start  = new ControlFlowBlock());
     AddVertex(_finish = new ControlFlowBlock());
 }
 public ViewOfControlFlowGraph InheritFinish(ControlFlowBlock finish)
 {
     _finish.AssertNull();
     if (!_vertices.Contains(finish)) AddEigenVertex(finish);
     _finish = finish.AssertNotNull();
     return this;
 }
 public ViewOfControlFlowGraph InheritStartAndFinish(ControlFlowBlock start, ControlFlowBlock finish)
 {
     InheritStart(start);
     InheritFinish(finish);
     return this;
 }
 public ViewOfControlFlowGraph CreateEigenFinish()
 {
     _finish.AssertNull();
     var eigenFinish = new ControlFlowBlock().SetName("finish");
     AddEigenVertex(eigenFinish);
     _finish = eigenFinish;
     return this;
 }
 public ViewOfControlFlowGraph InheritStart(ControlFlowBlock start)
 {
     _start.AssertNull();
     if (!_vertices.Contains(start)) AddEigenVertex(start);
     _start = start.AssertNotNull();
     return this;
 }
 public ViewOfControlFlowGraph CreateEigenStart()
 {
     _start.AssertNull();
     var eigenStart = new ControlFlowBlock().SetName("start");
     AddEigenVertex(eigenStart);
     _start = eigenStart;
     return this;
 }
Exemple #17
0
 public ViewOfControlFlowGraph InheritStartAndFinish(ControlFlowBlock start, ControlFlowBlock finish)
 {
     InheritStart(start);
     InheritFinish(finish);
     return(this);
 }
 public ControlFlowGraph()
 {
     HookUpVertexPostprocessors();
     AddVertex(_start = new ControlFlowBlock());
     AddVertex(_finish = new ControlFlowBlock());
 }
 private InitialDecompilation(ControlFlowBlock block, ReadOnlyCollection<IILOp> cil, Symbols symbols)
 {
     _block = block;
     _cil = cil;
     _symbols = symbols;
 }
 public static void DoPrimaryDecompilation(ControlFlowBlock block, ReadOnlyCollection<IILOp> cil, Symbols symbols) { new InitialDecompilation(block, cil, symbols).DoPrimaryDecompilation(); }