mirror of
https://github.com/frida/tinycc
synced 2024-12-24 05:56:49 +03:00
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.
This commit is contained in:
parent
0691b7630b
commit
e946eb2a41
6
libtcc.c
6
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;
|
||||
|
3
tcc.c
3
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);
|
||||
|
3
tcc.h
3
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;
|
||||
|
10
tccpp.c
10
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);
|
||||
|
Loading…
Reference in New Issue
Block a user