aboutsummaryrefslogtreecommitdiff
path: root/src/parseTools.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-12-06 12:02:03 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-12-07 14:23:24 -0800
commitd1d33362df70a31e7248e2fda0eb4bad0fe58390 (patch)
treed0973fc4d737043a7c19d9fa5fdd3edcf026e445 /src/parseTools.js
parent32635a86097de499d7ee84bd9fb6967bd96e6169 (diff)
legalize illegal parts of structural types
Diffstat (limited to 'src/parseTools.js')
-rw-r--r--src/parseTools.js18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index 49740c6d..19913949 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -136,6 +136,20 @@ function getStructuralTypeParts(type) { // split { i32, i8 } etc. into parts
return type.replace(/[ {}]/g, '').split(',');
}
+function getStructureTypeParts(type) {
+ if (isStructuralType(type)) {
+ return type.replace(/[ {}]/g, '').split(',');
+ } else {
+ var typeData = Types.types[type];
+ assert(typeData, type);
+ return typeData.fields;
+ }
+}
+
+function getStructuralTypePartBits(part) {
+ return Math.ceil(getBits(part)/32)*32; // simple 32-bit alignment
+}
+
function isIntImplemented(type) {
return type[0] == 'i' || isPointerType(type);
}
@@ -148,7 +162,9 @@ function getBits(type) {
if (!isNumber(left)) return 0;
return parseInt(left);
}
- if (isStructuralType(type)) return getStructuralTypeParts(type).length*32; // 32 bits per part in { i32, i1, i8, i32 } etc
+ if (isStructuralType(type)) {
+ return sum(getStructuralTypeParts(type).map(getStructuralTypePartBits));
+ }
if (isStructType(type)) {
var typeData = Types.types[type];
return typeData.flatSize*8;