this system allows dialects to register named interfaces, which are collections of function pointers. an op can then implement this interface, providing callbacks for the interface's virtual function pointers. C code can request a pointer to an op's implementation of a given interface and call virtual functions with no knowledge required about the op itself. this functonality will also be extended to types, attributes, and dialects themselves.
40 lines
929 B
C
40 lines
929 B
C
#include <blue/ds/string.h>
|
|
#include <mie/dialect/dialect.h>
|
|
#include <mie/ir/op-definition.h>
|
|
|
|
struct mie_op_definition *mie_op_definition_create(
|
|
struct mie_dialect *parent, const char *name)
|
|
{
|
|
struct mie_op_definition *out = malloc(sizeof *out);
|
|
if (!out) {
|
|
return NULL;
|
|
}
|
|
|
|
out->op_name = b_strdup(name);
|
|
if (!out->op_name) {
|
|
free(out);
|
|
return NULL;
|
|
}
|
|
|
|
out->op_parent = parent;
|
|
mie_trait_table_init(&out->op_traits);
|
|
mie_interface_map_init(&out->op_iface);
|
|
|
|
b_rope name_rope = B_ROPE_CSTR(name);
|
|
mie_id_map_put(&parent->d_ops, &out->op_id, &name_rope);
|
|
|
|
return out;
|
|
}
|
|
|
|
enum mie_status mie_op_definition_add_trait(
|
|
struct mie_op_definition *op, const struct mie_trait *trait)
|
|
{
|
|
return mie_trait_table_put(&op->op_traits, trait);
|
|
}
|
|
|
|
enum mie_status mie_op_definition_add_interface(
|
|
struct mie_op_definition *op, struct mie_interface *interface)
|
|
{
|
|
return mie_interface_map_put(&op->op_iface, interface);
|
|
}
|