In file included from math.c:8: In file included from /usr/include/math.h:43: /usr/include/bits/nan.h:52: warning: NAN redefined
Unified · Split
| @@ -1656,6 +1656,7 @@ enum { · 1655 unmodified lines | |||
| 1656 | TCC_OPTION_b, | 1656 | TCC_OPTION_b, |
| 1657 | TCC_OPTION_g, | 1657 | TCC_OPTION_g, |
| 1658 | TCC_OPTION_c, | 1658 | TCC_OPTION_c, |
| 1659 | TCC_OPTION_d, | ||
| 1659 | TCC_OPTION_float_abi, | 1660 | TCC_OPTION_float_abi, |
| 1660 | TCC_OPTION_static, | 1661 | TCC_OPTION_static, |
| 1661 | TCC_OPTION_shared, | 1662 | TCC_OPTION_shared, |
| @@ -1709,6 +1710,7 @@ static const TCCOption tcc_options[] = { · 47 unmodified lines | |||
| 1709 | #endif | 1710 | #endif |
| 1710 | { "g", TCC_OPTION_g, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, | 1711 | { "g", TCC_OPTION_g, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, |
| 1711 | { "c", TCC_OPTION_c, 0 }, | 1712 | { "c", TCC_OPTION_c, 0 }, |
| 1713 | { "d", TCC_OPTION_d, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, | ||
| 1712 | #ifdef TCC_TARGET_ARM | 1714 | #ifdef TCC_TARGET_ARM |
| 1713 | { "mfloat-abi", TCC_OPTION_float_abi, TCC_OPTION_HAS_ARG }, | 1715 | { "mfloat-abi", TCC_OPTION_float_abi, TCC_OPTION_HAS_ARG }, |
| 1714 | #endif | 1716 | #endif |
| @@ -1848,6 +1850,14 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 133 unmodified lines | |||
| 1848 | tcc_warning("-c: some compiler action already specified (%d)", s->output_type); | 1850 | tcc_warning("-c: some compiler action already specified (%d)", s->output_type); |
| 1849 | s->output_type = TCC_OUTPUT_OBJ; | 1851 | s->output_type = TCC_OUTPUT_OBJ; |
| 1850 | break; | 1852 | break; |
| 1853 | case TCC_OPTION_d: | ||
| 1854 | if (*optarg != 'D') { | ||
| 1855 | if (s->warn_unsupported) | ||
| 1856 | goto unsupported_option; | ||
| 1857 | tcc_error("invalid option -- '%s'", r); | ||
| 1858 | } | ||
| 1859 | s->dflag = 1; | ||
| 1860 | break; | ||
| 1851 | #ifdef TCC_TARGET_ARM | 1861 | #ifdef TCC_TARGET_ARM |
| 1852 | case TCC_OPTION_float_abi: | 1862 | case TCC_OPTION_float_abi: |
| 1853 | /* tcc doesn't support soft float yet */ | 1863 | /* tcc doesn't support soft float yet */ |
| @@ -47,6 +47,7 @@ static void help(void) · 46 unmodified lines | |||
| 47 | " -Usym undefine 'sym'\n" | 47 | " -Usym undefine 'sym'\n" |
| 48 | " -P do not output a #line directive\n" | 48 | " -P do not output a #line directive\n" |
| 49 | " -P1 use a #line directive in output instead of the gcc style\n" | 49 | " -P1 use a #line directive in output instead of the gcc style\n" |
| 50 | " -dD put a define directive in the output (inside a comment)\n" | ||
| 50 | "Linker options:\n" | 51 | "Linker options:\n" |
| 51 | " -Ldir add library path 'dir'\n" | 52 | " -Ldir add library path 'dir'\n" |
| 52 | " -llib link with dynamic or static library 'lib'\n" | 53 | " -llib link with dynamic or static library 'lib'\n" |
| @@ -307,6 +308,8 @@ int main(int argc, char **argv) · 254 unmodified lines | |||
| 307 | start_time = getclock_us(); | 308 | start_time = getclock_us(); |
| 308 | 309 | ||
| 309 | tcc_set_output_type(s, s->output_type); | 310 | tcc_set_output_type(s, s->output_type); |
| 311 | if (s->output_type == TCC_OUTPUT_PREPROCESS) | ||
| 312 | print_defines(); | ||
| 310 | 313 | ||
| 311 | /* compile or add each files or library */ | 314 | /* compile or add each files or library */ |
| 312 | for(i = ret = 0; i < s->nb_files && ret == 0; i++) { | 315 | for(i = ret = 0; i < s->nb_files && ret == 0; i++) { |
| @@ -661,6 +661,7 @@ struct TCCState { · 660 unmodified lines | |||
| 661 | LINE_MACRO_OUTPUT_FORMAT_NONE, | 661 | LINE_MACRO_OUTPUT_FORMAT_NONE, |
| 662 | LINE_MACRO_OUTPUT_FORMAT_STD, | 662 | LINE_MACRO_OUTPUT_FORMAT_STD, |
| 663 | } Pflag; | 663 | } Pflag; |
| 664 | int dflag; /* for keeping a -dD value */ | ||
| 664 | 665 | ||
| 665 | /* for -MD/-MF: collected dependencies for this compilation */ | 666 | /* for -MD/-MF: collected dependencies for this compilation */ |
| 666 | char **target_deps; | 667 | char **target_deps; |
| @@ -1155,6 +1156,7 @@ ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg); · 488 unmodified lines | |||
| 1155 | ST_FUNC void define_undef(Sym *s); | 1156 | ST_FUNC void define_undef(Sym *s); |
| 1156 | ST_INLN Sym *define_find(int v); | 1157 | ST_INLN Sym *define_find(int v); |
| 1157 | ST_FUNC void free_defines(Sym *b); | 1158 | ST_FUNC void free_defines(Sym *b); |
| 1159 | void print_defines(void); | ||
| 1158 | ST_FUNC Sym *label_find(int v); | 1160 | ST_FUNC Sym *label_find(int v); |
| 1159 | ST_FUNC Sym *label_push(Sym **ptop, int v, int flags); | 1161 | ST_FUNC Sym *label_push(Sym **ptop, int v, int flags); |
| 1160 | ST_FUNC void label_pop(Sym **ptop, Sym *slast); | 1162 | ST_FUNC void label_pop(Sym **ptop, Sym *slast); |
| @@ -1049,6 +1049,55 @@ static int macro_is_equal(const int *a, const int *b) · 1048 unmodified lines | |||
| 1049 | return !(*a || *b); | 1049 | return !(*a || *b); |
| 1050 | } | 1050 | } |
| 1051 | 1051 | ||
| 1052 | static void define_print(Sym *s, int is_undef) | ||
| 1053 | { | ||
| 1054 | int c, t; | ||
| 1055 | CValue cval; | ||
| 1056 | const int *str; | ||
| 1057 | Sym *arg; | ||
| 1058 | |||
| 1059 | if (tcc_state->dflag == 0 || !s || !tcc_state->ppfp) | ||
| 1060 | return; | ||
| 1061 | |||
| 1062 | if (file) { | ||
| 1063 | c = file->line_num - file->line_ref - 1; | ||
| 1064 | if (c > 0) { | ||
| 1065 | while (c--) | ||
| 1066 | fputs("\n", tcc_state->ppfp); | ||
| 1067 | file->line_ref = file->line_num; | ||
| 1068 | } | ||
| 1069 | } | ||
| 1070 | |||
| 1071 | if (is_undef) { | ||
| 1072 | fprintf(tcc_state->ppfp, "// #undef %s\n", get_tok_str(s->v, NULL)); | ||
| 1073 | return; | ||
| 1074 | } | ||
| 1075 | |||
| 1076 | fprintf(tcc_state->ppfp, "// #define %s", get_tok_str(s->v, NULL)); | ||
| 1077 | arg = s->next; | ||
| 1078 | if (arg) { | ||
| 1079 | char *sep = "("; | ||
| 1080 | while (arg) { | ||
| 1081 | fprintf(tcc_state->ppfp, "%s%s", sep, get_tok_str(arg->v & ~SYM_FIELD, NULL)); | ||
| 1082 | sep = ","; | ||
| 1083 | arg = arg->next; | ||
| 1084 | } | ||
| 1085 | fprintf(tcc_state->ppfp, ")"); | ||
| 1086 | } | ||
| 1087 | |||
| 1088 | str = s->d; | ||
| 1089 | if (str) | ||
| 1090 | fprintf(tcc_state->ppfp, " "); | ||
| 1091 | |||
| 1092 | while (str) { | ||
| 1093 | TOK_GET(&t, &str, &cval); | ||
| 1094 | if (!t) | ||
| 1095 | break; | ||
| 1096 | fprintf(tcc_state->ppfp, "%s", get_tok_str(t, &cval)); | ||
| 1097 | } | ||
| 1098 | fprintf(tcc_state->ppfp, "\n"); | ||
| 1099 | } | ||
| 1100 | |||
| 1052 | /* defines handling */ | 1101 | /* defines handling */ |
| 1053 | ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg) | 1102 | ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg) |
| 1054 | { | 1103 | { |
| @@ -1062,6 +1111,7 @@ ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg) · 7 unmodified lines | |||
| 1062 | s->d = str; | 1111 | s->d = str; |
| 1063 | s->next = first_arg; | 1112 | s->next = first_arg; |
| 1064 | table_ident[v - TOK_IDENT]->sym_define = s; | 1113 | table_ident[v - TOK_IDENT]->sym_define = s; |
| 1114 | define_print(s, 0); | ||
| 1065 | } | 1115 | } |
| 1066 | 1116 | ||
| 1067 | /* undefined a define symbol. Its name is just set to zero */ | 1117 | /* undefined a define symbol. Its name is just set to zero */ |
| @@ -1069,8 +1119,10 @@ ST_FUNC void define_undef(Sym *s) · 1 unmodified line | |||
| 1069 | { | 1119 | { |
| 1070 | int v; | 1120 | int v; |
| 1071 | v = s->v; | 1121 | v = s->v; |
| 1072 | if (v >= TOK_IDENT && v < tok_ident) | 1122 | if (v >= TOK_IDENT && v < tok_ident) { |
| 1123 | define_print(s, 1); | ||
| 1073 | table_ident[v - TOK_IDENT]->sym_define = NULL; | 1124 | table_ident[v - TOK_IDENT]->sym_define = NULL; |
| 1125 | } | ||
| 1074 | s->v = 0; | 1126 | s->v = 0; |
| 1075 | } | 1127 | } |
| 1076 | 1128 | ||
| @@ -1103,6 +1155,22 @@ ST_FUNC void free_defines(Sym *b) · 26 unmodified lines | |||
| 1103 | define_stack = b; | 1155 | define_stack = b; |
| 1104 | } | 1156 | } |
| 1105 | 1157 | ||
| 1158 | void print_defines(void) | ||
| 1159 | { | ||
| 1160 | Sym *top, *s; | ||
| 1161 | int v; | ||
| 1162 | |||
| 1163 | top = define_stack; | ||
| 1164 | while (top) { | ||
| 1165 | v = top->v; | ||
| 1166 | if (v >= TOK_IDENT && v < tok_ident) { | ||
| 1167 | s = table_ident[v - TOK_IDENT]->sym_define; | ||
| 1168 | define_print(s, 0); | ||
| 1169 | } | ||
| 1170 | top = top->prev; | ||
| 1171 | } | ||
| 1172 | } | ||
| 1173 | |||
| 1106 | /* label lookup */ | 1174 | /* label lookup */ |
| 1107 | ST_FUNC Sym *label_find(int v) | 1175 | ST_FUNC Sym *label_find(int v) |
| 1108 | { | 1176 | { |
| @@ -1192,23 +1260,6 @@ static int expr_preprocess(void) · 83 unmodified lines | |||
| 1192 | return c != 0; | 1260 | return c != 0; |
| 1193 | } | 1261 | } |
| 1194 | 1262 | ||
| 1195 | #if defined(PARSE_DEBUG) || defined(PP_DEBUG) | ||
| 1196 | static void tok_print(int *str) | ||
| 1197 | { | ||
| 1198 | int t; | ||
| 1199 | CValue cval; | ||
| 1200 | |||
| 1201 | printf("<"); | ||
| 1202 | while (1) { | ||
| 1203 | TOK_GET(&t, &str, &cval); | ||
| 1204 | if (!t) | ||
| 1205 | break; | ||
| 1206 | printf("%s", get_tok_str(t, &cval)); | ||
| 1207 | } | ||
| 1208 | printf(">\n"); | ||
| 1209 | } | ||
| 1210 | #endif | ||
| 1211 | |||
| 1212 | /* parse after #define */ | 1263 | /* parse after #define */ |
| 1213 | ST_FUNC void parse_define(void) | 1264 | ST_FUNC void parse_define(void) |
| 1214 | { | 1265 | { |
| @@ -1279,10 +1330,6 @@ ST_FUNC void parse_define(void) · 64 unmodified lines | |||
| 1279 | if (spc == 1) | 1330 | if (spc == 1) |
| 1280 | --str.len; /* remove trailing space */ | 1331 | --str.len; /* remove trailing space */ |
| 1281 | tok_str_add(&str, 0); | 1332 | tok_str_add(&str, 0); |
| 1282 | #ifdef PP_DEBUG | ||
| 1283 | printf("define %s %d: ", get_tok_str(v, NULL), t); | ||
| 1284 | tok_print(str.str); | ||
| 1285 | #endif | ||
| 1286 | define_push(v, t, str.str, first); | 1333 | define_push(v, t, str.str, first); |
| 1287 | } | 1334 | } |
| 1288 | 1335 | ||