Skip to content

Commit e06fc14

Browse files
authored
Allow all features on wasm2js and add atomic tests (WebAssembly#2311)
This adds `-all` argument to wasm2js testing and fixes wasm2js to actually take that argument (currently it doesn't, when it takes a wast file). This also adds a wasm2js test for `atomic.fence` instruction that was added in WebAssembly#2307.
1 parent cb0b31a commit e06fc14

6 files changed

Lines changed: 113 additions & 15 deletions

File tree

scripts/test/wasm2js.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_wasm2js_output():
6161
for module, asserts in split_wast(t):
6262
write_wast('split.wast', module, asserts)
6363

64-
cmd = WASM2JS + ['split.wast']
64+
cmd = WASM2JS + ['split.wast', '-all']
6565
if opt:
6666
cmd += ['-O']
6767
if 'emscripten' in wasm:
@@ -110,7 +110,7 @@ def test_asserts_output():
110110
traps_expected_file = os.path.join(options.binaryen_test, traps)
111111

112112
wasm = os.path.join(wasm2js_dir, wasm)
113-
cmd = WASM2JS + [wasm, '--allow-asserts']
113+
cmd = WASM2JS + [wasm, '--allow-asserts', '-all']
114114
out = run_command(cmd)
115115
fail_if_not_identical_to_file(out, asserts_expected_file)
116116

@@ -157,7 +157,7 @@ def update_wasm2js_tests():
157157
for module, asserts in split_wast(t):
158158
write_wast('split.wast', module, asserts)
159159

160-
cmd = WASM2JS + ['split.wast']
160+
cmd = WASM2JS + ['split.wast', '-all']
161161
if opt:
162162
cmd += ['-O']
163163
if 'emscripten' in wasm:
@@ -176,7 +176,7 @@ def update_wasm2js_tests():
176176
asserts_expected_file = os.path.join(options.binaryen_test, asserts)
177177
traps_expected_file = os.path.join(options.binaryen_test, traps)
178178

179-
cmd = WASM2JS + [os.path.join(wasm2js_dir, wasm), '--allow-asserts']
179+
cmd = WASM2JS + [os.path.join(wasm2js_dir, wasm), '--allow-asserts', '-all']
180180
out = run_command(cmd)
181181
with open(asserts_expected_file, 'w') as o:
182182
o.write(out)

src/support/command-line.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ class Options {
5252
void parse(int argc, const char* argv[]);
5353

5454
private:
55-
Options() = delete;
56-
Options(const Options&) = delete;
57-
Options& operator=(const Options&) = delete;
58-
5955
struct Option {
6056
std::string longName;
6157
std::string shortName;

src/tools/wasm2js.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ class AssertionEmitter {
517517
SExpressionWasmBuilder& sexpBuilder,
518518
Output& out,
519519
Wasm2JSBuilder::Flags flags,
520-
PassOptions options)
520+
const ToolOptions& options)
521521
: root(root), sexpBuilder(sexpBuilder), out(out), flags(flags),
522522
options(options) {}
523523

@@ -528,7 +528,7 @@ class AssertionEmitter {
528528
SExpressionWasmBuilder& sexpBuilder;
529529
Output& out;
530530
Wasm2JSBuilder::Flags flags;
531-
PassOptions options;
531+
ToolOptions options;
532532
Module tempAllocationModule;
533533

534534
Ref emitAssertReturnFunc(Builder& wasmBuilder,
@@ -547,7 +547,7 @@ class AssertionEmitter {
547547
void fixCalls(Ref asmjs, Name asmModule);
548548

549549
Ref processFunction(Function* func) {
550-
Wasm2JSBuilder sub(flags, options);
550+
Wasm2JSBuilder sub(flags, options.passOptions);
551551
return sub.processStandaloneFunction(&tempAllocationModule, func);
552552
}
553553

@@ -771,8 +771,9 @@ void AssertionEmitter::emit() {
771771
Name funcName(funcNameS.str().c_str());
772772
asmModule = Name(moduleNameS.str().c_str());
773773
Module wasm;
774+
options.applyFeatures(wasm);
774775
SExpressionWasmBuilder builder(wasm, e);
775-
emitWasm(wasm, out, flags, options, funcName);
776+
emitWasm(wasm, out, flags, options.passOptions, funcName);
776777
continue;
777778
}
778779
if (!isAssertHandled(e)) {
@@ -859,6 +860,7 @@ int main(int argc, const char* argv[]) {
859860

860861
Element* root = nullptr;
861862
Module wasm;
863+
options.applyFeatures(wasm);
862864
Ref js;
863865
std::unique_ptr<SExpressionParser> sexprParser;
864866
std::unique_ptr<SExpressionWasmBuilder> sexprBuilder;
@@ -882,7 +884,6 @@ int main(int argc, const char* argv[]) {
882884
ModuleReader reader;
883885
reader.setDebug(options.debug);
884886
reader.read(input, wasm, "");
885-
options.applyFeatures(wasm);
886887
} else {
887888
auto input(read_file<std::vector<char>>(options.extra["infile"],
888889
Flags::Text,
@@ -921,8 +922,7 @@ int main(int argc, const char* argv[]) {
921922
Flags::Text,
922923
options.debug ? Flags::Debug : Flags::Release);
923924
if (!binaryInput && options.extra["asserts"] == "1") {
924-
AssertionEmitter(*root, *sexprBuilder, output, flags, options.passOptions)
925-
.emit();
925+
AssertionEmitter(*root, *sexprBuilder, output, flags, options).emit();
926926
} else {
927927
emitWasm(wasm, output, flags, options.passOptions, "asmFunc");
928928
}

test/wasm2js/atomic_fence.2asm.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
function asmFunc(global, env, buffer) {
3+
var HEAP8 = new global.Int8Array(buffer);
4+
var HEAP16 = new global.Int16Array(buffer);
5+
var HEAP32 = new global.Int32Array(buffer);
6+
var HEAPU8 = new global.Uint8Array(buffer);
7+
var HEAPU16 = new global.Uint16Array(buffer);
8+
var HEAPU32 = new global.Uint32Array(buffer);
9+
var HEAPF32 = new global.Float32Array(buffer);
10+
var HEAPF64 = new global.Float64Array(buffer);
11+
var Math_imul = global.Math.imul;
12+
var Math_fround = global.Math.fround;
13+
var Math_abs = global.Math.abs;
14+
var Math_clz32 = global.Math.clz32;
15+
var Math_min = global.Math.min;
16+
var Math_max = global.Math.max;
17+
var Math_floor = global.Math.floor;
18+
var Math_ceil = global.Math.ceil;
19+
var Math_sqrt = global.Math.sqrt;
20+
var abort = env.abort;
21+
var nan = global.NaN;
22+
var infinity = global.Infinity;
23+
function $0() {
24+
25+
}
26+
27+
var FUNCTION_TABLE = [];
28+
function __wasm_memory_grow(pagesToAdd) {
29+
pagesToAdd = pagesToAdd | 0;
30+
var oldPages = __wasm_memory_size() | 0;
31+
var newPages = oldPages + pagesToAdd | 0;
32+
if ((oldPages < newPages) && (newPages < 65536)) {
33+
var newBuffer = new ArrayBuffer(Math_imul(newPages, 65536));
34+
var newHEAP8 = new global.Int8Array(newBuffer);
35+
newHEAP8.set(HEAP8);
36+
HEAP8 = newHEAP8;
37+
HEAP8 = new global.Int8Array(newBuffer);
38+
HEAP16 = new global.Int16Array(newBuffer);
39+
HEAP32 = new global.Int32Array(newBuffer);
40+
HEAPU8 = new global.Uint8Array(newBuffer);
41+
HEAPU16 = new global.Uint16Array(newBuffer);
42+
HEAPU32 = new global.Uint32Array(newBuffer);
43+
HEAPF32 = new global.Float32Array(newBuffer);
44+
HEAPF64 = new global.Float64Array(newBuffer);
45+
buffer = newBuffer;
46+
}
47+
return oldPages;
48+
}
49+
50+
function __wasm_memory_size() {
51+
return buffer.byteLength / 65536 | 0;
52+
}
53+
54+
return {
55+
"atomic_fence": $0
56+
};
57+
}
58+
59+
var memasmFunc = new ArrayBuffer(1507328);
60+
var retasmFunc = asmFunc({Math,Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,NaN,Infinity}, {abort:function() { throw new Error('abort'); }},memasmFunc);
61+
export var atomic_fence = retasmFunc.atomic_fence;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
function asmFunc(global, env, buffer) {
3+
var HEAP8 = new global.Int8Array(buffer);
4+
var HEAP16 = new global.Int16Array(buffer);
5+
var HEAP32 = new global.Int32Array(buffer);
6+
var HEAPU8 = new global.Uint8Array(buffer);
7+
var HEAPU16 = new global.Uint16Array(buffer);
8+
var HEAPU32 = new global.Uint32Array(buffer);
9+
var HEAPF32 = new global.Float32Array(buffer);
10+
var HEAPF64 = new global.Float64Array(buffer);
11+
var Math_imul = global.Math.imul;
12+
var Math_fround = global.Math.fround;
13+
var Math_abs = global.Math.abs;
14+
var Math_clz32 = global.Math.clz32;
15+
var Math_min = global.Math.min;
16+
var Math_max = global.Math.max;
17+
var Math_floor = global.Math.floor;
18+
var Math_ceil = global.Math.ceil;
19+
var Math_sqrt = global.Math.sqrt;
20+
var abort = env.abort;
21+
var nan = global.NaN;
22+
var infinity = global.Infinity;
23+
function $0() {
24+
25+
}
26+
27+
var FUNCTION_TABLE = [];
28+
return {
29+
"atomic_fence": $0
30+
};
31+
}
32+
33+
var memasmFunc = new ArrayBuffer(65536);
34+
var retasmFunc = asmFunc({Math,Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,NaN,Infinity}, {abort:function() { throw new Error('abort'); }},memasmFunc);
35+
export var atomic_fence = retasmFunc.atomic_fence;

test/wasm2js/atomic_fence.wast

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(module
2+
(memory $0 (shared 23 256))
3+
(func (export "atomic-fence")
4+
(atomic.fence)
5+
)
6+
)

0 commit comments

Comments
 (0)