Skip to content

Supports bit-array register delcaration - #41

Closed
hudongrui wants to merge 2 commits into
SanDisk-Open-Source:masterfrom
hudongrui:master
Closed

Supports bit-array register delcaration#41
hudongrui wants to merge 2 commits into
SanDisk-Open-Source:masterfrom
hudongrui:master

Conversation

@hudongrui

Copy link
Copy Markdown

Example:

$var reg 178 /Y mem_array[0] [177:0] $end

In above expression, mem_array[0] is saved as VAR, instead raising ParserError

jpgrayson added a commit that referenced this pull request Aug 10, 2026
Scope identifiers and variable references in real VCD files routinely
contain characters that IEEE 1800-2023 21.7 admits only within escaped
identifiers, e.g. verilator's mem_array[0] and genblock[3].mod, UVM's
uvm_phase::m_wait_for_pred, and cva6's scope_name(432). Extending the
simple identifier character set once per newly reported character does
not converge, so lex these names as everything up to whitespace instead,
and keep the identifier lexer for keywords, types, and units, where the
character set of a simple identifier does apply. For scopes this also
matches the grammar, which gives scope_identifier ::= { ASCII character }
rather than an identifier.

A variable reference is ambiguous once brackets are part of a name:
mem_array[0] is indistinguishable from a bit select of mem_array.
Whitespace cannot separate the two, as the reference in the standard's
own example is unspaced:

    $var reg 32 (k accumulator[31:0] $end

So only the final bracketed section of a reference is treated as a bit
index, and only when it holds decimal indices. This preserves the
existing interpretation of accumulator[31:0] and foo [17] while
admitting references such as varname[1423][SOMENAME][2]. Brackets within
an escaped identifier are always part of the name.

Resolves issues #22 and #35 and supersedes PRs #29, #40, and #41.
@jpgrayson

Copy link
Copy Markdown
Collaborator

Thanks for this PR. Sorry for the long delay.

Fixed in 92b8181.

Took the same view that mem_array[0] is part of the reference. Rather than balancing brackets during lexing, the reference is lexed whole and the trailing bracketed section is split off afterwards if it holds decimal indices. That way $var reg 178 /Y mem_array[0] [177:0] $end works, and so does the unspaced form, which the balanced-bracket approach would have stopped at the :.

Your example is now a test case.

Closing in favor of the version on master.

@jpgrayson jpgrayson closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants