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