]> de.git.xonotic.org Git - xonotic/gmqcc.git/blob - main.c
Updating usage message a bit
[xonotic/gmqcc.git] / main.c
1 /*
2  * Copyright (C) 2012
3  *     Dale Weiler
4  *     Wolfgang Bumiller
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy of
7  * this software and associated documentation files (the "Software"), to deal in
8  * the Software without restriction, including without limitation the rights to
9  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10  * of the Software, and to permit persons to whom the Software is furnished to do
11  * so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "gmqcc.h"
25 #include "lexer.h"
26
27 /* counter increased in ir.c */
28 unsigned int optimization_count[COUNT_OPTIMIZATIONS];
29 static bool opts_output_wasset = false;
30
31 cmd_options opts;
32
33 /* set by the standard */
34 const oper_info *operators      = NULL;
35 size_t           operator_count = 0;
36
37 typedef struct { char *filename; int type; } argitem;
38 static argitem *items = NULL;
39
40 #define TYPE_QC  0
41 #define TYPE_ASM 1
42 #define TYPE_SRC 2
43
44 static const char *app_name;
45
46 static int usage() {
47     con_out("usage: %s [options] [files...]", app_name);
48     con_out("options:\n"
49             "  -h, --help             show this help message\n"
50             "  -debug                 turns on compiler debug messages\n"
51             "  -memchk                turns on compiler memory leak check\n");
52     con_out("  -o, --output=file      output file, defaults to progs.dat\n"
53             "  -s filename            add a progs.src file to be used\n");
54     con_out("  -E                     stop after preprocessing\n");
55     con_out("  -std=standard          select one of the following standards\n"
56             "       -std=qcc          original QuakeC\n"
57             "       -std=fteqcc       fteqcc QuakeC\n"
58             "       -std=gmqcc        this compiler (default)\n");
59     con_out("  -f<flag>               enable a flag\n"
60             "  -fno-<flag>            disable a flag\n"
61             "  -fhelp                 list possible flags\n");
62     con_out("  -W<warning>            enable a warning\n"
63             "  -Wno-<warning>         disable a warning\n"
64             "  -Wall                  enable all warnings\n"
65             "  -Werror                treat warnings as errors\n");
66     con_out("  -Whelp                 list possible warnings\n");
67     con_out("  -O<number>             optimization level\n"
68             "  -O<name>               enable specific optimization\n"
69             "  -Ono-<name>            disable specific optimization\n"
70             "  -Ohelp                 list optimizations\n");
71     con_out("  -force-crc=num         force a specific checksum into the header\n");
72     return -1;
73 }
74
75 static bool options_setflag_all(const char *name, bool on, uint32_t *flags, const opts_flag_def *list, size_t listsize) {
76     size_t i;
77
78     for (i = 0; i < listsize; ++i) {
79         if (!strcmp(name, list[i].name)) {
80             longbit lb = list[i].bit;
81 #if 0
82             if (on)
83                 flags[lb.idx] |= (1<<(lb.bit));
84             else
85                 flags[lb.idx] &= ~(1<<(lb.bit));
86 #else
87             if (on)
88                 flags[0] |= (1<<lb);
89             else
90                 flags[0] &= ~(1<<(lb));
91 #endif
92             return true;
93         }
94     }
95     return false;
96 }
97 static bool options_setflag(const char *name, bool on) {
98     return options_setflag_all(name, on, opts.flags, opts_flag_list, COUNT_FLAGS);
99 }
100 static bool options_setwarn(const char *name, bool on) {
101     return options_setflag_all(name, on, opts.warn, opts_warn_list, COUNT_WARNINGS);
102 }
103 static bool options_setoptim(const char *name, bool on) {
104     return options_setflag_all(name, on, opts.optimization, opts_opt_list, COUNT_OPTIMIZATIONS);
105 }
106
107 static bool options_witharg(int *argc_, char ***argv_, char **out) {
108     int  argc   = *argc_;
109     char **argv = *argv_;
110
111     if (argv[0][2]) {
112         *out = argv[0]+2;
113         return true;
114     }
115     /* eat up the next */
116     if (argc < 2) /* no parameter was provided */
117         return false;
118
119     *out = argv[1];
120     --*argc_;
121     ++*argv_;
122     return true;
123 }
124
125 static bool options_long_witharg_all(const char *optname, int *argc_, char ***argv_, char **out, int ds, bool split) {
126     int  argc   = *argc_;
127     char **argv = *argv_;
128
129     size_t len = strlen(optname);
130
131     if (strncmp(argv[0]+ds, optname, len))
132         return false;
133
134     /* it's --optname, check how the parameter is supplied */
135     if (argv[0][ds+len] == '=') {
136         /* using --opt=param */
137         *out = argv[0]+ds+len+1;
138         return true;
139     }
140
141     if (!split || argc < ds) /* no parameter was provided, or only single-arg form accepted */
142         return false;
143
144     /* using --opt param */
145     *out = argv[1];
146     --*argc_;
147     ++*argv_;
148     return true;
149 }
150 static bool options_long_witharg(const char *optname, int *argc_, char ***argv_, char **out) {
151     return options_long_witharg_all(optname, argc_, argv_, out, 2, true);
152 }
153 static bool options_long_gcc(const char *optname, int *argc_, char ***argv_, char **out) {
154     return options_long_witharg_all(optname, argc_, argv_, out, 1, false);
155 }
156
157 void options_set(uint32_t *flags, size_t idx, bool on)
158 {
159     longbit lb = LONGBIT(idx);
160 #if 0
161     if (on)
162         flags[lb.idx] |= (1<<(lb.bit));
163     else
164         flags[lb.idx] &= ~(1<<(lb.bit));
165 #else
166     if (on)
167         flags[0] |= (1<<(lb));
168     else
169         flags[0] &= ~(1<<(lb));
170 #endif
171 }
172
173 static void set_optimizations(unsigned int level)
174 {
175     size_t i;
176     for (i = 0; i < COUNT_OPTIMIZATIONS; ++i)
177         options_set(opts.optimization, i, level >= opts_opt_oflag[i]);
178 }
179
180 static bool options_parse(int argc, char **argv) {
181     bool argend = false;
182     size_t itr;
183     char  buffer[1024];
184     char *redirout = (char*)stdout;
185     char *redirerr = (char*)stderr;
186
187     while (!argend && argc > 1) {
188         char *argarg;
189         argitem item;
190
191         ++argv;
192         --argc;
193
194         if (argv[0][0] == '-') {
195     /* All gcc-type long options */
196             if (options_long_gcc("std", &argc, &argv, &argarg)) {
197                 if      (!strcmp(argarg, "gmqcc") || !strcmp(argarg, "default")) {
198                     options_set(opts.flags, ADJUST_VECTOR_FIELDS, true);
199                     opts.standard = COMPILER_GMQCC;
200                 } else if (!strcmp(argarg, "qcc")) {
201                     options_set(opts.flags, ADJUST_VECTOR_FIELDS, false);
202                     options_set(opts.flags, ASSIGN_FUNCTION_TYPES, true);
203                     opts.standard = COMPILER_QCC;
204                 } else if (!strcmp(argarg, "fte") || !strcmp(argarg, "fteqcc")) {
205                     options_set(opts.flags, FTEPP,                true);
206                     options_set(opts.flags, TRANSLATABLE_STRINGS, true);
207                     options_set(opts.flags, ADJUST_VECTOR_FIELDS, false);
208                     options_set(opts.flags, ASSIGN_FUNCTION_TYPES, true);
209                     options_set(opts.warn, WARN_TERNARY_PRECEDENCE, true);
210                     options_set(opts.flags, CORRECT_TERNARY, false);
211                     opts.standard = COMPILER_FTEQCC;
212                 } else if (!strcmp(argarg, "qccx")) {
213                     options_set(opts.flags, ADJUST_VECTOR_FIELDS, false);
214                     opts.standard = COMPILER_QCCX;
215                 } else {
216                     con_out("Unknown standard: %s\n", argarg);
217                     return false;
218                 }
219                 continue;
220             }
221             if (options_long_gcc("force-crc", &argc, &argv, &argarg)) {
222                 opts.forcecrc = true;
223                 opts.forced_crc = strtol(argarg, NULL, 0);
224                 continue;
225             }
226             if (options_long_gcc("redirout", &argc, &argv, &redirout)) {
227                 con_change(redirout, redirerr);
228                 continue;
229             }
230             if (options_long_gcc("redirerr", &argc, &argv, &redirerr)) {
231                 con_change(redirout, redirerr);
232                 continue;
233             }
234
235             /* show defaults (like pathscale) */
236             if (!strcmp(argv[0]+1, "show-defaults")) {
237                 size_t itr;
238                 char   buffer[1024];
239                 for (itr = 0; itr < COUNT_FLAGS; ++itr) {
240                     if (!OPTS_FLAG(itr))
241                         continue;
242
243                     memset(buffer, 0, sizeof(buffer));
244                     util_strtononcmd(opts_flag_list[itr].name, buffer, strlen(opts_flag_list[itr].name) + 1);
245
246                     con_out("-f%s ", buffer);
247                 }
248                 for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
249                     if (!OPTS_WARN(itr))
250                         continue;
251
252                     memset(buffer, 0, sizeof(buffer));
253                     util_strtononcmd(opts_warn_list[itr].name, buffer, strlen(opts_warn_list[itr].name) + 1);
254                     con_out("-W%s ", buffer);
255                 }
256                 con_out("\n");
257                 exit(0);
258             }
259
260             if (!strcmp(argv[0]+1, "debug")) {
261                 opts.debug = true;
262                 continue;
263             }
264             if (!strcmp(argv[0]+1, "dump")) {
265                 opts.dump = true;
266                 continue;
267             }
268             if (!strcmp(argv[0]+1, "dumpfin")) {
269                 opts.dumpfin = true;
270                 continue;
271             }
272             if (!strcmp(argv[0]+1, "memchk")) {
273                 opts.memchk = true;
274                 continue;
275             }
276             if (!strcmp(argv[0]+1, "nocolor")) {
277                 con_color(0);
278                 continue;
279             }
280
281             switch (argv[0][1]) {
282                 /* -h, show usage but exit with 0 */
283                 case 'h':
284                     usage();
285                     exit(0);
286                     /* break; never reached because of exit(0) */
287
288                 case 'E':
289                     opts.pp_only = true;
290                     break;
291
292                 /* debug turns on -flno */
293                 case 'g':
294                     options_setflag("LNO", true);
295                     break;
296
297                 /* handle all -fflags */
298                 case 'f':
299                     util_strtocmd(argv[0]+2, argv[0]+2, strlen(argv[0]+2)+1);
300                     if (!strcmp(argv[0]+2, "HELP") || *(argv[0]+2) == '?') {
301                         con_out("Possible flags:\n");
302                         for (itr = 0; itr < COUNT_FLAGS; ++itr) {
303                             util_strtononcmd(opts_flag_list[itr].name, buffer, sizeof(buffer));
304                             con_out(" -f%s\n", buffer);
305                         }
306                         exit(0);
307                     }
308                     else if (!strncmp(argv[0]+2, "NO_", 3)) {
309                         if (!options_setflag(argv[0]+5, false)) {
310                             con_out("unknown flag: %s\n", argv[0]+2);
311                             return false;
312                         }
313                     }
314                     else if (!options_setflag(argv[0]+2, true)) {
315                         con_out("unknown flag: %s\n", argv[0]+2);
316                         return false;
317                     }
318                     break;
319                 case 'W':
320                     util_strtocmd(argv[0]+2, argv[0]+2, strlen(argv[0]+2)+1);
321                     if (!strcmp(argv[0]+2, "HELP") || *(argv[0]+2) == '?') {
322                         con_out("Possible warnings:\n");
323                         for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
324                             util_strtononcmd(opts_warn_list[itr].name, buffer, sizeof(buffer));
325                             con_out(" -W%s\n", buffer);
326                         }
327                         exit(0);
328                     }
329                     else if (!strcmp(argv[0]+2, "NO_ERROR")) {
330                         opts.werror = false;
331                         break;
332                     }
333                     else if (!strcmp(argv[0]+2, "ERROR")) {
334                         opts.werror = true;
335                         break;
336                     }
337                     else if (!strcmp(argv[0]+2, "NONE")) {
338                         for (itr = 0; itr < sizeof(opts.warn)/sizeof(opts.warn[0]); ++itr)
339                             opts.warn[itr] = 0;
340                         break;
341                     }
342                     else if (!strcmp(argv[0]+2, "ALL")) {
343                         for (itr = 0; itr < sizeof(opts.warn)/sizeof(opts.warn[0]); ++itr)
344                             opts.warn[itr] = 0xFFFFFFFFL;
345                         break;
346                     }
347                     if (!strncmp(argv[0]+2, "NO_", 3)) {
348                         if (!options_setwarn(argv[0]+5, false)) {
349                             con_out("unknown warning: %s\n", argv[0]+2);
350                             return false;
351                         }
352                     }
353                     else if (!options_setwarn(argv[0]+2, true)) {
354                         con_out("unknown warning: %s\n", argv[0]+2);
355                         return false;
356                     }
357                     break;
358
359                 case 'O':
360                     if (!options_witharg(&argc, &argv, &argarg)) {
361                         con_out("option -O requires a numerical argument, or optimization name with an optional 'no-' prefix\n");
362                         return false;
363                     }
364                     if (isdigit(argarg[0])) {
365                         opts.O = atoi(argarg);
366                         set_optimizations(opts.O);
367                     } else {
368                         util_strtocmd(argarg, argarg, strlen(argarg)+1);
369                         if (!strcmp(argarg, "HELP")) {
370                             con_out("Possible optimizations:\n");
371                             for (itr = 0; itr < COUNT_OPTIMIZATIONS; ++itr) {
372                                 util_strtononcmd(opts_opt_list[itr].name, buffer, sizeof(buffer));
373                                 con_out(" -O%-20s (-O%u)\n", buffer, opts_opt_oflag[itr]);
374                             }
375                             exit(0);
376                         }
377                         else if (!strcmp(argarg, "ALL"))
378                             set_optimizations(opts.O = 9999);
379                         else if (!strncmp(argarg, "NO_", 3)) {
380                             if (!options_setoptim(argarg+3, false)) {
381                                 con_out("unknown optimization: %s\n", argarg+3);
382                                 return false;
383                             }
384                         }
385                         else {
386                             if (!options_setoptim(argarg, true)) {
387                                 con_out("unknown optimization: %s\n", argarg);
388                                 return false;
389                             }
390                         }
391                     }
392                     break;
393
394                 case 'o':
395                     if (!options_witharg(&argc, &argv, &argarg)) {
396                         con_out("option -o requires an argument: the output file name\n");
397                         return false;
398                     }
399                     opts.output = argarg;
400                     opts_output_wasset = true;
401                     break;
402
403                 case 'a':
404                 case 's':
405                     item.type = argv[0][1] == 'a' ? TYPE_ASM : TYPE_SRC;
406                     if (!options_witharg(&argc, &argv, &argarg)) {
407                         con_out("option -a requires a filename %s\n",
408                                 (argv[0][1] == 'a' ? "containing QC-asm" : "containing a progs.src formatted list"));
409                         return false;
410                     }
411                     item.filename = argarg;
412                     vec_push(items, item);
413                     break;
414
415                 case '-':
416                     if (!argv[0][2]) {
417                         /* anything following -- is considered a non-option argument */
418                         argend = true;
419                         break;
420                     }
421             /* All long options without arguments */
422                     else if (!strcmp(argv[0]+2, "help")) {
423                         usage();
424                         exit(0);
425                     }
426                     else {
427             /* All long options with arguments */
428                         if (options_long_witharg("output", &argc, &argv, &argarg)) {
429                             opts.output = argarg;
430                             opts_output_wasset = true;
431                         } else {
432                             con_out("Unknown parameter: %s\n", argv[0]);
433                             return false;
434                         }
435                     }
436                     break;
437
438                 default:
439                     con_out("Unknown parameter: %s\n", argv[0]);
440                     return false;
441             }
442         }
443         else
444         {
445             /* it's a QC filename */
446             item.filename = argv[0];
447             item.type     = TYPE_QC;
448             vec_push(items, item);
449         }
450     }
451     return true;
452 }
453
454 /* returns the line number, or -1 on error */
455 static bool progs_nextline(char **out, size_t *alen,FILE *src) {
456     int    len;
457     char  *line;
458     char  *start;
459     char  *end;
460
461     line = *out;
462     len = util_getline(&line, alen, src);
463     if (len == -1)
464         return false;
465
466     /* start at first non-blank */
467     for (start = line; isspace(*start); ++start) {}
468     /* end at the first non-blank */
469     for (end = start;  *end && !isspace(*end);  ++end)   {}
470
471     *out = line;
472     /* move the actual filename to the beginning */
473     while (start != end) {
474         *line++ = *start++;
475     }
476     *line = 0;
477     return true;
478 }
479
480 int main(int argc, char **argv) {
481     size_t itr;
482     int retval = 0;
483     bool opts_output_free = false;
484     bool operators_free = false;
485     bool progs_src = false;
486     FILE *outfile = NULL;
487
488     memset(&opts, 0, sizeof(opts));
489     opts.output         = "progs.dat";
490     opts.standard       = COMPILER_GMQCC;
491     opts.max_array_size = (1024<<3);
492
493     app_name = argv[0];
494     con_init();
495
496     /* default options / warn flags */
497     options_set(opts.warn, WARN_UNKNOWN_CONTROL_SEQUENCE, true);
498     options_set(opts.warn, WARN_EXTENSIONS, true);
499     options_set(opts.warn, WARN_FIELD_REDECLARED, true);
500     options_set(opts.warn, WARN_TOO_FEW_PARAMETERS, true);
501     options_set(opts.warn, WARN_MISSING_RETURN_VALUES, true);
502     options_set(opts.warn, WARN_USED_UNINITIALIZED, true);
503     options_set(opts.warn, WARN_LOCAL_CONSTANTS, true);
504     options_set(opts.warn, WARN_VOID_VARIABLES, true);
505     options_set(opts.warn, WARN_IMPLICIT_FUNCTION_POINTER, true);
506     options_set(opts.warn, WARN_VARIADIC_FUNCTION, true);
507     options_set(opts.warn, WARN_FRAME_MACROS, true);
508     options_set(opts.warn, WARN_UNUSED_VARIABLE, true);
509     options_set(opts.warn, WARN_EFFECTLESS_STATEMENT, true);
510     options_set(opts.warn, WARN_END_SYS_FIELDS, true);
511     options_set(opts.warn, WARN_ASSIGN_FUNCTION_TYPES, true);
512     options_set(opts.warn, WARN_PREPROCESSOR, true);
513     options_set(opts.warn, WARN_MULTIFILE_IF, true);
514     options_set(opts.warn, WARN_DOUBLE_DECLARATION, true);
515     options_set(opts.warn, WARN_CONST_VAR, true);
516     options_set(opts.warn, WARN_MULTIBYTE_CHARACTER, true);
517
518     options_set(opts.flags, ADJUST_VECTOR_FIELDS, true);
519     options_set(opts.flags, FTEPP, false);
520     options_set(opts.flags, CORRECT_TERNARY, true);
521
522     if (!options_parse(argc, argv)) {
523         return usage();
524     }
525
526     /* the standard decides which set of operators to use */
527     if (opts.standard == COMPILER_GMQCC) {
528         operators = c_operators;
529         operator_count = c_operator_count;
530     } else if (opts.standard == COMPILER_FTEQCC) {
531         operators = fte_operators;
532         operator_count = fte_operator_count;
533     } else {
534         operators = qcc_operators;
535         operator_count = qcc_operator_count;
536     }
537
538     if (operators == fte_operators) {
539         /* fix ternary? */
540         if (OPTS_FLAG(CORRECT_TERNARY)) {
541             oper_info *newops;
542             if (operators[operator_count-2].id != opid1(',') ||
543                 operators[operator_count-1].id != opid2(':','?'))
544             {
545                 con_err("internal error: operator precedence table wasn't updated correctly!\n");
546                 exit(1);
547             }
548             operators_free = true;
549             newops = mem_a(sizeof(operators[0]) * operator_count);
550             memcpy(newops, operators, sizeof(operators[0]) * operator_count);
551             memcpy(&newops[operator_count-2], &operators[operator_count-1], sizeof(newops[0]));
552             memcpy(&newops[operator_count-1], &operators[operator_count-2], sizeof(newops[0]));
553             newops[operator_count-2].prec = newops[operator_count-1].prec+1;
554             operators = newops;
555         }
556     }
557
558     if (opts.dump) {
559         for (itr = 0; itr < COUNT_FLAGS; ++itr) {
560             con_out("Flag %s = %i\n", opts_flag_list[itr].name, OPTS_FLAG(itr));
561         }
562         for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
563             con_out("Warning %s = %i\n", opts_warn_list[itr].name, OPTS_WARN(itr));
564         }
565         con_out("output = %s\n", opts.output);
566         con_out("optimization level = %i\n", (int)opts.O);
567         con_out("standard = %i\n", opts.standard);
568     }
569
570     if (opts.pp_only) {
571         if (opts_output_wasset) {
572             outfile = util_fopen(opts.output, "wb");
573             if (!outfile) {
574                 con_err("failed to open `%s` for writing\n", opts.output);
575                 retval = 1;
576                 goto cleanup;
577             }
578         }
579         else
580             outfile = stdout;
581     }
582
583     if (!opts.pp_only) {
584         if (!parser_init()) {
585             con_err("failed to initialize parser\n");
586             retval = 1;
587             goto cleanup;
588         }
589     }
590     if (opts.pp_only || OPTS_FLAG(FTEPP)) {
591         if (!ftepp_init()) {
592             con_err("failed to initialize parser\n");
593             retval = 1;
594             goto cleanup;
595         }
596     }
597
598     util_debug("COM", "starting ...\n");
599
600     if (!vec_size(items)) {
601         FILE *src;
602         char *line;
603         size_t linelen = 0;
604
605         progs_src = true;
606
607         src = util_fopen("progs.src", "rb");
608         if (!src) {
609             con_err("failed to open `progs.src` for reading\n");
610             retval = 1;
611             goto cleanup;
612         }
613
614         line = NULL;
615         if (!progs_nextline(&line, &linelen, src) || !line[0]) {
616             con_err("illformatted progs.src file: expected output filename in first line\n");
617             retval = 1;
618             goto srcdone;
619         }
620
621         if (!opts_output_wasset) {
622             opts.output = util_strdup(line);
623             opts_output_free = true;
624         }
625
626         while (progs_nextline(&line, &linelen, src)) {
627             argitem item;
628             if (!line[0] || (line[0] == '/' && line[1] == '/'))
629                 continue;
630             item.filename = util_strdup(line);
631             item.type     = TYPE_QC;
632             vec_push(items, item);
633         }
634
635 srcdone:
636         fclose(src);
637         mem_d(line);
638     }
639
640     if (retval)
641         goto cleanup;
642
643     if (vec_size(items)) {
644         if (!opts.pp_only) {
645             con_out("Mode: %s\n", (progs_src ? "progs.src" : "manual"));
646             con_out("There are %lu items to compile:\n", (unsigned long)vec_size(items));
647         }
648         for (itr = 0; itr < vec_size(items); ++itr) {
649             if (!opts.pp_only) {
650                 con_out("  item: %s (%s)\n",
651                        items[itr].filename,
652                        ( (items[itr].type == TYPE_QC ? "qc" :
653                          (items[itr].type == TYPE_ASM ? "asm" :
654                          (items[itr].type == TYPE_SRC ? "progs.src" :
655                          ("unknown"))))));
656             }
657
658             if (opts.pp_only) {
659                 const char *out;
660                 if (!ftepp_preprocess_file(items[itr].filename)) {
661                     retval = 1;
662                     goto cleanup;
663                 }
664                 out = ftepp_get();
665                 if (out)
666                     fprintf(outfile, "%s", out);
667                 ftepp_flush();
668             }
669             else {
670                 if (OPTS_FLAG(FTEPP)) {
671                     const char *data;
672                     if (!ftepp_preprocess_file(items[itr].filename)) {
673                         retval = 1;
674                         goto cleanup;
675                     }
676                     data = ftepp_get();
677                     if (vec_size(data)) {
678                         if (!parser_compile_string_len(items[itr].filename, data, vec_size(data))) {
679                             retval = 1;
680                             goto cleanup;
681                         }
682                     }
683                     ftepp_flush();
684                 }
685                 else {
686                     if (!parser_compile_file(items[itr].filename)) {
687                         retval = 1;
688                         goto cleanup;
689                     }
690                 }
691             }
692
693             if (progs_src) {
694                 mem_d(items[itr].filename);
695                 items[itr].filename = NULL;
696             }
697         }
698
699         ftepp_finish();
700         if (!opts.pp_only) {
701             if (!parser_finish(opts.output)) {
702                 retval = 1;
703                 goto cleanup;
704             }
705         }
706     }
707
708     /* stuff */
709
710     if (!opts.pp_only) {
711         for (itr = 0; itr < COUNT_OPTIMIZATIONS; ++itr) {
712             if (optimization_count[itr]) {
713                 con_out("%s: %u\n", opts_opt_list[itr].name, (unsigned int)optimization_count[itr]);
714             }
715         }
716     }
717
718 cleanup:
719     util_debug("COM", "cleaning ...\n");
720     ftepp_finish();
721     con_close();
722     vec_free(items);
723
724     if (!opts.pp_only)
725         parser_cleanup();
726     if (opts_output_free)
727         mem_d((char*)opts.output);
728     if (operators_free)
729         mem_d((void*)operators);
730
731     lex_cleanup();
732     util_meminfo();
733     return retval;
734 }