Skip to content

WIP:preparser: adding 2 optional compiler directives delay_mode_path , delay_mode_distributed #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions sv-parser-parser/src/general/compiler_directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ pub(crate) fn compiler_directive(s: Span) -> IResult<Span, CompilerDirective> {
map(text_macro_usage, |x| {
CompilerDirective::TextMacroUsage(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
Expand Down Expand Up @@ -118,6 +132,23 @@ pub(crate) fn compiler_directive_without_resetall(s: Span) -> IResult<Span, Comp
map(text_macro_usage, |x| {
CompilerDirective::TextMacroUsage(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
Expand Down Expand Up @@ -873,3 +904,43 @@ pub(crate) fn endkeywords_directive(s: Span) -> IResult<Span, EndkeywordsDirecti
end_keywords();
Ok((s, EndkeywordsDirective { nodes: (a, b) }))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn delay_mode_distributed_compiler_directive(
s: Span,
) -> IResult<Span, DelayModeDistributedDirective> {
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<Span, DelayModePathDirective> {
let (s, a) = symbol("`")(s)?;
let (s, b) = keyword("delay_mode_path")(s)?;
Ok((s, DelayModePathDirective { nodes: (a, b) }))
}

#[tracable_parser]
#[packrat_parser]
pub(crate) fn delay_mode_unit_compiler_directive(
s: Span,
) -> IResult<Span, DelayModeUnitDirective> {
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<Span, DelayModeZeroDirective> {
let (s, a) = symbol("`")(s)?;
let (s, b) = keyword("delay_mode_zero")(s)?;
Ok((s, DelayModeZeroDirective { nodes: (a, b) }))
}
4 changes: 4 additions & 0 deletions sv-parser-parser/src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
];
44 changes: 44 additions & 0 deletions sv-parser-pp/src/preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,42 @@ pub fn preprocess_str<T: AsRef<Path>, U: AsRef<Path>, 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);
Expand Down Expand Up @@ -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)
}
}
}
18 changes: 18 additions & 0 deletions sv-parser-pp/testcases/IEEE18002017_AnnexE_delaydirectives.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
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:
*/

//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]
25 changes: 25 additions & 0 deletions sv-parser-syntaxtree/src/general/compiler_directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ pub enum CompilerDirective {
PositionCompilerDirective(Box<PositionCompilerDirective>),
KeywordsDirective(Box<KeywordsDirective>),
EndkeywordsDirective(Box<EndkeywordsDirective>),
DelayModeDistributedDirective(Box<DelayModeDistributedDirective>),
DelayModePathDirective(Box<DelayModePathDirective>),
DelayModeUnitDirective(Box<DelayModeUnitDirective>),
DelayModeZeroDirective(Box<DelayModeZeroDirective>)
}

#[derive(Clone, Debug, PartialEq, Node)]
Expand Down Expand Up @@ -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),
}