diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-11-08 19:13:57 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-11-08 19:13:57 -0800 |
commit | 11418ef9f027c503e371da0bf82aff9387826594 (patch) | |
tree | 6196dc075d32b5a262f6f7445c720215fc7fe08f | |
parent | 8d20a1424af064991bee3c66ef83ba0886b01180 (diff) |
emit proper large float constants when js opts are to be run
-rw-r--r-- | src/parseTools.js | 7 | ||||
-rw-r--r-- | tests/cases/storebigfloat.ll | 17 |
2 files changed, 19 insertions, 5 deletions
diff --git a/src/parseTools.js b/src/parseTools.js index d25f9bd0..088fea16 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 00000000..c9995835 --- /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*, ...) + |