- Change Function's so that their argument list is populated when they are

constructed.  Before, external functions would have an empty argument list,
    now a Function ALWAYS has a populated argument list.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4149 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2002-10-13 20:57:00 +00:00
parent 0b16ae209a
commit 69da5cf261
9 changed files with 79 additions and 86 deletions

View File

@ -602,7 +602,7 @@ Module *RunVMAsmParser(const string &Filename, FILE *F) {
%union {
Module *ModuleVal;
Function *FunctionVal;
std::pair<Argument*, char*> *ArgVal;
std::pair<PATypeHolder*, char*> *ArgVal;
BasicBlock *BasicBlockVal;
TerminatorInst *TermInstVal;
Instruction *InstVal;
@ -612,7 +612,7 @@ Module *RunVMAsmParser(const string &Filename, FILE *F) {
PATypeHolder *TypeVal;
Value *ValueVal;
std::list<std::pair<Argument*,char*> > *ArgList;
std::vector<std::pair<PATypeHolder*,char*> > *ArgList;
std::vector<Value*> *ValueList;
std::list<PATypeHolder> *TypeList;
std::list<std::pair<Value*,
@ -1174,28 +1174,33 @@ ConstPool : ConstPool OptAssign CONST ConstVal {
OptVAR_ID : VAR_ID | /*empty*/ { $$ = 0; };
ArgVal : Types OptVAR_ID {
$$ = new pair<Argument*, char*>(new Argument(*$1), $2);
delete $1; // Delete the type handle..
if (*$1 == Type::VoidTy)
ThrowException("void typed arguments are invalid!");
$$ = new pair<PATypeHolder*, char*>($1, $2);
};
ArgListH : ArgVal ',' ArgListH {
$$ = $3;
$3->push_front(*$1);
delete $1;
ArgListH : ArgListH ',' ArgVal {
$$ = $1;
$1->push_back(*$3);
delete $3;
}
| ArgVal {
$$ = new list<pair<Argument*,char*> >();
$$->push_front(*$1);
$$ = new vector<pair<PATypeHolder*,char*> >();
$$->push_back(*$1);
delete $1;
}
| DOTDOTDOT {
$$ = new list<pair<Argument*, char*> >();
$$->push_front(pair<Argument*,char*>(new Argument(Type::VoidTy), 0));
};
ArgList : ArgListH {
$$ = $1;
}
| ArgListH ',' DOTDOTDOT {
$$ = $1;
$$->push_back(pair<PATypeHolder*, char*>(new PATypeHolder(Type::VoidTy),0));
}
| DOTDOTDOT {
$$ = new vector<pair<PATypeHolder*,char*> >();
$$->push_back(pair<PATypeHolder*, char*>(new PATypeHolder(Type::VoidTy),0));
}
| /* empty */ {
$$ = 0;
};
@ -1208,9 +1213,9 @@ FunctionHeaderH : OptInternal TypesV FuncName '(' ArgList ')' {
vector<const Type*> ParamTypeList;
if ($5)
for (list<pair<Argument*,char*> >::iterator I = $5->begin();
for (vector<pair<PATypeHolder*,char*> >::iterator I = $5->begin();
I != $5->end(); ++I)
ParamTypeList.push_back(I->first->getType());
ParamTypeList.push_back(I->first->get());
bool isVarArg = ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy;
if (isVarArg) ParamTypeList.pop_back();
@ -1253,25 +1258,25 @@ FunctionHeaderH : OptInternal TypesV FuncName '(' ArgList ')' {
CurMeth.FunctionStart(M);
// Add all of the arguments we parsed to the function...
if ($5 && !CurMeth.isDeclare) { // Is null if empty...
for (list<pair<Argument*, char*> >::iterator I = $5->begin();
I != $5->end(); ++I) {
if (setValueName(I->first, I->second)) { // Insert into symtab...
assert(0 && "No arg redef allowed!");
}
if ($5) { // Is null if empty...
if (isVarArg) { // Nuke the last entry
assert($5->back().first->get() == Type::VoidTy && $5->back().second == 0&&
"Not a varargs marker!");
delete $5->back().first;
$5->pop_back(); // Delete the last entry
}
Function::aiterator ArgIt = M->abegin();
for (vector<pair<PATypeHolder*, char*> >::iterator I = $5->begin();
I != $5->end(); ++I, ++ArgIt) {
delete I->first; // Delete the typeholder...
InsertValue(I->first);
M->getArgumentList().push_back(I->first);
if (setValueName(ArgIt, I->second)) // Insert arg into symtab...
assert(0 && "No arg redef allowed!");
InsertValue(ArgIt);
}
delete $5; // We're now done with the argument list
} else if ($5) {
// If we are a declaration, we should free the memory for the argument list!
for (list<pair<Argument*, char*> >::iterator I = $5->begin(), E = $5->end();
I != E; ++I) {
if (I->second) free(I->second); // Free the memory for the name...
delete I->first; // Free the unused function argument
}
delete $5; // Free the memory for the list itself
}
};

View File

@ -270,14 +270,13 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf,
BCR_TRACE(2, "METHOD TYPE: " << MTy << "\n");
const FunctionType::ParamTypes &Params = MTy->getParamTypes();
Function::aiterator AI = M->abegin();
for (FunctionType::ParamTypes::const_iterator It = Params.begin();
It != Params.end(); ++It) {
Argument *FA = new Argument(*It);
if (insertValue(FA, Values) == -1) {
It != Params.end(); ++It, ++AI) {
if (insertValue(AI, Values) == -1) {
Error = "Error reading method arguments!\n";
delete M; return true;
}
M->getArgumentList().push_back(FA);
}
while (Buf < EndBuf) {
@ -358,10 +357,6 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf,
// We don't need the placeholder anymore!
delete FunctionPHolder;
// If the method is empty, we don't need the method argument entries...
if (M->isExternal())
M->getArgumentList().clear();
ResolveReferencesToValue(M, MethSlot);
return false;

View File

@ -323,14 +323,13 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
map<const Value*, Value*> LocalMap; // Map for function local values
// Go through and convert function arguments over...
Function::aiterator DI = Dest->abegin();
for (Function::const_aiterator I = Src->abegin(), E = Src->aend();
I != E; ++I) {
// Create the new function argument and add to the dest function...
Argument *DFA = new Argument(I->getType(), I->getName());
Dest->getArgumentList().push_back(DFA);
I != E; ++I, ++DI) {
DI->setName(I->getName()); // Copy the name information over...
// Add a mapping to our local map
LocalMap.insert(std::make_pair(I, DFA));
LocalMap.insert(std::make_pair(I, DI));
}
// Loop over all of the basic blocks, copying the instructions over...

View File

@ -317,10 +317,10 @@ void MutateStructTypes::transformFunction(Function *m) {
Function *NewMeth = cast<Function>(GMI->second);
// Okay, first order of business, create the arguments...
for (Function::aiterator I = m->abegin(), E = m->aend(); I != E; ++I) {
Argument *NFA = new Argument(ConvertType(I->getType()), I->getName());
NewMeth->getArgumentList().push_back(NFA);
LocalValueMap[I] = NFA; // Keep track of value mapping
for (Function::aiterator I = m->abegin(), E = m->aend(),
DI = NewMeth->abegin(); I != E; ++I, ++DI) {
DI->setName(I->getName());
LocalValueMap[I] = DI; // Keep track of value mapping
}

View File

@ -323,14 +323,13 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
map<const Value*, Value*> LocalMap; // Map for function local values
// Go through and convert function arguments over...
Function::aiterator DI = Dest->abegin();
for (Function::const_aiterator I = Src->abegin(), E = Src->aend();
I != E; ++I) {
// Create the new function argument and add to the dest function...
Argument *DFA = new Argument(I->getType(), I->getName());
Dest->getArgumentList().push_back(DFA);
I != E; ++I, ++DI) {
DI->setName(I->getName()); // Copy the name information over...
// Add a mapping to our local map
LocalMap.insert(std::make_pair(I, DFA));
LocalMap.insert(std::make_pair(I, DI));
}
// Loop over all of the basic blocks, copying the instructions over...

View File

@ -607,17 +607,8 @@ void AssemblyWriter::printFunction(const Function *F) {
// Loop over the arguments, printing them...
const FunctionType *FT = F->getFunctionType();
if (!F->isExternal()) {
for(Function::const_aiterator I = F->abegin(), E = F->aend(); I != E; ++I)
printArgument(I);
} else {
// Loop over the arguments, printing them...
for (FunctionType::ParamTypes::const_iterator I = FT->getParamTypes().begin(),
E = FT->getParamTypes().end(); I != E; ++I) {
if (I != FT->getParamTypes().begin()) Out << ", ";
printType(*I);
}
}
for(Function::const_aiterator I = F->abegin(), E = F->aend(); I != E; ++I)
printArgument(I);
// Finish printing arguments...
if (FT->isVarArg()) {

View File

@ -61,7 +61,7 @@ void Argument::setName(const std::string &name, SymbolTable *ST) {
"Invalid symtab argument!");
if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this);
Value::setName(name);
if (P && hasName()) P->getSymbolTable()->insert(this);
if (P && hasName()) P->getSymbolTableSure()->insert(this);
}
void Argument::setParent(Function *parent) {
@ -86,6 +86,13 @@ Function::Function(const FunctionType *Ty, bool isInternal,
ArgumentList.setParent(this);
ParentSymTab = SymTab = 0;
// Create the arguments vector, all arguments start out unnamed.
for (unsigned i = 0, e = Ty->getNumParams(); i != e; ++i) {
assert(Ty->getParamType(i) != Type::VoidTy &&
"Cannot have void typed arguments!");
ArgumentList.push_back(new Argument(Ty->getParamType(i)));
}
// Make sure that we get added to a function
LeakDetector::addGarbageObject(this);

View File

@ -323,14 +323,13 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
map<const Value*, Value*> LocalMap; // Map for function local values
// Go through and convert function arguments over...
Function::aiterator DI = Dest->abegin();
for (Function::const_aiterator I = Src->abegin(), E = Src->aend();
I != E; ++I) {
// Create the new function argument and add to the dest function...
Argument *DFA = new Argument(I->getType(), I->getName());
Dest->getArgumentList().push_back(DFA);
I != E; ++I, ++DI) {
DI->setName(I->getName()); // Copy the name information over...
// Add a mapping to our local map
LocalMap.insert(std::make_pair(I, DFA));
LocalMap.insert(std::make_pair(I, DI));
}
// Loop over all of the basic blocks, copying the instructions over...

View File

@ -193,32 +193,30 @@ void Verifier::verifySymbolTable(SymbolTable *ST) {
// visitFunction - Verify that a function is ok.
//
void Verifier::visitFunction(Function &F) {
if (F.isExternal()) return;
verifySymbolTable(F.getSymbolTable());
// Check function arguments...
const FunctionType *FT = F.getFunctionType();
unsigned NumArgs = F.getArgumentList().size();
Assert2(!FT->isVarArg(), "Cannot define varargs functions in LLVM!", &F, FT);
Assert2(FT->getParamTypes().size() == NumArgs,
Assert2(FT->getNumParams() == NumArgs,
"# formal arguments must match # of arguments for function type!",
&F, FT);
// Check that the argument values match the function type for this function...
if (FT->getParamTypes().size() == NumArgs) {
unsigned i = 0;
for (Function::aiterator I = F.abegin(), E = F.aend(); I != E; ++I, ++i)
Assert2(I->getType() == FT->getParamType(i),
"Argument value does not match function argument type!",
I, FT->getParamType(i));
}
unsigned i = 0;
for (Function::aiterator I = F.abegin(), E = F.aend(); I != E; ++I, ++i)
Assert2(I->getType() == FT->getParamType(i),
"Argument value does not match function argument type!",
I, FT->getParamType(i));
// Check the entry node
BasicBlock *Entry = &F.getEntryNode();
Assert1(pred_begin(Entry) == pred_end(Entry),
"Entry block to function must not have predecessors!", Entry);
if (!F.isExternal()) {
verifySymbolTable(F.getSymbolTable());
// Check the entry node
BasicBlock *Entry = &F.getEntryNode();
Assert1(pred_begin(Entry) == pred_end(Entry),
"Entry block to function must not have predecessors!", Entry);
}
}