mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-02 07:32:52 +00:00
More symbol table bugfixes that are impossible to track down. Goody
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@960 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5855f0db2a
commit
e638c10cb0
@ -24,13 +24,8 @@
|
|||||||
#include "llvm/ConstPoolVals.h"
|
#include "llvm/ConstPoolVals.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class Value;
|
|
||||||
class Type;
|
class Type;
|
||||||
|
|
||||||
// TODO: Change this back to vector<map<const string, Value *> >
|
|
||||||
// Make the vector be a data member, and base it on UniqueID's
|
|
||||||
// That should be much more efficient!
|
|
||||||
//
|
|
||||||
class SymbolTable : public AbstractTypeUser,
|
class SymbolTable : public AbstractTypeUser,
|
||||||
public map<const Type *, map<const string, Value *> > {
|
public map<const Type *, map<const string, Value *> > {
|
||||||
public:
|
public:
|
||||||
@ -47,7 +42,10 @@ public:
|
|||||||
typedef VarMap::iterator type_iterator;
|
typedef VarMap::iterator type_iterator;
|
||||||
typedef VarMap::const_iterator type_const_iterator;
|
typedef VarMap::const_iterator type_const_iterator;
|
||||||
|
|
||||||
inline SymbolTable(SymbolTable *P = 0) { ParentSymTab = P; }
|
inline SymbolTable(SymbolTable *P = 0) {
|
||||||
|
ParentSymTab = P;
|
||||||
|
InternallyInconsistent = false;
|
||||||
|
}
|
||||||
~SymbolTable();
|
~SymbolTable();
|
||||||
|
|
||||||
SymbolTable *getParentSymTab() { return ParentSymTab; }
|
SymbolTable *getParentSymTab() { return ParentSymTab; }
|
||||||
@ -106,6 +104,15 @@ public:
|
|||||||
void dump() const; // Debug method, print out symbol table
|
void dump() const; // Debug method, print out symbol table
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// InternallyInconsistent - There are times when the symbol table is
|
||||||
|
// internally inconsistent with the rest of the program. In this one case, a
|
||||||
|
// value exists with a Name, and it's not in the symbol table. When we call
|
||||||
|
// V->setName(""), it tries to remove itself from the symbol table and dies.
|
||||||
|
// We know this is happening, and so if the flag InternallyInconsistent is
|
||||||
|
// set, removal from the symbol table is a noop.
|
||||||
|
//
|
||||||
|
bool InternallyInconsistent;
|
||||||
|
|
||||||
inline super::value_type operator[](const Type *Ty) {
|
inline super::value_type operator[](const Type *Ty) {
|
||||||
assert(0 && "Should not use this operator to access symbol table!");
|
assert(0 && "Should not use this operator to access symbol table!");
|
||||||
return super::value_type();
|
return super::value_type();
|
||||||
|
@ -80,6 +80,7 @@ void SymbolTable::remove(Value *N) {
|
|||||||
// removeEntry - Remove a value from the symbol table...
|
// removeEntry - Remove a value from the symbol table...
|
||||||
//
|
//
|
||||||
Value *SymbolTable::removeEntry(iterator Plane, type_iterator Entry) {
|
Value *SymbolTable::removeEntry(iterator Plane, type_iterator Entry) {
|
||||||
|
if (InternallyInconsistent) return 0;
|
||||||
assert(Plane != super::end() &&
|
assert(Plane != super::end() &&
|
||||||
Entry != Plane->second.end() && "Invalid entry to remove!");
|
Entry != Plane->second.end() && "Invalid entry to remove!");
|
||||||
|
|
||||||
@ -206,9 +207,10 @@ void SymbolTable::refineAbstractType(const DerivedType *OldType,
|
|||||||
// The only thing we are allowing for now is two method prototypes being
|
// The only thing we are allowing for now is two method prototypes being
|
||||||
// folded into one.
|
// folded into one.
|
||||||
//
|
//
|
||||||
if (Method *ExistM = dyn_cast<Method>(TI->second))
|
Method *ExistM = dyn_cast<Method>(TI->second);
|
||||||
if (Method *NewM = dyn_cast<Method>(V.second))
|
Method *NewM = dyn_cast<Method>(V.second);
|
||||||
if (ExistM->isExternal() && NewM->isExternal()) {
|
|
||||||
|
if (ExistM && NewM && ExistM->isExternal() && NewM->isExternal()) {
|
||||||
// Ok we have two external methods. Make all uses of the new one
|
// Ok we have two external methods. Make all uses of the new one
|
||||||
// use the old one...
|
// use the old one...
|
||||||
//
|
//
|
||||||
@ -218,25 +220,19 @@ void SymbolTable::refineAbstractType(const DerivedType *OldType,
|
|||||||
// added to our symbol table. The problem is that if we call
|
// added to our symbol table. The problem is that if we call
|
||||||
// setName on the method that it will try to remove itself from
|
// setName on the method that it will try to remove itself from
|
||||||
// the symbol table and die... because it's not in the symtab
|
// the symbol table and die... because it's not in the symtab
|
||||||
// right now. To fix this, we temporarily insert it (by setting
|
// right now. To fix this, we have an internally consistent flag
|
||||||
// TI's entry to the old value. Then after it is removed, we
|
// that turns remove into a noop. Thus the name will get null'd
|
||||||
// restore ExistM into the symbol table.
|
// out, but the symbol table won't get upset.
|
||||||
//
|
//
|
||||||
if (NewM->getType() == NewType) {
|
InternallyInconsistent = true;
|
||||||
TI->second = NewM; // Add newM to the symtab
|
|
||||||
|
|
||||||
// Remove newM from the symtab
|
// Remove newM from the symtab
|
||||||
NewM->setName("");
|
NewM->setName("");
|
||||||
|
InternallyInconsistent = false;
|
||||||
// Readd ExistM to the symbol table....
|
|
||||||
NewPlane.insert(make_pair(V.first, ExistM));
|
|
||||||
} else {
|
} else {
|
||||||
NewM->setName("");
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
assert(0 && "Two ploanes folded together with overlapping "
|
assert(0 && "Two ploanes folded together with overlapping "
|
||||||
"value names!");
|
"value names!");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
insertEntry(V.first, NewType, V.second);
|
insertEntry(V.first, NewType, V.second);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user