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