Software APIs
adv_macros.h
1// Copyright lowRISC contributors (OpenTitan project).
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
5#ifndef OPENTITAN_SW_DEVICE_LIB_BASE_ADV_MACROS_H_
6#define OPENTITAN_SW_DEVICE_LIB_BASE_ADV_MACROS_H_
7
9
10// The preprocessor techniques below are explained at
11// https://github.com/pfultz2/Cloak/wiki/C-Preprocessor-tricks,-tips,-and-idioms
12
13#define OT_IIF(c) OT_PRIMITIVE_CAT(OT_IIF_, c)
14#define OT_IIF_0(t, ...) __VA_ARGS__
15#define OT_IIF_1(t, ...) t
16
17#define OT_CHECK_N(x, n, ...) n
18#define OT_CHECK(...) OT_CHECK_N(__VA_ARGS__, 0, )
19#define OT_PROBE(x) x, 1,
20
21#define OT_NOT(x) OT_CHECK(OT_PRIMITIVE_CAT(OT_NOT_, x))
22#define OT_NOT_0 OT_PROBE(~)
23
24#define OT_EMPTY()
25#define OT_DEFER(id) id OT_EMPTY()
26#define OT_OBSTRUCT(...) __VA_ARGS__ OT_DEFER(OT_EMPTY)()
27#define OT_EXPAND(...) __VA_ARGS__
28
29#define OT_EVAL(...) OT_EVAL1(OT_EVAL1(OT_EVAL1(__VA_ARGS__)))
30#define OT_EVAL1(...) OT_EVAL2(OT_EVAL2(OT_EVAL2(__VA_ARGS__)))
31#define OT_EVAL2(...) OT_EVAL3(OT_EVAL3(OT_EVAL3(__VA_ARGS__)))
32#define OT_EVAL3(...) OT_EVAL4(OT_EVAL4(OT_EVAL4(__VA_ARGS__)))
33#define OT_EVAL4(...) OT_EVAL5(OT_EVAL5(OT_EVAL5(__VA_ARGS__)))
34#define OT_EVAL5(...) __VA_ARGS__
35
36#endif // OPENTITAN_SW_DEVICE_LIB_BASE_ADV_MACROS_H_