aboutsummaryrefslogtreecommitdiff
path: root/src/parseTools.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-01-23 16:34:36 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-01-23 16:34:36 -0800
commitab20c69e046731f722f39016539dc1ffe4040aa1 (patch)
treea20370a075ddb043c9e32608dad7e4402a9eda42 /src/parseTools.js
parent4200a73e281b3bb10c11d9bc57a9a07602ff23b4 (diff)
refactor makeComparison and use it in more places
Diffstat (limited to 'src/parseTools.js')
-rw-r--r--src/parseTools.js13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index 4f68d0a1..cceba188 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -1792,13 +1792,14 @@ function finalizeLLVMParameter(param, noIndexizeFunctions) {
return ret;
}
-function makeComparison(a, b, type) {
+function makeComparison(a, op, b, type) {
+ assert(type);
if (!isIllegalType(type)) {
- return asmCoercion(a, type) + ' == ' + asmCoercion(b, type);
+ return asmCoercion(a, type) + op + asmCoercion(b, type);
} else {
assert(type == 'i64');
- return asmCoercion(a + '$0', 'i32') + ' == ' + asmCoercion(b + '$0', 'i32') + ' & ' +
- asmCoercion(a + '$1', 'i32') + ' == ' + asmCoercion(b + '$1', 'i32');
+ return asmCoercion(a + '$0', 'i32') + op + asmCoercion(b + '$0', 'i32') + ' & ' +
+ asmCoercion(a + '$1', 'i32') + op + asmCoercion(b + '$1', 'i32');
}
}
@@ -1870,7 +1871,7 @@ function makeRounding(value, bits, signed, floatConversion) {
// Note that if converting a float, we may have the wrong sign at this point! But, we have
// been rounded properly regardless, and we will be sign-corrected later when actually used, if
// necessary.
- return makeInlineCalculation('VALUE >= 0 ? Math.floor(VALUE) : Math.ceil(VALUE)', value, 'tempBigIntR');
+ return makeInlineCalculation(makeComparison('VALUE', '>=', '0', 'float') + ' ? Math.floor(VALUE) : Math.ceil(VALUE)', value, 'tempBigIntR');
} else {
// asm.js mode, cleaner refactoring of this function as well. TODO: use in non-asm case, most of this
if (floatConversion && bits <= 32) {
@@ -1887,7 +1888,7 @@ function makeRounding(value, bits, signed, floatConversion) {
// Math.floor is reasonably fast if we don't care about corrections (and even correct if unsigned)
if (!correctRoundings() || !signed) return 'Math.floor(' + value + ')';
// We are left with >32 bits
- return makeInlineCalculation('VALUE >= 0 ? Math.floor(VALUE) : Math.ceil(VALUE)', value, 'tempBigIntR');
+ return makeInlineCalculation(makeComparison('VALUE', '>=', '0', 'float') + ' ? Math.floor(VALUE) : Math.ceil(VALUE)', value, 'tempBigIntR');
}
}