• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. #ifdef #else #endif inside module instantiation in Veri...

Stats

  • Locked Locked
  • Replies 8
  • Subscribers 65
  • Views 22698
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

#ifdef #else #endif inside module instantiation in Verilog

aarthymani
aarthymani over 7 years ago

Hi all, 

             I am trying to reverse engineer an open source verilog code for learning purpose. The code has some similar structure as below(please ignore my syntax errors) 

                         module tb_trail();

                              ....

                              test dut (

                                   .a(out)

                                   .b(in1) 

                                #ifdef TRAIL

                                     .c(in3) 

                                #else 

                                      .c(in4)

                                #endif 

                               );

             I have some basic knowledge in Verilog, and compiling it with INCISIVE. But when i try to compile the above module, I am getting error for missing either left or right parenthesis (*E,EXPLPA).

            Wondering, where is my mistake. Does INCISIVE(irun) supposed to understand those statements? is there a runtime option i need to specify to clear it? for your info, the definition for "TRAIL" is found with *.vh file  and I included it with -incdir option, and also added -vlog_ext +.vh to my run command

            Could someone help? 

Thanks in Advance! 

Aarthy 

                     

  • Cancel
  • StephenH
    StephenH over 7 years ago

    The problem is you've got a typo, it should be "#ifdef TRIAL" but you put "TRAIL". Only kidding ;-)

    Your real problem is not the ifdef pragmas, it's the missing commas between the port connections.

    Try this:

                             module tb_trail();

                                  ....

                                  test dut (

                                       .a(out),  // added a comma

                                       .b(in1) , // added a comma

                                    #ifdef TRAIL

                                         .c(in3)   //no comma because it's the last one in the list

                                    #else 

                                          .c(in4)

                                    #endif 

                                   );

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • aarthymani
    aarthymani over 7 years ago in reply to StephenH

    Hi Stephen, 

           Thanks for typo correction. As I mentioned, "Please ignore my syntax errors". The original codes runs pages and pages, so i tried to mimic the concept into a smaller code version.  I do have commas placed in those areas, the main focus of the question is on the #ifdef #else #endif itself.  

          Does doing the instantiation with #ifdef PARAMETER works?  so far, i have never used or seen it before. 

    Thanks!

    Aarthy 

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • StephenH
    StephenH over 7 years ago in reply to aarthymani

    ifdef pragmas work everywhere; they are processed before any other syntax parsing and are independent of the Verilog code.

    It's impossible to ignore syntax errors when you're asking about a parser problem, so either provide us with a runnable example of your issue, or at least clean up the other errors so that we only look at the one you think is real. Slight smile

    I'm 100% certain that your issue has nothing to do with the ifdef/else/endif, it's far more likely that you've simply broken your original code by putting the ifdef in a way that either the true or false branch introduces a syntax error by, for example, having a comma in one branch and not in the other. You'll get a much quicker solution if you can share the full code either here or by filing a support request at support.cadence.com (better, if the code is confidential).

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • TAM1
    TAM1 over 7 years ago

    It looks like the person who created your Verilog example was using the C preprocessor to handle his defines and macros. Your example shows #ifdef which will work for C. The Verilog preprocessor uses the "accent-grave" character or backwards-single-quote `. It is in the far upper-left of my keyboard. Try this:

    `ifdef TRIAL

      .c(in3),

    `else

      .c(in4),

    `endif

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • StephenH
    StephenH over 7 years ago in reply to TAM1

    Good catch Tom, I've been writing C code all day and totally missed the # versus back-tick typo! Slight smile

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • StephenH
    StephenH over 7 years ago in reply to StephenH

    As ever though, this highlights why it's better to submit a runnable testcase rather than a broken code fragment that has multiple errors in it!

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • aarthymani
    aarthymani over 7 years ago in reply to StephenH

    Hi Stephen, 

              I totally understand. It is my mistake :( I will make sure I will post a bug free/no syntax error codes in future. The code is based on open source License, so I wasn't sure whether I can just like post anywhere.  I should have checked before posting my example.  :(

     

    Tom, Thanks for your response. I will change and try to simulate, will update here. 

    Thanks!

    Aarthy

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • aarthymani
    aarthymani over 7 years ago in reply to TAM1

    Hi Tom,

       Changing the " # " to " ` " does solve that missing parenthesis error.

       Thank you! 

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information