[libc-commits] [PATCH] D126830: [libc] move printf_main in to object library

Michael Jones via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Jun 1 15:02:36 PDT 2022


michaelrj created this revision.
michaelrj added reviewers: sivachandra, lntue.
Herald added subscribers: libc-commits, ecnelises, tschuett, mgorny.
Herald added projects: libc-project, All.
michaelrj requested review of this revision.

Previously printf_main was a header library, but header library
dependencies don't work properly so it's been moved to an object
library. Additionally, the writers have been marked inline.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126830

Files:
  libc/src/stdio/printf_core/CMakeLists.txt
  libc/src/stdio/printf_core/file_writer.h
  libc/src/stdio/printf_core/printf_main.cpp
  libc/src/stdio/printf_core/printf_main.h
  libc/src/stdio/printf_core/string_writer.h


Index: libc/src/stdio/printf_core/string_writer.h
===================================================================
--- libc/src/stdio/printf_core/string_writer.h
+++ libc/src/stdio/printf_core/string_writer.h
@@ -44,7 +44,7 @@
 
 // write_to_string treats raw_pointer as a StringWriter and calls its write
 // function.
-void write_to_string(void *raw_pointer, const char *__restrict to_write,
+inline void write_to_string(void *raw_pointer, const char *__restrict to_write,
                      size_t len) {
   StringWriter *string_writer = reinterpret_cast<StringWriter *>(raw_pointer);
   string_writer->write(to_write, len);
Index: libc/src/stdio/printf_core/printf_main.h
===================================================================
--- libc/src/stdio/printf_core/printf_main.h
+++ libc/src/stdio/printf_core/printf_main.h
@@ -10,9 +10,6 @@
 #define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PRINTF_MAIN_H
 
 #include "src/__support/arg_list.h"
-#include "src/stdio/printf_core/converter.h"
-#include "src/stdio/printf_core/core_structs.h"
-#include "src/stdio/printf_core/parser.h"
 #include "src/stdio/printf_core/writer.h"
 
 #include <stddef.h>
@@ -21,19 +18,7 @@
 namespace printf_core {
 
 int printf_main(Writer *writer, const char *__restrict str,
-                internal::ArgList &args) {
-  Parser parser(str, args);
-
-  for (FormatSection cur_section = parser.get_next_section();
-       cur_section.raw_len > 0; cur_section = parser.get_next_section()) {
-    if (cur_section.has_conv)
-      convert(writer, cur_section);
-    else
-      writer->write(cur_section.raw_string, cur_section.raw_len);
-  }
-
-  return writer->get_chars_written();
-}
+                internal::ArgList &args);
 
 } // namespace printf_core
 } // namespace __llvm_libc
Index: libc/src/stdio/printf_core/printf_main.cpp
===================================================================
--- libc/src/stdio/printf_core/printf_main.cpp
+++ libc/src/stdio/printf_core/printf_main.cpp
@@ -6,8 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PRINTF_MAIN_H
-#define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PRINTF_MAIN_H
+#include "src/stdio/printf_core/printf_main.h"
 
 #include "src/__support/arg_list.h"
 #include "src/stdio/printf_core/converter.h"
@@ -37,5 +36,3 @@
 
 } // namespace printf_core
 } // namespace __llvm_libc
-
-#endif // LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PRINTF_MAIN_H
Index: libc/src/stdio/printf_core/file_writer.h
===================================================================
--- libc/src/stdio/printf_core/file_writer.h
+++ libc/src/stdio/printf_core/file_writer.h
@@ -17,7 +17,7 @@
 
 // write_to_file treats raw_pointer as a File and calls its write
 // function.
-void write_to_file(void *raw_pointer, const char *__restrict to_write,
+inline void write_to_file(void *raw_pointer, const char *__restrict to_write,
                    size_t len) {
   __llvm_libc::File *file = reinterpret_cast<__llvm_libc::File *>(raw_pointer);
   file->write(to_write, len);
Index: libc/src/stdio/printf_core/CMakeLists.txt
===================================================================
--- libc/src/stdio/printf_core/CMakeLists.txt
+++ libc/src/stdio/printf_core/CMakeLists.txt
@@ -61,8 +61,10 @@
 )
 
 
-add_header_library(
+add_object_library(
   printf_main
+  SRCS
+    printf_main.cpp
   HDRS
     printf_main.h
   DEPENDS


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126830.433563.patch
Type: text/x-patch
Size: 3429 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20220601/e50cbff6/attachment-0001.bin>


More information about the libc-commits mailing list