aboutsummaryrefslogtreecommitdiff
path: root/src/jsifier.js
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2010-12-09 20:09:11 -0800
committerAlon Zakai <azakai@mozilla.com>2010-12-09 20:09:11 -0800
commit1c5355c76c0389775f3e11b5b962311e7501ad31 (patch)
treefda230be1c9214bf6b2e7d9dda016fa0fd70a7e9 /src/jsifier.js
parent023a34753e1e47f03eadfd91a7e639afbbead888 (diff)
proper support for bitfields
Diffstat (limited to 'src/jsifier.js')
-rw-r--r--src/jsifier.js10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index e5ab6b4c..17fe4fd3 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -749,7 +749,15 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) {
default: throw 'Unknown fcmp variant: ' + variant
}
}
- case 'zext': case 'fpext': case 'trunc': case 'sext': case 'fptrunc': return ident1;
+ case 'zext': case 'fpext': case 'sext': case 'fptrunc': return ident1;
+ case 'trunc': {
+ // Unlike extending, which we just 'do' (by doing nothing),
+ // truncating can change the number, e.g. by truncating to an i1
+ // in order to get the first bit
+ assert(ident2[0] == 'i');
+ var bitsLeft = ident2.substr(1);
+ return '((' + ident1 + ') & ' + (Math.pow(2, bitsLeft)-1) + ')';
+ }
case 'select': return ident1 + ' ? ' + ident2 + ' : ' + ident3;
case 'ptrtoint': {
//if (type != 'i8*') print('// XXX Warning: Risky ptrtoint operation on line ' + lineNum);