summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-08-31 23:14:31 +0000
committerZachary Turner <zturner@google.com>2016-08-31 23:14:31 +0000
commit77807637ffb0fffd6f215187258b0e12c6b6a620 (patch)
tree4215a4361a29ae79026b28478948056d7109fdf2
parent97e49ac59e428a935971139dc69750e25c8d2ac8 (diff)
downloadbcm5719-llvm-77807637ffb0fffd6f215187258b0e12c6b6a620.tar.gz
bcm5719-llvm-77807637ffb0fffd6f215187258b0e12c6b6a620.zip
[codeview] Have visitTypeBegin return the record type.
Previously we were assuming that any visitation of types would necessarily be against a type we had binary data for. Reasonable assumption when were just reading PDBs and dumping them, but once we start writing PDBs from Yaml this breaks down, because we have no binary data yet, only Yaml, and from that we need to read the record kind and perform the switch based on that. So this patch does that. Instead of having the visitor switch on the kind that is already in the CVType record, we change the visitTypeBegin() method to return the Kind, and switch on the returned value. This way, the default implementation can still return the value from the CVType, but the implementation which visits Yaml records and serializes binary PDB type records can use the field in the Yaml as the source of the switch. llvm-svn: 280307
-rw-r--r--llvm/include/llvm/DebugInfo/CodeView/TypeDumper.h3
-rw-r--r--llvm/include/llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h12
-rw-r--r--llvm/include/llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h8
-rw-r--r--llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp14
-rw-r--r--llvm/lib/DebugInfo/CodeView/TypeDumper.cpp5
-rw-r--r--llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp8
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/TpiStream.cpp5
-rw-r--r--llvm/tools/llvm-pdbdump/CodeViewYaml.cpp8
-rw-r--r--llvm/tools/llvm-pdbdump/CodeViewYaml.h3
9 files changed, 43 insertions, 23 deletions
diff --git a/llvm/include/llvm/DebugInfo/CodeView/TypeDumper.h b/llvm/include/llvm/DebugInfo/CodeView/TypeDumper.h
index 49db43d6b7b..598f9704780 100644
--- a/llvm/include/llvm/DebugInfo/CodeView/TypeDumper.h
+++ b/llvm/include/llvm/DebugInfo/CodeView/TypeDumper.h
@@ -68,7 +68,8 @@ public:
/// Paired begin/end actions for all types. Receives all record data,
/// including the fixed-length record prefix.
- Error visitTypeBegin(const CVRecord<TypeLeafKind> &Record) override;
+ Expected<TypeLeafKind>
+ visitTypeBegin(const CVRecord<TypeLeafKind> &Record) override;
Error visitTypeEnd(const CVRecord<TypeLeafKind> &Record) override;
#define TYPE_RECORD(EnumName, EnumVal, Name) \
diff --git a/llvm/include/llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h b/llvm/include/llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h
index 3bfd52d4da4..d158f42947c 100644
--- a/llvm/include/llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h
+++ b/llvm/include/llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h
@@ -40,12 +40,16 @@ public:
return Error::success();
}
- virtual Error visitTypeBegin(const CVRecord<TypeLeafKind> &Record) override {
+ virtual Expected<TypeLeafKind>
+ visitTypeBegin(const CVRecord<TypeLeafKind> &Record) override {
+ TypeLeafKind Kind = Record.Type;
for (auto Visitor : Pipeline) {
- if (auto EC = Visitor->visitTypeBegin(Record))
- return EC;
+ if (auto ExpectedKind = Visitor->visitTypeBegin(Record))
+ Kind = *ExpectedKind;
+ else
+ return ExpectedKind.takeError();
}
- return Error::success();
+ return Kind;
}
virtual Error visitTypeEnd(const CVRecord<TypeLeafKind> &Record) override {
for (auto Visitor : Pipeline) {
diff --git a/llvm/include/llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h b/llvm/include/llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h
index a734d480fe3..ecae9eef807 100644
--- a/llvm/include/llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h
+++ b/llvm/include/llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h
@@ -33,9 +33,11 @@ public:
}
/// Paired begin/end actions for all types. Receives all record data,
- /// including the fixed-length record prefix.
- virtual Error visitTypeBegin(const CVRecord<TypeLeafKind> &Record) {
- return Error::success();
+ /// including the fixed-length record prefix. visitTypeBegin() should return
+ /// the type of the Record, or an error if it cannot be determined.
+ virtual Expected<TypeLeafKind>
+ visitTypeBegin(const CVRecord<TypeLeafKind> &Record) {
+ return Record.Type;
}
virtual Error visitTypeEnd(const CVRecord<TypeLeafKind> &Record) {
return Error::success();
diff --git a/llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp b/llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp
index 18215d35582..b4c3a9f4c21 100644
--- a/llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp
+++ b/llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp
@@ -75,10 +75,13 @@ static Error visitKnownRecord(const CVRecord<TypeLeafKind> &Record,
}
Error CVTypeVisitor::visitTypeRecord(const CVRecord<TypeLeafKind> &Record) {
- if (auto EC = Callbacks.visitTypeBegin(Record))
- return EC;
+ TypeLeafKind Kind;
+ if (auto ExpectedKind = Callbacks.visitTypeBegin(Record))
+ Kind = *ExpectedKind;
+ else
+ return ExpectedKind.takeError();
- switch (Record.Type) {
+ switch (Kind) {
default:
if (auto EC = Callbacks.visitUnknownType(Record))
return EC;
@@ -133,8 +136,9 @@ Error CVTypeVisitor::visitFieldListMemberStream(ArrayRef<uint8_t> Data) {
if (!ExpectedRecord) \
return ExpectedRecord.takeError(); \
auto &Record = *ExpectedRecord; \
- if (auto EC = Callbacks.visitTypeBegin(Record)) \
- return EC; \
+ auto ExpectedKind = Callbacks.visitTypeBegin(Record); \
+ if (!ExpectedKind || *ExpectedKind != Leaf) \
+ return ExpectedKind.takeError(); \
if (auto EC = visitKnownRecord<Name##Record>(Record, Callbacks)) \
return EC; \
if (auto EC = Callbacks.visitTypeEnd(Record)) \
diff --git a/llvm/lib/DebugInfo/CodeView/TypeDumper.cpp b/llvm/lib/DebugInfo/CodeView/TypeDumper.cpp
index f7dfdd2f398..43e29b7f451 100644
--- a/llvm/lib/DebugInfo/CodeView/TypeDumper.cpp
+++ b/llvm/lib/DebugInfo/CodeView/TypeDumper.cpp
@@ -203,7 +203,8 @@ static StringRef getLeafTypeName(TypeLeafKind LT) {
return "UnknownLeaf";
}
-Error CVTypeDumper::visitTypeBegin(const CVRecord<TypeLeafKind> &Record) {
+Expected<TypeLeafKind>
+CVTypeDumper::visitTypeBegin(const CVRecord<TypeLeafKind> &Record) {
// Reset Name to the empty string. If the visitor sets it, we know it.
Name = "";
@@ -223,7 +224,7 @@ Error CVTypeDumper::visitTypeBegin(const CVRecord<TypeLeafKind> &Record) {
assert(!IsInFieldList);
IsInFieldList = true;
}
- return Error::success();
+ return Record.Type;
}
Error CVTypeDumper::visitTypeEnd(const CVRecord<TypeLeafKind> &Record) {
diff --git a/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp b/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
index ddc3f4af58e..f2a7298a8d1 100644
--- a/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
+++ b/llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
@@ -70,7 +70,8 @@ public:
Error visitUnknownType(const CVRecord<TypeLeafKind> &Record) override;
- Error visitTypeBegin(const CVRecord<TypeLeafKind> &Record) override;
+ Expected<TypeLeafKind>
+ visitTypeBegin(const CVRecord<TypeLeafKind> &Record) override;
Error visitTypeEnd(const CVRecord<TypeLeafKind> &Record) override;
bool mergeStream(const CVTypeArray &Types);
@@ -123,13 +124,14 @@ private:
} // end anonymous namespace
-Error TypeStreamMerger::visitTypeBegin(const CVRecord<TypeLeafKind> &Rec) {
+Expected<TypeLeafKind>
+TypeStreamMerger::visitTypeBegin(const CVRecord<TypeLeafKind> &Rec) {
if (Rec.Type == TypeLeafKind::LF_FIELDLIST) {
assert(!IsInFieldList);
IsInFieldList = true;
} else
BeginIndexMapSize = IndexMap.size();
- return Error::success();
+ return Rec.Type;
}
Error TypeStreamMerger::visitTypeEnd(const CVRecord<TypeLeafKind> &Rec) {
diff --git a/llvm/lib/DebugInfo/PDB/Raw/TpiStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/TpiStream.cpp
index 74200e70119..7154b297b12 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/TpiStream.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/TpiStream.cpp
@@ -121,10 +121,11 @@ public:
return verify(Rec);
}
- Error visitTypeBegin(const CVRecord<TypeLeafKind> &Rec) override {
+ Expected<TypeLeafKind>
+ visitTypeBegin(const CVRecord<TypeLeafKind> &Rec) override {
++Index;
RawRecord = &Rec;
- return Error::success();
+ return Rec.Type;
}
private:
diff --git a/llvm/tools/llvm-pdbdump/CodeViewYaml.cpp b/llvm/tools/llvm-pdbdump/CodeViewYaml.cpp
index 96bf1c19aa6..e75f454b34a 100644
--- a/llvm/tools/llvm-pdbdump/CodeViewYaml.cpp
+++ b/llvm/tools/llvm-pdbdump/CodeViewYaml.cpp
@@ -508,9 +508,13 @@ void ScalarEnumerationTraits<TypeLeafKind>::enumeration(IO &io,
}
}
-Error llvm::codeview::yaml::YamlTypeDumperCallbacks::visitTypeBegin(
+Expected<TypeLeafKind>
+llvm::codeview::yaml::YamlTypeDumperCallbacks::visitTypeBegin(
const CVRecord<TypeLeafKind> &CVR) {
+ // When we're outputting, `CVR.Type` already has the right value in it. But
+ // when we're inputting, we need to read the value. Since `CVR.Type` is const
+ // we do it into a temp variable.
TypeLeafKind K = CVR.Type;
YamlIO.mapRequired("Kind", K);
- return Error::success();
+ return K;
}
diff --git a/llvm/tools/llvm-pdbdump/CodeViewYaml.h b/llvm/tools/llvm-pdbdump/CodeViewYaml.h
index bacb55cef40..8932d008ca3 100644
--- a/llvm/tools/llvm-pdbdump/CodeViewYaml.h
+++ b/llvm/tools/llvm-pdbdump/CodeViewYaml.h
@@ -21,7 +21,8 @@ class YamlTypeDumperCallbacks : public TypeVisitorCallbacks {
public:
YamlTypeDumperCallbacks(llvm::yaml::IO &IO) : YamlIO(IO) {}
- virtual Error visitTypeBegin(const CVRecord<TypeLeafKind> &Record) override;
+ virtual Expected<TypeLeafKind>
+ visitTypeBegin(const CVRecord<TypeLeafKind> &Record) override;
#define TYPE_RECORD(EnumName, EnumVal, Name) \
Error visitKnownRecord(const CVRecord<TypeLeafKind> &CVR, \
OpenPOWER on IntegriCloud