Add ALLOCAN() and ALLOCANZ().
[libfirm] / ir / external / read.c
index f06873c..5cbe392 100644 (file)
@@ -1,33 +1,33 @@
-/* -*- c -*- */
-
-
 /*
- * Project:     libFIRM
- * File name:   ir/external/read.c
- * Purpose:     Read descriptions of external effects
- * Author:      Florian
- * Modified by: Boris Boesler
- * Created:     11.10.2004
- * CVS-ID:      $Id$
- * Copyright:   (c) 1999-2004 Universität Karlsruhe
- * Licence:     This file is protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
+ *
+ * This file is part of libFirm.
+ *
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
+ *
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
  */
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-/* get prototype for alloca somehow */
-#ifdef HAVE_ALLOCA_H
-# include <alloca.h>
-#endif
-#ifdef HAVE_STDLIB_H
-# include <stdlib.h>
-#endif
-#ifdef HAVE_STRING_H
-# include <string.h>
-#endif
+/**
+ * @file
+ * @brief     Read descriptions of external effects
+ * @author    Florian, Boris Boesler
+ * @date      11.10.2004
+ * @version   $Id$
+ */
+#include "config.h"
 
+#include <stdlib.h>
+#include <string.h>
 #include <assert.h>
 
 #include <libxml/xmlmemory.h>
@@ -43,7 +43,7 @@
 #include "irmode.h"
 #include "irdump.h"
 #include "irvrfy.h"
-#include "type.h"
+#include "typerep.h"
 #include "tv.h"
 #include "xmalloc.h"
 
@@ -54,8 +54,6 @@
 # define NODE_NAME(n, m) (0 == xmlStrcmp (n->name, (const xmlChar*) #m))
 # define CHECK_NAME(n, m) assert (0 == xmlStrcmp (n->name, (const xmlChar*) #m))
 
-# define NEW(T)     (T*)xmalloc(sizeof (T))
-
 
 #define VERBOSE_PRINTING 0
 
@@ -294,6 +292,7 @@ parseArg (xmlDocPtr doc, xmlNodePtr argelm)
   int num;
   char *num_str;
   eff_t *arg;
+  (void) doc;
 
   CHECK_NAME (argelm, arg);
   VERBOSE_PRINT ((stdout, "arg node \t0x%08x\n", (int) argelm));
@@ -306,7 +305,7 @@ parseArg (xmlDocPtr doc, xmlNodePtr argelm)
 
   typeid = getNodeTypeStr (argelm);
 
-  arg = NEW (eff_t);
+  arg = XMALLOC(eff_t);
   arg -> kind = eff_arg;
   arg -> id = new_id_from_str(id);
   arg -> effect.arg.num = num;
@@ -320,6 +319,7 @@ parseValref (xmlDocPtr doc, xmlNodePtr valelm)
 {
   const char *ref_id;
   eff_t *valref;
+  (void) doc;
 
   CHECK_NAME (valelm, valref);
   VERBOSE_PRINT ((stdout, "valref node \t0x%08x\n", (int) valelm));
@@ -327,7 +327,7 @@ parseValref (xmlDocPtr doc, xmlNodePtr valelm)
   ref_id = getNodeRefId (valelm);
   VERBOSE_PRINT ((stdout, "val->refid = \"%s\"\n", ref_id));
 
-  valref = NEW (eff_t);
+  valref = XMALLOC(eff_t);
   valref->kind = eff_valref;
   valref-> id = new_id_from_str(ref_id);
 
@@ -341,7 +341,7 @@ parseSelect (xmlDocPtr doc, xmlNodePtr selelm)
   entity_t *ent;
   xmlNodePtr child;
   eff_t *valref = NULL;
-  eff_t *sel = NEW (eff_t);
+  eff_t *sel = XMALLOC(eff_t);
   sel->kind = eff_select;
 
   CHECK_NAME (selelm, select);
@@ -373,7 +373,7 @@ parseLoad (xmlDocPtr doc, xmlNodePtr loadelm)
   ident *id;
   xmlNodePtr child;
   eff_t *sel;
-  eff_t *load = NEW (eff_t);
+  eff_t *load = XMALLOC(eff_t);
   load->kind = eff_load;
 
   CHECK_NAME (loadelm, load);
@@ -406,7 +406,7 @@ parseStore (xmlDocPtr doc, xmlNodePtr storeelm)
   xmlNodePtr child;
   eff_t *sel;
   eff_t *valref;
-  eff_t *store = NEW (eff_t);
+  eff_t *store = XMALLOC(eff_t);
   store->kind = eff_store;
 
   CHECK_NAME (storeelm, store);
@@ -439,8 +439,9 @@ parseAlloc (xmlDocPtr doc, xmlNodePtr allocelm)
 {
   ident *id;
   ident *type_id;
-  eff_t *alloc = NEW (eff_t); /* ...! */
+  eff_t *alloc = XMALLOC(eff_t); /* ...! */
   alloc->kind = eff_alloc;
+  (void) doc;
 
   CHECK_NAME (allocelm, alloc);
   VERBOSE_PRINT ((stdout, "alloc node \t0x%08x\n", (int) allocelm));
@@ -463,7 +464,7 @@ parseCall (xmlDocPtr doc, xmlNodePtr callelm)
   eff_t *sel;
   xmlNodePtr arg;
   int n_args;
-  eff_t *call = NEW (eff_t);
+  eff_t *call = XMALLOC(eff_t);
   call->kind = eff_call;
 
   CHECK_NAME (callelm, call);
@@ -497,7 +498,7 @@ parseCall (xmlDocPtr doc, xmlNodePtr callelm)
   free (sel);
 
   if (0 != n_args) {
-    ident **args = (ident**) xmalloc(n_args * sizeof(ident*));
+    ident **args = XMALLOCN(ident*, n_args);
     int i = 0;
 
     while (NULL != arg) {
@@ -521,7 +522,7 @@ parseJoin (xmlDocPtr doc, xmlNodePtr joinelm)
   ident **ins;
   int i;
   xmlNodePtr child;
-  eff_t *join = NEW (eff_t);
+  eff_t *join = XMALLOC(eff_t);
   join->kind = eff_join;
 
   CHECK_NAME (joinelm, join);
@@ -537,7 +538,7 @@ parseJoin (xmlDocPtr doc, xmlNodePtr joinelm)
     child = child->next;
   }
 
-  ins = (ident **) xmalloc (n_ins * sizeof (ident *) );
+  ins = XMALLOCN(ident*, n_ins);
   i = 0;
   child = get_valid_child(joinelm);
 
@@ -559,8 +560,9 @@ static eff_t*
 parseUnknown (xmlDocPtr doc, xmlNodePtr unknownelm)
 {
   ident *id;
-  eff_t *unknown = NEW (eff_t);
+  eff_t *unknown = XMALLOC(eff_t);
   unknown->kind = eff_unknown;
+  (void) doc;
 
   CHECK_NAME (unknownelm, unknown);
   VERBOSE_PRINT ((stdout, "unknown node \t0x%08x\n", (int) unknownelm));
@@ -574,7 +576,7 @@ static eff_t*
 parseReturn (xmlDocPtr doc, xmlNodePtr retelm)
 {
   xmlNodePtr child;
-  eff_t *ret = NEW (eff_t);
+  eff_t *ret = XMALLOC(eff_t);
   ret->kind = eff_ret;
 
   CHECK_NAME (retelm, ret);
@@ -599,7 +601,7 @@ parseRaise (xmlDocPtr doc, xmlNodePtr raiseelm)
   const char *tp_id;
   eff_t *valref;
   xmlNodePtr child;
-  eff_t *raise = NEW (eff_t);
+  eff_t *raise = XMALLOC(eff_t);
   raise->kind = eff_raise;
 
   CHECK_NAME (raiseelm, raise);
@@ -631,8 +633,9 @@ parseType (xmlDocPtr doc, xmlNodePtr typeelm)
   const char *tp_id = getNodeId (typeelm);
   VERBOSE_PRINT ((stdout, "type node \t0x%08x (%s)\n", (int) typeelm, tp_id));
   VERBOSE_PRINT ((stdout, "type = \"%s\"\n", getNodeTypeStr (typeelm)));
+  (void) doc;
 
-  type = (type_t*) xmalloc (sizeof (type_t));
+  type = XMALLOC(type_t);
   type -> type_ident = new_id_from_str(getNodeTypeStr (typeelm));
   type -> id         = new_id_from_str(tp_id);
 
@@ -644,7 +647,8 @@ parseType (xmlDocPtr doc, xmlNodePtr typeelm)
 static void
 parseEntity (xmlDocPtr doc, xmlNodePtr entelm)
 {
-  entity_t *ent = NEW (entity_t);
+  entity_t *ent = XMALLOC(entity_t);
+  (void) doc;
 
   /* parse it */
   const char *ent_id = getNodeId (entelm);
@@ -683,10 +687,10 @@ parseEffect (xmlDocPtr doc, xmlNodePtr effelm)
   }
   VERBOSE_PRINT ((stdout, "has %d effects\n", n_effs));
 
-  curr_effs = NEW (proc_t);
+  curr_effs = XMALLOC(proc_t);
   curr_effs -> proc_ident = new_id_from_str(procname);
   curr_effs -> ownerid = new_id_from_str(ownerid);
-  curr_effs->effs = (eff_t**) xmalloc (n_effs * sizeof (eff_t*));
+  curr_effs->effs = XMALLOCN(eff_t*, n_effs);
 
   cur = effelm -> xmlChildrenNode;
   while (NULL != cur) {
@@ -783,7 +787,7 @@ int read_extern (const char *filename)
     cur = cur->next;
   }
 
-  module = NEW(module_t);
+  module = XMALLOC(module_t);
   module -> id = mod_id;
   module -> types = types;
   module -> entities = entities;
@@ -809,7 +813,6 @@ void freeArg (eff_t *arg)
 {
   VERBOSE_PRINT ((stdout, "free arg node \t0x%08x\n", (int) arg));
   free(arg);
-  return;
 }
 
 static
@@ -817,7 +820,6 @@ void freeValref (eff_t *valref)
 {
   VERBOSE_PRINT ((stdout, "free valref node \t0x%08x\n", (int) valref));
   free(valref);
-  return;
 }
 
 static
@@ -825,7 +827,6 @@ void freeSelect (eff_t *sel)
 {
   VERBOSE_PRINT ((stdout, "free select node \t0x%08x\n", (int) sel));
   free(sel);
-  return;
 }
 
 static
@@ -833,7 +834,6 @@ void freeLoad (eff_t *load)
 {
   VERBOSE_PRINT ((stdout, "free load node \t0x%08x\n", (int) load));
   free (load);
-  return;
 }
 
 static
@@ -841,7 +841,6 @@ void freeStore (eff_t *store)
 {
   VERBOSE_PRINT ((stdout, "free store node \t0x%08x\n", (int) store));
   free (store);
-  return;
 }
 
 static
@@ -849,7 +848,6 @@ void freeAlloc (eff_t *alloc)
 {
   VERBOSE_PRINT ((stdout, "free alloc node \t0x%08x\n", (int) alloc));
   free(alloc);
-  return;
 }
 
 static
@@ -858,7 +856,6 @@ void freeCall (eff_t *call)
   VERBOSE_PRINT ((stdout, "free call node \t0x%08x\n", (int) call));
   free(call -> effect.call.args);
   free(call);
-  return;
 }
 
 static
@@ -867,7 +864,6 @@ void freeJoin (eff_t *join)
   VERBOSE_PRINT ((stdout, "free join node \t0x%08x\n", (int) join));
   free(join -> effect.join.ins);
   free(join);
-  return;
 }
 
 static
@@ -875,7 +871,6 @@ void freeUnknown (eff_t *unknown)
 {
   VERBOSE_PRINT ((stdout, "free unknown node \t0x%08x\n", (int) unknown));
   free(unknown);
-  return;
 }
 
 static
@@ -883,7 +878,6 @@ void freeReturn (eff_t *ret)
 {
   VERBOSE_PRINT ((stdout, "free ret node \t0x%08x\n", (int) ret));
   free(ret);
-  return;
 }
 
 static
@@ -891,7 +885,6 @@ void freeRaise (eff_t *raise)
 {
   VERBOSE_PRINT ((stdout, "free raise node \t0x%08x\n", (int) raise));
   free (raise);
-  return;
 }
 
 
@@ -1085,6 +1078,7 @@ static void create_abstract_load(ir_graph *irg, proc_t *proc, eff_t *eff)
   ir_entity *ent;
   ir_mode *mode;
   eff_t *addr;
+  (void) irg;
 
   VERBOSE_PRINT((stdout, "create load in %s\n",
          get_id_str(proc -> proc_ident)));
@@ -1126,6 +1120,7 @@ static void create_abstract_store(ir_graph *irg, proc_t *proc, eff_t *eff)
   ir_node *sel, *store;
   ir_entity *ent;
   eff_t *addr, *val;
+  (void) irg;
 
   VERBOSE_PRINT((stdout, "create store in %s\n",
          get_id_str(proc -> proc_ident)));
@@ -1171,6 +1166,7 @@ static void create_abstract_alloc(ir_graph *irg, proc_t *proc, eff_t *eff)
   ir_node *alloc;
   type_t *xtype;
   symconst_symbol sym;
+  (void) irg;
 
   VERBOSE_PRINT((stdout, "create alloc in %s\n",
          get_id_str(proc -> proc_ident)));
@@ -1180,7 +1176,7 @@ static void create_abstract_alloc(ir_graph *irg, proc_t *proc, eff_t *eff)
   ftype = xtype -> f_tp;
 
   sym.type_p = ftype;
-  alloc = new_Alloc(get_store(), new_SymConst(sym, symconst_type_size), ftype,
+  alloc = new_Alloc(get_store(), new_SymConst(mode_Is, sym, symconst_type_size), ftype,
             heap_alloc);
   set_store(new_Proj(alloc, mode_M, 0));
   eff -> firmnode = new_Proj(alloc, mode_P, 2);
@@ -1192,6 +1188,7 @@ static void create_abstract_alloc(ir_graph *irg, proc_t *proc, eff_t *eff)
 static void create_abstract_unknown(ir_graph *irg, proc_t *proc, eff_t *eff)
 {
   ir_node *unknown;
+  (void) irg;
 
   VERBOSE_PRINT((stdout, "create unknown in %s\n",
          get_id_str(proc -> proc_ident)));
@@ -1212,6 +1209,7 @@ static void create_abstract_call(ir_graph *irg, proc_t *proc, eff_t *eff)
   int i, num;
   ir_type *mtype;
   int mik; /* is method somehow known? */
+  (void) irg;
 
   VERBOSE_PRINT((stdout, "create call in %s\n",
          get_id_str(proc -> proc_ident)));
@@ -1254,7 +1252,7 @@ static void create_abstract_call(ir_graph *irg, proc_t *proc, eff_t *eff)
     VERBOSE_PRINT((stdout, "number of args expected: %d\n",
            get_method_n_params(mtype)));
   }
-  irns = alloca(num * sizeof(ir_node*));
+  irns = ALLOCAN(ir_node*, num);
   for(i = 0; i < num; i++) {
     irns[i] = find_valueid_in_proc_effects(eff -> effect.call.args[i], proc)
       -> firmnode;
@@ -1291,6 +1289,7 @@ static void create_abstract_join (ir_graph *irg, proc_t *proc, eff_t *eff)
   ir_mode *join_md = mode_ANY;
   int n_ins = -1;
   int i;
+  (void) irg;
 
   VERBOSE_PRINT((stdout, "create join in %s\n",
          get_id_str(proc -> proc_ident)));
@@ -1310,7 +1309,7 @@ static void create_abstract_join (ir_graph *irg, proc_t *proc, eff_t *eff)
 
   c_block   = new_immBlock ();  /* for the Phi after the branch(es) */
 
-  ins = (ir_node**) xmalloc (n_ins * sizeof (ir_node*));
+  ins = XMALLOCN(ir_node*, n_ins);
   for (i = 0; i < n_ins; i ++) {
     ir_node *projX   = NULL;
     ir_node *s_block = NULL;
@@ -1345,7 +1344,6 @@ static void create_abstract_join (ir_graph *irg, proc_t *proc, eff_t *eff)
   phi = new_Phi (n_ins, ins, join_md);
 
   mature_immBlock (c_block);
-  memset (ins, 0x00, n_ins * sizeof (ir_node*));
   free (ins);
 
   eff->firmnode = phi;
@@ -1406,6 +1404,7 @@ static void create_abstract_firm(module_t *module, proc_t *proc, ir_entity *fent
   eff_t *eff;
   ir_graph *irg;
   int i, num;
+  (void) module;
 
   /* test ir_entity */
   assert(visibility_external_allocated == get_entity_visibility(fent)