This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PRU Compiler: PRU Compiler 2.1.4 : cdecls workaround for Conditional Compilation (#if/#else/#ifdef/etc.)

Tool/software: TI PRU Compiler 

Hi

I am trying to include a C header file ( having multiple #ifdef / #endif ) into an assembly source file using cdecls. 

http://downloads.ti.com/docs/esd/SLAU131K/Content/SLAU131K_HTML/sharing_c_c_header_files_with_assembly_source.html mentions that presently it wont do Conditional Compilation. Can somebody suggest a workaround for this issue?

  • Garvit Jain said:
    I am trying to include a C header file ( having multiple #ifdef / #endif ) into an assembly source file using cdecls. 

    Go ahead and use .cdecls to include it.  But you need to understand that the #ifdef  and #endif lines are evaluated as the include file is processed.  They are not converted into assembler directives like .if and .endif, then evaluated by the directive processing phase of the assembler.

    Thanks and regards,

    -George

  • Thanks for the speedy reply. I think my use-case differs a bit & I'll explain it here.
    Lets assume there's a C header file A_C.h which contains

    #ifdef P

    #define R

    #endif

    And another ASM header file A_ASM.h file doing the same thing in assembler format as shown
    .if $isdefed("P")
    R .set 1
    .endif

    If I include A_ASM.h in some assembly source files with P as a predefined symbol in the build configuration , I can see statements under .if $isdefed("R") getting executed. But NOT when I directly include the C header file A_C.h using cdecls. Moreover, now if I add R too as a predefined symbol to the build configuration , it build properly but with a warning of re declaration of R.

    This suggests that R was getting defined in both scenarios but in prior case it didn't enter the symbol table. So I would like to know is there some way for something like R getting entry into symbol table without being explicitly mentioned in the build configuration?

  • In summary, test for existence of symbols created inside .cdecls with #define by using ...

        .if    $defined(C_define_name)    ; works

    ... and not by using ...

        .if    $isdefed("C_define_name")   ; fails

    To understand why requires you understand a few concepts defined by the assembler.  There are two kinds of symbols: regular (also called standard) symbols, and substitution symbols.  C has these too, though not by those terms.  In C, a #define symbol replaces one piece of text with another.  For example 

       #define FOREVER while(1)
    

    ... means the text FOREVER is replaced with the text "while (1)".  That is quite different from a regular symbol ...

        int global_variable;

    The directive .set creates a regular symbol.  A #define symbol is implemented with a .define directive, and that creates a substitution symbol.  Wherever a substitution symbol appears, it is replaced by the corresponding text.  

    The $isdefed operator only checks the regular symbol table.  But the $defined operator checks both the regular symbol table, and the substitution symbol table.

    For more details, please see the PRU assembly tools manual.

    Thanks and regards,

    -George