sim: use ARRAY_SIZE instead of ad-hoc sizeof calculations

This commit is contained in:
Mike Frysinger 2017-02-13 00:12:35 -05:00
parent b1499fc214
commit 13a590ca65
39 changed files with 141 additions and 62 deletions

View File

@ -1,3 +1,11 @@
2017-02-13 Mike Frysinger <vapier@gentoo.org>
* armos.c: Include libiberty.h.
(SWIopen): Use ARRAY_SIZE.
* armsupp.c: Include libiberty.h.
(ModeToBank): Use ARRAY_SIZE.
* wrapper.c (sim_target_parse_command_line): Likewise.
2016-07-14 Nick Clifton <nickc@redhat.com> 2016-07-14 Nick Clifton <nickc@redhat.com>
* armemu.c (Multiply64): Only issue error messages about invalid * armemu.c (Multiply64): Only issue error messages about invalid

View File

@ -23,6 +23,7 @@
#include "config.h" #include "config.h"
#include "ansidecl.h" #include "ansidecl.h"
#include "libiberty.h"
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
@ -260,7 +261,7 @@ SWIopen (ARMul_State * state, ARMword name, ARMword SWIflags)
return; return;
/* Now we need to decode the Demon open mode. */ /* Now we need to decode the Demon open mode. */
if (SWIflags >= sizeof (translate_open_mode) / sizeof (translate_open_mode[0])) if (SWIflags >= ARRAY_SIZE (translate_open_mode))
flags = 0; flags = 0;
else else
flags = translate_open_mode[SWIflags]; flags = translate_open_mode[SWIflags];

View File

@ -17,6 +17,7 @@
#include "armdefs.h" #include "armdefs.h"
#include "armemu.h" #include "armemu.h"
#include "ansidecl.h" #include "ansidecl.h"
#include "libiberty.h"
#include <math.h> #include <math.h>
/* Definitions for the support routines. */ /* Definitions for the support routines. */
@ -373,7 +374,7 @@ ModeToBank (ARMword mode)
DUMMYBANK, DUMMYBANK, DUMMYBANK, SYSTEMBANK DUMMYBANK, DUMMYBANK, DUMMYBANK, SYSTEMBANK
}; };
if (mode >= (sizeof (bankofmode) / sizeof (bankofmode[0]))) if (mode >= ARRAY_SIZE (bankofmode))
return DUMMYBANK; return DUMMYBANK;
return bankofmode[mode]; return bankofmode[mode];

View File

@ -740,7 +740,7 @@ sim_target_parse_command_line (int argc, char ** argv)
{ {
int i; int i;
for (i = sizeof options / sizeof options[0]; i--;) for (i = ARRAY_SIZE (options); i--;)
if (strncmp (ptr, options[i].swi_option, if (strncmp (ptr, options[i].swi_option,
strlen (options[i].swi_option)) == 0) strlen (options[i].swi_option)) == 0)
{ {

View File

@ -1,3 +1,9 @@
2017-02-13 Mike Frysinger <vapier@gentoo.org>
* decodev10.c (crisv10f_init_idesc_table): Use ARRAY_SIZE.
* decodev32.c (crisv32f_init_idesc_table): Likewise.
* sim-if.c (sim_open): Likewise.
2016-01-10 Mike Frysinger <vapier@gentoo.org> 2016-01-10 Mike Frysinger <vapier@gentoo.org>
* config.in, configure: Regenerate. * config.in, configure: Regenerate.

View File

@ -302,7 +302,7 @@ crisv10f_init_idesc_table (SIM_CPU *cpu)
init_idesc (cpu, id, t); init_idesc (cpu, id, t);
/* Now fill in the values for the chosen cpu. */ /* Now fill in the values for the chosen cpu. */
for (t = crisv10f_insn_sem, tend = t + sizeof (crisv10f_insn_sem) / sizeof (*t); for (t = crisv10f_insn_sem, tend = t + ARRAY_SIZE (crisv10f_insn_sem);
t != tend; ++t) t != tend; ++t)
{ {
init_idesc (cpu, & table[t->index], t); init_idesc (cpu, & table[t->index], t);

View File

@ -306,7 +306,7 @@ crisv32f_init_idesc_table (SIM_CPU *cpu)
init_idesc (cpu, id, t); init_idesc (cpu, id, t);
/* Now fill in the values for the chosen cpu. */ /* Now fill in the values for the chosen cpu. */
for (t = crisv32f_insn_sem, tend = t + sizeof (crisv32f_insn_sem) / sizeof (*t); for (t = crisv32f_insn_sem, tend = t + ARRAY_SIZE (crisv32f_insn_sem);
t != tend; ++t) t != tend; ++t)
{ {
init_idesc (cpu, & table[t->index], t); init_idesc (cpu, & table[t->index], t);

View File

@ -786,7 +786,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
/* Note that the linux kernel does not correctly compute the storage /* Note that the linux kernel does not correctly compute the storage
needs for the static-exe AUX vector. */ needs for the static-exe AUX vector. */
csp -= sizeof (auxv_entries) / sizeof (auxv_entries[0]) * 4 * 2; csp -= ARRAY_SIZE (auxv_entries) * 4 * 2;
csp -= (envc + 1) * 4; csp -= (envc + 1) * 4;
csp -= (my_argc + 1) * 4; csp -= (my_argc + 1) * 4;
@ -874,7 +874,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
goto abandon_chip; goto abandon_chip;
if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
for (i = 0; i < sizeof (auxv_entries) / sizeof (auxv_entries[0]); i++) for (i = 0; i < ARRAY_SIZE (auxv_entries); i++)
{ {
write_dword (csp, auxv_entries[i].id); write_dword (csp, auxv_entries[i].id);
write_dword (csp + 4, write_dword (csp + 4,

View File

@ -1,3 +1,7 @@
2017-02-13 Mike Frysinger <vapier@gentoo.org>
* decode.c (frvbf_init_idesc_table): Use ARRAY_SIZE.
2016-01-10 Mike Frysinger <vapier@gentoo.org> 2016-01-10 Mike Frysinger <vapier@gentoo.org>
* config.in, configure: Regenerate. * config.in, configure: Regenerate.

View File

@ -841,7 +841,7 @@ frvbf_init_idesc_table (SIM_CPU *cpu)
init_idesc (cpu, id, t); init_idesc (cpu, id, t);
/* Now fill in the values for the chosen cpu. */ /* Now fill in the values for the chosen cpu. */
for (t = frvbf_insn_sem, tend = t + sizeof (frvbf_insn_sem) / sizeof (*t); for (t = frvbf_insn_sem, tend = t + ARRAY_SIZE (frvbf_insn_sem);
t != tend; ++t) t != tend; ++t)
{ {
init_idesc (cpu, & table[t->index], t); init_idesc (cpu, & table[t->index], t);

View File

@ -1,3 +1,7 @@
2017-02-13 Mike Frysinger <vapier@gentoo.org>
* decode.c (iq2000bf_init_idesc_table): Use ARRAY_SIZE.
2016-01-10 Mike Frysinger <vapier@gentoo.org> 2016-01-10 Mike Frysinger <vapier@gentoo.org>
* config.in, configure: Regenerate. * config.in, configure: Regenerate.

View File

@ -242,7 +242,7 @@ iq2000bf_init_idesc_table (SIM_CPU *cpu)
init_idesc (cpu, id, t); init_idesc (cpu, id, t);
/* Now fill in the values for the chosen cpu. */ /* Now fill in the values for the chosen cpu. */
for (t = iq2000bf_insn_sem, tend = t + sizeof (iq2000bf_insn_sem) / sizeof (*t); for (t = iq2000bf_insn_sem, tend = t + ARRAY_SIZE (iq2000bf_insn_sem);
t != tend; ++t) t != tend; ++t)
{ {
init_idesc (cpu, & table[t->index], t); init_idesc (cpu, & table[t->index], t);

View File

@ -1,3 +1,7 @@
2017-02-13 Mike Frysinger <vapier@gentoo.org>
* decode.c (lm32bf_init_idesc_table): Use ARRAY_SIZE.
2016-08-15 Mike Frysinger <vapier@gentoo.org> 2016-08-15 Mike Frysinger <vapier@gentoo.org>
* sim-if.c (find_limit): Change prototype to take a SIM_DESC. * sim-if.c (find_limit): Change prototype to take a SIM_DESC.

View File

@ -160,7 +160,7 @@ lm32bf_init_idesc_table (SIM_CPU *cpu)
init_idesc (cpu, id, t); init_idesc (cpu, id, t);
/* Now fill in the values for the chosen cpu. */ /* Now fill in the values for the chosen cpu. */
for (t = lm32bf_insn_sem, tend = t + sizeof (lm32bf_insn_sem) / sizeof (*t); for (t = lm32bf_insn_sem, tend = t + ARRAY_SIZE (lm32bf_insn_sem);
t != tend; ++t) t != tend; ++t)
{ {
init_idesc (cpu, & table[t->index], t); init_idesc (cpu, & table[t->index], t);

View File

@ -1,3 +1,8 @@
2017-02-13 Mike Frysinger <vapier@gentoo.org>
* srcdest.c: Include libiberty.h.
(decode_sd23): Use ARRAY_SIZE.
2016-01-10 Mike Frysinger <vapier@gentoo.org> 2016-01-10 Mike Frysinger <vapier@gentoo.org>
* config.in, configure: Regenerate. * config.in, configure: Regenerate.

View File

@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "libiberty.h"
#include "cpu.h" #include "cpu.h"
#include "mem.h" #include "mem.h"
@ -354,7 +355,7 @@ decode_sd23 (int bbb, int bb, int bytes, int ind, int add)
srcdest sd; srcdest sd;
int code = (bbb << 2) | bb; int code = (bbb << 2) | bb;
if (code >= sizeof (modes23) / sizeof (modes23[0])) if (code >= ARRAY_SIZE (modes23))
abort (); abort ();
if (trace) if (trace)

View File

@ -1,3 +1,9 @@
2017-02-13 Mike Frysinger <vapier@gentoo.org>
* decode.c (m32rbf_init_idesc_table): Use ARRAY_SIZE.
* decode2.c (m32r2f_init_idesc_table): Likewise.
* decodex.c (m32rxf_init_idesc_table): Likewise.
2016-01-10 Mike Frysinger <vapier@gentoo.org> 2016-01-10 Mike Frysinger <vapier@gentoo.org>
* config.in, configure: Regenerate. * config.in, configure: Regenerate.

View File

@ -202,7 +202,7 @@ m32rbf_init_idesc_table (SIM_CPU *cpu)
init_idesc (cpu, id, t); init_idesc (cpu, id, t);
/* Now fill in the values for the chosen cpu. */ /* Now fill in the values for the chosen cpu. */
for (t = m32rbf_insn_sem, tend = t + sizeof (m32rbf_insn_sem) / sizeof (*t); for (t = m32rbf_insn_sem, tend = t + ARRAY_SIZE (m32rbf_insn_sem);
t != tend; ++t) t != tend; ++t)
{ {
init_idesc (cpu, & table[t->index], t); init_idesc (cpu, & table[t->index], t);

View File

@ -235,7 +235,7 @@ m32r2f_init_idesc_table (SIM_CPU *cpu)
init_idesc (cpu, id, t); init_idesc (cpu, id, t);
/* Now fill in the values for the chosen cpu. */ /* Now fill in the values for the chosen cpu. */
for (t = m32r2f_insn_sem, tend = t + sizeof (m32r2f_insn_sem) / sizeof (*t); for (t = m32r2f_insn_sem, tend = t + ARRAY_SIZE (m32r2f_insn_sem);
t != tend; ++t) t != tend; ++t)
{ {
init_idesc (cpu, & table[t->index], t); init_idesc (cpu, & table[t->index], t);

View File

@ -228,7 +228,7 @@ m32rxf_init_idesc_table (SIM_CPU *cpu)
init_idesc (cpu, id, t); init_idesc (cpu, id, t);
/* Now fill in the values for the chosen cpu. */ /* Now fill in the values for the chosen cpu. */
for (t = m32rxf_insn_sem, tend = t + sizeof (m32rxf_insn_sem) / sizeof (*t); for (t = m32rxf_insn_sem, tend = t + ARRAY_SIZE (m32rxf_insn_sem);
t != tend; ++t) t != tend; ++t)
{ {
init_idesc (cpu, & table[t->index], t); init_idesc (cpu, & table[t->index], t);

View File

@ -1,3 +1,12 @@
2017-02-13 Mike Frysinger <vapier@gentoo.org>
* gencode.c: Include libiberty.h.
(TABLE_SIZE): Delete.
(find_opcode_pattern): Change TABLE_SIZE to ARRAY_SIZE.
(gen_interpreter): Likewise.
* interrupts.c (TableSize): Delete.
(interrupts_update_pending): Change TableSize to ARRAY_SIZE.
2016-08-16 Mike Frysinger <vapier@gentoo.org> 2016-08-16 Mike Frysinger <vapier@gentoo.org>
* sim-main.h (inline): Delete define. * sim-main.h (inline): Delete define.

View File

@ -24,10 +24,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <errno.h> #include <errno.h>
#include "ansidecl.h" #include "ansidecl.h"
#include "libiberty.h"
#include "opcode/m68hc11.h" #include "opcode/m68hc11.h"
#define TABLE_SIZE(X) (sizeof(X) / sizeof(X[0]))
/* Combination of CCR flags. */ /* Combination of CCR flags. */
#define M6811_ZC_BIT M6811_Z_BIT|M6811_C_BIT #define M6811_ZC_BIT M6811_Z_BIT|M6811_C_BIT
#define M6811_NZ_BIT M6811_N_BIT|M6811_Z_BIT #define M6811_NZ_BIT M6811_N_BIT|M6811_Z_BIT
@ -1812,7 +1811,7 @@ find_opcode_pattern (const struct m6811_opcode_def *opcode)
{ {
pattern = opcode->name; pattern = opcode->name;
} }
for (i = 0; i < TABLE_SIZE(m6811_opcode_patterns); i++) for (i = 0; i < ARRAY_SIZE (m6811_opcode_patterns); i++)
{ {
if (strcmp (m6811_opcode_patterns[i].name, pattern) == 0) if (strcmp (m6811_opcode_patterns[i].name, pattern) == 0)
{ {
@ -2036,13 +2035,13 @@ gen_interpreter (FILE *fp)
{ {
int col = 0; int col = 0;
prepare_table (m6811_page1_opcodes, TABLE_SIZE (m6811_page1_opcodes)); prepare_table (m6811_page1_opcodes, ARRAY_SIZE (m6811_page1_opcodes));
prepare_table (m6811_page2_opcodes, TABLE_SIZE (m6811_page2_opcodes)); prepare_table (m6811_page2_opcodes, ARRAY_SIZE (m6811_page2_opcodes));
prepare_table (m6811_page3_opcodes, TABLE_SIZE (m6811_page3_opcodes)); prepare_table (m6811_page3_opcodes, ARRAY_SIZE (m6811_page3_opcodes));
prepare_table (m6811_page4_opcodes, TABLE_SIZE (m6811_page4_opcodes)); prepare_table (m6811_page4_opcodes, ARRAY_SIZE (m6811_page4_opcodes));
prepare_table (m6812_page1_opcodes, TABLE_SIZE (m6812_page1_opcodes)); prepare_table (m6812_page1_opcodes, ARRAY_SIZE (m6812_page1_opcodes));
prepare_table (m6812_page2_opcodes, TABLE_SIZE (m6812_page2_opcodes)); prepare_table (m6812_page2_opcodes, ARRAY_SIZE (m6812_page2_opcodes));
/* Generate header of interpretor. */ /* Generate header of interpretor. */
print (fp, col, "/* File generated automatically by gencode. */\n"); print (fp, col, "/* File generated automatically by gencode. */\n");
@ -2051,25 +2050,25 @@ gen_interpreter (FILE *fp)
if (cpu_type & cpu6811) if (cpu_type & cpu6811)
{ {
gen_cycle_table (fp, "cycles_page1", m6811_page1_opcodes, gen_cycle_table (fp, "cycles_page1", m6811_page1_opcodes,
TABLE_SIZE (m6811_page1_opcodes)); ARRAY_SIZE (m6811_page1_opcodes));
gen_cycle_table (fp, "cycles_page2", m6811_page2_opcodes, gen_cycle_table (fp, "cycles_page2", m6811_page2_opcodes,
TABLE_SIZE (m6811_page2_opcodes)); ARRAY_SIZE (m6811_page2_opcodes));
gen_cycle_table (fp, "cycles_page3", m6811_page3_opcodes, gen_cycle_table (fp, "cycles_page3", m6811_page3_opcodes,
TABLE_SIZE (m6811_page3_opcodes)); ARRAY_SIZE (m6811_page3_opcodes));
gen_cycle_table (fp, "cycles_page4", m6811_page4_opcodes, gen_cycle_table (fp, "cycles_page4", m6811_page4_opcodes,
TABLE_SIZE (m6811_page4_opcodes)); ARRAY_SIZE (m6811_page4_opcodes));
gen_function_entry (fp, "static void\ncpu_page3_interp", 0); gen_function_entry (fp, "static void\ncpu_page3_interp", 0);
gen_interpreter_for_table (fp, indent_level, gen_interpreter_for_table (fp, indent_level,
m6811_page3_opcodes, m6811_page3_opcodes,
TABLE_SIZE(m6811_page3_opcodes), ARRAY_SIZE (m6811_page3_opcodes),
"cycles_page3"); "cycles_page3");
gen_function_close (fp); gen_function_close (fp);
gen_function_entry (fp, "static void\ncpu_page4_interp", 0); gen_function_entry (fp, "static void\ncpu_page4_interp", 0);
gen_interpreter_for_table (fp, indent_level, gen_interpreter_for_table (fp, indent_level,
m6811_page4_opcodes, m6811_page4_opcodes,
TABLE_SIZE(m6811_page4_opcodes), ARRAY_SIZE (m6811_page4_opcodes),
"cycles_page4"); "cycles_page4");
gen_function_close (fp); gen_function_close (fp);
@ -2078,7 +2077,7 @@ gen_interpreter (FILE *fp)
USE_SRC8 | USE_DST8); USE_SRC8 | USE_DST8);
gen_interpreter_for_table (fp, indent_level, gen_interpreter_for_table (fp, indent_level,
m6811_page2_opcodes, m6811_page2_opcodes,
TABLE_SIZE(m6811_page2_opcodes), ARRAY_SIZE (m6811_page2_opcodes),
"cycles_page2"); "cycles_page2");
gen_function_close (fp); gen_function_close (fp);
@ -2087,22 +2086,22 @@ gen_interpreter (FILE *fp)
USE_SRC8 | USE_DST8); USE_SRC8 | USE_DST8);
gen_interpreter_for_table (fp, indent_level, m6811_page1_opcodes, gen_interpreter_for_table (fp, indent_level, m6811_page1_opcodes,
TABLE_SIZE(m6811_page1_opcodes), ARRAY_SIZE (m6811_page1_opcodes),
"cycles_page1"); "cycles_page1");
gen_function_close (fp); gen_function_close (fp);
} }
else else
{ {
gen_cycle_table (fp, "cycles_page1", m6812_page1_opcodes, gen_cycle_table (fp, "cycles_page1", m6812_page1_opcodes,
TABLE_SIZE (m6812_page1_opcodes)); ARRAY_SIZE (m6812_page1_opcodes));
gen_cycle_table (fp, "cycles_page2", m6812_page2_opcodes, gen_cycle_table (fp, "cycles_page2", m6812_page2_opcodes,
TABLE_SIZE (m6812_page2_opcodes)); ARRAY_SIZE (m6812_page2_opcodes));
gen_function_entry (fp, "static void\ncpu_page2_interp", gen_function_entry (fp, "static void\ncpu_page2_interp",
USE_SRC8 | USE_DST8); USE_SRC8 | USE_DST8);
gen_interpreter_for_table (fp, indent_level, gen_interpreter_for_table (fp, indent_level,
m6812_page2_opcodes, m6812_page2_opcodes,
TABLE_SIZE(m6812_page2_opcodes), ARRAY_SIZE (m6812_page2_opcodes),
"cycles_page2"); "cycles_page2");
gen_function_close (fp); gen_function_close (fp);
@ -2111,7 +2110,7 @@ gen_interpreter (FILE *fp)
USE_SRC8 | USE_DST8); USE_SRC8 | USE_DST8);
gen_interpreter_for_table (fp, indent_level, m6812_page1_opcodes, gen_interpreter_for_table (fp, indent_level, m6812_page1_opcodes,
TABLE_SIZE(m6812_page1_opcodes), ARRAY_SIZE (m6812_page1_opcodes),
"cycles_page1"); "cycles_page1");
gen_function_close (fp); gen_function_close (fp);
} }

View File

@ -91,7 +91,6 @@ struct interrupt_def idefs[] = {
#endif #endif
}; };
#define TableSize(X) (sizeof X / sizeof(X[0]))
#define CYCLES_MAX ((((signed64) 1) << 62) - 1) #define CYCLES_MAX ((((signed64) 1) << 62) - 1)
enum enum
@ -290,7 +289,7 @@ interrupts_update_pending (struct interrupts *interrupts)
set_mask = 0; set_mask = 0;
ioregs = &interrupts->cpu->ios[0]; ioregs = &interrupts->cpu->ios[0];
for (i = 0; i < TableSize(idefs); i++) for (i = 0; i < ARRAY_SIZE (idefs); i++)
{ {
struct interrupt_def *idef = &idefs[i]; struct interrupt_def *idef = &idefs[i];
uint8 data; uint8 data;

View File

@ -1,3 +1,15 @@
2017-02-13 Mike Frysinger <vapier@gentoo.org>
* cpu.h: Include libiberty.h.
* emul_bugapi.c (emul_bugapi_instruction_name): Use ARRAY_SIZE.
* emul_generic.h: Include libiberty.h.
* emul_netbsd.c (emul_netbsd_syscalls): Use ARRAY_SIZE.
* emul_unix.c (convert_to_solaris_stat): Likewise.
(emul_solaris_syscalls): Likewise.
(emul_linux_syscalls): Likewise.
* options.c (print_options): Likewise.
* ppc-instructions: Likewise.
2016-01-10 Mike Frysinger <vapier@gentoo.org> 2016-01-10 Mike Frysinger <vapier@gentoo.org>
* configure.ac (sim-assert): Call AC_MSG_CHECKING, * configure.ac (sim-assert): Call AC_MSG_CHECKING,

View File

@ -34,6 +34,7 @@
#include "os_emul.h" #include "os_emul.h"
#include "mon.h" #include "mon.h"
#include "model.h" #include "model.h"
#include "libiberty.h"
#ifndef CONST_ATTRIBUTE #ifndef CONST_ATTRIBUTE
#define CONST_ATTRIBUTE __attribute__((__const__)) #define CONST_ATTRIBUTE __attribute__((__const__))

View File

@ -339,7 +339,7 @@ emul_bugapi_instruction_name(int call_id)
static char buffer[40]; static char buffer[40];
int i; int i;
for (i = 0; i < sizeof (bug_mapping) / sizeof (bug_mapping[0]); i++) for (i = 0; i < ARRAY_SIZE (bug_mapping); i++)
{ {
if (bug_mapping[i].value == call_id) if (bug_mapping[i].value == call_id)
return bug_mapping[i].info; return bug_mapping[i].info;

View File

@ -28,6 +28,7 @@
#include "tree.h" #include "tree.h"
#include "bfd.h" #include "bfd.h"
#include "libiberty.h"
#ifndef INLINE_EMUL_GENERIC #ifndef INLINE_EMUL_GENERIC
#define INLINE_EMUL_GENERIC #define INLINE_EMUL_GENERIC

View File

@ -1413,11 +1413,11 @@ static char *(netbsd_signal_names[]) = {
static emul_syscall emul_netbsd_syscalls = { static emul_syscall emul_netbsd_syscalls = {
netbsd_descriptors, netbsd_descriptors,
sizeof(netbsd_descriptors) / sizeof(netbsd_descriptors[0]), ARRAY_SIZE (netbsd_descriptors),
netbsd_error_names, netbsd_error_names,
sizeof(netbsd_error_names) / sizeof(netbsd_error_names[0]), ARRAY_SIZE (netbsd_error_names),
netbsd_signal_names, netbsd_signal_names,
sizeof(netbsd_signal_names) / sizeof(netbsd_signal_names[0]), ARRAY_SIZE (netbsd_signal_names),
}; };

View File

@ -1147,15 +1147,15 @@ convert_to_solaris_stat(unsigned_word addr,
target.st_mtim.tv_sec = H2T_4(host->st_mtime); target.st_mtim.tv_sec = H2T_4(host->st_mtime);
target.st_mtim.tv_usec = 0; target.st_mtim.tv_usec = 0;
for (i = 0; i < sizeof (target.st_pad1) / sizeof (target.st_pad1[0]); i++) for (i = 0; i < ARRAY_SIZE (target.st_pad1); i++)
target.st_pad1[i] = 0; target.st_pad1[i] = 0;
for (i = 0; i < sizeof (target.st_pad2) / sizeof (target.st_pad2[0]); i++) for (i = 0; i < ARRAY_SIZE (target.st_pad2); i++)
target.st_pad2[i] = 0; target.st_pad2[i] = 0;
target.st_pad3 = 0; target.st_pad3 = 0;
for (i = 0; i < sizeof (target.st_pad4) / sizeof (target.st_pad4[0]); i++) for (i = 0; i < ARRAY_SIZE (target.st_pad4); i++)
target.st_pad4[i] = 0; target.st_pad4[i] = 0;
/* For now, just punt and always say it is a ufs file */ /* For now, just punt and always say it is a ufs file */
@ -1945,11 +1945,11 @@ static char *(solaris_signal_names[]) = {
static emul_syscall emul_solaris_syscalls = { static emul_syscall emul_solaris_syscalls = {
solaris_descriptors, solaris_descriptors,
sizeof(solaris_descriptors) / sizeof(solaris_descriptors[0]), ARRAY_SIZE (solaris_descriptors),
solaris_error_names, solaris_error_names,
sizeof(solaris_error_names) / sizeof(solaris_error_names[0]), ARRAY_SIZE (solaris_error_names),
solaris_signal_names, solaris_signal_names,
sizeof(solaris_signal_names) / sizeof(solaris_signal_names[0]), ARRAY_SIZE (solaris_signal_names),
}; };
@ -2824,11 +2824,11 @@ static char *(linux_signal_names[]) = {
static emul_syscall emul_linux_syscalls = { static emul_syscall emul_linux_syscalls = {
linux_descriptors, linux_descriptors,
sizeof(linux_descriptors) / sizeof(linux_descriptors[0]), ARRAY_SIZE (linux_descriptors),
linux_error_names, linux_error_names,
sizeof(linux_error_names) / sizeof(linux_error_names[0]), ARRAY_SIZE (linux_error_names),
linux_signal_names, linux_signal_names,
sizeof(linux_signal_names) / sizeof(linux_signal_names[0]), ARRAY_SIZE (linux_signal_names),
}; };

View File

@ -216,7 +216,7 @@ print_options (void)
int max_len = 0; int max_len = 0;
int cols; int cols;
for (i = 0; i < sizeof (defines) / sizeof (defines[0]); i++) { for (i = 0; i < ARRAY_SIZE (defines); i++) {
int len = strlen (defines[i]); int len = strlen (defines[i]);
if (len > max_len) if (len > max_len)
max_len = len; max_len = len;
@ -227,10 +227,10 @@ print_options (void)
cols = 1; cols = 1;
printf_filtered ("\n#defines:"); printf_filtered ("\n#defines:");
for (i = 0; i < sizeof (defines) / sizeof (defines[0]); i++) { for (i = 0; i < ARRAY_SIZE (defines); i++) {
const char *const prefix = ((i % cols) == 0) ? "\n" : ""; const char *const prefix = ((i % cols) == 0) ? "\n" : "";
printf_filtered ("%s %s%*s", prefix, defines[i], printf_filtered ("%s %s%*s", prefix, defines[i],
(((i == (sizeof (defines) / sizeof (defines[0])) - 1) (((i == ARRAY_SIZE (defines) - 1)
|| (((i + 1) % cols) == 0)) || (((i + 1) % cols) == 0))
? 0 ? 0
: max_len + 4 - strlen (defines[i])), : max_len + 4 - strlen (defines[i])),

View File

@ -908,7 +908,7 @@ model_print *::model-function::model_mon_info:model_data *model_ptr
tail->suffix_singular = ""; tail->suffix_singular = "";
} }
for (j = 0; j < (sizeof(ppc_branch_conditional_name) / sizeof(ppc_branch_conditional_name[0])) ; j++) { for (j = 0; j < ARRAY_SIZE (ppc_branch_conditional_name); j++) {
if (model_ptr->nr_branch_conditional[j]) { if (model_ptr->nr_branch_conditional[j]) {
tail->next = ZALLOC(model_print); tail->next = ZALLOC(model_print);
tail = tail->next; tail = tail->next;

View File

@ -1,3 +1,8 @@
2017-02-13 Mike Frysinger <vapier@gentoo.org>
* rx.c: Include libiberty.h.
(N_RXO, N_RXT): Use ARRAY_SIZE.
2016-07-27 Alan Modra <amodra@gmail.com> 2016-07-27 Alan Modra <amodra@gmail.com>
* load.c: Don't include libbfd.h. * load.c: Don't include libbfd.h.

View File

@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include "libiberty.h"
#include "opcode/rx.h" #include "opcode/rx.h"
#include "cpu.h" #include "cpu.h"
@ -151,8 +152,8 @@ static const char * optype_names[] = {
"RbRi" /* [Rb + scale * Ri] */ "RbRi" /* [Rb + scale * Ri] */
}; };
#define N_RXO (sizeof(id_names)/sizeof(id_names[0])) #define N_RXO ARRAY_SIZE (id_names)
#define N_RXT (sizeof(optype_names)/sizeof(optype_names[0])) #define N_RXT ARRAY_SIZE (optype_names)
#define N_MAP 90 #define N_MAP 90
static unsigned long long benchmark_start_cycle; static unsigned long long benchmark_start_cycle;

View File

@ -1,3 +1,9 @@
2017-02-13 Mike Frysinger <vapier@gentoo.org>
* gencode.c: Include libiberty.h.
(conflict_warn): Use ARRAY_SIZE.
* interp.c (init_dsp): Likewise.
2016-04-10 Oleg Endo <olegendo@gcc.gnu.org> 2016-04-10 Oleg Endo <olegendo@gcc.gnu.org>
* interp.c (dmul): Split into dmul_s and dmul_u. Use explicit integer * interp.c (dmul): Split into dmul_s and dmul_u. Use explicit integer

View File

@ -35,6 +35,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "libiberty.h"
#define MAX_NR_STUFF 42 #define MAX_NR_STUFF 42
@ -2595,7 +2596,7 @@ conflict_warn (int val, int i)
fprintf (stderr, "Warning: opcode table conflict: 0x%04x (idx %d && %d)\n", fprintf (stderr, "Warning: opcode table conflict: 0x%04x (idx %d && %d)\n",
val, i, table[val]); val, i, table[val]);
for (ix = sizeof (tab) / sizeof (tab[0]); ix >= 0; ix--) for (ix = ARRAY_SIZE (tab); ix >= 0; ix--)
if (tab[ix].index == i || tab[ix].index == j) if (tab[ix].index == i || tab[ix].index == j)
{ {
key = ((tab[ix].code[0] - '0') << 3) + key = ((tab[ix].code[0] - '0') << 3) +
@ -2607,7 +2608,7 @@ conflict_warn (int val, int i)
fprintf (stderr, " %s -- %s\n", tab[ix].code, tab[ix].name); fprintf (stderr, " %s -- %s\n", tab[ix].code, tab[ix].name);
} }
for (ix = sizeof (movsxy_tab) / sizeof (movsxy_tab[0]); ix >= 0; ix--) for (ix = ARRAY_SIZE (movsxy_tab); ix >= 0; ix--)
if (movsxy_tab[ix].index == i || movsxy_tab[ix].index == j) if (movsxy_tab[ix].index == i || movsxy_tab[ix].index == j)
{ {
key = ((movsxy_tab[ix].code[0] - '0') << 3) + key = ((movsxy_tab[ix].code[0] - '0') << 3) +
@ -2620,7 +2621,7 @@ conflict_warn (int val, int i)
movsxy_tab[ix].code, movsxy_tab[ix].name); movsxy_tab[ix].code, movsxy_tab[ix].name);
} }
for (ix = sizeof (ppi_tab) / sizeof (ppi_tab[0]); ix >= 0; ix--) for (ix = ARRAY_SIZE (ppi_tab); ix >= 0; ix--)
if (ppi_tab[ix].index == i || ppi_tab[ix].index == j) if (ppi_tab[ix].index == i || ppi_tab[ix].index == j)
{ {
key = ((ppi_tab[ix].code[0] - '0') << 3) + key = ((ppi_tab[ix].code[0] - '0') << 3) +

View File

@ -1658,7 +1658,7 @@ init_dsp (struct bfd *abfd)
{ {
int i, tmp; int i, tmp;
for (i = (sizeof sh_dsp_table / sizeof sh_dsp_table[0]) - 1; i >= 0; i--) for (i = ARRAY_SIZE (sh_dsp_table) - 1; i >= 0; i--)
{ {
tmp = sh_jump_table[0xf000 + i]; tmp = sh_jump_table[0xf000 + i];
sh_jump_table[0xf000 + i] = sh_dsp_table[i]; sh_jump_table[0xf000 + i] = sh_dsp_table[i];

View File

@ -1,3 +1,8 @@
2017-02-13 Mike Frysinger <vapier@gentoo.org>
* decode-compact.c (sh64_compact_init_idesc_table): Use ARRAY_SIZE.
* decode-media.c (sh64_media_init_idesc_table): Likewise.
2016-01-10 Mike Frysinger <vapier@gentoo.org> 2016-01-10 Mike Frysinger <vapier@gentoo.org>
* config.in, configure: Regenerate. * config.in, configure: Regenerate.

View File

@ -292,7 +292,7 @@ sh64_compact_init_idesc_table (SIM_CPU *cpu)
init_idesc (cpu, id, t); init_idesc (cpu, id, t);
/* Now fill in the values for the chosen cpu. */ /* Now fill in the values for the chosen cpu. */
for (t = sh64_compact_insn_sem, tend = t + sizeof (sh64_compact_insn_sem) / sizeof (*t); for (t = sh64_compact_insn_sem, tend = t + ARRAY_SIZE (sh64_compact_insn_sem);
t != tend; ++t) t != tend; ++t)
{ {
init_idesc (cpu, & table[t->index], t); init_idesc (cpu, & table[t->index], t);

View File

@ -306,7 +306,7 @@ sh64_media_init_idesc_table (SIM_CPU *cpu)
init_idesc (cpu, id, t); init_idesc (cpu, id, t);
/* Now fill in the values for the chosen cpu. */ /* Now fill in the values for the chosen cpu. */
for (t = sh64_media_insn_sem, tend = t + sizeof (sh64_media_insn_sem) / sizeof (*t); for (t = sh64_media_insn_sem, tend = t + ARRAY_SIZE (sh64_media_insn_sem);
t != tend; ++t) t != tend; ++t)
{ {
init_idesc (cpu, & table[t->index], t); init_idesc (cpu, & table[t->index], t);