scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

arch.c (4718B)


      1 #include <scc/scc.h>
      2 #include "../../cc1.h"
      3 
      4 #define RANK_BOOL    0
      5 #define RANK_SCHAR   1
      6 #define RANK_UCHAR   1
      7 #define RANK_CHAR    1
      8 #define RANK_SHORT   2
      9 #define RANK_USHORT  2
     10 #define RANK_INT     3
     11 #define RANK_UINT    3
     12 #define RANK_LONG    4
     13 #define RANK_ULONG   4
     14 #define RANK_LLONG   5
     15 #define RANK_ULLONG  5
     16 #define RANK_FLOAT   6
     17 #define RANK_DOUBLE  7
     18 #define RANK_LDOUBLE 8
     19 
     20 /*
     21  * Initializaion of type pointers were done with
     22  * a C99 initilizator '... = &(Type) {...', but
     23  * c compiler in Plan9 gives error with this
     24  * syntax, so I have switched it to this ugly form
     25  * I hope I will change it again in the future
     26  */
     27 
     28 static Type types[] = {
     29 	{       /* 0 = voidtype */
     30 		.op = VOID,
     31 		.letter = L_VOID,
     32 	},
     33 	{       /* 1 = pvoidtype */
     34 		.op = PTR,
     35 		.letter = L_POINTER,
     36 		.prop = TDEFINED,
     37 		.type = &types[5],  /* chartype */
     38 		.size = 8,
     39 		.align = 8,
     40 	},
     41 	{      /* 2 = booltype */
     42 		.op = INT,
     43 		.letter = L_BOOL,
     44 		.prop = TDEFINED | TINTEGER | TARITH,
     45 		.size = 1,
     46 		.align = 1,
     47 		.n.rank = RANK_BOOL,
     48 	},
     49 	{       /* 3 = schartype */
     50 		.op = INT,
     51 		.letter = L_INT8,
     52 		.prop = TDEFINED | TINTEGER | TARITH | TSIGNED,
     53 		.size = 1,
     54 		.align = 1,
     55 		.n.rank = RANK_SCHAR,
     56 	},
     57 	{      /* 4 = uchartype */
     58 		.op = INT,
     59 		.letter = L_UINT8,
     60 		.prop = TDEFINED | TINTEGER | TARITH,
     61 		.size = 1,
     62 		.align = 1,
     63 		.n.rank = RANK_UCHAR,
     64 	},
     65 	{      /* 5 = chartype */
     66 		.op = INT,
     67 		.letter = L_INT8,
     68 		.prop = TDEFINED | TINTEGER | TARITH | TSIGNED,
     69 		.size = 1,
     70 		.align = 1,
     71 		.n.rank = RANK_CHAR,
     72 	},
     73 	{       /* 6 = ushortype */
     74 		.op = INT,
     75 		.letter = L_UINT16,
     76 		.prop = TDEFINED | TINTEGER | TARITH,
     77 		.size = 2,
     78 		.align = 2,
     79 		.n.rank = RANK_USHORT,
     80 	},
     81 	{       /* 7 = shortype */
     82 		.op = INT,
     83 		.letter = L_INT16,
     84 		.prop = TDEFINED | TINTEGER | TARITH | TSIGNED,
     85 		.size = 2,
     86 		.align = 2,
     87 		.n.rank = RANK_SHORT,
     88 	},
     89 	{       /* 8 = uinttype */
     90 		.op = INT,
     91 		.letter = L_UINT32,
     92 		.prop = TDEFINED | TINTEGER | TARITH,
     93 		.size = 4,
     94 		.align = 4,
     95 		.n.rank = RANK_UINT,
     96 	},
     97 	{       /* 9 = inttype */
     98 		.op = INT,
     99 		.letter = L_INT32,
    100 		.prop = TDEFINED | TINTEGER | TARITH | TSIGNED,
    101 		.size = 4,
    102 		.align = 4,
    103 		.n.rank = RANK_INT,
    104 	},
    105 	{      /* 10 = longtype */
    106 		.op = INT,
    107 		.letter = L_INT64,
    108 		.prop = TDEFINED | TINTEGER | TARITH | TSIGNED,
    109 		.size = 8,
    110 		.align = 8,
    111 		.n.rank = RANK_LONG,
    112 	},
    113 	{       /* 11 = ulongtype */
    114 		.op = INT,
    115 		.letter = L_UINT64,
    116 		.prop = TDEFINED | TINTEGER | TARITH,
    117 		.size = 8,
    118 		.align = 8,
    119 		.n.rank = RANK_ULONG,
    120 	},
    121 	{	/* 12 = ullongtype */
    122 		.op = INT,
    123 		.letter = L_UINT64,
    124 		.prop = TDEFINED | TINTEGER | TARITH,
    125 		.size = 8,
    126 		.align = 8,
    127 		.n.rank = RANK_ULLONG,
    128 	},
    129 	{       /* 13 = llongtype */
    130 		.op = INT,
    131 		.letter = L_INT64,
    132 		.prop = TDEFINED | TINTEGER | TARITH | TSIGNED,
    133 		.size = 8,
    134 		.align = 8,
    135 		.n.rank = RANK_LLONG,
    136 	},
    137 	{       /* 14 = floattype */
    138 		.op = FLOAT,
    139 		.letter = L_FLOAT,
    140 		.prop = TDEFINED | TARITH,
    141 		.size = 4,
    142 		.align = 4,
    143 		.n.rank = RANK_FLOAT,
    144 	},
    145 	{       /* 15 = doubletype */
    146 		.op = FLOAT,
    147 		.letter = L_DOUBLE,
    148 		.prop = TDEFINED | TARITH,
    149 		.size = 8,
    150 		.align = 8,
    151 		.n.rank = RANK_DOUBLE,
    152 	},
    153 	{       /* 16 = ldoubletype */
    154 		.op = FLOAT,
    155 		.letter = L_LDOUBLE,
    156 		.prop = TDEFINED | TARITH,
    157 		.size = 16,
    158 		.align = 16,
    159 		.n.rank = RANK_LDOUBLE,
    160 	},
    161 	{       /* 17 = sizettype */
    162 		.op = INT,
    163 		.letter = L_UINT64,
    164 		.prop = TDEFINED | TINTEGER | TARITH,
    165 		.size = 8,
    166 		.align = 8,
    167 		.n.rank = RANK_UINT,
    168 	},
    169 	{      /* 18 = ellipsis */
    170 		.op = ELLIPSIS,
    171 		.letter = L_ELLIPSIS,
    172 		.prop = TDEFINED,
    173 	},
    174 	{      /* 19 = pdifftype */
    175 		.op = INT,
    176 		.letter = L_INT64,
    177 		.prop = TDEFINED | TINTEGER | TARITH | TSIGNED,
    178 		.size = 8,
    179 		.align = 8,
    180 		.n.rank = RANK_LONG,
    181 	},
    182 	{      /* 20 = va_type */
    183 		.op = STRUCT,
    184 		.letter = L_VA_ARG,
    185 		.prop = TDEFINED,
    186 		.size = 24,
    187 		.align = 8,
    188 	},
    189 };
    190 
    191 Type *voidtype = &types[0], *pvoidtype = &types[1],
    192      *booltype = &types[2], *schartype = &types[3],
    193      *uchartype = &types[4], *chartype = &types[5],
    194      *ushortype = &types[6], *shortype = &types[7],
    195      *uinttype = &types[8], *inttype = &types[9],
    196      *longtype = &types[10], *ulongtype = &types[11],
    197      *ullongtype = &types[12], *llongtype = &types[13],
    198      *floattype = &types[14], *doubletype = &types[15],
    199      *ldoubletype = &types[16],
    200      *sizettype = &types[17], *pdifftype = &types[19],
    201      *ellipsistype = &types[18], *va_type = &types[20],
    202      *va_list_type;
    203 
    204 static Symbol dummy0 = {.u.i = 0, .type = &types[9]},
    205               dummy1 = {.u.i = 1, .type = &types[9]};
    206 Symbol *zero = &dummy0, *one = &dummy1;
    207 
    208 void
    209 iarch(void)
    210 {
    211 	va_list_type = mktype(va_type, ARY, 1, NULL);
    212 }
    213 
    214 int
    215 valid_va_list(Type *tp)
    216 {
    217 	return tp->op == PTR && eqtype(tp->type, va_type, 1);
    218 }