aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-04-20 21:09:05 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-04-29 13:01:58 -0700
commit0fedeaa62d955ce57e6751a57e263122420671c1 (patch)
tree63b1f98055274be81159371bedde12300a0f9ba0
parentd5afbea4576cae55facb921e2b88e56cc0ecbace (diff)
refactor struct detection of alignment size
-rw-r--r--src/runtime.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/runtime.js b/src/runtime.js
index d0c22c6f..ec39636f 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -175,6 +175,13 @@ var Runtime = {
set: set,
+ // type can be a native type or a struct (or null, for structs we only look at size here)
+ getAlignSize: function(type, size) {
+ // we align i64s and doubles on 64-bit boundaries, unlike x86
+ if (type == 'i64' || type == 'double') return 8;
+ return Math.min(size, Runtime.QUANTUM_SIZE);
+ },
+
// Calculate aligned size, just like C structs should be. TODO: Consider
// requesting that compilation be done with #pragma pack(push) /n #pragma pack(1),
// which would remove much of the complexity here.
@@ -187,10 +194,10 @@ var Runtime = {
var size, alignSize;
if (Runtime.isNumberType(field) || Runtime.isPointerType(field)) {
size = Runtime.getNativeTypeSize(field); // pack char; char; in structs, also char[X]s.
- alignSize = size; // we align i64s and doubles on 64-bit boundaries, unlike x86
+ alignSize = Runtime.getAlignSize(field, size);
} else if (Runtime.isStructType(field)) {
size = Types.types[field].flatSize;
- alignSize = Math.min(Types.types[field].alignSize, Runtime.QUANTUM_SIZE);
+ alignSize = Runtime.getAlignSize(null, Types.types[field].alignSize);
} else if (field[0] == 'b') {
// bN, large number field, like a [N x i8]
size = field.substr(1)|0;