Skip to content

Commit ef98669

Browse files
committed
sim/common: convert sim-arange to use sim-inline
This fixes a TODO item and also fixes an error which we get when building with no optimizations (-O0) in at least gcc 8.2.1. Tested with sims that use cgen code lm32, or1k, cris, m32r and inlining is working corretly. Reference Error: gcc -DHAVE_CONFIG_H -DWITH_DEFAULT_MODEL='"or1200"' -DWITH_ALIGNMENT=STRICT_ALIGNMENT \ -DWITH_TARGET_WORD_BITSIZE=32 -DWITH_TARGET_WORD_MSB=31 -DWITH_TARGET_ADDRESS_BITSIZE=32 \ -DWITH_TARGET_BYTE_ORDER=BFD_ENDIAN_BIG -DDEFAULT_INLINE=0 -DWITH_SCACHE=16384 \ -I. -I../../../binutils-gdb/sim/or1k -I../common -I../../../binutils-gdb/sim/or1k/../common \ -I../../include -I../../../binutils-gdb/sim/or1k/../../include -I../../bfd \ -I../../../binutils-gdb/sim/or1k/../../bfd -I../../opcodes -I../../../binutils-gdb/sim/or1k/../../opcodes \ -g -o run nrun.o libsim.a ../../bfd/libbfd.a ../../opcodes/libopcodes.a ../../libiberty/libiberty.a \ -ldl -lz -lm /usr/bin/ld: libsim.a(mloop.o): in function `extract': /home/shorne/work/openrisc/gdb-musl/sim/or1k/mloop.c:82: undefined reference to `sim_addr_range_hit_p' /usr/bin/ld: /home/shorne/work/openrisc/gdb-musl/sim/or1k/mloop.c:83: undefined reference to `sim_addr_range_hit_p' collect2: error: ld returned 1 exit status make[3]: *** [Makefile:305: run] Error 1 sim/common/ChangeLog: * Make-common.in (sim-arange_h): Remove sim-arange.c * sim-arange.c: Remove SIM_ARANGE_C. Add ifdef for _SIM_ARANGE_C_. Include "sim-arange.h". Remove include for unused "sim-assert.h". Remove DEFINE_INLINE_P. Remove DEFINE_NON_INLINE_P. (sim_addr_range_add): Declare as INLINE_SIM_ARANGE. (sim_addr_range_delete): Declare as INLINE_SIM_ARANGE. (sim_addr_range_hit_p): Change from SIM_ARANGE_INLINE to INLINE_SIM_ARANGE. * sim-arange.h (sim_addr_range_add): Declare as INLINE_SIM_ARANGE. (sim_addr_range_delete): Declare as INLINE_SIM_ARANGE. (sim_addr_range_hit_p) Declare as INLINE_SIM_ARANGE. Remove definition of SIM_ARANGE_INLINE. Remove [HAVE_INLINE]. Wrap include "sim-arange.c" in H_REVEALS_MODULE_P. * sim-base.h: Include "sim-arange.h" * sim-basics.h: Remove include of "sim-arange.h" * sim-inline.c: Include "sim-arange.c" * sim-inline.h: Define INLINE_SIM_ARANGE. Define SIM_ARANGE_INLINE. Define EXTERN_SIM_ARANGE_P. Define STATIC_INLINE_SIM_ARANGE. Define STATIC_SIM_ARANGE.
1 parent 20dc7e9 commit ef98669

File tree

8 files changed

+83
-36
lines changed

8 files changed

+83
-36
lines changed

sim/common/ChangeLog

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
2019-03-28 Stafford Horne <[email protected]>
2+
3+
* Make-common.in (sim-arange_h): Remove sim-arange.c
4+
* sim-arange.c: Remove SIM_ARANGE_C.
5+
Add ifdef for _SIM_ARANGE_C_.
6+
Include "sim-arange.h".
7+
Remove include for unused "sim-assert.h".
8+
Remove DEFINE_INLINE_P. Remove DEFINE_NON_INLINE_P.
9+
(sim_addr_range_add): Declare as INLINE_SIM_ARANGE.
10+
(sim_addr_range_delete): Declare as INLINE_SIM_ARANGE.
11+
(sim_addr_range_hit_p): Change from SIM_ARANGE_INLINE to
12+
INLINE_SIM_ARANGE.
13+
* sim-arange.h (sim_addr_range_add): Declare as
14+
INLINE_SIM_ARANGE.
15+
(sim_addr_range_delete): Declare as INLINE_SIM_ARANGE.
16+
(sim_addr_range_hit_p) Declare as INLINE_SIM_ARANGE.
17+
Remove definition of SIM_ARANGE_INLINE.
18+
Remove [HAVE_INLINE].
19+
Wrap include "sim-arange.c" in H_REVEALS_MODULE_P.
20+
* sim-base.h: Include "sim-arange.h"
21+
* sim-basics.h: Remove include of "sim-arange.h"
22+
* sim-inline.c: Include "sim-arange.c"
23+
* sim-inline.h: Define INLINE_SIM_ARANGE.
24+
Define SIM_ARANGE_INLINE. Define EXTERN_SIM_ARANGE_P.
25+
Define STATIC_INLINE_SIM_ARANGE. Define STATIC_SIM_ARANGE.
26+
127
2019-01-26 Tom Tromey <[email protected]>
228

329
* Make-common.in (version.c): Use sim's create-version.sh.

sim/common/Make-common.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,7 @@ SIM_MAIN_DEPS = \
319319
$(sim_main_headers)
320320

321321
sim-alu_h = $(srccom)/sim-alu.h
322-
sim-arange_h = $(srccom)/sim-arange.h \
323-
$(srccom)/sim-arange.c
322+
sim-arange_h = $(srccom)/sim-arange.h
324323
sim-assert_h = $(srccom)/sim-assert.h
325324
sim-base_h = $(srccom)/sim-base.h \
326325
$(sim-module_h) \

sim/common/sim-arange.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ GNU General Public License for more details.
1717
You should have received a copy of the GNU General Public License
1818
along with this program. If not, see <http://www.gnu.org/licenses/>. */
1919

20-
/* Tell sim-arange.h it's us. */
21-
#define SIM_ARANGE_C
20+
#ifndef _SIM_ARANGE_C_
21+
#define _SIM_ARANGE_C_
2222

2323
#include "libiberty.h"
2424
#include "sim-basics.h"
25-
#include "sim-assert.h"
25+
#include "sim-arange.h"
2626

2727
#ifdef HAVE_STDLIB_H
2828
#include <stdlib.h>
@@ -32,8 +32,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
3232
#include <string.h>
3333
#endif
3434

35-
#ifdef SIM_ARANGE_C_INCLUDED
36-
3735
/* Insert a range. */
3836

3937
static void
@@ -251,7 +249,8 @@ build_search_tree (ADDR_RANGE *ar)
251249
free (asrtab);
252250
}
253251

254-
void
252+
INLINE_SIM_ARANGE\
253+
(void)
255254
sim_addr_range_add (ADDR_RANGE *ar, address_word start, address_word end)
256255
{
257256
frob_range (ar, start, end, 0);
@@ -264,7 +263,8 @@ sim_addr_range_add (ADDR_RANGE *ar, address_word start, address_word end)
264263
build_search_tree (ar);
265264
}
266265

267-
void
266+
INLINE_SIM_ARANGE\
267+
(void)
268268
sim_addr_range_delete (ADDR_RANGE *ar, address_word start, address_word end)
269269
{
270270
frob_range (ar, start, end, 1);
@@ -277,9 +277,8 @@ sim_addr_range_delete (ADDR_RANGE *ar, address_word start, address_word end)
277277
build_search_tree (ar);
278278
}
279279

280-
#else /* SIM_ARANGE_C_INCLUDED */
281-
282-
SIM_ARANGE_INLINE int
280+
INLINE_SIM_ARANGE\
281+
(int)
283282
sim_addr_range_hit_p (ADDR_RANGE *ar, address_word addr)
284283
{
285284
ADDR_RANGE_TREE *t = ar->range_tree;
@@ -296,4 +295,4 @@ sim_addr_range_hit_p (ADDR_RANGE *ar, address_word addr)
296295
return 0;
297296
}
298297

299-
#endif /* SIM_ARANGE_C_INCLUDED */
298+
#endif /* _SIM_ARANGE_C_ */

sim/common/sim-arange.h

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,24 @@ typedef struct _addr_range {
5151
} ADDR_RANGE;
5252

5353
/* Add address range START,END to AR. */
54-
extern void sim_addr_range_add (ADDR_RANGE * /*ar*/,
55-
address_word /*start*/,
56-
address_word /*end*/);
54+
INLINE_SIM_ARANGE (void) sim_addr_range_add (ADDR_RANGE * /*ar*/,
55+
address_word /*start*/,
56+
address_word /*end*/);
5757

5858
/* Delete address range START,END from AR. */
59-
extern void sim_addr_range_delete (ADDR_RANGE * /*ar*/,
60-
address_word /*start*/,
61-
address_word /*end*/);
62-
63-
/* TODO: This should get moved into sim-inline.h. */
64-
#ifdef HAVE_INLINE
65-
#ifdef SIM_ARANGE_C
66-
#define SIM_ARANGE_INLINE INLINE
67-
#else
68-
#define SIM_ARANGE_INLINE EXTERN_INLINE
69-
#endif
70-
#else
71-
#define SIM_ARANGE_INLINE extern
72-
#endif
59+
INLINE_SIM_ARANGE (void) sim_addr_range_delete (ADDR_RANGE * /*ar*/,
60+
address_word /*start*/,
61+
address_word /*end*/);
7362

7463
/* Return non-zero if ADDR is in range AR, traversing the entire tree.
7564
If no range is specified, that is defined to mean "everything". */
76-
SIM_ARANGE_INLINE int
77-
sim_addr_range_hit_p (ADDR_RANGE * /*ar*/, address_word /*addr*/);
65+
INLINE_SIM_ARANGE (int) sim_addr_range_hit_p (ADDR_RANGE * /*ar*/,
66+
address_word /*addr*/);
7867
#define ADDR_RANGE_HIT_P(ar, addr) \
7968
((ar)->range_tree == NULL || sim_addr_range_hit_p ((ar), (addr)))
8069

81-
#ifdef HAVE_INLINE
70+
#if H_REVEALS_MODULE_P (SIM_ARANGE_INLINE)
8271
#include "sim-arange.c"
8372
#endif
84-
#define SIM_ARANGE_C_INCLUDED
8573

8674
#endif /* SIM_ARANGE_H */

sim/common/sim-base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ typedef struct _sim_cpu sim_cpu;
8282

8383
#include "sim-module.h"
8484

85+
#include "sim-arange.h"
8586
#include "sim-trace.h"
8687
#include "sim-core.h"
8788
#include "sim-events.h"

sim/common/sim-basics.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ typedef enum {
144144
#include "sim-bits.h"
145145
#include "sim-endian.h"
146146
#include "sim-signal.h"
147-
#include "sim-arange.h"
148147

149148
#include "sim-utils.h"
150149

sim/common/sim-inline.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#include "sim-inline.h"
3030
#include "sim-main.h"
3131

32+
#if C_REVEALS_MODULE_P (SIM_ARANGE_INLINE)
33+
#include "sim-arange.c"
34+
#endif
35+
3236

3337
#if C_REVEALS_MODULE_P (SIM_BITS_INLINE)
3438
#include "sim-bits.c"
@@ -64,7 +68,6 @@
6468
#include "sim-main.c"
6569
#endif
6670

67-
6871
#if C_REVEALS_MODULE_P (ENGINE_INLINE)
6972
/* #include "engine.c" - handled by generator */
7073
#endif

sim/common/sim-inline.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,38 @@
348348

349349

350350

351+
352+
/* sim_arange */
353+
354+
#if !defined (SIM_ARANGE_INLINE) && (DEFAULT_INLINE)
355+
# define SIM_ARANGE_INLINE (ALL_H_INLINE)
356+
#endif
357+
358+
#if ((H_REVEALS_MODULE_P (SIM_ARANGE_INLINE) || defined (SIM_INLINE_C)) \
359+
&& !defined (SIM_ARANGE_C) \
360+
&& (REVEAL_MODULE_P (SIM_ARANGE_INLINE)))
361+
# if (SIM_ARANGE_INLINE & INLINE_GLOBALS)
362+
# define INLINE_SIM_ARANGE(TYPE) static INLINE TYPE UNUSED
363+
# define EXTERN_SIM_ARANGE_P 0
364+
# else
365+
# define INLINE_SIM_ARANGE(TYPE) static TYPE UNUSED
366+
# define EXTERN_SIM_ARANGE_P 0
367+
# endif
368+
#else
369+
# define INLINE_SIM_ARANGE(TYPE) TYPE
370+
# define EXTERN_SIM_ARANGE_P 1
371+
#endif
372+
373+
#if (SIM_ARANGE_INLINE & INLINE_LOCALS)
374+
# define STATIC_INLINE_SIM_ARANGE(TYPE) static INLINE TYPE
375+
#else
376+
# define STATIC_INLINE_SIM_ARANGE(TYPE) static TYPE
377+
#endif
378+
379+
#define STATIC_SIM_ARANGE(TYPE) static TYPE
380+
381+
382+
351383
/* *****
352384
sim-bits and sim-endian are treated differently from the rest
353385
of the modules below. Their default value is ALL_H_INLINE.

0 commit comments

Comments
 (0)