diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-12-05 16:14:36 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-12-07 14:23:23 -0800 |
commit | b6466081c6023181cdbfc3421c78966edfdf7c44 (patch) | |
tree | 152fc0e133b974d032201f7719a170ecd6a0a768 /src/parseTools.js | |
parent | cfc6b10be7b2742949b78f0c41371ceaff5978ce (diff) |
start to legalize structural types
Diffstat (limited to 'src/parseTools.js')
-rw-r--r-- | src/parseTools.js | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/parseTools.js b/src/parseTools.js index 5cae53b4..a7a45f09 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -128,12 +128,21 @@ function isStructType(type) { return type[0] == '%'; } +function isStructuralType(type) { + return /^{ ?[^}]* ?}$/.test(type); // { i32, i8 } etc. - anonymous struct types +} + +function getStructuralTypeParts(type) { // split { i32, i8 } etc. into parts + return type.replace(/[ {}]/g, '').split(','); +} + function isIntImplemented(type) { return type[0] == 'i' || isPointerType(type); } // Note: works for iX types, not pointers (even though they are implemented as ints) function getBits(type) { + if (isStructuralType(type)) return getStructuralTypeParts(type).length*32; // 32 bits per part in { i32, i1, i8, i32 } etc if (!type || type[0] != 'i') return 0; var left = type.substr(1); if (!isNumber(left)) return 0; |