Exemplo n.º 1
0
static __isl_give isl_id *id_alloc(isl_ctx *ctx, const char *name, void *user)
{
	const char *copy = name ? strdup(name) : NULL;
	isl_id *id;

	if (name && !copy)
		return NULL;
	id = isl_alloc_type(ctx, struct isl_id);
	if (!id)
		goto error;

	id->ctx = ctx;
	isl_ctx_ref(id->ctx);
	id->ref = 1;
	id->name = copy;
	id->user = user;

	id->hash = isl_hash_init();
	if (name)
		id->hash = isl_hash_string(id->hash, name);
	else
		id->hash = isl_hash_builtin(id->hash, user);

	return id;
error:
	free((char *)copy);
	return NULL;
}
Exemplo n.º 2
0
__isl_give isl_id *isl_id_alloc(isl_ctx *ctx, const char *name, void *user)
{
	struct isl_hash_table_entry *entry;
	uint32_t id_hash;
	struct isl_name_and_user nu = { name, user };

	if (!ctx)
		return NULL;

	id_hash = isl_hash_init();
	if (name)
		id_hash = isl_hash_string(id_hash, name);
	else
		id_hash = isl_hash_builtin(id_hash, user);
	entry = isl_hash_table_find(ctx, &ctx->id_table, id_hash,
					isl_id_has_name_and_user, &nu, 1);
	if (!entry)
		return NULL;
	if (entry->data)
		return isl_id_copy(entry->data);
	entry->data = id_alloc(ctx, name, user);
	if (!entry->data)
		ctx->id_table.n--;
	return entry->data;
}
Exemplo n.º 3
0
struct isl_name *isl_name_get(struct isl_ctx *ctx, const char *name)
{
	struct isl_hash_table_entry *entry;
	uint32_t name_hash;

	name_hash = isl_hash_string(isl_hash_init(), name);
	entry = isl_hash_table_find(ctx, &ctx->name_hash, name_hash,
					isl_name_has_name, name, 1);
	if (!entry)
		return NULL;
	if (entry->data)
		return isl_name_copy(ctx, entry->data);
	entry->data = isl_name_alloc(ctx, name);
	if (!entry->data)
		ctx->name_hash.n--;
	return entry->data;
}
Exemplo n.º 4
0
void isl_name_free(struct isl_ctx *ctx, struct isl_name *name)
{
	uint32_t name_hash;
	struct isl_hash_table_entry *entry;

	if (!name)
		return;

	if (--name->ref > 0)
		return;

	name_hash = isl_hash_string(isl_hash_init(), name->name);
	entry = isl_hash_table_find(ctx, &ctx->name_hash, name_hash,
					isl_name_eq, name, 0);
	isl_assert(ctx, entry, return);
	isl_hash_table_remove(ctx, &ctx->name_hash, entry);

	free((char *)name->name);
	free(name);
}
Exemplo n.º 5
0
/* Return a hash value that digests "pw".
 */
uint32_t FN(PW,get_hash)(__isl_keep PW *pw)
{
	int i;
	uint32_t hash;

	if (!pw)
		return 0;

	hash = isl_hash_init();
	for (i = 0; i < pw->n; ++i) {
		uint32_t set_hash, el_hash;

		set_hash = isl_set_get_hash(pw->p[i].set);
		isl_hash_hash(hash, set_hash);
		el_hash = FN(EL,get_hash)(pw->p[i].FIELD);
		isl_hash_hash(hash, el_hash);
	}

	return hash;
}
Exemplo n.º 6
0
struct isl_name *isl_name_alloc(struct isl_ctx *ctx, const char *s)
{
	const char *copy = strdup(s);
	struct isl_name *name;

	if (!copy)
		return NULL;
	name = isl_alloc_type(ctx, struct isl_name);
	if (!name)
		goto error;

	name->ref = 1;
	name->name = copy;

	name->hash = isl_hash_init();
	name->hash = isl_hash_string(name->hash, s);

	return name;
error:
	free((char *)copy);
	return NULL;
}
Exemplo n.º 7
0
enum isl_token_type isl_stream_register_keyword(struct isl_stream *s,
	const char *name)
{
	struct isl_hash_table_entry *entry;
	struct isl_keyword *keyword;
	uint32_t name_hash;

	if (!s->keywords) {
		s->keywords = isl_hash_table_alloc(s->ctx, 10);
		if (!s->keywords)
			return ISL_TOKEN_ERROR;
		s->next_type = ISL_TOKEN_LAST;
	}

	name_hash = isl_hash_string(isl_hash_init(), name);

	entry = isl_hash_table_find(s->ctx, s->keywords, name_hash,
					same_name, name, 1);
	if (!entry)
		return ISL_TOKEN_ERROR;
	if (entry->data) {
		keyword = entry->data;
		return keyword->type;
	}

	keyword = isl_calloc_type(s->ctx, struct isl_keyword);
	if (!keyword)
		return ISL_TOKEN_ERROR;
	keyword->type = s->next_type++;
	keyword->name = strdup(name);
	if (!keyword->name) {
		free(keyword);
		return ISL_TOKEN_ERROR;
	}
	entry->data = keyword;

	return keyword->type;
}