diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 8613a413ca4..52ef6907f29 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -602,7 +602,7 @@ Module *RunVMAsmParser(const string &Filename, FILE *F) { %union { Module *ModuleVal; Function *FunctionVal; - std::pair *ArgVal; + std::pair *ArgVal; BasicBlock *BasicBlockVal; TerminatorInst *TermInstVal; Instruction *InstVal; @@ -612,7 +612,7 @@ Module *RunVMAsmParser(const string &Filename, FILE *F) { PATypeHolder *TypeVal; Value *ValueVal; - std::list > *ArgList; + std::vector > *ArgList; std::vector *ValueList; std::list *TypeList; std::list(new Argument(*$1), $2); - delete $1; // Delete the type handle.. + if (*$1 == Type::VoidTy) + ThrowException("void typed arguments are invalid!"); + $$ = new pair($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 >(); - $$->push_front(*$1); + $$ = new vector >(); + $$->push_back(*$1); delete $1; - } - | DOTDOTDOT { - $$ = new list >(); - $$->push_front(pair(new Argument(Type::VoidTy), 0)); }; ArgList : ArgListH { $$ = $1; } + | ArgListH ',' DOTDOTDOT { + $$ = $1; + $$->push_back(pair(new PATypeHolder(Type::VoidTy),0)); + } + | DOTDOTDOT { + $$ = new vector >(); + $$->push_back(pair(new PATypeHolder(Type::VoidTy),0)); + } | /* empty */ { $$ = 0; }; @@ -1208,9 +1213,9 @@ FunctionHeaderH : OptInternal TypesV FuncName '(' ArgList ')' { vector ParamTypeList; if ($5) - for (list >::iterator I = $5->begin(); + for (vector >::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 >::iterator I = $5->begin(); - I != $5->end(); ++I) { - if (setValueName(I->first, I->second)) { // Insert into symtab... + 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 >::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!"); - } - InsertValue(I->first); - M->getArgumentList().push_back(I->first); + 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 >::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 } }; diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index 22b15924d26..9898af93187 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -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; diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 6753f51657c..8fe9113d821 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -323,14 +323,13 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src, map 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... diff --git a/lib/Transforms/IPO/MutateStructTypes.cpp b/lib/Transforms/IPO/MutateStructTypes.cpp index 7f62f2b50e1..483fba56784 100644 --- a/lib/Transforms/IPO/MutateStructTypes.cpp +++ b/lib/Transforms/IPO/MutateStructTypes.cpp @@ -317,10 +317,10 @@ void MutateStructTypes::transformFunction(Function *m) { Function *NewMeth = cast(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 } diff --git a/lib/Transforms/Utils/Linker.cpp b/lib/Transforms/Utils/Linker.cpp index 6753f51657c..8fe9113d821 100644 --- a/lib/Transforms/Utils/Linker.cpp +++ b/lib/Transforms/Utils/Linker.cpp @@ -323,14 +323,13 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src, map 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... diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index f43fda9087d..e27bd26ba27 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -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()) { diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index d7e8bea9ddc..d03a72a81ab 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -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); diff --git a/lib/VMCore/Linker.cpp b/lib/VMCore/Linker.cpp index 6753f51657c..8fe9113d821 100644 --- a/lib/VMCore/Linker.cpp +++ b/lib/VMCore/Linker.cpp @@ -323,14 +323,13 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src, map 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... diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index b01b5efc847..da3449b95c0 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -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); + } }