source: Deliverables/D2.2/8051/src/RTLabs/RTLabs.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: 4.7 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
13type argument =
14  | Reg of Register.t
15  | Imm of AST.cst*AST.sig_type
16
17(* A function in RTLabs is a mapping from labels to
18   statements. Statements explicitely mention their successors. *)
19
20type statement =
21
22  (* The empty statement. *)
23  | St_skip of Label.t
24
25  (* Emit a cost label. *)
26  | St_cost of CostLabel.t * Label.t
27
28  (* Reset to 0 a loop index *) 
29  | St_ind_0 of CostLabel.index * Label.t
30
31  (* Increment a loop index *)
32  | St_ind_inc of CostLabel.index * Label.t
33
34  (* Assign a constant to registers. Parameters are the destination register,
35     the constant and the label of the next statement. *)
36  | St_cst of Register.t * AST.cst * Label.t
37
38  (* Application of an unary operation. Parameters are the operation, the
39     destination register, the argument register and the label of the next
40     statement. *)
41  | St_op1 of AST.op1 * Register.t * Register.t * Label.t
42
43  (* Application of a binary operation. Parameters are the operation, the
44     destination register, the two arguments and the label of the next
45     statement. *)
46  | St_op2 of AST.op2 * Register.t * argument * argument * Label.t
47
48  (* Memory load. Parameters are the size in bytes of what to load, the
49     register containing the address, the destination register and the label
50     of the next statement. *)
51  | St_load of AST.quantity * argument * Register.t * Label.t
52
53  (* Memory store. Parameters are the size in bytes of what to store, the
54     register containing the address, the source register and the label of the
55     next statement. *)
56  | St_store of AST.quantity * argument * argument * Label.t
57
58  (* Call to a function given its name. Parameters are the name of the
59     function, the arguments of the function, the destination
60     register, the signature of the function and the label of the next
61     statement. *)
62  | St_call_id of AST.ident * Register.t list * Register.t option *
63                  AST.signature * Label.t
64
65  (* Call to a function given its address. Parameters are the register
66     holding the address of the function, the arguments of the
67     function, the destination register, the signature of the function
68     and the label of the next statement. This statement with an
69     [St_op] before can represent a [St_call_id]. However, we
70     differenciate the two to allow translation to a formalism with no
71     function pointer. *)
72  | St_call_ptr of Register.t * Register.t list * Register.t option *
73                   AST.signature * Label.t
74
75  (* Tail call to a function given its name. Parameters are the name of the
76     function, the arguments of the function, the signature of the function and
77     the label of the next statement. *)
78  | St_tailcall_id of AST.ident * Register.t list * AST.signature
79
80  (* Tail call to a function given its address. Parameters are a register
81     holding the address of the function, the arguments of the function, the
82     signature of the function and the label of the next statement. Same remark
83     as for the [St_call_ptr]. *)
84  | St_tailcall_ptr of Register.t * Register.t list * AST.signature
85
86  (* Branch. Parameters are the register holding the value to branch on, the
87     label to go to when the value evaluates to true (not 0), and the label
88     to go to when the value evaluates to false (0). *)
89  | St_cond of Register.t * Label.t * Label.t
90
91  (* Jump statement. Parameters are a register and a list of
92     labels. The execution will go to the [n]th label of the list of
93     labels, where [n] is the natural value held in the register. *)
94  | St_jumptable of Register.t * Label.t list
95
96  (* Return statement. *)
97  | St_return of Register.t option
98
99
100type graph = statement Label.Map.t
101
102type internal_function =
103    { f_luniverse : Label.Gen.universe ;
104      f_runiverse : Register.universe ;
105      f_result    : (Register.t * AST.sig_type) option ;
106      f_params    : (Register.t * AST.sig_type) list ;
107      f_locals    : (Register.t * AST.sig_type) list ;
108      f_stacksize : AST.abstract_size ;
109      f_graph     : graph ;
110      f_entry     : Label.t ;
111      f_exit      : Label.t }
112
113type function_def =
114  | F_int of internal_function
115  | F_ext of AST.external_function
116
117(* A program is a list of global variables and their reserved space, a list of
118   function names and their definition, and the name of the main function. *)
119
120type program =
121    { vars   : (AST.ident * AST.abstract_size) list ;
122      functs : (AST.ident * function_def) list ;
123      main   : AST.ident option }
Note: See TracBrowser for help on using the repository browser.