Commit b4f2286715e5d94ee25ada50027f1690079cca1b
added debuging agent
wanderer committed on 1/26/2017, 2:14:15 AMParent: fe338fdb6c586d0d30ccf3d53e445c347b67e8aa
Files changed
codeHandler.js | changed |
debugInterface.js | changed |
wasmAgent.js | changed |
wasmDebugAgent.js | added |
codeHandler.js | ||
---|---|---|
@@ -18,15 +18,16 @@ | ||
18 | 18 | return new Wasm(code) |
19 | 19 | } |
20 | 20 | } |
21 | 21 | |
22 | -let codeHandlers = exports.codeHandlers = [ | |
23 | - defaultHandler, | |
24 | - wasm | |
25 | -] | |
22 | +let codeHandlers = exports.handlers = { | |
23 | + default: defaultHandler, | |
24 | + wasm: wasm | |
25 | +} | |
26 | 26 | |
27 | 27 | exports.init = (code) => { |
28 | - for (let handler of codeHandlers) { | |
28 | + for (let name in codeHandlers) { | |
29 | + const handler = codeHandlers[name] | |
29 | 30 | if (handler.test(code)) { |
30 | 31 | return handler.init(code) |
31 | 32 | } |
32 | 33 | } |
debugInterface.js | ||
---|---|---|
@@ -3,9 +3,8 @@ | ||
3 | 3 | /** |
4 | 4 | * Debug Interface |
5 | 5 | * This expose some functions that can help with debugging wast |
6 | 6 | */ |
7 | - | |
8 | 7 | module.exports = class DebugInterface { |
9 | 8 | constructor (kernel) { |
10 | 9 | this.kernel = kernel |
11 | 10 | } |
wasmAgent.js | ||
---|---|---|
@@ -26,9 +26,9 @@ | ||
26 | 26 | return importMap |
27 | 27 | } |
28 | 28 | |
29 | 29 | let instance |
30 | - const interfaceApi = { | |
30 | + const interfaceApi = this.api = { | |
31 | 31 | /** |
32 | 32 | * adds an aync operation to the operations queue |
33 | 33 | */ |
34 | 34 | pushOpsQueue: (promise, callbackIndex, intefaceCallback) => { |
wasmDebugAgent.js | ||
---|---|---|
@@ -1,0 +1,50 @@ | ||
1 | +const Wasm = require('./wasmAgent') | |
2 | + | |
3 | +module.exports = class Test extends Wasm { | |
4 | + /** | |
5 | + * Runs the core VM with a given environment and imports | |
6 | + */ | |
7 | + async run (message, kernel, imports) { | |
8 | + const responses = {} | |
9 | + /** | |
10 | + * Builds a import map with an array of given interfaces | |
11 | + */ | |
12 | + async function buildImports (kernelApi, kernel, imports) { | |
13 | + const importMap = {} | |
14 | + for (const Import of imports) { | |
15 | + const response = responses[Import.name] = {} | |
16 | + const newIterface = new Import(kernelApi, message, response) | |
17 | + importMap[Import.name] = newIterface.exports | |
18 | + // initailize the import | |
19 | + await newIterface.initialize() | |
20 | + } | |
21 | + return importMap | |
22 | + } | |
23 | + | |
24 | + let instance | |
25 | + const interfaceApi = { | |
26 | + /** | |
27 | + * adds an aync operation to the operations queue | |
28 | + */ | |
29 | + pushOpsQueue: (promise, callbackIndex, intefaceCallback) => { | |
30 | + this._opsQueue = Promise.all([this._opsQueue, promise]).then(values => { | |
31 | + const result = intefaceCallback(values.pop()) | |
32 | + instance.exports.callback.get(callbackIndex)(result) | |
33 | + }) | |
34 | + }, | |
35 | + memory: () => { | |
36 | + return instance.exports.memory.buffer | |
37 | + }, | |
38 | + kernel: kernel | |
39 | + } | |
40 | + | |
41 | + const initializedImports = await buildImports(interfaceApi, kernel, imports) | |
42 | + this.instance = instance = WebAssembly.Instance(this._module, initializedImports) | |
43 | + | |
44 | + if (instance.exports.main) { | |
45 | + instance.exports.main() | |
46 | + } | |
47 | + await this.onDone() | |
48 | + return responses | |
49 | + } | |
50 | +} |
Built with git-ssb-web