Skip to content

Commit c49a7b0

Browse files
committed
phase 2
Signed-off-by: mrhapile <allinonegaming3456@gmail.com>
1 parent df75905 commit c49a7b0

21 files changed

Lines changed: 318 additions & 11 deletions

build_corpus.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
# build_corpus.sh
3+
# Compiles all .wat files to .wasm binaries using wat2wasm (from wabt)
4+
#
5+
# Prerequisites:
6+
# brew install wabt # or apt-get install wabt
7+
8+
set -e
9+
10+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11+
CORPUS_DIR="$SCRIPT_DIR/corpus"
12+
13+
echo "Building WASM corpus from WAT files..."
14+
15+
# Check for wat2wasm
16+
if ! command -v wat2wasm &> /dev/null; then
17+
echo "Error: wat2wasm not found. Install wabt:"
18+
echo " macOS: brew install wabt"
19+
echo " Ubuntu: apt-get install wabt"
20+
exit 1
21+
fi
22+
23+
# Compile each .wat file
24+
for wat_file in "$CORPUS_DIR"/*.wat; do
25+
if [ -f "$wat_file" ]; then
26+
base_name=$(basename "$wat_file" .wat)
27+
wasm_file="$CORPUS_DIR/$base_name.wasm"
28+
29+
# Skip if we already have a hand-crafted binary
30+
if [ -f "$wasm_file" ]; then
31+
echo " [SKIP] $base_name.wasm (already exists)"
32+
continue
33+
fi
34+
35+
echo " [BUILD] $base_name.wat -> $base_name.wasm"
36+
wat2wasm "$wat_file" -o "$wasm_file"
37+
fi
38+
done
39+
40+
echo ""
41+
echo "Corpus files:"
42+
ls -la "$CORPUS_DIR"/*.wasm 2>/dev/null || echo "No .wasm files found"
43+
44+
echo ""
45+
echo "Build complete."

corpus/01_valid_module.wasm

44 Bytes
Binary file not shown.

corpus/01_valid_module.wat

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
;; 01_valid_module.wat
2+
;; A valid WASM module with correct ABI: int process(int)
3+
;; Expected stage: NONE (success)
4+
;; Tests: Full pipeline execution succeeds
5+
6+
(module
7+
;; Export a function named "process" that takes i32 and returns i32
8+
(func $process (export "process") (param $input i32) (result i32)
9+
;; Simple computation: return input + 1
10+
local.get $input
11+
i32.const 1
12+
i32.add
13+
)
14+
)

corpus/02_empty_file.wasm

Whitespace-only changes.

corpus/03_truncated_binary.wasm

7 Bytes
Binary file not shown.

corpus/04_missing_export.wasm

52 Bytes
Binary file not shown.

corpus/04_missing_export.wat

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
;; 04_missing_export.wat
2+
;; A valid WASM module but without the required "process" export
3+
;; Expected stage: EXECUTE (function not found)
4+
;; Tests: Export resolution / function lookup
5+
6+
(module
7+
;; Internal function not exported
8+
(func $internal (param $x i32) (result i32)
9+
local.get $x
10+
i32.const 2
11+
i32.mul
12+
)
13+
14+
;; Different export name - not "process"
15+
(func $compute (export "compute") (param $x i32) (result i32)
16+
local.get $x
17+
call $internal
18+
)
19+
)
40 Bytes
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
;; 05_abi_mismatch_no_param.wat
2+
;; WASM module with "process" export but wrong signature (no parameters)
3+
;; Expected stage: EXECUTE (ABI mismatch - wrong parameter count)
4+
;; Tests: Function signature validation at call time
5+
6+
(module
7+
;; "process" exists but takes no parameters
8+
(func $process (export "process") (result i32)
9+
i32.const 42
10+
)
11+
)
44 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)