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

*** empty log message ***

[r69]
parent 4b3c973f
7.9.2000 Goetz
Finished implementation of dump_all_types.
Added new testprogram inheritance_example.
6.9.2000 Chris
Added seven access routines in type.[hc]:
get_class_n_member, get_class_n_subtype, get_class_n_supertype,
......
......@@ -15,3 +15,20 @@ firm_kind
get_kind (void *firm_thing) {
return *(firm_kind *)firm_thing;
}
const char* print_firm_kind(void *firm_thing) {
switch (*(firm_kind *)firm_thing) {
case k_entity: { return "k_enitity"; } break;
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;
case k_type_union: { return "k_type_union"; } break;
case k_type_array: { return "k_type_array"; } break;
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;
case k_ir_node: { return "k_ir_node"; } break;
}
return "";
}
......@@ -48,5 +48,8 @@ typedef enum {
/* returns the kind of the thing */
firm_kind get_kind(void *firm_thing);
/* returns a string. */
const char* print_firm_kind(void *firm_thing);
# endif /*_COMMON_H_ */
......@@ -289,23 +289,17 @@ dump_ir_node (ir_node *n)
break;
case iro_Sel:
assert(get_kind(get_Sel_entity(n)) == k_entity);
/*assert(n->attr.s.ent->kind == k_entity);*/
xfprintf (F, "\"%I ", n->op->name);
/*xfprintf (F, "%s\" ", id_to_str(n->attr.s.ent->name));*/
xfprintf (F, "%s", id_to_str(get_entity_ident(get_Sel_entity(n))));
/* xdoesn't work for some reason.
fprintf (F, "\"%I %I\" ", n->op->name, n->attr.s.ent); */
fprintf (F, "\"%I %I\" ", n->op->name, get_entity_ident(get_Sel_entity(n))); */
xfprintf (F, DEFAULT_NODE_ATTR);
break;
case iro_SymConst:
assert(get_kind(get_SymConst_type(n)) == k_type_class);
/* assert(n->attr.i.type->kind == k_type_class); */
assert(get_class_ident((type_class *)get_SymConst_type(n)));
/* assert(n->attr.i.type->clss->name); */
xfprintf (F, "\"%s ", id_to_str(get_class_ident((type_class *)get_SymConst_type(n))));
/* xfprintf (F, "\"%s ", id_to_str(n->attr.i.type->name)); */
/* doesn't work for some reason. */
/* xfprintf (F, "\"%N\" ", n->attr.i.type); */
xfprintf (F, "\"%s ",
id_to_str(get_class_ident((type_class *)get_SymConst_type(n))));
switch (n->attr.i.num){
case type_tag:
xfprintf (F, "tag\" ");
......@@ -419,14 +413,16 @@ dump_type_info (type_or_ent *tore, void *env) {
{
type_class *type = (type_class *)tore;
xfprintf (F, "\"class %I\"}\n", get_class_ident(type));
/* edges !!!??? */
for (i=0; i < get_class_n_supertype(type); i++)
xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
" label: \"supertype\" " TYPE_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:
......
......@@ -399,6 +399,8 @@ int is_fragile_op(ir_node *node);
id_to_str(get_irn_opname(X)))
#define DDMSG2(X) printf("%s(l.%i) %s: %ld\n", __FUNCTION__, __LINE__, \
id_to_str(get_irn_opname(X)), get_irn_node_nr(X))
#define DDMSG3(X) printf("%s(l.%i) %s: %p\n", __FUNCTION__, __LINE__, \
print_firm_kind(X), (X))
#endif
......
......@@ -38,9 +38,21 @@ new_entity (type *owner, ident *name, type *type)
res->visit = 0;
/* add entity to the list of entities of the owner. */
// res->owner->member[res->owner->n_members] = res;
// res->owner->n_members ++;
switch (get_kind(owner)) {
case k_type_class: {
add_class_member ((type_class *) owner, res);
} break;
case k_type_strct: {
add_strct_member ((type_strct *) owner, res);
} break;
case k_type_union: {
/* not implemented */
} break;
case k_type_method: {
/* not implemented */
} break;
default: ;
}
return res;
}
......
......@@ -55,14 +55,15 @@ typedef struct ir_graph ir_graph;
typedef struct entity entity;
#endif
/* create a new entity */
entity *new_entity (type *owner, ident *name, type *type);
/* Creates a new entity.
Automatically inserts the entity as a member of owner. */
entity *new_entity (type *owner, ident *name, type *type);
/* manipulate fields of entity */
char *get_entity_name (entity *ent);
ident *get_entity_ident (entity *ent);
ident *get_entity_ld_name (entity *ent);
const char *get_entity_name (entity *ent);
ident *get_entity_ident (entity *ent);
/* returns the mangled name of the entity */
ident *get_entity_ld_name (entity *ent);
/*
char *get_entity_ld_name (entity *ent);
......
......@@ -115,11 +115,8 @@ set_class_subtype (type_class *class, type_class *subtype, int pos)
int
get_class_n_subtype (type_class *class)
{
int res;
assert(class);
res = (ARR_LEN (class->members))-1;
return res;
return (ARR_LEN (class->subtypes))-1;
}
/* field: supertype */
......@@ -145,11 +142,8 @@ set_class_supertype (type_class *class, type_class *supertype, int pos)
int
get_class_n_supertype (type_class *class)
{
int res;
assert(class);
res = (ARR_LEN (class->members))-1;
return res;
return (ARR_LEN (class->supertypes))-1;
}
/*******************************************************************/
......
......@@ -228,27 +228,27 @@ type_class *new_type_class (ident *name);
/* manipulate fields of type_class */
const char *get_class_name (type_class *class);
ident *get_class_ident (type_class *class);
ident *get_class_ident (type_class *class);
/* Not necessary now!
void set_class_name (type_class *class, char *name);
void set_class_ident (type_class *class, ident* ident);
*/
void add_class_member (type_class *class, entity *member);
void add_class_member (type_class *class, entity *member);
int get_class_n_member (type_class *class);
entity *get_class_member (type_class *class, int pos);
void set_class_member (type_class *class, entity *member, int pos);
int get_class_n_member (type_class *class);
void set_class_member (type_class *class, entity *member, int pos);
void add_class_subtype (type_class *class, type_class *subtype);
void add_class_subtype (type_class *class, type_class *subtype);
int get_class_n_subtype (type_class *class);
type_class *get_class_subtype (type_class *class, int pos);
void set_class_subtype (type_class *class, type_class *subtype, int pos);
int get_class_n_subtype (type_class *class);
void set_class_subtype (type_class *class, type_class *subtype, int pos);
void add_class_supertype (type_class *class, type_class *supertype);
void add_class_supertype (type_class *class, type_class *supertype);
int get_class_n_supertype (type_class *class);
type_class *get_class_supertype (type_class *class, int pos);
void set_class_supertype (type_class *class, type_class *supertype, int pos);
int get_class_n_supertype (type_class *class);
void set_class_supertype (type_class *class, type_class *supertype, int pos);
/*******************************************************************/
/** TYPE_STRCT **/
......@@ -267,12 +267,12 @@ type_strct *new_type_strct (ident *name);
/* manipulate fields of type_strct */
const char *get_strct_name (type_strct *strct);
ident *get_strct_ident (type_strct *strct);
ident *get_strct_ident (type_strct *strct);
int get_strct_n_member (type_strct *strct);
void add_strct_member (type_strct *strct, entity *member);
entity *get_strct_member (type_strct *strct, int pos);
void set_strct_member (type_strct *strct, int pos, entity *member);
void add_strct_member (type_strct *strct, entity *member);
int get_strct_n_member (type_strct *strct);
entity *get_strct_member (type_strct *strct, int pos);
void set_strct_member (type_strct *strct, int pos, entity *member);
/*
void set_strct_name (type_strct *strct, char *name);
......@@ -299,24 +299,24 @@ typedef struct {
unsigned long visit; /* visited counter for walks of the type information */
} type_method;
/* create a new type_method
arity is number of parameters. */
/* Create a new type_method.
Arity is the number of parameters. */
type_method *new_type_method (ident *name, int arity, int n_res);
/* manipulate fields of type_method */
const char *get_method_name (type_method *method);
ident *get_method_ident (type_method *method);
ident *get_method_ident (type_method *method);
/*
void set_method_name (type_method *method, char *name);
void set_method_ident (type_method *method, ident* ident); */
inline int get_method_arity (type_method *method);
inline void set_method_arity (type_method *method, int arity);
/*inline void set_method_arity (type_method *method, int arity);*/
inline type *get_method_param_type(type_method *method, int pos);
inline void set_method_param_type(type_method *method, int pos, type* type);
inline int get_method_n_res (type_method *method);
inline void set_method_n_res (type_method *method, int n_res);
/*inline void set_method_n_res (type_method *method, int n_res);*/
inline type *get_method_res_type(type_method *method, int pos);
inline void set_method_res_type(type_method *method, int pos, type* type);
......@@ -338,7 +338,7 @@ type_union *new_type_union (ident *name, int n_types);
/* manipulate fields of type_union */
const char *get_union_name (type_union *uni);
ident *get_union_ident (type_union *uni);
ident *get_union_ident (type_union *uni);
/*
void set_union_name (type_union *union, char *name);
void set_union_ident (type_union *union, ident* ident);
......@@ -370,7 +370,7 @@ type_array *new_type_array (ident *name, int n_dimensions);
/* manipulate fields of type_array */
const char *get_array_name (type_array *array);
ident *get_array_ident (type_array *array);
ident *get_array_ident (type_array *array);
/*
void set_array_name (type_array *array, char *name);
void set_array_ident (type_array *array, ident* ident);
......@@ -412,7 +412,7 @@ type_enumeration *new_type_enumeration (ident *name /* , int n_enums */);
/* manipulate fields of type_enumeration */
const char *get_enumeration_name (type_enumeration *enumeration);
ident *get_enumeration_ident (type_enumeration *enumeration);
ident *get_enumeration_ident (type_enumeration *enumeration);
/*
void set_enumeration_name (type_enumeration *enumeration, char *name);
void set_enumeration_ident (type_enumeration *enumeration, ident* ident);
......
......@@ -77,7 +77,6 @@ void type_walk_2(type_or_ent *tore,
case k_type_class:
{
int i;
((type_class *)tore)->visit = type_visited;
//CS
for (i=0; i<get_class_n_member((type_class *)tore); i++)
......
......@@ -11,7 +11,8 @@ LIBS=-lfirm -lgmp
all: empty const_eval_example \
if_example if_else_example if_while_example cond_example \
call_str_example memory_example array-stack_example \
array-heap_example oo_program_example irr_cf_example \
array-heap_example oo_program_example inheritance_example \
irr_cf_example \
irr_loop_example dead_block_example global_var_example \
three_cfpred_example
......@@ -22,7 +23,8 @@ clean:
if_while_example cond_example \
call_str_example memory_example \
array-stack_example array-heap_example \
oo_program_example irr_cf_example \
oo_program_example inheritance_example \
irr_cf_example \
irr_loop_example dead_block_example \
global_var_example three_cfpred_example \
*.o *.vcg core
......@@ -41,6 +43,7 @@ run:
array-stack_example; \
array-heap_example; \
oo_program_example; \
inheritance_example; \
irr_cf_example; \
irr_loop_example; \
dead_block_example; \
......@@ -80,6 +83,9 @@ array-heap_example: array-heap_example.o
oo_program_example: oo_program_example.o
gcc -o oo_program_example oo_program_example.o $(LIBDIRS) $(LIBS)
inheritance_example: inheritance_example.o
gcc -o inheritance_example inheritance_example.o $(LIBDIRS) $(LIBS)
irr_cf_example: irr_cf_example.o
gcc -o irr_cf_example irr_cf_example.o $(LIBDIRS) $(LIBS)
......
/* Copyright (C) 2000 by Universitaet Karlsruhe
** All rights reserved.
**
** Author: Goetz Lindenmaier
**
** testprogram.
*/
#include <stdio.h>
# include "irdump.h"
# include "firm.h"
/**
*** This file constructs type information for the following pseudo-program:
***
*** interface I {
*** void m1 (void);
*** }
***
*** class C implements I {
*** void m1 (void) {return};
*** void m2 (int) {return 0};
*** }
***
*** class D {
*** int a;
*** }
***
*** class E extends C, D {
*** void m2 (int) {return 1};
*** int a;
*** }
***
**/
int main(int argc, char **argv)
{
ident *ii, *ci, *di, *ei, *m1i, *m2i, *inti, *ai; /* suffix i names identifiers */
type_class *it, *ct, *dt, *et; /* t names types */
type_method *m1t, *m2t;
type_primitive *intt;
entity *c_m1e, *c_m2e, *e_m2e, *d_ae, *e_ae; /* e names entities */
ir_node *x;
printf("\nCreating type information...\n");
/** init library */
init_firm ();
/** make idents for all used identifiers in the program. */
ii = id_from_str("i", strlen("i"));
ci = id_from_str("c", strlen("c"));
di = id_from_str("d", strlen("d"));
ei = id_from_str("e", strlen("e"));
m1i = id_from_str("m1", strlen("m1"));
m2i = id_from_str("m2", strlen("m2"));
inti= id_from_str("int",strlen("int"));
ai = id_from_str("a", strlen("a"));
/** make the type information needed */
/* Language defined types */
intt = new_type_primitive(inti, mode_I);
/* Program defined types */
it = new_type_class(ii);
ct = new_type_class(ci);
dt = new_type_class(di);
et = new_type_class(ei);
m1t = new_type_method(m1i, 0, 0); /* 0 parameters, 0 results */
m2t = new_type_method(m2i, 1, 0); /* 1 parameter, 0 results */
/** add structure to type graph **/
/* parameters of methods */
set_method_param_type(m2t, 0, (type *)intt);
/* inheritance */
add_class_subtype(it, ct);
add_class_subtype(ct, et);
add_class_subtype(dt, et);
add_class_supertype(ct, it);
add_class_supertype(et, ct);
add_class_supertype(et, dt);
/** make entities **/
c_m1e = new_entity((type *)ct, m1i, (type *)m1t);
c_m2e = new_entity((type *)ct, m2i, (type *)m2t);
e_m2e = new_entity((type *)et, m2i, (type *)m2t);
d_ae = new_entity((type *)dt, ai, (type *)intt);
e_ae = new_entity((type *)et, ai, (type *)intt);
printf("Done building the graph. Dumping it.\n");
dump_all_types();
printf("use xvcg to view this graph:\n");
printf("/ben/goetz/bin/xvcg GRAPHNAME\n\n");
return (0);
}
Supports Markdown
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