1.0.31 • Published 4 years ago

was v1.0.31

Weekly downloads
7
License
GPL-3.0
Repository
github
Last release
4 years ago

was

WebAssembly assembler JavaScript (libwabt.js) wrapper

Install

To install was, you may use the npm package manager.

	npm install -g was

If you are using Linux or Mac, you might want to add sudo to installation.

Usage

was can assemble, disassemlbe and run webassembly modules.

It also include an io library so writing wasm programs is made easier.

Assemble

	was program.wat

This will generate a file with the name program.wasm.

You may use several options:

OptionShortDescription
--debug-dAdd debug information to the wasm binary. This will add a section with the function, variables, table and label names
--log-lWrite a log about the compiled binary file
--output-oThe name of the output file. If it is not specified, the name of the input file will be used and the extension will be changed to wasm

Disassemble

	was disassemble program.wasm

This will generate a file with the name program.wat.

You may use several options:

OptionShortDescription
--debug-dLoad the debug information (if it exists) from the wasm binary. This will load the section with the function, variables, table and label names
--names-nGenerate names for the functions, variable, tables and labels. usually this is used if the debug information is not present.
--inline-export-eWrite the export statements inside the exported element. The default option is to write the export as a separate statement
--fold-fFold expresssion
--output-oThe name of the output file. If it is not specified, the name of the input file will be used and the extension will be changed to wat

Run

	was run program.wasm

This will run the program.wasm program using Node.

You may use several options:

OptionShortDescription
--import-iLoad a Node module and allow the WebAssembly program to import it. The module may be imported by webassembly using the file name (without extension). All the exprted items from the module are made available to the WebAssembly program. You may write several import items in the command line.
--memory-mThe format is minPages:maxPages. Set up a memory space with a minimum number of minPages and a maximum number of maxPages. A memory page is 64 KB of storage

Libraries

These libraries are automatically imported when running a WebAssembly program with wasm.

io

The io library provides simple input and output functions.

FunctionImport StatementDescriptions
mem(import "io" "mem" (memory _minPage_))The memory (if it was set with the --memory option). minPage is the minimum number of pages specified
readstr(import "io" "readstr" (func $readstr (param $strAddr i32) (param $length i32) (result i32)))Reads a string from the standard input and writes it into the memory. The reading is stopped when the return key is pressed, maximum $length bytes are written to the memory. A \0 character is added to the buffer. $strAddr is the memory location where the string will be written. The function returns the number of charcters read (without the \0)
readchar(import "io" "readchar" (func $readchar (result i32)))Reads a charcter from the standard input and returns it
readint(import "io" "readint" (func $readint (result i32)))Reads a signed integer from the standard input and returns it
writestr(import "io" "writestr" (func $writestr (param $strAddr i32)))Writes a string to the standard output: $strAddr is the address of a null terminated string inside the memory
writechar(import "io" "writechar" (func $writechar (param $char i32)))Writes a charcter to the standard output: _$char is the character
writeint(import "io" "writeint" (func $writeint (param $int i32)))Writes a signed integer to the standard output: _$int is the number
1.0.31

4 years ago

1.0.25

4 years ago

1.0.23

4 years ago

1.0.21

4 years ago

1.0.17

4 years ago

1.0.14

4 years ago

1.0.12

4 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.0

6 years ago