mie: print: add more functions to printer interface

This commit is contained in:
2026-01-17 10:27:23 +00:00
parent f19dfaa050
commit 3ba20e5ed4
4 changed files with 86 additions and 13 deletions

View File

@@ -8,6 +8,8 @@
struct mie_ctx; struct mie_ctx;
struct mie_module; struct mie_module;
struct mie_op; struct mie_op;
struct mie_op_arg;
struct mie_op_successor;
struct mie_region; struct mie_region;
struct mie_block; struct mie_block;
struct mie_type; struct mie_type;
@@ -43,6 +45,8 @@ MIE_API void mie_printer_print_region(
MIE_API void mie_printer_print_block( MIE_API 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); enum mie_print_flags flags);
MIE_API void mie_printer_print_block_ref(
struct mie_printer *printer, const struct mie_block *block);
MIE_API void mie_printer_print_type( MIE_API void mie_printer_print_type(
struct mie_printer *printer, const struct mie_type *type); struct mie_printer *printer, const struct mie_type *type);
MIE_API void mie_printer_print_attribute( MIE_API void mie_printer_print_attribute(
@@ -51,4 +55,13 @@ MIE_API 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); enum mie_print_flags flags);
MIE_API void mie_printer_print_op_name(
struct mie_printer *printer, const struct mie_op *op);
MIE_API void mie_printer_print_op_successor(
struct mie_printer *printer, const struct mie_op_successor *s,
bool compact);
MIE_API void mie_printer_print_op_arg(
struct mie_printer *printer, const struct mie_op_arg *arg,
bool include_type);
#endif #endif

View File

@@ -63,3 +63,9 @@ void mie_printer_print_block(
b_stream_pop_indent(printer->p_stream); b_stream_pop_indent(printer->p_stream);
} }
void mie_printer_print_block_ref(
struct mie_printer *printer, const struct mie_block *block)
{
print_block_header(printer, block);
}

View File

@@ -5,7 +5,7 @@
#include <mie/ir/region.h> #include <mie/ir/region.h>
#include <mie/print/printer.h> #include <mie/print/printer.h>
static void print_op_arg( void mie_printer_print_op_arg(
struct mie_printer *printer, const struct mie_op_arg *arg, bool include_type) struct mie_printer *printer, const struct mie_op_arg *arg, bool include_type)
{ {
enum mie_register_flags arg_flags = 0; enum mie_register_flags arg_flags = 0;
@@ -39,8 +39,9 @@ static void print_op_arg(
mie_printer_print_type(printer, arg_type); mie_printer_print_type(printer, arg_type);
} }
static void print_successor( void mie_printer_print_op_successor(
struct mie_printer *printer, const struct mie_op_successor *successor) struct mie_printer *printer, const struct mie_op_successor *successor,
bool compact)
{ {
b_stream_write_char(printer->p_stream, '^'); b_stream_write_char(printer->p_stream, '^');
if (successor->s_flags & MIE_OP_F_SUCCESSOR_RESOLVED) { if (successor->s_flags & MIE_OP_F_SUCCESSOR_RESOLVED) {
@@ -55,14 +56,18 @@ static void print_successor(
return; return;
} }
b_stream_write_string(printer->p_stream, ":(", NULL); if (!compact) {
b_stream_write_char(printer->p_stream, ':');
}
b_stream_write_char(printer->p_stream, '(');
for (size_t i = 0; i < MIE_VECTOR_COUNT(successor->s_args); i++) { for (size_t i = 0; i < MIE_VECTOR_COUNT(successor->s_args); i++) {
if (i > 0) { if (i > 0) {
b_stream_write_string(printer->p_stream, ", ", NULL); b_stream_write_string(printer->p_stream, ", ", NULL);
} }
print_op_arg(printer, &successor->s_args.items[i], true); mie_printer_print_op_arg(printer, &successor->s_args.items[i], true);
} }
b_stream_write_char(printer->p_stream, ')'); b_stream_write_char(printer->p_stream, ')');
@@ -82,7 +87,8 @@ static void print_successor_list(
b_stream_write_string(printer->p_stream, ", ", NULL); b_stream_write_string(printer->p_stream, ", ", NULL);
} }
print_successor(printer, &op->op_successors.items[i]); mie_printer_print_op_successor(
printer, &op->op_successors.items[i], false);
} }
b_stream_write_string(printer->p_stream, " ]", NULL); b_stream_write_string(printer->p_stream, " ]", NULL);
@@ -201,7 +207,7 @@ static void print_generic_op(struct mie_printer *printer, const struct mie_op *o
b_stream_write_string(printer->p_stream, ", ", NULL); b_stream_write_string(printer->p_stream, ", ", NULL);
} }
print_op_arg(printer, &op->op_args.items[i], false); mie_printer_print_op_arg(printer, &op->op_args.items[i], false);
} }
b_stream_write_char(printer->p_stream, ')'); b_stream_write_char(printer->p_stream, ')');
@@ -234,9 +240,44 @@ void mie_printer_print_op(struct mie_printer *printer, const struct mie_op *op)
return; return;
} }
b_stream_write_fmt( mie_printer_print_op_name(printer, op);
printer->p_stream, NULL, "%s.%s", op->op_dialect->d_name,
op->op_info->op_name);
op->op_info->op_print(printer, op); op->op_info->op_print(printer, op);
} }
void mie_printer_print_op_name(struct mie_printer *printer, const struct mie_op *op)
{
bool builtin = false;
bool resolved = false;
bool generic = false;
bool abbreviate = false;
if (op->op_flags & MIE_OP_F_OP_RESOLVED) {
resolved = true;
}
if (printer->p_flags & MIE_PRINT_F_ABBREVIATED) {
abbreviate = true;
}
if (printer->p_flags & MIE_PRINT_F_GENERIC) {
generic = true;
b_stream_write_char(printer->p_stream, '~');
} else if (!strcmp(op->op_dialect->d_name, "builtin")) {
builtin = true;
}
if (!resolved) {
b_stream_write_string(printer->p_stream, op->op_name, NULL);
return;
}
if (generic || !builtin || !abbreviate) {
b_stream_write_fmt(
printer->p_stream, NULL, "%s.", op->op_dialect->d_name);
}
b_stream_write_string(printer->p_stream, op->op_info->op_name, NULL);
return;
}

View File

@@ -1,14 +1,27 @@
#include <mie/dialect/dialect.h>
#include <mie/print/printer.h> #include <mie/print/printer.h>
#include <mie/type/type-definition.h> #include <mie/type/type-definition.h>
#include <mie/type/type.h> #include <mie/type/type.h>
#define TYPE_HAS_PRINT_CALLBACK(p) (type->ty_def && type->ty_def->ty_print)
#define TYPE_IS_BUILTIN(p) \
(p->ty_def && p->ty_def->ty_parent \
&& !strcmp(p->ty_def->ty_parent->d_name, "builtin"))
#define TYPE_HAS_NAME(p) (type->ty_name)
#define TYPE_DEF_HAS_NAME(p) (type->ty_def && type->ty_def->ty_name)
void mie_printer_print_type(struct mie_printer *printer, const struct mie_type *type) void mie_printer_print_type(struct mie_printer *printer, const struct mie_type *type)
{ {
if (type->ty_def && type->ty_def->ty_print) { if (TYPE_HAS_PRINT_CALLBACK(type)) {
type->ty_def->ty_print(type, printer); type->ty_def->ty_print(type, printer);
} else if (type->ty_name) { } else if (TYPE_IS_BUILTIN(type)) {
b_stream_write_string(
printer->p_stream, type->ty_def->ty_name, NULL);
} else if (TYPE_HAS_NAME(type)) {
b_stream_write_char(printer->p_stream, '!');
b_stream_write_string(printer->p_stream, type->ty_name, NULL); b_stream_write_string(printer->p_stream, type->ty_name, NULL);
} else if (type->ty_def && type->ty_def->ty_name) { } else if (TYPE_DEF_HAS_NAME(type)) {
b_stream_write_char(printer->p_stream, '!');
b_stream_write_string( b_stream_write_string(
printer->p_stream, type->ty_def->ty_name, NULL); printer->p_stream, type->ty_def->ty_name, NULL);
} else { } else {