diff options
author | Alex Lorenz <arphaman@gmail.com> | 2015-06-23 17:10:10 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2015-06-23 17:10:10 +0000 |
commit | d31dc69aa100f8cb0dc673f45215e9338711f179 (patch) | |
tree | 6700984cf4cd9386d653601e727a2ca824270845 /unittests/AsmParser | |
parent | 3edc38d96735d000db766f7fc7a1466c134326e6 (diff) |
AsmParser: Extend the API to make the global value and metadata node slot mappings publicly accessible.
This commit creates a new structure called 'SlotMapping' in the AsmParser library.
This structure can be passed into the public parsing APIs from the AsmParser library
in order to extract the data structures that map from slot numbers to unnamed global
values and metadata nodes.
This change is useful for MIR Serialization, as the MIR Parser has to lookup the
unnamed global values and metadata nodes by their slot numbers.
Reviewers: Duncan P. N. Exon Smith
Differential Revision: http://reviews.llvm.org/D10551
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240427 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/AsmParser')
-rw-r--r-- | unittests/AsmParser/AsmParserTest.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/unittests/AsmParser/AsmParserTest.cpp b/unittests/AsmParser/AsmParserTest.cpp index 8847b1871673..9c2081fa2f2d 100644 --- a/unittests/AsmParser/AsmParserTest.cpp +++ b/unittests/AsmParser/AsmParserTest.cpp @@ -9,6 +9,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/AsmParser/Parser.h" +#include "llvm/AsmParser/SlotMapping.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/Support/SourceMgr.h" @@ -44,4 +45,23 @@ TEST(AsmParserTest, NonNullTerminatedInput) { #endif #endif +TEST(AsmParserTest, SlotMappingTest) { + LLVMContext &Ctx = getGlobalContext(); + StringRef Source = "@0 = global i32 0\n !0 = !{}\n !42 = !{i32 42}"; + SMDiagnostic Error; + SlotMapping Mapping; + auto Mod = parseAssemblyString(Source, Error, Ctx, &Mapping); + + EXPECT_TRUE(Mod != nullptr); + EXPECT_TRUE(Error.getMessage().empty()); + + ASSERT_EQ(Mapping.GlobalValues.size(), 1u); + EXPECT_TRUE(isa<GlobalVariable>(Mapping.GlobalValues[0])); + + EXPECT_EQ(Mapping.MetadataNodes.size(), 2u); + EXPECT_EQ(Mapping.MetadataNodes.count(0), 1u); + EXPECT_EQ(Mapping.MetadataNodes.count(42), 1u); + EXPECT_EQ(Mapping.MetadataNodes.count(1), 0u); +} + } // end anonymous namespace |