mie: add null IR value
This commit is contained in:
17
mie/ctx.c
17
mie/ctx.c
@@ -43,6 +43,14 @@ struct mie_ctx *mie_ctx_create(void)
|
|||||||
out->ctx_true = MIE_CONST(mie_ctx_get_int(out, 1, 1));
|
out->ctx_true = MIE_CONST(mie_ctx_get_int(out, 1, 1));
|
||||||
out->ctx_false = MIE_CONST(mie_ctx_get_int(out, 0, 1));
|
out->ctx_false = MIE_CONST(mie_ctx_get_int(out, 0, 1));
|
||||||
|
|
||||||
|
out->ctx_null = malloc(sizeof *out->ctx_null);
|
||||||
|
if (!out->ctx_null) {
|
||||||
|
mie_ctx_destroy(out);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
mie_value_init(out->ctx_null, MIE_VALUE_NONE);
|
||||||
|
|
||||||
out->ctx_sel_cache = b_hashmap_create(free, free);
|
out->ctx_sel_cache = b_hashmap_create(free, free);
|
||||||
out->ctx_string_cache = b_hashmap_create(free, free);
|
out->ctx_string_cache = b_hashmap_create(free, free);
|
||||||
|
|
||||||
@@ -81,6 +89,10 @@ void mie_ctx_destroy(struct mie_ctx *ctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ctx->ctx_null) {
|
||||||
|
mie_value_destroy(ctx->ctx_null);
|
||||||
|
}
|
||||||
|
|
||||||
b_hashmap_release(ctx->ctx_sel_cache);
|
b_hashmap_release(ctx->ctx_sel_cache);
|
||||||
|
|
||||||
free(ctx);
|
free(ctx);
|
||||||
@@ -107,6 +119,11 @@ struct mie_type *mie_ctx_get_type(struct mie_ctx *ctx, enum mie_type_id type_id)
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct mie_value *mie_ctx_get_null(struct mie_ctx *ctx)
|
||||||
|
{
|
||||||
|
return ctx->ctx_null;
|
||||||
|
}
|
||||||
|
|
||||||
struct mie_type *mie_ctx_get_int_type(struct mie_ctx *ctx, unsigned int nr_bits)
|
struct mie_type *mie_ctx_get_int_type(struct mie_ctx *ctx, unsigned int nr_bits)
|
||||||
{
|
{
|
||||||
struct ctx_int_cache_entry *entry
|
struct ctx_int_cache_entry *entry
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
struct mie_ctx {
|
struct mie_ctx {
|
||||||
struct mie_const *ctx_true, *ctx_false;
|
struct mie_const *ctx_true, *ctx_false;
|
||||||
|
struct mie_value *ctx_null;
|
||||||
struct mie_type *ctx_types[__MIE_TYPE_COUNT];
|
struct mie_type *ctx_types[__MIE_TYPE_COUNT];
|
||||||
b_btree ctx_int_cache;
|
b_btree ctx_int_cache;
|
||||||
struct b_hashmap *ctx_sel_cache;
|
struct b_hashmap *ctx_sel_cache;
|
||||||
@@ -19,6 +20,7 @@ extern struct mie_type *mie_ctx_get_type(
|
|||||||
struct mie_ctx *ctx, enum mie_type_id type_id);
|
struct mie_ctx *ctx, enum mie_type_id type_id);
|
||||||
extern struct mie_type *mie_ctx_get_int_type(
|
extern struct mie_type *mie_ctx_get_int_type(
|
||||||
struct mie_ctx *ctx, unsigned int nr_bits);
|
struct mie_ctx *ctx, unsigned int nr_bits);
|
||||||
|
extern struct mie_value *mie_ctx_get_null(struct mie_ctx *ctx);
|
||||||
extern struct mie_value *mie_ctx_get_bool(struct mie_ctx *ctx, bool val);
|
extern struct mie_value *mie_ctx_get_bool(struct mie_ctx *ctx, bool val);
|
||||||
extern struct mie_value *mie_ctx_get_int(
|
extern struct mie_value *mie_ctx_get_int(
|
||||||
struct mie_ctx *ctx, long long val, unsigned int nr_bits);
|
struct mie_ctx *ctx, long long val, unsigned int nr_bits);
|
||||||
|
|||||||
@@ -259,11 +259,14 @@ static b_status write_operand(
|
|||||||
struct mie_ir_converter *converter, struct mie_value *value, int flags)
|
struct mie_ir_converter *converter, struct mie_value *value, int flags)
|
||||||
{
|
{
|
||||||
if (!value) {
|
if (!value) {
|
||||||
write_string(converter, "<null>");
|
write_string(converter, "<NULL VALUE PTR>");
|
||||||
return B_SUCCESS;
|
return B_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (value->v_type->t_id) {
|
switch (value->v_type->t_id) {
|
||||||
|
case MIE_VALUE_NONE:
|
||||||
|
write_string(converter, "null");
|
||||||
|
return B_SUCCESS;
|
||||||
case MIE_VALUE_CONST:
|
case MIE_VALUE_CONST:
|
||||||
return write_operand_const(converter, value, flags);
|
return write_operand_const(converter, value, flags);
|
||||||
case MIE_VALUE_INSTR:
|
case MIE_VALUE_INSTR:
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
#include <mie/ir/value.h>
|
#include <mie/ir/value.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
const struct mie_value_type null_value_type = {
|
||||||
|
.t_id = MIE_VALUE_NONE,
|
||||||
|
};
|
||||||
|
|
||||||
extern const struct mie_value_type module_value_type;
|
extern const struct mie_value_type module_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;
|
||||||
@@ -12,7 +16,7 @@ extern const struct mie_value_type const_value_type;
|
|||||||
extern const struct mie_value_type data_value_type;
|
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_value_type,
|
||||||
[MIE_VALUE_MODULE] = &module_value_type,
|
[MIE_VALUE_MODULE] = &module_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,
|
||||||
|
|||||||
Reference in New Issue
Block a user