summaryrefslogtreecommitdiffstats
path: root/libraries/goffice/import-ryu
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/goffice/import-ryu')
-rw-r--r--libraries/goffice/import-ryu97
1 files changed, 97 insertions, 0 deletions
diff --git a/libraries/goffice/import-ryu b/libraries/goffice/import-ryu
new file mode 100644
index 0000000000..e99f022e0b
--- /dev/null
+++ b/libraries/goffice/import-ryu
@@ -0,0 +1,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";