Skip to content

Commit

Permalink
wasm2c: run multi-memory tests
Browse files Browse the repository at this point in the history
This runs and passes 5 of the 9 multi-memory tests (although
one of them, binary.wast, is a nop for wasm2c itself).

The other 4 tests would require reference types or bulk memory:

	imports.wast
	load.wast
	memory-multi.wast
	store.wast
  • Loading branch information
keithw authored and yhdengh committed Feb 18, 2022
1 parent a8f401d commit 31889d1
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/tools/wasm2c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ static const char s_description[] =
$ wasm2c test.wasm --no-debug-names -o test.c
)";

static const std::string supported_features[] = {"multi-memory"};

static bool IsFeatureSupported(const std::string& feature) {
return std::find(std::begin(supported_features), std::end(supported_features),
feature) != std::end(supported_features);
};

static void ParseOptions(int argc, char** argv) {
OptionParser parser("wasm2c", s_description);

Expand All @@ -80,15 +87,15 @@ static void ParseOptions(int argc, char** argv) {
});
parser.Parse(argc, argv);

// TODO(binji): currently wasm2c doesn't support any non-default feature
// flags.
bool any_non_default_feature = false;
#define WABT_FEATURE(variable, flag, default_, help) \
any_non_default_feature |= (s_features.variable##_enabled() != default_);
bool any_non_supported_feature = false;
#define WABT_FEATURE(variable, flag, default_, help) \
any_non_supported_feature |= \
(s_features.variable##_enabled() != default_) && \
!IsFeatureSupported(flag);
#include "src/feature.def"
#undef WABT_FEATURE

if (any_non_default_feature) {
if (any_non_supported_feature) {
fprintf(stderr,
"wasm2c currently only supports a fixed set of features.\n");
exit(1);
Expand Down
7 changes: 6 additions & 1 deletion test/run-spec-wasm2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ def main(args):
help='print the commands that are run.',
action='store_true')
parser.add_argument('file', help='wast file.')
parser.add_argument('--enable-multi-memory', action='store_true')
options = parser.parse_args(args)

with utils.TempDirectory(options.out_dir, 'run-spec-wasm2c-') as out_dir:
Expand All @@ -385,7 +386,9 @@ def main(args):
find_exe.GetWast2JsonExecutable(options.bindir),
error_cmdline=options.error_cmdline)
wast2json.verbose = options.print_cmd
wast2json.AppendOptionalArgs({'-v': options.verbose})
wast2json.AppendOptionalArgs({
'-v': options.verbose,
'--enable-multi-memory': options.enable_multi_memory})

json_file_path = utils.ChangeDir(
utils.ChangeExt(options.file, '.json'), out_dir)
Expand All @@ -395,6 +398,8 @@ def main(args):
find_exe.GetWasm2CExecutable(options.bindir),
error_cmdline=options.error_cmdline)
wasm2c.verbose = options.print_cmd
wasm2c.AppendOptionalArgs({
'--enable-multi-memory': options.enable_multi_memory})

cc = utils.Executable(options.cc, *options.cflags)
cc.verbose = options.print_cmd
Expand Down
6 changes: 6 additions & 0 deletions test/wasm2c/spec/multi-memory/binary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;;; TOOL: run-spec-wasm2c
;;; STDIN_FILE: third_party/testsuite/proposals/multi-memory/binary.wast
;;; ARGS*: --enable-multi-memory
(;; STDOUT ;;;
0/0 tests passed.
;;; STDOUT ;;)
6 changes: 6 additions & 0 deletions test/wasm2c/spec/multi-memory/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;;; TOOL: run-spec-wasm2c
;;; STDIN_FILE: third_party/testsuite/proposals/multi-memory/data.wast
;;; ARGS*: --enable-multi-memory
(;; STDOUT ;;;
14/14 tests passed.
;;; STDOUT ;;)
6 changes: 6 additions & 0 deletions test/wasm2c/spec/multi-memory/memory.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;;; TOOL: run-spec-wasm2c
;;; STDIN_FILE: third_party/testsuite/proposals/multi-memory/memory.wast
;;; ARGS*: --enable-multi-memory
(;; STDOUT ;;;
45/45 tests passed.
;;; STDOUT ;;)
6 changes: 6 additions & 0 deletions test/wasm2c/spec/multi-memory/memory_grow.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;;; TOOL: run-spec-wasm2c
;;; STDIN_FILE: third_party/testsuite/proposals/multi-memory/memory_grow.wast
;;; ARGS*: --enable-multi-memory
(;; STDOUT ;;;
131/131 tests passed.
;;; STDOUT ;;)
6 changes: 6 additions & 0 deletions test/wasm2c/spec/multi-memory/memory_size.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;;; TOOL: run-spec-wasm2c
;;; STDIN_FILE: third_party/testsuite/proposals/multi-memory/memory_size.wast
;;; ARGS*: --enable-multi-memory
(;; STDOUT ;;;
40/40 tests passed.
;;; STDOUT ;;)

0 comments on commit 31889d1

Please sign in to comment.