Cannot include ASM header file in C without loss of preprocessor

Short version:

I want to be able to define assembler macros in macros.Sand use them internally asm()in GNU C.

I can do this from asm(".include \"macros.S\"");the top of my C source, but I want to macros.Sgo through the C preprocessor.


Long version:

In GCC asm, files are *.Spre-processed by the C preprocessor, allowing you to use the C style #define, etc.

In GCC C, you can include the asm header file (which may include asm macro definitions, declarations .set, etc.) by writing asm(".include \"myasmheader.S\"");at the top of the file.

Including the ASM header file this way allows you to use asm macros inside asm blocks.

Unfortunately, this does not invoke the C preprocessor in the file .Sthat is included (since it .includeis executed later during the compilation process), and therefore is #defineno longer replaced.

So, is there a way to properly include the file .Sinside the C file?

Some other compilers support:

#asm
#include "myasmheader.S"
#endasm

That would not show such a problem. But alas, GCC seems to require all asm inside the C file to be in the form of lines.

With the exception of using asm (not an option, a built-in DSP project that mixes asm and c a lot), or removing the use of the C preprocessor in ASM files, what can I do?

+4
source share

Source: https://habr.com/ru/post/1689962/


All Articles