1 //===-- Starting point for printf -------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PRINTF_MAIN_H 10 #define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PRINTF_MAIN_H 11 12 #include "src/__support/arg_list.h" 13 #include "src/stdio/printf_core/converter.h" 14 #include "src/stdio/printf_core/core_structs.h" 15 #include "src/stdio/printf_core/parser.h" 16 #include "src/stdio/printf_core/writer.h" 17 18 #include <stddef.h> 19 20 namespace __llvm_libc { 21 namespace printf_core { 22 23 int printf_main(Writer *writer, const char *__restrict str, 24 internal::ArgList args) { 25 Parser parser(str, args); 26 Converter converter(writer); 27 28 for (FormatSection cur_section = parser.get_next_section(); 29 cur_section.raw_len > 0; cur_section = parser.get_next_section()) { 30 if (cur_section.has_conv) 31 converter.convert(cur_section); 32 else 33 writer->write(cur_section.raw_string, cur_section.raw_len); 34 } 35 36 return writer->get_chars_written(); 37 } 38 39 } // namespace printf_core 40 } // namespace __llvm_libc 41 42 #endif // LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PRINTF_MAIN_H 43