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
3232 }
3333
3434 ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe);
35+static int tcc_assemble_internal(TCCState *s1, int do_preprocess);
36+static Sym sym_dot;
3537
3638 /* We do not use the C expression parser to handle symbols. Maybe the
3739 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
101103 asm_expr(s1, pe);
102104 skip(')');
103105 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;
104114 default:
105115 if (tok >= TOK_IDENT) {
106116 /* label case : if the label was not found, add one */
@@ -474,6 +484,33 @@ static void asm_parse_directive(TCCState *s1) · 367 unmodified lines
474484 }
475485 }
476486 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+ }
477514 case TOK_ASMDIR_org:
478515 {
479516 unsigned long n;
tccpp.c+2−1
@@ -2784,7 +2784,8 @@ maybe_newline: · 2783 unmodified lines
27842784 cstr_reset(&tokcstr);
27852785 cstr_ccat(&tokcstr, '.');
27862786 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))) {
27882789 *--p = c = '.';
27892790 goto parse_ident_fast;
27902791 } else if (c == '.') {
tcctok.h+2−0
@@ -324,6 +324,8 @@ · 323 unmodified lines
324324 DEF_ASMDIR(bss)
325325 DEF_ASMDIR(previous)
326326 DEF_ASMDIR(fill)
327+ DEF_ASMDIR(rept)
328+ DEF_ASMDIR(endr)
327329 DEF_ASMDIR(org)
328330 DEF_ASMDIR(quad)
329331 #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