Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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 *)
13{
14 return 1;
15}
16
17static inline int z_cbprintf_cxx_is_pchar(const char *)
18{
19 return 1;
20}
21
22static inline int z_cbprintf_cxx_is_pchar(volatile char *)
23{
24 return 1;
25}
26
27static inline int z_cbprintf_cxx_is_pchar(const volatile char *)
28{
29 return 1;
30}
31
32static inline int z_cbprintf_cxx_is_pchar(wchar_t *)
33{
34 return 1;
35}
36
37static inline int z_cbprintf_cxx_is_pchar(const wchar_t *)
38{
39 return 1;
40}
41
42static inline int z_cbprintf_cxx_is_pchar(volatile wchar_t *)
43{
44 return 1;
45}
46
47static inline int z_cbprintf_cxx_is_pchar(const volatile wchar_t *)
48{
49 return 1;
50}
51
52template < typename T >
53static inline int z_cbprintf_cxx_is_pchar(T arg)
54{
55 _Pragma("GCC diagnostic push")
56 _Pragma("GCC diagnostic ignored \"-Wpointer-arith\"")
57 return 0;
58 _Pragma("GCC diagnostic pop")
59}
60
61/* C++ version for calculating argument size. */
62static inline size_t z_cbprintf_cxx_arg_size(float f)
63{
64 ARG_UNUSED(f);
65
66 return sizeof(double);
67}
68
69static inline size_t z_cbprintf_cxx_arg_size(void *p)
70{
71 ARG_UNUSED(p);
72
73 return sizeof(void *);
74}
75
76template < typename T >
77static inline size_t z_cbprintf_cxx_arg_size(T arg)
78{
79 return sizeof(arg + 0);
80}
81
82/* C++ version for storing arguments. */
83static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, float arg)
84{
85 double d = (double)arg;
86 void *p = &d;
87
88 z_cbprintf_wcpy((int *)dst, (int *)p, sizeof(d) / sizeof(int));
89}
90
91static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, void *p)
92{
93 z_cbprintf_wcpy((int *)dst, (int *)&p, sizeof(p) / sizeof(int));
94}
95
96static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, char arg)
97{
98 int tmp = arg + 0;
99
100 z_cbprintf_wcpy((int *)dst, &tmp, 1);
101}
102
103static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, unsigned char arg)
104{
105 int tmp = arg + 0;
106
107 z_cbprintf_wcpy((int *)dst, &tmp, 1);
108}
109
110static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, signed char arg)
111{
112 int tmp = arg + 0;
113
114 z_cbprintf_wcpy((int *)dst, &tmp, 1);
115}
116
117static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, short arg)
118{
119 int tmp = arg + 0;
120
121 z_cbprintf_wcpy((int *)dst, &tmp, 1);
122}
123
124static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, unsigned short arg)
125{
126 int tmp = arg + 0;
127
128 z_cbprintf_wcpy((int *)dst, &tmp, 1);
129}
130
131template < typename T >
132static inline void z_cbprintf_cxx_store_arg(uint8_t *dst, T arg)
133{
134 size_t wlen = z_cbprintf_cxx_arg_size(arg) / sizeof(int);
135 void *p = &arg;
136
137 z_cbprintf_wcpy((int *)dst, (int *)p, wlen);
138}
139
140/* C++ version for long double detection. */
141static inline int z_cbprintf_cxx_is_longdouble(long double arg)
142{
143 ARG_UNUSED(arg);
144 return 1;
145}
146
147template < typename T >
148static inline int z_cbprintf_cxx_is_longdouble(T arg)
149{
150 ARG_UNUSED(arg);
151
152 return 0;
153}
154
155/* C++ version for caluculating argument alignment. */
156static inline size_t z_cbprintf_cxx_alignment(float arg)
157{
158 ARG_UNUSED(arg);
159
160 return VA_STACK_ALIGN(double);
161}
162
163static inline size_t z_cbprintf_cxx_alignment(double arg)
164{
165 ARG_UNUSED(arg);
166
167 return VA_STACK_ALIGN(double);
168}
169
170static inline size_t z_cbprintf_cxx_alignment(long double arg)
171{
172 ARG_UNUSED(arg);
173
174 return VA_STACK_ALIGN(long double);
175}
176
177static inline size_t z_cbprintf_cxx_alignment(long long arg)
178{
179 ARG_UNUSED(arg);
180
181 return VA_STACK_ALIGN(long long);
182}
183
184static inline size_t z_cbprintf_cxx_alignment(unsigned long long arg)
185{
186 ARG_UNUSED(arg);
187
188 return VA_STACK_ALIGN(long long);
189}
190
191template < typename T >
192static inline size_t z_cbprintf_cxx_alignment(T arg)
193{
194 return MAX(__alignof__(arg), VA_STACK_MIN_ALIGN);
195}
196
197#endif /* __cplusplus */
198#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:168
struct k_futex f
Definition: kobject.c:1319
struct k_pipe p
Definition: kobject.c:1311
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58