user4284354
user4284354

Reputation:

replace `define with let construct

I'm trying to avoid using `define pre-processor and start using "let" since it's a language construct.

Here is my example:

`define MY_REGISTER_RANGE 15:0

logic [`MY_REGISTER_RANGE] my_array;

How can I do the same with let construct? My code is very simple but it assumes that I'm `include the file where my macro MY_REGISTER_RANGE is defined (in another file).

Thanks.

Upvotes: 0

Views: 2839

Answers (2)

Serge
Serge

Reputation: 12364

In this particular case you do not need the let construct. Moreover, the construct has nothing to do with declarations of variables.

You can start using parameters instead of text macros. For example

parameter MY_REGISTER_WIDTH = 16;
...
logic [MY_REGISTER_WIDTH-1:0] my_array;

The let construct defines a simple function containing a single expression. In this respect it could be used to replace certain types of macros, e.g.

`define MULT(A,B)   A * B
...
R = `MULT(O1,O2);

could be replaced with

let MULT(A,B) = A * B;
...
R = MULT(O1,O2);

Upvotes: 1

dave_59
dave_59

Reputation: 42723

You can only substitute certain kinds of expressions using let. You can't just define a range.

You should use a typedef instead of let

typedef logic [15:0] MY_REGISTER_t;
MY_REGISTER_t my_array;

Upvotes: 2

Related Questions