btf_encoder: Adopt btf__encode_base_type() as btf_encoder__add_base_type()

As it is just prep work to call libbpf's btf__add_base_type() using
pahole's data structures populated from another format, normally DWARF.

So that we can eventually ditch the btf_encoder__verbose and
btf_gen_float globals, making them members of 'struct btf_encoder'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2021-06-09 09:31:26 -03:00
parent 14ab2e0361
commit 68ed8af859
3 changed files with 10 additions and 9 deletions

View File

@ -234,7 +234,7 @@ static int btf_encoder__encode_tag(struct btf_encoder *encoder, struct cu *cu, s
switch (tag->tag) {
case DW_TAG_base_type:
name = dwarves__active_loader->strings__ptr(cu, tag__base_type(tag)->name);
return btf__encode_base_type(btf, tag__base_type(tag), name);
return btf_encoder__add_base_type(encoder, tag__base_type(tag), name);
case DW_TAG_const_type:
return btf__encode_ref_type(btf, BTF_KIND_CONST, ref_type_id, NULL, false);
case DW_TAG_pointer_type:
@ -707,7 +707,7 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu, bool skip
bt.name = 0;
bt.bit_size = 32;
btf__encode_base_type(encoder->btf, &bt, "__ARRAY_SIZE_TYPE__");
btf_encoder__add_base_type(encoder, &bt, "__ARRAY_SIZE_TYPE__");
encoder->has_index_type = true;
}

View File

@ -226,7 +226,7 @@ static int32_t btf__encode_float_type(struct btf *btf, const struct base_type *b
return id;
}
int32_t btf__encode_base_type(struct btf *btf, const struct base_type *bt, const char *name)
int32_t btf_encoder__add_base_type(struct btf_encoder *encoder, const struct base_type *bt, const char *name)
{
const struct btf_type *t;
uint8_t encoding = 0;
@ -246,7 +246,7 @@ int32_t btf__encode_base_type(struct btf *btf, const struct base_type *bt, const
if (bt->float_type == BT_FP_SINGLE ||
bt->float_type == BT_FP_DOUBLE ||
bt->float_type == BT_FP_LDBL)
return btf__encode_float_type(btf, bt, name);
return btf__encode_float_type(encoder->btf, bt, name);
fprintf(stderr, "Complex, interval and imaginary float types are not supported\n");
return -1;
}
@ -287,12 +287,12 @@ int32_t btf__encode_base_type(struct btf *btf, const struct base_type *bt, const
byte_sz = 4;
}
id = btf__add_int(btf, name, byte_sz, encoding);
id = btf__add_int(encoder->btf, name, byte_sz, encoding);
if (id < 0) {
btf__log_err(btf, BTF_KIND_INT, name, true, "Error emitting BTF type");
btf__log_err(encoder->btf, BTF_KIND_INT, name, true, "Error emitting BTF type");
} else {
t = btf__type_by_id(btf, id);
btf__log_type(btf, t, false, true,
t = btf__type_by_id(encoder->btf, id);
btf__log_type(encoder->btf, t, false, true,
"size=%u nr_bits=%u encoding=%s%s",
t->size, bt->bit_size,
btf__int_encoding_str(encoding),

View File

@ -17,11 +17,12 @@ extern bool btf_gen_floats;
#define PERCPU_SECTION ".data..percpu"
struct btf_encoder;
struct cu;
struct base_type;
struct ftype;
int32_t btf__encode_base_type(struct btf *btf, const struct base_type *bt, const char *name);
int32_t btf_encoder__add_base_type(struct btf_encoder *encoder, const struct base_type *bt, const char *name);
int32_t btf__encode_ref_type(struct btf *btf, uint16_t kind, uint32_t type, const char *name, bool kind_flag);
int btf__encode_member(struct btf *btf, const char *name, uint32_t type, uint32_t bitfield_size, uint32_t bit_offset);
int32_t btf__encode_struct(struct btf *btf, uint8_t kind, const char *name, uint32_t size);