1 | |
---|
2 | (** This module defines the abstract syntax tree of [LIN]. *) |
---|
3 | |
---|
4 | type argument = LTL.argument |
---|
5 | |
---|
6 | (** Compared to LTL where functions were graphs, the functions of a LIN program |
---|
7 | are sequential instructions. *) |
---|
8 | |
---|
9 | type statement = |
---|
10 | |
---|
11 | (* Unconditional branch. *) |
---|
12 | | St_goto of Label.t |
---|
13 | |
---|
14 | (* Label a statement. *) |
---|
15 | | St_label of Label.t |
---|
16 | |
---|
17 | (* Comment. *) |
---|
18 | | St_comment of string |
---|
19 | |
---|
20 | (* Emit a cost label. *) |
---|
21 | | St_cost of CostLabel.t |
---|
22 | |
---|
23 | (* Reset to 0 a loop index *) |
---|
24 | | St_ind_0 of CostLabel.index |
---|
25 | |
---|
26 | (* Increment a loop index *) |
---|
27 | | St_ind_inc of CostLabel.index |
---|
28 | |
---|
29 | (* Assign an integer constant to a register. Parameters are the destination |
---|
30 | register, and the integer. *) |
---|
31 | | St_int of I8051.register * int |
---|
32 | |
---|
33 | (* Pop a value from the IRAM to the accumulator. *) |
---|
34 | | St_pop |
---|
35 | |
---|
36 | (* Push a value from the accumulator to the IRAM. *) |
---|
37 | | St_push |
---|
38 | |
---|
39 | (* Assign the address of a symbol to DPTR. Parameter is the symbol. *) |
---|
40 | | St_addr of AST.ident |
---|
41 | |
---|
42 | (* Move the content of the accumulator to a register. Parameters is the |
---|
43 | destination register. *) |
---|
44 | | St_from_acc of I8051.register |
---|
45 | |
---|
46 | (* Move the content of a register to the accumulator. Parameters is the source |
---|
47 | register. *) |
---|
48 | | St_to_acc of I8051.register |
---|
49 | |
---|
50 | (* Apply an operation on the accumulators. Parameter is the operation. *) |
---|
51 | | St_opaccs of I8051.opaccs |
---|
52 | |
---|
53 | (* Apply an unary operation on the A accumulator. Parameter is the |
---|
54 | operation. *) |
---|
55 | | St_op1 of I8051.op1 |
---|
56 | |
---|
57 | (* Apply a binary operation on the A accumulator. Parameters are the |
---|
58 | operation, and the other source register. *) |
---|
59 | | St_op2 of I8051.op2 * argument |
---|
60 | |
---|
61 | (* Set the carry flag to zero. *) |
---|
62 | | St_clear_carry |
---|
63 | |
---|
64 | (* Set the carry flag to 1. *) |
---|
65 | | St_set_carry |
---|
66 | |
---|
67 | (* Load from external memory (address in DPTR) to the accumulator. *) |
---|
68 | | St_load |
---|
69 | |
---|
70 | (* Store to external memory (address in DPTR) from the accumulator. *) |
---|
71 | | St_store |
---|
72 | |
---|
73 | (* Call to a function given its name. Parameter is the name of the |
---|
74 | function. *) |
---|
75 | | St_call_id of AST.ident |
---|
76 | |
---|
77 | (* Call to a function given its address in DPTR. *) |
---|
78 | | St_call_ptr |
---|
79 | |
---|
80 | (* Branch on A accumulator. Parameter is the label to go to when the A |
---|
81 | accumulator is not 0. *) |
---|
82 | | St_condacc of Label.t |
---|
83 | |
---|
84 | (* Transfer control to the address stored in the return address registers. *) |
---|
85 | | St_return |
---|
86 | |
---|
87 | type internal_function = statement list |
---|
88 | |
---|
89 | type function_def = |
---|
90 | | F_int of internal_function |
---|
91 | | F_ext of AST.external_function |
---|
92 | |
---|
93 | (* A program is a list of global variables and their reserved space, a list of |
---|
94 | function names and their definition, and the name of the main function. *) |
---|
95 | |
---|
96 | type program = |
---|
97 | { vars : (AST.ident * int (* size *)) list ; |
---|
98 | functs : (AST.ident * function_def) list ; |
---|
99 | main : AST.ident option } |
---|