(** This module defines the abstract syntax tree of [RTL]. *) (* The main differences between RTLabs and RTL is instruction selection. Also, since addresses in 8051 are two words long, the instructions involving addresses use two registers to represent them. *) type registers = Register.t list type statement = (* The empty statement. *) | St_skip of Label.t (* Emit a cost label. *) | St_cost of CostLabel.t * Label.t (* Assign the address of a symbol to registers. Parameters are the destination registers (low bytes first), the symbol and the label of the next statement. *) | St_addr of Register.t * Register.t * AST.ident * Label.t (* Assign the stack pointer to registers. Parameters are the destination registers (low bytes first), and the label of the next statement. *) | St_stackaddr of Register.t * Register.t * Label.t (* Assign an integer constant to a register. Parameters are the destination register, the integer and the label of the next statement. *) | St_int of Register.t * int * Label.t (* Move the content of a register to another. Parameters are the destination register, the source register, and the label of the next statement. *) | St_move of Register.t * Register.t * Label.t (* Apply a binary operation that will later be translated in an operation on the accumulators. Parameters are the operation, the destination registers (ACC first, BACC second), the source registers, and the label of the next statement. *) | St_opaccs of I8051.opaccs * Register.t * Register.t * Register.t * Register.t * Label.t (* Apply an unary operation. Parameters are the operation, the destination register, the source register, and the label of the next statement. *) | St_op1 of I8051.op1 * Register.t * Register.t * Label.t (* Apply a binary operation. Parameters are the operation, the destination register, the source registers, and the label of the next statement. *) | St_op2 of I8051.op2 * Register.t * Register.t * Register.t * Label.t (* Set the carry flag to zero. Parameter is the label of the next statement. *) | St_clear_carry of Label.t (* Set the carry flag to 1. Parameter is the label of the next statement. *) | St_set_carry of Label.t (* Load from external memory. Parameters are the destination register, the address registers (low bytes first), and the label of the next statement. *) | St_load of Register.t * Register.t * Register.t * Label.t (* Store to external memory. Parameters are the address registers (low bytes first), the source register, and the label of the next statement. *) | St_store of Register.t * Register.t * Register.t * Label.t (* Call to a function given its name. Parameters are the name of the function, the arguments of the function, the destination registers, and the label of the next statement. *) | St_call_id of AST.ident * Register.t list * registers * Label.t (* Call to a function given its address. Parameters are the registers holding the address of the function (low bytes first), the arguments of the function, the destination registers, and the label of the next statement. *) | St_call_ptr of Register.t * Register.t * Register.t list * registers * Label.t (* Tail call to a function given its name. Parameters are the name of the function, and the arguments of the function. *) | St_tailcall_id of AST.ident * Register.t list (* Tail call to a function given its address. Parameters are the registers holding the address of the function (low bytes first), and the arguments of the function. *) | St_tailcall_ptr of Register.t * Register.t * Register.t list (* Branch. Parameters are the register holding the value for the branching, the label to go to when the value is not 0, and the label to go to when the value is 0. *) | St_cond of Register.t * Label.t * Label.t (* Return the value of some registers (low bytes first). *) | St_return of registers type graph = statement Label.Map.t type internal_function = { f_luniverse : Label.Gen.universe ; f_runiverse : Register.universe ; f_result : Register.t list (* low byte first *) ; f_params : Register.t list ; f_locals : Register.Set.t ; f_stacksize : int ; f_graph : graph ; f_entry : Label.t ; f_exit : Label.t } type function_def = | F_int of internal_function | F_ext of AST.external_function (* A program is a list of global variables and their reserved space, a list of function names and their definition, and the name of the main function. *) type program = { vars : (AST.ident * int (* size *)) list ; functs : (AST.ident * function_def) list ; main : AST.ident option }