source: Deliverables/D2.2/8051-indexed-labels-branch/src/RTLabs/RTLabs.mli @ 1340

Last change on this file since 1340 was 1340, checked in by tranquil, 8 years ago

work on RTLabs and RTL completed

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