diff options
Diffstat (limited to 'mesalib/src')
-rwxr-xr-x[-rw-r--r--] | mesalib/src/glsl/ast.h | 38 | ||||
-rwxr-xr-x[-rw-r--r--] | mesalib/src/glsl/glsl_parser_extras.h | 17 | ||||
-rwxr-xr-x | mesalib/src/glsl/glsl_symbol_table.cpp | 15 | ||||
-rwxr-xr-x[-rw-r--r--] | mesalib/src/glsl/ir_constant_expression.cpp | 25 | ||||
-rw-r--r-- | mesalib/src/glsl/ir_function_detect_recursion.cpp | 20 | ||||
-rwxr-xr-x[-rw-r--r--] | mesalib/src/glsl/list.h | 38 | ||||
-rw-r--r-- | mesalib/src/glsl/ralloc.h | 26 | ||||
-rw-r--r-- | mesalib/src/mesa/program/ir_to_mesa.cpp | 12 | ||||
-rw-r--r-- | mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 12 |
9 files changed, 47 insertions, 156 deletions
diff --git a/mesalib/src/glsl/ast.h b/mesalib/src/glsl/ast.h index e6d8afef3..242ee4883 100644..100755 --- a/mesalib/src/glsl/ast.h +++ b/mesalib/src/glsl/ast.h @@ -49,28 +49,11 @@ struct YYLTYPE; */ class ast_node { public: - /* 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 *node; - - node = rzalloc_size(ctx, size); - assert(node != NULL); - - return node; - } - - /* If the user *does* call delete, that's OK, we will just - * ralloc_free in that case. */ + DECLARE_RZALLOC_CXX_OPERATORS(ast_node); static void operator delete(void *table, void *ctx) { ralloc_free(table); } - static void operator delete(void *table) - { - ralloc_free(table); - } /** * Print an AST node in something approximating the original GLSL code @@ -367,24 +350,7 @@ enum { }; struct ast_type_qualifier { - /* 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 *node; - - node = rzalloc_size(ctx, size); - assert(node != NULL); - - return node; - } - - /* If the user *does* call delete, that's OK, we will just - * ralloc_free in that case. */ - static void operator delete(void *table) - { - ralloc_free(table); - } + DECLARE_RZALLOC_CXX_OPERATORS(ast_type_qualifier); union { struct { diff --git a/mesalib/src/glsl/glsl_parser_extras.h b/mesalib/src/glsl/glsl_parser_extras.h index 6e3b0282d..597e5427b 100644..100755 --- a/mesalib/src/glsl/glsl_parser_extras.h +++ b/mesalib/src/glsl/glsl_parser_extras.h @@ -73,26 +73,11 @@ struct _mesa_glsl_parse_state { _mesa_glsl_parse_state(struct gl_context *_ctx, GLenum target, void *mem_ctx); - /* 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 *mem = rzalloc_size(ctx, size); - assert(mem != NULL); - - return mem; - } - - /* If the user *does* call delete, that's OK, we will just - * ralloc_free in that case. */ + DECLARE_RZALLOC_CXX_OPERATORS(_mesa_glsl_parse_state); static void operator delete(void *mem, void *ctx) { ralloc_free(mem); } - static void operator delete(void *mem) - { - ralloc_free(mem); - } /** * Generate a string representing the GLSL version currently being compiled diff --git a/mesalib/src/glsl/glsl_symbol_table.cpp b/mesalib/src/glsl/glsl_symbol_table.cpp index 99057bced..0eabc23d8 100755 --- a/mesalib/src/glsl/glsl_symbol_table.cpp +++ b/mesalib/src/glsl/glsl_symbol_table.cpp @@ -26,24 +26,11 @@ class symbol_table_entry { public: - /* 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 = ralloc_size(ctx, size); - assert(entry != NULL); - return entry; - } - - /* If the user *does* call delete, that's OK, we will just ralloc_free. */ + DECLARE_RALLOC_CXX_OPERATORS(symbol_table_entry); static void operator delete(void *entry, void *ctx) { ralloc_free(entry); } - static void operator delete(void *entry) - { - ralloc_free(entry); - } bool add_interface(const glsl_type *i, enum ir_variable_mode mode) { diff --git a/mesalib/src/glsl/ir_constant_expression.cpp b/mesalib/src/glsl/ir_constant_expression.cpp index 3e30510a6..215c4a0ff 100644..100755 --- a/mesalib/src/glsl/ir_constant_expression.cpp +++ b/mesalib/src/glsl/ir_constant_expression.cpp @@ -40,19 +40,18 @@ #include "glsl_types.h" #include "program/hash_table.h" -#ifdef _MSC_VER -#include <limits> - -inline bool isnormal(float x)
-{
- if(x < 0) x = -x;
- return x >= (std::numeric_limits<float>::min)()
- && x <= (std::numeric_limits<float>::max)();
-}
-inline float copysign(const float& x, const float& y)
-{
- return fabs(x) * ((y<0) ? -1 : 1);
-}
+#if defined(_MSC_VER) && (_MSC_VER < 1800) +static int isnormal(double x) +{ + return _fpclass(x) == _FPCLASS_NN || _fpclass(x) == _FPCLASS_PN; +} +#endif + +#if defined(_MSC_VER) +static double copysign(double x, double y) +{ + return _copysign(x, y); +} #endif static float diff --git a/mesalib/src/glsl/ir_function_detect_recursion.cpp b/mesalib/src/glsl/ir_function_detect_recursion.cpp index 280c4734a..b02c32518 100644 --- a/mesalib/src/glsl/ir_function_detect_recursion.cpp +++ b/mesalib/src/glsl/ir_function_detect_recursion.cpp @@ -139,25 +139,7 @@ public: /* empty */ } - - /* 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 *node; - - node = ralloc_size(ctx, size); - assert(node != NULL); - - return node; - } - - /* If the user *does* call delete, that's OK, we will just - * ralloc_free in that case. */ - static void operator delete(void *node) - { - ralloc_free(node); - } + DECLARE_RALLOC_CXX_OPERATORS(function) ir_function_signature *sig; diff --git a/mesalib/src/glsl/list.h b/mesalib/src/glsl/list.h index fb6f0fbba..2934539fe 100644..100755 --- a/mesalib/src/glsl/list.h +++ b/mesalib/src/glsl/list.h @@ -76,28 +76,11 @@ struct exec_node { struct exec_node *prev; #ifdef __cplusplus - /* 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 *node; - - node = ralloc_size(ctx, size); - assert(node != NULL); - - return node; - } - - /* If the user *does* call delete, that's OK, we will just - * ralloc_free in that case. */ + DECLARE_RALLOC_CXX_OPERATORS(exec_node) static void operator delete(void *node, void *ctx) { ralloc_free(node); } - static void operator delete(void *node) - { - ralloc_free(node); - } exec_node() : next(NULL), prev(NULL) { @@ -289,28 +272,11 @@ struct exec_list { struct exec_node *tail_pred; #ifdef __cplusplus - /* 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 *node; - - node = ralloc_size(ctx, size); - assert(node != NULL); - - return node; - } - - /* If the user *does* call delete, that's OK, we will just - * ralloc_free in that case. */ + DECLARE_RALLOC_CXX_OPERATORS(exec_list) static void operator delete(void *node, void *ctx) { ralloc_free(node); } - static void operator delete(void *node) - { - ralloc_free(node); - } exec_list() { diff --git a/mesalib/src/glsl/ralloc.h b/mesalib/src/glsl/ralloc.h index 67eb93833..799d3a9b8 100644 --- a/mesalib/src/glsl/ralloc.h +++ b/mesalib/src/glsl/ralloc.h @@ -404,4 +404,30 @@ bool ralloc_vasprintf_append(char **str, const char *fmt, va_list args); } /* end of extern "C" */ #endif +#define _RALLOC_OPS(ALLOC, TYPE) \ + static void* operator new(size_t size, void *mem_ctx) \ + { \ + void *p = ALLOC(mem_ctx, size); \ + assert(p != NULL); \ + return p; \ + } \ + \ + static void operator delete(void *p) \ + { \ + ralloc_free(p); \ + } + +/** + * Declare C++ new and delete operators which use ralloc. + * + * Placing one of these macros in the body of a class makes it possible to do: + * + * TYPE *var = new(mem_ctx) TYPE(...); + * delete var; + * + * which is more idiomatic in C++ than calling ralloc or rzalloc. + */ +#define DECLARE_RALLOC_CXX_OPERATORS(TYPE) _RALLOC_OPS(ralloc_size, TYPE) +#define DECLARE_RZALLOC_CXX_OPERATORS(TYPE) _RALLOC_OPS(rzalloc_size, TYPE) + #endif diff --git a/mesalib/src/mesa/program/ir_to_mesa.cpp b/mesalib/src/mesa/program/ir_to_mesa.cpp index cef32dc07..c46a3d005 100644 --- a/mesalib/src/mesa/program/ir_to_mesa.cpp +++ b/mesalib/src/mesa/program/ir_to_mesa.cpp @@ -149,17 +149,7 @@ dst_reg::dst_reg(src_reg reg) class ir_to_mesa_instruction : public exec_node { public: - /* 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 *node; - - node = rzalloc_size(ctx, size); - assert(node != NULL); - - return node; - } + DECLARE_RZALLOC_CXX_OPERATORS(ir_to_mesa_instruction) enum prog_opcode op; dst_reg dst; diff --git a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index 0a1837f69..271cf0523 100644 --- a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -217,17 +217,7 @@ st_dst_reg::st_dst_reg(st_src_reg reg) class glsl_to_tgsi_instruction : public exec_node { public: - /* 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 *node; - - node = rzalloc_size(ctx, size); - assert(node != NULL); - - return node; - } + DECLARE_RZALLOC_CXX_OPERATORS(glsl_to_tgsi_instruction) unsigned op; st_dst_reg dst; |