Merge pull request #1911 from acqn/TypeFix
[cc65] Organized type-related stuff better
This commit is contained in:
1333
src/cc65/datatype.c
1333
src/cc65/datatype.c
File diff suppressed because it is too large
Load Diff
@@ -239,23 +239,6 @@ extern const Type type_c_void_p[];
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const char* GetBasicTypeName (const Type* T);
|
|
||||||
/* Return a const name string of the basic type.
|
|
||||||
** Return "type" for unknown basic types.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const char* GetFullTypeName (const Type* T);
|
|
||||||
/* Return the full name string of the given type */
|
|
||||||
|
|
||||||
struct StrBuf* GetFullTypeNameBuf (struct StrBuf* S, const Type* T);
|
|
||||||
/* Return the full name string of the given type */
|
|
||||||
|
|
||||||
int GetQualifierTypeCodeNameBuf (struct StrBuf* S, TypeCode Qual, TypeCode IgnoredQual);
|
|
||||||
/* Return the names of the qualifiers of the type.
|
|
||||||
** Qualifiers to be ignored can be specified with the IgnoredQual flags.
|
|
||||||
** Return the count of added qualifier names.
|
|
||||||
*/
|
|
||||||
|
|
||||||
unsigned TypeLen (const Type* T);
|
unsigned TypeLen (const Type* T);
|
||||||
/* Return the length of the type string */
|
/* Return the length of the type string */
|
||||||
|
|
||||||
@@ -273,17 +256,26 @@ Type* TypeAlloc (unsigned Len);
|
|||||||
void TypeFree (Type* T);
|
void TypeFree (Type* T);
|
||||||
/* Free a type string */
|
/* Free a type string */
|
||||||
|
|
||||||
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE void CopyTypeAttr (const Type* Src, Type* Dest)
|
||||||
|
/* Copy attribute data from Src to Dest */
|
||||||
|
{
|
||||||
|
Dest->A = Src->A;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define CopyTypeAttr(Src, Dest) ((Dest)->A = (Src)->A)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Type info extraction */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int SignExtendChar (int C);
|
int SignExtendChar (int C);
|
||||||
/* Do correct sign extension of a character */
|
/* Do correct sign extension of a character to an int */
|
||||||
|
|
||||||
Type* GetCharArrayType (unsigned Len);
|
|
||||||
/* Return the type for a char array of the given length */
|
|
||||||
|
|
||||||
Type* GetImplicitFuncType (void);
|
|
||||||
/* Return a type string for an inplicitly declared function */
|
|
||||||
|
|
||||||
const Type* GetStructReplacementType (const Type* SType);
|
|
||||||
/* Get a replacement type for passing a struct/union in the primary register */
|
|
||||||
|
|
||||||
long GetIntegerTypeMin (const Type* Type);
|
long GetIntegerTypeMin (const Type* Type);
|
||||||
/* Get the smallest possible value of the integer type.
|
/* Get the smallest possible value of the integer type.
|
||||||
@@ -295,9 +287,42 @@ unsigned long GetIntegerTypeMax (const Type* Type);
|
|||||||
** The type must have a known size.
|
** The type must have a known size.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
unsigned SizeOf (const Type* T);
|
||||||
|
/* Compute size (in bytes) of object represented by type array */
|
||||||
|
|
||||||
|
unsigned PSizeOf (const Type* T);
|
||||||
|
/* Compute size (in bytes) of pointee object */
|
||||||
|
|
||||||
|
unsigned CheckedSizeOf (const Type* T);
|
||||||
|
/* Return the size (in bytes) of a data type. If the size is zero, emit an
|
||||||
|
** error and return some valid size instead (so the rest of the compiler
|
||||||
|
** doesn't have to work with invalid sizes).
|
||||||
|
*/
|
||||||
|
|
||||||
|
unsigned CheckedPSizeOf (const Type* T);
|
||||||
|
/* Return the size (in bytes) of a data type that is pointed to by a pointer.
|
||||||
|
** If the size is zero, emit an error and return some valid size instead (so
|
||||||
|
** the rest of the compiler doesn't have to work with invalid sizes).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE TypeCode GetQualifier (const Type* T)
|
||||||
|
/* Get the qualifier from the given type string */
|
||||||
|
{
|
||||||
|
return (T->C & T_MASK_QUAL);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define GetQualifier(T) ((T)->C & T_MASK_QUAL)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
TypeCode GetUnderlyingTypeCode (const Type* Type);
|
||||||
|
/* Get the type code of the unqualified underlying type of TCode.
|
||||||
|
** Return TCode if it is not scalar.
|
||||||
|
*/
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
INLINE TypeCode UnqualifiedType (TypeCode T)
|
INLINE TypeCode UnqualifiedType (TypeCode T)
|
||||||
/* Return the unqalified type code */
|
/* Return the unqualified type code */
|
||||||
{
|
{
|
||||||
return (T & ~T_MASK_QUAL);
|
return (T & ~T_MASK_QUAL);
|
||||||
}
|
}
|
||||||
@@ -305,39 +330,94 @@ INLINE TypeCode UnqualifiedType (TypeCode T)
|
|||||||
# define UnqualifiedType(T) ((T) & ~T_MASK_QUAL)
|
# define UnqualifiedType(T) ((T) & ~T_MASK_QUAL)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const Type* GetUnderlyingType (const Type* Type);
|
#if defined(HAVE_INLINE)
|
||||||
/* Get the underlying type of an enum or other integer class type */
|
INLINE TypeCode GetClass (const Type* T)
|
||||||
|
/* Get the class of a type string */
|
||||||
|
{
|
||||||
|
return (T->C & T_MASK_CLASS);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define GetClass(T) ((T)->C & T_MASK_CLASS)
|
||||||
|
#endif
|
||||||
|
|
||||||
TypeCode GetUnderlyingTypeCode (const Type* Type);
|
#if defined(HAVE_INLINE)
|
||||||
/* Get the type code of the unqualified underlying type of TCode.
|
INLINE TypeCode GetSignedness (const Type* T)
|
||||||
** Return TCode if it is not scalar.
|
/* Get the signedness of a type */
|
||||||
|
{
|
||||||
|
return (GetUnderlyingTypeCode (T) & T_MASK_SIGN);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define GetSignedness(T) (GetUnderlyingTypeCode (T) & T_MASK_SIGN)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE TypeCode GetSizeModifier (const Type* T)
|
||||||
|
/* Get the size modifier of a type */
|
||||||
|
{
|
||||||
|
return (GetUnderlyingTypeCode (T) & T_MASK_SIZE);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define GetSizeModifier(T) (GetUnderlyingTypeCode (T) & T_MASK_SIZE)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE TypeCode GetRawType (const Type* T)
|
||||||
|
/* Get the raw type */
|
||||||
|
{
|
||||||
|
return (T->C & T_MASK_TYPE);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define GetRawType(T) ((T)->C & T_MASK_TYPE)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE TypeCode GetRawSignedness (const Type* T)
|
||||||
|
/* Get the raw signedness of a type */
|
||||||
|
{
|
||||||
|
return ((T)->C & T_MASK_SIGN);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define GetRawSignedness(T) ((T)->C & T_MASK_SIGN)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE TypeCode GetRawSizeModifier (const Type* T)
|
||||||
|
/* Get the size modifier of a raw type */
|
||||||
|
{
|
||||||
|
return (T->C & T_MASK_SIZE);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define GetRawSizeModifier(T) ((T)->C & T_MASK_SIZE)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Type manipulation */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Type* GetImplicitFuncType (void);
|
||||||
|
/* Return a type string for an implicitly declared function */
|
||||||
|
|
||||||
|
Type* GetCharArrayType (unsigned Len);
|
||||||
|
/* Return the type for a char array of the given length */
|
||||||
|
|
||||||
|
Type* NewPointerTo (const Type* T);
|
||||||
|
/* Return a type string that is "pointer to T". The type string is allocated
|
||||||
|
** on the heap and may be freed after use.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const Type* GetBitFieldChunkType (const Type* Type);
|
Type* NewBitFieldType (const Type* T, unsigned BitOffs, unsigned BitWidth);
|
||||||
/* Get the type needed to operate on the byte chunk containing the bit-field */
|
/* Return a type string that is "T : BitWidth" aligned on BitOffs. The type
|
||||||
|
** string is allocated on the heap and may be freed after use.
|
||||||
unsigned SizeOf (const Type* T);
|
|
||||||
/* Compute size of object represented by type array. */
|
|
||||||
|
|
||||||
unsigned PSizeOf (const Type* T);
|
|
||||||
/* Compute size of pointer object. */
|
|
||||||
|
|
||||||
unsigned CheckedSizeOf (const Type* T);
|
|
||||||
/* Return the size of a data type. If the size is zero, emit an error and
|
|
||||||
** return some valid size instead (so the rest of the compiler doesn't have
|
|
||||||
** to work with invalid sizes).
|
|
||||||
*/
|
|
||||||
unsigned CheckedPSizeOf (const Type* T);
|
|
||||||
/* Return the size of a data type that is pointed to by a pointer. If the
|
|
||||||
** size is zero, emit an error and return some valid size instead (so the
|
|
||||||
** rest of the compiler doesn't have to work with invalid sizes).
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned TypeOf (const Type* T);
|
const Type* AddressOf (const Type* T);
|
||||||
/* Get the code generator base type of the object */
|
/* Return a type string that is "address of T". The type string is allocated
|
||||||
|
** on the heap and may be freed after use.
|
||||||
unsigned FuncTypeOf (const Type* T);
|
*/
|
||||||
/* Get the code generator flag for calling the function */
|
|
||||||
|
|
||||||
const Type* Indirect (const Type* T);
|
const Type* Indirect (const Type* T);
|
||||||
/* Do one indirection for the given type, that is, return the type where the
|
/* Do one indirection for the given type, that is, return the type where the
|
||||||
@@ -349,16 +429,6 @@ Type* IndirectModifiable (Type* T);
|
|||||||
** given type points to.
|
** given type points to.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Type* NewPointerTo (const Type* T);
|
|
||||||
/* Return a type string that is "pointer to T". The type string is allocated
|
|
||||||
** on the heap and may be freed after use.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const Type* AddressOf (const Type* T);
|
|
||||||
/* Return a type string that is "address of T". The type string is allocated
|
|
||||||
** on the heap and may be freed after use.
|
|
||||||
*/
|
|
||||||
|
|
||||||
Type* ArrayToPtr (const Type* T);
|
Type* ArrayToPtr (const Type* T);
|
||||||
/* Convert an array to a pointer to it's first element */
|
/* Convert an array to a pointer to it's first element */
|
||||||
|
|
||||||
@@ -388,20 +458,22 @@ const Type* SignedType (const Type* T);
|
|||||||
const Type* UnsignedType (const Type* T);
|
const Type* UnsignedType (const Type* T);
|
||||||
/* Get unsigned counterpart of the integral type */
|
/* Get unsigned counterpart of the integral type */
|
||||||
|
|
||||||
Type* NewBitFieldType (const Type* T, unsigned BitOffs, unsigned BitWidth);
|
const Type* GetUnderlyingType (const Type* Type);
|
||||||
/* Return a type string that is "T : BitWidth" aligned on BitOffs. The type
|
/* Get the underlying type of an enum or other integer class type */
|
||||||
** string is allocated on the heap and may be freed after use.
|
|
||||||
*/
|
const Type* GetStructReplacementType (const Type* SType);
|
||||||
|
/* Get a replacement type for passing a struct/union in the primary register */
|
||||||
|
|
||||||
|
const Type* GetBitFieldChunkType (const Type* Type);
|
||||||
|
/* Get the type needed to operate on the byte chunk containing the bit-field */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Type Predicates */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
|
||||||
INLINE TypeCode GetRawType (const Type* T)
|
|
||||||
/* Get the raw type */
|
|
||||||
{
|
|
||||||
return (T->C & T_MASK_TYPE);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define GetRawType(T) ((T)->C & T_MASK_TYPE)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
INLINE int IsTypeChar (const Type* T)
|
INLINE int IsTypeChar (const Type* T)
|
||||||
@@ -628,16 +700,6 @@ INLINE int IsTypeFuncPtr (const Type* T)
|
|||||||
# define IsTypeFuncPtr(T) (IsTypePtr (T) && IsTypeFunc (T+1))
|
# define IsTypeFuncPtr(T) (IsTypePtr (T) && IsTypeFunc (T+1))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
|
||||||
INLINE TypeCode GetClass (const Type* T)
|
|
||||||
/* Get the class of a type string */
|
|
||||||
{
|
|
||||||
return (T->C & T_MASK_CLASS);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define GetClass(T) ((T)->C & T_MASK_CLASS)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
INLINE int IsClassInt (const Type* T)
|
INLINE int IsClassInt (const Type* T)
|
||||||
/* Return true if this is an integer type */
|
/* Return true if this is an integer type */
|
||||||
@@ -727,25 +789,8 @@ int IsEmptiableObjectType (const Type* T);
|
|||||||
int HasUnknownSize (const Type* T);
|
int HasUnknownSize (const Type* T);
|
||||||
/* Return true if this is an incomplete ESU type or an array of unknown size */
|
/* Return true if this is an incomplete ESU type or an array of unknown size */
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
int TypeHasAttr (const Type* T);
|
||||||
INLINE TypeCode GetRawSignedness (const Type* T)
|
/* Return true if the given type has attribute data */
|
||||||
/* Get the raw signedness of a type */
|
|
||||||
{
|
|
||||||
return ((T)->C & T_MASK_SIGN);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define GetRawSignedness(T) ((T)->C & T_MASK_SIGN)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
|
||||||
INLINE TypeCode GetSignedness (const Type* T)
|
|
||||||
/* Get the signedness of a type */
|
|
||||||
{
|
|
||||||
return (GetUnderlyingTypeCode (T) & T_MASK_SIGN);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define GetSignedness(T) (GetUnderlyingTypeCode (T) & T_MASK_SIGN)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
INLINE int IsRawSignUnsigned (const Type* T)
|
INLINE int IsRawSignUnsigned (const Type* T)
|
||||||
@@ -787,35 +832,13 @@ INLINE int IsSignSigned (const Type* T)
|
|||||||
# define IsSignSigned(T) (GetSignedness (T) == T_SIGN_SIGNED)
|
# define IsSignSigned(T) (GetSignedness (T) == T_SIGN_SIGNED)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
|
||||||
INLINE TypeCode GetRawSizeModifier (const Type* T)
|
|
||||||
/* Get the size modifier of a raw type */
|
|
||||||
{
|
|
||||||
return (T->C & T_MASK_SIZE);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define GetRawSizeModifier(T) ((T)->C & T_MASK_SIZE)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
|
||||||
INLINE TypeCode GetSizeModifier (const Type* T)
|
|
||||||
/* Get the size modifier of a type */
|
|
||||||
{
|
|
||||||
return (GetUnderlyingTypeCode (T) & T_MASK_SIZE);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define GetSizeModifier(T) (GetUnderlyingTypeCode (T) & T_MASK_SIZE)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
/*****************************************************************************/
|
||||||
INLINE TypeCode GetQualifier (const Type* T)
|
/* Qualifier helpers */
|
||||||
/* Get the qualifier from the given type string */
|
/*****************************************************************************/
|
||||||
{
|
|
||||||
return (T->C & T_MASK_QUAL);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define GetQualifier(T) ((T)->C & T_MASK_QUAL)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
INLINE int IsQualConst (const Type* T)
|
INLINE int IsQualConst (const Type* T)
|
||||||
@@ -897,6 +920,37 @@ INLINE int IsQualCConv (const Type* T)
|
|||||||
# define IsQualCConv(T) (((T)->C & T_QUAL_CCONV) != 0)
|
# define IsQualCConv(T) (((T)->C & T_QUAL_CCONV) != 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
TypeCode AddrSizeQualifier (unsigned AddrSize);
|
||||||
|
/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the address size */
|
||||||
|
|
||||||
|
#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 AddrSizeQualifier (DataAddrSize);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define DataAddrSizeQualifier() (AddrSizeQualifier (DataAddrSize))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Function type helpers */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int IsVariadicFunc (const Type* T) attribute ((const));
|
int IsVariadicFunc (const Type* T) attribute ((const));
|
||||||
/* Return true if this is a function type or pointer to function type with
|
/* Return true if this is a function type or pointer to function type with
|
||||||
** variable parameter list.
|
** variable parameter list.
|
||||||
@@ -924,6 +978,14 @@ Type* GetFuncReturnModifiable (Type* T) attribute ((const));
|
|||||||
const FuncDesc* GetFuncDefinitionDesc (const Type* T) attribute ((const));
|
const FuncDesc* GetFuncDefinitionDesc (const Type* T) attribute ((const));
|
||||||
/* Get the function descriptor of the function definition */
|
/* Get the function descriptor of the function definition */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Array type helpers */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
long GetElementCount (const Type* T);
|
long GetElementCount (const Type* T);
|
||||||
/* Get the element count of the array specified in T (which must be of
|
/* Get the element count of the array specified in T (which must be of
|
||||||
** array type).
|
** array type).
|
||||||
@@ -943,6 +1005,14 @@ const Type* GetBaseElementType (const Type* T);
|
|||||||
** the element type that is not an array.
|
** the element type that is not an array.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* ESU types helpers */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct SymEntry* GetESUTagSym (const Type* T) attribute ((const));
|
struct SymEntry* GetESUTagSym (const Type* T) attribute ((const));
|
||||||
/* Get the tag symbol entry of the enum/struct/union type.
|
/* Get the tag symbol entry of the enum/struct/union type.
|
||||||
** Return 0 if it is not an enum/struct/union.
|
** Return 0 if it is not an enum/struct/union.
|
||||||
@@ -951,41 +1021,30 @@ struct SymEntry* GetESUTagSym (const Type* T) attribute ((const));
|
|||||||
void SetESUTagSym (Type* T, struct SymEntry* S);
|
void SetESUTagSym (Type* T, struct SymEntry* S);
|
||||||
/* Set the tag symbol entry of the enum/struct/union type */
|
/* Set the tag symbol entry of the enum/struct/union type */
|
||||||
|
|
||||||
TypeCode AddrSizeQualifier (unsigned AddrSize);
|
|
||||||
/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the address size */
|
|
||||||
|
|
||||||
#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)
|
/* Helpers */
|
||||||
/* Return T_QUAL_NEAR or T_QUAL_FAR depending on the data address size */
|
/*****************************************************************************/
|
||||||
{
|
|
||||||
return AddrSizeQualifier (DataAddrSize);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define DataAddrSizeQualifier() (AddrSizeQualifier (DataAddrSize))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int TypeHasAttr (const Type* T);
|
|
||||||
/* Return true if the given type has attribute data */
|
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
|
||||||
INLINE void CopyTypeAttr (const Type* Src, Type* Dest)
|
const char* GetBasicTypeName (const Type* T);
|
||||||
/* Copy attribute data from Src to Dest */
|
/* Return a const name string of the basic type.
|
||||||
{
|
** Return "type" for unknown basic types.
|
||||||
Dest->A = Src->A;
|
*/
|
||||||
}
|
|
||||||
#else
|
const char* GetFullTypeName (const Type* T);
|
||||||
# define CopyTypeAttr(Src, Dest) ((Dest)->A = (Src)->A)
|
/* Return the full name string of the given type */
|
||||||
#endif
|
|
||||||
|
struct StrBuf* GetFullTypeNameBuf (struct StrBuf* S, const Type* T);
|
||||||
|
/* Return the full name string of the given type */
|
||||||
|
|
||||||
|
int GetQualifierTypeCodeNameBuf (struct StrBuf* S, TypeCode Qual, TypeCode IgnoredQual);
|
||||||
|
/* Return the names of the qualifiers of the type.
|
||||||
|
** Qualifiers to be ignored can be specified with the IgnoredQual flags.
|
||||||
|
** Return the count of added qualifier names.
|
||||||
|
*/
|
||||||
|
|
||||||
void PrintType (FILE* F, const Type* T);
|
void PrintType (FILE* F, const Type* T);
|
||||||
/* Print fulle name of the type */
|
/* Print fulle name of the type */
|
||||||
|
|||||||
@@ -103,6 +103,100 @@ unsigned GlobalModeFlags (const ExprDesc* Expr)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static unsigned TypeOfBySize (unsigned Size)
|
||||||
|
/* Get the code generator replacement type of the object by its size */
|
||||||
|
{
|
||||||
|
unsigned NewType;
|
||||||
|
/* If the size is less than or equal to that of a a long, we will copy
|
||||||
|
** the struct using the primary register, otherwise we use memcpy.
|
||||||
|
*/
|
||||||
|
switch (Size) {
|
||||||
|
case 1: NewType = CF_CHAR; break;
|
||||||
|
case 2: NewType = CF_INT; break;
|
||||||
|
case 3: /* FALLTHROUGH */
|
||||||
|
case 4: NewType = CF_LONG; break;
|
||||||
|
default: NewType = CF_NONE; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NewType;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
unsigned TypeOf (const Type* T)
|
||||||
|
/* Get the code generator base type of the object */
|
||||||
|
{
|
||||||
|
unsigned NewType;
|
||||||
|
|
||||||
|
switch (GetUnderlyingTypeCode (T)) {
|
||||||
|
|
||||||
|
case T_SCHAR:
|
||||||
|
return CF_CHAR;
|
||||||
|
|
||||||
|
case T_UCHAR:
|
||||||
|
return CF_CHAR | CF_UNSIGNED;
|
||||||
|
|
||||||
|
case T_SHORT:
|
||||||
|
case T_INT:
|
||||||
|
return CF_INT;
|
||||||
|
|
||||||
|
case T_USHORT:
|
||||||
|
case T_UINT:
|
||||||
|
case T_PTR:
|
||||||
|
case T_ARRAY:
|
||||||
|
return CF_INT | CF_UNSIGNED;
|
||||||
|
|
||||||
|
case T_LONG:
|
||||||
|
return CF_LONG;
|
||||||
|
|
||||||
|
case T_ULONG:
|
||||||
|
return CF_LONG | CF_UNSIGNED;
|
||||||
|
|
||||||
|
case T_FLOAT:
|
||||||
|
case T_DOUBLE:
|
||||||
|
/* These two are identical in the backend */
|
||||||
|
return CF_FLOAT;
|
||||||
|
|
||||||
|
case T_FUNC:
|
||||||
|
/* Treat this as a function pointer */
|
||||||
|
return CF_INT | CF_UNSIGNED;
|
||||||
|
|
||||||
|
case T_STRUCT:
|
||||||
|
case T_UNION:
|
||||||
|
NewType = TypeOfBySize (SizeOf (T));
|
||||||
|
if (NewType != CF_NONE) {
|
||||||
|
return NewType;
|
||||||
|
}
|
||||||
|
/* Address of ... */
|
||||||
|
return CF_INT | CF_UNSIGNED;
|
||||||
|
|
||||||
|
case T_VOID:
|
||||||
|
case T_ENUM:
|
||||||
|
/* Incomplete enum type */
|
||||||
|
Error ("Incomplete type '%s'", GetFullTypeName (T));
|
||||||
|
return CF_INT;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Error ("Illegal type %04lX", T->C);
|
||||||
|
return CF_INT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
unsigned FuncTypeOf (const Type* T)
|
||||||
|
/* Get the code generator flag for calling the function */
|
||||||
|
{
|
||||||
|
if (GetUnderlyingTypeCode (T) == T_FUNC) {
|
||||||
|
return (T->A.F->Flags & FD_VARIADIC) ? 0 : CF_FIXARGC;
|
||||||
|
} else {
|
||||||
|
Error ("Illegal function type %04lX", T->C);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ExprWithCheck (void (*Func) (ExprDesc*), ExprDesc* Expr)
|
void ExprWithCheck (void (*Func) (ExprDesc*), ExprDesc* Expr)
|
||||||
/* Call an expression function with checks. */
|
/* Call an expression function with checks. */
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -51,6 +51,12 @@ typedef struct GenDesc {
|
|||||||
unsigned GlobalModeFlags (const ExprDesc* Expr);
|
unsigned GlobalModeFlags (const ExprDesc* Expr);
|
||||||
/* Return the addressing mode flags for the given expression */
|
/* Return the addressing mode flags for the given expression */
|
||||||
|
|
||||||
|
unsigned TypeOf (const Type* T);
|
||||||
|
/* Get the code generator base type of the object */
|
||||||
|
|
||||||
|
unsigned FuncTypeOf (const Type* T);
|
||||||
|
/* Get the code generator flag for calling the function */
|
||||||
|
|
||||||
void ExprWithCheck (void (*Func) (ExprDesc*), ExprDesc* Expr);
|
void ExprWithCheck (void (*Func) (ExprDesc*), ExprDesc* Expr);
|
||||||
/* Call an expression function with checks. */
|
/* Call an expression function with checks. */
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
#include "asmlabel.h"
|
#include "asmlabel.h"
|
||||||
#include "codegen.h"
|
#include "codegen.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
#include "expr.h"
|
||||||
#include "funcdesc.h"
|
#include "funcdesc.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "litpool.h"
|
#include "litpool.h"
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
/* cc65 */
|
/* cc65 */
|
||||||
#include "codegen.h"
|
#include "codegen.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
#include "expr.h"
|
||||||
#include "exprdesc.h"
|
#include "exprdesc.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "loadexpr.h"
|
#include "loadexpr.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user