This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[patch] avr port: numbers can be used as registers names



Mon May  1 14:19:39 2000  Denis Chertykov  <denisc@overta.ru>

	* config/tc-avr.c: ATTRIBUTE_UNUSED added to the necessary places.
	More comments added.
	(md_begin): Removed "construct symbols for each register name".
	Because register names conflicts with GCC generated function
	names.
	(avr_operand): Now constant numbers can be used as a register
	identifiers (0 as r0, 31 as r31).
	(md_assemble): use skip_space () before parsing instruction
	operands.


Index: gas/config/tc-avr.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-avr.c,v
retrieving revision 1.2
diff -c -3 -p -r1.2 tc-avr.c
*** tc-avr.c	2000/05/01 08:48:32	1.2
--- tc-avr.c	2000/05/01 11:08:08
*************** static char * extract_word (char *from, 
*** 130,136 ****
  static unsigned int avr_operand (struct avr_opcodes_s *opcode,
  				 int where, char *op, char **line);
  static unsigned int avr_operands (struct avr_opcodes_s *opcode, char **line);
! static unsigned int avr_get_constant (char * str, unsigned int max);
  static char *parse_exp (char *s, expressionS * op);
  static bfd_reloc_code_real_type avr_ldi_expression (expressionS *exp);
  long md_pcrel_from_section PARAMS ((fixS *, segT));
--- 130,136 ----
  static unsigned int avr_operand (struct avr_opcodes_s *opcode,
  				 int where, char *op, char **line);
  static unsigned int avr_operands (struct avr_opcodes_s *opcode, char **line);
! static unsigned int avr_get_constant (char * str, int max);
  static char *parse_exp (char *s, expressionS * op);
  static bfd_reloc_code_real_type avr_ldi_expression (expressionS *exp);
  long md_pcrel_from_section PARAMS ((fixS *, segT));
*************** extract_word (char *from, char *to, int 
*** 371,378 ****
  
  int
  md_estimate_size_before_relax (fragp, seg)
!      fragS *fragp;
!      asection *seg;
  {
    abort ();
    return 0;
--- 371,378 ----
  
  int
  md_estimate_size_before_relax (fragp, seg)
!      fragS *fragp ATTRIBUTE_UNUSED;
!      asection *seg ATTRIBUTE_UNUSED;
  {
    abort ();
    return 0;
*************** md_show_usage (stream)
*** 396,402 ****
  
  static void
  avr_set_arch (dummy)
!      int dummy;
  {
    char * str;
    str = (char *)alloca (20);
--- 396,402 ----
  
  static void
  avr_set_arch (dummy)
!      int dummy ATTRIBUTE_UNUSED;
  {
    char * str;
    str = (char *)alloca (20);
*************** md_parse_option (c, arg)
*** 438,444 ****
  
  symbolS *
  md_undefined_symbol(name)
!      char *name;
  {
    return 0;
  }
--- 438,444 ----
  
  symbolS *
  md_undefined_symbol(name)
!      char *name ATTRIBUTE_UNUSED;
  {
    return 0;
  }
*************** md_atof (type, litP, sizeP)
*** 487,495 ****
  
  void
  md_convert_frag (abfd, sec, fragP)
!   bfd *abfd;
!   asection *sec;
!   fragS *fragP;
  {
    abort ();
  }
--- 487,495 ----
  
  void
  md_convert_frag (abfd, sec, fragP)
!   bfd *abfd ATTRIBUTE_UNUSED;
!   asection *sec ATTRIBUTE_UNUSED;
!   fragS *fragP ATTRIBUTE_UNUSED;
  {
    abort ();
  }
*************** md_convert_frag (abfd, sec, fragP)
*** 498,504 ****
  void
  md_begin ()
  {
!   int i;
    struct avr_opcodes_s *opcode;
    avr_hash = hash_new();
  
--- 498,504 ----
  void
  md_begin ()
  {
!   unsigned int i;
    struct avr_opcodes_s *opcode;
    avr_hash = hash_new();
  
*************** md_begin ()
*** 513,542 ****
  
    for (i = 0; i < sizeof (exp_mod) / sizeof (exp_mod[0]); ++i)
      hash_insert (avr_mod_hash, EXP_MOD_NAME(i), (void*)(i+10));
  
-   /* Construct symbols for each register */
-   /* FIXME: register names are in the same namespace as labels.
-      This means that C functions or global variables with the same
-      name as a register will cause assembler errors, even though
-      such names (r0-r31) are perfectly valid in C.  I'd suggest to
-      put '%' or "." in front of register names both here and in avr-gcc.  */
  
!   for (i = 0; i < 32; i++)
!     {
!       char buf[10];
  
!       sprintf (buf, "r%d", i);
!       symbol_table_insert (symbol_new (buf, reg_section, i,
! 				       &zero_address_frag));
!       sprintf (buf, "R%d", i);
!       symbol_table_insert (symbol_new (buf, reg_section, i,
! 				       &zero_address_frag));
!     }
!   
!   bfd_set_arch_mach (stdoutput, TARGET_ARCH, avr_mcu->mach);
  }
  
  
  static unsigned int
  avr_operands (opcode, line)
       struct avr_opcodes_s *opcode;
--- 513,548 ----
  
    for (i = 0; i < sizeof (exp_mod) / sizeof (exp_mod[0]); ++i)
      hash_insert (avr_mod_hash, EXP_MOD_NAME(i), (void*)(i+10));
+   
+   bfd_set_arch_mach (stdoutput, TARGET_ARCH, avr_mcu->mach);
+ }
  
  
! /* Resolve STR as a constant expression and return the result.
!    If result greater than MAX then error. */
  
! static unsigned int
! avr_get_constant (str, max)
!      char * str;
!      int max;
! {
!   expressionS ex;
!   str = skip_space (str);
!   input_line_pointer = str;
!   expression (&ex);
! 
!   if (ex.X_op != O_constant)
!     as_bad (_("constant value required"));
! 
!   if (ex.X_add_number > max || ex.X_add_number < 0)
!     as_bad (_("number must be less than %d"), max+1);
!   return ex.X_add_number;
  }
  
  
+ /* Parse instruction operands.
+    Returns binary opcode. */
+ 
  static unsigned int
  avr_operands (opcode, line)
       struct avr_opcodes_s *opcode;
*************** avr_operands (opcode, line)
*** 622,645 ****
    return bin;
  }
  
- static unsigned int
- avr_get_constant (str, max)
-      char * str;
-      unsigned int max;
- {
-   expressionS ex;
-   str = skip_space (str);
-   input_line_pointer = str;
-   expression (&ex);
- 
-   if (ex.X_op != O_constant)
-     as_bad (_("constant value required"));
  
!   if (ex.X_add_number > max)
!     as_bad (_("number must be less than %d"), max+1);
!   return ex.X_add_number;
! }
! 
  static unsigned int
  avr_operand (opcode, where, op, line)
       struct avr_opcodes_s *opcode;
--- 628,637 ----
    return bin;
  }
  
  
! /* Parse one instruction operand.
!    Returns operand bitmask. Also fixups can be generated.  */
!    
  static unsigned int
  avr_operand (opcode, where, op, line)
       struct avr_opcodes_s *opcode;
*************** avr_operand (opcode, where, op, line)
*** 647,657 ****
       char *op;
       char **line;
  {
-   unsigned int op_mask = 0;
-   char *str = *line;
    expressionS op_expr;
  
-   str = skip_space (str);
    switch (*op)
      {
        /* Any register operand.  */
--- 639,648 ----
       char *op;
       char **line;
  {
    expressionS op_expr;
+   unsigned int op_mask = 0;
+   char *str = skip_space (*line);
  
    switch (*op)
      {
        /* Any register operand.  */
*************** avr_operand (opcode, where, op, line)
*** 661,672 ****
      case 'a':
      case 'v':
        {
- 	char r_name[256];
  	op_mask = -1;
  
! 	str = extract_word (str, r_name, sizeof (r_name));
! 	if (r_name[0] == 'r' || r_name[0] == 'R')
! 	  {
  	    if (isdigit(r_name[1]))
  	      {
  		if (r_name[2] == '\0')
--- 652,664 ----
      case 'a':
      case 'v':
        {
  	op_mask = -1;
  
! 	if (*str == 'r' || *str == 'R')
! 	  {	    
! 	    char r_name[20];
! 	    
! 	    str = extract_word (str, r_name, sizeof (r_name));
  	    if (isdigit(r_name[1]))
  	      {
  		if (r_name[2] == '\0')
*************** avr_operand (opcode, where, op, line)
*** 679,690 ****
  	  }
  	else
  	  {
! 	    parse_exp (r_name, &op_expr);
! 	    if (op_expr.X_op == O_register)
! 	      op_mask = op_expr.X_add_number;
  	  }
  	
! 	if (op_mask <= 31 && op_mask >= 0)
  	  {
  	    switch (*op)
  	      {
--- 671,681 ----
  	  }
  	else
  	  {
! 	    op_mask = avr_get_constant (str, 31);
! 	    str = input_line_pointer;
  	  }
  	
! 	if (op_mask <= 31)
  	  {
  	    switch (*op)
  	      {
*************** avr_operand (opcode, where, op, line)
*** 715,721 ****
  	      }
  	    break;
  	  }
! 	as_bad (_ ("register required"));
        }
        break;
  
--- 706,712 ----
  	      }
  	    break;
  	  }
! 	as_bad (_ ("register name or number from 0 to 31 required"));
        }
        break;
  
*************** md_apply_fix3 (fixp, valuep, seg)
*** 1147,1153 ****
  
  arelent *
  tc_gen_reloc (seg, fixp)
!      asection *seg;
       fixS *fixp;
  {
    arelent *reloc;
--- 1138,1144 ----
  
  arelent *
  tc_gen_reloc (seg, fixp)
!      asection *seg ATTRIBUTE_UNUSED;
       fixS *fixp;
  {
    arelent *reloc;
*************** md_assemble (str)
*** 1184,1190 ****
    struct avr_opcodes_s * opcode;
    char op[11];
  
!   str = extract_word (str, op, sizeof(op));
  
    if (!op[0])
      as_bad (_ ("can't find opcode "));
--- 1175,1181 ----
    struct avr_opcodes_s * opcode;
    char op[11];
  
!   str = skip_space (extract_word (str, op, sizeof(op)));
  
    if (!op[0])
      as_bad (_ ("can't find opcode "));



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]