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 statement = |
---|
11 | |
---|
12 | (* The empty statement. *) |
---|
13 | | St_skip of Label.t |
---|
14 | |
---|
15 | (* Comment. *) |
---|
16 | | St_comment of string * Label.t |
---|
17 | |
---|
18 | (* Emit a cost label. *) |
---|
19 | | St_cost of CostLabel.t * Label.t |
---|
20 | |
---|
21 | (* Assign an integer constant to a register. Parameters are the destination |
---|
22 | register, the integer and the label of the next statement. *) |
---|
23 | | St_int of I8051.register * int * Label.t |
---|
24 | |
---|
25 | (* Pop a value from the IRAM to the accumulator. Parameter is the label of the |
---|
26 | next statement. *) |
---|
27 | | St_pop of Label.t |
---|
28 | |
---|
29 | (* Push a value from the accumulator to the IRAM. Parameter is the label of |
---|
30 | the next statement. *) |
---|
31 | | St_push of Label.t |
---|
32 | |
---|
33 | (* Assign the address of a symbol to a DPTR. Parameters are the symbol, and |
---|
34 | the label of the next statement. *) |
---|
35 | | St_addr of AST.ident * Label.t |
---|
36 | |
---|
37 | (* Move the content of the accumulator to a register. Parameters are the |
---|
38 | destination register, and the label of the next statement. *) |
---|
39 | | St_from_acc of I8051.register * Label.t |
---|
40 | |
---|
41 | (* Move the content of a register to the accumulator. Parameters are the |
---|
42 | source register, and the label of the next statement. *) |
---|
43 | | St_to_acc of I8051.register * Label.t |
---|
44 | |
---|
45 | (* Apply an operation on the accumulators. Parameters are the operation, and |
---|
46 | the label of the next statement. *) |
---|
47 | | St_opaccs of I8051.opaccs * Label.t |
---|
48 | |
---|
49 | (* Apply an unary operation on the A accumulator. Parameters are the |
---|
50 | operation, and the label of the next statement. *) |
---|
51 | | St_op1 of I8051.op1 * Label.t |
---|
52 | |
---|
53 | (* Apply a binary operation on the A accumulator. Parameters are the |
---|
54 | operation, the other source register, and the label of the next |
---|
55 | statement. *) |
---|
56 | | St_op2 of I8051.op2 * I8051.register * Label.t |
---|
57 | |
---|
58 | (* Set the carry flag to zero. Parameter is the label of the next |
---|
59 | statement. *) |
---|
60 | | St_clear_carry of Label.t |
---|
61 | |
---|
62 | (* Set the carry flag to 1. Parameter is the label of the next statement. *) |
---|
63 | | St_set_carry of Label.t |
---|
64 | |
---|
65 | (* Load from external memory (address in DPTR) to the accumulator. Parameter |
---|
66 | is the label of the next statement. *) |
---|
67 | | St_load of Label.t |
---|
68 | |
---|
69 | (* Store to external memory (address in DPTR) from the accumulator. Parameter |
---|
70 | is the label of the next statement. *) |
---|
71 | | St_store of Label.t |
---|
72 | |
---|
73 | (* Call to a function given its name. Parameters are the name of the function, |
---|
74 | and the label of the next statement. *) |
---|
75 | | St_call_id of AST.ident * Label.t |
---|
76 | |
---|
77 | (* Call to a function given its address in DPTR. Parameter is the label of the |
---|
78 | next statement. *) |
---|
79 | | St_call_ptr of Label.t |
---|
80 | |
---|
81 | (* Branch on A accumulator. Parameters are the label to go to when the A |
---|
82 | accumulator is not 0, and the label to go to when the A accumulator is |
---|
83 | 0. *) |
---|
84 | | St_condacc of Label.t * Label.t |
---|
85 | |
---|
86 | (* Transfer control to the address stored in the return address registers. *) |
---|
87 | | St_return |
---|
88 | |
---|
89 | type graph = statement Label.Map.t |
---|
90 | |
---|
91 | type internal_function = |
---|
92 | { f_luniverse : Label.Gen.universe ; |
---|
93 | f_stacksize : int ; |
---|
94 | f_graph : graph ; |
---|
95 | f_entry : Label.t ; |
---|
96 | f_exit : Label.t } |
---|
97 | |
---|
98 | type function_def = |
---|
99 | | F_int of internal_function |
---|
100 | | F_ext of AST.external_function |
---|
101 | |
---|
102 | (* A program is a list of global variables and their reserved space, a list of |
---|
103 | function names and their definition, and the name of the main function. *) |
---|
104 | |
---|
105 | type program = |
---|
106 | { vars : (AST.ident * int (* size *)) list ; |
---|
107 | functs : (AST.ident * function_def) list ; |
---|
108 | main : AST.ident option } |
---|