OSDN Git Service

2011-11-03 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / lto-opts.c
1 /* LTO IL options.
2
3    Copyright 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4    Contributed by Simon Baldwin <simonb@google.com>
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tree.h"
26 #include "hashtab.h"
27 #include "ggc.h"
28 #include "vec.h"
29 #include "bitmap.h"
30 #include "flags.h"
31 #include "opts.h"
32 #include "options.h"
33 #include "common/common-target.h"
34 #include "diagnostic.h"
35 #include "lto-streamer.h"
36 #include "toplev.h"
37
38 /* Write currently held options to an LTO IL section.  */
39
40 void
41 lto_write_options (void)
42 {
43   struct lto_output_stream stream;
44   char *section_name;
45   struct obstack temporary_obstack;
46   unsigned int i, j;
47   char *args;
48
49   section_name = lto_get_section_name (LTO_section_opts, NULL, NULL);
50   lto_begin_section (section_name, false);
51   memset (&stream, 0, sizeof (stream));
52
53   obstack_init (&temporary_obstack);
54   for (i = 1; i < save_decoded_options_count; ++i)
55     {
56       struct cl_decoded_option *option = &save_decoded_options[i];
57       const char *q, *p;
58
59       /* Skip frontend and driver specific options here.  */
60       if (!(cl_options[option->opt_index].flags & (CL_COMMON|CL_TARGET|CL_LTO)))
61         continue;
62
63       /* Drop options created from the gcc driver that will be rejected
64          when passed on to the driver again.  */
65       if (cl_options[option->opt_index].cl_reject_driver)
66         continue;
67
68       /* Also drop all options that are handled by the driver as well,
69          which includes things like -o and -v or -fhelp for example.
70          We do not need those.  Also drop all diagnostic options.  */
71       if (cl_options[option->opt_index].flags & (CL_DRIVER|CL_WARNING))
72         continue;
73
74       /* Skip explicitly some common options that we do not need.  */
75       switch (option->opt_index)
76         {
77         case OPT_dumpbase:
78         case OPT_SPECIAL_input_file:
79           continue;
80
81         default:
82           break;
83         }
84
85       if (i != 1)
86         obstack_grow (&temporary_obstack, " ", 1);
87       obstack_grow (&temporary_obstack, "'", 1);
88       q = option->canonical_option[0];
89       while ((p = strchr (q, '\'')))
90         {
91           obstack_grow (&temporary_obstack, q, p - q);
92           obstack_grow (&temporary_obstack, "'\\''", 4);
93           q = ++p;
94         }
95       obstack_grow (&temporary_obstack, q, strlen (q));
96       obstack_grow (&temporary_obstack, "'", 1);
97
98       for (j = 1; j < option->canonical_option_num_elements; ++j)
99         {
100           obstack_grow (&temporary_obstack, " '", 2);
101           q = option->canonical_option[j];
102           while ((p = strchr (q, '\'')))
103             {
104               obstack_grow (&temporary_obstack, q, p - q);
105               obstack_grow (&temporary_obstack, "'\\''", 4);
106               q = ++p;
107             }
108           obstack_grow (&temporary_obstack, q, strlen (q));
109           obstack_grow (&temporary_obstack, "'", 1);
110         }
111     }
112   obstack_grow (&temporary_obstack, "\0", 1);
113   args = XOBFINISH (&temporary_obstack, char *);
114   lto_output_data_stream (&stream, args, strlen (args) + 1);
115
116   lto_write_stream (&stream);
117   lto_end_section ();
118
119   obstack_free (&temporary_obstack, NULL);
120   free (section_name);
121 }