|
12 | 12 | #include "ansi_c_parser.h"
|
13 | 13 | #include "ansi_c_typecheck.h"
|
14 | 14 |
|
| 15 | +#include <util/config.h> |
| 16 | + |
15 | 17 | #include <cstring>
|
16 | 18 | #include <ostream>
|
17 | 19 | #include <sstream>
|
18 | 20 |
|
19 |
| -const char windows_headers[]= |
20 |
| - "int __noop();\n" |
21 |
| - "int __assume(int);\n"; |
22 |
| - |
23 | 21 | //! Advance to the next line
|
24 | 22 | static const char *next_line(const char *line)
|
25 | 23 | {
|
@@ -93,7 +91,8 @@ static bool convert(
|
93 | 91 |
|
94 | 92 | symbol_tablet new_symbol_table;
|
95 | 93 |
|
96 |
| - // very recursive! |
| 94 | + // this is recursive -- builtin_factory is called |
| 95 | + // from the typechecker |
97 | 96 | if(ansi_c_typecheck(
|
98 | 97 | ansi_c_parser.parse_tree,
|
99 | 98 | new_symbol_table,
|
@@ -137,33 +136,96 @@ bool builtin_factory(
|
137 | 136 | std::string code;
|
138 | 137 | ansi_c_internal_additions(code);
|
139 | 138 | s << code;
|
140 |
| - |
141 |
| - if(find_pattern(pattern, gcc_builtin_headers_generic, s)) |
142 |
| - return convert(identifier, s, symbol_table, mh); |
143 | 139 |
|
144 |
| - if(find_pattern(pattern, gcc_builtin_headers_mem_string, s)) |
145 |
| - return convert(identifier, s, symbol_table, mh); |
| 140 | + // this is Visual C/C++ only |
| 141 | + if(config.ansi_c.os==configt::ansi_ct::ost::OS_WIN) |
| 142 | + { |
| 143 | + if(find_pattern(pattern, windows_builtin_headers, s)) |
| 144 | + return convert(identifier, s, symbol_table, mh); |
| 145 | + } |
| 146 | + |
| 147 | + // ARM stuff |
| 148 | + if(config.ansi_c.mode==configt::ansi_ct::flavourt::ARM) |
| 149 | + { |
| 150 | + if(find_pattern(pattern, arm_builtin_headers, s)) |
| 151 | + return convert(identifier, s, symbol_table, mh); |
| 152 | + } |
| 153 | + |
| 154 | + // CW stuff |
| 155 | + if(config.ansi_c.mode==configt::ansi_ct::flavourt::CODEWARRIOR) |
| 156 | + { |
| 157 | + if(find_pattern(pattern, cw_builtin_headers, s)) |
| 158 | + return convert(identifier, s, symbol_table, mh); |
| 159 | + } |
| 160 | + |
| 161 | + // GCC junk stuff, also for CLANG and ARM |
| 162 | + if(config.ansi_c.mode==configt::ansi_ct::flavourt::GCC || |
| 163 | + config.ansi_c.mode==configt::ansi_ct::flavourt::APPLE || |
| 164 | + config.ansi_c.mode==configt::ansi_ct::flavourt::ARM) |
| 165 | + { |
| 166 | + if(find_pattern(pattern, gcc_builtin_headers_generic, s)) |
| 167 | + return convert(identifier, s, symbol_table, mh); |
| 168 | + |
| 169 | + if(find_pattern(pattern, gcc_builtin_headers_math, s)) |
| 170 | + return convert(identifier, s, symbol_table, mh); |
| 171 | + |
| 172 | + if(find_pattern(pattern, gcc_builtin_headers_mem_string, s)) |
| 173 | + return convert(identifier, s, symbol_table, mh); |
| 174 | + |
| 175 | + if(find_pattern(pattern, gcc_builtin_headers_omp, s)) |
| 176 | + return convert(identifier, s, symbol_table, mh); |
146 | 177 |
|
147 |
| - if(find_pattern(pattern, gcc_builtin_headers_omp, s)) |
148 |
| - return convert(identifier, s, symbol_table, mh); |
| 178 | + if(find_pattern(pattern, gcc_builtin_headers_tm, s)) |
| 179 | + return convert(identifier, s, symbol_table, mh); |
149 | 180 |
|
150 |
| - if(find_pattern(pattern, gcc_builtin_headers_tm, s)) |
151 |
| - return convert(identifier, s, symbol_table, mh); |
| 181 | + if(find_pattern(pattern, gcc_builtin_headers_ubsan, s)) |
| 182 | + return convert(identifier, s, symbol_table, mh); |
152 | 183 |
|
153 |
| - if(find_pattern(pattern, gcc_builtin_headers_ubsan, s)) |
154 |
| - return convert(identifier, s, symbol_table, mh); |
| 184 | + if(find_pattern(pattern, clang_builtin_headers, s)) |
| 185 | + return convert(identifier, s, symbol_table, mh); |
155 | 186 |
|
156 |
| - if(find_pattern(pattern, gcc_builtin_headers_ia32, s)) |
157 |
| - return convert(identifier, s, symbol_table, mh); |
| 187 | + if(config.ansi_c.arch=="i386" || |
| 188 | + config.ansi_c.arch=="x86_64" || |
| 189 | + config.ansi_c.arch=="x32") |
| 190 | + { |
| 191 | + if(find_pattern(pattern, gcc_builtin_headers_ia32, s)) |
| 192 | + return convert(identifier, s, symbol_table, mh); |
158 | 193 |
|
159 |
| - if(find_pattern(pattern, gcc_builtin_headers_ia32_2, s)) |
160 |
| - return convert(identifier, s, symbol_table, mh); |
| 194 | + if(find_pattern(pattern, gcc_builtin_headers_ia32_2, s)) |
| 195 | + return convert(identifier, s, symbol_table, mh); |
161 | 196 |
|
162 |
| - if(find_pattern(pattern, gcc_builtin_headers_ia32_3, s)) |
163 |
| - return convert(identifier, s, symbol_table, mh); |
| 197 | + if(find_pattern(pattern, gcc_builtin_headers_ia32_3, s)) |
| 198 | + return convert(identifier, s, symbol_table, mh); |
164 | 199 |
|
165 |
| - if(find_pattern(pattern, gcc_builtin_headers_ia32_4, s)) |
166 |
| - return convert(identifier, s, symbol_table, mh); |
| 200 | + if(find_pattern(pattern, gcc_builtin_headers_ia32_4, s)) |
| 201 | + return convert(identifier, s, symbol_table, mh); |
| 202 | + } |
| 203 | + else if(config.ansi_c.arch=="arm64" || |
| 204 | + config.ansi_c.arch=="armel" || |
| 205 | + config.ansi_c.arch=="armhf" || |
| 206 | + config.ansi_c.arch=="arm") |
| 207 | + { |
| 208 | + if(find_pattern(pattern, gcc_builtin_headers_arm, s)) |
| 209 | + return convert(identifier, s, symbol_table, mh); |
| 210 | + } |
| 211 | + else if(config.ansi_c.arch=="mips64el" || |
| 212 | + config.ansi_c.arch=="mipsn32el" || |
| 213 | + config.ansi_c.arch=="mipsel" || |
| 214 | + config.ansi_c.arch=="mips64" || |
| 215 | + config.ansi_c.arch=="mipsn32" || |
| 216 | + config.ansi_c.arch=="mips") |
| 217 | + { |
| 218 | + if(find_pattern(pattern, gcc_builtin_headers_mips, s)) |
| 219 | + return convert(identifier, s, symbol_table, mh); |
| 220 | + } |
| 221 | + else if(config.ansi_c.arch=="powerpc" || |
| 222 | + config.ansi_c.arch=="ppc64" || |
| 223 | + config.ansi_c.arch=="ppc64le") |
| 224 | + { |
| 225 | + if(find_pattern(pattern, gcc_builtin_headers_power, s)) |
| 226 | + return convert(identifier, s, symbol_table, mh); |
| 227 | + } |
| 228 | + } |
167 | 229 |
|
168 | 230 | return true;
|
169 | 231 | }
|
0 commit comments