X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gas%2Fconfig%2Ftc-score7.c;h=941467be3bfcaf13317c9df8ed4c7a08ff28f211;hb=97f50151221de0a023a8317559b1992a90f9cb8f;hp=b282b1d9a313f30aec9d2d1c1f3f00442bea49f8;hpb=c3b7224ae49a815ca1e60d058acc980530832881;p=deliverable%2Fbinutils-gdb.git diff --git a/gas/config/tc-score7.c b/gas/config/tc-score7.c index b282b1d9a3..941467be3b 100644 --- a/gas/config/tc-score7.c +++ b/gas/config/tc-score7.c @@ -1,5 +1,5 @@ /* tc-score7.c -- Assembler for Score7 - Copyright 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2016 Free Software Foundation, Inc. Contributed by: Brain.lin (brain.lin@sunplusct.com) Mei Ligang (ligang@sunnorth.com.cn) @@ -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; }; @@ -597,7 +597,7 @@ static struct s7_datafield_range s7_score_df_range[] = struct s7_asm_opcode { /* Instruction name. */ - const char *template; + const char *template_name; /* Instruction Opcode. */ bfd_vma value; @@ -1260,12 +1260,12 @@ static int s7_my_get_expression (expressionS * ep, char **str) { char *save_in; - segT seg; save_in = input_line_pointer; input_line_pointer = *str; s7_in_my_get_expression = 1; - seg = expression (ep); + + (void) expression (ep); s7_in_my_get_expression = 0; if (ep->X_op == O_illegal) @@ -2620,7 +2620,7 @@ s7_get_insn_class_from_type (enum score_insn_type type) } static unsigned long -s7_adjust_paritybit (unsigned long m_code, enum insn_class class) +s7_adjust_paritybit (unsigned long m_code, enum insn_class i_class) { unsigned long result = 0; unsigned long m_code_high = 0; @@ -2628,22 +2628,22 @@ s7_adjust_paritybit (unsigned long m_code, enum insn_class class) unsigned long pb_high = 0; unsigned long pb_low = 0; - if (class == INSN_CLASS_32) + if (i_class == INSN_CLASS_32) { pb_high = 0x80000000; pb_low = 0x00008000; } - else if (class == INSN_CLASS_16) + else if (i_class == INSN_CLASS_16) { pb_high = 0; pb_low = 0; } - else if (class == INSN_CLASS_PCE) + else if (i_class == INSN_CLASS_PCE) { pb_high = 0; pb_low = 0x00008000; } - else if (class == INSN_CLASS_SYN) + else if (i_class == INSN_CLASS_SYN) { /* FIXME. at this time, INSN_CLASS_SYN must be 32 bit, but, instruction type should be changed if macro instruction has been expanded. */ @@ -2795,7 +2795,7 @@ s7_parse_16_32_inst (char *insnstr, bfd_boolean gen_frag_p) *p = c; memset (&s7_inst, '\0', sizeof (s7_inst)); - sprintf (s7_inst.str, "%s", insnstr); + strcpy (s7_inst.str, insnstr); if (opcode) { s7_inst.instruction = opcode->value; @@ -2804,7 +2804,7 @@ s7_parse_16_32_inst (char *insnstr, bfd_boolean gen_frag_p) s7_inst.size = s7_GET_INSN_SIZE (s7_inst.type); s7_inst.relax_size = 0; s7_inst.bwarn = 0; - sprintf (s7_inst.name, "%s", opcode->template); + strcpy (s7_inst.name, opcode->template_name); strcpy (s7_inst.reg, ""); s7_inst.error = NULL; s7_inst.reloc.type = BFD_RELOC_NONE; @@ -3096,14 +3096,12 @@ s7_do_ldst_insn (char *str) int conflict_reg; int value; char * temp; - char *strbak; char *dataptr; int reg; int ldst_idx = 0; int hex_p = 0; - strbak = str; s7_skip_whitespace (str); if (((conflict_reg = s7_reg_required_here (&str, 20, s7_REG_TYPE_SCORE)) == (int) s7_FAIL) @@ -3306,7 +3304,6 @@ s7_do_ldst_insn (char *str) if (s7_inst.reloc.exp.X_op == O_constant) { - int value; unsigned int data_type; if (pre_inc == 1) @@ -4382,7 +4379,7 @@ s7_do_macro_la_rdi32 (char *str) } else { - assert (s7_inst.reloc.exp.X_add_symbol); + gas_assert (s7_inst.reloc.exp.X_add_symbol); s7_build_la_pic (reg_rd, s7_inst.reloc.exp); } @@ -4789,7 +4786,8 @@ s7_do_macro_ldst_label (char *str) { int ldst_idx = 0; ldst_idx = s7_inst.instruction & OPC_PSEUDOLDST_MASK; - s7_build_lwst_pic (reg_rd, s7_inst.reloc.exp, s7_score_ldst_insns[ldst_idx * 3 + 0].template); + s7_build_lwst_pic (reg_rd, s7_inst.reloc.exp, + s7_score_ldst_insns[ldst_idx * 3 + 0].template_name); return; } else @@ -5092,20 +5090,22 @@ s7_build_score_ops_hsh (void) for (i = 0; i < sizeof (s7_score_insns) / sizeof (struct s7_asm_opcode); i++) { const struct s7_asm_opcode *insn = s7_score_insns + i; - unsigned len = strlen (insn->template); - struct s7_asm_opcode *new; - char *template; - new = obstack_alloc (&insn_obstack, sizeof (struct s7_asm_opcode)); - template = obstack_alloc (&insn_obstack, len + 1); - - strcpy (template, insn->template); - new->template = template; - new->parms = insn->parms; - new->value = insn->value; - new->relax_value = insn->relax_value; - new->type = insn->type; - new->bitmask = insn->bitmask; - hash_insert (s7_score_ops_hsh, new->template, (void *) new); + size_t len = strlen (insn->template_name); + struct s7_asm_opcode *new_opcode; + char *template_name; + new_opcode = (struct s7_asm_opcode *) + obstack_alloc (&insn_obstack, sizeof (struct s7_asm_opcode)); + template_name = (char *) obstack_alloc (&insn_obstack, len + 1); + + strcpy (template_name, insn->template_name); + new_opcode->template_name = template_name; + new_opcode->parms = insn->parms; + new_opcode->value = insn->value; + new_opcode->relax_value = insn->relax_value; + new_opcode->type = insn->type; + new_opcode->bitmask = insn->bitmask; + hash_insert (s7_score_ops_hsh, new_opcode->template_name, + (void *) new_opcode); } } @@ -5119,15 +5119,20 @@ s7_build_dependency_insn_hsh (void) for (i = 0; i < ARRAY_SIZE (s7_insn_to_dependency_table); i++) { const struct s7_insn_to_dependency *tmp = s7_insn_to_dependency_table + i; - unsigned len = strlen (tmp->insn_name); - struct s7_insn_to_dependency *new; + size_t len = strlen (tmp->insn_name); + struct s7_insn_to_dependency *new_i2d; + char *insn_name; - new = obstack_alloc (&dependency_obstack, sizeof (struct s7_insn_to_dependency)); - new->insn_name = obstack_alloc (&dependency_obstack, len + 1); + new_i2d = (struct s7_insn_to_dependency *) + obstack_alloc (&dependency_obstack, + sizeof (struct s7_insn_to_dependency)); + insn_name = (char *) obstack_alloc (&dependency_obstack, len + 1); - strcpy (new->insn_name, tmp->insn_name); - new->type = tmp->type; - hash_insert (s7_dependency_insn_hsh, new->insn_name, (void *) new); + 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); } } @@ -5196,10 +5201,10 @@ s7_pic_need_relax (symbolS *sym, asection *segtype) } /* This must duplicate the test in adjust_reloc_syms. */ - return (symsec != &bfd_und_section - && symsec != &bfd_abs_section - && ! bfd_is_com_section (symsec) - && !linkonce + return (!bfd_is_und_section (symsec) + && !bfd_is_abs_section (symsec) + && !bfd_is_com_section (symsec) + && !linkonce #ifdef OBJ_ELF /* A global or weak symbol is treated as external. */ && (OUTPUT_FLAVOR != bfd_target_elf_flavour @@ -5238,8 +5243,6 @@ s7_b32_relax_to_b16 (fragS * fragp) { int grows = 0; int relaxable_p = 0; - int old; - int new; int frag_addr = fragp->fr_address + fragp->insn_addr; addressT symbol_address = 0; @@ -5253,8 +5256,6 @@ s7_b32_relax_to_b16 (fragS * fragp) so in relax stage , it may be wrong to calculate the symbol's offset when the frag's section is different from the symbol's. */ - old = s7_RELAX_OLD (fragp->fr_subtype); - new = s7_RELAX_NEW (fragp->fr_subtype); relaxable_p = s7_RELAX_OPT (fragp->fr_subtype); s = fragp->fr_symbol; @@ -5263,8 +5264,8 @@ s7_b32_relax_to_b16 (fragS * fragp) frag_addr = 0; else { - if (s->bsym != 0) - symbol_address = (addressT) s->sy_frag->fr_address; + if (s->bsym != NULL) + symbol_address = (addressT) symbol_get_frag (s)->fr_address; } value = s7_md_chars_to_number (fragp->fr_literal, s7_INSN_SIZE); @@ -5308,12 +5309,12 @@ s7_parse_pce_inst (char *insnstr) p = strstr (insnstr, "||"); c = *p; *p = '\0'; - sprintf (first, "%s", insnstr); + strcpy (first, insnstr); /* Get second part string of PCE. */ *p = c; p += 2; - sprintf (second, "%s", p); + strcpy (second, p); s7_parse_16_32_inst (first, FALSE); if (s7_inst.error) @@ -5337,7 +5338,7 @@ s7_parse_pce_inst (char *insnstr) || ((pec_part_1.size == s7_INSN16_SIZE) && (s7_inst.size == s7_INSN_SIZE))) { s7_inst.error = _("pce instruction error (16 bit || 16 bit)'"); - sprintf (s7_inst.str, insnstr); + strcpy (s7_inst.str, insnstr); return; } @@ -5352,8 +5353,8 @@ s7_insert_reg (const struct s7_reg_entry *r, struct hash_control *htab) { int i = 0; int len = strlen (r->name) + 2; - char *buf = xmalloc (len); - char *buf2 = xmalloc (len); + char *buf = XNEWVEC (char, len); + char *buf2 = XNEWVEC (char, len); strcpy (buf + i, r->name); for (i = 0; buf[i]; i++) @@ -5471,10 +5472,9 @@ s7_get_symbol (void) char *name; symbolS *p; - name = input_line_pointer; - c = get_symbol_end (); + c = get_symbol_name (&name); p = (symbolS *) symbol_find_or_make (name); - *input_line_pointer = c; + (void) restore_line_pointer (c); return p; } @@ -5642,7 +5642,6 @@ s7_s_score_end (int x ATTRIBUTE_UNUSED) /* Generate a .pdr section. */ segT saved_seg = now_seg; subsegT saved_subseg = now_subseg; - valueT dot; expressionS exp; char *fragp; @@ -5676,7 +5675,7 @@ s7_s_score_end (int x ATTRIBUTE_UNUSED) } if (p != NULL) { - assert (S_GET_NAME (p)); + gas_assert (S_GET_NAME (p)); if (strcmp (S_GET_NAME (p), S_GET_NAME (s7_cur_proc_ptr->isym))) as_warn (_(".end symbol does not match .ent symbol.")); if (debug_type == DEBUG_STABS) @@ -5693,8 +5692,8 @@ s7_s_score_end (int x ATTRIBUTE_UNUSED) else { - dot = frag_now_fix (); - assert (s7_pdr_seg); + (void) frag_now_fix (); + gas_assert (s7_pdr_seg); subseg_set (s7_pdr_seg, 0); /* Write the symbol. */ exp.X_op = O_symbol; @@ -5955,8 +5954,7 @@ s7_s_score_lcomm (int bytes_p) segT bss_seg = bss_section; int needs_align = 0; - name = input_line_pointer; - c = get_symbol_end (); + c = get_symbol_name (&name); p = input_line_pointer; *p = c; @@ -5967,7 +5965,7 @@ s7_s_score_lcomm (int bytes_p) return; } - SKIP_WHITESPACE (); + SKIP_WHITESPACE_AFTER_NAME (); /* Accept an optional comma after the name. The comma used to be required, but Irix 5 cc does not generate it. */ @@ -6187,11 +6185,11 @@ s7_assemble (char *str) instruction in the error message. */ static void -s7_operand (expressionS * expr) +s7_operand (expressionS * exp) { if (s7_in_my_get_expression) { - expr->X_op = O_illegal; + exp->X_op = O_illegal; if (s7_inst.error == NULL) { s7_inst.error = _("bad expression"); @@ -6211,7 +6209,7 @@ s7_operand (expressionS * expr) the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is the byte sequence 99 99 f1 3f 9a 99 99 99. */ -static char * +static const char * s7_atof (int type, char *litP, int *sizeP) { int prec; @@ -6274,7 +6272,7 @@ s7_atof (int type, char *litP, int *sizeP) Called after md_convert_frag(). */ static void -s7_frag_check (fragS * fragp) +s7_frag_check (fragS * fragp ATTRIBUTE_UNUSED) { know (fragp->insn_addr <= s7_RELAX_PAD_BYTE); } @@ -6370,7 +6368,6 @@ s7_relax_frag (asection * sec ATTRIBUTE_UNUSED, { int grows = 0; int insn_size; - int insn_relax_size; int do_relax_p = 0; /* Indicate doing relaxation for this frag. */ int relaxable_p = 0; bfd_boolean word_align_p = FALSE; @@ -6390,15 +6387,9 @@ s7_relax_frag (asection * sec ATTRIBUTE_UNUSED, /* Get instruction size and relax size after the last relaxation. */ if (fragp->fr_opcode) - { - insn_size = s7_RELAX_NEW (fragp->fr_subtype); - insn_relax_size = s7_RELAX_OLD (fragp->fr_subtype); - } + insn_size = s7_RELAX_NEW (fragp->fr_subtype); else - { - insn_size = s7_RELAX_OLD (fragp->fr_subtype); - insn_relax_size = s7_RELAX_NEW (fragp->fr_subtype); - } + insn_size = s7_RELAX_OLD (fragp->fr_subtype); /* Handle specially for s7_GP instruction. for, s7_judge_size_before_relax() has already determine whether the s7_GP instruction should do relax. */ @@ -6575,28 +6566,28 @@ s7_convert_frag (bfd * abfd ATTRIBUTE_UNUSED, segT sec ATTRIBUTE_UNUSED, fragS * fragp) { - int old; - int new; + int r_old; + int r_new; char backup[20]; fixS *fixp; - old = s7_RELAX_OLD (fragp->fr_subtype); - new = s7_RELAX_NEW (fragp->fr_subtype); + r_old = s7_RELAX_OLD (fragp->fr_subtype); + r_new = s7_RELAX_NEW (fragp->fr_subtype); /* fragp->fr_opcode indicates whether this frag should be relaxed. */ if (fragp->fr_opcode == NULL) { - memcpy (backup, fragp->fr_literal, old); - fragp->fr_fix = old; + memcpy (backup, fragp->fr_literal, r_old); + fragp->fr_fix = r_old; } else { - memcpy (backup, fragp->fr_literal + old, new); - fragp->fr_fix = new; + memcpy (backup, fragp->fr_literal + r_old, r_new); + fragp->fr_fix = r_new; } fixp = fragp->tc_frag_data.fixp; - while (fixp && fixp->fx_frag == fragp && fixp->fx_where < old) + while (fixp && fixp->fx_frag == fragp && fixp->fx_where < r_old) { if (fragp->fr_opcode) fixp->fx_done = 1; @@ -6605,7 +6596,7 @@ s7_convert_frag (bfd * abfd ATTRIBUTE_UNUSED, while (fixp && fixp->fx_frag == fragp) { if (fragp->fr_opcode) - fixp->fx_where -= old + fragp->insn_addr; + fixp->fx_where -= r_old + fragp->insn_addr; else fixp->fx_done = 1; fixp = fixp->fx_next; @@ -6644,7 +6635,7 @@ s7_section_align (segT segment, valueT size) { int align = bfd_get_section_alignment (stdoutput, segment); - return ((size + (1 << align) - 1) & (-1 << align)); + return ((size + (1 << align) - 1) & -(1 << align)); } static void @@ -6658,7 +6649,7 @@ s7_apply_fix (fixS *fixP, valueT *valP, segT seg) char *buf = fixP->fx_frag->fr_literal + fixP->fx_where; - assert (fixP->fx_r_type < BFD_RELOC_UNUSED); + gas_assert (fixP->fx_r_type < BFD_RELOC_UNUSED); if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) { if (fixP->fx_r_type != BFD_RELOC_SCORE_DUMMY_HI16) @@ -6884,15 +6875,12 @@ s7_gen_reloc (asection * section ATTRIBUTE_UNUSED, fixS * fixp) static arelent *retval[MAX_RELOC_EXPANSION + 1]; /* MAX_RELOC_EXPANSION equals 2. */ arelent *reloc; bfd_reloc_code_real_type code; - char *type; - fragS *f; - symbolS *s; - expressionS e; + const char *type; - reloc = retval[0] = xmalloc (sizeof (arelent)); + reloc = retval[0] = XNEW (arelent); retval[1] = NULL; - reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *)); + reloc->sym_ptr_ptr = XNEW (asymbol *); *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; reloc->addend = fixp->fx_offset; @@ -6920,19 +6908,15 @@ s7_gen_reloc (asection * section ATTRIBUTE_UNUSED, fixS * fixp) newval |= (((off >> 14) & 0x3) << 16); s7_number_to_chars (buf, newval, s7_INSN_SIZE); - retval[1] = xmalloc (sizeof (arelent)); + retval[1] = XNEW (arelent); retval[2] = NULL; - retval[1]->sym_ptr_ptr = xmalloc (sizeof (asymbol *)); + retval[1]->sym_ptr_ptr = XNEW (asymbol *); *retval[1]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); retval[1]->address = (reloc->address + s7_RELAX_RELOC2 (fixp->fx_frag->fr_subtype)); - f = fixp->fx_frag; - s = f->fr_symbol; - e = s->sy_value; - retval[1]->addend = 0; retval[1]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO16); - assert (retval[1]->howto != NULL); + gas_assert (retval[1]->howto != NULL); fixp->fx_r_type = BFD_RELOC_HI16_S; }