source: Deliverables/D2.2/8051/src/RTL/RTL.mli @ 1568

Last change on this file since 1568 was 1568, checked in by tranquil, 8 years ago
  • Immediates introduced (but not fully used yet in RTLabs to RTL pass)
  • translation streamlined
  • BUGGY: interpretation fails in LTL, trying to fetch a function with incorrect address
File size: 5.1 KB
Line 
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
9type registers = Register.t list
10
11(* arguments to certain operations: either registers or immediate args *)
12type argument =
13  | Reg of Register.t
14  | Imm of int
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 the address of a symbol to registers. Parameters are the destination
31     registers (low bytes first), the symbol and the label of the next
32     statement. *)
33  | St_addr of Register.t * Register.t * AST.ident * Label.t
34
35  (* Assign the stack pointer to registers. Parameters are the destination
36     registers (low bytes first), and the label of the next statement. *)
37  | St_stackaddr of Register.t * Register.t * Label.t
38
39  (* (\* Assign an integer constant to a register. Parameters are the destination *)
40  (*    register, the integer and the label of the next statement. *\) *)
41  (* | St_int of Register.t * int * Label.t *)
42
43  (* Move the content of a register to another. Parameters are the destination
44     register, the source argument, and the label of the next statement. *)
45  | St_move of Register.t * argument * Label.t
46
47  (* Apply a binary operation that will later be translated in an operation on
48     the accumulators. Parameters are the operation, the destination registers
49     (ACC first, BACC second), the source registers, and the label of the next
50     statement. *)
51  | St_opaccs of I8051.opaccs * Register.t * Register.t *
52                                Register.t * Register.t * Label.t
53
54  (* Apply an unary operation. Parameters are the operation, the destination
55     register, the source register, and the label of the next statement. *)
56  | St_op1 of I8051.op1 * Register.t * Register.t * Label.t
57
58  (* Apply a binary operation. Parameters are the operation, the destination
59     register, the source arguments, and the label of the next statement. *)
60  | St_op2 of I8051.op2 * Register.t * Register.t * argument * Label.t
61
62  (* Set the carry flag to zero. Parameter is the label of the next
63     statement. *)
64  | St_clear_carry of Label.t
65
66  (* Set the carry flag to 1. Parameter is the label of the next statement. *)
67  | St_set_carry of Label.t
68
69  (* Load from external memory. Parameters are the destination register, the
70     address registers (low bytes first), and the label of the next
71     statement. *)
72  | St_load of Register.t * Register.t * Register.t * Label.t
73
74  (* Store to external memory. Parameters are the address registers (low bytes
75     first), the source register, and the label of the next statement. *)
76  | St_store of Register.t * Register.t * Register.t * Label.t
77
78  (* Call to a function given its name. Parameters are the name of the function,
79     the arguments of the function, the destination registers, and the label of
80     the next statement. *)
81  | St_call_id of AST.ident * Register.t list * registers * Label.t
82
83  (* Call to a function given its address. Parameters are the registers holding
84     the address of the function (low bytes first), the arguments of the
85     function, the destination registers, and the label of the next
86     statement. *)
87  | St_call_ptr of Register.t * Register.t * Register.t list * registers *
88      Label.t
89
90  (* Tail call to a function given its name. Parameters are the name of the
91     function, and the arguments of the function. *)
92  | St_tailcall_id of AST.ident * Register.t list
93
94  (* Tail call to a function given its address. Parameters are the registers
95     holding the address of the function (low bytes first), and the arguments of
96     the function. *)
97  | St_tailcall_ptr of Register.t * Register.t * Register.t list
98
99  (* Branch. Parameters are the register holding the value for the branching,
100     the label to go to when the value is not 0, and the label to go to when the
101     value is 0. *)
102  | St_cond of Register.t * Label.t * Label.t
103
104  (* Return the value of some registers (low bytes first). *)
105  | St_return of registers
106
107
108type graph = statement Label.Map.t
109
110type internal_function =
111    { f_luniverse : Label.Gen.universe ;
112      f_runiverse : Register.universe ;
113      f_result    : Register.t list (* low byte first *) ;
114      f_params    : Register.t list ;
115      f_locals    : Register.Set.t ;
116      f_stacksize : int ;
117      f_graph     : graph ;
118      f_entry     : Label.t ;
119      f_exit      : Label.t }
120
121type function_def =
122  | F_int of internal_function
123  | F_ext of AST.external_function
124
125(* A program is a list of global variables and their reserved space, a list of
126   function names and their definition, and the name of the main function. *)
127
128type program =
129    { vars   : (AST.ident * int (* size *)) list ;
130      functs : (AST.ident * function_def) list ;
131      main   : AST.ident option }
Note: See TracBrowser for help on using the repository browser.