mie: ctx is now used to query the type of a value
this allows value get_type callbacks to use mie_ctx to obtain mie_type pointers, rather than having to define their own static versions of the type structs.
This commit is contained in:
20
mie/instr.c
20
mie/instr.c
@@ -1,10 +1,9 @@
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/instr.h>
|
||||
#include <mie/msg.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)
|
||||
{
|
||||
memset(instr, 0x0, sizeof *instr);
|
||||
@@ -12,25 +11,14 @@ void mie_instr_init(struct mie_instr *instr, enum mie_instr_type type)
|
||||
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)
|
||||
static struct mie_type *get_type(struct mie_value *v, struct mie_ctx *ctx)
|
||||
{
|
||||
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);
|
||||
return mie_value_get_type(ret->r_val, ctx);
|
||||
}
|
||||
case MIE_INSTR_ADD:
|
||||
case MIE_INSTR_SUB:
|
||||
@@ -44,7 +32,7 @@ static struct mie_type *get_type(struct mie_value *v)
|
||||
return load->l_type;
|
||||
}
|
||||
case MIE_INSTR_ALLOCA:
|
||||
return &ptr_type;
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user