waffle/src/ir.rs

61 lines
1.2 KiB
Rust
Raw Normal View History

2021-11-13 06:16:54 +00:00
//! Intermediate representation for Wasm.
use wasmparser::{FuncType, Operator, Type};
2021-11-13 06:16:54 +00:00
pub type SignatureId = usize;
pub type FuncId = usize;
2021-11-13 08:20:02 +00:00
pub type BlockId = usize;
pub type InstId = usize;
pub type ValueId = usize;
2021-11-13 06:16:54 +00:00
#[derive(Clone, Debug, Default)]
2021-11-13 06:16:54 +00:00
pub struct Module {
pub funcs: Vec<FuncDecl>,
pub signatures: Vec<FuncType>,
}
#[derive(Clone, Debug)]
pub enum FuncDecl {
Import(SignatureId),
2021-11-13 08:20:02 +00:00
Body(SignatureId, FunctionBody),
2021-11-13 06:16:54 +00:00
}
#[derive(Clone, Debug, Default)]
2021-11-13 08:20:02 +00:00
pub struct FunctionBody {
2021-11-13 06:16:54 +00:00
pub locals: Vec<Type>,
2021-11-13 08:20:02 +00:00
pub blocks: Vec<Block>,
pub values: Vec<ValueDef>,
}
#[derive(Clone, Debug)]
pub struct ValueDef {
pub kind: ValueKind,
pub ty: Type,
}
#[derive(Clone, Debug)]
pub enum ValueKind {
BlockParam(Block),
2021-11-13 09:41:32 +00:00
Inst(BlockId, InstId),
}
#[derive(Clone, Debug, Default)]
pub struct Block {
pub params: Vec<Type>,
pub insts: Vec<Inst>,
}
#[derive(Clone, Debug)]
pub struct Inst {
pub operator: Operator<'static>,
pub outputs: Vec<ValueId>,
pub inputs: Vec<Operand>,
}
#[derive(Clone, Debug)]
pub enum Operand {
Value(ValueId),
Sub(Box<Inst>),
2021-11-13 09:41:32 +00:00
Local(usize), // eliminated during local2ssa pass
2021-11-13 06:16:54 +00:00
}