fix null-pointer crash with with ident same as one of the attributes
[smatch.git] / target.h
blob92b8af9169d72f94958244084afc326777585714
1 #ifndef TARGET_H
2 #define TARGET_H
4 #include "machine.h"
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;
38 * For "__attribute__((aligned))"
40 extern int max_alignment;
43 * Integer data types
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;
53 extern int max_int_alignment;
56 * Floating point data types
58 extern int bits_in_float;
59 extern int bits_in_double;
60 extern int bits_in_longdouble;
62 extern int max_fp_alignment;
65 * Pointer data type
67 extern int bits_in_pointer;
68 extern int pointer_alignment;
71 * Enum data types
73 extern int bits_in_enum;
74 extern int enum_alignment;
76 struct asm_operand;
77 struct builtin_fn;
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;
88 struct symbol *wchar;
89 struct symbol *wint;
91 unsigned int bits_in_longdouble;
92 unsigned int max_fp_alignment;
94 const struct target *target_32bit;
95 const struct target *target_x32bit;
96 const struct target *target_64bit;
98 const struct builtin_fn *builtins;
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);
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;
132 /* target.c */
133 extern const struct target *arch_target;
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);
141 * Helper functions for converting bits to bytes and vice versa.
144 static inline int bits_to_bytes(int bits)
146 return bits >= 0 ? (bits + bits_in_char - 1) / bits_in_char : -1;
149 static inline int bytes_to_bits(int bytes)
151 return bytes * bits_in_char;
154 static inline unsigned long array_element_offset(unsigned long base_bits, int idx)
156 int fragment = base_bits % bits_in_char;
157 if (fragment)
158 base_bits += bits_in_char - fragment;
159 return base_bits * idx;
162 #endif