Machine.ml 5.89 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(* *********************************************************************)
(*                                                                     *)
(*              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 *)

type t = {
19
  name: string;
20
21
22
23
24
25
26
27
28
29
30
31
  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;
32
  wchar_signed: bool;
33
34
35
36
37
38
39
40
41
42
43
  sizeof_size_t: int;
  sizeof_ptrdiff_t: int;
  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;
44
  alignof_fun: int option;
45
  bigendian: bool;
46
  bitfields_msb_first: bool;
47
  supports_unaligned_accesses: bool
48
49
50
}

let ilp32ll64 = {
51
  name = "ilp32ll64";
52
53
54
55
56
57
58
59
60
61
62
63
  char_signed = false;
  sizeof_ptr = 4;
  sizeof_short = 2;
  sizeof_int = 4;
  sizeof_long = 4;
  sizeof_longlong = 8;
  sizeof_float = 4;
  sizeof_double = 8;
  sizeof_longdouble = 16;
  sizeof_void = None;
  sizeof_fun = None;
  sizeof_wchar = 4;
64
  wchar_signed = true;
65
66
67
68
69
70
71
72
73
74
75
  sizeof_size_t = 4;
  sizeof_ptrdiff_t = 4;
  alignof_ptr = 4;
  alignof_short = 2;
  alignof_int = 4;
  alignof_long = 4;
  alignof_longlong = 8;
  alignof_float = 4;
  alignof_double = 8;
  alignof_longdouble = 16;
  alignof_void = None;
76
  alignof_fun = None;
77
  bigendian = false;
78
  bitfields_msb_first = false;
79
  supports_unaligned_accesses = false
80
81
82
}

let i32lpll64 = {
83
  name = "i32lpll64";
84
85
86
87
88
89
90
91
92
93
94
95
  char_signed = false;
  sizeof_ptr = 8;
  sizeof_short = 2;
  sizeof_int = 4;
  sizeof_long = 8;
  sizeof_longlong = 8;
  sizeof_float = 4;
  sizeof_double = 8;
  sizeof_longdouble = 16;
  sizeof_void = None;
  sizeof_fun = None;
  sizeof_wchar = 4;
96
  wchar_signed = true;
97
98
99
100
101
102
103
104
105
106
107
  sizeof_size_t = 8;
  sizeof_ptrdiff_t = 8;
  alignof_ptr = 8;
  alignof_short = 2;
  alignof_int = 4;
  alignof_long = 8;
  alignof_longlong = 8;
  alignof_float = 4;
  alignof_double = 8;
  alignof_longdouble = 16;
  alignof_void = None;
108
  alignof_fun = None;
109
  bigendian = false;
110
  bitfields_msb_first = false;
111
  supports_unaligned_accesses = false
112
113
114
}

let il32pll64 = {
115
  name = "il32pll64";
116
117
118
119
120
121
122
123
124
125
126
127
  char_signed = false;
  sizeof_ptr = 8;
  sizeof_short = 2;
  sizeof_int = 4;
  sizeof_long = 4;
  sizeof_longlong = 8;
  sizeof_float = 4;
  sizeof_double = 8;
  sizeof_longdouble = 16;
  sizeof_void = None;
  sizeof_fun = None;
  sizeof_wchar = 4;
128
  wchar_signed = true;
129
130
131
132
133
134
135
136
137
138
139
  sizeof_size_t = 8;
  sizeof_ptrdiff_t = 8;
  alignof_ptr = 8;
  alignof_short = 2;
  alignof_int = 4;
  alignof_long = 4;
  alignof_longlong = 8;
  alignof_float = 4;
  alignof_double = 8;
  alignof_longdouble = 16;
  alignof_void = None;
140
  alignof_fun = None;
141
  bigendian = false;
142
  bitfields_msb_first = false;
143
  supports_unaligned_accesses = false
144
145
}

146
147
(* Canned configurations for some ABIs *)

148
let x86_32 =
149
150
151
  { ilp32ll64 with name = "x86_32";
                   char_signed = true;
                   alignof_longlong = 4; alignof_double = 4;
152
                   sizeof_longdouble = 12; alignof_longdouble = 4;
153
                   supports_unaligned_accesses = true }
154
155

let x86_32_macosx =
156
  { x86_32 with sizeof_longdouble = 16; alignof_longdouble = 16 }
157

158
let x86_64 =
159
  { i32lpll64 with name = "x86_64"; char_signed = true }
160

161
162
163
let win32 =
  { ilp32ll64 with name = "win32"; char_signed = true;
                   sizeof_wchar = 2; wchar_signed = false }
164
let win64 =
165
166
  { il32pll64 with name = "win64"; char_signed = true;
                   sizeof_wchar = 2; wchar_signed = false }
167
let ppc_32_bigendian =
168
169
170
  { ilp32ll64 with name = "powerpc";
                   bigendian = true;
                   bitfields_msb_first = true;
171
                   supports_unaligned_accesses = true }
172

173
174
175
176
let ppc_32_diab_bigendian =
  { ppc_32_bigendian with sizeof_wchar = 2; wchar_signed = false }


177
let arm_littleendian =
178
  { ilp32ll64 with name = "arm" }
179
180

(* Add GCC extensions re: sizeof and alignof *)
181
182
183
184
185

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

186
187
188
189
(* Normalize configuration for use with the CompCert reference interpreter *)

let compcert_interpreter c =
  { c with sizeof_longdouble = 8; alignof_longdouble = 8;
190
           supports_unaligned_accesses = false }
191

192
(* Undefined configuration *)
193

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
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;
  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;
223
  supports_unaligned_accesses = false
224
225
226
227
228
}

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

let config = ref undef