Zephyr API Documentation  3.0.0
A Scalable Open Source RTOS
3.0.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
cbprintf_cxx.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_SYS_CBPRINTF_CXX_H_
8#define ZEPHYR_INCLUDE_SYS_CBPRINTF_CXX_H_
9#ifdef __cplusplus
10
11/* C++ version for detecting a pointer to a string. */
12static inline int z_cbprintf_cxx_is_pchar(char *, bool const_as_fixed)
13{
14 ARG_UNUSED(const_as_fixed);
15 return 1;
16}
17
18static inline int z_cbprintf_cxx_is_pchar(const char *, bool const_as_fixed)
19{
20 return const_as_fixed ? 0 : 1;
21}
22
23static inline int z_cbprintf_cxx_is_pchar(volatile char *, bool const_as_fixed)
24{
25 ARG_UNUSED(const_as_fixed);
26 return 1;
27}
28
29static inline int z_cbprintf_cxx_is_pchar(const volatile char *, bool const_as_fixed)
30{
31 ARG_UNUSED(const_as_fixed);
32 return 1;
33}
34
35static inline int z_cbprintf_cxx_is_pchar(wchar_t *, bool const_as_fixed)
36{
37 ARG_UNUSED(const_as_fixed);
38 return 1;
39}
40
41static inline int z_cbprintf_cxx_is_pchar(const wchar_t *, bool const_as_fixed)
42{
43 return const_as_fixed ? 0 : 1;
44}
45
46static inline int z_cbprintf_cxx_is_pchar(volatile wchar_t *, bool const_as_fixed)
47{
48 ARG_UNUSED(const_as_fixed);
49 return 1;
50}
51
52static inline int z_cbprintf_cxx_is_pchar(const volatile wchar_t *, bool const_as_fixed)
53{
54 ARG_UNUSED(const_as_fixed);
55 return 1;
56}
57
58template < typename T >
59static inline int z_cbprintf_cxx_is_pchar(T arg, bool const_as_fixed)
60{
61 ARG_UNUSED(arg);
62 _Pragma("GCC diagnostic push")
63 _Pragma("GCC diagnostic ignored \"-Wpointer-arith\"")
64 ARG_UNUSED(const_as_fixed);
65 return 0;
66 _Pragma("GCC diagnostic pop")
67}
68
69/* C++ version for calculating argument size. */
70static inline size_t z_cbprintf_cxx_arg_size(float f)
71{
72 ARG_UNUSED(f);
73
74 return sizeof(double);
75}
76
77static inline size_t z_cbprintf_cxx_arg_size(void *p)
78{
79 ARG_UNUSED(p);
80
81 return sizeof(void *);
82}
83
84template < typename T >
85static inline size_t z_cbprintf_cxx_arg_size(T arg)
86{
87 return sizeof(arg + 0);
88}
89
90/* C++ version for storing arguments. */
91static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, float arg)
92{
93 double d = (double)arg;
94 void *p = &d;
95
96 z_cbprintf_wcpy((int *)dst, (int *)p, sizeof(d) / sizeof(int));
97}
98
99static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, void *p)
100{
101 z_cbprintf_wcpy((int *)dst, (int *)&p, sizeof(p) / sizeof(int));
102}
103
104static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, char arg)
105{
106 int tmp = arg + 0;
107
108 z_cbprintf_wcpy((int *)dst, &tmp, 1);
109}
110
111static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, unsigned char arg)
112{
113 int tmp = arg + 0;
114
115 z_cbprintf_wcpy((int *)dst, &tmp, 1);
116}
117
118static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, signed char arg)
119{
120 int tmp = arg + 0;
121
122 z_cbprintf_wcpy((int *)dst, &tmp, 1);
123}
124
125static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, short arg)
126{
127 int tmp = arg + 0;
128
129 z_cbprintf_wcpy((int *)dst, &tmp, 1);
130}
131
132static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, unsigned short arg)
133{
134 int tmp = arg + 0;
135
136 z_cbprintf_wcpy((int *)dst, &tmp, 1);
137}
138
139template < typename T >
140static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, T arg)
141{
142 size_t wlen = z_cbprintf_cxx_arg_size(arg) / sizeof(int);
143 void *p = &arg;
144
145 z_cbprintf_wcpy((int *)dst, (int *)p, wlen);
146}
147
148/* C++ version for long double detection. */
149static inline int z_cbprintf_cxx_is_longdouble(long double arg)
150{
151 ARG_UNUSED(arg);
152 return 1;
153}
154
155template < typename T >
156static inline int z_cbprintf_cxx_is_longdouble(T arg)
157{
158 ARG_UNUSED(arg);
159
160 return 0;
161}
162
163/* C++ version for caluculating argument alignment. */
164static inline size_t z_cbprintf_cxx_alignment(float arg)
165{
166 ARG_UNUSED(arg);
167
168 return VA_STACK_ALIGN(double);
169}
170
171static inline size_t z_cbprintf_cxx_alignment(double arg)
172{
173 ARG_UNUSED(arg);
174
175 return VA_STACK_ALIGN(double);
176}
177
178static inline size_t z_cbprintf_cxx_alignment(long double arg)
179{
180 ARG_UNUSED(arg);
181
182 return VA_STACK_ALIGN(long double);
183}
184
185static inline size_t z_cbprintf_cxx_alignment(long long arg)
186{
187 ARG_UNUSED(arg);
188
189 return VA_STACK_ALIGN(long long);
190}
191
192static inline size_t z_cbprintf_cxx_alignment(unsigned long long arg)
193{
194 ARG_UNUSED(arg);
195
196 return VA_STACK_ALIGN(long long);
197}
198
199template < typename T >
200static inline size_t z_cbprintf_cxx_alignment(T arg)
201{
202 return MAX(__alignof__(arg), VA_STACK_MIN_ALIGN);
203}
204
205#endif /* __cplusplus */
206#endif /* ZEPHYR_INCLUDE_SYS_CBPRINTF_CXX_H_ */
irp nz macro MOVR cc d
Definition: asm-macro-32-bit-gnu.h:11
#define VA_STACK_MIN_ALIGN
Definition: cbprintf_internal.h:44
#define VA_STACK_ALIGN(type)
Definition: cbprintf_internal.h:48
#define MAX(a, b)
The larger value between a and b.
Definition: util.h:184
struct k_futex f
Definition: kobject.c:1324
struct k_pipe p
Definition: kobject.c:1316
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58