2025-08-16 20:53:40 +01:00
|
|
|
#include <mie/ctx.h>
|
2025-06-02 11:31:19 +01:00
|
|
|
#include <mie/ir/instr.h>
|
|
|
|
|
#include <mie/ir/msg.h>
|
|
|
|
|
#include <mie/ir/op.h>
|
|
|
|
|
#include <mie/ir/ptr.h>
|
2025-04-13 18:34:02 +01:00
|
|
|
|
2025-04-11 13:40:54 +01:00
|
|
|
void mie_instr_init(struct mie_instr *instr, enum mie_instr_type type)
|
|
|
|
|
{
|
|
|
|
|
memset(instr, 0x0, sizeof *instr);
|
|
|
|
|
mie_value_init(&instr->i_base, MIE_VALUE_INSTR);
|
|
|
|
|
instr->i_type = type;
|
|
|
|
|
}
|
2025-04-13 18:34:02 +01:00
|
|
|
|
2025-04-28 15:38:25 +01:00
|
|
|
static struct mie_type *get_type(struct mie_value *v, struct mie_ctx *ctx)
|
2025-04-13 18:34:02 +01:00
|
|
|
{
|
|
|
|
|
struct mie_instr *instr = MIE_INSTR(v);
|
|
|
|
|
|
|
|
|
|
switch (instr->i_type) {
|
|
|
|
|
case MIE_INSTR_RET: {
|
|
|
|
|
struct mie_ret *ret = (struct mie_ret *)instr;
|
2025-04-28 15:38:25 +01:00
|
|
|
return mie_value_get_type(ret->r_val, ctx);
|
2025-04-13 18:34:02 +01:00
|
|
|
}
|
|
|
|
|
case MIE_INSTR_ADD:
|
|
|
|
|
case MIE_INSTR_SUB:
|
|
|
|
|
case MIE_INSTR_MUL:
|
|
|
|
|
case MIE_INSTR_DIV: {
|
|
|
|
|
struct mie_binary_op *op = (struct mie_binary_op *)instr;
|
|
|
|
|
return op->op_type;
|
|
|
|
|
}
|
2025-04-28 15:41:31 +01:00
|
|
|
case MIE_INSTR_CMP_EQ:
|
|
|
|
|
case MIE_INSTR_CMP_NEQ:
|
|
|
|
|
case MIE_INSTR_CMP_LT:
|
|
|
|
|
case MIE_INSTR_CMP_LEQ:
|
|
|
|
|
case MIE_INSTR_CMP_GT:
|
|
|
|
|
case MIE_INSTR_CMP_GEQ:
|
|
|
|
|
return mie_ctx_get_int_type(ctx, 1);
|
2025-04-13 18:34:02 +01:00
|
|
|
case MIE_INSTR_LOAD: {
|
|
|
|
|
struct mie_load *load = (struct mie_load *)instr;
|
|
|
|
|
return load->l_type;
|
|
|
|
|
}
|
|
|
|
|
case MIE_INSTR_ALLOCA:
|
2025-04-28 15:38:25 +01:00
|
|
|
return mie_ctx_get_type(ctx, MIE_TYPE_PTR);
|
2025-04-17 21:43:02 +01:00
|
|
|
case MIE_INSTR_MSG: {
|
|
|
|
|
struct mie_msg *msg = (struct mie_msg *)instr;
|
|
|
|
|
return msg->msg_ret_type;
|
|
|
|
|
}
|
2025-04-13 18:34:02 +01:00
|
|
|
default:
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const struct mie_value_type instr_value_type = {
|
|
|
|
|
.t_id = MIE_VALUE_INSTR,
|
|
|
|
|
.t_get_type = get_type,
|
|
|
|
|
};
|