mie: implement support for custom op print formats
This commit is contained in:
@@ -25,3 +25,15 @@ struct mie_attribute_definition *mie_attribute_definition_create(
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
bool mie_attribute_definition_check_name(
|
||||
const struct mie_attribute_definition *def, const char *dialect_name,
|
||||
const char *attrib_name)
|
||||
{
|
||||
if (!def || !def->a_parent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (!strcmp(def->a_name, attrib_name)
|
||||
&& !strcmp(def->a_parent->d_name, dialect_name));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <mie/attribute/attribute-definition.h>
|
||||
#include <mie/attribute/attribute.h>
|
||||
|
||||
bool mie_attribute_check_name(
|
||||
const struct mie_attribute *attrib, const char *dialect_name,
|
||||
const char *attrib_name)
|
||||
{
|
||||
if (!attrib || !attrib->a_def) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return mie_attribute_definition_check_name(
|
||||
attrib->a_def, dialect_name, attrib_name);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
#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(const struct mie_op *op, b_stream *out)
|
||||
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
|
||||
{
|
||||
const struct mie_attribute *sym_name
|
||||
= mie_attribute_map_get(&op->op_attrib, "sym_name");
|
||||
b_stream_write_fmt(printer->p_stream, NULL, " @%s", NULL);
|
||||
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <mie/ir/op-definition.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
#include <mie/attribute/attribute-definition.h>
|
||||
#include <mie/attribute/attribute.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/dialect/builtin.h>
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/macros.h>
|
||||
#include <mie/parse/parser.h>
|
||||
#include <mie/print/printer.h>
|
||||
|
||||
static enum mie_status print(
|
||||
const struct mie_attribute *value, struct mie_printer *out)
|
||||
{
|
||||
const struct mie_array *array = (const struct mie_array *)value;
|
||||
|
||||
if (!(out->p_flags & MIE_PRINT_F_ABBREVIATED)) {
|
||||
b_stream_write_string(out->p_stream, "#builtin.array<", NULL);
|
||||
}
|
||||
|
||||
b_stream_write_char(out->p_stream, '[');
|
||||
|
||||
for (size_t i = 0; i < MIE_VECTOR_COUNT(array->a_items); i++) {
|
||||
if (i > 0) {
|
||||
b_stream_write_char(out->p_stream, ',');
|
||||
}
|
||||
|
||||
b_stream_write_char(out->p_stream, ' ');
|
||||
mie_printer_print_attribute(out, array->a_items.items[i]);
|
||||
}
|
||||
|
||||
if (MIE_VECTOR_COUNT(array->a_items) != 0) {
|
||||
b_stream_write_char(out->p_stream, ' ');
|
||||
}
|
||||
b_stream_write_char(out->p_stream, ']');
|
||||
|
||||
if (!(out->p_flags & MIE_PRINT_F_ABBREVIATED)) {
|
||||
b_stream_write_char(out->p_stream, '>');
|
||||
}
|
||||
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static struct mie_array *array_create(struct mie_ctx *ctx)
|
||||
{
|
||||
struct mie_array *array = malloc(sizeof *array);
|
||||
if (!array) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(array, 0x0, sizeof *array);
|
||||
|
||||
array->a_base.a_def
|
||||
= mie_ctx_get_attribute_definition(ctx, "builtin", "array");
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
static enum mie_status parse(
|
||||
struct mie_parser *ctx, const struct mie_attribute **out)
|
||||
{
|
||||
if (!mie_parser_parse_symbol(ctx, MIE_SYM_LEFT_BRACKET)) {
|
||||
return MIE_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
struct mie_array *array = array_create(mie_parser_get_mie_ctx(ctx));
|
||||
if (!array) {
|
||||
return MIE_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
const struct mie_attribute *item = NULL;
|
||||
|
||||
if (!mie_parser_parse_attribute(ctx, &item)) {
|
||||
free(array);
|
||||
return MIE_ERR_BAD_FORMAT;
|
||||
}
|
||||
|
||||
mie_vector_push_back(array->a_items, &item);
|
||||
|
||||
while (1) {
|
||||
if (mie_parser_parse_symbol(ctx, MIE_SYM_RIGHT_BRACKET)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!mie_parser_parse_symbol(ctx, MIE_SYM_COMMA)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mie_parser_parse_attribute(ctx, &item)) {
|
||||
free(array);
|
||||
return MIE_ERR_BAD_FORMAT;
|
||||
}
|
||||
|
||||
mie_vector_push_back(array->a_items, &item);
|
||||
}
|
||||
|
||||
*out = (struct mie_attribute *)array;
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_builtin_array, "array")
|
||||
MIE_ATTRIBUTE_DEFINITION_STRUCT(struct mie_array);
|
||||
MIE_ATTRIBUTE_DEFINITION_PRINT(print);
|
||||
MIE_ATTRIBUTE_DEFINITION_PARSE(parse);
|
||||
MIE_ATTRIBUTE_DEFINITION_END()
|
||||
|
||||
@@ -51,31 +51,31 @@ static enum mie_status parse(
|
||||
struct mie_file_span span;
|
||||
|
||||
if (!mie_parser_parse_float(ctx, &value, &span)) {
|
||||
return false;
|
||||
return MIE_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
if (!mie_parser_parse_symbol(ctx, MIE_SYM_COLON)) {
|
||||
return false;
|
||||
return MIE_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
const struct mie_type *type = NULL;
|
||||
if (!mie_parser_parse_type(ctx, &type)) {
|
||||
return false;
|
||||
return MIE_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
size_t width = mie_float_type_get_width(type);
|
||||
if (width == (size_t)-1) {
|
||||
return false;
|
||||
return MIE_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
struct mie_attribute *v
|
||||
= mie_ctx_get_float(mie_parser_get_mie_ctx(ctx), value, width);
|
||||
if (!v) {
|
||||
return false;
|
||||
return MIE_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
*out = v;
|
||||
return true;
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_builtin_float, "float")
|
||||
|
||||
@@ -15,20 +15,25 @@ static enum mie_status print(
|
||||
{
|
||||
const struct mie_int *int_val = (const struct mie_int *)value;
|
||||
const struct int_type *int_ty = (const struct int_type *)int_val->i_type;
|
||||
if (!(out->p_flags & MIE_PRINT_F_ABBREVIATED)) {
|
||||
bool abbrev = ((out->p_flags & MIE_PRINT_F_ABBREVIATED) != 0);
|
||||
|
||||
if (!abbrev) {
|
||||
b_stream_write_string(out->p_stream, "#builtin.int<", NULL);
|
||||
}
|
||||
|
||||
if (int_ty->i_width <= 64) {
|
||||
if (int_ty->i_width < 64 || !abbrev) {
|
||||
b_stream_write_fmt(
|
||||
out->p_stream, NULL, "%zu : i%zu",
|
||||
int_val->i_val.v_small, int_ty->i_width);
|
||||
} else if (int_ty->i_width == 64 && abbrev) {
|
||||
b_stream_write_fmt(
|
||||
out->p_stream, NULL, "%zu", int_val->i_val.v_small);
|
||||
} else {
|
||||
b_stream_write_fmt(
|
||||
out->p_stream, NULL, "INF : i%zu", int_ty->i_width);
|
||||
}
|
||||
|
||||
if (!(out->p_flags & MIE_PRINT_F_ABBREVIATED)) {
|
||||
if (!abbrev) {
|
||||
b_stream_write_string(out->p_stream, ">", NULL);
|
||||
}
|
||||
|
||||
@@ -42,31 +47,32 @@ static enum mie_status parse(
|
||||
struct mie_file_span span;
|
||||
|
||||
if (!mie_parser_parse_int(ctx, &value, &span)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mie_parser_parse_symbol(ctx, MIE_SYM_COLON)) {
|
||||
return false;
|
||||
return MIE_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
const struct mie_type *type = NULL;
|
||||
if (!mie_parser_parse_type(ctx, &type)) {
|
||||
size_t width = (size_t)-1;
|
||||
|
||||
if (!mie_parser_parse_symbol(ctx, MIE_SYM_COLON)) {
|
||||
width = 64;
|
||||
} else if (!mie_parser_parse_type(ctx, &type)) {
|
||||
return false;
|
||||
} else {
|
||||
width = mie_int_type_get_width(type);
|
||||
}
|
||||
|
||||
size_t width = mie_int_type_get_width(type);
|
||||
if (width == (size_t)-1) {
|
||||
return false;
|
||||
return MIE_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
struct mie_attribute *v
|
||||
= mie_ctx_get_int(mie_parser_get_mie_ctx(ctx), value, width);
|
||||
if (!v) {
|
||||
return false;
|
||||
return MIE_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
*out = v;
|
||||
return true;
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_builtin_int, "int")
|
||||
|
||||
@@ -26,18 +26,28 @@ static enum mie_status parse(
|
||||
b_string *str = mie_parser_get_tempstr(ctx);
|
||||
struct mie_file_span span;
|
||||
if (!mie_parser_parse_string(ctx, str, &span)) {
|
||||
return false;
|
||||
return MIE_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
struct mie_attribute *v = mie_ctx_get_string(
|
||||
mie_parser_get_mie_ctx(ctx), b_string_ptr(str));
|
||||
|
||||
if (!v) {
|
||||
return false;
|
||||
return MIE_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
*out = v;
|
||||
return true;
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
const char *mie_string_get_cstr(const struct mie_attribute *attrib)
|
||||
{
|
||||
if (!mie_attribute_check_name(attrib, "builtin", "string")) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const struct mie_string *str = (const struct mie_string *)attrib;
|
||||
return str->str_val;
|
||||
}
|
||||
|
||||
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_builtin_string, "string")
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
#include <mie/attribute/attribute-definition.h>
|
||||
#include <mie/attribute/attribute.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/dialect/builtin.h>
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/macros.h>
|
||||
#include <mie/parse/parser.h>
|
||||
#include <mie/print/printer.h>
|
||||
|
||||
static enum mie_status print(
|
||||
const struct mie_attribute *value, struct mie_printer *out)
|
||||
{
|
||||
const struct mie_type_attr *ty = (const struct mie_type_attr *)value;
|
||||
|
||||
if (!(out->p_flags & MIE_PRINT_F_ABBREVIATED)) {
|
||||
b_stream_write_string(out->p_stream, "#builtin.type<", NULL);
|
||||
}
|
||||
|
||||
mie_printer_print_type(out, ty->ty_value);
|
||||
|
||||
if (!(out->p_flags & MIE_PRINT_F_ABBREVIATED)) {
|
||||
b_stream_write_char(out->p_stream, '>');
|
||||
}
|
||||
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static struct mie_type_attr *type_attr_create(struct mie_ctx *ctx)
|
||||
{
|
||||
struct mie_type_attr *ty = malloc(sizeof *ty);
|
||||
if (!ty) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(ty, 0x0, sizeof *ty);
|
||||
|
||||
ty->ty_base.a_def
|
||||
= mie_ctx_get_attribute_definition(ctx, "builtin", "type");
|
||||
|
||||
return ty;
|
||||
}
|
||||
|
||||
static enum mie_status parse(
|
||||
struct mie_parser *ctx, const struct mie_attribute **out)
|
||||
{
|
||||
struct mie_type_attr *ty = type_attr_create(mie_parser_get_mie_ctx(ctx));
|
||||
if (!ty) {
|
||||
return MIE_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
const struct mie_type *type = NULL;
|
||||
|
||||
if (!mie_parser_parse_type(ctx, &type)) {
|
||||
free(ty);
|
||||
return MIE_ERR_BAD_FORMAT;
|
||||
}
|
||||
|
||||
ty->ty_value = type;
|
||||
|
||||
*out = (struct mie_attribute *)ty;
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
const struct mie_type *mie_type_attr_get_type(const struct mie_attribute *attrib)
|
||||
{
|
||||
if (!mie_attribute_check_name(attrib, "builtin", "type")) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const struct mie_type_attr *ty = (const struct mie_type_attr *)attrib;
|
||||
return ty->ty_value;
|
||||
}
|
||||
|
||||
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_builtin_type, "type")
|
||||
MIE_ATTRIBUTE_DEFINITION_STRUCT(struct mie_type_attr);
|
||||
MIE_ATTRIBUTE_DEFINITION_PRINT(print);
|
||||
MIE_ATTRIBUTE_DEFINITION_PARSE(parse);
|
||||
MIE_ATTRIBUTE_DEFINITION_END()
|
||||
|
||||
@@ -91,6 +91,8 @@ MIE_DIALECT_BEGIN(mie_builtin, struct builtin_dialect, "builtin")
|
||||
MIE_DIALECT_ADD_ATTRIBUTE(mie_builtin_string);
|
||||
MIE_DIALECT_ADD_ATTRIBUTE(mie_builtin_int);
|
||||
MIE_DIALECT_ADD_ATTRIBUTE(mie_builtin_float);
|
||||
MIE_DIALECT_ADD_ATTRIBUTE(mie_builtin_array);
|
||||
MIE_DIALECT_ADD_ATTRIBUTE(mie_builtin_type);
|
||||
MIE_DIALECT_ADD_TRAIT(mie_builtin_isolated_from_above);
|
||||
MIE_DIALECT_ADD_TRAIT(mie_builtin_symbol_table);
|
||||
MIE_DIALECT_ADD_INTERFACE(mie_builtin_symbol);
|
||||
|
||||
@@ -15,6 +15,10 @@ static void type_init(
|
||||
|
||||
static enum mie_status print(const struct mie_type *ty, struct mie_printer *out)
|
||||
{
|
||||
b_stream_write_string(
|
||||
out->p_stream,
|
||||
(out->p_flags & MIE_PRINT_F_ABBREVIATED) ? "str" : "!builtin.string",
|
||||
NULL);
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <mie/ir/op-definition.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <mie/ir/op-definition.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,69 @@
|
||||
#include <mie/attribute/attribute-map.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/dialect/builtin.h>
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/interface/interface-definition.h>
|
||||
#include <mie/interface/interface.h>
|
||||
#include <mie/ir/block.h>
|
||||
#include <mie/ir/op-definition.h>
|
||||
#include <mie/ir/op.h>
|
||||
#include <mie/ir/region.h>
|
||||
#include <mie/macros.h>
|
||||
#include <mie/print/printer.h>
|
||||
#include <mie/type/function.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
|
||||
{
|
||||
const struct mie_attribute *sym_name
|
||||
= mie_attribute_map_get(&op->op_attrib, "sym_name");
|
||||
const struct mie_attribute *function_type_attr
|
||||
= mie_attribute_map_get(&op->op_attrib, "function_type");
|
||||
const char *sym_name_cstr = mie_string_get_cstr(sym_name);
|
||||
const struct mie_type *function_type_g
|
||||
= mie_type_attr_get_type(function_type_attr);
|
||||
const struct mie_function_type *function_ty
|
||||
= (const struct mie_function_type *)function_type_g;
|
||||
|
||||
b_stream_write_fmt(printer->p_stream, NULL, " @%s(", sym_name_cstr);
|
||||
|
||||
const struct mie_region *code = &op->op_regions.items[0];
|
||||
const struct mie_block *entry = code->r_blocks.items[0];
|
||||
|
||||
for (size_t i = 0; i < MIE_VECTOR_COUNT(entry->b_params); i++) {
|
||||
if (i > 0) {
|
||||
b_stream_write_string(printer->p_stream, ", ", NULL);
|
||||
}
|
||||
|
||||
const struct mie_register *param = entry->b_params.items[i];
|
||||
|
||||
mie_printer_print_register(printer, param, MIE_PRINT_F_INCLUDE_TYPE);
|
||||
}
|
||||
|
||||
b_stream_write_string(printer->p_stream, ") -> ", NULL);
|
||||
|
||||
if (MIE_VECTOR_COUNT(function_ty->func_out) != 1) {
|
||||
b_stream_write_char(printer->p_stream, '(');
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < MIE_VECTOR_COUNT(function_ty->func_out); i++) {
|
||||
if (i > 0) {
|
||||
b_stream_write_string(printer->p_stream, ", ", NULL);
|
||||
}
|
||||
|
||||
const struct mie_type *ty = function_ty->func_out.items[i];
|
||||
|
||||
mie_printer_print_type(printer, ty);
|
||||
}
|
||||
|
||||
if (MIE_VECTOR_COUNT(function_ty->func_out) != 1) {
|
||||
b_stream_write_char(printer->p_stream, ')');
|
||||
}
|
||||
|
||||
b_stream_write_char(printer->p_stream, ' ');
|
||||
|
||||
mie_printer_print_region(
|
||||
printer, code, MIE_PRINT_F_EXCLUDE_FIRST_BLOCK_HEADER);
|
||||
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <mie/ir/op-definition.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <mie/ir/op-definition.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <mie/ir/op-definition.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <mie/ir/op-definition.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <mie/ir/op-definition.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <mie/ir/op-definition.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <mie/macros.h>
|
||||
#include <mie/trait/trait.h>
|
||||
|
||||
static enum mie_status print(const struct mie_op *op, b_stream *out)
|
||||
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -26,4 +26,8 @@ struct mie_attribute_definition {
|
||||
MIE_API struct mie_attribute_definition *mie_attribute_definition_create(
|
||||
struct mie_dialect *parent, const char *name);
|
||||
|
||||
MIE_API bool mie_attribute_definition_check_name(
|
||||
const struct mie_attribute_definition *def, const char *dialect_name,
|
||||
const char *attrib_name);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
#ifndef MIE_ATTRIBUTE_ATTRIBUTE_H_
|
||||
#define MIE_ATTRIBUTE_ATTRIBUTE_H_
|
||||
|
||||
#include <mie/misc.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct mie_attribute_definition;
|
||||
|
||||
struct mie_attribute {
|
||||
const struct mie_attribute_definition *a_def;
|
||||
};
|
||||
|
||||
MIE_API bool mie_attribute_check_name(
|
||||
const struct mie_attribute *attrib, const char *dialect_name,
|
||||
const char *attrib_name);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <mie/interface/interface.h>
|
||||
#include <mie/misc.h>
|
||||
#include <mie/trait/trait.h>
|
||||
#include <mie/vector.h>
|
||||
|
||||
struct mie_dialect;
|
||||
|
||||
@@ -54,6 +55,16 @@ struct mie_index {
|
||||
size_t i_value;
|
||||
};
|
||||
|
||||
struct mie_array {
|
||||
struct mie_attribute a_base;
|
||||
MIE_VECTOR_DECLARE(const struct mie_attribute *, a_items);
|
||||
};
|
||||
|
||||
struct mie_type_attr {
|
||||
struct mie_attribute ty_base;
|
||||
const struct mie_type *ty_value;
|
||||
};
|
||||
|
||||
struct mie_symbol {
|
||||
struct mie_interface sym_base;
|
||||
const char *(*sym_get_name)(const struct mie_op *);
|
||||
@@ -100,6 +111,10 @@ MIE_API struct mie_attribute *mie_ctx_get_string(
|
||||
struct mie_ctx *ctx, const char *s);
|
||||
MIE_API struct mie_attribute *mie_ctx_get_index(struct mie_ctx *ctx, size_t val);
|
||||
|
||||
MIE_API const char *mie_string_get_cstr(const struct mie_attribute *attrib);
|
||||
MIE_API const struct mie_type *mie_type_attr_get_type(
|
||||
const struct mie_attribute *attrib);
|
||||
|
||||
MIE_API struct mie_type *mie_ctx_get_int_type(struct mie_ctx *ctx, size_t bit_width);
|
||||
MIE_API struct mie_type *mie_ctx_get_float_type(
|
||||
struct mie_ctx *ctx, size_t bit_width);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#define MIE_OP_MAX_RESULTS 8
|
||||
|
||||
struct mie_op;
|
||||
struct mie_printer;
|
||||
struct mie_parser;
|
||||
struct mie_dialect;
|
||||
|
||||
@@ -101,7 +102,7 @@ struct mie_op_definition {
|
||||
const struct mie_op_param op_params[MIE_OP_MAX_PARAMS];
|
||||
const struct mie_op_result op_results[MIE_OP_MAX_RESULTS];
|
||||
|
||||
enum mie_status (*op_print)(const struct mie_op *, b_stream *);
|
||||
enum mie_status (*op_print)(struct mie_printer *, const struct mie_op *);
|
||||
enum mie_status (*op_parse)(struct mie_parser *, struct mie_op *);
|
||||
};
|
||||
|
||||
|
||||
@@ -17,6 +17,10 @@ struct mie_register;
|
||||
enum mie_print_flags {
|
||||
MIE_PRINT_F_GENERIC = 0x01u,
|
||||
MIE_PRINT_F_ABBREVIATED = 0x02u,
|
||||
|
||||
MIE_PRINT_F_INCLUDE_TYPE = 0x04u,
|
||||
MIE_PRINT_F_EXCLUDE_BLOCK_HEADER = 0x08u,
|
||||
MIE_PRINT_F_EXCLUDE_FIRST_BLOCK_HEADER = 0x10u,
|
||||
};
|
||||
|
||||
struct mie_printer {
|
||||
@@ -34,14 +38,17 @@ MIE_API void mie_printer_print_module(
|
||||
MIE_API void mie_printer_print_op(
|
||||
struct mie_printer *printer, const struct mie_op *op);
|
||||
MIE_API void mie_printer_print_region(
|
||||
struct mie_printer *printer, const struct mie_region *region);
|
||||
struct mie_printer *printer, const struct mie_region *region,
|
||||
enum mie_print_flags flags);
|
||||
MIE_API void mie_printer_print_block(
|
||||
struct mie_printer *printer, const struct mie_block *block);
|
||||
struct mie_printer *printer, const struct mie_block *block,
|
||||
enum mie_print_flags flags);
|
||||
MIE_API void mie_printer_print_type(
|
||||
struct mie_printer *printer, const struct mie_type *type);
|
||||
MIE_API void mie_printer_print_attribute(
|
||||
struct mie_printer *printer, const struct mie_attribute *attrib);
|
||||
MIE_API void mie_printer_print_register(
|
||||
struct mie_printer *printer, const struct mie_register *reg);
|
||||
struct mie_printer *printer, const struct mie_register *reg,
|
||||
enum mie_print_flags flags);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -355,8 +355,25 @@ static bool parse_type_name(struct mie_parser *ctx, const struct mie_type **out)
|
||||
return false;
|
||||
}
|
||||
|
||||
*out = NULL;
|
||||
const struct mie_type_definition *ty_def
|
||||
= get_type_by_full_name(ctx, name);
|
||||
|
||||
if (!ty_def) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const struct mie_type *ty = NULL;
|
||||
enum mie_status status = MIE_SUCCESS;
|
||||
|
||||
if (ty_def->ty_parse) {
|
||||
status = ty_def->ty_parse(ctx, &ty);
|
||||
} else {
|
||||
ty = mie_ctx_get_type(
|
||||
ctx->p_ctx, ty_def->ty_parent->d_name, ty_def->ty_name);
|
||||
}
|
||||
|
||||
*out = ty;
|
||||
return ty != NULL;
|
||||
}
|
||||
|
||||
static bool parse_composite_type(struct mie_parser *ctx, const struct mie_type **out)
|
||||
@@ -1244,6 +1261,10 @@ bool mie_parser_parse_attribute(
|
||||
attribute = mie_ctx_get_attribute_definition(
|
||||
ctx->p_ctx, "builtin", "dict");
|
||||
break;
|
||||
case MIE_SYM_LEFT_PAREN:
|
||||
attribute = mie_ctx_get_attribute_definition(
|
||||
ctx->p_ctx, "builtin", "type");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -1273,7 +1294,7 @@ bool mie_parser_parse_attribute(
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!attribute->a_parse(ctx, dest)) {
|
||||
if (attribute->a_parse(ctx, dest) != MIE_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ static void print_block_header_params(
|
||||
b_stream_write_string(printer->p_stream, ", ", NULL);
|
||||
}
|
||||
|
||||
mie_printer_print_register(printer, block->b_params.items[i]);
|
||||
mie_printer_print_register(printer, block->b_params.items[i], 0);
|
||||
|
||||
b_stream_write_string(printer->p_stream, ": ", NULL);
|
||||
|
||||
@@ -46,9 +46,13 @@ static void print_block_header(
|
||||
}
|
||||
|
||||
void mie_printer_print_block(
|
||||
struct mie_printer *printer, const struct mie_block *block)
|
||||
struct mie_printer *printer, const struct mie_block *block,
|
||||
enum mie_print_flags flags)
|
||||
{
|
||||
if (!(flags & MIE_PRINT_F_EXCLUDE_BLOCK_HEADER)) {
|
||||
print_block_header(printer, block);
|
||||
}
|
||||
|
||||
b_stream_push_indent(printer->p_stream, 4);
|
||||
|
||||
for (size_t i = 0; i < MIE_VECTOR_COUNT(block->b_ops); i++) {
|
||||
|
||||
@@ -101,7 +101,7 @@ static void print_region_list(struct mie_printer *printer, const struct mie_op *
|
||||
b_stream_write_string(printer->p_stream, ", ", NULL);
|
||||
}
|
||||
|
||||
mie_printer_print_region(printer, &op->op_regions.items[i]);
|
||||
mie_printer_print_region(printer, &op->op_regions.items[i], 0);
|
||||
}
|
||||
|
||||
b_stream_write_string(printer->p_stream, ")", NULL);
|
||||
@@ -182,23 +182,9 @@ static void print_type_signature(
|
||||
}
|
||||
}
|
||||
|
||||
void mie_printer_print_op(struct mie_printer *printer, const struct mie_op *op)
|
||||
static void print_generic_op(struct mie_printer *printer, const struct mie_op *op)
|
||||
{
|
||||
for (size_t i = 0; i < MIE_VECTOR_COUNT(op->op_result); i++) {
|
||||
if (i > 0) {
|
||||
b_stream_write_string(printer->p_stream, ", ", NULL);
|
||||
}
|
||||
|
||||
mie_printer_print_register(printer, op->op_result.items[i]);
|
||||
}
|
||||
|
||||
if (MIE_VECTOR_COUNT(op->op_result) > 0) {
|
||||
b_stream_write_string(printer->p_stream, " = ", NULL);
|
||||
}
|
||||
|
||||
if (printer->p_flags & MIE_PRINT_F_GENERIC) {
|
||||
b_stream_write_char(printer->p_stream, '~');
|
||||
}
|
||||
|
||||
if (op->op_flags & MIE_OP_F_OP_RESOLVED) {
|
||||
b_stream_write_fmt(
|
||||
@@ -225,3 +211,32 @@ void mie_printer_print_op(struct mie_printer *printer, const struct mie_op *op)
|
||||
print_attribute_list(printer, op);
|
||||
print_type_signature(printer, op);
|
||||
}
|
||||
|
||||
void mie_printer_print_op(struct mie_printer *printer, const struct mie_op *op)
|
||||
{
|
||||
for (size_t i = 0; i < MIE_VECTOR_COUNT(op->op_result); i++) {
|
||||
if (i > 0) {
|
||||
b_stream_write_string(printer->p_stream, ", ", NULL);
|
||||
}
|
||||
|
||||
mie_printer_print_register(printer, op->op_result.items[i], 0);
|
||||
}
|
||||
|
||||
if (MIE_VECTOR_COUNT(op->op_result) > 0) {
|
||||
b_stream_write_string(printer->p_stream, " = ", NULL);
|
||||
}
|
||||
|
||||
bool use_generic = !op->op_info || !op->op_info->op_print
|
||||
|| printer->p_flags & MIE_PRINT_F_GENERIC;
|
||||
|
||||
if (use_generic) {
|
||||
print_generic_op(printer, op);
|
||||
return;
|
||||
}
|
||||
|
||||
b_stream_write_fmt(
|
||||
printer->p_stream, NULL, "%s.%s", op->op_dialect->d_name,
|
||||
op->op_info->op_name);
|
||||
|
||||
op->op_info->op_print(printer, op);
|
||||
}
|
||||
|
||||
@@ -3,13 +3,20 @@
|
||||
#include <mie/print/printer.h>
|
||||
|
||||
void mie_printer_print_region(
|
||||
struct mie_printer *printer, const struct mie_region *region)
|
||||
struct mie_printer *printer, const struct mie_region *region,
|
||||
enum mie_print_flags flags)
|
||||
{
|
||||
b_stream_write_string(printer->p_stream, "{\n", NULL);
|
||||
|
||||
for (size_t i = 0; i < MIE_VECTOR_COUNT(region->r_blocks); i++) {
|
||||
enum mie_print_flags block_flags = 0;
|
||||
|
||||
if ((flags & MIE_PRINT_F_EXCLUDE_FIRST_BLOCK_HEADER) && (i == 0)) {
|
||||
block_flags = MIE_PRINT_F_EXCLUDE_BLOCK_HEADER;
|
||||
}
|
||||
|
||||
const struct mie_block *block = region->r_blocks.items[i];
|
||||
mie_printer_print_block(printer, block);
|
||||
mie_printer_print_block(printer, block, block_flags);
|
||||
}
|
||||
|
||||
b_stream_write_string(printer->p_stream, "}", NULL);
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
#include <mie/print/printer.h>
|
||||
|
||||
void mie_printer_print_register(
|
||||
struct mie_printer *printer, const struct mie_register *reg)
|
||||
struct mie_printer *printer, const struct mie_register *reg,
|
||||
enum mie_print_flags flags)
|
||||
{
|
||||
if (reg->reg_flags & MIE_REGISTER_F_VIRTUAL) {
|
||||
b_stream_write_fmt(
|
||||
@@ -14,4 +15,9 @@ void mie_printer_print_register(
|
||||
} else {
|
||||
b_stream_write_string(printer->p_stream, "?REG", NULL);
|
||||
}
|
||||
|
||||
if (flags & MIE_PRINT_F_INCLUDE_TYPE) {
|
||||
b_stream_write_string(printer->p_stream, ": ", NULL);
|
||||
mie_printer_print_type(printer, reg->reg_type);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user