I have a package that I wanted to put some useful helper lets in to do some common calculations that I use all over the place. I thought I could just use them in a class, but when I do I get an error. Here is a basic example that shows the issue:
package let_pkg;
let sum(b,c) = b+c;
endpackage
class class_that_uses_let;
int a,b,c;
task use_let;
a = let_pkg::sum(b,c);
endtask
endclass
First: Why is this illegal?
Second: What is a better way to do this if I want these let constructs to be useable in various parts of my testbench? In the past I have used macros, but 'let' seems so much cleaner so I want to make it work.
It might be a tool bug.
Using
import let_pkg::*;works for me on eda playground in multiple simulators based on comments by @dave_59You can optionally remove the scope resolution operator
let_pkg::whenimport::*is used.Example using import
Testbench
Produces
Putting the 'let' construct in a package, then importing the package as needed works to build a library.
Small math or logic operations can be done in tasks or functions in a package. Using tasks & functions may be more familiar to Verilog coders than
let(important if you are going to share the library).Yet another way would be to put tasks, functions, let, etc in another class, and have instances of that class where needed, rather than using a package as the library.
No
Here is the full explanation by @dave_59
package-contents-into-class-scope