use std::collections::HashMap;
use std::rc::Rc;
pub type Id = String;
pub type Map = HashMap<Id, Expr>;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Unop {
LogNot,
Not,
And,
Nand,
Or,
Nor,
Xor,
Xnor,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Binop {
LogOr,
LogAnd,
Add,
Sub,
Mul,
Gt,
Lt,
Geq,
Leq,
Equal,
NotEqual,
IndexBit,
BitAnd,
BitOr,
ShiftLeft,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Terop {
Mux,
Slice,
IndexSlice,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Radix {
Dec,
Bin,
Hex,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct InstancePath {
pub path: Vec<Id>,
}
#[derive(Default, Clone, Debug, PartialEq, Eq, Hash)]
pub struct ExprConcat {
pub exprs: Vec<Expr>,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Expr {
X,
Ref(Id),
Int(i32),
ULit(u32, Radix, String),
Str(String),
Signed(Rc<Expr>),
IPath(InstancePath, Option<Rc<Expr>>),
Unop(Unop, Rc<Expr>),
Binop(Binop, Rc<Expr>, Rc<Expr>),
Terop(Terop, Rc<Expr>, Rc<Expr>, Rc<Expr>),
Concat(ExprConcat),
Repeat(u64, Rc<Expr>),
Call(Id, Vec<Expr>),
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum AttributeTy {
Val(String),
Stmt(String, String),
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct Attribute {
pub attrs: Vec<AttributeTy>,
}
#[derive(Clone, Debug)]
pub enum EventTy {
Posedge,
Negedge,
}
#[derive(Clone, Debug)]
pub struct Instance {
pub id: Id,
pub prim: Id,
pub params: Map,
pub ports: Map,
pub attr: Attribute,
}
#[derive(Clone, Debug)]
pub enum AssignTy {
Blocking,
NonBlocking,
}
#[derive(Clone, Debug)]
pub struct GenericCaseBranch<T> {
pub cond: Expr,
pub body: Vec<T>,
}
#[derive(Clone, Debug)]
pub struct GenericCaseDefault<T> {
pub body: Vec<T>,
}
#[derive(Clone, Debug)]
pub struct GenericCase<T> {
pub cond: Expr,
pub branches: Vec<GenericCaseBranch<T>>,
pub default: Option<GenericCaseDefault<T>>,
}
#[derive(Clone, Debug)]
pub enum GenericPort<T> {
Input(T),
Output(T),
}
#[derive(Clone, Debug)]
pub struct GenericFunction<F, T, U, V> {
pub ty: F,
pub name: Id,
pub ports: Vec<GenericPort<T>>,
pub decls: Vec<T>,
pub body: Vec<U>,
pub ret: V,
}
#[derive(Clone, Debug)]
pub enum GenericStmt<T, U> {
Decl(T),
Parallel(U),
RawStr(String),
}
#[derive(Clone, Debug)]
pub struct GenericModule<T, U> {
pub name: String,
pub params: Vec<T>,
pub ports: Vec<GenericPort<T>>,
pub body: Vec<GenericStmt<T, U>>,
pub attr: Attribute,
}