mie: move mie_type_to_string to type.c

This commit is contained in:
2025-08-29 15:46:12 +01:00
parent 1a37898d48
commit 7fdae9f1e0
2 changed files with 48 additions and 44 deletions

View File

@@ -24,50 +24,6 @@
typedef b_status (*write_function)(struct mie_ir_converter *, struct mie_value *);
static void mie_type_to_string(struct mie_type *type, char *out, size_t max)
{
if (!type) {
snprintf(out, max, "<no-type>");
return;
}
switch (type->t_id) {
case MIE_TYPE_PTR:
snprintf(out, max, "ptr");
break;
case MIE_TYPE_VOID:
snprintf(out, max, "void");
break;
case MIE_TYPE_INT:
snprintf(out, max, "i%u", type->t_width);
break;
case MIE_TYPE_ID:
snprintf(out, max, "id");
break;
case MIE_TYPE_STR:
snprintf(out, max, "str");
break;
case MIE_TYPE_ATOM:
snprintf(out, max, "atom");
break;
case MIE_TYPE_LABEL:
snprintf(out, max, "label");
break;
case MIE_TYPE_ARRAY:
snprintf(out, max, "array");
break;
case MIE_TYPE_FUNC:
snprintf(out, max, "func");
break;
case MIE_TYPE_SELECTOR:
snprintf(out, max, "");
break;
default:
snprintf(out, max, "<unknown-type>");
break;
}
}
b_status write_char(struct mie_ir_converter *converter, char c)
{
long result = 0;

View File

@@ -1,4 +1,5 @@
#include <mie/type.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -25,3 +26,50 @@ struct mie_type *mie_type_create(void)
return out;
}
void mie_type_to_string(const struct mie_type *type, char *out, size_t max)
{
if (!type) {
snprintf(out, max, "no-type");
return;
}
switch (type->t_id) {
case MIE_TYPE_PTR:
snprintf(out, max, "ptr");
break;
case MIE_TYPE_VOID:
snprintf(out, max, "void");
break;
case MIE_TYPE_INT:
snprintf(out, max, "i%u", type->t_width);
break;
case MIE_TYPE_ID:
snprintf(out, max, "id");
break;
case MIE_TYPE_STR:
snprintf(out, max, "str");
break;
case MIE_TYPE_ATOM:
snprintf(out, max, "atom");
break;
case MIE_TYPE_LABEL:
snprintf(out, max, "label");
break;
case MIE_TYPE_ARRAY:
snprintf(out, max, "array");
break;
case MIE_TYPE_FUNC:
snprintf(out, max, "func");
break;
case MIE_TYPE_GLUE:
snprintf(out, max, "glue");
break;
case MIE_TYPE_SELECTOR:
snprintf(out, max, "");
break;
default:
snprintf(out, max, "unknown-type");
break;
}
}