diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-02-08 12:07:17 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-02-08 12:07:17 -0800 |
commit | ef59283debcb71ddadf5d9e9c2444d463f165557 (patch) | |
tree | 4d45bcf00b6a0620e3c3aa77adb03eff54dd4bd9 /src/analyzer.js | |
parent | cd7d64a1945a7309804008feead7ebe4acb5a722 (diff) |
refactor legalizer code, and handle stores of <32 bits but not i8 or i16, properly
Diffstat (limited to 'src/analyzer.js')
-rw-r--r-- | src/analyzer.js | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index e1f2f6c1..41d46b95 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -169,6 +169,15 @@ function analyzer(data, sidePass) { item[slot] = { intertype: 'value', ident: tempIdent, type: item[slot].type }; return i+1; } + function removeAndAdd(lines, i, toAdd) { + var item = lines[i]; + var interp = getInterp(lines, i, toAdd.length); + for (var k = 0; k < toAdd.length; k++) { + toAdd[k].lineNum = item.lineNum + (k*interp); + } + Array.prototype.splice.apply(lines, [i, 1].concat(toAdd)); + return toAdd.length; + } // Assuming we will replace the item at line i, with num items, returns // the right factor to multiply line numbers by so that they fit in between // the removed line and the line after it @@ -184,16 +193,15 @@ function analyzer(data, sidePass) { if (item.intertype == 'store') { if (isIllegalType(item.valueType)) { dprint('legalizer', 'Legalizing store at line ' + item.lineNum); + var toAdd = []; bits = getBits(item.valueType); i = unfold(label.lines, i, item, 'value'); - var interp = getInterp(label.lines, i, Math.ceil(bits/32)); - label.lines.splice(i, 1); var elements; elements = getLegalVars(item.value.ident, bits); var j = 0; elements.forEach(function(element) { var tempVar = '$st$' + i + '$' + j; - label.lines.splice(i+j*2, 0, { + toAdd.push({ intertype: 'getelementptr', assignTo: tempVar, ident: item.pointer.ident, @@ -203,10 +211,9 @@ function analyzer(data, sidePass) { { intertype: 'value', ident: '0', type: 'i32' }, { intertype: 'value', ident: j.toString(), type: 'i32' } ], - lineNum: item.lineNum + (j*interp) }); var actualSizeType = 'i' + element.bits; // The last one may be smaller than 32 bits - label.lines.splice(i+j*2+1, 0, { + toAdd.push({ intertype: 'store', valueType: actualSizeType, value: { intertype: 'value', ident: element.ident, type: actualSizeType }, @@ -214,12 +221,11 @@ function analyzer(data, sidePass) { ident: tempVar, pointerType: actualSizeType + '*', align: item.align, - lineNum: item.lineNum + ((j+0.5)*interp) }); j++; }); Types.needAnalysis['[0 x i32]'] = 0; - i += j*2; + i += removeAndAdd(label.lines, i, toAdd); continue; } } else if (item.assignTo) { @@ -412,12 +418,7 @@ function analyzer(data, sidePass) { legalValue.assignTo = item.assignTo; toAdd.push(legalValue); } - var interp = getInterp(label.lines, i, toAdd.length); - for (var k = 0; k < toAdd.length; k++) { - toAdd[k].lineNum = item.lineNum + (k*interp); - } - Array.prototype.splice.apply(label.lines, [i, 1].concat(toAdd)); - i += toAdd.length; + i += removeAndAdd(label.lines, i, toAdd); continue; } } |