tool: optimise: add flags to control ir output format
This commit is contained in:
@@ -47,6 +47,9 @@
|
|||||||
enum {
|
enum {
|
||||||
ARG_FILEPATH,
|
ARG_FILEPATH,
|
||||||
|
|
||||||
|
OPT_GENERIC,
|
||||||
|
OPT_NO_ABBREV,
|
||||||
|
|
||||||
OPT_PASS_OFFSET = 200,
|
OPT_PASS_OFFSET = 200,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -126,14 +129,47 @@ static int optimise_file(
|
|||||||
|
|
||||||
mie_pass_manager_add_pass(func_pm, prefix_func_with_underscore);
|
mie_pass_manager_add_pass(func_pm, prefix_func_with_underscore);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *pass_name = b_command_option_get_long_name(opt);
|
||||||
|
struct mie_pass *pass = NULL;
|
||||||
|
enum mie_status status
|
||||||
|
= mie_ctx_get_pass(ctx, pass_name, NULL, &pass);
|
||||||
|
if (status != MIE_SUCCESS) {
|
||||||
|
printf("cannot load pass %s\n", pass_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
mie_pass_manager_add_pass(func_pm, pass);
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
mie_pass_manager_parse(
|
mie_pass_manager_parse(
|
||||||
pm, "builtin.module(func.func(prefix-func-with-underscore))");
|
pm, "builtin.module(func.func(prefix-func-with-underscore))");
|
||||||
#endif
|
#endif
|
||||||
mie_pass_manager_run(pm, root);
|
mie_pass_manager_run(pm, root);
|
||||||
|
|
||||||
|
enum mie_print_flags flags = 0;
|
||||||
|
if (b_arglist_get_count(args, OPT_GENERIC, B_COMMAND_INVALID_ID) > 0) {
|
||||||
|
flags |= MIE_PRINT_F_GENERIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (b_arglist_get_count(args, OPT_NO_ABBREV, B_COMMAND_INVALID_ID) == 0) {
|
||||||
|
flags |= MIE_PRINT_F_ABBREVIATED;
|
||||||
|
}
|
||||||
|
|
||||||
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, flags);
|
||||||
mie_printer_print_op(&printer, root);
|
mie_printer_print_op(&printer, root);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
@@ -216,6 +252,21 @@ B_COMMAND(CMD_OPTIMISE, CMD_ROOT)
|
|||||||
B_ARG_NR_VALUES(1);
|
B_ARG_NR_VALUES(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
B_COMMAND_OPTION(OPT_GENERIC)
|
||||||
|
{
|
||||||
|
B_OPTION_LONG_NAME("generic");
|
||||||
|
B_OPTION_SHORT_NAME('g');
|
||||||
|
B_OPTION_DESC("print operations in generic format.");
|
||||||
|
}
|
||||||
|
|
||||||
|
B_COMMAND_OPTION(OPT_NO_ABBREV)
|
||||||
|
{
|
||||||
|
B_OPTION_LONG_NAME("no-abbrev");
|
||||||
|
B_OPTION_SHORT_NAME('n');
|
||||||
|
B_OPTION_DESC(
|
||||||
|
"don't use abbreviations for builtin types and ops.");
|
||||||
|
}
|
||||||
|
|
||||||
struct mie_ctx *ctx = mie_ctx_create();
|
struct mie_ctx *ctx = mie_ctx_create();
|
||||||
mie_builtin_passes_register(ctx);
|
mie_builtin_passes_register(ctx);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user