mie: move all builtin types (int, float, index, etc) and attributes to the builtin dialect
This commit is contained in:
@@ -3,61 +3,7 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
struct arith_dialect {
|
||||
struct mie_dialect d_base;
|
||||
struct mie_int_cache *ctx_ints;
|
||||
struct mie_float_cache *ctx_floats;
|
||||
};
|
||||
|
||||
static enum mie_status init(struct mie_dialect *d)
|
||||
{
|
||||
struct arith_dialect *dialect = (struct arith_dialect *)d;
|
||||
dialect->ctx_ints = mie_int_cache_create();
|
||||
dialect->ctx_floats = mie_float_cache_create();
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status cleanup(struct mie_dialect *d)
|
||||
{
|
||||
struct arith_dialect *dialect = (struct arith_dialect *)d;
|
||||
mie_int_cache_destroy(dialect->ctx_ints);
|
||||
mie_float_cache_destroy(dialect->ctx_floats);
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
struct mie_attribute *mie_ctx_get_int(
|
||||
struct mie_ctx *ctx, long long val, size_t nr_bits)
|
||||
{
|
||||
struct arith_dialect *dialect
|
||||
= (struct arith_dialect *)mie_ctx_get_dialect(ctx, "arith");
|
||||
if (!dialect) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (struct mie_attribute *)mie_int_cache_get(
|
||||
dialect->ctx_ints, ctx, val, nr_bits);
|
||||
}
|
||||
|
||||
struct mie_attribute *mie_ctx_get_float(
|
||||
struct mie_ctx *ctx, double val, size_t nr_bits)
|
||||
{
|
||||
struct arith_dialect *dialect
|
||||
= (struct arith_dialect *)mie_ctx_get_dialect(ctx, "arith");
|
||||
if (!dialect) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (struct mie_attribute *)mie_float_cache_get(
|
||||
dialect->ctx_floats, ctx, val, nr_bits);
|
||||
}
|
||||
|
||||
MIE_DIALECT_BEGIN(mie_arith, struct arith_dialect, "arith")
|
||||
MIE_DIALECT_INIT(init);
|
||||
MIE_DIALECT_CLEANUP(cleanup);
|
||||
MIE_DIALECT_ADD_TYPE(mie_arith_int);
|
||||
MIE_DIALECT_ADD_TYPE(mie_arith_float);
|
||||
MIE_DIALECT_BEGIN(mie_arith, struct mie_dialect, "arith")
|
||||
MIE_DIALECT_ADD_OP(mie_arith_addi);
|
||||
MIE_DIALECT_ADD_OP(mie_arith_addf);
|
||||
MIE_DIALECT_ADD_ATTRIBUTE(mie_arith_int);
|
||||
MIE_DIALECT_ADD_ATTRIBUTE(mie_arith_float);
|
||||
MIE_DIALECT_END()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <blue/core/btree.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/dialect/arith.h>
|
||||
#include <mie/dialect/builtin.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -147,8 +147,8 @@ static struct float_width_cache_entry *float_width_cache_entry_create(
|
||||
}
|
||||
|
||||
out->e_value.f_base.a_def
|
||||
= mie_ctx_get_attribute_definition(ctx, "arith", "float");
|
||||
out->e_value.f_type = mie_arith_float_get_type(ctx, width);
|
||||
= mie_ctx_get_attribute_definition(ctx, "builtin", "float");
|
||||
out->e_value.f_type = mie_ctx_get_float_type(ctx, width);
|
||||
if (!out->e_value.f_type) {
|
||||
free(out);
|
||||
return NULL;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <blue/core/btree.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/dialect/arith.h>
|
||||
#include <mie/dialect/builtin.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -72,9 +72,9 @@ static struct int_width_cache_entry *int_width_cache_entry_create(
|
||||
memset(out, 0x0, sizeof *out);
|
||||
|
||||
out->e_value.i_base.a_def
|
||||
= mie_ctx_get_attribute_definition(ctx, "arith", "int");
|
||||
= mie_ctx_get_attribute_definition(ctx, "builtin", "int");
|
||||
out->e_value.i_val.v_small = value;
|
||||
out->e_value.i_type = mie_arith_int_get_type(ctx, width);
|
||||
out->e_value.i_type = mie_ctx_get_int_type(ctx, width);
|
||||
if (!out->e_value.i_type) {
|
||||
free(out);
|
||||
return NULL;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <mie/attribute/attribute-definition.h>
|
||||
#include <mie/attribute/attribute.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/dialect/arith.h>
|
||||
#include <mie/dialect/builtin.h>
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/macros.h>
|
||||
#include <mie/parse/parser.h>
|
||||
@@ -17,7 +17,7 @@ static enum mie_status print(
|
||||
const struct float_type *float_ty
|
||||
= (const struct float_type *)float_val->f_type;
|
||||
if (!(out->p_flags & MIE_PRINT_F_ABBREVIATED)) {
|
||||
b_stream_write_string(out->p_stream, "#arith.float<", NULL);
|
||||
b_stream_write_string(out->p_stream, "#builtin.float<", NULL);
|
||||
}
|
||||
|
||||
switch (float_ty->f_width) {
|
||||
@@ -63,7 +63,7 @@ static enum mie_status parse(
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t width = mie_arith_float_type_get_width(type);
|
||||
size_t width = mie_float_type_get_width(type);
|
||||
if (width == (size_t)-1) {
|
||||
return false;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ static enum mie_status parse(
|
||||
return true;
|
||||
}
|
||||
|
||||
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_arith_float, "float")
|
||||
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_builtin_float, "float")
|
||||
MIE_ATTRIBUTE_DEFINITION_STRUCT(struct mie_float);
|
||||
MIE_ATTRIBUTE_DEFINITION_PRINT(print);
|
||||
MIE_ATTRIBUTE_DEFINITION_PARSE(parse);
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <mie/attribute/attribute-definition.h>
|
||||
#include <mie/attribute/attribute.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/dialect/arith.h>
|
||||
#include <mie/dialect/builtin.h>
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/macros.h>
|
||||
#include <mie/parse/parser.h>
|
||||
@@ -16,7 +16,7 @@ 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)) {
|
||||
b_stream_write_string(out->p_stream, "#arith.int<", NULL);
|
||||
b_stream_write_string(out->p_stream, "#builtin.int<", NULL);
|
||||
}
|
||||
|
||||
if (int_ty->i_width <= 64) {
|
||||
@@ -54,7 +54,7 @@ static enum mie_status parse(
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t width = mie_arith_int_type_get_width(type);
|
||||
size_t width = mie_int_type_get_width(type);
|
||||
if (width == (size_t)-1) {
|
||||
return false;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ static enum mie_status parse(
|
||||
return true;
|
||||
}
|
||||
|
||||
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_arith_int, "int")
|
||||
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_builtin_int, "int")
|
||||
MIE_ATTRIBUTE_DEFINITION_STRUCT(struct mie_int);
|
||||
MIE_ATTRIBUTE_DEFINITION_PRINT(print);
|
||||
MIE_ATTRIBUTE_DEFINITION_PARSE(parse);
|
||||
@@ -6,12 +6,18 @@
|
||||
struct builtin_dialect {
|
||||
struct mie_dialect d_base;
|
||||
struct mie_string_cache *ctx_strings;
|
||||
struct mie_int_cache *ctx_ints;
|
||||
struct mie_float_cache *ctx_floats;
|
||||
struct mie_index_cache *ctx_indices;
|
||||
};
|
||||
|
||||
static enum mie_status init(struct mie_dialect *d)
|
||||
{
|
||||
struct builtin_dialect *dialect = (struct builtin_dialect *)d;
|
||||
dialect->ctx_strings = mie_string_cache_create();
|
||||
dialect->ctx_ints = mie_int_cache_create();
|
||||
dialect->ctx_floats = mie_float_cache_create();
|
||||
dialect->ctx_indices = mie_index_cache_create();
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -19,9 +25,38 @@ static enum mie_status cleanup(struct mie_dialect *d)
|
||||
{
|
||||
struct builtin_dialect *dialect = (struct builtin_dialect *)d;
|
||||
mie_string_cache_destroy(dialect->ctx_strings);
|
||||
mie_int_cache_destroy(dialect->ctx_ints);
|
||||
mie_float_cache_destroy(dialect->ctx_floats);
|
||||
mie_index_cache_destroy(dialect->ctx_indices);
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
struct mie_attribute *mie_ctx_get_int(
|
||||
struct mie_ctx *ctx, long long val, size_t nr_bits)
|
||||
{
|
||||
struct builtin_dialect *dialect
|
||||
= (struct builtin_dialect *)mie_ctx_get_dialect(ctx, "builtin");
|
||||
if (!dialect) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (struct mie_attribute *)mie_int_cache_get(
|
||||
dialect->ctx_ints, ctx, val, nr_bits);
|
||||
}
|
||||
|
||||
struct mie_attribute *mie_ctx_get_float(
|
||||
struct mie_ctx *ctx, double val, size_t nr_bits)
|
||||
{
|
||||
struct builtin_dialect *dialect
|
||||
= (struct builtin_dialect *)mie_ctx_get_dialect(ctx, "builtin");
|
||||
if (!dialect) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (struct mie_attribute *)mie_float_cache_get(
|
||||
dialect->ctx_floats, ctx, val, nr_bits);
|
||||
}
|
||||
|
||||
struct mie_attribute *mie_ctx_get_string(struct mie_ctx *ctx, const char *s)
|
||||
{
|
||||
struct builtin_dialect *dialect
|
||||
@@ -34,10 +69,27 @@ struct mie_attribute *mie_ctx_get_string(struct mie_ctx *ctx, const char *s)
|
||||
dialect->ctx_strings, ctx, s);
|
||||
}
|
||||
|
||||
struct mie_attribute *mie_ctx_get_index(struct mie_ctx *ctx, size_t val)
|
||||
{
|
||||
struct builtin_dialect *dialect
|
||||
= (struct builtin_dialect *)mie_ctx_get_dialect(ctx, "builtin");
|
||||
if (!dialect) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (struct mie_attribute *)mie_index_cache_get(
|
||||
dialect->ctx_indices, ctx, val);
|
||||
}
|
||||
|
||||
MIE_DIALECT_BEGIN(mie_builtin, struct builtin_dialect, "builtin")
|
||||
MIE_DIALECT_INIT(init);
|
||||
MIE_DIALECT_CLEANUP(cleanup);
|
||||
MIE_DIALECT_ADD_TYPE(mie_builtin_string);
|
||||
MIE_DIALECT_ADD_TYPE(mie_builtin_int);
|
||||
MIE_DIALECT_ADD_TYPE(mie_builtin_float);
|
||||
MIE_DIALECT_ADD_TYPE(mie_builtin_index);
|
||||
MIE_DIALECT_ADD_ATTRIBUTE(mie_builtin_string);
|
||||
MIE_DIALECT_ADD_ATTRIBUTE(mie_builtin_int);
|
||||
MIE_DIALECT_ADD_ATTRIBUTE(mie_builtin_float);
|
||||
MIE_DIALECT_ADD_TRAIT(mie_builtin_isolated_from_above);
|
||||
MIE_DIALECT_END()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef _ARITH_FLOAT_H_
|
||||
#define _ARITH_FLOAT_H_
|
||||
#ifndef _BUILTIN_FLOAT_H_
|
||||
#define _BUILTIN_FLOAT_H_
|
||||
|
||||
#include <mie/attribute/attribute.h>
|
||||
#include <mie/type/type.h>
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <blue/core/btree.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/dialect/index.h>
|
||||
#include <mie/dialect/builtin.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -28,6 +28,8 @@ static struct index_cache_entry *index_cache_entry_create(
|
||||
|
||||
memset(out, 0x0, sizeof *out);
|
||||
|
||||
out->e_value.i_base.a_def
|
||||
= mie_ctx_get_attribute_definition(ctx, "builtin", "index");
|
||||
out->e_value.i_value = val;
|
||||
|
||||
return out;
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef _ARITH_INT_H_
|
||||
#define _ARITH_INT_H_
|
||||
#ifndef _BUILTIN_INT_H_
|
||||
#define _BUILTIN_INT_H_
|
||||
|
||||
#include <mie/attribute/attribute.h>
|
||||
#include <mie/type/type.h>
|
||||
@@ -2,17 +2,17 @@
|
||||
|
||||
#include <blue/core/bstr.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/dialect/arith.h>
|
||||
#include <mie/dialect/builtin.h>
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/macros.h>
|
||||
#include <mie/print/printer.h>
|
||||
#include <mie/type/type-definition.h>
|
||||
#include <mie/type/type.h>
|
||||
|
||||
struct mie_type *mie_arith_float_get_type(struct mie_ctx *ctx, size_t bit_width)
|
||||
struct mie_type *mie_ctx_get_float_type(struct mie_ctx *ctx, size_t bit_width)
|
||||
{
|
||||
struct mie_type_definition *type_info
|
||||
= mie_ctx_get_type_definition(ctx, "arith", "float");
|
||||
= mie_ctx_get_type_definition(ctx, "builtin", "float");
|
||||
if (!type_info) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -34,7 +34,7 @@ struct mie_type *mie_arith_float_get_type(struct mie_ctx *ctx, size_t bit_width)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
type->f_base.ty_name = b_bstr_fmt("arith.float<%zu>", bit_width);
|
||||
type->f_base.ty_name = b_bstr_fmt("builtin.float<%zu>", bit_width);
|
||||
type->f_base.ty_instance_size = sizeof(struct mie_float);
|
||||
type->f_width = bit_width;
|
||||
|
||||
@@ -42,9 +42,9 @@ struct mie_type *mie_arith_float_get_type(struct mie_ctx *ctx, size_t bit_width)
|
||||
return (struct mie_type *)type;
|
||||
}
|
||||
|
||||
size_t mie_arith_float_type_get_width(const struct mie_type *type)
|
||||
size_t mie_float_type_get_width(const struct mie_type *type)
|
||||
{
|
||||
if (strcmp(type->ty_def->ty_parent->d_name, "arith") != 0) {
|
||||
if (strcmp(type->ty_def->ty_parent->d_name, "builtin") != 0) {
|
||||
return (size_t)-1;
|
||||
}
|
||||
|
||||
@@ -61,8 +61,7 @@ static enum mie_status print(const struct mie_type *ty, struct mie_printer *out)
|
||||
const struct float_type *float_type = (const struct float_type *)ty;
|
||||
b_stream_write_fmt(
|
||||
out->p_stream, NULL,
|
||||
(out->p_flags & MIE_PRINT_F_ABBREVIATED) ? "f%zu"
|
||||
: "!arith.float<%zu>",
|
||||
(out->p_flags & MIE_PRINT_F_ABBREVIATED) ? "f%zu" : "!builtin.float<%zu>",
|
||||
float_type->f_width);
|
||||
|
||||
return MIE_SUCCESS;
|
||||
@@ -73,7 +72,7 @@ static enum mie_status parse(struct mie_parser *parser, const struct mie_type **
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_TYPE_DEFINITION_BEGIN(mie_arith_float, "float")
|
||||
MIE_TYPE_DEFINITION_BEGIN(mie_builtin_float, "float")
|
||||
// MIE_TYPE_DEFINITION_FLAGS(MIE_TYPE_DEFINITION_PARAMETISED);
|
||||
MIE_TYPE_DEFINITION_STRUCT(struct float_type);
|
||||
MIE_TYPE_DEFINITION_PRINT(print);
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <mie/dialect/builtin.h>
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/index.h>
|
||||
#include <mie/macros.h>
|
||||
#include <mie/print/printer.h>
|
||||
#include <mie/type/type-definition.h>
|
||||
@@ -19,12 +19,12 @@ 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) ? "index" : "!index.index",
|
||||
(out->p_flags & MIE_PRINT_F_ABBREVIATED) ? "index" : "!builtin.index",
|
||||
NULL);
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_TYPE_DEFINITION_BEGIN(mie_index_index, "index")
|
||||
MIE_TYPE_DEFINITION_BEGIN(mie_builtin_index, "index")
|
||||
MIE_TYPE_DEFINITION_STRUCT(struct index_type);
|
||||
MIE_TYPE_DEFINITION_INIT(type_init);
|
||||
MIE_TYPE_DEFINITION_PRINT(print);
|
||||
@@ -2,17 +2,17 @@
|
||||
|
||||
#include <blue/core/bstr.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/dialect/arith.h>
|
||||
#include <mie/dialect/builtin.h>
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/macros.h>
|
||||
#include <mie/print/printer.h>
|
||||
#include <mie/type/type-definition.h>
|
||||
#include <mie/type/type.h>
|
||||
|
||||
struct mie_type *mie_arith_int_get_type(struct mie_ctx *ctx, size_t bit_width)
|
||||
struct mie_type *mie_ctx_get_int_type(struct mie_ctx *ctx, size_t bit_width)
|
||||
{
|
||||
struct mie_type_definition *type_info
|
||||
= mie_ctx_get_type_definition(ctx, "arith", "int");
|
||||
= mie_ctx_get_type_definition(ctx, "builtin", "int");
|
||||
if (!type_info) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -34,7 +34,7 @@ struct mie_type *mie_arith_int_get_type(struct mie_ctx *ctx, size_t bit_width)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
type->i_base.ty_name = b_bstr_fmt("arith.int<%zu>", bit_width);
|
||||
type->i_base.ty_name = b_bstr_fmt("builtin.int<%zu>", bit_width);
|
||||
type->i_base.ty_instance_size = sizeof(struct mie_int);
|
||||
type->i_width = bit_width;
|
||||
|
||||
@@ -42,9 +42,9 @@ struct mie_type *mie_arith_int_get_type(struct mie_ctx *ctx, size_t bit_width)
|
||||
return (struct mie_type *)type;
|
||||
}
|
||||
|
||||
size_t mie_arith_int_type_get_width(const struct mie_type *type)
|
||||
size_t mie_int_type_get_width(const struct mie_type *type)
|
||||
{
|
||||
if (strcmp(type->ty_def->ty_parent->d_name, "arith") != 0) {
|
||||
if (strcmp(type->ty_def->ty_parent->d_name, "builtin") != 0) {
|
||||
return (size_t)-1;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,8 @@ static enum mie_status print(const struct mie_type *ty, struct mie_printer *out)
|
||||
const struct int_type *int_type = (const struct int_type *)ty;
|
||||
b_stream_write_fmt(
|
||||
out->p_stream, NULL,
|
||||
(out->p_flags & MIE_PRINT_F_ABBREVIATED) ? "i%zu" : "!arith.int<%zu>",
|
||||
(out->p_flags & MIE_PRINT_F_ABBREVIATED) ? "i%zu"
|
||||
: "!builtin.int<%zu>",
|
||||
int_type->i_width);
|
||||
|
||||
return MIE_SUCCESS;
|
||||
@@ -72,7 +73,7 @@ static enum mie_status parse(struct mie_parser *parser, const struct mie_type **
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_TYPE_DEFINITION_BEGIN(mie_arith_int, "int")
|
||||
MIE_TYPE_DEFINITION_BEGIN(mie_builtin_int, "int")
|
||||
// MIE_TYPE_DEFINITION_FLAGS(MIE_TYPE_DEFINITION_PARAMETISED);
|
||||
MIE_TYPE_DEFINITION_STRUCT(struct int_type);
|
||||
MIE_TYPE_DEFINITION_PRINT(print);
|
||||
@@ -6,39 +6,5 @@
|
||||
#include <mie/type/type-definition.h>
|
||||
#include <mie/type/type.h>
|
||||
|
||||
struct index_dialect {
|
||||
struct mie_dialect d_base;
|
||||
struct mie_index_cache *ctx_indices;
|
||||
};
|
||||
|
||||
static enum mie_status init(struct mie_dialect *d)
|
||||
{
|
||||
struct index_dialect *dialect = (struct index_dialect *)d;
|
||||
dialect->ctx_indices = mie_index_cache_create();
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status cleanup(struct mie_dialect *d)
|
||||
{
|
||||
struct index_dialect *dialect = (struct index_dialect *)d;
|
||||
mie_index_cache_destroy(dialect->ctx_indices);
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
struct mie_attribute *mie_ctx_get_index(struct mie_ctx *ctx, size_t val)
|
||||
{
|
||||
struct index_dialect *dialect
|
||||
= (struct index_dialect *)mie_ctx_get_dialect(ctx, "index");
|
||||
if (!dialect) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (struct mie_attribute *)mie_index_cache_get(
|
||||
dialect->ctx_indices, ctx, val);
|
||||
}
|
||||
|
||||
MIE_DIALECT_BEGIN(mie_index, struct index_dialect, "index")
|
||||
MIE_DIALECT_INIT(init);
|
||||
MIE_DIALECT_CLEANUP(cleanup);
|
||||
MIE_DIALECT_ADD_TYPE(mie_index_index);
|
||||
MIE_DIALECT_BEGIN(mie_index, struct mie_dialect, "index")
|
||||
MIE_DIALECT_END()
|
||||
|
||||
@@ -9,62 +9,6 @@
|
||||
struct mie_ctx;
|
||||
struct mie_dialect;
|
||||
|
||||
enum mie_float_width {
|
||||
MIE_FLOAT_32 = 32,
|
||||
MIE_FLOAT_64 = 64,
|
||||
};
|
||||
|
||||
struct mie_int {
|
||||
struct mie_attribute i_base;
|
||||
const struct mie_type *i_type;
|
||||
|
||||
union {
|
||||
int64_t v_small;
|
||||
|
||||
struct {
|
||||
long *a_parts;
|
||||
size_t a_nr_parts;
|
||||
} v_arbitrary;
|
||||
} i_val;
|
||||
};
|
||||
|
||||
struct mie_float {
|
||||
struct mie_attribute f_base;
|
||||
const struct mie_type *f_type;
|
||||
|
||||
union {
|
||||
float v_32;
|
||||
double v_64;
|
||||
} f_val;
|
||||
};
|
||||
|
||||
struct mie_int_cache;
|
||||
|
||||
MIE_API struct mie_dialect *mie_arith_dialect_create(struct mie_ctx *ctx);
|
||||
|
||||
MIE_API struct mie_type *mie_arith_int_get_type(
|
||||
struct mie_ctx *ctx, size_t bit_width);
|
||||
MIE_API struct mie_type *mie_arith_float_get_type(
|
||||
struct mie_ctx *ctx, size_t bit_width);
|
||||
|
||||
MIE_API size_t mie_arith_int_type_get_width(const struct mie_type *type);
|
||||
MIE_API size_t mie_arith_float_type_get_width(const struct mie_type *type);
|
||||
|
||||
MIE_API struct mie_int_cache *mie_int_cache_create(void);
|
||||
MIE_API void mie_int_cache_destroy(struct mie_int_cache *cache);
|
||||
MIE_API struct mie_int *mie_int_cache_get(
|
||||
struct mie_int_cache *cache, struct mie_ctx *ctx, size_t value,
|
||||
size_t bit_width);
|
||||
|
||||
MIE_API struct mie_float_cache *mie_float_cache_create(void);
|
||||
MIE_API void mie_float_cache_destroy(struct mie_float_cache *cache);
|
||||
MIE_API struct mie_float *mie_float_cache_get(
|
||||
struct mie_float_cache *cache, struct mie_ctx *ctx, double value,
|
||||
size_t bit_width);
|
||||
|
||||
MIE_API struct mie_attribute *mie_ctx_get_int(
|
||||
struct mie_ctx *ctx, long long val, size_t nr_bits);
|
||||
MIE_API struct mie_attribute *mie_ctx_get_float(
|
||||
struct mie_ctx *ctx, double val, size_t nr_bits);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -11,13 +11,50 @@ struct mie_ctx;
|
||||
struct mie_int_type;
|
||||
struct mie_float_type;
|
||||
|
||||
enum mie_float_width {
|
||||
MIE_FLOAT_32 = 32,
|
||||
MIE_FLOAT_64 = 64,
|
||||
};
|
||||
|
||||
struct mie_string {
|
||||
struct mie_attribute str_base;
|
||||
char *str_val;
|
||||
size_t str_len;
|
||||
};
|
||||
|
||||
struct mie_int {
|
||||
struct mie_attribute i_base;
|
||||
const struct mie_type *i_type;
|
||||
|
||||
union {
|
||||
int64_t v_small;
|
||||
|
||||
struct {
|
||||
long *a_parts;
|
||||
size_t a_nr_parts;
|
||||
} v_arbitrary;
|
||||
} i_val;
|
||||
};
|
||||
|
||||
struct mie_float {
|
||||
struct mie_attribute f_base;
|
||||
const struct mie_type *f_type;
|
||||
|
||||
union {
|
||||
float v_32;
|
||||
double v_64;
|
||||
} f_val;
|
||||
};
|
||||
|
||||
struct mie_index {
|
||||
struct mie_attribute i_base;
|
||||
size_t i_value;
|
||||
};
|
||||
|
||||
struct mie_int_cache;
|
||||
struct mie_float_cache;
|
||||
struct mie_string_cache;
|
||||
struct mie_index_cache;
|
||||
|
||||
MIE_API struct mie_dialect *mie_builtin_dialect_create(struct mie_ctx *ctx);
|
||||
|
||||
@@ -26,7 +63,36 @@ MIE_API void mie_string_cache_destroy(struct mie_string_cache *cache);
|
||||
MIE_API struct mie_string *mie_string_cache_get(
|
||||
struct mie_string_cache *cache, struct mie_ctx *ctx, const char *val);
|
||||
|
||||
MIE_API struct mie_int_cache *mie_int_cache_create(void);
|
||||
MIE_API void mie_int_cache_destroy(struct mie_int_cache *cache);
|
||||
MIE_API struct mie_int *mie_int_cache_get(
|
||||
struct mie_int_cache *cache, struct mie_ctx *ctx, size_t value,
|
||||
size_t bit_width);
|
||||
|
||||
MIE_API struct mie_float_cache *mie_float_cache_create(void);
|
||||
MIE_API void mie_float_cache_destroy(struct mie_float_cache *cache);
|
||||
MIE_API struct mie_float *mie_float_cache_get(
|
||||
struct mie_float_cache *cache, struct mie_ctx *ctx, double value,
|
||||
size_t bit_width);
|
||||
|
||||
MIE_API struct mie_index_cache *mie_index_cache_create(void);
|
||||
MIE_API void mie_index_cache_destroy(struct mie_index_cache *cache);
|
||||
MIE_API struct mie_index *mie_index_cache_get(
|
||||
struct mie_index_cache *cache, struct mie_ctx *ctx, size_t value);
|
||||
|
||||
MIE_API struct mie_attribute *mie_ctx_get_int(
|
||||
struct mie_ctx *ctx, long long val, size_t nr_bits);
|
||||
MIE_API struct mie_attribute *mie_ctx_get_float(
|
||||
struct mie_ctx *ctx, double val, size_t nr_bits);
|
||||
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 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);
|
||||
|
||||
MIE_API size_t mie_int_type_get_width(const struct mie_type *type);
|
||||
MIE_API size_t mie_float_type_get_width(const struct mie_type *type);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -9,20 +9,6 @@
|
||||
struct mie_ctx;
|
||||
struct mie_dialect;
|
||||
|
||||
struct mie_index {
|
||||
struct mie_attribute i_base;
|
||||
size_t i_value;
|
||||
};
|
||||
|
||||
struct mie_index_cache;
|
||||
|
||||
MIE_API struct mie_dialect *mie_index_dialect_create(struct mie_ctx *ctx);
|
||||
|
||||
MIE_API struct mie_index_cache *mie_index_cache_create(void);
|
||||
MIE_API void mie_index_cache_destroy(struct mie_index_cache *cache);
|
||||
MIE_API struct mie_index *mie_index_cache_get(
|
||||
struct mie_index_cache *cache, struct mie_ctx *ctx, size_t value);
|
||||
|
||||
MIE_API struct mie_attribute *mie_ctx_get_index(struct mie_ctx *ctx, size_t val);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <mie/attribute/attribute-definition.h>
|
||||
#include <mie/attribute/attribute-map.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/dialect/arith.h>
|
||||
#include <mie/dialect/builtin.h>
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/dialect/index.h>
|
||||
@@ -301,17 +300,17 @@ static bool parse_builtin_type_name(
|
||||
ctx->p_ctx, "memref", "memref");
|
||||
} else if (!strcmp(name_cstr, "index")) {
|
||||
type_info = mie_ctx_get_type_definition(
|
||||
ctx->p_ctx, "index", "index");
|
||||
ctx->p_ctx, "builtin", "index");
|
||||
} else if (!strcmp(name_cstr, "str")) {
|
||||
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_type_definition(
|
||||
ctx->p_ctx, "arith", "int");
|
||||
ctx->p_ctx, "builtin", "int");
|
||||
base_type = INT;
|
||||
} else if (sscanf(name_cstr, "f%zu%c", &width, &tmp) == 1) {
|
||||
type_info = mie_ctx_get_type_definition(
|
||||
ctx->p_ctx, "arith", "float");
|
||||
ctx->p_ctx, "builtin", "float");
|
||||
base_type = FLOAT;
|
||||
}
|
||||
|
||||
@@ -323,10 +322,10 @@ static bool parse_builtin_type_name(
|
||||
|
||||
switch (base_type) {
|
||||
case INT:
|
||||
type = mie_arith_int_get_type(ctx->p_ctx, width);
|
||||
type = mie_ctx_get_int_type(ctx->p_ctx, width);
|
||||
break;
|
||||
case FLOAT:
|
||||
type = mie_arith_float_get_type(ctx->p_ctx, width);
|
||||
type = mie_ctx_get_float_type(ctx->p_ctx, width);
|
||||
break;
|
||||
default:
|
||||
if (type_info->ty_parse) {
|
||||
@@ -1229,11 +1228,11 @@ bool mie_parser_parse_attribute(
|
||||
break;
|
||||
case MIE_TOK_INT:
|
||||
attribute = mie_ctx_get_attribute_definition(
|
||||
ctx->p_ctx, "arith", "int");
|
||||
ctx->p_ctx, "builtin", "int");
|
||||
break;
|
||||
case MIE_TOK_FLOAT:
|
||||
attribute = mie_ctx_get_attribute_definition(
|
||||
ctx->p_ctx, "arith", "float");
|
||||
ctx->p_ctx, "builtin", "float");
|
||||
break;
|
||||
case MIE_TOK_SYMBOL:
|
||||
switch (mie_parser_peek_symbol(ctx)) {
|
||||
|
||||
Reference in New Issue
Block a user