aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbellard <bellard>2003-04-26 21:28:09 +0000
committerbellard <bellard>2003-04-26 21:28:09 +0000
commit7828683e609c0d2b03193a78a0aaaf9368c8f03b (patch)
tree7f60b39374e692fea90b5964cd6a215bfc5e4a6f
parent60efcfe27c3bf3710e08003517edbfa3bfe3587f (diff)
downloadtinycc-7828683e609c0d2b03193a78a0aaaf9368c8f03b.tar.gz
tinycc-7828683e609c0d2b03193a78a0aaaf9368c8f03b.tar.bz2
added __builtin_constant_p() and __builtin_types_compatible_p() support
-rw-r--r--tcc.c48
-rw-r--r--tcctok.h2
2 files changed, 46 insertions, 4 deletions
diff --git a/tcc.c b/tcc.c
index 1091a56..58ae72a 100644
--- a/tcc.c
+++ b/tcc.c
@@ -6593,6 +6593,17 @@ static void parse_expr_type(CType *type)
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)
{
CType type;
@@ -6777,7 +6788,36 @@ static void unary(void)
vpushi(align);
}
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_DEC:
t = tok;
@@ -7274,14 +7314,14 @@ static void gexpr(void)
/* parse an expression and return its type without any side effect. */
static void expr_type(CType *type)
{
- int a;
+ int saved_nocode_wanted;
- a = nocode_wanted;
+ saved_nocode_wanted = nocode_wanted;
nocode_wanted = 1;
gexpr();
*type = vtop->type;
vpop();
- nocode_wanted = a;
+ nocode_wanted = saved_nocode_wanted;
}
/* parse a unary expression and return its type without any side
diff --git a/tcctok.h b/tcctok.h
index d957eb1..4082b28 100644
--- a/tcctok.h
+++ b/tcctok.h
@@ -100,6 +100,8 @@
DEF(TOK_STDCALL3, "__stdcall__")
DEF(TOK_NORETURN1, "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 */
DEF(TOK_memcpy, "memcpy")