diff options
-rw-r--r-- | src/compiler.js | 2 | ||||
-rw-r--r-- | src/intertyper.js | 29 | ||||
-rw-r--r-- | src/utility.js | 11 |
3 files changed, 40 insertions, 2 deletions
diff --git a/src/compiler.js b/src/compiler.js index 24136551..06cbcd1f 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -275,7 +275,7 @@ function compile(raw) { JSify(analyzed); //dumpInterProf(); - //printErr('Paths (fast, slow): ' + [fastPaths, slowPaths]); + //printErr(phase + ' paths (fast, slow): ' + [fastPaths, slowPaths]); phase = null; diff --git a/src/intertyper.js b/src/intertyper.js index f452c955..d4e9c7b4 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -1012,12 +1012,39 @@ function intertyper(lines, sidePass, baseLineNums) { }; noteGlobalVariable(ret); } + } else if (phase === 'funcs') { + // simple gep + if (m = / (%[\w\d\._]+) = getelementptr (?:inbounds )?([%\w\d\._ ,\*-@]+$)/.exec(line.lineText)) { + var params = m[2].split(', ').map(function(param) { + var parts = param.split(' '); + assert(parts.length === 2); + Types.needAnalysis[parts[0]] = 0; + return { + intertype: 'value', + type: parts[0], + ident: toNiceIdent(parts[1]), + byVal: 0 + } + }); + ret = { + intertype: 'getelementptr', + lineNum: line.lineNum, + assignTo: toNiceIdent(m[1]), + ident: params[0].ident, + type: '*', + params: params + }; + } + // else if (line.lineText.indexOf(' = getelementptr ') > 0) printErr('close: ' + line.lineText); } if (ret) { fastPaths++; if (COMPILER_ASSERTIONS) { //printErr(['\n', JSON.stringify(ret), '\n', JSON.stringify(triager(tokenizer(line)))]); - assert(JSON.stringify(ret) === JSON.stringify(triager(tokenizer(line))), 'fast path'); + var normal = triager(tokenizer(line)); + delete normal.tokens; + delete normal.indent; + assert(sortedJsonCompare(normal, ret), 'fast path: ' + dump(normal) + '\n vs \n' + dump(ret)); } finalResults.push(ret); } diff --git a/src/utility.js b/src/utility.js index 7d122cef..b793106c 100644 --- a/src/utility.js +++ b/src/utility.js @@ -334,6 +334,17 @@ function jsonCompare(x, y) { return JSON.stringify(x) == JSON.stringify(y); } +function sortedJsonCompare(x, y) { + if (x === null || typeof x !== 'object') return x === y; + for (var i in x) { + if (!sortedJsonCompare(x[i], y[i])) return false; + } + for (var i in y) { + if (!sortedJsonCompare(x[i], y[i])) return false; + } + return true; +} + function stringifyWithFunctions(obj) { if (typeof obj === 'function') return obj.toString(); if (obj === null || typeof obj !== 'object') return JSON.stringify(obj); |