futilehdl/src/frontend/typed_ir.rs

61 lines
1.2 KiB
Rust
Raw Normal View History

2022-02-16 21:17:25 +00:00
use super::callable::CallableId;
2022-02-16 15:37:12 +00:00
use super::types::{ElabData, 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 {
2022-02-16 15:37:12 +00:00
Literal(ElabData),
2022-02-15 20:32:55 +00:00
Path(DefId),
Call {
called: CallableId,
args: Vec<Expr>,
genargs: Vec<Type>,
},
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
}
impl Expr {
pub fn with_type(mut self, typ: Type) -> Self {
self.typ = typ;
self
}
}