[libc-commits] [libc] [libc][NFC] Cleanup the GPU file I/O utility header (PR #65680)

Siva Chandra via libc-commits libc-commits at lists.llvm.org
Fri Sep 8 12:12:29 PDT 2023


================
@@ -14,35 +14,16 @@
 namespace __llvm_libc {
 namespace file {
 
-LIBC_INLINE uint64_t write_to_stdout(const void *data, size_t size) {
+template <uint16_t opcode>
+LIBC_INLINE uint64_t write_impl(::FILE *file, const void *data, size_t size) {
   uint64_t ret = 0;
-  rpc::Client::Port port = rpc::client.open<RPC_WRITE_TO_STDOUT>();
-  port.send_n(data, size);
-  port.recv([&](rpc::Buffer *buffer) {
-    ret = reinterpret_cast<uint64_t *>(buffer->data)[0];
-  });
-  port.close();
-  return ret;
-}
+  rpc::Client::Port port = rpc::client.open<opcode>();
 
-LIBC_INLINE uint64_t write_to_stderr(const void *data, size_t size) {
-  uint64_t ret = 0;
-  rpc::Client::Port port = rpc::client.open<RPC_WRITE_TO_STDERR>();
-  port.send_n(data, size);
-  port.recv([&](rpc::Buffer *buffer) {
-    ret = reinterpret_cast<uint64_t *>(buffer->data)[0];
-  });
-  port.close();
-  return ret;
-}
+  if constexpr (opcode == RPC_WRITE_TO_STREAM)
----------------
sivachandra wrote:

It a multi-line statement under the `if` so you should use braces. I was struggling to figure out alignment of the indents.

https://github.com/llvm/llvm-project/pull/65680


More information about the libc-commits mailing list