1 /* This file is part of GCC.
3 GCC is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 3, or (at your option)
8 GCC is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with GCC; see the file COPYING3. If not see
15 <http://www.gnu.org/licenses/>. */
20 #include "coretypes.h"
29 #include "diagnostic-core.h"
30 #include "langhooks.h"
31 #include "langhooks-def.h"
41 #include "py-dot-codes.def"
45 #include "py-runtime.h"
47 /* Language-dependent contents of a type. */
48 struct GTY(()) lang_type
{
52 /* Language-dependent contents of a decl. */
53 struct GTY(()) lang_decl
{
57 /* Language-dependent contents of an identifier. This must include a
60 struct GTY(()) lang_identifier
{
61 struct tree_identifier common
;
64 /* The resulting tree type. */
65 union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
66 chain_next ("(union lang_tree_node *) TREE_CHAIN (&%h.generic)")))
69 union tree_node
GTY((tag ("0"),
70 desc ("tree_node_structure (&%h)"))) generic
;
71 struct lang_identifier
GTY((tag ("1"))) identifier
;
74 /* We don't use language_function. */
75 struct GTY(()) language_function
{
81 bool gpy_langhook_init( void )
85 build_common_tree_nodes( false );
86 build_common_tree_nodes_2( 0 );
88 void_list_node
= build_tree_list( NULL_TREE
, void_type_node
);
93 /* Initialize before parsing options. */
95 gpy_langhook_init_options( unsigned int decoded_options_count
,
96 struct cl_decoded_option
*decoded_options
)
98 flag_strict_aliasing
= 1;
99 debug("init options!\n");
101 mpfr_set_default_prec( 128 );
104 /* Handle gpy specific options. Return 0 if we didn't do anything. */
106 gpy_langhook_handle_option( size_t scode
, const char *arg
, int value
, int kind
,
107 const struct cl_option_handlers
*handlers
)
109 enum opt_code code
= (enum opt_code
) scode
;
112 debug("inside handle option!\n");
117 /* Just return 1 to indicate that the option is valid. */
124 /* Run after parsing options. */
126 gpy_langhook_post_options( const char **pfilename ATTRIBUTE_UNUSED
)
128 debug("post options!\n");
129 gcc_assert( num_in_fnames
> 0 );
131 if( flag_excess_precision_cmdline
== EXCESS_PRECISION_DEFAULT
)
133 flag_excess_precision_cmdline
= EXCESS_PRECISION_STANDARD
;
136 /* Returning false means that the backend should be used. */
141 gpy_langhook_parse_file( int set_yy_debug ATTRIBUTE_UNUSED
)
143 unsigned int idx
= 0;
144 debug("parse file!\n");
146 for( ; idx
<num_in_fnames
; ++idx
)
148 const char * t
= in_fnames
[idx
];
149 debug("<%i> input = <%s>!\n", idx
, t
);
155 gpy_langhook_type_for_size( unsigned int bits ATTRIBUTE_UNUSED
,
156 int unsignedp ATTRIBUTE_UNUSED
)
158 debug("type for size!\n");
163 gpy_langhook_type_for_mode( enum machine_mode mode ATTRIBUTE_UNUSED
,
164 int unsignedp ATTRIBUTE_UNUSED
)
166 debug("type for mode!\n");
170 /* Record a builtin function. We just ignore builtin functions. */
172 gpy_langhook_builtin_function( tree decl ATTRIBUTE_UNUSED
)
174 debug("builtin function!\n");
180 gpy_langhook_global_bindings_p( void )
182 debug("global bindings!\n");
187 gpy_langhook_pushdecl( tree decl ATTRIBUTE_UNUSED
)
189 debug("pushdecl!\n");
195 gpy_langhook_getdecls( void )
197 debug("get decls!\n");
201 /* Write out globals. */
203 gpy_langhook_write_globals( void )
205 debug("write globals!\n");
206 gpy_write_globals( );
210 gpy_langhook_gimplify_expr( tree
*expr_p ATTRIBUTE_UNUSED
,
211 gimple_seq
*pre_p ATTRIBUTE_UNUSED
,
212 gimple_seq
*post_p ATTRIBUTE_UNUSED
)
217 /* Functions called directly by the generic backend. */
218 tree
convert( tree type ATTRIBUTE_UNUSED
,
219 tree expr ATTRIBUTE_UNUSED
)
221 debug("tree convert!\n");
226 static GTY(()) tree gpy_gc_root
;
229 gpy_preserve_from_gc( tree t ATTRIBUTE_UNUSED
)
231 gpy_gc_root
= tree_cons( NULL_TREE
, t
, gpy_gc_root
);
232 debug("preserve from gc!\n");
235 void __gpy_debug__( const char * file
, unsigned int lineno
,
236 const char * fmt
, ... )
239 fprintf( stderr
, "debug: <%s:%i> -> ",
241 va_start( args
, fmt
);
242 vfprintf( stderr
, fmt
, args
);
246 /* The attribute table might be used for the GCC attribute syntax, e.g.
247 * __attribute__((unused)), but this feature isn't yet used in gcalc
249 const struct attribute_spec python_attribute_table
[] = {
250 { NULL
, 0, 0, false, false, false, NULL
}
254 /* The language hooks data structure. This is the main interface between the GCC front-end
255 * and the GCC middle-end/back-end. A list of language hooks could be found in
258 #undef LANG_HOOKS_NAME
259 #undef LANG_HOOKS_INIT
260 #undef LANG_HOOKS_INIT_OPTIONS
261 #undef LANG_HOOKS_HANDLE_OPTION
262 #undef LANG_HOOKS_POST_OPTIONS
263 #undef LANG_HOOKS_PARSE_FILE
264 #undef LANG_HOOKS_TYPE_FOR_MODE
265 #undef LANG_HOOKS_TYPE_FOR_SIZE
266 #undef LANG_HOOKS_BUILTIN_FUNCTION
267 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
268 #undef LANG_HOOKS_PUSHDECL
269 #undef LANG_HOOKS_GETDECLS
270 #undef LANG_HOOKS_WRITE_GLOBALS
271 #undef LANG_HOOKS_GIMPLIFY_EXPR
273 #define LANG_HOOKS_NAME "GNU Python"
274 #define LANG_HOOKS_INIT gpy_langhook_init
275 #define LANG_HOOKS_INIT_OPTIONS gpy_langhook_init_options
276 #define LANG_HOOKS_HANDLE_OPTION gpy_langhook_handle_option
277 #define LANG_HOOKS_POST_OPTIONS gpy_langhook_post_options
278 #define LANG_HOOKS_PARSE_FILE gpy_langhook_parse_file
279 #define LANG_HOOKS_TYPE_FOR_MODE gpy_langhook_type_for_mode
280 #define LANG_HOOKS_TYPE_FOR_SIZE gpy_langhook_type_for_size
281 #define LANG_HOOKS_BUILTIN_FUNCTION gpy_langhook_builtin_function
282 #define LANG_HOOKS_GLOBAL_BINDINGS_P gpy_langhook_global_bindings_p
283 #define LANG_HOOKS_PUSHDECL gpy_langhook_pushdecl
284 #define LANG_HOOKS_GETDECLS gpy_langhook_getdecls
285 #define LANG_HOOKS_WRITE_GLOBALS gpy_langhook_write_globals
286 #define LANG_HOOKS_GIMPLIFY_EXPR gpy_langhook_gimplify_expr
288 struct lang_hooks lang_hooks
= LANG_HOOKS_INITIALIZER
;
290 #include "gt-python-py-lang.h"
291 #include "gtype-python.h"