bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Patch] Improve expression tree printing in ld


From: Nick Clifton
Subject: [Patch] Improve expression tree printing in ld
Date: 19 Jul 2001 17:32:28 +0100

Hi Guys,

  I am applying the patch below to improve the tree printing function
  (exp_print_tree) in ldexp.c.  With this patch applied it will use
  stderr if config.map_file has not been specified, it will detect and
  report a NULL tree parameter, and it will not try to print tokens
  with values greater than 126 as ASCII codes.

Cheers
        Nick

2001-07-19  Nick Clifton  <address@hidden>

        * ldexp.c (exp_print_tree): Use stderr if config.map_file is not
        available.  Do not print NULL trees.
        (exp_print_token): Print unknown tokens with values > 126 as
        decimal values not ASCII characters.

Index: ld/ldexp.c
===================================================================
RCS file: /cvs/src/src/ld/ldexp.c,v
retrieving revision 1.8
diff -p -r1.8 ldexp.c
*** ldexp.c     2001/03/13 06:14:27     1.8
--- ldexp.c     2001/07/19 16:28:43
*************** Software Foundation, 59 Temple Place - S
*** 38,43 ****
--- 38,44 ----
  #include "ldexp.h"
  #include "ldgram.h"
  #include "ldlang.h"
+ #include "libiberty.h"
  
  static void exp_print_token PARAMS ((token_code_type code));
  static void make_abs PARAMS ((etree_value_type *ptr));
*************** static void
*** 67,78 ****
  exp_print_token (code)
       token_code_type code;
  {
!   static CONST struct {
      token_code_type code;
!     char *name;
!   } table[] = {
      { INT, "int" },
-     { REL, "relocateable" },
      { NAME, "NAME" },
      { PLUSEQ, "+=" },
      { MINUSEQ, "-=" },
--- 68,81 ----
  exp_print_token (code)
       token_code_type code;
  {
!   static CONST struct
!   {
      token_code_type code;
!     char * name;
!   }
!   table[] =
!   {
      { INT, "int" },
      { NAME, "NAME" },
      { PLUSEQ, "+=" },
      { MINUSEQ, "-=" },
*************** exp_print_token (code)
*** 92,128 ****
      { RSHIFT, ">>=" },
      { ALIGN_K, "ALIGN" },
      { BLOCK, "BLOCK" },
      { SECTIONS, "SECTIONS" },
      { SIZEOF_HEADERS, "SIZEOF_HEADERS" },
-     { NEXT, "NEXT" },
-     { SIZEOF, "SIZEOF" },
-     { ADDR, "ADDR" },
-     { LOADADDR, "LOADADDR" },
      { MEMORY, "MEMORY" },
      { DEFINED, "DEFINED" },
      { TARGET_K, "TARGET" },
      { SEARCH_DIR, "SEARCH_DIR" },
      { MAP, "MAP" },
-     { QUAD, "QUAD" },
-     { SQUAD, "SQUAD" },
-     { LONG, "LONG" },
-     { SHORT, "SHORT" },
-     { BYTE, "BYTE" },
      { ENTRY, "ENTRY" },
!     { 0, (char *) NULL }
    };
    unsigned int idx;
  
!   for (idx = 0; table[idx].name != (char *) NULL; idx++)
      {
        if (table[idx].code == code)
        {
!         fprintf (config.map_file, "%s", table[idx].name);
          return;
        }
      }
!   /* Not in table, just print it alone */
!   fprintf (config.map_file, "%c", code);
  }
  
  static void
--- 95,136 ----
      { RSHIFT, ">>=" },
      { ALIGN_K, "ALIGN" },
      { BLOCK, "BLOCK" },
+     { QUAD, "QUAD" },
+     { SQUAD, "SQUAD" },
+     { LONG, "LONG" },
+     { SHORT, "SHORT" },
+     { BYTE, "BYTE" },
      { SECTIONS, "SECTIONS" },
      { SIZEOF_HEADERS, "SIZEOF_HEADERS" },
      { MEMORY, "MEMORY" },
      { DEFINED, "DEFINED" },
      { TARGET_K, "TARGET" },
      { SEARCH_DIR, "SEARCH_DIR" },
      { MAP, "MAP" },
      { ENTRY, "ENTRY" },
!     { NEXT, "NEXT" },
!     { SIZEOF, "SIZEOF" },
!     { ADDR, "ADDR" },
!     { LOADADDR, "LOADADDR" },
!     { MAX_K, "MAX_K" },
!     { REL, "relocateable" },
    };
    unsigned int idx;
  
!   for (idx = ARRAY_SIZE (table); idx--;)
      {
        if (table[idx].code == code)
        {
!         fprintf (config.map_file, " %s ", table[idx].name);
          return;
        }
      }
! 
!   /* Not in table, just print it alone.  */
!   if (code < 127)
!     fprintf (config.map_file, " %c ", code);
!   else
!     fprintf (config.map_file, " <code %d> ", code);
  }
  
  static void
*************** fold_name (tree, current_section, alloca
*** 335,340 ****
--- 343,349 ----
       bfd_vma dot;
  {
    etree_value_type result;
+ 
    switch (tree->type.node_code)
      {
      case SIZEOF_HEADERS:
*************** exp_fold_tree (tree, current_section, al
*** 597,603 ****
      case etree_provided:
        if (tree->assign.dst[0] == '.' && tree->assign.dst[1] == 0)
        {
!         /* Assignment to dot can only be done during allocation */
          if (tree->type.node_class != etree_assign)
            einfo (_("%F%S can not PROVIDE assignment to location counter\n"));
          if (allocation_done == lang_allocating_phase_enum
--- 606,612 ----
      case etree_provided:
        if (tree->assign.dst[0] == '.' && tree->assign.dst[1] == 0)
        {
!         /* Assignment to dot can only be done during allocation.  */
          if (tree->type.node_class != etree_assign)
            einfo (_("%F%S can not PROVIDE assignment to location counter\n"));
          if (allocation_done == lang_allocating_phase_enum
*************** exp_fold_tree (tree, current_section, al
*** 622,631 ****
                                 + current_section->bfd_section->vma);
                      if (nextdot < dot
                          && current_section != abs_output_section)
!                       {
!                         einfo (_("%F%S cannot move location counter backwards 
(from %V to %V)\n"),
!                                dot, nextdot);
!                       }
                      else
                        *dotp = nextdot;
                    }
--- 631,638 ----
                                 + current_section->bfd_section->vma);
                      if (nextdot < dot
                          && current_section != abs_output_section)
!                       einfo (_("%F%S cannot move location counter backwards 
(from %V to %V)\n"),
!                              dot, nextdot);
                      else
                        *dotp = nextdot;
                    }
*************** exp_trinop (code, cond, lhs, rhs)
*** 740,748 ****
                            (lang_output_section_statement_type *) NULL,
                            lang_first_phase_enum);
    if (r.valid_p)
!     {
!       return exp_intop (r.value);
!     }
    new = (etree_type *) stat_alloc (sizeof (new->trinary));
    memcpy ((char *) new, (char *) &value, sizeof (new->trinary));
    return new;
--- 747,754 ----
                            (lang_output_section_statement_type *) NULL,
                            lang_first_phase_enum);
    if (r.valid_p)
!     return exp_intop (r.value);
! 
    new = (etree_type *) stat_alloc (sizeof (new->trinary));
    memcpy ((char *) new, (char *) &value, sizeof (new->trinary));
    return new;
*************** exp_unop (code, child)
*** 762,770 ****
    r = exp_fold_tree_no_dot (&value, abs_output_section,
                            lang_first_phase_enum);
    if (r.valid_p)
!     {
!       return exp_intop (r.value);
!     }
    new = (etree_type *) stat_alloc (sizeof (new->unary));
    memcpy ((char *) new, (char *) &value, sizeof (new->unary));
    return new;
--- 768,775 ----
    r = exp_fold_tree_no_dot (&value, abs_output_section,
                            lang_first_phase_enum);
    if (r.valid_p)
!     return exp_intop (r.value);
! 
    new = (etree_type *) stat_alloc (sizeof (new->unary));
    memcpy ((char *) new, (char *) &value, sizeof (new->unary));
    return new;
*************** exp_nameop (code, name)
*** 785,793 ****
                            (lang_output_section_statement_type *) NULL,
                            lang_first_phase_enum);
    if (r.valid_p)
!     {
!       return exp_intop (r.value);
!     }
    new = (etree_type *) stat_alloc (sizeof (new->name));
    memcpy ((char *) new, (char *) &value, sizeof (new->name));
    return new;
--- 790,797 ----
                            (lang_output_section_statement_type *) NULL,
                            lang_first_phase_enum);
    if (r.valid_p)
!     return exp_intop (r.value);
! 
    new = (etree_type *) stat_alloc (sizeof (new->name));
    memcpy ((char *) new, (char *) &value, sizeof (new->name));
    return new;
*************** exp_assop (code, dst, src)
*** 810,818 ****
  
  #if 0
    if (exp_fold_tree_no_dot (&value, &result))
!     {
!       return exp_intop (result);
!     }
  #endif
    new = (etree_type *) stat_alloc (sizeof (new->assign));
    memcpy ((char *) new, (char *) &value, sizeof (new->assign));
--- 814,820 ----
  
  #if 0
    if (exp_fold_tree_no_dot (&value, &result))
!     return exp_intop (result);
  #endif
    new = (etree_type *) stat_alloc (sizeof (new->assign));
    memcpy ((char *) new, (char *) &value, sizeof (new->assign));
*************** void
*** 857,862 ****
--- 859,873 ----
  exp_print_tree (tree)
       etree_type *tree;
  {
+   if (config.map_file == NULL)
+     config.map_file = stderr;
+   
+   if (tree == NULL)
+     {
+       minfo ("NULL TREE\n");
+       return;
+     }
+   
    switch (tree->type.node_class)
      {
      case etree_value:
*************** exp_print_tree (tree)
*** 870,883 ****
      case etree_assign:
  #if 0
        if (tree->assign.dst->sdefs != (asymbol *) NULL)
!       {
!         fprintf (config.map_file, "%s (%x) ", tree->assign.dst->name,
!                  tree->assign.dst->sdefs->value);
!       }
        else
!       {
!         fprintf (config.map_file, "%s (UNDEFINED)", tree->assign.dst->name);
!       }
  #endif
        fprintf (config.map_file, "%s", tree->assign.dst);
        exp_print_token (tree->type.node_code);
--- 881,890 ----
      case etree_assign:
  #if 0
        if (tree->assign.dst->sdefs != (asymbol *) NULL)
!       fprintf (config.map_file, "%s (%x) ", tree->assign.dst->name,
!                tree->assign.dst->sdefs->value);
        else
!       fprintf (config.map_file, "%s (UNDEFINED)", tree->assign.dst->name);
  #endif
        fprintf (config.map_file, "%s", tree->assign.dst);
        exp_print_token (tree->type.node_code);
*************** exp_get_abs_int (tree, def, name, alloca
*** 981,992 ****
    res = exp_fold_tree_no_dot (tree, abs_output_section, allocation_done);
  
    if (res.valid_p)
!     {
!       res.value += res.section->bfd_section->vma;
!     }
    else
!     {
!       einfo (_("%F%S non constant expression for %s\n"), name);
!     }
    return res.value;
  }
--- 988,996 ----
    res = exp_fold_tree_no_dot (tree, abs_output_section, allocation_done);
  
    if (res.valid_p)
!     res.value += res.section->bfd_section->vma;
    else
!     einfo (_("%F%S non constant expression for %s\n"), name);
! 
    return res.value;
  }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]