#include #include #include #include #include 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; } static struct mie_type *get_type(struct mie_value *v, struct mie_ctx *ctx) { struct mie_instr *instr = MIE_INSTR(v); switch (instr->i_type) { case MIE_INSTR_RET: { struct mie_ret *ret = (struct mie_ret *)instr; return mie_value_get_type(ret->r_val, ctx); } 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; } 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); case MIE_INSTR_LOAD: { struct mie_load *load = (struct mie_load *)instr; return load->l_type; } case MIE_INSTR_ALLOCA: return mie_ctx_get_type(ctx, MIE_TYPE_PTR); case MIE_INSTR_MSG: { struct mie_msg *msg = (struct mie_msg *)instr; return msg->msg_ret_type; } default: return NULL; } } const struct mie_value_type instr_value_type = { .t_id = MIE_VALUE_INSTR, .t_get_type = get_type, };