3 Copyright 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 Contributed by Simon Baldwin <simonb@google.com>
6 This file is part of GCC.
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
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
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/>. */
24 #include "coretypes.h"
33 #include "common/common-target.h"
34 #include "diagnostic.h"
35 #include "lto-streamer.h"
38 /* Write currently held options to an LTO IL section. */
41 lto_write_options (void)
43 struct lto_output_stream stream
;
45 struct obstack temporary_obstack
;
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
));
53 obstack_init (&temporary_obstack
);
54 for (i
= 1; i
< save_decoded_options_count
; ++i
)
56 struct cl_decoded_option
*option
= &save_decoded_options
[i
];
59 /* Skip frontend and driver specific options here. */
60 if (!(cl_options
[option
->opt_index
].flags
& (CL_COMMON
|CL_TARGET
|CL_LTO
)))
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
)
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
))
74 /* Skip explicitly some common options that we do not need. */
75 switch (option
->opt_index
)
78 case OPT_SPECIAL_input_file
:
86 obstack_grow (&temporary_obstack
, " ", 1);
87 obstack_grow (&temporary_obstack
, "'", 1);
88 q
= option
->canonical_option
[0];
89 while ((p
= strchr (q
, '\'')))
91 obstack_grow (&temporary_obstack
, q
, p
- q
);
92 obstack_grow (&temporary_obstack
, "'\\''", 4);
95 obstack_grow (&temporary_obstack
, q
, strlen (q
));
96 obstack_grow (&temporary_obstack
, "'", 1);
98 for (j
= 1; j
< option
->canonical_option_num_elements
; ++j
)
100 obstack_grow (&temporary_obstack
, " '", 2);
101 q
= option
->canonical_option
[j
];
102 while ((p
= strchr (q
, '\'')))
104 obstack_grow (&temporary_obstack
, q
, p
- q
);
105 obstack_grow (&temporary_obstack
, "'\\''", 4);
108 obstack_grow (&temporary_obstack
, q
, strlen (q
));
109 obstack_grow (&temporary_obstack
, "'", 1);
112 obstack_grow (&temporary_obstack
, "\0", 1);
113 args
= XOBFINISH (&temporary_obstack
, char *);
114 lto_output_data_stream (&stream
, args
, strlen (args
) + 1);
116 lto_write_stream (&stream
);
119 obstack_free (&temporary_obstack
, NULL
);