diff options
author | alon@honor <none@none> | 2010-10-19 20:25:25 -0700 |
---|---|---|
committer | alon@honor <none@none> | 2010-10-19 20:25:25 -0700 |
commit | c98eadd6b726ef17b56177dc81b7a9ecedfbe13c (patch) | |
tree | 1fe180a2b1a0ed96680dcb68c036baedc117d7a7 /src/analyzer.js | |
parent | 84266fa6f9afc63d1b5a260c715ec70fddc4d156 (diff) |
cleanup structure packing calculation
Diffstat (limited to 'src/analyzer.js')
-rw-r--r-- | src/analyzer.js | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index 15e7b291..e7f0dfff 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -182,15 +182,20 @@ function analyzer(data) { more = true; return; } + // 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. type.flatSize = 0; var diffs = []; - var prev = -1; + var prev = -1, maxSize = -1; type.flatIndexes = type.fields.map(function(field) { var size; if (isNumberType(field) || isPointerType(field)) { size = getNativeFieldSize(field, true); // pack char; char; in structs, also char[X]s. + maxSize = Math.max(maxSize, size); } else if (isStructType(field)) { size = item.types[field].flatSize; + maxSize = Math.max(maxSize, QUANTUM_SIZE); } else { dprint('Unclear type in struct: ' + field + ', in ' + type.name_); assert(0); @@ -203,14 +208,12 @@ function analyzer(data) { prev = curr; return curr; }); + type.flatSize = Runtime.alignMemory(type.flatSize, maxSize); if (diffs.length == 0) { type.flatFactor = type.flatSize; } else if (dedup(diffs).length == 1) { type.flatFactor = diffs[0]; } - if (type.flatSize > QUANTUM_SIZE) { - type.flatSize = Runtime.alignMemory(type.flatSize); // final padding at end - } type.needsFlattening = (this.flatFactor != 1); dprint('types', 'type: ' + type.name_ + ' : ' + JSON.stringify(type.fields)); dprint('types', ' has final size of ' + type.flatSize + ', flatting: ' + type.needsFlattening + ' ? ' + (type.flatFactor ? type.flatFactor : JSON.stringify(type.flatIndexes))); |