int slang_variable_copy(slang_variable * x, const slang_variable * y) { slang_variable z; if (!slang_variable_construct(&z)) return 0; if (!slang_fully_specified_type_copy(&z.type, &y->type)) { slang_variable_destruct(&z); return 0; } z.a_name = y->a_name; z.array_len = y->array_len; if (y->initializer != NULL) { z.initializer = (slang_operation *) _slang_alloc(sizeof(slang_operation)); if (z.initializer == NULL) { slang_variable_destruct(&z); return 0; } if (!slang_operation_construct(z.initializer)) { _slang_free(z.initializer); slang_variable_destruct(&z); return 0; } if (!slang_operation_copy(z.initializer, y->initializer)) { slang_variable_destruct(&z); return 0; } } z.size = y->size; slang_variable_destruct(x); *x = z; return 1; }
int slang_variable_scope_copy(slang_variable_scope * x, const slang_variable_scope * y) { slang_variable_scope z; unsigned int i; _slang_variable_scope_ctr(&z); z.variables = (slang_variable **) _slang_alloc(y->num_variables * sizeof(slang_variable *)); if (z.variables == NULL) { slang_variable_scope_destruct(&z); return 0; } for (z.num_variables = 0; z.num_variables < y->num_variables; z.num_variables++) { z.variables[z.num_variables] = slang_variable_new(); if (!z.variables[z.num_variables]) { slang_variable_scope_destruct(&z); return 0; } } for (i = 0; i < z.num_variables; i++) { if (!slang_variable_copy(z.variables[i], y->variables[i])) { slang_variable_scope_destruct(&z); return 0; } } z.outer_scope = y->outer_scope; slang_variable_scope_destruct(x); *x = z; return 1; }
void * _slang_realloc(void *oldBuffer, GLuint oldSize, GLuint newSize) { #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 }
/** * As above, but suffix the name with a unique number. */ slang_label * _slang_label_new_unique(const char *name) { static int id = 1; slang_label *l = (slang_label *) _slang_alloc(sizeof(slang_label)); if (l) { l->Name = (char *) _slang_alloc(strlen(name) + 10); if (!l->Name) { free(l); return NULL; } sprintf(l->Name, "%s_%d", name, id); id++; l->Location = -1; } return l; }
slang_variable_scope * _slang_variable_scope_new(slang_variable_scope *parent) { slang_variable_scope *s; s = (slang_variable_scope *) _slang_alloc(sizeof(slang_variable_scope)); if (s) s->outer_scope = parent; return s; }
slang_label * _slang_label_new(const char *name) { slang_label *l = (slang_label *) _slang_alloc(sizeof(slang_label)); if (l) { l->Name = _slang_strdup(name); l->Location = -1; } return l; }
static slang_variable * slang_variable_new(void) { slang_variable *v = (slang_variable *) _slang_alloc(sizeof(slang_variable)); if (v) { if (!slang_variable_construct(v)) { _slang_free(v); v = NULL; } } return v; }
/** * Return a new slang_ir_storage object. */ slang_ir_storage * _slang_new_ir_storage(enum register_file file, GLint index, GLint size) { slang_ir_storage *st; st = (slang_ir_storage *) _slang_alloc(sizeof(slang_ir_storage)); if (st) { st->File = file; st->Index = index; st->Size = size; st->Swizzle = SWIZZLE_NOOP; st->Parent = NULL; } return st; }
/** * Clone string, storing in current mempool. */ char * _slang_strdup(const char *s) { if (s) { size_t l = _mesa_strlen(s); char *s2 = (char *) _slang_alloc(l + 1); if (s2) _mesa_strcpy(s2, s); return s2; } else { return NULL; } }
/* * 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. */ slang_atom slang_atom_pool_atom(slang_atom_pool * pool, const char * id) { GLuint hash; const char * p = id; slang_atom_entry ** entry; /* Hash a given string to a number in the range [0, ATOM_POOL_SIZE). */ hash = 0; while (*p != '\0') { GLuint g; hash = (hash << 4) + (GLuint) (*p++); g = hash & 0xf0000000; if (g != 0) hash ^= g >> 24; hash &= ~g; } 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. */ entry = &pool->entries[hash]; while (*entry != NULL) { /* If the same, return the associated atom. */ if (slang_string_compare((**entry).id, id) == 0) return (slang_atom) (**entry).id; /* Grab the next atom in the linked list. */ entry = &(**entry).next; } /* 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. */ *entry = (slang_atom_entry *) _slang_alloc(sizeof(slang_atom_entry)); 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. */ (**entry).next = NULL; (**entry).id = _slang_strdup(id); if ((**entry).id == NULL) return SLANG_ATOM_NULL; return (slang_atom) (**entry).id; }
/** * Return a new slang_ir_storage object. */ slang_ir_storage * _slang_new_ir_storage_relative(GLint index, GLint size, slang_ir_storage *parent) { slang_ir_storage *st; st = (slang_ir_storage *) _slang_alloc(sizeof(slang_ir_storage)); if (st) { st->File = PROGRAM_UNDEFINED; st->Index = index; st->Size = size; st->Swizzle = SWIZZLE_NOOP; st->Parent = parent; } return st; }