fix rts_mapping code, add alloca mapping
authorMatthias Braun <matze@braunis.de>
Sat, 31 May 2008 10:39:13 +0000 (10:39 +0000)
committerMatthias Braun <matze@braunis.de>
Sat, 31 May 2008 10:39:13 +0000 (10:39 +0000)
[r19883]

ast2firm.c
driver/firm_opt.c
driver/firm_opt.h

index 1798a06..6bc4fdb 100644 (file)
@@ -814,8 +814,6 @@ static inline ir_mode *get_ir_mode(type_t *type)
        return mode;
 }
 
-static ident *predef_idents[rts_max];
-
 /** Names of the runtime functions. */
 static const struct {
        int        id;           /**< the rts id */
@@ -826,6 +824,7 @@ static const struct {
 } rts_data[] = {
        { rts_debugbreak, 0, "__debugbreak", 0, _MS },
        { rts_abort,      0, "abort",        0, _C89 },
+       { rts_alloca,     1, "alloca",       1, _GNUC },
        { rts_abs,        1, "abs",          1, _C89 },
        { rts_labs,       1, "labs",         1, _C89 },
        { rts_llabs,      1, "llabs",        1, _C99 },
@@ -897,6 +896,8 @@ static const struct {
        { rts_strncmp,    1, "strncmp",      3, _C89 }
 };
 
+static ident *rts_idents[sizeof(rts_data) / sizeof(rts_data[0])];
+
 /**
  * Mangles an entity linker (ld) name for win32 usage.
  *
@@ -980,36 +981,30 @@ static ir_entity* get_function_entity(declaration_t *declaration)
                set_entity_visibility(entity, visibility_external_visible);
        } else {
                set_entity_visibility(entity, visibility_external_allocated);
-
-               /* We should check for file scope here, but as long as we compile C only
-                  this is not needed. */
-               int    n_params = get_method_n_params(ir_type_method);
-               int    n_res    = get_method_n_ress(ir_type_method);
-               int    i;
-
-               if (n_params == 0 && n_res == 0 && id == predef_idents[rts_abort]) {
-                       /* found abort(), store for later */
-                       //abort_ent = ent;
-                       //abort_tp  = ftype;
-               } else {
-                       if (! firm_opt.freestanding) {
-                               /* check for a known runtime function */
-                               for (i = 0; i < rts_max; ++i) {
-                                       /* ignore those rts functions not necessary needed for current mode */
-                                       if ((c_mode & rts_data[i].flags) == 0)
-                                               continue;
-                                       if (n_params == rts_data[i].n_params && n_res == rts_data[i].n_res &&
-                                               id == predef_idents[rts_data[i].id])
-                                               rts_entities[rts_data[i].id] = entity;
-                               }
-                       }
-               }
        }
        set_entity_allocation(entity, allocation_static);
 
        declaration->declaration_kind = DECLARATION_KIND_FUNCTION;
        declaration->v.entity         = entity;
 
+       /* We should check for file scope here, but as long as we compile C only
+          this is not needed. */
+       if (! firm_opt.freestanding) {
+               /* check for a known runtime function */
+               for (size_t i = 0; i < sizeof(rts_data) / sizeof(rts_data[0]); ++i) {
+                       if (id != rts_idents[i])
+                               continue;
+
+                       printf("FoudnID: %s\n", symbol->string);
+
+                       /* ignore those rts functions not necessary needed for current mode */
+                       if ((c_mode & rts_data[i].flags) == 0)
+                               continue;
+                       printf("Found rts: %s\n", symbol->string);
+                       rts_entities[rts_data[i].id] = entity;
+               }
+       }
+
        return entity;
 }
 
@@ -4897,7 +4892,7 @@ void init_ast2firm(void)
 
        /* create idents for all known runtime functions */
        for (size_t i = 0; i < sizeof(rts_data) / sizeof(rts_data[0]); ++i) {
-               predef_idents[rts_data[i].id] = new_id_from_str(rts_data[i].name);
+               rts_idents[i] = new_id_from_str(rts_data[i].name);
        }
 }
 
index 969d038..c33995c 100644 (file)
@@ -143,6 +143,7 @@ static void rts_map(void) {
   } mapper[] = {
     /* integer */
     { &rts_entities[rts_abs],     i_mapper_abs },
+       { &rts_entities[rts_alloca],  i_mapper_alloca },
     { &rts_entities[rts_labs],    i_mapper_abs },
     { &rts_entities[rts_llabs],   i_mapper_abs },
     { &rts_entities[rts_imaxabs], i_mapper_abs },
@@ -220,7 +221,7 @@ static void rts_map(void) {
   i_record rec[sizeof(mapper)/sizeof(mapper[0])];
   unsigned i, n_map;
 
-  for (i = n_map = 0; i < sizeof(mapper)/sizeof(mapper[0]); ++i)
+  for (i = n_map = 0; i < sizeof(mapper)/sizeof(mapper[0]); ++i) {
     if (*mapper[i].ent != NULL) {
       rec[n_map].i_call.kind     = INTRINSIC_CALL;
       rec[n_map].i_call.i_ent    = *mapper[i].ent;
@@ -228,7 +229,8 @@ static void rts_map(void) {
       rec[n_map].i_call.ctx      = NULL;
       rec[n_map].i_call.link     = NULL;
       ++n_map;
-  }  /* if */
+    }  /* if */
+  }
   if (n_map > 0)
     lower_intrinsics(rec, n_map, /* part_block_used=*/0);
 }  /* rts_map */
index 872c2f8..e4029ca 100644 (file)
@@ -10,6 +10,7 @@ extern ir_mode *firm_imm_fp_mode;
 enum rts_names {
   rts_debugbreak,  /**< the name of the __debugbreak() intrinsic */
   rts_abort,       /**< the name of the abort() function */
+  rts_alloca,      /**< the name of the alloca() function */
   rts_abs,         /**< the name of the abs() function */
   rts_labs,        /**< the name of the labs() function */
   rts_llabs,       /**< the name of the llabs() function */