diff --git a/README.md b/README.md index d65a349..76dd8ff 100644 --- a/README.md +++ b/README.md @@ -21,13 +21,13 @@ A parser library for System Verilog. | declaration | type_declarations | | | | | declaration | net_and_variable_types | | | | | declaration | strengths | | | | -| declaration | delays | | | | +| declaration | delays | x | | | | declaration | declaration_lists | | | | | declaration | declaration_assignments | | | | | declaration | declaration_ranges | | | | | declaration | function_declarations | | | | | declaration | task_declarations | | | | -| declaration | block_item_declarations | | | | +| declaration | block_item_declarations | x | x | | | declaration | interface_declarations | | | | | declaration | assertion_declarations | | | | | declaration | covergroup_declarations | | | | @@ -40,7 +40,7 @@ A parser library for System Verilog. | instantiations | interface_instantiation | x | x | | | instantiations | program_instantiation | x | x | | | instantiations | checker_instantiation | x | x | | -| instantiations | generated_instantiation | | | | +| instantiations | generated_instantiation | x | x | | | udp_declaration_and_instantiation | udp_declaration | | | | | udp_declaration_and_instantiation | udp_ports | | | | | udp_declaration_and_instantiation | udp_body | | | | diff --git a/src/parser/declarations/block_item_declarations.rs b/src/parser/declarations/block_item_declarations.rs index 88a25df..bd7831e 100644 --- a/src/parser/declarations/block_item_declarations.rs +++ b/src/parser/declarations/block_item_declarations.rs @@ -1,8 +1,7 @@ use crate::parser::*; -//use nom::branch::*; -//use nom::combinator::*; -use nom::error::*; -use nom::{Err, IResult}; +use nom::branch::*; +use nom::multi::*; +use nom::IResult; // ----------------------------------------------------------------------------- @@ -21,12 +20,20 @@ pub struct BlockItemDeclarationData<'a> { #[derive(Debug)] pub struct BlockItemDeclarationLocalParameter<'a> { - pub nodes: (Vec>, LocalParameterDeclaration<'a>), + pub nodes: ( + Vec>, + LocalParameterDeclaration<'a>, + Symbol<'a>, + ), } #[derive(Debug)] pub struct BlockItemDeclarationParameter<'a> { - pub nodes: (Vec>, ParameterDeclaration<'a>), + pub nodes: ( + Vec>, + ParameterDeclaration<'a>, + Symbol<'a>, + ), } #[derive(Debug)] @@ -37,5 +44,50 @@ pub struct BlockItemDeclarationLet<'a> { // ----------------------------------------------------------------------------- pub fn block_item_declaration(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + block_item_declaration_data, + block_item_declaration_local_parameter, + block_item_declaration_parameter, + block_item_declaration_let, + ))(s) +} + +pub fn block_item_declaration_data(s: Span) -> IResult { + let (s, a) = many0(attribute_instance)(s)?; + let (s, b) = data_declaration(s)?; + Ok(( + s, + BlockItemDeclaration::Data(BlockItemDeclarationData { nodes: (a, b) }), + )) +} + +pub fn block_item_declaration_local_parameter(s: Span) -> IResult { + let (s, a) = many0(attribute_instance)(s)?; + let (s, b) = local_parameter_declaration(s)?; + let (s, c) = symbol(";")(s)?; + Ok(( + s, + BlockItemDeclaration::LocalParameter(BlockItemDeclarationLocalParameter { + nodes: (a, b, c), + }), + )) +} + +pub fn block_item_declaration_parameter(s: Span) -> IResult { + let (s, a) = many0(attribute_instance)(s)?; + let (s, b) = parameter_declaration(s)?; + let (s, c) = symbol(";")(s)?; + Ok(( + s, + BlockItemDeclaration::Parameter(BlockItemDeclarationParameter { nodes: (a, b, c) }), + )) +} + +pub fn block_item_declaration_let(s: Span) -> IResult { + let (s, a) = many0(attribute_instance)(s)?; + let (s, b) = let_declaration(s)?; + Ok(( + s, + BlockItemDeclaration::Let(BlockItemDeclarationLet { nodes: (a, b) }), + )) } diff --git a/src/parser/declarations/delays.rs b/src/parser/declarations/delays.rs index f46a51e..48216e6 100644 --- a/src/parser/declarations/delays.rs +++ b/src/parser/declarations/delays.rs @@ -8,27 +8,46 @@ use nom::{Err, IResult}; #[derive(Debug)] pub enum Delay3<'a> { - DelayValue(DelayValue<'a>), + Single(Delay3Single<'a>), Mintypmax(Delay3Mintypmax<'a>), } +#[derive(Debug)] +pub struct Delay3Single<'a> { + pub nodes: (Symbol<'a>, DelayValue<'a>), +} + #[derive(Debug)] pub struct Delay3Mintypmax<'a> { pub nodes: ( - MintypmaxExpression<'a>, - Option<(MintypmaxExpression<'a>, Option>)>, + Symbol<'a>, + Paren< + 'a, + ( + MintypmaxExpression<'a>, + Option<(MintypmaxExpression<'a>, Option>)>, + ), + >, ), } #[derive(Debug)] pub enum Delay2<'a> { - DelayValue(DelayValue<'a>), + Single(Delay2Single<'a>), Mintypmax(Delay2Mintypmax<'a>), } +#[derive(Debug)] +pub struct Delay2Single<'a> { + pub nodes: (Symbol<'a>, DelayValue<'a>), +} + #[derive(Debug)] pub struct Delay2Mintypmax<'a> { - pub nodes: (MintypmaxExpression<'a>, Option>), + pub nodes: ( + Symbol<'a>, + Paren<'a, (MintypmaxExpression<'a>, Option>)>, + ), } #[derive(Debug)] @@ -37,7 +56,7 @@ pub enum DelayValue<'a> { RealNumber(RealNumber<'a>), Identifier(Identifier<'a>), TimeLiteral(TimeLiteral<'a>), - Step1, + Step1(Symbol<'a>), } // ----------------------------------------------------------------------------- diff --git a/src/parser/instantiations/generated_instantiation.rs b/src/parser/instantiations/generated_instantiation.rs index 8864549..10c9f78 100644 --- a/src/parser/instantiations/generated_instantiation.rs +++ b/src/parser/instantiations/generated_instantiation.rs @@ -9,26 +9,41 @@ use nom::IResult; #[derive(Debug)] pub struct GenerateRegion<'a> { - pub nodes: (Vec>,), + pub nodes: (Symbol<'a>, Vec>, Symbol<'a>), } #[derive(Debug)] pub struct LoopGenerateConstruct<'a> { pub nodes: ( - GenvarInitialization<'a>, - GenvarExpression<'a>, - GenvarIteration<'a>, + Symbol<'a>, + Paren< + 'a, + ( + GenvarInitialization<'a>, + Symbol<'a>, + GenvarExpression<'a>, + Symbol<'a>, + GenvarIteration<'a>, + ), + >, GenerateBlock<'a>, ), } #[derive(Debug)] pub struct GenvarInitialization<'a> { - pub nodes: (Option, GenvarIdentifier<'a>, ConstantExpression<'a>), + pub nodes: ( + Option>, + GenvarIdentifier<'a>, + Symbol<'a>, + ConstantExpression<'a>, + ), } #[derive(Debug)] -pub struct Genvar {} +pub struct Genvar<'a> { + pub nodes: (Symbol<'a>,), +} #[derive(Debug)] pub enum GenvarIteration<'a> { @@ -65,15 +80,21 @@ pub enum ConditionalGenerateConstruct<'a> { #[derive(Debug)] pub struct IfGenerateConstruct<'a> { pub nodes: ( - ConstantExpression<'a>, + Symbol<'a>, + Paren<'a, ConstantExpression<'a>>, GenerateBlock<'a>, - Option>, + Option<(Symbol<'a>, GenerateBlock<'a>)>, ), } #[derive(Debug)] pub struct CaseGenerateConstruct<'a> { - pub nodes: (ConstantExpression<'a>, Vec>), + pub nodes: ( + Symbol<'a>, + Paren<'a, ConstantExpression<'a>>, + Vec>, + Symbol<'a>, + ), } #[derive(Debug)] @@ -84,73 +105,74 @@ pub enum CaseGenerateItem<'a> { #[derive(Debug)] pub struct CaseGenerateItemNondefault<'a> { - pub nodes: (Vec>, GenerateBlock<'a>), + pub nodes: ( + List, ConstantExpression<'a>>, + Symbol<'a>, + GenerateBlock<'a>, + ), } #[derive(Debug)] pub struct CaseGenerateItemDefault<'a> { - pub nodes: (GenerateBlock<'a>,), + pub nodes: (Symbol<'a>, Option>, GenerateBlock<'a>), } #[derive(Debug)] pub enum GenerateBlock<'a> { - Single(GenerateItem<'a>), + GenerateItem(GenerateItem<'a>), Multiple(GenerateBlockMultiple<'a>), } #[derive(Debug)] pub struct GenerateBlockMultiple<'a> { pub nodes: ( - Option>, - Option>, + Option<(GenerateBlockIdentifier<'a>, Symbol<'a>)>, + Symbol<'a>, + Option<(Symbol<'a>, GenerateBlockIdentifier<'a>)>, Vec>, - Option>, + Symbol<'a>, + Option<(Symbol<'a>, GenerateBlockIdentifier<'a>)>, ), } #[derive(Debug)] pub enum GenerateItem<'a> { - Module(ModuleOrGenerateItem<'a>), - Interface(InterfaceOrGenerateItem<'a>), - Checker(CheckerOrGenerateItem<'a>), + ModuleOrGenerateItem(ModuleOrGenerateItem<'a>), + InterfaceOrGenerateItem(InterfaceOrGenerateItem<'a>), + CheckerOrGenerateItem(CheckerOrGenerateItem<'a>), } // ----------------------------------------------------------------------------- pub fn generate_region(s: Span) -> IResult { - let (s, _) = symbol("generate")(s)?; - let (s, x) = many0(generate_item)(s)?; - let (s, _) = symbol("endgenerate")(s)?; - Ok((s, GenerateRegion { nodes: (x,) })) + let (s, a) = symbol("generate")(s)?; + let (s, b) = many0(generate_item)(s)?; + let (s, c) = symbol("endgenerate")(s)?; + Ok((s, GenerateRegion { nodes: (a, b, c) })) } pub fn loop_generate_construct(s: Span) -> IResult { - let (s, _) = symbol("for")(s)?; - let (s, _) = symbol("(")(s)?; - let (s, x) = generate_initialization(s)?; - let (s, _) = symbol(";")(s)?; - let (s, y) = genvar_expression(s)?; - let (s, _) = symbol(";")(s)?; - let (s, z) = genvar_iteration(s)?; - let (s, _) = symbol(")")(s)?; - let (s, v) = generate_block(s)?; - Ok(( - s, - LoopGenerateConstruct { - nodes: (x, y, z, v), - }, - )) + let (s, a) = symbol("for")(s)?; + let (s, b) = paren2(tuple(( + generate_initialization, + symbol(";"), + genvar_expression, + symbol(";"), + genvar_iteration, + )))(s)?; + let (s, c) = generate_block(s)?; + Ok((s, LoopGenerateConstruct { nodes: (a, b, c) })) } pub fn generate_initialization(s: Span) -> IResult { - let (s, x) = opt(symbol("genvar"))(s)?; - let (s, y) = genvar_identifier(s)?; - let (s, _) = symbol("=")(s)?; - let (s, z) = constant_expression(s)?; + let (s, a) = opt(map(symbol("genvar"), |x| Genvar { nodes: (x,) }))(s)?; + let (s, b) = genvar_identifier(s)?; + let (s, c) = symbol("=")(s)?; + let (s, d) = constant_expression(s)?; Ok(( s, GenvarInitialization { - nodes: (x.map(|_| Genvar {}), y, z), + nodes: (a, b, c, d), }, )) } @@ -164,30 +186,30 @@ pub fn genvar_iteration(s: Span) -> IResult { } pub fn genvar_iteration_assignment(s: Span) -> IResult { - let (s, x) = genvar_identifier(s)?; - let (s, y) = assignment_operator(s)?; - let (s, z) = genvar_expression(s)?; + let (s, a) = genvar_identifier(s)?; + let (s, b) = assignment_operator(s)?; + let (s, c) = genvar_expression(s)?; Ok(( s, - GenvarIteration::Assignment(GenvarIterationAssignment { nodes: (x, y, z) }), + GenvarIteration::Assignment(GenvarIterationAssignment { nodes: (a, b, c) }), )) } pub fn genvar_iteration_prefix(s: Span) -> IResult { - let (s, x) = inc_or_dec_operator(s)?; - let (s, y) = genvar_identifier(s)?; + let (s, a) = inc_or_dec_operator(s)?; + let (s, b) = genvar_identifier(s)?; Ok(( s, - GenvarIteration::Prefix(GenvarIterationPrefix { nodes: (x, y) }), + GenvarIteration::Prefix(GenvarIterationPrefix { nodes: (a, b) }), )) } pub fn genvar_iteration_suffix(s: Span) -> IResult { - let (s, x) = genvar_identifier(s)?; - let (s, y) = inc_or_dec_operator(s)?; + let (s, a) = genvar_identifier(s)?; + let (s, b) = inc_or_dec_operator(s)?; Ok(( s, - GenvarIteration::Suffix(GenvarIterationSuffix { nodes: (x, y) }), + GenvarIteration::Suffix(GenvarIterationSuffix { nodes: (a, b) }), )) } @@ -203,19 +225,29 @@ pub fn conditional_generate_construct(s: Span) -> IResult IResult { - let (s, _) = symbol("if")(s)?; - let (s, x) = paren(constant_expression)(s)?; - let (s, y) = generate_block(s)?; - let (s, z) = opt(preceded(symbol("else"), generate_block))(s)?; - Ok((s, IfGenerateConstruct { nodes: (x, y, z) })) + let (s, a) = symbol("if")(s)?; + let (s, b) = paren2(constant_expression)(s)?; + let (s, c) = generate_block(s)?; + let (s, d) = opt(pair(symbol("else"), generate_block))(s)?; + Ok(( + s, + IfGenerateConstruct { + nodes: (a, b, c, d), + }, + )) } pub fn case_generate_construct(s: Span) -> IResult { - let (s, _) = symbol("case")(s)?; - let (s, x) = paren(constant_expression)(s)?; - let (s, y) = many1(case_generate_item)(s)?; - let (s, _) = symbol("endcase")(s)?; - Ok((s, CaseGenerateConstruct { nodes: (x, y) })) + let (s, a) = symbol("case")(s)?; + let (s, b) = paren2(constant_expression)(s)?; + let (s, c) = many1(case_generate_item)(s)?; + let (s, d) = symbol("endcase")(s)?; + Ok(( + s, + CaseGenerateConstruct { + nodes: (a, b, c, d), + }, + )) } pub fn case_generate_item(s: Span) -> IResult { @@ -223,54 +255,58 @@ pub fn case_generate_item(s: Span) -> IResult { } pub fn case_generate_item_nondefault(s: Span) -> IResult { - let (s, x) = separated_nonempty_list(symbol(","), constant_expression)(s)?; - let (s, _) = symbol(":")(s)?; - let (s, y) = generate_block(s)?; + let (s, a) = list(symbol(","), constant_expression)(s)?; + let (s, b) = symbol(":")(s)?; + let (s, c) = generate_block(s)?; Ok(( s, - CaseGenerateItem::Nondefault(CaseGenerateItemNondefault { nodes: (x, y) }), + CaseGenerateItem::Nondefault(CaseGenerateItemNondefault { nodes: (a, b, c) }), )) } pub fn case_generate_item_default(s: Span) -> IResult { - let (s, _) = symbol("default")(s)?; - let (s, _) = opt(symbol(":"))(s)?; - let (s, x) = generate_block(s)?; + let (s, a) = symbol("default")(s)?; + let (s, b) = opt(symbol(":"))(s)?; + let (s, c) = generate_block(s)?; Ok(( s, - CaseGenerateItem::Default(CaseGenerateItemDefault { nodes: (x,) }), + CaseGenerateItem::Default(CaseGenerateItemDefault { nodes: (a, b, c) }), )) } pub fn generate_block(s: Span) -> IResult { - alt((generate_block_single, generate_block_multiple))(s) -} - -pub fn generate_block_single(s: Span) -> IResult { - let (s, x) = generate_item(s)?; - Ok((s, GenerateBlock::Single(x))) + alt(( + map(generate_item, |x| GenerateBlock::GenerateItem(x)), + generate_block_multiple, + ))(s) } pub fn generate_block_multiple(s: Span) -> IResult { - let (s, x) = opt(terminated(generate_block_identifier, symbol(":")))(s)?; - let (s, _) = symbol("begin")(s)?; - let (s, y) = opt(preceded(symbol(":"), generate_block_identifier))(s)?; - let (s, z) = many0(generate_item)(s)?; - let (s, _) = symbol("end")(s)?; - let (s, v) = opt(preceded(symbol(":"), generate_block_identifier))(s)?; + let (s, a) = opt(pair(generate_block_identifier, symbol(":")))(s)?; + let (s, b) = symbol("begin")(s)?; + let (s, c) = opt(pair(symbol(":"), generate_block_identifier))(s)?; + let (s, d) = many0(generate_item)(s)?; + let (s, e) = symbol("end")(s)?; + let (s, f) = opt(pair(symbol(":"), generate_block_identifier))(s)?; Ok(( s, GenerateBlock::Multiple(GenerateBlockMultiple { - nodes: (x, y, z, v), + nodes: (a, b, c, d, e, f), }), )) } pub fn generate_item(s: Span) -> IResult { alt(( - map(module_or_generate_item, |x| GenerateItem::Module(x)), - map(interface_or_generate_item, |x| GenerateItem::Interface(x)), - map(checker_or_generate_item, |x| GenerateItem::Checker(x)), + map(module_or_generate_item, |x| { + GenerateItem::ModuleOrGenerateItem(x) + }), + map(interface_or_generate_item, |x| { + GenerateItem::InterfaceOrGenerateItem(x) + }), + map(checker_or_generate_item, |x| { + GenerateItem::CheckerOrGenerateItem(x) + }), ))(s) }