Extend #pragma wrapped-call to support "bank" argument

This commit is contained in:
mrdudz
2021-05-05 14:42:29 +02:00
parent 216bb22b20
commit c9f242e566
6 changed files with 28 additions and 13 deletions

View File

@@ -1739,6 +1739,7 @@ static FuncDesc* ParseFuncDecl (void)
SymEntry* Sym; SymEntry* Sym;
SymEntry* WrappedCall; SymEntry* WrappedCall;
unsigned char WrappedCallData; unsigned char WrappedCallData;
int WrappedCallUseBank;
/* Create a new function descriptor */ /* Create a new function descriptor */
FuncDesc* F = NewFuncDesc (); FuncDesc* F = NewFuncDesc ();
@@ -1791,10 +1792,11 @@ static FuncDesc* ParseFuncDecl (void)
RememberFunctionLevel (F); RememberFunctionLevel (F);
/* Did we have a WrappedCall for this function? */ /* Did we have a WrappedCall for this function? */
GetWrappedCall((void **) &WrappedCall, &WrappedCallData); GetWrappedCall((void **) &WrappedCall, &WrappedCallData, &WrappedCallUseBank);
if (WrappedCall) { if (WrappedCall) {
F->WrappedCall = WrappedCall; F->WrappedCall = WrappedCall;
F->WrappedCallData = WrappedCallData; F->WrappedCallData = WrappedCallData;
F->WrappedCallUseBank = WrappedCallUseBank;
} }
/* Return the function descriptor */ /* Return the function descriptor */

View File

@@ -997,9 +997,16 @@ static void FunctionCall (ExprDesc* Expr)
char tmp[64]; char tmp[64];
StrBuf S = AUTO_STRBUF_INITIALIZER; StrBuf S = AUTO_STRBUF_INITIALIZER;
/* Store the WrappedCall data in tmp4 */ if (Func->WrappedCallUseBank) {
sprintf(tmp, "ldy #%u", Func->WrappedCallData); /* Store the bank attribute in tmp4 */
SB_AppendStr (&S, tmp); SB_AppendStr (&S, "ldy #<.bank(_");
SB_AppendStr (&S, (const char*) Expr->Name);
SB_AppendChar (&S, ')');
} else {
/* Store the WrappedCall data in tmp4 */
sprintf(tmp, "ldy #%u", Func->WrappedCallData);
SB_AppendStr (&S, tmp);
}
g_asmcode (&S); g_asmcode (&S);
SB_Clear(&S); SB_Clear(&S);

View File

@@ -72,6 +72,7 @@ struct FuncDesc {
struct FuncDesc* FuncDef; /* Descriptor used in definition */ struct FuncDesc* FuncDef; /* Descriptor used in definition */
struct SymEntry* WrappedCall; /* Pointer to the WrappedCall */ struct SymEntry* WrappedCall; /* Pointer to the WrappedCall */
unsigned char WrappedCallData;/* The WrappedCall's user data */ unsigned char WrappedCallData;/* The WrappedCall's user data */
int WrappedCallUseBank;/* Flag: does WrappedCall use .bank() or literal value */
}; };

View File

@@ -497,6 +497,7 @@ static void WrappedCallPragma (StrBuf* B)
const char *Name; const char *Name;
long Val; long Val;
SymEntry *Entry; SymEntry *Entry;
int UseBank = 0;
/* Check for the "push" or "pop" keywords */ /* Check for the "push" or "pop" keywords */
switch (ParsePushPop (B)) { switch (ParsePushPop (B)) {
@@ -535,12 +536,15 @@ static void WrappedCallPragma (StrBuf* B)
goto ExitPoint; goto ExitPoint;
} }
if (!GetNumber (B, &Val)) { /* Next must be either a numeric value, or "bank" */
if (HasStr (B, "bank")) {
UseBank = 1;
} else if (!GetNumber (B, &Val)) {
Error ("Value required for wrapped-call identifier"); Error ("Value required for wrapped-call identifier");
goto ExitPoint; goto ExitPoint;
} }
if (Val < 0 || Val > 255) { if (!UseBank && (Val < 0 || Val > 255)) {
Error ("Identifier must be between 0-255"); Error ("Identifier must be between 0-255");
goto ExitPoint; goto ExitPoint;
} }
@@ -552,7 +556,7 @@ static void WrappedCallPragma (StrBuf* B)
/* Check if the name is valid */ /* Check if the name is valid */
if (Entry && (Entry->Flags & SC_FUNC) == SC_FUNC) { if (Entry && (Entry->Flags & SC_FUNC) == SC_FUNC) {
PushWrappedCall(Entry, (unsigned char) Val); PushWrappedCall(Entry, (unsigned char) Val, UseBank);
Entry->Flags |= SC_REF; Entry->Flags |= SC_REF;
GetFuncDesc (Entry->Type)->Flags |= FD_CALL_WRAPPER; GetFuncDesc (Entry->Type)->Flags |= FD_CALL_WRAPPER;

View File

@@ -64,13 +64,13 @@ static IntPtrStack WrappedCalls;
void PushWrappedCall (void *Ptr, unsigned char Val) void PushWrappedCall (void *Ptr, unsigned char Val, int UseBank)
/* Push the current WrappedCall */ /* Push the current WrappedCall */
{ {
if (IPS_IsFull (&WrappedCalls)) { if (IPS_IsFull (&WrappedCalls)) {
Error ("WrappedCall stack overflow"); Error ("WrappedCall stack overflow");
} else { } else {
IPS_Push (&WrappedCalls, Val, Ptr); IPS_Push (&WrappedCalls, Val | (UseBank << 8), Ptr);
} }
} }
@@ -88,7 +88,7 @@ void PopWrappedCall (void)
void GetWrappedCall (void **Ptr, unsigned char *Val) void GetWrappedCall (void **Ptr, unsigned char *Val, int *UseBank)
/* Get the current WrappedCall */ /* Get the current WrappedCall */
{ {
if (IPS_GetCount (&WrappedCalls) < 1) { if (IPS_GetCount (&WrappedCalls) < 1) {
@@ -97,6 +97,7 @@ void GetWrappedCall (void **Ptr, unsigned char *Val)
} else { } else {
long Temp; long Temp;
IPS_Get (&WrappedCalls, &Temp, Ptr); IPS_Get (&WrappedCalls, &Temp, Ptr);
*Val = (unsigned char) Temp; *UseBank = (int) Temp >> 8;
*Val = (unsigned char) Temp & 0xff;
} }
} }

View File

@@ -50,13 +50,13 @@
void PushWrappedCall (void *Ptr, unsigned char Val); void PushWrappedCall (void *Ptr, unsigned char Val, int usebank);
/* Push the current WrappedCall */ /* Push the current WrappedCall */
void PopWrappedCall (void); void PopWrappedCall (void);
/* Pop the current WrappedCall */ /* Pop the current WrappedCall */
void GetWrappedCall (void **Ptr, unsigned char *Val); void GetWrappedCall (void **Ptr, unsigned char *Val, int *usebank);
/* Get the current WrappedCall, if any */ /* Get the current WrappedCall, if any */