Commit a3a4f27f authored by Götz Lindenmaier's avatar Götz Lindenmaier
Browse files

Changed implementation of tr module.

[r141]
parent 4ce65700
......@@ -26,6 +26,8 @@ const char* print_firm_kind(void *firm_thing) {
assert (firm_thing);
switch (*(firm_kind *)firm_thing) {
case k_entity: { return "k_enitity"; } break;
case k_type: { return "k_type"; } break;
#if 0
case k_type_class: { return "k_type_class"; } break;
case k_type_strct: { return "k_type_strct:"; } break;
case k_type_method: { return "k_type_method:"; } break;
......@@ -34,6 +36,7 @@ const char* print_firm_kind(void *firm_thing) {
case k_type_enumeration: { return "k_type_enumeration"; } break;
case k_type_pointer: { return "k_type_pointer"; } break;
case k_type_primitive: { return "k_type_primitive"; } break;
#endif
case k_ir_node: { return "k_ir_node"; } break;
}
return "";
......
......@@ -40,6 +40,11 @@
/* a list of firm kinds */
typedef enum {
k_entity,
k_type,
k_ir_node
} firm_kind;
#if 0
k_type_class,
k_type_strct,
k_type_method,
......@@ -48,8 +53,7 @@ typedef enum {
k_type_enumeration,
k_type_pointer,
k_type_primitive,
k_ir_node
} firm_kind;
#endif
/* returns the kind of the thing */
firm_kind get_kind(void *firm_thing);
......
......@@ -16,6 +16,7 @@
# include "xp_help.h"
# include "irnode_t.h"
# include "tv_t.h"
# include "tpop_t.h"
void
init_firm (void)
......@@ -28,7 +29,9 @@ init_firm (void)
xprintf_register ('R', ir_node_print);
/* initialize all ident stuff */
id_init ();
/* create an obstack and put alle tarvals in a pdeq */
/* create the type kinds. */
init_tpop ();
/* create an obstack and put all tarvals in a pdeq */
tarval_init_1 ();
/* initialize all modes an ir node can consist of */
init_mode ();
......
......@@ -58,7 +58,8 @@ inline ident *id_from_str (char *str, int len);
* SYNOPSIS
* char *cp = id_to_str (ident *id);
* FUNCTION
* Returns the string cp represented by id. This string cp is not Null terminated!
* Returns the string cp represented by id. This string cp is not
* Null terminated!
* INPUTS
* id - the ident
* RESULT
......
......@@ -404,7 +404,7 @@ new_r_Cond (ir_graph *irg, ir_node *block, ir_node *c)
ir_node *
new_r_Call (ir_graph *irg, ir_node *block, ir_node *store,
ir_node *callee, int arity, ir_node **in, type_method *type)
ir_node *callee, int arity, ir_node **in, type *type)
{
ir_node **r_in;
ir_node *res;
......@@ -418,6 +418,7 @@ new_r_Call (ir_graph *irg, ir_node *block, ir_node *store,
res = new_ir_node (irg, block, op_Call, mode_T, r_arity, r_in);
assert(is_method_type(type));
set_Call_type(res, type);
res = optimize (res);
irn_vrfy (res);
......@@ -1433,7 +1434,7 @@ new_Cond (ir_node *c)
ir_node *
new_Call (ir_node *store, ir_node *callee, int arity, ir_node **in,
type_method *type)
type *type)
{
return new_r_Call (current_ir_graph, current_ir_graph->current_block,
store, callee, arity, in, type);
......
......@@ -1118,7 +1118,7 @@ ir_node *new_r_Sel (ir_graph *irg, ir_node *block, ir_node *store,
entity *ent);
ir_node *new_r_Call (ir_graph *irg, ir_node *block, ir_node *store,
ir_node *callee, int arity, ir_node **in,
type_method *type);
type *type);
ir_node *new_r_Add (ir_graph *irg, ir_node *block,
ir_node *op1, ir_node *op2, ir_mode *mode);
ir_node *new_r_Sub (ir_graph *irg, ir_node *block,
......@@ -1201,7 +1201,7 @@ ir_node *new_simpleSel (ir_node *store, ir_node *objptr, entity *ent);
ir_node *new_Sel (ir_node *store, ir_node *objptr, int arity, ir_node **in,
entity *ent);
ir_node *new_Call (ir_node *store, ir_node *callee, int arity, ir_node **in,
type_method *type);
type *type);
ir_node *new_Add (ir_node *op1, ir_node *op2, ir_mode *mode);
ir_node *new_Sub (ir_node *op1, ir_node *op2, ir_mode *mode);
ir_node *new_Minus (ir_node *op, ir_mode *mode);
......
......@@ -46,6 +46,7 @@
#define METH_PAR_EDGE_ATTR "label: \"param %d\" color: green"
#define METH_RES_EDGE_ATTR "label: \"res %d\" color: green"
#define TYPE_SUPER_EDGE_ATTR "label: \"supertype\" color: blue"
#define UNION_EDGE_ATTR "label: \"component\" color: blue"
#define PTR_PTS_TO_EDGE_ATTR "label: \"points to\" color:green"
#define ARR_ELT_TYPE_EDGE_ATTR "label: \"arr elt\" color:green"
......@@ -73,9 +74,9 @@ dump_node_opcode (ir_node *n)
if (get_SymConst_kind(n) == linkage_ptr_info) {
xfprintf (F, "%I", get_SymConst_ptrinfo(n));
} else {
assert(get_kind(get_SymConst_type(n)) == k_type_class);
assert(get_class_ident((type_class *)get_SymConst_type(n)));
xfprintf (F, "%s ", id_to_str(get_class_ident((type_class *)get_SymConst_type(n))));
assert(get_kind(get_SymConst_type(n)) == k_type);
assert(get_type_nameid(get_SymConst_type(n)));
xfprintf (F, "%s ", id_to_str(get_type_nameid(get_SymConst_type(n))));
if (get_SymConst_kind == type_tag)
xfprintf (F, "tag");
else
......@@ -317,10 +318,9 @@ dump_ir_node (ir_node *n)
xfprintf (F, DEFAULT_NODE_ATTR);
break;
case iro_SymConst:
assert(get_kind(get_SymConst_type(n)) == k_type_class);
assert(get_class_ident((type_class *)get_SymConst_type(n)));
xfprintf (F, "\"%s ",
id_to_str(get_class_ident((type_class *)get_SymConst_type(n))));
assert(get_kind(get_SymConst_type(n)) == k_type);
assert(get_type_nameid(get_SymConst_type(n)));
xfprintf (F, "\"%s ", get_type_name(get_SymConst_type(n)));
switch (n->attr.i.num){
case type_tag:
xfprintf (F, "tag\" ");
......@@ -497,73 +497,75 @@ dump_type_info (type_or_ent *tore, void *env) {
xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
ENT_TYPE_EDGE_ATTR "}\n", tore, get_entity_type(ent));
} break;
case k_type_class:
case k_type:
{
type_class *type = (type_class *)tore;
xfprintf (F, "\"class %I\" " TYPE_CLASS_NODE_ATTR "}\n", get_class_ident(type));
for (i=0; i < get_class_n_supertype(type); i++)
xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
TYPE_SUPER_EDGE_ATTR "}\n",
type, get_class_supertype(type, i));
} break;
case k_type_strct:
{
type_strct *type = (type_strct *)tore;
xfprintf (F, "\"strct %I\"}\n", get_strct_ident(type));
/* edges !!!??? */
} break;
case k_type_method:
{
type_method *type = (type_method *)tore;
xfprintf (F, "\"meth %I\" " TYPE_METH_NODE_ATTR "}\n", get_method_ident(type));
for (i = 0; i < get_method_arity(type); i++)
xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
METH_PAR_EDGE_ATTR "}\n",
tore, get_method_param_type(type, i), i);
for (i = 0; i < get_method_n_res(type); i++)
xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
METH_RES_EDGE_ATTR "}\n",
tore, get_method_res_type(type, i), i);
} break;
case k_type_union:
{
type_union *type = (type_union *)tore;
xfprintf (F, "\"union %I\"}\n", get_union_ident(type));
/* edges !!!??? */
} break;
case k_type_array:
{
type_array *type = (type_array *)tore;
xfprintf (F, "\"array %I\"}\n", get_array_ident(type));
xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
ARR_ELT_TYPE_EDGE_ATTR "}\n", tore, get_array_element_type(type), i);
/* edges !!!??? */
} break;
case k_type_enumeration:
{
type_enumeration *type = (type_enumeration *)tore;
xfprintf (F, "\"enum %I\"}\n", get_enumeration_ident(type));
} break;
case k_type_pointer:
{
type_pointer *type = (type_pointer *)tore;
xfprintf (F, "\"ptr %I\"}\n", get_pointer_ident(type));
xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
PTR_PTS_TO_EDGE_ATTR "}\n", tore,
get_pointer_points_to_type(type), i);
} break;
case k_type_primitive:
{
type_primitive *type = (type_primitive *)tore;
xfprintf (F, "\"prim %I, mode %I\"}\n", get_primitive_ident(type),
get_mode_ident(get_primitive_mode(type)));
} break;
type *type = tore;
xfprintf (F, "\"%I %I", get_type_tpop_nameid(type), get_type_nameid(type));
switch (get_type_tpop_code(type)) {
case tpo_class:
{
xfprintf (F, "\" " TYPE_CLASS_NODE_ATTR "}\n");
for (i=0; i < get_class_n_supertype(type); i++)
xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
TYPE_SUPER_EDGE_ATTR "}\n",
type, get_class_supertype(type, i));
} break;
case tpo_struct:
{
xfprintf (F, "\"}\n");
} break;
case tpo_method:
{
xfprintf (F, "\" " TYPE_METH_NODE_ATTR "}\n");
for (i = 0; i < get_method_n_params(type); i++)
xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
METH_PAR_EDGE_ATTR "}\n",
type, get_method_param_type(type, i), i);
for (i = 0; i < get_method_n_res(type); i++)
xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
METH_RES_EDGE_ATTR "}\n",
type, get_method_res_type(type, i), i);
} break;
case tpo_union:
{
xfprintf (F, "\"}\n");
for (i = 0; i < get_union_n_types(type); i++)
xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
"label: \"%I\"f" UNION_EDGE_ATTR "}\n",
type, get_union_unioned_type(type, i), get_union_delim_nameid(type, i));
} break;
case tpo_array:
{
xfprintf (F, "\"}\n");
xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
ARR_ELT_TYPE_EDGE_ATTR "}\n", type, get_array_element_type(type), i);
} break;
case tpo_enumeration:
{
xfprintf (F, "\"}\n");
} break;
case tpo_pointer:
{
xfprintf (F, "\"}\n");
xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
PTR_PTS_TO_EDGE_ATTR "}\n", type,
get_pointer_points_to_type(type), i);
} break;
case tpo_primitive:
{
xfprintf (F, "mode %I\"}\n", get_mode_ident(get_type_mode(type)));
} break;
default: break;
} /* switch type */
} break; /* case k_type */
default:
{
xfprintf (F, "\" faulty type \"}\n");
printf(" *** irdump, %s(l.%i), faulty type.\n", __FUNCTION__, __LINE__);
} break;
}
} /* switch kind_or_entity */
}
/************************************************************************/
......
......@@ -29,7 +29,7 @@ extern ir_graph *current_ir_graph;
/* Create a new ir graph to built ir for a procedure.
ent is the entity representing this procedure, i.e., the type of the
entity must be type_method. The constructor automatically sets the
entity must be of a method type. The constructor automatically sets the
field irg of the entity to the new ir graph.
n_loc is the number of local variables in this procedure including
the procedure parameters. */
......
......@@ -146,7 +146,7 @@ ir_node_print (XP_PAR1, const xprintf_info *info ATTRIBUTE((unused)), XP_PARN)
XPF1 ("%I", get_irn_mode(np)->name);
XPC (" ");
XP (symconst_name_arr[get_irn_symconst_attr(np).num]);
XPF1 (" %#N", get_class_ident((type_class *)get_SymConst_type(np)));
XPF1 (" %#N", get_type_nameid(get_SymConst_type(np)));
break;
case iro_Start: /* don't dump mode of these */
case iro_Cond:
......@@ -335,7 +335,7 @@ get_irn_symconst_attr (ir_node *node)
return node->attr.i;
}
inline type_method *
inline type *
get_irn_call_attr (ir_node *node)
{
assert (node->op == op_Call);
......@@ -741,15 +741,16 @@ set_Call_param (ir_node *node, int pos, ir_node *param) {
set_irn_n(node, pos + CALL_PARAM_OFFSET, param);
}
inline type_method *
inline type *
get_Call_type (ir_node *node) {
assert (node->op == op_Call);
return node->attr.call;
}
inline void
set_Call_type (ir_node *node, type_method *type) {
set_Call_type (ir_node *node, type *type) {
assert (node->op == op_Call);
assert (is_method_type(type));
node->attr.call = type;
}
......
......@@ -180,8 +180,8 @@ inline int get_Call_arity (ir_node *node);
/* inline void set_Call_arity (ir_node *node, ir_node *arity); */
inline ir_node *get_Call_param (ir_node *node, int pos);
inline void set_Call_param (ir_node *node, int pos, ir_node *param);
inline type_method *get_Call_type (ir_node *node);
inline void set_Call_type (ir_node *node, type_method *type);
inline type *get_Call_type (ir_node *node);
inline void set_Call_type (ir_node *node, type *type);
/* For unary and binary arithmetic operations the access to the
operands can be factored out. Left is the first, right the
......
......@@ -53,7 +53,7 @@ typedef union {
struct tarval *con; /* For Const: contains the value of the constant */
symconst_attr i; /* For SymConst. */
sel_attr s; /* For Sel. */
type_method *call; /* For Call: pointer to the type of the method to call */
type *call; /* For Call: pointer to the type of the method to call */
long proj; /* For Proj: contains the result position to project */
alloc_attr a; /* For Alloc. */
type *f; /* For Free. */
......@@ -104,7 +104,7 @@ inline long get_irn_proj_attr (ir_node *node);
inline alloc_attr get_irn_alloc_attr (ir_node *node);
inline type *get_irn_free_attr (ir_node *node);
inline symconst_attr get_irn_symconst_attr (ir_node *node);
type_method *get_irn_call_attr (ir_node *node);
type *get_irn_call_attr (ir_node *node);
sel_attr get_irn_sel_attr (ir_node *node);
int get_irn_phi_attr (ir_node *node);
block_attr get_irn_return_attr (ir_node *node);
......
......@@ -96,7 +96,7 @@ init_op(void)
op_Sel = new_ir_op (iro_Sel, id_from_str ("Sel", 3), sizeof (sel_attr), 1);
op_Call = new_ir_op (iro_Call, id_from_str ("Call", 4), sizeof (type_method *), 1);
op_Call = new_ir_op (iro_Call, id_from_str ("Call", 4), sizeof (type *), 1);
op_Add = new_ir_op (iro_Add, id_from_str ("Add", 3), 0, 0);
op_Minus = new_ir_op (iro_Minus, id_from_str ("Minus", 5), 0, 0);
op_Sub = new_ir_op (iro_Sub, id_from_str ("Sub", 3), 0, 1);
......
......@@ -768,8 +768,7 @@ vt_cmp (const void *elt, const void *key)
return (get_irn_symconst_attr(a).num != get_irn_symconst_attr(b).num)
|| (get_irn_symconst_attr(a).tori.typ != get_irn_symconst_attr(b).tori.typ);
case iro_Call:
return (get_irn_call_attr(a)->kind != get_irn_call_attr(b)->kind)
|| (get_irn_call_attr(a)->arity != get_irn_call_attr(b)->arity);
return (get_irn_call_attr(a) != get_irn_call_attr(b));
case iro_Sel:
return (get_irn_sel_attr(a).ent->kind != get_irn_sel_attr(b).ent->kind)
|| (get_irn_sel_attr(a).ent->name != get_irn_sel_attr(b).ent->name)
......
......@@ -60,7 +60,7 @@ void set_irp_main_irg(ir_graph *main_irg) {
irp->main_irg = main_irg;
}
type_class *get_glob_type(void) {
type *get_glob_type(void) {
assert(irp);
return irp->glob_type;
}
......
......@@ -51,7 +51,7 @@ type *get_irp_type(int pos);
void set_irp_type(int pos, type *typ);
/** Functions to access the fields of ir_prog **/
type_class *get_glob_type(void);
type *get_glob_type(void);
#ifdef DEBUG_libfirm
/* Returns a new, unique number to number nodes or the like. */
......
......@@ -6,15 +6,14 @@
struct ir_prog {
firm_kind kind;
ir_graph *main_irg; /* entry point to the compiled program */
ir_graph *main_irg; /* entry point to the compiled program */
/* or a list, in case we compile a library or the like? */
ir_graph **graphs; /* all graphs in the ir */
type_class *glob_type; /* global type. Class as it can have
fields and procedures. Does this work?
Better name??? @@@ */
type **types; /* all types in the ir */
/*struct obstack *obst; * @@@ Should we place all types and
entities on an obstack, too? */
ir_graph **graphs; /* all graphs in the ir */
type *glob_type; /* global type. Must be a class as it can
have fields and procedures. */
type **types; /* all types in the ir */
/*struct obstack *obst; * @@@ Should we place all types and
entities on an obstack, too? */
#ifdef DEBUG_libfirm
long max_node_nr; /* to generate unique numbers for nodes. */
#endif
......
......@@ -22,7 +22,7 @@ X_INCLUDES =
SHELL = /bin/sh
MAKE = /usr/bin/make
DISTRIBMEMBERS = entity.m type.m typewalk.m
DISTRIBMEMBERS = entity.m type.m typewalk.m tpop.m
MEMBERS = $(DISTRIBMEMBERS) mangle.m
CFILES = $(MEMBERS:.m=.c)
......@@ -31,7 +31,8 @@ HFILES = $(MEMBERS:.m=.h)
HFILES += type_or_entity.h
HFILES += common.h debug.h gmp.h host.h ident.h irgraph.h \
irgwalk.h irmode.h irnode.h irop.h label.h misc.h \
obst.h pset.h set.h tv.h xprintf.h xp_help.h entity_t.h
obst.h pset.h set.h tv.h xprintf.h xp_help.h entity_t.h \
type_t.h tpop_t.h
DISTRIB = $(DISTRIBMEMBERS:.m=.h)
DISTRIB += type_or_entity.h
......
......@@ -10,12 +10,12 @@ srcdir = @srcdir@
topdir = ../..
subdir := ir/tr
INSTALL_HEADERS = mangle.h type.h entity.h type_or_entity.h typewalk.h
INSTALL_HEADERS = entity.h mangle.h tpop.h type.h typewalk.h type_or_entity.h
SOURCES = $(INSTALL_HEADERS)
SOURCES += Makefile.in \
entity.c entity_t.h typewalk.c mangle.c type.c
entity.c entity_t.h mangle.c tpop.c tpop_t.h type.c type_t.h typewalk.c
include $(topdir)/MakeRules
......
......@@ -43,17 +43,17 @@ new_entity (type *owner, ident *name, type *type)
res->visit = 0;
switch (get_kind(owner)) {
case k_type_class: {
add_class_member ((type_class *) owner, res);
switch (get_type_tpop_code(owner)) {
case tpo_class: {
add_class_member (owner, res);
} break;
case k_type_strct: {
add_strct_member ((type_strct *) owner, res);
case tpo_struct: {
add_struct_member (owner, res);
} break;
case k_type_union: {
case tpo_union: {
/* not implemented */
} break;
case k_type_method: {
case tpo_method: {
/* not implemented */
} break;
default: ;
......@@ -92,10 +92,10 @@ set_entity_owner (entity *ent, type *owner) {
inline void /* should this go into type.c? */
assert_legal_owner_of_ent(type *owner) {
assert (owner->clss.kind == k_type_class ||
owner->uni.kind == k_type_union ||
owner->array.kind == k_type_array ||
owner->method.kind == k_type_method );
assert (get_type_tpop_code(owner) == tpo_class ||
get_type_tpop_code(owner) == tpo_union ||
get_type_tpop_code(owner) == tpo_array ||
get_type_tpop_code(owner) == tpo_method );
}
inline ident *
......@@ -134,7 +134,7 @@ set_entity_offset (entity *ent, int offset) {
inline ir_graph *
get_entity_irg(entity *ent) {
assert (ent);
assert (get_kind(ent->type) == k_type_method);
assert (is_method_type(ent->type));
return ent->irg;
}
......@@ -142,6 +142,6 @@ inline void
set_entity_irg(entity *ent, ir_graph *irg) {
assert (ent && ent->type);
assert (irg);
assert (get_kind(ent->type) == k_type_method);
assert (is_method_type(ent->type));
ent->irg = irg;
}
......@@ -12,12 +12,13 @@
# include "mangle.h"
# include <obstack.h>
# include "obst.h"
# include "entity.h"
# include <stdlib.h>
# include "ident_t.h"
# include "misc.h"
/* Make types visible to allow most efficient access */
# include "entity_t.h"
# include "type_t.h"
# include "tpop_t.h"
static struct obstack mangle_obst;
......@@ -45,9 +46,10 @@ mangle_type (type *type)
int len;
ident *res;
assert (type->kind == k_type_class);
assert (type->kind == k_type);
assert (type->type_op->code == tpo_class);
xoprintf (&mangle_obst, "%I", type->clss.name);
xoprintf (&mangle_obst, "%I", type->name);
len = obstack_object_size (&mangle_obst);
cp = obstack_finish (&mangle_obst);
res = id_from_str (cp, len);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment