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:
10
mie/include/mie/pass/builtin.h
Normal file
10
mie/include/mie/pass/builtin.h
Normal 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
|
||||
7
mie/pass/builtin/builtin.c
Normal file
7
mie/pass/builtin/builtin.c
Normal 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()
|
||||
35
mie/pass/builtin/prefix-func-with-underscore.c
Normal file
35
mie/pass/builtin/prefix-func-with-underscore.c
Normal 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()
|
||||
Reference in New Issue
Block a user