1 | |
---|
2 | (** This module defines the abstract syntax tree of [LTL]. *) |
---|
3 | |
---|
4 | (** The main difference with ERTL is that only physical registers are present in |
---|
5 | LTL (no more pseudo-registers). Pseudo-registers are associated either a |
---|
6 | physical register or a location on the stack. This is done by a coloring |
---|
7 | algorithm. Actually, this coloring algorithm relies on the result of a |
---|
8 | liveness analysis that will also allow to remove dead code. *) |
---|
9 | |
---|
10 | type argument = |
---|
11 | | Reg of I8051.register |
---|
12 | | Imm of int |
---|
13 | |
---|
14 | type statement = |
---|
15 | |
---|
16 | (* The empty statement. *) |
---|
17 | | St_skip of Label.t |
---|
18 | |
---|
19 | (* Comment. *) |
---|
20 | | St_comment of string * Label.t |
---|
21 | |
---|
22 | (* Emit a cost label. *) |
---|
23 | | St_cost of CostLabel.t * Label.t |
---|
24 | |
---|
25 | (* Reset to 0 a loop index *) |
---|
26 | | St_ind_0 of CostLabel.index * Label.t |
---|
27 | |
---|
28 | (* Increment a loop index *) |
---|
29 | | St_ind_inc of CostLabel.index * Label.t |
---|
30 | |
---|
31 | (* Assign an integer constant to a register. Parameters are the destination |
---|
32 | register, the integer and the label of the next statement. *) |
---|
33 | | St_int of I8051.register * int * Label.t |
---|
34 | |
---|
35 | (* Pop a value from the IRAM to the accumulator. Parameter is the label of the |
---|
36 | next statement. *) |
---|
37 | | St_pop of Label.t |
---|
38 | |
---|
39 | (* Push a value from the accumulator to the IRAM. Parameter is the label of |
---|
40 | the next statement. *) |
---|
41 | | St_push of Label.t |
---|
42 | |
---|
43 | (* Assign the address of a symbol to a DPTR. Parameters are the symbol, and |
---|
44 | the label of the next statement. *) |
---|
45 | | St_addr of AST.ident * Label.t |
---|
46 | |
---|
47 | (* Move the content of the accumulator to a register. Parameters are the |
---|
48 | destination register, and the label of the next statement. *) |
---|
49 | | St_from_acc of I8051.register * Label.t |
---|
50 | |
---|
51 | (* Move the content of a register to the accumulator. Parameters are the |
---|
52 | source register, and the label of the next statement. *) |
---|
53 | | St_to_acc of I8051.register * Label.t |
---|
54 | |
---|
55 | (* Apply an operation on the accumulators. Parameters are the operation, and |
---|
56 | the label of the next statement. *) |
---|
57 | | St_opaccs of I8051.opaccs * Label.t |
---|
58 | |
---|
59 | (* Apply an unary operation on the A accumulator. Parameters are the |
---|
60 | operation, and the label of the next statement. *) |
---|
61 | | St_op1 of I8051.op1 * Label.t |
---|
62 | |
---|
63 | (* Apply a binary operation on the A accumulator. Parameters are the |
---|
64 | operation, the other argument, and the label of the next |
---|
65 | statement. *) |
---|
66 | | St_op2 of I8051.op2 * argument * Label.t |
---|
67 | |
---|
68 | (* Set the carry flag to zero. Parameter is the label of the next |
---|
69 | statement. *) |
---|
70 | | St_clear_carry of Label.t |
---|
71 | |
---|
72 | (* Set the carry flag to 1. Parameter is the label of the next statement. *) |
---|
73 | | St_set_carry of Label.t |
---|
74 | |
---|
75 | (* Load from external memory (address in DPTR) to the accumulator. Parameter |
---|
76 | is the label of the next statement. *) |
---|
77 | | St_load of Label.t |
---|
78 | |
---|
79 | (* Store to external memory (address in DPTR) from the accumulator. Parameter |
---|
80 | is the label of the next statement. *) |
---|
81 | | St_store of Label.t |
---|
82 | |
---|
83 | (* Call to a function given its name. Parameters are the name of the function, |
---|
84 | and the label of the next statement. *) |
---|
85 | | St_call_id of AST.ident * Label.t |
---|
86 | |
---|
87 | (* Call to a function given its address in DPTR. Parameter is the label of the |
---|
88 | next statement. *) |
---|
89 | | St_call_ptr of Label.t |
---|
90 | |
---|
91 | (* Branch on A accumulator. Parameters are the label to go to when the A |
---|
92 | accumulator is not 0, and the label to go to when the A accumulator is |
---|
93 | 0. *) |
---|
94 | | St_condacc of Label.t * Label.t |
---|
95 | |
---|
96 | (* Transfer control to the address stored in the return address registers. *) |
---|
97 | | St_return |
---|
98 | |
---|
99 | type graph = statement Label.Map.t |
---|
100 | |
---|
101 | type internal_function = |
---|
102 | { f_luniverse : Label.Gen.universe ; |
---|
103 | f_stacksize : int ; |
---|
104 | f_graph : graph ; |
---|
105 | f_entry : Label.t ; |
---|
106 | f_exit : Label.t } |
---|
107 | |
---|
108 | type function_def = |
---|
109 | | F_int of internal_function |
---|
110 | | F_ext of AST.external_function |
---|
111 | |
---|
112 | (* A program is a list of global variables and their reserved space, a list of |
---|
113 | function names and their definition, and the name of the main function. *) |
---|
114 | |
---|
115 | type program = |
---|
116 | { vars : (AST.ident * int (* size *)) list ; |
---|
117 | functs : (AST.ident * function_def) list ; |
---|
118 | main : AST.ident option } |
---|