#include "llvm/DerivedTypes.h"
#include "llvm/InlineAsm.h"
#include "llvm/Instructions.h"
+#include "llvm/LLVMContext.h"
+#include "llvm/Metadata.h"
#include "llvm/Module.h"
+#include "llvm/Operator.h"
#include "llvm/ValueSymbolTable.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
t_Null, t_Undef, t_Zero, // No value.
t_EmptyArray, // No value: []
t_Constant, // Value in ConstantVal.
- t_InlineAsm // Value in StrVal/StrVal2/UIntVal.
+ t_InlineAsm, // Value in StrVal/StrVal2/UIntVal.
+ t_Metadata // Value in MetadataVal.
} Kind;
LLParser::LocTy Loc;
APSInt APSIntVal;
APFloat APFloatVal;
Constant *ConstantVal;
+ MetadataBase *MetadataVal;
ValID() : APFloatVal(0.0) {}
};
}
"use of undefined value '@" +
utostr(ForwardRefValIDs.begin()->first) + "'");
+ if (!ForwardRefMDNodes.empty())
+ return Error(ForwardRefMDNodes.begin()->second.second,
+ "use of undefined metadata '!" +
+ utostr(ForwardRefMDNodes.begin()->first) + "'");
+
+
// Look for intrinsic functions and CallInst that need to be upgraded
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; )
UpgradeCallsToIntrinsic(FI++); // must be post-increment, as we remove
case lltok::kw_target: if (ParseTargetDefinition()) return true; break;
case lltok::kw_deplibs: if (ParseDepLibs()) return true; break;
case lltok::kw_type: if (ParseUnnamedType()) return true; break;
+ case lltok::LocalVarID: if (ParseUnnamedType()) return true; break;
case lltok::StringConstant: // FIXME: REMOVE IN LLVM 3.0
case lltok::LocalVar: if (ParseNamedType()) return true; break;
+ case lltok::GlobalID: if (ParseUnnamedGlobal()) return true; break;
case lltok::GlobalVar: if (ParseNamedGlobal()) return true; break;
+ case lltok::Metadata: if (ParseStandaloneMetadata()) return true; break;
+ case lltok::NamedMD: if (ParseNamedMetadata()) return true; break;
// The Global variable production with no name can have many different
// optional leading prefixes, the production is:
// GlobalVar ::= OptionalLinkage OptionalVisibility OptionalThreadLocal
// OptionalAddrSpace ('constant'|'global') ...
- case lltok::kw_internal: // OptionalLinkage
- case lltok::kw_weak: // OptionalLinkage
- case lltok::kw_linkonce: // OptionalLinkage
- case lltok::kw_appending: // OptionalLinkage
- case lltok::kw_dllexport: // OptionalLinkage
- case lltok::kw_common: // OptionalLinkage
- case lltok::kw_dllimport: // OptionalLinkage
- case lltok::kw_extern_weak: // OptionalLinkage
- case lltok::kw_external: { // OptionalLinkage
+ case lltok::kw_private : // OptionalLinkage
+ case lltok::kw_linker_private: // OptionalLinkage
+ case lltok::kw_internal: // OptionalLinkage
+ case lltok::kw_weak: // OptionalLinkage
+ case lltok::kw_weak_odr: // OptionalLinkage
+ case lltok::kw_linkonce: // OptionalLinkage
+ case lltok::kw_linkonce_odr: // OptionalLinkage
+ case lltok::kw_appending: // OptionalLinkage
+ case lltok::kw_dllexport: // OptionalLinkage
+ case lltok::kw_common: // OptionalLinkage
+ case lltok::kw_dllimport: // OptionalLinkage
+ case lltok::kw_extern_weak: // OptionalLinkage
+ case lltok::kw_external: { // OptionalLinkage
unsigned Linkage, Visibility;
if (ParseOptionalLinkage(Linkage) ||
ParseOptionalVisibility(Visibility) ||
- ParseGlobal("", 0, Linkage, true, Visibility))
+ ParseGlobal("", SMLoc(), Linkage, true, Visibility))
return true;
break;
}
case lltok::kw_protected: { // OptionalVisibility
unsigned Visibility;
if (ParseOptionalVisibility(Visibility) ||
- ParseGlobal("", 0, 0, false, Visibility))
+ ParseGlobal("", SMLoc(), 0, false, Visibility))
return true;
break;
}
case lltok::kw_addrspace: // OptionalAddrSpace
case lltok::kw_constant: // GlobalType
case lltok::kw_global: // GlobalType
- if (ParseGlobal("", 0, 0, false, 0)) return true;
+ if (ParseGlobal("", SMLoc(), 0, false, 0)) return true;
break;
}
}
return ParseToken(lltok::rsquare, "expected ']' at end of list");
}
-/// toplevelentity
+/// ParseUnnamedType:
/// ::= 'type' type
+/// ::= LocalVarID '=' 'type' type
bool LLParser::ParseUnnamedType() {
+ unsigned TypeID = NumberedTypes.size();
+
+ // Handle the LocalVarID form.
+ if (Lex.getKind() == lltok::LocalVarID) {
+ if (Lex.getUIntVal() != TypeID)
+ return Error(Lex.getLoc(), "type expected to be numbered '%" +
+ utostr(TypeID) + "'");
+ Lex.Lex(); // eat LocalVarID;
+
+ if (ParseToken(lltok::equal, "expected '=' after name"))
+ return true;
+ }
+
assert(Lex.getKind() == lltok::kw_type);
LocTy TypeLoc = Lex.getLoc();
Lex.Lex(); // eat kw_type
- PATypeHolder Ty(Type::VoidTy);
+ PATypeHolder Ty(Type::getVoidTy(Context));
if (ParseType(Ty)) return true;
- unsigned TypeID = NumberedTypes.size();
-
- // We don't allow assigning names to void type
- if (Ty == Type::VoidTy)
- return Error(TypeLoc, "can't assign name to the void type");
-
// See if this type was previously referenced.
std::map<unsigned, std::pair<PATypeHolder, LocTy> >::iterator
FI = ForwardRefTypeIDs.find(TypeID);
LocTy NameLoc = Lex.getLoc();
Lex.Lex(); // eat LocalVar.
- PATypeHolder Ty(Type::VoidTy);
+ PATypeHolder Ty(Type::getVoidTy(Context));
if (ParseToken(lltok::equal, "expected '=' after name") ||
ParseToken(lltok::kw_type, "expected 'type' after name") ||
ParseType(Ty))
return true;
- // We don't allow assigning names to void type
- if (Ty == Type::VoidTy)
- return Error(NameLoc, "can't assign name '" + Name + "' to the void type");
-
// Set the type name, checking for conflicts as we do so.
bool AlreadyExists = M->addTypeName(Name, Ty);
if (!AlreadyExists) return false;
IsConstant = true;
else if (Lex.getKind() == lltok::kw_global)
IsConstant = false;
- else
+ else {
+ IsConstant = false;
return TokError("expected 'global' or 'constant'");
+ }
Lex.Lex();
return false;
}
+/// ParseUnnamedGlobal:
+/// OptionalVisibility ALIAS ...
+/// OptionalLinkage OptionalVisibility ... -> global variable
+/// GlobalID '=' OptionalVisibility ALIAS ...
+/// GlobalID '=' OptionalLinkage OptionalVisibility ... -> global variable
+bool LLParser::ParseUnnamedGlobal() {
+ unsigned VarID = NumberedVals.size();
+ std::string Name;
+ LocTy NameLoc = Lex.getLoc();
+
+ // Handle the GlobalID form.
+ if (Lex.getKind() == lltok::GlobalID) {
+ if (Lex.getUIntVal() != VarID)
+ return Error(Lex.getLoc(), "variable expected to be numbered '%" +
+ utostr(VarID) + "'");
+ Lex.Lex(); // eat GlobalID;
+
+ if (ParseToken(lltok::equal, "expected '=' after name"))
+ return true;
+ }
+
+ bool HasLinkage;
+ unsigned Linkage, Visibility;
+ if (ParseOptionalLinkage(Linkage, HasLinkage) ||
+ ParseOptionalVisibility(Visibility))
+ return true;
+
+ if (HasLinkage || Lex.getKind() != lltok::kw_alias)
+ return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility);
+ return ParseAlias(Name, NameLoc, Visibility);
+}
+
/// ParseNamedGlobal:
/// GlobalVar '=' OptionalVisibility ALIAS ...
/// GlobalVar '=' OptionalLinkage OptionalVisibility ... -> global variable
return ParseAlias(Name, NameLoc, Visibility);
}
+// MDString:
+// ::= '!' STRINGCONSTANT
+bool LLParser::ParseMDString(MetadataBase *&MDS) {
+ std::string Str;
+ if (ParseStringConstant(Str)) return true;
+ MDS = MDString::get(Context, Str);
+ return false;
+}
+
+// MDNode:
+// ::= '!' MDNodeNumber
+bool LLParser::ParseMDNode(MetadataBase *&Node) {
+ // !{ ..., !42, ... }
+ unsigned MID = 0;
+ if (ParseUInt32(MID)) return true;
+
+ // Check existing MDNode.
+ std::map<unsigned, MetadataBase *>::iterator I = MetadataCache.find(MID);
+ if (I != MetadataCache.end()) {
+ Node = I->second;
+ return false;
+ }
+
+ // Check known forward references.
+ std::map<unsigned, std::pair<MetadataBase *, LocTy> >::iterator
+ FI = ForwardRefMDNodes.find(MID);
+ if (FI != ForwardRefMDNodes.end()) {
+ Node = FI->second.first;
+ return false;
+ }
+
+ // Create MDNode forward reference
+ SmallVector<Value *, 1> Elts;
+ std::string FwdRefName = "llvm.mdnode.fwdref." + utostr(MID);
+ Elts.push_back(MDString::get(Context, FwdRefName));
+ MDNode *FwdNode = MDNode::get(Context, Elts.data(), Elts.size());
+ ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.getLoc());
+ Node = FwdNode;
+ return false;
+}
+
+///ParseNamedMetadata:
+/// !foo = !{ !1, !2 }
+bool LLParser::ParseNamedMetadata() {
+ assert(Lex.getKind() == lltok::NamedMD);
+ Lex.Lex();
+ std::string Name = Lex.getStrVal();
+
+ if (ParseToken(lltok::equal, "expected '=' here"))
+ return true;
+
+ if (Lex.getKind() != lltok::Metadata)
+ return TokError("Expected '!' here");
+ Lex.Lex();
+
+ if (Lex.getKind() != lltok::lbrace)
+ return TokError("Expected '{' here");
+ Lex.Lex();
+ SmallVector<MetadataBase *, 8> Elts;
+ do {
+ if (Lex.getKind() != lltok::Metadata)
+ return TokError("Expected '!' here");
+ Lex.Lex();
+ MetadataBase *N = 0;
+ if (ParseMDNode(N)) return true;
+ Elts.push_back(N);
+ } while (EatIfPresent(lltok::comma));
+
+ if (ParseToken(lltok::rbrace, "expected end of metadata node"))
+ return true;
+
+ NamedMDNode::Create(Context, Name, Elts.data(), Elts.size(), M);
+ return false;
+}
+
+/// ParseStandaloneMetadata:
+/// !42 = !{...}
+bool LLParser::ParseStandaloneMetadata() {
+ assert(Lex.getKind() == lltok::Metadata);
+ Lex.Lex();
+ unsigned MetadataID = 0;
+ if (ParseUInt32(MetadataID))
+ return true;
+ if (MetadataCache.find(MetadataID) != MetadataCache.end())
+ return TokError("Metadata id is already used");
+ if (ParseToken(lltok::equal, "expected '=' here"))
+ return true;
+
+ LocTy TyLoc;
+ PATypeHolder Ty(Type::getVoidTy(Context));
+ if (ParseType(Ty, TyLoc))
+ return true;
+
+ if (Lex.getKind() != lltok::Metadata)
+ return TokError("Expected metadata here");
+
+ Lex.Lex();
+ if (Lex.getKind() != lltok::lbrace)
+ return TokError("Expected '{' here");
+
+ SmallVector<Value *, 16> Elts;
+ if (ParseMDNodeVector(Elts)
+ || ParseToken(lltok::rbrace, "expected end of metadata node"))
+ return true;
+
+ MDNode *Init = MDNode::get(Context, Elts.data(), Elts.size());
+ MetadataCache[MetadataID] = Init;
+ std::map<unsigned, std::pair<MetadataBase *, LocTy> >::iterator
+ FI = ForwardRefMDNodes.find(MetadataID);
+ if (FI != ForwardRefMDNodes.end()) {
+ MDNode *FwdNode = cast<MDNode>(FI->second.first);
+ FwdNode->replaceAllUsesWith(Init);
+ ForwardRefMDNodes.erase(FI);
+ }
+
+ return false;
+}
+
/// ParseAlias:
/// ::= GlobalVar '=' OptionalVisibility 'alias' OptionalLinkage Aliasee
/// Aliasee
-/// ::= TypeAndValue | 'bitcast' '(' TypeAndValue 'to' Type ')'
+/// ::= TypeAndValue
+/// ::= 'bitcast' '(' TypeAndValue 'to' Type ')'
+/// ::= 'getelementptr' 'inbounds'? '(' ... ')'
///
/// Everything through visibility has already been parsed.
///
return true;
if (Linkage != GlobalValue::ExternalLinkage &&
- Linkage != GlobalValue::WeakLinkage &&
- Linkage != GlobalValue::InternalLinkage)
+ Linkage != GlobalValue::WeakAnyLinkage &&
+ Linkage != GlobalValue::WeakODRLinkage &&
+ Linkage != GlobalValue::InternalLinkage &&
+ Linkage != GlobalValue::PrivateLinkage &&
+ Linkage != GlobalValue::LinkerPrivateLinkage)
return Error(LinkageLoc, "invalid linkage type for alias");
Constant *Aliasee;
LocTy AliaseeLoc = Lex.getLoc();
- if (Lex.getKind() != lltok::kw_bitcast) {
+ if (Lex.getKind() != lltok::kw_bitcast &&
+ Lex.getKind() != lltok::kw_getelementptr) {
if (ParseGlobalTypeAndValue(Aliasee)) return true;
} else {
// The bitcast dest type is not present, it is implied by the dest type.
bool ThreadLocal, IsConstant;
LocTy TyLoc;
- PATypeHolder Ty(Type::VoidTy);
+ PATypeHolder Ty(Type::getVoidTy(Context));
if (ParseOptionalToken(lltok::kw_thread_local, ThreadLocal) ||
ParseOptionalAddrSpace(AddrSpace) ||
ParseGlobalType(IsConstant) ||
return true;
}
- if (isa<FunctionType>(Ty) || Ty == Type::LabelTy)
- return Error(TyLoc, "invald type for global variable");
+ if (isa<FunctionType>(Ty) || Ty == Type::getLabelTy(Context))
+ return Error(TyLoc, "invalid type for global variable");
GlobalVariable *GV = 0;
// See if the global was forward referenced, if so, use the global.
- if (!Name.empty() && (GV = M->getGlobalVariable(Name, true))) {
- if (!ForwardRefVals.erase(Name))
+ if (!Name.empty()) {
+ if ((GV = M->getGlobalVariable(Name, true)) &&
+ !ForwardRefVals.erase(Name))
return Error(NameLoc, "redefinition of global '@" + Name + "'");
} else {
std::map<unsigned, std::pair<GlobalValue*, LocTy> >::iterator
}
if (GV == 0) {
- GV = new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage, 0, Name,
- M, false, AddrSpace);
+ GV = new GlobalVariable(*M, Ty, false, GlobalValue::ExternalLinkage, 0,
+ Name, 0, false, AddrSpace);
} else {
if (GV->getType()->getElementType() != Ty)
return Error(TyLoc,
// Otherwise, create a new forward reference for this value and remember it.
GlobalValue *FwdVal;
- if (const FunctionType *FT = dyn_cast<FunctionType>(PTy->getElementType()))
+ if (const FunctionType *FT = dyn_cast<FunctionType>(PTy->getElementType())) {
+ // Function types can return opaque but functions can't.
+ if (isa<OpaqueType>(FT->getReturnType())) {
+ Error(Loc, "function may not return opaque type");
+ return 0;
+ }
+
FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M);
- else
- FwdVal = new GlobalVariable(PTy->getElementType(), false,
- GlobalValue::ExternalWeakLinkage, 0, Name, M);
+ } else {
+ FwdVal = new GlobalVariable(*M, PTy->getElementType(), false,
+ GlobalValue::ExternalWeakLinkage, 0, Name);
+ }
ForwardRefVals[Name] = std::make_pair(FwdVal, Loc);
return FwdVal;
}
FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, "", M);
} else {
- FwdVal = new GlobalVariable(PTy->getElementType(), false,
- GlobalValue::ExternalWeakLinkage, 0, "", M);
+ FwdVal = new GlobalVariable(*M, PTy->getElementType(), false,
+ GlobalValue::ExternalWeakLinkage, 0, "");
}
ForwardRefValIDs[ID] = std::make_pair(FwdVal, Loc);
/// ParseOptionalAttrs - Parse a potentially empty attribute list. AttrKind
/// indicates what kind of attribute list this is: 0: function arg, 1: result,
/// 2: function attr.
+/// 3: function arg after value: FIXME: REMOVE IN LLVM 3.0
bool LLParser::ParseOptionalAttrs(unsigned &Attrs, unsigned AttrKind) {
Attrs = Attribute::None;
LocTy AttrLoc = Lex.getLoc();
switch (Lex.getKind()) {
case lltok::kw_sext:
case lltok::kw_zext:
- // Treat these as signext/zeroext unless they are function attrs.
+ // Treat these as signext/zeroext if they occur in the argument list after
+ // the value, as in "call i8 @foo(i8 10 sext)". If they occur before the
+ // value, as in "call i8 @foo(i8 sext (" then it is part of a constant
+ // expr.
// FIXME: REMOVE THIS IN LLVM 3.0
- if (AttrKind != 2) {
+ if (AttrKind == 3) {
if (Lex.getKind() == lltok::kw_sext)
Attrs |= Attribute::SExt;
else
if (AttrKind != 2 && (Attrs & Attribute::FunctionOnly))
return Error(AttrLoc, "invalid use of function-only attribute");
- if (AttrKind != 0 && (Attrs & Attribute::ParameterOnly))
+ if (AttrKind != 0 && AttrKind != 3 && (Attrs & Attribute::ParameterOnly))
return Error(AttrLoc, "invalid use of parameter-only attribute");
return false;
- case lltok::kw_zeroext: Attrs |= Attribute::ZExt; break;
- case lltok::kw_signext: Attrs |= Attribute::SExt; break;
- case lltok::kw_inreg: Attrs |= Attribute::InReg; break;
- case lltok::kw_sret: Attrs |= Attribute::StructRet; break;
- case lltok::kw_noalias: Attrs |= Attribute::NoAlias; break;
- case lltok::kw_nocapture: Attrs |= Attribute::NoCapture; break;
- case lltok::kw_byval: Attrs |= Attribute::ByVal; break;
- case lltok::kw_nest: Attrs |= Attribute::Nest; break;
-
- case lltok::kw_noreturn: Attrs |= Attribute::NoReturn; break;
- case lltok::kw_nounwind: Attrs |= Attribute::NoUnwind; break;
- case lltok::kw_noinline: Attrs |= Attribute::NoInline; break;
- case lltok::kw_readnone: Attrs |= Attribute::ReadNone; break;
- case lltok::kw_readonly: Attrs |= Attribute::ReadOnly; break;
- case lltok::kw_alwaysinline: Attrs |= Attribute::AlwaysInline; break;
- case lltok::kw_optsize: Attrs |= Attribute::OptimizeForSize; break;
- case lltok::kw_ssp: Attrs |= Attribute::StackProtect; break;
- case lltok::kw_sspreq: Attrs |= Attribute::StackProtectReq; break;
-
+ case lltok::kw_zeroext: Attrs |= Attribute::ZExt; break;
+ case lltok::kw_signext: Attrs |= Attribute::SExt; break;
+ case lltok::kw_inreg: Attrs |= Attribute::InReg; break;
+ case lltok::kw_sret: Attrs |= Attribute::StructRet; break;
+ case lltok::kw_noalias: Attrs |= Attribute::NoAlias; break;
+ case lltok::kw_nocapture: Attrs |= Attribute::NoCapture; break;
+ case lltok::kw_byval: Attrs |= Attribute::ByVal; break;
+ case lltok::kw_nest: Attrs |= Attribute::Nest; break;
+
+ case lltok::kw_noreturn: Attrs |= Attribute::NoReturn; break;
+ case lltok::kw_nounwind: Attrs |= Attribute::NoUnwind; break;
+ case lltok::kw_noinline: Attrs |= Attribute::NoInline; break;
+ case lltok::kw_readnone: Attrs |= Attribute::ReadNone; break;
+ case lltok::kw_readonly: Attrs |= Attribute::ReadOnly; break;
+ case lltok::kw_inlinehint: Attrs |= Attribute::InlineHint; break;
+ case lltok::kw_alwaysinline: Attrs |= Attribute::AlwaysInline; break;
+ case lltok::kw_optsize: Attrs |= Attribute::OptimizeForSize; break;
+ case lltok::kw_ssp: Attrs |= Attribute::StackProtect; break;
+ case lltok::kw_sspreq: Attrs |= Attribute::StackProtectReq; break;
+ case lltok::kw_noredzone: Attrs |= Attribute::NoRedZone; break;
+ case lltok::kw_noimplicitfloat: Attrs |= Attribute::NoImplicitFloat; break;
+ case lltok::kw_naked: Attrs |= Attribute::Naked; break;
case lltok::kw_align: {
unsigned Alignment;
/// ParseOptionalLinkage
/// ::= /*empty*/
+/// ::= 'private'
+/// ::= 'linker_private'
/// ::= 'internal'
/// ::= 'weak'
+/// ::= 'weak_odr'
/// ::= 'linkonce'
+/// ::= 'linkonce_odr'
/// ::= 'appending'
/// ::= 'dllexport'
/// ::= 'common'
bool LLParser::ParseOptionalLinkage(unsigned &Res, bool &HasLinkage) {
HasLinkage = false;
switch (Lex.getKind()) {
- default: Res = GlobalValue::ExternalLinkage; return false;
- case lltok::kw_internal: Res = GlobalValue::InternalLinkage; break;
- case lltok::kw_weak: Res = GlobalValue::WeakLinkage; break;
- case lltok::kw_linkonce: Res = GlobalValue::LinkOnceLinkage; break;
- case lltok::kw_appending: Res = GlobalValue::AppendingLinkage; break;
- case lltok::kw_dllexport: Res = GlobalValue::DLLExportLinkage; break;
- case lltok::kw_common: Res = GlobalValue::CommonLinkage; break;
- case lltok::kw_dllimport: Res = GlobalValue::DLLImportLinkage; break;
- case lltok::kw_extern_weak: Res = GlobalValue::ExternalWeakLinkage; break;
- case lltok::kw_external: Res = GlobalValue::ExternalLinkage; break;
+ default: Res=GlobalValue::ExternalLinkage; return false;
+ case lltok::kw_private: Res = GlobalValue::PrivateLinkage; break;
+ case lltok::kw_linker_private: Res = GlobalValue::LinkerPrivateLinkage; break;
+ case lltok::kw_internal: Res = GlobalValue::InternalLinkage; break;
+ case lltok::kw_weak: Res = GlobalValue::WeakAnyLinkage; break;
+ case lltok::kw_weak_odr: Res = GlobalValue::WeakODRLinkage; break;
+ case lltok::kw_linkonce: Res = GlobalValue::LinkOnceAnyLinkage; break;
+ case lltok::kw_linkonce_odr: Res = GlobalValue::LinkOnceODRLinkage; break;
+ case lltok::kw_available_externally:
+ Res = GlobalValue::AvailableExternallyLinkage;
+ break;
+ case lltok::kw_appending: Res = GlobalValue::AppendingLinkage; break;
+ case lltok::kw_dllexport: Res = GlobalValue::DLLExportLinkage; break;
+ case lltok::kw_common: Res = GlobalValue::CommonLinkage; break;
+ case lltok::kw_dllimport: Res = GlobalValue::DLLImportLinkage; break;
+ case lltok::kw_extern_weak: Res = GlobalValue::ExternalWeakLinkage; break;
+ case lltok::kw_external: Res = GlobalValue::ExternalLinkage; break;
}
Lex.Lex();
HasLinkage = true;
/// ::= 'coldcc'
/// ::= 'x86_stdcallcc'
/// ::= 'x86_fastcallcc'
+/// ::= 'arm_apcscc'
+/// ::= 'arm_aapcscc'
+/// ::= 'arm_aapcs_vfpcc'
/// ::= 'cc' UINT
-///
+///
bool LLParser::ParseOptionalCallingConv(unsigned &CC) {
switch (Lex.getKind()) {
default: CC = CallingConv::C; return false;
case lltok::kw_coldcc: CC = CallingConv::Cold; break;
case lltok::kw_x86_stdcallcc: CC = CallingConv::X86_StdCall; break;
case lltok::kw_x86_fastcallcc: CC = CallingConv::X86_FastCall; break;
+ case lltok::kw_arm_apcscc: CC = CallingConv::ARM_APCS; break;
+ case lltok::kw_arm_aapcscc: CC = CallingConv::ARM_AAPCS; break;
+ case lltok::kw_arm_aapcs_vfpcc:CC = CallingConv::ARM_AAPCS_VFP; break;
case lltok::kw_cc: Lex.Lex(); return ParseUInt32(CC);
}
Lex.Lex();
//===----------------------------------------------------------------------===//
/// ParseType - Parse and resolve a full type.
-bool LLParser::ParseType(PATypeHolder &Result) {
+bool LLParser::ParseType(PATypeHolder &Result, bool AllowVoid) {
+ LocTy TypeLoc = Lex.getLoc();
if (ParseTypeRec(Result)) return true;
// Verify no unresolved uprefs.
if (!UpRefs.empty())
return Error(UpRefs.back().Loc, "invalid unresolved type up reference");
+ if (!AllowVoid && Result.get() == Type::getVoidTy(Context))
+ return Error(TypeLoc, "void type only allowed for function results");
+
return false;
}
break;
case lltok::kw_opaque:
// TypeRec ::= 'opaque'
- Result = OpaqueType::get();
+ Result = OpaqueType::get(Context);
Lex.Lex();
break;
case lltok::lbrace:
if (const Type *T = M->getTypeByName(Lex.getStrVal())) {
Result = T;
} else {
- Result = OpaqueType::get();
+ Result = OpaqueType::get(Context);
ForwardRefTypes.insert(std::make_pair(Lex.getStrVal(),
std::make_pair(Result,
Lex.getLoc())));
if (I != ForwardRefTypeIDs.end())
Result = I->second.first;
else {
- Result = OpaqueType::get();
+ Result = OpaqueType::get(Context);
ForwardRefTypeIDs.insert(std::make_pair(Lex.getUIntVal(),
std::make_pair(Result,
Lex.getLoc())));
Lex.Lex();
unsigned Val;
if (ParseUInt32(Val)) return true;
- OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder.
+ OpaqueType *OT = OpaqueType::get(Context); //Use temporary placeholder.
UpRefs.push_back(UpRefRecord(Lex.getLoc(), Val, OT));
Result = OT;
break;
// TypeRec ::= TypeRec '*'
case lltok::star:
- if (Result.get() == Type::LabelTy)
+ if (Result.get() == Type::getLabelTy(Context))
return TokError("basic block pointers are invalid");
+ if (Result.get() == Type::getVoidTy(Context))
+ return TokError("pointers to void are invalid; use i8* instead");
+ if (!PointerType::isValidElementType(Result.get()))
+ return TokError("pointer to this type is invalid");
Result = HandleUpRefs(PointerType::getUnqual(Result.get()));
Lex.Lex();
break;
// TypeRec ::= TypeRec 'addrspace' '(' uint32 ')' '*'
case lltok::kw_addrspace: {
- if (Result.get() == Type::LabelTy)
+ if (Result.get() == Type::getLabelTy(Context))
return TokError("basic block pointers are invalid");
+ if (Result.get() == Type::getVoidTy(Context))
+ return TokError("pointers to void are invalid; use i8* instead");
+ if (!PointerType::isValidElementType(Result.get()))
+ return TokError("pointer to this type is invalid");
unsigned AddrSpace;
if (ParseOptionalAddrSpace(AddrSpace) ||
ParseToken(lltok::star, "expected '*' in address space"))
// Parse the argument.
LocTy ArgLoc;
- PATypeHolder ArgTy(Type::VoidTy);
+ PATypeHolder ArgTy(Type::getVoidTy(Context));
unsigned ArgAttrs1, ArgAttrs2;
Value *V;
if (ParseType(ArgTy, ArgLoc) ||
ParseValue(ArgTy, V, PFS) ||
// FIXME: Should not allow attributes after the argument, remove this in
// LLVM 3.0.
- ParseOptionalAttrs(ArgAttrs2, 0))
+ ParseOptionalAttrs(ArgAttrs2, 3))
return true;
ArgList.push_back(ParamInfo(ArgLoc, V, ArgAttrs1|ArgAttrs2));
}
Lex.Lex();
} else {
LocTy TypeLoc = Lex.getLoc();
- PATypeHolder ArgTy(Type::VoidTy);
+ PATypeHolder ArgTy(Type::getVoidTy(Context));
unsigned Attrs;
std::string Name;
if ((inType ? ParseTypeRec(ArgTy) : ParseType(ArgTy)) ||
ParseOptionalAttrs(Attrs, 0)) return true;
+ if (ArgTy == Type::getVoidTy(Context))
+ return Error(TypeLoc, "argument can not have void type");
+
if (Lex.getKind() == lltok::LocalVar ||
Lex.getKind() == lltok::StringConstant) { // FIXME: REMOVE IN LLVM 3.0
Name = Lex.getStrVal();
Lex.Lex();
}
- if (!ArgTy->isFirstClassType() && !isa<OpaqueType>(ArgTy))
+ if (!FunctionType::isValidArgumentType(ArgTy))
return Error(TypeLoc, "invalid type for function argument");
ArgList.push_back(ArgInfo(TypeLoc, ArgTy, Attrs, Name));
// Otherwise must be an argument type.
TypeLoc = Lex.getLoc();
- if (ParseTypeRec(ArgTy) ||
+ if ((inType ? ParseTypeRec(ArgTy) : ParseType(ArgTy)) ||
ParseOptionalAttrs(Attrs, 0)) return true;
+ if (ArgTy == Type::getVoidTy(Context))
+ return Error(TypeLoc, "argument can not have void type");
+
if (Lex.getKind() == lltok::LocalVar ||
Lex.getKind() == lltok::StringConstant) { // FIXME: REMOVE IN LLVM 3.0
Name = Lex.getStrVal();
for (unsigned i = 0, e = ArgList.size(); i != e; ++i)
ArgListTy.push_back(ArgList[i].Type);
- Result = HandleUpRefs(FunctionType::get(Result.get(), ArgListTy, isVarArg));
+ Result = HandleUpRefs(FunctionType::get(Result.get(),
+ ArgListTy, isVarArg));
return false;
}
Lex.Lex(); // Consume the '{'
if (EatIfPresent(lltok::rbrace)) {
- Result = StructType::get(std::vector<const Type*>(), Packed);
+ Result = StructType::get(Context, Packed);
return false;
}
std::vector<PATypeHolder> ParamsList;
+ LocTy EltTyLoc = Lex.getLoc();
if (ParseTypeRec(Result)) return true;
ParamsList.push_back(Result);
+ if (Result == Type::getVoidTy(Context))
+ return Error(EltTyLoc, "struct element can not have void type");
+ if (!StructType::isValidElementType(Result))
+ return Error(EltTyLoc, "invalid element type for struct");
+
while (EatIfPresent(lltok::comma)) {
+ EltTyLoc = Lex.getLoc();
if (ParseTypeRec(Result)) return true;
+
+ if (Result == Type::getVoidTy(Context))
+ return Error(EltTyLoc, "struct element can not have void type");
+ if (!StructType::isValidElementType(Result))
+ return Error(EltTyLoc, "invalid element type for struct");
+
ParamsList.push_back(Result);
}
std::vector<const Type*> ParamsListTy;
for (unsigned i = 0, e = ParamsList.size(); i != e; ++i)
ParamsListTy.push_back(ParamsList[i].get());
- Result = HandleUpRefs(StructType::get(ParamsListTy, Packed));
+ Result = HandleUpRefs(StructType::get(Context, ParamsListTy, Packed));
return false;
}
return true;
LocTy TypeLoc = Lex.getLoc();
- PATypeHolder EltTy(Type::VoidTy);
+ PATypeHolder EltTy(Type::getVoidTy(Context));
if (ParseTypeRec(EltTy)) return true;
+ if (EltTy == Type::getVoidTy(Context))
+ return Error(TypeLoc, "array and vector element type cannot be void");
+
if (ParseToken(isVector ? lltok::greater : lltok::rsquare,
"expected end of sequential type"))
return true;
if (isVector) {
+ if (Size == 0)
+ return Error(SizeLoc, "zero element vector is illegal");
if ((unsigned)Size != Size)
return Error(SizeLoc, "size too large for vector");
- if (!EltTy->isFloatingPoint() && !EltTy->isInteger())
+ if (!VectorType::isValidElementType(EltTy))
return Error(TypeLoc, "vector element type must be fp or integer");
Result = VectorType::get(EltTy, unsigned(Size));
} else {
- if (!EltTy->isFirstClassType() && !isa<OpaqueType>(EltTy))
+ if (!ArrayType::isValidElementType(EltTy))
return Error(TypeLoc, "invalid array element type");
Result = HandleUpRefs(ArrayType::get(EltTy, Size));
}
for (std::map<std::string, std::pair<Value*, LocTy> >::iterator
I = ForwardRefVals.begin(), E = ForwardRefVals.end(); I != E; ++I)
if (!isa<BasicBlock>(I->second.first)) {
- I->second.first->replaceAllUsesWith(UndefValue::get(I->second.first
- ->getType()));
+ I->second.first->replaceAllUsesWith(
+ UndefValue::get(I->second.first->getType()));
delete I->second.first;
I->second.first = 0;
}
for (std::map<unsigned, std::pair<Value*, LocTy> >::iterator
I = ForwardRefValIDs.begin(), E = ForwardRefValIDs.end(); I != E; ++I)
if (!isa<BasicBlock>(I->second.first)) {
- I->second.first->replaceAllUsesWith(UndefValue::get(I->second.first
- ->getType()));
+ I->second.first->replaceAllUsesWith(
+ UndefValue::get(I->second.first->getType()));
delete I->second.first;
I->second.first = 0;
}
// If we have the value in the symbol table or fwd-ref table, return it.
if (Val) {
if (Val->getType() == Ty) return Val;
- if (Ty == Type::LabelTy)
+ if (Ty == Type::getLabelTy(F.getContext()))
P.Error(Loc, "'%" + Name + "' is not a basic block");
else
P.Error(Loc, "'%" + Name + "' defined with type '" +
}
// Don't make placeholders with invalid type.
- if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty) && Ty != Type::LabelTy) {
+ if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty) &&
+ Ty != Type::getLabelTy(F.getContext())) {
P.Error(Loc, "invalid use of a non-first-class type");
return 0;
}
// Otherwise, create a new forward reference for this value and remember it.
Value *FwdVal;
- if (Ty == Type::LabelTy)
- FwdVal = BasicBlock::Create(Name, &F);
+ if (Ty == Type::getLabelTy(F.getContext()))
+ FwdVal = BasicBlock::Create(F.getContext(), Name, &F);
else
FwdVal = new Argument(Ty, Name);
// If we have the value in the symbol table or fwd-ref table, return it.
if (Val) {
if (Val->getType() == Ty) return Val;
- if (Ty == Type::LabelTy)
+ if (Ty == Type::getLabelTy(F.getContext()))
P.Error(Loc, "'%" + utostr(ID) + "' is not a basic block");
else
P.Error(Loc, "'%" + utostr(ID) + "' defined with type '" +
return 0;
}
- if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty) && Ty != Type::LabelTy) {
+ if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty) &&
+ Ty != Type::getLabelTy(F.getContext())) {
P.Error(Loc, "invalid use of a non-first-class type");
return 0;
}
// Otherwise, create a new forward reference for this value and remember it.
Value *FwdVal;
- if (Ty == Type::LabelTy)
- FwdVal = BasicBlock::Create("", &F);
+ if (Ty == Type::getLabelTy(F.getContext()))
+ FwdVal = BasicBlock::Create(F.getContext(), "", &F);
else
FwdVal = new Argument(Ty);
const std::string &NameStr,
LocTy NameLoc, Instruction *Inst) {
// If this instruction has void type, it cannot have a name or ID specified.
- if (Inst->getType() == Type::VoidTy) {
+ if (Inst->getType() == Type::getVoidTy(F.getContext())) {
if (NameID != -1 || !NameStr.empty())
return P.Error(NameLoc, "instructions returning void cannot have a name");
return false;
/// forward reference record if needed.
BasicBlock *LLParser::PerFunctionState::GetBB(const std::string &Name,
LocTy Loc) {
- return cast_or_null<BasicBlock>(GetVal(Name, Type::LabelTy, Loc));
+ return cast_or_null<BasicBlock>(GetVal(Name,
+ Type::getLabelTy(F.getContext()), Loc));
}
BasicBlock *LLParser::PerFunctionState::GetBB(unsigned ID, LocTy Loc) {
- return cast_or_null<BasicBlock>(GetVal(ID, Type::LabelTy, Loc));
+ return cast_or_null<BasicBlock>(GetVal(ID,
+ Type::getLabelTy(F.getContext()), Loc));
}
/// DefineBB - Define the specified basic block, which is either named or
ID.StrVal = Lex.getStrVal();
ID.Kind = ValID::t_LocalName;
break;
+ case lltok::Metadata: { // !{...} MDNode, !"foo" MDString
+ ID.Kind = ValID::t_Metadata;
+ Lex.Lex();
+ if (Lex.getKind() == lltok::lbrace) {
+ SmallVector<Value*, 16> Elts;
+ if (ParseMDNodeVector(Elts) ||
+ ParseToken(lltok::rbrace, "expected end of metadata node"))
+ return true;
+
+ ID.MetadataVal = MDNode::get(Context, Elts.data(), Elts.size());
+ return false;
+ }
+
+ // Standalone metadata reference
+ // !{ ..., !42, ... }
+ if (!ParseMDNode(ID.MetadataVal))
+ return false;
+
+ // MDString:
+ // ::= '!' STRINGCONSTANT
+ if (ParseMDString(ID.MetadataVal)) return true;
+ ID.Kind = ValID::t_Metadata;
+ return false;
+ }
case lltok::APSInt:
ID.APSIntVal = Lex.getAPSIntVal();
ID.Kind = ValID::t_APSInt;
ID.Kind = ValID::t_APFloat;
break;
case lltok::kw_true:
- ID.ConstantVal = ConstantInt::getTrue();
+ ID.ConstantVal = ConstantInt::getTrue(Context);
ID.Kind = ValID::t_Constant;
break;
case lltok::kw_false:
- ID.ConstantVal = ConstantInt::getFalse();
+ ID.ConstantVal = ConstantInt::getFalse(Context);
ID.Kind = ValID::t_Constant;
break;
case lltok::kw_null: ID.Kind = ValID::t_Null; break;
ParseToken(lltok::rbrace, "expected end of struct constant"))
return true;
- ID.ConstantVal = ConstantStruct::get(&Elts[0], Elts.size(), false);
+ ID.ConstantVal = ConstantStruct::get(Context, Elts.data(),
+ Elts.size(), false);
ID.Kind = ValID::t_Constant;
return false;
}
return true;
if (isPackedStruct) {
- ID.ConstantVal = ConstantStruct::get(&Elts[0], Elts.size(), true);
+ ID.ConstantVal =
+ ConstantStruct::get(Context, Elts.data(), Elts.size(), true);
ID.Kind = ValID::t_Constant;
return false;
}
"vector element #" + utostr(i) +
" is not of type '" + Elts[0]->getType()->getDescription());
- ID.ConstantVal = ConstantVector::get(&Elts[0], Elts.size());
+ ID.ConstantVal = ConstantVector::get(Elts.data(), Elts.size());
ID.Kind = ValID::t_Constant;
return false;
}
"array element #" + utostr(i) +
" is not of type '" +Elts[0]->getType()->getDescription());
}
-
- ID.ConstantVal = ConstantArray::get(ATy, &Elts[0], Elts.size());
+
+ ID.ConstantVal = ConstantArray::get(ATy, Elts.data(), Elts.size());
ID.Kind = ValID::t_Constant;
return false;
}
case lltok::kw_c: // c "foo"
Lex.Lex();
- ID.ConstantVal = ConstantArray::get(Lex.getStrVal(), false);
+ ID.ConstantVal = ConstantArray::get(Context, Lex.getStrVal(), false);
if (ParseToken(lltok::StringConstant, "expected string")) return true;
ID.Kind = ValID::t_Constant;
return false;
case lltok::kw_inttoptr:
case lltok::kw_ptrtoint: {
unsigned Opc = Lex.getUIntVal();
- PATypeHolder DestTy(Type::VoidTy);
+ PATypeHolder DestTy(Type::getVoidTy(Context));
Constant *SrcVal;
Lex.Lex();
if (ParseToken(lltok::lparen, "expected '(' after constantexpr cast") ||
ParseGlobalTypeAndValue(SrcVal) ||
- ParseToken(lltok::kw_to, "expected 'to' int constantexpr cast") ||
+ ParseToken(lltok::kw_to, "expected 'to' in constantexpr cast") ||
ParseType(DestTy) ||
ParseToken(lltok::rparen, "expected ')' at end of constantexpr cast"))
return true;
return Error(ID.Loc, "invalid cast opcode for cast from '" +
SrcVal->getType()->getDescription() + "' to '" +
DestTy->getDescription() + "'");
- ID.ConstantVal = ConstantExpr::getCast((Instruction::CastOps)Opc, SrcVal,
- DestTy);
+ ID.ConstantVal = ConstantExpr::getCast((Instruction::CastOps)Opc,
+ SrcVal, DestTy);
ID.Kind = ValID::t_Constant;
return false;
}
if (!ExtractValueInst::getIndexedType(Val->getType(), Indices.begin(),
Indices.end()))
return Error(ID.Loc, "invalid indices for extractvalue");
- ID.ConstantVal = ConstantExpr::getExtractValue(Val,
- &Indices[0], Indices.size());
+ ID.ConstantVal =
+ ConstantExpr::getExtractValue(Val, Indices.data(), Indices.size());
ID.Kind = ValID::t_Constant;
return false;
}
Indices.end()))
return Error(ID.Loc, "invalid indices for insertvalue");
ID.ConstantVal = ConstantExpr::getInsertValue(Val0, Val1,
- &Indices[0], Indices.size());
+ Indices.data(), Indices.size());
ID.Kind = ValID::t_Constant;
return false;
}
case lltok::kw_icmp:
- case lltok::kw_fcmp:
- case lltok::kw_vicmp:
- case lltok::kw_vfcmp: {
+ case lltok::kw_fcmp: {
unsigned PredVal, Opc = Lex.getUIntVal();
Constant *Val0, *Val1;
Lex.Lex();
if (!Val0->getType()->isFPOrFPVector())
return Error(ID.Loc, "fcmp requires floating point operands");
ID.ConstantVal = ConstantExpr::getFCmp(Pred, Val0, Val1);
- } else if (Opc == Instruction::ICmp) {
+ } else {
+ assert(Opc == Instruction::ICmp && "Unexpected opcode for CmpInst!");
if (!Val0->getType()->isIntOrIntVector() &&
!isa<PointerType>(Val0->getType()))
return Error(ID.Loc, "icmp requires pointer or integer operands");
ID.ConstantVal = ConstantExpr::getICmp(Pred, Val0, Val1);
- } else if (Opc == Instruction::VFCmp) {
- // FIXME: REMOVE VFCMP Support
- if (!Val0->getType()->isFPOrFPVector() ||
- !isa<VectorType>(Val0->getType()))
- return Error(ID.Loc, "vfcmp requires vector floating point operands");
- ID.ConstantVal = ConstantExpr::getVFCmp(Pred, Val0, Val1);
- } else if (Opc == Instruction::VICmp) {
- // FIXME: REMOVE VICMP Support
- if (!Val0->getType()->isIntOrIntVector() ||
- !isa<VectorType>(Val0->getType()))
- return Error(ID.Loc, "vicmp requires vector floating point operands");
- ID.ConstantVal = ConstantExpr::getVICmp(Pred, Val0, Val1);
}
ID.Kind = ValID::t_Constant;
return false;
// Binary Operators.
case lltok::kw_add:
+ case lltok::kw_fadd:
case lltok::kw_sub:
+ case lltok::kw_fsub:
case lltok::kw_mul:
+ case lltok::kw_fmul:
case lltok::kw_udiv:
case lltok::kw_sdiv:
case lltok::kw_fdiv:
case lltok::kw_urem:
case lltok::kw_srem:
case lltok::kw_frem: {
+ bool NUW = false;
+ bool NSW = false;
+ bool Exact = false;
unsigned Opc = Lex.getUIntVal();
Constant *Val0, *Val1;
Lex.Lex();
+ LocTy ModifierLoc = Lex.getLoc();
+ if (Opc == Instruction::Add ||
+ Opc == Instruction::Sub ||
+ Opc == Instruction::Mul) {
+ if (EatIfPresent(lltok::kw_nuw))
+ NUW = true;
+ if (EatIfPresent(lltok::kw_nsw)) {
+ NSW = true;
+ if (EatIfPresent(lltok::kw_nuw))
+ NUW = true;
+ }
+ } else if (Opc == Instruction::SDiv) {
+ if (EatIfPresent(lltok::kw_exact))
+ Exact = true;
+ }
if (ParseToken(lltok::lparen, "expected '(' in binary constantexpr") ||
ParseGlobalTypeAndValue(Val0) ||
ParseToken(lltok::comma, "expected comma in binary constantexpr") ||
return true;
if (Val0->getType() != Val1->getType())
return Error(ID.Loc, "operands of constexpr must have same type");
+ if (!Val0->getType()->isIntOrIntVector()) {
+ if (NUW)
+ return Error(ModifierLoc, "nuw only applies to integer operations");
+ if (NSW)
+ return Error(ModifierLoc, "nsw only applies to integer operations");
+ }
+ // API compatibility: Accept either integer or floating-point types with
+ // add, sub, and mul.
if (!Val0->getType()->isIntOrIntVector() &&
!Val0->getType()->isFPOrFPVector())
return Error(ID.Loc,"constexpr requires integer, fp, or vector operands");
- ID.ConstantVal = ConstantExpr::get(Opc, Val0, Val1);
+ Constant *C = ConstantExpr::get(Opc, Val0, Val1);
+ if (NUW)
+ cast<OverflowingBinaryOperator>(C)->setHasNoUnsignedWrap(true);
+ if (NSW)
+ cast<OverflowingBinaryOperator>(C)->setHasNoSignedWrap(true);
+ if (Exact)
+ cast<SDivOperator>(C)->setIsExact(true);
+ ID.ConstantVal = C;
ID.Kind = ValID::t_Constant;
return false;
}
case lltok::kw_select: {
unsigned Opc = Lex.getUIntVal();
SmallVector<Constant*, 16> Elts;
+ bool InBounds = false;
Lex.Lex();
+ if (Opc == Instruction::GetElementPtr)
+ InBounds = EatIfPresent(lltok::kw_inbounds);
if (ParseToken(lltok::lparen, "expected '(' in constantexpr") ||
ParseGlobalValueVector(Elts) ||
ParseToken(lltok::rparen, "expected ')' in constantexpr"))
return Error(ID.Loc, "getelementptr requires pointer operand");
if (!GetElementPtrInst::getIndexedType(Elts[0]->getType(),
- (Value**)&Elts[1], Elts.size()-1))
+ (Value**)(Elts.data() + 1),
+ Elts.size() - 1))
return Error(ID.Loc, "invalid indices for getelementptr");
ID.ConstantVal = ConstantExpr::getGetElementPtr(Elts[0],
- &Elts[1], Elts.size()-1);
+ Elts.data() + 1, Elts.size() - 1);
+ if (InBounds)
+ cast<GEPOperator>(ID.ConstantVal)->setIsInBounds(true);
} else if (Opc == Instruction::Select) {
if (Elts.size() != 3)
return Error(ID.Loc, "expected three operands to select");
return Error(ID.Loc, "expected three operands to shufflevector");
if (!ShuffleVectorInst::isValidOperands(Elts[0], Elts[1], Elts[2]))
return Error(ID.Loc, "invalid operands to shufflevector");
- ID.ConstantVal = ConstantExpr::getShuffleVector(Elts[0], Elts[1],Elts[2]);
+ ID.ConstantVal =
+ ConstantExpr::getShuffleVector(Elts[0], Elts[1],Elts[2]);
} else if (Opc == Instruction::ExtractElement) {
if (Elts.size() != 2)
return Error(ID.Loc, "expected two operands to extractelement");
return Error(ID.Loc, "expected three operands to insertelement");
if (!InsertElementInst::isValidOperands(Elts[0], Elts[1], Elts[2]))
return Error(ID.Loc, "invalid insertelement operands");
- ID.ConstantVal = ConstantExpr::getInsertElement(Elts[0], Elts[1],Elts[2]);
+ ID.ConstantVal =
+ ConstantExpr::getInsertElement(Elts[0], Elts[1],Elts[2]);
}
ID.Kind = ValID::t_Constant;
return Error(ID.Loc, "functions are not values, refer to them as pointers");
switch (ID.Kind) {
- default: assert(0 && "Unknown ValID!");
+ default: llvm_unreachable("Unknown ValID!");
+ case ValID::t_Metadata:
+ return Error(ID.Loc, "invalid use of metadata");
case ValID::t_LocalID:
case ValID::t_LocalName:
return Error(ID.Loc, "invalid use of function-local name");
if (!isa<IntegerType>(Ty))
return Error(ID.Loc, "integer constant must have integer type");
ID.APSIntVal.extOrTrunc(Ty->getPrimitiveSizeInBits());
- V = ConstantInt::get(ID.APSIntVal);
+ V = ConstantInt::get(Context, ID.APSIntVal);
return false;
case ValID::t_APFloat:
if (!Ty->isFloatingPoint() ||
// The lexer has no type info, so builds all float and double FP constants
// as double. Fix this here. Long double does not need this.
if (&ID.APFloatVal.getSemantics() == &APFloat::IEEEdouble &&
- Ty == Type::FloatTy) {
+ Ty == Type::getFloatTy(Context)) {
bool Ignored;
ID.APFloatVal.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven,
&Ignored);
}
- V = ConstantFP::get(ID.APFloatVal);
+ V = ConstantFP::get(Context, ID.APFloatVal);
if (V->getType() != Ty)
return Error(ID.Loc, "floating point constant does not have type '" +
return false;
case ValID::t_Undef:
// FIXME: LabelTy should not be a first-class type.
- if ((!Ty->isFirstClassType() || Ty == Type::LabelTy) &&
+ if ((!Ty->isFirstClassType() || Ty == Type::getLabelTy(Context)) &&
!isa<OpaqueType>(Ty))
return Error(ID.Loc, "invalid type for undef constant");
V = UndefValue::get(Ty);
return false;
case ValID::t_Zero:
// FIXME: LabelTy should not be a first-class type.
- if (!Ty->isFirstClassType() || Ty == Type::LabelTy)
+ if (!Ty->isFirstClassType() || Ty == Type::getLabelTy(Context))
return Error(ID.Loc, "invalid type for null constant");
V = Constant::getNullValue(Ty);
return false;
}
bool LLParser::ParseGlobalTypeAndValue(Constant *&V) {
- PATypeHolder Type(Type::VoidTy);
+ PATypeHolder Type(Type::getVoidTy(Context));
return ParseType(Type) ||
ParseGlobalValue(Type, V);
}
return Error(ID.Loc, "invalid type for inline asm constraint string");
V = InlineAsm::get(FTy, ID.StrVal, ID.StrVal2, ID.UIntVal);
return false;
+ } else if (ID.Kind == ValID::t_Metadata) {
+ V = ID.MetadataVal;
} else {
Constant *C;
if (ConvertGlobalValIDToValue(Ty, ID, C)) return true;
}
bool LLParser::ParseTypeAndValue(Value *&V, PerFunctionState &PFS) {
- PATypeHolder T(Type::VoidTy);
+ PATypeHolder T(Type::getVoidTy(Context));
return ParseType(T) ||
ParseValue(T, V, PFS);
}
unsigned Linkage;
unsigned Visibility, CC, RetAttrs;
- PATypeHolder RetType(Type::VoidTy);
+ PATypeHolder RetType(Type::getVoidTy(Context));
LocTy RetTypeLoc = Lex.getLoc();
if (ParseOptionalLinkage(Linkage) ||
ParseOptionalVisibility(Visibility) ||
ParseOptionalCallingConv(CC) ||
ParseOptionalAttrs(RetAttrs, 1) ||
- ParseType(RetType, RetTypeLoc))
+ ParseType(RetType, RetTypeLoc, true /*void allowed*/))
return true;
// Verify that the linkage is ok.
if (isDefine)
return Error(LinkageLoc, "invalid linkage for function definition");
break;
+ case GlobalValue::PrivateLinkage:
+ case GlobalValue::LinkerPrivateLinkage:
case GlobalValue::InternalLinkage:
- case GlobalValue::LinkOnceLinkage:
- case GlobalValue::WeakLinkage:
+ case GlobalValue::AvailableExternallyLinkage:
+ case GlobalValue::LinkOnceAnyLinkage:
+ case GlobalValue::LinkOnceODRLinkage:
+ case GlobalValue::WeakAnyLinkage:
+ case GlobalValue::WeakODRLinkage:
case GlobalValue::DLLExportLinkage:
if (!isDefine)
return Error(LinkageLoc, "invalid linkage for function declaration");
isa<OpaqueType>(RetType))
return Error(RetTypeLoc, "invalid function return type");
- if (Lex.getKind() != lltok::GlobalVar)
+ LocTy NameLoc = Lex.getLoc();
+
+ std::string FunctionName;
+ if (Lex.getKind() == lltok::GlobalVar) {
+ FunctionName = Lex.getStrVal();
+ } else if (Lex.getKind() == lltok::GlobalID) { // @42 is ok.
+ unsigned NameID = Lex.getUIntVal();
+
+ if (NameID != NumberedVals.size())
+ return TokError("function expected to be numbered '%" +
+ utostr(NumberedVals.size()) + "'");
+ } else {
return TokError("expected function name");
+ }
- LocTy NameLoc = Lex.getLoc();
- std::string FunctionName = Lex.getStrVal();
Lex.Lex();
if (Lex.getKind() != lltok::lparen)
AttrListPtr PAL = AttrListPtr::get(Attrs.begin(), Attrs.end());
- const FunctionType *FT = FunctionType::get(RetType, ParamTypeList, isVarArg);
+ if (PAL.paramHasAttr(1, Attribute::StructRet) &&
+ RetType != Type::getVoidTy(Context))
+ return Error(RetTypeLoc, "functions with 'sret' argument must return void");
+
+ const FunctionType *FT =
+ FunctionType::get(RetType, ParamTypeList, isVarArg);
const PointerType *PFT = PointerType::getUnqual(FT);
Fn = 0;
if (Token == lltok::Eof)
return TokError("found end of file when expecting more instructions");
LocTy Loc = Lex.getLoc();
+ unsigned KeywordVal = Lex.getUIntVal();
Lex.Lex(); // Eat the keyword.
switch (Token) {
default: return Error(Loc, "expected instruction opcode");
// Terminator Instructions.
- case lltok::kw_unwind: Inst = new UnwindInst(); return false;
- case lltok::kw_unreachable: Inst = new UnreachableInst(); return false;
+ case lltok::kw_unwind: Inst = new UnwindInst(Context); return false;
+ case lltok::kw_unreachable: Inst = new UnreachableInst(Context); return false;
case lltok::kw_ret: return ParseRet(Inst, BB, PFS);
case lltok::kw_br: return ParseBr(Inst, PFS);
case lltok::kw_switch: return ParseSwitch(Inst, PFS);
// Binary Operators.
case lltok::kw_add:
case lltok::kw_sub:
- case lltok::kw_mul: return ParseArithmetic(Inst, PFS, Lex.getUIntVal(), 0);
-
+ case lltok::kw_mul: {
+ bool NUW = false;
+ bool NSW = false;
+ LocTy ModifierLoc = Lex.getLoc();
+ if (EatIfPresent(lltok::kw_nuw))
+ NUW = true;
+ if (EatIfPresent(lltok::kw_nsw)) {
+ NSW = true;
+ if (EatIfPresent(lltok::kw_nuw))
+ NUW = true;
+ }
+ // API compatibility: Accept either integer or floating-point types.
+ bool Result = ParseArithmetic(Inst, PFS, KeywordVal, 0);
+ if (!Result) {
+ if (!Inst->getType()->isIntOrIntVector()) {
+ if (NUW)
+ return Error(ModifierLoc, "nuw only applies to integer operations");
+ if (NSW)
+ return Error(ModifierLoc, "nsw only applies to integer operations");
+ }
+ if (NUW)
+ cast<OverflowingBinaryOperator>(Inst)->setHasNoUnsignedWrap(true);
+ if (NSW)
+ cast<OverflowingBinaryOperator>(Inst)->setHasNoSignedWrap(true);
+ }
+ return Result;
+ }
+ case lltok::kw_fadd:
+ case lltok::kw_fsub:
+ case lltok::kw_fmul: return ParseArithmetic(Inst, PFS, KeywordVal, 2);
+
+ case lltok::kw_sdiv: {
+ bool Exact = false;
+ if (EatIfPresent(lltok::kw_exact))
+ Exact = true;
+ bool Result = ParseArithmetic(Inst, PFS, KeywordVal, 1);
+ if (!Result)
+ if (Exact)
+ cast<SDivOperator>(Inst)->setIsExact(true);
+ return Result;
+ }
+
case lltok::kw_udiv:
- case lltok::kw_sdiv:
case lltok::kw_urem:
- case lltok::kw_srem: return ParseArithmetic(Inst, PFS, Lex.getUIntVal(), 1);
+ case lltok::kw_srem: return ParseArithmetic(Inst, PFS, KeywordVal, 1);
case lltok::kw_fdiv:
- case lltok::kw_frem: return ParseArithmetic(Inst, PFS, Lex.getUIntVal(), 2);
+ case lltok::kw_frem: return ParseArithmetic(Inst, PFS, KeywordVal, 2);
case lltok::kw_shl:
case lltok::kw_lshr:
case lltok::kw_ashr:
case lltok::kw_and:
case lltok::kw_or:
- case lltok::kw_xor: return ParseLogical(Inst, PFS, Lex.getUIntVal());
+ case lltok::kw_xor: return ParseLogical(Inst, PFS, KeywordVal);
case lltok::kw_icmp:
- case lltok::kw_fcmp:
- case lltok::kw_vicmp:
- case lltok::kw_vfcmp: return ParseCompare(Inst, PFS, Lex.getUIntVal());
+ case lltok::kw_fcmp: return ParseCompare(Inst, PFS, KeywordVal);
// Casts.
case lltok::kw_trunc:
case lltok::kw_zext:
case lltok::kw_fptoui:
case lltok::kw_fptosi:
case lltok::kw_inttoptr:
- case lltok::kw_ptrtoint: return ParseCast(Inst, PFS, Lex.getUIntVal());
+ case lltok::kw_ptrtoint: return ParseCast(Inst, PFS, KeywordVal);
// Other.
case lltok::kw_select: return ParseSelect(Inst, PFS);
case lltok::kw_va_arg: return ParseVA_Arg(Inst, PFS);
case lltok::kw_tail: return ParseCall(Inst, PFS, true);
// Memory.
case lltok::kw_alloca:
- case lltok::kw_malloc: return ParseAlloc(Inst, PFS, Lex.getUIntVal());
+ case lltok::kw_malloc: return ParseAlloc(Inst, PFS, KeywordVal);
case lltok::kw_free: return ParseFree(Inst, PFS);
case lltok::kw_load: return ParseLoad(Inst, PFS, false);
case lltok::kw_store: return ParseStore(Inst, PFS, false);
/// ParseCmpPredicate - Parse an integer or fp predicate, based on Kind.
bool LLParser::ParseCmpPredicate(unsigned &P, unsigned Opc) {
- // FIXME: REMOVE vicmp/vfcmp!
- if (Opc == Instruction::FCmp || Opc == Instruction::VFCmp) {
+ if (Opc == Instruction::FCmp) {
switch (Lex.getKind()) {
default: TokError("expected fcmp predicate (e.g. 'oeq')");
case lltok::kw_oeq: P = CmpInst::FCMP_OEQ; break;
/// ::= 'ret' TypeAndValue (',' TypeAndValue)+ [[obsolete: LLVM 3.0]]
bool LLParser::ParseRet(Instruction *&Inst, BasicBlock *BB,
PerFunctionState &PFS) {
- PATypeHolder Ty(Type::VoidTy);
- if (ParseType(Ty)) return true;
+ PATypeHolder Ty(Type::getVoidTy(Context));
+ if (ParseType(Ty, true /*void allowed*/)) return true;
- if (Ty == Type::VoidTy) {
- Inst = ReturnInst::Create();
+ if (Ty == Type::getVoidTy(Context)) {
+ Inst = ReturnInst::Create(Context);
return false;
}
RV = I;
}
}
- Inst = ReturnInst::Create(RV);
+ Inst = ReturnInst::Create(Context, RV);
return false;
}
return false;
}
- if (Op0->getType() != Type::Int1Ty)
+ if (Op0->getType() != Type::getInt1Ty(Context))
return Error(Loc, "branch condition must have 'i1' type");
if (ParseToken(lltok::comma, "expected ',' after branch condition") ||
bool LLParser::ParseInvoke(Instruction *&Inst, PerFunctionState &PFS) {
LocTy CallLoc = Lex.getLoc();
unsigned CC, RetAttrs, FnAttrs;
- PATypeHolder RetType(Type::VoidTy);
+ PATypeHolder RetType(Type::getVoidTy(Context));
LocTy RetTypeLoc;
ValID CalleeID;
SmallVector<ParamInfo, 16> ArgList;
Value *NormalBB, *UnwindBB;
if (ParseOptionalCallingConv(CC) ||
ParseOptionalAttrs(RetAttrs, 1) ||
- ParseType(RetType, RetTypeLoc) ||
+ ParseType(RetType, RetTypeLoc, true /*void allowed*/) ||
ParseValID(CalleeID) ||
ParseParameterList(ArgList, PFS) ||
ParseOptionalAttrs(FnAttrs, 2) ||
bool Valid;
switch (OperandType) {
- default: assert(0 && "Unknown operand type!");
+ default: llvm_unreachable("Unknown operand type!");
case 0: // int or FP.
Valid = LHS->getType()->isIntOrIntVector() ||
LHS->getType()->isFPOrFPVector();
/// ParseCompare
/// ::= 'icmp' IPredicates TypeAndValue ',' Value
/// ::= 'fcmp' FPredicates TypeAndValue ',' Value
-/// ::= 'vicmp' IPredicates TypeAndValue ',' Value
-/// ::= 'vfcmp' FPredicates TypeAndValue ',' Value
bool LLParser::ParseCompare(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc) {
// Parse the integer/fp comparison predicate.
if (!LHS->getType()->isFPOrFPVector())
return Error(Loc, "fcmp requires floating point operands");
Inst = new FCmpInst(CmpInst::Predicate(Pred), LHS, RHS);
- } else if (Opc == Instruction::ICmp) {
+ } else {
+ assert(Opc == Instruction::ICmp && "Unknown opcode for CmpInst!");
if (!LHS->getType()->isIntOrIntVector() &&
!isa<PointerType>(LHS->getType()))
return Error(Loc, "icmp requires integer operands");
Inst = new ICmpInst(CmpInst::Predicate(Pred), LHS, RHS);
- } else if (Opc == Instruction::VFCmp) {
- if (!LHS->getType()->isFPOrFPVector() || !isa<VectorType>(LHS->getType()))
- return Error(Loc, "vfcmp requires vector floating point operands");
- Inst = new VFCmpInst(CmpInst::Predicate(Pred), LHS, RHS);
- } else if (Opc == Instruction::VICmp) {
- if (!LHS->getType()->isIntOrIntVector() || !isa<VectorType>(LHS->getType()))
- return Error(Loc, "vicmp requires vector floating point operands");
- Inst = new VICmpInst(CmpInst::Predicate(Pred), LHS, RHS);
}
return false;
}
bool LLParser::ParseCast(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc) {
LocTy Loc; Value *Op;
- PATypeHolder DestTy(Type::VoidTy);
+ PATypeHolder DestTy(Type::getVoidTy(Context));
if (ParseTypeAndValue(Op, Loc, PFS) ||
ParseToken(lltok::kw_to, "expected 'to' after cast value") ||
ParseType(DestTy))
return true;
- if (!CastInst::castIsValid((Instruction::CastOps)Opc, Op, DestTy))
+ if (!CastInst::castIsValid((Instruction::CastOps)Opc, Op, DestTy)) {
+ CastInst::castIsValid((Instruction::CastOps)Opc, Op, DestTy);
return Error(Loc, "invalid cast opcode for cast from '" +
Op->getType()->getDescription() + "' to '" +
DestTy->getDescription() + "'");
+ }
Inst = CastInst::Create((Instruction::CastOps)Opc, Op, DestTy);
return false;
}
/// ::= 'va_arg' TypeAndValue ',' Type
bool LLParser::ParseVA_Arg(Instruction *&Inst, PerFunctionState &PFS) {
Value *Op;
- PATypeHolder EltTy(Type::VoidTy);
+ PATypeHolder EltTy(Type::getVoidTy(Context));
LocTy TypeLoc;
if (ParseTypeAndValue(Op, PFS) ||
ParseToken(lltok::comma, "expected ',' after vaarg operand") ||
if (!ExtractElementInst::isValidOperands(Op0, Op1))
return Error(Loc, "invalid extractelement operands");
- Inst = new ExtractElementInst(Op0, Op1);
+ Inst = ExtractElementInst::Create(Op0, Op1);
return false;
}
return true;
if (!InsertElementInst::isValidOperands(Op0, Op1, Op2))
- return Error(Loc, "invalid extractelement operands");
+ return Error(Loc, "invalid insertelement operands");
Inst = InsertElementInst::Create(Op0, Op1, Op2);
return false;
/// ParsePHI
/// ::= 'phi' Type '[' Value ',' Value ']' (',' '[' Value ',' Valueß ']')*
bool LLParser::ParsePHI(Instruction *&Inst, PerFunctionState &PFS) {
- PATypeHolder Ty(Type::VoidTy);
+ PATypeHolder Ty(Type::getVoidTy(Context));
Value *Op0, *Op1;
LocTy TypeLoc = Lex.getLoc();
ParseToken(lltok::lsquare, "expected '[' in phi value list") ||
ParseValue(Ty, Op0, PFS) ||
ParseToken(lltok::comma, "expected ',' after insertelement value") ||
- ParseValue(Type::LabelTy, Op1, PFS) ||
+ ParseValue(Type::getLabelTy(Context), Op1, PFS) ||
ParseToken(lltok::rsquare, "expected ']' in phi value list"))
return true;
if (ParseToken(lltok::lsquare, "expected '[' in phi value list") ||
ParseValue(Ty, Op0, PFS) ||
ParseToken(lltok::comma, "expected ',' after insertelement value") ||
- ParseValue(Type::LabelTy, Op1, PFS) ||
+ ParseValue(Type::getLabelTy(Context), Op1, PFS) ||
ParseToken(lltok::rsquare, "expected ']' in phi value list"))
return true;
}
bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS,
bool isTail) {
unsigned CC, RetAttrs, FnAttrs;
- PATypeHolder RetType(Type::VoidTy);
+ PATypeHolder RetType(Type::getVoidTy(Context));
LocTy RetTypeLoc;
ValID CalleeID;
SmallVector<ParamInfo, 16> ArgList;
if ((isTail && ParseToken(lltok::kw_call, "expected 'tail call'")) ||
ParseOptionalCallingConv(CC) ||
ParseOptionalAttrs(RetAttrs, 1) ||
- ParseType(RetType, RetTypeLoc) ||
+ ParseType(RetType, RetTypeLoc, true /*void allowed*/) ||
ParseValID(CalleeID) ||
ParseParameterList(ArgList, PFS) ||
ParseOptionalAttrs(FnAttrs, 2))
Value *Callee;
if (ConvertValIDToValue(PFTy, CalleeID, Callee, PFS)) return true;
- // Check for call to invalid intrinsic to avoid crashing later.
- if (Function *F = dyn_cast<Function>(Callee)) {
- if (F->hasName() && F->getNameLen() >= 5 &&
- !strncmp(F->getValueName()->getKeyData(), "llvm.", 5) &&
- !F->getIntrinsicID(true))
- return Error(CallLoc, "Call to invalid LLVM intrinsic function '" +
- F->getNameStr() + "'");
- }
-
// FIXME: In LLVM 3.0, stop accepting zext, sext and inreg as optional
// function attributes.
unsigned ObsoleteFuncAttrs = Attribute::ZExt|Attribute::SExt|Attribute::InReg;
/// ::= 'alloca' Type (',' TypeAndValue)? (',' OptionalAlignment)?
bool LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS,
unsigned Opc) {
- PATypeHolder Ty(Type::VoidTy);
+ PATypeHolder Ty(Type::getVoidTy(Context));
Value *Size = 0;
- LocTy SizeLoc = 0;
+ LocTy SizeLoc;
unsigned Alignment = 0;
if (ParseType(Ty)) return true;
}
}
- if (Size && Size->getType() != Type::Int32Ty)
+ if (Size && Size->getType() != Type::getInt32Ty(Context))
return Error(SizeLoc, "element count must be i32");
if (Opc == Instruction::Malloc)
}
/// ParseLoad
-/// ::= 'volatile'? 'load' TypeAndValue (',' 'align' uint)?
+/// ::= 'volatile'? 'load' TypeAndValue (',' 'align' i32)?
bool LLParser::ParseLoad(Instruction *&Inst, PerFunctionState &PFS,
bool isVolatile) {
Value *Val; LocTy Loc;
}
/// ParseStore
-/// ::= 'volatile'? 'store' TypeAndValue ',' TypeAndValue (',' 'align' uint)?
+/// ::= 'volatile'? 'store' TypeAndValue ',' TypeAndValue (',' 'align' i32)?
bool LLParser::ParseStore(Instruction *&Inst, PerFunctionState &PFS,
bool isVolatile) {
Value *Val, *Ptr; LocTy Loc, PtrLoc;
}
/// ParseGetResult
-/// ::= 'getresult' TypeAndValue ',' uint
+/// ::= 'getresult' TypeAndValue ',' i32
/// FIXME: Remove support for getresult in LLVM 3.0
bool LLParser::ParseGetResult(Instruction *&Inst, PerFunctionState &PFS) {
Value *Val; LocTy ValLoc, EltLoc;
}
/// ParseGetElementPtr
-/// ::= 'getelementptr' TypeAndValue (',' TypeAndValue)*
+/// ::= 'getelementptr' 'inbounds'? TypeAndValue (',' TypeAndValue)*
bool LLParser::ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
Value *Ptr, *Val; LocTy Loc, EltLoc;
+
+ bool InBounds = EatIfPresent(lltok::kw_inbounds);
+
if (ParseTypeAndValue(Ptr, Loc, PFS)) return true;
if (!isa<PointerType>(Ptr->getType()))
Indices.begin(), Indices.end()))
return Error(Loc, "invalid getelementptr indices");
Inst = GetElementPtrInst::Create(Ptr, Indices.begin(), Indices.end());
+ if (InBounds)
+ cast<GEPOperator>(Inst)->setIsInBounds(true);
return false;
}
Inst = InsertValueInst::Create(Val0, Val1, Indices.begin(), Indices.end());
return false;
}
+
+//===----------------------------------------------------------------------===//
+// Embedded metadata.
+//===----------------------------------------------------------------------===//
+
+/// ParseMDNodeVector
+/// ::= Element (',' Element)*
+/// Element
+/// ::= 'null' | TypeAndValue
+bool LLParser::ParseMDNodeVector(SmallVectorImpl<Value*> &Elts) {
+ assert(Lex.getKind() == lltok::lbrace);
+ Lex.Lex();
+ do {
+ Value *V = 0;
+ if (Lex.getKind() == lltok::kw_null) {
+ Lex.Lex();
+ V = 0;
+ } else {
+ PATypeHolder Ty(Type::getVoidTy(Context));
+ if (ParseType(Ty)) return true;
+ if (Lex.getKind() == lltok::Metadata) {
+ Lex.Lex();
+ MetadataBase *Node = 0;
+ if (!ParseMDNode(Node))
+ V = Node;
+ else {
+ MetadataBase *MDS = 0;
+ if (ParseMDString(MDS)) return true;
+ V = MDS;
+ }
+ } else {
+ Constant *C;
+ if (ParseGlobalValue(Ty, C)) return true;
+ V = C;
+ }
+ }
+ Elts.push_back(V);
+ } while (EatIfPresent(lltok::comma));
+
+ return false;
+}