[PATCH] D33245: Simplify the use of CVTypeVisitor
Zachary Turner via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 16 10:30:32 PDT 2017
zturner created this revision.
Similar to https://reviews.llvm.org/D33229, this patch is aimed at reducing boilerplate and simplifying usage.
The problem I'm trying to address here is that there is often a lot of code required to visit a type stream, or even a single record. You have to create a visitation pipeline. Then you have to stick a bunch of visitors in it. Then you have to invoke the right method on the pipeline. This is usually between 3 and 6 lines of code, with at least 3 different objects in play. But one of the most common usages is that you have a sequence of bytes, and you want to visit them as deserialized records. In order to make this work, you have to create a `TypeVisitorCallbackPipeline` and then put a `TypeDeserializer` on it to deserialize the records, and only then can you add your real callbacks to the visitation pipeline.
Since this is such a common use case, it would be nice if it were automatic. But we don't always want to deserialize records first. We might not even **have** any record data to deserialize in the first place (think Yaml -> PDB where we have Yaml describing the records, not bytes). So it can't be required.
At the same time, there is no fundamental reason why `CVTypeVisitor` has to be an object. It just happens to be one. We could just invoke a free free function and pass the visitor into the free function instead of constructing a `CVTypeVisitor` with one.
So this patch does all of the above. After this patch, the following code:
if (IO.outputting()) {
codeview::TypeDeserializer Deserializer;
codeview::TypeVisitorCallbackPipeline Pipeline;
Pipeline.addCallbackToPipeline(Deserializer);
Pipeline.addCallbackToPipeline(Context.Dumper);
codeview::CVTypeVisitor Visitor(Pipeline);
consumeError(Visitor.visitTypeRecord(Record));
}
turns into this:
if (IO.outputting())
consumeError(codeview::visitTypeRecord(Record, Context.Dumper));
https://reviews.llvm.org/D33245
Files:
llvm/include/llvm/DebugInfo/CodeView/CVTypeVisitor.h
llvm/include/llvm/DebugInfo/CodeView/RandomAccessTypeVisitor.h
llvm/include/llvm/DebugInfo/PDB/Native/TpiStream.h
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/lib/DebugInfo/CodeView/CVTypeDumper.cpp
llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp
llvm/lib/DebugInfo/CodeView/RandomAccessTypeVisitor.cpp
llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp
llvm/lib/DebugInfo/CodeView/TypeStreamMerger.cpp
llvm/lib/DebugInfo/PDB/Native/PDBTypeServerHandler.cpp
llvm/tools/llvm-pdbdump/Analyze.cpp
llvm/tools/llvm-pdbdump/LLVMOutputStyle.cpp
llvm/tools/llvm-pdbdump/PdbYaml.cpp
llvm/tools/llvm-pdbdump/YamlTypeDumper.cpp
llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp
llvm/unittests/DebugInfo/PDB/TypeServerHandlerTest.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33245.99163.patch
Type: text/x-patch
Size: 27821 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170516/e98e94c4/attachment-0001.bin>
More information about the llvm-commits
mailing list