mie: move mie_ctx out of the ir subsystem
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
#include <blue/object/hashmap.h>
|
#include <blue/object/hashmap.h>
|
||||||
#include <blue/object/list.h>
|
#include <blue/object/list.h>
|
||||||
#include <blue/object/string.h>
|
#include <blue/object/string.h>
|
||||||
|
#include <mie/ctx.h>
|
||||||
#include <mie/ir/const.h>
|
#include <mie/ir/const.h>
|
||||||
#include <mie/ir/ctx.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -96,14 +96,11 @@ struct mie_type *mie_ctx_get_type(struct mie_ctx *ctx, enum mie_type_id type_id)
|
|||||||
return ctx->ctx_types[type_id];
|
return ctx->ctx_types[type_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mie_type *type = malloc(sizeof *type);
|
struct mie_type *type = mie_type_create();
|
||||||
if (!type) {
|
if (!type) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(type, 0x0, sizeof *type);
|
|
||||||
|
|
||||||
mie_value_init(&type->t_base, MIE_VALUE_TYPE);
|
|
||||||
type->t_id = type_id;
|
type->t_id = type_id;
|
||||||
|
|
||||||
ctx->ctx_types[type_id] = type;
|
ctx->ctx_types[type_id] = type;
|
||||||
@@ -126,7 +123,6 @@ struct mie_type *mie_ctx_get_int_type(struct mie_ctx *ctx, unsigned int nr_bits)
|
|||||||
|
|
||||||
memset(entry, 0x0, sizeof *entry);
|
memset(entry, 0x0, sizeof *entry);
|
||||||
|
|
||||||
mie_value_init(&entry->i_type.t_base, MIE_VALUE_TYPE);
|
|
||||||
entry->i_type.t_id = MIE_TYPE_INT;
|
entry->i_type.t_id = MIE_TYPE_INT;
|
||||||
entry->i_type.t_width = nr_bits;
|
entry->i_type.t_width = nr_bits;
|
||||||
|
|
||||||
@@ -153,7 +149,6 @@ struct mie_value *mie_ctx_get_int(
|
|||||||
|
|
||||||
memset(entry, 0x0, sizeof *entry);
|
memset(entry, 0x0, sizeof *entry);
|
||||||
|
|
||||||
mie_value_init(&entry->i_type.t_base, MIE_VALUE_TYPE);
|
|
||||||
entry->i_type.t_id = MIE_TYPE_INT;
|
entry->i_type.t_id = MIE_TYPE_INT;
|
||||||
entry->i_type.t_width = nr_bits;
|
entry->i_type.t_width = nr_bits;
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
#define MIE_CTX_H_
|
#define MIE_CTX_H_
|
||||||
|
|
||||||
#include <blue/core/btree.h>
|
#include <blue/core/btree.h>
|
||||||
#include <mie/ir/type.h>
|
#include <mie/type.h>
|
||||||
|
|
||||||
struct mie_ctx {
|
struct mie_ctx {
|
||||||
struct mie_const *ctx_true, *ctx_false;
|
struct mie_const *ctx_true, *ctx_false;
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
#define MIE_ALLOCA_H_
|
#define MIE_ALLOCA_H_
|
||||||
|
|
||||||
#include <mie/ir/instr.h>
|
#include <mie/ir/instr.h>
|
||||||
#include <mie/ir/type.h>
|
#include <mie/type.h>
|
||||||
|
|
||||||
struct mie_alloca {
|
struct mie_alloca {
|
||||||
struct mie_instr a_base;
|
struct mie_instr a_base;
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
#include <blue/core/btree.h>
|
#include <blue/core/btree.h>
|
||||||
#include <mie/ir/switch.h>
|
#include <mie/ir/switch.h>
|
||||||
#include <mie/ir/type.h>
|
|
||||||
#include <mie/ir/value.h>
|
#include <mie/ir/value.h>
|
||||||
#include <mie/misc.h>
|
#include <mie/misc.h>
|
||||||
|
#include <mie/type.h>
|
||||||
|
|
||||||
struct b_hashmap;
|
struct b_hashmap;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#define MIE_MSG_H_
|
#define MIE_MSG_H_
|
||||||
|
|
||||||
#include <mie/ir/instr.h>
|
#include <mie/ir/instr.h>
|
||||||
#include <mie/ir/type.h>
|
#include <mie/type.h>
|
||||||
|
|
||||||
#define MIE_MSG(p) ((struct mie_msg *)(p))
|
#define MIE_MSG(p) ((struct mie_msg *)(p))
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#define MIE_PTR_H_
|
#define MIE_PTR_H_
|
||||||
|
|
||||||
#include <mie/ir/instr.h>
|
#include <mie/ir/instr.h>
|
||||||
#include <mie/ir/type.h>
|
#include <mie/type.h>
|
||||||
|
|
||||||
struct mie_getelementptr {
|
struct mie_getelementptr {
|
||||||
struct mie_instr gep_base;
|
struct mie_instr gep_base;
|
||||||
|
|||||||
@@ -17,17 +17,22 @@ enum mie_type_id {
|
|||||||
MIE_TYPE_LABEL = 0x09u,
|
MIE_TYPE_LABEL = 0x09u,
|
||||||
MIE_TYPE_SELECTOR = 0x0Au,
|
MIE_TYPE_SELECTOR = 0x0Au,
|
||||||
MIE_TYPE_FUNC = 0x0Bu,
|
MIE_TYPE_FUNC = 0x0Bu,
|
||||||
|
MIE_TYPE_GLUE = 0xFEu,
|
||||||
|
MIE_TYPE_OTHER = 0xFFu,
|
||||||
__MIE_TYPE_COUNT,
|
__MIE_TYPE_COUNT,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mie_type {
|
struct mie_type {
|
||||||
struct mie_value t_base;
|
struct mie_value t_base;
|
||||||
|
|
||||||
enum mie_type_id t_id;
|
enum mie_type_id t_id;
|
||||||
|
unsigned int t_count;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
unsigned int t_width;
|
unsigned int t_width;
|
||||||
b_queue t_vars;
|
b_queue t_vars;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern struct mie_type *mie_type_create(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
|
#include <mie/ctx.h>
|
||||||
#include <mie/ir/block.h>
|
#include <mie/ir/block.h>
|
||||||
#include <mie/ir/ctx.h>
|
|
||||||
#include <mie/ir/func.h>
|
#include <mie/ir/func.h>
|
||||||
#include <mie/ir/instr.h>
|
#include <mie/ir/instr.h>
|
||||||
#include <mie/ir/type.h>
|
#include <mie/type.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
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)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include <blue/object/string.h>
|
#include <blue/object/string.h>
|
||||||
|
#include <mie/ctx.h>
|
||||||
#include <mie/ir/alloca.h>
|
#include <mie/ir/alloca.h>
|
||||||
#include <mie/ir/block.h>
|
#include <mie/ir/block.h>
|
||||||
#include <mie/ir/branch.h>
|
#include <mie/ir/branch.h>
|
||||||
#include <mie/ir/builder.h>
|
#include <mie/ir/builder.h>
|
||||||
#include <mie/ir/ctx.h>
|
|
||||||
#include <mie/ir/data.h>
|
#include <mie/ir/data.h>
|
||||||
#include <mie/ir/func.h>
|
#include <mie/ir/func.h>
|
||||||
#include <mie/ir/module.h>
|
#include <mie/ir/module.h>
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#include <mie/ir/op.h>
|
#include <mie/ir/op.h>
|
||||||
#include <mie/ir/ptr.h>
|
#include <mie/ir/ptr.h>
|
||||||
#include <mie/ir/record.h>
|
#include <mie/ir/record.h>
|
||||||
#include <mie/ir/type.h>
|
#include <mie/type.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,8 @@
|
|||||||
#include <mie/ir/op.h>
|
#include <mie/ir/op.h>
|
||||||
#include <mie/ir/ptr.h>
|
#include <mie/ir/ptr.h>
|
||||||
#include <mie/ir/record.h>
|
#include <mie/ir/record.h>
|
||||||
#include <mie/ir/type.h>
|
|
||||||
#include <mie/ir/value.h>
|
#include <mie/ir/value.h>
|
||||||
|
#include <mie/type.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#define F_INCLUDE_TYPE 0x01u
|
#define F_INCLUDE_TYPE 0x01u
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <blue/object/string.h>
|
#include <blue/object/string.h>
|
||||||
#include <mie/ir/ctx.h>
|
#include <mie/ctx.h>
|
||||||
#include <mie/ir/data.h>
|
#include <mie/ir/data.h>
|
||||||
#include <mie/ir/type.h>
|
#include <mie/type.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include <mie/ir/ctx.h>
|
#include <mie/ctx.h>
|
||||||
#include <mie/ir/instr.h>
|
#include <mie/ir/instr.h>
|
||||||
#include <mie/ir/msg.h>
|
#include <mie/ir/msg.h>
|
||||||
#include <mie/ir/op.h>
|
#include <mie/ir/op.h>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <mie/ir/data.h>
|
#include <mie/ir/data.h>
|
||||||
#include <mie/ir/func.h>
|
#include <mie/ir/func.h>
|
||||||
#include <mie/ir/module.h>
|
#include <mie/ir/module.h>
|
||||||
#include <mie/ir/type.h>
|
#include <mie/type.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
#include <mie/ir/type.h>
|
|
||||||
|
|
||||||
static struct mie_type *get_type(struct mie_value *v, struct mie_ctx *ctx)
|
|
||||||
{
|
|
||||||
return MIE_TYPE(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
const struct mie_value_type type_value_type = {
|
|
||||||
.t_id = MIE_VALUE_TYPE,
|
|
||||||
.t_get_type = get_type,
|
|
||||||
};
|
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
extern const struct mie_value_type module_value_type;
|
extern const struct mie_value_type module_value_type;
|
||||||
extern const struct mie_value_type type_value_type;
|
|
||||||
extern const struct mie_value_type record_value_type;
|
extern const struct mie_value_type record_value_type;
|
||||||
extern const struct mie_value_type func_value_type;
|
extern const struct mie_value_type func_value_type;
|
||||||
extern const struct mie_value_type arg_value_type;
|
extern const struct mie_value_type arg_value_type;
|
||||||
@@ -15,7 +14,6 @@ extern const struct mie_value_type data_value_type;
|
|||||||
static const struct mie_value_type *value_types[] = {
|
static const struct mie_value_type *value_types[] = {
|
||||||
[MIE_VALUE_NONE] = NULL,
|
[MIE_VALUE_NONE] = NULL,
|
||||||
[MIE_VALUE_MODULE] = &module_value_type,
|
[MIE_VALUE_MODULE] = &module_value_type,
|
||||||
[MIE_VALUE_TYPE] = &type_value_type,
|
|
||||||
[MIE_VALUE_RECORD] = &record_value_type,
|
[MIE_VALUE_RECORD] = &record_value_type,
|
||||||
[MIE_VALUE_FUNC] = &func_value_type,
|
[MIE_VALUE_FUNC] = &func_value_type,
|
||||||
[MIE_VALUE_ARG] = &arg_value_type,
|
[MIE_VALUE_ARG] = &arg_value_type,
|
||||||
@@ -39,8 +37,8 @@ void mie_value_destroy(struct mie_value *val)
|
|||||||
val->v_type->t_cleanup(val);
|
val->v_type->t_cleanup(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (val->v_name.n_str) {
|
if (MIE_NAME_VALID(&val->v_name)) {
|
||||||
free(val->v_name.n_str);
|
mie_name_destroy(&val->v_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(val);
|
free(val);
|
||||||
|
|||||||
27
mie/type.c
Normal file
27
mie/type.c
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#include <mie/type.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static struct mie_type *get_type(struct mie_value *v, struct mie_ctx *ctx)
|
||||||
|
{
|
||||||
|
return MIE_TYPE(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct mie_value_type type_value_type = {
|
||||||
|
.t_id = MIE_VALUE_TYPE,
|
||||||
|
.t_get_type = get_type,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mie_type *mie_type_create(void)
|
||||||
|
{
|
||||||
|
struct mie_type *out = malloc(sizeof *out);
|
||||||
|
if (!out) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(out, 0x0, sizeof *out);
|
||||||
|
|
||||||
|
out->t_base.v_type = &type_value_type;
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user