Bind semantics, the spaced macro call and the directive inside a connection, and lucisv.instantiate
TODO section 26; closes docs/topo.md 2.9-15 and 2.9-19; coverage_gaps
M4/M5/M6 corrected against a fresh opentitan census.
A bind directive's target is a path of segments with optional indices
(bind top.gen[0].u_core chk u_chk (...)); a lone target binds as a
module reference, an instance path records nothing rather than a guess.
Each connection's port half resolves against the module being bound in
and its expression half in the target module's scope first, the
workspace's member path when the target lives elsewhere, the writing
scope last (Target::BindScope, resolve::in_bind_target - the
inline-constraint shape). FACTS_FORMAT 14 -> 15: binds now post
references and an instantiation edge.
Expression-position spaced macro calls (assign x = `WIDTH (a + b);)
keep the author's gap, read from the source as glued_null_item reads
its gap; verify.rs untouched, both pins stand. A conditional directive
inside a connection value becomes ExprKind::Verbatim, byte-exact
through raw_inline as Doc::Inline, with the closing paren's line and
the list's break read from the source - so the instantiation keeps its
edge, lens and port references instead of collapsing to opaque bytes
(opentitan: the two padring sites in chip_earlgrey_{asic,cw340}.sv,
+2 edges, everything else byte-identical to 0.31.0).
lucisv.instantiate [uri, position, module] renders the inline ghost's
plan as plain text through workspace/applyEdit for clients without
inline completion; the Neovim README documents it.
QA: 3186 tests / 47 binaries, corpus 814/820, independent binary diff
over corpus and 2 645 opentitan files: only the two named files differ.
docs/features/bind-semantics/README.md.
Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
a0c290ccc2
commit
81df63d942
27 files changed
+2038
-134
No files matched your search
@@ -1033,18 +1033,36 @@ pub struct Connection {
|
||||
pub span: TextRange,
|
||||
}
|
||||
|
||||
/// One segment of a hierarchical path: the `gen[0]` of `top.gen[0].u_core`.
|
||||
///
|
||||
/// Only a `bind` directive's target is written this way today. Every other
|
||||
/// dotted name in the AST is either an expression
|
||||
/// ([`ExprKind::Member`]) or a joined string, and neither wanted a third
|
||||
/// spelling — this one exists because a bind target is a *scope*, not a
|
||||
/// value, and because its `[…]` is not part of any name.
|
||||
#[derive(Debug)]
|
||||
pub struct PathSegment {
|
||||
/// The segment's identifier, exactly as written.
|
||||
pub name: String,
|
||||
/// Byte range of `name`.
|
||||
pub span: TextRange,
|
||||
/// The `[…]` selector written after it, if any: `gen[0]`'s `0`.
|
||||
pub index: Option<Expr>,
|
||||
}
|
||||
|
||||
/// A `bind` directive: everything after the target scope is an ordinary
|
||||
/// module instantiation, so it is parsed and printed as one.
|
||||
#[derive(Debug)]
|
||||
pub struct BindDirective {
|
||||
/// The bind target: a module or interface name (`prim_secded_22_16_tb`),
|
||||
/// an instance name (`i_nopass1`) or a hierarchical path
|
||||
/// (`top.u_dut.u_core`), stored with its `.` separators glued.
|
||||
pub target: String,
|
||||
/// Byte range of `target`. A hierarchical target is stored with its `.`
|
||||
/// glued, so there the slice matches `target` only modulo the whitespace
|
||||
/// the source may have written around the dots — the same caveat
|
||||
/// [`Instantiation::module_span`] carries for `::`.
|
||||
/// (`top.u_dut.u_core`, `top.gen[0].u_core`), one [`PathSegment`] per
|
||||
/// name. A path is *not* joined into one string: an escaped segment needs
|
||||
/// the whitespace that terminates it (`docs/topo.md` §2.9-21), and an
|
||||
/// indexed segment is not a name at all.
|
||||
pub target: Vec<PathSegment>,
|
||||
/// Byte range of the whole target path, `.` separators and `[…]`
|
||||
/// selectors included.
|
||||
pub target_span: TextRange,
|
||||
/// Comments written between `bind` and the target name. They have no node
|
||||
/// of their own to hang on — the target is a bare string — so they are
|
||||
@@ -1060,6 +1078,33 @@ pub struct BindDirective {
|
||||
pub inst: Instantiation,
|
||||
}
|
||||
|
||||
impl BindDirective {
|
||||
/// The target path as one dotted string, for consumers that want a
|
||||
/// spelling rather than the segments — the workspace's paths, a
|
||||
/// diagnostic, a test. An escaped segment keeps the space that terminates
|
||||
/// it, so the spelling re-lexes as the same names.
|
||||
pub fn target_path(&self) -> String {
|
||||
let mut out = String::new();
|
||||
for seg in &self.target {
|
||||
if !out.is_empty() {
|
||||
if out.rsplit(char::is_whitespace).next().is_some_and(|s| s.contains('\\')) {
|
||||
out.push(' ');
|
||||
}
|
||||
out.push('.');
|
||||
}
|
||||
out.push_str(&seg.name);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The head of the target path — the module, interface or instance name a
|
||||
/// `bind` starts at. `None` only for a path with no segments, which the
|
||||
/// parser never builds.
|
||||
pub fn head(&self) -> Option<&PathSegment> {
|
||||
self.target.first()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GateInstantiation {
|
||||
/// `and`, `or`, `not`, ...
|
||||
@@ -2024,6 +2069,17 @@ pub enum ExprKind {
|
||||
/// an [`ExprKind::Range`] has, read by the same shared parse.
|
||||
comments: Box<SegmentComments>,
|
||||
},
|
||||
/// A balanced region of a connection's value that holds a
|
||||
/// **conditional-compilation directive**, kept byte for byte:
|
||||
/// `` .dio_pad_io({ IOR9, `ifdef ANALOGSIM '0, `else CC2, `endif POR_N }) ``.
|
||||
///
|
||||
/// lucisv never evaluates a `` `ifdef `` condition, so such a region has
|
||||
/// no single value to model. Capturing just the value keeps everything
|
||||
/// around it structural — the instantiation's edge, its code lens, its
|
||||
/// hierarchy site and its other connections' references — where before
|
||||
/// the whole *item* became [`ItemKind::Verbatim`]. The region itself
|
||||
/// records nothing and is re-emitted exactly as written.
|
||||
Verbatim(RawText),
|
||||
/// A type used in expression position (`parameter type T = logic [7:0]`).
|
||||
Type(DataType),
|
||||
/// `(min : typ : max)` delay expression.
|
||||
|
||||
@@ -1557,6 +1557,18 @@ impl<'a> Parser<'a> {
|
||||
/// to catch before this round (`docs/topo.md` §2.9-21). Whitespace is an
|
||||
/// escaped identifier's only terminator, so it is part of the name as
|
||||
/// written and belongs in the joined text.
|
||||
/// [`Parser::push_scope_segment`]'s `.` twin, for the hierarchical paths
|
||||
/// a `bind`'s `: instance, list` glues into one name. Same rule, same
|
||||
/// reason: whitespace is an escaped identifier's only terminator, so
|
||||
/// `\my-inst .u_core` must not come back as `\my-inst.u_core`.
|
||||
fn push_path_segment(joined: &mut String, segment: &str) {
|
||||
if joined.rsplit(char::is_whitespace).next().is_some_and(|s| s.contains('\\')) {
|
||||
joined.push(' ');
|
||||
}
|
||||
joined.push('.');
|
||||
joined.push_str(segment);
|
||||
}
|
||||
|
||||
fn push_scope_segment(joined: &mut String, segment: &str) {
|
||||
if joined.rsplit(char::is_whitespace).next().is_some_and(|s| s.contains('\\')) {
|
||||
joined.push(' ');
|
||||
@@ -5340,9 +5352,12 @@ impl<'a> Parser<'a> {
|
||||
/// parsing as the ordinary method call it is in existing testbenches.
|
||||
/// A directive is recognized from its shape instead: the word `bind`,
|
||||
/// then a target scope (a name, possibly a `.`-separated hierarchical
|
||||
/// path), then either the `:` of an instance list or the module name of
|
||||
/// the instantiation. A declaration of a variable called `bind` reaches
|
||||
/// `;`, `,`, `=` or a dimension there, so it never matches.
|
||||
/// path, each segment possibly carrying one `[…]` selector), then either
|
||||
/// the `:` of an instance list or the module name of the instantiation.
|
||||
/// A declaration of a variable called `bind` reaches `;`, `,`, `=` or a
|
||||
/// dimension there, so it never matches — a `bind [3:0] x;` declaration
|
||||
/// is a *dimension on the first name*, which is why the scan only steps
|
||||
/// over a `[…]` that has a `.` or the instantiation after it.
|
||||
fn at_bind_directive(&self) -> bool {
|
||||
let t = self.cur();
|
||||
if t.kind != TokenKind::Ident || t.text != "bind" {
|
||||
@@ -5353,10 +5368,25 @@ impl<'a> Parser<'a> {
|
||||
return false;
|
||||
}
|
||||
p += 1;
|
||||
while self.tokens.get(p).is_some_and(|t| t.is_sym("."))
|
||||
&& self.tokens.get(p + 1).is_some_and(|t| t.kind == TokenKind::Ident)
|
||||
{
|
||||
p += 2;
|
||||
loop {
|
||||
// `top.gen[0].u_core` (IEEE 1800 §23.11's bind_target_instance):
|
||||
// binding SVA into a generate array is the shape formal setups
|
||||
// write. One selector per segment; anything more is not a bind
|
||||
// this parser reads, and stays the clean error it always was.
|
||||
if self.tokens.get(p).is_some_and(|t| t.is_sym("[")) {
|
||||
let after = self.scan_matching(p, "[", "]");
|
||||
if after == p {
|
||||
return false;
|
||||
}
|
||||
p = after;
|
||||
}
|
||||
if self.tokens.get(p).is_some_and(|t| t.is_sym("."))
|
||||
&& self.tokens.get(p + 1).is_some_and(|t| t.kind == TokenKind::Ident)
|
||||
{
|
||||
p += 2;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
self.tokens.get(p).is_some_and(|t| t.is_sym(":") || t.kind == TokenKind::Ident)
|
||||
}
|
||||
@@ -5369,11 +5399,10 @@ impl<'a> Parser<'a> {
|
||||
// known, rather than letting it drift onto the instance below.
|
||||
let target_comments = self.take_dangling();
|
||||
let start = self.here();
|
||||
let mut target = self.expect_ident()?;
|
||||
let mut target = vec![self.parse_path_segment()?];
|
||||
while self.cur().is_sym(".") {
|
||||
self.bump();
|
||||
target.push('.');
|
||||
target.push_str(&self.expect_ident()?);
|
||||
target.push(self.parse_path_segment()?);
|
||||
}
|
||||
let target_span = self.span_from(start);
|
||||
let mut instances = Vec::new();
|
||||
@@ -5401,12 +5430,24 @@ impl<'a> Parser<'a> {
|
||||
let mut text = self.expect_ident()?;
|
||||
while self.cur().is_sym(".") {
|
||||
self.bump();
|
||||
text.push('.');
|
||||
text.push_str(&self.expect_ident()?);
|
||||
let segment = self.expect_ident()?;
|
||||
Self::push_path_segment(&mut text, &segment);
|
||||
}
|
||||
Ok(Name { text, span: self.span_from(start) })
|
||||
}
|
||||
|
||||
/// One segment of a `bind` target path: a name and the one `[…]`
|
||||
/// selector it may carry.
|
||||
fn parse_path_segment(&mut self) -> PResult<PathSegment> {
|
||||
let Name { text: name, span } = self.expect_name()?;
|
||||
let mut index = None;
|
||||
if self.eat_sym("[") {
|
||||
index = Some(self.parse_expr()?);
|
||||
self.expect_sym("]")?;
|
||||
}
|
||||
Ok(PathSegment { name, span, index })
|
||||
}
|
||||
|
||||
fn parse_instantiation(&mut self) -> PResult<Instantiation> {
|
||||
let module_start = self.here();
|
||||
let mut module = self.expect_ident()?;
|
||||
@@ -5648,7 +5689,10 @@ impl<'a> Parser<'a> {
|
||||
} else {
|
||||
after_open = self.take_gap();
|
||||
let value_mark = self.pending_trailing.len();
|
||||
let e = self.parse_expr_or_type()?;
|
||||
let e = match self.conditional_region_end(")") {
|
||||
Some(end_pos) => self.parse_verbatim_expr(end_pos),
|
||||
None => self.parse_expr_or_type()?,
|
||||
};
|
||||
// `.name(x /* c */)`: written inside the parens, so it is
|
||||
// printed inside them too.
|
||||
close_comments = self.take_around(value_mark);
|
||||
@@ -5691,6 +5735,61 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The token index of the `close` matching the bracket just consumed —
|
||||
/// but **only** when a conditional-compilation directive stands somewhere
|
||||
/// inside it. `None` for every ordinary expression, which is nearly all
|
||||
/// of them, and for a region that never closes.
|
||||
///
|
||||
/// This is what parts `` .dio_pad_io({ IOR9, `ifdef ANALOGSIM '0, `else
|
||||
/// CC2, `endif POR_N }) `` (opentitan
|
||||
/// `hw/top_earlgrey/rtl/autogen/chip_earlgrey_asic.sv:604`) from an
|
||||
/// expression: lucisv never evaluates a `` `ifdef `` condition, so the
|
||||
/// region has no one value to model. Before this round the whole *item*
|
||||
/// became opaque bytes through [`Parser::split_conditional_item`], which
|
||||
/// cost the instantiation its edge, its lens and its port references;
|
||||
/// now only the one connection's value does.
|
||||
///
|
||||
/// Only the given bracket pair is counted, exactly as
|
||||
/// [`Parser::scan_matching`] counts: a directive's own text is one
|
||||
/// `TokenKind::Directive` token and can hold no stray bracket, and a
|
||||
/// string literal is a token too.
|
||||
fn conditional_region_end(&self, close: &str) -> Option<usize> {
|
||||
let mut depth = 1usize;
|
||||
let mut conditional = false;
|
||||
for (i, t) in self.tokens.iter().enumerate().skip(self.pos) {
|
||||
if t.kind == TokenKind::Eof {
|
||||
return None;
|
||||
}
|
||||
if t.is_sym("(") {
|
||||
depth += 1;
|
||||
} else if t.is_sym(close) {
|
||||
depth -= 1;
|
||||
if depth == 0 {
|
||||
return conditional.then_some(i);
|
||||
}
|
||||
} else if opens_conditional(t) || continues_conditional(t) || closes_conditional(t) {
|
||||
conditional = true;
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Consume the tokens up to `end_pos` as one verbatim expression.
|
||||
///
|
||||
/// [`Parser::open_conds`] is deliberately left alone: it counts *item*
|
||||
/// scope only, and a construct that walks its body through
|
||||
/// [`Parser::bump`] inherits "does not count" by doing nothing — see
|
||||
/// [`Parser::note_item_conditional`].
|
||||
fn parse_verbatim_expr(&mut self, end_pos: usize) -> Expr {
|
||||
let start = self.here();
|
||||
let col = self.cur().col;
|
||||
while self.pos < end_pos && !self.at_eof() {
|
||||
self.bump();
|
||||
}
|
||||
let raw = self.verbatim_since(start, col);
|
||||
self.expr_at(start, ExprKind::Verbatim(raw))
|
||||
}
|
||||
|
||||
/// In parameter connections a value may be a type (`.T(logic [7:0])`).
|
||||
fn parse_expr_or_type(&mut self) -> PResult<Expr> {
|
||||
let t = self.cur();
|
||||
@@ -8033,7 +8132,7 @@ mod tests {
|
||||
parse_ok("module m;\n bind top.u_dut : u_a, u_b chk #(.W(8)) u (.a(x));\nendmodule\n");
|
||||
let m = module_of(&file);
|
||||
let ItemKind::Bind(b) = &m.items[0].kind else { panic!("expected a bind directive") };
|
||||
assert_eq!(b.target, "top.u_dut");
|
||||
assert_eq!(b.target_path(), "top.u_dut");
|
||||
assert_eq!(b.instances.iter().map(|n| n.text.as_str()).collect::<Vec<_>>(), ["u_a", "u_b"]);
|
||||
assert_eq!(b.inst.module, "chk");
|
||||
assert_eq!(b.inst.params.as_ref().map(Vec::len), Some(1));
|
||||
@@ -8052,6 +8151,58 @@ mod tests {
|
||||
assert_eq!(texts(&b.module_comments), ["/*c2*/"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_indexed_bind_target_parses_as_path_segments() {
|
||||
// `docs/coverage_gaps.md` M6: binding SVA into a generate array is
|
||||
// the shape formal setups write, and until TODO §26 the path scan
|
||||
// stopped at the `[` and the file failed with `expected ';'`.
|
||||
let file = parse_ok("module m;\n bind top.gen[0].u_core chk c (.clk(clk));\nendmodule\n");
|
||||
let ItemKind::Bind(b) = &module_of(&file).items[0].kind else {
|
||||
panic!("expected a bind directive")
|
||||
};
|
||||
let names: Vec<&str> = b.target.iter().map(|s| s.name.as_str()).collect();
|
||||
assert_eq!(names, ["top", "gen", "u_core"]);
|
||||
assert!(b.target[0].index.is_none());
|
||||
assert!(matches!(
|
||||
b.target[1].index.as_ref().map(|e| &e.kind),
|
||||
Some(ExprKind::Number(n)) if n == "0"
|
||||
));
|
||||
assert!(b.target[2].index.is_none());
|
||||
assert_eq!(b.target_path(), "top.gen.u_core");
|
||||
assert_eq!(b.inst.module, "chk");
|
||||
// A non-constant selector is an ordinary expression, and a bare
|
||||
// indexed head needs no path at all.
|
||||
let file = parse_ok("module m;\n bind arr[N-1] chk c (.*);\nendmodule\n");
|
||||
let ItemKind::Bind(b) = &module_of(&file).items[0].kind else {
|
||||
panic!("expected a bind directive")
|
||||
};
|
||||
assert_eq!(b.target.len(), 1);
|
||||
assert!(matches!(
|
||||
b.target[0].index.as_ref().map(|e| &e.kind),
|
||||
Some(ExprKind::Binary { .. })
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_escaped_bind_path_segment_keeps_its_terminator() {
|
||||
// §2.9-21's rule for `::` chains, applied to the `.` ones: whitespace
|
||||
// is an escaped identifier's only terminator, so the segments are
|
||||
// kept apart rather than glued.
|
||||
let file = parse_ok("module m;\n bind \\my-inst .u_core chk c (.*);\nendmodule\n");
|
||||
let ItemKind::Bind(b) = &module_of(&file).items[0].kind else {
|
||||
panic!("expected a bind directive")
|
||||
};
|
||||
assert_eq!(b.target[0].name, "\\my-inst");
|
||||
assert_eq!(b.target_path(), "\\my-inst .u_core");
|
||||
// The `: instance, list` glues its paths into one name, so it carries
|
||||
// the same rule through `push_path_segment`.
|
||||
let file = parse_ok("module m;\n bind d : \\my-inst .u_core chk c (.*);\nendmodule\n");
|
||||
let ItemKind::Bind(b) = &module_of(&file).items[0].kind else {
|
||||
panic!("expected a bind directive")
|
||||
};
|
||||
assert_eq!(b.instances[0].text, "\\my-inst .u_core");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bind_is_still_a_usable_identifier() {
|
||||
// `bind` is not in the lexer's keyword table, so a method called
|
||||
@@ -8061,6 +8212,9 @@ mod tests {
|
||||
"module m;\n initial begin\n obj.bind();\n x = obj.bind;\n end\nendmodule\n",
|
||||
);
|
||||
parse_ok("module m;\n bind x;\n bind y = 1;\nendmodule\n");
|
||||
// And the shapes the `[…]` scan could have swallowed: a packed
|
||||
// dimension on the type, and an unpacked one on the declarator.
|
||||
parse_ok("module m;\n bind [3:0] x;\n bind y [7:0];\nendmodule\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -8993,19 +9147,30 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn a_directive_inside_a_connection_is_captured_or_refused_by_kind() {
|
||||
// Superseded in part by `directive-in-statements` (2026-08-29). A
|
||||
// *conditional* region inside a connection's parens is the bucket-7
|
||||
// shape — `chip_earlgrey_asic.sv` writes one inside a parameter
|
||||
// value's concatenation — so it is now captured verbatim rather than
|
||||
// refused. `directives-in-lists` still does not read it as a list
|
||||
// element: the whole instantiation becomes opaque bytes.
|
||||
// Superseded twice. `directive-in-statements` (2026-08-29) made a
|
||||
// *conditional* region inside a connection's parens a verbatim
|
||||
// capture rather than a refusal — of the whole item. TODO §26
|
||||
// narrowed the capture to the one connection's **value**, so the
|
||||
// instantiation is a real node again: its module, its instance and
|
||||
// its other connections are all structural, and only the region
|
||||
// itself is opaque bytes.
|
||||
let src =
|
||||
"module m;\n sub u (\n .a(\n`ifdef X\n y\n`endif\n )\n );\nendmodule\n";
|
||||
let f = parse_ok(src);
|
||||
let ItemKind::Module(m) = &f.items[0].kind else { panic!("expected a module") };
|
||||
let ItemKind::Verbatim(raw) = &m.items[0].kind else { panic!("expected a verbatim block") };
|
||||
assert!(raw.text.starts_with("sub u ("), "{:?}", raw.text);
|
||||
assert!(raw.text.ends_with(");"), "{:?}", raw.text);
|
||||
let ItemKind::Instantiation(inst) = &m.items[0].kind else {
|
||||
panic!("expected an instantiation")
|
||||
};
|
||||
assert_eq!(inst.module, "sub");
|
||||
let Connections::Named(conns) = &inst.instances[0].conns else {
|
||||
panic!("expected named connections")
|
||||
};
|
||||
assert_eq!(conns[0].name, "a");
|
||||
let Some(Expr { kind: ExprKind::Verbatim(raw), .. }) = &conns[0].expr else {
|
||||
panic!("expected a verbatim value")
|
||||
};
|
||||
assert!(raw.text.starts_with("`ifdef X"), "{:?}", raw.text);
|
||||
assert!(raw.text.ends_with("`endif"), "{:?}", raw.text);
|
||||
|
||||
// Any *other* directive there is still an ordinary parse error: the
|
||||
// recovery triggers on `ifdef / `ifndef only.
|
||||
@@ -11597,18 +11762,33 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_ifdef_inside_an_instantiations_parameter_value_captures_the_instantiation() {
|
||||
fn an_ifdef_inside_an_instantiations_parameter_value_captures_only_that_value() {
|
||||
// hw/top_earlgrey/rtl/autogen/chip_earlgrey_asic.sv:621 -- a region
|
||||
// between the elements of a concatenation, three brackets deep inside
|
||||
// a parameter override. The `;` after the whole instantiation ends it.
|
||||
// a parameter override. Until TODO §26 the whole instantiation became
|
||||
// opaque bytes, which cost it its edge, its lens and its port
|
||||
// references; now the override's value alone is the verbatim leaf.
|
||||
let src = "module m;\n padring #(\n .PadType({\n A,\n`ifdef ANALOGSIM\n \
|
||||
'0,\n`else\n CC2,\n`endif\n B\n })\n ) u_padring (\n \
|
||||
.clk(c)\n );\n wire z;\nendmodule\n";
|
||||
let f = parse_ok(src);
|
||||
let ItemKind::Module(m) = &f.items[0].kind else { panic!("expected a module") };
|
||||
let ItemKind::Verbatim(raw) = &m.items[0].kind else { panic!("expected a verbatim block") };
|
||||
assert!(raw.text.starts_with("padring #("), "{:?}", raw.text);
|
||||
assert!(raw.text.ends_with(");"), "{:?}", raw.text);
|
||||
let ItemKind::Instantiation(inst) = &m.items[0].kind else {
|
||||
panic!("expected an instantiation")
|
||||
};
|
||||
assert_eq!(inst.module, "padring");
|
||||
assert_eq!(inst.instances[0].name, "u_padring");
|
||||
let params = inst.params.as_ref().expect("a parameter override list");
|
||||
let Some(Expr { kind: ExprKind::Verbatim(raw), .. }) = ¶ms[0].expr else {
|
||||
panic!("expected a verbatim override value")
|
||||
};
|
||||
assert!(raw.text.starts_with("{"), "{:?}", raw.text);
|
||||
assert!(raw.text.ends_with("}"), "{:?}", raw.text);
|
||||
// The connection list around it is structural again.
|
||||
let Connections::Named(conns) = &inst.instances[0].conns else {
|
||||
panic!("expected named connections")
|
||||
};
|
||||
assert_eq!(conns[0].name, "clk");
|
||||
assert!(matches!(m.items[1].kind, ItemKind::DataDecl(_)), "the next item survived");
|
||||
}
|
||||
|
||||
@@ -12064,7 +12244,7 @@ mod tests {
|
||||
let f =
|
||||
parse_ok("bind prim_packer_fifo : dut.u_core.u_fifo fifo_if #(.P(1)) u (.clk_i);\n");
|
||||
let ItemKind::Bind(b) = &f.items[0].kind else { panic!("expected a bind") };
|
||||
assert_eq!(b.target, "prim_packer_fifo");
|
||||
assert_eq!(b.target_path(), "prim_packer_fifo");
|
||||
assert_eq!(
|
||||
b.instances.iter().map(|i| i.text.as_str()).collect::<Vec<_>>(),
|
||||
["dut.u_core.u_fifo"]
|
||||
|
||||
@@ -550,15 +550,20 @@ fn check_item(src: &str, item: &Item, parent: TextRange) {
|
||||
}
|
||||
ItemKind::Instantiation(inst) => check_instantiation(src, inst, here),
|
||||
ItemKind::Bind(b) => {
|
||||
// Like an instantiation's `module_span`: a hierarchical target
|
||||
// is stored with its `.` glued, so the slice matches it modulo
|
||||
// whitespace the source may have written around the dots.
|
||||
// The path's own span covers the `.` separators and any `[…]`
|
||||
// selectors, so only each segment's span slices back to a name.
|
||||
assert_inside(src, "bind target", b.target_span, here);
|
||||
assert_eq!(
|
||||
despace(slice(src, b.target_span)),
|
||||
despace(&b.target),
|
||||
"the bind target span does not slice back to its name"
|
||||
);
|
||||
for seg in &b.target {
|
||||
assert_inside(src, "bind target segment", seg.span, b.target_span);
|
||||
assert_eq!(
|
||||
slice(src, seg.span),
|
||||
seg.name,
|
||||
"a bind target segment's span does not slice back to its name"
|
||||
);
|
||||
if let Some(index) = &seg.index {
|
||||
check_expr(src, index, b.target_span);
|
||||
}
|
||||
}
|
||||
// An instance may itself be a hierarchical path, glued the same
|
||||
// way, so it gets the same modulo-whitespace comparison.
|
||||
for i in &b.instances {
|
||||
@@ -1045,6 +1050,12 @@ fn check_expr(src: &str, e: &Expr, parent: TextRange) {
|
||||
}
|
||||
}
|
||||
ExprKind::Ident(_) | ExprKind::Number(_) | ExprKind::Str(_) | ExprKind::Empty(_) => {}
|
||||
// A verbatim region's text is its own bytes, exactly as an item-level
|
||||
// verbatim leaf's is.
|
||||
ExprKind::Verbatim(raw) => {
|
||||
assert_inside(src, "verbatim expression", raw.span, here);
|
||||
assert_eq!(slice(src, raw.span), raw.text, "a verbatim expression does not slice back");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user