mie: implement ir generation for message sending
This commit is contained in:
@@ -6,9 +6,11 @@
|
||||
#include <mie/block.h>
|
||||
#include <mie/branch.h>
|
||||
#include <mie/const.h>
|
||||
#include <mie/data.h>
|
||||
#include <mie/func.h>
|
||||
#include <mie/instr.h>
|
||||
#include <mie/module.h>
|
||||
#include <mie/msg.h>
|
||||
#include <mie/op.h>
|
||||
#include <mie/ptr.h>
|
||||
#include <mie/type.h>
|
||||
@@ -43,6 +45,9 @@ static void mie_type_to_string(struct mie_type *type, char *out, size_t max)
|
||||
case MIE_TYPE_LABEL:
|
||||
snprintf(out, max, "label");
|
||||
break;
|
||||
case MIE_TYPE_SELECTOR:
|
||||
snprintf(out, max, "");
|
||||
break;
|
||||
default:
|
||||
snprintf(out, max, "<unknown-type>");
|
||||
break;
|
||||
@@ -131,7 +136,11 @@ static b_status write_operand_const(
|
||||
if (flags & F_INCLUDE_TYPE) {
|
||||
char type_name[64];
|
||||
mie_type_to_string(c->c_type, type_name, sizeof type_name);
|
||||
write_string_f(converter, "%s ", type_name);
|
||||
write_string_f(converter, "%s", type_name);
|
||||
|
||||
if (type_name[0] != 0) {
|
||||
write_char(converter, ' ');
|
||||
}
|
||||
}
|
||||
|
||||
switch (c->c_type->t_id) {
|
||||
@@ -149,6 +158,9 @@ static b_status write_operand_const(
|
||||
case MIE_TYPE_CLASS:
|
||||
write_string_f(converter, "@%s", value->v_name.n_str);
|
||||
break;
|
||||
case MIE_TYPE_SELECTOR:
|
||||
write_string_f(converter, "@%s", c->c_v.v_selector);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -188,6 +200,20 @@ static b_status write_operand_block(
|
||||
return B_SUCCESS;
|
||||
}
|
||||
|
||||
static b_status write_operand_data(
|
||||
struct mie_ir_converter *converter, struct mie_value *value, int flags)
|
||||
{
|
||||
struct mie_const *c = MIE_CONST(value);
|
||||
|
||||
if (flags & F_INCLUDE_TYPE) {
|
||||
write_string(converter, "ptr ");
|
||||
}
|
||||
|
||||
write_string_f(converter, "@%s", value->v_name.n_str);
|
||||
|
||||
return B_SUCCESS;
|
||||
}
|
||||
|
||||
static b_status write_operand(
|
||||
struct mie_ir_converter *converter, struct mie_value *value, int flags)
|
||||
{
|
||||
@@ -198,6 +224,8 @@ static b_status write_operand(
|
||||
return write_operand_instr(converter, value, flags);
|
||||
case MIE_VALUE_BLOCK:
|
||||
return write_operand_block(converter, value, flags);
|
||||
case MIE_VALUE_DATA:
|
||||
return write_operand_data(converter, value, flags);
|
||||
default:
|
||||
return B_SUCCESS;
|
||||
}
|
||||
@@ -220,6 +248,10 @@ static b_status write_module(
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -230,6 +262,10 @@ static b_status write_module(
|
||||
}
|
||||
}
|
||||
|
||||
if (!b_queue_empty(&mod->m_types)) {
|
||||
write_char(converter, '\n');
|
||||
}
|
||||
|
||||
b_queue_foreach (&it, &mod->m_data) {
|
||||
struct mie_value *data
|
||||
= b_unbox(struct mie_value, it.entry, v_entry);
|
||||
@@ -240,6 +276,10 @@ static b_status write_module(
|
||||
}
|
||||
}
|
||||
|
||||
if (!b_queue_empty(&mod->m_data)) {
|
||||
write_char(converter, '\n');
|
||||
}
|
||||
|
||||
b_queue_foreach (&it, &mod->m_func) {
|
||||
struct mie_value *func
|
||||
= b_unbox(struct mie_value, it.entry, v_entry);
|
||||
@@ -439,9 +479,30 @@ static b_status write_instr(
|
||||
write_operand(converter, MIE_VALUE(br->b_dest), F_INCLUDE_TYPE);
|
||||
break;
|
||||
}
|
||||
case MIE_INSTR_MSG:
|
||||
write_string(converter, "msg");
|
||||
case MIE_INSTR_MSG: {
|
||||
struct mie_msg *msg = (struct mie_msg *)instr;
|
||||
mie_type_to_string(msg->msg_ret_type, type, sizeof type);
|
||||
write_string_f(converter, "msg %s, ", type);
|
||||
write_operand(converter, msg->msg_recipient, F_INCLUDE_TYPE);
|
||||
write_string(converter, ", ");
|
||||
write_operand(converter, msg->msg_selector, F_INCLUDE_TYPE);
|
||||
|
||||
if (msg->msg_nr_args == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
write_string(converter, " [");
|
||||
for (size_t i = 0; i < msg->msg_nr_args; i++) {
|
||||
if (i > 0) {
|
||||
write_string(converter, ", ");
|
||||
}
|
||||
|
||||
write_operand(converter, msg->msg_args[i], F_INCLUDE_TYPE);
|
||||
}
|
||||
write_string(converter, "]");
|
||||
|
||||
break;
|
||||
}
|
||||
case MIE_INSTR_CMP_EQ:
|
||||
write_string(converter, "cmp eq");
|
||||
break;
|
||||
@@ -475,6 +536,33 @@ static b_status write_instr(
|
||||
return B_SUCCESS;
|
||||
}
|
||||
|
||||
static b_status write_data(
|
||||
struct mie_ir_converter *converter, struct mie_value *value)
|
||||
{
|
||||
char type_name[128];
|
||||
|
||||
struct mie_data *data = MIE_DATA(value);
|
||||
write_string_f(converter, "data @%s = ", value->v_name.n_str);
|
||||
|
||||
switch (data->d_type) {
|
||||
case MIE_DATA_EXTERN_GLOBAL:
|
||||
mie_type_to_string(
|
||||
data->d_extern_global.g_type, type_name, sizeof type_name);
|
||||
write_string_f(converter, "extern global %s", type_name);
|
||||
break;
|
||||
case MIE_DATA_CONST:
|
||||
write_operand_const(
|
||||
converter, data->d_const.c_value, F_INCLUDE_TYPE);
|
||||
break;
|
||||
default:
|
||||
write_string(converter, "<unknown>");
|
||||
break;
|
||||
}
|
||||
|
||||
write_char(converter, '\n');
|
||||
return B_SUCCESS;
|
||||
}
|
||||
|
||||
static const write_function value_writers[] = {
|
||||
[MIE_VALUE_MODULE] = write_module,
|
||||
[MIE_VALUE_TYPE] = write_type_definition,
|
||||
@@ -483,6 +571,7 @@ static const write_function value_writers[] = {
|
||||
[MIE_VALUE_ARG] = NULL,
|
||||
[MIE_VALUE_BLOCK] = write_block_definition,
|
||||
[MIE_VALUE_INSTR] = write_instr,
|
||||
[MIE_VALUE_DATA] = write_data,
|
||||
[MIE_VALUE_CONST] = NULL,
|
||||
};
|
||||
static const size_t nr_value_printers
|
||||
|
||||
Reference in New Issue
Block a user