From 17a0752e0c01e0b44c5a3f08dce8e8fbd21a0dee Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 15 Dec 2019 08:22:16 +0100 Subject: arch: move cmodel predefines to the target files. Now that each supported arch has its own target file, move the predefines for cmodel, which are arch-specific, to the target files. Signed-off-by: Luc Van Oostenryck --- lib.c | 50 -------------------------------------------------- lib.h | 1 + target-arm64.c | 10 ++++++++++ target-riscv.c | 10 ++++++++++ 4 files changed, 21 insertions(+), 50 deletions(-) diff --git a/lib.c b/lib.c index a2514b42..de9c87c1 100644 --- a/lib.c +++ b/lib.c @@ -1275,55 +1275,6 @@ static void predefined_ctype(const char *name, struct symbol *type, int flags) predefined_width(name, bits); } -static void predefined_cmodel(void) -{ - const char *pre, *suf; - const char *def = NULL; - switch (arch_mach) { - case MACH_ARM64: - pre = "__AARCH64_CMODEL_"; - suf = "__"; - switch (arch_cmodel) { - case CMODEL_LARGE: - def = "LARGE"; - break; - case CMODEL_SMALL: - def = "SMALL"; - break; - case CMODEL_TINY: - def = "TINY"; - break; - default: - break; - } - break; - case MACH_RISCV32: - case MACH_RISCV64: - pre = "__riscv_cmodel_"; - suf = ""; - switch (arch_cmodel) { - case CMODEL_MEDLOW: - def = "medlow"; - break; - case CMODEL_MEDANY: - def = "medany"; - break; - case CMODEL_PIC: - def = "pic"; - break; - default: - break; - } - break; - default: - break; - } - - if (!def) - return; - add_pre_buffer("#weak_define %s%s%s 1\n", pre, def, suf); -} - static void predefined_macros(void) { predefine("__CHECKER__", 0, "1"); @@ -1457,7 +1408,6 @@ static void predefined_macros(void) if (arch_target->predefine) arch_target->predefine(arch_target); - predefined_cmodel(); } //////////////////////////////////////////////////////////////////////////////// diff --git a/lib.h b/lib.h index d0585e36..290cbc57 100644 --- a/lib.h +++ b/lib.h @@ -222,6 +222,7 @@ enum { CMODEL_PIC, CMODEL_SMALL, CMODEL_TINY, + CMODEL_LAST, }; extern int arch_cmodel; diff --git a/target-arm64.c b/target-arm64.c index cddabb82..71db639c 100644 --- a/target-arm64.c +++ b/target-arm64.c @@ -11,7 +11,17 @@ static void init_arm64(const struct target *self) static void predefine_arm64(const struct target *self) { + static const char *cmodels[CMODEL_LAST] = { + [CMODEL_LARGE] = "LARGE", + [CMODEL_SMALL] = "SMALL", + [CMODEL_TINY] = "TINY", + }; + const char *cmodel = cmodels[arch_cmodel]; + predefine("__aarch64__", 1, "1"); + + if (cmodel) + add_pre_buffer("#define __AARCH64_CMODEL_%s__ 1\n", cmodel); } const struct target target_arm64 = { diff --git a/target-riscv.c b/target-riscv.c index e7acb363..bbb47e9d 100644 --- a/target-riscv.c +++ b/target-riscv.c @@ -13,8 +13,18 @@ static void init_riscv(const struct target *self) static void predefine_riscv(const struct target *self) { + static const char *cmodels[CMODEL_LAST] = { + [CMODEL_MEDANY] = "medany", + [CMODEL_MEDLOW] = "medlow", + [CMODEL_PIC] = "pic", + }; + const char *cmodel = cmodels[arch_cmodel]; + predefine("__riscv", 1, "1"); predefine("__riscv_xlen", 1, "%d", ptr_ctype.bit_size); + + if (cmodel) + add_pre_buffer("#define __riscv_cmodel_%s 1\n", cmodel); } const struct target target_riscv32 = { -- cgit 1.2.3-korg