computer science - How to generate a Control Flow Graph from Assembly? -


for context, i'm attempting write decompiler avm2 (actionscript virtual machine 2) bytecode/assembly high-level actionscript 3 code. far aware, requires me analyze assembly , generate resulting control flow graph this, in order deduce structures such loops, , conditional branching (if/else).

given assembly like:

0         getlocal0          1         pushscope          2         findpropstrict    {, private, }::trace 4         pushstring        "one" 6         callproperty      {, private, }::trace (1) 9         pop                10        pushbyte          5 12        pushbyte          3 14        ifngt             l1  18        findpropstrict    {, private, }::trace 20        pushstring        "two" 22        callproperty      {, private, }::trace (1) 25        pop                 l1:  26        findpropstrict    {, private, }::trace 28        pushstring        "three" 30        callproperty      {, private, }::trace (1) 33        coerce_a           34        setlocal1          35        getlocal1          36        returnvalue        37        kill              1 

what algorithm generate control flow graph?

i figured out. basically, keep list of labels (which in case indices instructions in array). each list of instructions between labels blocks (which vertices in graph). label instruction after each branch (so branch last instruction of block, way can figure out kind of edge is. alternatively, tag on branch type edge.), , target of each branch.

once have labels, split them blocks. loop through each sorted index in labels , if last block's last instruction branch, add edge target. if not, add edge current block (as fall-through node).


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -