71 lines
1.4 KiB
Rust
71 lines
1.4 KiB
Rust
use nom::{combinator::map, multi::separated_list0};
|
|
|
|
use crate::parser::{
|
|
declaration,
|
|
proc::ProcBlock,
|
|
tokens::{token, TokenKind as tk, TokenSpan},
|
|
Assign, IResult, NetDecl, Span,
|
|
};
|
|
|
|
#[derive(Debug)]
|
|
pub enum PortDirection {
|
|
Input,
|
|
Output,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct PortDecl<'a> {
|
|
pub direction: PortDirection,
|
|
pub net: NetDecl<'a>,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct Module<'a> {
|
|
pub name: Span<'a>,
|
|
pub ports: Vec<PortDecl<'a>>,
|
|
pub items: Vec<ModuleItem<'a>>,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum ModuleItem<'a> {
|
|
Assign(Assign<'a>),
|
|
Proc(ProcBlock<'a>),
|
|
}
|
|
|
|
fn port_decl(i: TokenSpan) -> IResult<TokenSpan, PortDecl> {
|
|
map(declaration, |net| PortDecl {
|
|
direction: PortDirection::Input,
|
|
net,
|
|
})(i)
|
|
}
|
|
|
|
pub fn inputs_list(input: TokenSpan) -> IResult<TokenSpan, Vec<PortDecl>> {
|
|
separated_list0(token(tk::Comma), port_decl)(input)
|
|
}
|
|
|
|
pub fn module(_input: TokenSpan) -> IResult<TokenSpan, Module> {
|
|
todo!();
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
use super::*;
|
|
use nom::combinator::all_consuming;
|
|
|
|
#[test]
|
|
fn test_decl() {
|
|
declaration("reg abcd".into()).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn test_assignment_item() {
|
|
all_consuming(assign_item)(" assign a = b ; ".into()).unwrap();
|
|
all_consuming(assign_item)(" assign a = b | c ; ".into()).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn test_module_item() {
|
|
all_consuming(module_item)(" assign a = b ;".into()).unwrap();
|
|
}
|
|
}
|