mie: implement more ir building functionality
This commit is contained in:
47
mie/instr.c
47
mie/instr.c
@@ -1,4 +1,8 @@
|
||||
#include <mie/instr.h>
|
||||
#include <mie/op.h>
|
||||
#include <mie/ptr.h>
|
||||
|
||||
static struct mie_type ptr_type = {};
|
||||
|
||||
void mie_instr_init(struct mie_instr *instr, enum mie_instr_type type)
|
||||
{
|
||||
@@ -6,3 +10,46 @@ void mie_instr_init(struct mie_instr *instr, enum mie_instr_type type)
|
||||
mie_value_init(&instr->i_base, MIE_VALUE_INSTR);
|
||||
instr->i_type = type;
|
||||
}
|
||||
|
||||
static void init_ptr_type(struct mie_type *out)
|
||||
{
|
||||
mie_value_init(&out->t_base, MIE_VALUE_TYPE);
|
||||
out->t_id = MIE_TYPE_PTR;
|
||||
out->t_width = sizeof(uintptr_t) * 8;
|
||||
}
|
||||
|
||||
static struct mie_type *get_type(struct mie_value *v)
|
||||
{
|
||||
struct mie_instr *instr = MIE_INSTR(v);
|
||||
|
||||
if (!ptr_type.t_id) {
|
||||
init_ptr_type(&ptr_type);
|
||||
}
|
||||
|
||||
switch (instr->i_type) {
|
||||
case MIE_INSTR_RET: {
|
||||
struct mie_ret *ret = (struct mie_ret *)instr;
|
||||
return mie_value_get_type(ret->r_val);
|
||||
}
|
||||
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_LOAD: {
|
||||
struct mie_load *load = (struct mie_load *)instr;
|
||||
return load->l_type;
|
||||
}
|
||||
case MIE_INSTR_ALLOCA:
|
||||
return &ptr_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