58 lines
1.7 KiB
C
58 lines
1.7 KiB
C
#include <mie/dialect/dialect.h>
|
|
#include <mie/ir/emit.h>
|
|
#include <mie/ir/op-definition.h>
|
|
#include <mie/ir/op.h>
|
|
#include <mie/macros.h>
|
|
#include <mie/print/printer.h>
|
|
|
|
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
|
|
{
|
|
if (MIE_VECTOR_COUNT(op->op_args) != 1) {
|
|
return MIE_SUCCESS;
|
|
}
|
|
|
|
if (MIE_VECTOR_COUNT(op->op_successors) != 2) {
|
|
return MIE_SUCCESS;
|
|
}
|
|
|
|
const struct mie_op_arg *cond = &op->op_args.items[0];
|
|
const struct mie_op_successor *if_true = &op->op_successors.items[0];
|
|
const struct mie_op_successor *if_false = &op->op_successors.items[1];
|
|
|
|
b_stream_write_char(printer->p_stream, ' ');
|
|
mie_printer_print_op_arg(printer, cond, false);
|
|
b_stream_write_string(printer->p_stream, ", ", NULL);
|
|
mie_printer_print_op_successor(printer, if_true, true);
|
|
b_stream_write_string(printer->p_stream, ", ", NULL);
|
|
mie_printer_print_op_successor(printer, if_false, true);
|
|
|
|
return MIE_SUCCESS;
|
|
}
|
|
|
|
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
|
|
{
|
|
return MIE_SUCCESS;
|
|
}
|
|
|
|
struct mie_op *mie_cf_br_cond_put(
|
|
struct mie_emitter *e, struct mie_register *cond,
|
|
struct mie_block *true_block, struct mie_register **true_args,
|
|
size_t nr_true_args, struct mie_block *false_block,
|
|
struct mie_register **false_args, size_t nr_false_args)
|
|
{
|
|
struct mie_op *op = mie_emitter_put_op(e, "cf", "br-cond", &cond, 1);
|
|
if (!op) {
|
|
return NULL;
|
|
}
|
|
|
|
mie_op_add_successor(op, true_block, true_args, nr_true_args);
|
|
mie_op_add_successor(op, false_block, false_args, nr_false_args);
|
|
|
|
return op;
|
|
}
|
|
|
|
MIE_OP_DEFINITION_BEGIN(mie_cf_br_cond, "br-cond")
|
|
MIE_OP_DEFINITION_PRINT(print);
|
|
MIE_OP_DEFINITION_PARSE(parse);
|
|
MIE_OP_DEFINITION_END()
|