summaryrefslogtreecommitdiffstats
path: root/gcc/c-pch.c
diff options
context:
space:
mode:
authorgeoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4>2004-06-22 06:51:56 +0000
committergeoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4>2004-06-22 06:51:56 +0000
commitd718b525701491becba5852fc642f13f9f1ed42f (patch)
tree33b0e3a2356eea4890c97f802528ed3f9e8ceebd /gcc/c-pch.c
parenta61b7bc46d0b0850dba55f8cd8afc33d729f14b1 (diff)
downloadppe42-gcc-d718b525701491becba5852fc642f13f9f1ed42f.tar.gz
ppe42-gcc-d718b525701491becba5852fc642f13f9f1ed42f.zip
2004-06-21 Geoffrey Keating <geoffk@apple.com>
* c-opts.c (c_common_handle_option): Handle -fpch-preprocess. * c-common.h (flag_pch_preprocess): Declare. (c_common_pch_pragma): Likewise. * c-common.c (flag_pch_preprocess): New. * c-pch.c (c_common_read_pch): Support -fpreprocess-only. (c_common_pch_pragma): New. * c-ppoutput.c (cb_read_pch): New. (init_pp_output): Support -fpch-preprocess. * c-pragma.c (init_pragma): Support #pragma GNUC pch_preprocess. * c.opt (fpch-preprocess): New. * gcc.c (cpp_options): When save-temps, pass -fpch-preprocess. * doc/cppopts.texi: Document -fpch-preprocess. * doc/invoke.texi (Precompiled Headers): Mention that -fpreprocessed is safe for PCH. Mention that if an option is listed as safe that doesn't mean it does what you expect. Index: gcc/testsuite/ChangeLog 2004-06-21 Geoffrey Keating <geoffk@apple.com> * gcc.dg/pch/save-temps-1.c: New file. * gcc.dg/pch/save-temps-1.hs: New file. Index: libcpp/ChangeLog 2004-06-21 Geoffrey Keating <geoffk@apple.com> * files.c (should_stack_file): Correct swapped parameters to call to cb.read_pch. * pch.c (cpp_valid_state): Handle -fpreprocessed. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@83478 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-pch.c')
-rw-r--r--gcc/c-pch.c78
1 files changed, 66 insertions, 12 deletions
diff --git a/gcc/c-pch.c b/gcc/c-pch.c
index 03cf3bf08bc..eb043bd089e 100644
--- a/gcc/c-pch.c
+++ b/gcc/c-pch.c
@@ -393,8 +393,6 @@ c_common_read_pch (cpp_reader *pfile, const char *name,
{
FILE *f;
struct c_pch_header h;
- char *buf;
- unsigned long written;
struct save_macro_data *smd;
f = fdopen (fd, "rb");
@@ -412,18 +410,30 @@ c_common_read_pch (cpp_reader *pfile, const char *name,
return;
}
- buf = xmalloc (16384);
- for (written = 0; written < h.asm_size; )
+ if (!flag_preprocess_only)
{
- long size = h.asm_size - written;
- if (size > 16384)
- size = 16384;
- if (fread (buf, size, 1, f) != 1
- || fwrite (buf, size, 1, asm_out_file) != 1)
- cpp_errno (pfile, CPP_DL_ERROR, "reading");
- written += size;
+ unsigned long written;
+ char * buf = xmalloc (16384);
+
+ for (written = 0; written < h.asm_size; )
+ {
+ long size = h.asm_size - written;
+ if (size > 16384)
+ size = 16384;
+ if (fread (buf, size, 1, f) != 1
+ || fwrite (buf, size, 1, asm_out_file) != 1)
+ cpp_errno (pfile, CPP_DL_ERROR, "reading");
+ written += size;
+ }
+ free (buf);
+ }
+ else
+ {
+ /* If we're preprocessing, don't write to a NULL
+ asm_out_file. */
+ if (fseek (f, h.asm_size, SEEK_CUR) != 0)
+ cpp_errno (pfile, CPP_DL_ERROR, "seeking");
}
- free (buf);
cpp_prepare_state (pfile, &smd);
@@ -446,3 +456,47 @@ c_common_no_more_pch (void)
host_hooks.gt_pch_use_address (NULL, 0, -1, 0);
}
}
+
+/* Handle #pragma GCC pch_preprocess, to load in the PCH file. */
+
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
+void
+c_common_pch_pragma (cpp_reader *pfile)
+{
+ tree name_t;
+ const char *name;
+ int fd;
+
+ if (c_lex (&name_t) != CPP_STRING)
+ {
+ error ("malformed #pragma GCC pch_preprocess, ignored");
+ return;
+ }
+
+ if (! cpp_get_options (pfile)->preprocessed)
+ {
+ error ("pch_preprocess pragma should only be used with -fpreprocessed");
+ inform ("use #include instead");
+ return;
+ }
+
+ name = TREE_STRING_POINTER (name_t);
+
+ fd = open (name, O_RDONLY | O_BINARY, 0666);
+ if (fd == -1)
+ fatal_error ("%s: couldn't open PCH file: %m\n", name);
+
+ if (c_common_valid_pch (pfile, name, fd) != 1)
+ {
+ if (!cpp_get_options (pfile)->warn_invalid_pch)
+ inform ("use -Winvalid-pch for more information");
+ fatal_error ("%s: PCH file was invalid", name);
+ }
+
+ c_common_read_pch (pfile, name, fd, name);
+
+ close (fd);
+}
OpenPOWER on IntegriCloud