mie: arith: add cmpi and constant ops

This commit is contained in:
2026-01-17 10:31:39 +00:00
parent ee9e2d3050
commit 76477be5bd
3 changed files with 128 additions and 0 deletions

View File

@@ -5,5 +5,7 @@
MIE_DIALECT_BEGIN(mie_arith, struct mie_dialect, "arith")
MIE_DIALECT_ADD_OP(mie_arith_addi);
MIE_DIALECT_ADD_OP(mie_arith_cmpi);
MIE_DIALECT_ADD_OP(mie_arith_addf);
MIE_DIALECT_ADD_OP(mie_arith_constant);
MIE_DIALECT_END()

View File

@@ -0,0 +1,80 @@
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.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) != 2
|| MIE_VECTOR_COUNT(op->op_result) != 1) {
return MIE_SUCCESS;
}
const struct mie_op_arg *left = &op->op_args.items[0];
const struct mie_op_arg *right = &op->op_args.items[1];
const struct mie_register *result = op->op_result.items[0];
const struct mie_attribute *pred_attr
= mie_attribute_map_get(&op->op_attrib, "predicate");
long long pred;
if (!mie_int_get_value(pred_attr, &pred)) {
return MIE_SUCCESS;
}
b_stream_write_char(printer->p_stream, ' ');
switch (pred) {
case 0:
b_stream_write_string(printer->p_stream, "eq", NULL);
break;
case 1:
b_stream_write_string(printer->p_stream, "ne", NULL);
break;
case 2:
b_stream_write_string(printer->p_stream, "slt", NULL);
break;
case 3:
b_stream_write_string(printer->p_stream, "sle", NULL);
break;
case 4:
b_stream_write_string(printer->p_stream, "sgt", NULL);
break;
case 5:
b_stream_write_string(printer->p_stream, "sge", NULL);
break;
case 6:
b_stream_write_string(printer->p_stream, "ult", NULL);
break;
case 7:
b_stream_write_string(printer->p_stream, "ule", NULL);
break;
case 8:
b_stream_write_string(printer->p_stream, "ugt", NULL);
break;
case 9:
b_stream_write_string(printer->p_stream, "uge", NULL);
break;
default:
return MIE_SUCCESS;
}
b_stream_write_char(printer->p_stream, ' ');
mie_printer_print_op_arg(printer, left, false);
b_stream_write_string(printer->p_stream, ", ", NULL);
mie_printer_print_op_arg(printer, right, false);
b_stream_write_string(printer->p_stream, " : ", NULL);
mie_printer_print_type(printer, mie_op_arg_get_type(left));
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
MIE_OP_DEFINITION_BEGIN(mie_arith_cmpi, "cmpi")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -0,0 +1,46 @@
#include <mie/attribute/attribute.h>
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.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)
{
const struct mie_attribute *value
= mie_attribute_map_get(&op->op_attrib, "value");
if (!value) {
return MIE_SUCCESS;
}
const struct mie_type *type = NULL;
if (mie_attribute_check_name(value, "builtin", "int")) {
const struct mie_int *i = (const struct mie_int *)value;
b_stream_write_fmt(
printer->p_stream, NULL, " %lld : ", i->i_val.v_small);
type = i->i_type;
} else if (mie_attribute_check_name(value, "builtin", "float")) {
const struct mie_float *f = (const struct mie_float *)value;
double d;
mie_float_get_value(value, &d);
b_stream_write_fmt(printer->p_stream, NULL, " %g : ", d);
type = f->f_type;
} else {
return MIE_SUCCESS;
}
mie_printer_print_type(printer, type);
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
MIE_OP_DEFINITION_BEGIN(mie_arith_constant, "constant")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()