aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgrischka <grischka>2016-10-01 21:52:11 +0200
committergrischka <grischka>2016-10-01 21:52:11 +0200
commit643a1b8848d3d9cb703a7561c7f89191e8511cf1 (patch)
treecfe321d31366d2675588e2b8ec29946f57426e5f
parentafdbc5b8152debb2ef053720b95f37a4cf4106eb (diff)
downloadtinycc-643a1b8848d3d9cb703a7561c7f89191e8511cf1.tar.gz
tinycc-643a1b8848d3d9cb703a7561c7f89191e8511cf1.tar.bz2
tcc -E: add one space in cases: tiny solution
replaces f5f82abc99424c4ece836000934fcf57a867c635 Also: fix tcc flags in Makefile, fix tcc -E
-rw-r--r--Makefile2
-rw-r--r--tcc.c6
-rw-r--r--tccpp.c72
3 files changed, 26 insertions, 54 deletions
diff --git a/Makefile b/Makefile
index eccac07..57d9bc4 100644
--- a/Makefile
+++ b/Makefile
@@ -140,7 +140,7 @@ all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
# Host Tiny C Compiler
tcc$(EXESUF): tcc.c $(LIBTCC)
- $(CC) -o $@ $^ $(LIBS) $(CFLAGS) $(LDFLAGS) $(LINK_LIBTCC)
+ $(CC) -o $@ $^ $(LIBS) $(NATIVE_DEFINES) $(CFLAGS) $(LDFLAGS) $(LINK_LIBTCC)
# Cross Tiny C Compilers
%-tcc$(EXESUF): tcc.c
diff --git a/tcc.c b/tcc.c
index 35680ec..ab9b907 100644
--- a/tcc.c
+++ b/tcc.c
@@ -331,7 +331,11 @@ int main(int argc, char **argv)
s->alacarte_link = 1;
}
- if (0 == ret) {
+ if (s->output_type == TCC_OUTPUT_PREPROCESS) {
+ if (s->outfile)
+ fclose(s->ppfp);
+
+ } else if (0 == ret) {
if (s->do_bench)
tcc_print_stats(s, getclock_us() - start_time);
if (s->output_type == TCC_OUTPUT_MEMORY) {
diff --git a/tccpp.c b/tccpp.c
index c237903..d4ad514 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -3645,52 +3645,22 @@ static void pp_debug_builtins(TCCState *s1)
define_print(s1, v);
}
-static int need_space(int prev_tok, int tok, const char *tokstr)
+/* Add a space between tokens a and b to avoid unwanted textual pasting */
+static int pp_need_space(int a, int b)
{
- const char *sp_chars = "";
- if ((prev_tok >= TOK_IDENT || prev_tok == TOK_PPNUM) &&
- (tok >= TOK_IDENT || tok == TOK_PPNUM))
- return 1;
- switch (prev_tok) {
- case '+':
- sp_chars = "+=";
- break;
- case '-':
- sp_chars = "-=>";
- break;
- case '*':
- case '/':
- case '%':
- case '^':
- case '=':
- case '!':
- case TOK_A_SHL:
- case TOK_A_SAR:
- sp_chars = "=";
- break;
- case '&':
- sp_chars = "&=";
- break;
- case '|':
- sp_chars = "|=";
- break;
- case '<':
- sp_chars = "<=";
- break;
- case '>':
- sp_chars = ">=";
- break;
- case '.':
- sp_chars = ".";
- break;
- case '#':
- sp_chars = "#";
- break;
- case TOK_PPNUM:
- sp_chars = "+-";
- break;
- }
- return !!strchr(sp_chars, tokstr[0]);
+ return 'E' == a ? '+' == b || '-' == b
+ : '+' == a ? TOK_INC == b || '+' == b
+ : '-' == a ? TOK_DEC == b || '-' == b
+ : a >= TOK_IDENT ? b >= TOK_IDENT
+ : 0;
+}
+
+/* maybe hex like 0x1e */
+static int pp_check_he0xE(int t, const char *p)
+{
+ if (t == TOK_PPNUM && toup(strchr(p, 0)[-1]) == 'E')
+ return 'E';
+ return t;
}
/* Preprocess the current file */
@@ -3698,8 +3668,8 @@ ST_FUNC int tcc_preprocess(TCCState *s1)
{
BufferedFile **iptr;
int token_seen, spcs, level;
+ const char *p;
Sym *define_start;
- const char *tokstr;
preprocess_init(s1);
ch = file->buf_ptr[0];
@@ -3761,16 +3731,14 @@ ST_FUNC int tcc_preprocess(TCCState *s1)
pp_line(s1, file, 0);
} else if (tok == TOK_LINEFEED) {
++file->line_ref;
+ } else {
+ spcs = pp_need_space(token_seen, tok);
}
- tokstr = get_tok_str(tok, &tokc);
- if (!spcs && need_space(token_seen, tok, tokstr))
- ++spcs;
while (spcs)
fputs(" ", s1->ppfp), --spcs;
- fputs(tokstr, s1->ppfp);
-
- token_seen = tok;
+ fputs(p = get_tok_str(tok, &tokc), s1->ppfp);
+ token_seen = pp_check_he0xE(tok, p);;
}
/* reset define stack, but keep -D and built-ins */
free_defines(define_start);