add ia32 command line handler for fp-unit and architecture
[libfirm] / ir / be / ia32 / ia32_gen_decls.c
index 8ec8024..911a959 100644 (file)
 #include <ctype.h>
 #include <assert.h>
 
+#include "xmalloc.h"
 #include <obstack.h>
 
 #ifdef obstack_chunk_alloc
 # undef obstack_chunk_alloc
-# define obstack_chunk_alloc malloc
+# define obstack_chunk_alloc xmalloc
 #else
-# define obstack_chunk_alloc malloc
+# define obstack_chunk_alloc xmalloc
 # define obstack_chunk_free free
 #endif
 
+extern int obstack_printf(struct obstack *obst, char *fmt, ...);
+
 #include "tv.h"
 #include "irnode.h"
 #include "entity.h"
@@ -110,41 +113,6 @@ static void dump_arith_tarval(struct obstack *obst, tarval *tv, int bytes)
   }
 }
 
-/*
- * dump an arithmetic tarval
- */
-static void ia32_dump_arith_tarval(struct obstack *obst, tarval *tv, int bytes)
-{
-  switch (bytes) {
-
-  case 1:
-    obstack_printf(obst, "\t.byte\t");
-    break;
-
-  case 2:
-    obstack_printf(obst, "\t.value\t");
-    break;
-
-  case 4:
-    obstack_printf(obst, "\t.long\t");
-    break;
-
-  case 8:
-    obstack_printf(obst, "\t.quad\t");
-    break;
-
-  case 10:
-  case 12:
-    break;
-
-  default:
-    fprintf(stderr, "Try to dump an tarval with %d bytes\n", bytes);
-    assert(0);
-  }
-  dump_arith_tarval(obst, tv, bytes);
-}
-
-
 /*
  * dump an atomic value
  */
@@ -268,15 +236,15 @@ static void dump_atomic_init(struct obstack *obst, ir_node *init)
 static int ent_is_string_const(entity *ent)
 {
   int res = 0;
-  type *ty;
+  ir_type *ty;
 
   ty = get_entity_type(ent);
 
   /* if it's an array */
   if (is_Array_type(ty)) {
-    type *elm_ty = get_array_element_type(ty);
+    ir_type *elm_ty = get_array_element_type(ty);
 
-    /* and the array's alement type is primitive */
+    /* and the array's element type is primitive */
     if (is_Primitive_type(elm_ty)) {
       ir_mode *mode = get_type_mode(elm_ty);
 
@@ -358,7 +326,7 @@ struct arr_info {
  */
 static void dump_global(struct obstack *rdata_obstack, struct obstack *data_obstack, struct obstack *comm_obstack, entity *ent)
 {
-  type *ty            = get_entity_type(ent);
+  ir_type *ty         = get_entity_type(ent);
   const char *ld_name = get_entity_ld_name(ent);
   int align, h;
   struct obstack *obst = data_obstack;
@@ -404,7 +372,7 @@ static void dump_global(struct obstack *rdata_obstack, struct obstack *data_obst
           /* potential spare values should be already included! */
                  for (i = 0; i < get_compound_ent_n_values(ent); ++i) {
             entity *step = get_compound_ent_value_member(ent, i);
-            type *stype  = get_entity_type(step);
+            ir_type *stype = get_entity_type(step);
 
             if (get_type_mode(stype)) {
               int align = (get_type_alignment_bits(stype) + 7) >> 3;
@@ -437,7 +405,7 @@ static void dump_global(struct obstack *rdata_obstack, struct obstack *data_obst
            * size should be equal or bigger the number of fields
            */
           type_size = get_type_size_bytes(ty);
-          vals      = calloc(type_size, sizeof(*vals));
+          vals      = xcalloc(type_size, sizeof(*vals));
 
           /* collect the values and store them at the offsets */
           for(i = 0; i < get_compound_ent_n_values(ent); ++i) {
@@ -448,15 +416,15 @@ static void dump_global(struct obstack *rdata_obstack, struct obstack *data_obst
 
             /* get the access path to the costant value */
             graph_length = get_compound_graph_path_length(path);
-            ai = calloc(graph_length, sizeof(struct arr_info));
+            ai = xcalloc(graph_length, sizeof(struct arr_info));
 
             /* We wanna know how many arrays are on the path to the entity. We also have to know how
              * many elements each array holds to calculate the offset for the entity. */
             for (j = 0; j < graph_length; j++) {
-              entity *step      = get_compound_graph_path_node(path, j);
-              type   *step_type = get_entity_type(step);
-              int    ty_size    = (get_type_size_bits(step_type) + 7) >> 3;
-              int    k, n       = 0;
+              entity  *step      = get_compound_graph_path_node(path, j);
+              ir_type *step_type = get_entity_type(step);
+              int     ty_size    = (get_type_size_bits(step_type) + 7) >> 3;
+              int     k, n       = 0;
 
               if (is_Array_type(step_type))
                 for (k = 0; k < get_array_n_dimensions(step_type); k++)
@@ -471,10 +439,10 @@ static void dump_global(struct obstack *rdata_obstack, struct obstack *data_obst
             if (aipos) aipos--;
 
             for (offset = j = 0; j < graph_length; j++) {
-              entity *step    = get_compound_graph_path_node(path, j);
-              type *step_type = get_entity_type(step);
-              int ent_ofs     = get_entity_offset_bytes(step);
-              int stepsize    = 0;
+              entity *step       = get_compound_graph_path_node(path, j);
+              ir_type *step_type = get_entity_type(step);
+              int ent_ofs        = get_entity_offset_bytes(step);
+              int stepsize       = 0;
 
               /* add all positive offsets (= offsets in structs) */
               if (ent_ofs >= 0) offset += ent_ofs;
@@ -549,7 +517,7 @@ static void dump_global(struct obstack *rdata_obstack, struct obstack *data_obst
  */
 void ia32_dump_globals(struct obstack *rdata_obstack, struct obstack *data_obstack, struct obstack *comm_obstack)
 {
-  type *gt = get_glob_type();
+  ir_type *gt = get_glob_type();
   int i, n = get_class_n_members(gt);
 
   for (i = 0; i < n; i++)
@@ -567,6 +535,8 @@ void ia32_gen_decls(FILE *out) {
   obstack_init(&data);
   obstack_init(&comm);
 
+  fprintf(out, "\t.intel_syntax\n");
+
   ia32_dump_globals(&rodata, &data, &comm);
 
   size = obstack_object_size(&data);
@@ -586,7 +556,7 @@ void ia32_gen_decls(FILE *out) {
   size = obstack_object_size(&comm);
   cp   = obstack_finish(&comm);
   if (size > 0) {
-    fprintf(out, "\t.common\n");
+    fprintf(out, "\t.text\n");
     fwrite(cp, 1, size, out);
   }