cast { RET_TOK(OtherOpVal, Cast, CAST); }
shl { RET_TOK(OtherOpVal, Shl, SHL); }
shr { RET_TOK(OtherOpVal, Shr, SHR); }
+va_arg { RET_TOK(OtherOpVal, VarArg, VA_ARG); }
ret { RET_TOK(TermOpVal, Ret, RET); }
br { RET_TOK(TermOpVal, Br, BR); }
// Other Operators
%type <OtherOpVal> ShiftOps
-%token <OtherOpVal> PHI CALL INVOKE CAST SHL SHR
+%token <OtherOpVal> PHI CALL INVOKE CAST SHL SHR VA_ARG
%start Module
%%
$$ = new CastInst($2, *$4);
delete $4;
}
+ | VA_ARG ResolvedVal ',' Types {
+ $$ = new VarArgInst($2, *$4);
+ delete $4;
+ }
| PHI PHIList {
const Type *Ty = $2->front().first->getType();
$$ = new PHINode(Ty);
Value *V;
switch (Raw.Opcode) {
+ case Instruction::VarArg:
case Instruction::Cast: {
V = getValue(Raw.Ty, Raw.Arg1);
const Type *Ty = getType(Raw.Arg2);
if (V == 0 || Ty == 0) { std::cerr << "Invalid cast!\n"; return true; }
- Res = new CastInst(V, Ty);
+ if (Raw.Opcode == Instruction::Cast)
+ Res = new CastInst(V, Ty);
+ else
+ Res = new VarArgInst(V, Ty);
return false;
}
case Instruction::PHINode: {
output_vbr(Type, Out); // Result type
unsigned NumArgs = I->getNumOperands();
- output_vbr(NumArgs + isa<CastInst>(I), Out);
+ output_vbr(NumArgs + (isa<CastInst>(I) || isa<VarArgInst>(I)), Out);
for (unsigned i = 0; i < NumArgs; ++i) {
int Slot = Table.getValSlot(I->getOperand(i));
output_vbr((unsigned)Slot, Out);
}
- if (isa<CastInst>(I)) {
+ if (isa<CastInst>(I) || isa<VarArgInst>(I)) {
int Slot = Table.getValSlot(I->getType());
- assert(Slot != -1 && "Cast return type unknown?");
+ assert(Slot != -1 && "Cast/VarArg return type unknown?");
output_vbr((unsigned)Slot, Out);
}
if (Slot > MaxOpSlot) MaxOpSlot = Slot;
// Handle the special case for cast...
- if (isa<CastInst>(I)) {
+ if (isa<CastInst>(I) || isa<VarArgInst>(I)) {
// Cast has to encode the destination type as the second argument in the
// packet, or else we won't know what type to cast to!
Slots[1] = Table.getValSlot(I.getType());
// This library implements the functionality defined in llvm/Assembly/Writer.h
//
// Note that these routines must be extremely tolerant of various errors in the
-// LLVM code, because of of the primary uses of it is for debugging
-// transformations.
+// LLVM code, because it can be used for debugging transformations.
//
//===----------------------------------------------------------------------===//
writeOperand(AI->getArraySize(), true);
}
} else if (isa<CastInst>(I)) {
- if (Operand) writeOperand(Operand, true);
+ writeOperand(Operand, true);
Out << " to ";
printType(I.getType());
+ } else if (isa<VarArgInst>(I)) {
+ writeOperand(Operand, true);
+ Out << ", ";
+ printType(I.getType());
} else if (Operand) { // Print the normal way...
// PrintAllTypes - Instructions who have operands of all the same type
case Call: return "call";
case Shl: return "shl";
case Shr: return "shr";
-
+ case VarArg: return "va_arg";
+
default: return "<Invalid operator> ";
}
void visitPHINode(PHINode &PN);
void visitBinaryOperator(BinaryOperator &B);
void visitShiftInst(ShiftInst &SI);
+ void visitVarArgInst(VarArgInst &VAI);
void visitCallInst(CallInst &CI);
void visitGetElementPtrInst(GetElementPtrInst &GEP);
void visitLoadInst(LoadInst &LI);
visitInstruction(SI);
}
-
+void Verifier::visitVarArgInst(VarArgInst &VAI) {
+ Assert1(VAI.getParent()->getParent()->getFunctionType()->isVarArg(),
+ "va_arg instruction may only occur in function with variable args!",
+ &VAI);
+ visitInstruction(VAI);
+}
void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
const Type *ElTy =