source: Deliverables/D2.2/8051/src/RTLabs/RTLabs.mli @ 486

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

Deliverable D2.2

File size: 6.0 KB
RevLine 
[486]1
2(** This module defines the abstract syntax tree of [RTLabs]. *)
3
4(* A program in RTLabs associates to each function of the program a
5   Control Flow Graph. Pseudo-registers are used to represent the
6   variables. The operations and instructions of the language are
7   those of Cminor.
8
9   RTLabs is the last language of the frontend. It is intended to
10   ease retargetting. *)
11
12
13(* From the RTLabs point of view, a pseudo-register can represent a physical
14   location or a pointer. When instruction selection is over, a pseudo-register
15   represents a physical location. Thus, some operations --- those on pointers
16   --- may involve several pseudo-registers when a pointer value is more than
17   one physical location (which is the case of the 8051). *)
18
19type registers = Register.t list
20
21
22(* The following type represents the possible addresses to load from or store to
23   memory. *)
24
25type addressing =
26
27  (* Address is r1 + offset *)
28  | Aindexed of AST.immediate
29
30  (* Address is r1 + r2 *)
31  | Aindexed2
32
33  (* Address is symbol + offset *)
34  | Aglobal of AST.ident * AST.immediate
35
36  (* Address is symbol + offset + r1 *)
37  | Abased of AST.ident * AST.immediate
38
39  (* Address is stack_pointer + offset *)
40  | Ainstack of AST.immediate
41
42
43(* A function in RTLabs is a mapping from labels to
44   statements. Statements explicitely mention their successors. *)
45
46type statement =
47
48  (* The empty statement. *)
49  | St_skip of Label.t
50
51  (* Emit a cost label. *)
52  | St_cost of CostLabel.t * Label.t
53
54  (* Assign a constant to registers. Parameters are the destination registers,
55     the constant and the label of the next statement. *)
56  | St_cst of registers * AST.cst * Label.t
57
58  (* Application of an unary operation. Parameters are the operation, the
59     destination registers, the argument registers and the label of the next
60     statement. *)
61  | St_op1 of AST.op1 * registers * registers * Label.t
62
63  (* Application of a binary operation. Parameters are the operation, the
64     destination register, the argument registers and the label of the next
65     statement. *)
66  | St_op2 of AST.op2 * registers * registers * registers * Label.t
67
68  (* Memory load. Parameters are the size and type of what to load,
69     the addressing mode and its arguments, the destination register
70     and the label of the next statement. *)
71  | St_load of Memory.memory_q * addressing * registers list *
72               registers * Label.t
73
74  (* Memory store. Parameters are the size and type of what to store,
75     the addressing mode and its arguments, the source register
76     and the label of the next statement. *)
77  | St_store of Memory.memory_q * addressing * registers list *
78                registers * Label.t
79
80  (* Call to a function given its name. Parameters are the name of the
81     function, the arguments of the function, the destination
82     registers, the signature of the function and the label of the next
83     statement. *)
84  | St_call_id of AST.ident * registers list * registers *
85                  AST.signature * Label.t
86
87  (* Call to a function given its address. Parameters are registers
88     holding the address of the function, the arguments of the
89     function, the destination registers, the signature of the function
90     and the label of the next statement. This statement with an
91     [St_op] before can represent a [St_call_id]. However, we
92     differenciate the two to allow translation to a formalism with no
93     function pointer. *)
94  | St_call_ptr of registers * registers list * registers *
95                   AST.signature * Label.t
96
97  (* Tail call to a function given its name. Parameters are the name
98     of the function, the arguments of the function, the destination
99     register, the signature of the function and the label of the next
100     statement. *)
101  | St_tailcall_id of AST.ident * registers list * AST.signature
102
103  (* Tail call to a function given its address. Parameters are a
104     register holding the address of the function, the arguments of
105     the function, the destination register, the signature of the
106     function and the label of the next statement. Same remark as for
107     the [St_call_ptr]. *)
108  | St_tailcall_ptr of registers * registers list * AST.signature
109
110  (* Constant branch. Parameters are the constant, the label to go to when the
111     constant evaluates to true (not 0), and the label to go to when the
112     constant evaluates to false (0). *)
113  | St_condcst of AST.cst * Label.t * Label.t
114
115  (* Unary branch. Parameters are the operation, its argument, the
116     label to go to when the operation on the argument evaluates to
117     true (not 0), and the label to go to when the operation on the
118     argument evaluates to false (0). *)
119  | St_cond1 of AST.op1 * registers * Label.t * Label.t
120
121  (* Binary branch. Parameters are the operation, its arguments, the
122     label to go to when the operation on the arguments evaluates to
123     true (not 0), and the label to go to when the operation on the
124     arguments evaluates to false (0). *)
125  | St_cond2 of AST.op2 * registers * registers * Label.t * Label.t
126
127  (* Jump statement. Parameters are a register and a list of
128     labels. The execution will go to the [n]th label of the list of
129     labels, where [n] is the natural value held in the register. *)
130  | St_jumptable of registers * Label.t list
131
132  (* Return statement. *)
133  | St_return of registers
134
135
136type graph = statement Label.Map.t
137
138type internal_function =
139    { f_luniverse : Label.Gen.universe ;
140      f_runiverse : Register.universe ;
141      f_sig       : AST.signature ;
142      f_result    : registers ;
143      f_params    : registers list ;
144      f_locals    : registers list ;
145      f_stacksize : int ;
146      f_graph     : graph ;
147      f_entry     : Label.t ;
148      f_exit      : Label.t }
149
150type function_def =
151  | F_int of internal_function
152  | F_ext of AST.external_function
153
154(* A program is a list of global variables and their reserved space, a list of
155   function names and their definition, and the name of the main function. *)
156
157type program =
158    { vars   : (AST.ident * int (* size *)) list ;
159      functs : (AST.ident * function_def) list ;
160      main   : AST.ident option }
Note: See TracBrowser for help on using the repository browser.