Follow a HID to find the associated declaration.
(vl-follow-hidexpr x ss &key (origx 'origx) strictp (elabpath 'nil)) → (mv err trace context tail)
Prerequisite: see hid-tools for considerable discussion about the goals and design of this function.
This is our top-level routine for following hierarchical identifiers. It
understands how to resolve both top-level hierarchical identifiers like
We try to follow
We return a vl-hidtrace-p that records, in ``backwards'' order, the
steps that we took to resolve
The trace we return stops at variable declarations. This may be confusing
because, in Verilog, the same
typedef struct { logic fastMode; ...; } opcode_t; typedef struct { opcode_t opcode; ... } instruction_t; module bar (...) ; instruction_t instruction1; ... endmodule module foo (...) ; bar mybar(...) ; ... endmodule module main (...) ; foo myfoo(...) ; ... $display("fastMode is %b", myfoo.mybar.instruction1.opcode.fastMode); endmodule
When we follow
To account for this, we return not only the
Function:
(defun vl-follow-hidexpr-fn (x ss origx strictp elabpath) (declare (xargs :guard (and (vl-hidexpr-p x) (vl-scopestack-p ss) (vl-scopeexpr-p origx) (booleanp strictp) (vl-elabtraversal-p elabpath)))) (let ((__function__ 'vl-follow-hidexpr)) (declare (ignorable __function__)) (b* ((x (vl-hidexpr-fix x)) ((mv name1 indices rest kind) (vl-hidexpr-case x :end (mv x.name nil nil :end) :dot (b* (((vl-hidindex x.first))) (mv x.first.name x.first.indices x.rest :dot)))) (trace nil) ((when (eq name1 :vl-$root)) (mv (vl-follow-hidexpr-error "$root isn't supported yet" ss) trace nil x)) ((mv item ctx-ss pkg-name) (vl-scopestack-find-item/context name1 ss)) ((when item) (b* (((mv err trace tail) (vl-follow-hidexpr-aux x nil ss :strictp strictp :elabpath elabpath)) ((when err) (mv err trace nil tail)) ((mv err context) (cond (pkg-name (b* ((pkg (vl-scopestack-find-package pkg-name ss)) ((unless pkg) (mv (vmsg "Programming error: found item in ~ package ~s0 but couldn't find package" pkg-name) nil))) (mv nil (make-vl-scopecontext-package :pkg pkg)))) ((vl-scopestack-case ctx-ss :global) (mv nil (make-vl-scopecontext-root))) (t (mv nil (make-vl-scopecontext-local :levels (- (vl-scopestack-nesting-level ss) (vl-scopestack-nesting-level ctx-ss)))))))) (mv err trace context tail))) ((when (eq kind :end)) (mv (vl-follow-hidexpr-error "item not found" ss) trace nil x)) (design (vl-scopestack->design ss)) ((unless design) (mv (vl-follow-hidexpr-error "item not found" ss) trace nil x)) (toplevel (vl-design-toplevel design)) ((unless (member-equal name1 toplevel)) (mv (vl-follow-hidexpr-error "item not found" ss) trace nil x)) ((when (consp indices)) (mv (vl-follow-hidexpr-error "array indices into top level module" ss) trace nil x)) (topdef (or (vl-find-module name1 (vl-design->mods design)) (vl-find-interface name1 (vl-design->interfaces design)))) (topdef-ss (vl-scopestack-init design)) (next-ss (vl-scopestack-push topdef topdef-ss)) (elabpath (list (vl-elabinstruction-push-named (vl-elabkey-def name1)) (vl-elabinstruction-root))) ((mv err trace tail) (vl-follow-hidexpr-aux rest trace next-ss :strictp strictp :elabpath elabpath)) (context (if (eq (tag topdef) :vl-module) (make-vl-scopecontext-module :mod topdef) (make-vl-scopecontext-interface :iface topdef)))) (mv err trace context tail))))
Theorem:
(defthm return-type-of-vl-follow-hidexpr.err (b* (((mv ?err common-lisp::?trace ?context set::?tail) (vl-follow-hidexpr-fn x ss origx strictp elabpath))) (iff (vl-msg-p err) err)) :rule-classes :rewrite)
Theorem:
(defthm vl-hidtrace-p-of-vl-follow-hidexpr.trace (b* (((mv ?err common-lisp::?trace ?context set::?tail) (vl-follow-hidexpr-fn x ss origx strictp elabpath))) (vl-hidtrace-p trace)) :rule-classes :rewrite)
Theorem:
(defthm return-type-of-vl-follow-hidexpr.context (b* (((mv ?err common-lisp::?trace ?context set::?tail) (vl-follow-hidexpr-fn x ss origx strictp elabpath))) (implies (not err) (vl-scopecontext-p context))) :rule-classes :rewrite)
Theorem:
(defthm vl-hidexpr-p-of-vl-follow-hidexpr.tail (b* (((mv ?err common-lisp::?trace ?context set::?tail) (vl-follow-hidexpr-fn x ss origx strictp elabpath))) (vl-hidexpr-p tail)) :rule-classes :rewrite)
Theorem:
(defthm consp-of-vl-follow-hidexpr.trace (b* (((mv ?err common-lisp::?trace ?context set::?tail) (vl-follow-hidexpr-fn x ss origx strictp elabpath))) (implies (not err) (consp trace))))
Theorem:
(defthm count-of-vl-follow-hidexpr.tail (b* (((mv ?err common-lisp::?trace ?context set::?tail) (vl-follow-hidexpr-fn x ss origx strictp elabpath))) (<= (vl-hidexpr-count tail) (vl-hidexpr-count x))) :rule-classes :linear)
Theorem:
(defthm vl-subhid-p-of-vl-follow-hidexpr (b* (((mv ?err common-lisp::?trace ?context set::?tail) (vl-follow-hidexpr-fn x ss origx strictp elabpath))) (implies (not err) (vl-subhid-p tail x))))
Theorem:
(defthm vl-follow-hidexpr-fn-of-vl-hidexpr-fix-x (equal (vl-follow-hidexpr-fn (vl-hidexpr-fix x) ss origx strictp elabpath) (vl-follow-hidexpr-fn x ss origx strictp elabpath)))
Theorem:
(defthm vl-follow-hidexpr-fn-vl-hidexpr-equiv-congruence-on-x (implies (vl-hidexpr-equiv x x-equiv) (equal (vl-follow-hidexpr-fn x ss origx strictp elabpath) (vl-follow-hidexpr-fn x-equiv ss origx strictp elabpath))) :rule-classes :congruence)
Theorem:
(defthm vl-follow-hidexpr-fn-of-vl-scopestack-fix-ss (equal (vl-follow-hidexpr-fn x (vl-scopestack-fix ss) origx strictp elabpath) (vl-follow-hidexpr-fn x ss origx strictp elabpath)))
Theorem:
(defthm vl-follow-hidexpr-fn-vl-scopestack-equiv-congruence-on-ss (implies (vl-scopestack-equiv ss ss-equiv) (equal (vl-follow-hidexpr-fn x ss origx strictp elabpath) (vl-follow-hidexpr-fn x ss-equiv origx strictp elabpath))) :rule-classes :congruence)
Theorem:
(defthm vl-follow-hidexpr-fn-of-vl-scopeexpr-fix-origx (equal (vl-follow-hidexpr-fn x ss (vl-scopeexpr-fix origx) strictp elabpath) (vl-follow-hidexpr-fn x ss origx strictp elabpath)))
Theorem:
(defthm vl-follow-hidexpr-fn-vl-scopeexpr-equiv-congruence-on-origx (implies (vl-scopeexpr-equiv origx origx-equiv) (equal (vl-follow-hidexpr-fn x ss origx strictp elabpath) (vl-follow-hidexpr-fn x ss origx-equiv strictp elabpath))) :rule-classes :congruence)
Theorem:
(defthm vl-follow-hidexpr-fn-of-bool-fix-strictp (equal (vl-follow-hidexpr-fn x ss origx (acl2::bool-fix strictp) elabpath) (vl-follow-hidexpr-fn x ss origx strictp elabpath)))
Theorem:
(defthm vl-follow-hidexpr-fn-iff-congruence-on-strictp (implies (iff strictp strictp-equiv) (equal (vl-follow-hidexpr-fn x ss origx strictp elabpath) (vl-follow-hidexpr-fn x ss origx strictp-equiv elabpath))) :rule-classes :congruence)
Theorem:
(defthm vl-follow-hidexpr-fn-of-vl-elabtraversal-fix-elabpath (equal (vl-follow-hidexpr-fn x ss origx strictp (vl-elabtraversal-fix elabpath)) (vl-follow-hidexpr-fn x ss origx strictp elabpath)))
Theorem:
(defthm vl-follow-hidexpr-fn-vl-elabtraversal-equiv-congruence-on-elabpath (implies (vl-elabtraversal-equiv elabpath elabpath-equiv) (equal (vl-follow-hidexpr-fn x ss origx strictp elabpath) (vl-follow-hidexpr-fn x ss origx strictp elabpath-equiv))) :rule-classes :congruence)