uses 'nocode_wanted' as a level couter instead of 'saved_nocode_wanted' everywhere.
Unified · Split
| @@ -146,6 +146,7 @@ ST_FUNC void tccgen_start(TCCState *s1) · 145 unmodified lines | |||
| 146 | funcname = ""; | 146 | funcname = ""; |
| 147 | anon_sym = SYM_FIRST_ANOM; | 147 | anon_sym = SYM_FIRST_ANOM; |
| 148 | section_sym = 0; | 148 | section_sym = 0; |
| 149 | const_wanted = 0; | ||
| 149 | nocode_wanted = 1; | 150 | nocode_wanted = 1; |
| 150 | 151 | ||
| 151 | /* define some often used types */ | 152 | /* define some often used types */ |
| @@ -4457,16 +4458,14 @@ ST_FUNC void unary(void) · 4305 unmodified lines | |||
| 4457 | case TOK_builtin_expect: | 4458 | case TOK_builtin_expect: |
| 4458 | { | 4459 | { |
| 4459 | /* __builtin_expect is a no-op for now */ | 4460 | /* __builtin_expect is a no-op for now */ |
| 4460 | int saved_nocode_wanted; | ||
| 4461 | next(); | 4461 | next(); |
| 4462 | skip('('); | 4462 | skip('('); |
| 4463 | expr_eq(); | 4463 | expr_eq(); |
| 4464 | skip(','); | 4464 | skip(','); |
| 4465 | saved_nocode_wanted = nocode_wanted; | 4465 | nocode_wanted++; |
| 4466 | nocode_wanted = 1; | ||
| 4467 | expr_lor_const(); | 4466 | expr_lor_const(); |
| 4468 | vpop(); | 4467 | vpop(); |
| 4469 | nocode_wanted = saved_nocode_wanted; | 4468 | nocode_wanted--; |
| 4470 | skip(')'); | 4469 | skip(')'); |
| 4471 | } | 4470 | } |
| 4472 | break; | 4471 | break; |
| @@ -4486,45 +4485,41 @@ ST_FUNC void unary(void) · 13 unmodified lines | |||
| 4486 | break; | 4485 | break; |
| 4487 | case TOK_builtin_choose_expr: | 4486 | case TOK_builtin_choose_expr: |
| 4488 | { | 4487 | { |
| 4489 | int saved_nocode_wanted; | ||
| 4490 | int64_t c; | 4488 | int64_t c; |
| 4491 | next(); | 4489 | next(); |
| 4492 | skip('('); | 4490 | skip('('); |
| 4493 | c = expr_const64(); | 4491 | c = expr_const64(); |
| 4494 | skip(','); | 4492 | skip(','); |
| 4495 | if (!c) { | 4493 | if (!c) { |
| 4496 | saved_nocode_wanted = nocode_wanted; | 4494 | nocode_wanted++; |
| 4497 | nocode_wanted = 1; | ||
| 4498 | } | 4495 | } |
| 4499 | expr_eq(); | 4496 | expr_eq(); |
| 4500 | if (!c) { | 4497 | if (!c) { |
| 4501 | vpop(); | 4498 | vpop(); |
| 4502 | nocode_wanted = saved_nocode_wanted; | 4499 | nocode_wanted--; |
| 4503 | } | 4500 | } |
| 4504 | skip(','); | 4501 | skip(','); |
| 4505 | if (c) { | 4502 | if (c) { |
| 4506 | saved_nocode_wanted = nocode_wanted; | 4503 | nocode_wanted++; |
| 4507 | nocode_wanted = 1; | ||
| 4508 | } | 4504 | } |
| 4509 | expr_eq(); | 4505 | expr_eq(); |
| 4510 | if (c) { | 4506 | if (c) { |
| 4511 | vpop(); | 4507 | vpop(); |
| 4512 | nocode_wanted = saved_nocode_wanted; | 4508 | nocode_wanted--; |
| 4513 | } | 4509 | } |
| 4514 | skip(')'); | 4510 | skip(')'); |
| 4515 | } | 4511 | } |
| 4516 | break; | 4512 | break; |
| 4517 | case TOK_builtin_constant_p: | 4513 | case TOK_builtin_constant_p: |
| 4518 | { | 4514 | { |
| 4519 | int saved_nocode_wanted, res; | 4515 | int res; |
| 4520 | next(); | 4516 | next(); |
| 4521 | skip('('); | 4517 | skip('('); |
| 4522 | saved_nocode_wanted = nocode_wanted; | 4518 | nocode_wanted++; |
| 4523 | nocode_wanted = 1; | ||
| 4524 | gexpr(); | 4519 | gexpr(); |
| 4525 | res = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST; | 4520 | res = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST; |
| 4526 | vpop(); | 4521 | vpop(); |
| 4527 | nocode_wanted = saved_nocode_wanted; | 4522 | nocode_wanted--; |
| 4528 | skip(')'); | 4523 | skip(')'); |
| 4529 | vpushi(res); | 4524 | vpushi(res); |
| 4530 | } | 4525 | } |
| @@ -5054,14 +5049,13 @@ static void expr_land(void) · 523 unmodified lines | |||
| 5054 | if (vtop->c.i) { | 5049 | if (vtop->c.i) { |
| 5055 | vpop(); | 5050 | vpop(); |
| 5056 | } else { | 5051 | } else { |
| 5057 | int saved_nocode_wanted = nocode_wanted; | 5052 | nocode_wanted++; |
| 5058 | nocode_wanted = 1; | ||
| 5059 | while (tok == TOK_LAND) { | 5053 | while (tok == TOK_LAND) { |
| 5060 | next(); | 5054 | next(); |
| 5061 | expr_or(); | 5055 | expr_or(); |
| 5062 | vpop(); | 5056 | vpop(); |
| 5063 | } | 5057 | } |
| 5064 | nocode_wanted = saved_nocode_wanted; | 5058 | nocode_wanted--; |
| 5065 | if (t) | 5059 | if (t) |
| 5066 | gsym(t); | 5060 | gsym(t); |
| 5067 | gen_cast(&int_type); | 5061 | gen_cast(&int_type); |
| @@ -5098,14 +5092,13 @@ static void expr_lor(void) · 30 unmodified lines | |||
| 5098 | if (!vtop->c.i) { | 5092 | if (!vtop->c.i) { |
| 5099 | vpop(); | 5093 | vpop(); |
| 5100 | } else { | 5094 | } else { |
| 5101 | int saved_nocode_wanted = nocode_wanted; | 5095 | nocode_wanted++; |
| 5102 | nocode_wanted = 1; | ||
| 5103 | while (tok == TOK_LOR) { | 5096 | while (tok == TOK_LOR) { |
| 5104 | next(); | 5097 | next(); |
| 5105 | expr_land(); | 5098 | expr_land(); |
| 5106 | vpop(); | 5099 | vpop(); |
| 5107 | } | 5100 | } |
| 5108 | nocode_wanted = saved_nocode_wanted; | 5101 | nocode_wanted--; |
| 5109 | if (t) | 5102 | if (t) |
| 5110 | gsym(t); | 5103 | gsym(t); |
| 5111 | gen_cast(&int_type); | 5104 | gen_cast(&int_type); |
| @@ -5153,7 +5146,6 @@ static void expr_cond(void) · 41 unmodified lines | |||
| 5153 | int tt, u, r1, r2, rc, t1, t2, bt1, bt2, islv, c, g; | 5146 | int tt, u, r1, r2, rc, t1, t2, bt1, bt2, islv, c, g; |
| 5154 | SValue sv; | 5147 | SValue sv; |
| 5155 | CType type, type1, type2; | 5148 | CType type, type1, type2; |
| 5156 | int saved_nocode_wanted = nocode_wanted; | ||
| 5157 | 5149 | ||
| 5158 | expr_lor(); | 5150 | expr_lor(); |
| 5159 | if (tok == '?') { | 5151 | if (tok == '?') { |
| @@ -5186,7 +5178,7 @@ static void expr_cond(void) · 26 unmodified lines | |||
| 5186 | 5178 | ||
| 5187 | if (1) { | 5179 | if (1) { |
| 5188 | if (c == 0) | 5180 | if (c == 0) |
| 5189 | nocode_wanted = 1; | 5181 | nocode_wanted++; |
| 5190 | if (!g) | 5182 | if (!g) |
| 5191 | gexpr(); | 5183 | gexpr(); |
| 5192 | 5184 | ||
| @@ -5199,11 +5191,14 @@ static void expr_cond(void) · 6 unmodified lines | |||
| 5199 | if (c < 0) | 5191 | if (c < 0) |
| 5200 | u = gjmp(0); | 5192 | u = gjmp(0); |
| 5201 | gsym(tt); | 5193 | gsym(tt); |
| 5202 | nocode_wanted = saved_nocode_wanted; | 5194 | |
| 5195 | if (c == 0) | ||
| 5196 | nocode_wanted--; | ||
| 5203 | if (c == 1) | 5197 | if (c == 1) |
| 5204 | nocode_wanted = 1; | 5198 | nocode_wanted++; |
| 5205 | expr_cond(); | 5199 | expr_cond(); |
| 5206 | nocode_wanted = saved_nocode_wanted; | 5200 | if (c == 1) |
| 5201 | nocode_wanted--; | ||
| 5207 | 5202 | ||
| 5208 | type2 = vtop->type; | 5203 | type2 = vtop->type; |
| 5209 | t1 = type1.t; | 5204 | t1 = type1.t; |
| @@ -5355,38 +5350,31 @@ ST_FUNC void gexpr(void) · 145 unmodified lines | |||
| 5355 | /* parse an expression and return its type without any side effect. */ | 5350 | /* parse an expression and return its type without any side effect. */ |
| 5356 | static void expr_type(CType *type) | 5351 | static void expr_type(CType *type) |
| 5357 | { | 5352 | { |
| 5358 | int saved_nocode_wanted; | ||
| 5359 | 5353 | ||
| 5360 | saved_nocode_wanted = nocode_wanted; | 5354 | nocode_wanted++; |
| 5361 | nocode_wanted = 1; | ||
| 5362 | gexpr(); | 5355 | gexpr(); |
| 5363 | *type = vtop->type; | 5356 | *type = vtop->type; |
| 5364 | vpop(); | 5357 | vpop(); |
| 5365 | nocode_wanted = saved_nocode_wanted; | 5358 | nocode_wanted--; |
| 5366 | } | 5359 | } |
| 5367 | 5360 | ||
| 5368 | /* parse a unary expression and return its type without any side | 5361 | /* parse a unary expression and return its type without any side |
| 5369 | effect. */ | 5362 | effect. */ |
| 5370 | static void unary_type(CType *type) | 5363 | static void unary_type(CType *type) |
| 5371 | { | 5364 | { |
| 5372 | int a; | 5365 | nocode_wanted++; |
| 5373 | |||
| 5374 | a = nocode_wanted; | ||
| 5375 | nocode_wanted = 1; | ||
| 5376 | unary(); | 5366 | unary(); |
| 5377 | *type = vtop->type; | 5367 | *type = vtop->type; |
| 5378 | vpop(); | 5368 | vpop(); |
| 5379 | nocode_wanted = a; | 5369 | nocode_wanted--; |
| 5380 | } | 5370 | } |
| 5381 | 5371 | ||
| 5382 | /* parse a constant expression and return value in vtop. */ | 5372 | /* parse a constant expression and return value in vtop. */ |
| 5383 | static void expr_const1(void) | 5373 | static void expr_const1(void) |
| 5384 | { | 5374 | { |
| 5385 | int a; | 5375 | const_wanted++; |
| 5386 | a = const_wanted; | ||
| 5387 | const_wanted = 1; | ||
| 5388 | expr_cond(); | 5376 | expr_cond(); |
| 5389 | const_wanted = a; | 5377 | const_wanted--; |
| 5390 | } | 5378 | } |
| 5391 | 5379 | ||
| 5392 | /* parse an integer constant and return its value. */ | 5380 | /* parse an integer constant and return its value. */ |
| @@ -5552,7 +5540,7 @@ static void block(int *bsym, int *csym, int is_expr) · 159 unmodified lines | |||
| 5552 | else | 5540 | else |
| 5553 | a = gvtst(1, 0); | 5541 | a = gvtst(1, 0); |
| 5554 | if (cond == 0) | 5542 | if (cond == 0) |
| 5555 | nocode_wanted |= 2; | 5543 | nocode_wanted |= 0x20000000; |
| 5556 | block(bsym, csym, 0); | 5544 | block(bsym, csym, 0); |
| 5557 | if (cond != 1) | 5545 | if (cond != 1) |
| 5558 | nocode_wanted = saved_nocode_wanted; | 5546 | nocode_wanted = saved_nocode_wanted; |
| @@ -5562,7 +5550,7 @@ static void block(int *bsym, int *csym, int is_expr) · 3 unmodified lines | |||
| 5562 | d = gjmp(0); | 5550 | d = gjmp(0); |
| 5563 | gsym(a); | 5551 | gsym(a); |
| 5564 | if (cond == 1) | 5552 | if (cond == 1) |
| 5565 | nocode_wanted |= 2; | 5553 | nocode_wanted |= 0x20000000; |
| 5566 | block(bsym, csym, 0); | 5554 | block(bsym, csym, 0); |
| 5567 | gsym(d); /* patch else jmp */ | 5555 | gsym(d); /* patch else jmp */ |
| 5568 | if (cond != 0) | 5556 | if (cond != 0) |
| @@ -5571,7 +5559,7 @@ static void block(int *bsym, int *csym, int is_expr) · 2 unmodified lines | |||
| 5571 | gsym(a); | 5559 | gsym(a); |
| 5572 | } else if (tok == TOK_WHILE) { | 5560 | } else if (tok == TOK_WHILE) { |
| 5573 | int saved_nocode_wanted; | 5561 | int saved_nocode_wanted; |
| 5574 | nocode_wanted &= ~2; | 5562 | nocode_wanted &= ~0x20000000; |
| 5575 | next(); | 5563 | next(); |
| 5576 | d = ind; | 5564 | d = ind; |
| 5577 | vla_sp_restore(); | 5565 | vla_sp_restore(); |
| @@ -5718,7 +5706,7 @@ static void block(int *bsym, int *csym, int is_expr) · 140 unmodified lines | |||
| 5718 | /* jump unless last stmt in top-level block */ | 5706 | /* jump unless last stmt in top-level block */ |
| 5719 | if (tok != '}' || local_scope != 1) | 5707 | if (tok != '}' || local_scope != 1) |
| 5720 | rsym = gjmp(rsym); | 5708 | rsym = gjmp(rsym); |
| 5721 | nocode_wanted |= 2; | 5709 | nocode_wanted |= 0x20000000; |
| 5722 | } else if (tok == TOK_BREAK) { | 5710 | } else if (tok == TOK_BREAK) { |
| 5723 | /* compute jump */ | 5711 | /* compute jump */ |
| 5724 | if (!bsym) | 5712 | if (!bsym) |
| @@ -5726,7 +5714,7 @@ static void block(int *bsym, int *csym, int is_expr) · 1 unmodified line | |||
| 5726 | *bsym = gjmp(*bsym); | 5714 | *bsym = gjmp(*bsym); |
| 5727 | next(); | 5715 | next(); |
| 5728 | skip(';'); | 5716 | skip(';'); |
| 5729 | nocode_wanted |= 2; | 5717 | nocode_wanted |= 0x20000000; |
| 5730 | } else if (tok == TOK_CONTINUE) { | 5718 | } else if (tok == TOK_CONTINUE) { |
| 5731 | /* compute jump */ | 5719 | /* compute jump */ |
| 5732 | if (!csym) | 5720 | if (!csym) |
| @@ -5738,7 +5726,7 @@ static void block(int *bsym, int *csym, int is_expr) · 5 unmodified lines | |||
| 5738 | } else if (tok == TOK_FOR) { | 5726 | } else if (tok == TOK_FOR) { |
| 5739 | int e; | 5727 | int e; |
| 5740 | int saved_nocode_wanted; | 5728 | int saved_nocode_wanted; |
| 5741 | nocode_wanted &= ~2; | 5729 | nocode_wanted &= ~0x20000000; |
| 5742 | next(); | 5730 | next(); |
| 5743 | skip('('); | 5731 | skip('('); |
| 5744 | s = local_stack; | 5732 | s = local_stack; |
| @@ -5784,7 +5772,7 @@ static void block(int *bsym, int *csym, int is_expr) · 39 unmodified lines | |||
| 5784 | } else | 5772 | } else |
| 5785 | if (tok == TOK_DO) { | 5773 | if (tok == TOK_DO) { |
| 5786 | int saved_nocode_wanted; | 5774 | int saved_nocode_wanted; |
| 5787 | nocode_wanted &= ~2; | 5775 | nocode_wanted &= ~0x20000000; |
| 5788 | next(); | 5776 | next(); |
| 5789 | a = 0; | 5777 | a = 0; |
| 5790 | b = 0; | 5778 | b = 0; |
| @@ -5844,7 +5832,7 @@ static void block(int *bsym, int *csym, int is_expr) · 53 unmodified lines | |||
| 5844 | struct case_t *cr = tcc_malloc(sizeof(struct case_t)); | 5832 | struct case_t *cr = tcc_malloc(sizeof(struct case_t)); |
| 5845 | if (!cur_switch) | 5833 | if (!cur_switch) |
| 5846 | expect("switch"); | 5834 | expect("switch"); |
| 5847 | nocode_wanted &= ~2; | 5835 | nocode_wanted &= ~0x20000000; |
| 5848 | next(); | 5836 | next(); |
| 5849 | cr->v1 = cr->v2 = expr_const64(); | 5837 | cr->v1 = cr->v2 = expr_const64(); |
| 5850 | if (gnu_ext && tok == TOK_DOTS) { | 5838 | if (gnu_ext && tok == TOK_DOTS) { |
| @@ -5917,7 +5905,7 @@ static void block(int *bsym, int *csym, int is_expr) · 66 unmodified lines | |||
| 5917 | vla_sp_restore(); | 5905 | vla_sp_restore(); |
| 5918 | /* we accept this, but it is a mistake */ | 5906 | /* we accept this, but it is a mistake */ |
| 5919 | block_after_label: | 5907 | block_after_label: |
| 5920 | nocode_wanted &= ~2; | 5908 | nocode_wanted &= ~0x20000000; |
| 5921 | if (tok == '}') { | 5909 | if (tok == '}') { |
| 5922 | tcc_warning("deprecated use of label at end of compound statement"); | 5910 | tcc_warning("deprecated use of label at end of compound statement"); |
| 5923 | } else { | 5911 | } else { |
| @@ -6833,8 +6821,6 @@ static void func_decl_list(Sym *func_sym) · 909 unmodified lines | |||
| 6833 | 'cur_text_section' */ | 6821 | 'cur_text_section' */ |
| 6834 | static void gen_function(Sym *sym) | 6822 | static void gen_function(Sym *sym) |
| 6835 | { | 6823 | { |
| 6836 | int saved_nocode_wanted = nocode_wanted; | ||
| 6837 | |||
| 6838 | nocode_wanted = 0; | 6824 | nocode_wanted = 0; |
| 6839 | ind = cur_text_section->data_offset; | 6825 | ind = cur_text_section->data_offset; |
| 6840 | /* NOTE: we patch the symbol size later */ | 6826 | /* NOTE: we patch the symbol size later */ |
| @@ -6881,7 +6867,7 @@ static void gen_function(Sym *sym) · 40 unmodified lines | |||
| 6881 | func_vt.t = VT_VOID; /* for safety */ | 6867 | func_vt.t = VT_VOID; /* for safety */ |
| 6882 | func_var = 0; /* for safety */ | 6868 | func_var = 0; /* for safety */ |
| 6883 | ind = 0; /* for safety */ | 6869 | ind = 0; /* for safety */ |
| 6884 | nocode_wanted = saved_nocode_wanted; | 6870 | nocode_wanted = 1; |
| 6885 | check_vstack(); | 6871 | check_vstack(); |
| 6886 | } | 6872 | } |
| 6887 | 6873 | ||