2 # -----------------------------------------------------------------------------
7 my $cc = $ENV{'REAL_CC'} || 'cc';
8 my $check = $ENV{'CHECK'} || 'sparse';
30 # Look for a .c file. We don't want to run the checker on .o or .so files
32 $do_check = 1 if /^[^-].*\.c$/;
35 $do_check = 1 if $_ eq '-';
37 if (/^-(o|MF|MT|MQ)$/) {
38 # Need to be checked explicitly since otherwise
39 # the argument would be processed as a
40 # (non-existant) source file or as an option.
41 die ("$0: missing argument for $_") if !@ARGV;
45 # Ignore the extension if '-x c' is given.
47 die ("$0: missing argument for $_") if !@ARGV;
48 die ("$0: invalid argument for $_") if $ARGV[0] ne 'c';
55 $gendeps = 1 if /^-(M|MM)$/;
57 if (/^-target=(.*)$/) {
58 $check .= &add_specs
($1);
63 if ($_ eq '-no-compile') {
68 if (/^-gcc-base-dir$/) {
69 $gcc_base_dir = shift @ARGV;
70 die ("$0: missing argument for -gcc-base-dir option") if !$gcc_base_dir;
74 if (/^-multiarch-dir$/) {
75 $multiarch_dir = shift @ARGV;
76 die ("$0: missing argument for -multiarch-dir option") if !$multiarch_dir;
80 # If someone adds "-E", don't pre-process twice.
81 $do_compile = 0 if $_ eq '-E';
83 $verbose = 1 if $_ eq '-v';
86 my $this_arg = ' ' . "e_arg
($_);
87 $cc .= $this_arg unless &check_only_option
($_);
98 $check .= &add_specs
('host_arch_specs');
99 $check .= &add_specs
('host_os_specs');
102 $gcc_base_dir = qx($ccom -print-file
-name
=) if !$gcc_base_dir;
103 chomp($gcc_base_dir); # possibly remove '\n' from compiler
104 $check .= " -gcc-base-dir " . $gcc_base_dir if $gcc_base_dir;
106 $multiarch_dir = qx($ccom -print-multiarch
) if ! defined $multiarch_dir;
107 chomp($multiarch_dir); # possibly remove '\n' from compiler
108 $check .= " -multiarch-dir " . $multiarch_dir if $multiarch_dir;
110 print "$check\n" if $verbose;
119 print "$cc\n" if $verbose;
125 # -----------------------------------------------------------------------------
126 # Check if an option is for "check" only.
128 sub check_only_option
{
130 return 1 if $arg =~ /^-W(no-?)?(address-space|bitwise|cast-to-as|cast-truncate|constant-suffix|context|decl|default-bitfield-sign|designated-init|do-while|enum-mismatch|external-function-has-definition|init-cstring|memcpy-max-count|non-pointer-null|old-initializer|one-bit-signed-bitfield|override-init-all|paren-string|ptr-subtraction-blows|return-void|sizeof-bool|sparse-all|sparse-error|transparent-union|typesign|undef|unknown-attribute)$/;
131 return 1 if $arg =~ /^-v(no-?)?(entry|dead)$/;
132 return 1 if $arg =~ /^-f(dump-ir|memcpy-max-count|diagnostic-prefix)(=\S*)?$/;
133 return 1 if $arg =~ /^-f(mem2reg|optim)(-enable|-disable|=last)?$/;
134 return 1 if $arg =~ /^-msize-(long|llp64)$/;
138 # -----------------------------------------------------------------------------
139 # Simple arg-quoting function. Just adds backslashes when needed.
143 return "''" if $arg eq '';
146 m
|^[-a
-zA
-Z0
-9._
/,=]+$| ?
$_ : "\\" . $_;
147 } (split (//, $arg)));
150 # -----------------------------------------------------------------------------
153 my ($has_inf,$has_qnan,$dec_dig,@bitsizes) = @_;
154 my $result = " -D__FLT_RADIX__=2";
155 $result .= " -D__FINITE_MATH_ONLY__=" . ($has_inf || $has_qnan ?
'0' : '1');
156 $result .= " -D__DECIMAL_DIG__=$dec_dig";
161 'MIN' => '1.17549435e-38',
162 'MAX' => '3.40282347e+38',
163 'EPSILON' => '1.19209290e-7',
164 'DENORM_MIN' => '1.40129846e-45',
168 'MIN' => '2.2250738585072014e-308',
169 'MAX' => '1.7976931348623157e+308',
170 'EPSILON' => '2.2204460492503131e-16',
171 'DENORM_MIN' => '4.9406564584124654e-324',
175 'MIN' => '3.36210314311209350626e-4932',
176 'MAX' => '1.18973149535723176502e+4932',
177 'EPSILON' => '1.08420217248550443401e-19',
178 'DENORM_MIN' => '3.64519953188247460253e-4951',
182 'MIN' => '3.36210314311209350626267781732175260e-4932',
183 'MAX' => '1.18973149535723176508575932662800702e+4932',
184 'EPSILON' => '1.92592994438723585305597794258492732e-34',
185 'DENORM_MIN' => '6.47517511943802511092443895822764655e-4966',
189 my @types = (['FLT','F'], ['DBL',''], ['LDBL','L']);
191 my ($mant_bits,$exp_bits) = @
{ shift @bitsizes };
192 my ($name,$suffix) = @
{ shift @types };
194 my $h = $constants{$mant_bits};
195 die "$0: weird number of mantissa bits." unless $h;
197 my $mant_dig = int (($mant_bits - 1) * log (2) / log (10));
198 my $max_exp = 1 << ($exp_bits - 1);
199 my $min_exp = 3 - $max_exp;
200 my $max_10_exp = int ($max_exp * log (2) / log (10));
201 my $min_10_exp = -int (-$min_exp * log (2) / log (10));
203 $result .= " -D__${name}_MANT_DIG__=$mant_bits";
204 $result .= " -D__${name}_DIG__=$mant_dig";
205 $result .= " -D__${name}_MIN_EXP__='($min_exp)'";
206 $result .= " -D__${name}_MAX_EXP__=$max_exp";
207 $result .= " -D__${name}_MIN_10_EXP__='($min_10_exp)'";
208 $result .= " -D__${name}_MAX_10_EXP__=$max_10_exp";
209 $result .= " -D__${name}_HAS_INFINITY__=" . ($has_inf ?
'1' : '0');
210 $result .= " -D__${name}_HAS_QUIET_NAN__=" . ($has_qnan ?
'1' : '0');;
212 foreach my $inf (sort keys %$h) {
213 $result .= " -D__${name}_${inf}__=" . $h->{$inf} . $suffix;
219 # -----------------------------------------------------------------------------
223 if ($spec eq 'sunos') {
224 return &add_specs
('unix') .
225 ' -D__sun__=1 -D__sun=1 -Dsun=1' .
226 ' -D__svr4__=1 -DSVR4=1' .
229 ' -D_SOLARIS_THREADS' .
230 ' -DNULL="((void *)0)"';
231 } elsif ($spec eq 'linux') {
232 return &add_specs
('unix') .
233 ' -D__linux__=1 -D__linux=1 -Dlinux=1';
234 } elsif ($spec eq 'gnu/kfreebsd') {
235 return &add_specs
('unix') .
236 ' -D__FreeBSD_kernel__=1';
237 } elsif ($spec eq 'openbsd') {
238 return &add_specs
('unix') .
240 } elsif ($spec eq 'freebsd') {
241 return &add_specs
('unix') .
243 } elsif ($spec eq 'netbsd') {
244 return &add_specs
('unix') .
246 } elsif ($spec eq 'darwin') {
248 ' -D__APPLE__=1 -D__APPLE_CC__=1 -D__MACH__=1';
249 } elsif ($spec eq 'gnu') { # Hurd
250 return &add_specs
('unix') . # So, GNU is Unix, uh?
251 ' -D__GNU__=1 -D__gnu_hurd__=1 -D__MACH__=1';
252 } elsif ($spec eq 'unix') {
253 return ' -Dunix=1 -D__unix=1 -D__unix__=1';
254 } elsif ( $spec =~ /^cygwin/) {
255 return &add_specs
('unix') .
258 ($m32 ?
' -D__CYGWIN32__=1' : '') .
259 " -D'_cdecl=__attribute__((__cdecl__))'" .
260 " -D'__cdecl=__attribute__((__cdecl__))'" .
261 " -D'_stdcall=__attribute__((__stdcall__))'" .
262 " -D'__stdcall=__attribute__((__stdcall__))'" .
263 " -D'_fastcall=__attribute__((__fastcall__))'" .
264 " -D'__fastcall=__attribute__((__fastcall__))'" .
265 " -D'__declspec(x)=__attribute__((x))'";
266 } elsif ($spec eq 'i386') {
270 &float_types
(1, 1, 21, [24,8], [53,11], [64,15]));
271 } elsif ($spec eq 'sparc') {
274 &float_types
(1, 1, 33, [24,8], [53,11], [113,15]));
275 } elsif ($spec eq 'sparc64') {
278 &float_types
(1, 1, 33, [24,8], [53,11], [113,15]));
279 } elsif ($spec eq 'x86_64') {
280 return (' --arch=x86_64' .
281 &float_types
(1, 1, 33, [24,8], [53,11], [113,15]));
282 } elsif ($spec eq 'ppc') {
283 return (' --arch=ppc' .
284 &float_types
(1, 1, 21, [24,8], [53,11], [113,15]));
285 } elsif ($spec eq 'ppc64') {
288 &float_types
(1, 1, 21, [24,8], [53,11], [113,15]));
289 } elsif ($spec eq 'ppc64be') {
290 return &add_specs
('ppc64') . ' -mbig-endian -D_CALL_ELF=1';
291 } elsif ($spec eq 'ppc64le') {
292 return &add_specs
('ppc64') . ' -mlittle-endian -D_CALL_ELF=2';
293 } elsif ($spec eq 's390x') {
294 return (' -D_BIG_ENDIAN' .
296 &float_types
(1, 1, 36, [24,8], [53,11], [113,15]));
297 } elsif ($spec eq 'riscv32') {
298 return (' --arch=riscv32' .
299 &float_types
(1, 1, 33, [24,8], [53,11], [53,11]));
300 } elsif ($spec eq 'riscv64') {
301 return (' --arch=riscv64' .
302 &float_types
(1, 1, 33, [24,8], [53,11], [113,15]));
303 } elsif ($spec eq 'arm') {
304 return (' --arch=arm' .
305 &float_types
(1, 1, 36, [24,8], [53,11], [53, 11]));
306 } elsif ($spec eq 'arm+hf') {
307 return &add_specs
('arm') . ' -mfloat-abi=hard';
308 } elsif ($spec eq 'aarch64') {
309 return (' --arch=aarch64' .
310 &float_types
(1, 1, 36, [24,8], [53,11], [113,15]));
311 } elsif ($spec eq 'host_os_specs') {
314 return &add_specs
(lc $os);
315 } elsif ($spec eq 'host_arch_specs') {
319 $gccmachine = `$ccom -dumpmachine`;
322 if ($gccmachine =~ '^aarch64-') {
323 return &add_specs
('aarch64');
324 } elsif ($gccmachine =~ '^arm-.*eabihf$') {
325 return &add_specs
('arm+hf');
326 } elsif ($gccmachine =~ '^arm-') {
327 return &add_specs
('arm');
328 } elsif ($gccmachine =~ '^i[23456]86-') {
329 return &add_specs
('i386');
330 } elsif ($gccmachine =~ '^(powerpc|ppc)64le-') {
331 return &add_specs
('ppc64le');
332 } elsif ($gccmachine =~ '^s390x-') {
333 return &add_specs
('s390x');
334 } elsif ($gccmachine eq 'x86_64-linux-gnux32') {
335 return &add_specs
('x86_64') . ' -mx32';
336 } elsif ($gccmachine =~ '^x86_64-') {
337 return &add_specs
('x86_64');
340 # fall back to uname -m to determine the specifics.
341 # Note: this is only meaningful when using natively
342 # since information about the host is used to
343 # guess characteristics of the target.
347 if ($arch =~ /^(i.?86|athlon)$/i) {
348 return &add_specs
('i386');
349 } elsif ($arch =~ /^(sun4u)$/i) {
350 return &add_specs
('sparc');
351 } elsif ($arch =~ /^(x86_64)$/i) {
352 return &add_specs
('x86_64');
353 } elsif ($arch =~ /^(ppc)$/i) {
354 return &add_specs
('ppc');
355 } elsif ($arch =~ /^(ppc64)$/i) {
356 return &add_specs
('ppc64be');
357 } elsif ($arch =~ /^(ppc64le)$/i) {
358 return &add_specs
('ppc64le');
359 } elsif ($arch =~ /^(s390x)$/i) {
360 return &add_specs
('s390x');
361 } elsif ($arch =~ /^(sparc64)$/i) {
362 return &add_specs
('sparc64');
363 } elsif ($arch =~ /^arm(?:v[78]l)?$/i) {
364 return &add_specs
('arm');
365 } elsif ($arch =~ /^(aarch64)$/i) {
366 return &add_specs
('aarch64');
369 die "$0: invalid specs: $spec\n";
373 # -----------------------------------------------------------------------------