[05/10] arch: move handle_arch_finalize() into target_init()
diff mbox series

Message ID 20191216223756.2428-6-luc.vanoostenryck@gmail.com
State Mainlined, archived
Headers show
Series
  • move arch specificities in their own files
Related show

Commit Message

Luc Van Oostenryck Dec. 16, 2019, 10:37 p.m. UTC
Before initaializing the builtin types some 'finalizations' are
needed. target_ini() already does most of this.

So, move the arch-specific content of handle_arch_finalize()
into the corresponding target files and the generic part to
target_init().

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 lib.c          | 35 +----------------------------------
 lib.h          |  1 +
 target-arm64.c |  8 ++++++++
 target-riscv.c | 12 ++++++++++++
 target.c       | 10 ++++++++++
 5 files changed, 32 insertions(+), 34 deletions(-)

Patch
diff mbox series

diff --git a/lib.c b/lib.c
index 82354af7eafa..366acd45436a 100644
--- a/lib.c
+++ b/lib.c
@@ -320,7 +320,7 @@  int preprocess_only;
 
 enum standard standard = STANDARD_GNU89;
 
-static int arch_msize_long = 0;
+int arch_msize_long = 0;
 int arch_m64 = ARCH_M64_DEFAULT;
 int arch_big_endian = ARCH_BIG_ENDIAN;
 int arch_fp_abi = FP_ABI_NATIVE;
@@ -714,38 +714,6 @@  static char **handle_switch_m(char *arg, char **next)
 	return next;
 }
 
-static void handle_arch_msize_long_finalize(void)
-{
-	if (arch_msize_long) {
-		size_t_ctype = &ulong_ctype;
-		ssize_t_ctype = &long_ctype;
-	}
-}
-
-static void handle_arch_finalize(void)
-{
-	handle_arch_msize_long_finalize();
-
-	if (fpie > fpic)
-		fpic = fpie;
-	if (fshort_wchar)
-		wchar_ctype = &ushort_ctype;
-
-	switch (arch_mach) {
-	case MACH_ARM64:
-		if (arch_cmodel == CMODEL_UNKNOWN)
-			arch_cmodel = CMODEL_SMALL;
-		break;
-	case MACH_RISCV32:
-	case MACH_RISCV64:
-		if (arch_cmodel == CMODEL_UNKNOWN)
-			arch_cmodel = CMODEL_MEDLOW;
-		if (fpic)
-			arch_cmodel = CMODEL_PIC;
-		break;
-	}
-}
-
 static char **handle_switch_o(char *arg, char **next)
 {
 	if (!strcmp (arg, "o")) {       // "-o foo"
@@ -1732,7 +1700,6 @@  struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list
 	if (filelist) {
 		// Initialize type system
 		target_init();
-		handle_arch_finalize();
 		init_ctype();
 
 		predefined_macros();
diff --git a/lib.h b/lib.h
index 3e565c6fd02d..d0585e363bce 100644
--- a/lib.h
+++ b/lib.h
@@ -205,6 +205,7 @@  extern int fpie;
 extern int fshort_wchar;
 extern int funsigned_char;
 
+extern int arch_msize_long;
 extern int arch_m64;
 extern int arch_big_endian;
 extern int arch_fp_abi;
diff --git a/target-arm64.c b/target-arm64.c
index bfada515b81f..1efd0899495d 100644
--- a/target-arm64.c
+++ b/target-arm64.c
@@ -3,6 +3,12 @@ 
 #include "machine.h"
 
 
+static void init_arm64(const struct target *self)
+{
+	if (arch_cmodel == CMODEL_UNKNOWN)
+		arch_cmodel = CMODEL_SMALL;
+}
+
 const struct target target_arm64 = {
 	.mach = MACH_ARM64,
 	.bitness = ARCH_LP64,
@@ -11,4 +17,6 @@  const struct target target_arm64 = {
 	.unsigned_char = 1,
 
 	.wchar = &uint_ctype,
+
+	.init = init_arm64,
 };
diff --git a/target-riscv.c b/target-riscv.c
index cbec76237d48..09edfd7afeaf 100644
--- a/target-riscv.c
+++ b/target-riscv.c
@@ -3,6 +3,14 @@ 
 #include "machine.h"
 
 
+static void init_riscv(const struct target *self)
+{
+	if (arch_cmodel == CMODEL_UNKNOWN)
+		arch_cmodel = CMODEL_MEDLOW;
+	if (fpic)
+		arch_cmodel = CMODEL_PIC;
+}
+
 const struct target target_riscv32 = {
 	.mach = MACH_RISCV32,
 	.bitness = ARCH_LP32,
@@ -10,6 +18,8 @@  const struct target target_riscv32 = {
 	.unsigned_char = 1,
 
 	.target_64bit = &target_riscv64,
+
+	.init = init_riscv,
 };
 
 const struct target target_riscv64 = {
@@ -19,4 +29,6 @@  const struct target target_riscv64 = {
 	.unsigned_char = 1,
 
 	.target_32bit = &target_riscv32,
+
+	.init = init_riscv,
 };
diff --git a/target.c b/target.c
index 8d2d10588d60..006292cc00ba 100644
--- a/target.c
+++ b/target.c
@@ -181,6 +181,9 @@  void target_init(void)
 	arch_target = target;
 	arch_mach = target->mach;
 
+	if (fpie > fpic)
+		fpic = fpie;
+
 	if (target->wchar)
 		wchar_ctype = target->wchar;
 	if (target->wint)
@@ -192,4 +195,11 @@  void target_init(void)
 
 	if (target->init)
 		target->init(target);
+
+	if (arch_msize_long) {
+		size_t_ctype = &ulong_ctype;
+		ssize_t_ctype = &long_ctype;
+	}
+	if (fshort_wchar)
+		wchar_ctype = &ushort_ctype;
 }