Skip to content

Commit

Permalink
fix: generation and bump dep
Browse files Browse the repository at this point in the history
  • Loading branch information
xtuc committed May 4, 2018
1 parent edddefb commit 9cc4ebb
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 92 deletions.
35 changes: 26 additions & 9 deletions lib/wasm/WebAssemblyGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,35 @@ function getImportedGlobals(ast) {
}

/**
* Get next func index
*
* Funcs are referenced by their index in the type section, we just return the
* next index.
* Get next type index
*
* @param {Object} ast - Module's AST
* @returns {t.IndexLiteral} - index
*/
function getNextFuncIndex(ast) {
function getNextTypeIndex(ast) {
const typeSectionMetadata = t.getSectionMetadata(ast, "type");

if (typeof typeSectionMetadata === "undefined") {
return t.indexLiteral(0);
}

return t.indexLiteral(typeSectionMetadata.vectorOfSize);
return t.indexLiteral(typeSectionMetadata.vectorOfSize.value);
}

/**
* Get next func index
*
* @param {Object} ast - Module's AST
* @returns {t.IndexLiteral} - index
*/
function getNextFuncIndex(ast) {
const funcSectionMetadata = t.getSectionMetadata(ast, "func");

if (typeof funcSectionMetadata === "undefined") {
return t.indexLiteral(0);
}

return t.indexLiteral(funcSectionMetadata.vectorOfSize.value);
}

/**
Expand Down Expand Up @@ -145,13 +158,15 @@ const rewriteImportedGlobals = state => bin => {
* @param {t.ModuleImport[]} state.importedGlobals list of imported globals
* @param {*} state.funcSectionMetadata ??
* @param {t.IndexLiteral} state.nextFuncIndex index of the next function
* @param {t.IndexLiteral} state.nextTypeIndex index of the next type
* @returns {ArrayBufferTransform} transform
*/
const addInitFunction = ({
startAtFuncIndex,
importedGlobals,
funcSectionMetadata,
nextFuncIndex
nextFuncIndex,
nextTypeIndex
}) => bin => {
const funcParams = importedGlobals.map(importedGlobal => {
// used for debugging
Expand Down Expand Up @@ -182,7 +197,7 @@ const addInitFunction = ({
func.signature.params,
func.signature.result
);
const funcindex = t.indexInFuncSection(nextFuncIndex);
const funcindex = t.indexInFuncSection(nextTypeIndex);

const moduleExport = t.moduleExport(initFuncId.value, "Func", nextFuncIndex);

Expand All @@ -201,6 +216,7 @@ class WebAssemblyGenerator extends Generator {
const funcSectionMetadata = t.getSectionMetadata(ast, "func");
const startAtFuncIndex = getStartFuncIndex(ast);
const nextFuncIndex = getNextFuncIndex(ast);
const nextTypeIndex = getNextTypeIndex(ast);

const transform = compose(
removeStartFunc({}),
Expand All @@ -211,7 +227,8 @@ class WebAssemblyGenerator extends Generator {
importedGlobals,
funcSectionMetadata,
startAtFuncIndex,
nextFuncIndex
nextFuncIndex,
nextTypeIndex
})
);

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
"license": "MIT",
"dependencies": {
"@webassemblyjs/ast": "1.2.7",
"@webassemblyjs/wasm-edit": "1.2.7",
"@webassemblyjs/wasm-parser": "1.2.7",
"@webassemblyjs/ast": "1.3.0",
"@webassemblyjs/wasm-edit": "1.3.0",
"@webassemblyjs/wasm-parser": "1.3.0",
"acorn": "^5.0.0",
"acorn-dynamic-import": "^3.0.0",
"ajv": "^6.1.0",
Expand Down
171 changes: 91 additions & 80 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,104 +18,115 @@
version "1.0.2"
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.2.tgz#e13182e1b69871a422d7863e11a4a6f5b814a4bd"

"@webassemblyjs/ast@1.2.7":
version "1.2.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.2.7.tgz#2643dcda911e9dcb18a1ca40ac8f0a23dd1eb176"
"@webassemblyjs/ast@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.3.0.tgz#524246cd578c30ff792d0c7b49bb0a0f89191dd2"
dependencies:
"@webassemblyjs/wast-parser" "1.2.7"
webassemblyjs "1.2.7"
"@webassemblyjs/helper-wasm-bytecode" "1.3.0"
"@webassemblyjs/wast-parser" "1.3.0"
webassemblyjs "1.3.0"

"@webassemblyjs/floating-point-hex-parser@1.2.7":
version "1.2.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.2.7.tgz#a6dd3fbcd016a3af4f358b7ed01eed1901b8aada"
"@webassemblyjs/floating-point-hex-parser@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.3.0.tgz#a32574e1327a946c78711179fda8bcc808285913"

"@webassemblyjs/helper-buffer@1.2.7":
version "1.2.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.2.7.tgz#ea049ceda8d052c3d9a67339ab58c6d374ae7231"
"@webassemblyjs/helper-buffer@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.3.0.tgz#790599218673099863b6f5f84d36cc8caab861b2"

"@webassemblyjs/helper-code-frame@1.2.7":
version "1.2.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-code-frame/-/helper-code-frame-1.2.7.tgz#7af6870fdd2038adaac31ee11c9b166cd2c4e957"
"@webassemblyjs/helper-code-frame@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-code-frame/-/helper-code-frame-1.3.0.tgz#8f7d4cd9a2aed3c633cdd79aa660e96279a349bf"
dependencies:
"@webassemblyjs/wast-printer" "1.2.7"
"@webassemblyjs/wast-printer" "1.3.0"

"@webassemblyjs/helper-fsm@1.2.7":
version "1.2.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-fsm/-/helper-fsm-1.2.7.tgz#c5c346a19195f854fcf698bba3d4608c9505985b"
"@webassemblyjs/helper-fsm@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-fsm/-/helper-fsm-1.3.0.tgz#515141ec51c47b892def606dfc706e7708d4398a"

"@webassemblyjs/helper-wasm-bytecode@1.2.7":
version "1.2.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.2.7.tgz#7e0020e9112ffe3b76a83bb8071b65e540e9f895"
"@webassemblyjs/helper-wasm-bytecode@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.3.0.tgz#d23d55fcef04e4f24d6728e31bda8f1257293f91"

"@webassemblyjs/helper-wasm-section@1.2.7":
version "1.2.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.2.7.tgz#98ae0312f285fe4ae6ab2c3daac3121cf078a568"
"@webassemblyjs/helper-wasm-section@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.3.0.tgz#a8c9435faca44734fc67dfaee4911ac8e6627bd7"
dependencies:
"@webassemblyjs/ast" "1.2.7"
"@webassemblyjs/helper-buffer" "1.2.7"
"@webassemblyjs/helper-wasm-bytecode" "1.2.7"
"@webassemblyjs/wasm-gen" "1.2.7"
"@webassemblyjs/ast" "1.3.0"
"@webassemblyjs/helper-buffer" "1.3.0"
"@webassemblyjs/helper-wasm-bytecode" "1.3.0"
"@webassemblyjs/wasm-gen" "1.3.0"

"@webassemblyjs/leb128@1.2.7":
version "1.2.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.2.7.tgz#53c0c0f261ab27c52f585296d561b0e4078853ad"
"@webassemblyjs/leb128@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.3.0.tgz#b9995160f0f94d785579a149716bb2cb0d102f08"
dependencies:
leb "^0.3.0"

"@webassemblyjs/validation@1.2.7":
version "1.2.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/validation/-/validation-1.2.7.tgz#4ae3b08cb2a802598c44cf824c06c030d3c30c82"
"@webassemblyjs/validation@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/validation/-/validation-1.3.0.tgz#0a1261f414607a04e2ffebb1b3ea9777b35c97af"
dependencies:
"@webassemblyjs/ast" "1.2.7"
"@webassemblyjs/ast" "1.3.0"

"@webassemblyjs/[email protected]":
version "1.2.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.2.7.tgz#5a253b0451dd49ee4159b9bae78ce47d23610d9c"
dependencies:
"@webassemblyjs/ast" "1.2.7"
"@webassemblyjs/helper-buffer" "1.2.7"
"@webassemblyjs/helper-wasm-bytecode" "1.2.7"
"@webassemblyjs/helper-wasm-section" "1.2.7"
"@webassemblyjs/wasm-gen" "1.2.7"
"@webassemblyjs/wasm-parser" "1.2.7"
"@webassemblyjs/wast-printer" "1.2.7"
"@webassemblyjs/[email protected]":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.3.0.tgz#48551c391aebb07e82634cd4ecf257456208a0d3"
dependencies:
"@webassemblyjs/ast" "1.3.0"
"@webassemblyjs/helper-buffer" "1.3.0"
"@webassemblyjs/helper-wasm-bytecode" "1.3.0"
"@webassemblyjs/helper-wasm-section" "1.3.0"
"@webassemblyjs/wasm-gen" "1.3.0"
"@webassemblyjs/wasm-opt" "1.3.0"
"@webassemblyjs/wasm-parser" "1.3.0"
"@webassemblyjs/wast-printer" "1.3.0"
debug "^3.1.0"

"@webassemblyjs/wasm-gen@1.2.7":
version "1.2.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.2.7.tgz#c104608f22b079950e7822703159d43f2c18529f"
"@webassemblyjs/wasm-gen@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.3.0.tgz#acf45b38159f351178aa14135e5efa4172931e9a"
dependencies:
"@webassemblyjs/ast" "1.2.7"
"@webassemblyjs/helper-wasm-bytecode" "1.2.7"
"@webassemblyjs/leb128" "1.2.7"
"@webassemblyjs/ast" "1.3.0"
"@webassemblyjs/helper-wasm-bytecode" "1.3.0"
"@webassemblyjs/leb128" "1.3.0"

"@webassemblyjs/wasm-parser@1.2.7":
version "1.2.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.2.7.tgz#cbdf0b2882004e07be071719c99f30447b2a4294"
"@webassemblyjs/wasm-opt@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.3.0.tgz#958150b0d631eb407fc9b85b9a852526c849c015"
dependencies:
"@webassemblyjs/ast" "1.2.7"
"@webassemblyjs/helper-wasm-bytecode" "1.2.7"
"@webassemblyjs/leb128" "1.2.7"
"@webassemblyjs/wasm-parser" "1.2.7"
webassemblyjs "1.2.7"
"@webassemblyjs/ast" "1.3.0"
"@webassemblyjs/helper-buffer" "1.3.0"
"@webassemblyjs/wasm-gen" "1.3.0"
"@webassemblyjs/wasm-parser" "1.3.0"

"@webassemblyjs/[email protected]":
version "1.2.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.2.7.tgz#e1989a4dc5b0c30acc85b63c9efdc0844034b399"
"@webassemblyjs/[email protected]":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.3.0.tgz#66dd5ac632e0f938b1656bd46f01fe5f5f9488d0"
dependencies:
"@webassemblyjs/ast" "1.3.0"
"@webassemblyjs/helper-wasm-bytecode" "1.3.0"
"@webassemblyjs/leb128" "1.3.0"
"@webassemblyjs/wasm-parser" "1.3.0"
webassemblyjs "1.3.0"

"@webassemblyjs/[email protected]":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.3.0.tgz#bfc692d8a159d5fde7c1fee0f4e6d848d5bbcb71"
dependencies:
"@webassemblyjs/ast" "1.2.7"
"@webassemblyjs/floating-point-hex-parser" "1.2.7"
"@webassemblyjs/helper-code-frame" "1.2.7"
"@webassemblyjs/helper-fsm" "1.2.7"
"@webassemblyjs/ast" "1.3.0"
"@webassemblyjs/floating-point-hex-parser" "1.3.0"
"@webassemblyjs/helper-code-frame" "1.3.0"
"@webassemblyjs/helper-fsm" "1.3.0"
long "^3.2.0"
webassemblyjs "1.2.7"
webassemblyjs "1.3.0"

"@webassemblyjs/wast-printer@1.2.7":
version "1.2.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.2.7.tgz#22cc81b123a9c9f4f2166994c737c8f9cd47d1b8"
"@webassemblyjs/wast-printer@1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.3.0.tgz#b4ed84f0fea9f222d540e25b262cd5eabfee84d4"
dependencies:
"@webassemblyjs/ast" "1.2.7"
"@webassemblyjs/wast-parser" "1.2.7"
"@webassemblyjs/ast" "1.3.0"
"@webassemblyjs/wast-parser" "1.3.0"
long "^3.2.0"

abab@^1.0.4:
Expand Down Expand Up @@ -6143,14 +6154,14 @@ watchpack@^1.5.0:
graceful-fs "^4.1.2"
neo-async "^2.5.0"

webassemblyjs@1.2.7:
version "1.2.7"
resolved "https://registry.yarnpkg.com/webassemblyjs/-/webassemblyjs-1.2.7.tgz#cb151e1afa7659b42d1016c7700b42ec2c851ccb"
webassemblyjs@1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/webassemblyjs/-/webassemblyjs-1.3.0.tgz#970ca465d5ee45ebe611c5c6f7d461900c3e10b2"
dependencies:
"@webassemblyjs/ast" "1.2.7"
"@webassemblyjs/validation" "1.2.7"
"@webassemblyjs/wasm-parser" "1.2.7"
"@webassemblyjs/wast-parser" "1.2.7"
"@webassemblyjs/ast" "1.3.0"
"@webassemblyjs/validation" "1.3.0"
"@webassemblyjs/wasm-parser" "1.3.0"
"@webassemblyjs/wast-parser" "1.3.0"
long "^3.2.0"

webidl-conversions@^4.0.1, webidl-conversions@^4.0.2:
Expand Down

0 comments on commit 9cc4ebb

Please sign in to comment.