summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/BinaryFormat
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2018-03-21 11:46:37 +0000
committerPavel Labath <labath@google.com>2018-03-21 11:46:37 +0000
commit9025f9559d778f425dbcc7f55917a6dccbb7d2f1 (patch)
treeb8dcc62f78e306eced611a27b9b0365daa6172b8 /llvm/unittests/BinaryFormat
parentecc8aee652d66dd2a9db575a66d13b477582bcb2 (diff)
downloadbcm5719-llvm-9025f9559d778f425dbcc7f55917a6dccbb7d2f1.tar.gz
bcm5719-llvm-9025f9559d778f425dbcc7f55917a6dccbb7d2f1.zip
[dwarf] Unify unknown dwarf enum formatting code
Summary: We have had at least three pieces of code (in DWARFAbbreviationDeclaration, DWARFAcceleratorTable and DWARFDie) that have hand-rolled support for dumping unknown dwarf enum values. While not terrible, they are a bit distracting and enable small differences to creep in (Unknown_ffff vs. Unknown_0xffff). I ended up needing to add a fourth place (DWARFVerifier), so it seems it would be a good time to centralize. This patch creates an alternative to the XXXString dumping functions in the BinaryFormat library, which formats an unknown value as DW_TYPE_unknown_1234, instead of just an empty string. It is based on the formatv function, as that allows us to avoid materializing the string for unknown values (and because this way I don't have to invent a name for the new functions :P). In this patch I add formatters for dwarf attributes, forms, tags, and index attributes as these are the ones in use currently, but adding other enums is straight-forward. Reviewers: dblaikie, JDevlieghere, aprantl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D44570 llvm-svn: 328090
Diffstat (limited to 'llvm/unittests/BinaryFormat')
-rw-r--r--llvm/unittests/BinaryFormat/DwarfTest.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/unittests/BinaryFormat/DwarfTest.cpp b/llvm/unittests/BinaryFormat/DwarfTest.cpp
index c30910aa856..08a731f6174 100644
--- a/llvm/unittests/BinaryFormat/DwarfTest.cpp
+++ b/llvm/unittests/BinaryFormat/DwarfTest.cpp
@@ -9,6 +9,7 @@
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatVariadic.h"
#include "gtest/gtest.h"
using namespace llvm;
@@ -192,4 +193,14 @@ TEST(DwarfTest, FixedFormSizes) {
EXPECT_EQ(*RefSize, 8);
}
+TEST(DwarfTest, format_provider) {
+ EXPECT_EQ("DW_AT_name", formatv("{0}", DW_AT_name).str());
+ EXPECT_EQ("DW_AT_unknown_3fff", formatv("{0}", DW_AT_hi_user).str());
+ EXPECT_EQ("DW_FORM_addr", formatv("{0}", DW_FORM_addr).str());
+ EXPECT_EQ("DW_FORM_unknown_1f00", formatv("{0}", DW_FORM_lo_user).str());
+ EXPECT_EQ("DW_IDX_compile_unit", formatv("{0}", DW_IDX_compile_unit).str());
+ EXPECT_EQ("DW_IDX_unknown_3fff", formatv("{0}", DW_IDX_hi_user).str());
+ EXPECT_EQ("DW_TAG_compile_unit", formatv("{0}", DW_TAG_compile_unit).str());
+ EXPECT_EQ("DW_TAG_unknown_ffff", formatv("{0}", DW_TAG_hi_user).str());
+}
} // end namespace
OpenPOWER on IntegriCloud