Passing hierarchy to Verilog module

I have a “watcher” module that currently uses global hierarchies within it. I need to instantiate a second instance with a second global hierarchy.

Currently

module watcher; wire sig = `HIER.sig; wire bar = `HIER.foo.bar; ... endmodule watcher w; // instantiation 

Desired:

 module watcher(input base_hier); wire sig = base_hier.sig; wire bar = base_hier.foo.bar; ... endmodule watcher w1(`HIER1); // instantiation watcher w2(`HIER2); // second instantiation, except with a different hierarchy 

My best idea is to use vpp (Verilog preprocessor) to force the generation of two almost identical modules (one with each hierarchy), but is there a more elegant way?

+6
verilog
source share
2 answers

My preference is that your testbed has one module (or a small number of modules) that contains all your probes, but no other functions. All other modules of your test bench that require probes are then connected to this "probe module". Use SystemVerilog interfaces, preferring raw wires, if this is an option for you. This circumvents your problem, since no observer will require global hierarchies, and your test bench as a whole will be much easier to maintain. See the Law of Demeter .

Alternatively ... (but this puts the hierarchy in your instances ...)

 module watcher(sig, bar); input sig; input bar; ... endmodule watcher w1(`HIER1.sig, `HIER1.foo.bar); // instantiation watcher w2(`HIER2.sig, `HIER2.foo.bar); // second instantiation, except with a different hierarchy 

Subsequently, you can also:

 `define WATCHER_INST(NAME, HIER) watcher NAME(HIER.sig, HIER.foo.sig) `WATCHER_INST(w1, `HIER1); `WATCHER_INST(w2, `HIER2); 
+8
source share

Is it possible to use the SystemVerilog bind keyword to bind a module to each hierarchy that requires it? (This requires the use of SystemVerilog and a simulator license.)

Using bind is similar to instantiating a module in the usual way, except that you provide a path to the hierarchy into which the instance is created “remotely”:

 bind top.my.hier my_module instance_name(.*); bind top.my_other.hier my_module instance_name(.*); 

Even better: suppose that each hierarchy you attach to is a separate instance of the same module. Then:

 bind remote_module my_module instance_name(.*); 

This binds your module to each instance of the target, regardless of where it is located in the project. This is very powerful if your module is a validation check.

+2
source share

All Articles