1

I am using the ObjectWeb ASM library found here to parse jar files and read the bytecode of methods. I have already written code to generate a control flow graph from the bytecode instruction lists.

However, after I perform some operations on the control flow graph I want to be able to "export" the control flow graph back to a (simple) list of instructions. In theory, I should be able to iterate through all of the basic blocks and print out the instructions that are stored in each one. However, doing this will most likely result in the instructions being in a very bizarre order because there is no ordering to the list of basic blocks.

I have read that forming a "dominator tree" can help figure out the best (most logical) ordering of the basic blocks. I'm not sure how to calculate the dominator tree and how to use it to sort the basic blocks.

Does anyone have any knowledge on this topic that they could share?

Thanks.

Bradley Odell
  • 1,248
  • 2
  • 15
  • 28
  • a trick way: the first and the last basic block can't change their position when you write them. The rest of basic block can have whatever order only if each block has an edge or two or more to their next basic block [set]. The problem is that there are block that its next basic block is below it, and then if you move the block, now its next block(the new below) can be another, and the program might crash. Thats why i recommend you to put a unconditional jump between blocks that has fallthrough edge. In other way, a good reference of dominators trees is in Compiler,Principles... 2nd Edition – Jordy Baylac Nov 30 '15 at 19:52

0 Answers0