From 7828683e609c0d2b03193a78a0aaaf9368c8f03b Mon Sep 17 00:00:00 2001 From: bellard Date: Sat, 26 Apr 2003 21:28:09 +0000 Subject: [PATCH] added __builtin_constant_p() and __builtin_types_compatible_p() support --- tcc.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- tcctok.h | 2 ++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/tcc.c b/tcc.c index 1091a56e..58ae72a9 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 d957eb1d..4082b28e 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") -- 2.11.4.GIT