[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] [PATCH] add a gcc preprocessor -P directive
From: |
Thomas Preud'homme |
Subject: |
Re: [Tinycc-devel] [PATCH] add a gcc preprocessor -P directive |
Date: |
Sun, 04 Jan 2015 00:20:57 +0000 |
User-agent: |
KMail/4.14.1 (Linux/2.6.38-ac2-ac100; KDE/4.14.2; armv7l; ; ) |
Le mardi 30 décembre 2014, 18:40:14 Sergey Korshunoff a écrit :
> tcc -E -P
> Added a gcc preprocessor option -P. If given then there is
> no #line directive in preprocessor output.
>
> tcc -E -P1
> don't follow a gcc preprocessor style and do output a standard
> #line directive. In such case we don't lose a location info when
> we going to compile a resulting file wtith a compiler not
> understanding a gnu style line info.
diff -urN tinycc.old/libtcc.c tinycc/libtcc.c
--- tinycc.old/tcc.h 2014-12-30 17:57:24.000000000 +0300
+++ tinycc/tcc.h 2014-12-30 17:46:01.000000000 +0300
@@ -645,6 +645,7 @@
/* output file for preprocessing (-E) */
FILE *ppfp;
+ int Pflag; /* if true, no #line directive in preprocessor output */
/* for -MD/-MF: collected dependencies for this compilation */
char **target_deps;
The code below shows that Pflag may have 3 values so the comment should reflect
that. Did you call it Pflag with the idea that it could be used to encode
something else later? If yes, you should use its value with a 0x3 mask. If
not, better rename it to something that shows it's about the line macro like
int line_macro_style or something better.
diff -urN tinycc.old/tccpp.c tinycc/tccpp.c
--- tinycc.old/tccpp.c 2014-12-30 17:57:24.000000000 +0300
+++ tinycc/tccpp.c 2014-12-30 18:19:40.000000000 +0300
@@ -3184,7 +3184,15 @@
: ""
;
iptr = iptr_new;
- fprintf(s1->ppfp, "# %d \"%s\"%s\n", file->line_num, file-
>filename, s);
+ if (tcc_state->Pflag == 0)
+ fprintf(s1->ppfp, "# %d \"%s\"%s\n", file->line_num, file-
>filename, s);
+ else
+ if (tcc_state->Pflag == 1)
+ ; /* "tcc -E -P" case: don't output a line directive */
+ else
+ if (tcc_state->Pflag == 2)
+ fprintf(s1->ppfp, "# line %d \"%s\"\n", file->line_num,
file-
>filename);
+ /* "tcc -E -P1" case */
} else {
while (d)
fputs("\n", s1->ppfp), --d;
Better use a switch case here. By the way, when doing a switch made of it
statement it's traditional to put the if right after the else like this:
if (condition1)
foo;
else if (condition2)
bar;
else
baz;
Also why not define a union for that flag, it would read better to see if
(tcc_stage->Pflag == LINE_MACRO_NONE) or the same with
LINE_MACRO_GCC/LINE_MACRO_STD? Well, I leave that one up to you.
Best regards,
Thomas
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [Tinycc-devel] [PATCH] add a gcc preprocessor -P directive,
Thomas Preud'homme <=