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 ================================
* It's important that this table never exceed 32 keywords, the ascii
* table starts at 33 (and we don't want conflicts)
*/
-#define TOKEN_DO 0
-#define TOKEN_ELSE 1
-#define TOKEN_IF 2
-#define TOKEN_WHILE 3
-#define TOKEN_BREAK 4
-#define TOKEN_CONTINUE 5
-#define TOKEN_RETURN 6
-#define TOKEN_GOTO 7
-#define TOKEN_FOR 8 // extension
-#define TOKEN_TYPEDEF 9 // extension
+enum {
+ TOKEN_DO ,
+ TOKEN_ELSE ,
+ TOKEN_IF ,
+ TOKEN_WHILE ,
+ TOKEN_BREAK ,
+ TOKEN_CONTINUE ,
+ TOKEN_RETURN ,
+ TOKEN_GOTO ,
+ TOKEN_FOR , // extension
+ TOKEN_TYPEDEF , // extension
-// ensure the token types are out of the
-// bounds of anyothers that may conflict.
-#define TOKEN_FLOAT 110
-#define TOKEN_VECTOR 111
-#define TOKEN_STRING 112
-#define TOKEN_ENTITY 113
-#define TOKEN_VOID 114
+ // ensure the token types are out of the
+ // bounds of anyothers that may conflict.
+ TOKEN_FLOAT = 110,
+ TOKEN_VECTOR ,
+ TOKEN_STRING ,
+ TOKEN_ENTITY ,
+ TOKEN_VOID
+};
/*
* Lexer state constants, these are numbers for where exactly in
* error occurs. These numbers must be > where the ascii-table ends
* and > the last type token which is TOKEN_VOID
*/
-#define LEX_COMMENT 1128
-#define LEX_CHRLIT 1129
-#define LEX_STRLIT 1130
-#define LEX_IDENT 1131
+enum {
+ LEX_COMMENT = 1128,
+ LEX_CHRLIT ,
+ LEX_STRLIT ,
+ LEX_IDENT
+};
int lex_token (struct lex_file *);
void lex_reset (struct lex_file *);
//===================================================================
//=========================== util.c ================================
//===================================================================
-void *util_memory_a(unsigned int, unsigned int, const char *);
-void util_memory_d(void *, unsigned int, const char *);
-void util_meminfo ();
+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);
-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 *);
+uint32_t util_crc32(const char *, int, register const short);
#ifdef NOTRACK
# define mem_a(x) malloc(x)
//===================================================================
//=========================== code.c ================================
//===================================================================
-#define TYPE_VOID 0
-#define TYPE_STRING 1
-#define TYPE_FLOAT 2
-#define TYPE_VECTOR 3
-#define TYPE_ENTITY 4
-#define TYPE_FIELD 5
-#define TYPE_FUNCTION 6
-#define TYPE_POINTER 7
+enum {
+ TYPE_VOID ,
+ TYPE_STRING ,
+ TYPE_FLOAT ,
+ TYPE_VECTOR ,
+ TYPE_ENTITY ,
+ TYPE_FIELD ,
+ TYPE_FUNCTION ,
+ TYPE_POINTER
+};
/*
* Each paramater incerements by 3 since vector types hold
* 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;
//===================================================================
//========================= 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