summaryrefslogtreecommitdiff
path: root/src/utilcode/opinfo.cpp
diff options
context:
space:
mode:
authordotnet-bot <dotnet-bot@microsoft.com>2015-01-30 14:14:42 -0800
committerdotnet-bot <dotnet-bot@microsoft.com>2015-01-30 14:14:42 -0800
commitef1e2ab328087c61a6878c1e84f4fc5d710aebce (patch)
treedee1bbb89e9d722e16b0d1485e3cdd1b6c8e2cfa /src/utilcode/opinfo.cpp
downloadcoreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.gz
coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.tar.bz2
coreclr-ef1e2ab328087c61a6878c1e84f4fc5d710aebce.zip
Initial commit to populate CoreCLR repo
[tfs-changeset: 1407945]
Diffstat (limited to 'src/utilcode/opinfo.cpp')
-rw-r--r--src/utilcode/opinfo.cpp129
1 files changed, 129 insertions, 0 deletions
diff --git a/src/utilcode/opinfo.cpp b/src/utilcode/opinfo.cpp
new file mode 100644
index 0000000000..a7d71dbfc2
--- /dev/null
+++ b/src/utilcode/opinfo.cpp
@@ -0,0 +1,129 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+/***************************************************************************/
+/* OpInfo.cpp */
+/***************************************************************************/
+
+#include "stdafx.h"
+#include <cor.h> // for debugMacros.h
+#include "debugmacros.h" // for ASSERTE
+#include "opinfo.h"
+
+
+OpInfo::OpInfoData OpInfo::table[] = {
+
+#ifdef _MSC_VER
+#define OPDEF(c,s,pop,push,args,type,l,s1,s2,ctrl) \
+ { s, args + type, FLOW_ ## ctrl, pop, push, c },
+#else
+#define OPDEF(c,s,pop,push,args,type,l,s1,s2,ctrl) \
+ { s, (OPCODE_FORMAT) (args + type), FLOW_ ## ctrl, pop, push, c },
+#endif
+
+ // Kind of a workaround, get the prefixes (IInternal) to return InlineOpcode instead of InlineNone
+#define IInternal (InlineOpcode - InlineNone)
+#define IMacro 0
+#define IPrimitive 0
+#define IAnnotation 0
+#define IObjModel 0
+#define IPrefix 0
+
+#define Pop0 0
+#define Pop1 1
+#define PopI 1
+#define PopI4 1
+#define PopR4 1
+#define PopI8 1
+#define PopR8 1
+#define PopRef 1
+#define VarPop -1
+
+#define Push0 0
+#define Push1 1
+#define PushI 1
+#define PushI4 1
+#define PushR4 1
+#define PushI8 1
+#define PushR8 1
+#define PushRef 1
+#define VarPush -1
+
+#include "opcode.def"
+#undef OPDEF
+};
+
+
+/***************************************************************************/
+/* parse instruction at 'instrPtr', into its opcode (OpInfo), and its
+ (inline)args, 'args' 'instrPtr' is updated */
+
+/***************************************************************************/
+const BYTE* OpInfo::fetch(const BYTE* instrPtr, OpArgsVal* args) {
+
+ data = &table[*instrPtr++];
+AGAIN:
+ _ASSERTE(data - table == data->opcode);
+ switch(data->format) {
+ case InlineNone:
+ break;
+ case InlineOpcode:
+ _ASSERTE(*instrPtr + 256 < (int) (sizeof(table) / sizeof(OpInfoData)));
+ data = &table[256 + *instrPtr++];
+ goto AGAIN;
+
+ case ShortInlineVar:
+ args->i = *instrPtr; instrPtr +=1;
+ break;
+ case InlineVar:
+ args->i = GET_UNALIGNED_VAL16(instrPtr); instrPtr +=2;
+ break;
+ case ShortInlineI:
+ case ShortInlineBrTarget:
+ args->i = *instrPtr; instrPtr +=1;
+ break;
+ case ShortInlineR: {
+ DWORD f = GET_UNALIGNED_VAL32(instrPtr); instrPtr +=4;
+ args->r = *((float*) (&f));
+ }
+ break;
+ case InlineRVA:
+ case InlineI:
+ case InlineMethod:
+ case InlineField:
+ case InlineType:
+ case InlineString:
+ case InlineSig:
+ case InlineTok:
+ case InlineBrTarget:
+ args->i = GET_UNALIGNED_VAL32(instrPtr); instrPtr +=4;
+ break;
+ case InlineI8:
+ args->i8 = GET_UNALIGNED_VAL64(instrPtr); instrPtr +=8;
+ break;
+ case InlineR: {
+ __int64 d = GET_UNALIGNED_VAL64(instrPtr); instrPtr +=8;
+ instrPtr += 8;
+ args->r = *((double*) (&d));
+ } break;
+ case InlineSwitch:
+ args->switch_.count = GET_UNALIGNED_VAL32(instrPtr); instrPtr +=4;
+ args->switch_.targets = (int*) instrPtr; instrPtr += (4 * args->switch_.count);
+ break;
+ case InlinePhi:
+ args->phi.count = GET_UNALIGNED_VAL32(instrPtr); instrPtr +=1;
+ args->phi.vars = (unsigned short*) instrPtr; instrPtr += (2 * args->phi.count);
+ break;
+ default:
+#ifdef _DEBUG
+ _ASSERTE(!"BadType");
+#else
+ __assume(0); // we are really certain the default case does not happen
+#endif
+ break;
+ }
+ return(instrPtr);
+}
+