Host Call Log (WAT)
A minimal WAT program that demonstrates PVM host calls. It invokes ecalli 100 (the log host call) to print “Hello from PVM!” and returns 42.
Source
File: examples/sources/host-call-log.wat
(module
(import "env" "pvm_ptr" (func $pvm_ptr (param i64) (result i64)))
(import "env" "host_call_5" (func $host_call_5 (param i64 i64 i64 i64 i64 i64) (result i64)))
(memory (export "memory") 1)
;; "test-log" at offset 0 (8 bytes)
(data (i32.const 0) "test-log")
;; "Hello from PVM!" at offset 8 (15 bytes)
(data (i32.const 8) "Hello from PVM!")
(func (export "main") (param $args_ptr i32) (param $args_len i32) (result i64)
;; ecalli 100 = log host call
;; r7 = level (3 = INFO)
;; r8 = target_ptr (PVM address of "test-log")
;; r9 = target_len (8)
;; r10 = msg_ptr (PVM address of "Hello from PVM!")
;; r11 = msg_len (15)
(drop (call $host_call_5
(i64.const 100)
(i64.const 3)
(call $pvm_ptr (i64.const 0))
(i64.const 8)
(call $pvm_ptr (i64.const 8))
(i64.const 15)))
;; Return result: store 42 at offset 24, return (ptr=24, len=4)
(i32.store (i32.const 24) (i32.const 42))
(i64.const 17179869208)))
The program uses two imported helpers:
pvm_ptr– translates a Wasm linear-memory offset to a PVM addresshost_call_5– dispatches to a numbered host function with 5 data arguments (here,ecalli 100for logging). The_5suffix indicates the number of data registers (r7-r11) passed to the host call.
Compiled Metadata
| Field | Value |
|---|---|
| File | examples/compiled/host-call-log.pvm |
| Size | 12486 bytes |
| Format | SPI |
| Functions | 1 |
Decompiled Output
./target/release/pvm-decompiler examples/compiled/host-call-log.pvm
fn main(r0: u64, r1: u64, r3: u64, r5: u64, r6: u64, r7: u64, r12: u64) {
let var_28
// @0006
log()
u32[var_28 + 0x33000] = 42
halt()
}
What to notice:
- Host call recognition: The
ecalli 100instruction is recognized and rendered aslog(). The decompiler collapses the multi-register setup (level, target pointer/length, message pointer/length) into a single named call. - Compact output: Despite the binary being ~12 KB (due to the
pvm_ptrhelper and runtime support code being compiled in), the decompiler produces just 7 lines of pseudo-code for the main function. - Result encoding:
u32[var_28 + 0x33000] = 42stores the return value, followed byhalt(). - Binary size vs. complexity: The 12 KB binary size comes from the
pvm_ptraddress-translation helper and memory setup code compiled from the imports, not from the application logic itself.