1 | |
---|
2 | (** This file defines some common structures of several languages. *) |
---|
3 | |
---|
4 | (** Types and Signatures *) |
---|
5 | |
---|
6 | type signedness = Signed | Unsigned |
---|
7 | |
---|
8 | type size = int (* in bytes *) |
---|
9 | |
---|
10 | type sig_type = |
---|
11 | | Sig_int of size * signedness |
---|
12 | | Sig_float of size * signedness |
---|
13 | | Sig_offset |
---|
14 | | Sig_ptr |
---|
15 | |
---|
16 | type type_return = Type_ret of sig_type | Type_void |
---|
17 | |
---|
18 | type signature = { args: sig_type list ; res: type_return } |
---|
19 | |
---|
20 | |
---|
21 | type ident = string (* identifiers for variable and function names *) |
---|
22 | |
---|
23 | type immediate = int (* immediate values for assembler constants and offsets *) |
---|
24 | |
---|
25 | |
---|
26 | (** Memory quantities is the size of what can fit in memory. *) |
---|
27 | |
---|
28 | type quantity = |
---|
29 | | QInt of size (* concrete size in bytes *) |
---|
30 | | QOffset (* size of an offset *) |
---|
31 | | QPtr (* size of a pointer *) |
---|
32 | |
---|
33 | type abstract_size = |
---|
34 | | SQ of quantity |
---|
35 | | SProd of abstract_size list |
---|
36 | | SSum of abstract_size list |
---|
37 | | SArray of int * abstract_size |
---|
38 | |
---|
39 | type abstract_offset = abstract_size * int (* nth in size *) |
---|
40 | |
---|
41 | |
---|
42 | (** Comparison between integers or floats *) |
---|
43 | |
---|
44 | type cmp = Cmp_eq | Cmp_ne | Cmp_gt | Cmp_ge | Cmp_lt | Cmp_le |
---|
45 | |
---|
46 | (** Constants in high level languages *) |
---|
47 | |
---|
48 | type cst = |
---|
49 | | Cst_int of int (* integer constant *) |
---|
50 | | Cst_float of float (* float constant *) |
---|
51 | | Cst_addrsymbol of ident (* address of a global symbol *) |
---|
52 | | Cst_stack (* address of the stack *) |
---|
53 | | Cst_offset of abstract_offset (* offset *) |
---|
54 | | Cst_sizeof of abstract_size (* size of a type *) |
---|
55 | |
---|
56 | (** Unary operations *) |
---|
57 | |
---|
58 | type op1 = |
---|
59 | | Op_cast of (size * signedness) * size |
---|
60 | | Op_negint (**r integer opposite *) |
---|
61 | | Op_notbool (**r boolean negation *) |
---|
62 | | Op_notint (**r bitwise complement *) |
---|
63 | | Op_id (**r identity *) |
---|
64 | | Op_ptrofint (**r int to pointer *) |
---|
65 | | Op_intofptr (**r pointer to int *) |
---|
66 | |
---|
67 | (** Binary operations *) |
---|
68 | |
---|
69 | type op2 = |
---|
70 | | Op_add (**r integer addition *) |
---|
71 | | Op_sub (**r integer subtraction *) |
---|
72 | | Op_mul (**r integer multiplication *) |
---|
73 | | Op_div (**r integer division *) |
---|
74 | | Op_divu (**r integer unsigned division *) |
---|
75 | | Op_mod (**r integer modulus *) |
---|
76 | | Op_modu (**r integer unsigned modulus *) |
---|
77 | | Op_and (**r bitwise ``and'' *) |
---|
78 | | Op_or (**r bitwise ``or'' *) |
---|
79 | | Op_xor (**r bitwise ``xor'' *) |
---|
80 | | Op_shl (**r left shift *) |
---|
81 | | Op_shr (**r right shift *) |
---|
82 | | Op_shru (**r unsigned right shift *) |
---|
83 | | Op_cmp of cmp (**r integer comparison *) |
---|
84 | | Op_cmpu of cmp (**r unsigned integer comparison *) |
---|
85 | | Op_addp (**r addition for a pointer and an integer *) |
---|
86 | | Op_subp (**r substraction for a pointer and a integer *) |
---|
87 | | Op_subpp (**r substraction for two pointers *) |
---|
88 | | Op_cmpp of cmp (**r pointer comparaison *) |
---|
89 | |
---|
90 | (* Datas are used to initialize the value of variables *) |
---|
91 | |
---|
92 | type data = |
---|
93 | (* (* Disabled: needed abstraction. *) |
---|
94 | | Data_reserve of int (* only reserve some space *) |
---|
95 | *) |
---|
96 | | Data_int8 of int |
---|
97 | | Data_int16 of int |
---|
98 | | Data_int32 of int |
---|
99 | | Data_float32 of float |
---|
100 | | Data_float64 of float |
---|
101 | |
---|
102 | type data_size = Byte | HalfWord | Word |
---|
103 | |
---|
104 | (* External functions. *) |
---|
105 | |
---|
106 | type external_function = { ef_tag: ident ; ef_sig: signature } |
---|
107 | |
---|
108 | (* Traces returned by interpreters: result and cost labels are observed. The |
---|
109 | result is interpreted as an 8 bits integer for coherence between |
---|
110 | languages. *) |
---|
111 | |
---|
112 | type trace = IntValue.int32 * CostLabel.t list |
---|