diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-10-12 10:28:48 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-10-12 10:28:48 -0700 |
commit | a6cfef0ce650e089d8b23bb0035c8ac19bd7c417 (patch) | |
tree | b1cdfe79b03a0f91982547405c66c5323986cd9a /src | |
parent | 11e6a91e022ff5c58479fa69059e23ad6286fb59 (diff) |
demangle basic params
Diffstat (limited to 'src')
-rw-r--r-- | src/preamble.js | 72 |
1 files changed, 54 insertions, 18 deletions
diff --git a/src/preamble.js b/src/preamble.js index 6f148e60..ecabcf69 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -641,25 +641,61 @@ function stringToUTF32(str, outPtr) { Module['stringToUTF32'] = stringToUTF32; function demangle(func) { - if (typeof func === 'number') func = Pointer_stringify(func); - assert(func[0] === '_'); - if (func[1] !== '_') return func.substr(1); // C function - assert(func[2] === 'Z'); - if (func[3] !== 'N') { - // not namespaced - var m = /(\d+)([^\d].*)/.exec(func.substr(3)); - return m ? m[2].substr(0, m[1]) : func; - } - // namespaced N-E - var i = 4, ret = []; - while (func[i] !== 'E') { - var size = parseInt(func.substr(i)); - var pre = size.toString().length; - ret.push(func.substr(i + pre, size)); - i += pre + size; - assert(pre > 0 && size > 0 && i < func.length); + try { + if (typeof func === 'number') func = Pointer_stringify(func); + assert(func[0] === '_'); + if (func[1] !== '_') return func.substr(1); // C function + assert(func[2] === 'Z'); + var i, ret; + if (func[3] !== 'N') { + // not namespaced + var m = /(\d+)([^\d].*)/.exec(func.substr(3)); + if (!m) return func; + var size = parseInt(m[1]); + i = 3 + size.toString().length + size; + ret = m[2].substr(0, size); + } else { + // namespaced N-E + var i = 4, ret = []; + while (func[i] !== 'E') { + var size = parseInt(func.substr(i)); + var pre = size.toString().length; + ret.push(func.substr(i + pre, size)); + i += pre + size; + assert(pre > 0 && size > 0 && i < func.length); + } + i++; // skip E + ret = ret.join('::'); + } + // params + if (i < func.length) { + ret += '('; + var first = true, suffix = null; + paramLoop: while (i < func.length) { + if (!suffix && !first) ret += ', '; + first = false; + switch (func[i]) { + case 'c': ret += 'char'; i++; break; + case 's': ret += 'short'; i++; break; + case 'i': ret += 'int'; i++; break; + case 'l': ret += 'long'; i++; break; + case 'f': ret += 'float'; i++; break; + case 'd': ret += 'double'; i++; break; + case 'P': suffix = '*'; i++; continue; break; + case 'v': ret += 'void'; i++; break; + default: ret += '?' + func[i]; break paramLoop; + } + if (suffix) { + ret += suffix; + suffix = null; + } + } + ret += ')'; + } + return ret; + } catch(e) { + return func + '<demangle-err>'; } - return ret.join('::'); } // Memory management |