2021-11-13 00:16:54 -06:00
|
|
|
//! Intermediate representation for Wasm.
|
|
|
|
|
2022-11-09 13:45:47 -06:00
|
|
|
use crate::declare_entity;
|
2021-11-13 00:16:54 -06:00
|
|
|
|
2022-11-02 14:38:45 -05:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
|
|
pub enum Type {
|
|
|
|
I32,
|
|
|
|
I64,
|
|
|
|
F32,
|
|
|
|
F64,
|
|
|
|
V128,
|
2022-11-02 15:44:35 -05:00
|
|
|
FuncRef,
|
2022-11-02 14:38:45 -05:00
|
|
|
}
|
2022-11-23 01:30:11 -06:00
|
|
|
impl From<wasmparser::ValType> for Type {
|
|
|
|
fn from(ty: wasmparser::ValType) -> Self {
|
2022-11-02 14:38:45 -05:00
|
|
|
match ty {
|
2022-11-23 01:30:11 -06:00
|
|
|
wasmparser::ValType::I32 => Type::I32,
|
|
|
|
wasmparser::ValType::I64 => Type::I64,
|
|
|
|
wasmparser::ValType::F32 => Type::F32,
|
|
|
|
wasmparser::ValType::F64 => Type::F64,
|
|
|
|
wasmparser::ValType::V128 => Type::V128,
|
|
|
|
wasmparser::ValType::FuncRef => Type::FuncRef,
|
2022-11-02 14:38:45 -05:00
|
|
|
_ => panic!("Unsupported type: {:?}", ty),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::fmt::Display for Type {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
let s = match self {
|
|
|
|
Type::I32 => "i32",
|
|
|
|
Type::I64 => "i64",
|
|
|
|
Type::F32 => "f32",
|
|
|
|
Type::F64 => "f64",
|
|
|
|
Type::V128 => "v128",
|
2022-11-02 15:44:35 -05:00
|
|
|
Type::FuncRef => "funcref",
|
2022-11-02 14:38:45 -05:00
|
|
|
};
|
|
|
|
write!(f, "{}", s)
|
|
|
|
}
|
|
|
|
}
|
2021-11-13 00:16:54 -06:00
|
|
|
|
2022-11-29 02:58:55 -06:00
|
|
|
impl From<Type> for wasm_encoder::ValType {
|
|
|
|
fn from(ty: Type) -> wasm_encoder::ValType {
|
|
|
|
match ty {
|
|
|
|
Type::I32 => wasm_encoder::ValType::I32,
|
|
|
|
Type::I64 => wasm_encoder::ValType::I64,
|
|
|
|
Type::F32 => wasm_encoder::ValType::F32,
|
|
|
|
Type::F64 => wasm_encoder::ValType::F64,
|
|
|
|
Type::V128 => wasm_encoder::ValType::V128,
|
|
|
|
Type::FuncRef => wasm_encoder::ValType::FuncRef,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-09 13:45:47 -06:00
|
|
|
declare_entity!(Signature, "sig");
|
|
|
|
declare_entity!(Func, "func");
|
|
|
|
declare_entity!(Block, "block");
|
|
|
|
declare_entity!(Local, "local");
|
|
|
|
declare_entity!(Global, "global");
|
|
|
|
declare_entity!(Table, "table");
|
|
|
|
declare_entity!(Memory, "memory");
|
|
|
|
declare_entity!(Value, "v");
|
2021-11-13 16:23:22 -06:00
|
|
|
|
2022-11-01 22:51:18 -05:00
|
|
|
mod module;
|
|
|
|
pub use module::*;
|
|
|
|
mod func;
|
|
|
|
pub use func::*;
|
|
|
|
mod value;
|
|
|
|
pub use value::*;
|
2022-11-02 14:38:45 -05:00
|
|
|
mod display;
|
|
|
|
pub use display::*;
|
2023-02-10 22:55:45 -06:00
|
|
|
mod debug;
|
|
|
|
pub use debug::*;
|