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
25412541 case TOK_ERROR:
25422542 case TOK_WARNING:
25432543 c = tok;
2544+ ch = file->buf_ptr[0];
25442545 skip_spaces();
25452546 q = buf;
25462547 while (ch != '\n' && ch != CH_EOF) {
@@ -5567,12 +5568,16 @@ void parse_attribute(AttributeDef *ad) · 3020 unmodified lines
55675568 break;
55685569 case TOK_ALIGNED:
55695570 case TOK___ALIGNED__:
5570− skip('(');
5571− n = expr_const();
5572− if (n <= 0 || (n & (n - 1)) != 0)
5573− error("alignment must be a positive power of two");
5571+ if (tok == '(') {
5572+ next();
5573+ n = expr_const();
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+ }
55745580 ad->aligned = n;
5575− skip(')');
55765581 break;
55775582 case TOK_UNUSED:
55785583 case TOK___UNUSED__:
@@ -7263,8 +7268,9 @@ static void decl_designator(CType *type, Section *sec, unsigned long c, · 1684 unmodified lines
72637268 static void init_putv(CType *type, Section *sec, unsigned long c,
72647269 int v, int expr_type)
72657270 {
7266− int saved_global_expr, bt;
7271+ int saved_global_expr, bt, bit_pos, bit_size;
72677272 void *ptr;
7273+ unsigned long long bit_mask;
72687274
72697275 switch(expr_type) {
72707276 case EXPR_VAL:
@@ -7291,19 +7297,30 @@ static void init_putv(CType *type, Section *sec, unsigned long c, · 20 unmodified lines
72917297 gen_assign_cast(type);
72927298 bt = type->t & VT_BTYPE;
72937299 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+ }
72947310 if ((vtop->r & VT_SYM) &&
72957311 (bt == VT_BYTE ||
72967312 bt == VT_SHORT ||
72977313 bt == VT_DOUBLE ||
72987314 bt == VT_LDOUBLE ||
7299− bt == VT_LLONG))
7315+ bt == VT_LLONG ||
7316+ (bt == VT_INT && bit_size != 32)))
73007317 error("initializer element is not computable at load time");
73017318 switch(bt) {
73027319 case VT_BYTE:
7303− *(char *)ptr = vtop->c.i;
7320+ *(char *)ptr |= (vtop->c.i & bit_mask) << bit_pos;
73047321 break;
73057322 case VT_SHORT:
7306− *(short *)ptr = vtop->c.i;
7323+ *(short *)ptr |= (vtop->c.i & bit_mask) << bit_pos;
73077324 break;
73087325 case VT_DOUBLE:
73097326 *(double *)ptr = vtop->c.d;
@@ -7312,13 +7329,13 @@ static void init_putv(CType *type, Section *sec, unsigned long c, · 2 unmodified lines
73127329 *(long double *)ptr = vtop->c.ld;
73137330 break;
73147331 case VT_LLONG:
7315− *(long long *)ptr = vtop->c.ll;
7332+ *(long long *)ptr |= (vtop->c.ll & bit_mask) << bit_pos;
73167333 break;
73177334 default:
73187335 if (vtop->r & VT_SYM) {
73197336 greloc(sec, vtop->sym, c, R_DATA_32);
73207337 }
7321− *(int *)ptr = vtop->c.i;
7338+ *(int *)ptr |= (vtop->c.i & bit_mask) << bit_pos;
73227339 break;
73237340 }
73247341 vtop--;
@@ -7467,7 +7484,6 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 142 unmodified lines
74677484 /* NOTE: the previous test is a specific case for automatic
74687485 struct/union init */
74697486 /* XXX: union needs only one init */
7470− /* XXX: handle bit fields */
74717487 no_oblock = 1;
74727488 if (first || tok == '{') {
74737489 skip('{');
@@ -7480,8 +7496,6 @@ static void decl_initializer(CType *type, Section *sec, unsigned long c, · 6 unmodified lines
74807496 n = s->c;
74817497 while (tok != '}') {
74827498 decl_designator(type, sec, c, NULL, &f, size_only);
7483− /* XXX: bitfields ? */
7484− /* fill with zero between fields */
74857499 index = f->c;
74867500 if (!size_only && array_length < index) {
74877501 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
74907504 index = index + type_size(&f->type, &align1);
74917505 if (index > array_length)
74927506 array_length = index;
7493− if (no_oblock && f->next == NULL)
7507+ f = f->next;
7508+ if (no_oblock && f == NULL)
74947509 break;
74957510 if (tok == '}')
74967511 break;
74977512 skip(',');
7498− f = f->next;
74997513 }
75007514 /* put zeros at the end */
75017515 if (!size_only && array_length < n) {
@@ -8843,7 +8857,7 @@ static int64_t getclock_us(void) · 1341 unmodified lines
88438857
88448858 void help(void)
88458859 {
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"
88478861 "usage: tcc [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym]\n"
88488862 " [-g] [-b] [-bt N] [-Ldir] [-llib] [-shared] [-static]\n"
88498863 " [--] 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