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
|
#!/usr/bin/perl -w
# -----------------------------------------------------------------------------
my $ryu = $ARGV[0];
my @files = (# "ryu.h",
"common.h",
"digit_table.h",
"d2s_intrinsics.h",
"d2s_small_table.h",
'd2s.c',
'WITH_LONG_DOUBLE',
'ryu_generic_128.h',
'generic_128.h',
'generic_128.c');
print "#define RYU_OPTIMIZE_SIZE 1\n\n";
print "#define bool int\n\n";
print "#include \"go-ryu.h\"\n";
print "#include <inttypes.h>\n";
print "\n";
my $with_long_double = 0;
foreach my $f (@files) {
if ($f eq 'WITH_LONG_DOUBLE') {
$with_long_double = 1;
next;
}
my $fn = "$ryu/ryu/$f";
my $in_conditional = 0;
print STDERR "Importing $f...\n";
open my $fh, "<", $fn or die "$0: cannot read $fn:$!\n";
print "#ifdef GOFFICE_WITH_LONG_DOUBLE\n" if $with_long_double;
print "// File $f imported from ryu\n";
while (<$fh>) {
next if /^\s*#\s*include\s*"ryu.*"/;
s/\b((float|double|long_double)_to_fd128|generic_binary_to_decimal|generic_to_chars|(d|f)2(s|exp|fixed)(|_buffered_n|_buffered))\b/go_ryu_$1/g;
if (/\b(go_ryu_d2s_buffered|go_ryu_d2s|go_ryu_f2s_buffered_n|go_ryu_f2s_buffered|go_ryu_f2s|go_ryu_d2fixed_buffered_n|go_ryu_d2fixed_buffered|go_ryu_d2fixed|go_ryu_d2exp_buffered_n|go_ryu_d2exp_buffered|go_ryu_d2exp)\s*\([a-z]+\s.*\)(;|\s*\{)$/) {
print "#if 0\n";
$_ = "static $_";
$in_conditional = 1;
}
if (/\b(go_ryu_long_double_to_fd128|go_ryu_generic_to_chars)\s*\([a-z]+\s.*\)(;|\s*\{)$/) {
$_ = "static $_";
}
if (/struct floating_decimal_128 go_ryu_generic_binary_to_decimal\(/) {
$_ = "static $_";
}
if ($f =~ /128/) {
s/\b(pow5bits|pow5Factor|multipleOfPowerOf[25]|log10Pow[25]|copy_special_str|POW5_TABLE_SIZE)\b/$1l/g;
if (/go_ryu_float_to_fd128\(float/) {
print "#if 0\n";
$_ = "static $_";
$in_conditional = 1;
}
if (/go_ryu_double_to_fd128\(double/) {
print "#if 0\n";
$_ = "static $_";
$in_conditional = 1;
}
}
if ($in_conditional && (/^[a-z].*\);$/ || /^}/)) {
$_ = "$_#endif\n";
$in_conditional = 0;
}
print;
}
print "// End of file $f imported from ryu\n";
print "#endif // GOFFICE_WITH_LONG_DOUBLE\n" if $with_long_double;
print "\n";
die "Trouble" if $in_conditional;
}
print "\n";
print "#ifdef GOFFICE_WITH_LONG_DOUBLE\n";
print "int go_ryu_ld2s_buffered_n (long double d, char *dst) {\n";
print " struct floating_decimal_128 fd128 = go_ryu_long_double_to_fd128(d);\n";
print " return go_ryu_generic_to_chars(fd128, dst);\n";
print "}\n";
print "#endif\n";
|