Skip to content

Commit

Permalink
feat: store wasm ast on the module
Browse files Browse the repository at this point in the history
  • Loading branch information
xtuc committed May 9, 2018
1 parent d491fdc commit d72f7c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 1 addition & 8 deletions lib/wasm/WebAssemblyGenerator.js
Expand Up @@ -8,7 +8,6 @@ const Generator = require("../Generator");
const { RawSource } = require("webpack-sources");

const { editWithAST, addWithAST } = require("@webassemblyjs/wasm-edit");
const { decode } = require("@webassemblyjs/wasm-parser");
const t = require("@webassemblyjs/ast");

function compose(...fns) {
Expand Down Expand Up @@ -244,15 +243,9 @@ const addInitFunction = ({

class WebAssemblyGenerator extends Generator {
generate(module) {
const ast = module._ast;
const bin = module.originalSource().source();

// FIXME(sven): this module is parsed twice, we could preserve the AST
// from wasm/WebAssemblyParser.js
const ast = decode(bin, {
ignoreDataSection: true,
ignoreCodeSection: true
});

const importedGlobals = getImportedGlobals(ast);
const countImportedFunc = getCountImportedFunc(ast);
const startAtFuncIndex = getStartFuncIndex(ast);
Expand Down
2 changes: 2 additions & 0 deletions lib/wasm/WebAssemblyParser.js
Expand Up @@ -73,6 +73,8 @@ class WebAssemblyParser extends Tapable {
}
});

state.module._ast = ast;

return state;
}
}
Expand Down

0 comments on commit d72f7c6

Please sign in to comment.