diff --git a/mie/include/mie/print/printer.h b/mie/include/mie/print/printer.h index 709a782..a730126 100644 --- a/mie/include/mie/print/printer.h +++ b/mie/include/mie/print/printer.h @@ -8,6 +8,8 @@ struct mie_ctx; struct mie_module; struct mie_op; +struct mie_op_arg; +struct mie_op_successor; struct mie_region; struct mie_block; struct mie_type; @@ -43,6 +45,8 @@ MIE_API void mie_printer_print_region( MIE_API void mie_printer_print_block( struct mie_printer *printer, const struct mie_block *block, 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( struct mie_printer *printer, const struct mie_type *type); 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, 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 diff --git a/mie/print/block.c b/mie/print/block.c index a93b462..e915ad6 100644 --- a/mie/print/block.c +++ b/mie/print/block.c @@ -63,3 +63,9 @@ void mie_printer_print_block( 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); +} diff --git a/mie/print/op.c b/mie/print/op.c index b129399..72c3544 100644 --- a/mie/print/op.c +++ b/mie/print/op.c @@ -5,7 +5,7 @@ #include #include -static void print_op_arg( +void mie_printer_print_op_arg( struct mie_printer *printer, const struct mie_op_arg *arg, bool include_type) { enum mie_register_flags arg_flags = 0; @@ -39,8 +39,9 @@ static void print_op_arg( mie_printer_print_type(printer, arg_type); } -static void print_successor( - struct mie_printer *printer, const struct mie_op_successor *successor) +void mie_printer_print_op_successor( + struct mie_printer *printer, const struct mie_op_successor *successor, + bool compact) { b_stream_write_char(printer->p_stream, '^'); if (successor->s_flags & MIE_OP_F_SUCCESSOR_RESOLVED) { @@ -55,14 +56,18 @@ static void print_successor( 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++) { if (i > 0) { 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, ')'); @@ -82,7 +87,8 @@ static void print_successor_list( 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); @@ -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); } - 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, ')'); @@ -234,9 +240,44 @@ void mie_printer_print_op(struct mie_printer *printer, const struct mie_op *op) return; } - b_stream_write_fmt( - printer->p_stream, NULL, "%s.%s", op->op_dialect->d_name, - op->op_info->op_name); + mie_printer_print_op_name(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; +} diff --git a/mie/print/type.c b/mie/print/type.c index 444e019..bb5e60c 100644 --- a/mie/print/type.c +++ b/mie/print/type.c @@ -1,14 +1,27 @@ +#include #include #include #include +#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) { - if (type->ty_def && type->ty_def->ty_print) { + if (TYPE_HAS_PRINT_CALLBACK(type)) { 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); - } 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( printer->p_stream, type->ty_def->ty_name, NULL); } else {