From 54174c6f16cb45a044e023ef84aab27c7c099b81 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Mon, 6 Jan 2014 19:55:58 +0000 Subject: [PATCH] [PECOFF] Simplify: Replace two-value enum with bool. llvm-svn: 198634 --- lld/include/lld/ReaderWriter/PECOFFLinkingContext.h | 14 ++++---------- lld/lib/Driver/WinLinkDriver.cpp | 4 ++-- lld/lib/ReaderWriter/PECOFF/SetSubsystemPass.h | 2 +- lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp | 6 ++---- lld/unittests/DriverTests/WinLinkDriverTest.cpp | 4 ++-- 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h index 9c80cd4..fd27343 100644 --- a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h +++ b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h @@ -46,8 +46,7 @@ public: _terminalServerAware(true), _dynamicBaseEnabled(true), _createManifest(true), _embedManifest(false), _manifestId(1), _manifestLevel("'asInvoker'"), _manifestUiAccess("'false'"), - _imageType(ImageType::exe), - _dosStub(llvm::makeArrayRef(DEFAULT_DOS_STUB)) { + _isDll(false), _dosStub(llvm::makeArrayRef(DEFAULT_DOS_STUB)) { setDeadStripping(true); } @@ -72,11 +71,6 @@ public: /// \brief Casting support static inline bool classof(const LinkingContext *info) { return true; } - enum class ImageType { - exe, - dll - }; - virtual Writer &writer() const; virtual bool validateImpl(raw_ostream &diagnostics); @@ -193,8 +187,8 @@ public: return _manifestDependency; } - void setImageType(ImageType type) { _imageType = type; } - ImageType getImageType() const { return _imageType; } + void setIsDll(bool val) { _isDll = val; } + bool isDll() const { return _isDll; } StringRef getOutputSectionName(StringRef sectionName) const; bool addSectionRenaming(raw_ostream &diagnostics, @@ -282,7 +276,7 @@ private: std::string _manifestLevel; std::string _manifestUiAccess; std::string _manifestDependency; - ImageType _imageType; + bool _isDll; // The set to store /nodefaultlib arguments. std::set _noDefaultLibs; diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp index ebbaa8b..ab1f37f 100644 --- a/lld/lib/Driver/WinLinkDriver.cpp +++ b/lld/lib/Driver/WinLinkDriver.cpp @@ -571,7 +571,7 @@ void processLibEnv(PECOFFLinkingContext &context) { // Returns a default entry point symbol name depending on context image type and // subsystem. These default names are MS CRT compliant. StringRef getDefaultEntrySymbolName(PECOFFLinkingContext &context) { - if (context.getImageType() == PECOFFLinkingContext::ImageType::dll) + if (context.isDll()) return "_DllMainCRTStartup@12"; llvm::COFF::WindowsSubsystem subsystem = context.getSubsystem(); if (subsystem == llvm::COFF::WindowsSubsystem::IMAGE_SUBSYSTEM_WINDOWS_GUI) @@ -726,7 +726,7 @@ WinLinkDriver::parse(int argc, const char *argv[], PECOFFLinkingContext &ctx, case OPT_dll: // Parse /dll command line option - ctx.setImageType(PECOFFLinkingContext::ImageType::dll); + ctx.setIsDll(true); // Default base address of a DLL is 0x10000000. if (!parsedArgs->getLastArg(OPT_base)) ctx.setBaseAddress(0x10000000); diff --git a/lld/lib/ReaderWriter/PECOFF/SetSubsystemPass.h b/lld/lib/ReaderWriter/PECOFF/SetSubsystemPass.h index 9495b8c..8371449 100644 --- a/lld/lib/ReaderWriter/PECOFF/SetSubsystemPass.h +++ b/lld/lib/ReaderWriter/PECOFF/SetSubsystemPass.h @@ -41,7 +41,7 @@ public: return; } } - if (_ctx.getImageType() == PECOFFLinkingContext::ImageType::dll) { + if (_ctx.isDll()) { _ctx.setSubsystem(WindowsSubsystem::IMAGE_SUBSYSTEM_WINDOWS_GUI); return; } diff --git a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp index e289792..8dfa20a 100644 --- a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp @@ -911,8 +911,7 @@ error_code PECOFFWriter::writeFile(const File &linkedFile, StringRef path) { applyAllRelocations(buffer->getBufferStart()); DEBUG(printAllAtomAddresses()); - if (_PECOFFLinkingContext.getImageType() == - PECOFFLinkingContext::ImageType::dll) + if (_PECOFFLinkingContext.isDll()) writeImportLibrary(_PECOFFLinkingContext); return buffer->commit(); @@ -984,8 +983,7 @@ void PECOFFWriter::setAddressOfEntryPoint(AtomChunk *text, // PECOFF spec says that entry point for dll images is optional, in which // case it must be set to 0. if (_PECOFFLinkingContext.entrySymbolName().empty() && - _PECOFFLinkingContext.getImageType() == - PECOFFLinkingContext::ImageType::dll) { + _PECOFFLinkingContext.isDll()) { peHeader->setAddressOfEntryPoint(0); } else { uint64_t entryPointAddress = diff --git a/lld/unittests/DriverTests/WinLinkDriverTest.cpp b/lld/unittests/DriverTests/WinLinkDriverTest.cpp index 31680b3..679c567 100644 --- a/lld/unittests/DriverTests/WinLinkDriverTest.cpp +++ b/lld/unittests/DriverTests/WinLinkDriverTest.cpp @@ -46,7 +46,7 @@ TEST_F(WinLinkParserTest, Basic) { EXPECT_TRUE(_context.getInputSearchPaths().empty()); // Unspecified flags will have default values. - EXPECT_EQ(PECOFFLinkingContext::ImageType::exe, _context.getImageType()); + EXPECT_FALSE(_context.isDll()); EXPECT_EQ(6, _context.getMinOSVersion().majorVersion); EXPECT_EQ(0, _context.getMinOSVersion().minorVersion); EXPECT_EQ(0x400000U, _context.getBaseAddress()); @@ -426,7 +426,7 @@ TEST_F(WinLinkParserTest, DisallowLib) { TEST_F(WinLinkParserTest, NoEntry) { EXPECT_TRUE(parse("link.exe", "/noentry", "/dll", "a.obj", nullptr)); - EXPECT_EQ(PECOFFLinkingContext::ImageType::dll, _context.getImageType()); + EXPECT_TRUE(_context.isDll()); EXPECT_EQ(0x10000000U, _context.getBaseAddress()); EXPECT_EQ("", _context.entrySymbolName()); } -- 2.7.4