aboutsummaryrefslogtreecommitdiff
path: root/tccasm.c
diff options
context:
space:
mode:
authorgrischka <grischka>2017-07-20 22:21:27 +0200
committergrischka <grischka>2017-07-20 22:21:27 +0200
commit0cc24d0e8487eaf53bb2849fef7e438a8e8fc94d (patch)
treeba77f5e03cb8944f995b103abb668e37a9dceef2 /tccasm.c
parentba2b25e4ead7f0037d548289e517b31d29242880 (diff)
downloadtinycc-0cc24d0e8487eaf53bb2849fef7e438a8e8fc94d.tar.gz
tinycc-0cc24d0e8487eaf53bb2849fef7e438a8e8fc94d.tar.bz2
tcc -dt -run ... : simpler is better
* -dt now with lowercase t * test snippets now separated by real preprocessor statements which is valid C also for other compilers #if defined test_xxx < test snippet x > #elif defined test_yyy < test snippet y > #elif ... #endif * simpler implementation, behaves like -run if no 'test_...' macros are seen, works with -E too * for demonstration I combined some of the small tests for errors and warnings (56..63,74) in "60_errors_and_warnings.c" Also: * libtcc.c: put tcc_preprocess() and tcc_assemble() under the setjmp clause to let them return to caller after errors. This is for -dt -E. * tccgen.c: - get rid of save/restore_parse_state(), macro_ptr is saved by begin_macro anyway, now line_num too. - use expr_eq for parsing _Generic's controlling_type - set nocode_wanted with const_wanted. too, This is to keep VT_JMP on vtop when parsing preprocessor expressions. * tccpp.c: tcc -E: suppress trailing whitespace from lines with comments (that -E removes) such as NO_GOTPLT_ENTRY,\t /* never generate ... */
Diffstat (limited to 'tccasm.c')
-rw-r--r--tccasm.c38
1 files changed, 9 insertions, 29 deletions
diff --git a/tccasm.c b/tccasm.c
index 59264ce..1e20dc6 100644
--- a/tccasm.c
+++ b/tccasm.c
@@ -628,20 +628,16 @@ static void asm_parse_directive(TCCState *s1, int global)
{
int repeat;
TokenString *init_str;
- ParseState saved_parse_state = {0};
next();
repeat = asm_int_expr(s1);
init_str = tok_str_alloc();
- next();
- while ((tok != TOK_ASMDIR_endr) && (tok != CH_EOF)) {
+ while (next(), tok != TOK_ASMDIR_endr) {
+ if (tok == CH_EOF)
+ tcc_error("we at end of file, .endr not found");
tok_str_add_tok(init_str);
- next();
}
- if (tok == CH_EOF) tcc_error("we at end of file, .endr not found");
- next();
tok_str_add(init_str, -1);
tok_str_add(init_str, 0);
- save_parse_state(&saved_parse_state);
begin_macro(init_str, 1);
while (repeat-- > 0) {
tcc_assemble_internal(s1, (parse_flags & PARSE_FLAG_PREPROCESS),
@@ -649,7 +645,7 @@ static void asm_parse_directive(TCCState *s1, int global)
macro_ptr = init_str->str;
}
end_macro();
- restore_parse_state(&saved_parse_state);
+ next();
break;
}
case TOK_ASMDIR_org:
@@ -917,13 +913,10 @@ static void asm_parse_directive(TCCState *s1, int global)
static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global)
{
int opcode;
+ int saved_parse_flags = parse_flags;
/* XXX: undefine C labels */
-
- ch = file->buf_ptr[0];
- tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
parse_flags = PARSE_FLAG_ASM_FILE | PARSE_FLAG_TOK_STR;
- set_idnum('.', IS_ID);
if (do_preprocess)
parse_flags |= PARSE_FLAG_PREPROCESS;
for(;;) {
@@ -990,30 +983,22 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global)
}
asm_free_labels(s1);
+ parse_flags = saved_parse_flags;
return 0;
}
/* Assemble the current file */
ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess)
{
- Sym *define_start;
int ret;
-
- define_start = define_stack;
- preprocess_start(s1);
tcc_debug_start(s1);
-
/* default section is text */
cur_text_section = text_section;
ind = cur_text_section->data_offset;
nocode_wanted = 0;
-
ret = tcc_assemble_internal(s1, do_preprocess, 1);
-
cur_text_section->data_offset = ind;
-
tcc_debug_end(s1);
- free_defines(define_start);
return ret;
}
@@ -1025,21 +1010,16 @@ ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess)
end */
static void tcc_assemble_inline(TCCState *s1, char *str, int len, int global)
{
- int saved_parse_flags;
- const int *saved_macro_ptr;
-
- saved_parse_flags = parse_flags;
- saved_macro_ptr = macro_ptr;
+ const int *saved_macro_ptr = macro_ptr;
+ int dotid = set_idnum('.', IS_ID);
tcc_open_bf(s1, ":asm:", len);
memcpy(file->buffer, str, len);
-
macro_ptr = NULL;
tcc_assemble_internal(s1, 0, global);
tcc_close();
- parse_flags = saved_parse_flags;
- set_idnum('.', (parse_flags & PARSE_FLAG_ASM_FILE) ? IS_ID : 0);
+ set_idnum('.', dotid);
macro_ptr = saved_macro_ptr;
}