2012-04-09 10:42:06 +00:00
|
|
|
/*
|
2012-04-28 20:43:39 +00:00
|
|
|
* Copyright (C) 2012
|
2012-04-17 20:24:22 +00:00
|
|
|
* Dale Weiler
|
2012-04-09 10:42:06 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the Software without restriction, including without limitation the rights to
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
|
|
|
* so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
2012-04-17 08:29:58 +00:00
|
|
|
#include "gmqcc.h"
|
2012-04-20 05:20:22 +00:00
|
|
|
typedef struct { char *name, type; } argitem;
|
|
|
|
VECTOR_MAKE(argitem, items);
|
|
|
|
|
|
|
|
static const int usage(const char *const app) {
|
2012-04-26 15:37:47 +00:00
|
|
|
printf("usage:\n"
|
|
|
|
" %s -c<file> -oprog.dat -- compile file\n"
|
|
|
|
" %s -a<file> -oprog.dat -- assemble file\n"
|
|
|
|
" %s -c<file> -i<file> -oprog.dat -- compile together (allowed multiple -i<file>)\n"
|
|
|
|
" %s -a<file> -i<file> -oprog.dat -- assemble together(allowed multiple -i<file>)\n"
|
|
|
|
" example:\n"
|
2012-04-28 22:56:09 +00:00
|
|
|
" %s -cfoo.qc -ibar.qc -oqc.dat -afoo.qs -ibar.qs -oqs.dat\n", app, app, app, app, app);
|
2012-04-28 23:03:16 +00:00
|
|
|
|
2012-04-28 22:56:09 +00:00
|
|
|
printf(" additional flags:\n"
|
2012-04-26 15:37:47 +00:00
|
|
|
" -debug -- turns on compiler debug messages\n"
|
|
|
|
" -memchk -- turns on compiler memory leak check\n"
|
|
|
|
" -help -- prints this help/usage text\n"
|
2012-04-28 22:56:09 +00:00
|
|
|
" -std -- select the QuakeC compile type (types below):\n");
|
2012-04-28 23:03:16 +00:00
|
|
|
|
2012-04-28 22:56:09 +00:00
|
|
|
printf(" -std=qcc -- original QuakeC\n"
|
2012-04-26 15:37:47 +00:00
|
|
|
" -std=ftqecc -- fteqcc QuakeC\n"
|
|
|
|
" -std=qccx -- qccx QuakeC\n"
|
2012-04-28 22:56:09 +00:00
|
|
|
" -std=gmqcc -- this compiler QuakeC (default selection)\n");
|
2012-04-28 23:03:16 +00:00
|
|
|
|
2012-04-28 22:56:09 +00:00
|
|
|
printf(" codegen flags:\n"
|
2012-04-26 15:37:47 +00:00
|
|
|
" -fdarkplaces-string-table-bug -- patches the string table to work with bugged versions of darkplaces\n"
|
2012-04-28 22:56:09 +00:00
|
|
|
" -fomit-nullcode -- omits the generation of null code (will break everywhere see propsal.txt)\n");
|
2012-04-20 05:20:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2012-04-28 09:35:32 +00:00
|
|
|
size_t itr = 0;
|
|
|
|
char *app = &argv[0][0];
|
|
|
|
FILE *fpp = NULL;
|
|
|
|
lex_file *lex = NULL;
|
2012-04-20 05:20:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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]) {
|
2012-04-26 15:37:47 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-04-28 19:20:13 +00:00
|
|
|
#define param_argument(argtype) do { \
|
2012-04-28 22:56:09 +00:00
|
|
|
argitem item; \
|
2012-04-28 19:36:39 +00:00
|
|
|
if (argv[1][2]) { \
|
2012-04-28 22:56:09 +00:00
|
|
|
item.name = util_strdup(&argv[1][2]); \
|
|
|
|
item.type = argtype; \
|
|
|
|
items_add(item); \
|
2012-04-28 19:36:39 +00:00
|
|
|
} else { \
|
|
|
|
++argv; \
|
|
|
|
--argc; \
|
2012-04-28 19:20:13 +00:00
|
|
|
if (argc <= 1) \
|
|
|
|
goto clean_params_usage; \
|
2012-04-28 22:56:09 +00:00
|
|
|
item.name = util_strdup(argv[1]); \
|
|
|
|
item.type = argtype; \
|
|
|
|
items_add(item); \
|
2012-04-28 22:56:44 +00:00
|
|
|
} \
|
2012-04-28 19:20:13 +00:00
|
|
|
} while (0)
|
2012-04-28 12:32:52 +00:00
|
|
|
|
2012-04-28 22:56:09 +00:00
|
|
|
case 'c': { param_argument(0); break; } /* compile */
|
|
|
|
case 'a': { param_argument(1); break; } /* assemble */
|
|
|
|
case 'i': { param_argument(2); break; } /* includes */
|
2012-04-28 19:20:13 +00:00
|
|
|
#undef parm_argument
|
2012-04-20 05:20:22 +00:00
|
|
|
default:
|
2012-04-25 21:03:56 +00:00
|
|
|
if (!strncmp(&argv[1][1], "debug" , 5)) { opts_debug = true; break; }
|
|
|
|
if (!strncmp(&argv[1][1], "memchk", 6)) { opts_memchk = true; break; }
|
2012-04-22 02:55:30 +00:00
|
|
|
if (!strncmp(&argv[1][1], "help", 4)) {
|
|
|
|
return usage(app);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* compiler type selection */
|
|
|
|
if (!strncmp(&argv[1][1], "std=qcc" , 7 )) { opts_compiler = COMPILER_QCC; break; }
|
|
|
|
if (!strncmp(&argv[1][1], "std=fteqcc", 10)) { opts_compiler = COMPILER_FTEQCC; break; }
|
|
|
|
if (!strncmp(&argv[1][1], "std=qccx", 8 )) { opts_compiler = COMPILER_QCCX; break; }
|
|
|
|
if (!strncmp(&argv[1][1], "std=gmqcc", 9 )) { opts_compiler = COMPILER_GMQCC; break; }
|
|
|
|
if (!strncmp(&argv[1][1], "std=", 4 )) {
|
2012-04-26 15:37:47 +00:00
|
|
|
printf("invalid std selection, supported types:\n"
|
|
|
|
" -std=qcc -- original QuakeC\n"
|
|
|
|
" -std=ftqecc -- fteqcc QuakeC\n"
|
|
|
|
" -std=qccx -- qccx QuakeC\n"
|
|
|
|
" -std=gmqcc -- this compiler QuakeC (default selection)\n");
|
2012-04-22 02:55:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-04-22 20:58:12 +00:00
|
|
|
|
|
|
|
/* code specific switches */
|
2012-04-24 17:05:19 +00:00
|
|
|
if (!strcmp(&argv[1][1], "fdarkplaces-stringtablebug")) {
|
2012-04-25 21:03:56 +00:00
|
|
|
opts_darkplaces_stringtablebug = true;
|
2012-04-22 20:58:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-04-24 12:19:48 +00:00
|
|
|
if (!strcmp(&argv[1][1], "fomit-nullcode")) {
|
2012-04-25 21:03:56 +00:00
|
|
|
opts_omit_nullcode = true;
|
2012-04-24 12:19:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-04-20 05:20:22 +00:00
|
|
|
return usage(app);
|
2012-04-28 20:43:39 +00:00
|
|
|
|
2012-04-20 05:20:22 +00:00
|
|
|
}
|
|
|
|
++argv;
|
|
|
|
--argc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* options could depend on another option, this is where option
|
|
|
|
* validity checking like that would take place.
|
|
|
|
*/
|
2012-04-28 20:43:39 +00:00
|
|
|
if (opts_memchk && !opts_debug)
|
2012-04-20 05:20:22 +00:00
|
|
|
printf("Warning: cannot enable -memchk, without -debug.\n");
|
|
|
|
|
2012-04-22 02:55:30 +00:00
|
|
|
util_debug("COM", "starting ...\n");
|
2012-04-20 05:20:22 +00:00
|
|
|
/* multi file multi path compilation system */
|
|
|
|
for (; itr < items_elements; itr++) {
|
|
|
|
switch (items_data[itr].type) {
|
|
|
|
case 0:
|
2012-04-28 09:35:32 +00:00
|
|
|
lex_init (items_data[itr].name, &lex);
|
2012-04-28 22:56:09 +00:00
|
|
|
if (lex) {
|
|
|
|
lex_parse(lex);
|
|
|
|
lex_close(lex);
|
|
|
|
}
|
2012-04-20 05:20:22 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
asm_init (items_data[itr].name, &fpp);
|
2012-04-28 22:56:09 +00:00
|
|
|
if (fpp) {
|
|
|
|
asm_parse(fpp);
|
|
|
|
asm_close(fpp);
|
|
|
|
}
|
2012-04-20 05:20:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-04-22 02:55:30 +00:00
|
|
|
|
2012-04-28 20:43:39 +00:00
|
|
|
util_debug("COM", "cleaning ...\n");
|
2012-04-20 05:20:22 +00:00
|
|
|
/* clean list */
|
|
|
|
for (itr = 0; itr < items_elements; itr++)
|
|
|
|
mem_d(items_data[itr].name);
|
|
|
|
mem_d(items_data);
|
2012-04-28 20:43:39 +00:00
|
|
|
|
2012-04-20 05:24:11 +00:00
|
|
|
util_meminfo();
|
2012-04-17 20:24:22 +00:00
|
|
|
return 0;
|
2012-04-28 23:03:16 +00:00
|
|
|
|
2012-04-28 12:32:52 +00:00
|
|
|
clean_params_usage:
|
|
|
|
for (itr = 0; itr < items_elements; itr++)
|
|
|
|
mem_d(items_data[itr].name);
|
|
|
|
mem_d(items_data);
|
|
|
|
return usage(app);
|
2012-04-09 10:42:06 +00:00
|
|
|
}
|