From 6e55642a1973f6ca5186141964de2c8766d00ca5 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sun, 11 Jan 2026 14:23:10 +0000 Subject: [PATCH] mie: arith: add support for querying the width of int/float types --- mie/dialect/arith/float.c | 14 ++++++++++++++ mie/dialect/arith/int.c | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/mie/dialect/arith/float.c b/mie/dialect/arith/float.c index 61098c2..5f085d0 100644 --- a/mie/dialect/arith/float.c +++ b/mie/dialect/arith/float.c @@ -69,6 +69,20 @@ 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) +{ + if (strcmp(type->ty_def->ty_parent->d_name, "arith") != 0) { + return (size_t)-1; + } + + if (strcmp(type->ty_def->ty_name, "float") != 0) { + return (size_t)-1; + } + + const struct float_type *float_type = (const struct float_type *)type; + return float_type->f_width; +} + static enum mie_status print( const struct mie_type_definition *def, const struct mie_type *ty, b_stream *out) diff --git a/mie/dialect/arith/int.c b/mie/dialect/arith/int.c index 95e8ab0..820e3ef 100644 --- a/mie/dialect/arith/int.c +++ b/mie/dialect/arith/int.c @@ -61,6 +61,20 @@ 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) +{ + if (strcmp(type->ty_def->ty_parent->d_name, "arith") != 0) { + return (size_t)-1; + } + + if (strcmp(type->ty_def->ty_name, "int") != 0) { + return (size_t)-1; + } + + const struct int_type *int_type = (const struct int_type *)type; + return int_type->i_width; +} + static enum mie_status print( const struct mie_type_definition *def, const struct mie_type *ty, b_stream *out)