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

*** empty log message ***

[r24]
parent 83afa91b
5.7.2000 Goetz
Fixed a bug in irop: Size of Sel node was (entity *) instead of
sel_attr. Therefor array_heap_example aborted.
Also found a missing break in typewalk, case iro_Alloc.
5.7.2000 Goetz
Added a construct that unifies all things constructed by the lib
and needed to represent a program: irprog.ch
This contains a list of all types as well as a list of all ir graphs.
I added calls to initialization and constructors so that this is constructed
automatically. I changed firm.c, type.c, irgraph.c and ev. more.
5.7.2000 Goetz
Removed strange block struct and constructor from ircons.c.
Moved routines for automatic Phi construction from irgmod to ircons.
......
......@@ -30,7 +30,7 @@ CFILES += xfprintf.c xfprintf.c xfprintf.c
HFILES = $(MEMBERS:.m=.h)
HFILES += tune.h xp_help.h xprintf.h misc.h
HFILES += common.h debug.h entity.h gmp.h host.h ident.h irgraph.h \
irmode.h irnode.h irop.h label.h misc.h obst.h pset.h set.h \
irmode.h irnode.h irop.h irprog.h label.h misc.h obst.h pset.h set.h \
tv.h type.h xprintf.h xp_help.h
OFILES = $(MEMBERS:%.m=../objects/%.o)
......
......@@ -34,4 +34,7 @@ init_firm (void)
init_op ();
/* called once for each run of this library, empty at this moment!!! */
init_cons ();
/* Builds a construct allowing to access all information to be constructed
later. */
init_irprog ();
}
......@@ -12,8 +12,8 @@
# include "entity.h"
# include "ircons.h"
# include "irprog.h"
# include "type.h"
# include "iropt.h"
# include "xprintf.h"
......
......@@ -23,7 +23,7 @@ SHELL = /bin/sh
MAKE = /usr/bin/make
MEMBERS = ircons.m irdump.m irflag.m irgmod.m irgraph.m irgopt.m \
irgwalk.m irmode.m irnode.m irop.m iropt.m irvrfy.m
irgwalk.m irmode.m irnode.m irop.m iropt.m irprog.m irvrfy.m
CFILES = $(MEMBERS:.m=.c)
......
......@@ -262,6 +262,7 @@ void dump_node2type_edges (ir_node *n, void *env)
NODE2TYPE_EDGE_ATTR "}\n", n, get_Alloc_type(n));
break;
case iro_Free:
printf(" in irdum\n");
xfprintf (F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
NODE2TYPE_EDGE_ATTR "}\n", n, get_Free_type(n));
break;
......
......@@ -31,5 +31,7 @@ void dump_cfg (ir_graph *irg);
/* dumps the type information reachable from an ir graph. */
void dump_type_graph (ir_graph *irg);
/* dumps a graph and the type inforamtion. */
void dump_ir_graph_w_types (ir_graph *irg);
# endif /* _IRDUMP_H_ */
......@@ -8,6 +8,7 @@
# include "ircons.h"
# include "irgraph.h"
# include "irprog.h"
# include "iropt.h"
# include "array.h"
# include "irgmod.h"
......@@ -36,6 +37,7 @@ new_ir_graph (entity *ent, int params)
res = (ir_graph *) malloc (sizeof (ir_graph));
current_ir_graph = res;
add_irp_irg(res); /* remember this graph global. */
/** Internal information for graph construction either held in the graph or
*** initialized for each graph. **/
......@@ -47,7 +49,6 @@ new_ir_graph (entity *ent, int params)
res->Phi_in_stack = new_Phi_in_stack(); /* A stack needed for automatic Phi
generation */
#endif
//???!! turn the Phi_in_stack into a field of ir_graph??
res->obst = (struct obstack *) xmalloc (sizeof (struct obstack));
obstack_init (res->obst);
res->value_table = new_identities (); /* Symbol table for local variables
......@@ -159,6 +160,21 @@ set_frame_of_irgraph(ir_graph *irg, ir_node *node)
irg->frame = node;
}
ir_node *
get_irg_globals (ir_graph *irg)
{
return irg->globals;
}
void
set_irg_globals (ir_graph *irg, ir_node *node)
{
irg->globals = node;
}
ir_node *
get_args_of_irgraph (ir_graph *irg)
{
......
......@@ -81,10 +81,10 @@ void set_cstore_of_irgraph (ir_graph *irg, ir_node *node);
ir_node *get_frame_of_irgraph (ir_graph *irg);
void set_frame_of_irgraph (ir_graph *irg, ir_node *node);
/*
ir_node *get_irg_globals (ir_graph *irg);
void set_irg_globals (ir_graph *irg, ir_node *node);
*/
ir_node *get_args_of_irgraph (ir_graph *irg);
void set_args_of_irgraph (ir_graph *irg, ir_node *node);
......
......@@ -144,8 +144,7 @@ ir_node_print (XP_PAR1, const xprintf_info *info ATTRIBUTE((unused)), XP_PARN)
inline int
get_irn_arity (ir_node *node)
{
// printf("called for node %s\n", ID_TO_STR(node->op->name));
// if (get_irn_opcode(node) == iro_Block) return (ARR_LEN((node)->in));
assert(node);
return (ARR_LEN((node)->in)-1);
}
......@@ -160,8 +159,7 @@ get_irn_in (ir_node *node)
/* to iterate through the predecessors without touching the array */
/* To iterate over the operands iterate from 0 to i < get_irn_arity(),
to iterate includind the Block predecessor iterate from i = -1 to
i < get_irn_arity.
Don't know how to iterate if it is a block ?? */
i < get_irn_arity. */
inline ir_node *
get_irn_n (ir_node *node, int n)
{
......@@ -553,14 +551,14 @@ set_Sel_entity (ir_node *node, entity *ent) {
node->attr.s.ent = ent;
}
inline linkage_type *
inline linkage_type
get_Sel_linkage_type (ir_node *node) {
assert (node->op == op_Sel);
return node->attr.s.ltyp;
}
inline void
set_Sel_linkage_type (ir_node *node, linkage_type *lt) {
set_Sel_linkage_type (ir_node *node, linkage_type lt) {
assert (node->op == op_Sel);
node->attr.s.ltyp = lt;
}
......
......@@ -101,7 +101,7 @@ typedef enum {
typedef struct {
entity *ent; /* entity to select */
linkage_type *ltyp; /* linkage type of the entity */
linkage_type ltyp; /* linkage type of the entity */
} sel_attr;
/* Alloc attributes */
......@@ -265,8 +265,8 @@ inline ir_node *get_Sel_index (ir_node *node, int pos);
inline void set_Sel_index (ir_node *node, int pos, ir_node *index);
inline entity *get_Sel_entity (ir_node *node); /* entity to select */
inline void set_Sel_entity (ir_node *node, entity *ent);
inline linkage_type *get_Sel_linkage_type (ir_node *node);
inline void set_Sel_linkage_type (ir_node *node, linkage_type *lt);
inline linkage_type get_Sel_linkage_type (ir_node *node);
inline void set_Sel_linkage_type (ir_node *node, linkage_type lt);
inline ir_node *get_Call_mem (ir_node *node);
inline void set_Call_mem (ir_node *node, ir_node *mem);
......
......@@ -89,7 +89,7 @@ init_op(void)
op_SymConst = new_ir_op (iro_SymConst, id_from_str ("SymConst", 8),
sizeof (symconst_attr), 0);
op_Sel = new_ir_op (iro_Sel, id_from_str ("Sel", 3), sizeof (entity *), 1);
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_Add = new_ir_op (iro_Add, id_from_str ("Add", 3), 0, 0);
......
/* Copyright (C) 2000 by Universitaet Karlsruhe
** All rights reserved.
**
** Authors: Goetz Lindenmaier
**
** irprog.c: ir representation of a program
*/
# include "irprog.h"
# include "array.h"
#define GLOBAL_TYPE_NAME "GlobalType"
/* initializes ir_prog. Calles the constructor for an ir_prog. */
void init_irprog(void) {
new_ir_prog ();
}
/* Create a new ir prog. Automatically called by init_firm through init_irprog. */
ir_prog *new_ir_prog (void) {
ir_prog *res;
res = (ir_prog *) malloc (sizeof(ir_prog));
irp = res;
/* res->obst = (struct obstack *) xmalloc (sizeof (struct obstack)); */
res->graphs = NEW_ARR_F (ir_graph *, 1);
res->types = NEW_ARR_F (type *, 1);
res->glob_type = new_type_class(id_from_str (GLOBAL_TYPE_NAME,
strlen(GLOBAL_TYPE_NAME)));
add_irp_type((type *)res->glob_type);
return res;
}
/** Functions to access the fields of ir_prog **/
type_class *get_glob_type(void) {
assert(irp);
return irp->glob_type;
}
/* Adds irg to the list of ir graphs in irp. */
void add_irp_irg(ir_graph *irg) {
assert (irg != NULL);
assert(irp);
ARR_APP1 (ir_graph *, irp->graphs, irg);
}
/* Adds type to the list of types in irp. */
void add_irp_type(type *typ) {
assert (typ != NULL);
assert(irp);
ARR_APP1 (type *, irp->types, typ);
}
/* Copyright (C) 2000 by Universitaet Karlsruhe
** All rights reserved.
**
** Authors: Goetz Lindenmaier
**
** irprog.h: ir representation of a program
**
** This file defines a construct that keeps all information about a
** program:
** - A list of all procedures.
** - A list of all types.
** - A global type that can be thought of as a god-class containing all
** global variables and procedures. This is not the base class of
** all classes in a class hierarchy (as, e.g., "object" in java).
** - An obstack containing global things, e.g., the above mentioned lists.
*/
# ifndef _IRPROG_H_
# define _IRPROG_H_
# include "irnode.h"
# include "type.h"
/*# include "obst.h"*/
typedef struct ir_prog {
firm_kind kind;
ir_graph **graphs; /* all graphs in the ir */
type **types; /* all types in the ir */
type_class *glob_type; /* global type. Class as it can have
fields and procedures. Does this work?
Better name??? @@@ */
/*struct obstack *obst; * @@@ Should we place all types and entities themselves
on an obstack, too? */
} ir_prog;
/* A variable from where everything in the ir can be accessed. */
ir_prog *irp;
/* initializes ir_prog. Calles the constructor for an ir_prog. */
void init_irprog(void);
/* Creates a new ir_prog, returns it and sets irp with it.
Automatically called by init_firm through init_prog. */
ir_prog *new_ir_prog (void);
/** Functions to access the fields of ir_prog **/
type_class *get_glob_type(void);
/* Adds irg to the list of ir graphs in irp. */
void add_irp_irg(ir_graph *irg);
/* Adds type to the list of types in irp. */
void add_irp_type(type *typ);
#endif /* ifndef _IRPROG_H_ */
......@@ -8,6 +8,8 @@
*/
# include "type.h"
# include "irprog.h" /* So that constructors can add the type to global
data structure. */
unsigned long type_visited = 0;
......@@ -26,6 +28,7 @@ new_type_class (ident *name)//, int members)
type_class *res;
res = (type_class *) xmalloc (sizeof (type_class));
add_irp_type((type *) res); /* Remember the new type global. */
res->kind = k_type_class;
res->name = name;
......@@ -69,6 +72,7 @@ new_type_strct (ident *name)//, int members)
type_strct *res;
res = (type_strct *) xmalloc (sizeof (type_strct));
add_irp_type((type *) res); /* Remember the new type global. */
res->kind = k_type_strct;
res->name = name;
......@@ -113,6 +117,7 @@ new_type_method (ident *name, int arity, int n_res)
type_method *res;
res = (type_method *) xmalloc (sizeof (type_method));
add_irp_type((type *) res); /* Remember the new type global. */
res->kind = k_type_method;
res->name = name; // do I need the name, or is the name in entity sufficient?
res->arity = arity;
......@@ -203,6 +208,7 @@ new_type_union (ident *name, int n_types)
type_union *res;
res = (type_union *) xmalloc (sizeof (type_union));
add_irp_type((type *) res); /* Remember the new type global. */
res->kind = k_type_union;
res->name = name; // do I need a name?
res->n_types = n_types;
......@@ -252,6 +258,7 @@ new_type_array (ident *name, int n_dimensions)
type_array *res;
res = (type_array *) xmalloc (sizeof (type_array));
add_irp_type((type *) res); /* Remember the new type global. */
res->kind = k_type_array;
res->name = name;
res->n_dimensions = n_dimensions;
......@@ -341,6 +348,7 @@ new_type_enumeration (ident *name /* , int n_enums */)
type_enumeration *res;
res = (type_enumeration *) xmalloc (sizeof (type_enumeration));
add_irp_type((type *) res); /* Remember the new type global. */
res->kind = k_type_enumeration;
res->name = name;
/*
......@@ -392,6 +400,7 @@ new_type_pointer (ident *name, type *points_to)
type_pointer *res;
res = (type_pointer *) xmalloc (sizeof (type_pointer));
add_irp_type((type *) res); /* Remember the new type global. */
res->kind = k_type_pointer;
res->name = name;
res->points_to = points_to;
......@@ -443,6 +452,7 @@ new_type_primitive (ident *name, ir_mode *mode)
type_primitive *res;
res = (type_primitive *) xmalloc (sizeof (type_primitive));
add_irp_type((type *) res); /* Remember the new type global. */
res->kind = k_type_primitive;
res->name = name;
res->mode = mode;
......
......@@ -42,8 +42,8 @@ type_class *new_type_class (ident *name);
char *get_class_name (type_class *clss);
ident *get_class_ident (type_class *clss);
/*
void set_class_name (type_class *class, char *name);
void set_class_ident (type_class *class, ident* ident);
void set_class_name (type_class *clss, char *name);
void set_class_ident (type_class *clss, ident* ident);
*/
/*******************************************************************/
......
......@@ -139,7 +139,9 @@ void start_type_walk(ir_node *node, void *env) {
break;
case iro_Alloc:
type_walk_2((type_or_ent *)get_Alloc_type(node), pre, post, envi);
break;
case iro_Free:
printf("here in typewalk\n");
type_walk_2((type_or_ent *)get_Free_type(node), pre, post, envi);
break;
assert(node);
......
......@@ -12,7 +12,7 @@ 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 \
irr_loop_example dead_block_example
irr_loop_example dead_block_example global_var_example
clean:
rm -f \
......@@ -30,7 +30,7 @@ clean:
irr_cf_example.o irr_cf_example \
irr_loop_example.o irr_loop_example \
dead_block_example.o dead_block_example \
*.vcg core
global_var_example *.vcg core
realclean: clean
......@@ -48,7 +48,8 @@ run:
oo_program_example; \
irr_cf_example; \
irr_loop_example; \
dead_block_example;
dead_block_example; \
global_var_example;
empty: empty.o
gcc -o empty empty.o $(LIBDIRS) $(LIBS)
......@@ -91,3 +92,6 @@ irr_loop_example: irr_loop_example.o
dead_block_example: dead_block_example.o
gcc -o dead_block_example dead_block_example.o $(LIBDIRS) $(LIBS)
global_var_example: global_var_example.o
gcc -o global_var_example global_var_example.o $(LIBDIRS) $(LIBS)
......@@ -43,7 +43,7 @@
int
main(void)
{
/* describes the fake class "ARRAY-HEAP_EXAMPLE" with it's method main */
/* describes the method main */
type_class *owner;
type_method *proc_main;
entity *proc_main_e;
......@@ -65,7 +65,6 @@ main(void)
ir_graph *main_irg;
ir_node *array, *array_ptr, *c3, *elt, *val, *x;
init_firm ();
/* make basic type information for primitive type int.
......@@ -78,7 +77,7 @@ main(void)
printf("creating an IR graph: ARRAY-HEAP_EXAMPLE...\n");
/* first build procedure main */
owner = new_type_class (id_from_str ("ARRAY-HEAP_EXAMPLE", 13));
owner = get_glob_type();
proc_main = new_type_method(id_from_str("main", 4), 0, 1);
set_method_res_type(proc_main, 0, (type *)prim_t_int);
proc_main_e = new_entity ((type*)owner, id_from_str ("main", 4), (type *)proc_main);
......@@ -92,9 +91,10 @@ main(void)
set_array_bounds(array_type, 1, L_BOUND, U_BOUND);
set_array_element_type(array_type, (union type*)prim_t_int);
/* As the array is accessed by Sel nodes, we need information about
the entity the node select. Entities of an array are it's elements
the entity the node selects. Entities of an array are it's elements
which are, in this case, integers. */
array_ent = new_entity((type*)array_type, id_from_str("array_field", 11), (type*)prim_t_int);
array_ent = new_entity((type*)array_type, id_from_str("array_field", 11),
(type*)prim_t_int);
/* Allocate the array. All program known variables that
are not modeled by dataflow edges need an explicit allocate node.
......
......@@ -27,7 +27,7 @@ int main(int argc, char **argv)
{
ir_graph *irg; /* this variable contains the irgraph */
type_class *owner; /* the class in which this method is defined */
type_method *proc_main; /* typeinformation for the method main */
type_method *proc_main; /* type information for the method main */
entity *ent; /* represents this method as entity of owner */
ir_node *x;
......@@ -39,15 +39,15 @@ int main(int argc, char **argv)
/* FIRM was designed for oo languages where all methods belong to a class.
* For imperative languages like C we view a file as a large class containing
* all functions as methods in this file.
* Therefore we define a class "empty" according to the file name
* with a method main as an entity.
* (Therefore we define a class "empty" according to the file name
* with a method main as an entity.)
* This class now is automatically generated.
*/
#define CLASSNAME "EMPTY"
#define METHODNAME "main"
#define NRARGS 0
#define NRES 0
owner = new_type_class (id_from_str (CLASSNAME, strlen(CLASSNAME)));
owner = get_glob_type();
proc_main = new_type_method(id_from_str(METHODNAME, strlen(METHODNAME)),
NRARGS, NRES);
ent = new_entity ((type *)owner,
......@@ -86,7 +86,7 @@ int main(int argc, char **argv)
dump_ir_block_graph (irg);
printf("use xvcg to view this graph:\n");
printf("/ben/trapp/bin/i486/xvcg GRAPHNAME\n");
printf("/ben/goetz/bin/xvcg GRAPHNAME\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