From 0cc24d0e8487eaf53bb2849fef7e438a8e8fc94d Mon Sep 17 00:00:00 2001 From: grischka Date: Thu, 20 Jul 2017 22:21:27 +0200 Subject: 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 ... */ --- tcc.h | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'tcc.h') diff --git a/tcc.h b/tcc.h index 4113028..4b272f5 100644 --- a/tcc.h +++ b/tcc.h @@ -556,15 +556,6 @@ typedef struct BufferedFile { #define CH_EOB '\\' /* end of buffer or '\0' char in file */ #define CH_EOF (-1) /* end of file */ -/* parsing state (used to save parser state to reparse part of the - source several times) */ -typedef struct ParseState { - const int *macro_ptr; - int line_num; - int tok; - CValue tokc; -} ParseState; - /* used to record tokens */ typedef struct TokenString { int *str; @@ -572,6 +563,7 @@ typedef struct TokenString { int lastlen; int allocated_len; int last_line_num; + int save_line_num; /* used to chain token-strings with begin/end_macro() */ struct TokenString *prev; const int *prev_ptr; @@ -675,6 +667,7 @@ struct TCCState { #ifdef TCC_TARGET_ARM enum float_abi float_abi; /* float ABI of the generated code*/ #endif + int run_test; /* nth test to run with -dt -run */ addr_t text_addr; /* address of text section */ int has_text_addr; @@ -813,7 +806,6 @@ struct TCCState { int option_pthread; /* -pthread option */ int argc; char **argv; - int do_test; }; struct filespec { @@ -1145,14 +1137,13 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) /* flags: */ #define AFF_PRINT_ERROR 0x10 /* print error if file not found */ #define AFF_REFERENCED_DLL 0x20 /* load a referenced dll from another dll */ -#define AFF_PREPROCESS 0x40 /* preprocess file */ -/* combined with: */ +#define AFF_TYPE_BIN 0x40 /* file to add is binary */ +/* s->filetype: */ #define AFF_TYPE_NONE 0 #define AFF_TYPE_C 1 #define AFF_TYPE_ASM 2 #define AFF_TYPE_ASMPP 3 -#define AFF_TYPE_BIN 4 -#define AFF_TYPE_LIB 5 +#define AFF_TYPE_LIB 4 /* values from tcc_object_type(...) */ #define AFF_BINTYPE_REL 1 #define AFF_BINTYPE_DYN 2 @@ -1220,9 +1211,7 @@ ST_FUNC TokenSym *tok_alloc(const char *str, int len); ST_FUNC const char *get_tok_str(int v, CValue *cv); ST_FUNC void begin_macro(TokenString *str, int alloc); ST_FUNC void end_macro(void); -ST_FUNC void set_idnum(int c, int val); -ST_FUNC void save_parse_state(ParseState *s); -ST_FUNC void restore_parse_state(ParseState *s); +ST_FUNC int set_idnum(int c, int val); ST_INLN void tok_str_new(TokenString *s); ST_FUNC TokenString *tok_str_alloc(void); ST_FUNC void tok_str_free(TokenString *s); @@ -1241,7 +1230,8 @@ ST_FUNC void preprocess(int is_bof); ST_FUNC void next_nomacro(void); ST_FUNC void next(void); ST_INLN void unget_tok(int last_tok); -ST_FUNC void preprocess_start(TCCState *s1); +ST_FUNC void preprocess_start(TCCState *s1, int is_asm); +ST_FUNC void preprocess_end(TCCState *s1); ST_FUNC void tccpp_new(TCCState *s); ST_FUNC void tccpp_delete(TCCState *s); ST_FUNC int tcc_preprocess(TCCState *s1); @@ -1298,9 +1288,7 @@ ST_FUNC void tcc_debug_funcstart(TCCState *s1, Sym *sym); ST_FUNC void tcc_debug_funcend(TCCState *s1, int size); ST_FUNC void tcc_debug_line(TCCState *s1); -ST_FUNC void tccgen_start(TCCState *s1); -ST_FUNC void tccgen_end(TCCState *s1); - +ST_FUNC int tccgen_compile(TCCState *s1); ST_FUNC void free_inline_functions(TCCState *s); ST_FUNC void check_vstack(void); @@ -1342,7 +1330,6 @@ ST_FUNC void expr_prod(void); ST_FUNC void expr_sum(void); ST_FUNC void gexpr(void); ST_FUNC int expr_const(void); -ST_FUNC void decl(int l); #if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_C67 ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size); #endif -- cgit v1.3.1