etl/include/etl/stringify.h
David Hebbeker cab9b76821
add stringify macro (#741)
* Add include/linux/stringify.h from Linux kernel 2.6.12-rc2

(cherry picked from commit 1da177e4c3)

* Make __stringify support variable argument macros too

For example:

  __stringify(__entry->irq, __entry->ret)

will now convert it to:

  "REC->irq, REC->ret"

It also still supports single arguments as the old macro did.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <49DC6751.30308@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
(cherry picked from commit 8f7c2c3731)

* Add documentation.

* Adjust names in order to satisfy naming convention.

* Use __VA_ARGS__ instead a GNU extension as this works with more compilers.

Works with the newest versions of ICCAVR, GCC, CLANG and MSCV. C++11 may be required.

* Adjust to ETL folder structure.

* Change include guard to the one usual in ETL.

* Add definition guard for STRINGIFY.

---------

Co-authored-by: Linus Torvalds <torvalds@ppc970.osdl.org>
Co-authored-by: Zhaolei <zhaolei@cn.fujitsu.com>
2023-08-11 10:09:06 +01:00

21 lines
632 B
C

#ifndef ETL_ETL_STRINGIFY_INCLUDED
#define ETL_ETL_STRINGIFY_INCLUDED
#ifndef STRINGIFY
/** Helper macro for STRINGIFY. */
#define STRINGIFY_1(...) #__VA_ARGS__
/**
* Indirect stringification.
*
* Doing two levels allows the parameter to be a macro itself.
* For example, compile with `-DFOO=bar`, `STRINGIFY(FOO)` converts to "bar".
*
* \param x will be converted to one string, including the spaces and commas between arguments.
* For example `STRINGIFY( a , b )` will be expanded to "a , b".
*/
#define STRINGIFY(...) STRINGIFY_1(__VA_ARGS__)
#endif /* STRINGIFY */
#endif /* ETL_ETL_STRINGIFY_INCLUDED */