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
6593 skip(')');6593 skip(')');
6594}6594}
6595 6595
6596static 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
6596static void vpush_tokc(int t)6607static void vpush_tokc(int t)
6597{6608{
6598 CType type;6609 CType type;
@@ -6777,7 +6788,36 @@ static void unary(void) · 178 unmodified lines
6777 vpushi(align);6788 vpushi(align);
6778 }6789 }
6779 break;6790 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;
6781 case TOK_INC:6821 case TOK_INC:
6782 case TOK_DEC:6822 case TOK_DEC:
6783 t = tok;6823 t = tok;
@@ -7274,14 +7314,14 @@ static void gexpr(void) · 490 unmodified lines
7274/* parse an expression and return its type without any side effect. */7314/* parse an expression and return its type without any side effect. */
7275static void expr_type(CType *type)7315static void expr_type(CType *type)
7276{7316{
7277 int a;7317 int saved_nocode_wanted;
7278 7318
7279 a = nocode_wanted;7319 saved_nocode_wanted = nocode_wanted;
7280 nocode_wanted = 1;7320 nocode_wanted = 1;
7281 gexpr();7321 gexpr();
7282 *type = vtop->type;7322 *type = vtop->type;
7283 vpop();7323 vpop();
7284 nocode_wanted = a;7324 nocode_wanted = saved_nocode_wanted;
7285}7325}
7286 7326
7287/* parse a unary expression and return its type without any side7327/* parse a unary expression and return its type without any side
tcctok.h+2−0
@@ -100,6 +100,8 @@ · 99 unmodified lines
100 DEF(TOK_STDCALL3, "__stdcall__")100 DEF(TOK_STDCALL3, "__stdcall__")
101 DEF(TOK_NORETURN1, "noreturn")101 DEF(TOK_NORETURN1, "noreturn")
102 DEF(TOK_NORETURN2, "__noreturn__")102 DEF(TOK_NORETURN2, "__noreturn__")
103 DEF(TOK_builtin_types_compatible_p, "__builtin_types_compatible_p")
104 DEF(TOK_builtin_constant_p, "__builtin_constant_p")
103 105
104/* builtin functions or variables */106/* builtin functions or variables */
105 DEF(TOK_memcpy, "memcpy")107 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