Skip to content

Commit 0d67a6b

Browse files
radaretrufae
authored andcommitted
Avoid wasm builds from using long doubles ##wasm
1 parent 6a2c937 commit 0d67a6b

File tree

7 files changed

+36
-5
lines changed

7 files changed

+36
-5
lines changed

libr/core/cmd_debug.inc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3074,8 +3074,14 @@ static void cmd_debug_reg(RCore *core, const char *str) {
30743074
double dval = 0.0f;
30753075
sscanf (eq, "%lf", (double*)&dval);
30763076
val = dval;
3077+
#else
3078+
#if R2_NO_LONG_DOUBLE_FMT
3079+
double dval = 0.0;
3080+
sscanf (eq, "%lf", &dval);
3081+
val = (long double)dval;
30773082
#else
30783083
sscanf (eq, "%Lf", &val);
3084+
#endif
30793085
#endif
30803086
r_reg_set_double (core->dbg->reg, item, val);
30813087
r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, true);
@@ -3084,7 +3090,11 @@ static void cmd_debug_reg(RCore *core, const char *str) {
30843090
r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false);
30853091
r_debug_reg_sync (core->dbg, R_REG_TYPE_FPU, false);
30863092
long double res = r_reg_get_longdouble (core->dbg->reg, item);
3093+
#if R2_NO_LONG_DOUBLE_FMT
3094+
r_cons_printf (core->cons, "%f\n", (double)res);
3095+
#else
30873096
r_cons_printf (core->cons, "%Lf\n", res);
3097+
#endif
30883098
}
30893099
} else {
30903100
/* note, that negative type forces sync to print the regs from the backend */

libr/core/cmd_write.inc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,12 @@ static void cmd_write_value_float(RCore *core, const char *input) {
530530

531531
static void cmd_write_value_long_double(RCore *core, const char *input) {
532532
long double v = 0.0;
533+
#if R2_NO_LONG_DOUBLE_FMT
534+
double tmp = strtod (input, NULL);
535+
v = (long double)tmp;
536+
#else
533537
sscanf (input, "%Lf", &v);
538+
#endif
534539
r_io_write_at (core->io, core->addr, (const ut8*)&v, sizeof (long double));
535540
}
536541

libr/debug/p/native/linux/linux_debug.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,11 @@ static void print_fpu(RCons *cons, void *f) {
10291029
}
10301030
// Using %Lf and %Le even though we do not show the extra precision to avoid another cast
10311031
// %f with (double)*st_ld would also work
1032+
#if R2_NO_LONG_DOUBLE_FMT
1033+
r_cons_printf (cons, " %e %f\n", (double)(*st_ld), (double)(*st_ld));
1034+
#else
10321035
r_cons_printf (cons, " %Le %Lf\n", *st_ld, *st_ld);
1036+
#endif
10331037
} else {
10341038
r_cons_printf (cons, "\n");
10351039
}

libr/util/format.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,18 +1071,26 @@ static void r_print_format_long_double(const RPrint* p, int endian, int mode, co
10711071
r_mem_swaporcopy ((ut8*)&val_f, buf + i, sizeof (long double), endian);
10721072
if (MUSTSET) {
10731073
r_print_printf (p, "wv8 %s @ 0x%08"PFMT64x"\n", setval,
1074-
seeki + ((elem >= 0) ? elem * 8 : 0));
1074+
seeki + ((elem >= 0) ? elem * 8 : 0));
10751075
} else if ((mode & R_PRINT_DOT) || MUSTSEESTRUCT) {
1076+
#if R2_NO_LONG_DOUBLE_FMT
1077+
r_print_printf (p, "%.17g", (double)val_f);
1078+
#else
10761079
r_print_printf (p, "%.17Lg", val_f);
1080+
#endif
10771081
} else {
10781082
if (MUSTSEE) {
10791083
if (!SEEVALUE && !ISQUIET) {
10801084
r_print_printf (p, "0x%08"PFMT64x" = ",
1081-
seeki + ((elem >= 0) ? elem * 8 : 0));
1085+
seeki + ((elem >= 0) ? elem * 8 : 0));
10821086
}
10831087
}
10841088
if (size == -1) {
1089+
#if R2_NO_LONG_DOUBLE_FMT
1090+
r_print_printf (p, "%.17g", (double)val_f);
1091+
#else
10851092
r_print_printf (p, "%.17Lg", val_f);
1093+
#endif
10861094
} else {
10871095
if (!SEEVALUE) {
10881096
r_print_printf (p, "[ ");
@@ -1092,7 +1100,11 @@ static void r_print_format_long_double(const RPrint* p, int endian, int mode, co
10921100
updateAddr (buf + i, 9999, endian, &addr, NULL);
10931101
r_mem_swaporcopy ((ut8*)&val_f, buf + i, sizeof (double), endian);
10941102
if (elem == -1 || elem == 0) {
1103+
#if R2_NO_LONG_DOUBLE_FMT
1104+
r_print_printf (p, "%.17g", (double)val_f);
1105+
#else
10951106
r_print_printf (p, "%.17Lg", val_f);
1107+
#endif
10961108
if (elem == 0) {
10971109
elem = -2;
10981110
}

mk/emscripten.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ _INCLUDE_MK_GCC_=1
33
EXT_EXE=.js
44
EXT_SO=.bc
55
EXT_AR=a
6-
CC=emcc
6+
CC=emcc -DR2_NO_LONG_DOUBLE_FMT=1
77
AR=emar
88
LINK=
99
RANLIB=emranlib

mk/wasi.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ EXT_EXE=.wasm
44
EXT_SO=so
55
WITH_LIBS=0
66
EXT_AR=a
7-
CC=$(WASI_SDK)/bin/clang --sysroot=$(WASI_SYSROOT) -DHAVE_PTHREAD=0 -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_MMAN -DHAVE_PTY=0
7+
CC=$(WASI_SDK)/bin/clang --sysroot=$(WASI_SYSROOT) -DHAVE_PTHREAD=0 -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_MMAN -DHAVE_PTY=0 -DR2_NO_LONG_DOUBLE_FMT=1
88
# -lc-printscan-long-double
99
AR=$(WASI_SDK)/bin/ar
1010
LINK=

mk/wasm.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ _INCLUDE_MK_GCC_=1
33
EXT_EXE=.wasm
44
EXT_SO=wasm
55
EXT_AR=a
6-
CC=emcc
6+
CC=emcc -DR2_NO_LONG_DOUBLE_FMT=1
77
AR=emar
88
RANLIB=emranlib
99
ONELIB=0

0 commit comments

Comments
 (0)