74 lines
1.5 KiB
Rust
74 lines
1.5 KiB
Rust
use super::callable::CallableId;
|
|
use super::types::{ElabData, Type};
|
|
use std::collections::HashMap;
|
|
use std::fmt::Debug;
|
|
|
|
/// ID of a definition (e.g. variable, block, function)
|
|
#[derive(Clone, Copy)]
|
|
pub struct DefId(pub u32);
|
|
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
|
|
pub struct ExprId(pub u32);
|
|
|
|
// more compact Debug impl
|
|
impl Debug for DefId {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "DefId({})", self.0)
|
|
}
|
|
}
|
|
impl Debug for ExprId {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "ExprId({})", self.0)
|
|
}
|
|
}
|
|
|
|
/// an abstract element that performs some kind of computation on inputs
|
|
#[derive(Debug, Clone)]
|
|
pub struct Expr {
|
|
pub id: ExprId,
|
|
pub kind: ExprKind,
|
|
pub typ: Type,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Call {
|
|
pub called: CallableId,
|
|
pub args: Vec<ExprId>,
|
|
pub genargs: Vec<Type>,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Match {
|
|
pub expr: ExprId,
|
|
pub arms: Vec<(ExprId, ExprId)>,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub enum ExprKind {
|
|
Literal(ElabData),
|
|
Path(DefId),
|
|
Call(Call),
|
|
Match(Box<Match>),
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Signal {
|
|
pub id: DefId,
|
|
pub typ: Type,
|
|
}
|
|
|
|
/// A block of HDL code, e.g. comb block
|
|
#[derive(Debug, Clone)]
|
|
pub struct Body {
|
|
pub signature: CallableId,
|
|
pub signals: Vec<Signal>,
|
|
pub exprs: HashMap<ExprId, Expr>,
|
|
pub expr: ExprId,
|
|
}
|
|
|
|
impl Expr {
|
|
pub fn with_type(mut self, typ: Type) -> Self {
|
|
self.typ = typ;
|
|
self
|
|
}
|
|
}
|