X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=main.c;h=195574ea1538c737b65aeb0f7bb4207a5d3066c8;hp=006fdea863722c2d5b9c56666eb816c41b976c00;hb=61fa54318c3aa1ce0c2099f9793d830e5896c016;hpb=69173876f11da6ea695f7d518d5036ddcf5179a6 diff --git a/main.c b/main.c index 006fdea..4c8062d 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,141 +22,602 @@ * SOFTWARE. */ #include "gmqcc.h" -// todo CLEANUP this argitem thing -typedef struct { char *name, type; } argitem; -VECTOR_MAKE(argitem, items); - -/* global options */ -bool opts_debug = false; -bool opts_memchk = false; -bool opts_darkplaces_stringtablebug = false; -bool opts_omit_nullcode = false; -int opts_compiler = COMPILER_GMQCC; - -static const int usage(const char *const app) { - printf("usage:\n" - " %s -c -oprog.dat -- compile file\n" - " %s -a -oprog.dat -- assemble file\n" - " %s -c -i -oprog.dat -- compile together (allowed multiple -i)\n" - " %s -a -i -oprog.dat -- assemble together(allowed multiple -i)\n" - " example:\n" - " %s -cfoo.qc -ibar.qc -oqc.dat -afoo.qs -ibar.qs -oqs.dat\n" - " additional flags:\n" - " -debug -- turns on compiler debug messages\n" - " -memchk -- turns on compiler memory leak check\n" - " -help -- prints this help/usage text\n" - " -std -- select the QuakeC compile type (types below):\n" - " -std=qcc -- original QuakeC\n" - " -std=ftqecc -- fteqcc QuakeC\n" - " -std=qccx -- qccx QuakeC\n" - " -std=gmqcc -- this compiler QuakeC (default selection)\n" - " codegen flags:\n" - " -fdarkplaces-string-table-bug -- patches the string table to work with bugged versions of darkplaces\n" - " -fomit-nullcode -- omits the generation of null code (will break everywhere see propsal.txt)\n", - app,app,app,app,app - ); +#include "lexer.h" + +uint32_t opts_flags[1 + (COUNT_FLAGS / 32)]; +uint32_t opts_warn [1 + (COUNT_WARNINGS / 32)]; + +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_dump = false; +bool opts_werror = false; +bool opts_forcecrc = false; +bool opts_pp_only = false; +size_t opts_max_array_size = 1024; + +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 'v': { - printf("GMQCC:\n" - " version: %d.%d.%d (0x%08X)\n" - " build date: %s\n" - " build time: %s\n", - (GMQCC_VERSION >> 16) & 0xFF, - (GMQCC_VERSION >> 8) & 0xFF, - (GMQCC_VERSION >> 0) & 0xFF, - (GMQCC_VERSION), - __DATE__, - __TIME__ - ); - return 0; +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<