mirror of
https://github.com/cc65/cc65.git
synced 2024-12-28 06:30:16 +00:00
More changes to support address size qualifiers.
git-svn-id: svn://svn.cc65.org/cc65/trunk@3899 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
63943c3f44
commit
1e46bc16e4
@ -90,7 +90,7 @@ unsigned TypeLen (const Type* T)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Type* TypeCpy (Type* Dest, const Type* Src)
|
Type* TypeCopy (Type* Dest, const Type* Src)
|
||||||
/* Copy a type string */
|
/* Copy a type string */
|
||||||
{
|
{
|
||||||
Type* Orig = Dest;
|
Type* Orig = Dest;
|
||||||
@ -712,25 +712,21 @@ Type* PtrConversion (Type* T)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
TypeCode CodeAddrSizeQualifier (void)
|
TypeCode AddrSizeQualifier (unsigned AddrSize)
|
||||||
/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the code address size */
|
/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the address size */
|
||||||
{
|
{
|
||||||
if (CodeAddrSize == ADDR_SIZE_FAR) {
|
switch (AddrSize) {
|
||||||
return T_QUAL_FAR;
|
|
||||||
} else {
|
case ADDR_SIZE_ABS:
|
||||||
return T_QUAL_NEAR;
|
return T_QUAL_NEAR;
|
||||||
}
|
|
||||||
}
|
case ADDR_SIZE_FAR:
|
||||||
|
return T_QUAL_FAR;
|
||||||
|
|
||||||
|
default:
|
||||||
TypeCode DataAddrSizeQualifier (void)
|
Error ("Invalid address size");
|
||||||
/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the data address size */
|
return T_QUAL_NEAR;
|
||||||
{
|
|
||||||
if (DataAddrSize == ADDR_SIZE_FAR) {
|
|
||||||
return T_QUAL_FAR;
|
|
||||||
} else {
|
|
||||||
return T_QUAL_NEAR;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
/* common */
|
/* common */
|
||||||
#include "attrib.h"
|
#include "attrib.h"
|
||||||
#include "inline.h"
|
#include "inline.h"
|
||||||
|
#include "mmodel.h"
|
||||||
|
|
||||||
/* cc65 */
|
/* cc65 */
|
||||||
#include "funcdesc.h"
|
#include "funcdesc.h"
|
||||||
@ -199,7 +200,7 @@ struct SymEntry;
|
|||||||
unsigned TypeLen (const Type* T);
|
unsigned TypeLen (const Type* T);
|
||||||
/* Return the length of the type string */
|
/* Return the length of the type string */
|
||||||
|
|
||||||
Type* TypeCpy (Type* Dest, const Type* Src);
|
Type* TypeCopy (Type* Dest, const Type* Src);
|
||||||
/* Copy a type string */
|
/* Copy a type string */
|
||||||
|
|
||||||
Type* TypeDup (const Type* T);
|
Type* TypeDup (const Type* T);
|
||||||
@ -634,11 +635,28 @@ Type* PtrConversion (Type* T);
|
|||||||
* return T.
|
* return T.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
TypeCode CodeAddrSizeQualifier (void);
|
TypeCode AddrSizeQualifier (unsigned AddrSize);
|
||||||
/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the code address size */
|
/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the address size */
|
||||||
|
|
||||||
TypeCode DataAddrSizeQualifier (void);
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE TypeCode CodeAddrSizeQualifier (void)
|
||||||
|
/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the code address size */
|
||||||
|
{
|
||||||
|
return AddrSizeQualifier (CodeAddrSize);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define CodeAddrSizeQualifier() (AddrSizeQualifier (CodeAddrSize))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE TypeCode DataAddrSizeQualifier (void)
|
||||||
/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the data address size */
|
/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the data address size */
|
||||||
|
{
|
||||||
|
return AddrSizeQualifier (DataAddrSize);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define DataAddrSizeQualifier() (AddrSizeQualifier (DataAddrSize))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -90,9 +90,15 @@ static void DuplicateQualifier (const char* Name)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static TypeCode OptionalQualifiers (TypeCode Q, TypeCode Allowed)
|
static TypeCode OptionalQualifiers (TypeCode Allowed)
|
||||||
/* Read type qualifiers if we have any */
|
/* Read type qualifiers if we have any. Allowed specifies the allowed
|
||||||
|
* qualifiers.
|
||||||
|
*/
|
||||||
{
|
{
|
||||||
|
/* We start without any qualifiers */
|
||||||
|
TypeCode Q = T_QUAL_NONE;
|
||||||
|
|
||||||
|
/* Check for more qualifiers */
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
switch (CurTok.Tok) {
|
switch (CurTok.Tok) {
|
||||||
@ -173,6 +179,19 @@ static TypeCode OptionalQualifiers (TypeCode Q, TypeCode Allowed)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Done:
|
Done:
|
||||||
|
/* We cannot have more than one address size far qualifier */
|
||||||
|
switch (Q & T_QUAL_ADDRSIZE) {
|
||||||
|
|
||||||
|
case T_QUAL_NONE:
|
||||||
|
case T_QUAL_NEAR:
|
||||||
|
case T_QUAL_FAR:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Error ("Cannot specify more than one address size qualifier");
|
||||||
|
Q &= ~T_QUAL_ADDRSIZE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Return the qualifiers read */
|
/* Return the qualifiers read */
|
||||||
return Q;
|
return Q;
|
||||||
}
|
}
|
||||||
@ -555,7 +574,7 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers)
|
|||||||
D->Flags &= ~DS_DEF_TYPE;
|
D->Flags &= ~DS_DEF_TYPE;
|
||||||
|
|
||||||
/* Read type qualifiers if we have any */
|
/* Read type qualifiers if we have any */
|
||||||
Qualifiers = OptionalQualifiers (Qualifiers, T_QUAL_CONST | T_QUAL_VOLATILE);
|
Qualifiers |= OptionalQualifiers (T_QUAL_CONST | T_QUAL_VOLATILE);
|
||||||
|
|
||||||
/* Look at the data type */
|
/* Look at the data type */
|
||||||
switch (CurTok.Tok) {
|
switch (CurTok.Tok) {
|
||||||
@ -744,7 +763,7 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers)
|
|||||||
if (Entry && SymIsTypeDef (Entry)) {
|
if (Entry && SymIsTypeDef (Entry)) {
|
||||||
/* It's a typedef */
|
/* It's a typedef */
|
||||||
NextToken ();
|
NextToken ();
|
||||||
TypeCpy (D->Type, Entry->Type);
|
TypeCopy (D->Type, Entry->Type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* FALL THROUGH */
|
/* FALL THROUGH */
|
||||||
@ -763,7 +782,7 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* There may also be qualifiers *after* the initial type */
|
/* There may also be qualifiers *after* the initial type */
|
||||||
D->Type[0].C |= OptionalQualifiers (Qualifiers, T_QUAL_CONST | T_QUAL_VOLATILE);
|
D->Type[0].C |= (Qualifiers | OptionalQualifiers (T_QUAL_CONST | T_QUAL_VOLATILE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1030,7 +1049,7 @@ static FuncDesc* ParseFuncDecl (void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void Decl (const DeclSpec* Spec, Declaration* D, unsigned Mode)
|
static void Declarator (const DeclSpec* Spec, Declaration* D, unsigned Mode)
|
||||||
/* Recursively process declarators. Build a type array in reverse order. */
|
/* Recursively process declarators. Build a type array in reverse order. */
|
||||||
{
|
{
|
||||||
/* Read optional function or pointer qualifiers. These modify the
|
/* Read optional function or pointer qualifiers. These modify the
|
||||||
@ -1039,21 +1058,7 @@ static void Decl (const DeclSpec* Spec, Declaration* D, unsigned Mode)
|
|||||||
* qualifier will later be transfered to the function itself. If it's a
|
* qualifier will later be transfered to the function itself. If it's a
|
||||||
* pointer to something else, it will be flagged as an error.
|
* pointer to something else, it will be flagged as an error.
|
||||||
*/
|
*/
|
||||||
TypeCode Qualifiers =
|
TypeCode Qualifiers = OptionalQualifiers (T_QUAL_ADDRSIZE | T_QUAL_FASTCALL);
|
||||||
OptionalQualifiers (T_QUAL_NONE, T_QUAL_ADDRSIZE | T_QUAL_FASTCALL);
|
|
||||||
|
|
||||||
/* We cannot have more than one address size far qualifier */
|
|
||||||
switch (Qualifiers & T_QUAL_ADDRSIZE) {
|
|
||||||
|
|
||||||
case T_QUAL_NONE:
|
|
||||||
case T_QUAL_NEAR:
|
|
||||||
case T_QUAL_FAR:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Error ("Cannot specify more than one address size qualifier");
|
|
||||||
Qualifiers &= ~T_QUAL_ADDRSIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Pointer to something */
|
/* Pointer to something */
|
||||||
if (CurTok.Tok == TOK_STAR) {
|
if (CurTok.Tok == TOK_STAR) {
|
||||||
@ -1061,11 +1066,11 @@ static void Decl (const DeclSpec* Spec, Declaration* D, unsigned Mode)
|
|||||||
/* Skip the star */
|
/* Skip the star */
|
||||||
NextToken ();
|
NextToken ();
|
||||||
|
|
||||||
/* Allow optional pointer qualifiers */
|
/* Allow const, restrict and volatile qualifiers */
|
||||||
Qualifiers = OptionalQualifiers (Qualifiers, T_QUAL_CONST | T_QUAL_VOLATILE);
|
Qualifiers |= OptionalQualifiers (T_QUAL_CONST | T_QUAL_VOLATILE | T_QUAL_RESTRICT);
|
||||||
|
|
||||||
/* Parse the type, the pointer points to */
|
/* Parse the type, the pointer points to */
|
||||||
Decl (Spec, D, Mode);
|
Declarator (Spec, D, Mode);
|
||||||
|
|
||||||
/* Add the type */
|
/* Add the type */
|
||||||
AddTypeToDeclaration (D, T_PTR | Qualifiers);
|
AddTypeToDeclaration (D, T_PTR | Qualifiers);
|
||||||
@ -1074,7 +1079,7 @@ static void Decl (const DeclSpec* Spec, Declaration* D, unsigned Mode)
|
|||||||
|
|
||||||
if (CurTok.Tok == TOK_LPAREN) {
|
if (CurTok.Tok == TOK_LPAREN) {
|
||||||
NextToken ();
|
NextToken ();
|
||||||
Decl (Spec, D, Mode);
|
Declarator (Spec, D, Mode);
|
||||||
ConsumeRParen ();
|
ConsumeRParen ();
|
||||||
} else {
|
} else {
|
||||||
/* Things depend on Mode now:
|
/* Things depend on Mode now:
|
||||||
@ -1200,7 +1205,7 @@ Type* ParseType (Type* T)
|
|||||||
ParseDecl (&Spec, &Decl, DM_NO_IDENT);
|
ParseDecl (&Spec, &Decl, DM_NO_IDENT);
|
||||||
|
|
||||||
/* Copy the type to the target buffer */
|
/* Copy the type to the target buffer */
|
||||||
TypeCpy (T, Decl.Type);
|
TypeCopy (T, Decl.Type);
|
||||||
|
|
||||||
/* Return a pointer to the target buffer */
|
/* Return a pointer to the target buffer */
|
||||||
return T;
|
return T;
|
||||||
@ -1215,11 +1220,11 @@ void ParseDecl (const DeclSpec* Spec, Declaration* D, unsigned Mode)
|
|||||||
InitDeclaration (D);
|
InitDeclaration (D);
|
||||||
|
|
||||||
/* Get additional declarators and the identifier */
|
/* Get additional declarators and the identifier */
|
||||||
Decl (Spec, D, Mode);
|
Declarator (Spec, D, Mode);
|
||||||
|
|
||||||
/* Add the base type. */
|
/* Add the base type. */
|
||||||
NeedTypeSpace (D, TypeLen (Spec->Type) + 1); /* Bounds check */
|
NeedTypeSpace (D, TypeLen (Spec->Type) + 1); /* Bounds check */
|
||||||
TypeCpy (D->Type + D->Index, Spec->Type);
|
TypeCopy (D->Type + D->Index, Spec->Type);
|
||||||
|
|
||||||
/* Use the storage class from the declspec */
|
/* Use the storage class from the declspec */
|
||||||
D->StorageClass = Spec->StorageClass;
|
D->StorageClass = Spec->StorageClass;
|
||||||
@ -1310,7 +1315,7 @@ void ParseDeclSpec (DeclSpec* D, unsigned DefStorage, long DefType)
|
|||||||
InitDeclSpec (D);
|
InitDeclSpec (D);
|
||||||
|
|
||||||
/* There may be qualifiers *before* the storage class specifier */
|
/* There may be qualifiers *before* the storage class specifier */
|
||||||
Qualifiers = OptionalQualifiers (T_QUAL_NONE, T_QUAL_CONST | T_QUAL_VOLATILE);
|
Qualifiers = OptionalQualifiers (T_QUAL_CONST | T_QUAL_VOLATILE);
|
||||||
|
|
||||||
/* Now get the storage class specifier for this declaration */
|
/* Now get the storage class specifier for this declaration */
|
||||||
ParseStorageClass (D, DefStorage);
|
ParseStorageClass (D, DefStorage);
|
||||||
|
Loading…
Reference in New Issue
Block a user