1 //===-- Format specifier converter implmentation 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/converter.h" 10 11 #include "src/stdio/printf_core/core_structs.h" 12 #include "src/stdio/printf_core/writer.h" 13 14 // This option allows for replacing all of the conversion functions with custom 15 // replacements. This allows conversions to be replaced at compile time. 16 #ifndef LLVM_LIBC_PRINTF_CONV_ATLAS 17 #include "src/stdio/printf_core/converter_atlas.h" 18 #else 19 #include LLVM_LIBC_PRINTF_CONV_ATLAS 20 #endif 21 22 #include <stddef.h> 23 24 namespace __llvm_libc { 25 namespace printf_core { 26 27 void convert(Writer *writer, const FormatSection &to_conv) { 28 if (!to_conv.has_conv) { 29 writer->write(to_conv.raw_string, to_conv.raw_len); 30 return; 31 } 32 switch (to_conv.conv_name) { 33 case '%': 34 writer->write("%", 1); 35 return; 36 case 'c': 37 convert_char(writer, to_conv); 38 return; 39 case 's': 40 convert_string(writer, to_conv); 41 return; 42 case 'd': 43 case 'i': 44 case 'u': 45 // convert_int(writer, to_conv); 46 return; 47 case 'o': 48 // convert_oct(writer, to_conv); 49 return; 50 case 'x': 51 case 'X': 52 // convert_hex(writer, to_conv); 53 return; 54 // TODO(michaelrj): add a flag to disable float point values here 55 case 'f': 56 case 'F': 57 // convert_float_decimal(writer, to_conv); 58 return; 59 case 'e': 60 case 'E': 61 // convert_float_dec_exp(writer, to_conv); 62 return; 63 case 'a': 64 case 'A': 65 // convert_float_hex_exp(writer, to_conv); 66 return; 67 case 'g': 68 case 'G': 69 // convert_float_mixed(writer, to_conv); 70 return; 71 // TODO(michaelrj): add a flag to disable writing an int here 72 case 'n': 73 // convert_write_int(writer, to_conv); 74 return; 75 case 'p': 76 // convert_pointer(writer, to_conv); 77 return; 78 default: 79 writer->write(to_conv.raw_string, to_conv.raw_len); 80 return; 81 } 82 } 83 84 } // namespace printf_core 85 } // namespace __llvm_libc 86