aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/target.c
blob: c2ab55490ad0a68059cd908094b93581f018339a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <stdio.h>

#include "symbol.h"
#include "target.h"
#include "machine.h"

struct symbol *size_t_ctype = &uint_ctype;
struct symbol *ssize_t_ctype = &int_ctype;
struct symbol *intmax_ctype = &llong_ctype;
struct symbol *uintmax_ctype = &ullong_ctype;
struct symbol *int64_ctype = &long_ctype;
struct symbol *uint64_ctype = &ulong_ctype;
struct symbol *int32_ctype = &int_ctype;
struct symbol *uint32_ctype = &uint_ctype;
struct symbol *wchar_ctype = &int_ctype;
struct symbol *wint_ctype = &uint_ctype;

/*
 * For "__attribute__((aligned))"
 */
int max_alignment = 16;

/*
 * Integer data types
 */
int bits_in_bool = 1;
int bits_in_char = 8;
int bits_in_short = 16;
int bits_in_int = 32;
int bits_in_long = 32;
int bits_in_longlong = 64;
int bits_in_longlonglong = 128;

int max_int_alignment = 4;

/*
 * Floating point data types
 */
int bits_in_float = 32;
int bits_in_double = 64;
int bits_in_longdouble = 128;

int max_fp_alignment = 16;

/*
 * Pointer data type
 */
int bits_in_pointer = 32;
int pointer_alignment = 4;

/*
 * Enum data types
 */
int bits_in_enum = 32;
int enum_alignment = 4;


void init_target(void)
{
	switch (arch_mach) {
	case MACH_X86_64:
		if (arch_m64 == ARCH_LP64)
			break;
		/* fall through */
	case MACH_I386:
	case MACH_M68K:
	case MACH_SPARC32:
	case MACH_PPC32:
		wchar_ctype = &long_ctype;
		break;
	case MACH_ARM:
	case MACH_ARM64:
		wchar_ctype = &uint_ctype;
		break;
	default:
		break;
	}

	switch (arch_mach) {
	case MACH_MIPS64:
		if (arch_m64 == ARCH_LP64)
			break;
		/* fall through */
	case MACH_M68K:
	case MACH_SPARC32:
	case MACH_PPC32:
	case MACH_MIPS32:
	case MACH_RISCV32:
		arch_m64 = ARCH_LP32;
		int32_ctype = &long_ctype;
		uint32_ctype = &ulong_ctype;
		break;
	default:
		break;
	}

	switch (arch_mach) {
	case MACH_ARM:
	case MACH_MIPS32:
	case MACH_S390X:
	case MACH_SPARC32:
		bits_in_longdouble = 64;
		max_fp_alignment = 8;
		break;
	case MACH_X86_64:
		if (arch_m64 == ARCH_LP64 || arch_m64 == ARCH_X32)
			break;
		/* fall through */
	case MACH_I386:
	case MACH_M68K:
		bits_in_longdouble = 96;
		max_fp_alignment = 4;
		break;
	default:
		break;
	}

	switch (arch_m64) {
	case ARCH_X32:
		max_int_alignment = 8;
		int64_ctype = &llong_ctype;
		uint64_ctype = &ullong_ctype;
		break;
	case ARCH_LP32:
		/* default values */
		int64_ctype = &llong_ctype;
		uint64_ctype = &ullong_ctype;
		intmax_ctype = &llong_ctype;
		uintmax_ctype = &ullong_ctype;
		break;
	case ARCH_LP64:
		bits_in_long = 64;
		max_int_alignment = 8;
		size_t_ctype = &ulong_ctype;
		ssize_t_ctype = &long_ctype;
		intmax_ctype = &long_ctype;
		uintmax_ctype = &ulong_ctype;
		goto case_64bit_common;
	case ARCH_LLP64:
		bits_in_long = 32;
		max_int_alignment = 8;
		size_t_ctype = &ullong_ctype;
		ssize_t_ctype = &llong_ctype;
		int64_ctype = &llong_ctype;
		uint64_ctype = &ullong_ctype;
		goto case_64bit_common;
	case_64bit_common:
		bits_in_pointer = 64;
		pointer_alignment = 8;
		break;
	}

#if defined(__CYGWIN__)
	wchar_ctype = &ushort_ctype;
#endif
#if defined(__FreeBSD__) || defined(__APPLE__)
	wint_ctype = &int_ctype;
#endif
#if defined(__APPLE__)
	int64_ctype = &llong_ctype;
	uint64_ctype = &ullong_ctype;
#endif
}