tool: optimise: resolve ops; report any diagnostic messages
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#include "../diag/diag.h"
|
||||
#include "../resolve.h"
|
||||
#include "cmd.h"
|
||||
|
||||
#include <assert.h>
|
||||
@@ -13,6 +15,7 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/func.h>
|
||||
#include <mie/dialect/index.h>
|
||||
#include <mie/dialect/memref.h>
|
||||
#include <mie/dialect/meta.h>
|
||||
#include <mie/dialect/ptr.h>
|
||||
#include <mie/dialect/scf.h>
|
||||
@@ -23,6 +26,7 @@
|
||||
#include <mie/ir/op.h>
|
||||
#include <mie/ir/region.h>
|
||||
#include <mie/ir/register.h>
|
||||
#include <mie/ir/resolve.h>
|
||||
#include <mie/ir/walk.h>
|
||||
#include <mie/name.h>
|
||||
#include <mie/parse/lex.h>
|
||||
@@ -46,6 +50,16 @@ enum {
|
||||
OPT_PASS_OFFSET = 200,
|
||||
};
|
||||
|
||||
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 optimise_file(
|
||||
const b_command *cmd, const char *path, const b_arglist *args)
|
||||
{
|
||||
@@ -59,25 +73,11 @@ static int optimise_file(
|
||||
|
||||
printf("File OK\n");
|
||||
|
||||
b_arglist_iterator it;
|
||||
b_arglist_foreach(&it, args)
|
||||
{
|
||||
if (it.opt_id < OPT_PASS_OFFSET) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const b_command_option *opt = b_command_get_option(cmd, it.opt_id);
|
||||
if (!opt) {
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("running pass %s\n", b_command_option_get_long_name(opt));
|
||||
}
|
||||
|
||||
struct mie_ctx *ctx = mie_ctx_create();
|
||||
mie_builtin_dialect_create(ctx);
|
||||
mie_meta_dialect_create(ctx);
|
||||
mie_select_dialect_create(ctx);
|
||||
mie_memref_dialect_create(ctx);
|
||||
mie_ptr_dialect_create(ctx);
|
||||
mie_arith_dialect_create(ctx);
|
||||
mie_func_dialect_create(ctx);
|
||||
@@ -98,27 +98,11 @@ static int optimise_file(
|
||||
struct mie_op *root = mie_op_create();
|
||||
|
||||
if (!mie_parser_parse_op(parse, NULL, root)) {
|
||||
report_diag(ctx);
|
||||
printf("parse failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
enum mie_walker_flags flags = MIE_WALKER_F_INCLUDE_OPS
|
||||
| MIE_WALKER_F_PREORDER | MIE_WALKER_F_FORWARD
|
||||
| MIE_WALKER_F_RECURSIVE;
|
||||
struct mie_walker walker;
|
||||
mie_walker_begin(&walker, root, flags);
|
||||
|
||||
do {
|
||||
const struct mie_walk_item *item = mie_walker_get(&walker);
|
||||
for (size_t i = 0; i < item->i_depth; i++) {
|
||||
fputs(" ", stdout);
|
||||
}
|
||||
|
||||
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");
|
||||
} while (mie_walker_step(&walker) == MIE_SUCCESS);
|
||||
|
||||
struct mie_pass *prefix_func_with_underscore = NULL;
|
||||
if (mie_ctx_get_pass(
|
||||
ctx, "prefix-func-with-underscore", NULL,
|
||||
@@ -128,6 +112,11 @@ static int optimise_file(
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!resolve_op(root, ctx)) {
|
||||
report_diag(ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct mie_pass_manager *pm = mie_pass_manager_create(ctx);
|
||||
struct mie_pass_manager *module_pm = mie_pass_manager_nest(pm);
|
||||
mie_pass_manager_filter_op(module_pm, "builtin", "module");
|
||||
@@ -237,12 +226,13 @@ B_COMMAND(CMD_OPTIMISE, CMD_ROOT)
|
||||
struct mie_pass_definition *pass
|
||||
= b_unbox(struct mie_pass_definition, id, p_id);
|
||||
|
||||
B_COMMAND_OPTION_GEN(OPT_PASS_OFFSET + 1)
|
||||
B_COMMAND_OPTION_GEN(OPT_PASS_OFFSET + i)
|
||||
{
|
||||
B_OPTION_LONG_NAME(pass->p_name);
|
||||
B_OPTION_DESC(pass->p_description);
|
||||
}
|
||||
|
||||
node = b_btree_next(node);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user