Splits resolve.rs, parser/item.rs, parser/instance.rs, format/stmt.rs and
lexer.rs (really 771 lines); moves 23 inline test modules of lucisv_server
to their own files; reasons on all 12 bare #[ignore]; the giant-line
references test times the real request; sites.py default root.
Output over 4,046 OpenTitan files byte-identical to a479faf.
Co-Authored-By: Claude Mythos 5.2 <[email protected]>
111 lines
4.6 KiB
Rust
111 lines
4.6 KiB
Rust
// Author: Guoliang Chen, a Senior Digital Design Engineer
|
|
|
|
//! Timing controls and sensitivity lists: the `#delay` or `@(…)` that
|
|
//! heads a statement, an `always` block, or a clocking event.
|
|
|
|
use crate::doc::*;
|
|
use vlog_parser::ast::*;
|
|
|
|
use super::comment::is_line_comment;
|
|
use super::Fmt;
|
|
|
|
impl<'a> Fmt<'a> {
|
|
pub(super) fn timing_control(&self, tc: &TimingControl) -> Doc {
|
|
match tc {
|
|
TimingControl::Delay { after_hash, expr } => {
|
|
let mut docs = vec![text("#")];
|
|
self.slot_comments(after_hash, &mut docs);
|
|
docs.push(self.expr(expr));
|
|
concat(docs)
|
|
}
|
|
TimingControl::Event(sens) => self.sens_list(sens),
|
|
}
|
|
}
|
|
|
|
pub(super) fn sens_list(&self, sens: &SensList) -> Doc {
|
|
match sens {
|
|
// Written without parens, printed without parens: `@ev`,
|
|
// `@a.b` — inventing a `( ... )` changes the token stream.
|
|
SensList::Bare { expr, after_at } => {
|
|
let mut docs = vec![text("@")];
|
|
self.slot_comments(after_at, &mut docs);
|
|
docs.push(self.expr(expr));
|
|
concat(docs)
|
|
}
|
|
SensList::Star { before, after } => {
|
|
if before.is_empty() && after.is_empty() {
|
|
return text("@(*)");
|
|
}
|
|
// Comments written inside the parens stay inside them, on the
|
|
// side of the `*` they were written on.
|
|
let mut inner = Vec::new();
|
|
if before.is_empty() {
|
|
// `(*` directly followed by anything but `)` lexes as an
|
|
// attribute instance, so keep the `*` off the paren.
|
|
inner.push(text(" "));
|
|
}
|
|
for c in before {
|
|
inner.push(self.comment(c));
|
|
inner.push(if is_line_comment(&c.text) { Doc::HardLine } else { text(" ") });
|
|
}
|
|
inner.push(text("*"));
|
|
for c in after {
|
|
inner.push(text(" "));
|
|
inner.push(self.comment(c));
|
|
if is_line_comment(&c.text) {
|
|
inner.push(Doc::HardLine);
|
|
}
|
|
}
|
|
concat(vec![text("@("), indent(inner), text(")")])
|
|
}
|
|
SensList::List { items, after_at } => {
|
|
// Each separator is printed as it was written: `,` and `or`
|
|
// mean the same thing but are different tokens, and rewriting
|
|
// one as the other is a token change the safety net rejects.
|
|
let mut parts: Vec<Doc> = Vec::new();
|
|
for i in items {
|
|
match i.sep {
|
|
Some(SensSep::Comma) => parts.push(text(", ")),
|
|
Some(SensSep::Or) => parts.push(text(" or ")),
|
|
None => {}
|
|
}
|
|
for c in &i.meta.leading {
|
|
parts.push(self.comment(c));
|
|
parts.push(if is_line_comment(&c.text) {
|
|
Doc::HardLine
|
|
} else {
|
|
text(" ")
|
|
});
|
|
}
|
|
if let Some(e) = &i.edge {
|
|
parts.push(text(e.clone()));
|
|
if i.after_edge.is_empty() {
|
|
parts.push(text(" "));
|
|
} else {
|
|
self.inline_comments_spaced(&i.after_edge, &mut parts);
|
|
}
|
|
}
|
|
parts.push(self.expr(&i.expr));
|
|
// `posedge clk iff enable` — the gate belongs to this
|
|
// term, so it prints before the separator, not after it.
|
|
if let Some(iff) = &i.iff {
|
|
parts.push(text(" iff "));
|
|
parts.push(self.expr(iff));
|
|
}
|
|
if self.inline_comments(&i.meta.before_sep, &mut parts) {
|
|
parts.push(Doc::HardLine);
|
|
}
|
|
}
|
|
let mut docs = vec![text("@")];
|
|
self.slot_comments(after_at, &mut docs);
|
|
docs.push(text("("));
|
|
docs.push(group(vec![indent(vec![Doc::SoftLine, concat(parts)]), Doc::SoftLine]));
|
|
docs.push(text(")"));
|
|
concat(docs)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com
|