From 17c031a7ab99618fd5a849eaccffe022ebd77098 Mon Sep 17 00:00:00 2001 From: maor malka Date: Wed, 26 Feb 2025 16:47:16 -0500 Subject: [PATCH 1/3] preparser: adding 2 optional compiler directives `delay_mode_path , `delay_mode_distributed --- .../src/general/compiler_directives.rs | 65 +++++++++++++++++++ sv-parser-parser/src/keywords.rs | 4 ++ sv-parser-pp/src/preprocess.rs | 44 +++++++++++++ .../IEEE18002017_AnnexE_delaydirectives.sv | 11 ++++ .../src/general/compiler_directives.rs | 25 +++++++ 5 files changed, 149 insertions(+) create mode 100644 sv-parser-pp/testcases/IEEE18002017_AnnexE_delaydirectives.sv diff --git a/sv-parser-parser/src/general/compiler_directives.rs b/sv-parser-parser/src/general/compiler_directives.rs index 2eea5f6e..48f5eee1 100644 --- a/sv-parser-parser/src/general/compiler_directives.rs +++ b/sv-parser-parser/src/general/compiler_directives.rs @@ -59,6 +59,18 @@ pub(crate) fn compiler_directive(s: Span) -> IResult { map(text_macro_usage, |x| { CompilerDirective::TextMacroUsage(Box::new(x)) }), + map(delay_mode_distributed_compiler_directive, |x| { + CompilerDirective::DelayModeDistributedDirective(Box::new(x)) + }), + map(delay_mode_path_compiler_directive, |x| { + CompilerDirective::DelayModePathDirective(Box::new(x)) + }), + // map(delay_mode_unit_compiler_directive, |x| { + // CompilerDirective::DelayModeUnitDirective(Box::new(x)) + // }), + // map(delay_mode_zero_compiler_directive, |x| { + // CompilerDirective::DelayModeZeroDirective(Box::new(x)) + // }), ))(s); end_directive(); ret @@ -118,6 +130,18 @@ pub(crate) fn compiler_directive_without_resetall(s: Span) -> IResult IResult IResult { + let (s, a) = symbol("`")(s)?; + let (s, b) = keyword("delay_mode_distributed")(s)?; + Ok((s, DelayModeDistributedDirective { nodes: (a, b) })) +} + +#[tracable_parser] +#[packrat_parser] +pub(crate) fn delay_mode_path_compiler_directive( + s: Span, +) -> IResult { + let (s, a) = symbol("`")(s)?; + let (s, b) = keyword("delay_mode_path")(s)?; + Ok((s, DelayModePathDirective { nodes: (a, b) })) +} + +//TODO: bring back once nom issue is solved +// #[tracable_parser] +// #[packrat_parser] +// pub(crate) fn delay_mode_unit_compiler_directive( +// s: Span, +// ) -> IResult { +// let (s, a) = symbol("`")(s)?; +// let (s, b) = keyword("delay_mode_unit")(s)?; +// Ok((s, DelayModeUnitDirective { nodes: (a, b) })) +// } + +// #[tracable_parser] +// #[packrat_parser] +// pub(crate) fn delay_mode_zero_compiler_directive( +// s: Span, +// ) -> IResult { +// let (s, a) = symbol("`")(s)?; +// let (s, b) = keyword("delay_mode_zero")(s)?; +// Ok((s, DelayModeZeroDirective { nodes: (a, b) })) +// } \ No newline at end of file diff --git a/sv-parser-parser/src/keywords.rs b/sv-parser-parser/src/keywords.rs index 52442fef..2fdbb1a8 100644 --- a/sv-parser-parser/src/keywords.rs +++ b/sv-parser-parser/src/keywords.rs @@ -1466,4 +1466,8 @@ pub(crate) const KEYWORDS_DIRECTIVE: &[&str] = &[ "unconnected_drive", "undef", "undefineall", + "delay_mode_distributed", + "delay_mode_path", + // "delay_mode_unit", + // "delay_mode_zero" ]; diff --git a/sv-parser-pp/src/preprocess.rs b/sv-parser-pp/src/preprocess.rs index 9a01eff3..0f90bff3 100644 --- a/sv-parser-pp/src/preprocess.rs +++ b/sv-parser-pp/src/preprocess.rs @@ -406,6 +406,42 @@ pub fn preprocess_str, U: AsRef, V: BuildHasher>( NodeEvent::Leave(RefNode::EndcelldefineDriveCompilerDirective(_)) => { skip_whitespace = false; } + NodeEvent::Enter(RefNode::DelayModeDistributedDirective(x)) => { + let locate: Locate = x.try_into().unwrap(); + let range = Range::new(locate.offset, locate.offset + locate.len); + ret.push(locate.str(&s), Some((path.as_ref(), range))); + skip_whitespace = true; + } + NodeEvent::Leave(RefNode::DelayModeDistributedDirective(_)) => { + skip_whitespace = false; + } + NodeEvent::Enter(RefNode::DelayModePathDirective(x)) => { + let locate: Locate = x.try_into().unwrap(); + let range = Range::new(locate.offset, locate.offset + locate.len); + ret.push(locate.str(&s), Some((path.as_ref(), range))); + skip_whitespace = true; + } + NodeEvent::Leave(RefNode::DelayModePathDirective(_)) => { + skip_whitespace = false; + } + // NodeEvent::Enter(RefNode::DelayModeUnitDirective(x)) => { + // let locate: Locate = x.try_into().unwrap(); + // let range = Range::new(locate.offset, locate.offset + locate.len); + // ret.push(locate.str(&s), Some((path.as_ref(), range))); + // skip_whitespace = true; + // } + // NodeEvent::Leave(RefNode::DelayModeUnitDirective(_)) => { + // skip_whitespace = false; + // } + // NodeEvent::Enter(RefNode::DelayModeZeroDirective(x)) => { + // let locate: Locate = x.try_into().unwrap(); + // let range = Range::new(locate.offset, locate.offset + locate.len); + // ret.push(locate.str(&s), Some((path.as_ref(), range))); + // skip_whitespace = true; + // } + // NodeEvent::Leave(RefNode::DelayModeZeroDirective(_)) => { + // skip_whitespace = false; + // } NodeEvent::Enter(RefNode::Pragma(x)) => { let locate: Locate = x.try_into().unwrap(); let range = Range::new(locate.offset, locate.offset + locate.len); @@ -1639,4 +1675,12 @@ mod tests { testfile_contents("expected/undefineall.sv") ); } // }}} + + #[test] + fn annex_e(){ + match preprocess_usualargs("IEEE18002017_AnnexE_delaydirectives.sv"){ + Ok(_x) => (), + Err(x) => panic!("failed with {}",x) + } + } } diff --git a/sv-parser-pp/testcases/IEEE18002017_AnnexE_delaydirectives.sv b/sv-parser-pp/testcases/IEEE18002017_AnnexE_delaydirectives.sv new file mode 100644 index 00000000..a1535b2e --- /dev/null +++ b/sv-parser-pp/testcases/IEEE18002017_AnnexE_delaydirectives.sv @@ -0,0 +1,11 @@ +/* +The compiler directives described in this annex are for informative purposes only and are not part of this +standard. +This annex describes additional compiler directives as companions to the compiler directives described in +Clause 22. The compiler directives described in this annex may not be available in all implementations of +SystemVerilog. The following compiler directives are described in this annex: +*/ + + +`delay_mode_distributed //[E.4] +`delay_mode_path //[E.5] diff --git a/sv-parser-syntaxtree/src/general/compiler_directives.rs b/sv-parser-syntaxtree/src/general/compiler_directives.rs index e0c7c269..834fff8a 100644 --- a/sv-parser-syntaxtree/src/general/compiler_directives.rs +++ b/sv-parser-syntaxtree/src/general/compiler_directives.rs @@ -22,6 +22,10 @@ pub enum CompilerDirective { PositionCompilerDirective(Box), KeywordsDirective(Box), EndkeywordsDirective(Box), + DelayModeDistributedDirective(Box), + DelayModePathDirective(Box), + // DelayModeUnitDirective(Box), + // DelayModeZeroDirective(Box) } #[derive(Clone, Debug, PartialEq, Node)] @@ -305,3 +309,24 @@ pub struct VersionSpecifier { pub struct EndkeywordsDirective { pub nodes: (Symbol, Keyword), } + + +#[derive(Clone, Debug, PartialEq, Node)] +pub struct DelayModeDistributedDirective { + pub nodes: (Symbol, Keyword), +} + +#[derive(Clone, Debug, PartialEq, Node)] +pub struct DelayModePathDirective { + pub nodes: (Symbol, Keyword), +} + +#[derive(Clone, Debug, PartialEq, Node)] +pub struct DelayModeUnitDirective { + pub nodes: (Symbol, Keyword), +} + +#[derive(Clone, Debug, PartialEq, Node)] +pub struct DelayModeZeroDirective { + pub nodes: (Symbol, Keyword), +} From dabd7734ec9578ae32c9cae7feb7251c7f70eb0b Mon Sep 17 00:00:00 2001 From: maor malka Date: Thu, 27 Feb 2025 06:34:19 -0500 Subject: [PATCH 2/3] revised compiler directives to add support for delay_mode_unit and delay_mode_zero --- .../src/general/compiler_directives.rs | 94 ++++++++++--------- sv-parser-parser/src/keywords.rs | 4 +- sv-parser-pp/src/preprocess.rs | 36 +++---- .../IEEE18002017_AnnexE_delaydirectives.sv | 7 ++ .../src/general/compiler_directives.rs | 4 +- 5 files changed, 79 insertions(+), 66 deletions(-) diff --git a/sv-parser-parser/src/general/compiler_directives.rs b/sv-parser-parser/src/general/compiler_directives.rs index 48f5eee1..9d2a116c 100644 --- a/sv-parser-parser/src/general/compiler_directives.rs +++ b/sv-parser-parser/src/general/compiler_directives.rs @@ -59,18 +59,20 @@ pub(crate) fn compiler_directive(s: Span) -> IResult { map(text_macro_usage, |x| { CompilerDirective::TextMacroUsage(Box::new(x)) }), - map(delay_mode_distributed_compiler_directive, |x| { - CompilerDirective::DelayModeDistributedDirective(Box::new(x)) - }), - map(delay_mode_path_compiler_directive, |x| { - CompilerDirective::DelayModePathDirective(Box::new(x)) - }), - // map(delay_mode_unit_compiler_directive, |x| { - // CompilerDirective::DelayModeUnitDirective(Box::new(x)) - // }), - // map(delay_mode_zero_compiler_directive, |x| { - // CompilerDirective::DelayModeZeroDirective(Box::new(x)) - // }), + alt(( + map(delay_mode_distributed_compiler_directive, |x| { + CompilerDirective::DelayModeDistributedDirective(Box::new(x)) + }), + map(delay_mode_path_compiler_directive, |x| { + CompilerDirective::DelayModePathDirective(Box::new(x)) + }), + map(delay_mode_unit_compiler_directive, |x| { + CompilerDirective::DelayModeUnitDirective(Box::new(x)) + }), + map(delay_mode_zero_compiler_directive, |x| { + CompilerDirective::DelayModeZeroDirective(Box::new(x)) + }), + )) ))(s); end_directive(); ret @@ -130,18 +132,23 @@ pub(crate) fn compiler_directive_without_resetall(s: Span) -> IResult IResult { -// let (s, a) = symbol("`")(s)?; -// let (s, b) = keyword("delay_mode_unit")(s)?; -// Ok((s, DelayModeUnitDirective { nodes: (a, b) })) -// } - -// #[tracable_parser] -// #[packrat_parser] -// pub(crate) fn delay_mode_zero_compiler_directive( -// s: Span, -// ) -> IResult { -// let (s, a) = symbol("`")(s)?; -// let (s, b) = keyword("delay_mode_zero")(s)?; -// Ok((s, DelayModeZeroDirective { nodes: (a, b) })) -// } \ No newline at end of file +#[tracable_parser] +#[packrat_parser] +pub(crate) fn delay_mode_unit_compiler_directive( + s: Span, +) -> IResult { + let (s, a) = symbol("`")(s)?; + let (s, b) = keyword("delay_mode_unit")(s)?; + Ok((s, DelayModeUnitDirective { nodes: (a, b) })) +} + +#[tracable_parser] +#[packrat_parser] +pub(crate) fn delay_mode_zero_compiler_directive( + s: Span, +) -> IResult { + let (s, a) = symbol("`")(s)?; + let (s, b) = keyword("delay_mode_zero")(s)?; + Ok((s, DelayModeZeroDirective { nodes: (a, b) })) +} \ No newline at end of file diff --git a/sv-parser-parser/src/keywords.rs b/sv-parser-parser/src/keywords.rs index 2fdbb1a8..c6b44628 100644 --- a/sv-parser-parser/src/keywords.rs +++ b/sv-parser-parser/src/keywords.rs @@ -1468,6 +1468,6 @@ pub(crate) const KEYWORDS_DIRECTIVE: &[&str] = &[ "undefineall", "delay_mode_distributed", "delay_mode_path", - // "delay_mode_unit", - // "delay_mode_zero" + "delay_mode_unit", + "delay_mode_zero" ]; diff --git a/sv-parser-pp/src/preprocess.rs b/sv-parser-pp/src/preprocess.rs index 0f90bff3..06c7f8a1 100644 --- a/sv-parser-pp/src/preprocess.rs +++ b/sv-parser-pp/src/preprocess.rs @@ -424,24 +424,24 @@ pub fn preprocess_str, U: AsRef, V: BuildHasher>( NodeEvent::Leave(RefNode::DelayModePathDirective(_)) => { skip_whitespace = false; } - // NodeEvent::Enter(RefNode::DelayModeUnitDirective(x)) => { - // let locate: Locate = x.try_into().unwrap(); - // let range = Range::new(locate.offset, locate.offset + locate.len); - // ret.push(locate.str(&s), Some((path.as_ref(), range))); - // skip_whitespace = true; - // } - // NodeEvent::Leave(RefNode::DelayModeUnitDirective(_)) => { - // skip_whitespace = false; - // } - // NodeEvent::Enter(RefNode::DelayModeZeroDirective(x)) => { - // let locate: Locate = x.try_into().unwrap(); - // let range = Range::new(locate.offset, locate.offset + locate.len); - // ret.push(locate.str(&s), Some((path.as_ref(), range))); - // skip_whitespace = true; - // } - // NodeEvent::Leave(RefNode::DelayModeZeroDirective(_)) => { - // skip_whitespace = false; - // } + NodeEvent::Enter(RefNode::DelayModeUnitDirective(x)) => { + let locate: Locate = x.try_into().unwrap(); + let range = Range::new(locate.offset, locate.offset + locate.len); + ret.push(locate.str(&s), Some((path.as_ref(), range))); + skip_whitespace = true; + } + NodeEvent::Leave(RefNode::DelayModeUnitDirective(_)) => { + skip_whitespace = false; + } + NodeEvent::Enter(RefNode::DelayModeZeroDirective(x)) => { + let locate: Locate = x.try_into().unwrap(); + let range = Range::new(locate.offset, locate.offset + locate.len); + ret.push(locate.str(&s), Some((path.as_ref(), range))); + skip_whitespace = true; + } + NodeEvent::Leave(RefNode::DelayModeZeroDirective(_)) => { + skip_whitespace = false; + } NodeEvent::Enter(RefNode::Pragma(x)) => { let locate: Locate = x.try_into().unwrap(); let range = Range::new(locate.offset, locate.offset + locate.len); diff --git a/sv-parser-pp/testcases/IEEE18002017_AnnexE_delaydirectives.sv b/sv-parser-pp/testcases/IEEE18002017_AnnexE_delaydirectives.sv index a1535b2e..f4f95ade 100644 --- a/sv-parser-pp/testcases/IEEE18002017_AnnexE_delaydirectives.sv +++ b/sv-parser-pp/testcases/IEEE18002017_AnnexE_delaydirectives.sv @@ -6,6 +6,13 @@ Clause 22. The compiler directives described in this annex may not be available SystemVerilog. The following compiler directives are described in this annex: */ +//not supported: +// `default_decay_time 1.3 //[E.2] +// `defualt_decay_time 5 +// `default_decay_time infinite +// `default_trireg_strength 100 //[E.3] `delay_mode_distributed //[E.4] `delay_mode_path //[E.5] +`delay_mode_unit //[E.6] +`delay_mode_zero //[E.7] \ No newline at end of file diff --git a/sv-parser-syntaxtree/src/general/compiler_directives.rs b/sv-parser-syntaxtree/src/general/compiler_directives.rs index 834fff8a..73324b54 100644 --- a/sv-parser-syntaxtree/src/general/compiler_directives.rs +++ b/sv-parser-syntaxtree/src/general/compiler_directives.rs @@ -24,8 +24,8 @@ pub enum CompilerDirective { EndkeywordsDirective(Box), DelayModeDistributedDirective(Box), DelayModePathDirective(Box), - // DelayModeUnitDirective(Box), - // DelayModeZeroDirective(Box) + DelayModeUnitDirective(Box), + DelayModeZeroDirective(Box) } #[derive(Clone, Debug, PartialEq, Node)] From c3d9007b85286c82172220768e9d8cda11f2783e Mon Sep 17 00:00:00 2001 From: maor malka Date: Thu, 27 Feb 2025 09:11:16 -0500 Subject: [PATCH 3/3] commented out node enter/leave events for delay_mode_* --- sv-parser-pp/src/preprocess.rs | 72 +++++++++++++++++----------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/sv-parser-pp/src/preprocess.rs b/sv-parser-pp/src/preprocess.rs index 06c7f8a1..06e78509 100644 --- a/sv-parser-pp/src/preprocess.rs +++ b/sv-parser-pp/src/preprocess.rs @@ -406,42 +406,42 @@ pub fn preprocess_str, U: AsRef, V: BuildHasher>( NodeEvent::Leave(RefNode::EndcelldefineDriveCompilerDirective(_)) => { skip_whitespace = false; } - NodeEvent::Enter(RefNode::DelayModeDistributedDirective(x)) => { - let locate: Locate = x.try_into().unwrap(); - let range = Range::new(locate.offset, locate.offset + locate.len); - ret.push(locate.str(&s), Some((path.as_ref(), range))); - skip_whitespace = true; - } - NodeEvent::Leave(RefNode::DelayModeDistributedDirective(_)) => { - skip_whitespace = false; - } - NodeEvent::Enter(RefNode::DelayModePathDirective(x)) => { - let locate: Locate = x.try_into().unwrap(); - let range = Range::new(locate.offset, locate.offset + locate.len); - ret.push(locate.str(&s), Some((path.as_ref(), range))); - skip_whitespace = true; - } - NodeEvent::Leave(RefNode::DelayModePathDirective(_)) => { - skip_whitespace = false; - } - NodeEvent::Enter(RefNode::DelayModeUnitDirective(x)) => { - let locate: Locate = x.try_into().unwrap(); - let range = Range::new(locate.offset, locate.offset + locate.len); - ret.push(locate.str(&s), Some((path.as_ref(), range))); - skip_whitespace = true; - } - NodeEvent::Leave(RefNode::DelayModeUnitDirective(_)) => { - skip_whitespace = false; - } - NodeEvent::Enter(RefNode::DelayModeZeroDirective(x)) => { - let locate: Locate = x.try_into().unwrap(); - let range = Range::new(locate.offset, locate.offset + locate.len); - ret.push(locate.str(&s), Some((path.as_ref(), range))); - skip_whitespace = true; - } - NodeEvent::Leave(RefNode::DelayModeZeroDirective(_)) => { - skip_whitespace = false; - } + // NodeEvent::Enter(RefNode::DelayModeDistributedDirective(x)) => { + // let locate: Locate = x.try_into().unwrap(); + // let range = Range::new(locate.offset, locate.offset + locate.len); + // ret.push(locate.str(&s), Some((path.as_ref(), range))); + // skip_whitespace = true; + // } + // NodeEvent::Leave(RefNode::DelayModeDistributedDirective(_)) => { + // skip_whitespace = false; + // } + // NodeEvent::Enter(RefNode::DelayModePathDirective(x)) => { + // let locate: Locate = x.try_into().unwrap(); + // let range = Range::new(locate.offset, locate.offset + locate.len); + // ret.push(locate.str(&s), Some((path.as_ref(), range))); + // skip_whitespace = true; + // } + // NodeEvent::Leave(RefNode::DelayModePathDirective(_)) => { + // skip_whitespace = false; + // } + // NodeEvent::Enter(RefNode::DelayModeUnitDirective(x)) => { + // let locate: Locate = x.try_into().unwrap(); + // let range = Range::new(locate.offset, locate.offset + locate.len); + // ret.push(locate.str(&s), Some((path.as_ref(), range))); + // skip_whitespace = true; + // } + // NodeEvent::Leave(RefNode::DelayModeUnitDirective(_)) => { + // skip_whitespace = false; + // } + // NodeEvent::Enter(RefNode::DelayModeZeroDirective(x)) => { + // let locate: Locate = x.try_into().unwrap(); + // let range = Range::new(locate.offset, locate.offset + locate.len); + // ret.push(locate.str(&s), Some((path.as_ref(), range))); + // skip_whitespace = true; + // } + // NodeEvent::Leave(RefNode::DelayModeZeroDirective(_)) => { + // skip_whitespace = false; + // } NodeEvent::Enter(RefNode::Pragma(x)) => { let locate: Locate = x.try_into().unwrap(); let range = Range::new(locate.offset, locate.offset + locate.len);