mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-14 09:38:40 +00:00
Simplify code. Do not allow functions to be redefined more than once.
Since the stupid '%X = const int 4' thing is gone, we can now simplify setValueNameMergingDuplicates a bit more. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14810 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e002694ce2
commit
66028f208e
@ -591,22 +591,17 @@ static void setValueName(Value *V, char *NameStr) {
|
|||||||
// allowed to be redefined in the specified context. If the name is a new name
|
// allowed to be redefined in the specified context. If the name is a new name
|
||||||
// for the typeplane, false is returned.
|
// for the typeplane, false is returned.
|
||||||
//
|
//
|
||||||
static bool setValueNameMergingDuplicates(Value *V, char *NameStr) {
|
static bool setValueNameMergingDuplicates(GlobalValue *V, char *NameStr) {
|
||||||
assert(V->getType() != Type::VoidTy && "Global or constant of type void?");
|
|
||||||
|
|
||||||
if (NameStr == 0) return false;
|
if (NameStr == 0) return false;
|
||||||
|
|
||||||
std::string Name(NameStr); // Copy string
|
std::string Name(NameStr); // Copy string
|
||||||
free(NameStr); // Free old string
|
free(NameStr); // Free old string
|
||||||
|
|
||||||
// FIXME: If we eliminated the function constant pool (which we should), this
|
SymbolTable &ST = CurModule.CurrentModule->getSymbolTable();
|
||||||
// would just unconditionally look at the module symtab.
|
|
||||||
SymbolTable &ST = inFunctionScope() ?
|
|
||||||
CurFun.CurrentFunction->getSymbolTable() :
|
|
||||||
CurModule.CurrentModule->getSymbolTable();
|
|
||||||
|
|
||||||
Value *Existing = ST.lookup(V->getType(), Name);
|
Value *Existing = ST.lookup(V->getType(), Name);
|
||||||
if (Existing) { // Inserting a name that is already defined???
|
if (Existing) { // Inserting a name that is already defined???
|
||||||
|
|
||||||
// We are a simple redefinition of a value, check to see if it is defined
|
// We are a simple redefinition of a value, check to see if it is defined
|
||||||
// the same as the old one...
|
// the same as the old one...
|
||||||
if (GlobalVariable *EGV = dyn_cast<GlobalVariable>(Existing)) {
|
if (GlobalVariable *EGV = dyn_cast<GlobalVariable>(Existing)) {
|
||||||
@ -630,8 +625,6 @@ static bool setValueNameMergingDuplicates(Value *V, char *NameStr) {
|
|||||||
return true; // They are equivalent!
|
return true; // They are equivalent!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (const Constant *C = dyn_cast<Constant>(Existing)) {
|
|
||||||
if (C == V) return true; // Constants are equal to themselves
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ThrowException("Redefinition of value named '" + Name + "' in the '" +
|
ThrowException("Redefinition of value named '" + Name + "' in the '" +
|
||||||
@ -1571,24 +1564,14 @@ FunctionHeaderH : TypesV Name '(' ArgList ')' {
|
|||||||
const PointerType *PFT = PointerType::get(FT);
|
const PointerType *PFT = PointerType::get(FT);
|
||||||
delete $1;
|
delete $1;
|
||||||
|
|
||||||
Function *Fn = 0;
|
|
||||||
// Is the function already in symtab?
|
// Is the function already in symtab?
|
||||||
if ((Fn = CurModule.CurrentModule->getFunction(FunctionName, FT))) {
|
if (CurModule.CurrentModule->getFunction(FunctionName, FT))
|
||||||
// Yes it is. If this is the case, either we need to be a forward decl,
|
ThrowException("Redefinition of function '" + FunctionName + "'!");
|
||||||
// or it needs to be.
|
|
||||||
if (!CurFun.isDeclare && !Fn->isExternal())
|
|
||||||
ThrowException("Redefinition of function '" + FunctionName + "'!");
|
|
||||||
|
|
||||||
// Make sure to strip off any argument names so we can't get conflicts...
|
Function *Fn = new Function(FT, GlobalValue::ExternalLinkage, FunctionName,
|
||||||
for (Function::aiterator AI = Fn->abegin(), AE = Fn->aend(); AI != AE; ++AI)
|
CurModule.CurrentModule);
|
||||||
AI->setName("");
|
InsertValue(Fn, CurModule.Values);
|
||||||
|
CurModule.DeclareNewGlobalValue(Fn, ValID::create($2));
|
||||||
} else { // Not already defined?
|
|
||||||
Fn = new Function(FT, GlobalValue::ExternalLinkage, FunctionName,
|
|
||||||
CurModule.CurrentModule);
|
|
||||||
InsertValue(Fn, CurModule.Values);
|
|
||||||
CurModule.DeclareNewGlobalValue(Fn, ValID::create($2));
|
|
||||||
}
|
|
||||||
free($2); // Free strdup'd memory!
|
free($2); // Free strdup'd memory!
|
||||||
|
|
||||||
CurFun.FunctionStart(Fn);
|
CurFun.FunctionStart(Fn);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user