OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [sim/] [ppc/] [table.c] - Diff between revs 834 and 842

Only display areas with differences | Details | Blame | View Log

Rev 834 Rev 842
/*  This file is part of the program psim.
/*  This file is part of the program psim.
 
 
    Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
    Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
 
 
    This program is free software; you can redistribute it and/or modify
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    (at your option) any later version.
 
 
    This program is distributed in the hope that it will be useful,
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    GNU General Public License for more details.
 
 
    You should have received a copy of the GNU General Public License
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 
    */
    */
 
 
 
 
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdio.h>
#include <fcntl.h>
#include <fcntl.h>
#include <ctype.h>
#include <ctype.h>
 
 
#include "build-config.h"
#include "build-config.h"
#include "misc.h"
#include "misc.h"
#include "lf.h"
#include "lf.h"
#include "table.h"
#include "table.h"
 
 
#ifdef HAVE_UNISTD_H
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#include <unistd.h>
#endif
#endif
 
 
#ifdef HAVE_STDLIB_H
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#include <stdlib.h>
#endif
#endif
 
 
typedef struct _open_table open_table;
typedef struct _open_table open_table;
struct _open_table {
struct _open_table {
  size_t size;
  size_t size;
  char *buffer;
  char *buffer;
  char *pos;
  char *pos;
  int line_nr;
  int line_nr;
  int nr_fields;
  int nr_fields;
  int nr_model_fields;
  int nr_model_fields;
  char *file_name;
  char *file_name;
  open_table *parent;
  open_table *parent;
  table *root;
  table *root;
};
};
struct _table {
struct _table {
  open_table *current;
  open_table *current;
};
};
 
 
void
void
table_push (table *root,
table_push (table *root,
            table_include *includes,
            table_include *includes,
            const char *file_name,
            const char *file_name,
            int nr_fields,
            int nr_fields,
            int nr_model_fields)
            int nr_model_fields)
 
 
{
{
  int fd;
  int fd;
  struct stat stat_buf;
  struct stat stat_buf;
  open_table *file;
  open_table *file;
  table_include dummy;
  table_include dummy;
  table_include *include = &dummy;
  table_include *include = &dummy;
  int nr;
  int nr;
 
 
  /* dummy up a search of this directory */
  /* dummy up a search of this directory */
  dummy.next = includes;
  dummy.next = includes;
  dummy.dir = "";
  dummy.dir = "";
 
 
  /* create a file descriptor */
  /* create a file descriptor */
  file = ZALLOC (open_table);
  file = ZALLOC (open_table);
  ASSERT(file != NULL);
  ASSERT(file != NULL);
  file->nr_fields = nr_fields;
  file->nr_fields = nr_fields;
  file->nr_model_fields = nr_model_fields;
  file->nr_model_fields = nr_model_fields;
  file->root = root;
  file->root = root;
  file->parent = root->current;
  file->parent = root->current;
  root->current = file;
  root->current = file;
 
 
  while (1)
  while (1)
    {
    {
      /* save the file name */
      /* save the file name */
      char *dup_name = NZALLOC (char, strlen (include->dir) + strlen (file_name) + 2);
      char *dup_name = NZALLOC (char, strlen (include->dir) + strlen (file_name) + 2);
      if (dup_name == NULL)
      if (dup_name == NULL)
        {
        {
          perror (file_name);
          perror (file_name);
          exit (1);
          exit (1);
        }
        }
      if (include->dir[0] != '\0')
      if (include->dir[0] != '\0')
        {
        {
          strcat (dup_name, include->dir);
          strcat (dup_name, include->dir);
          strcat (dup_name, "/");
          strcat (dup_name, "/");
        }
        }
      strcat (dup_name, file_name);
      strcat (dup_name, file_name);
      file->file_name = dup_name;
      file->file_name = dup_name;
      /* open the file */
      /* open the file */
      fd = open (dup_name, O_RDONLY, 0);
      fd = open (dup_name, O_RDONLY, 0);
      if (fd >= 0)
      if (fd >= 0)
        break;
        break;
      /* zfree (dup_name); */
      /* zfree (dup_name); */
      if (include->next == NULL)
      if (include->next == NULL)
        {
        {
          error ("Problem opening file `%s'\n", file_name);
          error ("Problem opening file `%s'\n", file_name);
          perror (file_name);
          perror (file_name);
          exit (1);
          exit (1);
        }
        }
      include = include->next;
      include = include->next;
  }
  }
 
 
  /* determine the size */
  /* determine the size */
  if (fstat(fd, &stat_buf) < 0) {
  if (fstat(fd, &stat_buf) < 0) {
    perror("table_open.fstat");
    perror("table_open.fstat");
    exit(1);
    exit(1);
  }
  }
  file->size = stat_buf.st_size;
  file->size = stat_buf.st_size;
 
 
  /* allocate this much memory */
  /* allocate this much memory */
  file->buffer = (char*)zalloc(file->size+1);
  file->buffer = (char*)zalloc(file->size+1);
  if(file->buffer == NULL) {
  if(file->buffer == NULL) {
    perror("table_open.calloc.file->size+1");
    perror("table_open.calloc.file->size+1");
    exit(1);
    exit(1);
  }
  }
  file->pos = file->buffer;
  file->pos = file->buffer;
 
 
  /* read it in */
  /* read it in */
#ifdef __CYGWIN32__
#ifdef __CYGWIN32__
  if ((file->size) && ((nr = read(fd, file->buffer, file->size)) <= 0)) {
  if ((file->size) && ((nr = read(fd, file->buffer, file->size)) <= 0)) {
#else
#else
  if ((nr = read(fd, file->buffer, file->size)) < file->size) {
  if ((nr = read(fd, file->buffer, file->size)) < file->size) {
#endif
#endif
    perror("table_open.read");
    perror("table_open.read");
    exit(1);
    exit(1);
  }
  }
  file->size = nr;
  file->size = nr;
  file->buffer[file->size] = '\0';
  file->buffer[file->size] = '\0';
 
 
  /* done */
  /* done */
  close(fd);
  close(fd);
}
}
 
 
extern table *
extern table *
table_open(const char *file_name,
table_open(const char *file_name,
           int nr_fields,
           int nr_fields,
           int nr_model_fields)
           int nr_model_fields)
{
{
  table *root;
  table *root;
 
 
  /* create a file descriptor */
  /* create a file descriptor */
  root = ZALLOC (table);
  root = ZALLOC (table);
  if (root == NULL)
  if (root == NULL)
    {
    {
      perror (file_name);
      perror (file_name);
      exit (1);
      exit (1);
    }
    }
 
 
  table_push (root, NULL, file_name, nr_fields, nr_model_fields);
  table_push (root, NULL, file_name, nr_fields, nr_model_fields);
  return root;
  return root;
}
}
 
 
extern table_entry *
extern table_entry *
table_entry_read(table *root)
table_entry_read(table *root)
{
{
  open_table *file = root->current;
  open_table *file = root->current;
  int field;
  int field;
  table_entry *entry;
  table_entry *entry;
 
 
  /* skip comments/blanks */
  /* skip comments/blanks */
  while(1) {
  while(1) {
    /* end-of-file? */
    /* end-of-file? */
    while (*file->pos == '\0')
    while (*file->pos == '\0')
      {
      {
        if (file->parent != NULL)
        if (file->parent != NULL)
          {
          {
            file = file->parent;
            file = file->parent;
            root->current = file;
            root->current = file;
          }
          }
        else
        else
          return NULL;
          return NULL;
      }
      }
    /* leading white space */
    /* leading white space */
    while (*file->pos != '\0'
    while (*file->pos != '\0'
           && *file->pos != '\n'
           && *file->pos != '\n'
           && isspace(*file->pos))
           && isspace(*file->pos))
      file->pos++;
      file->pos++;
    /* comment */
    /* comment */
    if (*file->pos == '#') {
    if (*file->pos == '#') {
      do {
      do {
        file->pos++;
        file->pos++;
      } while (*file->pos != '\0' && *file->pos != '\n');
      } while (*file->pos != '\0' && *file->pos != '\n');
    }
    }
    /* end of line? */
    /* end of line? */
    if (*file->pos == '\n') {
    if (*file->pos == '\n') {
      file->pos++;
      file->pos++;
      file->line_nr++;
      file->line_nr++;
    }
    }
    else
    else
      break;
      break;
  }
  }
 
 
  /* create this new entry */
  /* create this new entry */
  entry = (table_entry*)zalloc(sizeof(table_entry)
  entry = (table_entry*)zalloc(sizeof(table_entry)
                               + (file->nr_fields + 1) * sizeof(char*));
                               + (file->nr_fields + 1) * sizeof(char*));
  ASSERT(entry != NULL);
  ASSERT(entry != NULL);
  entry->file_name = file->file_name;
  entry->file_name = file->file_name;
  entry->nr_fields = file->nr_fields;
  entry->nr_fields = file->nr_fields;
 
 
  /* break the line into its colon delimitered fields */
  /* break the line into its colon delimitered fields */
  for (field = 0; field < file->nr_fields-1; field++) {
  for (field = 0; field < file->nr_fields-1; field++) {
    entry->fields[field] = file->pos;
    entry->fields[field] = file->pos;
    while(*file->pos && *file->pos != ':' && *file->pos != '\n')
    while(*file->pos && *file->pos != ':' && *file->pos != '\n')
      file->pos++;
      file->pos++;
    if (*file->pos == ':') {
    if (*file->pos == ':') {
      *file->pos = '\0';
      *file->pos = '\0';
      file->pos++;
      file->pos++;
    }
    }
  }
  }
 
 
  /* any trailing stuff not the last field */
  /* any trailing stuff not the last field */
  ASSERT(field == file->nr_fields-1);
  ASSERT(field == file->nr_fields-1);
  entry->fields[field] = file->pos;
  entry->fields[field] = file->pos;
  while (*file->pos && *file->pos != '\n') {
  while (*file->pos && *file->pos != '\n') {
    file->pos++;
    file->pos++;
  }
  }
  if (*file->pos == '\n') {
  if (*file->pos == '\n') {
    *file->pos = '\0';
    *file->pos = '\0';
    file->pos++;
    file->pos++;
  }
  }
  file->line_nr++;
  file->line_nr++;
 
 
  /* if following lines begin with a star, add them to the model
  /* if following lines begin with a star, add them to the model
     section.  */
     section.  */
  while ((file->nr_model_fields > 0) && (*file->pos == '*')) {
  while ((file->nr_model_fields > 0) && (*file->pos == '*')) {
    table_model_entry *model = (table_model_entry*)zalloc(sizeof(table_model_entry)
    table_model_entry *model = (table_model_entry*)zalloc(sizeof(table_model_entry)
                                                          + (file->nr_model_fields + 1) * sizeof(char*));
                                                          + (file->nr_model_fields + 1) * sizeof(char*));
    if (entry->model_last)
    if (entry->model_last)
      entry->model_last->next = model;
      entry->model_last->next = model;
    else
    else
      entry->model_first = model;
      entry->model_first = model;
    entry->model_last = model;
    entry->model_last = model;
 
 
    /* break the line into its colon delimitered fields */
    /* break the line into its colon delimitered fields */
    file->pos++;
    file->pos++;
    for (field = 0; field < file->nr_model_fields-1; field++) {
    for (field = 0; field < file->nr_model_fields-1; field++) {
      model->fields[field] = file->pos;
      model->fields[field] = file->pos;
      while(*file->pos && *file->pos != ':' && *file->pos != '\n')
      while(*file->pos && *file->pos != ':' && *file->pos != '\n')
        file->pos++;
        file->pos++;
      if (*file->pos == ':') {
      if (*file->pos == ':') {
        *file->pos = '\0';
        *file->pos = '\0';
        file->pos++;
        file->pos++;
      }
      }
    }
    }
 
 
    /* any trailing stuff not the last field */
    /* any trailing stuff not the last field */
    ASSERT(field == file->nr_model_fields-1);
    ASSERT(field == file->nr_model_fields-1);
    model->fields[field] = file->pos;
    model->fields[field] = file->pos;
    while (*file->pos && *file->pos != '\n') {
    while (*file->pos && *file->pos != '\n') {
      file->pos++;
      file->pos++;
    }
    }
    if (*file->pos == '\n') {
    if (*file->pos == '\n') {
      *file->pos = '\0';
      *file->pos = '\0';
      file->pos++;
      file->pos++;
    }
    }
 
 
    file->line_nr++;
    file->line_nr++;
    model->line_nr = file->line_nr;
    model->line_nr = file->line_nr;
  }
  }
 
 
  entry->line_nr = file->line_nr;
  entry->line_nr = file->line_nr;
 
 
  /* if following lines are tab indented, put in the annex */
  /* if following lines are tab indented, put in the annex */
  if (*file->pos == '\t') {
  if (*file->pos == '\t') {
    entry->annex = file->pos;
    entry->annex = file->pos;
    do {
    do {
      do {
      do {
        file->pos++;
        file->pos++;
      } while (*file->pos != '\0' && *file->pos != '\n');
      } while (*file->pos != '\0' && *file->pos != '\n');
      if (*file->pos == '\n') {
      if (*file->pos == '\n') {
        char *save_pos = ++file->pos;
        char *save_pos = ++file->pos;
        int extra_lines = 0;
        int extra_lines = 0;
        file->line_nr++;
        file->line_nr++;
        /* Allow tab indented to have blank lines */
        /* Allow tab indented to have blank lines */
        while (*save_pos == '\n') {
        while (*save_pos == '\n') {
          save_pos++;
          save_pos++;
          extra_lines++;
          extra_lines++;
        }
        }
        if (*save_pos == '\t') {
        if (*save_pos == '\t') {
          file->pos = save_pos;
          file->pos = save_pos;
          file->line_nr += extra_lines;
          file->line_nr += extra_lines;
        }
        }
      }
      }
    } while (*file->pos != '\0' && *file->pos == '\t');
    } while (*file->pos != '\0' && *file->pos == '\t');
    if (file->pos[-1] == '\n')
    if (file->pos[-1] == '\n')
      file->pos[-1] = '\0';
      file->pos[-1] = '\0';
  }
  }
  else
  else
    entry->annex = NULL;
    entry->annex = NULL;
 
 
  /* return it */
  /* return it */
  return entry;
  return entry;
 
 
}
}
 
 
 
 
extern void
extern void
dump_table_entry(table_entry *entry,
dump_table_entry(table_entry *entry,
                 int indent)
                 int indent)
{
{
  printf("(table_entry*)%p\n", entry);
  printf("(table_entry*)%p\n", entry);
 
 
  if (entry != NULL) {
  if (entry != NULL) {
    int field;
    int field;
    char sep;
    char sep;
 
 
    sep = ' ';
    sep = ' ';
    dumpf(indent, "(fields");
    dumpf(indent, "(fields");
    for (field = 0; field < entry->nr_fields; field++) {
    for (field = 0; field < entry->nr_fields; field++) {
      printf("%c%s", sep, entry->fields[field]);
      printf("%c%s", sep, entry->fields[field]);
      sep = ':';
      sep = ':';
    }
    }
    printf(")\n");
    printf(")\n");
 
 
    dumpf(indent, "(line_nr %d)\n", entry->line_nr);
    dumpf(indent, "(line_nr %d)\n", entry->line_nr);
 
 
    dumpf(indent, "(file_name %s)\n", entry->file_name);
    dumpf(indent, "(file_name %s)\n", entry->file_name);
 
 
    dumpf(indent, "(annex\n%s\n", entry->annex);
    dumpf(indent, "(annex\n%s\n", entry->annex);
    dumpf(indent, " )\n");
    dumpf(indent, " )\n");
 
 
  }
  }
}
}
 
 
 
 
extern void
extern void
table_entry_print_cpp_line_nr(lf *file,
table_entry_print_cpp_line_nr(lf *file,
                              table_entry *entry)
                              table_entry *entry)
{
{
  lf_print__external_reference(file, entry->line_nr, entry->file_name);
  lf_print__external_reference(file, entry->line_nr, entry->file_name);
}
}
 
 
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.