mirror of
https://github.com/frida/tinycc
synced 2024-12-24 05:56:49 +03:00
tcc -E: add one space in cases: tiny solution
replaces f5f82abc99
Also: fix tcc flags in Makefile, fix tcc -E
This commit is contained in:
parent
afdbc5b815
commit
643a1b8848
2
Makefile
2
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
|
||||
|
6
tcc.c
6
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) {
|
||||
|
72
tccpp.c
72
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);
|
||||
|
Loading…
Reference in New Issue
Block a user