Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Machine.ml 9.95 KB
Newer Older
1
2
3
4
5
6
7
8
(* *********************************************************************)
(*                                                                     *)
(*              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       *)
9
10
11
12
13
(*  under the terms of the GNU Lesser General Public License as        *)
(*  published by the Free Software Foundation, either version 2.1 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.                            *)
14
15
16
17
18
(*                                                                     *)
(* *********************************************************************)

(* Machine-dependent aspects *)

19
20
21
type struct_passing_style =
  | SP_ref_callee                       (* by reference, callee takes copy *)
  | SP_ref_caller                       (* by reference, caller takes copy *)
22
  | SP_value32_ref_callee               (* by value if <= 32 bits, by ref_callee otherwise *)
23
24
25
26
27
28
29
30
31
  | 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 *)

32
type t = {
33
  name: string;
34
35
36
37
38
39
40
41
42
43
44
45
  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;
46
  wchar_signed: bool;
47
48
  sizeof_size_t: int;
  sizeof_ptrdiff_t: int;
49
  sizeof_intreg: int;
50
51
52
53
54
55
56
57
58
  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;
59
  alignof_fun: int option;
60
  bigendian: bool;
61
  bitfields_msb_first: bool;
62
63
64
  supports_unaligned_accesses: bool;
  struct_passing_style: struct_passing_style;
  struct_return_style : struct_return_style;
65
  has_non_trapping_loads : bool;
66
67
68
}

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

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

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

176
177
(* Canned configurations for some ABIs *)

178
let x86_32 =
179
180
181
  { ilp32ll64 with name = "x86_32";
                   char_signed = true;
                   alignof_longlong = 4; alignof_double = 4;
182
                   alignof_longdouble = 4;
183
184
185
                   supports_unaligned_accesses = true;
                   struct_passing_style = SP_split_args;
                   struct_return_style = SR_ref}
186

Xavier Leroy's avatar
Xavier Leroy committed
187
let x86_32_macos =
188
189
190
191
  {x86_32 with struct_passing_style = SP_split_args;
               struct_return_style = SR_int1248 }

let x86_32_bsd =
Xavier Leroy's avatar
Xavier Leroy committed
192
  x86_32_macos
193

194
let x86_64 =
195
196
197
  { i32lpll64 with name = "x86_64"; char_signed = true;
                   struct_passing_style = SP_ref_callee; (* wrong *)
                   struct_return_style = SR_ref } (* to check *)
198

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

215
216
217
let ppc_32_r64_bigendian =
  { ppc_32_bigendian with sizeof_intreg = 8;}

218
219
220
let ppc_32_diab_bigendian =
  { ppc_32_bigendian with sizeof_wchar = 2; wchar_signed = false }

221
222
223
let ppc_32_r64_diab_bigendian =
  { ppc_32_diab_bigendian with sizeof_intreg = 8;}

224
225
let ppc_32_linux_bigendian = {ppc_32_bigendian with struct_return_style = SR_ref;}

226
227
228
let ppc_32_r64_linux_bigendian =
  { ppc_32_linux_bigendian with sizeof_intreg = 8;}

229
let arm_littleendian =
230
231
  { ilp32ll64 with name = "arm"; struct_passing_style = SP_split_args;
                   struct_return_style = SR_int1to4;}
232

233
234
235
236
let arm_bigendian =
  { arm_littleendian with bigendian = true;
                          bitfields_msb_first = true }

237
let rv32 =
238
239
240
  { ilp32ll64 with name = "rv32";
                   struct_passing_style = SP_ref_callee; (* Wrong *)
                   struct_return_style = SR_ref } (* to check *)
241
let rv64 =
242
243
244
  { i32lpll64 with name = "rv64";
                   struct_passing_style = SP_ref_callee; (* Wrong *)
                   struct_return_style = SR_ref } (* to check *)
245

246
let kvxbase =
David Monniaux's avatar
David Monniaux committed
247
  { name = "kvx";
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
    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
263
    sizeof_intreg = 8; (* What is this for ? *)
264
265
266
267
268
269
270
271
272
273
274
275
276
    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;
277
    struct_passing_style = SP_value32_ref_callee;
278
    struct_return_style = SR_int1to4;
279
280
281
282
283
284
285
286
287
    has_non_trapping_loads = false;
}

let kvxcos =
  { kvxbase with has_non_trapping_loads = false;
}

let kvxmbr =
  { kvxbase with has_non_trapping_loads = true;
288
}
289

Cyril SIX's avatar
Cyril SIX committed
290
291
let kvxelf = kvxmbr

Xavier Leroy's avatar
Xavier Leroy committed
292
293
294
295
296
let aarch64 =
  { i32lpll64 with name = "aarch64";
                   struct_passing_style = SP_ref_callee; (* Wrong *)
                   struct_return_style = SR_ref } (* Wrong *)

Xavier Leroy's avatar
Xavier Leroy committed
297
298
299
let aarch64_apple =
  { aarch64 with char_signed = true }

300
(* Add GCC extensions re: sizeof and alignof *)
301
302
303
304
305

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

306
307
308
(* Normalize configuration for use with the CompCert reference interpreter *)

let compcert_interpreter c =
309
  { c with supports_unaligned_accesses = false }
310

311
(* Undefined configuration *)
312

313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
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;
330
  sizeof_intreg = 0;
331
332
333
334
335
336
337
338
339
340
341
342
  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;
343
344
345
  supports_unaligned_accesses = false;
  struct_passing_style = SP_ref_callee;
  struct_return_style = SR_ref;
346
  has_non_trapping_loads = false;
347
348
349
350
351
}

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

let config = ref undef