Also implement a reverse-lookup function for use in the IR reader.
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)
{
ir_rvalue *condition;
};
-/* Update ir_expression::num_operands() and ir_print_visitor.cpp when
+/* Update ir_expression::num_operands() and operator_strs when
* updating this list.
-*/
+ */
enum ir_expression_operation {
ir_unop_bit_not,
ir_unop_logic_not,
return get_num_operands(operation);
}
+ /**
+ * Return a string representing this expression's operator.
+ */
+ const char *operator_string();
+
+ /**
+ * Do a reverse-lookup to translate the given string into an operator.
+ */
+ static ir_expression_operation get_operator(const char *);
+
virtual void accept(ir_visitor *v)
{
v->visit(this);
void ir_print_visitor::visit(ir_expression *ir)
{
- static const char *const operators[] = {
- "~",
- "!",
- "-",
- "abs",
- "rcp",
- "rsq",
- "sqrt",
- "exp",
- "log",
- "exp2",
- "log2",
- "f2i",
- "i2f",
- "f2b",
- "b2f",
- "i2b",
- "b2i",
- "u2f",
- "trunc",
- "ceil",
- "floor",
- "+",
- "-",
- "*",
- "/",
- "%",
- "<",
- ">",
- "<=",
- ">=",
- "==",
- "!=",
- "<<",
- ">>",
- "&",
- "^",
- "|",
- "&&",
- "^^",
- "||",
- "dot",
- "min",
- "max",
- "pow",
- };
-
printf("(expression ");
print_type(ir->type);
- assert((unsigned int)ir->operation <
- sizeof(operators) / sizeof(operators[0]));
-
- printf(" %s ", operators[ir->operation]);
+ printf(" %s ", ir->operator_string());
if (ir->operands[0])
ir->operands[0]->accept(this);