tccgen: propagate alignment from typedef
Store (part of) the AttributeDef structure in the (int)sym-r field of the typedef symbol (kludgy).
This commit is contained in:
parent
c0620c8a00
commit
56d6abdb3d
2 changed files with 34 additions and 38 deletions
41
tcc.h
41
tcc.h
|
@ -46,9 +46,6 @@
|
||||||
#include <direct.h> /* getcwd */
|
#include <direct.h> /* getcwd */
|
||||||
#define inline __inline
|
#define inline __inline
|
||||||
#define inp next_inp
|
#define inp next_inp
|
||||||
#ifdef _MSC_VER
|
|
||||||
#define __aligned(n) __declspec(align(n))
|
|
||||||
#endif
|
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
#define uplong unsigned long long
|
#define uplong unsigned long long
|
||||||
#endif
|
#endif
|
||||||
|
@ -67,10 +64,6 @@
|
||||||
#define uplong unsigned long
|
#define uplong unsigned long
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __aligned
|
|
||||||
#define __aligned(n) __attribute__((aligned(n)))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef PAGESIZE
|
#ifndef PAGESIZE
|
||||||
#define PAGESIZE 4096
|
#define PAGESIZE 4096
|
||||||
#endif
|
#endif
|
||||||
|
@ -263,26 +256,25 @@ typedef struct DLLReference {
|
||||||
|
|
||||||
/* GNUC attribute definition */
|
/* GNUC attribute definition */
|
||||||
typedef struct AttributeDef {
|
typedef struct AttributeDef {
|
||||||
int aligned;
|
unsigned
|
||||||
int packed;
|
packed : 1,
|
||||||
Section *section;
|
aligned : 5, /* alignement (0..16) */
|
||||||
int func_attr; /* calling convention, exports, ... */
|
func_call : 3, /* calling convention (0..5), see below */
|
||||||
|
func_export : 1,
|
||||||
|
func_import : 1,
|
||||||
|
func_args : 8;
|
||||||
|
struct Section *section;
|
||||||
} AttributeDef;
|
} AttributeDef;
|
||||||
|
|
||||||
/* -------------------------------------------------- */
|
|
||||||
/* gr: wrappers for casting sym->r for other purposes */
|
/* gr: wrappers for casting sym->r for other purposes */
|
||||||
typedef struct {
|
#define FUNC_CALL(r) (((AttributeDef*)&(r))->func_call)
|
||||||
unsigned
|
#define FUNC_EXPORT(r) (((AttributeDef*)&(r))->func_export)
|
||||||
func_call : 8,
|
#define FUNC_IMPORT(r) (((AttributeDef*)&(r))->func_import)
|
||||||
func_args : 8,
|
#define FUNC_ARGS(r) (((AttributeDef*)&(r))->func_args)
|
||||||
func_export : 1,
|
#define FUNC_ALIGN(r) (((AttributeDef*)&(r))->aligned)
|
||||||
func_import : 1;
|
#define FUNC_PACKED(r) (((AttributeDef*)&(r))->packed)
|
||||||
} func_attr_t;
|
#define INT_ATTR(ad) (*(int*)(ad))
|
||||||
|
|
||||||
#define FUNC_CALL(r) (((func_attr_t*)&(r))->func_call)
|
|
||||||
#define FUNC_EXPORT(r) (((func_attr_t*)&(r))->func_export)
|
|
||||||
#define FUNC_IMPORT(r) (((func_attr_t*)&(r))->func_import)
|
|
||||||
#define FUNC_ARGS(r) (((func_attr_t*)&(r))->func_args)
|
|
||||||
/* -------------------------------------------------- */
|
/* -------------------------------------------------- */
|
||||||
|
|
||||||
#define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
|
#define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
|
||||||
|
@ -480,9 +472,6 @@ struct TCCState {
|
||||||
void *error_opaque;
|
void *error_opaque;
|
||||||
void (*error_func)(void *opaque, const char *msg);
|
void (*error_func)(void *opaque, const char *msg);
|
||||||
int error_set_jmp_enabled;
|
int error_set_jmp_enabled;
|
||||||
#ifdef _WIN64
|
|
||||||
__aligned(16)
|
|
||||||
#endif
|
|
||||||
jmp_buf error_jmp_buf;
|
jmp_buf error_jmp_buf;
|
||||||
int nb_errors;
|
int nb_errors;
|
||||||
|
|
||||||
|
|
31
tccgen.c
31
tccgen.c
|
@ -2230,12 +2230,12 @@ static void parse_attribute(AttributeDef *ad)
|
||||||
case TOK_CDECL1:
|
case TOK_CDECL1:
|
||||||
case TOK_CDECL2:
|
case TOK_CDECL2:
|
||||||
case TOK_CDECL3:
|
case TOK_CDECL3:
|
||||||
FUNC_CALL(ad->func_attr) = FUNC_CDECL;
|
ad->func_call = FUNC_CDECL;
|
||||||
break;
|
break;
|
||||||
case TOK_STDCALL1:
|
case TOK_STDCALL1:
|
||||||
case TOK_STDCALL2:
|
case TOK_STDCALL2:
|
||||||
case TOK_STDCALL3:
|
case TOK_STDCALL3:
|
||||||
FUNC_CALL(ad->func_attr) = FUNC_STDCALL;
|
ad->func_call = FUNC_STDCALL;
|
||||||
break;
|
break;
|
||||||
#ifdef TCC_TARGET_I386
|
#ifdef TCC_TARGET_I386
|
||||||
case TOK_REGPARM1:
|
case TOK_REGPARM1:
|
||||||
|
@ -2247,20 +2247,20 @@ static void parse_attribute(AttributeDef *ad)
|
||||||
else if (n < 0)
|
else if (n < 0)
|
||||||
n = 0;
|
n = 0;
|
||||||
if (n > 0)
|
if (n > 0)
|
||||||
FUNC_CALL(ad->func_attr) = FUNC_FASTCALL1 + n - 1;
|
ad->func_call = FUNC_FASTCALL1 + n - 1;
|
||||||
skip(')');
|
skip(')');
|
||||||
break;
|
break;
|
||||||
case TOK_FASTCALL1:
|
case TOK_FASTCALL1:
|
||||||
case TOK_FASTCALL2:
|
case TOK_FASTCALL2:
|
||||||
case TOK_FASTCALL3:
|
case TOK_FASTCALL3:
|
||||||
FUNC_CALL(ad->func_attr) = FUNC_FASTCALLW;
|
ad->func_call = FUNC_FASTCALLW;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case TOK_DLLEXPORT:
|
case TOK_DLLEXPORT:
|
||||||
FUNC_EXPORT(ad->func_attr) = 1;
|
ad->func_export = 1;
|
||||||
break;
|
break;
|
||||||
case TOK_DLLIMPORT:
|
case TOK_DLLIMPORT:
|
||||||
FUNC_IMPORT(ad->func_attr) = 1;
|
ad->func_import = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (tcc_state->warn_unsupported)
|
if (tcc_state->warn_unsupported)
|
||||||
|
@ -2646,6 +2646,14 @@ static int parse_btype(CType *type, AttributeDef *ad)
|
||||||
typedef_found = 1;
|
typedef_found = 1;
|
||||||
t |= (s->type.t & ~VT_TYPEDEF);
|
t |= (s->type.t & ~VT_TYPEDEF);
|
||||||
type->ref = s->type.ref;
|
type->ref = s->type.ref;
|
||||||
|
if (s->r) {
|
||||||
|
/* get attributes from typedef */
|
||||||
|
if (0 == ad->aligned)
|
||||||
|
ad->aligned = FUNC_ALIGN(s->r);
|
||||||
|
if (0 == ad->func_call)
|
||||||
|
ad->func_call = FUNC_CALL(s->r);
|
||||||
|
ad->packed |= FUNC_PACKED(s->r);
|
||||||
|
}
|
||||||
next();
|
next();
|
||||||
typespec_found = 1;
|
typespec_found = 1;
|
||||||
break;
|
break;
|
||||||
|
@ -2751,8 +2759,8 @@ static void post_type(CType *type, AttributeDef *ad)
|
||||||
type->t &= ~(VT_STORAGE | VT_CONSTANT);
|
type->t &= ~(VT_STORAGE | VT_CONSTANT);
|
||||||
post_type(type, ad);
|
post_type(type, ad);
|
||||||
/* we push a anonymous symbol which will contain the function prototype */
|
/* we push a anonymous symbol which will contain the function prototype */
|
||||||
FUNC_ARGS(ad->func_attr) = arg_size;
|
ad->func_args = arg_size;
|
||||||
s = sym_push(SYM_FIELD, type, ad->func_attr, l);
|
s = sym_push(SYM_FIELD, type, INT_ATTR(ad), l);
|
||||||
s->next = first;
|
s->next = first;
|
||||||
type->t = t1 | VT_FUNC;
|
type->t = t1 | VT_FUNC;
|
||||||
type->ref = s;
|
type->ref = s;
|
||||||
|
@ -5115,13 +5123,12 @@ static void decl(int l)
|
||||||
if (btype.t & VT_TYPEDEF) {
|
if (btype.t & VT_TYPEDEF) {
|
||||||
/* save typedefed type */
|
/* save typedefed type */
|
||||||
/* XXX: test storage specifiers ? */
|
/* XXX: test storage specifiers ? */
|
||||||
sym = sym_push(v, &type, 0, 0);
|
sym = sym_push(v, &type, INT_ATTR(&ad), 0);
|
||||||
sym->type.t |= VT_TYPEDEF;
|
sym->type.t |= VT_TYPEDEF;
|
||||||
} else if ((type.t & VT_BTYPE) == VT_FUNC) {
|
} else if ((type.t & VT_BTYPE) == VT_FUNC) {
|
||||||
/* external function definition */
|
/* external function definition */
|
||||||
/* specific case for func_call attribute */
|
/* specific case for func_call attribute */
|
||||||
if (ad.func_attr)
|
type.ref->r = INT_ATTR(&ad);
|
||||||
type.ref->r = ad.func_attr;
|
|
||||||
external_sym(v, &type, 0);
|
external_sym(v, &type, 0);
|
||||||
} else {
|
} else {
|
||||||
/* not lvalue if array */
|
/* not lvalue if array */
|
||||||
|
@ -5137,7 +5144,7 @@ static void decl(int l)
|
||||||
arrays of null size are considered as
|
arrays of null size are considered as
|
||||||
extern */
|
extern */
|
||||||
#ifdef TCC_TARGET_PE
|
#ifdef TCC_TARGET_PE
|
||||||
if (FUNC_IMPORT(ad.func_attr))
|
if (ad.func_import)
|
||||||
type.t |= VT_IMPORT;
|
type.t |= VT_IMPORT;
|
||||||
#endif
|
#endif
|
||||||
external_sym(v, &type, r);
|
external_sym(v, &type, r);
|
||||||
|
|
Loading…
Reference in a new issue