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.
9 // ZapNode that points into middle of other ZapNode. It is used to create
10 // pointers into datastructures that are not convenient to split into smaller zap nodes.
12 // ======================================================================================
14 #ifndef __ZAPINNERPTR_H__
15 #define __ZAPINNERPTR_H__
17 class ZapInnerPtr : public ZapNode
22 ZapInnerPtr(ZapNode * pBase)
32 virtual int GetOffset() = 0;
36 if (m_pBase->IsPlaced())
38 SetRVA(m_pBase->GetRVA() + GetOffset());
42 virtual ZapNodeType GetType()
44 return ZapNodeType_InnerPtr;
48 class ZapInnerPtrTable
50 // Create more space efficient nodes for a few common constant offsets
51 template <DWORD offset>
52 class InnerPtrConst : public ZapInnerPtr
55 InnerPtrConst(ZapNode * pBase)
60 virtual int GetOffset()
66 // The generic node for arbitrary offsets
67 class InnerPtrVar : public ZapInnerPtr
72 InnerPtrVar(ZapNode * pBase, SSIZE_T offset)
73 : ZapInnerPtr(pBase), m_offset((int)offset)
75 if (offset != (int)offset)
76 ThrowHR(COR_E_OVERFLOW);
79 virtual int GetOffset()
87 InnerPtrKey(ZapNode * pBase, SSIZE_T offset)
88 : m_pBase(pBase), m_offset(offset)
96 class InnerPtrTraits : public NoRemoveSHashTraits< DefaultSHashTraits<ZapInnerPtr *> >
99 typedef const InnerPtrKey key_t;
101 static key_t GetKey(element_t e)
103 LIMITED_METHOD_CONTRACT;
104 return InnerPtrKey(e->GetBase(), e->GetOffset());
106 static BOOL Equals(key_t k1, key_t k2)
108 LIMITED_METHOD_CONTRACT;
109 return (k1.m_pBase == k2.m_pBase) && (k1.m_offset == k2.m_offset);
111 static count_t Hash(key_t k)
113 LIMITED_METHOD_CONTRACT;
114 return (count_t)(size_t)k.m_pBase ^ (count_t)k.m_offset;
117 static const element_t Null() { LIMITED_METHOD_CONTRACT; return NULL; }
118 static bool IsNull(const element_t &e) { LIMITED_METHOD_CONTRACT; return e == NULL; }
121 typedef SHash< InnerPtrTraits > InnerPtrTable;
123 InnerPtrTable m_entries;
124 ZapWriter * m_pWriter;
127 ZapInnerPtrTable(ZapWriter * pWriter)
132 void Preallocate(COUNT_T cbILImage)
134 PREALLOCATE_HASHTABLE_NOT_NEEDED(ZapInnerPtrTable::m_entries, cbILImage);
137 // Returns ZapNode that points at given offset in base ZapNode
138 ZapNode * Get(ZapNode * pBase, SSIZE_T offset);
140 // Assign offsets to the inner-ptr ZapNodes
144 #endif // __ZAPINNERPTR_H__