/* */
/* */
/* */
-/* (C) 1998-2006 Ullrich von Bassewitz */
-/* Römerstrasse 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 */
/* common */
#include "attrib.h"
#include "inline.h"
+#include "mmodel.h"
/* cc65 */
#include "funcdesc.h"
/* Basic data types */
enum {
- T_END = 0x0000,
+ T_END = 0x000000,
/* Basic types */
- T_TYPE_NONE = 0x0000,
- T_TYPE_CHAR = 0x0001,
- T_TYPE_SHORT = 0x0002,
- T_TYPE_INT = 0x0003,
- T_TYPE_LONG = 0x0004,
- T_TYPE_LONGLONG = 0x0005,
- T_TYPE_ENUM = 0x0006,
- T_TYPE_FLOAT = 0x0007,
- T_TYPE_DOUBLE = 0x0008,
- T_TYPE_VOID = 0x0009,
- T_TYPE_STRUCT = 0x000A,
- T_TYPE_UNION = 0x000B,
- T_TYPE_ARRAY = 0x000C,
- T_TYPE_PTR = 0x000D,
- T_TYPE_FUNC = 0x000E,
- T_MASK_TYPE = 0x001F,
+ T_TYPE_NONE = 0x000000,
+ T_TYPE_CHAR = 0x000001,
+ T_TYPE_SHORT = 0x000002,
+ T_TYPE_INT = 0x000003,
+ T_TYPE_LONG = 0x000004,
+ T_TYPE_LONGLONG = 0x000005,
+ T_TYPE_ENUM = 0x000006,
+ T_TYPE_FLOAT = 0x000007,
+ T_TYPE_DOUBLE = 0x000008,
+ T_TYPE_VOID = 0x000009,
+ T_TYPE_STRUCT = 0x00000A,
+ T_TYPE_UNION = 0x00000B,
+ T_TYPE_ARRAY = 0x00000C,
+ T_TYPE_PTR = 0x00000D,
+ T_TYPE_FUNC = 0x00000E,
+ T_MASK_TYPE = 0x00000F,
/* Type classes */
- T_CLASS_NONE = 0x0000,
- T_CLASS_INT = 0x0020,
- T_CLASS_FLOAT = 0x0040,
- T_CLASS_PTR = 0x0060,
- T_CLASS_STRUCT = 0x0080,
- T_CLASS_FUNC = 0x00A0,
- T_MASK_CLASS = 0x00E0,
+ T_CLASS_NONE = 0x000000,
+ T_CLASS_INT = 0x000010,
+ T_CLASS_FLOAT = 0x000020,
+ T_CLASS_PTR = 0x000030,
+ T_CLASS_STRUCT = 0x000040,
+ T_CLASS_FUNC = 0x000050,
+ T_MASK_CLASS = 0x000070,
/* Type signedness */
- T_SIGN_NONE = 0x0000,
- T_SIGN_UNSIGNED = 0x0100,
- T_SIGN_SIGNED = 0x0200,
- T_MASK_SIGN = 0x0300,
+ T_SIGN_NONE = 0x000000,
+ T_SIGN_UNSIGNED = 0x000080,
+ T_SIGN_SIGNED = 0x000100,
+ T_MASK_SIGN = 0x000180,
/* Type size modifiers */
- T_SIZE_NONE = 0x0000,
- T_SIZE_SHORT = 0x0400,
- T_SIZE_LONG = 0x0800,
- T_SIZE_LONGLONG = 0x0C00,
- T_MASK_SIZE = 0x0C00,
+ T_SIZE_NONE = 0x000000,
+ T_SIZE_SHORT = 0x000200,
+ T_SIZE_LONG = 0x000400,
+ T_SIZE_LONGLONG = 0x000600,
+ T_MASK_SIZE = 0x000600,
/* Type qualifiers */
- T_QUAL_NONE = 0x0000,
- T_QUAL_CONST = 0x1000,
- T_QUAL_VOLATILE = 0x2000,
- T_QUAL_RESTRICT = 0x4000,
- T_MASK_QUAL = 0x7000,
+ T_QUAL_NONE = 0x000000,
+ T_QUAL_CONST = 0x000800,
+ T_QUAL_VOLATILE = 0x001000,
+ T_QUAL_RESTRICT = 0x002000,
+ T_QUAL_NEAR = 0x004000,
+ T_QUAL_FAR = 0x008000,
+ T_QUAL_ADDRSIZE = T_QUAL_NEAR | T_QUAL_FAR,
+ T_QUAL_FASTCALL = 0x010000,
+ 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,
#define UNSPECIFIED -1L /* Element count was not specified */
#define FLEXIBLE 0L /* Flexible array struct member */
-/* Sizes */
-#define SIZEOF_CHAR 1
-#define SIZEOF_SHORT 2
-#define SIZEOF_INT 2
-#define SIZEOF_LONG 4
-#define SIZEOF_LONGLONG 8
-#define SIZEOF_FLOAT 4
-#define SIZEOF_DOUBLE 4
-#define SIZEOF_PTR 2
+/* Sizes. Floating point sizes come from fp.h */
+#define SIZEOF_CHAR 1U
+#define SIZEOF_SHORT 2U
+#define SIZEOF_INT 2U
+#define SIZEOF_LONG 4U
+#define SIZEOF_LONGLONG 8U
+#define SIZEOF_FLOAT (FP_F_Size())
+#define SIZEOF_DOUBLE (FP_D_Size())
+#define SIZEOF_PTR SIZEOF_INT
+
+/* Bit sizes */
+#define CHAR_BITS (8 * SIZEOF_CHAR)
+#define SHORT_BITS (8 * SIZEOF_SHORT)
+#define INT_BITS (8 * SIZEOF_INT)
+#define LONG_BITS (8 * SIZEOF_LONG)
+#define LONGLONG_BITS (8 * SIZEOF_LONGLONG)
+#define FLOAT_BITS (8 * SIZEOF_FLOAT)
+#define DOUBLE_BITS (8 * SIZEOF_DOUBLE)
+#define PTR_BITS (8 * SIZEOF_PTR)
/* Predefined type strings */
extern Type type_schar[];
unsigned TypeLen (const Type* T);
/* 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 */
Type* TypeDup (const Type* T);
* given type points to.
*/
-Type* ArrayToPtr (const Type* T);
+Type* ArrayToPtr (Type* T);
/* Convert an array to a pointer to it's first element */
#if defined(HAVE_INLINE)
# define IsSignUnsigned(T) (GetSignedness (T) == T_SIGN_UNSIGNED)
#endif
-TypeCode GetQualifier (const Type* T) attribute ((const));
+#if defined(HAVE_INLINE)
+INLINE int IsSignSigned (const Type* T)
+/* Return true if this is a signed type */
+{
+ return (GetSignedness (T) == T_SIGN_SIGNED);
+}
+#else
+# define IsSignSigned(T) (GetSignedness (T) == T_SIGN_SIGNED)
+#endif
+
+#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
#if defined(HAVE_INLINE)
INLINE int IsQualConst (const Type* T)
/* Return true if the given type has a const memory image */
{
- return (GetQualifier (T) & T_QUAL_CONST) != 0;
+ return (T->C & T_QUAL_CONST) != 0;
}
#else
-# define IsQualConst(T) (GetQualifier (T) & T_QUAL_CONST) != 0)
+# define IsQualConst(T) (((T)->C & T_QUAL_CONST) != 0)
#endif
#if defined(HAVE_INLINE)
INLINE int IsQualVolatile (const Type* T)
/* Return true if the given type has a volatile type qualifier */
{
- return (GetQualifier (T) & T_QUAL_VOLATILE) != 0;
+ return (T->C & T_QUAL_VOLATILE) != 0;
}
#else
-# define IsQualVolatile(T) (GetQualifier (T) & T_QUAL_VOLATILE) != 0)
+# define IsQualVolatile(T) (((T)->C & T_QUAL_VOLATILE) != 0)
#endif
#if defined(HAVE_INLINE)
INLINE int IsQualRestrict (const Type* T)
/* Return true if the given type has a restrict qualifier */
{
- return (GetQualifier (T) & T_QUAL_RESTRICT) != 0;
+ return (T->C & T_QUAL_RESTRICT) != 0;
}
#else
-# define IsQualRestrict(T) (GetQualifier (T) & T_QUAL_RESTRICT) != 0)
+# define IsQualRestrict(T) (((T)->C & T_QUAL_RESTRICT) != 0)
#endif
-int IsFastCallFunc (const Type* T) attribute ((const));
-/* Return true if this is a function type or pointer to function with
- * __fastcall__ calling conventions
- */
+#if defined(HAVE_INLINE)
+INLINE int IsQualNear (const Type* T)
+/* Return true if the given type has a near qualifier */
+{
+ return (T->C & T_QUAL_NEAR) != 0;
+}
+#else
+# define IsQualNear(T) (((T)->C & T_QUAL_NEAR) != 0)
+#endif
+
+#if defined(HAVE_INLINE)
+INLINE int IsQualFar (const Type* T)
+/* Return true if the given type has a far qualifier */
+{
+ return (T->C & T_QUAL_FAR) != 0;
+}
+#else
+# define IsQualFar(T) (((T)->C & T_QUAL_FAR) != 0)
+#endif
+
+#if defined(HAVE_INLINE)
+INLINE int IsQualFastcall (const Type* T)
+/* Return true if the given type has a fastcall qualifier */
+{
+ return (T->C & T_QUAL_FASTCALL) != 0;
+}
+#else
+# 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
* return T.
*/
+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
+
/* End of datatype.h */