aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent023a34753e1e47f03eadfd91a7e639afbbead888 (diff)
proper support for bitfields
Diffstat (limited to 'src')
-rw-r--r--src/jsifier.js10
-rw-r--r--src/preamble.js3
2 files changed, 11 insertions, 2 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);
diff --git a/src/preamble.js b/src/preamble.js
index 7ae7e0ad..aa58e172 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -35,7 +35,8 @@ function SAFE_HEAP_ACCESS(dest, type, store) {
}
var history = HEAP_HISTORY[dest];
if (history === null) return;
- assert(history, 'Must have a history for a safe heap load!');
+ assert(history, 'Must have a history for a safe heap load!'); // Warning - bit fields in C structs cause loads+stores for each store, so
+ // they will show up here...
// assert((history && history[0]) /* || HEAP[dest] === 0 */, "Loading from where there was no store! " + dest + ',' + HEAP[dest] + ',' + type + ', \n\n' + new Error().stack + '\n');
// if (history[0].type !== type) {
if (history !== type) {