Back to index

cell-binutils  2.17cvs20070401
Classes | Defines | Typedefs | Functions | Variables
input-scrub.c File Reference
#include "as.h"
#include "input-file.h"
#include "sb.h"
#include "listing.h"

Go to the source code of this file.

Classes

struct  input_save

Defines

#define BEFORE_STRING   ("\n")
#define AFTER_STRING   ("\0") /* memcpy of 0 chars might choke. */
#define BEFORE_SIZE   (1)
#define AFTER_SIZE   (1)
#define TC_EOL_IN_INSN(P)   0

Typedefs

typedef unsigned int line_numberT

Functions

static struct input_saveinput_scrub_push (char *saved_position)
static char * input_scrub_pop (struct input_save *arg)
void input_scrub_begin (void)
void input_scrub_end (void)
char * input_scrub_new_file (char *filename)
char * input_scrub_include_file (char *filename, char *position)
void input_scrub_include_sb (sb *from, char *position, int is_expansion)
void input_scrub_close (void)
char * input_scrub_next_buffer (char **bufp)
int seen_at_least_1_file (void)
void bump_line_counters (void)
int new_logical_line_flags (char *fname, int line_number, int flags)
int new_logical_line (char *fname, int line_number)
void as_where (char **namep, unsigned int *linep)

Variables

static char * buffer_start
static char * partial_where
static int partial_size
static char save_source [AFTER_SIZE]
static unsigned int buffer_length
static int sb_index = -1
static sb from_sb
static int from_sb_is_expansion = 1
int macro_nest
static char * physical_input_file
static char * logical_input_file
static line_numberT physical_input_line
static int logical_input_line
static struct input_savenext_saved_file

Class Documentation

struct input_save

Definition at line 109 of file input-scrub.c.

Collaboration diagram for input_save:
Class Members
unsigned int buffer_length
char * buffer_start
sb from_sb
int from_sb_is_expansion
char * input_file_save
char * logical_input_file
int logical_input_line
struct input_save * next_saved_file
int partial_size
char * partial_where
char * physical_input_file
line_numberT physical_input_line
char save_source
char * saved_position
int sb_index

Define Documentation

#define AFTER_SIZE   (1)

Definition at line 57 of file input-scrub.c.

#define AFTER_STRING   ("\0") /* memcpy of 0 chars might choke. */

Definition at line 55 of file input-scrub.c.

#define BEFORE_SIZE   (1)

Definition at line 56 of file input-scrub.c.

#define BEFORE_STRING   ("\n")

Definition at line 54 of file input-scrub.c.

#define TC_EOL_IN_INSN (   P)    0

Definition at line 60 of file input-scrub.c.


Typedef Documentation

Definition at line 102 of file input-scrub.c.


Function Documentation

void as_where ( char **  namep,
unsigned int linep 
)

Definition at line 490 of file input-scrub.c.

{
  if (logical_input_file != NULL
      && (linep == NULL || logical_input_line >= 0))
    {
      *namep = logical_input_file;
      if (linep != NULL)
       *linep = logical_input_line;
    }
  else if (physical_input_file != NULL)
    {
      *namep = physical_input_file;
      if (linep != NULL)
       *linep = physical_input_line;
    }
  else
    {
      *namep = 0;
      if (linep != NULL)
       *linep = 0;
    }
}

Here is the caller graph for this function:

void bump_line_counters ( void  )

Definition at line 419 of file input-scrub.c.

Here is the caller graph for this function:

void input_scrub_begin ( void  )

Definition at line 202 of file input-scrub.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void input_scrub_close ( void  )

Definition at line 295 of file input-scrub.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void input_scrub_end ( void  )

Definition at line 224 of file input-scrub.c.

Here is the call graph for this function:

Here is the caller graph for this function:

char* input_scrub_include_file ( char *  filename,
char *  position 
)

Definition at line 253 of file input-scrub.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void input_scrub_include_sb ( sb from,
char *  position,
int  is_expansion 
)

Definition at line 263 of file input-scrub.c.

{
  if (macro_nest > max_macro_nest)
    as_fatal (_("macros nested too deeply"));
  ++macro_nest;

#ifdef md_macro_start
  if (is_expansion)
    {
      md_macro_start ();
    }
#endif

  next_saved_file = input_scrub_push (position);

  sb_new (&from_sb);
  from_sb_is_expansion = is_expansion;
  if (from->len >= 1 && from->ptr[0] != '\n')
    {
      /* Add the sentinel required by read.c.  */
      sb_add_char (&from_sb, '\n');
    }
  sb_scrub_and_add_sb (&from_sb, from);
  sb_index = 1;

  /* These variables are reset by input_scrub_push.  Restore them
     since we are, after all, still at the same point in the file.  */
  logical_input_line = next_saved_file->logical_input_line;
  logical_input_file = next_saved_file->logical_input_file;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* input_scrub_new_file ( char *  filename)

Definition at line 238 of file input-scrub.c.

Here is the call graph for this function:

Here is the caller graph for this function:

char* input_scrub_next_buffer ( char **  bufp)

Definition at line 301 of file input-scrub.c.

{
  register char *limit;            /*->just after last char of buffer.  */

  if (sb_index >= 0)
    {
      if (sb_index >= from_sb.len)
       {
         sb_kill (&from_sb);
         if (from_sb_is_expansion
             )
           {
             cond_finish_check (macro_nest);
#ifdef md_macro_end
             /* Allow the target to clean up per-macro expansion
                data.  */
             md_macro_end ();
#endif
           }
         --macro_nest;
         partial_where = NULL;
         if (next_saved_file != NULL)
           *bufp = input_scrub_pop (next_saved_file);
         return partial_where;
       }

      partial_where = from_sb.ptr + from_sb.len;
      partial_size = 0;
      *bufp = from_sb.ptr + sb_index;
      sb_index = from_sb.len;
      return partial_where;
    }

  *bufp = buffer_start + BEFORE_SIZE;

  if (partial_size)
    {
      memcpy (buffer_start + BEFORE_SIZE, partial_where,
             (unsigned int) partial_size);
      memcpy (buffer_start + BEFORE_SIZE, save_source, AFTER_SIZE);
    }
  limit = input_file_give_next_buffer (buffer_start
                                   + BEFORE_SIZE
                                   + partial_size);
  if (limit)
    {
      register char *p;            /* Find last newline.  */
      /* Terminate the buffer to avoid confusing TC_EOL_IN_INSN.  */
      *limit = '\0';
      for (p = limit - 1; *p != '\n' || TC_EOL_IN_INSN (p); --p)
       ;
      ++p;

      while (p <= buffer_start + BEFORE_SIZE)
       {
         int limoff;

         limoff = limit - buffer_start;
         buffer_length += input_file_buffer_size ();
         buffer_start = xrealloc (buffer_start,
                               (BEFORE_SIZE
                                + 2 * buffer_length
                                + AFTER_SIZE));
         *bufp = buffer_start + BEFORE_SIZE;
         limit = input_file_give_next_buffer (buffer_start + limoff);

         if (limit == NULL)
           {
             as_warn (_("partial line at end of file ignored"));
             partial_where = NULL;
             if (next_saved_file)
              *bufp = input_scrub_pop (next_saved_file);
             return NULL;
           }

         /* Terminate the buffer to avoid confusing TC_EOL_IN_INSN.  */
         *limit = '\0';
         for (p = limit - 1; *p != '\n' || TC_EOL_IN_INSN (p); --p)
           ;
         ++p;
       }

      partial_where = p;
      partial_size = limit - p;
      memcpy (save_source, partial_where, (int) AFTER_SIZE);
      memcpy (partial_where, AFTER_STRING, (int) AFTER_SIZE);
    }
  else
    {
      partial_where = 0;
      if (partial_size > 0)
       {
         as_warn (_("partial line at end of file ignored"));
       }

      /* Tell the listing we've finished the file.  */
      LISTING_EOF ();

      /* If we should pop to another file at EOF, do it.  */
      if (next_saved_file)
       {
         *bufp = input_scrub_pop (next_saved_file);     /* Pop state */
         /* partial_where is now correct to return, since we popped it.  */
       }
    }
  return (partial_where);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char * input_scrub_pop ( struct input_save arg) [static]

Definition at line 175 of file input-scrub.c.

{
  char *saved_position;

  input_scrub_end ();              /* Finish off old buffer */

  input_file_pop (saved->input_file_save);
  saved_position = saved->saved_position;
  buffer_start = saved->buffer_start;
  buffer_length = saved->buffer_length;
  physical_input_file = saved->physical_input_file;
  logical_input_file = saved->logical_input_file;
  physical_input_line = saved->physical_input_line;
  logical_input_line = saved->logical_input_line;
  sb_index = saved->sb_index;
  from_sb = saved->from_sb;
  from_sb_is_expansion = saved->from_sb_is_expansion;
  partial_where = saved->partial_where;
  partial_size = saved->partial_size;
  next_saved_file = saved->next_saved_file;
  memcpy (save_source, saved->save_source, sizeof (save_source));

  free (saved);
  return saved_position;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static struct input_save * input_scrub_push ( char *  saved_position) [static, read]

Definition at line 140 of file input-scrub.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int new_logical_line ( char *  fname,
int  line_number 
)

Definition at line 479 of file input-scrub.c.

{
  return new_logical_line_flags (fname, line_number, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int new_logical_line_flags ( char *  fname,
int  line_number,
int  flags 
)

Definition at line 438 of file input-scrub.c.

{
  switch (flags)
    {
    case 0:
      break;
    case 1:
      if (line_number != -1)
       abort ();
      break;
    case 1 << 1:
    case 1 << 2:
      /* FIXME: we could check that include nesting is correct.  */
      break;
    default:
      abort ();
    }

  if (line_number >= 0)
    logical_input_line = line_number;
  else if (line_number == -1 && fname && !*fname && (flags & (1 << 2)))
    {
      logical_input_file = physical_input_file;
      logical_input_line = physical_input_line;
      fname = NULL;
    }

  if (fname
      && (logical_input_file == NULL
         || strcmp (logical_input_file, fname)))
    {
      logical_input_file = fname;
      return 1;
    }
  else
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 413 of file input-scrub.c.

{
  return (physical_input_file != NULL);
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 74 of file input-scrub.c.

char* buffer_start [static]

Definition at line 63 of file input-scrub.c.

sb from_sb [static]

Definition at line 80 of file input-scrub.c.

int from_sb_is_expansion = 1 [static]

Definition at line 83 of file input-scrub.c.

char* logical_input_file [static]

Definition at line 100 of file input-scrub.c.

Definition at line 106 of file input-scrub.c.

Definition at line 86 of file input-scrub.c.

Definition at line 133 of file input-scrub.c.

int partial_size [static]

Definition at line 65 of file input-scrub.c.

char* partial_where [static]

Definition at line 64 of file input-scrub.c.

char* physical_input_file [static]

Definition at line 99 of file input-scrub.c.

Definition at line 105 of file input-scrub.c.

char save_source[AFTER_SIZE] [static]

Definition at line 70 of file input-scrub.c.

int sb_index = -1 [static]

Definition at line 77 of file input-scrub.c.