# include "config.h"
#endif
+#include <assert.h>
+
/**
Erweiterter Aufrufgraph.
*/
#include "irvrfy.h"
#include "trvrfy.h"
#include "xmalloc.h"
+#include "irdump.h"
+#include "irprog_t.h"
# ifndef TRUE
# define TRUE 1
# include "typalise.h"
# include "lset.h"
+# include "gnu_ext.h"
+
# define HERE(msg) fprintf (stdout, "%s:%i %s\n", __FUNCTION__, __LINE__, msg)
/*
static int _max_depth = 0;
static int _max_callEds = 0;
-static entity* _max_callEds_callR = NULL;
+static ir_entity* _max_callEds_callR = NULL;
/* Protos */
void set_main_ctx (ctx_info_t*);
/* ====================
Alloc stuff
==================== */
-static void append_alloc (graph_info_t *ginfo, ir_node *alloc, type *tp)
+static void append_alloc (graph_info_t *ginfo, ir_node *alloc, ir_type *tp)
{
- alloc_info_t *ainfo = xmalloc(sizeof(*ainfo));
+ alloc_info_t *ainfo = xmalloc (sizeof (alloc_info_t));
ainfo->graph = ginfo->graph;
ainfo->alloc = alloc;
/* ====================
CallEd stuff
==================== */
+/**
+ Create a new call info struct from the given values.
+*/
+static call_info_t *new_call_info (ir_node *call,
+ callEd_info_t *callEds,
+ call_info_t *prev)
+{
+ call_info_t *cinfo = xmalloc (sizeof (call_info_t));
+ cinfo->call = call;
+ cinfo->callEds = callEds;
+ cinfo->prev = prev;
+
+ return (cinfo);
+}
+
/**
Append the given callEd to the given callEd info.
*/
static callEd_info_t *append_callEd_info (callEd_info_t *ced, ir_graph *callEd)
{
- callEd_info_t *nced = xmalloc(sizeof(*nced));
+ callEd_info_t *nced = xmalloc (sizeof (callEd_info_t));
+
+ assert (NULL != callEd);
nced->callEd = callEd;
nced->prev = ced;
*/
static void append_calls (graph_info_t *info, ir_node *call, lset_t *callEds)
{
- call_info_t *cinfo = xmalloc(sizeof(*cinfo));
- ir_graph *callEd;
+ ir_graph *callEd = NULL;
+ call_info_t *cinfo = new_call_info (call, NULL, info->calls);
- /* setup */
- cinfo->call = call;
- cinfo->prev = info->calls;
info->calls = cinfo;
- cinfo->callEds = NULL;
/* enter */
- for (callEd = lset_first (callEds); callEd; callEd = lset_next(callEds))
+ callEd = lset_first (callEds);
+
+ while (NULL != callEd) {
cinfo->callEds = append_callEd_info (cinfo->callEds, callEd);
+ callEd = lset_next(callEds);
+ }
+
}
/**
*/
static void append_call (graph_info_t *info, ir_node *call, ir_graph *callEd)
{
- call_info_t *cinfo = xmalloc (sizeof(*cinfo));
+ call_info_t *cinfo = new_call_info (call, NULL, info->calls);
- cinfo->call = call;
- cinfo->prev = info->calls;
info->calls = cinfo;
cinfo->callEds = append_callEd_info (cinfo->callEds, callEd);
Given a method, find the firm graph that implements that method.
Return NULL for abstract and native methods.
*/
-static ir_graph *_get_implementing_graph (entity *method)
+static ir_graph *_get_implementing_graph (ir_entity *method)
{
ir_graph *graph = NULL;
assert (!graph);
for (i = 0; (NULL == graph) && (i < n_over); i ++) {
- entity *over = get_entity_overwrites (method, i);
+ ir_entity *over = get_entity_overwrites (method, i);
graph = _get_implementing_graph (over);
}
/**
Collect all graphs of 'method' in the given set.
*/
-static void _collect_implementing_graphs (entity *method, lset_t *set)
+static void _collect_implementing_graphs (ir_entity *method, lset_t *set)
{
/* search DOWN-wards in clazz hierarchy */
int i;
}
for (i = 0; i < n_over; i ++) {
- entity *over = get_entity_overwrittenby (method, i);
+ ir_entity *over = get_entity_overwrittenby (method, i);
_collect_implementing_graphs (over, set);
}
/**
Collect all graphs that could possibly be executed when 'method' is called.
*/
-static lset_t *get_implementing_graphs (entity *method, ir_node *select)
+static lset_t *get_implementing_graphs (ir_entity *method, ir_node *select)
{
+ /* const char *name = get_entity_name (method); */
+ /* fprintf (stdout, "%s (ent %s)\n", __FUNCTION__, name); */
+
int n_graphs;
lset_t *set = lset_create ();
{
/* void *tmp = lset_first (set); */
n_graphs = lset_n_entries (set);
+
+ if (visibility_external_allocated != get_entity_visibility (method)) {
+ if (0 == n_graphs) {
+ ir_graph *graph = get_irn_irg (select);
+
+ dump_ir_block_graph (graph, "-typealise");
+
+ /* fprintf (stdout, "no graphs for method %s\n", get_entity_name (method)); */
+ assert (n_graphs && "no graphs for method");
+ }
+ }
/* typalise select_in */
if (do_typalise) {
ir_node *select_in = get_Sel_ptr (select);
typalise_t *ta = typalise (select_in);
- assert (ta && "typalise failed (go figure)");
-
- /* const char *res = ta_name (ta); */
+ /* assert (ta && "typalise failed (go figure)"); */
- /* fprintf (stdout, "typalyse res = %s\n", res); */
+ /*
+ fprintf (stdout, "typalyse res = ");
+
+ if (NULL != ta) {
+ if (type_invalid == ta->kind) {
+ fprintf (stdout, "invalid");
+ } else if (type_exact == ta->kind) {
+ const char *name = get_type_name (ta->res.type);
+
+ fprintf (stdout, "exact [");
+ fprintf (stdout, "%s", name);
+ fprintf (stdout, "]\n");
+ } else if (type_types == ta->kind) {
+ fprintf (stdout, "types [");
+ fprintf (stdout, "...");
+ fprintf (stdout, "]\n");
+ } else if (type_type == ta->kind) {
+ const char *name = get_type_name (ta->res.type);
+ fprintf (stdout, "type [");
+ fprintf (stdout, "%s", name);
+ fprintf (stdout, "]\n");
+ }
+ } else {
+ fprintf (stdout, "(null)\n");
+ }
+ */
if (1 != n_graphs) {
int n_filtered_graphs;
*/
n_graphs = n_filtered_graphs;
}
+
+ if (visibility_external_allocated != get_entity_visibility (method)) {
+ if (0 == n_graphs) {
+ ir_graph *graph = get_irn_irg (select);
+
+ dump_ir_block_graph (graph, "-ecg");
+ /* fprintf (stdout, "no graphs for method %s\n", get_entity_name (method)); */
+ assert (n_graphs && "no graphs for method");
+ }
+ }
+
}
if (n_graphs > _max_callEds) {
}
- if (visibility_external_allocated != get_entity_visibility (method)) {
- if (0 == n_graphs) {
- /* fprintf (stdout, "no graphs for method %s\n", get_entity_name (method)); */
- assert (n_graphs && "no graphs for method");
- }
+ return (set);
+}
+
+/**
+ Determine whether a call is actually a call or if it is being
+ abused for some b/d-ed reason.
+*/
+static int call_is_call (ir_node *call, ir_node *ptr)
+{
+ if (op_SymConst != get_irn_op (ptr)) {
+ return (TRUE);
+ } else if (get_SymConst_kind (ptr) != symconst_addr_name) {
+ return (TRUE);
}
- return (set);
+ return (FALSE);
}
/**
graph_info_t *graph_info = (graph_info_t*) env;
if (op_Call == op) { /* CALL */
- entity *ent = NULL;
+ ir_entity *ent = NULL;
ir_node *ptr = get_Call_ptr (node);
+ if (!call_is_call (node, ptr)) {
+ /*
+ fprintf (stdout, "not a call: %s[%li]\n",
+ get_op_name (get_irn_op (node)),
+ get_irn_node_nr (node)); */
+ return;
+ }
+
/* CALL SEL */
- if (op_Sel == get_irn_op(ptr)) {
+ if (op_Sel == get_irn_op (ptr)) {
lset_t *graphs;
ent = get_Sel_entity (ptr);
graphs = get_implementing_graphs (ent, ptr);
append_calls (graph_info, node, graphs);
- } else if (op_SymConst == get_irn_op(ptr)) {
+ } else if (op_SymConst == get_irn_op (ptr)) {
if (get_SymConst_kind (ptr) == symconst_addr_ent) {
ir_graph *graph;
ent = get_SymConst_entity (ptr);
assert (0 && "Unexpected address expression");
}
} else if (op_Alloc == op) {
- type *tp = get_Alloc_type (node);
+ ir_type *tp = get_Alloc_type (node);
/* const char *name = get_type_name (tp); */
append_alloc (graph_info, node, tp);
*/
static void ecg_fill_graph_calls (ir_graph *graph)
{
- graph_info_t *ginfo = xmalloc(sizeof(*ginfo));
+ graph_info_t *ginfo = xmalloc (sizeof (graph_info_t));
/* memset (ginfo, 0x00, sizeof (graph_info_t)); */
assert (ginfo != graph_infos_list);
- ginfo->graph = graph;
- ginfo->calls = NULL;
- ginfo->ecg_seen = 0;
- ginfo->ctxs = NULL;
- ginfo->n_ctxs = 0;
- ginfo->prev = NULL;
+ ginfo->graph = graph;
+ ginfo->calls = NULL;
+ ginfo->allocs = NULL;
+ ginfo->ctxs = NULL;
+ ginfo->n_ctxs = 0;
+ ginfo->ecg_seen = 0;
+ ginfo->allocs_seen = 0;
+ ginfo->prev = NULL;
/* link up into global list */
ginfo->prev = graph_infos_list;
*/
static ctx_info_t *new_ctx (ir_graph *graph, ir_node *call, ctx_info_t *enc)
{
- ctx_info_t *res = xmalloc(sizeof(*res));
+ ctx_info_t *res = xmalloc (sizeof (ctx_info_t));
res->graph = graph;
res->call = call;
graph_info_t *ginfo = graph_infos_list;
while (NULL != ginfo) {
- ginfo->ctxs = xmalloc(ginfo->n_ctxs * sizeof(*ginfo->ctxs));
+ ginfo->ctxs = xcalloc (ginfo->n_ctxs, sizeof (ctx_info_t *));
/*
fprintf (stdout, "graph of \"%s\": n_ctxs = %i\n",
callEd_info->ctxs [callEd_info->n_ctxs] = ctx;
callEd_info->n_ctxs ++;
- /* Calling graph -> callEd_graph */
+ /* CallR graph -> callEd_graph */
ecg_fill_ctxs_write (callEd_graph, ctx);
ced = ced->prev;
/* Grrr, have to add this ctx manually to main.ginfo ... */
ginfo = ecg_get_info (main_irg);
ginfo->n_ctxs = 1;
- ginfo->ctxs = xmalloc(1 * sizeof(*ginfo->ctxs));
+ ginfo->ctxs = xcalloc (1, sizeof (ctx_info_t *));
ginfo->ctxs [0] = main_ctx;
ecg_fill_ctxs_write (main_irg, main_ctx);
*/
void ecg_print_ctx (ctx_info_t *ctx, FILE *stream)
{
- entity *ent = get_irg_entity(ctx->graph);
+ ir_entity *ent = get_irg_entity(ctx->graph);
ir_node *call = ctx->call;
const char *ent_name = get_entity_name (ent);
const char *own_name = get_type_name (get_entity_owner (ent));
{
do_typalise = typalise;
+ if (typalise) {
+ typalise_init ();
+ }
+
graph_infos = pmap_create ();
ecg_fill_calls ();
const int n_ctxs = (ginfo->n_ctxs > max_ctxs) ? max_ctxs : ginfo->n_ctxs;
fprintf (dot, "\t/* now the ctxs */\n");
- fprintf (dot, "\tctx_0x%08x [label=\"<HEAD>", (void*) graph);
+ fprintf (dot, "\tctx_0x%08x [label=\"<HEAD>", (int) graph);
assert (ginfo->ctxs && "no ctx");
for (i = 0; i < n_ctxs; i ++) {
fprintf (dot,
"\tgraph_0x%08x -> ctx_0x%08x:HEAD [label=\"ctx\", dir=\"none\", style=\"dotted\"];\n",
- (void*) graph, (void*) graph);
+ (int) graph, (int) graph);
}
} else {
fprintf (dot, "\t/* graph is not called */\n");
/*
$Log$
+ Revision 1.23 2006/12/13 19:46:47 beck
+ rename type entity into ir_entity
+
+ Revision 1.22 2006/01/13 22:55:03 beck
+ renamed all types 'type' to 'ir_type'
+
+ Revision 1.21 2005/12/31 15:58:57 beck
+ added missing includes
+
+ Revision 1.20 2005/12/05 12:01:06 beck
+ needed include added
+
+ Revision 1.19 2005/03/22 13:55:51 liekweg
+ Need to initialise typalise now
+
+ Revision 1.18 2005/01/14 14:14:43 liekweg
+ fix gnu extension
+
+ Revision 1.17 2005/01/14 13:34:25 liekweg
+ Factor out call_info_t ctor; fix mallocs; fix initialisation
+
+ Revision 1.16 2005/01/10 17:26:34 liekweg
+ fixup printfs, don't put environments on the stack
+
+ Revision 1.15 2004/12/23 15:40:03 beck
+ used new xcalloc
+
Revision 1.14 2004/12/22 14:43:14 beck
made allocations C-like