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
46#include <direct.h> /* getcwd */46#include <direct.h> /* getcwd */
47#define inline __inline47#define inline __inline
48#define inp next_inp48#define inp next_inp
49#ifdef _MSC_VER
50#define __aligned(n) __declspec(align(n))
51#endif
52#ifdef _WIN6449#ifdef _WIN64
53#define uplong unsigned long long50#define uplong unsigned long long
54#endif51#endif
@@ -67,10 +64,6 @@ · 12 unmodified lines
67#define uplong unsigned long64#define uplong unsigned long
68#endif65#endif
69 66
70#ifndef __aligned
71#define __aligned(n) __attribute__((aligned(n)))
72#endif
73
74#ifndef PAGESIZE67#ifndef PAGESIZE
75#define PAGESIZE 409668#define PAGESIZE 4096
76#endif69#endif
@@ -263,26 +256,25 @@ typedef struct DLLReference { · 186 unmodified lines
263 256
264/* GNUC attribute definition */257/* GNUC attribute definition */
265typedef struct AttributeDef {258typedef struct AttributeDef {
266 int aligned;259 unsigned
267 int packed; 260 packed : 1,
268 Section *section;261 aligned : 5, /* alignement (0..16) */
269 int func_attr; /* calling convention, exports, ... */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;
270} AttributeDef;267} AttributeDef;
271 268
272/* -------------------------------------------------- */
273/* gr: wrappers for casting sym->r for other purposes */269/* gr: wrappers for casting sym->r for other purposes */
274typedef struct {270#define FUNC_CALL(r) (((AttributeDef*)&(r))->func_call)
275 unsigned271#define FUNC_EXPORT(r) (((AttributeDef*)&(r))->func_export)
276 func_call : 8,272#define FUNC_IMPORT(r) (((AttributeDef*)&(r))->func_import)
277 func_args : 8,273#define FUNC_ARGS(r) (((AttributeDef*)&(r))->func_args)
278 func_export : 1,274#define FUNC_ALIGN(r) (((AttributeDef*)&(r))->aligned)
279 func_import : 1;275#define FUNC_PACKED(r) (((AttributeDef*)&(r))->packed)
280} func_attr_t;276#define INT_ATTR(ad) (*(int*)(ad))
281 277
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)
286/* -------------------------------------------------- */278/* -------------------------------------------------- */
287 279
288#define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */280#define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
@@ -480,9 +472,6 @@ struct TCCState { · 191 unmodified lines
480 void *error_opaque;472 void *error_opaque;
481 void (*error_func)(void *opaque, const char *msg);473 void (*error_func)(void *opaque, const char *msg);
482 int error_set_jmp_enabled;474 int error_set_jmp_enabled;
483#ifdef _WIN64
484 __aligned(16)
485#endif
486 jmp_buf error_jmp_buf;475 jmp_buf error_jmp_buf;
487 int nb_errors;476 int nb_errors;
488 477
tccgen.c+19−12
@@ -2230,12 +2230,12 @@ static void parse_attribute(AttributeDef *ad) · 2229 unmodified lines
2230 case TOK_CDECL1:2230 case TOK_CDECL1:
2231 case TOK_CDECL2:2231 case TOK_CDECL2:
2232 case TOK_CDECL3:2232 case TOK_CDECL3:
2233 FUNC_CALL(ad->func_attr) = FUNC_CDECL;2233 ad->func_call = FUNC_CDECL;
2234 break;2234 break;
2235 case TOK_STDCALL1:2235 case TOK_STDCALL1:
2236 case TOK_STDCALL2:2236 case TOK_STDCALL2:
2237 case TOK_STDCALL3:2237 case TOK_STDCALL3:
2238 FUNC_CALL(ad->func_attr) = FUNC_STDCALL;2238 ad->func_call = FUNC_STDCALL;
2239 break;2239 break;
2240#ifdef TCC_TARGET_I3862240#ifdef TCC_TARGET_I386
2241 case TOK_REGPARM1:2241 case TOK_REGPARM1:
@@ -2247,20 +2247,20 @@ static void parse_attribute(AttributeDef *ad) · 5 unmodified lines
2247 else if (n < 0)2247 else if (n < 0)
2248 n = 0;2248 n = 0;
2249 if (n > 0)2249 if (n > 0)
2250 FUNC_CALL(ad->func_attr) = FUNC_FASTCALL1 + n - 1;2250 ad->func_call = FUNC_FASTCALL1 + n - 1;
2251 skip(')');2251 skip(')');
2252 break;2252 break;
2253 case TOK_FASTCALL1:2253 case TOK_FASTCALL1:
2254 case TOK_FASTCALL2:2254 case TOK_FASTCALL2:
2255 case TOK_FASTCALL3:2255 case TOK_FASTCALL3:
2256 FUNC_CALL(ad->func_attr) = FUNC_FASTCALLW;2256 ad->func_call = FUNC_FASTCALLW;
2257 break; 2257 break;
2258#endif2258#endif
2259 case TOK_DLLEXPORT:2259 case TOK_DLLEXPORT:
2260 FUNC_EXPORT(ad->func_attr) = 1;2260 ad->func_export = 1;
2261 break;2261 break;
2262 case TOK_DLLIMPORT:2262 case TOK_DLLIMPORT:
2263 FUNC_IMPORT(ad->func_attr) = 1;2263 ad->func_import = 1;
2264 break;2264 break;
2265 default:2265 default:
2266 if (tcc_state->warn_unsupported)2266 if (tcc_state->warn_unsupported)
@@ -2646,6 +2646,14 @@ static int parse_btype(CType *type, AttributeDef *ad) · 379 unmodified lines
2646 typedef_found = 1;2646 typedef_found = 1;
2647 t |= (s->type.t & ~VT_TYPEDEF);2647 t |= (s->type.t & ~VT_TYPEDEF);
2648 type->ref = s->type.ref;2648 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 }
2649 next();2657 next();
2650 typespec_found = 1;2658 typespec_found = 1;
2651 break;2659 break;
@@ -2751,8 +2759,8 @@ static void post_type(CType *type, AttributeDef *ad) · 99 unmodified lines
2751 type->t &= ~(VT_STORAGE | VT_CONSTANT); 2759 type->t &= ~(VT_STORAGE | VT_CONSTANT);
2752 post_type(type, ad);2760 post_type(type, ad);
2753 /* we push a anonymous symbol which will contain the function prototype */2761 /* we push a anonymous symbol which will contain the function prototype */
2754 FUNC_ARGS(ad->func_attr) = arg_size;2762 ad->func_args = arg_size;
2755 s = sym_push(SYM_FIELD, type, ad->func_attr, l);2763 s = sym_push(SYM_FIELD, type, INT_ATTR(ad), l);
2756 s->next = first;2764 s->next = first;
2757 type->t = t1 | VT_FUNC;2765 type->t = t1 | VT_FUNC;
2758 type->ref = s;2766 type->ref = s;
@@ -5115,13 +5123,12 @@ static void decl(int l) · 2356 unmodified lines
5115 if (btype.t & VT_TYPEDEF) {5123 if (btype.t & VT_TYPEDEF) {
5116 /* save typedefed type */5124 /* save typedefed type */
5117 /* XXX: test storage specifiers ? */5125 /* XXX: test storage specifiers ? */
5118 sym = sym_push(v, &type, 0, 0);5126 sym = sym_push(v, &type, INT_ATTR(&ad), 0);
5119 sym->type.t |= VT_TYPEDEF;5127 sym->type.t |= VT_TYPEDEF;
5120 } else if ((type.t & VT_BTYPE) == VT_FUNC) {5128 } else if ((type.t & VT_BTYPE) == VT_FUNC) {
5121 /* external function definition */5129 /* external function definition */
5122 /* specific case for func_call attribute */5130 /* specific case for func_call attribute */
5123 if (ad.func_attr)5131 type.ref->r = INT_ATTR(&ad);
5124 type.ref->r = ad.func_attr;
5125 external_sym(v, &type, 0);5132 external_sym(v, &type, 0);
5126 } else {5133 } else {
5127 /* not lvalue if array */5134 /* not lvalue if array */
@@ -5137,7 +5144,7 @@ static void decl(int l) · 9 unmodified lines
5137 arrays of null size are considered as5144 arrays of null size are considered as
5138 extern */5145 extern */
5139#ifdef TCC_TARGET_PE5146#ifdef TCC_TARGET_PE
5140 if (FUNC_IMPORT(ad.func_attr))5147 if (ad.func_import)
5141 type.t |= VT_IMPORT;5148 type.t |= VT_IMPORT;
5142#endif5149#endif
5143 external_sym(v, &type, r);5150 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