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

Last change on this file since 740 was 740, checked in by ayache, 9 years ago

New memory model and bug fixes in 8051 branch. Added primitive operations in interpreters from Clight to LIN.

File size: 7.4 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  (* Assign the content of a hardware register to a pseudo register. Parameters
52     are the destination pseudo register, the source hardware register, and the
53     label of the next statement. *)
54  | St_get_hdw of Register.t * I8051.register * Label.t
55
56  (* Assign the content of a pseudo register to a hardware register. Parameters
57     are the destination hardware register, the source pseudo register, and the
58     label of the next statement. *)
59  | St_set_hdw of I8051.register * Register.t * Label.t
60
61  (* Assign the content of a hardware register to a hardware
62     register. Parameters are the destination register, the source register, and
63     the label of the next statement. Only used to save the return value before
64     the epilogue and restore it right before leaving the function. *)
65  | St_hdw_to_hdw of I8051.register * I8051.register * Label.t
66
67  (* Allocate required space on the stack for the function. Parameter is the
68     label of the next statement. *)
69  | St_newframe of Label.t
70
71  (* Deallocate required space on the stack for the function. Parameter is the
72     label of the next statement. *)
73  | St_delframe of Label.t
74
75  (* Assign the frame size to a register. Parameters are the destination
76     register, and the label of the next statement. *)
77  | St_framesize of Register.t * Label.t
78
79  (* Pop a value from the IRAM to a register. Parameter are the destination
80     register, and the label of the next statement. *)
81  | St_pop of Register.t * Label.t
82
83  (* Push a value from a register to the IRAM. Parameter are the source
84     register, and the label of the next statement. *)
85  | St_push of Register.t * Label.t
86
87  (* Assign the most significant bits of the address of a symbol to a
88     register. Parameters are the destination register, the symbol and the label
89     of the next statement. *)
90  | St_addrH of Register.t * AST.ident * Label.t
91
92  (* Assign the least significant bits of the address of a symbol to a
93     register. Parameters are the destination register, the symbol and the label
94     of the next statement. *)
95  | St_addrL of Register.t * AST.ident * Label.t
96
97  (* Assign an integer constant to a register. Parameters are the destination
98     register, the integer and the label of the next statement. *)
99  | St_int of Register.t * int * Label.t
100
101  (* Move the content of a register to another. Parameters are the destination
102     register, the source register, and the label of the next statement. *)
103  | St_move of Register.t * Register.t * Label.t
104
105  (* Apply a binary operation that will later be translated in an operation on
106     the accumulators. Parameters are the operation, the destination register,
107     the source registers, and the label of the next statement. *)
108  | St_opaccs of I8051.opaccs * Register.t * Register.t * Register.t * Label.t
109
110  (* Apply an unary operation. Parameters are the operation, the destination
111     register, the source register, and the label of the next statement. *)
112  | St_op1 of I8051.op1 * Register.t * Register.t * Label.t
113
114  (* Apply a binary operation. Parameters are the operation, the destination
115     register, the source registers, and the label of the next statement. *)
116  | St_op2 of I8051.op2 * Register.t * Register.t * Register.t * Label.t
117
118  (* Set the carry flag to zero. Parameter is the label of the next
119     statement. *)
120  | St_clear_carry of Label.t
121
122  (* Load from external memory. Parameters are the destination register, the
123     address registers (low bytes first), and the label of the next
124     statement. *)
125  | St_load of Register.t * Register.t * Register.t * Label.t
126
127  (* Store to external memory. Parameters are the address registers (low bytes
128     first), the source register, and the label of the next statement. *)
129  | St_store of Register.t * Register.t * Register.t * Label.t
130
131  (* Call to a function given its name. Parameters are the name of the function,
132     the number of arguments of the function, and the label of the next
133     statement. *)
134  | St_call_id of AST.ident * int * Label.t
135
136(*
137  (* Call to a function given its address. Parameters are registers holding the
138     address of the function, the arguments of the function, the destination
139     registers, and the label of the next statement. *)
140  | St_call_ptr of registers * register list * registers * Label.t
141
142  (* Tail call to a function given its name. Parameters are the name of the
143     function, and the number of arguments of the function. *)
144  | St_tailcall_id of AST.ident * int
145
146  (* Tail call to a function given its address. Parameters are registers holding
147     the address of the function, and the arguments of the function. *)
148  | St_tailcall_ptr of registers * register list
149*)
150
151  (* Branch. Parameters are the register holding the value for the branching,
152     the label to go to when the value is not 0, and the label to go to when the
153     value is 0. *)
154  | St_condacc of Register.t * Label.t * Label.t
155
156  (* Transfer control to the address stored in the return address registers. *)
157  | St_return of registers
158
159type graph = statement Label.Map.t
160
161type internal_function =
162    { f_luniverse : Label.Gen.universe ;
163      f_runiverse : Register.universe ;
164      f_params    : int ;
165      f_locals    : Register.Set.t ;
166      f_stacksize : int ;
167      f_graph     : graph ;
168      f_entry     : Label.t ;
169      f_exit      : Label.t }
170
171type function_def =
172  | F_int of internal_function
173  | F_ext of AST.external_function
174
175(* A program is a list of global variables and their reserved space, a list of
176   function names and their definition, and the name of the main function. *)
177
178type program =
179    { vars   : (AST.ident * int (* size *)) list ;
180      functs : (AST.ident * function_def) list ;
181      main   : AST.ident option }
Note: See TracBrowser for help on using the repository browser.