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

added Cast node.

The Cast node remarks source language casts.

[r1676]
parent df4842b7
......@@ -23,7 +23,7 @@ SOURCES := Makefile.in MakeRules.in MakeTargets\
config.guess config.sub configure.in \
stamp-h.in install-sh README configure
INSTALL_LIBS = libfirm.a
INSTALL_LIBS = libfirm.a libfirm.so
GENFILES := stamp-h config.log config.cache
# config.status config.h.in $(srcdir)/stamp-h.in
......@@ -35,15 +35,18 @@ XOFILES += $(addsuffix /subdir.o, $(subdirs))
include $(top_srcdir)/MakeTargets
# add target firmjni if configured with --enable-firmjni
all: config.h Makefile libfirm.a
all: firm
firm: config.h Makefile libfirm.a
firm: config.h Makefile libfirm.a libfirm.so
libfirm.a: subdir_all $(XOFILES) $(OFILES)
$(AR) $(ARFLAGS) $@.new $(XOFILES) $(OFILES)
$(RANLIB) $@.new
mv -f $@.new $@
libfirm.so: subdir_all $(XOFILES) $(OFILES)
ld -Bshareable -o ./libfirm.so $(XOFILES) -lm
testprograms: libfirm.a
$(MAKE) -C testprograms
......
......@@ -189,7 +189,17 @@ new_rd_Conv (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *op, ir_mode *
res = optimize_node (res);
irn_vrfy_irg (res, irg);
return res;
}
INLINE ir_node *
new_rd_Cast (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *op, type *to_tp)
{
ir_node *res;
res = new_ir_node (db, irg, block, op_Cast, get_irn_mode(op), 1, &op);
res->attr.cast.totype = to_tp;
res = optimize_node (res);
irn_vrfy_irg (res, irg);
return res;
}
INLINE ir_node *
......@@ -889,6 +899,9 @@ INLINE ir_node *new_r_Conv (ir_graph *irg, ir_node *block,
ir_node *op, ir_mode *mode) {
return new_rd_Conv(NULL, irg, block, op, mode);
}
INLINE ir_node *new_r_Cast (ir_graph *irg, ir_node *block, ir_node *op, type *to_tp) {
return new_rd_Cast(NULL, irg, block, op, to_tp);
}
INLINE ir_node *new_r_Phi (ir_graph *irg, ir_node *block, int arity,
ir_node **in, ir_mode *mode) {
return new_rd_Phi(NULL, irg, block, arity, in, mode);
......@@ -1792,6 +1805,12 @@ new_d_Conv (dbg_info* db, ir_node *op, ir_mode *mode)
op, mode);
}
ir_node *
new_d_Cast (dbg_info* db, ir_node *op, type *to_tp)
{
return new_rd_Cast (db, current_ir_graph, current_ir_graph->current_block, op, to_tp);
}
ir_node *
new_d_Tuple (dbg_info* db, int arity, ir_node **in)
{
......@@ -2380,6 +2399,9 @@ ir_node *new_Cmp (ir_node *op1, ir_node *op2) {
ir_node *new_Conv (ir_node *op, ir_mode *mode) {
return new_d_Conv(NULL, op, mode);
}
ir_node *new_Cast (ir_node *op, type *to_tp) {
return new_d_Cast(NULL, op, to_tp);
}
ir_node *new_Phi (int arity, ir_node **in, ir_mode *mode) {
return new_d_Phi(NULL, arity, in, mode);
}
......
......@@ -342,6 +342,7 @@
* ir_node *new_Rot (ir_node *op, ir_node *k, ir_mode *mode);
* ir_node *new_Cmp (ir_node *op1, ir_node *op2);
* ir_node *new_Conv (ir_node *op, ir_mode *mode);
* ir_node *new_Cast (ir_node *op, type *to_tp);
* ir_node *new_Load (ir_node *store, ir_node *addr);
* ir_node *new_Store (ir_node *store, ir_node *addr, ir_node *val);
* ir_node *new_Alloc (ir_node *store, ir_node *size, type *alloc_type,
......@@ -1146,6 +1147,8 @@ ir_node *new_rd_Rot (dbg_info *db, ir_graph *irg, ir_node *block,
ir_node *op, ir_node *k, ir_mode *mode);
ir_node *new_rd_Conv (dbg_info *db, ir_graph *irg, ir_node *block,
ir_node *op, ir_mode *mode);
ir_node *new_rd_Cast (dbg_info* db, ir_graph *irg, ir_node *block,
ir_node *op, type *to_tp);
ir_node *new_rd_Phi (dbg_info *db, ir_graph *irg, ir_node *block, int arity,
ir_node *in[], ir_mode *mode);
ir_node *new_rd_Load (dbg_info *db, ir_graph *irg, ir_node *block,
......@@ -1238,6 +1241,8 @@ ir_node *new_r_Rot (ir_graph *irg, ir_node *block,
ir_node *op, ir_node *k, ir_mode *mode);
ir_node *new_r_Conv (ir_graph *irg, ir_node *block,
ir_node *op, ir_mode *mode);
ir_node *new_r_Cast (ir_graph *irg, ir_node *block,
ir_node *op, type *to_tp);
ir_node *new_r_Phi (ir_graph *irg, ir_node *block, int arity,
ir_node *in[], ir_mode *mode);
ir_node *new_r_Load (ir_graph *irg, ir_node *block,
......@@ -1312,6 +1317,7 @@ ir_node *new_d_Shrs (dbg_info* db, ir_node *op, ir_node *k, ir_mode *mode);
ir_node *new_d_Rot (dbg_info* db, ir_node *op, ir_node *k, ir_mode *mode);
ir_node *new_d_Cmp (dbg_info* db, ir_node *op1, ir_node *op2);
ir_node *new_d_Conv (dbg_info* db, ir_node *op, ir_mode *mode);
ir_node *new_d_Cast (dbg_info* db, ir_node *op, type *to_tp);
ir_node *new_d_Phi (dbg_info* db, int arity, ir_node *in[], ir_mode *mode);
ir_node *new_d_Load (dbg_info* db, ir_node *store, ir_node *addr);
ir_node *new_d_Store (dbg_info* db, ir_node *store, ir_node *addr, ir_node *val);
......@@ -1380,6 +1386,7 @@ ir_node *new_Shrs (ir_node *op, ir_node *k, ir_mode *mode);
ir_node *new_Rot (ir_node *op, ir_node *k, ir_mode *mode);
ir_node *new_Cmp (ir_node *op1, ir_node *op2);
ir_node *new_Conv (ir_node *op, ir_mode *mode);
ir_node *new_Cast (ir_node *op, type *to_tp);
ir_node *new_Phi (int arity, ir_node *in[], ir_mode *mode);
ir_node *new_Load (ir_node *store, ir_node *addr);
ir_node *new_Store (ir_node *store, ir_node *addr, ir_node *val);
......
......@@ -221,7 +221,10 @@ dump_node_nodeattr (ir_node *n)
break;
case iro_Sel: {
assert(get_kind(get_Sel_entity(n)) == k_entity);
fprintf (F, "%s", id_to_str(get_entity_ident(get_Sel_entity(n))));
fprintf (F, "%s", get_entity_name(get_Sel_entity(n)));
} break;
case iro_Cast: {
fprintf (F, "to %s", get_type_name(get_Cast_type(n)));
} break;
default:
;
......@@ -539,21 +542,24 @@ static void dump_node2type_edges (ir_node *n, void *env)
case iro_SymConst:
if ( (get_SymConst_kind(n) == type_tag)
|| (get_SymConst_kind(n) == size))
{
PRINT_NODE_TYPE_EDGE(n,get_SymConst_type(n),NODE2TYPE_EDGE_ATTR);
}
{
PRINT_NODE_TYPE_EDGE(n,get_SymConst_type(n),NODE2TYPE_EDGE_ATTR);
}
break;
case iro_Sel: {
PRINT_NODE_ENT_EDGE(n,get_Sel_entity(n),NODE2TYPE_EDGE_ATTR);
PRINT_NODE_ENT_EDGE(n,get_Sel_entity(n),NODE2TYPE_EDGE_ATTR);
} break;
case iro_Call: {
PRINT_NODE_TYPE_EDGE(n,get_Call_type(n),NODE2TYPE_EDGE_ATTR);
PRINT_NODE_TYPE_EDGE(n,get_Call_type(n),NODE2TYPE_EDGE_ATTR);
} break;
case iro_Alloc: {
PRINT_NODE_TYPE_EDGE(n,get_Alloc_type(n),NODE2TYPE_EDGE_ATTR);
PRINT_NODE_TYPE_EDGE(n,get_Alloc_type(n),NODE2TYPE_EDGE_ATTR);
} break;
case iro_Free: {
PRINT_NODE_TYPE_EDGE(n,get_Free_type(n),NODE2TYPE_EDGE_ATTR);
PRINT_NODE_TYPE_EDGE(n,get_Free_type(n),NODE2TYPE_EDGE_ATTR);
} break;
case iro_Cast: {
PRINT_NODE_TYPE_EDGE(n,get_Cast_type(n),NODE2TYPE_EDGE_ATTR);
} break;
default:
break;
......
......@@ -976,7 +976,7 @@ set_InstOf_obj (ir_node *node, ir_node *obj) {
/* For unary and binary arithmetic operations the access to the
operands can be factored out. Left is the first, right the
second arithmetic value as listed in tech report 0999-33.
unops are: Minus, Abs, Not, Conv
unops are: Minus, Abs, Not, Conv, Cast
binops are: Add, Sub, Mul, Quot, DivMod, Div, Mod, And, Or, Eor, Shl,
Shr, Shrs, Rotate, Cmp */
......@@ -1558,44 +1558,63 @@ set_Conv_op (ir_node *node, ir_node *op) {
set_irn_n(node, 0, op);
}
INLINE ir_node *
get_Cast_op (ir_node *node) {
assert (node->op == op_Cast);
return get_irn_n(node, 0);
}
INLINE void
set_Cast_op (ir_node *node, ir_node *op) {
assert (node->op == op_Cast);
set_irn_n(node, 0, op);
}
INLINE type *
get_Cast_type (ir_node *node) {
assert (node->op == op_Cast);
return node->attr.cast.totype;
}
int
INLINE void
set_Cast_type (ir_node *node, type *to_tp) {
assert (node->op == op_Cast);
node->attr.cast.totype = to_tp;
}
INLINE int
is_unop (ir_node *node) {
return ( node->op == op_Minus ||
node->op == op_Abs ||
node->op == op_Not ||
node->op == op_Conv );
node->op == op_Conv ||
node->op == op_Cast );
}
INLINE ir_node *
get_unop_op (ir_node *node) {
assert ( node->op == op_Minus ||
node->op == op_Abs ||
node->op == op_Not ||
node->op == op_Conv );
assert (is_unop(node));
switch (get_irn_opcode (node)) {
case iro_Minus: return get_Minus_op(node); break;
case iro_Abs: return get_Abs_op(node); break;
case iro_Not: return get_Not_op(node); break;
case iro_Conv: return get_Conv_op(node); break;
case iro_Cast: return get_Cast_op(node); break;
default: return NULL;
}
}
INLINE void
set_unop_op (ir_node *node, ir_node *op) {
assert (node->op == op_Minus ||
node->op == op_Abs ||
node->op == op_Not ||
node->op == op_Conv );
switch (get_irn_opcode (node)) {
assert (is_unop(node));
switch (get_irn_opcode (node)) {
case iro_Minus: set_Minus_op(node, op); break;
case iro_Abs: set_Abs_op(node, op); break;
case iro_Not: set_Not_op(node, op); break;
case iro_Conv: set_Conv_op(node, op); break;
case iro_Cast: set_Cast_op(node, op); break;
default: ;
}
}
}
......
......@@ -353,7 +353,7 @@ void set_CallBegin_call (ir_node *node, ir_node *call);
/* For unary and binary arithmetic operations the access to the
operands can be factored out. Left is the first, right the
second arithmetic value as listed in tech report 1999-44.
unops are: Minus, Abs, Not, Conv
unops are: Minus, Abs, Not, Conv, Cast
binops are: Add, Sub, Mul, Quot, DivMod, Div, Mod, And, Or, Eor, Shl,
Shr, Shrs, Rot, Cmp */
INLINE int is_unop (ir_node *node);
......@@ -463,6 +463,11 @@ INLINE void set_Rot_right (ir_node *node, ir_node *right);
INLINE ir_node *get_Conv_op (ir_node *node);
INLINE void set_Conv_op (ir_node *node, ir_node *op);
INLINE ir_node *get_Cast_op (ir_node *node);
INLINE void set_Cast_op (ir_node *node, ir_node *op);
INLINE type *get_Cast_type (ir_node *node);
INLINE void set_Cast_type (ir_node *node, type *to_tp);
INLINE ir_node **get_Phi_preds_arr (ir_node *node);
INLINE int get_Phi_n_preds (ir_node *node);
INLINE ir_node *get_Phi_pred (ir_node *node, int pos);
......
......@@ -120,6 +120,11 @@ typedef struct {
ir_node * call; /**< associated Call-operation */
} callbegin_attr;
/** Cast attributes */
typedef struct {
type *totype;
} cast_attr;
/** Some irnodes just have one attribute, these are stored here,
some have more. Their name is 'irnodename_attr' */
typedef union {
......@@ -133,6 +138,7 @@ typedef union {
alloc_attr a; /**< For Alloc. */
io_attr io; /**< For InstOf */
type *f; /**< For Free. */
cast_attr cast; /**< For Cast. */
int phi0_pos; /**< For Phi. Used to remember the value defined by
this Phi node. Needed when the Phi is completed
to call get_r_internal_value to find the
......
......@@ -52,6 +52,7 @@ ir_op *op_Shr; ir_op *get_op_Shr () { return op_Shr; }
ir_op *op_Shrs; ir_op *get_op_Shrs () { return op_Shrs; }
ir_op *op_Rot; ir_op *get_op_Rot () { return op_Rot; }
ir_op *op_Conv; ir_op *get_op_Conv () { return op_Conv; }
ir_op *op_Cast; ir_op *get_op_Cast () { return op_Cast; }
ir_op *op_Phi; ir_op *get_op_Phi () { return op_Phi; }
......@@ -131,6 +132,7 @@ init_op(void)
op_Shrs = new_ir_op (iro_Shrs, "Shrs", floats, 1, 0);
op_Rot = new_ir_op (iro_Rot, "Rot", floats, 1, 0);
op_Conv = new_ir_op (iro_Conv, "Conv", floats, 0, 0);
op_Cast = new_ir_op (iro_Cast, "Cast", floats, 0, sizeof (cast_attr));
op_Phi = new_ir_op (iro_Phi, "Phi", pinned, 1, sizeof (int));
......
......@@ -30,7 +30,7 @@ typedef enum {
iro_Sel, iro_InstOf,
iro_Call, iro_Add, iro_Sub, iro_Minus, iro_Mul, iro_Quot, iro_DivMod,
iro_Div, iro_Mod, iro_Abs, iro_And, iro_Or, iro_Eor, iro_Not,
iro_Cmp, iro_Shl, iro_Shr, iro_Shrs, iro_Rot, iro_Conv,
iro_Cmp, iro_Shl, iro_Shr, iro_Shrs, iro_Rot, iro_Conv, iro_Cast,
iro_Phi,
iro_Load, iro_Store, iro_Alloc, iro_Free, iro_Sync,
iro_Proj, iro_Tuple, iro_Id, iro_Bad,
......@@ -73,6 +73,7 @@ extern ir_op *op_Shr; ir_op *get_op_Shr (void);
extern ir_op *op_Shrs; ir_op *get_op_Shrs (void);
extern ir_op *op_Rot; ir_op *get_op_Rot (void);
extern ir_op *op_Conv; ir_op *get_op_Conv (void);
extern ir_op *op_Cast; ir_op *get_op_Cast (void);
extern ir_op *op_Phi; ir_op *get_op_Phi (void);
......
......@@ -900,6 +900,8 @@ vt_cmp (const void *elt, const void *key)
|| (get_irn_sel_attr(a).ent->type != get_irn_sel_attr(b).ent->type);
case iro_Phi:
return get_irn_phi_attr (a) != get_irn_phi_attr (b);
case iro_Cast:
return get_Cast_type(a) != get_Cast_type(b);
default: ;
}
......
......@@ -595,6 +595,15 @@ int irn_vrfy_irg(ir_node *n, ir_graph *irg)
);
break;
case iro_Cast:
op1mode = get_irn_mode(in[1]);
ASSERT_AND_RET(
/* Conv: BB x datab1 --> datab2 */
mode_is_data(op1mode) && op1mode == mymode,
"Cast node", 0
);
break;
case iro_Phi:
/* Phi: BB x dataM^n --> dataM */
/* for some reason "<=" aborts. int there a problem with get_store? */
......
......@@ -174,6 +174,9 @@ static void start_type_walk(ir_node *node, void *env) {
case iro_Free:
type_walk_2((type_or_ent *)get_Free_type(node), pre, post, envi);
break;
case iro_Cast:
type_walk_2((type_or_ent *)get_Cast_type(node), pre, post, envi);
break;
default:
break;
}
......
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