Add mappings between ir_texture_opcode and strings.
authorKenneth Graunke <kenneth@whitecape.org>
Wed, 26 May 2010 23:41:47 +0000 (16:41 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Wed, 9 Jun 2010 18:14:57 +0000 (11:14 -0700)
ir.cpp
ir.h

diff --git a/ir.cpp b/ir.cpp
index 2b05e9776d305d1505ddcff1daf937edc4a01e61..9a713494d3b467c8bcb336fa28d0433f96d27170 100644 (file)
--- a/ir.cpp
+++ b/ir.cpp
@@ -303,6 +303,27 @@ ir_dereference::is_lvalue()
 }
 
 
+const char *tex_opcode_strs[] = { "tex", "txb", "txl", "txd", "txf" };
+
+const char *ir_texture::opcode_string()
+{
+   assert((unsigned int) op <=
+         sizeof(tex_opcode_strs) / sizeof(tex_opcode_strs[0]));
+   return tex_opcode_strs[op];
+}
+
+ir_texture_opcode
+ir_texture::get_opcode(const char *str)
+{
+   const int count = sizeof(tex_opcode_strs) / sizeof(tex_opcode_strs[0]);
+   for (int op = 0; op < count; op++) {
+      if (strcmp(str, tex_opcode_strs[op]) == 0)
+        return (ir_texture_opcode) op;
+   }
+   return (ir_texture_opcode) -1;
+}
+
+
 ir_swizzle::ir_swizzle(ir_rvalue *val, unsigned x, unsigned y, unsigned z,
                       unsigned w, unsigned count)
    : val(val)
diff --git a/ir.h b/ir.h
index fcb23ea0fab8852443b63ca20dedace2fee0e3c3..44ffdc554ee87aa07c0b5bb9c1ebd4e641f8d488 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -775,6 +775,16 @@ public:
       /* empty */
    }
 
+   /**
+    * Return a string representing the ir_texture_opcode.
+    */
+   const char *opcode_string();
+
+   /**
+    * Do a reverse-lookup to translate a string into an ir_texture_opcode.
+    */
+   static ir_texture_opcode get_opcode(const char *);
+
    enum ir_texture_opcode op;
 
    /** Sampler to use for the texture access. */