mie: update bluelib api usage
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user