mie: refactor ir api into a separate sub-directory
This commit is contained in:
56
mie/ir/value.c
Normal file
56
mie/ir/value.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <mie/ir/const.h>
|
||||
#include <mie/ir/value.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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 func_value_type;
|
||||
extern const struct mie_value_type arg_value_type;
|
||||
extern const struct mie_value_type block_value_type;
|
||||
extern const struct mie_value_type instr_value_type;
|
||||
extern const struct mie_value_type const_value_type;
|
||||
extern const struct mie_value_type data_value_type;
|
||||
|
||||
static const struct mie_value_type *value_types[] = {
|
||||
[MIE_VALUE_NONE] = NULL,
|
||||
[MIE_VALUE_MODULE] = &module_value_type,
|
||||
[MIE_VALUE_TYPE] = &type_value_type,
|
||||
[MIE_VALUE_RECORD] = &record_value_type,
|
||||
[MIE_VALUE_FUNC] = &func_value_type,
|
||||
[MIE_VALUE_ARG] = &arg_value_type,
|
||||
[MIE_VALUE_BLOCK] = &block_value_type,
|
||||
[MIE_VALUE_INSTR] = &instr_value_type,
|
||||
[MIE_VALUE_CONST] = &const_value_type,
|
||||
[MIE_VALUE_DATA] = &data_value_type,
|
||||
};
|
||||
static const size_t nr_value_types = sizeof value_types / sizeof value_types[0];
|
||||
|
||||
void mie_value_init(struct mie_value *val, enum mie_value_type_id type)
|
||||
{
|
||||
memset(val, 0x0, sizeof *val);
|
||||
|
||||
val->v_type = value_types[type];
|
||||
}
|
||||
|
||||
void mie_value_destroy(struct mie_value *val)
|
||||
{
|
||||
if (val->v_type && val->v_type->t_cleanup) {
|
||||
val->v_type->t_cleanup(val);
|
||||
}
|
||||
|
||||
if (val->v_name.n_str) {
|
||||
free(val->v_name.n_str);
|
||||
}
|
||||
|
||||
free(val);
|
||||
}
|
||||
|
||||
struct mie_type *mie_value_get_type(struct mie_value *val, struct mie_ctx *ctx)
|
||||
{
|
||||
if (val->v_type->t_get_type) {
|
||||
return val->v_type->t_get_type(val, ctx);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
Reference in New Issue
Block a user