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