better output of testprograms, warning removed,
[libfirm] / testprograms / memory_example.c
index c56ef8f..1ec5af1 100644 (file)
@@ -1,10 +1,14 @@
-/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
-** All rights reserved.
-**
-** Authors: Christian Schaefer, Goetz Lindenmaier
-**
-** testprogram.
-*/
+/*
+ * Project:     libFIRM
+ * File name:   testprograms/memory_example.c
+ * Purpose:     Illustrate memory edges.
+ * Author:      Christian Schaefer, Goetz Lindenmaier
+ * Modified by:
+ * Created:
+ * CVS-ID:      $Id$
+ * Copyright:   (c) 1999-2003 Universität Karlsruhe
+ * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ */
 
 
 # include <stdio.h>
 # include "irdump.h"
 # include "firm.h"
 
-/**  This example demonstrates the use of memory edges.
-***  This file constructs the ir for the following pseudo-program:
-***
-***  int VAR_A
-***  int VAR_B
-***
-***  main() {
-***
-***    VAR_A = 0
-***    VAR_B = 1
-***
-***    repeat {
-***      h = VAR_A;
-***      VAR_A = VAR_B;
-***      VAR_B = h;
-***    } until (0 == h)
-***
-***    return (VAR_A)
-***  }
-***
-***
-***  A better example would be the following program:
-***  (name e.g.: memory-imp_example.c as it models imperative concepts.)
-***
-***  In this program a local variable is dereferenced.  It has
-***  to be modeled as an entity of the stack so that a pointer to it is available.
-***  It is also an example where an analysis could find out that the
-***  pointer is never actually used.
-***
-***  main () {
-***    int a;
-***    int *p;
-***
-***    a = 2;
-***    p = &a;
-***    return (*p);
-***  }
-***
+/**
+*  This file constructs the ir for the following pseudo-program:
+*
+*  int VAR_A
+*  int VAR_B
+*
+*  main() {
+*
+*    VAR_A = 0
+*    VAR_B = 1
+*
+*    repeat {
+*      h = VAR_A;
+*      VAR_A = VAR_B;
+*      VAR_B = h;
+*    } until (0 == h)
+*
+*    return (VAR_A)
+*  }
+*
+*
+*  A better example would be the following program:
+*  (name e.g.: memory-imp_example.c as it models imperative concepts.)
+*
+*  In this program a local variable is dereferenced.  It has
+*  to be modeled as an entity of the stack so that a pointer to it is available.
+*  It is also an example where an analysis could find out that the
+*  pointer is never actually used.
+*
+*  main () {
+*    int a;
+*    int *p;
+*
+*    a = 2;
+*    p = &a;
+*    return (*p);
+*  }
+*
 **/
 
 int
@@ -66,7 +70,7 @@ main(void)
 
   printf("\nCreating an IR graph: MEMORY_EXAMPLE...\n");
 
-  init_firm ();
+  init_firm (NULL);
 
   set_opt_dead_node_elimination (1);
 
@@ -78,22 +82,27 @@ main(void)
   method = new_type_method (id_from_str("main", 4), 0, 1);
   set_method_res_type(method, 0, prim_t_int);
   ent = new_entity (owner, id_from_str ("main", 4), method);
+  get_entity_ld_name(ent); /* To enforce name mangling for vcg graph name */
 
   /* Generates start and end blocks and nodes and a first, initial block */
   irg = new_ir_graph (ent, 4);
 
-  /* generate two constant pointers to string constants */
-  /* this simulates two global variables, a and b point to these variables */
-  a = new_Const (mode_P, tarval_P_from_str ("VAR_A"));
-  b = new_Const (mode_P, tarval_P_from_str ("VAR_B"));
-
-  /* set VAR_A and VAR_B to constant values */
+  /* create two global variables, a and b point to these variables */
+  a = new_simpleSel(
+              get_store(),
+              get_irg_globals(irg),
+              new_entity(get_glob_type(),id_from_str("VAR_A",6),prim_t_int));
+  b = new_simpleSel(
+              get_store(),
+              get_irg_globals(irg),
+              new_entity(get_glob_type(),id_from_str("VAR_B",6),prim_t_int));
+   /* set VAR_A and VAR_B to constant values */
   set_store (new_Proj (new_Store (get_store (), a,
-                                 new_Const (mode_Iu, tarval_from_long (mode_Is, 0))),
+                                 new_Const (mode_Iu, new_tarval_from_long (0, mode_Is))),
                        mode_M, 0));
 
   set_store (new_Proj (new_Store (get_store (), b,
-                                 new_Const (mode_Iu, tarval_from_long (mode_Is, 1))),
+                                 new_Const (mode_Iu, new_tarval_from_long (1, mode_Is))),
                        mode_M, 0));
 
   /* finish this first block */
@@ -121,7 +130,7 @@ main(void)
   x = new_Cond (
         new_Proj (
           new_Cmp (
-            new_Const (mode_Iu, tarval_from_long (mode_Is, 0)),
+            new_Const (mode_Iu, new_tarval_from_long (0, mode_Is)),
             x),
           mode_b, Gt));