diff options
author | Randall Spangler <rspangler@chromium.org> | 2013-07-24 11:19:10 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-07-24 14:05:17 -0700 |
commit | fe660aa3729aa6f468a62f4e6c37f3dd5c85503d (patch) | |
tree | 3d784cdf240e80fd31c2fdc291c24ddaca6b7d08 /include/common.h | |
parent | 596480de062da815326071630ebf2348ce1c02ac (diff) | |
download | chrome-ec-fe660aa3729aa6f468a62f4e6c37f3dd5c85503d.tar.gz |
Standardize concatenation macros
To create a token by concatenating already-defined macros and new
text, it's necessary to use multiple levels of macro. We'd already
done that in several places in the code such as STM32_CAT; this now
standardizes it into a single place.
BUG=chrome-os-partner:18343
BRANCH=none
TEST=Build all platforms; examine ec.RO.map to see that irq_*_handler and prio_* symbols
evaluated the same as before. (Other macro evaluations would simply fail to compile
if they were incorrect, since the concatenated tokens wouldn't fully expand.)
Change-Id: Ic9bf11d27881a84507fe7b6096dab6217c6c6dc7
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/63231
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'include/common.h')
-rw-r--r-- | include/common.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/include/common.h b/include/common.h index 1fb4fc5563..c6eeb11fef 100644 --- a/include/common.h +++ b/include/common.h @@ -10,6 +10,23 @@ #include <stdint.h> +/* + * Macros to concatenate 2 - 4 tokens together to form a single token. + * Multiple levels of nesting are required to convince the preprocessor to + * expand currently-defined tokens before concatenation. + * + * For example, if you have + * #define FOO 1 + * #define BAR1 42 + * Then + * #define BAZ CONCAT2(BAR, FOO) + * Will evaluate to BAR1, which then evaluates to 42. + */ +#define CONCAT_STAGE_1(w, x, y, z) w ## x ## y ## z +#define CONCAT2(w, x) CONCAT_STAGE_1(w, x, , ) +#define CONCAT3(w, x, y) CONCAT_STAGE_1(w, x, y, ) +#define CONCAT4(w, x, y, z) CONCAT_STAGE_1(w, x, y, z) + /* Macros to access registers */ #define REG32(addr) (*(volatile uint32_t *)(addr)) #define REG16(addr) (*(volatile uint16_t *)(addr)) |