mie: ir: replace mie_module ir object with a builtin generic "module" op
the builtin.module op behaves exactly like any other op, and is designed to be a container for other ops of any type. it can be used as the top-level container for other ops (other top-level containers can be used instead). this also changes the file format. now, an ir file can only contain a single top-level op. any other ops in the ir must be contained directly or indirectly by this top-level op.
This commit is contained in:
@@ -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);
|
||||
|
||||
20
mie/dialect/builtin/op/module.c
Normal file
20
mie/dialect/builtin/op/module.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/ir/op-definition.h>
|
||||
#include <mie/ir/op.h>
|
||||
#include <mie/macros.h>
|
||||
#include <mie/print/printer.h>
|
||||
|
||||
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()
|
||||
@@ -1,22 +0,0 @@
|
||||
#ifndef MIE_IR_MODULE_H_
|
||||
#define MIE_IR_MODULE_H_
|
||||
|
||||
#include <blue/core/stream.h>
|
||||
#include <mie/misc.h>
|
||||
#include <mie/name.h>
|
||||
#include <mie/vector.h>
|
||||
#include <stddef.h>
|
||||
|
||||
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
|
||||
@@ -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
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
#include <mie/ir/module.h>
|
||||
#include <mie/ir/op.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
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);
|
||||
}
|
||||
32
mie/ir/op.c
Normal file
32
mie/ir/op.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <mie/ir/op.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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 */
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/index.h>
|
||||
#include <mie/ir/block.h>
|
||||
#include <mie/ir/module.h>
|
||||
#include <mie/ir/op.h>
|
||||
#include <mie/ir/region.h>
|
||||
#include <mie/ir/register.h>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#include <mie/ir/module.h>
|
||||
#include <mie/ir/op.h>
|
||||
#include <mie/print/printer.h>
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user