mie: refactor ir api into a separate sub-directory
This commit is contained in:
55
mie/ir/instr.c
Normal file
55
mie/ir/instr.c
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <mie/ir/ctx.h>
|
||||
#include <mie/ir/instr.h>
|
||||
#include <mie/ir/msg.h>
|
||||
#include <mie/ir/op.h>
|
||||
#include <mie/ir/ptr.h>
|
||||
|
||||
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,
|
||||
};
|
||||
Reference in New Issue
Block a user