31-10-2012, 04:50 PM
Intermediate Code Generation
Intermediate Code.ppt (Size: 92 KB / Downloads: 33)
Intermediate codes are machine independent codes, but they are close to machine instructions.
The given program in a source language is converted to an equivalent program in an intermediate language by the intermediate code generator.
Intermediate language can be many different languages, and the designer of the compiler decides this intermediate language.
syntax trees can be used as an intermediate language.
postfix notation can be used as an intermediate language.
three-address code (Quadraples) can be used as an intermediate language
we will use quadraples to discuss intermediate code generation
quadraples are close to machine instructions, but they are not actual machine instructions.
some programming languages have well defined intermediate languages.
java – java virtual machine
prolog – warren abstract machine
In fact, there are byte-code emulators to execute instructions in these intermediate languages.
Nested Procedure Declarations
For each procedure we should create a symbol table.
mktable(previous) – create a new symbol table where previous is the parent symbol table of this new symbol table
enter(symtable,name,type,offset) – create a new entry for a variable in the given symbol table.
enterproc(symtable,name,newsymbtable) – create a new entry for the procedure in the symbol table of its parent.
addwidth(symtable,width) – puts the total width of all entries in the symbol table into the header of that table.
We will have two stacks:
tblptr – to hold the pointers to the symbol tables
offset – to hold the current offsets in the symbol tables in tblptr stack.