History

revert of the 'Identifiers can start and/or contain'

When tccboot kernels compiles with 'Identifiers can start and/or', this kernel don't start. It is hard to find what is wrong. PS: there was no test for identifiers in *.S with '.'

seyko committed 10 years ago

Commit 131d7761 parent 174d06a4 files · +70 −92Browse files

Unified · Split

4 files
  1. tcc.h +1 −3
  2. tccasm.c +41 −46
  3. tccpp.c +2 −12
  4. tcctok.h +26 −31
tcc.h+1−3
@@ -958,9 +958,7 @@ struct TCCState { · 957 unmodified lines
958958
959959 #define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
960960 #define TOK_ASM_int TOK_INT
961−#define DEF_ASMDIR(x) DEF(TOK_ASMDIR_ ## x, "." #x)
962−#define TOK_ASMDIR_FIRST TOK_ASMDIR_byte
963−#define TOK_ASMDIR_LAST TOK_ASMDIR_section
961+#define TOK_ASM_weak TOK_WEAK1
964962
965963 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
966964 /* only used for i386 asm opcodes definitions */
tccasm.c+41−46
@@ -331,23 +331,24 @@ static void asm_parse_directive(TCCState *s1) · 330 unmodified lines
331331 uint8_t *ptr;
332332
333333 /* assembler directive */
334+ next();
334335 sec = cur_text_section;
335336 switch(tok) {
336− case TOK_ASMDIR_align:
337− case TOK_ASMDIR_p2align:
338− case TOK_ASMDIR_skip:
339− case TOK_ASMDIR_space:
337+ case TOK_ASM_align:
338+ case TOK_ASM_p2align:
339+ case TOK_ASM_skip:
340+ case TOK_ASM_space:
340341 tok1 = tok;
341342 next();
342343 n = asm_int_expr(s1);
343− if (tok1 == TOK_ASMDIR_p2align)
344+ if (tok1 == TOK_ASM_p2align)
344345 {
345346 if (n < 0 || n > 30)
346347 tcc_error("invalid p2align, must be between 0 and 30");
347348 n = 1 << n;
348− tok1 = TOK_ASMDIR_align;
349+ tok1 = TOK_ASM_align;
349350 }
350− if (tok1 == TOK_ASMDIR_align) {
351+ if (tok1 == TOK_ASM_align) {
351352 if (n < 0 || (n & (n-1)) != 0)
352353 tcc_error("alignment must be a positive power of two");
353354 offset = (ind + n - 1) & -n;
@@ -371,7 +372,7 @@ static void asm_parse_directive(TCCState *s1) · 17 unmodified lines
371372 }
372373 ind += size;
373374 break;
374− case TOK_ASMDIR_quad:
375+ case TOK_ASM_quad:
375376 next();
376377 for(;;) {
377378 uint64_t vl;
@@ -398,15 +399,15 @@ static void asm_parse_directive(TCCState *s1) · 20 unmodified lines
398399 next();
399400 }
400401 break;
401− case TOK_ASMDIR_byte:
402+ case TOK_ASM_byte:
402403 size = 1;
403404 goto asm_data;
404− case TOK_ASMDIR_word:
405− case TOK_ASMDIR_short:
405+ case TOK_ASM_word:
406+ case TOK_SHORT:
406407 size = 2;
407408 goto asm_data;
408− case TOK_ASMDIR_long:
409− case TOK_ASMDIR_int:
409+ case TOK_LONG:
410+ case TOK_INT:
410411 size = 4;
411412 asm_data:
412413 next();
@@ -432,7 +433,7 @@ static void asm_parse_directive(TCCState *s1) · 19 unmodified lines
432433 next();
433434 }
434435 break;
435− case TOK_ASMDIR_fill:
436+ case TOK_ASM_fill:
436437 {
437438 int repeat, size, val, i, j;
438439 uint8_t repeat_buf[8];
@@ -474,7 +475,7 @@ static void asm_parse_directive(TCCState *s1) · 35 unmodified lines
474475 }
475476 }
476477 break;
477− case TOK_ASMDIR_org:
478+ case TOK_ASM_org:
478479 {
479480 unsigned long n;
480481 next();
@@ -487,10 +488,10 @@ static void asm_parse_directive(TCCState *s1) · 6 unmodified lines
487488 goto zero_pad;
488489 }
489490 break;
490− case TOK_ASMDIR_globl:
491− case TOK_ASMDIR_global:
492− case TOK_ASMDIR_weak:
493− case TOK_ASMDIR_hidden:
491+ case TOK_ASM_globl:
492+ case TOK_ASM_global:
493+ case TOK_ASM_weak:
494+ case TOK_ASM_hidden:
494495 tok1 = tok;
495496 do {
496497 Sym *sym;
@@ -501,18 +502,18 @@ static void asm_parse_directive(TCCState *s1) · 4 unmodified lines
501502 sym = label_push(&s1->asm_labels, tok, 0);
502503 sym->type.t = VT_VOID;
503504 }
504− if (tok1 != TOK_ASMDIR_hidden)
505+ if (tok1 != TOK_ASM_hidden)
505506 sym->type.t &= ~VT_STATIC;
506− if (tok1 == TOK_ASMDIR_weak)
507+ if (tok1 == TOK_ASM_weak)
507508 sym->type.t |= VT_WEAK;
508− else if (tok1 == TOK_ASMDIR_hidden)
509+ else if (tok1 == TOK_ASM_hidden)
509510 sym->type.t |= STV_HIDDEN << VT_VIS_SHIFT;
510511 next();
511512 } while (tok == ',');
512513 break;
513− case TOK_ASMDIR_string:
514− case TOK_ASMDIR_ascii:
515− case TOK_ASMDIR_asciz:
514+ case TOK_ASM_string:
515+ case TOK_ASM_ascii:
516+ case TOK_ASM_asciz:
516517 {
517518 const uint8_t *p;
518519 int i, size, t;
@@ -524,7 +525,7 @@ static void asm_parse_directive(TCCState *s1) · 5 unmodified lines
524525 expect("string constant");
525526 p = tokc.str.data;
526527 size = tokc.str.size;
527− if (t == TOK_ASMDIR_ascii && size > 0)
528+ if (t == TOK_ASM_ascii && size > 0)
528529 size--;
529530 for(i = 0; i < size; i++)
530531 g(p[i]);
@@ -537,9 +538,9 @@ static void asm_parse_directive(TCCState *s1) · 6 unmodified lines
537538 }
538539 }
539540 break;
540− case TOK_ASMDIR_text:
541− case TOK_ASMDIR_data:
542− case TOK_ASMDIR_bss:
541+ case TOK_ASM_text:
542+ case TOK_ASM_data:
543+ case TOK_ASM_bss:
543544 {
544545 char sname[64];
545546 tok1 = tok;
@@ -556,7 +557,7 @@ static void asm_parse_directive(TCCState *s1) · 10 unmodified lines
556557 use_section(s1, sname);
557558 }
558559 break;
559− case TOK_ASMDIR_file:
560+ case TOK_ASM_file:
560561 {
561562 char filename[512];
562563
@@ -574,7 +575,7 @@ static void asm_parse_directive(TCCState *s1) · 11 unmodified lines
574575 next();
575576 }
576577 break;
577− case TOK_ASMDIR_ident:
578+ case TOK_ASM_ident:
578579 {
579580 char ident[256];
580581
@@ -592,7 +593,7 @@ static void asm_parse_directive(TCCState *s1) · 11 unmodified lines
592593 next();
593594 }
594595 break;
595− case TOK_ASMDIR_size:
596+ case TOK_ASM_size:
596597 {
597598 Sym *sym;
598599
@@ -613,7 +614,7 @@ static void asm_parse_directive(TCCState *s1) · 14 unmodified lines
613614 }
614615 }
615616 break;
616− case TOK_ASMDIR_type:
617+ case TOK_ASM_type:
617618 {
618619 Sym *sym;
619620 const char *newtype;
@@ -631,7 +632,7 @@ static void asm_parse_directive(TCCState *s1) · 11 unmodified lines
631632 newtype = tokc.str.data;
632633 } else {
633634 if (tok == '@' || tok == '%')
634− next();
635+ skip(tok);
635636 newtype = get_tok_str(tok, NULL);
636637 }
637638
@@ -645,7 +646,7 @@ static void asm_parse_directive(TCCState *s1) · 7 unmodified lines
645646 next();
646647 }
647648 break;
648− case TOK_ASMDIR_section:
649+ case TOK_SECTION1:
649650 {
650651 char sname[256];
651652
@@ -665,18 +666,12 @@ static void asm_parse_directive(TCCState *s1) · 13 unmodified lines
665666 if (tok != TOK_STR)
666667 expect("string constant");
667668 next();
668− if (tok == ',') {
669− next();
670− if (tok == '@' || tok == '%')
671− next();
672− next();
673− }
674669 }
675670 last_text_section = cur_text_section;
676671 use_section(s1, sname);
677672 }
678673 break;
679− case TOK_ASMDIR_previous:
674+ case TOK_ASM_previous:
680675 {
681676 Section *sec;
682677 next();
@@ -688,13 +683,13 @@ static void asm_parse_directive(TCCState *s1) · 5 unmodified lines
688683 }
689684 break;
690685 #ifdef TCC_TARGET_I386
691− case TOK_ASMDIR_code16:
686+ case TOK_ASM_code16:
692687 {
693688 next();
694689 s1->seg_size = 16;
695690 }
696691 break;
697− case TOK_ASMDIR_code32:
692+ case TOK_ASM_code32:
698693 {
699694 next();
700695 s1->seg_size = 32;
@@ -703,7 +698,7 @@ static void asm_parse_directive(TCCState *s1) · 2 unmodified lines
703698 #endif
704699 #ifdef TCC_TARGET_X86_64
705700 /* added for compatibility with GAS */
706− case TOK_ASMDIR_code64:
701+ case TOK_ASM_code64:
707702 next();
708703 break;
709704 #endif
@@ -768,7 +763,7 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess) · 58 unmodified lines
768763 /* horrible gas comment */
769764 while (tok != TOK_LINEFEED)
770765 next();
771− } else if (tok >= TOK_ASMDIR_FIRST && tok <= TOK_ASMDIR_LAST) {
766+ } else if (tok == '.') {
772767 asm_parse_directive(s1);
773768 } else if (tok == TOK_PPNUM) {
774769 const char *p;
tccpp.c+2−12
@@ -1328,9 +1328,6 @@ ST_FUNC void parse_define(void) · 1327 unmodified lines
13281328 parse_flags |= PARSE_FLAG_SPACES;
13291329 next_nomacro_spc();
13301330 if (tok == '(') {
1331− /* must be able to parse TOK_DOTS (in asm mode '.' can be part of identifier) */
1332− parse_flags &= ~PARSE_FLAG_ASM_FILE;
1333− isidnum_table['.' - CH_EOF] = 0;
13341331 next_nomacro();
13351332 ps = &first;
13361333 if (tok != ')') for (;;) {
@@ -1358,9 +1355,6 @@ ST_FUNC void parse_define(void) · 21 unmodified lines
13581355 }
13591356 next_nomacro_spc();
13601357 t = MACRO_FUNC;
1361− parse_flags |= (saved_parse_flags & PARSE_FLAG_ASM_FILE);
1362− isidnum_table['.' - CH_EOF] =
1363− (parse_flags & PARSE_FLAG_ASM_FILE) ? IS_ID : 0;
13641358 }
13651359 tok_str_new(&str);
13661360 spc = 2;
@@ -2511,8 +2505,7 @@ maybe_newline: · 1144 unmodified lines
25112505 p--;
25122506 PEEKC(c, p);
25132507 parse_ident_slow:
2514− while (isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))
2515− {
2508+ while (isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM)) {
25162509 cstr_ccat(&tokcstr, c);
25172510 PEEKC(c, p);
25182511 }
@@ -2571,7 +2564,7 @@ maybe_newline: · 52 unmodified lines
25712564 cstr_reset(&tokcstr);
25722565 cstr_ccat(&tokcstr, '.');
25732566 goto parse_num;
2574− } else if (parse_flags & PARSE_FLAG_ASM_FILE) {
2567+ } else if ((isidnum_table['.' - CH_EOF] & IS_ID) != 0) { /* asm mode */
25752568 *--p = c = '.';
25762569 goto parse_ident_fast;
25772570 } else if (c == '.') {
@@ -3368,9 +3361,6 @@ ST_FUNC void preprocess_init(TCCState *s1) · 790 unmodified lines
33683361
33693362 isidnum_table['$' - CH_EOF] =
33703363 tcc_state->dollars_in_identifiers ? IS_ID : 0;
3371−
3372− isidnum_table['.' - CH_EOF] =
3373− (parse_flags & PARSE_FLAG_ASM_FILE) ? IS_ID : 0;
33743364 }
33753365
33763366 ST_FUNC void preprocess_new(void)
tcctok.h+26−31
@@ -301,40 +301,35 @@ · 300 unmodified lines
301301 #endif
302302
303303 /* Tiny Assembler */
304− DEF_ASMDIR(byte) /* must be first directive */
305− DEF_ASMDIR(word)
306− DEF_ASMDIR(align)
307− DEF_ASMDIR(p2align)
308− DEF_ASMDIR(skip)
309− DEF_ASMDIR(space)
310− DEF_ASMDIR(string)
311− DEF_ASMDIR(asciz)
312− DEF_ASMDIR(ascii)
313− DEF_ASMDIR(file)
314− DEF_ASMDIR(globl)
315− DEF_ASMDIR(global)
316− DEF_ASMDIR(weak)
317− DEF_ASMDIR(hidden)
318− DEF_ASMDIR(ident)
319− DEF_ASMDIR(size)
320− DEF_ASMDIR(type)
321− DEF_ASMDIR(text)
322− DEF_ASMDIR(data)
323− DEF_ASMDIR(bss)
324− DEF_ASMDIR(previous)
325− DEF_ASMDIR(fill)
326− DEF_ASMDIR(org)
327− DEF_ASMDIR(quad)
304+ DEF_ASM(byte)
305+ DEF_ASM(word)
306+ DEF_ASM(align)
307+ DEF_ASM(p2align)
308+ DEF_ASM(skip)
309+ DEF_ASM(space)
310+ DEF_ASM(string)
311+ DEF_ASM(asciz)
312+ DEF_ASM(ascii)
313+ DEF_ASM(file)
314+ DEF_ASM(globl)
315+ DEF_ASM(global)
316+ DEF_ASM(hidden)
317+ DEF_ASM(ident)
318+ DEF_ASM(size)
319+ DEF_ASM(type)
320+ DEF_ASM(text)
321+ DEF_ASM(data)
322+ DEF_ASM(bss)
323+ DEF_ASM(previous)
324+ DEF_ASM(fill)
325+ DEF_ASM(org)
326+ DEF_ASM(quad)
328327 #if defined(TCC_TARGET_I386)
329− DEF_ASMDIR(code16)
330− DEF_ASMDIR(code32)
328+ DEF_ASM(code16)
329+ DEF_ASM(code32)
331330 #elif defined(TCC_TARGET_X86_64)
332− DEF_ASMDIR(code64)
331+ DEF_ASM(code64)
333332 #endif
334− DEF_ASMDIR(short)
335− DEF_ASMDIR(long)
336− DEF_ASMDIR(int)
337− DEF_ASMDIR(section) /* must be last directive */
338333
339334 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
340335 #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