Machine.ml 9.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(* *********************************************************************)
(*                                                                     *)
(*              The Compcert verified compiler                         *)
(*                                                                     *)
(*          Xavier Leroy, INRIA Paris-Rocquencourt                     *)
(*                                                                     *)
(*  Copyright Institut National de Recherche en Informatique et en     *)
(*  Automatique.  All rights reserved.  This file is distributed       *)
(*  under the terms of the GNU General Public License as published by  *)
(*  the Free Software Foundation, either version 2 of the License, or  *)
(*  (at your option) any later version.  This file is also distributed *)
(*  under the terms of the INRIA Non-Commercial License Agreement.     *)
(*                                                                     *)
(* *********************************************************************)

(* Machine-dependent aspects *)

18
19
20
type struct_passing_style =
  | SP_ref_callee                       (* by reference, callee takes copy *)
  | SP_ref_caller                       (* by reference, caller takes copy *)
21
  | SP_value32_ref_callee               (* by value if <= 32 bits, by ref_callee otherwise *)
22
23
24
25
26
27
28
29
30
  | SP_split_args                       (* by value, as a sequence of ints *)

type struct_return_style =
  | SR_int1248      (* return by content if size is 1, 2, 4 or 8 bytes *)
  | SR_int1to4      (* return by content if size is <= 4 *)
  | SR_int1to8      (* return by content if size is <= 8 *)
  | SR_ref          (* always return by assignment to a reference
                       given as extra argument *)

31
type t = {
32
  name: string;
33
34
35
36
37
38
39
40
41
42
43
44
  char_signed: bool;
  sizeof_ptr: int;
  sizeof_short: int;
  sizeof_int: int;
  sizeof_long: int;
  sizeof_longlong: int;
  sizeof_float: int;
  sizeof_double: int;
  sizeof_longdouble: int;
  sizeof_void: int option;
  sizeof_fun: int option;
  sizeof_wchar: int;
45
  wchar_signed: bool;
46
47
  sizeof_size_t: int;
  sizeof_ptrdiff_t: int;
48
  sizeof_intreg: int;
49
50
51
52
53
54
55
56
57
  alignof_ptr: int;
  alignof_short: int;
  alignof_int: int;
  alignof_long: int;
  alignof_longlong: int;
  alignof_float: int;
  alignof_double: int;
  alignof_longdouble: int;
  alignof_void: int option;
58
  alignof_fun: int option;
59
  bigendian: bool;
60
  bitfields_msb_first: bool;
61
62
63
  supports_unaligned_accesses: bool;
  struct_passing_style: struct_passing_style;
  struct_return_style : struct_return_style;
64
65
66
}

let ilp32ll64 = {
67
  name = "ilp32ll64";
68
69
70
71
72
73
74
75
  char_signed = false;
  sizeof_ptr = 4;
  sizeof_short = 2;
  sizeof_int = 4;
  sizeof_long = 4;
  sizeof_longlong = 8;
  sizeof_float = 4;
  sizeof_double = 8;
76
  sizeof_longdouble = 8;
77
78
79
  sizeof_void = None;
  sizeof_fun = None;
  sizeof_wchar = 4;
80
  wchar_signed = true;
81
82
  sizeof_size_t = 4;
  sizeof_ptrdiff_t = 4;
83
  sizeof_intreg = 4;
84
85
86
87
88
89
90
  alignof_ptr = 4;
  alignof_short = 2;
  alignof_int = 4;
  alignof_long = 4;
  alignof_longlong = 8;
  alignof_float = 4;
  alignof_double = 8;
91
  alignof_longdouble = 8;
92
  alignof_void = None;
93
  alignof_fun = None;
94
  bigendian = false;
95
  bitfields_msb_first = false;
96
97
98
  supports_unaligned_accesses = false;
  struct_passing_style = SP_ref_callee;
  struct_return_style = SR_ref;
99
100
101
}

let i32lpll64 = {
102
  name = "i32lpll64";
103
104
105
106
107
108
109
110
  char_signed = false;
  sizeof_ptr = 8;
  sizeof_short = 2;
  sizeof_int = 4;
  sizeof_long = 8;
  sizeof_longlong = 8;
  sizeof_float = 4;
  sizeof_double = 8;
111
  sizeof_longdouble = 8;
112
113
114
  sizeof_void = None;
  sizeof_fun = None;
  sizeof_wchar = 4;
115
  wchar_signed = true;
116
117
  sizeof_size_t = 8;
  sizeof_ptrdiff_t = 8;
118
  sizeof_intreg = 8;
119
120
121
122
123
124
125
  alignof_ptr = 8;
  alignof_short = 2;
  alignof_int = 4;
  alignof_long = 8;
  alignof_longlong = 8;
  alignof_float = 4;
  alignof_double = 8;
126
  alignof_longdouble = 8;
127
  alignof_void = None;
128
  alignof_fun = None;
129
  bigendian = false;
130
  bitfields_msb_first = false;
131
132
133
  supports_unaligned_accesses = false;
  struct_passing_style = SP_ref_callee;
  struct_return_style = SR_ref;
134
135
136
}

let il32pll64 = {
137
  name = "il32pll64";
138
139
140
141
142
143
144
145
  char_signed = false;
  sizeof_ptr = 8;
  sizeof_short = 2;
  sizeof_int = 4;
  sizeof_long = 4;
  sizeof_longlong = 8;
  sizeof_float = 4;
  sizeof_double = 8;
146
  sizeof_longdouble = 8;
147
148
149
  sizeof_void = None;
  sizeof_fun = None;
  sizeof_wchar = 4;
150
  wchar_signed = true;
151
152
  sizeof_size_t = 8;
  sizeof_ptrdiff_t = 8;
153
  sizeof_intreg = 8;
154
155
156
157
158
159
160
  alignof_ptr = 8;
  alignof_short = 2;
  alignof_int = 4;
  alignof_long = 4;
  alignof_longlong = 8;
  alignof_float = 4;
  alignof_double = 8;
161
  alignof_longdouble = 8;
162
  alignof_void = None;
163
  alignof_fun = None;
164
  bigendian = false;
165
  bitfields_msb_first = false;
166
167
168
  supports_unaligned_accesses = false;
  struct_passing_style = SP_ref_callee;
  struct_return_style = SR_ref;
169
170
}

171
172
(* Canned configurations for some ABIs *)

173
let x86_32 =
174
175
176
  { ilp32ll64 with name = "x86_32";
                   char_signed = true;
                   alignof_longlong = 4; alignof_double = 4;
177
                   alignof_longdouble = 4;
178
179
180
                   supports_unaligned_accesses = true;
                   struct_passing_style = SP_split_args;
                   struct_return_style = SR_ref}
181
182

let x86_32_macosx =
183
184
185
186
  {x86_32 with struct_passing_style = SP_split_args;
               struct_return_style = SR_int1248 }

let x86_32_bsd =
187
  x86_32_macosx
188

189
let x86_64 =
190
191
192
  { i32lpll64 with name = "x86_64"; char_signed = true;
                   struct_passing_style = SP_ref_callee; (* wrong *)
                   struct_return_style = SR_ref } (* to check *)
193

194
195
let win32 =
  { ilp32ll64 with name = "win32"; char_signed = true;
196
197
198
                   sizeof_wchar = 2; wchar_signed = false;
                   struct_passing_style = SP_split_args;
                   struct_return_style = SR_ref }
199
let win64 =
200
201
  { il32pll64 with name = "win64"; char_signed = true;
                   sizeof_wchar = 2; wchar_signed = false }
202
let ppc_32_bigendian =
203
204
205
  { ilp32ll64 with name = "powerpc";
                   bigendian = true;
                   bitfields_msb_first = true;
206
207
208
                   supports_unaligned_accesses = true;
                   struct_passing_style = SP_ref_caller;
                   struct_return_style =  SR_int1to8; }
209

210
211
212
let ppc_32_r64_bigendian =
  { ppc_32_bigendian with sizeof_intreg = 8;}

213
214
215
let ppc_32_diab_bigendian =
  { ppc_32_bigendian with sizeof_wchar = 2; wchar_signed = false }

216
217
218
let ppc_32_r64_diab_bigendian =
  { ppc_32_diab_bigendian with sizeof_intreg = 8;}

219
220
let ppc_32_linux_bigendian = {ppc_32_bigendian with struct_return_style = SR_ref;}

221
222
223
let ppc_32_r64_linux_bigendian =
  { ppc_32_linux_bigendian with sizeof_intreg = 8;}

224
let arm_littleendian =
225
226
  { ilp32ll64 with name = "arm"; struct_passing_style = SP_split_args;
                   struct_return_style = SR_int1to4;}
227

228
229
230
231
let arm_bigendian =
  { arm_littleendian with bigendian = true;
                          bitfields_msb_first = true }

232
let rv32 =
233
234
235
  { ilp32ll64 with name = "rv32";
                   struct_passing_style = SP_ref_callee; (* Wrong *)
                   struct_return_style = SR_ref } (* to check *)
236
let rv64 =
237
238
239
  { i32lpll64 with name = "rv64";
                   struct_passing_style = SP_ref_callee; (* Wrong *)
                   struct_return_style = SR_ref } (* to check *)
240

241
let mppa_k1c =
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
  { name = "k1c";
    char_signed = true;
    wchar_signed = true;
    sizeof_ptr = 8;
    sizeof_short = 2;
    sizeof_int = 4;
    sizeof_long = 8;
    sizeof_longlong = 8;
    sizeof_float = 4;
    sizeof_double = 8;
    sizeof_longdouble = 8;
    sizeof_void = None; (* What is this for ? *)
    sizeof_fun = None; (* What is this for ? *)
    sizeof_wchar = 4;
    sizeof_size_t = 8;
    sizeof_ptrdiff_t = 8;
Cyril SIX's avatar
Cyril SIX committed
258
    sizeof_intreg = 8; (* What is this for ? *)
259
260
261
262
263
264
265
266
267
268
269
270
271
    alignof_ptr = 8;
    alignof_short = 2;
    alignof_int = 4;
    alignof_long = 8;
    alignof_longlong = 8;
    alignof_float = 4;
    alignof_double = 8;
    alignof_longdouble = 8;
    alignof_void = None; (* what is this for ? *)
    alignof_fun = None; (* what is this for ? *)
    bigendian = false;
    bitfields_msb_first = false; (* TO CHECK *)
    supports_unaligned_accesses = true;
272
273
    struct_passing_style = SP_value32_ref_callee;
    struct_return_style = SR_int1to4 }
274

275
(* Add GCC extensions re: sizeof and alignof *)
276
277
278
279
280

let gcc_extensions c =
  { c with sizeof_void = Some 1; sizeof_fun = Some 1;
           alignof_void = Some 1; alignof_fun = Some 1 }

281
282
283
(* Normalize configuration for use with the CompCert reference interpreter *)

let compcert_interpreter c =
284
  { c with supports_unaligned_accesses = false }
285

286
(* Undefined configuration *)
287

288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
let undef = {
  name = "UNDEFINED";
  char_signed = false;
  sizeof_ptr = 0;
  sizeof_short = 0;
  sizeof_int = 0;
  sizeof_long = 0;
  sizeof_longlong = 0;
  sizeof_float = 0;
  sizeof_double = 0;
  sizeof_longdouble = 0;
  sizeof_void = None;
  sizeof_fun = None;
  sizeof_wchar = 0;
  wchar_signed = true;
  sizeof_size_t = 0;
  sizeof_ptrdiff_t = 0;
305
  sizeof_intreg = 0;
306
307
308
309
310
311
312
313
314
315
316
317
  alignof_ptr = 0;
  alignof_short = 0;
  alignof_int = 0;
  alignof_long = 0;
  alignof_longlong = 0;
  alignof_float = 0;
  alignof_double = 0;
  alignof_longdouble = 0;
  alignof_void = None;
  alignof_fun = None;
  bigendian = false;
  bitfields_msb_first = false;
318
319
320
  supports_unaligned_accesses = false;
  struct_passing_style = SP_ref_callee;
  struct_return_style = SR_ref;
321
322
323
324
325
}

(* The current configuration.  Must be initialized before use. *)

let config = ref undef