#[derive(Clone, Debug, PartialEq, Eq)]
pub enum NetType {
Wire,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Statement {
Wire(Wire),
Register(Register),
Assign(Assign),
Always(Always),
LocalParam(LocalParam),
If(If),
Case(Case),
Assignment(Assignment),
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Assign {
pub left: String,
pub right: Expression,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Always {
pub statements: Vec<Statement>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Expression {
Identifier(String),
Unary(UnaryOp, Box<Expression>),
Binary(Box<Expression>, BinaryOp, Box<Expression>),
Number(Number),
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum UnaryOp {
Not,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum BinaryOp {
And,
Or,
Eq,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Port {
Input(Input),
Output(Output),
Inout(Inout),
}
trait PortTrait {
fn what_type(&self) -> String;
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct If {
pub condition: Expression,
pub then_statements: Vec<Statement>,
pub else_statements: Vec<Statement>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Case {
pub expression: Expression,
pub items: Vec<(Option<String>, Statement)>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Input {
pub name: String,
pub net_type: Option<NetType>,
pub width: Option<u32>,
pub is_signed: bool,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Inout {
pub name: String,
pub net_type: Option<NetType>,
pub width: Option<u32>,
pub is_signed: bool,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum RegNetType {
NetType(NetType),
Reg(bool),
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Output {
pub name: String,
pub reg_net_type: Option<RegNetType>,
pub width: Option<u32>,
pub is_signed: bool,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum OperationType {
Sync, Async, }
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Assignment {
pub name: String,
pub ass_type: OperationType,
pub right: Expression,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Module {
pub name: String,
pub statements: Vec<Statement>,
pub ports: Vec<Port>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Wire {
pub name: String,
pub width: u32,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Register {
pub name: String,
pub width: u32,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LocalParam {
pub name: String,
pub value: Number,
pub width: u32,
pub is_signed: bool,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Number {
Binary(u32, String),
Octal(u32, String),
Decimal(u32, String),
Hex(u32, String),
}