Skip to content
Permalink
Browse files
Merge pull request #7416 from xtuc/fix-rewritten-global-type
wasm: correct initializer type for rewritten globals
  • Loading branch information
sokra committed May 28, 2018
2 parents cc57b12 + fd4e84b commit 3ac1d02057de2a56455b693df618262796e06b7d
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 97 deletions.
@@ -64,6 +64,7 @@ declare module "@webassemblyjs/ast" {
export class ModuleExportDescr extends Node {}
export class IndexLiteral extends Node {}
export class NumberLiteral extends Node {}
export class FloatLiteral extends Node {}
export class Global extends Node {}
export class FuncParam extends Node {
valtype: string;
@@ -82,6 +83,7 @@ declare module "@webassemblyjs/ast" {
export class IndexInFuncSection extends Node {}
export function indexLiteral(index: number): IndexLiteral;
export function numberLiteralFromRaw(num: number): NumberLiteral;
export function floatLiteral(value: number, nan?: boolean, inf?: boolean, raw?: string): FloatLiteral;
export function global(globalType: string, nodes: Node[]): Global;
export function identifier(indentifier: string): Identifier;
export function funcParam(valType: string, id: Identifier): FuncParam;
@@ -187,11 +187,23 @@ const rewriteImportedGlobals = state => bin => {

globalType.mutability = "var";

newGlobals.push(
t.global(globalType, [
t.objectInstruction("const", "i32", [t.numberLiteralFromRaw(0)])
])
);
let init;

if (globalType.valtype[0] === "i") {
// create NumberLiteral global initializer
init = t.objectInstruction("const", globalType.valtype, [
t.numberLiteralFromRaw(0)
]);
} else if (globalType.valtype[0] === "f") {
// create FloatLiteral global initializer
init = t.objectInstruction("const", globalType.valtype, [
t.floatLiteral(0, false, false, "0")
]);
} else {
throw new Error("unknown type: " + globalType.valtype);
}

newGlobals.push(t.global(globalType, [init]));

path.remove();
}
@@ -5,10 +5,10 @@
"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.5.7",
"@webassemblyjs/wasm-edit": "1.5.7",
"@webassemblyjs/wasm-opt": "1.5.7",
"@webassemblyjs/wasm-parser": "1.5.7",
"@webassemblyjs/ast": "1.5.8",
"@webassemblyjs/wasm-edit": "1.5.8",
"@webassemblyjs/wasm-opt": "1.5.8",
"@webassemblyjs/wasm-parser": "1.5.8",
"acorn": "^5.0.0",
"acorn-dynamic-import": "^3.0.0",
"ajv": "^6.1.0",
@@ -0,0 +1 @@
export const number = 0xFFFFFFFFFF;
@@ -0,0 +1,5 @@
it("should preserve the valtype of the imported global", function() {
return import("./module.wat").then(function({get}) {
expect(get()).toBe(0xFFFFFFFFFF);
});
});
@@ -0,0 +1,7 @@
(module
(import "./env.js" "number" (global f64))

(func (export "get") (result f64)
(get_global 0)
)
)
@@ -0,0 +1,5 @@
var supportsWebAssembly = require("../../../helpers/supportsWebAssembly");

module.exports = function(config) {
return supportsWebAssembly();
};
183 yarn.lock
@@ -34,124 +34,131 @@
version "1.0.2"
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.2.tgz#e13182e1b69871a422d7863e11a4a6f5b814a4bd"

"@webassemblyjs/ast@1.5.7":
version "1.5.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.5.7.tgz#af544e995a4e9132791987c92d333378afcfb046"
"@webassemblyjs/ast@1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.5.8.tgz#f75ac7e7602b7833abd5d53951baae8a07ebb5df"
dependencies:
"@webassemblyjs/helper-module-context" "1.5.7"
"@webassemblyjs/helper-wasm-bytecode" "1.5.7"
"@webassemblyjs/wast-parser" "1.5.7"
"@webassemblyjs/helper-module-context" "1.5.8"
"@webassemblyjs/helper-wasm-bytecode" "1.5.8"
"@webassemblyjs/wast-parser" "1.5.8"
debug "^3.1.0"
mamacro "^0.0.3"

"@webassemblyjs/floating-point-hex-parser@1.5.7":
version "1.5.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.5.7.tgz#45d88100cdc5c068c961fd606d1deaa2bc55b061"
"@webassemblyjs/floating-point-hex-parser@1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.5.8.tgz#e0604d34fab0c910e16113720a5a3c01f558fa54"

"@webassemblyjs/helper-api-error@1.5.7":
version "1.5.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.5.7.tgz#b5030962e196767ee30645ecfc03866857855ed3"
"@webassemblyjs/helper-api-error@1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.5.8.tgz#f5570aff60090fae1b78a690a95d04cb021da9ca"

"@webassemblyjs/helper-buffer@1.5.7":
version "1.5.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.5.7.tgz#24e5a31e7786e1062d9b45e746f9aebe9d041323"
"@webassemblyjs/helper-buffer@1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.5.8.tgz#b1405e819a2c537964682fb70551796ab9602632"
dependencies:
debug "^3.1.0"

"@webassemblyjs/helper-code-frame@1.5.7":
version "1.5.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-code-frame/-/helper-code-frame-1.5.7.tgz#f98b941e32a254b7d85340f8425f31d250ae1aab"
"@webassemblyjs/helper-code-frame@1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-code-frame/-/helper-code-frame-1.5.8.tgz#6439de475720198a48fa8b4c38e41987798f73cc"
dependencies:
"@webassemblyjs/wast-printer" "1.5.7"
"@webassemblyjs/wast-printer" "1.5.8"

"@webassemblyjs/helper-fsm@1.5.7":
version "1.5.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-fsm/-/helper-fsm-1.5.7.tgz#92efc1e1cd307087087f843e5919fb71e0b49a9d"
"@webassemblyjs/helper-fsm@1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-fsm/-/helper-fsm-1.5.8.tgz#6169af3c9530cf9e89a8f3cf2970ed70e650ae4f"

"@webassemblyjs/helper-module-context@1.5.7":
version "1.5.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-module-context/-/helper-module-context-1.5.7.tgz#5525cdea9ffeea4e131872dfcc55f856e5cc8a64"
"@webassemblyjs/helper-module-context@1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-module-context/-/helper-module-context-1.5.8.tgz#73d0de45cebb774d465b5a66fef061f834d6c23c"

"@webassemblyjs/helper-wasm-bytecode@1.5.7":
version "1.5.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.5.7.tgz#319a3e8ec7248ff32df3f7b48335a31b7ac3f503"
"@webassemblyjs/helper-wasm-bytecode@1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.5.8.tgz#60df17f72d12b07e1398756e6ebfe59c03ab2e1a"

"@webassemblyjs/helper-wasm-section@1.5.7":
version "1.5.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.5.7.tgz#8ae8c004b99dc80afcf46a46135c53bc23ec6d71"
"@webassemblyjs/helper-wasm-section@1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.5.8.tgz#cda7fdb6f3b7b0d215c8f92b7435d47726822f49"
dependencies:
"@webassemblyjs/ast" "1.5.7"
"@webassemblyjs/helper-buffer" "1.5.7"
"@webassemblyjs/helper-wasm-bytecode" "1.5.7"
"@webassemblyjs/wasm-gen" "1.5.7"
"@webassemblyjs/ast" "1.5.8"
"@webassemblyjs/helper-buffer" "1.5.8"
"@webassemblyjs/helper-wasm-bytecode" "1.5.8"
"@webassemblyjs/wasm-gen" "1.5.8"
debug "^3.1.0"

"@webassemblyjs/leb128@1.5.7":
version "1.5.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.5.7.tgz#9dd206782e80a85f969377ce283f4a941b3e37ff"
"@webassemblyjs/ieee754@1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@webassemblyjs/ieee754/-/ieee754-1.5.8.tgz#29383c7172e90121613d5614d532f22c19255c3b"
dependencies:
ieee754 "^1.1.11"

"@webassemblyjs/leb128@1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@webassemblyjs/leb128/-/leb128-1.5.8.tgz#657c48ef2537ea2921e897a50157be700bf24eac"
dependencies:
leb "^0.3.0"

"@webassemblyjs/wasm-edit@1.5.7":
version "1.5.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.5.7.tgz#7d368a3a059028b8b6e756ef333730ddb140f0bc"
dependencies:
"@webassemblyjs/ast" "1.5.7"
"@webassemblyjs/helper-buffer" "1.5.7"
"@webassemblyjs/helper-wasm-bytecode" "1.5.7"
"@webassemblyjs/helper-wasm-section" "1.5.7"
"@webassemblyjs/wasm-gen" "1.5.7"
"@webassemblyjs/wasm-opt" "1.5.7"
"@webassemblyjs/wasm-parser" "1.5.7"
"@webassemblyjs/wast-printer" "1.5.7"
"@webassemblyjs/wasm-edit@1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-edit/-/wasm-edit-1.5.8.tgz#592d3678894eaa2ee7e7c2c6a13c2a697db1aa7e"
dependencies:
"@webassemblyjs/ast" "1.5.8"
"@webassemblyjs/helper-buffer" "1.5.8"
"@webassemblyjs/helper-wasm-bytecode" "1.5.8"
"@webassemblyjs/helper-wasm-section" "1.5.8"
"@webassemblyjs/wasm-gen" "1.5.8"
"@webassemblyjs/wasm-opt" "1.5.8"
"@webassemblyjs/wasm-parser" "1.5.8"
"@webassemblyjs/wast-printer" "1.5.8"
debug "^3.1.0"

"@webassemblyjs/wasm-gen@1.5.7":
version "1.5.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.5.7.tgz#00e36330ef9103bd343e37a90c23a6e2fd4e617d"
"@webassemblyjs/wasm-gen@1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-gen/-/wasm-gen-1.5.8.tgz#e94e034a45227aaa7c481b25c1aa9a0a00ab9488"
dependencies:
"@webassemblyjs/ast" "1.5.7"
"@webassemblyjs/helper-wasm-bytecode" "1.5.7"
"@webassemblyjs/leb128" "1.5.7"
"@webassemblyjs/ast" "1.5.8"
"@webassemblyjs/helper-wasm-bytecode" "1.5.8"
"@webassemblyjs/ieee754" "1.5.8"
"@webassemblyjs/leb128" "1.5.8"

"@webassemblyjs/wasm-opt@1.5.7":
version "1.5.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.5.7.tgz#c0b8ff4241549aca63f72284cc945c8556d5702e"
"@webassemblyjs/wasm-opt@1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-opt/-/wasm-opt-1.5.8.tgz#a3a0d00d98dee0f3cf2ae41084eb62715a39242c"
dependencies:
"@webassemblyjs/ast" "1.5.7"
"@webassemblyjs/helper-buffer" "1.5.7"
"@webassemblyjs/wasm-gen" "1.5.7"
"@webassemblyjs/wasm-parser" "1.5.7"
"@webassemblyjs/ast" "1.5.8"
"@webassemblyjs/helper-buffer" "1.5.8"
"@webassemblyjs/wasm-gen" "1.5.8"
"@webassemblyjs/wasm-parser" "1.5.8"
debug "^3.1.0"

"@webassemblyjs/wasm-parser@1.5.7":
version "1.5.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.5.7.tgz#2d3513e3437596ac19584f09abab5a5d482a0fb6"
dependencies:
"@webassemblyjs/ast" "1.5.7"
"@webassemblyjs/helper-api-error" "1.5.7"
"@webassemblyjs/helper-wasm-bytecode" "1.5.7"
"@webassemblyjs/leb128" "1.5.7"
"@webassemblyjs/wasm-parser" "1.5.7"

"@webassemblyjs/wast-parser@1.5.7":
version "1.5.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.5.7.tgz#56692821e2190a4dcddd3fa460cdfda0ab120f74"
dependencies:
"@webassemblyjs/ast" "1.5.7"
"@webassemblyjs/floating-point-hex-parser" "1.5.7"
"@webassemblyjs/helper-api-error" "1.5.7"
"@webassemblyjs/helper-code-frame" "1.5.7"
"@webassemblyjs/helper-fsm" "1.5.7"
"@webassemblyjs/wasm-parser@1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wasm-parser/-/wasm-parser-1.5.8.tgz#a258a7fd15bd57597e4211d9068639807546555b"
dependencies:
"@webassemblyjs/ast" "1.5.8"
"@webassemblyjs/helper-api-error" "1.5.8"
"@webassemblyjs/helper-wasm-bytecode" "1.5.8"
"@webassemblyjs/leb128" "1.5.8"
"@webassemblyjs/wasm-parser" "1.5.8"

"@webassemblyjs/wast-parser@1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.5.8.tgz#85705659e15d19b89af38a8d6803d720bb0493cf"
dependencies:
"@webassemblyjs/ast" "1.5.8"
"@webassemblyjs/floating-point-hex-parser" "1.5.8"
"@webassemblyjs/helper-api-error" "1.5.8"
"@webassemblyjs/helper-code-frame" "1.5.8"
"@webassemblyjs/helper-fsm" "1.5.8"
long "^3.2.0"
mamacro "^0.0.3"

"@webassemblyjs/wast-printer@1.5.7":
version "1.5.7"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.5.7.tgz#89d74f7fbe0ff5560e87a50afd28183074b6327b"
"@webassemblyjs/wast-printer@1.5.8":
version "1.5.8"
resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-printer/-/wast-printer-1.5.8.tgz#0f83aa67eddf377dd1d6205d4a4ac976db60e1f6"
dependencies:
"@webassemblyjs/ast" "1.5.7"
"@webassemblyjs/wast-parser" "1.5.7"
"@webassemblyjs/ast" "1.5.8"
"@webassemblyjs/wast-parser" "1.5.8"
long "^3.2.0"

abab@^1.0.4:
@@ -2598,7 +2605,7 @@ icss-utils@^2.1.0:
dependencies:
postcss "^6.0.1"

ieee754@^1.1.4:
ieee754@^1.1.11, ieee754@^1.1.4:
version "1.1.11"
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.11.tgz#c16384ffe00f5b7835824e67b6f2bd44a5229455"

0 comments on commit 3ac1d02

Please sign in to comment.