| @@ -335,6 +335,22 @@ static void use_section(TCCState *s1, const char *name) · 334 unmodified lines |
| 335 | 335 | use_section1(s1, sec); |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | +static void push_section(TCCState *s1, const char *name) |
| 339 | +{ |
| 340 | + Section *sec = find_section(s1, name); |
| 341 | + sec->prev = cur_text_section; |
| 342 | + use_section1(s1, sec); |
| 343 | +} |
| 344 | + |
| 345 | +static void pop_section(TCCState *s1) |
| 346 | +{ |
| 347 | + Section *prev = cur_text_section->prev; |
| 348 | + if (!prev) |
| 349 | + tcc_error(".popsection without .pushsection"); |
| 350 | + cur_text_section->prev = NULL; |
| 351 | + use_section1(s1, prev); |
| 352 | +} |
| 353 | + |
| 338 | 354 | static void asm_parse_directive(TCCState *s1) |
| 339 | 355 | { |
| 340 | 356 | int n, offset, v, size, tok1; |
| @@ -683,10 +699,12 @@ static void asm_parse_directive(TCCState *s1) · 342 unmodified lines |
| 683 | 699 | next(); |
| 684 | 700 | } |
| 685 | 701 | break; |
| 702 | + case TOK_ASMDIR_pushsection: |
| 686 | 703 | case TOK_ASMDIR_section: |
| 687 | 704 | { |
| 688 | 705 | char sname[256]; |
| 689 | 706 | |
| 707 | + tok1 = tok; |
| 690 | 708 | /* XXX: support more options */ |
| 691 | 709 | next(); |
| 692 | 710 | sname[0] = '\0'; |
| @@ -711,7 +729,10 @@ static void asm_parse_directive(TCCState *s1) · 18 unmodified lines |
| 711 | 729 | } |
| 712 | 730 | } |
| 713 | 731 | last_text_section = cur_text_section; |
| 714 | | − use_section(s1, sname); |
| 732 | + if (tok1 == TOK_ASMDIR_section) |
| 733 | + use_section(s1, sname); |
| 734 | + else |
| 735 | + push_section(s1, sname); |
| 715 | 736 | } |
| 716 | 737 | break; |
| 717 | 738 | case TOK_ASMDIR_previous: |
| @@ -725,6 +746,10 @@ static void asm_parse_directive(TCCState *s1) · 7 unmodified lines |
| 725 | 746 | last_text_section = sec; |
| 726 | 747 | } |
| 727 | 748 | break; |
| 749 | + case TOK_ASMDIR_popsection: |
| 750 | + next(); |
| 751 | + pop_section(s1); |
| 752 | + break; |
| 728 | 753 | #ifdef TCC_TARGET_I386 |
| 729 | 754 | case TOK_ASMDIR_code16: |
| 730 | 755 | { |