gpt4 book ai didi

Specman:如何检索存储在另一个 var 中的 var 值

转载 作者:行者123 更新时间:2023-12-02 02:32:07 27 4
gpt4 key购买 nike

我已将变量名称存储在另一个变量中,我想从原始变量中检索值。

例如:

var var_A: list of uint = {1,3,2};
var var_A_str:string = "var_A";

//现在我想使用 var_A_str 打印 var_A 值列表。我该怎么做?

print $var_A_str;

最佳答案

这称为内省(introspection)或反射(reflection)。您必须使用 Specman 的 rf_manager。在文档中搜索它。但是,文档并未向您展示该单元具有的所有方法。如果您真的想查看所有方法,请运行这段代码:

extend sys {
run() is also {
var rf_man : rf_struct = rf_manager.get_exact_subtype_of_instance(rf_manager);
out(" RF Manager:");
for each (meth) in rf_man.get_declared_methods() {
print meth;
};
};
};

我不确定如何遍历列表元素,但您可以使用此代码段查看对对象实例成员(不是子例程的变量)的引用的方法。

extend sys {

A : list of uint;
keep A == {1;3;2};
run() is also {

var variable_name := "A";
var rf_obj: rf_struct = rf_manager.get_exact_subtype_of_instance(sys);
var rf_i : rf_field = rf_obj.get_field(variable_name);
print rf_i;
var rf_rf_i := rf_manager.get_exact_subtype_of_instance(rf_i);
out ( "#\n# RF_RFI\n#");
for each (meth) in rf_rf_i.get_declared_methods() {
print meth;
};
};
};

在我的版本 ( 8.2 ) 中打印:

    Starting the test ...    Running the test ...      rf_i = rf_field 'A', line 7 in @rf_test4    #    # RF_RFI    #      meth = rf_method 'get_type', Specman's private modules      meth = rf_method 'is_physical', Specman's private modules      meth = rf_method 'get_svtp_pack', Specman's private modules      meth = rf_method 'set_svtp_pack', Specman's private modules      meth = rf_method 'is_ungenerated', Specman's private modules      meth = rf_method 'is_const', Specman's private modules      meth = rf_method 'is_unit_instance', Specman's private modules      meth = rf_method 'is_port_instance', Specman's private modules      meth = rf_method 'is_reference', Specman's private modules      meth = rf_method 'get_constrained_types', Specman's private modules      meth = rf_method 'get_deep_copy_attr', Specman's private modules      meth = rf_method 'get_value', Specman's private modules      meth = rf_method 'set_value', Specman's private modules      meth = rf_method 'get_value_unsafe', Specman's private modules      meth = rf_method 'get_all_when_value_unsafe', Specman's private modules      meth = rf_method 'set_value_unsafe', Specman's private modules      meth = rf_method 'set_value_const_reassign_unsafe', Specman's private modules      meth = rf_method 'get_interface_port_prefix', Specman's private modules      meth = rf_method 'get_interface_port_suffix', Specman's private modules      meth = rf_method 'is_gen_intelligen', Specman's private modules      meth = rf_method 'get_long_name', Specman's private modules      meth = rf_method 'get_implicit_constraints', Specman's private modules      meth = rf_method 'make_path', Specman's private modules      meth = rf_method 'make_element', Specman's private modules      meth = rf_method 'make_list_size_path', Specman's private modules      meth = rf_method 'is_unit_reference', Specman's private modules      meth = rf_method 'get_id_name_for_port_type', Specman's private modules      meth = rf_method 'get_list_upper_bound', Specman's private modules      meth = rf_method 'get_sv_typename', Specman's private modules      meth = rf_method 'get_sv_name_under_when', Specman's private modules      meth = rf_method 'get_sv_size', Specman's private modules      meth = rf_method 'sv_add_encode_lines', Specman's private modules      meth = rf_method 'sv_get_decode_function_local_var_name', Specman's private modules      meth = rf_method 'sv_get_decode_function_local_var_decl', Specman's private modules      meth = rf_method 'sv_add_decode_lines', Specman's private modules      meth = rf_method 'get_sv_field_name', Specman's private modules      meth = rf_method 'get_sv_field', Specman's private modules      meth = rf_method 'sv_must_be_protected_field', Specman's private modules      meth = rf_method 'sv_add_get_set_field_functions', Specman's private modules      meth = rf_method 'sv_add_get_set_field_function_decs', Specman's private modules      meth = rf_method 'is_sv_exported_field', Specman's private modules      meth = rf_method 'is_sv_determinant_field', Specman's private modules      meth = rf_method 'field_configured_to_svtp_pack', Specman's private modules      meth = rf_method 'get_ovm_field_macro', Specman's private modules      meth = rf_method 'is_internal', Specman's private modules      meth = rf_method 'get', Specman's private modules      meth = rf_method 'eanalyze_lnt', Specman's private modules    No actual running requested.    Checking the test ...

Checking is complete - 0 DUT errors, 0 DUT warnings.

我确信有一种方法可以做你想做的事,但使用 Specman 的反射接口(interface)可能非常困难。

快乐的黑客!

关于Specman:如何检索存储在另一个 var 中的 var 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3331627/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com