From a77d6703313f8e76f0bffbb69f804a3a7866922e Mon Sep 17 00:00:00 2001 From: Mauro Bringolf Date: Tue, 29 May 2018 09:35:11 +0200 Subject: [PATCH 01/13] Setup for AST transpilation --- packages/helper-wasm-bytecode/src/index.js | 7 ++++ .../proposal-sign-extension-ops/README.md | 27 +++++++++++++++ .../proposal-sign-extension-ops/package.json | 33 +++++++++++++++++++ .../proposal-sign-extension-ops/src/index.js | 13 ++++++++ .../proposal-sign-extension-ops/test/index.js | 19 +++++++++++ .../test/wast/empty/input.wast | 4 +++ .../test/wast/empty/output.wast | 4 +++ 7 files changed, 107 insertions(+) create mode 100644 packages/proposal-sign-extension-ops/README.md create mode 100644 packages/proposal-sign-extension-ops/package.json create mode 100644 packages/proposal-sign-extension-ops/src/index.js create mode 100644 packages/proposal-sign-extension-ops/test/index.js create mode 100644 packages/proposal-sign-extension-ops/test/wast/empty/input.wast create mode 100644 packages/proposal-sign-extension-ops/test/wast/empty/output.wast diff --git a/packages/helper-wasm-bytecode/src/index.js b/packages/helper-wasm-bytecode/src/index.js index c7f854cc3..1c17719b0 100644 --- a/packages/helper-wasm-bytecode/src/index.js +++ b/packages/helper-wasm-bytecode/src/index.js @@ -319,6 +319,13 @@ const symbolsByByte = { 0xba: createSymbolObject("convert_u/i64", "f64"), 0xbb: createSymbolObject("promote/f32", "f64"), + // Sign extension op proposal + 0xc0: createSymbolObject("extend8_s", "i32"), + 0xc1: createSymbolObject("extend16_s", "i32"), + 0xc2: createSymbolObject("extend8_s", "i64"), + 0xc3: createSymbolObject("extend16_s", "i64"), + 0xc4: createSymbolObject("extend32_s", "i64"), + 0xbc: createSymbolObject("reinterpret/f32", "i32"), 0xbd: createSymbolObject("reinterpret/f64", "i64"), 0xbe: createSymbolObject("reinterpret/i32", "f32"), diff --git a/packages/proposal-sign-extension-ops/README.md b/packages/proposal-sign-extension-ops/README.md new file mode 100644 index 000000000..4502a8f68 --- /dev/null +++ b/packages/proposal-sign-extension-ops/README.md @@ -0,0 +1,27 @@ +# Sign extension proposal + + + +```c +#include "stdint.h" + +int32_t i32_extend8_s(int32_t x) { + return (x & 0x00000080) ? (x | 0xffffff80) : (x & 0x0000007f); +} + +int32_t i32_extend16_s(int32_t x) { + return (x & 0x00008000) ? (x | 0xffff8000) : (x & 0x00007fff); +} + +int64_t i64_extend8_s(int64_t x) { + return (x & 0x0000000000000080) ? (x | 0xffffffffffffff80) : (x & 0x000000000000007f); +} + +int64_t i64_extend16_s(int64_t x) { + return (x & 0x0000000000008000) ? (x | 0xffffffffffff8000) : (x & 0x0000000000007fff); +} + +int64_t i64_extend32_s(int64_t x) { + return (x & 0x0000000080000000) ? (x | 0xffffffff80000000) : (x & 0x000000007fffffff); +} +``` diff --git a/packages/proposal-sign-extension-ops/package.json b/packages/proposal-sign-extension-ops/package.json new file mode 100644 index 000000000..814e6a19e --- /dev/null +++ b/packages/proposal-sign-extension-ops/package.json @@ -0,0 +1,33 @@ +{ + "name": "@webassemblyjs/proposal-sign-ops", + "version": "1.5.6", + "description": "", + "main": "lib/index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://github.com/xtuc/webassemblyjs.git" + }, + "publishConfig": { + "access": "public" + }, + "author": "Mauro Bringolf", + "license": "MIT", + "dependencies": { + "@webassemblyjs/helper-buffer": "1.5.6", + "@webassemblyjs/helper-wasm-bytecode": "1.5.6", + "@webassemblyjs/helper-wasm-section": "1.5.6", + "@webassemblyjs/wasm-gen": "1.5.6", + "@webassemblyjs/wasm-edit": "1.5.6", + "@webassemblyjs/ast": "1.5.6", + "@webassemblyjs/wasm-opt": "1.5.6", + "debug": "^3.1.0" + }, + "devDependencies": { + "@webassemblyjs/helper-test-framework": "1.5.6", + "@webassemblyjs/wast-parser": "1.5.6", + "@webassemblyjs/wast-printer": "1.5.6" + } +} diff --git a/packages/proposal-sign-extension-ops/src/index.js b/packages/proposal-sign-extension-ops/src/index.js new file mode 100644 index 000000000..2cfba1b41 --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/index.js @@ -0,0 +1,13 @@ +import { edit } from '@webassemblyjs/wasm-edit'; +import { traverse } from '@webassemblyjs/ast'; + +export function transformAst(ast) { + traverse(ast, signExtendVisitor); + return ast +} + +const signExtendVisitor = { + Instr(path) { + console.log(path.node); + } +} diff --git a/packages/proposal-sign-extension-ops/test/index.js b/packages/proposal-sign-extension-ops/test/index.js new file mode 100644 index 000000000..0c6a7c383 --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/index.js @@ -0,0 +1,19 @@ +const { parse } = require('@webassemblyjs/wast-parser') +const { print } = require('@webassemblyjs/wast-printer') +const path = require('path') + +const { getFixtures, compareStrings } = require('@webassemblyjs/helper-test-framework') +const { readFileSync } = require('fs') + +const { transformAst } = require('../lib/') + +const testCases = getFixtures(path.join(__dirname, './wast/'), '/**/input.wast') + +testCases.forEach(testCase => { + const input = readFileSync(testCase, "utf8").trim(); + const expectedOutput = readFileSync(path.join(path.dirname(testCase), 'output.wast' ), "utf8").trim(); + + const actualOutput = print(transformAst(parse(input))) + + compareStrings(actualOutput, expectedOutput); +}) diff --git a/packages/proposal-sign-extension-ops/test/wast/empty/input.wast b/packages/proposal-sign-extension-ops/test/wast/empty/input.wast new file mode 100644 index 000000000..4d181e6e6 --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/empty/input.wast @@ -0,0 +1,4 @@ +(module + (func) +) + diff --git a/packages/proposal-sign-extension-ops/test/wast/empty/output.wast b/packages/proposal-sign-extension-ops/test/wast/empty/output.wast new file mode 100644 index 000000000..4d181e6e6 --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/empty/output.wast @@ -0,0 +1,4 @@ +(module + (func) +) + From fb5bd7b430790daae472f9d3db6be32a7315aabd Mon Sep 17 00:00:00 2001 From: Mauro Bringolf Date: Tue, 29 May 2018 22:00:07 +0200 Subject: [PATCH 02/13] Sketchy first example working --- .gitignore | 3 ++ .../proposal-sign-extension-ops/package.json | 8 ++-- .../proposal-sign-extension-ops/src/index.js | 38 ++++++++++++---- .../src/polyfills.js | 45 +++++++++++++++++++ .../src/polyfills/i32_extend8_s.c | 7 +++ .../proposal-sign-extension-ops/test/index.js | 38 ++++++++++------ .../test/wast/single-instruction/input.wast | 6 +++ .../test/wast/single-instruction/output.wast | 20 +++++++++ scripts/build.sh | 2 + scripts/generate-polyfills.js | 3 ++ 10 files changed, 146 insertions(+), 24 deletions(-) create mode 100644 packages/proposal-sign-extension-ops/src/polyfills.js create mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.c create mode 100644 packages/proposal-sign-extension-ops/test/wast/single-instruction/input.wast create mode 100644 packages/proposal-sign-extension-ops/test/wast/single-instruction/output.wast create mode 100755 scripts/generate-polyfills.js diff --git a/.gitignore b/.gitignore index aac1b9026..06b4db74f 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,6 @@ typings/ lib/ package-lock.json + +# Generated polyfill binaries +packages/proposal-sign-extension-ops/src/polyfills/*.wasm diff --git a/packages/proposal-sign-extension-ops/package.json b/packages/proposal-sign-extension-ops/package.json index 814e6a19e..e80cb332b 100644 --- a/packages/proposal-sign-extension-ops/package.json +++ b/packages/proposal-sign-extension-ops/package.json @@ -16,18 +16,20 @@ "author": "Mauro Bringolf", "license": "MIT", "dependencies": { + "@webassemblyjs/ast": "1.5.6", "@webassemblyjs/helper-buffer": "1.5.6", "@webassemblyjs/helper-wasm-bytecode": "1.5.6", "@webassemblyjs/helper-wasm-section": "1.5.6", - "@webassemblyjs/wasm-gen": "1.5.6", "@webassemblyjs/wasm-edit": "1.5.6", - "@webassemblyjs/ast": "1.5.6", + "@webassemblyjs/wasm-gen": "1.5.6", "@webassemblyjs/wasm-opt": "1.5.6", - "debug": "^3.1.0" + "debug": "^3.1.0", + "webassembly": "^0.11.0" }, "devDependencies": { "@webassemblyjs/helper-test-framework": "1.5.6", "@webassemblyjs/wast-parser": "1.5.6", + "@webassemblyjs/wasm-parser": "1.5.6", "@webassemblyjs/wast-printer": "1.5.6" } } diff --git a/packages/proposal-sign-extension-ops/src/index.js b/packages/proposal-sign-extension-ops/src/index.js index 2cfba1b41..55884e3f7 100644 --- a/packages/proposal-sign-extension-ops/src/index.js +++ b/packages/proposal-sign-extension-ops/src/index.js @@ -1,13 +1,35 @@ -import { edit } from '@webassemblyjs/wasm-edit'; -import { traverse } from '@webassemblyjs/ast'; +import { edit } from "@webassemblyjs/wasm-edit"; +import { traverse, callInstruction, numberLiteral } from "@webassemblyjs/ast"; +import i32_extend8_s from "./polyfills/i32_extend8_s.json"; export function transformAst(ast) { - traverse(ast, signExtendVisitor); - return ast -} + let polyfillIndex = 0; + let needsPolyfill = false; + + const countFuncVisitor = { + Func(path) { + ++polyfillIndex; + } + }; + + const signExtendVisitor = polyfillIndex => ({ + Instr(path) { + if (path.node.id === "i32_extend8_s") { + needsPolyfill = true; + path.replaceWith( + callInstruction(numberLiteral(polyfillIndex, String(polyfillIndex))) + ); + } + } + }); -const signExtendVisitor = { - Instr(path) { - console.log(path.node); + traverse(ast, countFuncVisitor); + + traverse(ast, signExtendVisitor(polyfillIndex)); + + if (needsPolyfill) { + ast.body[0].fields.push(i32_extend8_s); } + + return ast; } diff --git a/packages/proposal-sign-extension-ops/src/polyfills.js b/packages/proposal-sign-extension-ops/src/polyfills.js new file mode 100644 index 000000000..d53346356 --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills.js @@ -0,0 +1,45 @@ +import compiler from "webassembly/cli/compiler"; +import { decode } from "@webassemblyjs/wasm-parser"; + +import { readFileSync, writeFileSync } from "fs"; + +import path from "path"; +import mkdirp from "mkdirp"; + +export function generateAsts() { + compiler.main( + [ + "-o", + "./packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.wasm", + "--optimize", + path.resolve( + "./packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.c" + ) + ], + function(err, filename) { + if (err) { + throw err; + } + console.log("saved to: " + filename); + + const wasmFile = readFileSync(filename); + + const ast = decode(wasmFile); + + const i32_extend8_s = ast.body[0].fields.filter( + f => f.type === "Func" + )[0]; + + mkdirp( + path.resolve("./packages/proposal-sign-extension-ops/lib/polyfills") + ); + + writeFileSync( + path.resolve( + "./packages/proposal-sign-extension-ops/lib/polyfills/i32_extend8_s.json" + ), + JSON.stringify(i32_extend8_s, null, 2) + ); + } + ); +} diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.c b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.c new file mode 100644 index 000000000..cbac91c16 --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.c @@ -0,0 +1,7 @@ +#include +#include "stdint.h" + +export int32_t i32_extend8_s(int32_t x) { + return (x & 0x00000080) ? (x | 0xffffff80) : (x & 0x0000007f); +} + diff --git a/packages/proposal-sign-extension-ops/test/index.js b/packages/proposal-sign-extension-ops/test/index.js index 0c6a7c383..079d6991a 100644 --- a/packages/proposal-sign-extension-ops/test/index.js +++ b/packages/proposal-sign-extension-ops/test/index.js @@ -1,19 +1,31 @@ -const { parse } = require('@webassemblyjs/wast-parser') -const { print } = require('@webassemblyjs/wast-printer') -const path = require('path') +const { parse } = require("@webassemblyjs/wast-parser"); +const { print } = require("@webassemblyjs/wast-printer"); +const path = require("path"); -const { getFixtures, compareStrings } = require('@webassemblyjs/helper-test-framework') -const { readFileSync } = require('fs') +const { + getFixtures, + compareStrings +} = require("@webassemblyjs/helper-test-framework"); +const { readFileSync } = require("fs"); -const { transformAst } = require('../lib/') +const { transformAst } = require("../lib/"); -const testCases = getFixtures(path.join(__dirname, './wast/'), '/**/input.wast') +const testCases = getFixtures( + path.join(__dirname, "./wast/"), + "/**/input.wast" +); testCases.forEach(testCase => { - const input = readFileSync(testCase, "utf8").trim(); - const expectedOutput = readFileSync(path.join(path.dirname(testCase), 'output.wast' ), "utf8").trim(); + describe(testCase, () => { + const input = readFileSync(testCase, "utf8").trim(); + const expectedOutput = readFileSync( + path.join(path.dirname(testCase), "output.wast"), + "utf8" + ).trim(); - const actualOutput = print(transformAst(parse(input))) - - compareStrings(actualOutput, expectedOutput); -}) + it("should transpile sign extension operators into functions correctly", () => { + const actualOutput = print(transformAst(parse(input))); + compareStrings(actualOutput, expectedOutput); + }); + }); +}); diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction/input.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction/input.wast new file mode 100644 index 000000000..c1affbf67 --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction/input.wast @@ -0,0 +1,6 @@ +(module + (func (param i32) (result i32) + (i32_extend8_s) + ) +) + diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction/output.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction/output.wast new file mode 100644 index 000000000..4662c14a2 --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction/output.wast @@ -0,0 +1,20 @@ +(module + (func (param i32) (result i32) + (call 1) + ) + (func (param i32) (result i32) + (get_local 0) + (i32.const -128) + (i32.or) + (get_local 0) + (i32.const 127) + (i32.and) + (get_local 0) + (i32.const 128) + (i32.and) + (i32.const 7) + (i32.shr_u) + (select) + ) +) + diff --git a/scripts/build.sh b/scripts/build.sh index 651fec628..c94fce4f1 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -31,4 +31,6 @@ done wait +./scripts/generate-polyfills.js + cp -v packages/dce/src/libwabt.js packages/dce/lib/libwabt.js diff --git a/scripts/generate-polyfills.js b/scripts/generate-polyfills.js new file mode 100755 index 000000000..c9afbd1d5 --- /dev/null +++ b/scripts/generate-polyfills.js @@ -0,0 +1,3 @@ +#!/usr/bin/env node + +require("../packages/proposal-sign-extension-ops/lib/polyfills.js").generateAsts(); From 8143ee6ef72c29a5c1e1fbd1a43b4431f5f6e847 Mon Sep 17 00:00:00 2001 From: Mauro Bringolf Date: Wed, 30 May 2018 11:40:29 +0200 Subject: [PATCH 03/13] Make testcase actually executable --- .../test/wast/single-instruction/input.wast | 1 + .../test/wast/single-instruction/output.wast | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction/input.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction/input.wast index c1affbf67..ec3a4b4cd 100644 --- a/packages/proposal-sign-extension-ops/test/wast/single-instruction/input.wast +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction/input.wast @@ -1,5 +1,6 @@ (module (func (param i32) (result i32) + (get_local 0) (i32_extend8_s) ) ) diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction/output.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction/output.wast index 4662c14a2..d2ac65d2c 100644 --- a/packages/proposal-sign-extension-ops/test/wast/single-instruction/output.wast +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction/output.wast @@ -1,5 +1,6 @@ (module (func (param i32) (result i32) + (get_local 0) (call 1) ) (func (param i32) (result i32) From 1872d949c3817afb188cfb59b66440307bab41a2 Mon Sep 17 00:00:00 2001 From: Mauro Bringolf Date: Wed, 30 May 2018 11:42:47 +0200 Subject: [PATCH 04/13] Multiple calls to same instruction test case --- .../test/wast/multiple-instruction/input.wast | 15 ++++++++++ .../wast/multiple-instruction/output.wast | 29 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 packages/proposal-sign-extension-ops/test/wast/multiple-instruction/input.wast create mode 100644 packages/proposal-sign-extension-ops/test/wast/multiple-instruction/output.wast diff --git a/packages/proposal-sign-extension-ops/test/wast/multiple-instruction/input.wast b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction/input.wast new file mode 100644 index 000000000..d05cd70dd --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction/input.wast @@ -0,0 +1,15 @@ +(module + (func (param i32) (result i32) + (get_local 0) + (i32_extend8_s) + ) + (func (param i32) (result i32) + (get_local 0) + (i32_extend8_s) + ) + (func (param i32) (result i32) + (get_local 0) + (i32_extend8_s) + ) +) + diff --git a/packages/proposal-sign-extension-ops/test/wast/multiple-instruction/output.wast b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction/output.wast new file mode 100644 index 000000000..1283e9c97 --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction/output.wast @@ -0,0 +1,29 @@ +(module + (func (param i32) (result i32) + (get_local 0) + (call 3) + ) + (func (param i32) (result i32) + (get_local 0) + (call 3) + ) + (func (param i32) (result i32) + (get_local 0) + (call 3) + ) + (func (param i32) (result i32) + (get_local 0) + (i32.const -128) + (i32.or) + (get_local 0) + (i32.const 127) + (i32.and) + (get_local 0) + (i32.const 128) + (i32.and) + (i32.const 7) + (i32.shr_u) + (select) + ) +) + From 4930ae875d289379d7e538836f2237b1b628d057 Mon Sep 17 00:00:00 2001 From: Mauro Bringolf Date: Wed, 30 May 2018 12:56:06 +0200 Subject: [PATCH 05/13] Setup polyfill state for multiple instructions --- .../proposal-sign-extension-ops/src/index.js | 75 +++++++++++++++---- 1 file changed, 59 insertions(+), 16 deletions(-) diff --git a/packages/proposal-sign-extension-ops/src/index.js b/packages/proposal-sign-extension-ops/src/index.js index 55884e3f7..d394bfa07 100644 --- a/packages/proposal-sign-extension-ops/src/index.js +++ b/packages/proposal-sign-extension-ops/src/index.js @@ -2,34 +2,77 @@ import { edit } from "@webassemblyjs/wasm-edit"; import { traverse, callInstruction, numberLiteral } from "@webassemblyjs/ast"; import i32_extend8_s from "./polyfills/i32_extend8_s.json"; +class Polyfills { + constructor(startIndex) { + this.startIndex = startIndex; + + this.asts = { + i32_extend8_s + }; + + this.instructions = Object.keys(this.asts); + + this.index = {}; + + this.instructions.forEach(instrName => { + this.index[instrName] = -1; + }); + } + + replaceWith(path, instrName) { + if (this.index[instrName] === -1) { + this.index[instrName] = this.startIndex++; + } + + const index = this.index[instrName]; + path.replaceWith(callInstruction(numberLiteral(index, String(index)))); + } + + matchesInstruction(instrName) { + return this.instructions.includes(instrName); + } + + insertInto(ast) { + const funcsToPush = Object.keys(this.index) + .filter(instrName => this.index[instrName] >= 0) + .sort((x, y) => (this.index[x] > this.index[y] ? 1 : -1)) + .map(instrName => this.asts[instrName]); + + ast.body[0].fields.push(...funcsToPush); + } +} + export function transformAst(ast) { - let polyfillIndex = 0; - let needsPolyfill = false; + const polyfillState = {}; + + const needsPolyfill = instr => polyfillState[instr] > 0; + const requirePolyfill = instr => { + polyfillState[instr]; + }; + + let numberOfFuncs = 0; const countFuncVisitor = { Func(path) { - ++polyfillIndex; + ++numberOfFuncs; } }; - const signExtendVisitor = polyfillIndex => ({ + traverse(ast, countFuncVisitor); + + const polyfills = new Polyfills(numberOfFuncs); + + const signExtendVisitor = { Instr(path) { - if (path.node.id === "i32_extend8_s") { - needsPolyfill = true; - path.replaceWith( - callInstruction(numberLiteral(polyfillIndex, String(polyfillIndex))) - ); + if (polyfills.matchesInstruction(path.node.id)) { + polyfills.replaceWith(path, path.node.id); } } - }); - - traverse(ast, countFuncVisitor); + }; - traverse(ast, signExtendVisitor(polyfillIndex)); + traverse(ast, signExtendVisitor); - if (needsPolyfill) { - ast.body[0].fields.push(i32_extend8_s); - } + polyfills.insertInto(ast); return ast; } From a23af0f5f4eca15dff9564a1919c7560248da0cf Mon Sep 17 00:00:00 2001 From: Mauro Bringolf Date: Wed, 30 May 2018 13:12:33 +0200 Subject: [PATCH 06/13] Implement polyfill for i32_extend16_s --- .../proposal-sign-extension-ops/src/index.js | 4 +- .../src/polyfills.js | 70 ++++++++++--------- .../src/polyfills/i32_extend16_s.c | 7 ++ .../test/wast/mixed/input.wast | 15 ++++ .../test/wast/mixed/output.wast | 43 ++++++++++++ .../input.wast | 14 ++++ .../output.wast | 28 ++++++++ .../input.wast | 0 .../output.wast | 0 .../input.wast | 7 ++ .../output.wast | 21 ++++++ .../input.wast | 0 .../output.wast | 0 13 files changed, 174 insertions(+), 35 deletions(-) create mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.c create mode 100644 packages/proposal-sign-extension-ops/test/wast/mixed/input.wast create mode 100644 packages/proposal-sign-extension-ops/test/wast/mixed/output.wast create mode 100644 packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend16_s/input.wast create mode 100644 packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend16_s/output.wast rename packages/proposal-sign-extension-ops/test/wast/{multiple-instruction => multiple-instruction-i32_extend8_s}/input.wast (100%) rename packages/proposal-sign-extension-ops/test/wast/{multiple-instruction => multiple-instruction-i32_extend8_s}/output.wast (100%) create mode 100644 packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend16_s/input.wast create mode 100644 packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend16_s/output.wast rename packages/proposal-sign-extension-ops/test/wast/{single-instruction => single-instruction-i32_extend8_s}/input.wast (100%) rename packages/proposal-sign-extension-ops/test/wast/{single-instruction => single-instruction-i32_extend8_s}/output.wast (100%) diff --git a/packages/proposal-sign-extension-ops/src/index.js b/packages/proposal-sign-extension-ops/src/index.js index d394bfa07..f0455e71e 100644 --- a/packages/proposal-sign-extension-ops/src/index.js +++ b/packages/proposal-sign-extension-ops/src/index.js @@ -1,13 +1,15 @@ import { edit } from "@webassemblyjs/wasm-edit"; import { traverse, callInstruction, numberLiteral } from "@webassemblyjs/ast"; import i32_extend8_s from "./polyfills/i32_extend8_s.json"; +import i32_extend16_s from "./polyfills/i32_extend16_s.json"; class Polyfills { constructor(startIndex) { this.startIndex = startIndex; this.asts = { - i32_extend8_s + i32_extend8_s, + i32_extend16_s }; this.instructions = Object.keys(this.asts); diff --git a/packages/proposal-sign-extension-ops/src/polyfills.js b/packages/proposal-sign-extension-ops/src/polyfills.js index d53346356..241481c9b 100644 --- a/packages/proposal-sign-extension-ops/src/polyfills.js +++ b/packages/proposal-sign-extension-ops/src/polyfills.js @@ -6,40 +6,42 @@ import { readFileSync, writeFileSync } from "fs"; import path from "path"; import mkdirp from "mkdirp"; -export function generateAsts() { - compiler.main( - [ - "-o", - "./packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.wasm", - "--optimize", - path.resolve( - "./packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.c" - ) - ], - function(err, filename) { - if (err) { - throw err; - } - console.log("saved to: " + filename); - - const wasmFile = readFileSync(filename); - - const ast = decode(wasmFile); +const instructions = ["i32_extend8_s", "i32_extend16_s"]; - const i32_extend8_s = ast.body[0].fields.filter( - f => f.type === "Func" - )[0]; - - mkdirp( - path.resolve("./packages/proposal-sign-extension-ops/lib/polyfills") - ); - - writeFileSync( +export function generateAsts() { + instructions.forEach(instr => { + compiler.main( + [ + "-o", + `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.wasm`, + "--optimize", path.resolve( - "./packages/proposal-sign-extension-ops/lib/polyfills/i32_extend8_s.json" - ), - JSON.stringify(i32_extend8_s, null, 2) - ); - } - ); + `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.c` + ) + ], + function(err, filename) { + if (err) { + throw err; + } + console.log("saved to: " + filename); + + const wasmFile = readFileSync(filename); + + const ast = decode(wasmFile); + + const funcAst = ast.body[0].fields.filter(f => f.type === "Func")[0]; + + mkdirp( + path.resolve("./packages/proposal-sign-extension-ops/lib/polyfills") + ); + + writeFileSync( + path.resolve( + `./packages/proposal-sign-extension-ops/lib/polyfills/${instr}.json` + ), + JSON.stringify(funcAst, null, 2) + ); + } + ); + }); } diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.c b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.c new file mode 100644 index 000000000..8ee566315 --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.c @@ -0,0 +1,7 @@ +#include +#include "stdint.h" + +export int32_t i32_extend16_s(int32_t x) { + return (x & 0x00008000) ? (x | 0xffff8000) : (x & 0x00007fff); +} + diff --git a/packages/proposal-sign-extension-ops/test/wast/mixed/input.wast b/packages/proposal-sign-extension-ops/test/wast/mixed/input.wast new file mode 100644 index 000000000..91c7ff015 --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/mixed/input.wast @@ -0,0 +1,15 @@ +(module + (func (param i32) (result i32) + (get_local 0) + (i32_extend16_s) + (i32_extend8_s) + ) + (func (param i32) (result i32) + (get_local 0) + ) + (func (param i32) (result i32) + (get_local 0) + (i32_extend8_s) + ) +) + diff --git a/packages/proposal-sign-extension-ops/test/wast/mixed/output.wast b/packages/proposal-sign-extension-ops/test/wast/mixed/output.wast new file mode 100644 index 000000000..47ea56305 --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/mixed/output.wast @@ -0,0 +1,43 @@ +(module + (func (param i32) (result i32) + (get_local 0) + (call 3) + (call 4) + ) + (func (param i32) (result i32) + (get_local 0) + ) + (func (param i32) (result i32) + (get_local 0) + (call 4) + ) + (func (param i32) (result i32) + (get_local 0) + (i32.const -32768) + (i32.or) + (get_local 0) + (i32.const 32767) + (i32.and) + (get_local 0) + (i32.const 32768) + (i32.and) + (i32.const 15) + (i32.shr_u) + (select) + ) + (func (param i32) (result i32) + (get_local 0) + (i32.const -128) + (i32.or) + (get_local 0) + (i32.const 127) + (i32.and) + (get_local 0) + (i32.const 128) + (i32.and) + (i32.const 7) + (i32.shr_u) + (select) + ) +) + diff --git a/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend16_s/input.wast b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend16_s/input.wast new file mode 100644 index 000000000..ac66606a2 --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend16_s/input.wast @@ -0,0 +1,14 @@ +(module + (func (param i32) (result i32) + (get_local 0) + (i32_extend16_s) + ) + (func (param i32) (result i32) + (get_local 0) + ) + (func (param i32) (result i32) + (get_local 0) + (i32_extend16_s) + ) +) + diff --git a/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend16_s/output.wast b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend16_s/output.wast new file mode 100644 index 000000000..e13c95f16 --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend16_s/output.wast @@ -0,0 +1,28 @@ +(module + (func (param i32) (result i32) + (get_local 0) + (call 3) + ) + (func (param i32) (result i32) + (get_local 0) + ) + (func (param i32) (result i32) + (get_local 0) + (call 3) + ) + (func (param i32) (result i32) + (get_local 0) + (i32.const -32768) + (i32.or) + (get_local 0) + (i32.const 32767) + (i32.and) + (get_local 0) + (i32.const 32768) + (i32.and) + (i32.const 15) + (i32.shr_u) + (select) + ) +) + diff --git a/packages/proposal-sign-extension-ops/test/wast/multiple-instruction/input.wast b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend8_s/input.wast similarity index 100% rename from packages/proposal-sign-extension-ops/test/wast/multiple-instruction/input.wast rename to packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend8_s/input.wast diff --git a/packages/proposal-sign-extension-ops/test/wast/multiple-instruction/output.wast b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend8_s/output.wast similarity index 100% rename from packages/proposal-sign-extension-ops/test/wast/multiple-instruction/output.wast rename to packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend8_s/output.wast diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend16_s/input.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend16_s/input.wast new file mode 100644 index 000000000..ddbb8821c --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend16_s/input.wast @@ -0,0 +1,7 @@ +(module + (func (param i32) (result i32) + (get_local 0) + (i32_extend16_s) + ) +) + diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend16_s/output.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend16_s/output.wast new file mode 100644 index 000000000..2d3a2d391 --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend16_s/output.wast @@ -0,0 +1,21 @@ +(module + (func (param i32) (result i32) + (get_local 0) + (call 1) + ) + (func (param i32) (result i32) + (get_local 0) + (i32.const -32768) + (i32.or) + (get_local 0) + (i32.const 32767) + (i32.and) + (get_local 0) + (i32.const 32768) + (i32.and) + (i32.const 15) + (i32.shr_u) + (select) + ) +) + diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction/input.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend8_s/input.wast similarity index 100% rename from packages/proposal-sign-extension-ops/test/wast/single-instruction/input.wast rename to packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend8_s/input.wast diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction/output.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend8_s/output.wast similarity index 100% rename from packages/proposal-sign-extension-ops/test/wast/single-instruction/output.wast rename to packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend8_s/output.wast From 4a27ad5375bc35b2cce148718727dbf2039d8438 Mon Sep 17 00:00:00 2001 From: Mauro Bringolf Date: Thu, 31 May 2018 09:02:31 +0200 Subject: [PATCH 07/13] Migrate polyfill source to assemblyScript --- .../proposal-sign-extension-ops/package.json | 6 ++-- .../proposal-sign-extension-ops/src/index.js | 10 +------ .../src/polyfills.js | 30 +++++++++---------- .../src/polyfills/i32_extend16_s.c | 7 ----- .../src/polyfills/i32_extend16_s.ts | 6 ++++ .../src/polyfills/i32_extend8_s.c | 7 ----- .../src/polyfills/i32_extend8_s.ts | 6 ++++ .../test/wast/mixed/output.wast | 8 ++--- .../output.wast | 4 +-- .../output.wast | 4 +-- .../output.wast | 4 +-- .../output.wast | 4 +-- 12 files changed, 37 insertions(+), 59 deletions(-) delete mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.c create mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.ts delete mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.c create mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.ts diff --git a/packages/proposal-sign-extension-ops/package.json b/packages/proposal-sign-extension-ops/package.json index e80cb332b..2cdd02e17 100644 --- a/packages/proposal-sign-extension-ops/package.json +++ b/packages/proposal-sign-extension-ops/package.json @@ -23,13 +23,13 @@ "@webassemblyjs/wasm-edit": "1.5.6", "@webassemblyjs/wasm-gen": "1.5.6", "@webassemblyjs/wasm-opt": "1.5.6", - "debug": "^3.1.0", - "webassembly": "^0.11.0" + "debug": "^3.1.0" }, "devDependencies": { "@webassemblyjs/helper-test-framework": "1.5.6", "@webassemblyjs/wast-parser": "1.5.6", "@webassemblyjs/wasm-parser": "1.5.6", - "@webassemblyjs/wast-printer": "1.5.6" + "@webassemblyjs/wast-printer": "1.5.6", + "assemblyscript": "github:AssemblyScript/assemblyscript" } } diff --git a/packages/proposal-sign-extension-ops/src/index.js b/packages/proposal-sign-extension-ops/src/index.js index f0455e71e..4ff5ef474 100644 --- a/packages/proposal-sign-extension-ops/src/index.js +++ b/packages/proposal-sign-extension-ops/src/index.js @@ -1,4 +1,3 @@ -import { edit } from "@webassemblyjs/wasm-edit"; import { traverse, callInstruction, numberLiteral } from "@webassemblyjs/ast"; import i32_extend8_s from "./polyfills/i32_extend8_s.json"; import i32_extend16_s from "./polyfills/i32_extend16_s.json"; @@ -45,17 +44,10 @@ class Polyfills { } export function transformAst(ast) { - const polyfillState = {}; - - const needsPolyfill = instr => polyfillState[instr] > 0; - const requirePolyfill = instr => { - polyfillState[instr]; - }; - let numberOfFuncs = 0; const countFuncVisitor = { - Func(path) { + Func() { ++numberOfFuncs; } }; diff --git a/packages/proposal-sign-extension-ops/src/polyfills.js b/packages/proposal-sign-extension-ops/src/polyfills.js index 241481c9b..489c8377f 100644 --- a/packages/proposal-sign-extension-ops/src/polyfills.js +++ b/packages/proposal-sign-extension-ops/src/polyfills.js @@ -1,4 +1,4 @@ -import compiler from "webassembly/cli/compiler"; +import asc from "assemblyscript/cli/asc"; import { decode } from "@webassemblyjs/wasm-parser"; import { readFileSync, writeFileSync } from "fs"; @@ -10,25 +10,25 @@ const instructions = ["i32_extend8_s", "i32_extend16_s"]; export function generateAsts() { instructions.forEach(instr => { - compiler.main( + asc.main( [ - "-o", + `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.ts`, + "--binaryFile", `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.wasm`, - "--optimize", - path.resolve( - `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.c` - ) + "--optimize" ], - function(err, filename) { - if (err) { - throw err; - } - console.log("saved to: " + filename); - - const wasmFile = readFileSync(filename); + { + stdout: process.stdout, + stderr: process.stderr + }, + function(err) { + if (err) throw err; + + const wasmFile = readFileSync( + `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.wasm` + ); const ast = decode(wasmFile); - const funcAst = ast.body[0].fields.filter(f => f.type === "Func")[0]; mkdirp( diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.c b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.c deleted file mode 100644 index 8ee566315..000000000 --- a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "stdint.h" - -export int32_t i32_extend16_s(int32_t x) { - return (x & 0x00008000) ? (x | 0xffff8000) : (x & 0x00007fff); -} - diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.ts b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.ts new file mode 100644 index 000000000..ec5225fba --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.ts @@ -0,0 +1,6 @@ +/** + * Polyfill for i32_extend16_s instruction + */ +export function i32_extend16_s(x: i32): i32 { + return (x & 0x00008000) ? (x | 0xffff8000) : (x & 0x00007fff); +} diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.c b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.c deleted file mode 100644 index cbac91c16..000000000 --- a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "stdint.h" - -export int32_t i32_extend8_s(int32_t x) { - return (x & 0x00000080) ? (x | 0xffffff80) : (x & 0x0000007f); -} - diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.ts b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.ts new file mode 100644 index 000000000..b8e6b4610 --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.ts @@ -0,0 +1,6 @@ +/** + * Polyfill for i32_extend8_s instruction + */ +export function i32_extend8_s(x: i32): i32 { + return (x & 0x00000080) ? (x | 0xffffff80) : (x & 0x0000007f); +} diff --git a/packages/proposal-sign-extension-ops/test/wast/mixed/output.wast b/packages/proposal-sign-extension-ops/test/wast/mixed/output.wast index 47ea56305..3d62f292d 100644 --- a/packages/proposal-sign-extension-ops/test/wast/mixed/output.wast +++ b/packages/proposal-sign-extension-ops/test/wast/mixed/output.wast @@ -11,7 +11,7 @@ (get_local 0) (call 4) ) - (func (param i32) (result i32) + (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s/i32_extend16_s (param i32) (result i32) (get_local 0) (i32.const -32768) (i32.or) @@ -21,11 +21,9 @@ (get_local 0) (i32.const 32768) (i32.and) - (i32.const 15) - (i32.shr_u) (select) ) - (func (param i32) (result i32) + (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s/i32_extend8_s (param i32) (result i32) (get_local 0) (i32.const -128) (i32.or) @@ -35,8 +33,6 @@ (get_local 0) (i32.const 128) (i32.and) - (i32.const 7) - (i32.shr_u) (select) ) ) diff --git a/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend16_s/output.wast b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend16_s/output.wast index e13c95f16..c85516bee 100644 --- a/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend16_s/output.wast +++ b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend16_s/output.wast @@ -10,7 +10,7 @@ (get_local 0) (call 3) ) - (func (param i32) (result i32) + (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s/i32_extend16_s (param i32) (result i32) (get_local 0) (i32.const -32768) (i32.or) @@ -20,8 +20,6 @@ (get_local 0) (i32.const 32768) (i32.and) - (i32.const 15) - (i32.shr_u) (select) ) ) diff --git a/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend8_s/output.wast b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend8_s/output.wast index 1283e9c97..99ac3cd76 100644 --- a/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend8_s/output.wast +++ b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend8_s/output.wast @@ -11,7 +11,7 @@ (get_local 0) (call 3) ) - (func (param i32) (result i32) + (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s/i32_extend8_s (param i32) (result i32) (get_local 0) (i32.const -128) (i32.or) @@ -21,8 +21,6 @@ (get_local 0) (i32.const 128) (i32.and) - (i32.const 7) - (i32.shr_u) (select) ) ) diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend16_s/output.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend16_s/output.wast index 2d3a2d391..252b049e0 100644 --- a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend16_s/output.wast +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend16_s/output.wast @@ -3,7 +3,7 @@ (get_local 0) (call 1) ) - (func (param i32) (result i32) + (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s/i32_extend16_s (param i32) (result i32) (get_local 0) (i32.const -32768) (i32.or) @@ -13,8 +13,6 @@ (get_local 0) (i32.const 32768) (i32.and) - (i32.const 15) - (i32.shr_u) (select) ) ) diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend8_s/output.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend8_s/output.wast index d2ac65d2c..957051cd4 100644 --- a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend8_s/output.wast +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend8_s/output.wast @@ -3,7 +3,7 @@ (get_local 0) (call 1) ) - (func (param i32) (result i32) + (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s/i32_extend8_s (param i32) (result i32) (get_local 0) (i32.const -128) (i32.or) @@ -13,8 +13,6 @@ (get_local 0) (i32.const 128) (i32.and) - (i32.const 7) - (i32.shr_u) (select) ) ) From 258091fea3b75a8bd34b00bface5e23eb84e0063 Mon Sep 17 00:00:00 2001 From: Mauro Bringolf Date: Thu, 31 May 2018 09:23:44 +0200 Subject: [PATCH 08/13] Moved polyfill generation into scripts and fix build process --- package.json | 3 +- .../proposal-sign-extension-ops/package.json | 3 +- .../src/polyfills.js | 47 ----- .../src/polyfills/i32_extend16_s.json | 165 ++++++++++++++++++ .../src/polyfills/i32_extend8_s.json | 165 ++++++++++++++++++ scripts/build.sh | 5 +- scripts/generate-polyfills.js | 54 +++++- yarn.lock | 59 ++++++- 8 files changed, 446 insertions(+), 55 deletions(-) delete mode 100644 packages/proposal-sign-extension-ops/src/polyfills.js create mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.json create mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.json diff --git a/package.json b/package.json index 242ad4119..4d17fdf3a 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "markdown-to-html": "0.0.13", "mocha": "4.0.1", "performance-now": "2.1.0", - "prettier": "1.9.2" + "prettier": "1.9.2", + "assemblyscript": "github:AssemblyScript/assemblyscript" }, "dependencies": { "babel-plugin-mamacro": "0.0.3", diff --git a/packages/proposal-sign-extension-ops/package.json b/packages/proposal-sign-extension-ops/package.json index 2cdd02e17..88a00d6b7 100644 --- a/packages/proposal-sign-extension-ops/package.json +++ b/packages/proposal-sign-extension-ops/package.json @@ -29,7 +29,6 @@ "@webassemblyjs/helper-test-framework": "1.5.6", "@webassemblyjs/wast-parser": "1.5.6", "@webassemblyjs/wasm-parser": "1.5.6", - "@webassemblyjs/wast-printer": "1.5.6", - "assemblyscript": "github:AssemblyScript/assemblyscript" + "@webassemblyjs/wast-printer": "1.5.6" } } diff --git a/packages/proposal-sign-extension-ops/src/polyfills.js b/packages/proposal-sign-extension-ops/src/polyfills.js deleted file mode 100644 index 489c8377f..000000000 --- a/packages/proposal-sign-extension-ops/src/polyfills.js +++ /dev/null @@ -1,47 +0,0 @@ -import asc from "assemblyscript/cli/asc"; -import { decode } from "@webassemblyjs/wasm-parser"; - -import { readFileSync, writeFileSync } from "fs"; - -import path from "path"; -import mkdirp from "mkdirp"; - -const instructions = ["i32_extend8_s", "i32_extend16_s"]; - -export function generateAsts() { - instructions.forEach(instr => { - asc.main( - [ - `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.ts`, - "--binaryFile", - `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.wasm`, - "--optimize" - ], - { - stdout: process.stdout, - stderr: process.stderr - }, - function(err) { - if (err) throw err; - - const wasmFile = readFileSync( - `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.wasm` - ); - - const ast = decode(wasmFile); - const funcAst = ast.body[0].fields.filter(f => f.type === "Func")[0]; - - mkdirp( - path.resolve("./packages/proposal-sign-extension-ops/lib/polyfills") - ); - - writeFileSync( - path.resolve( - `./packages/proposal-sign-extension-ops/lib/polyfills/${instr}.json` - ), - JSON.stringify(funcAst, null, 2) - ); - } - ); - }); -} diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.json b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.json new file mode 100644 index 000000000..56cfcb292 --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.json @@ -0,0 +1,165 @@ +{ + "type": "Func", + "name": { + "type": "Identifier", + "value": "packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s/i32_extend16_s" + }, + "signature": { + "type": "Signature", + "params": [ + { + "valtype": "i32" + } + ], + "results": [ + "i32" + ] + }, + "body": [ + { + "type": "Instr", + "id": "get_local", + "args": [ + { + "type": "NumberLiteral", + "value": 0, + "raw": "0" + } + ], + "loc": { + "start": { + "line": -1, + "column": 59 + }, + "end": { + "line": -1, + "column": 61 + } + } + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "NumberLiteral", + "value": -32768, + "raw": "-32768" + } + ], + "object": "i32" + }, + { + "type": "Instr", + "id": "or", + "args": [], + "object": "i32" + }, + { + "type": "Instr", + "id": "get_local", + "args": [ + { + "type": "NumberLiteral", + "value": 0, + "raw": "0" + } + ], + "loc": { + "start": { + "line": -1, + "column": 66 + }, + "end": { + "line": -1, + "column": 68 + } + } + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "NumberLiteral", + "value": 32767, + "raw": "32767" + } + ], + "object": "i32" + }, + { + "type": "Instr", + "id": "and", + "args": [], + "object": "i32" + }, + { + "type": "Instr", + "id": "get_local", + "args": [ + { + "type": "NumberLiteral", + "value": 0, + "raw": "0" + } + ], + "loc": { + "start": { + "line": -1, + "column": 73 + }, + "end": { + "line": -1, + "column": 75 + } + } + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "NumberLiteral", + "value": 32768, + "raw": "32768" + } + ], + "object": "i32" + }, + { + "type": "Instr", + "id": "and", + "args": [], + "object": "i32" + }, + { + "type": "Instr", + "id": "select", + "args": [], + "loc": { + "start": { + "line": -1, + "column": 80 + }, + "end": { + "line": -1, + "column": 81 + } + } + } + ], + "loc": { + "start": { + "line": -1, + "column": 57 + }, + "end": { + "line": -1, + "column": 82 + } + }, + "metadata": { + "bodySize": 24 + } +} \ No newline at end of file diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.json b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.json new file mode 100644 index 000000000..76af9fb12 --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.json @@ -0,0 +1,165 @@ +{ + "type": "Func", + "name": { + "type": "Identifier", + "value": "packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s/i32_extend8_s" + }, + "signature": { + "type": "Signature", + "params": [ + { + "valtype": "i32" + } + ], + "results": [ + "i32" + ] + }, + "body": [ + { + "type": "Instr", + "id": "get_local", + "args": [ + { + "type": "NumberLiteral", + "value": 0, + "raw": "0" + } + ], + "loc": { + "start": { + "line": -1, + "column": 58 + }, + "end": { + "line": -1, + "column": 60 + } + } + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "NumberLiteral", + "value": -128, + "raw": "-128" + } + ], + "object": "i32" + }, + { + "type": "Instr", + "id": "or", + "args": [], + "object": "i32" + }, + { + "type": "Instr", + "id": "get_local", + "args": [ + { + "type": "NumberLiteral", + "value": 0, + "raw": "0" + } + ], + "loc": { + "start": { + "line": -1, + "column": 64 + }, + "end": { + "line": -1, + "column": 66 + } + } + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "NumberLiteral", + "value": 127, + "raw": "127" + } + ], + "object": "i32" + }, + { + "type": "Instr", + "id": "and", + "args": [], + "object": "i32" + }, + { + "type": "Instr", + "id": "get_local", + "args": [ + { + "type": "NumberLiteral", + "value": 0, + "raw": "0" + } + ], + "loc": { + "start": { + "line": -1, + "column": 70 + }, + "end": { + "line": -1, + "column": 72 + } + } + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "NumberLiteral", + "value": 128, + "raw": "128" + } + ], + "object": "i32" + }, + { + "type": "Instr", + "id": "and", + "args": [], + "object": "i32" + }, + { + "type": "Instr", + "id": "select", + "args": [], + "loc": { + "start": { + "line": -1, + "column": 76 + }, + "end": { + "line": -1, + "column": 77 + } + } + } + ], + "loc": { + "start": { + "line": -1, + "column": 56 + }, + "end": { + "line": -1, + "column": 78 + } + }, + "metadata": { + "bodySize": 21 + } +} \ No newline at end of file diff --git a/scripts/build.sh b/scripts/build.sh index c94fce4f1..c69c37d1b 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -7,6 +7,7 @@ cd $ROOT_DIR OPTS="$@" sh ./scripts/generate-ast-utils.sh +./scripts/generate-polyfills.js if [ -z "$DISABLE_FUZZER_TEST" ]; then yarn --cwd ./packages/floating-point-hex-parser run build-fuzzer @@ -29,8 +30,8 @@ for D in ./packages/*; do $OPTS & done -wait -./scripts/generate-polyfills.js +wait +cp -r packages/proposal-sign-extension-ops/src/polyfills packages/proposal-sign-extension-ops/lib/ cp -v packages/dce/src/libwabt.js packages/dce/lib/libwabt.js diff --git a/scripts/generate-polyfills.js b/scripts/generate-polyfills.js index c9afbd1d5..24e88a7af 100755 --- a/scripts/generate-polyfills.js +++ b/scripts/generate-polyfills.js @@ -1,3 +1,55 @@ #!/usr/bin/env node -require("../packages/proposal-sign-extension-ops/lib/polyfills.js").generateAsts(); +const asc = require("assemblyscript/cli/asc") +const { decode } = require("../packages/wasm-parser/lib/"); + +const { readFileSync, writeFileSync } = require("fs"); + +const path = require("path"); +const mkdirp = require("mkdirp"); + +const instructions = ["i32_extend8_s", "i32_extend16_s"]; + +instructions.forEach(instr => { + console.log(`Generating polyfill for ${instr}...`) + asc.main( + [ + `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.ts`, + "--binaryFile", + `./packages/proposal-sign-extension-ops/lib/polyfills/${instr}.wasm`, + "--optimize" + ], + { + stdout: process.stdout, + stderr: process.stderr + }, + function(err) { + if (err) throw err; + + console.log("Successfuly compiled polyfill from TypeScript to wasm.") + + const wasmFile = readFileSync( + `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.wasm` + ); + + const ast = decode(wasmFile); + const funcAst = ast.body[0].fields.filter(f => f.type === "Func")[0]; + + console.log("Successfuly decoded wasm polyfill into AST.") + + mkdirp( + path.resolve("./packages/proposal-sign-extension-ops/src/polyfills") + ); + + writeFileSync( + path.resolve( + `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.json` + ), + JSON.stringify(funcAst, null, 2) + ); + + console.log("Successfuly stored JSON source for polyfill.") + } + ); +}); + diff --git a/yarn.lock b/yarn.lock index 6e082d90b..261b58854 100644 --- a/yarn.lock +++ b/yarn.lock @@ -554,6 +554,10 @@ lodash "^4.17.5" to-fast-properties "^2.0.0" +"@protobufjs/utf8@^1.1.0": + version "1.1.0" + resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570" + "@yarnpkg/lockfile@^1.0.0": version "1.0.0" resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.0.0.tgz#33d1dbb659a23b81f87f048762b35a446172add3" @@ -707,6 +711,17 @@ asn1@~0.2.3: version "0.2.3" resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.3.tgz#dac8787713c9966849fc8180777ebe9c1ddf3b86" +"assemblyscript@github:AssemblyScript/assemblyscript": + version "0.5.0" + resolved "https://codeload.github.com/AssemblyScript/assemblyscript/tar.gz/9d25f78fc15d61cc180e55aa6d53636ec7350e6e" + dependencies: + "@protobufjs/utf8" "^1.1.0" + binaryen "48.0.0-nightly.20180520" + glob "^7.1.2" + long "^4.0.0" + minimist "^1.2.0" + ts-node "^6.0.3" + assert-plus@1.0.0, assert-plus@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525" @@ -807,6 +822,10 @@ binary-extensions@^1.0.0: buffers "~0.1.1" chainsaw "~0.1.0" +binaryen@48.0.0-nightly.20180520: + version "48.0.0-nightly.20180520" + resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-48.0.0-nightly.20180520.tgz#24ce2172da6c6e44af97889fce5b1d96542db596" + bl@~0.4.1: version "0.4.2" resolved "https://registry.yarnpkg.com/bl/-/bl-0.4.2.tgz#5db31d72f038c54e68adc39578125fe3b0addc96" @@ -954,7 +973,7 @@ chalk@^1.1.3: strip-ansi "^3.0.0" supports-color "^2.0.0" -chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0: +chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0: version "2.4.1" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e" dependencies: @@ -1410,7 +1429,7 @@ diff@3.3.1: version "3.3.1" resolved "https://registry.yarnpkg.com/diff/-/diff-3.3.1.tgz#aa8567a6eed03c531fc89d3f711cd0e5259dec75" -diff@^3.2.0: +diff@^3.1.0, diff@^3.2.0: version "3.5.0" resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12" @@ -2587,6 +2606,10 @@ lodash@^4.15.0, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.2.1, lo version "4.17.10" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7" +long@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28" + longest@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097" @@ -2621,6 +2644,10 @@ make-dir@^1.0.0: dependencies: pify "^3.0.0" +make-error@^1.1.1: + version "1.3.4" + resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.4.tgz#19978ed575f9e9545d2ff8c13e33b5d18a67d535" + map-obj@^1.0.0, map-obj@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-1.0.1.tgz#d933ceb9205d82bdcf4886f6742bdc2b4dea146d" @@ -3609,6 +3636,13 @@ sort-keys@^2.0.0: dependencies: is-plain-obj "^1.0.0" +source-map-support@^0.5.3: + version "0.5.6" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.6.tgz#4435cee46b1aab62b8e8610ce60f788091c51c13" + dependencies: + buffer-from "^1.0.0" + source-map "^0.6.0" + source-map@^0.4.4: version "0.4.4" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.4.4.tgz#eba4f5da9c0dc999de68032d8b4f76173652036b" @@ -3619,6 +3653,10 @@ source-map@^0.5.0, source-map@~0.5.1: version "0.5.7" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" +source-map@^0.6.0: + version "0.6.1" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" + spdx-correct@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.0.0.tgz#05a5b4d7153a195bc92c3c425b69f3b2a9524c82" @@ -3891,6 +3929,19 @@ trim-right@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003" +ts-node@^6.0.3: + version "6.0.5" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-6.0.5.tgz#977c1c931da7a2b09ae2930101f0104a5c2271e9" + dependencies: + arrify "^1.0.0" + chalk "^2.3.0" + diff "^3.1.0" + make-error "^1.1.1" + minimist "^1.2.0" + mkdirp "^0.5.1" + source-map-support "^0.5.3" + yn "^2.0.0" + tunnel-agent@^0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd" @@ -4192,3 +4243,7 @@ yargs@~3.10.0: cliui "^2.1.0" decamelize "^1.0.0" window-size "0.1.0" + +yn@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/yn/-/yn-2.0.0.tgz#e5adabc8acf408f6385fc76495684c88e6af689a" From fe73f49ef605dea295d85a7fac5e174699c4387f Mon Sep 17 00:00:00 2001 From: Mauro Bringolf Date: Thu, 31 May 2018 10:03:30 +0200 Subject: [PATCH 09/13] Add polyfills for i64 --- .../proposal-sign-extension-ops/src/index.js | 8 +- .../src/polyfills/i64_extend16_s.json | 191 ++++++++++++++++++ .../src/polyfills/i64_extend16_s.ts | 6 + .../src/polyfills/i64_extend32_s.json | 191 ++++++++++++++++++ .../src/polyfills/i64_extend32_s.ts | 6 + .../src/polyfills/i64_extend8_s.json | 191 ++++++++++++++++++ .../src/polyfills/i64_extend8_s.ts | 6 + .../proposal-sign-extension-ops/test/index.js | 20 +- .../input.wast | 7 + .../output.wast | 20 ++ .../input.wast | 7 + .../output.wast | 20 ++ .../input.wast | 7 + .../output.wast | 20 ++ scripts/generate-polyfills.js | 15 +- 15 files changed, 706 insertions(+), 9 deletions(-) create mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.json create mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.ts create mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.json create mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.ts create mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.json create mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.ts create mode 100644 packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend16_s/input.wast create mode 100644 packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend16_s/output.wast create mode 100644 packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend32_s/input.wast create mode 100644 packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend32_s/output.wast create mode 100644 packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend8_s/input.wast create mode 100644 packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend8_s/output.wast diff --git a/packages/proposal-sign-extension-ops/src/index.js b/packages/proposal-sign-extension-ops/src/index.js index 4ff5ef474..8105e2a2a 100644 --- a/packages/proposal-sign-extension-ops/src/index.js +++ b/packages/proposal-sign-extension-ops/src/index.js @@ -1,6 +1,9 @@ import { traverse, callInstruction, numberLiteral } from "@webassemblyjs/ast"; import i32_extend8_s from "./polyfills/i32_extend8_s.json"; import i32_extend16_s from "./polyfills/i32_extend16_s.json"; +import i64_extend8_s from "./polyfills/i64_extend8_s.json"; +import i64_extend16_s from "./polyfills/i64_extend16_s.json"; +import i64_extend32_s from "./polyfills/i64_extend32_s.json"; class Polyfills { constructor(startIndex) { @@ -8,7 +11,10 @@ class Polyfills { this.asts = { i32_extend8_s, - i32_extend16_s + i32_extend16_s, + i64_extend8_s, + i64_extend16_s, + i64_extend32_s }; this.instructions = Object.keys(this.asts); diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.json b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.json new file mode 100644 index 000000000..a91a01875 --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.json @@ -0,0 +1,191 @@ +{ + "type": "Func", + "name": { + "type": "Identifier", + "value": "packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s/i64_extend16_s" + }, + "signature": { + "type": "Signature", + "params": [ + { + "valtype": "i64" + } + ], + "results": [ + "i64" + ] + }, + "body": [ + { + "type": "Instr", + "id": "get_local", + "args": [ + { + "type": "NumberLiteral", + "value": 0, + "raw": "0" + } + ], + "loc": { + "start": { + "line": -1, + "column": 59 + }, + "end": { + "line": -1, + "column": 61 + } + } + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "LongNumberLiteral", + "value": { + "high": -1, + "low": 4294934528 + } + } + ], + "object": "i64" + }, + { + "type": "Instr", + "id": "or", + "args": [], + "object": "i64" + }, + { + "type": "Instr", + "id": "get_local", + "args": [ + { + "type": "NumberLiteral", + "value": 0, + "raw": "0" + } + ], + "loc": { + "start": { + "line": -1, + "column": 66 + }, + "end": { + "line": -1, + "column": 68 + } + } + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "LongNumberLiteral", + "value": { + "high": 0, + "low": 32767 + } + } + ], + "object": "i64" + }, + { + "type": "Instr", + "id": "and", + "args": [], + "object": "i64" + }, + { + "type": "Instr", + "id": "get_local", + "args": [ + { + "type": "NumberLiteral", + "value": 0, + "raw": "0" + } + ], + "loc": { + "start": { + "line": -1, + "column": 73 + }, + "end": { + "line": -1, + "column": 75 + } + } + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "LongNumberLiteral", + "value": { + "high": 0, + "low": 32768 + } + } + ], + "object": "i64" + }, + { + "type": "Instr", + "id": "and", + "args": [], + "object": "i64" + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "LongNumberLiteral", + "value": { + "high": 0, + "low": 0 + } + } + ], + "object": "i64" + }, + { + "type": "Instr", + "id": "ne", + "args": [], + "object": "i64" + }, + { + "type": "Instr", + "id": "select", + "args": [], + "loc": { + "start": { + "line": -1, + "column": 83 + }, + "end": { + "line": -1, + "column": 84 + } + } + } + ], + "loc": { + "start": { + "line": -1, + "column": 57 + }, + "end": { + "line": -1, + "column": 85 + } + }, + "metadata": { + "bodySize": 27 + } +} \ No newline at end of file diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.ts b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.ts new file mode 100644 index 000000000..8006941e7 --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.ts @@ -0,0 +1,6 @@ +/** + * Polyfill for i64_extend16_s instruction + */ +export function i64_extend16_s(x : i64) : i64 { + return (x & 0x0000000000008000) ? (x | 0xffffffffffff8000) : (x & 0x0000000000007fff); +} diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.json b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.json new file mode 100644 index 000000000..9ebcd68be --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.json @@ -0,0 +1,191 @@ +{ + "type": "Func", + "name": { + "type": "Identifier", + "value": "packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s/i64_extend32_s" + }, + "signature": { + "type": "Signature", + "params": [ + { + "valtype": "i64" + } + ], + "results": [ + "i64" + ] + }, + "body": [ + { + "type": "Instr", + "id": "get_local", + "args": [ + { + "type": "NumberLiteral", + "value": 0, + "raw": "0" + } + ], + "loc": { + "start": { + "line": -1, + "column": 59 + }, + "end": { + "line": -1, + "column": 61 + } + } + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "LongNumberLiteral", + "value": { + "high": -1, + "low": 2147483648 + } + } + ], + "object": "i64" + }, + { + "type": "Instr", + "id": "or", + "args": [], + "object": "i64" + }, + { + "type": "Instr", + "id": "get_local", + "args": [ + { + "type": "NumberLiteral", + "value": 0, + "raw": "0" + } + ], + "loc": { + "start": { + "line": -1, + "column": 68 + }, + "end": { + "line": -1, + "column": 70 + } + } + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "LongNumberLiteral", + "value": { + "high": 0, + "low": 2147483647 + } + } + ], + "object": "i64" + }, + { + "type": "Instr", + "id": "and", + "args": [], + "object": "i64" + }, + { + "type": "Instr", + "id": "get_local", + "args": [ + { + "type": "NumberLiteral", + "value": 0, + "raw": "0" + } + ], + "loc": { + "start": { + "line": -1, + "column": 77 + }, + "end": { + "line": -1, + "column": 79 + } + } + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "LongNumberLiteral", + "value": { + "high": 0, + "low": 2147483648 + } + } + ], + "object": "i64" + }, + { + "type": "Instr", + "id": "and", + "args": [], + "object": "i64" + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "LongNumberLiteral", + "value": { + "high": 0, + "low": 0 + } + } + ], + "object": "i64" + }, + { + "type": "Instr", + "id": "ne", + "args": [], + "object": "i64" + }, + { + "type": "Instr", + "id": "select", + "args": [], + "loc": { + "start": { + "line": -1, + "column": 89 + }, + "end": { + "line": -1, + "column": 90 + } + } + } + ], + "loc": { + "start": { + "line": -1, + "column": 57 + }, + "end": { + "line": -1, + "column": 91 + } + }, + "metadata": { + "bodySize": 33 + } +} \ No newline at end of file diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.ts b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.ts new file mode 100644 index 000000000..bb34531e3 --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.ts @@ -0,0 +1,6 @@ +/** + * Polyfill for i64_extend32_s instruction + */ +export function i64_extend32_s(x : i64) : i64 { + return (x & 0x0000000080000000) ? (x | 0xffffffff80000000) : (x & 0x000000007fffffff); +} diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.json b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.json new file mode 100644 index 000000000..afbe894a9 --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.json @@ -0,0 +1,191 @@ +{ + "type": "Func", + "name": { + "type": "Identifier", + "value": "packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s/i64_extend8_s" + }, + "signature": { + "type": "Signature", + "params": [ + { + "valtype": "i64" + } + ], + "results": [ + "i64" + ] + }, + "body": [ + { + "type": "Instr", + "id": "get_local", + "args": [ + { + "type": "NumberLiteral", + "value": 0, + "raw": "0" + } + ], + "loc": { + "start": { + "line": -1, + "column": 58 + }, + "end": { + "line": -1, + "column": 60 + } + } + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "LongNumberLiteral", + "value": { + "high": -1, + "low": 4294967168 + } + } + ], + "object": "i64" + }, + { + "type": "Instr", + "id": "or", + "args": [], + "object": "i64" + }, + { + "type": "Instr", + "id": "get_local", + "args": [ + { + "type": "NumberLiteral", + "value": 0, + "raw": "0" + } + ], + "loc": { + "start": { + "line": -1, + "column": 64 + }, + "end": { + "line": -1, + "column": 66 + } + } + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "LongNumberLiteral", + "value": { + "high": 0, + "low": 127 + } + } + ], + "object": "i64" + }, + { + "type": "Instr", + "id": "and", + "args": [], + "object": "i64" + }, + { + "type": "Instr", + "id": "get_local", + "args": [ + { + "type": "NumberLiteral", + "value": 0, + "raw": "0" + } + ], + "loc": { + "start": { + "line": -1, + "column": 70 + }, + "end": { + "line": -1, + "column": 72 + } + } + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "LongNumberLiteral", + "value": { + "high": 0, + "low": 128 + } + } + ], + "object": "i64" + }, + { + "type": "Instr", + "id": "and", + "args": [], + "object": "i64" + }, + { + "type": "Instr", + "id": "const", + "args": [ + { + "type": "LongNumberLiteral", + "value": { + "high": 0, + "low": 0 + } + } + ], + "object": "i64" + }, + { + "type": "Instr", + "id": "ne", + "args": [], + "object": "i64" + }, + { + "type": "Instr", + "id": "select", + "args": [], + "loc": { + "start": { + "line": -1, + "column": 79 + }, + "end": { + "line": -1, + "column": 80 + } + } + } + ], + "loc": { + "start": { + "line": -1, + "column": 56 + }, + "end": { + "line": -1, + "column": 81 + } + }, + "metadata": { + "bodySize": 24 + } +} \ No newline at end of file diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.ts b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.ts new file mode 100644 index 000000000..d8c7f338c --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.ts @@ -0,0 +1,6 @@ +/** + * Polyfill for i64_extend8_s instruction + */ +export function i64_extend8_s(x : i64) : i64 { + return (x & 0x0000000000000080) ? (x | 0xffffffffffffff80) : (x & 0x000000000000007f); +} diff --git a/packages/proposal-sign-extension-ops/test/index.js b/packages/proposal-sign-extension-ops/test/index.js index 079d6991a..23a18ac31 100644 --- a/packages/proposal-sign-extension-ops/test/index.js +++ b/packages/proposal-sign-extension-ops/test/index.js @@ -6,7 +6,7 @@ const { getFixtures, compareStrings } = require("@webassemblyjs/helper-test-framework"); -const { readFileSync } = require("fs"); +const { readFileSync, existsSync, writeFileSync } = require("fs"); const { transformAst } = require("../lib/"); @@ -18,13 +18,23 @@ const testCases = getFixtures( testCases.forEach(testCase => { describe(testCase, () => { const input = readFileSync(testCase, "utf8").trim(); - const expectedOutput = readFileSync( - path.join(path.dirname(testCase), "output.wast"), - "utf8" - ).trim(); it("should transpile sign extension operators into functions correctly", () => { const actualOutput = print(transformAst(parse(input))); + + if (!existsSync(path.join(path.dirname(testCase), "output.wast"))) { + writeFileSync( + path.join(path.dirname(testCase), "output.wast"), + actualOutput + ); + return; + } + + const expectedOutput = readFileSync( + path.join(path.dirname(testCase), "output.wast"), + "utf8" + ).trim(); + compareStrings(actualOutput, expectedOutput); }); }); diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend16_s/input.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend16_s/input.wast new file mode 100644 index 000000000..5870a7742 --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend16_s/input.wast @@ -0,0 +1,7 @@ +(module + (func (param i64) (result i64) + (get_local 0) + (i64_extend16_s) + ) +) + diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend16_s/output.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend16_s/output.wast new file mode 100644 index 000000000..e9dc10830 --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend16_s/output.wast @@ -0,0 +1,20 @@ +(module + (func (param i64) (result i64) + (get_local 0) + (call 1) + ) + (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s/i64_extend16_s (param i64) (result i64) + (get_local 0) + (i64.const -32768) + (i64.or) + (get_local 0) + (i64.const 32767) + (i64.and) + (get_local 0) + (i64.const 32768) + (i64.and) + (i64.const 0) + (i64.ne) + (select) + ) +) diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend32_s/input.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend32_s/input.wast new file mode 100644 index 000000000..bc8aa90eb --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend32_s/input.wast @@ -0,0 +1,7 @@ +(module + (func (param i64) (result i64) + (get_local 0) + (i64_extend32_s) + ) +) + diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend32_s/output.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend32_s/output.wast new file mode 100644 index 000000000..e99ceda79 --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend32_s/output.wast @@ -0,0 +1,20 @@ +(module + (func (param i64) (result i64) + (get_local 0) + (call 1) + ) + (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s/i64_extend32_s (param i64) (result i64) + (get_local 0) + (i64.const -2147483648) + (i64.or) + (get_local 0) + (i64.const 2147483647) + (i64.and) + (get_local 0) + (i64.const 2147483648) + (i64.and) + (i64.const 0) + (i64.ne) + (select) + ) +) diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend8_s/input.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend8_s/input.wast new file mode 100644 index 000000000..044ce51d9 --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend8_s/input.wast @@ -0,0 +1,7 @@ +(module + (func (param i64) (result i64) + (get_local 0) + (i64_extend8_s) + ) +) + diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend8_s/output.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend8_s/output.wast new file mode 100644 index 000000000..2aeee71ae --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend8_s/output.wast @@ -0,0 +1,20 @@ +(module + (func (param i64) (result i64) + (get_local 0) + (call 1) + ) + (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s/i64_extend8_s (param i64) (result i64) + (get_local 0) + (i64.const -128) + (i64.or) + (get_local 0) + (i64.const 127) + (i64.and) + (get_local 0) + (i64.const 128) + (i64.and) + (i64.const 0) + (i64.ne) + (select) + ) +) diff --git a/scripts/generate-polyfills.js b/scripts/generate-polyfills.js index 24e88a7af..3b0fbddc4 100755 --- a/scripts/generate-polyfills.js +++ b/scripts/generate-polyfills.js @@ -3,12 +3,12 @@ const asc = require("assemblyscript/cli/asc") const { decode } = require("../packages/wasm-parser/lib/"); -const { readFileSync, writeFileSync } = require("fs"); +const { readFileSync, writeFileSync, copyFileSync } = require("fs"); const path = require("path"); const mkdirp = require("mkdirp"); -const instructions = ["i32_extend8_s", "i32_extend16_s"]; +const instructions = ["i32_extend8_s", "i32_extend16_s", "i64_extend8_s", "i64_extend16_s", "i64_extend32_s"]; instructions.forEach(instr => { console.log(`Generating polyfill for ${instr}...`) @@ -16,7 +16,7 @@ instructions.forEach(instr => { [ `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.ts`, "--binaryFile", - `./packages/proposal-sign-extension-ops/lib/polyfills/${instr}.wasm`, + `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.wasm`, "--optimize" ], { @@ -48,6 +48,15 @@ instructions.forEach(instr => { JSON.stringify(funcAst, null, 2) ); + copyFileSync( + path.resolve( + `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.json` + ), + path.resolve( + `./packages/proposal-sign-extension-ops/lib/polyfills/${instr}.json` + ) + ); + console.log("Successfuly stored JSON source for polyfill.") } ); From 75cf6167cf2a0ed8cb94656ef731875fa5581487 Mon Sep 17 00:00:00 2001 From: Mauro Bringolf Date: Thu, 31 May 2018 10:16:27 +0200 Subject: [PATCH 10/13] Remove C sketch from readme --- .../proposal-sign-extension-ops/README.md | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/packages/proposal-sign-extension-ops/README.md b/packages/proposal-sign-extension-ops/README.md index 4502a8f68..17c7d5f28 100644 --- a/packages/proposal-sign-extension-ops/README.md +++ b/packages/proposal-sign-extension-ops/README.md @@ -2,26 +2,3 @@ -```c -#include "stdint.h" - -int32_t i32_extend8_s(int32_t x) { - return (x & 0x00000080) ? (x | 0xffffff80) : (x & 0x0000007f); -} - -int32_t i32_extend16_s(int32_t x) { - return (x & 0x00008000) ? (x | 0xffff8000) : (x & 0x00007fff); -} - -int64_t i64_extend8_s(int64_t x) { - return (x & 0x0000000000000080) ? (x | 0xffffffffffffff80) : (x & 0x000000000000007f); -} - -int64_t i64_extend16_s(int64_t x) { - return (x & 0x0000000000008000) ? (x | 0xffffffffffff8000) : (x & 0x0000000000007fff); -} - -int64_t i64_extend32_s(int64_t x) { - return (x & 0x0000000080000000) ? (x | 0xffffffff80000000) : (x & 0x000000007fffffff); -} -``` From c7b349d760e0e19c6bf53710f41872b1b54d34de Mon Sep 17 00:00:00 2001 From: Mauro Bringolf Date: Fri, 1 Jun 2018 21:46:36 +0200 Subject: [PATCH 11/13] Migrate to wast as source for polyfills --- .../proposal-sign-extension-ops/src/index.js | 33 ++- .../src/polyfills/i32_extend16_s.json | 165 --------------- .../src/polyfills/i32_extend16_s.ts | 6 - .../src/polyfills/i32_extend16_s.wast | 16 ++ .../src/polyfills/i32_extend8_s.json | 165 --------------- .../src/polyfills/i32_extend8_s.ts | 6 - .../src/polyfills/i32_extend8_s.wast | 16 ++ .../src/polyfills/i64_extend16_s.json | 191 ------------------ .../src/polyfills/i64_extend16_s.ts | 6 - .../src/polyfills/i64_extend16_s.wast | 18 ++ .../src/polyfills/i64_extend32_s.json | 191 ------------------ .../src/polyfills/i64_extend32_s.ts | 6 - .../src/polyfills/i64_extend32_s.wast | 18 ++ .../src/polyfills/i64_extend8_s.json | 191 ------------------ .../src/polyfills/i64_extend8_s.ts | 6 - .../src/polyfills/i64_extend8_s.wast | 18 ++ scripts/build.sh | 1 - scripts/generate-polyfills.js | 64 ------ 18 files changed, 109 insertions(+), 1008 deletions(-) delete mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.json delete mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.ts create mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.wast delete mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.json delete mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.ts create mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.wast delete mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.json delete mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.ts create mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.wast delete mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.json delete mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.ts create mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.wast delete mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.json delete mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.ts create mode 100644 packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.wast delete mode 100755 scripts/generate-polyfills.js diff --git a/packages/proposal-sign-extension-ops/src/index.js b/packages/proposal-sign-extension-ops/src/index.js index 8105e2a2a..f2811d629 100644 --- a/packages/proposal-sign-extension-ops/src/index.js +++ b/packages/proposal-sign-extension-ops/src/index.js @@ -1,20 +1,33 @@ import { traverse, callInstruction, numberLiteral } from "@webassemblyjs/ast"; -import i32_extend8_s from "./polyfills/i32_extend8_s.json"; -import i32_extend16_s from "./polyfills/i32_extend16_s.json"; -import i64_extend8_s from "./polyfills/i64_extend8_s.json"; -import i64_extend16_s from "./polyfills/i64_extend16_s.json"; -import i64_extend32_s from "./polyfills/i64_extend32_s.json"; +import { parse } from "@webassemblyjs/wast-parser"; +import { readFileSync } from "fs"; +import path from "path"; + +const funcFromWast = sourcePath => { + const ast = parse(readFileSync(sourcePath, "utf8")); + return ast.body[0].fields.find(f => f.type === "Func"); +}; class Polyfills { constructor(startIndex) { this.startIndex = startIndex; this.asts = { - i32_extend8_s, - i32_extend16_s, - i64_extend8_s, - i64_extend16_s, - i64_extend32_s + i32_extend8_s: funcFromWast( + path.join(__dirname, "/polyfills/i32_extend8_s.wast") + ), + i32_extend16_s: funcFromWast( + path.join(__dirname, "/polyfills/i32_extend16_s.wast") + ), + i64_extend8_s: funcFromWast( + path.join(__dirname, "/polyfills/i64_extend8_s.wast") + ), + i64_extend16_s: funcFromWast( + path.join(__dirname, "/polyfills/i64_extend16_s.wast") + ), + i64_extend32_s: funcFromWast( + path.join(__dirname, "/polyfills/i64_extend32_s.wast") + ) }; this.instructions = Object.keys(this.asts); diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.json b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.json deleted file mode 100644 index 56cfcb292..000000000 --- a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.json +++ /dev/null @@ -1,165 +0,0 @@ -{ - "type": "Func", - "name": { - "type": "Identifier", - "value": "packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s/i32_extend16_s" - }, - "signature": { - "type": "Signature", - "params": [ - { - "valtype": "i32" - } - ], - "results": [ - "i32" - ] - }, - "body": [ - { - "type": "Instr", - "id": "get_local", - "args": [ - { - "type": "NumberLiteral", - "value": 0, - "raw": "0" - } - ], - "loc": { - "start": { - "line": -1, - "column": 59 - }, - "end": { - "line": -1, - "column": 61 - } - } - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "NumberLiteral", - "value": -32768, - "raw": "-32768" - } - ], - "object": "i32" - }, - { - "type": "Instr", - "id": "or", - "args": [], - "object": "i32" - }, - { - "type": "Instr", - "id": "get_local", - "args": [ - { - "type": "NumberLiteral", - "value": 0, - "raw": "0" - } - ], - "loc": { - "start": { - "line": -1, - "column": 66 - }, - "end": { - "line": -1, - "column": 68 - } - } - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "NumberLiteral", - "value": 32767, - "raw": "32767" - } - ], - "object": "i32" - }, - { - "type": "Instr", - "id": "and", - "args": [], - "object": "i32" - }, - { - "type": "Instr", - "id": "get_local", - "args": [ - { - "type": "NumberLiteral", - "value": 0, - "raw": "0" - } - ], - "loc": { - "start": { - "line": -1, - "column": 73 - }, - "end": { - "line": -1, - "column": 75 - } - } - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "NumberLiteral", - "value": 32768, - "raw": "32768" - } - ], - "object": "i32" - }, - { - "type": "Instr", - "id": "and", - "args": [], - "object": "i32" - }, - { - "type": "Instr", - "id": "select", - "args": [], - "loc": { - "start": { - "line": -1, - "column": 80 - }, - "end": { - "line": -1, - "column": 81 - } - } - } - ], - "loc": { - "start": { - "line": -1, - "column": 57 - }, - "end": { - "line": -1, - "column": 82 - } - }, - "metadata": { - "bodySize": 24 - } -} \ No newline at end of file diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.ts b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.ts deleted file mode 100644 index ec5225fba..000000000 --- a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Polyfill for i32_extend16_s instruction - */ -export function i32_extend16_s(x: i32): i32 { - return (x & 0x00008000) ? (x | 0xffff8000) : (x & 0x00007fff); -} diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.wast b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.wast new file mode 100644 index 000000000..c68f98fa3 --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.wast @@ -0,0 +1,16 @@ +(module + (type (func (param i32) (result i32))) + (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s/i32_extend16_s (param i32) (result i32) + (get_local 0) + (i32.const -32768) + (i32.or) + (get_local 0) + (i32.const 32767) + (i32.and) + (get_local 0) + (i32.const 32768) + (i32.and) + (select) + ) + (export "i32_extend16_s" (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s/i32_extend16_s)) +) diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.json b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.json deleted file mode 100644 index 76af9fb12..000000000 --- a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.json +++ /dev/null @@ -1,165 +0,0 @@ -{ - "type": "Func", - "name": { - "type": "Identifier", - "value": "packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s/i32_extend8_s" - }, - "signature": { - "type": "Signature", - "params": [ - { - "valtype": "i32" - } - ], - "results": [ - "i32" - ] - }, - "body": [ - { - "type": "Instr", - "id": "get_local", - "args": [ - { - "type": "NumberLiteral", - "value": 0, - "raw": "0" - } - ], - "loc": { - "start": { - "line": -1, - "column": 58 - }, - "end": { - "line": -1, - "column": 60 - } - } - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "NumberLiteral", - "value": -128, - "raw": "-128" - } - ], - "object": "i32" - }, - { - "type": "Instr", - "id": "or", - "args": [], - "object": "i32" - }, - { - "type": "Instr", - "id": "get_local", - "args": [ - { - "type": "NumberLiteral", - "value": 0, - "raw": "0" - } - ], - "loc": { - "start": { - "line": -1, - "column": 64 - }, - "end": { - "line": -1, - "column": 66 - } - } - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "NumberLiteral", - "value": 127, - "raw": "127" - } - ], - "object": "i32" - }, - { - "type": "Instr", - "id": "and", - "args": [], - "object": "i32" - }, - { - "type": "Instr", - "id": "get_local", - "args": [ - { - "type": "NumberLiteral", - "value": 0, - "raw": "0" - } - ], - "loc": { - "start": { - "line": -1, - "column": 70 - }, - "end": { - "line": -1, - "column": 72 - } - } - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "NumberLiteral", - "value": 128, - "raw": "128" - } - ], - "object": "i32" - }, - { - "type": "Instr", - "id": "and", - "args": [], - "object": "i32" - }, - { - "type": "Instr", - "id": "select", - "args": [], - "loc": { - "start": { - "line": -1, - "column": 76 - }, - "end": { - "line": -1, - "column": 77 - } - } - } - ], - "loc": { - "start": { - "line": -1, - "column": 56 - }, - "end": { - "line": -1, - "column": 78 - } - }, - "metadata": { - "bodySize": 21 - } -} \ No newline at end of file diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.ts b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.ts deleted file mode 100644 index b8e6b4610..000000000 --- a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Polyfill for i32_extend8_s instruction - */ -export function i32_extend8_s(x: i32): i32 { - return (x & 0x00000080) ? (x | 0xffffff80) : (x & 0x0000007f); -} diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.wast b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.wast new file mode 100644 index 000000000..617bcfa6c --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.wast @@ -0,0 +1,16 @@ +(module + (type (func (param i32) (result i32))) + (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s/i32_extend8_s (param i32) (result i32) + (get_local 0) + (i32.const -128) + (i32.or) + (get_local 0) + (i32.const 127) + (i32.and) + (get_local 0) + (i32.const 128) + (i32.and) + (select) + ) + (export "i32_extend8_s" (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s/i32_extend8_s)) +) diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.json b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.json deleted file mode 100644 index a91a01875..000000000 --- a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.json +++ /dev/null @@ -1,191 +0,0 @@ -{ - "type": "Func", - "name": { - "type": "Identifier", - "value": "packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s/i64_extend16_s" - }, - "signature": { - "type": "Signature", - "params": [ - { - "valtype": "i64" - } - ], - "results": [ - "i64" - ] - }, - "body": [ - { - "type": "Instr", - "id": "get_local", - "args": [ - { - "type": "NumberLiteral", - "value": 0, - "raw": "0" - } - ], - "loc": { - "start": { - "line": -1, - "column": 59 - }, - "end": { - "line": -1, - "column": 61 - } - } - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "LongNumberLiteral", - "value": { - "high": -1, - "low": 4294934528 - } - } - ], - "object": "i64" - }, - { - "type": "Instr", - "id": "or", - "args": [], - "object": "i64" - }, - { - "type": "Instr", - "id": "get_local", - "args": [ - { - "type": "NumberLiteral", - "value": 0, - "raw": "0" - } - ], - "loc": { - "start": { - "line": -1, - "column": 66 - }, - "end": { - "line": -1, - "column": 68 - } - } - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "LongNumberLiteral", - "value": { - "high": 0, - "low": 32767 - } - } - ], - "object": "i64" - }, - { - "type": "Instr", - "id": "and", - "args": [], - "object": "i64" - }, - { - "type": "Instr", - "id": "get_local", - "args": [ - { - "type": "NumberLiteral", - "value": 0, - "raw": "0" - } - ], - "loc": { - "start": { - "line": -1, - "column": 73 - }, - "end": { - "line": -1, - "column": 75 - } - } - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "LongNumberLiteral", - "value": { - "high": 0, - "low": 32768 - } - } - ], - "object": "i64" - }, - { - "type": "Instr", - "id": "and", - "args": [], - "object": "i64" - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "LongNumberLiteral", - "value": { - "high": 0, - "low": 0 - } - } - ], - "object": "i64" - }, - { - "type": "Instr", - "id": "ne", - "args": [], - "object": "i64" - }, - { - "type": "Instr", - "id": "select", - "args": [], - "loc": { - "start": { - "line": -1, - "column": 83 - }, - "end": { - "line": -1, - "column": 84 - } - } - } - ], - "loc": { - "start": { - "line": -1, - "column": 57 - }, - "end": { - "line": -1, - "column": 85 - } - }, - "metadata": { - "bodySize": 27 - } -} \ No newline at end of file diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.ts b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.ts deleted file mode 100644 index 8006941e7..000000000 --- a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Polyfill for i64_extend16_s instruction - */ -export function i64_extend16_s(x : i64) : i64 { - return (x & 0x0000000000008000) ? (x | 0xffffffffffff8000) : (x & 0x0000000000007fff); -} diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.wast b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.wast new file mode 100644 index 000000000..9d2654bd8 --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.wast @@ -0,0 +1,18 @@ +(module + (type (func (param i64) (result i64))) + (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s/i64_extend16_s (param i64) (result i64) + (get_local 0) + (i64.const -32768) + (i64.or) + (get_local 0) + (i64.const 32767) + (i64.and) + (get_local 0) + (i64.const 32768) + (i64.and) + (i64.const 0) + (i64.ne) + (select) + ) + (export "i64_extend16_s" (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s/i64_extend16_s)) +) diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.json b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.json deleted file mode 100644 index 9ebcd68be..000000000 --- a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.json +++ /dev/null @@ -1,191 +0,0 @@ -{ - "type": "Func", - "name": { - "type": "Identifier", - "value": "packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s/i64_extend32_s" - }, - "signature": { - "type": "Signature", - "params": [ - { - "valtype": "i64" - } - ], - "results": [ - "i64" - ] - }, - "body": [ - { - "type": "Instr", - "id": "get_local", - "args": [ - { - "type": "NumberLiteral", - "value": 0, - "raw": "0" - } - ], - "loc": { - "start": { - "line": -1, - "column": 59 - }, - "end": { - "line": -1, - "column": 61 - } - } - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "LongNumberLiteral", - "value": { - "high": -1, - "low": 2147483648 - } - } - ], - "object": "i64" - }, - { - "type": "Instr", - "id": "or", - "args": [], - "object": "i64" - }, - { - "type": "Instr", - "id": "get_local", - "args": [ - { - "type": "NumberLiteral", - "value": 0, - "raw": "0" - } - ], - "loc": { - "start": { - "line": -1, - "column": 68 - }, - "end": { - "line": -1, - "column": 70 - } - } - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "LongNumberLiteral", - "value": { - "high": 0, - "low": 2147483647 - } - } - ], - "object": "i64" - }, - { - "type": "Instr", - "id": "and", - "args": [], - "object": "i64" - }, - { - "type": "Instr", - "id": "get_local", - "args": [ - { - "type": "NumberLiteral", - "value": 0, - "raw": "0" - } - ], - "loc": { - "start": { - "line": -1, - "column": 77 - }, - "end": { - "line": -1, - "column": 79 - } - } - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "LongNumberLiteral", - "value": { - "high": 0, - "low": 2147483648 - } - } - ], - "object": "i64" - }, - { - "type": "Instr", - "id": "and", - "args": [], - "object": "i64" - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "LongNumberLiteral", - "value": { - "high": 0, - "low": 0 - } - } - ], - "object": "i64" - }, - { - "type": "Instr", - "id": "ne", - "args": [], - "object": "i64" - }, - { - "type": "Instr", - "id": "select", - "args": [], - "loc": { - "start": { - "line": -1, - "column": 89 - }, - "end": { - "line": -1, - "column": 90 - } - } - } - ], - "loc": { - "start": { - "line": -1, - "column": 57 - }, - "end": { - "line": -1, - "column": 91 - } - }, - "metadata": { - "bodySize": 33 - } -} \ No newline at end of file diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.ts b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.ts deleted file mode 100644 index bb34531e3..000000000 --- a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Polyfill for i64_extend32_s instruction - */ -export function i64_extend32_s(x : i64) : i64 { - return (x & 0x0000000080000000) ? (x | 0xffffffff80000000) : (x & 0x000000007fffffff); -} diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.wast b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.wast new file mode 100644 index 000000000..c7af935d5 --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.wast @@ -0,0 +1,18 @@ +(module + (type (func (param i64) (result i64))) + (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s/i64_extend32_s (param i64) (result i64) + (get_local 0) + (i64.const -2147483648) + (i64.or) + (get_local 0) + (i64.const 2147483647) + (i64.and) + (get_local 0) + (i64.const 2147483648) + (i64.and) + (i64.const 0) + (i64.ne) + (select) + ) + (export "i64_extend32_s" (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s/i64_extend32_s)) +) diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.json b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.json deleted file mode 100644 index afbe894a9..000000000 --- a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.json +++ /dev/null @@ -1,191 +0,0 @@ -{ - "type": "Func", - "name": { - "type": "Identifier", - "value": "packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s/i64_extend8_s" - }, - "signature": { - "type": "Signature", - "params": [ - { - "valtype": "i64" - } - ], - "results": [ - "i64" - ] - }, - "body": [ - { - "type": "Instr", - "id": "get_local", - "args": [ - { - "type": "NumberLiteral", - "value": 0, - "raw": "0" - } - ], - "loc": { - "start": { - "line": -1, - "column": 58 - }, - "end": { - "line": -1, - "column": 60 - } - } - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "LongNumberLiteral", - "value": { - "high": -1, - "low": 4294967168 - } - } - ], - "object": "i64" - }, - { - "type": "Instr", - "id": "or", - "args": [], - "object": "i64" - }, - { - "type": "Instr", - "id": "get_local", - "args": [ - { - "type": "NumberLiteral", - "value": 0, - "raw": "0" - } - ], - "loc": { - "start": { - "line": -1, - "column": 64 - }, - "end": { - "line": -1, - "column": 66 - } - } - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "LongNumberLiteral", - "value": { - "high": 0, - "low": 127 - } - } - ], - "object": "i64" - }, - { - "type": "Instr", - "id": "and", - "args": [], - "object": "i64" - }, - { - "type": "Instr", - "id": "get_local", - "args": [ - { - "type": "NumberLiteral", - "value": 0, - "raw": "0" - } - ], - "loc": { - "start": { - "line": -1, - "column": 70 - }, - "end": { - "line": -1, - "column": 72 - } - } - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "LongNumberLiteral", - "value": { - "high": 0, - "low": 128 - } - } - ], - "object": "i64" - }, - { - "type": "Instr", - "id": "and", - "args": [], - "object": "i64" - }, - { - "type": "Instr", - "id": "const", - "args": [ - { - "type": "LongNumberLiteral", - "value": { - "high": 0, - "low": 0 - } - } - ], - "object": "i64" - }, - { - "type": "Instr", - "id": "ne", - "args": [], - "object": "i64" - }, - { - "type": "Instr", - "id": "select", - "args": [], - "loc": { - "start": { - "line": -1, - "column": 79 - }, - "end": { - "line": -1, - "column": 80 - } - } - } - ], - "loc": { - "start": { - "line": -1, - "column": 56 - }, - "end": { - "line": -1, - "column": 81 - } - }, - "metadata": { - "bodySize": 24 - } -} \ No newline at end of file diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.ts b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.ts deleted file mode 100644 index d8c7f338c..000000000 --- a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Polyfill for i64_extend8_s instruction - */ -export function i64_extend8_s(x : i64) : i64 { - return (x & 0x0000000000000080) ? (x | 0xffffffffffffff80) : (x & 0x000000000000007f); -} diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.wast b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.wast new file mode 100644 index 000000000..75bc02b22 --- /dev/null +++ b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.wast @@ -0,0 +1,18 @@ +(module + (type (func (param i64) (result i64))) + (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s/i64_extend8_s (param i64) (result i64) + (get_local 0) + (i64.const -128) + (i64.or) + (get_local 0) + (i64.const 127) + (i64.and) + (get_local 0) + (i64.const 128) + (i64.and) + (i64.const 0) + (i64.ne) + (select) + ) + (export "i64_extend8_s" (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s/i64_extend8_s)) +) diff --git a/scripts/build.sh b/scripts/build.sh index c69c37d1b..99f964870 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -7,7 +7,6 @@ cd $ROOT_DIR OPTS="$@" sh ./scripts/generate-ast-utils.sh -./scripts/generate-polyfills.js if [ -z "$DISABLE_FUZZER_TEST" ]; then yarn --cwd ./packages/floating-point-hex-parser run build-fuzzer diff --git a/scripts/generate-polyfills.js b/scripts/generate-polyfills.js deleted file mode 100755 index 3b0fbddc4..000000000 --- a/scripts/generate-polyfills.js +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env node - -const asc = require("assemblyscript/cli/asc") -const { decode } = require("../packages/wasm-parser/lib/"); - -const { readFileSync, writeFileSync, copyFileSync } = require("fs"); - -const path = require("path"); -const mkdirp = require("mkdirp"); - -const instructions = ["i32_extend8_s", "i32_extend16_s", "i64_extend8_s", "i64_extend16_s", "i64_extend32_s"]; - -instructions.forEach(instr => { - console.log(`Generating polyfill for ${instr}...`) - asc.main( - [ - `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.ts`, - "--binaryFile", - `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.wasm`, - "--optimize" - ], - { - stdout: process.stdout, - stderr: process.stderr - }, - function(err) { - if (err) throw err; - - console.log("Successfuly compiled polyfill from TypeScript to wasm.") - - const wasmFile = readFileSync( - `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.wasm` - ); - - const ast = decode(wasmFile); - const funcAst = ast.body[0].fields.filter(f => f.type === "Func")[0]; - - console.log("Successfuly decoded wasm polyfill into AST.") - - mkdirp( - path.resolve("./packages/proposal-sign-extension-ops/src/polyfills") - ); - - writeFileSync( - path.resolve( - `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.json` - ), - JSON.stringify(funcAst, null, 2) - ); - - copyFileSync( - path.resolve( - `./packages/proposal-sign-extension-ops/src/polyfills/${instr}.json` - ), - path.resolve( - `./packages/proposal-sign-extension-ops/lib/polyfills/${instr}.json` - ) - ); - - console.log("Successfuly stored JSON source for polyfill.") - } - ); -}); - From 2c07ba090cc0d8ed424fdfb4dae7edbe08d7ed48 Mon Sep 17 00:00:00 2001 From: Mauro Bringolf Date: Fri, 1 Jun 2018 22:35:19 +0200 Subject: [PATCH 12/13] Implement functional tests for i32 polyfills --- .../proposal-sign-extension-ops/package.json | 3 +- .../proposal-sign-extension-ops/test/exec.js | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 packages/proposal-sign-extension-ops/test/exec.js diff --git a/packages/proposal-sign-extension-ops/package.json b/packages/proposal-sign-extension-ops/package.json index 88a00d6b7..6555a2358 100644 --- a/packages/proposal-sign-extension-ops/package.json +++ b/packages/proposal-sign-extension-ops/package.json @@ -29,6 +29,7 @@ "@webassemblyjs/helper-test-framework": "1.5.6", "@webassemblyjs/wast-parser": "1.5.6", "@webassemblyjs/wasm-parser": "1.5.6", - "@webassemblyjs/wast-printer": "1.5.6" + "@webassemblyjs/wast-printer": "1.5.6", + "wabt": "1.0.0" } } diff --git a/packages/proposal-sign-extension-ops/test/exec.js b/packages/proposal-sign-extension-ops/test/exec.js new file mode 100644 index 000000000..034d85ac4 --- /dev/null +++ b/packages/proposal-sign-extension-ops/test/exec.js @@ -0,0 +1,54 @@ +const path = require("path"); +const wabt = require("wabt"); +const assert = require("assert"); + +const { readFileSync } = require("fs"); + +const polyfills = [ + { + name: "i32_extend8_s", + fixtures: [ + [0, 0], + [0x7f, 127], + [0x80, -128], + [0xff, -1], + [0x01234500, 0], + [0xfedcba80, -0x80], + [-1, -1] + ] + }, + { + name: "i32_extend16_s", + fixtures: [ + [0, 0], + [0x7fff, 32767], + [0x8000, -32768], + [0xffff, -1], + [0x01230000, 0], + [0xfedc8000, -0x8000], + [-1, -1] + ] + } +]; + +polyfills.forEach(p => { + p.path = path.join(__dirname, `../lib/polyfills/${p.name}.wast`); +}); + +polyfills.forEach(polyfill => { + describe(polyfill.path, () => { + const wast = readFileSync(polyfill.path, "utf8").trim(); + const wasm = wabt + .parseWat(polyfill.path, wast) + .toBinary({ write_debug_names: false }); + + it("should return correct values", () => { + return WebAssembly.instantiate(wasm.buffer).then(result => { + const polyfillFn = result.instance.exports[polyfill.name]; + polyfill.fixtures.forEach(([input, output]) => { + assert.equal(output, polyfillFn(input)); + }); + }); + }); + }); +}); From fb971f112a0f7b2473348fc85b98295cd2edf0c9 Mon Sep 17 00:00:00 2001 From: Mauro Bringolf Date: Mon, 4 Jun 2018 17:22:56 +0200 Subject: [PATCH 13/13] Replace generated wast identifiers with short ones --- .../src/polyfills/i32_extend16_s.wast | 4 ++-- .../src/polyfills/i32_extend8_s.wast | 4 ++-- .../src/polyfills/i64_extend16_s.wast | 4 ++-- .../src/polyfills/i64_extend32_s.wast | 4 ++-- .../src/polyfills/i64_extend8_s.wast | 4 ++-- .../proposal-sign-extension-ops/test/wast/mixed/output.wast | 5 ++--- .../wast/multiple-instruction-i32_extend16_s/output.wast | 3 +-- .../test/wast/multiple-instruction-i32_extend8_s/output.wast | 3 +-- .../test/wast/single-instruction-i32_extend16_s/output.wast | 3 +-- .../test/wast/single-instruction-i32_extend8_s/output.wast | 3 +-- .../test/wast/single-instruction-i64_extend16_s/output.wast | 2 +- .../test/wast/single-instruction-i64_extend32_s/output.wast | 2 +- .../test/wast/single-instruction-i64_extend8_s/output.wast | 2 +- 13 files changed, 19 insertions(+), 24 deletions(-) diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.wast b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.wast index c68f98fa3..45a3fb183 100644 --- a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.wast +++ b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s.wast @@ -1,6 +1,6 @@ (module (type (func (param i32) (result i32))) - (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s/i32_extend16_s (param i32) (result i32) + (func $i32_extend16_s (param i32) (result i32) (get_local 0) (i32.const -32768) (i32.or) @@ -12,5 +12,5 @@ (i32.and) (select) ) - (export "i32_extend16_s" (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s/i32_extend16_s)) + (export "i32_extend16_s" (func $i32_extend16_s)) ) diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.wast b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.wast index 617bcfa6c..78a7712a1 100644 --- a/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.wast +++ b/packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s.wast @@ -1,6 +1,6 @@ (module (type (func (param i32) (result i32))) - (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s/i32_extend8_s (param i32) (result i32) + (func $i32_extend8_s (param i32) (result i32) (get_local 0) (i32.const -128) (i32.or) @@ -12,5 +12,5 @@ (i32.and) (select) ) - (export "i32_extend8_s" (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s/i32_extend8_s)) + (export "i32_extend8_s" (func $i32_extend8_s)) ) diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.wast b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.wast index 9d2654bd8..ac52c000b 100644 --- a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.wast +++ b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s.wast @@ -1,6 +1,6 @@ (module (type (func (param i64) (result i64))) - (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s/i64_extend16_s (param i64) (result i64) + (func $i64_extend16_s (param i64) (result i64) (get_local 0) (i64.const -32768) (i64.or) @@ -14,5 +14,5 @@ (i64.ne) (select) ) - (export "i64_extend16_s" (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s/i64_extend16_s)) + (export "i64_extend16_s" (func $i64_extend16_s)) ) diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.wast b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.wast index c7af935d5..648d6b635 100644 --- a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.wast +++ b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s.wast @@ -1,6 +1,6 @@ (module (type (func (param i64) (result i64))) - (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s/i64_extend32_s (param i64) (result i64) + (func $i64_extend32_s (param i64) (result i64) (get_local 0) (i64.const -2147483648) (i64.or) @@ -14,5 +14,5 @@ (i64.ne) (select) ) - (export "i64_extend32_s" (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s/i64_extend32_s)) + (export "i64_extend32_s" (func $i64_extend32_s)) ) diff --git a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.wast b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.wast index 75bc02b22..04cd1a2dc 100644 --- a/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.wast +++ b/packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s.wast @@ -1,6 +1,6 @@ (module (type (func (param i64) (result i64))) - (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s/i64_extend8_s (param i64) (result i64) + (func $i64_extend8_s (param i64) (result i64) (get_local 0) (i64.const -128) (i64.or) @@ -14,5 +14,5 @@ (i64.ne) (select) ) - (export "i64_extend8_s" (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s/i64_extend8_s)) + (export "i64_extend8_s" (func $i64_extend8_s)) ) diff --git a/packages/proposal-sign-extension-ops/test/wast/mixed/output.wast b/packages/proposal-sign-extension-ops/test/wast/mixed/output.wast index 3d62f292d..827a06c5b 100644 --- a/packages/proposal-sign-extension-ops/test/wast/mixed/output.wast +++ b/packages/proposal-sign-extension-ops/test/wast/mixed/output.wast @@ -11,7 +11,7 @@ (get_local 0) (call 4) ) - (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s/i32_extend16_s (param i32) (result i32) + (func $i32_extend16_s (param i32) (result i32) (get_local 0) (i32.const -32768) (i32.or) @@ -23,7 +23,7 @@ (i32.and) (select) ) - (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s/i32_extend8_s (param i32) (result i32) + (func $i32_extend8_s (param i32) (result i32) (get_local 0) (i32.const -128) (i32.or) @@ -36,4 +36,3 @@ (select) ) ) - diff --git a/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend16_s/output.wast b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend16_s/output.wast index c85516bee..13f198a7b 100644 --- a/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend16_s/output.wast +++ b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend16_s/output.wast @@ -10,7 +10,7 @@ (get_local 0) (call 3) ) - (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s/i32_extend16_s (param i32) (result i32) + (func $i32_extend16_s (param i32) (result i32) (get_local 0) (i32.const -32768) (i32.or) @@ -23,4 +23,3 @@ (select) ) ) - diff --git a/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend8_s/output.wast b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend8_s/output.wast index 99ac3cd76..f07f0095c 100644 --- a/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend8_s/output.wast +++ b/packages/proposal-sign-extension-ops/test/wast/multiple-instruction-i32_extend8_s/output.wast @@ -11,7 +11,7 @@ (get_local 0) (call 3) ) - (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s/i32_extend8_s (param i32) (result i32) + (func $i32_extend8_s (param i32) (result i32) (get_local 0) (i32.const -128) (i32.or) @@ -24,4 +24,3 @@ (select) ) ) - diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend16_s/output.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend16_s/output.wast index 252b049e0..6a69176ba 100644 --- a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend16_s/output.wast +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend16_s/output.wast @@ -3,7 +3,7 @@ (get_local 0) (call 1) ) - (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend16_s/i32_extend16_s (param i32) (result i32) + (func $i32_extend16_s (param i32) (result i32) (get_local 0) (i32.const -32768) (i32.or) @@ -16,4 +16,3 @@ (select) ) ) - diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend8_s/output.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend8_s/output.wast index 957051cd4..ffb292095 100644 --- a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend8_s/output.wast +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i32_extend8_s/output.wast @@ -3,7 +3,7 @@ (get_local 0) (call 1) ) - (func $packages/proposal-sign-extension-ops/src/polyfills/i32_extend8_s/i32_extend8_s (param i32) (result i32) + (func $i32_extend8_s (param i32) (result i32) (get_local 0) (i32.const -128) (i32.or) @@ -16,4 +16,3 @@ (select) ) ) - diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend16_s/output.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend16_s/output.wast index e9dc10830..8bcfd45c4 100644 --- a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend16_s/output.wast +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend16_s/output.wast @@ -3,7 +3,7 @@ (get_local 0) (call 1) ) - (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend16_s/i64_extend16_s (param i64) (result i64) + (func $i64_extend16_s (param i64) (result i64) (get_local 0) (i64.const -32768) (i64.or) diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend32_s/output.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend32_s/output.wast index e99ceda79..455693bc5 100644 --- a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend32_s/output.wast +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend32_s/output.wast @@ -3,7 +3,7 @@ (get_local 0) (call 1) ) - (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend32_s/i64_extend32_s (param i64) (result i64) + (func $i64_extend32_s (param i64) (result i64) (get_local 0) (i64.const -2147483648) (i64.or) diff --git a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend8_s/output.wast b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend8_s/output.wast index 2aeee71ae..91c2628c0 100644 --- a/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend8_s/output.wast +++ b/packages/proposal-sign-extension-ops/test/wast/single-instruction-i64_extend8_s/output.wast @@ -3,7 +3,7 @@ (get_local 0) (call 1) ) - (func $packages/proposal-sign-extension-ops/src/polyfills/i64_extend8_s/i64_extend8_s (param i64) (result i64) + (func $i64_extend8_s (param i64) (result i64) (get_local 0) (i64.const -128) (i64.or)