wasmedgec CLI

After installation, users can execute the wasmedgec tool with commands.

$ wasmedgec -v
wasmedge version 0.11.1

The usage of the wasmedge tool will be:

$ wasmedge -h
USAGE
   wasmedgec [OPTIONS] [--] WASM WASM_SO

...

The wasmedgec can compile WebAssembly into native machine code (i.e., the AOT compiler). For the pure WebAssembly, the wasmedge tool will execute the WASM in interpreter mode. After compiling with the wasmedgec AOT compiler, the wasmedge tool can execute the WASM in AOT mode which is much faster.

Options

The options of the wasmedgec CLI tool are as follows.

  1. -v|--version: Show the version information. Will ignore other arguments below.
  2. -h|--help: Show the help messages. Will ignore other arguments below.
  3. (Optional) --dump: Dump the LLVM IR to wasm.ll and wasm-opt.ll.
  4. (Optional) --interruptible: Generate the binary which supports interruptible execution.
  5. (Optional) Statistics informations:
    • By default, the AOT-compiled WASM not supports all statistics even if the options are turned on when running the wasmedge tool.
    • Use --enable-time-measuring to generate code for enabling the statistics of time measuring in execution.
    • Use --enable-gas-measuring to generate code for enabling the statistics of gas measuring in execution.
    • Use --enable-instruction-count to generate code for enabling the statistics of counting WebAssembly instructions.
    • Or use --enable-all-statistics to generate code for enabling all of the statistics.
  6. (Optional) --generic-binary: Generate the generic binary of the current host CPU architecture.
  7. (Optional) WebAssembly proposals:
  8. (Optional) --optimize: Select the LLVM optimization level.
    • Use --optimize LEVEL to set the optimization level. The LEVEL should be one of 0, 1, 2, 3, s, or z.
    • The default value will be 2, which means O2.
  9. Input WASM file (/path/to/wasm/file).
  10. Output path (/path/to/output/file).
    • By default, the wasmedgec tool will output the universal WASM format.
    • If the specific file extension (.so on Linux, .dylib on MacOS, and .dll on Windows) is assigned in the output path, the wasmedgec tool will output the shared library format.

Example

Take the fibonacci.wasm for example. It exported a fib() function which takes a single i32 integer as the input parameter.

You can run:

wasmedgec fibonacci.wasm fibonacci_aot.wasm

or:

wasmedgec fibonacci.wasm fibonacci_aot.so # On Linux.

The output will be:

[2022-09-09 14:22:10.540] [info] compile start
[2022-09-09 14:22:10.541] [info] verify start
[2022-09-09 14:22:10.542] [info] optimize start
[2022-09-09 14:22:10.547] [info] codegen start
[2022-09-09 14:22:10.552] [info] output start
[2022-09-09 14:22:10.600] [info] compile done

Then you can execute the output file with wasmedge and measure the execution time:

time wasmedge --reactor fibonacci_aot.wasm fib 30

The output will be:

1346269

real    0m0.029s
user    0m0.012s
sys     0m0.014s

Then you can compare it with the interpreter mode:

time wasmedge --reactor fibonacci.wasm fib 30

The output shows that the AOT-compiled WASM is much faster than the interpreter mode:

1346269

real    0m0.442s
user    0m0.427s
sys     0m0.012s