typo removed
[libfirm] / ir / ir / ircons.c
index c24a3cc..dac81fe 100644 (file)
@@ -1,15 +1,16 @@
-/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
-* All rights reserved.
-*
-* Authors: Martin Trapp, Christian Schaefer
-*
-* ircons.c: basic and more detailed irnode constructors
-*           store, block and parameter administration.
-* Adapted to extended FIRM nodes (exceptions...) and commented
-*   by Goetz Lindenmaier
-*/
+/*
+ * Project:     libFIRM
+ * File name:   ir/ir/ircons.c
+ * Purpose:     Various irnode constructors.  Automatic construction
+ *              of SSA representation.
+ * Author:      Martin Trapp, Christian Schaefer
+ * Modified by: Goetz Lindenmaier, Boris Boesler
+ * Created:
+ * CVS-ID:      $Id$
+ * Copyright:   (c) 1998-2003 Universität Karlsruhe
+ * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ */
 
-/* $Id$ */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
@@ -75,6 +76,7 @@ new_rd_Start (dbg_info* db, ir_graph *irg, ir_node *block)
   ir_node *res;
 
   res = new_ir_node (db, irg, block, op_Start, mode_T, 0, NULL);
+  res->attr.start.irg = irg;
 
   irn_vrfy_irg (res, irg);
   return res;
@@ -119,12 +121,14 @@ new_rd_Phi (dbg_info* db, ir_graph *irg, ir_node *block, int arity, ir_node **in
 }
 
 INLINE ir_node *
-new_rd_Const (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con)
+new_rd_Const_type (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con, type *tp)
 {
   ir_node *res;
   res = new_ir_node (db, irg, block, op_Const, mode, 0, NULL);
-  res->attr.con = con;
+  res->attr.con.tv = con;
+  set_Const_type(res, tp);  /* Call method because of complex assertion. */
   res = optimize_node (res);
+  assert(get_Const_type(res) == tp);
   irn_vrfy_irg (res, irg);
 
 #if 0
@@ -134,6 +138,15 @@ new_rd_Const (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval
   return res;
 }
 
+INLINE ir_node *
+new_rd_Const (dbg_info* db, ir_graph *irg, ir_node *block, ir_mode *mode, tarval *con)
+{
+  type *tp = unknown_type;
+  if (tarval_is_entity(con))
+    tp = find_pointer_type_to_type(get_entity_type(get_tarval_entity(con)));
+  return new_rd_Const_type (db, irg, block, mode, con, tp);
+}
+
 INLINE ir_node *
 new_rd_Id (dbg_info* db, ir_graph *irg, ir_node *block, ir_node *val, ir_mode *mode)
 {
@@ -189,7 +202,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 +912,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);
@@ -971,6 +997,7 @@ new_d_Start (dbg_info* db)
 
   res = new_ir_node (db, current_ir_graph, current_ir_graph->current_block,
                     op_Start, mode_T, 0, NULL);
+  res->attr.start.irg = current_ir_graph;
 
   res = optimize_node (res);
   irn_vrfy_irg (res, current_ir_graph);
@@ -1256,7 +1283,7 @@ phi_merge (ir_node *block, int pos, ir_mode *mode, ir_node **nin, int ins)
     block->attr.block.graph_arr[pos] = res;
   } else {
     /*  printf(" value already computed by %s\n",
-        id_to_str(block->attr.block.graph_arr[pos]->op->name));  */
+        get_id_str(block->attr.block.graph_arr[pos]->op->name));  */
   }
 
   return res;
@@ -1760,6 +1787,14 @@ new_d_Const (dbg_info* db, ir_mode *mode, tarval *con)
                      mode, con);
 }
 
+ir_node *
+new_d_Const_type (dbg_info* db, ir_mode *mode, tarval *con, type *tp)
+{
+  return new_rd_Const_type (db, current_ir_graph, current_ir_graph->start_block,
+                           mode, con, tp);
+}
+
+
 ir_node *
 new_d_Id (dbg_info* db, ir_node *val, ir_mode *mode)
 {
@@ -1792,6 +1827,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 +2421,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);
 }