1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5
6/***************************************************************************/
7/* ILFormatter.h */
8/***************************************************************************/
9
10#ifndef ILFormatter_h
11#define ILFormatter_h
12
13#include "opinfo.h"
14#include "outstring.h"
15
16struct IMetaDataImport;
17
18#define INVALID_IL_OFFSET 0x80000000
19
20/***************************************************************************/
21class ILFormatter {
22public:
23 ILFormatter() : start(0), targetStart(0), stackStart(0) {}
24
25 ILFormatter(IMetaDataImport* aMeta, const BYTE* aStart,
26 const BYTE* aLimit, unsigned maxStack, const COR_ILMETHOD_SECT_EH* eh)
27 : targetStart(0), stackStart(0) {
28 init(aMeta, aStart, aLimit, maxStack, eh);
29 }
30 ~ILFormatter() { delete [] stackStart; delete [] targetStart; }
31
32 void init(IMetaDataImport* aMeta, const BYTE* aStart,
33 const BYTE* aLimit, unsigned maxStack, const COR_ILMETHOD_SECT_EH* eh);
34 const BYTE* formatStatement(const BYTE* stmtIL, OutString* out);
35 const BYTE* formatInstr(const BYTE* instrIL, OutString* out);
36private:
37
38 void formatInstrArgs(OpInfo op, OpArgsVal arg, OutString* out, size_t curIP=INVALID_IL_OFFSET);
39 void formatArgs(unsigned numArgs, OutString* out);
40 void spillStack(OutString* out);
41 void setStackAsTarget(size_t ilOffset);
42 void setTarget(size_t ilOffset, size_t depth);
43
44private:
45 const BYTE* start; // keeps us sane
46 const BYTE* limit;
47 IMetaDataImport* meta; // used to parse tokens etc
48
49 struct StackEntry {
50 OutString val;
51 int prec;
52 };
53
54 struct Target {
55 size_t ilOffset;
56 size_t stackDepth;
57 };
58
59 Target* targetStart;
60 Target* targetEnd;
61 Target* targetCur;
62
63 size_t stackDepth();
64 void pushAndClear(OutString* val, int prec);
65 OutString* pop(int prec = 0);
66 OutString* top();
67 void popN(size_t num);
68
69 StackEntry* stackStart;
70 StackEntry* stackEnd;
71 StackEntry* stackCur; // points at the next slot to fill
72
73};
74
75#endif
76
77