Conditional compiling, exists ?

L

LC

Hi.

Sorry for the naive question.

Is there a way to implement conditional compiling
in VHDL (as in C for example, #ifdef... #endif).

I would like to have a source with two variants
that I may decide to compile one way or another
but there are several small differences spread
across the code so...

(two separate files is difficult to maintain in sync
while design progresses)
(commenting and uncommenting parts is prone to mistakes
and messy)

Is there any hope to make my life easier ?


Luis. C.
 
Joined
Jan 29, 2009
Messages
152
Reaction score
0
Inside a process you can simply use if statements, checking whether a constant boolean is true or similar;
Code:
  if ( DO_MANUAL_CHECK ) then 
    -- any valid code inside a process
  else
    -- alternative code inside the process
  end if;
The else case is optional obviously;

Outside of a process, you can do something similar, using the if generate construct:
Code:
checked: if ( DO_MANUAL_CHECK ) generate
    -- any valid code inside the body of an architecture
  end generate checked;

alt_checked: if ( not DO_MANUAL_CHECK ) generate
    -- alternative code inside the body of the architecture
  end generate alt_checked;
An if-generate is required to have a label ("checked" in this case)
There is not "else" part for the if-generate construct, so you have to add another if-generate, testing
for the not case.

Any synthesizer will pick up that the check is always true (or always false), so it will do what you expect.
 
Last edited:
T

Tricky

Hi.

Sorry for the naive question.

Is there a way to implement conditional compiling
in VHDL (as in C for example, #ifdef... #endif).

I would like to have a source with two variants
that I may decide to compile one way or another
but there are several small differences spread
across the code so...

(two separate files is difficult to maintain in sync
while design progresses)
(commenting and uncommenting parts is prone to mistakes
and messy)

Is there any hope to make my life easier ?

Luis. C.

I think there may be a couple of options:

1. Have 2 different architectures for the same entity and use
configurations to change which one to compile
2. Use generics to control what gets compiled based on the values:

for example:

reg_gen : if add_register generate

process(clk)
begin
if rising_edge(clk) then
out <= in;
end if;
end process;
end reg_gen

no_reg_gen : if not add_register generate

out <= in;
end no_reg_gen;


Given what you already said (2 variants on the same thing) you
probably want configurations (someone else will have to explain this
mystical VHDL concept).
 
R

Rich Webb

Hi.

Sorry for the naive question.

Is there a way to implement conditional compiling
in VHDL (as in C for example, #ifdef... #endif).

I would like to have a source with two variants
that I may decide to compile one way or another
but there are several small differences spread
across the code so...

(two separate files is difficult to maintain in sync
while design progresses)
(commenting and uncommenting parts is prone to mistakes
and messy)

Is there any hope to make my life easier ?

You might want to look at "m4" which is a macro preprocessor intended as
a front end to the "normal" compilation process. It's a pretty standard
Unix utility (or did it pre-date Unix?) that's now on most (all?) *ix
distributions. There are binary versions for Windows (Cygwin and native
code) and Mac.

For more info, hop over to the Wikipedia entry and go from there.
 
M

Mike Treseler

LC said:
Is there a way to implement conditional compiling
in VHDL (as in C for example, #ifdef... #endif).

There is no preprocessor.
I use packaged constants with regular
vhdl conditional statements or generics.

-- Mike Treseler
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,427
Latest member
HildredDic

Latest Threads

Top