diff options
Diffstat (limited to 'src/parseTools.js')
-rw-r--r-- | src/parseTools.js | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/src/parseTools.js b/src/parseTools.js index 1a58b4e7..090d85ac 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -129,9 +129,13 @@ function isPointerType(type) { return type[type.length-1] == '*'; } +function isArrayType(type) { + return /^\[\d+\ x\ (.*)\]/.test(type); +} + function isStructType(type) { if (isPointerType(type)) return false; - if (/^\[\d+\ x\ (.*)\]/.test(type)) return true; // [15 x ?] blocks. Like structs + if (isArrayType(type)) return true; if (/<?{ ?[^}]* ?}>?/.test(type)) return true; // { i32, i8 } etc. - anonymous struct types // See comment in isStructPointerType() return type[0] == '%'; @@ -286,11 +290,22 @@ function isVarArgsFunctionType(type) { return type.substr(-varArgsSuffix.length) == varArgsSuffix; } -function countNormalArgs(type, out) { +function getNumLegalizedVars(type) { // how many legalized variables are needed to represent this type + if (type in Runtime.FLOAT_TYPES) return 1; + return Math.max(getNumIntChunks(type), 1); +} + +function countNormalArgs(type, out, legalized) { out = out || {}; if (!isFunctionType(type, out)) return -1; - if (isVarArgsFunctionType(type)) out.numArgs--; - return out.numArgs; + var ret = 0; + if (out.segments) { + for (var i = 0; i < out.segments.length; i++) { + ret += legalized ? getNumLegalizedVars(out.segments[i][0].text) : 1; + } + } + if (isVarArgsFunctionType(type)) ret--; + return ret; } function addIdent(token) { @@ -1743,10 +1758,11 @@ function getGetElementPtrIndexes(item) { indexes.push(getFastValue(Runtime.getNativeTypeSize(type), '*', offset, 'i32')); } } - item.params.slice(2, item.params.length).forEach(function(arg) { + item.params.slice(2, item.params.length).forEach(function(arg, i) { var curr = arg; // TODO: If index is constant, optimize var typeData = Types.types[type]; + assert(typeData || i == item.params.length - 3); // can be null, when we get to the end (a basic type) if (isStructType(type) && typeData.needsFlattening) { if (typeData.flatFactor) { indexes.push(getFastValue(curr, '*', typeData.flatFactor, 'i32')); @@ -1762,16 +1778,15 @@ function getGetElementPtrIndexes(item) { indexes.push(curr); } } - if (!isNumber(curr) || parseInt(curr) < 0) { - // We have a *variable* to index with, or a negative number. In both - // cases, in theory we might need to do something dynamic here. FIXME? - // But, most likely all the possible types are the same, so do that case here now... - for (var i = 1; i < typeData.fields.length; i++) { - assert(typeData.fields[0] === typeData.fields[i]); + if (typeData) { + if (isArrayType(type)) { + type = typeData.fields[0]; // all the same, so accept even out-of-bounds this way + } else { + assert(isNumber(curr)); // cannot be dynamic + type = typeData.fields[curr]; } - curr = 0; + assert(type); } - type = typeData && typeData.fields[curr] ? typeData.fields[curr] : ''; }); var ret = getFastValues(indexes, '+', 'i32'); @@ -2023,12 +2038,19 @@ function processMathop(item) { } var bitsBefore = parseInt((item.params[0] ? item.params[0].type : item.type).substr(1)); // remove i to leave the number of bits left after this var bitsLeft = parseInt(((item.params[1] && item.params[1].ident) ? item.params[1].ident : item.type).substr(1)); // remove i to leave the number of bits left after this operation + var rawBits = getBits(item.type); + assert(rawBits <= 64); function integerizeBignum(value) { return makeInlineCalculation('VALUE-VALUE%1', value, 'tempBigIntI'); } - if ((type == 'i64' || paramTypes[0] == 'i64' || paramTypes[1] == 'i64' || idents[1] == '(i64)') && USE_TYPED_ARRAYS == 2) { + if ((type == 'i64' || paramTypes[0] == 'i64' || paramTypes[1] == 'i64' || idents[1] == '(i64)' || rawBits > 32) && USE_TYPED_ARRAYS == 2) { + // this code assumes i64 for the most part + if (ASSERTIONS && rawBits < 64) { + warnOnce('processMathop processing illegal non-i64 value: ' + [type, paramTypes, idents]) + } + var warnI64_1 = function() { warnOnce('Arithmetic on 64-bit integers in mode 1 is rounded and flaky, like mode 0!'); }; |