mie: ir: implement generation and text output of phi instruction

This commit is contained in:
2025-09-08 15:34:58 +01:00
parent dd0dcc9c0a
commit 32a520e210
6 changed files with 97 additions and 9 deletions

View File

@@ -14,6 +14,7 @@
#include <mie/ir/module.h>
#include <mie/ir/msg.h>
#include <mie/ir/op.h>
#include <mie/ir/phi.h>
#include <mie/ir/ptr.h>
#include <mie/ir/record.h>
#include <mie/ir/value.h>
@@ -138,7 +139,7 @@ static b_status write_operand_const(
case MIE_TYPE_SELECTOR: {
struct mie_selector *v = MIE_SELECTOR(c);
write_string_f(converter, "\"%s\"", v->sel_value);
write_string_f(converter, "@%s", v->sel_value);
break;
}
case MIE_TYPE_CLASS:
@@ -648,9 +649,26 @@ static b_status write_instr(
case MIE_INSTR_SETELEMENTPTR:
write_string(converter, "setelementptr");
break;
case MIE_INSTR_PHI:
write_string(converter, "phi");
case MIE_INSTR_PHI: {
struct mie_phi *phi = (struct mie_phi *)instr;
mie_type_to_string(phi->p_type, type, sizeof type);
write_string_f(converter, "phi %s ", type);
for (size_t i = 0; i < phi->p_nr_edges; i++) {
if (i > 0) {
write_string(converter, ", ");
}
write_string(converter, "[ ");
write_operand(
converter,
MIE_VALUE(phi->p_edges[i].e_incoming_block), 0);
write_string(converter, ", ");
write_operand(converter, phi->p_edges[i].e_value, 0);
write_string(converter, " ]");
}
break;
}
default:
write_string_f(converter, "<unknown>");
break;