[PATCH 08/10] arch: move cmodel predefines to the target files.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <luc.vanoostenryck@xxxxxxxxx>
---
 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 a2514b420888..de9c87c180cb 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 d0585e363bce..290cbc576abe 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 cddabb820085..71db639cdf85 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 e7acb36349ad..bbb47e9d7a34 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 = {
-- 
2.24.0




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux