X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fglsl%2Fglsl_symbol_table.cpp;h=2f291d4f97fe95e8a9c33b1aa085a611e8bbf695;hb=cbcb84fccf0e7a9450a10bc1daf3572ab9a4955c;hp=76c440c3420a955c0a3f1128e64f1cdb3416b4d7;hpb=e9c7ceed27f6811ad1cae46c93ce9bc3fb3668d8;p=mesa.git diff --git a/src/glsl/glsl_symbol_table.cpp b/src/glsl/glsl_symbol_table.cpp index 76c440c3420..2f291d4f97f 100644 --- a/src/glsl/glsl_symbol_table.cpp +++ b/src/glsl/glsl_symbol_table.cpp @@ -26,27 +26,24 @@ class symbol_table_entry { public: - /* Callers of this talloc-based new need not call delete. It's - * easier to just talloc_free 'ctx' (or any of its ancestors). */ + /* Callers of this ralloc-based new need not call delete. It's + * easier to just ralloc_free 'ctx' (or any of its ancestors). */ static void* operator new(size_t size, void *ctx) { - void *entry = talloc_size(ctx, size); + void *entry = ralloc_size(ctx, size); assert(entry != NULL); return entry; } - /* If the user *does* call delete, that's OK, we will just - * talloc_free in that case. Here, C++ will have already called the - * destructor so tell talloc not to do that again. */ - static void operator delete(void *table) + /* If the user *does* call delete, that's OK, we will just ralloc_free. */ + static void operator delete(void *entry) { - talloc_set_destructor(table, NULL); - talloc_free(table); + ralloc_free(entry); } symbol_table_entry(ir_variable *v) : v(v), f(0), t(0) {} symbol_table_entry(ir_function *f) : v(0), f(f), t(0) {} - symbol_table_entry(const glsl_type *t, ir_function *f) : v(0), f(f), t(t) {} + symbol_table_entry(const glsl_type *t) : v(0), f(0), t(t) {} ir_variable *v; ir_function *f; @@ -57,13 +54,13 @@ glsl_symbol_table::glsl_symbol_table() { this->language_version = 120; this->table = _mesa_symbol_table_ctor(); - this->mem_ctx = talloc_init("symbol table entries"); + this->mem_ctx = ralloc_context(NULL); } glsl_symbol_table::~glsl_symbol_table() { _mesa_symbol_table_dtor(table); - talloc_free(mem_ctx); + ralloc_free(mem_ctx); } void glsl_symbol_table::push_scope() @@ -81,12 +78,12 @@ bool glsl_symbol_table::name_declared_this_scope(const char *name) return _mesa_symbol_table_symbol_scope(table, -1, name) == 0; } -bool glsl_symbol_table::add_variable(const char *name, ir_variable *v) +bool glsl_symbol_table::add_variable(ir_variable *v) { if (this->language_version == 110) { /* In 1.10, functions and variables have separate namespaces. */ - symbol_table_entry *existing = get_entry(name); - if (name_declared_this_scope(name)) { + symbol_table_entry *existing = get_entry(v->name); + if (name_declared_this_scope(v->name)) { /* If there's already an existing function (not a constructor!) in * the current scope, just update the existing entry to include 'v'. */ @@ -102,8 +99,9 @@ bool glsl_symbol_table::add_variable(const char *name, ir_variable *v) symbol_table_entry *entry = new(mem_ctx) symbol_table_entry(v); if (existing != NULL) entry->f = existing->f; - int added = _mesa_symbol_table_add_symbol(table, -1, name, entry); + int added = _mesa_symbol_table_add_symbol(table, -1, v->name, entry); assert(added == 0); + (void)added; return true; } return false; @@ -111,28 +109,34 @@ bool glsl_symbol_table::add_variable(const char *name, ir_variable *v) /* 1.20+ rules: */ symbol_table_entry *entry = new(mem_ctx) symbol_table_entry(v); - return _mesa_symbol_table_add_symbol(table, -1, name, entry) == 0; + return _mesa_symbol_table_add_symbol(table, -1, v->name, entry) == 0; } -bool glsl_symbol_table::add_type(const char *name, const glsl_type *t, - ir_function *constructor) +bool glsl_symbol_table::add_type(const char *name, const glsl_type *t) { - symbol_table_entry *entry = new(mem_ctx) symbol_table_entry(t, constructor); + symbol_table_entry *entry = new(mem_ctx) symbol_table_entry(t); return _mesa_symbol_table_add_symbol(table, -1, name, entry) == 0; } -bool glsl_symbol_table::add_function(const char *name, ir_function *f) +bool glsl_symbol_table::add_function(ir_function *f) { - if (this->language_version == 110 && name_declared_this_scope(name)) { + if (this->language_version == 110 && name_declared_this_scope(f->name)) { /* In 1.10, functions and variables have separate namespaces. */ - symbol_table_entry *existing = get_entry(name); - if (existing->f == NULL) { + symbol_table_entry *existing = get_entry(f->name); + if ((existing->f == NULL) && (existing->t == NULL)) { existing->f = f; return true; } } symbol_table_entry *entry = new(mem_ctx) symbol_table_entry(f); - return _mesa_symbol_table_add_symbol(table, -1, name, entry) == 0; + return _mesa_symbol_table_add_symbol(table, -1, f->name, entry) == 0; +} + +void glsl_symbol_table::add_global_function(ir_function *f) +{ + symbol_table_entry *entry = new(mem_ctx) symbol_table_entry(f); + int added = _mesa_symbol_table_add_global_symbol(table, -1, f->name, entry); + assert(added == 0); } ir_variable *glsl_symbol_table::get_variable(const char *name)