X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=main.c;h=9cbf026dd75fa5c1a697fa5579dc1e82b1f699b0;hb=53fd019780bc33c28c7d41aa046c4b74ed65b01f;hp=e24a7fe6bae9a92b932edb3409fc075e66ab1ff5;hpb=8049252f651bb31f6965303c7f141980b0aa5c6b;p=xonotic%2Fgmqcc.git diff --git a/main.c b/main.c index e24a7fe..220a2e3 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,7 @@ /* - * Copyright (C) 2012 + * Copyright (C) 2012 * Dale Weiler + * Wolfgang Bumiller * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -21,125 +22,718 @@ * SOFTWARE. */ #include "gmqcc.h" -// todo CLEANUP this argitem thing -typedef struct { char *name, type; } argitem; -VECTOR_MAKE(argitem, items); - -/* global options */ -int opts_debug = 0; -int opts_memchk = 0; -int opts_compiler = COMPILER_GMQCC; -int opts_darkplaces_stringtablebug = 0; -int opts_omit_nullcode = 0; - -static const int usage(const char *const app) { - printf("usage:\n"); - printf(" %s -c -oprog.dat -- compile file\n" , app); - printf(" %s -a -oprog.dat -- assemble file\n" , app); - printf(" %s -c -i -oprog.dat -- compile together (allowed multiple -i)\n" , app); - printf(" %s -a -i -oprog.dat -- assemble together(allowed multiple -i)\n", app); - printf(" example:\n"); - printf(" %s -cfoo.qc -ibar.qc -oqc.dat -afoo.qs -ibar.qs -oqs.dat\n", app); - printf(" additional flags:\n"); - printf(" -debug -- turns on compiler debug messages\n"); - printf(" -memchk -- turns on compiler memory leak check\n"); - printf(" -help -- prints this help/usage text\n"); - printf(" -std -- select the QuakeC compile type (types below):\n"); - printf(" -std=qcc -- original QuakeC\n"); - printf(" -std=ftqecc -- fteqcc QuakeC\n"); - printf(" -std=qccx -- qccx QuakeC\n"); - printf(" -std=gmqcc -- this compiler QuakeC (default selection)\n"); - printf(" codegen flags:\n"); - printf(" -fdarkplaces-string-table-bug -- patches the string table to work with bugged versions of darkplaces\n"); - printf(" -fomit-nullcode -- omits the generation of null code (will break everywhere see propsal.txt)\n"); +#include "lexer.h" + +uint32_t opts_flags[1 + (COUNT_FLAGS / 32)]; +uint32_t opts_optimization[1 + (COUNT_OPTIMIZATIONS / 32)]; + +/* counter increased in ir.c */ +unsigned int optimization_count[COUNT_OPTIMIZATIONS]; + +uint32_t opts_O = 1; +const char *opts_output = "progs.dat"; +int opts_standard = COMPILER_GMQCC; +bool opts_debug = false; +bool opts_memchk = false; +bool opts_dumpfin = false; +bool opts_dump = false; +bool opts_forcecrc = false; +bool opts_pp_only = false; +size_t opts_max_array_size = (1024 << 3); + +uint16_t opts_forced_crc; + +static bool opts_output_wasset = false; + +/* set by the standard */ +const oper_info *operators = NULL; +size_t operator_count = 0; + +typedef struct { char *filename; int type; } argitem; +static argitem *items = NULL; + +#define TYPE_QC 0 +#define TYPE_ASM 1 +#define TYPE_SRC 2 + +static const char *app_name; + +static int usage() { + con_out("usage: %s [options] [files...]", app_name); + con_out("options:\n" + " -h, --help show this help message\n" + " -debug turns on compiler debug messages\n" + " -memchk turns on compiler memory leak check\n"); + con_out(" -o, --output=file output file, defaults to progs.dat\n" + " -a filename add an asm file to be assembled\n" + " -s filename add a progs.src file to be used\n"); + con_out(" -E stop after preprocessing\n"); + con_out(" -f enable a flag\n" + " -fno- disable a flag\n" + " -std standard select one of the following standards\n" + " -std=qcc original QuakeC\n" + " -std=fteqcc fteqcc QuakeC\n" + " -std=gmqcc this compiler (default)\n"); + con_out(" -W enable a warning\n" + " -Wno- disable a warning\n" + " -Wall enable all warnings\n" + " -Werror treat warnings as errors\n"); + con_out(" -force-crc=num force a specific checksum into the header\n"); + con_out("\n"); + con_out("flags:\n" + " -fadjust-vector-fields\n" + " when assigning a vector field, its _y and _z fields also get assigned\n" + ); return -1; } -int main(int argc, char **argv) { - size_t itr = 0; - char *app = &argv[0][0]; - FILE *fpp = NULL; - - /* - * Parse all command line arguments. This is rather annoying to do - * because of all tiny corner cases. - */ - if (argc <= 1 || (argv[1][0] != '-')) - return usage(app); - - while ((argc > 1) && argv[1][0] == '-') { - switch (argv[1][1]) { - case 'c': items_add((argitem){util_strdup(&argv[1][2]), 0}); break; /* compile */ - case 'a': items_add((argitem){util_strdup(&argv[1][2]), 1}); break; /* assemble */ - case 'i': items_add((argitem){util_strdup(&argv[1][2]), 2}); break; /* includes */ - default: - if (!strncmp(&argv[1][1], "debug" , 5)) { opts_debug = 1; break; } - if (!strncmp(&argv[1][1], "memchk", 6)) { opts_memchk = 1; break; } - if (!strncmp(&argv[1][1], "help", 4)) { - return usage(app); - break; +static bool options_setflag_all(const char *name, bool on, uint32_t *flags, const opts_flag_def *list, size_t listsize) { + size_t i; + + for (i = 0; i < listsize; ++i) { + if (!strcmp(name, list[i].name)) { + longbit lb = list[i].bit; +#if 0 + if (on) + flags[lb.idx] |= (1<<(lb.bit)); + else + flags[lb.idx] &= ~(1<<(lb.bit)); +#else + if (on) + flags[0] |= (1<