From 54740da820b8449d09d56e3c7494b74ddd088cd0 Mon Sep 17 00:00:00 2001 From: uz Date: Thu, 29 Apr 2010 20:30:49 +0000 Subject: [PATCH] More preparations for an extension of the calling conventions. git-svn-id: svn://svn.cc65.org/cc65/trunk@4650 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/datatype.c | 4 ++++ src/cc65/datatype.h | 22 +++++++++++++++++----- src/cc65/declare.c | 35 +++++++++++++++++++++++++++++++---- src/cc65/scanner.c | 5 +++-- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index 5cbcb792d..0d7b27c60 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -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 */ diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h index 8f72fa105..0fe46f6d2 100644 --- a/src/cc65/datatype.h +++ b/src/cc65/datatype.h @@ -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 diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 2b5e5fb63..587d7ce74 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -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"); + } } diff --git a/src/cc65/scanner.c b/src/cc65/scanner.c index 2f9b019af..360305852 100644 --- a/src/cc65/scanner.c +++ b/src/cc65/scanner.c @@ -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); } -- 2.39.5