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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
builtins = foldr doIdent (foldr doTypeDef emptyDefTable typedefs) idents
where doTypeDef d = snd . defineTypeDef (identOfTypeDef d) d
doIdent d = snd . defineGlobalIdent (declIdent d) d
dName s = VarName (builtinIdent s) Nothing
param ty = ParamDecl (VarDecl
NoName
(DeclAttrs noFunctionAttrs (Auto False) [])
ty) undefNode
fnAttrs = DeclAttrs noFunctionAttrs (FunLinkage ExternalLinkage) []
varAttrs = DeclAttrs noFunctionAttrs (Static InternalLinkage False) []
fnType r as = FunctionType (FunType r (map param as) False) noAttributes
fnType' r as = FunctionType (FunType r (map param as) True) noAttributes
func n r as = Declaration
(Decl
(VarDecl (dName n) fnAttrs (fnType r as))
undefNode)
func' n r as = Declaration
(Decl
(VarDecl (dName n) fnAttrs (fnType' r as))
undefNode)
var n t = Declaration
(Decl (VarDecl (dName n) varAttrs t) undefNode)
typedef n t = TypeDef (builtinIdent n) t [] undefNode
typedefs = [ typedef "__builtin_va_list"
valistType
]
idents = [ func "__builtin_expect"
(integral TyLong)
[integral TyLong, integral TyLong]
, func "__builtin_bswap16"
uint16_tType
[uint16_tType]
, func "__builtin_bswap32"
uint32_tType
[uint32_tType]
, func "__builtin_bswap64"
uint64_tType
[uint64_tType]
, func "__builtin_fabs"
(floating TyDouble)
[floating TyDouble]
, func "__builtin_fabsf"
(floating TyFloat)
[floating TyFloat]
, func "__builtin_fabsl"
(floating TyLDouble)
[floating TyLDouble]
, func "__builtin_inf" (floating TyDouble) []
, func "__builtin_inff" (floating TyFloat) []
, func "__builtin_infl" (floating TyLDouble) []
, func "__builtin_huge_val" (floating TyDouble) []
, func "__builtin_huge_valf" (floating TyFloat) []
, func "__builtin_huge_vall" (floating TyLDouble) []
, func "__builtin_copysign"
(floating TyDouble)
[ floating TyDouble, floating TyDouble ]
, func "__builtin_va_start"
voidType
[ valistType , voidPtr ]
, func "__builtin_va_end"
voidType
[valistType]
, func "__builtin_va_copy"
voidType
[ valistType, valistType ]
, func "__builtin_va_arg_pack" (integral TyInt) []
, func "__builtin_va_arg_pack_len" (integral TyInt) []
, func "__builtin_alloca"
voidPtr
[ size_tType ]
, func "__builtin_memcpy"
voidPtr
[ voidPtr
, constVoidPtr
, size_tType
]
, func "__builtin_strspn"
size_tType
[ constCharPtr, constCharPtr ]
, func "__builtin_strcspn"
size_tType
[ constCharPtr, constCharPtr ]
, func "__builtin_strchr"
charPtr
[ constCharPtr, integral TyInt]
, func "__builtin_strncpy"
charPtr
[ constCharPtr -- XXX: restrict
, constCharPtr -- XXX: restrict
, size_tType
]
, func "__builtin_strncat"
charPtr
[ constCharPtr -- XXX: restrict
, constCharPtr -- XXX: restrict
, size_tType
]
, func "__builtin_strcmp"
(integral TyInt)
[ constCharPtr, constCharPtr ]
, func "__builtin_strpbrk"
charPtr
[ constCharPtr, constCharPtr ]
, func "__builtin_bzero"
voidType
[ voidPtr, size_tType ]
, func "__builtin_clz"
(integral TyInt)
[ integral TyUInt ]
, func "__builtin_constant_p"
(integral TyInt)
[DirectType (TyBuiltin TyAny) noTypeQuals noAttributes]
-- XXX: I don't know if the following has the
-- correct type. It doesn't seem to be
-- documented.
, func "__builtin_extract_return_addr"
voidPtr
[ voidPtr ]
, func "__builtin_return_address"
voidPtr
[ integral TyUInt ]
, func "__builtin_frame_address"
voidPtr
[ integral TyUInt ]
, func "__builtin_expect"
(integral TyLong)
[ integral TyLong, integral TyLong ]
, func "__builtin_prefetch"
voidType
[ constVoidPtr ]
, var "__func__"
stringType
, var "__PRETTY_FUNCTION__"
stringType
, var "__FUNCTION__"
stringType
-- Builtin GCC error checking functions
, func "__builtin_object_size"
size_tType
[ voidPtr, integral TyInt ]
, func "__builtin___memcpy_chk"
voidPtr
[ voidPtr, constVoidPtr, size_tType, size_tType ]
, func "__builtin___mempcpy_chk"
voidPtr
[ voidPtr, constVoidPtr, size_tType, size_tType ]
, func "__builtin___memmove_chk"
voidPtr
[ voidPtr, constVoidPtr, size_tType, size_tType ]
, func "__builtin___memset_chk"
voidPtr
[ voidPtr, integral TyInt, size_tType, size_tType ]
, func "__builtin___strcpy_chk"
charPtr
[ constCharPtr -- XXX: restrict
, constCharPtr -- XXX: restrict
, size_tType
]
, func "__builtin___stpcpy_chk"
charPtr
[ constCharPtr -- XXX: restrict
, constCharPtr -- XXX: restrict
, size_tType
]
, func "__builtin___strncpy_chk"
charPtr
[ constCharPtr -- XXX: restrict
, constCharPtr -- XXX: restrict
, size_tType
, size_tType
]
, func "__builtin___strcat_chk"
charPtr
[ constCharPtr -- XXX: restrict
, constCharPtr -- XXX: restrict
, size_tType
]
, func "__builtin___strncat_chk"
charPtr
[ constCharPtr -- XXX: restrict
, constCharPtr -- XXX: restrict
, size_tType
, size_tType
]
, func' "__builtin___sprintf_chk"
(integral TyInt)
[ charPtr
, integral TyInt
, size_tType
, constCharPtr
]
, func' "__builtin___snprintf_chk"
(integral TyInt)
[ charPtr
, size_tType
, integral TyInt
, size_tType
, constCharPtr
]
, func "__builtin___vsprintf_chk"
(integral TyInt)
[ charPtr
, integral TyInt
, size_tType
, constCharPtr
, valistType
]
, func "__builtin___vsnprintf_chk"
(integral TyInt)
[ charPtr
, size_tType
, integral TyInt
, size_tType
, constCharPtr
, valistType
]
]