MtFmt 1.0.0
MtFmt is a format library on embed. system and wrote by pure C.
载入中...
搜索中...
未找到
mm_cfg.h
浏览该文件的文档.
1// SPDX-License-Identifier: LGPL-3.0
12#if !defined(_INCLUDE_MM_CFG_H_)
13#define _INCLUDE_MM_CFG_H_
14#include <stdint.h>
15
20#define MSTR_BUILD_CC_MSVC 0x1
21
26#define MSTR_BUILD_CC_GNUC 0x2
27
32#define MSTR_BUILD_CC_ARMCC 0x3
33
38#define MSTR_BUILD_CC_ARMCLANG 0x4
39
44#define MSTR_BUILD_CC_EMSCRIPTEN 0x5
45
50#define MSTR_BUILD_CC_OTHER 0xf
51
52#if defined(_MSC_VER)
53#define MSTR_BUILD_CC MSTR_BUILD_CC_MSVC
54#elif defined(__ARMCC_VERSION)
55// 优先考虑armcc而不是gnuc
56#if __ARMCC_VERSION >= 6000000
57#define MSTR_BUILD_CC MSTR_BUILD_CC_ARMCLANG
58#else
59#define MSTR_BUILD_CC MSTR_BUILD_CC_ARMCC
60#endif // __ARMCC_VERSION
61#elif defined(__GNUC__)
62#define MSTR_BUILD_CC MSTR_BUILD_CC_GNUC
63#elif defined(__EMSCRIPTEN__)
64#define MSTR_BUILD_CC MSTR_BUILD_CC_EMSCRIPTEN
65#else
66#define MSTR_BUILD_CC MSTR_BUILD_CC_OTHER
67#endif // 编译器版本
68
69#if defined(MSTR_IMP_SOURCES) && MSTR_BUILD_CC == MSTR_BUILD_CC_MSVC
70// "该文件包含不能在当前代码页(XXXX)中表示的字符"
71// unbengable ( ̄_ ̄|||)
72#pragma warning(disable : 4819)
73#endif // _MSC_VER
74
75#if defined(MSTR_IMP_SOURCES) && MSTR_BUILD_CC == MSTR_BUILD_CC_ARMCLANG
76// 我们不需要任何的对齐警告, 分支覆盖警告
77// 因为parser在很多case不会处理所有情况(取而代之由default: 处理 break;)
78// 所有的结构体不需要关注padding填充, 因为没有任何一个地方使用
79// reinterpret_cast 指针转换均不需要关注对齐问题,
80// 因为堆内存分配按照机器字长对齐
81#pragma clang diagnostic ignored "-Wpadded"
82#pragma clang diagnostic ignored "-Wcast-align"
83#pragma clang diagnostic ignored "-Wswitch-enum"
84#elif defined(MSTR_IMP_SOURCES) && MSTR_BUILD_CC == MSTR_BUILD_CC_ARMCC
85// TODO
86#endif // _MSC_VER
87
88#if !defined(_MSTR_BUILD_DLL)
93#define _MSTR_BUILD_DLL 0
94#endif // _MSTR_BUILD_DLL
95
96#if !defined(_MSTR_USE_ALLOC)
101#define _MSTR_USE_ALLOC 1
102#endif // _MSTR_USE_ALLOC
103
104#if !defined(_MSTR_USE_UTF_8)
109#define _MSTR_USE_UTF_8 1
110#endif // _MSTR_USE_UTF_8
111
112#if !defined(_MSTR_USE_STD_IO)
117#define _MSTR_USE_STD_IO 0
118#endif // _MSTR_USE_STD_IO
119
120#if _MSTR_USE_STD_IO
121#include <stdio.h>
122#endif // _MSTR_USE_STD_IO
123
124#if !defined(_MSTR_USE_MALLOC)
129#define _MSTR_USE_MALLOC 0
130#endif // _MSTR_USE_MALLOC
131
132#if !defined(_MSTR_RUNTIME_HEAP_ALIGN)
137#define _MSTR_RUNTIME_HEAP_ALIGN 4
138#endif // _MSTR_RUNTIME_HEAP_ALIGN
139
140#if _MSTR_USE_MALLOC
141#include <stdlib.h>
142#include <string.h>
143
144#if !defined(_MSTR_MEM_ALLOC_FUNCTION)
149#define _MSTR_MEM_ALLOC_FUNCTION(s) malloc(s)
150#endif // _MSTR_MALLOC_FUNCTION
151
152#if !defined(_MSTR_MEM_FREE_FUNCTION)
157#define _MSTR_MEM_FREE_FUNCTION(s) free(s)
158#endif // _MSTR_MEM_FREE_FUNCTION
159
160#if !defined(_MSTR_MEM_REALLOC_FUNCTION)
161#if !defined(_MSTR_MEM_ALLOC_FUNCTION) && \
162 !defined(_MSTR_MEM_FREE_FUNCTION)
167#define _MSTR_MEM_REALLOC_FUNCTION(old_p, s) realloc((old_p), (s))
172#define MSTR_MEM_REALLOC_FUNCTION_NOT_AVAL 0
173#else
178#define MSTR_MEM_REALLOC_FUNCTION_NOT_AVAL 1
179#endif // _MSTR_MEM_XXX
180#endif // _MSTR_MEM_REALLOC_FUNCTION
181#else
186#define MSTR_MEM_REALLOC_FUNCTION_NOT_AVAL 0
187#endif // _MSTR_USE_MALLOCs
188
189#if !defined(_MSTR_RUNTIME_HEAP_TRACING)
202#define _MSTR_RUNTIME_HEAP_TRACING(type, ptr, size, old_size) ((void)0U)
203#endif // _MSTR_RUNTIME_HEAP_TRACING
204
205#if !defined(_MSTR_USE_CPP_EXCEPTION)
206#if MSTR_BUILD_CC == MSTR_BUILD_CC_ARMCLANG || \
207 MSTR_BUILD_CC == MSTR_BUILD_CC_ARMCC
208#if defined(__EXCEPTIONS)
213#define _MSTR_USE_CPP_EXCEPTION 1
214#else
219#define _MSTR_USE_CPP_EXCEPTION 0
220#endif // __EXCEPTIONS
221#else
226#define _MSTR_USE_CPP_EXCEPTION 1
227#endif // MSTR_BUILD_CC
228#endif // _MSTR_USE_CPP_EXCEPTION
229
230#if !defined(_MSTR_RUNTIME_CTRLFLOW_MARKER)
235#define _MSTR_RUNTIME_CTRLFLOW_MARKER 1
236#endif // _MSTR_RUNTIME_CTRLFLOW_MARKER
237
238#if !defined(_MSTR_USE_HARDWARE_DIV)
239#if MSTR_BUILD_CC == MSTR_BUILD_CC_ARMCLANG || \
240 MSTR_BUILD_CC == MSTR_BUILD_CC_ARMCC
241#if defined(__TARGET_FEATURE_DIVIDE)
246#define _MSTR_USE_HARDWARE_DIV 1
247#else
252#define _MSTR_USE_HARDWARE_DIV 1
253#endif // __TARGET_FEATURE_DIVIDE
254#elif MSTR_BUILD_CC == MSTR_BUILD_CC_GNUC && \
255 (defined(__x86_64__) || defined(__i386__))
260#define _MSTR_USE_HARDWARE_DIV 1
261#elif MSTR_BUILD_CC == MSTR_BUILD_CC_MSVC
266#define _MSTR_USE_HARDWARE_DIV 1
267#else
272#define _MSTR_USE_HARDWARE_DIV 0
273#endif // 硬件除法, 默认关掉
274#endif // _MSTR_USE_HARDWARE_DIV
275
276#if !defined(_MSTR_USE_FP_FLOAT32)
277#if MSTR_BUILD_CC == MSTR_BUILD_CC_ARMCLANG || \
278 MSTR_BUILD_CC == MSTR_BUILD_CC_ARMCC
279#if defined(__TARGET_FPU_VFP)
284#define _MSTR_USE_FP_FLOAT32 1
285#else
290#define _MSTR_USE_FP_FLOAT32 0
291#endif // ARMCC: __TARGET_FPU
292#elif MSTR_BUILD_CC == MSTR_BUILD_CC_GNUC && \
293 (defined(__x86_64__) || defined(__i386__))
298#define _MSTR_USE_FP_FLOAT32 1
299#elif MSTR_BUILD_CC == MSTR_BUILD_CC_MSVC
304#define _MSTR_USE_FP_FLOAT32 1
305#else
310#define _MSTR_USE_FP_FLOAT32 0
311#endif // MSTR_BUILD_CC
312#endif // _MSTR_USE_FP_FLOAT32
313
314#if !defined(_MSTR_USE_FP_FLOAT64)
315#if MSTR_BUILD_CC == MSTR_BUILD_CC_ARMCLANG || \
316 MSTR_BUILD_CC == MSTR_BUILD_CC_ARMCC
317#if defined(__TARGET_FPU_SOFTVFP_VFPV3_D16) || \
318 defined(__TARGET_FPU_SOFTVFP_VFPV3_D16_FP16) || \
319 defined(__TARGET_FPU_SOFTVFP_VFPV4_D16) || \
320 defined(__TARGET_FPU_VFPV3_D16) || \
321 defined(__TARGET_FPU_VFPV3_D16_FP16) || \
322 defined(__TARGET_FPU_VFPV4_D16)
327#define _MSTR_USE_FP_FLOAT64 1
328#else
333#define _MSTR_USE_FP_FLOAT64 0
334#endif // ARMCC: __TARGET_FPU
335#elif MSTR_BUILD_CC == MSTR_BUILD_CC_GNUC && \
336 (defined(__x86_64__) || defined(__i386__))
341#define _MSTR_USE_FP_FLOAT64 1
342#elif MSTR_BUILD_CC == MSTR_BUILD_CC_MSVC
347#define _MSTR_USE_FP_FLOAT64 1
348#else
353#define _MSTR_USE_FP_FLOAT64 0
354#endif // MSTR_BUILD_CC
355#endif // _MSTR_USE_FP_FLOAT64
356
361#define _MSTR_USE_FP (_MSTR_USE_FP_FLOAT32 || _MSTR_USE_FP_FLOAT64)
362
363#if _MSTR_RUNTIME_CTRLFLOW_MARKER
364#if defined(USE_FULL_ASSERT)
365#include "stm32_assert.h"
370#define mstr_unreachable() assert_param(0)
375#define mstr_bounding_check(expr) assert_param(!!(expr))
380#define mstr_cause_exception(code) assert_param(0)
385#define mstr_assert(e) assert_param(e)
386#elif defined(_MSTR_RUNTIME_ASSERT)
387#include <assert.h>
388#define mstr_unreachable() assert(0)
389#define mstr_bounding_check(expr) assert(!!(expr))
390#define mstr_cause_exception(code) assert(0)
391#define mstr_assert(e) assert(e)
392#else
393#define mstr_unreachable() ((void)0U)
394#define mstr_bounding_check(expr) ((void)0U)
395#define mstr_cause_exception(code) ((void)0U)
396#define mstr_assert(e) ((void)0U)
397#endif
398#else
399#define mstr_unreachable() ((void)0U)
400#define mstr_bounding_check(expr) ((void)0U)
401#define mstr_cause_exception(code) ((void)0U)
402#define mstr_assert(e) ((void)0U)
403#endif // _MSTR_RUNTIME_CTRLFLOW_MARKER
404
405//
406// 导出函数修辞
407//
408#if defined(__cplusplus)
409#define MSTR_EXPORT_MANGLE extern "C"
410#else
411#define MSTR_EXPORT_MANGLE extern
412#endif // __cplusplus
413//
414// 定义导出定义
415//
416#if defined(_MSTR_BUILD_DLL)
417#if MSTR_BUILD_CC == MSTR_BUILD_CC_MSVC
418#define MSTR_EXPORT_API(ret) \
419 MSTR_EXPORT_MANGLE __declspec(dllexport) ret __stdcall
420#else
421#define MSTR_EXPORT_API(ret) \
422 MSTR_EXPORT_MANGLE __attribute__((visibility("default"))) ret
423#endif // _MSC_VER
424#elif defined(_MSTR_IMPORT_FROM_DLL)
425#define MSTR_EXPORT_API(ret) \
426 MSTR_EXPORT_MANGLE __declspec(dllimport) ret __stdcall
427#elif MSTR_BUILD_CC == MSTR_BUILD_CC_EMSCRIPTEN
428#include <emscripten.h>
429#define MSTR_EXPORT_API(ret) MSTR_EXPORT_MANGLE ret EMSCRIPTEN_KEEPALIVE
430#else
431#define MSTR_EXPORT_API(ret) MSTR_EXPORT_MANGLE ret
432#endif // EXPORT
433
438#define MSTRCFG_USE_MALLOC_BIT 0x01
439
444#define MSTRCFG_BUILD_DLL_BIT 0x02
445
450#define MSTRCFG_BUILD_HARDWARE_DIV 0x04
451
456#define MSTRCFG_USE_STD_IO 0x08
457
462#define MSTRCFG_USE_UTF_8 0x10
463
468#define MSTRCFG_USE_CXX_EXCEPTION 0x20
469
474#define MSTRCFG_USE_FLOAT32 0x40
475
480#define MSTRCFG_USE_FLOAT64 0x80
481
486#define MSTRCFG_USE_ALLOCATOR 0x100
487
492#define MSTR_CONFIGURE_VER_VAL(c) (((c) >> 16) & 0xffff)
493
498#define MSTR_CONFIGURE_CC_VAL(c) (((c) >> 12) & 0xf)
499
504#define MSTR_CONFIGURE_CFG_VAL(c) ((c)&0xfff)
505
506//@ <autogen:version>
507
508//@ </autogen:version>
509
515MSTR_EXPORT_API(uint32_t) mstr_configure(void);
516#endif // _INCLUDE_MM_CFG_H_
#define MSTR_EXPORT_API(ret)
Definition mm_cfg.h:421