source: Deliverables/D2.2/8051/src/ERTL/ERTL.mli @ 1542

Last change on this file since 1542 was 1542, checked in by tranquil, 8 years ago

merge of indexed labels branch

File size: 8.0 KB
Line 
1
2(** This module defines the abstract syntax tree of [RTL]. *)
3
4(* Adapted from Pottiers's Pseudo-Pascal pedagogical compiler *)
5
6(* This is the definition of the abstract syntax for the Explicit
7   Register Transfer Language (ERTL).
8
9   This language is very much like RTL, except the calling convention
10   has been made explicit. That is, functions and procedures no longer
11   accept parameters and return results via a high-level mechanism;
12   instead, they do so via either hardware registers or stack
13   slots.
14
15   Functions and procedures no longer magically return to their caller: instead,
16   a new [St_return] instruction appears, whose semantics is to transfer control
17   to the address stored in the return address registers.
18
19   Functions and procedures are no longer explicitly distinguished: functions
20   are simply procedures that happen to write the hardware register. There only
21   remains a distinction at [St_return] instructions (see below).
22
23   Two new instructions, [St_newframe] and [St_delframe], appear in order to
24   allocate and release stack frames. They will be translated, in the final
25   assembly code, to arithmetic on the stack pointer registers. *)
26
27(* Stack organization.
28
29   The stack is going from top to bottom. Below is a schema of the stack
30   organization viewed by the function being executed.
31
32                    formal parameters (the first parameter is at the top)
33                    spilled variables (the first spilled variable is a the top)
34                    local variables (the first local variable is at the bottom)
35   stack pointer ->
36*)
37
38type registers = Register.t list
39
40type statement =
41
42  (* The empty statement. *)
43  | St_skip of Label.t
44
45  (* Comment. *)
46  | St_comment of string * Label.t
47
48  (* Emit a cost label. *)
49  | St_cost of CostLabel.t * Label.t
50
51  (* Reset to 0 a loop index *) 
52  | St_ind_0 of CostLabel.index * Label.t
53
54  (* Increment a loop index *)
55  | St_ind_inc of CostLabel.index * Label.t
56
57  (* Assign the content of a hardware register to a pseudo register. Parameters
58     are the destination pseudo register, the source hardware register, and the
59     label of the next statement. *)
60  | St_get_hdw of Register.t * I8051.register * Label.t
61
62  (* Assign the content of a pseudo register to a hardware register. Parameters
63     are the destination hardware register, the source pseudo register, and the
64     label of the next statement. *)
65  | St_set_hdw of I8051.register * Register.t * Label.t
66
67  (* Assign the content of a hardware register to a hardware
68     register. Parameters are the destination register, the source register, and
69     the label of the next statement. Only used to save the return value before
70     the epilogue and restore it right before leaving the function. *)
71  | St_hdw_to_hdw of I8051.register * I8051.register * Label.t
72
73  (* Allocate required space on the stack for the function. Parameter is the
74     label of the next statement. *)
75  | St_newframe of Label.t
76
77  (* Deallocate required space on the stack for the function. Parameter is the
78     label of the next statement. *)
79  | St_delframe of Label.t
80
81  (* Assign the frame size to a register. Parameters are the destination
82     register, and the label of the next statement. *)
83  | St_framesize of Register.t * Label.t
84
85  (* Pop a value from the IRAM to a register. Parameter are the destination
86     register, and the label of the next statement. *)
87  | St_pop of Register.t * Label.t
88
89  (* Push a value from a register to the IRAM. Parameter are the source
90     register, and the label of the next statement. *)
91  | St_push of Register.t * Label.t
92
93  (* Assign the most significant bits of the address of a symbol to a
94     register. Parameters are the destination register, the symbol and the label
95     of the next statement. *)
96  | St_addrH of Register.t * AST.ident * Label.t
97
98  (* Assign the least significant bits of the address of a symbol to a
99     register. Parameters are the destination register, the symbol and the label
100     of the next statement. *)
101  | St_addrL of Register.t * AST.ident * Label.t
102
103  (* Assign an integer constant to a register. Parameters are the destination
104     register, the integer and the label of the next statement. *)
105  | St_int of Register.t * int * Label.t
106
107  (* Move the content of a register to another. Parameters are the destination
108     register, the source register, and the label of the next statement. *)
109  | St_move of Register.t * Register.t * Label.t
110
111  (* Apply a binary operation that will later be translated in an operation on
112     the accumulators, keeping only the result in ACC. Parameters are the
113     operation, the destination register, the source registers, and the label of
114     the next statement. *)
115  | St_opaccsA of I8051.opaccs * Register.t * Register.t * Register.t * Label.t
116
117  (* Apply a binary operation that will later be translated in an operation on
118     the accumulators, keeping only the result in BACC. Parameters are the
119     operation, the destination register, the source registers, and the label of
120     the next statement. *)
121  | St_opaccsB of I8051.opaccs * Register.t * Register.t * Register.t * Label.t
122
123  (* Apply an unary operation. Parameters are the operation, the destination
124     register, the source register, and the label of the next statement. *)
125  | St_op1 of I8051.op1 * Register.t * Register.t * Label.t
126
127  (* Apply a binary operation. Parameters are the operation, the destination
128     register, the source registers, and the label of the next statement. *)
129  | St_op2 of I8051.op2 * Register.t * Register.t * Register.t * Label.t
130
131  (* Set the carry flag to zero. Parameter is the label of the next
132     statement. *)
133  | St_clear_carry of Label.t
134
135  (* Set the carry flag to 1. Parameter is the label of the next statement. *)
136  | St_set_carry of Label.t
137
138  (* Load from external memory. Parameters are the destination register, the
139     address registers (low bytes first), and the label of the next
140     statement. *)
141  | St_load of Register.t * Register.t * Register.t * Label.t
142
143  (* Store to external memory. Parameters are the address registers (low bytes
144     first), the source register, and the label of the next statement. *)
145  | St_store of Register.t * Register.t * Register.t * Label.t
146
147  (* Call to a function given its name. Parameters are the name of the function,
148     the number of arguments of the function, and the label of the next
149     statement. *)
150  | St_call_id of AST.ident * int * Label.t
151
152  (* Call to a function given its address. Parameters are the registers holding
153     the address of the function, the number of arguments of the function, and
154     the label of the next statement. *)
155  | St_call_ptr of Register.t * Register.t * int * Label.t
156
157(*
158  (* Tail call to a function given its name. Parameters are the name of the
159    function, and the number of arguments of the function. *)
160  | St_tailcall_id of AST.ident * int
161
162  (* Tail call to a function given its address. Parameters are registers holding
163     the address of the function, and the arguments of the function. *)
164  | St_tailcall_ptr of registers * register list
165*)
166
167  (* Branch. Parameters are the register holding the value for the branching,
168     the label to go to when the value is not 0, and the label to go to when the
169     value is 0. *)
170  | St_cond of Register.t * Label.t * Label.t
171
172  (* Transfer control to the address stored in the return address registers. *)
173  | St_return of registers
174
175type graph = statement Label.Map.t
176
177type internal_function =
178    { f_luniverse : Label.Gen.universe ;
179      f_runiverse : Register.universe ;
180      f_params    : int ;
181      f_locals    : Register.Set.t ;
182      f_stacksize : int ;
183      f_graph     : graph ;
184      f_entry     : Label.t ;
185      f_exit      : Label.t }
186
187type function_def =
188  | F_int of internal_function
189  | F_ext of AST.external_function
190
191(* A program is a list of global variables and their reserved space, a list of
192   function names and their definition, and the name of the main function. *)
193
194type program =
195    { vars   : (AST.ident * int (* size *)) list ;
196      functs : (AST.ident * function_def) list ;
197      main   : AST.ident option }
Note: See TracBrowser for help on using the repository browser.