Skip to content

Verilog: bind directive - #2124

Open
kroening wants to merge 2 commits into
diffblue:mainfrom
kroening:kroening/bind-directive
Open

Verilog: bind directive#2124
kroening wants to merge 2 commits into
diffblue:mainfrom
kroening:kroening/bind-directive

Conversation

@kroening

@kroening kroening commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

This adds support for the SystemVerilog bind directive, per 1800-2017 section 23.11. The directive specifies an instantiation of a module without modifying the source of the target module, which is used, e.g., to attach assertions or other instrumentation to a design in a non-intrusive manner.

Changes

  • Grammar: bind_directive (1800-2017 A.1.4) is now parsed, both at the top level and as a module item, producing a new verilog_bind_directive parse-tree node.
  • Bind directives are handled during elaboration: compilation-unit level directives are registered when the compilation unit is elaborated, and directives that are module items are registered when the enclosing design element instance is elaborated. Registered directives are applied when a matching design element instance is elaborated, by adding the instantiation to the instance's copy of the module source, as if it was written there.
  • Because registration happens during elaboration, a bind directive inside a generate construct only takes effect if its generate branch is taken.
  • Both target forms are supported: a module target (bind mod ...) applies to every instance of the module, and an instance target (bind top.sub ...) applies to that one instance only. A directive that targets the design element instance currently being elaborated is applied in place.
  • Errors are reported for directives that bind a module to itself, whose target does not exist, or whose target has already been elaborated (the target's item list is fixed at that point).
  • Modules that are instantiated only through a bind directive are found when scanning library directories (-y).
  • CHANGELOG entry.

Testing

  • New regression tests in regression/verilog/bind/: top-level bind (refuted bound assertion), bind as module item with a parameter assignment (proved), binds inside taken/untaken generate branches, an in-place bind targeting the enclosing module from a generate branch, an instance-target bind that verifies the sibling instance is unaffected, and error tests for unknown module targets, unknown instance targets, self-binds, and too-late binds.
  • Full regression/verilog, regression/ebmc, regression/vlindex suites and the unit tests pass.

Fixes #2102

@kroening kroening changed the title Verilog: bind directive Verilog: bind directive Sep 6, 2026
This adds support for the SystemVerilog bind directive, per 1800-2017
section 23.11. The directive specifies an instantiation of a module
without modifying the source of the target module, which is used, e.g.,
to attach assertions to a design in a non-intrusive manner.

The bind directives are collected from the parse trees and stored in the
symbol table; they are applied when a design element instance is
elaborated, by adding the instantiation given in the directive to the
instance's copy of the module source, as if it was written there.

Both target forms are supported: a module target applies to every
instance of the target module, while an instance target applies to one
particular instance without affecting other instances of the same
module. Directives that bind a module to itself are rejected, and
modules instantiated only through bind directives are found when
scanning library directories.

Fixes: diffblue#2102
@kroening
kroening force-pushed the kroening/bind-directive branch from c24d40c to 5514f7b Compare September 6, 2026 01:04
Bind directives are now handled during module elaboration, instead of
being collected from the parse trees up front. Directives at the
compilation-unit level are registered when the compilation unit is
elaborated; directives that are module items are registered when the
enclosing design element instance is elaborated, which means that a
directive inside a generate construct only takes effect if its generate
branch is taken. Previously, such directives failed an invariant.

A directive that targets the design element instance currently being
elaborated is applied in place. Directives whose target has already
been elaborated are rejected with an error, since the target's item
list is fixed at that point.
Comment on lines +31 to +34
id2string(binary.op1().get(ID_base_name));
}
else
return id2string(target.get(ID_base_name));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In both of these uses of .get(ID_base_name): how do we know that this irept entry exists (for what seemingly could be an arbitrary irept?

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.

Assertion binding not supported

2 participants