/* Encoding information for integers, floating-point values, and certain other
intrinsics can be obtained by calling ctf_type_encoding, below. The flags
- field will contain values appropriate for the type defined in <ctf.h>. */
+ field will contain values appropriate for the type defined in <ctf.h>.
+
+ For floats, only the first of these fields is meaningful. */
typedef struct ctf_encoding
{
extern ctf_id_t ctf_add_enum_encoded (ctf_dict_t *, uint32_t, const char *,
const ctf_encoding_t *);
extern ctf_id_t ctf_add_enum (ctf_dict_t *, uint32_t, const char *);
+extern ctf_id_t ctf_add_btf_float (ctf_dict_t *, uint32_t,
+ const char *, const ctf_encoding_t *);
extern ctf_id_t ctf_add_float (ctf_dict_t *, uint32_t,
const char *, const ctf_encoding_t *);
extern ctf_id_t ctf_add_forward (ctf_dict_t *, uint32_t, const char *,
if (name == NULL || name[0] == '\0')
return (ctf_set_typed_errno (fp, ECTF_NONAME));
- if (!ctf_assert (fp, kind == CTF_K_INTEGER || kind == CTF_K_FLOAT))
- return CTF_ERR; /* errno is set for us. */
+ if (!ctf_assert (fp, kind == CTF_K_INTEGER || kind == CTF_K_FLOAT
+ || kind == CTF_K_BTF_FLOAT))
+ return CTF_ERR; /* errno is set for us. */
- if ((type = ctf_add_generic (fp, flag, name, kind, sizeof (uint32_t),
- &dtd)) == CTF_ERR)
+ if (kind == CTF_K_BTF_FLOAT)
+ vlen = 0;
+
+ if ((dtd = ctf_add_generic (fp, flag, name, kind, 0, vlen, 0, NULL)) == NULL)
return CTF_ERR; /* errno is set for us. */
- dtd->dtd_data.ctt_info = CTF_TYPE_INFO (kind, flag, 0);
- dtd->dtd_data.ctt_size = clp2 (P2ROUNDUP (ep->cte_bits, CHAR_BIT)
- / CHAR_BIT);
- switch (kind)
+ dtd->dtd_data->ctt_info = CTF_TYPE_INFO (kind, 0, 0);
+ dtd->dtd_data->ctt_size = clp2 (P2ROUNDUP (ep->cte_bits, CHAR_BIT) / CHAR_BIT);
+
+ if (kind != CTF_K_BTF_FLOAT)
{
- case CTF_K_INTEGER:
- encoding = CTF_INT_DATA (ep->cte_format, ep->cte_offset, ep->cte_bits);
- break;
- case CTF_K_FLOAT:
- encoding = CTF_FP_DATA (ep->cte_format, ep->cte_offset, ep->cte_bits);
- break;
- default:
- /* ctf_assert is opaque with -fno-inline. This dead code avoids
- a warning about "encoding" being used uninitialized. */
- return CTF_ERR;
+ encoding = ep->cte_format;
+ if (kind == CTF_K_INTEGER)
+ encoding = CTF_INT_DATA (ep->cte_format, ep->cte_offset, ep->cte_bits);
+
+ memcpy (dtd->dtd_vlen, &encoding, sizeof (encoding));
}
- memcpy (dtd->dtd_vlen, &encoding, sizeof (encoding));
- return type;
+ return dtd->dtd_type;
}
ctf_id_t
kind = ctf_type_kind_unsliced (fp, resolved_ref);
if ((kind != CTF_K_INTEGER) && (kind != CTF_K_FLOAT) &&
- (kind != CTF_K_ENUM)
+ (kind != CTF_K_ENUM) && (kind != CTF_K_BTF_FLOAT)
&& (ref != 0))
return (ctf_set_typed_errno (fp, ECTF_NOTINTFP));
return (ctf_add_encoded (fp, flag, name, ep, CTF_K_FLOAT));
}
+ctf_id_t
+ctf_add_btf_float (ctf_dict_t *fp, uint32_t flag,
+ const char *name, const ctf_encoding_t *ep)
+{
+ return (ctf_add_encoded (fp, flag, name, ep, CTF_K_BTF_FLOAT));
+}
+
ctf_id_t
ctf_add_pointer (ctf_dict_t *fp, uint32_t flag, ctf_id_t ref)
{
case CTF_K_FLOAT:
case CTF_K_TYPEDEF:
/* Integers, floats, and typedefs must always be named types. */
+ case CTF_K_BTF_FLOAT:
if (name[0] == '\0')
{
ctf_type_encoding (ctf_dict_t *fp, ctf_id_t type, ctf_encoding_t *ep)
{
ctf_dict_t *ofp = fp;
- ctf_dtdef_t *dtd;
- const ctf_type_t *tp;
- ssize_t increment;
+ const ctf_type_t *tp, *suffix;
const unsigned char *vlen;
uint32_t data;
- if ((tp = ctf_lookup_by_id (&fp, type)) == NULL)
+ if ((tp = ctf_lookup_by_id (&fp, type, &suffix)) == NULL)
return -1; /* errno is set for us. */
- if ((dtd = ctf_dynamic_type (ofp, type)) != NULL)
- vlen = dtd->dtd_vlen;
- else
- {
- ctf_get_ctt_size (fp, tp, NULL, &increment);
- vlen = (const unsigned char *) ((uintptr_t) tp + increment);
- }
+ if ((type = ctf_type_resolve (fp, type)) == CTF_ERR)
+ return (ctf_set_typed_errno (ofp, ECTF_NOTYPE));
- switch (LCTF_INFO_KIND (fp, tp->ctt_info))
+ vlen = ctf_vlen (fp, type, tp, NULL);
+
+ switch (LCTF_KIND (fp, tp))
{
case CTF_K_INTEGER:
data = *(const uint32_t *) vlen;
ep->cte_offset = 0;
ep->cte_bits = 0;
break;
+ case CTF_K_BTF_FLOAT:
+ ep->cte_format = 0;
+ ep->cte_offset = 0;
+ ep->cte_bits = suffix->ctt_size * CHAR_BIT;
+ break;
case CTF_K_SLICE:
{
const ctf_slice_t *slice;