Hi, I generate code using a single instruction list for the method. The generated code structure follows the norms outlined in just about any book on compiler design.
The "trick" with BCEL is to define branch labels. These are inserted as NOP's in the methods instruction list. Branch instructions that you emit have the NOP associated with a branch label as the target. Having generated the method code you then call the removeNOPs() method that BCEL provides. This removes all the branch label NOP's and fixes up the branches to reference the next instruction after the NOP. My BCEL code generator uses a visitor pattern to traverse an AST generated by my compiler front end. I was very tempted to get each method in the visitor to create an instruction list for it's own code and to return that to it's parent method. The parent would then insert the childs code at the appropriate place in it's instruction list. I think this would give a very neat solution. At the time I was concerned about the robustness of BCEL. I felt it may have short comings and so went for the most conservative solution. Now that I'm familiar with BCEL I would use the nested list approach without any hesitation. Cheers Steve, --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
