diff --git a/mie/ctx.c b/mie/ctx.c index abd744a..8741347 100644 --- a/mie/ctx.c +++ b/mie/ctx.c @@ -7,10 +7,10 @@ #include #include #include -#include #include #include #include +#include #include #include #include @@ -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; diff --git a/mie/dialect/arith/addf.c b/mie/dialect/arith/addf.c index a77c2e1..90dfb2c 100644 --- a/mie/dialect/arith/addf.c +++ b/mie/dialect/arith/addf.c @@ -1,5 +1,5 @@ #include -#include +#include #include 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() diff --git a/mie/dialect/arith/addi.c b/mie/dialect/arith/addi.c index f4fae8f..43b6217 100644 --- a/mie/dialect/arith/addi.c +++ b/mie/dialect/arith/addi.c @@ -1,5 +1,5 @@ #include -#include +#include #include 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() diff --git a/mie/dialect/arith/float.c b/mie/dialect/arith/float.c index c2420fa..61098c2 100644 --- a/mie/dialect/arith/float.c +++ b/mie/dialect/arith/float.c @@ -2,8 +2,8 @@ #include #include #include -#include #include +#include #include #include @@ -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() diff --git a/mie/dialect/arith/int.c b/mie/dialect/arith/int.c index 88ef0d1..95e8ab0 100644 --- a/mie/dialect/arith/int.c +++ b/mie/dialect/arith/int.c @@ -2,8 +2,8 @@ #include #include #include -#include #include +#include #include #include @@ -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() diff --git a/mie/dialect/builtin/string.c b/mie/dialect/builtin/string.c index 2f39892..72e1c22 100644 --- a/mie/dialect/builtin/string.c +++ b/mie/dialect/builtin/string.c @@ -2,40 +2,43 @@ #include #include #include -#include #include +#include #include #include -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() diff --git a/mie/dialect/cf/br-cond.c b/mie/dialect/cf/br-cond.c index e8f97f8..e0473ab 100644 --- a/mie/dialect/cf/br-cond.c +++ b/mie/dialect/cf/br-cond.c @@ -1,5 +1,5 @@ #include -#include +#include #include 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() diff --git a/mie/dialect/cf/br.c b/mie/dialect/cf/br.c index 58275a6..e895fac 100644 --- a/mie/dialect/cf/br.c +++ b/mie/dialect/cf/br.c @@ -1,5 +1,5 @@ #include -#include +#include #include 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() diff --git a/mie/dialect/dialect.c b/mie/dialect/dialect.c index 121b3a9..b605245 100644 --- a/mie/dialect/dialect.c +++ b/mie/dialect/dialect.c @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include #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); } diff --git a/mie/dialect/func/func.c b/mie/dialect/func/func.c index 662e42b..f3134d8 100644 --- a/mie/dialect/func/func.c +++ b/mie/dialect/func/func.c @@ -1,5 +1,5 @@ #include -#include +#include #include 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); diff --git a/mie/dialect/index/index.c b/mie/dialect/index/index.c index 2935dd0..8607de8 100644 --- a/mie/dialect/index/index.c +++ b/mie/dialect/index/index.c @@ -1,7 +1,7 @@ #include #include -#include #include +#include #include #include @@ -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); diff --git a/mie/dialect/meta/source-filename.c b/mie/dialect/meta/source-filename.c index 8729ee5..bf12fc6 100644 --- a/mie/dialect/meta/source-filename.c +++ b/mie/dialect/meta/source-filename.c @@ -1,5 +1,5 @@ #include -#include +#include #include 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() diff --git a/mie/dialect/ptr/load.c b/mie/dialect/ptr/load.c index c2fd71f..ef66336 100644 --- a/mie/dialect/ptr/load.c +++ b/mie/dialect/ptr/load.c @@ -1,5 +1,5 @@ #include -#include +#include #include 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() diff --git a/mie/dialect/ptr/ptr.c b/mie/dialect/ptr/ptr.c index 3dad98e..f52289d 100644 --- a/mie/dialect/ptr/ptr.c +++ b/mie/dialect/ptr/ptr.c @@ -1,29 +1,30 @@ #include -#include #include +#include 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); diff --git a/mie/dialect/ptr/store.c b/mie/dialect/ptr/store.c index 2e8a77a..88add82 100644 --- a/mie/dialect/ptr/store.c +++ b/mie/dialect/ptr/store.c @@ -1,5 +1,5 @@ #include -#include +#include #include 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() diff --git a/mie/dialect/scf/for.c b/mie/dialect/scf/for.c index d808c70..aa9f2a0 100644 --- a/mie/dialect/scf/for.c +++ b/mie/dialect/scf/for.c @@ -1,5 +1,5 @@ #include -#include +#include #include 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() diff --git a/mie/dialect/scf/if.c b/mie/dialect/scf/if.c index 36a1947..19d0356 100644 --- a/mie/dialect/scf/if.c +++ b/mie/dialect/scf/if.c @@ -1,5 +1,5 @@ #include -#include +#include #include 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() diff --git a/mie/dialect/scf/scf.c b/mie/dialect/scf/scf.c index c3bbf8f..0bc2562 100644 --- a/mie/dialect/scf/scf.c +++ b/mie/dialect/scf/scf.c @@ -1,5 +1,3 @@ -#include "scf.h" - #include #include diff --git a/mie/dialect/scf/scf.h b/mie/dialect/scf/scf.h deleted file mode 100644 index 3b8267f..0000000 --- a/mie/dialect/scf/scf.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef MIE_DIALECT_SCF_H_ -#define MIE_DIALECT_SCF_H_ - -#include -#include - -#endif diff --git a/mie/dialect/scf/yield.c b/mie/dialect/scf/yield.c index 7371ac6..ffb64b4 100644 --- a/mie/dialect/scf/yield.c +++ b/mie/dialect/scf/yield.c @@ -1,5 +1,5 @@ #include -#include +#include #include 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() diff --git a/mie/include/mie/ctx.h b/mie/include/mie/ctx.h index ea5edea..be126b7 100644 --- a/mie/include/mie/ctx.h +++ b/mie/include/mie/ctx.h @@ -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); diff --git a/mie/include/mie/dialect/dialect.h b/mie/include/mie/dialect/dialect.h index 443f192..e2c1387 100644 --- a/mie/include/mie/dialect/dialect.h +++ b/mie/include/mie/dialect/dialect.h @@ -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); diff --git a/mie/include/mie/dialect/type.h b/mie/include/mie/dialect/type.h deleted file mode 100644 index 8a4f038..0000000 --- a/mie/include/mie/dialect/type.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef MIE_DIALECT_TYPE_H_ -#define MIE_DIALECT_TYPE_H_ - -#include -#include -#include -#include -#include - -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 . */ - 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 diff --git a/mie/include/mie/dialect/op.h b/mie/include/mie/ir/op-definition.h similarity index 94% rename from mie/include/mie/dialect/op.h rename to mie/include/mie/ir/op-definition.h index 034385f..35eca8e 100644 --- a/mie/include/mie/dialect/op.h +++ b/mie/include/mie/ir/op-definition.h @@ -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 #include @@ -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 diff --git a/mie/include/mie/ir/op.h b/mie/include/mie/ir/op.h index b8e3586..e3b3eb3 100644 --- a/mie/include/mie/ir/op.h +++ b/mie/include/mie/ir/op.h @@ -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 */ diff --git a/mie/include/mie/macros.h b/mie/include/mie/macros.h index b52ad7d..4c182d3 100644 --- a/mie/include/mie/macros.h +++ b/mie/include/mie/macros.h @@ -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() diff --git a/mie/include/mie/type/type-definition.h b/mie/include/mie/type/type-definition.h new file mode 100644 index 0000000..a0a1362 --- /dev/null +++ b/mie/include/mie/type/type-definition.h @@ -0,0 +1,36 @@ +#ifndef MIE_TYPE_TYPE_DEFINITION_H_ +#define MIE_TYPE_TYPE_DEFINITION_H_ + +#include + +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 diff --git a/mie/include/mie/type/type.h b/mie/include/mie/type/type.h index 32d8735..7a33fca 100644 --- a/mie/include/mie/type/type.h +++ b/mie/include/mie/type/type.h @@ -8,37 +8,40 @@ #include 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 . */ + 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); diff --git a/mie/dialect/op.c b/mie/ir/op-definition.c similarity index 72% rename from mie/dialect/op.c rename to mie/ir/op-definition.c index e670841..0175d1c 100644 --- a/mie/dialect/op.c +++ b/mie/ir/op-definition.c @@ -1,11 +1,11 @@ #include #include -#include +#include -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; } diff --git a/mie/parse/parse.c b/mie/parse/parse.c index 79cc68d..41458fb 100644 --- a/mie/parse/parse.c +++ b/mie/parse/parse.c @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -10,6 +9,7 @@ #include #include #include +#include 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; } diff --git a/mie/type/function.c b/mie/type/function.c index 1689c8f..89f8cb0 100644 --- a/mie/type/function.c +++ b/mie/type/function.c @@ -1,5 +1,5 @@ -#include #include +#include #include #include @@ -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; } diff --git a/mie/type/storage.c b/mie/type/storage.c index 759e99f..5630b81 100644 --- a/mie/type/storage.c +++ b/mie/type/storage.c @@ -1,5 +1,5 @@ -#include #include +#include #include #include @@ -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; } diff --git a/mie/dialect/type.c b/mie/type/type-definition.c similarity index 71% rename from mie/dialect/type.c rename to mie/type/type-definition.c index e4c8a9e..a163d6f 100644 --- a/mie/dialect/type.c +++ b/mie/type/type-definition.c @@ -1,11 +1,11 @@ #include #include -#include +#include -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; } diff --git a/mie/type/type.c b/mie/type/type.c index cef231d..e617230 100644 --- a/mie/type/type.c +++ b/mie/type/type.c @@ -1,9 +1,9 @@ -#include #include #include +#include #include -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) { diff --git a/mie/value.c b/mie/value.c index ed1fbcb..4fc96eb 100644 --- a/mie/value.c +++ b/mie/value.c @@ -1,4 +1,4 @@ -#include +#include #include #include