1 //===-- Starting point for printf -------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "src/stdio/printf_core/printf_main.h"
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"
19 namespace __llvm_libc
{
20 namespace printf_core
{
22 int printf_main(Writer
*writer
, const char *__restrict str
,
23 internal::ArgList
&args
) {
24 Parser
<internal::ArgList
> parser(str
, args
);
26 for (FormatSection cur_section
= parser
.get_next_section();
27 !cur_section
.raw_string
.empty();
28 cur_section
= parser
.get_next_section()) {
29 if (cur_section
.has_conv
)
30 result
= convert(writer
, cur_section
);
32 result
= writer
->write(cur_section
.raw_string
);
38 return writer
->get_chars_written();
41 } // namespace printf_core
42 } // namespace __llvm_libc