Compiler Development Series-Ocelot language 7. intermediate code, compiler-ocelot
Ocelot's intermediate code is designed in accordance with the intermediate code named Tree used in the foreign Compiler-related book Modern Compiler Implementation. As the name suggests, Tree is a Tree structure with simple features and easy conversion to machine language.
For example, the following code:
int main(int argc, char** argv){return ++argc;}
Will be converted into the following intermediate code:
<IR> (G: \ Compilation Principle \ homemade compiler \ source code \ test \ hello_ir.cb: 1) variables: functions: <DefinedFunction> (G: \ Compilation Principle \ homemade compiler \ source code \ test \ hello_ir.cb: 1) name: main isPrivate: false type: int (int, char **) body: <Assign> (G: \ Compilation Principle \ homemade compiler \ source code \ test \ hello_ir.cb: 3) lhs: <Addr> type: INT32 entity: argc rhs: <Bin> type: INT32 op: ADD left: <Var> type: INT32 entity: argc right: <Int> type: INT32 value: 1 <Return> (G: \ Compilation Principle \ homemade compiler \ source code \ test \ hello_ir.cb: 3) expr: <Var> type: INT32 entity: argc
The classes that constitute the intermediate code are shown in table 11.1.
All statement nodes are inherited from the Stmt class, and the expression nodes are inherited from the Expr class.