aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/glsl
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/glsl')
-rw-r--r--mesalib/src/glsl/ast.h38
-rw-r--r--mesalib/src/glsl/glsl_parser_extras.h17
-rw-r--r--mesalib/src/glsl/glsl_symbol_table.cpp15
-rw-r--r--mesalib/src/glsl/ir_constant_expression.cpp14
-rw-r--r--mesalib/src/glsl/ir_function_detect_recursion.cpp20
-rw-r--r--mesalib/src/glsl/list.h38
-rw-r--r--mesalib/src/glsl/ralloc.h26
7 files changed, 47 insertions, 121 deletions
diff --git a/mesalib/src/glsl/ast.h b/mesalib/src/glsl/ast.h
index 1c7fc63ac..c3361a106 100644
--- a/mesalib/src/glsl/ast.h
+++ b/mesalib/src/glsl/ast.h
@@ -49,24 +49,7 @@ 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. */
- static void operator delete(void *table)
- {
- ralloc_free(table);
- }
+ DECLARE_RZALLOC_CXX_OPERATORS(ast_node);
/**
* Print an AST node in something approximating the original GLSL code
@@ -363,24 +346,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 2e2440a9e..364a98345 100644
--- a/mesalib/src/glsl/glsl_parser_extras.h
+++ b/mesalib/src/glsl/glsl_parser_extras.h
@@ -73,22 +73,7 @@ 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. */
- static void operator delete(void *mem)
- {
- ralloc_free(mem);
- }
+ DECLARE_RZALLOC_CXX_OPERATORS(_mesa_glsl_parse_state);
/**
* 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 4c96620bf..6e916b458 100644
--- a/mesalib/src/glsl/glsl_symbol_table.cpp
+++ b/mesalib/src/glsl/glsl_symbol_table.cpp
@@ -26,20 +26,7 @@
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. */
- static void operator delete(void *entry)
- {
- ralloc_free(entry);
- }
+ DECLARE_RALLOC_CXX_OPERATORS(symbol_table_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 4579ef209..12641e5df 100644
--- a/mesalib/src/glsl/ir_constant_expression.cpp
+++ b/mesalib/src/glsl/ir_constant_expression.cpp
@@ -40,6 +40,20 @@
#include "glsl_types.h"
#include "program/hash_table.h"
+#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
dot(ir_constant *op0, ir_constant *op1)
{
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 1d46365fa..5ac17cb37 100644
--- a/mesalib/src/glsl/list.h
+++ b/mesalib/src/glsl/list.h
@@ -76,24 +76,7 @@ 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. */
- static void operator delete(void *node)
- {
- ralloc_free(node);
- }
+ DECLARE_RALLOC_CXX_OPERATORS(exec_node)
exec_node() : next(NULL), prev(NULL)
{
@@ -285,24 +268,7 @@ 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. */
- static void operator delete(void *node)
- {
- ralloc_free(node);
- }
+ DECLARE_RALLOC_CXX_OPERATORS(exec_list)
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