/* 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;
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;
return h;
}
-hash_types_func_tp hash_types_func = hash_name;
-
-
/* The function that hashes a type. */
type *mature_type(type *tp) {
type *o;
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);
}
/**
- *
* @file type.h
*
* Project: libFIRM <br>
* @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.
*
*/
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.
*
*/
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.
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_ */