diff options
author | alon@honor <none@none> | 2010-09-25 20:26:16 -0700 |
---|---|---|
committer | alon@honor <none@none> | 2010-09-25 20:26:16 -0700 |
commit | b94c061e122f155cc5c1262a1bb470cb49ee04b4 (patch) | |
tree | 134322b7ed16b9a3ed805d4663e3233625d5ef7a /src/parseTools.js | |
parent | 481dec302bfb02b574741c4e505d274718854dff (diff) |
optional memory alignment that matches c/c++; used in clang, not in llvm-gcc
Diffstat (limited to 'src/parseTools.js')
-rw-r--r-- | src/parseTools.js | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/parseTools.js b/src/parseTools.js index cdd20e2f..5d868920 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -1,8 +1,11 @@ // Various tools for parsing llvm // Simple #if/else/endif preprocessing for a file. Checks if the -// ident checked is true in our global. -function preprocess(text) { +// ident checked is true in our global. Also replaces some constants +function preprocess(text, constants) { + for (constant in constants) { + text = text.replace(eval('/' + constant + '/g'), constants[constant]); + } var lines = text.split('\n'); var ret = ''; var show = true; @@ -375,3 +378,28 @@ function getLabelIds(labels) { return labels.map(function(label) { return label.ident }); } +//! Returns the size of a field, as C/C++ would have it (in 32-bit, +//! for now). +//! @param field The field type, by name +//! @param alone Whether this is inside a structure (so padding is +//! used) or alone (line in char*, where no padding is done). +function getNativeFieldSize(field, alone) { + var size; + if (QUANTUM_SIZE > 1) { + size = { + 'i1': alone ? 1 : 4, // inside a struct, aligned to 4, + 'i8': alone ? 1 : 4, // most likely...? XXX + 'i32': 4, + 'i64': 8, + 'float': 4, + 'double':8, + }[field]; // XXX 32/64 bit stuff + if (!size) { + size = 4; // Must be a pointer XXX 32/64 + } + } else { + size = 1; + } + return size; +} + |