Refactoring
This commit is contained in:
parent
783a420cfa
commit
164016ef80
@ -7,8 +7,8 @@ A parser library for System Verilog.
|
|||||||
| --------------------------------- | ------------------------------------- | ---- | ------ | ---- |
|
| --------------------------------- | ------------------------------------- | ---- | ------ | ---- |
|
||||||
| source_text | library_source_text | x | x | x |
|
| source_text | library_source_text | x | x | x |
|
||||||
| source_text | system_verilog_source_text | x | x | |
|
| source_text | system_verilog_source_text | x | x | |
|
||||||
| source_text | module_parameters_and_ports | | | |
|
| source_text | module_parameters_and_ports | x | x | |
|
||||||
| source_text | module_items | | | |
|
| source_text | module_items | x | x | |
|
||||||
| source_text | configuration_source_text | | | |
|
| source_text | configuration_source_text | | | |
|
||||||
| source_text | interface_items | | | |
|
| source_text | interface_items | | | |
|
||||||
| source_text | program_items | | | |
|
| source_text | program_items | | | |
|
||||||
|
@ -72,14 +72,14 @@ pub struct RefDeclaration<'a> {
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
pub fn inout_declaratrion(s: Span) -> IResult<Span, InoutDeclaration> {
|
pub fn inout_declaration(s: Span) -> IResult<Span, InoutDeclaration> {
|
||||||
let (s, a) = symbol("inout")(s)?;
|
let (s, a) = symbol("inout")(s)?;
|
||||||
let (s, b) = net_port_type(s)?;
|
let (s, b) = net_port_type(s)?;
|
||||||
let (s, c) = list_of_port_identifiers(s)?;
|
let (s, c) = list_of_port_identifiers(s)?;
|
||||||
Ok((s, InoutDeclaration { nodes: (a, b, c) }))
|
Ok((s, InoutDeclaration { nodes: (a, b, c) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn input_declaratrion(s: Span) -> IResult<Span, InputDeclaration> {
|
pub fn input_declaration(s: Span) -> IResult<Span, InputDeclaration> {
|
||||||
alt((input_declaration_net, input_declaration_variable))(s)
|
alt((input_declaration_net, input_declaration_variable))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ pub fn input_declaration_variable(s: Span) -> IResult<Span, InputDeclaration> {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn output_declaratrion(s: Span) -> IResult<Span, OutputDeclaration> {
|
pub fn output_declaration(s: Span) -> IResult<Span, OutputDeclaration> {
|
||||||
alt((output_declaration_net, output_declaration_variable))(s)
|
alt((output_declaration_net, output_declaration_variable))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
use crate::ast::*;
|
use crate::ast::*;
|
||||||
use crate::parser::*;
|
use crate::parser::*;
|
||||||
//use nom::branch::*;
|
use nom::branch::*;
|
||||||
//use nom::combinator::*;
|
use nom::combinator::*;
|
||||||
use nom::error::*;
|
use nom::multi::*;
|
||||||
use nom::{Err, IResult};
|
use nom::sequence::*;
|
||||||
|
use nom::IResult;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -17,22 +18,38 @@ pub enum ElaborationSystemTask<'a> {
|
|||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct ElaborationSystemTaskFatal<'a> {
|
pub struct ElaborationSystemTaskFatal<'a> {
|
||||||
pub nodes: (Option<(FinishNumber<'a>, Option<ListOfArguments<'a>>)>,),
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
|
Option<Paren<'a, (FinishNumber<'a>, Option<(Symbol<'a>, ListOfArguments<'a>)>)>>,
|
||||||
|
Symbol<'a>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct ElaborationSystemTaskError<'a> {
|
pub struct ElaborationSystemTaskError<'a> {
|
||||||
pub nodes: (Option<Option<ListOfArguments<'a>>>,),
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
|
Option<Paren<'a, Option<ListOfArguments<'a>>>>,
|
||||||
|
Symbol<'a>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct ElaborationSystemTaskWarning<'a> {
|
pub struct ElaborationSystemTaskWarning<'a> {
|
||||||
pub nodes: (Option<Option<ListOfArguments<'a>>>,),
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
|
Option<Paren<'a, Option<ListOfArguments<'a>>>>,
|
||||||
|
Symbol<'a>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct ElaborationSystemTaskInfo<'a> {
|
pub struct ElaborationSystemTaskInfo<'a> {
|
||||||
pub nodes: (Option<Option<ListOfArguments<'a>>>,),
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
|
Option<Paren<'a, Option<ListOfArguments<'a>>>>,
|
||||||
|
Symbol<'a>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
@ -61,7 +78,7 @@ pub enum ModuleCommonItem<'a> {
|
|||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub enum ModuleItem<'a> {
|
pub enum ModuleItem<'a> {
|
||||||
PortDeclaratoin(PortDeclaration<'a>),
|
PortDeclaration((PortDeclaration<'a>, Symbol<'a>)),
|
||||||
NonPortModuleItem(NonPortModuleItem<'a>),
|
NonPortModuleItem(NonPortModuleItem<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,17 +122,23 @@ pub enum ModuleOrGenerateItemDeclaration<'a> {
|
|||||||
GenvarDeclaration(GenvarDeclaration<'a>),
|
GenvarDeclaration(GenvarDeclaration<'a>),
|
||||||
ClockingDeclaration(ClockingDeclaration<'a>),
|
ClockingDeclaration(ClockingDeclaration<'a>),
|
||||||
Clocking(ModuleOrGenerateItemDeclarationClocking<'a>),
|
Clocking(ModuleOrGenerateItemDeclarationClocking<'a>),
|
||||||
Expression(ModuleOrGenerateItemDeclarationExpression<'a>),
|
Disable(ModuleOrGenerateItemDeclarationDisable<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct ModuleOrGenerateItemDeclarationClocking<'a> {
|
pub struct ModuleOrGenerateItemDeclarationClocking<'a> {
|
||||||
pub nodes: (ClockingIdentifier<'a>),
|
pub nodes: (Symbol<'a>, Symbol<'a>, ClockingIdentifier<'a>, Symbol<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct ModuleOrGenerateItemDeclarationExpression<'a> {
|
pub struct ModuleOrGenerateItemDeclarationDisable<'a> {
|
||||||
pub nodes: (ExpressionOrDist<'a>),
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
|
Symbol<'a>,
|
||||||
|
Symbol<'a>,
|
||||||
|
ExpressionOrDist<'a>,
|
||||||
|
Symbol<'a>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
@ -137,7 +160,7 @@ pub struct NonPortModuleItemSpecparam<'a> {
|
|||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct ParameterOverride<'a> {
|
pub struct ParameterOverride<'a> {
|
||||||
pub nodes: (ListOfDefparamAssignments<'a>,),
|
pub nodes: (Symbol<'a>, ListOfDefparamAssignments<'a>, Symbol<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
@ -149,15 +172,22 @@ pub enum BindDirective<'a> {
|
|||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct BindDirectiveScope<'a> {
|
pub struct BindDirectiveScope<'a> {
|
||||||
pub nodes: (
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
BindTargetScope<'a>,
|
BindTargetScope<'a>,
|
||||||
Option<BindTargetInstanceList<'a>>,
|
Option<(Symbol<'a>, BindTargetInstanceList<'a>)>,
|
||||||
BindInstantiation<'a>,
|
BindInstantiation<'a>,
|
||||||
|
Symbol<'a>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct BindDirectiveInstance<'a> {
|
pub struct BindDirectiveInstance<'a> {
|
||||||
pub nodes: (BindTargetInstanceList<'a>, BindInstantiation<'a>),
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
|
BindTargetInstance<'a>,
|
||||||
|
BindInstantiation<'a>,
|
||||||
|
Symbol<'a>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
@ -173,7 +203,7 @@ pub struct BindTargetInstance<'a> {
|
|||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct BindTargetInstanceList<'a> {
|
pub struct BindTargetInstanceList<'a> {
|
||||||
pub nodes: (Vec<BindTargetInstance<'a>>,),
|
pub nodes: (List<Symbol<'a>, BindTargetInstance<'a>>,),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
@ -187,55 +217,313 @@ pub enum BindInstantiation<'a> {
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
pub fn elaboration_system_task(s: Span) -> IResult<Span, ElaborationSystemTask> {
|
pub fn elaboration_system_task(s: Span) -> IResult<Span, ElaborationSystemTask> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((
|
||||||
|
elaboration_system_task_fatal,
|
||||||
|
elaboration_system_task_error,
|
||||||
|
elaboration_system_task_warning,
|
||||||
|
elaboration_system_task_info,
|
||||||
|
))(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn elaboration_system_task_fatal(s: Span) -> IResult<Span, ElaborationSystemTask> {
|
||||||
|
let (s, a) = symbol("$fatal")(s)?;
|
||||||
|
let (s, b) = opt(paren(pair(
|
||||||
|
finish_number,
|
||||||
|
opt(pair(symbol(","), list_of_arguments)),
|
||||||
|
)))(s)?;
|
||||||
|
let (s, c) = symbol(";")(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ElaborationSystemTask::Fatal(ElaborationSystemTaskFatal { nodes: (a, b, c) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn elaboration_system_task_error(s: Span) -> IResult<Span, ElaborationSystemTask> {
|
||||||
|
let (s, a) = symbol("$error")(s)?;
|
||||||
|
let (s, b) = opt(paren(opt(list_of_arguments)))(s)?;
|
||||||
|
let (s, c) = symbol(";")(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ElaborationSystemTask::Error(ElaborationSystemTaskError { nodes: (a, b, c) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn elaboration_system_task_warning(s: Span) -> IResult<Span, ElaborationSystemTask> {
|
||||||
|
let (s, a) = symbol("$warning")(s)?;
|
||||||
|
let (s, b) = opt(paren(opt(list_of_arguments)))(s)?;
|
||||||
|
let (s, c) = symbol(";")(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ElaborationSystemTask::Warning(ElaborationSystemTaskWarning { nodes: (a, b, c) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn elaboration_system_task_info(s: Span) -> IResult<Span, ElaborationSystemTask> {
|
||||||
|
let (s, a) = symbol("$info")(s)?;
|
||||||
|
let (s, b) = opt(paren(opt(list_of_arguments)))(s)?;
|
||||||
|
let (s, c) = symbol(";")(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ElaborationSystemTask::Info(ElaborationSystemTaskInfo { nodes: (a, b, c) }),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn finish_number(s: Span) -> IResult<Span, FinishNumber> {
|
pub fn finish_number(s: Span) -> IResult<Span, FinishNumber> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((
|
||||||
|
map(symbol("0"), |x| FinishNumber::Zero(x)),
|
||||||
|
map(symbol("1"), |x| FinishNumber::One(x)),
|
||||||
|
map(symbol("2"), |x| FinishNumber::Two(x)),
|
||||||
|
))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn module_common_item(s: Span) -> IResult<Span, ModuleCommonItem> {
|
pub fn module_common_item(s: Span) -> IResult<Span, ModuleCommonItem> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((
|
||||||
|
map(module_or_generate_item_declaration, |x| {
|
||||||
|
ModuleCommonItem::ModuleOrGenerateItemDeclaration(x)
|
||||||
|
}),
|
||||||
|
map(interface_instantiation, |x| {
|
||||||
|
ModuleCommonItem::InterfaceInstantiation(x)
|
||||||
|
}),
|
||||||
|
map(program_instantiation, |x| {
|
||||||
|
ModuleCommonItem::ProgramInstantiation(x)
|
||||||
|
}),
|
||||||
|
map(assertion_item, |x| ModuleCommonItem::AssertionItem(x)),
|
||||||
|
map(bind_directive, |x| ModuleCommonItem::BindDirective(x)),
|
||||||
|
map(continuous_assign, |x| ModuleCommonItem::ContinuousAssign(x)),
|
||||||
|
map(net_alias, |x| ModuleCommonItem::NetAlias(x)),
|
||||||
|
map(initial_construct, |x| ModuleCommonItem::InitialConstruct(x)),
|
||||||
|
map(final_construct, |x| ModuleCommonItem::FinalConstruct(x)),
|
||||||
|
map(always_construct, |x| ModuleCommonItem::AlwaysConstruct(x)),
|
||||||
|
map(loop_generate_construct, |x| {
|
||||||
|
ModuleCommonItem::LoopGenerateConstruct(Box::new(x))
|
||||||
|
}),
|
||||||
|
map(conditional_generate_construct, |x| {
|
||||||
|
ModuleCommonItem::ConditionalGenerateConstruct(Box::new(x))
|
||||||
|
}),
|
||||||
|
map(elaboration_system_task, |x| {
|
||||||
|
ModuleCommonItem::ElaborationSystemTask(x)
|
||||||
|
}),
|
||||||
|
))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn module_item(s: Span) -> IResult<Span, ModuleItem> {
|
pub fn module_item(s: Span) -> IResult<Span, ModuleItem> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((
|
||||||
|
map(pair(port_declaration, symbol(";")), |x| {
|
||||||
|
ModuleItem::PortDeclaration(x)
|
||||||
|
}),
|
||||||
|
map(non_port_module_item, |x| ModuleItem::NonPortModuleItem(x)),
|
||||||
|
))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn module_or_generate_item(s: Span) -> IResult<Span, ModuleOrGenerateItem> {
|
pub fn module_or_generate_item(s: Span) -> IResult<Span, ModuleOrGenerateItem> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((
|
||||||
|
module_or_generate_item_parameter,
|
||||||
|
module_or_generate_item_gate,
|
||||||
|
module_or_generate_item_udp,
|
||||||
|
module_or_generate_item_module,
|
||||||
|
module_or_generate_item_module_item,
|
||||||
|
))(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn module_or_generate_item_parameter(s: Span) -> IResult<Span, ModuleOrGenerateItem> {
|
||||||
|
let (s, a) = many0(attribute_instance)(s)?;
|
||||||
|
let (s, b) = parameter_override(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ModuleOrGenerateItem::Parameter(ModuleOrGenerateItemParameter { nodes: (a, b) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn module_or_generate_item_gate(s: Span) -> IResult<Span, ModuleOrGenerateItem> {
|
||||||
|
let (s, a) = many0(attribute_instance)(s)?;
|
||||||
|
let (s, b) = gate_instantiation(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ModuleOrGenerateItem::Gate(ModuleOrGenerateItemGate { nodes: (a, b) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn module_or_generate_item_udp(s: Span) -> IResult<Span, ModuleOrGenerateItem> {
|
||||||
|
let (s, a) = many0(attribute_instance)(s)?;
|
||||||
|
let (s, b) = udp_instantiation(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ModuleOrGenerateItem::Udp(ModuleOrGenerateItemUdp { nodes: (a, b) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn module_or_generate_item_module(s: Span) -> IResult<Span, ModuleOrGenerateItem> {
|
||||||
|
let (s, a) = many0(attribute_instance)(s)?;
|
||||||
|
let (s, b) = module_instantiation(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ModuleOrGenerateItem::Module(ModuleOrGenerateItemModule { nodes: (a, b) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn module_or_generate_item_module_item(s: Span) -> IResult<Span, ModuleOrGenerateItem> {
|
||||||
|
let (s, a) = many0(attribute_instance)(s)?;
|
||||||
|
let (s, b) = module_common_item(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ModuleOrGenerateItem::ModuleItem(Box::new(ModuleOrGenerateItemModuleItem {
|
||||||
|
nodes: (a, b),
|
||||||
|
})),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn module_or_generate_item_declaration(
|
pub fn module_or_generate_item_declaration(
|
||||||
s: Span,
|
s: Span,
|
||||||
) -> IResult<Span, ModuleOrGenerateItemDeclaration> {
|
) -> IResult<Span, ModuleOrGenerateItemDeclaration> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((
|
||||||
|
map(package_or_generate_item_declaration, |x| {
|
||||||
|
ModuleOrGenerateItemDeclaration::PackageOrGenerateItemDeclaration(x)
|
||||||
|
}),
|
||||||
|
map(genvar_declaration, |x| {
|
||||||
|
ModuleOrGenerateItemDeclaration::GenvarDeclaration(x)
|
||||||
|
}),
|
||||||
|
map(clocking_declaration, |x| {
|
||||||
|
ModuleOrGenerateItemDeclaration::ClockingDeclaration(x)
|
||||||
|
}),
|
||||||
|
module_or_generate_item_declaration_clocking,
|
||||||
|
module_or_generate_item_declaration_disable,
|
||||||
|
))(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn module_or_generate_item_declaration_clocking(
|
||||||
|
s: Span,
|
||||||
|
) -> IResult<Span, ModuleOrGenerateItemDeclaration> {
|
||||||
|
let (s, a) = symbol("default")(s)?;
|
||||||
|
let (s, b) = symbol("clocking")(s)?;
|
||||||
|
let (s, c) = clocking_identifier(s)?;
|
||||||
|
let (s, d) = symbol(";")(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ModuleOrGenerateItemDeclaration::Clocking(ModuleOrGenerateItemDeclarationClocking {
|
||||||
|
nodes: (a, b, c, d),
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn module_or_generate_item_declaration_disable(
|
||||||
|
s: Span,
|
||||||
|
) -> IResult<Span, ModuleOrGenerateItemDeclaration> {
|
||||||
|
let (s, a) = symbol("default")(s)?;
|
||||||
|
let (s, b) = symbol("disable")(s)?;
|
||||||
|
let (s, c) = symbol("iff")(s)?;
|
||||||
|
let (s, d) = expression_or_dist(s)?;
|
||||||
|
let (s, e) = symbol(";")(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ModuleOrGenerateItemDeclaration::Disable(ModuleOrGenerateItemDeclarationDisable {
|
||||||
|
nodes: (a, b, c, d, e),
|
||||||
|
}),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn non_port_module_item(s: Span) -> IResult<Span, NonPortModuleItem> {
|
pub fn non_port_module_item(s: Span) -> IResult<Span, NonPortModuleItem> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((
|
||||||
|
map(generate_region, |x| NonPortModuleItem::GenerateRegion(x)),
|
||||||
|
map(module_or_generate_item, |x| {
|
||||||
|
NonPortModuleItem::ModuleOrGenerateItem(x)
|
||||||
|
}),
|
||||||
|
map(specify_block, |x| NonPortModuleItem::SpecifyBlock(x)),
|
||||||
|
non_port_module_item_specparam,
|
||||||
|
map(program_declaration, |x| {
|
||||||
|
NonPortModuleItem::ProgramDeclaration(x)
|
||||||
|
}),
|
||||||
|
map(module_declaration, |x| {
|
||||||
|
NonPortModuleItem::ModuleDeclaration(x)
|
||||||
|
}),
|
||||||
|
map(interface_declaration, |x| {
|
||||||
|
NonPortModuleItem::InterfaceDeclaration(x)
|
||||||
|
}),
|
||||||
|
map(timeunits_declaration, |x| {
|
||||||
|
NonPortModuleItem::TimeunitsDeclaration(x)
|
||||||
|
}),
|
||||||
|
))(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn non_port_module_item_specparam(s: Span) -> IResult<Span, NonPortModuleItem> {
|
||||||
|
let (s, a) = many0(attribute_instance)(s)?;
|
||||||
|
let (s, b) = specparam_declaration(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
NonPortModuleItem::Specparam(NonPortModuleItemSpecparam { nodes: (a, b) }),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parameter_override(s: Span) -> IResult<Span, ParameterOverride> {
|
pub fn parameter_override(s: Span) -> IResult<Span, ParameterOverride> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
let (s, a) = symbol("defparam")(s)?;
|
||||||
|
let (s, b) = list_of_defparam_assignments(s)?;
|
||||||
|
let (s, c) = symbol(";")(s)?;
|
||||||
|
Ok((s, ParameterOverride { nodes: (a, b, c) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bind_directive(s: Span) -> IResult<Span, BindDirective> {
|
pub fn bind_directive(s: Span) -> IResult<Span, BindDirective> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((bind_directive_scope, bind_directive_instance))(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn bind_directive_scope(s: Span) -> IResult<Span, BindDirective> {
|
||||||
|
let (s, a) = symbol("bind")(s)?;
|
||||||
|
let (s, b) = bind_target_scope(s)?;
|
||||||
|
let (s, c) = opt(pair(symbol(":"), bind_target_instance_list))(s)?;
|
||||||
|
let (s, d) = bind_instantiation(s)?;
|
||||||
|
let (s, e) = symbol(";")(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
BindDirective::Scope(BindDirectiveScope {
|
||||||
|
nodes: (a, b, c, d, e),
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn bind_directive_instance(s: Span) -> IResult<Span, BindDirective> {
|
||||||
|
let (s, a) = symbol("bind")(s)?;
|
||||||
|
let (s, b) = bind_target_instance(s)?;
|
||||||
|
let (s, c) = bind_instantiation(s)?;
|
||||||
|
let (s, d) = symbol(";")(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
BindDirective::Instance(BindDirectiveInstance {
|
||||||
|
nodes: (a, b, c, d),
|
||||||
|
}),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bind_target_scope(s: Span) -> IResult<Span, BindTargetScope> {
|
pub fn bind_target_scope(s: Span) -> IResult<Span, BindTargetScope> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((
|
||||||
|
map(module_identifier, |x| BindTargetScope::ModuleIdentifier(x)),
|
||||||
|
map(interface_identifier, |x| {
|
||||||
|
BindTargetScope::InterfaceIdentifier(x)
|
||||||
|
}),
|
||||||
|
))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bind_target_instance(s: Span) -> IResult<Span, BindTargetInstance> {
|
pub fn bind_target_instance(s: Span) -> IResult<Span, BindTargetInstance> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
let (s, a) = hierarchical_identifier(s)?;
|
||||||
|
let (s, b) = constant_bit_select(s)?;
|
||||||
|
Ok((s, BindTargetInstance { nodes: (a, b) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bind_target_instance_list(s: Span) -> IResult<Span, BindTargetInstanceList> {
|
pub fn bind_target_instance_list(s: Span) -> IResult<Span, BindTargetInstanceList> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
let (s, a) = list(symbol(","), bind_target_instance)(s)?;
|
||||||
|
Ok((s, BindTargetInstanceList { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bind_instantiation(s: Span) -> IResult<Span, BindInstantiation> {
|
pub fn bind_instantiation(s: Span) -> IResult<Span, BindInstantiation> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((
|
||||||
|
map(program_instantiation, |x| {
|
||||||
|
BindInstantiation::ProgramInstantiation(x)
|
||||||
|
}),
|
||||||
|
map(module_instantiation, |x| {
|
||||||
|
BindInstantiation::ModuleInstantiation(x)
|
||||||
|
}),
|
||||||
|
map(interface_instantiation, |x| {
|
||||||
|
BindInstantiation::InterfaceInstantiation(x)
|
||||||
|
}),
|
||||||
|
map(checker_instantiation, |x| {
|
||||||
|
BindInstantiation::CheckerInstantiation(x)
|
||||||
|
}),
|
||||||
|
))(s)
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
use crate::ast::*;
|
use crate::ast::*;
|
||||||
use crate::parser::*;
|
use crate::parser::*;
|
||||||
//use nom::branch::*;
|
use nom::branch::*;
|
||||||
//use nom::combinator::*;
|
use nom::combinator::*;
|
||||||
use nom::error::*;
|
use nom::multi::*;
|
||||||
use nom::{Err, IResult};
|
use nom::sequence::*;
|
||||||
|
use nom::IResult;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -11,20 +12,29 @@ use nom::{Err, IResult};
|
|||||||
pub enum ParameterPortList<'a> {
|
pub enum ParameterPortList<'a> {
|
||||||
Assignment(ParameterPortListAssignment<'a>),
|
Assignment(ParameterPortListAssignment<'a>),
|
||||||
Declaration(ParameterPortListDeclaration<'a>),
|
Declaration(ParameterPortListDeclaration<'a>),
|
||||||
Empty(Symbol<'a>),
|
Empty((Symbol<'a>, Symbol<'a>, Symbol<'a>)),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct ParameterPortListAssignment<'a> {
|
pub struct ParameterPortListAssignment<'a> {
|
||||||
pub nodes: (
|
pub nodes: (
|
||||||
ListOfParamAssignments<'a>,
|
Symbol<'a>,
|
||||||
Vec<ParameterPortDeclaration<'a>>,
|
Paren<
|
||||||
|
'a,
|
||||||
|
(
|
||||||
|
ListOfParamAssignments<'a>,
|
||||||
|
Vec<(Symbol<'a>, ParameterPortDeclaration<'a>)>,
|
||||||
|
),
|
||||||
|
>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct ParameterPortListDeclaration<'a> {
|
pub struct ParameterPortListDeclaration<'a> {
|
||||||
pub nodes: (Vec<ParameterPortDeclaration<'a>>,),
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
|
Paren<'a, List<Symbol<'a>, ParameterPortDeclaration<'a>>>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
@ -42,17 +52,19 @@ pub struct ParameterPortDeclarationParamList<'a> {
|
|||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct ParameterPortDeclarationTypeList<'a> {
|
pub struct ParameterPortDeclarationTypeList<'a> {
|
||||||
pub nodes: (ListOfTypeAssignments<'a>,),
|
pub nodes: (Symbol<'a>, ListOfTypeAssignments<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct ListOfPorts<'a> {
|
pub struct ListOfPorts<'a> {
|
||||||
pub nodes: (Vec<Port<'a>>,),
|
pub nodes: (Paren<'a, List<Symbol<'a>, Port<'a>>>,),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct ListOfPortDeclarations<'a> {
|
pub struct ListOfPortDeclarations<'a> {
|
||||||
pub nodes: (Option<Vec<(Vec<AttributeInstance<'a>>, AnsiPortDeclaration<'a>)>>,),
|
pub nodes: (
|
||||||
|
Paren<'a, Option<List<Symbol<'a>, (Vec<AttributeInstance<'a>>, AnsiPortDeclaration<'a>)>>>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
@ -102,18 +114,22 @@ pub struct PortNonNamed<'a> {
|
|||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct PortNamed<'a> {
|
pub struct PortNamed<'a> {
|
||||||
pub nodes: (PortIdentifier<'a>, Option<PortExpression<'a>>),
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
|
PortIdentifier<'a>,
|
||||||
|
Paren<'a, Option<PortExpression<'a>>>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub enum PortExpression<'a> {
|
pub enum PortExpression<'a> {
|
||||||
PortReference(PortReference<'a>),
|
PortReference(PortReference<'a>),
|
||||||
Bracket(PortExpressionBracket<'a>),
|
Brace(PortExpressionBrace<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct PortExpressionBracket<'a> {
|
pub struct PortExpressionBrace<'a> {
|
||||||
pub nodes: (Vec<PortReference<'a>>,),
|
pub nodes: (Brace<'a, List<Symbol<'a>, PortReference<'a>>>,),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
@ -147,12 +163,15 @@ pub enum InterfacePortHeader<'a> {
|
|||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct InterfacePortHeaderIdentifier<'a> {
|
pub struct InterfacePortHeaderIdentifier<'a> {
|
||||||
pub nodes: (InterfaceIdentifier<'a>, Option<ModportIdentifier<'a>>),
|
pub nodes: (
|
||||||
|
InterfaceIdentifier<'a>,
|
||||||
|
Option<(Symbol<'a>, ModportIdentifier<'a>)>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
pub struct InterfacePortHeaderInterface<'a> {
|
pub struct InterfacePortHeaderInterface<'a> {
|
||||||
pub nodes: (Option<ModportIdentifier<'a>>,),
|
pub nodes: (Symbol<'a>, Option<(Symbol<'a>, ModportIdentifier<'a>)>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Node)]
|
#[derive(Debug, Node)]
|
||||||
@ -173,7 +192,7 @@ pub struct AnsiPortDeclarationNet<'a> {
|
|||||||
Option<NetPortHeaderOrInterfacePortHeader<'a>>,
|
Option<NetPortHeaderOrInterfacePortHeader<'a>>,
|
||||||
PortIdentifier<'a>,
|
PortIdentifier<'a>,
|
||||||
Vec<UnpackedDimension<'a>>,
|
Vec<UnpackedDimension<'a>>,
|
||||||
Option<ConstantExpression<'a>>,
|
Option<(Symbol<'a>, ConstantExpression<'a>)>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +202,7 @@ pub struct AnsiPortDeclarationVariable<'a> {
|
|||||||
Option<VariablePortHeader<'a>>,
|
Option<VariablePortHeader<'a>>,
|
||||||
PortIdentifier<'a>,
|
PortIdentifier<'a>,
|
||||||
Vec<VariableDimension<'a>>,
|
Vec<VariableDimension<'a>>,
|
||||||
Option<ConstantExpression<'a>>,
|
Option<(Symbol<'a>, ConstantExpression<'a>)>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,61 +210,288 @@ pub struct AnsiPortDeclarationVariable<'a> {
|
|||||||
pub struct AnsiPortDeclarationParen<'a> {
|
pub struct AnsiPortDeclarationParen<'a> {
|
||||||
pub nodes: (
|
pub nodes: (
|
||||||
Option<PortDirection<'a>>,
|
Option<PortDirection<'a>>,
|
||||||
|
Symbol<'a>,
|
||||||
PortIdentifier<'a>,
|
PortIdentifier<'a>,
|
||||||
Option<Expression<'a>>,
|
Paren<'a, Option<Expression<'a>>>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
pub fn parameter_port_list(s: Span) -> IResult<Span, ParameterPortList> {
|
pub fn parameter_port_list(s: Span) -> IResult<Span, ParameterPortList> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((
|
||||||
|
parameter_port_list_assignment,
|
||||||
|
parameter_port_list_declaration,
|
||||||
|
parameter_port_list_empty,
|
||||||
|
))(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parameter_port_list_assignment(s: Span) -> IResult<Span, ParameterPortList> {
|
||||||
|
let (s, a) = symbol("#")(s)?;
|
||||||
|
let (s, b) = paren(pair(
|
||||||
|
list_of_param_assignments,
|
||||||
|
many0(pair(symbol(","), parameter_port_declaration)),
|
||||||
|
))(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ParameterPortList::Assignment(ParameterPortListAssignment { nodes: (a, b) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parameter_port_list_declaration(s: Span) -> IResult<Span, ParameterPortList> {
|
||||||
|
let (s, a) = symbol("#")(s)?;
|
||||||
|
let (s, b) = paren(list(symbol(","), parameter_port_declaration))(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ParameterPortList::Declaration(ParameterPortListDeclaration { nodes: (a, b) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parameter_port_list_empty(s: Span) -> IResult<Span, ParameterPortList> {
|
||||||
|
let (s, a) = symbol("#")(s)?;
|
||||||
|
let (s, b) = symbol("(")(s)?;
|
||||||
|
let (s, c) = symbol(")")(s)?;
|
||||||
|
Ok((s, ParameterPortList::Empty((a, b, c))))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parameter_port_declaration(s: Span) -> IResult<Span, ParameterPortDeclaration> {
|
pub fn parameter_port_declaration(s: Span) -> IResult<Span, ParameterPortDeclaration> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((
|
||||||
|
map(parameter_declaration, |x| {
|
||||||
|
ParameterPortDeclaration::ParameterDeclaration(x)
|
||||||
|
}),
|
||||||
|
map(local_parameter_declaration, |x| {
|
||||||
|
ParameterPortDeclaration::LocalParameterDeclaration(x)
|
||||||
|
}),
|
||||||
|
parameter_port_declaration_param_list,
|
||||||
|
parameter_port_declaration_type_list,
|
||||||
|
))(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parameter_port_declaration_param_list(s: Span) -> IResult<Span, ParameterPortDeclaration> {
|
||||||
|
let (s, a) = data_type(s)?;
|
||||||
|
let (s, b) = list_of_param_assignments(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ParameterPortDeclaration::ParamList(ParameterPortDeclarationParamList { nodes: (a, b) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parameter_port_declaration_type_list(s: Span) -> IResult<Span, ParameterPortDeclaration> {
|
||||||
|
let (s, a) = symbol("type")(s)?;
|
||||||
|
let (s, b) = list_of_type_assignments(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ParameterPortDeclaration::TypeList(ParameterPortDeclarationTypeList { nodes: (a, b) }),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_of_ports(s: Span) -> IResult<Span, ListOfPorts> {
|
pub fn list_of_ports(s: Span) -> IResult<Span, ListOfPorts> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
let (s, a) = paren(list(symbol(","), port))(s)?;
|
||||||
|
Ok((s, ListOfPorts { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_of_port_declarations(s: Span) -> IResult<Span, ListOfPortDeclarations> {
|
pub fn list_of_port_declarations(s: Span) -> IResult<Span, ListOfPortDeclarations> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
let (s, a) = paren(opt(list(
|
||||||
|
symbol(","),
|
||||||
|
pair(many0(attribute_instance), ansi_port_declaration),
|
||||||
|
)))(s)?;
|
||||||
|
Ok((s, ListOfPortDeclarations { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn port_declaration(s: Span) -> IResult<Span, PortDeclaration> {
|
pub fn port_declaration(s: Span) -> IResult<Span, PortDeclaration> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((
|
||||||
|
port_declaration_inout,
|
||||||
|
port_declaration_input,
|
||||||
|
port_declaration_output,
|
||||||
|
port_declaration_ref,
|
||||||
|
port_declaration_interface,
|
||||||
|
))(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn port_declaration_inout(s: Span) -> IResult<Span, PortDeclaration> {
|
||||||
|
let (s, a) = many0(attribute_instance)(s)?;
|
||||||
|
let (s, b) = inout_declaration(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
PortDeclaration::Inout(PortDeclarationInout { nodes: (a, b) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn port_declaration_input(s: Span) -> IResult<Span, PortDeclaration> {
|
||||||
|
let (s, a) = many0(attribute_instance)(s)?;
|
||||||
|
let (s, b) = input_declaration(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
PortDeclaration::Input(PortDeclarationInput { nodes: (a, b) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn port_declaration_output(s: Span) -> IResult<Span, PortDeclaration> {
|
||||||
|
let (s, a) = many0(attribute_instance)(s)?;
|
||||||
|
let (s, b) = output_declaration(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
PortDeclaration::Output(PortDeclarationOutput { nodes: (a, b) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn port_declaration_ref(s: Span) -> IResult<Span, PortDeclaration> {
|
||||||
|
let (s, a) = many0(attribute_instance)(s)?;
|
||||||
|
let (s, b) = ref_declaration(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
PortDeclaration::Ref(PortDeclarationRef { nodes: (a, b) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn port_declaration_interface(s: Span) -> IResult<Span, PortDeclaration> {
|
||||||
|
let (s, a) = many0(attribute_instance)(s)?;
|
||||||
|
let (s, b) = interface_port_declaration(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
PortDeclaration::Interface(PortDeclarationInterface { nodes: (a, b) }),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn port(s: Span) -> IResult<Span, Port> {
|
pub fn port(s: Span) -> IResult<Span, Port> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((port_non_named, port_named))(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn port_non_named(s: Span) -> IResult<Span, Port> {
|
||||||
|
let (s, a) = opt(port_expression)(s)?;
|
||||||
|
Ok((s, Port::NonNamed(PortNonNamed { nodes: (a,) })))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn port_named(s: Span) -> IResult<Span, Port> {
|
||||||
|
let (s, a) = symbol(".")(s)?;
|
||||||
|
let (s, b) = port_identifier(s)?;
|
||||||
|
let (s, c) = paren(opt(port_expression))(s)?;
|
||||||
|
Ok((s, Port::Named(PortNamed { nodes: (a, b, c) })))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn port_expression(s: Span) -> IResult<Span, PortExpression> {
|
pub fn port_expression(s: Span) -> IResult<Span, PortExpression> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((
|
||||||
|
map(port_reference, |x| PortExpression::PortReference(x)),
|
||||||
|
port_expressio_named,
|
||||||
|
))(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn port_expressio_named(s: Span) -> IResult<Span, PortExpression> {
|
||||||
|
let (s, a) = brace(list(symbol(","), port_reference))(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
PortExpression::Brace(PortExpressionBrace { nodes: (a,) }),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn port_reference(s: Span) -> IResult<Span, PortReference> {
|
pub fn port_reference(s: Span) -> IResult<Span, PortReference> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
let (s, a) = port_identifier(s)?;
|
||||||
|
let (s, b) = constant_select(s)?;
|
||||||
|
Ok((s, PortReference { nodes: (a, b) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn port_direction(s: Span) -> IResult<Span, PortDirection> {
|
pub fn port_direction(s: Span) -> IResult<Span, PortDirection> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((
|
||||||
|
map(symbol("input"), |x| PortDirection::Input(x)),
|
||||||
|
map(symbol("output"), |x| PortDirection::Output(x)),
|
||||||
|
map(symbol("inout"), |x| PortDirection::Inout(x)),
|
||||||
|
map(symbol("ref"), |x| PortDirection::Ref(x)),
|
||||||
|
))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn net_port_header(s: Span) -> IResult<Span, NetPortHeader> {
|
pub fn net_port_header(s: Span) -> IResult<Span, NetPortHeader> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
let (s, a) = opt(port_direction)(s)?;
|
||||||
|
let (s, b) = net_port_type(s)?;
|
||||||
|
Ok((s, NetPortHeader { nodes: (a, b) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn variable_port_header(s: Span) -> IResult<Span, VariablePortHeader> {
|
pub fn variable_port_header(s: Span) -> IResult<Span, VariablePortHeader> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
let (s, a) = opt(port_direction)(s)?;
|
||||||
|
let (s, b) = variable_port_type(s)?;
|
||||||
|
Ok((s, VariablePortHeader { nodes: (a, b) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn interface_port_header(s: Span) -> IResult<Span, InterfacePortHeader> {
|
pub fn interface_port_header(s: Span) -> IResult<Span, InterfacePortHeader> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((
|
||||||
|
interface_port_header_identifier,
|
||||||
|
interface_port_header_interface,
|
||||||
|
))(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn interface_port_header_identifier(s: Span) -> IResult<Span, InterfacePortHeader> {
|
||||||
|
let (s, a) = interface_identifier(s)?;
|
||||||
|
let (s, b) = opt(pair(symbol("."), modport_identifier))(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
InterfacePortHeader::Identifier(InterfacePortHeaderIdentifier { nodes: (a, b) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn interface_port_header_interface(s: Span) -> IResult<Span, InterfacePortHeader> {
|
||||||
|
let (s, a) = symbol("interface")(s)?;
|
||||||
|
let (s, b) = opt(pair(symbol("."), modport_identifier))(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
InterfacePortHeader::Interface(InterfacePortHeaderInterface { nodes: (a, b) }),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ansi_port_declaration(s: Span) -> IResult<Span, AnsiPortDeclaration> {
|
pub fn ansi_port_declaration(s: Span) -> IResult<Span, AnsiPortDeclaration> {
|
||||||
Err(Err::Error(make_error(s, ErrorKind::Fix)))
|
alt((
|
||||||
|
ansi_port_declaration_net,
|
||||||
|
ansi_port_declaration_port,
|
||||||
|
ansi_port_declaration_paren,
|
||||||
|
))(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ansi_port_declaration_net(s: Span) -> IResult<Span, AnsiPortDeclaration> {
|
||||||
|
let (s, a) = opt(net_port_header_or_interface_port_header)(s)?;
|
||||||
|
let (s, b) = port_identifier(s)?;
|
||||||
|
let (s, c) = many0(unpacked_dimension)(s)?;
|
||||||
|
let (s, d) = opt(pair(symbol("="), constant_expression))(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
AnsiPortDeclaration::Net(AnsiPortDeclarationNet {
|
||||||
|
nodes: (a, b, c, d),
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn net_port_header_or_interface_port_header(
|
||||||
|
s: Span,
|
||||||
|
) -> IResult<Span, NetPortHeaderOrInterfacePortHeader> {
|
||||||
|
alt((
|
||||||
|
map(net_port_header, |x| {
|
||||||
|
NetPortHeaderOrInterfacePortHeader::NetPortHeader(x)
|
||||||
|
}),
|
||||||
|
map(interface_port_header, |x| {
|
||||||
|
NetPortHeaderOrInterfacePortHeader::InterfacePortHeader(x)
|
||||||
|
}),
|
||||||
|
))(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ansi_port_declaration_port(s: Span) -> IResult<Span, AnsiPortDeclaration> {
|
||||||
|
let (s, a) = opt(variable_port_header)(s)?;
|
||||||
|
let (s, b) = port_identifier(s)?;
|
||||||
|
let (s, c) = many0(variable_dimension)(s)?;
|
||||||
|
let (s, d) = opt(pair(symbol("="), constant_expression))(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
AnsiPortDeclaration::Variable(AnsiPortDeclarationVariable {
|
||||||
|
nodes: (a, b, c, d),
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ansi_port_declaration_paren(s: Span) -> IResult<Span, AnsiPortDeclaration> {
|
||||||
|
let (s, a) = opt(port_direction)(s)?;
|
||||||
|
let (s, b) = symbol(".")(s)?;
|
||||||
|
let (s, c) = port_identifier(s)?;
|
||||||
|
let (s, d) = paren(opt(expression))(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
AnsiPortDeclaration::Paren(AnsiPortDeclarationParen {
|
||||||
|
nodes: (a, b, c, d),
|
||||||
|
}),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user