1 /* gupcspec.c: the UPC compiler driver program
2 Copyright (C) 2001-2014 Free Software Foundation, Inc.
3 Contributed by Gary Funck <gary@intrepid.com>
4 and Nenad Vukicevic <nenad@intrepid.com>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
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"
35 /* GUPC driver - derived from fortran/gfortranspec.c. */
37 /* The original argument list and related info is copied here. */
38 static unsigned int gupc_xargc
;
39 static const struct cl_decoded_option
*gupc_x_decoded_options
;
40 static void append_arg (const struct cl_decoded_option
*);
42 /* The new argument list will be built here. */
43 static unsigned int gupc_newargc
;
44 static struct cl_decoded_option
*gupc_new_decoded_options
;
46 static const char *const standard_bindir_prefix
= STANDARD_BINDIR_PREFIX
;
47 static const char *const standard_exec_prefix
= STANDARD_EXEC_PREFIX
;
49 /* By default the linker is always invoked. */
50 static int invoke_linker
= 1;
52 static int match_suffix (const char *s
, const char *suffix
);
54 #define END_ARGS ((char *) 0)
56 /* Return true if the strings S1 and S2 are either both NULL
57 * or both the same string. */
60 strings_same (const char *s1
, const char *s2
)
62 return s1
== s2
|| (s1
!= NULL
&& s2
!= NULL
&& strcmp (s1
, s2
) == 0);
65 /* Return whether decoded option structures OPT1 and OPT2 are the
69 options_same (const struct cl_decoded_option
*opt1
,
70 const struct cl_decoded_option
*opt2
)
72 return (opt1
->opt_index
== opt2
->opt_index
73 && strings_same (opt1
->arg
, opt2
->arg
)
74 && strings_same (opt1
->orig_option_with_args_text
,
75 opt2
->orig_option_with_args_text
)
76 && strings_same (opt1
->canonical_option
[0],
77 opt2
->canonical_option
[0])
78 && strings_same (opt1
->canonical_option
[1],
79 opt2
->canonical_option
[1])
80 && strings_same (opt1
->canonical_option
[2],
81 opt2
->canonical_option
[2])
82 && strings_same (opt1
->canonical_option
[3],
83 opt2
->canonical_option
[3])
84 && (opt1
->canonical_option_num_elements
85 == opt2
->canonical_option_num_elements
)
86 && opt1
->value
== opt2
->value
&& opt1
->errors
== opt2
->errors
);
89 /* Append another argument to the list being built. As long as it is
90 identical to the corresponding arg in the original list, just increment
91 the new arg count. Otherwise allocate a new list, etc. */
94 append_arg (const struct cl_decoded_option
*arg
)
96 static unsigned int newargsize
;
98 if (gupc_new_decoded_options
== gupc_x_decoded_options
99 && gupc_newargc
< gupc_xargc
100 && options_same (arg
, &gupc_x_decoded_options
[gupc_newargc
]))
103 return; /* Nothing new here. */
106 if (gupc_new_decoded_options
== gupc_x_decoded_options
)
107 { /* Make new arglist. */
110 newargsize
= (gupc_xargc
<< 2) + 20; /* This should handle all. */
111 gupc_new_decoded_options
=
112 XNEWVEC (struct cl_decoded_option
, newargsize
);
114 /* Copy what has been done so far. */
115 for (i
= 0; i
< gupc_newargc
; ++i
)
116 gupc_new_decoded_options
[i
] = gupc_x_decoded_options
[i
];
119 if (gupc_newargc
== newargsize
)
120 fatal_error ("overflowed output arg list for %qs",
121 arg
->orig_option_with_args_text
);
123 gupc_new_decoded_options
[gupc_newargc
++] = *arg
;
126 /* Append an option described by OPT_INDEX, ARG and VALUE to the list
129 append_option (size_t opt_index
, const char *arg
, int value
)
131 struct cl_decoded_option decoded
;
133 generate_option (opt_index
, arg
, value
, CL_DRIVER
, &decoded
);
134 append_arg (&decoded
);
138 match_suffix (const char *s
, const char *suffix
)
140 int slen
= strlen (s
);
141 int xlen
= strlen (suffix
);
142 const char *start
= (xlen
<= slen
) ? s
+ slen
- xlen
: 0;
143 return start
&& !strncmp (start
, suffix
, xlen
);
147 lang_specific_driver (struct cl_decoded_option
**in_decoded_options
,
148 unsigned int *in_decoded_options_count
,
149 int *in_added_libraries ATTRIBUTE_UNUSED
)
151 struct cl_decoded_option
*decoded_options
= *in_decoded_options
;
153 int is_x_in_effect
= 0;
154 int is_x_upc_in_effect
= 0;
158 int pre_processed
= 0;
160 gupc_xargc
= *in_decoded_options_count
;
161 gupc_x_decoded_options
= decoded_options
;
163 gupc_new_decoded_options
= decoded_options
;
165 /* First pass through the argument list. */
167 /* Check to see if any switches are asserted that inhibit linking
168 and record the presence of other switches that may require
170 for (i
= 1; i
< gupc_xargc
; ++i
)
172 if (decoded_options
[i
].errors
& CL_ERR_MISSING_ARG
)
175 switch (decoded_options
[i
].opt_index
)
178 case OPT_SPECIAL_input_file
:
183 case OPT_nodefaultlibs
:
186 case OPT_fsyntax_only
:
188 /* These options disable linking entirely or linking of the
189 standard libraries. */
193 case OPT_fpreprocessed
:
210 /* Optional GUPC version string. Let GCC handle it for now. */
214 /* Let gcc.c handle this, as it has a really
215 cool facility for handling --help and --verbose --help. */
223 /* Create the new argument list. */
225 /* Start with the compiler itself. */
226 append_arg (&decoded_options
[0]);
228 /* Always assert -fupc. */
229 append_option (OPT_fupc
, NULL
, 1);
231 /* If there are no input files, no need for the library. */
235 /* Copy in the arguments as passed to 'upc' */
237 is_x_upc_in_effect
= 0;
238 for (i
= 1; i
< gupc_xargc
; ++i
)
240 /* Skip -fupc, we asserted it above. */
241 if (decoded_options
[i
].opt_index
== OPT_fupc
)
244 /* Check for "-x [c,upc,..]". */
245 if (decoded_options
[i
].opt_index
== OPT_x
)
247 /* Go to default if "none" found. */
248 if (!strcmp (decoded_options
[i
].arg
, "none"))
251 is_x_upc_in_effect
= 0;
257 /* By default, driver accepts C files as UPC files. Unless there
258 is "-x" option in affect. */
259 if (decoded_options
[i
].opt_index
== OPT_SPECIAL_input_file
)
261 const int is_c_file
= match_suffix (decoded_options
[i
].arg
, ".c")
262 || match_suffix (decoded_options
[i
].arg
, ".h")
263 || (pre_processed
&& match_suffix (decoded_options
[i
].arg
, ".i"));
266 if ( !(is_x_in_effect
|| is_x_upc_in_effect
))
268 append_option (OPT_x
, "upc", 1);
269 is_x_upc_in_effect
= 1;
271 append_arg (&decoded_options
[i
]);
276 if (is_x_upc_in_effect
)
278 is_x_upc_in_effect
= 0;
279 append_option (OPT_x
, "none", 1);
283 append_arg (&decoded_options
[i
]);
288 fprintf (stderr
, "Driving:");
289 for (i
= 0; i
< gupc_newargc
; i
++)
290 fprintf (stderr
, " %s",
291 gupc_new_decoded_options
[i
].orig_option_with_args_text
);
292 fprintf (stderr
, "\n");
295 *in_decoded_options_count
= gupc_newargc
;
296 *in_decoded_options
= gupc_new_decoded_options
;
299 /* Called before linking. Returns 0 on success and -1 on failure. */
301 lang_specific_pre_link (void)
306 /* Number of extra output files that lang_specific_pre_link may generate. */
307 int lang_specific_extra_outfiles
= 0; /* Not used for GUPC. */