diff options
author | Alon Zakai <azakai@mozilla.com> | 2011-02-12 19:36:02 -0800 |
---|---|---|
committer | Alon Zakai <azakai@mozilla.com> | 2011-02-12 19:36:02 -0800 |
commit | bace573eb4e44e43227d4134e34158969d914efa (patch) | |
tree | cb50163af1c4a424132b20e1ded77e5cf8e6f4b2 /src | |
parent | ffb61d77cae700fe2f45c60e06715033ae9f653a (diff) |
line number debugging info
Diffstat (limited to 'src')
-rw-r--r-- | src/intertyper.js | 46 | ||||
-rw-r--r-- | src/jsifier.js | 2 |
2 files changed, 47 insertions, 1 deletions
diff --git a/src/intertyper.js b/src/intertyper.js index efe34216..3db09516 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -10,6 +10,45 @@ var LLVM = { CALLING_CONVENTIONS: set('ccc', 'fastcc', 'coldcc', 'cc10') }; +var Debugging = { + processMetadata: function(lines) { + var llvmLineToMetadata = {}; + var metadataToSourceLine = {}; + var form1 = new RegExp(/^ .*, !dbg !(\d+)$/); + var form2 = new RegExp(/^ .*, !dbg !(\d+) +; \[#uses=\d+\]$/); + var form3 = new RegExp(/^!(\d+) = metadata !{\w+\d* !?(\d+)[^\d].*$/); + var form4 = new RegExp(/^!llvm.dbg.\w+ = .*$/); + var form5 = new RegExp(/^!(\d+) = metadata !{null.*$/); + var form6 = new RegExp(/^ call void \@llvm.dbg.declare\(metadata .*$/); + + var ret = lines.map(function(line, i) { + if (form6.exec(line)) return null; + + var calc = form1.exec(line) || form2.exec(line); + if (calc) { + llvmLineToMetadata[i+1] = calc[1]; + return line.replace(', !dbg !' + calc[1], ''); + } + calc = form3.exec(line); + if (calc) { + metadataToSourceLine[calc[1]] = calc[2]; + return ';'; // return an empty line, to keep line numbers of subsequent lines the same + } + calc = form4.exec(line) || form5.exec(line); + if (calc) return ';'; + return line; + }, this); + + this.llvmLineToSourceLine = {}; + for (var l in llvmLineToMetadata) { + this.llvmLineToSourceLine[l] = metadataToSourceLine[llvmLineToMetadata[l]]; + } + this.on = true; + + return ret; + }, +}; + //! @param parseFunctions We parse functions only on later passes, since we do not //! want to parse all of them at once, and have all their //! lines and data in memory at the same time. @@ -25,6 +64,13 @@ function intertyper(data, parseFunctions, baseLineNum) { dprint('LLVM_STYLE: ' + LLVM_STYLE); } + // If the source contains debug info as LLVM metadata, process that out (and save the debugging info for later) + if (/!\d+ = metadata .*/.exec(data[data.length-1])) { // Fast test to see if we have metadata. If this fails when it shouldn't, we should generalize + data = Debugging.processMetadata(data); + //print(data.join('\n')); + //dprint(JSON.stringify(Debugging)); + } + substrate = new Substrate('Intertyper'); // Line splitter. diff --git a/src/jsifier.js b/src/jsifier.js index 765c41f8..32cf263d 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -436,7 +436,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria ret += indent + 'if (Date.now() - START_TIME >= ' + (EXECUTION_TIMEOUT*1000) + ') throw "Timed out!" + (new Error().stack);\n'; } // for special labels we care about (for phi), mark that we visited them - return ret + label.lines.map(function(line) { return line.JS + (line.comment ? ' // ' + line.comment : '') }) + return ret + label.lines.map(function(line) { return line.JS + (Debugging.on ? ' //@line ' + Debugging.llvmLineToSourceLine[line.lineNum] : '') }) .join('\n') .split('\n') // some lines include line breaks .map(function(line) { return indent + line }) |