示例#1
0
void *drc_cache::alloc_near(size_t bytes)
{
	assert(bytes > 0);

	// pick first from the free list
	if (bytes < MAX_PERMANENT_ALLOC)
	{
		free_link **linkptr = &m_nearfree[(bytes + CACHE_ALIGNMENT - 1) / CACHE_ALIGNMENT];
		free_link *link = *linkptr;
		if (link != NULL)
		{
			*linkptr = link->m_next;
			return link;
		}
	}

	// if no space, we just fail
	drccodeptr ptr = (drccodeptr)ALIGN_PTR_UP(m_neartop);
	if (ptr + bytes > m_base)
		return NULL;

	// otherwise update the top of the near part of the cache
	m_neartop = ptr + bytes;
	return ptr;
}
示例#2
0
drccodeptr drccache_end_codegen(drccache *cache)
{
	drccodeptr result = cache->codegen;

	/* run the OOB handlers */
	while (cache->ooblist != NULL)
	{
		/* remove us from the list */
		oob_handler *oob = cache->ooblist;
		cache->ooblist = oob->next;

		/* call the callback */
		(*oob->callback)(&cache->top, oob->param1, oob->param2, oob->param3);
		assert(cache->top - cache->codegen < CODEGEN_MAX_BYTES);

		/* release our memory */
		drccache_memory_free(cache, oob, sizeof(*oob));
	}

	/* update the cache top */
	cache->top = (drccodeptr)ALIGN_PTR_UP(cache->top);
	cache->codegen = NULL;

	return result;
}
示例#3
0
void *drccache_memory_alloc_near(drccache *cache, size_t bytes)
{
	drccodeptr ptr;

	assert(bytes > 0);

	/* pick first from the free list */
	if (bytes < MAX_PERMANENT_ALLOC)
	{
		free_link **linkptr = &cache->nearfree[(bytes + CACHE_ALIGNMENT - 1) / CACHE_ALIGNMENT];
		free_link *link = *linkptr;
		if (link != NULL)
		{
			*linkptr = link->next;
			return link;
		}
	}

	/* if no space, we just fail */
	ptr = (drccodeptr)ALIGN_PTR_UP(cache->neartop);
	if (ptr + bytes > cache->base)
		return NULL;

	/* otherwise update the top of the near part of the cache */
	cache->neartop = ptr + bytes;
	return ptr;
}
示例#4
0
void *drc_cache::alloc_temporary(size_t bytes)
{
	// can't allocate in the middle of codegen
	assert(m_codegen == NULL);

	// if no space, we just fail
	drccodeptr ptr = m_top;
	if (ptr + bytes >= m_end)
		return NULL;

	// otherwise, update the cache top
	m_top = (drccodeptr)ALIGN_PTR_UP(ptr + bytes);
	return ptr;
}
示例#5
0
void *drccache_memory_alloc_temporary(drccache *cache, size_t bytes)
{
	drccodeptr ptr = cache->top;

	/* can't allocate in the middle of codegen */
	assert(cache->codegen == NULL);

	/* if no space, we just fail */
	if (ptr + bytes >= cache->end)
		return NULL;

	/* otherwise, update the cache top */
	cache->top = (drccodeptr)ALIGN_PTR_UP(ptr + bytes);
	return ptr;
}
示例#6
0
drccodeptr drc_cache::end_codegen()
{
	drccodeptr result = m_codegen;

	// run the OOB handlers
	oob_handler *oob;
	while ((oob = m_ooblist.detach_head()) != NULL)
	{
		// call the callback
		oob->m_callback(&m_top, oob->m_param1, oob->m_param2);
		assert(m_top - m_codegen < CODEGEN_MAX_BYTES);

		// release our memory
		dealloc(oob, sizeof(*oob));
	}

	// update the cache top
	m_top = (drccodeptr)ALIGN_PTR_UP(m_top);
	m_codegen = NULL;

	return result;
}