Download IR Tree Language: Compiler Course Representation by Jingke Li, PSU - Prof. Jingke Li and more Exams Computer Science in PDF only on Docsity! The IR Tree Language (for CS321/322 compiler courses) Jingke Li Dept. of Computer Science Portland State University (version 1.0 s’06) For our MINI compiler, we use a tree intermediate representation, which is a modified version from Andrew Appel’s IR Tree Langauage given in the textbook. 1 IR Tree Nodes The IR Tree Language has the following nodes: EXP: BINOP(binop, EXP, EXP) EXP: CALL(EXP, EXPlist) EXP: MEM(EXP) EXP: NAME(String) EXP: TEMP(int) EXP: PARAM(int) EXP: VAR(int) EXP: CONST(int) EXP: STRING(String) EXP: ESEQ(STMT, EXP) EXP: EXPlist() STMT: MOVE(EXP, EXP) STMT: JUMP(EXP) STMT: CJUMP(relop, EXP, EXP, EXP) STMT: LABEL(EXP) STMT: CALLST(EXP, EXPlist) STMT: RETURN(EXP) STMT: STMTlist() FUNC: FUNC(String, int, int, STMTlist) FUNClist: FUNClist() PROG: PROG(FUNClist) binop: + - * / && || (&& and || are bitwise ops) relop: == != < <= > >= 1.1 Expressions EXP: BINOP(int binop, EXP left, EXP right) Binary operation. binop is a pre-defined integer code representing one of the following ops: + = * / && ||. 1 EXP: CALL(NAME func, EXPList args) A function call (i.e. a call to a method that returns a value). The argument list args is evaluated and are passed to the function, whose address is given by func. The function returns a result, which is the result of the CALL expression. All arguments are passed by value. EXP: MEM(EXP exp) Fetch from an address in memory. exp represents the address. EXP: NAME(String label) EXP: NAME() Represent a symbolic label, which is typically used as the target of a jump statement. If called without an argument, an unique new label will be created. EXP: TEMP(int num) EXP: TEMP() Represent a temp (symbolic register). num is the temp number. If called without an argument, a new temp will be created. EXP: PARAM(int idx) A parameter of a method. idx is the index number, representing the relative position of the parameter in the parameter list; the first parameter has an index of 1. EXP: VAR(int idx) A local variable of a method. idx is the index number, representing the relative position of the variable in the declaration section; the first variable has an index of 1. EXP: CONST(int val) An integer constant. EXP: ESEQ(STMT stmt, EXP exp) Enforce an order: stmt is evaluated, then exp is evaluated. The value of the ESEQ node are that of exp. EXP: EXPlist() A list of expressions. It is only used to represent the argument list of a CALL or CALLST node. It’s value (which is defined to to the value of the last expression in the list) is never used. 1.2 Statements STMT: MOVE(EXP dst, EXP src) Store a value to an address in memory or to a temp. dst must be an MEM node or a TEMP node; src is the value. STMT: JUMP(NAME target) A jump to a fixed label. target must be a NAME node. 2