tool: validate: resolve ops and references; report any diagnostics
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
#include "../diag/diag.h"
|
#include "../diag/diag.h"
|
||||||
|
#include "../resolve.h"
|
||||||
#include "cmd.h"
|
#include "cmd.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@@ -14,6 +15,7 @@
|
|||||||
#include <mie/dialect/dialect.h>
|
#include <mie/dialect/dialect.h>
|
||||||
#include <mie/dialect/func.h>
|
#include <mie/dialect/func.h>
|
||||||
#include <mie/dialect/index.h>
|
#include <mie/dialect/index.h>
|
||||||
|
#include <mie/dialect/memref.h>
|
||||||
#include <mie/dialect/meta.h>
|
#include <mie/dialect/meta.h>
|
||||||
#include <mie/dialect/ptr.h>
|
#include <mie/dialect/ptr.h>
|
||||||
#include <mie/dialect/scf.h>
|
#include <mie/dialect/scf.h>
|
||||||
@@ -45,6 +47,16 @@ enum {
|
|||||||
ARG_FILEPATH,
|
ARG_FILEPATH,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void report_diag(struct mie_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct mie_diag *diag = mie_ctx_pop_diag(ctx);
|
||||||
|
while (diag) {
|
||||||
|
mie_diag_write_pretty(diag, b_stdtty_err);
|
||||||
|
/* TODO cleanup */
|
||||||
|
diag = mie_ctx_pop_diag(ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int validate_file(const char *path, const b_arglist *args)
|
static int validate_file(const char *path, const b_arglist *args)
|
||||||
{
|
{
|
||||||
b_file *file = NULL;
|
b_file *file = NULL;
|
||||||
@@ -61,6 +73,7 @@ static int validate_file(const char *path, const b_arglist *args)
|
|||||||
mie_builtin_dialect_create(ctx);
|
mie_builtin_dialect_create(ctx);
|
||||||
mie_meta_dialect_create(ctx);
|
mie_meta_dialect_create(ctx);
|
||||||
mie_select_dialect_create(ctx);
|
mie_select_dialect_create(ctx);
|
||||||
|
mie_memref_dialect_create(ctx);
|
||||||
mie_ptr_dialect_create(ctx);
|
mie_ptr_dialect_create(ctx);
|
||||||
mie_arith_dialect_create(ctx);
|
mie_arith_dialect_create(ctx);
|
||||||
mie_func_dialect_create(ctx);
|
mie_func_dialect_create(ctx);
|
||||||
@@ -81,49 +94,15 @@ static int validate_file(const char *path, const b_arglist *args)
|
|||||||
struct mie_op *root = mie_op_create();
|
struct mie_op *root = mie_op_create();
|
||||||
|
|
||||||
if (!mie_parser_parse_op(parse, NULL, root)) {
|
if (!mie_parser_parse_op(parse, NULL, root)) {
|
||||||
struct mie_diag *diag = mie_ctx_pop_diag(ctx);
|
report_diag(ctx);
|
||||||
while (diag) {
|
|
||||||
mie_diag_write_pretty(diag, b_stdtty_err);
|
|
||||||
/* TODO cleanup */
|
|
||||||
diag = mie_ctx_pop_diag(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("parse failed\n");
|
printf("parse failed\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum mie_walker_flags walk_flags
|
if (!resolve_op(root, ctx)) {
|
||||||
= MIE_WALKER_F_INCLUDE_OPS | MIE_WALKER_F_PREORDER
|
report_diag(ctx);
|
||||||
| MIE_WALKER_F_FORWARD | MIE_WALKER_F_RECURSIVE;
|
return -1;
|
||||||
struct mie_walker walker;
|
}
|
||||||
mie_walker_begin(&walker, root, walk_flags);
|
|
||||||
|
|
||||||
do {
|
|
||||||
const struct mie_walk_item *item = mie_walker_get(&walker);
|
|
||||||
for (size_t i = 0; i < item->i_depth; i++) {
|
|
||||||
fputs(" ", stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (item->i_type) {
|
|
||||||
case MIE_WALK_ITEM_REGION:
|
|
||||||
printf("looking at region %p...\n", item->i_region);
|
|
||||||
continue;
|
|
||||||
case MIE_WALK_ITEM_BLOCK:
|
|
||||||
printf("looking at block %p %s...\n", item->i_block,
|
|
||||||
item->i_block->b_name.n_str);
|
|
||||||
continue;
|
|
||||||
case MIE_WALK_ITEM_OP:
|
|
||||||
|
|
||||||
printf("resolving %p %s... ", item->i_op,
|
|
||||||
item->i_op->op_name);
|
|
||||||
bool ok = mie_ctx_resolve_op(ctx, item->i_op);
|
|
||||||
printf("%s\n", ok ? "OK" : "FAIL");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (mie_walker_step(&walker) == MIE_SUCCESS);
|
|
||||||
mie_walker_end(&walker);
|
|
||||||
|
|
||||||
struct mie_pass *prefix_func_with_underscore = NULL;
|
struct mie_pass *prefix_func_with_underscore = NULL;
|
||||||
enum mie_status status = mie_ctx_get_pass(
|
enum mie_status status = mie_ctx_get_pass(
|
||||||
@@ -150,44 +129,52 @@ static int validate_file(const char *path, const b_arglist *args)
|
|||||||
mie_pass_manager_run(pm, root);
|
mie_pass_manager_run(pm, root);
|
||||||
|
|
||||||
struct mie_printer printer;
|
struct mie_printer printer;
|
||||||
mie_printer_init(&printer, ctx, b_stdout, MIE_PRINT_F_ABBREVIATED);
|
mie_printer_init(
|
||||||
|
&printer, ctx, b_stdout,
|
||||||
|
MIE_PRINT_F_ABBREVIATED | MIE_PRINT_F_MARK_UNRESOLVED_ELEMENTS);
|
||||||
mie_printer_print_op(&printer, root);
|
mie_printer_print_op(&printer, root);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
struct mie_op *func = mie_op_get_first_child_op(root);
|
#if 0
|
||||||
walk_flags = MIE_WALKER_F_INCLUDE_OPS | MIE_WALKER_F_PREORDER
|
struct mie_walker walker;
|
||||||
| MIE_WALKER_F_FORWARD;
|
enum mie_walker_flags walk_flags = MIE_WALKER_F_INCLUDE_BLOCKS
|
||||||
mie_walker_begin(&walker, func, walk_flags);
|
| MIE_WALKER_F_PREORDER
|
||||||
|
| MIE_WALKER_F_FORWARD;
|
||||||
|
mie_walker_begin(&walker, root, walk_flags);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
const struct mie_walk_item *item = mie_walker_get(&walker);
|
const struct mie_walk_item *item = mie_walker_get(&walker);
|
||||||
for (size_t i = 0; i < item->i_depth; i++) {
|
printf("looking at block %p %s...\n", item->i_block,
|
||||||
fputs(" ", stdout);
|
item->i_block->b_name.n_str);
|
||||||
}
|
printf(" id=%u\n", item->i_block->b_id);
|
||||||
|
const char *idom = item->i_block->b_idom
|
||||||
|
? item->i_block->b_idom->b_name.n_str
|
||||||
|
: "Unk";
|
||||||
|
printf(" idom=%s\n", idom);
|
||||||
|
#if 0
|
||||||
|
const char *sdom = item->i_block->b_sdom
|
||||||
|
? item->i_block->b_sdom->b_name.n_str
|
||||||
|
: "Unk";
|
||||||
|
const char *dfs_parent
|
||||||
|
= item->i_block->b_dfs_parent
|
||||||
|
? item->i_block->b_dfs_parent->b_name.n_str
|
||||||
|
: "Unk";
|
||||||
|
printf(" sdom=%s\n", sdom);
|
||||||
|
printf(" dfs_parent=%s\n", dfs_parent);
|
||||||
|
#endif
|
||||||
|
|
||||||
switch (item->i_type) {
|
printf(" preds=");
|
||||||
case MIE_WALK_ITEM_REGION:
|
|
||||||
printf("looking at region %p...\n", item->i_region);
|
struct mie_block_predecessor *pred
|
||||||
break;
|
= mie_block_get_first_predecessor(item->i_block);
|
||||||
case MIE_WALK_ITEM_BLOCK:
|
while (pred) {
|
||||||
printf("looking at block %p %s...\n", item->i_block,
|
printf(" %s", pred->p_block->b_name.n_str);
|
||||||
item->i_block->b_name.n_str);
|
pred = mie_block_get_next_predecessor(item->i_block, pred);
|
||||||
break;
|
|
||||||
case MIE_WALK_ITEM_OP:
|
|
||||||
if (item->i_op->op_flags & MIE_OP_F_OP_RESOLVED) {
|
|
||||||
printf("looking at %p %s.%s...\n", item->i_op,
|
|
||||||
item->i_op->op_dialect->d_name,
|
|
||||||
item->i_op->op_info->op_name);
|
|
||||||
} else {
|
|
||||||
printf("looking at %p %s...\n", item->i_op,
|
|
||||||
item->i_op->op_name);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
printf("\n");
|
||||||
} while (mie_walker_step(&walker) == MIE_SUCCESS);
|
} while (mie_walker_step(&walker) == MIE_SUCCESS);
|
||||||
mie_walker_end(&walker);
|
mie_walker_end(&walker);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user