public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/c++-modules] Rebase libcody -- $flag support.
@ 2020-11-11 17:55 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2020-11-11 17:55 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6bfad31b62fc7b95db0477c9edca7c9f4264f2e4

commit 6bfad31b62fc7b95db0477c9edca7c9f4264f2e4
Author: Nathan Sidwell <nathan@acm.org>
Date:   Tue Nov 10 11:54:25 2020 -0800

    Rebase libcody -- $flag support.
    
            libcody/
            Rebase on upstream -- $flag support.

Diff:
---
 ChangeLog.modules   |   3 ++
 libcody/README.md   |  81 ++++++++++++++++++++++------------
 libcody/client.cc   |  43 +++++++++++++-----
 libcody/cody.hh     | 125 +++++++++++++++++++++++++++++++++++++++++++---------
 libcody/resolver.cc |  37 +++++++++++++++-
 libcody/server.cc   |  73 ++++++++++++++++++++++++------
 6 files changed, 288 insertions(+), 74 deletions(-)

diff --git a/ChangeLog.modules b/ChangeLog.modules
index e603578cdd1..349133d0f78 100644
--- a/ChangeLog.modules
+++ b/ChangeLog.modules
@@ -1,5 +1,8 @@
 2020-11-10  Nathan Sidwell  <nathan@acm.org>
 
+	libcody/
+	Rebase on upstream -- $flag support.
+
 	Create c++tools dir
 	* Makefile.def: Add c++tools
 	* Makefile.tpl: Likewise.
diff --git a/libcody/README.md b/libcody/README.md
index 940d37c320c..05264ee7112 100644
--- a/libcody/README.md
+++ b/libcody/README.md
@@ -8,10 +8,10 @@ compilers and build systems.
 **WARNING:**  This is preliminary software.
 
 In addition to supporting C++modules, this may also support LTO
-requirements and could also feed deal with generated #include files
+requirements and could also deal with generated #include files
 and feed the compiler with prepruned include paths and whatnot.  (The
 system calls involved in include searches can be quite expensive on
-some build infrastuctures.)
+some build infrastructures.)
 
 * Client and Server objects
 * Direct connection for in-process use
@@ -47,11 +47,15 @@ The protocol is turn-based.  The compiler sends a block of one or more
 requests to the builder, then waits for a block of responses to all of
 those requests.  If the builder needs to compile something to satisfy
 a request, there may be some time before the response.  A builder may
-service multiple compilers concurrently, and it'll need some buffering
-scheme to deal with that.
+service multiple compilers concurrently, each as a separate connection.
 
 When multiple requests are in a block, the responses are also in a
-block, and in corresponding order.
+block, and in corresponding order.  The responses must not be
+commenced eagerly -- they must wait until the incoming block has ended
+(as mentioned above, it is turn-based).  To do otherwise risks
+deadlock, as there is no requirement for a sending end of the
+communication to listen for incoming responses (or new requests) until
+it has completed sending its current block.
 
 Every request has a response.
 
@@ -62,7 +66,7 @@ system, for that kind of thing.<sup><a href="#3">3</a></sup>
 
 Messages characters are encoded in UTF8.
 
-Messages are a sequenc of octets ending with a NEWLINE (0xa).  The lines
+Messages are a sequence of octets ending with a NEWLINE (0xa).  The lines
 consist of a sequence of words, separated by WHITESPACE (0x20 or 0x9).
 Words themselves do not contain WHITESPACE.  Lines consisting solely
 of WHITESPACE (or empty) are ignored.
@@ -106,10 +110,10 @@ It is recommended that words are separated by single SPACE characters.
 
 The message descriptions use `$metavariable` examples.
 
-The request messages are specific to a particlar action.  The response
+The request messages are specific to a particular action.  The response
 messages are more generic, describing their value types, but not their
 meaning.  Message consumers need to know the response to decode them.
-Notice the `Packet::GetRequest()` method records in response packates
+Notice the `Packet::GetRequest()` method records in response packets
 what the request being responded to was.  Do not confuse this with the
 `Packet::GetCode ()` method.
 
@@ -144,45 +148,70 @@ The first message is a handshake:
 
 The `$version` is a numeric value, currently `1`.  `$compiler` identifies
 the compiler &mdash; builders may need to keep compiled modules from
-different compilers separate.  `$ident` is an identifer the builder
-might use to identify the compilation it is communicting with.
+different compilers separate.  `$ident` is an identifier the builder
+might use to identify the compilation it is communicating with.
 
 Responses are:
 
-`HELLO $version $builder`
+`HELLO $version $builder [$flags]`
 
 A successful handshake.  The communication is now connected and other
-messages may be exchanged.  An ERROR response indicates an unsuccesful
+messages may be exchanged.  An ERROR response indicates an unsuccessful
 handshake.  The communication remains unconnected.
 
 There is nothing restricting a handshake to its own message block.  Of
 course, if the handshake fails, subsequent non-handshake messages in
 the block will fail (producing error responses).
 
+The `$flags` word, if present allows a server to control what requests
+might be given.  See below.
+
 ### C++ Module Requests
 
-A set of requests are specific to C++ modules
+A set of requests are specific to C++ modules:
+
+#### Flags
+
+Several requests and one response have an optional `$flags` word.
+These are the `Cody::Flags` value pertaining to that request.  If
+omitted the value 0 is implied.  The following flags are available:
+
+* `0`, `None`: No flags.
+
+* `1<<0`, `NameOnly`: The request is for the name only, and not the
+  CMI contents.
+
+The `NameOnly` flag may be provded in a handshake response, and
+indicates that the server is interested in requests only for their
+implied dependency information.  It may be provided on a request to
+indicate that only the CMI name is required, not its contents (for
+instance, when preprocessing).  Note that a compiler may still make
+`NameOnly` requests even if the server did not ask for such.
 
 #### Repository
 
 All relative CMI file names are relative to a repository.  (There are
-usually no abosolute CMI files).  The respository may be determined
+usually no absolute CMI files).  The repository may be determined
 with:
 
 `MODULE-REPO`
 
 A PATHNAME response is expected.  The `$pathname` may be an empty
-word, which is equivalent to `.`.
+word, which is equivalent to `.`.  When the response is a relative
+pathname, it must be relative to the client's current working
+directory (which might be a process on a different host to the
+server).  You may set the repository to `/`, if you with to use paths
+relative to the root directory.
 
 #### Exporting
 
 A compilation of a module interface, partition or header unit can
 inform the builder with:
 
-`MODULE-EXPORT $module`
+`MODULE-EXPORT $module [$flags]`
 
-This will result in a PATHNAME response naming the Compiled Module Interface
-pathname to write.
+This will result in a PATHNAME response naming the Compiled Module
+Interface pathname to write.
 
 The `MODULE-EXPORT` request does not indicate the module has been
 successfully compiled.  At most one `MODULE-EXPORT` is to be made, and
@@ -213,9 +242,7 @@ spelling a particular header-unit to a unique CMI file.
 
 Successful compilation of an interface is indicated with a subsequent:
 
-`MODULE-COMPILED $module`
-
-FIXME: do we need the module here?
+`MODULE-COMPILED $module [$flags]`
 
 request.  This indicates the CMI file has been written to disk, so
 that any other compilations waiting on it may proceed.  Depending on
@@ -229,9 +256,9 @@ themselves.
 
 #### Importing
 
-Importation, inculding that of header-units, uses:
+Importation, including that of header-units, uses:
 
-`MODULE-IMPORT $module`
+`MODULE-IMPORT $module [$flags]`
 
 A PATHNAME response names the CMI file to be read.  Should the builder
 have to invoke a compilation to produce the CMI, the response should
@@ -243,10 +270,10 @@ presumably fail in some manner.
 
 Include translation can be determined with:
 
-`INCLUDE-TRANSLATE $header`
+`INCLUDE-TRANSLATE $header [$flags]`
 
 The header name, `$header`, is the fully resolved header name, in the
-above-mentioned unambigous filename form.  The response will either be
+above-mentioned unambiguous filename form.  The response will either be
 a BOOL response indicating translation (TRUE) or textual inclusion
 (FALSE).  Alternatively a PATHNAME response can directly name the CMI,
 and implies translation, this possibly elides a subsequent
@@ -266,12 +293,12 @@ A successful invocation provides an OK response.  A failed
 invocation's produces an ERROR response.
 
 FIXME: Note for generalization this command needs to indicate which
-files may need transfering to and from a remote build system.
+files may need transferring to and from a remote build system.
 
 ## Building libCody
 
 Libcody is written in C++11.  (It's a intended for compilers, so
-there'd be a boostrapping problem if it used the latest and greatest.)
+there'd be a bootstrapping problem if it used the latest and greatest.)
 
 ### Using configure and make.
 
diff --git a/libcody/client.cc b/libcody/client.cc
index 56c13a4118c..b3c952756f4 100644
--- a/libcody/client.cc
+++ b/libcody/client.cc
@@ -209,17 +209,27 @@ Packet Client::Connect (char const *agent, char const *ident,
   return MaybeRequest (Detail::RC_CONNECT);
 }
 
-// HELLO VERSION AGENT
+// HELLO $version $agent [$flags]
 Packet ConnectResponse (std::vector<std::string> &words)
 {
-  if (words[0] == u8"HELLO" && words.size () == 3)
+  if (words[0] == u8"HELLO" && (words.size () == 3 || words.size () == 4))
     {
       char *eptr;
-      unsigned long version = strtoul (words[1].c_str (), &eptr, 10);
-      if (*eptr || version < Version)
+      unsigned long val = strtoul (words[1].c_str (), &eptr, 10);
+
+      unsigned version = unsigned (val);
+      if (*eptr || version != val || version < Version)
 	return Packet (Client::PC_ERROR, u8"incompatible version");
       else
-	return Packet (Client::PC_CONNECT, version);
+	{
+	  unsigned flags = 0;
+	  if (words.size () == 4)
+	    {
+	      val = strtoul (words[3].c_str (), &eptr, 10);
+	      flags = unsigned (val);
+	    }
+	  return Packet (Client::PC_CONNECT, flags);
+	}
     }
 
   return Packet (Client::PC_ERROR, u8"");
@@ -267,44 +277,53 @@ Packet OKResponse (std::vector<std::string> &words)
 		   words.size () == 2 ? std::move (words[1]) : "");
 }
 
-// MODULE-EXPORT $modulename
-Packet Client::ModuleExport (char const *module, size_t mlen)
+// MODULE-EXPORT $modulename [$flags]
+Packet Client::ModuleExport (char const *module, Flags flags, size_t mlen)
 {
   write.BeginLine ();
   write.AppendWord (u8"MODULE-EXPORT");
   write.AppendWord (module, true, mlen);
+  if (flags != Flags::None)
+    write.AppendInteger (unsigned (flags));
   write.EndLine ();
 
   return MaybeRequest (Detail::RC_MODULE_EXPORT);
 }
 
-// MODULE-IMPORT $modulename
-Packet Client::ModuleImport (char const *module, size_t mlen)
+// MODULE-IMPORT $modulename [$flags]
+Packet Client::ModuleImport (char const *module, Flags flags, size_t mlen)
 {
   write.BeginLine ();
   write.AppendWord (u8"MODULE-IMPORT");
   write.AppendWord (module, true, mlen);
+  if (flags != Flags::None)
+    write.AppendInteger (unsigned (flags));
   write.EndLine ();
 
   return MaybeRequest (Detail::RC_MODULE_IMPORT);
 }
 
-// MODULE-COMPILED $modulename
-Packet Client::ModuleCompiled (char const *module, size_t mlen)
+// MODULE-COMPILED $modulename [$flags]
+Packet Client::ModuleCompiled (char const *module, Flags flags, size_t mlen)
 {
   write.BeginLine ();
   write.AppendWord (u8"MODULE-COMPILED");
   write.AppendWord (module, true, mlen);
+  if (flags != Flags::None)
+    write.AppendInteger (unsigned (flags));
   write.EndLine ();
 
   return MaybeRequest (Detail::RC_MODULE_COMPILED);
 }
 
-Packet Client::IncludeTranslate (char const *include, size_t ilen)
+// INCLUDE-TRANSLATE $includename [$flags]
+Packet Client::IncludeTranslate (char const *include, Flags flags, size_t ilen)
 {
   write.BeginLine ();
   write.AppendWord (u8"INCLUDE-TRANSLATE");
   write.AppendWord (include, true, ilen);
+  if (flags != Flags::None)
+    write.AppendInteger (unsigned (flags));
   write.EndLine ();
 
   return MaybeRequest (Detail::RC_INCLUDE_TRANSLATE);
diff --git a/libcody/cody.hh b/libcody/cody.hh
index 330a8401bb9..1eb68da93c8 100644
--- a/libcody/cody.hh
+++ b/libcody/cody.hh
@@ -207,6 +207,22 @@ struct FD
 
 }
 
+// Flags for various requests
+enum class Flags : unsigned
+{
+  None,
+  NameOnly = 1<<0,  // Only querying for CMI names, not contents
+};
+
+inline Flags operator& (Flags a, Flags b)
+{
+  return Flags (unsigned (a) & unsigned (b));
+}
+inline Flags operator| (Flags a, Flags b)
+{
+  return Flags (unsigned (a) | unsigned (b));
+}
+
 ///
 /// Response data for a request.  Returned by Client's request calls,
 /// which return a single Packet.  When the connection is Corked, the
@@ -226,7 +242,7 @@ private:
     std::string string; ///< String value
     std::vector<std::string> vector;  ///< Vector of string value
   };
-  Category cat : 2;  ///< Discriminatory
+  Category cat : 2;  ///< Discriminator
 
 private:
   unsigned short code = 0;  ///< Packet type
@@ -435,7 +451,8 @@ public:
   /// @param ident compilation identifiation (maybe nullptr)
   /// @param alen length of agent string, if known
   /// @param ilen length of ident string, if known
-  /// @result packet indicating success (or deferrment) of the connection.
+  /// @result packet indicating success (or deferrment) of the
+  /// connection, payload is optional flags
   Packet Connect (char const *agent, char const *ident,
 		 size_t alen = ~size_t (0), size_t ilen = ~size_t (0));
   /// std::string wrapper for connection
@@ -463,37 +480,73 @@ public:
   /// @result packet indicating repo
   Packet ModuleRepo ();
 
+public:
   /// Inform of compilation of a named module interface or partition,
   /// or a header unit
   /// @param str module or header-unit
   /// @param len name length, if known
   /// @result CMI name (or deferrment/error)
-  Packet ModuleExport (char const *str, size_t len = ~size_t (0));
-  Packet ModuleExport (std::string const &s)
+  Packet ModuleExport (char const *str, Flags flags, size_t len = ~size_t (0));
+
+  Packet ModuleExport (char const *str)
+  {
+    return ModuleExport (str, Flags::None, ~size_t (0));
+  }
+  Packet ModuleExport
+    [[deprecated ("EOL:20201130, use Cody::Flag variant")]]
+    (char const *str, size_t len)
+  {
+    return ModuleExport (str, Flags::None, len);
+  }
+  Packet ModuleExport (std::string const &s, Flags flags = Flags::None)
   {
-    return ModuleExport (s.c_str (), s.size ());
+    return ModuleExport (s.c_str (), flags, s.size ());
   }
 
+public:
   /// Importation of a module, partition or header-unit
   /// @param str module or header-unit
   /// @param len name length, if known
   /// @result CMI name (or deferrment/error)
-  Packet ModuleImport (char const *str, size_t len = ~size_t (0));
-  Packet ModuleImport (std::string const &s)
+  Packet ModuleImport (char const *str, Flags flags, size_t len = ~size_t (0));
+
+  Packet ModuleImport (char const *str)
   {
-    return ModuleImport (s.c_str (), s.size ());
+    return ModuleImport (str, Flags::None, ~size_t (0));
+  }
+  Packet ModuleImport
+    [[deprecated ("EOL:20201130, use Cody::Flag variant")]]
+    (char const *str, size_t len)
+  {
+    return ModuleImport (str, Flags::None, len);
+  }
+  Packet ModuleImport (std::string const &s, Flags flags = Flags::None)
+  {
+    return ModuleImport (s.c_str (), flags, s.size ());
   }
 
+public:
   /// Successful compilation of a module interface, partition or
   /// header-unit.  Must have been preceeded by a ModuleExport
   /// request.
   /// @param str module or header-unit
   /// @param len name length, if known
   /// @result  OK (or deferment/error)
-  Packet ModuleCompiled (char const *str, size_t len = ~size_t (0));
-  Packet ModuleCompiled (std::string const &s)
+  Packet ModuleCompiled (char const *str, Flags flags, size_t len = ~size_t (0));
+
+  Packet ModuleCompiled (char const *str)
+  {
+    return ModuleCompiled (str, Flags::None, ~size_t (0));
+  }
+  Packet ModuleCompiled
+    [[deprecated ("EOL:20201130, use Cody::Flag variant")]]
+    (char const *str, size_t len)
+  {
+    return ModuleCompiled (str, Flags::None, len);
+  }
+  Packet ModuleCompiled (std::string const &s, Flags flags = Flags::None)
   {
-    return ModuleCompiled (s.c_str (), s.size ());
+    return ModuleCompiled (s.c_str (), flags, s.size ());
   }
 
   /// Include translation query.
@@ -501,10 +554,22 @@ public:
   /// @param len name length, if known
   /// @result  Packet indicating include translation boolean, or CMI
   /// name (or deferment/error)
-  Packet IncludeTranslate (char const *str, size_t len = ~size_t (0));
-  Packet IncludeTranslate (std::string const &s)
+  Packet IncludeTranslate (char const *str, Flags flags,
+			   size_t len = ~size_t (0));
+
+  Packet IncludeTranslate (char const *str)
+  {
+    return IncludeTranslate (str, Flags::None, ~size_t (0));
+  }
+  Packet IncludeTranslate
+    [[deprecated ("EOL:20201130, use Cody::Flag variant")]]
+    (char const *str, size_t len)
   {
-    return IncludeTranslate (s.c_str (), s.size ());
+    return IncludeTranslate (str, Flags::None, len);
+  }
+  Packet IncludeTranslate (std::string const &s, Flags flags = Flags::None)
+  {
+    return IncludeTranslate (s.c_str (), flags, s.size ());
   }
 
 public:
@@ -582,13 +647,31 @@ public:
 public:
   // return 0 on ok, ERRNO on failure, -1 on unspecific error
   virtual int ModuleRepoRequest (Server *s);
-  virtual int ModuleExportRequest (Server *s, std::string &module);
-  virtual int ModuleImportRequest (Server *s, std::string &module);
-  virtual int ModuleCompiledRequest (Server *s, std::string &module);
-  virtual int IncludeTranslateRequest (Server *s, std::string &include);
-
-public:
-  virtual int InvokeSubProcessRequest (Server *s, std::vector<std::string> &args);
+  virtual int ModuleExportRequest
+    [[deprecated ("EOL:20201130, use Cody::Flag variant")]]
+    (Server *s, std::string &module);
+  virtual int ModuleImportRequest
+    [[deprecated ("EOL:20201130, use Cody::Flag variant")]]
+    (Server *s, std::string &module);
+  virtual int ModuleCompiledRequest
+    [[deprecated ("EOL:20201130, use Cody::Flag variant")]]
+    (Server *s, std::string &module);
+  virtual int IncludeTranslateRequest
+    [[deprecated ("EOL:20201130, use Cody::Flag variant")]]
+    (Server *s, std::string &include);
+
+  virtual int ModuleExportRequest (Server *s, Flags flags,
+				   std::string &module);
+  virtual int ModuleImportRequest (Server *s, Flags flags,
+				   std::string &module);
+  virtual int ModuleCompiledRequest (Server *s, Flags flags,
+				     std::string &module);
+  virtual int IncludeTranslateRequest (Server *s, Flags flags,
+				       std::string &include);
+
+public:
+  virtual int InvokeSubProcessRequest (Server *s,
+				       std::vector<std::string> &args);
 };
 
 
diff --git a/libcody/resolver.cc b/libcody/resolver.cc
index 6100ece76a6..85520293ffd 100644
--- a/libcody/resolver.cc
+++ b/libcody/resolver.cc
@@ -142,6 +142,7 @@ int Resolver::ModuleRepoRequest (Server *s)
   return 0;
 }
 
+// Deprecated resolver functions
 int Resolver::ModuleExportRequest (Server *s, std::string &module)
 {
   auto cmi = GetCMIName (module);
@@ -175,7 +176,7 @@ int Resolver::IncludeTranslateRequest (Server *s, std::string &include)
   if (fd_dir >= 0
       && fstatat (fd_dir, cmi.c_str (), &statbuf, 0) == 0
       && S_ISREG (statbuf.st_mode))
-    // Sadly can't easily check if this proces has read access,
+    // Sadly can't easily check if this process has read access,
     // except by trying to open it.
     xlate = true;
   if (fd_dir >= 0)
@@ -197,6 +198,40 @@ int Resolver::IncludeTranslateRequest (Server *s, std::string &include)
   return 0;
 }
 
+// Default behaviour is to call the deprecated entry points and ignore
+// the Flags parameter, until the deprecation becomes removal
+int Resolver::ModuleExportRequest (Server *s, Flags, std::string &module)
+{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated"
+  return ModuleExportRequest (s, module);
+#pragma GCC diagnostic pop
+}
+
+int Resolver::ModuleImportRequest (Server *s, Flags, std::string &module)
+{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated"
+  return ModuleImportRequest (s, module);
+#pragma GCC diagnostic pop
+}
+
+int Resolver::ModuleCompiledRequest (Server *s, Flags, std::string &module)
+{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated"
+  return ModuleCompiledRequest (s, module);
+#pragma GCC diagnostic pop
+}
+
+int Resolver::IncludeTranslateRequest (Server *s, Flags, std::string &include)
+{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated"
+  return IncludeTranslateRequest (s, include);
+#pragma GCC diagnostic pop
+}
+
 int Resolver::InvokeSubProcessRequest (Server *s, std::vector<std::string> &)
 {
   s->ErrorResponse ("unimplemented");
diff --git a/libcody/server.cc b/libcody/server.cc
index 19a6e9f842f..c57e88879fb 100644
--- a/libcody/server.cc
+++ b/libcody/server.cc
@@ -159,6 +159,18 @@ void Server::ProcessRequests (void)
     }
 }
 
+// Return numeric value of STR as an unsigned.  Returns ~0u on error
+// (so that value is not representable).
+static unsigned ParseUnsigned (std::string &str)
+{
+  char *eptr;
+  unsigned long val = strtoul (str.c_str (), &eptr, 10);
+  if (*eptr || unsigned (val) != val)
+    return ~0u;
+
+  return unsigned (val);
+}
+
 Resolver *ConnectRequest (Server *s, Resolver *r,
 			  std::vector<std::string> &words)
 {
@@ -167,12 +179,11 @@ Resolver *ConnectRequest (Server *s, Resolver *r,
 
   if (words.size () == 3)
     words.emplace_back (u8"");
-  char *eptr;
-  unsigned long version = strtoul (words[1].c_str (), &eptr, 10);
-  if (*eptr)
+  unsigned version = ParseUnsigned (words[1]);
+  if (version == ~0u)
     return nullptr;
 
-  return r->ConnectRequest (s, unsigned (version), words[2], words[3]);
+  return r->ConnectRequest (s, version, words[2], words[3]);
 }
 
 int ModuleRepoRequest (Server *s, Resolver *r,std::vector<std::string> &words)
@@ -185,36 +196,72 @@ int ModuleRepoRequest (Server *s, Resolver *r,std::vector<std::string> &words)
 
 int ModuleExportRequest (Server *s, Resolver *r, std::vector<std::string> &words)
 {
-  if (words.size () != 2 || words[1].empty ())
-    return EINVAL;
+  if (words.size () < 2 || words.size () > 3 || words[1].empty ())
+    return -1;
+
+  Flags flags = Flags::None;
+  if (words.size () == 3)
+    {
+      unsigned val = ParseUnsigned (words[2]);
+      if (val == ~0u)
+	return -1;
+      flags = Flags (val);
+    }
 
-  return r->ModuleExportRequest (s, words[1]);
+  return r->ModuleExportRequest (s, flags, words[1]);
 }
 
 int ModuleImportRequest (Server *s, Resolver *r, std::vector<std::string> &words)
 {
-  if (words.size () != 2 || words[1].empty ())
+  if (words.size () < 2 || words.size () > 3 || words[1].empty ())
     return -1;
 
-  return r->ModuleExportRequest (s, words[1]);
+  Flags flags = Flags::None;
+  if (words.size () == 3)
+    {
+      unsigned val = ParseUnsigned (words[2]);
+      if (val == ~0u)
+	return -1;
+      flags = Flags (val);
+    }
+
+  return r->ModuleImportRequest (s, flags, words[1]);
 }
 
 int ModuleCompiledRequest (Server *s, Resolver *r,
 			   std::vector<std::string> &words)
 {
-  if (words.size () != 2 || words[1].empty ())
+  if (words.size () < 2 || words.size () > 3 || words[1].empty ())
     return -1;
 
-  return r->ModuleCompiledRequest (s, words[1]);
+  Flags flags = Flags::None;
+  if (words.size () == 3)
+    {
+      unsigned val = ParseUnsigned (words[2]);
+      if (val == ~0u)
+	return -1;
+      flags = Flags (val);
+    }
+
+  return r->ModuleCompiledRequest (s, flags, words[1]);
 }
 
 int IncludeTranslateRequest (Server *s, Resolver *r,
 			     std::vector<std::string> &words)
 {
-  if (words.size () != 2 || words[1].empty ())
+  if (words.size () < 2 || words.size () > 3 || words[1].empty ())
     return -1;
 
-  return r->IncludeTranslateRequest (s, words[1]);
+  Flags flags = Flags::None;
+  if (words.size () == 3)
+    {
+      unsigned val = ParseUnsigned (words[2]);
+      if (val == ~0u)
+	return -1;
+      flags = Flags (val);
+    }
+
+  return r->IncludeTranslateRequest (s, flags, words[1]);
 }
 
 int InvokeSubProcessRequest (Server *s, Resolver *r,


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-11 17:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-11 17:55 [gcc/devel/c++-modules] Rebase libcody -- $flag support Nathan Sidwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).