Modport method prototypes, unnamed DPI formals, and the const ref comment gap
TODO section 30 (coverage_gaps M13, corrected). A modport port may be a method prototype - import task drive(int x), export function int get() - parsed by Parser::parse_tf_header, the one header parse parse_function_decl and parse_task_decl now destructure, printed by Fmt::tf_header, bound as Target::InScope (IEEE 1800-2017 25.5: a modport names a member of its own interface) with the formals declared in a scope of their own; one prototype per import/export group, the LRM's comma list still a clean error (recorded narrowing). A DPI import's formals may be unnamed (35.5.5) behind parse_tf_ports(allow_unnamed), the empty-name convention documented on TfArg::name, every other caller unchanged and a non-DPI unnamed formal still an error at its position. M13's const half was misfiled - const ref already parsed - but the probe found the unowned gap in const /*c*/ ref, now TfArg::after_const. Proof: 3 223 tests / 48 binaries, corpus 814/820, 4 807 corpus + opentitan files byte-identical to 0.33.0 (zero population), QA's adversarial probes and consumer audit of the possibly-empty names. docs/features/interface-dpi-arms/README.md. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
d1821ff859
commit
ee0faa2e18
22 files changed
+1208
-156
No files matched your search
@@ -113,6 +113,9 @@ impl<'a> Parser<'a> {
|
||||
/// One direction group of a modport's port list. `input a, b, output c` is
|
||||
/// two groups: the comma keeps the group open only while a plain name
|
||||
/// follows it — a direction keyword starts the next group.
|
||||
///
|
||||
/// An `import` or `export` may write a method prototype instead of a name
|
||||
/// (IEEE 1800 §25.5.4); that is a group of its own.
|
||||
fn parse_modport_port(&mut self) -> PResult<ModportPort> {
|
||||
const MODPORT_KEYWORDS: &[&str] =
|
||||
&["input", "output", "inout", "ref", "import", "export", "clocking"];
|
||||
@@ -123,6 +126,10 @@ impl<'a> Parser<'a> {
|
||||
return self.error("expected a modport port direction");
|
||||
}
|
||||
let kw = self.bump().text;
|
||||
let after_kw = self.take_gap();
|
||||
if let Some(kind) = self.at_modport_prototype(&kw) {
|
||||
return self.parse_modport_prototype(meta, kw, after_kw, kind, start);
|
||||
}
|
||||
let mut names = vec![self.expect_name()?];
|
||||
let mut span = self.span_from(start);
|
||||
let mut comma = false;
|
||||
@@ -142,7 +149,52 @@ impl<'a> Parser<'a> {
|
||||
if meta.trailing.is_none() {
|
||||
meta.trailing = self.take_trailing();
|
||||
}
|
||||
Ok(ModportPort { meta, kw, names, comma, span })
|
||||
Ok(ModportPort { meta, kw, after_kw, names, prototype: None, comma, span })
|
||||
}
|
||||
|
||||
/// Which method prototype an `import`/`export` group is about to write, if
|
||||
/// it is writing one at all (IEEE 1800 §25.5.4).
|
||||
fn at_modport_prototype(&self, kw: &str) -> Option<TfKind> {
|
||||
if kw != "import" && kw != "export" {
|
||||
return None;
|
||||
}
|
||||
if self.cur().is_kw("task") {
|
||||
Some(TfKind::Task)
|
||||
} else if self.cur().is_kw("function") {
|
||||
Some(TfKind::Function)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// `import task drive(int x)` — one modport list element holding a whole
|
||||
/// subroutine header and nothing else. It ends where the modport list
|
||||
/// says: at the `,` that starts the next group or the `)` that closes the
|
||||
/// list, never at a `;`, because a prototype here has no body to open.
|
||||
fn parse_modport_prototype(
|
||||
&mut self,
|
||||
mut meta: Meta,
|
||||
kw: String,
|
||||
after_kw: Vec<Comment>,
|
||||
kind: TfKind,
|
||||
start: u32,
|
||||
) -> PResult<ModportPort> {
|
||||
let prototype = self.parse_tf_header(kind, false)?;
|
||||
let span = self.span_from(start);
|
||||
self.take_before_sep(&mut meta, ",");
|
||||
let comma = self.eat_sym(",");
|
||||
if meta.trailing.is_none() {
|
||||
meta.trailing = self.take_trailing();
|
||||
}
|
||||
Ok(ModportPort {
|
||||
meta,
|
||||
kw,
|
||||
after_kw,
|
||||
names: Vec::new(),
|
||||
prototype: Some(Box::new(prototype)),
|
||||
comma,
|
||||
span,
|
||||
})
|
||||
}
|
||||
|
||||
/// `clocking cb @(posedge clk); ... endclocking` (IEEE 1800 §14.3). The
|
||||
|
||||
Reference in new issue
Block a user