types based on parameters?

Guest
I want to make a type based on a parameter (DO_THIS), like this:

if( DO_THIS ) begin
typedef struct packed {
logic val;
logic a;
logic b;
logic c;
logic d;
} my_t;
end else begin
typedef struct packed {
logic val;
logic a;
logic b;
} my_t;
end

Is there any way to do this other than a generate block? My lint tool does not like this with a generate block.
 
In article <726f3d0b-2409-475a-9f1e-8500f0241967@googlegroups.com>,
<sk3499@gmail.com> wrote:
I want to make a type based on a parameter (DO_THIS), like this:

if( DO_THIS ) begin
typedef struct packed {
logic val;
logic a;
logic b;
logic c;
logic d;
} my_t;
end else begin
typedef struct packed {
logic val;
logic a;
logic b;
} my_t;
end

Is there any way to do this other than a generate block? My lint
tool does not like this with a generate block.

Yeah, that's not going to work. The typedef will only exist
within the (respective clause of the) generate block.

Are you looking for a synthesizable solution, or testbench only?

If it's testbench only, I'd suggest something more object oriented - using
classes and methods.

Regards,

Mark
 
sk3499@gmail.com wrote:
I want to make a type based on a parameter (DO_THIS), like this:

if( DO_THIS ) begin
typedef struct packed {
logic val;
logic a;
logic b;
logic c;
logic d;
} my_t;
end else begin
typedef struct packed {
logic val;
logic a;
logic b;
} my_t;
end

Is there any way to do this other than a generate block? My lint tool does not like this with a generate block.

I might be wrong, but if you put this inside a generate block, its
scope may not extend outside the block. Did you make use of the
struct (variable declarations) inside the generate block as well?

--
Gabor
 
On Monday, June 16, 2014 5:58:17 PM UTC-4, Mark Curry wrote:
In article <726f3d0b-2409-475a-9f1e-8500f0241967@googlegroups.com>,

sk3499@gmail.com> wrote:

I want to make a type based on a parameter (DO_THIS), like this:



if( DO_THIS ) begin

typedef struct packed {

logic val;

logic a;

logic b;

logic c;

logic d;

} my_t;

end else begin

typedef struct packed {

logic val;

logic a;

logic b;

} my_t;

end



Is there any way to do this other than a generate block? My lint

tool does not like this with a generate block.



Yeah, that's not going to work. The typedef will only exist

within the (respective clause of the) generate block.



Are you looking for a synthesizable solution, or testbench only?



If it's testbench only, I'd suggest something more object oriented - using

classes and methods.



Regards,



Mark


Synthesizable solution is what I am looking for.
 
In article <32eca651-3a14-453c-83ab-cafe43d01e1c@googlegroups.com>,
<sk3499@gmail.com> wrote:
On Monday, June 16, 2014 5:58:17 PM UTC-4, Mark Curry wrote:
In article <726f3d0b-2409-475a-9f1e-8500f0241967@googlegroups.com>,

sk3499@gmail.com> wrote:

I want to make a type based on a parameter (DO_THIS), like this:

if( DO_THIS ) begin
typedef struct packed {
logic val;
logic a;
logic b;
logic c;
logic d;
} my_t;
end else begin
typedef struct packed {
logic val;
logic a;
logic b;
} my_t;
end



Is there any way to do this other than a generate block? My lint
tool does not like this with a generate block.

Yeah, that's not going to work. The typedef will only exist
within the (respective clause of the) generate block.

Are you looking for a synthesizable solution, or testbench only?

Synthesizable solution is what I am looking for.

I'd consider just making everything easier, and just make everything a member
of the first type (it's the superset). So the second set doesn't need "c" or
"d". Just tie them off as (unused) constants, and let synthesis do its
job and optimize things away.

I'm having trouble trying to think of a good use case within a module. You'd
need to have large generate blocks where each part handled the seperate
definitions. Or a seperate module that handles each type. If all you need
to do is connect up the modules, then just pass the "shared" structure
as a long wire of the appropriate length, and make the length a parameter.

There's probably other ways, but nothing really clean, and it all depends
on how you're finally using the resolved type.

Regards,

Mark
 

Welcome to EDABoard.com

Sponsor

Back
Top