waffle/src/ir.rs

59 lines
1.4 KiB
Rust
Raw Normal View History

2021-11-13 06:16:54 +00:00
//! Intermediate representation for Wasm.
2022-11-09 19:45:47 +00:00
use crate::declare_entity;
2021-11-13 06:16:54 +00:00
2022-11-02 19:38:45 +00:00
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Type {
I32,
I64,
F32,
F64,
V128,
2022-11-02 20:44:35 +00:00
FuncRef,
2022-11-02 19:38:45 +00:00
}
impl From<wasmparser::Type> for Type {
fn from(ty: wasmparser::Type) -> Self {
match ty {
wasmparser::Type::I32 => Type::I32,
wasmparser::Type::I64 => Type::I64,
wasmparser::Type::F32 => Type::F32,
wasmparser::Type::F64 => Type::F64,
wasmparser::Type::V128 => Type::V128,
2022-11-02 20:44:35 +00:00
wasmparser::Type::FuncRef => Type::FuncRef,
2022-11-02 19:38:45 +00: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 20:44:35 +00:00
Type::FuncRef => "funcref",
2022-11-02 19:38:45 +00:00
};
write!(f, "{}", s)
}
}
2021-11-13 06:16:54 +00:00
2022-11-09 19:45:47 +00: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 22:23:22 +00:00
2022-11-02 03:51:18 +00:00
mod module;
pub use module::*;
mod func;
pub use func::*;
mod value;
pub use value::*;
2022-11-02 19:38:45 +00:00
mod display;
pub use display::*;