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