What is the efficient way to convert struct to a list of strings (list of all its field - name and value)?
For example the following struct:
struct spot_top_s {
%D_LDO_SFS_EN : uint(bits:1);
%D_COMP3P3_ACC_EN : uint(bits:1);
%D_BGCOMP_TRIM : uint(bits:6);
%spot_top_jtagtest_out : bit;
%spot_top_jtagtest_in : bit;
}; // spot_top_s
Indeed a generic code which accepts any struct can be implemented using reflection. Here is one example of such a code. You can modify it, for example - add to the list only physical fields (by calling "if it.is_physical()"), etc.
extend sys {
get_fields(input_struct : any_struct) : list of string is {
var struct_rf : rf_struct;
struct_rf = rf_manager.get_struct_of_instance( input_struct);
var struct_fields : list of rf_field;
struct_fields = struct_rf.get_fields();
var field_type_rf : rf_type;
var field_value_unsafe : untyped;
for each in struct_fields {
result.add(it.get_name());
var f:= it.get_value_unsafe(input_struct);
field_type_rf = it.get_type();
field_value_unsafe = it.get_value_unsafe(input_struct);
result.add(field_type_rf.value_to_string(field_value_unsafe));
};
};
// usage example:
my_spot_top : spot_top_s;
post_generate() is also {
print get_field(my_spot_top);
};
};