Edge AI Add-on API 2.2.0
Loading...
Searching...
No Matches
nrf_axon_stringization.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#pragma once
8
9/*
10 * macro jiu jitsu...
11 *
12 * Our goal is to generate the include file names from 3 tokens:
13 * - file name root (ie,axon_mfcc_properties_)
14 * - target name (ie, default)
15 * - .h extension
16 * The caller will provide the correct target name via the build system, and the proper
17 * header files will be included.
18 * Thanks stack-overflow (https://stackoverflow.com/questions/5256313/c-c-macro-string-concatenation)for below.
19*/
20
21#define PPCAT2_NX(A, B) A ## B// concatenate w/o macro expanding
22#define PPCAT2(A, B) PPCAT2_NX(A, B) // concatenate w/ macro expanding (macros are expanded by PPCAT before being passed to PPCAT_NX)
23#define PPCAT3_NX(A, B, C) A ## B ## C // concatenate w/o macro expanding
24#define PPCAT3(A, B, C) PPCAT3_NX(A, B, C) // concatenate w/ macro expanding (macros are expanded by PPCAT before being passed to PPCAT_NX)
25#define STRINGIZE_NX(A) #A // convert to string litteral w/o macro expanding
26#define STRINGIZE(A) STRINGIZE_NX(A) // convert to string litteral w/ macro expanding (macros are expanded by STRINGIZE before being passed to STRINGIZE_NX)
27#define STRINGIZE_3_CONCAT(A,B,C) STRINGIZE(PPCAT3_NX(A,B,C)) // since the outer macro will expand A, B, C, call PPCAT_NX instead.
28#define STRINGIZE_2_CONCAT(A,B) STRINGIZE(PPCAT2_NX(A,B))
29
30/*
31 * concats a litteral with an expanded macro.
32 * "litteral" will not be expanded, "macro" will be.
33 * #define my_litteral FOO
34 * #define my_macro BAR
35 * STRINGIZE_CONCAT_LITTERAL_MACRO(my_litteral, my_macro)
36 * => my_litteralBAR
37*/
38#define MACRO_EXPAND(A) A
39#define CONCAT_LITTERAL_MACRO(litteral, macro) PPCAT2_NX(litteral,MACRO_EXPAND(macro))
40#define STRINGIZE_CONCAT_LITTERAL_MACRO(litteral, macro) STRINGIZE(litteral##MACRO_EXPAND(macro))
41#define STRINGIZE_CONCAT_LITTERAL_MACRO_LITTERAL(litteral1, macro,litteral2) #litteral1##STRINGIZE(macro)##litteral2
42
43/* examples
44#define T1 foo
45#define T2 _bar
46#define T3 .h
47
48#include STRINGIZE_3_CONCAT(T1,T2,T3)
49#include STRINGIZE_NX(PPCAT(T1, T2, T3)) // this becomes "PPCAT(T1, T2, T3)"
50#include STRINGIZE(PPCAT_NX(foo, _bar, .h)) // this is "foo_bar.h" since neither foo nor .h are macros
51#include STRINGIZE(PPCAT_NX(T1, T2, T3)) // this is "T1T2T3"
52#include STRINGIZE(PPCAT(T1, T2, T3)) // this is "foo_bar.h"
53*/