* [PATCH 2/3] tc-pdp11.c: remove useless code
2016-03-20 19:41 [PATCH 1/3] tc-sparc.c: get rid of wierd usage of strchr () tbsaunde+binutils
@ 2016-03-20 19:41 ` tbsaunde+binutils
2016-03-22 16:31 ` Nick Clifton
2016-03-20 19:41 ` [PATCH 3/3] make more variables const tbsaunde+binutils
2016-03-22 16:29 ` [PATCH 1/3] tc-sparc.c: get rid of wierd usage of strchr () Nick Clifton
2 siblings, 1 reply; 6+ messages in thread
From: tbsaunde+binutils @ 2016-03-20 19:41 UTC (permalink / raw)
To: binutils; +Cc: Trevor Saunders
From: Trevor Saunders <tbsaunde+binutils@tbsaunde.org>
HI,
if the condition is true then we know that str already points to a'\0' in the
string passed to the function. Since we know the latter part of the function
doesn't modify that string, and str already points to a null byte there's no
point in changing str to point to a literal empty string.
built and regtested a cross to pdp11-aout, ok?
Trev
gas/ChangeLog:
2016-03-20 Trevor Saunders <tbsaunde+binutils@tbsaunde.org>
* config/tc-pdp11.c (md_assemble): Remove useless if and assignment to
str.
---
gas/config/tc-pdp11.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/gas/config/tc-pdp11.c b/gas/config/tc-pdp11.c
index 89c75c3..f144754 100644
--- a/gas/config/tc-pdp11.c
+++ b/gas/config/tc-pdp11.c
@@ -697,8 +697,6 @@ md_assemble (char *instruction_string)
{
case PDP11_OPCODE_NO_OPS:
str = skip_whitespace (str);
- if (*str == 0)
- str = "";
break;
case PDP11_OPCODE_IMM3:
--
2.1.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] tc-sparc.c: get rid of wierd usage of strchr ()
@ 2016-03-20 19:41 tbsaunde+binutils
2016-03-20 19:41 ` [PATCH 2/3] tc-pdp11.c: remove useless code tbsaunde+binutils
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: tbsaunde+binutils @ 2016-03-20 19:41 UTC (permalink / raw)
To: binutils; +Cc: Trevor Saunders
From: Trevor Saunders <tbsaunde+binutils@tbsaunde.org>
Hi,
This lets us avoid assigning a literal to a char *, and perhaps more
importantly makes it clearer what is going on here.
built and regtested a cross to sparc64-elf without regression, ok?
Trev
gas/ChangeLog:
2016-03-20 Trevor Saunders <tbsaunde+binutils@tbsaunde.org>
* config/tc-sparc.c (sparc_regname_to_dw2regnum): Replace strchr ()
call with a switch.
---
gas/config/tc-sparc.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/gas/config/tc-sparc.c b/gas/config/tc-sparc.c
index cac5d18..5d4e0d6 100644
--- a/gas/config/tc-sparc.c
+++ b/gas/config/tc-sparc.c
@@ -4829,18 +4829,25 @@ sparc_cfi_frame_initial_instructions (void)
int
sparc_regname_to_dw2regnum (char *regname)
{
- char *p, *q;
+ char *q;
+ int i;
if (!regname[0])
return -1;
- q = "goli";
- p = strchr (q, regname[0]);
- if (p)
+ switch (regname[0])
+ {
+ case 'g': i = 0; break;
+ case 'o': i = 1; break;
+ case 'l': i = 2; break;
+ case 'i': i = 3; break;
+ default: i = -1; break;
+ }
+ if (i != -1)
{
if (regname[1] < '0' || regname[1] > '8' || regname[2])
return -1;
- return (p - q) * 8 + regname[1] - '0';
+ return i * 8 + regname[1] - '0';
}
if (regname[0] == 's' && regname[1] == 'p' && !regname[2])
return 14;
@@ -4851,7 +4858,7 @@ sparc_regname_to_dw2regnum (char *regname)
unsigned int regnum;
regnum = strtoul (regname + 1, &q, 10);
- if (p == q || *q)
+ if (q == NULL || *q)
return -1;
if (regnum >= ((regname[0] == 'f'
&& SPARC_OPCODE_ARCH_V9_P (max_architecture))
--
2.1.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] make more variables const
2016-03-20 19:41 [PATCH 1/3] tc-sparc.c: get rid of wierd usage of strchr () tbsaunde+binutils
2016-03-20 19:41 ` [PATCH 2/3] tc-pdp11.c: remove useless code tbsaunde+binutils
@ 2016-03-20 19:41 ` tbsaunde+binutils
2016-03-22 16:33 ` Nick Clifton
2016-03-22 16:29 ` [PATCH 1/3] tc-sparc.c: get rid of wierd usage of strchr () Nick Clifton
2 siblings, 1 reply; 6+ messages in thread
From: tbsaunde+binutils @ 2016-03-20 19:41 UTC (permalink / raw)
To: binutils; +Cc: Trevor Saunders
From: Trevor Saunders <tbsaunde+binutils@tbsaunde.org>
Hi,
not very interesting, basically just adding a bunch of const.
built and regtested on x86_64-linux-gnu, and built one target per tc-*.c, ok?
Trev
gas/ChangeLog:
2016-03-20 Trevor Saunders <tbsaunde+binutils@tbsaunde.org>
* config/tc-h8300.c (h8300_elf_section): Add const qualifiers.
* config/tc-ia64.c (obj_elf_vms_common): Likewise.
* config/tc-m68hc11.c (md_begin): Likewise.
(print_opcode_list): Likewise.
* config/tc-msp430.c (msp430_section): Likewise.
* config/tc-score.c (struct s3_insn_to_dependency): Likewise.
(s3_build_dependency_insn_hsh): Likewise.
* config/tc-score7.c (struct s7_insn_to_dependency): Likewise.
(s7_build_dependency_insn_hsh): Likewise.
* config/tc-tic4x.c: Likewise.
* config/tc-tic54x.c (tic54x_set_default_include): Likewise.
(subsym_get_arg): Likewise.
* config/tc-xtensa.c (struct suffix_reloc_map): Likewise.
(get_directive): Likewise.
(cache_literal_section): Likewise.
* config/xtensa-relax.c: Likewise.
* symbols.c (symbol_create): Likewise.
(local_symbol_make): Likewise.
(symbol_relc_make_expr): Likewise.
include/ChangeLog:
2016-03-20 Trevor Saunders <tbsaunde+binutils@tbsaunde.org>
* opcode/i960.h: Add const qualifiers.
* opcode/tic4x.h (struct tic4x_inst): Likewise.
---
gas/config/tc-h8300.c | 2 +-
gas/config/tc-ia64.c | 2 +-
gas/config/tc-m68hc11.c | 4 ++--
gas/config/tc-msp430.c | 2 +-
gas/config/tc-score.c | 9 +++++----
gas/config/tc-score7.c | 9 +++++----
gas/config/tc-tic4x.c | 2 +-
gas/config/tc-tic54x.c | 10 +++++-----
gas/config/tc-xtensa.c | 13 +++++++------
gas/config/xtensa-relax.c | 2 +-
gas/symbols.c | 10 +++++-----
include/opcode/i960.h | 2 +-
include/opcode/tic4x.h | 2 +-
13 files changed, 36 insertions(+), 33 deletions(-)
diff --git a/gas/config/tc-h8300.c b/gas/config/tc-h8300.c
index 1b075c4..a620e6d 100644
--- a/gas/config/tc-h8300.c
+++ b/gas/config/tc-h8300.c
@@ -152,7 +152,7 @@ h8300_elf_section (int push)
static const char * known_data_sections [] = { ".rodata", ".tdata", ".tbss" };
static const char * known_data_prefixes [] = { ".debug", ".zdebug", ".gnu.warning" };
char * saved_ilp = input_line_pointer;
- char * name;
+ const char * name;
name = obj_elf_section_name ();
if (name == NULL)
diff --git a/gas/config/tc-ia64.c b/gas/config/tc-ia64.c
index e43a7f9..76d3a46 100644
--- a/gas/config/tc-ia64.c
+++ b/gas/config/tc-ia64.c
@@ -1054,7 +1054,7 @@ ia64_cons_align (int nbytes)
static void
obj_elf_vms_common (int ignore ATTRIBUTE_UNUSED)
{
- char *sec_name;
+ const char *sec_name;
char *sym_name;
char c;
offsetT size;
diff --git a/gas/config/tc-m68hc11.c b/gas/config/tc-m68hc11.c
index 05992ef..54ece5f 100644
--- a/gas/config/tc-m68hc11.c
+++ b/gas/config/tc-m68hc11.c
@@ -603,7 +603,7 @@ cmp_opcode (struct m68hc11_opcode *op1, struct m68hc11_opcode *op2)
void
md_begin (void)
{
- char *prev_name = "";
+ const char *prev_name = "";
struct m68hc11_opcode *opcodes;
struct m68hc11_opcode_def *opc = 0;
int i, j;
@@ -964,7 +964,7 @@ static void
print_opcode_list (void)
{
int i;
- char *prev_name = "";
+ const char *prev_name = "";
struct m68hc11_opcode *opcodes;
int example = flag_print_opcodes == 2;
diff --git a/gas/config/tc-msp430.c b/gas/config/tc-msp430.c
index eb7df08..ee14d20 100644
--- a/gas/config/tc-msp430.c
+++ b/gas/config/tc-msp430.c
@@ -1497,7 +1497,7 @@ static void
msp430_section (int arg)
{
char * saved_ilp = input_line_pointer;
- char * name = obj_elf_section_name ();
+ const char * name = obj_elf_section_name ();
msp430_make_init_symbols (name);
diff --git a/gas/config/tc-score.c b/gas/config/tc-score.c
index fadae49..ee195e2 100644
--- a/gas/config/tc-score.c
+++ b/gas/config/tc-score.c
@@ -334,7 +334,7 @@ enum s3_insn_type_for_dependency
struct s3_insn_to_dependency
{
- char *insn_name;
+ const char *insn_name;
enum s3_insn_type_for_dependency type;
};
@@ -6344,14 +6344,15 @@ s3_build_dependency_insn_hsh (void)
const struct s3_insn_to_dependency *tmp = s3_insn_to_dependency_table + i;
size_t len = strlen (tmp->insn_name);
struct s3_insn_to_dependency *new_i2n;
+ char *buf;
new_i2n = (struct s3_insn_to_dependency *)
obstack_alloc (&dependency_obstack,
sizeof (struct s3_insn_to_dependency));
- new_i2n->insn_name = (char *) obstack_alloc (&dependency_obstack,
- len + 1);
+ buf = (char *) obstack_alloc (&dependency_obstack, len + 1);
- strcpy (new_i2n->insn_name, tmp->insn_name);
+ strcpy (buf, tmp->insn_name);
+ new_i2n->insn_name = buf;
new_i2n->type = tmp->type;
hash_insert (s3_dependency_insn_hsh, new_i2n->insn_name,
(void *) new_i2n);
diff --git a/gas/config/tc-score7.c b/gas/config/tc-score7.c
index 6070589..97dfea2 100644
--- a/gas/config/tc-score7.c
+++ b/gas/config/tc-score7.c
@@ -191,7 +191,7 @@ enum s7_insn_type_for_dependency
struct s7_insn_to_dependency
{
- char *insn_name;
+ const char *insn_name;
enum s7_insn_type_for_dependency type;
};
@@ -5121,14 +5121,15 @@ s7_build_dependency_insn_hsh (void)
const struct s7_insn_to_dependency *tmp = s7_insn_to_dependency_table + i;
size_t len = strlen (tmp->insn_name);
struct s7_insn_to_dependency *new_i2d;
+ char *insn_name;
new_i2d = (struct s7_insn_to_dependency *)
obstack_alloc (&dependency_obstack,
sizeof (struct s7_insn_to_dependency));
- new_i2d->insn_name = (char *) obstack_alloc (&dependency_obstack,
- len + 1);
+ insn_name = (char *) obstack_alloc (&dependency_obstack, len + 1);
- strcpy (new_i2d->insn_name, tmp->insn_name);
+ strcpy (insn_name, tmp->insn_name);
+ new_i2d->insn_name = insn_name;
new_i2d->type = tmp->type;
hash_insert (s7_dependency_insn_hsh, new_i2d->insn_name,
(void *) new_i2d);
diff --git a/gas/config/tc-tic4x.c b/gas/config/tc-tic4x.c
index 0905658..21e6e36 100644
--- a/gas/config/tc-tic4x.c
+++ b/gas/config/tc-tic4x.c
@@ -1239,7 +1239,7 @@ tic4x_inst_insert (const tic4x_inst_t *inst)
/* Make a new instruction template. */
static tic4x_inst_t *
-tic4x_inst_make (const char *name, unsigned long opcode, char *args)
+tic4x_inst_make (const char *name, unsigned long opcode, const char *args)
{
static tic4x_inst_t *insts = NULL;
static char *names = NULL;
diff --git a/gas/config/tc-tic54x.c b/gas/config/tc-tic54x.c
index e071f95..050aa84 100644
--- a/gas/config/tc-tic54x.c
+++ b/gas/config/tc-tic54x.c
@@ -1871,7 +1871,7 @@ tic54x_clink (int ignored ATTRIBUTE_UNUSED)
static void
tic54x_set_default_include (int dot)
{
- char *dir = ".";
+ const char *dir = ".";
char *tmp = NULL;
if (!dot)
@@ -2912,7 +2912,7 @@ math_tanh (float arg1, float ignore ATTRIBUTE_UNUSED)
/* Built-in substitution symbol functions and math functions. */
typedef struct
{
- char *name;
+ const char *name;
int (*proc) (char *, char *);
int nargs;
} subsym_proc_entry;
@@ -2936,7 +2936,7 @@ static const subsym_proc_entry subsym_procs[] =
typedef struct
{
- char *name;
+ const char *name;
float (*proc) (float, float);
int nargs;
int int_return;
@@ -4296,7 +4296,7 @@ tic54x_parse_parallel_insn_lastline (tic54x_insn *insn, char *line)
replacement on the value. */
static char *
-subsym_get_arg (char *line, char *terminators, char **str, int nosub)
+subsym_get_arg (char *line, const char *terminators, char **str, int nosub)
{
char *ptr = line;
char *endp;
@@ -4328,7 +4328,7 @@ subsym_get_arg (char *line, char *terminators, char **str, int nosub)
}
else
{
- char *term = terminators;
+ const char *term = terminators;
char *value = NULL;
while (*ptr && *ptr != *term)
diff --git a/gas/config/tc-xtensa.c b/gas/config/tc-xtensa.c
index d995131..180181c 100644
--- a/gas/config/tc-xtensa.c
+++ b/gas/config/tc-xtensa.c
@@ -361,7 +361,7 @@ op_placement_info_table op_placement_table;
struct suffix_reloc_map
{
- char *suffix;
+ const char *suffix;
int length;
bfd_reloc_code_real_type reloc;
unsigned char operator;
@@ -1244,7 +1244,7 @@ get_directive (directiveE *directive, bfd_boolean *negated)
{
int len;
unsigned i;
- char *directive_string;
+ const char *directive_string;
if (strncmp (input_line_pointer, "no-", 3) != 0)
*negated = FALSE;
@@ -2269,7 +2269,7 @@ xg_arg_is_constant (char *arg, offsetT *valp)
static void
-xg_replace_opname (char **popname, char *newop)
+xg_replace_opname (char **popname, const char *newop)
{
free (*popname);
*popname = (char *) xmalloc (strlen (newop) + 1);
@@ -2439,8 +2439,8 @@ xtensa_translate_old_userreg_ops (char **popname)
static int
-xtensa_translate_zero_immed (char *old_op,
- char *new_op,
+xtensa_translate_zero_immed (const char *old_op,
+ const char *new_op,
char **popname,
int *pnum_args,
char **arg_strings)
@@ -11518,7 +11518,8 @@ static segT
cache_literal_section (bfd_boolean use_abs_literals)
{
const char *text_name, *group_name = 0;
- char *base_name, *name, *suffix;
+ const char *base_name, *suffix;
+ char *name;
segT *pcached;
segT seg, current_section;
int current_subsec;
diff --git a/gas/config/xtensa-relax.c b/gas/config/xtensa-relax.c
index 41f5714..a67fbe6 100644
--- a/gas/config/xtensa-relax.c
+++ b/gas/config/xtensa-relax.c
@@ -1572,7 +1572,7 @@ transition_applies (insn_pattern *initial_insn,
static bfd_boolean
wide_branch_opcode (const char *opcode_name,
- char *suffix,
+ const char *suffix,
xtensa_opcode *popcode)
{
xtensa_isa isa = xtensa_default_isa;
diff --git a/gas/symbols.c b/gas/symbols.c
index e117049..32236ba 100644
--- a/gas/symbols.c
+++ b/gas/symbols.c
@@ -66,7 +66,7 @@ struct obstack notes;
const char * an_external_name;
#endif
-static char *save_symbol_name (const char *);
+static const char *save_symbol_name (const char *);
static void fb_label_init (void);
static long dollar_label_instance (long);
static long fb_label_instance (long);
@@ -101,7 +101,7 @@ symbol_new (const char *name, segT segment, valueT valu, fragS *frag)
/* Save a symbol name on a permanent obstack, and convert it according
to the object file format. */
-static char *
+static const char *
save_symbol_name (const char *name)
{
size_t name_length;
@@ -132,7 +132,7 @@ symbol_create (const char *name, /* It is copied, the caller can destroy/modify.
valueT valu, /* Symbol value. */
fragS *frag /* Associated fragment. */)
{
- char *preserved_copy_of_name;
+ const char *preserved_copy_of_name;
symbolS *symbolP;
preserved_copy_of_name = save_symbol_name (name);
@@ -190,7 +190,7 @@ static unsigned long local_symbol_conversion_count;
struct local_symbol *
local_symbol_make (const char *name, segT section, valueT val, fragS *frag)
{
- char *name_copy;
+ const char *name_copy;
struct local_symbol *ret;
++local_symbol_count;
@@ -3103,7 +3103,7 @@ symbol_relc_make_value (offsetT val)
char *
symbol_relc_make_expr (expressionS * exp)
{
- char * opstr = NULL; /* Operator prefix string. */
+ const char * opstr = NULL; /* Operator prefix string. */
int arity = 0; /* Arity of this operator. */
char * operands[3]; /* Up to three operands. */
char * concat_string = NULL;
diff --git a/include/opcode/i960.h b/include/opcode/i960.h
index 0904e1b..be3ac10 100644
--- a/include/opcode/i960.h
+++ b/include/opcode/i960.h
@@ -134,7 +134,7 @@
/* Description of a single i80960 instruction */
struct i960_opcode {
long opcode; /* 32 bits, constant fields filled in, rest zeroed */
- char *name; /* Assembler mnemonic */
+ const char *name; /* Assembler mnemonic */
short iclass; /* Class: see #defines below */
char format; /* REG, COBR, CTRL, MEMn, COJ, FBRA, or CALLJ */
char num_ops; /* Number of operands */
diff --git a/include/opcode/tic4x.h b/include/opcode/tic4x.h
index f95d46a..b4209a1 100644
--- a/include/opcode/tic4x.h
+++ b/include/opcode/tic4x.h
@@ -226,7 +226,7 @@ struct tic4x_inst
const char * name;
unsigned long opcode;
unsigned long opmask;
- char * args;
+ const char * args;
unsigned long oplevel;
};
--
2.1.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] tc-sparc.c: get rid of wierd usage of strchr ()
2016-03-20 19:41 [PATCH 1/3] tc-sparc.c: get rid of wierd usage of strchr () tbsaunde+binutils
2016-03-20 19:41 ` [PATCH 2/3] tc-pdp11.c: remove useless code tbsaunde+binutils
2016-03-20 19:41 ` [PATCH 3/3] make more variables const tbsaunde+binutils
@ 2016-03-22 16:29 ` Nick Clifton
2 siblings, 0 replies; 6+ messages in thread
From: Nick Clifton @ 2016-03-22 16:29 UTC (permalink / raw)
To: tbsaunde+binutils, binutils
Hi Trevor,
> 2016-03-20 Trevor Saunders <tbsaunde+binutils@tbsaunde.org>
>
> * config/tc-sparc.c (sparc_regname_to_dw2regnum): Replace strchr ()
> call with a switch.
Approved - please apply.
Cheers
Nick
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] tc-pdp11.c: remove useless code
2016-03-20 19:41 ` [PATCH 2/3] tc-pdp11.c: remove useless code tbsaunde+binutils
@ 2016-03-22 16:31 ` Nick Clifton
0 siblings, 0 replies; 6+ messages in thread
From: Nick Clifton @ 2016-03-22 16:31 UTC (permalink / raw)
To: tbsaunde+binutils, binutils
Hi Trevor,
> 2016-03-20 Trevor Saunders <tbsaunde+binutils@tbsaunde.org>
>
> * config/tc-pdp11.c (md_assemble): Remove useless if and assignment to
> str.
Approved - please apply.
Cheers
Nick
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] make more variables const
2016-03-20 19:41 ` [PATCH 3/3] make more variables const tbsaunde+binutils
@ 2016-03-22 16:33 ` Nick Clifton
0 siblings, 0 replies; 6+ messages in thread
From: Nick Clifton @ 2016-03-22 16:33 UTC (permalink / raw)
To: binutils
Hi Trevor,
> gas/ChangeLog:
> 2016-03-20 Trevor Saunders <tbsaunde+binutils@tbsaunde.org>
>
> * config/tc-h8300.c (h8300_elf_section): Add const qualifiers.
> * config/tc-ia64.c (obj_elf_vms_common): Likewise.
> * config/tc-m68hc11.c (md_begin): Likewise.
> (print_opcode_list): Likewise.
> * config/tc-msp430.c (msp430_section): Likewise.
> * config/tc-score.c (struct s3_insn_to_dependency): Likewise.
> (s3_build_dependency_insn_hsh): Likewise.
> * config/tc-score7.c (struct s7_insn_to_dependency): Likewise.
> (s7_build_dependency_insn_hsh): Likewise.
> * config/tc-tic4x.c: Likewise.
> * config/tc-tic54x.c (tic54x_set_default_include): Likewise.
> (subsym_get_arg): Likewise.
> * config/tc-xtensa.c (struct suffix_reloc_map): Likewise.
> (get_directive): Likewise.
> (cache_literal_section): Likewise.
> * config/xtensa-relax.c: Likewise.
> * symbols.c (symbol_create): Likewise.
> (local_symbol_make): Likewise.
> (symbol_relc_make_expr): Likewise.
>
> include/ChangeLog:
> 2016-03-20 Trevor Saunders <tbsaunde+binutils@tbsaunde.org>
>
> * opcode/i960.h: Add const qualifiers.
> * opcode/tic4x.h (struct tic4x_inst): Likewise.
Approved - please apply.
Cheers
Nick
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-03-22 16:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-20 19:41 [PATCH 1/3] tc-sparc.c: get rid of wierd usage of strchr () tbsaunde+binutils
2016-03-20 19:41 ` [PATCH 2/3] tc-pdp11.c: remove useless code tbsaunde+binutils
2016-03-22 16:31 ` Nick Clifton
2016-03-20 19:41 ` [PATCH 3/3] make more variables const tbsaunde+binutils
2016-03-22 16:33 ` Nick Clifton
2016-03-22 16:29 ` [PATCH 1/3] tc-sparc.c: get rid of wierd usage of strchr () Nick Clifton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).