• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef TARGET_H
2 #define TARGET_H
3 
4 #include "machine.h"
5 
6 extern struct symbol *size_t_ctype;
7 extern struct symbol *ssize_t_ctype;
8 extern struct symbol *ptrdiff_ctype;
9 extern struct symbol *intptr_ctype;
10 extern struct symbol *uintptr_ctype;
11 extern struct symbol *intmax_ctype;
12 extern struct symbol *uintmax_ctype;
13 extern struct symbol *int64_ctype;
14 extern struct symbol *uint64_ctype;
15 extern struct symbol *int32_ctype;
16 extern struct symbol *uint32_ctype;
17 extern struct symbol *wchar_ctype;
18 extern struct symbol *wint_ctype;
19 extern struct symbol *least8_ctype;
20 extern struct symbol *uleast8_ctype;
21 extern struct symbol *least16_ctype;
22 extern struct symbol *uleast16_ctype;
23 extern struct symbol *least32_ctype;
24 extern struct symbol *uleast32_ctype;
25 extern struct symbol *least64_ctype;
26 extern struct symbol *uleast64_ctype;
27 extern struct symbol *fast8_ctype;
28 extern struct symbol *ufast8_ctype;
29 extern struct symbol *fast16_ctype;
30 extern struct symbol *ufast16_ctype;
31 extern struct symbol *fast32_ctype;
32 extern struct symbol *ufast32_ctype;
33 extern struct symbol *fast64_ctype;
34 extern struct symbol *ufast64_ctype;
35 extern struct symbol *sig_atomic_ctype;
36 
37 /*
38  * For "__attribute__((aligned))"
39  */
40 extern int max_alignment;
41 
42 /*
43  * Integer data types
44  */
45 extern int bits_in_bool;
46 extern int bits_in_char;
47 extern int bits_in_short;
48 extern int bits_in_int;
49 extern int bits_in_long;
50 extern int bits_in_longlong;
51 extern int bits_in_longlonglong;
52 
53 extern int max_int_alignment;
54 
55 /*
56  * Floating point data types
57  */
58 extern int bits_in_float;
59 extern int bits_in_double;
60 extern int bits_in_longdouble;
61 
62 extern int max_fp_alignment;
63 
64 /*
65  * Pointer data type
66  */
67 extern int bits_in_pointer;
68 extern int pointer_alignment;
69 
70 /*
71  * Enum data types
72  */
73 extern int bits_in_enum;
74 extern int enum_alignment;
75 
76 struct asm_operand;
77 struct builtin_fn;
78 
79 struct target {
80 	enum machine	mach;
81 	enum bitness	bitness;
82 	unsigned int	big_endian:1;
83 	unsigned int	unsigned_char:1;
84 	unsigned int	size_t_long:1;
85 	unsigned int	has_int128:1;
86 	unsigned long	flags;
87 
88 	struct symbol	*wchar;
89 	struct symbol	*wint;
90 
91 	unsigned int	bits_in_longdouble;
92 	unsigned int	max_fp_alignment;
93 
94 	const struct target *target_32bit;
95 	const struct target *target_x32bit;
96 	const struct target *target_64bit;
97 
98 	const struct builtin_fn *builtins;
99 
100 	void (*init)(const struct target *self);
101 	void (*parse_march)(const char *arg);
102 	void (*predefine)(const struct target *self);
103 	const char *(*asm_constraint)(struct asm_operand *op, int c, const char *str);
104 };
105 
106 extern const struct target target_default;
107 extern const struct target target_alpha;
108 extern const struct target target_arm;
109 extern const struct target target_arm64;
110 extern const struct target target_bfin;
111 extern const struct target target_h8300;
112 extern const struct target target_m68k;
113 extern const struct target target_microblaze;
114 extern const struct target target_mips32;
115 extern const struct target target_mips64;
116 extern const struct target target_nds32;
117 extern const struct target target_nios2;
118 extern const struct target target_openrisc;
119 extern const struct target target_ppc32;
120 extern const struct target target_ppc64;
121 extern const struct target target_riscv32;
122 extern const struct target target_riscv64;
123 extern const struct target target_s390;
124 extern const struct target target_s390x;
125 extern const struct target target_sh;
126 extern const struct target target_sparc32;
127 extern const struct target target_sparc64;
128 extern const struct target target_i386;
129 extern const struct target target_x86_64;
130 extern const struct target target_xtensa;
131 
132 /* target.c */
133 extern const struct target *arch_target;
134 
135 enum machine target_parse(const char *name);
136 void target_os(const char *name);
137 void target_config(enum machine mach);
138 void target_init(void);
139 
140 /*
141  * Helper functions for converting bits to bytes and vice versa.
142  */
143 
bits_to_bytes(int bits)144 static inline int bits_to_bytes(int bits)
145 {
146 	return bits >= 0 ? (bits + bits_in_char - 1) / bits_in_char : -1;
147 }
148 
bytes_to_bits(int bytes)149 static inline int bytes_to_bits(int bytes)
150 {
151 	return bytes * bits_in_char;
152 }
153 
array_element_offset(unsigned long base_bits,int idx)154 static inline unsigned long array_element_offset(unsigned long base_bits, int idx)
155 {
156 	int fragment = base_bits % bits_in_char;
157 	if (fragment)
158 		base_bits += bits_in_char - fragment;
159 	return base_bits * idx;
160 }
161 
162 #endif
163