mie: implement support for custom op print formats

This commit is contained in:
2026-01-15 14:20:13 +00:00
parent 3c4af9c26e
commit 65905bc55b
31 changed files with 442 additions and 64 deletions

View File

@@ -17,7 +17,7 @@ static void print_block_header_params(
b_stream_write_string(printer->p_stream, ", ", NULL);
}
mie_printer_print_register(printer, block->b_params.items[i]);
mie_printer_print_register(printer, block->b_params.items[i], 0);
b_stream_write_string(printer->p_stream, ": ", NULL);
@@ -46,9 +46,13 @@ static void print_block_header(
}
void mie_printer_print_block(
struct mie_printer *printer, const struct mie_block *block)
struct mie_printer *printer, const struct mie_block *block,
enum mie_print_flags flags)
{
print_block_header(printer, block);
if (!(flags & MIE_PRINT_F_EXCLUDE_BLOCK_HEADER)) {
print_block_header(printer, block);
}
b_stream_push_indent(printer->p_stream, 4);
for (size_t i = 0; i < MIE_VECTOR_COUNT(block->b_ops); i++) {

View File

@@ -101,7 +101,7 @@ static void print_region_list(struct mie_printer *printer, const struct mie_op *
b_stream_write_string(printer->p_stream, ", ", NULL);
}
mie_printer_print_region(printer, &op->op_regions.items[i]);
mie_printer_print_region(printer, &op->op_regions.items[i], 0);
}
b_stream_write_string(printer->p_stream, ")", NULL);
@@ -182,23 +182,9 @@ static void print_type_signature(
}
}
void mie_printer_print_op(struct mie_printer *printer, const struct mie_op *op)
static void print_generic_op(struct mie_printer *printer, const struct mie_op *op)
{
for (size_t i = 0; i < MIE_VECTOR_COUNT(op->op_result); i++) {
if (i > 0) {
b_stream_write_string(printer->p_stream, ", ", NULL);
}
mie_printer_print_register(printer, op->op_result.items[i]);
}
if (MIE_VECTOR_COUNT(op->op_result) > 0) {
b_stream_write_string(printer->p_stream, " = ", NULL);
}
if (printer->p_flags & MIE_PRINT_F_GENERIC) {
b_stream_write_char(printer->p_stream, '~');
}
b_stream_write_char(printer->p_stream, '~');
if (op->op_flags & MIE_OP_F_OP_RESOLVED) {
b_stream_write_fmt(
@@ -225,3 +211,32 @@ void mie_printer_print_op(struct mie_printer *printer, const struct mie_op *op)
print_attribute_list(printer, op);
print_type_signature(printer, op);
}
void mie_printer_print_op(struct mie_printer *printer, const struct mie_op *op)
{
for (size_t i = 0; i < MIE_VECTOR_COUNT(op->op_result); i++) {
if (i > 0) {
b_stream_write_string(printer->p_stream, ", ", NULL);
}
mie_printer_print_register(printer, op->op_result.items[i], 0);
}
if (MIE_VECTOR_COUNT(op->op_result) > 0) {
b_stream_write_string(printer->p_stream, " = ", NULL);
}
bool use_generic = !op->op_info || !op->op_info->op_print
|| printer->p_flags & MIE_PRINT_F_GENERIC;
if (use_generic) {
print_generic_op(printer, op);
return;
}
b_stream_write_fmt(
printer->p_stream, NULL, "%s.%s", op->op_dialect->d_name,
op->op_info->op_name);
op->op_info->op_print(printer, op);
}

View File

@@ -3,13 +3,20 @@
#include <mie/print/printer.h>
void mie_printer_print_region(
struct mie_printer *printer, const struct mie_region *region)
struct mie_printer *printer, const struct mie_region *region,
enum mie_print_flags flags)
{
b_stream_write_string(printer->p_stream, "{\n", NULL);
for (size_t i = 0; i < MIE_VECTOR_COUNT(region->r_blocks); i++) {
enum mie_print_flags block_flags = 0;
if ((flags & MIE_PRINT_F_EXCLUDE_FIRST_BLOCK_HEADER) && (i == 0)) {
block_flags = MIE_PRINT_F_EXCLUDE_BLOCK_HEADER;
}
const struct mie_block *block = region->r_blocks.items[i];
mie_printer_print_block(printer, block);
mie_printer_print_block(printer, block, block_flags);
}
b_stream_write_string(printer->p_stream, "}", NULL);

View File

@@ -2,7 +2,8 @@
#include <mie/print/printer.h>
void mie_printer_print_register(
struct mie_printer *printer, const struct mie_register *reg)
struct mie_printer *printer, const struct mie_register *reg,
enum mie_print_flags flags)
{
if (reg->reg_flags & MIE_REGISTER_F_VIRTUAL) {
b_stream_write_fmt(
@@ -14,4 +15,9 @@ void mie_printer_print_register(
} else {
b_stream_write_string(printer->p_stream, "?REG", NULL);
}
if (flags & MIE_PRINT_F_INCLUDE_TYPE) {
b_stream_write_string(printer->p_stream, ": ", NULL);
mie_printer_print_type(printer, reg->reg_type);
}
}