History

tccgen: propagate alignment from typedef

Store (part of) the AttributeDef structure in the (int)sym-r field of the typedef symbol (kludgy).

grischka committed 16 years ago

Commit 56d6abd1 parent c0620c82 files · +35 −39Browse files

Unified · Split

2 files
  1. tcc.h +16 −27
  2. tccgen.c +19 −12
tcc.h+16−27
@@ -46,9 +46,6 @@ · 45 unmodified lines
4646 #include <direct.h> /* getcwd */
4747 #define inline __inline
4848 #define inp next_inp
49−#ifdef _MSC_VER
50−#define __aligned(n) __declspec(align(n))
51−#endif
5249 #ifdef _WIN64
5350 #define uplong unsigned long long
5451 #endif
@@ -67,10 +64,6 @@ · 12 unmodified lines
6764 #define uplong unsigned long
6865 #endif
6966
70−#ifndef __aligned
71−#define __aligned(n) __attribute__((aligned(n)))
72−#endif
73−
7467 #ifndef PAGESIZE
7568 #define PAGESIZE 4096
7669 #endif
@@ -263,26 +256,25 @@ typedef struct DLLReference { · 186 unmodified lines
263256
264257 /* GNUC attribute definition */
265258 typedef struct AttributeDef {
266− int aligned;
267− int packed;
268− Section *section;
269− int func_attr; /* calling convention, exports, ... */
259+ unsigned
260+ packed : 1,
261+ aligned : 5, /* alignement (0..16) */
262+ func_call : 3, /* calling convention (0..5), see below */
263+ func_export : 1,
264+ func_import : 1,
265+ func_args : 8;
266+ struct Section *section;
270267 } AttributeDef;
271268
272−/* -------------------------------------------------- */
273269 /* gr: wrappers for casting sym->r for other purposes */
274−typedef struct {
275− unsigned
276− func_call : 8,
277− func_args : 8,
278− func_export : 1,
279− func_import : 1;
280−} func_attr_t;
281−
282−#define FUNC_CALL(r) (((func_attr_t*)&(r))->func_call)
283−#define FUNC_EXPORT(r) (((func_attr_t*)&(r))->func_export)
284−#define FUNC_IMPORT(r) (((func_attr_t*)&(r))->func_import)
285−#define FUNC_ARGS(r) (((func_attr_t*)&(r))->func_args)
270+#define FUNC_CALL(r) (((AttributeDef*)&(r))->func_call)
271+#define FUNC_EXPORT(r) (((AttributeDef*)&(r))->func_export)
272+#define FUNC_IMPORT(r) (((AttributeDef*)&(r))->func_import)
273+#define FUNC_ARGS(r) (((AttributeDef*)&(r))->func_args)
274+#define FUNC_ALIGN(r) (((AttributeDef*)&(r))->aligned)
275+#define FUNC_PACKED(r) (((AttributeDef*)&(r))->packed)
276+#define INT_ATTR(ad) (*(int*)(ad))
277+
286278 /* -------------------------------------------------- */
287279
288280 #define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
@@ -480,9 +472,6 @@ struct TCCState { · 191 unmodified lines
480472 void *error_opaque;
481473 void (*error_func)(void *opaque, const char *msg);
482474 int error_set_jmp_enabled;
483−#ifdef _WIN64
484− __aligned(16)
485−#endif
486475 jmp_buf error_jmp_buf;
487476 int nb_errors;
488477
tccgen.c+19−12
@@ -2230,12 +2230,12 @@ static void parse_attribute(AttributeDef *ad) · 2229 unmodified lines
22302230 case TOK_CDECL1:
22312231 case TOK_CDECL2:
22322232 case TOK_CDECL3:
2233− FUNC_CALL(ad->func_attr) = FUNC_CDECL;
2233+ ad->func_call = FUNC_CDECL;
22342234 break;
22352235 case TOK_STDCALL1:
22362236 case TOK_STDCALL2:
22372237 case TOK_STDCALL3:
2238− FUNC_CALL(ad->func_attr) = FUNC_STDCALL;
2238+ ad->func_call = FUNC_STDCALL;
22392239 break;
22402240 #ifdef TCC_TARGET_I386
22412241 case TOK_REGPARM1:
@@ -2247,20 +2247,20 @@ static void parse_attribute(AttributeDef *ad) · 5 unmodified lines
22472247 else if (n < 0)
22482248 n = 0;
22492249 if (n > 0)
2250− FUNC_CALL(ad->func_attr) = FUNC_FASTCALL1 + n - 1;
2250+ ad->func_call = FUNC_FASTCALL1 + n - 1;
22512251 skip(')');
22522252 break;
22532253 case TOK_FASTCALL1:
22542254 case TOK_FASTCALL2:
22552255 case TOK_FASTCALL3:
2256− FUNC_CALL(ad->func_attr) = FUNC_FASTCALLW;
2256+ ad->func_call = FUNC_FASTCALLW;
22572257 break;
22582258 #endif
22592259 case TOK_DLLEXPORT:
2260− FUNC_EXPORT(ad->func_attr) = 1;
2260+ ad->func_export = 1;
22612261 break;
22622262 case TOK_DLLIMPORT:
2263− FUNC_IMPORT(ad->func_attr) = 1;
2263+ ad->func_import = 1;
22642264 break;
22652265 default:
22662266 if (tcc_state->warn_unsupported)
@@ -2646,6 +2646,14 @@ static int parse_btype(CType *type, AttributeDef *ad) · 379 unmodified lines
26462646 typedef_found = 1;
26472647 t |= (s->type.t & ~VT_TYPEDEF);
26482648 type->ref = s->type.ref;
2649+ if (s->r) {
2650+ /* get attributes from typedef */
2651+ if (0 == ad->aligned)
2652+ ad->aligned = FUNC_ALIGN(s->r);
2653+ if (0 == ad->func_call)
2654+ ad->func_call = FUNC_CALL(s->r);
2655+ ad->packed |= FUNC_PACKED(s->r);
2656+ }
26492657 next();
26502658 typespec_found = 1;
26512659 break;
@@ -2751,8 +2759,8 @@ static void post_type(CType *type, AttributeDef *ad) · 99 unmodified lines
27512759 type->t &= ~(VT_STORAGE | VT_CONSTANT);
27522760 post_type(type, ad);
27532761 /* we push a anonymous symbol which will contain the function prototype */
2754− FUNC_ARGS(ad->func_attr) = arg_size;
2755− s = sym_push(SYM_FIELD, type, ad->func_attr, l);
2762+ ad->func_args = arg_size;
2763+ s = sym_push(SYM_FIELD, type, INT_ATTR(ad), l);
27562764 s->next = first;
27572765 type->t = t1 | VT_FUNC;
27582766 type->ref = s;
@@ -5115,13 +5123,12 @@ static void decl(int l) · 2356 unmodified lines
51155123 if (btype.t & VT_TYPEDEF) {
51165124 /* save typedefed type */
51175125 /* XXX: test storage specifiers ? */
5118− sym = sym_push(v, &type, 0, 0);
5126+ sym = sym_push(v, &type, INT_ATTR(&ad), 0);
51195127 sym->type.t |= VT_TYPEDEF;
51205128 } else if ((type.t & VT_BTYPE) == VT_FUNC) {
51215129 /* external function definition */
51225130 /* specific case for func_call attribute */
5123− if (ad.func_attr)
5124− type.ref->r = ad.func_attr;
5131+ type.ref->r = INT_ATTR(&ad);
51255132 external_sym(v, &type, 0);
51265133 } else {
51275134 /* not lvalue if array */
@@ -5137,7 +5144,7 @@ static void decl(int l) · 9 unmodified lines
51375144 arrays of null size are considered as
51385145 extern */
51395146 #ifdef TCC_TARGET_PE
5140− if (FUNC_IMPORT(ad.func_attr))
5147+ if (ad.func_import)
51415148 type.t |= VT_IMPORT;
51425149 #endif
51435150 external_sym(v, &type, r);

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