diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-09-01 15:25:44 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-09-01 15:25:44 -0700 |
commit | 10ff1bd0083e4a54ccd949e9e4b6b84d66b9c569 (patch) | |
tree | b1d39301b14a0161a1f1e771977950ef001b4a39 | |
parent | c1a6d53ea95c104ca454c7690d2210b1731f54a4 (diff) |
fix parsing bugs
-rw-r--r-- | src/intertyper.js | 14 | ||||
-rw-r--r-- | src/library.js | 4 | ||||
-rw-r--r-- | src/modules.js | 4 | ||||
-rw-r--r-- | src/parseTools.js | 18 |
4 files changed, 22 insertions, 18 deletions
diff --git a/src/intertyper.js b/src/intertyper.js index 2a220882..3cdaa45e 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -53,6 +53,7 @@ function intertyper(data, parseFunctions, baseLineNum) { if (!inFunction || parseFunctions) { if (inContinual || new RegExp(/^\ +to.*/g).test(line) || new RegExp(/^\ +catch .*/g).test(line) + || new RegExp(/^\ +filter .*/g).test(line) || new RegExp(/^\ +cleanup .*/g).test(line)) { // to after invoke or landingpad second line ret.slice(-1)[0].lineText += line; @@ -391,8 +392,8 @@ function intertyper(data, parseFunctions, baseLineNum) { } if (item.tokens[2].text == 'alias') { - cleanOutTokensSet(LLVM.LINKAGES, item.tokens, 3); - cleanOutTokensSet(LLVM.VISIBILITIES, item.tokens, 3); + cleanOutTokens(LLVM.LINKAGES, item.tokens, 3); + cleanOutTokens(LLVM.VISIBILITIES, item.tokens, 3); return [{ intertype: 'alias', ident: toNiceIdent(item.tokens[0].text), @@ -431,8 +432,7 @@ function intertyper(data, parseFunctions, baseLineNum) { } else { // variable var ident = item.tokens[0].text; - cleanOutTokensSet(LLVM.GLOBAL_MODIFIERS, item.tokens, 3); - cleanOutTokensSet(LLVM.GLOBAL_MODIFIERS, item.tokens, 2); + cleanOutTokens(LLVM.GLOBAL_MODIFIERS, item.tokens, [2, 3]); var external = false; if (item.tokens[2].text === 'external') { external = true; @@ -528,7 +528,7 @@ function intertyper(data, parseFunctions, baseLineNum) { substrate.addActor('Load', { processItem: function(item) { item.intertype = 'load'; - if (item.tokens[0].text == 'volatile') item.tokens.shift(0); + cleanOutTokens(LLVM.ACCESS_OPTIONS, item.tokens, [0, 1]); item.pointerType = item.tokens[1].text; item.valueType = item.type = removePointing(item.pointerType); Types.needAnalysis[item.type] = 0; @@ -634,7 +634,7 @@ function intertyper(data, parseFunctions, baseLineNum) { } item.ident = toNiceIdent(item.ident); if (type === 'invoke') { - cleanOutTokens(['alignstack', 'alwaysinline', 'inlinehint', 'naked', 'noimplicitfloat', 'noinline', 'alwaysinline attribute.', 'noredzone', 'noreturn', 'nounwind', 'optsize', 'readnone', 'readonly', 'ssp', 'sspreq'], item.tokens, 4); + cleanOutTokens(LLVM.INVOKE_MODIFIERS, item.tokens, 4); item.toLabel = toNiceIdent(item.tokens[6].text); item.unwindLabel = toNiceIdent(item.tokens[9].text); } @@ -740,7 +740,7 @@ function intertyper(data, parseFunctions, baseLineNum) { // 'store' substrate.addActor('Store', { processItem: function(item) { - if (item.tokens[0].text == 'volatile') item.tokens.shift(0); + cleanOutTokens(LLVM.ACCESS_OPTIONS, item.tokens, [0, 1]); var segments = splitTokenList(item.tokens.slice(1)); var ret = { intertype: 'store', diff --git a/src/library.js b/src/library.js index 62e4de55..3b4c0962 100644 --- a/src/library.js +++ b/src/library.js @@ -4046,6 +4046,10 @@ LibraryManager.library = { return ret; }, + llvm_expect_i32: function(x, y) { + assert(x == y, 'Expect failed!'); + }, + // ========================================================================== // iostream.h // ========================================================================== diff --git a/src/modules.js b/src/modules.js index cc056314..495f8663 100644 --- a/src/modules.js +++ b/src/modules.js @@ -8,7 +8,9 @@ var LLVM = { 'weak_odr', 'externally_visible', 'dllimport', 'dllexport', 'unnamed_addr'), VISIBILITIES: set('default', 'hidden', 'protected'), PARAM_ATTR: set('noalias', 'signext', 'zeroext', 'inreg', 'sret', 'nocapture', 'nest'), - CALLING_CONVENTIONS: set('ccc', 'fastcc', 'coldcc', 'cc10', 'x86_fastcallcc') + CALLING_CONVENTIONS: set('ccc', 'fastcc', 'coldcc', 'cc10', 'x86_fastcallcc'), + ACCESS_OPTIONS: set('volatile', 'atomic'), + INVOKE_MODIFIERS: set('alignstack', 'alwaysinline', 'inlinehint', 'naked', 'noimplicitfloat', 'noinline', 'alwaysinline attribute.', 'noredzone', 'noreturn', 'nounwind', 'optsize', 'readnone', 'readonly', 'ssp', 'sspreq') }; LLVM.GLOBAL_MODIFIERS = set(keys(LLVM.LINKAGES).concat(['constant', 'global', 'hidden'])); diff --git a/src/parseTools.js b/src/parseTools.js index 46f664b4..3d747aec 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -53,7 +53,7 @@ function preprocess(text, constants) { function addPointing(type) { return type + '*' } function removePointing(type, num) { if (num === 0) return type; - assert(type.substr(type.length-(num ? num : 1)).replace(/\*/g, '') === ''); + assert(type.substr(type.length-(num ? num : 1)).replace(/\*/g, '') === ''); //, 'Error in removePointing with ' + [type, num, type.substr(type.length-(num ? num : 1))]); return type.substr(0, type.length-(num ? num : 1)); } @@ -467,15 +467,13 @@ function eatLLVMIdent(tokens) { return ret; } -function cleanOutTokens(filterOut, tokens, index) { - while (filterOut.indexOf(tokens[index].text) != -1) { - tokens.splice(index, 1); - } -} - -function cleanOutTokensSet(filterOut, tokens, index) { - while (tokens[index].text in filterOut) { - tokens.splice(index, 1); +function cleanOutTokens(filterOut, tokens, indexes) { + if (typeof indexes !== 'object') indexes = [indexes]; + for (var i = indexes.length-1; i >=0; i--) { + var index = indexes[i]; + while (tokens[index].text in filterOut) { + tokens.splice(index, 1); + } } } |