mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-11-27 22:22:17 +00:00
Merge branch 'master' into blub/ast-and-ir-merging
This commit is contained in:
commit
69173876f1
4 changed files with 67 additions and 43 deletions
19
Makefile_win
Normal file
19
Makefile_win
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
CC = i486-mingw32-gcc
|
||||||
|
CFLAGS += -Wall
|
||||||
|
OBJ = main.o \
|
||||||
|
lex.o \
|
||||||
|
error.o \
|
||||||
|
parse.o \
|
||||||
|
typedef.o \
|
||||||
|
util.o \
|
||||||
|
code.o \
|
||||||
|
asm.c
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) -c $< -o $@ $(CFLAGS)
|
||||||
|
|
||||||
|
gmqcc: $(OBJ)
|
||||||
|
$(CC) -o $@ $^ $(CFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.o gmqcc
|
9
gmqcc.h
9
gmqcc.h
|
@ -28,6 +28,13 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#define GMQCC_VERSION_MAJOR 0
|
||||||
|
#define GMQCC_VERSION_MINOR 1
|
||||||
|
#define GMQCC_VERSION_PATCH 0
|
||||||
|
#define GMQCC_VERSION_BUILD(J,N,P) (((J)<<16)|((N)<<8)|(P))
|
||||||
|
#define GMQCC_VERSION \
|
||||||
|
GMQCC_VERSION_BUILD(GMQCC_VERSION_MAJOR, GMQCC_VERSION_MINOR, GMQCC_VERSION_PATCH)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We cannoy rely on C99 at all, since compilers like MSVC
|
* We cannoy rely on C99 at all, since compilers like MSVC
|
||||||
* simply don't support it. We define our own boolean type
|
* simply don't support it. We define our own boolean type
|
||||||
|
@ -86,7 +93,7 @@
|
||||||
typedef char uint8_size_is_correct [sizeof(uint8_t) == 1?1:-1];
|
typedef char uint8_size_is_correct [sizeof(uint8_t) == 1?1:-1];
|
||||||
typedef char uint16_size_if_correct [sizeof(uint16_t) == 2?1:-1];
|
typedef char uint16_size_if_correct [sizeof(uint16_t) == 2?1:-1];
|
||||||
typedef char uint32_size_is_correct [sizeof(uint32_t) == 4?1:-1];
|
typedef char uint32_size_is_correct [sizeof(uint32_t) == 4?1:-1];
|
||||||
typedef char int8_size_is_correct [sizeof(int8_t) == 1?1:-1];
|
//typedef char int8_size_is_correct [sizeof(int8_t) == 1?1:-1];
|
||||||
typedef char int16_size_if_correct [sizeof(int16_t) == 2?1:-1];
|
typedef char int16_size_if_correct [sizeof(int16_t) == 2?1:-1];
|
||||||
typedef char int32_size_is_correct [sizeof(int32_t) == 4?1:-1];
|
typedef char int32_size_is_correct [sizeof(int32_t) == 4?1:-1];
|
||||||
/* intptr_t / uintptr_t correct size check */
|
/* intptr_t / uintptr_t correct size check */
|
||||||
|
|
64
main.c
64
main.c
|
@ -33,25 +33,27 @@ bool opts_omit_nullcode = false;
|
||||||
int opts_compiler = COMPILER_GMQCC;
|
int opts_compiler = COMPILER_GMQCC;
|
||||||
|
|
||||||
static const int usage(const char *const app) {
|
static const int usage(const char *const app) {
|
||||||
printf("usage:\n");
|
printf("usage:\n"
|
||||||
printf(" %s -c<file> -oprog.dat -- compile file\n" , app);
|
" %s -c<file> -oprog.dat -- compile file\n"
|
||||||
printf(" %s -a<file> -oprog.dat -- assemble file\n" , app);
|
" %s -a<file> -oprog.dat -- assemble file\n"
|
||||||
printf(" %s -c<file> -i<file> -oprog.dat -- compile together (allowed multiple -i<file>)\n" , app);
|
" %s -c<file> -i<file> -oprog.dat -- compile together (allowed multiple -i<file>)\n"
|
||||||
printf(" %s -a<file> -i<file> -oprog.dat -- assemble together(allowed multiple -i<file>)\n", app);
|
" %s -a<file> -i<file> -oprog.dat -- assemble together(allowed multiple -i<file>)\n"
|
||||||
printf(" example:\n");
|
" example:\n"
|
||||||
printf(" %s -cfoo.qc -ibar.qc -oqc.dat -afoo.qs -ibar.qs -oqs.dat\n", app);
|
" %s -cfoo.qc -ibar.qc -oqc.dat -afoo.qs -ibar.qs -oqs.dat\n"
|
||||||
printf(" additional flags:\n");
|
" additional flags:\n"
|
||||||
printf(" -debug -- turns on compiler debug messages\n");
|
" -debug -- turns on compiler debug messages\n"
|
||||||
printf(" -memchk -- turns on compiler memory leak check\n");
|
" -memchk -- turns on compiler memory leak check\n"
|
||||||
printf(" -help -- prints this help/usage text\n");
|
" -help -- prints this help/usage text\n"
|
||||||
printf(" -std -- select the QuakeC compile type (types below):\n");
|
" -std -- select the QuakeC compile type (types below):\n"
|
||||||
printf(" -std=qcc -- original QuakeC\n");
|
" -std=qcc -- original QuakeC\n"
|
||||||
printf(" -std=ftqecc -- fteqcc QuakeC\n");
|
" -std=ftqecc -- fteqcc QuakeC\n"
|
||||||
printf(" -std=qccx -- qccx QuakeC\n");
|
" -std=qccx -- qccx QuakeC\n"
|
||||||
printf(" -std=gmqcc -- this compiler QuakeC (default selection)\n");
|
" -std=gmqcc -- this compiler QuakeC (default selection)\n"
|
||||||
printf(" codegen flags:\n");
|
" codegen flags:\n"
|
||||||
printf(" -fdarkplaces-string-table-bug -- patches the string table to work with bugged versions of darkplaces\n");
|
" -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");
|
" -fomit-nullcode -- omits the generation of null code (will break everywhere see propsal.txt)\n",
|
||||||
|
app,app,app,app,app
|
||||||
|
);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +71,20 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
while ((argc > 1) && argv[1][0] == '-') {
|
while ((argc > 1) && argv[1][0] == '-') {
|
||||||
switch (argv[1][1]) {
|
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;
|
||||||
|
}
|
||||||
case 'c': items_add((argitem){util_strdup(&argv[1][2]), 0}); break; /* compile */
|
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 '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 */
|
case 'i': items_add((argitem){util_strdup(&argv[1][2]), 2}); break; /* includes */
|
||||||
|
@ -85,11 +101,11 @@ int main(int argc, char **argv) {
|
||||||
if (!strncmp(&argv[1][1], "std=qccx", 8 )) { opts_compiler = COMPILER_QCCX; 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=gmqcc", 9 )) { opts_compiler = COMPILER_GMQCC; break; }
|
||||||
if (!strncmp(&argv[1][1], "std=", 4 )) {
|
if (!strncmp(&argv[1][1], "std=", 4 )) {
|
||||||
printf("invalid std selection, supported types:\n");
|
printf("invalid std selection, supported types:\n"
|
||||||
printf(" -std=qcc -- original QuakeC\n");
|
" -std=qcc -- original QuakeC\n"
|
||||||
printf(" -std=ftqecc -- fteqcc QuakeC\n");
|
" -std=ftqecc -- fteqcc QuakeC\n"
|
||||||
printf(" -std=qccx -- qccx QuakeC\n");
|
" -std=qccx -- qccx QuakeC\n"
|
||||||
printf(" -std=gmqcc -- this compiler QuakeC (default selection)\n");
|
" -std=gmqcc -- this compiler QuakeC (default selection)\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
util.c
18
util.c
|
@ -335,21 +335,3 @@ int util_getline(char **lineptr, size_t *n, FILE *stream) {
|
||||||
*pos = '\0';
|
*pos = '\0';
|
||||||
return (ret = pos - *lineptr);
|
return (ret = pos - *lineptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Strechy string buffer (for easy string creation) -- this is fast, just
|
|
||||||
* say no to strict aliasing.
|
|
||||||
*/
|
|
||||||
//#define util_stringbuf_add(a,v) ((((a)==0 ||((int*)(a)-2)[1]+(1)>=((int*)(a)-2)[0])?util_stringbuf_grow((void**)&(a),(1),sizeof(*(a))):0),(a)[((int*)(a)-2)[1]++]=(v))
|
|
||||||
//#define util_stringbuf_len(a) ((a)? ((int*)(a)-2)[1]:0)
|
|
||||||
//#define util_stringbuf_del(a) ((a)?free (((int*)(a)-2)),0:0)
|
|
||||||
void *util_stringbuf_grow(void **a, int in, int it) {
|
|
||||||
int m = *a ? 2 * ((int*)(*a)-2)[0]+in : in+1;
|
|
||||||
void *p = realloc(*a ? ((int*)(*a)-2) : 0, it * m + sizeof(int)*2);
|
|
||||||
if (p) {
|
|
||||||
if (!*a) ((int*)p)[1] = 0;
|
|
||||||
*a = (void*)((int*)p+2);
|
|
||||||
((int*)(*a)-2)[0] = m;
|
|
||||||
}
|
|
||||||
return *a;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue