History

added __builtin_constant_p() and __builtin_types_compatible_p() support

bellard committed 23 years ago

Commit 78286831 parent 60efcfe2 files · +46 −4Browse files

Unified · Split

2 files
  1. tcc.c +44 −4
  2. tcctok.h +2 −0
tcc.c+44−4
@@ -6593,6 +6593,17 @@ static void parse_expr_type(CType *type) · 6592 unmodified lines
65936593 skip(')');
65946594 }
65956595
6596+static void parse_type(CType *type)
6597+{
6598+ AttributeDef ad;
6599+ int n;
6600+
6601+ if (!parse_btype(type, &ad)) {
6602+ expect("type");
6603+ }
6604+ type_decl(type, &ad, &n, TYPE_ABSTRACT);
6605+}
6606+
65966607 static void vpush_tokc(int t)
65976608 {
65986609 CType type;
@@ -6777,7 +6788,36 @@ static void unary(void) · 178 unmodified lines
67776788 vpushi(align);
67786789 }
67796790 break;
6780−
6791+
6792+ case TOK_builtin_types_compatible_p:
6793+ {
6794+ CType type1, type2;
6795+ next();
6796+ skip('(');
6797+ parse_type(&type1);
6798+ skip(',');
6799+ parse_type(&type2);
6800+ skip(')');
6801+ type1.t &= ~(VT_CONSTANT | VT_VOLATILE);
6802+ type2.t &= ~(VT_CONSTANT | VT_VOLATILE);
6803+ vpushi(is_compatible_types(&type1, &type2));
6804+ }
6805+ break;
6806+ case TOK_builtin_constant_p:
6807+ {
6808+ int saved_nocode_wanted, res;
6809+ next();
6810+ skip('(');
6811+ saved_nocode_wanted = nocode_wanted;
6812+ nocode_wanted = 1;
6813+ gexpr();
6814+ res = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
6815+ vpop();
6816+ nocode_wanted = saved_nocode_wanted;
6817+ skip(')');
6818+ vpushi(res);
6819+ }
6820+ break;
67816821 case TOK_INC:
67826822 case TOK_DEC:
67836823 t = tok;
@@ -7274,14 +7314,14 @@ static void gexpr(void) · 490 unmodified lines
72747314 /* parse an expression and return its type without any side effect. */
72757315 static void expr_type(CType *type)
72767316 {
7277− int a;
7317+ int saved_nocode_wanted;
72787318
7279− a = nocode_wanted;
7319+ saved_nocode_wanted = nocode_wanted;
72807320 nocode_wanted = 1;
72817321 gexpr();
72827322 *type = vtop->type;
72837323 vpop();
7284− nocode_wanted = a;
7324+ nocode_wanted = saved_nocode_wanted;
72857325 }
72867326
72877327 /* parse a unary expression and return its type without any side
tcctok.h+2−0
@@ -100,6 +100,8 @@ · 99 unmodified lines
100100 DEF(TOK_STDCALL3, "__stdcall__")
101101 DEF(TOK_NORETURN1, "noreturn")
102102 DEF(TOK_NORETURN2, "__noreturn__")
103+ DEF(TOK_builtin_types_compatible_p, "__builtin_types_compatible_p")
104+ DEF(TOK_builtin_constant_p, "__builtin_constant_p")
103105
104106 /* builtin functions or variables */
105107 DEF(TOK_memcpy, "memcpy")

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t