Remove .*_ptr variants of firm-types
[libfirm] / ir / ir / irprofile.c
index 6046ca9..70e2340 100644 (file)
@@ -22,7 +22,6 @@
  * @brief       Code instrumentation and execution count profiling.
  * @author      Adam M. Szalkowski, Steven Schaefer
  * @date        06.04.2006, 11.11.2010
- * @version     $Id$
  */
 #include "config.h"
 
@@ -150,8 +149,6 @@ static void add_constructor(ir_entity *method)
     ir_type   *ptr_type     = new_type_pointer(method_type);
 
     ir_type   *constructors = get_segment_type(IR_SEGMENT_CONSTRUCTORS);
-       /* Mach-O does not like labels in the constructor segment, but with ELF
-        * the linker dies horribly if there is no label. */
        ident     *ide = id_unique("constructor_ptr.%u");
     ir_entity *ptr = new_entity(constructors, ide, ptr_type);
     ir_graph  *irg = get_const_code_irg();
@@ -267,7 +264,7 @@ static void instrument_block(ir_node *bb, ir_node *address, unsigned int id)
        load    = new_r_Load(bb, unknown, offset, mode_Iu, cons_none);
        projm   = new_r_Proj(load, mode_M, pn_Load_M);
        proji   = new_r_Proj(load, mode_Iu, pn_Load_res);
-       cnst    = new_r_Const_long(irg, mode_Iu, 1);
+       cnst    = new_r_Const(irg, get_mode_one(mode_Iu));
        add     = new_r_Add(bb, proji, cnst, mode_Iu);
        store   = new_r_Store(bb, projm, offset, add, cons_none);
        projm   = new_r_Proj(store, mode_M, pn_Store_M);
@@ -513,8 +510,9 @@ static unsigned int *
 parse_profile(const char *filename, unsigned int num_blocks)
 {
        unsigned int *result = NULL;
-       char buf[8];
-       size_t ret;
+       char          buf[8];
+       size_t        ret;
+       unsigned int  i;
 
        FILE *f = fopen(filename, "rb");
        if (!f) {
@@ -530,9 +528,22 @@ parse_profile(const char *filename, unsigned int num_blocks)
        }
 
        result = XMALLOCN(unsigned int, num_blocks);
-       if (fread(result, sizeof(unsigned int) * num_blocks, 1, f) < 1) {
+
+       /* The profiling output format is defined to be a sequence of integer
+        * values stored little endian format. */
+       for (i = 0; i < num_blocks; ++i) {
+               unsigned char bytes[4];
+
+               if ((ret = fread(bytes, 1, 4, f)) < 1)
+                       break;
+
+               result[i] = (bytes[0] <<  0) | (bytes[1] <<  8)
+                         | (bytes[2] << 16) | (bytes[3] << 24);
+       }
+
+       if (ret < 1) {
                DBG((dbg, LEVEL_4, "Failed to read counters... (size: %u)\n",
-                   sizeof(unsigned int) * num_blocks));
+                       sizeof(unsigned int) * num_blocks));
                xfree(result);
                result = NULL;
        }