From: Dale Weiler Date: Sun, 2 Dec 2012 04:30:46 +0000 (+0000) Subject: added __STD_VERSION_[MINOR/MAJOR]__, and vec_upload X-Git-Tag: 0.1.9~134 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=37ccf1976968c83c47ee0dfd958a453913cf1b1e;p=xonotic%2Fgmqcc.git added __STD_VERSION_[MINOR/MAJOR]__, and vec_upload --- diff --git a/code.c b/code.c index 9b724cf..73d63b4 100644 --- a/code.c +++ b/code.c @@ -30,7 +30,6 @@ prog_section_field *code_fields; prog_section_function *code_functions; int *code_globals; char *code_chars; - uint16_t code_crc; uint32_t code_entfields; @@ -89,47 +88,6 @@ uint32_t code_cachedstring(const char *str) return code_genstring(str); } -void code_test() { - prog_section_def d1 = { TYPE_VOID, 28, 1 }; - prog_section_def d2 = { TYPE_FUNCTION, 29, 8 }; - prog_section_def d3 = { TYPE_STRING, 30, 14}; - prog_section_function f1 = { 1, 0, 0, 0, 1, 0,0, {0}}; - prog_section_function f2 = {-4, 0, 0, 0, 8, 0,0, {0}}; - prog_section_function f3 = { 0, 0, 0, 0, 14+13, 0,0, {0}}; - prog_section_function f4 = { 0, 0, 0, 0, 14+13+10, 0,0, {0}}; - prog_section_function f5 = { 0, 0, 0, 0, 14+13+10+7, 0,0, {0}}; - prog_section_function f6 = { 0, 0, 0, 0, 14+13+10+7+9, 0,0, {0}}; - prog_section_statement s1 = { INSTR_STORE_F, {30}, {OFS_PARM0}, {0}}; - prog_section_statement s2 = { INSTR_CALL1, {29}, {0}, {0}}; - prog_section_statement s3 = { INSTR_RETURN, {0}, {0}, {0}}; - - strcpy(vec_add(code_chars, 0x7), "m_init"); - strcpy(vec_add(code_chars, 0x6), "print"); - strcpy(vec_add(code_chars, 0xD), "hello world\n"); - strcpy(vec_add(code_chars, 0xA), "m_keydown"); - strcpy(vec_add(code_chars, 0x7), "m_draw"); - strcpy(vec_add(code_chars, 0x9), "m_toggle"); - strcpy(vec_add(code_chars, 0xB), "m_shutdown"); - - vec_push(code_globals, 1); /* m_init */ - vec_push(code_globals, 2); /* print */ - vec_push(code_globals, 14); /* hello world in string table */ - - /* now the defs */ - vec_push(code_defs, d1); /* m_init */ - vec_push(code_defs, d2); /* print */ - vec_push(code_defs, d3); /*hello_world*/ - vec_push(code_functions, f1); /* m_init */ - vec_push(code_functions, f2); /* print */ - vec_push(code_functions, f3); /* m_keydown */ - vec_push(code_functions, f4); - vec_push(code_functions, f5); - vec_push(code_functions, f6); - vec_push(code_statements, s1); - vec_push(code_statements, s2); - vec_push(code_statements, s3); -} - qcint code_alloc_field (size_t qcsize) { qcint pos = (qcint)code_entfields; @@ -178,27 +136,16 @@ bool code_write(const char *filename, const char *lnofile) { if (!fp) return false; - if (fwrite(&lnotype, sizeof(lnotype), 1, fp) != 1 || - fwrite(&version, sizeof(version), 1, fp) != 1 || - fwrite(&code_header.defs.length, sizeof(code_header.defs.length), 1, fp) != 1 || - fwrite(&code_header.globals.length, sizeof(code_header.globals.length), 1, fp) != 1 || - fwrite(&code_header.fields.length, sizeof(code_header.fields.length), 1, fp) != 1 || - fwrite(&code_header.statements.length, sizeof(code_header.statements.length), 1, fp) != 1 || - fwrite(code_linenums, sizeof(code_linenums[0]), vec_size(code_linenums), fp) != vec_size(code_linenums)) + if (fwrite(&lnotype, sizeof(lnotype), 1, fp) != 1 || + fwrite(&version, sizeof(version), 1, fp) != 1 || + fwrite(&code_header.defs.length, sizeof(code_header.defs.length), 1, fp) != 1 || + fwrite(&code_header.globals.length, sizeof(code_header.globals.length), 1, fp) != 1 || + fwrite(&code_header.fields.length, sizeof(code_header.fields.length), 1, fp) != 1 || + fwrite(&code_header.statements.length, sizeof(code_header.statements.length), 1, fp) != 1 || + fwrite(code_linenums, sizeof(code_linenums[0]), vec_size(code_linenums), fp) != vec_size(code_linenums)) { con_err("failed to write lno file\n"); } - /* - h = SafeOpenWrite (destfile, 2*1024*1024); - SafeWrite (h, &lnotype, sizeof(int)); - SafeWrite (h, &version, sizeof(int)); - SafeWrite (h, &numglobaldefs, sizeof(int)); - SafeWrite (h, &numpr_globals, sizeof(int)); - SafeWrite (h, &numfielddefs, sizeof(int)); - SafeWrite (h, &numstatements, sizeof(int)); - SafeWrite (h, statement_linenums, numstatements*sizeof(int)); - SafeClose (h); - */ fclose(fp); fp = NULL; diff --git a/ftepp.c b/ftepp.c index 0a7ba6b..84c1719 100644 --- a/ftepp.c +++ b/ftepp.c @@ -1,6 +1,7 @@ /* * Copyright (C) 2012 * Wolfgang Bumiller + * Dale Weiler * * 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 @@ -1367,19 +1368,48 @@ bool ftepp_preprocess_string(const char *name, const char *str) bool ftepp_init() { + char minor[32]; + char major[32]; + char *verminor = NULL; + char *vermajor = NULL; + ftepp = ftepp_new(); if (!ftepp) return false; + memset(minor, 0, sizeof(minor)); + memset(major, 0, sizeof(major)); + /* set the right macro based on the selected standard */ ftepp_add_define(NULL, "GMQCC"); - if (opts_standard == COMPILER_FTEQCC) + if (opts_standard == COMPILER_FTEQCC) { ftepp_add_define(NULL, "__STD_FTEQCC__"); - else if (opts_standard == COMPILER_GMQCC) + /* 1.00 */ + major[0] = '1'; + minor[0] = '0'; + } else if (opts_standard == COMPILER_GMQCC) { ftepp_add_define(NULL, "__STD_GMQCC__"); - else if (opts_standard == COMPILER_QCC) + sprintf(major, "%d", GMQCC_VERSION_MAJOR); + sprintf(minor, "%d", GMQCC_VERSION_MINOR); + } else if (opts_standard == COMPILER_QCC) { ftepp_add_define(NULL, "__STD_QCC__"); + /* 1.0 */ + major[0] = '1'; + minor[0] = '0'; + } + + vec_upload(verminor, "#define __STD_VERSION_MINOR__ \"", 31); + vec_upload(vermajor, "#define __STD_VERSION_MAJOR__ \"", 31); + vec_upload(verminor, minor, strlen(minor)); + vec_upload(vermajor, major, strlen(major)); + vec_push (verminor, '"'); + vec_push (vermajor, '"'); + + ftepp_preprocess_string("__builtin__", verminor); + ftepp_preprocess_string("__builtin__", vermajor); + vec_free(verminor); + vec_free(vermajor); return true; } diff --git a/gmqcc.h b/gmqcc.h index cc26505..2253c9e 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -263,6 +263,15 @@ void _util_vec_grow(void **a, size_t i, size_t s); #define vec_shrinkto(A,N) (_vec_end(A) = (N)) #define vec_shrinkby(A,N) (_vec_end(A) -= (N)) +#define vec_upload(X,Y,S) \ + do { \ + size_t E = 0; \ + while (E < S) { \ + vec_push(X, Y[E]); \ + E ++; \ + } \ + } while(0) + typedef struct hash_table_t { size_t size; struct hash_node_t **table; @@ -333,21 +342,21 @@ enum { #define CV_CONST 1 #define CV_VAR -1 -extern const char *type_name[TYPE_COUNT]; +extern const char *type_name [TYPE_COUNT]; +extern size_t type_sizeof [TYPE_COUNT]; +extern uint16_t type_store_instr [TYPE_COUNT]; +extern uint16_t field_store_instr[TYPE_COUNT]; -extern size_t type_sizeof[TYPE_COUNT]; -extern uint16_t type_store_instr[TYPE_COUNT]; -extern uint16_t field_store_instr[TYPE_COUNT]; -/* could use type_store_instr + INSTR_STOREP_F - INSTR_STORE_F +/* + * could use type_store_instr + INSTR_STOREP_F - INSTR_STORE_F * but this breaks when TYPE_INTEGER is added, since with the enhanced * instruction set, the old ones are left untouched, thus the _I instructions * are at a seperate place. */ extern uint16_t type_storep_instr[TYPE_COUNT]; -/* other useful lists */ -extern uint16_t type_eq_instr[TYPE_COUNT]; -extern uint16_t type_ne_instr[TYPE_COUNT]; -extern uint16_t type_not_instr[TYPE_COUNT]; +extern uint16_t type_eq_instr [TYPE_COUNT]; +extern uint16_t type_ne_instr [TYPE_COUNT]; +extern uint16_t type_not_instr [TYPE_COUNT]; typedef struct { uint32_t offset; /* Offset in file of where data begins */ @@ -356,15 +365,15 @@ typedef struct { typedef struct { uint32_t version; /* Program version (6) */ - uint16_t crc16; /* What is this? */ - uint16_t skip; /* see propsal.txt */ + uint16_t crc16; + uint16_t skip; prog_section statements; /* prog_section_statement */ prog_section defs; /* prog_section_def */ prog_section fields; /* prog_section_field */ prog_section functions; /* prog_section_function */ - prog_section strings; /* What is this? */ - prog_section globals; /* What is this? */ + prog_section strings; + prog_section globals; uint32_t entfield; /* Number of entity fields */ } prog_header; @@ -414,7 +423,8 @@ typedef struct { } prog_section_statement; typedef struct { - /* The types: + /* + * The types: * 0 = ev_void * 1 = ev_string * 2 = ev_float @@ -429,6 +439,7 @@ typedef struct { uint16_t offset; uint32_t name; } prog_section_both; + typedef prog_section_both prog_section_def; typedef prog_section_both prog_section_field; @@ -570,7 +581,6 @@ typedef struct { size_t line; } lex_ctx; - /*===================================================================*/ /*============================ con.c ================================*/ /*===================================================================*/ @@ -592,27 +602,26 @@ enum { LVL_ERROR }; - void con_vprintmsg (int level, const char *name, size_t line, const char *msgtype, const char *msg, va_list ap); void con_printmsg (int level, const char *name, size_t line, const char *msgtype, const char *msg, ...); void con_cvprintmsg(void *ctx, int lvl, const char *msgtype, const char *msg, va_list ap); void con_cprintmsg (void *ctx, int lvl, const char *msgtype, const char *msg, ...); -void con_close(); -void con_color(int state); -void con_init (); -void con_reset(); -int con_change(const char *out, const char *err); -int con_verr (const char *fmt, va_list va); -int con_vout (const char *fmt, va_list va); -int con_err (const char *fmt, ...); -int con_out (const char *fmt, ...); +void con_close (); +void con_init (); +void con_reset (); +void con_color (int); +int con_change(const char *, const char *); +int con_verr (const char *, va_list); +int con_vout (const char *, va_list); +int con_err (const char *, ...); +int con_out (const char *, ...); /* error/warning interface */ extern size_t compile_errors; extern size_t compile_warnings; -void compile_error(lex_ctx ctx, const char *msg, ...); +void /********/ compile_error (lex_ctx ctx, /*LVL_ERROR*/ const char *msg, ...); bool GMQCC_WARN compile_warning(lex_ctx ctx, int warntype, const char *fmt, ...); /*===================================================================*/ @@ -717,7 +726,8 @@ vector vec3_mulvf(vector, float); /*============================= exec.c ==============================*/ /*===================================================================*/ -/* darkplaces has (or will have) a 64 bit prog loader +/* + * Darkplaces has (or will have) a 64 bit prog loader * where the 32 bit qc program is autoconverted on load. * Since we may want to support that as well, let's redefine * float and int here. @@ -855,7 +865,7 @@ typedef uint32_t longbit; /* Used to store the list of flags with names */ typedef struct { const char *name; - longbit bit; + longbit bit; } opts_flag_def; /*===================================================================*/ @@ -913,6 +923,7 @@ enum { COMPILER_QCCX, /* qccx QuakeC */ COMPILER_GMQCC /* this QuakeC */ }; + extern uint32_t opts_O; /* -Ox */ extern const char *opts_output; /* -o file */ extern int opts_standard; @@ -927,11 +938,12 @@ extern bool opts_pp_only; extern size_t opts_max_array_size; /*===================================================================*/ -#define OPTS_FLAG(i) (!! (opts_flags[(i)/32] & (1<< ((i)%32)))) -extern uint32_t opts_flags[1 + (COUNT_FLAGS / 32)]; -#define OPTS_WARN(i) (!! (opts_warn[(i)/32] & (1<< ((i)%32)))) -extern uint32_t opts_warn[1 + (COUNT_WARNINGS / 32)]; +#define OPTS_FLAG(i) (!! (opts_flags [(i)/32] & (1<< ((i)%32)))) +#define OPTS_WARN(i) (!! (opts_warn [(i)/32] & (1<< ((i)%32)))) #define OPTS_OPTIMIZATION(i) (!! (opts_optimization[(i)/32] & (1<< ((i)%32)))) + +extern uint32_t opts_flags [1 + (COUNT_FLAGS / 32)]; +extern uint32_t opts_warn [1 + (COUNT_WARNINGS / 32)]; extern uint32_t opts_optimization[1 + (COUNT_OPTIMIZATIONS / 32)]; #endif