diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-02-10 18:03:53 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-02-11 14:54:56 -0800 |
commit | 0f645b390083136644b99ef3a28c10dd31f3c0bb (patch) | |
tree | 9415ce85cc38e9e7ae06c2f4b4b59e6b5b1be5ac /src | |
parent | 71509977339accc2b8213767a613604e93eaa378 (diff) |
legalize function params
Diffstat (limited to 'src')
-rw-r--r-- | src/analyzer.js | 43 | ||||
-rw-r--r-- | src/jsifier.js | 25 | ||||
-rw-r--r-- | src/parseTools.js | 21 |
3 files changed, 31 insertions, 58 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index bba617a7..ab0e8231 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -164,11 +164,10 @@ function analyzer(data, sidePass) { Array.prototype.splice.apply(lines, [i, 1].concat(toAdd)); return toAdd.length; } - data.functions.forEach(function(func) { - // Legalize function parameters + function legalizeFunctionParameters(params) { var i = 0; - while (i < func.params.length) { - var param = func.params[i]; + while (i < params.length) { + var param = params[i]; if (param.intertype == 'value' && isIllegalType(param.type)) { var toAdd = getLegalVars(param.ident, getBits(param.type)).map(function(element) { return { @@ -178,12 +177,16 @@ function analyzer(data, sidePass) { byval: 0 }; }); - Array.prototype.splice.apply(func.params, [i, 1].concat(toAdd)); + Array.prototype.splice.apply(params, [i, 1].concat(toAdd)); i += toAdd.length; continue; } i++; } + } + data.functions.forEach(function(func) { + // Legalize function params + legalizeFunctionParameters(func.params); // Legalize lines in labels var tempId = 0; func.labels.forEach(function(label) { @@ -266,25 +269,31 @@ function analyzer(data, sidePass) { i += removeAndAdd(label.lines, i, toAdd); continue; } - // call, ret: Return value is in an unlegalized array literal. Not fully optimal. + // call, return: Return value is in an unlegalized array literal. Not fully optimal. case 'call': { bits = getBits(value.type); var elements = getLegalVars(item.assignTo, bits); var j = 0; - var toAdd = [value].concat(elements.map(function(element) { - return { - intertype: 'value', - assignTo: element.ident, - type: 'i' + bits, - ident: value.assignTo + '[' + j + ']', - // Add the assignTo as a value so it is not eliminated as unneeded (the ident is not a simple ident here) - value: { intertype: 'value', ident: value.assignTo, type: value.type } - }; - })); + var toAdd = [value]; + // legalize parameters + legalizeFunctionParameters(value.params); + if (value.assignTo) { + // legalize return value + toAdd = toAdd.concat(elements.map(function(element) { + return { + intertype: 'value', + assignTo: element.ident, + type: 'i' + bits, + ident: value.assignTo + '[' + j + ']', + // Add the assignTo as a value so it is not eliminated as unneeded (the ident is not a simple ident here) + value: { intertype: 'value', ident: value.assignTo, type: value.type } + }; + })); + } i += removeAndAdd(label.lines, i, toAdd); continue; } - case 'ret': { + case 'return': { bits = getBits(item.type); var elements = getLegalVars(item.value.ident, bits); item.value.ident = '[' + elements.map(function(element) { return element.ident }).join(',') + ']'; diff --git a/src/jsifier.js b/src/jsifier.js index 8bfe453b..b830fc7c 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1053,29 +1053,13 @@ function JSify(data, functionsOnly, givenFunctions) { params.forEach(function(param, i) { var val = finalizeParam(param); if (!hasVarArgs || useJSArgs || i < normalArgs) { - if (param.type == 'i64' && I64_MODE == 1) { - val = makeCopyI64(val); // Must copy [low, high] i64s, so they don't end up modified in the caller - } args.push(val); argsTypes.push(param.type); } else { - if (!(param.type == 'i64' && I64_MODE == 1)) { - varargs.push(val); - varargs = varargs.concat(zeros(Runtime.getNativeFieldSize(param.type)-1)); - varargsTypes.push(param.type); - varargsTypes = varargsTypes.concat(zeros(Runtime.getNativeFieldSize(param.type)-1)); - } else { - // i64 mode 1. Write one i32 with type i64, and one i32 with type i32 - varargs.push(val + '[0]'); - varargs = varargs.concat(zeros(Runtime.getNativeFieldSize('i32')-1)); - ignoreFunctionIndexizing.push(varargs.length); // We will have a value there, but no type (the type is i64, but we write two i32s) - varargs.push(val + '[1]'); - varargs = varargs.concat(zeros(Runtime.getNativeFieldSize('i32')-1)); - varargsTypes.push('i64'); - varargsTypes = varargsTypes.concat(zeros(Runtime.getNativeFieldSize('i32')-1)); - varargsTypes.push('i32'); - varargsTypes = varargsTypes.concat(zeros(Runtime.getNativeFieldSize('i32')-1)); - } + varargs.push(val); + varargs = varargs.concat(zeros(Runtime.getNativeFieldSize(param.type)-1)); + varargsTypes.push(param.type); + varargsTypes = varargsTypes.concat(zeros(Runtime.getNativeFieldSize(param.type)-1)); } }); @@ -1095,7 +1079,6 @@ function JSify(data, functionsOnly, givenFunctions) { varargs.map(function(arg, i) { var type = varargsTypes[i]; if (type == 0) return null; - if (I64_MODE == 1 && type == 'i64') type = 'i32'; // We have [i64, 0, 0, 0, i32, 0, 0, 0] in the layout at this point var ret = makeSetValue(getFastValue('tempInt', '+', offset), 0, arg, type, null, null, QUANTUM_SIZE, null, ','); offset += Runtime.getNativeFieldSize(type); return ret; diff --git a/src/parseTools.js b/src/parseTools.js index d8221499..e1072308 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -901,11 +901,6 @@ function makeGetValue(ptr, pos, type, noNeedFirst, unsigned, ignore, align, noSa if (i < bytes-1) ret += '|'; } ret = '(' + makeSignOp(ret, type, unsigned ? 'un' : 're', true); - } else { - assert(bytes == 8); - ret += 'tempBigInt=' + makeGetValue(ptr, pos, 'i32', noNeedFirst, true, ignore, align) + ','; - ret += 'tempBigInt2=' + makeGetValue(ptr, getFastValue(pos, '+', Runtime.getNativeTypeSize('i32')), 'i32', noNeedFirst, true, ignore, align) + ','; - ret += makeI64('tempBigInt', 'tempBigInt2'); } } else { if (type == 'float') { @@ -919,11 +914,6 @@ function makeGetValue(ptr, pos, type, noNeedFirst, unsigned, ignore, align, noSa } } - if (type == 'i64' && I64_MODE == 1) { - return '[' + makeGetValue(ptr, pos, 'i32', noNeedFirst, 1, ignore) + ',' - + makeGetValue(ptr, getFastValue(pos, '+', Runtime.getNativeTypeSize('i32')), 'i32', noNeedFirst, 1, ignore) + ']'; - } - var offset = calcFastOffset(ptr, pos, noNeedFirst); if (SAFE_HEAP && !noSafe) { if (type !== 'null' && type[0] !== '#') type = '"' + safeQuote(type) + '"'; @@ -992,16 +982,12 @@ function makeSetValue(ptr, pos, value, type, noNeedFirst, ignore, align, noSafe, ret += 'tempBigInt=' + value + sep; ret += makeSetValue(ptr, pos, 'tempBigInt&0xffff', 'i16', noNeedFirst, ignore, 2) + sep; ret += makeSetValue(ptr, getFastValue(pos, '+', 2), 'tempBigInt>>16', 'i16', noNeedFirst, ignore, 2); - } else if (bytes != 8) { + } else { ret += 'tempBigInt=' + value + sep; for (var i = 0; i < bytes; i++) { ret += makeSetValue(ptr, getFastValue(pos, '+', i), 'tempBigInt&0xff', 'i8', noNeedFirst, ignore, 1); if (i < bytes-1) ret += sep + 'tempBigInt>>=8' + sep; } - } else { // bytes == 8, specific optimization - ret += 'tempPair=' + ensureI64_1(value) + sep; - ret += makeSetValue(ptr, pos, 'tempPair[0]', 'i32', noNeedFirst, ignore, align) + sep; - ret += makeSetValue(ptr, getFastValue(pos, '+', Runtime.getNativeTypeSize('i32')), 'tempPair[1]', 'i32', noNeedFirst, ignore, align); } } else { ret += makeSetValue('tempDoublePtr', 0, value, type, noNeedFirst, ignore, 8) + sep; @@ -1011,11 +997,6 @@ function makeSetValue(ptr, pos, value, type, noNeedFirst, ignore, align, noSafe, } } - if (type == 'i64' && I64_MODE == 1) { - return '(' + makeSetValue(ptr, pos, value + '[0]', 'i32', noNeedFirst, ignore) + ',' - + makeSetValue(ptr, getFastValue(pos, '+', Runtime.getNativeTypeSize('i32')), value + '[1]', 'i32', noNeedFirst, ignore) + ')'; - } - value = indexizeFunctions(value, type); var offset = calcFastOffset(ptr, pos, noNeedFirst); if (SAFE_HEAP && !noSafe) { |