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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [c-pch.c] - Diff between revs 154 and 816

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

Rev 154 Rev 816
/* Precompiled header implementation for the C languages.
/* Precompiled header implementation for the C languages.
   Copyright (C) 2000, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
   Copyright (C) 2000, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
 
 
This file is part of GCC.
This file is part of GCC.
 
 
GCC is free software; you can redistribute it and/or modify
GCC 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, or (at your option)
the Free Software Foundation; either version 3, or (at your option)
any later version.
any later version.
 
 
GCC is distributed in the hope that it will be useful,
GCC 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 GCC; see the file COPYING3.  If not see
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */
<http://www.gnu.org/licenses/>.  */
 
 
#include "config.h"
#include "config.h"
#include "system.h"
#include "system.h"
#include "coretypes.h"
#include "coretypes.h"
#include "version.h"
#include "version.h"
#include "cpplib.h"
#include "cpplib.h"
#include "tree.h"
#include "tree.h"
#include "flags.h"
#include "flags.h"
#include "c-common.h"
#include "c-common.h"
#include "output.h"
#include "output.h"
#include "toplev.h"
#include "toplev.h"
#include "debug.h"
#include "debug.h"
#include "c-pragma.h"
#include "c-pragma.h"
#include "ggc.h"
#include "ggc.h"
#include "langhooks.h"
#include "langhooks.h"
#include "hosthooks.h"
#include "hosthooks.h"
#include "target.h"
#include "target.h"
 
 
/* This is a list of flag variables that must match exactly, and their
/* This is a list of flag variables that must match exactly, and their
   names for the error message.  The possible values for *flag_var must
   names for the error message.  The possible values for *flag_var must
   fit in a 'signed char'.  */
   fit in a 'signed char'.  */
 
 
static const struct c_pch_matching
static const struct c_pch_matching
{
{
  int *flag_var;
  int *flag_var;
  const char *flag_name;
  const char *flag_name;
} pch_matching[] = {
} pch_matching[] = {
  { &flag_exceptions, "-fexceptions" },
  { &flag_exceptions, "-fexceptions" },
  { &flag_unit_at_a_time, "-funit-at-a-time" }
  { &flag_unit_at_a_time, "-funit-at-a-time" }
};
};
 
 
enum {
enum {
  MATCH_SIZE = ARRAY_SIZE (pch_matching)
  MATCH_SIZE = ARRAY_SIZE (pch_matching)
};
};
 
 
/* The value of the checksum in the dummy compiler that is actually
/* The value of the checksum in the dummy compiler that is actually
   checksummed.  That compiler should never be run.  */
   checksummed.  That compiler should never be run.  */
static const char no_checksum[16] = { 0 };
static const char no_checksum[16] = { 0 };
 
 
/* Information about flags and suchlike that affect PCH validity.
/* Information about flags and suchlike that affect PCH validity.
 
 
   Before this structure is read, both an initial 8-character identification
   Before this structure is read, both an initial 8-character identification
   string, and a 16-byte checksum, have been read and validated.  */
   string, and a 16-byte checksum, have been read and validated.  */
 
 
struct c_pch_validity
struct c_pch_validity
{
{
  unsigned char debug_info_type;
  unsigned char debug_info_type;
  signed char match[MATCH_SIZE];
  signed char match[MATCH_SIZE];
  void (*pch_init) (void);
  void (*pch_init) (void);
  size_t target_data_length;
  size_t target_data_length;
};
};
 
 
struct c_pch_header
struct c_pch_header
{
{
  unsigned long asm_size;
  unsigned long asm_size;
};
};
 
 
#define IDENT_LENGTH 8
#define IDENT_LENGTH 8
 
 
/* The file we'll be writing the PCH to.  */
/* The file we'll be writing the PCH to.  */
static FILE *pch_outfile;
static FILE *pch_outfile;
 
 
/* The position in the assembler output file when pch_init was called.  */
/* The position in the assembler output file when pch_init was called.  */
static long asm_file_startpos;
static long asm_file_startpos;
 
 
static const char *get_ident (void);
static const char *get_ident (void);
 
 
/* Compute an appropriate 8-byte magic number for the PCH file, so that
/* Compute an appropriate 8-byte magic number for the PCH file, so that
   utilities like file(1) can identify it, and so that GCC can quickly
   utilities like file(1) can identify it, and so that GCC can quickly
   ignore non-PCH files and PCH files that are of a completely different
   ignore non-PCH files and PCH files that are of a completely different
   format.  */
   format.  */
 
 
static const char *
static const char *
get_ident (void)
get_ident (void)
{
{
  static char result[IDENT_LENGTH];
  static char result[IDENT_LENGTH];
  static const char template[IDENT_LENGTH] = "gpch.013";
  static const char template[IDENT_LENGTH] = "gpch.013";
  static const char c_language_chars[] = "Co+O";
  static const char c_language_chars[] = "Co+O";
 
 
  memcpy (result, template, IDENT_LENGTH);
  memcpy (result, template, IDENT_LENGTH);
  result[4] = c_language_chars[c_language];
  result[4] = c_language_chars[c_language];
 
 
  return result;
  return result;
}
}
 
 
/* Prepare to write a PCH file, if one is being written.  This is
/* Prepare to write a PCH file, if one is being written.  This is
   called at the start of compilation.
   called at the start of compilation.
 
 
   Also, print out the executable checksum if -fverbose-asm is in effect.  */
   Also, print out the executable checksum if -fverbose-asm is in effect.  */
 
 
void
void
pch_init (void)
pch_init (void)
{
{
  FILE *f;
  FILE *f;
  struct c_pch_validity v;
  struct c_pch_validity v;
  void *target_validity;
  void *target_validity;
  static const char partial_pch[IDENT_LENGTH] = "gpcWrite";
  static const char partial_pch[IDENT_LENGTH] = "gpcWrite";
 
 
#ifdef ASM_COMMENT_START
#ifdef ASM_COMMENT_START
  if (flag_verbose_asm)
  if (flag_verbose_asm)
    {
    {
      fprintf (asm_out_file, "%s ", ASM_COMMENT_START);
      fprintf (asm_out_file, "%s ", ASM_COMMENT_START);
      c_common_print_pch_checksum (asm_out_file);
      c_common_print_pch_checksum (asm_out_file);
      fputc ('\n', asm_out_file);
      fputc ('\n', asm_out_file);
    }
    }
#endif
#endif
 
 
  if (!pch_file)
  if (!pch_file)
    return;
    return;
 
 
  f = fopen (pch_file, "w+b");
  f = fopen (pch_file, "w+b");
  if (f == NULL)
  if (f == NULL)
    fatal_error ("can%'t create precompiled header %s: %m", pch_file);
    fatal_error ("can%'t create precompiled header %s: %m", pch_file);
  pch_outfile = f;
  pch_outfile = f;
 
 
  gcc_assert (memcmp (executable_checksum, no_checksum, 16) != 0);
  gcc_assert (memcmp (executable_checksum, no_checksum, 16) != 0);
 
 
  v.debug_info_type = write_symbols;
  v.debug_info_type = write_symbols;
  {
  {
    size_t i;
    size_t i;
    for (i = 0; i < MATCH_SIZE; i++)
    for (i = 0; i < MATCH_SIZE; i++)
      {
      {
        v.match[i] = *pch_matching[i].flag_var;
        v.match[i] = *pch_matching[i].flag_var;
        gcc_assert (v.match[i] == *pch_matching[i].flag_var);
        gcc_assert (v.match[i] == *pch_matching[i].flag_var);
      }
      }
  }
  }
  v.pch_init = &pch_init;
  v.pch_init = &pch_init;
  target_validity = targetm.get_pch_validity (&v.target_data_length);
  target_validity = targetm.get_pch_validity (&v.target_data_length);
 
 
  if (fwrite (partial_pch, IDENT_LENGTH, 1, f) != 1
  if (fwrite (partial_pch, IDENT_LENGTH, 1, f) != 1
      || fwrite (executable_checksum, 16, 1, f) != 1
      || fwrite (executable_checksum, 16, 1, f) != 1
      || fwrite (&v, sizeof (v), 1, f) != 1
      || fwrite (&v, sizeof (v), 1, f) != 1
      || fwrite (target_validity, v.target_data_length, 1, f) != 1)
      || fwrite (target_validity, v.target_data_length, 1, f) != 1)
    fatal_error ("can%'t write to %s: %m", pch_file);
    fatal_error ("can%'t write to %s: %m", pch_file);
 
 
  /* We need to be able to re-read the output.  */
  /* We need to be able to re-read the output.  */
  /* The driver always provides a valid -o option.  */
  /* The driver always provides a valid -o option.  */
  if (asm_file_name == NULL
  if (asm_file_name == NULL
      || strcmp (asm_file_name, "-") == 0)
      || strcmp (asm_file_name, "-") == 0)
    fatal_error ("%qs is not a valid output file", asm_file_name);
    fatal_error ("%qs is not a valid output file", asm_file_name);
 
 
  asm_file_startpos = ftell (asm_out_file);
  asm_file_startpos = ftell (asm_out_file);
 
 
  /* Let the debugging format deal with the PCHness.  */
  /* Let the debugging format deal with the PCHness.  */
  (*debug_hooks->handle_pch) (0);
  (*debug_hooks->handle_pch) (0);
 
 
  cpp_save_state (parse_in, f);
  cpp_save_state (parse_in, f);
}
}
 
 
/* Write the PCH file.  This is called at the end of a compilation which
/* Write the PCH file.  This is called at the end of a compilation which
   will produce a PCH file.  */
   will produce a PCH file.  */
 
 
void
void
c_common_write_pch (void)
c_common_write_pch (void)
{
{
  char *buf;
  char *buf;
  long asm_file_end;
  long asm_file_end;
  long written;
  long written;
  struct c_pch_header h;
  struct c_pch_header h;
 
 
  (*debug_hooks->handle_pch) (1);
  (*debug_hooks->handle_pch) (1);
 
 
  cpp_write_pch_deps (parse_in, pch_outfile);
  cpp_write_pch_deps (parse_in, pch_outfile);
 
 
  asm_file_end = ftell (asm_out_file);
  asm_file_end = ftell (asm_out_file);
  h.asm_size = asm_file_end - asm_file_startpos;
  h.asm_size = asm_file_end - asm_file_startpos;
 
 
  if (fwrite (&h, sizeof (h), 1, pch_outfile) != 1)
  if (fwrite (&h, sizeof (h), 1, pch_outfile) != 1)
    fatal_error ("can%'t write %s: %m", pch_file);
    fatal_error ("can%'t write %s: %m", pch_file);
 
 
  buf = XNEWVEC (char, 16384);
  buf = XNEWVEC (char, 16384);
 
 
  if (fseek (asm_out_file, asm_file_startpos, SEEK_SET) != 0)
  if (fseek (asm_out_file, asm_file_startpos, SEEK_SET) != 0)
    fatal_error ("can%'t seek in %s: %m", asm_file_name);
    fatal_error ("can%'t seek in %s: %m", asm_file_name);
 
 
  for (written = asm_file_startpos; written < asm_file_end; )
  for (written = asm_file_startpos; written < asm_file_end; )
    {
    {
      long size = asm_file_end - written;
      long size = asm_file_end - written;
      if (size > 16384)
      if (size > 16384)
        size = 16384;
        size = 16384;
      if (fread (buf, size, 1, asm_out_file) != 1)
      if (fread (buf, size, 1, asm_out_file) != 1)
        fatal_error ("can%'t read %s: %m", asm_file_name);
        fatal_error ("can%'t read %s: %m", asm_file_name);
      if (fwrite (buf, size, 1, pch_outfile) != 1)
      if (fwrite (buf, size, 1, pch_outfile) != 1)
        fatal_error ("can%'t write %s: %m", pch_file);
        fatal_error ("can%'t write %s: %m", pch_file);
      written += size;
      written += size;
    }
    }
  free (buf);
  free (buf);
  /* asm_out_file can be written afterwards, so fseek to clear
  /* asm_out_file can be written afterwards, so fseek to clear
     _IOREAD flag.  */
     _IOREAD flag.  */
  if (fseek (asm_out_file, 0, SEEK_END) != 0)
  if (fseek (asm_out_file, 0, SEEK_END) != 0)
    fatal_error ("can%'t seek in %s: %m", asm_file_name);
    fatal_error ("can%'t seek in %s: %m", asm_file_name);
 
 
  gt_pch_save (pch_outfile);
  gt_pch_save (pch_outfile);
  cpp_write_pch_state (parse_in, pch_outfile);
  cpp_write_pch_state (parse_in, pch_outfile);
 
 
  if (fseek (pch_outfile, 0, SEEK_SET) != 0
  if (fseek (pch_outfile, 0, SEEK_SET) != 0
      || fwrite (get_ident (), IDENT_LENGTH, 1, pch_outfile) != 1)
      || fwrite (get_ident (), IDENT_LENGTH, 1, pch_outfile) != 1)
    fatal_error ("can%'t write %s: %m", pch_file);
    fatal_error ("can%'t write %s: %m", pch_file);
 
 
  fclose (pch_outfile);
  fclose (pch_outfile);
}
}
 
 
/* Check the PCH file called NAME, open on FD, to see if it can be
/* Check the PCH file called NAME, open on FD, to see if it can be
   used in this compilation.  Return 1 if valid, 0 if the file can't
   used in this compilation.  Return 1 if valid, 0 if the file can't
   be used now but might be if it's seen later in the compilation, and
   be used now but might be if it's seen later in the compilation, and
   2 if this file could never be used in the compilation.  */
   2 if this file could never be used in the compilation.  */
 
 
int
int
c_common_valid_pch (cpp_reader *pfile, const char *name, int fd)
c_common_valid_pch (cpp_reader *pfile, const char *name, int fd)
{
{
  int sizeread;
  int sizeread;
  int result;
  int result;
  char ident[IDENT_LENGTH + 16];
  char ident[IDENT_LENGTH + 16];
  const char *pch_ident;
  const char *pch_ident;
  struct c_pch_validity v;
  struct c_pch_validity v;
 
 
  /* Perform a quick test of whether this is a valid
  /* Perform a quick test of whether this is a valid
     precompiled header for the current language.  */
     precompiled header for the current language.  */
 
 
  gcc_assert (memcmp (executable_checksum, no_checksum, 16) != 0);
  gcc_assert (memcmp (executable_checksum, no_checksum, 16) != 0);
 
 
  sizeread = read (fd, ident, IDENT_LENGTH + 16);
  sizeread = read (fd, ident, IDENT_LENGTH + 16);
  if (sizeread == -1)
  if (sizeread == -1)
    fatal_error ("can%'t read %s: %m", name);
    fatal_error ("can%'t read %s: %m", name);
  else if (sizeread != IDENT_LENGTH + 16)
  else if (sizeread != IDENT_LENGTH + 16)
    {
    {
      cpp_error (pfile, CPP_DL_WARNING, "%s: too short to be a PCH file",
      cpp_error (pfile, CPP_DL_WARNING, "%s: too short to be a PCH file",
                 name);
                 name);
      return 2;
      return 2;
    }
    }
 
 
  pch_ident = get_ident();
  pch_ident = get_ident();
  if (memcmp (ident, pch_ident, IDENT_LENGTH) != 0)
  if (memcmp (ident, pch_ident, IDENT_LENGTH) != 0)
    {
    {
      if (cpp_get_options (pfile)->warn_invalid_pch)
      if (cpp_get_options (pfile)->warn_invalid_pch)
        {
        {
          if (memcmp (ident, pch_ident, 5) == 0)
          if (memcmp (ident, pch_ident, 5) == 0)
            /* It's a PCH, for the right language, but has the wrong version.
            /* It's a PCH, for the right language, but has the wrong version.
             */
             */
            cpp_error (pfile, CPP_DL_WARNING,
            cpp_error (pfile, CPP_DL_WARNING,
                       "%s: not compatible with this GCC version", name);
                       "%s: not compatible with this GCC version", name);
          else if (memcmp (ident, pch_ident, 4) == 0)
          else if (memcmp (ident, pch_ident, 4) == 0)
            /* It's a PCH for the wrong language.  */
            /* It's a PCH for the wrong language.  */
            cpp_error (pfile, CPP_DL_WARNING, "%s: not for %s", name,
            cpp_error (pfile, CPP_DL_WARNING, "%s: not for %s", name,
                       lang_hooks.name);
                       lang_hooks.name);
          else
          else
            /* Not any kind of PCH.  */
            /* Not any kind of PCH.  */
            cpp_error (pfile, CPP_DL_WARNING, "%s: not a PCH file", name);
            cpp_error (pfile, CPP_DL_WARNING, "%s: not a PCH file", name);
        }
        }
      return 2;
      return 2;
    }
    }
  if (memcmp (ident + IDENT_LENGTH, executable_checksum, 16) != 0)
  if (memcmp (ident + IDENT_LENGTH, executable_checksum, 16) != 0)
    {
    {
      if (cpp_get_options (pfile)->warn_invalid_pch)
      if (cpp_get_options (pfile)->warn_invalid_pch)
        cpp_error (pfile, CPP_DL_WARNING,
        cpp_error (pfile, CPP_DL_WARNING,
                   "%s: created by a different GCC executable", name);
                   "%s: created by a different GCC executable", name);
      return 2;
      return 2;
    }
    }
 
 
  /* At this point, we know it's a PCH file created by this
  /* At this point, we know it's a PCH file created by this
     executable, so it ought to be long enough that we can read a
     executable, so it ought to be long enough that we can read a
     c_pch_validity structure.  */
     c_pch_validity structure.  */
  if (read (fd, &v, sizeof (v)) != sizeof (v))
  if (read (fd, &v, sizeof (v)) != sizeof (v))
    fatal_error ("can%'t read %s: %m", name);
    fatal_error ("can%'t read %s: %m", name);
 
 
  /* The allowable debug info combinations are that either the PCH file
  /* The allowable debug info combinations are that either the PCH file
     was built with the same as is being used now, or the PCH file was
     was built with the same as is being used now, or the PCH file was
     built for some kind of debug info but now none is in use.  */
     built for some kind of debug info but now none is in use.  */
  if (v.debug_info_type != write_symbols
  if (v.debug_info_type != write_symbols
      && write_symbols != NO_DEBUG)
      && write_symbols != NO_DEBUG)
    {
    {
      if (cpp_get_options (pfile)->warn_invalid_pch)
      if (cpp_get_options (pfile)->warn_invalid_pch)
        cpp_error (pfile, CPP_DL_WARNING,
        cpp_error (pfile, CPP_DL_WARNING,
                   "%s: created with -g%s, but used with -g%s", name,
                   "%s: created with -g%s, but used with -g%s", name,
                   debug_type_names[v.debug_info_type],
                   debug_type_names[v.debug_info_type],
                   debug_type_names[write_symbols]);
                   debug_type_names[write_symbols]);
      return 2;
      return 2;
    }
    }
 
 
  /* Check flags that must match exactly.  */
  /* Check flags that must match exactly.  */
  {
  {
    size_t i;
    size_t i;
    for (i = 0; i < MATCH_SIZE; i++)
    for (i = 0; i < MATCH_SIZE; i++)
      if (*pch_matching[i].flag_var != v.match[i])
      if (*pch_matching[i].flag_var != v.match[i])
        {
        {
          if (cpp_get_options (pfile)->warn_invalid_pch)
          if (cpp_get_options (pfile)->warn_invalid_pch)
            cpp_error (pfile, CPP_DL_WARNING,
            cpp_error (pfile, CPP_DL_WARNING,
                       "%s: settings for %s do not match", name,
                       "%s: settings for %s do not match", name,
                       pch_matching[i].flag_name);
                       pch_matching[i].flag_name);
          return 2;
          return 2;
        }
        }
  }
  }
 
 
  /* If the text segment was not loaded at the same address as it was
  /* If the text segment was not loaded at the same address as it was
     when the PCH file was created, function pointers loaded from the
     when the PCH file was created, function pointers loaded from the
     PCH will not be valid.  We could in theory remap all the function
     PCH will not be valid.  We could in theory remap all the function
     pointers, but no support for that exists at present.
     pointers, but no support for that exists at present.
     Since we have the same executable, it should only be necessary to
     Since we have the same executable, it should only be necessary to
     check one function.  */
     check one function.  */
  if (v.pch_init != &pch_init)
  if (v.pch_init != &pch_init)
    {
    {
      if (cpp_get_options (pfile)->warn_invalid_pch)
      if (cpp_get_options (pfile)->warn_invalid_pch)
        cpp_error (pfile, CPP_DL_WARNING,
        cpp_error (pfile, CPP_DL_WARNING,
                   "%s: had text segment at different address", name);
                   "%s: had text segment at different address", name);
      return 2;
      return 2;
    }
    }
 
 
  /* Check the target-specific validity data.  */
  /* Check the target-specific validity data.  */
  {
  {
    void *this_file_data = xmalloc (v.target_data_length);
    void *this_file_data = xmalloc (v.target_data_length);
    const char *msg;
    const char *msg;
 
 
    if ((size_t) read (fd, this_file_data, v.target_data_length)
    if ((size_t) read (fd, this_file_data, v.target_data_length)
        != v.target_data_length)
        != v.target_data_length)
      fatal_error ("can%'t read %s: %m", name);
      fatal_error ("can%'t read %s: %m", name);
    msg = targetm.pch_valid_p (this_file_data, v.target_data_length);
    msg = targetm.pch_valid_p (this_file_data, v.target_data_length);
    free (this_file_data);
    free (this_file_data);
    if (msg != NULL)
    if (msg != NULL)
      {
      {
        if (cpp_get_options (pfile)->warn_invalid_pch)
        if (cpp_get_options (pfile)->warn_invalid_pch)
          cpp_error (pfile, CPP_DL_WARNING, "%s: %s", name, msg);
          cpp_error (pfile, CPP_DL_WARNING, "%s: %s", name, msg);
        return 2;
        return 2;
      }
      }
  }
  }
 
 
  /* Check the preprocessor macros are the same as when the PCH was
  /* Check the preprocessor macros are the same as when the PCH was
     generated.  */
     generated.  */
 
 
  result = cpp_valid_state (pfile, name, fd);
  result = cpp_valid_state (pfile, name, fd);
  if (result == -1)
  if (result == -1)
    return 2;
    return 2;
  else
  else
    return result == 0;
    return result == 0;
}
}
 
 
/* If non-NULL, this function is called after a precompile header file
/* If non-NULL, this function is called after a precompile header file
   is loaded.  */
   is loaded.  */
void (*lang_post_pch_load) (void);
void (*lang_post_pch_load) (void);
 
 
/* Load in the PCH file NAME, open on FD.  It was originally searched for
/* Load in the PCH file NAME, open on FD.  It was originally searched for
   by ORIG_NAME.  */
   by ORIG_NAME.  */
 
 
void
void
c_common_read_pch (cpp_reader *pfile, const char *name,
c_common_read_pch (cpp_reader *pfile, const char *name,
                   int fd, const char *orig_name ATTRIBUTE_UNUSED)
                   int fd, const char *orig_name ATTRIBUTE_UNUSED)
{
{
  FILE *f;
  FILE *f;
  struct c_pch_header h;
  struct c_pch_header h;
  struct save_macro_data *smd;
  struct save_macro_data *smd;
 
 
  f = fdopen (fd, "rb");
  f = fdopen (fd, "rb");
  if (f == NULL)
  if (f == NULL)
    {
    {
      cpp_errno (pfile, CPP_DL_ERROR, "calling fdopen");
      cpp_errno (pfile, CPP_DL_ERROR, "calling fdopen");
      return;
      return;
    }
    }
 
 
  cpp_get_callbacks (parse_in)->valid_pch = NULL;
  cpp_get_callbacks (parse_in)->valid_pch = NULL;
 
 
  if (fread (&h, sizeof (h), 1, f) != 1)
  if (fread (&h, sizeof (h), 1, f) != 1)
    {
    {
      cpp_errno (pfile, CPP_DL_ERROR, "reading");
      cpp_errno (pfile, CPP_DL_ERROR, "reading");
      return;
      return;
    }
    }
 
 
  if (!flag_preprocess_only)
  if (!flag_preprocess_only)
    {
    {
      unsigned long written;
      unsigned long written;
      char * buf = XNEWVEC (char, 16384);
      char * buf = XNEWVEC (char, 16384);
 
 
      for (written = 0; written < h.asm_size; )
      for (written = 0; written < h.asm_size; )
        {
        {
          long size = h.asm_size - written;
          long size = h.asm_size - written;
          if (size > 16384)
          if (size > 16384)
            size = 16384;
            size = 16384;
          if (fread (buf, size, 1, f) != 1
          if (fread (buf, size, 1, f) != 1
              || fwrite (buf, size, 1, asm_out_file) != 1)
              || fwrite (buf, size, 1, asm_out_file) != 1)
            cpp_errno (pfile, CPP_DL_ERROR, "reading");
            cpp_errno (pfile, CPP_DL_ERROR, "reading");
          written += size;
          written += size;
        }
        }
      free (buf);
      free (buf);
    }
    }
  else
  else
    {
    {
      /* If we're preprocessing, don't write to a NULL
      /* If we're preprocessing, don't write to a NULL
         asm_out_file.  */
         asm_out_file.  */
      if (fseek (f, h.asm_size, SEEK_CUR) != 0)
      if (fseek (f, h.asm_size, SEEK_CUR) != 0)
        cpp_errno (pfile, CPP_DL_ERROR, "seeking");
        cpp_errno (pfile, CPP_DL_ERROR, "seeking");
    }
    }
 
 
  cpp_prepare_state (pfile, &smd);
  cpp_prepare_state (pfile, &smd);
 
 
  gt_pch_restore (f);
  gt_pch_restore (f);
 
 
  if (cpp_read_state (pfile, name, f, smd) != 0)
  if (cpp_read_state (pfile, name, f, smd) != 0)
    return;
    return;
 
 
  fclose (f);
  fclose (f);
 
 
  /* Give the front end a chance to take action after a PCH file has
  /* Give the front end a chance to take action after a PCH file has
     been loaded.  */
     been loaded.  */
  if (lang_post_pch_load)
  if (lang_post_pch_load)
    (*lang_post_pch_load) ();
    (*lang_post_pch_load) ();
}
}
 
 
/* Indicate that no more PCH files should be read.  */
/* Indicate that no more PCH files should be read.  */
 
 
void
void
c_common_no_more_pch (void)
c_common_no_more_pch (void)
{
{
  if (cpp_get_callbacks (parse_in)->valid_pch)
  if (cpp_get_callbacks (parse_in)->valid_pch)
    {
    {
      cpp_get_callbacks (parse_in)->valid_pch = NULL;
      cpp_get_callbacks (parse_in)->valid_pch = NULL;
      host_hooks.gt_pch_use_address (NULL, 0, -1, 0);
      host_hooks.gt_pch_use_address (NULL, 0, -1, 0);
    }
    }
}
}
 
 
/* Handle #pragma GCC pch_preprocess, to load in the PCH file.  */
/* Handle #pragma GCC pch_preprocess, to load in the PCH file.  */
 
 
#ifndef O_BINARY
#ifndef O_BINARY
# define O_BINARY 0
# define O_BINARY 0
#endif
#endif
 
 
void
void
c_common_pch_pragma (cpp_reader *pfile, const char *name)
c_common_pch_pragma (cpp_reader *pfile, const char *name)
{
{
  int fd;
  int fd;
 
 
  if (!cpp_get_options (pfile)->preprocessed)
  if (!cpp_get_options (pfile)->preprocessed)
    {
    {
      error ("pch_preprocess pragma should only be used with -fpreprocessed");
      error ("pch_preprocess pragma should only be used with -fpreprocessed");
      inform ("use #include instead");
      inform ("use #include instead");
      return;
      return;
    }
    }
 
 
  fd = open (name, O_RDONLY | O_BINARY, 0666);
  fd = open (name, O_RDONLY | O_BINARY, 0666);
  if (fd == -1)
  if (fd == -1)
    fatal_error ("%s: couldn%'t open PCH file: %m", name);
    fatal_error ("%s: couldn%'t open PCH file: %m", name);
 
 
  if (c_common_valid_pch (pfile, name, fd) != 1)
  if (c_common_valid_pch (pfile, name, fd) != 1)
    {
    {
      if (!cpp_get_options (pfile)->warn_invalid_pch)
      if (!cpp_get_options (pfile)->warn_invalid_pch)
        inform ("use -Winvalid-pch for more information");
        inform ("use -Winvalid-pch for more information");
      fatal_error ("%s: PCH file was invalid", name);
      fatal_error ("%s: PCH file was invalid", name);
    }
    }
 
 
  c_common_read_pch (pfile, name, fd, name);
  c_common_read_pch (pfile, name, fd, name);
 
 
  close (fd);
  close (fd);
}
}
 
 
/* Print out executable_checksum[].  */
/* Print out executable_checksum[].  */
 
 
void
void
c_common_print_pch_checksum (FILE *f)
c_common_print_pch_checksum (FILE *f)
{
{
  int i;
  int i;
  fputs ("Compiler executable checksum: ", f);
  fputs ("Compiler executable checksum: ", f);
  for (i = 0; i < 16; i++)
  for (i = 0; i < 16; i++)
    fprintf (f, "%02x", executable_checksum[i]);
    fprintf (f, "%02x", executable_checksum[i]);
  putc ('\n', f);
  putc ('\n', f);
}
}
 
 

powered by: WebSVN 2.1.0

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