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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [binutils-2.18.50/] [ld/] [deffilep.y] - Diff between revs 156 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 156 Rev 816
%{ /* deffilep.y - parser for .def files */
%{ /* deffilep.y - parser for .def files */
/*   Copyright 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007
/*   Copyright 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007
     Free Software Foundation, Inc.
     Free Software Foundation, Inc.
     This file is part of GNU Binutils.
     This file is part of GNU Binutils.
     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, write to the Free Software
     along with this program; if not, write to the Free Software
     Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     MA 02110-1301, USA.  */
     MA 02110-1301, USA.  */
#include "sysdep.h"
#include "sysdep.h"
#include "libiberty.h"
#include "libiberty.h"
#include "safe-ctype.h"
#include "safe-ctype.h"
#include "bfd.h"
#include "bfd.h"
#include "ld.h"
#include "ld.h"
#include "ldmisc.h"
#include "ldmisc.h"
#include "deffile.h"
#include "deffile.h"
#define TRACE 0
#define TRACE 0
#define ROUND_UP(a, b) (((a)+((b)-1))&~((b)-1))
#define ROUND_UP(a, b) (((a)+((b)-1))&~((b)-1))
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
   as well as gratuitiously global symbol names, so we can have multiple
   as well as gratuitiously global symbol names, so we can have multiple
   yacc generated parsers in ld.  Note that these are only the variables
   yacc generated parsers in ld.  Note that these are only the variables
   produced by yacc.  If other parser generators (bison, byacc, etc) produce
   produced by yacc.  If other parser generators (bison, byacc, etc) produce
   additional global names that conflict at link time, then those parser
   additional global names that conflict at link time, then those parser
   generators need to be fixed instead of adding those names to this list.  */
   generators need to be fixed instead of adding those names to this list.  */
#define yymaxdepth def_maxdepth
#define yymaxdepth def_maxdepth
#define yyparse def_parse
#define yyparse def_parse
#define yylex   def_lex
#define yylex   def_lex
#define yyerror def_error
#define yyerror def_error
#define yylval  def_lval
#define yylval  def_lval
#define yychar  def_char
#define yychar  def_char
#define yydebug def_debug
#define yydebug def_debug
#define yypact  def_pact
#define yypact  def_pact
#define yyr1    def_r1
#define yyr1    def_r1
#define yyr2    def_r2
#define yyr2    def_r2
#define yydef   def_def
#define yydef   def_def
#define yychk   def_chk
#define yychk   def_chk
#define yypgo   def_pgo
#define yypgo   def_pgo
#define yyact   def_act
#define yyact   def_act
#define yyexca  def_exca
#define yyexca  def_exca
#define yyerrflag def_errflag
#define yyerrflag def_errflag
#define yynerrs def_nerrs
#define yynerrs def_nerrs
#define yyps    def_ps
#define yyps    def_ps
#define yypv    def_pv
#define yypv    def_pv
#define yys     def_s
#define yys     def_s
#define yy_yys  def_yys
#define yy_yys  def_yys
#define yystate def_state
#define yystate def_state
#define yytmp   def_tmp
#define yytmp   def_tmp
#define yyv     def_v
#define yyv     def_v
#define yy_yyv  def_yyv
#define yy_yyv  def_yyv
#define yyval   def_val
#define yyval   def_val
#define yylloc  def_lloc
#define yylloc  def_lloc
#define yyreds  def_reds                /* With YYDEBUG defined.  */
#define yyreds  def_reds                /* With YYDEBUG defined.  */
#define yytoks  def_toks                /* With YYDEBUG defined.  */
#define yytoks  def_toks                /* With YYDEBUG defined.  */
#define yylhs   def_yylhs
#define yylhs   def_yylhs
#define yylen   def_yylen
#define yylen   def_yylen
#define yydefred def_yydefred
#define yydefred def_yydefred
#define yydgoto def_yydgoto
#define yydgoto def_yydgoto
#define yysindex def_yysindex
#define yysindex def_yysindex
#define yyrindex def_yyrindex
#define yyrindex def_yyrindex
#define yygindex def_yygindex
#define yygindex def_yygindex
#define yytable  def_yytable
#define yytable  def_yytable
#define yycheck  def_yycheck
#define yycheck  def_yycheck
static void def_description (const char *);
static void def_description (const char *);
static void def_exports (const char *, const char *, int, int);
static void def_exports (const char *, const char *, int, int);
static void def_heapsize (int, int);
static void def_heapsize (int, int);
static void def_import (const char *, const char *, const char *, const char *,
static void def_import (const char *, const char *, const char *, const char *,
                        int);
                        int);
static void def_image_name (const char *, int, int);
static void def_image_name (const char *, int, int);
static void def_section (const char *, int);
static void def_section (const char *, int);
static void def_section_alt (const char *, const char *);
static void def_section_alt (const char *, const char *);
static void def_stacksize (int, int);
static void def_stacksize (int, int);
static void def_version (int, int);
static void def_version (int, int);
static void def_directive (char *);
static void def_directive (char *);
static int def_parse (void);
static int def_parse (void);
static int def_error (const char *);
static int def_error (const char *);
static int def_lex (void);
static int def_lex (void);
static int lex_forced_token = 0;
static int lex_forced_token = 0;
static const char *lex_parse_string = 0;
static const char *lex_parse_string = 0;
static const char *lex_parse_string_end = 0;
static const char *lex_parse_string_end = 0;
%}
%}
%union {
%union {
  char *id;
  char *id;
  int number;
  int number;
};
};
%token NAME LIBRARY DESCRIPTION STACKSIZE HEAPSIZE CODE DATAU DATAL
%token NAME LIBRARY DESCRIPTION STACKSIZE HEAPSIZE CODE DATAU DATAL
%token SECTIONS EXPORTS IMPORTS VERSIONK BASE CONSTANTU CONSTANTL
%token SECTIONS EXPORTS IMPORTS VERSIONK BASE CONSTANTU CONSTANTL
%token PRIVATEU PRIVATEL
%token PRIVATEU PRIVATEL
%token READ WRITE EXECUTE SHARED NONAMEU NONAMEL DIRECTIVE
%token READ WRITE EXECUTE SHARED NONAMEU NONAMEL DIRECTIVE
%token  ID
%token  ID
%token  NUMBER
%token  NUMBER
%type   opt_base opt_ordinal
%type   opt_base opt_ordinal
%type   attr attr_list opt_number exp_opt_list exp_opt
%type   attr attr_list opt_number exp_opt_list exp_opt
%type   opt_name opt_equal_name dot_name
%type   opt_name opt_equal_name dot_name
%%
%%
start: start command
start: start command
        | command
        | command
        ;
        ;
command:
command:
                NAME opt_name opt_base { def_image_name ($2, $3, 0); }
                NAME opt_name opt_base { def_image_name ($2, $3, 0); }
        |       LIBRARY opt_name opt_base { def_image_name ($2, $3, 1); }
        |       LIBRARY opt_name opt_base { def_image_name ($2, $3, 1); }
        |       DESCRIPTION ID { def_description ($2);}
        |       DESCRIPTION ID { def_description ($2);}
        |       STACKSIZE NUMBER opt_number { def_stacksize ($2, $3);}
        |       STACKSIZE NUMBER opt_number { def_stacksize ($2, $3);}
        |       HEAPSIZE NUMBER opt_number { def_heapsize ($2, $3);}
        |       HEAPSIZE NUMBER opt_number { def_heapsize ($2, $3);}
        |       CODE attr_list { def_section ("CODE", $2);}
        |       CODE attr_list { def_section ("CODE", $2);}
        |       DATAU attr_list  { def_section ("DATA", $2);}
        |       DATAU attr_list  { def_section ("DATA", $2);}
        |       SECTIONS seclist
        |       SECTIONS seclist
        |       EXPORTS explist
        |       EXPORTS explist
        |       IMPORTS implist
        |       IMPORTS implist
        |       VERSIONK NUMBER { def_version ($2, 0);}
        |       VERSIONK NUMBER { def_version ($2, 0);}
        |       VERSIONK NUMBER '.' NUMBER { def_version ($2, $4);}
        |       VERSIONK NUMBER '.' NUMBER { def_version ($2, $4);}
        |       DIRECTIVE ID { def_directive ($2);}
        |       DIRECTIVE ID { def_directive ($2);}
        ;
        ;
explist:
explist:
                /* EMPTY */
                /* EMPTY */
        |       expline
        |       expline
        |       explist expline
        |       explist expline
        ;
        ;
expline:
expline:
                /* The opt_comma is necessary to support both the usual
                /* The opt_comma is necessary to support both the usual
                  DEF file syntax as well as .drectve syntax which
                  DEF file syntax as well as .drectve syntax which
                  mandates ,.  */
                  mandates ,.  */
                dot_name opt_equal_name opt_ordinal opt_comma exp_opt_list
                dot_name opt_equal_name opt_ordinal opt_comma exp_opt_list
                        { def_exports ($1, $2, $3, $5); }
                        { def_exports ($1, $2, $3, $5); }
        ;
        ;
exp_opt_list:
exp_opt_list:
                /* The opt_comma is necessary to support both the usual
                /* The opt_comma is necessary to support both the usual
                   DEF file syntax as well as .drectve syntax which
                   DEF file syntax as well as .drectve syntax which
                   allows for comma separated opt list.  */
                   allows for comma separated opt list.  */
                exp_opt opt_comma exp_opt_list { $$ = $1 | $3; }
                exp_opt opt_comma exp_opt_list { $$ = $1 | $3; }
        |       { $$ = 0; }
        |       { $$ = 0; }
        ;
        ;
exp_opt:
exp_opt:
                NONAMEU         { $$ = 1; }
                NONAMEU         { $$ = 1; }
        |       NONAMEL         { $$ = 1; }
        |       NONAMEL         { $$ = 1; }
        |       CONSTANTU       { $$ = 2; }
        |       CONSTANTU       { $$ = 2; }
        |       CONSTANTL       { $$ = 2; }
        |       CONSTANTL       { $$ = 2; }
        |       DATAU           { $$ = 4; }
        |       DATAU           { $$ = 4; }
        |       DATAL           { $$ = 4; }
        |       DATAL           { $$ = 4; }
        |       PRIVATEU        { $$ = 8; }
        |       PRIVATEU        { $$ = 8; }
        |       PRIVATEL        { $$ = 8; }
        |       PRIVATEL        { $$ = 8; }
        ;
        ;
implist:
implist:
                implist impline
                implist impline
        |       impline
        |       impline
        ;
        ;
impline:
impline:
               ID '=' ID '.' ID '.' ID     { def_import ($1, $3, $5, $7, -1); }
               ID '=' ID '.' ID '.' ID     { def_import ($1, $3, $5, $7, -1); }
       |       ID '=' ID '.' ID '.' NUMBER { def_import ($1, $3, $5,  0, $7); }
       |       ID '=' ID '.' ID '.' NUMBER { def_import ($1, $3, $5,  0, $7); }
       |       ID '=' ID '.' ID            { def_import ($1, $3,  0, $5, -1); }
       |       ID '=' ID '.' ID            { def_import ($1, $3,  0, $5, -1); }
       |       ID '=' ID '.' NUMBER        { def_import ($1, $3,  0,  0, $5); }
       |       ID '=' ID '.' NUMBER        { def_import ($1, $3,  0,  0, $5); }
       |       ID '.' ID '.' ID            { def_import ( 0, $1, $3, $5, -1); }
       |       ID '.' ID '.' ID            { def_import ( 0, $1, $3, $5, -1); }
       |       ID '.' ID                   { def_import ( 0, $1,  0, $3, -1); }
       |       ID '.' ID                   { def_import ( 0, $1,  0, $3, -1); }
;
;
seclist:
seclist:
                seclist secline
                seclist secline
        |       secline
        |       secline
        ;
        ;
secline:
secline:
        ID attr_list { def_section ($1, $2);}
        ID attr_list { def_section ($1, $2);}
        | ID ID { def_section_alt ($1, $2);}
        | ID ID { def_section_alt ($1, $2);}
        ;
        ;
attr_list:
attr_list:
        attr_list opt_comma attr { $$ = $1 | $3; }
        attr_list opt_comma attr { $$ = $1 | $3; }
        | attr { $$ = $1; }
        | attr { $$ = $1; }
        ;
        ;
opt_comma:
opt_comma:
        ','
        ','
        |
        |
        ;
        ;
opt_number: ',' NUMBER { $$=$2;}
opt_number: ',' NUMBER { $$=$2;}
        |          { $$=-1;}
        |          { $$=-1;}
        ;
        ;
attr:
attr:
                READ    { $$ = 1;}
                READ    { $$ = 1;}
        |       WRITE   { $$ = 2;}
        |       WRITE   { $$ = 2;}
        |       EXECUTE { $$=4;}
        |       EXECUTE { $$=4;}
        |       SHARED  { $$=8;}
        |       SHARED  { $$=8;}
        ;
        ;
opt_name: ID            { $$ = $1; }
opt_name: ID            { $$ = $1; }
        | ID '.' ID
        | ID '.' ID
          {
          {
            char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
            char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
            sprintf (name, "%s.%s", $1, $3);
            sprintf (name, "%s.%s", $1, $3);
            $$ = name;
            $$ = name;
          }
          }
        |               { $$ = ""; }
        |               { $$ = ""; }
        ;
        ;
opt_ordinal:
opt_ordinal:
          '@' NUMBER     { $$ = $2;}
          '@' NUMBER     { $$ = $2;}
        |                { $$ = -1;}
        |                { $$ = -1;}
        ;
        ;
opt_equal_name:
opt_equal_name:
          '=' dot_name  { $$ = $2; }
          '=' dot_name  { $$ = $2; }
        |               { $$ =  0; }
        |               { $$ =  0; }
        ;
        ;
opt_base: BASE  '=' NUMBER      { $$ = $3;}
opt_base: BASE  '=' NUMBER      { $$ = $3;}
        |       { $$ = -1;}
        |       { $$ = -1;}
        ;
        ;
dot_name: ID            { $$ = $1; }
dot_name: ID            { $$ = $1; }
        | dot_name '.' ID
        | dot_name '.' ID
          {
          {
            char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
            char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
            sprintf (name, "%s.%s", $1, $3);
            sprintf (name, "%s.%s", $1, $3);
            $$ = name;
            $$ = name;
          }
          }
        ;
        ;
%%
%%
/*****************************************************************************
/*****************************************************************************
 API
 API
 *****************************************************************************/
 *****************************************************************************/
static FILE *the_file;
static FILE *the_file;
static const char *def_filename;
static const char *def_filename;
static int linenumber;
static int linenumber;
static def_file *def;
static def_file *def;
static int saw_newline;
static int saw_newline;
struct directive
struct directive
  {
  {
    struct directive *next;
    struct directive *next;
    char *name;
    char *name;
    int len;
    int len;
  };
  };
static struct directive *directives = 0;
static struct directive *directives = 0;
def_file *
def_file *
def_file_empty (void)
def_file_empty (void)
{
{
  def_file *rv = xmalloc (sizeof (def_file));
  def_file *rv = xmalloc (sizeof (def_file));
  memset (rv, 0, sizeof (def_file));
  memset (rv, 0, sizeof (def_file));
  rv->is_dll = -1;
  rv->is_dll = -1;
  rv->base_address = (bfd_vma) -1;
  rv->base_address = (bfd_vma) -1;
  rv->stack_reserve = rv->stack_commit = -1;
  rv->stack_reserve = rv->stack_commit = -1;
  rv->heap_reserve = rv->heap_commit = -1;
  rv->heap_reserve = rv->heap_commit = -1;
  rv->version_major = rv->version_minor = -1;
  rv->version_major = rv->version_minor = -1;
  return rv;
  return rv;
}
}
def_file *
def_file *
def_file_parse (const char *filename, def_file *add_to)
def_file_parse (const char *filename, def_file *add_to)
{
{
  struct directive *d;
  struct directive *d;
  the_file = fopen (filename, "r");
  the_file = fopen (filename, "r");
  def_filename = filename;
  def_filename = filename;
  linenumber = 1;
  linenumber = 1;
  if (!the_file)
  if (!the_file)
    {
    {
      perror (filename);
      perror (filename);
      return 0;
      return 0;
    }
    }
  if (add_to)
  if (add_to)
    {
    {
      def = add_to;
      def = add_to;
    }
    }
  else
  else
    {
    {
      def = def_file_empty ();
      def = def_file_empty ();
    }
    }
  saw_newline = 1;
  saw_newline = 1;
  if (def_parse ())
  if (def_parse ())
    {
    {
      def_file_free (def);
      def_file_free (def);
      fclose (the_file);
      fclose (the_file);
      return 0;
      return 0;
    }
    }
  fclose (the_file);
  fclose (the_file);
  for (d = directives; d; d = d->next)
  for (d = directives; d; d = d->next)
    {
    {
#if TRACE
#if TRACE
      printf ("Adding directive %08x `%s'\n", d->name, d->name);
      printf ("Adding directive %08x `%s'\n", d->name, d->name);
#endif
#endif
      def_file_add_directive (def, d->name, d->len);
      def_file_add_directive (def, d->name, d->len);
    }
    }
  return def;
  return def;
}
}
void
void
def_file_free (def_file *def)
def_file_free (def_file *def)
{
{
  int i;
  int i;
  if (!def)
  if (!def)
    return;
    return;
  if (def->name)
  if (def->name)
    free (def->name);
    free (def->name);
  if (def->description)
  if (def->description)
    free (def->description);
    free (def->description);
  if (def->section_defs)
  if (def->section_defs)
    {
    {
      for (i = 0; i < def->num_section_defs; i++)
      for (i = 0; i < def->num_section_defs; i++)
        {
        {
          if (def->section_defs[i].name)
          if (def->section_defs[i].name)
            free (def->section_defs[i].name);
            free (def->section_defs[i].name);
          if (def->section_defs[i].class)
          if (def->section_defs[i].class)
            free (def->section_defs[i].class);
            free (def->section_defs[i].class);
        }
        }
      free (def->section_defs);
      free (def->section_defs);
    }
    }
  if (def->exports)
  if (def->exports)
    {
    {
      for (i = 0; i < def->num_exports; i++)
      for (i = 0; i < def->num_exports; i++)
        {
        {
          if (def->exports[i].internal_name
          if (def->exports[i].internal_name
              && def->exports[i].internal_name != def->exports[i].name)
              && def->exports[i].internal_name != def->exports[i].name)
            free (def->exports[i].internal_name);
            free (def->exports[i].internal_name);
          if (def->exports[i].name)
          if (def->exports[i].name)
            free (def->exports[i].name);
            free (def->exports[i].name);
        }
        }
      free (def->exports);
      free (def->exports);
    }
    }
  if (def->imports)
  if (def->imports)
    {
    {
      for (i = 0; i < def->num_imports; i++)
      for (i = 0; i < def->num_imports; i++)
        {
        {
          if (def->imports[i].internal_name
          if (def->imports[i].internal_name
              && def->imports[i].internal_name != def->imports[i].name)
              && def->imports[i].internal_name != def->imports[i].name)
            free (def->imports[i].internal_name);
            free (def->imports[i].internal_name);
          if (def->imports[i].name)
          if (def->imports[i].name)
            free (def->imports[i].name);
            free (def->imports[i].name);
        }
        }
      free (def->imports);
      free (def->imports);
    }
    }
  while (def->modules)
  while (def->modules)
    {
    {
      def_file_module *m = def->modules;
      def_file_module *m = def->modules;
      def->modules = def->modules->next;
      def->modules = def->modules->next;
      free (m);
      free (m);
    }
    }
  free (def);
  free (def);
}
}
#ifdef DEF_FILE_PRINT
#ifdef DEF_FILE_PRINT
void
void
def_file_print (FILE *file, def_file *def)
def_file_print (FILE *file, def_file *def)
{
{
  int i;
  int i;
  fprintf (file, ">>>> def_file at 0x%08x\n", def);
  fprintf (file, ">>>> def_file at 0x%08x\n", def);
  if (def->name)
  if (def->name)
    fprintf (file, "  name: %s\n", def->name ? def->name : "(unspecified)");
    fprintf (file, "  name: %s\n", def->name ? def->name : "(unspecified)");
  if (def->is_dll != -1)
  if (def->is_dll != -1)
    fprintf (file, "  is dll: %s\n", def->is_dll ? "yes" : "no");
    fprintf (file, "  is dll: %s\n", def->is_dll ? "yes" : "no");
  if (def->base_address != (bfd_vma) -1)
  if (def->base_address != (bfd_vma) -1)
    fprintf (file, "  base address: 0x%08x\n", def->base_address);
    fprintf (file, "  base address: 0x%08x\n", def->base_address);
  if (def->description)
  if (def->description)
    fprintf (file, "  description: `%s'\n", def->description);
    fprintf (file, "  description: `%s'\n", def->description);
  if (def->stack_reserve != -1)
  if (def->stack_reserve != -1)
    fprintf (file, "  stack reserve: 0x%08x\n", def->stack_reserve);
    fprintf (file, "  stack reserve: 0x%08x\n", def->stack_reserve);
  if (def->stack_commit != -1)
  if (def->stack_commit != -1)
    fprintf (file, "  stack commit: 0x%08x\n", def->stack_commit);
    fprintf (file, "  stack commit: 0x%08x\n", def->stack_commit);
  if (def->heap_reserve != -1)
  if (def->heap_reserve != -1)
    fprintf (file, "  heap reserve: 0x%08x\n", def->heap_reserve);
    fprintf (file, "  heap reserve: 0x%08x\n", def->heap_reserve);
  if (def->heap_commit != -1)
  if (def->heap_commit != -1)
    fprintf (file, "  heap commit: 0x%08x\n", def->heap_commit);
    fprintf (file, "  heap commit: 0x%08x\n", def->heap_commit);
  if (def->num_section_defs > 0)
  if (def->num_section_defs > 0)
    {
    {
      fprintf (file, "  section defs:\n");
      fprintf (file, "  section defs:\n");
      for (i = 0; i < def->num_section_defs; i++)
      for (i = 0; i < def->num_section_defs; i++)
        {
        {
          fprintf (file, "    name: `%s', class: `%s', flags:",
          fprintf (file, "    name: `%s', class: `%s', flags:",
                   def->section_defs[i].name, def->section_defs[i].class);
                   def->section_defs[i].name, def->section_defs[i].class);
          if (def->section_defs[i].flag_read)
          if (def->section_defs[i].flag_read)
            fprintf (file, " R");
            fprintf (file, " R");
          if (def->section_defs[i].flag_write)
          if (def->section_defs[i].flag_write)
            fprintf (file, " W");
            fprintf (file, " W");
          if (def->section_defs[i].flag_execute)
          if (def->section_defs[i].flag_execute)
            fprintf (file, " X");
            fprintf (file, " X");
          if (def->section_defs[i].flag_shared)
          if (def->section_defs[i].flag_shared)
            fprintf (file, " S");
            fprintf (file, " S");
          fprintf (file, "\n");
          fprintf (file, "\n");
        }
        }
    }
    }
  if (def->num_exports > 0)
  if (def->num_exports > 0)
    {
    {
      fprintf (file, "  exports:\n");
      fprintf (file, "  exports:\n");
      for (i = 0; i < def->num_exports; i++)
      for (i = 0; i < def->num_exports; i++)
        {
        {
          fprintf (file, "    name: `%s', int: `%s', ordinal: %d, flags:",
          fprintf (file, "    name: `%s', int: `%s', ordinal: %d, flags:",
                   def->exports[i].name, def->exports[i].internal_name,
                   def->exports[i].name, def->exports[i].internal_name,
                   def->exports[i].ordinal);
                   def->exports[i].ordinal);
          if (def->exports[i].flag_private)
          if (def->exports[i].flag_private)
            fprintf (file, " P");
            fprintf (file, " P");
          if (def->exports[i].flag_constant)
          if (def->exports[i].flag_constant)
            fprintf (file, " C");
            fprintf (file, " C");
          if (def->exports[i].flag_noname)
          if (def->exports[i].flag_noname)
            fprintf (file, " N");
            fprintf (file, " N");
          if (def->exports[i].flag_data)
          if (def->exports[i].flag_data)
            fprintf (file, " D");
            fprintf (file, " D");
          fprintf (file, "\n");
          fprintf (file, "\n");
        }
        }
    }
    }
  if (def->num_imports > 0)
  if (def->num_imports > 0)
    {
    {
      fprintf (file, "  imports:\n");
      fprintf (file, "  imports:\n");
      for (i = 0; i < def->num_imports; i++)
      for (i = 0; i < def->num_imports; i++)
        {
        {
          fprintf (file, "    int: %s, from: `%s', name: `%s', ordinal: %d\n",
          fprintf (file, "    int: %s, from: `%s', name: `%s', ordinal: %d\n",
                   def->imports[i].internal_name,
                   def->imports[i].internal_name,
                   def->imports[i].module,
                   def->imports[i].module,
                   def->imports[i].name,
                   def->imports[i].name,
                   def->imports[i].ordinal);
                   def->imports[i].ordinal);
        }
        }
    }
    }
  if (def->version_major != -1)
  if (def->version_major != -1)
    fprintf (file, "  version: %d.%d\n", def->version_major, def->version_minor);
    fprintf (file, "  version: %d.%d\n", def->version_major, def->version_minor);
  fprintf (file, "<<<< def_file at 0x%08x\n", def);
  fprintf (file, "<<<< def_file at 0x%08x\n", def);
}
}
#endif
#endif
def_file_export *
def_file_export *
def_file_add_export (def_file *def,
def_file_add_export (def_file *def,
                     const char *external_name,
                     const char *external_name,
                     const char *internal_name,
                     const char *internal_name,
                     int ordinal)
                     int ordinal)
{
{
  def_file_export *e;
  def_file_export *e;
  int max_exports = ROUND_UP(def->num_exports, 32);
  int max_exports = ROUND_UP(def->num_exports, 32);
  if (def->num_exports >= max_exports)
  if (def->num_exports >= max_exports)
    {
    {
      max_exports = ROUND_UP(def->num_exports + 1, 32);
      max_exports = ROUND_UP(def->num_exports + 1, 32);
      if (def->exports)
      if (def->exports)
        def->exports = xrealloc (def->exports,
        def->exports = xrealloc (def->exports,
                                 max_exports * sizeof (def_file_export));
                                 max_exports * sizeof (def_file_export));
      else
      else
        def->exports = xmalloc (max_exports * sizeof (def_file_export));
        def->exports = xmalloc (max_exports * sizeof (def_file_export));
    }
    }
  e = def->exports + def->num_exports;
  e = def->exports + def->num_exports;
  memset (e, 0, sizeof (def_file_export));
  memset (e, 0, sizeof (def_file_export));
  if (internal_name && !external_name)
  if (internal_name && !external_name)
    external_name = internal_name;
    external_name = internal_name;
  if (external_name && !internal_name)
  if (external_name && !internal_name)
    internal_name = external_name;
    internal_name = external_name;
  e->name = xstrdup (external_name);
  e->name = xstrdup (external_name);
  e->internal_name = xstrdup (internal_name);
  e->internal_name = xstrdup (internal_name);
  e->ordinal = ordinal;
  e->ordinal = ordinal;
  def->num_exports++;
  def->num_exports++;
  return e;
  return e;
}
}
def_file_module *
def_file_module *
def_get_module (def_file *def, const char *name)
def_get_module (def_file *def, const char *name)
{
{
  def_file_module *s;
  def_file_module *s;
  for (s = def->modules; s; s = s->next)
  for (s = def->modules; s; s = s->next)
    if (strcmp (s->name, name) == 0)
    if (strcmp (s->name, name) == 0)
      return s;
      return s;
  return NULL;
  return NULL;
}
}
static def_file_module *
static def_file_module *
def_stash_module (def_file *def, const char *name)
def_stash_module (def_file *def, const char *name)
{
{
  def_file_module *s;
  def_file_module *s;
  if ((s = def_get_module (def, name)) != NULL)
  if ((s = def_get_module (def, name)) != NULL)
      return s;
      return s;
  s = xmalloc (sizeof (def_file_module) + strlen (name));
  s = xmalloc (sizeof (def_file_module) + strlen (name));
  s->next = def->modules;
  s->next = def->modules;
  def->modules = s;
  def->modules = s;
  s->user_data = 0;
  s->user_data = 0;
  strcpy (s->name, name);
  strcpy (s->name, name);
  return s;
  return s;
}
}
def_file_import *
def_file_import *
def_file_add_import (def_file *def,
def_file_add_import (def_file *def,
                     const char *name,
                     const char *name,
                     const char *module,
                     const char *module,
                     int ordinal,
                     int ordinal,
                     const char *internal_name)
                     const char *internal_name)
{
{
  def_file_import *i;
  def_file_import *i;
  int max_imports = ROUND_UP (def->num_imports, 16);
  int max_imports = ROUND_UP (def->num_imports, 16);
  if (def->num_imports >= max_imports)
  if (def->num_imports >= max_imports)
    {
    {
      max_imports = ROUND_UP (def->num_imports+1, 16);
      max_imports = ROUND_UP (def->num_imports+1, 16);
      if (def->imports)
      if (def->imports)
        def->imports = xrealloc (def->imports,
        def->imports = xrealloc (def->imports,
                                 max_imports * sizeof (def_file_import));
                                 max_imports * sizeof (def_file_import));
      else
      else
        def->imports = xmalloc (max_imports * sizeof (def_file_import));
        def->imports = xmalloc (max_imports * sizeof (def_file_import));
    }
    }
  i = def->imports + def->num_imports;
  i = def->imports + def->num_imports;
  memset (i, 0, sizeof (def_file_import));
  memset (i, 0, sizeof (def_file_import));
  if (name)
  if (name)
    i->name = xstrdup (name);
    i->name = xstrdup (name);
  if (module)
  if (module)
    i->module = def_stash_module (def, module);
    i->module = def_stash_module (def, module);
  i->ordinal = ordinal;
  i->ordinal = ordinal;
  if (internal_name)
  if (internal_name)
    i->internal_name = xstrdup (internal_name);
    i->internal_name = xstrdup (internal_name);
  else
  else
    i->internal_name = i->name;
    i->internal_name = i->name;
  def->num_imports++;
  def->num_imports++;
  return i;
  return i;
}
}
struct
struct
{
{
  char *param;
  char *param;
  int token;
  int token;
}
}
diropts[] =
diropts[] =
{
{
  { "-heap", HEAPSIZE },
  { "-heap", HEAPSIZE },
  { "-stack", STACKSIZE },
  { "-stack", STACKSIZE },
  { "-attr", SECTIONS },
  { "-attr", SECTIONS },
  { "-export", EXPORTS },
  { "-export", EXPORTS },
  { 0, 0 }
  { 0, 0 }
};
};
void
void
def_file_add_directive (def_file *my_def, const char *param, int len)
def_file_add_directive (def_file *my_def, const char *param, int len)
{
{
  def_file *save_def = def;
  def_file *save_def = def;
  const char *pend = param + len;
  const char *pend = param + len;
  char * tend = (char *) param;
  char * tend = (char *) param;
  int i;
  int i;
  def = my_def;
  def = my_def;
  while (param < pend)
  while (param < pend)
    {
    {
      while (param < pend
      while (param < pend
             && (ISSPACE (*param) || *param == '\n' || *param == 0))
             && (ISSPACE (*param) || *param == '\n' || *param == 0))
        param++;
        param++;
      if (param == pend)
      if (param == pend)
        break;
        break;
      /* Scan forward until we encounter any of:
      /* Scan forward until we encounter any of:
          - the end of the buffer
          - the end of the buffer
          - the start of a new option
          - the start of a new option
          - a newline seperating options
          - a newline seperating options
          - a NUL seperating options.  */
          - a NUL seperating options.  */
      for (tend = (char *) (param + 1);
      for (tend = (char *) (param + 1);
           (tend < pend
           (tend < pend
            && !(ISSPACE (tend[-1]) && *tend == '-')
            && !(ISSPACE (tend[-1]) && *tend == '-')
            && *tend != '\n' && *tend != 0);
            && *tend != '\n' && *tend != 0);
           tend++)
           tend++)
        ;
        ;
      for (i = 0; diropts[i].param; i++)
      for (i = 0; diropts[i].param; i++)
        {
        {
          int len = strlen (diropts[i].param);
          int len = strlen (diropts[i].param);
          if (tend - param >= len
          if (tend - param >= len
              && strncmp (param, diropts[i].param, len) == 0
              && strncmp (param, diropts[i].param, len) == 0
              && (param[len] == ':' || param[len] == ' '))
              && (param[len] == ':' || param[len] == ' '))
            {
            {
              lex_parse_string_end = tend;
              lex_parse_string_end = tend;
              lex_parse_string = param + len + 1;
              lex_parse_string = param + len + 1;
              lex_forced_token = diropts[i].token;
              lex_forced_token = diropts[i].token;
              saw_newline = 0;
              saw_newline = 0;
              if (def_parse ())
              if (def_parse ())
                continue;
                continue;
              break;
              break;
            }
            }
        }
        }
      if (!diropts[i].param)
      if (!diropts[i].param)
        {
        {
          char saved;
          char saved;
          saved = * tend;
          saved = * tend;
          * tend = 0;
          * tend = 0;
          /* xgettext:c-format */
          /* xgettext:c-format */
          einfo (_("Warning: .drectve `%s' unrecognized\n"), param);
          einfo (_("Warning: .drectve `%s' unrecognized\n"), param);
          * tend = saved;
          * tend = saved;
        }
        }
      lex_parse_string = 0;
      lex_parse_string = 0;
      param = tend;
      param = tend;
    }
    }
  def = save_def;
  def = save_def;
}
}
/* Parser Callbacks.  */
/* Parser Callbacks.  */
static void
static void
def_image_name (const char *name, int base, int is_dll)
def_image_name (const char *name, int base, int is_dll)
{
{
  /* If a LIBRARY or NAME statement is specified without a name, there is nothing
  /* If a LIBRARY or NAME statement is specified without a name, there is nothing
     to do here.  We retain the output filename specified on command line.  */
     to do here.  We retain the output filename specified on command line.  */
  if (*name)
  if (*name)
    {
    {
      const char* image_name = lbasename (name);
      const char* image_name = lbasename (name);
      if (image_name != name)
      if (image_name != name)
        einfo ("%s:%d: Warning: path components stripped from %s, '%s'\n",
        einfo ("%s:%d: Warning: path components stripped from %s, '%s'\n",
               def_filename, linenumber, is_dll ? "LIBRARY" : "NAME",
               def_filename, linenumber, is_dll ? "LIBRARY" : "NAME",
               name);
               name);
      if (def->name)
      if (def->name)
        free (def->name);
        free (def->name);
      /* Append the default suffix, if none specified.  */
      /* Append the default suffix, if none specified.  */
      if (strchr (image_name, '.') == 0)
      if (strchr (image_name, '.') == 0)
        {
        {
          const char * suffix = is_dll ? ".dll" : ".exe";
          const char * suffix = is_dll ? ".dll" : ".exe";
          def->name = xmalloc (strlen (image_name) + strlen (suffix) + 1);
          def->name = xmalloc (strlen (image_name) + strlen (suffix) + 1);
          sprintf (def->name, "%s%s", image_name, suffix);
          sprintf (def->name, "%s%s", image_name, suffix);
        }
        }
      else
      else
        def->name = xstrdup (image_name);
        def->name = xstrdup (image_name);
    }
    }
  /* Honor a BASE address statement, even if LIBRARY string is empty.  */
  /* Honor a BASE address statement, even if LIBRARY string is empty.  */
  def->base_address = base;
  def->base_address = base;
  def->is_dll = is_dll;
  def->is_dll = is_dll;
}
}
static void
static void
def_description (const char *text)
def_description (const char *text)
{
{
  int len = def->description ? strlen (def->description) : 0;
  int len = def->description ? strlen (def->description) : 0;
  len += strlen (text) + 1;
  len += strlen (text) + 1;
  if (def->description)
  if (def->description)
    {
    {
      def->description = xrealloc (def->description, len);
      def->description = xrealloc (def->description, len);
      strcat (def->description, text);
      strcat (def->description, text);
    }
    }
  else
  else
    {
    {
      def->description = xmalloc (len);
      def->description = xmalloc (len);
      strcpy (def->description, text);
      strcpy (def->description, text);
    }
    }
}
}
static void
static void
def_stacksize (int reserve, int commit)
def_stacksize (int reserve, int commit)
{
{
  def->stack_reserve = reserve;
  def->stack_reserve = reserve;
  def->stack_commit = commit;
  def->stack_commit = commit;
}
}
static void
static void
def_heapsize (int reserve, int commit)
def_heapsize (int reserve, int commit)
{
{
  def->heap_reserve = reserve;
  def->heap_reserve = reserve;
  def->heap_commit = commit;
  def->heap_commit = commit;
}
}
static void
static void
def_section (const char *name, int attr)
def_section (const char *name, int attr)
{
{
  def_file_section *s;
  def_file_section *s;
  int max_sections = ROUND_UP (def->num_section_defs, 4);
  int max_sections = ROUND_UP (def->num_section_defs, 4);
  if (def->num_section_defs >= max_sections)
  if (def->num_section_defs >= max_sections)
    {
    {
      max_sections = ROUND_UP (def->num_section_defs+1, 4);
      max_sections = ROUND_UP (def->num_section_defs+1, 4);
      if (def->section_defs)
      if (def->section_defs)
        def->section_defs = xrealloc (def->section_defs,
        def->section_defs = xrealloc (def->section_defs,
                                      max_sections * sizeof (def_file_import));
                                      max_sections * sizeof (def_file_import));
      else
      else
        def->section_defs = xmalloc (max_sections * sizeof (def_file_import));
        def->section_defs = xmalloc (max_sections * sizeof (def_file_import));
    }
    }
  s = def->section_defs + def->num_section_defs;
  s = def->section_defs + def->num_section_defs;
  memset (s, 0, sizeof (def_file_section));
  memset (s, 0, sizeof (def_file_section));
  s->name = xstrdup (name);
  s->name = xstrdup (name);
  if (attr & 1)
  if (attr & 1)
    s->flag_read = 1;
    s->flag_read = 1;
  if (attr & 2)
  if (attr & 2)
    s->flag_write = 1;
    s->flag_write = 1;
  if (attr & 4)
  if (attr & 4)
    s->flag_execute = 1;
    s->flag_execute = 1;
  if (attr & 8)
  if (attr & 8)
    s->flag_shared = 1;
    s->flag_shared = 1;
  def->num_section_defs++;
  def->num_section_defs++;
}
}
static void
static void
def_section_alt (const char *name, const char *attr)
def_section_alt (const char *name, const char *attr)
{
{
  int aval = 0;
  int aval = 0;
  for (; *attr; attr++)
  for (; *attr; attr++)
    {
    {
      switch (*attr)
      switch (*attr)
        {
        {
        case 'R':
        case 'R':
        case 'r':
        case 'r':
          aval |= 1;
          aval |= 1;
          break;
          break;
        case 'W':
        case 'W':
        case 'w':
        case 'w':
          aval |= 2;
          aval |= 2;
          break;
          break;
        case 'X':
        case 'X':
        case 'x':
        case 'x':
          aval |= 4;
          aval |= 4;
          break;
          break;
        case 'S':
        case 'S':
        case 's':
        case 's':
          aval |= 8;
          aval |= 8;
          break;
          break;
        }
        }
    }
    }
  def_section (name, aval);
  def_section (name, aval);
}
}
static void
static void
def_exports (const char *external_name,
def_exports (const char *external_name,
             const char *internal_name,
             const char *internal_name,
             int ordinal,
             int ordinal,
             int flags)
             int flags)
{
{
  def_file_export *dfe;
  def_file_export *dfe;
  if (!internal_name && external_name)
  if (!internal_name && external_name)
    internal_name = external_name;
    internal_name = external_name;
#if TRACE
#if TRACE
  printf ("def_exports, ext=%s int=%s\n", external_name, internal_name);
  printf ("def_exports, ext=%s int=%s\n", external_name, internal_name);
#endif
#endif
  dfe = def_file_add_export (def, external_name, internal_name, ordinal);
  dfe = def_file_add_export (def, external_name, internal_name, ordinal);
  if (flags & 1)
  if (flags & 1)
    dfe->flag_noname = 1;
    dfe->flag_noname = 1;
  if (flags & 2)
  if (flags & 2)
    dfe->flag_constant = 1;
    dfe->flag_constant = 1;
  if (flags & 4)
  if (flags & 4)
    dfe->flag_data = 1;
    dfe->flag_data = 1;
  if (flags & 8)
  if (flags & 8)
    dfe->flag_private = 1;
    dfe->flag_private = 1;
}
}
static void
static void
def_import (const char *internal_name,
def_import (const char *internal_name,
            const char *module,
            const char *module,
            const char *dllext,
            const char *dllext,
            const char *name,
            const char *name,
            int ordinal)
            int ordinal)
{
{
  char *buf = 0;
  char *buf = 0;
  const char *ext = dllext ? dllext : "dll";
  const char *ext = dllext ? dllext : "dll";
  buf = xmalloc (strlen (module) + strlen (ext) + 2);
  buf = xmalloc (strlen (module) + strlen (ext) + 2);
  sprintf (buf, "%s.%s", module, ext);
  sprintf (buf, "%s.%s", module, ext);
  module = buf;
  module = buf;
  def_file_add_import (def, name, module, ordinal, internal_name);
  def_file_add_import (def, name, module, ordinal, internal_name);
  if (buf)
  if (buf)
    free (buf);
    free (buf);
}
}
static void
static void
def_version (int major, int minor)
def_version (int major, int minor)
{
{
  def->version_major = major;
  def->version_major = major;
  def->version_minor = minor;
  def->version_minor = minor;
}
}
static void
static void
def_directive (char *str)
def_directive (char *str)
{
{
  struct directive *d = xmalloc (sizeof (struct directive));
  struct directive *d = xmalloc (sizeof (struct directive));
  d->next = directives;
  d->next = directives;
  directives = d;
  directives = d;
  d->name = xstrdup (str);
  d->name = xstrdup (str);
  d->len = strlen (str);
  d->len = strlen (str);
}
}
static int
static int
def_error (const char *err)
def_error (const char *err)
{
{
  einfo ("%P: %s:%d: %s\n",
  einfo ("%P: %s:%d: %s\n",
         def_filename ? def_filename : "", linenumber, err);
         def_filename ? def_filename : "", linenumber, err);
  return 0;
  return 0;
}
}
/* Lexical Scanner.  */
/* Lexical Scanner.  */
#undef TRACE
#undef TRACE
#define TRACE 0
#define TRACE 0
/* Never freed, but always reused as needed, so no real leak.  */
/* Never freed, but always reused as needed, so no real leak.  */
static char *buffer = 0;
static char *buffer = 0;
static int buflen = 0;
static int buflen = 0;
static int bufptr = 0;
static int bufptr = 0;
static void
static void
put_buf (char c)
put_buf (char c)
{
{
  if (bufptr == buflen)
  if (bufptr == buflen)
    {
    {
      buflen += 50;             /* overly reasonable, eh?  */
      buflen += 50;             /* overly reasonable, eh?  */
      if (buffer)
      if (buffer)
        buffer = xrealloc (buffer, buflen + 1);
        buffer = xrealloc (buffer, buflen + 1);
      else
      else
        buffer = xmalloc (buflen + 1);
        buffer = xmalloc (buflen + 1);
    }
    }
  buffer[bufptr++] = c;
  buffer[bufptr++] = c;
  buffer[bufptr] = 0;           /* not optimal, but very convenient.  */
  buffer[bufptr] = 0;           /* not optimal, but very convenient.  */
}
}
static struct
static struct
{
{
  char *name;
  char *name;
  int token;
  int token;
}
}
tokens[] =
tokens[] =
{
{
  { "BASE", BASE },
  { "BASE", BASE },
  { "CODE", CODE },
  { "CODE", CODE },
  { "CONSTANT", CONSTANTU },
  { "CONSTANT", CONSTANTU },
  { "constant", CONSTANTL },
  { "constant", CONSTANTL },
  { "DATA", DATAU },
  { "DATA", DATAU },
  { "data", DATAL },
  { "data", DATAL },
  { "DESCRIPTION", DESCRIPTION },
  { "DESCRIPTION", DESCRIPTION },
  { "DIRECTIVE", DIRECTIVE },
  { "DIRECTIVE", DIRECTIVE },
  { "EXECUTE", EXECUTE },
  { "EXECUTE", EXECUTE },
  { "EXPORTS", EXPORTS },
  { "EXPORTS", EXPORTS },
  { "HEAPSIZE", HEAPSIZE },
  { "HEAPSIZE", HEAPSIZE },
  { "IMPORTS", IMPORTS },
  { "IMPORTS", IMPORTS },
  { "LIBRARY", LIBRARY },
  { "LIBRARY", LIBRARY },
  { "NAME", NAME },
  { "NAME", NAME },
  { "NONAME", NONAMEU },
  { "NONAME", NONAMEU },
  { "noname", NONAMEL },
  { "noname", NONAMEL },
  { "PRIVATE", PRIVATEU },
  { "PRIVATE", PRIVATEU },
  { "private", PRIVATEL },
  { "private", PRIVATEL },
  { "READ", READ },
  { "READ", READ },
  { "SECTIONS", SECTIONS },
  { "SECTIONS", SECTIONS },
  { "SEGMENTS", SECTIONS },
  { "SEGMENTS", SECTIONS },
  { "SHARED", SHARED },
  { "SHARED", SHARED },
  { "STACKSIZE", STACKSIZE },
  { "STACKSIZE", STACKSIZE },
  { "VERSION", VERSIONK },
  { "VERSION", VERSIONK },
  { "WRITE", WRITE },
  { "WRITE", WRITE },
  { 0, 0 }
  { 0, 0 }
};
};
static int
static int
def_getc (void)
def_getc (void)
{
{
  int rv;
  int rv;
  if (lex_parse_string)
  if (lex_parse_string)
    {
    {
      if (lex_parse_string >= lex_parse_string_end)
      if (lex_parse_string >= lex_parse_string_end)
        rv = EOF;
        rv = EOF;
      else
      else
        rv = *lex_parse_string++;
        rv = *lex_parse_string++;
    }
    }
  else
  else
    {
    {
      rv = fgetc (the_file);
      rv = fgetc (the_file);
    }
    }
  if (rv == '\n')
  if (rv == '\n')
    saw_newline = 1;
    saw_newline = 1;
  return rv;
  return rv;
}
}
static int
static int
def_ungetc (int c)
def_ungetc (int c)
{
{
  if (lex_parse_string)
  if (lex_parse_string)
    {
    {
      lex_parse_string--;
      lex_parse_string--;
      return c;
      return c;
    }
    }
  else
  else
    return ungetc (c, the_file);
    return ungetc (c, the_file);
}
}
static int
static int
def_lex (void)
def_lex (void)
{
{
  int c, i, q;
  int c, i, q;
  if (lex_forced_token)
  if (lex_forced_token)
    {
    {
      i = lex_forced_token;
      i = lex_forced_token;
      lex_forced_token = 0;
      lex_forced_token = 0;
#if TRACE
#if TRACE
      printf ("lex: forcing token %d\n", i);
      printf ("lex: forcing token %d\n", i);
#endif
#endif
      return i;
      return i;
    }
    }
  c = def_getc ();
  c = def_getc ();
  /* Trim leading whitespace.  */
  /* Trim leading whitespace.  */
  while (c != EOF && (c == ' ' || c == '\t') && saw_newline)
  while (c != EOF && (c == ' ' || c == '\t') && saw_newline)
    c = def_getc ();
    c = def_getc ();
  if (c == EOF)
  if (c == EOF)
    {
    {
#if TRACE
#if TRACE
      printf ("lex: EOF\n");
      printf ("lex: EOF\n");
#endif
#endif
      return 0;
      return 0;
    }
    }
  if (saw_newline && c == ';')
  if (saw_newline && c == ';')
    {
    {
      do
      do
        {
        {
          c = def_getc ();
          c = def_getc ();
        }
        }
      while (c != EOF && c != '\n');
      while (c != EOF && c != '\n');
      if (c == '\n')
      if (c == '\n')
        return def_lex ();
        return def_lex ();
      return 0;
      return 0;
    }
    }
  /* Must be something else.  */
  /* Must be something else.  */
  saw_newline = 0;
  saw_newline = 0;
  if (ISDIGIT (c))
  if (ISDIGIT (c))
    {
    {
      bufptr = 0;
      bufptr = 0;
      while (c != EOF && (ISXDIGIT (c) || (c == 'x')))
      while (c != EOF && (ISXDIGIT (c) || (c == 'x')))
        {
        {
          put_buf (c);
          put_buf (c);
          c = def_getc ();
          c = def_getc ();
        }
        }
      if (c != EOF)
      if (c != EOF)
        def_ungetc (c);
        def_ungetc (c);
      yylval.number = strtoul (buffer, 0, 0);
      yylval.number = strtoul (buffer, 0, 0);
#if TRACE
#if TRACE
      printf ("lex: `%s' returns NUMBER %d\n", buffer, yylval.number);
      printf ("lex: `%s' returns NUMBER %d\n", buffer, yylval.number);
#endif
#endif
      return NUMBER;
      return NUMBER;
    }
    }
  if (ISALPHA (c) || strchr ("$:-_?@", c))
  if (ISALPHA (c) || strchr ("$:-_?@", c))
    {
    {
      bufptr = 0;
      bufptr = 0;
      q = c;
      q = c;
      put_buf (c);
      put_buf (c);
      c = def_getc ();
      c = def_getc ();
      if (q == '@')
      if (q == '@')
        {
        {
          if (ISBLANK (c) ) /* '@' followed by whitespace.  */
          if (ISBLANK (c) ) /* '@' followed by whitespace.  */
            return (q);
            return (q);
          else if (ISDIGIT (c)) /* '@' followed by digit.  */
          else if (ISDIGIT (c)) /* '@' followed by digit.  */
            {
            {
              def_ungetc (c);
              def_ungetc (c);
              return (q);
              return (q);
            }
            }
#if TRACE
#if TRACE
          printf ("lex: @ returns itself\n");
          printf ("lex: @ returns itself\n");
#endif
#endif
        }
        }
      while (c != EOF && (ISALNUM (c) || strchr ("$:-_?/@", c)))
      while (c != EOF && (ISALNUM (c) || strchr ("$:-_?/@", c)))
        {
        {
          put_buf (c);
          put_buf (c);
          c = def_getc ();
          c = def_getc ();
        }
        }
      if (c != EOF)
      if (c != EOF)
        def_ungetc (c);
        def_ungetc (c);
      if (ISALPHA (q)) /* Check for tokens.  */
      if (ISALPHA (q)) /* Check for tokens.  */
        {
        {
          for (i = 0; tokens[i].name; i++)
          for (i = 0; tokens[i].name; i++)
            if (strcmp (tokens[i].name, buffer) == 0)
            if (strcmp (tokens[i].name, buffer) == 0)
              {
              {
#if TRACE
#if TRACE
                printf ("lex: `%s' is a string token\n", buffer);
                printf ("lex: `%s' is a string token\n", buffer);
#endif
#endif
                return tokens[i].token;
                return tokens[i].token;
              }
              }
        }
        }
#if TRACE
#if TRACE
      printf ("lex: `%s' returns ID\n", buffer);
      printf ("lex: `%s' returns ID\n", buffer);
#endif
#endif
      yylval.id = xstrdup (buffer);
      yylval.id = xstrdup (buffer);
      return ID;
      return ID;
    }
    }
  if (c == '\'' || c == '"')
  if (c == '\'' || c == '"')
    {
    {
      q = c;
      q = c;
      c = def_getc ();
      c = def_getc ();
      bufptr = 0;
      bufptr = 0;
      while (c != EOF && c != q)
      while (c != EOF && c != q)
        {
        {
          put_buf (c);
          put_buf (c);
          c = def_getc ();
          c = def_getc ();
        }
        }
      yylval.id = xstrdup (buffer);
      yylval.id = xstrdup (buffer);
#if TRACE
#if TRACE
      printf ("lex: `%s' returns ID\n", buffer);
      printf ("lex: `%s' returns ID\n", buffer);
#endif
#endif
      return ID;
      return ID;
    }
    }
  if (c == '=' || c == '.' || c == ',')
  if (c == '=' || c == '.' || c == ',')
    {
    {
#if TRACE
#if TRACE
      printf ("lex: `%c' returns itself\n", c);
      printf ("lex: `%c' returns itself\n", c);
#endif
#endif
      return c;
      return c;
    }
    }
  if (c == '\n')
  if (c == '\n')
    {
    {
      linenumber++;
      linenumber++;
      saw_newline = 1;
      saw_newline = 1;
    }
    }
  /*printf ("lex: 0x%02x ignored\n", c); */
  /*printf ("lex: 0x%02x ignored\n", c); */
  return def_lex ();
  return def_lex ();
}
}
 
 

powered by: WebSVN 2.1.0

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