aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVlad Vissoultchev <wqweto@gmail.com>2016-04-06 18:57:11 +0300
committerVlad Vissoultchev <wqweto@gmail.com>2016-04-06 18:57:11 +0300
commite946eb2a4109e0de5f8514457f851897a4824c3e (patch)
treeb5b0b86b298e2d2c8bb5cb78e1573d10978de43e
parent0691b7630b89bf3de5f7691802cb923bd7c1fd99 (diff)
downloadtinycc-e946eb2a4109e0de5f8514457f851897a4824c3e.tar.gz
tinycc-e946eb2a4109e0de5f8514457f851897a4824c3e.tar.bz2
Implement -dM preprocessor option as in gcc
There was already support for -dD option but in contrast -dM dumps only `#define` directives w/o actual preprocessor output. The original -dD output differs from gcc output by additional comment in front of `#define`s so this quirk is left for -dM as well.
-rw-r--r--libtcc.c6
-rw-r--r--tcc.c3
-rw-r--r--tcc.h3
-rw-r--r--tccpp.c10
4 files changed, 14 insertions, 8 deletions
diff --git a/libtcc.c b/libtcc.c
index 8fd8183..7b232a2 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -1225,6 +1225,8 @@ LIBTCCAPI void tcc_delete(TCCState *s1)
/* close a preprocessor output */
if (s1->ppfp && s1->ppfp != stdout)
fclose(s1->ppfp);
+ if (s1->dffp && s1->dffp != s1->ppfp)
+ fclose(s1->dffp);
/* free all sections */
for(i = 1; i < s1->nb_sections; i++)
@@ -2175,8 +2177,8 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv)
s->output_type = TCC_OUTPUT_OBJ;
break;
case TCC_OPTION_d:
- if (*optarg == 'D')
- s->dflag = 1;
+ if (*optarg == 'D' || *optarg == 'M')
+ s->dflag = *optarg;
else {
if (s->warn_unsupported)
goto unsupported_option;
diff --git a/tcc.c b/tcc.c
index 9daf6e6..95e1a15 100644
--- a/tcc.c
+++ b/tcc.c
@@ -301,6 +301,9 @@ int main(int argc, char **argv)
if (!s->ppfp)
tcc_error("could not write '%s'", s->outfile);
}
+ s->dffp = s->ppfp;
+ if (s->dflag == 'M')
+ s->ppfp = NULL;
}
tcc_set_output_type(s, s->output_type);
diff --git a/tcc.h b/tcc.h
index 2e1e32f..f5d283e 100644
--- a/tcc.h
+++ b/tcc.h
@@ -712,7 +712,8 @@ struct TCCState {
LINE_MACRO_OUTPUT_FORMAT_NONE,
LINE_MACRO_OUTPUT_FORMAT_STD
} Pflag; /* -P switch */
- int dflag; /* -dX value */
+ char dflag; /* -dX value */
+ FILE *dffp;
/* for -MD/-MF: collected dependencies for this compilation */
char **target_deps;
diff --git a/tccpp.c b/tccpp.c
index 70a2258..80c7dd8 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -1092,7 +1092,7 @@ static void pp_line(TCCState *s1, BufferedFile *f, int level)
static void tok_print(const char *msg, const int *str)
{
- FILE *pr = tcc_state->ppfp;
+ FILE *pr = tcc_state->dffp;
int t;
CValue cval;
@@ -1108,13 +1108,13 @@ static void tok_print(const char *msg, const int *str)
static int define_print_prepared(Sym *s)
{
- if (!s || !tcc_state->ppfp || tcc_state->dflag == 0)
+ if (!s || !tcc_state->dffp || tcc_state->dflag == 0)
return 0;
if (s->v < TOK_IDENT || s->v >= tok_ident)
return 0;
- if (file) {
+ if (file && tcc_state->dflag == 'D') {
file->line_num--;
pp_line(tcc_state, file, 0);
file->line_ref = ++file->line_num;
@@ -1124,7 +1124,7 @@ static int define_print_prepared(Sym *s)
static void define_print(int v)
{
- FILE *pr = tcc_state->ppfp;
+ FILE *pr = tcc_state->dffp;
Sym *s, *a;
s = define_find(v);
@@ -1149,7 +1149,7 @@ static void define_print(int v)
static void undef_print(int v)
{
- FILE *pr = tcc_state->ppfp;
+ FILE *pr = tcc_state->dffp;
Sym *s;
s = define_find(v);