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 #include "src/stdio/printf_core/printf_main.h"
10 
11 #include "src/__support/arg_list.h"
12 #include "src/stdio/printf_core/converter.h"
13 #include "src/stdio/printf_core/core_structs.h"
14 #include "src/stdio/printf_core/parser.h"
15 #include "src/stdio/printf_core/writer.h"
16 
17 #include <stddef.h>
18 
19 namespace __llvm_libc {
20 namespace printf_core {
21 
22 int printf_main(Writer *writer, const char *__restrict str,
23                 internal::ArgList &args) {
24   Parser parser(str, args);
25 
26   for (FormatSection cur_section = parser.get_next_section();
27        cur_section.raw_len > 0; cur_section = parser.get_next_section()) {
28     if (cur_section.has_conv)
29       convert(writer, cur_section);
30     else
31       writer->write(cur_section.raw_string, cur_section.raw_len);
32   }
33 
34   return writer->get_chars_written();
35 }
36 
37 } // namespace printf_core
38 } // namespace __llvm_libc
39