reverse of the "Identifiers can start and/or contain '.'"

- Identifiers can start and/or contain '.' in PARSE_FLAG_ASM_FILE
    - Move all GAS directives under TOK_ASMDIR prefix

    This patches breaks compilation of the tccboot (linux 2.4.26
    kernel). A test.S which fails with this patches:

    #define SRC(y...) \
    9999: y; \
    .section __ex_table, "a"; \
    .long 9999b, 6001f<---->; \
    .previous

    SRC(1:<>movw (%esi), %bx<------>)
    // 029-test.S:7: error: macro 'SRC' used with too many args
This commit is contained in:
seyko 2016-04-03 11:01:05 +03:00
parent 80343ab7d8
commit 2bf43b5483
4 changed files with 69 additions and 82 deletions

4
tcc.h
View File

@ -956,9 +956,7 @@ struct TCCState {
#define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
#define TOK_ASM_int TOK_INT
#define DEF_ASMDIR(x) DEF(TOK_ASMDIR_ ## x, "." #x)
#define TOK_ASMDIR_FIRST TOK_ASMDIR_byte
#define TOK_ASMDIR_LAST TOK_ASMDIR_section
#define TOK_ASM_weak TOK_WEAK1
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
/* only used for i386 asm opcodes definitions */

View File

@ -331,23 +331,24 @@ static void asm_parse_directive(TCCState *s1)
uint8_t *ptr;
/* assembler directive */
next();
sec = cur_text_section;
switch(tok) {
case TOK_ASMDIR_align:
case TOK_ASMDIR_p2align:
case TOK_ASMDIR_skip:
case TOK_ASMDIR_space:
case TOK_ASM_align:
case TOK_ASM_p2align:
case TOK_ASM_skip:
case TOK_ASM_space:
tok1 = tok;
next();
n = asm_int_expr(s1);
if (tok1 == TOK_ASMDIR_p2align)
if (tok1 == TOK_ASM_p2align)
{
if (n < 0 || n > 30)
tcc_error("invalid p2align, must be between 0 and 30");
n = 1 << n;
tok1 = TOK_ASMDIR_align;
tok1 = TOK_ASM_align;
}
if (tok1 == TOK_ASMDIR_align) {
if (tok1 == TOK_ASM_align) {
if (n < 0 || (n & (n-1)) != 0)
tcc_error("alignment must be a positive power of two");
offset = (ind + n - 1) & -n;
@ -371,7 +372,7 @@ static void asm_parse_directive(TCCState *s1)
}
ind += size;
break;
case TOK_ASMDIR_quad:
case TOK_ASM_quad:
next();
for(;;) {
uint64_t vl;
@ -398,15 +399,15 @@ static void asm_parse_directive(TCCState *s1)
next();
}
break;
case TOK_ASMDIR_byte:
case TOK_ASM_byte:
size = 1;
goto asm_data;
case TOK_ASMDIR_word:
case TOK_ASMDIR_short:
case TOK_ASM_word:
case TOK_SHORT:
size = 2;
goto asm_data;
case TOK_ASMDIR_long:
case TOK_ASMDIR_int:
case TOK_LONG:
case TOK_INT:
size = 4;
asm_data:
next();
@ -432,7 +433,7 @@ static void asm_parse_directive(TCCState *s1)
next();
}
break;
case TOK_ASMDIR_fill:
case TOK_ASM_fill:
{
int repeat, size, val, i, j;
uint8_t repeat_buf[8];
@ -474,7 +475,7 @@ static void asm_parse_directive(TCCState *s1)
}
}
break;
case TOK_ASMDIR_org:
case TOK_ASM_org:
{
unsigned long n;
next();
@ -487,10 +488,10 @@ static void asm_parse_directive(TCCState *s1)
goto zero_pad;
}
break;
case TOK_ASMDIR_globl:
case TOK_ASMDIR_global:
case TOK_ASMDIR_weak:
case TOK_ASMDIR_hidden:
case TOK_ASM_globl:
case TOK_ASM_global:
case TOK_ASM_weak:
case TOK_ASM_hidden:
tok1 = tok;
do {
Sym *sym;
@ -501,18 +502,18 @@ static void asm_parse_directive(TCCState *s1)
sym = label_push(&s1->asm_labels, tok, 0);
sym->type.t = VT_VOID;
}
if (tok1 != TOK_ASMDIR_hidden)
if (tok1 != TOK_ASM_hidden)
sym->type.t &= ~VT_STATIC;
if (tok1 == TOK_ASMDIR_weak)
if (tok1 == TOK_ASM_weak)
sym->type.t |= VT_WEAK;
else if (tok1 == TOK_ASMDIR_hidden)
else if (tok1 == TOK_ASM_hidden)
sym->type.t |= STV_HIDDEN << VT_VIS_SHIFT;
next();
} while (tok == ',');
break;
case TOK_ASMDIR_string:
case TOK_ASMDIR_ascii:
case TOK_ASMDIR_asciz:
case TOK_ASM_string:
case TOK_ASM_ascii:
case TOK_ASM_asciz:
{
const uint8_t *p;
int i, size, t;
@ -524,7 +525,7 @@ static void asm_parse_directive(TCCState *s1)
expect("string constant");
p = tokc.str.data;
size = tokc.str.size;
if (t == TOK_ASMDIR_ascii && size > 0)
if (t == TOK_ASM_ascii && size > 0)
size--;
for(i = 0; i < size; i++)
g(p[i]);
@ -537,9 +538,9 @@ static void asm_parse_directive(TCCState *s1)
}
}
break;
case TOK_ASMDIR_text:
case TOK_ASMDIR_data:
case TOK_ASMDIR_bss:
case TOK_ASM_text:
case TOK_ASM_data:
case TOK_ASM_bss:
{
char sname[64];
tok1 = tok;
@ -556,7 +557,7 @@ static void asm_parse_directive(TCCState *s1)
use_section(s1, sname);
}
break;
case TOK_ASMDIR_file:
case TOK_ASM_file:
{
char filename[512];
@ -574,7 +575,7 @@ static void asm_parse_directive(TCCState *s1)
next();
}
break;
case TOK_ASMDIR_ident:
case TOK_ASM_ident:
{
char ident[256];
@ -592,7 +593,7 @@ static void asm_parse_directive(TCCState *s1)
next();
}
break;
case TOK_ASMDIR_size:
case TOK_ASM_size:
{
Sym *sym;
@ -613,7 +614,7 @@ static void asm_parse_directive(TCCState *s1)
}
}
break;
case TOK_ASMDIR_type:
case TOK_ASM_type:
{
Sym *sym;
const char *newtype;
@ -631,7 +632,7 @@ static void asm_parse_directive(TCCState *s1)
newtype = tokc.str.data;
} else {
if (tok == '@' || tok == '%')
next();
skip(tok);
newtype = get_tok_str(tok, NULL);
}
@ -645,7 +646,7 @@ static void asm_parse_directive(TCCState *s1)
next();
}
break;
case TOK_ASMDIR_section:
case TOK_SECTION1:
{
char sname[256];
@ -665,18 +666,12 @@ static void asm_parse_directive(TCCState *s1)
if (tok != TOK_STR)
expect("string constant");
next();
if (tok == ',') {
next();
if (tok == '@' || tok == '%')
next();
next();
}
}
last_text_section = cur_text_section;
use_section(s1, sname);
}
break;
case TOK_ASMDIR_previous:
case TOK_ASM_previous:
{
Section *sec;
next();
@ -688,13 +683,13 @@ static void asm_parse_directive(TCCState *s1)
}
break;
#ifdef TCC_TARGET_I386
case TOK_ASMDIR_code16:
case TOK_ASM_code16:
{
next();
s1->seg_size = 16;
}
break;
case TOK_ASMDIR_code32:
case TOK_ASM_code32:
{
next();
s1->seg_size = 32;
@ -703,7 +698,7 @@ static void asm_parse_directive(TCCState *s1)
#endif
#ifdef TCC_TARGET_X86_64
/* added for compatibility with GAS */
case TOK_ASMDIR_code64:
case TOK_ASM_code64:
next();
break;
#endif
@ -768,7 +763,7 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess)
/* horrible gas comment */
while (tok != TOK_LINEFEED)
next();
} else if (tok >= TOK_ASMDIR_FIRST && tok <= TOK_ASMDIR_LAST) {
} else if (tok == '.') {
asm_parse_directive(s1);
} else if (tok == TOK_PPNUM) {
const char *p;

View File

@ -3345,9 +3345,8 @@ ST_FUNC void preprocess_init(TCCState *s1)
s1->pack_stack[0] = 0;
s1->pack_stack_ptr = s1->pack_stack;
isidnum_table['$' - CH_EOF] = (parse_flags & PARSE_FLAG_ASM_FILE) ||
isidnum_table['$' - CH_EOF] =
tcc_state->dollars_in_identifiers ? IS_ID : 0;
isidnum_table['.' - CH_EOF] = (parse_flags & PARSE_FLAG_ASM_FILE) ? IS_ID : 0;
}
ST_FUNC void preprocess_new(void)

View File

@ -301,40 +301,35 @@
#endif
/* Tiny Assembler */
DEF_ASMDIR(byte) /* must be first directive */
DEF_ASMDIR(word)
DEF_ASMDIR(align)
DEF_ASMDIR(p2align)
DEF_ASMDIR(skip)
DEF_ASMDIR(space)
DEF_ASMDIR(string)
DEF_ASMDIR(asciz)
DEF_ASMDIR(ascii)
DEF_ASMDIR(file)
DEF_ASMDIR(globl)
DEF_ASMDIR(global)
DEF_ASMDIR(weak)
DEF_ASMDIR(hidden)
DEF_ASMDIR(ident)
DEF_ASMDIR(size)
DEF_ASMDIR(type)
DEF_ASMDIR(text)
DEF_ASMDIR(data)
DEF_ASMDIR(bss)
DEF_ASMDIR(previous)
DEF_ASMDIR(fill)
DEF_ASMDIR(org)
DEF_ASMDIR(quad)
DEF_ASM(byte)
DEF_ASM(word)
DEF_ASM(align)
DEF_ASM(p2align)
DEF_ASM(skip)
DEF_ASM(space)
DEF_ASM(string)
DEF_ASM(asciz)
DEF_ASM(ascii)
DEF_ASM(file)
DEF_ASM(globl)
DEF_ASM(global)
DEF_ASM(hidden)
DEF_ASM(ident)
DEF_ASM(size)
DEF_ASM(type)
DEF_ASM(text)
DEF_ASM(data)
DEF_ASM(bss)
DEF_ASM(previous)
DEF_ASM(fill)
DEF_ASM(org)
DEF_ASM(quad)
#if defined(TCC_TARGET_I386)
DEF_ASMDIR(code16)
DEF_ASMDIR(code32)
DEF_ASM(code16)
DEF_ASM(code32)
#elif defined(TCC_TARGET_X86_64)
DEF_ASMDIR(code64)
DEF_ASM(code64)
#endif
DEF_ASMDIR(short)
DEF_ASMDIR(long)
DEF_ASMDIR(int)
DEF_ASMDIR(section) /* must be last directive */
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
#include "i386-tok.h"