8 struct symbol
*size_t_ctype
= &ulong_ctype
;
9 struct symbol
*ssize_t_ctype
= &long_ctype
;
10 struct symbol
*intmax_ctype
= &long_ctype
;
11 struct symbol
*uintmax_ctype
= &ulong_ctype
;
12 struct symbol
*int64_ctype
= &long_ctype
;
13 struct symbol
*uint64_ctype
= &ulong_ctype
;
14 struct symbol
*int32_ctype
= &int_ctype
;
15 struct symbol
*uint32_ctype
= &uint_ctype
;
16 struct symbol
*wchar_ctype
= &int_ctype
;
17 struct symbol
*wint_ctype
= &uint_ctype
;
20 * For "__attribute__((aligned))"
22 int max_alignment
= 16;
29 int bits_in_short
= 16;
31 int bits_in_long
= 64;
32 int bits_in_longlong
= 64;
33 int bits_in_longlonglong
= 128;
35 int max_int_alignment
= 8;
38 * Floating point data types
40 int bits_in_float
= 32;
41 int bits_in_double
= 64;
42 int bits_in_longdouble
= 128;
44 int max_fp_alignment
= 16;
49 int bits_in_pointer
= 64;
50 int pointer_alignment
= 8;
55 int bits_in_enum
= 32;
56 int enum_alignment
= 4;
59 static const struct target
*targets
[] = {
60 [MACH_ALPHA
] = &target_alpha
,
61 [MACH_ARM
] = &target_arm
,
62 [MACH_ARM64
] = &target_arm64
,
63 [MACH_I386
] = &target_i386
,
64 [MACH_BFIN
] = &target_bfin
,
65 [MACH_X86_64
] = &target_x86_64
,
66 [MACH_MICROBLAZE
] = &target_microblaze
,
67 [MACH_MIPS32
] = &target_mips32
,
68 [MACH_MIPS64
] = &target_mips64
,
69 [MACH_NIOS2
] = &target_nios2
,
70 [MACH_PPC32
] = &target_ppc32
,
71 [MACH_PPC64
] = &target_ppc64
,
72 [MACH_RISCV32
] = &target_riscv32
,
73 [MACH_RISCV64
] = &target_riscv64
,
74 [MACH_S390
] = &target_s390
,
75 [MACH_S390X
] = &target_s390x
,
76 [MACH_SPARC32
] = &target_sparc32
,
77 [MACH_SPARC64
] = &target_sparc64
,
78 [MACH_M68K
] = &target_m68k
,
79 [MACH_UNKNOWN
] = &target_default
,
81 const struct target
*arch_target
= &target_default
;
83 enum machine
target_parse(const char *name
)
85 static const struct arch
{
90 { "alpha", MACH_ALPHA
, 64, },
91 { "aarch64", MACH_ARM64
, 64, },
92 { "arm64", MACH_ARM64
, 64, },
93 { "arm", MACH_ARM
, 32, },
94 { "i386", MACH_I386
, 32, },
95 { "bfin", MACH_BFIN
, 32, },
96 { "m68k", MACH_M68K
, 32, },
97 { "microblaze", MACH_MICROBLAZE
,32, },
98 { "mips", MACH_MIPS32
, 0, },
99 { "nios2", MACH_NIOS2
, 32, },
100 { "powerpc", MACH_PPC32
, 0, },
101 { "ppc", MACH_PPC32
, 0, },
102 { "riscv", MACH_RISCV32
, 0, },
103 { "s390x", MACH_S390X
, 64, },
104 { "s390", MACH_S390
, 32, },
105 { "sparc", MACH_SPARC32
, 0, },
106 { "x86_64", MACH_X86_64
, 64, },
107 { "x86-64", MACH_X86_64
, 64, },
110 const struct arch
*p
;
112 for (p
= &archs
[0]; p
->name
; p
++) {
113 size_t len
= strlen(p
->name
);
114 if (strncmp(p
->name
, name
, len
) == 0) {
115 enum machine mach
= p
->mach
;
116 const char *suf
= name
+ len
;
120 if (!strcmp(suf
, "") || !strcmp(suf
, "32")) {
122 } else if (!strcmp(suf
, "64")) {
125 die("invalid architecture: %s", name
);
129 die("invalid architecture: %s", name
);
140 void target_config(enum machine mach
)
142 const struct target
*target
= targets
[mach
];
144 arch_target
= target
;
145 arch_m64
= target
->bitness
;
146 arch_big_endian
= target
->big_endian
;
148 funsigned_char
= target
->unsigned_char
;
152 void target_init(void)
154 const struct target
*target
= arch_target
;
158 max_int_alignment
= 4;
162 bits_in_pointer
= 32;
163 pointer_alignment
= 4;
164 size_t_ctype
= &uint_ctype
;
165 ssize_t_ctype
= &int_ctype
;
166 int64_ctype
= &llong_ctype
;
167 uint64_ctype
= &ullong_ctype
;
168 intmax_ctype
= &llong_ctype
;
169 uintmax_ctype
= &ullong_ctype
;
170 if (target
->target_32bit
)
171 target
= target
->target_32bit
;
176 size_t_ctype
= &ullong_ctype
;
177 ssize_t_ctype
= &llong_ctype
;
178 int64_ctype
= &llong_ctype
;
179 uint64_ctype
= &ullong_ctype
;
180 intmax_ctype
= &llong_ctype
;
181 uintmax_ctype
= &ullong_ctype
;
184 if (target
->target_64bit
)
185 target
= target
->target_64bit
;
188 arch_target
= target
;
194 wchar_ctype
= target
->wchar
;
196 wint_ctype
= target
->wint
;
197 if (target
->bits_in_longdouble
)
198 bits_in_longdouble
= target
->bits_in_longdouble
;
199 if (target
->max_fp_alignment
)
200 max_fp_alignment
= target
->max_fp_alignment
;
203 target
->init(target
);
205 if (arch_msize_long
|| target
->size_t_long
) {
206 size_t_ctype
= &ulong_ctype
;
207 ssize_t_ctype
= &long_ctype
;
210 wchar_ctype
= &ushort_ctype
;