From 04af390fe818eace2a48789f70fdfdcf3e66ab92 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sun, 18 Jan 2026 21:19:15 +0000 Subject: [PATCH] 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. --- mie/include/mie/pass/builtin.h | 10 ++++++ mie/pass/builtin/builtin.c | 7 ++++ .../builtin/prefix-func-with-underscore.c | 35 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 mie/include/mie/pass/builtin.h create mode 100644 mie/pass/builtin/builtin.c create mode 100644 mie/pass/builtin/prefix-func-with-underscore.c diff --git a/mie/include/mie/pass/builtin.h b/mie/include/mie/pass/builtin.h new file mode 100644 index 0000000..930cd93 --- /dev/null +++ b/mie/include/mie/pass/builtin.h @@ -0,0 +1,10 @@ +#ifndef MIE_PASS_BUILTIN_H_ +#define MIE_PASS_BUILTIN_H_ + +#include + +struct mie_ctx; + +MIE_API enum mie_status mie_builtin_passes_register(struct mie_ctx *); + +#endif diff --git a/mie/pass/builtin/builtin.c b/mie/pass/builtin/builtin.c new file mode 100644 index 0000000..19fa546 --- /dev/null +++ b/mie/pass/builtin/builtin.c @@ -0,0 +1,7 @@ +#include +#include +#include + +MIE_PASS_GROUP_BEGIN(mie_builtin) + MIE_PASS_GROUP_ADD_PASS(prefix_func_with_underscore); +MIE_PASS_GROUP_END() diff --git a/mie/pass/builtin/prefix-func-with-underscore.c b/mie/pass/builtin/prefix-func-with-underscore.c new file mode 100644 index 0000000..5a844b5 --- /dev/null +++ b/mie/pass/builtin/prefix-func-with-underscore.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include +#include + +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()