mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-04 05:31:51 +00:00
Refactor metadata parsing routines into separate functions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76455 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a3af370dc1
commit
256be96457
@ -365,6 +365,47 @@ bool LLParser::ParseNamedGlobal() {
|
|||||||
return ParseAlias(Name, NameLoc, Visibility);
|
return ParseAlias(Name, NameLoc, Visibility);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MDString:
|
||||||
|
// ::= '!' STRINGCONSTANT
|
||||||
|
bool LLParser::ParseMDString(Constant *&MDS) {
|
||||||
|
std::string Str;
|
||||||
|
if (ParseStringConstant(Str)) return true;
|
||||||
|
MDS = Context.getMDString(Str.data(), Str.data() + Str.size());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// MDNode:
|
||||||
|
// ::= '!' MDNodeNumber
|
||||||
|
bool LLParser::ParseMDNode(Constant *&Node) {
|
||||||
|
// !{ ..., !42, ... }
|
||||||
|
unsigned MID = 0;
|
||||||
|
if (ParseUInt32(MID)) return true;
|
||||||
|
|
||||||
|
// Check existing MDNode.
|
||||||
|
std::map<unsigned, Constant *>::iterator I = MetadataCache.find(MID);
|
||||||
|
if (I != MetadataCache.end()) {
|
||||||
|
Node = I->second;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check known forward references.
|
||||||
|
std::map<unsigned, std::pair<Constant *, 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(Context.getMDString(FwdRefName));
|
||||||
|
MDNode *FwdNode = Context.getMDNode(Elts.data(), Elts.size());
|
||||||
|
ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.getLoc());
|
||||||
|
Node = FwdNode;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// ParseStandaloneMetadata:
|
/// ParseStandaloneMetadata:
|
||||||
/// !42 = !{...}
|
/// !42 = !{...}
|
||||||
bool LLParser::ParseStandaloneMetadata() {
|
bool LLParser::ParseStandaloneMetadata() {
|
||||||
@ -1647,36 +1688,12 @@ bool LLParser::ParseValID(ValID &ID) {
|
|||||||
|
|
||||||
// Standalone metadata reference
|
// Standalone metadata reference
|
||||||
// !{ ..., !42, ... }
|
// !{ ..., !42, ... }
|
||||||
unsigned MID = 0;
|
if (!ParseMDNode(ID.ConstantVal))
|
||||||
if (!ParseUInt32(MID)) {
|
|
||||||
std::map<unsigned, Constant *>::iterator I = MetadataCache.find(MID);
|
|
||||||
if (I != MetadataCache.end())
|
|
||||||
ID.ConstantVal = I->second;
|
|
||||||
else {
|
|
||||||
std::map<unsigned, std::pair<Constant *, LocTy> >::iterator
|
|
||||||
FI = ForwardRefMDNodes.find(MID);
|
|
||||||
if (FI != ForwardRefMDNodes.end())
|
|
||||||
ID.ConstantVal = FI->second.first;
|
|
||||||
else {
|
|
||||||
// Create MDNode forward reference
|
|
||||||
SmallVector<Value *, 1> Elts;
|
|
||||||
std::string FwdRefName = "llvm.mdnode.fwdref." + utostr(MID);
|
|
||||||
Elts.push_back(Context.getMDString(FwdRefName));
|
|
||||||
MDNode *FwdNode = Context.getMDNode(Elts.data(), Elts.size());
|
|
||||||
ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.getLoc());
|
|
||||||
ID.ConstantVal = FwdNode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
// MDString:
|
// MDString:
|
||||||
// ::= '!' STRINGCONSTANT
|
// ::= '!' STRINGCONSTANT
|
||||||
std::string Str;
|
if (ParseMDString(ID.ConstantVal)) return true;
|
||||||
if (ParseStringConstant(Str)) return true;
|
|
||||||
|
|
||||||
ID.ConstantVal = Context.getMDString(Str.data(), Str.data() + Str.size());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case lltok::APSInt:
|
case lltok::APSInt:
|
||||||
|
@ -147,6 +147,8 @@ namespace llvm {
|
|||||||
bool HasLinkage, unsigned Visibility);
|
bool HasLinkage, unsigned Visibility);
|
||||||
bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility);
|
bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility);
|
||||||
bool ParseStandaloneMetadata();
|
bool ParseStandaloneMetadata();
|
||||||
|
bool ParseMDString(Constant *&S);
|
||||||
|
bool ParseMDNode(Constant *&N);
|
||||||
|
|
||||||
// Type Parsing.
|
// Type Parsing.
|
||||||
bool ParseType(PATypeHolder &Result, bool AllowVoid = false);
|
bool ParseType(PATypeHolder &Result, bool AllowVoid = false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user