]> git.sur5r.net Git - cc65/commitdiff
Made __fastcall__ be the default calling convention for non-variadic functions.
authorGreg King <gregdk@users.sf.net>
Tue, 10 Mar 2015 09:53:52 +0000 (05:53 -0400)
committerGreg King <gregdk@users.sf.net>
Tue, 10 Mar 2015 09:53:52 +0000 (05:53 -0400)
include/ace.h
include/assert.h
include/cbm.h
include/dbg.h
include/lynx.h
include/zlib.h
libsrc/cbm/cbm_load.c
src/cc65/codeinfo.c
src/cc65/expr.c
src/cc65/function.c

index 8d91300852742dc17d3da43aefb433fcaf270eba..fba672227715d5902b63161a82ef28cfc579f97f 100644 (file)
@@ -2,14 +2,14 @@
 /*                                                                           */
 /*                                   ace.h                                   */
 /*                                                                           */
-/*                      ACE system specific definitions                      */
+/*                      ACE system-specific definitions                      */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2001 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 1998-2015, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -61,9 +61,9 @@ struct aceDirentBuf {
     char            ad_name [17];       /* Name itself, ASCIIZ */
 };
 
-int aceDirOpen (char* dir);
-int aceDirClose (int handle);
-int aceDirRead (int handle, struct aceDirentBuf* buf);
+int __cdecl__ aceDirOpen (char* dir);
+int __cdecl__ aceDirClose (int handle);
+int __cdecl__ aceDirRead (int handle, struct aceDirentBuf* buf);
 
 /* Type of an ACE key. Key in low byte, shift mask in high byte */
 typedef unsigned int aceKey;
@@ -92,23 +92,23 @@ typedef unsigned int aceKey;
 #define aceOP_RPTRATE           11      /* Key repeat rate */
 
 /* Console functions */
-void aceConWrite (char* buf, size_t count);
-void aceConPutLit (int c);
-void aceConPos (unsigned x, unsigned y);
-void aceConGetPos (unsigned* x, unsigned* y);
+void __cdecl__ aceConWrite (char* buf, size_t count);
+void __cdecl__ aceConPutLit (int c);
+void __cdecl__ aceConPos (unsigned x, unsigned y);
+void __cdecl__ aceConGetPos (unsigned* x, unsigned* y);
 unsigned aceConGetX (void);
 unsigned aceConGetY (void);
-char* aceConInput (char* buf, unsigned initial);
+char __cdecl__* aceConInput (char* buf, unsigned initial);
 int aceConStopKey (void);
 aceKey aceConGetKey (void);
-int aceConKeyAvail (aceKey* key);
-void aceConKeyMat (char* matrix);
-void aceConSetOpt (unsigned char opt, unsigned char val);
-int aceConGetOpt (unsigned char opt);
+int __cdecl__ aceConKeyAvail (aceKey* key);
+void __cdecl__ aceConKeyMat (char* matrix);
+void __cdecl__ aceConSetOpt (unsigned char opt, unsigned char val);
+int __cdecl__ aceConGetOpt (unsigned char opt);
 
 /* Misc stuff */
-int aceMiscIoPeek (unsigned addr);
-void aceMiscIoPoke (unsigned addr, unsigned char val);
+int __cdecl__ aceMiscIoPeek (unsigned addr);
+void __cdecl__ aceMiscIoPoke (unsigned addr, unsigned char val);
 
 
 
index 87bc4ff02dcc459a6ef6c1ce38a9828f68aae1ed..ceabd2482c3bde4c49ed277d9cad3c2eb59757a4 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2000 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 1998-2000, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -42,7 +42,7 @@
 #ifdef NDEBUG
 #  define assert(expr)
 #else
-extern void _afailed (const char*, unsigned);
+extern void __cdecl__ _afailed (const char*, unsigned);
 #  define assert(expr)  ((expr)? (void)0 : _afailed(__FILE__, __LINE__))
 #endif
 
index 730b0b49e6f06d5502bb2003b776a92309bdb7ab..1bc29bf4c684a564644a4b4f9c1f213a5d0175c6 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2012, Ullrich von Bassewitz                                      */
+/* (C) 1998-2015, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -222,7 +222,7 @@ void cbm_k_unlsn (void);
 
 
 
-unsigned int cbm_load (const char* name, unsigned char device, void* data);
+unsigned int __cdecl__ cbm_load (const char* name, unsigned char device, void* data);
 /* Loads file "name", from given device, to given address -- or, to the load
 ** address of the file if "data" is the null pointer (like load"name",8,1
 ** in BASIC).
index 734ca06b8950eb31af02851deec1342a303b92f2..7b4f67e3143c4407b020a40120b0a2e7253a88ab 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2000 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 1998-2000, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -88,7 +88,7 @@ unsigned __fastcall__ DbgDisAsmLen (unsigned Addr);
 int __fastcall__ DbgIsRAM (unsigned Addr);
 /* Return true if we can read and write the given address */
 
-char* DbgMemDump (unsigned Addr, char* Buf, unsigned char Len);
+char* __cdecl__ DbgMemDump (unsigned Addr, char* Buf, unsigned char Len);
 /* Create a line of a memory dump in the given buffer. The buffer contains
 ** the starting address (4 digits hex), then Len bytes in this format:
 ** "AAAA__XX_YY_ZZ_...". The passed char buffer must hold Len*3+5 bytes
index e9c7029940237ee15b062e0f7457c60d1c27fad1..72f3d5bfd6a4221fc2b98e69986544e3d8a9e73c 100644 (file)
@@ -2,7 +2,7 @@
 /*                                                                           */
 /*                                  lynx.h                                   */
 /*                                                                           */
-/*                     Lynx system specific definitions                      */
+/*                     Lynx system-specific definitions                      */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
@@ -109,25 +109,25 @@ extern void lynx_160_102_16_tgi[];    /* Referred to by tgi_static_stddrv[] */
 /*                           Sound support                                   */
 /*****************************************************************************/
 
-void lynx_snd_init ();
+void lynx_snd_init (void);
 /* Initialize the sound driver */
 
-void lynx_snd_pause ();
+void lynx_snd_pause (void);
 /* Pause sound */
 
-void lynx_snd_continue ();
+void lynx_snd_continue (void);
 /* Continue sound after pause */
 
 void __fastcall__ lynx_snd_play (unsigned char channel, unsigned char *music);
 /* Play tune on channel */
 
-void lynx_snd_stop ();
+void lynx_snd_stop (void);
 /* Stop sound on all channels */
 
 void __fastcall__ lynx_snd_stop_channel (unsigned char channel);
 /* Stop sound on all channels */
 
-unsigned char lynx_snd_active();
+unsigned char lynx_snd_active(void);
 /* Show which channels are active */
 
 /*****************************************************************************/
index 9bc5dcb270a583b18728947222d1788b2c7c7154..971095cd30ee56d945eb02574114d155a45503f9 100644 (file)
@@ -83,8 +83,8 @@ unsigned __fastcall__ inflatemem (char* dest, const char* source);
 */\r
 \r
 \r
-int uncompress (char* dest, unsigned* destLen,\r
-                const char* source, unsigned sourceLen);\r
+int __cdecl__ uncompress (char* dest, unsigned* destLen,\r
+                          const char* source, unsigned sourceLen);\r
 /*\r
    Original zlib description:\r
 \r
index 695af504b61d0829e5ba7daa05c5738d9f256d0d..7d4a5086b40544b276763f5e67e61d3f58fb6192 100644 (file)
@@ -1,9 +1,9 @@
 /*
 ** Marc 'BlackJack' Rintsch, 06.03.2001
 **
-** unsigned int cbm_load(const char* name,
-**                       unsigned char device,
-**                       const unsigned char* data);
+** unsigned int __cdecl__ cbm_load(const char* name,
+**                                 unsigned char device,
+**                                 const unsigned char* data);
 */
 
 #include <cbm.h>
@@ -11,7 +11,7 @@
 /* loads file "name" from given device to given address or to the load address
 ** of the file if "data" is 0
 */
-unsigned int cbm_load(const char* name, unsigned char device, void* data)
+unsigned int __cdecl__ cbm_load(const char* name, unsigned char device, void* data)
 {
     /* LFN is set to 0; but, it's not needed for loading
     ** (BASIC V2 sets it to the value of the SA for LOAD).
index be80319e7389c79c2f5ea5dbcf76fff74bbf12f7..ae264dce4eae1b594ac9d2f2aa42711992f69cbf 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2001-2012, Ullrich von Bassewitz                                      */
+/* (C) 2001-2015, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -386,33 +386,32 @@ void GetFuncInfo (const char* Name, unsigned short* Use, unsigned short* Chg)
     ** Search for it in the list of builtin functions.
     */
     if (Name[0] == '_') {
-
         /* Search in the symbol table, skip the leading underscore */
         SymEntry* E = FindGlobalSym (Name+1);
 
-        /* Did we find it in the top level table? */
+        /* Did we find it in the top-level table? */
         if (E && IsTypeFunc (E->Type)) {
-
             FuncDesc* D = E->V.F.Func;
 
-            /* A function may use the A or A/X registers if it is a fastcall
-            ** function. If it is not a fastcall function but a variadic one,
-            ** it will use the Y register (the parameter size is passed here).
-            ** In all other cases, no registers are used. However, we assume
-            ** that any function will destroy all registers.
+            /* A variadic function will use the Y register (the parameter list
+            ** size is passed there). A fastcall function will use the A or A/X
+            ** registers. In all other cases, no registers are used. However,
+            ** we assume that any function will destroy all registers.
             */
-            if (IsQualFastcall (E->Type) && D->ParamCount > 0) {
-                /* Will use registers depending on the last param */
-                unsigned LastParamSize = CheckedSizeOf (D->LastParam->Type);
-                if (LastParamSize == 1) {
-                    *Use = REG_A;
-                } else if (LastParamSize == 2) {
-                    *Use = REG_AX;
-                } else {
-                    *Use = REG_EAX;
-                }
-            } else if ((D->Flags & FD_VARIADIC) != 0) {
+            if ((D->Flags & FD_VARIADIC) != 0) {
                 *Use = REG_Y;
+            } else if (!IsQualCDecl (E->Type) && D->ParamCount > 0) {
+                /* Will use registers depending on the last param. */
+                switch (CheckedSizeOf (D->LastParam->Type)) {
+                    case 1u:
+                        *Use = REG_A;
+                        break;
+                    case 2u:
+                        *Use = REG_AX;
+                        break;
+                    default:
+                        *Use = REG_EAX;
+                }
             } else {
                 /* Will not use any registers */
                 *Use = REG_NONE;
index 03374a52147f86d48edbe648b4935cff8e1e371d..c8c47f6aa55120cf340a11892b74f96c00753cba 100644 (file)
@@ -1,6 +1,7 @@
 /* expr.c
 **
-** Ullrich von Bassewitz, 21.06.1998
+** 1998-06-21, Ullrich von Bassewitz
+** 2015-03-10, Greg King
 */
 
 
@@ -471,8 +472,8 @@ static void FunctionCall (ExprDesc* Expr)
     IsFuncPtr = IsTypeFuncPtr (Expr->Type);
     if (IsFuncPtr) {
 
-        /* Check wether it's a fastcall function that has parameters */
-        IsFastcall = IsQualFastcall (Expr->Type + 1) && (Func->ParamCount > 0);
+        /* Check whether it's a fastcall function that has parameters */
+        IsFastcall = (Func->Flags & FD_VARIADIC) == 0 && !IsQualCDecl (Expr->Type + 1) && (Func->ParamCount > 0);
 
         /* Things may be difficult, depending on where the function pointer
         ** resides. If the function pointer is an expression of some sort
@@ -517,7 +518,7 @@ static void FunctionCall (ExprDesc* Expr)
         }
 
         /* If we didn't inline the function, get fastcall info */
-        IsFastcall = IsQualFastcall (Expr->Type);
+        IsFastcall = (Func->Flags & FD_VARIADIC) == 0 && !IsQualCDecl (Expr->Type);
     }
 
     /* Parse the parameter list */
index d9f1eeac320455234147aec92e9c75f0c375741e..d80ba916a9bf29209f1b7431e0c86cf9c06f43f3 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2012, Ullrich von Bassewitz                                      */
+/* (C) 2000-2015, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -460,6 +460,9 @@ void NewFunc (SymEntry* Func)
         */
         if (D->ParamCount > 0 || (D->Flags & FD_VARIADIC) != 0) {
             g_importmainargs ();
+
+            /* The start-up code doesn't fast-call main(). */
+            Func->Type->C |= T_QUAL_CDECL;
         }
 
         /* Determine if this is a main function in a C99 environment that
@@ -478,13 +481,9 @@ void NewFunc (SymEntry* Func)
     PushLiteralPool (Func);
 
     /* If this is a fastcall function, push the last parameter onto the stack */
-    if (IsQualFastcall (Func->Type) && D->ParamCount > 0) {
-
+    if ((D->Flags & FD_VARIADIC) == 0 && !IsQualCDecl (Func->Type) && D->ParamCount > 0) {
         unsigned Flags;
 
-        /* Fastcall functions may never have an ellipsis or the compiler is buggy */
-        CHECK ((D->Flags & FD_VARIADIC) == 0);
-
         /* Generate the push */
         if (IsTypeFunc (D->LastParam->Type)) {
             /* Pointer to function */