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

Last change on this file since 1572 was 1572, checked in by tranquil, 8 years ago
  • corrected previous bug
  • finished propagating immediates
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 argument = RTL.argument
41
42type statement =
43
44  (* The empty statement. *)
45  | St_skip of Label.t
46
47  (* Comment. *)
48  | St_comment of string * Label.t
49
50  (* Emit a cost label. *)
51  | St_cost of CostLabel.t * Label.t
52
53  (* Reset to 0 a loop index *) 
54  | St_ind_0 of CostLabel.index * Label.t
55
56  (* Increment a loop index *)
57  | St_ind_inc of CostLabel.index * Label.t
58
59  (* Assign the content of a hardware register to a pseudo register. Parameters
60     are the destination pseudo register, the source hardware register, and the
61     label of the next statement. *)
62  | St_get_hdw of Register.t * I8051.register * Label.t
63
64  (* Assign the content of a pseudo register to a hardware register. Parameters
65     are the destination hardware register, the source pseudo register, and the
66     label of the next statement. *)
67  | St_set_hdw of I8051.register * argument * Label.t
68
69  (* Assign the content of a hardware register to a hardware
70     register. Parameters are the destination register, the source register, and
71     the label of the next statement. Only used to save the return value before
72     the epilogue and restore it right before leaving the function. *)
73  | St_hdw_to_hdw of I8051.register * I8051.register * Label.t
74
75  (* Allocate required space on the stack for the function. Parameter is the
76     label of the next statement. *)
77  | St_newframe of Label.t
78
79  (* Deallocate required space on the stack for the function. Parameter is the
80     label of the next statement. *)
81  | St_delframe of Label.t
82
83  (* Assign the frame size to a register. Parameters are the destination
84     register, and the label of the next statement. *)
85  | St_framesize of Register.t * Label.t
86
87  (* Pop a value from the IRAM to a register. Parameter are the destination
88     register, and the label of the next statement. *)
89  | St_pop of Register.t * Label.t
90
91  (* Push a value from a register to the IRAM. Parameter are the source
92     register, and the label of the next statement. *)
93  | St_push of argument * Label.t
94
95  (* Assign the most significant bits of the address of a symbol to a
96     register. Parameters are the destination register, the symbol and the label
97     of the next statement. *)
98  | St_addrH of Register.t * AST.ident * Label.t
99
100  (* Assign the least significant bits of the address of a symbol to a
101     register. Parameters are the destination register, the symbol and the label
102     of the next statement. *)
103  | St_addrL of Register.t * AST.ident * Label.t
104
105  (* (\* Assign an integer constant to a register. Parameters are the destination *)
106  (*    register, the integer and the label of the next statement. *\) *)
107  (* | St_int of Register.t * int * Label.t *)
108
109  (* Move the content of a register to another. Parameters are the destination
110     register, the source register, and the label of the next statement. *)
111  | St_move of Register.t * argument * Label.t
112
113  (* Apply a binary operation that will later be translated in an operation on
114     the accumulators, keeping only the result in ACC. Parameters are the
115     operation, the destination register, the source registers, and the label of
116     the next statement. *)
117  | St_opaccsA of I8051.opaccs * Register.t * argument * argument * Label.t
118
119  (* Apply a binary operation that will later be translated in an operation on
120     the accumulators, keeping only the result in BACC. Parameters are the
121     operation, the destination register, the source registers, and the label of
122     the next statement. *)
123  | St_opaccsB of I8051.opaccs * Register.t * argument * argument * Label.t
124
125  (* Apply an unary operation. Parameters are the operation, the destination
126     register, the source register, and the label of the next statement. *)
127  | St_op1 of I8051.op1 * Register.t * Register.t * Label.t
128
129  (* Apply a binary operation. Parameters are the operation, the destination
130     register, the source registers, and the label of the next statement. *)
131  | St_op2 of I8051.op2 * Register.t * argument * argument * Label.t
132
133  (* Set the carry flag to zero. Parameter is the label of the next
134     statement. *)
135  | St_clear_carry of Label.t
136
137  (* Set the carry flag to 1. Parameter is the label of the next statement. *)
138  | St_set_carry of Label.t
139
140  (* Load from external memory. Parameters are the destination register, the
141     address registers (low bytes first), and the label of the next
142     statement. *)
143  | St_load of Register.t * argument * argument * Label.t
144
145  (* Store to external memory. Parameters are the address registers (low bytes
146     first), the source register, and the label of the next statement. *)
147  | St_store of argument * argument * argument * Label.t
148
149  (* Call to a function given its name. Parameters are the name of the function,
150     the number of arguments of the function, and the label of the next
151     statement. *)
152  | St_call_id of AST.ident * int * Label.t
153
154  (* Call to a function given its address. Parameters are the registers holding
155     the address of the function, the number of arguments of the function, and
156     the label of the next statement. *)
157  | St_call_ptr of Register.t * Register.t * int * Label.t
158
159(*
160  (* Tail call to a function given its name. Parameters are the name of the
161    function, and the number of arguments of the function. *)
162  | St_tailcall_id of AST.ident * int
163
164  (* Tail call to a function given its address. Parameters are registers holding
165     the address of the function, and the arguments of the function. *)
166  | St_tailcall_ptr of registers * register list
167*)
168
169  (* Branch. Parameters are the register holding the value for the branching,
170     the label to go to when the value is not 0, and the label to go to when the
171     value is 0. *)
172  | St_cond of Register.t * Label.t * Label.t
173
174  (* Transfer control to the address stored in the return address registers. *)
175  | St_return of argument list
176
177type graph = statement Label.Map.t
178
179type internal_function =
180    { f_luniverse : Label.Gen.universe ;
181      f_runiverse : Register.universe ;
182      f_params    : int ;
183      f_locals    : Register.Set.t ;
184      f_stacksize : int ;
185      f_graph     : graph ;
186      f_entry     : Label.t ;
187      f_exit      : Label.t }
188
189type function_def =
190  | F_int of internal_function
191  | F_ext of AST.external_function
192
193(* A program is a list of global variables and their reserved space, a list of
194   function names and their definition, and the name of the main function. *)
195
196type program =
197    { vars   : (AST.ident * int (* size *)) list ;
198      functs : (AST.ident * function_def) list ;
199      main   : AST.ident option }
Note: See TracBrowser for help on using the repository browser.