mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-02 07:32:52 +00:00
really get this working with a custom allocator.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122722 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
61a10a0dc9
commit
4f20c6d354
@ -40,7 +40,7 @@ template <typename K, typename V, typename KInfo = DenseMapInfo<K>,
|
|||||||
typename AllocatorTy = MallocAllocator>
|
typename AllocatorTy = MallocAllocator>
|
||||||
class ScopedHashTable;
|
class ScopedHashTable;
|
||||||
|
|
||||||
template <typename K, typename V, typename KInfo = DenseMapInfo<K> >
|
template <typename K, typename V>
|
||||||
class ScopedHashTableVal {
|
class ScopedHashTableVal {
|
||||||
ScopedHashTableVal *NextInScope;
|
ScopedHashTableVal *NextInScope;
|
||||||
ScopedHashTableVal *NextForKey;
|
ScopedHashTableVal *NextForKey;
|
||||||
@ -78,29 +78,30 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V, typename KInfo = DenseMapInfo<K> >
|
template <typename K, typename V, typename KInfo = DenseMapInfo<K>,
|
||||||
|
typename AllocatorTy = MallocAllocator>
|
||||||
class ScopedHashTableScope {
|
class ScopedHashTableScope {
|
||||||
/// HT - The hashtable that we are active for.
|
/// HT - The hashtable that we are active for.
|
||||||
ScopedHashTable<K, V, KInfo> &HT;
|
ScopedHashTable<K, V, KInfo, AllocatorTy> &HT;
|
||||||
|
|
||||||
/// PrevScope - This is the scope that we are shadowing in HT.
|
/// PrevScope - This is the scope that we are shadowing in HT.
|
||||||
ScopedHashTableScope *PrevScope;
|
ScopedHashTableScope *PrevScope;
|
||||||
|
|
||||||
/// LastValInScope - This is the last value that was inserted for this scope
|
/// LastValInScope - This is the last value that was inserted for this scope
|
||||||
/// or null if none have been inserted yet.
|
/// or null if none have been inserted yet.
|
||||||
ScopedHashTableVal<K, V, KInfo> *LastValInScope;
|
ScopedHashTableVal<K, V> *LastValInScope;
|
||||||
void operator=(ScopedHashTableScope&); // DO NOT IMPLEMENT
|
void operator=(ScopedHashTableScope&); // DO NOT IMPLEMENT
|
||||||
ScopedHashTableScope(ScopedHashTableScope&); // DO NOT IMPLEMENT
|
ScopedHashTableScope(ScopedHashTableScope&); // DO NOT IMPLEMENT
|
||||||
public:
|
public:
|
||||||
ScopedHashTableScope(ScopedHashTable<K, V, KInfo> &HT);
|
ScopedHashTableScope(ScopedHashTable<K, V, KInfo, AllocatorTy> &HT);
|
||||||
~ScopedHashTableScope();
|
~ScopedHashTableScope();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class ScopedHashTable<K, V, KInfo>;
|
friend class ScopedHashTable<K, V, KInfo, AllocatorTy>;
|
||||||
ScopedHashTableVal<K, V, KInfo> *getLastValInScope() {
|
ScopedHashTableVal<K, V> *getLastValInScope() {
|
||||||
return LastValInScope;
|
return LastValInScope;
|
||||||
}
|
}
|
||||||
void setLastValInScope(ScopedHashTableVal<K, V, KInfo> *Val) {
|
void setLastValInScope(ScopedHashTableVal<K, V> *Val) {
|
||||||
LastValInScope = Val;
|
LastValInScope = Val;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -108,9 +109,9 @@ private:
|
|||||||
|
|
||||||
template <typename K, typename V, typename KInfo = DenseMapInfo<K> >
|
template <typename K, typename V, typename KInfo = DenseMapInfo<K> >
|
||||||
class ScopedHashTableIterator {
|
class ScopedHashTableIterator {
|
||||||
ScopedHashTableVal<K, V, KInfo> *Node;
|
ScopedHashTableVal<K, V> *Node;
|
||||||
public:
|
public:
|
||||||
ScopedHashTableIterator(ScopedHashTableVal<K, V, KInfo> *node) : Node(node) {}
|
ScopedHashTableIterator(ScopedHashTableVal<K, V> *node) : Node(node) {}
|
||||||
|
|
||||||
V &operator*() const {
|
V &operator*() const {
|
||||||
assert(Node && "Dereference end()");
|
assert(Node && "Dereference end()");
|
||||||
@ -140,15 +141,15 @@ public:
|
|||||||
|
|
||||||
template <typename K, typename V, typename KInfo, typename AllocatorTy>
|
template <typename K, typename V, typename KInfo, typename AllocatorTy>
|
||||||
class ScopedHashTable {
|
class ScopedHashTable {
|
||||||
typedef ScopedHashTableVal<K, V, KInfo> ValTy;
|
typedef ScopedHashTableVal<K, V> ValTy;
|
||||||
DenseMap<K, ValTy*, KInfo> TopLevelMap;
|
DenseMap<K, ValTy*, KInfo> TopLevelMap;
|
||||||
ScopedHashTableScope<K, V, KInfo> *CurScope;
|
ScopedHashTableScope<K, V, KInfo, AllocatorTy> *CurScope;
|
||||||
|
|
||||||
AllocatorTy Allocator;
|
AllocatorTy Allocator;
|
||||||
|
|
||||||
ScopedHashTable(const ScopedHashTable&); // NOT YET IMPLEMENTED
|
ScopedHashTable(const ScopedHashTable&); // NOT YET IMPLEMENTED
|
||||||
void operator=(const ScopedHashTable&); // NOT YET IMPLEMENTED
|
void operator=(const ScopedHashTable&); // NOT YET IMPLEMENTED
|
||||||
friend class ScopedHashTableScope<K, V, KInfo>;
|
friend class ScopedHashTableScope<K, V, KInfo, AllocatorTy>;
|
||||||
public:
|
public:
|
||||||
ScopedHashTable() : CurScope(0) {}
|
ScopedHashTable() : CurScope(0) {}
|
||||||
ScopedHashTable(AllocatorTy A) : CurScope(0), Allocator(A) {}
|
ScopedHashTable(AllocatorTy A) : CurScope(0), Allocator(A) {}
|
||||||
@ -176,7 +177,7 @@ public:
|
|||||||
void insert(const K &Key, const V &Val) {
|
void insert(const K &Key, const V &Val) {
|
||||||
assert(CurScope && "No scope active!");
|
assert(CurScope && "No scope active!");
|
||||||
|
|
||||||
ScopedHashTableVal<K, V, KInfo> *&KeyEntry = TopLevelMap[Key];
|
ScopedHashTableVal<K, V> *&KeyEntry = TopLevelMap[Key];
|
||||||
|
|
||||||
KeyEntry = ValTy::Create(CurScope->getLastValInScope(), KeyEntry, Key, Val,
|
KeyEntry = ValTy::Create(CurScope->getLastValInScope(), KeyEntry, Key, Val,
|
||||||
Allocator);
|
Allocator);
|
||||||
@ -197,29 +198,28 @@ public:
|
|||||||
|
|
||||||
/// ScopedHashTableScope ctor - Install this as the current scope for the hash
|
/// ScopedHashTableScope ctor - Install this as the current scope for the hash
|
||||||
/// table.
|
/// table.
|
||||||
template <typename K, typename V, typename KInfo>
|
template <typename K, typename V, typename KInfo, typename Allocator>
|
||||||
ScopedHashTableScope<K, V, KInfo>::
|
ScopedHashTableScope<K, V, KInfo, Allocator>::
|
||||||
ScopedHashTableScope(ScopedHashTable<K, V, KInfo> &ht) : HT(ht) {
|
ScopedHashTableScope(ScopedHashTable<K, V, KInfo, Allocator> &ht) : HT(ht) {
|
||||||
PrevScope = HT.CurScope;
|
PrevScope = HT.CurScope;
|
||||||
HT.CurScope = this;
|
HT.CurScope = this;
|
||||||
LastValInScope = 0;
|
LastValInScope = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename K, typename V, typename KInfo>
|
template <typename K, typename V, typename KInfo, typename Allocator>
|
||||||
ScopedHashTableScope<K, V, KInfo>::~ScopedHashTableScope() {
|
ScopedHashTableScope<K, V, KInfo, Allocator>::~ScopedHashTableScope() {
|
||||||
assert(HT.CurScope == this && "Scope imbalance!");
|
assert(HT.CurScope == this && "Scope imbalance!");
|
||||||
HT.CurScope = PrevScope;
|
HT.CurScope = PrevScope;
|
||||||
|
|
||||||
// Pop and delete all values corresponding to this scope.
|
// Pop and delete all values corresponding to this scope.
|
||||||
while (ScopedHashTableVal<K, V, KInfo> *ThisEntry = LastValInScope) {
|
while (ScopedHashTableVal<K, V> *ThisEntry = LastValInScope) {
|
||||||
// Pop this value out of the TopLevelMap.
|
// Pop this value out of the TopLevelMap.
|
||||||
if (ThisEntry->getNextForKey() == 0) {
|
if (ThisEntry->getNextForKey() == 0) {
|
||||||
assert(HT.TopLevelMap[ThisEntry->getKey()] == ThisEntry &&
|
assert(HT.TopLevelMap[ThisEntry->getKey()] == ThisEntry &&
|
||||||
"Scope imbalance!");
|
"Scope imbalance!");
|
||||||
HT.TopLevelMap.erase(ThisEntry->getKey());
|
HT.TopLevelMap.erase(ThisEntry->getKey());
|
||||||
} else {
|
} else {
|
||||||
ScopedHashTableVal<K, V, KInfo> *&KeyEntry =
|
ScopedHashTableVal<K, V> *&KeyEntry = HT.TopLevelMap[ThisEntry->getKey()];
|
||||||
HT.TopLevelMap[ThisEntry->getKey()];
|
|
||||||
assert(KeyEntry == ThisEntry && "Scope imbalance!");
|
assert(KeyEntry == ThisEntry && "Scope imbalance!");
|
||||||
KeyEntry = ThisEntry->getNextForKey();
|
KeyEntry = ThisEntry->getNextForKey();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user