diff --git a/tools/qfcc/include/class.h b/tools/qfcc/include/class.h index dc1572575..c1bea2f6d 100644 --- a/tools/qfcc/include/class.h +++ b/tools/qfcc/include/class.h @@ -96,4 +96,6 @@ void add_protocol (protocollist_t *protocollist, protocol_t *protocol); int emit_protocol (protocol_t *protocol); int emit_protocol_list (protocollist_t *protocols, const char *name); +void clear_classes (void); + #endif//__class_h diff --git a/tools/qfcc/include/def.h b/tools/qfcc/include/def.h index 5190b25ce..ac375b1ee 100644 --- a/tools/qfcc/include/def.h +++ b/tools/qfcc/include/def.h @@ -111,5 +111,6 @@ void reset_tempdefs (); void flush_scope (scope_t *scope, int force_used); void def_initialized (def_t *d); +void clear_defs (void); #endif//__def_h diff --git a/tools/qfcc/include/immediate.h b/tools/qfcc/include/immediate.h index b56017baf..3e51b24f7 100644 --- a/tools/qfcc/include/immediate.h +++ b/tools/qfcc/include/immediate.h @@ -38,4 +38,6 @@ struct def_s *ReuseConstant (struct expr_s *expr, struct def_s *def); int CopyString (const char *str); int ReuseString (const char *str); +void clear_immediates (void); + #endif//__immediate_h diff --git a/tools/qfcc/include/method.h b/tools/qfcc/include/method.h index 3161d96fe..443ceb081 100644 --- a/tools/qfcc/include/method.h +++ b/tools/qfcc/include/method.h @@ -82,4 +82,6 @@ struct def_s *selector_def (const char *sel_id, const char *sel_types); int emit_methods (methodlist_t *methods, const char *name, int instance); +void clear_selectors (void); + #endif//__method_h diff --git a/tools/qfcc/include/qfcc.h b/tools/qfcc/include/qfcc.h index 73b000cef..d94a781dc 100644 --- a/tools/qfcc/include/qfcc.h +++ b/tools/qfcc/include/qfcc.h @@ -32,6 +32,7 @@ #ifndef __qfcc_h #define __qfcc_h +#include #include "QF/pr_comp.h" //============================================================================ @@ -93,6 +94,9 @@ extern string_t s_file; // filename for function definition const char *strip_path (const char *filename); const char *save_string (const char *str); +void clear_frame_macros (void); +extern FILE *yyin; +int yyparse (void); #define ALLOC(s, t, n, v) \ do { \ diff --git a/tools/qfcc/include/struct.h b/tools/qfcc/include/struct.h index 4f475c94d..6de7f3d72 100644 --- a/tools/qfcc/include/struct.h +++ b/tools/qfcc/include/struct.h @@ -60,4 +60,7 @@ int emit_struct (struct type_s *strct, const char *name); void process_enum (struct expr_s *enm); expr_t *get_enum (const char *name); +void clear_structs (void); +void clear_enums (void); + #endif//__struct_h diff --git a/tools/qfcc/include/type.h b/tools/qfcc/include/type.h index c8843cee1..65438683f 100644 --- a/tools/qfcc/include/type.h +++ b/tools/qfcc/include/type.h @@ -89,4 +89,6 @@ int type_size (type_t *type); void init_types (void); +void clear_typedefs (void); + #endif//__type_h diff --git a/tools/qfcc/source/class.c b/tools/qfcc/source/class.c index b25ba6411..cf970bc70 100644 --- a/tools/qfcc/source/class.c +++ b/tools/qfcc/source/class.c @@ -618,3 +618,14 @@ emit_protocol_list (protocollist_t *protocols, const char *name) proto_list->list[i] = emit_protocol (protocols->list[i]); return proto_list_def->ofs; } + +void +clear_classes (void) +{ + if (class_hash) + Hash_FlushTable (class_hash); + if (protocol_hash) + Hash_FlushTable (protocol_hash); + if (category_hash) + Hash_FlushTable (category_hash); +} diff --git a/tools/qfcc/source/def.c b/tools/qfcc/source/def.c index f81ded148..7f32ce78e 100644 --- a/tools/qfcc/source/def.c +++ b/tools/qfcc/source/def.c @@ -397,3 +397,10 @@ def_initialized (def_t *d) d->initialized = 1; } } + +void +clear_defs (void) +{ + if (defs_by_name) + Hash_FlushTable (defs_by_name); +} diff --git a/tools/qfcc/source/immediate.c b/tools/qfcc/source/immediate.c index 06f2c974c..3e1888c56 100644 --- a/tools/qfcc/source/immediate.c +++ b/tools/qfcc/source/immediate.c @@ -156,32 +156,7 @@ ReuseConstant (expr_t *expr, def_t *def) if (!rep) rep = dstring_newstr (); if (!string_imm_defs) { - string_imm_defs = Hash_NewTable (16381, string_imm_get_key, 0, 0); - float_imm_defs = Hash_NewTable (16381, float_imm_get_key, 0, 0); - vector_imm_defs = Hash_NewTable (16381, vector_imm_get_key, 0, 0); - entity_imm_defs = Hash_NewTable (16381, int_imm_get_key, 0, "entity"); - field_imm_defs = Hash_NewTable (16381, int_imm_get_key, 0, "field"); - func_imm_defs = Hash_NewTable (16381, int_imm_get_key, 0, "func"); - pointer_imm_defs = Hash_NewTable (16381, int_imm_get_key, 0, "pointer"); - quaternion_imm_defs = - Hash_NewTable (16381, quaternion_imm_get_key, 0, 0); - integer_imm_defs = Hash_NewTable (16381, int_imm_get_key, 0, "integer"); - - Hash_Add (string_imm_defs, cn = new_def (&type_string, ".imm", - pr.scope)); - cn->initialized = cn->constant = 1; - Hash_Add (float_imm_defs, cn = new_def (&type_float, ".imm", - pr.scope)); - cn->initialized = cn->constant = 1; - Hash_Add (entity_imm_defs, cn = new_def (&type_entity, ".imm", - pr.scope)); - cn->initialized = cn->constant = 1; - Hash_Add (pointer_imm_defs, cn = new_def (&type_pointer, ".imm", - pr.scope)); - cn->initialized = cn->constant = 1; - Hash_Add (integer_imm_defs, cn = new_def (&type_integer, ".imm", - pr.scope)); - cn->initialized = cn->constant = 1; + clear_immediates (); } cn = 0; switch (e.type) { @@ -295,3 +270,41 @@ ReuseConstant (expr_t *expr, def_t *def) return cn; } + +void +clear_immediates (void) +{ + def_t *cn; + if (string_imm_defs) { + Hash_FlushTable (string_imm_defs); + Hash_FlushTable (float_imm_defs); + Hash_FlushTable (vector_imm_defs); + Hash_FlushTable (entity_imm_defs); + Hash_FlushTable (field_imm_defs); + Hash_FlushTable (func_imm_defs); + Hash_FlushTable (pointer_imm_defs); + Hash_FlushTable (quaternion_imm_defs); + } else { + string_imm_defs = Hash_NewTable (16381, string_imm_get_key, 0, 0); + float_imm_defs = Hash_NewTable (16381, float_imm_get_key, 0, 0); + vector_imm_defs = Hash_NewTable (16381, vector_imm_get_key, 0, 0); + entity_imm_defs = Hash_NewTable (16381, int_imm_get_key, 0, "entity"); + field_imm_defs = Hash_NewTable (16381, int_imm_get_key, 0, "field"); + func_imm_defs = Hash_NewTable (16381, int_imm_get_key, 0, "func"); + pointer_imm_defs = Hash_NewTable (16381, int_imm_get_key, 0, "pointer"); + quaternion_imm_defs = + Hash_NewTable (16381, quaternion_imm_get_key, 0, 0); + } + integer_imm_defs = Hash_NewTable (16381, int_imm_get_key, 0, "integer"); + + Hash_Add (string_imm_defs, cn = new_def (&type_string, ".imm", pr.scope)); + cn->initialized = cn->constant = 1; + Hash_Add (float_imm_defs, cn = new_def (&type_float, ".imm", pr.scope)); + cn->initialized = cn->constant = 1; + Hash_Add (entity_imm_defs, cn = new_def (&type_entity, ".imm", pr.scope)); + cn->initialized = cn->constant = 1; + Hash_Add (pointer_imm_defs, cn = new_def (&type_pointer, ".imm", pr.scope)); + cn->initialized = cn->constant = 1; + Hash_Add (integer_imm_defs, cn = new_def (&type_integer, ".imm", pr.scope)); + cn->initialized = cn->constant = 1; +} diff --git a/tools/qfcc/source/method.c b/tools/qfcc/source/method.c index 6d2307255..07ec02061 100644 --- a/tools/qfcc/source/method.c +++ b/tools/qfcc/source/method.c @@ -323,3 +323,10 @@ emit_methods (methodlist_t *_methods, const char *name, int instance) } return methods_def->ofs; } + +void +clear_selectors (void) +{ + if (sel_def_hash) + Hash_FlushTable (sel_def_hash); +} diff --git a/tools/qfcc/source/qfcc.c b/tools/qfcc/source/qfcc.c index c737a9135..e6dd0724a 100644 --- a/tools/qfcc/source/qfcc.c +++ b/tools/qfcc/source/qfcc.c @@ -71,10 +71,12 @@ static const char rcsid[] = #include "function.h" #include "idstuff.h" #include "immediate.h" +#include "method.h" #include "obj_file.h" #include "opcodes.h" #include "options.h" #include "reloc.h" +#include "struct.h" #include "type.h" options_t options; @@ -125,6 +127,12 @@ InitData (void) { int i; + if (pr.statements) { + free (pr.statements); + memset (&pr, 0, sizeof (pr)); + } + pr_source_line = 1; + pr_error_count = 0; pr.num_statements = 1; pr.strofs = 1; pr.num_functions = 1; @@ -444,6 +452,37 @@ setup_sym_file (const char *output_file) } } +static int +compile_to_obj (const char *file, const char *obj) +{ + int err; + + yyin = preprocess_file (file); + + InitData (); + begin_compilation (); + s_file = ReuseString (strip_path (file)); + clear_frame_macros (); + clear_classes (); + clear_defs (); + clear_immediates (); + clear_selectors (); + clear_structs (); + clear_enums (); + clear_typedefs (); + err = yyparse () || pr_error_count; + fclose (yyin); + if (cpp_name && (!options.save_temps)) { + if (unlink (tempname->str)) { + perror ("unlink"); + exit (1); + } + } + if (!err) + write_obj_file (obj); + return err; +} + static int separate_compile (void) { @@ -475,6 +514,9 @@ separate_compile (void) if (strncmp (*file, "-l", 2) && (!strcmp (extension->str, ".r") || !strcmp (extension->str, ".qc"))) { + printf ("%s %s\n", *file, output_file->str); + compile_to_obj (*file, output_file->str); + free ((char *)*file); *file = strdup (output_file->str); } else { @@ -522,15 +564,13 @@ progs_src_compile (void) } setup_sym_file (options.output_file); + InitData (); + begin_compilation (); // compile all the files while ((src = Parse (src))) { - int error; - - extern FILE *yyin; - int yyparse (void); - extern void clear_frame_macros (void); + int err; //extern int yydebug; //yydebug = 1; @@ -548,7 +588,7 @@ progs_src_compile (void) s_file = ReuseString (strip_path (filename->str)); pr_source_line = 1; clear_frame_macros (); - error = yyparse () || pr_error_count; + err = yyparse () || pr_error_count; fclose (yyin); if (cpp_name && (!options.save_temps)) { if (unlink (tempname->str)) { @@ -556,7 +596,7 @@ progs_src_compile (void) exit (1); } } - if (error) + if (err) return 1; } @@ -608,8 +648,6 @@ main (int argc, char **argv) opcode_init (); init_types (); - InitData (); - if (source_files) { res = separate_compile (); } else { diff --git a/tools/qfcc/source/struct.c b/tools/qfcc/source/struct.c index e6657f053..03952d834 100644 --- a/tools/qfcc/source/struct.c +++ b/tools/qfcc/source/struct.c @@ -246,6 +246,13 @@ emit_struct(type_t *strct, const char *name) return ivars_def->ofs; } +void +clear_structs (void) +{ + if (structs) + Hash_FlushTable (structs); +} + void process_enum (expr_t *enm) { @@ -302,3 +309,10 @@ get_enum (const char *name) return 0; return &e->value; } + +void +clear_enums (void) +{ + if (enums) + Hash_FlushTable (enums); +} diff --git a/tools/qfcc/source/type.c b/tools/qfcc/source/type.c index d942d051b..ef97100ba 100644 --- a/tools/qfcc/source/type.c +++ b/tools/qfcc/source/type.c @@ -529,3 +529,10 @@ init_types (void) type_obj_exec_class.parm_types[0] = pointer_type (type_module); chain_type (&type_obj_exec_class); } + +void +clear_typedefs (void) +{ + if (typedef_hash) + Hash_FlushTable (typedef_hash); +}