Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / metadata / opcodes.c
1 /**
2  * \file
3  * CIL instruction information
4  *
5  * Author:
6  *   Paolo Molaro (lupus@ximian.com)
7  *
8  * Copyright 2002-2003 Ximian, Inc (http://www.ximian.com)
9  * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
10  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
11  */
12 #include <mono/metadata/opcodes.h>
13 #include <stddef.h> /* for NULL */
14 #include <config.h>
15
16 #define MONO_PREFIX1_OFFSET MONO_CEE_ARGLIST
17 #define MONO_CUSTOM_PREFIX_OFFSET MONO_CEE_MONO_ICALL
18
19 #define OPDEF(a,b,c,d,e,f,g,h,i,j) \
20         { Mono ## e, MONO_FLOW_ ## j, MONO_ ## a },
21
22 const MonoOpcode
23 mono_opcodes [MONO_CEE_LAST + 1] = {
24 #include "mono/cil/opcode.def"
25         {0}
26 };
27
28 #undef OPDEF
29
30 #ifdef HAVE_ARRAY_ELEM_INIT
31 #define MSGSTRFIELD(line) MSGSTRFIELD1(line)
32 #define MSGSTRFIELD1(line) str##line
33 static const struct msgstr_t {
34 #define OPDEF(a,b,c,d,e,f,g,h,i,j) char MSGSTRFIELD(__LINE__) [sizeof (b)];
35 #include "mono/cil/opcode.def"
36 #undef OPDEF
37 } opstr = {
38 #define OPDEF(a,b,c,d,e,f,g,h,i,j) b,
39 #include "mono/cil/opcode.def"
40 #undef OPDEF
41 };
42 static const int16_t opidx [] = {
43 #define OPDEF(a,b,c,d,e,f,g,h,i,j) [MONO_ ## a] = offsetof (struct msgstr_t, MSGSTRFIELD(__LINE__)),
44 #include "mono/cil/opcode.def"
45 #undef OPDEF
46 };
47
48 /**
49  * mono_opcode_name:
50  */
51 const char*
52 mono_opcode_name (int opcode)
53 {
54         return (const char*)&opstr + opidx [opcode];
55 }
56
57 #else
58 #define OPDEF(a,b,c,d,e,f,g,h,i,j) b,
59 static const char* const
60 mono_opcode_names [MONO_CEE_LAST + 1] = {
61 #include "mono/cil/opcode.def"
62         NULL
63 };
64
65 const char*
66 mono_opcode_name (int opcode)
67 {
68         return mono_opcode_names [opcode];
69 }
70
71 #endif
72
73 MonoOpcodeEnum
74 mono_opcode_value (const mono_byte **ip, const mono_byte *end)
75 {
76         MonoOpcodeEnum res;
77         const mono_byte *p = *ip;
78
79         if (p >= end)
80                 return (MonoOpcodeEnum)-1;
81         if (*p == 0xfe) {
82                 ++p;
83                 if (p >= end)
84                         return (MonoOpcodeEnum)-1;
85                 res = (MonoOpcodeEnum)(*p + MONO_PREFIX1_OFFSET);
86         } else if (*p == MONO_CUSTOM_PREFIX) {
87                 ++p;
88                 if (p >= end)
89                         return (MonoOpcodeEnum)-1;
90                 res = (MonoOpcodeEnum)(*p + MONO_CUSTOM_PREFIX_OFFSET);
91         } else {
92                 res = (MonoOpcodeEnum)*p;
93         }
94         *ip = p;
95         return res;
96 }
97