gcc/
[official-gcc.git] / gcc / upc / upc-lang.c
blobb18828b8e65a046a7760e775d92d351f3230fc87
1 /* upc-lang.c: UPC language-specific hooks
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck <gary@intrepid.com>
5 and Nenad Vukicevic <nenad@intrepid.com>.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
12 any later version.
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "tree.h"
28 #include "c-tree.h"
29 #include "c-family/c-common.h"
30 #include "ggc.h"
31 #include "upc-act.h"
32 #include "upc-pts.h"
33 #include "upc-genericize.h"
34 #include "upc-gasp.h"
35 #include "upc-pts.h"
36 #include "langhooks.h"
37 #include "langhooks-def.h"
38 #include "c-objc-common.h"
39 #include "toplev.h"
40 #include "diagnostic.h"
41 #include "c-family/c-pretty-print.h"
42 #include "c-family/c-pragma.h"
43 #include "c-family/c-upc.h"
44 #include "flags.h"
45 #include "opts.h"
46 #include "options.h"
48 /* Non-zero if the current compilation context is UPC */
49 int compiling_upc;
51 /* Non-zero if dwarf2 debugging information should
52 encode UPC specific information. */
53 int use_upc_dwarf2_extensions;
55 /* Nonzero whenever UPC functionality is being used. */
56 int flag_upc;
58 enum c_language_kind c_language = clk_upc;
60 static void upc_initialize_diagnostics (diagnostic_context *);
61 static void upc_init_options (unsigned int, struct cl_decoded_option *);
62 static bool upc_post_options (const char **);
63 static alias_set_type upc_get_alias_set (tree);
64 static void upc_init_ts (void);
66 /* UPC inherits hook definitions from "c-objc-common.h"
67 and adds to them. */
69 #undef LANG_HOOKS_NAME
70 #define LANG_HOOKS_NAME "GCC UPC"
71 #undef LANG_HOOKS_EXPAND_CONSTANT
72 #define LANG_HOOKS_EXPAND_CONSTANT upc_pts_build_constant
73 #undef LANG_HOOKS_GET_ALIAS_SET
74 #define LANG_HOOKS_GET_ALIAS_SET upc_get_alias_set
75 #undef LANG_HOOKS_GENERICIZE
76 #define LANG_HOOKS_GENERICIZE upc_genericize
77 #undef LANG_HOOKS_HANDLE_OPTION
78 #define LANG_HOOKS_HANDLE_OPTION upc_handle_option
79 #undef LANG_HOOKS_INIT
80 #define LANG_HOOKS_INIT upc_lang_init
81 #undef LANG_HOOKS_FINISH
82 #define LANG_HOOKS_FINISH upc_finish
83 #undef LANG_HOOKS_INITIALIZE_DIAGNOSTICS
84 #define LANG_HOOKS_INITIALIZE_DIAGNOSTICS upc_initialize_diagnostics
85 #undef LANG_HOOKS_INIT_OPTIONS
86 #define LANG_HOOKS_INIT_OPTIONS upc_init_options
87 #undef LANG_HOOKS_POST_OPTIONS
88 #define LANG_HOOKS_POST_OPTIONS upc_post_options
89 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
90 #define LANG_HOOKS_TYPES_COMPATIBLE_P upc_types_compatible_p
91 #undef LANG_HOOKS_INIT_TS
92 #define LANG_HOOKS_INIT_TS upc_init_ts
94 /* Each front end provides its own hooks, for toplev.c. */
95 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
97 static void
98 upc_initialize_diagnostics (diagnostic_context *context)
100 pretty_printer *base = context->printer;
101 c_pretty_printer *pp = (c_pretty_printer *)
102 xmalloc (sizeof (c_pretty_printer));
103 memcpy (pp_base (pp), base, sizeof (pretty_printer));
104 pp_c_pretty_printer_init (pp);
105 context->printer = (pretty_printer *) pp;
106 /* It is safe to free this object because it was previously malloc()'d. */
107 free (base);
110 /* Set the C 99 standard (without GNU extensions if ISO).
111 (borrowed from c-opts.c) */
113 static void
114 set_std_c99 (int iso)
116 cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
117 flag_no_asm = iso;
118 flag_no_nonansi_builtin = iso;
119 flag_iso = iso;
120 flag_isoc99 = 1;
121 flag_isoc94 = 1;
124 static void
125 upc_init_options (unsigned int decoded_options_count,
126 struct cl_decoded_option *decoded_options)
128 struct cl_option_handlers handlers;
130 c_common_init_options (decoded_options_count, decoded_options);
132 /* UPC is based upon the C99 dialect. Assert it here.
133 * We'll let the user override these options as he/she
134 * sees fit. For example, -traditional will disable
135 * prototype checking */
136 set_std_c99 ( 0 /* iso=0 */ );
138 /* The consensus of the UPC community seems to be that
139 arithmetic on (void *) pointers and sizeof (void)
140 are compilation errors. Enable this warning-as-error
141 mode by default. */
142 warn_pointer_arith = 1;
143 set_default_handlers (&handlers);
144 control_warning_option (OPT_Wpointer_arith, (int) DK_ERROR, true,
145 UNKNOWN_LOCATION, CL_C | CL_ObjC | CL_UPC,
146 &handlers, &global_options, &global_options_set,
147 global_dc);
149 #ifdef ENABLE_UPC_DWARF2_SUPPORT
150 /* Some targets support UPC's DWARF2 extensions by default. */
151 use_upc_dwarf2_extensions = 1;
152 #else
153 use_upc_dwarf2_extensions = 0;
154 #endif
156 flag_upc = 1;
157 flag_upc_threads = 0;
158 flag_upc_pthreads = 0;
159 /* We begin in the state where we assume that we're compiling UPC
160 The 'compiling_upc' flag is queried when compiling for a
161 pthreads environment to determine whether global static
162 variables should be allocated to thread local storage. */
163 compiling_upc = 1;
164 /* By default, don't map UPC threads to POSIX threads. */
165 flag_upc_pthreads = 0;
166 upc_pthreads_model = upc_pthreads_no_model;
167 flag_upc_pthreads_per_process = 0;
168 /* By default, GASP profiling is off. */
169 flag_upc_instrument = 0;
170 flag_upc_instrument_functions = 0;
171 /* By default, optimization level > 0 defines shared access routines
172 inlining, otherwise use the user specified flag for unconditional
173 enable/disable of inlining (0 - disable, 1 - enable) */
174 flag_upc_inline_lib = -1;
177 static bool upc_post_options (const char **pfilename)
179 return c_common_post_options (pfilename);
182 static alias_set_type
183 upc_get_alias_set (tree t)
186 /* For the time being, make UPC pointers-to-shared conflict
187 with everything else. Ideally, UPC pointers-to-shared should
188 only conflict with the internal type used to represent
189 the UPC pointer-to-shared (i.e., upc_pts_rep_type_node). */
191 if (TYPE_P (t) ? (TREE_CODE (t) == POINTER_TYPE
192 && upc_shared_type_p (TREE_TYPE (t)))
193 : (TREE_TYPE(t)
194 && TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE
195 && upc_shared_type_p (TREE_TYPE (TREE_TYPE (t)))))
196 return 0;
199 /* Otherwise, do the default thing. */
201 return c_common_get_alias_set (t);
204 static void
205 upc_init_ts (void)
207 c_common_init_ts ();
208 MARK_TS_COMMON (UPC_FORALL_STMT);
209 MARK_TS_COMMON (UPC_SYNC_STMT);
212 #include "gtype-upc.h"