[llvm-commits] CVS: llvm/lib/AsmParser/llvmAsmParser.y
Chris Lattner
lattner at cs.uiuc.edu
Sun Oct 13 15:54:01 PDT 2002
Changes in directory llvm/lib/AsmParser:
llvmAsmParser.y updated: 1.95 -> 1.96
---
Log message:
- 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.
---
Diffs of the changes:
Index: llvm/lib/AsmParser/llvmAsmParser.y
diff -u llvm/lib/AsmParser/llvmAsmParser.y:1.95 llvm/lib/AsmParser/llvmAsmParser.y:1.96
--- llvm/lib/AsmParser/llvmAsmParser.y:1.95 Tue Oct 8 19:25:32 2002
+++ llvm/lib/AsmParser/llvmAsmParser.y Sun Oct 13 15:53:08 2002
@@ -602,7 +602,7 @@
%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 @@
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 @@
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 @@
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 @@
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...
+ 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...
+
+ 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<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
}
};
More information about the llvm-commits
mailing list