History

added static bit fields init - version change - #error and #warning fix - support aligned attribute without parameter

bellard committed 23 years ago

Commit abf909e1 parent 2ec23ab1 file · +31 −17Browse files

Unified · Split

tcc.c+31−17
@@ -2541,6 +2541,7 @@ static void preprocess(int is_bof) · 2540 unmodified lines
2541 case TOK_ERROR:2541 case TOK_ERROR:
2542 case TOK_WARNING:2542 case TOK_WARNING:
2543 c = tok;2543 c = tok;
2544 ch = file->buf_ptr[0];
2544 skip_spaces();2545 skip_spaces();
2545 q = buf;2546 q = buf;
2546 while (ch != '\n' && ch != CH_EOF) {2547 while (ch != '\n' && ch != CH_EOF) {
@@ -5567,12 +5568,16 @@ void parse_attribute(AttributeDef *ad) · 3020 unmodified lines
5567 break;5568 break;
5568 case TOK_ALIGNED:5569 case TOK_ALIGNED:
5569 case TOK___ALIGNED__:5570 case TOK___ALIGNED__:
5570 skip('(');5571 if (tok == '(') {
5571 n = expr_const();5572 next();
5572 if (n <= 0 || (n & (n - 1)) != 0) 5573 n = expr_const();
5573 error("alignment must be a positive power of two");5574 if (n <= 0 || (n & (n - 1)) != 0)
5575 error("alignment must be a positive power of two");
5576 skip(')');
5577 } else {
5578 n = MAX_ALIGN;
5579 }
5574 ad->aligned = n;5580 ad->aligned = n;
5575 skip(')');
5576 break;5581 break;
5577 case TOK_UNUSED:5582 case TOK_UNUSED:
5578 case TOK___UNUSED__:5583 case TOK___UNUSED__:
@@ -7263,8 +7268,9 @@ static void decl_designator(CType *type, Section *sec, unsigned long c, · 1684 unmodified lines
7263static void init_putv(CType *type, Section *sec, unsigned long c, 7268static void init_putv(CType *type, Section *sec, unsigned long c,
7264 int v, int expr_type)7269 int v, int expr_type)
7265{7270{
7266 int saved_global_expr, bt;7271 int saved_global_expr, bt, bit_pos, bit_size;
7267 void *ptr;7272 void *ptr;
7273 unsigned long long bit_mask;
7268 7274
7269 switch(expr_type) {7275 switch(expr_type) {
7270 case EXPR_VAL:7276 case EXPR_VAL:
@@ -7291,19 +7297,30 @@ static void init_putv(CType *type, Section *sec, unsigned long c, · 20 unmodified lines
7291 gen_assign_cast(type);7297 gen_assign_cast(type);
7292 bt = type->t & VT_BTYPE;7298 bt = type->t & VT_BTYPE;
7293 ptr = sec->data + c;7299 ptr = sec->data + c;
7300 /* XXX: make code faster ? */
7301 if (!(type->t & VT_BITFIELD)) {
7302 bit_pos = 0;
7303 bit_size = 32;
7304 bit_mask = -1LL;
7305 } else {
7306 bit_pos = (vtop->type.t >> VT_STRUCT_SHIFT) & 0x3f;
7307 bit_size = (vtop->type.t >> (VT_STRUCT_SHIFT + 6)) & 0x3f;
7308 bit_mask = (1LL << bit_size) - 1;
7309 }
7294 if ((vtop->r & VT_SYM) &&7310 if ((vtop->r & VT_SYM) &&
7295 (bt == VT_BYTE ||7311 (bt == VT_BYTE ||
7296 bt == VT_SHORT ||7312 bt == VT_SHORT ||
7297 bt == VT_DOUBLE ||7313 bt == VT_DOUBLE ||
7298 bt == VT_LDOUBLE ||7314 bt == VT_LDOUBLE ||
7299 bt == VT_LLONG))7315 bt == VT_LLONG ||
7316 (bt == VT_INT && bit_size != 32)))
7300 error("initializer element is not computable at load time");7317 error("initializer element is not computable at load time");
7301 switch(bt) {7318 switch(bt) {
7302 case VT_BYTE:7319 case VT_BYTE:
7303 *(char *)ptr = vtop->c.i;7320 *(char *)ptr |= (vtop->c.i & bit_mask) << bit_pos;
7304 break;7321 break;
7305 case VT_SHORT:7322 case VT_SHORT:
7306 *(short *)ptr = vtop->c.i;7323 *(short *)ptr |= (vtop->c.i & bit_mask) << bit_pos;
7307 break;7324 break;
7308 case VT_DOUBLE:7325 case VT_DOUBLE:
7309 *(double *)ptr = vtop->c.d;7326 *(double *)ptr = vtop->c.d;
@@ -7312,13 +7329,13 @@ static void init_putv(CType *type, Section *sec, unsigned long c, · 2 unmodified lines
7312 *(long double *)ptr = vtop->c.ld;7329 *(long double *)ptr = vtop->c.ld;
7313 break;7330 break;
7314 case VT_LLONG:7331 case VT_LLONG:
7315 *(long long *)ptr = vtop->c.ll;7332 *(long long *)ptr |= (vtop->c.ll & bit_mask) << bit_pos;
7316 break;7333 break;
7317 default:7334 default:
7318 if (vtop->r & VT_SYM) {7335 if (vtop->r & VT_SYM) {
7319 greloc(sec, vtop->sym, c, R_DATA_32);7336 greloc(sec, vtop->sym, c, R_DATA_32);
7320 }7337 }
7321 *(int *)ptr = vtop->c.i;7338 *(int *)ptr |= (vtop->c.i & bit_mask) << bit_pos;
7322 break;7339 break;
7323 }7340 }
7324 vtop--;7341 vtop--;
@@ -7467,7 +7484,6 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 142 unmodified lines
7467 /* NOTE: the previous test is a specific case for automatic7484 /* NOTE: the previous test is a specific case for automatic
7468 struct/union init */7485 struct/union init */
7469 /* XXX: union needs only one init */7486 /* XXX: union needs only one init */
7470 /* XXX: handle bit fields */
7471 no_oblock = 1;7487 no_oblock = 1;
7472 if (first || tok == '{') {7488 if (first || tok == '{') {
7473 skip('{');7489 skip('{');
@@ -7480,8 +7496,6 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 6 unmodified lines
7480 n = s->c;7496 n = s->c;
7481 while (tok != '}') {7497 while (tok != '}') {
7482 decl_designator(type, sec, c, NULL, &f, size_only);7498 decl_designator(type, sec, c, NULL, &f, size_only);
7483 /* XXX: bitfields ? */
7484 /* fill with zero between fields */
7485 index = f->c;7499 index = f->c;
7486 if (!size_only && array_length < index) {7500 if (!size_only && array_length < index) {
7487 init_putz(type, sec, c + array_length, 7501 init_putz(type, sec, c + array_length,
@@ -7490,12 +7504,12 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 2 unmodified lines
7490 index = index + type_size(&f->type, &align1);7504 index = index + type_size(&f->type, &align1);
7491 if (index > array_length)7505 if (index > array_length)
7492 array_length = index;7506 array_length = index;
7493 if (no_oblock && f->next == NULL)7507 f = f->next;
7508 if (no_oblock && f == NULL)
7494 break;7509 break;
7495 if (tok == '}')7510 if (tok == '}')
7496 break;7511 break;
7497 skip(',');7512 skip(',');
7498 f = f->next;
7499 }7513 }
7500 /* put zeros at the end */7514 /* put zeros at the end */
7501 if (!size_only && array_length < n) {7515 if (!size_only && array_length < n) {
@@ -8843,7 +8857,7 @@ static int64_t getclock_us(void) · 1341 unmodified lines
8843 8857
8844void help(void)8858void help(void)
8845{8859{
8846 printf("tcc version 0.9.13 - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n" 8860 printf("tcc version 0.9.14 - Tiny C Compiler - Copyright (C) 2001, 2002 Fabrice Bellard\n"
8847 "usage: tcc [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym]\n"8861 "usage: tcc [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym]\n"
8848 " [-g] [-b] [-bt N] [-Ldir] [-llib] [-shared] [-static]\n"8862 " [-g] [-b] [-bt N] [-Ldir] [-llib] [-shared] [-static]\n"
8849 " [--] infile1 [infile2... --] [infile_args...]\n"8863 " [--] infile1 [infile2... --] [infile_args...]\n"

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t