mie: update bluelib api usage
This commit is contained in:
@@ -11,5 +11,5 @@ else ()
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
target_include_directories(mie PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/)
|
target_include_directories(mie PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/)
|
||||||
target_link_libraries(mie Bluelib::Core Bluelib::Object)
|
target_link_libraries(mie Bluelib::Core Bluelib::Ds)
|
||||||
target_compile_definitions(mie PRIVATE MIE_EXPORT=1 MIE_STATIC=${IVY_STATIC})
|
target_compile_definitions(mie PRIVATE MIE_EXPORT=1 MIE_STATIC=${IVY_STATIC})
|
||||||
|
|||||||
30
mie/ctx.c
30
mie/ctx.c
@@ -1,6 +1,6 @@
|
|||||||
#include <blue/object/hashmap.h>
|
#include <blue/ds/hashmap.h>
|
||||||
#include <blue/object/list.h>
|
#include <blue/ds/list.h>
|
||||||
#include <blue/object/string.h>
|
#include <blue/ds/string.h>
|
||||||
#include <mie/ctx.h>
|
#include <mie/ctx.h>
|
||||||
#include <mie/ir/const.h>
|
#include <mie/ir/const.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -62,23 +62,25 @@ void mie_ctx_destroy(struct mie_ctx *ctx)
|
|||||||
ctx->ctx_true = NULL;
|
ctx->ctx_true = NULL;
|
||||||
ctx->ctx_false = NULL;
|
ctx->ctx_false = NULL;
|
||||||
|
|
||||||
b_btree_iterator it = {};
|
b_btree_node *node = b_btree_first(&ctx->ctx_int_cache);
|
||||||
b_btree_iterator_begin(&ctx->ctx_int_cache, &it);
|
while (node) {
|
||||||
while (b_btree_iterator_is_valid(&it)) {
|
|
||||||
struct ctx_int_cache_entry *entry
|
struct ctx_int_cache_entry *entry
|
||||||
= b_unbox(struct ctx_int_cache_entry, it.node, i_node);
|
= b_unbox(struct ctx_int_cache_entry, node, i_node);
|
||||||
b_btree_iterator_erase(&it);
|
b_btree_node *next = b_btree_next(node);
|
||||||
|
b_btree_delete(&ctx->ctx_int_cache, node);
|
||||||
|
|
||||||
b_btree_iterator it2 = {};
|
b_btree_node *node2 = b_btree_first(&entry->i_values);
|
||||||
b_btree_iterator_begin(&entry->i_values, &it2);
|
while (node2) {
|
||||||
while (b_btree_iterator_is_valid(&it2)) {
|
|
||||||
struct ctx_int_value_cache_entry *value = b_unbox(
|
struct ctx_int_value_cache_entry *value = b_unbox(
|
||||||
struct ctx_int_value_cache_entry, it2.node, i_node);
|
struct ctx_int_value_cache_entry, node2, i_node);
|
||||||
b_btree_iterator_erase(&it2);
|
b_btree_node *next2 = b_btree_next(node2);
|
||||||
|
b_btree_delete(&entry->i_values, node2);
|
||||||
free(value);
|
free(value);
|
||||||
|
node2 = next2;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(entry);
|
free(entry);
|
||||||
|
node = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t nr_types = sizeof ctx->ctx_types / sizeof ctx->ctx_types[0];
|
const size_t nr_types = sizeof ctx->ctx_types / sizeof ctx->ctx_types[0];
|
||||||
@@ -93,7 +95,7 @@ void mie_ctx_destroy(struct mie_ctx *ctx)
|
|||||||
mie_value_destroy(ctx->ctx_null);
|
mie_value_destroy(ctx->ctx_null);
|
||||||
}
|
}
|
||||||
|
|
||||||
b_hashmap_release(ctx->ctx_sel_cache);
|
b_hashmap_unref(ctx->ctx_sel_cache);
|
||||||
|
|
||||||
free(ctx);
|
free(ctx);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define MIE_CTX_H_
|
#define MIE_CTX_H_
|
||||||
|
|
||||||
#include <blue/core/btree.h>
|
#include <blue/core/btree.h>
|
||||||
|
#include <blue/ds/hashmap.h>
|
||||||
#include <mie/type.h>
|
#include <mie/type.h>
|
||||||
|
|
||||||
struct mie_ctx {
|
struct mie_ctx {
|
||||||
@@ -9,8 +10,8 @@ struct mie_ctx {
|
|||||||
struct mie_value *ctx_null;
|
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;
|
b_hashmap *ctx_sel_cache;
|
||||||
struct b_hashmap *ctx_string_cache;
|
b_hashmap *ctx_string_cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct mie_ctx *mie_ctx_create(void);
|
extern struct mie_ctx *mie_ctx_create(void);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef MIE_CONST_H_
|
#ifndef MIE_CONST_H_
|
||||||
#define MIE_CONST_H_
|
#define MIE_CONST_H_
|
||||||
|
|
||||||
|
#include <blue/ds/list.h>
|
||||||
#include <mie/ir/value.h>
|
#include <mie/ir/value.h>
|
||||||
#include <mie/type.h>
|
#include <mie/type.h>
|
||||||
|
|
||||||
@@ -13,8 +14,6 @@
|
|||||||
#define MIE_SELECTOR(p) ((struct mie_selector *)(p))
|
#define MIE_SELECTOR(p) ((struct mie_selector *)(p))
|
||||||
#define MIE_ARRAY(p) ((struct mie_array *)(p))
|
#define MIE_ARRAY(p) ((struct mie_array *)(p))
|
||||||
|
|
||||||
struct b_list;
|
|
||||||
|
|
||||||
struct mie_const {
|
struct mie_const {
|
||||||
struct mie_value c_base;
|
struct mie_value c_base;
|
||||||
struct mie_type *c_type;
|
struct mie_type *c_type;
|
||||||
@@ -47,7 +46,7 @@ struct mie_selector {
|
|||||||
|
|
||||||
struct mie_array {
|
struct mie_array {
|
||||||
struct mie_const a_base;
|
struct mie_const a_base;
|
||||||
struct b_list *a_values;
|
b_list *a_values;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void mie_const_init(struct mie_const *c, struct mie_type *type);
|
extern void mie_const_init(struct mie_const *c, struct mie_type *type);
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
#define MIE_CONVERT_H_
|
#define MIE_CONVERT_H_
|
||||||
|
|
||||||
#include <blue/core/stringstream.h>
|
#include <blue/core/stringstream.h>
|
||||||
#include <blue/object/bitbuffer.h>
|
#include <blue/ds/bitbuffer.h>
|
||||||
#include <blue/object/string.h>
|
#include <blue/ds/string.h>
|
||||||
#include <mie/misc.h>
|
#include <mie/misc.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
#define MIE_MODULE(p) ((struct mie_module *)(p))
|
#define MIE_MODULE(p) ((struct mie_module *)(p))
|
||||||
|
|
||||||
#include <blue/core/queue.h>
|
#include <blue/core/queue.h>
|
||||||
|
#include <blue/ds/hashmap.h>
|
||||||
#include <mie/ir/value.h>
|
#include <mie/ir/value.h>
|
||||||
#include <mie/name.h>
|
#include <mie/name.h>
|
||||||
|
|
||||||
struct mie_func;
|
struct mie_func;
|
||||||
struct b_hashmap;
|
|
||||||
|
|
||||||
struct mie_module {
|
struct mie_module {
|
||||||
struct mie_value m_base;
|
struct mie_value m_base;
|
||||||
@@ -17,8 +17,8 @@ struct mie_module {
|
|||||||
b_queue m_types;
|
b_queue m_types;
|
||||||
b_queue m_func;
|
b_queue m_func;
|
||||||
|
|
||||||
struct b_hashmap *m_data;
|
b_hashmap *m_data;
|
||||||
struct b_hashmap *m_data_strings;
|
b_hashmap *m_data_strings;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct mie_module *mie_module_create(void);
|
extern struct mie_module *mie_module_create(void);
|
||||||
|
|||||||
@@ -31,20 +31,9 @@ struct mie_select_graph {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct mie_select_use_iterator {
|
struct mie_select_use_iterator {
|
||||||
b_queue_iterator it_base;
|
b_queue_entry *it_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define mie_select_use_foreach(it, q) b_queue_foreach (&(it)->it_base, q)
|
|
||||||
|
|
||||||
static inline struct mie_select_use *mie_select_use_iterator_unbox(
|
|
||||||
struct mie_select_use_iterator *it)
|
|
||||||
{
|
|
||||||
return b_unbox(struct mie_select_use, it->it_base.entry, u_entry);
|
|
||||||
}
|
|
||||||
MIE_API void mie_select_use_iterator_next(struct mie_select_use_iterator *it);
|
|
||||||
MIE_API bool mie_select_use_iterator_is_valid(
|
|
||||||
const struct mie_select_use_iterator *it);
|
|
||||||
|
|
||||||
MIE_API struct mie_select_graph *mie_select_graph_create(struct mie_ctx *ctx);
|
MIE_API struct mie_select_graph *mie_select_graph_create(struct mie_ctx *ctx);
|
||||||
MIE_API void mie_select_graph_destroy(struct mie_select_graph *graph);
|
MIE_API void mie_select_graph_destroy(struct mie_select_graph *graph);
|
||||||
|
|
||||||
|
|||||||
@@ -61,13 +61,13 @@ struct mie_select_node {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct mie_select_node_iterator {
|
struct mie_select_node_iterator {
|
||||||
b_queue_iterator it_base;
|
b_queue_entry *it_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline struct mie_select_node *mie_select_node_iterator_unbox(
|
static inline struct mie_select_node *mie_select_node_iterator_unbox(
|
||||||
struct mie_select_node_iterator *it)
|
struct mie_select_node_iterator *it)
|
||||||
{
|
{
|
||||||
return b_unbox(struct mie_select_node, it->it_base.entry, n_entry);
|
return b_unbox(struct mie_select_node, it->it_ptr, n_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
MIE_API void mie_select_node_iterator_next(struct mie_select_node_iterator *it);
|
MIE_API void mie_select_node_iterator_next(struct mie_select_node_iterator *it);
|
||||||
|
|||||||
@@ -70,19 +70,26 @@ static void cleanup(struct mie_value *value)
|
|||||||
{
|
{
|
||||||
struct mie_block *block = MIE_BLOCK(value);
|
struct mie_block *block = MIE_BLOCK(value);
|
||||||
|
|
||||||
b_queue_iterator it;
|
b_queue_entry *entry = b_queue_first(&block->b_phi);
|
||||||
b_queue_iterator_begin(&block->b_phi, &it);
|
b_queue_entry *next = NULL;
|
||||||
while (b_queue_iterator_is_valid(&it)) {
|
|
||||||
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
while (entry) {
|
||||||
b_queue_iterator_erase(&it);
|
struct mie_value *v = b_unbox(struct mie_value, entry, v_entry);
|
||||||
|
next = b_queue_next(entry);
|
||||||
|
b_queue_delete(&block->b_phi, entry);
|
||||||
mie_value_destroy(v);
|
mie_value_destroy(v);
|
||||||
|
|
||||||
|
entry = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
b_queue_iterator_begin(&block->b_instr, &it);
|
entry = b_queue_first(&block->b_instr);
|
||||||
while (b_queue_iterator_is_valid(&it)) {
|
while (entry) {
|
||||||
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
struct mie_value *v = b_unbox(struct mie_value, entry, v_entry);
|
||||||
b_queue_iterator_erase(&it);
|
next = b_queue_next(entry);
|
||||||
|
b_queue_delete(&block->b_instr, entry);
|
||||||
mie_value_destroy(v);
|
mie_value_destroy(v);
|
||||||
|
|
||||||
|
entry = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block->b_terminator) {
|
if (block->b_terminator) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include <blue/object/string.h>
|
#include <blue/ds/string.h>
|
||||||
#include <mie/ctx.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>
|
||||||
@@ -52,15 +52,16 @@ struct mie_record *mie_builder_put_record(
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
b_queue_iterator it = {};
|
b_queue_entry *entry = b_queue_first(&builder->b_module->m_records);
|
||||||
b_queue_foreach (&it, &builder->b_module->m_records) {
|
while (entry) {
|
||||||
struct mie_value *rec
|
struct mie_value *rec = b_unbox(struct mie_value, entry, v_entry);
|
||||||
= b_unbox(struct mie_value, it.entry, v_entry);
|
|
||||||
|
|
||||||
if (!strcmp(rec->v_name.n_str, name)) {
|
if (!strcmp(rec->v_name.n_str, name)) {
|
||||||
/* TODO what to do about `val` here? */
|
/* TODO what to do about `val` here? */
|
||||||
return MIE_RECORD(rec);
|
return MIE_RECORD(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entry = b_queue_next(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mie_record *rec = mie_record_create(val);
|
struct mie_record *rec = mie_record_create(val);
|
||||||
@@ -77,14 +78,15 @@ struct mie_record *mie_builder_get_record(
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
b_queue_iterator it = {};
|
b_queue_entry *entry = b_queue_first(&builder->b_module->m_records);
|
||||||
b_queue_foreach (&it, &builder->b_module->m_records) {
|
while (entry) {
|
||||||
struct mie_value *rec
|
struct mie_value *rec = b_unbox(struct mie_value, entry, v_entry);
|
||||||
= b_unbox(struct mie_value, it.entry, v_entry);
|
|
||||||
|
|
||||||
if (!strcmp(rec->v_name.n_str, name)) {
|
if (!strcmp(rec->v_name.n_str, name)) {
|
||||||
return MIE_RECORD(rec);
|
return MIE_RECORD(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entry = b_queue_next(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "convert.h"
|
#include "convert.h"
|
||||||
|
|
||||||
#include <blue/object/hashmap.h>
|
#include <blue/ds/hashmap.h>
|
||||||
#include <blue/object/list.h>
|
#include <blue/ds/list.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <mie/ir/alloca.h>
|
#include <mie/ir/alloca.h>
|
||||||
#include <mie/ir/arg.h>
|
#include <mie/ir/arg.h>
|
||||||
@@ -32,7 +32,8 @@ b_status write_char(struct mie_ir_converter *converter, char c)
|
|||||||
|
|
||||||
switch (converter->c_dest_medium) {
|
switch (converter->c_dest_medium) {
|
||||||
case MIE_IR_CONVERTER_STRINGSTREAM:
|
case MIE_IR_CONVERTER_STRINGSTREAM:
|
||||||
return b_stringstream_add(converter->c_dest.stringstream, s);
|
return b_stream_write_string(
|
||||||
|
converter->c_dest.stringstream, s, NULL);
|
||||||
case MIE_IR_CONVERTER_STRING:
|
case MIE_IR_CONVERTER_STRING:
|
||||||
b_string_append_cstr(converter->c_dest.string, s);
|
b_string_append_cstr(converter->c_dest.string, s);
|
||||||
return B_SUCCESS;
|
return B_SUCCESS;
|
||||||
@@ -52,7 +53,8 @@ b_status write_string(struct mie_ir_converter *converter, const char *s)
|
|||||||
|
|
||||||
switch (converter->c_dest_medium) {
|
switch (converter->c_dest_medium) {
|
||||||
case MIE_IR_CONVERTER_STRINGSTREAM:
|
case MIE_IR_CONVERTER_STRINGSTREAM:
|
||||||
return b_stringstream_add(converter->c_dest.stringstream, s);
|
return b_stream_write_string(
|
||||||
|
converter->c_dest.stringstream, s, NULL);
|
||||||
case MIE_IR_CONVERTER_STRING:
|
case MIE_IR_CONVERTER_STRING:
|
||||||
b_string_append_cstr(converter->c_dest.string, s);
|
b_string_append_cstr(converter->c_dest.string, s);
|
||||||
return B_SUCCESS;
|
return B_SUCCESS;
|
||||||
@@ -79,7 +81,8 @@ b_status write_string_f(struct mie_ir_converter *converter, const char *format,
|
|||||||
switch (converter->c_dest_medium) {
|
switch (converter->c_dest_medium) {
|
||||||
case MIE_IR_CONVERTER_STRINGSTREAM:
|
case MIE_IR_CONVERTER_STRINGSTREAM:
|
||||||
vsnprintf(buf, sizeof buf, format, arg);
|
vsnprintf(buf, sizeof buf, format, arg);
|
||||||
status = b_stringstream_add(converter->c_dest.stringstream, buf);
|
status = b_stream_write_string(
|
||||||
|
converter->c_dest.stringstream, buf, NULL);
|
||||||
break;
|
break;
|
||||||
case MIE_IR_CONVERTER_STRING:
|
case MIE_IR_CONVERTER_STRING:
|
||||||
vsnprintf(buf, sizeof buf, format, arg);
|
vsnprintf(buf, sizeof buf, format, arg);
|
||||||
@@ -147,23 +150,26 @@ static b_status write_operand_const(
|
|||||||
break;
|
break;
|
||||||
case MIE_TYPE_ARRAY: {
|
case MIE_TYPE_ARRAY: {
|
||||||
struct mie_array *array = MIE_ARRAY(value);
|
struct mie_array *array = MIE_ARRAY(value);
|
||||||
b_list_iterator it;
|
b_iterator *it = b_list_begin(array->a_values);
|
||||||
b_list_iterator_begin(array->a_values, &it);
|
|
||||||
|
|
||||||
write_char(converter, '{');
|
write_char(converter, '{');
|
||||||
while (b_list_iterator_is_valid(&it)) {
|
size_t i = 0;
|
||||||
if (it.i > 0) {
|
b_foreach(void *, item, it)
|
||||||
|
{
|
||||||
|
if (i > 0) {
|
||||||
write_char(converter, ',');
|
write_char(converter, ',');
|
||||||
}
|
}
|
||||||
|
|
||||||
write_string(converter, "\n ");
|
write_string(converter, "\n ");
|
||||||
|
|
||||||
struct mie_value *child = it.item;
|
struct mie_value *child = item;
|
||||||
write_operand_const(converter, child, F_INCLUDE_TYPE);
|
write_operand_const(converter, child, F_INCLUDE_TYPE);
|
||||||
|
|
||||||
b_list_iterator_next(&it);
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b_iterator_unref(it);
|
||||||
|
|
||||||
if (!b_list_empty(array->a_values)) {
|
if (!b_list_empty(array->a_values)) {
|
||||||
write_char(converter, '\n');
|
write_char(converter, '\n');
|
||||||
}
|
}
|
||||||
@@ -292,39 +298,43 @@ static b_status write_module(
|
|||||||
struct mie_module *mod = MIE_MODULE(value);
|
struct mie_module *mod = MIE_MODULE(value);
|
||||||
b_status status = B_SUCCESS;
|
b_status status = B_SUCCESS;
|
||||||
|
|
||||||
b_queue_iterator it;
|
b_queue_entry *entry = b_queue_first(&mod->m_records);
|
||||||
b_queue_foreach (&it, &mod->m_records) {
|
while (entry) {
|
||||||
struct mie_value *record
|
struct mie_value *record
|
||||||
= b_unbox(struct mie_value, it.entry, v_entry);
|
= b_unbox(struct mie_value, entry, v_entry);
|
||||||
status = write_value_to_text(converter, record);
|
status = write_value_to_text(converter, record);
|
||||||
|
|
||||||
if (!B_OK(status)) {
|
if (!B_OK(status)) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entry = b_queue_next(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!b_queue_empty(&mod->m_records)) {
|
if (!b_queue_empty(&mod->m_records)) {
|
||||||
write_char(converter, '\n');
|
write_char(converter, '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
b_queue_foreach (&it, &mod->m_types) {
|
entry = b_queue_first(&mod->m_types);
|
||||||
struct mie_value *type
|
while (entry) {
|
||||||
= b_unbox(struct mie_value, it.entry, v_entry);
|
struct mie_value *type = b_unbox(struct mie_value, entry, v_entry);
|
||||||
status = write_value_to_text(converter, type);
|
status = write_value_to_text(converter, type);
|
||||||
|
|
||||||
if (!B_OK(status)) {
|
if (!B_OK(status)) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entry = b_queue_next(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!b_queue_empty(&mod->m_types)) {
|
if (!b_queue_empty(&mod->m_types)) {
|
||||||
write_char(converter, '\n');
|
write_char(converter, '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
b_hashmap_iterator it2;
|
b_iterator *it = b_iterator_begin(mod->m_data);
|
||||||
b_hashmap_foreach(&it2, mod->m_data)
|
b_foreach_ptr(b_hashmap_item, item, it)
|
||||||
{
|
{
|
||||||
struct mie_value *data = it2.value->value_data;
|
struct mie_value *data = item->value.value_data;
|
||||||
status = write_value_to_text(converter, data);
|
status = write_value_to_text(converter, data);
|
||||||
|
|
||||||
if (!B_OK(status)) {
|
if (!B_OK(status)) {
|
||||||
@@ -332,18 +342,20 @@ static b_status write_module(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b_iterator_unref(it);
|
||||||
|
|
||||||
if (!b_hashmap_is_empty(mod->m_data)) {
|
if (!b_hashmap_is_empty(mod->m_data)) {
|
||||||
write_char(converter, '\n');
|
write_char(converter, '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
b_queue_foreach (&it, &mod->m_func) {
|
entry = b_queue_first(&mod->m_func);
|
||||||
|
while (entry) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
write_char(converter, '\n');
|
write_char(converter, '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mie_value *func
|
struct mie_value *func = b_unbox(struct mie_value, entry, v_entry);
|
||||||
= b_unbox(struct mie_value, it.entry, v_entry);
|
|
||||||
status = write_value_to_text(converter, func);
|
status = write_value_to_text(converter, func);
|
||||||
|
|
||||||
if (!B_OK(status)) {
|
if (!B_OK(status)) {
|
||||||
@@ -351,6 +363,7 @@ static b_status write_module(
|
|||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
entry = b_queue_next(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_SUCCESS;
|
return B_SUCCESS;
|
||||||
@@ -390,10 +403,10 @@ static b_status write_func_definition(
|
|||||||
converter, "define %s @%s(", type_name, func->f_base.v_name.n_str);
|
converter, "define %s @%s(", type_name, func->f_base.v_name.n_str);
|
||||||
|
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
b_queue_iterator it;
|
struct b_queue_entry *entry = b_queue_first(&func->f_args);
|
||||||
b_queue_foreach (&it, &func->f_args) {
|
while (entry) {
|
||||||
struct mie_arg *arg = (struct mie_arg *)b_unbox(
|
struct mie_arg *arg = (struct mie_arg *)b_unbox(
|
||||||
struct mie_value, it.entry, v_entry);
|
struct mie_value, entry, v_entry);
|
||||||
|
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
write_string(converter, ", ");
|
write_string(converter, ", ");
|
||||||
@@ -405,6 +418,7 @@ static b_status write_func_definition(
|
|||||||
converter, "%s %%%s", type_name,
|
converter, "%s %%%s", type_name,
|
||||||
arg->arg_base.v_name.n_str);
|
arg->arg_base.v_name.n_str);
|
||||||
i++;
|
i++;
|
||||||
|
entry = b_queue_next(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
write_string_f(converter, ")");
|
write_string_f(converter, ")");
|
||||||
@@ -425,10 +439,12 @@ static b_status write_func_definition(
|
|||||||
|
|
||||||
write_string_f(converter, " {\n");
|
write_string_f(converter, " {\n");
|
||||||
|
|
||||||
b_queue_foreach (&it, &func->f_blocks) {
|
entry = b_queue_first(&func->f_blocks);
|
||||||
|
while (entry) {
|
||||||
struct mie_value *block
|
struct mie_value *block
|
||||||
= b_unbox(struct mie_value, it.entry, v_entry);
|
= b_unbox(struct mie_value, entry, v_entry);
|
||||||
write_value_to_text(converter, block);
|
write_value_to_text(converter, block);
|
||||||
|
entry = b_queue_next(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
write_string_f(converter, "}\n");
|
write_string_f(converter, "}\n");
|
||||||
@@ -442,17 +458,20 @@ static b_status write_block_definition(
|
|||||||
struct mie_block *block = MIE_BLOCK(value);
|
struct mie_block *block = MIE_BLOCK(value);
|
||||||
|
|
||||||
write_string_f(converter, "%s:\n", block->b_base.v_name.n_str);
|
write_string_f(converter, "%s:\n", block->b_base.v_name.n_str);
|
||||||
b_queue_iterator it;
|
b_queue_entry *entry = b_queue_first(&block->b_phi);
|
||||||
b_queue_foreach (&it, &block->b_phi) {
|
while (entry) {
|
||||||
struct mie_value *instr
|
struct mie_value *instr
|
||||||
= b_unbox(struct mie_value, it.entry, v_entry);
|
= b_unbox(struct mie_value, entry, v_entry);
|
||||||
write_value_to_text(converter, instr);
|
write_value_to_text(converter, instr);
|
||||||
|
entry = b_queue_next(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
b_queue_foreach (&it, &block->b_instr) {
|
entry = b_queue_first(&block->b_instr);
|
||||||
|
while (entry) {
|
||||||
struct mie_value *instr
|
struct mie_value *instr
|
||||||
= b_unbox(struct mie_value, it.entry, v_entry);
|
= b_unbox(struct mie_value, entry, v_entry);
|
||||||
write_value_to_text(converter, instr);
|
write_value_to_text(converter, instr);
|
||||||
|
entry = b_queue_next(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block->b_terminator) {
|
if (block->b_terminator) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include <blue/object/string.h>
|
#include <blue/ds/string.h>
|
||||||
#include <mie/ctx.h>
|
#include <mie/ctx.h>
|
||||||
#include <mie/ir/data.h>
|
#include <mie/ir/data.h>
|
||||||
#include <mie/type.h>
|
#include <mie/type.h>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include <blue/core/hash.h>
|
#include <blue/core/hash.h>
|
||||||
#include <blue/object/string.h>
|
#include <blue/ds/string.h>
|
||||||
#include <mie/ir/arg.h>
|
#include <mie/ir/arg.h>
|
||||||
#include <mie/ir/block.h>
|
#include <mie/ir/block.h>
|
||||||
#include <mie/ir/func.h>
|
#include <mie/ir/func.h>
|
||||||
@@ -118,19 +118,26 @@ static void cleanup(struct mie_value *value)
|
|||||||
{
|
{
|
||||||
struct mie_func *func = MIE_FUNC(value);
|
struct mie_func *func = MIE_FUNC(value);
|
||||||
|
|
||||||
b_queue_iterator it;
|
b_queue_entry *entry = b_queue_first(&func->f_args);
|
||||||
b_queue_iterator_begin(&func->f_args, &it);
|
b_queue_entry *next = NULL;
|
||||||
while (b_queue_iterator_is_valid(&it)) {
|
while (entry) {
|
||||||
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
struct mie_value *v = b_unbox(struct mie_value, entry, v_entry);
|
||||||
b_queue_iterator_erase(&it);
|
next = b_queue_next(entry);
|
||||||
|
b_queue_delete(&func->f_args, entry);
|
||||||
|
|
||||||
mie_value_destroy(v);
|
mie_value_destroy(v);
|
||||||
|
entry = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
b_queue_iterator_begin(&func->f_blocks, &it);
|
entry = b_queue_first(&func->f_blocks);
|
||||||
while (b_queue_iterator_is_valid(&it)) {
|
while (entry) {
|
||||||
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
struct mie_value *v = b_unbox(struct mie_value, entry, v_entry);
|
||||||
b_queue_iterator_erase(&it);
|
next = b_queue_next(entry);
|
||||||
|
b_queue_delete(&func->f_blocks, entry);
|
||||||
|
|
||||||
mie_value_destroy(v);
|
mie_value_destroy(v);
|
||||||
|
|
||||||
|
entry = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
mie_name_map_destroy(func->f_names);
|
mie_name_map_destroy(func->f_names);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include <blue/object/hashmap.h>
|
#include <blue/ds/hashmap.h>
|
||||||
#include <mie/ir/const.h>
|
#include <mie/ir/const.h>
|
||||||
#include <mie/ir/data.h>
|
#include <mie/ir/data.h>
|
||||||
#include <mie/ir/func.h>
|
#include <mie/ir/func.h>
|
||||||
@@ -116,30 +116,36 @@ static void cleanup(struct mie_value *value)
|
|||||||
{
|
{
|
||||||
struct mie_module *module = MIE_MODULE(value);
|
struct mie_module *module = MIE_MODULE(value);
|
||||||
|
|
||||||
b_queue_iterator it;
|
b_queue_entry *entry = b_queue_first(&module->m_records);
|
||||||
b_queue_iterator_begin(&module->m_records, &it);
|
b_queue_entry *next = NULL;
|
||||||
while (b_queue_iterator_is_valid(&it)) {
|
while (entry) {
|
||||||
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
struct mie_value *v = b_unbox(struct mie_value, entry, v_entry);
|
||||||
b_queue_iterator_erase(&it);
|
next = b_queue_next(entry);
|
||||||
|
b_queue_delete(&module->m_records, entry);
|
||||||
mie_value_destroy(v);
|
mie_value_destroy(v);
|
||||||
|
entry = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
b_queue_iterator_begin(&module->m_types, &it);
|
entry = b_queue_first(&module->m_types);
|
||||||
while (b_queue_iterator_is_valid(&it)) {
|
while (entry) {
|
||||||
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
struct mie_value *v = b_unbox(struct mie_value, entry, v_entry);
|
||||||
b_queue_iterator_erase(&it);
|
next = b_queue_next(entry);
|
||||||
|
b_queue_delete(&module->m_types, entry);
|
||||||
mie_value_destroy(v);
|
mie_value_destroy(v);
|
||||||
|
entry = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
b_queue_iterator_begin(&module->m_func, &it);
|
entry = b_queue_first(&module->m_func);
|
||||||
while (b_queue_iterator_is_valid(&it)) {
|
while (entry) {
|
||||||
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
struct mie_value *v = b_unbox(struct mie_value, entry, v_entry);
|
||||||
b_queue_iterator_erase(&it);
|
next = b_queue_next(entry);
|
||||||
|
b_queue_delete(&module->m_func, entry);
|
||||||
mie_value_destroy(v);
|
mie_value_destroy(v);
|
||||||
|
entry = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
b_hashmap_release(module->m_data_strings);
|
b_hashmap_unref(module->m_data_strings);
|
||||||
b_hashmap_release(module->m_data);
|
b_hashmap_unref(module->m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct mie_value_type module_value_type = {
|
const struct mie_value_type module_value_type = {
|
||||||
|
|||||||
35
mie/name.c
35
mie/name.c
@@ -1,5 +1,5 @@
|
|||||||
#include <blue/core/rope.h>
|
#include <blue/core/rope.h>
|
||||||
#include <blue/object/string.h>
|
#include <blue/ds/string.h>
|
||||||
#include <mie/name.h>
|
#include <mie/name.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -25,11 +25,12 @@ static struct mie_name_bucket *create_bucket(void)
|
|||||||
|
|
||||||
static void destroy_bucket(struct mie_name_bucket *bucket)
|
static void destroy_bucket(struct mie_name_bucket *bucket)
|
||||||
{
|
{
|
||||||
b_queue_iterator it;
|
b_queue_entry *entry = b_queue_first(&bucket->b_names);
|
||||||
b_queue_iterator_begin(&bucket->b_names, &it);
|
|
||||||
|
|
||||||
while (b_queue_iterator_is_valid(&it)) {
|
while (entry) {
|
||||||
b_queue_iterator_erase(&it);
|
b_queue_entry *next = b_queue_next(entry);
|
||||||
|
b_queue_delete(&bucket->b_names, entry);
|
||||||
|
entry = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(bucket);
|
free(bucket);
|
||||||
@@ -48,19 +49,20 @@ struct mie_name_map *mie_name_map_create(void)
|
|||||||
|
|
||||||
void mie_name_map_destroy(struct mie_name_map *map)
|
void mie_name_map_destroy(struct mie_name_map *map)
|
||||||
{
|
{
|
||||||
b_btree_iterator it;
|
b_btree_node *node = b_btree_first(&map->m_entries);
|
||||||
b_btree_iterator_begin(&map->m_entries, &it);
|
|
||||||
|
|
||||||
while (b_btree_iterator_is_valid(&it)) {
|
while (node) {
|
||||||
struct mie_name_map_entry *entry
|
struct mie_name_map_entry *entry
|
||||||
= b_unbox(struct mie_name_map_entry, it.node, e_node);
|
= b_unbox(struct mie_name_map_entry, node, e_node);
|
||||||
b_btree_iterator_erase(&it);
|
b_btree_node *next = b_btree_next(node);
|
||||||
|
b_btree_delete(&map->m_entries, node);
|
||||||
if (entry->e_type == MIE_NAME_MAP_E_BUCKET) {
|
if (entry->e_type == MIE_NAME_MAP_E_BUCKET) {
|
||||||
struct mie_name_bucket *bucket
|
struct mie_name_bucket *bucket
|
||||||
= (struct mie_name_bucket *)entry;
|
= (struct mie_name_bucket *)entry;
|
||||||
destroy_bucket(bucket);
|
destroy_bucket(bucket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(map);
|
free(map);
|
||||||
@@ -69,14 +71,17 @@ void mie_name_map_destroy(struct mie_name_map *map)
|
|||||||
static b_status put_name_in_bucket(
|
static b_status put_name_in_bucket(
|
||||||
struct mie_name_bucket *bucket, struct mie_name *name)
|
struct mie_name_bucket *bucket, struct mie_name *name)
|
||||||
{
|
{
|
||||||
b_queue_iterator it;
|
b_queue_entry *entry = b_queue_first(&bucket->b_names);
|
||||||
b_queue_foreach (&it, &bucket->b_names) {
|
|
||||||
|
while (entry) {
|
||||||
struct mie_name *cur = (struct mie_name *)b_unbox(
|
struct mie_name *cur = (struct mie_name *)b_unbox(
|
||||||
struct mie_name_map_entry, it.entry, e_entry);
|
struct mie_name_map_entry, entry, e_entry);
|
||||||
|
|
||||||
if (!strcmp(cur->n_str, name->n_str)) {
|
if (!strcmp(cur->n_str, name->n_str)) {
|
||||||
return B_ERR_NAME_EXISTS;
|
return B_ERR_NAME_EXISTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entry = b_queue_next(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
b_queue_push_back(&bucket->b_names, &name->n_base.e_entry);
|
b_queue_push_back(&bucket->b_names, &name->n_base.e_entry);
|
||||||
@@ -181,7 +186,7 @@ struct mie_name *mie_name_map_put(
|
|||||||
b_rope_to_cstr(&unique_name, str, sizeof str);
|
b_rope_to_cstr(&unique_name, str, sizeof str);
|
||||||
|
|
||||||
entry->n_str = str;
|
entry->n_str = str;
|
||||||
entry->n_base.e_hash = b_hash_string(str);
|
entry->n_base.e_hash = b_hash_cstr(str);
|
||||||
b_status status = put_name(map, entry);
|
b_status status = put_name(map, entry);
|
||||||
|
|
||||||
if (B_OK(status)) {
|
if (B_OK(status)) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "builder.h"
|
#include "builder.h"
|
||||||
|
|
||||||
#include <blue/object/hashmap.h>
|
#include <blue/ds/hashmap.h>
|
||||||
#include <mie/ctx.h>
|
#include <mie/ctx.h>
|
||||||
#include <mie/ir/const.h>
|
#include <mie/ir/const.h>
|
||||||
#include <mie/ir/data.h>
|
#include <mie/ir/data.h>
|
||||||
@@ -51,7 +51,7 @@ struct mie_select_builder *mie_select_builder_create(
|
|||||||
|
|
||||||
out->b_mem_access = b_hashmap_create(NULL, NULL);
|
out->b_mem_access = b_hashmap_create(NULL, NULL);
|
||||||
if (!out->b_mem_access) {
|
if (!out->b_mem_access) {
|
||||||
b_hashmap_release(out->b_nodes);
|
b_hashmap_unref(out->b_nodes);
|
||||||
mie_select_graph_destroy(out->b_graph);
|
mie_select_graph_destroy(out->b_graph);
|
||||||
free(out);
|
free(out);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -63,11 +63,11 @@ struct mie_select_builder *mie_select_builder_create(
|
|||||||
void mie_select_builder_destroy(struct mie_select_builder *builder)
|
void mie_select_builder_destroy(struct mie_select_builder *builder)
|
||||||
{
|
{
|
||||||
if (builder->b_nodes) {
|
if (builder->b_nodes) {
|
||||||
b_hashmap_release(builder->b_nodes);
|
b_hashmap_unref(builder->b_nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (builder->b_mem_access) {
|
if (builder->b_mem_access) {
|
||||||
b_hashmap_release(builder->b_mem_access);
|
b_hashmap_unref(builder->b_mem_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (builder->b_graph) {
|
if (builder->b_graph) {
|
||||||
@@ -96,12 +96,14 @@ const struct mie_target *mie_select_builder_get_target(
|
|||||||
|
|
||||||
static void clear_node_map(struct mie_select_builder *builder)
|
static void clear_node_map(struct mie_select_builder *builder)
|
||||||
{
|
{
|
||||||
b_hashmap_iterator it;
|
b_iterator *it = b_iterator_begin(builder->b_nodes);
|
||||||
b_hashmap_iterator_begin(builder->b_nodes, &it);
|
while (b_iterator_is_valid(it)) {
|
||||||
while (b_hashmap_iterator_is_valid(&it)) {
|
b_hashmap_item *item = b_iterator_get_value(it).v_ptr;
|
||||||
free(it.value->value_data);
|
free(item->value.value_data);
|
||||||
b_hashmap_iterator_erase(&it);
|
b_iterator_erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b_iterator_unref(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mie_select_graph *mie_select_builder_finish(struct mie_select_builder *builder)
|
struct mie_select_graph *mie_select_builder_finish(struct mie_select_builder *builder)
|
||||||
@@ -142,28 +144,30 @@ enum mie_status mie_select_builder_get_const(
|
|||||||
struct mie_type *ctype = mie_ctx_get_int_type(builder->b_ctx, 32);
|
struct mie_type *ctype = mie_ctx_get_int_type(builder->b_ctx, 32);
|
||||||
struct mie_select_node *node = NULL;
|
struct mie_select_node *node = NULL;
|
||||||
|
|
||||||
b_queue_iterator it;
|
b_queue_entry *entry = b_queue_first(&builder->b_graph->g_nodes);
|
||||||
b_queue_foreach (&it, &builder->b_graph->g_nodes) {
|
while (entry) {
|
||||||
node = b_unbox(struct mie_select_node, it.entry, n_entry);
|
node = b_unbox(struct mie_select_node, entry, n_entry);
|
||||||
|
|
||||||
if (node->n_target != builtin) {
|
if (node->n_target != builtin) {
|
||||||
continue;
|
goto skip;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node->n_opcode != MIE_SELECT_OP_CONSTANT) {
|
if (node->n_opcode != MIE_SELECT_OP_CONSTANT) {
|
||||||
continue;
|
goto skip;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(node->n_flags & MIE_SELECT_NODE_F_IVALUE)) {
|
if (!(node->n_flags & MIE_SELECT_NODE_F_IVALUE)) {
|
||||||
continue;
|
goto skip;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node->n_value.i != value) {
|
if (node->n_value.i != value) {
|
||||||
continue;
|
goto skip;
|
||||||
}
|
}
|
||||||
|
|
||||||
mie_select_node_get_value(node, ctype, 0, out);
|
mie_select_node_get_value(node, ctype, 0, out);
|
||||||
return MIE_SUCCESS;
|
return MIE_SUCCESS;
|
||||||
|
skip:
|
||||||
|
entry = b_queue_next(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum mie_status status = mie_select_graph_get_node(
|
enum mie_status status = mie_select_graph_get_node(
|
||||||
@@ -368,15 +372,17 @@ struct mie_select_node *mie_select_builder_find_node_with_ivalue(
|
|||||||
struct mie_select_builder *builder, const struct mie_target *target,
|
struct mie_select_builder *builder, const struct mie_target *target,
|
||||||
unsigned int opcode, long long val)
|
unsigned int opcode, long long val)
|
||||||
{
|
{
|
||||||
b_queue_iterator it;
|
b_queue_entry *entry = b_queue_first(&builder->b_graph->g_nodes);
|
||||||
b_queue_foreach (&it, &builder->b_graph->g_nodes) {
|
while (entry) {
|
||||||
struct mie_select_node *node
|
struct mie_select_node *node
|
||||||
= b_unbox(struct mie_select_node, it.entry, n_entry);
|
= b_unbox(struct mie_select_node, entry, n_entry);
|
||||||
|
|
||||||
if (node->n_target == target && node->n_opcode == opcode
|
if (node->n_target == target && node->n_opcode == opcode
|
||||||
&& node->n_value.i == val) {
|
&& node->n_value.i == val) {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entry = b_queue_next(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -245,11 +245,12 @@ static void node_links_dump_dot(struct mie_select_node *node, b_stream *out)
|
|||||||
|
|
||||||
void mie_select_graph_dump_text(struct mie_select_graph *graph)
|
void mie_select_graph_dump_text(struct mie_select_graph *graph)
|
||||||
{
|
{
|
||||||
b_queue_iterator it;
|
b_queue_entry *entry = b_queue_first(&graph->g_nodes);
|
||||||
b_queue_foreach (&it, &graph->g_nodes) {
|
while (entry) {
|
||||||
struct mie_select_node *node
|
struct mie_select_node *node
|
||||||
= b_unbox(struct mie_select_node, it.entry, n_entry);
|
= b_unbox(struct mie_select_node, entry, n_entry);
|
||||||
node_dump_text(node);
|
node_dump_text(node);
|
||||||
|
entry = b_queue_next(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,22 +264,25 @@ void mie_select_graph_dump_dot(struct mie_select_graph *graph)
|
|||||||
b_stream_write_string(tmpstream, "\tnode [shape=Mrecord];\n", NULL);
|
b_stream_write_string(tmpstream, "\tnode [shape=Mrecord];\n", NULL);
|
||||||
b_stream_write_string(tmpstream, "\trankdir=\"BT\";\n", NULL);
|
b_stream_write_string(tmpstream, "\trankdir=\"BT\";\n", NULL);
|
||||||
|
|
||||||
b_queue_iterator it;
|
b_queue_entry *entry = b_queue_first(&graph->g_nodes);
|
||||||
b_queue_foreach (&it, &graph->g_nodes) {
|
while (entry) {
|
||||||
struct mie_select_node *node
|
struct mie_select_node *node
|
||||||
= b_unbox(struct mie_select_node, it.entry, n_entry);
|
= b_unbox(struct mie_select_node, entry, n_entry);
|
||||||
node_dump_dot(node, tmpstream);
|
node_dump_dot(node, tmpstream);
|
||||||
|
entry = b_queue_next(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
b_queue_foreach (&it, &graph->g_nodes) {
|
entry = b_queue_first(&graph->g_nodes);
|
||||||
|
while (entry) {
|
||||||
struct mie_select_node *node
|
struct mie_select_node *node
|
||||||
= b_unbox(struct mie_select_node, it.entry, n_entry);
|
= b_unbox(struct mie_select_node, entry, n_entry);
|
||||||
node_links_dump_dot(node, tmpstream);
|
node_links_dump_dot(node, tmpstream);
|
||||||
|
entry = b_queue_next(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
b_stream_write_string(tmpstream, "}\n", NULL);
|
b_stream_write_string(tmpstream, "}\n", NULL);
|
||||||
|
|
||||||
b_stream_close(tmpstream);
|
b_stream_unref(tmpstream);
|
||||||
|
|
||||||
system("open graph.dot");
|
system("open graph.dot");
|
||||||
|
|
||||||
|
|||||||
@@ -42,12 +42,12 @@ struct mie_select_graph *mie_select_graph_create(struct mie_ctx *ctx)
|
|||||||
|
|
||||||
void mie_select_graph_destroy(struct mie_select_graph *graph)
|
void mie_select_graph_destroy(struct mie_select_graph *graph)
|
||||||
{
|
{
|
||||||
b_queue_iterator it;
|
b_queue_entry *entry = b_queue_first(&graph->g_nodes);
|
||||||
b_queue_iterator_begin(&graph->g_nodes, &it);
|
while (entry) {
|
||||||
while (b_queue_iterator_is_valid(&it)) {
|
|
||||||
struct mie_select_node *node
|
struct mie_select_node *node
|
||||||
= b_unbox(struct mie_select_node, it.entry, n_entry);
|
= b_unbox(struct mie_select_node, entry, n_entry);
|
||||||
b_queue_iterator_erase(&it);
|
b_queue_entry *next = b_queue_next(entry);
|
||||||
|
b_queue_delete(&graph->g_nodes, entry);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (node->n_value) {
|
if (node->n_value) {
|
||||||
@@ -56,6 +56,7 @@ void mie_select_graph_destroy(struct mie_select_graph *graph)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
free(node);
|
free(node);
|
||||||
|
entry = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(graph);
|
free(graph);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ const struct select_node_type *select_type_for_node(enum mie_select_opcode node)
|
|||||||
return node_types[node];
|
return node_types[node];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
void mie_select_node_iterator_next(struct mie_select_node_iterator *it)
|
void mie_select_node_iterator_next(struct mie_select_node_iterator *it)
|
||||||
{
|
{
|
||||||
b_queue_iterator_next(&it->it_base);
|
b_queue_iterator_next(&it->it_base);
|
||||||
@@ -31,6 +32,7 @@ bool mie_select_node_iterator_is_valid(const struct mie_select_node_iterator *it
|
|||||||
{
|
{
|
||||||
return b_queue_iterator_is_valid(&it->it_base);
|
return b_queue_iterator_is_valid(&it->it_base);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
struct mie_select_node *mie_select_node_create(
|
struct mie_select_node *mie_select_node_create(
|
||||||
const struct mie_target *target, unsigned int op,
|
const struct mie_target *target, unsigned int op,
|
||||||
@@ -101,13 +103,16 @@ enum mie_status mie_select_node_set_operands(
|
|||||||
|
|
||||||
enum mie_status mie_select_node_clear_operands(struct mie_select_node *node)
|
enum mie_status mie_select_node_clear_operands(struct mie_select_node *node)
|
||||||
{
|
{
|
||||||
struct mie_select_use_iterator it;
|
b_queue_entry *entry = b_queue_first(&node->n_use);
|
||||||
mie_select_use_foreach(&it, &node->n_use)
|
while (entry) {
|
||||||
{
|
|
||||||
struct mie_select_use *use = mie_select_use_iterator_unbox(&it);
|
struct mie_select_use *use
|
||||||
|
= b_unbox(struct mie_select_use, entry, u_entry);
|
||||||
if (use->u_value.v_node == node) {
|
if (use->u_value.v_node == node) {
|
||||||
memset(&use->u_value, 0x0, sizeof use->u_value);
|
memset(&use->u_value, 0x0, sizeof use->u_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entry = b_queue_next(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node->n_operands) {
|
if (node->n_operands) {
|
||||||
@@ -158,12 +163,12 @@ enum mie_status mie_select_node_set_description(
|
|||||||
{
|
{
|
||||||
va_list arg;
|
va_list arg;
|
||||||
va_start(arg, format);
|
va_start(arg, format);
|
||||||
b_stringstream str;
|
b_stringstream *str = b_stringstream_create();
|
||||||
b_stringstream_begin_dynamic(&str);
|
b_stream_write_vfmt(str, NULL, format, arg);
|
||||||
b_stringstream_addvf(&str, format, arg);
|
|
||||||
va_end(arg);
|
va_end(arg);
|
||||||
|
|
||||||
node->n_description = b_stringstream_end(&str);
|
node->n_description = b_stringstream_steal(str);
|
||||||
|
b_stringstream_unref(str);
|
||||||
return node->n_description ? MIE_SUCCESS : MIE_ERR_NO_MEMORY;
|
return node->n_description ? MIE_SUCCESS : MIE_ERR_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user