2 (** This module defines the abstract syntax tree of [RTLabs]. *)
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
9 RTLabs is the last language of the frontend. It is intended to
13 (* A function in RTLabs is a mapping from labels to
14 statements. Statements explicitely mention their successors. *)
18 (* The empty statement. *)
21 (* Emit a cost label. *)
22 | St_cost of CostLabel.t * Label.t
24 (* Assign a constant to registers. Parameters are the destination register,
25 the constant and the label of the next statement. *)
26 | St_cst of Register.t * AST.cst * Label.t
28 (* Application of an unary operation. Parameters are the operation, the
29 destination register, the argument register and the label of the next
31 | St_op1 of AST.op1 * Register.t * Register.t * Label.t
33 (* Application of a binary operation. Parameters are the operation, the
34 destination register, the two argument registers and the label of the next
36 | St_op2 of AST.op2 * Register.t * Register.t * Register.t * Label.t
38 (* Memory load. Parameters are the size in bytes of what to load, the
39 register containing the address, the destination register and the label
40 of the next statement. *)
41 | St_load of AST.quantity * Register.t * Register.t * Label.t
43 (* Memory store. Parameters are the size in bytes of what to store, the
44 register containing the address, the source register and the label of the
46 | St_store of AST.quantity * Register.t * Register.t * Label.t
48 (* Call to a function given its name. Parameters are the name of the
49 function, the arguments of the function, the destination
50 register, the signature of the function and the label of the next
52 | St_call_id of AST.ident * Register.t list * Register.t option *
53 AST.signature * Label.t
55 (* Call to a function given its address. Parameters are the register
56 holding the address of the function, the arguments of the
57 function, the destination register, the signature of the function
58 and the label of the next statement. This statement with an
59 [St_op] before can represent a [St_call_id]. However, we
60 differenciate the two to allow translation to a formalism with no
62 | St_call_ptr of Register.t * Register.t list * Register.t option *
63 AST.signature * Label.t
65 (* Tail call to a function given its name. Parameters are the name of the
66 function, the arguments of the function, the signature of the function and
67 the label of the next statement. *)
68 | St_tailcall_id of AST.ident * Register.t list * AST.signature
70 (* Tail call to a function given its address. Parameters are a register
71 holding the address of the function, the arguments of the function, the
72 signature of the function and the label of the next statement. Same remark
73 as for the [St_call_ptr]. *)
74 | St_tailcall_ptr of Register.t * Register.t list * AST.signature
76 (* Branch. Parameters are the register holding the value to branch on, the
77 label to go to when the value evaluates to true (not 0), and the label
78 to go to when the value evaluates to false (0). *)
79 | St_cond of Register.t * Label.t * Label.t
81 (* Jump statement. Parameters are a register and a list of
82 labels. The execution will go to the [n]th label of the list of
83 labels, where [n] is the natural value held in the register. *)
84 | St_jumptable of Register.t * Label.t list
86 (* Return statement. *)
87 | St_return of Register.t option
90 type graph = statement Label.Map.t
92 type internal_function =
93 { f_luniverse : Label.Gen.universe ;
94 f_runiverse : Register.universe ;
95 f_result : (Register.t * AST.sig_type) option ;
96 f_params : (Register.t * AST.sig_type) list ;
97 f_locals : (Register.t * AST.sig_type) list ;
98 f_stacksize : AST.abstract_size ;
104 | F_int of internal_function
105 | F_ext of AST.external_function
107 (* A program is a list of global variables and their reserved space, a list of
108 function names and their definition, and the name of the main function. *)
111 { vars : (AST.ident * AST.abstract_size * AST.data list option) list ;
112 functs : (AST.ident * function_def) list ;
113 main : AST.ident option }