From 2d922d86bac7b51bfe8e45ed4c8aa7af37010ead Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 26 Jun 2021 22:29:35 -0400 Subject: [PATCH] sim: cgen: always leverage the mem prototypes This fixes missing prototype warnings, and guarantees the prototypes stay in sync with the function definitions. One of the macros had fallen out by declaring the wrong return type. --- sim/common/ChangeLog | 13 ++++++++++ sim/common/cgen-mem.h | 56 ++++++++++++++++++++++++++++++++----------- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index 1675528f30b..b0c3cb17d06 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,3 +1,16 @@ +2021-06-27 Mike Frysinger + + * cgen-mem.h (DECLARE_GETMEM_EXTERN): New macro. + (DECLARE_GETMEM): Use DECLARE_GETMEM_EXTERN. + (DECLARE_SETMEM_EXTERN): New macro. + (DECLARE_SETMEM): Use DECLARE_SETMEM_EXTERN. + (DECLARE_GETIMEM_EXTERN): New macro. + (DECLARE_GETIMEM): Use DECLARE_GETIMEM_EXTERN. + (DECLARE_GETT_EXTERN): New macro. + (DECLARE_GETT): Use DECLARE_GETT_EXTERN. + (DECLARE_SETT_EXTERN): New macro. + (DECLARE_SETT): Use DECLARE_SETT_EXTERN. + 2021-06-27 Mike Frysinger * cgen-ops.h: Move prototype blocks before function definitions. diff --git a/sim/common/cgen-mem.h b/sim/common/cgen-mem.h index 1a3843f8efe..deb3cc091c6 100644 --- a/sim/common/cgen-mem.h +++ b/sim/common/cgen-mem.h @@ -33,8 +33,12 @@ along with this program. If not, see . */ floating point modes, only floating point operations (whose arguments and results are arrays of bits that we treat as integer modes). */ +#define DECLARE_GETMEM_EXTERN(mode, size) \ +extern mode XCONCAT2 (GETMEM,mode) (SIM_CPU *, IADDR, ADDR); + #if defined (__GNUC__) || defined (MEMOPS_DEFINE_INLINE) #define DECLARE_GETMEM(mode, size) \ +DECLARE_GETMEM_EXTERN (mode, size) \ MEMOPS_INLINE mode \ XCONCAT2 (GETMEM,mode) (SIM_CPU *cpu, IADDR pc, ADDR a) \ { \ @@ -43,8 +47,7 @@ XCONCAT2 (GETMEM,mode) (SIM_CPU *cpu, IADDR pc, ADDR a) \ return XCONCAT2 (sim_core_read_unaligned_,size) (cpu, pc, read_map, a); \ } #else -#define DECLARE_GETMEM(mode, size) \ -extern mode XCONCAT2 (GETMEM,mode) (SIM_CPU *, IADDR, ADDR); +#define DECLARE_GETMEM(mode, size) DECLARE_GETMEM_EXTERN (mode, size) #endif DECLARE_GETMEM (QI, 1) /* TAGS: GETMEMQI */ @@ -57,11 +60,16 @@ DECLARE_GETMEM (DI, 8) /* TAGS: GETMEMDI */ DECLARE_GETMEM (UDI, 8) /* TAGS: GETMEMUDI */ #undef DECLARE_GETMEM +#undef DECLARE_GETMEM_EXTERN /* Integer memory write support. */ +#define DECLARE_SETMEM_EXTERN(mode, size) \ +extern void XCONCAT2 (SETMEM,mode) (SIM_CPU *, IADDR, ADDR, mode); + #if defined (__GNUC__) || defined (MEMOPS_DEFINE_INLINE) #define DECLARE_SETMEM(mode, size) \ +DECLARE_SETMEM_EXTERN (mode, size) \ MEMOPS_INLINE void \ XCONCAT2 (SETMEM,mode) (SIM_CPU *cpu, IADDR pc, ADDR a, mode val) \ { \ @@ -70,8 +78,7 @@ XCONCAT2 (SETMEM,mode) (SIM_CPU *cpu, IADDR pc, ADDR a, mode val) \ XCONCAT2 (sim_core_write_unaligned_,size) (cpu, pc, write_map, a, val); \ } #else -#define DECLARE_SETMEM(mode, size) \ -extern void XCONCAT2 (SETMEM,mode) (SIM_CPU *, IADDR, ADDR, mode); +#define DECLARE_SETMEM(mode, size) DECLARE_SETMEM_EXTERN (mode, size) #endif DECLARE_SETMEM (QI, 1) /* TAGS: SETMEMQI */ @@ -84,11 +91,16 @@ DECLARE_SETMEM (DI, 8) /* TAGS: SETMEMDI */ DECLARE_SETMEM (UDI, 8) /* TAGS: SETMEMUDI */ #undef DECLARE_SETMEM +#undef DECLARE_SETMEM_EXTERN /* Instruction read support. */ +#define DECLARE_GETIMEM_EXTERN(mode, size) \ +extern mode XCONCAT2 (GETIMEM,mode) (SIM_CPU *, ADDR); + #if defined (__GNUC__) || defined (MEMOPS_DEFINE_INLINE) #define DECLARE_GETIMEM(mode, size) \ +DECLARE_GETIMEM_EXTERN (mode, size) \ MEMOPS_INLINE mode \ XCONCAT2 (GETIMEM,mode) (SIM_CPU *cpu, IADDR a) \ { \ @@ -97,8 +109,7 @@ XCONCAT2 (GETIMEM,mode) (SIM_CPU *cpu, IADDR a) \ return XCONCAT2 (sim_core_read_unaligned_,size) (cpu, a, exec_map, a); \ } #else -#define DECLARE_GETIMEM(mode, size) \ -extern mode XCONCAT2 (GETIMEM,mode) (SIM_CPU *, ADDR); +#define DECLARE_GETIMEM(mode, size) DECLARE_GETIMEM_EXTERN (mode, size) #endif DECLARE_GETIMEM (UQI, 1) /* TAGS: GETIMEMUQI */ @@ -107,6 +118,7 @@ DECLARE_GETIMEM (USI, 4) /* TAGS: GETIMEMUSI */ DECLARE_GETIMEM (UDI, 8) /* TAGS: GETIMEMUDI */ #undef DECLARE_GETIMEM +#undef DECLARE_GETIMEM_EXTERN /* Floating point support. @@ -118,8 +130,12 @@ DECLARE_GETIMEM (UDI, 8) /* TAGS: GETIMEMUDI */ that's a complication of its own (not that having these fns isn't). But for now, we do things this way. */ +#define DECLARE_GETMEM_EXTERN(mode, size) \ +extern mode XCONCAT2 (GETMEM,mode) (SIM_CPU *, IADDR, ADDR); + #if defined (__GNUC__) || defined (MEMOPS_DEFINE_INLINE) #define DECLARE_GETMEM(mode, size) \ +DECLARE_GETMEM_EXTERN (mode, size) \ MEMOPS_INLINE mode \ XCONCAT2 (GETMEM,mode) (SIM_CPU *cpu, IADDR pc, ADDR a) \ { \ @@ -128,17 +144,21 @@ XCONCAT2 (GETMEM,mode) (SIM_CPU *cpu, IADDR pc, ADDR a) \ return XCONCAT2 (sim_core_read_unaligned_,size) (cpu, pc, read_map, a); \ } #else -#define DECLARE_GETMEM(mode, size) \ -extern mode XCONCAT2 (GETMEM,mode) (SIM_CPU *, IADDR, ADDR); +#define DECLARE_GETMEM(mode, size) DECLARE_GETMEM_EXTERN (mode, size) #endif DECLARE_GETMEM (SF, 4) /* TAGS: GETMEMSF */ DECLARE_GETMEM (DF, 8) /* TAGS: GETMEMDF */ #undef DECLARE_GETMEM +#undef DECLARE_GETMEM_EXTERN + +#define DECLARE_SETMEM_EXTERN(mode, size) \ +extern void XCONCAT2 (SETMEM,mode) (SIM_CPU *, IADDR, ADDR, mode); #if defined (__GNUC__) || defined (MEMOPS_DEFINE_INLINE) #define DECLARE_SETMEM(mode, size) \ +DECLARE_SETMEM_EXTERN (mode, size) \ MEMOPS_INLINE void \ XCONCAT2 (SETMEM,mode) (SIM_CPU *cpu, IADDR pc, ADDR a, mode val) \ { \ @@ -147,21 +167,25 @@ XCONCAT2 (SETMEM,mode) (SIM_CPU *cpu, IADDR pc, ADDR a, mode val) \ XCONCAT2 (sim_core_write_unaligned_,size) (cpu, pc, write_map, a, val); \ } #else -#define DECLARE_SETMEM(mode, size) \ -extern void XCONCAT2 (SETMEM,mode) (SIM_CPU *, IADDR, ADDR, mode); +#define DECLARE_SETMEM(mode, size) DECLARE_SETMEM_EXTERN (mode, size #endif DECLARE_SETMEM (SF, 4) /* TAGS: SETMEMSF */ DECLARE_SETMEM (DF, 8) /* TAGS: SETMEMDF */ #undef DECLARE_SETMEM +#undef DECLARE_SETMEM_EXTERN /* GETT: translate target value at P to host value. This needn't be very efficient (i.e. can call memcpy) as this is only used when interfacing with the outside world (e.g. gdb). */ +#define DECLARE_GETT_EXTERN(mode, size) \ +extern mode XCONCAT2 (GETT,mode) (unsigned char *); + #if defined (MEMOPS_DEFINE_INLINE) #define DECLARE_GETT(mode, size) \ +DECLARE_GETT_EXTERN (mode, size) \ mode \ XCONCAT2 (GETT,mode) (unsigned char *p) \ { \ @@ -170,8 +194,7 @@ XCONCAT2 (GETT,mode) (unsigned char *p) \ return XCONCAT2 (T2H_,size) (tmp); \ } #else -#define DECLARE_GETT(mode, size) \ -extern mode XCONCAT2 (GETT,mode) (unsigned char *); +#define DECLARE_GETT(mode, size) DECLARE_GETT_EXTERN (mode, size) #endif DECLARE_GETT (QI, 1) /* TAGS: GETTQI */ @@ -190,13 +213,18 @@ DECLARE_GETT (TF, 16) /* TAGS: GETTTF */ #endif #undef DECLARE_GETT +#undef DECLARE_GETT_EXTERN /* SETT: translate host value to target value and store at P. This needn't be very efficient (i.e. can call memcpy) as this is only used when interfacing with the outside world (e.g. gdb). */ +#define DECLARE_SETT_EXTERN(mode, size) \ +extern void XCONCAT2 (SETT,mode) (unsigned char *, mode); + #if defined (MEMOPS_DEFINE_INLINE) #define DECLARE_SETT(mode, size) \ +DECLARE_SETT_EXTERN (mode, size) \ void \ XCONCAT2 (SETT,mode) (unsigned char *buf, mode val) \ { \ @@ -205,8 +233,7 @@ XCONCAT2 (SETT,mode) (unsigned char *buf, mode val) \ memcpy (buf, &tmp, sizeof (mode)); \ } #else -#define DECLARE_SETT(mode, size) \ -extern mode XCONCAT2 (SETT,mode) (unsigned char *, mode); +#define DECLARE_SETT(mode, size) DECLARE_SETT_EXTERN (mode, size) #endif DECLARE_SETT (QI, 1) /* TAGS: SETTQI */ @@ -225,5 +252,6 @@ DECLARE_SETT (TF, 16) /* TAGS: SETTTF */ #endif #undef DECLARE_SETT +#undef DECLARE_SETT_EXTERN #endif /* CGEN_MEM_H */ -- 2.30.2