diff options
author | Anthony Pesch <inolen@gmail.com> | 2013-06-26 07:16:13 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-06-28 10:39:54 -0700 |
commit | 57bac5ccc9ce0d01e9c200a114fc4bf4ca690a11 (patch) | |
tree | 82db1be2e8898447273b952145a6b9002c41f185 /src/parseTools.js | |
parent | 41577acbb7dfd5c32de98ef0ae6596389afbfdb2 (diff) |
don't explicitly initialize uninitialized globals
Diffstat (limited to 'src/parseTools.js')
-rw-r--r-- | src/parseTools.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/parseTools.js b/src/parseTools.js index 0b83a12b..babb2692 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -467,6 +467,17 @@ function isIndexableGlobal(ident) { return !data.alias && !data.external; } +function isBSS(item) { + if (!USE_BSS) { + return false; + } + + // return true if a global is uninitialized or initialized to 0 + return item.external || + (item.value && item.value.intertype === 'emptystruct') || + (item.value && item.value.value !== undefined && item.value.value === '0'); +} + function makeGlobalDef(ident) { if (!NAMED_GLOBALS && isIndexableGlobal(ident)) return ''; return 'var ' + ident + ';'; @@ -490,7 +501,10 @@ function sortGlobals(globals) { ks.sort(); var inv = invertArray(ks); return values(globals).sort(function(a, b) { - return inv[b.ident] - inv[a.ident]; + // sort globals based on if they need to be explicitly initialized or not (moving + // values that don't need to be to the end of the array). if equal, sort by name. + return (Number(isBSS(a)) - Number(isBSS(b))) || + (inv[b.ident] - inv[a.ident]); }); } |