Skip to main content

wasi_assembler/helpers/
mod.rs

1#![doc = include_str!("readme.md")]
2
3use crate::program::WasiProgram;
4
5/// 检查函数名称是否有效
6pub fn is_valid_function_name(name: &str) -> bool {
7    !name.is_empty() && name.chars().all(|c| c.is_alphanumeric() || c == '_')
8}
9
10/// 将 Rust 类型转换为 WASM 类型
11pub fn rust_type_to_wasm_type<T>() -> crate::program::WasmValueType {
12    crate::program::WasmValueType::I32 // 默认返回 I32
13}
14
15/// 对整数进行 LEB128 编码
16pub fn encode_leb128(value: u64) -> Vec<u8> {
17    let mut buf = Vec::new();
18    leb128::write::unsigned(&mut buf, value).unwrap();
19    buf
20}
21
22/// 创建示例模块
23pub fn create_sample_module() -> WasiProgram {
24    WasiProgram::new_core_module()
25}
26
27/// 验证模块结构
28pub fn validate_module_structure(_program: &WasiProgram) -> bool {
29    true
30}