forked from Mirrors/tinycc
added __builtin_constant_p() and __builtin_types_compatible_p() support
parent
60efcfe27c
commit
7828683e60
46
tcc.c
46
tcc.c
|
@ -6593,6 +6593,17 @@ static void parse_expr_type(CType *type)
|
||||||
skip(')');
|
skip(')');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void parse_type(CType *type)
|
||||||
|
{
|
||||||
|
AttributeDef ad;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if (!parse_btype(type, &ad)) {
|
||||||
|
expect("type");
|
||||||
|
}
|
||||||
|
type_decl(type, &ad, &n, TYPE_ABSTRACT);
|
||||||
|
}
|
||||||
|
|
||||||
static void vpush_tokc(int t)
|
static void vpush_tokc(int t)
|
||||||
{
|
{
|
||||||
CType type;
|
CType type;
|
||||||
|
@ -6778,6 +6789,35 @@ static void unary(void)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TOK_builtin_types_compatible_p:
|
||||||
|
{
|
||||||
|
CType type1, type2;
|
||||||
|
next();
|
||||||
|
skip('(');
|
||||||
|
parse_type(&type1);
|
||||||
|
skip(',');
|
||||||
|
parse_type(&type2);
|
||||||
|
skip(')');
|
||||||
|
type1.t &= ~(VT_CONSTANT | VT_VOLATILE);
|
||||||
|
type2.t &= ~(VT_CONSTANT | VT_VOLATILE);
|
||||||
|
vpushi(is_compatible_types(&type1, &type2));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TOK_builtin_constant_p:
|
||||||
|
{
|
||||||
|
int saved_nocode_wanted, res;
|
||||||
|
next();
|
||||||
|
skip('(');
|
||||||
|
saved_nocode_wanted = nocode_wanted;
|
||||||
|
nocode_wanted = 1;
|
||||||
|
gexpr();
|
||||||
|
res = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
|
||||||
|
vpop();
|
||||||
|
nocode_wanted = saved_nocode_wanted;
|
||||||
|
skip(')');
|
||||||
|
vpushi(res);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case TOK_INC:
|
case TOK_INC:
|
||||||
case TOK_DEC:
|
case TOK_DEC:
|
||||||
t = tok;
|
t = tok;
|
||||||
|
@ -7274,14 +7314,14 @@ static void gexpr(void)
|
||||||
/* parse an expression and return its type without any side effect. */
|
/* parse an expression and return its type without any side effect. */
|
||||||
static void expr_type(CType *type)
|
static void expr_type(CType *type)
|
||||||
{
|
{
|
||||||
int a;
|
int saved_nocode_wanted;
|
||||||
|
|
||||||
a = nocode_wanted;
|
saved_nocode_wanted = nocode_wanted;
|
||||||
nocode_wanted = 1;
|
nocode_wanted = 1;
|
||||||
gexpr();
|
gexpr();
|
||||||
*type = vtop->type;
|
*type = vtop->type;
|
||||||
vpop();
|
vpop();
|
||||||
nocode_wanted = a;
|
nocode_wanted = saved_nocode_wanted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse a unary expression and return its type without any side
|
/* parse a unary expression and return its type without any side
|
||||||
|
|
2
tcctok.h
2
tcctok.h
|
@ -100,6 +100,8 @@
|
||||||
DEF(TOK_STDCALL3, "__stdcall__")
|
DEF(TOK_STDCALL3, "__stdcall__")
|
||||||
DEF(TOK_NORETURN1, "noreturn")
|
DEF(TOK_NORETURN1, "noreturn")
|
||||||
DEF(TOK_NORETURN2, "__noreturn__")
|
DEF(TOK_NORETURN2, "__noreturn__")
|
||||||
|
DEF(TOK_builtin_types_compatible_p, "__builtin_types_compatible_p")
|
||||||
|
DEF(TOK_builtin_constant_p, "__builtin_constant_p")
|
||||||
|
|
||||||
/* builtin functions or variables */
|
/* builtin functions or variables */
|
||||||
DEF(TOK_memcpy, "memcpy")
|
DEF(TOK_memcpy, "memcpy")
|
||||||
|
|
Loading…
Reference in New Issue