git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: ccd5cf6291ba56bba5cd804c94c57da6b7801c40

Files: ccd5cf6291ba56bba5cd804c94c57da6b7801c40 / debugInterface.js

860 bytesRaw
1/**
2 * Debug Interface
3 * This expose some functions that can help with debugging wast
4 */
5
6// This is ASCII only
7function Uint8ArrayToString (input) {
8 return String.fromCharCode.apply(null, input)
9}
10
11function Uint8ArrayToHexString (input) {
12 var ret = ''
13 for (var i = 0; i < input.length; i++) {
14 ret += input[i].toString(16)
15 }
16 return ret
17}
18
19module.exports = class DebugInterface {
20 setModule (mod) {
21 this.module = mod
22 }
23
24 get exportTable () {
25 return {
26 'print': function (offset, length) {
27 console.log(`<DEBUG(str): ${Uint8ArrayToString(new Uint8Array(this.module.exports.memory, offset, length))}>`)
28 }.bind(this),
29
30 'printHex': function (offset, length) {
31 console.log(`<DEBUG(hex): ${Uint8ArrayToHexString(new Uint8Array(this.module.exports.memory, offset, length))}>`)
32 }.bind(this)
33 }
34 }
35}
36

Built with git-ssb-web