mie: builtin: add function to get int/float value from an attribute
This commit is contained in:
@@ -78,6 +78,28 @@ static enum mie_status parse(
|
|||||||
return MIE_SUCCESS;
|
return MIE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool mie_float_get_value(const struct mie_attribute *attrib, double *out)
|
||||||
|
{
|
||||||
|
if (!mie_attribute_check_name(attrib, "builtin", "float")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct mie_float *v = (const struct mie_float *)attrib;
|
||||||
|
|
||||||
|
switch (mie_float_type_get_width(v->f_type)) {
|
||||||
|
case MIE_FLOAT_32:
|
||||||
|
*out = v->f_val.v_32;
|
||||||
|
break;
|
||||||
|
case MIE_FLOAT_64:
|
||||||
|
*out = v->f_val.v_64;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_builtin_float, "float")
|
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_builtin_float, "float")
|
||||||
MIE_ATTRIBUTE_DEFINITION_STRUCT(struct mie_float);
|
MIE_ATTRIBUTE_DEFINITION_STRUCT(struct mie_float);
|
||||||
MIE_ATTRIBUTE_DEFINITION_PRINT(print);
|
MIE_ATTRIBUTE_DEFINITION_PRINT(print);
|
||||||
|
|||||||
@@ -75,6 +75,18 @@ static enum mie_status parse(
|
|||||||
return MIE_SUCCESS;
|
return MIE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool mie_int_get_value(const struct mie_attribute *attrib, long long *out)
|
||||||
|
{
|
||||||
|
if (!mie_attribute_check_name(attrib, "builtin", "int")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct mie_int *v = (const struct mie_int *)attrib;
|
||||||
|
*out = v->i_val.v_small;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_builtin_int, "int")
|
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_builtin_int, "int")
|
||||||
MIE_ATTRIBUTE_DEFINITION_STRUCT(struct mie_int);
|
MIE_ATTRIBUTE_DEFINITION_STRUCT(struct mie_int);
|
||||||
MIE_ATTRIBUTE_DEFINITION_PRINT(print);
|
MIE_ATTRIBUTE_DEFINITION_PRINT(print);
|
||||||
|
|||||||
@@ -114,6 +114,8 @@ 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 char *mie_string_get_cstr(const struct mie_attribute *attrib);
|
||||||
MIE_API const struct mie_type *mie_type_attr_get_type(
|
MIE_API const struct mie_type *mie_type_attr_get_type(
|
||||||
const struct mie_attribute *attrib);
|
const struct mie_attribute *attrib);
|
||||||
|
MIE_API bool mie_int_get_value(const struct mie_attribute *attrib, long long *out);
|
||||||
|
MIE_API bool mie_float_get_value(const struct mie_attribute *attrib, double *out);
|
||||||
|
|
||||||
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_int_type(struct mie_ctx *ctx, size_t bit_width);
|
||||||
MIE_API struct mie_type *mie_ctx_get_float_type(
|
MIE_API struct mie_type *mie_ctx_get_float_type(
|
||||||
|
|||||||
Reference in New Issue
Block a user