[lld] r198634 - [PECOFF] Simplify: Replace two-value enum with bool.

Rui Ueyama ruiu at google.com
Mon Jan 6 11:55:59 PST 2014


Author: ruiu
Date: Mon Jan  6 13:55:58 2014
New Revision: 198634

URL: http://llvm.org/viewvc/llvm-project?rev=198634&view=rev
Log:
[PECOFF] Simplify: Replace two-value enum with bool.

Modified:
    lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
    lld/trunk/lib/Driver/WinLinkDriver.cpp
    lld/trunk/lib/ReaderWriter/PECOFF/SetSubsystemPass.h
    lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
    lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp

Modified: lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h?rev=198634&r1=198633&r2=198634&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/PECOFFLinkingContext.h Mon Jan  6 13:55:58 2014
@@ -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<std::string> _noDefaultLibs;

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=198634&r1=198633&r2=198634&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Mon Jan  6 13:55:58 2014
@@ -571,7 +571,7 @@ void processLibEnv(PECOFFLinkingContext
 // 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 at 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 cha
 
     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);

Modified: lld/trunk/lib/ReaderWriter/PECOFF/SetSubsystemPass.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/SetSubsystemPass.h?rev=198634&r1=198633&r2=198634&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/SetSubsystemPass.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/SetSubsystemPass.h Mon Jan  6 13:55:58 2014
@@ -41,7 +41,7 @@ public:
         return;
       }
     }
-    if (_ctx.getImageType() == PECOFFLinkingContext::ImageType::dll) {
+    if (_ctx.isDll()) {
       _ctx.setSubsystem(WindowsSubsystem::IMAGE_SUBSYSTEM_WINDOWS_GUI);
       return;
     }

Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=198634&r1=198633&r2=198634&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Mon Jan  6 13:55:58 2014
@@ -911,8 +911,7 @@ error_code PECOFFWriter::writeFile(const
   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::setAddressOfEntryPoin
   // 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 =

Modified: lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp?rev=198634&r1=198633&r2=198634&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Mon Jan  6 13:55:58 2014
@@ -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());
 }





More information about the llvm-commits mailing list