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
958 958
959#define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)959#define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
960#define TOK_ASM_int TOK_INT960#define TOK_ASM_int TOK_INT
961#define DEF_ASMDIR(x) DEF(TOK_ASMDIR_ ## x, "." #x)961#define TOK_ASM_weak TOK_WEAK1
962#define TOK_ASMDIR_FIRST TOK_ASMDIR_byte
963#define TOK_ASMDIR_LAST TOK_ASMDIR_section
964 962
965#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64963#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
966/* only used for i386 asm opcodes definitions */964/* 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
331 uint8_t *ptr;331 uint8_t *ptr;
332 332
333 /* assembler directive */333 /* assembler directive */
334 next();
334 sec = cur_text_section;335 sec = cur_text_section;
335 switch(tok) {336 switch(tok) {
336 case TOK_ASMDIR_align:337 case TOK_ASM_align:
337 case TOK_ASMDIR_p2align:338 case TOK_ASM_p2align:
338 case TOK_ASMDIR_skip:339 case TOK_ASM_skip:
339 case TOK_ASMDIR_space:340 case TOK_ASM_space:
340 tok1 = tok;341 tok1 = tok;
341 next();342 next();
342 n = asm_int_expr(s1);343 n = asm_int_expr(s1);
343 if (tok1 == TOK_ASMDIR_p2align)344 if (tok1 == TOK_ASM_p2align)
344 {345 {
345 if (n < 0 || n > 30)346 if (n < 0 || n > 30)
346 tcc_error("invalid p2align, must be between 0 and 30");347 tcc_error("invalid p2align, must be between 0 and 30");
347 n = 1 << n;348 n = 1 << n;
348 tok1 = TOK_ASMDIR_align;349 tok1 = TOK_ASM_align;
349 }350 }
350 if (tok1 == TOK_ASMDIR_align) {351 if (tok1 == TOK_ASM_align) {
351 if (n < 0 || (n & (n-1)) != 0)352 if (n < 0 || (n & (n-1)) != 0)
352 tcc_error("alignment must be a positive power of two");353 tcc_error("alignment must be a positive power of two");
353 offset = (ind + n - 1) & -n;354 offset = (ind + n - 1) & -n;
@@ -371,7 +372,7 @@ static void asm_parse_directive(TCCState *s1) · 17 unmodified lines
371 }372 }
372 ind += size;373 ind += size;
373 break;374 break;
374 case TOK_ASMDIR_quad:375 case TOK_ASM_quad:
375 next();376 next();
376 for(;;) {377 for(;;) {
377 uint64_t vl;378 uint64_t vl;
@@ -398,15 +399,15 @@ static void asm_parse_directive(TCCState *s1) · 20 unmodified lines
398 next();399 next();
399 }400 }
400 break;401 break;
401 case TOK_ASMDIR_byte:402 case TOK_ASM_byte:
402 size = 1;403 size = 1;
403 goto asm_data;404 goto asm_data;
404 case TOK_ASMDIR_word:405 case TOK_ASM_word:
405 case TOK_ASMDIR_short:406 case TOK_SHORT:
406 size = 2;407 size = 2;
407 goto asm_data;408 goto asm_data;
408 case TOK_ASMDIR_long:409 case TOK_LONG:
409 case TOK_ASMDIR_int:410 case TOK_INT:
410 size = 4;411 size = 4;
411 asm_data:412 asm_data:
412 next();413 next();
@@ -432,7 +433,7 @@ static void asm_parse_directive(TCCState *s1) · 19 unmodified lines
432 next();433 next();
433 }434 }
434 break;435 break;
435 case TOK_ASMDIR_fill:436 case TOK_ASM_fill:
436 {437 {
437 int repeat, size, val, i, j;438 int repeat, size, val, i, j;
438 uint8_t repeat_buf[8];439 uint8_t repeat_buf[8];
@@ -474,7 +475,7 @@ static void asm_parse_directive(TCCState *s1) · 35 unmodified lines
474 }475 }
475 }476 }
476 break;477 break;
477 case TOK_ASMDIR_org:478 case TOK_ASM_org:
478 {479 {
479 unsigned long n;480 unsigned long n;
480 next();481 next();
@@ -487,10 +488,10 @@ static void asm_parse_directive(TCCState *s1) · 6 unmodified lines
487 goto zero_pad;488 goto zero_pad;
488 }489 }
489 break;490 break;
490 case TOK_ASMDIR_globl:491 case TOK_ASM_globl:
491 case TOK_ASMDIR_global:492 case TOK_ASM_global:
492 case TOK_ASMDIR_weak:493 case TOK_ASM_weak:
493 case TOK_ASMDIR_hidden:494 case TOK_ASM_hidden:
494 tok1 = tok;495 tok1 = tok;
495 do { 496 do {
496 Sym *sym;497 Sym *sym;
@@ -501,18 +502,18 @@ static void asm_parse_directive(TCCState *s1) · 4 unmodified lines
501 sym = label_push(&s1->asm_labels, tok, 0);502 sym = label_push(&s1->asm_labels, tok, 0);
502 sym->type.t = VT_VOID;503 sym->type.t = VT_VOID;
503 }504 }
504 if (tok1 != TOK_ASMDIR_hidden)505 if (tok1 != TOK_ASM_hidden)
505 sym->type.t &= ~VT_STATIC;506 sym->type.t &= ~VT_STATIC;
506 if (tok1 == TOK_ASMDIR_weak)507 if (tok1 == TOK_ASM_weak)
507 sym->type.t |= VT_WEAK;508 sym->type.t |= VT_WEAK;
508 else if (tok1 == TOK_ASMDIR_hidden)509 else if (tok1 == TOK_ASM_hidden)
509 sym->type.t |= STV_HIDDEN << VT_VIS_SHIFT;510 sym->type.t |= STV_HIDDEN << VT_VIS_SHIFT;
510 next();511 next();
511 } while (tok == ',');512 } while (tok == ',');
512 break;513 break;
513 case TOK_ASMDIR_string:514 case TOK_ASM_string:
514 case TOK_ASMDIR_ascii:515 case TOK_ASM_ascii:
515 case TOK_ASMDIR_asciz:516 case TOK_ASM_asciz:
516 {517 {
517 const uint8_t *p;518 const uint8_t *p;
518 int i, size, t;519 int i, size, t;
@@ -524,7 +525,7 @@ static void asm_parse_directive(TCCState *s1) · 5 unmodified lines
524 expect("string constant");525 expect("string constant");
525 p = tokc.str.data;526 p = tokc.str.data;
526 size = tokc.str.size;527 size = tokc.str.size;
527 if (t == TOK_ASMDIR_ascii && size > 0)528 if (t == TOK_ASM_ascii && size > 0)
528 size--;529 size--;
529 for(i = 0; i < size; i++)530 for(i = 0; i < size; i++)
530 g(p[i]);531 g(p[i]);
@@ -537,9 +538,9 @@ static void asm_parse_directive(TCCState *s1) · 6 unmodified lines
537 }538 }
538 }539 }
539 break;540 break;
540 case TOK_ASMDIR_text:541 case TOK_ASM_text:
541 case TOK_ASMDIR_data:542 case TOK_ASM_data:
542 case TOK_ASMDIR_bss:543 case TOK_ASM_bss:
543 { 544 {
544 char sname[64];545 char sname[64];
545 tok1 = tok;546 tok1 = tok;
@@ -556,7 +557,7 @@ static void asm_parse_directive(TCCState *s1) · 10 unmodified lines
556 use_section(s1, sname);557 use_section(s1, sname);
557 }558 }
558 break;559 break;
559 case TOK_ASMDIR_file:560 case TOK_ASM_file:
560 {561 {
561 char filename[512];562 char filename[512];
562 563
@@ -574,7 +575,7 @@ static void asm_parse_directive(TCCState *s1) · 11 unmodified lines
574 next();575 next();
575 }576 }
576 break;577 break;
577 case TOK_ASMDIR_ident:578 case TOK_ASM_ident:
578 {579 {
579 char ident[256];580 char ident[256];
580 581
@@ -592,7 +593,7 @@ static void asm_parse_directive(TCCState *s1) · 11 unmodified lines
592 next();593 next();
593 }594 }
594 break;595 break;
595 case TOK_ASMDIR_size:596 case TOK_ASM_size:
596 { 597 {
597 Sym *sym;598 Sym *sym;
598 599
@@ -613,7 +614,7 @@ static void asm_parse_directive(TCCState *s1) · 14 unmodified lines
613 }614 }
614 }615 }
615 break;616 break;
616 case TOK_ASMDIR_type:617 case TOK_ASM_type:
617 { 618 {
618 Sym *sym;619 Sym *sym;
619 const char *newtype;620 const char *newtype;
@@ -631,7 +632,7 @@ static void asm_parse_directive(TCCState *s1) · 11 unmodified lines
631 newtype = tokc.str.data;632 newtype = tokc.str.data;
632 } else {633 } else {
633 if (tok == '@' || tok == '%')634 if (tok == '@' || tok == '%')
634 next();635 skip(tok);
635 newtype = get_tok_str(tok, NULL);636 newtype = get_tok_str(tok, NULL);
636 }637 }
637 638
@@ -645,7 +646,7 @@ static void asm_parse_directive(TCCState *s1) · 7 unmodified lines
645 next();646 next();
646 }647 }
647 break;648 break;
648 case TOK_ASMDIR_section:649 case TOK_SECTION1:
649 {650 {
650 char sname[256];651 char sname[256];
651 652
@@ -665,18 +666,12 @@ static void asm_parse_directive(TCCState *s1) · 13 unmodified lines
665 if (tok != TOK_STR)666 if (tok != TOK_STR)
666 expect("string constant");667 expect("string constant");
667 next();668 next();
668 if (tok == ',') {
669 next();
670 if (tok == '@' || tok == '%')
671 next();
672 next();
673 }
674 }669 }
675 last_text_section = cur_text_section;670 last_text_section = cur_text_section;
676 use_section(s1, sname);671 use_section(s1, sname);
677 }672 }
678 break;673 break;
679 case TOK_ASMDIR_previous:674 case TOK_ASM_previous:
680 { 675 {
681 Section *sec;676 Section *sec;
682 next();677 next();
@@ -688,13 +683,13 @@ static void asm_parse_directive(TCCState *s1) · 5 unmodified lines
688 }683 }
689 break;684 break;
690#ifdef TCC_TARGET_I386685#ifdef TCC_TARGET_I386
691 case TOK_ASMDIR_code16:686 case TOK_ASM_code16:
692 {687 {
693 next();688 next();
694 s1->seg_size = 16;689 s1->seg_size = 16;
695 }690 }
696 break;691 break;
697 case TOK_ASMDIR_code32:692 case TOK_ASM_code32:
698 {693 {
699 next();694 next();
700 s1->seg_size = 32;695 s1->seg_size = 32;
@@ -703,7 +698,7 @@ static void asm_parse_directive(TCCState *s1) · 2 unmodified lines
703#endif698#endif
704#ifdef TCC_TARGET_X86_64699#ifdef TCC_TARGET_X86_64
705 /* added for compatibility with GAS */700 /* added for compatibility with GAS */
706 case TOK_ASMDIR_code64:701 case TOK_ASM_code64:
707 next();702 next();
708 break;703 break;
709#endif704#endif
@@ -768,7 +763,7 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess) · 58 unmodified lines
768 /* horrible gas comment */763 /* horrible gas comment */
769 while (tok != TOK_LINEFEED)764 while (tok != TOK_LINEFEED)
770 next();765 next();
771 } else if (tok >= TOK_ASMDIR_FIRST && tok <= TOK_ASMDIR_LAST) {766 } else if (tok == '.') {
772 asm_parse_directive(s1);767 asm_parse_directive(s1);
773 } else if (tok == TOK_PPNUM) {768 } else if (tok == TOK_PPNUM) {
774 const char *p;769 const char *p;
tccpp.c+2−12
@@ -1328,9 +1328,6 @@ ST_FUNC void parse_define(void) · 1327 unmodified lines
1328 parse_flags |= PARSE_FLAG_SPACES;1328 parse_flags |= PARSE_FLAG_SPACES;
1329 next_nomacro_spc();1329 next_nomacro_spc();
1330 if (tok == '(') {1330 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;
1334 next_nomacro();1331 next_nomacro();
1335 ps = &first;1332 ps = &first;
1336 if (tok != ')') for (;;) {1333 if (tok != ')') for (;;) {
@@ -1358,9 +1355,6 @@ ST_FUNC void parse_define(void) · 21 unmodified lines
1358 }1355 }
1359 next_nomacro_spc();1356 next_nomacro_spc();
1360 t = MACRO_FUNC;1357 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;
1364 }1358 }
1365 tok_str_new(&str);1359 tok_str_new(&str);
1366 spc = 2;1360 spc = 2;
@@ -2511,8 +2505,7 @@ maybe_newline: · 1144 unmodified lines
2511 p--;2505 p--;
2512 PEEKC(c, p);2506 PEEKC(c, p);
2513 parse_ident_slow:2507 parse_ident_slow:
2514 while (isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))2508 while (isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM)) {
2515 {
2516 cstr_ccat(&tokcstr, c);2509 cstr_ccat(&tokcstr, c);
2517 PEEKC(c, p);2510 PEEKC(c, p);
2518 }2511 }
@@ -2571,7 +2564,7 @@ maybe_newline: · 52 unmodified lines
2571 cstr_reset(&tokcstr);2564 cstr_reset(&tokcstr);
2572 cstr_ccat(&tokcstr, '.');2565 cstr_ccat(&tokcstr, '.');
2573 goto parse_num;2566 goto parse_num;
2574 } else if (parse_flags & PARSE_FLAG_ASM_FILE) {2567 } else if ((isidnum_table['.' - CH_EOF] & IS_ID) != 0) { /* asm mode */
2575 *--p = c = '.';2568 *--p = c = '.';
2576 goto parse_ident_fast;2569 goto parse_ident_fast;
2577 } else if (c == '.') {2570 } else if (c == '.') {
@@ -3368,9 +3361,6 @@ ST_FUNC void preprocess_init(TCCState *s1) · 790 unmodified lines
3368 3361
3369 isidnum_table['$' - CH_EOF] =3362 isidnum_table['$' - CH_EOF] =
3370 tcc_state->dollars_in_identifiers ? IS_ID : 0;3363 tcc_state->dollars_in_identifiers ? IS_ID : 0;
3371
3372 isidnum_table['.' - CH_EOF] =
3373 (parse_flags & PARSE_FLAG_ASM_FILE) ? IS_ID : 0;
3374}3364}
3375 3365
3376ST_FUNC void preprocess_new(void)3366ST_FUNC void preprocess_new(void)
tcctok.h+26−31
@@ -301,40 +301,35 @@ · 300 unmodified lines
301#endif301#endif
302 302
303/* Tiny Assembler */303/* Tiny Assembler */
304 DEF_ASMDIR(byte) /* must be first directive */304 DEF_ASM(byte)
305 DEF_ASMDIR(word)305 DEF_ASM(word)
306 DEF_ASMDIR(align)306 DEF_ASM(align)
307 DEF_ASMDIR(p2align)307 DEF_ASM(p2align)
308 DEF_ASMDIR(skip)308 DEF_ASM(skip)
309 DEF_ASMDIR(space)309 DEF_ASM(space)
310 DEF_ASMDIR(string)310 DEF_ASM(string)
311 DEF_ASMDIR(asciz)311 DEF_ASM(asciz)
312 DEF_ASMDIR(ascii)312 DEF_ASM(ascii)
313 DEF_ASMDIR(file)313 DEF_ASM(file)
314 DEF_ASMDIR(globl)314 DEF_ASM(globl)
315 DEF_ASMDIR(global)315 DEF_ASM(global)
316 DEF_ASMDIR(weak)316 DEF_ASM(hidden)
317 DEF_ASMDIR(hidden)317 DEF_ASM(ident)
318 DEF_ASMDIR(ident)318 DEF_ASM(size)
319 DEF_ASMDIR(size)319 DEF_ASM(type)
320 DEF_ASMDIR(type)320 DEF_ASM(text)
321 DEF_ASMDIR(text)321 DEF_ASM(data)
322 DEF_ASMDIR(data)322 DEF_ASM(bss)
323 DEF_ASMDIR(bss)323 DEF_ASM(previous)
324 DEF_ASMDIR(previous)324 DEF_ASM(fill)
325 DEF_ASMDIR(fill)325 DEF_ASM(org)
326 DEF_ASMDIR(org)326 DEF_ASM(quad)
327 DEF_ASMDIR(quad)
328#if defined(TCC_TARGET_I386)327#if defined(TCC_TARGET_I386)
329 DEF_ASMDIR(code16)328 DEF_ASM(code16)
330 DEF_ASMDIR(code32)329 DEF_ASM(code32)
331#elif defined(TCC_TARGET_X86_64)330#elif defined(TCC_TARGET_X86_64)
332 DEF_ASMDIR(code64)331 DEF_ASM(code64)
333#endif332#endif
334 DEF_ASMDIR(short)
335 DEF_ASMDIR(long)
336 DEF_ASMDIR(int)
337 DEF_ASMDIR(section) /* must be last directive */
338 333
339#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64334#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
340#include "i386-tok.h"335#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