wasm_parser 0.0.1 wasm_parser: ^0.0.1 copied to clipboard
Parses Web Assembly (WASM), WASM Text Format (WAT) and Web Assembly Interface Types (WIT) files
example/wasm_parser_example.dart
import 'package:wasm_parser/wasm_parser.dart';
import 'package:wasm_wit_component/wasm_wit_component.dart';
Future<void> main() async {
final world = await createWasmParser(
wasiConfig: WasiConfig(preopenedDirs: [], webBrowserFileSystem: {}),
imports: WasmParserWorldImports(),
);
final result = world.parseWat(
input: WatInput.text(r'''
(module
(import "host" "hello" (func $host_hello (param i32)))
(func (export "hello")
(call $host_hello (i32.const 3))
)
)
'''),
);
print(result);
const expected = ModuleType(
imports: [
ModuleImport(
module: 'host',
name: 'hello',
type: FunctionType(
parameters: [ValueType.i32()],
results: [],
),
),
],
exports: [
ModuleExport(
name: 'hello',
type: FunctionType(
parameters: [],
results: [],
),
),
],
);
assert(
result == const Ok<WasmType, String>(expected),
);
}