summaryrefslogtreecommitdiff
path: root/ir.cpp
diff options
context:
space:
mode:
authorKenneth Graunke <kenneth@whitecape.org>2010-04-07 17:18:29 -0700
committerIan Romanick <ian.d.romanick@intel.com>2010-04-28 15:42:07 -0700
commit3b96996b7eb6e3603a5f138177867c3e856e0dfa (patch)
tree0dad0ce7c51cad062115e44fa31b7c798a34052c /ir.cpp
parentbff6013d469b3d4e54cdc5731801c56994a523ec (diff)
Move array of operator strings out of ir_print_visitor.cpp.
Also implement a reverse-lookup function for use in the IR reader.
Diffstat (limited to 'ir.cpp')
-rw-r--r--ir.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/ir.cpp b/ir.cpp
index e7e5dee00c..3f4c40d0c9 100644
--- a/ir.cpp
+++ b/ir.cpp
@@ -108,6 +108,70 @@ ir_expression::get_num_operands(ir_expression_operation op)
return num_operands[op];
}
+static const char *const operator_strs[] = {
+ "~",
+ "!",
+ "-",
+ "abs",
+ "rcp",
+ "rsq",
+ "sqrt",
+ "exp",
+ "log",
+ "exp2",
+ "log2",
+ "f2i",
+ "i2f",
+ "f2b",
+ "b2f",
+ "i2b",
+ "b2i",
+ "u2f",
+ "trunc",
+ "ceil",
+ "floor",
+ "+",
+ "-",
+ "*",
+ "/",
+ "%",
+ "<",
+ ">",
+ "<=",
+ ">=",
+ "==",
+ "!=",
+ "<<",
+ ">>",
+ "&",
+ "^",
+ "|",
+ "&&",
+ "^^",
+ "||",
+ "dot",
+ "min",
+ "max",
+ "pow",
+};
+
+const char *ir_expression::operator_string()
+{
+ assert((unsigned int) operation <=
+ sizeof(operator_strs) / sizeof(operator_strs[0]));
+ return operator_strs[operation];
+}
+
+ir_expression_operation
+ir_expression::get_operator(const char *str)
+{
+ const int operator_count = sizeof(operator_strs) / sizeof(operator_strs[0]);
+ for (int op = 0; op < operator_count; op++) {
+ if (strcmp(str, operator_strs[op]) == 0)
+ return (ir_expression_operation) op;
+ }
+ return (ir_expression_operation) -1;
+}
ir_constant::ir_constant(const struct glsl_type *type, const void *data)
{