waffle/src/ir.rs

56 lines
1.2 KiB
Rust
Raw Normal View History

2021-11-13 06:16:54 +00:00
//! Intermediate representation for Wasm.
2022-11-02 03:43:47 +00:00
use crate::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,
}
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,
_ => 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",
};
write!(f, "{}", s)
}
}
2021-11-13 06:16:54 +00:00
2022-11-02 03:43:47 +00:00
entity!(Signature, "sig");
entity!(Func, "func");
entity!(Block, "block");
entity!(Local, "local");
entity!(Global, "global");
entity!(Table, "table");
entity!(Memory, "memory");
entity!(Value, "value");
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::*;