Specman - 如何将结构转换为字符串列表

Specman - how to convert struct to a list of string

将结构转换为字符串列表(所有字段的列表 - 名称和值)的有效方法是什么?

例如以下结构:

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

确实可以使用反射实现接受任何结构的通用代码。 这是此类代码的一个示例。您可以对其进行修改,例如 - 仅将物理字段添加到列表中(通过调用 "if it.is_physical()")等

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);
    };
};