Merge pull request #2810 from kumpera/fix_hazard_free
[mono.git] / mono / metadata / opcodes.c
index cbf00514f8d613035a9925fef6f348d1f030f939..838142e253f01761818863eade191b0f48381df4 100644 (file)
@@ -4,13 +4,16 @@
  * Author:
  *   Paolo Molaro (lupus@ximian.com)
  *
- * (C) 2002 Ximian, Inc.
+ * Copyright 2002-2003 Ximian, Inc (http://www.ximian.com)
+ * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  */
 #include <mono/metadata/opcodes.h>
 #include <stddef.h> /* for NULL */
+#include <config.h>
 
 #define MONO_PREFIX1_OFFSET MONO_CEE_ARGLIST
-#define MONO_CUSTOM_PREFIX_OFFSET MONO_CEE_MONO_FUNC1
+#define MONO_CUSTOM_PREFIX_OFFSET MONO_CEE_MONO_ICALL
 
 #define OPDEF(a,b,c,d,e,f,g,h,i,j) \
        { Mono ## e, MONO_FLOW_ ## j, MONO_ ## a },
@@ -23,29 +26,68 @@ mono_opcodes [MONO_CEE_LAST + 1] = {
 
 #undef OPDEF
 
+#ifdef HAVE_ARRAY_ELEM_INIT
+#define MSGSTRFIELD(line) MSGSTRFIELD1(line)
+#define MSGSTRFIELD1(line) str##line
+static const struct msgstr_t {
+#define OPDEF(a,b,c,d,e,f,g,h,i,j) char MSGSTRFIELD(__LINE__) [sizeof (b)];
+#include "mono/cil/opcode.def"
+#undef OPDEF
+} opstr = {
 #define OPDEF(a,b,c,d,e,f,g,h,i,j) b,
+#include "mono/cil/opcode.def"
+#undef OPDEF
+};
+static const int16_t opidx [] = {
+#define OPDEF(a,b,c,d,e,f,g,h,i,j) [MONO_ ## a] = offsetof (struct msgstr_t, MSGSTRFIELD(__LINE__)),
+#include "mono/cil/opcode.def"
+#undef OPDEF
+};
 
-const char* const
+const char*
+mono_opcode_name (int opcode)
+{
+       return (const char*)&opstr + opidx [opcode];
+}
+
+#else
+#define OPDEF(a,b,c,d,e,f,g,h,i,j) b,
+static const char* const
 mono_opcode_names [MONO_CEE_LAST + 1] = {
 #include "mono/cil/opcode.def"
        NULL
 };
 
+const char*
+mono_opcode_name (int opcode)
+{
+       return mono_opcode_names [opcode];
+}
+
+#endif
+
 MonoOpcodeEnum
-mono_opcode_value (const guint8 **ip)
+mono_opcode_value (const mono_byte **ip, const mono_byte *end)
 {
        MonoOpcodeEnum res;
+       const mono_byte *p = *ip;
 
-       if (**ip == 0xfe) {
-               ++*ip;
-               res = **ip + MONO_PREFIX1_OFFSET;
-       } else if (**ip == MONO_CUSTOM_PREFIX) {
-               ++*ip;
-               res = **ip + MONO_CUSTOM_PREFIX_OFFSET;
+       if (p >= end)
+               return (MonoOpcodeEnum)-1;
+       if (*p == 0xfe) {
+               ++p;
+               if (p >= end)
+                       return (MonoOpcodeEnum)-1;
+               res = (MonoOpcodeEnum)(*p + MONO_PREFIX1_OFFSET);
+       } else if (*p == MONO_CUSTOM_PREFIX) {
+               ++p;
+               if (p >= end)
+                       return (MonoOpcodeEnum)-1;
+               res = (MonoOpcodeEnum)(*p + MONO_CUSTOM_PREFIX_OFFSET);
        } else {
-               res = **ip;
+               res = (MonoOpcodeEnum)*p;
        }
-       
+       *ip = p;
        return res;
 }