2022-02-15 20:32:55 +00:00
|
|
|
use super::types::Type;
|
2022-02-15 22:56:52 +00:00
|
|
|
use std::fmt::Debug;
|
2022-02-15 20:32:55 +00:00
|
|
|
|
|
|
|
/// ID of a definition (e.g. variable, block, function)
|
2022-02-15 22:56:52 +00:00
|
|
|
#[derive(Clone, Copy)]
|
2022-02-15 20:32:55 +00:00
|
|
|
pub struct DefId(pub u32);
|
2022-02-15 22:56:52 +00:00
|
|
|
#[derive(Clone, Copy)]
|
2022-02-15 20:32:55 +00:00
|
|
|
pub struct ExprId(pub u32);
|
2022-01-30 22:54:19 +00:00
|
|
|
|
2022-02-15 22:56:52 +00:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-06 22:19:55 +00:00
|
|
|
/// an abstract element that performs some kind of computation on inputs
|
2022-02-15 20:32:55 +00:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct Expr {
|
|
|
|
pub id: ExprId,
|
|
|
|
pub kind: ExprKind,
|
|
|
|
pub typ: Type,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub enum ExprKind {
|
|
|
|
Literal,
|
|
|
|
Path(DefId),
|
|
|
|
Call { called: DefId, args: Vec<Expr> },
|
2022-01-30 22:54:19 +00:00
|
|
|
}
|
|
|
|
|
2022-02-15 20:32:55 +00:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct Signal {
|
|
|
|
pub id: DefId,
|
|
|
|
pub typ: Type,
|
2022-01-30 22:54:19 +00:00
|
|
|
}
|
|
|
|
|
2022-02-06 22:19:55 +00:00
|
|
|
/// A block of HDL code, e.g. comb block
|
2022-02-15 20:32:55 +00:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct Block {
|
|
|
|
pub signals: Vec<Signal>,
|
|
|
|
pub expr: Expr,
|
2022-02-06 22:19:55 +00:00
|
|
|
}
|