]> git.sur5r.net Git - cc65/commitdiff
More preparations for an extension of the calling conventions.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 29 Apr 2010 20:30:49 +0000 (20:30 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 29 Apr 2010 20:30:49 +0000 (20:30 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@4650 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/cc65/datatype.c
src/cc65/datatype.h
src/cc65/declare.c
src/cc65/scanner.c

index 5cbcb792d2d110799180e7f8e7a735d8b0fff248..0d7b27c6021b0aec761a2cfd340b9b15117fe1fc 100644 (file)
@@ -249,6 +249,7 @@ void PrintType (FILE* F, const Type* T)
         C = PrintTypeComp (F, C, T_QUAL_NEAR, "__near__");
         C = PrintTypeComp (F, C, T_QUAL_FAR, "__far__");
         C = PrintTypeComp (F, C, T_QUAL_FASTCALL, "__fastcall__");
+        C = PrintTypeComp (F, C, T_QUAL_CDECL, "__cdecl__");
 
        /* Signedness. Omit the signedness specifier for long and int */
                if ((C & T_MASK_TYPE) != T_TYPE_INT && (C & T_MASK_TYPE) != T_TYPE_LONG) {
@@ -333,6 +334,9 @@ void PrintFuncSig (FILE* F, const char* Name, Type* T)
     if (IsQualFastcall (T)) {
        fprintf (F, " __fastcall__");
     }
+    if (IsQualCDecl (T)) {
+       fprintf (F, " __cdecl__");
+    }
     fprintf (F, " %s (", Name);
 
     /* Parameters */
index 8f72fa105e98371aa10c4da5a61c096b91aa2079..0fe46f6d2b0b781ed53a6424b6d350ad8bae888e 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2008 Ullrich von Bassewitz                                       */
-/*               Roemerstrasse 52                                            */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 1998-2010, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -110,7 +110,9 @@ enum {
     T_QUAL_FAR      = 0x008000,
     T_QUAL_ADDRSIZE = T_QUAL_NEAR | T_QUAL_FAR,
     T_QUAL_FASTCALL = 0x010000,
-    T_MASK_QUAL            = 0x01F800,
+    T_QUAL_CDECL    = 0x020000,
+    T_QUAL_CCONV    = T_QUAL_FASTCALL | T_QUAL_CDECL,
+    T_MASK_QUAL            = 0x03F800,
 
     /* Types */
     T_CHAR             = T_TYPE_CHAR     | T_CLASS_INT    | T_SIGN_UNSIGNED | T_SIZE_NONE,
@@ -591,6 +593,16 @@ INLINE int IsQualFastcall (const Type* T)
 #  define IsQualFastcall(T)     (((T)->C & T_QUAL_FASTCALL) != 0)
 #endif
 
+#if defined(HAVE_INLINE)
+INLINE int IsQualCDecl (const Type* T)
+/* Return true if the given type has a cdecl qualifier */
+{
+    return (T->C & T_QUAL_CDECL) != 0;
+}
+#else
+#  define IsQualCDecl(T)        (((T)->C & T_QUAL_CDECL) != 0)
+#endif
+
 int IsVariadicFunc (const Type* T) attribute ((const));
 /* Return true if this is a function type or pointer to function type with
  * variable parameter list
index 2b5e5fb639cd8b14f37b9261f5667aa6a367c0b0..587d7ce74b34a2ab84cf0fb83ae0e1d4b2069dbe 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2008 Ullrich von Bassewitz                                       */
-/*               Roemerstrasse 52                                            */
-/*               D-70794 Filderstadt                                         */
-/* EMail:        uz@cc65.org                                                 */
+/* (C) 1998-2010, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -185,6 +185,17 @@ static TypeCode OptionalQualifiers (TypeCode Allowed)
                 }
                 break;
 
+            case TOK_CDECL:
+                if (Allowed & T_QUAL_CDECL) {
+                    if (Q & T_QUAL_CDECL) {
+                        DuplicateQualifier ("cdecl");
+                    }
+                    Q |= T_QUAL_CDECL;
+                } else {
+                    goto Done;
+                }
+                break;
+
            default:
                goto Done;
 
@@ -208,6 +219,19 @@ Done:
             Q &= ~T_QUAL_ADDRSIZE;
     }
 
+    /* We cannot have more than one calling convention specifier */
+    switch (Q & T_QUAL_CCONV) {
+
+        case T_QUAL_NONE:
+        case T_QUAL_FASTCALL:
+        case T_QUAL_CDECL:
+            break;
+
+        default:
+            Error ("Cannot specify more than one calling convention qualifier");
+            Q &= ~T_QUAL_CCONV;
+    }
+
     /* Return the qualifiers read */
     return Q;
 }
@@ -1405,6 +1429,9 @@ static void Declarator (const DeclSpec* Spec, Declaration* D, declmode_t Mode)
     if (Qualifiers & T_QUAL_FASTCALL) {
         Error ("Invalid `__fastcall__' qualifier");
     }
+    if (Qualifiers & T_QUAL_CDECL) {
+        Error ("Invalid `__cdecl__' qualifier");
+    }
 }
 
 
index 2f9b019aff7685d57ed88ac8ec68975511b1e3e1..360305852c1be7b13e7ad2ee583ae765c6d15b45 100644 (file)
@@ -205,8 +205,9 @@ static int SkipWhite (void)
 int TokIsFuncSpec (const Token* T)
 /* Return true if the token is a function specifier */
 {
-    return (T->Tok == TOK_INLINE) || (T->Tok == TOK_FASTCALL) ||
-           (T->Tok == TOK_NEAR)   || (T->Tok == TOK_FAR);
+    return (T->Tok == TOK_INLINE)   ||
+           (T->Tok == TOK_FASTCALL) || (T->Tok == TOK_CDECL) ||
+           (T->Tok == TOK_NEAR)     || (T->Tok == TOK_FAR);
 }