On Mon, Jun 03, 2024 at 11:01:02AM -0400, Jason Merrill wrote:
> On 6/2/24 23:45, Andi Kleen wrote:
> > Some programing styles use a lot of inline assembler, and it is common
> > to use very complex preprocessor macros to generate the assembler
> > strings for the asm statements. In C++ there would be a typesafe alternative
> > using templates and constexpr to generate the assembler strings, but
> > unfortunately the asm statement requires plain string literals, so this
> > doesn't work.
> > 
> > This patch modifies the C++ parser to accept strings generated by
> > constexpr instead of just plain strings. This requires new syntax
> > because e.g. asm("..." : "r" (expr)) would be ambigious with a function
> > call. I chose () to make it unique. For example now you can write
> > 
> > constexpr const char *genasm() { return "insn"; }
> > constexpr const char *genconstraint() { return "r"; }
> > 
> >     asm(genasm() :: (genconstraint()) (input));
> 
> Looks plausible.  What happens when someone forgets the parens, as seems a
> likely mistake?

constexpr-asm-1.C:27:13: error: expected string-literal before ‘genfoo’
   27 |         asm(genfoo() : genoutput() (a) : geninput() (1) :
   genclobber());
         |             ^~~~~~


Admittedly not great, I will try to give a better message.


-Andi

Reply via email to