diff --git a/tool/cmd/internal/ctx-dump.c b/tool/cmd/internal/ctx-dump.c index be88329..14aa49a 100644 --- a/tool/cmd/internal/ctx-dump.c +++ b/tool/cmd/internal/ctx-dump.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include #include #include @@ -29,108 +31,6 @@ #include #include -static int trait_ref_print(const struct mie_trait *trait, void *arg) -{ - fputc(' ', stdout); - mie_trait_print(trait, b_stdout); - - return 0; -} - -static void op_arg_dump(struct mie_printer *printer, const struct mie_op_arg *arg) -{ - enum mie_register_flags arg_flags = 0; - const char *arg_name = NULL; - const struct mie_type *arg_type = NULL; - - if (MIE_TEST_FLAGS(arg->arg_flags, MIE_OP_F_ARG_RESOLVED)) { - arg_flags = arg->arg_value.u_reg->reg_flags; - arg_name = arg->arg_value.u_reg->reg_name.n_str; - arg_type = arg->arg_value.u_reg->reg_type; - } else { - arg_flags = arg->arg_unresolved.reg_flags; - arg_name = arg->arg_unresolved.reg_name; - arg_type = arg->arg_unresolved.reg_type; - } - - if (arg_flags & MIE_REGISTER_F_MACHINE) { - b_printf(" [bold,red]MR"); - } else { - b_printf(" [bold,magenta]VR"); - } - - printf(":("); - mie_printer_print_type(printer, arg_type); - b_printf(")%s[reset]", arg_name); -} - -static void op_dump(const struct mie_op *op) -{ - b_stringstream *tmp = b_stringstream_create(); - struct mie_printer printer; - mie_printer_init(&printer, NULL, b_stdout, MIE_PRINT_F_GENERIC); - - printf("FLAGS:"); - (op->op_flags & MIE_OP_F_OP_RESOLVED) && printf(" OP_RESOLVED"); - (op->op_flags & MIE_OP_F_ARG_RESOLVED) && printf(" ARG_RESOLVED"); - printf("\n"); - printf("DIALECT: %s\n", - op->op_dialect ? op->op_dialect->d_name : ""); - printf("OP: %s\n", op->op_info ? op->op_info->op_name : ""); - printf("NAME: %s\n", op->op_name ? op->op_name : ""); - printf("TRAITS:"); - mie_trait_table_iterate(&op->op_info->op_traits, trait_ref_print, NULL); - printf("\n"); - printf("ATTRIBUTES:"); -#if 0 - for (size_t i = 0; i < MIE_VECTOR_COUNT(op->op_attrib); i++) { - printf(" (%s = ", op->op_attrib.items[i].attrib_name); - mie_printer_print_value( - &printer, op->op_attrib.items[i].attrib_value); - printf(")"); - } -#endif - printf("\n"); - - printf("REGIONS: %zu\n", b_queue_length(&op->op_regions)); - printf("SUCCESSORS:"); - for (size_t i = 0; i < MIE_VECTOR_COUNT(op->op_successors); i++) { - const struct mie_op_successor *s = &op->op_successors.items[i]; - if (MIE_TEST_FLAGS(s->s_flags, MIE_OP_F_SUCCESSOR_RESOLVED)) { - printf(" ^%s", s->s_block->b_name.n_str); - } else { - printf(" ^%s?", s->s_block_name); - } - - printf(":("); - - for (size_t i = 0; i < MIE_VECTOR_COUNT(s->s_args); i++) { - const struct mie_op_arg *arg = &s->s_args.items[i]; - op_arg_dump(&printer, arg); - } - - printf(" )"); - } - printf("\n"); - - printf("ARGS:"); - for (size_t i = 0; i < op->op_args.count; i++) { - const struct mie_op_arg *arg = &op->op_args.items[i]; - op_arg_dump(&printer, arg); - } - printf("\n"); - - printf("RESULT:"); - for (size_t i = 0; i < MIE_VECTOR_COUNT(op->op_result); i++) { - const struct mie_register *reg = &op->op_result.items[i]; - printf(" %s:(", - (reg->reg_flags & MIE_REGISTER_F_MACHINE) ? "MR" : "VR"); - mie_printer_print_type(&printer, reg->reg_type); - printf(")%s", reg->reg_name.n_str); - } - printf("\n"); -} - static void mie_op_definition_print(const struct mie_op_definition *op) { char id_str[MIE_ID_STRING_MAX]; @@ -187,6 +87,36 @@ static void mie_pass_definition_print(const struct mie_pass_definition *interfac interface->p_name, id_str); } +static void mie_diag_class_print( + const struct mie_dialect *dialect, const struct mie_diag_class *c) +{ + switch (c->c_type) { + case MIE_DIAG_CLASS_HINT: + b_printf(" [bold,cyan]Hint:[reset]"); + break; + case MIE_DIAG_CLASS_WARNING: + b_printf(" [bold,yellow]Warn:[reset]"); + break; + case MIE_DIAG_CLASS_ERROR: + b_printf(" [bold,red]Err: [reset]"); + break; + default: + return; + } + + b_printf( + "%s.%-25s [green]%s[reset]\n", dialect->d_name, + c->c_id_str_short, c->c_title); +} + +static void mie_diag_msg_print( + const struct mie_dialect *dialect, const struct mie_diag_msg *msg) +{ + b_printf( + " [bold,blue]Msg: [reset]%s.%-25s [green]%s[reset]\n", + dialect->d_name, msg->msg_id_str_short, msg->msg_content); +} + static void mie_dialect_print(const struct mie_dialect *dialect) { char id_str[MIE_ID_STRING_MAX]; @@ -269,6 +199,24 @@ static void mie_ctx_print(const struct mie_ctx *ctx) mie_pass_definition_print(pass); node = b_btree_next(node); } + + printf("\nDiagnostics:\n"); + node = b_btree_first(&ctx->ctx_dialects.map_entries); + while (node) { + mie_id *id = b_unbox(mie_id, node, e_node); + struct mie_dialect *dialect + = b_unbox(struct mie_dialect, id, d_id); + + for (size_t i = 0; i < dialect->d_nr_diag_classes; i++) { + mie_diag_class_print(dialect, &dialect->d_diag_classes[i]); + } + + for (size_t i = 0; i < dialect->d_nr_diag_msgs; i++) { + mie_diag_msg_print(dialect, &dialect->d_diag_msgs[i]); + } + + node = b_btree_next(node); + } } static int ctx_dump(const b_command *cmd, const b_arglist *args, const b_array *_)