mie: pass: add a group of builtin passes

right now, the group only contains a single pass: prefix-func-with-underscore.
this is a test pass that visits instances of func.func and prepends
an underscore to the func's symbol name.
This commit is contained in:
2026-01-18 21:19:15 +00:00
parent 0add39f304
commit 04af390fe8
3 changed files with 52 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
#ifndef MIE_PASS_BUILTIN_H_
#define MIE_PASS_BUILTIN_H_
#include <mie/misc.h>
struct mie_ctx;
MIE_API enum mie_status mie_builtin_passes_register(struct mie_ctx *);
#endif

View File

@@ -0,0 +1,7 @@
#include <mie/ctx.h>
#include <mie/macros.h>
#include <mie/pass/pass-definition.h>
MIE_PASS_GROUP_BEGIN(mie_builtin)
MIE_PASS_GROUP_ADD_PASS(prefix_func_with_underscore);
MIE_PASS_GROUP_END()

View File

@@ -0,0 +1,35 @@
#include <mie/ctx.h>
#include <mie/dialect/builtin.h>
#include <mie/ir/op.h>
#include <mie/macros.h>
#include <mie/pass/pass-definition.h>
#include <mie/pass/pass.h>
static struct mie_pass_result transform(
struct mie_pass *pass, struct mie_op *op, struct mie_pass_args *args)
{
const struct mie_attribute *sym_name_attr
= mie_attribute_map_get(&op->op_attrib, "sym_name");
const char *sym_name = mie_string_get_cstr(sym_name_attr);
char tmp[256];
snprintf(tmp, sizeof tmp, "_%s", sym_name);
const struct mie_attribute *new_name
= mie_ctx_get_string(args->p_ctx, tmp);
mie_attribute_map_put(
&op->op_attrib, "sym_name", new_name, MIE_ATTRMAP_F_REPLACE);
printf("%s: taking a look at @%s\n", mie_pass_get_name(pass), sym_name);
return MIE_PASS_CONTINUE;
}
MIE_PASS_DEFINITION_BEGIN(prefix_func_with_underscore)
MIE_PASS_NAME("prefix-func-with-underscore");
MIE_PASS_DESCRIPTION(
"Test pass that prefixes the identifier of every function with "
"an underscore.");
MIE_PASS_TRANSFORM(transform);
MIE_PASS_FILTER_OP("func", "func");
MIE_PASS_DEFINITION_END()