aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-12-03 05:45:44 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-12-03 05:45:44 +0000
commit08de34b229e0f4d8acd05f95275fd5483e492eb8 (patch)
tree990d76fc648ea579303b65680bf4583fd3084232
parente968dc9847345157e540ec57e5f106a80add86f4 (diff)
Remove backwards compatibility goop. Now implemented in llvm-upgrade.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32144 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AsmParser/Lexer.l75
-rw-r--r--lib/AsmParser/ParserInternals.h52
-rw-r--r--lib/AsmParser/llvmAsmParser.y899
3 files changed, 424 insertions, 602 deletions
diff --git a/lib/AsmParser/Lexer.l b/lib/AsmParser/Lexer.l
index 553ba8100e..5e60654c84 100644
--- a/lib/AsmParser/Lexer.l
+++ b/lib/AsmParser/Lexer.l
@@ -41,20 +41,16 @@ void set_scan_string (const char * str) {
// Construct a token value for a non-obsolete token
#define RET_TOK(type, Enum, sym) \
- llvmAsmlval.type.opcode = Instruction::Enum; \
- llvmAsmlval.type.obsolete = false; \
+ llvmAsmlval.type = Instruction::Enum; \
return sym
-// Construct a token value for an obsolete token
-#define RET_TOK_OBSOLETE(type, Enum, sym) \
- llvmAsmlval.type.opcode = Instruction::Enum; \
- llvmAsmlval.type.obsolete = true; \
+#define RET_ENUM(type, Enum, sym) \
+ llvmAsmlval.type = Enum; \
return sym
// Construct a token value for an obsolete token
-#define RET_TY(CTYPE, SIGN, SYM) \
- llvmAsmlval.TypeVal.type = new PATypeHolder(CTYPE); \
- llvmAsmlval.TypeVal.signedness = SIGN; \
+#define RET_TY(CTYPE, SYM) \
+ llvmAsmlval.PrimType = CTYPE;\
return SYM
namespace llvm {
@@ -209,7 +205,6 @@ appending { return APPENDING; }
dllimport { return DLLIMPORT; }
dllexport { return DLLEXPORT; }
extern_weak { return EXTERN_WEAK; }
-uninitialized { return EXTERNAL; } /* Deprecated, turn into external */
external { return EXTERNAL; }
implementation { return IMPLEMENTATION; }
zeroinitializer { return ZEROINITIALIZER; }
@@ -217,8 +212,6 @@ zeroinitializer { return ZEROINITIALIZER; }
undef { return UNDEF; }
null { return NULL_TOK; }
to { return TO; }
-except { RET_TOK(TermOpVal, Unwind, UNWIND); }
-not { return NOT; } /* Deprecated, turned into XOR */
tail { return TAIL; }
target { return TARGET; }
triple { return TRIPLE; }
@@ -243,30 +236,28 @@ coldcc { return COLDCC_TOK; }
x86_stdcallcc { return X86_STDCALLCC_TOK; }
x86_fastcallcc { return X86_FASTCALLCC_TOK; }
-void { RET_TY(Type::VoidTy, isSignless, VOID); }
-bool { RET_TY(Type::BoolTy, isSignless, BOOL); }
-sbyte { RET_TY(Type::SByteTy, isSigned, SBYTE); }
-ubyte { RET_TY(Type::UByteTy, isUnsigned, UBYTE); }
-short { RET_TY(Type::ShortTy, isSigned, SHORT); }
-ushort { RET_TY(Type::UShortTy,isUnsigned, USHORT);}
-int { RET_TY(Type::IntTy, isSigned, INT); }
-uint { RET_TY(Type::UIntTy, isUnsigned, UINT); }
-long { RET_TY(Type::LongTy, isSigned, LONG); }
-ulong { RET_TY(Type::ULongTy, isUnsigned, ULONG); }
-float { RET_TY(Type::FloatTy, isSignless, FLOAT); }
-double { RET_TY(Type::DoubleTy,isSignless, DOUBLE);}
-label { RET_TY(Type::LabelTy, isSignless, LABEL); }
+void { RET_TY(Type::VoidTy, VOID); }
+bool { RET_TY(Type::BoolTy, BOOL); }
+sbyte { RET_TY(Type::SByteTy, SBYTE); }
+ubyte { RET_TY(Type::UByteTy, UBYTE); }
+short { RET_TY(Type::ShortTy, SHORT); }
+ushort { RET_TY(Type::UShortTy,USHORT);}
+int { RET_TY(Type::IntTy, INT); }
+uint { RET_TY(Type::UIntTy, UINT); }
+long { RET_TY(Type::LongTy, LONG); }
+ulong { RET_TY(Type::ULongTy, ULONG); }
+float { RET_TY(Type::FloatTy, FLOAT); }
+double { RET_TY(Type::DoubleTy,DOUBLE);}
+label { RET_TY(Type::LabelTy, LABEL); }
type { return TYPE; }
opaque { return OPAQUE; }
add { RET_TOK(BinaryOpVal, Add, ADD); }
sub { RET_TOK(BinaryOpVal, Sub, SUB); }
mul { RET_TOK(BinaryOpVal, Mul, MUL); }
-div { RET_TOK_OBSOLETE(BinaryOpVal, UDiv, UDIV); }
udiv { RET_TOK(BinaryOpVal, UDiv, UDIV); }
sdiv { RET_TOK(BinaryOpVal, SDiv, SDIV); }
fdiv { RET_TOK(BinaryOpVal, FDiv, FDIV); }
-rem { RET_TOK_OBSOLETE(BinaryOpVal, URem, UREM); }
urem { RET_TOK(BinaryOpVal, URem, UREM); }
srem { RET_TOK(BinaryOpVal, SRem, SREM); }
frem { RET_TOK(BinaryOpVal, FRem, FREM); }
@@ -279,10 +270,35 @@ setlt { RET_TOK(BinaryOpVal, SetLT, SETLT); }
setgt { RET_TOK(BinaryOpVal, SetGT, SETGT); }
setle { RET_TOK(BinaryOpVal, SetLE, SETLE); }
setge { RET_TOK(BinaryOpVal, SetGE, SETGE); }
+icmp { RET_TOK(OtherOpVal, ICmp, ICMP); }
+fcmp { RET_TOK(OtherOpVal, FCmp, FCMP); }
+eq { RET_ENUM(IPredicate, ICmpInst::ICMP_EQ, EQ); }
+ne { RET_ENUM(IPredicate, ICmpInst::ICMP_NE, NE); }
+slt { RET_ENUM(IPredicate, ICmpInst::ICMP_SLT, SLT); }
+sgt { RET_ENUM(IPredicate, ICmpInst::ICMP_SGT, SGT); }
+sle { RET_ENUM(IPredicate, ICmpInst::ICMP_SLE, SLE); }
+sge { RET_ENUM(IPredicate, ICmpInst::ICMP_SGE, SGE); }
+ult { RET_ENUM(IPredicate, ICmpInst::ICMP_ULT, ULT); }
+ugt { RET_ENUM(IPredicate, ICmpInst::ICMP_UGT, UGT); }
+ule { RET_ENUM(IPredicate, ICmpInst::ICMP_ULE, ULE); }
+uge { RET_ENUM(IPredicate, ICmpInst::ICMP_UGE, UGE); }
+ordeq { RET_ENUM(FPredicate, FCmpInst::FCMP_OEQ, ORDEQ); }
+ordne { RET_ENUM(FPredicate, FCmpInst::FCMP_ONE, ORDNE); }
+ordlt { RET_ENUM(FPredicate, FCmpInst::FCMP_OLT, ORDLT); }
+ordgt { RET_ENUM(FPredicate, FCmpInst::FCMP_OGT, ORDGT); }
+ordle { RET_ENUM(FPredicate, FCmpInst::FCMP_OLE, ORDLE); }
+ordge { RET_ENUM(FPredicate, FCmpInst::FCMP_OGE, ORDGE); }
+ord { RET_ENUM(FPredicate, FCmpInst::FCMP_ORD, ORD); }
+uno { RET_ENUM(FPredicate, FCmpInst::FCMP_UNO, UNO); }
+unoeq { RET_ENUM(FPredicate, FCmpInst::FCMP_UEQ, UNOEQ); }
+unone { RET_ENUM(FPredicate, FCmpInst::FCMP_UNE, UNONE); }
+unolt { RET_ENUM(FPredicate, FCmpInst::FCMP_ULT, UNOLT); }
+unogt { RET_ENUM(FPredicate, FCmpInst::FCMP_UGT, UNOGT); }
+unole { RET_ENUM(FPredicate, FCmpInst::FCMP_ULE, UNOLE); }
+unoge { RET_ENUM(FPredicate, FCmpInst::FCMP_UGE, UNOGE); }
phi { RET_TOK(OtherOpVal, PHI, PHI_TOK); }
call { RET_TOK(OtherOpVal, Call, CALL); }
-cast { RET_TOK_OBSOLETE(CastOpVal, Trunc, TRUNC); }
trunc { RET_TOK(CastOpVal, Trunc, TRUNC); }
zext { RET_TOK(CastOpVal, ZExt, ZEXT); }
sext { RET_TOK(CastOpVal, SExt, SEXT); }
@@ -297,11 +313,8 @@ ptrtoint { RET_TOK(CastOpVal, PtrToInt, PTRTOINT); }
bitcast { RET_TOK(CastOpVal, BitCast, BITCAST); }
select { RET_TOK(OtherOpVal, Select, SELECT); }
shl { RET_TOK(OtherOpVal, Shl, SHL); }
-shr { RET_TOK_OBSOLETE(OtherOpVal, LShr, LSHR); }
lshr { RET_TOK(OtherOpVal, LShr, LSHR); }
ashr { RET_TOK(OtherOpVal, AShr, ASHR); }
-vanext { return VANEXT_old; }
-vaarg { return VAARG_old; }
va_arg { RET_TOK(OtherOpVal, VAArg , VAARG); }
ret { RET_TOK(TermOpVal, Ret, RET); }
br { RET_TOK(TermOpVal, Br, BR); }
diff --git a/lib/AsmParser/ParserInternals.h b/lib/AsmParser/ParserInternals.h
index 604057c9ba..79e367fe1f 100644
--- a/lib/AsmParser/ParserInternals.h
+++ b/lib/AsmParser/ParserInternals.h
@@ -201,56 +201,4 @@ struct ValID {
} // End llvm namespace
-// This structure is used to keep track of obsolete opcodes. The lexer will
-// retain the ability to parse obsolete opcode mnemonics. In this case it will
-// set "obsolete" to true and the opcode will be the replacement opcode. For
-// example if "rem" is encountered then opcode will be set to "urem" and the
-// "obsolete" flag will be true. If the opcode is not obsolete then "obsolete"
-// will be false.
-template <class Enum>
-struct OpcodeInfo {
- Enum opcode;
- bool obsolete;
-};
-typedef OpcodeInfo<llvm::Instruction::BinaryOps> BinaryOpInfo;
-typedef OpcodeInfo<llvm::Instruction::TermOps> TermOpInfo;
-typedef OpcodeInfo<llvm::Instruction::MemoryOps> MemOpInfo;
-typedef OpcodeInfo<llvm::Instruction::CastOps> CastOpInfo;
-typedef OpcodeInfo<llvm::Instruction::OtherOps> OtherOpInfo;
-
-/// This enumeration is used to indicate if a type is signed, signless or
-/// unsigned. It is used for backwards compatibility with assembly code that
-/// pre-dates the signless types conversion.
-enum Signedness {
- isSigned,
- isUnsigned,
- isSignless
-};
-
-/// This type is used to keep track of the signedness of the obsolete
-/// integer types. Instead of creating an llvm::Type directly, the Lexer will
-/// create instances of TypeInfo which retains the signedness indication so
-/// it can be used by the parser for upgrade decisions.
-/// For example if "uint" is encountered then the "first" field will be set
-/// to "int32" and the "second" field will be set to "isUnsigned". If the
-/// type is not obsolete then "second" will be set to "isSignless".
-struct TypeInfo {
- llvm::PATypeHolder* type;
- Signedness signedness;
-};
-
-/// This type is used to keep track of the signedness of values. Instead
-/// of creating llvm::Value directly, the parser will create ValueInfo which
-/// associates a Value* with a Signedness indication.
-struct ValueInfo {
- llvm::Value* val;
- Signedness signedness;
-};
-
-/// This type is used to keep track of the signedness of constants.
-struct ConstInfo {
- llvm::Constant *cnst;
- Signedness signedness;
-};
-
#endif
diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y
index 1d1558eb6b..8d0b7a2714 100644
--- a/lib/AsmParser/llvmAsmParser.y
+++ b/lib/AsmParser/llvmAsmParser.y
@@ -124,11 +124,6 @@ static struct PerModuleInfo {
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;
@@ -254,7 +249,7 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
Type *Typ = OpaqueType::get();
CurModule.LateResolveTypes.insert(std::make_pair(D, Typ));
return Typ;
-}
+ }
static Value *lookupInSymbolTable(const Type *Ty, const std::string &Name) {
SymbolTable &SymTab =
@@ -813,71 +808,6 @@ static PATypeHolder HandleUpRefs(const Type *ty) {
return Ty;
}
-/// This function is used to obtain the correct opcode for an instruction when
-/// an obsolete opcode is encountered. The OI parameter (OpcodeInfo) has both
-/// an opcode and an "obsolete" flag. These are generated by the lexer and
-/// the "obsolete" member will be true when the lexer encounters the token for
-/// an obsolete opcode. For example, "div" was replaced by [usf]div but we need
-/// to maintain backwards compatibility for asm files that still have the "div"
-/// instruction. This function handles converting div -> [usf]div appropriately.
-/// @brief Convert obsolete BinaryOps opcodes to new values
-static void
-sanitizeOpcode(OpcodeInfo<Instruction::BinaryOps> &OI, const Type *Ty)
-{
- // If its not obsolete, don't do anything
- if (!OI.obsolete)
- return;
-
- // If its a packed type we want to use the element type
- if (const PackedType *PTy = dyn_cast<PackedType>(Ty))
- Ty = PTy->getElementType();
-
- // Depending on the opcode ..
- switch (OI.opcode) {
- default:
- GenerateError("Invalid obsolete opCode (check Lexer.l)");
- break;
- case Instruction::UDiv:
- // Handle cases where the opcode needs to change
- if (Ty->isFloatingPoint())
- OI.opcode = Instruction::FDiv;
- else if (Ty->isSigned())
- OI.opcode = Instruction::SDiv;
- break;
- case Instruction::URem:
- if (Ty->isFloatingPoint())
- OI.opcode = Instruction::FRem;
- else if (Ty->isSigned())
- OI.opcode = Instruction::SRem;
- break;
- }
- // Its not obsolete any more, we fixed it.
- OI.obsolete = false;
-}
-
-/// This function is similar to the previous overload of sanitizeOpcode but
-/// operates on Instruction::OtherOps instead of Instruction::BinaryOps.
-/// @brief Convert obsolete OtherOps opcodes to new values
-static void
-sanitizeOpcode(OpcodeInfo<Instruction::OtherOps> &OI, const Type *Ty)
-{
- // If its not obsolete, don't do anything
- if (!OI.obsolete)
- return;
-
- switch (OI.opcode) {
- default:
- GenerateError("Invalid obsolete opcode (check Lexer.l)");
- break;
- case Instruction::LShr:
- if (Ty->isSigned())
- OI.opcode = Instruction::AShr;
- break;
- }
- // Its not obsolete any more, we fixed it.
- OI.obsolete = false;
-}
-
// common code from the two 'RunVMAsmParser' functions
static Module* RunParser(Module * M) {
@@ -1038,21 +968,24 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
%union {
llvm::Module *ModuleVal;
llvm::Function *FunctionVal;
- std::pair<TypeInfo, char*> *ArgVal;
+ std::pair<llvm::PATypeHolder*, char*> *ArgVal;
llvm::BasicBlock *BasicBlockVal;
llvm::TerminatorInst *TermInstVal;
llvm::Instruction *InstVal;
- ConstInfo ConstVal;
- TypeInfo TypeVal;
- ValueInfo ValueVal;
+ llvm::Constant *ConstVal;
- std::vector<std::pair<TypeInfo,char*> >*ArgList;
- std::vector<ValueInfo> *ValueList;
- std::list<TypeInfo> *TypeList;
+ const llvm::Type *PrimType;
+ llvm::PATypeHolder *TypeVal;
+ llvm::Value *ValueVal;
+
+ std::vector<std::pair<llvm::PATypeHolder*,char*> > *ArgList;
+ std::vector<llvm::Value*> *ValueList;
+ std::list<llvm::PATypeHolder> *TypeList;
// Represent the RHS of PHI node
- std::list<std::pair<llvm::Value*, llvm::BasicBlock*> > *PHIList;
+ std::list<std::pair<llvm::Value*,
+ llvm::BasicBlock*> > *PHIList;
std::vector<std::pair<llvm::Constant*, llvm::BasicBlock*> > *JumpTable;
- std::vector<ConstInfo> *ConstVector;
+ std::vector<llvm::Constant*> *ConstVector;
llvm::GlobalValue::LinkageTypes Linkage;
int64_t SInt64Val;
@@ -1065,12 +998,14 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
char *StrVal; // This memory is strdup'd!
llvm::ValID ValIDVal; // strdup'd memory maybe!
- BinaryOpInfo BinaryOpVal;
- TermOpInfo TermOpVal;
- MemOpInfo MemOpVal;
- CastOpInfo CastOpVal;
- OtherOpInfo OtherOpVal;
+ 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
@@ -1113,9 +1048,9 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
// Built in types...
%type <TypeVal> Types TypesV UpRTypes UpRTypesV
-%type <TypeVal> SIntType UIntType IntType FPType PrimType // Classifications
-%token <TypeVal> VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG
-%token <TypeVal> FLOAT DOUBLE TYPE LABEL
+%type <PrimType> SIntType UIntType IntType FPType PrimType // Classifications
+%token <PrimType> VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG
+%token <PrimType> FLOAT DOUBLE TYPE LABEL
%token <StrVal> VAR_ID LABELSTR STRINGCONSTANT
%type <StrVal> Name OptName OptAssign
@@ -1140,6 +1075,12 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
%type <BinaryOpVal> ArithmeticOps LogicalOps SetCondOps // Binops Subcatagories
%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
+%token <IPredicate> EQ NE SLT SGT SLE SGE ULT UGT ULE UGE
+%type <IPredicate> IPredicates
+%token <FPredicate> ORDEQ ORDNE ORDLT ORDGT ORDLE ORDGE ORD UNO UNOEQ UNONE
+%token <FPredicate> UNOLT UNOGT UNOLE UNOGE
+%type <FPredicate> FPredicates
// Memory Instructions
%token <MemOpVal> MALLOC ALLOCA FREE LOAD STORE GETELEMENTPTR
@@ -1187,6 +1128,9 @@ SetCondOps : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE;
CastOps : TRUNC | ZEXT | SEXT | FPTRUNC | FPEXT | BITCAST |
UITOFP | SITOFP | FPTOUI | FPTOSI | INTTOPTR | PTRTOINT;
ShiftOps : SHL | LSHR | ASHR;
+IPredicates : EQ | NE | SLT | SGT | SLE | SGE | ULT | UGT | ULE | UGE ;
+FPredicates : ORDEQ | ORDNE | ORDLT | ORDGT | ORDLE | ORDGE | ORD | UNO
+ | UNOEQ | UNONE | UNOLT | UNOGT | UNOLE | UNOGE ;
// These are some types that allow classification if we only want a particular
// thing... for example, only a signed, unsigned, or integral type.
@@ -1281,22 +1225,15 @@ GlobalVarAttribute : SectionString {
//
// TypesV includes all of 'Types', but it also includes the void type.
-TypesV : Types | VOID {
- $$.type = new PATypeHolder($1.type->get());
- $$.signedness = $1.signedness;
-};
-UpRTypesV : UpRTypes | VOID {
- $$.type = new PATypeHolder($1.type->get());
- $$.signedness = $1.signedness;
-};
+TypesV : Types | VOID { $$ = new PATypeHolder($1); };
+UpRTypesV : UpRTypes | VOID { $$ = new PATypeHolder($1); };
Types : UpRTypes {
if (!UpRefs.empty())
- GEN_ERROR("Invalid upreference in type: " +
- ($1.type->get())->getDescription());
+ GEN_ERROR("Invalid upreference in type: " + (*$1)->getDescription());
$$ = $1;
CHECK_FOR_ERROR
-};
+ };
// Derived types are added later...
@@ -1304,19 +1241,17 @@ Types : UpRTypes {
PrimType : BOOL | SBYTE | UBYTE | SHORT | USHORT | INT | UINT ;
PrimType : LONG | ULONG | FLOAT | DOUBLE | TYPE | LABEL;
UpRTypes : OPAQUE {
- $$.type = new PATypeHolder(OpaqueType::get());
- $$.signedness = isSignless;
+ $$ = new PATypeHolder(OpaqueType::get());
CHECK_FOR_ERROR
}
| PrimType {
- $$ = $1;
+ $$ = new PATypeHolder($1);
CHECK_FOR_ERROR
};
UpRTypes : SymbolicValueRef { // Named types are also simple types...
const Type* tmp = getTypeVal($1);
CHECK_FOR_ERROR
- $$.type = new PATypeHolder(tmp);
- $$.signedness = isSignless;
+ $$ = new PATypeHolder(tmp);
};
// Include derived types in the Types production.
@@ -1325,69 +1260,59 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference
if ($2 > (uint64_t)~0U) GEN_ERROR("Value out of range!");
OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder
UpRefs.push_back(UpRefRecord((unsigned)$2, OT)); // Add to vector...
- $$.type = new PATypeHolder(OT);
- $$.signedness = isSignless;
+ $$ = new PATypeHolder(OT);
UR_OUT("New Upreference!\n");
CHECK_FOR_ERROR
}
| UpRTypesV '(' ArgTypeListI ')' { // Function derived type?
std::vector<const Type*> Params;
- for (std::list<TypeInfo>::iterator I = $3->begin(),
+ for (std::list<llvm::PATypeHolder>::iterator I = $3->begin(),
E = $3->end(); I != E; ++I)
- Params.push_back(I->type->get());
+ Params.push_back(*I);
bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
if (isVarArg) Params.pop_back();
- $$.type = new PATypeHolder(HandleUpRefs(
- FunctionType::get($1.type->get(),Params,isVarArg)));
- $$.signedness = isSignless;
+ $$ = new PATypeHolder(HandleUpRefs(FunctionType::get(*$1,Params,isVarArg)));
delete $3; // Delete the argument list
- delete $1.type;
+ delete $1; // Delete the return type handle
CHECK_FOR_ERROR
}
| '[' EUINT64VAL 'x' UpRTypes ']' { // Sized array type?
- $$.type = new PATypeHolder(HandleUpRefs(
- ArrayType::get($4.type->get(), (unsigned)$2)));
- $$.signedness = isSignless;
- delete $4.type;
+ $$ = new PATypeHolder(HandleUpRefs(ArrayType::get(*$4, (unsigned)$2)));
+ delete $4;
CHECK_FOR_ERROR
}
| '<' EUINT64VAL 'x' UpRTypes '>' { // Packed array type?
- const llvm::Type* ElemTy = $4.type->get();
- if ((unsigned)$2 != $2)
- GEN_ERROR("Unsigned result not equal to signed result");
- if (!ElemTy->isPrimitiveType())
- GEN_ERROR("Elemental type of a PackedType must be primitive");
- if (!isPowerOf2_32($2))
- GEN_ERROR("Vector length should be a power of 2!");
- $$.type = new PATypeHolder(HandleUpRefs(
- PackedType::get($4.type->get(), (unsigned)$2)));
- $$.signedness = isSignless;
- delete $4.type;
- CHECK_FOR_ERROR
+ const llvm::Type* ElemTy = $4->get();
+ if ((unsigned)$2 != $2)
+ GEN_ERROR("Unsigned result not equal to signed result");
+ if (!ElemTy->isPrimitiveType())
+ GEN_ERROR("Elemental type of a PackedType must be primitive");
+ if (!isPowerOf2_32($2))
+ GEN_ERROR("Vector length should be a power of 2!");
+ $$ = new PATypeHolder(HandleUpRefs(PackedType::get(*$4, (unsigned)$2)));
+ delete $4;
+ CHECK_FOR_ERROR
}
| '{' TypeListI '}' { // Structure type?
std::vector<const Type*> Elements;
- for (std::list<TypeInfo>::iterator I = $2->begin(),
+ for (std::list<llvm::PATypeHolder>::iterator I = $2->begin(),
E = $2->end(); I != E; ++I)
- Elements.push_back((*I).type->get());
+ Elements.push_back(*I);
- $$.type = new PATypeHolder(HandleUpRefs(StructType::get(Elements)));
- $$.signedness = isSignless;
+ $$ = new PATypeHolder(HandleUpRefs(StructType::get(Elements)));
delete $2;
CHECK_FOR_ERROR
}
| '{' '}' { // Empty structure type?
- $$.type = new PATypeHolder(StructType::get(std::vector<const Type*>()));
- $$.signedness = isSignless;
+ $$ = new PATypeHolder(StructType::get(std::vector<const Type*>()));
CHECK_FOR_ERROR
}
| UpRTypes '*' { // Pointer type?
- if ($1.type->get() == Type::LabelTy)
+ if (*$1 == Type::LabelTy)
GEN_ERROR("Cannot form a pointer to a basic block");
- $$.type = new PATypeHolder(HandleUpRefs(PointerType::get($1.type->get())));
- $$.signedness = isSignless;
- delete $1.type;
+ $$ = new PATypeHolder(HandleUpRefs(PointerType::get(*$1)));
+ delete $1;
CHECK_FOR_ERROR
};
@@ -1395,31 +1320,27 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference
// declaration type lists
//
TypeListI : UpRTypes {
- $$ = new std::list<TypeInfo>();
- $$->push_back($1);
+ $$ = new std::list<PATypeHolder>();
+ $$->push_back(*$1); delete $1;
CHECK_FOR_ERROR
}
| TypeListI ',' UpRTypes {
- ($$=$1)->push_back($3);
+ ($$=$1)->push_back(*$3); delete $3;
CHECK_FOR_ERROR
};
// ArgTypeList - List of types for a function type declaration...
ArgTypeListI : TypeListI
| TypeListI ',' DOTDOTDOT {
- TypeInfo TI;
- TI.type = new PATypeHolder(Type::VoidTy); TI.signedness = isSignless;
- ($$=$1)->push_back(TI);
+ ($$=$1)->push_back(Type::VoidTy);
CHECK_FOR_ERROR
}
| DOTDOTDOT {
- TypeInfo TI;
- TI.type = new PATypeHolder(Type::VoidTy); TI.signedness = isSignless;
- ($$ = new std::list<TypeInfo>())->push_back(TI);
+ ($$ = new std::list<PATypeHolder>())->push_back(Type::VoidTy);
CHECK_FOR_ERROR
}
| /*empty*/ {
- $$ = new std::list<TypeInfo>();
+ $$ = new std::list<PATypeHolder>();
CHECK_FOR_ERROR
};
@@ -1430,10 +1351,10 @@ ArgTypeListI : TypeListI
// ResolvedVal, ValueRef and ConstValueRef productions.
//
ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
- const ArrayType *ATy = dyn_cast<ArrayType>($1.type->get());
+ const ArrayType *ATy = dyn_cast<ArrayType>($1->get());
if (ATy == 0)
GEN_ERROR("Cannot make array constant with type: '" +
- ($1.type->get())->getDescription() + "'!");
+ (*$1)->getDescription() + "'!");
const Type *ETy = ATy->getElementType();
int NumElements = ATy->getNumElements();
@@ -1444,42 +1365,36 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
itostr(NumElements) + "!");
// Verify all elements are correct type!
- std::vector<Constant*> elems;
for (unsigned i = 0; i < $3->size(); i++) {
- if (ETy != (*$3)[i].cnst->getType()) {
+ if (ETy != (*$3)[i]->getType())
GEN_ERROR("Element #" + utostr(i) + " is not of type '" +
ETy->getDescription() +"' as required!\nIt is of type '"+
- (*$3)[i].cnst->getType()->getDescription() + "'.");
- } else {
- elems.push_back((*$3)[i].cnst);
- }
+ (*$3)[i]->getType()->getDescription() + "'.");
}
- $$.cnst = ConstantArray::get(ATy, elems);
- $$.signedness = isSignless;
- delete $1.type; delete $3;
+ $$ = ConstantArray::get(ATy, *$3);
+ delete $1; delete $3;
CHECK_FOR_ERROR
}
| Types '[' ']' {
- const ArrayType *ATy = dyn_cast<ArrayType>($1.type->get());
+ const ArrayType *ATy = dyn_cast<ArrayType>($1->get());
if (ATy == 0)
GEN_ERROR("Cannot make array constant with type: '" +
- ($1.type->get())->getDescription() + "'!");
+ (*$1)->getDescription() + "'!");
int NumElements = ATy->getNumElements();
if (NumElements != -1 && NumElements != 0)
GEN_ERROR("Type mismatch: constant sized array initialized with 0"
" arguments, but has size of " + itostr(NumElements) +"!");
- $$.cnst = ConstantArray::get(ATy, std::vector<llvm::Constant*>());
- $$.signedness = isSignless;
- delete $1.type;
+ $$ = ConstantArray::get(ATy, std::vector<Constant*>());
+ delete $1;
CHECK_FOR_ERROR
}
| Types 'c' STRINGCONSTANT {
- const ArrayType *ATy = dyn_cast<ArrayType>($1.type->get());
+ const ArrayType *ATy = dyn_cast<ArrayType>($1->get());
if (ATy == 0)
GEN_ERROR("Cannot make array constant with type: '" +
- ($1.type->get())->getDescription() + "'!");
+ (*$1)->getDescription() + "'!");
int NumElements = ATy->getNumElements();
const Type *ETy = ATy->getElementType();
@@ -1501,16 +1416,15 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
GEN_ERROR("Cannot build string arrays of non byte sized elements!");
}
free($3);
- $$.cnst = ConstantArray::get(ATy, Vals);
- $$.signedness = isSignless;
- delete $1.type;
+ $$ = ConstantArray::get(ATy, Vals);
+ delete $1;
CHECK_FOR_ERROR
}
| Types '<' ConstVector '>' { // Nonempty unsized arr
- const PackedType *PTy = dyn_cast<PackedType>($1.type->get());
+ const PackedType *PTy = dyn_cast<PackedType>($1->get());
if (PTy == 0)
GEN_ERROR("Cannot make packed constant with type: '" +
- $1.type->get()->getDescription() + "'!");
+ (*$1)->getDescription() + "'!");
const Type *ETy = PTy->getElementType();
int NumElements = PTy->getNumElements();
@@ -1521,79 +1435,68 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
itostr(NumElements) + "!");
// Verify all elements are correct type!
- std::vector<Constant*> elems;
for (unsigned i = 0; i < $3->size(); i++) {
- if (ETy != (*$3)[i].cnst->getType()) {
+ if (ETy != (*$3)[i]->getType())
GEN_ERROR("Element #" + utostr(i) + " is not of type '" +
ETy->getDescription() +"' as required!\nIt is of type '"+
- (*$3)[i].cnst->getType()->getDescription() + "'.");
- } else
- elems.push_back((*$3)[i].cnst);
+ (*$3)[i]->getType()->getDescription() + "'.");
}
- $$.cnst = ConstantPacked::get(PTy, elems);
- $$.signedness = isSignless;
- delete $1.type; delete $3;
+ $$ = ConstantPacked::get(PTy, *$3);
+ delete $1; delete $3;
CHECK_FOR_ERROR
}
| Types '{' ConstVector '}' {
- const StructType *STy = dyn_cast<StructType>($1.type->get());
+ const StructType *STy = dyn_cast<StructType>($1->get());
if (STy == 0)
GEN_ERROR("Cannot make struct constant with type: '" +
- $1.type->get()->getDescription() + "'!");
+ (*$1)->getDescription() + "'!");
if ($3->size() != STy->getNumContainedTypes())
GEN_ERROR("Illegal number of initializers for structure type!");
// Check to ensure that constants are compatible with the type initializer!
- std::vector<Constant*> elems;
for (unsigned i = 0, e = $3->size(); i != e; ++i)
- if ((*$3)[i].cnst->getType() != STy->getElementType(i)) {
+ if ((*$3)[i]->getType() != STy->getElementType(i))
GEN_ERROR("Expected type '" +
STy->getElementType(i)->getDescription() +
"' for element #" + utostr(i) +
" of structure initializer!");
- } else
- elems.push_back((*$3)[i].cnst);
- $$.cnst = ConstantStruct::get(STy, elems);
- $$.signedness = isSignless;
- delete $1.type; delete $3;
+ $$ = ConstantStruct::get(STy, *$3);
+ delete $1; delete $3;
CHECK_FOR_ERROR
}
| Types '{' '}' {
- const StructType *STy = dyn_cast<StructType>($1.type->get());
+ const StructType *STy = dyn_cast<StructType>($1->get());
if (STy == 0)
GEN_ERROR("Cannot make struct constant with type: '" +
- $1.type->get()->getDescription() + "'!");
+ (*$1)->getDescription() + "'!");
if (STy->getNumContainedTypes() != 0)
GEN_ERROR("Illegal number of initializers for structure type!");
- $$.cnst = ConstantStruct::get(STy, std::vector<Constant*>());
- $$.signedness = isSignless;
- delete $1.type;
+ $$ = ConstantStruct::get(STy, std::vector<Constant*>());
+ delete $1;
CHECK_FOR_ERROR
}
| Types NULL_TOK {
- const PointerType *PTy = dyn_cast<PointerType>($1.type->get());
+ const PointerType *PTy = dyn_cast<PointerType>($1->get());
if (PTy == 0)
GEN_ERROR("Cannot make null pointer constant with type: '" +
- $1.type->get()->getDescription() + "'!");
+ (*$1)->getDescription() + "'!");
- $$.cnst = ConstantPointerNull::get(PTy);
- $$.signedness = isSignless;
- delete $1.type;
+ $$ = ConstantPointerNull::get(PTy);
+ delete $1;
CHECK_FOR_ERROR
}
| Types UNDEF {
- $$.cnst = UndefValue::get($1.type->get());
- $$.signedness = isSignless;
- delete $1.type;
+ $$ = UndefValue::get($1->get());
+ delete $1;
CHECK_FOR_ERROR
}
| Types SymbolicValueRef {
- const PointerType *Ty = dyn_cast<PointerType>($1.type->get());
+ const PointerType *Ty = dyn_cast<PointerType>($1->get());
if (Ty == 0)
GEN_ERROR("Global const reference must be a pointer type!");
@@ -1649,132 +1552,116 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
}
}
- $$.cnst = cast<GlobalValue>(V);
- $$.signedness = $1.signedness;
- delete $1.type; // Free the type handle
+ $$ = cast<GlobalValue>(V);
+ delete $1; // Free the type handle
CHECK_FOR_ERROR
}
| Types ConstExpr {
- if ($1.type->get() != $2.cnst->getType())
+ if ($1->get() != $2->getType())
GEN_ERROR("Mismatched types for constant expression!");
$$ = $2;
- delete $1.type;
+ delete $1;
CHECK_FOR_ERROR
}
| Types ZEROINITIALIZER {
- const Type *Ty = $1.type->get();
+ const Type *Ty = $1->get();
if (isa<FunctionType>(Ty) || Ty == Type::LabelTy || isa<OpaqueType>(Ty))
GEN_ERROR("Cannot create a null initialized value of this type!");
- $$.cnst = Constant::getNullValue(Ty);
- $$.signedness = isSignless;
- delete $1.type;
+ $$ = Constant::getNullValue(Ty);
+ delete $1;
CHECK_FOR_ERROR
- };
-
-ConstVal : SIntType EINT64VAL { // integral constants
- if (!ConstantInt::isValueValidForType($1.type->get(), $2))
+ }
+ | SIntType EINT64VAL { // integral constants
+ if (!ConstantInt::isValueValidForType($1, $2))
GEN_ERROR("Constant value doesn't fit in type!");
- $$.cnst = ConstantInt::get($1.type->get(), $2);
- $$.signedness = $1.signedness;
+ $$ = ConstantInt::get($1, $2);
CHECK_FOR_ERROR
}
| UIntType EUINT64VAL { // integral constants
- if (!ConstantInt::isValueValidForType($1.type->get(), $2))
+ if (!ConstantInt::isValueValidForType($1, $2))
GEN_ERROR("Constant value doesn't fit in type!");
- $$.cnst = ConstantInt::get($1.type->get(), $2);
- $$.signedness = $1.signedness;
+ $$ = ConstantInt::get($1, $2);
CHECK_FOR_ERROR
}
| BOOL TRUETOK { // Boolean constants
- $$.cnst = ConstantBool::getTrue();
- $$.signedness = isSignless;
+ $$ = ConstantBool::getTrue();
CHECK_FOR_ERROR
}
| BOOL FALSETOK { // Boolean constants
- $$.cnst = ConstantBool::getFalse();
- $$.signedness = isSignless;
+ $$ = ConstantBool::getFalse();
CHECK_FOR_ERROR
}
| FPType FPVAL { // Float & Double constants
- if (!ConstantFP::isValueValidForType($1.type->get(), $2))
+ if (!ConstantFP::isValueValidForType($1, $2))
GEN_ERROR("Floating point constant invalid for type!!");
- $$.cnst = ConstantFP::get($1.type->get(), $2);
- $$.signedness = isSignless;
+ $$ = ConstantFP::get($1, $2);
CHECK_FOR_ERROR
};
ConstExpr: CastOps '(' ConstVal TO Types ')' {
- Constant *Val = $3.cnst;
- const Type *Ty = $5.type->get();
+ Constant *Val = $3;
+ const Type *Ty = $5->get();
if (!Val->getType()->isFirstClassType())
GEN_ERROR("cast constant expression from a non-primitive type: '" +
Val->getType()->getDescription() + "'!");
if (!Ty->isFirstClassType())
GEN_ERROR("cast constant expression to a non-primitive type: '" +
Ty->getDescription() + "'!");
- if ($1.obsolete) {
- if (Ty == Type::BoolTy) {
- // The previous definition of cast to bool was a compare against zero.
- // We have to retain that semantic so we do it here.
- $$.cnst = ConstantExpr::get(Instruction::SetNE, Val,
- Constant::getNullValue(Val->getType()));
- } else if (Val->getType()->isFloatingPoint() && isa<PointerType>(Ty)) {
- Constant *CE = ConstantExpr::getFPToUI(Val, Type::ULongTy);
- $$.cnst = ConstantExpr::getIntToPtr(CE, Ty);
- } else {
- $$.cnst = ConstantExpr::getCast(Val, Ty);
- }
- } else {
- $$.cnst = ConstantExpr::getCast($1.opcode, $3.cnst, $5.type->get());
- }
- delete $5.type;
+ $$ = ConstantExpr::getCast($1, $3, $5->get());
+ delete $5;
}
| GETELEMENTPTR '(' ConstVal IndexList ')' {
- if (!isa<PointerType>($3.cnst->getType()))
+ if (!isa<PointerType>($3->getType()))
GEN_ERROR("GetElementPtr requires a pointer operand!");
- std::vector<llvm::Value*> IdxVec;
- for (unsigned i = 0, e = $4->size(); i < e; ++i)
- if (Constant *C = dyn_cast<Constant>((*$4)[i].val))
- IdxVec.push_back(C);
- else
- GEN_ERROR("Indices to constant getelementptr must be constants!");
+ // 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 (ConstantInt *CUI = dyn_cast<ConstantInt>((*$4)[i]))