X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=main.c;h=4c8062d7dcdb1b125101c77348c26952c9ac592c;hp=54c64b639ca4ae0103ad60ce52e2cd01f5122d1b;hb=61fa54318c3aa1ce0c2099f9793d830e5896c016;hpb=975356cbce515a5d558a9def6f26a4b311965546 diff --git a/main.c b/main.c index 54c64b6..4c8062d 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,7 @@ /* * 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,87 +22,602 @@ * SOFTWARE. */ #include "gmqcc.h" +#include "lexer.h" -static const char *output = "progs.dat"; -static const char *input = NULL; - -#define OptReq(opt, body) \ - case opt: \ - if (argv[0][2]) argarg = argv[0]+2; \ - else { \ - if (argc < 2) { \ - printf("option -%c requires an argument\n", opt); \ - exit(1); \ - } \ - argarg = argv[1]; \ - --argc; \ - ++argv; \ - } \ - do { body } while (0); \ - break; - -#define LongReq(opt, body) \ - if (!strcmp(argv[0], opt)) { \ - if (argc < 2) { \ - printf("option " opt " requires an argument\n"); \ - exit(1); \ - } \ - argarg = argv[1]; \ - --argc; \ - ++argv; \ - do { body } while (0); \ - break; \ - } else if (!strncmp(argv[0], opt "=", sizeof(opt "="))) \ - { \ - argarg = argv[0] + sizeof(opt "="); \ - do { body } while (0); \ - break; \ +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; +} + +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<