Add support for the __mode__ attribute

--
By by ... Detlef
master
Detlef Riekenberg 2010-01-26 22:56:22 +01:00 committed by Detlef Riekenberg
parent 2650584ac4
commit a975008ae7
3 changed files with 30 additions and 1 deletions

4
tcc.h
View File

@ -267,7 +267,8 @@ typedef struct AttributeDef {
func_export : 1,
func_import : 1,
func_args : 5,
fill : 16;
mode : 4,
fill : 12;
struct Section *section;
} AttributeDef;
@ -278,6 +279,7 @@ typedef struct AttributeDef {
#define FUNC_ARGS(r) (((AttributeDef*)&(r))->func_args)
#define FUNC_ALIGN(r) (((AttributeDef*)&(r))->aligned)
#define FUNC_PACKED(r) (((AttributeDef*)&(r))->packed)
#define ATTR_MODE(r) (((AttributeDef*)&(r))->mode)
#define INT_ATTR(ad) (*(int*)(ad))
/* -------------------------------------------------- */

View File

@ -2501,6 +2501,25 @@ static void parse_attribute(AttributeDef *ad)
ad->func_call = FUNC_FASTCALLW;
break;
#endif
case TOK_MODE:
skip('(');
switch(tok) {
case TOK_MODE_DI:
ad->mode = VT_LLONG + 1;
break;
case TOK_MODE_HI:
ad->mode = VT_SHORT + 1;
break;
case TOK_MODE_SI:
ad->mode = VT_INT + 1;
break;
default:
warning("__mode__(%s) not supported\n", get_tok_str(tok, NULL));
break;
}
next();
skip(')');
break;
case TOK_DLLEXPORT:
ad->func_export = 1;
break;
@ -2874,6 +2893,10 @@ static int parse_btype(CType *type, AttributeDef *ad)
case TOK_ATTRIBUTE1:
case TOK_ATTRIBUTE2:
parse_attribute(ad);
if (ATTR_MODE(ad)) {
u = ATTR_MODE(ad) -1;
t = (t & ~VT_BTYPE) | u;
}
break;
/* GNUC typeof */
case TOK_TYPEOF1:

View File

@ -104,6 +104,10 @@
DEF(TOK_FASTCALL1, "fastcall")
DEF(TOK_FASTCALL2, "__fastcall")
DEF(TOK_FASTCALL3, "__fastcall__")
DEF(TOK_MODE, "__mode__")
DEF(TOK_MODE_DI, "__DI__")
DEF(TOK_MODE_HI, "__HI__")
DEF(TOK_MODE_SI, "__SI__")
DEF(TOK_DLLEXPORT, "dllexport")
DEF(TOK_DLLIMPORT, "dllimport")
DEF(TOK_NORETURN1, "noreturn")