waffle/src/ir.rs

56 lines
1.2 KiB
Rust
Raw Normal View History

2021-11-13 00:16:54 -06:00
//! Intermediate representation for Wasm.
2022-11-01 22:43:47 -05:00
use crate::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,
}
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 00:16:54 -06:00
2022-11-01 22:43:47 -05: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 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::*;