From 11418ef9f027c503e371da0bf82aff9387826594 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 8 Nov 2013 19:13:57 -0800 Subject: [PATCH] emit proper large float constants when js opts are to be run --- src/parseTools.js | 7 ++----- tests/cases/storebigfloat.ll | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 tests/cases/storebigfloat.ll diff --git a/src/parseTools.js b/src/parseTools.js index d25f9bd0c..088fea169 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -1166,6 +1166,7 @@ function makeVarDef(js) { function ensureDot(value) { value = value.toString(); if (value.indexOf('.') >= 0 || /[IN]/.test(value)) return value; // if already dotted, or Infinity or NaN, nothing to do here + if (RUNNING_JS_OPTS) return '(+' + value + ')'; // JS optimizer will run, we must do +x, and it will be corrected later var e = value.indexOf('e'); if (e < 0) return value + '.0'; return value.substr(0, e) + '.0' + value.substr(e); @@ -1182,11 +1183,7 @@ function asmEnsureFloat(value, type) { // ensures that a float type has either 5 } // coerce if missing a '.', or if smaller than 1, so could be 1e-5 which has no . if (type in Runtime.FLOAT_TYPES && (value.toString().indexOf('.') < 0 || Math.abs(value) < 1)) { - if (RUNNING_JS_OPTS) { - return '(+' + value + ')'; // JS optimizer will run, we must do +x, and it will be corrected later - } else { - return ensureDot(value); - } + return ensureDot(value); } else { return value; } diff --git a/tests/cases/storebigfloat.ll b/tests/cases/storebigfloat.ll new file mode 100644 index 000000000..c9995835b --- /dev/null +++ b/tests/cases/storebigfloat.ll @@ -0,0 +1,17 @@ + +@.str = private unnamed_addr constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*] + +; [#uses=0] +define i32 @main() { +entry: + %retval = alloca i32, align 4 ; [#uses=1 type=i32*] + %f = alloca float, align 4 + store float 1.000000e+10, float* %f, align 4 + store i32 0, i32* %retval + %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32] + ret i32 1 +} + +; [#uses=1] +declare i32 @printf(i8*, ...) +