Implement binary emitter for fpush.
[libfirm] / ir / ir / irprog.c
index f3aef2d..9aa9612 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "irprog_t.h"
 #include "irgraph_t.h"
+#include "irpass_t.h"
 #include "pseudo_irg.h"
 #include "array.h"
 #include "error.h"
@@ -78,14 +79,16 @@ static ir_prog *new_incomplete_ir_prog(void)
 static ir_prog *complete_ir_prog(ir_prog *irp, const char *module_name) {
        int i;
 
+#define IDENT(x)  new_id_from_chars(x, sizeof(x) - 1)
+
        irp->name = new_id_from_str(module_name);
-       irp->segment_types[IR_SEGMENT_GLOBAL] = new_type_class(new_id_from_str("GlobalType"));
+       irp->segment_types[IR_SEGMENT_GLOBAL] = new_type_class(IDENT("GlobalType"));
        irp->segment_types[IR_SEGMENT_THREAD_LOCAL]
-               = new_type_struct(new_id_from_str("ThreadLocal"));
+               = new_type_struct(IDENT("ThreadLocal"));
        irp->segment_types[IR_SEGMENT_CONSTRUCTORS]
-               = new_type_struct(new_id_from_str("Constructors"));
+               = new_type_struct(IDENT("Constructors"));
        irp->segment_types[IR_SEGMENT_DESTRUCTORS]
-               = new_type_struct(new_id_from_str("Destructors"));
+               = new_type_struct(IDENT("Destructors"));
        /* Remove these types from type list.  Must be treated differently than
           other types. */
        for (i = 0; i < IR_SEGMENT_COUNT; ++i) {
@@ -111,6 +114,7 @@ static ir_prog *complete_ir_prog(ir_prog *irp, const char *module_name) {
        irp->globals_entity_usage_state = ir_entity_usage_not_computed;
 
        return irp;
+#undef IDENT
 }
 
 /* initializes ir_prog. Constructs only the basic lists. */
@@ -125,8 +129,8 @@ void init_irprog_2(void) {
 
 /* Create a new ir prog. Automatically called by init_firm through
    init_irprog. */
-ir_prog *new_ir_prog(void) {
-       return complete_ir_prog(new_incomplete_ir_prog(), INITAL_PROG_NAME);
+ir_prog *new_ir_prog(const char *name) {
+       return complete_ir_prog(new_incomplete_ir_prog(), name);
 }
 
 /* frees all memory used by irp.  Types in type list, irgs in irg
@@ -319,7 +323,7 @@ void add_irp_opcode(ir_op *opcode) {
        assert(irp);
        len  = ARR_LEN(irp->opcodes);
        code = opcode->code;
-       if (code >= len) {
+       if ((int) code >= len) {
                ARR_RESIZE(ir_op*, irp->opcodes, code+1);
                memset(&irp->opcodes[len], 0, (code-len+1) * sizeof(irp->opcodes[0]));
        }
@@ -330,7 +334,7 @@ void add_irp_opcode(ir_op *opcode) {
 
 /* Removes opcode from the list of opcodes and shrinks the list by one. */
 void remove_irp_opcode(ir_op *opcode) {
-       assert(opcode->code < ARR_LEN(irp->opcodes));
+       assert((int) opcode->code < ARR_LEN(irp->opcodes));
        irp->opcodes[opcode->code] = NULL;
 }
 
@@ -381,6 +385,45 @@ void set_irp_phase_state(irg_phase_state s) {
        irp->phase_state = s;
 }
 
+struct pass_t {
+       ir_prog_pass_t  pass;
+       irg_phase_state state;
+};
+
+/**
+ * Wrapper for setting the state of a whole ir_prog.
+ */
+static int set_irp_phase_state_wrapper(ir_prog *irp, void *context) {
+       struct pass_t  *pass  = context;
+       irg_phase_state state = pass->state;
+       int             i;
+
+       (void)irp;
+
+       /* set the phase of all graphs */
+       for (i = get_irp_n_irgs() - 1; i >= 0; --i)
+               set_irg_phase_state(get_irp_irg(i), state);
+
+       /* set the irp phase */
+       set_irp_phase_state(state);
+
+       return 0;
+}
+
+ir_prog_pass_t *set_irp_phase_state_pass(const char *name, irg_phase_state state) {
+       struct pass_t *pass = XMALLOCZ(struct pass_t);
+
+       def_prog_pass_constructor(
+               &pass->pass, name ? name : "set_irp_phase", set_irp_phase_state_wrapper);
+       pass->state = state;
+
+       /* no dump/verify */
+       pass->pass.verify_irprog = ir_prog_no_verify;
+       pass->pass.dump_irprog   = ir_prog_no_dump;
+
+       return &pass->pass;
+}
+
 irg_outs_state get_irp_ip_outs_state(void) {
        return irp->outs_state;
 }