xref: /illumos-gate/usr/src/tools/smatch/src/target.c (revision c85f09cc)
1 #include <stdio.h>
2 
3 #include "symbol.h"
4 #include "target.h"
5 #include "machine.h"
6 
7 struct symbol *size_t_ctype = &ulong_ctype;
8 struct symbol *ssize_t_ctype = &long_ctype;
9 struct symbol *intmax_ctype = &llong_ctype;
10 struct symbol *uintmax_ctype = &ullong_ctype;
11 struct symbol *int64_ctype = &long_ctype;
12 struct symbol *uint64_ctype = &ulong_ctype;
13 struct symbol *int32_ctype = &int_ctype;
14 struct symbol *uint32_ctype = &uint_ctype;
15 struct symbol *wchar_ctype = &int_ctype;
16 struct symbol *wint_ctype = &uint_ctype;
17 
18 /*
19  * For "__attribute__((aligned))"
20  */
21 int max_alignment = 16;
22 
23 /*
24  * Integer data types
25  */
26 int bits_in_bool = 1;
27 int bits_in_char = 8;
28 int bits_in_short = 16;
29 int bits_in_int = 32;
30 int bits_in_long = 32;
31 int bits_in_longlong = 64;
32 int bits_in_longlonglong = 128;
33 
34 int max_int_alignment = 4;
35 
36 /*
37  * Floating point data types
38  */
39 int bits_in_float = 32;
40 int bits_in_double = 64;
41 int bits_in_longdouble = 128;
42 
43 int max_fp_alignment = 16;
44 
45 /*
46  * Pointer data type
47  */
48 int bits_in_pointer = 32;
49 int pointer_alignment = 4;
50 
51 /*
52  * Enum data types
53  */
54 int bits_in_enum = 32;
55 int enum_alignment = 4;
56 
57 
init_target(void)58 void init_target(void)
59 {
60 	switch (arch_mach) {
61 	case MACH_X86_64:
62 		if (arch_m64 == ARCH_LP64)
63 			break;
64 		/* fall through */
65 	case MACH_I386:
66 	case MACH_M68K:
67 	case MACH_SPARC32:
68 	case MACH_PPC32:
69 		wchar_ctype = &long_ctype;
70 		break;
71 	case MACH_ARM:
72 	case MACH_ARM64:
73 		wchar_ctype = &uint_ctype;
74 		break;
75 	default:
76 		break;
77 	}
78 
79 	switch (arch_mach) {
80 	case MACH_MIPS64:
81 		if (arch_m64 == ARCH_LP64)
82 			break;
83 		/* fall through */
84 	case MACH_M68K:
85 	case MACH_SPARC32:
86 	case MACH_PPC32:
87 	case MACH_MIPS32:
88 	case MACH_RISCV32:
89 		arch_m64 = ARCH_LP32;
90 		int32_ctype = &long_ctype;
91 		uint32_ctype = &ulong_ctype;
92 		break;
93 	default:
94 		break;
95 	}
96 
97 	switch (arch_mach) {
98 	case MACH_ARM:
99 	case MACH_MIPS32:
100 	case MACH_S390X:
101 	case MACH_SPARC32:
102 		bits_in_longdouble = 64;
103 		max_fp_alignment = 8;
104 		break;
105 	case MACH_X86_64:
106 		if (arch_m64 == ARCH_LP64 || arch_m64 == ARCH_X32)
107 			break;
108 		/* fall through */
109 	case MACH_I386:
110 	case MACH_M68K:
111 		bits_in_longdouble = 96;
112 		max_fp_alignment = 4;
113 		break;
114 	default:
115 		break;
116 	}
117 
118 	switch (arch_m64) {
119 	case ARCH_X32:
120 		max_int_alignment = 8;
121 		int64_ctype = &llong_ctype;
122 		uint64_ctype = &ullong_ctype;
123 		break;
124 	case ARCH_LP32:
125 		/* default values */
126 		int64_ctype = &llong_ctype;
127 		uint64_ctype = &ullong_ctype;
128 		intmax_ctype = &llong_ctype;
129 		uintmax_ctype = &ullong_ctype;
130 		break;
131 	case ARCH_LP64:
132 		bits_in_long = 64;
133 		max_int_alignment = 8;
134 		size_t_ctype = &ulong_ctype;
135 		ssize_t_ctype = &long_ctype;
136 		intmax_ctype = &long_ctype;
137 		uintmax_ctype = &ulong_ctype;
138 		goto case_64bit_common;
139 	case ARCH_LLP64:
140 		bits_in_long = 32;
141 		max_int_alignment = 8;
142 		size_t_ctype = &ullong_ctype;
143 		ssize_t_ctype = &llong_ctype;
144 		int64_ctype = &llong_ctype;
145 		uint64_ctype = &ullong_ctype;
146 		goto case_64bit_common;
147 	case_64bit_common:
148 		bits_in_pointer = 64;
149 		pointer_alignment = 8;
150 		break;
151 	}
152 
153 #if defined(__CYGWIN__)
154 	wchar_ctype = &ushort_ctype;
155 #endif
156 #if defined(__FreeBSD__) || defined(__APPLE__)
157 	wint_ctype = &int_ctype;
158 #endif
159 #if defined(__APPLE__)
160 	int64_ctype = &llong_ctype;
161 	uint64_ctype = &ullong_ctype;
162 #endif
163 }
164