2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
11 #include <isl_ctx_private.h>
12 #include <isl_id_private.h>
14 isl_ctx *isl_id_get_ctx(__isl_keep isl_id *id)
16 return id ? id->ctx : NULL;
19 void *isl_id_get_user(__isl_keep isl_id *id)
21 return id ? id->user : NULL;
24 const char *isl_id_get_name(__isl_keep isl_id *id)
26 return id ? id->name : NULL;
29 static __isl_give isl_id *id_alloc(isl_ctx *ctx, const char *name, void *user)
31 const char *copy = name ? strdup(name) : NULL;
36 id = isl_alloc_type(ctx, struct isl_id);
46 id->hash = isl_hash_init();
48 id->hash = isl_hash_string(id->hash, name);
50 id->hash = isl_hash_builtin(id->hash, user);
58 static int isl_id_has_name(const void *entry, const void *val)
60 isl_id *id = (isl_id *)entry;
61 const char *s = (const char *)val;
63 return !strcmp(id->name, s);
66 __isl_give isl_id *isl_id_alloc(isl_ctx *ctx, const char *name, void *user)
68 struct isl_hash_table_entry *entry;
71 id_hash = isl_hash_init();
73 id_hash = isl_hash_string(id_hash, name);
75 id_hash = isl_hash_builtin(id_hash, user);
76 entry = isl_hash_table_find(ctx, &ctx->id_table, id_hash,
77 isl_id_has_name, name, 1);
81 return isl_id_copy(entry->data);
82 entry->data = id_alloc(ctx, name, user);
88 __isl_give isl_id *isl_id_copy(isl_id *id)
97 static int isl_id_eq(const void *entry, const void *name)
102 uint32_t isl_hash_id(uint32_t hash, __isl_keep isl_id *id)
105 isl_hash_hash(hash, id->hash);
110 void *isl_id_free(__isl_take isl_id *id)
112 struct isl_hash_table_entry *entry;
120 entry = isl_hash_table_find(id->ctx, &id->ctx->id_table, id->hash,
123 isl_die(id->ctx, isl_error_unknown,
124 "unable to find id", (void)0);
126 isl_hash_table_remove(id->ctx, &id->ctx->id_table, entry);
128 free((char *)id->name);
129 isl_ctx_deref(id->ctx);
135 __isl_give isl_printer *isl_printer_print_id(__isl_take isl_printer *p,
136 __isl_keep isl_id *id)
142 p = isl_printer_print_str(p, id->name);
145 snprintf(buffer, sizeof(buffer), "@%p", id->user);
146 p = isl_printer_print_str(p, buffer);
154 void isl_id_dump(__isl_keep isl_id *id)
156 isl_printer *printer;
161 printer = isl_printer_to_file(isl_id_get_ctx(id), stderr);
162 printer = isl_printer_print_id(printer, id);
163 printer = isl_printer_end_line(printer);
165 isl_printer_free(printer);