aboutsummaryrefslogtreecommitdiff
path: root/cgcc
diff options
context:
space:
mode:
authorwelinder@troll.com <welinder@troll.com>2004-10-05 12:44:06 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:03:29 -0700
commitcf2bde63a650ca75a04c555dec9046dac5e6f592 (patch)
tree7e0c8fbe63b31ce917e783d6c458d93fb5e894ec /cgcc
parentMerge http://sparse-mw.bkbits.net:8080/janitorial (diff)
downloadsparse-cf2bde63a650ca75a04c555dec9046dac5e6f592.tar.gz
sparse-cf2bde63a650ca75a04c555dec9046dac5e6f592.tar.bz2
sparse-cf2bde63a650ca75a04c555dec9046dac5e6f592.zip
Handle predefines for integer types, floating point types,
and system in cgcc.
Diffstat (limited to 'cgcc')
-rw-r--r--cgcc147
1 files changed, 146 insertions, 1 deletions
diff --git a/cgcc b/cgcc
index 231f6ee..a87d774 100644
--- a/cgcc
+++ b/cgcc
@@ -4,18 +4,44 @@
my $cc = $ENV{'REAL_CC'} || 'cc';
my $check = $ENV{'CHECK'} || 'check';
+my $m64 = 0;
my $seen_a_c_file = 0;
+my $has_specs = 0;
foreach (@ARGV) {
# Look for a .c file. We don't want to run the checker on .o or .so files
# in the link run. (This simplistic check knows nothing about options
# with arguments, but it seems to do the job.)
- $seen_a_c_file = 1 if /^[^-].*\.c/;
+ $seen_a_c_file = 1 if /^[^-].*\.c$/;
+ $m64 = 1 if /^-m64$/;
+ if (/^-specs=(.*)$/) {
+ $check .= &add_specs ($1);
+ $has_specs = 1;
+ }
my $this_arg = ' ' . &quote_arg ($_);
$cc .= $this_arg unless &check_only_option ($_);
$check .= $this_arg;
}
+my $arch = `uname -m`;
+chomp $arch;
+if ($arch =~ /^(i.?86|athlon)$/) {
+ $check .= &integer_types (8, 16, 32, $m64 ? 64 : 32, 64);
+ $check .= &float_types (1, 1, 21, [24,8], [53,11], [64,15]);
+} elsif ($arch =~ /^(sun4u)$/) {
+ $check .= &integer_types (8, 16, 32, $m64 ? 64 : 32, 64);
+ $check .= &float_types (1, 1, 33, [24,8], [53,11], [113,15]);
+}
+
+if (!$has_specs) {
+ my $os = `uname -s`;
+ chomp $os;
+ $check .= &add_specs (lc $os);
+}
+
+# print "$check\n";
+# exit 1;
+
system ($check) if $seen_a_c_file;
exec ($cc);
@@ -25,6 +51,7 @@ exec ($cc);
sub check_only_option {
my ($arg) = @_;
return 1 if $arg =~ /^-W(no-?)?(default-bitfield-sig|bitwise|typesign)$/;
+ return 1 if $arg =~ /^-specs=/;
return 0;
}
@@ -41,3 +68,121 @@ sub quote_arg {
}
# -----------------------------------------------------------------------------
+
+sub integer_types {
+ my ($char,@dummy) = @_;
+
+ my %pow2m1 =
+ (8 => '127',
+ 16 => '32767',
+ 32 => '2147483647',
+ 64 => '9223372036854775807',
+ );
+ my @types = (['SCHAR',''], ['SHRT',''], ['INT',''], ['LONG','L'], ['LONG_LONG','LL']);
+
+ my $result = " -D__CHAR_BIT__=$char";
+ while (@types) {
+ my $bits = shift @_;
+ my ($name,$suffix) = @{ shift @types };
+ die "$0: wierd number of bits." unless exists $pow2m1{$bits};
+ $result .= " -D__${name}_MAX__=" . $pow2m1{$bits} . $suffix;
+ }
+ return $result;
+}
+
+# -----------------------------------------------------------------------------
+
+sub float_types {
+ my ($has_inf,$has_qnan,$dec_dig,@bitsizes) = @_;
+ my $result = " -D__FLT_RADIX__=2";
+ $result .= " -D__FINITE_MATH_ONLY__=" . ($has_inf || $has_qnan ? '0' : '1');
+ $result .= " -D__DECIMAL_DIG__=$dec_dig";
+
+ my %constants =
+ (24 =>
+ {
+ 'MIN' => '1.17549435e-38',
+ 'MAX' => '3.40282347e+38',
+ 'EPSILON' => '1.19209290e-7',
+ 'DENORM_MIN' => '1.40129846e-45',
+ },
+ 53 =>
+ {
+ 'MIN' => '2.2250738585072014e-308',
+ 'MAX' => '1.7976931348623157e+308',
+ 'EPSILON' => '2.2204460492503131e-16',
+ 'DENORM_MIN' => '4.9406564584124654e-324',
+ },
+ 64 =>
+ {
+ 'MIN' => '3.36210314311209350626e-4932',
+ 'MAX' => '1.18973149535723176502e+4932',
+ 'EPSILON' => '1.08420217248550443401e-19',
+ 'DENORM_MIN' => '3.64519953188247460253e-4951',
+ },
+ 113 =>
+ {
+ 'MIN' => '3.36210314311209350626267781732175260e-4932',
+ 'MAX' => '1.18973149535723176508575932662800702e+4932',
+ 'EPSILON' => '1.92592994438723585305597794258492732e-34',
+ 'DENORM_MIN' => '6.47517511943802511092443895822764655e-4966',
+ },
+ );
+
+ my @types = (['FLT','F'], ['DBL',''], ['LDBL','L']);
+ while (@types) {
+ my ($mant_bits,$exp_bits) = @{ shift @bitsizes };
+ my ($name,$suffix) = @{ shift @types };
+
+ my $h = $constants{$mant_bits};
+ die "$0: wierd number of mantissa bits." unless $h;
+
+ my $mant_dig = int (($mant_bits - 1) * log (2) / log (10));
+ my $max_exp = 1 << ($exp_bits - 1);
+ my $min_exp = 3 - $max_exp;
+ my $max_10_exp = int ($max_exp * log (2) / log (10));
+ my $min_10_exp = -int (-$min_exp * log (2) / log (10));
+
+ $result .= " -D__${name}_MANT_DIG__=$mant_bits";
+ $result .= " -D__${name}_DIG__=$mant_dig";
+ $result .= " -D__${name}_MIN_EXP__='($min_exp)'";
+ $result .= " -D__${name}_MAX_EXP__=$max_exp";
+ $result .= " -D__${name}_MIN_10_EXP__='($min_10_exp)'";
+ $result .= " -D__${name}_MAX_10_EXP__=$max_10_exp";
+ $result .= " -D__${name}_HAS_INFINITY__=" . ($has_inf ? '1' : '0');
+ $result .= " -D__${name}_HAS_QUIET_NAN__=" . ($has_qnan ? '1' : '0');;
+
+ foreach my $inf (sort keys %$h) {
+ $result .= " -D__${name}_${inf}__=" . $h->{$inf} . $suffix;
+ }
+ }
+ return $result;
+}
+
+# -----------------------------------------------------------------------------
+
+sub add_specs {
+ my ($spec) = @_;
+ if ($spec eq 'sunos') {
+ return &add_specs ('unix') .
+ &add_specs ('sparc') .
+ ' -D__sun__=1 -D__sun=1 -Dsun=1' .
+ ' -D__svr4__=1 -DSVR4=1' .
+ ' -D__STDC__=0' .
+ ' -D_REENTRANT' .
+ ' -D_SOLARIS_THREADS' .
+ ' -DNULL="((void *)0)"';
+ } elsif ($spec eq 'linux') {
+ return &add_specs ('unix') .
+ ' -D__linux__=1 -Dlinux=linux' .
+ ' -D__STDC__=1';
+ } elsif ($spec eq 'unix') {
+ return ' -Dunix=1 -D__unix=1 -D__unix__=1';
+ } elsif ($spec eq 'sparc') {
+ return ' -Dsparc=1 -D__sparc=1 -D__sparc__=1';
+ } else {
+ die "$0: invalid specs: $spec\n";
+ }
+}
+
+# -----------------------------------------------------------------------------