From b3d56fb9354522a110ac2ef6b6acef44eaa92705 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Wed, 7 Dec 2016 13:53:32 -0600 Subject: [PATCH] Demangle *after* parsing ASM. This means the ASM parser sees "simpler" mangled names, which makes its primitive RegExp-based parser much simpler and more correct. Once we've extracted labels etc, we can demangle the symbols. This should address #193 --- app.js | 1 + etc/config/c++.defaults.properties | 3 ++- lib/compile.js | 43 +++++++++++++++++++++--------- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/app.js b/app.js index 8b7d475c..fb3121f1 100755 --- a/app.js +++ b/app.js @@ -328,6 +328,7 @@ function findCompilers() { versionFlag: props("versionFlag"), versionRe: props("versionRe"), compilerType: props("compilerType", ""), + demangler: props("demangler", ""), intelAsm: props("intelAsm", ""), needsMulti: !!props("needsMulti", true), supportsBinary: !!props("supportsBinary", true), diff --git a/etc/config/c++.defaults.properties b/etc/config/c++.defaults.properties index 73eef18a..32cb1a91 100644 --- a/etc/config/c++.defaults.properties +++ b/etc/config/c++.defaults.properties @@ -2,7 +2,8 @@ compilers=/usr/bin/g++-4.4:/usr/bin/g++-4.5:/usr/bin/g++-4.6:/usr/bin/g++-4.7:/usr/bin/clang++:/usr/bin/g++ defaultCompiler=/usr/bin/g++ compileFilename=example.cpp -postProcess=c++filt +postProcess= +demangler=c++filt #androidNdk=/opt/google/android-ndk-r9c options= supportsBinary=true diff --git a/lib/compile.js b/lib/compile.js index ab649405..e6ece045 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -190,20 +190,38 @@ Compile.prototype.compile = function (source, options, filters) { }); return self.env.enqueue(function () { - return compileToAsmPromise.then(function (result) { - if (result.dirPath) { - fs.remove(result.dirPath); - result.dirPath = undefined; - } - if (result.okToCache) { - result.asm = asm.processAsm(result.asm, filters); - self.env.cachePut(key, result); - } else { - result.asm = {text: result.asm}; - } + return compileToAsmPromise + .then(function (result) { + if (result.dirPath) { + fs.remove(result.dirPath); + result.dirPath = undefined; + } + if (result.okToCache) { + result.asm = asm.processAsm(result.asm, filters); + } else { + result.asm = {text: result.asm}; + } + return result; + }) + .then(_.bind(self.postProcessAsm, self)) + .then(function (result) { + if (result.okToCache) self.env.cachePut(key, result); + return result; + }); + }); +}; + +Compile.prototype.postProcessAsm = function (result) { + if (!result.okToCache) return result; + var demangler = this.compiler.demangler; + if (!demangler) return result; + return this.exec(demangler, [], {input: _.pluck(result.asm, 'text').join("\n")}) + .then(function (demangleResult) { + var lines = utils.splitLines(demangleResult.stdout); + for (var i = 0; i < result.asm.length; ++i) + result.asm[i].text = lines[i]; return result; }); - }); }; Compile.prototype.postProcess = function (result, outputFilename, filters) { @@ -321,6 +339,7 @@ Compile.prototype.exec = function (command, args, options) { }); }, 0); }); + if (options.input) child.stdin.write(options.input); child.stdin.end(); }); };