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

*** empty log message ***

[r48]
parent 0cc9b819
/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
** All rights reserved.
**
** Authors: Martin Trapp, Christian Schaefer
** Authors: Martin Trapp, Christian Schaefer, Goetz Lindenmaier.
**
** firm.h: Central FIRM header.
**
**
**
**
FIRM is a full graph based intermediate representation in SSA Form
with a novel concept to model side effects. It allows fast, aggressive
optimizations.
This header is the central header of the library implementation of this
IR.
The internal representation of a program in firm is separated into five
different modules:
- Firm Graphs representing the code of a program. (Subdirectory ir.)
Firm Graphs are assembled out of several data structures:
irprog: represents a program. Allows access to all types and all
FIRM graphs for procedures and other global things.
irgraph: represents a procedure. Allows access to the code of the
procedure, the actual FIRM graph.
irnode: A node of a FIRM graph. Nodes are typed with an opcode and a mode
and represent instructions in a program.
irop: The opcode of FIRM nodes.
irmode: The mode of FIRM nodes. Most modes correspond to machine known
data types (int, float, pointer).
- Entities representing program known objects. (Subdirectory tr.)
All variables and procedures are entities.
- Types describing the type system for the program. (Subdirectory tr.)
- Target Values representing program known constants. (Subdirectory tv.)
- Identifiers representing any Strings used in the program. (Subdirectory ident.)
Further this library supplies functionality to build and optimize FIRM graphs
and further functionality needed in a compiler. Finally there is more
generic functionality to support implementations using firm. (Code generation,
further optimizations).
ircons: Interface to construct firm graphs, implements automatic Phi node
construction.
iropt: Optimizations applied to individual nodes.
irgopt: Optimizations for ir graphs.
irflag: Flags to direct the functionality.
common: dynamic typ check for all nodes, configuration of the library,
debug: ???
irgwalk: walker for ir graphs.
irvrfy: verify the correctness of a firm node.
**
** firm.h: initialize the firm tree with all its components
*/
# ifndef _FIRM_H_
......
......@@ -98,8 +98,10 @@ dump_node_nodeattr (ir_node *n)
}
break;
case iro_Sel:
assert(n->attr.s.ent->kind == k_entity);
xfprintf (F, "%s", id_to_str(n->attr.s.ent->name));
/*assert(n->attr.s.ent->kind == k_entity);*/
assert(get_kind(get_Sel_entity(n)) == k_entity);
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); */
break;
......@@ -285,9 +287,11 @@ dump_ir_node (ir_node *n)
xfprintf (F, DEFAULT_NODE_ATTR);
break;
case iro_Sel:
assert(n->attr.s.ent->kind == k_entity);
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(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); */
xfprintf (F, DEFAULT_NODE_ATTR);
......
......@@ -55,7 +55,7 @@ new_ir_graph (entity *ent, int params)
/** Type inforamtion for the procedure of the graph **/
res->ent = ent;
ent->irg = res;
set_entity_irg(ent, res);
/** Nodes needed in every graph **/
res->end_block = new_Block ();
......
......@@ -12,6 +12,9 @@
# include "irvrfy.h"
# include "tv.h"
/* Make types visible to allow most efficient access */
# include "entity_t.h"
/* Trivial inlineable routine for copy propagation.
Does follow Ids, needed to optimize inlined code. */
static inline ir_node *
......
......@@ -30,7 +30,7 @@ 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
obst.h pset.h set.h tv.h xprintf.h xp_help.h entity_t.h
OFILES = $(MEMBERS:%.m=../objects/%.o)
......
......@@ -6,6 +6,7 @@
*/
# include <stdlib.h>
# include "entity_t.h"
# include "entity.h"
# include "mangle.h"
......@@ -23,7 +24,6 @@ init_entity (void)
/*******************************************************************/
entity *
// new_entity (type_class *owner, ident *name, type *type)
new_entity (type *owner, ident *name, type *type)
{
entity *res;
......@@ -45,38 +45,46 @@ new_entity (type *owner, ident *name, type *type)
return res;
}
/*
char *get_entity_name (entity *); */
#if 0
inline char *
get_entity_name (entity *ent) {
assert (ent);
return id_to_str(get_entity_ident(ent));
/* GL:
entity.c:52: warning: return discards `const' from pointer target type
-- ned so guud
*/
}
#endif
ident *
get_entity_ident (entity *ent) {
assert(ent);
return ent->name;
}
/*
void set_entity_ld_name (entity *, char *ld_name);
void set_entity_ld_ident (entity *, ident *ld_ident);
*/
//inline type_class *
inline type *
get_entity_owner (entity *entity) {
return entity->owner;
get_entity_owner (entity *ent) {
return ent->owner;
}
inline void
// set_entity_owner (entity *entity, type_class *owner) {
set_entity_owner (entity *entity, type *owner) {
set_entity_owner (entity *ent, type *owner) {
assert_legal_owner_of_ent(owner);
entity->owner = owner;
ent->owner = owner;
}
inline void /* should this go into type.c? */
assert_legal_owner_of_ent(type *type) {
assert (type->clss.kind == k_type_class ||
type->uni.kind == k_type_union ||
type->array.kind == k_type_array ||
type->method.kind == k_type_method );
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 );
}
inline ident *
......@@ -93,11 +101,26 @@ void set_entity_ld_ident (entity *, ident *ld_ident);
*/
inline type *
get_entity_type (entity *entity) {
return entity->type;
get_entity_type (entity *ent) {
return ent->type;
}
inline void
set_entity_type (entity *ent, type *type) {
ent->type = type;
}
inline ir_graph *
get_entity_irg(entity *ent) {
assert (ent);
assert (get_kind(ent->type) == k_type_method);
return ent->irg;
}
inline void
set_entity_type (entity *entity, type *type) {
entity->type = type;
set_entity_irg(entity *ent, ir_graph *irg) {
assert (ent && ent->type);
assert (irg);
assert (get_kind(ent->type) == k_type_method);
ent->irg = irg;
}
/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
** All rights reserved.
/*
** Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
** All rights reserved.
**
** Authors: Martin Trapp, Christian Schaefer,
** Goetz Lindenmaier
**
** entity.h: entities represent all program known objects.
**
** Authors: Martin Trapp, Christian Schaefer,
** Goetz Lindenmaier
** An entity is the representation of program known objects in Firm.
** The primary concept of entities is to represent members of complex
** types, i.e., fields and methods of classes. As not all programming
** language model all variables and methods as members of some class,
** the concept of entities is extended to cover also local and global
** variables, and arbitrary procedures.
**
** An entity always specifies the type of the object it represents and
** the type of the object it is a part of, the owner of the entity.
** Originally this is the type of the class of which the entity is a
** member.
** The owner of local variables is the procedure they are defined in.
** The owner of global variables and procedures visible in the whole
** program is a universally defined class type "GlobalType". The owner
** of procedures defined in the scope of an other procedure is the
** enclosing procedure.
**
** entity.h: declarations for entity
*/
# ifndef _ENTITY_H_
......@@ -30,56 +49,34 @@ void init_entity (void);
typedef struct ir_graph ir_graph;
#endif
struct entity {
firm_kind kind;
ident *name; /* name of this entity */
ident *ld_name; /* Unique name of this entity, i.e., the mangled
name. E.g., for a class `A' with field `a' this
is the ident for `A_a'. */
type *type; /* The type of this entity, e.g., a method type, a
basic type of the language or a class itself */
type *owner; /* The class this entity belongs to */
/* for methods */
ir_graph *irg; /* If (type == method_type) this is the corresponding irg.
The ir_graph constructor automatically sets this field.
@@@ Does this go here, or should it be in type_mehtod,
or should Call have an attribute ent?? */
/* Do we need to remember the initializer of fields? */
unsigned long visit; /* visited counter for walks of the type information */
};
#ifndef _ENTITY_TYPEDEF_
#define _ENTITY_TYPEDEF_
/* to resolve recursion between entity.h and irgraph.h */
typedef struct entity entity;
#endif
/* create a new entity */
entity *new_entity (type *owner, ident *name, type *type);
/* manipulate fields of entity */
char *get_entity_name (entity *);
ident *get_entity_ident (entity *);
char *get_entity_name (entity *ent);
ident *get_entity_ident (entity *ent);
ident *get_entity_ld_name (entity *);
ident *get_entity_ld_name (entity *ent);
/*
char *get_entity_ld_name (entity *);
ident *get_entity_ld_ident (entity *);
void set_entity_ld_name (entity *, char *ld_name);
void set_entity_ld_ident (entity *, ident *ld_ident);
char *get_entity_ld_name (entity *ent);
ident *get_entity_ld_ident (entity *ent);
void set_entity_ld_name (entity *ent, char *ld_name);
void set_entity_ld_ident (entity *ent, ident *ld_ident);
*/
type *get_entity_owner (entity *);
void set_entity_owner (entity *, type *);
inline void assert_legal_owner_of_ent(type *);
type *get_entity_owner (entity *ent);
void set_entity_owner (entity *ent, type *owner);
inline void assert_legal_owner_of_ent(type *owner);
type *get_entity_type (entity *);
void set_entity_type (entity *, type *);
type *get_entity_type (entity *ent);
void set_entity_type (entity *ent, type *type);
/* The entity knows the corresponding irg if the entity is a method.
This allows to get from a Call to the called irg. *
This allows to get from a Call to the called irg. */
ir_graph *get_entity_irg(entity *ent);
void set_entity_irg(entity *ent, ir_graph *irg);
*/
# endif /* _ENTITY_H_ */
/*
** Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
** All rights reserved.
**
** Authors: Martin Trapp, Christian Schaefer,
** Goetz Lindenmaier
**
** entity.h: entities represent all program known objects.
**
** An entity is the representation of program known objects in Firm.
** The primary concept of entities is to represent members of complex
** types, i.e., fields and methods of classes. As not all programming
** language model all variables and methods as members of some class,
** the concept of entities is extended to cover also local and global
** variables, and arbitrary procedures.
**
** An entity always specifies the type of the object it represents and
** the type of the object it is a part of, the owner of the entity.
** Originally this is the type of the class of which the entity is a
** member.
** The owner of local variables is the procedure they are defined in.
** The owner of global variables and procedures visible in the whole
** program is a universally defined class type "GlobalType". The owner
** of procedures defined in the scope of an other procedure is the
** enclosing procedure.
**
*/
# ifndef _ENTITY_T_H_
# define _ENTITY_T_H_
# include "ident.h"
# include "type.h"
#ifndef _IR_GRAPH_TYPEDEF_
#define _IR_GRAPH_TYPEDEF_
/* to resolve recursion between entity.h and irgraph.h */
typedef struct ir_graph ir_graph;
#endif
struct entity {
firm_kind kind;
ident *name; /* name of this entity */
ident *ld_name; /* Unique name of this entity, i.e., the mangled
name. E.g., for a class `A' with field `a' this
is the ident for `A_a'. */
type *type; /* The type of this entity, e.g., a method type, a
basic type of the language or a class itself */
type *owner; /* The class this entity belongs to. In case of local variables
the method they are defined in. */
/* for methods */
ir_graph *irg; /* If (type == method_type) this is the corresponding irg.
The ir_graph constructor automatically sets this field.
@@@ Does this go here, or should it be in type_method,
or should Call have an attribute ent?? */
/* Do we need to remember the initializer of fields? */
unsigned long visit; /* visited counter for walks of the type information */
};
# endif /* _ENTITY_T_H_ */
......@@ -11,6 +11,9 @@
# include "entity.h"
# include <stdlib.h>
/* Make types visible to allow most efficient access */
# include "entity_t.h"
static struct obstack mangle_obst;
ident *
......
......@@ -14,6 +14,9 @@
#include "irnode.h"
#include "type_or_entity.h"
/* Make types visible to allow most efficient access */
# include "entity_t.h"
typedef struct type_walk_env {
void *pre;
void *post;
......
......@@ -43,6 +43,8 @@
#include "ident.h"
#include "tv.h"
# include "entity_t.h"
static struct obstack tv_obst; /* obstack for all the target values */
static pset *tarvals; /* pset containing pointers to _all_ tarvals */
......
......@@ -25,6 +25,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 *method; /* the type of this method */
entity *ent; /* represents this method as entity of owner */
ir_node *x, *x_then, *arg1, *c2, *c10, *cmpGt, *cmpLt, *and, *f, *t, *b;
......@@ -43,7 +44,8 @@ int main(int argc, char **argv)
#define ENTITYNAME "main"
owner = new_type_class (id_from_str (CLASSNAME, strlen(CLASSNAME)));
ent = new_entity ((type *)owner, id_from_str (ENTITYNAME, strlen(ENTITYNAME)), NULL);
method = new_type_method (id_from_str("main", 4), 0, 2);
ent = new_entity ((type *)owner, id_from_str (ENTITYNAME, strlen(ENTITYNAME)), (type *)method);
/* Generates the basic graph for the method represented by entity ent, that
......
......@@ -27,22 +27,22 @@ main(void)
{
ir_graph *irg;
type_class *owner;
type_method *method;
entity *ent;
ir_node *a, *b, *c, *d, *x;
printf("creating an IR graph: CONST_EVAL_EXAMPLE...\n");
init_firm ();
/* Try both optimizations: */
set_opt_constant_folding(1);
set_opt_cse(1);
set_opt_dead_node_elimination (0);
owner = new_type_class (id_from_str ("CONST_EVAL_EXAMPLE", 18));
ent = new_entity ((type *)owner, id_from_str ("main", 4), NULL);
method = new_type_method (id_from_str("main", 4), 0, 2);
ent = new_entity ((type *)owner, id_from_str ("main", 4), (type *)method);
irg = new_ir_graph (ent, 4);
......
......@@ -34,6 +34,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 *method; /* the type of this method */
entity *ent; /* represents this method as entity of owner */
ir_node *x, *x_then, *x_else, *c0, *c1, *c2, *cmpGt, *f, *t, *b;
......@@ -52,7 +53,8 @@ int main(int argc, char **argv)
#define ENTITYNAME "main"
owner = new_type_class (id_from_str (CLASSNAME, strlen(CLASSNAME)));
ent = new_entity ((type *)owner, id_from_str (ENTITYNAME, strlen(ENTITYNAME)), NULL);
method = new_type_method (id_from_str("main", 4), 0, 2);
ent = new_entity ((type *)owner, id_from_str (ENTITYNAME, strlen(ENTITYNAME)), (type *)method);
/* Generates the basic graph for the method represented by entity ent, that
......
......@@ -54,6 +54,7 @@ main(void)
{
ir_graph *irg;
type_class *owner;
type_method *method; /* the type of this method */
entity *ent;
ir_node *a, *b, *x, *y, *r;
......@@ -63,7 +64,8 @@ main(void)
/* a class to get started with, containing the main procedure */
owner = new_type_class (id_from_str ("MEMORY_EXAMPLE", 14));
ent = new_entity ((type *)owner, id_from_str ("main", 4), NULL);
method = new_type_method (id_from_str("main", 4), 0, 2);
ent = new_entity ((type *)owner, id_from_str ("main", 4), (type *)method);
/* Generates start and end blocks and nodes and a first, initial block */
irg = new_ir_graph (ent, 4);
......
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