mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-07 14:33:15 +00:00
Consolidate ConvertGlobalValIDToValue, ConvertGlobalOrMetadataValIDToValue, and ConvertValIDToValue into a more powerful ConvertValIDToValue() that does all three's work
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93197 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d53e42efe9
commit
92f238dd8f
@ -2358,30 +2358,85 @@ bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// ParseGlobalValue - Parse a global value with the specified type.
|
/// ParseGlobalValue - Parse a global value with the specified type.
|
||||||
bool LLParser::ParseGlobalValue(const Type *Ty, Constant *&V) {
|
bool LLParser::ParseGlobalValue(const Type *Ty, Constant *&C) {
|
||||||
V = 0;
|
C = 0;
|
||||||
ValID ID;
|
ValID ID;
|
||||||
return ParseValID(ID) ||
|
Value *V = NULL;
|
||||||
ConvertGlobalValIDToValue(Ty, ID, V);
|
bool Parsed = ParseValID(ID) ||
|
||||||
|
ConvertValIDToValue(Ty, ID, V, NULL);
|
||||||
|
if (V && !(C = dyn_cast<Constant>(V)))
|
||||||
|
return Error(ID.Loc, "global values must be constants");
|
||||||
|
return Parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ConvertGlobalValIDToValue - Apply a type to a ValID to get a fully resolved
|
bool LLParser::ParseGlobalTypeAndValue(Constant *&V) {
|
||||||
/// constant.
|
PATypeHolder Type(Type::getVoidTy(Context));
|
||||||
bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID,
|
return ParseType(Type) ||
|
||||||
Constant *&V) {
|
ParseGlobalValue(Type, V);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ParseGlobalValueVector
|
||||||
|
/// ::= /*empty*/
|
||||||
|
/// ::= TypeAndValue (',' TypeAndValue)*
|
||||||
|
bool LLParser::ParseGlobalValueVector(SmallVectorImpl<Constant*> &Elts) {
|
||||||
|
// Empty list.
|
||||||
|
if (Lex.getKind() == lltok::rbrace ||
|
||||||
|
Lex.getKind() == lltok::rsquare ||
|
||||||
|
Lex.getKind() == lltok::greater ||
|
||||||
|
Lex.getKind() == lltok::rparen)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Constant *C;
|
||||||
|
if (ParseGlobalTypeAndValue(C)) return true;
|
||||||
|
Elts.push_back(C);
|
||||||
|
|
||||||
|
while (EatIfPresent(lltok::comma)) {
|
||||||
|
if (ParseGlobalTypeAndValue(C)) return true;
|
||||||
|
Elts.push_back(C);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Function Parsing.
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
bool LLParser::ConvertValIDToValue(const Type *Ty, ValID &ID, Value *&V,
|
||||||
|
PerFunctionState *PFS) {
|
||||||
if (isa<FunctionType>(Ty))
|
if (isa<FunctionType>(Ty))
|
||||||
return Error(ID.Loc, "functions are not values, refer to them as pointers");
|
return Error(ID.Loc, "functions are not values, refer to them as pointers");
|
||||||
|
|
||||||
switch (ID.Kind) {
|
switch (ID.Kind) {
|
||||||
default: llvm_unreachable("Unknown ValID!");
|
default: llvm_unreachable("Unknown ValID!");
|
||||||
case ValID::t_MDNode:
|
|
||||||
case ValID::t_MDString:
|
|
||||||
return Error(ID.Loc, "invalid use of metadata");
|
|
||||||
case ValID::t_LocalID:
|
case ValID::t_LocalID:
|
||||||
|
if (!PFS) return Error(ID.Loc, "invalid use of function-local name");
|
||||||
|
V = PFS->GetVal(ID.UIntVal, Ty, ID.Loc);
|
||||||
|
return (V == 0);
|
||||||
case ValID::t_LocalName:
|
case ValID::t_LocalName:
|
||||||
return Error(ID.Loc, "invalid use of function-local name");
|
if (!PFS) return Error(ID.Loc, "invalid use of function-local name");
|
||||||
case ValID::t_InlineAsm:
|
V = PFS->GetVal(ID.StrVal, Ty, ID.Loc);
|
||||||
return Error(ID.Loc, "inline asm can only be an operand of call/invoke");
|
return (V == 0);
|
||||||
|
case ValID::t_InlineAsm: {
|
||||||
|
const PointerType *PTy = dyn_cast<PointerType>(Ty);
|
||||||
|
const FunctionType *FTy =
|
||||||
|
PTy ? dyn_cast<FunctionType>(PTy->getElementType()) : 0;
|
||||||
|
if (!FTy || !InlineAsm::Verify(FTy, ID.StrVal2))
|
||||||
|
return Error(ID.Loc, "invalid type for inline asm constraint string");
|
||||||
|
V = InlineAsm::get(FTy, ID.StrVal, ID.StrVal2, ID.UIntVal&1, ID.UIntVal>>1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case ValID::t_MDNode:
|
||||||
|
if (!Ty->isMetadataTy())
|
||||||
|
return Error(ID.Loc, "metadata value must have metadata type");
|
||||||
|
V = ID.MDNodeVal;
|
||||||
|
return false;
|
||||||
|
case ValID::t_MDString:
|
||||||
|
if (!Ty->isMetadataTy())
|
||||||
|
return Error(ID.Loc, "metadata value must have metadata type");
|
||||||
|
V = ID.MDStringVal;
|
||||||
|
return false;
|
||||||
case ValID::t_GlobalName:
|
case ValID::t_GlobalName:
|
||||||
V = GetGlobalVal(ID.StrVal, Ty, ID.Loc);
|
V = GetGlobalVal(ID.StrVal, Ty, ID.Loc);
|
||||||
return V == 0;
|
return V == 0;
|
||||||
@ -2445,100 +2500,11 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ConvertGlobalOrMetadataValIDToValue - Apply a type to a ValID to get a fully
|
|
||||||
/// resolved constant, metadata, or function-local value. PFS is used to
|
|
||||||
/// convert a function-local ValID and can be null when parsing a global or a
|
|
||||||
/// non-function-local metadata ValID.
|
|
||||||
|
|
||||||
bool LLParser::ConvertGlobalOrMetadataValIDToValue(const Type *Ty, ValID &ID,
|
|
||||||
Value *&V,
|
|
||||||
PerFunctionState *PFS) {
|
|
||||||
switch (ID.Kind) {
|
|
||||||
case ValID::t_MDNode:
|
|
||||||
if (!Ty->isMetadataTy())
|
|
||||||
return Error(ID.Loc, "metadata value must have metadata type");
|
|
||||||
V = ID.MDNodeVal;
|
|
||||||
return false;
|
|
||||||
case ValID::t_MDString:
|
|
||||||
if (!Ty->isMetadataTy())
|
|
||||||
return Error(ID.Loc, "metadata value must have metadata type");
|
|
||||||
V = ID.MDStringVal;
|
|
||||||
return false;
|
|
||||||
case ValID::t_LocalID:
|
|
||||||
case ValID::t_LocalName:
|
|
||||||
if (!PFS)
|
|
||||||
return Error(ID.Loc, "invalid use of function-local name");
|
|
||||||
if (ConvertValIDToValue(Ty, ID, V, *PFS)) return true;
|
|
||||||
return false;
|
|
||||||
default:
|
|
||||||
Constant *C;
|
|
||||||
if (ConvertGlobalValIDToValue(Ty, ID, C)) return true;
|
|
||||||
V = C;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool LLParser::ParseGlobalTypeAndValue(Constant *&V) {
|
|
||||||
PATypeHolder Type(Type::getVoidTy(Context));
|
|
||||||
return ParseType(Type) ||
|
|
||||||
ParseGlobalValue(Type, V);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ParseGlobalValueVector
|
|
||||||
/// ::= /*empty*/
|
|
||||||
/// ::= TypeAndValue (',' TypeAndValue)*
|
|
||||||
bool LLParser::ParseGlobalValueVector(SmallVectorImpl<Constant*> &Elts) {
|
|
||||||
// Empty list.
|
|
||||||
if (Lex.getKind() == lltok::rbrace ||
|
|
||||||
Lex.getKind() == lltok::rsquare ||
|
|
||||||
Lex.getKind() == lltok::greater ||
|
|
||||||
Lex.getKind() == lltok::rparen)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
Constant *C;
|
|
||||||
if (ParseGlobalTypeAndValue(C)) return true;
|
|
||||||
Elts.push_back(C);
|
|
||||||
|
|
||||||
while (EatIfPresent(lltok::comma)) {
|
|
||||||
if (ParseGlobalTypeAndValue(C)) return true;
|
|
||||||
Elts.push_back(C);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
// Function Parsing.
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
bool LLParser::ConvertValIDToValue(const Type *Ty, ValID &ID, Value *&V,
|
|
||||||
PerFunctionState &PFS) {
|
|
||||||
switch (ID.Kind) {
|
|
||||||
case ValID::t_LocalID: V = PFS.GetVal(ID.UIntVal, Ty, ID.Loc); break;
|
|
||||||
case ValID::t_LocalName: V = PFS.GetVal(ID.StrVal, Ty, ID.Loc); break;
|
|
||||||
case ValID::t_InlineAsm: {
|
|
||||||
const PointerType *PTy = dyn_cast<PointerType>(Ty);
|
|
||||||
const FunctionType *FTy =
|
|
||||||
PTy ? dyn_cast<FunctionType>(PTy->getElementType()) : 0;
|
|
||||||
if (!FTy || !InlineAsm::Verify(FTy, ID.StrVal2))
|
|
||||||
return Error(ID.Loc, "invalid type for inline asm constraint string");
|
|
||||||
V = InlineAsm::get(FTy, ID.StrVal, ID.StrVal2, ID.UIntVal&1, ID.UIntVal>>1);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return ConvertGlobalOrMetadataValIDToValue(Ty, ID, V, &PFS);
|
|
||||||
}
|
|
||||||
|
|
||||||
return V == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LLParser::ParseValue(const Type *Ty, Value *&V, PerFunctionState &PFS) {
|
bool LLParser::ParseValue(const Type *Ty, Value *&V, PerFunctionState &PFS) {
|
||||||
V = 0;
|
V = 0;
|
||||||
ValID ID;
|
ValID ID;
|
||||||
return ParseValID(ID, &PFS) ||
|
return ParseValID(ID, &PFS) ||
|
||||||
ConvertValIDToValue(Ty, ID, V, PFS);
|
ConvertValIDToValue(Ty, ID, V, &PFS);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LLParser::ParseTypeAndValue(Value *&V, PerFunctionState &PFS) {
|
bool LLParser::ParseTypeAndValue(Value *&V, PerFunctionState &PFS) {
|
||||||
@ -3250,7 +3216,7 @@ bool LLParser::ParseInvoke(Instruction *&Inst, PerFunctionState &PFS) {
|
|||||||
|
|
||||||
// Look up the callee.
|
// Look up the callee.
|
||||||
Value *Callee;
|
Value *Callee;
|
||||||
if (ConvertValIDToValue(PFTy, CalleeID, Callee, PFS)) return true;
|
if (ConvertValIDToValue(PFTy, CalleeID, Callee, &PFS)) return true;
|
||||||
|
|
||||||
// FIXME: In LLVM 3.0, stop accepting zext, sext and inreg as optional
|
// FIXME: In LLVM 3.0, stop accepting zext, sext and inreg as optional
|
||||||
// function attributes.
|
// function attributes.
|
||||||
@ -3596,7 +3562,7 @@ bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS,
|
|||||||
|
|
||||||
// Look up the callee.
|
// Look up the callee.
|
||||||
Value *Callee;
|
Value *Callee;
|
||||||
if (ConvertValIDToValue(PFTy, CalleeID, Callee, PFS)) return true;
|
if (ConvertValIDToValue(PFTy, CalleeID, Callee, &PFS)) return true;
|
||||||
|
|
||||||
// FIXME: In LLVM 3.0, stop accepting zext, sext and inreg as optional
|
// FIXME: In LLVM 3.0, stop accepting zext, sext and inreg as optional
|
||||||
// function attributes.
|
// function attributes.
|
||||||
@ -3871,7 +3837,7 @@ bool LLParser::ParseMDNodeVector(SmallVectorImpl<Value*> &Elts,
|
|||||||
PATypeHolder Ty(Type::getVoidTy(Context));
|
PATypeHolder Ty(Type::getVoidTy(Context));
|
||||||
ValID ID;
|
ValID ID;
|
||||||
if (ParseType(Ty) || ParseValID(ID, PFS) ||
|
if (ParseType(Ty) || ParseValID(ID, PFS) ||
|
||||||
ConvertGlobalOrMetadataValIDToValue(Ty, ID, V, PFS))
|
ConvertValIDToValue(Ty, ID, V, PFS))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Elts.push_back(V);
|
Elts.push_back(V);
|
||||||
|
@ -259,7 +259,7 @@ namespace llvm {
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool ConvertValIDToValue(const Type *Ty, ValID &ID, Value *&V,
|
bool ConvertValIDToValue(const Type *Ty, ValID &ID, Value *&V,
|
||||||
PerFunctionState &PFS);
|
PerFunctionState *PFS);
|
||||||
|
|
||||||
bool ParseValue(const Type *Ty, Value *&V, PerFunctionState &PFS);
|
bool ParseValue(const Type *Ty, Value *&V, PerFunctionState &PFS);
|
||||||
bool ParseValue(const Type *Ty, Value *&V, LocTy &Loc,
|
bool ParseValue(const Type *Ty, Value *&V, LocTy &Loc,
|
||||||
@ -292,9 +292,6 @@ namespace llvm {
|
|||||||
|
|
||||||
// Constant Parsing.
|
// Constant Parsing.
|
||||||
bool ParseValID(ValID &ID, PerFunctionState *PFS = NULL);
|
bool ParseValID(ValID &ID, PerFunctionState *PFS = NULL);
|
||||||
bool ConvertGlobalValIDToValue(const Type *Ty, ValID &ID, Constant *&V);
|
|
||||||
bool ConvertGlobalOrMetadataValIDToValue(const Type *Ty, ValID &ID,
|
|
||||||
Value *&V, PerFunctionState *PFS);
|
|
||||||
bool ParseGlobalValue(const Type *Ty, Constant *&V);
|
bool ParseGlobalValue(const Type *Ty, Constant *&V);
|
||||||
bool ParseGlobalTypeAndValue(Constant *&V);
|
bool ParseGlobalTypeAndValue(Constant *&V);
|
||||||
bool ParseGlobalValueVector(SmallVectorImpl<Constant*> &Elts);
|
bool ParseGlobalValueVector(SmallVectorImpl<Constant*> &Elts);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user