mie: implement comparison and branch instruction generation

This commit is contained in:
2025-04-28 15:41:31 +01:00
parent 1431cb7b47
commit 6af9b62b88
5 changed files with 286 additions and 16 deletions

View File

@@ -593,6 +593,18 @@ static b_status write_instr(
write_operand(converter, MIE_VALUE(br->b_dest), F_INCLUDE_TYPE);
break;
}
case MIE_INSTR_BR_IF: {
struct mie_branch_if *br = (struct mie_branch_if *)instr;
write_string(converter, "br ");
write_operand(converter, MIE_VALUE(br->b_cond), F_INCLUDE_TYPE);
write_string(converter, ", ");
write_operand(
converter, MIE_VALUE(br->b_true_block), F_INCLUDE_TYPE);
write_string(converter, ", ");
write_operand(
converter, MIE_VALUE(br->b_false_block), F_INCLUDE_TYPE);
break;
}
case MIE_INSTR_MSG: {
struct mie_msg *msg = (struct mie_msg *)instr;
mie_type_to_string(msg->msg_ret_type, type, sizeof type);
@@ -617,21 +629,60 @@ static b_status write_instr(
break;
}
case MIE_INSTR_CMP_EQ:
write_string(converter, "cmp eq");
case MIE_INSTR_CMP_EQ: {
struct mie_binary_op *op = (struct mie_binary_op *)instr;
mie_type_to_string(op->op_type, type, sizeof type);
write_string_f(converter, "cmp eq %s ", type);
write_operand(converter, op->op_left, 0);
write_string(converter, ", ");
write_operand(converter, op->op_right, 0);
break;
case MIE_INSTR_CMP_LT:
write_string(converter, "cmp lt");
}
case MIE_INSTR_CMP_NEQ: {
struct mie_binary_op *op = (struct mie_binary_op *)instr;
mie_type_to_string(op->op_type, type, sizeof type);
write_string_f(converter, "cmp neq %s ", type);
write_operand(converter, op->op_left, 0);
write_string(converter, ", ");
write_operand(converter, op->op_right, 0);
break;
case MIE_INSTR_CMP_GT:
write_string(converter, "cmp gt");
}
case MIE_INSTR_CMP_LT: {
struct mie_binary_op *op = (struct mie_binary_op *)instr;
mie_type_to_string(op->op_type, type, sizeof type);
write_string_f(converter, "cmp lt %s ", type);
write_operand(converter, op->op_left, 0);
write_string(converter, ", ");
write_operand(converter, op->op_right, 0);
break;
case MIE_INSTR_CMP_LEQ:
write_string(converter, "cmp leq");
}
case MIE_INSTR_CMP_LEQ: {
struct mie_binary_op *op = (struct mie_binary_op *)instr;
mie_type_to_string(op->op_type, type, sizeof type);
write_string_f(converter, "cmp leq %s ", type);
write_operand(converter, op->op_left, 0);
write_string(converter, ", ");
write_operand(converter, op->op_right, 0);
break;
case MIE_INSTR_CMP_GEQ:
write_string(converter, "cmp geq");
}
case MIE_INSTR_CMP_GT: {
struct mie_binary_op *op = (struct mie_binary_op *)instr;
mie_type_to_string(op->op_type, type, sizeof type);
write_string_f(converter, "cmp gt %s ", type);
write_operand(converter, op->op_left, 0);
write_string(converter, ", ");
write_operand(converter, op->op_right, 0);
break;
}
case MIE_INSTR_CMP_GEQ: {
struct mie_binary_op *op = (struct mie_binary_op *)instr;
mie_type_to_string(op->op_type, type, sizeof type);
write_string_f(converter, "cmp geq %s ", type);
write_operand(converter, op->op_left, 0);
write_string(converter, ", ");
write_operand(converter, op->op_right, 0);
break;
}
case MIE_INSTR_GETELEMENTPTR:
write_string(converter, "getelementptr");
break;