-fdollar-in-identifiers addon

* disable a -fdollar-in-identifiers option in assembler files
    * a test is added

    This is a patch addon from Daniel Holden.
master
seyko 2015-04-20 03:44:08 +03:00
parent 9336fa7ae5
commit 5ce2154c74
4 changed files with 21 additions and 13 deletions

View File

@ -747,7 +747,7 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess)
ch = file->buf_ptr[0]; ch = file->buf_ptr[0];
tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF; tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
parse_flags = PARSE_FLAG_ASM_COMMENTS; parse_flags = PARSE_FLAG_ASM_COMMENTS | PARSE_FLAG_ASM_FILE;
if (do_preprocess) if (do_preprocess)
parse_flags |= PARSE_FLAG_PREPROCESS; parse_flags |= PARSE_FLAG_PREPROCESS;
next(); next();

18
tccpp.c
View File

@ -2313,9 +2313,11 @@ maybe_newline:
} }
break; break;
/* treat $ as allowed char in indentifier */ /* dollar is allowed to start identifiers when not parsing asm */
case '$': if (!tcc_state->dollars_in_identifiers) goto parse_simple; case '$':
if (!tcc_state->dollars_in_identifiers
|| (parse_flags & PARSE_FLAG_ASM_FILE)) goto parse_simple;
case 'a': case 'b': case 'c': case 'd': case 'a': case 'b': case 'c': case 'd':
case 'e': case 'f': case 'g': case 'h': case 'e': case 'f': case 'g': case 'h':
case 'i': case 'j': case 'k': case 'l': case 'i': case 'j': case 'k': case 'l':
@ -2338,7 +2340,8 @@ maybe_newline:
p++; p++;
for(;;) { for(;;) {
c = *p; c = *p;
if (!isidnum_table[c-CH_EOF]) if (!isidnum_table[c-CH_EOF]
&& (tcc_state->dollars_in_identifiers ? (c != '$') : 1))
break; break;
h = TOK_HASH_FUNC(h, c); h = TOK_HASH_FUNC(h, c);
p++; p++;
@ -2373,7 +2376,8 @@ maybe_newline:
p--; p--;
PEEKC(c, p); PEEKC(c, p);
parse_ident_slow: parse_ident_slow:
while (isidnum_table[c-CH_EOF]) { while (isidnum_table[c-CH_EOF]
|| (tcc_state->dollars_in_identifiers ? (c == '$') : 0)) {
cstr_ccat(&tokcstr, c); cstr_ccat(&tokcstr, c);
PEEKC(c, p); PEEKC(c, p);
} }
@ -3202,9 +3206,9 @@ ST_FUNC void preprocess_new(void)
const char *p, *r; const char *p, *r;
/* init isid table */ /* init isid table */
for(i=CH_EOF;i<256;i++) for(i=CH_EOF;i<256;i++)
isidnum_table[i-CH_EOF] = (isid(i) || isnum(i) || isidnum_table[i-CH_EOF] = isid(i) || isnum(i);
(tcc_state->dollars_in_identifiers ? i == '$' : 0));
/* add all tokens */ /* add all tokens */
if (table_ident) { if (table_ident) {

View File

@ -199,7 +199,7 @@ ex%: $(top_srcdir)/examples/ex%.c
# tiny assembler testing # tiny assembler testing
asmtest.ref: asmtest.S asmtest.ref: asmtest.S
$(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S $(CC) -m32 -Wa,-W -o asmtest.ref.o -c asmtest.S
objdump -D asmtest.ref.o > asmtest.ref objdump -D asmtest.ref.o > asmtest.ref
asmtest: asmtest.ref asmtest: asmtest.ref

View File

@ -94,8 +94,8 @@ TESTS = \
72_long_long_constant.test \ 72_long_long_constant.test \
73_arm64.test \ 73_arm64.test \
74_nocode_wanted.test \ 74_nocode_wanted.test \
75_array_in_struct_init.test 75_array_in_struct_init.test \
76_dollars_in_identifiers.test
# 34_array_assignment.test -- array assignment is not in C standard # 34_array_assignment.test -- array assignment is not in C standard
@ -121,15 +121,19 @@ ARGS =
31_args.test : ARGS = arg1 arg2 arg3 arg4 arg5 31_args.test : ARGS = arg1 arg2 arg3 arg4 arg5
46_grep.test : ARGS = '[^* ]*[:a:d: ]+\:\*-/: $$' 46_grep.c 46_grep.test : ARGS = '[^* ]*[:a:d: ]+\:\*-/: $$' 46_grep.c
# Some tests might need different flags
FLAGS =
76_dollars_in_identifiers.test : FLAGS = -fdollars-in-identifiers
all test: $(filter-out $(SKIP),$(TESTS)) all test: $(filter-out $(SKIP),$(TESTS))
%.test: %.c %.test: %.c
@echo Test: $*... @echo Test: $*...
@$(TCC) -run $< $(ARGS) 2>&1 | grep -v 'warning: soft float ABI currently not supported: default to softfp' >$*.output || true @$(TCC) -run $(FLAGS) $< $(ARGS) 2>&1 | grep -v 'warning: soft float ABI currently not supported: default to softfp' >$*.output || true
@diff -Nbu $*.expect $*.output && rm -f $*.output @diff -Nbu $*.expect $*.output && rm -f $*.output
@($(TCC) $< -o $*.exe && ./$*.exe $(ARGS)) 2>&1 | grep -v 'warning: soft float ABI currently not supported: default to softfp' >$*.output2 || true @($(TCC) $(FLAGS) $< -o $*.exe && ./$*.exe $(ARGS)) 2>&1 | grep -v 'warning: soft float ABI currently not supported: default to softfp' >$*.output2 || true
@diff -Nbu $*.expect $*.output2 && rm -f $*.output2 $*.exe @diff -Nbu $*.expect $*.output2 && rm -f $*.output2 $*.exe
clean: clean: