Pre-processing assembly sources

Using the C pre-processor for maintaining assembly source files is really useful, but which ISO C Standard pre-processor is selected when pre-processing files with the extension ‘.S’?

Thanks,

MartinO

Assuming you do something like clang -E foo.S > foo.s it uses the default for the compiler. If you want a specific language standard, use the -std=c99 or -std=c11.

Or are you doing something different from that?

When I use ‘-std=*’ I get an error reporting that the ‘.S’ is not a C or C++ program. So I assume that the default therefore is C89 (C90)?

I’m actually using it as follows:

clang -c foo.S

to directly create the ‘.o’.

Thanks,

MartinO

Actually, it isn't exactly ISO C. The language mode is called
assembler-with-cpp and it has a bunch of explicit changes from normal
CPP rules. For example, it silently accepts certain tokenisation errors.

Joerg

Thanks Joerg.

I have another question about pre-processing for assembly sources.

C and C++ do not distinguish newline from any other kind of whitespace, and
the expansion of a macro has no embedded newlines (keeps line tracking
happy).

But assemblers typically process a line at a time, so a macro such as:

  #define LOAD_and_ADDI(n) \
    LD r1, r2 \
    ADDI r1, r1, n

  LOAD_and_ADDI(0x20)

expands to:

  LD r1, r2 ADDI r1, r1, 0x20

With strict ISO C phases of translation rules there is no way that I can
think of to embed newlines so that the expansion becomes:

  LD r1, r2
  ADDI r1, r1, 0x20

Is there any trick with CLang (or GCC) that allows a newline to be embedded
in the expansion? Or possibly a "magic" token? (for example '__NL') so that
I could rewrite this as:

  #define LOAD_and_ADDI(n) \
    LD r1, r2 __NL \
    ADDI r1, r1, n

Or if the source is assembly the magic token could expand to something like:

  LD r1, r2
  .loc <resync the line-numbering>
  ADDI r1, r1, 0x20

and for C/C++ it might expand to:

  LD r1, r2
  # <resync the line-numbering>
  ADDI r1, r1, 0x20

Thanks,

  MartinO

This is normally dealt with by separating the instructions explicitly
with ";".

Joerg

Yes, unfortunately our assembler uses ';' to start a comment to end of line :frowning:

Thanks,

  MartinO