Fix typos in comments: s/wether/whether/ and related corrections.
[libfirm] / ir / be / bemain.c
index 72ffb7b..9d63372 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
+ * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
  *
  * This file is part of libFirm.
  *
@@ -73,6 +73,7 @@
 #include "be_dbgout.h"
 #include "beirg.h"
 #include "bestack.h"
+#include "beemitter.h"
 
 #define NEW_ID(s) new_id_from_chars(s, sizeof(s) - 1)
 
@@ -362,7 +363,6 @@ static be_main_env_t *be_init_env(be_main_env_t *env, FILE *file_handle)
        memset(asm_constraint_flags, 0, sizeof(asm_constraint_flags));
        env->arch_env = arch_env_init(isa_if, file_handle, env);
 
-       be_dbg_open();
        return env;
 }
 
@@ -371,9 +371,6 @@ static be_main_env_t *be_init_env(be_main_env_t *env, FILE *file_handle)
  */
 static void be_done_env(be_main_env_t *env)
 {
-       arch_env_done(env->arch_env);
-       be_dbg_close();
-
        pmap_destroy(env->ent_trampoline_map);
        pmap_destroy(env->ent_pic_symbol_map);
        free_type(env->pic_trampolines_type);
@@ -469,17 +466,28 @@ ir_timer_t *be_timers[T_LAST+1];
 
 void be_lower_for_target(void)
 {
-       int i;
+       size_t i;
 
        isa_if->lower_for_target();
        /* set the phase to low */
-       for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
-               ir_graph *irg = get_irp_irg(i);
+       for (i = get_irp_n_irgs(); i > 0;) {
+               ir_graph *irg = get_irp_irg(--i);
                set_irg_phase_state(irg, phase_low);
        }
        set_irp_phase_state(phase_low);
 }
 
+static void emit_global_asms(void)
+{
+       size_t n = get_irp_n_asms();
+       size_t i;
+       for (i = 0; i < n; ++i) {
+               be_emit_cstring("#APP\n");
+               be_emit_ident(get_irp_asm(i));
+               be_emit_cstring("\n#NO_APP\n");
+       }
+}
+
 /**
  * The Firm backend main loop.
  * Do architecture specific lowering for all graphs
@@ -492,7 +500,8 @@ static void be_main_loop(FILE *file_handle, const char *cup_name)
 {
        static const char suffix[] = ".prof";
 
-       int           i, num_birgs, stat_active = 0;
+       size_t        i, num_birgs;
+       int           stat_active = 0;
        be_main_env_t env;
        char          prof_filename[256];
        be_irg_t      *birgs;
@@ -510,9 +519,12 @@ static void be_main_loop(FILE *file_handle, const char *cup_name)
        be_init_env(&env, file_handle);
        env.cup_name = cup_name;
 
-       be_dbg_so(cup_name);
+       be_dbg_open();
+       be_dbg_unit_begin(cup_name);
        be_dbg_types();
 
+       emit_global_asms();
+
        arch_env = env.arch_env;
 
        /* backend may provide an ordered list of irgs where code should be
@@ -799,6 +811,12 @@ static void be_main_loop(FILE *file_handle, const char *cup_name)
                be_free_birg(irg);
                stat_ev_ctx_pop("bemain_irg");
        }
+
+       arch_env_done(arch_env);
+
+       be_dbg_unit_end();
+       be_dbg_close();
+
        ir_profile_free();
        be_done_env(&env);