History

Move all GAS directives under TOK_ASMDIR prefix to include leading '.'

Use only these tokens in `asm_parse_directive` and don't recycle others' tokens (like TOK_SECTION1)

Vlad Vissoultchev committed 10 years ago

Commit aa1ed611 parent 05ec6653 files · +80 −68Browse files

Unified · Split

3 files
  1. tcc.h +3 −1
  2. tccasm.c +46 −41
  3. tcctok.h +31 −26
tcc.h+3−1
@@ -956,7 +956,9 @@ struct TCCState { · 955 unmodified lines
956 956
957#define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)957#define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
958#define TOK_ASM_int TOK_INT958#define TOK_ASM_int TOK_INT
959#define TOK_ASM_weak TOK_WEAK1959#define DEF_ASMDIR(x) DEF(TOK_ASMDIR_ ## x, "." #x)
960#define TOK_ASMDIR_FIRST TOK_ASMDIR_byte
961#define TOK_ASMDIR_LAST TOK_ASMDIR_section
960 962
961#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64963#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
962/* only used for i386 asm opcodes definitions */964/* only used for i386 asm opcodes definitions */
tccasm.c+46−41
@@ -331,24 +331,23 @@ static void asm_parse_directive(TCCState *s1) · 330 unmodified lines
331 uint8_t *ptr;331 uint8_t *ptr;
332 332
333 /* assembler directive */333 /* assembler directive */
334 next();
335 sec = cur_text_section;334 sec = cur_text_section;
336 switch(tok) {335 switch(tok) {
337 case TOK_ASM_align:336 case TOK_ASMDIR_align:
338 case TOK_ASM_p2align:337 case TOK_ASMDIR_p2align:
339 case TOK_ASM_skip:338 case TOK_ASMDIR_skip:
340 case TOK_ASM_space:339 case TOK_ASMDIR_space:
341 tok1 = tok;340 tok1 = tok;
342 next();341 next();
343 n = asm_int_expr(s1);342 n = asm_int_expr(s1);
344 if (tok1 == TOK_ASM_p2align)343 if (tok1 == TOK_ASMDIR_p2align)
345 {344 {
346 if (n < 0 || n > 30)345 if (n < 0 || n > 30)
347 tcc_error("invalid p2align, must be between 0 and 30");346 tcc_error("invalid p2align, must be between 0 and 30");
348 n = 1 << n;347 n = 1 << n;
349 tok1 = TOK_ASM_align;348 tok1 = TOK_ASMDIR_align;
350 }349 }
351 if (tok1 == TOK_ASM_align) {350 if (tok1 == TOK_ASMDIR_align) {
352 if (n < 0 || (n & (n-1)) != 0)351 if (n < 0 || (n & (n-1)) != 0)
353 tcc_error("alignment must be a positive power of two");352 tcc_error("alignment must be a positive power of two");
354 offset = (ind + n - 1) & -n;353 offset = (ind + n - 1) & -n;
@@ -372,7 +371,7 @@ static void asm_parse_directive(TCCState *s1) · 17 unmodified lines
372 }371 }
373 ind += size;372 ind += size;
374 break;373 break;
375 case TOK_ASM_quad:374 case TOK_ASMDIR_quad:
376 next();375 next();
377 for(;;) {376 for(;;) {
378 uint64_t vl;377 uint64_t vl;
@@ -399,15 +398,15 @@ static void asm_parse_directive(TCCState *s1) · 20 unmodified lines
399 next();398 next();
400 }399 }
401 break;400 break;
402 case TOK_ASM_byte:401 case TOK_ASMDIR_byte:
403 size = 1;402 size = 1;
404 goto asm_data;403 goto asm_data;
405 case TOK_ASM_word:404 case TOK_ASMDIR_word:
406 case TOK_SHORT:405 case TOK_ASMDIR_short:
407 size = 2;406 size = 2;
408 goto asm_data;407 goto asm_data;
409 case TOK_LONG:408 case TOK_ASMDIR_long:
410 case TOK_INT:409 case TOK_ASMDIR_int:
411 size = 4;410 size = 4;
412 asm_data:411 asm_data:
413 next();412 next();
@@ -433,7 +432,7 @@ static void asm_parse_directive(TCCState *s1) · 19 unmodified lines
433 next();432 next();
434 }433 }
435 break;434 break;
436 case TOK_ASM_fill:435 case TOK_ASMDIR_fill:
437 {436 {
438 int repeat, size, val, i, j;437 int repeat, size, val, i, j;
439 uint8_t repeat_buf[8];438 uint8_t repeat_buf[8];
@@ -475,7 +474,7 @@ static void asm_parse_directive(TCCState *s1) · 35 unmodified lines
475 }474 }
476 }475 }
477 break;476 break;
478 case TOK_ASM_org:477 case TOK_ASMDIR_org:
479 {478 {
480 unsigned long n;479 unsigned long n;
481 next();480 next();
@@ -488,10 +487,10 @@ static void asm_parse_directive(TCCState *s1) · 6 unmodified lines
488 goto zero_pad;487 goto zero_pad;
489 }488 }
490 break;489 break;
491 case TOK_ASM_globl:490 case TOK_ASMDIR_globl:
492 case TOK_ASM_global:491 case TOK_ASMDIR_global:
493 case TOK_ASM_weak:492 case TOK_ASMDIR_weak:
494 case TOK_ASM_hidden:493 case TOK_ASMDIR_hidden:
495 tok1 = tok;494 tok1 = tok;
496 do { 495 do {
497 Sym *sym;496 Sym *sym;
@@ -502,18 +501,18 @@ static void asm_parse_directive(TCCState *s1) · 4 unmodified lines
502 sym = label_push(&s1->asm_labels, tok, 0);501 sym = label_push(&s1->asm_labels, tok, 0);
503 sym->type.t = VT_VOID;502 sym->type.t = VT_VOID;
504 }503 }
505 if (tok1 != TOK_ASM_hidden)504 if (tok1 != TOK_ASMDIR_hidden)
506 sym->type.t &= ~VT_STATIC;505 sym->type.t &= ~VT_STATIC;
507 if (tok1 == TOK_ASM_weak)506 if (tok1 == TOK_ASMDIR_weak)
508 sym->type.t |= VT_WEAK;507 sym->type.t |= VT_WEAK;
509 else if (tok1 == TOK_ASM_hidden)508 else if (tok1 == TOK_ASMDIR_hidden)
510 sym->type.t |= STV_HIDDEN << VT_VIS_SHIFT;509 sym->type.t |= STV_HIDDEN << VT_VIS_SHIFT;
511 next();510 next();
512 } while (tok == ',');511 } while (tok == ',');
513 break;512 break;
514 case TOK_ASM_string:513 case TOK_ASMDIR_string:
515 case TOK_ASM_ascii:514 case TOK_ASMDIR_ascii:
516 case TOK_ASM_asciz:515 case TOK_ASMDIR_asciz:
517 {516 {
518 const uint8_t *p;517 const uint8_t *p;
519 int i, size, t;518 int i, size, t;
@@ -525,7 +524,7 @@ static void asm_parse_directive(TCCState *s1) · 5 unmodified lines
525 expect("string constant");524 expect("string constant");
526 p = tokc.str.data;525 p = tokc.str.data;
527 size = tokc.str.size;526 size = tokc.str.size;
528 if (t == TOK_ASM_ascii && size > 0)527 if (t == TOK_ASMDIR_ascii && size > 0)
529 size--;528 size--;
530 for(i = 0; i < size; i++)529 for(i = 0; i < size; i++)
531 g(p[i]);530 g(p[i]);
@@ -538,9 +537,9 @@ static void asm_parse_directive(TCCState *s1) · 6 unmodified lines
538 }537 }
539 }538 }
540 break;539 break;
541 case TOK_ASM_text:540 case TOK_ASMDIR_text:
542 case TOK_ASM_data:541 case TOK_ASMDIR_data:
543 case TOK_ASM_bss:542 case TOK_ASMDIR_bss:
544 { 543 {
545 char sname[64];544 char sname[64];
546 tok1 = tok;545 tok1 = tok;
@@ -557,7 +556,7 @@ static void asm_parse_directive(TCCState *s1) · 10 unmodified lines
557 use_section(s1, sname);556 use_section(s1, sname);
558 }557 }
559 break;558 break;
560 case TOK_ASM_file:559 case TOK_ASMDIR_file:
561 {560 {
562 char filename[512];561 char filename[512];
563 562
@@ -575,7 +574,7 @@ static void asm_parse_directive(TCCState *s1) · 11 unmodified lines
575 next();574 next();
576 }575 }
577 break;576 break;
578 case TOK_ASM_ident:577 case TOK_ASMDIR_ident:
579 {578 {
580 char ident[256];579 char ident[256];
581 580
@@ -593,7 +592,7 @@ static void asm_parse_directive(TCCState *s1) · 11 unmodified lines
593 next();592 next();
594 }593 }
595 break;594 break;
596 case TOK_ASM_size:595 case TOK_ASMDIR_size:
597 { 596 {
598 Sym *sym;597 Sym *sym;
599 598
@@ -614,7 +613,7 @@ static void asm_parse_directive(TCCState *s1) · 14 unmodified lines
614 }613 }
615 }614 }
616 break;615 break;
617 case TOK_ASM_type:616 case TOK_ASMDIR_type:
618 { 617 {
619 Sym *sym;618 Sym *sym;
620 const char *newtype;619 const char *newtype;
@@ -632,7 +631,7 @@ static void asm_parse_directive(TCCState *s1) · 11 unmodified lines
632 newtype = tokc.str.data;631 newtype = tokc.str.data;
633 } else {632 } else {
634 if (tok == '@' || tok == '%')633 if (tok == '@' || tok == '%')
635 skip(tok);634 next();
636 newtype = get_tok_str(tok, NULL);635 newtype = get_tok_str(tok, NULL);
637 }636 }
638 637
@@ -646,7 +645,7 @@ static void asm_parse_directive(TCCState *s1) · 7 unmodified lines
646 next();645 next();
647 }646 }
648 break;647 break;
649 case TOK_SECTION1:648 case TOK_ASMDIR_section:
650 {649 {
651 char sname[256];650 char sname[256];
652 651
@@ -666,12 +665,18 @@ static void asm_parse_directive(TCCState *s1) · 13 unmodified lines
666 if (tok != TOK_STR)665 if (tok != TOK_STR)
667 expect("string constant");666 expect("string constant");
668 next();667 next();
668 if (tok == ',') {
669 next();
670 if (tok == '@' || tok == '%')
671 next();
672 next();
673 }
669 }674 }
670 last_text_section = cur_text_section;675 last_text_section = cur_text_section;
671 use_section(s1, sname);676 use_section(s1, sname);
672 }677 }
673 break;678 break;
674 case TOK_ASM_previous:679 case TOK_ASMDIR_previous:
675 { 680 {
676 Section *sec;681 Section *sec;
677 next();682 next();
@@ -683,13 +688,13 @@ static void asm_parse_directive(TCCState *s1) · 5 unmodified lines
683 }688 }
684 break;689 break;
685#ifdef TCC_TARGET_I386690#ifdef TCC_TARGET_I386
686 case TOK_ASM_code16:691 case TOK_ASMDIR_code16:
687 {692 {
688 next();693 next();
689 s1->seg_size = 16;694 s1->seg_size = 16;
690 }695 }
691 break;696 break;
692 case TOK_ASM_code32:697 case TOK_ASMDIR_code32:
693 {698 {
694 next();699 next();
695 s1->seg_size = 32;700 s1->seg_size = 32;
@@ -698,7 +703,7 @@ static void asm_parse_directive(TCCState *s1) · 2 unmodified lines
698#endif703#endif
699#ifdef TCC_TARGET_X86_64704#ifdef TCC_TARGET_X86_64
700 /* added for compatibility with GAS */705 /* added for compatibility with GAS */
701 case TOK_ASM_code64:706 case TOK_ASMDIR_code64:
702 next();707 next();
703 break;708 break;
704#endif709#endif
@@ -763,7 +768,7 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess) · 58 unmodified lines
763 /* horrible gas comment */768 /* horrible gas comment */
764 while (tok != TOK_LINEFEED)769 while (tok != TOK_LINEFEED)
765 next();770 next();
766 } else if (tok == '.') {771 } else if (tok >= TOK_ASMDIR_FIRST && tok <= TOK_ASMDIR_LAST) {
767 asm_parse_directive(s1);772 asm_parse_directive(s1);
768 } else if (tok == TOK_PPNUM) {773 } else if (tok == TOK_PPNUM) {
769 const char *p;774 const char *p;
tcctok.h+31−26
@@ -301,35 +301,40 @@ · 300 unmodified lines
301#endif301#endif
302 302
303/* Tiny Assembler */303/* Tiny Assembler */
304 DEF_ASM(byte)304 DEF_ASMDIR(byte) /* must be first directive */
305 DEF_ASM(word)305 DEF_ASMDIR(word)
306 DEF_ASM(align)306 DEF_ASMDIR(align)
307 DEF_ASM(p2align)307 DEF_ASMDIR(p2align)
308 DEF_ASM(skip)308 DEF_ASMDIR(skip)
309 DEF_ASM(space)309 DEF_ASMDIR(space)
310 DEF_ASM(string)310 DEF_ASMDIR(string)
311 DEF_ASM(asciz)311 DEF_ASMDIR(asciz)
312 DEF_ASM(ascii)312 DEF_ASMDIR(ascii)
313 DEF_ASM(file)313 DEF_ASMDIR(file)
314 DEF_ASM(globl)314 DEF_ASMDIR(globl)
315 DEF_ASM(global)315 DEF_ASMDIR(global)
316 DEF_ASM(hidden)316 DEF_ASMDIR(weak)
317 DEF_ASM(ident)317 DEF_ASMDIR(hidden)
318 DEF_ASM(size)318 DEF_ASMDIR(ident)
319 DEF_ASM(type)319 DEF_ASMDIR(size)
320 DEF_ASM(text)320 DEF_ASMDIR(type)
321 DEF_ASM(data)321 DEF_ASMDIR(text)
322 DEF_ASM(bss)322 DEF_ASMDIR(data)
323 DEF_ASM(previous)323 DEF_ASMDIR(bss)
324 DEF_ASM(fill)324 DEF_ASMDIR(previous)
325 DEF_ASM(org)325 DEF_ASMDIR(fill)
326 DEF_ASM(quad)326 DEF_ASMDIR(org)
327 DEF_ASMDIR(quad)
327#if defined(TCC_TARGET_I386)328#if defined(TCC_TARGET_I386)
328 DEF_ASM(code16)329 DEF_ASMDIR(code16)
329 DEF_ASM(code32)330 DEF_ASMDIR(code32)
330#elif defined(TCC_TARGET_X86_64)331#elif defined(TCC_TARGET_X86_64)
331 DEF_ASM(code64)332 DEF_ASMDIR(code64)
332#endif333#endif
334 DEF_ASMDIR(short)
335 DEF_ASMDIR(long)
336 DEF_ASMDIR(int)
337 DEF_ASMDIR(section) /* must be last directive */
333 338
334#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64339#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
335#include "i386-tok.h"340#include "i386-tok.h"

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