fixed many errors and cleaned up includes
[official-gcc.git] / gcc / python / py-lang.c
blob60aa8f6acd5f479ae78b5a1fdfedf8bc48fcb4a4
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)
6 any later version.
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/>. */
17 #include "config.h"
18 #include "system.h"
19 #include "ansidecl.h"
20 #include "coretypes.h"
21 #include "opts.h"
22 #include "tree.h"
23 #include "gimple.h"
24 #include "toplev.h"
25 #include "debug.h"
26 #include "options.h"
27 #include "flags.h"
28 #include "convert.h"
29 #include "diagnostic-core.h"
30 #include "langhooks.h"
31 #include "langhooks-def.h"
32 #include "target.h"
34 #include <gmp.h>
35 #include <mpfr.h>
37 #include "vec.h"
38 #include "hashtab.h"
40 #include "gpython.h"
41 #include "py-dot-codes.def"
42 #include "py-dot.h"
43 #include "py-vec.h"
44 #include "py-tree.h"
45 #include "py-runtime.h"
47 /* Language-dependent contents of a type. */
48 struct GTY(()) lang_type {
49 char dummy;
50 } ;
52 /* Language-dependent contents of a decl. */
53 struct GTY(()) lang_decl {
54 char dummy;
55 } ;
57 /* Language-dependent contents of an identifier. This must include a
58 tree_identifier.
60 struct GTY(()) lang_identifier {
61 struct tree_identifier common;
62 } ;
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)")))
67 lang_tree_node
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 {
76 int dummy;
79 /* Language hooks. */
80 static
81 bool gpy_langhook_init( void )
83 gpy_init_tbls( );
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 );
90 return true;
93 /* Initialize before parsing options. */
94 static void
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. */
105 static bool
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;
110 int retval = 1;
112 debug("inside handle option!\n");
114 switch( code )
116 default:
117 /* Just return 1 to indicate that the option is valid. */
118 break;
121 return retval;
124 /* Run after parsing options. */
125 static bool
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. */
137 return false;
140 static void
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);
150 gpy_lex_parse( t );
154 static tree
155 gpy_langhook_type_for_size( unsigned int bits ATTRIBUTE_UNUSED,
156 int unsignedp ATTRIBUTE_UNUSED )
158 debug("type for size!\n");
159 return NULL;
162 static tree
163 gpy_langhook_type_for_mode( enum machine_mode mode ATTRIBUTE_UNUSED,
164 int unsignedp ATTRIBUTE_UNUSED )
166 debug("type for mode!\n");
167 return NULL_TREE;
170 /* Record a builtin function. We just ignore builtin functions. */
171 static tree
172 gpy_langhook_builtin_function( tree decl ATTRIBUTE_UNUSED )
174 debug("builtin function!\n");
176 return decl;
179 static int
180 gpy_langhook_global_bindings_p( void )
182 debug("global bindings!\n");
183 return 1;
186 static tree
187 gpy_langhook_pushdecl( tree decl ATTRIBUTE_UNUSED )
189 debug("pushdecl!\n");
190 gcc_unreachable ();
191 return NULL;
194 static tree
195 gpy_langhook_getdecls( void )
197 debug("get decls!\n");
198 return NULL;
201 /* Write out globals. */
202 static void
203 gpy_langhook_write_globals( void )
205 debug("write globals!\n");
206 gpy_write_globals( );
209 static int
210 gpy_langhook_gimplify_expr( tree *expr_p ATTRIBUTE_UNUSED,
211 gimple_seq *pre_p ATTRIBUTE_UNUSED,
212 gimple_seq *post_p ATTRIBUTE_UNUSED )
214 return GS_UNHANDLED;
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");
222 gcc_unreachable( );
223 return NULL;
226 static GTY(()) tree gpy_gc_root;
228 void
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, ... )
238 va_list args;
239 fprintf( stderr, "debug: <%s:%i> -> ",
240 file, lineno );
241 va_start( args, fmt );
242 vfprintf( stderr, fmt, args );
243 va_end( 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
256 * <gcc>/langhooks.h
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"