mirror of
https://github.com/cc65/cc65.git
synced 2024-10-01 00:57:11 +00:00
commit
1c54213091
@ -401,6 +401,11 @@ void GetFuncInfo (const char* Name, unsigned short* Use, unsigned short* Chg)
|
|||||||
*/
|
*/
|
||||||
if ((D->Flags & FD_VARIADIC) != 0) {
|
if ((D->Flags & FD_VARIADIC) != 0) {
|
||||||
*Use = REG_Y;
|
*Use = REG_Y;
|
||||||
|
} else if (D->Flags & FD_CALL_WRAPPER) {
|
||||||
|
/* Wrappers may go to any functions, so mark them as using all
|
||||||
|
** registers.
|
||||||
|
*/
|
||||||
|
*Use = REG_EAXY;
|
||||||
} else if (D->ParamCount > 0 &&
|
} else if (D->ParamCount > 0 &&
|
||||||
(AutoCDecl ?
|
(AutoCDecl ?
|
||||||
IsQualFastcall (E->Type) :
|
IsQualFastcall (E->Type) :
|
||||||
|
@ -52,9 +52,10 @@
|
|||||||
#define FD_OLDSTYLE 0x0010U /* Old style (K&R) function */
|
#define FD_OLDSTYLE 0x0010U /* Old style (K&R) function */
|
||||||
#define FD_OLDSTYLE_INTRET 0x0020U /* K&R func has implicit int return */
|
#define FD_OLDSTYLE_INTRET 0x0020U /* K&R func has implicit int return */
|
||||||
#define FD_UNNAMED_PARAMS 0x0040U /* Function has unnamed params */
|
#define FD_UNNAMED_PARAMS 0x0040U /* Function has unnamed params */
|
||||||
|
#define FD_CALL_WRAPPER 0x0080U /* This function is used as a wrapper */
|
||||||
|
|
||||||
/* Bits that must be ignored when comparing funcs */
|
/* Bits that must be ignored when comparing funcs */
|
||||||
#define FD_IGNORE (FD_OLDSTYLE | FD_OLDSTYLE_INTRET | FD_UNNAMED_PARAMS)
|
#define FD_IGNORE (FD_OLDSTYLE | FD_OLDSTYLE_INTRET | FD_UNNAMED_PARAMS | FD_CALL_WRAPPER)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -513,6 +513,7 @@ static void WrappedCallPragma (StrBuf* B)
|
|||||||
|
|
||||||
PushWrappedCall(Entry, Val);
|
PushWrappedCall(Entry, Val);
|
||||||
Entry->Flags |= SC_REF;
|
Entry->Flags |= SC_REF;
|
||||||
|
Entry->V.F.Func->Flags |= FD_CALL_WRAPPER;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
32
test/val/trampoline-params.c
Normal file
32
test/val/trampoline-params.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
!!DESCRIPTION!! wrapped-call pragma w/ many params
|
||||||
|
!!ORIGIN!! cc65 regression tests
|
||||||
|
!!LICENCE!! Public Domain
|
||||||
|
!!AUTHOR!! Lauri Kasanen
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
static unsigned char flag;
|
||||||
|
|
||||||
|
static void trampoline_set() {
|
||||||
|
asm("ldy tmp4");
|
||||||
|
asm("sty %v", flag);
|
||||||
|
asm("jsr callptr4");
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma wrapped-call(push, trampoline_set, 4)
|
||||||
|
long adder(long in);
|
||||||
|
#pragma wrapped-call(pop)
|
||||||
|
|
||||||
|
long adder(long in) {
|
||||||
|
|
||||||
|
return in + 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
flag = 0;
|
||||||
|
|
||||||
|
return adder(70436) == 70436 + 7 && flag == 4 ? 0 : 1;
|
||||||
|
}
|
48
test/val/trampoline-varargs.c
Normal file
48
test/val/trampoline-varargs.c
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
!!DESCRIPTION!! wrapped-call pragma w/ variadic function
|
||||||
|
!!ORIGIN!! cc65 regression tests
|
||||||
|
!!LICENCE!! Public Domain
|
||||||
|
!!AUTHOR!! Lauri Kasanen
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
static unsigned char flag;
|
||||||
|
|
||||||
|
static void trampoline_set() {
|
||||||
|
// The Y register is used for variadics - save and restore
|
||||||
|
asm("sty tmp3");
|
||||||
|
|
||||||
|
asm("ldy tmp4");
|
||||||
|
asm("sty %v", flag);
|
||||||
|
|
||||||
|
asm("ldy tmp3");
|
||||||
|
asm("jsr callptr4");
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma wrapped-call(push, trampoline_set, 4)
|
||||||
|
unsigned adder(unsigned char num, ...);
|
||||||
|
#pragma wrapped-call(pop)
|
||||||
|
|
||||||
|
unsigned adder(unsigned char num, ...) {
|
||||||
|
|
||||||
|
unsigned char i;
|
||||||
|
unsigned sum = 0;
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, num);
|
||||||
|
|
||||||
|
for (i = 0; i < num; i++) {
|
||||||
|
sum += va_arg(ap, unsigned);
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
flag = 0;
|
||||||
|
|
||||||
|
return adder(3, 0, 5, 500) == 505 && flag == 4 ? 0 : 1;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user