diff --git a/Cargo.toml b/Cargo.toml index c9d84bd..0c50830 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,8 @@ [workspace] members = [ "sv-parser", + "sv-parser-syntaxtree", + "sv-parser-parser", "sv-parser-macros", ] diff --git a/sv-parser-parser/Cargo.toml b/sv-parser-parser/Cargo.toml new file mode 100644 index 0000000..2b0b1a2 --- /dev/null +++ b/sv-parser-parser/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "sv-parser-parser" +version = "0.1.0" +authors = ["dalance "] +edition = "2018" + +[features] +default = [] +trace = [] + +[dependencies] +nom = "5.0.0" +nom-packrat = "0.1.17" +str-concat = "*" +sv-parser-syntaxtree = { path = "../sv-parser-syntaxtree" } +sv-parser-macros = { path = "../sv-parser-macros" } diff --git a/sv-parser/src/parser/behavioral_statements/assertion_statements.rs b/sv-parser-parser/src/behavioral_statements/assertion_statements.rs similarity index 60% rename from sv-parser/src/parser/behavioral_statements/assertion_statements.rs rename to sv-parser-parser/src/behavioral_statements/assertion_statements.rs index e2f3925..7f4e6b2 100644 --- a/sv-parser/src/parser/behavioral_statements/assertion_statements.rs +++ b/sv-parser-parser/src/behavioral_statements/assertion_statements.rs @@ -1,88 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum AssertionItem { - Concurrent(Box), - Immediate(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct DeferredImmediateAssetionItem { - pub nodes: ( - Option<(BlockIdentifier, Symbol)>, - DeferredImmediateAssertionStatement, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ProceduralAssertionStatement { - Concurrent(Box), - Immediate(Box), - Checker(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum ImmediateAssetionStatement { - Simple(Box), - Deferred(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum SimpleImmediateAssertionStatement { - Assert(Box), - Assume(Box), - Cover(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct SimpleImmediateAssertStatement { - pub nodes: (Keyword, Paren, ActionBlock), -} - -#[derive(Clone, Debug, Node)] -pub struct SimpleImmediateAssumeStatement { - pub nodes: (Keyword, Paren, ActionBlock), -} - -#[derive(Clone, Debug, Node)] -pub struct SimpleImmediateCoverStatement { - pub nodes: (Keyword, Paren, StatementOrNull), -} - -#[derive(Clone, Debug, Node)] -pub enum DeferredImmediateAssertionStatement { - Assert(Box), - Assume(Box), - Cover(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct DeferredImmediateAssertStatement { - pub nodes: (Keyword, AssertTiming, Paren, ActionBlock), -} - -#[derive(Clone, Debug, Node)] -pub struct DeferredImmediateAssumeStatement { - pub nodes: (Keyword, AssertTiming, Paren, ActionBlock), -} - -#[derive(Clone, Debug, Node)] -pub struct DeferredImmediateCoverStatement { - pub nodes: (Keyword, AssertTiming, Paren, StatementOrNull), -} - -#[derive(Clone, Debug, Node)] -pub enum AssertTiming { - Zero(Box), - Final(Box), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -99,14 +15,18 @@ pub(crate) fn assertion_item(s: Span) -> IResult { } #[parser] -pub(crate) fn deferred_immediate_assertion_item(s: Span) -> IResult { +pub(crate) fn deferred_immediate_assertion_item( + s: Span, +) -> IResult { let (s, a) = opt(pair(block_identifier, symbol(":")))(s)?; let (s, b) = deferred_immediate_assertion_statement(s)?; Ok((s, DeferredImmediateAssetionItem { nodes: (a, b) })) } #[parser] -pub(crate) fn procedural_assertion_statement(s: Span) -> IResult { +pub(crate) fn procedural_assertion_statement( + s: Span, +) -> IResult { alt(( map(concurrent_assertion_statement, |x| { ProceduralAssertionStatement::Concurrent(Box::new(x)) @@ -150,7 +70,9 @@ pub(crate) fn simple_immediate_assertion_statement( } #[parser] -pub(crate) fn simple_immediate_assert_statement(s: Span) -> IResult { +pub(crate) fn simple_immediate_assert_statement( + s: Span, +) -> IResult { let (s, a) = keyword("assert")(s)?; let (s, b) = paren(expression)(s)?; let (s, c) = action_block(s)?; @@ -158,7 +80,9 @@ pub(crate) fn simple_immediate_assert_statement(s: Span) -> IResult IResult { +pub(crate) fn simple_immediate_assume_statement( + s: Span, +) -> IResult { let (s, a) = keyword("assume")(s)?; let (s, b) = paren(expression)(s)?; let (s, c) = action_block(s)?; @@ -166,7 +90,9 @@ pub(crate) fn simple_immediate_assume_statement(s: Span) -> IResult IResult { +pub(crate) fn simple_immediate_cover_statement( + s: Span, +) -> IResult { let (s, a) = keyword("cover")(s)?; let (s, b) = paren(expression)(s)?; let (s, c) = statement_or_null(s)?; @@ -245,5 +171,3 @@ pub(crate) fn assert_timing(s: Span) -> IResult { map(keyword("final"), |x| AssertTiming::Final(Box::new(x))), ))(s) } - -// ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/behavioral_statements/case_statements.rs b/sv-parser-parser/src/behavioral_statements/case_statements.rs similarity index 65% rename from sv-parser/src/parser/behavioral_statements/case_statements.rs rename to sv-parser-parser/src/behavioral_statements/case_statements.rs index 3844282..a44b94e 100644 --- a/sv-parser/src/parser/behavioral_statements/case_statements.rs +++ b/sv-parser-parser/src/behavioral_statements/case_statements.rs @@ -1,137 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum CaseStatement { - Normal(Box), - Matches(Box), - Inside(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CaseStatementNormal { - pub nodes: ( - Option, - CaseKeyword, - Paren, - CaseItem, - Vec, - Keyword, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct CaseStatementMatches { - pub nodes: ( - Option, - CaseKeyword, - Paren, - Keyword, - CasePatternItem, - Vec, - Keyword, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct CaseStatementInside { - pub nodes: ( - Option, - Keyword, - Paren, - Keyword, - CaseInsideItem, - Vec, - Keyword, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum CaseKeyword { - Case(Box), - Casez(Box), - Casex(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CaseExpression { - pub nodes: (Expression,), -} - -#[derive(Clone, Debug, Node)] -pub enum CaseItem { - NonDefault(Box), - Default(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CaseItemNondefault { - pub nodes: (List, Symbol, StatementOrNull), -} - -#[derive(Clone, Debug, Node)] -pub struct CaseItemDefault { - pub nodes: (Keyword, Option, StatementOrNull), -} - -#[derive(Clone, Debug, Node)] -pub enum CasePatternItem { - NonDefault(Box), - Default(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CasePatternItemNondefault { - pub nodes: ( - Pattern, - Option<(Symbol, Expression)>, - Symbol, - StatementOrNull, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum CaseInsideItem { - NonDefault(Box), - Default(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CaseInsideItemNondefault { - pub nodes: (OpenRangeList, Symbol, StatementOrNull), -} - -#[derive(Clone, Debug, Node)] -pub struct CaseItemExpression { - pub nodes: (Expression,), -} - -#[derive(Clone, Debug, Node)] -pub struct RandcaseStatement { - pub nodes: (Keyword, RandcaseItem, Vec, Keyword), -} - -#[derive(Clone, Debug, Node)] -pub struct RandcaseItem { - pub nodes: (Expression, Symbol, StatementOrNull), -} - -#[derive(Clone, Debug, Node)] -pub struct OpenRangeList { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct OpenValueRange { - pub nodes: (ValueRange,), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/behavioral_statements/clocking_block.rs b/sv-parser-parser/src/behavioral_statements/clocking_block.rs similarity index 65% rename from sv-parser/src/parser/behavioral_statements/clocking_block.rs rename to sv-parser-parser/src/behavioral_statements/clocking_block.rs index 60e211e..599671b 100644 --- a/sv-parser/src/parser/behavioral_statements/clocking_block.rs +++ b/sv-parser-parser/src/behavioral_statements/clocking_block.rs @@ -1,193 +1,7 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; +use crate::*; // ----------------------------------------------------------------------------- -#[derive(Clone, Debug, Node)] -pub enum ClockingDeclaration { - Local(Box), - Global(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ClockingDeclarationLocal { - pub nodes: ( - Option, - Keyword, - Option, - ClockingEvent, - Symbol, - Vec, - Keyword, - Option<(Symbol, ClockingIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct Default { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct ClockingDeclarationGlobal { - pub nodes: ( - Keyword, - Keyword, - Option, - ClockingEvent, - Symbol, - Keyword, - Option<(Symbol, ClockingIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ClockingEvent { - Identifier(Box), - Expression(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ClockingEventIdentifier { - pub nodes: (Symbol, Identifier), -} - -#[derive(Clone, Debug, Node)] -pub struct ClockingEventExpression { - pub nodes: (Symbol, Paren), -} - -#[derive(Clone, Debug, Node)] -pub enum ClockingItem { - Default(Box), - Direction(Box), - Assertion(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ClockingItemDefault { - pub nodes: (Keyword, DefaultSkew, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct ClockingItemDirection { - pub nodes: (ClockingDirection, ListOfClockingDeclAssign, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct ClockingItemAssertion { - pub nodes: (Vec, AssertionItemDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub enum DefaultSkew { - Input(Box), - Output(Box), - InputOutput(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct DefaultSkewInput { - pub nodes: (Keyword, ClockingSkew), -} - -#[derive(Clone, Debug, Node)] -pub struct DefaultSkewOutput { - pub nodes: (Keyword, ClockingSkew), -} - -#[derive(Clone, Debug, Node)] -pub struct DefaultSkewInputOutput { - pub nodes: (Keyword, ClockingSkew, Keyword, ClockingSkew), -} - -#[derive(Clone, Debug, Node)] -pub enum ClockingDirection { - Input(Box), - Output(Box), - InputOutput(Box), - Inout(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ClockingDirectionInput { - pub nodes: (Keyword, Option), -} - -#[derive(Clone, Debug, Node)] -pub struct ClockingDirectionOutput { - pub nodes: (Keyword, Option), -} - -#[derive(Clone, Debug, Node)] -pub struct ClockingDirectionInputOutput { - pub nodes: (Keyword, Option, Keyword, Option), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfClockingDeclAssign { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct ClockingDeclAssign { - pub nodes: (SignalIdentifier, Option<(Symbol, Expression)>), -} - -#[derive(Clone, Debug, Node)] -pub enum ClockingSkew { - Edge(Box), - DelayControl(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ClockingSkewEdge { - pub nodes: (EdgeIdentifier, Option), -} - -#[derive(Clone, Debug, Node)] -pub struct ClockingDrive { - pub nodes: (ClockvarExpression, Symbol, Option, Expression), -} - -#[derive(Clone, Debug, Node)] -pub enum CycleDelay { - Integral(Box), - Identifier(Box), - Expression(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CycleDelayIntegral { - pub nodes: (Symbol, IntegralNumber), -} - -#[derive(Clone, Debug, Node)] -pub struct CycleDelayIdentifier { - pub nodes: (Symbol, Identifier), -} - -#[derive(Clone, Debug, Node)] -pub struct CycleDelayExpression { - pub nodes: (Symbol, Paren), -} - -#[derive(Clone, Debug, Node)] -pub struct Clockvar { - pub nodes: (HierarchicalIdentifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct ClockvarExpression { - pub nodes: (Clockvar, Select), -} -// ----------------------------------------------------------------------------- - #[parser] pub(crate) fn clocking_declaration(s: Span) -> IResult { alt((clocking_declaration_local, clocking_declaration_global))(s) @@ -489,5 +303,3 @@ pub(crate) fn clockvar_expression(s: Span) -> IResult let (s, b) = select(s)?; Ok((s, ClockvarExpression { nodes: (a, b) })) } - -// ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/behavioral_statements/conditional_statements.rs b/sv-parser-parser/src/behavioral_statements/conditional_statements.rs similarity index 63% rename from sv-parser/src/parser/behavioral_statements/conditional_statements.rs rename to sv-parser-parser/src/behavioral_statements/conditional_statements.rs index 729f061..257e864 100644 --- a/sv-parser/src/parser/behavioral_statements/conditional_statements.rs +++ b/sv-parser-parser/src/behavioral_statements/conditional_statements.rs @@ -1,47 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct ConditionalStatement { - pub nodes: ( - Option, - Keyword, - Paren, - StatementOrNull, - Vec<(Keyword, Keyword, Paren, StatementOrNull)>, - Option<(Keyword, StatementOrNull)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum UniquePriority { - Unique(Box), - Unique0(Box), - Priority(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CondPredicate { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub enum ExpressionOrCondPattern { - Expression(Box), - CondPattern(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CondPattern { - pub nodes: (Expression, Keyword, Pattern), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/behavioral_statements/continuous_assignment_and_net_alias_statements.rs b/sv-parser-parser/src/behavioral_statements/continuous_assignment_and_net_alias_statements.rs similarity index 64% rename from sv-parser/src/parser/behavioral_statements/continuous_assignment_and_net_alias_statements.rs rename to sv-parser-parser/src/behavioral_statements/continuous_assignment_and_net_alias_statements.rs index 91e8be1..eb2b913 100644 --- a/sv-parser/src/parser/behavioral_statements/continuous_assignment_and_net_alias_statements.rs +++ b/sv-parser-parser/src/behavioral_statements/continuous_assignment_and_net_alias_statements.rs @@ -1,57 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum ContinuousAssign { - Net(Box), - Variable(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ContinuousAssignNet { - pub nodes: ( - Keyword, - Option, - Option, - ListOfNetAssignments, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ContinuousAssignVariable { - pub nodes: ( - Keyword, - Option, - ListOfVariableAssignments, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfNetAssignments { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfVariableAssignments { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct NetAlias { - pub nodes: (Keyword, NetLvalue, Symbol, List, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct NetAssignment { - pub nodes: (NetLvalue, Symbol, Expression), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/behavioral_statements/looping_statements.rs b/sv-parser-parser/src/behavioral_statements/looping_statements.rs similarity index 63% rename from sv-parser/src/parser/behavioral_statements/looping_statements.rs rename to sv-parser-parser/src/behavioral_statements/looping_statements.rs index b072d31..05b1cc1 100644 --- a/sv-parser/src/parser/behavioral_statements/looping_statements.rs +++ b/sv-parser-parser/src/behavioral_statements/looping_statements.rs @@ -1,107 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum LoopStatement { - Forever(Box), - Repeat(Box), - While(Box), - For(Box), - DoWhile(Box), - Foreach(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct LoopStatementForever { - pub nodes: (Keyword, StatementOrNull), -} - -#[derive(Clone, Debug, Node)] -pub struct LoopStatementRepeat { - pub nodes: (Keyword, Paren, StatementOrNull), -} - -#[derive(Clone, Debug, Node)] -pub struct LoopStatementWhile { - pub nodes: (Keyword, Paren, StatementOrNull), -} - -#[derive(Clone, Debug, Node)] -pub struct LoopStatementFor { - pub nodes: ( - Keyword, - Paren<( - Option, - Symbol, - Option, - Symbol, - Option, - )>, - StatementOrNull, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct LoopStatementDoWhile { - pub nodes: (Keyword, StatementOrNull, Keyword, Paren, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct LoopStatementForeach { - pub nodes: ( - Keyword, - Paren<(PsOrHierarchicalArrayIdentifier, Bracket)>, - Statement, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ForInitialization { - ListOfVariableAssignments(Box), - Declaration(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ForInitializationDeclaration { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct ForVariableDeclaration { - pub nodes: ( - Option, - DataType, - List, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct Var { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct ForStep { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub enum ForStepAssignment { - OperatorAssignment(Box), - IncOrDecExpression(Box), - FunctionSubroutineCall(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct LoopVariables { - pub nodes: (List>,), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -257,5 +154,3 @@ pub(crate) fn loop_variables(s: Span) -> IResult { let (s, a) = list(symbol(","), opt(index_variable_identifier))(s)?; Ok((s, LoopVariables { nodes: (a,) })) } - -// ----------------------------------------------------------------------------- diff --git a/sv-parser-parser/src/behavioral_statements/mod.rs b/sv-parser-parser/src/behavioral_statements/mod.rs new file mode 100644 index 0000000..c637a7e --- /dev/null +++ b/sv-parser-parser/src/behavioral_statements/mod.rs @@ -0,0 +1,26 @@ +pub mod assertion_statements; +pub mod case_statements; +pub mod clocking_block; +pub mod conditional_statements; +pub mod continuous_assignment_and_net_alias_statements; +pub mod looping_statements; +pub mod parallel_and_sequential_blocks; +pub mod patterns; +pub mod procedural_blocks_and_assignments; +pub mod randsequence; +pub mod statements; +pub mod subroutine_call_statements; +pub mod timing_control_statements; +pub(crate) use assertion_statements::*; +pub(crate) use case_statements::*; +pub(crate) use clocking_block::*; +pub(crate) use conditional_statements::*; +pub(crate) use continuous_assignment_and_net_alias_statements::*; +pub(crate) use looping_statements::*; +pub(crate) use parallel_and_sequential_blocks::*; +pub(crate) use patterns::*; +pub(crate) use procedural_blocks_and_assignments::*; +pub(crate) use randsequence::*; +pub(crate) use statements::*; +pub(crate) use subroutine_call_statements::*; +pub(crate) use timing_control_statements::*; diff --git a/sv-parser/src/parser/behavioral_statements/parallel_and_sequential_blocks.rs b/sv-parser-parser/src/behavioral_statements/parallel_and_sequential_blocks.rs similarity index 61% rename from sv-parser/src/parser/behavioral_statements/parallel_and_sequential_blocks.rs rename to sv-parser-parser/src/behavioral_statements/parallel_and_sequential_blocks.rs index a98e2a4..13d8ce9 100644 --- a/sv-parser/src/parser/behavioral_statements/parallel_and_sequential_blocks.rs +++ b/sv-parser-parser/src/behavioral_statements/parallel_and_sequential_blocks.rs @@ -1,54 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum ActionBlock { - StatementOrNull(Box), - Else(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ActionBlockElse { - pub nodes: (Option, Keyword, StatementOrNull), -} - -#[derive(Clone, Debug, Node)] -pub struct SeqBlock { - pub nodes: ( - Keyword, - Option<(Symbol, BlockIdentifier)>, - Vec, - Vec, - Keyword, - Option<(Symbol, BlockIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ParBlock { - pub nodes: ( - Keyword, - Option<(Symbol, BlockIdentifier)>, - Vec, - Vec, - JoinKeyword, - Option<(Symbol, BlockIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum JoinKeyword { - Join(Box), - JoinAny(Box), - JoinNone(Box), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/behavioral_statements/patterns.rs b/sv-parser-parser/src/behavioral_statements/patterns.rs similarity index 64% rename from sv-parser/src/parser/behavioral_statements/patterns.rs rename to sv-parser-parser/src/behavioral_statements/patterns.rs index 34f3323..6924ea7 100644 --- a/sv-parser/src/parser/behavioral_statements/patterns.rs +++ b/sv-parser-parser/src/behavioral_statements/patterns.rs @@ -1,116 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::sequence::*; -use nom::IResult; -use nom_packrat::packrat_parser; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum Pattern { - Variable(Box), - Asterisk(Box), - ConstantExpression(Box), - Tagged(Box), - List(Box), - IdentifierList(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PatternVariable { - pub nodes: (Symbol, VariableIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub struct PatternTagged { - pub nodes: (Keyword, MemberIdentifier, Option), -} - -#[derive(Clone, Debug, Node)] -pub struct PatternList { - pub nodes: (ApostropheBrace>,), -} - -#[derive(Clone, Debug, Node)] -pub struct PatternIdentifierList { - pub nodes: (ApostropheBrace>,), -} - -#[derive(Clone, Debug, Node)] -pub enum AssignmentPattern { - List(Box), - Structure(Box), - Array(Box), - Repeat(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct AssignmentPatternList { - pub nodes: (ApostropheBrace>,), -} - -#[derive(Clone, Debug, Node)] -pub struct AssignmentPatternStructure { - pub nodes: (ApostropheBrace>,), -} - -#[derive(Clone, Debug, Node)] -pub struct AssignmentPatternArray { - pub nodes: (ApostropheBrace>,), -} - -#[derive(Clone, Debug, Node)] -pub struct AssignmentPatternRepeat { - pub nodes: (ApostropheBrace<(ConstantExpression, Brace>)>,), -} - -#[derive(Clone, Debug, Node)] -pub enum StructurePatternKey { - MemberIdentifier(Box), - AssignmentPatternKey(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum ArrayPatternKey { - ConstantExpression(Box), - AssignmentPatternKey(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum AssignmentPatternKey { - SimpleType(Box), - Default(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct AssignmentPatternExpression { - pub nodes: (Option, AssignmentPattern), -} - -#[derive(Clone, Debug, Node)] -pub enum AssignmentPatternExpressionType { - PsTypeIdentifier(Box), - PsParameterIdentifier(Box), - IntegerAtomType(Box), - TypeReference(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantAssignmentPatternExpression { - pub nodes: (AssignmentPatternExpression,), -} - -#[derive(Clone, Debug, Node)] -pub struct AssignmentPatternNetLvalue { - pub nodes: (ApostropheBrace>,), -} - -#[derive(Clone, Debug, Node)] -pub struct AssignmentPatternVariableLvalue { - pub nodes: (ApostropheBrace>,), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -307,5 +195,3 @@ pub(crate) fn assignment_pattern_variable_lvalue( let (s, a) = apostrophe_brace(list(symbol(","), variable_lvalue))(s)?; Ok((s, AssignmentPatternVariableLvalue { nodes: (a,) })) } - -// ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/behavioral_statements/procedural_blocks_and_assignments.rs b/sv-parser-parser/src/behavioral_statements/procedural_blocks_and_assignments.rs similarity index 66% rename from sv-parser/src/parser/behavioral_statements/procedural_blocks_and_assignments.rs rename to sv-parser-parser/src/behavioral_statements/procedural_blocks_and_assignments.rs index f960a79..57e4a45 100644 --- a/sv-parser/src/parser/behavioral_statements/procedural_blocks_and_assignments.rs +++ b/sv-parser-parser/src/behavioral_statements/procedural_blocks_and_assignments.rs @@ -1,127 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct InitialConstruct { - pub nodes: (Keyword, StatementOrNull), -} - -#[derive(Clone, Debug, Node)] -pub struct AlwaysConstruct { - pub nodes: (AlwaysKeyword, Statement), -} - -#[derive(Clone, Debug, Node)] -pub enum AlwaysKeyword { - Always(Box), - AlwaysComb(Box), - AlwaysLatch(Box), - AlwaysFf(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct FinalConstruct { - pub nodes: (Keyword, FunctionStatement), -} - -#[derive(Clone, Debug, Node)] -pub enum BlockingAssignment { - Variable(Box), - NonrangeVariable(Box), - HierarchicalVariable(Box), - OperatorAssignment(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct BlockingAssignmentVariable { - pub nodes: (VariableLvalue, Symbol, DelayOrEventControl, Expression), -} - -#[derive(Clone, Debug, Node)] -pub struct BlockingAssignmentNonrangeVariable { - pub nodes: (NonrangeVariableLvalue, Symbol, DynamicArrayNew), -} - -#[derive(Clone, Debug, Node)] -pub struct BlockingAssignmentHierarchicalVariable { - pub nodes: ( - Option, - HierarchicalVariableIdentifier, - Select, - Symbol, - ClassNew, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct OperatorAssignment { - pub nodes: (VariableLvalue, AssignmentOperator, Expression), -} - -#[derive(Clone, Debug, Node)] -pub struct AssignmentOperator { - pub nodes: (Symbol,), -} - -#[derive(Clone, Debug, Node)] -pub struct NonblockingAssignment { - pub nodes: ( - VariableLvalue, - Symbol, - Option, - Expression, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ProceduralContinuousAssignment { - Assign(Box), - Deassign(Box), - ForceVariable(Box), - ForceNet(Box), - ReleaseVariable(Box), - ReleaseNet(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ProceduralContinuousAssignmentAssign { - pub nodes: (Keyword, VariableAssignment), -} - -#[derive(Clone, Debug, Node)] -pub struct ProceduralContinuousAssignmentDeassign { - pub nodes: (Keyword, VariableLvalue), -} - -#[derive(Clone, Debug, Node)] -pub struct ProceduralContinuousAssignmentForceVariable { - pub nodes: (Keyword, VariableAssignment), -} - -#[derive(Clone, Debug, Node)] -pub struct ProceduralContinuousAssignmentForceNet { - pub nodes: (Keyword, NetAssignment), -} - -#[derive(Clone, Debug, Node)] -pub struct ProceduralContinuousAssignmentReleaseVariable { - pub nodes: (Keyword, VariableLvalue), -} - -#[derive(Clone, Debug, Node)] -pub struct ProceduralContinuousAssignmentReleaseNet { - pub nodes: (Keyword, NetLvalue), -} - -#[derive(Clone, Debug, Node)] -pub struct VariableAssignment { - pub nodes: (VariableLvalue, Symbol, Expression), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -202,7 +79,9 @@ pub(crate) fn blocking_assignment_nonrange_variable(s: Span) -> IResult IResult { +pub(crate) fn blocking_assignment_hierarchical_variable( + s: Span, +) -> IResult { let (s, a) = opt(implicit_class_handle_or_class_scope_or_package_scope)(s)?; let (s, b) = hierarchical_variable_identifier(s)?; let (s, c) = select(s)?; @@ -260,7 +139,9 @@ pub(crate) fn nonblocking_assignment(s: Span) -> IResult IResult { +pub(crate) fn procedural_continuous_assignment( + s: Span, +) -> IResult { alt(( procedural_continuous_assignment_assign, procedural_continuous_assignment_deassign, @@ -362,19 +243,3 @@ pub(crate) fn variable_assignment(s: Span) -> IResult let (s, c) = expression(s)?; Ok((s, VariableAssignment { nodes: (a, b, c) })) } - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_blocking_assignment() { - parser_test!( - blocking_assignment, - "idest = new [3] (isrc)", - Ok((_, BlockingAssignment::NonrangeVariable(_))) - ); - } -} diff --git a/sv-parser/src/parser/behavioral_statements/randsequence.rs b/sv-parser-parser/src/behavioral_statements/randsequence.rs similarity index 64% rename from sv-parser/src/parser/behavioral_statements/randsequence.rs rename to sv-parser-parser/src/behavioral_statements/randsequence.rs index b548b70..b676e02 100644 --- a/sv-parser/src/parser/behavioral_statements/randsequence.rs +++ b/sv-parser-parser/src/behavioral_statements/randsequence.rs @@ -1,144 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct RandsequenceStatement { - pub nodes: ( - Keyword, - Paren>, - Production, - Vec, - Keyword, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct Production { - pub nodes: ( - Option, - ProductionIdentifier, - Option>, - Symbol, - List, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct RsRule { - pub nodes: ( - RsProductionList, - Option<(Symbol, WeightSpecification, Option)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum RsProductionList { - Prod(Box), - Join(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct RsProductionListProd { - pub nodes: (RsProd, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct RsProductionListJoin { - pub nodes: ( - Keyword, - Keyword, - Option>, - ProductionItem, - ProductionItem, - Vec, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum WeightSpecification { - IntegralNumber(Box), - PsIdentifier(Box), - Expression(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct WeightSpecificationExpression { - pub nodes: (Paren,), -} - -#[derive(Clone, Debug, Node)] -pub struct RsCodeBlock { - pub nodes: (Brace<(Vec, Vec)>,), -} - -#[derive(Clone, Debug, Node)] -pub enum RsProd { - ProductionItem(Box), - RsCodeBlock(Box), - RsIfElse(Box), - RsRepeat(Box), - RsCase(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ProductionItem { - pub nodes: (ProductionIdentifier, Option>), -} - -#[derive(Clone, Debug, Node)] -pub struct RsIfElse { - pub nodes: ( - Keyword, - Paren, - ProductionItem, - Option<(Keyword, ProductionItem)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct RsRepeat { - pub nodes: (Keyword, Paren, ProductionItem), -} - -#[derive(Clone, Debug, Node)] -pub struct RsCase { - pub nodes: ( - Keyword, - Paren, - RsCaseItem, - Vec, - Keyword, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum RsCaseItem { - NonDefault(Box), - Default(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct RsCaseItemNondefault { - pub nodes: ( - List, - Symbol, - ProductionItem, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct RsCaseItemDefault { - pub nodes: (Keyword, Option, ProductionItem, Symbol), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/behavioral_statements/statements.rs b/sv-parser-parser/src/behavioral_statements/statements.rs similarity index 63% rename from sv-parser/src/parser/behavioral_statements/statements.rs rename to sv-parser-parser/src/behavioral_statements/statements.rs index 5b48161..0e1418e 100644 --- a/sv-parser/src/parser/behavioral_statements/statements.rs +++ b/sv-parser-parser/src/behavioral_statements/statements.rs @@ -1,77 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum StatementOrNull { - Statement(Box), - Attribute(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct StatementOrNullAttribute { - pub nodes: (Vec, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct Statement { - pub nodes: ( - Option<(BlockIdentifier, Symbol)>, - Vec, - StatementItem, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum StatementItem { - BlockingAssignment(Box<(BlockingAssignment, Symbol)>), - NonblockingAssignment(Box<(NonblockingAssignment, Symbol)>), - ProceduralContinuousAssignment(Box<(ProceduralContinuousAssignment, Symbol)>), - CaseStatement(Box), - ConditionalStatement(Box), - IncOrDecExpression(Box<(IncOrDecExpression, Symbol)>), - SubroutineCallStatement(Box), - DisableStatement(Box), - EventTrigger(Box), - LoopStatement(Box), - JumpStatement(Box), - ParBlock(Box), - ProceduralTimingControlStatement(Box), - SeqBlock(Box), - WaitStatement(Box), - ProceduralAssertionStatement(Box), - ClockingDrive(Box<(ClockingDrive, Symbol)>), - RandsequenceStatement(Box), - RandcaseStatement(Box), - ExpectPropertyStatement(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct FunctionStatement { - pub nodes: (Statement,), -} - -#[derive(Clone, Debug, Node)] -pub enum FunctionStatementOrNull { - Statement(Box), - Attribute(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct FunctionStatementOrNullAttribute { - pub nodes: (Vec, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct VariableIdentifierList { - pub nodes: (List,), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -178,7 +105,9 @@ pub(crate) fn function_statement_or_null(s: Span) -> IResult IResult { +pub(crate) fn function_statement_or_null_attribute( + s: Span, +) -> IResult { let (s, a) = many0(attribute_instance)(s)?; let (s, b) = symbol(";")(s)?; Ok(( diff --git a/sv-parser/src/parser/behavioral_statements/subroutine_call_statements.rs b/sv-parser-parser/src/behavioral_statements/subroutine_call_statements.rs similarity index 50% rename from sv-parser/src/parser/behavioral_statements/subroutine_call_statements.rs rename to sv-parser-parser/src/behavioral_statements/subroutine_call_statements.rs index 553021a..003618b 100644 --- a/sv-parser/src/parser/behavioral_statements/subroutine_call_statements.rs +++ b/sv-parser-parser/src/behavioral_statements/subroutine_call_statements.rs @@ -1,22 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum SubroutineCallStatement { - SubroutineCall(Box<(SubroutineCall, Symbol)>), - Function(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct SubroutineCallStatementFunction { - pub nodes: (Keyword, Symbol, Paren, Symbol), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -31,7 +13,9 @@ pub(crate) fn subroutine_call_statement(s: Span) -> IResult IResult { +pub(crate) fn subroutine_call_statement_function( + s: Span, +) -> IResult { let (s, a) = keyword("void")(s)?; let (s, b) = symbol("'")(s)?; let (s, c) = paren(function_subroutine_call)(s)?; @@ -43,5 +27,3 @@ pub(crate) fn subroutine_call_statement_function(s: Span) -> IResult), - Event(Box), - Repeat(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct DelayOrEventControlRepeat { - pub nodes: (Keyword, Paren, EventControl), -} - -#[derive(Clone, Debug, Node)] -pub enum DelayControl { - Delay(Box), - Mintypmax(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct DelayControlDelay { - pub nodes: (Symbol, DelayValue), -} - -#[derive(Clone, Debug, Node)] -pub struct DelayControlMintypmax { - pub nodes: (Symbol, Paren), -} - -#[derive(Clone, Debug, Node)] -pub enum EventControl { - EventIdentifier(Box), - EventExpression(Box), - Asterisk(Box), - ParenAsterisk(Box), - SequenceIdentifier(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct EventControlEventIdentifier { - pub nodes: (Symbol, HierarchicalEventIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub struct EventControlEventExpression { - pub nodes: (Symbol, Paren), -} - -#[derive(Clone, Debug, Node)] -pub struct EventControlAsterisk { - pub nodes: (Symbol,), -} - -#[derive(Clone, Debug, Node)] -pub struct EventControlParenAsterisk { - pub nodes: (Symbol, Paren), -} - -#[derive(Clone, Debug, Node)] -pub struct EventControlSequenceIdentifier { - pub nodes: (Symbol, PsOrHierarchicalSequenceIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub enum EventExpression { - Expression(Box), - Sequence(Box), - Or(Box), - Comma(Box), - Paren(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct EventExpressionExpression { - pub nodes: ( - Option, - Expression, - Option<(Keyword, Expression)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct EventExpressionSequence { - pub nodes: (SequenceInstance, Option<(Keyword, Expression)>), -} - -#[derive(Clone, Debug, Node)] -pub struct EventExpressionOr { - pub nodes: (EventExpression, Keyword, EventExpression), -} - -#[derive(Clone, Debug, Node)] -pub struct EventExpressionComma { - pub nodes: (EventExpression, Symbol, EventExpression), -} - -#[derive(Clone, Debug, Node)] -pub struct EventExpressionParen { - pub nodes: (Paren,), -} - -#[derive(Clone, Debug, Node)] -pub enum ProceduralTimingControl { - DelayControl(Box), - EventControl(Box), - CycleDelay(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum JumpStatement { - Return(Box), - Break(Box), - Continue(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct JumpStatementReturn { - pub nodes: (Keyword, Option, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct JumpStatementBreak { - pub nodes: (Keyword, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct JumpStatementContinue { - pub nodes: (Keyword, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub enum WaitStatement { - Wait(Box), - Fork(Box), - Order(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct WaitStatementWait { - pub nodes: (Keyword, Paren, StatementOrNull), -} - -#[derive(Clone, Debug, Node)] -pub struct WaitStatementFork { - pub nodes: (Keyword, Keyword, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct WaitStatementOrder { - pub nodes: ( - Keyword, - Paren>, - ActionBlock, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum EventTrigger { - Named(Box), - Nonblocking(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct EventTriggerNamed { - pub nodes: (Symbol, HierarchicalEventIdentifier, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct EventTriggerNonblocking { - pub nodes: ( - Symbol, - Option, - HierarchicalEventIdentifier, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum DisableStatement { - Task(Box), - Block(Box), - Fork(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct DisableStatementTask { - pub nodes: (Keyword, HierarchicalTaskIdentifier, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct DisableStatementBlock { - pub nodes: (Keyword, HierarchicalBlockIdentifier, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct DisableStatementFork { - pub nodes: (Keyword, Keyword, Symbol), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/declarations/assertion_declarations.rs b/sv-parser-parser/src/declarations/assertion_declarations.rs similarity index 66% rename from sv-parser/src/parser/declarations/assertion_declarations.rs rename to sv-parser-parser/src/declarations/assertion_declarations.rs index 756b3ec..e3bcb59 100644 --- a/sv-parser/src/parser/declarations/assertion_declarations.rs +++ b/sv-parser-parser/src/declarations/assertion_declarations.rs @@ -1,671 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum ConcurrentAssertionItem { - Statement(Box), - CheckerInstantiation(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ConcurrentAssertionItemStatement { - pub nodes: ( - Option<(BlockIdentifier, Symbol)>, - ConcurrentAssertionStatement, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ConcurrentAssertionStatement { - AssertPropertyStatement(Box), - AssumePropertyStatement(Box), - CoverPropertyStatement(Box), - CoverSequenceStatement(Box), - RestrictPropertyStatement(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct AssertPropertyStatement { - pub nodes: (Keyword, Keyword, Paren, ActionBlock), -} - -#[derive(Clone, Debug, Node)] -pub struct AssumePropertyStatement { - pub nodes: (Keyword, Keyword, Paren, ActionBlock), -} - -#[derive(Clone, Debug, Node)] -pub struct CoverPropertyStatement { - pub nodes: (Keyword, Keyword, Paren, StatementOrNull), -} - -#[derive(Clone, Debug, Node)] -pub struct ExpectPropertyStatement { - pub nodes: (Keyword, Paren, ActionBlock), -} - -#[derive(Clone, Debug, Node)] -pub struct CoverSequenceStatement { - pub nodes: ( - Keyword, - Keyword, - Paren<( - Option, - Option<(Keyword, Keyword, Paren)>, - SequenceExpr, - )>, - StatementOrNull, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct RestrictPropertyStatement { - pub nodes: (Keyword, Keyword, Paren, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyInstance { - pub nodes: ( - PsOrHierarchicalPropertyIdentifier, - Option>>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum PropertyListOfArguments { - Ordered(Box), - Named(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyListOfArgumentsOrdered { - pub nodes: ( - List>, - Vec<(Symbol, Symbol, Identifier, Paren>)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyListOfArgumentsNamed { - pub nodes: (List>)>,), -} - -#[derive(Clone, Debug, Node)] -pub enum PropertyActualArg { - PropertyExpr(Box), - SequenceActualArg(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum AssertionItemDeclaration { - PropertyDeclaration(Box), - SequenceDeclaration(Box), - LetDeclaration(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyDeclaration { - pub nodes: ( - Keyword, - PropertyIdentifier, - Option>>, - Symbol, - Vec, - PropertySpec, - Option, - Keyword, - Option<(Symbol, PropertyIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyPortList { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyPortItem { - pub nodes: ( - Vec, - Option<(Local, Option)>, - Option, - FormalPortIdentifier, - Vec, - Option<(Symbol, PropertyActualArg)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum PropertyLvarPortDirection { - Input(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum PropertyFormalType { - SequenceFormalType(Box), - Property(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertySpec { - pub nodes: ( - Option, - Option<(Keyword, Keyword, Paren)>, - PropertyExpr, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum PropertyExpr { - SequenceExpr(Box), - Strong(Box), - Weak(Box), - Paren(Box), - Not(Box), - Or(Box), - And(Box), - ImplicationOverlapped(Box), - ImplicationNonoverlapped(Box), - If(Box), - Case(Box), - FollowedByOverlapped(Box), - FollowedByNonoverlapped(Box), - Nexttime(Box), - SNexttime(Box), - Always(Box), - SAlways(Box), - Eventually(Box), - SEventually(Box), - Until(Box), - SUntil(Box), - UntilWith(Box), - SUntilWith(Box), - Implies(Box), - Iff(Box), - AcceptOn(Box), - RejectOn(Box), - SyncAcceptOn(Box), - SyncRejectOn(Box), - PropertyInstance(Box), - ClockingEvent(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprStrong { - pub nodes: (Keyword, Paren), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprWeak { - pub nodes: (Keyword, Paren), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprParen { - pub nodes: (Paren,), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprNot { - pub nodes: (Keyword, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprOr { - pub nodes: (PropertyExpr, Keyword, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprAnd { - pub nodes: (PropertyExpr, Keyword, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprImplicationOverlapped { - pub nodes: (SequenceExpr, Symbol, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprImplicationNonoverlapped { - pub nodes: (SequenceExpr, Symbol, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprIf { - pub nodes: ( - Keyword, - Paren, - PropertyExpr, - Option<(Keyword, PropertyExpr)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprCase { - pub nodes: ( - Keyword, - Paren, - PropertyCaseItem, - Vec, - Keyword, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprFollowedByOverlapped { - pub nodes: (SequenceExpr, Symbol, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprFollowedByNonoverlapped { - pub nodes: (SequenceExpr, Symbol, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprNexttime { - pub nodes: (Keyword, Option>, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprSNexttime { - pub nodes: (Keyword, Option>, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprAlways { - pub nodes: ( - Keyword, - Option>, - PropertyExpr, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprSAlways { - pub nodes: ( - Keyword, - Bracket, - PropertyExpr, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprEventually { - pub nodes: (Keyword, Bracket, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprSEventually { - pub nodes: ( - Keyword, - Option>, - PropertyExpr, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprUntil { - pub nodes: (PropertyExpr, Keyword, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprSUntil { - pub nodes: (PropertyExpr, Keyword, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprUntilWith { - pub nodes: (PropertyExpr, Keyword, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprSUntilWith { - pub nodes: (PropertyExpr, Keyword, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprImplies { - pub nodes: (PropertyExpr, Keyword, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprIff { - pub nodes: (PropertyExpr, Keyword, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprAcceptOn { - pub nodes: (Keyword, Paren, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprRejectOn { - pub nodes: (Keyword, Paren, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprSyncAcceptOn { - pub nodes: (Keyword, Paren, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprSyncRejectOn { - pub nodes: (Keyword, Paren, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyExprClockingEvent { - pub nodes: (ClockingEvent, PropertyExpr), -} - -#[derive(Clone, Debug, Node)] -pub enum PropertyCaseItem { - Nondefault(Box), - Default(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyCaseItemNondefault { - pub nodes: (List, Symbol, PropertyExpr, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyCaseItemDefault { - pub nodes: (Keyword, Option, PropertyExpr, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceDeclaration { - pub nodes: ( - Keyword, - SequenceIdentifier, - Option>>, - Symbol, - Vec, - SequenceExpr, - Option, - Keyword, - Option<(Symbol, SequenceIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct SequencePortList { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct SequencePortItem { - pub nodes: ( - Vec, - Option<(Local, Option)>, - Option, - FormalPortIdentifier, - Vec, - Option<(Symbol, SequenceActualArg)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum SequenceLvarPortDirection { - Input(Box), - Inout(Box), - Output(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum SequenceFormalType { - DataTypeOrImplicit(Box), - Sequence(Box), - Untyped(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum SequenceExpr { - CycleDelayExpr(Box), - ExprCycleDelayExpr(Box), - Expression(Box), - Instance(Box), - Paren(Box), - And(Box), - Intersect(Box), - Or(Box), - FirstMatch(Box), - Throughout(Box), - Within(Box), - ClockingEvent(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceExprCycleDelayExpr { - pub nodes: ( - CycleDelayRange, - SequenceExpr, - Vec<(CycleDelayRange, SequenceExpr)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceExprExprCycleDelayExpr { - pub nodes: ( - SequenceExpr, - CycleDelayRange, - SequenceExpr, - Vec<(CycleDelayRange, SequenceExpr)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceExprExpression { - pub nodes: (ExpressionOrDist, Option), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceExprInstance { - pub nodes: (SequenceInstance, Option), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceExprParen { - pub nodes: ( - Paren<(SequenceExpr, Vec<(Symbol, SequenceMatchItem)>)>, - Option, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceExprAnd { - pub nodes: (SequenceExpr, Keyword, SequenceExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceExprIntersect { - pub nodes: (SequenceExpr, Keyword, SequenceExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceExprOr { - pub nodes: (SequenceExpr, Keyword, SequenceExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceExprFirstMatch { - pub nodes: ( - Keyword, - Paren<(SequenceExpr, Vec<(Symbol, SequenceMatchItem)>)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceExprThroughout { - pub nodes: (ExpressionOrDist, Keyword, SequenceExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceExprWithin { - pub nodes: (SequenceExpr, Keyword, SequenceExpr), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceExprClockingEvent { - pub nodes: (ClockingEvent, SequenceExpr), -} - -#[derive(Clone, Debug, Node)] -pub enum CycleDelayRange { - Primary(Box), - Expression(Box), - Asterisk(Box), - Plus(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CycleDelayRangePrimary { - pub nodes: (Symbol, ConstantPrimary), -} - -#[derive(Clone, Debug, Node)] -pub struct CycleDelayRangeExpression { - pub nodes: (Symbol, Bracket), -} - -#[derive(Clone, Debug, Node)] -pub struct CycleDelayRangeAsterisk { - pub nodes: (Symbol, Bracket), -} - -#[derive(Clone, Debug, Node)] -pub struct CycleDelayRangePlus { - pub nodes: (Symbol, Bracket), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceMethodCall { - pub nodes: (SequenceInstance, Symbol, MethodIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub enum SequenceMatchItem { - OperatorAssignment(Box), - IncOrDecExpression(Box), - SubroutineCall(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceInstance { - pub nodes: ( - PsOrHierarchicalSequenceIdentifier, - Option>>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum SequenceListOfArguments { - Ordered(Box), - Named(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceListOfArgumentsOrdered { - pub nodes: ( - List>, - Vec<(Symbol, Symbol, Identifier, Paren>)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceListOfArgumentsNamed { - pub nodes: (List>)>,), -} - -#[derive(Clone, Debug, Node)] -pub enum SequenceActualArg { - EventExpression(Box), - SequenceExpr(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum BooleanAbbrev { - ConsecutiveRepetition(Box), - NonConsecutiveRepetition(Box), - GotoRepetition(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceAbbrev { - pub nodes: (ConsecutiveRepetition,), -} - -#[derive(Clone, Debug, Node)] -pub enum ConsecutiveRepetition { - Expression(Box), - Asterisk(Box), - Plus(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ConsecutiveRepetitionExpression { - pub nodes: (Bracket<(Symbol, ConstOrRangeExpression)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct ConsecutiveRepetitionAsterisk { - pub nodes: (Bracket,), -} - -#[derive(Clone, Debug, Node)] -pub struct ConsecutiveRepetitionPlus { - pub nodes: (Bracket,), -} - -#[derive(Clone, Debug, Node)] -pub struct NonConsecutiveRepetition { - pub nodes: (Bracket<(Symbol, ConstOrRangeExpression)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct GotoRepetition { - pub nodes: (Bracket<(Symbol, ConstOrRangeExpression)>,), -} - -#[derive(Clone, Debug, Node)] -pub enum ConstOrRangeExpression { - ConstantExpression(Box), - CycleDelayConstRangeExpression(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum CycleDelayConstRangeExpression { - Binary(Box), - Dollar(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CycleDelayConstRangeExpressionBinary { - pub nodes: (ConstantExpression, Symbol, ConstantExpression), -} - -#[derive(Clone, Debug, Node)] -pub struct CycleDelayConstRangeExpressionDollar { - pub nodes: (ConstantExpression, Symbol, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct ExpressionOrDist { - pub nodes: (Expression, Option<(Keyword, Brace)>), -} - -#[derive(Clone, Debug, Node)] -pub struct AssertionVariableDeclaration { - pub nodes: (VarDataType, ListOfVariableDeclAssignments, Symbol), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -680,7 +13,9 @@ pub(crate) fn concurrent_assertion_item(s: Span) -> IResult IResult { +pub(crate) fn concurrent_assertion_item_statement( + s: Span, +) -> IResult { let (s, a) = opt(pair(block_identifier, symbol(":")))(s)?; let (s, b) = concurrent_assertion_statement(s)?; Ok(( @@ -692,7 +27,9 @@ pub(crate) fn concurrent_assertion_item_statement(s: Span) -> IResult IResult { +pub(crate) fn concurrent_assertion_statement( + s: Span, +) -> IResult { alt(( map(assert_property_statement, |x| { ConcurrentAssertionStatement::AssertPropertyStatement(Box::new(x)) @@ -814,7 +151,9 @@ pub(crate) fn property_list_of_arguments(s: Span) -> IResult IResult { +pub(crate) fn property_list_of_arguments_ordered( + s: Span, +) -> IResult { let (s, a) = list(symbol(","), opt(property_actual_arg))(s)?; let (s, b) = many0(tuple(( symbol(","), @@ -1658,7 +997,9 @@ pub(crate) fn sequence_list_of_arguments(s: Span) -> IResult IResult { +pub(crate) fn sequence_list_of_arguments_ordered( + s: Span, +) -> IResult { let (s, a) = list(symbol(","), opt(sequence_actual_arg))(s)?; let (s, b) = many0(tuple(( symbol(","), @@ -1829,7 +1170,9 @@ pub(crate) fn expression_or_dist(s: Span) -> IResult { } #[parser] -pub(crate) fn assertion_variable_declaration(s: Span) -> IResult { +pub(crate) fn assertion_variable_declaration( + s: Span, +) -> IResult { let (s, a) = var_data_type(s)?; let (s, b) = list_of_variable_decl_assignments(s)?; let (s, c) = symbol(";")(s)?; diff --git a/sv-parser/src/parser/declarations/block_item_declarations.rs b/sv-parser-parser/src/declarations/block_item_declarations.rs similarity index 60% rename from sv-parser/src/parser/declarations/block_item_declarations.rs rename to sv-parser-parser/src/declarations/block_item_declarations.rs index 066b826..c9c35b0 100644 --- a/sv-parser/src/parser/declarations/block_item_declarations.rs +++ b/sv-parser-parser/src/declarations/block_item_declarations.rs @@ -1,38 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::multi::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum BlockItemDeclaration { - Data(Box), - LocalParameter(Box), - Parameter(Box), - Let(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct BlockItemDeclarationData { - pub nodes: (Vec, DataDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct BlockItemDeclarationLocalParameter { - pub nodes: (Vec, LocalParameterDeclaration, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct BlockItemDeclarationParameter { - pub nodes: (Vec, ParameterDeclaration, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct BlockItemDeclarationLet { - pub nodes: (Vec, LetDeclaration), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -57,7 +23,9 @@ pub(crate) fn block_item_declaration_data(s: Span) -> IResult IResult { +pub(crate) 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)?; diff --git a/sv-parser/src/parser/declarations/covergroup_declarations.rs b/sv-parser-parser/src/declarations/covergroup_declarations.rs similarity index 65% rename from sv-parser/src/parser/declarations/covergroup_declarations.rs rename to sv-parser-parser/src/declarations/covergroup_declarations.rs index 64ebb9c..596285c 100644 --- a/sv-parser/src/parser/declarations/covergroup_declarations.rs +++ b/sv-parser-parser/src/declarations/covergroup_declarations.rs @@ -1,477 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct CovergroupDeclaration { - pub nodes: ( - Keyword, - CovergroupIdentifier, - Option>>, - Option, - Symbol, - Vec, - Keyword, - Option<(Symbol, CovergroupIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum CoverageSpecOrOption { - Spec(Box), - Option(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CoverageSpecOrOptionSpec { - pub nodes: (Vec, CoverageSpec), -} - -#[derive(Clone, Debug, Node)] -pub struct CoverageSpecOrOptionOption { - pub nodes: (Vec, CoverageOption, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub enum CoverageOption { - Option(Box), - TypeOption(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CoverageOptionOption { - pub nodes: (Keyword, Symbol, MemberIdentifier, Symbol, Expression), -} - -#[derive(Clone, Debug, Node)] -pub struct CoverageOptionTypeOption { - pub nodes: ( - Keyword, - Symbol, - MemberIdentifier, - Symbol, - ConstantExpression, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum CoverageSpec { - CoverPoint(Box), - CoverCross(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum CoverageEvent { - ClockingEvent(Box), - Sample(Box), - At(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CoverageEventSample { - pub nodes: (Keyword, Keyword, Keyword, Paren>), -} - -#[derive(Clone, Debug, Node)] -pub struct CoverageEventAt { - pub nodes: (Symbol, Paren), -} - -#[derive(Clone, Debug, Node)] -pub enum BlockEventExpression { - Or(Box), - Begin(Box), - End(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct BlockEventExpressionOr { - pub nodes: (BlockEventExpression, Keyword, BlockEventExpression), -} - -#[derive(Clone, Debug, Node)] -pub struct BlockEventExpressionBegin { - pub nodes: (Keyword, HierarchicalBtfIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub struct BlockEventExpressionEnd { - pub nodes: (Keyword, HierarchicalBtfIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub enum HierarchicalBtfIdentifier { - HierarchicalTfIdentifier(Box), - HierarchicalBlockIdentifier(Box), - Method(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct HierarchicalBtfIdentifierMethod { - pub nodes: (Option, MethodIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub enum HierarchicalIdentifierOrClassScope { - HierarchicalIdentifier(Box<(HierarchicalIdentifier, Symbol)>), - ClassScope(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CoverPoint { - pub nodes: ( - Option<(Option, CoverPointIdentifier, Symbol)>, - Keyword, - Expression, - Option<(Keyword, Paren)>, - BinsOrEmpty, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum BinsOrEmpty { - NonEmpty(Box), - Empty(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct BinsOrEmptyNonEmpty { - pub nodes: (Brace<(Vec, Vec<(BinsOrOptions, Symbol)>)>,), -} - -#[derive(Clone, Debug, Node)] -pub enum BinsOrOptions { - CoverageOption(Box), - Covergroup(Box), - CoverPoint(Box), - SetCovergroup(Box), - TransList(Box), - Default(Box), - DefaultSequence(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct BinsOrOptionsCovergroup { - pub nodes: ( - Option, - BinsKeyword, - BinIdentifier, - Option>>, - Symbol, - Brace, - Option<(Keyword, Paren)>, - Option<(Keyword, Paren)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct Wildcard { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct BinsOrOptionsCoverPoint { - pub nodes: ( - Option, - BinsKeyword, - BinIdentifier, - Option>>, - Symbol, - CoverPointIdentifier, - Keyword, - Paren, - Option<(Keyword, Paren)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct BinsOrOptionsSetCovergroup { - pub nodes: ( - Option, - BinsKeyword, - BinIdentifier, - Option>>, - Symbol, - SetCovergroupExpression, - Option<(Keyword, Paren)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct BinsOrOptionsTransList { - pub nodes: ( - Option, - BinsKeyword, - BinIdentifier, - Option<(Symbol, Symbol)>, - Symbol, - TransList, - Option<(Keyword, Paren)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct BinsOrOptionsDefault { - pub nodes: ( - BinsKeyword, - BinIdentifier, - Option>>, - Symbol, - Keyword, - Option<(Keyword, Paren)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct BinsOrOptionsDefaultSequence { - pub nodes: ( - BinsKeyword, - BinIdentifier, - Symbol, - Keyword, - Keyword, - Option<(Keyword, Paren)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum BinsKeyword { - Bins(Box), - IllegalBins(Box), - IgnoreBins(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct TransList { - pub nodes: (List>,), -} - -#[derive(Clone, Debug, Node)] -pub struct TransSet { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub enum TransRangeList { - TransItem(Box), - Asterisk(Box), - Arrow(Box), - Equal(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct TransRangeListAsterisk { - pub nodes: (TransItem, Bracket<(Symbol, RepeatRange)>), -} - -#[derive(Clone, Debug, Node)] -pub struct TransRangeListArrow { - pub nodes: (TransItem, Bracket<(Symbol, RepeatRange)>), -} - -#[derive(Clone, Debug, Node)] -pub struct TransRangeListEqual { - pub nodes: (TransItem, Bracket<(Symbol, RepeatRange)>), -} - -#[derive(Clone, Debug, Node)] -pub struct TransItem { - pub nodes: (CovergroupRangeList,), -} - -#[derive(Clone, Debug, Node)] -pub enum RepeatRange { - CovergroupExpression(Box), - Binary(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct RepeatRangeBinary { - pub nodes: (CovergroupExpression, Symbol, CovergroupExpression), -} - -#[derive(Clone, Debug, Node)] -pub struct CoverCross { - pub nodes: ( - Option<(CrossIdentifier, Symbol)>, - Keyword, - ListOfCrossItems, - Option<(Keyword, Paren)>, - CrossBody, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfCrossItems { - pub nodes: (CrossItem, List), -} - -#[derive(Clone, Debug, Node)] -pub enum CrossItem { - CoverPointIdentifier(Box), - VariableIdentifier(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum CrossBody { - NonEmpty(Box), - Empty(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CrossBodyNonEmpty { - pub nodes: (Brace>,), -} - -#[derive(Clone, Debug, Node)] -pub enum CrossBodyItem { - FunctionDeclaration(Box), - BinsSelectionOrOption(Box<(BinsSelectionOrOption, Symbol)>), -} - -#[derive(Clone, Debug, Node)] -pub enum BinsSelectionOrOption { - Coverage(Box), - Bins(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct BinsSelectionOrOptionCoverage { - pub nodes: (Vec, CoverageOption), -} - -#[derive(Clone, Debug, Node)] -pub struct BinsSelectionOrOptionBins { - pub nodes: (Vec, BinsSelection), -} - -#[derive(Clone, Debug, Node)] -pub struct BinsSelection { - pub nodes: ( - BinsKeyword, - BinIdentifier, - Symbol, - SelectExpression, - Option<(Keyword, Paren)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum SelectExpression { - SelectCondition(Box), - Not(Box), - And(Box), - Or(Box), - Paren(Box), - With(Box), - CrossIdentifier(Box), - CrossSet(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct SelectExpressionNot { - pub nodes: (Symbol, SelectCondition), -} - -#[derive(Clone, Debug, Node)] -pub struct SelectExpressionAnd { - pub nodes: (SelectExpression, Symbol, SelectExpression), -} - -#[derive(Clone, Debug, Node)] -pub struct SelectExpressionOr { - pub nodes: (SelectExpression, Symbol, SelectExpression), -} - -#[derive(Clone, Debug, Node)] -pub struct SelectExpressionParen { - pub nodes: (Paren,), -} - -#[derive(Clone, Debug, Node)] -pub struct SelectExpressionWith { - pub nodes: ( - SelectExpression, - Keyword, - Paren, - Option<(Keyword, IntegerCovergroupExpression)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct SelectExpressionCrossSet { - pub nodes: ( - CrossSetExpression, - Option<(Keyword, IntegerCovergroupExpression)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct SelectCondition { - pub nodes: ( - Keyword, - Paren, - Option<(Keyword, Brace)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum BinsExpression { - VariableIdentifier(Box), - CoverPoint(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct BinsExpressionCoverPoint { - pub nodes: (CoverPointIdentifier, Option<(Symbol, BinIdentifier)>), -} - -#[derive(Clone, Debug, Node)] -pub struct CovergroupRangeList { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub enum CovergroupValueRange { - CovergroupExpression(Box), - Binary(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CovergroupValueRangeBinary { - pub nodes: (Bracket<(CovergroupExpression, Symbol, CovergroupExpression)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct WithCovergroupExpression { - pub nodes: (CovergroupExpression,), -} - -#[derive(Clone, Debug, Node)] -pub struct SetCovergroupExpression { - pub nodes: (CovergroupExpression,), -} - -#[derive(Clone, Debug, Node)] -pub struct IntegerCovergroupExpression { - pub nodes: (CovergroupExpression,), -} - -#[derive(Clone, Debug, Node)] -pub struct CrossSetExpression { - pub nodes: (CovergroupExpression,), -} - -#[derive(Clone, Debug, Node)] -pub struct CovergroupExpression { - pub nodes: (Expression,), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -651,7 +178,9 @@ pub(crate) fn hierarchical_btf_identifier(s: Span) -> IResult IResult { +pub(crate) fn hierarchical_btf_identifier_method( + s: Span, +) -> IResult { let (s, a) = opt(hierarchical_identifier_or_class_scope)(s)?; let (s, b) = method_identifier(s)?; Ok(( diff --git a/sv-parser/src/parser/declarations/declaration_assignments.rs b/sv-parser-parser/src/declarations/declaration_assignments.rs similarity index 60% rename from sv-parser/src/parser/declarations/declaration_assignments.rs rename to sv-parser-parser/src/declarations/declaration_assignments.rs index fffcd5b..0fc43e1 100644 --- a/sv-parser/src/parser/declarations/declaration_assignments.rs +++ b/sv-parser-parser/src/declarations/declaration_assignments.rs @@ -1,149 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct DefparamAssignment { - pub nodes: ( - HierarchicalParameterIdentifier, - Symbol, - ConstantMintypmaxExpression, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct NetDeclAssignment { - pub nodes: ( - NetIdentifier, - Vec, - Option<(Symbol, Expression)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ParamAssignment { - pub nodes: ( - ParameterIdentifier, - Vec, - Option<(Symbol, ConstantParamExpression)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum SpecparamAssignment { - Mintypmax(Box), - PulseControlSpecparam(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct SpecparamAssignmentMintypmax { - pub nodes: (SpecparamIdentifier, Symbol, ConstantMintypmaxExpression), -} - -#[derive(Clone, Debug, Node)] -pub struct TypeAssignment { - pub nodes: (TypeIdentifier, Option<(Symbol, DataType)>), -} - -#[derive(Clone, Debug, Node)] -pub enum PulseControlSpecparam { - WithoutDescriptor(Box), - WithDescriptor(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PulseControlSpecparamWithoutDescriptor { - pub nodes: ( - Symbol, - Symbol, - Paren<(RejectLimitValue, Option<(Symbol, ErrorLimitValue)>)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct PulseControlSpecparamWithDescriptor { - pub nodes: ( - Symbol, - SpecifyInputTerminalDescriptor, - Symbol, - SpecifyOutputTerminalDescriptor, - Symbol, - Paren<(RejectLimitValue, Option<(Symbol, ErrorLimitValue)>)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ErrorLimitValue { - pub nodes: (LimitValue,), -} - -#[derive(Clone, Debug, Node)] -pub struct RejectLimitValue { - pub nodes: (LimitValue,), -} - -#[derive(Clone, Debug, Node)] -pub struct LimitValue { - pub nodes: (ConstantMintypmaxExpression,), -} - -#[derive(Clone, Debug, Node)] -pub enum VariableDeclAssignment { - Variable(Box), - DynamicArray(Box), - Class(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct VariableDeclAssignmentVariable { - pub nodes: ( - VariableIdentifier, - Vec, - Option<(Symbol, Expression)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct VariableDeclAssignmentDynamicArray { - pub nodes: ( - DynamicArrayVariableIdentifier, - UnsizedDimension, - Vec, - Option<(Symbol, DynamicArrayNew)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct VariableDeclAssignmentClass { - pub nodes: (ClassVariableIdentifier, Option<(Symbol, ClassNew)>), -} - -#[derive(Clone, Debug, Node)] -pub enum ClassNew { - Argument(Box), - Expression(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassNewArgument { - pub nodes: (Option, Keyword, Option>), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassNewExpression { - pub nodes: (Keyword, Expression), -} - -#[derive(Clone, Debug, Node)] -pub struct DynamicArrayNew { - pub nodes: (Keyword, Bracket, Option>), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -208,7 +63,9 @@ pub(crate) fn pulse_control_specparam(s: Span) -> IResult IResult { +pub(crate) fn pulse_control_specparam_without_descriptor( + s: Span, +) -> IResult { let (s, a) = symbol("PATHPULSE$")(s)?; let (s, b) = symbol("=")(s)?; let (s, c) = paren(pair( @@ -224,7 +81,9 @@ pub(crate) fn pulse_control_specparam_without_descriptor(s: Span) -> IResult IResult { +pub(crate) fn pulse_control_specparam_with_descriptor( + s: Span, +) -> IResult { let (s, a) = symbol("PATHPULSE$")(s)?; let (s, b) = specify_input_terminal_descriptor(s)?; let (s, c) = symbol("$")(s)?; @@ -283,7 +142,9 @@ pub(crate) fn variable_decl_assignment_variable(s: Span) -> IResult IResult { +pub(crate) fn variable_decl_assignment_dynamic_array( + s: Span, +) -> IResult { let (s, a) = dynamic_array_variable_identifier(s)?; let (s, b) = unsized_dimension(s)?; let (s, c) = many0(variable_dimension)(s)?; diff --git a/sv-parser/src/parser/declarations/declaration_lists.rs b/sv-parser-parser/src/declarations/declaration_lists.rs similarity index 55% rename from sv-parser/src/parser/declarations/declaration_lists.rs rename to sv-parser-parser/src/declarations/declaration_lists.rs index df00936..30f2dc9 100644 --- a/sv-parser/src/parser/declarations/declaration_lists.rs +++ b/sv-parser-parser/src/declarations/declaration_lists.rs @@ -1,94 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct ListOfDefparamAssignments { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfGenvarIdentifiers { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfInterfaceIdentifiers { - pub nodes: (List)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfNetDeclAssignments { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfParamAssignments { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfPortIdentifiers { - pub nodes: (List)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfUdpPortIdentifiers { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfSpecparamAssignments { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfTfVariableIdentifiers { - pub nodes: ( - List< - Symbol, - ( - PortIdentifier, - Vec, - Option<(Symbol, Expression)>, - ), - >, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfTypeAssignments { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfVariableDeclAssignments { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfVariableIdentifiers { - pub nodes: (List)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfVariablePortIdentifiers { - pub nodes: ( - List< - Symbol, - ( - PortIdentifier, - Vec, - Option<(Symbol, ConstantExpression)>, - ), - >, - ), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -147,7 +57,9 @@ pub(crate) fn list_of_specparam_assignments(s: Span) -> IResult IResult { +pub(crate) fn list_of_tf_variable_identifiers( + s: Span, +) -> IResult { let (s, a) = list( symbol(","), triple( @@ -166,7 +78,9 @@ pub(crate) fn list_of_type_assignments(s: Span) -> IResult IResult { +pub(crate) fn list_of_variable_decl_assignments( + s: Span, +) -> IResult { let (s, a) = list(symbol(","), variable_decl_assignment)(s)?; Ok((s, ListOfVariableDeclAssignments { nodes: (a,) })) } @@ -181,7 +95,9 @@ pub(crate) fn list_of_variable_identifiers(s: Span) -> IResult IResult { +pub(crate) fn list_of_variable_port_identifiers( + s: Span, +) -> IResult { let (s, a) = list( symbol(","), triple( diff --git a/sv-parser/src/parser/declarations/declaration_ranges.rs b/sv-parser-parser/src/declarations/declaration_ranges.rs similarity index 63% rename from sv-parser/src/parser/declarations/declaration_ranges.rs rename to sv-parser-parser/src/declarations/declaration_ranges.rs index 98d9b83..e02b417 100644 --- a/sv-parser/src/parser/declarations/declaration_ranges.rs +++ b/sv-parser-parser/src/declarations/declaration_ranges.rs @@ -1,72 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum UnpackedDimension { - Range(Box), - Expression(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct UnpackedDimensionRange { - pub nodes: (Bracket,), -} - -#[derive(Clone, Debug, Node)] -pub struct UnpackedDimensionExpression { - pub nodes: (Bracket,), -} - -#[derive(Clone, Debug, Node)] -pub enum PackedDimension { - Range(Box), - UnsizedDimension(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PackedDimensionRange { - pub nodes: (Bracket,), -} - -#[derive(Clone, Debug, Node)] -pub enum AssociativeDimension { - DataType(Box), - Asterisk(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct AssociativeDimensionDataType { - pub nodes: (Bracket,), -} - -#[derive(Clone, Debug, Node)] -pub struct AssociativeDimensionAsterisk { - pub nodes: (Bracket,), -} - -#[derive(Clone, Debug, Node)] -pub enum VariableDimension { - UnsizedDimension(Box), - UnpackedDimension(Box), - AssociativeDimension(Box), - QueueDimension(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct QueueDimension { - pub nodes: (Bracket<(Symbol, Option<(Symbol, ConstantExpression)>)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct UnsizedDimension { - pub nodes: (Symbol, Symbol), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/declarations/delays.rs b/sv-parser-parser/src/declarations/delays.rs similarity index 59% rename from sv-parser/src/parser/declarations/delays.rs rename to sv-parser-parser/src/declarations/delays.rs index 662ecd7..ad22ef6 100644 --- a/sv-parser/src/parser/declarations/delays.rs +++ b/sv-parser-parser/src/declarations/delays.rs @@ -1,65 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum Delay3 { - Single(Box), - Mintypmax(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct Delay3Single { - pub nodes: (Symbol, DelayValue), -} - -#[derive(Clone, Debug, Node)] -pub struct Delay3Mintypmax { - pub nodes: ( - Symbol, - Paren<( - MintypmaxExpression, - Option<( - Symbol, - MintypmaxExpression, - Option<(Symbol, MintypmaxExpression)>, - )>, - )>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum Delay2 { - Single(Box), - Mintypmax(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct Delay2Single { - pub nodes: (Symbol, DelayValue), -} - -#[derive(Clone, Debug, Node)] -pub struct Delay2Mintypmax { - pub nodes: ( - Symbol, - Paren<(MintypmaxExpression, Option<(Symbol, MintypmaxExpression)>)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum DelayValue { - UnsignedNumber(Box), - RealNumber(Box), - PsIdentifier(Box), - TimeLiteral(Box), - Step1(Box), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/declarations/function_declarations.rs b/sv-parser-parser/src/declarations/function_declarations.rs similarity index 62% rename from sv-parser/src/parser/declarations/function_declarations.rs rename to sv-parser-parser/src/declarations/function_declarations.rs index d198547..67fb0e8 100644 --- a/sv-parser/src/parser/declarations/function_declarations.rs +++ b/sv-parser-parser/src/declarations/function_declarations.rs @@ -1,157 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum FunctionDataTypeOrImplicit { - DataTypeOrVoid(Box), - ImplicitDataType(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct FunctionDeclaration { - pub nodes: (Keyword, Option, FunctionBodyDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub enum FunctionBodyDeclaration { - WithoutPort(Box), - WithPort(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct FunctionBodyDeclarationWithoutPort { - pub nodes: ( - Option, - Option, - FunctionIdentifier, - Symbol, - Vec, - Vec, - Keyword, - Option<(Symbol, FunctionIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct FunctionBodyDeclarationWithPort { - pub nodes: ( - Option, - Option, - FunctionIdentifier, - Paren>, - Symbol, - Vec, - Vec, - Keyword, - Option<(Symbol, FunctionIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum InterfaceIdentifierOrClassScope { - InterfaceIdentifier(Box<(InterfaceIdentifier, Symbol)>), - ClassScope(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct FunctionPrototype { - pub nodes: ( - Keyword, - DataTypeOrVoid, - FunctionIdentifier, - Option>>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum DpiImportExport { - ImportFunction(Box), - ImportTask(Box), - ExportFunction(Box), - ExportTask(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct DpiImportExportImportFunction { - pub nodes: ( - Keyword, - DpiSpecString, - Option, - Option<(CIdentifier, Symbol)>, - DpiFunctionProto, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct DpiImportExportImportTask { - pub nodes: ( - Keyword, - DpiSpecString, - Option, - Option<(CIdentifier, Symbol)>, - DpiTaskProto, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct DpiImportExportExportFunction { - pub nodes: ( - Keyword, - DpiSpecString, - Option<(CIdentifier, Symbol)>, - Keyword, - FunctionIdentifier, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct DpiImportExportExportTask { - pub nodes: ( - Keyword, - DpiSpecString, - Option<(CIdentifier, Symbol)>, - Keyword, - TaskIdentifier, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum DpiSpecString { - DpiC(Box), - Dpi(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum DpiFunctionImportProperty { - Context(Box), - Pure(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum DpiTaskImportProperty { - Context(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct DpiFunctionProto { - pub nodes: (FunctionPrototype,), -} - -#[derive(Clone, Debug, Node)] -pub struct DpiTaskProto { - pub nodes: (TaskPrototype,), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -184,7 +31,9 @@ pub(crate) fn function_body_declaration(s: Span) -> IResult IResult { +pub(crate) fn function_body_declaration_without_port( + s: Span, +) -> IResult { let (s, a) = ambiguous_opt(function_data_type_or_implicit)(s)?; let (s, b) = opt(interface_identifier_or_class_scope)(s)?; let (s, c) = function_identifier(s)?; @@ -202,7 +51,9 @@ pub(crate) fn function_body_declaration_without_port(s: Span) -> IResult IResult { +pub(crate) fn function_body_declaration_with_port( + s: Span, +) -> IResult { let (s, a) = ambiguous_opt(function_data_type_or_implicit)(s)?; let (s, b) = opt(interface_identifier_or_class_scope)(s)?; let (s, c) = function_identifier(s)?; diff --git a/sv-parser/src/parser/declarations/interface_declarations.rs b/sv-parser-parser/src/declarations/interface_declarations.rs similarity index 62% rename from sv-parser/src/parser/declarations/interface_declarations.rs rename to sv-parser-parser/src/declarations/interface_declarations.rs index 57200cd..ba5ce79 100644 --- a/sv-parser/src/parser/declarations/interface_declarations.rs +++ b/sv-parser-parser/src/declarations/interface_declarations.rs @@ -1,89 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct ModportDeclaration { - pub nodes: (Keyword, List, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct ModportItem { - pub nodes: ( - ModportIdentifier, - Paren>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ModportPortsDeclaraton { - Simple(Box), - Tf(Box), - Clocking(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ModportPortsDeclaratonSimple { - pub nodes: (Vec, ModportSimplePortsDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct ModportPortsDeclaratonTf { - pub nodes: (Vec, ModportTfPortsDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct ModportPortsDeclaratonClocking { - pub nodes: (Vec, ModportClockingDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct ModportClockingDeclaration { - pub nodes: (Keyword, ClockingIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub struct ModportSimplePortsDeclaration { - pub nodes: (PortDirection, List), -} - -#[derive(Clone, Debug, Node)] -pub enum ModportSimplePort { - Ordered(Box), - Named(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ModportSimplePortOrdered { - pub nodes: (PortIdentifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct ModportSimplePortNamed { - pub nodes: (Symbol, PortIdentifier, Paren>), -} - -#[derive(Clone, Debug, Node)] -pub struct ModportTfPortsDeclaration { - pub nodes: (ImportExport, List), -} - -#[derive(Clone, Debug, Node)] -pub enum ModportTfPort { - MethodPrototype(Box), - TfIdentifier(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum ImportExport { - Import(Box), - Export(Box), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -151,7 +66,9 @@ pub(crate) fn modport_clocking_declaration(s: Span) -> IResult IResult { +pub(crate) fn modport_simple_ports_declaration( + s: Span, +) -> IResult { let (s, a) = port_direction(s)?; let (s, b) = list(symbol(","), modport_simple_port)(s)?; Ok((s, ModportSimplePortsDeclaration { nodes: (a, b) })) diff --git a/sv-parser/src/parser/declarations/let_declarations.rs b/sv-parser-parser/src/declarations/let_declarations.rs similarity index 62% rename from sv-parser/src/parser/declarations/let_declarations.rs rename to sv-parser-parser/src/declarations/let_declarations.rs index 068014e..be9c312 100644 --- a/sv-parser/src/parser/declarations/let_declarations.rs +++ b/sv-parser-parser/src/declarations/let_declarations.rs @@ -1,84 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct LetDeclaration { - pub nodes: ( - Keyword, - LetIdentifier, - Option>>, - Symbol, - Expression, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct LetIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct LetPortList { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct LetPortItem { - pub nodes: ( - Vec, - Option, - FormalPortIdentifier, - Vec, - Option<(Symbol, Expression)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum LetFormalType { - DataTypeOrImplicit(Box), - Untyped(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct LetExpression { - pub nodes: ( - Option, - LetIdentifier, - Option>>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum LetListOfArguments { - Ordered(Box), - Named(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct LetListOfArgumentsOrdered { - pub nodes: ( - List>, - Vec<(Symbol, Symbol, Identifier, Paren>)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct LetListOfArgumentsNamed { - pub nodes: (List>)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct LetActualArg { - pub nodes: (Expression,), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser-parser/src/declarations/mod.rs b/sv-parser-parser/src/declarations/mod.rs new file mode 100644 index 0000000..004fef8 --- /dev/null +++ b/sv-parser-parser/src/declarations/mod.rs @@ -0,0 +1,32 @@ +pub mod assertion_declarations; +pub mod block_item_declarations; +pub mod covergroup_declarations; +pub mod declaration_assignments; +pub mod declaration_lists; +pub mod declaration_ranges; +pub mod delays; +pub mod function_declarations; +pub mod interface_declarations; +pub mod let_declarations; +pub mod module_parameter_declarations; +pub mod net_and_variable_types; +pub mod port_declarations; +pub mod strengths; +pub mod task_declarations; +pub mod type_declarations; +pub(crate) use assertion_declarations::*; +pub(crate) use block_item_declarations::*; +pub(crate) use covergroup_declarations::*; +pub(crate) use declaration_assignments::*; +pub(crate) use declaration_lists::*; +pub(crate) use declaration_ranges::*; +pub(crate) use delays::*; +pub(crate) use function_declarations::*; +pub(crate) use interface_declarations::*; +pub(crate) use let_declarations::*; +pub(crate) use module_parameter_declarations::*; +pub(crate) use net_and_variable_types::*; +pub(crate) use port_declarations::*; +pub(crate) use strengths::*; +pub(crate) use task_declarations::*; +pub(crate) use type_declarations::*; diff --git a/sv-parser-parser/src/declarations/module_parameter_declarations.rs b/sv-parser-parser/src/declarations/module_parameter_declarations.rs new file mode 100644 index 0000000..16d70db --- /dev/null +++ b/sv-parser-parser/src/declarations/module_parameter_declarations.rs @@ -0,0 +1,82 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[parser] +pub(crate) fn local_parameter_declaration(s: Span) -> IResult { + alt(( + local_parameter_declaration_param, + local_parameter_declaration_type, + ))(s) +} + +#[parser(Ambiguous)] +pub(crate) fn local_parameter_declaration_param( + s: Span, +) -> IResult { + let (s, a) = keyword("localparam")(s)?; + let (s, b) = ambiguous_opt(data_type_or_implicit)(s)?; + let (s, c) = list_of_param_assignments(s)?; + Ok(( + s, + LocalParameterDeclaration::Param(Box::new(LocalParameterDeclarationParam { + nodes: (a, b, c), + })), + )) +} + +#[parser] +pub(crate) fn local_parameter_declaration_type( + s: Span, +) -> IResult { + let (s, a) = keyword("localparam")(s)?; + let (s, b) = keyword("type")(s)?; + let (s, c) = list_of_type_assignments(s)?; + Ok(( + s, + LocalParameterDeclaration::Type(Box::new(LocalParameterDeclarationType { + nodes: (a, b, c), + })), + )) +} + +#[parser] +pub(crate) fn parameter_declaration(s: Span) -> IResult { + alt((parameter_declaration_param, parameter_declaration_type))(s) +} + +#[parser(Ambiguous)] +pub(crate) fn parameter_declaration_param(s: Span) -> IResult { + let (s, a) = keyword("parameter")(s)?; + let (s, b) = ambiguous_opt(data_type_or_implicit)(s)?; + let (s, c) = list_of_param_assignments(s)?; + Ok(( + s, + ParameterDeclaration::Param(Box::new(ParameterDeclarationParam { nodes: (a, b, c) })), + )) +} + +#[parser] +pub(crate) fn parameter_declaration_type(s: Span) -> IResult { + let (s, a) = keyword("parameter")(s)?; + let (s, b) = keyword("type")(s)?; + let (s, c) = list_of_type_assignments(s)?; + Ok(( + s, + ParameterDeclaration::Type(Box::new(ParameterDeclarationType { nodes: (a, b, c) })), + )) +} + +#[parser] +pub(crate) fn specparam_declaration(s: Span) -> IResult { + let (s, a) = keyword("specparam")(s)?; + let (s, b) = opt(packed_dimension)(s)?; + let (s, c) = list_of_specparam_assignments(s)?; + let (s, d) = symbol(";")(s)?; + Ok(( + s, + SpecparamDeclaration { + nodes: (a, b, c, d), + }, + )) +} diff --git a/sv-parser/src/parser/declarations/net_and_variable_types.rs b/sv-parser-parser/src/declarations/net_and_variable_types.rs similarity index 62% rename from sv-parser/src/parser/declarations/net_and_variable_types.rs rename to sv-parser-parser/src/declarations/net_and_variable_types.rs index 419458c..2067d5d 100644 --- a/sv-parser/src/parser/declarations/net_and_variable_types.rs +++ b/sv-parser-parser/src/declarations/net_and_variable_types.rs @@ -1,288 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; -use nom_packrat::packrat_parser; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum CastingType { - SimpleType(Box), - ConstantPrimary(Box), - Signing(Box), - String(Box), - Const(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum DataType { - Vector(Box), - Atom(Box), - NonIntegerType(Box), - StructUnion(Box), - Enum(Box), - String(Box), - Chandle(Box), - Virtual(Box), - Type(Box), - ClassType(Box), - Event(Box), - PsCovergroupIdentifier(Box), - TypeReference(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct DataTypeVector { - pub nodes: (IntegerVectorType, Option, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct DataTypeAtom { - pub nodes: (IntegerAtomType, Option), -} - -#[derive(Clone, Debug, Node)] -pub struct DataTypeStructUnion { - pub nodes: ( - StructUnion, - Option<(Packed, Option)>, - Brace<(StructUnionMember, Vec)>, - Vec, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct Packed { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct DataTypeEnum { - pub nodes: ( - Keyword, - Option, - Brace>, - Vec, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct DataTypeVirtual { - pub nodes: ( - Keyword, - Option, - InterfaceIdentifier, - Option, - Option<(Symbol, ModportIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct Interface { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct DataTypeType { - pub nodes: ( - Option, - TypeIdentifier, - Vec, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum DataTypeOrImplicit { - DataType(Box), - ImplicitDataType(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ImplicitDataType { - pub nodes: (Option, Vec), -} - -#[derive(Clone, Debug, Node)] -pub enum EnumBaseType { - Atom(Box), - Vector(Box), - Type(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct EnumBaseTypeAtom { - pub nodes: (IntegerAtomType, Option), -} - -#[derive(Clone, Debug, Node)] -pub struct EnumBaseTypeVector { - pub nodes: (IntegerVectorType, Option, Option), -} - -#[derive(Clone, Debug, Node)] -pub struct EnumBaseTypeType { - pub nodes: (TypeIdentifier, Option), -} - -#[derive(Clone, Debug, Node)] -pub struct EnumNameDeclaration { - pub nodes: ( - EnumIdentifier, - Option)>>, - Option<(Symbol, ConstantExpression)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassScope { - pub nodes: (ClassType, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassType { - pub nodes: ( - PsClassIdentifier, - Option, - Vec<(Symbol, ClassIdentifier, Option)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum IntegerType { - IntegerVectorType(Box), - IntegerAtomType(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum IntegerAtomType { - Byte(Box), - Shortint(Box), - Int(Box), - Longint(Box), - Integer(Box), - Time(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum IntegerVectorType { - Bit(Box), - Logic(Box), - Reg(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum NonIntegerType { - Shortreal(Box), - Real(Box), - Realtime(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum NetType { - Supply0(Box), - Supply1(Box), - Tri(Box), - Triand(Box), - Trior(Box), - Trireg(Box), - Tri0(Box), - Tri1(Box), - Uwire(Box), - Wire(Box), - Wand(Box), - Wor(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum NetPortType { - DataType(Box), - NetTypeIdentifier(Box), - Interconnect(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct NetPortTypeDataType { - pub nodes: (Option, DataTypeOrImplicit), -} - -#[derive(Clone, Debug, Node)] -pub struct NetPortTypeInterconnect { - pub nodes: (Keyword, ImplicitDataType), -} - -#[derive(Clone, Debug, Node)] -pub struct VariablePortType { - pub nodes: (VarDataType,), -} - -#[derive(Clone, Debug, Node)] -pub enum VarDataType { - DataType(Box), - Var(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct VarDataTypeVar { - pub nodes: (Keyword, DataTypeOrImplicit), -} - -#[derive(Clone, Debug, Node)] -pub enum Signing { - Signed(Box), - Unsigned(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum SimpleType { - IntegerType(Box), - NonIntegerType(Box), - PsTypeIdentifier(Box), - PsParameterIdentifier(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct StructUnionMember { - pub nodes: ( - Vec, - Option, - DataTypeOrVoid, - ListOfVariableDeclAssignments, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum DataTypeOrVoid { - DataType(Box), - Void(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum StructUnion { - Struct(Box), - Union(Box), - UnionTagged(Box<(Keyword, Keyword)>), -} - -#[derive(Clone, Debug, Node)] -pub enum TypeReference { - Expression(Box), - DataType(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct TypeReferenceExpression { - pub nodes: (Keyword, Paren), -} - -#[derive(Clone, Debug, Node)] -pub struct TypeReferenceDataType { - pub nodes: (Keyword, Paren), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -701,44 +417,3 @@ pub(crate) fn type_reference_data_type(s: Span) -> IResult TypeReference::DataType(Box::new(TypeReferenceDataType { nodes: (a, b) })), )) } - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_data_type() { - parser_test!( - data_type, - "struct { bit [7:0] opcode; bit [23:0] addr; }", - Ok((_, DataType::StructUnion(_))) - ); - parser_test!( - data_type, - "struct packed signed { int a; shortint b; byte c; bit [7:0] d; }", - Ok((_, DataType::StructUnion(_))) - ); - parser_test!( - data_type, - "union { int i; shortreal f; } ", - Ok((_, DataType::StructUnion(_))) - ); - parser_test!( - data_type, - "struct { bit isfloat; union { int i; shortreal f; } n; }", - Ok((_, DataType::StructUnion(_))) - ); - parser_test!( - data_type, - "union packed { s_atmcell acell; bit [423:0] bit_slice; bit [52:0][7:0] byte_slice; }", - Ok((_, DataType::StructUnion(_))) - ); - parser_test!( - data_type, - "union tagged { void Invalid; int Valid; }", - Ok((_, DataType::StructUnion(_))) - ); - } -} diff --git a/sv-parser/src/parser/declarations/port_declarations.rs b/sv-parser-parser/src/declarations/port_declarations.rs similarity index 63% rename from sv-parser/src/parser/declarations/port_declarations.rs rename to sv-parser-parser/src/declarations/port_declarations.rs index 25aa56a..91d1b38 100644 --- a/sv-parser/src/parser/declarations/port_declarations.rs +++ b/sv-parser-parser/src/declarations/port_declarations.rs @@ -1,62 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct InoutDeclaration { - pub nodes: (Keyword, Option, ListOfPortIdentifiers), -} - -#[derive(Clone, Debug, Node)] -pub enum InputDeclaration { - Net(Box), - Variable(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct InputDeclarationNet { - pub nodes: (Keyword, Option, ListOfPortIdentifiers), -} - -#[derive(Clone, Debug, Node)] -pub struct InputDeclarationVariable { - pub nodes: (Keyword, VariablePortType, ListOfVariableIdentifiers), -} - -#[derive(Clone, Debug, Node)] -pub enum OutputDeclaration { - Net(Box), - Variable(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct OutputDeclarationNet { - pub nodes: (Keyword, Option, ListOfPortIdentifiers), -} - -#[derive(Clone, Debug, Node)] -pub struct OutputDeclarationVariable { - pub nodes: (Keyword, VariablePortType, ListOfVariablePortIdentifiers), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfacePortDeclaration { - pub nodes: ( - InterfaceIdentifier, - Option<(Symbol, ModportIdentifier)>, - ListOfInterfaceIdentifiers, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct RefDeclaration { - pub nodes: (Keyword, VariablePortType, ListOfVariableIdentifiers), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -155,17 +97,3 @@ pub(crate) fn implicit_var(s: Span) -> IResult { }, )) } - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_inout_declaration() { - parser_test!(inout_declaration, "inout a", Ok((_, _))); - parser_test!(inout_declaration, "inout [7:0] a", Ok((_, _))); - parser_test!(inout_declaration, "inout signed [7:0] a", Ok((_, _))); - } -} diff --git a/sv-parser/src/parser/declarations/strengths.rs b/sv-parser-parser/src/declarations/strengths.rs similarity index 56% rename from sv-parser/src/parser/declarations/strengths.rs rename to sv-parser-parser/src/declarations/strengths.rs index 300c3b6..75a87a7 100644 --- a/sv-parser/src/parser/declarations/strengths.rs +++ b/sv-parser-parser/src/declarations/strengths.rs @@ -1,88 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum DriveStrength { - Strength01(Box), - Strength10(Box), - Strength0z(Box), - Strength1z(Box), - Strengthz0(Box), - Strengthz1(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct DriveStrength01 { - pub nodes: (Paren<(Strength0, Symbol, Strength1)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct DriveStrength10 { - pub nodes: (Paren<(Strength1, Symbol, Strength0)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct DriveStrength0z { - pub nodes: (Paren<(Strength0, Symbol, Keyword)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct DriveStrength1z { - pub nodes: (Paren<(Strength1, Symbol, Keyword)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct DriveStrengthz1 { - pub nodes: (Paren<(Keyword, Symbol, Strength1)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct DriveStrengthz0 { - pub nodes: (Paren<(Keyword, Symbol, Strength0)>,), -} - -#[derive(Clone, Debug, Node)] -pub enum Strength0 { - Supply0(Box), - Strong0(Box), - Pull0(Box), - Weak0(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum Strength1 { - Supply1(Box), - Strong1(Box), - Pull1(Box), - Weak1(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum ChargeStrength { - Small(Box), - Medium(Box), - Large(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ChargeStrengthSmall { - pub nodes: (Paren,), -} - -#[derive(Clone, Debug, Node)] -pub struct ChargeStrengthMedium { - pub nodes: (Paren,), -} - -#[derive(Clone, Debug, Node)] -pub struct ChargeStrengthLarge { - pub nodes: (Paren,), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -207,27 +123,3 @@ pub(crate) fn charge_strength_large(s: Span) -> IResult { ChargeStrength::Large(Box::new(ChargeStrengthLarge { nodes: (a,) })), )) } - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_drive_strength() { - parser_test!(drive_strength, "(supply0, strong1)", Ok((_, _))); - parser_test!(drive_strength, "(pull1, weak0)", Ok((_, _))); - parser_test!(drive_strength, "(pull0, highz1)", Ok((_, _))); - parser_test!(drive_strength, "(weak1, highz0)", Ok((_, _))); - parser_test!(drive_strength, "(highz0, supply1)", Ok((_, _))); - parser_test!(drive_strength, "(highz1, strong0)", Ok((_, _))); - } - - #[test] - fn test_charge_strength() { - parser_test!(charge_strength, "( small)", Ok((_, _))); - parser_test!(charge_strength, "( medium )", Ok((_, _))); - parser_test!(charge_strength, "(large)", Ok((_, _))); - } -} diff --git a/sv-parser/src/parser/declarations/task_declarations.rs b/sv-parser-parser/src/declarations/task_declarations.rs similarity index 62% rename from sv-parser/src/parser/declarations/task_declarations.rs rename to sv-parser-parser/src/declarations/task_declarations.rs index 157ef62..9660209 100644 --- a/sv-parser/src/parser/declarations/task_declarations.rs +++ b/sv-parser-parser/src/declarations/task_declarations.rs @@ -1,99 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct TaskDeclaration { - pub nodes: (Keyword, Option, TaskBodyDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub enum TaskBodyDeclaration { - WithoutPort(Box), - WithPort(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct TaskBodyDeclarationWithoutPort { - pub nodes: ( - Option, - TaskIdentifier, - Symbol, - Vec, - Vec, - Keyword, - Option<(Symbol, TaskIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct TaskBodyDeclarationWithPort { - pub nodes: ( - Option, - TaskIdentifier, - Paren>, - Symbol, - Vec, - Vec, - Keyword, - Option<(Symbol, TaskIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum TfItemDeclaration { - BlockItemDeclaration(Box), - TfPortDeclaration(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct TfPortList { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct TfPortItem { - pub nodes: ( - Vec, - Option, - Option, - Option, - Option<( - PortIdentifier, - Vec, - Option<(Symbol, Expression)>, - )>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum TfPortDirection { - PortDirection(Box), - ConstRef(Box<(Keyword, Keyword)>), -} - -#[derive(Clone, Debug, Node)] -pub struct TfPortDeclaration { - pub nodes: ( - Vec, - TfPortDirection, - Option, - Option, - ListOfTfVariableIdentifiers, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct TaskPrototype { - pub nodes: (Keyword, TaskIdentifier, Option>>), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser-parser/src/declarations/type_declarations.rs b/sv-parser-parser/src/declarations/type_declarations.rs new file mode 100644 index 0000000..675d1ed --- /dev/null +++ b/sv-parser-parser/src/declarations/type_declarations.rs @@ -0,0 +1,321 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[parser] +pub(crate) fn data_declaration(s: Span) -> IResult { + alt(( + data_declaration_variable, + map(type_declaration, |x| { + DataDeclaration::TypeDeclaration(Box::new(x)) + }), + map(package_import_declaration, |x| { + DataDeclaration::PackageImportDeclaration(Box::new(x)) + }), + map(net_type_declaration, |x| { + DataDeclaration::NetTypeDeclaration(Box::new(x)) + }), + ))(s) +} + +#[parser(Ambiguous)] +pub(crate) fn data_declaration_variable(s: Span) -> IResult { + let (s, a) = opt(r#const)(s)?; + let (s, b) = opt(var)(s)?; + let (s, c) = opt(lifetime)(s)?; + let (s, d) = ambiguous_opt(data_type_or_implicit)(s)?; + let (s, e) = list_of_variable_decl_assignments(s)?; + let (s, f) = symbol(";")(s)?; + Ok(( + s, + DataDeclaration::Variable(Box::new(DataDeclarationVariable { + nodes: (a, b, c, d, e, f), + })), + )) +} + +#[parser] +pub(crate) fn r#const(s: Span) -> IResult { + let (s, a) = keyword("const")(s)?; + Ok((s, Const { nodes: (a,) })) +} + +#[parser] +pub(crate) fn package_import_declaration(s: Span) -> IResult { + let (s, a) = keyword("import")(s)?; + let (s, b) = list(symbol(","), package_import_item)(s)?; + let (s, c) = symbol(";")(s)?; + Ok((s, PackageImportDeclaration { nodes: (a, b, c) })) +} + +#[parser] +pub(crate) fn package_import_item(s: Span) -> IResult { + alt((package_import_item_identifier, package_import_item_asterisk))(s) +} + +#[parser] +pub(crate) fn package_import_item_identifier(s: Span) -> IResult { + let (s, a) = package_identifier(s)?; + let (s, b) = symbol("::")(s)?; + let (s, c) = identifier(s)?; + Ok(( + s, + PackageImportItem::Identifier(Box::new(PackageImportItemIdentifier { nodes: (a, b, c) })), + )) +} + +#[parser] +pub(crate) fn package_import_item_asterisk(s: Span) -> IResult { + let (s, a) = package_identifier(s)?; + let (s, b) = symbol("::")(s)?; + let (s, c) = symbol("*")(s)?; + Ok(( + s, + PackageImportItem::Asterisk(Box::new(PackageImportItemAsterisk { nodes: (a, b, c) })), + )) +} + +#[parser] +pub(crate) fn package_export_declaration(s: Span) -> IResult { + alt(( + package_export_declaration_asterisk, + package_export_declaration_item, + ))(s) +} + +#[parser] +pub(crate) fn package_export_declaration_asterisk( + s: Span, +) -> IResult { + let (s, a) = keyword("export")(s)?; + let (s, b) = symbol("*::*")(s)?; + let (s, c) = symbol(";")(s)?; + Ok(( + s, + PackageExportDeclaration::Asterisk(Box::new(PackageExportDeclarationAsterisk { + nodes: (a, b, c), + })), + )) +} + +#[parser] +pub(crate) fn package_export_declaration_item(s: Span) -> IResult { + let (s, a) = keyword("export")(s)?; + let (s, b) = list(symbol(","), package_import_item)(s)?; + let (s, c) = symbol(";")(s)?; + Ok(( + s, + PackageExportDeclaration::Item(Box::new(PackageExportDeclarationItem { nodes: (a, b, c) })), + )) +} + +#[parser] +pub(crate) fn genvar_declaration(s: Span) -> IResult { + let (s, a) = keyword("genvar")(s)?; + let (s, b) = list_of_genvar_identifiers(s)?; + let (s, c) = symbol(";")(s)?; + Ok((s, GenvarDeclaration { nodes: (a, b, c) })) +} + +#[parser] +pub(crate) fn net_declaration(s: Span) -> IResult { + alt(( + net_declaration_interconnect, + net_declaration_net_type, + net_declaration_net_type_identifier, + ))(s) +} + +#[parser(Ambiguous)] +pub(crate) fn net_declaration_net_type(s: Span) -> IResult { + let (s, a) = net_type(s)?; + let (s, b) = opt(strength)(s)?; + let (s, c) = opt(vector_scalar)(s)?; + let (s, d) = ambiguous_opt(data_type_or_implicit)(s)?; + let (s, e) = opt(delay3)(s)?; + let (s, f) = list_of_net_decl_assignments(s)?; + let (s, g) = symbol(";")(s)?; + Ok(( + s, + NetDeclaration::NetType(Box::new(NetDeclarationNetType { + nodes: (a, b, c, d, e, f, g), + })), + )) +} + +#[parser] +pub(crate) fn strength(s: Span) -> IResult { + alt(( + map(drive_strength, |x| Strength::Drive(Box::new(x))), + map(charge_strength, |x| Strength::Charge(Box::new(x))), + ))(s) +} + +#[parser] +pub(crate) fn vector_scalar(s: Span) -> IResult { + alt(( + map(keyword("vectored"), |x| VectorScalar::Vectored(Box::new(x))), + map(keyword("scalared"), |x| VectorScalar::Scalared(Box::new(x))), + ))(s) +} + +#[parser] +pub(crate) fn net_declaration_net_type_identifier(s: Span) -> IResult { + let (s, a) = net_type_identifier(s)?; + let (s, b) = opt(delay_control)(s)?; + let (s, c) = list_of_net_decl_assignments(s)?; + let (s, d) = symbol(";")(s)?; + Ok(( + s, + NetDeclaration::NetTypeIdentifier(Box::new(NetDeclarationNetTypeIdentifier { + nodes: (a, b, c, d), + })), + )) +} + +#[parser] +pub(crate) fn net_declaration_interconnect(s: Span) -> IResult { + let (s, a) = keyword("interconnect")(s)?; + let (s, b) = implicit_data_type(s)?; + let (s, c) = opt(pair(symbol("#"), delay_value))(s)?; + let (s, d) = net_identifier(s)?; + let (s, e) = many0(unpacked_dimension)(s)?; + let (s, f) = opt(triple( + symbol(","), + net_identifier, + many0(unpacked_dimension), + ))(s)?; + let (s, g) = symbol(";")(s)?; + Ok(( + s, + NetDeclaration::Interconnect(Box::new(NetDeclarationInterconnect { + nodes: (a, b, c, d, e, f, g), + })), + )) +} + +#[parser] +pub(crate) fn type_declaration(s: Span) -> IResult { + alt(( + type_declaration_data_type, + type_declaration_interface, + type_declaration_reserved, + ))(s) +} + +#[parser] +pub(crate) fn type_declaration_data_type(s: Span) -> IResult { + let (s, a) = keyword("typedef")(s)?; + let (s, b) = data_type(s)?; + let (s, c) = type_identifier(s)?; + let (s, d) = many0(variable_dimension)(s)?; + let (s, e) = symbol(";")(s)?; + Ok(( + s, + TypeDeclaration::DataType(Box::new(TypeDeclarationDataType { + nodes: (a, b, c, d, e), + })), + )) +} + +#[parser] +pub(crate) fn type_declaration_interface(s: Span) -> IResult { + let (s, a) = keyword("typedef")(s)?; + let (s, b) = interface_instance_identifier(s)?; + let (s, c) = constant_bit_select(s)?; + let (s, d) = symbol(".")(s)?; + let (s, e) = type_identifier(s)?; + let (s, f) = type_identifier(s)?; + let (s, g) = symbol(";")(s)?; + Ok(( + s, + TypeDeclaration::Interface(Box::new(TypeDeclarationInterface { + nodes: (a, b, c, d, e, f, g), + })), + )) +} + +#[parser] +pub(crate) fn type_declaration_reserved(s: Span) -> IResult { + let (s, a) = keyword("typedef")(s)?; + let (s, b) = opt(type_declaration_keyword)(s)?; + let (s, c) = type_identifier(s)?; + let (s, d) = symbol(";")(s)?; + Ok(( + s, + TypeDeclaration::Reserved(Box::new(TypeDeclarationReserved { + nodes: (a, b, c, d), + })), + )) +} + +#[parser] +pub(crate) fn type_declaration_keyword(s: Span) -> IResult { + alt(( + map(keyword("enum"), |x| { + TypeDeclarationKeyword::Enum(Box::new(x)) + }), + map(keyword("struct"), |x| { + TypeDeclarationKeyword::Struct(Box::new(x)) + }), + map(keyword("union"), |x| { + TypeDeclarationKeyword::Union(Box::new(x)) + }), + map(keyword("class"), |x| { + TypeDeclarationKeyword::Class(Box::new(x)) + }), + map(pair(keyword("interface"), keyword("class")), |x| { + TypeDeclarationKeyword::InterfaceClass(Box::new(x)) + }), + ))(s) +} + +#[parser] +pub(crate) fn net_type_declaration(s: Span) -> IResult { + alt(( + net_type_declaration_data_type, + net_type_declaration_net_type, + ))(s) +} + +#[parser] +pub(crate) fn net_type_declaration_data_type(s: Span) -> IResult { + let (s, a) = keyword("nettype")(s)?; + let (s, b) = data_type(s)?; + let (s, c) = net_type_identifier(s)?; + let (s, d) = opt(triple( + keyword("with"), + opt(package_scope_or_class_scope), + tf_identifier, + ))(s)?; + let (s, e) = symbol(";")(s)?; + Ok(( + s, + NetTypeDeclaration::DataType(Box::new(NetTypeDeclarationDataType { + nodes: (a, b, c, d, e), + })), + )) +} + +#[parser] +pub(crate) fn net_type_declaration_net_type(s: Span) -> IResult { + let (s, a) = keyword("nettype")(s)?; + let (s, b) = opt(package_scope_or_class_scope)(s)?; + let (s, c) = net_type_identifier(s)?; + let (s, d) = net_type_identifier(s)?; + let (s, e) = symbol(";")(s)?; + Ok(( + s, + NetTypeDeclaration::NetType(Box::new(NetTypeDeclarationNetType { + nodes: (a, b, c, d, e), + })), + )) +} + +#[parser] +pub(crate) fn lifetime(s: Span) -> IResult { + alt(( + map(keyword("static"), |x| Lifetime::Static(Box::new(x))), + map(keyword("automatic"), |x| Lifetime::Automatic(Box::new(x))), + ))(s) +} diff --git a/sv-parser/src/parser/expressions/concatenations.rs b/sv-parser-parser/src/expressions/concatenations.rs similarity index 62% rename from sv-parser/src/parser/expressions/concatenations.rs rename to sv-parser-parser/src/expressions/concatenations.rs index cb05e24..60f2a7d 100644 --- a/sv-parser/src/parser/expressions/concatenations.rs +++ b/sv-parser-parser/src/expressions/concatenations.rs @@ -1,95 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct Concatenation { - pub nodes: (Brace>,), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantConcatenation { - pub nodes: (Brace>,), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantMultipleConcatenation { - pub nodes: (Brace<(ConstantExpression, ConstantConcatenation)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct ModulePathConcatenation { - pub nodes: (Brace>,), -} - -#[derive(Clone, Debug, Node)] -pub struct ModulePathMultipleConcatenation { - pub nodes: (Brace<(ConstantExpression, ModulePathConcatenation)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct MultipleConcatenation { - pub nodes: (Brace<(Expression, Concatenation)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct StreamingConcatenation { - pub nodes: (Brace<(StreamOperator, Option, StreamConcatenation)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct StreamOperator { - pub nodes: (Symbol,), -} - -#[derive(Clone, Debug, Node)] -pub enum SliceSize { - SimpleType(Box), - ConstantExpression(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct StreamConcatenation { - pub nodes: (Brace>,), -} - -#[derive(Clone, Debug, Node)] -pub struct StreamExpression { - pub nodes: (Expression, Option<(Keyword, Bracket)>), -} - -#[derive(Clone, Debug, Node)] -pub enum ArrayRangeExpression { - Expression(Box), - Colon(Box), - PlusColon(Box), - MinusColon(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ArrayRangeExpressionColon { - pub nodes: (Expression, Symbol, Expression), -} - -#[derive(Clone, Debug, Node)] -pub struct ArrayRangeExpressionPlusColon { - pub nodes: (Expression, Symbol, Expression), -} - -#[derive(Clone, Debug, Node)] -pub struct ArrayRangeExpressionMinusColon { - pub nodes: (Expression, Symbol, Expression), -} - -#[derive(Clone, Debug, Node)] -pub struct EmptyUnpackedArrayConcatenation { - pub nodes: (Symbol, Symbol), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -106,7 +15,9 @@ pub(crate) fn constant_concatenation(s: Span) -> IResult IResult { +pub(crate) fn constant_multiple_concatenation( + s: Span, +) -> IResult { let (s, a) = brace(pair(constant_expression, constant_concatenation))(s)?; Ok((s, ConstantMultipleConcatenation { nodes: (a,) })) } @@ -229,5 +140,3 @@ pub(crate) fn empty_unpacked_array_concatenation( let (s, b) = symbol("}")(s)?; Ok((s, EmptyUnpackedArrayConcatenation { nodes: (a, b) })) } - -// ----------------------------------------------------------------------------- diff --git a/sv-parser-parser/src/expressions/expression_leftside_values.rs b/sv-parser-parser/src/expressions/expression_leftside_values.rs new file mode 100644 index 0000000..421d86a --- /dev/null +++ b/sv-parser-parser/src/expressions/expression_leftside_values.rs @@ -0,0 +1,89 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[packrat_parser] +#[parser] +pub(crate) fn net_lvalue(s: Span) -> IResult { + alt((net_lvalue_identifier, net_lvalue_lvalue, net_lvalue_pattern))(s) +} + +#[parser] +pub(crate) fn net_lvalue_identifier(s: Span) -> IResult { + let (s, a) = ps_or_hierarchical_net_identifier(s)?; + let (s, b) = constant_select(s)?; + Ok(( + s, + NetLvalue::Identifier(Box::new(NetLvalueIdentifier { nodes: (a, b) })), + )) +} + +#[parser] +pub(crate) fn net_lvalue_pattern(s: Span) -> IResult { + let (s, a) = opt(assignment_pattern_expression_type)(s)?; + let (s, b) = assignment_pattern_net_lvalue(s)?; + Ok(( + s, + NetLvalue::Pattern(Box::new(NetLvaluePattern { nodes: (a, b) })), + )) +} + +#[parser] +pub(crate) fn net_lvalue_lvalue(s: Span) -> IResult { + let (s, a) = brace(list(symbol(","), net_lvalue))(s)?; + Ok(( + s, + NetLvalue::Lvalue(Box::new(NetLvalueLvalue { nodes: (a,) })), + )) +} + +#[packrat_parser] +#[parser] +pub(crate) fn variable_lvalue(s: Span) -> IResult { + alt(( + variable_lvalue_identifier, + variable_lvalue_lvalue, + variable_lvalue_pattern, + map(streaming_concatenation, |x| { + VariableLvalue::StreamingConcatenation(Box::new(x)) + }), + ))(s) +} + +#[parser] +pub(crate) fn variable_lvalue_identifier(s: Span) -> IResult { + let (s, a) = opt(implicit_class_handle_or_package_scope)(s)?; + let (s, b) = hierarchical_variable_identifier(s)?; + let (s, c) = select(s)?; + Ok(( + s, + VariableLvalue::Identifier(Box::new(VariableLvalueIdentifier { nodes: (a, b, c) })), + )) +} + +#[parser] +pub(crate) fn variable_lvalue_pattern(s: Span) -> IResult { + let (s, a) = opt(assignment_pattern_expression_type)(s)?; + let (s, b) = assignment_pattern_variable_lvalue(s)?; + Ok(( + s, + VariableLvalue::Pattern(Box::new(VariableLvaluePattern { nodes: (a, b) })), + )) +} + +#[parser] +pub(crate) fn variable_lvalue_lvalue(s: Span) -> IResult { + let (s, a) = brace(list(symbol(","), variable_lvalue))(s)?; + Ok(( + s, + VariableLvalue::Lvalue(Box::new(VariableLvalueLvalue { nodes: (a,) })), + )) +} + +#[parser] +pub(crate) fn nonrange_variable_lvalue(s: Span) -> IResult { + let (s, a) = opt(implicit_class_handle_or_package_scope)(s)?; + let (s, b) = hierarchical_variable_identifier(s)?; + let (s, c) = nonrange_select(s)?; + Ok((s, NonrangeVariableLvalue { nodes: (a, b, c) })) +} diff --git a/sv-parser/src/parser/expressions/expressions.rs b/sv-parser-parser/src/expressions/expressions.rs similarity index 65% rename from sv-parser/src/parser/expressions/expressions.rs rename to sv-parser-parser/src/expressions/expressions.rs index 7ef00bf..43f33fd 100644 --- a/sv-parser/src/parser/expressions/expressions.rs +++ b/sv-parser-parser/src/expressions/expressions.rs @@ -1,264 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::IResult; -use nom_packrat::packrat_parser; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum IncOrDecExpression { - Prefix(Box), - Suffix(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct IncOrDecExpressionPrefix { - pub nodes: (IncOrDecOperator, Vec, VariableLvalue), -} - -#[derive(Clone, Debug, Node)] -pub struct IncOrDecExpressionSuffix { - pub nodes: (VariableLvalue, Vec, IncOrDecOperator), -} - -#[derive(Clone, Debug, Node)] -pub struct ConditionalExpression { - pub nodes: ( - CondPredicate, - Symbol, - Vec, - Expression, - Symbol, - Expression, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ConstantExpression { - ConstantPrimary(Box), - Unary(Box), - Binary(Box), - Ternary(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantExpressionUnary { - pub nodes: (UnaryOperator, Vec, ConstantPrimary), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantExpressionBinary { - pub nodes: ( - ConstantExpression, - BinaryOperator, - Vec, - ConstantExpression, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantExpressionTernary { - pub nodes: ( - ConstantExpression, - Symbol, - Vec, - ConstantExpression, - Symbol, - ConstantExpression, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ConstantMintypmaxExpression { - Unary(Box), - Ternary(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantMintypmaxExpressionTernary { - pub nodes: ( - ConstantExpression, - Symbol, - ConstantExpression, - Symbol, - ConstantExpression, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ConstantParamExpression { - ConstantMintypmaxExpression(Box), - DataType(Box), - Dollar(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum ParamExpression { - MintypmaxExpression(Box), - DataType(Box), - Dollar(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum ConstantRangeExpression { - ConstantExpression(Box), - ConstantPartSelectRange(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum ConstantPartSelectRange { - ConstantRange(Box), - ConstantIndexedRange(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantRange { - pub nodes: (ConstantExpression, Symbol, ConstantExpression), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantIndexedRange { - pub nodes: (ConstantExpression, Symbol, ConstantExpression), -} - -#[derive(Clone, Debug, Node)] -pub enum Expression { - Primary(Box), - Unary(Box), - IncOrDecExpression(Box), - OperatorAssignment(Box), - Binary(Box), - ConditionalExpression(Box), - InsideExpression(Box), - TaggedUnionExpression(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ExpressionUnary { - pub nodes: (UnaryOperator, Vec, Primary), -} - -#[derive(Clone, Debug, Node)] -pub struct ExpressionOperatorAssignment { - pub nodes: (Paren,), -} - -#[derive(Clone, Debug, Node)] -pub struct ExpressionBinary { - pub nodes: ( - Expression, - BinaryOperator, - Vec, - Expression, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct TaggedUnionExpression { - pub nodes: (Keyword, MemberIdentifier, Option), -} - -#[derive(Clone, Debug, Node)] -pub struct InsideExpression { - pub nodes: (Expression, Keyword, Brace), -} - -#[derive(Clone, Debug, Node)] -pub enum ValueRange { - Expression(Box), - Binary(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ValueRangeBinary { - pub nodes: (Bracket<(Expression, Symbol, Expression)>,), -} - -#[derive(Clone, Debug, Node)] -pub enum MintypmaxExpression { - Expression(Box), - Ternary(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct MintypmaxExpressionTernary { - pub nodes: (Expression, Symbol, Expression, Symbol, Expression), -} - -#[derive(Clone, Debug, Node)] -pub struct ModulePathConditionalExpression { - pub nodes: ( - ModulePathExpression, - Symbol, - Vec, - ModulePathExpression, - Symbol, - ModulePathExpression, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ModulePathExpression { - ModulePathPrimary(Box), - Unary(Box), - Binary(Box), - ModulePathConditionalExpression(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ModulePathExpressionUnary { - pub nodes: ( - UnaryModulePathOperator, - Vec, - ModulePathPrimary, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ModulePathExpressionBinary { - pub nodes: ( - ModulePathExpression, - BinaryModulePathOperator, - Vec, - ModulePathExpression, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ModulePathMintypmaxExpression { - ModulePathExpression(Box), - Ternary(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ModulePathMintypmaxExpressionTernary { - pub nodes: ( - ModulePathExpression, - Symbol, - ModulePathExpression, - Symbol, - ModulePathExpression, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum PartSelectRange { - ConstantRange(Box), - IndexedRange(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct IndexedRange { - pub nodes: (Expression, Symbol, ConstantExpression), -} - -#[derive(Clone, Debug, Node)] -pub struct GenvarExpression { - pub nodes: (ConstantExpression,), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -623,7 +363,9 @@ pub(crate) fn module_path_expression_binary(s: Span) -> IResult IResult { +pub(crate) fn module_path_mintypmax_expression( + s: Span, +) -> IResult { alt(( module_path_mintypmax_expression_ternary, map(module_path_expression, |x| { @@ -674,12 +416,3 @@ pub(crate) fn genvar_expression(s: Span) -> IResult { let (s, a) = constant_expression(s)?; Ok((s, GenvarExpression { nodes: (a,) })) } - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - - #[test] - fn test() {} -} diff --git a/sv-parser-parser/src/expressions/mod.rs b/sv-parser-parser/src/expressions/mod.rs new file mode 100644 index 0000000..4764847 --- /dev/null +++ b/sv-parser-parser/src/expressions/mod.rs @@ -0,0 +1,16 @@ +pub mod concatenations; +pub mod expression_leftside_values; +pub mod expressions; +pub mod numbers; +pub mod operators; +pub mod primaries; +pub mod strings; +pub mod subroutine_calls; +pub(crate) use concatenations::*; +pub(crate) use expression_leftside_values::*; +pub(crate) use expressions::*; +pub(crate) use numbers::*; +pub(crate) use operators::*; +pub(crate) use primaries::*; +pub(crate) use strings::*; +pub(crate) use subroutine_calls::*; diff --git a/sv-parser/src/parser/expressions/numbers.rs b/sv-parser-parser/src/expressions/numbers.rs similarity index 58% rename from sv-parser/src/parser/expressions/numbers.rs rename to sv-parser-parser/src/expressions/numbers.rs index 859d30f..5dcb95b 100644 --- a/sv-parser/src/parser/expressions/numbers.rs +++ b/sv-parser-parser/src/expressions/numbers.rs @@ -1,165 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::bytes::complete::*; -use nom::character::complete::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; -use nom_packrat::packrat_parser; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum Number { - IntegralNumber(Box), - RealNumber(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum IntegralNumber { - DecimalNumber(Box), - OctalNumber(Box), - BinaryNumber(Box), - HexNumber(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum DecimalNumber { - UnsignedNumber(Box), - BaseUnsigned(Box), - BaseXNumber(Box), - BaseZNumber(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct DecimalNumberBaseUnsigned { - pub nodes: (Option, DecimalBase, UnsignedNumber), -} - -#[derive(Clone, Debug, Node)] -pub struct DecimalNumberBaseXNumber { - pub nodes: (Option, DecimalBase, XNumber), -} - -#[derive(Clone, Debug, Node)] -pub struct DecimalNumberBaseZNumber { - pub nodes: (Option, DecimalBase, ZNumber), -} - -#[derive(Clone, Debug, Node)] -pub struct BinaryNumber { - pub nodes: (Option, BinaryBase, BinaryValue), -} - -#[derive(Clone, Debug, Node)] -pub struct OctalNumber { - pub nodes: (Option, OctalBase, OctalValue), -} - -#[derive(Clone, Debug, Node)] -pub struct HexNumber { - pub nodes: (Option, HexBase, HexValue), -} - -#[derive(Clone, Debug, Node)] -pub enum Sign { - Plus(Box), - Minus(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct Size { - pub nodes: (NonZeroUnsignedNumber,), -} - -#[derive(Clone, Debug, Node)] -pub struct NonZeroUnsignedNumber { - pub nodes: (Locate, Vec), -} - -#[derive(Clone, Debug, Node)] -pub enum RealNumber { - FixedPointNumber(Box), - Floating(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct RealNumberFloating { - pub nodes: ( - UnsignedNumber, - Option<(Symbol, UnsignedNumber)>, - Exp, - Option, - UnsignedNumber, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct FixedPointNumber { - pub nodes: (UnsignedNumber, Symbol, UnsignedNumber), -} - -#[derive(Clone, Debug, Node)] -pub struct Exp { - pub nodes: (Symbol,), -} - -#[derive(Clone, Debug, Node)] -pub struct UnsignedNumber { - pub nodes: (Locate, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct BinaryValue { - pub nodes: (Locate, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct OctalValue { - pub nodes: (Locate, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct HexValue { - pub nodes: (Locate, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct DecimalBase { - pub nodes: (Locate, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct BinaryBase { - pub nodes: (Locate, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct OctalBase { - pub nodes: (Locate, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct HexBase { - pub nodes: (Locate, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct XNumber { - pub nodes: (Locate, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct ZNumber { - pub nodes: (Locate, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct UnbasedUnsizedLiteral { - pub nodes: (Symbol,), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -468,59 +307,3 @@ pub(crate) fn unbased_unsized_literal(s: Span) -> IResult IResult { + let (s, a) = alt(( + symbol("+"), + symbol("-"), + symbol("!"), + symbol("&"), + symbol("|"), + symbol("~&"), + symbol("~|"), + symbol("~^"), + symbol("^~"), + symbol("^"), + symbol("~"), + ))(s)?; + Ok((s, UnaryOperator { nodes: (a,) })) +} + +#[parser] +pub(crate) fn binary_operator(s: Span) -> IResult { + let (s, a) = alt(( + alt(( + symbol("+"), + symbol("->"), + symbol("-"), + symbol("**"), + symbol("*"), + symbol("/"), + symbol("%"), + symbol("==="), + symbol("==?"), + symbol("=="), + symbol("!=="), + symbol("!=?"), + symbol("!="), + symbol("&&"), + symbol("||"), + )), + alt(( + symbol("&"), + symbol("|"), + symbol("^~"), + symbol("^"), + symbol("~^"), + symbol(">>>"), + symbol(">>"), + symbol("<<<"), + symbol("<<"), + symbol("<->"), + symbol("<="), + symbol("<"), + symbol(">="), + symbol(">"), + )), + ))(s)?; + Ok((s, BinaryOperator { nodes: (a,) })) +} + +#[parser] +pub(crate) fn inc_or_dec_operator(s: Span) -> IResult { + let (s, a) = alt((symbol("++"), symbol("--")))(s)?; + Ok((s, IncOrDecOperator { nodes: (a,) })) +} + +#[parser] +pub(crate) fn unary_module_path_operator(s: Span) -> IResult { + let (s, a) = alt(( + symbol("!"), + symbol("&"), + symbol("|"), + symbol("~&"), + symbol("~|"), + symbol("~^"), + symbol("^~"), + symbol("^"), + symbol("~"), + ))(s)?; + Ok((s, UnaryModulePathOperator { nodes: (a,) })) +} + +#[parser] +pub(crate) fn binary_module_path_operator(s: Span) -> IResult { + let (s, a) = alt(( + symbol("=="), + symbol("!="), + symbol("&&"), + symbol("||"), + symbol("&"), + symbol("|"), + symbol("^~"), + symbol("^"), + symbol("~^"), + ))(s)?; + Ok((s, BinaryModulePathOperator { nodes: (a,) })) +} diff --git a/sv-parser/src/parser/expressions/primaries.rs b/sv-parser-parser/src/expressions/primaries.rs similarity index 61% rename from sv-parser/src/parser/expressions/primaries.rs rename to sv-parser-parser/src/expressions/primaries.rs index 3886c84..5773203 100644 --- a/sv-parser/src/parser/expressions/primaries.rs +++ b/sv-parser-parser/src/expressions/primaries.rs @@ -1,254 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::IResult; -use nom_packrat::packrat_parser; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum ConstantPrimary { - PrimaryLiteral(Box), - PsParameter(Box), - Specparam(Box), - GenvarIdentifier(Box), - FormalPort(Box), - Enum(Box), - Concatenation(Box), - MultipleConcatenation(Box), - ConstantFunctionCall(Box), - ConstantLetExpression(Box), - MintypmaxExpression(Box), - ConstantCast(Box), - ConstantAssignmentPatternExpression(Box), - TypeReference(Box), - Null(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantPrimaryPsParameter { - pub nodes: (PsParameterIdentifier, ConstantSelect), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantPrimarySpecparam { - pub nodes: ( - SpecparamIdentifier, - Option>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantPrimaryFormalPort { - pub nodes: (FormalPortIdentifier, ConstantSelect), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantPrimaryEnum { - pub nodes: (PackageScopeOrClassScope, EnumIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantPrimaryConcatenation { - pub nodes: ( - ConstantConcatenation, - Option>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantPrimaryMultipleConcatenation { - pub nodes: ( - ConstantMultipleConcatenation, - Option>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantPrimaryMintypmaxExpression { - pub nodes: (Paren,), -} - -#[derive(Clone, Debug, Node)] -pub enum ModulePathPrimary { - Number(Box), - Identifier(Box), - ModulePathConcatenation(Box), - ModulePathMultipleConcatenation(Box), - FunctionSubroutineCall(Box), - Mintypmax(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ModulePathPrimaryMintypmax { - pub nodes: (Paren,), -} - -#[derive(Clone, Debug, Node)] -pub enum Primary { - PrimaryLiteral(Box), - Hierarchical(Box), - EmptyUnpackedArrayConcatenation(Box), - Concatenation(Box), - MultipleConcatenation(Box), - FunctionSubroutineCall(Box), - LetExpression(Box), - MintypmaxExpression(Box), - Cast(Box), - AssignmentPatternExpression(Box), - StreamingConcatenation(Box), - SequenceMethodCall(Box), - This(Box), - Dollar(Box), - Null(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PrimaryHierarchical { - pub nodes: ( - Option, - HierarchicalIdentifier, - Select, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct PrimaryConcatenation { - pub nodes: (Concatenation, Option>), -} - -#[derive(Clone, Debug, Node)] -pub struct PrimaryMultipleConcatenation { - pub nodes: (MultipleConcatenation, Option>), -} - -#[derive(Clone, Debug, Node)] -pub struct PrimaryMintypmaxExpression { - pub nodes: (Paren,), -} - -#[derive(Clone, Debug, Node)] -pub enum ClassQualifierOrPackageScope { - ClassQualifier(Box), - PackageScope(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassQualifier { - pub nodes: (Option, Option), -} - -#[derive(Clone, Debug, Node)] -pub enum RangeExpression { - Expression(Box), - PartSelectRange(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum PrimaryLiteral { - Number(Box), - TimeLiteral(Box), - UnbasedUnsizedLiteral(Box), - StringLiteral(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum TimeLiteral { - Unsigned(Box), - FixedPoint(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct TimeLiteralUnsigned { - pub nodes: (UnsignedNumber, TimeUnit), -} - -#[derive(Clone, Debug, Node)] -pub struct TimeLiteralFixedPoint { - pub nodes: (FixedPointNumber, TimeUnit), -} - -#[derive(Clone, Debug, Node)] -pub enum TimeUnit { - S(Box), - MS(Box), - US(Box), - NS(Box), - PS(Box), - FS(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum ImplicitClassHandle { - This(Box), - Super(Box), - ThisSuper(Box<(Keyword, Symbol, Keyword)>), -} - -#[derive(Clone, Debug, Node)] -pub struct BitSelect { - nodes: (Vec>,), -} - -#[derive(Clone, Debug, Node)] -pub struct Select { - pub nodes: ( - Option<( - Vec<(Symbol, MemberIdentifier, BitSelect)>, - Symbol, - MemberIdentifier, - )>, - BitSelect, - Option>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct NonrangeSelect { - pub nodes: ( - Option<( - Vec<(Symbol, MemberIdentifier, BitSelect)>, - Symbol, - MemberIdentifier, - )>, - BitSelect, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantBitSelect { - nodes: (Vec>,), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantSelect { - pub nodes: ( - Option<( - Vec<(Symbol, MemberIdentifier, ConstantBitSelect)>, - Symbol, - MemberIdentifier, - )>, - ConstantBitSelect, - Option>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantCast { - pub nodes: (CastingType, Symbol, Paren), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstantLetExpression { - pub nodes: (LetExpression,), -} - -#[derive(Clone, Debug, Node)] -pub struct Cast { - pub nodes: (CastingType, Symbol, Paren), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -627,31 +377,3 @@ pub(crate) fn cast(s: Span) -> IResult { let (s, c) = paren(expression)(s)?; Ok((s, Cast { nodes: (a, b, c) })) } - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_primary() { - parser_test!(primary, "2.1ns ", Ok((_, Primary::PrimaryLiteral(_)))); - parser_test!(primary, "40 ps ", Ok((_, Primary::PrimaryLiteral(_)))); - parser_test!(primary, "'0", Ok((_, Primary::PrimaryLiteral(_)))); - parser_test!(primary, "10", Ok((_, Primary::PrimaryLiteral(_)))); - parser_test!(primary, "\"aaa\"", Ok((_, Primary::PrimaryLiteral(_)))); - parser_test!(primary, "this ", Ok((_, Primary::This(_)))); - parser_test!(primary, "$", Ok((_, Primary::Dollar(_)))); - parser_test!(primary, "null ", Ok((_, Primary::Null(_)))); - } - - #[test] - fn test_cast() { - parser_test!(cast, "int'(2.0 * 3.0)", Ok((_, _))); - parser_test!(cast, "shortint'({8'hFA,8'hCE}) ", Ok((_, _))); - parser_test!(cast, "signed'(x)", Ok((_, _))); - parser_test!(cast, "const'(x)", Ok((_, _))); - parser_test!(cast, "type_t'(x)", Ok((_, _))); - } -} diff --git a/sv-parser/src/parser/expressions/strings.rs b/sv-parser-parser/src/expressions/strings.rs similarity index 61% rename from sv-parser/src/parser/expressions/strings.rs rename to sv-parser-parser/src/expressions/strings.rs index 0b1bc9a..9c3437e 100644 --- a/sv-parser/src/parser/expressions/strings.rs +++ b/sv-parser-parser/src/expressions/strings.rs @@ -1,17 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::bytes::complete::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct StringLiteral { - pub nodes: (Locate, Vec), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -54,17 +41,3 @@ pub(crate) fn string_literal_impl(s: Span) -> IResult { Ok((s, a.into())) } - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_string_literal() { - parser_test!(string_literal, "\"aaa aaaa\"", Ok((_, _))); - parser_test!(string_literal, r#""aaa\" aaaa""#, Ok((_, _))); - parser_test!(string_literal, r#""aaa\"""#, Ok((_, _))); - } -} diff --git a/sv-parser/src/parser/expressions/subroutine_calls.rs b/sv-parser-parser/src/expressions/subroutine_calls.rs similarity index 62% rename from sv-parser/src/parser/expressions/subroutine_calls.rs rename to sv-parser-parser/src/expressions/subroutine_calls.rs index c4800c1..bb1b350 100644 --- a/sv-parser/src/parser/expressions/subroutine_calls.rs +++ b/sv-parser-parser/src/expressions/subroutine_calls.rs @@ -1,171 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; -use nom_packrat::packrat_parser; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct ConstantFunctionCall { - pub nodes: (FunctionSubroutineCall,), -} - -#[derive(Clone, Debug, Node)] -pub struct TfCall { - pub nodes: ( - PsOrHierarchicalTfIdentifier, - Vec, - Option>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum SystemTfCall { - ArgOptionl(Box), - ArgDataType(Box), - ArgExpression(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct SystemTfCallArgOptional { - pub nodes: (SystemTfIdentifier, Option>), -} - -#[derive(Clone, Debug, Node)] -pub struct SystemTfCallArgDataType { - pub nodes: ( - SystemTfIdentifier, - Paren<(DataType, Option<(Symbol, Expression)>)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct SystemTfCallArgExpression { - pub nodes: ( - SystemTfIdentifier, - Paren<( - List>, - Option<(Symbol, Option)>, - )>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum SubroutineCall { - TfCall(Box), - SystemTfCall(Box), - MethodCall(Box), - Randomize(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct SubroutineCallRandomize { - pub nodes: (Option<(Keyword, Symbol)>, RandomizeCall), -} - -#[derive(Clone, Debug, Node)] -pub struct FunctionSubroutineCall { - pub nodes: (SubroutineCall,), -} - -#[derive(Clone, Debug, Node)] -pub enum ListOfArguments { - Ordered(Box), - Named(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfArgumentsOrdered { - pub nodes: ( - List>, - Vec<(Symbol, Symbol, Identifier, Paren>)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfArgumentsNamed { - pub nodes: ( - Symbol, - Identifier, - Paren>, - Vec<(Symbol, Symbol, Identifier, Paren>)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct MethodCall { - pub nodes: (MethodCallRoot, Symbol, MethodCallBody), -} - -#[derive(Clone, Debug, Node)] -pub enum MethodCallBody { - User(Box), - BuiltInMethodCall(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct MethodCallBodyUser { - pub nodes: ( - MethodIdentifier, - Vec, - Option>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum BuiltInMethodCall { - ArrayManipulationCall(Box), - RandomizeCall(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ArrayManipulationCall { - pub nodes: ( - ArrayMethodName, - Vec, - Option>, - Option<(Keyword, Paren)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct RandomizeCall { - pub nodes: ( - Keyword, - Vec, - Option>>, - Option<( - Keyword, - Option>>, - ConstraintBlock, - )>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum VariableIdentifierListOrNull { - VariableIdentifierList(Box), - Null(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum MethodCallRoot { - Primary(Box), - ImplicitClassHandle(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum ArrayMethodName { - MethodIdentifier(Box), - Unique(Box), - And(Box), - Or(Box), - Xor(Box), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -367,7 +200,9 @@ pub(crate) fn randomize_call(s: Span) -> IResult { } #[parser] -pub(crate) fn variable_identifier_list_or_null(s: Span) -> IResult { +pub(crate) fn variable_identifier_list_or_null( + s: Span, +) -> IResult { alt(( map(variable_identifier_list, |x| { VariableIdentifierListOrNull::VariableIdentifierList(Box::new(x)) @@ -400,5 +235,3 @@ pub(crate) fn array_method_name(s: Span) -> IResult { }), ))(s) } - -// ----------------------------------------------------------------------------- diff --git a/sv-parser-parser/src/general/attributes.rs b/sv-parser-parser/src/general/attributes.rs new file mode 100644 index 0000000..138a224 --- /dev/null +++ b/sv-parser-parser/src/general/attributes.rs @@ -0,0 +1,18 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[parser] +pub(crate) fn attribute_instance(s: Span) -> IResult { + let (s, a) = symbol("(*")(s)?; + let (s, b) = list(symbol(","), attr_spec)(s)?; + let (s, c) = symbol("*)")(s)?; + Ok((s, AttributeInstance { nodes: (a, b, c) })) +} + +#[parser] +pub(crate) fn attr_spec(s: Span) -> IResult { + let (s, a) = identifier(s)?; + let (s, b) = opt(pair(symbol("="), constant_expression))(s)?; + Ok((s, AttrSpec { nodes: (a, b) })) +} diff --git a/sv-parser/src/parser/general/comments.rs b/sv-parser-parser/src/general/comments.rs similarity index 55% rename from sv-parser/src/parser/general/comments.rs rename to sv-parser-parser/src/general/comments.rs index db40117..cf93c3b 100644 --- a/sv-parser/src/parser/general/comments.rs +++ b/sv-parser-parser/src/general/comments.rs @@ -1,15 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::bytes::complete::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct Comment { - nodes: (Locate,), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -35,17 +24,3 @@ pub(crate) fn block_comment(s: Span) -> IResult { let a = concat(a, c).unwrap(); Ok((s, Comment { nodes: (a.into(),) })) } - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - use super::*; - use nom::combinator::*; - - #[test] - fn test_comment() { - parser_test!(comment, "// comment", Ok((_, _))); - parser_test!(comment, "/* comment\n\n */", Ok((_, _))); - } -} diff --git a/sv-parser/src/parser/general/identifiers.rs b/sv-parser-parser/src/general/identifiers.rs similarity index 64% rename from sv-parser/src/parser/general/identifiers.rs rename to sv-parser-parser/src/general/identifiers.rs index 0118b4b..5950224 100644 --- a/sv-parser/src/parser/general/identifiers.rs +++ b/sv-parser-parser/src/general/identifiers.rs @@ -1,13 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::bytes::complete::*; -use nom::combinator::*; -use nom::error::*; -use nom::multi::*; -use nom::sequence::*; -use nom::{Err, IResult}; -use nom_packrat::packrat_parser; +use crate::*; // ----------------------------------------------------------------------------- @@ -16,531 +7,6 @@ pub(crate) const AZ09_: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV pub(crate) const AZ09_DOLLAR: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$"; -#[derive(Clone, Debug, Node)] -pub struct ArrayIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct BlockIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct BinIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct CIdentifier { - pub nodes: (Locate, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct CellIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct CheckerIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassVariableIdentifier { - pub nodes: (VariableIdentifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct ClockingIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct ConfigIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstraintIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct CovergroupIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct CovergroupVariableIdentifier { - pub nodes: (VariableIdentifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct CoverPointIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct CrossIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct DynamicArrayVariableIdentifier { - pub nodes: (VariableIdentifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct EnumIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct EscapedIdentifier { - pub nodes: (Locate, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct FormalIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct FormalPortIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct FunctionIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct GenerateBlockIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct GenvarIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct HierarchicalArrayIdentifier { - pub nodes: (HierarchicalIdentifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct HierarchicalBlockIdentifier { - pub nodes: (HierarchicalIdentifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct HierarchicalEventIdentifier { - pub nodes: (HierarchicalIdentifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct HierarchicalIdentifier { - pub nodes: ( - Option, - Vec<(Identifier, ConstantBitSelect, Symbol)>, - Identifier, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct Root { - pub nodes: (Keyword, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct HierarchicalNetIdentifier { - pub nodes: (HierarchicalIdentifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct HierarchicalParameterIdentifier { - pub nodes: (HierarchicalIdentifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct HierarchicalPropertyIdentifier { - pub nodes: (HierarchicalIdentifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct HierarchicalSequenceIdentifier { - pub nodes: (HierarchicalIdentifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct HierarchicalTaskIdentifier { - pub nodes: (HierarchicalIdentifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct HierarchicalTfIdentifier { - pub nodes: (HierarchicalIdentifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct HierarchicalVariableIdentifier { - pub nodes: (HierarchicalIdentifier,), -} - -#[derive(Clone, Debug, Node)] -pub enum Identifier { - SimpleIdentifier(Box), - EscapedIdentifier(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct IndexVariableIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfaceIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfaceInstanceIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct InoutPortIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct InputPortIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct InstanceIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct LibraryIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct MemberIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct MethodIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct ModportIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct ModuleIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct NetIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct NetTypeIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct OutputPortIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct PackageIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub enum PackageScope { - Package(Box), - Unit(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PackageScopePackage { - pub nodes: (PackageIdentifier, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct Unit { - pub nodes: (Keyword, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct ParameterIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct PortIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct ProductionIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct ProgramIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct PropertyIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct PsClassIdentifier { - pub nodes: (Option, ClassIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub struct PsCovergroupIdentifier { - pub nodes: (Option, CovergroupIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub struct PsCheckerIdentifier { - pub nodes: (Option, CheckerIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub struct PsIdentifier { - pub nodes: (Option, Identifier), -} - -#[derive(Clone, Debug, Node)] -pub struct PsOrHierarchicalArrayIdentifier { - pub nodes: ( - Option, - HierarchicalArrayIdentifier, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum PsOrHierarchicalNetIdentifier { - PackageScope(Box), - HierarchicalNetIdentifier(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PsOrHierarchicalNetIdentifierPackageScope { - pub nodes: (Option, NetIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub struct PsOrHierarchicalNetIdentifierHierarchical { - pub nodes: (HierarchicalNetIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub enum PsOrHierarchicalPropertyIdentifier { - PackageScope(Box), - HierarchicalPropertyIdentifier(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PsOrHierarchicalPropertyIdentifierPackageScope { - pub nodes: (Option, PropertyIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub struct PsOrHierarchicalPropertyIdentifierHierarchical { - pub nodes: (HierarchicalPropertyIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub enum PsOrHierarchicalSequenceIdentifier { - PackageScope(Box), - HierarchicalSequenceIdentifier(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PsOrHierarchicalSequenceIdentifierPackageScope { - pub nodes: (Option, SequenceIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub struct PsOrHierarchicalSequenceIdentifierHierarchical { - pub nodes: (HierarchicalSequenceIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub enum PsOrHierarchicalTfIdentifier { - PackageScope(Box), - HierarchicalTfIdentifier(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PsOrHierarchicalTfIdentifierPackageScope { - pub nodes: (Option, TfIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub struct PsOrHierarchicalTfIdentifierHierarchical { - pub nodes: (HierarchicalTfIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub enum PsParameterIdentifier { - Scope(Box), - Generate(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PsParameterIdentifierScope { - pub nodes: (Option, ParameterIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub struct PsParameterIdentifierGenerate { - pub nodes: ( - Vec<( - GenerateBlockIdentifier, - Option>, - Symbol, - )>, - ParameterIdentifier, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct PsTypeIdentifier { - pub nodes: (Option, TypeIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub enum LocalOrPackageScopeOrClassScope { - Local(Box), - PackageScope(Box), - ClassScope(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct Local { - pub nodes: (Keyword, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct SequenceIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct SignalIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct SimpleIdentifier { - pub nodes: (Locate, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct SpecparamIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct SystemTfIdentifier { - pub nodes: (Locate, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct TaskIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct TfIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct TerminalIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct TopmoduleIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct TypeIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct UdpIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct VariableIdentifier { - pub nodes: (Identifier,), -} - -#[derive(Clone, Debug, Node)] -pub enum ImplicitClassHandleOrClassScopeOrPackageScope { - ImplicitClassHandle(Box<(ImplicitClassHandle, Symbol)>), - ClassScope(Box), - PackageScope(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum ImplicitClassHandleOrPackageScope { - ImplicitClassHandle(Box<(ImplicitClassHandle, Symbol)>), - PackageScope(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum ImplicitClassHandleOrClassScope { - ImplicitClassHandle(Box<(ImplicitClassHandle, Symbol)>), - ClassScope(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum PackageScopeOrClassScope { - PackageScope(Box), - ClassScope(Box), -} - -// ----------------------------------------------------------------------------- - #[allow(dead_code)] #[parser] pub(crate) fn array_identifier(s: Span) -> IResult { @@ -1318,44 +784,3 @@ pub(crate) fn local(s: Span) -> IResult { let (s, b) = symbol("::")(s)?; Ok((s, Local { nodes: (a, b) })) } - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_identifier() { - parser_test!( - identifier, - "shiftreg_a", - Ok((_, Identifier::SimpleIdentifier(_))) - ); - parser_test!( - identifier, - "_bus3", - Ok((_, Identifier::SimpleIdentifier(_))) - ); - parser_test!( - identifier, - "n$657", - Ok((_, Identifier::SimpleIdentifier(_))) - ); - parser_test!( - identifier, - "\\busa+index", - Ok((_, Identifier::EscapedIdentifier(_))) - ); - parser_test!( - identifier, - "\\-clock", - Ok((_, Identifier::EscapedIdentifier(_))) - ); - } - - #[test] - fn test_system_tf_identifier() { - parser_test!(system_tf_identifier, "$display", Ok((_, _))); - } -} diff --git a/sv-parser-parser/src/general/mod.rs b/sv-parser-parser/src/general/mod.rs new file mode 100644 index 0000000..27f9c15 --- /dev/null +++ b/sv-parser-parser/src/general/mod.rs @@ -0,0 +1,6 @@ +pub mod attributes; +pub mod comments; +pub mod identifiers; +pub(crate) use attributes::*; +pub(crate) use comments::*; +pub(crate) use identifiers::*; diff --git a/sv-parser/src/parser/instantiations/checker_instantiation.rs b/sv-parser-parser/src/instantiations/checker_instantiation.rs similarity index 58% rename from sv-parser/src/parser/instantiations/checker_instantiation.rs rename to sv-parser-parser/src/instantiations/checker_instantiation.rs index b21324e..f397d66 100644 --- a/sv-parser/src/parser/instantiations/checker_instantiation.rs +++ b/sv-parser-parser/src/instantiations/checker_instantiation.rs @@ -1,63 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct CheckerInstantiation { - pub nodes: ( - PsCheckerIdentifier, - NameOfInstance, - Paren>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ListOfCheckerPortConnections { - Ordered(Box), - Named(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfCheckerPortConnectionsOrdered { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfCheckerPortConnectionsNamed { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct OrderedCheckerPortConnection { - pub nodes: (Vec, Option), -} - -#[derive(Clone, Debug, Node)] -pub enum NamedCheckerPortConnection { - Identifier(Box), - Asterisk(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct NamedCheckerPortConnectionIdentifier { - pub nodes: ( - Vec, - Symbol, - FormalPortIdentifier, - Option>>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct NamedCheckerPortConnectionAsterisk { - pub nodes: (Vec, Symbol), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -76,7 +17,9 @@ pub(crate) fn checker_instantiation(s: Span) -> IResult IResult { +pub(crate) fn list_of_checker_port_connections( + s: Span, +) -> IResult { alt(( list_of_checker_port_connections_ordered, list_of_checker_port_connections_named, @@ -110,7 +53,9 @@ pub(crate) fn list_of_checker_port_connections_named( } #[parser(MaybeRecursive)] -pub(crate) fn ordered_checker_port_connection(s: Span) -> IResult { +pub(crate) fn ordered_checker_port_connection( + s: Span, +) -> IResult { let (s, x) = many0(attribute_instance)(s)?; let (s, y) = opt(property_actual_arg)(s)?; Ok((s, OrderedCheckerPortConnection { nodes: (x, y) })) @@ -153,5 +98,3 @@ pub(crate) fn named_checker_port_connection_asterisk( })), )) } - -// ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/instantiations/generated_instantiation.rs b/sv-parser-parser/src/instantiations/generated_instantiation.rs similarity index 62% rename from sv-parser/src/parser/instantiations/generated_instantiation.rs rename to sv-parser-parser/src/instantiations/generated_instantiation.rs index 21906d3..530bb26 100644 --- a/sv-parser/src/parser/instantiations/generated_instantiation.rs +++ b/sv-parser-parser/src/instantiations/generated_instantiation.rs @@ -1,131 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct GenerateRegion { - pub nodes: (Keyword, Vec, Keyword), -} - -#[derive(Clone, Debug, Node)] -pub struct LoopGenerateConstruct { - pub nodes: ( - Keyword, - Paren<( - GenvarInitialization, - Symbol, - GenvarExpression, - Symbol, - GenvarIteration, - )>, - GenerateBlock, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct GenvarInitialization { - pub nodes: (Option, GenvarIdentifier, Symbol, ConstantExpression), -} - -#[derive(Clone, Debug, Node)] -pub struct Genvar { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub enum GenvarIteration { - Assignment(Box), - Prefix(Box), - Suffix(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct GenvarIterationAssignment { - pub nodes: (GenvarIdentifier, AssignmentOperator, GenvarExpression), -} - -#[derive(Clone, Debug, Node)] -pub struct GenvarIterationPrefix { - pub nodes: (IncOrDecOperator, GenvarIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub struct GenvarIterationSuffix { - pub nodes: (GenvarIdentifier, IncOrDecOperator), -} - -#[derive(Clone, Debug, Node)] -pub enum ConditionalGenerateConstruct { - If(Box), - Case(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct IfGenerateConstruct { - pub nodes: ( - Keyword, - Paren, - GenerateBlock, - Option<(Keyword, GenerateBlock)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct CaseGenerateConstruct { - pub nodes: ( - Keyword, - Paren, - Vec, - Keyword, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum CaseGenerateItem { - Nondefault(Box), - Default(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CaseGenerateItemNondefault { - pub nodes: (List, Symbol, GenerateBlock), -} - -#[derive(Clone, Debug, Node)] -pub struct CaseGenerateItemDefault { - pub nodes: (Keyword, Option, GenerateBlock), -} - -#[derive(Clone, Debug, Node)] -pub enum GenerateBlock { - GenerateItem(Box), - Multiple(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct GenerateBlockMultiple { - pub nodes: ( - Option<(GenerateBlockIdentifier, Symbol)>, - Keyword, - Option<(Symbol, GenerateBlockIdentifier)>, - Vec, - Keyword, - Option<(Symbol, GenerateBlockIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum GenerateItem { - ModuleOrGenerateItem(Box), - InterfaceOrGenerateItem(Box), - CheckerOrGenerateItem(Box), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -206,7 +79,9 @@ pub(crate) fn genvar_iteration_suffix(s: Span) -> IResult } #[parser] -pub(crate) fn conditional_generate_construct(s: Span) -> IResult { +pub(crate) fn conditional_generate_construct( + s: Span, +) -> IResult { alt(( map(if_generate_construct, |x| { ConditionalGenerateConstruct::If(Box::new(x)) @@ -310,5 +185,3 @@ pub(crate) fn generate_item(s: Span) -> IResult { }), ))(s) } - -// ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/instantiations/interface_instantiation.rs b/sv-parser-parser/src/instantiations/interface_instantiation.rs similarity index 50% rename from sv-parser/src/parser/instantiations/interface_instantiation.rs rename to sv-parser-parser/src/instantiations/interface_instantiation.rs index 24cfb46..c7f2688 100644 --- a/sv-parser/src/parser/instantiations/interface_instantiation.rs +++ b/sv-parser-parser/src/instantiations/interface_instantiation.rs @@ -1,19 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::combinator::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct InterfaceInstantiation { - pub nodes: ( - InterfaceIdentifier, - Option, - List, - Symbol, - ), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -30,5 +15,3 @@ pub(crate) fn interface_instantiation(s: Span) -> IResult, - List, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ParameterValueAssignment { - pub nodes: (Symbol, Paren>), -} - -#[derive(Clone, Debug, Node)] -pub enum ListOfParameterAssignments { - Ordered(Box), - Named(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfParameterAssignmentsOrdered { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfParameterAssignmentsNamed { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct OrderedParameterAssignment { - pub nodes: (ParamExpression,), -} - -#[derive(Clone, Debug, Node)] -pub struct NamedParameterAssignment { - pub nodes: (Symbol, ParameterIdentifier, Paren>), -} - -#[derive(Clone, Debug, Node)] -pub struct HierarchicalInstance { - pub nodes: (NameOfInstance, Paren>), -} - -#[derive(Clone, Debug, Node)] -pub struct NameOfInstance { - pub nodes: (InstanceIdentifier, Vec), -} - -#[derive(Clone, Debug, Node)] -pub enum ListOfPortConnections { - Ordered(Box), - Named(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfPortConnectionsOrdered { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfPortConnectionsNamed { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct OrderedPortConnection { - pub nodes: (Vec, Option), -} - -#[derive(Clone, Debug, Node)] -pub enum NamedPortConnection { - Identifier(Box), - Asterisk(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct NamedPortConnectionIdentifier { - pub nodes: ( - Vec, - Symbol, - PortIdentifier, - Option>>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct NamedPortConnectionAsterisk { - pub nodes: (Vec, Symbol), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -132,7 +32,9 @@ pub(crate) fn list_of_parameter_assignments(s: Span) -> IResult IResult { +pub(crate) fn list_of_parameter_assignments_ordered( + s: Span, +) -> IResult { let (s, a) = list(symbol(","), ordered_parameter_assignment)(s)?; Ok(( s, @@ -143,7 +45,9 @@ pub(crate) fn list_of_parameter_assignments_ordered(s: Span) -> IResult IResult { +pub(crate) fn list_of_parameter_assignments_named( + s: Span, +) -> IResult { let (s, a) = list(symbol(","), named_parameter_assignment)(s)?; Ok(( s, @@ -245,5 +149,3 @@ pub(crate) fn named_port_connection_asterisk(s: Span) -> IResult, - List, - Symbol, - ), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -30,5 +15,3 @@ pub(crate) fn program_instantiation(s: Span) -> IResult Result { + let s = Span::new_extra(s, Extra::default()); + match source_text(s) { + Ok((_, x)) => Ok(x), + Err(_) => Err(()), + } } -pub(crate) type Span<'a> = nom_locate::LocatedSpanEx<&'a str, Extra>; +pub fn parse_lib(s: &str) -> Result { + let s = Span::new_extra(s, Extra::default()); + match library_text(s) { + Ok((_, x)) => Ok(x), + Err(_) => Err(()), + } +} // ----------------------------------------------------------------------------- mod thread_context { - use crate::parser::RECURSIVE_FLAG_WORDS; use std::cell::RefCell; use std::collections::HashMap; + use sv_parser_syntaxtree::RECURSIVE_FLAG_WORDS; pub struct ParserIndex { index: HashMap<&'static str, usize>, diff --git a/sv-parser-parser/src/primitive_instances/mod.rs b/sv-parser-parser/src/primitive_instances/mod.rs new file mode 100644 index 0000000..8782986 --- /dev/null +++ b/sv-parser-parser/src/primitive_instances/mod.rs @@ -0,0 +1,8 @@ +pub mod primitive_gate_and_switch_types; +pub mod primitive_instantiation_and_instances; +pub mod primitive_strengths; +pub mod primitive_terminals; +pub(crate) use primitive_gate_and_switch_types::*; +pub(crate) use primitive_instantiation_and_instances::*; +pub(crate) use primitive_strengths::*; +pub(crate) use primitive_terminals::*; diff --git a/sv-parser-parser/src/primitive_instances/primitive_gate_and_switch_types.rs b/sv-parser-parser/src/primitive_instances/primitive_gate_and_switch_types.rs new file mode 100644 index 0000000..a223b1a --- /dev/null +++ b/sv-parser-parser/src/primitive_instances/primitive_gate_and_switch_types.rs @@ -0,0 +1,67 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[parser] +pub(crate) fn cmos_switchtype(s: Span) -> IResult { + let (s, a) = alt((keyword("cmos"), keyword("rcmos")))(s)?; + Ok((s, CmosSwitchtype { nodes: (a,) })) +} + +#[parser] +pub(crate) fn enable_gatetype(s: Span) -> IResult { + let (s, a) = alt(( + keyword("bufif0"), + keyword("bufif1"), + keyword("notif0"), + keyword("notif1"), + ))(s)?; + Ok((s, EnableGatetype { nodes: (a,) })) +} + +#[parser] +pub(crate) fn mos_switchtype(s: Span) -> IResult { + let (s, a) = alt(( + keyword("nmos"), + keyword("pmos"), + keyword("rnmos"), + keyword("rpmos"), + ))(s)?; + Ok((s, MosSwitchtype { nodes: (a,) })) +} + +#[parser] +pub(crate) fn n_input_gatetype(s: Span) -> IResult { + let (s, a) = alt(( + keyword("and"), + keyword("nand"), + keyword("or"), + keyword("nor"), + keyword("xor"), + keyword("xnor"), + ))(s)?; + Ok((s, NInputGatetype { nodes: (a,) })) +} + +#[parser] +pub(crate) fn n_output_gatetype(s: Span) -> IResult { + let (s, a) = alt((keyword("buf"), keyword("not")))(s)?; + Ok((s, NOutputGatetype { nodes: (a,) })) +} + +#[parser] +pub(crate) fn pass_en_switchtype(s: Span) -> IResult { + let (s, a) = alt(( + keyword("tranif0"), + keyword("tranif1"), + keyword("rtranif0"), + keyword("rtranif1"), + ))(s)?; + Ok((s, PassEnSwitchtype { nodes: (a,) })) +} + +#[parser] +pub(crate) fn pass_switchtype(s: Span) -> IResult { + let (s, a) = alt((keyword("tran"), keyword("rtran")))(s)?; + Ok((s, PassSwitchtype { nodes: (a,) })) +} diff --git a/sv-parser/src/parser/primitive_instances/primitive_instantiation_and_instances.rs b/sv-parser-parser/src/primitive_instances/primitive_instantiation_and_instances.rs similarity index 62% rename from sv-parser/src/parser/primitive_instances/primitive_instantiation_and_instances.rs rename to sv-parser-parser/src/primitive_instances/primitive_instantiation_and_instances.rs index f6cc30e..1a3f9c6 100644 --- a/sv-parser/src/parser/primitive_instances/primitive_instantiation_and_instances.rs +++ b/sv-parser-parser/src/primitive_instances/primitive_instantiation_and_instances.rs @@ -1,193 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum GateInstantiation { - Cmos(Box), - Enable(Box), - Mos(Box), - NInput(Box), - NOutput(Box), - PassEn(Box), - Pass(Box), - Pulldown(Box), - Pullup(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct GateInstantiationCmos { - pub nodes: ( - CmosSwitchtype, - Option, - List, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct GateInstantiationEnable { - pub nodes: ( - EnableGatetype, - Option, - Option, - List, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct GateInstantiationMos { - pub nodes: ( - MosSwitchtype, - Option, - List, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct GateInstantiationNInput { - pub nodes: ( - NInputGatetype, - Option, - Option, - List, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct GateInstantiationNOutput { - pub nodes: ( - NOutputGatetype, - Option, - Option, - List, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct GateInstantiationPassEn { - pub nodes: ( - PassEnSwitchtype, - Option, - List, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct GateInstantiationPass { - pub nodes: (PassSwitchtype, List, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct GateInstantiationPulldown { - pub nodes: ( - Keyword, - Option, - List, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct GateInstantiationPullup { - pub nodes: ( - Keyword, - Option, - List, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct CmosSwitchInstance { - pub nodes: ( - Option, - Paren<( - OutputTerminal, - Symbol, - InputTerminal, - Symbol, - NcontrolTerminal, - Symbol, - PcontrolTerminal, - )>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct EnableGateInstance { - pub nodes: ( - Option, - Paren<( - OutputTerminal, - Symbol, - InputTerminal, - Symbol, - EnableTerminal, - )>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct MosSwitchInstance { - pub nodes: ( - Option, - Paren<( - OutputTerminal, - Symbol, - InputTerminal, - Symbol, - EnableTerminal, - )>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct NInputGateInstance { - pub nodes: ( - Option, - Paren<(OutputTerminal, Symbol, List)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct NOutputGateInstance { - pub nodes: ( - Option, - Paren<(List, Symbol, InputTerminal)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct PassSwitchInstance { - pub nodes: ( - Option, - Paren<(InoutTerminal, Symbol, InoutTerminal)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct PassEnableSwitchInstance { - pub nodes: ( - Option, - Paren<(InoutTerminal, Symbol, InoutTerminal, Symbol, EnableTerminal)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct PullGateInstance { - pub nodes: (Option, Paren), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/primitive_instances/primitive_strengths.rs b/sv-parser-parser/src/primitive_instances/primitive_strengths.rs similarity index 51% rename from sv-parser/src/parser/primitive_instances/primitive_strengths.rs rename to sv-parser-parser/src/primitive_instances/primitive_strengths.rs index 161d0c2..833f853 100644 --- a/sv-parser/src/parser/primitive_instances/primitive_strengths.rs +++ b/sv-parser-parser/src/primitive_instances/primitive_strengths.rs @@ -1,53 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum PulldownStrength { - Strength01(Box), - Strength10(Box), - Strength0(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PulldownStrength01 { - pub nodes: (Paren<(Strength0, Symbol, Strength1)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct PulldownStrength10 { - pub nodes: (Paren<(Strength1, Symbol, Strength0)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct PulldownStrength0 { - pub nodes: (Paren,), -} - -#[derive(Clone, Debug, Node)] -pub enum PullupStrength { - Strength01(Box), - Strength10(Box), - Strength1(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PullupStrength01 { - pub nodes: (Paren<(Strength0, Symbol, Strength1)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct PullupStrength10 { - pub nodes: (Paren<(Strength1, Symbol, Strength0)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct PullupStrength1 { - pub nodes: (Paren,), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -114,25 +65,3 @@ pub(crate) fn pullup_strength1(s: Span) -> IResult { PullupStrength::Strength1(Box::new(PullupStrength1 { nodes: (a,) })), )) } - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - use super::*; - use nom::combinator::*; - - #[test] - fn test_pulldown_strength() { - parser_test!(pulldown_strength, "(supply0, strong1)", Ok((_, _))); - parser_test!(pulldown_strength, "(pull1, weak0)", Ok((_, _))); - parser_test!(pulldown_strength, "(pull0)", Ok((_, _))); - } - - #[test] - fn test_pullup_strength() { - parser_test!(pullup_strength, "(supply0, strong1)", Ok((_, _))); - parser_test!(pullup_strength, "(pull1, weak0)", Ok((_, _))); - parser_test!(pullup_strength, "(supply1)", Ok((_, _))); - } -} diff --git a/sv-parser/src/parser/primitive_instances/primitive_terminals.rs b/sv-parser-parser/src/primitive_instances/primitive_terminals.rs similarity index 58% rename from sv-parser/src/parser/primitive_instances/primitive_terminals.rs rename to sv-parser-parser/src/primitive_instances/primitive_terminals.rs index e9f7baf..3c1a396 100644 --- a/sv-parser/src/parser/primitive_instances/primitive_terminals.rs +++ b/sv-parser-parser/src/primitive_instances/primitive_terminals.rs @@ -1,38 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct EnableTerminal { - pub nodes: (Expression,), -} - -#[derive(Clone, Debug, Node)] -pub struct InoutTerminal { - pub nodes: (NetLvalue,), -} - -#[derive(Clone, Debug, Node)] -pub struct InputTerminal { - pub nodes: (Expression,), -} - -#[derive(Clone, Debug, Node)] -pub struct NcontrolTerminal { - pub nodes: (Expression,), -} - -#[derive(Clone, Debug, Node)] -pub struct OutputTerminal { - pub nodes: (NetLvalue,), -} - -#[derive(Clone, Debug, Node)] -pub struct PcontrolTerminal { - pub nodes: (Expression,), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -71,5 +37,3 @@ pub(crate) fn pcontrol_terminal(s: Span) -> IResult { let (s, a) = expression(s)?; Ok((s, PcontrolTerminal { nodes: (a,) })) } - -// ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/source_text/checker_items.rs b/sv-parser-parser/src/source_text/checker_items.rs similarity index 68% rename from sv-parser/src/parser/source_text/checker_items.rs rename to sv-parser-parser/src/source_text/checker_items.rs index cce9dc9..8d2af48 100644 --- a/sv-parser/src/parser/source_text/checker_items.rs +++ b/sv-parser-parser/src/source_text/checker_items.rs @@ -1,88 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct CheckerPortList { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct CheckerPortItem { - pub nodes: ( - Vec, - Option, - PropertyFormalType, - FormalPortIdentifier, - Vec, - Option<(Symbol, PropertyActualArg)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum CheckerPortDirection { - Input(Box), - Output(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum CheckerOrGenerateItem { - CheckerOrGenerateItemDeclaration(Box), - InitialConstruct(Box), - AlwaysConstruct(Box), - FinalConstruct(Box), - AssertionItem(Box), - ContinuousAssign(Box), - CheckerGenerateItem(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum CheckerOrGenerateItemDeclaration { - Data(Box), - FunctionDeclaration(Box), - CheckerDeclaration(Box), - AssertionItemDeclaration(Box), - CovergroupDeclaration(Box), - GenvarDeclaration(Box), - ClockingDeclaration(Box), - Clocking(Box), - Disable(Box), - Empty(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CheckerOrGenerateItemDeclarationData { - pub nodes: (Option, DataDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct Rand { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct CheckerOrGenerateItemDeclarationClocking { - pub nodes: (Keyword, Keyword, ClockingIdentifier, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct CheckerOrGenerateItemDeclarationDisable { - pub nodes: (Keyword, Keyword, Keyword, ExpressionOrDist, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub enum CheckerGenerateItem { - LoopGenerateConstruct(Box), - ConditionalGenerateConstruct(Box), - GenerateRegion(Box), - ElaborationSystemTask(Box), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/source_text/class_items.rs b/sv-parser-parser/src/source_text/class_items.rs similarity index 65% rename from sv-parser/src/parser/source_text/class_items.rs rename to sv-parser-parser/src/source_text/class_items.rs index bbf024b..42c6f6f 100644 --- a/sv-parser/src/parser/source_text/class_items.rs +++ b/sv-parser-parser/src/source_text/class_items.rs @@ -1,188 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum ClassItem { - Property(Box), - Method(Box), - Constraint(Box), - Declaration(Box), - Covergroup(Box), - LocalParameterDeclaration(Box<(LocalParameterDeclaration, Symbol)>), - ParameterDeclaration(Box<(ParameterDeclaration, Symbol)>), - Empty(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassItemProperty { - pub nodes: (Vec, ClassProperty), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassItemMethod { - pub nodes: (Vec, ClassMethod), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassItemConstraint { - pub nodes: (Vec, ClassConstraint), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassItemDeclaration { - pub nodes: (Vec, ClassDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassItemCovergroup { - pub nodes: (Vec, CovergroupDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub enum ClassProperty { - NonConst(Box), - Const(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassPropertyNonConst { - pub nodes: (Vec, DataDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassPropertyConst { - pub nodes: ( - Keyword, - Vec, - DataType, - ConstIdentifier, - Option<(Symbol, ConstantExpression)>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ClassMethod { - Task(Box), - Function(Box), - PureVirtual(Box), - ExternMethod(Box), - Constructor(Box), - ExternConstructor(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassMethodTask { - pub nodes: (Vec, TaskDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassMethodFunction { - pub nodes: (Vec, FunctionDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassMethodPureVirtual { - pub nodes: ( - Keyword, - Keyword, - Vec, - MethodPrototype, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassMethodExternMethod { - pub nodes: (Keyword, Vec, MethodPrototype, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassMethodConstructor { - pub nodes: (Vec, ClassConstructorDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassMethodExternConstructor { - pub nodes: (Keyword, Vec, ClassConstructorPrototype), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassConstructorPrototype { - pub nodes: (Keyword, Keyword, Option>>, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub enum ClassConstraint { - ConstraintPrototype(Box), - ConstraintDeclaration(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum ClassItemQualifier { - Static(Box), - Protected(Box), - Local(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum PropertyQualifier { - RandomQualifier(Box), - ClassItemQualifier(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum RandomQualifier { - Rand(Box), - Randc(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum MethodQualifier { - Virtual(Box), - PureVirtual(Box<(Keyword, Keyword)>), - ClassItemQualifier(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum MethodPrototype { - TaskPrototype(Box), - FunctionPrototype(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassConstructorDeclaration { - pub nodes: ( - Keyword, - Option, - Keyword, - Option>>, - Symbol, - Vec, - Option<( - Keyword, - Symbol, - Keyword, - Option>, - Symbol, - )>, - Vec, - Keyword, - Option<(Symbol, New)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct New { - pub nodes: (Keyword,), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/source_text/configuration_source_text.rs b/sv-parser-parser/src/source_text/configuration_source_text.rs similarity index 64% rename from sv-parser/src/parser/source_text/configuration_source_text.rs rename to sv-parser-parser/src/source_text/configuration_source_text.rs index 0cdbcd1..b4b3059 100644 --- a/sv-parser/src/parser/source_text/configuration_source_text.rs +++ b/sv-parser-parser/src/source_text/configuration_source_text.rs @@ -1,136 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct ConfigDeclaration { - pub nodes: ( - Keyword, - ConfigIdentifier, - Symbol, - Vec<(LocalParameterDeclaration, Symbol)>, - DesignStatement, - Vec, - Keyword, - Option<(Symbol, ConfigIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct DesignStatement { - pub nodes: ( - Keyword, - Vec<(Option<(LibraryIdentifier, Symbol)>, CellIdentifier)>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ConfigRuleStatement { - Default(Box), - InstLib(Box), - InstUse(Box), - CellLib(Box), - CellUse(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ConfigRuleStatementDefault { - pub nodes: (DefaultClause, LiblistClause, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct ConfigRuleStatementInstLib { - pub nodes: (InstClause, LiblistClause, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct ConfigRuleStatementInstUse { - pub nodes: (InstClause, UseClause, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct ConfigRuleStatementCellLib { - pub nodes: (CellClause, LiblistClause, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct ConfigRuleStatementCellUse { - pub nodes: (CellClause, UseClause, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct DefaultClause { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct InstClause { - pub nodes: (Keyword, InstName), -} - -#[derive(Clone, Debug, Node)] -pub struct InstName { - pub nodes: (TopmoduleIdentifier, Vec<(Symbol, InstanceIdentifier)>), -} - -#[derive(Clone, Debug, Node)] -pub struct CellClause { - pub nodes: (Keyword, Option<(LibraryIdentifier, Symbol)>, CellIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub struct LiblistClause { - pub nodes: (Keyword, Vec), -} - -#[derive(Clone, Debug, Node)] -pub enum UseClause { - Cell(Box), - Named(Box), - CellNamed(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct UseClauseCell { - pub nodes: ( - Keyword, - Option<(LibraryIdentifier, Symbol)>, - CellIdentifier, - Option<(Symbol, Config)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct UseClauseNamed { - pub nodes: ( - Keyword, - List, - Option<(Symbol, Config)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct UseClauseCellNamed { - pub nodes: ( - Keyword, - Option<(LibraryIdentifier, Symbol)>, - CellIdentifier, - List, - Option<(Symbol, Config)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct Config { - pub nodes: (Keyword,), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/source_text/constraints.rs b/sv-parser-parser/src/source_text/constraints.rs similarity index 65% rename from sv-parser/src/parser/source_text/constraints.rs rename to sv-parser-parser/src/source_text/constraints.rs index 4c179cc..715c909 100644 --- a/sv-parser/src/parser/source_text/constraints.rs +++ b/sv-parser-parser/src/source_text/constraints.rs @@ -1,181 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct ConstraintDeclaration { - pub nodes: ( - Option, - Keyword, - ConstraintIdentifier, - ConstraintBlock, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct Static { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstraintBlock { - pub nodes: (Brace>,), -} - -#[derive(Clone, Debug, Node)] -pub enum ConstraintBlockItem { - Solve(Box), - ConstraintExpression(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstraintBlockItemSolve { - pub nodes: (Keyword, SolveBeforeList, Keyword, SolveBeforeList, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct SolveBeforeList { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstraintPrimary { - pub nodes: ( - Option, - HierarchicalIdentifier, - Select, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ConstraintExpression { - Expression(Box), - UniquenessConstraint(Box<(UniquenessConstraint, Symbol)>), - Arrow(Box), - If(Box), - Foreach(Box), - Disable(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstraintExpressionExpression { - pub nodes: (Option, ExpressionOrDist, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct Soft { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstraintExpressionArrow { - pub nodes: (Expression, Symbol, ConstraintSet), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstraintExpressionIf { - pub nodes: ( - Keyword, - Paren, - ConstraintSet, - Option<(Keyword, ConstraintSet)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstraintExpressionForeach { - pub nodes: ( - Keyword, - Paren<(PsOrHierarchicalArrayIdentifier, Bracket)>, - ConstraintSet, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstraintExpressionDisable { - pub nodes: (Keyword, Keyword, ConstraintPrimary, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct UniquenessConstraint { - pub nodes: (Keyword, Brace), -} - -#[derive(Clone, Debug, Node)] -pub enum ConstraintSet { - ConstraintExpression(Box), - Brace(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstraintSetBrace { - pub nodes: (Brace>,), -} - -#[derive(Clone, Debug, Node)] -pub struct DistList { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct DistItem { - pub nodes: (ValueRange, Option), -} - -#[derive(Clone, Debug, Node)] -pub enum DistWeight { - Equal(Box), - Divide(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct DistWeightEqual { - pub nodes: (Symbol, Expression), -} - -#[derive(Clone, Debug, Node)] -pub struct DistWeightDivide { - pub nodes: (Symbol, Expression), -} - -#[derive(Clone, Debug, Node)] -pub struct ConstraintPrototype { - pub nodes: ( - Option, - Option, - Keyword, - ConstraintIdentifier, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ConstraintPrototypeQualifier { - Extern(Box), - Pure(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ExternConstraintDeclaration { - pub nodes: ( - Option, - Keyword, - ClassScope, - ConstraintIdentifier, - ConstraintBlock, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct IdentifierList { - pub nodes: (List,), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -410,7 +233,9 @@ pub(crate) fn constraint_prototype(s: Span) -> IResult IResult { +pub(crate) fn constraint_prototype_qualifier( + s: Span, +) -> IResult { alt(( map(keyword("extern"), |x| { ConstraintPrototypeQualifier::Extern(Box::new(x)) diff --git a/sv-parser/src/parser/source_text/interface_items.rs b/sv-parser-parser/src/source_text/interface_items.rs similarity index 65% rename from sv-parser/src/parser/source_text/interface_items.rs rename to sv-parser-parser/src/source_text/interface_items.rs index e36278b..c84945e 100644 --- a/sv-parser/src/parser/source_text/interface_items.rs +++ b/sv-parser-parser/src/source_text/interface_items.rs @@ -1,60 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum InterfaceOrGenerateItem { - Module(Box), - Extern(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfaceOrGenerateItemModule { - pub nodes: (Vec, ModuleCommonItem), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfaceOrGenerateItemExtern { - pub nodes: (Vec, ExternTfDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub enum ExternTfDeclaration { - Method(Box), - Task(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ExternTfDeclarationMethod { - pub nodes: (Keyword, MethodPrototype, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct ExternTfDeclarationTask { - pub nodes: (Keyword, Keyword, TaskPrototype, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub enum InterfaceItem { - PortDeclaration(Box<(PortDeclaration, Symbol)>), - NonPortInterfaceItem(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum NonPortInterfaceItem { - GenerateRegion(Box), - InterfaceOrGenerateItem(Box), - ProgramDeclaration(Box), - ModportDeclaration(Box), - InterfaceDeclaration(Box), - TimeunitsDeclaration(Box), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/source_text/library_source_text.rs b/sv-parser-parser/src/source_text/library_source_text.rs similarity index 55% rename from sv-parser/src/parser/source_text/library_source_text.rs rename to sv-parser-parser/src/source_text/library_source_text.rs index cd7bf56..086abaf 100644 --- a/sv-parser/src/parser/source_text/library_source_text.rs +++ b/sv-parser-parser/src/source_text/library_source_text.rs @@ -1,46 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct LibraryText { - pub nodes: (Vec,), -} - -#[derive(Clone, Debug, Node)] -pub enum LibraryDescription { - LibraryDeclaration(Box), - IncludeStatement(Box), - ConfigDeclaration(Box), - Null(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct LibraryDeclaration { - pub nodes: ( - Keyword, - LibraryIdentifier, - List, - Option<(Keyword, List)>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct IncludeStatement { - pub nodes: (Keyword, FilePathSpec, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct FilePathSpec { - pub nodes: (StringLiteral,), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -95,19 +53,3 @@ pub(crate) fn file_path_spec(s: Span) -> IResult { let (s, a) = string_literal(s)?; Ok((s, FilePathSpec { nodes: (a,) })) } - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_library_text() { - parser_test!( - library_text, - "library rtlLib \"*.v\" -incdir \"aaa\";\ninclude \"bbb\";;", - Ok((_, _)) - ); - } -} diff --git a/sv-parser-parser/src/source_text/mod.rs b/sv-parser-parser/src/source_text/mod.rs new file mode 100644 index 0000000..e3383b9 --- /dev/null +++ b/sv-parser-parser/src/source_text/mod.rs @@ -0,0 +1,22 @@ +pub mod checker_items; +pub mod class_items; +pub mod configuration_source_text; +pub mod constraints; +pub mod interface_items; +pub mod library_source_text; +pub mod module_items; +pub mod module_parameters_and_ports; +pub mod package_items; +pub mod program_items; +pub mod system_verilog_source_text; +pub(crate) use checker_items::*; +pub(crate) use class_items::*; +pub(crate) use configuration_source_text::*; +pub(crate) use constraints::*; +pub(crate) use interface_items::*; +pub(crate) use library_source_text::*; +pub(crate) use module_items::*; +pub(crate) use module_parameters_and_ports::*; +pub(crate) use package_items::*; +pub(crate) use program_items::*; +pub(crate) use system_verilog_source_text::*; diff --git a/sv-parser/src/parser/source_text/module_items.rs b/sv-parser-parser/src/source_text/module_items.rs similarity index 67% rename from sv-parser/src/parser/source_text/module_items.rs rename to sv-parser-parser/src/source_text/module_items.rs index 0cf9ff4..be08325 100644 --- a/sv-parser/src/parser/source_text/module_items.rs +++ b/sv-parser-parser/src/source_text/module_items.rs @@ -1,195 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum ElaborationSystemTask { - TaskFatal(Box), - TaskError(Box), - TaskWarning(Box), - TaskInfo(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ElaborationSystemTaskFatal { - pub nodes: ( - Keyword, - Option)>>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ElaborationSystemTaskError { - pub nodes: (Keyword, Option>>, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct ElaborationSystemTaskWarning { - pub nodes: (Keyword, Option>>, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct ElaborationSystemTaskInfo { - pub nodes: (Keyword, Option>>, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub enum FinishNumber { - Zero(Box), - One(Box), - Two(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum ModuleCommonItem { - ModuleOrGenerateItemDeclaration(Box), - InterfaceInstantiation(Box), - ProgramInstantiation(Box), - AssertionItem(Box), - BindDirective(Box), - ContinuousAssign(Box), - NetAlias(Box), - InitialConstruct(Box), - FinalConstruct(Box), - AlwaysConstruct(Box), - LoopGenerateConstruct(Box), - ConditionalGenerateConstruct(Box), - ElaborationSystemTask(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum ModuleItem { - PortDeclaration(Box<(PortDeclaration, Symbol)>), - NonPortModuleItem(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum ModuleOrGenerateItem { - Parameter(Box), - Gate(Box), - Udp(Box), - Module(Box), - ModuleItem(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ModuleOrGenerateItemParameter { - pub nodes: (Vec, ParameterOverride), -} - -#[derive(Clone, Debug, Node)] -pub struct ModuleOrGenerateItemGate { - pub nodes: (Vec, GateInstantiation), -} - -#[derive(Clone, Debug, Node)] -pub struct ModuleOrGenerateItemUdp { - pub nodes: (Vec, UdpInstantiation), -} - -#[derive(Clone, Debug, Node)] -pub struct ModuleOrGenerateItemModule { - pub nodes: (Vec, ModuleInstantiation), -} - -#[derive(Clone, Debug, Node)] -pub struct ModuleOrGenerateItemModuleItem { - pub nodes: (Vec, ModuleCommonItem), -} - -#[derive(Clone, Debug, Node)] -pub enum ModuleOrGenerateItemDeclaration { - PackageOrGenerateItemDeclaration(Box), - GenvarDeclaration(Box), - ClockingDeclaration(Box), - Clocking(Box), - Disable(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ModuleOrGenerateItemDeclarationClocking { - pub nodes: (Keyword, Keyword, ClockingIdentifier, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct ModuleOrGenerateItemDeclarationDisable { - pub nodes: (Keyword, Keyword, Keyword, ExpressionOrDist, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub enum NonPortModuleItem { - GenerateRegion(Box), - ModuleOrGenerateItem(Box), - SpecifyBlock(Box), - Specparam(Box), - ProgramDeclaration(Box), - ModuleDeclaration(Box), - InterfaceDeclaration(Box), - TimeunitsDeclaration(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct NonPortModuleItemSpecparam { - pub nodes: (Vec, SpecparamDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct ParameterOverride { - pub nodes: (Keyword, ListOfDefparamAssignments, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub enum BindDirective { - Scope(Box), - Instance(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct BindDirectiveScope { - pub nodes: ( - Keyword, - BindTargetScope, - Option<(Symbol, BindTargetInstanceList)>, - BindInstantiation, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct BindDirectiveInstance { - pub nodes: (Keyword, BindTargetInstance, BindInstantiation, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub enum BindTargetScope { - ModuleIdentifier(Box), - InterfaceIdentifier(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct BindTargetInstance { - pub nodes: (HierarchicalIdentifier, ConstantBitSelect), -} - -#[derive(Clone, Debug, Node)] -pub struct BindTargetInstanceList { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub enum BindInstantiation { - ProgramInstantiation(Box), - ModuleInstantiation(Box), - InterfaceInstantiation(Box), - CheckerInstantiation(Box), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/source_text/module_parameters_and_ports.rs b/sv-parser-parser/src/source_text/module_parameters_and_ports.rs similarity index 63% rename from sv-parser/src/parser/source_text/module_parameters_and_ports.rs rename to sv-parser-parser/src/source_text/module_parameters_and_ports.rs index f92052d..6c5e599 100644 --- a/sv-parser/src/parser/source_text/module_parameters_and_ports.rs +++ b/sv-parser-parser/src/source_text/module_parameters_and_ports.rs @@ -1,205 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum ParameterPortList { - Assignment(Box), - Declaration(Box), - Empty(Box<(Symbol, Symbol, Symbol)>), -} - -#[derive(Clone, Debug, Node)] -pub struct ParameterPortListAssignment { - pub nodes: ( - Symbol, - Paren<( - ListOfParamAssignments, - Vec<(Symbol, ParameterPortDeclaration)>, - )>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ParameterPortListDeclaration { - pub nodes: (Symbol, Paren>), -} - -#[derive(Clone, Debug, Node)] -pub enum ParameterPortDeclaration { - ParameterDeclaration(Box), - LocalParameterDeclaration(Box), - ParamList(Box), - TypeList(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ParameterPortDeclarationParamList { - pub nodes: (DataType, ListOfParamAssignments), -} - -#[derive(Clone, Debug, Node)] -pub struct ParameterPortDeclarationTypeList { - pub nodes: (Keyword, ListOfTypeAssignments), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfPorts { - pub nodes: (Paren>,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfPortDeclarations { - pub nodes: (Paren, AnsiPortDeclaration)>>>,), -} - -#[derive(Clone, Debug, Node)] -pub enum PortDeclaration { - Inout(Box), - Input(Box), - Output(Box), - Ref(Box), - Interface(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PortDeclarationInout { - pub nodes: (Vec, InoutDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct PortDeclarationInput { - pub nodes: (Vec, InputDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct PortDeclarationOutput { - pub nodes: (Vec, OutputDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct PortDeclarationRef { - pub nodes: (Vec, RefDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct PortDeclarationInterface { - pub nodes: (Vec, InterfacePortDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub enum Port { - NonNamed(Box), - Named(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PortNonNamed { - pub nodes: (Option,), -} - -#[derive(Clone, Debug, Node)] -pub struct PortNamed { - pub nodes: (Symbol, PortIdentifier, Paren>), -} - -#[derive(Clone, Debug, Node)] -pub enum PortExpression { - PortReference(Box), - Brace(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PortExpressionBrace { - pub nodes: (Brace>,), -} - -#[derive(Clone, Debug, Node)] -pub struct PortReference { - pub nodes: (PortIdentifier, ConstantSelect), -} - -#[derive(Clone, Debug, Node)] -pub enum PortDirection { - Input(Box), - Output(Box), - Inout(Box), - Ref(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct NetPortHeader { - pub nodes: (Option, NetPortType), -} - -#[derive(Clone, Debug, Node)] -pub struct VariablePortHeader { - pub nodes: (Option, VariablePortType), -} - -#[derive(Clone, Debug, Node)] -pub enum InterfacePortHeader { - Identifier(Box), - Interface(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfacePortHeaderIdentifier { - pub nodes: (InterfaceIdentifier, Option<(Symbol, ModportIdentifier)>), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfacePortHeaderInterface { - pub nodes: (Keyword, Option<(Symbol, ModportIdentifier)>), -} - -#[derive(Clone, Debug, Node)] -pub enum NetPortHeaderOrInterfacePortHeader { - NetPortHeader(Box), - InterfacePortHeader(Box), -} -#[derive(Clone, Debug, Node)] -pub enum AnsiPortDeclaration { - Net(Box), - Variable(Box), - Paren(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct AnsiPortDeclarationNet { - pub nodes: ( - Option, - PortIdentifier, - Vec, - Option<(Symbol, ConstantExpression)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct AnsiPortDeclarationVariable { - pub nodes: ( - Option, - PortIdentifier, - Vec, - Option<(Symbol, ConstantExpression)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct AnsiPortDeclarationParen { - pub nodes: ( - Option, - Symbol, - PortIdentifier, - Paren>, - ), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -258,7 +57,9 @@ pub(crate) fn parameter_port_declaration(s: Span) -> IResult IResult { +pub(crate) fn parameter_port_declaration_param_list( + s: Span, +) -> IResult { let (s, a) = data_type(s)?; let (s, b) = list_of_param_assignments(s)?; Ok(( @@ -270,7 +71,9 @@ pub(crate) fn parameter_port_declaration_param_list(s: Span) -> IResult IResult { +pub(crate) fn parameter_port_declaration_type_list( + s: Span, +) -> IResult { let (s, a) = keyword("type")(s)?; let (s, b) = list_of_type_assignments(s)?; Ok(( diff --git a/sv-parser/src/parser/source_text/package_items.rs b/sv-parser-parser/src/source_text/package_items.rs similarity index 68% rename from sv-parser/src/parser/source_text/package_items.rs rename to sv-parser-parser/src/source_text/package_items.rs index 43612f7..616c73d 100644 --- a/sv-parser/src/parser/source_text/package_items.rs +++ b/sv-parser-parser/src/source_text/package_items.rs @@ -1,53 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum PackageItem { - PackageOrGenerateItemDeclaration(Box), - AnonymousProgram(Box), - PackageExportDeclaration(Box), - TimeunitsDeclaration(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum PackageOrGenerateItemDeclaration { - NetDeclaration(Box), - DataDeclaration(Box), - TaskDeclaration(Box), - FunctionDeclaration(Box), - CheckerDeclaration(Box), - DpiImportExport(Box), - ExternConstraintDeclaration(Box), - ClassDeclaration(Box), - ClassConstructorDeclaration(Box), - LocalParameterDeclaration(Box<(LocalParameterDeclaration, Symbol)>), - ParameterDeclaration(Box<(ParameterDeclaration, Symbol)>), - CovergroupDeclaration(Box), - AssertionItemDeclaration(Box), - Empty(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct AnonymousProgram { - pub nodes: (Keyword, Symbol, Vec, Keyword), -} - -#[derive(Clone, Debug, Node)] -pub enum AnonymousProgramItem { - TaskDeclaration(Box), - FunctionDeclaration(Box), - ClassDeclaration(Box), - CovergroupDeclaration(Box), - ClassConstructorDeclaration(Box), - Empty(Box), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/source_text/program_items.rs b/sv-parser-parser/src/source_text/program_items.rs similarity index 64% rename from sv-parser/src/parser/source_text/program_items.rs rename to sv-parser-parser/src/source_text/program_items.rs index bb59786..6b9aad5 100644 --- a/sv-parser/src/parser/source_text/program_items.rs +++ b/sv-parser-parser/src/source_text/program_items.rs @@ -1,62 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum ProgramItem { - PortDeclaration(Box<(PortDeclaration, Symbol)>), - NonPortProgramItem(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum NonPortProgramItem { - Assign(Box), - Module(Box), - Initial(Box), - Final(Box), - Assertion(Box), - TimeunitsDeclaration(Box), - ProgramGenerateItem(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct NonPortProgramItemAssign { - pub nodes: (Vec, ContinuousAssign), -} - -#[derive(Clone, Debug, Node)] -pub struct NonPortProgramItemModule { - pub nodes: (Vec, ModuleOrGenerateItemDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct NonPortProgramItemInitial { - pub nodes: (Vec, InitialConstruct), -} - -#[derive(Clone, Debug, Node)] -pub struct NonPortProgramItemFinal { - pub nodes: (Vec, FinalConstruct), -} - -#[derive(Clone, Debug, Node)] -pub struct NonPortProgramItemAssertion { - pub nodes: (Vec, ConcurrentAssertionItem), -} - -#[derive(Clone, Debug, Node)] -pub enum ProgramGenerateItem { - LoopGenerateConstruct(Box), - ConditionalGenerateConstruct(Box), - GenerateRegion(Box), - ElaborationSystemTask(Box), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/source_text/system_verilog_source_text.rs b/sv-parser-parser/src/source_text/system_verilog_source_text.rs similarity index 64% rename from sv-parser/src/parser/source_text/system_verilog_source_text.rs rename to sv-parser-parser/src/source_text/system_verilog_source_text.rs index de29f5e..8bbf20a 100644 --- a/sv-parser/src/parser/source_text/system_verilog_source_text.rs +++ b/sv-parser-parser/src/source_text/system_verilog_source_text.rs @@ -1,417 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct SourceText { - pub nodes: (Option, Vec), -} - -#[derive(Clone, Debug, Node)] -pub enum Description { - ModuleDeclaration(Box), - UdpDeclaration(Box), - InterfaceDeclaration(Box), - InterfaceClassDeclaration(Box), - ProgramDeclaration(Box), - PackageDeclaration(Box), - PackageItem(Box), - BindDirective(Box), - ConfigDeclaration(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct DescriptionPackageItem { - pub nodes: (Vec, PackageItem), -} - -#[derive(Clone, Debug, Node)] -pub struct DescriptionBindDirective { - pub nodes: (Vec, BindDirective), -} - -#[derive(Clone, Debug, Node)] -pub struct ModuleNonansiHeader { - pub nodes: ( - Vec, - ModuleKeyword, - Option, - ModuleIdentifier, - Vec, - Option, - ListOfPorts, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ModuleAnsiHeader { - pub nodes: ( - Vec, - ModuleKeyword, - Option, - ModuleIdentifier, - Vec, - Option, - Option, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ModuleDeclaration { - Nonansi(Box), - Ansi(Box), - Wildcard(Box), - ExternNonansi(Box), - ExternAnsi(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ModuleDeclarationNonansi { - pub nodes: ( - ModuleNonansiHeader, - Option, - Vec, - Keyword, - Option<(Symbol, ModuleIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ModuleDeclarationAnsi { - pub nodes: ( - ModuleAnsiHeader, - Option, - Vec, - Keyword, - Option<(Symbol, ModuleIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ModuleDeclarationWildcard { - pub nodes: ( - Vec, - ModuleKeyword, - Option, - ModuleIdentifier, - Paren, - Symbol, - Option, - Vec, - Keyword, - Option<(Symbol, ModuleIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ModuleDeclarationExternNonansi { - pub nodes: (Keyword, ModuleNonansiHeader), -} - -#[derive(Clone, Debug, Node)] -pub struct ModuleDeclarationExternAnsi { - pub nodes: (Keyword, ModuleAnsiHeader), -} - -#[derive(Clone, Debug, Node)] -pub enum ModuleKeyword { - Module(Box), - Macromodule(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum InterfaceDeclaration { - Nonansi(Box), - Ansi(Box), - Wildcard(Box), - ExternNonansi(Box), - ExternAnsi(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfaceDeclarationNonansi { - pub nodes: ( - InterfaceNonansiHeader, - Option, - Vec, - Keyword, - Option<(Symbol, InterfaceIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfaceDeclarationAnsi { - pub nodes: ( - InterfaceAnsiHeader, - Option, - Vec, - Keyword, - Option<(Symbol, InterfaceIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfaceDeclarationWildcard { - pub nodes: ( - Vec, - Keyword, - Option, - InterfaceIdentifier, - Paren, - Symbol, - Option, - Vec, - Keyword, - Option<(Symbol, InterfaceIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfaceDeclarationExternNonansi { - pub nodes: (Keyword, InterfaceNonansiHeader), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfaceDeclarationExternAnsi { - pub nodes: (Keyword, InterfaceAnsiHeader), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfaceNonansiHeader { - pub nodes: ( - Vec, - Keyword, - Option, - InterfaceIdentifier, - Vec, - Option, - ListOfPorts, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfaceAnsiHeader { - pub nodes: ( - Vec, - Keyword, - Option, - InterfaceIdentifier, - Vec, - Option, - Option, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum ProgramDeclaration { - Nonansi(Box), - Ansi(Box), - Wildcard(Box), - ExternNonansi(Box), - ExternAnsi(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ProgramDeclarationNonansi { - pub nodes: ( - ProgramNonansiHeader, - Option, - Vec, - Keyword, - Option<(Symbol, ProgramIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ProgramDeclarationAnsi { - pub nodes: ( - ProgramAnsiHeader, - Option, - Vec, - Keyword, - Option<(Symbol, ProgramIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ProgramDeclarationWildcard { - pub nodes: ( - Vec, - Keyword, - ProgramIdentifier, - Paren, - Symbol, - Option, - Vec, - Keyword, - Option<(Symbol, ProgramIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ProgramDeclarationExternNonansi { - pub nodes: (Keyword, ProgramNonansiHeader), -} - -#[derive(Clone, Debug, Node)] -pub struct ProgramDeclarationExternAnsi { - pub nodes: (Keyword, ProgramAnsiHeader), -} - -#[derive(Clone, Debug, Node)] -pub struct ProgramNonansiHeader { - pub nodes: ( - Vec, - Keyword, - Option, - ProgramIdentifier, - Vec, - Option, - ListOfPorts, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ProgramAnsiHeader { - pub nodes: ( - Vec, - Keyword, - Option, - ProgramIdentifier, - Vec, - Option, - Option, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct CheckerDeclaration { - pub nodes: ( - Keyword, - CheckerIdentifier, - Option>>, - Symbol, - Vec<(Vec, CheckerOrGenerateItem)>, - Keyword, - Option<(Symbol, CheckerIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ClassDeclaration { - pub nodes: ( - Option, - Keyword, - Option, - ClassIdentifier, - Option, - Option<(Keyword, ClassType, Option>)>, - Option<(Keyword, List)>, - Symbol, - Vec, - Keyword, - Option<(Symbol, ClassIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct Virtual { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfaceClassType { - pub nodes: (PsClassIdentifier, Option), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfaceClassDeclaration { - pub nodes: ( - Keyword, - Keyword, - ClassIdentifier, - Option, - Option<(Keyword, List)>, - Symbol, - Vec, - Keyword, - Option<(Symbol, ClassIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum InterfaceClassItem { - TypeDeclaration(Box), - Method(Box), - LocalParameterDeclaration(Box<(LocalParameterDeclaration, Symbol)>), - ParameterDeclaration(Box<(ParameterDeclaration, Symbol)>), - Null(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfaceClassItemMethod { - pub nodes: (Vec, InterfaceClassMethod), -} - -#[derive(Clone, Debug, Node)] -pub struct InterfaceClassMethod { - pub nodes: (Keyword, Keyword, MethodPrototype, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct PackageDeclaration { - pub nodes: ( - Vec, - Keyword, - Option, - PackageIdentifier, - Symbol, - Option, - Vec<(Vec, PackageItem)>, - Keyword, - Option<(Symbol, PackageIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum TimeunitsDeclaration { - Timeunit(Box), - Timeprecision(Box), - TimeunitTimeprecision(Box), - TimeprecisionTimeunit(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct TimeunitsDeclarationTimeunit { - pub nodes: (Keyword, TimeLiteral, Option<(Symbol, TimeLiteral)>, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct TimeunitsDeclarationTimeprecision { - pub nodes: (Keyword, TimeLiteral, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct TimeunitsDeclarationTimeunitTimeprecision { - pub nodes: (Keyword, TimeLiteral, Symbol, Keyword, TimeLiteral, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct TimeunitsDeclarationTimeprecisionTimeunit { - pub nodes: (Keyword, TimeLiteral, Symbol, Keyword, TimeLiteral, Symbol), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -1049,27 +636,3 @@ pub(crate) fn timeunits_declaration_timeprecision_timeunit( )), )) } - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_timeunits_declaration() { - parser_test!(timeunits_declaration, "timeunit 1.0ps;", Ok((_, _))); - parser_test!(timeunits_declaration, "timeunit 1.0ps / 20ms;", Ok((_, _))); - parser_test!(timeunits_declaration, "timeprecision 10.0fs;", Ok((_, _))); - parser_test!( - timeunits_declaration, - "timeunit 10.0fs; timeprecision 20s;", - Ok((_, _)) - ); - parser_test!( - timeunits_declaration, - "timeprecision 10.0fs; timeunit 20s \n;", - Ok((_, _)) - ); - } -} diff --git a/sv-parser-parser/src/specify_section/mod.rs b/sv-parser-parser/src/specify_section/mod.rs new file mode 100644 index 0000000..6682721 --- /dev/null +++ b/sv-parser-parser/src/specify_section/mod.rs @@ -0,0 +1,14 @@ +pub mod specify_block_declaration; +pub mod specify_block_terminals; +pub mod specify_path_declarations; +pub mod specify_path_delays; +pub mod system_timing_check_command_arguments; +pub mod system_timing_check_commands; +pub mod system_timing_check_event_definitions; +pub(crate) use specify_block_declaration::*; +pub(crate) use specify_block_terminals::*; +pub(crate) use specify_path_declarations::*; +pub(crate) use specify_path_delays::*; +pub(crate) use system_timing_check_command_arguments::*; +pub(crate) use system_timing_check_commands::*; +pub(crate) use system_timing_check_event_definitions::*; diff --git a/sv-parser/src/parser/specify_section/specify_block_declaration.rs b/sv-parser-parser/src/specify_section/specify_block_declaration.rs similarity index 65% rename from sv-parser/src/parser/specify_section/specify_block_declaration.rs rename to sv-parser-parser/src/specify_section/specify_block_declaration.rs index cd56150..e27b55c 100644 --- a/sv-parser/src/parser/specify_section/specify_block_declaration.rs +++ b/sv-parser-parser/src/specify_section/specify_block_declaration.rs @@ -1,35 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct SpecifyBlock { - pub nodes: (Keyword, Vec, Keyword), -} - -#[derive(Clone, Debug, Node)] -pub enum SpecifyItem { - SpecparamDeclaration(Box), - PulsestyleDeclaration(Box), - ShowcancelledDeclaration(Box), - PathDeclaration(Box), - SystemTimingCheck(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PulsestyleDeclaration { - pub nodes: (Keyword, ListOfPathOutputs, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct ShowcancelledDeclaration { - pub nodes: (Keyword, ListOfPathOutputs, Symbol), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/specify_section/specify_block_terminals.rs b/sv-parser-parser/src/specify_section/specify_block_terminals.rs similarity index 60% rename from sv-parser/src/parser/specify_section/specify_block_terminals.rs rename to sv-parser-parser/src/specify_section/specify_block_terminals.rs index ac0b9fb..001776c 100644 --- a/sv-parser/src/parser/specify_section/specify_block_terminals.rs +++ b/sv-parser-parser/src/specify_section/specify_block_terminals.rs @@ -1,49 +1,11 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct SpecifyInputTerminalDescriptor { - pub nodes: (InputIdentifier, Option>), -} - -#[derive(Clone, Debug, Node)] -pub struct SpecifyOutputTerminalDescriptor { - pub nodes: (OutputIdentifier, Option>), -} - -#[derive(Clone, Debug, Node)] -pub enum InputIdentifier { - InputPortIdentifier(Box), - InoutPortIdentifier(Box), - Interface(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct InputIdentifierInterface { - pub nodes: (InterfaceIdentifier, Symbol, PortIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub enum OutputIdentifier { - OutputPortIdentifier(Box), - InoutPortIdentifier(Box), - Interface(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct OutputIdentifierInterface { - pub nodes: (InterfaceIdentifier, Symbol, PortIdentifier), -} +use crate::*; // ----------------------------------------------------------------------------- #[parser] -pub(crate) fn specify_input_terminal_descriptor(s: Span) -> IResult { +pub(crate) fn specify_input_terminal_descriptor( + s: Span, +) -> IResult { let (s, a) = input_identifier(s)?; let (s, b) = opt(bracket(constant_range_expression))(s)?; Ok((s, SpecifyInputTerminalDescriptor { nodes: (a, b) })) diff --git a/sv-parser/src/parser/specify_section/specify_path_declarations.rs b/sv-parser-parser/src/specify_section/specify_path_declarations.rs similarity index 61% rename from sv-parser/src/parser/specify_section/specify_path_declarations.rs rename to sv-parser-parser/src/specify_section/specify_path_declarations.rs index 7120b06..6276fa4 100644 --- a/sv-parser/src/parser/specify_section/specify_path_declarations.rs +++ b/sv-parser-parser/src/specify_section/specify_path_declarations.rs @@ -1,68 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum PathDeclaration { - SimplePathDeclaration(Box<(SimplePathDeclaration, Symbol)>), - EdgeSensitivePathDeclaration(Box<(EdgeSensitivePathDeclaration, Symbol)>), - StateDependentPathDeclaration(Box<(StateDependentPathDeclaration, Symbol)>), -} - -#[derive(Clone, Debug, Node)] -pub enum SimplePathDeclaration { - Parallel(Box), - Full(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct SimplePathDeclarationParallel { - pub nodes: (ParallelPathDescription, Symbol, PathDelayValue), -} - -#[derive(Clone, Debug, Node)] -pub struct SimplePathDeclarationFull { - pub nodes: (FullPathDescription, Symbol, PathDelayValue), -} - -#[derive(Clone, Debug, Node)] -pub struct ParallelPathDescription { - pub nodes: ( - Paren<( - SpecifyInputTerminalDescriptor, - Option, - Symbol, - SpecifyOutputTerminalDescriptor, - )>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct FullPathDescription { - pub nodes: ( - Paren<( - ListOfPathInputs, - Option, - Symbol, - ListOfPathOutputs, - )>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfPathInputs { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfPathOutputs { - pub nodes: (List,), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/specify_section/specify_path_delays.rs b/sv-parser-parser/src/specify_section/specify_path_delays.rs similarity index 61% rename from sv-parser/src/parser/specify_section/specify_path_delays.rs rename to sv-parser-parser/src/specify_section/specify_path_delays.rs index fdbccbb..0bcb5c7 100644 --- a/sv-parser/src/parser/specify_section/specify_path_delays.rs +++ b/sv-parser-parser/src/specify_section/specify_path_delays.rs @@ -1,131 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum PathDelayValue { - ListOfPathDelayExpressions(Box), - Paren(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PathDelayValueParen { - pub nodes: (Paren,), -} - -#[derive(Clone, Debug, Node)] -pub struct ListOfPathDelayExpressions { - pub nodes: (List,), -} - -#[derive(Clone, Debug, Node)] -pub struct TPathDelayExpression { - pub nodes: (PathDelayExpression,), -} -#[derive(Clone, Debug, Node)] -pub struct PathDelayExpression { - pub nodes: (ConstantMintypmaxExpression,), -} - -#[derive(Clone, Debug, Node)] -pub enum EdgeSensitivePathDeclaration { - Parallel(Box), - Full(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct EdgeSensitivePathDeclarationParallel { - pub nodes: (ParallelEdgeSensitivePathDescription, Symbol, PathDelayValue), -} - -#[derive(Clone, Debug, Node)] -pub struct EdgeSensitivePathDeclarationFull { - pub nodes: (FullEdgeSensitivePathDescription, Symbol, PathDelayValue), -} - -#[derive(Clone, Debug, Node)] -pub struct ParallelEdgeSensitivePathDescription { - pub nodes: ( - Paren<( - Option, - SpecifyInputTerminalDescriptor, - Option, - Symbol, - Paren<( - SpecifyOutputTerminalDescriptor, - Option, - Symbol, - DataSourceExpression, - )>, - )>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct FullEdgeSensitivePathDescription { - pub nodes: ( - Paren<( - Option, - ListOfPathInputs, - Option, - Symbol, - Paren<( - ListOfPathOutputs, - Option, - Symbol, - DataSourceExpression, - )>, - )>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct DataSourceExpression { - pub nodes: (Expression,), -} - -#[derive(Clone, Debug, Node)] -pub enum EdgeIdentifier { - Posedge(Box), - Negedge(Box), - Edge(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum StateDependentPathDeclaration { - IfSimple(Box), - IfEdgeSensitive(Box), - IfNone(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct StateDependentPathDeclarationIfSimple { - pub nodes: (Keyword, Paren, SimplePathDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct StateDependentPathDeclarationIfEdgeSensitive { - pub nodes: ( - Keyword, - Paren, - EdgeSensitivePathDeclaration, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct StateDependentPathDeclarationIfNone { - pub nodes: (Keyword, SimplePathDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct PolarityOperator { - pub nodes: (Symbol,), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -167,7 +40,9 @@ pub(crate) fn path_delay_expression(s: Span) -> IResult IResult { +pub(crate) fn edge_sensitive_path_declaration( + s: Span, +) -> IResult { alt(( edge_sensitive_path_declaration_parallel, edge_sensitive_path_declaration_full, @@ -258,7 +133,9 @@ pub(crate) fn edge_identifier(s: Span) -> IResult { } #[parser] -pub(crate) fn state_dependent_path_declaration(s: Span) -> IResult { +pub(crate) fn state_dependent_path_declaration( + s: Span, +) -> IResult { alt(( state_dependent_path_declaration_if_simple, state_dependent_path_declaration_if_edge_sensitive, diff --git a/sv-parser/src/parser/specify_section/system_timing_check_command_arguments.rs b/sv-parser-parser/src/specify_section/system_timing_check_command_arguments.rs similarity index 62% rename from sv-parser/src/parser/specify_section/system_timing_check_command_arguments.rs rename to sv-parser-parser/src/specify_section/system_timing_check_command_arguments.rs index 1fe991b..bf92151 100644 --- a/sv-parser/src/parser/specify_section/system_timing_check_command_arguments.rs +++ b/sv-parser-parser/src/specify_section/system_timing_check_command_arguments.rs @@ -1,92 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct TimecheckCondition { - pub nodes: (MintypmaxExpression,), -} - -#[derive(Clone, Debug, Node)] -pub struct ControlledReferenceEvent { - pub nodes: (ControlledTimingCheckEvent,), -} - -#[derive(Clone, Debug, Node)] -pub struct DataEvent { - pub nodes: (TimingCheckEvent,), -} - -#[derive(Clone, Debug, Node)] -pub enum DelayedData { - TerminalIdentifier(Box), - WithMintypmax(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct DelayedDataWithMintypmax { - pub nodes: (TerminalIdentifier, Bracket), -} - -#[derive(Clone, Debug, Node)] -pub enum DelayedReference { - TerminalIdentifier(Box), - WithMintypmax(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct DelayedReferenceWithMintypmax { - pub nodes: (TerminalIdentifier, Bracket), -} - -#[derive(Clone, Debug, Node)] -pub struct EndEdgeOffset { - pub nodes: (MintypmaxExpression,), -} - -#[derive(Clone, Debug, Node)] -pub struct EventBasedFlag { - pub nodes: (ConstantExpression,), -} - -#[derive(Clone, Debug, Node)] -pub struct Notifier { - pub nodes: (VariableIdentifier,), -} - -#[derive(Clone, Debug, Node)] -pub struct ReferenceEvent { - pub nodes: (TimingCheckEvent,), -} - -#[derive(Clone, Debug, Node)] -pub struct RemainActiveFlag { - pub nodes: (ConstantMintypmaxExpression,), -} - -#[derive(Clone, Debug, Node)] -pub struct TimestampCondition { - pub nodes: (MintypmaxExpression,), -} - -#[derive(Clone, Debug, Node)] -pub struct StartEdgeOffset { - pub nodes: (MintypmaxExpression,), -} - -#[derive(Clone, Debug, Node)] -pub struct Threshold { - pub nodes: (ConstantExpression,), -} - -#[derive(Clone, Debug, Node)] -pub struct TimingCheckLimit { - pub nodes: (Expression,), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/specify_section/system_timing_check_commands.rs b/sv-parser-parser/src/specify_section/system_timing_check_commands.rs similarity index 56% rename from sv-parser/src/parser/specify_section/system_timing_check_commands.rs rename to sv-parser-parser/src/specify_section/system_timing_check_commands.rs index 6f7ebef..fee248b 100644 --- a/sv-parser/src/parser/specify_section/system_timing_check_commands.rs +++ b/sv-parser-parser/src/specify_section/system_timing_check_commands.rs @@ -1,273 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum SystemTimingCheck { - SetupTimingCheck(Box), - HoldTimingCheck(Box), - SetupholdTimingCheck(Box), - RecoveryTimingCheck(Box), - RemovalTimingCheck(Box), - RecremTimingCheck(Box), - SkewTimingCheck(Box), - TimeskewTimingCheck(Box), - FullskewTimingCheck(Box), - PeriodTimingCheck(Box), - WidthTimingCheck(Box), - NochargeTimingCheck(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct SetupTimingCheck { - pub nodes: ( - Keyword, - Paren<( - DataEvent, - Symbol, - ReferenceEvent, - Symbol, - TimingCheckLimit, - Option<(Symbol, Option)>, - )>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct HoldTimingCheck { - pub nodes: ( - Keyword, - Paren<( - ReferenceEvent, - Symbol, - DataEvent, - Symbol, - TimingCheckLimit, - Option<(Symbol, Option)>, - )>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct SetupholdTimingCheck { - pub nodes: ( - Keyword, - Paren<( - ReferenceEvent, - Symbol, - DataEvent, - Symbol, - TimingCheckLimit, - Symbol, - TimingCheckLimit, - Option<( - Symbol, - Option, - Option<( - Symbol, - Option, - Option<( - Symbol, - Option, - Option<( - Symbol, - Option, - Option<(Symbol, Option)>, - )>, - )>, - )>, - )>, - )>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct RecoveryTimingCheck { - pub nodes: ( - Keyword, - Paren<( - ReferenceEvent, - Symbol, - DataEvent, - Symbol, - TimingCheckLimit, - Option<(Symbol, Option)>, - )>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct RemovalTimingCheck { - pub nodes: ( - Keyword, - Paren<( - ReferenceEvent, - Symbol, - DataEvent, - Symbol, - TimingCheckLimit, - Option<(Symbol, Option)>, - )>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct RecremTimingCheck { - pub nodes: ( - Keyword, - Paren<( - ReferenceEvent, - Symbol, - DataEvent, - Symbol, - TimingCheckLimit, - Symbol, - TimingCheckLimit, - Option<( - Symbol, - Option, - Option<( - Symbol, - Option, - Option<( - Symbol, - Option, - Option<( - Symbol, - Option, - Option<(Symbol, Option)>, - )>, - )>, - )>, - )>, - )>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct SkewTimingCheck { - pub nodes: ( - Keyword, - Paren<( - ReferenceEvent, - Symbol, - DataEvent, - Symbol, - TimingCheckLimit, - Option<(Symbol, Option)>, - )>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct TimeskewTimingCheck { - pub nodes: ( - Keyword, - Paren<( - ReferenceEvent, - Symbol, - DataEvent, - Symbol, - TimingCheckLimit, - Option<( - Symbol, - Option, - Option<( - Symbol, - Option, - Option<(Symbol, Option)>, - )>, - )>, - )>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct FullskewTimingCheck { - pub nodes: ( - Keyword, - Paren<( - ReferenceEvent, - Symbol, - DataEvent, - Symbol, - TimingCheckLimit, - Symbol, - TimingCheckLimit, - Option<( - Symbol, - Option, - Option<( - Symbol, - Option, - Option<(Symbol, Option)>, - )>, - )>, - )>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct PeriodTimingCheck { - pub nodes: ( - Keyword, - Paren<( - ControlledReferenceEvent, - Symbol, - TimingCheckLimit, - Option<(Symbol, Option)>, - )>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct WidthTimingCheck { - pub nodes: ( - Keyword, - Paren<( - ControlledReferenceEvent, - Symbol, - TimingCheckLimit, - Symbol, - Threshold, - Option<(Symbol, Option)>, - )>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct NochargeTimingCheck { - pub nodes: ( - Keyword, - Paren<( - ReferenceEvent, - Symbol, - DataEvent, - Symbol, - StartEdgeOffset, - Symbol, - EndEdgeOffset, - Option<(Symbol, Option)>, - )>, - Symbol, - ), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/specify_section/system_timing_check_event_definitions.rs b/sv-parser-parser/src/specify_section/system_timing_check_event_definitions.rs similarity index 70% rename from sv-parser/src/parser/specify_section/system_timing_check_event_definitions.rs rename to sv-parser-parser/src/specify_section/system_timing_check_event_definitions.rs index 491ebcb..38f028a 100644 --- a/sv-parser/src/parser/specify_section/system_timing_check_event_definitions.rs +++ b/sv-parser-parser/src/specify_section/system_timing_check_event_definitions.rs @@ -1,86 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct TimingCheckEvent { - pub nodes: ( - Option, - SpecifyTerminalDescriptor, - Option<(Symbol, TimingCheckCondition)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct ControlledTimingCheckEvent { - pub nodes: ( - TimingCheckEventControl, - SpecifyTerminalDescriptor, - Option<(Symbol, TimingCheckCondition)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum TimingCheckEventControl { - Posedge(Box), - Negedge(Box), - Edge(Box), - EdgeControlSpecifier(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum SpecifyTerminalDescriptor { - SpecifyInputTerminalDescriptor(Box), - SpecifyOutputTerminalDescriptor(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct EdgeControlSpecifier { - pub nodes: (Keyword, Bracket>), -} - -#[derive(Clone, Debug, Node)] -pub struct EdgeDescriptor { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub enum TimingCheckCondition { - ScalarTimingCheckCondition(Box), - Paren(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct TimingCheckConditionParen { - pub nodes: (Paren,), -} - -#[derive(Clone, Debug, Node)] -pub enum ScalarTimingCheckCondition { - Expression(Box), - Unary(Box), - Binary(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ScalarTimingCheckConditionUnary { - pub nodes: (Symbol, Expression), -} - -#[derive(Clone, Debug, Node)] -pub struct ScalarTimingCheckConditionBinary { - pub nodes: (Expression, Symbol, ScalarConstant), -} - -#[derive(Clone, Debug, Node)] -pub struct ScalarConstant { - pub nodes: (Keyword,), -} +use crate::*; // ----------------------------------------------------------------------------- @@ -192,7 +110,9 @@ pub(crate) fn scalar_timing_check_condition(s: Span) -> IResult IResult { +pub(crate) fn scalar_timing_check_condition_unary( + s: Span, +) -> IResult { let (s, a) = symbol("~")(s)?; let (s, b) = expression(s)?; Ok(( @@ -204,7 +124,9 @@ pub(crate) fn scalar_timing_check_condition_unary(s: Span) -> IResult IResult { +pub(crate) fn scalar_timing_check_condition_binary( + s: Span, +) -> IResult { let (s, a) = expression(s)?; let (s, b) = alt((symbol("==="), symbol("=="), symbol("!=="), symbol("!=")))(s)?; let (s, c) = scalar_constant(s)?; diff --git a/sv-parser-parser/src/tests.rs b/sv-parser-parser/src/tests.rs new file mode 100644 index 0000000..788c1af --- /dev/null +++ b/sv-parser-parser/src/tests.rs @@ -0,0 +1,791 @@ +#![cfg(test)] + +use crate::*; + +macro_rules! test { + ( $x:expr, $y:expr, $z:pat ) => { + let ret = all_consuming($x)(Span::new_extra($y, Extra::default())); + if let $z = ret { + } else { + assert!(false, "{:?}", ret) + } + }; +} + +#[test] +fn test_pulldown_strength() { + test!(pulldown_strength, "(supply0, strong1)", Ok((_, _))); + test!(pulldown_strength, "(pull1, weak0)", Ok((_, _))); + test!(pulldown_strength, "(pull0)", Ok((_, _))); + test!(pulldown_strength, "(pull0)", Ok((_, _))); + test!(pulldown_strength, "(pull0)", Ok((_, _))); +} + +#[test] +fn test_pullup_strength() { + test!(pullup_strength, "(supply0, strong1)", Ok((_, _))); + test!(pullup_strength, "(pull1, weak0)", Ok((_, _))); + test!(pullup_strength, "(supply1)", Ok((_, _))); +} + +#[test] +fn test_cmos_switchtype() { + test!(cmos_switchtype, "cmos ", Ok((_, _))); + test!(cmos_switchtype, "rcmos ", Ok((_, _))); +} + +#[test] +fn test_enable_gatetype() { + test!(enable_gatetype, "bufif0 ", Ok((_, _))); + test!(enable_gatetype, "bufif1 ", Ok((_, _))); + test!(enable_gatetype, "notif0 ", Ok((_, _))); + test!(enable_gatetype, "notif1 ", Ok((_, _))); +} + +#[test] +fn test_mos_switchtype() { + test!(mos_switchtype, "nmos ", Ok((_, _))); + test!(mos_switchtype, "pmos ", Ok((_, _))); + test!(mos_switchtype, "rnmos ", Ok((_, _))); + test!(mos_switchtype, "rpmos ", Ok((_, _))); +} + +#[test] +fn test_n_input_gatetype() { + test!(n_input_gatetype, "and ", Ok((_, _))); + test!(n_input_gatetype, "nand ", Ok((_, _))); + test!(n_input_gatetype, "or ", Ok((_, _))); + test!(n_input_gatetype, "nor ", Ok((_, _))); + test!(n_input_gatetype, "xor ", Ok((_, _))); + test!(n_input_gatetype, "xnor ", Ok((_, _))); +} + +#[test] +fn test_n_output_gatetype() { + test!(n_output_gatetype, "buf ", Ok((_, _))); + test!(n_output_gatetype, "not ", Ok((_, _))); +} + +#[test] +fn test_pass_en_switchtype() { + test!(pass_en_switchtype, "tranif0 ", Ok((_, _))); + test!(pass_en_switchtype, "tranif1 ", Ok((_, _))); + test!(pass_en_switchtype, "rtranif0 ", Ok((_, _))); + test!(pass_en_switchtype, "rtranif1 ", Ok((_, _))); +} + +#[test] +fn test_pass_switchtype() { + test!(pass_switchtype, "tran ", Ok((_, _))); + test!(pass_switchtype, "rtran ", Ok((_, _))); +} + +#[test] +fn test_library_text() { + test!( + library_text, + "library rtlLib \"*.v\" -incdir \"aaa\";\ninclude \"bbb\";;", + Ok((_, _)) + ); +} + +#[test] +fn test_timeunits_declaration() { + test!(timeunits_declaration, "timeunit 1.0ps;", Ok((_, _))); + test!(timeunits_declaration, "timeunit 1.0ps / 20ms;", Ok((_, _))); + test!(timeunits_declaration, "timeprecision 10.0fs;", Ok((_, _))); + test!( + timeunits_declaration, + "timeunit 10.0fs; timeprecision 20s;", + Ok((_, _)) + ); + test!( + timeunits_declaration, + "timeprecision 10.0fs; timeunit 20s \n;", + Ok((_, _)) + ); +} + +#[test] +fn test_data_type() { + test!( + data_type, + "struct { bit [7:0] opcode; bit [23:0] addr; }", + Ok((_, DataType::StructUnion(_))) + ); + test!( + data_type, + "struct packed signed { int a; shortint b; byte c; bit [7:0] d; }", + Ok((_, DataType::StructUnion(_))) + ); + test!( + data_type, + "union { int i; shortreal f; } ", + Ok((_, DataType::StructUnion(_))) + ); + test!( + data_type, + "struct { bit isfloat; union { int i; shortreal f; } n; }", + Ok((_, DataType::StructUnion(_))) + ); + test!( + data_type, + "union packed { s_atmcell acell; bit [423:0] bit_slice; bit [52:0][7:0] byte_slice; }", + Ok((_, DataType::StructUnion(_))) + ); + test!( + data_type, + "union tagged { void Invalid; int Valid; }", + Ok((_, DataType::StructUnion(_))) + ); +} + +#[test] +fn test_local_parameter_declaration() { + test!( + local_parameter_declaration, + "localparam byte colon1 = \":\" ", + Ok((_, LocalParameterDeclaration::Param(_))) + ); +} + +#[test] +fn test_parameter_declaration() { + test!( + parameter_declaration, + "parameter logic flag = 1 ", + Ok((_, ParameterDeclaration::Param(_))) + ); + test!( + parameter_declaration, + "parameter e = 25, f = 9 ", + Ok((_, ParameterDeclaration::Param(_))) + ); + test!( + parameter_declaration, + "parameter byte_size = 8, byte_mask = byte_size - 1", + Ok((_, ParameterDeclaration::Param(_))) + ); + test!( + parameter_declaration, + "parameter signed [3:0] mux_selector = 0", + Ok((_, ParameterDeclaration::Param(_))) + ); + test!( + parameter_declaration, + "parameter real r1 = 3.5e17", + Ok((_, ParameterDeclaration::Param(_))) + ); + test!( + parameter_declaration, + "parameter logic [31:0] P1 [3:0] = '{ 1, 2, 3, 4 } ", + Ok((_, ParameterDeclaration::Param(_))) + ); + test!( + parameter_declaration, + "parameter r2 = $ ", + Ok((_, ParameterDeclaration::Param(_))) + ); + test!( + parameter_declaration, + "parameter type p2 = shortint ", + Ok((_, ParameterDeclaration::Type(_))) + ); +} + +#[test] +fn test_specparam_declaration() { + test!(specparam_declaration, "specparam delay = 10 ; ", Ok((_, _))); + test!( + specparam_declaration, + "specparam tRise_clk_q = 150, tFall_clk_q = 200;", + Ok((_, _)) + ); +} + +#[test] +fn test_inout_declaration() { + test!(inout_declaration, "inout a", Ok((_, _))); + test!(inout_declaration, "inout [7:0] a", Ok((_, _))); + test!(inout_declaration, "inout signed [7:0] a", Ok((_, _))); +} + +#[test] +fn test_net_type_declaration() { + test!( + net_type_declaration, + "nettype T wT;", + Ok((_, NetTypeDeclaration::DataType(_))) + ); + test!( + net_type_declaration, + "nettype T wTsum with Tsum;", + Ok((_, NetTypeDeclaration::DataType(_))) + ); + test!( + net_type_declaration, + "nettype MyBaseT::T narrowTsum with MyBaseT::Tsum;", + Ok((_, NetTypeDeclaration::DataType(_))) + ); +} + +#[test] +fn test_net_declaration() { + test!( + net_declaration, + "trireg (large) logic #(0,0,0) cap1;", + Ok((_, NetDeclaration::NetType(_))) + ); + test!( + net_declaration, + "wire addressT w1;", + Ok((_, NetDeclaration::NetType(_))) + ); + test!( + net_declaration, + "wire struct packed { logic ecc; logic [7:0] data; } memsig;", + Ok((_, NetDeclaration::NetType(_))) + ); + test!( + net_declaration, + "wire w;", + Ok((_, NetDeclaration::NetType(_))) + ); + test!( + net_declaration, + "wire [15:0] w;", + Ok((_, NetDeclaration::NetType(_))) + ); + test!( + net_declaration, + "interconnect w1;", + Ok((_, NetDeclaration::Interconnect(_))) + ); + test!( + net_declaration, + "interconnect [3:0] w2;", + Ok((_, NetDeclaration::Interconnect(_))) + ); + test!( + net_declaration, + "interconnect [3:0] w3 [1:0];", + Ok((_, NetDeclaration::Interconnect(_))) + ); + test!(net_declaration, "interconnect logic [3:0] w4;", Err(_)); + test!(net_declaration, "interconnect #(1,2,3) w5;", Err(_)); + test!( + net_declaration, + "wand w;", + Ok((_, NetDeclaration::NetType(_))) + ); + test!( + net_declaration, + "tri [15:0] busa;", + Ok((_, NetDeclaration::NetType(_))) + ); + test!( + net_declaration, + "trireg (small) storeit;", + Ok((_, NetDeclaration::NetType(_))) + ); + test!( + net_declaration, + "wire w1, w2;", + Ok((_, NetDeclaration::NetType(_))) + ); + test!( + net_declaration, + "tri1 scalared [63:0] bus64;", + Ok((_, NetDeclaration::NetType(_))) + ); + test!( + net_declaration, + "tri vectored [31:0] data;", + Ok((_, NetDeclaration::NetType(_))) + ); +} + +#[test] +fn test_data_declaration() { + test!( + data_declaration, + "shortint s1, s2[0:9];", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "var byte my_byte;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "var v;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "var [15:0] vw;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "var enum bit { clear, error } status;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "var reg r;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "int i = 0;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "logic a;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "logic[3:0] v;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "logic signed [3:0] signed_reg;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "logic [-1:4] b;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "logic [4:0] x, y, z;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "int unsigned ui;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "int signed si;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "string myName = default_name;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "byte c = \"A\";", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "bit [10:0] b = \"x41\";", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "bit [1:4][7:0] h = \"hello\" ;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "event done;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "event done_too = done;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "event empty = null;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "typedef int intP;", + Ok((_, DataDeclaration::TypeDeclaration(_))) + ); + test!( + data_declaration, + "intP a, b;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "typedef enum type_identifier;", + Ok((_, DataDeclaration::TypeDeclaration(_))) + ); + test!( + data_declaration, + "typedef struct type_identifier;", + Ok((_, DataDeclaration::TypeDeclaration(_))) + ); + test!( + data_declaration, + "typedef union type_identifier;", + Ok((_, DataDeclaration::TypeDeclaration(_))) + ); + test!( + data_declaration, + "typedef class type_identifier;", + Ok((_, DataDeclaration::TypeDeclaration(_))) + ); + test!( + data_declaration, + "typedef interface class type_identifier;", + Ok((_, DataDeclaration::TypeDeclaration(_))) + ); + test!( + data_declaration, + "typedef type_identifier;", + Ok((_, DataDeclaration::TypeDeclaration(_))) + ); + test!( + data_declaration, + "typedef C::T c_t;", + Ok((_, DataDeclaration::TypeDeclaration(_))) + ); + test!( + data_declaration, + "enum {red, yellow, green} light1, light2;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "enum bit [1:0] {IDLE, XX='x, S1=2'b01, S2=2'b10} state, next;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "enum integer {IDLE, XX='x, S1='b01, S2='b10} state, next;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "enum integer {IDLE, XX='x, S1='b01, S2='b10} state, next;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "enum {bronze=3, silver, gold} medal;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "enum {a=3, b=7, c} alphabet;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "enum bit [3:0] {bronze='h3, silver, gold='h5} medal2;", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "integer i_array[*];", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "bit [20:0] array_b[string];", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "event ev_array[myClass];", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "int array_name [*];", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "int array_name1 [ integer ];", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "int a[int] = '{default:1};", + Ok((_, DataDeclaration::Variable(_))) + ); + test!( + data_declaration, + "byte q1[$];", + Ok((_, DataDeclaration::Variable(_))) + ); +} + +#[test] +fn test_drive_strength() { + test!(drive_strength, "(supply0, strong1)", Ok((_, _))); + test!(drive_strength, "(pull1, weak0)", Ok((_, _))); + test!(drive_strength, "(pull0, highz1)", Ok((_, _))); + test!(drive_strength, "(weak1, highz0)", Ok((_, _))); + test!(drive_strength, "(highz0, supply1)", Ok((_, _))); + test!(drive_strength, "(highz1, strong0)", Ok((_, _))); +} + +#[test] +fn test_charge_strength() { + test!(charge_strength, "( small)", Ok((_, _))); + test!(charge_strength, "( medium )", Ok((_, _))); + test!(charge_strength, "(large)", Ok((_, _))); +} + +#[test] +fn test_blocking_assignment() { + test!( + blocking_assignment, + "idest = new [3] (isrc)", + Ok((_, BlockingAssignment::NonrangeVariable(_))) + ); +} + +#[test] +fn test_primary() { + test!(primary, "2.1ns ", Ok((_, Primary::PrimaryLiteral(_)))); + test!(primary, "40 ps ", Ok((_, Primary::PrimaryLiteral(_)))); + test!(primary, "'0", Ok((_, Primary::PrimaryLiteral(_)))); + test!(primary, "10", Ok((_, Primary::PrimaryLiteral(_)))); + test!(primary, "\"aaa\"", Ok((_, Primary::PrimaryLiteral(_)))); + test!(primary, "this ", Ok((_, Primary::This(_)))); + test!(primary, "$", Ok((_, Primary::Dollar(_)))); + test!(primary, "null ", Ok((_, Primary::Null(_)))); +} + +#[test] +fn test_cast() { + test!(cast, "int'(2.0 * 3.0)", Ok((_, _))); + test!(cast, "shortint'({8'hFA,8'hCE}) ", Ok((_, _))); + test!(cast, "signed'(x)", Ok((_, _))); + test!(cast, "const'(x)", Ok((_, _))); + test!(cast, "type_t'(x)", Ok((_, _))); +} + +#[test] +fn test_number() { + test!(number, "659", Ok((_, Number::IntegralNumber(_)))); + test!(number, "'h 837FF", Ok((_, Number::IntegralNumber(_)))); + test!(number, "'h 837FF", Ok((_, Number::IntegralNumber(_)))); + test!(number, "'o7460", Ok((_, Number::IntegralNumber(_)))); + test!(number, "'4af", Err(_)); + test!(number, "4'b1001", Ok((_, Number::IntegralNumber(_)))); + test!(number, "5 'D 3", Ok((_, Number::IntegralNumber(_)))); + test!(number, "3'b01x", Ok((_, Number::IntegralNumber(_)))); + test!(number, "12'hx", Ok((_, Number::IntegralNumber(_)))); + test!(number, "16'hz", Ok((_, Number::IntegralNumber(_)))); + test!(number, "8 'd -6", Err(_)); + test!(number, "4 'shf", Ok((_, Number::IntegralNumber(_)))); + test!(number, "16'sd?", Ok((_, Number::IntegralNumber(_)))); + test!(number, "27_195_000", Ok((_, Number::IntegralNumber(_)))); + test!( + number, + "16'b0011_0101_0001_1111", + Ok((_, Number::IntegralNumber(_))) + ); + test!( + number, + "32 'h 12ab_f001", + Ok((_, Number::IntegralNumber(_))) + ); + test!(number, "1.2", Ok((_, Number::RealNumber(_)))); + test!(number, "0.1", Ok((_, Number::RealNumber(_)))); + test!(number, "2394.26331", Ok((_, Number::RealNumber(_)))); + test!(number, "1.2E12", Ok((_, Number::RealNumber(_)))); + test!(number, "1.30e-2", Ok((_, Number::RealNumber(_)))); + test!(number, "0.1e-0", Ok((_, Number::RealNumber(_)))); + test!(number, "23E10", Ok((_, Number::RealNumber(_)))); + test!(number, "29E-2", Ok((_, Number::RealNumber(_)))); + test!(number, "236.123_763_e-12", Ok((_, Number::RealNumber(_)))); + test!(number, ".12", Err(_)); + test!(number, "9.", Err(_)); + test!(number, "4.E3", Err(_)); + test!(number, ".2e-7", Err(_)); +} + +#[test] +fn test_unbased_unsized_literal() { + test!(unbased_unsized_literal, "'0", Ok((_, _))); + test!(unbased_unsized_literal, "'1", Ok((_, _))); + test!(unbased_unsized_literal, "'x", Ok((_, _))); + test!(unbased_unsized_literal, "'z", Ok((_, _))); +} + +#[test] +fn test_net_lvalue() { + test!(net_lvalue, "A", Ok((_, _))); + test!(net_lvalue, "{A[7:0],A[15:8],A[23:16]}", Ok((_, _))); + test!(net_lvalue, "'{A[7:0],A[15:8]}", Ok((_, _))); +} + +#[test] +fn test_variable_lvalue() { + test!(variable_lvalue, "A", Ok((_, _))); + test!(variable_lvalue, "{A[7:0],A[15:8],A[23:16]}", Ok((_, _))); + test!(variable_lvalue, "'{A[7:0],A[15:8]}", Ok((_, _))); +} + +#[test] +fn test_nonrange_variable_lvalue() { + test!(nonrange_variable_lvalue, "A", Ok((_, _))); + test!(nonrange_variable_lvalue, "A[1][2][3]", Ok((_, _))); + //TODO + //test!(nonrange_variable_lvalue, "A[][2][3]", Ok((_, _))); + //test!(nonrange_variable_lvalue, "A[][]", Ok((_, _))); +} + +#[test] +fn test_unary_operator() { + test!(unary_operator, "+", Ok((_, _))); + test!(unary_operator, "-", Ok((_, _))); + test!(unary_operator, "!", Ok((_, _))); + test!(unary_operator, "&", Ok((_, _))); + test!(unary_operator, "|", Ok((_, _))); + test!(unary_operator, "~&", Ok((_, _))); + test!(unary_operator, "~|", Ok((_, _))); + test!(unary_operator, "~^", Ok((_, _))); + test!(unary_operator, "^~", Ok((_, _))); + test!(unary_operator, "^", Ok((_, _))); + test!(unary_operator, "~", Ok((_, _))); +} + +#[test] +fn test_binary_operator() { + test!(binary_operator, "+", Ok((_, _))); + test!(binary_operator, "-", Ok((_, _))); + test!(binary_operator, "**", Ok((_, _))); + test!(binary_operator, "*", Ok((_, _))); + test!(binary_operator, "/", Ok((_, _))); + test!(binary_operator, "%", Ok((_, _))); + test!(binary_operator, "===", Ok((_, _))); + test!(binary_operator, "==?", Ok((_, _))); + test!(binary_operator, "==", Ok((_, _))); + test!(binary_operator, "!==", Ok((_, _))); + test!(binary_operator, "!=?", Ok((_, _))); + test!(binary_operator, "!=", Ok((_, _))); + test!(binary_operator, "&&", Ok((_, _))); + test!(binary_operator, "||", Ok((_, _))); + test!(binary_operator, "&", Ok((_, _))); + test!(binary_operator, "|", Ok((_, _))); + test!(binary_operator, "^~", Ok((_, _))); + test!(binary_operator, "^", Ok((_, _))); + test!(binary_operator, "~^", Ok((_, _))); + test!(binary_operator, ">>>", Ok((_, _))); + test!(binary_operator, ">>", Ok((_, _))); + test!(binary_operator, "<<<", Ok((_, _))); + test!(binary_operator, "<<", Ok((_, _))); + test!(binary_operator, "->", Ok((_, _))); + test!(binary_operator, "<->", Ok((_, _))); + test!(binary_operator, "<=", Ok((_, _))); + test!(binary_operator, "<", Ok((_, _))); + test!(binary_operator, ">=", Ok((_, _))); + test!(binary_operator, ">", Ok((_, _))); +} + +#[test] +fn test_inc_or_dec_operator() { + test!(inc_or_dec_operator, "++", Ok((_, _))); + test!(inc_or_dec_operator, "--", Ok((_, _))); +} + +#[test] +fn test_unary_module_path_operator() { + test!(unary_module_path_operator, "!", Ok((_, _))); + test!(unary_module_path_operator, "&", Ok((_, _))); + test!(unary_module_path_operator, "|", Ok((_, _))); + test!(unary_module_path_operator, "~&", Ok((_, _))); + test!(unary_module_path_operator, "~|", Ok((_, _))); + test!(unary_module_path_operator, "~^", Ok((_, _))); + test!(unary_module_path_operator, "^~", Ok((_, _))); + test!(unary_module_path_operator, "^", Ok((_, _))); + test!(unary_module_path_operator, "~", Ok((_, _))); +} + +#[test] +fn test_binary_module_path_operator() { + test!(binary_module_path_operator, "==", Ok((_, _))); + test!(binary_module_path_operator, "!=", Ok((_, _))); + test!(binary_module_path_operator, "&&", Ok((_, _))); + test!(binary_module_path_operator, "||", Ok((_, _))); + test!(binary_module_path_operator, "&", Ok((_, _))); + test!(binary_module_path_operator, "|", Ok((_, _))); + test!(binary_module_path_operator, "^~", Ok((_, _))); + test!(binary_module_path_operator, "^", Ok((_, _))); + test!(binary_module_path_operator, "~^", Ok((_, _))); +} + +#[test] +fn test_string_literal() { + test!(string_literal, "\"aaa aaaa\"", Ok((_, _))); + test!(string_literal, r#""aaa\" aaaa""#, Ok((_, _))); + test!(string_literal, r#""aaa\"""#, Ok((_, _))); +} + +#[test] +fn test_identifier() { + test!( + identifier, + "shiftreg_a", + Ok((_, Identifier::SimpleIdentifier(_))) + ); + test!( + identifier, + "_bus3", + Ok((_, Identifier::SimpleIdentifier(_))) + ); + test!( + identifier, + "n$657", + Ok((_, Identifier::SimpleIdentifier(_))) + ); + test!( + identifier, + "\\busa+index", + Ok((_, Identifier::EscapedIdentifier(_))) + ); + test!( + identifier, + "\\-clock", + Ok((_, Identifier::EscapedIdentifier(_))) + ); +} + +#[test] +fn test_system_tf_identifier() { + test!(system_tf_identifier, "$display", Ok((_, _))); +} + +#[test] +fn test_comment() { + test!(comment, "// comment", Ok((_, _))); + test!(comment, "/* comment\n\n */", Ok((_, _))); +} + +#[test] +fn test_attribute_instance() { + test!( + attribute_instance, + "(* full_case, parallel_case *)", + Ok((_, _)) + ); + test!(attribute_instance, "(* full_case=1 *)", Ok((_, _))); + test!( + attribute_instance, + "(* full_case=1, parallel_case = 0 *)", + Ok((_, _)) + ); +} diff --git a/sv-parser-parser/src/udp_declaration_and_instantiation/mod.rs b/sv-parser-parser/src/udp_declaration_and_instantiation/mod.rs new file mode 100644 index 0000000..bf15873 --- /dev/null +++ b/sv-parser-parser/src/udp_declaration_and_instantiation/mod.rs @@ -0,0 +1,8 @@ +pub mod udp_body; +pub mod udp_declaration; +pub mod udp_instantiation; +pub mod udp_ports; +pub(crate) use udp_body::*; +pub(crate) use udp_declaration::*; +pub(crate) use udp_instantiation::*; +pub(crate) use udp_ports::*; diff --git a/sv-parser/src/parser/udp_declaration_and_instantiation/udp_body.rs b/sv-parser-parser/src/udp_declaration_and_instantiation/udp_body.rs similarity index 71% rename from sv-parser/src/parser/udp_declaration_and_instantiation/udp_body.rs rename to sv-parser-parser/src/udp_declaration_and_instantiation/udp_body.rs index fc90690..bb689ed 100644 --- a/sv-parser/src/parser/udp_declaration_and_instantiation/udp_body.rs +++ b/sv-parser-parser/src/udp_declaration_and_instantiation/udp_body.rs @@ -1,119 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum UdpBody { - CombinationalBody(Box), - SequentialBody(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct CombinationalBody { - pub nodes: ( - Keyword, - CombinationalEntry, - Vec, - Keyword, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct CombinationalEntry { - pub nodes: (LevelInputList, Symbol, OutputSymbol, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct SequentialBody { - pub nodes: ( - Option, - Keyword, - SequentialEntry, - Vec, - Keyword, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct UdpInitialStatement { - pub nodes: (Keyword, OutputPortIdentifier, Symbol, InitVal, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct InitVal { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct SequentialEntry { - pub nodes: ( - SeqInputList, - Symbol, - CurrentState, - Symbol, - NextState, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum SeqInputList { - LevelInputList(Box), - EdgeInputList(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct LevelInputList { - pub nodes: (LevelSymbol, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct EdgeInputList { - pub nodes: (Vec, EdgeIndicator, Vec), -} - -#[derive(Clone, Debug, Node)] -pub enum EdgeIndicator { - Paren(Box), - EdgeSymbol(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct EdgeIndicatorParen { - pub nodes: (Paren<(LevelSymbol, LevelSymbol)>,), -} - -#[derive(Clone, Debug, Node)] -pub struct CurrentState { - pub nodes: (LevelSymbol,), -} - -#[derive(Clone, Debug, Node)] -pub enum NextState { - OutputSymbol(Box), - Minus(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct OutputSymbol { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct LevelSymbol { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct EdgeSymbol { - pub nodes: (Keyword,), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/udp_declaration_and_instantiation/udp_declaration.rs b/sv-parser-parser/src/udp_declaration_and_instantiation/udp_declaration.rs similarity index 63% rename from sv-parser/src/parser/udp_declaration_and_instantiation/udp_declaration.rs rename to sv-parser-parser/src/udp_declaration_and_instantiation/udp_declaration.rs index 366242c..61c2970 100644 --- a/sv-parser/src/parser/udp_declaration_and_instantiation/udp_declaration.rs +++ b/sv-parser-parser/src/udp_declaration_and_instantiation/udp_declaration.rs @@ -1,90 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct UdpNonansiDeclaration { - pub nodes: ( - Vec, - Keyword, - UdpIdentifier, - Paren, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct UdpAnsiDeclaration { - pub nodes: ( - Vec, - Keyword, - UdpIdentifier, - Paren, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum UdpDeclaration { - Nonansi(Box), - Ansi(Box), - ExternNonansi(Box), - ExternAnsi(Box), - Wildcard(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct UdpDeclarationNonansi { - pub nodes: ( - UdpNonansiDeclaration, - UdpPortDeclaration, - Vec, - UdpBody, - Keyword, - Option<(Symbol, UdpIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct UdpDeclarationAnsi { - pub nodes: ( - UdpAnsiDeclaration, - UdpBody, - Keyword, - Option<(Symbol, UdpIdentifier)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct UdpDeclarationExternNonansi { - pub nodes: (Keyword, UdpNonansiDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct UdpDeclarationExternAnsi { - pub nodes: (Keyword, UdpAnsiDeclaration), -} - -#[derive(Clone, Debug, Node)] -pub struct UdpDeclarationWildcard { - pub nodes: ( - Vec, - Keyword, - UdpIdentifier, - Paren, - Symbol, - Vec, - UdpBody, - Keyword, - Option<(Symbol, UdpIdentifier)>, - ), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/udp_declaration_and_instantiation/udp_instantiation.rs b/sv-parser-parser/src/udp_declaration_and_instantiation/udp_instantiation.rs similarity index 54% rename from sv-parser/src/parser/udp_declaration_and_instantiation/udp_instantiation.rs rename to sv-parser-parser/src/udp_declaration_and_instantiation/udp_instantiation.rs index 8d91dcc..41263af 100644 --- a/sv-parser/src/parser/udp_declaration_and_instantiation/udp_instantiation.rs +++ b/sv-parser-parser/src/udp_declaration_and_instantiation/udp_instantiation.rs @@ -1,35 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct UdpInstantiation { - pub nodes: ( - UdpIdentifier, - Option, - Option, - List, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct UdpInstance { - pub nodes: ( - Option, - Paren<( - OutputTerminal, - Symbol, - InputTerminal, - Vec<(Symbol, InputTerminal)>, - )>, - ), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/udp_declaration_and_instantiation/udp_ports.rs b/sv-parser-parser/src/udp_declaration_and_instantiation/udp_ports.rs similarity index 62% rename from sv-parser/src/parser/udp_declaration_and_instantiation/udp_ports.rs rename to sv-parser-parser/src/udp_declaration_and_instantiation/udp_ports.rs index 8a8f891..aeaca23 100644 --- a/sv-parser/src/parser/udp_declaration_and_instantiation/udp_ports.rs +++ b/sv-parser-parser/src/udp_declaration_and_instantiation/udp_ports.rs @@ -1,69 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct UdpPortList { - pub nodes: ( - OutputPortIdentifier, - Symbol, - List, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct UdpDeclarationPortList { - pub nodes: ( - UdpOutputDeclaration, - Symbol, - List, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum UdpPortDeclaration { - UdpOutputDeclaration(Box<(UdpOutputDeclaration, Symbol)>), - UdpInputDeclaration(Box<(UdpInputDeclaration, Symbol)>), - UdpRegDeclaration(Box<(UdpRegDeclaration, Symbol)>), -} - -#[derive(Clone, Debug, Node)] -pub enum UdpOutputDeclaration { - Nonreg(Box), - Reg(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct UdpOutputDeclarationNonreg { - pub nodes: (Vec, Keyword, PortIdentifier), -} - -#[derive(Clone, Debug, Node)] -pub struct UdpOutputDeclarationReg { - pub nodes: ( - Vec, - Keyword, - Keyword, - PortIdentifier, - Option<(Symbol, ConstantExpression)>, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct UdpInputDeclaration { - pub nodes: (Vec, Keyword, ListOfUdpPortIdentifiers), -} - -#[derive(Clone, Debug, Node)] -pub struct UdpRegDeclaration { - pub nodes: (Vec, Keyword, VariableIdentifier), -} +use crate::*; // ----------------------------------------------------------------------------- diff --git a/sv-parser/src/parser/utils.rs b/sv-parser-parser/src/utils.rs similarity index 88% rename from sv-parser/src/parser/utils.rs rename to sv-parser-parser/src/utils.rs index 2ec0f8d..2b01075 100644 --- a/sv-parser/src/parser/utils.rs +++ b/sv-parser-parser/src/utils.rs @@ -1,12 +1,4 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::bytes::complete::*; -use nom::character::complete::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; +use crate::*; // ----------------------------------------------------------------------------- @@ -261,47 +253,6 @@ const KEYWORDS: &[&str] = &[ "xor", ]; -#[derive(Clone, Debug, Node)] -pub struct Symbol { - pub nodes: (Locate, Vec), -} - -#[derive(Clone, Debug, Node)] -pub struct Keyword { - pub nodes: (Locate, Vec), -} - -#[derive(Clone, Debug, Node)] -pub enum WhiteSpace { - Space(Box), - Comment(Box), -} - -#[derive(Clone, Debug)] -pub struct Paren { - pub nodes: (Symbol, T, Symbol), -} - -#[derive(Clone, Debug)] -pub struct Brace { - pub nodes: (Symbol, T, Symbol), -} - -#[derive(Clone, Debug)] -pub struct Bracket { - pub nodes: (Symbol, T, Symbol), -} - -#[derive(Clone, Debug)] -pub struct ApostropheBrace { - pub nodes: (Symbol, T, Symbol), -} - -#[derive(Clone, Debug)] -pub struct List { - pub nodes: (U, Vec<(T, U)>), -} - // ----------------------------------------------------------------------------- pub(crate) fn ws<'a, O, F>(f: F) -> impl Fn(Span<'a>) -> IResult, (O, Vec)> @@ -543,16 +494,3 @@ pub(crate) fn trace<'a>(mut s: Span<'a>, name: &str) -> Span<'a> { s.extra.depth += 1; s } - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -macro_rules! parser_test { - ( $x:expr, $y:expr, $z:pat ) => { - let ret = all_consuming($x)(Span::new_extra($y, Extra::default())); - if let $z = ret { - } else { - assert!(false, "{:?}", ret) - } - }; -} diff --git a/sv-parser-syntaxtree/Cargo.toml b/sv-parser-syntaxtree/Cargo.toml new file mode 100644 index 0000000..238cb71 --- /dev/null +++ b/sv-parser-syntaxtree/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "sv-parser-syntaxtree" +version = "0.1.0" +authors = ["dalance "] +edition = "2018" +build = "build.rs" + +[dependencies] +sv-parser-macros = { path = "../sv-parser-macros" } +nom_locate = { path = "../../nom_locate" } + +[build-dependencies] +walkdir = "2" +regex = "1" diff --git a/sv-parser/build.rs b/sv-parser-syntaxtree/build.rs similarity index 97% rename from sv-parser/build.rs rename to sv-parser-syntaxtree/build.rs index 008c6b0..f003fb0 100644 --- a/sv-parser/build.rs +++ b/sv-parser-syntaxtree/build.rs @@ -22,7 +22,7 @@ fn main() { let re_node = Regex::new(r"#\[derive.*Node.*\]").unwrap(); - for entry in WalkDir::new("src/parser") { + for entry in WalkDir::new("src") { let entry = entry.unwrap(); if entry.file_type().is_file() { let f = File::open(entry.path()).unwrap(); diff --git a/sv-parser/src/ast/any_node.rs b/sv-parser-syntaxtree/src/any_node.rs similarity index 99% rename from sv-parser/src/ast/any_node.rs rename to sv-parser-syntaxtree/src/any_node.rs index 0b80c99..d604581 100644 --- a/sv-parser/src/ast/any_node.rs +++ b/sv-parser-syntaxtree/src/any_node.rs @@ -1,12 +1,11 @@ -use crate::ast::*; -use crate::parser::*; +use crate::*; use core::convert::TryFrom; // ----------------------------------------------------------------------------- include!(concat!(env!("OUT_DIR"), "/any_node.rs")); -pub(crate) struct RefNodes<'a>(pub Vec>); +pub struct RefNodes<'a>(pub Vec>); // ----------------------------------------------------------------------------- diff --git a/sv-parser-syntaxtree/src/behavioral_statements/assertion_statements.rs b/sv-parser-syntaxtree/src/behavioral_statements/assertion_statements.rs new file mode 100644 index 0000000..b6c76c6 --- /dev/null +++ b/sv-parser-syntaxtree/src/behavioral_statements/assertion_statements.rs @@ -0,0 +1,80 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum AssertionItem { + Concurrent(Box), + Immediate(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct DeferredImmediateAssetionItem { + pub nodes: ( + Option<(BlockIdentifier, Symbol)>, + DeferredImmediateAssertionStatement, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ProceduralAssertionStatement { + Concurrent(Box), + Immediate(Box), + Checker(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum ImmediateAssetionStatement { + Simple(Box), + Deferred(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum SimpleImmediateAssertionStatement { + Assert(Box), + Assume(Box), + Cover(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct SimpleImmediateAssertStatement { + pub nodes: (Keyword, Paren, ActionBlock), +} + +#[derive(Clone, Debug, Node)] +pub struct SimpleImmediateAssumeStatement { + pub nodes: (Keyword, Paren, ActionBlock), +} + +#[derive(Clone, Debug, Node)] +pub struct SimpleImmediateCoverStatement { + pub nodes: (Keyword, Paren, StatementOrNull), +} + +#[derive(Clone, Debug, Node)] +pub enum DeferredImmediateAssertionStatement { + Assert(Box), + Assume(Box), + Cover(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct DeferredImmediateAssertStatement { + pub nodes: (Keyword, AssertTiming, Paren, ActionBlock), +} + +#[derive(Clone, Debug, Node)] +pub struct DeferredImmediateAssumeStatement { + pub nodes: (Keyword, AssertTiming, Paren, ActionBlock), +} + +#[derive(Clone, Debug, Node)] +pub struct DeferredImmediateCoverStatement { + pub nodes: (Keyword, AssertTiming, Paren, StatementOrNull), +} + +#[derive(Clone, Debug, Node)] +pub enum AssertTiming { + Zero(Box), + Final(Box), +} diff --git a/sv-parser-syntaxtree/src/behavioral_statements/case_statements.rs b/sv-parser-syntaxtree/src/behavioral_statements/case_statements.rs new file mode 100644 index 0000000..b3a6061 --- /dev/null +++ b/sv-parser-syntaxtree/src/behavioral_statements/case_statements.rs @@ -0,0 +1,128 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum CaseStatement { + Normal(Box), + Matches(Box), + Inside(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CaseStatementNormal { + pub nodes: ( + Option, + CaseKeyword, + Paren, + CaseItem, + Vec, + Keyword, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct CaseStatementMatches { + pub nodes: ( + Option, + CaseKeyword, + Paren, + Keyword, + CasePatternItem, + Vec, + Keyword, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct CaseStatementInside { + pub nodes: ( + Option, + Keyword, + Paren, + Keyword, + CaseInsideItem, + Vec, + Keyword, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum CaseKeyword { + Case(Box), + Casez(Box), + Casex(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CaseExpression { + pub nodes: (Expression,), +} + +#[derive(Clone, Debug, Node)] +pub enum CaseItem { + NonDefault(Box), + Default(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CaseItemNondefault { + pub nodes: (List, Symbol, StatementOrNull), +} + +#[derive(Clone, Debug, Node)] +pub struct CaseItemDefault { + pub nodes: (Keyword, Option, StatementOrNull), +} + +#[derive(Clone, Debug, Node)] +pub enum CasePatternItem { + NonDefault(Box), + Default(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CasePatternItemNondefault { + pub nodes: ( + Pattern, + Option<(Symbol, Expression)>, + Symbol, + StatementOrNull, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum CaseInsideItem { + NonDefault(Box), + Default(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CaseInsideItemNondefault { + pub nodes: (OpenRangeList, Symbol, StatementOrNull), +} + +#[derive(Clone, Debug, Node)] +pub struct CaseItemExpression { + pub nodes: (Expression,), +} + +#[derive(Clone, Debug, Node)] +pub struct RandcaseStatement { + pub nodes: (Keyword, RandcaseItem, Vec, Keyword), +} + +#[derive(Clone, Debug, Node)] +pub struct RandcaseItem { + pub nodes: (Expression, Symbol, StatementOrNull), +} + +#[derive(Clone, Debug, Node)] +pub struct OpenRangeList { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct OpenValueRange { + pub nodes: (ValueRange,), +} diff --git a/sv-parser-syntaxtree/src/behavioral_statements/clocking_block.rs b/sv-parser-syntaxtree/src/behavioral_statements/clocking_block.rs new file mode 100644 index 0000000..1ee508e --- /dev/null +++ b/sv-parser-syntaxtree/src/behavioral_statements/clocking_block.rs @@ -0,0 +1,182 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum ClockingDeclaration { + Local(Box), + Global(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ClockingDeclarationLocal { + pub nodes: ( + Option, + Keyword, + Option, + ClockingEvent, + Symbol, + Vec, + Keyword, + Option<(Symbol, ClockingIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct Default { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct ClockingDeclarationGlobal { + pub nodes: ( + Keyword, + Keyword, + Option, + ClockingEvent, + Symbol, + Keyword, + Option<(Symbol, ClockingIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ClockingEvent { + Identifier(Box), + Expression(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ClockingEventIdentifier { + pub nodes: (Symbol, Identifier), +} + +#[derive(Clone, Debug, Node)] +pub struct ClockingEventExpression { + pub nodes: (Symbol, Paren), +} + +#[derive(Clone, Debug, Node)] +pub enum ClockingItem { + Default(Box), + Direction(Box), + Assertion(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ClockingItemDefault { + pub nodes: (Keyword, DefaultSkew, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct ClockingItemDirection { + pub nodes: (ClockingDirection, ListOfClockingDeclAssign, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct ClockingItemAssertion { + pub nodes: (Vec, AssertionItemDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub enum DefaultSkew { + Input(Box), + Output(Box), + InputOutput(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct DefaultSkewInput { + pub nodes: (Keyword, ClockingSkew), +} + +#[derive(Clone, Debug, Node)] +pub struct DefaultSkewOutput { + pub nodes: (Keyword, ClockingSkew), +} + +#[derive(Clone, Debug, Node)] +pub struct DefaultSkewInputOutput { + pub nodes: (Keyword, ClockingSkew, Keyword, ClockingSkew), +} + +#[derive(Clone, Debug, Node)] +pub enum ClockingDirection { + Input(Box), + Output(Box), + InputOutput(Box), + Inout(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ClockingDirectionInput { + pub nodes: (Keyword, Option), +} + +#[derive(Clone, Debug, Node)] +pub struct ClockingDirectionOutput { + pub nodes: (Keyword, Option), +} + +#[derive(Clone, Debug, Node)] +pub struct ClockingDirectionInputOutput { + pub nodes: (Keyword, Option, Keyword, Option), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfClockingDeclAssign { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct ClockingDeclAssign { + pub nodes: (SignalIdentifier, Option<(Symbol, Expression)>), +} + +#[derive(Clone, Debug, Node)] +pub enum ClockingSkew { + Edge(Box), + DelayControl(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ClockingSkewEdge { + pub nodes: (EdgeIdentifier, Option), +} + +#[derive(Clone, Debug, Node)] +pub struct ClockingDrive { + pub nodes: (ClockvarExpression, Symbol, Option, Expression), +} + +#[derive(Clone, Debug, Node)] +pub enum CycleDelay { + Integral(Box), + Identifier(Box), + Expression(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CycleDelayIntegral { + pub nodes: (Symbol, IntegralNumber), +} + +#[derive(Clone, Debug, Node)] +pub struct CycleDelayIdentifier { + pub nodes: (Symbol, Identifier), +} + +#[derive(Clone, Debug, Node)] +pub struct CycleDelayExpression { + pub nodes: (Symbol, Paren), +} + +#[derive(Clone, Debug, Node)] +pub struct Clockvar { + pub nodes: (HierarchicalIdentifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct ClockvarExpression { + pub nodes: (Clockvar, Select), +} diff --git a/sv-parser-syntaxtree/src/behavioral_statements/conditional_statements.rs b/sv-parser-syntaxtree/src/behavioral_statements/conditional_statements.rs new file mode 100644 index 0000000..0968d2e --- /dev/null +++ b/sv-parser-syntaxtree/src/behavioral_statements/conditional_statements.rs @@ -0,0 +1,38 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct ConditionalStatement { + pub nodes: ( + Option, + Keyword, + Paren, + StatementOrNull, + Vec<(Keyword, Keyword, Paren, StatementOrNull)>, + Option<(Keyword, StatementOrNull)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum UniquePriority { + Unique(Box), + Unique0(Box), + Priority(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CondPredicate { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub enum ExpressionOrCondPattern { + Expression(Box), + CondPattern(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CondPattern { + pub nodes: (Expression, Keyword, Pattern), +} diff --git a/sv-parser-syntaxtree/src/behavioral_statements/continuous_assignment_and_net_alias_statements.rs b/sv-parser-syntaxtree/src/behavioral_statements/continuous_assignment_and_net_alias_statements.rs new file mode 100644 index 0000000..064ffcd --- /dev/null +++ b/sv-parser-syntaxtree/src/behavioral_statements/continuous_assignment_and_net_alias_statements.rs @@ -0,0 +1,50 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum ContinuousAssign { + Net(Box), + Variable(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ContinuousAssignNet { + pub nodes: ( + Keyword, + Option, + Option, + ListOfNetAssignments, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ContinuousAssignVariable { + pub nodes: ( + Keyword, + Option, + ListOfVariableAssignments, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfNetAssignments { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfVariableAssignments { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct NetAlias { + pub nodes: (Keyword, NetLvalue, Symbol, List, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct NetAssignment { + pub nodes: (NetLvalue, Symbol, Expression), +} diff --git a/sv-parser-syntaxtree/src/behavioral_statements/looping_statements.rs b/sv-parser-syntaxtree/src/behavioral_statements/looping_statements.rs new file mode 100644 index 0000000..f405df3 --- /dev/null +++ b/sv-parser-syntaxtree/src/behavioral_statements/looping_statements.rs @@ -0,0 +1,99 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum LoopStatement { + Forever(Box), + Repeat(Box), + While(Box), + For(Box), + DoWhile(Box), + Foreach(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct LoopStatementForever { + pub nodes: (Keyword, StatementOrNull), +} + +#[derive(Clone, Debug, Node)] +pub struct LoopStatementRepeat { + pub nodes: (Keyword, Paren, StatementOrNull), +} + +#[derive(Clone, Debug, Node)] +pub struct LoopStatementWhile { + pub nodes: (Keyword, Paren, StatementOrNull), +} + +#[derive(Clone, Debug, Node)] +pub struct LoopStatementFor { + pub nodes: ( + Keyword, + Paren<( + Option, + Symbol, + Option, + Symbol, + Option, + )>, + StatementOrNull, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct LoopStatementDoWhile { + pub nodes: (Keyword, StatementOrNull, Keyword, Paren, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct LoopStatementForeach { + pub nodes: ( + Keyword, + Paren<(PsOrHierarchicalArrayIdentifier, Bracket)>, + Statement, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ForInitialization { + ListOfVariableAssignments(Box), + Declaration(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ForInitializationDeclaration { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct ForVariableDeclaration { + pub nodes: ( + Option, + DataType, + List, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct Var { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct ForStep { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub enum ForStepAssignment { + OperatorAssignment(Box), + IncOrDecExpression(Box), + FunctionSubroutineCall(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct LoopVariables { + pub nodes: (List>,), +} diff --git a/sv-parser/src/parser/behavioral_statements/mod.rs b/sv-parser-syntaxtree/src/behavioral_statements/mod.rs similarity index 100% rename from sv-parser/src/parser/behavioral_statements/mod.rs rename to sv-parser-syntaxtree/src/behavioral_statements/mod.rs diff --git a/sv-parser-syntaxtree/src/behavioral_statements/parallel_and_sequential_blocks.rs b/sv-parser-syntaxtree/src/behavioral_statements/parallel_and_sequential_blocks.rs new file mode 100644 index 0000000..d8e2251 --- /dev/null +++ b/sv-parser-syntaxtree/src/behavioral_statements/parallel_and_sequential_blocks.rs @@ -0,0 +1,45 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum ActionBlock { + StatementOrNull(Box), + Else(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ActionBlockElse { + pub nodes: (Option, Keyword, StatementOrNull), +} + +#[derive(Clone, Debug, Node)] +pub struct SeqBlock { + pub nodes: ( + Keyword, + Option<(Symbol, BlockIdentifier)>, + Vec, + Vec, + Keyword, + Option<(Symbol, BlockIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ParBlock { + pub nodes: ( + Keyword, + Option<(Symbol, BlockIdentifier)>, + Vec, + Vec, + JoinKeyword, + Option<(Symbol, BlockIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum JoinKeyword { + Join(Box), + JoinAny(Box), + JoinNone(Box), +} diff --git a/sv-parser-syntaxtree/src/behavioral_statements/patterns.rs b/sv-parser-syntaxtree/src/behavioral_statements/patterns.rs new file mode 100644 index 0000000..797e124 --- /dev/null +++ b/sv-parser-syntaxtree/src/behavioral_statements/patterns.rs @@ -0,0 +1,107 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum Pattern { + Variable(Box), + Asterisk(Box), + ConstantExpression(Box), + Tagged(Box), + List(Box), + IdentifierList(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PatternVariable { + pub nodes: (Symbol, VariableIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub struct PatternTagged { + pub nodes: (Keyword, MemberIdentifier, Option), +} + +#[derive(Clone, Debug, Node)] +pub struct PatternList { + pub nodes: (ApostropheBrace>,), +} + +#[derive(Clone, Debug, Node)] +pub struct PatternIdentifierList { + pub nodes: (ApostropheBrace>,), +} + +#[derive(Clone, Debug, Node)] +pub enum AssignmentPattern { + List(Box), + Structure(Box), + Array(Box), + Repeat(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct AssignmentPatternList { + pub nodes: (ApostropheBrace>,), +} + +#[derive(Clone, Debug, Node)] +pub struct AssignmentPatternStructure { + pub nodes: (ApostropheBrace>,), +} + +#[derive(Clone, Debug, Node)] +pub struct AssignmentPatternArray { + pub nodes: (ApostropheBrace>,), +} + +#[derive(Clone, Debug, Node)] +pub struct AssignmentPatternRepeat { + pub nodes: (ApostropheBrace<(ConstantExpression, Brace>)>,), +} + +#[derive(Clone, Debug, Node)] +pub enum StructurePatternKey { + MemberIdentifier(Box), + AssignmentPatternKey(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum ArrayPatternKey { + ConstantExpression(Box), + AssignmentPatternKey(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum AssignmentPatternKey { + SimpleType(Box), + Default(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct AssignmentPatternExpression { + pub nodes: (Option, AssignmentPattern), +} + +#[derive(Clone, Debug, Node)] +pub enum AssignmentPatternExpressionType { + PsTypeIdentifier(Box), + PsParameterIdentifier(Box), + IntegerAtomType(Box), + TypeReference(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantAssignmentPatternExpression { + pub nodes: (AssignmentPatternExpression,), +} + +#[derive(Clone, Debug, Node)] +pub struct AssignmentPatternNetLvalue { + pub nodes: (ApostropheBrace>,), +} + +#[derive(Clone, Debug, Node)] +pub struct AssignmentPatternVariableLvalue { + pub nodes: (ApostropheBrace>,), +} diff --git a/sv-parser-syntaxtree/src/behavioral_statements/procedural_blocks_and_assignments.rs b/sv-parser-syntaxtree/src/behavioral_statements/procedural_blocks_and_assignments.rs new file mode 100644 index 0000000..5901b47 --- /dev/null +++ b/sv-parser-syntaxtree/src/behavioral_statements/procedural_blocks_and_assignments.rs @@ -0,0 +1,120 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct InitialConstruct { + pub nodes: (Keyword, StatementOrNull), +} + +#[derive(Clone, Debug, Node)] +pub struct AlwaysConstruct { + pub nodes: (AlwaysKeyword, Statement), +} + +#[derive(Clone, Debug, Node)] +pub enum AlwaysKeyword { + Always(Box), + AlwaysComb(Box), + AlwaysLatch(Box), + AlwaysFf(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct FinalConstruct { + pub nodes: (Keyword, FunctionStatement), +} + +#[derive(Clone, Debug, Node)] +pub enum BlockingAssignment { + Variable(Box), + NonrangeVariable(Box), + HierarchicalVariable(Box), + OperatorAssignment(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct BlockingAssignmentVariable { + pub nodes: (VariableLvalue, Symbol, DelayOrEventControl, Expression), +} + +#[derive(Clone, Debug, Node)] +pub struct BlockingAssignmentNonrangeVariable { + pub nodes: (NonrangeVariableLvalue, Symbol, DynamicArrayNew), +} + +#[derive(Clone, Debug, Node)] +pub struct BlockingAssignmentHierarchicalVariable { + pub nodes: ( + Option, + HierarchicalVariableIdentifier, + Select, + Symbol, + ClassNew, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct OperatorAssignment { + pub nodes: (VariableLvalue, AssignmentOperator, Expression), +} + +#[derive(Clone, Debug, Node)] +pub struct AssignmentOperator { + pub nodes: (Symbol,), +} + +#[derive(Clone, Debug, Node)] +pub struct NonblockingAssignment { + pub nodes: ( + VariableLvalue, + Symbol, + Option, + Expression, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ProceduralContinuousAssignment { + Assign(Box), + Deassign(Box), + ForceVariable(Box), + ForceNet(Box), + ReleaseVariable(Box), + ReleaseNet(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ProceduralContinuousAssignmentAssign { + pub nodes: (Keyword, VariableAssignment), +} + +#[derive(Clone, Debug, Node)] +pub struct ProceduralContinuousAssignmentDeassign { + pub nodes: (Keyword, VariableLvalue), +} + +#[derive(Clone, Debug, Node)] +pub struct ProceduralContinuousAssignmentForceVariable { + pub nodes: (Keyword, VariableAssignment), +} + +#[derive(Clone, Debug, Node)] +pub struct ProceduralContinuousAssignmentForceNet { + pub nodes: (Keyword, NetAssignment), +} + +#[derive(Clone, Debug, Node)] +pub struct ProceduralContinuousAssignmentReleaseVariable { + pub nodes: (Keyword, VariableLvalue), +} + +#[derive(Clone, Debug, Node)] +pub struct ProceduralContinuousAssignmentReleaseNet { + pub nodes: (Keyword, NetLvalue), +} + +#[derive(Clone, Debug, Node)] +pub struct VariableAssignment { + pub nodes: (VariableLvalue, Symbol, Expression), +} diff --git a/sv-parser-syntaxtree/src/behavioral_statements/randsequence.rs b/sv-parser-syntaxtree/src/behavioral_statements/randsequence.rs new file mode 100644 index 0000000..9010adf --- /dev/null +++ b/sv-parser-syntaxtree/src/behavioral_statements/randsequence.rs @@ -0,0 +1,135 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct RandsequenceStatement { + pub nodes: ( + Keyword, + Paren>, + Production, + Vec, + Keyword, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct Production { + pub nodes: ( + Option, + ProductionIdentifier, + Option>, + Symbol, + List, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct RsRule { + pub nodes: ( + RsProductionList, + Option<(Symbol, WeightSpecification, Option)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum RsProductionList { + Prod(Box), + Join(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct RsProductionListProd { + pub nodes: (RsProd, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct RsProductionListJoin { + pub nodes: ( + Keyword, + Keyword, + Option>, + ProductionItem, + ProductionItem, + Vec, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum WeightSpecification { + IntegralNumber(Box), + PsIdentifier(Box), + Expression(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct WeightSpecificationExpression { + pub nodes: (Paren,), +} + +#[derive(Clone, Debug, Node)] +pub struct RsCodeBlock { + pub nodes: (Brace<(Vec, Vec)>,), +} + +#[derive(Clone, Debug, Node)] +pub enum RsProd { + ProductionItem(Box), + RsCodeBlock(Box), + RsIfElse(Box), + RsRepeat(Box), + RsCase(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ProductionItem { + pub nodes: (ProductionIdentifier, Option>), +} + +#[derive(Clone, Debug, Node)] +pub struct RsIfElse { + pub nodes: ( + Keyword, + Paren, + ProductionItem, + Option<(Keyword, ProductionItem)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct RsRepeat { + pub nodes: (Keyword, Paren, ProductionItem), +} + +#[derive(Clone, Debug, Node)] +pub struct RsCase { + pub nodes: ( + Keyword, + Paren, + RsCaseItem, + Vec, + Keyword, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum RsCaseItem { + NonDefault(Box), + Default(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct RsCaseItemNondefault { + pub nodes: ( + List, + Symbol, + ProductionItem, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct RsCaseItemDefault { + pub nodes: (Keyword, Option, ProductionItem, Symbol), +} diff --git a/sv-parser-syntaxtree/src/behavioral_statements/statements.rs b/sv-parser-syntaxtree/src/behavioral_statements/statements.rs new file mode 100644 index 0000000..90f1a8b --- /dev/null +++ b/sv-parser-syntaxtree/src/behavioral_statements/statements.rs @@ -0,0 +1,68 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum StatementOrNull { + Statement(Box), + Attribute(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct StatementOrNullAttribute { + pub nodes: (Vec, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct Statement { + pub nodes: ( + Option<(BlockIdentifier, Symbol)>, + Vec, + StatementItem, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum StatementItem { + BlockingAssignment(Box<(BlockingAssignment, Symbol)>), + NonblockingAssignment(Box<(NonblockingAssignment, Symbol)>), + ProceduralContinuousAssignment(Box<(ProceduralContinuousAssignment, Symbol)>), + CaseStatement(Box), + ConditionalStatement(Box), + IncOrDecExpression(Box<(IncOrDecExpression, Symbol)>), + SubroutineCallStatement(Box), + DisableStatement(Box), + EventTrigger(Box), + LoopStatement(Box), + JumpStatement(Box), + ParBlock(Box), + ProceduralTimingControlStatement(Box), + SeqBlock(Box), + WaitStatement(Box), + ProceduralAssertionStatement(Box), + ClockingDrive(Box<(ClockingDrive, Symbol)>), + RandsequenceStatement(Box), + RandcaseStatement(Box), + ExpectPropertyStatement(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct FunctionStatement { + pub nodes: (Statement,), +} + +#[derive(Clone, Debug, Node)] +pub enum FunctionStatementOrNull { + Statement(Box), + Attribute(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct FunctionStatementOrNullAttribute { + pub nodes: (Vec, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct VariableIdentifierList { + pub nodes: (List,), +} diff --git a/sv-parser-syntaxtree/src/behavioral_statements/subroutine_call_statements.rs b/sv-parser-syntaxtree/src/behavioral_statements/subroutine_call_statements.rs new file mode 100644 index 0000000..abc1ae8 --- /dev/null +++ b/sv-parser-syntaxtree/src/behavioral_statements/subroutine_call_statements.rs @@ -0,0 +1,14 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum SubroutineCallStatement { + SubroutineCall(Box<(SubroutineCall, Symbol)>), + Function(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct SubroutineCallStatementFunction { + pub nodes: (Keyword, Symbol, Paren, Symbol), +} diff --git a/sv-parser-syntaxtree/src/behavioral_statements/timing_control_statements.rs b/sv-parser-syntaxtree/src/behavioral_statements/timing_control_statements.rs new file mode 100644 index 0000000..ae2e51a --- /dev/null +++ b/sv-parser-syntaxtree/src/behavioral_statements/timing_control_statements.rs @@ -0,0 +1,206 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct ProceduralTimingControlStatement { + pub nodes: (ProceduralTimingControl, StatementOrNull), +} + +#[derive(Clone, Debug, Node)] +pub enum DelayOrEventControl { + Delay(Box), + Event(Box), + Repeat(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct DelayOrEventControlRepeat { + pub nodes: (Keyword, Paren, EventControl), +} + +#[derive(Clone, Debug, Node)] +pub enum DelayControl { + Delay(Box), + Mintypmax(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct DelayControlDelay { + pub nodes: (Symbol, DelayValue), +} + +#[derive(Clone, Debug, Node)] +pub struct DelayControlMintypmax { + pub nodes: (Symbol, Paren), +} + +#[derive(Clone, Debug, Node)] +pub enum EventControl { + EventIdentifier(Box), + EventExpression(Box), + Asterisk(Box), + ParenAsterisk(Box), + SequenceIdentifier(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct EventControlEventIdentifier { + pub nodes: (Symbol, HierarchicalEventIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub struct EventControlEventExpression { + pub nodes: (Symbol, Paren), +} + +#[derive(Clone, Debug, Node)] +pub struct EventControlAsterisk { + pub nodes: (Symbol,), +} + +#[derive(Clone, Debug, Node)] +pub struct EventControlParenAsterisk { + pub nodes: (Symbol, Paren), +} + +#[derive(Clone, Debug, Node)] +pub struct EventControlSequenceIdentifier { + pub nodes: (Symbol, PsOrHierarchicalSequenceIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub enum EventExpression { + Expression(Box), + Sequence(Box), + Or(Box), + Comma(Box), + Paren(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct EventExpressionExpression { + pub nodes: ( + Option, + Expression, + Option<(Keyword, Expression)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct EventExpressionSequence { + pub nodes: (SequenceInstance, Option<(Keyword, Expression)>), +} + +#[derive(Clone, Debug, Node)] +pub struct EventExpressionOr { + pub nodes: (EventExpression, Keyword, EventExpression), +} + +#[derive(Clone, Debug, Node)] +pub struct EventExpressionComma { + pub nodes: (EventExpression, Symbol, EventExpression), +} + +#[derive(Clone, Debug, Node)] +pub struct EventExpressionParen { + pub nodes: (Paren,), +} + +#[derive(Clone, Debug, Node)] +pub enum ProceduralTimingControl { + DelayControl(Box), + EventControl(Box), + CycleDelay(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum JumpStatement { + Return(Box), + Break(Box), + Continue(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct JumpStatementReturn { + pub nodes: (Keyword, Option, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct JumpStatementBreak { + pub nodes: (Keyword, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct JumpStatementContinue { + pub nodes: (Keyword, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub enum WaitStatement { + Wait(Box), + Fork(Box), + Order(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct WaitStatementWait { + pub nodes: (Keyword, Paren, StatementOrNull), +} + +#[derive(Clone, Debug, Node)] +pub struct WaitStatementFork { + pub nodes: (Keyword, Keyword, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct WaitStatementOrder { + pub nodes: ( + Keyword, + Paren>, + ActionBlock, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum EventTrigger { + Named(Box), + Nonblocking(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct EventTriggerNamed { + pub nodes: (Symbol, HierarchicalEventIdentifier, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct EventTriggerNonblocking { + pub nodes: ( + Symbol, + Option, + HierarchicalEventIdentifier, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum DisableStatement { + Task(Box), + Block(Box), + Fork(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct DisableStatementTask { + pub nodes: (Keyword, HierarchicalTaskIdentifier, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct DisableStatementBlock { + pub nodes: (Keyword, HierarchicalBlockIdentifier, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct DisableStatementFork { + pub nodes: (Keyword, Keyword, Symbol), +} diff --git a/sv-parser-syntaxtree/src/declarations/assertion_declarations.rs b/sv-parser-syntaxtree/src/declarations/assertion_declarations.rs new file mode 100644 index 0000000..ece821b --- /dev/null +++ b/sv-parser-syntaxtree/src/declarations/assertion_declarations.rs @@ -0,0 +1,662 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum ConcurrentAssertionItem { + Statement(Box), + CheckerInstantiation(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ConcurrentAssertionItemStatement { + pub nodes: ( + Option<(BlockIdentifier, Symbol)>, + ConcurrentAssertionStatement, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ConcurrentAssertionStatement { + AssertPropertyStatement(Box), + AssumePropertyStatement(Box), + CoverPropertyStatement(Box), + CoverSequenceStatement(Box), + RestrictPropertyStatement(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct AssertPropertyStatement { + pub nodes: (Keyword, Keyword, Paren, ActionBlock), +} + +#[derive(Clone, Debug, Node)] +pub struct AssumePropertyStatement { + pub nodes: (Keyword, Keyword, Paren, ActionBlock), +} + +#[derive(Clone, Debug, Node)] +pub struct CoverPropertyStatement { + pub nodes: (Keyword, Keyword, Paren, StatementOrNull), +} + +#[derive(Clone, Debug, Node)] +pub struct ExpectPropertyStatement { + pub nodes: (Keyword, Paren, ActionBlock), +} + +#[derive(Clone, Debug, Node)] +pub struct CoverSequenceStatement { + pub nodes: ( + Keyword, + Keyword, + Paren<( + Option, + Option<(Keyword, Keyword, Paren)>, + SequenceExpr, + )>, + StatementOrNull, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct RestrictPropertyStatement { + pub nodes: (Keyword, Keyword, Paren, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyInstance { + pub nodes: ( + PsOrHierarchicalPropertyIdentifier, + Option>>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum PropertyListOfArguments { + Ordered(Box), + Named(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyListOfArgumentsOrdered { + pub nodes: ( + List>, + Vec<(Symbol, Symbol, Identifier, Paren>)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyListOfArgumentsNamed { + pub nodes: (List>)>,), +} + +#[derive(Clone, Debug, Node)] +pub enum PropertyActualArg { + PropertyExpr(Box), + SequenceActualArg(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum AssertionItemDeclaration { + PropertyDeclaration(Box), + SequenceDeclaration(Box), + LetDeclaration(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyDeclaration { + pub nodes: ( + Keyword, + PropertyIdentifier, + Option>>, + Symbol, + Vec, + PropertySpec, + Option, + Keyword, + Option<(Symbol, PropertyIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyPortList { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyPortItem { + pub nodes: ( + Vec, + Option<(Local, Option)>, + Option, + FormalPortIdentifier, + Vec, + Option<(Symbol, PropertyActualArg)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum PropertyLvarPortDirection { + Input(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum PropertyFormalType { + SequenceFormalType(Box), + Property(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertySpec { + pub nodes: ( + Option, + Option<(Keyword, Keyword, Paren)>, + PropertyExpr, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum PropertyExpr { + SequenceExpr(Box), + Strong(Box), + Weak(Box), + Paren(Box), + Not(Box), + Or(Box), + And(Box), + ImplicationOverlapped(Box), + ImplicationNonoverlapped(Box), + If(Box), + Case(Box), + FollowedByOverlapped(Box), + FollowedByNonoverlapped(Box), + Nexttime(Box), + SNexttime(Box), + Always(Box), + SAlways(Box), + Eventually(Box), + SEventually(Box), + Until(Box), + SUntil(Box), + UntilWith(Box), + SUntilWith(Box), + Implies(Box), + Iff(Box), + AcceptOn(Box), + RejectOn(Box), + SyncAcceptOn(Box), + SyncRejectOn(Box), + PropertyInstance(Box), + ClockingEvent(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprStrong { + pub nodes: (Keyword, Paren), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprWeak { + pub nodes: (Keyword, Paren), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprParen { + pub nodes: (Paren,), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprNot { + pub nodes: (Keyword, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprOr { + pub nodes: (PropertyExpr, Keyword, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprAnd { + pub nodes: (PropertyExpr, Keyword, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprImplicationOverlapped { + pub nodes: (SequenceExpr, Symbol, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprImplicationNonoverlapped { + pub nodes: (SequenceExpr, Symbol, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprIf { + pub nodes: ( + Keyword, + Paren, + PropertyExpr, + Option<(Keyword, PropertyExpr)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprCase { + pub nodes: ( + Keyword, + Paren, + PropertyCaseItem, + Vec, + Keyword, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprFollowedByOverlapped { + pub nodes: (SequenceExpr, Symbol, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprFollowedByNonoverlapped { + pub nodes: (SequenceExpr, Symbol, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprNexttime { + pub nodes: (Keyword, Option>, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprSNexttime { + pub nodes: (Keyword, Option>, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprAlways { + pub nodes: ( + Keyword, + Option>, + PropertyExpr, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprSAlways { + pub nodes: ( + Keyword, + Bracket, + PropertyExpr, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprEventually { + pub nodes: (Keyword, Bracket, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprSEventually { + pub nodes: ( + Keyword, + Option>, + PropertyExpr, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprUntil { + pub nodes: (PropertyExpr, Keyword, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprSUntil { + pub nodes: (PropertyExpr, Keyword, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprUntilWith { + pub nodes: (PropertyExpr, Keyword, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprSUntilWith { + pub nodes: (PropertyExpr, Keyword, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprImplies { + pub nodes: (PropertyExpr, Keyword, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprIff { + pub nodes: (PropertyExpr, Keyword, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprAcceptOn { + pub nodes: (Keyword, Paren, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprRejectOn { + pub nodes: (Keyword, Paren, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprSyncAcceptOn { + pub nodes: (Keyword, Paren, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprSyncRejectOn { + pub nodes: (Keyword, Paren, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyExprClockingEvent { + pub nodes: (ClockingEvent, PropertyExpr), +} + +#[derive(Clone, Debug, Node)] +pub enum PropertyCaseItem { + Nondefault(Box), + Default(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyCaseItemNondefault { + pub nodes: (List, Symbol, PropertyExpr, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyCaseItemDefault { + pub nodes: (Keyword, Option, PropertyExpr, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceDeclaration { + pub nodes: ( + Keyword, + SequenceIdentifier, + Option>>, + Symbol, + Vec, + SequenceExpr, + Option, + Keyword, + Option<(Symbol, SequenceIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct SequencePortList { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct SequencePortItem { + pub nodes: ( + Vec, + Option<(Local, Option)>, + Option, + FormalPortIdentifier, + Vec, + Option<(Symbol, SequenceActualArg)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum SequenceLvarPortDirection { + Input(Box), + Inout(Box), + Output(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum SequenceFormalType { + DataTypeOrImplicit(Box), + Sequence(Box), + Untyped(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum SequenceExpr { + CycleDelayExpr(Box), + ExprCycleDelayExpr(Box), + Expression(Box), + Instance(Box), + Paren(Box), + And(Box), + Intersect(Box), + Or(Box), + FirstMatch(Box), + Throughout(Box), + Within(Box), + ClockingEvent(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceExprCycleDelayExpr { + pub nodes: ( + CycleDelayRange, + SequenceExpr, + Vec<(CycleDelayRange, SequenceExpr)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceExprExprCycleDelayExpr { + pub nodes: ( + SequenceExpr, + CycleDelayRange, + SequenceExpr, + Vec<(CycleDelayRange, SequenceExpr)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceExprExpression { + pub nodes: (ExpressionOrDist, Option), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceExprInstance { + pub nodes: (SequenceInstance, Option), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceExprParen { + pub nodes: ( + Paren<(SequenceExpr, Vec<(Symbol, SequenceMatchItem)>)>, + Option, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceExprAnd { + pub nodes: (SequenceExpr, Keyword, SequenceExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceExprIntersect { + pub nodes: (SequenceExpr, Keyword, SequenceExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceExprOr { + pub nodes: (SequenceExpr, Keyword, SequenceExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceExprFirstMatch { + pub nodes: ( + Keyword, + Paren<(SequenceExpr, Vec<(Symbol, SequenceMatchItem)>)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceExprThroughout { + pub nodes: (ExpressionOrDist, Keyword, SequenceExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceExprWithin { + pub nodes: (SequenceExpr, Keyword, SequenceExpr), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceExprClockingEvent { + pub nodes: (ClockingEvent, SequenceExpr), +} + +#[derive(Clone, Debug, Node)] +pub enum CycleDelayRange { + Primary(Box), + Expression(Box), + Asterisk(Box), + Plus(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CycleDelayRangePrimary { + pub nodes: (Symbol, ConstantPrimary), +} + +#[derive(Clone, Debug, Node)] +pub struct CycleDelayRangeExpression { + pub nodes: (Symbol, Bracket), +} + +#[derive(Clone, Debug, Node)] +pub struct CycleDelayRangeAsterisk { + pub nodes: (Symbol, Bracket), +} + +#[derive(Clone, Debug, Node)] +pub struct CycleDelayRangePlus { + pub nodes: (Symbol, Bracket), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceMethodCall { + pub nodes: (SequenceInstance, Symbol, MethodIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub enum SequenceMatchItem { + OperatorAssignment(Box), + IncOrDecExpression(Box), + SubroutineCall(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceInstance { + pub nodes: ( + PsOrHierarchicalSequenceIdentifier, + Option>>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum SequenceListOfArguments { + Ordered(Box), + Named(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceListOfArgumentsOrdered { + pub nodes: ( + List>, + Vec<(Symbol, Symbol, Identifier, Paren>)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceListOfArgumentsNamed { + pub nodes: (List>)>,), +} + +#[derive(Clone, Debug, Node)] +pub enum SequenceActualArg { + EventExpression(Box), + SequenceExpr(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum BooleanAbbrev { + ConsecutiveRepetition(Box), + NonConsecutiveRepetition(Box), + GotoRepetition(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceAbbrev { + pub nodes: (ConsecutiveRepetition,), +} + +#[derive(Clone, Debug, Node)] +pub enum ConsecutiveRepetition { + Expression(Box), + Asterisk(Box), + Plus(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ConsecutiveRepetitionExpression { + pub nodes: (Bracket<(Symbol, ConstOrRangeExpression)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct ConsecutiveRepetitionAsterisk { + pub nodes: (Bracket,), +} + +#[derive(Clone, Debug, Node)] +pub struct ConsecutiveRepetitionPlus { + pub nodes: (Bracket,), +} + +#[derive(Clone, Debug, Node)] +pub struct NonConsecutiveRepetition { + pub nodes: (Bracket<(Symbol, ConstOrRangeExpression)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct GotoRepetition { + pub nodes: (Bracket<(Symbol, ConstOrRangeExpression)>,), +} + +#[derive(Clone, Debug, Node)] +pub enum ConstOrRangeExpression { + ConstantExpression(Box), + CycleDelayConstRangeExpression(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum CycleDelayConstRangeExpression { + Binary(Box), + Dollar(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CycleDelayConstRangeExpressionBinary { + pub nodes: (ConstantExpression, Symbol, ConstantExpression), +} + +#[derive(Clone, Debug, Node)] +pub struct CycleDelayConstRangeExpressionDollar { + pub nodes: (ConstantExpression, Symbol, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct ExpressionOrDist { + pub nodes: (Expression, Option<(Keyword, Brace)>), +} + +#[derive(Clone, Debug, Node)] +pub struct AssertionVariableDeclaration { + pub nodes: (VarDataType, ListOfVariableDeclAssignments, Symbol), +} diff --git a/sv-parser-syntaxtree/src/declarations/block_item_declarations.rs b/sv-parser-syntaxtree/src/declarations/block_item_declarations.rs new file mode 100644 index 0000000..02e91a7 --- /dev/null +++ b/sv-parser-syntaxtree/src/declarations/block_item_declarations.rs @@ -0,0 +1,31 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum BlockItemDeclaration { + Data(Box), + LocalParameter(Box), + Parameter(Box), + Let(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct BlockItemDeclarationData { + pub nodes: (Vec, DataDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct BlockItemDeclarationLocalParameter { + pub nodes: (Vec, LocalParameterDeclaration, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct BlockItemDeclarationParameter { + pub nodes: (Vec, ParameterDeclaration, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct BlockItemDeclarationLet { + pub nodes: (Vec, LetDeclaration), +} diff --git a/sv-parser-syntaxtree/src/declarations/covergroup_declarations.rs b/sv-parser-syntaxtree/src/declarations/covergroup_declarations.rs new file mode 100644 index 0000000..41e031c --- /dev/null +++ b/sv-parser-syntaxtree/src/declarations/covergroup_declarations.rs @@ -0,0 +1,468 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct CovergroupDeclaration { + pub nodes: ( + Keyword, + CovergroupIdentifier, + Option>>, + Option, + Symbol, + Vec, + Keyword, + Option<(Symbol, CovergroupIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum CoverageSpecOrOption { + Spec(Box), + Option(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CoverageSpecOrOptionSpec { + pub nodes: (Vec, CoverageSpec), +} + +#[derive(Clone, Debug, Node)] +pub struct CoverageSpecOrOptionOption { + pub nodes: (Vec, CoverageOption, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub enum CoverageOption { + Option(Box), + TypeOption(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CoverageOptionOption { + pub nodes: (Keyword, Symbol, MemberIdentifier, Symbol, Expression), +} + +#[derive(Clone, Debug, Node)] +pub struct CoverageOptionTypeOption { + pub nodes: ( + Keyword, + Symbol, + MemberIdentifier, + Symbol, + ConstantExpression, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum CoverageSpec { + CoverPoint(Box), + CoverCross(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum CoverageEvent { + ClockingEvent(Box), + Sample(Box), + At(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CoverageEventSample { + pub nodes: (Keyword, Keyword, Keyword, Paren>), +} + +#[derive(Clone, Debug, Node)] +pub struct CoverageEventAt { + pub nodes: (Symbol, Paren), +} + +#[derive(Clone, Debug, Node)] +pub enum BlockEventExpression { + Or(Box), + Begin(Box), + End(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct BlockEventExpressionOr { + pub nodes: (BlockEventExpression, Keyword, BlockEventExpression), +} + +#[derive(Clone, Debug, Node)] +pub struct BlockEventExpressionBegin { + pub nodes: (Keyword, HierarchicalBtfIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub struct BlockEventExpressionEnd { + pub nodes: (Keyword, HierarchicalBtfIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub enum HierarchicalBtfIdentifier { + HierarchicalTfIdentifier(Box), + HierarchicalBlockIdentifier(Box), + Method(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct HierarchicalBtfIdentifierMethod { + pub nodes: (Option, MethodIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub enum HierarchicalIdentifierOrClassScope { + HierarchicalIdentifier(Box<(HierarchicalIdentifier, Symbol)>), + ClassScope(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CoverPoint { + pub nodes: ( + Option<(Option, CoverPointIdentifier, Symbol)>, + Keyword, + Expression, + Option<(Keyword, Paren)>, + BinsOrEmpty, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum BinsOrEmpty { + NonEmpty(Box), + Empty(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct BinsOrEmptyNonEmpty { + pub nodes: (Brace<(Vec, Vec<(BinsOrOptions, Symbol)>)>,), +} + +#[derive(Clone, Debug, Node)] +pub enum BinsOrOptions { + CoverageOption(Box), + Covergroup(Box), + CoverPoint(Box), + SetCovergroup(Box), + TransList(Box), + Default(Box), + DefaultSequence(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct BinsOrOptionsCovergroup { + pub nodes: ( + Option, + BinsKeyword, + BinIdentifier, + Option>>, + Symbol, + Brace, + Option<(Keyword, Paren)>, + Option<(Keyword, Paren)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct Wildcard { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct BinsOrOptionsCoverPoint { + pub nodes: ( + Option, + BinsKeyword, + BinIdentifier, + Option>>, + Symbol, + CoverPointIdentifier, + Keyword, + Paren, + Option<(Keyword, Paren)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct BinsOrOptionsSetCovergroup { + pub nodes: ( + Option, + BinsKeyword, + BinIdentifier, + Option>>, + Symbol, + SetCovergroupExpression, + Option<(Keyword, Paren)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct BinsOrOptionsTransList { + pub nodes: ( + Option, + BinsKeyword, + BinIdentifier, + Option<(Symbol, Symbol)>, + Symbol, + TransList, + Option<(Keyword, Paren)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct BinsOrOptionsDefault { + pub nodes: ( + BinsKeyword, + BinIdentifier, + Option>>, + Symbol, + Keyword, + Option<(Keyword, Paren)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct BinsOrOptionsDefaultSequence { + pub nodes: ( + BinsKeyword, + BinIdentifier, + Symbol, + Keyword, + Keyword, + Option<(Keyword, Paren)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum BinsKeyword { + Bins(Box), + IllegalBins(Box), + IgnoreBins(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct TransList { + pub nodes: (List>,), +} + +#[derive(Clone, Debug, Node)] +pub struct TransSet { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub enum TransRangeList { + TransItem(Box), + Asterisk(Box), + Arrow(Box), + Equal(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct TransRangeListAsterisk { + pub nodes: (TransItem, Bracket<(Symbol, RepeatRange)>), +} + +#[derive(Clone, Debug, Node)] +pub struct TransRangeListArrow { + pub nodes: (TransItem, Bracket<(Symbol, RepeatRange)>), +} + +#[derive(Clone, Debug, Node)] +pub struct TransRangeListEqual { + pub nodes: (TransItem, Bracket<(Symbol, RepeatRange)>), +} + +#[derive(Clone, Debug, Node)] +pub struct TransItem { + pub nodes: (CovergroupRangeList,), +} + +#[derive(Clone, Debug, Node)] +pub enum RepeatRange { + CovergroupExpression(Box), + Binary(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct RepeatRangeBinary { + pub nodes: (CovergroupExpression, Symbol, CovergroupExpression), +} + +#[derive(Clone, Debug, Node)] +pub struct CoverCross { + pub nodes: ( + Option<(CrossIdentifier, Symbol)>, + Keyword, + ListOfCrossItems, + Option<(Keyword, Paren)>, + CrossBody, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfCrossItems { + pub nodes: (CrossItem, List), +} + +#[derive(Clone, Debug, Node)] +pub enum CrossItem { + CoverPointIdentifier(Box), + VariableIdentifier(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum CrossBody { + NonEmpty(Box), + Empty(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CrossBodyNonEmpty { + pub nodes: (Brace>,), +} + +#[derive(Clone, Debug, Node)] +pub enum CrossBodyItem { + FunctionDeclaration(Box), + BinsSelectionOrOption(Box<(BinsSelectionOrOption, Symbol)>), +} + +#[derive(Clone, Debug, Node)] +pub enum BinsSelectionOrOption { + Coverage(Box), + Bins(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct BinsSelectionOrOptionCoverage { + pub nodes: (Vec, CoverageOption), +} + +#[derive(Clone, Debug, Node)] +pub struct BinsSelectionOrOptionBins { + pub nodes: (Vec, BinsSelection), +} + +#[derive(Clone, Debug, Node)] +pub struct BinsSelection { + pub nodes: ( + BinsKeyword, + BinIdentifier, + Symbol, + SelectExpression, + Option<(Keyword, Paren)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum SelectExpression { + SelectCondition(Box), + Not(Box), + And(Box), + Or(Box), + Paren(Box), + With(Box), + CrossIdentifier(Box), + CrossSet(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct SelectExpressionNot { + pub nodes: (Symbol, SelectCondition), +} + +#[derive(Clone, Debug, Node)] +pub struct SelectExpressionAnd { + pub nodes: (SelectExpression, Symbol, SelectExpression), +} + +#[derive(Clone, Debug, Node)] +pub struct SelectExpressionOr { + pub nodes: (SelectExpression, Symbol, SelectExpression), +} + +#[derive(Clone, Debug, Node)] +pub struct SelectExpressionParen { + pub nodes: (Paren,), +} + +#[derive(Clone, Debug, Node)] +pub struct SelectExpressionWith { + pub nodes: ( + SelectExpression, + Keyword, + Paren, + Option<(Keyword, IntegerCovergroupExpression)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct SelectExpressionCrossSet { + pub nodes: ( + CrossSetExpression, + Option<(Keyword, IntegerCovergroupExpression)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct SelectCondition { + pub nodes: ( + Keyword, + Paren, + Option<(Keyword, Brace)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum BinsExpression { + VariableIdentifier(Box), + CoverPoint(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct BinsExpressionCoverPoint { + pub nodes: (CoverPointIdentifier, Option<(Symbol, BinIdentifier)>), +} + +#[derive(Clone, Debug, Node)] +pub struct CovergroupRangeList { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub enum CovergroupValueRange { + CovergroupExpression(Box), + Binary(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CovergroupValueRangeBinary { + pub nodes: (Bracket<(CovergroupExpression, Symbol, CovergroupExpression)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct WithCovergroupExpression { + pub nodes: (CovergroupExpression,), +} + +#[derive(Clone, Debug, Node)] +pub struct SetCovergroupExpression { + pub nodes: (CovergroupExpression,), +} + +#[derive(Clone, Debug, Node)] +pub struct IntegerCovergroupExpression { + pub nodes: (CovergroupExpression,), +} + +#[derive(Clone, Debug, Node)] +pub struct CrossSetExpression { + pub nodes: (CovergroupExpression,), +} + +#[derive(Clone, Debug, Node)] +pub struct CovergroupExpression { + pub nodes: (Expression,), +} diff --git a/sv-parser-syntaxtree/src/declarations/declaration_assignments.rs b/sv-parser-syntaxtree/src/declarations/declaration_assignments.rs new file mode 100644 index 0000000..809c67f --- /dev/null +++ b/sv-parser-syntaxtree/src/declarations/declaration_assignments.rs @@ -0,0 +1,140 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct DefparamAssignment { + pub nodes: ( + HierarchicalParameterIdentifier, + Symbol, + ConstantMintypmaxExpression, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct NetDeclAssignment { + pub nodes: ( + NetIdentifier, + Vec, + Option<(Symbol, Expression)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ParamAssignment { + pub nodes: ( + ParameterIdentifier, + Vec, + Option<(Symbol, ConstantParamExpression)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum SpecparamAssignment { + Mintypmax(Box), + PulseControlSpecparam(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct SpecparamAssignmentMintypmax { + pub nodes: (SpecparamIdentifier, Symbol, ConstantMintypmaxExpression), +} + +#[derive(Clone, Debug, Node)] +pub struct TypeAssignment { + pub nodes: (TypeIdentifier, Option<(Symbol, DataType)>), +} + +#[derive(Clone, Debug, Node)] +pub enum PulseControlSpecparam { + WithoutDescriptor(Box), + WithDescriptor(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PulseControlSpecparamWithoutDescriptor { + pub nodes: ( + Symbol, + Symbol, + Paren<(RejectLimitValue, Option<(Symbol, ErrorLimitValue)>)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct PulseControlSpecparamWithDescriptor { + pub nodes: ( + Symbol, + SpecifyInputTerminalDescriptor, + Symbol, + SpecifyOutputTerminalDescriptor, + Symbol, + Paren<(RejectLimitValue, Option<(Symbol, ErrorLimitValue)>)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ErrorLimitValue { + pub nodes: (LimitValue,), +} + +#[derive(Clone, Debug, Node)] +pub struct RejectLimitValue { + pub nodes: (LimitValue,), +} + +#[derive(Clone, Debug, Node)] +pub struct LimitValue { + pub nodes: (ConstantMintypmaxExpression,), +} + +#[derive(Clone, Debug, Node)] +pub enum VariableDeclAssignment { + Variable(Box), + DynamicArray(Box), + Class(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct VariableDeclAssignmentVariable { + pub nodes: ( + VariableIdentifier, + Vec, + Option<(Symbol, Expression)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct VariableDeclAssignmentDynamicArray { + pub nodes: ( + DynamicArrayVariableIdentifier, + UnsizedDimension, + Vec, + Option<(Symbol, DynamicArrayNew)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct VariableDeclAssignmentClass { + pub nodes: (ClassVariableIdentifier, Option<(Symbol, ClassNew)>), +} + +#[derive(Clone, Debug, Node)] +pub enum ClassNew { + Argument(Box), + Expression(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassNewArgument { + pub nodes: (Option, Keyword, Option>), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassNewExpression { + pub nodes: (Keyword, Expression), +} + +#[derive(Clone, Debug, Node)] +pub struct DynamicArrayNew { + pub nodes: (Keyword, Bracket, Option>), +} diff --git a/sv-parser-syntaxtree/src/declarations/declaration_lists.rs b/sv-parser-syntaxtree/src/declarations/declaration_lists.rs new file mode 100644 index 0000000..e16587a --- /dev/null +++ b/sv-parser-syntaxtree/src/declarations/declaration_lists.rs @@ -0,0 +1,86 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct ListOfDefparamAssignments { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfGenvarIdentifiers { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfInterfaceIdentifiers { + pub nodes: (List)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfNetDeclAssignments { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfParamAssignments { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfPortIdentifiers { + pub nodes: (List)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfUdpPortIdentifiers { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfSpecparamAssignments { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfTfVariableIdentifiers { + pub nodes: ( + List< + Symbol, + ( + PortIdentifier, + Vec, + Option<(Symbol, Expression)>, + ), + >, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfTypeAssignments { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfVariableDeclAssignments { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfVariableIdentifiers { + pub nodes: (List)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfVariablePortIdentifiers { + pub nodes: ( + List< + Symbol, + ( + PortIdentifier, + Vec, + Option<(Symbol, ConstantExpression)>, + ), + >, + ), +} diff --git a/sv-parser-syntaxtree/src/declarations/declaration_ranges.rs b/sv-parser-syntaxtree/src/declarations/declaration_ranges.rs new file mode 100644 index 0000000..8bc9378 --- /dev/null +++ b/sv-parser-syntaxtree/src/declarations/declaration_ranges.rs @@ -0,0 +1,64 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum UnpackedDimension { + Range(Box), + Expression(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct UnpackedDimensionRange { + pub nodes: (Bracket,), +} + +#[derive(Clone, Debug, Node)] +pub struct UnpackedDimensionExpression { + pub nodes: (Bracket,), +} + +#[derive(Clone, Debug, Node)] +pub enum PackedDimension { + Range(Box), + UnsizedDimension(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PackedDimensionRange { + pub nodes: (Bracket,), +} + +#[derive(Clone, Debug, Node)] +pub enum AssociativeDimension { + DataType(Box), + Asterisk(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct AssociativeDimensionDataType { + pub nodes: (Bracket,), +} + +#[derive(Clone, Debug, Node)] +pub struct AssociativeDimensionAsterisk { + pub nodes: (Bracket,), +} + +#[derive(Clone, Debug, Node)] +pub enum VariableDimension { + UnsizedDimension(Box), + UnpackedDimension(Box), + AssociativeDimension(Box), + QueueDimension(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct QueueDimension { + pub nodes: (Bracket<(Symbol, Option<(Symbol, ConstantExpression)>)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct UnsizedDimension { + pub nodes: (Symbol, Symbol), +} diff --git a/sv-parser-syntaxtree/src/declarations/delays.rs b/sv-parser-syntaxtree/src/declarations/delays.rs new file mode 100644 index 0000000..7f3c8c1 --- /dev/null +++ b/sv-parser-syntaxtree/src/declarations/delays.rs @@ -0,0 +1,57 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum Delay3 { + Single(Box), + Mintypmax(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct Delay3Single { + pub nodes: (Symbol, DelayValue), +} + +#[derive(Clone, Debug, Node)] +pub struct Delay3Mintypmax { + pub nodes: ( + Symbol, + Paren<( + MintypmaxExpression, + Option<( + Symbol, + MintypmaxExpression, + Option<(Symbol, MintypmaxExpression)>, + )>, + )>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum Delay2 { + Single(Box), + Mintypmax(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct Delay2Single { + pub nodes: (Symbol, DelayValue), +} + +#[derive(Clone, Debug, Node)] +pub struct Delay2Mintypmax { + pub nodes: ( + Symbol, + Paren<(MintypmaxExpression, Option<(Symbol, MintypmaxExpression)>)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum DelayValue { + UnsignedNumber(Box), + RealNumber(Box), + PsIdentifier(Box), + TimeLiteral(Box), + Step1(Box), +} diff --git a/sv-parser-syntaxtree/src/declarations/function_declarations.rs b/sv-parser-syntaxtree/src/declarations/function_declarations.rs new file mode 100644 index 0000000..bcda0b2 --- /dev/null +++ b/sv-parser-syntaxtree/src/declarations/function_declarations.rs @@ -0,0 +1,148 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum FunctionDataTypeOrImplicit { + DataTypeOrVoid(Box), + ImplicitDataType(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct FunctionDeclaration { + pub nodes: (Keyword, Option, FunctionBodyDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub enum FunctionBodyDeclaration { + WithoutPort(Box), + WithPort(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct FunctionBodyDeclarationWithoutPort { + pub nodes: ( + Option, + Option, + FunctionIdentifier, + Symbol, + Vec, + Vec, + Keyword, + Option<(Symbol, FunctionIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct FunctionBodyDeclarationWithPort { + pub nodes: ( + Option, + Option, + FunctionIdentifier, + Paren>, + Symbol, + Vec, + Vec, + Keyword, + Option<(Symbol, FunctionIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum InterfaceIdentifierOrClassScope { + InterfaceIdentifier(Box<(InterfaceIdentifier, Symbol)>), + ClassScope(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct FunctionPrototype { + pub nodes: ( + Keyword, + DataTypeOrVoid, + FunctionIdentifier, + Option>>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum DpiImportExport { + ImportFunction(Box), + ImportTask(Box), + ExportFunction(Box), + ExportTask(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct DpiImportExportImportFunction { + pub nodes: ( + Keyword, + DpiSpecString, + Option, + Option<(CIdentifier, Symbol)>, + DpiFunctionProto, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct DpiImportExportImportTask { + pub nodes: ( + Keyword, + DpiSpecString, + Option, + Option<(CIdentifier, Symbol)>, + DpiTaskProto, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct DpiImportExportExportFunction { + pub nodes: ( + Keyword, + DpiSpecString, + Option<(CIdentifier, Symbol)>, + Keyword, + FunctionIdentifier, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct DpiImportExportExportTask { + pub nodes: ( + Keyword, + DpiSpecString, + Option<(CIdentifier, Symbol)>, + Keyword, + TaskIdentifier, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum DpiSpecString { + DpiC(Box), + Dpi(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum DpiFunctionImportProperty { + Context(Box), + Pure(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum DpiTaskImportProperty { + Context(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct DpiFunctionProto { + pub nodes: (FunctionPrototype,), +} + +#[derive(Clone, Debug, Node)] +pub struct DpiTaskProto { + pub nodes: (TaskPrototype,), +} diff --git a/sv-parser-syntaxtree/src/declarations/interface_declarations.rs b/sv-parser-syntaxtree/src/declarations/interface_declarations.rs new file mode 100644 index 0000000..b665e41 --- /dev/null +++ b/sv-parser-syntaxtree/src/declarations/interface_declarations.rs @@ -0,0 +1,81 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct ModportDeclaration { + pub nodes: (Keyword, List, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct ModportItem { + pub nodes: ( + ModportIdentifier, + Paren>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ModportPortsDeclaraton { + Simple(Box), + Tf(Box), + Clocking(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ModportPortsDeclaratonSimple { + pub nodes: (Vec, ModportSimplePortsDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct ModportPortsDeclaratonTf { + pub nodes: (Vec, ModportTfPortsDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct ModportPortsDeclaratonClocking { + pub nodes: (Vec, ModportClockingDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct ModportClockingDeclaration { + pub nodes: (Keyword, ClockingIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub struct ModportSimplePortsDeclaration { + pub nodes: (PortDirection, List), +} + +#[derive(Clone, Debug, Node)] +pub enum ModportSimplePort { + Ordered(Box), + Named(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ModportSimplePortOrdered { + pub nodes: (PortIdentifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct ModportSimplePortNamed { + pub nodes: (Symbol, PortIdentifier, Paren>), +} + +#[derive(Clone, Debug, Node)] +pub struct ModportTfPortsDeclaration { + pub nodes: (ImportExport, List), +} + +#[derive(Clone, Debug, Node)] +pub enum ModportTfPort { + MethodPrototype(Box), + TfIdentifier(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum ImportExport { + Import(Box), + Export(Box), +} diff --git a/sv-parser-syntaxtree/src/declarations/let_declarations.rs b/sv-parser-syntaxtree/src/declarations/let_declarations.rs new file mode 100644 index 0000000..12d311f --- /dev/null +++ b/sv-parser-syntaxtree/src/declarations/let_declarations.rs @@ -0,0 +1,75 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct LetDeclaration { + pub nodes: ( + Keyword, + LetIdentifier, + Option>>, + Symbol, + Expression, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct LetIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct LetPortList { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct LetPortItem { + pub nodes: ( + Vec, + Option, + FormalPortIdentifier, + Vec, + Option<(Symbol, Expression)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum LetFormalType { + DataTypeOrImplicit(Box), + Untyped(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct LetExpression { + pub nodes: ( + Option, + LetIdentifier, + Option>>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum LetListOfArguments { + Ordered(Box), + Named(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct LetListOfArgumentsOrdered { + pub nodes: ( + List>, + Vec<(Symbol, Symbol, Identifier, Paren>)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct LetListOfArgumentsNamed { + pub nodes: (List>)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct LetActualArg { + pub nodes: (Expression,), +} diff --git a/sv-parser/src/parser/declarations/mod.rs b/sv-parser-syntaxtree/src/declarations/mod.rs similarity index 100% rename from sv-parser/src/parser/declarations/mod.rs rename to sv-parser-syntaxtree/src/declarations/mod.rs diff --git a/sv-parser-syntaxtree/src/declarations/module_parameter_declarations.rs b/sv-parser-syntaxtree/src/declarations/module_parameter_declarations.rs new file mode 100644 index 0000000..013f1ec --- /dev/null +++ b/sv-parser-syntaxtree/src/declarations/module_parameter_declarations.rs @@ -0,0 +1,45 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum LocalParameterDeclaration { + Param(Box), + Type(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct LocalParameterDeclarationParam { + pub nodes: (Keyword, Option, ListOfParamAssignments), +} + +#[derive(Clone, Debug, Node)] +pub struct LocalParameterDeclarationType { + pub nodes: (Keyword, Keyword, ListOfTypeAssignments), +} + +#[derive(Clone, Debug, Node)] +pub enum ParameterDeclaration { + Param(Box), + Type(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ParameterDeclarationParam { + pub nodes: (Keyword, Option, ListOfParamAssignments), +} + +#[derive(Clone, Debug, Node)] +pub struct ParameterDeclarationType { + pub nodes: (Keyword, Keyword, ListOfTypeAssignments), +} + +#[derive(Clone, Debug, Node)] +pub struct SpecparamDeclaration { + pub nodes: ( + Keyword, + Option, + ListOfSpecparamAssignments, + Symbol, + ), +} diff --git a/sv-parser-syntaxtree/src/declarations/net_and_variable_types.rs b/sv-parser-syntaxtree/src/declarations/net_and_variable_types.rs new file mode 100644 index 0000000..9e64ffd --- /dev/null +++ b/sv-parser-syntaxtree/src/declarations/net_and_variable_types.rs @@ -0,0 +1,278 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum CastingType { + SimpleType(Box), + ConstantPrimary(Box), + Signing(Box), + String(Box), + Const(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum DataType { + Vector(Box), + Atom(Box), + NonIntegerType(Box), + StructUnion(Box), + Enum(Box), + String(Box), + Chandle(Box), + Virtual(Box), + Type(Box), + ClassType(Box), + Event(Box), + PsCovergroupIdentifier(Box), + TypeReference(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct DataTypeVector { + pub nodes: (IntegerVectorType, Option, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct DataTypeAtom { + pub nodes: (IntegerAtomType, Option), +} + +#[derive(Clone, Debug, Node)] +pub struct DataTypeStructUnion { + pub nodes: ( + StructUnion, + Option<(Packed, Option)>, + Brace<(StructUnionMember, Vec)>, + Vec, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct Packed { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct DataTypeEnum { + pub nodes: ( + Keyword, + Option, + Brace>, + Vec, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct DataTypeVirtual { + pub nodes: ( + Keyword, + Option, + InterfaceIdentifier, + Option, + Option<(Symbol, ModportIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct Interface { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct DataTypeType { + pub nodes: ( + Option, + TypeIdentifier, + Vec, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum DataTypeOrImplicit { + DataType(Box), + ImplicitDataType(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ImplicitDataType { + pub nodes: (Option, Vec), +} + +#[derive(Clone, Debug, Node)] +pub enum EnumBaseType { + Atom(Box), + Vector(Box), + Type(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct EnumBaseTypeAtom { + pub nodes: (IntegerAtomType, Option), +} + +#[derive(Clone, Debug, Node)] +pub struct EnumBaseTypeVector { + pub nodes: (IntegerVectorType, Option, Option), +} + +#[derive(Clone, Debug, Node)] +pub struct EnumBaseTypeType { + pub nodes: (TypeIdentifier, Option), +} + +#[derive(Clone, Debug, Node)] +pub struct EnumNameDeclaration { + pub nodes: ( + EnumIdentifier, + Option)>>, + Option<(Symbol, ConstantExpression)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassScope { + pub nodes: (ClassType, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassType { + pub nodes: ( + PsClassIdentifier, + Option, + Vec<(Symbol, ClassIdentifier, Option)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum IntegerType { + IntegerVectorType(Box), + IntegerAtomType(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum IntegerAtomType { + Byte(Box), + Shortint(Box), + Int(Box), + Longint(Box), + Integer(Box), + Time(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum IntegerVectorType { + Bit(Box), + Logic(Box), + Reg(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum NonIntegerType { + Shortreal(Box), + Real(Box), + Realtime(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum NetType { + Supply0(Box), + Supply1(Box), + Tri(Box), + Triand(Box), + Trior(Box), + Trireg(Box), + Tri0(Box), + Tri1(Box), + Uwire(Box), + Wire(Box), + Wand(Box), + Wor(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum NetPortType { + DataType(Box), + NetTypeIdentifier(Box), + Interconnect(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct NetPortTypeDataType { + pub nodes: (Option, DataTypeOrImplicit), +} + +#[derive(Clone, Debug, Node)] +pub struct NetPortTypeInterconnect { + pub nodes: (Keyword, ImplicitDataType), +} + +#[derive(Clone, Debug, Node)] +pub struct VariablePortType { + pub nodes: (VarDataType,), +} + +#[derive(Clone, Debug, Node)] +pub enum VarDataType { + DataType(Box), + Var(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct VarDataTypeVar { + pub nodes: (Keyword, DataTypeOrImplicit), +} + +#[derive(Clone, Debug, Node)] +pub enum Signing { + Signed(Box), + Unsigned(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum SimpleType { + IntegerType(Box), + NonIntegerType(Box), + PsTypeIdentifier(Box), + PsParameterIdentifier(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct StructUnionMember { + pub nodes: ( + Vec, + Option, + DataTypeOrVoid, + ListOfVariableDeclAssignments, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum DataTypeOrVoid { + DataType(Box), + Void(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum StructUnion { + Struct(Box), + Union(Box), + UnionTagged(Box<(Keyword, Keyword)>), +} + +#[derive(Clone, Debug, Node)] +pub enum TypeReference { + Expression(Box), + DataType(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct TypeReferenceExpression { + pub nodes: (Keyword, Paren), +} + +#[derive(Clone, Debug, Node)] +pub struct TypeReferenceDataType { + pub nodes: (Keyword, Paren), +} diff --git a/sv-parser-syntaxtree/src/declarations/port_declarations.rs b/sv-parser-syntaxtree/src/declarations/port_declarations.rs new file mode 100644 index 0000000..c0f39e7 --- /dev/null +++ b/sv-parser-syntaxtree/src/declarations/port_declarations.rs @@ -0,0 +1,54 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct InoutDeclaration { + pub nodes: (Keyword, Option, ListOfPortIdentifiers), +} + +#[derive(Clone, Debug, Node)] +pub enum InputDeclaration { + Net(Box), + Variable(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct InputDeclarationNet { + pub nodes: (Keyword, Option, ListOfPortIdentifiers), +} + +#[derive(Clone, Debug, Node)] +pub struct InputDeclarationVariable { + pub nodes: (Keyword, VariablePortType, ListOfVariableIdentifiers), +} + +#[derive(Clone, Debug, Node)] +pub enum OutputDeclaration { + Net(Box), + Variable(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct OutputDeclarationNet { + pub nodes: (Keyword, Option, ListOfPortIdentifiers), +} + +#[derive(Clone, Debug, Node)] +pub struct OutputDeclarationVariable { + pub nodes: (Keyword, VariablePortType, ListOfVariablePortIdentifiers), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfacePortDeclaration { + pub nodes: ( + InterfaceIdentifier, + Option<(Symbol, ModportIdentifier)>, + ListOfInterfaceIdentifiers, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct RefDeclaration { + pub nodes: (Keyword, VariablePortType, ListOfVariableIdentifiers), +} diff --git a/sv-parser-syntaxtree/src/declarations/strengths.rs b/sv-parser-syntaxtree/src/declarations/strengths.rs new file mode 100644 index 0000000..9c33560 --- /dev/null +++ b/sv-parser-syntaxtree/src/declarations/strengths.rs @@ -0,0 +1,81 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum DriveStrength { + Strength01(Box), + Strength10(Box), + Strength0z(Box), + Strength1z(Box), + Strengthz0(Box), + Strengthz1(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct DriveStrength01 { + pub nodes: (Paren<(Strength0, Symbol, Strength1)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct DriveStrength10 { + pub nodes: (Paren<(Strength1, Symbol, Strength0)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct DriveStrength0z { + pub nodes: (Paren<(Strength0, Symbol, Keyword)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct DriveStrength1z { + pub nodes: (Paren<(Strength1, Symbol, Keyword)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct DriveStrengthz1 { + pub nodes: (Paren<(Keyword, Symbol, Strength1)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct DriveStrengthz0 { + pub nodes: (Paren<(Keyword, Symbol, Strength0)>,), +} + +#[derive(Clone, Debug, Node)] +pub enum Strength0 { + Supply0(Box), + Strong0(Box), + Pull0(Box), + Weak0(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum Strength1 { + Supply1(Box), + Strong1(Box), + Pull1(Box), + Weak1(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum ChargeStrength { + Small(Box), + Medium(Box), + Large(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ChargeStrengthSmall { + pub nodes: (Paren,), +} + +#[derive(Clone, Debug, Node)] +pub struct ChargeStrengthMedium { + pub nodes: (Paren,), +} + +#[derive(Clone, Debug, Node)] +pub struct ChargeStrengthLarge { + pub nodes: (Paren,), +} diff --git a/sv-parser-syntaxtree/src/declarations/task_declarations.rs b/sv-parser-syntaxtree/src/declarations/task_declarations.rs new file mode 100644 index 0000000..278d9dc --- /dev/null +++ b/sv-parser-syntaxtree/src/declarations/task_declarations.rs @@ -0,0 +1,90 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct TaskDeclaration { + pub nodes: (Keyword, Option, TaskBodyDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub enum TaskBodyDeclaration { + WithoutPort(Box), + WithPort(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct TaskBodyDeclarationWithoutPort { + pub nodes: ( + Option, + TaskIdentifier, + Symbol, + Vec, + Vec, + Keyword, + Option<(Symbol, TaskIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct TaskBodyDeclarationWithPort { + pub nodes: ( + Option, + TaskIdentifier, + Paren>, + Symbol, + Vec, + Vec, + Keyword, + Option<(Symbol, TaskIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum TfItemDeclaration { + BlockItemDeclaration(Box), + TfPortDeclaration(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct TfPortList { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct TfPortItem { + pub nodes: ( + Vec, + Option, + Option, + Option, + Option<( + PortIdentifier, + Vec, + Option<(Symbol, Expression)>, + )>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum TfPortDirection { + PortDirection(Box), + ConstRef(Box<(Keyword, Keyword)>), +} + +#[derive(Clone, Debug, Node)] +pub struct TfPortDeclaration { + pub nodes: ( + Vec, + TfPortDirection, + Option, + Option, + ListOfTfVariableIdentifiers, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct TaskPrototype { + pub nodes: (Keyword, TaskIdentifier, Option>>), +} diff --git a/sv-parser-syntaxtree/src/declarations/type_declarations.rs b/sv-parser-syntaxtree/src/declarations/type_declarations.rs new file mode 100644 index 0000000..a56a858 --- /dev/null +++ b/sv-parser-syntaxtree/src/declarations/type_declarations.rs @@ -0,0 +1,209 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum DataDeclaration { + Variable(Box), + TypeDeclaration(Box), + PackageImportDeclaration(Box), + NetTypeDeclaration(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct DataDeclarationVariable { + pub nodes: ( + Option, + Option, + Option, + Option, + ListOfVariableDeclAssignments, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct Const { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct PackageImportDeclaration { + pub nodes: (Keyword, List, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub enum PackageImportItem { + Identifier(Box), + Asterisk(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PackageImportItemIdentifier { + pub nodes: (PackageIdentifier, Symbol, Identifier), +} + +#[derive(Clone, Debug, Node)] +pub struct PackageImportItemAsterisk { + pub nodes: (PackageIdentifier, Symbol, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub enum PackageExportDeclaration { + Asterisk(Box), + Item(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PackageExportDeclarationAsterisk { + pub nodes: (Keyword, Symbol, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct PackageExportDeclarationItem { + pub nodes: (Keyword, List, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct GenvarDeclaration { + pub nodes: (Keyword, ListOfGenvarIdentifiers, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub enum NetDeclaration { + NetType(Box), + NetTypeIdentifier(Box), + Interconnect(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct NetDeclarationNetType { + pub nodes: ( + NetType, + Option, + Option, + Option, + Option, + ListOfNetDeclAssignments, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum Strength { + Drive(Box), + Charge(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum VectorScalar { + Vectored(Box), + Scalared(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct NetDeclarationNetTypeIdentifier { + pub nodes: ( + NetTypeIdentifier, + Option, + ListOfNetDeclAssignments, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct NetDeclarationInterconnect { + pub nodes: ( + Keyword, + ImplicitDataType, + Option<(Symbol, DelayValue)>, + NetIdentifier, + Vec, + Option<(Symbol, NetIdentifier, Vec)>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum TypeDeclaration { + DataType(Box), + Interface(Box), + Reserved(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct TypeDeclarationDataType { + pub nodes: ( + Keyword, + DataType, + TypeIdentifier, + Vec, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct TypeDeclarationInterface { + pub nodes: ( + Keyword, + InterfaceInstanceIdentifier, + ConstantBitSelect, + Symbol, + TypeIdentifier, + TypeIdentifier, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct TypeDeclarationReserved { + pub nodes: ( + Keyword, + Option, + TypeIdentifier, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum TypeDeclarationKeyword { + Enum(Box), + Struct(Box), + Union(Box), + Class(Box), + InterfaceClass(Box<(Keyword, Keyword)>), +} + +#[derive(Clone, Debug, Node)] +pub enum NetTypeDeclaration { + DataType(Box), + NetType(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct NetTypeDeclarationDataType { + pub nodes: ( + Keyword, + DataType, + NetTypeIdentifier, + Option<(Keyword, Option, TfIdentifier)>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct NetTypeDeclarationNetType { + pub nodes: ( + Keyword, + Option, + NetTypeIdentifier, + NetTypeIdentifier, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum Lifetime { + Static(Box), + Automatic(Box), +} diff --git a/sv-parser-syntaxtree/src/expressions/concatenations.rs b/sv-parser-syntaxtree/src/expressions/concatenations.rs new file mode 100644 index 0000000..2684c38 --- /dev/null +++ b/sv-parser-syntaxtree/src/expressions/concatenations.rs @@ -0,0 +1,87 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct Concatenation { + pub nodes: (Brace>,), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantConcatenation { + pub nodes: (Brace>,), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantMultipleConcatenation { + pub nodes: (Brace<(ConstantExpression, ConstantConcatenation)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct ModulePathConcatenation { + pub nodes: (Brace>,), +} + +#[derive(Clone, Debug, Node)] +pub struct ModulePathMultipleConcatenation { + pub nodes: (Brace<(ConstantExpression, ModulePathConcatenation)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct MultipleConcatenation { + pub nodes: (Brace<(Expression, Concatenation)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct StreamingConcatenation { + pub nodes: (Brace<(StreamOperator, Option, StreamConcatenation)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct StreamOperator { + pub nodes: (Symbol,), +} + +#[derive(Clone, Debug, Node)] +pub enum SliceSize { + SimpleType(Box), + ConstantExpression(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct StreamConcatenation { + pub nodes: (Brace>,), +} + +#[derive(Clone, Debug, Node)] +pub struct StreamExpression { + pub nodes: (Expression, Option<(Keyword, Bracket)>), +} + +#[derive(Clone, Debug, Node)] +pub enum ArrayRangeExpression { + Expression(Box), + Colon(Box), + PlusColon(Box), + MinusColon(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ArrayRangeExpressionColon { + pub nodes: (Expression, Symbol, Expression), +} + +#[derive(Clone, Debug, Node)] +pub struct ArrayRangeExpressionPlusColon { + pub nodes: (Expression, Symbol, Expression), +} + +#[derive(Clone, Debug, Node)] +pub struct ArrayRangeExpressionMinusColon { + pub nodes: (Expression, Symbol, Expression), +} + +#[derive(Clone, Debug, Node)] +pub struct EmptyUnpackedArrayConcatenation { + pub nodes: (Symbol, Symbol), +} diff --git a/sv-parser-syntaxtree/src/expressions/expression_leftside_values.rs b/sv-parser-syntaxtree/src/expressions/expression_leftside_values.rs new file mode 100644 index 0000000..8fd753e --- /dev/null +++ b/sv-parser-syntaxtree/src/expressions/expression_leftside_values.rs @@ -0,0 +1,67 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum NetLvalue { + Identifier(Box), + Lvalue(Box), + Pattern(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct NetLvalueIdentifier { + pub nodes: (PsOrHierarchicalNetIdentifier, ConstantSelect), +} + +#[derive(Clone, Debug, Node)] +pub struct NetLvalueLvalue { + pub nodes: (Brace>,), +} + +#[derive(Clone, Debug, Node)] +pub struct NetLvaluePattern { + pub nodes: ( + Option, + AssignmentPatternNetLvalue, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum VariableLvalue { + Identifier(Box), + Lvalue(Box), + Pattern(Box), + StreamingConcatenation(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct VariableLvalueIdentifier { + pub nodes: ( + Option, + HierarchicalVariableIdentifier, + Select, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct VariableLvalueLvalue { + pub nodes: (Brace>,), +} + +#[derive(Clone, Debug, Node)] +pub struct VariableLvaluePattern { + pub nodes: ( + Option, + AssignmentPatternVariableLvalue, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct NonrangeVariableLvalue { + pub nodes: ( + Option, + HierarchicalVariableIdentifier, + NonrangeSelect, + ), +} diff --git a/sv-parser-syntaxtree/src/expressions/expressions.rs b/sv-parser-syntaxtree/src/expressions/expressions.rs new file mode 100644 index 0000000..9aac152 --- /dev/null +++ b/sv-parser-syntaxtree/src/expressions/expressions.rs @@ -0,0 +1,255 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum IncOrDecExpression { + Prefix(Box), + Suffix(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct IncOrDecExpressionPrefix { + pub nodes: (IncOrDecOperator, Vec, VariableLvalue), +} + +#[derive(Clone, Debug, Node)] +pub struct IncOrDecExpressionSuffix { + pub nodes: (VariableLvalue, Vec, IncOrDecOperator), +} + +#[derive(Clone, Debug, Node)] +pub struct ConditionalExpression { + pub nodes: ( + CondPredicate, + Symbol, + Vec, + Expression, + Symbol, + Expression, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ConstantExpression { + ConstantPrimary(Box), + Unary(Box), + Binary(Box), + Ternary(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantExpressionUnary { + pub nodes: (UnaryOperator, Vec, ConstantPrimary), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantExpressionBinary { + pub nodes: ( + ConstantExpression, + BinaryOperator, + Vec, + ConstantExpression, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantExpressionTernary { + pub nodes: ( + ConstantExpression, + Symbol, + Vec, + ConstantExpression, + Symbol, + ConstantExpression, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ConstantMintypmaxExpression { + Unary(Box), + Ternary(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantMintypmaxExpressionTernary { + pub nodes: ( + ConstantExpression, + Symbol, + ConstantExpression, + Symbol, + ConstantExpression, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ConstantParamExpression { + ConstantMintypmaxExpression(Box), + DataType(Box), + Dollar(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum ParamExpression { + MintypmaxExpression(Box), + DataType(Box), + Dollar(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum ConstantRangeExpression { + ConstantExpression(Box), + ConstantPartSelectRange(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum ConstantPartSelectRange { + ConstantRange(Box), + ConstantIndexedRange(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantRange { + pub nodes: (ConstantExpression, Symbol, ConstantExpression), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantIndexedRange { + pub nodes: (ConstantExpression, Symbol, ConstantExpression), +} + +#[derive(Clone, Debug, Node)] +pub enum Expression { + Primary(Box), + Unary(Box), + IncOrDecExpression(Box), + OperatorAssignment(Box), + Binary(Box), + ConditionalExpression(Box), + InsideExpression(Box), + TaggedUnionExpression(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ExpressionUnary { + pub nodes: (UnaryOperator, Vec, Primary), +} + +#[derive(Clone, Debug, Node)] +pub struct ExpressionOperatorAssignment { + pub nodes: (Paren,), +} + +#[derive(Clone, Debug, Node)] +pub struct ExpressionBinary { + pub nodes: ( + Expression, + BinaryOperator, + Vec, + Expression, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct TaggedUnionExpression { + pub nodes: (Keyword, MemberIdentifier, Option), +} + +#[derive(Clone, Debug, Node)] +pub struct InsideExpression { + pub nodes: (Expression, Keyword, Brace), +} + +#[derive(Clone, Debug, Node)] +pub enum ValueRange { + Expression(Box), + Binary(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ValueRangeBinary { + pub nodes: (Bracket<(Expression, Symbol, Expression)>,), +} + +#[derive(Clone, Debug, Node)] +pub enum MintypmaxExpression { + Expression(Box), + Ternary(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct MintypmaxExpressionTernary { + pub nodes: (Expression, Symbol, Expression, Symbol, Expression), +} + +#[derive(Clone, Debug, Node)] +pub struct ModulePathConditionalExpression { + pub nodes: ( + ModulePathExpression, + Symbol, + Vec, + ModulePathExpression, + Symbol, + ModulePathExpression, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ModulePathExpression { + ModulePathPrimary(Box), + Unary(Box), + Binary(Box), + ModulePathConditionalExpression(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ModulePathExpressionUnary { + pub nodes: ( + UnaryModulePathOperator, + Vec, + ModulePathPrimary, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ModulePathExpressionBinary { + pub nodes: ( + ModulePathExpression, + BinaryModulePathOperator, + Vec, + ModulePathExpression, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ModulePathMintypmaxExpression { + ModulePathExpression(Box), + Ternary(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ModulePathMintypmaxExpressionTernary { + pub nodes: ( + ModulePathExpression, + Symbol, + ModulePathExpression, + Symbol, + ModulePathExpression, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum PartSelectRange { + ConstantRange(Box), + IndexedRange(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct IndexedRange { + pub nodes: (Expression, Symbol, ConstantExpression), +} + +#[derive(Clone, Debug, Node)] +pub struct GenvarExpression { + pub nodes: (ConstantExpression,), +} diff --git a/sv-parser/src/parser/expressions/mod.rs b/sv-parser-syntaxtree/src/expressions/mod.rs similarity index 100% rename from sv-parser/src/parser/expressions/mod.rs rename to sv-parser-syntaxtree/src/expressions/mod.rs diff --git a/sv-parser-syntaxtree/src/expressions/numbers.rs b/sv-parser-syntaxtree/src/expressions/numbers.rs new file mode 100644 index 0000000..ddfe78b --- /dev/null +++ b/sv-parser-syntaxtree/src/expressions/numbers.rs @@ -0,0 +1,153 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum Number { + IntegralNumber(Box), + RealNumber(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum IntegralNumber { + DecimalNumber(Box), + OctalNumber(Box), + BinaryNumber(Box), + HexNumber(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum DecimalNumber { + UnsignedNumber(Box), + BaseUnsigned(Box), + BaseXNumber(Box), + BaseZNumber(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct DecimalNumberBaseUnsigned { + pub nodes: (Option, DecimalBase, UnsignedNumber), +} + +#[derive(Clone, Debug, Node)] +pub struct DecimalNumberBaseXNumber { + pub nodes: (Option, DecimalBase, XNumber), +} + +#[derive(Clone, Debug, Node)] +pub struct DecimalNumberBaseZNumber { + pub nodes: (Option, DecimalBase, ZNumber), +} + +#[derive(Clone, Debug, Node)] +pub struct BinaryNumber { + pub nodes: (Option, BinaryBase, BinaryValue), +} + +#[derive(Clone, Debug, Node)] +pub struct OctalNumber { + pub nodes: (Option, OctalBase, OctalValue), +} + +#[derive(Clone, Debug, Node)] +pub struct HexNumber { + pub nodes: (Option, HexBase, HexValue), +} + +#[derive(Clone, Debug, Node)] +pub enum Sign { + Plus(Box), + Minus(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct Size { + pub nodes: (NonZeroUnsignedNumber,), +} + +#[derive(Clone, Debug, Node)] +pub struct NonZeroUnsignedNumber { + pub nodes: (Locate, Vec), +} + +#[derive(Clone, Debug, Node)] +pub enum RealNumber { + FixedPointNumber(Box), + Floating(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct RealNumberFloating { + pub nodes: ( + UnsignedNumber, + Option<(Symbol, UnsignedNumber)>, + Exp, + Option, + UnsignedNumber, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct FixedPointNumber { + pub nodes: (UnsignedNumber, Symbol, UnsignedNumber), +} + +#[derive(Clone, Debug, Node)] +pub struct Exp { + pub nodes: (Symbol,), +} + +#[derive(Clone, Debug, Node)] +pub struct UnsignedNumber { + pub nodes: (Locate, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct BinaryValue { + pub nodes: (Locate, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct OctalValue { + pub nodes: (Locate, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct HexValue { + pub nodes: (Locate, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct DecimalBase { + pub nodes: (Locate, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct BinaryBase { + pub nodes: (Locate, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct OctalBase { + pub nodes: (Locate, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct HexBase { + pub nodes: (Locate, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct XNumber { + pub nodes: (Locate, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct ZNumber { + pub nodes: (Locate, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct UnbasedUnsizedLiteral { + pub nodes: (Symbol,), +} diff --git a/sv-parser-syntaxtree/src/expressions/operators.rs b/sv-parser-syntaxtree/src/expressions/operators.rs new file mode 100644 index 0000000..3131ea3 --- /dev/null +++ b/sv-parser-syntaxtree/src/expressions/operators.rs @@ -0,0 +1,28 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct UnaryOperator { + pub nodes: (Symbol,), +} + +#[derive(Clone, Debug, Node)] +pub struct BinaryOperator { + pub nodes: (Symbol,), +} + +#[derive(Clone, Debug, Node)] +pub struct IncOrDecOperator { + pub nodes: (Symbol,), +} + +#[derive(Clone, Debug, Node)] +pub struct UnaryModulePathOperator { + pub nodes: (Symbol,), +} + +#[derive(Clone, Debug, Node)] +pub struct BinaryModulePathOperator { + pub nodes: (Symbol,), +} diff --git a/sv-parser-syntaxtree/src/expressions/primaries.rs b/sv-parser-syntaxtree/src/expressions/primaries.rs new file mode 100644 index 0000000..9aacc70 --- /dev/null +++ b/sv-parser-syntaxtree/src/expressions/primaries.rs @@ -0,0 +1,245 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum ConstantPrimary { + PrimaryLiteral(Box), + PsParameter(Box), + Specparam(Box), + GenvarIdentifier(Box), + FormalPort(Box), + Enum(Box), + Concatenation(Box), + MultipleConcatenation(Box), + ConstantFunctionCall(Box), + ConstantLetExpression(Box), + MintypmaxExpression(Box), + ConstantCast(Box), + ConstantAssignmentPatternExpression(Box), + TypeReference(Box), + Null(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantPrimaryPsParameter { + pub nodes: (PsParameterIdentifier, ConstantSelect), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantPrimarySpecparam { + pub nodes: ( + SpecparamIdentifier, + Option>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantPrimaryFormalPort { + pub nodes: (FormalPortIdentifier, ConstantSelect), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantPrimaryEnum { + pub nodes: (PackageScopeOrClassScope, EnumIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantPrimaryConcatenation { + pub nodes: ( + ConstantConcatenation, + Option>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantPrimaryMultipleConcatenation { + pub nodes: ( + ConstantMultipleConcatenation, + Option>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantPrimaryMintypmaxExpression { + pub nodes: (Paren,), +} + +#[derive(Clone, Debug, Node)] +pub enum ModulePathPrimary { + Number(Box), + Identifier(Box), + ModulePathConcatenation(Box), + ModulePathMultipleConcatenation(Box), + FunctionSubroutineCall(Box), + Mintypmax(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ModulePathPrimaryMintypmax { + pub nodes: (Paren,), +} + +#[derive(Clone, Debug, Node)] +pub enum Primary { + PrimaryLiteral(Box), + Hierarchical(Box), + EmptyUnpackedArrayConcatenation(Box), + Concatenation(Box), + MultipleConcatenation(Box), + FunctionSubroutineCall(Box), + LetExpression(Box), + MintypmaxExpression(Box), + Cast(Box), + AssignmentPatternExpression(Box), + StreamingConcatenation(Box), + SequenceMethodCall(Box), + This(Box), + Dollar(Box), + Null(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PrimaryHierarchical { + pub nodes: ( + Option, + HierarchicalIdentifier, + Select, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct PrimaryConcatenation { + pub nodes: (Concatenation, Option>), +} + +#[derive(Clone, Debug, Node)] +pub struct PrimaryMultipleConcatenation { + pub nodes: (MultipleConcatenation, Option>), +} + +#[derive(Clone, Debug, Node)] +pub struct PrimaryMintypmaxExpression { + pub nodes: (Paren,), +} + +#[derive(Clone, Debug, Node)] +pub enum ClassQualifierOrPackageScope { + ClassQualifier(Box), + PackageScope(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassQualifier { + pub nodes: (Option, Option), +} + +#[derive(Clone, Debug, Node)] +pub enum RangeExpression { + Expression(Box), + PartSelectRange(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum PrimaryLiteral { + Number(Box), + TimeLiteral(Box), + UnbasedUnsizedLiteral(Box), + StringLiteral(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum TimeLiteral { + Unsigned(Box), + FixedPoint(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct TimeLiteralUnsigned { + pub nodes: (UnsignedNumber, TimeUnit), +} + +#[derive(Clone, Debug, Node)] +pub struct TimeLiteralFixedPoint { + pub nodes: (FixedPointNumber, TimeUnit), +} + +#[derive(Clone, Debug, Node)] +pub enum TimeUnit { + S(Box), + MS(Box), + US(Box), + NS(Box), + PS(Box), + FS(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum ImplicitClassHandle { + This(Box), + Super(Box), + ThisSuper(Box<(Keyword, Symbol, Keyword)>), +} + +#[derive(Clone, Debug, Node)] +pub struct BitSelect { + pub nodes: (Vec>,), +} + +#[derive(Clone, Debug, Node)] +pub struct Select { + pub nodes: ( + Option<( + Vec<(Symbol, MemberIdentifier, BitSelect)>, + Symbol, + MemberIdentifier, + )>, + BitSelect, + Option>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct NonrangeSelect { + pub nodes: ( + Option<( + Vec<(Symbol, MemberIdentifier, BitSelect)>, + Symbol, + MemberIdentifier, + )>, + BitSelect, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantBitSelect { + pub nodes: (Vec>,), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantSelect { + pub nodes: ( + Option<( + Vec<(Symbol, MemberIdentifier, ConstantBitSelect)>, + Symbol, + MemberIdentifier, + )>, + ConstantBitSelect, + Option>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantCast { + pub nodes: (CastingType, Symbol, Paren), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstantLetExpression { + pub nodes: (LetExpression,), +} + +#[derive(Clone, Debug, Node)] +pub struct Cast { + pub nodes: (CastingType, Symbol, Paren), +} diff --git a/sv-parser-syntaxtree/src/expressions/strings.rs b/sv-parser-syntaxtree/src/expressions/strings.rs new file mode 100644 index 0000000..9128761 --- /dev/null +++ b/sv-parser-syntaxtree/src/expressions/strings.rs @@ -0,0 +1,8 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct StringLiteral { + pub nodes: (Locate, Vec), +} diff --git a/sv-parser-syntaxtree/src/expressions/subroutine_calls.rs b/sv-parser-syntaxtree/src/expressions/subroutine_calls.rs new file mode 100644 index 0000000..c110414 --- /dev/null +++ b/sv-parser-syntaxtree/src/expressions/subroutine_calls.rs @@ -0,0 +1,161 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct ConstantFunctionCall { + pub nodes: (FunctionSubroutineCall,), +} + +#[derive(Clone, Debug, Node)] +pub struct TfCall { + pub nodes: ( + PsOrHierarchicalTfIdentifier, + Vec, + Option>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum SystemTfCall { + ArgOptionl(Box), + ArgDataType(Box), + ArgExpression(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct SystemTfCallArgOptional { + pub nodes: (SystemTfIdentifier, Option>), +} + +#[derive(Clone, Debug, Node)] +pub struct SystemTfCallArgDataType { + pub nodes: ( + SystemTfIdentifier, + Paren<(DataType, Option<(Symbol, Expression)>)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct SystemTfCallArgExpression { + pub nodes: ( + SystemTfIdentifier, + Paren<( + List>, + Option<(Symbol, Option)>, + )>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum SubroutineCall { + TfCall(Box), + SystemTfCall(Box), + MethodCall(Box), + Randomize(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct SubroutineCallRandomize { + pub nodes: (Option<(Keyword, Symbol)>, RandomizeCall), +} + +#[derive(Clone, Debug, Node)] +pub struct FunctionSubroutineCall { + pub nodes: (SubroutineCall,), +} + +#[derive(Clone, Debug, Node)] +pub enum ListOfArguments { + Ordered(Box), + Named(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfArgumentsOrdered { + pub nodes: ( + List>, + Vec<(Symbol, Symbol, Identifier, Paren>)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfArgumentsNamed { + pub nodes: ( + Symbol, + Identifier, + Paren>, + Vec<(Symbol, Symbol, Identifier, Paren>)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct MethodCall { + pub nodes: (MethodCallRoot, Symbol, MethodCallBody), +} + +#[derive(Clone, Debug, Node)] +pub enum MethodCallBody { + User(Box), + BuiltInMethodCall(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct MethodCallBodyUser { + pub nodes: ( + MethodIdentifier, + Vec, + Option>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum BuiltInMethodCall { + ArrayManipulationCall(Box), + RandomizeCall(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ArrayManipulationCall { + pub nodes: ( + ArrayMethodName, + Vec, + Option>, + Option<(Keyword, Paren)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct RandomizeCall { + pub nodes: ( + Keyword, + Vec, + Option>>, + Option<( + Keyword, + Option>>, + ConstraintBlock, + )>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum VariableIdentifierListOrNull { + VariableIdentifierList(Box), + Null(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum MethodCallRoot { + Primary(Box), + ImplicitClassHandle(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum ArrayMethodName { + MethodIdentifier(Box), + Unique(Box), + And(Box), + Or(Box), + Xor(Box), +} diff --git a/sv-parser-syntaxtree/src/general/attributes.rs b/sv-parser-syntaxtree/src/general/attributes.rs new file mode 100644 index 0000000..a948353 --- /dev/null +++ b/sv-parser-syntaxtree/src/general/attributes.rs @@ -0,0 +1,13 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct AttributeInstance { + pub nodes: (Symbol, List, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct AttrSpec { + pub nodes: (Identifier, Option<(Symbol, ConstantExpression)>), +} diff --git a/sv-parser-syntaxtree/src/general/comments.rs b/sv-parser-syntaxtree/src/general/comments.rs new file mode 100644 index 0000000..d3e05b8 --- /dev/null +++ b/sv-parser-syntaxtree/src/general/comments.rs @@ -0,0 +1,8 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct Comment { + pub nodes: (Locate,), +} diff --git a/sv-parser-syntaxtree/src/general/identifiers.rs b/sv-parser-syntaxtree/src/general/identifiers.rs new file mode 100644 index 0000000..c3b2a52 --- /dev/null +++ b/sv-parser-syntaxtree/src/general/identifiers.rs @@ -0,0 +1,526 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct ArrayIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct BlockIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct BinIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct CIdentifier { + pub nodes: (Locate, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct CellIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct CheckerIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassVariableIdentifier { + pub nodes: (VariableIdentifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct ClockingIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct ConfigIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstraintIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct CovergroupIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct CovergroupVariableIdentifier { + pub nodes: (VariableIdentifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct CoverPointIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct CrossIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct DynamicArrayVariableIdentifier { + pub nodes: (VariableIdentifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct EnumIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct EscapedIdentifier { + pub nodes: (Locate, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct FormalIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct FormalPortIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct FunctionIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct GenerateBlockIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct GenvarIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct HierarchicalArrayIdentifier { + pub nodes: (HierarchicalIdentifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct HierarchicalBlockIdentifier { + pub nodes: (HierarchicalIdentifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct HierarchicalEventIdentifier { + pub nodes: (HierarchicalIdentifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct HierarchicalIdentifier { + pub nodes: ( + Option, + Vec<(Identifier, ConstantBitSelect, Symbol)>, + Identifier, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct Root { + pub nodes: (Keyword, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct HierarchicalNetIdentifier { + pub nodes: (HierarchicalIdentifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct HierarchicalParameterIdentifier { + pub nodes: (HierarchicalIdentifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct HierarchicalPropertyIdentifier { + pub nodes: (HierarchicalIdentifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct HierarchicalSequenceIdentifier { + pub nodes: (HierarchicalIdentifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct HierarchicalTaskIdentifier { + pub nodes: (HierarchicalIdentifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct HierarchicalTfIdentifier { + pub nodes: (HierarchicalIdentifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct HierarchicalVariableIdentifier { + pub nodes: (HierarchicalIdentifier,), +} + +#[derive(Clone, Debug, Node)] +pub enum Identifier { + SimpleIdentifier(Box), + EscapedIdentifier(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct IndexVariableIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfaceIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfaceInstanceIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct InoutPortIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct InputPortIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct InstanceIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct LibraryIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct MemberIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct MethodIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct ModportIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct ModuleIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct NetIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct NetTypeIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct OutputPortIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct PackageIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub enum PackageScope { + Package(Box), + Unit(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PackageScopePackage { + pub nodes: (PackageIdentifier, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct Unit { + pub nodes: (Keyword, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct ParameterIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct PortIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct ProductionIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct ProgramIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct PropertyIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct PsClassIdentifier { + pub nodes: (Option, ClassIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub struct PsCovergroupIdentifier { + pub nodes: (Option, CovergroupIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub struct PsCheckerIdentifier { + pub nodes: (Option, CheckerIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub struct PsIdentifier { + pub nodes: (Option, Identifier), +} + +#[derive(Clone, Debug, Node)] +pub struct PsOrHierarchicalArrayIdentifier { + pub nodes: ( + Option, + HierarchicalArrayIdentifier, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum PsOrHierarchicalNetIdentifier { + PackageScope(Box), + HierarchicalNetIdentifier(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PsOrHierarchicalNetIdentifierPackageScope { + pub nodes: (Option, NetIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub struct PsOrHierarchicalNetIdentifierHierarchical { + pub nodes: (HierarchicalNetIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub enum PsOrHierarchicalPropertyIdentifier { + PackageScope(Box), + HierarchicalPropertyIdentifier(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PsOrHierarchicalPropertyIdentifierPackageScope { + pub nodes: (Option, PropertyIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub struct PsOrHierarchicalPropertyIdentifierHierarchical { + pub nodes: (HierarchicalPropertyIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub enum PsOrHierarchicalSequenceIdentifier { + PackageScope(Box), + HierarchicalSequenceIdentifier(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PsOrHierarchicalSequenceIdentifierPackageScope { + pub nodes: (Option, SequenceIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub struct PsOrHierarchicalSequenceIdentifierHierarchical { + pub nodes: (HierarchicalSequenceIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub enum PsOrHierarchicalTfIdentifier { + PackageScope(Box), + HierarchicalTfIdentifier(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PsOrHierarchicalTfIdentifierPackageScope { + pub nodes: (Option, TfIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub struct PsOrHierarchicalTfIdentifierHierarchical { + pub nodes: (HierarchicalTfIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub enum PsParameterIdentifier { + Scope(Box), + Generate(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PsParameterIdentifierScope { + pub nodes: (Option, ParameterIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub struct PsParameterIdentifierGenerate { + pub nodes: ( + Vec<( + GenerateBlockIdentifier, + Option>, + Symbol, + )>, + ParameterIdentifier, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct PsTypeIdentifier { + pub nodes: (Option, TypeIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub enum LocalOrPackageScopeOrClassScope { + Local(Box), + PackageScope(Box), + ClassScope(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct Local { + pub nodes: (Keyword, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct SequenceIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct SignalIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct SimpleIdentifier { + pub nodes: (Locate, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct SpecparamIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct SystemTfIdentifier { + pub nodes: (Locate, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct TaskIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct TfIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct TerminalIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct TopmoduleIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct TypeIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct UdpIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct VariableIdentifier { + pub nodes: (Identifier,), +} + +#[derive(Clone, Debug, Node)] +pub enum ImplicitClassHandleOrClassScopeOrPackageScope { + ImplicitClassHandle(Box<(ImplicitClassHandle, Symbol)>), + ClassScope(Box), + PackageScope(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum ImplicitClassHandleOrPackageScope { + ImplicitClassHandle(Box<(ImplicitClassHandle, Symbol)>), + PackageScope(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum ImplicitClassHandleOrClassScope { + ImplicitClassHandle(Box<(ImplicitClassHandle, Symbol)>), + ClassScope(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum PackageScopeOrClassScope { + PackageScope(Box), + ClassScope(Box), +} diff --git a/sv-parser/src/parser/general/mod.rs b/sv-parser-syntaxtree/src/general/mod.rs similarity index 100% rename from sv-parser/src/parser/general/mod.rs rename to sv-parser-syntaxtree/src/general/mod.rs diff --git a/sv-parser-syntaxtree/src/instantiations/checker_instantiation.rs b/sv-parser-syntaxtree/src/instantiations/checker_instantiation.rs new file mode 100644 index 0000000..ece25e3 --- /dev/null +++ b/sv-parser-syntaxtree/src/instantiations/checker_instantiation.rs @@ -0,0 +1,55 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct CheckerInstantiation { + pub nodes: ( + PsCheckerIdentifier, + NameOfInstance, + Paren>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ListOfCheckerPortConnections { + Ordered(Box), + Named(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfCheckerPortConnectionsOrdered { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfCheckerPortConnectionsNamed { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct OrderedCheckerPortConnection { + pub nodes: (Vec, Option), +} + +#[derive(Clone, Debug, Node)] +pub enum NamedCheckerPortConnection { + Identifier(Box), + Asterisk(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct NamedCheckerPortConnectionIdentifier { + pub nodes: ( + Vec, + Symbol, + FormalPortIdentifier, + Option>>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct NamedCheckerPortConnectionAsterisk { + pub nodes: (Vec, Symbol), +} diff --git a/sv-parser-syntaxtree/src/instantiations/generated_instantiation.rs b/sv-parser-syntaxtree/src/instantiations/generated_instantiation.rs new file mode 100644 index 0000000..45c8051 --- /dev/null +++ b/sv-parser-syntaxtree/src/instantiations/generated_instantiation.rs @@ -0,0 +1,122 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct GenerateRegion { + pub nodes: (Keyword, Vec, Keyword), +} + +#[derive(Clone, Debug, Node)] +pub struct LoopGenerateConstruct { + pub nodes: ( + Keyword, + Paren<( + GenvarInitialization, + Symbol, + GenvarExpression, + Symbol, + GenvarIteration, + )>, + GenerateBlock, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct GenvarInitialization { + pub nodes: (Option, GenvarIdentifier, Symbol, ConstantExpression), +} + +#[derive(Clone, Debug, Node)] +pub struct Genvar { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub enum GenvarIteration { + Assignment(Box), + Prefix(Box), + Suffix(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct GenvarIterationAssignment { + pub nodes: (GenvarIdentifier, AssignmentOperator, GenvarExpression), +} + +#[derive(Clone, Debug, Node)] +pub struct GenvarIterationPrefix { + pub nodes: (IncOrDecOperator, GenvarIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub struct GenvarIterationSuffix { + pub nodes: (GenvarIdentifier, IncOrDecOperator), +} + +#[derive(Clone, Debug, Node)] +pub enum ConditionalGenerateConstruct { + If(Box), + Case(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct IfGenerateConstruct { + pub nodes: ( + Keyword, + Paren, + GenerateBlock, + Option<(Keyword, GenerateBlock)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct CaseGenerateConstruct { + pub nodes: ( + Keyword, + Paren, + Vec, + Keyword, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum CaseGenerateItem { + Nondefault(Box), + Default(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CaseGenerateItemNondefault { + pub nodes: (List, Symbol, GenerateBlock), +} + +#[derive(Clone, Debug, Node)] +pub struct CaseGenerateItemDefault { + pub nodes: (Keyword, Option, GenerateBlock), +} + +#[derive(Clone, Debug, Node)] +pub enum GenerateBlock { + GenerateItem(Box), + Multiple(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct GenerateBlockMultiple { + pub nodes: ( + Option<(GenerateBlockIdentifier, Symbol)>, + Keyword, + Option<(Symbol, GenerateBlockIdentifier)>, + Vec, + Keyword, + Option<(Symbol, GenerateBlockIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum GenerateItem { + ModuleOrGenerateItem(Box), + InterfaceOrGenerateItem(Box), + CheckerOrGenerateItem(Box), +} diff --git a/sv-parser-syntaxtree/src/instantiations/interface_instantiation.rs b/sv-parser-syntaxtree/src/instantiations/interface_instantiation.rs new file mode 100644 index 0000000..cff8709 --- /dev/null +++ b/sv-parser-syntaxtree/src/instantiations/interface_instantiation.rs @@ -0,0 +1,13 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct InterfaceInstantiation { + pub nodes: ( + InterfaceIdentifier, + Option, + List, + Symbol, + ), +} diff --git a/sv-parser/src/parser/instantiations/mod.rs b/sv-parser-syntaxtree/src/instantiations/mod.rs similarity index 100% rename from sv-parser/src/parser/instantiations/mod.rs rename to sv-parser-syntaxtree/src/instantiations/mod.rs diff --git a/sv-parser-syntaxtree/src/instantiations/module_instantiation.rs b/sv-parser-syntaxtree/src/instantiations/module_instantiation.rs new file mode 100644 index 0000000..0ddce8d --- /dev/null +++ b/sv-parser-syntaxtree/src/instantiations/module_instantiation.rs @@ -0,0 +1,96 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct ModuleInstantiation { + pub nodes: ( + ModuleIdentifier, + Option, + List, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ParameterValueAssignment { + pub nodes: (Symbol, Paren>), +} + +#[derive(Clone, Debug, Node)] +pub enum ListOfParameterAssignments { + Ordered(Box), + Named(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfParameterAssignmentsOrdered { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfParameterAssignmentsNamed { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct OrderedParameterAssignment { + pub nodes: (ParamExpression,), +} + +#[derive(Clone, Debug, Node)] +pub struct NamedParameterAssignment { + pub nodes: (Symbol, ParameterIdentifier, Paren>), +} + +#[derive(Clone, Debug, Node)] +pub struct HierarchicalInstance { + pub nodes: (NameOfInstance, Paren>), +} + +#[derive(Clone, Debug, Node)] +pub struct NameOfInstance { + pub nodes: (InstanceIdentifier, Vec), +} + +#[derive(Clone, Debug, Node)] +pub enum ListOfPortConnections { + Ordered(Box), + Named(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfPortConnectionsOrdered { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfPortConnectionsNamed { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct OrderedPortConnection { + pub nodes: (Vec, Option), +} + +#[derive(Clone, Debug, Node)] +pub enum NamedPortConnection { + Identifier(Box), + Asterisk(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct NamedPortConnectionIdentifier { + pub nodes: ( + Vec, + Symbol, + PortIdentifier, + Option>>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct NamedPortConnectionAsterisk { + pub nodes: (Vec, Symbol), +} diff --git a/sv-parser-syntaxtree/src/instantiations/program_instantiation.rs b/sv-parser-syntaxtree/src/instantiations/program_instantiation.rs new file mode 100644 index 0000000..ed96561 --- /dev/null +++ b/sv-parser-syntaxtree/src/instantiations/program_instantiation.rs @@ -0,0 +1,13 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct ProgramInstantiation { + pub nodes: ( + ProgramIdentifier, + Option, + List, + Symbol, + ), +} diff --git a/sv-parser-syntaxtree/src/lib.rs b/sv-parser-syntaxtree/src/lib.rs new file mode 100644 index 0000000..b10e66a --- /dev/null +++ b/sv-parser-syntaxtree/src/lib.rs @@ -0,0 +1,70 @@ +#![recursion_limit = "256"] + +pub mod any_node; +pub mod behavioral_statements; +pub mod declarations; +pub mod expressions; +pub mod general; +pub mod instantiations; +pub mod primitive_instances; +pub mod source_text; +pub mod special_node; +pub mod specify_section; +pub mod udp_declaration_and_instantiation; +pub use any_node::*; +pub use behavioral_statements::*; +pub use declarations::*; +pub use expressions::*; +pub use general::*; +pub use instantiations::*; +pub use primitive_instances::*; +pub use source_text::*; +pub use special_node::*; +pub use specify_section::*; +pub use udp_declaration_and_instantiation::*; + +pub(crate) use sv_parser_macros::*; + +// ----------------------------------------------------------------------------- + +pub const RECURSIVE_FLAG_WORDS: usize = 1; + +#[derive(Copy, Clone, Default, Debug, PartialEq)] +pub struct Extra { + #[cfg(feature = "trace")] + pub depth: usize, + pub recursive_flag: [u128; RECURSIVE_FLAG_WORDS], +} + +pub type Span<'a> = nom_locate::LocatedSpanEx<&'a str, Extra>; + +// ----------------------------------------------------------------------------- + +#[derive(Copy, Clone, Default, Debug, PartialEq)] +pub struct Locate { + offset: usize, + line: u32, + len: usize, +} + +impl<'a> From> for Locate { + fn from(x: Span<'a>) -> Self { + Locate { + offset: x.offset, + line: x.line, + len: x.fragment.len(), + } + } +} + +// ----------------------------------------------------------------------------- + +pub trait Node<'a> { + fn next(&'a self) -> RefNodes<'a>; +} + +impl<'a> Node<'a> for Locate { + fn next(&'a self) -> RefNodes<'a> { + vec![].into() + } +} diff --git a/sv-parser/src/parser/primitive_instances/mod.rs b/sv-parser-syntaxtree/src/primitive_instances/mod.rs similarity index 100% rename from sv-parser/src/parser/primitive_instances/mod.rs rename to sv-parser-syntaxtree/src/primitive_instances/mod.rs diff --git a/sv-parser-syntaxtree/src/primitive_instances/primitive_gate_and_switch_types.rs b/sv-parser-syntaxtree/src/primitive_instances/primitive_gate_and_switch_types.rs new file mode 100644 index 0000000..9ff1802 --- /dev/null +++ b/sv-parser-syntaxtree/src/primitive_instances/primitive_gate_and_switch_types.rs @@ -0,0 +1,38 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct CmosSwitchtype { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct EnableGatetype { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct MosSwitchtype { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct NInputGatetype { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct NOutputGatetype { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct PassEnSwitchtype { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct PassSwitchtype { + pub nodes: (Keyword,), +} diff --git a/sv-parser-syntaxtree/src/primitive_instances/primitive_instantiation_and_instances.rs b/sv-parser-syntaxtree/src/primitive_instances/primitive_instantiation_and_instances.rs new file mode 100644 index 0000000..d0ecd04 --- /dev/null +++ b/sv-parser-syntaxtree/src/primitive_instances/primitive_instantiation_and_instances.rs @@ -0,0 +1,185 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum GateInstantiation { + Cmos(Box), + Enable(Box), + Mos(Box), + NInput(Box), + NOutput(Box), + PassEn(Box), + Pass(Box), + Pulldown(Box), + Pullup(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct GateInstantiationCmos { + pub nodes: ( + CmosSwitchtype, + Option, + List, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct GateInstantiationEnable { + pub nodes: ( + EnableGatetype, + Option, + Option, + List, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct GateInstantiationMos { + pub nodes: ( + MosSwitchtype, + Option, + List, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct GateInstantiationNInput { + pub nodes: ( + NInputGatetype, + Option, + Option, + List, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct GateInstantiationNOutput { + pub nodes: ( + NOutputGatetype, + Option, + Option, + List, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct GateInstantiationPassEn { + pub nodes: ( + PassEnSwitchtype, + Option, + List, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct GateInstantiationPass { + pub nodes: (PassSwitchtype, List, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct GateInstantiationPulldown { + pub nodes: ( + Keyword, + Option, + List, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct GateInstantiationPullup { + pub nodes: ( + Keyword, + Option, + List, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct CmosSwitchInstance { + pub nodes: ( + Option, + Paren<( + OutputTerminal, + Symbol, + InputTerminal, + Symbol, + NcontrolTerminal, + Symbol, + PcontrolTerminal, + )>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct EnableGateInstance { + pub nodes: ( + Option, + Paren<( + OutputTerminal, + Symbol, + InputTerminal, + Symbol, + EnableTerminal, + )>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct MosSwitchInstance { + pub nodes: ( + Option, + Paren<( + OutputTerminal, + Symbol, + InputTerminal, + Symbol, + EnableTerminal, + )>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct NInputGateInstance { + pub nodes: ( + Option, + Paren<(OutputTerminal, Symbol, List)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct NOutputGateInstance { + pub nodes: ( + Option, + Paren<(List, Symbol, InputTerminal)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct PassSwitchInstance { + pub nodes: ( + Option, + Paren<(InoutTerminal, Symbol, InoutTerminal)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct PassEnableSwitchInstance { + pub nodes: ( + Option, + Paren<(InoutTerminal, Symbol, InoutTerminal, Symbol, EnableTerminal)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct PullGateInstance { + pub nodes: (Option, Paren), +} diff --git a/sv-parser-syntaxtree/src/primitive_instances/primitive_strengths.rs b/sv-parser-syntaxtree/src/primitive_instances/primitive_strengths.rs new file mode 100644 index 0000000..be13c5a --- /dev/null +++ b/sv-parser-syntaxtree/src/primitive_instances/primitive_strengths.rs @@ -0,0 +1,47 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum PulldownStrength { + Strength01(Box), + Strength10(Box), + Strength0(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PulldownStrength01 { + pub nodes: (Paren<(Strength0, Symbol, Strength1)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct PulldownStrength10 { + pub nodes: (Paren<(Strength1, Symbol, Strength0)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct PulldownStrength0 { + pub nodes: (Paren,), +} + +#[derive(Clone, Debug, Node)] +pub enum PullupStrength { + Strength01(Box), + Strength10(Box), + Strength1(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PullupStrength01 { + pub nodes: (Paren<(Strength0, Symbol, Strength1)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct PullupStrength10 { + pub nodes: (Paren<(Strength1, Symbol, Strength0)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct PullupStrength1 { + pub nodes: (Paren,), +} diff --git a/sv-parser-syntaxtree/src/primitive_instances/primitive_terminals.rs b/sv-parser-syntaxtree/src/primitive_instances/primitive_terminals.rs new file mode 100644 index 0000000..e87c9c1 --- /dev/null +++ b/sv-parser-syntaxtree/src/primitive_instances/primitive_terminals.rs @@ -0,0 +1,33 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct EnableTerminal { + pub nodes: (Expression,), +} + +#[derive(Clone, Debug, Node)] +pub struct InoutTerminal { + pub nodes: (NetLvalue,), +} + +#[derive(Clone, Debug, Node)] +pub struct InputTerminal { + pub nodes: (Expression,), +} + +#[derive(Clone, Debug, Node)] +pub struct NcontrolTerminal { + pub nodes: (Expression,), +} + +#[derive(Clone, Debug, Node)] +pub struct OutputTerminal { + pub nodes: (NetLvalue,), +} + +#[derive(Clone, Debug, Node)] +pub struct PcontrolTerminal { + pub nodes: (Expression,), +} diff --git a/sv-parser-syntaxtree/src/source_text/checker_items.rs b/sv-parser-syntaxtree/src/source_text/checker_items.rs new file mode 100644 index 0000000..aeabea3 --- /dev/null +++ b/sv-parser-syntaxtree/src/source_text/checker_items.rs @@ -0,0 +1,79 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct CheckerPortList { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct CheckerPortItem { + pub nodes: ( + Vec, + Option, + PropertyFormalType, + FormalPortIdentifier, + Vec, + Option<(Symbol, PropertyActualArg)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum CheckerPortDirection { + Input(Box), + Output(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum CheckerOrGenerateItem { + CheckerOrGenerateItemDeclaration(Box), + InitialConstruct(Box), + AlwaysConstruct(Box), + FinalConstruct(Box), + AssertionItem(Box), + ContinuousAssign(Box), + CheckerGenerateItem(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum CheckerOrGenerateItemDeclaration { + Data(Box), + FunctionDeclaration(Box), + CheckerDeclaration(Box), + AssertionItemDeclaration(Box), + CovergroupDeclaration(Box), + GenvarDeclaration(Box), + ClockingDeclaration(Box), + Clocking(Box), + Disable(Box), + Empty(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CheckerOrGenerateItemDeclarationData { + pub nodes: (Option, DataDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct Rand { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct CheckerOrGenerateItemDeclarationClocking { + pub nodes: (Keyword, Keyword, ClockingIdentifier, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct CheckerOrGenerateItemDeclarationDisable { + pub nodes: (Keyword, Keyword, Keyword, ExpressionOrDist, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub enum CheckerGenerateItem { + LoopGenerateConstruct(Box), + ConditionalGenerateConstruct(Box), + GenerateRegion(Box), + ElaborationSystemTask(Box), +} diff --git a/sv-parser-syntaxtree/src/source_text/class_items.rs b/sv-parser-syntaxtree/src/source_text/class_items.rs new file mode 100644 index 0000000..10c10b2 --- /dev/null +++ b/sv-parser-syntaxtree/src/source_text/class_items.rs @@ -0,0 +1,179 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum ClassItem { + Property(Box), + Method(Box), + Constraint(Box), + Declaration(Box), + Covergroup(Box), + LocalParameterDeclaration(Box<(LocalParameterDeclaration, Symbol)>), + ParameterDeclaration(Box<(ParameterDeclaration, Symbol)>), + Empty(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassItemProperty { + pub nodes: (Vec, ClassProperty), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassItemMethod { + pub nodes: (Vec, ClassMethod), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassItemConstraint { + pub nodes: (Vec, ClassConstraint), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassItemDeclaration { + pub nodes: (Vec, ClassDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassItemCovergroup { + pub nodes: (Vec, CovergroupDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub enum ClassProperty { + NonConst(Box), + Const(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassPropertyNonConst { + pub nodes: (Vec, DataDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassPropertyConst { + pub nodes: ( + Keyword, + Vec, + DataType, + ConstIdentifier, + Option<(Symbol, ConstantExpression)>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ClassMethod { + Task(Box), + Function(Box), + PureVirtual(Box), + ExternMethod(Box), + Constructor(Box), + ExternConstructor(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassMethodTask { + pub nodes: (Vec, TaskDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassMethodFunction { + pub nodes: (Vec, FunctionDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassMethodPureVirtual { + pub nodes: ( + Keyword, + Keyword, + Vec, + MethodPrototype, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassMethodExternMethod { + pub nodes: (Keyword, Vec, MethodPrototype, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassMethodConstructor { + pub nodes: (Vec, ClassConstructorDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassMethodExternConstructor { + pub nodes: (Keyword, Vec, ClassConstructorPrototype), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassConstructorPrototype { + pub nodes: (Keyword, Keyword, Option>>, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub enum ClassConstraint { + ConstraintPrototype(Box), + ConstraintDeclaration(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum ClassItemQualifier { + Static(Box), + Protected(Box), + Local(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum PropertyQualifier { + RandomQualifier(Box), + ClassItemQualifier(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum RandomQualifier { + Rand(Box), + Randc(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum MethodQualifier { + Virtual(Box), + PureVirtual(Box<(Keyword, Keyword)>), + ClassItemQualifier(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum MethodPrototype { + TaskPrototype(Box), + FunctionPrototype(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassConstructorDeclaration { + pub nodes: ( + Keyword, + Option, + Keyword, + Option>>, + Symbol, + Vec, + Option<( + Keyword, + Symbol, + Keyword, + Option>, + Symbol, + )>, + Vec, + Keyword, + Option<(Symbol, New)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct New { + pub nodes: (Keyword,), +} diff --git a/sv-parser-syntaxtree/src/source_text/configuration_source_text.rs b/sv-parser-syntaxtree/src/source_text/configuration_source_text.rs new file mode 100644 index 0000000..cca62d4 --- /dev/null +++ b/sv-parser-syntaxtree/src/source_text/configuration_source_text.rs @@ -0,0 +1,127 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct ConfigDeclaration { + pub nodes: ( + Keyword, + ConfigIdentifier, + Symbol, + Vec<(LocalParameterDeclaration, Symbol)>, + DesignStatement, + Vec, + Keyword, + Option<(Symbol, ConfigIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct DesignStatement { + pub nodes: ( + Keyword, + Vec<(Option<(LibraryIdentifier, Symbol)>, CellIdentifier)>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ConfigRuleStatement { + Default(Box), + InstLib(Box), + InstUse(Box), + CellLib(Box), + CellUse(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ConfigRuleStatementDefault { + pub nodes: (DefaultClause, LiblistClause, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct ConfigRuleStatementInstLib { + pub nodes: (InstClause, LiblistClause, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct ConfigRuleStatementInstUse { + pub nodes: (InstClause, UseClause, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct ConfigRuleStatementCellLib { + pub nodes: (CellClause, LiblistClause, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct ConfigRuleStatementCellUse { + pub nodes: (CellClause, UseClause, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct DefaultClause { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct InstClause { + pub nodes: (Keyword, InstName), +} + +#[derive(Clone, Debug, Node)] +pub struct InstName { + pub nodes: (TopmoduleIdentifier, Vec<(Symbol, InstanceIdentifier)>), +} + +#[derive(Clone, Debug, Node)] +pub struct CellClause { + pub nodes: (Keyword, Option<(LibraryIdentifier, Symbol)>, CellIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub struct LiblistClause { + pub nodes: (Keyword, Vec), +} + +#[derive(Clone, Debug, Node)] +pub enum UseClause { + Cell(Box), + Named(Box), + CellNamed(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct UseClauseCell { + pub nodes: ( + Keyword, + Option<(LibraryIdentifier, Symbol)>, + CellIdentifier, + Option<(Symbol, Config)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct UseClauseNamed { + pub nodes: ( + Keyword, + List, + Option<(Symbol, Config)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct UseClauseCellNamed { + pub nodes: ( + Keyword, + Option<(LibraryIdentifier, Symbol)>, + CellIdentifier, + List, + Option<(Symbol, Config)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct Config { + pub nodes: (Keyword,), +} diff --git a/sv-parser-syntaxtree/src/source_text/constraints.rs b/sv-parser-syntaxtree/src/source_text/constraints.rs new file mode 100644 index 0000000..c073170 --- /dev/null +++ b/sv-parser-syntaxtree/src/source_text/constraints.rs @@ -0,0 +1,172 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct ConstraintDeclaration { + pub nodes: ( + Option, + Keyword, + ConstraintIdentifier, + ConstraintBlock, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct Static { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstraintBlock { + pub nodes: (Brace>,), +} + +#[derive(Clone, Debug, Node)] +pub enum ConstraintBlockItem { + Solve(Box), + ConstraintExpression(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstraintBlockItemSolve { + pub nodes: (Keyword, SolveBeforeList, Keyword, SolveBeforeList, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct SolveBeforeList { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstraintPrimary { + pub nodes: ( + Option, + HierarchicalIdentifier, + Select, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ConstraintExpression { + Expression(Box), + UniquenessConstraint(Box<(UniquenessConstraint, Symbol)>), + Arrow(Box), + If(Box), + Foreach(Box), + Disable(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstraintExpressionExpression { + pub nodes: (Option, ExpressionOrDist, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct Soft { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstraintExpressionArrow { + pub nodes: (Expression, Symbol, ConstraintSet), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstraintExpressionIf { + pub nodes: ( + Keyword, + Paren, + ConstraintSet, + Option<(Keyword, ConstraintSet)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstraintExpressionForeach { + pub nodes: ( + Keyword, + Paren<(PsOrHierarchicalArrayIdentifier, Bracket)>, + ConstraintSet, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstraintExpressionDisable { + pub nodes: (Keyword, Keyword, ConstraintPrimary, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct UniquenessConstraint { + pub nodes: (Keyword, Brace), +} + +#[derive(Clone, Debug, Node)] +pub enum ConstraintSet { + ConstraintExpression(Box), + Brace(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstraintSetBrace { + pub nodes: (Brace>,), +} + +#[derive(Clone, Debug, Node)] +pub struct DistList { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct DistItem { + pub nodes: (ValueRange, Option), +} + +#[derive(Clone, Debug, Node)] +pub enum DistWeight { + Equal(Box), + Divide(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct DistWeightEqual { + pub nodes: (Symbol, Expression), +} + +#[derive(Clone, Debug, Node)] +pub struct DistWeightDivide { + pub nodes: (Symbol, Expression), +} + +#[derive(Clone, Debug, Node)] +pub struct ConstraintPrototype { + pub nodes: ( + Option, + Option, + Keyword, + ConstraintIdentifier, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ConstraintPrototypeQualifier { + Extern(Box), + Pure(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ExternConstraintDeclaration { + pub nodes: ( + Option, + Keyword, + ClassScope, + ConstraintIdentifier, + ConstraintBlock, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct IdentifierList { + pub nodes: (List,), +} diff --git a/sv-parser-syntaxtree/src/source_text/interface_items.rs b/sv-parser-syntaxtree/src/source_text/interface_items.rs new file mode 100644 index 0000000..4698dbd --- /dev/null +++ b/sv-parser-syntaxtree/src/source_text/interface_items.rs @@ -0,0 +1,51 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum InterfaceOrGenerateItem { + Module(Box), + Extern(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfaceOrGenerateItemModule { + pub nodes: (Vec, ModuleCommonItem), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfaceOrGenerateItemExtern { + pub nodes: (Vec, ExternTfDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub enum ExternTfDeclaration { + Method(Box), + Task(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ExternTfDeclarationMethod { + pub nodes: (Keyword, MethodPrototype, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct ExternTfDeclarationTask { + pub nodes: (Keyword, Keyword, TaskPrototype, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub enum InterfaceItem { + PortDeclaration(Box<(PortDeclaration, Symbol)>), + NonPortInterfaceItem(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum NonPortInterfaceItem { + GenerateRegion(Box), + InterfaceOrGenerateItem(Box), + ProgramDeclaration(Box), + ModportDeclaration(Box), + InterfaceDeclaration(Box), + TimeunitsDeclaration(Box), +} diff --git a/sv-parser-syntaxtree/src/source_text/library_source_text.rs b/sv-parser-syntaxtree/src/source_text/library_source_text.rs new file mode 100644 index 0000000..4c328a0 --- /dev/null +++ b/sv-parser-syntaxtree/src/source_text/library_source_text.rs @@ -0,0 +1,37 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct LibraryText { + pub nodes: (Vec,), +} + +#[derive(Clone, Debug, Node)] +pub enum LibraryDescription { + LibraryDeclaration(Box), + IncludeStatement(Box), + ConfigDeclaration(Box), + Null(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct LibraryDeclaration { + pub nodes: ( + Keyword, + LibraryIdentifier, + List, + Option<(Keyword, List)>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct IncludeStatement { + pub nodes: (Keyword, FilePathSpec, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct FilePathSpec { + pub nodes: (StringLiteral,), +} diff --git a/sv-parser/src/parser/source_text/mod.rs b/sv-parser-syntaxtree/src/source_text/mod.rs similarity index 100% rename from sv-parser/src/parser/source_text/mod.rs rename to sv-parser-syntaxtree/src/source_text/mod.rs diff --git a/sv-parser-syntaxtree/src/source_text/module_items.rs b/sv-parser-syntaxtree/src/source_text/module_items.rs new file mode 100644 index 0000000..decc23d --- /dev/null +++ b/sv-parser-syntaxtree/src/source_text/module_items.rs @@ -0,0 +1,186 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum ElaborationSystemTask { + TaskFatal(Box), + TaskError(Box), + TaskWarning(Box), + TaskInfo(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ElaborationSystemTaskFatal { + pub nodes: ( + Keyword, + Option)>>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ElaborationSystemTaskError { + pub nodes: (Keyword, Option>>, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct ElaborationSystemTaskWarning { + pub nodes: (Keyword, Option>>, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct ElaborationSystemTaskInfo { + pub nodes: (Keyword, Option>>, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub enum FinishNumber { + Zero(Box), + One(Box), + Two(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum ModuleCommonItem { + ModuleOrGenerateItemDeclaration(Box), + InterfaceInstantiation(Box), + ProgramInstantiation(Box), + AssertionItem(Box), + BindDirective(Box), + ContinuousAssign(Box), + NetAlias(Box), + InitialConstruct(Box), + FinalConstruct(Box), + AlwaysConstruct(Box), + LoopGenerateConstruct(Box), + ConditionalGenerateConstruct(Box), + ElaborationSystemTask(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum ModuleItem { + PortDeclaration(Box<(PortDeclaration, Symbol)>), + NonPortModuleItem(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum ModuleOrGenerateItem { + Parameter(Box), + Gate(Box), + Udp(Box), + Module(Box), + ModuleItem(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ModuleOrGenerateItemParameter { + pub nodes: (Vec, ParameterOverride), +} + +#[derive(Clone, Debug, Node)] +pub struct ModuleOrGenerateItemGate { + pub nodes: (Vec, GateInstantiation), +} + +#[derive(Clone, Debug, Node)] +pub struct ModuleOrGenerateItemUdp { + pub nodes: (Vec, UdpInstantiation), +} + +#[derive(Clone, Debug, Node)] +pub struct ModuleOrGenerateItemModule { + pub nodes: (Vec, ModuleInstantiation), +} + +#[derive(Clone, Debug, Node)] +pub struct ModuleOrGenerateItemModuleItem { + pub nodes: (Vec, ModuleCommonItem), +} + +#[derive(Clone, Debug, Node)] +pub enum ModuleOrGenerateItemDeclaration { + PackageOrGenerateItemDeclaration(Box), + GenvarDeclaration(Box), + ClockingDeclaration(Box), + Clocking(Box), + Disable(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ModuleOrGenerateItemDeclarationClocking { + pub nodes: (Keyword, Keyword, ClockingIdentifier, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct ModuleOrGenerateItemDeclarationDisable { + pub nodes: (Keyword, Keyword, Keyword, ExpressionOrDist, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub enum NonPortModuleItem { + GenerateRegion(Box), + ModuleOrGenerateItem(Box), + SpecifyBlock(Box), + Specparam(Box), + ProgramDeclaration(Box), + ModuleDeclaration(Box), + InterfaceDeclaration(Box), + TimeunitsDeclaration(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct NonPortModuleItemSpecparam { + pub nodes: (Vec, SpecparamDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct ParameterOverride { + pub nodes: (Keyword, ListOfDefparamAssignments, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub enum BindDirective { + Scope(Box), + Instance(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct BindDirectiveScope { + pub nodes: ( + Keyword, + BindTargetScope, + Option<(Symbol, BindTargetInstanceList)>, + BindInstantiation, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct BindDirectiveInstance { + pub nodes: (Keyword, BindTargetInstance, BindInstantiation, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub enum BindTargetScope { + ModuleIdentifier(Box), + InterfaceIdentifier(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct BindTargetInstance { + pub nodes: (HierarchicalIdentifier, ConstantBitSelect), +} + +#[derive(Clone, Debug, Node)] +pub struct BindTargetInstanceList { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub enum BindInstantiation { + ProgramInstantiation(Box), + ModuleInstantiation(Box), + InterfaceInstantiation(Box), + CheckerInstantiation(Box), +} diff --git a/sv-parser-syntaxtree/src/source_text/module_parameters_and_ports.rs b/sv-parser-syntaxtree/src/source_text/module_parameters_and_ports.rs new file mode 100644 index 0000000..0685fa2 --- /dev/null +++ b/sv-parser-syntaxtree/src/source_text/module_parameters_and_ports.rs @@ -0,0 +1,196 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum ParameterPortList { + Assignment(Box), + Declaration(Box), + Empty(Box<(Symbol, Symbol, Symbol)>), +} + +#[derive(Clone, Debug, Node)] +pub struct ParameterPortListAssignment { + pub nodes: ( + Symbol, + Paren<( + ListOfParamAssignments, + Vec<(Symbol, ParameterPortDeclaration)>, + )>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ParameterPortListDeclaration { + pub nodes: (Symbol, Paren>), +} + +#[derive(Clone, Debug, Node)] +pub enum ParameterPortDeclaration { + ParameterDeclaration(Box), + LocalParameterDeclaration(Box), + ParamList(Box), + TypeList(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ParameterPortDeclarationParamList { + pub nodes: (DataType, ListOfParamAssignments), +} + +#[derive(Clone, Debug, Node)] +pub struct ParameterPortDeclarationTypeList { + pub nodes: (Keyword, ListOfTypeAssignments), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfPorts { + pub nodes: (Paren>,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfPortDeclarations { + pub nodes: (Paren, AnsiPortDeclaration)>>>,), +} + +#[derive(Clone, Debug, Node)] +pub enum PortDeclaration { + Inout(Box), + Input(Box), + Output(Box), + Ref(Box), + Interface(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PortDeclarationInout { + pub nodes: (Vec, InoutDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct PortDeclarationInput { + pub nodes: (Vec, InputDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct PortDeclarationOutput { + pub nodes: (Vec, OutputDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct PortDeclarationRef { + pub nodes: (Vec, RefDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct PortDeclarationInterface { + pub nodes: (Vec, InterfacePortDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub enum Port { + NonNamed(Box), + Named(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PortNonNamed { + pub nodes: (Option,), +} + +#[derive(Clone, Debug, Node)] +pub struct PortNamed { + pub nodes: (Symbol, PortIdentifier, Paren>), +} + +#[derive(Clone, Debug, Node)] +pub enum PortExpression { + PortReference(Box), + Brace(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PortExpressionBrace { + pub nodes: (Brace>,), +} + +#[derive(Clone, Debug, Node)] +pub struct PortReference { + pub nodes: (PortIdentifier, ConstantSelect), +} + +#[derive(Clone, Debug, Node)] +pub enum PortDirection { + Input(Box), + Output(Box), + Inout(Box), + Ref(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct NetPortHeader { + pub nodes: (Option, NetPortType), +} + +#[derive(Clone, Debug, Node)] +pub struct VariablePortHeader { + pub nodes: (Option, VariablePortType), +} + +#[derive(Clone, Debug, Node)] +pub enum InterfacePortHeader { + Identifier(Box), + Interface(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfacePortHeaderIdentifier { + pub nodes: (InterfaceIdentifier, Option<(Symbol, ModportIdentifier)>), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfacePortHeaderInterface { + pub nodes: (Keyword, Option<(Symbol, ModportIdentifier)>), +} + +#[derive(Clone, Debug, Node)] +pub enum NetPortHeaderOrInterfacePortHeader { + NetPortHeader(Box), + InterfacePortHeader(Box), +} +#[derive(Clone, Debug, Node)] +pub enum AnsiPortDeclaration { + Net(Box), + Variable(Box), + Paren(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct AnsiPortDeclarationNet { + pub nodes: ( + Option, + PortIdentifier, + Vec, + Option<(Symbol, ConstantExpression)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct AnsiPortDeclarationVariable { + pub nodes: ( + Option, + PortIdentifier, + Vec, + Option<(Symbol, ConstantExpression)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct AnsiPortDeclarationParen { + pub nodes: ( + Option, + Symbol, + PortIdentifier, + Paren>, + ), +} diff --git a/sv-parser-syntaxtree/src/source_text/package_items.rs b/sv-parser-syntaxtree/src/source_text/package_items.rs new file mode 100644 index 0000000..95bc9f3 --- /dev/null +++ b/sv-parser-syntaxtree/src/source_text/package_items.rs @@ -0,0 +1,44 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum PackageItem { + PackageOrGenerateItemDeclaration(Box), + AnonymousProgram(Box), + PackageExportDeclaration(Box), + TimeunitsDeclaration(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum PackageOrGenerateItemDeclaration { + NetDeclaration(Box), + DataDeclaration(Box), + TaskDeclaration(Box), + FunctionDeclaration(Box), + CheckerDeclaration(Box), + DpiImportExport(Box), + ExternConstraintDeclaration(Box), + ClassDeclaration(Box), + ClassConstructorDeclaration(Box), + LocalParameterDeclaration(Box<(LocalParameterDeclaration, Symbol)>), + ParameterDeclaration(Box<(ParameterDeclaration, Symbol)>), + CovergroupDeclaration(Box), + AssertionItemDeclaration(Box), + Empty(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct AnonymousProgram { + pub nodes: (Keyword, Symbol, Vec, Keyword), +} + +#[derive(Clone, Debug, Node)] +pub enum AnonymousProgramItem { + TaskDeclaration(Box), + FunctionDeclaration(Box), + ClassDeclaration(Box), + CovergroupDeclaration(Box), + ClassConstructorDeclaration(Box), + Empty(Box), +} diff --git a/sv-parser-syntaxtree/src/source_text/program_items.rs b/sv-parser-syntaxtree/src/source_text/program_items.rs new file mode 100644 index 0000000..51926e1 --- /dev/null +++ b/sv-parser-syntaxtree/src/source_text/program_items.rs @@ -0,0 +1,53 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum ProgramItem { + PortDeclaration(Box<(PortDeclaration, Symbol)>), + NonPortProgramItem(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum NonPortProgramItem { + Assign(Box), + Module(Box), + Initial(Box), + Final(Box), + Assertion(Box), + TimeunitsDeclaration(Box), + ProgramGenerateItem(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct NonPortProgramItemAssign { + pub nodes: (Vec, ContinuousAssign), +} + +#[derive(Clone, Debug, Node)] +pub struct NonPortProgramItemModule { + pub nodes: (Vec, ModuleOrGenerateItemDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct NonPortProgramItemInitial { + pub nodes: (Vec, InitialConstruct), +} + +#[derive(Clone, Debug, Node)] +pub struct NonPortProgramItemFinal { + pub nodes: (Vec, FinalConstruct), +} + +#[derive(Clone, Debug, Node)] +pub struct NonPortProgramItemAssertion { + pub nodes: (Vec, ConcurrentAssertionItem), +} + +#[derive(Clone, Debug, Node)] +pub enum ProgramGenerateItem { + LoopGenerateConstruct(Box), + ConditionalGenerateConstruct(Box), + GenerateRegion(Box), + ElaborationSystemTask(Box), +} diff --git a/sv-parser-syntaxtree/src/source_text/system_verilog_source_text.rs b/sv-parser-syntaxtree/src/source_text/system_verilog_source_text.rs new file mode 100644 index 0000000..8e1e6c7 --- /dev/null +++ b/sv-parser-syntaxtree/src/source_text/system_verilog_source_text.rs @@ -0,0 +1,408 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct SourceText { + pub nodes: (Option, Vec), +} + +#[derive(Clone, Debug, Node)] +pub enum Description { + ModuleDeclaration(Box), + UdpDeclaration(Box), + InterfaceDeclaration(Box), + InterfaceClassDeclaration(Box), + ProgramDeclaration(Box), + PackageDeclaration(Box), + PackageItem(Box), + BindDirective(Box), + ConfigDeclaration(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct DescriptionPackageItem { + pub nodes: (Vec, PackageItem), +} + +#[derive(Clone, Debug, Node)] +pub struct DescriptionBindDirective { + pub nodes: (Vec, BindDirective), +} + +#[derive(Clone, Debug, Node)] +pub struct ModuleNonansiHeader { + pub nodes: ( + Vec, + ModuleKeyword, + Option, + ModuleIdentifier, + Vec, + Option, + ListOfPorts, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ModuleAnsiHeader { + pub nodes: ( + Vec, + ModuleKeyword, + Option, + ModuleIdentifier, + Vec, + Option, + Option, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ModuleDeclaration { + Nonansi(Box), + Ansi(Box), + Wildcard(Box), + ExternNonansi(Box), + ExternAnsi(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ModuleDeclarationNonansi { + pub nodes: ( + ModuleNonansiHeader, + Option, + Vec, + Keyword, + Option<(Symbol, ModuleIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ModuleDeclarationAnsi { + pub nodes: ( + ModuleAnsiHeader, + Option, + Vec, + Keyword, + Option<(Symbol, ModuleIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ModuleDeclarationWildcard { + pub nodes: ( + Vec, + ModuleKeyword, + Option, + ModuleIdentifier, + Paren, + Symbol, + Option, + Vec, + Keyword, + Option<(Symbol, ModuleIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ModuleDeclarationExternNonansi { + pub nodes: (Keyword, ModuleNonansiHeader), +} + +#[derive(Clone, Debug, Node)] +pub struct ModuleDeclarationExternAnsi { + pub nodes: (Keyword, ModuleAnsiHeader), +} + +#[derive(Clone, Debug, Node)] +pub enum ModuleKeyword { + Module(Box), + Macromodule(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum InterfaceDeclaration { + Nonansi(Box), + Ansi(Box), + Wildcard(Box), + ExternNonansi(Box), + ExternAnsi(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfaceDeclarationNonansi { + pub nodes: ( + InterfaceNonansiHeader, + Option, + Vec, + Keyword, + Option<(Symbol, InterfaceIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfaceDeclarationAnsi { + pub nodes: ( + InterfaceAnsiHeader, + Option, + Vec, + Keyword, + Option<(Symbol, InterfaceIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfaceDeclarationWildcard { + pub nodes: ( + Vec, + Keyword, + Option, + InterfaceIdentifier, + Paren, + Symbol, + Option, + Vec, + Keyword, + Option<(Symbol, InterfaceIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfaceDeclarationExternNonansi { + pub nodes: (Keyword, InterfaceNonansiHeader), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfaceDeclarationExternAnsi { + pub nodes: (Keyword, InterfaceAnsiHeader), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfaceNonansiHeader { + pub nodes: ( + Vec, + Keyword, + Option, + InterfaceIdentifier, + Vec, + Option, + ListOfPorts, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfaceAnsiHeader { + pub nodes: ( + Vec, + Keyword, + Option, + InterfaceIdentifier, + Vec, + Option, + Option, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum ProgramDeclaration { + Nonansi(Box), + Ansi(Box), + Wildcard(Box), + ExternNonansi(Box), + ExternAnsi(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ProgramDeclarationNonansi { + pub nodes: ( + ProgramNonansiHeader, + Option, + Vec, + Keyword, + Option<(Symbol, ProgramIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ProgramDeclarationAnsi { + pub nodes: ( + ProgramAnsiHeader, + Option, + Vec, + Keyword, + Option<(Symbol, ProgramIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ProgramDeclarationWildcard { + pub nodes: ( + Vec, + Keyword, + ProgramIdentifier, + Paren, + Symbol, + Option, + Vec, + Keyword, + Option<(Symbol, ProgramIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ProgramDeclarationExternNonansi { + pub nodes: (Keyword, ProgramNonansiHeader), +} + +#[derive(Clone, Debug, Node)] +pub struct ProgramDeclarationExternAnsi { + pub nodes: (Keyword, ProgramAnsiHeader), +} + +#[derive(Clone, Debug, Node)] +pub struct ProgramNonansiHeader { + pub nodes: ( + Vec, + Keyword, + Option, + ProgramIdentifier, + Vec, + Option, + ListOfPorts, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ProgramAnsiHeader { + pub nodes: ( + Vec, + Keyword, + Option, + ProgramIdentifier, + Vec, + Option, + Option, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct CheckerDeclaration { + pub nodes: ( + Keyword, + CheckerIdentifier, + Option>>, + Symbol, + Vec<(Vec, CheckerOrGenerateItem)>, + Keyword, + Option<(Symbol, CheckerIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ClassDeclaration { + pub nodes: ( + Option, + Keyword, + Option, + ClassIdentifier, + Option, + Option<(Keyword, ClassType, Option>)>, + Option<(Keyword, List)>, + Symbol, + Vec, + Keyword, + Option<(Symbol, ClassIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct Virtual { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfaceClassType { + pub nodes: (PsClassIdentifier, Option), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfaceClassDeclaration { + pub nodes: ( + Keyword, + Keyword, + ClassIdentifier, + Option, + Option<(Keyword, List)>, + Symbol, + Vec, + Keyword, + Option<(Symbol, ClassIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum InterfaceClassItem { + TypeDeclaration(Box), + Method(Box), + LocalParameterDeclaration(Box<(LocalParameterDeclaration, Symbol)>), + ParameterDeclaration(Box<(ParameterDeclaration, Symbol)>), + Null(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfaceClassItemMethod { + pub nodes: (Vec, InterfaceClassMethod), +} + +#[derive(Clone, Debug, Node)] +pub struct InterfaceClassMethod { + pub nodes: (Keyword, Keyword, MethodPrototype, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct PackageDeclaration { + pub nodes: ( + Vec, + Keyword, + Option, + PackageIdentifier, + Symbol, + Option, + Vec<(Vec, PackageItem)>, + Keyword, + Option<(Symbol, PackageIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum TimeunitsDeclaration { + Timeunit(Box), + Timeprecision(Box), + TimeunitTimeprecision(Box), + TimeprecisionTimeunit(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct TimeunitsDeclarationTimeunit { + pub nodes: (Keyword, TimeLiteral, Option<(Symbol, TimeLiteral)>, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct TimeunitsDeclarationTimeprecision { + pub nodes: (Keyword, TimeLiteral, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct TimeunitsDeclarationTimeunitTimeprecision { + pub nodes: (Keyword, TimeLiteral, Symbol, Keyword, TimeLiteral, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct TimeunitsDeclarationTimeprecisionTimeunit { + pub nodes: (Keyword, TimeLiteral, Symbol, Keyword, TimeLiteral, Symbol), +} diff --git a/sv-parser-syntaxtree/src/special_node.rs b/sv-parser-syntaxtree/src/special_node.rs new file mode 100644 index 0000000..8d7fbd6 --- /dev/null +++ b/sv-parser-syntaxtree/src/special_node.rs @@ -0,0 +1,44 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct Symbol { + pub nodes: (Locate, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct Keyword { + pub nodes: (Locate, Vec), +} + +#[derive(Clone, Debug, Node)] +pub enum WhiteSpace { + Space(Box), + Comment(Box), +} + +#[derive(Clone, Debug)] +pub struct Paren { + pub nodes: (Symbol, T, Symbol), +} + +#[derive(Clone, Debug)] +pub struct Brace { + pub nodes: (Symbol, T, Symbol), +} + +#[derive(Clone, Debug)] +pub struct Bracket { + pub nodes: (Symbol, T, Symbol), +} + +#[derive(Clone, Debug)] +pub struct ApostropheBrace { + pub nodes: (Symbol, T, Symbol), +} + +#[derive(Clone, Debug)] +pub struct List { + pub nodes: (U, Vec<(T, U)>), +} diff --git a/sv-parser/src/parser/specify_section/mod.rs b/sv-parser-syntaxtree/src/specify_section/mod.rs similarity index 100% rename from sv-parser/src/parser/specify_section/mod.rs rename to sv-parser-syntaxtree/src/specify_section/mod.rs diff --git a/sv-parser-syntaxtree/src/specify_section/specify_block_declaration.rs b/sv-parser-syntaxtree/src/specify_section/specify_block_declaration.rs new file mode 100644 index 0000000..f511a50 --- /dev/null +++ b/sv-parser-syntaxtree/src/specify_section/specify_block_declaration.rs @@ -0,0 +1,27 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct SpecifyBlock { + pub nodes: (Keyword, Vec, Keyword), +} + +#[derive(Clone, Debug, Node)] +pub enum SpecifyItem { + SpecparamDeclaration(Box), + PulsestyleDeclaration(Box), + ShowcancelledDeclaration(Box), + PathDeclaration(Box), + SystemTimingCheck(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PulsestyleDeclaration { + pub nodes: (Keyword, ListOfPathOutputs, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct ShowcancelledDeclaration { + pub nodes: (Keyword, ListOfPathOutputs, Symbol), +} diff --git a/sv-parser-syntaxtree/src/specify_section/specify_block_terminals.rs b/sv-parser-syntaxtree/src/specify_section/specify_block_terminals.rs new file mode 100644 index 0000000..5caed7d --- /dev/null +++ b/sv-parser-syntaxtree/src/specify_section/specify_block_terminals.rs @@ -0,0 +1,37 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct SpecifyInputTerminalDescriptor { + pub nodes: (InputIdentifier, Option>), +} + +#[derive(Clone, Debug, Node)] +pub struct SpecifyOutputTerminalDescriptor { + pub nodes: (OutputIdentifier, Option>), +} + +#[derive(Clone, Debug, Node)] +pub enum InputIdentifier { + InputPortIdentifier(Box), + InoutPortIdentifier(Box), + Interface(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct InputIdentifierInterface { + pub nodes: (InterfaceIdentifier, Symbol, PortIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub enum OutputIdentifier { + OutputPortIdentifier(Box), + InoutPortIdentifier(Box), + Interface(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct OutputIdentifierInterface { + pub nodes: (InterfaceIdentifier, Symbol, PortIdentifier), +} diff --git a/sv-parser-syntaxtree/src/specify_section/specify_path_declarations.rs b/sv-parser-syntaxtree/src/specify_section/specify_path_declarations.rs new file mode 100644 index 0000000..3b73afa --- /dev/null +++ b/sv-parser-syntaxtree/src/specify_section/specify_path_declarations.rs @@ -0,0 +1,60 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum PathDeclaration { + SimplePathDeclaration(Box<(SimplePathDeclaration, Symbol)>), + EdgeSensitivePathDeclaration(Box<(EdgeSensitivePathDeclaration, Symbol)>), + StateDependentPathDeclaration(Box<(StateDependentPathDeclaration, Symbol)>), +} + +#[derive(Clone, Debug, Node)] +pub enum SimplePathDeclaration { + Parallel(Box), + Full(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct SimplePathDeclarationParallel { + pub nodes: (ParallelPathDescription, Symbol, PathDelayValue), +} + +#[derive(Clone, Debug, Node)] +pub struct SimplePathDeclarationFull { + pub nodes: (FullPathDescription, Symbol, PathDelayValue), +} + +#[derive(Clone, Debug, Node)] +pub struct ParallelPathDescription { + pub nodes: ( + Paren<( + SpecifyInputTerminalDescriptor, + Option, + Symbol, + SpecifyOutputTerminalDescriptor, + )>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct FullPathDescription { + pub nodes: ( + Paren<( + ListOfPathInputs, + Option, + Symbol, + ListOfPathOutputs, + )>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfPathInputs { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfPathOutputs { + pub nodes: (List,), +} diff --git a/sv-parser-syntaxtree/src/specify_section/specify_path_delays.rs b/sv-parser-syntaxtree/src/specify_section/specify_path_delays.rs new file mode 100644 index 0000000..8c407a4 --- /dev/null +++ b/sv-parser-syntaxtree/src/specify_section/specify_path_delays.rs @@ -0,0 +1,123 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum PathDelayValue { + ListOfPathDelayExpressions(Box), + Paren(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct PathDelayValueParen { + pub nodes: (Paren,), +} + +#[derive(Clone, Debug, Node)] +pub struct ListOfPathDelayExpressions { + pub nodes: (List,), +} + +#[derive(Clone, Debug, Node)] +pub struct TPathDelayExpression { + pub nodes: (PathDelayExpression,), +} +#[derive(Clone, Debug, Node)] +pub struct PathDelayExpression { + pub nodes: (ConstantMintypmaxExpression,), +} + +#[derive(Clone, Debug, Node)] +pub enum EdgeSensitivePathDeclaration { + Parallel(Box), + Full(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct EdgeSensitivePathDeclarationParallel { + pub nodes: (ParallelEdgeSensitivePathDescription, Symbol, PathDelayValue), +} + +#[derive(Clone, Debug, Node)] +pub struct EdgeSensitivePathDeclarationFull { + pub nodes: (FullEdgeSensitivePathDescription, Symbol, PathDelayValue), +} + +#[derive(Clone, Debug, Node)] +pub struct ParallelEdgeSensitivePathDescription { + pub nodes: ( + Paren<( + Option, + SpecifyInputTerminalDescriptor, + Option, + Symbol, + Paren<( + SpecifyOutputTerminalDescriptor, + Option, + Symbol, + DataSourceExpression, + )>, + )>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct FullEdgeSensitivePathDescription { + pub nodes: ( + Paren<( + Option, + ListOfPathInputs, + Option, + Symbol, + Paren<( + ListOfPathOutputs, + Option, + Symbol, + DataSourceExpression, + )>, + )>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct DataSourceExpression { + pub nodes: (Expression,), +} + +#[derive(Clone, Debug, Node)] +pub enum EdgeIdentifier { + Posedge(Box), + Negedge(Box), + Edge(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum StateDependentPathDeclaration { + IfSimple(Box), + IfEdgeSensitive(Box), + IfNone(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct StateDependentPathDeclarationIfSimple { + pub nodes: (Keyword, Paren, SimplePathDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct StateDependentPathDeclarationIfEdgeSensitive { + pub nodes: ( + Keyword, + Paren, + EdgeSensitivePathDeclaration, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct StateDependentPathDeclarationIfNone { + pub nodes: (Keyword, SimplePathDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct PolarityOperator { + pub nodes: (Symbol,), +} diff --git a/sv-parser-syntaxtree/src/specify_section/system_timing_check_command_arguments.rs b/sv-parser-syntaxtree/src/specify_section/system_timing_check_command_arguments.rs new file mode 100644 index 0000000..a7dbcbb --- /dev/null +++ b/sv-parser-syntaxtree/src/specify_section/system_timing_check_command_arguments.rs @@ -0,0 +1,85 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct TimecheckCondition { + pub nodes: (MintypmaxExpression,), +} + +#[derive(Clone, Debug, Node)] +pub struct ControlledReferenceEvent { + pub nodes: (ControlledTimingCheckEvent,), +} + +#[derive(Clone, Debug, Node)] +pub struct DataEvent { + pub nodes: (TimingCheckEvent,), +} + +#[derive(Clone, Debug, Node)] +pub enum DelayedData { + TerminalIdentifier(Box), + WithMintypmax(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct DelayedDataWithMintypmax { + pub nodes: (TerminalIdentifier, Bracket), +} + +#[derive(Clone, Debug, Node)] +pub enum DelayedReference { + TerminalIdentifier(Box), + WithMintypmax(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct DelayedReferenceWithMintypmax { + pub nodes: (TerminalIdentifier, Bracket), +} + +#[derive(Clone, Debug, Node)] +pub struct EndEdgeOffset { + pub nodes: (MintypmaxExpression,), +} + +#[derive(Clone, Debug, Node)] +pub struct EventBasedFlag { + pub nodes: (ConstantExpression,), +} + +#[derive(Clone, Debug, Node)] +pub struct Notifier { + pub nodes: (VariableIdentifier,), +} + +#[derive(Clone, Debug, Node)] +pub struct ReferenceEvent { + pub nodes: (TimingCheckEvent,), +} + +#[derive(Clone, Debug, Node)] +pub struct RemainActiveFlag { + pub nodes: (ConstantMintypmaxExpression,), +} + +#[derive(Clone, Debug, Node)] +pub struct TimestampCondition { + pub nodes: (MintypmaxExpression,), +} + +#[derive(Clone, Debug, Node)] +pub struct StartEdgeOffset { + pub nodes: (MintypmaxExpression,), +} + +#[derive(Clone, Debug, Node)] +pub struct Threshold { + pub nodes: (ConstantExpression,), +} + +#[derive(Clone, Debug, Node)] +pub struct TimingCheckLimit { + pub nodes: (Expression,), +} diff --git a/sv-parser-syntaxtree/src/specify_section/system_timing_check_commands.rs b/sv-parser-syntaxtree/src/specify_section/system_timing_check_commands.rs new file mode 100644 index 0000000..1f5a722 --- /dev/null +++ b/sv-parser-syntaxtree/src/specify_section/system_timing_check_commands.rs @@ -0,0 +1,265 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum SystemTimingCheck { + SetupTimingCheck(Box), + HoldTimingCheck(Box), + SetupholdTimingCheck(Box), + RecoveryTimingCheck(Box), + RemovalTimingCheck(Box), + RecremTimingCheck(Box), + SkewTimingCheck(Box), + TimeskewTimingCheck(Box), + FullskewTimingCheck(Box), + PeriodTimingCheck(Box), + WidthTimingCheck(Box), + NochargeTimingCheck(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct SetupTimingCheck { + pub nodes: ( + Keyword, + Paren<( + DataEvent, + Symbol, + ReferenceEvent, + Symbol, + TimingCheckLimit, + Option<(Symbol, Option)>, + )>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct HoldTimingCheck { + pub nodes: ( + Keyword, + Paren<( + ReferenceEvent, + Symbol, + DataEvent, + Symbol, + TimingCheckLimit, + Option<(Symbol, Option)>, + )>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct SetupholdTimingCheck { + pub nodes: ( + Keyword, + Paren<( + ReferenceEvent, + Symbol, + DataEvent, + Symbol, + TimingCheckLimit, + Symbol, + TimingCheckLimit, + Option<( + Symbol, + Option, + Option<( + Symbol, + Option, + Option<( + Symbol, + Option, + Option<( + Symbol, + Option, + Option<(Symbol, Option)>, + )>, + )>, + )>, + )>, + )>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct RecoveryTimingCheck { + pub nodes: ( + Keyword, + Paren<( + ReferenceEvent, + Symbol, + DataEvent, + Symbol, + TimingCheckLimit, + Option<(Symbol, Option)>, + )>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct RemovalTimingCheck { + pub nodes: ( + Keyword, + Paren<( + ReferenceEvent, + Symbol, + DataEvent, + Symbol, + TimingCheckLimit, + Option<(Symbol, Option)>, + )>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct RecremTimingCheck { + pub nodes: ( + Keyword, + Paren<( + ReferenceEvent, + Symbol, + DataEvent, + Symbol, + TimingCheckLimit, + Symbol, + TimingCheckLimit, + Option<( + Symbol, + Option, + Option<( + Symbol, + Option, + Option<( + Symbol, + Option, + Option<( + Symbol, + Option, + Option<(Symbol, Option)>, + )>, + )>, + )>, + )>, + )>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct SkewTimingCheck { + pub nodes: ( + Keyword, + Paren<( + ReferenceEvent, + Symbol, + DataEvent, + Symbol, + TimingCheckLimit, + Option<(Symbol, Option)>, + )>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct TimeskewTimingCheck { + pub nodes: ( + Keyword, + Paren<( + ReferenceEvent, + Symbol, + DataEvent, + Symbol, + TimingCheckLimit, + Option<( + Symbol, + Option, + Option<( + Symbol, + Option, + Option<(Symbol, Option)>, + )>, + )>, + )>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct FullskewTimingCheck { + pub nodes: ( + Keyword, + Paren<( + ReferenceEvent, + Symbol, + DataEvent, + Symbol, + TimingCheckLimit, + Symbol, + TimingCheckLimit, + Option<( + Symbol, + Option, + Option<( + Symbol, + Option, + Option<(Symbol, Option)>, + )>, + )>, + )>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct PeriodTimingCheck { + pub nodes: ( + Keyword, + Paren<( + ControlledReferenceEvent, + Symbol, + TimingCheckLimit, + Option<(Symbol, Option)>, + )>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct WidthTimingCheck { + pub nodes: ( + Keyword, + Paren<( + ControlledReferenceEvent, + Symbol, + TimingCheckLimit, + Symbol, + Threshold, + Option<(Symbol, Option)>, + )>, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct NochargeTimingCheck { + pub nodes: ( + Keyword, + Paren<( + ReferenceEvent, + Symbol, + DataEvent, + Symbol, + StartEdgeOffset, + Symbol, + EndEdgeOffset, + Option<(Symbol, Option)>, + )>, + Symbol, + ), +} diff --git a/sv-parser-syntaxtree/src/specify_section/system_timing_check_event_definitions.rs b/sv-parser-syntaxtree/src/specify_section/system_timing_check_event_definitions.rs new file mode 100644 index 0000000..cb36aa1 --- /dev/null +++ b/sv-parser-syntaxtree/src/specify_section/system_timing_check_event_definitions.rs @@ -0,0 +1,78 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct TimingCheckEvent { + pub nodes: ( + Option, + SpecifyTerminalDescriptor, + Option<(Symbol, TimingCheckCondition)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct ControlledTimingCheckEvent { + pub nodes: ( + TimingCheckEventControl, + SpecifyTerminalDescriptor, + Option<(Symbol, TimingCheckCondition)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum TimingCheckEventControl { + Posedge(Box), + Negedge(Box), + Edge(Box), + EdgeControlSpecifier(Box), +} + +#[derive(Clone, Debug, Node)] +pub enum SpecifyTerminalDescriptor { + SpecifyInputTerminalDescriptor(Box), + SpecifyOutputTerminalDescriptor(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct EdgeControlSpecifier { + pub nodes: (Keyword, Bracket>), +} + +#[derive(Clone, Debug, Node)] +pub struct EdgeDescriptor { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub enum TimingCheckCondition { + ScalarTimingCheckCondition(Box), + Paren(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct TimingCheckConditionParen { + pub nodes: (Paren,), +} + +#[derive(Clone, Debug, Node)] +pub enum ScalarTimingCheckCondition { + Expression(Box), + Unary(Box), + Binary(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct ScalarTimingCheckConditionUnary { + pub nodes: (Symbol, Expression), +} + +#[derive(Clone, Debug, Node)] +pub struct ScalarTimingCheckConditionBinary { + pub nodes: (Expression, Symbol, ScalarConstant), +} + +#[derive(Clone, Debug, Node)] +pub struct ScalarConstant { + pub nodes: (Keyword,), +} diff --git a/sv-parser/src/parser/udp_declaration_and_instantiation/mod.rs b/sv-parser-syntaxtree/src/udp_declaration_and_instantiation/mod.rs similarity index 100% rename from sv-parser/src/parser/udp_declaration_and_instantiation/mod.rs rename to sv-parser-syntaxtree/src/udp_declaration_and_instantiation/mod.rs diff --git a/sv-parser-syntaxtree/src/udp_declaration_and_instantiation/udp_body.rs b/sv-parser-syntaxtree/src/udp_declaration_and_instantiation/udp_body.rs new file mode 100644 index 0000000..388ed23 --- /dev/null +++ b/sv-parser-syntaxtree/src/udp_declaration_and_instantiation/udp_body.rs @@ -0,0 +1,110 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub enum UdpBody { + CombinationalBody(Box), + SequentialBody(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct CombinationalBody { + pub nodes: ( + Keyword, + CombinationalEntry, + Vec, + Keyword, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct CombinationalEntry { + pub nodes: (LevelInputList, Symbol, OutputSymbol, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct SequentialBody { + pub nodes: ( + Option, + Keyword, + SequentialEntry, + Vec, + Keyword, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct UdpInitialStatement { + pub nodes: (Keyword, OutputPortIdentifier, Symbol, InitVal, Symbol), +} + +#[derive(Clone, Debug, Node)] +pub struct InitVal { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct SequentialEntry { + pub nodes: ( + SeqInputList, + Symbol, + CurrentState, + Symbol, + NextState, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum SeqInputList { + LevelInputList(Box), + EdgeInputList(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct LevelInputList { + pub nodes: (LevelSymbol, Vec), +} + +#[derive(Clone, Debug, Node)] +pub struct EdgeInputList { + pub nodes: (Vec, EdgeIndicator, Vec), +} + +#[derive(Clone, Debug, Node)] +pub enum EdgeIndicator { + Paren(Box), + EdgeSymbol(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct EdgeIndicatorParen { + pub nodes: (Paren<(LevelSymbol, LevelSymbol)>,), +} + +#[derive(Clone, Debug, Node)] +pub struct CurrentState { + pub nodes: (LevelSymbol,), +} + +#[derive(Clone, Debug, Node)] +pub enum NextState { + OutputSymbol(Box), + Minus(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct OutputSymbol { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct LevelSymbol { + pub nodes: (Keyword,), +} + +#[derive(Clone, Debug, Node)] +pub struct EdgeSymbol { + pub nodes: (Keyword,), +} diff --git a/sv-parser-syntaxtree/src/udp_declaration_and_instantiation/udp_declaration.rs b/sv-parser-syntaxtree/src/udp_declaration_and_instantiation/udp_declaration.rs new file mode 100644 index 0000000..65f802b --- /dev/null +++ b/sv-parser-syntaxtree/src/udp_declaration_and_instantiation/udp_declaration.rs @@ -0,0 +1,81 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct UdpNonansiDeclaration { + pub nodes: ( + Vec, + Keyword, + UdpIdentifier, + Paren, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct UdpAnsiDeclaration { + pub nodes: ( + Vec, + Keyword, + UdpIdentifier, + Paren, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum UdpDeclaration { + Nonansi(Box), + Ansi(Box), + ExternNonansi(Box), + ExternAnsi(Box), + Wildcard(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct UdpDeclarationNonansi { + pub nodes: ( + UdpNonansiDeclaration, + UdpPortDeclaration, + Vec, + UdpBody, + Keyword, + Option<(Symbol, UdpIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct UdpDeclarationAnsi { + pub nodes: ( + UdpAnsiDeclaration, + UdpBody, + Keyword, + Option<(Symbol, UdpIdentifier)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct UdpDeclarationExternNonansi { + pub nodes: (Keyword, UdpNonansiDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct UdpDeclarationExternAnsi { + pub nodes: (Keyword, UdpAnsiDeclaration), +} + +#[derive(Clone, Debug, Node)] +pub struct UdpDeclarationWildcard { + pub nodes: ( + Vec, + Keyword, + UdpIdentifier, + Paren, + Symbol, + Vec, + UdpBody, + Keyword, + Option<(Symbol, UdpIdentifier)>, + ), +} diff --git a/sv-parser-syntaxtree/src/udp_declaration_and_instantiation/udp_instantiation.rs b/sv-parser-syntaxtree/src/udp_declaration_and_instantiation/udp_instantiation.rs new file mode 100644 index 0000000..6576a13 --- /dev/null +++ b/sv-parser-syntaxtree/src/udp_declaration_and_instantiation/udp_instantiation.rs @@ -0,0 +1,27 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct UdpInstantiation { + pub nodes: ( + UdpIdentifier, + Option, + Option, + List, + Symbol, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct UdpInstance { + pub nodes: ( + Option, + Paren<( + OutputTerminal, + Symbol, + InputTerminal, + Vec<(Symbol, InputTerminal)>, + )>, + ), +} diff --git a/sv-parser-syntaxtree/src/udp_declaration_and_instantiation/udp_ports.rs b/sv-parser-syntaxtree/src/udp_declaration_and_instantiation/udp_ports.rs new file mode 100644 index 0000000..4efe76e --- /dev/null +++ b/sv-parser-syntaxtree/src/udp_declaration_and_instantiation/udp_ports.rs @@ -0,0 +1,60 @@ +use crate::*; + +// ----------------------------------------------------------------------------- + +#[derive(Clone, Debug, Node)] +pub struct UdpPortList { + pub nodes: ( + OutputPortIdentifier, + Symbol, + List, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct UdpDeclarationPortList { + pub nodes: ( + UdpOutputDeclaration, + Symbol, + List, + ), +} + +#[derive(Clone, Debug, Node)] +pub enum UdpPortDeclaration { + UdpOutputDeclaration(Box<(UdpOutputDeclaration, Symbol)>), + UdpInputDeclaration(Box<(UdpInputDeclaration, Symbol)>), + UdpRegDeclaration(Box<(UdpRegDeclaration, Symbol)>), +} + +#[derive(Clone, Debug, Node)] +pub enum UdpOutputDeclaration { + Nonreg(Box), + Reg(Box), +} + +#[derive(Clone, Debug, Node)] +pub struct UdpOutputDeclarationNonreg { + pub nodes: (Vec, Keyword, PortIdentifier), +} + +#[derive(Clone, Debug, Node)] +pub struct UdpOutputDeclarationReg { + pub nodes: ( + Vec, + Keyword, + Keyword, + PortIdentifier, + Option<(Symbol, ConstantExpression)>, + ), +} + +#[derive(Clone, Debug, Node)] +pub struct UdpInputDeclaration { + pub nodes: (Vec, Keyword, ListOfUdpPortIdentifiers), +} + +#[derive(Clone, Debug, Node)] +pub struct UdpRegDeclaration { + pub nodes: (Vec, Keyword, VariableIdentifier), +} diff --git a/sv-parser/Cargo.toml b/sv-parser/Cargo.toml index 584f5ed..58273fe 100644 --- a/sv-parser/Cargo.toml +++ b/sv-parser/Cargo.toml @@ -9,20 +9,7 @@ license = "MIT" readme = "../README.md" description = "" edition = "2018" -build = "build.rs" - -[features] -default = [] -trace = [] [dependencies] -nom = "5.0.0" -#nom_locate = { git = "https://github.com/fflorent/nom_locate" } -nom_locate = { path = "../../nom_locate" } -str-concat = "*" -sv-parser-macros = { path = "../sv-parser-macros" } -nom-packrat = "0.1.17" - -[build-dependencies] -walkdir = "2" -regex = "1" +sv-parser-syntaxtree = { path = "../sv-parser-syntaxtree" } +sv-parser-parser = { path = "../sv-parser-parser" } diff --git a/sv-parser/src/ast.rs b/sv-parser/src/ast.rs deleted file mode 100644 index 2ec9fc3..0000000 --- a/sv-parser/src/ast.rs +++ /dev/null @@ -1,6 +0,0 @@ -pub mod any_node; -pub mod locate; -pub mod node; -pub(crate) use any_node::*; -pub(crate) use locate::*; -pub(crate) use node::*; diff --git a/sv-parser/src/ast/locate.rs b/sv-parser/src/ast/locate.rs deleted file mode 100644 index 530600f..0000000 --- a/sv-parser/src/ast/locate.rs +++ /dev/null @@ -1,18 +0,0 @@ -use crate::parser::*; - -#[derive(Copy, Clone, Default, Debug, PartialEq)] -pub struct Locate { - offset: usize, - line: u32, - len: usize, -} - -impl<'a> From> for Locate { - fn from(x: Span<'a>) -> Self { - Locate { - offset: x.offset, - line: x.line, - len: x.fragment.len(), - } - } -} diff --git a/sv-parser/src/ast/node.rs b/sv-parser/src/ast/node.rs deleted file mode 100644 index a112a90..0000000 --- a/sv-parser/src/ast/node.rs +++ /dev/null @@ -1,11 +0,0 @@ -use crate::ast::*; - -pub(crate) trait Node<'a> { - fn next(&'a self) -> RefNodes<'a>; -} - -impl<'a> Node<'a> for Locate { - fn next(&'a self) -> RefNodes<'a> { - vec![].into() - } -} diff --git a/sv-parser/src/lib.rs b/sv-parser/src/lib.rs index 9eaf5e8..ab05c5d 100644 --- a/sv-parser/src/lib.rs +++ b/sv-parser/src/lib.rs @@ -1,24 +1,4 @@ #![recursion_limit = "256"] -pub mod ast; -pub mod parser; -use parser::*; -use nom_packrat::storage; - -storage!(ast::AnyNode); - -pub fn parse_sv(s: &str) -> Result { - let s = Span::new_extra(s, Extra::default()); - match source_text(s) { - Ok((_, x)) => Ok(x), - Err(_) => Err(()), - } -} - -pub fn parse_lib(s: &str) -> Result { - let s = Span::new_extra(s, Extra::default()); - match library_text(s) { - Ok((_, x)) => Ok(x), - Err(_) => Err(()), - } -} +pub use sv_parser_parser::{parse_lib, parse_sv}; +pub use sv_parser_syntaxtree::*; diff --git a/sv-parser/src/parser/declarations/module_parameter_declarations.rs b/sv-parser/src/parser/declarations/module_parameter_declarations.rs deleted file mode 100644 index 12f82bc..0000000 --- a/sv-parser/src/parser/declarations/module_parameter_declarations.rs +++ /dev/null @@ -1,196 +0,0 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum LocalParameterDeclaration { - Param(Box), - Type(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct LocalParameterDeclarationParam { - pub nodes: (Keyword, Option, ListOfParamAssignments), -} - -#[derive(Clone, Debug, Node)] -pub struct LocalParameterDeclarationType { - pub nodes: (Keyword, Keyword, ListOfTypeAssignments), -} - -#[derive(Clone, Debug, Node)] -pub enum ParameterDeclaration { - Param(Box), - Type(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct ParameterDeclarationParam { - pub nodes: (Keyword, Option, ListOfParamAssignments), -} - -#[derive(Clone, Debug, Node)] -pub struct ParameterDeclarationType { - pub nodes: (Keyword, Keyword, ListOfTypeAssignments), -} - -#[derive(Clone, Debug, Node)] -pub struct SpecparamDeclaration { - pub nodes: ( - Keyword, - Option, - ListOfSpecparamAssignments, - Symbol, - ), -} - -// ----------------------------------------------------------------------------- - -#[parser] -pub(crate) fn local_parameter_declaration(s: Span) -> IResult { - alt(( - local_parameter_declaration_param, - local_parameter_declaration_type, - ))(s) -} - -#[parser(Ambiguous)] -pub(crate) fn local_parameter_declaration_param(s: Span) -> IResult { - let (s, a) = keyword("localparam")(s)?; - let (s, b) = ambiguous_opt(data_type_or_implicit)(s)?; - let (s, c) = list_of_param_assignments(s)?; - Ok(( - s, - LocalParameterDeclaration::Param(Box::new(LocalParameterDeclarationParam { - nodes: (a, b, c), - })), - )) -} - -#[parser] -pub(crate) fn local_parameter_declaration_type(s: Span) -> IResult { - let (s, a) = keyword("localparam")(s)?; - let (s, b) = keyword("type")(s)?; - let (s, c) = list_of_type_assignments(s)?; - Ok(( - s, - LocalParameterDeclaration::Type(Box::new(LocalParameterDeclarationType { - nodes: (a, b, c), - })), - )) -} - -#[parser] -pub(crate) fn parameter_declaration(s: Span) -> IResult { - alt((parameter_declaration_param, parameter_declaration_type))(s) -} - -#[parser(Ambiguous)] -pub(crate) fn parameter_declaration_param(s: Span) -> IResult { - let (s, a) = keyword("parameter")(s)?; - let (s, b) = ambiguous_opt(data_type_or_implicit)(s)?; - let (s, c) = list_of_param_assignments(s)?; - Ok(( - s, - ParameterDeclaration::Param(Box::new(ParameterDeclarationParam { nodes: (a, b, c) })), - )) -} - -#[parser] -pub(crate) fn parameter_declaration_type(s: Span) -> IResult { - let (s, a) = keyword("parameter")(s)?; - let (s, b) = keyword("type")(s)?; - let (s, c) = list_of_type_assignments(s)?; - Ok(( - s, - ParameterDeclaration::Type(Box::new(ParameterDeclarationType { nodes: (a, b, c) })), - )) -} - -#[parser] -pub(crate) fn specparam_declaration(s: Span) -> IResult { - let (s, a) = keyword("specparam")(s)?; - let (s, b) = opt(packed_dimension)(s)?; - let (s, c) = list_of_specparam_assignments(s)?; - let (s, d) = symbol(";")(s)?; - Ok(( - s, - SpecparamDeclaration { - nodes: (a, b, c, d), - }, - )) -} - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_local_parameter_declaration() { - parser_test!( - local_parameter_declaration, - "localparam byte colon1 = \":\" ", - Ok((_, LocalParameterDeclaration::Param(_))) - ); - } - - #[test] - fn test_parameter_declaration() { - parser_test!( - parameter_declaration, - "parameter logic flag = 1 ", - Ok((_, ParameterDeclaration::Param(_))) - ); - parser_test!( - parameter_declaration, - "parameter e = 25, f = 9 ", - Ok((_, ParameterDeclaration::Param(_))) - ); - parser_test!( - parameter_declaration, - "parameter byte_size = 8, byte_mask = byte_size - 1", - Ok((_, ParameterDeclaration::Param(_))) - ); - parser_test!( - parameter_declaration, - "parameter signed [3:0] mux_selector = 0", - Ok((_, ParameterDeclaration::Param(_))) - ); - parser_test!( - parameter_declaration, - "parameter real r1 = 3.5e17", - Ok((_, ParameterDeclaration::Param(_))) - ); - parser_test!( - parameter_declaration, - "parameter logic [31:0] P1 [3:0] = '{ 1, 2, 3, 4 } ", - Ok((_, ParameterDeclaration::Param(_))) - ); - parser_test!( - parameter_declaration, - "parameter r2 = $ ", - Ok((_, ParameterDeclaration::Param(_))) - ); - parser_test!( - parameter_declaration, - "parameter type p2 = shortint ", - Ok((_, ParameterDeclaration::Type(_))) - ); - } - - #[test] - fn test_specparam_declaration() { - parser_test!(specparam_declaration, "specparam delay = 10 ; ", Ok((_, _))); - parser_test!( - specparam_declaration, - "specparam tRise_clk_q = 150, tFall_clk_q = 200;", - Ok((_, _)) - ); - } -} diff --git a/sv-parser/src/parser/declarations/type_declarations.rs b/sv-parser/src/parser/declarations/type_declarations.rs deleted file mode 100644 index 62dd39d..0000000 --- a/sv-parser/src/parser/declarations/type_declarations.rs +++ /dev/null @@ -1,860 +0,0 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::multi::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum DataDeclaration { - Variable(Box), - TypeDeclaration(Box), - PackageImportDeclaration(Box), - NetTypeDeclaration(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct DataDeclarationVariable { - pub nodes: ( - Option, - Option, - Option, - Option, - ListOfVariableDeclAssignments, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct Const { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct PackageImportDeclaration { - pub nodes: (Keyword, List, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub enum PackageImportItem { - Identifier(Box), - Asterisk(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PackageImportItemIdentifier { - pub nodes: (PackageIdentifier, Symbol, Identifier), -} - -#[derive(Clone, Debug, Node)] -pub struct PackageImportItemAsterisk { - pub nodes: (PackageIdentifier, Symbol, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub enum PackageExportDeclaration { - Asterisk(Box), - Item(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct PackageExportDeclarationAsterisk { - pub nodes: (Keyword, Symbol, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct PackageExportDeclarationItem { - pub nodes: (Keyword, List, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct GenvarDeclaration { - pub nodes: (Keyword, ListOfGenvarIdentifiers, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub enum NetDeclaration { - NetType(Box), - NetTypeIdentifier(Box), - Interconnect(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct NetDeclarationNetType { - pub nodes: ( - NetType, - Option, - Option, - Option, - Option, - ListOfNetDeclAssignments, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum Strength { - Drive(Box), - Charge(Box), -} - -#[derive(Clone, Debug, Node)] -pub enum VectorScalar { - Vectored(Box), - Scalared(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct NetDeclarationNetTypeIdentifier { - pub nodes: ( - NetTypeIdentifier, - Option, - ListOfNetDeclAssignments, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct NetDeclarationInterconnect { - pub nodes: ( - Keyword, - ImplicitDataType, - Option<(Symbol, DelayValue)>, - NetIdentifier, - Vec, - Option<(Symbol, NetIdentifier, Vec)>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum TypeDeclaration { - DataType(Box), - Interface(Box), - Reserved(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct TypeDeclarationDataType { - pub nodes: ( - Keyword, - DataType, - TypeIdentifier, - Vec, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct TypeDeclarationInterface { - pub nodes: ( - Keyword, - InterfaceInstanceIdentifier, - ConstantBitSelect, - Symbol, - TypeIdentifier, - TypeIdentifier, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct TypeDeclarationReserved { - pub nodes: ( - Keyword, - Option, - TypeIdentifier, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum TypeDeclarationKeyword { - Enum(Box), - Struct(Box), - Union(Box), - Class(Box), - InterfaceClass(Box<(Keyword, Keyword)>), -} - -#[derive(Clone, Debug, Node)] -pub enum NetTypeDeclaration { - DataType(Box), - NetType(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct NetTypeDeclarationDataType { - pub nodes: ( - Keyword, - DataType, - NetTypeIdentifier, - Option<(Keyword, Option, TfIdentifier)>, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct NetTypeDeclarationNetType { - pub nodes: ( - Keyword, - Option, - NetTypeIdentifier, - NetTypeIdentifier, - Symbol, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum Lifetime { - Static(Box), - Automatic(Box), -} - -// ----------------------------------------------------------------------------- - -#[parser] -pub(crate) fn data_declaration(s: Span) -> IResult { - alt(( - data_declaration_variable, - map(type_declaration, |x| { - DataDeclaration::TypeDeclaration(Box::new(x)) - }), - map(package_import_declaration, |x| { - DataDeclaration::PackageImportDeclaration(Box::new(x)) - }), - map(net_type_declaration, |x| { - DataDeclaration::NetTypeDeclaration(Box::new(x)) - }), - ))(s) -} - -#[parser(Ambiguous)] -pub(crate) fn data_declaration_variable(s: Span) -> IResult { - let (s, a) = opt(r#const)(s)?; - let (s, b) = opt(var)(s)?; - let (s, c) = opt(lifetime)(s)?; - let (s, d) = ambiguous_opt(data_type_or_implicit)(s)?; - let (s, e) = list_of_variable_decl_assignments(s)?; - let (s, f) = symbol(";")(s)?; - Ok(( - s, - DataDeclaration::Variable(Box::new(DataDeclarationVariable { - nodes: (a, b, c, d, e, f), - })), - )) -} - -#[parser] -pub(crate) fn r#const(s: Span) -> IResult { - let (s, a) = keyword("const")(s)?; - Ok((s, Const { nodes: (a,) })) -} - -#[parser] -pub(crate) fn package_import_declaration(s: Span) -> IResult { - let (s, a) = keyword("import")(s)?; - let (s, b) = list(symbol(","), package_import_item)(s)?; - let (s, c) = symbol(";")(s)?; - Ok((s, PackageImportDeclaration { nodes: (a, b, c) })) -} - -#[parser] -pub(crate) fn package_import_item(s: Span) -> IResult { - alt((package_import_item_identifier, package_import_item_asterisk))(s) -} - -#[parser] -pub(crate) fn package_import_item_identifier(s: Span) -> IResult { - let (s, a) = package_identifier(s)?; - let (s, b) = symbol("::")(s)?; - let (s, c) = identifier(s)?; - Ok(( - s, - PackageImportItem::Identifier(Box::new(PackageImportItemIdentifier { nodes: (a, b, c) })), - )) -} - -#[parser] -pub(crate) fn package_import_item_asterisk(s: Span) -> IResult { - let (s, a) = package_identifier(s)?; - let (s, b) = symbol("::")(s)?; - let (s, c) = symbol("*")(s)?; - Ok(( - s, - PackageImportItem::Asterisk(Box::new(PackageImportItemAsterisk { nodes: (a, b, c) })), - )) -} - -#[parser] -pub(crate) fn package_export_declaration(s: Span) -> IResult { - alt(( - package_export_declaration_asterisk, - package_export_declaration_item, - ))(s) -} - -#[parser] -pub(crate) fn package_export_declaration_asterisk(s: Span) -> IResult { - let (s, a) = keyword("export")(s)?; - let (s, b) = symbol("*::*")(s)?; - let (s, c) = symbol(";")(s)?; - Ok(( - s, - PackageExportDeclaration::Asterisk(Box::new(PackageExportDeclarationAsterisk { - nodes: (a, b, c), - })), - )) -} - -#[parser] -pub(crate) fn package_export_declaration_item(s: Span) -> IResult { - let (s, a) = keyword("export")(s)?; - let (s, b) = list(symbol(","), package_import_item)(s)?; - let (s, c) = symbol(";")(s)?; - Ok(( - s, - PackageExportDeclaration::Item(Box::new(PackageExportDeclarationItem { nodes: (a, b, c) })), - )) -} - -#[parser] -pub(crate) fn genvar_declaration(s: Span) -> IResult { - let (s, a) = keyword("genvar")(s)?; - let (s, b) = list_of_genvar_identifiers(s)?; - let (s, c) = symbol(";")(s)?; - Ok((s, GenvarDeclaration { nodes: (a, b, c) })) -} - -#[parser] -pub(crate) fn net_declaration(s: Span) -> IResult { - alt(( - net_declaration_interconnect, - net_declaration_net_type, - net_declaration_net_type_identifier, - ))(s) -} - -#[parser(Ambiguous)] -pub(crate) fn net_declaration_net_type(s: Span) -> IResult { - let (s, a) = net_type(s)?; - let (s, b) = opt(strength)(s)?; - let (s, c) = opt(vector_scalar)(s)?; - let (s, d) = ambiguous_opt(data_type_or_implicit)(s)?; - let (s, e) = opt(delay3)(s)?; - let (s, f) = list_of_net_decl_assignments(s)?; - let (s, g) = symbol(";")(s)?; - Ok(( - s, - NetDeclaration::NetType(Box::new(NetDeclarationNetType { - nodes: (a, b, c, d, e, f, g), - })), - )) -} - -#[parser] -pub(crate) fn strength(s: Span) -> IResult { - alt(( - map(drive_strength, |x| Strength::Drive(Box::new(x))), - map(charge_strength, |x| Strength::Charge(Box::new(x))), - ))(s) -} - -#[parser] -pub(crate) fn vector_scalar(s: Span) -> IResult { - alt(( - map(keyword("vectored"), |x| VectorScalar::Vectored(Box::new(x))), - map(keyword("scalared"), |x| VectorScalar::Scalared(Box::new(x))), - ))(s) -} - -#[parser] -pub(crate) fn net_declaration_net_type_identifier(s: Span) -> IResult { - let (s, a) = net_type_identifier(s)?; - let (s, b) = opt(delay_control)(s)?; - let (s, c) = list_of_net_decl_assignments(s)?; - let (s, d) = symbol(";")(s)?; - Ok(( - s, - NetDeclaration::NetTypeIdentifier(Box::new(NetDeclarationNetTypeIdentifier { - nodes: (a, b, c, d), - })), - )) -} - -#[parser] -pub(crate) fn net_declaration_interconnect(s: Span) -> IResult { - let (s, a) = keyword("interconnect")(s)?; - let (s, b) = implicit_data_type(s)?; - let (s, c) = opt(pair(symbol("#"), delay_value))(s)?; - let (s, d) = net_identifier(s)?; - let (s, e) = many0(unpacked_dimension)(s)?; - let (s, f) = opt(triple( - symbol(","), - net_identifier, - many0(unpacked_dimension), - ))(s)?; - let (s, g) = symbol(";")(s)?; - Ok(( - s, - NetDeclaration::Interconnect(Box::new(NetDeclarationInterconnect { - nodes: (a, b, c, d, e, f, g), - })), - )) -} - -#[parser] -pub(crate) fn type_declaration(s: Span) -> IResult { - alt(( - type_declaration_data_type, - type_declaration_interface, - type_declaration_reserved, - ))(s) -} - -#[parser] -pub(crate) fn type_declaration_data_type(s: Span) -> IResult { - let (s, a) = keyword("typedef")(s)?; - let (s, b) = data_type(s)?; - let (s, c) = type_identifier(s)?; - let (s, d) = many0(variable_dimension)(s)?; - let (s, e) = symbol(";")(s)?; - Ok(( - s, - TypeDeclaration::DataType(Box::new(TypeDeclarationDataType { - nodes: (a, b, c, d, e), - })), - )) -} - -#[parser] -pub(crate) fn type_declaration_interface(s: Span) -> IResult { - let (s, a) = keyword("typedef")(s)?; - let (s, b) = interface_instance_identifier(s)?; - let (s, c) = constant_bit_select(s)?; - let (s, d) = symbol(".")(s)?; - let (s, e) = type_identifier(s)?; - let (s, f) = type_identifier(s)?; - let (s, g) = symbol(";")(s)?; - Ok(( - s, - TypeDeclaration::Interface(Box::new(TypeDeclarationInterface { - nodes: (a, b, c, d, e, f, g), - })), - )) -} - -#[parser] -pub(crate) fn type_declaration_reserved(s: Span) -> IResult { - let (s, a) = keyword("typedef")(s)?; - let (s, b) = opt(type_declaration_keyword)(s)?; - let (s, c) = type_identifier(s)?; - let (s, d) = symbol(";")(s)?; - Ok(( - s, - TypeDeclaration::Reserved(Box::new(TypeDeclarationReserved { - nodes: (a, b, c, d), - })), - )) -} - -#[parser] -pub(crate) fn type_declaration_keyword(s: Span) -> IResult { - alt(( - map(keyword("enum"), |x| { - TypeDeclarationKeyword::Enum(Box::new(x)) - }), - map(keyword("struct"), |x| { - TypeDeclarationKeyword::Struct(Box::new(x)) - }), - map(keyword("union"), |x| { - TypeDeclarationKeyword::Union(Box::new(x)) - }), - map(keyword("class"), |x| { - TypeDeclarationKeyword::Class(Box::new(x)) - }), - map(pair(keyword("interface"), keyword("class")), |x| { - TypeDeclarationKeyword::InterfaceClass(Box::new(x)) - }), - ))(s) -} - -#[parser] -pub(crate) fn net_type_declaration(s: Span) -> IResult { - alt(( - net_type_declaration_data_type, - net_type_declaration_net_type, - ))(s) -} - -#[parser] -pub(crate) fn net_type_declaration_data_type(s: Span) -> IResult { - let (s, a) = keyword("nettype")(s)?; - let (s, b) = data_type(s)?; - let (s, c) = net_type_identifier(s)?; - let (s, d) = opt(triple( - keyword("with"), - opt(package_scope_or_class_scope), - tf_identifier, - ))(s)?; - let (s, e) = symbol(";")(s)?; - Ok(( - s, - NetTypeDeclaration::DataType(Box::new(NetTypeDeclarationDataType { - nodes: (a, b, c, d, e), - })), - )) -} - -#[parser] -pub(crate) fn net_type_declaration_net_type(s: Span) -> IResult { - let (s, a) = keyword("nettype")(s)?; - let (s, b) = opt(package_scope_or_class_scope)(s)?; - let (s, c) = net_type_identifier(s)?; - let (s, d) = net_type_identifier(s)?; - let (s, e) = symbol(";")(s)?; - Ok(( - s, - NetTypeDeclaration::NetType(Box::new(NetTypeDeclarationNetType { - nodes: (a, b, c, d, e), - })), - )) -} - -#[parser] -pub(crate) fn lifetime(s: Span) -> IResult { - alt(( - map(keyword("static"), |x| Lifetime::Static(Box::new(x))), - map(keyword("automatic"), |x| Lifetime::Automatic(Box::new(x))), - ))(s) -} - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_net_type_declaration() { - parser_test!( - net_type_declaration, - "nettype T wT;", - Ok((_, NetTypeDeclaration::DataType(_))) - ); - parser_test!( - net_type_declaration, - "nettype T wTsum with Tsum;", - Ok((_, NetTypeDeclaration::DataType(_))) - ); - parser_test!( - net_type_declaration, - "nettype MyBaseT::T narrowTsum with MyBaseT::Tsum;", - Ok((_, NetTypeDeclaration::DataType(_))) - ); - } - - #[test] - fn test_net_declaration() { - parser_test!( - net_declaration, - "trireg (large) logic #(0,0,0) cap1;", - Ok((_, NetDeclaration::NetType(_))) - ); - parser_test!( - net_declaration, - "wire addressT w1;", - Ok((_, NetDeclaration::NetType(_))) - ); - parser_test!( - net_declaration, - "wire struct packed { logic ecc; logic [7:0] data; } memsig;", - Ok((_, NetDeclaration::NetType(_))) - ); - parser_test!( - net_declaration, - "wire w;", - Ok((_, NetDeclaration::NetType(_))) - ); - parser_test!( - net_declaration, - "wire [15:0] w;", - Ok((_, NetDeclaration::NetType(_))) - ); - parser_test!( - net_declaration, - "interconnect w1;", - Ok((_, NetDeclaration::Interconnect(_))) - ); - parser_test!( - net_declaration, - "interconnect [3:0] w2;", - Ok((_, NetDeclaration::Interconnect(_))) - ); - parser_test!( - net_declaration, - "interconnect [3:0] w3 [1:0];", - Ok((_, NetDeclaration::Interconnect(_))) - ); - parser_test!(net_declaration, "interconnect logic [3:0] w4;", Err(_)); - parser_test!(net_declaration, "interconnect #(1,2,3) w5;", Err(_)); - parser_test!( - net_declaration, - "wand w;", - Ok((_, NetDeclaration::NetType(_))) - ); - parser_test!( - net_declaration, - "tri [15:0] busa;", - Ok((_, NetDeclaration::NetType(_))) - ); - parser_test!( - net_declaration, - "trireg (small) storeit;", - Ok((_, NetDeclaration::NetType(_))) - ); - parser_test!( - net_declaration, - "wire w1, w2;", - Ok((_, NetDeclaration::NetType(_))) - ); - parser_test!( - net_declaration, - "tri1 scalared [63:0] bus64;", - Ok((_, NetDeclaration::NetType(_))) - ); - parser_test!( - net_declaration, - "tri vectored [31:0] data;", - Ok((_, NetDeclaration::NetType(_))) - ); - } - - #[test] - fn test_data_declaration() { - //parser_test!( - // data_declaration, - // "shortint s1, s2[0:9];", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "var byte my_byte;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "var v;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "var [15:0] vw;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "var enum bit { clear, error } status;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "var reg r;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "int i = 0;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "logic a;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "logic[3:0] v;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "logic signed [3:0] signed_reg;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "logic [-1:4] b;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "logic [4:0] x, y, z;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "int unsigned ui;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "int signed si;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "string myName = default_name;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "byte c = \"A\";", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "bit [10:0] b = \"x41\";", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "bit [1:4][7:0] h = \"hello\" ;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "event done;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "event done_too = done;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "event empty = null;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "typedef int intP;", - // Ok((_, DataDeclaration::TypeDeclaration(_))) - //); - //parser_test!( - // data_declaration, - // "intP a, b;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "typedef enum type_identifier;", - // Ok((_, DataDeclaration::TypeDeclaration(_))) - //); - //parser_test!( - // data_declaration, - // "typedef struct type_identifier;", - // Ok((_, DataDeclaration::TypeDeclaration(_))) - //); - //parser_test!( - // data_declaration, - // "typedef union type_identifier;", - // Ok((_, DataDeclaration::TypeDeclaration(_))) - //); - //parser_test!( - // data_declaration, - // "typedef class type_identifier;", - // Ok((_, DataDeclaration::TypeDeclaration(_))) - //); - //parser_test!( - // data_declaration, - // "typedef interface class type_identifier;", - // Ok((_, DataDeclaration::TypeDeclaration(_))) - //); - //parser_test!( - // data_declaration, - // "typedef type_identifier;", - // Ok((_, DataDeclaration::TypeDeclaration(_))) - //); - //parser_test!( - // data_declaration, - // "typedef C::T c_t;", - // Ok((_, DataDeclaration::TypeDeclaration(_))) - //); - //parser_test!( - // data_declaration, - // "enum {red, yellow, green} light1, light2;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "enum bit [1:0] {IDLE, XX='x, S1=2'b01, S2=2'b10} state, next;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "enum integer {IDLE, XX='x, S1='b01, S2='b10} state, next;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "enum integer {IDLE, XX='x, S1='b01, S2='b10} state, next;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "enum {bronze=3, silver, gold} medal;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "enum {a=3, b=7, c} alphabet;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "enum bit [3:0] {bronze='h3, silver, gold='h5} medal2;", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "integer i_array[*];", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "bit [20:0] array_b[string];", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "event ev_array[myClass];", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "int array_name [*];", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "int array_name1 [ integer ];", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "int a[int] = '{default:1};", - // Ok((_, DataDeclaration::Variable(_))) - //); - //parser_test!( - // data_declaration, - // "byte q1[$];", - // Ok((_, DataDeclaration::Variable(_))) - //); - parser_test!(primary, "'{default:1}", Ok((_, _))); - } -} diff --git a/sv-parser/src/parser/expressions/expression_leftside_values.rs b/sv-parser/src/parser/expressions/expression_leftside_values.rs deleted file mode 100644 index 2feb206..0000000 --- a/sv-parser/src/parser/expressions/expression_leftside_values.rs +++ /dev/null @@ -1,190 +0,0 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::combinator::*; -use nom::IResult; -use nom_packrat::packrat_parser; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub enum NetLvalue { - Identifier(Box), - Lvalue(Box), - Pattern(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct NetLvalueIdentifier { - pub nodes: (PsOrHierarchicalNetIdentifier, ConstantSelect), -} - -#[derive(Clone, Debug, Node)] -pub struct NetLvalueLvalue { - pub nodes: (Brace>,), -} - -#[derive(Clone, Debug, Node)] -pub struct NetLvaluePattern { - pub nodes: ( - Option, - AssignmentPatternNetLvalue, - ), -} - -#[derive(Clone, Debug, Node)] -pub enum VariableLvalue { - Identifier(Box), - Lvalue(Box), - Pattern(Box), - StreamingConcatenation(Box), -} - -#[derive(Clone, Debug, Node)] -pub struct VariableLvalueIdentifier { - pub nodes: ( - Option, - HierarchicalVariableIdentifier, - Select, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct VariableLvalueLvalue { - pub nodes: (Brace>,), -} - -#[derive(Clone, Debug, Node)] -pub struct VariableLvaluePattern { - pub nodes: ( - Option, - AssignmentPatternVariableLvalue, - ), -} - -#[derive(Clone, Debug, Node)] -pub struct NonrangeVariableLvalue { - pub nodes: ( - Option, - HierarchicalVariableIdentifier, - NonrangeSelect, - ), -} - -// ----------------------------------------------------------------------------- - -#[packrat_parser] -#[parser] -pub(crate) fn net_lvalue(s: Span) -> IResult { - alt((net_lvalue_identifier, net_lvalue_lvalue, net_lvalue_pattern))(s) -} - -#[parser] -pub(crate) fn net_lvalue_identifier(s: Span) -> IResult { - let (s, a) = ps_or_hierarchical_net_identifier(s)?; - let (s, b) = constant_select(s)?; - Ok(( - s, - NetLvalue::Identifier(Box::new(NetLvalueIdentifier { nodes: (a, b) })), - )) -} - -#[parser] -pub(crate) fn net_lvalue_pattern(s: Span) -> IResult { - let (s, a) = opt(assignment_pattern_expression_type)(s)?; - let (s, b) = assignment_pattern_net_lvalue(s)?; - Ok(( - s, - NetLvalue::Pattern(Box::new(NetLvaluePattern { nodes: (a, b) })), - )) -} - -#[parser] -pub(crate) fn net_lvalue_lvalue(s: Span) -> IResult { - let (s, a) = brace(list(symbol(","), net_lvalue))(s)?; - Ok(( - s, - NetLvalue::Lvalue(Box::new(NetLvalueLvalue { nodes: (a,) })), - )) -} - -#[packrat_parser] -#[parser] -pub(crate) fn variable_lvalue(s: Span) -> IResult { - alt(( - variable_lvalue_identifier, - variable_lvalue_lvalue, - variable_lvalue_pattern, - map(streaming_concatenation, |x| { - VariableLvalue::StreamingConcatenation(Box::new(x)) - }), - ))(s) -} - -#[parser] -pub(crate) fn variable_lvalue_identifier(s: Span) -> IResult { - let (s, a) = opt(implicit_class_handle_or_package_scope)(s)?; - let (s, b) = hierarchical_variable_identifier(s)?; - let (s, c) = select(s)?; - Ok(( - s, - VariableLvalue::Identifier(Box::new(VariableLvalueIdentifier { nodes: (a, b, c) })), - )) -} - -#[parser] -pub(crate) fn variable_lvalue_pattern(s: Span) -> IResult { - let (s, a) = opt(assignment_pattern_expression_type)(s)?; - let (s, b) = assignment_pattern_variable_lvalue(s)?; - Ok(( - s, - VariableLvalue::Pattern(Box::new(VariableLvaluePattern { nodes: (a, b) })), - )) -} - -#[parser] -pub(crate) fn variable_lvalue_lvalue(s: Span) -> IResult { - let (s, a) = brace(list(symbol(","), variable_lvalue))(s)?; - Ok(( - s, - VariableLvalue::Lvalue(Box::new(VariableLvalueLvalue { nodes: (a,) })), - )) -} - -#[parser] -pub(crate) fn nonrange_variable_lvalue(s: Span) -> IResult { - let (s, a) = opt(implicit_class_handle_or_package_scope)(s)?; - let (s, b) = hierarchical_variable_identifier(s)?; - let (s, c) = nonrange_select(s)?; - Ok((s, NonrangeVariableLvalue { nodes: (a, b, c) })) -} - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_net_lvalue() { - parser_test!(net_lvalue, "A", Ok((_, _))); - parser_test!(net_lvalue, "{A[7:0],A[15:8],A[23:16]}", Ok((_, _))); - parser_test!(net_lvalue, "'{A[7:0],A[15:8]}", Ok((_, _))); - } - - #[test] - fn test_variable_lvalue() { - parser_test!(variable_lvalue, "A", Ok((_, _))); - parser_test!(variable_lvalue, "{A[7:0],A[15:8],A[23:16]}", Ok((_, _))); - parser_test!(variable_lvalue, "'{A[7:0],A[15:8]}", Ok((_, _))); - } - - #[test] - fn test_nonrange_variable_lvalue() { - parser_test!(nonrange_variable_lvalue, "A", Ok((_, _))); - parser_test!(nonrange_variable_lvalue, "A[1][2][3]", Ok((_, _))); - //TODO - //parser_test!(nonrange_variable_lvalue, "A[][2][3]", Ok((_, _))); - //parser_test!(nonrange_variable_lvalue, "A[][]", Ok((_, _))); - } -} diff --git a/sv-parser/src/parser/expressions/operators.rs b/sv-parser/src/parser/expressions/operators.rs deleted file mode 100644 index fdb08cc..0000000 --- a/sv-parser/src/parser/expressions/operators.rs +++ /dev/null @@ -1,219 +0,0 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::IResult; -use nom_packrat::packrat_parser; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct UnaryOperator { - pub nodes: (Symbol,), -} - -#[derive(Clone, Debug, Node)] -pub struct BinaryOperator { - pub nodes: (Symbol,), -} - -#[derive(Clone, Debug, Node)] -pub struct IncOrDecOperator { - pub nodes: (Symbol,), -} - -#[derive(Clone, Debug, Node)] -pub struct UnaryModulePathOperator { - pub nodes: (Symbol,), -} - -#[derive(Clone, Debug, Node)] -pub struct BinaryModulePathOperator { - pub nodes: (Symbol,), -} - -// ----------------------------------------------------------------------------- - -#[packrat_parser] -#[parser] -pub(crate) fn unary_operator(s: Span) -> IResult { - let (s, a) = alt(( - symbol("+"), - symbol("-"), - symbol("!"), - symbol("&"), - symbol("|"), - symbol("~&"), - symbol("~|"), - symbol("~^"), - symbol("^~"), - symbol("^"), - symbol("~"), - ))(s)?; - Ok((s, UnaryOperator { nodes: (a,) })) -} - -#[parser] -pub(crate) fn binary_operator(s: Span) -> IResult { - let (s, a) = alt(( - alt(( - symbol("+"), - symbol("->"), - symbol("-"), - symbol("**"), - symbol("*"), - symbol("/"), - symbol("%"), - symbol("==="), - symbol("==?"), - symbol("=="), - symbol("!=="), - symbol("!=?"), - symbol("!="), - symbol("&&"), - symbol("||"), - )), - alt(( - symbol("&"), - symbol("|"), - symbol("^~"), - symbol("^"), - symbol("~^"), - symbol(">>>"), - symbol(">>"), - symbol("<<<"), - symbol("<<"), - symbol("<->"), - symbol("<="), - symbol("<"), - symbol(">="), - symbol(">"), - )), - ))(s)?; - Ok((s, BinaryOperator { nodes: (a,) })) -} - -#[parser] -pub(crate) fn inc_or_dec_operator(s: Span) -> IResult { - let (s, a) = alt((symbol("++"), symbol("--")))(s)?; - Ok((s, IncOrDecOperator { nodes: (a,) })) -} - -#[parser] -pub(crate) fn unary_module_path_operator(s: Span) -> IResult { - let (s, a) = alt(( - symbol("!"), - symbol("&"), - symbol("|"), - symbol("~&"), - symbol("~|"), - symbol("~^"), - symbol("^~"), - symbol("^"), - symbol("~"), - ))(s)?; - Ok((s, UnaryModulePathOperator { nodes: (a,) })) -} - -#[parser] -pub(crate) fn binary_module_path_operator(s: Span) -> IResult { - let (s, a) = alt(( - symbol("=="), - symbol("!="), - symbol("&&"), - symbol("||"), - symbol("&"), - symbol("|"), - symbol("^~"), - symbol("^"), - symbol("~^"), - ))(s)?; - Ok((s, BinaryModulePathOperator { nodes: (a,) })) -} - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - use super::*; - use nom::combinator::*; - - #[test] - fn test_unary_operator() { - parser_test!(unary_operator, "+", Ok((_, _))); - parser_test!(unary_operator, "-", Ok((_, _))); - parser_test!(unary_operator, "!", Ok((_, _))); - parser_test!(unary_operator, "&", Ok((_, _))); - parser_test!(unary_operator, "|", Ok((_, _))); - parser_test!(unary_operator, "~&", Ok((_, _))); - parser_test!(unary_operator, "~|", Ok((_, _))); - parser_test!(unary_operator, "~^", Ok((_, _))); - parser_test!(unary_operator, "^~", Ok((_, _))); - parser_test!(unary_operator, "^", Ok((_, _))); - parser_test!(unary_operator, "~", Ok((_, _))); - } - - #[test] - fn test_binary_operator() { - parser_test!(binary_operator, "+", Ok((_, _))); - parser_test!(binary_operator, "-", Ok((_, _))); - parser_test!(binary_operator, "**", Ok((_, _))); - parser_test!(binary_operator, "*", Ok((_, _))); - parser_test!(binary_operator, "/", Ok((_, _))); - parser_test!(binary_operator, "%", Ok((_, _))); - parser_test!(binary_operator, "===", Ok((_, _))); - parser_test!(binary_operator, "==?", Ok((_, _))); - parser_test!(binary_operator, "==", Ok((_, _))); - parser_test!(binary_operator, "!==", Ok((_, _))); - parser_test!(binary_operator, "!=?", Ok((_, _))); - parser_test!(binary_operator, "!=", Ok((_, _))); - parser_test!(binary_operator, "&&", Ok((_, _))); - parser_test!(binary_operator, "||", Ok((_, _))); - parser_test!(binary_operator, "&", Ok((_, _))); - parser_test!(binary_operator, "|", Ok((_, _))); - parser_test!(binary_operator, "^~", Ok((_, _))); - parser_test!(binary_operator, "^", Ok((_, _))); - parser_test!(binary_operator, "~^", Ok((_, _))); - parser_test!(binary_operator, ">>>", Ok((_, _))); - parser_test!(binary_operator, ">>", Ok((_, _))); - parser_test!(binary_operator, "<<<", Ok((_, _))); - parser_test!(binary_operator, "<<", Ok((_, _))); - parser_test!(binary_operator, "->", Ok((_, _))); - parser_test!(binary_operator, "<->", Ok((_, _))); - parser_test!(binary_operator, "<=", Ok((_, _))); - parser_test!(binary_operator, "<", Ok((_, _))); - parser_test!(binary_operator, ">=", Ok((_, _))); - parser_test!(binary_operator, ">", Ok((_, _))); - } - - #[test] - fn test_inc_or_dec_operator() { - parser_test!(inc_or_dec_operator, "++", Ok((_, _))); - parser_test!(inc_or_dec_operator, "--", Ok((_, _))); - } - - #[test] - fn test_unary_module_path_operator() { - parser_test!(unary_module_path_operator, "!", Ok((_, _))); - parser_test!(unary_module_path_operator, "&", Ok((_, _))); - parser_test!(unary_module_path_operator, "|", Ok((_, _))); - parser_test!(unary_module_path_operator, "~&", Ok((_, _))); - parser_test!(unary_module_path_operator, "~|", Ok((_, _))); - parser_test!(unary_module_path_operator, "~^", Ok((_, _))); - parser_test!(unary_module_path_operator, "^~", Ok((_, _))); - parser_test!(unary_module_path_operator, "^", Ok((_, _))); - parser_test!(unary_module_path_operator, "~", Ok((_, _))); - } - - #[test] - fn test_binary_module_path_operator() { - parser_test!(binary_module_path_operator, "==", Ok((_, _))); - parser_test!(binary_module_path_operator, "!=", Ok((_, _))); - parser_test!(binary_module_path_operator, "&&", Ok((_, _))); - parser_test!(binary_module_path_operator, "||", Ok((_, _))); - parser_test!(binary_module_path_operator, "&", Ok((_, _))); - parser_test!(binary_module_path_operator, "|", Ok((_, _))); - parser_test!(binary_module_path_operator, "^~", Ok((_, _))); - parser_test!(binary_module_path_operator, "^", Ok((_, _))); - parser_test!(binary_module_path_operator, "~^", Ok((_, _))); - } -} diff --git a/sv-parser/src/parser/general/attributes.rs b/sv-parser/src/parser/general/attributes.rs deleted file mode 100644 index d7ec4ec..0000000 --- a/sv-parser/src/parser/general/attributes.rs +++ /dev/null @@ -1,56 +0,0 @@ -use crate::ast::*; -use crate::parser::*; -use nom::combinator::*; -use nom::sequence::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct AttributeInstance { - pub nodes: (Symbol, List, Symbol), -} - -#[derive(Clone, Debug, Node)] -pub struct AttrSpec { - pub nodes: (Identifier, Option<(Symbol, ConstantExpression)>), -} - -// ----------------------------------------------------------------------------- - -#[parser] -pub(crate) fn attribute_instance(s: Span) -> IResult { - let (s, a) = symbol("(*")(s)?; - let (s, b) = list(symbol(","), attr_spec)(s)?; - let (s, c) = symbol("*)")(s)?; - Ok((s, AttributeInstance { nodes: (a, b, c) })) -} - -#[parser] -pub(crate) fn attr_spec(s: Span) -> IResult { - let (s, a) = identifier(s)?; - let (s, b) = opt(pair(symbol("="), constant_expression))(s)?; - Ok((s, AttrSpec { nodes: (a, b) })) -} - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_attribute_instance() { - parser_test!( - attribute_instance, - "(* full_case, parallel_case *)", - Ok((_, _)) - ); - parser_test!(attribute_instance, "(* full_case=1 *)", Ok((_, _))); - parser_test!( - attribute_instance, - "(* full_case=1, parallel_case = 0 *)", - Ok((_, _)) - ); - } -} diff --git a/sv-parser/src/parser/primitive_instances/primitive_gate_and_switch_types.rs b/sv-parser/src/parser/primitive_instances/primitive_gate_and_switch_types.rs deleted file mode 100644 index fbe2c33..0000000 --- a/sv-parser/src/parser/primitive_instances/primitive_gate_and_switch_types.rs +++ /dev/null @@ -1,167 +0,0 @@ -use crate::ast::*; -use crate::parser::*; -use nom::branch::*; -use nom::IResult; - -// ----------------------------------------------------------------------------- - -#[derive(Clone, Debug, Node)] -pub struct CmosSwitchtype { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct EnableGatetype { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct MosSwitchtype { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct NInputGatetype { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct NOutputGatetype { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct PassEnSwitchtype { - pub nodes: (Keyword,), -} - -#[derive(Clone, Debug, Node)] -pub struct PassSwitchtype { - pub nodes: (Keyword,), -} - -// ----------------------------------------------------------------------------- - -#[parser] -pub(crate) fn cmos_switchtype(s: Span) -> IResult { - let (s, a) = alt((keyword("cmos"), keyword("rcmos")))(s)?; - Ok((s, CmosSwitchtype { nodes: (a,) })) -} - -#[parser] -pub(crate) fn enable_gatetype(s: Span) -> IResult { - let (s, a) = alt(( - keyword("bufif0"), - keyword("bufif1"), - keyword("notif0"), - keyword("notif1"), - ))(s)?; - Ok((s, EnableGatetype { nodes: (a,) })) -} - -#[parser] -pub(crate) fn mos_switchtype(s: Span) -> IResult { - let (s, a) = alt(( - keyword("nmos"), - keyword("pmos"), - keyword("rnmos"), - keyword("rpmos"), - ))(s)?; - Ok((s, MosSwitchtype { nodes: (a,) })) -} - -#[parser] -pub(crate) fn n_input_gatetype(s: Span) -> IResult { - let (s, a) = alt(( - keyword("and"), - keyword("nand"), - keyword("or"), - keyword("nor"), - keyword("xor"), - keyword("xnor"), - ))(s)?; - Ok((s, NInputGatetype { nodes: (a,) })) -} - -#[parser] -pub(crate) fn n_output_gatetype(s: Span) -> IResult { - let (s, a) = alt((keyword("buf"), keyword("not")))(s)?; - Ok((s, NOutputGatetype { nodes: (a,) })) -} - -#[parser] -pub(crate) fn pass_en_switchtype(s: Span) -> IResult { - let (s, a) = alt(( - keyword("tranif0"), - keyword("tranif1"), - keyword("rtranif0"), - keyword("rtranif1"), - ))(s)?; - Ok((s, PassEnSwitchtype { nodes: (a,) })) -} - -#[parser] -pub(crate) fn pass_switchtype(s: Span) -> IResult { - let (s, a) = alt((keyword("tran"), keyword("rtran")))(s)?; - Ok((s, PassSwitchtype { nodes: (a,) })) -} - -// ----------------------------------------------------------------------------- - -#[cfg(test)] -mod tests { - use super::*; - use nom::combinator::*; - - #[test] - fn test_cmos_switchtype() { - parser_test!(cmos_switchtype, "cmos ", Ok((_, _))); - parser_test!(cmos_switchtype, "rcmos ", Ok((_, _))); - } - - #[test] - fn test_enable_gatetype() { - parser_test!(enable_gatetype, "bufif0 ", Ok((_, _))); - parser_test!(enable_gatetype, "bufif1 ", Ok((_, _))); - parser_test!(enable_gatetype, "notif0 ", Ok((_, _))); - parser_test!(enable_gatetype, "notif1 ", Ok((_, _))); - } - - #[test] - fn test_mos_switchtype() { - parser_test!(mos_switchtype, "nmos ", Ok((_, _))); - parser_test!(mos_switchtype, "pmos ", Ok((_, _))); - parser_test!(mos_switchtype, "rnmos ", Ok((_, _))); - parser_test!(mos_switchtype, "rpmos ", Ok((_, _))); - } - - #[test] - fn test_n_input_gatetype() { - parser_test!(n_input_gatetype, "and ", Ok((_, _))); - parser_test!(n_input_gatetype, "nand ", Ok((_, _))); - parser_test!(n_input_gatetype, "or ", Ok((_, _))); - parser_test!(n_input_gatetype, "nor ", Ok((_, _))); - parser_test!(n_input_gatetype, "xor ", Ok((_, _))); - parser_test!(n_input_gatetype, "xnor ", Ok((_, _))); - } - - #[test] - fn test_n_output_gatetype() { - parser_test!(n_output_gatetype, "buf ", Ok((_, _))); - parser_test!(n_output_gatetype, "not ", Ok((_, _))); - } - - #[test] - fn test_pass_en_switchtype() { - parser_test!(pass_en_switchtype, "tranif0 ", Ok((_, _))); - parser_test!(pass_en_switchtype, "tranif1 ", Ok((_, _))); - parser_test!(pass_en_switchtype, "rtranif0 ", Ok((_, _))); - parser_test!(pass_en_switchtype, "rtranif1 ", Ok((_, _))); - } - - #[test] - fn test_pass_switchtype() { - parser_test!(pass_switchtype, "tran ", Ok((_, _))); - parser_test!(pass_switchtype, "rtran ", Ok((_, _))); - } -}