removed globals and add them to the initialization function
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Tue, 20 Jul 2004 09:13:59 +0000 (09:13 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Tue, 20 Jul 2004 09:13:59 +0000 (09:13 +0000)
[r3510]

ir/tr/type_identify.c
ir/tr/type_identify.h

index cbf76d7..96eb358 100644 (file)
@@ -40,6 +40,9 @@
 /* The hash set for types. */
 static pset *type_table = NULL;
 
+/* hash and compare types */
+static hash_types_func_t    *hash_types_func;
+static compare_types_func_t *compare_types_func;
 
 int compare_names (const void *tp1, const void *tp2) {
   type *t1 = (type *) tp1;
@@ -57,8 +60,6 @@ int compare_strict (const void *tp1, const void *tp2) {
   return t1 != t2;
 }
 
-compare_types_func_tp compare_types_func = compare_strict;
-
 /* stuff to compute a hash value for a type. */
 int hash_name (type *tp) {
   unsigned h = (unsigned)tp->type_op;
@@ -66,9 +67,6 @@ int hash_name (type *tp) {
   return h;
 }
 
-hash_types_func_tp hash_types_func = hash_name;
-
-
 /* The function that hashes a type. */
 type *mature_type(type *tp) {
   type *o;
@@ -117,6 +115,10 @@ type *mature_type_free_entities(type *tp) {
   return o;
 }
 
-void init_type_identify(void) {
+/* initialize this module */
+void init_type_identify(compare_types_func_t *cmp, hash_types_func_t *hash) {
+  compare_types_func = cmp  ? cmp  : compare_strict;
+  hash_types_func    = hash ? hash : hash_name;
+
   type_table = new_pset (compare_types_func, 8);
 }
index 90333d7..c4a4be3 100644 (file)
@@ -1,5 +1,4 @@
 /**
- *
  * @file type.h
  *
  * Project:     libFIRM                                                   <br>
@@ -30,7 +29,7 @@ typedef struct type type;
  *   @param tp1  The first type to compare.
  *   @param tp2  The second type to compare.
  */
-typedef int (*compare_types_func_tp) (const void *tp1, const void *tp2);
+typedef int (compare_types_func_t)(const void *tp1, const void *tp2);
 
 /** Compares two types by their name.
  *
@@ -45,24 +44,13 @@ int compare_names (const void *tp1, const void *tp2);
  */
 int compare_strict (const void *tp1, const void *tp2);
 
-/** A variable that holds a compare function for types.
- *
- *  The compare function is used to identify equal types.  The
- *  variable is initialized with the function compare_strict().
- *
- *  The variable must be set before calling init_firm()! Later changes
- *  have no effect.
- */
-extern compare_types_func_tp compare_types_func;
-
-
 /* ------------------------------------------------------------------------ */
 
 /**  Type for a function that computes a hash value for a type.
  *
  *   @param tp The type to compute a hash for.
  */
-typedef int (*hash_types_func_tp)(type *tp);
+typedef int (hash_types_func_t)(type *tp);
 
 /** Computes a hash value by the type name.
  *
@@ -70,17 +58,6 @@ typedef int (*hash_types_func_tp)(type *tp);
  */
 int hash_name (type *tp);
 
-/** A variable that holds a hash function for a type.
- *
- *  The hash function is used to identify equal types.  The
- *  variable is initialized with the function hash_name().
- *
- *  The variable must be set before calling init_firm()! Later changes
- *  have no effect.
- */
-extern hash_types_func_tp hash_types_func;
-
-
 /* ------------------------------------------------------------------------ */
 
 /** Finalize type construction.
@@ -135,8 +112,13 @@ type *       mature_type_free(type *tp);
 type *       mature_type_free_entities(type *tp);
 
 /**
- * initialise the type identifier module.
+ * Initialise the type identifier module.
+ *
+ * @param cmp   The function that should be used to compare two types.
+ *              If NULL, compare_strict() will be used.
+ * @param hash  The function that should be used to calculate a hash
+ *              value of a type. If NULL, hash_name() will be used.
  */
-void init_type_identify(void);
+void init_type_identify(compare_types_func_t *cmp, hash_types_func_t *hash);
 
 # endif /* _TYPE_IDENTIFY_H_ */