Giter Site home page Giter Site logo

webassembly / wabt Goto Github PK

View Code? Open in Web Editor NEW
6.4K 157.0 653.0 23.91 MB

The WebAssembly Binary Toolkit

License: Apache License 2.0

Makefile 0.28% Shell 0.25% Python 5.44% JavaScript 0.57% C++ 85.98% CMake 1.11% C 6.09% WebAssembly 0.12% Lua 0.14%
webassembly

wabt's Introduction

Github CI Status

WABT: The WebAssembly Binary Toolkit

WABT (we pronounce it "wabbit") is a suite of tools for WebAssembly, including:

  • wat2wasm: translate from WebAssembly text format to the WebAssembly binary format
  • wasm2wat: the inverse of wat2wasm, translate from the binary format back to the text format (also known as a .wat)
  • wasm-objdump: print information about a wasm binary. Similiar to objdump.
  • wasm-interp: decode and run a WebAssembly binary file using a stack-based interpreter
  • wasm-decompile: decompile a wasm binary into readable C-like syntax.
  • wat-desugar: parse .wat text form as supported by the spec interpreter (s-expressions, flat syntax, or mixed) and print "canonical" flat format
  • wasm2c: convert a WebAssembly binary file to a C source and header
  • wasm-strip: remove sections of a WebAssembly binary file
  • wasm-validate: validate a file in the WebAssembly binary format
  • wast2json: convert a file in the wasm spec test format to a JSON file and associated wasm binary files
  • wasm-stats: output stats for a module
  • spectest-interp: read a Spectest JSON file, and run its tests in the interpreter

These tools are intended for use in (or for development of) toolchains or other systems that want to manipulate WebAssembly files. Unlike the WebAssembly spec interpreter (which is written to be as simple, declarative and "speccy" as possible), they are written in C/C++ and designed for easier integration into other systems. Unlike Binaryen these tools do not aim to provide an optimization platform or a higher-level compiler target; instead they aim for full fidelity and compliance with the spec (e.g. 1:1 round-trips with no changes to instructions).

Online Demos

Wabt has been compiled to JavaScript via emscripten. Some of the functionality is available in the following demos:

Supported Proposals

  • Proposal: Name and link to the WebAssembly proposal repo
  • flag: Flag to pass to the tool to enable/disable support for the feature
  • default: Whether the feature is enabled by default
  • binary: Whether wabt can read/write the binary format
  • text: Whether wabt can read/write the text format
  • validate: Whether wabt can validate the syntax
  • interpret: Whether wabt can execute these operations in wasm-interp or spectest-interp
  • wasm2c: Whether wasm2c supports these operations
Proposal flag default binary text validate interpret wasm2c
exception handling --enable-exceptions
mutable globals --disable-mutable-globals
nontrapping float-to-int conversions --disable-saturating-float-to-int
sign extension --disable-sign-extension
simd --disable-simd
threads --enable-threads
multi-value --disable-multi-value
tail-call --enable-tail-call
bulk memory --disable-bulk-memory
reference types --disable-reference-types
annotations --enable-annotations
memory64 --enable-memory64
multi-memory --enable-multi-memory
extended-const --enable-extended-const
relaxed-simd --enable-relaxed-simd

Cloning

Clone as normal, but don't forget to get the submodules as well:

$ git clone --recursive https://github.com/WebAssembly/wabt
$ cd wabt
$ git submodule update --init

This will fetch the testsuite and gtest repos, which are needed for some tests.

Building using CMake directly (Linux and macOS)

You'll need CMake. You can then run CMake, the normal way:

$ mkdir build
$ cd build
$ cmake ..
$ cmake --build .

This will produce build files using CMake's default build generator. Read the CMake documentation for more information.

NOTE: You must create a separate directory for the build artifacts (e.g. build above). Running cmake from the repo root directory will not work since the build produces an executable called wasm2c which conflicts with the wasm2c directory.

Building using the top-level Makefile (Linux and macOS)

NOTE: Under the hood, this uses make to run CMake, which then calls ninja to perform that actual build. On some systems (typically macOS), this doesn't build properly. If you see these errors, you can build using CMake directly as described above.

You'll need CMake and Ninja. If you just run make, it will run CMake for you, and put the result in out/clang/Debug/ by default:

Note: If you are on macOS, you will need to use CMake version 3.2 or higher

$ make

This will build the default version of the tools: a debug build using the Clang compiler.

There are many make targets available for other configurations as well. They are generated from every combination of a compiler, build type and configuration.

  • compilers: gcc, clang, gcc-i686, emscripten
  • build types: debug, release
  • configurations: empty, asan, msan, lsan, ubsan, fuzz, no-tests

They are combined with dashes, for example:

$ make clang-debug
$ make gcc-i686-release
$ make clang-debug-lsan
$ make gcc-debug-no-tests

Building (Windows)

You'll need CMake. You'll also need Visual Studio (2015 or newer) or MinGW.

Note: Visual Studio 2017 and later come with CMake (and the Ninja build system) out of the box, and should be on your PATH if you open a Developer Command prompt. See https://aka.ms/cmake for more details.

You can run CMake from the command prompt, or use the CMake GUI tool. See Running CMake for more information.

When running from the commandline, create a new directory for the build artifacts, then run cmake from this directory:

> cd [build dir]
> cmake [wabt project root] -DCMAKE_BUILD_TYPE=[config] -DCMAKE_INSTALL_PREFIX=[install directory] -G [generator]

The [config] parameter should be a CMake build type, typically DEBUG or RELEASE.

The [generator] parameter should be the type of project you want to generate, for example "Visual Studio 14 2015". You can see the list of available generators by running cmake --help.

To build the project, you can use Visual Studio, or you can tell CMake to do it:

> cmake --build [wabt project root] --config [config] --target install

This will build and install to the installation directory you provided above.

So, for example, if you want to build the debug configuration on Visual Studio 2015:

> mkdir build
> cd build
> cmake .. -DCMAKE_BUILD_TYPE=DEBUG -DCMAKE_INSTALL_PREFIX=..\ -G "Visual Studio 14 2015"
> cmake --build . --config DEBUG --target install

Adding new keywords to the lexer

If you want to add new keywords, you'll need to install gperf. Before you upload your PR, please run make update-gperf to update the prebuilt C++ sources in src/prebuilt/.

Running wat2wasm

Some examples:

# parse test.wat and write to .wasm binary file with the same name
$ bin/wat2wasm test.wat

# parse test.wat and write to binary file test.wasm
$ bin/wat2wasm test.wat -o test.wasm

# parse spec-test.wast, and write verbose output to stdout (including the
# meaning of every byte)
$ bin/wat2wasm spec-test.wast -v

You can use --help to get additional help:

$ bin/wat2wasm --help

Or try the online demo.

Running wasm2wat

Some examples:

# parse binary file test.wasm and write text file test.wat
$ bin/wasm2wat test.wasm -o test.wat

# parse test.wasm and write test.wat
$ bin/wasm2wat test.wasm -o test.wat

You can use --help to get additional help:

$ bin/wasm2wat --help

Or try the online demo.

Running wasm-interp

Some examples:

# parse binary file test.wasm, and type-check it
$ bin/wasm-interp test.wasm

# parse test.wasm and run all its exported functions
$ bin/wasm-interp test.wasm --run-all-exports

# parse test.wasm, run the exported functions and trace the output
$ bin/wasm-interp test.wasm --run-all-exports --trace

# parse test.json and run the spec tests
$ bin/wasm-interp test.json --spec

# parse test.wasm and run all its exported functions, setting the value stack
# size to 100 elements
$ bin/wasm-interp test.wasm -V 100 --run-all-exports

You can use --help to get additional help:

$ bin/wasm-interp --help

Running wast2json

See wast2json.md.

Running wasm-decompile

For example:

# parse binary file test.wasm and write text file test.dcmp
$ bin/wasm-decompile test.wasm -o test.dcmp

You can use --help to get additional help:

$ bin/wasm-decompile --help

See decompiler.md for more information on the language being generated.

Running wasm2c

See wasm2c.md

Running the test suite

See test/README.md.

Sanitizers

To build with the LLVM sanitizers, append the sanitizer name to the target:

$ make clang-debug-asan
$ make clang-debug-msan
$ make clang-debug-lsan
$ make clang-debug-ubsan

There are configurations for the Address Sanitizer (ASAN), Memory Sanitizer (MSAN), Leak Sanitizer (LSAN) and Undefined Behavior Sanitizer (UBSAN). You can read about the behaviors of the sanitizers in the link above, but essentially the Address Sanitizer finds invalid memory accesses (use after free, access out-of-bounds, etc.), Memory Sanitizer finds uses of uninitialized memory, the Leak Sanitizer finds memory leaks, and the Undefined Behavior Sanitizer finds undefined behavior (surprise!).

Typically, you'll just want to run all the tests for a given sanitizer:

$ make test-asan

You can also run the tests for a release build:

$ make test-clang-release-asan
...

The GitHub actions bots run all of these tests (and more). Before you land a change, you should run them too. One easy way is to use the test-everything target:

$ make test-everything

Fuzzing

To build using the LLVM fuzzer support, append fuzz to the target:

$ make clang-debug-fuzz

This will produce a wasm2wat_fuzz binary. It can be used to fuzz the binary reader, as well as reproduce fuzzer errors found by oss-fuzz.

$ out/clang/Debug/fuzz/wasm2wat_fuzz ...

See the libFuzzer documentation for more information about how to use this tool.

wabt's People

Contributors

aardappel avatar aheejin avatar alexcrichton avatar alexreinking avatar binji avatar cellule avatar chfast avatar citisolo avatar dschuff avatar jfbastien avatar jgravelle-google avatar karlschimpf avatar keithw avatar lizhengxing avatar marcusb avatar mwilliamson avatar ngzhian avatar nlewycky avatar ohorn avatar remko avatar rrrapha avatar sbc100 avatar shravanrn avatar soniex2 avatar steven-johnson avatar takikawa avatar walkingeyerobot avatar wingo avatar yhdengh avatar zherczeg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wabt's Issues

scripts/download-d8.sh seems broken

I get

Downloading https://storage.googleapis.com/webassembly/v8-native-prototype/7ee0c81f107ab72d6e46d94e0a1d01be7ae56d34/d8...

curl: (22) The requested URL returned error: 404 Not Found

br without continue label

the following
(module (func (loop $a (br $a))) (export "" 0))
(module (func (loop $a $b (br $a))) (export "" 0))
Should generate the same output
However, the first outputs br 0 (infinite loop) and the second outputs br 1 (all is good)

Incorrect code emitted involving unreachable code.

The following code emits a single unreachable operator which does not appear correct. When $i1 is zero this function would return 1.

(module
 (func (param $i1 i32) (result i32)
   (if_else (get_local $i1)
     (block (unreachable))
     (i32.const 1))))
0000004: 02                                         ; WASM_SECTION_FUNCTIONS
0000005: 01                                         ; num functions
; function 0
0000006: 00                                         ; func flags
0000007: 0000                                       ; func signature index
0000009: 0000                                       ; func body size
000000b: 01                                         ; OPCODE_BLOCK
000000c: 01                                         ; num expressions
000000d: 15                                         ; OPCODE_UNREACHABLE
0000009: 0300                                       ; FIXUP func body size
000000e: 06                                         ; WASM_SECTION_END

Some discussion at WebAssembly/design#527

Multiple exports per function being accepted?

The following test from the spec seems to conflict with the v8 encoding which can only have one export per function. Should sexp-wasm signal an error on this? Should the spec be changed to make this invalid?

(module (func (i32.const 1)) (export "a" 0) (export "b" 0))

Dirty repo

Updating sexpr-wasm in a pre-built repo causes the following error:

sexpr directory already exists
subprocess.check_call(`git fetch`, cwd=`/b/build/slave/linux/build/src/src/work/sexpr-wasm-prototype`)
subprocess.check_call(`git checkout origin/master`, cwd=`/b/build/slave/linux/build/src/src/work/sexpr-wasm-prototype`)
error: Your local changes to the following files would be overwritten by checkout:
    src/wasm-flex-lexer.c
Please, commit your changes or stash them before you can switch branches.
Aborting

Are in-tree builds expected to be clean?

br-block-named.txt is incorrect

Specifically:

          (block $inner     ;; 0
            (br $inner)
            (br $outer)))))))

->

0000013: 01                                         ; OPCODE_BLOCK
0000014: 02                                         ; num expressions
0000015: 06                                         ; OPCODE_BR
0000016: 00                                         ; break depth
0000017: 00                                         ; OPCODE_NOP
0000018: 06                                         ; OPCODE_BR
0000019: 04                                         ; break depth
000001a: 00                                         ; OPCODE_NOP

The block has 2 child expressions but four expressions are emitted. When parsing this produces br 0 followed by nop and then the function body has a trailing br 4, nop which is not only an incorrect decoding but invalid (due to the break depth).

Whitespace between function name token and left paren

I have a test that generated the following code, and fed it into sexpr-wasm
(module
(func $foomore(call $foo (i32.const 0x0)) )
(func $foo (param i32)(nop))
)

Note the lack of space between $foomore and its opening paren. Sometime between rev 64fb062 and rev 7601228 this stopped being accepted by the parser, which now issues the following confusing error:
:2:23: expected '(', not "$foo"
It looks like the "(call" is getting sucked into the "$foomore" token.

I don't actually know what the rules of s-expressions are in that case; maybe this is the correct behavior?

Easier method to debug broken d8 tests

Currently if d8 is broken, I just run manually:

out/sexpr-wasm <broken test> -o foo.wasm
gdb --args <d8> test/wasm.js -- foo.wasm

Probably should describe this process in the README. Maybe make it more convenient?

imports dont seem to work

test

(module
  (import $print_i32 "stdio" "print" (param i32))
  (memory 2000000 (segment 8 "0") (segment 16 "world"))
  (export "test" 0)
  (func (result i32)
    (call $print_i32 (i32.const 66))
    (i32.add (i32.const 0xFFF6789b) (i32.const 2))))

result
test.wasm:6:11: undefined function variable "$print_i32

Add tests for `wasmopcodecnt`

I'm worried I might break it as it stands :)

Also, it should probably be added to the top level Makefile so it ends up on the out directory?

Return nop arity

For the following function
(func $return-nop (return (nop))) (https://github.com/WebAssembly/testsuite/blob/master/functions.wast)

There is a conflict between the function type and return arity.
The type of the function is

; type 0
000000f: 40                                         ; function form
0000010: 00                                         ; num params
0000011: 00                                         ; num results

And the function body is the following

; function body 6
00001a0: 00                                         ; func body size (guess)
00001a1: 00                                         ; local decl count
00001a2: 00                                         ; OPCODE_NOP
00001a3: 09                                         ; OPCODE_RETURN
00001a4: 01                                         ; return arity
00001a0: 04                                         ; FIXUP func body size

Since nop is: an empty operator that does not yield a value
then the arity of the return statement should be 0 thus having a valid type.

I found this by running the tests, I am surprised this didn't come up in the CI

tableswitch block depth?

The following code fails to encode with sexp-wasm with: t60.wast:7:37: label variable out of range (max 1)

If an explicit label is added to the tableswitch it succeeds. I've seen other cases where this changes the depths. Does v8 always have an implicit block for a tableswitch? If so then adding an explicit label should make no difference, and if not then how is the difference encoded?

The v8 encoding seems to accept just one expression per case, so emits a block if there are more than one statement. I assume there is some logic to offset the br depths and might it only be in this case that the depths would be modified?

(module
  (func $f1 (param $i i32) (result i32)
    (block $l1
      (i32.add (tableswitch (get_local $i)
                 (table (case $0)) (case $default)
                 (case $0 (br 0 (i32.const 1)))
                 (case $default (br 1 (i32.const 2))))
               (i32.const 3))))
  (export "f1" $f1))
(invoke "f1" (i32.const 0))
(invoke "f1" (i32.const 1))

4 : i32
2 : i32

Runtime Error

This happens when given any *.wasm file

Starting program: /home/null/code/WASM/sexpr-wasm-prototype/out/sexpr-wasm ../test.wasm
*** Error in `/home/null/code/WASM/sexpr-wasm-prototype/out/sexpr-wasm': realloc(): invalid pointer: 0x00007ffff7fc1548 ***
======= Backtrace: =========
/usr/lib/libc.so.6(+0x72055)[0x7ffff7aa9055]
/usr/lib/libc.so.6(+0x779a6)[0x7ffff7aae9a6]
/usr/lib/libc.so.6(realloc+0x1db)[0x7ffff7ab2d0b]
/home/null/code/WASM/sexpr-wasm-prototype/out/sexpr-wasm[0x41ccd5]
/home/null/code/WASM/sexpr-wasm-prototype/out/sexpr-wasm[0x41cd41]
/home/null/code/WASM/sexpr-wasm-prototype/out/sexpr-wasm[0x401990]
/home/null/code/WASM/sexpr-wasm-prototype/out/sexpr-wasm[0x4019ae]
/home/null/code/WASM/sexpr-wasm-prototype/out/sexpr-wasm[0x40c30f]
/home/null/code/WASM/sexpr-wasm-prototype/out/sexpr-wasm[0x40385d]
/usr/lib/libc.so.6(__libc_start_main+0xf0)[0x7ffff7a57610]
/home/null/code/WASM/sexpr-wasm-prototype/out/sexpr-wasm[0x400ff9]
======= Memory map: ========
00400000-00431000 r-xp 00000000 08:03 9838228                            /home/null/code/WASM/sexpr-wasm-prototype/out/sexpr-wasm
00631000-00632000 rw-p 00031000 08:03 9838228                            /home/null/code/WASM/sexpr-wasm-prototype/out/sexpr-wasm
00632000-00653000 rw-p 00000000 00:00 0                                  [heap]
7ffff0000000-7ffff0021000 rw-p 00000000 00:00 0
7ffff0021000-7ffff4000000 ---p 00000000 00:00 0
7ffff7821000-7ffff7837000 r-xp 00000000 08:03 19140025                   /usr/lib/libgcc_s.so.1
7ffff7837000-7ffff7a36000 ---p 00016000 08:03 19140025                   /usr/lib/libgcc_s.so.1
7ffff7a36000-7ffff7a37000 rw-p 00015000 08:03 19140025                   /usr/lib/libgcc_s.so.1
7ffff7a37000-7ffff7bd2000 r-xp 00000000 08:03 19139726                   /usr/lib/libc-2.22.so
7ffff7bd2000-7ffff7dd1000 ---p 0019b000 08:03 19139726                   /usr/lib/libc-2.22.so
7ffff7dd1000-7ffff7dd5000 r--p 0019a000 08:03 19139726                   /usr/lib/libc-2.22.so
7ffff7dd5000-7ffff7dd7000 rw-p 0019e000 08:03 19139726                   /usr/lib/libc-2.22.so
7ffff7dd7000-7ffff7ddb000 rw-p 00000000 00:00 0
7ffff7ddb000-7ffff7dfd000 r-xp 00000000 08:03 19139725                   /usr/lib/ld-2.22.so
7ffff7fbf000-7ffff7fc2000 rw-p 00000000 00:00 0
7ffff7ff6000-7ffff7ff8000 rw-p 00000000 00:00 0
7ffff7ff8000-7ffff7ffa000 r--p 00000000 00:00 0                          [vvar]
7ffff7ffa000-7ffff7ffc000 r-xp 00000000 00:00 0                          [vdso]
7ffff7ffc000-7ffff7ffd000 r--p 00021000 08:03 19139725                   /usr/lib/ld-2.22.so
7ffff7ffd000-7ffff7ffe000 rw-p 00022000 08:03 19139725                   /usr/lib/ld-2.22.so
7ffff7ffe000-7ffff7fff000 rw-p 00000000 00:00 0
7ffffffde000-7ffffffff000 rw-p 00000000 00:00 0                          [stack]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

Program received signal SIGABRT, Aborted.
0x00007ffff7a6a5f8 in raise () from /usr/lib/libc.so.6
(gdb) bt
#0  0x00007ffff7a6a5f8 in raise () from /usr/lib/libc.so.6
#1  0x00007ffff7a6ba7a in abort () from /usr/lib/libc.so.6
#2  0x00007ffff7aa905a in __libc_message () from /usr/lib/libc.so.6
#3  0x00007ffff7aae9a6 in malloc_printerr () from /usr/lib/libc.so.6
#4  0x00007ffff7ab2d0b in realloc () from /usr/lib/libc.so.6
#5  0x000000000041ccd5 in ensure_capacity (data=0x7ffffffeca98, capacity=0x7ffffffecaa8,
    desired_size=2, elt_byte_size=8) at src/wasm-vector.c:16
#6  0x000000000041cd41 in append_element (data=0x7ffffffeca98, size=0x7ffffffecaa0,
        capacity=0x7ffffffecaa8, elt_byte_size=8) at src/wasm-vector.c:28
#7  0x0000000000401990 in wasm_append_import_ptr (vec=0x7ffffffeca98) at src/wasm.c:20
#8  0x00000000004019ae in wasm_append_import_ptr_value (vec=0x7ffffffeca98, value=0x7ffffffec058)
            at src/wasm.c:20
#9  0x000000000040c30f in wasm_parse (scanner=0x632260, parser=0x7fffffffe380) at src/wasm-parser.y:1275
#10 0x000000000040385d in main (argc=2, argv=0x7fffffffe4b8) at src/sexpr-wasm.c:180

Is there a way to force use of prebuilt wasm-bison-parser.[ch] files?

I have a flavor of bison installed, so the new build procedure tries to use it.
Trouble is, it's an older version and cannot consume wasm-bison-parser.y:

sexpr-wasm-prototype/src/wasm-bison-parser.y:101.20-33: error: syntax error, unexpected {...}
make[2]: *** [wasm-bison-parser.c] Error 1

Is there a way to force use of the prebuilt files?

For example, can cmake check the bison version?

Non-community group submodules

One thing we've recently been thinking a lot about on Chakra is our testing story for WebAssembly. I think it would be ideal if we could use this as a submodule, and have our testing build wasts using sexpr-wasm on the fly. This would allow us to run WebAssembly tests through our CI without needing to check in a whole bunch of binary files.

However, what makes me hesitant to do this is that V8 is a submodule of sexpr-wasm, and (for obvious reasons) I'd rather not have V8 as a submodule of ChakraCore. So what do you guys think? Feasible to remove that dependency? Also, I'm wondering how V8 handles wasm testing? Presumably you don't have this as a submodule either (that seems like there would be some weird recursion), so do you check in .wasm files, or something else?

memory exhaustion crash

This file crashes the prototype. crash_sexpre_proto.wast.txt

It crashes with

crash_sexpre_proto.wast:3569:37: memory exhausted
                  (else (if (i32.eq (get_local $jump_dest) (i32.const 16940))

The file is over 50,000 line. I'm generating it with evm2wasm and I added optimization to shink the size. But the source program is huge to start with and I don't think I can make it much smaller on my end.

wasm-interp: block-break type crash.

The following is valid wast but crashes in wasm-interp.

(module
  (func $tst1
    (block
      (block $l (br $l (i32.const 1)) (nop))
      (nop)))

  (export "tst" $tst1)
)

make: no rule to make target 'out'

Anyone else seeing this error?

make: *** No rule to make target out', needed byout/wasm.o'. Stop.

Presumably it's due to the trailing slash in the rule "out/:

I've only seen this on a couple systems, and it may be file system dependent as even on those
systems I don't see this if working in a directory on a different mount.

It's easily worked around by pre-creating out, or locally removing the slash after out in the Makefile, so a fix is by no means urgent or even necessary. But I thought I'd file an issue in case anyone can shed some light as to why this might be happening.

br not accepting a nop?

Seems odd that the v8 encoding requires a nop opcode as fill in br and br_if but sexpr-wasm-prototype will not accept a nop value in the same place?

uncompr.wast:109:11: arity mismatch of br_if value. label expects void, but br value is non-empty

LEB128 question

here is my test code

(module
  (func (result i32)
    (i32.add (i32.const 624485) (i32.const 2))))

LEB of 624485 should be 0xE58E26

But from the prototype if get

; function 0

....

0000014: 0a                                         ; OPCODE_I32_CONST
0000015: 6587 0900                                  ; u32 literal
....

how is 0x65870900 derived?

legacy if

It looks like this prototype is still using the old if. For example this

    (if
      (i32.const 1)
      (br 0)
     )

gets turned into

    (if
      (i32.const 1)
      (block (br 0))
     )

related

Windows build failing due to missing include header

Build on MSVC fails due to missing decl for memcpy. Line 94 at src/wasm-config.h.in,

#elif COMPILER_IS_MSVC

#define WASM_UNUSED
#define WASM_WARN_UNUSED _Check_return_
#define WASM_INLINE __inline
#define WASM_STATIC_ASSERT(x) _STATIC_ASSERT(x)
#define WASM_UNLIKELY(x) (x)
#define WASM_LIKELY(x) (x)
#define WASM_PRINTF_FORMAT(format_arg, first_arg)

__inline unsigned long wasm_clz_u32(unsigned long mask) {
  unsigned long index;
  _BitScanReverse(&index, mask);
  return sizeof(unsigned long) * 8 - (index + 1);
}

__inline unsigned long wasm_clz_u64(unsigned __int64 mask) {
#if _M_X64
  unsigned long index;
  _BitScanReverse64(&index, mask);
  return sizeof(unsigned __int64) * 8 - (index + 1);
#elif _M_IX86
  unsigned long index;
  unsigned long high_mask;
  memcpy(&high_mask, (unsigned char*)&mask + sizeof(unsigned long),
         sizeof(unsigned long));
  if (_BitScanReverse(&index, high_mask)) {
    return sizeof(unsigned long) * 8 - (index + 1);
  }

  unsigned long low_mask;
  memcpy(&low_mask, &mask, sizeof(unsigned long));
  _BitScanReverse(&index, low_mask);
  return sizeof(unsigned __int64) * 8 - (index + 1);
#else
#error unexpected architecture
#endif
}

Issue is fixed by include <string.h>

invalid initial memory size "0\00\"

I get the following error:

foo.wast:2:11: invalid initial memory size "0\00\"
foo.wast:2:17: invalid max memory size "0\00\00\00"

With this input file, it looks like the last segment makes it sad but I have not clue why. Everything seems properly quoted and escaped. It's happy if I remove all the nulls from the last segment. The quote looks well escaped.

(module
  (memory 19448 4294967295
    (segment 8 "\10\01\00\00")
    (segment 16 "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\03 \02 \02 \02 \02 \02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\02\00\01`\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\08\d8\08\d8\08\d8\08\d8\08\d8\08\d8\08\d8\08\d8\08\d8\08\d8\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\08\d5\08\d5\08\d5\08\d5\08\d5\08\d5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\08\c5\04\c0\04\c0\04\c0\04\c0\04\c0\04\c0\08\d6\08\d6\08\d6\08\d6\08\d6\08\d6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\08\c6\04\c0\04\c0\04\c0\04\c0\02\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
    (segment 784 " \05\00\00")
    (segment 800 "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00\02\00\00\00\03\00\00\00\04\00\00\00\05\00\00\00\06\00\00\00\07\00\00\00\08\00\00\00\t\00\00\00\n\00\00\00\0b\00\00\00\0c\00\00\00\0d\00\00\00\0e\00\00\00\0f\00\00\00\10\00\00\00\11\00\00\00\12\00\00\00\13\00\00\00\14\00\00\00\15\00\00\00\16\00\00\00\17\00\00\00\18\00\00\00\19\00\00\00\1a\00\00\00\1b\00\00\00\1c\00\00\00\1d\00\00\00\1e\00\00\00\1f\00\00\00 \00\00\00!\00\00\00\"\00\00\00#\00\00\00$\00\00\00%\00\00\00&\00\00\00\'\00\00\00(\00\00\00)\00\00\00*\00\00\00+\00\00\00,\00\00\00-\00\00\00.\00\00\00/\00\00\000\00\00\001\00\00\002\00\00\003\00\00\004\00\00\005\00\00\006\00\00\007\00\00\008\00\00\009\00\00\00:\00\00\00;\00\00\00<\00\00\00=\00\00\00>\00\00\00?\00\00\00@\00\00\00a\00\00\00b\00\00\00c\00\00\00d\00\00\00e\00\00\00f\00\00\00g\00\00\00h\00\00\00i\00\00\00j\00\00\00k\00\00\00l\00\00\00m\00\00\00n\00\00\00o\00\00\00p\00\00\00q\00\00\00r\00\00\00s\00\00\00t\00\00\00u\00\00\00v\00\00\00w\00\00\00x\00\00\00y\00\00\00z\00\00\00[\00\00\00\\\00\00\00]\00\00\00^\00\00\00_\00\00\00`\00\00\00a\00\00\00b\00\00\00c\00\00\00d\00\00\00e\00\00\00f\00\00\00g\00\00\00h\00\00\00i\00\00\00j\00\00\00k\00\00\00l\00\00\00m\00\00\00n\00\00\00o\00\00\00p\00\00\00q\00\00\00r\00\00\00s\00\00\00t\00\00\00u\00\00\00v\00\00\00w\00\00\00x\00\00\00y\00\00\00z\00\00\00{\00\00\00|\00\00\00}\00\00\00~\00\00\00\7f\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
    (segment 2336 "0\0b\00\00")
    (segment 2352 "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00\02\00\00\00\03\00\00\00\04\00\00\00\05\00\00\00\06\00\00\00\07\00\00\00\08\00\00\00\t\00\00\00\n\00\00\00\0b\00\00\00\0c\00\00\00\0d\00\00\00\0e\00\00\00\0f\00\00\00\10\00\00\00\11\00\00\00\12\00\00\00\13\00\00\00\14\00\00\00\15\00\00\00\16\00\00\00\17\00\00\00\18\00\00\00\19\00\00\00\1a\00\00\00\1b\00\00\00\1c\00\00\00\1d\00\00\00\1e\00\00\00\1f\00\00\00 \00\00\00!\00\00\00\"\00\00\00#\00\00\00$\00\00\00%\00\00\00&\00\00\00\'\00\00\00(\00\00\00)\00\00\00*\00\00\00+\00\00\00,\00\00\00-\00\00\00.\00\00\00/\00\00\000\00\00\001\00\00\002\00\00\003\00\00\004\00\00\005\00\00\006\00\00\007\00\00\008\00\00\009\00\00\00:\00\00\00;\00\00\00<\00\00\00=\00\00\00>\00\00\00?\00\00\00@\00\00\00A\00\00\00B\00\00\00C\00\00\00D\00\00\00E\00\00\00F\00\00\00G\00\00\00H\00\00\00I\00\00\00J\00\00\00K\00\00\00L\00\00\00M\00\00\00N\00\00\00O\00\00\00P\00\00\00Q\00\00\00R\00\00\00S\00\00\00T\00\00\00U\00\00\00V\00\00\00W\00\00\00X\00\00\00Y\00\00\00Z\00\00\00[\00\00\00\\\00\00\00]\00\00\00^\00\00\00_\00\00\00`\00\00\00A\00\00\00B\00\00\00C\00\00\00D\00\00\00E\00\00\00F\00\00\00G\00\00\00H\00\00\00I\00\00\00J\00\00\00K\00\00\00L\00\00\00M\00\00\00N\00\00\00O\00\00\00P\00\00\00Q\00\00\00R\00\00\00S\00\00\00T\00\00\00U\00\00\00V\00\00\00W\00\00\00X\00\00\00Y\00\00\00Z\00\00\00{\00\00\00|\00\00\00}\00\00\00~\00\00\00\7f\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
  )
)

sexpr-wasm can't commute align= offset=

Some of the torture tests fail with this because s2wasm emits them in the opposite order as wasmate, e.g.:

(f64.store align=1 offset=8 (i32.const 0) (f64.const 0))

It would be good to also update store-offset.txt adn load-offset.txt, as well as make sure that the spec repo has the same tests.

s2wasm_known_gcc_test_failures.txt has a list of expected failures. I don't run it on the bots yet (will add this afternoon), to repro:

/s/wasm/experimental/buildbot/assemble_files.py --assembler /s/wasm/experimental/buildbot/work/sexpr-wasm-prototype/out/sexpr-wasm --files /s/wasm/experimental/buildbot/work/s2wasm-out/\*.wast --fails /s/wasm/experimental/buildbot/work/sexpr-wasm-prototype/s2wasm_known_gcc_test_failures.txt --out /s/wasm/experimental/buildbot/work/sexpr-wasm-out/

Convert tests from AST format to new "flat" format

All of the internal tests are written using the old style, but should be converted to the new style, e.g.:

old style:

(func (result i32)
  (local i32)
  (block i32
    (i32.add (i32.const 1) (get_local 0))))

new style:

(func (result i32)
  (local i32)
  block i32
    i32.const 1
    get_local 0
    i32.add
  end)

Possible incorrect alignment encoding for a 64 bit access.

The load access byte on the i64.load below is zero, suggesting it is aligned, but would the natural alignment for a 64 bit load be 8 and not 2, so should it be setting the un-aligned bit in the load access byte?

(module (memory 65536 65536)
 (func $f1 (result i64)
  (i64.load align=2 (i32.const 0))))
; function 0
000000a: 00                                         ; func flags
000000b: 0000                                       ; func signature index
000000d: 0000                                       ; func body size
000000f: 2b                                         ; OPCODE_I64_LOAD_MEM
0000010: 00                                         ; load access byte  <<< should this be 0x80?
0000011: 09                                         ; OPCODE_I8_CONST
0000012: 00                                         ; u8 literal
000000d: 0400                                       ; FIXUP func body size

Global usage error

I tried to build emscripten's hello world wast into wasm, but I get errors like

a.out.wast:65:3: global can only be defined in terms of a previously defined global.
  (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import))
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The relevant lines are

  (import "env" "STACKTOP" (global $STACKTOP$asm2wasm$import i32))
[..]
  (global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import))

and that error was on the last line there.

I think that wast code should be valid? We import $STACKTOP$asm2wasm$import, then use it to init a mutable global (asm2wasm needs mutable imports, so first we import, then assign to a mutable since imports can't be mutable).

Return operator result expression arity issues.

Another issue, similar to the br optional value issues.

(module
  (memory 4)
  (export "test1" $test1)
  (func $test1 (return))
  (export "test2" $test2)
  (func $test2 (return (nop)))
  (export "test3" $test3)
  (func $test3 (return (i32.const 1)))
  )
0000011: 0000                                       ; func body size
0000013: 14                                         ; OPCODE_RETURN
0000011: 0100                                       ; FIXUP func body size
...
000001b: 0000                                       ; func body size
000001d: 14                                         ; OPCODE_RETURN
000001e: 00                                         ; OPCODE_NOP
000001b: 0200                                       ; FIXUP func body size
....
0000026: 0000                                       ; func body size
0000028: 14                                         ; OPCODE_RETURN
0000029: 09                                         ; OPCODE_I8_CONST
000002a: 01                                         ; u8 literal
0000026: 0300                                       ; FIXUP func body size

Looking at the v8 source code suggests it looks at the number of results types to determine the 'arity' of the return. Both the above functions have the same signature, perhaps the same 'arity' here, yet one excludes a value and the other includes it.

I'd like a solution to take into account the consistency of the type system and multi-value support. I propose that a return with no expression be equivalent to (return (nop)).

Rename the project?

sexpr-wasm-prototype is a very old name for the project, and doesn't really reflect what it is or does. Any ideas for a better name?

FP parsing fail

The following FP number doesn't parse: 1.e+300.
Error: unexpected token "1.e+300"

The problem is .e if I change it to 1.0e+300 it works.

Provide a way to get SourceLocations

The spec interpreter reports assertion errors with line numbers from the source. This would be really handy for debugging codegen issues (e.g. in a test suite with hundreds of assertions, which one is failing?). Currently WAOT just tracks and prints the count (i.e. "assertion number X failed") but a line number would be even better. That would have more immediate utility but at some point it might become nice to have line information for expressions too (maybe I want to generate debug info?) That's sort of a speculative use case and may not matter during the time horizon that sexpr-wasm matters, but something that might be nice to have in mind. I'd be happy for asserts for now.
I don't know if it would be better just to hang SourceLocations off of some existing data structure, or pass extra callback args or what, it doesn't matter much to me, I don't think.

Macros

Are there any plans to introduce support for macros? Something similar to Lisp's defmacro perhaps, with both the ' and ~ modifiers.

It would make life a bit easier writing wast. It won't be of course (easily) possible to turn wasm back to its original form with macros.

Invalid NaN literal

I'm testing a program which encounters the following sexpr-wasm error:

invalid literal "nan:0x7ff8000000000000"
invalid literal "nan:0x7fc00000"
invalid literal "nan:0x7ff8000000000000"
invalid literal "nan:0x7fc00000"
invalid literal "nan:0x7ff8000000000000"
invalid literal "nan:0x7fc00000"
invalid literal "nan:0x7ff8000000000000"
invalid literal "nan:0x7fc00000"

This was generated by binaryen's s2wasm, and seems to be in line with the spec repo. @binji could you confirm?

/cc @kripken @rossberg-chromium

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.