]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - gmqcc.h
Major utility rewrite for compiler memory utilization statistics. Cleanups everywhere...
[xonotic/gmqcc.git] / gmqcc.h
diff --git a/gmqcc.h b/gmqcc.h
index f09cd10905bdf53b1793efa61b583a18b89bd335..8edcbda59de899e2da20d6ad98132fca7715b899 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
 #endif /*! _MSC_VER */
 
 #define GMQCC_VERSION_MAJOR 0
-#define GMQCC_VERSION_MINOR 2
-#define GMQCC_VERSION_PATCH 9
+#define GMQCC_VERSION_MINOR 3
+#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)
 /* Undefine the following on a release-tag: */
-/* #define GMQCC_VERSION_TYPE_DEVEL */
+#define GMQCC_VERSION_TYPE_DEVEL
 
 /* Full version string in case we need it */
 #ifdef GMQCC_VERSION_TYPE_DEVEL
@@ -288,20 +288,47 @@ GMQCC_IND_STRING(GMQCC_VERSION_PATCH) \
 #   include <dirent.h>
 #endif /*! _WIN32 && !defined(__MINGW32__) */
 
+/*===================================================================*/
+/*=========================== stat.c ================================*/
+/*===================================================================*/
+typedef struct {
+    size_t key;
+    size_t value;
+} stat_size_entry_t, **stat_size_table_t;
+
+void  stat_info();
+
+char *stat_mem_strdup    (const char *, size_t,         const char *, bool);
+void *stat_mem_reallocate(void *,       size_t, size_t, const char *);
+void  stat_mem_deallocate(void *);
+void *stat_mem_allocate  (size_t, size_t, const char *);
+
+stat_size_table_t  stat_size_new();
+stat_size_entry_t *stat_size_get(stat_size_table_t, size_t);
+void               stat_size_del(stat_size_table_t);
+void               stat_size_put(stat_size_table_t, size_t, size_t);
+
+/* getters for hashtable: */
+stat_size_table_t *stat_size_hashtables_get();
+uint64_t          *stat_type_hashtables_get();
+uint64_t          *stat_used_hashtables_get();
+stat_size_table_t *stat_hashtables_init();
+
+#define mem_a(SIZE)              stat_mem_allocate  ((SIZE), __LINE__, __FILE__)
+#define mem_d(PTRN)              stat_mem_deallocate((void*)(PTRN))
+#define mem_r(PTRN, SIZE)        stat_mem_reallocate((void*)(PTRN), (SIZE), __LINE__, __FILE__)
+#define mem_af(SIZE, FILE, LINE) stat_mem_allocate  ((SIZE), (LINE), (FILE))
+
+/* TODO: rename to mem variations */
+#define util_strdup(SRC)         stat_mem_strdup((char*)(SRC), __LINE__, __FILE__, false)
+#define util_strdupe(SRC)        stat_mem_strdup((char*)(SRC), __LINE__, __FILE__, true)
 
 /*===================================================================*/
 /*=========================== util.c ================================*/
 /*===================================================================*/
-void *util_memory_a      (size_t, /*****/ unsigned int, const char *);
-void *util_memory_r      (void *, size_t, unsigned int, const char *);
-void  util_memory_d      (void *);
-void  util_meminfo       ();
-
 bool  util_filexists     (const char *);
 bool  util_strupper      (const char *);
 bool  util_strdigit      (const char *);
-char *_util_Estrdup      (const char *, const char *, size_t);
-char *_util_Estrdup_empty(const char *, const char *, size_t);
 void  util_debug         (const char *, const char *, ...);
 void  util_endianswap    (void *,  size_t, unsigned int);
 
@@ -326,22 +353,6 @@ char       *util_strcat   (char *dest, const char *src);
 char       *util_strncpy  (char *dest, const char *src, size_t num);
 const char *util_strerror (int num);
 
-
-#ifdef NOTRACK
-#    define mem_a(x)      malloc (x)
-#    define mem_d(x)      free   ((void*)x)
-#    define mem_r(x, n)   realloc((void*)x, n)
-#    define mem_af(x,f,l) malloc (x)
-#else
-#    define mem_a(x)      util_memory_a((x), __LINE__, __FILE__)
-#    define mem_d(x)      util_memory_d((void*)(x))
-#    define mem_r(x, n)   util_memory_r((void*)(x), (n), __LINE__, __FILE__)
-#    define mem_af(x,f,l) util_memory_a((x), __LINE__, __FILE__)
-#endif /*! NOTRACK */
-
-#define util_strdup(X)  _util_Estrdup((X), __FILE__, __LINE__)
-#define util_strdupe(X) _util_Estrdup_empty((X), __FILE__, __LINE__)
-
 /*
  * A flexible vector implementation: all vector pointers contain some
  * data about themselfs exactly - sizeof(vector_t) behind the pointer
@@ -734,7 +745,9 @@ typedef struct {
  * code_pop_statement  -- keeps statements and linenumbers together 
  */
 bool      code_write         (code_t *, const char *filename, const char *lno);
+GMQCC_WARN
 code_t   *code_init          (void);
+void      code_cleanup       (code_t *);
 uint32_t  code_genstring     (code_t *, const char *string);
 qcint     code_alloc_field   (code_t *, size_t qcsize);
 void      code_push_statement(code_t *, prog_section_statement *stmt, int linenum);
@@ -747,6 +760,7 @@ void      code_pop_statement (code_t *);
 typedef struct {
     const char *file;
     size_t      line;
+    size_t      column;
 } lex_ctx;
 
 /*===================================================================*/
@@ -773,8 +787,8 @@ enum {
 FILE *con_default_out();
 FILE *con_default_err();
 
-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_vprintmsg (int level, const char *name, size_t line, size_t column, const char *msgtype, const char *msg, va_list ap);
+void con_printmsg  (int level, const char *name, size_t line, size_t column, 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, ...);
 
@@ -991,7 +1005,7 @@ void        prog_delete(qc_program *prog);
 
 bool prog_exec(qc_program *prog, prog_section_function *func, size_t flags, long maxjumps);
 
-char*             prog_getstring (qc_program *prog, qcint str);
+const char*       prog_getstring (qc_program *prog, qcint str);
 prog_section_def* prog_entfield  (qc_program *prog, qcint off);
 prog_section_def* prog_getdef    (qc_program *prog, qcint off);
 qcany*            prog_getedict  (qc_program *prog, qcint e);
@@ -1161,7 +1175,7 @@ typedef struct {
 
 extern opts_cmd_t opts;
 
-#define OPTS_GENERIC(f,i)    (!! (((f)[(i)/32]) & (1<< ((i)%32))))
+#define OPTS_GENERIC(f,i)    (!! (((f)[(i)/32]) & (1<< (unsigned)((i)%32))))
 #define OPTS_FLAG(i)         OPTS_GENERIC(opts.flags,        (i))
 #define OPTS_WARN(i)         OPTS_GENERIC(opts.warn,         (i))
 #define OPTS_WERROR(i)       OPTS_GENERIC(opts.werror,       (i))