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:
@@ -18,7 +18,7 @@ struct mie_arg *mie_arg_create(struct mie_type *type)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
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_arg *arg = MIE_ARG(v);
|
struct mie_arg *arg = MIE_ARG(v);
|
||||||
return arg->arg_type;
|
return arg->arg_type;
|
||||||
|
|||||||
18
mie/block.c
18
mie/block.c
@@ -1,11 +1,10 @@
|
|||||||
#include <mie/block.h>
|
#include <mie/block.h>
|
||||||
|
#include <mie/ctx.h>
|
||||||
#include <mie/func.h>
|
#include <mie/func.h>
|
||||||
#include <mie/instr.h>
|
#include <mie/instr.h>
|
||||||
#include <mie/type.h>
|
#include <mie/type.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static struct mie_type label_type = {};
|
|
||||||
|
|
||||||
struct mie_block *mie_block_create(struct mie_func *parent, const char *name)
|
struct mie_block *mie_block_create(struct mie_func *parent, const char *name)
|
||||||
{
|
{
|
||||||
struct mie_block *out = malloc(sizeof *out);
|
struct mie_block *out = malloc(sizeof *out);
|
||||||
@@ -62,20 +61,9 @@ bool mie_block_add_instr(struct mie_block *block, struct mie_instr *instr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_label_type(struct mie_type *out)
|
static struct mie_type *get_type(struct mie_value *v, struct mie_ctx *ctx)
|
||||||
{
|
{
|
||||||
mie_value_init(&out->t_base, MIE_VALUE_TYPE);
|
return mie_ctx_get_type(ctx, MIE_TYPE_LABEL);
|
||||||
out->t_id = MIE_TYPE_LABEL;
|
|
||||||
out->t_width = sizeof(uintptr_t) * 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct mie_type *get_type(struct mie_value *v)
|
|
||||||
{
|
|
||||||
if (!label_type.t_id) {
|
|
||||||
init_label_type(&label_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
return &label_type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cleanup(struct mie_value *value)
|
static void cleanup(struct mie_value *value)
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ struct mie_value *mie_builder_add(
|
|||||||
|
|
||||||
add->op_left = left;
|
add->op_left = left;
|
||||||
add->op_right = right;
|
add->op_right = right;
|
||||||
add->op_type = mie_value_get_type(left);
|
add->op_type = mie_value_get_type(left, builder->b_ctx);
|
||||||
|
|
||||||
if (!mie_block_add_instr(builder->b_current_block, &add->op_base)) {
|
if (!mie_block_add_instr(builder->b_current_block, &add->op_base)) {
|
||||||
free(add);
|
free(add);
|
||||||
@@ -262,7 +262,7 @@ struct mie_value *mie_builder_sub(
|
|||||||
|
|
||||||
sub->op_left = left;
|
sub->op_left = left;
|
||||||
sub->op_right = right;
|
sub->op_right = right;
|
||||||
sub->op_type = mie_value_get_type(left);
|
sub->op_type = mie_value_get_type(left, builder->b_ctx);
|
||||||
|
|
||||||
if (!mie_block_add_instr(builder->b_current_block, &sub->op_base)) {
|
if (!mie_block_add_instr(builder->b_current_block, &sub->op_base)) {
|
||||||
free(sub);
|
free(sub);
|
||||||
@@ -298,7 +298,7 @@ struct mie_value *mie_builder_mul(
|
|||||||
|
|
||||||
mul->op_left = left;
|
mul->op_left = left;
|
||||||
mul->op_right = right;
|
mul->op_right = right;
|
||||||
mul->op_type = mie_value_get_type(left);
|
mul->op_type = mie_value_get_type(left, builder->b_ctx);
|
||||||
|
|
||||||
if (!mie_block_add_instr(builder->b_current_block, &mul->op_base)) {
|
if (!mie_block_add_instr(builder->b_current_block, &mul->op_base)) {
|
||||||
free(mul);
|
free(mul);
|
||||||
@@ -334,7 +334,7 @@ struct mie_value *mie_builder_div(
|
|||||||
|
|
||||||
div->op_left = left;
|
div->op_left = left;
|
||||||
div->op_right = right;
|
div->op_right = right;
|
||||||
div->op_type = mie_value_get_type(left);
|
div->op_type = mie_value_get_type(left, builder->b_ctx);
|
||||||
|
|
||||||
if (!mie_block_add_instr(builder->b_current_block, &div->op_base)) {
|
if (!mie_block_add_instr(builder->b_current_block, &div->op_base)) {
|
||||||
free(div);
|
free(div);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ void mie_const_init(struct mie_const *c, struct mie_type *type)
|
|||||||
c->c_type = type;
|
c->c_type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
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_const *c = MIE_CONST(v);
|
struct mie_const *c = MIE_CONST(v);
|
||||||
return c->c_type;
|
return c->c_type;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
struct mie_ir_converter *mie_ir_converter_create(
|
struct mie_ir_converter *mie_ir_converter_create(
|
||||||
enum mie_ir_format src, enum mie_ir_format dest)
|
struct mie_ctx *ctx, enum mie_ir_format src, enum mie_ir_format dest)
|
||||||
{
|
{
|
||||||
if (src == dest) {
|
if (src == dest) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -19,6 +19,7 @@ struct mie_ir_converter *mie_ir_converter_create(
|
|||||||
|
|
||||||
memset(out, 0x0, sizeof *out);
|
memset(out, 0x0, sizeof *out);
|
||||||
|
|
||||||
|
out->c_ctx = ctx;
|
||||||
out->c_src_format = src;
|
out->c_src_format = src;
|
||||||
out->c_dest_format = dest;
|
out->c_dest_format = dest;
|
||||||
|
|
||||||
|
|||||||
@@ -228,7 +228,8 @@ static b_status write_operand_instr(
|
|||||||
|
|
||||||
if (flags & F_INCLUDE_TYPE) {
|
if (flags & F_INCLUDE_TYPE) {
|
||||||
char type_name[64];
|
char type_name[64];
|
||||||
struct mie_type *type = mie_value_get_type(value);
|
struct mie_type *type
|
||||||
|
= mie_value_get_type(value, converter->c_ctx);
|
||||||
mie_type_to_string(type, type_name, sizeof type_name);
|
mie_type_to_string(type, type_name, sizeof type_name);
|
||||||
write_string_f(converter, "%s ", type_name);
|
write_string_f(converter, "%s ", type_name);
|
||||||
}
|
}
|
||||||
@@ -244,7 +245,8 @@ static b_status write_operand_block(
|
|||||||
|
|
||||||
if (flags & F_INCLUDE_TYPE) {
|
if (flags & F_INCLUDE_TYPE) {
|
||||||
char type_name[64];
|
char type_name[64];
|
||||||
struct mie_type *type = mie_value_get_type(value);
|
struct mie_type *type
|
||||||
|
= mie_value_get_type(value, converter->c_ctx);
|
||||||
mie_type_to_string(type, type_name, sizeof type_name);
|
mie_type_to_string(type, type_name, sizeof type_name);
|
||||||
write_string_f(converter, "%s ", type_name);
|
write_string_f(converter, "%s ", type_name);
|
||||||
}
|
}
|
||||||
|
|||||||
19
mie/data.c
19
mie/data.c
@@ -1,19 +1,10 @@
|
|||||||
#include <blue/object/string.h>
|
#include <blue/object/string.h>
|
||||||
|
#include <mie/ctx.h>
|
||||||
#include <mie/data.h>
|
#include <mie/data.h>
|
||||||
#include <mie/type.h>
|
#include <mie/type.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* TODO combine this with the ptr_type defined in instr.c */
|
|
||||||
static struct mie_type ptr_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;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct mie_data *mie_data_create_extern_global(
|
struct mie_data *mie_data_create_extern_global(
|
||||||
struct mie_type *type, const char *ident)
|
struct mie_type *type, const char *ident)
|
||||||
{
|
{
|
||||||
@@ -50,13 +41,9 @@ struct mie_data *mie_data_create_const(struct mie_const *value)
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct mie_type *get_type(struct mie_value *v)
|
static struct mie_type *get_type(struct mie_value *v, struct mie_ctx *ctx)
|
||||||
{
|
{
|
||||||
if (!ptr_type.t_id) {
|
return mie_ctx_get_type(ctx, MIE_TYPE_PTR);
|
||||||
init_ptr_type(&ptr_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
return &ptr_type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct mie_value_type data_value_type = {
|
const struct mie_value_type data_value_type = {
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ struct mie_block *mie_func_get_last_block(struct mie_func *func)
|
|||||||
return (struct mie_block *)b_unbox(struct mie_value, entry, v_entry);
|
return (struct mie_block *)b_unbox(struct mie_value, entry, v_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
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_func *f = MIE_FUNC(v);
|
struct mie_func *f = MIE_FUNC(v);
|
||||||
return f->f_ret;
|
return f->f_ret;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
struct mie_value;
|
struct mie_value;
|
||||||
|
struct mie_ctx;
|
||||||
|
|
||||||
enum mie_ir_format {
|
enum mie_ir_format {
|
||||||
MIE_IR_NONE = 0,
|
MIE_IR_NONE = 0,
|
||||||
@@ -27,6 +28,7 @@ enum mie_ir_converter_medium {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct mie_ir_converter {
|
struct mie_ir_converter {
|
||||||
|
struct mie_ctx *c_ctx;
|
||||||
enum mie_ir_format c_src_format, c_dest_format;
|
enum mie_ir_format c_src_format, c_dest_format;
|
||||||
enum mie_ir_converter_medium c_src_medium, c_dest_medium;
|
enum mie_ir_converter_medium c_src_medium, c_dest_medium;
|
||||||
|
|
||||||
@@ -50,7 +52,7 @@ struct mie_ir_converter {
|
|||||||
};
|
};
|
||||||
|
|
||||||
MIE_API struct mie_ir_converter *mie_ir_converter_create(
|
MIE_API struct mie_ir_converter *mie_ir_converter_create(
|
||||||
enum mie_ir_format src, enum mie_ir_format dest);
|
struct mie_ctx *ctx, enum mie_ir_format src, enum mie_ir_format dest);
|
||||||
MIE_API void mie_ir_converter_destroy(struct mie_ir_converter *converter);
|
MIE_API void mie_ir_converter_destroy(struct mie_ir_converter *converter);
|
||||||
|
|
||||||
MIE_API b_status mie_ir_converter_set_src_value(
|
MIE_API b_status mie_ir_converter_set_src_value(
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#define MIE_VALUE(p) ((struct mie_value *)(p))
|
#define MIE_VALUE(p) ((struct mie_value *)(p))
|
||||||
|
|
||||||
|
struct mie_ctx;
|
||||||
struct mie_value;
|
struct mie_value;
|
||||||
|
|
||||||
enum mie_value_type_id {
|
enum mie_value_type_id {
|
||||||
@@ -29,7 +30,7 @@ enum mie_value_flags {
|
|||||||
|
|
||||||
struct mie_value_type {
|
struct mie_value_type {
|
||||||
enum mie_value_type_id t_id;
|
enum mie_value_type_id t_id;
|
||||||
struct mie_type *(*t_get_type)(struct mie_value *);
|
struct mie_type *(*t_get_type)(struct mie_value *, struct mie_ctx *);
|
||||||
void (*t_cleanup)(struct mie_value *);
|
void (*t_cleanup)(struct mie_value *);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -43,7 +44,8 @@ struct mie_value {
|
|||||||
MIE_API void mie_value_init(struct mie_value *val, enum mie_value_type_id type);
|
MIE_API void mie_value_init(struct mie_value *val, enum mie_value_type_id type);
|
||||||
MIE_API void mie_value_destroy(struct mie_value *val);
|
MIE_API void mie_value_destroy(struct mie_value *val);
|
||||||
|
|
||||||
MIE_API struct mie_type *mie_value_get_type(struct mie_value *val);
|
MIE_API struct mie_type *mie_value_get_type(
|
||||||
|
struct mie_value *val, struct mie_ctx *ctx);
|
||||||
|
|
||||||
static inline bool mie_value_is(
|
static inline bool mie_value_is(
|
||||||
const struct mie_value *val, enum mie_value_type_id type_id)
|
const struct mie_value *val, enum mie_value_type_id type_id)
|
||||||
|
|||||||
20
mie/instr.c
20
mie/instr.c
@@ -1,10 +1,9 @@
|
|||||||
|
#include <mie/ctx.h>
|
||||||
#include <mie/instr.h>
|
#include <mie/instr.h>
|
||||||
#include <mie/msg.h>
|
#include <mie/msg.h>
|
||||||
#include <mie/op.h>
|
#include <mie/op.h>
|
||||||
#include <mie/ptr.h>
|
#include <mie/ptr.h>
|
||||||
|
|
||||||
static struct mie_type ptr_type = {};
|
|
||||||
|
|
||||||
void mie_instr_init(struct mie_instr *instr, enum mie_instr_type type)
|
void mie_instr_init(struct mie_instr *instr, enum mie_instr_type type)
|
||||||
{
|
{
|
||||||
memset(instr, 0x0, sizeof *instr);
|
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;
|
instr->i_type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_ptr_type(struct mie_type *out)
|
static struct mie_type *get_type(struct mie_value *v, struct mie_ctx *ctx)
|
||||||
{
|
|
||||||
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);
|
struct mie_instr *instr = MIE_INSTR(v);
|
||||||
|
|
||||||
if (!ptr_type.t_id) {
|
|
||||||
init_ptr_type(&ptr_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (instr->i_type) {
|
switch (instr->i_type) {
|
||||||
case MIE_INSTR_RET: {
|
case MIE_INSTR_RET: {
|
||||||
struct mie_ret *ret = (struct mie_ret *)instr;
|
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_ADD:
|
||||||
case MIE_INSTR_SUB:
|
case MIE_INSTR_SUB:
|
||||||
@@ -44,7 +32,7 @@ static struct mie_type *get_type(struct mie_value *v)
|
|||||||
return load->l_type;
|
return load->l_type;
|
||||||
}
|
}
|
||||||
case MIE_INSTR_ALLOCA:
|
case MIE_INSTR_ALLOCA:
|
||||||
return &ptr_type;
|
return mie_ctx_get_type(ctx, MIE_TYPE_PTR);
|
||||||
case MIE_INSTR_MSG: {
|
case MIE_INSTR_MSG: {
|
||||||
struct mie_msg *msg = (struct mie_msg *)instr;
|
struct mie_msg *msg = (struct mie_msg *)instr;
|
||||||
return msg->msg_ret_type;
|
return msg->msg_ret_type;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ struct mie_record *mie_record_create(const struct mie_const *val)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
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_record *r = MIE_RECORD(v);
|
struct mie_record *r = MIE_RECORD(v);
|
||||||
return r->r_value->c_type;
|
return r->r_value->c_type;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include <mie/type.h>
|
#include <mie/type.h>
|
||||||
|
|
||||||
static struct mie_type *get_type(struct mie_value *v)
|
static struct mie_type *get_type(struct mie_value *v, struct mie_ctx *ctx)
|
||||||
{
|
{
|
||||||
return MIE_TYPE(v);
|
return MIE_TYPE(v);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,10 +46,10 @@ void mie_value_destroy(struct mie_value *val)
|
|||||||
free(val);
|
free(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mie_type *mie_value_get_type(struct mie_value *val)
|
struct mie_type *mie_value_get_type(struct mie_value *val, struct mie_ctx *ctx)
|
||||||
{
|
{
|
||||||
if (val->v_type->t_get_type) {
|
if (val->v_type->t_get_type) {
|
||||||
return val->v_type->t_get_type(val);
|
return val->v_type->t_get_type(val, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user