#!/usr/bin/perl -w
# Copyright (C) 1999-2015 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# Contributed by Andreas Jaeger <aj@suse.de>, 1999.
# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, see
# <http://www.gnu.org/licenses/>.
# This file needs to be tidied up
# Note that functions and tests share the same namespace.
# Information about tests are stored in: %results
# $results{$test}{"type"} is the result type, e.g. normal or complex.
# $results{$test}{"has_ulps"} is set if deltas exist.
# In the following description $type and $float are:
# - $type is either "normal", "real" (for the real part of a complex number)
# or "imag" (for the imaginary part # of a complex number).
# - $float is either of float, ifloat, double, idouble, ldouble, ildouble;
# It represents the underlying floating point type (float, double or long
# double) and if inline functions (the leading i stands for inline)
# are used.
# $results{$test}{$type}{"ulp"}{$float} is defined and has a delta as value
use Getopt::Std;
use strict;
use vars qw ($input $output $auto_input);
use vars qw (%results);
use vars qw (%beautify @all_floats);
use vars qw ($output_dir $ulps_file $srcdir);
use vars qw (%auto_tests);
# all_floats is sorted and contains all recognised float types
@all_floats = ('double', 'float', 'idouble',
'ifloat', 'ildouble', 'ldouble');
%beautify =
( "minus_zero" => "-0",
"plus_zero" => "+0",
"-0x0p+0f" => "-0",
"-0x0p+0" => "-0",
"-0x0p+0L" => "-0",
"0x0p+0f" => "+0",
"0x0p+0" => "+0",
"0x0p+0L" => "+0",
"minus_infty" => "-inf",
"plus_infty" => "inf",
"qnan_value" => "qNaN",
);
# get Options
# Options:
# u: ulps-file
# h: help
# o: output-directory
# n: generate new ulps file
use vars qw($opt_u $opt_h $opt_o $opt_n);
getopts('u:o:nh');
$ulps_file = 'libm-test-ulps';
$output_dir = '';
($srcdir = $0) =~ s{[^/]*$}{};
if ($opt_h) {
print "Usage: gen-libm-test.pl [OPTIONS]\n";
print " -h print this help, then exit\n";
print " -o DIR directory where generated files will be placed\n";
print " -n only generate sorted file NewUlps from libm-test-ulps\n";
print " -u FILE input file with ulps\n";
exit 0;
}
$ulps_file = $opt_u if ($opt_u);
$output_dir = $opt_o if ($opt_o);
$input = "libm-test.inc";
$auto_input = "${srcdir}auto-libm-test-out";
$output = "${output_dir}libm-test.c";
&parse_ulps ($ulps_file);
&parse_auto_input ($auto_input);
&generate_testfile ($input, $output) unless ($opt_n);
&output_ulps ("${output_dir}libm-test-ulps.h", $ulps_file) unless ($opt_n);
&print_ulps_file ("${output_dir}NewUlps") if ($opt_n);