summaryrefslogtreecommitdiffstats
path: root/llvm/lib/AsmParser/LLParser.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-02-04 22:05:21 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-02-04 22:05:21 +0000
commit077c0318dcf2e996df82924b232c55c525242949 (patch)
tree2c3a4e0930b006fdbb5459c9deac728d345182dd /llvm/lib/AsmParser/LLParser.cpp
parent79ede571947ff1232f1d63d6249299003b78b777 (diff)
downloadbcm5719-llvm-077c0318dcf2e996df82924b232c55c525242949.tar.gz
bcm5719-llvm-077c0318dcf2e996df82924b232c55c525242949.zip
AsmParser: Move MDField details to source file, NFC
Move all the types of `MDField` to an anonymous namespace in the source file. This also eliminates the duplication of `ParseMDField()` declarations in the header for each new field type. llvm-svn: 228211
Diffstat (limited to 'llvm/lib/AsmParser/LLParser.cpp')
-rw-r--r--llvm/lib/AsmParser/LLParser.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 31c9d65d1e2..427b38ee3b8 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -2923,6 +2923,44 @@ bool LLParser::ParseMDNodeTail(MDNode *&N) {
return ParseMDNodeID(N);
}
+namespace {
+
+/// Structure to represent an optional metadata field.
+template <class FieldTy> struct MDFieldImpl {
+ typedef MDFieldImpl ImplTy;
+ FieldTy Val;
+ bool Seen;
+
+ void assign(FieldTy Val) {
+ Seen = true;
+ this->Val = std::move(Val);
+ }
+
+ explicit MDFieldImpl(FieldTy Default)
+ : Val(std::move(Default)), Seen(false) {}
+};
+struct MDUnsignedField : public MDFieldImpl<uint64_t> {
+ uint64_t Max;
+
+ MDUnsignedField(uint64_t Default = 0, uint64_t Max = UINT64_MAX)
+ : ImplTy(Default), Max(Max) {}
+};
+struct DwarfTagField : public MDUnsignedField {
+ DwarfTagField() : MDUnsignedField(0, ~0u >> 16) {}
+};
+struct MDField : public MDFieldImpl<Metadata *> {
+ MDField() : ImplTy(nullptr) {}
+};
+struct MDStringField : public MDFieldImpl<std::string> {
+ MDStringField() : ImplTy(std::string()) {}
+};
+struct MDFieldList : public MDFieldImpl<SmallVector<Metadata *, 4>> {
+ MDFieldList() : ImplTy(SmallVector<Metadata *, 4>()) {}
+};
+
+} // end namespace
+
+template <>
bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
MDUnsignedField &Result) {
if (Lex.getKind() != lltok::APSInt || Lex.getAPSIntVal().isSigned())
@@ -2938,6 +2976,7 @@ bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
return false;
}
+template <>
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, DwarfTagField &Result) {
if (Lex.getKind() == lltok::APSInt)
return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
@@ -2955,6 +2994,7 @@ bool LLParser::ParseMDField(LocTy Loc, StringRef Name, DwarfTagField &Result) {
return false;
}
+template <>
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDField &Result) {
Metadata *MD;
if (ParseMetadata(MD, nullptr))
@@ -2964,6 +3004,7 @@ bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDField &Result) {
return false;
}
+template <>
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDStringField &Result) {
std::string S;
if (ParseStringConstant(S))
@@ -2973,6 +3014,7 @@ bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDStringField &Result) {
return false;
}
+template <>
bool LLParser::ParseMDField(LocTy Loc, StringRef Name, MDFieldList &Result) {
SmallVector<Metadata *, 4> MDs;
if (ParseMDNodeVector(MDs))
OpenPOWER on IntegriCloud