mie: update bluelib api usage
This commit is contained in:
@@ -70,19 +70,26 @@ static void cleanup(struct mie_value *value)
|
||||
{
|
||||
struct mie_block *block = MIE_BLOCK(value);
|
||||
|
||||
b_queue_iterator it;
|
||||
b_queue_iterator_begin(&block->b_phi, &it);
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
||||
b_queue_iterator_erase(&it);
|
||||
b_queue_entry *entry = b_queue_first(&block->b_phi);
|
||||
b_queue_entry *next = NULL;
|
||||
|
||||
while (entry) {
|
||||
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);
|
||||
|
||||
entry = next;
|
||||
}
|
||||
|
||||
b_queue_iterator_begin(&block->b_instr, &it);
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
||||
b_queue_iterator_erase(&it);
|
||||
entry = b_queue_first(&block->b_instr);
|
||||
while (entry) {
|
||||
struct mie_value *v = b_unbox(struct mie_value, entry, v_entry);
|
||||
next = b_queue_next(entry);
|
||||
b_queue_delete(&block->b_instr, entry);
|
||||
mie_value_destroy(v);
|
||||
|
||||
entry = next;
|
||||
}
|
||||
|
||||
if (block->b_terminator) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/ir/alloca.h>
|
||||
#include <mie/ir/block.h>
|
||||
@@ -52,15 +52,16 @@ struct mie_record *mie_builder_put_record(
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b_queue_iterator it = {};
|
||||
b_queue_foreach (&it, &builder->b_module->m_records) {
|
||||
struct mie_value *rec
|
||||
= b_unbox(struct mie_value, it.entry, v_entry);
|
||||
b_queue_entry *entry = b_queue_first(&builder->b_module->m_records);
|
||||
while (entry) {
|
||||
struct mie_value *rec = b_unbox(struct mie_value, entry, v_entry);
|
||||
|
||||
if (!strcmp(rec->v_name.n_str, name)) {
|
||||
/* TODO what to do about `val` here? */
|
||||
return MIE_RECORD(rec);
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
struct mie_record *rec = mie_record_create(val);
|
||||
@@ -77,14 +78,15 @@ struct mie_record *mie_builder_get_record(
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b_queue_iterator it = {};
|
||||
b_queue_foreach (&it, &builder->b_module->m_records) {
|
||||
struct mie_value *rec
|
||||
= b_unbox(struct mie_value, it.entry, v_entry);
|
||||
b_queue_entry *entry = b_queue_first(&builder->b_module->m_records);
|
||||
while (entry) {
|
||||
struct mie_value *rec = b_unbox(struct mie_value, entry, v_entry);
|
||||
|
||||
if (!strcmp(rec->v_name.n_str, name)) {
|
||||
return MIE_RECORD(rec);
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "convert.h"
|
||||
|
||||
#include <blue/object/hashmap.h>
|
||||
#include <blue/object/list.h>
|
||||
#include <blue/ds/hashmap.h>
|
||||
#include <blue/ds/list.h>
|
||||
#include <inttypes.h>
|
||||
#include <mie/ir/alloca.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) {
|
||||
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:
|
||||
b_string_append_cstr(converter->c_dest.string, s);
|
||||
return B_SUCCESS;
|
||||
@@ -52,7 +53,8 @@ b_status write_string(struct mie_ir_converter *converter, const char *s)
|
||||
|
||||
switch (converter->c_dest_medium) {
|
||||
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:
|
||||
b_string_append_cstr(converter->c_dest.string, s);
|
||||
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) {
|
||||
case MIE_IR_CONVERTER_STRINGSTREAM:
|
||||
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;
|
||||
case MIE_IR_CONVERTER_STRING:
|
||||
vsnprintf(buf, sizeof buf, format, arg);
|
||||
@@ -147,23 +150,26 @@ static b_status write_operand_const(
|
||||
break;
|
||||
case MIE_TYPE_ARRAY: {
|
||||
struct mie_array *array = MIE_ARRAY(value);
|
||||
b_list_iterator it;
|
||||
b_list_iterator_begin(array->a_values, &it);
|
||||
b_iterator *it = b_list_begin(array->a_values);
|
||||
|
||||
write_char(converter, '{');
|
||||
while (b_list_iterator_is_valid(&it)) {
|
||||
if (it.i > 0) {
|
||||
size_t i = 0;
|
||||
b_foreach(void *, item, it)
|
||||
{
|
||||
if (i > 0) {
|
||||
write_char(converter, ',');
|
||||
}
|
||||
|
||||
write_string(converter, "\n ");
|
||||
|
||||
struct mie_value *child = it.item;
|
||||
struct mie_value *child = item;
|
||||
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)) {
|
||||
write_char(converter, '\n');
|
||||
}
|
||||
@@ -292,39 +298,43 @@ static b_status write_module(
|
||||
struct mie_module *mod = MIE_MODULE(value);
|
||||
b_status status = B_SUCCESS;
|
||||
|
||||
b_queue_iterator it;
|
||||
b_queue_foreach (&it, &mod->m_records) {
|
||||
b_queue_entry *entry = b_queue_first(&mod->m_records);
|
||||
while (entry) {
|
||||
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);
|
||||
|
||||
if (!B_OK(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
if (!b_queue_empty(&mod->m_records)) {
|
||||
write_char(converter, '\n');
|
||||
}
|
||||
|
||||
b_queue_foreach (&it, &mod->m_types) {
|
||||
struct mie_value *type
|
||||
= b_unbox(struct mie_value, it.entry, v_entry);
|
||||
entry = b_queue_first(&mod->m_types);
|
||||
while (entry) {
|
||||
struct mie_value *type = b_unbox(struct mie_value, entry, v_entry);
|
||||
status = write_value_to_text(converter, type);
|
||||
|
||||
if (!B_OK(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
if (!b_queue_empty(&mod->m_types)) {
|
||||
write_char(converter, '\n');
|
||||
}
|
||||
|
||||
b_hashmap_iterator it2;
|
||||
b_hashmap_foreach(&it2, mod->m_data)
|
||||
b_iterator *it = b_iterator_begin(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);
|
||||
|
||||
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)) {
|
||||
write_char(converter, '\n');
|
||||
}
|
||||
|
||||
unsigned long i = 0;
|
||||
b_queue_foreach (&it, &mod->m_func) {
|
||||
entry = b_queue_first(&mod->m_func);
|
||||
while (entry) {
|
||||
if (i > 0) {
|
||||
write_char(converter, '\n');
|
||||
}
|
||||
|
||||
struct mie_value *func
|
||||
= b_unbox(struct mie_value, it.entry, v_entry);
|
||||
struct mie_value *func = b_unbox(struct mie_value, entry, v_entry);
|
||||
status = write_value_to_text(converter, func);
|
||||
|
||||
if (!B_OK(status)) {
|
||||
@@ -351,6 +363,7 @@ static b_status write_module(
|
||||
}
|
||||
|
||||
i++;
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
unsigned int i = 0;
|
||||
b_queue_iterator it;
|
||||
b_queue_foreach (&it, &func->f_args) {
|
||||
struct b_queue_entry *entry = b_queue_first(&func->f_args);
|
||||
while (entry) {
|
||||
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) {
|
||||
write_string(converter, ", ");
|
||||
@@ -405,6 +418,7 @@ static b_status write_func_definition(
|
||||
converter, "%s %%%s", type_name,
|
||||
arg->arg_base.v_name.n_str);
|
||||
i++;
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
write_string_f(converter, ")");
|
||||
@@ -425,10 +439,12 @@ static b_status write_func_definition(
|
||||
|
||||
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
|
||||
= b_unbox(struct mie_value, it.entry, v_entry);
|
||||
= b_unbox(struct mie_value, entry, v_entry);
|
||||
write_value_to_text(converter, block);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
write_string_f(converter, "}\n");
|
||||
@@ -442,17 +458,20 @@ static b_status write_block_definition(
|
||||
struct mie_block *block = MIE_BLOCK(value);
|
||||
|
||||
write_string_f(converter, "%s:\n", block->b_base.v_name.n_str);
|
||||
b_queue_iterator it;
|
||||
b_queue_foreach (&it, &block->b_phi) {
|
||||
b_queue_entry *entry = b_queue_first(&block->b_phi);
|
||||
while (entry) {
|
||||
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);
|
||||
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
|
||||
= b_unbox(struct mie_value, it.entry, v_entry);
|
||||
= b_unbox(struct mie_value, entry, v_entry);
|
||||
write_value_to_text(converter, instr);
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
if (block->b_terminator) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/ir/data.h>
|
||||
#include <mie/type.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <blue/core/hash.h>
|
||||
#include <blue/object/string.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <mie/ir/arg.h>
|
||||
#include <mie/ir/block.h>
|
||||
#include <mie/ir/func.h>
|
||||
@@ -118,19 +118,26 @@ static void cleanup(struct mie_value *value)
|
||||
{
|
||||
struct mie_func *func = MIE_FUNC(value);
|
||||
|
||||
b_queue_iterator it;
|
||||
b_queue_iterator_begin(&func->f_args, &it);
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
||||
b_queue_iterator_erase(&it);
|
||||
b_queue_entry *entry = b_queue_first(&func->f_args);
|
||||
b_queue_entry *next = NULL;
|
||||
while (entry) {
|
||||
struct mie_value *v = b_unbox(struct mie_value, entry, v_entry);
|
||||
next = b_queue_next(entry);
|
||||
b_queue_delete(&func->f_args, entry);
|
||||
|
||||
mie_value_destroy(v);
|
||||
entry = next;
|
||||
}
|
||||
|
||||
b_queue_iterator_begin(&func->f_blocks, &it);
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
||||
b_queue_iterator_erase(&it);
|
||||
entry = b_queue_first(&func->f_blocks);
|
||||
while (entry) {
|
||||
struct mie_value *v = b_unbox(struct mie_value, entry, v_entry);
|
||||
next = b_queue_next(entry);
|
||||
b_queue_delete(&func->f_blocks, entry);
|
||||
|
||||
mie_value_destroy(v);
|
||||
|
||||
entry = next;
|
||||
}
|
||||
|
||||
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/data.h>
|
||||
#include <mie/ir/func.h>
|
||||
@@ -116,30 +116,36 @@ static void cleanup(struct mie_value *value)
|
||||
{
|
||||
struct mie_module *module = MIE_MODULE(value);
|
||||
|
||||
b_queue_iterator it;
|
||||
b_queue_iterator_begin(&module->m_records, &it);
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
||||
b_queue_iterator_erase(&it);
|
||||
b_queue_entry *entry = b_queue_first(&module->m_records);
|
||||
b_queue_entry *next = NULL;
|
||||
while (entry) {
|
||||
struct mie_value *v = b_unbox(struct mie_value, entry, v_entry);
|
||||
next = b_queue_next(entry);
|
||||
b_queue_delete(&module->m_records, entry);
|
||||
mie_value_destroy(v);
|
||||
entry = next;
|
||||
}
|
||||
|
||||
b_queue_iterator_begin(&module->m_types, &it);
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
||||
b_queue_iterator_erase(&it);
|
||||
entry = b_queue_first(&module->m_types);
|
||||
while (entry) {
|
||||
struct mie_value *v = b_unbox(struct mie_value, entry, v_entry);
|
||||
next = b_queue_next(entry);
|
||||
b_queue_delete(&module->m_types, entry);
|
||||
mie_value_destroy(v);
|
||||
entry = next;
|
||||
}
|
||||
|
||||
b_queue_iterator_begin(&module->m_func, &it);
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
struct mie_value *v = b_unbox(struct mie_value, it.entry, v_entry);
|
||||
b_queue_iterator_erase(&it);
|
||||
entry = b_queue_first(&module->m_func);
|
||||
while (entry) {
|
||||
struct mie_value *v = b_unbox(struct mie_value, entry, v_entry);
|
||||
next = b_queue_next(entry);
|
||||
b_queue_delete(&module->m_func, entry);
|
||||
mie_value_destroy(v);
|
||||
entry = next;
|
||||
}
|
||||
|
||||
b_hashmap_release(module->m_data_strings);
|
||||
b_hashmap_release(module->m_data);
|
||||
b_hashmap_unref(module->m_data_strings);
|
||||
b_hashmap_unref(module->m_data);
|
||||
}
|
||||
|
||||
const struct mie_value_type module_value_type = {
|
||||
|
||||
Reference in New Issue
Block a user