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

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gdb-6.8/] [pre-binutils-2.20.1-sync/] [sim/] [igen/] [table.c] - Diff between revs 157 and 223

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

Rev 157 Rev 223
/* The IGEN simulator generator for GDB, the GNU Debugger.
/* The IGEN simulator generator for GDB, the GNU Debugger.
 
 
   Copyright 2002, 2007, 2008 Free Software Foundation, Inc.
   Copyright 2002, 2007, 2008 Free Software Foundation, Inc.
 
 
   Contributed by Andrew Cagney.
   Contributed by Andrew Cagney.
 
 
   This file is part of GDB.
   This file is part of GDB.
 
 
   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 3 of the License, or
   the Free Software Foundation; either version 3 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, see <http://www.gnu.org/licenses/>.  */
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
 
 
 
 
#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 "config.h"
#include "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;
  line_ref pseudo_line;
  line_ref pseudo_line;
  line_ref real_line;
  line_ref real_line;
  open_table *parent;
  open_table *parent;
  table *root;
  table *root;
};
};
struct _table
struct _table
{
{
  open_table *current;
  open_table *current;
};
};
 
 
 
 
static line_ref *
static line_ref *
current_line (open_table * file)
current_line (open_table * file)
{
{
  line_ref *entry = ZALLOC (line_ref);
  line_ref *entry = ZALLOC (line_ref);
  *entry = file->pseudo_line;
  *entry = file->pseudo_line;
  return entry;
  return entry;
}
}
 
 
static table_entry *
static table_entry *
new_table_entry (open_table * file, table_entry_type type)
new_table_entry (open_table * file, table_entry_type type)
{
{
  table_entry *entry;
  table_entry *entry;
  entry = ZALLOC (table_entry);
  entry = ZALLOC (table_entry);
  entry->file = file->root;
  entry->file = file->root;
  entry->line = current_line (file);
  entry->line = current_line (file);
  entry->type = type;
  entry->type = type;
  return entry;
  return entry;
}
}
 
 
static void
static void
set_nr_table_entry_fields (table_entry *entry, int nr_fields)
set_nr_table_entry_fields (table_entry *entry, int nr_fields)
{
{
  entry->field = NZALLOC (char *, nr_fields + 1);
  entry->field = NZALLOC (char *, nr_fields + 1);
  entry->nr_fields = nr_fields;
  entry->nr_fields = nr_fields;
}
}
 
 
 
 
void
void
table_push (table *root,
table_push (table *root,
            line_ref *line, table_include *includes, const char *file_name)
            line_ref *line, table_include *includes, const char *file_name)
{
{
  FILE *ff;
  FILE *ff;
  open_table *file;
  open_table *file;
  table_include dummy;
  table_include dummy;
  table_include *include = &dummy;
  table_include *include = &dummy;
 
 
  /* 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);
  if (file == NULL)
  if (file == NULL)
    {
    {
      perror (file_name);
      perror (file_name);
      exit (1);
      exit (1);
    }
    }
  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 =
      char *dup_name =
        NZALLOC (char, strlen (include->dir) + strlen (file_name) + 2);
        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->real_line.file_name = dup_name;
      file->real_line.file_name = dup_name;
      file->pseudo_line.file_name = dup_name;
      file->pseudo_line.file_name = dup_name;
      /* open the file */
      /* open the file */
 
 
      ff = fopen (dup_name, "rb");
      ff = fopen (dup_name, "rb");
      if (ff)
      if (ff)
        break;
        break;
      /* zfree (dup_name); */
      /* zfree (dup_name); */
      if (include->next == NULL)
      if (include->next == NULL)
        {
        {
          if (line != NULL)
          if (line != NULL)
            error (line, "Problem opening file `%s'\n", file_name);
            error (line, "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 */
  fseek (ff, 0, SEEK_END);
  fseek (ff, 0, SEEK_END);
  file->size = ftell (ff);
  file->size = ftell (ff);
  fseek (ff, 0, SEEK_SET);
  fseek (ff, 0, SEEK_SET);
 
 
  /* 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 (file_name);
      perror (file_name);
      exit (1);
      exit (1);
    }
    }
  file->pos = file->buffer;
  file->pos = file->buffer;
 
 
  /* read it all in */
  /* read it all in */
  if (fread (file->buffer, 1, file->size, ff) < file->size)
  if (fread (file->buffer, 1, file->size, ff) < file->size)
    {
    {
      perror (file_name);
      perror (file_name);
      exit (1);
      exit (1);
    }
    }
  file->buffer[file->size] = '\0';
  file->buffer[file->size] = '\0';
 
 
  /* set the initial line numbering */
  /* set the initial line numbering */
  file->real_line.line_nr = 1;  /* specifies current line */
  file->real_line.line_nr = 1;  /* specifies current line */
  file->pseudo_line.line_nr = 1;        /* specifies current line */
  file->pseudo_line.line_nr = 1;        /* specifies current line */
 
 
  /* done */
  /* done */
  fclose (ff);
  fclose (ff);
}
}
 
 
table *
table *
table_open (const char *file_name)
table_open (const char *file_name)
{
{
  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, NULL, file_name);
  table_push (root, NULL, NULL, file_name);
  return root;
  return root;
}
}
 
 
char *
char *
skip_spaces (char *chp)
skip_spaces (char *chp)
{
{
  while (1)
  while (1)
    {
    {
      if (*chp == '\0' || *chp == '\n' || !isspace (*chp))
      if (*chp == '\0' || *chp == '\n' || !isspace (*chp))
        return chp;
        return chp;
      chp++;
      chp++;
    }
    }
}
}
 
 
 
 
char *
char *
back_spaces (char *start, char *chp)
back_spaces (char *start, char *chp)
{
{
  while (1)
  while (1)
    {
    {
      if (chp <= start || !isspace (chp[-1]))
      if (chp <= start || !isspace (chp[-1]))
        return chp;
        return chp;
      chp--;
      chp--;
    }
    }
}
}
 
 
char *
char *
skip_digits (char *chp)
skip_digits (char *chp)
{
{
  while (1)
  while (1)
    {
    {
      if (*chp == '\0' || *chp == '\n' || !isdigit (*chp))
      if (*chp == '\0' || *chp == '\n' || !isdigit (*chp))
        return chp;
        return chp;
      chp++;
      chp++;
    }
    }
}
}
 
 
char *
char *
skip_to_separator (char *chp, char *separators)
skip_to_separator (char *chp, char *separators)
{
{
  while (1)
  while (1)
    {
    {
      char *sep = separators;
      char *sep = separators;
      while (1)
      while (1)
        {
        {
          if (*chp == *sep)
          if (*chp == *sep)
            return chp;
            return chp;
          if (*sep == '\0')
          if (*sep == '\0')
            break;
            break;
          sep++;
          sep++;
        }
        }
      chp++;
      chp++;
    }
    }
}
}
 
 
static char *
static char *
skip_to_null (char *chp)
skip_to_null (char *chp)
{
{
  return skip_to_separator (chp, "");
  return skip_to_separator (chp, "");
}
}
 
 
 
 
static char *
static char *
skip_to_nl (char *chp)
skip_to_nl (char *chp)
{
{
  return skip_to_separator (chp, "\n");
  return skip_to_separator (chp, "\n");
}
}
 
 
 
 
static void
static void
next_line (open_table * file)
next_line (open_table * file)
{
{
  file->pos = skip_to_nl (file->pos);
  file->pos = skip_to_nl (file->pos);
  if (*file->pos == '0')
  if (*file->pos == '0')
    error (&file->pseudo_line, "Missing <nl> at end of line\n");
    error (&file->pseudo_line, "Missing <nl> at end of line\n");
  *file->pos = '\0';
  *file->pos = '\0';
  file->pos += 1;
  file->pos += 1;
  file->real_line.line_nr += 1;
  file->real_line.line_nr += 1;
  file->pseudo_line.line_nr += 1;
  file->pseudo_line.line_nr += 1;
}
}
 
 
 
 
extern table_entry *
extern table_entry *
table_read (table *root)
table_read (table *root)
{
{
  open_table *file = root->current;
  open_table *file = root->current;
  table_entry *entry = NULL;
  table_entry *entry = NULL;
  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;
        }
        }
 
 
      /* code_block? */
      /* code_block? */
      if (*file->pos == '{')
      if (*file->pos == '{')
        {
        {
          char *chp;
          char *chp;
          next_line (file);     /* discard leading brace */
          next_line (file);     /* discard leading brace */
          entry = new_table_entry (file, table_code_entry);
          entry = new_table_entry (file, table_code_entry);
          chp = file->pos;
          chp = file->pos;
          /* determine how many lines are involved - look for <nl> "}" */
          /* determine how many lines are involved - look for <nl> "}" */
          {
          {
            int nr_lines = 0;
            int nr_lines = 0;
            while (*file->pos != '}')
            while (*file->pos != '}')
              {
              {
                next_line (file);
                next_line (file);
                nr_lines++;
                nr_lines++;
              }
              }
            set_nr_table_entry_fields (entry, nr_lines);
            set_nr_table_entry_fields (entry, nr_lines);
          }
          }
          /* now enter each line */
          /* now enter each line */
          {
          {
            int line_nr;
            int line_nr;
            for (line_nr = 0; line_nr < entry->nr_fields; line_nr++)
            for (line_nr = 0; line_nr < entry->nr_fields; line_nr++)
              {
              {
                if (strncmp (chp, "  ", 2) == 0)
                if (strncmp (chp, "  ", 2) == 0)
                  entry->field[line_nr] = chp + 2;
                  entry->field[line_nr] = chp + 2;
                else
                else
                  entry->field[line_nr] = chp;
                  entry->field[line_nr] = chp;
                chp = skip_to_null (chp) + 1;
                chp = skip_to_null (chp) + 1;
              }
              }
            /* skip trailing brace */
            /* skip trailing brace */
            ASSERT (*file->pos == '}');
            ASSERT (*file->pos == '}');
            next_line (file);
            next_line (file);
          }
          }
          break;
          break;
        }
        }
 
 
      /* tab block? */
      /* tab block? */
      if (*file->pos == '\t')
      if (*file->pos == '\t')
        {
        {
          char *chp = file->pos;
          char *chp = file->pos;
          entry = new_table_entry (file, table_code_entry);
          entry = new_table_entry (file, table_code_entry);
          /* determine how many lines are involved - look for <nl> !<tab> */
          /* determine how many lines are involved - look for <nl> !<tab> */
          {
          {
            int nr_lines = 0;
            int nr_lines = 0;
            int nr_blank_lines = 0;
            int nr_blank_lines = 0;
            while (1)
            while (1)
              {
              {
                if (*file->pos == '\t')
                if (*file->pos == '\t')
                  {
                  {
                    nr_lines = nr_lines + nr_blank_lines + 1;
                    nr_lines = nr_lines + nr_blank_lines + 1;
                    nr_blank_lines = 0;
                    nr_blank_lines = 0;
                    next_line (file);
                    next_line (file);
                  }
                  }
                else
                else
                  {
                  {
                    file->pos = skip_spaces (file->pos);
                    file->pos = skip_spaces (file->pos);
                    if (*file->pos != '\n')
                    if (*file->pos != '\n')
                      break;
                      break;
                    nr_blank_lines++;
                    nr_blank_lines++;
                    next_line (file);
                    next_line (file);
                  }
                  }
              }
              }
            set_nr_table_entry_fields (entry, nr_lines);
            set_nr_table_entry_fields (entry, nr_lines);
          }
          }
          /* now enter each line */
          /* now enter each line */
          {
          {
            int line_nr;
            int line_nr;
            for (line_nr = 0; line_nr < entry->nr_fields; line_nr++)
            for (line_nr = 0; line_nr < entry->nr_fields; line_nr++)
              {
              {
                if (*chp == '\t')
                if (*chp == '\t')
                  entry->field[line_nr] = chp + 1;
                  entry->field[line_nr] = chp + 1;
                else
                else
                  entry->field[line_nr] = "";   /* blank */
                  entry->field[line_nr] = "";   /* blank */
                chp = skip_to_null (chp) + 1;
                chp = skip_to_null (chp) + 1;
              }
              }
          }
          }
          break;
          break;
        }
        }
 
 
      /* cpp directive? */
      /* cpp directive? */
      if (file->pos[0] == '#')
      if (file->pos[0] == '#')
        {
        {
          char *chp = skip_spaces (file->pos + 1);
          char *chp = skip_spaces (file->pos + 1);
 
 
          /* cpp line-nr directive - # <line-nr> "<file>" */
          /* cpp line-nr directive - # <line-nr> "<file>" */
          if (isdigit (*chp)
          if (isdigit (*chp)
              && *skip_digits (chp) == ' '
              && *skip_digits (chp) == ' '
              && *skip_spaces (skip_digits (chp)) == '"')
              && *skip_spaces (skip_digits (chp)) == '"')
            {
            {
              int line_nr;
              int line_nr;
              char *file_name;
              char *file_name;
              file->pos = chp;
              file->pos = chp;
              /* parse the number */
              /* parse the number */
              line_nr = atoi (file->pos) - 1;
              line_nr = atoi (file->pos) - 1;
              /* skip to the file name */
              /* skip to the file name */
              while (file->pos[0] != '0'
              while (file->pos[0] != '0'
                     && file->pos[0] != '"' && file->pos[0] != '\0')
                     && file->pos[0] != '"' && file->pos[0] != '\0')
                file->pos++;
                file->pos++;
              if (file->pos[0] != '"')
              if (file->pos[0] != '"')
                error (&file->real_line,
                error (&file->real_line,
                       "Missing opening quote in cpp directive\n");
                       "Missing opening quote in cpp directive\n");
              /* parse the file name */
              /* parse the file name */
              file->pos++;
              file->pos++;
              file_name = file->pos;
              file_name = file->pos;
              while (file->pos[0] != '"' && file->pos[0] != '\0')
              while (file->pos[0] != '"' && file->pos[0] != '\0')
                file->pos++;
                file->pos++;
              if (file->pos[0] != '"')
              if (file->pos[0] != '"')
                error (&file->real_line,
                error (&file->real_line,
                       "Missing closing quote in cpp directive\n");
                       "Missing closing quote in cpp directive\n");
              file->pos[0] = '\0';
              file->pos[0] = '\0';
              file->pos++;
              file->pos++;
              file->pos = skip_to_nl (file->pos);
              file->pos = skip_to_nl (file->pos);
              if (file->pos[0] != '\n')
              if (file->pos[0] != '\n')
                error (&file->real_line,
                error (&file->real_line,
                       "Missing newline in cpp directive\n");
                       "Missing newline in cpp directive\n");
              file->pseudo_line.file_name = file_name;
              file->pseudo_line.file_name = file_name;
              file->pseudo_line.line_nr = line_nr;
              file->pseudo_line.line_nr = line_nr;
              next_line (file);
              next_line (file);
              continue;
              continue;
            }
            }
 
 
          /* #define and #undef - not implemented yet */
          /* #define and #undef - not implemented yet */
 
 
          /* Old style # comment */
          /* Old style # comment */
          next_line (file);
          next_line (file);
          continue;
          continue;
        }
        }
 
 
      /* blank line or end-of-file? */
      /* blank line or end-of-file? */
      file->pos = skip_spaces (file->pos);
      file->pos = skip_spaces (file->pos);
      if (*file->pos == '\0')
      if (*file->pos == '\0')
        error (&file->pseudo_line, "Missing <nl> at end of file\n");
        error (&file->pseudo_line, "Missing <nl> at end of file\n");
      if (*file->pos == '\n')
      if (*file->pos == '\n')
        {
        {
          next_line (file);
          next_line (file);
          continue;
          continue;
        }
        }
 
 
      /* comment - leading // or # - skip */
      /* comment - leading // or # - skip */
      if ((file->pos[0] == '/' && file->pos[1] == '/')
      if ((file->pos[0] == '/' && file->pos[1] == '/')
          || (file->pos[0] == '#'))
          || (file->pos[0] == '#'))
        {
        {
          next_line (file);
          next_line (file);
          continue;
          continue;
        }
        }
 
 
      /* colon field */
      /* colon field */
      {
      {
        char *chp = file->pos;
        char *chp = file->pos;
        entry = new_table_entry (file, table_colon_entry);
        entry = new_table_entry (file, table_colon_entry);
        next_line (file);
        next_line (file);
        /* figure out how many fields */
        /* figure out how many fields */
        {
        {
          int nr_fields = 1;
          int nr_fields = 1;
          char *tmpch = chp;
          char *tmpch = chp;
          while (1)
          while (1)
            {
            {
              tmpch = skip_to_separator (tmpch, "\\:");
              tmpch = skip_to_separator (tmpch, "\\:");
              if (*tmpch == '\\')
              if (*tmpch == '\\')
                {
                {
                  /* eat the escaped character */
                  /* eat the escaped character */
                  char *cp = tmpch;
                  char *cp = tmpch;
                  while (cp[1] != '\0')
                  while (cp[1] != '\0')
                    {
                    {
                      cp[0] = cp[1];
                      cp[0] = cp[1];
                      cp++;
                      cp++;
                    }
                    }
                  cp[0] = '\0';
                  cp[0] = '\0';
                  tmpch++;
                  tmpch++;
                }
                }
              else if (*tmpch != ':')
              else if (*tmpch != ':')
                break;
                break;
              else
              else
                {
                {
                  *tmpch = '\0';
                  *tmpch = '\0';
                  tmpch++;
                  tmpch++;
                  nr_fields++;
                  nr_fields++;
                }
                }
            }
            }
          set_nr_table_entry_fields (entry, nr_fields);
          set_nr_table_entry_fields (entry, nr_fields);
        }
        }
        /* now parse them */
        /* now parse them */
        {
        {
          int field_nr;
          int field_nr;
          for (field_nr = 0; field_nr < entry->nr_fields; field_nr++)
          for (field_nr = 0; field_nr < entry->nr_fields; field_nr++)
            {
            {
              chp = skip_spaces (chp);
              chp = skip_spaces (chp);
              entry->field[field_nr] = chp;
              entry->field[field_nr] = chp;
              chp = skip_to_null (chp);
              chp = skip_to_null (chp);
              *back_spaces (entry->field[field_nr], chp) = '\0';
              *back_spaces (entry->field[field_nr], chp) = '\0';
              chp++;
              chp++;
            }
            }
        }
        }
        break;
        break;
      }
      }
 
 
    }
    }
 
 
  ASSERT (entry == NULL || entry->field[entry->nr_fields] == NULL);
  ASSERT (entry == NULL || entry->field[entry->nr_fields] == NULL);
  return entry;
  return entry;
}
}
 
 
extern void
extern void
table_print_code (lf *file, table_entry *entry)
table_print_code (lf *file, table_entry *entry)
{
{
  int field_nr;
  int field_nr;
  int nr = 0;
  int nr = 0;
  for (field_nr = 0; field_nr < entry->nr_fields; field_nr++)
  for (field_nr = 0; field_nr < entry->nr_fields; field_nr++)
    {
    {
      char *chp = entry->field[field_nr];
      char *chp = entry->field[field_nr];
      int in_bit_field = 0;
      int in_bit_field = 0;
      if (*chp == '#')
      if (*chp == '#')
        lf_indent_suppress (file);
        lf_indent_suppress (file);
      while (*chp != '\0')
      while (*chp != '\0')
        {
        {
          if (chp[0] == '{' && !isspace (chp[1]) && chp[1] != '\0')
          if (chp[0] == '{' && !isspace (chp[1]) && chp[1] != '\0')
            {
            {
              in_bit_field = 1;
              in_bit_field = 1;
              nr += lf_putchr (file, '_');
              nr += lf_putchr (file, '_');
            }
            }
          else if (in_bit_field && chp[0] == ':')
          else if (in_bit_field && chp[0] == ':')
            {
            {
              nr += lf_putchr (file, '_');
              nr += lf_putchr (file, '_');
            }
            }
          else if (in_bit_field && *chp == '}')
          else if (in_bit_field && *chp == '}')
            {
            {
              nr += lf_putchr (file, '_');
              nr += lf_putchr (file, '_');
              in_bit_field = 0;
              in_bit_field = 0;
            }
            }
          else
          else
            {
            {
              nr += lf_putchr (file, *chp);
              nr += lf_putchr (file, *chp);
            }
            }
          chp++;
          chp++;
        }
        }
      if (in_bit_field)
      if (in_bit_field)
        {
        {
          line_ref line = *entry->line;
          line_ref line = *entry->line;
          line.line_nr += field_nr;
          line.line_nr += field_nr;
          error (&line, "Bit field brace miss match\n");
          error (&line, "Bit field brace miss match\n");
        }
        }
      nr += lf_putchr (file, '\n');
      nr += lf_putchr (file, '\n');
    }
    }
}
}
 
 
 
 
 
 
void
void
dump_line_ref (lf *file, char *prefix, const line_ref *line, char *suffix)
dump_line_ref (lf *file, char *prefix, const line_ref *line, char *suffix)
{
{
  lf_printf (file, "%s(line_ref*) 0x%lx", prefix, (long) line);
  lf_printf (file, "%s(line_ref*) 0x%lx", prefix, (long) line);
  if (line != NULL)
  if (line != NULL)
    {
    {
      lf_indent (file, +1);
      lf_indent (file, +1);
      lf_printf (file, "\n(line_nr %d)", line->line_nr);
      lf_printf (file, "\n(line_nr %d)", line->line_nr);
      lf_printf (file, "\n(file_name %s)", line->file_name);
      lf_printf (file, "\n(file_name %s)", line->file_name);
      lf_indent (file, -1);
      lf_indent (file, -1);
    }
    }
  lf_printf (file, "%s", suffix);
  lf_printf (file, "%s", suffix);
}
}
 
 
 
 
static const char *
static const char *
table_entry_type_to_str (table_entry_type type)
table_entry_type_to_str (table_entry_type type)
{
{
  switch (type)
  switch (type)
    {
    {
    case table_code_entry:
    case table_code_entry:
      return "code-entry";
      return "code-entry";
    case table_colon_entry:
    case table_colon_entry:
      return "colon-entry";
      return "colon-entry";
    }
    }
  return "*invalid*";
  return "*invalid*";
}
}
 
 
void
void
dump_table_entry (lf *file,
dump_table_entry (lf *file,
                  char *prefix, const table_entry *entry, char *suffix)
                  char *prefix, const table_entry *entry, char *suffix)
{
{
  lf_printf (file, "%s(table_entry*) 0x%lx", prefix, (long) entry);
  lf_printf (file, "%s(table_entry*) 0x%lx", prefix, (long) entry);
  if (entry != NULL)
  if (entry != NULL)
    {
    {
      int field;
      int field;
      lf_indent (file, +1);
      lf_indent (file, +1);
      dump_line_ref (file, "\n(line ", entry->line, ")");
      dump_line_ref (file, "\n(line ", entry->line, ")");
      lf_printf (file, "\n(type %s)", table_entry_type_to_str (entry->type));
      lf_printf (file, "\n(type %s)", table_entry_type_to_str (entry->type));
      lf_printf (file, "\n(nr_fields %d)", entry->nr_fields);
      lf_printf (file, "\n(nr_fields %d)", entry->nr_fields);
      lf_printf (file, "\n(fields");
      lf_printf (file, "\n(fields");
      lf_indent (file, +1);
      lf_indent (file, +1);
      for (field = 0; field < entry->nr_fields; field++)
      for (field = 0; field < entry->nr_fields; field++)
        lf_printf (file, "\n\"%s\"", entry->field[field]);
        lf_printf (file, "\n\"%s\"", entry->field[field]);
      lf_indent (file, -1);
      lf_indent (file, -1);
      lf_printf (file, ")");
      lf_printf (file, ")");
      lf_indent (file, -1);
      lf_indent (file, -1);
    }
    }
  lf_printf (file, "%s", suffix);
  lf_printf (file, "%s", suffix);
}
}
 
 
 
 
#ifdef MAIN
#ifdef MAIN
int
int
main (int argc, char **argv)
main (int argc, char **argv)
{
{
  table *t;
  table *t;
  table_entry *entry;
  table_entry *entry;
  lf *l;
  lf *l;
  int line_nr;
  int line_nr;
 
 
  if (argc != 2)
  if (argc != 2)
    {
    {
      printf ("Usage: table <file>\n");
      printf ("Usage: table <file>\n");
      exit (1);
      exit (1);
    }
    }
 
 
  t = table_open (argv[1]);
  t = table_open (argv[1]);
  l = lf_open ("-", "stdout", lf_omit_references, lf_is_text, "tmp-table");
  l = lf_open ("-", "stdout", lf_omit_references, lf_is_text, "tmp-table");
 
 
  line_nr = 0;
  line_nr = 0;
  do
  do
    {
    {
      char line[10];
      char line[10];
      entry = table_read (t);
      entry = table_read (t);
      line_nr++;
      line_nr++;
      sprintf (line, "(%d ", line_nr);
      sprintf (line, "(%d ", line_nr);
      dump_table_entry (l, line, entry, ")\n");
      dump_table_entry (l, line, entry, ")\n");
    }
    }
  while (entry != NULL);
  while (entry != NULL);
 
 
  return 0;
  return 0;
}
}
#endif
#endif
 
 

powered by: WebSVN 2.1.0

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