1 /*****************************************************************************/
5 /* Generic data type encoding */
9 /* (C) 2011, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
41 /*****************************************************************************/
43 /*****************************************************************************/
47 /* Termination, so we can use string functions to handle type strings */
50 /* Size of a data type */
51 #define GT_SIZE_1 0x00U
52 #define GT_SIZE_2 0x01U
53 #define GT_SIZE_3 0x02U
54 #define GT_SIZE_4 0x03U
55 #define GT_SIZE_MASK 0x07U
56 #define GT_GET_SIZE(x) (((x) & GT_SIZE_MASK) + 1U)
58 /* Sign of the data type */
59 #define GT_UNSIGNED 0x00U
60 #define GT_SIGNED 0x08U
61 #define GT_SIGN_MASK 0x08U
62 #define GT_HAS_SIGN(x) (((x) & GT_SIZE_MASK) == GT_SIGNED)
65 #define GT_LITTLE_ENDIAN 0x00U
66 #define GT_BIG_ENDIAN 0x10U
67 #define GT_BYTEORDER_MASK 0x10U
68 #define GT_IS_LITTLE_ENDIAN(x) (((x) & GT_BYTEORDER_MASK) == GT_LITTLE_ENDIAN)
69 #define GT_IS_BIG_ENDIAN(x) (((x) & GT_BYTEORDER_MASK) == GT_BIG_ENDIAN)
71 /* Type of the data. Since we want to have zero as a terminator, we must
72 * introduce one thing that cannot be zero for normal data. This is the
75 #define GT_INTEGER 0x20U
76 #define GT_POINTER 0x40U
77 #define GT_FLOAT 0x60U
78 #define GT_ARRAY 0x80U
79 #define GT_FUNCTION 0xA0U
80 #define GT_STRUCT 0xC0U
81 #define GT_UNION 0xE0U
83 #define GT_GET_TYPE(x) ((x) & GT_TYPE_MASK)
84 #define GT_IS_INTEGER(x) (GT_GET_TYPE(x) == GT_INTEGER)
85 #define GT_IS_POINTER(x) (GT_GET_TYPE(x) == GT_POINTER)
86 #define GT_IS_FLOAT(x) (GT_GET_TYPE(x) == GT_FLOAT)
87 #define GT_IS_ARRAY(x) (GT_GET_TYPE(x) == GT_ARRAY)
88 #define GT_IS_FUNCTION(x) (GT_GET_TYPE(x) == GT_FUNCTION)
89 #define GT_IS_STRUCT(x) (GT_GET_TYPE(x) == GT_STRUCT)
90 #define GT_IS_UNION(x) (GT_GET_TYPE(x) == GT_UNION)
92 /* Combined values for the 6502 family */
93 #define GT_BYTE (GT_INTEGER | GT_LITTLE_ENDIAN | GT_UNSIGNED | GT_SIZE_1)
94 #define GT_WORD (GT_INTEGER | GT_LITTLE_ENDIAN | GT_UNSIGNED | GT_SIZE_2)
95 #define GT_DWORD (GT_INTEGER | GT_LITTLE_ENDIAN | GT_UNSIGNED | GT_SIZE_4)
96 #define GT_DBYTE (GT_POINTER | GT_BIG_ENDIAN | GT_UNSIGNED | GT_SIZE_2)
97 #define GT_PTR (GT_POINTER | GT_LITTLE_ENDIAN | GT_UNSIGNED | GT_SIZE_2)
98 #define GT_FAR_PTR (GT_POINTER | GT_LITTLE_ENDIAN | GT_UNSIGNED | GT_SIZE_3)
102 /* End of gentype.h */