For PR950:

Retain the signedness of the old integer types in a new TypeInfo structure
so that it can be used in the grammar to implement auto-upgrade of things
that depended on signedness of types. This doesn't implement any new
functionality in the AsmParser, its just plumbing for future changes.

llvm-svn: 31866
This commit is contained in:
Reid Spencer 2006-11-19 23:07:00 +00:00
parent f69acf3e26
commit 9f4448a26e
3 changed files with 277 additions and 215 deletions

View File

@ -51,6 +51,17 @@ void set_scan_string (const char * str) {
llvmAsmlval.type.obsolete = true; \ llvmAsmlval.type.obsolete = true; \
return sym return sym
// Construct a token value for a non-obsolete type
#define RET_TY(CType, sym) \
llvmAsmlval.TypeVal.type = new PATypeHolder(CType); \
llvmAsmlval.TypeVal.signedness = isSignless; \
return sym
// Construct a token value for an obsolete token
#define RET_TY_OBSOLETE(CType, sign, sym) \
llvmAsmlval.TypeVal.type = new PATypeHolder(CType); \
llvmAsmlval.TypeVal.signedness = sign; \
return sym
namespace llvm { namespace llvm {
@ -238,19 +249,19 @@ coldcc { return COLDCC_TOK; }
x86_stdcallcc { return X86_STDCALLCC_TOK; } x86_stdcallcc { return X86_STDCALLCC_TOK; }
x86_fastcallcc { return X86_FASTCALLCC_TOK; } x86_fastcallcc { return X86_FASTCALLCC_TOK; }
void { llvmAsmlval.PrimType = Type::VoidTy ; return VOID; } void { RET_TY(Type::VoidTy, VOID); }
bool { llvmAsmlval.PrimType = Type::BoolTy ; return BOOL; } bool { RET_TY(Type::BoolTy, BOOL); }
sbyte { llvmAsmlval.PrimType = Type::SByteTy ; return SBYTE; } sbyte { RET_TY_OBSOLETE(Type::SByteTy, isSigned, SBYTE); }
ubyte { llvmAsmlval.PrimType = Type::UByteTy ; return UBYTE; } ubyte { RET_TY_OBSOLETE(Type::UByteTy, isUnsigned, UBYTE); }
short { llvmAsmlval.PrimType = Type::ShortTy ; return SHORT; } short { RET_TY_OBSOLETE(Type::ShortTy, isSigned, SHORT); }
ushort { llvmAsmlval.PrimType = Type::UShortTy; return USHORT; } ushort { RET_TY_OBSOLETE(Type::UShortTy,isUnsigned, USHORT); }
int { llvmAsmlval.PrimType = Type::IntTy ; return INT; } int { RET_TY_OBSOLETE(Type::IntTy, isSigned, INT); }
uint { llvmAsmlval.PrimType = Type::UIntTy ; return UINT; } uint { RET_TY_OBSOLETE(Type::UIntTy, isUnsigned, UINT); }
long { llvmAsmlval.PrimType = Type::LongTy ; return LONG; } long { RET_TY_OBSOLETE(Type::LongTy, isSigned, LONG); }
ulong { llvmAsmlval.PrimType = Type::ULongTy ; return ULONG; } ulong { RET_TY_OBSOLETE(Type::ULongTy, isUnsigned, ULONG); }
float { llvmAsmlval.PrimType = Type::FloatTy ; return FLOAT; } float { RET_TY(Type::FloatTy, FLOAT); }
double { llvmAsmlval.PrimType = Type::DoubleTy; return DOUBLE; } double { RET_TY(Type::DoubleTy, DOUBLE); }
label { llvmAsmlval.PrimType = Type::LabelTy ; return LABEL; } label { RET_TY(Type::LabelTy, LABEL); }
type { return TYPE; } type { return TYPE; }
opaque { return OPAQUE; } opaque { return OPAQUE; }

View File

@ -217,4 +217,30 @@ typedef OpcodeInfo<llvm::Instruction::TermOps> TermOpInfo;
typedef OpcodeInfo<llvm::Instruction::MemoryOps> MemOpInfo; typedef OpcodeInfo<llvm::Instruction::MemoryOps> MemOpInfo;
typedef OpcodeInfo<llvm::Instruction::OtherOps> OtherOpInfo; 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 structure 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 type will be set "int32"
/// and the "signedness" will be "isUnsigned". If the type is not obsolete
/// then "signedness" will be "isSignless".
struct TypeInfo {
llvm::PATypeHolder *type;
Signedness signedness;
};
struct ValueInfo {
std::vector<llvm::Value*> valuelist;
std::vector<Signedness> signlist;
};
#endif #endif

View File

@ -83,8 +83,8 @@ static struct PerModuleInfo {
Module *CurrentModule; Module *CurrentModule;
std::map<const Type *, ValueList> Values; // Module level numbered definitions std::map<const Type *, ValueList> Values; // Module level numbered definitions
std::map<const Type *,ValueList> LateResolveValues; std::map<const Type *,ValueList> LateResolveValues;
std::vector<PATypeHolder> Types; std::vector<TypeInfo> Types;
std::map<ValID, PATypeHolder> LateResolveTypes; std::map<ValID, TypeInfo> LateResolveTypes;
/// PlaceHolderInfo - When temporary placeholder objects are created, remember /// PlaceHolderInfo - When temporary placeholder objects are created, remember
/// how they were referenced and on which line of the input they came from so /// how they were referenced and on which line of the input they came from so
@ -217,7 +217,7 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
case ValID::NumberVal: // Is it a numbered definition? case ValID::NumberVal: // Is it a numbered definition?
// Module constants occupy the lowest numbered slots... // Module constants occupy the lowest numbered slots...
if ((unsigned)D.Num < CurModule.Types.size()) if ((unsigned)D.Num < CurModule.Types.size())
return CurModule.Types[(unsigned)D.Num]; return CurModule.Types[(unsigned)D.Num].type->get();
break; break;
case ValID::NameVal: // Is it a named definition? case ValID::NameVal: // Is it a named definition?
if (const Type *N = CurModule.CurrentModule->getTypeByName(D.Name)) { if (const Type *N = CurModule.CurrentModule->getTypeByName(D.Name)) {
@ -247,13 +247,15 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
} }
} }
std::map<ValID, PATypeHolder>::iterator I =CurModule.LateResolveTypes.find(D); std::map<ValID, TypeInfo>::iterator I =CurModule.LateResolveTypes.find(D);
if (I != CurModule.LateResolveTypes.end()) if (I != CurModule.LateResolveTypes.end())
return I->second; return I->second.type->get();
Type *Typ = OpaqueType::get(); TypeInfo TI;
CurModule.LateResolveTypes.insert(std::make_pair(D, Typ)); TI.type = new PATypeHolder(OpaqueType::get());
return Typ; TI.signedness = isSignless;
CurModule.LateResolveTypes.insert(std::make_pair(D, TI));
return TI.type->get();
} }
static Value *lookupInSymbolTable(const Type *Ty, const std::string &Name) { static Value *lookupInSymbolTable(const Type *Ty, const std::string &Name) {
@ -557,10 +559,10 @@ static void ResolveTypeTo(char *Name, const Type *ToTy) {
if (Name) D = ValID::create(Name); if (Name) D = ValID::create(Name);
else D = ValID::create((int)CurModule.Types.size()); else D = ValID::create((int)CurModule.Types.size());
std::map<ValID, PATypeHolder>::iterator I = std::map<ValID, TypeInfo>::iterator I =
CurModule.LateResolveTypes.find(D); CurModule.LateResolveTypes.find(D);
if (I != CurModule.LateResolveTypes.end()) { if (I != CurModule.LateResolveTypes.end()) {
((DerivedType*)I->second.get())->refineAbstractTypeTo(ToTy); ((DerivedType*)I->second.type->get())->refineAbstractTypeTo(ToTy);
CurModule.LateResolveTypes.erase(I); CurModule.LateResolveTypes.erase(I);
} }
} }
@ -822,14 +824,13 @@ static PATypeHolder HandleUpRefs(const Type *ty) {
/// instruction. This function handles converting div -> [usf]div appropriately. /// instruction. This function handles converting div -> [usf]div appropriately.
/// @brief Convert obsolete BinaryOps opcodes to new values /// @brief Convert obsolete BinaryOps opcodes to new values
static void static void
sanitizeOpCode(OpcodeInfo<Instruction::BinaryOps> &OI, const PATypeHolder& PATy) sanitizeOpCode(OpcodeInfo<Instruction::BinaryOps> &OI, const Type *Ty)
{ {
// If its not obsolete, don't do anything // If its not obsolete, don't do anything
if (!OI.obsolete) if (!OI.obsolete)
return; return;
// If its a packed type we want to use the element type // If its a packed type we want to use the element type
const Type* Ty = PATy;
if (const PackedType* PTy = dyn_cast<PackedType>(Ty)) if (const PackedType* PTy = dyn_cast<PackedType>(Ty))
Ty = PTy->getElementType(); Ty = PTy->getElementType();
@ -860,13 +861,12 @@ sanitizeOpCode(OpcodeInfo<Instruction::BinaryOps> &OI, const PATypeHolder& PATy)
/// operates on Instruction::OtherOps instead of Instruction::BinaryOps. /// operates on Instruction::OtherOps instead of Instruction::BinaryOps.
/// @brief Convert obsolete OtherOps opcodes to new values /// @brief Convert obsolete OtherOps opcodes to new values
static void static void
sanitizeOpCode(OpcodeInfo<Instruction::OtherOps> &OI, const PATypeHolder& PATy) sanitizeOpCode(OpcodeInfo<Instruction::OtherOps> &OI, const Type *Ty)
{ {
// If its not obsolete, don't do anything // If its not obsolete, don't do anything
if (!OI.obsolete) if (!OI.obsolete)
return; return;
const Type* Ty = PATy; // type conversion
switch (OI.opcode) { switch (OI.opcode) {
default: default:
GenerateError("Invalid obsolete opcode (check Lexer.l)"); GenerateError("Invalid obsolete opcode (check Lexer.l)");
@ -1040,19 +1040,18 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
%union { %union {
llvm::Module *ModuleVal; llvm::Module *ModuleVal;
llvm::Function *FunctionVal; llvm::Function *FunctionVal;
std::pair<llvm::PATypeHolder*, char*> *ArgVal; std::pair<TypeInfo, char*> *ArgVal;
llvm::BasicBlock *BasicBlockVal; llvm::BasicBlock *BasicBlockVal;
llvm::TerminatorInst *TermInstVal; llvm::TerminatorInst *TermInstVal;
llvm::Instruction *InstVal; llvm::Instruction *InstVal;
llvm::Constant *ConstVal; llvm::Constant *ConstVal;
const llvm::Type *PrimType; TypeInfo TypeVal;
llvm::PATypeHolder *TypeVal;
llvm::Value *ValueVal; llvm::Value *ValueVal;
std::vector<std::pair<llvm::PATypeHolder*,char*> > *ArgList; std::vector<std::pair<TypeInfo,char*> >*ArgList;
std::vector<llvm::Value*> *ValueList; std::vector<llvm::Value*> *ValueList;
std::list<llvm::PATypeHolder> *TypeList; std::list<TypeInfo> *TypeList;
// Represent the RHS of PHI node // Represent the RHS of PHI node
std::list<std::pair<llvm::Value*, std::list<std::pair<llvm::Value*,
llvm::BasicBlock*> > *PHIList; llvm::BasicBlock*> > *PHIList;
@ -1117,9 +1116,9 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
// Built in types... // Built in types...
%type <TypeVal> Types TypesV UpRTypes UpRTypesV %type <TypeVal> Types TypesV UpRTypes UpRTypesV
%type <PrimType> SIntType UIntType IntType FPType PrimType // Classifications %type <TypeVal> SIntType UIntType IntType FPType PrimType // Classifications
%token <PrimType> VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG %token <TypeVal> VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG
%token <PrimType> FLOAT DOUBLE TYPE LABEL %token <TypeVal> FLOAT DOUBLE TYPE LABEL
%token <StrVal> VAR_ID LABELSTR STRINGCONSTANT %token <StrVal> VAR_ID LABELSTR STRINGCONSTANT
%type <StrVal> Name OptName OptAssign %type <StrVal> Name OptName OptAssign
@ -1279,15 +1278,22 @@ GlobalVarAttribute : SectionString {
// //
// TypesV includes all of 'Types', but it also includes the void type. // TypesV includes all of 'Types', but it also includes the void type.
TypesV : Types | VOID { $$ = new PATypeHolder($1); }; TypesV : Types | VOID {
UpRTypesV : UpRTypes | VOID { $$ = new PATypeHolder($1); }; $$.type = new PATypeHolder($1.type->get());
$$.signedness = $1.signedness;
};
UpRTypesV : UpRTypes | VOID {
$$.type = new PATypeHolder($1.type->get());
$$.signedness = $1.signedness;
};
Types : UpRTypes { Types : UpRTypes {
if (!UpRefs.empty()) if (!UpRefs.empty())
GEN_ERROR("Invalid upreference in type: " + (*$1)->getDescription()); GEN_ERROR("Invalid upreference in type: " +
($1.type->get())->getDescription());
$$ = $1; $$ = $1;
CHECK_FOR_ERROR CHECK_FOR_ERROR
}; };
// Derived types are added later... // Derived types are added later...
@ -1295,17 +1301,19 @@ Types : UpRTypes {
PrimType : BOOL | SBYTE | UBYTE | SHORT | USHORT | INT | UINT ; PrimType : BOOL | SBYTE | UBYTE | SHORT | USHORT | INT | UINT ;
PrimType : LONG | ULONG | FLOAT | DOUBLE | TYPE | LABEL; PrimType : LONG | ULONG | FLOAT | DOUBLE | TYPE | LABEL;
UpRTypes : OPAQUE { UpRTypes : OPAQUE {
$$ = new PATypeHolder(OpaqueType::get()); $$.type = new PATypeHolder(OpaqueType::get());
$$.signedness = isSignless;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| PrimType { | PrimType {
$$ = new PATypeHolder($1); $$ = $1;
CHECK_FOR_ERROR CHECK_FOR_ERROR
}; };
UpRTypes : SymbolicValueRef { // Named types are also simple types... UpRTypes : SymbolicValueRef { // Named types are also simple types...
const Type* tmp = getTypeVal($1); const Type* tmp = getTypeVal($1);
CHECK_FOR_ERROR CHECK_FOR_ERROR
$$ = new PATypeHolder(tmp); $$.type = new PATypeHolder(tmp);
$$.signedness = isSignless;
}; };
// Include derived types in the Types production. // Include derived types in the Types production.
@ -1314,59 +1322,69 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference
if ($2 > (uint64_t)~0U) GEN_ERROR("Value out of range!"); if ($2 > (uint64_t)~0U) GEN_ERROR("Value out of range!");
OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder
UpRefs.push_back(UpRefRecord((unsigned)$2, OT)); // Add to vector... UpRefs.push_back(UpRefRecord((unsigned)$2, OT)); // Add to vector...
$$ = new PATypeHolder(OT); $$.type = new PATypeHolder(OT);
$$.signedness = isSignless;
UR_OUT("New Upreference!\n"); UR_OUT("New Upreference!\n");
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| UpRTypesV '(' ArgTypeListI ')' { // Function derived type? | UpRTypesV '(' ArgTypeListI ')' { // Function derived type?
std::vector<const Type*> Params; std::vector<const Type*> Params;
for (std::list<llvm::PATypeHolder>::iterator I = $3->begin(), for (std::list<TypeInfo>::iterator I = $3->begin(),
E = $3->end(); I != E; ++I) E = $3->end(); I != E; ++I)
Params.push_back(*I); Params.push_back(I->type->get());
bool isVarArg = Params.size() && Params.back() == Type::VoidTy; bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
if (isVarArg) Params.pop_back(); if (isVarArg) Params.pop_back();
$$ = new PATypeHolder(HandleUpRefs(FunctionType::get(*$1,Params,isVarArg))); $$.type = new PATypeHolder(HandleUpRefs(
FunctionType::get($1.type->get(),Params,isVarArg)));
$$.signedness = isSignless;
delete $3; // Delete the argument list delete $3; // Delete the argument list
delete $1; // Delete the return type handle delete $1.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| '[' EUINT64VAL 'x' UpRTypes ']' { // Sized array type? | '[' EUINT64VAL 'x' UpRTypes ']' { // Sized array type?
$$ = new PATypeHolder(HandleUpRefs(ArrayType::get(*$4, (unsigned)$2))); $$.type = new PATypeHolder(HandleUpRefs(
delete $4; ArrayType::get($4.type->get(), (unsigned)$2)));
$$.signedness = isSignless;
delete $4.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| '<' EUINT64VAL 'x' UpRTypes '>' { // Packed array type? | '<' EUINT64VAL 'x' UpRTypes '>' { // Packed array type?
const llvm::Type* ElemTy = $4->get(); const llvm::Type* ElemTy = $4.type->get();
if ((unsigned)$2 != $2) if ((unsigned)$2 != $2)
GEN_ERROR("Unsigned result not equal to signed result"); GEN_ERROR("Unsigned result not equal to signed result");
if (!ElemTy->isPrimitiveType()) if (!ElemTy->isPrimitiveType())
GEN_ERROR("Elemental type of a PackedType must be primitive"); GEN_ERROR("Elemental type of a PackedType must be primitive");
if (!isPowerOf2_32($2)) if (!isPowerOf2_32($2))
GEN_ERROR("Vector length should be a power of 2!"); GEN_ERROR("Vector length should be a power of 2!");
$$ = new PATypeHolder(HandleUpRefs(PackedType::get(*$4, (unsigned)$2))); $$.type = new PATypeHolder(HandleUpRefs(
delete $4; PackedType::get($4.type->get(), (unsigned)$2)));
CHECK_FOR_ERROR $$.signedness = isSignless;
delete $4.type;
CHECK_FOR_ERROR
} }
| '{' TypeListI '}' { // Structure type? | '{' TypeListI '}' { // Structure type?
std::vector<const Type*> Elements; std::vector<const Type*> Elements;
for (std::list<llvm::PATypeHolder>::iterator I = $2->begin(), for (std::list<TypeInfo>::iterator I = $2->begin(),
E = $2->end(); I != E; ++I) E = $2->end(); I != E; ++I)
Elements.push_back(*I); Elements.push_back(I->type->get());
$$ = new PATypeHolder(HandleUpRefs(StructType::get(Elements))); $$.type = new PATypeHolder(HandleUpRefs(StructType::get(Elements)));
$$.signedness = isSignless;
delete $2; delete $2;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| '{' '}' { // Empty structure type? | '{' '}' { // Empty structure type?
$$ = new PATypeHolder(StructType::get(std::vector<const Type*>())); $$.type = new PATypeHolder(StructType::get(std::vector<const Type*>()));
$$.signedness = isSignless;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| UpRTypes '*' { // Pointer type? | UpRTypes '*' { // Pointer type?
if (*$1 == Type::LabelTy) if ($1.type->get() == Type::LabelTy)
GEN_ERROR("Cannot form a pointer to a basic block"); GEN_ERROR("Cannot form a pointer to a basic block");
$$ = new PATypeHolder(HandleUpRefs(PointerType::get(*$1))); $$.type = new PATypeHolder(HandleUpRefs(PointerType::get($1.type->get())));
delete $1; $$.signedness = $1.signedness;
delete $1.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
}; };
@ -1374,27 +1392,31 @@ UpRTypes : '\\' EUINT64VAL { // Type UpReference
// declaration type lists // declaration type lists
// //
TypeListI : UpRTypes { TypeListI : UpRTypes {
$$ = new std::list<PATypeHolder>(); $$ = new std::list<TypeInfo>();
$$->push_back(*$1); delete $1; $$->push_back($1);
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| TypeListI ',' UpRTypes { | TypeListI ',' UpRTypes {
($$=$1)->push_back(*$3); delete $3; ($$=$1)->push_back($3);
CHECK_FOR_ERROR CHECK_FOR_ERROR
}; };
// ArgTypeList - List of types for a function type declaration... // ArgTypeList - List of types for a function type declaration...
ArgTypeListI : TypeListI ArgTypeListI : TypeListI
| TypeListI ',' DOTDOTDOT { | TypeListI ',' DOTDOTDOT {
($$=$1)->push_back(Type::VoidTy); TypeInfo TI;
TI.type = new PATypeHolder(Type::VoidTy); TI.signedness = isSignless;
($$=$1)->push_back(TI);
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| DOTDOTDOT { | DOTDOTDOT {
($$ = new std::list<PATypeHolder>())->push_back(Type::VoidTy); TypeInfo TI;
TI.type = new PATypeHolder(Type::VoidTy); TI.signedness = isSignless;
($$ = new std::list<TypeInfo>())->push_back(TI);
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| /*empty*/ { | /*empty*/ {
$$ = new std::list<PATypeHolder>(); $$ = new std::list<TypeInfo>();
CHECK_FOR_ERROR CHECK_FOR_ERROR
}; };
@ -1405,10 +1427,10 @@ ArgTypeListI : TypeListI
// ResolvedVal, ValueRef and ConstValueRef productions. // ResolvedVal, ValueRef and ConstValueRef productions.
// //
ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
const ArrayType *ATy = dyn_cast<ArrayType>($1->get()); const ArrayType *ATy = dyn_cast<ArrayType>($1.type->get());
if (ATy == 0) if (ATy == 0)
GEN_ERROR("Cannot make array constant with type: '" + GEN_ERROR("Cannot make array constant with type: '" +
(*$1)->getDescription() + "'!"); ($1.type->get())->getDescription() + "'!");
const Type *ETy = ATy->getElementType(); const Type *ETy = ATy->getElementType();
int NumElements = ATy->getNumElements(); int NumElements = ATy->getNumElements();
@ -1427,28 +1449,28 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
} }
$$ = ConstantArray::get(ATy, *$3); $$ = ConstantArray::get(ATy, *$3);
delete $1; delete $3; delete $1.type; delete $3;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| Types '[' ']' { | Types '[' ']' {
const ArrayType *ATy = dyn_cast<ArrayType>($1->get()); const ArrayType *ATy = dyn_cast<ArrayType>($1.type->get());
if (ATy == 0) if (ATy == 0)
GEN_ERROR("Cannot make array constant with type: '" + GEN_ERROR("Cannot make array constant with type: '" +
(*$1)->getDescription() + "'!"); ($1.type->get())->getDescription() + "'!");
int NumElements = ATy->getNumElements(); int NumElements = ATy->getNumElements();
if (NumElements != -1 && NumElements != 0) if (NumElements != -1 && NumElements != 0)
GEN_ERROR("Type mismatch: constant sized array initialized with 0" GEN_ERROR("Type mismatch: constant sized array initialized with 0"
" arguments, but has size of " + itostr(NumElements) +"!"); " arguments, but has size of " + itostr(NumElements) +"!");
$$ = ConstantArray::get(ATy, std::vector<Constant*>()); $$ = ConstantArray::get(ATy, std::vector<Constant*>());
delete $1; delete $1.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| Types 'c' STRINGCONSTANT { | Types 'c' STRINGCONSTANT {
const ArrayType *ATy = dyn_cast<ArrayType>($1->get()); const ArrayType *ATy = dyn_cast<ArrayType>($1.type->get());
if (ATy == 0) if (ATy == 0)
GEN_ERROR("Cannot make array constant with type: '" + GEN_ERROR("Cannot make array constant with type: '" +
(*$1)->getDescription() + "'!"); ($1.type->get())->getDescription() + "'!");
int NumElements = ATy->getNumElements(); int NumElements = ATy->getNumElements();
const Type *ETy = ATy->getElementType(); const Type *ETy = ATy->getElementType();
@ -1471,14 +1493,14 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
} }
free($3); free($3);
$$ = ConstantArray::get(ATy, Vals); $$ = ConstantArray::get(ATy, Vals);
delete $1; delete $1.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| Types '<' ConstVector '>' { // Nonempty unsized arr | Types '<' ConstVector '>' { // Nonempty unsized arr
const PackedType *PTy = dyn_cast<PackedType>($1->get()); const PackedType *PTy = dyn_cast<PackedType>($1.type->get());
if (PTy == 0) if (PTy == 0)
GEN_ERROR("Cannot make packed constant with type: '" + GEN_ERROR("Cannot make packed constant with type: '" +
(*$1)->getDescription() + "'!"); $1.type->get()->getDescription() + "'!");
const Type *ETy = PTy->getElementType(); const Type *ETy = PTy->getElementType();
int NumElements = PTy->getNumElements(); int NumElements = PTy->getNumElements();
@ -1497,14 +1519,14 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
} }
$$ = ConstantPacked::get(PTy, *$3); $$ = ConstantPacked::get(PTy, *$3);
delete $1; delete $3; delete $1.type; delete $3;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| Types '{' ConstVector '}' { | Types '{' ConstVector '}' {
const StructType *STy = dyn_cast<StructType>($1->get()); const StructType *STy = dyn_cast<StructType>($1.type->get());
if (STy == 0) if (STy == 0)
GEN_ERROR("Cannot make struct constant with type: '" + GEN_ERROR("Cannot make struct constant with type: '" +
(*$1)->getDescription() + "'!"); $1.type->get()->getDescription() + "'!");
if ($3->size() != STy->getNumContainedTypes()) if ($3->size() != STy->getNumContainedTypes())
GEN_ERROR("Illegal number of initializers for structure type!"); GEN_ERROR("Illegal number of initializers for structure type!");
@ -1518,39 +1540,39 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
" of structure initializer!"); " of structure initializer!");
$$ = ConstantStruct::get(STy, *$3); $$ = ConstantStruct::get(STy, *$3);
delete $1; delete $3; delete $1.type; delete $3;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| Types '{' '}' { | Types '{' '}' {
const StructType *STy = dyn_cast<StructType>($1->get()); const StructType *STy = dyn_cast<StructType>($1.type->get());
if (STy == 0) if (STy == 0)
GEN_ERROR("Cannot make struct constant with type: '" + GEN_ERROR("Cannot make struct constant with type: '" +
(*$1)->getDescription() + "'!"); $1.type->get()->getDescription() + "'!");
if (STy->getNumContainedTypes() != 0) if (STy->getNumContainedTypes() != 0)
GEN_ERROR("Illegal number of initializers for structure type!"); GEN_ERROR("Illegal number of initializers for structure type!");
$$ = ConstantStruct::get(STy, std::vector<Constant*>()); $$ = ConstantStruct::get(STy, std::vector<Constant*>());
delete $1; delete $1.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| Types NULL_TOK { | Types NULL_TOK {
const PointerType *PTy = dyn_cast<PointerType>($1->get()); const PointerType *PTy = dyn_cast<PointerType>($1.type->get());
if (PTy == 0) if (PTy == 0)
GEN_ERROR("Cannot make null pointer constant with type: '" + GEN_ERROR("Cannot make null pointer constant with type: '" +
(*$1)->getDescription() + "'!"); $1.type->get()->getDescription() + "'!");
$$ = ConstantPointerNull::get(PTy); $$ = ConstantPointerNull::get(PTy);
delete $1; delete $1.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| Types UNDEF { | Types UNDEF {
$$ = UndefValue::get($1->get()); $$ = UndefValue::get($1.type->get());
delete $1; delete $1.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| Types SymbolicValueRef { | Types SymbolicValueRef {
const PointerType *Ty = dyn_cast<PointerType>($1->get()); const PointerType *Ty = dyn_cast<PointerType>($1.type->get());
if (Ty == 0) if (Ty == 0)
GEN_ERROR("Global const reference must be a pointer type!"); GEN_ERROR("Global const reference must be a pointer type!");
@ -1607,35 +1629,35 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
} }
$$ = cast<GlobalValue>(V); $$ = cast<GlobalValue>(V);
delete $1; // Free the type handle delete $1.type; // Free the type handle
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| Types ConstExpr { | Types ConstExpr {
if ($1->get() != $2->getType()) if ($1.type->get() != $2->getType())
GEN_ERROR("Mismatched types for constant expression!"); GEN_ERROR("Mismatched types for constant expression!");
$$ = $2; $$ = $2;
delete $1; delete $1.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| Types ZEROINITIALIZER { | Types ZEROINITIALIZER {
const Type *Ty = $1->get(); const Type *Ty = $1.type->get();
if (isa<FunctionType>(Ty) || Ty == Type::LabelTy || isa<OpaqueType>(Ty)) if (isa<FunctionType>(Ty) || Ty == Type::LabelTy || isa<OpaqueType>(Ty))
GEN_ERROR("Cannot create a null initialized value of this type!"); GEN_ERROR("Cannot create a null initialized value of this type!");
$$ = Constant::getNullValue(Ty); $$ = Constant::getNullValue(Ty);
delete $1; delete $1.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
}; };
ConstVal : SIntType EINT64VAL { // integral constants ConstVal : SIntType EINT64VAL { // integral constants
if (!ConstantInt::isValueValidForType($1, $2)) if (!ConstantInt::isValueValidForType($1.type->get(), $2))
GEN_ERROR("Constant value doesn't fit in type!"); GEN_ERROR("Constant value doesn't fit in type!");
$$ = ConstantInt::get($1, $2); $$ = ConstantInt::get($1.type->get(), $2);
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| UIntType EUINT64VAL { // integral constants | UIntType EUINT64VAL { // integral constants
if (!ConstantInt::isValueValidForType($1, $2)) if (!ConstantInt::isValueValidForType($1.type->get(), $2))
GEN_ERROR("Constant value doesn't fit in type!"); GEN_ERROR("Constant value doesn't fit in type!");
$$ = ConstantInt::get($1, $2); $$ = ConstantInt::get($1.type->get(), $2);
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| BOOL TRUETOK { // Boolean constants | BOOL TRUETOK { // Boolean constants
@ -1647,9 +1669,9 @@ ConstVal : SIntType EINT64VAL { // integral constants
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| FPType FPVAL { // Float & Double constants | FPType FPVAL { // Float & Double constants
if (!ConstantFP::isValueValidForType($1, $2)) if (!ConstantFP::isValueValidForType($1.type->get(), $2))
GEN_ERROR("Floating point constant invalid for type!!"); GEN_ERROR("Floating point constant invalid for type!!");
$$ = ConstantFP::get($1, $2); $$ = ConstantFP::get($1.type->get(), $2);
CHECK_FOR_ERROR CHECK_FOR_ERROR
}; };
@ -1658,11 +1680,11 @@ ConstExpr: CAST '(' ConstVal TO Types ')' {
if (!$3->getType()->isFirstClassType()) if (!$3->getType()->isFirstClassType())
GEN_ERROR("cast constant expression from a non-primitive type: '" + GEN_ERROR("cast constant expression from a non-primitive type: '" +
$3->getType()->getDescription() + "'!"); $3->getType()->getDescription() + "'!");
if (!$5->get()->isFirstClassType()) if (!$5.type->get()->isFirstClassType())
GEN_ERROR("cast constant expression to a non-primitive type: '" + GEN_ERROR("cast constant expression to a non-primitive type: '" +
$5->get()->getDescription() + "'!"); $5.type->get()->getDescription() + "'!");
$$ = ConstantExpr::getCast($3, $5->get()); $$ = ConstantExpr::getCast($3, $5.type->get());
delete $5; delete $5.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| GETELEMENTPTR '(' ConstVal IndexList ')' { | GETELEMENTPTR '(' ConstVal IndexList ')' {
@ -1853,16 +1875,16 @@ ConstPool : ConstPool OptAssign TYPE TypesV {
// If types are not resolved eagerly, then the two types will not be // If types are not resolved eagerly, then the two types will not be
// determined to be the same type! // determined to be the same type!
// //
ResolveTypeTo($2, *$4); ResolveTypeTo($2, $4.type->get());
if (!setTypeName(*$4, $2) && !$2) { if (!setTypeName($4.type->get(), $2) && !$2) {
CHECK_FOR_ERROR CHECK_FOR_ERROR
// If this is a named type that is not a redefinition, add it to the slot // If this is a named type that is not a redefinition, add it to the slot
// table. // table.
CurModule.Types.push_back(*$4); CurModule.Types.push_back($4);
} else {
delete $4.type;
} }
delete $4;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| ConstPool FunctionProto { // Function prototypes can be in const pool | ConstPool FunctionProto { // Function prototypes can be in const pool
@ -1880,26 +1902,29 @@ ConstPool : ConstPool OptAssign TYPE TypesV {
CurGV = 0; CurGV = 0;
} }
| ConstPool OptAssign EXTERNAL GlobalType Types { | ConstPool OptAssign EXTERNAL GlobalType Types {
CurGV = ParseGlobalVariable($2, GlobalValue::ExternalLinkage, $4, *$5, 0); CurGV = ParseGlobalVariable($2, GlobalValue::ExternalLinkage, $4,
$5.type->get(), 0);
CHECK_FOR_ERROR CHECK_FOR_ERROR
delete $5; delete $5.type;
} GlobalVarAttributes { } GlobalVarAttributes {
CurGV = 0; CurGV = 0;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| ConstPool OptAssign DLLIMPORT GlobalType Types { | ConstPool OptAssign DLLIMPORT GlobalType Types {
CurGV = ParseGlobalVariable($2, GlobalValue::DLLImportLinkage, $4, *$5, 0); CurGV = ParseGlobalVariable($2, GlobalValue::DLLImportLinkage, $4,
$5.type->get(), 0);
CHECK_FOR_ERROR CHECK_FOR_ERROR
delete $5; delete $5.type;
} GlobalVarAttributes { } GlobalVarAttributes {
CurGV = 0; CurGV = 0;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| ConstPool OptAssign EXTERN_WEAK GlobalType Types { | ConstPool OptAssign EXTERN_WEAK GlobalType Types {
CurGV = CurGV =
ParseGlobalVariable($2, GlobalValue::ExternalWeakLinkage, $4, *$5, 0); ParseGlobalVariable($2, GlobalValue::ExternalWeakLinkage, $4,
$5.type->get(), 0);
CHECK_FOR_ERROR CHECK_FOR_ERROR
delete $5; delete $5.type;
} GlobalVarAttributes { } GlobalVarAttributes {
CurGV = 0; CurGV = 0;
CHECK_FOR_ERROR CHECK_FOR_ERROR
@ -1977,9 +2002,9 @@ Name : VAR_ID | STRINGCONSTANT;
OptName : Name | /*empty*/ { $$ = 0; }; OptName : Name | /*empty*/ { $$ = 0; };
ArgVal : Types OptName { ArgVal : Types OptName {
if (*$1 == Type::VoidTy) if ($1.type->get() == Type::VoidTy)
GEN_ERROR("void typed arguments are invalid!"); GEN_ERROR("void typed arguments are invalid!");
$$ = new std::pair<PATypeHolder*, char*>($1, $2); $$ = new std::pair<TypeInfo, char*>($1, $2);
CHECK_FOR_ERROR CHECK_FOR_ERROR
}; };
@ -1990,7 +2015,7 @@ ArgListH : ArgListH ',' ArgVal {
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| ArgVal { | ArgVal {
$$ = new std::vector<std::pair<PATypeHolder*,char*> >(); $$ = new std::vector<std::pair<TypeInfo,char*> >();
$$->push_back(*$1); $$->push_back(*$1);
delete $1; delete $1;
CHECK_FOR_ERROR CHECK_FOR_ERROR
@ -2002,13 +2027,18 @@ ArgList : ArgListH {
} }
| ArgListH ',' DOTDOTDOT { | ArgListH ',' DOTDOTDOT {
$$ = $1; $$ = $1;
$$->push_back(std::pair<PATypeHolder*, TypeInfo TI;
char*>(new PATypeHolder(Type::VoidTy), 0)); TI.type = new PATypeHolder(Type::VoidTy);
TI.signedness = isSignless;
$$->push_back(std::pair<TypeInfo,char*>(TI,(char*)0));
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| DOTDOTDOT { | DOTDOTDOT {
$$ = new std::vector<std::pair<PATypeHolder*,char*> >(); $$ = new std::vector<std::pair<TypeInfo,char*> >();
$$->push_back(std::make_pair(new PATypeHolder(Type::VoidTy), (char*)0)); TypeInfo TI;
TI.type = new PATypeHolder(Type::VoidTy);
TI.signedness = isSignless;
$$->push_back(std::make_pair(TI, (char*)0));
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| /* empty */ { | /* empty */ {
@ -2022,22 +2052,23 @@ FunctionHeaderH : OptCallingConv TypesV Name '(' ArgList ')'
std::string FunctionName($3); std::string FunctionName($3);
free($3); // Free strdup'd memory! free($3); // Free strdup'd memory!
if (!(*$2)->isFirstClassType() && *$2 != Type::VoidTy) if (!($2.type->get())->isFirstClassType() && $2.type->get() != Type::VoidTy)
GEN_ERROR("LLVM functions cannot return aggregate types!"); GEN_ERROR("LLVM functions cannot return aggregate types!");
std::vector<const Type*> ParamTypeList; std::vector<const Type*> ParamTypeList;
if ($5) { // If there are arguments... if ($5) { // If there are arguments...
for (std::vector<std::pair<PATypeHolder*,char*> >::iterator I = $5->begin(); for (std::vector<std::pair<TypeInfo,char*> >::iterator I = $5->begin();
I != $5->end(); ++I) I != $5->end(); ++I)
ParamTypeList.push_back(I->first->get()); ParamTypeList.push_back(I->first.type->get());
} }
bool isVarArg = ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy; bool isVarArg = ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy;
if (isVarArg) ParamTypeList.pop_back(); if (isVarArg) ParamTypeList.pop_back();
const FunctionType *FT = FunctionType::get(*$2, ParamTypeList, isVarArg); const FunctionType *FT = FunctionType::get($2.type->get(), ParamTypeList,
isVarArg);
const PointerType *PFT = PointerType::get(FT); const PointerType *PFT = PointerType::get(FT);
delete $2; delete $2.type;
ValID ID; ValID ID;
if (!FunctionName.empty()) { if (!FunctionName.empty()) {
@ -2091,21 +2122,19 @@ FunctionHeaderH : OptCallingConv TypesV Name '(' ArgList ')'
// Add all of the arguments we parsed to the function... // Add all of the arguments we parsed to the function...
if ($5) { // Is null if empty... if ($5) { // Is null if empty...
if (isVarArg) { // Nuke the last entry if (isVarArg) { // Nuke the last entry
assert($5->back().first->get() == Type::VoidTy && $5->back().second == 0&& assert($5->back().first.type->get() == Type::VoidTy &&
"Not a varargs marker!"); $5->back().second == 0 && "Not a varargs marker!");
delete $5->back().first; delete $5->back().first.type;
$5->pop_back(); // Delete the last entry $5->pop_back(); // Delete the last entry
} }
Function::arg_iterator ArgIt = Fn->arg_begin(); Function::arg_iterator ArgIt = Fn->arg_begin();
for (std::vector<std::pair<PATypeHolder*,char*> >::iterator I = $5->begin(); for (std::vector<std::pair<TypeInfo,char*> >::iterator I = $5->begin();
I != $5->end(); ++I, ++ArgIt) { I != $5->end(); ++I, ++ArgIt) {
delete I->first; // Delete the typeholder... delete I->first.type; // Delete the typeholder...
setValueName(ArgIt, I->second); // Insert arg into symtab... setValueName(ArgIt, I->second); // Insert arg into symtab...
CHECK_FOR_ERROR CHECK_FOR_ERROR
InsertValue(ArgIt); InsertValue(ArgIt);
} }
delete $5; // We're now done with the argument list delete $5; // We're now done with the argument list
} }
CHECK_FOR_ERROR CHECK_FOR_ERROR
@ -2189,12 +2218,7 @@ ConstValueRef : ESINT64VAL { // A reference to a direct constant
PackedType* pt = PackedType::get(ETy, NumElements); PackedType* pt = PackedType::get(ETy, NumElements);
PATypeHolder* PTy = new PATypeHolder( PATypeHolder* PTy = new PATypeHolder(
HandleUpRefs( HandleUpRefs(PackedType::get( ETy, NumElements)));
PackedType::get(
ETy,
NumElements)
)
);
// Verify all elements are correct type! // Verify all elements are correct type!
for (unsigned i = 0; i < $2->size(); i++) { for (unsigned i = 0; i < $2->size(); i++) {
@ -2243,7 +2267,7 @@ ValueRef : SymbolicValueRef | ConstValueRef;
// type immediately preceeds the value reference, and allows complex constant // type immediately preceeds the value reference, and allows complex constant
// pool references (for things like: 'ret [2 x int] [ int 12, int 42]') // pool references (for things like: 'ret [2 x int] [ int 12, int 42]')
ResolvedVal : Types ValueRef { ResolvedVal : Types ValueRef {
$$ = getVal(*$1, $2); delete $1; $$ = getVal($1.type->get(), $2); delete $1.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
}; };
@ -2324,7 +2348,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result...
$$ = new BranchInst(tmpBBA, tmpBBB, tmpVal); $$ = new BranchInst(tmpBBA, tmpBBB, tmpVal);
} }
| SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' { | SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' {
Value* tmpVal = getVal($2, $3); Value* tmpVal = getVal($2.type->get(), $3);
CHECK_FOR_ERROR CHECK_FOR_ERROR
BasicBlock* tmpBB = getBBVal($6); BasicBlock* tmpBB = getBBVal($6);
CHECK_FOR_ERROR CHECK_FOR_ERROR
@ -2343,7 +2367,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result...
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| SWITCH IntType ValueRef ',' LABEL ValueRef '[' ']' { | SWITCH IntType ValueRef ',' LABEL ValueRef '[' ']' {
Value* tmpVal = getVal($2, $3); Value* tmpVal = getVal($2.type->get(), $3);
CHECK_FOR_ERROR CHECK_FOR_ERROR
BasicBlock* tmpBB = getBBVal($6); BasicBlock* tmpBB = getBBVal($6);
CHECK_FOR_ERROR CHECK_FOR_ERROR
@ -2356,7 +2380,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result...
const PointerType *PFTy; const PointerType *PFTy;
const FunctionType *Ty; const FunctionType *Ty;
if (!(PFTy = dyn_cast<PointerType>($3->get())) || if (!(PFTy = dyn_cast<PointerType>($3.type->get())) ||
!(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) { !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
// Pull out the types of all of the arguments... // Pull out the types of all of the arguments...
std::vector<const Type*> ParamTypes; std::vector<const Type*> ParamTypes;
@ -2369,7 +2393,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result...
bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy; bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
if (isVarArg) ParamTypes.pop_back(); if (isVarArg) ParamTypes.pop_back();
Ty = FunctionType::get($3->get(), ParamTypes, isVarArg); Ty = FunctionType::get($3.type->get(), ParamTypes, isVarArg);
PFTy = PointerType::get(Ty); PFTy = PointerType::get(Ty);
} }
@ -2403,7 +2427,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result...
} }
cast<InvokeInst>($$)->setCallingConv($2); cast<InvokeInst>($$)->setCallingConv($2);
delete $3; delete $3.type;
delete $6; delete $6;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
@ -2420,7 +2444,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result...
JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef { JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef {
$$ = $1; $$ = $1;
Constant *V = cast<Constant>(getValNonImprovising($2, $3)); Constant *V = cast<Constant>(getValNonImprovising($2.type->get(), $3));
CHECK_FOR_ERROR CHECK_FOR_ERROR
if (V == 0) if (V == 0)
GEN_ERROR("May only switch on a constant pool value!"); GEN_ERROR("May only switch on a constant pool value!");
@ -2431,7 +2455,7 @@ JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef {
} }
| IntType ConstValueRef ',' LABEL ValueRef { | IntType ConstValueRef ',' LABEL ValueRef {
$$ = new std::vector<std::pair<Constant*, BasicBlock*> >(); $$ = new std::vector<std::pair<Constant*, BasicBlock*> >();
Constant *V = cast<Constant>(getValNonImprovising($1, $2)); Constant *V = cast<Constant>(getValNonImprovising($1.type->get(), $2));
CHECK_FOR_ERROR CHECK_FOR_ERROR
if (V == 0) if (V == 0)
@ -2453,12 +2477,12 @@ Inst : OptAssign InstVal {
PHIList : Types '[' ValueRef ',' ValueRef ']' { // Used for PHI nodes PHIList : Types '[' ValueRef ',' ValueRef ']' { // Used for PHI nodes
$$ = new std::list<std::pair<Value*, BasicBlock*> >(); $$ = new std::list<std::pair<Value*, BasicBlock*> >();
Value* tmpVal = getVal(*$1, $3); Value* tmpVal = getVal($1.type->get(), $3);
CHECK_FOR_ERROR CHECK_FOR_ERROR
BasicBlock* tmpBB = getBBVal($5); BasicBlock* tmpBB = getBBVal($5);
CHECK_FOR_ERROR CHECK_FOR_ERROR
$$->push_back(std::make_pair(tmpVal, tmpBB)); $$->push_back(std::make_pair(tmpVal, tmpBB));
delete $1; delete $1.type;
} }
| PHIList ',' '[' ValueRef ',' ValueRef ']' { | PHIList ',' '[' ValueRef ',' ValueRef ']' {
$$ = $1; $$ = $1;
@ -2493,55 +2517,55 @@ OptTailCall : TAIL CALL {
}; };
InstVal : ArithmeticOps Types ValueRef ',' ValueRef { InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
if (!(*$2)->isInteger() && !(*$2)->isFloatingPoint() && if (!$2.type->get()->isInteger() && !$2.type->get()->isFloatingPoint() &&
!isa<PackedType>((*$2).get())) !isa<PackedType>($2.type->get()))
GEN_ERROR( GEN_ERROR(
"Arithmetic operator requires integer, FP, or packed operands!"); "Arithmetic operator requires integer, FP, or packed operands!");
if (isa<PackedType>((*$2).get()) && if (isa<PackedType>($2.type->get()) &&
($1.opcode == Instruction::URem || ($1.opcode == Instruction::URem ||
$1.opcode == Instruction::SRem || $1.opcode == Instruction::SRem ||
$1.opcode == Instruction::FRem)) $1.opcode == Instruction::FRem))
GEN_ERROR("U/S/FRem not supported on packed types!"); GEN_ERROR("U/S/FRem not supported on packed types!");
// Upgrade the opcode from obsolete versions before we do anything with it. // Upgrade the opcode from obsolete versions before we do anything with it.
sanitizeOpCode($1,*$2); sanitizeOpCode($1,$2.type->get());
CHECK_FOR_ERROR; CHECK_FOR_ERROR;
Value* val1 = getVal(*$2, $3); Value* val1 = getVal($2.type->get(), $3);
CHECK_FOR_ERROR CHECK_FOR_ERROR
Value* val2 = getVal(*$2, $5); Value* val2 = getVal($2.type->get(), $5);
CHECK_FOR_ERROR CHECK_FOR_ERROR
$$ = BinaryOperator::create($1.opcode, val1, val2); $$ = BinaryOperator::create($1.opcode, val1, val2);
if ($$ == 0) if ($$ == 0)
GEN_ERROR("binary operator returned null!"); GEN_ERROR("binary operator returned null!");
delete $2; delete $2.type;
} }
| LogicalOps Types ValueRef ',' ValueRef { | LogicalOps Types ValueRef ',' ValueRef {
if (!(*$2)->isIntegral()) { if (!$2.type->get()->isIntegral()) {
if (!isa<PackedType>($2->get()) || if (!isa<PackedType>($2.type->get()) ||
!cast<PackedType>($2->get())->getElementType()->isIntegral()) !cast<PackedType>($2.type->get())->getElementType()->isIntegral())
GEN_ERROR("Logical operator requires integral operands!"); GEN_ERROR("Logical operator requires integral operands!");
} }
Value* tmpVal1 = getVal(*$2, $3); Value* tmpVal1 = getVal($2.type->get(), $3);
CHECK_FOR_ERROR CHECK_FOR_ERROR
Value* tmpVal2 = getVal(*$2, $5); Value* tmpVal2 = getVal($2.type->get(), $5);
CHECK_FOR_ERROR CHECK_FOR_ERROR
$$ = BinaryOperator::create($1.opcode, tmpVal1, tmpVal2); $$ = BinaryOperator::create($1.opcode, tmpVal1, tmpVal2);
if ($$ == 0) if ($$ == 0)
GEN_ERROR("binary operator returned null!"); GEN_ERROR("binary operator returned null!");
delete $2; delete $2.type;
} }
| SetCondOps Types ValueRef ',' ValueRef { | SetCondOps Types ValueRef ',' ValueRef {
if(isa<PackedType>((*$2).get())) { if(isa<PackedType>($2.type->get())) {
GEN_ERROR( GEN_ERROR(
"PackedTypes currently not supported in setcc instructions!"); "PackedTypes currently not supported in setcc instructions!");
} }
Value* tmpVal1 = getVal(*$2, $3); Value* tmpVal1 = getVal($2.type->get(), $3);
CHECK_FOR_ERROR CHECK_FOR_ERROR
Value* tmpVal2 = getVal(*$2, $5); Value* tmpVal2 = getVal($2.type->get(), $5);
CHECK_FOR_ERROR CHECK_FOR_ERROR
$$ = new SetCondInst($1.opcode, tmpVal1, tmpVal2); $$ = new SetCondInst($1.opcode, tmpVal1, tmpVal2);
if ($$ == 0) if ($$ == 0)
GEN_ERROR("binary operator returned null!"); GEN_ERROR("binary operator returned null!");
delete $2; delete $2.type;
} }
| NOT ResolvedVal { | NOT ResolvedVal {
std::cerr << "WARNING: Use of eliminated 'not' instruction:" std::cerr << "WARNING: Use of eliminated 'not' instruction:"
@ -2568,11 +2592,11 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| CAST ResolvedVal TO Types { | CAST ResolvedVal TO Types {
if (!$4->get()->isFirstClassType()) if (!$4.type->get()->isFirstClassType())
GEN_ERROR("cast instruction to a non-primitive type: '" + GEN_ERROR("cast instruction to a non-primitive type: '" +
$4->get()->getDescription() + "'!"); $4.type->get()->getDescription() + "'!");
$$ = new CastInst($2, *$4); $$ = new CastInst($2, $4.type->get());
delete $4; delete $4.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal { | SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
@ -2585,8 +2609,8 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
} }
| VAARG ResolvedVal ',' Types { | VAARG ResolvedVal ',' Types {
NewVarArgs = true; NewVarArgs = true;
$$ = new VAArgInst($2, *$4); $$ = new VAArgInst($2, $4.type->get());
delete $4; delete $4.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| VAARG_old ResolvedVal ',' Types { | VAARG_old ResolvedVal ',' Types {
@ -2605,8 +2629,8 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
CallInst* bar = new CallInst(NF, $2); CallInst* bar = new CallInst(NF, $2);
CurBB->getInstList().push_back(bar); CurBB->getInstList().push_back(bar);
CurBB->getInstList().push_back(new StoreInst(bar, foo)); CurBB->getInstList().push_back(new StoreInst(bar, foo));
$$ = new VAArgInst(foo, *$4); $$ = new VAArgInst(foo, $4.type->get());
delete $4; delete $4.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| VANEXT_old ResolvedVal ',' Types { | VANEXT_old ResolvedVal ',' Types {
@ -2626,10 +2650,10 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
CallInst* bar = new CallInst(NF, $2); CallInst* bar = new CallInst(NF, $2);
CurBB->getInstList().push_back(bar); CurBB->getInstList().push_back(bar);
CurBB->getInstList().push_back(new StoreInst(bar, foo)); CurBB->getInstList().push_back(new StoreInst(bar, foo));
Instruction* tmp = new VAArgInst(foo, *$4); Instruction* tmp = new VAArgInst(foo, $4.type->get());
CurBB->getInstList().push_back(tmp); CurBB->getInstList().push_back(tmp);
$$ = new LoadInst(foo); $$ = new LoadInst(foo);
delete $4; delete $4.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| EXTRACTELEMENT ResolvedVal ',' ResolvedVal { | EXTRACTELEMENT ResolvedVal ',' ResolvedVal {
@ -2669,7 +2693,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
const PointerType *PFTy = 0; const PointerType *PFTy = 0;
const FunctionType *Ty = 0; const FunctionType *Ty = 0;
if (!(PFTy = dyn_cast<PointerType>($3->get())) || if (!(PFTy = dyn_cast<PointerType>($3.type->get())) ||
!(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) { !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
// Pull out the types of all of the arguments... // Pull out the types of all of the arguments...
std::vector<const Type*> ParamTypes; std::vector<const Type*> ParamTypes;
@ -2682,10 +2706,11 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy; bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
if (isVarArg) ParamTypes.pop_back(); if (isVarArg) ParamTypes.pop_back();
if (!(*$3)->isFirstClassType() && *$3 != Type::VoidTy) if (!$3.type->get()->isFirstClassType() &&
$3.type->get() != Type::VoidTy)
GEN_ERROR("LLVM functions cannot return aggregate types!"); GEN_ERROR("LLVM functions cannot return aggregate types!");
Ty = FunctionType::get($3->get(), ParamTypes, isVarArg); Ty = FunctionType::get($3.type->get(), ParamTypes, isVarArg);
PFTy = PointerType::get(Ty); PFTy = PointerType::get(Ty);
} }
@ -2720,7 +2745,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
} }
cast<CallInst>($$)->setTailCall($1); cast<CallInst>($$)->setTailCall($1);
cast<CallInst>($$)->setCallingConv($2); cast<CallInst>($$)->setCallingConv($2);
delete $3; delete $3.type;
delete $6; delete $6;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
@ -2751,26 +2776,26 @@ OptVolatile : VOLATILE {
MemoryInst : MALLOC Types OptCAlign { MemoryInst : MALLOC Types OptCAlign {
$$ = new MallocInst(*$2, 0, $3); $$ = new MallocInst($2.type->get(), 0, $3);
delete $2; delete $2.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| MALLOC Types ',' UINT ValueRef OptCAlign { | MALLOC Types ',' UINT ValueRef OptCAlign {
Value* tmpVal = getVal($4, $5); Value* tmpVal = getVal($4.type->get(), $5);
CHECK_FOR_ERROR CHECK_FOR_ERROR
$$ = new MallocInst(*$2, tmpVal, $6); $$ = new MallocInst($2.type->get(), tmpVal, $6);
delete $2; delete $2.type;
} }
| ALLOCA Types OptCAlign { | ALLOCA Types OptCAlign {
$$ = new AllocaInst(*$2, 0, $3); $$ = new AllocaInst($2.type->get(), 0, $3);
delete $2; delete $2.type;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| ALLOCA Types ',' UINT ValueRef OptCAlign { | ALLOCA Types ',' UINT ValueRef OptCAlign {
Value* tmpVal = getVal($4, $5); Value* tmpVal = getVal($4.type->get(), $5);
CHECK_FOR_ERROR CHECK_FOR_ERROR
$$ = new AllocaInst(*$2, tmpVal, $6); $$ = new AllocaInst($2.type->get(), tmpVal, $6);
delete $2; delete $2.type;
} }
| FREE ResolvedVal { | FREE ResolvedVal {
if (!isa<PointerType>($2->getType())) if (!isa<PointerType>($2->getType()))
@ -2781,54 +2806,54 @@ MemoryInst : MALLOC Types OptCAlign {
} }
| OptVolatile LOAD Types ValueRef { | OptVolatile LOAD Types ValueRef {
if (!isa<PointerType>($3->get())) if (!isa<PointerType>($3.type->get()))
GEN_ERROR("Can't load from nonpointer type: " + GEN_ERROR("Can't load from nonpointer type: " +
(*$3)->getDescription()); $3.type->get()->getDescription());
if (!cast<PointerType>($3->get())->getElementType()->isFirstClassType()) if (!cast<PointerType>($3.type->get())->getElementType()->isFirstClassType())
GEN_ERROR("Can't load from pointer of non-first-class type: " + GEN_ERROR("Can't load from pointer of non-first-class type: " +
(*$3)->getDescription()); $3.type->get()->getDescription());
Value* tmpVal = getVal(*$3, $4); Value* tmpVal = getVal($3.type->get(), $4);
CHECK_FOR_ERROR CHECK_FOR_ERROR
$$ = new LoadInst(tmpVal, "", $1); $$ = new LoadInst(tmpVal, "", $1);
delete $3; delete $3.type;
} }
| OptVolatile STORE ResolvedVal ',' Types ValueRef { | OptVolatile STORE ResolvedVal ',' Types ValueRef {
const PointerType *PT = dyn_cast<PointerType>($5->get()); const PointerType *PT = dyn_cast<PointerType>($5.type->get());
if (!PT) if (!PT)
GEN_ERROR("Can't store to a nonpointer type: " + GEN_ERROR("Can't store to a nonpointer type: " +
(*$5)->getDescription()); ($5.type->get())->getDescription());
const Type *ElTy = PT->getElementType(); const Type *ElTy = PT->getElementType();
if (ElTy != $3->getType()) if (ElTy != $3->getType())
GEN_ERROR("Can't store '" + $3->getType()->getDescription() + GEN_ERROR("Can't store '" + $3->getType()->getDescription() +
"' into space of type '" + ElTy->getDescription() + "'!"); "' into space of type '" + ElTy->getDescription() + "'!");
Value* tmpVal = getVal(*$5, $6); Value* tmpVal = getVal($5.type->get(), $6);
CHECK_FOR_ERROR CHECK_FOR_ERROR
$$ = new StoreInst($3, tmpVal, $1); $$ = new StoreInst($3, tmpVal, $1);
delete $5; delete $5.type;
} }
| GETELEMENTPTR Types ValueRef IndexList { | GETELEMENTPTR Types ValueRef IndexList {
if (!isa<PointerType>($2->get())) if (!isa<PointerType>($2.type->get()))
GEN_ERROR("getelementptr insn requires pointer operand!"); GEN_ERROR("getelementptr insn requires pointer operand!");
// LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte struct // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte struct
// indices to uint struct indices for compatibility. // indices to uint struct indices for compatibility.
generic_gep_type_iterator<std::vector<Value*>::iterator> generic_gep_type_iterator<std::vector<Value*>::iterator>
GTI = gep_type_begin($2->get(), $4->begin(), $4->end()), GTI = gep_type_begin($2.type->get(), $4->begin(), $4->end()),
GTE = gep_type_end($2->get(), $4->begin(), $4->end()); GTE = gep_type_end($2.type->get(), $4->begin(), $4->end());
for (unsigned i = 0, e = $4->size(); i != e && GTI != GTE; ++i, ++GTI) for (unsigned i = 0, e = $4->size(); i != e && GTI != GTE; ++i, ++GTI)
if (isa<StructType>(*GTI)) // Only change struct indices if (isa<StructType>(*GTI)) // Only change struct indices
if (ConstantInt *CUI = dyn_cast<ConstantInt>((*$4)[i])) if (ConstantInt *CUI = dyn_cast<ConstantInt>((*$4)[i]))
if (CUI->getType() == Type::UByteTy) if (CUI->getType() == Type::UByteTy)
(*$4)[i] = ConstantExpr::getCast(CUI, Type::UIntTy); (*$4)[i] = ConstantExpr::getCast(CUI, Type::UIntTy);
if (!GetElementPtrInst::getIndexedType(*$2, *$4, true)) if (!GetElementPtrInst::getIndexedType($2.type->get(), *$4, true))
GEN_ERROR("Invalid getelementptr indices for type '" + GEN_ERROR("Invalid getelementptr indices for type '" +
(*$2)->getDescription()+ "'!"); $2.type->get()->getDescription()+ "'!");
Value* tmpVal = getVal(*$2, $3); Value* tmpVal = getVal($2.type->get(), $3);
CHECK_FOR_ERROR CHECK_FOR_ERROR
$$ = new GetElementPtrInst(tmpVal, *$4); $$ = new GetElementPtrInst(tmpVal, *$4);
delete $2; delete $2.type;
delete $4; delete $4;
}; };