[PECOFF] Refactor module-defintion file parser.
Refactor the parser so that the parser can return arbitrary type of parse result other than a vector of ExportDesc. Parsers for non-EXPORTS directives will be implemented in different patches. No functionality change. llvm-svn: 198993
This commit is contained in:
@@ -18,25 +18,33 @@ using namespace lld;
|
||||
|
||||
class ParserTest : public testing::Test {
|
||||
protected:
|
||||
bool parse(const char *contents,
|
||||
std::vector<PECOFFLinkingContext::ExportDesc> &ret) {
|
||||
llvm::Optional<moduledef::Directive *> parse(const char *contents,
|
||||
llvm::BumpPtrAllocator &alloc) {
|
||||
auto membuf =
|
||||
std::unique_ptr<MemoryBuffer>(MemoryBuffer::getMemBuffer(contents));
|
||||
moduledef::Lexer lexer(std::move(membuf));
|
||||
moduledef::Parser parser(lexer);
|
||||
return parser.parse(ret);
|
||||
moduledef::Parser parser(lexer, alloc);
|
||||
return parser.parse();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(ParserTest, Exports) {
|
||||
std::vector<PECOFFLinkingContext::ExportDesc> exports;
|
||||
EXPECT_TRUE(parse("EXPORTS\n"
|
||||
" sym1\n"
|
||||
" sym2 @5\n"
|
||||
" sym3 @8 NONAME\n"
|
||||
" sym4 DATA\n"
|
||||
" sym5 @10 NONAME DATA\n",
|
||||
exports));
|
||||
llvm::BumpPtrAllocator alloc;
|
||||
llvm::Optional<moduledef::Directive *> dir = parse("EXPORTS\n"
|
||||
" sym1\n"
|
||||
" sym2 @5\n"
|
||||
" sym3 @8 NONAME\n"
|
||||
" sym4 DATA\n"
|
||||
" sym5 @10 NONAME DATA\n",
|
||||
alloc);
|
||||
EXPECT_TRUE(dir.hasValue());
|
||||
EXPECT_EQ(moduledef::Directive::Kind::exports, dir.getValue()->getKind());
|
||||
|
||||
auto *exportsDir = dyn_cast<moduledef::Exports>(dir.getValue());
|
||||
EXPECT_TRUE(exportsDir != nullptr);
|
||||
|
||||
const std::vector<PECOFFLinkingContext::ExportDesc> &exports =
|
||||
exportsDir->getExports();
|
||||
EXPECT_EQ(5U, exports.size());
|
||||
EXPECT_EQ(exports[0].name, "sym1");
|
||||
EXPECT_EQ(exports[0].ordinal, -1);
|
||||
|
||||
Reference in New Issue
Block a user