#include "slang_codegen.h"
#include "slang_compile.h"
#include "slang_label.h"
+#include "slang_mem.h"
#include "slang_simplify.h"
#include "slang_emit.h"
#include "slang_vartable.h"
new_node3(slang_ir_opcode op,
slang_ir_node *c0, slang_ir_node *c1, slang_ir_node *c2)
{
+#if USE_MEMPOOL
+ slang_ir_node *n = (slang_ir_node *) _slang_alloc(sizeof(slang_ir_node));
+#else
slang_ir_node *n = (slang_ir_node *) calloc(1, sizeof(slang_ir_node));
+#endif
if (n) {
n->Opcode = op;
n->Children[0] = c0;
assert(fun->param_count == totalArgs);
/* allocate temporary arrays */
+#if USE_MEMPOOL
+ paramMode = (ParamMode *)
+ _slang_alloc(totalArgs * sizeof(ParamMode));
+ substOld = (slang_variable **)
+ _slang_alloc(totalArgs * sizeof(slang_variable *));
+ substNew = (slang_operation **)
+ _slang_alloc(totalArgs * sizeof(slang_operation *));
+#else
paramMode = (ParamMode *)
_mesa_calloc(totalArgs * sizeof(ParamMode));
substOld = (slang_variable **)
_mesa_calloc(totalArgs * sizeof(slang_variable *));
substNew = (slang_operation **)
_mesa_calloc(totalArgs * sizeof(slang_operation *));
+#endif
#if 0
printf("Inline call to %s (total vars=%d nparams=%d)\n",
}
}
+#if !USE_MEMPOOL
_mesa_free(paramMode);
_mesa_free(substOld);
_mesa_free(substNew);
+#endif
#if 0
printf("Done Inline call to %s (total vars=%d nparams=%d)\n",
/* Replace the function call with the inlined block */
slang_operation_destruct(oper);
*oper = *inlined;
- /* XXX slang_operation_destruct(inlined) ??? */
+#if !USE_MEMPOOL
+ _mesa_free(inlined);
+#endif
#if 0
assert(inlined->locals);
n->Store = n0->Store;
n->Writemask = writemask;
+#if !USE_MEMPOOL
free(n0);
+#endif
}
return n;
if (n) {
n->Store = store;
}
+#if !USE_MEMPOOL
else {
free(store);
}
+#endif
}
return n;
}
n = _slang_gen_select(A, select);
+#if !USE_MEMPOOL
/* xxx wrong */
free(select->children);
free(select);
+#endif
return n;
}
n = _slang_gen_select(A, select);
+#if !USE_MEMPOOL
/* xxx wrong */
free(select->children);
free(select);
+#endif
return n;
}
#include "slang_storage.h"
#include "slang_emit.h"
#include "slang_log.h"
+#include "slang_mem.h"
#include "slang_vartable.h"
#include "slang_simplify.h"
parse_identifier_str(C, &fractional);
parse_identifier_str(C, &exponent);
+#if USE_MEMPOOL
+ whole = (char *) (_slang_alloc((_mesa_strlen(integral) +
+#else
whole = (char *) (slang_alloc_malloc((_mesa_strlen(integral) +
+#endif
_mesa_strlen(fractional) +
_mesa_strlen(exponent) + 3) * sizeof(char)));
if (whole == NULL) {
*number = (float) (_mesa_strtod(whole, (char **) NULL));
+#if USE_MEMPOOL
+ _slang_free(whole);
+#else
slang_alloc_free(whole);
+#endif
return 1;
}
* parse the expression */
var->type.specifier.type = SLANG_SPEC_ARRAY;
var->type.specifier._array = (slang_type_specifier *)
+#if USE_MEMPOOL
+ _slang_alloc(sizeof(slang_type_specifier));
+#else
slang_alloc_malloc(sizeof(slang_type_specifier));
+#endif
if (var->type.specifier._array == NULL) {
slang_info_log_memory(C->L);
return GL_FALSE;
}
/* set-up a new struct */
+#if USE_MEMPOOL
+ *st = (slang_struct *) _slang_alloc(sizeof(slang_struct));
+#else
*st = (slang_struct *) slang_alloc_malloc(sizeof(slang_struct));
+#endif
if (*st == NULL) {
slang_info_log_memory(C->L);
return 0;
}
if (!slang_struct_construct(*st)) {
+#if USE_MEMPOOL
+ _slang_free(*st);
+#else
slang_alloc_free(*st);
+#endif
*st = NULL;
slang_info_log_memory(C->L);
return 0;
slang_struct *s;
O->structs->structs =
+#if USE_MEMPOOL
+ (slang_struct *) _slang_realloc(O->structs->structs,
+#else
(slang_struct *) slang_alloc_realloc(O->structs->structs,
+#endif
O->structs->num_structs *
sizeof(slang_struct),
(O->structs->num_structs +
}
spec->_struct =
+#if USE_MEMPOOL
+ (slang_struct *) _slang_alloc(sizeof(slang_struct));
+#else
(slang_struct *) slang_alloc_malloc(sizeof(slang_struct));
+#endif
if (spec->_struct == NULL) {
slang_info_log_memory(C->L);
return 0;
}
if (!slang_struct_construct(spec->_struct)) {
+#if USE_MEMPOOL
+ _slang_free(spec->_struct);
+#else
slang_alloc_free(spec->_struct);
+#endif
spec->_struct = NULL;
return 0;
}
*total_ops -= n;
*ops = (slang_operation *)
+#if USE_MEMPOOL
+ _slang_realloc(*ops,
+#else
slang_alloc_realloc(*ops,
+#endif
(*total_ops + n) * sizeof(slang_operation),
*total_ops * sizeof(slang_operation));
if (*ops == NULL) {
/* allocate default operation, becomes a no-op if not used */
ops = (slang_operation *)
+#if USE_MEMPOOL
+ _slang_realloc(ops,
+#else
slang_alloc_realloc(ops,
+#endif
num_ops * sizeof(slang_operation),
(num_ops + 1) * sizeof(slang_operation));
if (ops == NULL) {
slang_operation_destruct(oper);
*oper = *ops; /* struct copy */
+#if USE_MEMPOOL
+ _slang_free(ops);
+#else
slang_alloc_free(ops);
+#endif
return 1;
}
/* create function's body operation */
func->body =
+#if USE_MEMPOOL
+ (slang_operation *) _slang_alloc(sizeof(slang_operation));
+#else
(slang_operation *) slang_alloc_malloc(sizeof(slang_operation));
+#endif
if (func->body == NULL) {
slang_info_log_memory(C->L);
return 0;
}
if (!slang_operation_construct(func->body)) {
+#if USE_MEMPOOL
+ _slang_free(func->body);
+#else
slang_alloc_free(func->body);
+#endif
func->body = NULL;
slang_info_log_memory(C->L);
return 0;
/* put the variable into operation's scope */
op_id.locals->variables =
+#if USE_MEMPOOL
+ (slang_variable **) _slang_alloc(sizeof(slang_variable *));
+#else
(slang_variable **) slang_alloc_malloc(sizeof(slang_variable *));
+#endif
if (op_id.locals->variables == NULL) {
slang_operation_destruct(&op_id);
return GL_FALSE;
}
op_assign.type = SLANG_OPER_ASSIGN;
op_assign.children =
+#if USE_MEMPOOL
+ (slang_operation *) _slang_alloc(2 * sizeof(slang_operation));
+#else
(slang_operation *) slang_alloc_malloc(2 * sizeof(slang_operation));
+#endif
if (op_assign.children == NULL) {
slang_operation_destruct(&op_assign);
op_id.locals->num_variables = 0;
/* carefully destroy the operations */
op_assign.num_children = 0;
+#if USE_MEMPOOL
+ _slang_free(op_assign.children);
+#else
slang_alloc_free(op_assign.children);
+#endif
op_assign.children = NULL;
slang_operation_destruct(&op_assign);
op_id.locals->num_variables = 0;
if (!slang_type_specifier_copy(&var->type.specifier, &type->specifier))
return 0;
var->initializer =
+#if USE_MEMPOOL
+ (slang_operation *) _slang_alloc(sizeof(slang_operation));
+#else
(slang_operation *) slang_alloc_malloc(sizeof(slang_operation));
+#endif
if (var->initializer == NULL) {
slang_info_log_memory(C->L);
return 0;
}
if (!slang_operation_construct(var->initializer)) {
+#if USE_MEMPOOL
+ _slang_free(var->initializer);
+#else
slang_alloc_free(var->initializer);
+#endif
var->initializer = NULL;
slang_info_log_memory(C->L);
return 0;
if (found_func == NULL) {
/* New function, add it to the function list */
O->funs->functions =
+#if USE_MEMPOOL
+ (slang_function *) _slang_realloc(O->funs->functions,
+#else
(slang_function *) slang_alloc_realloc(O->funs->functions,
+#endif
O->funs->num_functions *
sizeof(slang_function),
(O->funs->num_functions +
C->I++;
_slang_pop_var_table(o.vartable);
+ _slang_delete_var_table(o.vartable);
+
return GL_TRUE;
}
type = SLANG_UNIT_FRAGMENT_SHADER;
}
+ ctx->Shader.MemPool = _slang_new_mempool(1024*1024);
+
/* XXX temporary hack */
if (!shader->Programs) {
GLenum progTarget;
slang_info_log_destruct(&info_log);
_slang_code_object_dtr(&obj);
+ _slang_delete_mempool((slang_mempool *) ctx->Shader.MemPool);
+ ctx->Shader.MemPool = NULL;
+
return success;
}
#include "imports.h"
#include "slang_compile.h"
+#include "slang_mem.h"
/* slang_fixup_table */
void
slang_fixup_table_free(slang_fixup_table * fix)
{
+#if USE_MEMPOOL
+ _slang_free(fix->table);
+#else
slang_alloc_free(fix->table);
+#endif
slang_fixup_table_init(fix);
}
slang_fixup_save(slang_fixup_table *fixups, GLuint address)
{
fixups->table = (GLuint *)
+#if USE_MEMPOOL
+ _slang_realloc(fixups->table,
+#else
slang_alloc_realloc(fixups->table,
+#endif
fixups->count * sizeof(GLuint),
(fixups->count + 1) * sizeof(GLuint));
if (fixups->table == NULL)
return 0;
func->parameters = (slang_variable_scope *)
+#if USE_MEMPOOL
+ _slang_alloc(sizeof(slang_variable_scope));
+#else
slang_alloc_malloc(sizeof(slang_variable_scope));
+#endif
if (func->parameters == NULL) {
slang_variable_destruct(&func->header);
return 0;
{
slang_variable_destruct(&func->header);
slang_variable_scope_destruct(func->parameters);
+#if USE_MEMPOOL
+ _slang_free(func->parameters);
+#else
slang_alloc_free(func->parameters);
+#endif
if (func->body != NULL) {
slang_operation_destruct(func->body);
+#if USE_MEMPOOL
+ _slang_free(func->body);
+#else
slang_alloc_free(func->body);
+#endif
}
slang_fixup_table_free(&func->fixups);
}
for (i = 0; i < scope->num_functions; i++)
slang_function_destruct(scope->functions + i);
+#if USE_MEMPOOL
+ _slang_free(scope->functions);
+#else
slang_alloc_free(scope->functions);
+#endif
}
#include "imports.h"
#include "slang_compile.h"
+#include "slang_mem.h"
/**
for (i = 0; i < oper->num_children; i++)
slang_operation_destruct(oper->children + i);
+#if !USE_MEMPOOL
slang_alloc_free(oper->children);
slang_variable_scope_destruct(oper->locals);
slang_alloc_free(oper->locals);
+#endif
oper->children = NULL;
oper->num_children = 0;
oper->locals = NULL;
return GL_FALSE;
z.type = y->type;
z.children = (slang_operation *)
+#if USE_MEMPOOL
+ _slang_alloc(y->num_children * sizeof(slang_operation));
+#else
slang_alloc_malloc(y->num_children * sizeof(slang_operation));
+#endif
if (z.children == NULL) {
slang_operation_destruct(&z);
return GL_FALSE;
slang_operation_new(GLuint count)
{
slang_operation *ops
+#if USE_MEMPOOL
+ = (slang_operation *) _slang_alloc(count * sizeof(slang_operation));
+#else
= (slang_operation *) _mesa_malloc(count * sizeof(slang_operation));
+#endif
assert(count > 0);
if (ops) {
GLuint i;
slang_operation_delete(slang_operation *oper)
{
slang_operation_destruct(oper);
+#if !USE_MEMPOOL
_mesa_free(oper);
+#endif
}
slang_operation *ops;
ops = (slang_operation *)
+#if USE_MEMPOOL
+ _slang_realloc(*children,
+#else
slang_alloc_realloc(*children,
+#endif
*numChildren * sizeof(slang_operation),
(*numChildren + 1) * sizeof(slang_operation));
if (ops) {
slang_operation *newOp = ops + *numChildren;
if (!slang_operation_construct(newOp)) {
+#if !USE_MEMPOOL
_mesa_free(ops);
+#endif
*children = NULL;
return NULL;
}
assert(pos <= *numElements);
ops = (slang_operation *)
+#if USE_MEMPOOL
+ _slang_alloc((*numElements + 1) * sizeof(slang_operation));
+#else
_mesa_malloc((*numElements + 1) * sizeof(slang_operation));
+#endif
if (ops) {
slang_operation *newOp;
newOp = ops + pos;
(*numElements - pos) * sizeof(slang_operation));
if (!slang_operation_construct(newOp)) {
+#if !USE_MEMPOOL
_mesa_free(ops);
+#endif
*numElements = 0;
*array = NULL;
return NULL;
}
+#if !USE_MEMPOOL
if (*array)
_mesa_free(*array);
+#endif
*array = ops;
(*numElements)++;
return newOp;
*/
#include "imports.h"
+#include "slang_mem.h"
#include "slang_compile.h"
for (i = 0; i < scope->num_structs; i++)
slang_struct_destruct(scope->structs + i);
+#if USE_MEMPOOL
+ _slang_free(scope->structs);
+#else
slang_alloc_free(scope->structs);
+#endif
/* do not free scope->outer_scope */
}
_slang_struct_scope_ctr(&z);
z.structs =
+#if USE_MEMPOOL
+ (slang_struct *) _slang_alloc(y->num_structs *
+#else
(slang_struct *) slang_alloc_malloc(y->num_structs *
+#endif
sizeof(slang_struct));
if (z.structs == NULL) {
slang_struct_scope_destruct(&z);
{
stru->a_name = SLANG_ATOM_NULL;
stru->fields = (slang_variable_scope *)
+#if USE_MEMPOOL
+ _slang_alloc(sizeof(slang_variable_scope));
+#else
slang_alloc_malloc(sizeof(slang_variable_scope));
+#endif
if (stru->fields == NULL)
return 0;
_slang_variable_scope_ctr(stru->fields);
stru->structs =
+#if USE_MEMPOOL
+ (slang_struct_scope *) _slang_alloc(sizeof(slang_struct_scope));
+#else
(slang_struct_scope *) slang_alloc_malloc(sizeof(slang_struct_scope));
+#endif
if (stru->structs == NULL) {
slang_variable_scope_destruct(stru->fields);
+#if USE_MEMPOOL
+ _slang_free(stru->fields);
+#else
slang_alloc_free(stru->fields);
+#endif
return 0;
}
_slang_struct_scope_ctr(stru->structs);
slang_struct_destruct(slang_struct * stru)
{
slang_variable_scope_destruct(stru->fields);
+#if USE_MEMPOOL
+ _slang_free(stru->fields);
+#else
slang_alloc_free(stru->fields);
+#endif
slang_struct_scope_destruct(stru->structs);
+#if USE_MEMPOOL
+ _slang_free(stru->structs);
+#else
slang_alloc_free(stru->structs);
+#endif
}
int
#include "imports.h"
#include "slang_compile.h"
+#include "slang_mem.h"
-/* slang_type_specifier_type */
typedef struct
{
static slang_variable *
slang_variable_new(void)
{
+#if USE_MEMPOOL
+ slang_variable *v = (slang_variable *) _slang_alloc(sizeof(slang_variable));
+#else
slang_variable *v = (slang_variable *) malloc(sizeof(slang_variable));
+#endif
if (v) {
if (!slang_variable_construct(v)) {
+#if !USE_MEMPOOL
free(v);
+#endif
v = NULL;
}
}
slang_variable_delete(slang_variable * var)
{
slang_variable_destruct(var);
+#if !USE_MEMPOOL
free(var);
+#endif
}
_slang_variable_scope_new(slang_variable_scope *parent)
{
slang_variable_scope *s;
+#if USE_MEMPOOL
+ s = (slang_variable_scope *) _slang_alloc(sizeof(slang_variable_scope));
+#else
s = (slang_variable_scope *) _mesa_calloc(sizeof(slang_variable_scope));
+#endif
s->outer_scope = parent;
return s;
}
if (scope->variables[i])
slang_variable_delete(scope->variables[i]);
}
+#if USE_MEMPOOL
+ _slang_free(scope->variables);
+#else
slang_alloc_free(scope->variables);
+#endif
/* do not free scope->outer_scope */
}
_slang_variable_scope_ctr(&z);
z.variables = (slang_variable **)
+#if USE_MEMPOOL
+ _slang_alloc(y->num_variables * sizeof(slang_variable *));
+#else
_mesa_calloc(y->num_variables * sizeof(slang_variable *));
+#endif
if (z.variables == NULL) {
slang_variable_scope_destruct(&z);
return 0;
{
const int n = scope->num_variables;
scope->variables = (slang_variable **)
+#if USE_MEMPOOL
+ _slang_realloc(scope->variables,
+#else
slang_alloc_realloc(scope->variables,
+#endif
n * sizeof(slang_variable *),
(n + 1) * sizeof(slang_variable *));
if (!scope->variables)
slang_fully_specified_type_destruct(&var->type);
if (var->initializer != NULL) {
slang_operation_destruct(var->initializer);
+#if USE_MEMPOOL
+ _slang_free(var->initializer);
+#else
slang_alloc_free(var->initializer);
+#endif
}
#if 0
if (var->aux) {
z.array_len = y->array_len;
if (y->initializer != NULL) {
z.initializer
+#if USE_MEMPOOL
+ = (slang_operation *) _slang_alloc(sizeof(slang_operation));
+#else
= (slang_operation *) slang_alloc_malloc(sizeof(slang_operation));
+#endif
if (z.initializer == NULL) {
slang_variable_destruct(&z);
return 0;
}
if (!slang_operation_construct(z.initializer)) {
+#if !USE_MEMPOOL
slang_alloc_free(z.initializer);
+#endif
slang_variable_destruct(&z);
return 0;
}
#include "prog_print.h"
#include "slang_builtin.h"
#include "slang_emit.h"
+#include "slang_mem.h"
#define PEEPHOLE_OPTIMIZATIONS 1
_slang_new_ir_storage(enum register_file file, GLint index, GLint size)
{
slang_ir_storage *st;
+#if USE_MEMPOOL
+ st = (slang_ir_storage *) _slang_alloc(sizeof(slang_ir_storage));
+#else
st = (slang_ir_storage *) _mesa_calloc(sizeof(slang_ir_storage));
+#endif
if (st) {
st->File = file;
st->Index = index;
if (!_slang_alloc_temp(emitInfo->vt, n->Store)) {
slang_info_log_error(emitInfo->log,
"Ran out of registers, too many temporaries");
+#if USE_MEMPOOL
+ _slang_free(n->Store);
+#else
_mesa_free(n->Store);
+#endif
n->Store = NULL;
return GL_FALSE;
}
if (n->Store) {
n->Store->RefCount--;
if (n->Store->RefCount == 0) {
-#if 0
+#if !USE_MEMPOOL
free(n->Store);
#endif
n->Store = NULL;
for (i = 0; i < 3; i++)
_slang_free_ir(n->Children[i]);
/* Do not free n->List since it's a child elsewhere */
+#if !USE_MEMPOOL
free(n);
+#endif
}
void
_slang_free_ir_tree(slang_ir_node *n)
{
+#if 0
_slang_refcount_storage(n);
_slang_free_ir(n);
+#endif
}
#include "slang_label.h"
+#include "slang_mem.h"
+
slang_label *
_slang_label_new(const char *name)
{
+#if !USE_MEMPOOL
slang_label *l = (slang_label *) _mesa_calloc(sizeof(slang_label));
+#else
+ slang_label *l = (slang_label *) _slang_alloc(sizeof(slang_label));
+#endif
if (l) {
+#if !USE_MEMPOOL
l->Name = _mesa_strdup(name);
+#else
+ l->Name = _slang_strdup(name);
+#endif
l->Location = -1;
}
return l;
_slang_label_new_unique(const char *name)
{
static int id = 1;
+#if !USE_MEMPOOL
slang_label *l = (slang_label *) _mesa_calloc(sizeof(slang_label));
+#else
+ slang_label *l = (slang_label *) _slang_alloc(sizeof(slang_label));
+#endif
if (l) {
+#if !USE_MEMPOOL
l->Name = (char *) _mesa_malloc(_mesa_strlen(name) + 10);
+#else
+ l->Name = (char *) _slang_alloc(_mesa_strlen(name) + 10);
+#endif
if (!l->Name) {
_mesa_free(l);
return NULL;
void
_slang_label_delete(slang_label *l)
{
+#if !USE_MEMPOOL
if (l->Name)
_mesa_free(l->Name);
if (l->References)
_mesa_free(l->References);
_mesa_free(l);
+#endif
}
{
const GLuint oldSize = l->NumReferences * sizeof(GLuint);
assert(l->Location < 0);
+#if !USE_MEMPOOL
l->References = _mesa_realloc(l->References,
oldSize, oldSize + sizeof(GLuint));
+#else
+ l->References = _slang_realloc(l->References,
+ oldSize, oldSize + sizeof(GLuint));
+#endif
if (l->References) {
l->References[l->NumReferences] = inst;
l->NumReferences++;
}
if (l->References) {
+#if !USE_MEMPOOL
_mesa_free(l->References);
+#endif
l->References = NULL;
}
}
slang_info_log_destruct(slang_info_log * log)
{
if (!log->dont_free_text)
+#if 0
slang_alloc_free(log->text);
+#else
+ _mesa_free(log->text);
+#endif
}
static int
if (log->text != NULL) {
GLuint old_len = slang_string_length(log->text);
log->text = (char *)
+#if 0
slang_alloc_realloc(log->text, old_len + 1, old_len + size);
+#else
+ _mesa_realloc(log->text, old_len + 1, old_len + size);
+#endif
}
else {
+#if 0
log->text = (char *) (slang_alloc_malloc(size));
+#else
+ log->text = (char *) (_mesa_malloc(size));
+#endif
if (log->text != NULL)
log->text[0] = '\0';
}
*/
#include "context.h"
+#include "macros.h"
#include "slang_mem.h"
+
#define GRANULARITY 8
#define ROUND_UP(B) ( ((B) + (GRANULARITY - 1)) & ~(GRANULARITY - 1) )
+/** If 1, use conventional malloc/free. Helpful for debugging */
+#define USE_MALLOC_FREE 0
+
+
+struct slang_mempool_
+{
+ GLuint Size, Used, Count, Largest;
+ char *Data;
+ struct slang_mempool_ *Next;
+};
+
+
slang_mempool *
_slang_new_mempool(GLuint initialSize)
{
slang_mempool *pool = (slang_mempool *) _mesa_calloc(sizeof(slang_mempool));
if (pool) {
pool->Data = (char *) _mesa_calloc(initialSize);
+ /*printf("ALLOC MEMPOOL %d at %p\n", initialSize, pool->Data);*/
if (!pool->Data) {
_mesa_free(pool);
return NULL;
GLuint total = 0;
while (pool) {
slang_mempool *next = pool->Next;
+ /*
+ printf("DELETE MEMPOOL %u / %u count=%u largest=%u\n",
+ pool->Used, pool->Size, pool->Count, pool->Largest);
+ */
total += pool->Used;
_mesa_free(pool->Data);
_mesa_free(pool);
pool = next;
}
- printf("TOTAL USED %u\n", total);
+ /*printf("TOTAL ALLOCATED: %u\n", total);*/
+}
+
+
+#ifdef DEBUG
+static void
+check_zero(const char *addr, GLuint n)
+{
+ GLuint i;
+ for (i = 0; i < n; i++) {
+ assert(addr[i]==0);
+ }
+}
+#endif
+
+
+#ifdef DEBUG
+static GLboolean
+is_valid_address(const slang_mempool *pool, void *addr)
+{
+ while (pool) {
+ if ((char *) addr >= pool->Data &&
+ (char *) addr < pool->Data + pool->Used)
+ return GL_TRUE;
+
+ pool = pool->Next;
+ }
+ return GL_FALSE;
}
+#endif
/**
void *
_slang_alloc(GLuint bytes)
{
+#if USE_MALLOC_FREE
+ return _mesa_calloc(bytes);
+#else
slang_mempool *pool;
GET_CURRENT_CONTEXT(ctx);
-
pool = (slang_mempool *) ctx->Shader.MemPool;
+ if (bytes == 0)
+ bytes = 1;
+
while (pool) {
if (pool->Used + bytes <= pool->Size) {
/* found room */
void *addr = (void *) (pool->Data + pool->Used);
+#ifdef DEBUG
+ check_zero((char*) addr, bytes);
+#endif
pool->Used += ROUND_UP(bytes);
+ pool->Largest = MAX2(pool->Largest, bytes);
+ pool->Count++;
/*printf("alloc %u Used %u\n", bytes, pool->Used);*/
return addr;
}
}
else {
/* alloc new pool */
- assert(bytes <= pool->Size); /* XXX or max2() */
- pool->Next = _slang_new_mempool(pool->Size);
+ const GLuint sz = MAX2(bytes, pool->Size);
+ pool->Next = _slang_new_mempool(sz);
if (!pool->Next) {
/* we're _really_ out of memory */
return NULL;
}
else {
+ pool = pool->Next;
+ pool->Largest = bytes;
+ pool->Count++;
pool->Used = ROUND_UP(bytes);
+#ifdef DEBUG
+ check_zero((char*) pool->Data, bytes);
+#endif
return (void *) pool->Data;
}
}
}
return NULL;
+#endif
}
void *
_slang_realloc(void *oldBuffer, GLuint oldSize, GLuint newSize)
{
- const GLuint copySize = (oldSize < newSize) ? oldSize : newSize;
- void *newBuffer = _slang_alloc(newSize);
- if (newBuffer && oldBuffer && copySize > 0)
- _mesa_memcpy(newBuffer, oldBuffer, copySize);
- return newBuffer;
+#if USE_MALLOC_FREE
+ return _mesa_realloc(oldBuffer, oldSize, newSize);
+#else
+ GET_CURRENT_CONTEXT(ctx);
+ slang_mempool *pool = (slang_mempool *) ctx->Shader.MemPool;
+
+ if (newSize < oldSize) {
+ return oldBuffer;
+ }
+ else {
+ const GLuint copySize = (oldSize < newSize) ? oldSize : newSize;
+ void *newBuffer = _slang_alloc(newSize);
+
+ if (oldBuffer)
+ ASSERT(is_valid_address(pool, oldBuffer));
+
+ if (newBuffer && oldBuffer && copySize > 0)
+ _mesa_memcpy(newBuffer, oldBuffer, copySize);
+
+ return newBuffer;
+ }
+#endif
}
return NULL;
}
}
+
+
+/**
+ * Don't actually free memory, but mark it (for debugging).
+ */
+void
+_slang_free(void *addr)
+{
+#if USE_MALLOC_FREE
+ _mesa_free(addr);
+#else
+ if (addr) {
+ GET_CURRENT_CONTEXT(ctx);
+ slang_mempool *pool = (slang_mempool *) ctx->Shader.MemPool;
+ ASSERT(is_valid_address(pool, addr));
+ }
+#endif
+}
#include "imports.h"
-typedef struct slang_mempool_
-{
- GLuint Size, Used;
- char *Data;
- struct slang_mempool_ *Next;
-} slang_mempool;
+typedef struct slang_mempool_ slang_mempool;
extern slang_mempool *
extern char *
_slang_strdup(const char *s);
+extern void
+_slang_free(void *addr);
+
#define USE_MEMPOOL 1 /* XXX temporary */
#include "imports.h"
#include "slang_storage.h"
+#include "slang_mem.h"
/* slang_storage_array */
{
if (arr->aggregate != NULL) {
slang_storage_aggregate_destruct(arr->aggregate);
+#if USE_MEMPOOL
+ _slang_free(arr->aggregate);
+#else
slang_alloc_free(arr->aggregate);
+#endif
}
}
for (i = 0; i < agg->count; i++)
slang_storage_array_destruct(agg->arrays + i);
+#if USE_MEMPOOL
+ _slang_free(agg->arrays);
+#else
slang_alloc_free(agg->arrays);
+#endif
}
static slang_storage_array *
slang_storage_array *arr = NULL;
agg->arrays = (slang_storage_array *)
+#if USE_MEMPOOL
+ _slang_realloc(agg->arrays,
+#else
slang_alloc_realloc(agg->arrays,
+#endif
agg->count * sizeof(slang_storage_array),
(agg->count + 1) * sizeof(slang_storage_array));
if (agg->arrays != NULL) {
arr->length = columns;
arr->aggregate =
(slang_storage_aggregate *)
+#if USE_MEMPOOL
+ _slang_alloc(sizeof(slang_storage_aggregate));
+#else
slang_alloc_malloc(sizeof(slang_storage_aggregate));
+#endif
if (arr->aggregate == NULL)
return GL_FALSE;
if (!slang_storage_aggregate_construct(arr->aggregate)) {
+#if USE_MEMPOOL
+ _slang_free(arr->aggregate);
+#else
slang_alloc_free(arr->aggregate);
+#endif
arr->aggregate = NULL;
return GL_FALSE;
}
arr->type = SLANG_STORE_AGGREGATE;
arr->aggregate =
(slang_storage_aggregate *)
+#if USE_MEMPOOL
+ _slang_alloc(sizeof(slang_storage_aggregate));
+#else
slang_alloc_malloc(sizeof(slang_storage_aggregate));
+#endif
if (arr->aggregate == NULL)
return GL_FALSE;
if (!slang_storage_aggregate_construct(arr->aggregate)) {
+#if USE_MEMPOOL
+ _slang_free(arr->aggregate);
+#else
slang_alloc_free(arr->aggregate);
+#endif
arr->aggregate = NULL;
return GL_FALSE;
}
#include "slang_typeinfo.h"
#include "slang_compile.h"
#include "slang_log.h"
+#include "slang_mem.h"
#include "prog_instruction.h"
{
if (self->_struct != NULL) {
slang_struct_destruct(self->_struct);
+#if USE_MEMPOOL
+ _slang_free(self->_struct);
+#else
slang_alloc_free(self->_struct);
+#endif
}
if (self->_array != NULL) {
slang_type_specifier_dtr(self->_array);
+#if USE_MEMPOOL
+ _slang_free(self->_array);
+#else
slang_alloc_free(self->_array);
+#endif
}
}
slang_type_specifier_ctr(&z);
z.type = y->type;
if (z.type == SLANG_SPEC_STRUCT) {
+#if USE_MEMPOOL
+ z._struct = (slang_struct *) _slang_alloc(sizeof(slang_struct));
+#else
z._struct = (slang_struct *) slang_alloc_malloc(sizeof(slang_struct));
+#endif
if (z._struct == NULL) {
slang_type_specifier_dtr(&z);
return GL_FALSE;
}
if (!slang_struct_construct(z._struct)) {
+#if USE_MEMPOOL
+ _slang_free(z._struct);
+#else
slang_alloc_free(z._struct);
+#endif
slang_type_specifier_dtr(&z);
return GL_FALSE;
}
else if (z.type == SLANG_SPEC_ARRAY) {
z._array =
(slang_type_specifier *)
+#if USE_MEMPOOL
+ _slang_alloc(sizeof(slang_type_specifier));
+#else
slang_alloc_malloc(sizeof(slang_type_specifier));
+#endif
if (z._array == NULL) {
slang_type_specifier_dtr(&z);
return GL_FALSE;
/* struct initializer */
ti->spec.type = SLANG_SPEC_STRUCT;
ti->spec._struct =
+#if USE_MEMPOOL
+ (slang_struct *) _slang_alloc(sizeof(slang_struct));
+#else
(slang_struct *) slang_alloc_malloc(sizeof(slang_struct));
+#endif
if (ti->spec._struct == NULL)
return GL_FALSE;
if (!slang_struct_construct(ti->spec._struct)) {
+#if USE_MEMPOOL
+ _slang_free(ti->spec._struct);
+#else
slang_alloc_free(ti->spec._struct);
+#endif
ti->spec._struct = NULL;
return GL_FALSE;
}
/*
* Mesa 3-D graphics library
- * Version: 6.6
+ * Version: 6.5.3
*
- * Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
+ * Copyright (C) 2005-2007 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
#include "imports.h"
#include "slang_utility.h"
+#include "slang_mem.h"
char *
slang_string_concat (char *dst, const char *src)
slang_atom_entry *next;
next = entry->next;
+#if USE_MEMPOOL
+ _slang_free(entry->id);
+ _slang_free(entry);
+#else
slang_alloc_free(entry->id);
slang_alloc_free(entry);
+#endif
entry = next;
}
}
/*
* Search the atom pool for an atom with a given name.
* If atom is not found, create and add it to the pool.
- * Returns ATOM_NULL if the atom was not found and the function failed to create a new atom.
+ * Returns ATOM_NULL if the atom was not found and the function failed
+ * to create a new atom.
*/
slang_atom
slang_atom_pool_atom(slang_atom_pool * pool, const char * id)
}
hash %= SLANG_ATOM_POOL_SIZE;
- /* Now the hash points to a linked list of atoms with names that have the same hash value.
- * Search the linked list for a given name. */
+ /* Now the hash points to a linked list of atoms with names that
+ * have the same hash value. Search the linked list for a given
+ * name.
+ */
entry = &pool->entries[hash];
while (*entry != NULL) {
/* If the same, return the associated atom. */
}
/* Okay, we have not found an atom. Create a new entry for it.
- * Note that the <entry> points to the last entry's <next> field. */
+ * Note that the <entry> points to the last entry's <next> field.
+ */
+#if USE_MEMPOOL
+ *entry = (slang_atom_entry *) (_slang_alloc(sizeof(slang_atom_entry)));
+#else
*entry = (slang_atom_entry *) (slang_alloc_malloc(sizeof(slang_atom_entry)));
+#endif
if (*entry == NULL)
return SLANG_ATOM_NULL;
- /* Initialize a new entry. Because we'll need the actual name of the atom, we use the pointer
- * to this string as an actual atom's value. */
+ /* Initialize a new entry. Because we'll need the actual name of
+ * the atom, we use the pointer to this string as an actual atom's
+ * value.
+ */
(**entry).next = NULL;
+#if USE_MEMPOOL
+ (**entry).id = _slang_strdup(id);
+#else
(**entry).id = slang_string_duplicate(id);
+#endif
if ((**entry).id == NULL)
return SLANG_ATOM_NULL;
return (slang_atom) (**entry).id;
/*
* Mesa 3-D graphics library
- * Version: 6.6
+ * Version: 6.5.3
*
- * Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
+ * Copyright (C) 2005-2007 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#if !defined SLANG_UTILITY_H
+#ifndef SLANG_UTILITY_H
#define SLANG_UTILITY_H
+#include "slang_mem.h"
+
/* Compile-time assertions. If the expression is zero, try to declare an
* array of size [-1] to cause compilation error.
*/
#define static_assert(expr) do { int _array[(expr) ? 1 : -1]; (void) _array[0]; } while (0)
+#if !USE_MEMPOOL
#define slang_alloc_free(ptr) _mesa_free (ptr)
#define slang_alloc_malloc(size) _mesa_malloc (size)
#define slang_alloc_realloc(ptr, old_size, size) _mesa_realloc (ptr, old_size, size)
+#endif
#define slang_string_compare(str1, str2) _mesa_strcmp (str1, str2)
#define slang_string_copy(dst, src) _mesa_strcpy (dst, src)
+#if !USE_MEMPOOL
#define slang_string_duplicate(src) _mesa_strdup (src)
+#endif
#define slang_string_length(str) _mesa_strlen (str)
char *slang_string_concat (char *, const char *);
#include "imports.h"
#include "slang_compile.h"
#include "slang_compile_variable.h"
+#include "slang_mem.h"
#include "slang_vartable.h"
#include "slang_ir.h"
#include "prog_instruction.h"
_slang_new_var_table(GLuint maxRegisters)
{
slang_var_table *vt
+#if USE_MEMPOOL
+ = (slang_var_table *) _slang_alloc(sizeof(slang_var_table));
+#else
= (slang_var_table *) _mesa_calloc(sizeof(slang_var_table));
+#endif
if (vt) {
vt->MaxRegisters = maxRegisters;
}
_mesa_problem(NULL, "non-empty var table in _slang_delete_var_table()");
return;
}
+#if !USE_MEMPOOL
_mesa_free(vt);
+#endif
}
void
_slang_push_var_table(slang_var_table *vt)
{
+#if USE_MEMPOOL
+ struct table *t = (struct table *) _slang_alloc(sizeof(struct table));
+#else
struct table *t = (struct table *) _mesa_calloc(sizeof(struct table));
+#endif
if (t) {
t->Level = vt->CurLevel++;
t->Parent = vt->Top;
}
if (t->Vars)
+#if USE_MEMPOOL
+ t->Vars = NULL;
+#else
free(t->Vars);
+#endif
vt->Top = t->Parent;
+#if !USE_MEMPOOL
free(t);
+#endif
vt->CurLevel--;
}
t = vt->Top;
assert(t);
if (dbg) printf("Adding var %s\n", (char *) v->a_name);
+#if USE_MEMPOOL
+ t->Vars =
+ (slang_variable **) _slang_realloc(t->Vars,
+ t->NumVars * sizeof(slang_variable *),
+ (t->NumVars + 1) * sizeof(slang_variable *));
+#else
t->Vars = realloc(t->Vars, (t->NumVars + 1) * sizeof(slang_variable *));
+#endif
t->Vars[t->NumVars] = v;
t->NumVars++;
}