emit proper large float constants when js opts are to be run

This commit is contained in:
Alon Zakai 2013-11-08 19:13:57 -08:00
Родитель 8d20a1424a
Коммит 11418ef9f0
2 изменённых файлов: 19 добавлений и 5 удалений

Просмотреть файл

@ -1166,6 +1166,7 @@ function makeVarDef(js) {
function ensureDot(value) { function ensureDot(value) {
value = value.toString(); value = value.toString();
if (value.indexOf('.') >= 0 || /[IN]/.test(value)) return value; // if already dotted, or Infinity or NaN, nothing to do here 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'); var e = value.indexOf('e');
if (e < 0) return value + '.0'; if (e < 0) return value + '.0';
return value.substr(0, e) + '.0' + value.substr(e); 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 . // 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 (type in Runtime.FLOAT_TYPES && (value.toString().indexOf('.') < 0 || Math.abs(value) < 1)) {
if (RUNNING_JS_OPTS) { return ensureDot(value);
return '(+' + value + ')'; // JS optimizer will run, we must do +x, and it will be corrected later
} else {
return ensureDot(value);
}
} else { } else {
return value; return value;
} }

Просмотреть файл

@ -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*, ...)