diff mbox

disas/microblaze: Add missing 'const' attributes

Message ID 1458631893-12812-1-git-send-email-sw@weilnetz.de
State Under Review
Headers show

Commit Message

Stefan Weil March 22, 2016, 7:31 a.m. UTC
Making the opcode list 'const' saves memory.
Some function arguments and local variables needed 'const', too.

Add also 'static' to two local functions.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 disas/microblaze.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Edgar E. Iglesias April 6, 2016, 9:16 a.m. UTC | #1
On Tue, Mar 22, 2016 at 08:31:33AM +0100, Stefan Weil wrote:
> Making the opcode list 'const' saves memory.
> Some function arguments and local variables needed 'const', too.
> 
> Add also 'static' to two local functions.

Hi Stefan,

Sorry for the delays...

I gave this a try but it fails for me:

/home/edgar/src/c/qemu/qemu/disas/microblaze.c:668:1: error: conflicting types for ‘get_field_special’
 get_field_special(long instr, const struct op_code_struct *op)
 ^
/home/edgar/src/c/qemu/qemu/disas/microblaze.c:599:8: note: previous declaration of ‘get_field_special’ was here
 char * get_field_special (long instr, struct op_code_struct * op);
        ^
/home/edgar/src/c/qemu/qemu/disas/microblaze.c:733:1: error: conflicting types for ‘read_insn_microblaze’
 read_insn_microblaze (bfd_vma memaddr, 
 ^
/home/edgar/src/c/qemu/qemu/disas/microblaze.c:600:15: note: previous declaration of ‘read_insn_microblaze’ was here
 unsigned long read_insn_microblaze (bfd_vma memaddr, 
               ^
make: *** [disas/microblaze.o] Error 1
make: *** Waiting for unfinished jobs....


It looks like if you may have forgotten to update or remove the function prototypes...

Best regards,
Edgar



> 
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>  disas/microblaze.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/disas/microblaze.c b/disas/microblaze.c
> index 91b30ac..780b388 100644
> --- a/disas/microblaze.c
> +++ b/disas/microblaze.c
> @@ -272,7 +272,7 @@ enum microblaze_instr_type {
>  
>  #define MAX_OPCODES 280
>  
> -static struct op_code_struct {
> +static const struct op_code_struct {
>    const char *name;
>    short inst_type; /* registers and immediate values involved */
>    short inst_offset_type; /* immediate vals offset from PC? (= 1 for branches) */
> @@ -664,8 +664,8 @@ get_field_unsigned_imm (long instr)
>    }
>  */
>  
> -char *
> -get_field_special (long instr, struct op_code_struct * op)
> +static char *
> +get_field_special(long instr, const struct op_code_struct *op)
>  {
>     char tmpstr[25];
>     char spr[6];
> @@ -729,14 +729,14 @@ get_field_special (long instr, struct op_code_struct * op)
>     return(strdup(tmpstr));
>  }
>  
> -unsigned long
> +static unsigned long
>  read_insn_microblaze (bfd_vma memaddr, 
>  		      struct disassemble_info *info,
> -		      struct op_code_struct **opr)
> +		      const struct op_code_struct **opr)
>  {
>    unsigned char       ibytes[4];
>    int                 status;
> -  struct op_code_struct * op;
> +  const struct op_code_struct *op;
>    unsigned long inst;
>  
>    status = info->read_memory_func (memaddr, ibytes, 4, info);
> @@ -770,7 +770,7 @@ print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info)
>    fprintf_function    fprintf_func = info->fprintf_func;
>    void *              stream = info->stream;
>    unsigned long       inst, prev_inst;
> -  struct op_code_struct * op, *pop;
> +  const struct op_code_struct *op, *pop;
>    int                 immval = 0;
>    bfd_boolean         immfound = FALSE;
>    static bfd_vma prev_insn_addr = -1; /*init the prev insn addr */
> -- 
> 2.1.4
>
Stefan Weil April 6, 2016, 10:01 a.m. UTC | #2
Am 06.04.2016 um 11:16 schrieb Edgar E. Iglesias:
> On Tue, Mar 22, 2016 at 08:31:33AM +0100, Stefan Weil wrote:
>> Making the opcode list 'const' saves memory.
>> Some function arguments and local variables needed 'const', too.
>>
>> Add also 'static' to two local functions.
> Hi Stefan,
>
> Sorry for the delays...
>
> I gave this a try but it fails for me:
>
> /home/edgar/src/c/qemu/qemu/disas/microblaze.c:668:1: error: conflicting types for ‘get_field_special’
>  get_field_special(long instr, const struct op_code_struct *op)
>  ^
> /home/edgar/src/c/qemu/qemu/disas/microblaze.c:599:8: note: previous declaration of ‘get_field_special’ was here
>  char * get_field_special (long instr, struct op_code_struct * op);
>         ^
> /home/edgar/src/c/qemu/qemu/disas/microblaze.c:733:1: error: conflicting types for ‘read_insn_microblaze’
>  read_insn_microblaze (bfd_vma memaddr, 
>  ^
> /home/edgar/src/c/qemu/qemu/disas/microblaze.c:600:15: note: previous declaration of ‘read_insn_microblaze’ was here
>  unsigned long read_insn_microblaze (bfd_vma memaddr, 
>                ^
> make: *** [disas/microblaze.o] Error 1
> make: *** Waiting for unfinished jobs....
>
>
> It looks like if you may have forgotten to update or remove the function prototypes...
>
> Best regards,
> Edgar
>

Hello Edgar,

you are right, I forgot to remove the two function prototypes.
They are not needed, so removing is the best solution which
I also used in most of my working trees. Obviously I had
chosen a bad tree for sending the patch, sorry for that.

Should I send an update, or can you just remove the two
conflicting prototypes?

Thanks,
Stefan
Edgar E. Iglesias May 5, 2016, 4:13 p.m. UTC | #3
On Wed, Apr 06, 2016 at 12:01:17PM +0200, Stefan Weil wrote:
> Am 06.04.2016 um 11:16 schrieb Edgar E. Iglesias:
> > On Tue, Mar 22, 2016 at 08:31:33AM +0100, Stefan Weil wrote:
> >> Making the opcode list 'const' saves memory.
> >> Some function arguments and local variables needed 'const', too.
> >>
> >> Add also 'static' to two local functions.
> > Hi Stefan,
> >
> > Sorry for the delays...
> >
> > I gave this a try but it fails for me:
> >
> > /home/edgar/src/c/qemu/qemu/disas/microblaze.c:668:1: error: conflicting types for ‘get_field_special’
> >  get_field_special(long instr, const struct op_code_struct *op)
> >  ^
> > /home/edgar/src/c/qemu/qemu/disas/microblaze.c:599:8: note: previous declaration of ‘get_field_special’ was here
> >  char * get_field_special (long instr, struct op_code_struct * op);
> >         ^
> > /home/edgar/src/c/qemu/qemu/disas/microblaze.c:733:1: error: conflicting types for ‘read_insn_microblaze’
> >  read_insn_microblaze (bfd_vma memaddr, 
> >  ^
> > /home/edgar/src/c/qemu/qemu/disas/microblaze.c:600:15: note: previous declaration of ‘read_insn_microblaze’ was here
> >  unsigned long read_insn_microblaze (bfd_vma memaddr, 
> >                ^
> > make: *** [disas/microblaze.o] Error 1
> > make: *** Waiting for unfinished jobs....
> >
> >
> > It looks like if you may have forgotten to update or remove the function prototypes...
> >
> > Best regards,
> > Edgar
> >
> 
> Hello Edgar,
> 
> you are right, I forgot to remove the two function prototypes.
> They are not needed, so removing is the best solution which
> I also used in most of my working trees. Obviously I had
> chosen a bad tree for sending the patch, sorry for that.
> 
> Should I send an update, or can you just remove the two
> conflicting prototypes?

Hi Stefan,

Nah, I've added a modified version of your patch into my
mb-next branch.

Thanks!
Edgar
diff mbox

Patch

diff --git a/disas/microblaze.c b/disas/microblaze.c
index 91b30ac..780b388 100644
--- a/disas/microblaze.c
+++ b/disas/microblaze.c
@@ -272,7 +272,7 @@  enum microblaze_instr_type {
 
 #define MAX_OPCODES 280
 
-static struct op_code_struct {
+static const struct op_code_struct {
   const char *name;
   short inst_type; /* registers and immediate values involved */
   short inst_offset_type; /* immediate vals offset from PC? (= 1 for branches) */
@@ -664,8 +664,8 @@  get_field_unsigned_imm (long instr)
   }
 */
 
-char *
-get_field_special (long instr, struct op_code_struct * op)
+static char *
+get_field_special(long instr, const struct op_code_struct *op)
 {
    char tmpstr[25];
    char spr[6];
@@ -729,14 +729,14 @@  get_field_special (long instr, struct op_code_struct * op)
    return(strdup(tmpstr));
 }
 
-unsigned long
+static unsigned long
 read_insn_microblaze (bfd_vma memaddr, 
 		      struct disassemble_info *info,
-		      struct op_code_struct **opr)
+		      const struct op_code_struct **opr)
 {
   unsigned char       ibytes[4];
   int                 status;
-  struct op_code_struct * op;
+  const struct op_code_struct *op;
   unsigned long inst;
 
   status = info->read_memory_func (memaddr, ibytes, 4, info);
@@ -770,7 +770,7 @@  print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info)
   fprintf_function    fprintf_func = info->fprintf_func;
   void *              stream = info->stream;
   unsigned long       inst, prev_inst;
-  struct op_code_struct * op, *pop;
+  const struct op_code_struct *op, *pop;
   int                 immval = 0;
   bfd_boolean         immfound = FALSE;
   static bfd_vma prev_insn_addr = -1; /*init the prev insn addr */