1
0
mirror of https://github.com/cc65/cc65.git synced 2025-08-08 06:25:17 +00:00

New %s inline asm format specifier

git-svn-id: svn://svn.cc65.org/cc65/trunk@2442 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2003-09-16 20:35:37 +00:00
parent 5537aee205
commit ffb77285de
2 changed files with 46 additions and 8 deletions

View File

@@ -910,6 +910,7 @@ the format specifier before passing the assembly code line to the backend.
<item><tt/%l/ - Numerical 32 bit value <item><tt/%l/ - Numerical 32 bit value
<item><tt/%v/ - Assembler name of a (global) variable or function <item><tt/%v/ - Assembler name of a (global) variable or function
<item><tt/%o/ - Stack offset of a (local) variable <item><tt/%o/ - Stack offset of a (local) variable
<item><tt/%s/ - The argument is converted to a string
<item><tt/%%/ - The % sign itself <item><tt/%%/ - The % sign itself
</itemize><p> </itemize><p>
@@ -949,7 +950,7 @@ variables or functions into your asm statements. Code like this
<p> <p>
may stop working if the way, the compiler generates these names is changed in may stop working if the way, the compiler generates these names is changed in
a future version. a future version. Instead use the format specifiers from the table above.
<p> <p>

View File

@@ -7,8 +7,8 @@
/* */ /* */
/* */ /* */
/* (C) 2001-2003 Ullrich von Bassewitz */ /* (C) 2001-2003 Ullrich von Bassewitz */
/* Wacholderweg 14 */ /* R<EFBFBD>merstrasse 52 */
/* D-70597 Stuttgart */ /* D-70794 Filderstadt */
/* EMail: uz@musoftware.de */ /* EMail: uz@musoftware.de */
/* */ /* */
/* */ /* */
@@ -274,6 +274,41 @@ static void ParseLVarArg (StrBuf* T, unsigned Arg)
static void ParseStrArg (StrBuf* T, unsigned Arg attribute ((unused)))
/* Parse the %s format specifier */
{
ExprDesc Expr;
char Buf [64];
/* We expect an argument separated by a comma */
ConsumeComma ();
/* Check what comes */
switch (CurTok.Tok) {
case TOK_IDENT:
/* Identifier */
SB_AppendStr (T, CurTok.Ident);
NextToken ();
break;
case TOK_SCONST:
/* String constant */
SB_AppendStr (T, GetLiteral (CurTok.IVal));
ResetLiteralPoolOffs (CurTok.IVal);
NextToken ();
break;
default:
ConstSubExpr (hie1, InitExprDesc (&Expr));
xsprintf (Buf, sizeof (Buf), "%ld", Expr.ConstVal);
SB_AppendStr (T, Buf);
break;
}
}
static void ParseAsm (void) static void ParseAsm (void)
/* Parse the contents of the ASM statement */ /* Parse the contents of the ASM statement */
{ {
@@ -304,6 +339,7 @@ static void ParseAsm (void)
* %l - Numerical 32 bit value * %l - Numerical 32 bit value
* %v - Assembler name of a (global) variable * %v - Assembler name of a (global) variable
* %o - Stack offset of a (local) variable * %o - Stack offset of a (local) variable
* %s - Any argument converted to a string (almost)
* %% - The % sign * %% - The % sign
*/ */
Arg = 0; Arg = 0;
@@ -322,12 +358,13 @@ static void ParseAsm (void)
++Arg; ++Arg;
C = SB_Get (&S); C = SB_Get (&S);
switch (C) { switch (C) {
case 'b': ParseByteArg (&T, Arg); break;
case 'w': ParseWordArg (&T, Arg); break;
case 'l': ParseLongArg (&T, Arg); break;
case 'v': ParseGVarArg (&T, Arg); break;
case 'o': ParseLVarArg (&T, Arg); break;
case '%': SB_AppendChar (&T, '%'); break; case '%': SB_AppendChar (&T, '%'); break;
case 'b': ParseByteArg (&T, Arg); break;
case 'l': ParseLongArg (&T, Arg); break;
case 'o': ParseLVarArg (&T, Arg); break;
case 's': ParseStrArg (&T, Arg); break;
case 'v': ParseGVarArg (&T, Arg); break;
case 'w': ParseWordArg (&T, Arg); break;
default: default:
Error ("Error in __asm__ format specifier %u", Arg); Error ("Error in __asm__ format specifier %u", Arg);
AsmErrorSkip (); AsmErrorSkip ();