mie: implement generating extern global data items
This commit is contained in:
48
mie/data.c
Normal file
48
mie/data.c
Normal file
@@ -0,0 +1,48 @@
|
||||
#include <blue/object/string.h>
|
||||
#include <mie/data.h>
|
||||
#include <mie/type.h>
|
||||
#include <stdlib.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_type *type, const char *ident)
|
||||
{
|
||||
struct mie_data *data = malloc(sizeof *data);
|
||||
if (!data) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(data, 0x0, sizeof *data);
|
||||
|
||||
mie_value_init(&data->d_base, MIE_VALUE_DATA);
|
||||
|
||||
data->d_type = MIE_DATA_EXTERN_GLOBAL;
|
||||
data->d_extern_global.g_type = type;
|
||||
data->d_base.v_name.n_str = b_strdup(ident);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static struct mie_type *get_type(struct mie_value *v)
|
||||
{
|
||||
if (!ptr_type.t_id) {
|
||||
init_ptr_type(&ptr_type);
|
||||
}
|
||||
|
||||
return &ptr_type;
|
||||
}
|
||||
|
||||
const struct mie_value_type data_value_type = {
|
||||
.t_id = MIE_VALUE_DATA,
|
||||
.t_get_type = get_type,
|
||||
};
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <mie/value.h>
|
||||
|
||||
#define MIE_DATA(p) ((struct mie_data *)(p))
|
||||
|
||||
enum mie_data_type {
|
||||
MIE_DATA_NONE = 0,
|
||||
MIE_DATA_EXTERN_GLOBAL,
|
||||
@@ -12,7 +14,18 @@ enum mie_data_type {
|
||||
struct mie_data {
|
||||
struct mie_value d_base;
|
||||
enum mie_data_type d_type;
|
||||
struct mie_value *d_data;
|
||||
union {
|
||||
struct {
|
||||
struct mie_value *c_value;
|
||||
} d_const;
|
||||
|
||||
struct {
|
||||
struct mie_type *g_type;
|
||||
} d_extern_global;
|
||||
};
|
||||
};
|
||||
|
||||
extern struct mie_data *mie_data_create_extern_global(
|
||||
struct mie_type *type, const char *ident);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user