waffle/src/ir.rs

60 lines
1.1 KiB
Rust
Raw Normal View History

2021-11-13 00:16:54 -06:00
//! Intermediate representation for Wasm.
use wasmparser::{FuncType, Operator, Type};
2021-11-13 00:16:54 -06:00
pub type SignatureId = usize;
pub type FuncId = usize;
2021-11-13 02:20:02 -06:00
pub type BlockId = usize;
pub type InstId = usize;
pub type ValueId = usize;
2021-11-13 00:16:54 -06:00
#[derive(Clone, Debug, Default)]
2021-11-13 00:16:54 -06:00
pub struct Module {
pub funcs: Vec<FuncDecl>,
pub signatures: Vec<FuncType>,
}
#[derive(Clone, Debug)]
pub enum FuncDecl {
Import(SignatureId),
2021-11-13 02:20:02 -06:00
Body(SignatureId, FunctionBody),
2021-11-13 00:16:54 -06:00
}
#[derive(Clone, Debug, Default)]
2021-11-13 02:20:02 -06:00
pub struct FunctionBody {
2021-11-13 00:16:54 -06:00
pub locals: Vec<Type>,
2021-11-13 02:20:02 -06: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),
Inst(Block, Inst),
}
#[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 00:16:54 -06:00
}