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