mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 13:11:39 +01:00
- 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. llvm-svn: 4149
This commit is contained in:
parent
fdf2ca9468
commit
82f54dca49
@ -602,7 +602,7 @@ Module *RunVMAsmParser(const string &Filename, FILE *F) {
|
|||||||
%union {
|
%union {
|
||||||
Module *ModuleVal;
|
Module *ModuleVal;
|
||||||
Function *FunctionVal;
|
Function *FunctionVal;
|
||||||
std::pair<Argument*, char*> *ArgVal;
|
std::pair<PATypeHolder*, char*> *ArgVal;
|
||||||
BasicBlock *BasicBlockVal;
|
BasicBlock *BasicBlockVal;
|
||||||
TerminatorInst *TermInstVal;
|
TerminatorInst *TermInstVal;
|
||||||
Instruction *InstVal;
|
Instruction *InstVal;
|
||||||
@ -612,7 +612,7 @@ Module *RunVMAsmParser(const string &Filename, FILE *F) {
|
|||||||
PATypeHolder *TypeVal;
|
PATypeHolder *TypeVal;
|
||||||
Value *ValueVal;
|
Value *ValueVal;
|
||||||
|
|
||||||
std::list<std::pair<Argument*,char*> > *ArgList;
|
std::vector<std::pair<PATypeHolder*,char*> > *ArgList;
|
||||||
std::vector<Value*> *ValueList;
|
std::vector<Value*> *ValueList;
|
||||||
std::list<PATypeHolder> *TypeList;
|
std::list<PATypeHolder> *TypeList;
|
||||||
std::list<std::pair<Value*,
|
std::list<std::pair<Value*,
|
||||||
@ -1174,28 +1174,33 @@ ConstPool : ConstPool OptAssign CONST ConstVal {
|
|||||||
OptVAR_ID : VAR_ID | /*empty*/ { $$ = 0; };
|
OptVAR_ID : VAR_ID | /*empty*/ { $$ = 0; };
|
||||||
|
|
||||||
ArgVal : Types OptVAR_ID {
|
ArgVal : Types OptVAR_ID {
|
||||||
$$ = new pair<Argument*, char*>(new Argument(*$1), $2);
|
if (*$1 == Type::VoidTy)
|
||||||
delete $1; // Delete the type handle..
|
ThrowException("void typed arguments are invalid!");
|
||||||
|
$$ = new pair<PATypeHolder*, char*>($1, $2);
|
||||||
};
|
};
|
||||||
|
|
||||||
ArgListH : ArgVal ',' ArgListH {
|
ArgListH : ArgListH ',' ArgVal {
|
||||||
$$ = $3;
|
$$ = $1;
|
||||||
$3->push_front(*$1);
|
$1->push_back(*$3);
|
||||||
delete $1;
|
delete $3;
|
||||||
}
|
}
|
||||||
| ArgVal {
|
| ArgVal {
|
||||||
$$ = new list<pair<Argument*,char*> >();
|
$$ = new vector<pair<PATypeHolder*,char*> >();
|
||||||
$$->push_front(*$1);
|
$$->push_back(*$1);
|
||||||
delete $1;
|
delete $1;
|
||||||
}
|
|
||||||
| DOTDOTDOT {
|
|
||||||
$$ = new list<pair<Argument*, char*> >();
|
|
||||||
$$->push_front(pair<Argument*,char*>(new Argument(Type::VoidTy), 0));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ArgList : ArgListH {
|
ArgList : ArgListH {
|
||||||
$$ = $1;
|
$$ = $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 */ {
|
| /* empty */ {
|
||||||
$$ = 0;
|
$$ = 0;
|
||||||
};
|
};
|
||||||
@ -1208,9 +1213,9 @@ FunctionHeaderH : OptInternal TypesV FuncName '(' ArgList ')' {
|
|||||||
|
|
||||||
vector<const Type*> ParamTypeList;
|
vector<const Type*> ParamTypeList;
|
||||||
if ($5)
|
if ($5)
|
||||||
for (list<pair<Argument*,char*> >::iterator I = $5->begin();
|
for (vector<pair<PATypeHolder*,char*> >::iterator I = $5->begin();
|
||||||
I != $5->end(); ++I)
|
I != $5->end(); ++I)
|
||||||
ParamTypeList.push_back(I->first->getType());
|
ParamTypeList.push_back(I->first->get());
|
||||||
|
|
||||||
bool isVarArg = ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy;
|
bool isVarArg = ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy;
|
||||||
if (isVarArg) ParamTypeList.pop_back();
|
if (isVarArg) ParamTypeList.pop_back();
|
||||||
@ -1253,25 +1258,25 @@ FunctionHeaderH : OptInternal TypesV FuncName '(' ArgList ')' {
|
|||||||
CurMeth.FunctionStart(M);
|
CurMeth.FunctionStart(M);
|
||||||
|
|
||||||
// Add all of the arguments we parsed to the function...
|
// Add all of the arguments we parsed to the function...
|
||||||
if ($5 && !CurMeth.isDeclare) { // Is null if empty...
|
if ($5) { // Is null if empty...
|
||||||
for (list<pair<Argument*, char*> >::iterator I = $5->begin();
|
if (isVarArg) { // Nuke the last entry
|
||||||
I != $5->end(); ++I) {
|
assert($5->back().first->get() == Type::VoidTy && $5->back().second == 0&&
|
||||||
if (setValueName(I->first, I->second)) { // Insert into symtab...
|
"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...
|
||||||
|
|
||||||
|
if (setValueName(ArgIt, I->second)) // Insert arg into symtab...
|
||||||
assert(0 && "No arg redef allowed!");
|
assert(0 && "No arg redef allowed!");
|
||||||
}
|
|
||||||
|
|
||||||
InsertValue(I->first);
|
InsertValue(ArgIt);
|
||||||
M->getArgumentList().push_back(I->first);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete $5; // We're now done with the argument list
|
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
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -270,14 +270,13 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf,
|
|||||||
BCR_TRACE(2, "METHOD TYPE: " << MTy << "\n");
|
BCR_TRACE(2, "METHOD TYPE: " << MTy << "\n");
|
||||||
|
|
||||||
const FunctionType::ParamTypes &Params = MTy->getParamTypes();
|
const FunctionType::ParamTypes &Params = MTy->getParamTypes();
|
||||||
|
Function::aiterator AI = M->abegin();
|
||||||
for (FunctionType::ParamTypes::const_iterator It = Params.begin();
|
for (FunctionType::ParamTypes::const_iterator It = Params.begin();
|
||||||
It != Params.end(); ++It) {
|
It != Params.end(); ++It, ++AI) {
|
||||||
Argument *FA = new Argument(*It);
|
if (insertValue(AI, Values) == -1) {
|
||||||
if (insertValue(FA, Values) == -1) {
|
|
||||||
Error = "Error reading method arguments!\n";
|
Error = "Error reading method arguments!\n";
|
||||||
delete M; return true;
|
delete M; return true;
|
||||||
}
|
}
|
||||||
M->getArgumentList().push_back(FA);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (Buf < EndBuf) {
|
while (Buf < EndBuf) {
|
||||||
@ -358,10 +357,6 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf,
|
|||||||
// We don't need the placeholder anymore!
|
// We don't need the placeholder anymore!
|
||||||
delete FunctionPHolder;
|
delete FunctionPHolder;
|
||||||
|
|
||||||
// If the method is empty, we don't need the method argument entries...
|
|
||||||
if (M->isExternal())
|
|
||||||
M->getArgumentList().clear();
|
|
||||||
|
|
||||||
ResolveReferencesToValue(M, MethSlot);
|
ResolveReferencesToValue(M, MethSlot);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -317,10 +317,10 @@ void MutateStructTypes::transformFunction(Function *m) {
|
|||||||
Function *NewMeth = cast<Function>(GMI->second);
|
Function *NewMeth = cast<Function>(GMI->second);
|
||||||
|
|
||||||
// Okay, first order of business, create the arguments...
|
// Okay, first order of business, create the arguments...
|
||||||
for (Function::aiterator I = m->abegin(), E = m->aend(); I != E; ++I) {
|
for (Function::aiterator I = m->abegin(), E = m->aend(),
|
||||||
Argument *NFA = new Argument(ConvertType(I->getType()), I->getName());
|
DI = NewMeth->abegin(); I != E; ++I, ++DI) {
|
||||||
NewMeth->getArgumentList().push_back(NFA);
|
DI->setName(I->getName());
|
||||||
LocalValueMap[I] = NFA; // Keep track of value mapping
|
LocalValueMap[I] = DI; // Keep track of value mapping
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -323,14 +323,13 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
|
|||||||
map<const Value*, Value*> LocalMap; // Map for function local values
|
map<const Value*, Value*> LocalMap; // Map for function local values
|
||||||
|
|
||||||
// Go through and convert function arguments over...
|
// Go through and convert function arguments over...
|
||||||
|
Function::aiterator DI = Dest->abegin();
|
||||||
for (Function::const_aiterator I = Src->abegin(), E = Src->aend();
|
for (Function::const_aiterator I = Src->abegin(), E = Src->aend();
|
||||||
I != E; ++I) {
|
I != E; ++I, ++DI) {
|
||||||
// Create the new function argument and add to the dest function...
|
DI->setName(I->getName()); // Copy the name information over...
|
||||||
Argument *DFA = new Argument(I->getType(), I->getName());
|
|
||||||
Dest->getArgumentList().push_back(DFA);
|
|
||||||
|
|
||||||
// Add a mapping to our local map
|
// 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...
|
// Loop over all of the basic blocks, copying the instructions over...
|
||||||
|
@ -607,17 +607,8 @@ void AssemblyWriter::printFunction(const Function *F) {
|
|||||||
// Loop over the arguments, printing them...
|
// Loop over the arguments, printing them...
|
||||||
const FunctionType *FT = F->getFunctionType();
|
const FunctionType *FT = F->getFunctionType();
|
||||||
|
|
||||||
if (!F->isExternal()) {
|
for(Function::const_aiterator I = F->abegin(), E = F->aend(); I != E; ++I)
|
||||||
for(Function::const_aiterator I = F->abegin(), E = F->aend(); I != E; ++I)
|
printArgument(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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finish printing arguments...
|
// Finish printing arguments...
|
||||||
if (FT->isVarArg()) {
|
if (FT->isVarArg()) {
|
||||||
|
@ -61,7 +61,7 @@ void Argument::setName(const std::string &name, SymbolTable *ST) {
|
|||||||
"Invalid symtab argument!");
|
"Invalid symtab argument!");
|
||||||
if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this);
|
if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this);
|
||||||
Value::setName(name);
|
Value::setName(name);
|
||||||
if (P && hasName()) P->getSymbolTable()->insert(this);
|
if (P && hasName()) P->getSymbolTableSure()->insert(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Argument::setParent(Function *parent) {
|
void Argument::setParent(Function *parent) {
|
||||||
@ -86,6 +86,13 @@ Function::Function(const FunctionType *Ty, bool isInternal,
|
|||||||
ArgumentList.setParent(this);
|
ArgumentList.setParent(this);
|
||||||
ParentSymTab = SymTab = 0;
|
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
|
// Make sure that we get added to a function
|
||||||
LeakDetector::addGarbageObject(this);
|
LeakDetector::addGarbageObject(this);
|
||||||
|
|
||||||
|
@ -193,32 +193,30 @@ void Verifier::verifySymbolTable(SymbolTable *ST) {
|
|||||||
// visitFunction - Verify that a function is ok.
|
// visitFunction - Verify that a function is ok.
|
||||||
//
|
//
|
||||||
void Verifier::visitFunction(Function &F) {
|
void Verifier::visitFunction(Function &F) {
|
||||||
if (F.isExternal()) return;
|
|
||||||
|
|
||||||
verifySymbolTable(F.getSymbolTable());
|
|
||||||
|
|
||||||
// Check function arguments...
|
// Check function arguments...
|
||||||
const FunctionType *FT = F.getFunctionType();
|
const FunctionType *FT = F.getFunctionType();
|
||||||
unsigned NumArgs = F.getArgumentList().size();
|
unsigned NumArgs = F.getArgumentList().size();
|
||||||
|
|
||||||
Assert2(!FT->isVarArg(), "Cannot define varargs functions in LLVM!", &F, FT);
|
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!",
|
"# formal arguments must match # of arguments for function type!",
|
||||||
&F, FT);
|
&F, FT);
|
||||||
|
|
||||||
// Check that the argument values match the function type for this function...
|
// Check that the argument values match the function type for this function...
|
||||||
if (FT->getParamTypes().size() == NumArgs) {
|
unsigned i = 0;
|
||||||
unsigned i = 0;
|
for (Function::aiterator I = F.abegin(), E = F.aend(); I != E; ++I, ++i)
|
||||||
for (Function::aiterator I = F.abegin(), E = F.aend(); I != E; ++I, ++i)
|
Assert2(I->getType() == FT->getParamType(i),
|
||||||
Assert2(I->getType() == FT->getParamType(i),
|
"Argument value does not match function argument type!",
|
||||||
"Argument value does not match function argument type!",
|
I, FT->getParamType(i));
|
||||||
I, FT->getParamType(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check the entry node
|
if (!F.isExternal()) {
|
||||||
BasicBlock *Entry = &F.getEntryNode();
|
verifySymbolTable(F.getSymbolTable());
|
||||||
Assert1(pred_begin(Entry) == pred_end(Entry),
|
|
||||||
"Entry block to function must not have predecessors!", Entry);
|
// Check the entry node
|
||||||
|
BasicBlock *Entry = &F.getEntryNode();
|
||||||
|
Assert1(pred_begin(Entry) == pred_end(Entry),
|
||||||
|
"Entry block to function must not have predecessors!", Entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user