diff options
author | Daniel Wirtz <dcode@dcode.io> | 2018-01-29 22:51:39 +0100 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2018-01-29 13:51:39 -0800 |
commit | b1d24f5c552ccb0c3076e252b893990340d6016e (patch) | |
tree | ffe29a3b77c1c717be279f21d6970cbfa83ed129 /test | |
parent | f9087893cde7e653a66dd125386a97d228a749a2 (diff) | |
download | binaryen-b1d24f5c552ccb0c3076e252b893990340d6016e.tar.gz binaryen-b1d24f5c552ccb0c3076e252b893990340d6016e.tar.bz2 binaryen-b1d24f5c552ccb0c3076e252b893990340d6016e.zip |
Sourcemap support for Binaryen C/JS (#1392)
* Initial source map support for C/JS
* Also test getDebugInfoFileName
Diffstat (limited to 'test')
-rw-r--r-- | test/binaryen.js/sourcemap.js | 39 | ||||
-rw-r--r-- | test/binaryen.js/sourcemap.js.txt | 8 |
2 files changed, 47 insertions, 0 deletions
diff --git a/test/binaryen.js/sourcemap.js b/test/binaryen.js/sourcemap.js new file mode 100644 index 000000000..b184f73ab --- /dev/null +++ b/test/binaryen.js/sourcemap.js @@ -0,0 +1,39 @@ +var module = new Binaryen.Module(); + +var signature = module.addFunctionType("i", Binaryen.i32, []); + +var fileIndex = module.addDebugInfoFileName("module.c"); + +console.log(module.getDebugInfoFileName(fileIndex)); +console.log(); + +var expr = module.i32.const(1); +var body = module.block("", [ + expr +], Binaryen.i32); + +var func = module.addFunction("main", signature, [], body); + +module.setDebugLocation(func, expr, fileIndex, 1, 2); +module.setDebugLocation(func, body, fileIndex, 0, 3); + +var output = module.emitBinaryWithSourceMap("module.wasm.map"); + +function dumpBinary(buffer) { + var hex = [], o, b, h; + for (var i = 0; i < buffer.length; ++i) { + o = i.toString(16); + while (o.length < 3) o = "0" + o; + if ((i & 15) === 0) hex.push((i ? "\n" : "") + o + ":"); + if ((b = buffer[i]) >= 0x21 && b <= 0x7e) + h = String.fromCharCode(b) + ' '; + else if ((h = b.toString(16)).length < 2) + h = "0" + h; + hex.push(h); + } + console.log(hex.join(" ")); +} + +dumpBinary(output.binary); +console.log(); +console.log(output.sourceMap); diff --git a/test/binaryen.js/sourcemap.js.txt b/test/binaryen.js/sourcemap.js.txt new file mode 100644 index 000000000..0065a09db --- /dev/null +++ b/test/binaryen.js/sourcemap.js.txt @@ -0,0 +1,8 @@ +module.c + +000: 00 a s m 01 00 00 00 01 05 01 ` 00 01 7f 03 +010: 02 01 00 0a 06 01 04 00 A 01 0b 00 ! 10 s o +020: u r c e M a p p i n g U R L 0f m +030: o d u l e . w a s m . m a p + +{"version":3,"sources":["module.c"],"names":[],"mappings":"gCAAE"} |