#include "llvm/Instructions.h"
#include "llvm/Module.h"
#include "llvm/SymbolTable.h"
-#include "llvm/Assembly/AutoUpgrade.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/MathExtras.h"
+#include "llvm/Support/Streams.h"
#include <algorithm>
-#include <iostream>
#include <list>
#include <utility>
// immediately invokes YYERROR. This would be so much cleaner if it was a
// recursive descent parser.
static bool TriggerError = false;
-#define CHECK_FOR_ERROR { if (TriggerError) { TriggerError = false; YYERROR; } }
+#define CHECK_FOR_ERROR { if (TriggerError) { TriggerError = false; YYABORT; } }
#define GEN_ERROR(msg) { GenerateError(msg); YYERROR; }
int yyerror(const char *ErrorMsg); // Forward declarations to prevent "implicit
//
//#define DEBUG_UPREFS 1
#ifdef DEBUG_UPREFS
-#define UR_OUT(X) std::cerr << X
+#define UR_OUT(X) llvm_cerr << X
#else
#define UR_OUT(X)
#endif
#define YYERROR_VERBOSE 1
-static bool ObsoleteVarArgs;
static bool NewVarArgs;
-static BasicBlock *CurBB;
static GlobalVariable *CurGV;
return;
}
- // Look for intrinsic functions and CallInst that need to be upgraded
- for (Module::iterator FI = CurrentModule->begin(),
- FE = CurrentModule->end(); FI != FE; )
- UpgradeCallsToIntrinsic(FI++);
-
Values.clear(); // Clear out function local definitions
Types.clear();
CurrentModule = 0;
// Check to make sure that "Ty" is an integral type, and that our
// value will fit into the specified type...
case ValID::ConstSIntVal: // Is it a constant pool reference??
- if (!ConstantSInt::isValueValidForType(Ty, D.ConstPool64)) {
+ if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
GenerateError("Signed integral constant '" +
itostr(D.ConstPool64) + "' is invalid for type '" +
Ty->getDescription() + "'!");
return 0;
}
- return ConstantSInt::get(Ty, D.ConstPool64);
+ return ConstantInt::get(Ty, D.ConstPool64);
case ValID::ConstUIntVal: // Is it an unsigned const pool reference?
- if (!ConstantUInt::isValueValidForType(Ty, D.UConstPool64)) {
- if (!ConstantSInt::isValueValidForType(Ty, D.ConstPool64)) {
+ if (!ConstantInt::isValueValidForType(Ty, D.UConstPool64)) {
+ if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
GenerateError("Integral constant '" + utostr(D.UConstPool64) +
"' is invalid or out of range!");
return 0;
} else { // This is really a signed reference. Transmogrify.
- return ConstantSInt::get(Ty, D.ConstPool64);
+ return ConstantInt::get(Ty, D.ConstPool64);
}
} else {
- return ConstantUInt::get(Ty, D.UConstPool64);
+ return ConstantInt::get(Ty, D.UConstPool64);
}
case ValID::ConstFPVal: // Is it a floating point const pool reference?
return Ty;
}
-
// common code from the two 'RunVMAsmParser' functions
static Module* RunParser(Module * M) {
llvmAsmlineno = 1; // Reset the current line number...
- ObsoleteVarArgs = false;
NewVarArgs = false;
-
CurModule.CurrentModule = M;
- yyparse(); // Parse the file, potentially throwing exception
- if (!ParserResult)
- return 0;
-
- Module *Result = ParserResult;
- ParserResult = 0;
-
- //Not all functions use vaarg, so make a second check for ObsoleteVarArgs
- {
- Function* F;
- if ((F = Result->getNamedFunction("llvm.va_start"))
- && F->getFunctionType()->getNumParams() == 0)
- ObsoleteVarArgs = true;
- if((F = Result->getNamedFunction("llvm.va_copy"))
- && F->getFunctionType()->getNumParams() == 1)
- ObsoleteVarArgs = true;
- }
- if (ObsoleteVarArgs && NewVarArgs) {
- GenerateError(
- "This file is corrupt: it uses both new and old style varargs");
+ // Check to make sure the parser succeeded
+ if (yyparse()) {
+ if (ParserResult)
+ delete ParserResult;
return 0;
}
- if(ObsoleteVarArgs) {
- if(Function* F = Result->getNamedFunction("llvm.va_start")) {
- if (F->arg_size() != 0) {
- GenerateError("Obsolete va_start takes 0 argument!");
- return 0;
- }
-
- //foo = va_start()
- // ->
- //bar = alloca typeof(foo)
- //va_start(bar)
- //foo = load bar
-
- const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
- const Type* ArgTy = F->getFunctionType()->getReturnType();
- const Type* ArgTyPtr = PointerType::get(ArgTy);
- Function* NF = Result->getOrInsertFunction("llvm.va_start",
- RetTy, ArgTyPtr, (Type *)0);
-
- while (!F->use_empty()) {
- CallInst* CI = cast<CallInst>(F->use_back());
- AllocaInst* bar = new AllocaInst(ArgTy, 0, "vastart.fix.1", CI);
- new CallInst(NF, bar, "", CI);
- Value* foo = new LoadInst(bar, "vastart.fix.2", CI);
- CI->replaceAllUsesWith(foo);
- CI->getParent()->getInstList().erase(CI);
- }
- Result->getFunctionList().erase(F);
- }
-
- if(Function* F = Result->getNamedFunction("llvm.va_end")) {
- if(F->arg_size() != 1) {
- GenerateError("Obsolete va_end takes 1 argument!");
- return 0;
- }
-
- //vaend foo
- // ->
- //bar = alloca 1 of typeof(foo)
- //vaend bar
- const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
- const Type* ArgTy = F->getFunctionType()->getParamType(0);
- const Type* ArgTyPtr = PointerType::get(ArgTy);
- Function* NF = Result->getOrInsertFunction("llvm.va_end",
- RetTy, ArgTyPtr, (Type *)0);
-
- while (!F->use_empty()) {
- CallInst* CI = cast<CallInst>(F->use_back());
- AllocaInst* bar = new AllocaInst(ArgTy, 0, "vaend.fix.1", CI);
- new StoreInst(CI->getOperand(1), bar, CI);
- new CallInst(NF, bar, "", CI);
- CI->getParent()->getInstList().erase(CI);
- }
- Result->getFunctionList().erase(F);
- }
+ // Check to make sure that parsing produced a result
+ if (!ParserResult)
+ return 0;
- if(Function* F = Result->getNamedFunction("llvm.va_copy")) {
- if(F->arg_size() != 1) {
- GenerateError("Obsolete va_copy takes 1 argument!");
- return 0;
- }
- //foo = vacopy(bar)
- // ->
- //a = alloca 1 of typeof(foo)
- //b = alloca 1 of typeof(foo)
- //store bar -> b
- //vacopy(a, b)
- //foo = load a
-
- const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
- const Type* ArgTy = F->getFunctionType()->getReturnType();
- const Type* ArgTyPtr = PointerType::get(ArgTy);
- Function* NF = Result->getOrInsertFunction("llvm.va_copy",
- RetTy, ArgTyPtr, ArgTyPtr,
- (Type *)0);
-
- while (!F->use_empty()) {
- CallInst* CI = cast<CallInst>(F->use_back());
- AllocaInst* a = new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI);
- AllocaInst* b = new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI);
- new StoreInst(CI->getOperand(1), b, CI);
- new CallInst(NF, a, b, "", CI);
- Value* foo = new LoadInst(a, "vacopy.fix.3", CI);
- CI->replaceAllUsesWith(foo);
- CI->getParent()->getInstList().erase(CI);
- }
- Result->getFunctionList().erase(F);
- }
- }
+ // Reset ParserResult variable while saving its value for the result.
+ Module *Result = ParserResult;
+ ParserResult = 0;
return Result;
}
bool BoolVal;
char *StrVal; // This memory is strdup'd!
- llvm::ValID ValIDVal; // strdup'd memory maybe!
-
- llvm::Instruction::BinaryOps BinaryOpVal;
- llvm::Instruction::TermOps TermOpVal;
- llvm::Instruction::MemoryOps MemOpVal;
- llvm::Instruction::OtherOps OtherOpVal;
- llvm::Module::Endianness Endianness;
+ llvm::ValID ValIDVal; // strdup'd memory maybe!
+
+ llvm::Instruction::BinaryOps BinaryOpVal;
+ llvm::Instruction::TermOps TermOpVal;
+ llvm::Instruction::MemoryOps MemOpVal;
+ llvm::Instruction::CastOps CastOpVal;
+ llvm::Instruction::OtherOps OtherOpVal;
+ llvm::Module::Endianness Endianness;
+ llvm::ICmpInst::Predicate IPredicate;
+ llvm::FCmpInst::Predicate FPredicate;
}
%type <ModuleVal> Module FunctionList
%token DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT
%token CC_TOK CCC_TOK CSRETCC_TOK FASTCC_TOK COLDCC_TOK
%token X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
+%token DATALAYOUT
%type <UIntVal> OptCallingConv
// Basic Block Terminating Operators
// Binary Operators
%type <BinaryOpVal> ArithmeticOps LogicalOps SetCondOps // Binops Subcatagories
-%token <BinaryOpVal> ADD SUB MUL DIV REM AND OR XOR
-%token <BinaryOpVal> SETLE SETGE SETLT SETGT SETEQ SETNE // Binary Comarators
+%token <BinaryOpVal> ADD SUB MUL UDIV SDIV FDIV UREM SREM FREM AND OR XOR
+%token <BinaryOpVal> SETLE SETGE SETLT SETGT SETEQ SETNE // Binary Comparators
+%token <OtherOpVal> ICMP FCMP
+%type <IPredicate> IPredicates
+%type <FPredicate> FPredicates
+%token EQ NE SLT SGT SLE SGE ULT UGT ULE UGE
+%token OEQ ONE OLT OGT OLE OGE ORD UNO UEQ UNE
// Memory Instructions
%token <MemOpVal> MALLOC ALLOCA FREE LOAD STORE GETELEMENTPTR
+// Cast Operators
+%type <CastOpVal> CastOps
+%token <CastOpVal> TRUNC ZEXT SEXT FPTRUNC FPEXT BITCAST
+%token <CastOpVal> UITOFP SITOFP FPTOUI FPTOSI INTTOPTR PTRTOINT
+
// Other Operators
%type <OtherOpVal> ShiftOps
-%token <OtherOpVal> PHI_TOK CAST SELECT SHL SHR VAARG
+%token <OtherOpVal> PHI_TOK SELECT SHL LSHR ASHR VAARG
%token <OtherOpVal> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
-%token VAARG_old VANEXT_old //OBSOLETE
%start Module
// Operations that are notably excluded from this list include:
// RET, BR, & SWITCH because they end basic blocks and are treated specially.
//
-ArithmeticOps: ADD | SUB | MUL | DIV | REM;
+ArithmeticOps: ADD | SUB | MUL | UDIV | SDIV | FDIV | UREM | SREM | FREM;
LogicalOps : AND | OR | XOR;
SetCondOps : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE;
-
-ShiftOps : SHL | SHR;
+CastOps : TRUNC | ZEXT | SEXT | FPTRUNC | FPEXT | BITCAST |
+ UITOFP | SITOFP | FPTOUI | FPTOSI | INTTOPTR | PTRTOINT;
+ShiftOps : SHL | LSHR | ASHR;
+IPredicates
+ : EQ { $$ = ICmpInst::ICMP_EQ; } | NE { $$ = ICmpInst::ICMP_NE; }
+ | SLT { $$ = ICmpInst::ICMP_SLT; } | SGT { $$ = ICmpInst::ICMP_SGT; }
+ | SLE { $$ = ICmpInst::ICMP_SLE; } | SGE { $$ = ICmpInst::ICMP_SGE; }
+ | ULT { $$ = ICmpInst::ICMP_ULT; } | UGT { $$ = ICmpInst::ICMP_UGT; }
+ | ULE { $$ = ICmpInst::ICMP_ULE; } | UGE { $$ = ICmpInst::ICMP_UGE; }
+ ;
+
+FPredicates
+ : OEQ { $$ = FCmpInst::FCMP_OEQ; } | ONE { $$ = FCmpInst::FCMP_ONE; }
+ | OLT { $$ = FCmpInst::FCMP_OLT; } | OGT { $$ = FCmpInst::FCMP_OGT; }
+ | OLE { $$ = FCmpInst::FCMP_OLE; } | OGE { $$ = FCmpInst::FCMP_OGE; }
+ | ORD { $$ = FCmpInst::FCMP_ORD; } | UNO { $$ = FCmpInst::FCMP_UNO; }
+ | UEQ { $$ = FCmpInst::FCMP_UEQ; } | UNE { $$ = FCmpInst::FCMP_UNE; }
+ | ULT { $$ = FCmpInst::FCMP_ULT; } | UGT { $$ = FCmpInst::FCMP_UGT; }
+ | ULE { $$ = FCmpInst::FCMP_ULE; } | UGE { $$ = FCmpInst::FCMP_UGE; }
+ | TRUETOK { $$ = FCmpInst::FCMP_TRUE; }
+ | FALSETOK { $$ = FCmpInst::FCMP_FALSE; }
+ ;
// These are some types that allow classification if we only want a particular
// thing... for example, only a signed, unsigned, or integral type.
CHECK_FOR_ERROR
}
| UpRTypes '*' { // Pointer type?
+ if (*$1 == Type::LabelTy)
+ GEN_ERROR("Cannot form a pointer to a basic block");
$$ = new PATypeHolder(HandleUpRefs(PointerType::get(*$1)));
delete $1;
CHECK_FOR_ERROR
std::vector<Constant*> Vals;
if (ETy == Type::SByteTy) {
for (signed char *C = (signed char *)$3; C != (signed char *)EndStr; ++C)
- Vals.push_back(ConstantSInt::get(ETy, *C));
+ Vals.push_back(ConstantInt::get(ETy, *C));
} else if (ETy == Type::UByteTy) {
for (unsigned char *C = (unsigned char *)$3;
C != (unsigned char*)EndStr; ++C)
- Vals.push_back(ConstantUInt::get(ETy, *C));
+ Vals.push_back(ConstantInt::get(ETy, *C));
} else {
free($3);
GEN_ERROR("Cannot build string arrays of non byte sized elements!");
$$ = Constant::getNullValue(Ty);
delete $1;
CHECK_FOR_ERROR
- };
-
-ConstVal : SIntType EINT64VAL { // integral constants
- if (!ConstantSInt::isValueValidForType($1, $2))
+ }
+ | SIntType EINT64VAL { // integral constants
+ if (!ConstantInt::isValueValidForType($1, $2))
GEN_ERROR("Constant value doesn't fit in type!");
- $$ = ConstantSInt::get($1, $2);
+ $$ = ConstantInt::get($1, $2);
CHECK_FOR_ERROR
}
| UIntType EUINT64VAL { // integral constants
- if (!ConstantUInt::isValueValidForType($1, $2))
+ if (!ConstantInt::isValueValidForType($1, $2))
GEN_ERROR("Constant value doesn't fit in type!");
- $$ = ConstantUInt::get($1, $2);
+ $$ = ConstantInt::get($1, $2);
CHECK_FOR_ERROR
}
| BOOL TRUETOK { // Boolean constants
};
-ConstExpr: CAST '(' ConstVal TO Types ')' {
- if (!$3->getType()->isFirstClassType())
+ConstExpr: CastOps '(' ConstVal TO Types ')' {
+ Constant *Val = $3;
+ const Type *Ty = $5->get();
+ if (!Val->getType()->isFirstClassType())
GEN_ERROR("cast constant expression from a non-primitive type: '" +
- $3->getType()->getDescription() + "'!");
- if (!$5->get()->isFirstClassType())
+ Val->getType()->getDescription() + "'!");
+ if (!Ty->isFirstClassType())
GEN_ERROR("cast constant expression to a non-primitive type: '" +
- $5->get()->getDescription() + "'!");
- $$ = ConstantExpr::getCast($3, $5->get());
+ Ty->getDescription() + "'!");
+ $$ = ConstantExpr::getCast($1, $3, $5->get());
delete $5;
- CHECK_FOR_ERROR
}
| GETELEMENTPTR '(' ConstVal IndexList ')' {
if (!isa<PointerType>($3->getType()))
GEN_ERROR("GetElementPtr requires a pointer operand!");
- // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte struct
- // indices to uint struct indices for compatibility.
- generic_gep_type_iterator<std::vector<Value*>::iterator>
- GTI = gep_type_begin($3->getType(), $4->begin(), $4->end()),
- GTE = gep_type_end($3->getType(), $4->begin(), $4->end());
- for (unsigned i = 0, e = $4->size(); i != e && GTI != GTE; ++i, ++GTI)
- if (isa<StructType>(*GTI)) // Only change struct indices
- if (ConstantUInt *CUI = dyn_cast<ConstantUInt>((*$4)[i]))
- if (CUI->getType() == Type::UByteTy)
- (*$4)[i] = ConstantExpr::getCast(CUI, Type::UIntTy);
-
const Type *IdxTy =
GetElementPtrInst::getIndexedType($3->getType(), *$4, true);
if (!IdxTy)
| ArithmeticOps '(' ConstVal ',' ConstVal ')' {
if ($3->getType() != $5->getType())
GEN_ERROR("Binary operator types must match!");
- // HACK: llvm 1.3 and earlier used to emit invalid pointer constant exprs.
- // To retain backward compatibility with these early compilers, we emit a
- // cast to the appropriate integer type automatically if we are in the
- // broken case. See PR424 for more information.
- if (!isa<PointerType>($3->getType())) {
- $$ = ConstantExpr::get($1, $3, $5);
- } else {
- const Type *IntPtrTy = 0;
- switch (CurModule.CurrentModule->getPointerSize()) {
- case Module::Pointer32: IntPtrTy = Type::IntTy; break;
- case Module::Pointer64: IntPtrTy = Type::LongTy; break;
- default: GEN_ERROR("invalid pointer binary constant expr!");
- }
- $$ = ConstantExpr::get($1, ConstantExpr::getCast($3, IntPtrTy),
- ConstantExpr::getCast($5, IntPtrTy));
- $$ = ConstantExpr::getCast($$, $3->getType());
- }
- CHECK_FOR_ERROR
+ CHECK_FOR_ERROR;
+ $$ = ConstantExpr::get($1, $3, $5);
}
| LogicalOps '(' ConstVal ',' ConstVal ')' {
if ($3->getType() != $5->getType())
$$ = ConstantExpr::get($1, $3, $5);
CHECK_FOR_ERROR
}
+ | ICMP IPredicates '(' ConstVal ',' ConstVal ')' {
+ if ($4->getType() != $6->getType())
+ GEN_ERROR("icmp operand types must match!");
+ $$ = ConstantExpr::getICmp($2, $4, $6);
+ }
+ | FCMP FPredicates '(' ConstVal ',' ConstVal ')' {
+ if ($4->getType() != $6->getType())
+ GEN_ERROR("fcmp operand types must match!");
+ $$ = ConstantExpr::getFCmp($2, $4, $6);
+ }
| ShiftOps '(' ConstVal ',' ConstVal ')' {
if ($5->getType() != Type::UByteTy)
GEN_ERROR("Shift count for shift constant must be unsigned byte!");
if (!$3->getType()->isInteger())
GEN_ERROR("Shift constant expression requires integer operand!");
+ CHECK_FOR_ERROR;
$$ = ConstantExpr::get($1, $3, $5);
CHECK_FOR_ERROR
}
Module : FunctionList {
$$ = ParserResult = $1;
CurModule.ModuleDone();
- CHECK_FOR_ERROR
+ CHECK_FOR_ERROR;
};
// FunctionList - A list of functions, preceeded by a constant pool.
| TRIPLE '=' STRINGCONSTANT {
CurModule.CurrentModule->setTargetTriple($3);
free($3);
- CHECK_FOR_ERROR
+ }
+ | DATALAYOUT '=' STRINGCONSTANT {
+ CurModule.CurrentModule->setDataLayout($3);
+ free($3);
};
LibrariesDefinition : '[' LibList ']';
};
FnDeclareLinkage: /*default*/ |
- DLLIMPORT { CurFun.Linkage = GlobalValue::DLLImportLinkage } |
- EXTERN_WEAK { CurFun.Linkage = GlobalValue::DLLImportLinkage };
+ DLLIMPORT { CurFun.Linkage = GlobalValue::DLLImportLinkage; } |
+ EXTERN_WEAK { CurFun.Linkage = GlobalValue::ExternalWeakLinkage; };
FunctionProto : DECLARE { CurFun.isDeclare = true; } FnDeclareLinkage FunctionHeaderH {
$$ = CurFun.CurrentFunction;
};
InstructionList : InstructionList Inst {
+ if (CastInst *CI1 = dyn_cast<CastInst>($2))
+ if (CastInst *CI2 = dyn_cast<CastInst>(CI1->getOperand(0)))
+ if (CI2->getParent() == 0)
+ $1->getInstList().push_back(CI2);
$1->getInstList().push_back($2);
$$ = $1;
CHECK_FOR_ERROR
}
| /* empty */ {
- $$ = CurBB = getBBVal(ValID::create((int)CurFun.NextBBNum++), true);
+ $$ = getBBVal(ValID::create((int)CurFun.NextBBNum++), true);
CHECK_FOR_ERROR
// Make sure to move the basic block to the correct location in the
CHECK_FOR_ERROR
}
| LABELSTR {
- $$ = CurBB = getBBVal(ValID::create($1), true);
+ $$ = getBBVal(ValID::create($1), true);
CHECK_FOR_ERROR
// Make sure to move the basic block to the correct location in the
!isa<PackedType>((*$2).get()))
GEN_ERROR(
"Arithmetic operator requires integer, FP, or packed operands!");
- if (isa<PackedType>((*$2).get()) && $1 == Instruction::Rem)
- GEN_ERROR("Rem not supported on packed types!");
+ if (isa<PackedType>((*$2).get()) &&
+ ($1 == Instruction::URem ||
+ $1 == Instruction::SRem ||
+ $1 == Instruction::FRem))
+ GEN_ERROR("U/S/FRem not supported on packed types!");
Value* val1 = getVal(*$2, $3);
CHECK_FOR_ERROR
Value* val2 = getVal(*$2, $5);
GEN_ERROR("binary operator returned null!");
delete $2;
}
+ | ICMP IPredicates Types ValueRef ',' ValueRef {
+ if (isa<PackedType>((*$3).get()))
+ GEN_ERROR("Packed types not supported by icmp instruction");
+ Value* tmpVal1 = getVal(*$3, $4);
+ CHECK_FOR_ERROR
+ Value* tmpVal2 = getVal(*$3, $6);
+ CHECK_FOR_ERROR
+ $$ = CmpInst::create($1, $2, tmpVal1, tmpVal2);
+ if ($$ == 0)
+ GEN_ERROR("icmp operator returned null!");
+ }
+ | FCMP FPredicates Types ValueRef ',' ValueRef {
+ if (isa<PackedType>((*$3).get()))
+ GEN_ERROR("Packed types not supported by fcmp instruction");
+ Value* tmpVal1 = getVal(*$3, $4);
+ CHECK_FOR_ERROR
+ Value* tmpVal2 = getVal(*$3, $6);
+ CHECK_FOR_ERROR
+ $$ = CmpInst::create($1, $2, tmpVal1, tmpVal2);
+ if ($$ == 0)
+ GEN_ERROR("fcmp operator returned null!");
+ }
| NOT ResolvedVal {
- std::cerr << "WARNING: Use of eliminated 'not' instruction:"
+ llvm_cerr << "WARNING: Use of eliminated 'not' instruction:"
<< " Replacing with 'xor'.\n";
Value *Ones = ConstantIntegral::getAllOnesValue($2->getType());
GEN_ERROR("Shift amount must be ubyte!");
if (!$2->getType()->isInteger())
GEN_ERROR("Shift constant expression requires integer operand!");
+ CHECK_FOR_ERROR;
$$ = new ShiftInst($1, $2, $4);
CHECK_FOR_ERROR
}
- | CAST ResolvedVal TO Types {
- if (!$4->get()->isFirstClassType())
- GEN_ERROR("cast instruction to a non-primitive type: '" +
- $4->get()->getDescription() + "'!");
- $$ = new CastInst($2, *$4);
+ | CastOps ResolvedVal TO Types {
+ Value* Val = $2;
+ const Type* Ty = $4->get();
+ if (!Val->getType()->isFirstClassType())
+ GEN_ERROR("cast from a non-primitive type: '" +
+ Val->getType()->getDescription() + "'!");
+ if (!Ty->isFirstClassType())
+ GEN_ERROR("cast to a non-primitive type: '" + Ty->getDescription() +"'!");
+ $$ = CastInst::create($1, $2, $4->get());
delete $4;
- CHECK_FOR_ERROR
}
| SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
if ($2->getType() != Type::BoolTy)
delete $4;
CHECK_FOR_ERROR
}
- | VAARG_old ResolvedVal ',' Types {
- ObsoleteVarArgs = true;
- const Type* ArgTy = $2->getType();
- Function* NF = CurModule.CurrentModule->
- getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0);
-
- //b = vaarg a, t ->
- //foo = alloca 1 of t
- //bar = vacopy a
- //store bar -> foo
- //b = vaarg foo, t
- AllocaInst* foo = new AllocaInst(ArgTy, 0, "vaarg.fix");
- CurBB->getInstList().push_back(foo);
- CallInst* bar = new CallInst(NF, $2);
- CurBB->getInstList().push_back(bar);
- CurBB->getInstList().push_back(new StoreInst(bar, foo));
- $$ = new VAArgInst(foo, *$4);
- delete $4;
- CHECK_FOR_ERROR
- }
- | VANEXT_old ResolvedVal ',' Types {
- ObsoleteVarArgs = true;
- const Type* ArgTy = $2->getType();
- Function* NF = CurModule.CurrentModule->
- getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0);
-
- //b = vanext a, t ->
- //foo = alloca 1 of t
- //bar = vacopy a
- //store bar -> foo
- //tmp = vaarg foo, t
- //b = load foo
- AllocaInst* foo = new AllocaInst(ArgTy, 0, "vanext.fix");
- CurBB->getInstList().push_back(foo);
- CallInst* bar = new CallInst(NF, $2);
- CurBB->getInstList().push_back(bar);
- CurBB->getInstList().push_back(new StoreInst(bar, foo));
- Instruction* tmp = new VAArgInst(foo, *$4);
- CurBB->getInstList().push_back(tmp);
- $$ = new LoadInst(foo);
- delete $4;
- CHECK_FOR_ERROR
- }
| EXTRACTELEMENT ResolvedVal ',' ResolvedVal {
if (!ExtractElementInst::isValidOperands($2, $4))
GEN_ERROR("Invalid extractelement operands!");
CHECK_FOR_ERROR
}
| OptTailCall OptCallingConv TypesV ValueRef '(' ValueRefListE ')' {
- const PointerType *PFTy;
- const FunctionType *Ty;
+ const PointerType *PFTy = 0;
+ const FunctionType *Ty = 0;
if (!(PFTy = dyn_cast<PointerType>($3->get())) ||
!(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
if (!isa<PointerType>($2->get()))
GEN_ERROR("getelementptr insn requires pointer operand!");
- // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte struct
- // indices to uint struct indices for compatibility.
- generic_gep_type_iterator<std::vector<Value*>::iterator>
- GTI = gep_type_begin($2->get(), $4->begin(), $4->end()),
- GTE = gep_type_end($2->get(), $4->begin(), $4->end());
- for (unsigned i = 0, e = $4->size(); i != e && GTI != GTE; ++i, ++GTI)
- if (isa<StructType>(*GTI)) // Only change struct indices
- if (ConstantUInt *CUI = dyn_cast<ConstantUInt>((*$4)[i]))
- if (CUI->getType() == Type::UByteTy)
- (*$4)[i] = ConstantExpr::getCast(CUI, Type::UIntTy);
-
if (!GetElementPtrInst::getIndexedType(*$2, *$4, true))
GEN_ERROR("Invalid getelementptr indices for type '" +
(*$2)->getDescription()+ "'!");