[lld] r199170 - [PECOFF] Support STACKSIZE module-definition file directive.

Rui Ueyama ruiu at google.com
Mon Jan 13 16:48:25 PST 2014


Author: ruiu
Date: Mon Jan 13 18:48:25 2014
New Revision: 199170

URL: http://llvm.org/viewvc/llvm-project?rev=199170&view=rev
Log:
[PECOFF] Support STACKSIZE module-definition file directive.

Modified:
    lld/trunk/include/lld/Driver/WinLinkModuleDef.h
    lld/trunk/lib/Driver/WinLinkModuleDef.cpp
    lld/trunk/unittests/DriverTests/WinLinkModuleDefTest.cpp

Modified: lld/trunk/include/lld/Driver/WinLinkModuleDef.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/WinLinkModuleDef.h?rev=199170&r1=199169&r2=199170&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/WinLinkModuleDef.h (original)
+++ lld/trunk/include/lld/Driver/WinLinkModuleDef.h Mon Jan 13 18:48:25 2014
@@ -35,6 +35,7 @@ enum class Kind {
   kw_heapsize,
   kw_name,
   kw_noname,
+  kw_stacksize,
   kw_version,
 };
 
@@ -63,7 +64,7 @@ private:
 
 class Directive {
 public:
-  enum class Kind { exports, heapsize, name, version };
+  enum class Kind { exports, heapsize, name, stacksize, version };
 
   Kind getKind() const { return _kind; }
   virtual ~Directive() {}
@@ -92,13 +93,14 @@ private:
   const std::vector<PECOFFLinkingContext::ExportDesc> _exports;
 };
 
-class Heapsize : public Directive {
+template <Directive::Kind kind>
+class MemorySize : public Directive {
 public:
-  explicit Heapsize(uint64_t reserve, uint64_t commit)
-      : Directive(Kind::heapsize), _reserve(reserve), _commit(commit) {}
+  explicit MemorySize(uint64_t reserve, uint64_t commit)
+      : Directive(kind), _reserve(reserve), _commit(commit) {}
 
   static bool classof(const Directive *dir) {
-    return dir->getKind() == Kind::heapsize;
+    return dir->getKind() == kind;
   }
 
   uint64_t getReserve() const { return _reserve; }
@@ -109,6 +111,9 @@ private:
   const uint64_t _commit;
 };
 
+typedef MemorySize<Directive::Kind::heapsize> Heapsize;
+typedef MemorySize<Directive::Kind::stacksize> Stacksize;
+
 class Name : public Directive {
 public:
   explicit Name(StringRef outputPath, uint64_t baseaddr)
@@ -159,7 +164,7 @@ private:
   void error(const Token &tok, Twine msg);
 
   bool parseExport(PECOFFLinkingContext::ExportDesc &result);
-  bool parseHeapsize(uint64_t &reserve, uint64_t &commit);
+  bool parseMemorySize(uint64_t &reserve, uint64_t &commit);
   bool parseName(std::string &outfile, uint64_t &baseaddr);
   bool parseVersion(int &major, int &minor);
 

Modified: lld/trunk/lib/Driver/WinLinkModuleDef.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkModuleDef.cpp?rev=199170&r1=199169&r2=199170&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkModuleDef.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkModuleDef.cpp Mon Jan 13 18:48:25 2014
@@ -54,6 +54,7 @@ Token Lexer::lex() {
                     .Case("HEAPSIZE", Kind::kw_heapsize)
                     .Case("NAME", Kind::kw_name)
                     .Case("NONAME", Kind::kw_noname)
+                    .Case("STACKSIZE", Kind::kw_stacksize)
                     .Case("VERSION", Kind::kw_version)
                     .Default(Kind::identifier);
     _buffer = (end == _buffer.npos) ? "" : _buffer.drop_front(end);
@@ -118,10 +119,17 @@ llvm::Optional<Directive *> Parser::pars
   // HEAPSIZE
   if (_tok._kind == Kind::kw_heapsize) {
     uint64_t reserve, commit;
-    if (!parseHeapsize(reserve, commit))
+    if (!parseMemorySize(reserve, commit))
       return llvm::None;
     return new (_alloc) Heapsize(reserve, commit);
   }
+  // STACKSIZE
+  if (_tok._kind == Kind::kw_stacksize) {
+    uint64_t reserve, commit;
+    if (!parseMemorySize(reserve, commit))
+      return llvm::None;
+    return new (_alloc) Stacksize(reserve, commit);
+  }
   // NAME
   if (_tok._kind == Kind::kw_name) {
     std::string outputPath;
@@ -170,8 +178,8 @@ bool Parser::parseExport(PECOFFLinkingCo
   }
 }
 
-// HEAPSIZE reserve [, commit]
-bool Parser::parseHeapsize(uint64_t &reserve, uint64_t &commit) {
+// HEAPSIZE/STACKSIZE reserve[,commit]
+bool Parser::parseMemorySize(uint64_t &reserve, uint64_t &commit) {
   if (!consumeTokenAsInt(reserve))
     return false;
 

Modified: lld/trunk/unittests/DriverTests/WinLinkModuleDefTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkModuleDefTest.cpp?rev=199170&r1=199169&r2=199170&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/WinLinkModuleDefTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/WinLinkModuleDefTest.cpp Mon Jan 13 18:48:25 2014
@@ -46,6 +46,7 @@ public:
 };
 
 class HeapsizeTest : public ParserTest<moduledef::Heapsize> {};
+class StacksizeTest : public ParserTest<moduledef::Stacksize> {};
 class NameTest : public ParserTest<moduledef::Name> {};
 class VersionTest : public ParserTest<moduledef::Version> {};
 
@@ -78,6 +79,18 @@ TEST_F(HeapsizeTest, WithCommit) {
   EXPECT_EQ(8192U, heapsize->getCommit());
 }
 
+TEST_F(StacksizeTest, Basic) {
+  moduledef::Stacksize *stacksize = parse("STACKSIZE 65536");
+  EXPECT_EQ(65536U, stacksize->getReserve());
+  EXPECT_EQ(0U, stacksize->getCommit());
+}
+
+TEST_F(StacksizeTest, WithCommit) {
+  moduledef::Stacksize *stacksize = parse("STACKSIZE 65536, 8192");
+  EXPECT_EQ(65536U, stacksize->getReserve());
+  EXPECT_EQ(8192U, stacksize->getCommit());
+}
+
 TEST_F(NameTest, Basic) {
   moduledef::Name *name = parse("NAME foo.exe");
   EXPECT_EQ("foo.exe", name->getOutputPath());





More information about the llvm-commits mailing list