Converting intermediate code to Jzero bytecode
The Jzero intermediate code generator from Chapter 9, Intermediate Code Generation, traversed a tree and created a list of intermediate code as a synthesized attribute in each tree node, named icode
. The intermediate code for the whole program is the icode
attribute in the root node of the syntax tree. In this section, we will use this list to produce our output bytecode. To generate bytecode, the gencode()
method in the j0
class calls a new method in this class, named bytecode()
, and passes it the intermediate code in root.icode
as its input. The Unicon gencode()
method that invokes this functionality in j0.icn
looks like the following code block. The two highlighted lines at the end of the following code snippet are added for bytecode generation, verified by simple text output:
method gencode(root)
root.genfirst()
root.genfollow()
root.gentargets()
root.gencode()
labeltable := table()
bcode...