topdir = ../..
subdir := ir/ana2
-INSTALL_HEADERS = ecg.h irmemwalk.h lset.h typalise.h pto.h \
- pto_init.h pto_util.h qset.h timing.h \
+INSTALL_HEADERS = ecg.h irmemwalk.h lset.h typalise.h pto.h pto_comp.h pto_debug.h \
+ pto_ctx.h pto_debug.h pto_init.h pto_name.h pto_util.h
SOURCES = $(INSTALL_HEADERS)
SOURCES += Makefile.in \
- ecg.c irmemwalk.c lset.c typalise.c pto.c \
- pto_init.c pto_util.c qset.c timing.c
+ ecg.c irmemwalk.c lset.c typalise.c \
+ pto_comp.c pto_ctx.c pto_debug.c pto_init.c pto_name.c pto_util.c
include $(topdir)/MakeRules
/* -*- c -*- */
/*
- * Project: libFIRM
- * File name: ir/ana2/pto.c
- * Purpose: Pto
- * Author: Florian
- * Modified by:
- * Created: Mon 18 Oct 2004
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2004 Universität Karlsruhe
- * Licence: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
+ Project: libFIRM
+ File name: ir/ana/pto.h
+ Purpose: Import all includes needed for PTO
+ Author: Florian
+ Modified by:
+ Created: Sat Nov 13 19:35:27 CET 2004
+ CVS-ID: $Id$
+ Copyright: (c) 1999-2004 Universität Karlsruhe
+ Licence: This file is protected by the GPL - GNU GENERAL PUBLIC LICENSE.
+*/
-# ifndef _PTO_H_
-# define _PTO_H_
-# include "pto_util.h"
+# ifndef _PTO_
+# define _PTO_
-void pto_init (void);
-void pto_run (int);
-void pto_cleanup (void);
+# include "pto_comp.h"
-# ifndef TRUE
-# define TRUE 1
-# define FALSE 0
-# endif /* not defined TRUE */
+/* ===================================================
+ Global Defines:
+ =================================================== */
-void set_pto (ir_node*, pto_t*);
-int get_pto_verbose (void);
-void set_pto_verbose (int);
+/* ===================================================
+ Global Data Types:
+ =================================================== */
+
+/* ===================================================
+ Global Prototypes:
+ =================================================== */
+
+/* ===================================================
+ Global Variables:
+ =================================================== */
+
+
+# endif /* not defined _PTO_ */
-# endif /* not defined _PTO_H_ */
\f
/*
- * $Log$
- * Revision 1.4 2004/11/04 14:58:38 liekweg
- * expanded pto, added initialisation, added debugging printing
- *
- * Revision 1.3 2004/10/25 11:59:45 liekweg
- * Copy Only works
- *
- * Revision 1.2 2004/10/21 11:09:37 liekweg
- * Moved memwalk stuf into irmemwalk
- * Moved lset stuff into lset
- * Moved typalise stuff into typalise
- *
- * Revision 1.1 2004/10/20 14:59:42 liekweg
- * Added ana2, added ecg and pto
- *
- */
+ $Log$
+ Revision 1.5 2004/11/18 16:37:07 liekweg
+ rewrite
+
+
+*/
/* -*- c -*- */
/*
- * Project: libFIRM
- * File name: ir/ana2/pto_init.c
- * Purpose: Pto Initialization
- * Author: Florian
- * Modified by:
- * Created: Wed 3 Nov 2004
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2004 Universität Karlsruhe
- * Licence: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
+ Project: libFIRM
+ File name: ir/ana/pto_init.c
+ Purpose: Initialisation Functions
+ Author: Florian
+ Modified by:
+ Created: Sat Nov 13 19:35:27 CET 2004
+ CVS-ID: $Id$
+ Copyright: (c) 1999-2004 Universität Karlsruhe
+ Licence: This file is protected by the GPL - GNU GENERAL PUBLIC LICENSE.
+*/
# ifdef HAVE_CONFIG_H
# include <config.h>
# endif
-# include "pto.h"
-# include "pto_util.h"
+/*
+ pto_init: Initialisation Functions
+*/
+
+# include "pto_init.h"
+# include "pto_debug.h"
+# include "pto_comp.h"
-# include "entity.h"
-# include "irnode.h"
+# include "typewalk.h"
+# include "irgwalk.h"
# include "xmalloc.h"
-# define DBGPRINT(lvl, msg) if (get_pto_verbose () > lvl) { fprintf msg; }
+/* Local Defines: */
-static void pto_init_proj_load (ir_node *proj, ir_node *load)
+/* Local Data Types: */
+typedef struct init_env_str
{
- assert ((mode_P == get_irn_mode (proj)) && "wrong proj(load)");
+ int n_ctxs;
+} init_env_t;
- pto_t *pto = pto_new_empty (proj);
- pto_set_dummy (pto);
+/* Local Variables: */
- DBGPRINT (1, (stdout, "%s: pto (%s[%li]) = 0x%08x\n",
- __FUNCTION__,
- get_op_name (get_irn_op (proj)),
- get_irn_node_nr (proj),
- (int) pto));
+/* Local Prototypes: */
+
+/* ===================================================
+ Local Implementation:
+ =================================================== */
+/* Allocate a new pto */
+static pto_t *new_pto (ir_node *node)
+{
+ /* dummy implementation for fake_pto */
+ pto_t *pto = xmalloc (sizeof (pto_t));
- set_pto (proj, pto);
+ return (pto);
}
-static void pto_init_call (ir_node *call)
+/* Allocate a new alloc_pto */
+static alloc_pto_t *new_alloc_pto (ir_node *node, int n_ctxs)
{
- /* check return value: */
- ir_node *ptr = get_Call_ptr (call);
- entity *ent = get_ptr_ent (ptr);
- type *meth_tp = get_entity_type (ent);
-
- if (0 == get_method_n_ress (meth_tp)) {
- /* no return value at all */
- return;
- }
+ int i;
+ /* dummy implementation for fake_pto */
+ alloc_pto_t *alloc_pto = xmalloc (sizeof (alloc_pto_t));
- type *ret_tp = get_method_res_type (meth_tp, 0);
+ alloc_pto->ptos = (pto_t**) xmalloc (n_ctxs * sizeof (pto_t*));
- if (mode_P != get_type_mode (ret_tp)) {
- /* no pointer-valued return value */
- return;
+ for (i = 0; i < n_ctxs; i ++) {
+ alloc_pto->ptos [i] = new_pto (node);
}
- pto_t *pto = pto_new_empty (call);
- pto_set_dummy (pto);
+ return (alloc_pto);
+}
+
+
+/* Helper to pto_init --- clear the link fields of class types */
+static void clear_type_link (type_or_ent *thing, void *__unused)
+{
+ if (is_type (thing)) {
+ type *tp = (type*) thing;
+
+ if (is_class_type (tp)) {
+ DBGPRINT (1, (stdout, "%s (\"%s\")\n",
+ __FUNCTION__, get_type_name (tp)));
+
+ set_type_link (tp, NULL);
+ }
+ } else if (is_entity (thing)) {
+ entity *ent = (entity*) thing;
- DBGPRINT (1, (stdout, "%s: pto (%s[%li]) = 0x%08x\n",
- __FUNCTION__,
- get_op_name (get_irn_op (call)),
- get_irn_node_nr (call),
- (int) pto));
+ DBGPRINT (1, (stdout, "%s (\"%s\")\n",
+ __FUNCTION__, get_entity_name (ent)));
- set_pto (call, pto);
+ set_entity_link (ent, NULL);
+ }
}
-static void pto_init_raise (ir_node *raise)
+/* Helper to pto_init_graph --- clear the links of the given node */
+static void clear_node_link (ir_node *node, void *__unused)
{
- /* assert (0 && "initialise raise?"); */
-
- /* right now, do nothing and hope that a raise can always be
- analysed on-the-fly. */
+ set_irn_link (node, NULL);
}
-static void pto_init_proj (ir_node *proj)
+/* Helper to pto_init_graph --- clear the links of all nodes */
+static void clear_graph_links (ir_graph *graph)
{
- ir_node *in = get_Proj_pred (proj);
- const opcode in_op = get_irn_opcode (in);
+ irg_walk_graph (graph, clear_node_link, NULL, NULL);
+}
- switch (in_op) {
- case (iro_Proj): {
- ir_node *in_in = get_Proj_pred (in);
- const opcode in_in_op = get_irn_opcode (in_in);
+/* Temporary fix until we get 'real' ptos: Allocate some dummy for pto */
+static void fake_pto (ir_node *node, void *env)
+{
+ init_env_t *init_env = (init_env_t*) env;
+ int n_ctxs = init_env->n_ctxs;
- switch (in_in_op) {
- case (iro_Start): {
- /* nothing (always initialised with actual values) */
- } break;
+ const opcode op = get_irn_opcode (node);
- case (iro_Call): {
- /* nothing (must use call itself) */
+ switch (op) {
+ case (iro_Load):
+ case (iro_SymConst):
+ case (iro_Const):
+ case (iro_Call):
+ case (iro_Phi): {
+ pto_t *pto = new_pto (node);
+ set_node_pto (node, pto);
} break;
- default: {
- fprintf (stderr, "%s: proj(proj(%s[%ld])) not handled\n",
- __FUNCTION__,
- get_op_name (get_irn_op (in_in)),
- get_irn_node_nr (in_in));
- assert (0);
- }
- } /* end switch(Proj.Proj.op) */
- } break; /* iro_Proj */
-
- case (iro_Start): {
- /* ProjM (start) or ProjT (start) --- nothing */
- } break;
-
- case (iro_Call): {
- /* ProjT (start) --- nothing */
- } break;
-
- case (iro_Load): {
- if (mode_P == get_irn_mode (proj)) {
- /* ProjV(load) */
- pto_init_proj_load (proj, in);
- } else {
- /* ProjM(load) --- nothing to do */
- }
- } break;
-
- case (iro_Store): {
- /* ProjM (store) --- nothing */
- } break;
-
case (iro_Alloc): {
- /* nothing to do --- can always be computed on-the-fly */
- } break;
-
- case (iro_Raise): {
- /* ProjX (raise) --- TODO */
- } break;
-
- case (iro_Cast): {
- /* not needed */
- } break;
-
- default: {
- fprintf (stderr, "%s: proj(%s[%ld]) not handled\n",
- __FUNCTION__,
- get_op_name (get_irn_op (in)),
- get_irn_node_nr (in));
- assert (0);
+ alloc_pto_t *alloc_pto = new_alloc_pto (node, n_ctxs);
+ set_alloc_pto (node, alloc_pto);
+
+ } break;
+ default:
+ HERE ("no pto");
}
- } /* end switch (Proj.op) */
+}
+/* ===================================================
+ Exported Implementation:
+ =================================================== */
+/* Initialise the Names of the Types/Entities */
+void pto_init_type_names ()
+{
+ HERE ("start");
+ type_walk (clear_type_link, NULL, NULL);
}
-void pto_init_node (ir_node *node)
+/* Initialise the given graph for a new pass run */
+void pto_init_graph (ir_graph *graph)
{
- const opcode op = get_irn_opcode (node);
+ graph_info_t *ginfo = ecg_get_info (graph);
+ int n_ctxs = ginfo->n_ctxs;
- DBGPRINT (1, (stdout, "%s (%s[%li])\n",
- __FUNCTION__,
- get_op_name (get_irn_op (node)),
- get_irn_node_nr (node)));
+ init_env_t *init_env = xmalloc (sizeof (init_env_t));
+ init_env->n_ctxs = n_ctxs;
- switch (op) {
- case (iro_Start): {
- /* nothing (not needed) */
- } break;
+ HERE ("start");
- case (iro_Load): {
- /* nothing (not needed) */
- } break;
+ clear_graph_links (graph);
- case (iro_Store): {
- /* nothing (not needed) */
- } break;
+ entity *ent = get_irg_entity (graph);
- case (iro_Alloc): {
- /* nothing (can always be computed on-the-fly) */
- } break;
+ const char *ent_name = (char*) get_entity_name (ent);
+ const char *own_name = (char*) get_type_name (get_entity_owner (ent));
- case (iro_Raise): {
- /* Todo: Check how a Raise works */
- pto_init_raise (node);
- } break;
+ DBGPRINT (0, (stdout, "%s: init \"%s.%s\" for %i ctxs\n", __FUNCTION__,
+ own_name, ent_name, n_ctxs));
- case (iro_Call): {
- /* pretend we have a return value */
- pto_init_call (node);
- } break;
+ irg_walk_graph (graph, fake_pto, NULL, init_env);
- case (iro_Proj): {
- /* this actually does most of the work */
- pto_init_proj (node);
- } break;
+ HERE ("end");
+}
- case (iro_Cast): {
- /* nothing (can always be computed on-the-fly) */
- } break;
+/* Set all alloc names to the right ptos for a new pass run */
+void pto_init_allocs (graph_info_t *ginfo, int ctx_idx)
+{
+ assert (NULL != ginfo);
- case (iro_SymConst): {
- /* nothing (can always be computed on-the-fly) */
- } break;
+ alloc_info_t *ainfo = ginfo->allocs;
- case (iro_Const): {
- /* nothing (can always be computed on-the-fly) */
- } break;
+ HERE ("start");
- case (iro_Block): {
- /* nothing (this is only interesting for the end block, and that
- can always be computed on-the-fly) */
- } break;
+ while (NULL != ainfo) {
+ ir_node *alloc = ainfo->alloc;
+ alloc_pto_t *alloc_pto = (alloc_pto_t*) get_irn_link (alloc);
- case (iro_Phi): {
- /* nothing (This would need the predecessors to be initialized! Do this on-the-fly) */
- } break;
-
- /* now, enumerate everything else that is uninteresting */
- case (iro_Return):
- case (iro_Div):
- case (iro_Quot):
- case (iro_Mod):
- case (iro_DivMod): {
- /* nothing (not needed) */
- } break;
-
- default: {
- fprintf (stderr, "%s: %s[%ld] not handled\n",
- __FUNCTION__,
- get_op_name (get_irn_op (node)),
- get_irn_node_nr (node));
- assert (0);
- } break;
+ alloc_pto->curr_pto = alloc_pto->ptos [ctx_idx];
+ DBGPRINT (0, (stdout, "%s:%i (%s[%li]): ctx_idx = %i\n",
+ __FUNCTION__, __LINE__, OPNAME (alloc), OPNUM (alloc), ctx_idx));
+
+ ainfo = ainfo->prev;
}
-}
+ HERE ("end");
+}
\f
/*
- * $Log$
- * Revision 1.2 2004/11/08 12:33:06 liekweg
- * initialisation; sanitize print levels, misc fixes
- *
- * Revision 1.1 2004/11/04 14:58:59 liekweg
- * added initialisation
- *
- *
- */
+ $Log$
+ Revision 1.3 2004/11/18 16:37:07 liekweg
+ rewrite
+
+
+*/
/* -*- c -*- */
/*
- * Project: libFIRM
- * File name: ir/ana2/pto_init.c
- * Purpose: Pto Initialization
- * Author: Florian
- * Modified by:
- * Created: Mon 18 Oct 2004
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2004 Universität Karlsruhe
- * Licence: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
+ Project: libFIRM
+ File name: ir/ana/pto_init.h
+ Purpose: ...
+ Author: Florian
+ Modified by:
+ Created: Sat Nov 13 19:35:27 CET 2004
+ CVS-ID: $Id$
+ Copyright: (c) 1999-2004 Universität Karlsruhe
+ Licence: This file is protected by the GPL - GNU GENERAL PUBLIC LICENSE.
+*/
-# ifndef _PTO_INIT_H_
-# define _PTO_INIT_H_
-void pto_init_node (ir_node*);
+# ifndef _PTO_INIT_
+# define _PTO_INIT_
+
+# include "irgraph.h"
+# include "ecg.h"
+
+/* ===================================================
+ Global Defines:
+ =================================================== */
+
+/* ===================================================
+ Global Data Types:
+ =================================================== */
+
+/* ===================================================
+ Global Prototypes:
+ =================================================== */
+/* Initialise the Names of the Types/Entities */
+void pto_init_type_names (void);
+
+/* Initialise the given graph */
+void pto_init_graph (ir_graph*);
+
+/* Set all alloc names to the right ptos */
+void pto_init_allocs (graph_info_t*, int);
+
+/* ===================================================
+ Global Variables:
+ =================================================== */
+
+
+# endif /* not defined _PTO_INIT_ */
-# endif /* not defined _PTO_INIT_H_ */
\f
/*
- * $Log$
- * Revision 1.1 2004/11/04 14:58:59 liekweg
- * added initialisation
- *
- * Revision 1.3 2004/10/25 11:59:45 liekweg
- * Copy Only works
- *
- * Revision 1.2 2004/10/21 11:09:37 liekweg
- * Moved memwalk stuf into irmemwalk
- * Moved lset stuff into lset
- * Moved typalise stuff into typalise
- *
- * Revision 1.1 2004/10/20 14:59:42 liekweg
- * Added ana2, added ecg and pto
- *
- */
+ $Log$
+ Revision 1.2 2004/11/18 16:37:07 liekweg
+ rewrite
+
+
+*/
/* -*- c -*- */
/*
- * Project: libFIRM
- * File name: ir/ana2/pto_util.c
- * Purpose: Pto Utilities
- * Author: Florian
- * Modified by:
- * Created: Mon 18 Oct 2004
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2004 Universität Karlsruhe
- * Licence: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
+ Project: libFIRM
+ File name: ir/ana/pto_util.c
+ Purpose: Utilitites for PTO
+ Author: Florian
+ Modified by:
+ Created: Sat Nov 13 19:35:27 CET 2004
+ CVS-ID: $Id$
+ Copyright: (c) 1999-2004 Universität Karlsruhe
+ Licence: This file is protected by the GPL - GNU GENERAL PUBLIC LICENSE.
+*/
# ifdef HAVE_CONFIG_H
# include <config.h>
# endif
-# include "pto_util.h"
-
-# include <malloc.h>
-# include <assert.h>
-# include <string.h>
-# include <obstack.h>
-
-# include "irnode.h"
-# include "irgwalk.h"
-# include "xmalloc.h"
-# include "entity.h"
-
-int get_pto_verbose (void); /* grrr, can't include pto.h */
-
-# define DBGPRINT(lvl, msg) if (get_pto_verbose () > lvl) { fprintf msg; }
-# define DBGEXE(lvl, cmd) if (get_pto_verbose () > lvl) { cmd; }
-
-static int pto_id = 0; /* only for pto_t->kind */
-
-static obj_desc_t *obj_descrs = NULL; /* list of all descrs */
-
-/*
- See whether the given entity is a field.
-*/
-static int is_field (entity *ent)
-{
- type *tp = get_entity_type (ent);
-
- if (is_primitive_type (tp) || is_pointer_type (tp)) {
- return (TRUE);
- } else {
- return (FALSE);
- }
-}
-
-/*
- Helper to collect_fields(type*): collect all fields of the given
- clazz and its super classes into the given obstack.
-*/
-# define obstack_chunk_alloc xmalloc
-# define obstack_chunk_free free
-
-static void _collect_fields (type *clazz, struct obstack *obst)
-{
- int n_members = get_class_n_members (clazz);
- int n_supers = get_class_n_supertypes (clazz);
- int i;
-
- for (i = 0; i < n_members; i ++) {
- entity *ent = get_class_member (clazz, i);
-
- if (is_field (ent)) {
- obstack_ptr_grow (obst, ent);
-
- DBGPRINT (4, (stdout, "%s: add entity \"%s.%s\"\n",
- __FUNCTION__,
- get_type_name (clazz),
- get_entity_name (ent)));
- }
- }
-
- for (i = 0; i < n_supers; i ++) {
- type *s_clazz = get_class_supertype (clazz, i);
-
- _collect_fields (s_clazz, obst);
- }
-}
-
-/*
- Collect the fields of the given class and its super classes into an array.
- The last entry of the array is written NULL.
-*/
-static entity **collect_fields (type *clazz)
-{
- if (NULL != get_type_link (clazz)) {
- DBGPRINT (3, (stdout, "%s: reusing field list for \"%s\"\n",
- __FUNCTION__, get_type_name (clazz)));
-
- return ((entity **) get_type_link (clazz));
- } else {
- DBGPRINT (2, (stdout, "%s: new field list for \"%s\"\n",
- __FUNCTION__, get_type_name (clazz)));
- }
-
- struct obstack obst;
-
- obstack_init (&obst);
-
- _collect_fields (clazz, &obst);
-
- /* append terminating NULL */
- int *the_null = NULL;
- obstack_ptr_grow (&obst, the_null);
-
- int n_fields = obstack_object_size (&obst) / sizeof (void*);
-
- entity ** fields = (entity**) xmalloc (n_fields * sizeof (entity*));
- void *tmp = obstack_finish (&obst);
-
- memcpy (fields, tmp, n_fields * sizeof (entity*));
-
- obstack_free (&obst, NULL);
-
- set_type_link (clazz, (void*) fields);
-
- return (fields);
-}
-# undef obstack_chunk_alloc
-# undef obstack_chunk_free
-
-
-/*
- Environment for find_irg_args
-*/
-typedef struct find_irg_args_env {
- ir_node **args;
- ir_node *arg;
-} find_irg_args_env_t;
-
/*
- Helper for find_irg_args
+ pto_util: Utilitites for PTO
*/
-static void find_irg_arg (ir_node *node, void *env)
-{
- find_irg_args_env_t *arg_env = (find_irg_args_env_t*) env;
-
- if (iro_Proj == get_irn_opcode (node)) {
- if (arg_env->arg == get_Proj_pred (node)) {
- long n = get_Proj_proj (node);
- assert (! arg_env->args [n]);
+# include "pto_util.h"
- arg_env->args [n] = node;
- }
- }
-}
+# include "irnode.h"
+# include "xmalloc.h"
-/*
- Print the given obj desc to stdout
-*/
-static void obj_desc_print (obj_desc_t *obj)
-{
- const char *tp_name = get_type_name (obj->tp);
+# include "pto_debug.h"
- if (obj_kind_obj == obj->kind) {
- /* object desc */
- obj_obj_desc_t *obj_obj = (obj_obj_desc_t*) obj;
- int i;
+/* Local Defines: */
- fprintf (stdout, "obj desc 0x%08x for type \"%s\"\n",
- (int) obj, tp_name);
+/* Local Data Types: */
- for (i = 0; i < obj_obj->n_fields; i ++) {
- if (! qset_is_empty (obj_obj->vals [i])) {
- fprintf (stdout, " \"%s.%s\" -> ",
- tp_name, get_entity_name (obj_obj->fields [i]));
- qset_print (obj_obj->vals [i], stdout);
- }
- }
+/* Local Variables: */
- } else if (obj_kind_array == obj->kind) {
- /* array desc */
- obj_arr_desc_t *obj_arr = (obj_arr_desc_t*) obj;
+/* Local Prototypes: */
- fprintf (stdout, "arr desc 0x%08x for type \"%s\"\n",
- (int) obj, get_type_name (obj->tp));
+/* ===================================================
+ Local Implementation:
+ =================================================== */
- if (! qset_is_empty (obj_arr->val)) {
- fprintf (stdout, " %s.[] -> ", tp_name);
- qset_print (obj_arr->val, stdout);
- }
- } else {
- fprintf (stderr, "%s:%i: Invalid desc\n", __FILE__, __LINE__);
- }
-}
-/*
- Get the entity of a ptr
-*/
+/* ===================================================
+ Exported Implementation:
+ =================================================== */
+/* Get the entity of a ptr */
entity *get_ptr_ent (ir_node *ptr)
{
entity *ent = NULL;
}
-/*
- Ctors for the pto types
-*/
-
-/*
- Create a new Object Description for the given type
-*/
-obj_desc_t *obj_desc_new (type *tp)
-{
- int i;
- obj_desc_t *res = NULL;
-
- if (is_array_type (tp)) {
- obj_arr_desc_t *arr_res = (obj_arr_desc_t*) xmalloc (sizeof (obj_arr_desc_t));
-
- arr_res->val = qset_new (N_INITIAL_OBJS);
-
- res = (obj_desc_t*) arr_res;
- res->kind = obj_kind_array;
-
- DBGPRINT (0, (stdout, "%s: new ARRAY desc 0x%08x for %s\n",
- __FUNCTION__, (int) res, get_type_name (tp)));
- } else if (is_class_type (tp)) {
- obj_obj_desc_t *obj_res = (obj_obj_desc_t*) xmalloc (sizeof (obj_obj_desc_t));
- int n_fields = 0;
- entity **tmp;
-
- DBGPRINT (0, (stdout, "%s: new CLAZZ desc 0x%08x for %s\n",
- __FUNCTION__, (int) obj_res, get_type_name (tp)));
-
- obj_res->fields = collect_fields (tp);
-
- /* grr, must count */
- for (tmp = obj_res->fields; NULL != *tmp; tmp ++) {
- n_fields ++;
- }
- obj_res->n_fields = n_fields;
-
- obj_res->vals = (qset_t **) xmalloc (n_fields * sizeof (qset_t*));
-
- for (i = 0; i < n_fields; i ++) {
- obj_res->vals [i] = qset_new (N_INITIAL_OBJS);
- }
-
- res = (obj_desc_t*) obj_res;
- res->kind = obj_kind_obj;
- } else {
- assert (0 && "unknown type");
- }
-
- res->tp = tp;
-
- res->next = obj_descrs;
- obj_descrs = res;
-# ifdef PTO_DUMMY
- res->is_dummy = FALSE;
-# endif /* defined PTO_DUMMY */
-
- return (res);
-}
-
-# ifdef PTO_DUMMY
-/*
- Mark an obj desc as a dummy
-*/
-void obj_desc_set_dummy (obj_desc_t *obj_desc)
-{
- obj_desc->is_dummy = TRUE;
-}
-
-/*
- Say whether an obj desc is a dummy
-*/
-int obj_desc_is_dummy (obj_desc_t *obj_desc)
-{
- return (obj_desc->is_dummy);
-}
-# endif /* defined PTO_DUMMY */
-
-/*
- Deallocate an obj desc
-*/
-void obj_desc_delete (obj_desc_t *obj_desc)
-{
- if (obj_kind_obj == obj_desc->kind) {
- /* object desc */
- obj_obj_desc_t *obj_obj = (obj_obj_desc_t*) obj_desc;
- int i;
-
- memset (obj_obj->fields, 0x00, obj_obj->n_fields * sizeof (entity*));
- free (obj_obj->fields);
-
- for (i = 0; i < obj_obj->n_fields; i ++) {
- qset_delete (obj_obj->vals [i]);
- }
-
- memset (obj_obj->vals, 0x00, obj_obj->n_fields * sizeof (entity*));
- free (obj_obj->vals);
-
- memset (obj_obj, 0x00, sizeof (obj_obj_desc_t));
-
- free (obj_obj);
- } else {
- /* array desc */
- obj_arr_desc_t *obj_arr = (obj_arr_desc_t*) obj_desc;
-
- qset_delete (obj_arr->val);
-
- memset (obj_arr, 0x00, sizeof (obj_arr_desc_t));
-
- free (obj_arr);
- }
-}
-
-/*
- List all obj descs that have been created. If tp is given non-NULL,
- only descs for this type are listed, else all types are listed.
-*/
-void obj_desc_list_all (type *tp)
-{
- obj_desc_t *cur = obj_descrs;
-
- while (NULL != cur) {
- if ((NULL == tp) || (tp == cur->tp)) {
- obj_desc_print (cur);
- }
-
- cur = cur->next;
- }
-}
-
-/*
- Create a new pto value containing no names.
-*/
-pto_t *pto_new_empty (ir_node *node)
-{
- pto_t *pto = (pto_t*) xmalloc (sizeof (pto_t));
-
- pto->kind = &pto_id;
- pto->node = node;
- pto->is_dummy = FALSE;
- pto->objs = qset_new (N_INITIAL_OBJS);
-
- return (pto);
-}
-
-/*
- Create a new pto value containing a name of the given type.
-*/
-pto_t *pto_new_name (ir_node *node, type *tp)
-{
- pto_t *pto = pto_new_empty (node);
- obj_desc_t *desc = obj_desc_new (tp);
-
- qset_insert (pto->objs, desc);
-
- return (pto);
-}
-
-/*
- Deallocate a pto
-*/
-void pto_delete (pto_t *pto)
-{
- qset_delete (pto->objs);
-
- memset (pto, 0x00, sizeof (pto_t));
-
- free (pto);
-}
-
-
-/*
- Pto types misc ops
-*/
-/*
- Sanity checking on a pto_t
-*/
-void check_pto (pto_t *pto)
-{
- assert (&pto_id == pto->kind);
-}
-
-/*
- Add the given name to the given pto.
-*/
-void pto_add_name (pto_t *pto, obj_desc_t *obj)
-{
- qset_insert (pto->objs, obj);
-}
-
-/*
- Add all the given names to the given pto.
-*/
-void pto_add_all_names (pto_t *pto, qset_t *objs)
-{
- qset_insert_all (pto->objs, objs);
-}
-
-/* Mark the given pto as a dumy */
-void pto_set_dummy (pto_t *pto)
-{
- pto->is_dummy = TRUE;
-}
-
-/* Say whether the given pto is a dummy */
-int pto_is_dummy (pto_t *pto)
-{
- return (pto->is_dummy);
-}
-
-/*
- Find the arguments of a graph. For a method that has n args, the
- result array has 'n+1' entries, the last of which is written NULL.
-*/
-ir_node **find_irg_args (ir_graph *graph)
-{
- type *tp = get_entity_type (get_irg_entity (graph));
- const int n_args = get_method_n_params (tp);
- ir_node **args = (ir_node**) xmalloc (sizeof (ir_node*) * (n_args+1));
- ir_node *arg = get_irg_args (graph);
- find_irg_args_env_t *arg_env =
- (find_irg_args_env_t*) xmalloc (sizeof (find_irg_args_env_t));
-
- arg_env->args = args;
- arg_env->arg = arg;
-
- /* or use get_irg_end ?!? */
- {
- ir_graph *save = get_current_ir_graph ();
- set_current_ir_graph (graph);
- irg_walk (get_irg_end (graph), find_irg_arg, NULL, arg_env);
- set_current_ir_graph (save);
- }
-
- free (arg_env);
-
- args [n_args] = NULL;
-
- return (args);
-}
-
-/*
- Perform a lookup of the contents of the given field in the given pto
-*/
-qset_t *pto_lookup (obj_desc_t *obj_desc, entity *ent)
-{
- qset_t *res = NULL;
-
- if (obj_kind_obj == obj_desc->kind) {
- /* obj lookup */
- obj_obj_desc_t *obj_obj = (obj_obj_desc_t*) obj_desc;
- int i;
-
- assert (NULL != ent);
-
- for (i = 0; NULL != obj_obj->fields [i]; i ++) {
- if (obj_obj->fields [i] == ent) {
- break;
- }
- }
-
- assert (obj_obj->fields [i]); /* this *must* find a field */
-
- res = obj_obj->vals [i];
- } else {
- /* array lookup */
- obj_arr_desc_t *arr_obj = (obj_arr_desc_t*) obj_desc;
-
- assert (NULL == ent);
-
- res = arr_obj->val;
- }
-
- return (res);
-}
-
-/*
- Enter the given ptr values into the given field of the given pto
-*/
-void pto_enter (obj_desc_t *obj_desc, entity *ent, pto_t *pto)
-{
- if (obj_kind_obj == obj_desc) {
- /* obj enter */
- obj_obj_desc_t *obj_obj = (obj_obj_desc_t*) obj_desc;
- int i;
-
- for (i = 0; NULL != obj_obj->fields [i]; i ++) {
- if (obj_obj->fields [i] == ent) {
- break;
- }
- }
-
- assert (obj_obj->fields [i]); /* this *must* find a field */
-
- qset_insert_all (obj_obj->vals [i], pto->objs);
- } else {
- /* array enter */
- assert (0 && "array enter not yet implemented");
- }
-}
\f
/*
$Log$
- Revision 1.5 2004/11/09 16:46:01 liekweg
- new DBGEXE macro
-
- Revision 1.4 2004/11/08 12:33:06 liekweg
- initialisation; sanitize print levels, misc fixes
-
- Revision 1.3 2004/11/04 14:58:38 liekweg
- expanded pto, added initialisation, added debugging printing
+ Revision 1.6 2004/11/18 16:37:07 liekweg
+ rewrite
- Revision 1.2 2004/10/25 11:59:45 liekweg
- Copy Only works
- Revision 1.1 2004/10/22 15:10:51 liekweg
- moved utils to pto_util
-
-
- */
+*/
/* -*- c -*- */
/*
- * Project: libFIRM
- * File name: ir/ana2/pto_util.c
- * Purpose: Pto Utilities
- * Author: Florian
- * Modified by:
- * Created: Mon 18 Oct 2004
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2004 Universität Karlsruhe
- * Licence: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-# ifndef _PTO_UTIL_H_
-# define _PTO_UTIL_H_
-
-# include "irgraph.h"
-# include "qset.h"
-
-# define N_INITIAL_OBJS 5
-
-typedef enum obj_kind_enum {
- obj_kind_obj,
- obj_kind_array,
-} obj_kind_t;
-
-typedef struct obj_desc_str
-{
- obj_kind_t kind; /* written obj_kind_obj or obj_kind_array */
- struct obj_desc_str *next; /* link all descrs into a linked list */
- type *tp; /* type of described object */
-} obj_desc_t;
-
-typedef struct obj_obj_desc_str
-{
- obj_kind_t kind; /* always written obj_kind_obj */
- struct obj_desc_str *next; /* link all descrs into a linked list */
- type *tp; /* type of described object */
- entity **fields; /* fields of described object */
- int n_fields; /* number of fields */
- qset_t **vals; /* qsets of values of the fields */
-} obj_obj_desc_t;
-
-typedef struct obj_arr_desc_str
-{
- obj_kind_t kind; /* always written obj_kind_array */
- struct obj_desc_str *next; /* link all descrs into a linked list */
- type *tp; /* (array) type of described object */
- qset_t *val; /* all values of 'the' 'field' */
-} obj_arr_desc_t;
-
-typedef struct pto_str
-{
- void *kind; /* always written to &pto_id */
- ir_node *node; /* Rubbish: node for which this pto_t was constructed */
- int is_dummy; /* allow to filter out dummy values */
- qset_t *objs; /* qset of obj_desc_t* */
-} pto_t;
-
-
-/* Get the entity of a ptr */
+ Project: libFIRM
+ File name: ir/ana/pto_util.h
+ Purpose: Utilitites for PTO
+ Author: Florian
+ Modified by:
+ Created: Sat Nov 13 19:35:27 CET 2004
+ CVS-ID: $Id$
+ Copyright: (c) 1999-2004 Universität Karlsruhe
+ Licence: This file is protected by the GPL - GNU GENERAL PUBLIC LICENSE.
+*/
+
+
+# ifndef _PTO_UTIL_
+# define _PTO_UTIL_
+
+# include "irnode.h"
+# include "entity.h"
+
+/* ===================================================
+ Global Defines:
+ =================================================== */
+
+/* ===================================================
+ Global Data Types:
+ =================================================== */
+
+/* ===================================================
+ Global Prototypes:
+ =================================================== */
entity *get_ptr_ent (ir_node*);
-/* Ctors for the pto types */
-obj_desc_t *obj_desc_new (type*);
-
-/* Deallocate an obj desc */
-void obj_desc_delete (obj_desc_t*);
-
-/* List all obj descs that have been created. If tp is given non-NULL,
- only descs for this type are listed, else all types are listed. */
-void obj_desc_list_all (type*);
+/* ===================================================
+ Global Variables:
+ =================================================== */
-/* Create a new pto value containing a name of the given type. */
-pto_t *pto_new_name (ir_node*, type*);
-/* Create a new pto value containing no names. */
-pto_t *pto_new_empty (ir_node*);
+# endif /* not defined _PTO_UTIL_ */
-/* Deallocate a pto */
-void pto_delete (pto_t*);
-
-/* Sanity checking on a pto_t */
-void check_pto (pto_t*);
-
-/* Add the given name to the given pto. */
-void pto_add_name (pto_t*, obj_desc_t*);
-
-/* Add all the given names to the given pto. */
-void pto_add_all_names (pto_t*, qset_t*);
-
-/* Mark the given pto as a dumy */
-void pto_set_dummy (pto_t*);
-
-/* Say whether the given pto is a dummy */
-int pto_is_dummy (pto_t*);
-
-/* Find the arguments of a graph. For a method that has n args, the
- result array has 'n+1' entries, the last of which is written NULL.
- If an argument is not used, it is also written NULL in this array. */
-ir_node **find_irg_args (ir_graph*);
-/* int is_field (entity*); */
-
-
-/* Perform a lookup of the contents of the given field in the given pto */
-qset_t *pto_lookup (obj_desc_t*, entity*);
-
-# endif /* not defined _PTO_UTIL_H_ */
\f
/*
$Log$
- Revision 1.3 2004/11/08 12:33:06 liekweg
- initialisation; sanitize print levels, misc fixes
-
- Revision 1.2 2004/11/04 14:58:38 liekweg
- expanded pto, added initialisation, added debugging printing
-
- Revision 1.1 2004/10/22 15:10:51 liekweg
- moved utils to pto_util
+ Revision 1.4 2004/11/18 16:37:07 liekweg
+ rewrite
- */
+*/