diff --git a/mie/dialect/builtin/builtin.c b/mie/dialect/builtin/builtin.c index 45add57..afba27c 100644 --- a/mie/dialect/builtin/builtin.c +++ b/mie/dialect/builtin/builtin.c @@ -84,6 +84,7 @@ struct mie_attribute *mie_ctx_get_index(struct mie_ctx *ctx, size_t val) MIE_DIALECT_BEGIN(mie_builtin, struct builtin_dialect, "builtin") MIE_DIALECT_INIT(init); MIE_DIALECT_CLEANUP(cleanup); + MIE_DIALECT_ADD_OP(mie_builtin_module); MIE_DIALECT_ADD_TYPE(mie_builtin_string); MIE_DIALECT_ADD_TYPE(mie_builtin_int); MIE_DIALECT_ADD_TYPE(mie_builtin_float); diff --git a/mie/dialect/builtin/op/module.c b/mie/dialect/builtin/op/module.c new file mode 100644 index 0000000..db9b4ab --- /dev/null +++ b/mie/dialect/builtin/op/module.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include +#include + +static enum mie_status print(struct mie_printer *printer, const struct mie_op *op) +{ + return MIE_SUCCESS; +} + +static enum mie_status parse(struct mie_parser *parser, struct mie_op *out) +{ + return MIE_SUCCESS; +} + +MIE_OP_DEFINITION_BEGIN(mie_builtin_module, "module") + MIE_OP_DEFINITION_PRINT(print); + MIE_OP_DEFINITION_PARSE(parse); +MIE_OP_DEFINITION_END() diff --git a/mie/include/mie/ir/module.h b/mie/include/mie/ir/module.h deleted file mode 100644 index 3dbeaa1..0000000 --- a/mie/include/mie/ir/module.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef MIE_IR_MODULE_H_ -#define MIE_IR_MODULE_H_ - -#include -#include -#include -#include -#include - -struct mie_op; - -struct mie_module { - struct mie_name_map *m_names; - MIE_VECTOR_DECLARE(struct mie_op, m_ops); -}; - -MIE_API struct mie_module *mie_module_create(void); -MIE_API void mie_module_destroy(struct mie_module *mod); - -MIE_API struct mie_op *mie_module_add_op(struct mie_module *mod); - -#endif diff --git a/mie/include/mie/ir/op.h b/mie/include/mie/ir/op.h index 103e4ac..783b3f3 100644 --- a/mie/include/mie/ir/op.h +++ b/mie/include/mie/ir/op.h @@ -66,9 +66,10 @@ struct mie_op { MIE_VECTOR_DECLARE(struct mie_register *, op_result); }; +MIE_API struct mie_op *mie_op_create(void); MIE_API void mie_op_destroy(struct mie_op *op); -MIE_API struct mie_region *mie_op_add_region(struct mie_op *op); -MIE_API struct mie_op_successor *mie_op_add_successor(struct mie_op *op); +MIE_API void mie_op_init(struct mie_op *op); +MIE_API void mie_op_cleanup(struct mie_op *op); #endif diff --git a/mie/ir/module.c b/mie/ir/module.c deleted file mode 100644 index 6609ba2..0000000 --- a/mie/ir/module.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include -#include - -struct mie_module *mie_module_create(void) -{ - struct mie_module *out = malloc(sizeof *out); - if (!out) { - return NULL; - } - - memset(out, 0x0, sizeof *out); - - out->m_names = mie_name_map_create(NULL); - - return out; -} - -void mie_module_destroy(struct mie_module *mod) -{ - /* TODO */ -} - -struct mie_op *mie_module_add_op(struct mie_module *mod) -{ - return mie_vector_emplace_back(mod->m_ops); -} diff --git a/mie/ir/op.c b/mie/ir/op.c new file mode 100644 index 0000000..b008957 --- /dev/null +++ b/mie/ir/op.c @@ -0,0 +1,32 @@ +#include +#include + +struct mie_op *mie_op_create(void) +{ + struct mie_op *out = malloc(sizeof *out); + if (!out) { + return NULL; + } + + mie_op_init(out); + + return out; +} + +void mie_op_destroy(struct mie_op *op) +{ + mie_op_cleanup(op); + free(op); +} + +void mie_op_init(struct mie_op *op) +{ + memset(op, 0x0, sizeof *op); + + mie_attribute_map_init(&op->op_attrib); +} + +void mie_op_cleanup(struct mie_op *op) +{ + /* TODO */ +} diff --git a/mie/parse/parser.c b/mie/parse/parser.c index e2219f9..3781877 100644 --- a/mie/parse/parser.c +++ b/mie/parse/parser.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -677,6 +676,10 @@ bool mie_parser_parse_register( { memset(out, 0x0, sizeof *out); + if (!names) { + return false; + } + struct mie_token *tok = mie_parser_peek(ctx); enum mie_token_type type = MIE_TOKEN_TYPE(tok); switch (type) { @@ -765,41 +768,6 @@ bool mie_parser_parse_register_list( return true; } -bool mie_parser_parse_module(struct mie_parser *ctx, struct mie_module *mod) -{ -#define OP_TOKEN_TYPES \ - (MIE_TOK_NAME | MIE_TOK_OPNAME | MIE_TOK_VREGNAME | MIE_TOK_MREGNAME \ - | MIE_TOK_GRAPHNAME | MIE_TOK_INSTNAME) - - for (size_t i = 0;; i++) { - if (mie_parser_check_eof(ctx)) { - break; - } - - if (i > 0 && !mie_parser_parse_linefeed(ctx)) { - return false; - } - - enum mie_token_type type = mie_parser_peek_type(ctx); - bool is_op = (type & OP_TOKEN_TYPES); - - if (!is_op) { - break; - } - - struct mie_op *op = mie_module_add_op(mod); - if (!op) { - return false; - } - - if (!mie_parser_parse_op(ctx, mod->m_names, op)) { - return false; - } - } - - return true; -} - bool mie_parser_parse_region(struct mie_parser *ctx, struct mie_region *region) { region->r_names = mie_name_map_create(NULL); @@ -875,6 +843,8 @@ bool mie_parser_parse_anonymous_block( mie_parser_parse_linefeed(ctx); struct mie_op *op = mie_vector_emplace_back(block->b_ops); + mie_op_init(op); + if (!mie_parser_parse_op(ctx, names, op)) { return false; } @@ -891,6 +861,8 @@ bool mie_parser_parse_anonymous_block( } struct mie_op *op = mie_vector_emplace_back(block->b_ops); + mie_op_init(op); + if (!mie_parser_parse_op(ctx, names, op)) { return false; } @@ -906,6 +878,10 @@ bool mie_parser_parse_anonymous_block( static bool parse_block_parameters( struct mie_parser *ctx, struct mie_name_map *names, struct mie_block *block) { + if (!names) { + return false; + } + if (!mie_parser_parse_symbol(ctx, MIE_SYM_LEFT_PAREN)) { return false; } @@ -943,6 +919,10 @@ static bool parse_block_parameters( bool mie_parser_parse_block( struct mie_parser *ctx, struct mie_name_map *names, struct mie_block *block) { + if (!names) { + return NULL; + } + b_string *str = get_temp_string(ctx); struct mie_file_span span; @@ -976,6 +956,7 @@ bool mie_parser_parse_block( } struct mie_op *op = mie_vector_emplace_back(block->b_ops); + mie_op_init(op); if (!mie_parser_parse_op(ctx, names, op)) { return false; } diff --git a/mie/print/module.c b/mie/print/module.c deleted file mode 100644 index e37056a..0000000 --- a/mie/print/module.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include - -void mie_printer_print_module( - struct mie_printer *printer, const struct mie_module *mod) -{ - for (size_t i = 0; i < MIE_VECTOR_COUNT(mod->m_ops); i++) { - mie_printer_print_op(printer, &mod->m_ops.items[i]); - b_stream_write_char(printer->p_stream, '\n'); - } -}