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"
49 static VEC(gpydot
,gc
) * gpy_decls
;
51 typedef VEC(gpydot
,gc
) * (*DOT_stmt_pass__
)(VEC(gpydot
,gc
) *);
52 static DOT_stmt_pass__ gpy_stmt_pass_mngr
[] =
57 /* Pushes each decl from the parser onto the current translation unit */
58 void gpy_stmt_process_decl (gpy_dot_tree_t
* const dot
)
60 /* Push the declaration! */
61 VEC_safe_push (gpydot
, gc
, gpy_decls
, dot
);
62 debug ("decl <%p> was pushed!\n", (void*)dot
);
66 * Fairly Confusing Function to read.
69 * >>> x = y = z = 2 + 2 + 2;
71 * --- Currently Yacc parses that expression into this Tree, which is just
72 side effect of the way we generate the gpy_dot_tree's the much higher level IR
73 which we bring down to GENERIC:
87 -- Is converted into the procedure:
93 -- Tree structure as so:
107 gpy_dot_tree_t
* gpy_stmt_process_AST_Align (gpy_dot_tree_t
** d_dot
)
109 gpy_dot_tree_t
* retval
= NULL_DOT
;
110 gpy_dot_tree_t
* nn
= NULL_DOT
;
111 gpy_dot_tree_t
* dot
= *d_dot
;
116 DOT_CHAIN(dot
) = NULL_DOT
;
120 if (DOT_TYPE(retval
) != D_MODIFY_EXPR
)
122 gpy_dot_tree_t
*o
= retval
;
123 gpy_dot_tree_t
*h
= NULL_DOT
;
125 while (o
!= NULL_DOT
)
127 if ((DOT_TYPE(o
) != D_IDENTIFIER
) ||
128 (DOT_TYPE(o
) != D_PRIMITIVE
))
130 if (DOT_lhs_T(o
) == D_TD_DOT
)
132 if (DOT_TYPE(DOT_lhs_TT(o
)) == D_MODIFY_EXPR
)
148 gpy_dot_tree_t
*head
= DOT_lhs_TT(h
);
149 if (DOT_TYPE(DOT_rhs_TT(head
)) == D_MODIFY_EXPR
)
151 gpy_dot_tree_t
*t
= head
, *m
= NULL_DOT
;
154 if ((DOT_TYPE(t
) != D_IDENTIFIER
) ||
155 (DOT_TYPE(t
) != D_PRIMITIVE
))
157 if (DOT_TYPE(DOT_rhs_TT(t
)) != D_MODIFY_EXPR
)
172 DOT_lhs_TT(h
) = DOT_rhs_TT(m
);
173 DOT_rhs_TT(m
) = retval
;
176 fatal_error ("error processing the expression AST!\n");
180 DOT_lhs_TT(h
) = DOT_rhs_TT(head
);
181 DOT_rhs_TT(head
) = retval
;
188 DOT_CHAIN(retval
) = nn
;
195 * Things are quite complicated from here on and will change frequently
196 * We need to do a 1st pass over the code to generate our module.
206 we need to generate out RECORD_TYPE with FIELDS x,y then pass again to generate
207 the rest of the code as our first pass will let us generate our TYPE so we know
208 how to access each variable in each context on the 2nd pass.
211 gpy_object_t *x , *y;
214 gpy_object_t * main.foo (struct main.main * self, gpy_object_t ** __args)
216 T.1 = gpy_rr_bin_op (OP_ADDITION, self->x, self->y);
220 void main.init (struct main.main *self)
222 self->x = fold_int (1);
223 self->y = fold_int (2);
225 T.2 = fold_call (&main.foo, 1, self)
226 gpy_rr_print_stmt (1, T.2)
229 int main (int argc, char *argv[])
245 void gpy_stmt_write_globals (void)
248 VEC(gpydot
,gc
) * dot_decls
= gpy_decls
;
249 while (gpy_stmt_pass_mngr
[idx
] != NULL
)
251 DOT_stmt_pass__ x
= gpy_stmt_pass_mngr
[idx
];
252 dot_decls
= x(dot_decls
);
256 VEC(tree
,gc
) * module_types
= gpy_stmt_pass_generate_types (dot_decls
);
257 VEC(tree
,gc
) * dot2gen_trees
= gpy_stmt_pass_lower (module_types
, gpy_decls
);
258 VEC(tree
,gc
) * globals
= dot2gen_trees
;
260 int global_vec_len
= VEC_length (tree
, globals
);
261 tree
* global_vec
= XNEWVEC (tree
, global_vec_len
);
262 tree itx
= NULL_TREE
;
265 FILE *tu_stream
= dump_begin (TDI_tu
, NULL
);
266 for (idx
=0; VEC_iterate (tree
,globals
,idx
,itx
); ++idx
)
271 dump_node (itx
, 0, tu_stream
);
273 global_vec
[idy
] = itx
;
277 dump_end(TDI_tu
, tu_stream
);
279 debug("Finished processing!\n\n");
281 debug("global_vec len = <%i>!\n", global_vec_len
);
283 wrapup_global_declarations (global_vec
, global_vec_len
);
285 check_global_declarations (global_vec
, global_vec_len
);
286 emit_debug_global_declarations (global_vec
, global_vec_len
);
288 cgraph_finalize_compilation_unit ();
290 debug("finished passing to middle-end!\n\n");