mirror of
https://github.com/cc65/cc65.git
synced 2024-12-23 19:29:37 +00:00
Extend #pragma wrapped-call to support "bank" argument
This commit is contained in:
parent
216bb22b20
commit
c9f242e566
@ -1739,6 +1739,7 @@ static FuncDesc* ParseFuncDecl (void)
|
||||
SymEntry* Sym;
|
||||
SymEntry* WrappedCall;
|
||||
unsigned char WrappedCallData;
|
||||
int WrappedCallUseBank;
|
||||
|
||||
/* Create a new function descriptor */
|
||||
FuncDesc* F = NewFuncDesc ();
|
||||
@ -1791,10 +1792,11 @@ static FuncDesc* ParseFuncDecl (void)
|
||||
RememberFunctionLevel (F);
|
||||
|
||||
/* Did we have a WrappedCall for this function? */
|
||||
GetWrappedCall((void **) &WrappedCall, &WrappedCallData);
|
||||
GetWrappedCall((void **) &WrappedCall, &WrappedCallData, &WrappedCallUseBank);
|
||||
if (WrappedCall) {
|
||||
F->WrappedCall = WrappedCall;
|
||||
F->WrappedCallData = WrappedCallData;
|
||||
F->WrappedCallUseBank = WrappedCallUseBank;
|
||||
}
|
||||
|
||||
/* Return the function descriptor */
|
||||
|
@ -997,9 +997,16 @@ static void FunctionCall (ExprDesc* Expr)
|
||||
char tmp[64];
|
||||
StrBuf S = AUTO_STRBUF_INITIALIZER;
|
||||
|
||||
/* Store the WrappedCall data in tmp4 */
|
||||
sprintf(tmp, "ldy #%u", Func->WrappedCallData);
|
||||
SB_AppendStr (&S, tmp);
|
||||
if (Func->WrappedCallUseBank) {
|
||||
/* Store the bank attribute in tmp4 */
|
||||
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);
|
||||
SB_Clear(&S);
|
||||
|
||||
|
@ -72,6 +72,7 @@ struct FuncDesc {
|
||||
struct FuncDesc* FuncDef; /* Descriptor used in definition */
|
||||
struct SymEntry* WrappedCall; /* Pointer to the WrappedCall */
|
||||
unsigned char WrappedCallData;/* The WrappedCall's user data */
|
||||
int WrappedCallUseBank;/* Flag: does WrappedCall use .bank() or literal value */
|
||||
};
|
||||
|
||||
|
||||
|
@ -497,6 +497,7 @@ static void WrappedCallPragma (StrBuf* B)
|
||||
const char *Name;
|
||||
long Val;
|
||||
SymEntry *Entry;
|
||||
int UseBank = 0;
|
||||
|
||||
/* Check for the "push" or "pop" keywords */
|
||||
switch (ParsePushPop (B)) {
|
||||
@ -535,12 +536,15 @@ static void WrappedCallPragma (StrBuf* B)
|
||||
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");
|
||||
goto ExitPoint;
|
||||
}
|
||||
|
||||
if (Val < 0 || Val > 255) {
|
||||
if (!UseBank && (Val < 0 || Val > 255)) {
|
||||
Error ("Identifier must be between 0-255");
|
||||
goto ExitPoint;
|
||||
}
|
||||
@ -552,7 +556,7 @@ static void WrappedCallPragma (StrBuf* B)
|
||||
/* Check if the name is valid */
|
||||
if (Entry && (Entry->Flags & SC_FUNC) == SC_FUNC) {
|
||||
|
||||
PushWrappedCall(Entry, (unsigned char) Val);
|
||||
PushWrappedCall(Entry, (unsigned char) Val, UseBank);
|
||||
Entry->Flags |= SC_REF;
|
||||
GetFuncDesc (Entry->Type)->Flags |= FD_CALL_WRAPPER;
|
||||
|
||||
|
@ -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 */
|
||||
{
|
||||
if (IPS_IsFull (&WrappedCalls)) {
|
||||
Error ("WrappedCall stack overflow");
|
||||
} 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 */
|
||||
{
|
||||
if (IPS_GetCount (&WrappedCalls) < 1) {
|
||||
@ -97,6 +97,7 @@ void GetWrappedCall (void **Ptr, unsigned char *Val)
|
||||
} else {
|
||||
long Temp;
|
||||
IPS_Get (&WrappedCalls, &Temp, Ptr);
|
||||
*Val = (unsigned char) Temp;
|
||||
*UseBank = (int) Temp >> 8;
|
||||
*Val = (unsigned char) Temp & 0xff;
|
||||
}
|
||||
}
|
||||
|
@ -50,13 +50,13 @@
|
||||
|
||||
|
||||
|
||||
void PushWrappedCall (void *Ptr, unsigned char Val);
|
||||
void PushWrappedCall (void *Ptr, unsigned char Val, int usebank);
|
||||
/* Push the current WrappedCall */
|
||||
|
||||
void PopWrappedCall (void);
|
||||
/* 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 */
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user