2010-07-26 54 views
3

我將var名稱存儲在另一個var中,我想從原始var中檢索值。Specman:如何檢索存儲在另一個var中的var的值

爲前:

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; 

回答

2

這被稱爲內省或反思。你必須使用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的反射界面。

風流黑客!

+0

嗨羅斯,感謝您的回答,但用「print rf_i;」聲明,是否打印存儲在A中的所有列表值? – Dan 2010-07-27 03:17:55

+0

不,'rf_i'是字段A的反射對象的引用。您必須弄清楚如何從反射字段中提取數據。 Specman的反射界面是一個真正的痛苦。不像Python的內省工作的輕鬆。 – 2010-07-27 18:30:06

相關問題