[cfe-dev] Pre-processing assembly sources

Martin J. O'Riordan via cfe-dev cfe-dev at lists.llvm.org
Thu Aug 11 01:16:17 PDT 2016


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

-----Original Message-----
From: Joerg Sonnenberger [mailto:joerg at bec.de] 
Sent: 08 August 2016 22:41
To: Martin J. O'Riordan
Subject: Re: [cfe-dev] Pre-processing assembly sources

On Mon, Aug 08, 2016 at 12:47:11PM +0100, Martin J. O'Riordan wrote:
> I'm assuming that this mode does not have any explicit documentation, 
> but I will do some experimentation to see which C dialect it is 
> closest to, in particular support for variadic macros.

It should be a superset of normal C99/C11 preprocessor logic. As long as you
don't try too fancy things, legal stuff should work.

Joerg




More information about the cfe-dev mailing list