A general utility for generating fresh names.
A name database allows you to easily and efficiently
generate good, fresh names that are not being used elsewhere.
Name databases are a general-purpose mechanism that has nothing to do with
Verilog. This was not always true; historically name databases were originally
part of a larger vl-namefactory structure that had a deep understanding of
Verilog modules, but that mechanism no longer exists.
Using Name Databases
Typically, the user begins by constructing a name database using
(vl-starting-namedb names), where names are just a list of the
names (strings) that are "in use."
Once constructed, name databases must be used in a single-threaded
discipline. That is, the functions for generating names actually return (mv
fresh-name db-prime), and to ensure that a sequence of generated names are
unique, one must always use the most recently returned database to generate
Two functions are provided for generating names:
(vl-namedb-indexed-name prefix db) produces a name that looks like
prefix_n, where n is the smallest positive natural number n such
that the name prefix_n is not in use.
(vl-namedb-plain-name name db) attempts to return name verbatim.
When this is not possible, a name of the form name_n, a note will be
printed to standard output and instead we will produce a name with
We use these functions for different purposes. We think that vl-namedb-indexed-name should be used for "throwaway" names that don't need
to be reliable or understandable, such as the names of temporary wires to be
generated for split-up expressions. Meanwhile, vl-namedb-plain-name
should be used for splitting up instance names or in any other cases where a
reliable name is desired.
Because name databases make use of fast alists, they should be destroyed
with (vl-free-namedb nf) when you are done using them.
To establish that name databases generate only fresh names, we introduce the
function (vl-namedb-allnames db). This function returns a list of all
names that the name database currently considers to be in use. We prove:
- Every name in names is among the allnames of the initial name
database produced by (vl-starting-namedb names).
- The fresh-names returned by vl-namedb-indexed-name or vl-namedb-plain-name are not members of the allnames of the input
- The allnames of the resulting db-prime include exactly the
allnames of the input db, along with the generated
Together, these theorems ensure that, when properly used, the name database
will only give you fresh names.
- Name database structure.
- Safely try to generate a particular name.
- Generate a list of fresh names.
- (vl-namedb-indexed-name prefix db) constructs a fresh name that looks
like prefix_n for some natural number n.
- (vl-unlike-any-prefix-p name prefixes) determines whether for all p in
prefixes, (vl-pgenstr-p p name) is false.
- (vl-namedb-p x) returns a list of all names that are
considered to be used by the name db.
- (vl-starting-namedb names) creates a name database that regards
names as already in use.
- (vl-pgenstr-highest prefix names) returns the largest n such that
"prefix_n" occurs in names.
- (vl-pgenstr-p prefix str) recognizes strings of the form
- (vl-pgenstr->val prefix str) retrieves n from the string str,
which must have the form "prefix_n"; we return n as a natural
- (vl-free-namedb db) frees the fast alists associated with a name
db and returns nil.
- Same as vl-namedb-plain-name, but doesn't print messages when
names aren't available.
- Fusion of vl-pgenstr-highest and alist-keys, for efficiency.
- (vl-pgenstr prefix n) creates the string "prefix_n".
- (vl-empty-namedb) creates an empty name db.
- An alist mapping stringp to true-p.
- An alist mapping stringp to natp.