2 (** This module defines the abstract syntax tree of [RTL]. *)
4 (* The main differences between RTLabs and RTL is instruction selection.
6 Also, since addresses in 8051 are two words long, the instructions involving
7 addresses use two registers to represent them. *)
9 type registers = Register.t list
13 (* The empty statement. *)
16 (* Emit a cost label. *)
17 | St_cost of CostLabel.t * Label.t
19 (* Assign the address of a symbol to registers. Parameters are the destination
20 registers (low bytes first), the symbol and the label of the next
22 | St_addr of Register.t * Register.t * AST.ident * Label.t
24 (* Assign the stack pointer to registers. Parameters are the destination
25 registers (low bytes first), and the label of the next statement. *)
26 | St_stackaddr of Register.t * Register.t * Label.t
28 (* Assign an integer constant to a register. Parameters are the destination
29 register, the integer and the label of the next statement. *)
30 | St_int of Register.t * int * Label.t
32 (* Move the content of a register to another. Parameters are the destination
33 register, the source register, and the label of the next statement. *)
34 | St_move of Register.t * Register.t * Label.t
36 (* Apply a binary operation that will later be translated in an operation on
37 the accumulators. Parameters are the operation, the destination registers
38 (ACC first, BACC second), the source registers, and the label of the next
40 | St_opaccs of I8051.opaccs * Register.t * Register.t *
41 Register.t * Register.t * Label.t
43 (* Apply an unary operation. Parameters are the operation, the destination
44 register, the source register, and the label of the next statement. *)
45 | St_op1 of I8051.op1 * Register.t * Register.t * Label.t
47 (* Apply a binary operation. Parameters are the operation, the destination
48 register, the source registers, and the label of the next statement. *)
49 | St_op2 of I8051.op2 * Register.t * Register.t * Register.t * Label.t
51 (* Set the carry flag to zero. Parameter is the label of the next
53 | St_clear_carry of Label.t
55 (* Set the carry flag to 1. Parameter is the label of the next statement. *)
56 | St_set_carry of Label.t
58 (* Load from external memory. Parameters are the destination register, the
59 address registers (low bytes first), and the label of the next
61 | St_load of Register.t * Register.t * Register.t * Label.t
63 (* Store to external memory. Parameters are the address registers (low bytes
64 first), the source register, and the label of the next statement. *)
65 | St_store of Register.t * Register.t * Register.t * Label.t
67 (* Call to a function given its name. Parameters are the name of the function,
68 the arguments of the function, the destination registers, and the label of
69 the next statement. *)
70 | St_call_id of AST.ident * Register.t list * registers * Label.t
72 (* Call to a function given its address. Parameters are the registers holding
73 the address of the function (low bytes first), the arguments of the
74 function, the destination registers, and the label of the next
76 | St_call_ptr of Register.t * Register.t * Register.t list * registers *
79 (* Tail call to a function given its name. Parameters are the name of the
80 function, and the arguments of the function. *)
81 | St_tailcall_id of AST.ident * Register.t list
83 (* Tail call to a function given its address. Parameters are the registers
84 holding the address of the function (low bytes first), and the arguments of
86 | St_tailcall_ptr of Register.t * Register.t * Register.t list
88 (* Branch. Parameters are the register holding the value for the branching,
89 the label to go to when the value is not 0, and the label to go to when the
91 | St_cond of Register.t * Label.t * Label.t
93 (* Return the value of some registers (low bytes first). *)
94 | St_return of registers
97 type graph = statement Label.Map.t
99 type internal_function =
100 { f_luniverse : Label.Gen.universe ;
101 f_runiverse : Register.universe ;
102 f_result : Register.t list (* low byte first *) ;
103 f_params : Register.t list ;
104 f_locals : Register.Set.t ;
111 | F_int of internal_function
112 | F_ext of AST.external_function
114 (* A program is a list of global variables and their reserved space, a list of
115 function names and their definition, and the name of the main function. *)
118 { vars : (AST.ident * int (* size *)) list ;
119 functs : (AST.ident * function_def) list ;
120 main : AST.ident option }