README.md 2.2 KB

packcc-wast

This is a wasm assembly language parser in C created using packcc parser tool

The wasm assembly language files have extension .wast or .wat

The file are zero or more module definitions

The minimal wasm assembly statement is "(module)"

This can be used to create own wasm assembler

This can be used to write output for GNU gas assembler which supports wasm assembly but not this format

This can be used to check syntax of wasm assembly

This can be used to generate call graph data from wasm

This parser does parse the syntax structure with the items

Then a syntax tree can be created and checked for valid data

This peg file can be extended to do syntax checks at parsing

The comment line in wasm assembly starts with ;; until end of line

This are the current tools for wasm

wasm-interp (1) - decode and run a WebAssembly binary file

wasm-objdump (1) - print information about a wasm binary

wasm-opcodecnt (1) - count opcode usage for instructions

wasm-strip (1) - remove sections of a WebAssembly binary file

wasm-validate (1) - validate a file in the WebAssembly binary format

wasm2c (1) - convert a WebAssembly binary file to a C source and header

wasm2wat (1) - translate from the binary format to the text format

wast2json (1) - convert a file in the wasm spec test format to a JSON file and associated ...

wat2wasm (1) - translate from WebAssembly text format to the WebAssembly binary format

This are the websites with the C++ source of these tools and specifications

https://github.com/WebAssembly/wabt

https://github.com/WebAssembly/binaryen

https://github.com/WebAssembly

There are not many tools to work with wasm assembly

To compile a test.c file to wasm binary using clang version 8+

clang test.c -o t.wasm --target=wasm32 -nostdlib -Xlinker --no-entry -Xlinker --allow-undefined

To get the assembly listing

wasm2wat t.wasm -o t.wat

To get the assembly listing as C source

wasm2c t.wasm -o twasm.c

Also possible

clang -emit-llvm --target=wasm32 -c test.c -o test.bc

llc -asm-verbose=false -o test.s test.bc

To get parser debug in the peg file set int debug to 1

See the file output.txt how the tokens are parsed