History

.rept asm directive

and '.' alone is a token now in *.S (not an identifier) representing a current position in the code (PC).

seyko committed 10 years ago

Commit 1f494411 parent edcb15c3 files · +41 −1Browse files

Unified · Split

3 files
  1. tccasm.c +37 −0
  2. tccpp.c +2 −1
  3. tcctok.h +2 −0
tccasm.c+37−0
@@ -32,6 +32,8 @@ ST_FUNC int asm_get_local_label_name(TCCState *s1, unsigned int n) · 31 unmodified lines
32}32}
33 33
34ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe);34ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe);
35static int tcc_assemble_internal(TCCState *s1, int do_preprocess);
36static Sym sym_dot;
35 37
36/* We do not use the C expression parser to handle symbols. Maybe the38/* We do not use the C expression parser to handle symbols. Maybe the
37 C expression parser could be tweaked to do so. */39 C expression parser could be tweaked to do so. */
@@ -101,6 +103,14 @@ static void asm_expr_unary(TCCState *s1, ExprValue *pe) · 63 unmodified lines
101 asm_expr(s1, pe);103 asm_expr(s1, pe);
102 skip(')');104 skip(')');
103 break;105 break;
106 case '.':
107 pe->v = 0;
108 pe->sym = &sym_dot;
109 sym_dot.type.t = VT_VOID | VT_STATIC;
110 sym_dot.r = cur_text_section->sh_num;
111 sym_dot.jnext = ind;
112 next();
113 break;
104 default:114 default:
105 if (tok >= TOK_IDENT) {115 if (tok >= TOK_IDENT) {
106 /* label case : if the label was not found, add one */116 /* label case : if the label was not found, add one */
@@ -474,6 +484,33 @@ static void asm_parse_directive(TCCState *s1) · 367 unmodified lines
474 }484 }
475 }485 }
476 break;486 break;
487 case TOK_ASMDIR_rept:
488 {
489 int repeat;
490 TokenString init_str;
491 ParseState saved_parse_state = {0};
492 next();
493 repeat = asm_int_expr(s1);
494 tok_str_new(&init_str);
495 next();
496 while ((tok != TOK_ASMDIR_endr) && (tok != CH_EOF)) {
497 tok_str_add_tok(&init_str);
498 next();
499 }
500 if (tok == CH_EOF) tcc_error("we at end of file, .endr not found");
501 next();
502 tok_str_add(&init_str, -1);
503 tok_str_add(&init_str, 0);
504 save_parse_state(&saved_parse_state);
505 begin_macro(&init_str, 0);
506 while (repeat-- > 0) {
507 tcc_assemble_internal(s1, (parse_flags & PARSE_FLAG_PREPROCESS));
508 macro_ptr = init_str.str;
509 }
510 end_macro();
511 restore_parse_state(&saved_parse_state);
512 break;
513 }
477 case TOK_ASMDIR_org:514 case TOK_ASMDIR_org:
478 {515 {
479 unsigned long n;516 unsigned long n;
tccpp.c+2−1
@@ -2784,7 +2784,8 @@ maybe_newline: · 2783 unmodified lines
2784 cstr_reset(&tokcstr);2784 cstr_reset(&tokcstr);
2785 cstr_ccat(&tokcstr, '.');2785 cstr_ccat(&tokcstr, '.');
2786 goto parse_num;2786 goto parse_num;
2787 } else if (parse_flags & PARSE_FLAG_ASM_FILE) {2787 } else if ((parse_flags & PARSE_FLAG_ASM_FILE)
2788 && (isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))) {
2788 *--p = c = '.';2789 *--p = c = '.';
2789 goto parse_ident_fast;2790 goto parse_ident_fast;
2790 } else if (c == '.') {2791 } else if (c == '.') {
tcctok.h+2−0
@@ -324,6 +324,8 @@ · 323 unmodified lines
324 DEF_ASMDIR(bss)324 DEF_ASMDIR(bss)
325 DEF_ASMDIR(previous)325 DEF_ASMDIR(previous)
326 DEF_ASMDIR(fill)326 DEF_ASMDIR(fill)
327 DEF_ASMDIR(rept)
328 DEF_ASMDIR(endr)
327 DEF_ASMDIR(org)329 DEF_ASMDIR(org)
328 DEF_ASMDIR(quad)330 DEF_ASMDIR(quad)
329#if defined(TCC_TARGET_I386)331#if defined(TCC_TARGET_I386)

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