]> de.git.xonotic.org Git - xonotic/gmqcc.git/blob - main.c
00d3bc835390a6cfca82836e35118cd663c85f7d
[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                     break;
270
271                 case 'D':
272                     if (!strlen(argv[0]+2)) {
273                         con_err("expected name after -D\n");
274                         exit(0);
275                     }
276
277                     if (!(argarg = strchr(argv[0] + 2, '='))) {
278                         macro.name  = util_strdup(argv[0]+2);
279                         macro.value = NULL;
280                     } else {
281                         *argarg='\0'; /* terminate for name */
282                         macro.name  = util_strdup(argv[0]+2);
283                         macro.value = util_strdup(argarg+1);
284                     }
285                     vec_push(ppems, macro);
286                     break;
287
288                 /* handle all -fflags */
289                 case 'f':
290                     util_strtocmd(argv[0]+2, argv[0]+2, strlen(argv[0]+2)+1);
291                     if (!strcmp(argv[0]+2, "HELP") || *(argv[0]+2) == '?') {
292                         con_out("Possible flags:\n");
293                         for (itr = 0; itr < COUNT_FLAGS; ++itr) {
294                             util_strtononcmd(opts_flag_list[itr].name, buffer, sizeof(buffer));
295                             con_out(" -f%s\n", buffer);
296                         }
297                         exit(0);
298                     }
299                     else if (!strncmp(argv[0]+2, "NO_", 3)) {
300                         if (!opts_setflag(argv[0]+5, false)) {
301                             con_out("unknown flag: %s\n", argv[0]+2);
302                             return false;
303                         }
304                     }
305                     else if (!opts_setflag(argv[0]+2, true)) {
306                         con_out("unknown flag: %s\n", argv[0]+2);
307                         return false;
308                     }
309                     break;
310                 case 'W':
311                     util_strtocmd(argv[0]+2, argv[0]+2, strlen(argv[0]+2)+1);
312                     if (!strcmp(argv[0]+2, "HELP") || *(argv[0]+2) == '?') {
313                         con_out("Possible warnings:\n");
314                         for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
315                             util_strtononcmd(opts_warn_list[itr].name, buffer, sizeof(buffer));
316                             con_out(" -W%s\n", buffer);
317                         }
318                         exit(0);
319                     }
320                     else if (!strcmp(argv[0]+2, "NO_ERROR")) {
321                         opts.werror = false;
322                         break;
323                     }
324                     else if (!strcmp(argv[0]+2, "ERROR")) {
325                         opts.werror = true;
326                         break;
327                     }
328                     else if (!strcmp(argv[0]+2, "NONE")) {
329                         for (itr = 0; itr < sizeof(opts.warn)/sizeof(opts.warn[0]); ++itr)
330                             opts.warn[itr] = 0;
331                         break;
332                     }
333                     else if (!strcmp(argv[0]+2, "ALL")) {
334                         for (itr = 0; itr < sizeof(opts.warn)/sizeof(opts.warn[0]); ++itr)
335                             opts.warn[itr] = 0xFFFFFFFFL;
336                         break;
337                     }
338                     if (!strncmp(argv[0]+2, "NO_", 3)) {
339                         if (!opts_setwarn(argv[0]+5, false)) {
340                             con_out("unknown warning: %s\n", argv[0]+2);
341                             return false;
342                         }
343                     }
344                     else if (!opts_setwarn(argv[0]+2, true)) {
345                         con_out("unknown warning: %s\n", argv[0]+2);
346                         return false;
347                     }
348                     break;
349
350                 case 'O':
351                     if (!options_witharg(&argc, &argv, &argarg)) {
352                         con_out("option -O requires a numerical argument, or optimization name with an optional 'no-' prefix\n");
353                         return false;
354                     }
355                     if (isdigit(argarg[0])) {
356                         opts.O = atoi(argarg);
357                         opts_setoptimlevel(opts.O);
358                     } else {
359                         util_strtocmd(argarg, argarg, strlen(argarg)+1);
360                         if (!strcmp(argarg, "HELP")) {
361                             con_out("Possible optimizations:\n");
362                             for (itr = 0; itr < COUNT_OPTIMIZATIONS; ++itr) {
363                                 util_strtononcmd(opts_opt_list[itr].name, buffer, sizeof(buffer));
364                                 con_out(" -O%-20s (-O%u)\n", buffer, opts_opt_oflag[itr]);
365                             }
366                             exit(0);
367                         }
368                         else if (!strcmp(argarg, "ALL"))
369                             opts_setoptimlevel(opts.O = 9999);
370                         else if (!strncmp(argarg, "NO_", 3)) {
371                             if (!opts_setoptim(argarg+3, false)) {
372                                 con_out("unknown optimization: %s\n", argarg+3);
373                                 return false;
374                             }
375                         }
376                         else {
377                             if (!opts_setoptim(argarg, true)) {
378                                 con_out("unknown optimization: %s\n", argarg);
379                                 return false;
380                             }
381                         }
382                     }
383                     break;
384
385                 case 'o':
386                     if (!options_witharg(&argc, &argv, &argarg)) {
387                         con_out("option -o requires an argument: the output file name\n");
388                         return false;
389                     }
390                     opts.output = argarg;
391                     opts_output_wasset = true;
392                     break;
393
394                 case 'a':
395                 case 's':
396                     item.type = argv[0][1] == 'a' ? TYPE_ASM : TYPE_SRC;
397                     if (!options_witharg(&argc, &argv, &argarg)) {
398                         con_out("option -a requires a filename %s\n",
399                                 (argv[0][1] == 'a' ? "containing QC-asm" : "containing a progs.src formatted list"));
400                         return false;
401                     }
402                     item.filename = argarg;
403                     vec_push(items, item);
404                     break;
405
406                 case '-':
407                     if (!argv[0][2]) {
408                         /* anything following -- is considered a non-option argument */
409                         argend = true;
410                         break;
411                     }
412             /* All long options without arguments */
413                     else if (!strcmp(argv[0]+2, "help")) {
414                         usage();
415                         exit(0);
416                     }
417                     else if (!strcmp(argv[0]+2, "version")) {
418                         version();
419                         exit(0);
420                     }
421                     else {
422             /* All long options with arguments */
423                         if (options_long_witharg("output", &argc, &argv, &argarg)) {
424                             opts.output = argarg;
425                             opts_output_wasset = true;
426                         } else {
427                             con_out("Unknown parameter: %s\n", argv[0]);
428                             return false;
429                         }
430                     }
431                     break;
432
433                 default:
434                     con_out("Unknown parameter: %s\n", argv[0]);
435                     return false;
436             }
437         }
438         else
439         {
440             /* it's a QC filename */
441             item.filename = argv[0];
442             item.type     = TYPE_QC;
443             vec_push(items, item);
444         }
445     }
446     opts_ini_init(config);
447     return true;
448 }
449
450 /* returns the line number, or -1 on error */
451 static bool progs_nextline(char **out, size_t *alen,FILE *src) {
452     int    len;
453     char  *line;
454     char  *start;
455     char  *end;
456
457     line = *out;
458     len = util_getline(&line, alen, src);
459     if (len == -1)
460         return false;
461
462     /* start at first non-blank */
463     for (start = line; isspace(*start); ++start) {}
464     /* end at the first non-blank */
465     for (end = start;  *end && !isspace(*end);  ++end)   {}
466
467     *out = line;
468     /* move the actual filename to the beginning */
469     while (start != end) {
470         *line++ = *start++;
471     }
472     *line = 0;
473     return true;
474 }
475
476 int main(int argc, char **argv) {
477     size_t itr;
478     int    retval           = 0;
479     bool   opts_output_free = false;
480     bool   operators_free   = false;
481     bool   progs_src        = false;
482     FILE  *outfile          = NULL;
483
484     app_name = argv[0];
485     con_init ();
486     opts_init("progs.dat", COMPILER_GMQCC, (1024 << 3));
487
488     if (!options_parse(argc, argv)) {
489         return usage();
490     }
491
492     /* the standard decides which set of operators to use */
493     if (opts.standard == COMPILER_GMQCC) {
494         operators      = c_operators;
495         operator_count = c_operator_count;
496     } else if (opts.standard == COMPILER_FTEQCC) {
497         operators      = fte_operators;
498         operator_count = fte_operator_count;
499     } else {
500         operators      = qcc_operators;
501         operator_count = qcc_operator_count;
502     }
503
504     if (operators == fte_operators) {
505         /* fix ternary? */
506         if (OPTS_FLAG(CORRECT_TERNARY)) {
507             oper_info *newops;
508             if (operators[operator_count-2].id != opid1(',') ||
509                 operators[operator_count-1].id != opid2(':','?'))
510             {
511                 con_err("internal error: operator precedence table wasn't updated correctly!\n");
512                 exit(1);
513             }
514             operators_free = true;
515             newops = mem_a(sizeof(operators[0]) * operator_count);
516             memcpy(newops, operators, sizeof(operators[0]) * operator_count);
517             memcpy(&newops[operator_count-2], &operators[operator_count-1], sizeof(newops[0]));
518             memcpy(&newops[operator_count-1], &operators[operator_count-2], sizeof(newops[0]));
519             newops[operator_count-2].prec = newops[operator_count-1].prec+1;
520             operators = newops;
521         }
522     }
523
524     if (opts.dump) {
525         for (itr = 0; itr < COUNT_FLAGS; ++itr)
526             con_out("Flag %s = %i\n",    opts_flag_list[itr].name, OPTS_FLAG(itr));
527         for (itr = 0; itr < COUNT_WARNINGS; ++itr)
528             con_out("Warning %s = %i\n", opts_warn_list[itr].name, OPTS_WARN(itr));
529         
530         con_out("output             = %s\n", opts.output);
531         con_out("optimization level = %d\n", opts.O);
532         con_out("standard           = %i\n", opts.standard);
533     }
534
535     if (opts.pp_only) {
536         if (opts_output_wasset) {
537             outfile = util_fopen(opts.output, "wb");
538             if (!outfile) {
539                 con_err("failed to open `%s` for writing\n", opts.output);
540                 retval = 1;
541                 goto cleanup;
542             }
543         }
544         else
545             outfile = stdout;
546     }
547
548     if (!opts.pp_only) {
549         if (!parser_init()) {
550             con_err("failed to initialize parser\n");
551             retval = 1;
552             goto cleanup;
553         }
554     }
555
556     if (opts.pp_only || OPTS_FLAG(FTEPP)) {
557         if (!ftepp_init()) {
558             con_err("failed to initialize parser\n");
559             retval = 1;
560             goto cleanup;
561         }
562     }
563
564     util_debug("COM", "starting ...\n");
565
566     /* add macros */
567     if (opts.pp_only || OPTS_FLAG(FTEPP)) {
568         for (itr = 0; itr < vec_size(ppems); itr++) {
569             ftepp_add_macro(ppems[itr].name, ppems[itr].value);
570             mem_d(ppems[itr].name);
571
572             /* can be null */
573             if (ppems[itr].value)
574                 mem_d(ppems[itr].value);
575         }
576     }
577
578     if (!vec_size(items)) {
579         FILE *src;
580         char *line;
581         size_t linelen = 0;
582
583         progs_src = true;
584
585         src = util_fopen("progs.src", "rb");
586         if (!src) {
587             con_err("failed to open `progs.src` for reading\n");
588             retval = 1;
589             goto cleanup;
590         }
591
592         line = NULL;
593         if (!progs_nextline(&line, &linelen, src) || !line[0]) {
594             con_err("illformatted progs.src file: expected output filename in first line\n");
595             retval = 1;
596             goto srcdone;
597         }
598
599         if (!opts_output_wasset) {
600             opts.output = util_strdup(line);
601             opts_output_free = true;
602         }
603
604         while (progs_nextline(&line, &linelen, src)) {
605             argitem item;
606             if (!line[0] || (line[0] == '/' && line[1] == '/'))
607                 continue;
608             item.filename = util_strdup(line);
609             item.type     = TYPE_QC;
610             vec_push(items, item);
611         }
612
613 srcdone:
614         fclose(src);
615         mem_d(line);
616     }
617
618     if (retval)
619         goto cleanup;
620
621     if (vec_size(items)) {
622         if (!opts.pp_only) {
623             con_out("Mode: %s\n", (progs_src ? "progs.src" : "manual"));
624             con_out("There are %lu items to compile:\n", (unsigned long)vec_size(items));
625         }
626         for (itr = 0; itr < vec_size(items); ++itr) {
627             if (!opts.pp_only) {
628                 con_out("  item: %s (%s)\n",
629                        items[itr].filename,
630                        ( (items[itr].type == TYPE_QC ? "qc" :
631                          (items[itr].type == TYPE_ASM ? "asm" :
632                          (items[itr].type == TYPE_SRC ? "progs.src" :
633                          ("unknown"))))));
634             }
635
636             if (opts.pp_only) {
637                 const char *out;
638                 if (!ftepp_preprocess_file(items[itr].filename)) {
639                     retval = 1;
640                     goto cleanup;
641                 }
642                 out = ftepp_get();
643                 if (out)
644                     fprintf(outfile, "%s", out);
645                 ftepp_flush();
646             }
647             else {
648                 if (OPTS_FLAG(FTEPP)) {
649                     const char *data;
650                     if (!ftepp_preprocess_file(items[itr].filename)) {
651                         retval = 1;
652                         goto cleanup;
653                     }
654                     data = ftepp_get();
655                     if (vec_size(data)) {
656                         if (!parser_compile_string_len(items[itr].filename, data, vec_size(data))) {
657                             retval = 1;
658                             goto cleanup;
659                         }
660                     }
661                     ftepp_flush();
662                 }
663                 else {
664                     if (!parser_compile_file(items[itr].filename)) {
665                         retval = 1;
666                         goto cleanup;
667                     }
668                 }
669             }
670
671             if (progs_src) {
672                 mem_d(items[itr].filename);
673                 items[itr].filename = NULL;
674             }
675         }
676
677         ftepp_finish();
678         if (!opts.pp_only) {
679             if (!parser_finish(opts.output)) {
680                 retval = 1;
681                 goto cleanup;
682             }
683         }
684     }
685
686     /* stuff */
687     if (!opts.pp_only) {
688         for (itr = 0; itr < COUNT_OPTIMIZATIONS; ++itr) {
689             if (opts_optimizationcount[itr]) {
690                 con_out("%s: %u\n", opts_opt_list[itr].name, (unsigned int)opts_optimizationcount[itr]);
691             }
692         }
693     }
694
695 cleanup:
696     util_debug("COM", "cleaning ...\n");
697     ftepp_finish();
698     con_close();
699     vec_free(items);
700     vec_free(ppems);
701
702     if (!opts.pp_only)
703         parser_cleanup();
704     if (opts_output_free)
705         mem_d((char*)opts.output);
706     if (operators_free)
707         mem_d((void*)operators);
708
709     lex_cleanup();
710     util_meminfo();
711     return retval;
712 }