diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-10-09 07:27:06 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-10-09 07:27:06 -0700 |
commit | 8c35202927a7cd8f14b219e4949195e1e6bc6946 (patch) | |
tree | 2cc79d36f916c220b3bc449cba4d3ab602f534c4 /src/analyzer.js | |
parent | efaf3590ac33702eeff423e31e85f690b1fc7eb2 (diff) | |
parent | 06354eda6092add55034c692bd65734a61083e8b (diff) |
Merge branch 'llvm-svn'
Conflicts:
src/dlmalloc.c
tests/dlmalloc.c
tests/runner.py
tools/shared.py
Diffstat (limited to 'src/analyzer.js')
-rw-r--r-- | src/analyzer.js | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index 824e7903..37285733 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -46,8 +46,10 @@ function analyzer(data) { // Functions & labels item.functions = []; var currLabelFinished; // Sometimes LLVM puts a branch in the middle of a label. We need to ignore all lines after that. + item.items.sort(function(a, b) { return a.lineNum - b.lineNum }); for (var i = 0; i < item.items.length; i++) { var subItem = item.items[i]; + assert(subItem.lineNum); if (subItem.intertype == 'function') { item.functions.push(subItem); subItem.endLineNum = null; @@ -58,7 +60,7 @@ function analyzer(data) { if (LLVM_STYLE == 'new' && item.items[i+1].intertype !== 'label') { item.items.splice(i+1, 0, { intertype: 'label', - ident: '_entry', + ident: toNiceIdent('%0'), lineNum: subItem.lineNum + '.5' }); } @@ -77,10 +79,10 @@ function analyzer(data) { currLabelFinished = true; } } else { - print('// WARNING: content after a branch in a label, line: ' + subItem.lineNum); + print('// WARNING: content after a branch in a label, line: ' + subItem.lineNum + '::' + dump(subItem)); } } else { - print("ERROR: what is this? " + JSON.stringify(subItem)); + throw "ERROR: what is this? " + JSON.stringify(subItem); } } delete item.items; @@ -93,6 +95,7 @@ function analyzer(data) { if (Types.types[type]) return; if (['internal', 'hidden', 'inbounds', 'void'].indexOf(type) != -1) return; if (Runtime.isNumberType(type)) return; + dprint('types', 'Adding type: ' + type); // 'blocks': [14 x %struct.X] etc. If this is a pointer, we need // to look at the underlying type - it was not defined explicitly @@ -107,6 +110,8 @@ function analyzer(data) { // check that we never allocate with this (either as a child structure // in the analyzer, or in calcSize in alloca). var subType = check[2]; + addTypeInternal(subType, data); // needed for anonymous structure definitions (see below) + Types.types[nonPointing] = { name_: nonPointing, fields: range(num).map(function() { return subType }), @@ -124,6 +129,21 @@ function analyzer(data) { return; } + // anonymous structure definition, for example |{ i32, i8*, void ()*, i32 }| + if (type[0] == '{' || type[0] == '<') { + type = nonPointing; + var packed = type[0] == '<'; + Types.types[type] = { + name_: type, + fields: splitTokenList(tokenize(type.substr(2 + packed, type.length - 4 - 2*packed)).tokens).map(function(segment) { + return segment[0].text; + }), + packed: packed, + lineNum: '?' + }; + return; + } + if (isPointerType(type)) return; if (['['].indexOf(type) != -1) return; Types.types[type] = { @@ -333,7 +353,7 @@ function analyzer(data) { // Decision time - var pointedType = removePointing(variable.type); + var pointedType = pointingLevels(variable.type) > 0 ? removePointing(variable.type) : null; if (variable.origin == 'getelementptr') { // Use our implementation that emulates pointers etc. // TODO Can we perhaps nativize some of these? However to do so, we need to discover their @@ -563,7 +583,7 @@ function analyzer(data) { func.labelsDict[label.ident] = label; func.labelIds[label.ident] = func.labelIdCounter++; }); - func.labelIds[toNiceIdent('%entry')] = -1; // entry is always -1 + func.labelIds[toNiceIdent('%0')] = -1; // entry is always -1 func.hasPhi = false; func.hasIndirectBr = false; @@ -575,8 +595,9 @@ function analyzer(data) { var remarkableLabelId = line.value.params[i].label; func.remarkableLabels.push(remarkableLabelId); var remarkableLabel = func.labelsDict[remarkableLabelId]; + assert(remarkableLabel); var lastLine = remarkableLabel.lines.slice(-1)[0]; - if (lastLine.value) { + if (lastLine.intertype === 'assign') { lastLine.value.currLabelId = remarkableLabelId; } else { lastLine.currLabelId = remarkableLabelId; |