]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - gmqcc.h
AUTHORS
[xonotic/gmqcc.git] / gmqcc.h
diff --git a/gmqcc.h b/gmqcc.h
index 14a4022d3bc15d05292381f055226129e7275c17..5edaeae14bd8172c9f0bcbf98d007c0d94174e7a 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -67,7 +67,7 @@ typedef char int16_size_if_correct  [sizeof(int16_t)  == 2?1:-1];
 typedef char int32_size_is_correct  [sizeof(int32_t)  == 4?1:-1];
 /* intptr_t / uintptr_t correct size check */
 typedef char uintptr_size_is_correct[sizeof(intptr_t) == sizeof(int*)?1:-1];
-typedef char uintptr_size_is_correct[sizeof(uintptr_t)== sizeof(int*)?1:-1];
+typedef char intptr_size_is_correct [sizeof(uintptr_t)== sizeof(int*)?1:-1];
 
 //===================================================================
 //============================ lex.c ================================
@@ -156,13 +156,18 @@ int           typedef_add (struct lex_file *file, const char *, const char *);
 //===================================================================
 //=========================== util.c ================================
 //===================================================================
-void *util_memory_a(unsigned int, unsigned int, const char *);
-void  util_memory_d(void       *, unsigned int, const char *);
-char *util_strdup  (const char *);
-char *util_strrq   (char *);
-char *util_strrnl  (char *);
-void  util_debug   (const char *, const char *, ...);
-int   util_getline (char **, size_t *, FILE *);
+void *util_memory_a  (unsigned int, unsigned int, const char *);
+void  util_memory_d  (void       *, unsigned int, const char *);
+void  util_meminfo   ();
+
+char *util_strdup    (const char *);
+char *util_strrq     (char *);
+char *util_strrnl    (char *);
+void  util_debug     (const char *, const char *, ...);
+int   util_getline   (char **, size_t *, FILE *);
+void  util_endianswap(void *, int, int);
+
+uint32_t util_crc32(const char *, int, register const short); 
 
 #ifdef NOTRACK
 #    define mem_a(x) malloc(x)
@@ -185,10 +190,11 @@ int   util_getline (char **, size_t *, FILE *);
             }                                                            \
             void *temp = mem_a(N##_allocated * sizeof(T));               \
             if  (!temp) {                                                \
-                free(temp);                                              \
+                mem_d(temp);                                             \
                 return -1;                                               \
             }                                                            \
             memcpy(temp, N##_data, (N##_elements * sizeof(T)));          \
+            mem_d(N##_data);                                             \
             N##_data = (T*)temp;                                         \
         }                                                                \
         N##_data[N##_elements] = element;                                \
@@ -211,13 +217,13 @@ int   util_getline (char **, size_t *, FILE *);
  * Each paramater incerements by 3 since vector types hold
  * 3 components (x,y,z).
  */
-#define    OFS_NULL      0
-#define    OFS_RETURN    1
-#define    OFS_PARM0     (OFS_RETURN+3)
-#define    OFS_PARM1     (OFS_PARM0 +3)
-#define    OFS_PARM2     (OFS_PARM1 +3)
-#define    OFS_PARM3     (OFS_PARM2 +3)
-#define    OFS_PARM4     (OFS_PARM3 +3)
+#define OFS_NULL      0
+#define OFS_RETURN    1
+#define OFS_PARM0     (OFS_RETURN+3)
+#define OFS_PARM1     (OFS_PARM0 +3)
+#define OFS_PARM2     (OFS_PARM1 +3)
+#define OFS_PARM3     (OFS_PARM2 +3)
+#define OFS_PARM4     (OFS_PARM3 +3)
 #define OFS_PARM5     (OFS_PARM4 +3)
 #define OFS_PARM6     (OFS_PARM5 +3)
 #define OFS_PARM7     (OFS_PARM6 +3)
@@ -365,16 +371,17 @@ enum {
  * VECTOR_MAKE(prog_section_field,     code_fields    );
  * VECTOR_MAKE(prog_section_function,  code_functions );
  * VECTOR_MAKE(int,                    code_globals   );
- * VECTOR_MAKE(char,                   code_strings   );
+ * VECTOR_MAKE(char,                   code_chars     );
  */
 int         code_statements_add(prog_section_statement);
-int         code_defs_add     (prog_section_def);
-int         code_fields_add   (prog_section_field);
-int         code_functions_add(prog_section_function);
-int         code_globals_add  (int);
-int         code_strings_add  (char);
+int         code_defs_add      (prog_section_def);
+int         code_fields_add    (prog_section_field);
+int         code_functions_add (prog_section_function);
+int         code_globals_add   (int);
+int         code_chars_add     (char);
+int         code_strings_add   (const char *); /* function wrapping code_chars_add */
 extern long code_statements_elements;
-extern long code_strings_elements;
+extern long code_chars_elements;
 extern long code_globals_elements;
 extern long code_functions_elements;
 extern long code_fields_elements;
@@ -390,7 +397,93 @@ void code_init  ();
 //===================================================================
 //========================= assembler.c =============================
 //===================================================================
+static const struct {
+    const char  *m; /* menomic     */
+    const size_t o; /* operands    */ 
+    const size_t l; /* menomic len */
+} const asm_instr[] = {
+    [INSTR_DONE]       = { "DONE"      , 1, 4 },
+    [INSTR_MUL_F]      = { "MUL_F"     , 3, 5 },
+    [INSTR_MUL_V]      = { "MUL_V"     , 3, 5 },
+    [INSTR_MUL_FV]     = { "MUL_FV"    , 3, 6 },
+    [INSTR_MUL_VF]     = { "MUL_VF"    , 3, 6 },
+    [INSTR_DIV_F]      = { "DIV"       , 0, 3 },
+    [INSTR_ADD_F]      = { "ADD_F"     , 3, 5 },
+    [INSTR_ADD_V]      = { "ADD_V"     , 3, 5 },
+    [INSTR_SUB_F]      = { "SUB_F"     , 3, 5 },
+    [INSTR_SUB_V]      = { "DUB_V"     , 3, 5 },
+    [INSTR_EQ_F]       = { "EQ_F"      , 0, 4 },
+    [INSTR_EQ_V]       = { "EQ_V"      , 0, 4 },
+    [INSTR_EQ_S]       = { "EQ_S"      , 0, 4 },
+    [INSTR_EQ_E]       = { "EQ_E"      , 0, 4 },
+    [INSTR_EQ_FNC]     = { "ES_FNC"    , 0, 6 },
+    [INSTR_NE_F]       = { "NE_F"      , 0, 4 },
+    [INSTR_NE_V]       = { "NE_V"      , 0, 4 },
+    [INSTR_NE_S]       = { "NE_S"      , 0, 4 },
+    [INSTR_NE_E]       = { "NE_E"      , 0, 4 },
+    [INSTR_NE_FNC]     = { "NE_FNC"    , 0, 6 },
+    [INSTR_LE]         = { "LE"        , 0, 2 },
+    [INSTR_GE]         = { "GE"        , 0, 2 },
+    [INSTR_LT]         = { "LT"        , 0, 2 },
+    [INSTR_GT]         = { "GT"        , 0, 2 },
+    [INSTR_LOAD_F]     = { "FIELD_F"   , 0, 7 },
+    [INSTR_LOAD_V]     = { "FIELD_V"   , 0, 7 },
+    [INSTR_LOAD_S]     = { "FIELD_S"   , 0, 7 },
+    [INSTR_LOAD_ENT]   = { "FIELD_ENT" , 0, 9 },
+    [INSTR_LOAD_FLD]   = { "FIELD_FLD" , 0, 9 },
+    [INSTR_LOAD_FNC]   = { "FIELD_FNC" , 0, 9 },
+    [INSTR_ADDRESS]    = { "ADDRESS"   , 0, 7 },
+    [INSTR_STORE_F]    = { "STORE_F"   , 0, 7 },
+    [INSTR_STORE_V]    = { "STORE_V"   , 0, 7 },
+    [INSTR_STORE_S]    = { "STORE_S"   , 0, 7 },
+    [INSTR_STORE_ENT]  = { "STORE_ENT" , 0, 9 },
+    [INSTR_STORE_FLD]  = { "STORE_FLD" , 0, 9 },
+    [INSTR_STORE_FNC]  = { "STORE_FNC" , 0, 9 },
+    [INSTR_STOREP_F]   = { "STOREP_F"  , 0, 8 },
+    [INSTR_STOREP_V]   = { "STOREP_V"  , 0, 8 },
+    [INSTR_STOREP_S]   = { "STOREP_S"  , 0, 8 },
+    [INSTR_STOREP_ENT] = { "STOREP_ENT", 0, 10},
+    [INSTR_STOREP_FLD] = { "STOREP_FLD", 0, 10},
+    [INSTR_STOREP_FNC] = { "STOREP_FNC", 0, 10},
+    [INSTR_RETURN]     = { "RETURN"    , 0, 6 },
+    [INSTR_NOT_F]      = { "NOT_F"     , 0, 5 },
+    [INSTR_NOT_V]      = { "NOT_V"     , 0, 5 },
+    [INSTR_NOT_S]      = { "NOT_S"     , 0, 5 },
+    [INSTR_NOT_ENT]    = { "NOT_ENT"   , 0, 7 },
+    [INSTR_NOT_FNC]    = { "NOT_FNC"   , 0, 7 },
+    [INSTR_IF]         = { "IF"        , 0, 2 },
+    [INSTR_IFNOT]      = { "IFNOT"     , 0, 5 },
+    [INSTR_CALL0]      = { "CALL0"     , 0, 5 },
+    [INSTR_CALL1]      = { "CALL1"     , 0, 5 },
+    [INSTR_CALL2]      = { "CALL2"     , 0, 5 },
+    [INSTR_CALL3]      = { "CALL3"     , 0, 5 },
+    [INSTR_CALL4]      = { "CALL4"     , 0, 5 },
+    [INSTR_CALL5]      = { "CALL5"     , 0, 5 },
+    [INSTR_CALL6]      = { "CALL6"     , 0, 5 },
+    [INSTR_CALL7]      = { "CALL7"     , 0, 5 },
+    [INSTR_CALL8]      = { "CALL8"     , 0, 5 },
+    [INSTR_STATE]      = { "STATE"     , 0, 5 },
+    [INSTR_GOTO]       = { "GOTO"      , 0, 4 },
+    [INSTR_AND]        = { "AND"       , 0, 3 },
+    [INSTR_OR]         = { "OR"        , 0, 2 },
+    [INSTR_BITAND]     = { "BITAND"    , 0, 6 },
+    [INSTR_BITOR]      = { "BITOR"     , 0, 5 }
+};
+
 void asm_init (const char *, FILE **);
 void asm_close(FILE *);
 void asm_parse(FILE *);
+//======================================================================
+//============================= main.c =================================
+//======================================================================
+enum {
+    COMPILER_QCC,     /* circa  QuakeC */
+    COMPILER_FTEQCC,  /* fteqcc QuakeC */
+    COMPILER_QCCX,    /* qccx   QuakeC */
+    COMPILER_GMQCC    /* this   QuakeC */
+};
+extern int opts_debug;
+extern int opts_memchk;
+extern int opts_darkplaces_stringtablebug;
+extern int opts_omit_nullcode;
 #endif