mie: move op and type definition from dialect/ to ir/ and type/ respectively

This commit is contained in:
2026-01-08 22:16:50 +00:00
parent 27e42340de
commit e76e7c17db
35 changed files with 285 additions and 283 deletions

View File

@@ -7,10 +7,10 @@
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/dialect/index.h>
#include <mie/dialect/type.h>
#include <mie/ir/op.h>
#include <mie/type/function.h>
#include <mie/type/storage.h>
#include <mie/type/type-definition.h>
#include <mie/type/type.h>
#include <stdlib.h>
#include <string.h>
@@ -358,7 +358,7 @@ bool mie_ctx_resolve_op(const struct mie_ctx *ctx, struct mie_op *op)
return false;
}
const struct mie_dialect_op *op_info
const struct mie_op_definition *op_info
= mie_dialect_get_op(dialect, op_name);
if (!op) {
return false;
@@ -385,7 +385,7 @@ struct mie_dialect *mie_ctx_get_dialect(const struct mie_ctx *ctx, const char *n
return b_unbox(struct mie_dialect, target, d_id);
}
struct mie_dialect_type *mie_ctx_get_dialect_type(
struct mie_type_definition *mie_ctx_get_type_definition(
const struct mie_ctx *ctx, const char *dialect_name, const char *type_name)
{
b_rope dialect_name_rope = B_ROPE_CSTR(dialect_name);
@@ -403,7 +403,7 @@ struct mie_dialect_type *mie_ctx_get_dialect_type(
mie_id_init_ns(&id, mie_id_map_get_ns(&dialect->d_types), &type_name_rope);
target = mie_id_map_get(&dialect->d_types, &id);
return b_unbox(struct mie_dialect_type, target, ty_id);
return b_unbox(struct mie_type_definition, target, ty_id);
}
struct mie_type *mie_ctx_get_type(
@@ -422,8 +422,8 @@ struct mie_type *mie_ctx_get_type(
return type;
}
struct mie_dialect_type *type_info
= mie_ctx_get_dialect_type(ctx, dialect_name, type_name);
struct mie_type_definition *type_info
= mie_ctx_get_type_definition(ctx, dialect_name, type_name);
if (!type_info /* || (type_info->ty_flags & MIE_DIALECT_TYPE_PARAMETISED) */) {
/* cannot initialise unknown or parametised types */
return NULL;

View File

@@ -1,5 +1,5 @@
#include <mie/dialect/dialect.h>
#include <mie/dialect/op.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
@@ -12,7 +12,7 @@ static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
return MIE_SUCCESS;
}
MIE_DIALECT_OP_BEGIN(mie_arith_addf, "addf")
MIE_DIALECT_OP_PRINT(print);
MIE_DIALECT_OP_PARSE(parse);
MIE_DIALECT_OP_END()
MIE_OP_DEFINITION_BEGIN(mie_arith_addf, "addf")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -1,5 +1,5 @@
#include <mie/dialect/dialect.h>
#include <mie/dialect/op.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
@@ -12,7 +12,7 @@ static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
return MIE_SUCCESS;
}
MIE_DIALECT_OP_BEGIN(mie_arith_addi, "addi")
MIE_DIALECT_OP_PRINT(print);
MIE_DIALECT_OP_PARSE(parse);
MIE_DIALECT_OP_END()
MIE_OP_DEFINITION_BEGIN(mie_arith_addi, "addi")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -2,8 +2,8 @@
#include <mie/ctx.h>
#include <mie/dialect/arith.h>
#include <mie/dialect/dialect.h>
#include <mie/dialect/type.h>
#include <mie/macros.h>
#include <mie/type/type-definition.h>
#include <mie/type/type.h>
#include <mie/value.h>
@@ -12,7 +12,7 @@ struct float_type {
size_t f_width;
};
static void value_print(
static enum mie_status value_print(
const struct mie_type *ty, const struct mie_value *value, b_stream *out)
{
struct float_type *float_ty = (struct float_type *)ty;
@@ -32,12 +32,14 @@ static void value_print(
b_stream_write_fmt(out, NULL, "NaN : f%zu", float_ty->f_width);
break;
}
return MIE_SUCCESS;
}
struct mie_type *mie_arith_float_get_type(struct mie_ctx *ctx, size_t bit_width)
{
struct mie_dialect_type *type_info
= mie_ctx_get_dialect_type(ctx, "arith", "float");
struct mie_type_definition *type_info
= mie_ctx_get_type_definition(ctx, "arith", "float");
if (!type_info) {
return NULL;
}
@@ -68,22 +70,23 @@ struct mie_type *mie_arith_float_get_type(struct mie_ctx *ctx, size_t bit_width)
}
static enum mie_status print(
const struct mie_dialect_type *def, const struct mie_type *ty, b_stream *out)
const struct mie_type_definition *def, const struct mie_type *ty,
b_stream *out)
{
return MIE_SUCCESS;
}
static enum mie_status parse(
const struct mie_dialect_type *def, struct mie_parser *parser,
const struct mie_type_definition *def, struct mie_parser *parser,
struct mie_type **out)
{
return MIE_SUCCESS;
}
MIE_DIALECT_TYPE_BEGIN(mie_arith_float, "float")
// MIE_DIALECT_TYPE_FLAGS(MIE_DIALECT_TYPE_PARAMETISED);
MIE_DIALECT_TYPE_STRUCT(struct float_type);
MIE_DIALECT_TYPE_PRINT(print);
MIE_DIALECT_TYPE_PARSE(parse);
MIE_DIALECT_TYPE_VALUE_PRINT(value_print);
MIE_DIALECT_TYPE_END()
MIE_TYPE_DEFINITION_BEGIN(mie_arith_float, "float")
// MIE_TYPE_DEFINITION_FLAGS(MIE_TYPE_DEFINITION_PARAMETISED);
MIE_TYPE_DEFINITION_STRUCT(struct float_type);
MIE_TYPE_DEFINITION_PRINT(print);
MIE_TYPE_DEFINITION_PARSE(parse);
MIE_TYPE_DEFINITION_VALUE_PRINT(value_print);
MIE_TYPE_DEFINITION_END()

View File

@@ -2,8 +2,8 @@
#include <mie/ctx.h>
#include <mie/dialect/arith.h>
#include <mie/dialect/dialect.h>
#include <mie/dialect/type.h>
#include <mie/macros.h>
#include <mie/type/type-definition.h>
#include <mie/type/type.h>
#include <mie/value.h>
@@ -12,7 +12,7 @@ struct int_type {
size_t i_width;
};
static void value_print(
static enum mie_status value_print(
const struct mie_type *ty, const struct mie_value *value, b_stream *out)
{
struct int_type *int_ty = (struct int_type *)ty;
@@ -24,12 +24,14 @@ static void value_print(
} else {
b_stream_write_fmt(out, NULL, "INF : i%zu", int_ty->i_width);
}
return MIE_SUCCESS;
}
struct mie_type *mie_arith_int_get_type(struct mie_ctx *ctx, size_t bit_width)
{
struct mie_dialect_type *type_info
= mie_ctx_get_dialect_type(ctx, "arith", "int");
struct mie_type_definition *type_info
= mie_ctx_get_type_definition(ctx, "arith", "int");
if (!type_info) {
return NULL;
}
@@ -60,22 +62,23 @@ struct mie_type *mie_arith_int_get_type(struct mie_ctx *ctx, size_t bit_width)
}
static enum mie_status print(
const struct mie_dialect_type *def, const struct mie_type *ty, b_stream *out)
const struct mie_type_definition *def, const struct mie_type *ty,
b_stream *out)
{
return MIE_SUCCESS;
}
static enum mie_status parse(
const struct mie_dialect_type *def, struct mie_parser *parser,
const struct mie_type_definition *def, struct mie_parser *parser,
struct mie_type **out)
{
return MIE_SUCCESS;
}
MIE_DIALECT_TYPE_BEGIN(mie_arith_int, "int")
// MIE_DIALECT_TYPE_FLAGS(MIE_DIALECT_TYPE_PARAMETISED);
MIE_DIALECT_TYPE_STRUCT(struct int_type);
MIE_DIALECT_TYPE_PRINT(print);
MIE_DIALECT_TYPE_PARSE(parse);
MIE_DIALECT_TYPE_VALUE_PRINT(value_print);
MIE_DIALECT_TYPE_END()
MIE_TYPE_DEFINITION_BEGIN(mie_arith_int, "int")
// MIE_TYPE_DEFINITION_FLAGS(MIE_TYPE_DEFINITION_PARAMETISED);
MIE_TYPE_DEFINITION_STRUCT(struct int_type);
MIE_TYPE_DEFINITION_PRINT(print);
MIE_TYPE_DEFINITION_PARSE(parse);
MIE_TYPE_DEFINITION_VALUE_PRINT(value_print);
MIE_TYPE_DEFINITION_END()

View File

@@ -2,40 +2,43 @@
#include <mie/ctx.h>
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/dialect/type.h>
#include <mie/macros.h>
#include <mie/type/type-definition.h>
#include <mie/type/type.h>
#include <mie/value.h>
static void value_print(
static enum mie_status value_print(
const struct mie_type *ty, const struct mie_value *value, b_stream *out)
{
const struct mie_string *str = (const struct mie_string *)value;
b_stream_write_fmt(out, NULL, "\"%s\"", str->str_val);
return MIE_SUCCESS;
}
static void type_init(const struct mie_dialect_type *type_info, struct mie_type *type)
static void type_init(
const struct mie_type_definition *type_info, struct mie_type *type)
{
type->ty_instance_size = sizeof(struct mie_string);
}
static enum mie_status print(
const struct mie_dialect_type *def, const struct mie_type *ty, b_stream *out)
const struct mie_type_definition *def, const struct mie_type *ty,
b_stream *out)
{
return MIE_SUCCESS;
}
static enum mie_status parse(
const struct mie_dialect_type *def, struct mie_parser *parser,
const struct mie_type_definition *def, struct mie_parser *parser,
struct mie_type **out)
{
return MIE_SUCCESS;
}
MIE_DIALECT_TYPE_BEGIN(mie_builtin_string, "string")
MIE_DIALECT_TYPE_STRUCT(struct mie_type);
MIE_DIALECT_TYPE_INIT(type_init);
MIE_DIALECT_TYPE_PRINT(print);
MIE_DIALECT_TYPE_PARSE(parse);
MIE_DIALECT_TYPE_VALUE_PRINT(value_print);
MIE_DIALECT_TYPE_END()
MIE_TYPE_DEFINITION_BEGIN(mie_builtin_string, "string")
MIE_TYPE_DEFINITION_STRUCT(struct mie_type);
MIE_TYPE_DEFINITION_INIT(type_init);
MIE_TYPE_DEFINITION_PRINT(print);
MIE_TYPE_DEFINITION_PARSE(parse);
MIE_TYPE_DEFINITION_VALUE_PRINT(value_print);
MIE_TYPE_DEFINITION_END()

View File

@@ -1,5 +1,5 @@
#include <mie/dialect/dialect.h>
#include <mie/dialect/op.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
@@ -12,7 +12,7 @@ static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
return MIE_SUCCESS;
}
MIE_DIALECT_OP_BEGIN(mie_cf_br_cond, "br-cond")
MIE_DIALECT_OP_PRINT(print);
MIE_DIALECT_OP_PARSE(parse);
MIE_DIALECT_OP_END()
MIE_OP_DEFINITION_BEGIN(mie_cf_br_cond, "br-cond")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -1,5 +1,5 @@
#include <mie/dialect/dialect.h>
#include <mie/dialect/op.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
@@ -12,7 +12,7 @@ static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
return MIE_SUCCESS;
}
MIE_DIALECT_OP_BEGIN(mie_cf_br, "br")
MIE_DIALECT_OP_PRINT(print);
MIE_DIALECT_OP_PARSE(parse);
MIE_DIALECT_OP_END()
MIE_OP_DEFINITION_BEGIN(mie_cf_br, "br")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -1,8 +1,8 @@
#include <blue/ds/string.h>
#include <mie/ctx.h>
#include <mie/dialect/dialect.h>
#include <mie/dialect/op.h>
#include <mie/dialect/type.h>
#include <mie/ir/op-definition.h>
#include <mie/type/type-definition.h>
#define TYPE_NS_ID \
MIE_ID(0xe4, 0x99, 0x42, 0x58, 0x2b, 0xdb, 0x45, 0xa3, 0xbd, 0x4b, \
@@ -38,7 +38,7 @@ struct mie_dialect *mie_dialect_create(struct mie_ctx *ctx, const char *name)
return out;
}
const struct mie_dialect_op *mie_dialect_get_op(
const struct mie_op_definition *mie_dialect_get_op(
const struct mie_dialect *dialect, const char *name)
{
b_rope name_rope = B_ROPE_CSTR(name);
@@ -46,10 +46,10 @@ const struct mie_dialect_op *mie_dialect_get_op(
mie_id_init_ns(&id, mie_id_map_get_ns(&dialect->d_ops), &name_rope);
mie_id *target = mie_id_map_get(&dialect->d_ops, &id);
return b_unbox(struct mie_dialect_op, target, op_id);
return b_unbox(struct mie_op_definition, target, op_id);
}
const struct mie_dialect_type *mie_dialect_get_type(
const struct mie_type_definition *mie_dialect_get_type(
const struct mie_dialect *dialect, const char *name)
{
b_rope name_rope = B_ROPE_CSTR(name);
@@ -57,5 +57,5 @@ const struct mie_dialect_type *mie_dialect_get_type(
mie_id_init_ns(&id, mie_id_map_get_ns(&dialect->d_types), &name_rope);
mie_id *target = mie_id_map_get(&dialect->d_types, &id);
return b_unbox(struct mie_dialect_type, target, ty_id);
return b_unbox(struct mie_type_definition, target, ty_id);
}

View File

@@ -1,5 +1,5 @@
#include <mie/dialect/dialect.h>
#include <mie/dialect/op.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
@@ -12,10 +12,10 @@ static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
return MIE_SUCCESS;
}
MIE_DIALECT_OP_BEGIN(mie_func_func, "func")
MIE_DIALECT_OP_PRINT(print);
MIE_DIALECT_OP_PARSE(parse);
MIE_DIALECT_OP_END()
MIE_OP_DEFINITION_BEGIN(mie_func_func, "func")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()
MIE_DIALECT_BEGIN(mie_func, "func")
MIE_DIALECT_ADD_OP(mie_func_func);

View File

@@ -1,7 +1,7 @@
#include <mie/dialect/dialect.h>
#include <mie/dialect/index.h>
#include <mie/dialect/type.h>
#include <mie/macros.h>
#include <mie/type/type-definition.h>
#include <mie/type/type.h>
#include <mie/value.h>
@@ -9,7 +9,7 @@ struct index_type {
struct mie_type i_base;
};
static void value_print(
static enum mie_status value_print(
const struct mie_type *ty, const struct mie_value *value, b_stream *out)
{
struct index_type *index_ty = (struct index_type *)ty;
@@ -17,33 +17,36 @@ static void value_print(
b_stream_write_fmt(
out, NULL, "%zu : %s", index_val->i_value,
index_ty->i_base.ty_def->ty_name);
return MIE_SUCCESS;
}
static void type_init(const struct mie_dialect_type *type_info, struct mie_type *type)
static void type_init(
const struct mie_type_definition *type_info, struct mie_type *type)
{
type->ty_instance_size = sizeof(struct mie_index);
}
static enum mie_status print(
const struct mie_dialect_type *def, const struct mie_type *ty, b_stream *out)
const struct mie_type_definition *def, const struct mie_type *ty,
b_stream *out)
{
return MIE_SUCCESS;
}
static enum mie_status parse(
const struct mie_dialect_type *def, struct mie_parser *parser,
const struct mie_type_definition *def, struct mie_parser *parser,
struct mie_type **out)
{
return MIE_SUCCESS;
}
MIE_DIALECT_TYPE_BEGIN(mie_index_index, "index")
MIE_DIALECT_TYPE_STRUCT(struct index_type);
MIE_DIALECT_TYPE_INIT(type_init);
MIE_DIALECT_TYPE_PRINT(print);
MIE_DIALECT_TYPE_PARSE(parse);
MIE_DIALECT_TYPE_VALUE_PRINT(value_print);
MIE_DIALECT_TYPE_END()
MIE_TYPE_DEFINITION_BEGIN(mie_index_index, "index")
MIE_TYPE_DEFINITION_STRUCT(struct index_type);
MIE_TYPE_DEFINITION_INIT(type_init);
MIE_TYPE_DEFINITION_PRINT(print);
MIE_TYPE_DEFINITION_PARSE(parse);
MIE_TYPE_DEFINITION_VALUE_PRINT(value_print);
MIE_TYPE_DEFINITION_END()
MIE_DIALECT_BEGIN(mie_index, "index")
MIE_DIALECT_ADD_TYPE(mie_index_index);

View File

@@ -1,5 +1,5 @@
#include <mie/dialect/dialect.h>
#include <mie/dialect/op.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
@@ -12,7 +12,7 @@ static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
return MIE_SUCCESS;
}
MIE_DIALECT_OP_BEGIN(mie_meta_source_filename, "source-filename")
MIE_DIALECT_OP_PRINT(print);
MIE_DIALECT_OP_PARSE(parse);
MIE_DIALECT_OP_END()
MIE_OP_DEFINITION_BEGIN(mie_meta_source_filename, "source-filename")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -1,5 +1,5 @@
#include <mie/dialect/dialect.h>
#include <mie/dialect/op.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
@@ -12,7 +12,7 @@ static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
return MIE_SUCCESS;
}
MIE_DIALECT_OP_BEGIN(mie_ptr_load, "load")
MIE_DIALECT_OP_PRINT(print);
MIE_DIALECT_OP_PARSE(parse);
MIE_DIALECT_OP_END()
MIE_OP_DEFINITION_BEGIN(mie_ptr_load, "load")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -1,29 +1,30 @@
#include <mie/dialect/dialect.h>
#include <mie/dialect/type.h>
#include <mie/macros.h>
#include <mie/type/type-definition.h>
struct ptr_type {
struct mie_dialect_type ptr_base;
struct mie_type_definition ptr_base;
};
static enum mie_status print(
const struct mie_dialect_type *def, const struct mie_type *ty, b_stream *out)
const struct mie_type_definition *def, const struct mie_type *ty,
b_stream *out)
{
return MIE_SUCCESS;
}
static enum mie_status parse(
const struct mie_dialect_type *def, struct mie_parser *parser,
const struct mie_type_definition *def, struct mie_parser *parser,
struct mie_type **out)
{
return MIE_SUCCESS;
}
MIE_DIALECT_TYPE_BEGIN(mie_ptr_ptr, "ptr")
MIE_DIALECT_TYPE_STRUCT(struct ptr_type);
MIE_DIALECT_TYPE_PRINT(print);
MIE_DIALECT_TYPE_PARSE(parse);
MIE_DIALECT_TYPE_END()
MIE_TYPE_DEFINITION_BEGIN(mie_ptr_ptr, "ptr")
MIE_TYPE_DEFINITION_STRUCT(struct ptr_type);
MIE_TYPE_DEFINITION_PRINT(print);
MIE_TYPE_DEFINITION_PARSE(parse);
MIE_TYPE_DEFINITION_END()
MIE_DIALECT_BEGIN(mie_ptr, "ptr")
MIE_DIALECT_ADD_OP(mie_ptr_load);

View File

@@ -1,5 +1,5 @@
#include <mie/dialect/dialect.h>
#include <mie/dialect/op.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
@@ -12,7 +12,7 @@ static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
return MIE_SUCCESS;
}
MIE_DIALECT_OP_BEGIN(mie_ptr_store, "store")
MIE_DIALECT_OP_PRINT(print);
MIE_DIALECT_OP_PARSE(parse);
MIE_DIALECT_OP_END()
MIE_OP_DEFINITION_BEGIN(mie_ptr_store, "store")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -1,5 +1,5 @@
#include <mie/dialect/dialect.h>
#include <mie/dialect/op.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
@@ -12,7 +12,7 @@ static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
return MIE_SUCCESS;
}
MIE_DIALECT_OP_BEGIN(mie_scf_for, "for")
MIE_DIALECT_OP_PRINT(print);
MIE_DIALECT_OP_PARSE(parse);
MIE_DIALECT_OP_END()
MIE_OP_DEFINITION_BEGIN(mie_scf_for, "for")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -1,5 +1,5 @@
#include <mie/dialect/dialect.h>
#include <mie/dialect/op.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
@@ -12,7 +12,7 @@ static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
return MIE_SUCCESS;
}
MIE_DIALECT_OP_BEGIN(mie_scf_if, "if")
MIE_DIALECT_OP_PRINT(print);
MIE_DIALECT_OP_PARSE(parse);
MIE_DIALECT_OP_END()
MIE_OP_DEFINITION_BEGIN(mie_scf_if, "if")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -1,5 +1,3 @@
#include "scf.h"
#include <mie/dialect/dialect.h>
#include <mie/macros.h>

View File

@@ -1,7 +0,0 @@
#ifndef MIE_DIALECT_SCF_H_
#define MIE_DIALECT_SCF_H_
#include <mie/dialect/dialect.h>
#include <mie/dialect/op.h>
#endif

View File

@@ -1,5 +1,5 @@
#include <mie/dialect/dialect.h>
#include <mie/dialect/op.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
@@ -12,7 +12,7 @@ static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
return MIE_SUCCESS;
}
MIE_DIALECT_OP_BEGIN(mie_scf_yield, "yield")
MIE_DIALECT_OP_PRINT(print);
MIE_DIALECT_OP_PARSE(parse);
MIE_DIALECT_OP_END()
MIE_OP_DEFINITION_BEGIN(mie_scf_yield, "yield")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -38,7 +38,7 @@ MIE_API bool mie_ctx_resolve_op(const struct mie_ctx *ctx, struct mie_op *op);
MIE_API struct mie_dialect *mie_ctx_get_dialect(
const struct mie_ctx *ctx, const char *name);
MIE_API struct mie_dialect_type *mie_ctx_get_dialect_type(
MIE_API struct mie_type_definition *mie_ctx_get_type_definition(
const struct mie_ctx *ctx, const char *dialect_name, const char *type_name);
MIE_API struct mie_type *mie_ctx_get_type(
struct mie_ctx *ctx, const char *dialect_name, const char *type_name);

View File

@@ -9,17 +9,17 @@
struct mie_ctx;
struct mie_dialect_op;
struct mie_dialect_type;
struct mie_op_definition;
struct mie_type_definition;
struct mie_trait_definition;
struct mie_dialect {
mie_id d_id;
char *d_name;
/* map of struct mie_dialect_op */
/* map of struct mie_op_definition */
struct mie_id_map d_ops;
/* map of struct mie_dialect_type */
/* map of struct mie_type_definition */
struct mie_id_map d_types;
/* map of struct mie_trait_definition */
struct mie_id_map d_traits;
@@ -28,9 +28,9 @@ struct mie_dialect {
MIE_API struct mie_dialect *mie_dialect_create(
struct mie_ctx *ctx, const char *name);
MIE_API const struct mie_dialect_op *mie_dialect_get_op(
MIE_API const struct mie_op_definition *mie_dialect_get_op(
const struct mie_dialect *dialect, const char *name);
MIE_API const struct mie_dialect_type *mie_dialect_get_type(
MIE_API const struct mie_type_definition *mie_dialect_get_type(
const struct mie_dialect *dialect, const char *name);
MIE_API const struct mie_trait_definition *mie_dialect_get_trait(
const struct mie_dialect *dialect, const char *name);

View File

@@ -1,52 +0,0 @@
#ifndef MIE_DIALECT_TYPE_H_
#define MIE_DIALECT_TYPE_H_
#include <blue/core/btree.h>
#include <blue/core/stream.h>
#include <mie/id.h>
#include <mie/status.h>
#include <mie/trait/trait-table.h>
struct mie_type;
struct mie_value;
struct mie_parser;
struct mie_dialect;
enum mie_type_trait {
/* this type is parametised. one or more arguments are required to create
* a corresponding mie_type instance. in textual IR, references to this
* type will be followed by a set of arguments surrounded
* by <angle brackets>. */
MIE_TYPE_TRAIT_PARAMETISED = 0x01u,
/* this type can only be used within graph regions. unlike graph ops,
* no special prefix is required */
MIE_TYPE_TRAIT_GRAPH_TYPE = 0x02u,
};
struct mie_dialect_type {
mie_id ty_id;
struct mie_trait_table ty_traits;
struct mie_dialect *ty_parent;
char *ty_name;
size_t ty_data_size;
void (*ty_init)(const struct mie_dialect_type *, struct mie_type *);
void (*ty_cleanup)(const struct mie_dialect_type *, struct mie_type *);
void (*ty_instance_cleanup)(const struct mie_type *, struct mie_value *);
enum mie_status (*ty_print)(
const struct mie_dialect_type *, const struct mie_type *,
b_stream *);
void (*ty_value_print)(
const struct mie_type *, const struct mie_value *, b_stream *);
enum mie_status (*ty_parse)(
const struct mie_dialect_type *, struct mie_parser *,
struct mie_type **);
void (*ty_build_id)(const struct mie_type *, struct mie_id_builder *);
};
MIE_API struct mie_dialect_type *mie_dialect_type_create(
struct mie_dialect *parent, const char *name);
#endif

View File

@@ -1,5 +1,5 @@
#ifndef MIE_DIALECT_OP_H_
#define MIE_DIALECT_OP_H_
#ifndef MIE_IR_OP_DEFINITION_H_
#define MIE_IR_OP_DEFINITION_H_
#include <blue/core/btree.h>
#include <blue/core/stream.h>
@@ -14,6 +14,7 @@ struct mie_op;
struct mie_parser;
struct mie_dialect;
#if 0
enum mie_op_trait {
MIE_OP_TRAIT_NONE = 0x00u,
@@ -34,6 +35,7 @@ enum mie_op_trait {
* values defined in the enclosing scope. */
MIE_OP_TRAIT_ISOLATED_FROM_ABOVE = 0x08u,
};
#endif
enum mie_op_param_type {
/* op has no parameter */
@@ -88,7 +90,7 @@ struct mie_op_result {
};
};
struct mie_dialect_op {
struct mie_op_definition {
mie_id op_id;
struct mie_dialect *op_parent;
char *op_name;
@@ -101,7 +103,7 @@ struct mie_dialect_op {
enum mie_status (*op_parse)(struct mie_parser *, struct mie_op *);
};
MIE_API struct mie_dialect_op *mie_dialect_op_create(
MIE_API struct mie_op_definition *mie_op_definition_create(
struct mie_dialect *parent, const char *name);
#endif

View File

@@ -15,7 +15,7 @@ struct mie_block;
struct mie_region;
struct mie_dialect;
struct mie_dialect_op;
struct mie_op_definition;
enum mie_op_flags {
MIE_OP_F_OP_RESOLVED = 0x01u,
@@ -47,7 +47,7 @@ struct mie_op {
/* these pointers are only valid if the F_RESOLVED flag is set */
const struct mie_dialect *op_dialect;
const struct mie_dialect_op *op_info;
const struct mie_op_definition *op_info;
struct mie_file_span op_name_span;
/* only valid if the F_RESOLVED flag is NOT set */

View File

@@ -8,71 +8,72 @@
if (!self) { \
return NULL; \
} \
struct mie_dialect_op *op = NULL; \
struct mie_dialect_type *type = NULL;
struct mie_op_definition *op = NULL; \
struct mie_type_definition *type = NULL;
#define __MIE_DIALECT_END() \
return self; \
}
#define __MIE_DIALECT_OP_BEGIN(func_prefix, op_name) \
struct mie_dialect_op *func_prefix##_op_create( \
#define __MIE_OP_DEFINITION_BEGIN(func_prefix, op_name) \
struct mie_op_definition *func_prefix##_op_create( \
struct mie_dialect *d, struct mie_ctx *ctx) \
{ \
struct mie_dialect_op *op = mie_dialect_op_create(d, op_name); \
struct mie_op_definition *op \
= mie_op_definition_create(d, op_name); \
if (!op) { \
return NULL; \
}
#define __MIE_DIALECT_OP_END() \
#define __MIE_OP_DEFINITION_END() \
return op; \
}
#define __MIE_DIALECT_TYPE_BEGIN(func_prefix, type_name) \
struct mie_dialect_type *func_prefix##_type_create( \
#define __MIE_TYPE_DEFINITION_BEGIN(func_prefix, type_name) \
struct mie_type_definition *func_prefix##_type_create( \
struct mie_dialect *d, struct mie_ctx *ctx) \
{ \
struct mie_dialect_type *type \
= mie_dialect_type_create(d, type_name); \
struct mie_type_definition *type \
= mie_type_definition_create(d, type_name); \
if (!type) { \
return NULL; \
}
#define __MIE_DIALECT_TYPE_END() \
#define __MIE_TYPE_DEFINITION_END() \
return type; \
}
#define __MIE_DIALECT_ADD_OP(op_id) \
extern struct mie_dialect_op *op_id##_op_create( \
extern struct mie_op_definition *op_id##_op_create( \
struct mie_dialect *, struct mie_ctx *); \
op = op_id##_op_create(self, ctx)
#define __MIE_DIALECT_ADD_TYPE(type_id) \
extern struct mie_dialect_type *type_id##_type_create( \
extern struct mie_type_definition *type_id##_type_create( \
struct mie_dialect *, struct mie_ctx *); \
type = type_id##_type_create(self, ctx)
#define MIE_DIALECT_BEGIN(c_sym, name) __MIE_DIALECT_BEGIN(c_sym, name)
#define MIE_DIALECT_END() __MIE_DIALECT_END()
#define MIE_DIALECT_ADD_OP(c_sym) __MIE_DIALECT_ADD_OP(c_sym)
#define MIE_DIALECT_ADD_TYPE(c_sym) __MIE_DIALECT_ADD_TYPE(c_sym)
#define MIE_DIALECT_BEGIN(c_sym, name) __MIE_DIALECT_BEGIN(c_sym, name)
#define MIE_DIALECT_END() __MIE_DIALECT_END()
#define MIE_DIALECT_ADD_OP(c_sym) __MIE_DIALECT_ADD_OP(c_sym)
#define MIE_DIALECT_ADD_TYPE(c_sym) __MIE_DIALECT_ADD_TYPE(c_sym)
#define MIE_DIALECT_OP_BEGIN(c_sym, op) __MIE_DIALECT_OP_BEGIN(c_sym, op)
#define MIE_DIALECT_OP_END() __MIE_DIALECT_OP_END()
#define MIE_DIALECT_OP_PRINT(func) op->op_print = (func)
#define MIE_DIALECT_OP_PARSE(func) op->op_parse = (func)
#define MIE_OP_DEFINITION_BEGIN(c_sym, op) __MIE_OP_DEFINITION_BEGIN(c_sym, op)
#define MIE_OP_DEFINITION_END() __MIE_OP_DEFINITION_END()
#define MIE_OP_DEFINITION_PRINT(func) op->op_print = (func)
#define MIE_OP_DEFINITION_PARSE(func) op->op_parse = (func)
#define MIE_DIALECT_TYPE_BEGIN(c_sym, type) \
__MIE_DIALECT_TYPE_BEGIN(c_sym, type)
#define MIE_DIALECT_TYPE_END() __MIE_DIALECT_TYPE_END()
#define MIE_DIALECT_TYPE_FLAGS(flags) type->ty_flags = flags
#define MIE_DIALECT_TYPE_STRUCT(name) type->ty_data_size = sizeof(name)
#define MIE_DIALECT_TYPE_INIT(func) type->ty_init = (func)
#define MIE_DIALECT_TYPE_PRINT(func) type->ty_print = (func)
#define MIE_DIALECT_TYPE_VALUE_PRINT(func) type->ty_value_print = (func)
#define MIE_DIALECT_TYPE_PARSE(func) type->ty_parse = (func)
#define MIE_DIALECT_TYPE_BUILD_ID(func) type->ty_build_id = (func)
#define MIE_DIALECT_TYPE_INIT(func) type->ty_init = (func)
#define MIE_DIALECT_TYPE_CLEANUP(func) type->ty_cleanup = (func)
#define MIE_TYPE_DEFINITION_BEGIN(c_sym, type) \
__MIE_TYPE_DEFINITION_BEGIN(c_sym, type)
#define MIE_TYPE_DEFINITION_END() __MIE_TYPE_DEFINITION_END()
#define MIE_TYPE_DEFINITION_FLAGS(flags) type->ty_flags = flags
#define MIE_TYPE_DEFINITION_STRUCT(name) type->ty_data_size = sizeof(name)
#define MIE_TYPE_DEFINITION_INIT(func) type->ty_init = (func)
#define MIE_TYPE_DEFINITION_PRINT(func) type->ty_print = (func)
#define MIE_TYPE_DEFINITION_VALUE_PRINT(func) type->ty_value_print = (func)
#define MIE_TYPE_DEFINITION_PARSE(func) type->ty_parse = (func)
#define MIE_TYPE_DEFINITION_BUILD_ID(func) type->ty_build_id = (func)
#define MIE_TYPE_DEFINITION_INIT(func) type->ty_init = (func)
#define MIE_TYPE_DEFINITION_CLEANUP(func) type->ty_cleanup = (func)
#define MIE_DIALECT_TRAIT_BEGIN(c_sym, trait)
#define MIE_DIALECT_TRAIT_END()

View File

@@ -0,0 +1,36 @@
#ifndef MIE_TYPE_TYPE_DEFINITION_H_
#define MIE_TYPE_TYPE_DEFINITION_H_
#include <mie/trait/trait-table.h>
struct mie_value;
struct mie_type;
struct mie_parser;
/* a static struct that defines the properties, traits, and callbacks for a type. */
struct mie_type_definition {
mie_id ty_id;
struct mie_trait_table ty_traits;
struct mie_dialect *ty_parent;
char *ty_name;
size_t ty_data_size;
void (*ty_init)(const struct mie_type_definition *, struct mie_type *);
void (*ty_cleanup)(const struct mie_type_definition *, struct mie_type *);
void (*ty_instance_cleanup)(const struct mie_type *, struct mie_value *);
enum mie_status (*ty_print)(
const struct mie_type_definition *, const struct mie_type *,
b_stream *);
enum mie_status (*ty_value_print)(
const struct mie_type *, const struct mie_value *, b_stream *);
enum mie_status (*ty_parse)(
const struct mie_type_definition *, struct mie_parser *,
struct mie_type **);
void (*ty_build_id)(const struct mie_type *, struct mie_id_builder *);
};
MIE_API struct mie_type_definition *mie_type_definition_create(
struct mie_dialect *parent, const char *name);
#endif

View File

@@ -8,37 +8,40 @@
#include <stddef.h>
struct mie_dialect;
struct mie_dialect_type;
struct mie_type_definition;
struct mie_value;
struct mie_id_builder;
enum mie_type_category {
/* all other types */
MIE_TYPE_OTHER = 0,
/* storage types (structs, etc) */
MIE_TYPE_STORAGE,
/* functional types (represents the param/result types of a function) */
MIE_TYPE_FUNCTION,
};
#if 0
enum mie_type_trait {
/* this type is parametised. one or more arguments are required to create
* a corresponding mie_type instance. in textual IR, references to this
* type will be followed by a set of arguments surrounded
* by <angle brackets>. */
MIE_TYPE_TRAIT_PARAMETISED = 0x01u,
/* a mie_type is an instance of mie_dialect_type.
* if the mie_dialect_type is a parametised type, the resulting mie_type
/* this type can only be used within graph regions. unlike graph ops,
* no special prefix is required */
MIE_TYPE_TRAIT_GRAPH_TYPE = 0x02u,
};
#endif
/* a mie_type is a type-instance created from a mie_type_definition.
* if the mie_type_definition is a parametised type, the resulting mie_type
* will have those parameters baked in.
* this is a base struct. dialects that defined their own types do so by
* inheriting from this struct. */
struct mie_type {
/* this is NOT the same as ty_def->ty_id */
mie_id ty_id;
enum mie_type_category ty_category;
char *ty_name;
struct mie_dialect_type *ty_def;
struct mie_type_definition *ty_def;
size_t ty_instance_size;
};
MIE_API struct mie_type *mie_type_create(struct mie_dialect_type *type);
MIE_API struct mie_type *mie_type_create(struct mie_type_definition *type);
MIE_API void mie_type_print(const struct mie_type *type, b_stream *out);
MIE_API void mie_type_build_id(
const struct mie_type *type, struct mie_id_builder *ctx);

View File

@@ -1,11 +1,11 @@
#include <blue/ds/string.h>
#include <mie/dialect/dialect.h>
#include <mie/dialect/op.h>
#include <mie/ir/op-definition.h>
struct mie_dialect_op *mie_dialect_op_create(
struct mie_op_definition *mie_op_definition_create(
struct mie_dialect *parent, const char *name)
{
struct mie_dialect_op *out = malloc(sizeof *out);
struct mie_op_definition *out = malloc(sizeof *out);
if (!out) {
return NULL;
}

View File

@@ -1,7 +1,6 @@
#include <mie/ctx.h>
#include <mie/dialect/arith.h>
#include <mie/dialect/dialect.h>
#include <mie/dialect/type.h>
#include <mie/ir/module.h>
#include <mie/ir/op.h>
#include <mie/ir/region.h>
@@ -10,6 +9,7 @@
#include <mie/parse/parse.h>
#include <mie/parse/token.h>
#include <mie/type/function.h>
#include <mie/type/type-definition.h>
struct mie_parser {
struct mie_ctx *p_ctx;
@@ -133,7 +133,7 @@ static bool parse_builtin_type_name(
return false;
}
const struct mie_dialect_type *type_info = NULL;
const struct mie_type_definition *type_info = NULL;
const struct mie_type *type = NULL;
size_t width = 0;
char tmp = 0;
@@ -147,20 +147,21 @@ static bool parse_builtin_type_name(
const char *name_cstr = b_string_ptr(name);
if (!strcmp(name_cstr, "memref")) {
type_info = mie_ctx_get_dialect_type(
type_info = mie_ctx_get_type_definition(
ctx->p_ctx, "memref", "memref");
} else if (!strcmp(name_cstr, "index")) {
type_info
= mie_ctx_get_dialect_type(ctx->p_ctx, "index", "index");
type_info = mie_ctx_get_type_definition(
ctx->p_ctx, "index", "index");
} else if (!strcmp(name_cstr, "str")) {
type_info = mie_ctx_get_dialect_type(
type_info = mie_ctx_get_type_definition(
ctx->p_ctx, "builtin", "string");
} else if (sscanf(name_cstr, "i%zu%c", &width, &tmp) == 1) {
type_info = mie_ctx_get_dialect_type(ctx->p_ctx, "arith", "int");
type_info = mie_ctx_get_type_definition(
ctx->p_ctx, "arith", "int");
base_type = INT;
} else if (sscanf(name_cstr, "f%zu%c", &width, &tmp) == 1) {
type_info
= mie_ctx_get_dialect_type(ctx->p_ctx, "arith", "float");
type_info = mie_ctx_get_type_definition(
ctx->p_ctx, "arith", "float");
base_type = FLOAT;
}

View File

@@ -1,5 +1,5 @@
#include <mie/dialect/type.h>
#include <mie/type/function.h>
#include <mie/type/type-definition.h>
#include <stdlib.h>
#include <string.h>
@@ -12,9 +12,19 @@ static void build_id(const struct mie_type *type, struct mie_id_builder *ctx)
function->func_out.items, function->func_out.count);
}
static struct mie_dialect_type function_type = {
static enum mie_status type_print(
const struct mie_type_definition *type_info,
const struct mie_type *type, b_stream *out)
{
mie_function_type_print((const struct mie_function_type *)type, out);
return MIE_SUCCESS;
}
static struct mie_type_definition function_type = {
.ty_name = "*function",
.ty_data_size = sizeof(struct mie_type),
.ty_build_id = build_id,
.ty_print = type_print,
};
struct mie_function_type *mie_function_type_create(void)
@@ -27,7 +37,6 @@ struct mie_function_type *mie_function_type_create(void)
memset(out, 0x0, sizeof *out);
out->func_base.ty_def = &function_type;
out->func_base.ty_category = MIE_TYPE_FUNCTION;
return out;
}

View File

@@ -1,5 +1,5 @@
#include <mie/dialect/type.h>
#include <mie/type/storage.h>
#include <mie/type/type-definition.h>
#include <stdlib.h>
#include <string.h>
@@ -11,9 +11,19 @@ static void build_id(const struct mie_type *type, struct mie_id_builder *ctx)
ctx, storage->st_parts.items, storage->st_parts.count);
}
static struct mie_dialect_type storage_type = {
static enum mie_status type_print(
const struct mie_type_definition *type_info,
const struct mie_type *type, b_stream *out)
{
mie_storage_type_print((const struct mie_storage_type *)type, out);
return MIE_SUCCESS;
}
static struct mie_type_definition storage_type = {
.ty_name = "*storage",
.ty_data_size = sizeof(struct mie_type),
.ty_build_id = build_id,
.ty_print = type_print,
};
struct mie_storage_type *mie_storage_type_create(void)
@@ -26,7 +36,6 @@ struct mie_storage_type *mie_storage_type_create(void)
memset(out, 0x0, sizeof *out);
out->st_base.ty_def = &storage_type;
out->st_base.ty_category = MIE_TYPE_STORAGE;
return out;
}

View File

@@ -1,11 +1,11 @@
#include <blue/ds/string.h>
#include <mie/dialect/dialect.h>
#include <mie/dialect/type.h>
#include <mie/type/type-definition.h>
struct mie_dialect_type *mie_dialect_type_create(
struct mie_type_definition *mie_type_definition_create(
struct mie_dialect *parent, const char *name)
{
struct mie_dialect_type *out = malloc(sizeof *out);
struct mie_type_definition *out = malloc(sizeof *out);
if (!out) {
return NULL;
}

View File

@@ -1,9 +1,9 @@
#include <mie/dialect/type.h>
#include <mie/type/function.h>
#include <mie/type/storage.h>
#include <mie/type/type-definition.h>
#include <mie/type/type.h>
struct mie_type *mie_type_create(struct mie_dialect_type *type)
struct mie_type *mie_type_create(struct mie_type_definition *type)
{
if (type->ty_data_size < sizeof(struct mie_type)) {
return NULL;
@@ -22,17 +22,6 @@ struct mie_type *mie_type_create(struct mie_dialect_type *type)
void mie_type_print(const struct mie_type *type, b_stream *out)
{
switch (type->ty_category) {
case MIE_TYPE_STORAGE:
mie_storage_type_print((const struct mie_storage_type *)type, out);
return;
case MIE_TYPE_FUNCTION:
mie_function_type_print((const struct mie_function_type *)type, out);
return;
default:
break;
}
if (type->ty_name) {
b_stream_write_string(out, type->ty_name, NULL);
} else if (type->ty_def && type->ty_def->ty_print) {

View File

@@ -1,4 +1,4 @@
#include <mie/dialect/type.h>
#include <mie/type/type-definition.h>
#include <mie/type/type.h>
#include <mie/value.h>