1 #include "symbol.h"
2 #include "target.h"
3 #include "machine.h"
4 #include "builtin.h"
5
6
predefine_i386(const struct target * self)7 static void predefine_i386(const struct target *self)
8 {
9 predefine("__i386__", 1, "1");
10 predefine("__i386", 1, "1");
11 predefine_nostd("i386");
12 }
13
predefine_x86_64(const struct target * self)14 static void predefine_x86_64(const struct target *self)
15 {
16 predefine("__x86_64__", 1, "1");
17 predefine("__x86_64", 1, "1");
18 predefine("__amd64__", 1, "1");
19 predefine("__amd64", 1, "1");
20 }
21
22
init_x86_common(const struct target * target)23 static void init_x86_common(const struct target *target)
24 {
25 switch (arch_os) {
26 case OS_CYGWIN:
27 wchar_ctype = &ushort_ctype;
28 break;
29 case OS_FREEBSD:
30 wint_ctype = &int_ctype;
31 break;
32 case OS_OPENBSD:
33 size_t_ctype = &ulong_ctype;
34 ssize_t_ctype = &long_ctype;
35 wchar_ctype = &int_ctype;
36 wint_ctype = &int_ctype;
37 fast16_ctype = &short_ctype;
38 ufast16_ctype = &ushort_ctype;
39 break;
40 }
41 }
42
43 static const struct builtin_fn builtins_x86_common[] = {
44 { "__builtin_ia32_pause", &void_ctype, 0, },
45 { }
46 };
47
48
init_i386(const struct target * target)49 static void init_i386(const struct target *target)
50 {
51 fast16_ctype = &int_ctype;
52 ufast16_ctype = &uint_ctype;
53 fast32_ctype = &int_ctype;
54 ufast32_ctype = &uint_ctype;
55
56 init_x86_common(target);
57 }
58
59 const struct target target_i386 = {
60 .mach = MACH_I386,
61 .bitness = ARCH_LP32,
62 .big_endian = 0,
63 .unsigned_char = 0,
64
65 .wchar = &long_ctype,
66 .bits_in_longdouble = 96,
67 .max_fp_alignment = 4,
68
69 .target_64bit = &target_x86_64,
70
71 .init = init_i386,
72 .predefine = predefine_i386,
73 .builtins = builtins_x86_common,
74 };
75
76
init_x86_x32(const struct target * target)77 static void init_x86_x32(const struct target *target)
78 {
79 init_x86_common(target);
80
81 max_int_alignment = 8;
82
83 fast16_ctype = &int_ctype;
84 ufast16_ctype = &uint_ctype;
85 fast32_ctype = &int_ctype;
86 ufast32_ctype = &uint_ctype;
87 wchar_ctype = &long_ctype;
88 }
89
90 static const struct target target_x86_x32 = {
91 .mach = MACH_X86_64,
92 .bitness = ARCH_X32,
93 .big_endian = 0,
94 .unsigned_char = 0,
95 .has_int128 = 1,
96
97 .bits_in_longdouble = 128,
98 .max_fp_alignment = 16,
99
100 .target_32bit = &target_i386,
101 .target_64bit = &target_x86_64,
102
103 .init = init_x86_x32,
104 .predefine = predefine_x86_64,
105 };
106
107
init_x86_64(const struct target * target)108 static void init_x86_64(const struct target *target)
109 {
110 init_x86_common(target);
111
112 switch (arch_os) {
113 case OS_CYGWIN:
114 break;
115 case OS_DARWIN:
116 int64_ctype = &llong_ctype;
117 uint64_ctype = &ullong_ctype;
118 wint_ctype = &int_ctype;
119 fast16_ctype = &short_ctype;
120 ufast16_ctype = &ushort_ctype;
121 fast32_ctype = &int_ctype;
122 ufast32_ctype = &uint_ctype;
123 fast64_ctype = &llong_ctype;
124 ufast64_ctype = &ullong_ctype;
125 break;
126 case OS_FREEBSD:
127 fast16_ctype = &short_ctype;
128 ufast16_ctype = &ushort_ctype;
129 fast32_ctype = &int_ctype;
130 ufast32_ctype = &uint_ctype;
131 break;
132 case OS_NETBSD:
133 fast8_ctype = &int_ctype;
134 ufast8_ctype = &uint_ctype;
135 fast16_ctype = &int_ctype;
136 ufast16_ctype = &uint_ctype;
137 fast32_ctype = &int_ctype;
138 ufast32_ctype = &uint_ctype;
139 wint_ctype = &int_ctype;
140 break;
141 case OS_OPENBSD:
142 fast32_ctype = &int_ctype;
143 ufast32_ctype = &uint_ctype;
144 int64_ctype = &llong_ctype;
145 uint64_ctype = &ullong_ctype;
146 intmax_ctype = &llong_ctype;
147 uintmax_ctype = &ullong_ctype;
148 least64_ctype = &long_ctype;
149 uleast64_ctype = &ulong_ctype;
150 break;
151 }
152 }
153
154 const struct target target_x86_64 = {
155 .mach = MACH_X86_64,
156 .bitness = ARCH_LP64,
157 .big_endian = 0,
158 .unsigned_char = 0,
159 .has_int128 = 1,
160
161 .bits_in_longdouble = 128,
162 .max_fp_alignment = 16,
163
164 .target_32bit = &target_i386,
165 .target_x32bit = &target_x86_x32,
166
167 .init = init_x86_64,
168 .predefine = predefine_x86_64,
169 .builtins = builtins_x86_common,
170 };
171