1 /* This file is part of GCC.
3 GCC is free software; you can redistribute it and/or modify it under
4 the terms of the GNU General Public License as published by the Free
5 Software Foundation; either version 3, or (at your option) any later
8 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
9 WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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"
24 #include "tree-iterator.h"
25 #include "tree-pass.h"
32 #include "diagnostic-core.h"
33 #include "langhooks.h"
34 #include "langhooks-def.h"
45 #include "py-dot-codes.def"
50 #include "py-runtime.h"
52 static VEC(gpydot
,gc
) * gpy_decls
;
54 static gpy_symbol_obj
* gpy_stmt_process_AST_Align (gpy_dot_tree_t
**);
56 void gpy_stmt_process_decl (gpy_dot_tree_t
* const dot
)
58 /* Push the declaration! */
59 VEC_safe_push (gpydot
, gc
, gpy_decls
, dot
);
60 debug ("decl <%p> was pushed!\n", (void*)dot
);
64 * Fairly Confusing Function to read.
67 * >>> x = y = z = 2 + 2 + 2;
69 * --- Currently Yacc parses that expression into this Tree, which is just
70 side effect of the way we generate the gpy_dot_tree's the much higher level IR
71 which we bring down to GENERIC:
85 -- Is converted into the procedure:
91 -- Tree structure as so:
106 gpy_dot_tree_t
* gpy_stmt_process_AST_Align (gpy_dot_tree_t
** dot
)
108 gpy_dot_tree_t
*retval
= NULL_DOT
;
109 gpy_dot_tree_t
*nn
= NULL_DOT
;
110 if (DECL_CHAIN(*dot
))
112 nn
= DECL_CHAIN(*dot
);
113 DECL_CHAIN(*dot
) = NULL_DOT
;
117 if (DOT_TYPE(retval
) != D_MODIFY_EXPR
)
119 gpy_dot_tree_t
*o
= retval
;
120 gpy_dot_tree_t
*h
= NULL_DOT
;
122 while (o
!= NULL_DOT
)
124 if ((DOT_TYPE(o
) != D_IDENTIFIER
) ||
125 (DOT_TYPE(o
) != D_PRIMITIVE
))
127 if (DOT_lhs_T(o
) == D_TD_DOT
)
129 if (DOT_TYPE(DOT_lhs_TT(o
)) == D_MODIFY_EXPR
)
145 gpy_dot_tree_t
*head
= DOT_lhs_TT(h
);
146 if (DOT_TYPE(DOT_rhs_TT(head
)) == D_MODIFY_EXPR
)
148 gpy_dot_tree_t
*t
= head
, *m
= NULL_DOT
;
151 if ((DOT_TYPE(t
) != D_IDENTIFIER
) ||
152 (DOT_TYPE(t
) != D_PRIMITIVE
))
154 if (DOT_TYPE(DOT_rhs_TT(t
)) != D_MODIFY_EXPR
)
169 DOT_lhs_TT(h
) = DOT_rhs_TT(m
);
170 DOT_rhs_TT(m
) = retval
;
173 fatal_error ("error processing the expression AST!\n");
177 DOT_lhs_TT(h
) = DOT_rhs_TT(head
);
178 DOT_rhs_TT(head
) = retval
;
185 DOT_CHAIN(retval
) = nn
;
191 VEC(tree
,gc
) * gpy_stmt_pass_generate_types (VEC(gpydot
,gc
) * decls
)
193 VEC(tree
,gc
) * retval
= VEC_alloc(tree
,gc
,0);
201 * Things are quite complicated from here on and will change frequently
202 * We need to do a 1st pass over the code to generate our module.
212 we need to generate out RECORD_TYPE with FIELDS x,y then pass again to generate
213 the rest of the code as our first pass will let us generate our TYPE so we know
214 how to access each variable in each context on the 2nd pass.
217 gpy_object_t *x , *y;
220 gpy_object_t * main.foo (struct main.main * self, gpy_object_t ** __args)
222 T.1 = gpy_rr_bin_op (OP_ADDITION, self->x, self->y);
226 void main.init (struct main.main *self)
228 self->x = fold_int (1);
229 self->y = fold_int (2);
231 T.2 = fold_call (&main.foo, 1, self)
232 gpy_rr_print_stmt (1, T.2)
235 int main (int argc, char *argv[])
251 void gpy_stmt_write_globals (void)
253 VEC(tree
,gc
) * module_types
= gpy_stmt_pass_generate_types (gpy_decls
);
254 VEC(tree
,gc
) * dot2gen_trees
= gpy_stmt_lower (module_types
, gpy_decls
);
256 VEC(tree
,gc
) * globals
= dot2gen_trees
;
258 while (gpy_stmt_pass_mngr
[idx
] != NULL
)
260 DOT_stmt_pass x
= gpy_stmt_pass_mngr
[idx
];
261 globals
= x(module_types
, globals
);
265 int global_vec_len
= VEC_length (tree
, globals
);
266 tree
* global_vec
= XNEWVEC (tree
, global_vec_len
);
267 tree itx
= NULL_TREE
;
270 FILE *tu_stream
= dump_begin (TDI_tu
, NULL
);
271 for (idx
=0; VEC_iterate (tree
,globals
,idx
,itx
); ++idx
)
276 dump_node (itx
, 0, tu_stream
);
278 global_vec
[idy
] = itx
;
282 dump_end(TDI_tu
, tu_stream
);
284 debug("Finished processing!\n\n");
286 debug("global_vec len = <%i>!\n", global_vec_len
);
288 wrapup_global_declarations (global_vec
, global_vec_len
);
290 check_global_declarations (global_vec
, global_vec_len
);
291 emit_debug_global_declarations (global_vec
, global_vec_len
);
293 cgraph_finalize_compilation_unit ();
295 debug("finished passing to middle-end!\n\n");
298 typedef VEC(tree
,gc
) * (*DOT_stmt_pass__
)(VEC(tree
,gc
) *, VEC(tree
,gc
) *);
299 static DOT_stmt_pass gpy_stmt_pass_mngr
[] = { NULL
};