mie: add select dialect

This commit is contained in:
2026-01-11 14:48:30 +00:00
parent 417b5dc354
commit fdf46b8867
6 changed files with 104 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
#include <mie/trait/trait-definition.h>
#include <mie/trait/trait.h>
static enum mie_status validate(
const struct mie_trait_definition *trait_def,
const struct mie_trait *trait, const struct mie_trait_target *target)
{
return MIE_SUCCESS;
}
/* select.graph-only trait:
* this is a graph-only op. references to it by name must be prefixed with +
* and the op can only be used within graph regions.
* a graph op can have the same name as a regular or non-graph op. */
MIE_TRAIT_DEFINITION_BEGIN(mie_select_graph_only, "graph-only")
MIE_TRAIT_DEFINITION_TARGETS(MIE_TRAIT_TARGET_OP | MIE_TRAIT_TARGET_TYPE);
MIE_TRAIT_DEFINITION_STRUCT(struct mie_trait);
MIE_TRAIT_DEFINITION_VALIDATE(validate);
MIE_TRAIT_DEFINITION_END()

View File

@@ -0,0 +1,21 @@
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
#include <mie/trait/trait-definition.h>
#include <mie/trait/trait.h>
static enum mie_status validate(
const struct mie_trait_definition *trait_def,
const struct mie_trait *trait, const struct mie_trait_target *target)
{
return MIE_SUCCESS;
}
/* select.graph-op trait:
* ops with this trait can be used within graph regions. by default, ops cannot
* be used in graph regions unless they have the graph-op or graph-only traits.
*/
MIE_TRAIT_DEFINITION_BEGIN(mie_select_graph_op, "graph-op")
MIE_TRAIT_DEFINITION_TARGETS(MIE_TRAIT_TARGET_OP | MIE_TRAIT_TARGET_TYPE);
MIE_TRAIT_DEFINITION_STRUCT(struct mie_trait);
MIE_TRAIT_DEFINITION_VALIDATE(validate);
MIE_TRAIT_DEFINITION_END()

View File

@@ -0,0 +1,21 @@
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
#include <mie/trait/trait-definition.h>
#include <mie/trait/trait.h>
static enum mie_status validate(
const struct mie_trait_definition *trait_def,
const struct mie_trait *trait, const struct mie_trait_target *target)
{
return MIE_SUCCESS;
}
/* select.graph-scope trait:
* regions of an op that has this trait are graph regions. graph regions
* cannot have more than one block, and the entry block must be unnamed
* with no parameters. However, graph ops can be used. */
MIE_TRAIT_DEFINITION_BEGIN(mie_select_graph_scope, "graph-scope")
MIE_TRAIT_DEFINITION_TARGETS(MIE_TRAIT_TARGET_OP | MIE_TRAIT_TARGET_TYPE);
MIE_TRAIT_DEFINITION_STRUCT(struct mie_trait);
MIE_TRAIT_DEFINITION_VALIDATE(validate);
MIE_TRAIT_DEFINITION_END()

View File

@@ -0,0 +1,21 @@
#include <mie/ctx.h>
#include <mie/dialect/dialect.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
#include <mie/trait/trait.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
{
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
MIE_OP_DEFINITION_BEGIN(mie_select_graph, "graph")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_TRAIT("select", "graph-scope");
MIE_OP_DEFINITION_END()

View File

@@ -0,0 +1,9 @@
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
MIE_DIALECT_BEGIN(mie_select, "select")
MIE_DIALECT_ADD_TRAIT(mie_select_graph_only);
MIE_DIALECT_ADD_TRAIT(mie_select_graph_op);
MIE_DIALECT_ADD_TRAIT(mie_select_graph_scope);
MIE_DIALECT_ADD_OP(mie_select_graph);
MIE_DIALECT_END()

View File

@@ -0,0 +1,11 @@
#ifndef MIE_DIALECT_SELECT_H_
#define MIE_DIALECT_SELECT_H_
#include <mie/misc.h>
struct mie_ctx;
struct mie_dialect;
MIE_API struct mie_dialect *mie_select_dialect_create(struct mie_ctx *ctx);
#endif