]> matita.cs.unibo.it Git - pkg-cerco/acc.git/blob - src/RTL/RTL.mli
Package description and copyright added.
[pkg-cerco/acc.git] / src / RTL / RTL.mli
1
2 (** This module defines the abstract syntax tree of [RTL]. *)
3
4 (* The main differences between RTLabs and RTL is instruction selection.
5
6    Also, since addresses in 8051 are two words long, the instructions involving
7    addresses use two registers to represent them. *)
8
9 type registers = Register.t list
10
11 type statement =
12
13   (* The empty statement. *)
14   | St_skip of Label.t
15
16   (* Emit a cost label. *)
17   | St_cost of CostLabel.t * Label.t
18
19   (* Assign the address of a symbol to registers. Parameters are the destination
20      registers (low bytes first), the symbol and the label of the next
21      statement. *)
22   | St_addr of Register.t * Register.t * AST.ident * Label.t
23
24   (* Assign the stack pointer to registers. Parameters are the destination
25      registers (low bytes first), and the label of the next statement. *)
26   | St_stackaddr of Register.t * Register.t * Label.t
27
28   (* Assign an integer constant to a register. Parameters are the destination
29      register, the integer and the label of the next statement. *)
30   | St_int of Register.t * int * Label.t
31
32   (* Move the content of a register to another. Parameters are the destination
33      register, the source register, and the label of the next statement. *)
34   | St_move of Register.t * Register.t * Label.t
35
36   (* Apply a binary operation that will later be translated in an operation on
37      the accumulators. Parameters are the operation, the destination registers
38      (ACC first, BACC second), the source registers, and the label of the next
39      statement. *)
40   | St_opaccs of I8051.opaccs * Register.t * Register.t *
41                                 Register.t * Register.t * Label.t
42
43   (* Apply an unary operation. Parameters are the operation, the destination
44      register, the source register, and the label of the next statement. *)
45   | St_op1 of I8051.op1 * Register.t * Register.t * Label.t
46
47   (* Apply a binary operation. Parameters are the operation, the destination
48      register, the source registers, and the label of the next statement. *)
49   | St_op2 of I8051.op2 * Register.t * Register.t * Register.t * Label.t
50
51   (* Set the carry flag to zero. Parameter is the label of the next
52      statement. *)
53   | St_clear_carry of Label.t
54
55   (* Set the carry flag to 1. Parameter is the label of the next statement. *)
56   | St_set_carry of Label.t
57
58   (* Load from external memory. Parameters are the destination register, the
59      address registers (low bytes first), and the label of the next
60      statement. *)
61   | St_load of Register.t * Register.t * Register.t * Label.t
62
63   (* Store to external memory. Parameters are the address registers (low bytes
64      first), the source register, and the label of the next statement. *)
65   | St_store of Register.t * Register.t * Register.t * Label.t
66
67   (* Call to a function given its name. Parameters are the name of the function,
68      the arguments of the function, the destination registers, and the label of
69      the next statement. *)
70   | St_call_id of AST.ident * Register.t list * registers * Label.t
71
72   (* Call to a function given its address. Parameters are the registers holding
73      the address of the function (low bytes first), the arguments of the
74      function, the destination registers, and the label of the next
75      statement. *)
76   | St_call_ptr of Register.t * Register.t * Register.t list * registers *
77       Label.t
78
79   (* Tail call to a function given its name. Parameters are the name of the
80      function, and the arguments of the function. *)
81   | St_tailcall_id of AST.ident * Register.t list
82
83   (* Tail call to a function given its address. Parameters are the registers
84      holding the address of the function (low bytes first), and the arguments of
85      the function. *)
86   | St_tailcall_ptr of Register.t * Register.t * Register.t list
87
88   (* Branch. Parameters are the register holding the value for the branching,
89      the label to go to when the value is not 0, and the label to go to when the
90      value is 0. *)
91   | St_cond of Register.t * Label.t * Label.t
92
93   (* Return the value of some registers (low bytes first). *)
94   | St_return of registers
95
96
97 type graph = statement Label.Map.t
98
99 type internal_function =
100     { f_luniverse : Label.Gen.universe ;
101       f_runiverse : Register.universe ;
102       f_result    : Register.t list (* low byte first *) ;
103       f_params    : Register.t list ;
104       f_locals    : Register.Set.t ;
105       f_stacksize : int ;
106       f_graph     : graph ;
107       f_entry     : Label.t ;
108       f_exit      : Label.t }
109
110 type function_def =
111   | F_int of internal_function
112   | F_ext of AST.external_function
113
114 (* A program is a list of global variables and their reserved space, a list of
115    function names and their definition, and the name of the main function. *)
116
117 type program =
118     { vars   : (AST.ident * int (* size *)) list ;
119       functs : (AST.ident * function_def) list ;
120       main   : AST.ident option }