Re: How to "import" an interface into a module w/o `include?



On 2007-09-11, Jonathan Bromley <jonathan.bromley@xxxxxxxxxxxxx> wrote:
On Tue, 11 Sep 2007 20:01:28 -0000,
mrfirmware <mrfirmware@xxxxxxxxx> wrote:

<mrfirmw...@xxxxxxxxx> wrote:
I'd like to have a file with an interface in it and then "import" it
into my top level testbench.sv file. Something like this:

// File: my_if.sv
interface my_if;
...
endinterface : my_if

---

// File testbench.sv
import my_if::*;

module testbench;
my_if if0;
...
endmodule : testbench

There's something very basic I'm missing here, I realize that.
[...]
[ModelSim/Questa] (v6.3b). I do compile different sources into different
libs but not one file per lib. Must I?

No, certainly not. In fact, many people work with just one
single library for the entire project; that's OK too.

I've got my RTL in lib nz_rtl,
my testbench and top level .sv files in lib nz_top, and my packages in
nz_pkg.

Do you mean the source files are in those directories, or
do you mean that you have used 'vlog' to compile your source files
into ModelSim libraries of those names? If these are simply
the names of directories that contain your source code, then
they are not "libraries" at all and your use of the -L option
is misplaced.

No. For now, I have all my files in one dir. No sub-dirs. Make will find
all the sources automatically when I do end up moving them into proper subdirs.

I put my sole a typedef package file and the interface file
into nz_pkg and then tell vlog about all the library dirs via -L
nz_rtl -L nz_pkg, etc. However, vlog just complains that 'my_if' is an
undefined variable (which isn't too surprising as I don't know how it
could possibly know it's an interface).

Ahah... Do you *really* mean that it's *vlog* complaining (not vsim) ?
If so, it's simple... You don't want the -L option at that stage,
unless you're using packages. You need the -L option to 'vsim'
to tell it the names of all the libraries into which you've compiled
your various SystemVerilog modules and interfaces.

Indeed. E.g.

vlog testbench.sv -work /user/modell/proj/xs1_tb/out/nz_tb
-L /user/modell/proj/xs1_tb/out/nz_pkg
-L /user/modell/proj/xs1_tb/out/nz_rtl
-quiet -nologo -novopt -incr -lint -source -hazards
-timescale 1ns/1ps -dpiheader testbench_dpi.h

###### testbench.sv(145): perbus_if pb_if();
** Error: testbench.sv(145): Undefined variable: perbus_if.
** Error: testbench.sv(145): near "pb_if": syntax error, unexpected "IDENTIFIER"

Line 145 contains the attempt to instantiate a perbus_if which is
an interface defined in the nz_pkg lib (created by vlib).

Just as a for-instance...

Suppose you have this file tree:

project_home/
project_home/sim/ ---- working dir for the simulator
project_home/sources/ ---- dir to hold all source code
project_home/sources/nz_pkg/
project_home/sources/nz_pkg/your_interface.sv
project_home/sources/nz_pkg/your_package.sv
project_home/sources/nz_rtl/
project_home/sources/nz_rtl/your_module1.sv
project_home/sources/nz_rtl/your_module2.sv
project_home/sources/nz_top/
project_home/sources/nz_top/your_design_top.sv
project_home/sources/nz_top/your_testbench.sv

File "your_package.sv" contains a package:
package your_package;
...
endpackage : your_package

Most of the other files import it; for example,
file "your_interface.sv" might look like this:

import your_package::*;
interface your_interface;
...
endinterface

And the instance hierarchy will be

your_testbench
|
|__ your_design_top
|
|__ your_module1
|
|__ your_interface
|
|__ your_module2

My compile/load script for ModelSim might look
something like this:

cd project_home/sim
# make a bunch of libraries - only needed on first run of
# the script, will give harmless warnings on later runs
vlib pkg_lib; # make a ModelSim lib for the packages
vlib rtl_lib; # and another for the RTL design
vlib tb_lib; # and a third for the testbench
# compile package first, into pkg_lib
vlog -work pkg_lib ../sources/nz_pkg/your_package.sv
# now compile all the other code, in any order;
# make pkg_lib visible to each compile so they can
# import the package as needed; put design modules
# into "rtl_lib" and testbench modules into "tb_lib"
vlog -work rtl_lib -L pkg_lib ../sources/nz_pkg/your_interface.sv
vlog -work rtl_lib -L pkg_lib ../sources/nz_rtl/*.sv
vlog -work rtl_lib -L pkg_lib ../sources/nz_top/your_design_top.sv
vlog -work tb_lib -L pkg_lib ../sources/nz_top/your_testbench.sv
# OK, now everything compiled, load it into ModelSim
# making sure that the simulator looks in the right libs
vsim -novopt -L pkg_lib -L rtl_lib tb_lib.your_testbench

This is pretty much what my makefile does too. I do use vmap to map the
long dir name to a shorter name but I think that step could be skipped
as I never actually refer to the short name in any switch usage.

Natch, you may want to add a bunch of other options on some
of these commands. The point I'm really trying to get across
is that a directory full of source code is absolutely NOT the
same as a ModelSim library. (Please, please don't get me
started about Verilog configurations and "libraries", the
Verilog library mapping file [as opposed to ModelSim's
library mapping] and the `uselib directive. That would
take too long, and it's not at all clear my blood pressure
would cope.)

Hope this makes some sense.

It does and thank you.
--
- Mark
.



Relevant Pages

  • Re: Getting started on the HP49g+
    ... either the original HP extable lib ... extable2 lib from http://www.hpcalc.org/details.php?id=3940. ... ask again if you have any problem installing libraries. ... compile the string with ASM (listed in the development lib menu, ...
    (comp.sys.hp48)
  • Re: Variable uses a type not supported in Visual Basic (Error 458)
    ... > Microsoft Visual Basic for Applications Software Development Kit ... > interface in a Visual Basic class, ... > generate libraries that use a Visual Basic- or Visual Basic for ... > Rebuild your type library by pressing CTRL+F7 or selecting Compile ...
    (microsoft.public.vb.bugs)
  • Re: How to "import" an interface into a module w/o `include?
    ... libs but not one file per lib. ... do you mean that you have used 'vlog' to compile your source files ... into ModelSim libraries of those names? ... could possibly know it's an interface). ...
    (comp.lang.verilog)
  • Re: large file support && ! large file support
    ... that is a truly different interface at the ABI level than ... an extra legacy library that provides the ABI for older programs that expect ... toolchain to compile programs in the legacy architecture (for example the ... libraries like libc might well have to be coded to understand which it ...
    (comp.unix.programmer)
  • Re: How to bind source code with its compiled library name ?
    ... Usually, when you develop a program, you use functions imported from commercial/free libraries. ... If you forgot to tell the linker to link the library, then you got the error "cannot open file thelib_1_0_5.lib". ... When I add the "pragma" in the source and I compile, ... Of course the lib does not exists yet. ...
    (microsoft.public.vc.ide_general)