<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://www.verific.com/faq/index.php?action=history&amp;feed=atom&amp;title=How_to_get_full_hierarchy_ID_path</id>
		<title>How to get full hierarchy ID path - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://www.verific.com/faq/index.php?action=history&amp;feed=atom&amp;title=How_to_get_full_hierarchy_ID_path"/>
		<link rel="alternate" type="text/html" href="https://www.verific.com/faq/index.php?title=How_to_get_full_hierarchy_ID_path&amp;action=history"/>
		<updated>2026-05-02T12:51:33Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.3</generator>

	<entry>
		<id>https://www.verific.com/faq/index.php?title=How_to_get_full_hierarchy_ID_path&amp;diff=532&amp;oldid=prev</id>
		<title>Hoa: Created page with &quot;Note that this code sample requires &quot;Hierarchy Tree&quot; feature.  C++ code:  &lt;nowiki&gt; #include &quot;VerificSystem.h&quot; #include &quot;veri_file.h&quot; #include &quot;VeriModuleItem.h&quot; #include &quot;Veri...&quot;</title>
		<link rel="alternate" type="text/html" href="https://www.verific.com/faq/index.php?title=How_to_get_full_hierarchy_ID_path&amp;diff=532&amp;oldid=prev"/>
				<updated>2020-06-23T19:31:14Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;Note that this code sample requires &amp;quot;Hierarchy Tree&amp;quot; feature.  C++ code:  &amp;lt;nowiki&amp;gt; #include &amp;quot;VerificSystem.h&amp;quot; #include &amp;quot;veri_file.h&amp;quot; #include &amp;quot;VeriModuleItem.h&amp;quot; #include &amp;quot;Veri...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Note that this code sample requires &amp;quot;Hierarchy Tree&amp;quot; feature.&lt;br /&gt;
&lt;br /&gt;
C++ code:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
#include &amp;quot;VerificSystem.h&amp;quot;&lt;br /&gt;
#include &amp;quot;veri_file.h&amp;quot;&lt;br /&gt;
#include &amp;quot;VeriModuleItem.h&amp;quot;&lt;br /&gt;
#include &amp;quot;VeriModule.h&amp;quot;&lt;br /&gt;
#include &amp;quot;VeriId.h&amp;quot;&lt;br /&gt;
#include &amp;quot;VeriExpression.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;hier_tree.h&amp;quot;&lt;br /&gt;
#include &amp;quot;HierTreeNode.h&amp;quot;&lt;br /&gt;
#include &amp;quot;HierId.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace Verific ;&lt;br /&gt;
using namespace std ;&lt;br /&gt;
&lt;br /&gt;
void PrintHierIdPath(HierTreeNode *tree_node, HierId *hier_id)&lt;br /&gt;
{&lt;br /&gt;
    if (!tree_node || !hier_id) return ;&lt;br /&gt;
    std::cerr &amp;lt;&amp;lt; &amp;quot;HierId &amp;quot; &amp;lt;&amp;lt; hier_id-&amp;gt;GetVeriNameRef()-&amp;gt;GetPrettyPrintedString()&lt;br /&gt;
        &amp;lt;&amp;lt; &amp;quot; full path nodes: &amp;quot;;&lt;br /&gt;
&lt;br /&gt;
    Array *path_ids = hier_id-&amp;gt;GetVeriElementIds(tree_node) ;&lt;br /&gt;
    Array* path = hier_id-&amp;gt;FullPath() ;&lt;br /&gt;
&lt;br /&gt;
    Map actual_vs_formal(POINTER_HASH) ;&lt;br /&gt;
    HierTreeNode *node ;&lt;br /&gt;
    VeriIdDef *interface_formal = 0 ;&lt;br /&gt;
    HierTreeNode *interface_actual = 0 ;&lt;br /&gt;
    VeriIdDef *id ;&lt;br /&gt;
    unsigned i ;&lt;br /&gt;
    // Here we assumed there can be only a single interface port in a hier path&lt;br /&gt;
    // This may not be true for a corner out of LRM case but still allowed by LRM&lt;br /&gt;
    // Eg: A interface has another interface instance inside it which has an interface&lt;br /&gt;
    // port. In that case we have to collect all such ports and iterate over it in the&lt;br /&gt;
    // next loop.&lt;br /&gt;
    FOREACH_ARRAY_ITEM(path_ids, i, id) {&lt;br /&gt;
        if (id &amp;amp;&amp;amp; id-&amp;gt;IsInterfacePort()) {&lt;br /&gt;
            interface_formal = id ;&lt;br /&gt;
            break ;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    FOREACH_ARRAY_ITEM(path, i, node) {&lt;br /&gt;
        if (!node) continue ;&lt;br /&gt;
        // Node actual {formal}&lt;br /&gt;
        std::cerr &amp;lt;&amp;lt; &amp;quot; (&amp;quot; &amp;lt;&amp;lt; node-&amp;gt;GetName() ;&lt;br /&gt;
        if (interface_formal) { // find respective actual for this formal&lt;br /&gt;
            InterfaceInfo *id_info = node-&amp;gt;GetParamValue(interface_formal) ;&lt;br /&gt;
            HierTreeNode *id_actual = (id_info) ? id_info-&amp;gt;GetScope() : 0 ;&lt;br /&gt;
            if (id_actual) interface_actual = id_actual ;&lt;br /&gt;
        }&lt;br /&gt;
        if (interface_actual == node) std::cerr &amp;lt;&amp;lt; &amp;quot; {&amp;quot; &amp;lt;&amp;lt; interface_formal-&amp;gt;GetName() &amp;lt;&amp;lt; &amp;quot;}&amp;quot; ;&lt;br /&gt;
        std::cerr &amp;lt;&amp;lt; &amp;quot;) &amp;quot; ;&lt;br /&gt;
&lt;br /&gt;
        // Index actual {formal}&lt;br /&gt;
        if (node-&amp;gt;IsArrayInstance() &amp;amp;&amp;amp; i+1 &amp;lt; path-&amp;gt;Size() &amp;amp;&amp;amp; path-&amp;gt;At(i+1)) {&lt;br /&gt;
            // works for single index&lt;br /&gt;
            std::cerr &amp;lt;&amp;lt; &amp;quot; [&amp;quot; &amp;lt;&amp;lt; node-&amp;gt;GetChildName((HierTreeNode*)path-&amp;gt;At(++i)) ;&lt;br /&gt;
            int pos = Strings::atoi(node-&amp;gt;GetChildName((HierTreeNode*)path-&amp;gt;At(i))) ;&lt;br /&gt;
            if (interface_formal) {&lt;br /&gt;
                VeriIdDef *actual = node-&amp;gt;GetVeriInstanceId() ;&lt;br /&gt;
                // Obtain dimensions of formal and actual Ids&lt;br /&gt;
                VeriRange *actual_range = (actual) ? actual-&amp;gt;GetDimensions() : 0 ;&lt;br /&gt;
                VeriRange *formal_range = interface_formal-&amp;gt;GetDimensions() ;&lt;br /&gt;
                if (actual_range &amp;amp;&amp;amp; formal_range) {&lt;br /&gt;
                    // Find corresponding index of formal wrt actual&lt;br /&gt;
                    int actual_left = actual_range-&amp;gt;EvaluateLeft(0) ;&lt;br /&gt;
                    int offset = std::abs(actual_left - pos) ;&lt;br /&gt;
                    int formal_left = formal_range-&amp;gt;EvaluateLeft(0) ;&lt;br /&gt;
                    int formal_right = formal_range-&amp;gt;EvaluateRight(0) ;&lt;br /&gt;
&lt;br /&gt;
                    if (formal_left &amp;gt; formal_right) std::cerr &amp;lt;&amp;lt; &amp;quot; {&amp;quot; &amp;lt;&amp;lt; (formal_left - offset) &amp;lt;&amp;lt; &amp;quot;}&amp;quot; ;&lt;br /&gt;
                    else std::cerr &amp;lt;&amp;lt; &amp;quot; {&amp;quot; &amp;lt;&amp;lt; (formal_left + offset) &amp;lt;&amp;lt; &amp;quot;}&amp;quot; ;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            std::cerr &amp;lt;&amp;lt; &amp;quot;]&amp;quot;;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    std::cerr&amp;lt;&amp;lt;std::endl;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void TraverseAndCollect(HierTreeNode *node, Array *instance_nodes, Array *path_name_stack)&lt;br /&gt;
{&lt;br /&gt;
    if (!node || !instance_nodes || !path_name_stack) return ;&lt;br /&gt;
    if (node-&amp;gt;GetClassId() == ID_VERIINSTANCEHIERTREENODE) {&lt;br /&gt;
        instance_nodes-&amp;gt;Insert(node) ;&lt;br /&gt;
        SetIter si ;&lt;br /&gt;
        HierId *hier_id ;&lt;br /&gt;
        FOREACH_SET_ITEM(node-&amp;gt;GetHierIdTab(), si, &amp;amp;hier_id) {&lt;br /&gt;
            PrintHierIdPath(node, hier_id) ;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    MapIter mi ;&lt;br /&gt;
    char *inst_name ;&lt;br /&gt;
    HierTreeNode *child_node ;&lt;br /&gt;
    FOREACH_MAP_ITEM(node-&amp;gt;GetChildren(), mi, &amp;amp;inst_name, &amp;amp;child_node) {&lt;br /&gt;
        if (!inst_name || !child_node) continue ;&lt;br /&gt;
        path_name_stack-&amp;gt;InsertLast(inst_name) ;&lt;br /&gt;
        TraverseAndCollect(child_node, instance_nodes, path_name_stack) ;&lt;br /&gt;
        (void) path_name_stack-&amp;gt;RemoveLast() ;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    if (!veri_file::Analyze(&amp;quot;test.v&amp;quot;, veri_file::SYSTEM_VERILOG)) return 1 ;&lt;br /&gt;
    Array *top_modules = veri_file::GetTopModules() ;&lt;br /&gt;
    if (!top_modules) return 1 ;&lt;br /&gt;
&lt;br /&gt;
    const Map *top_ht_nodes = hier_tree::CreateHierarchicalTree(top_modules, 0, 0) ;&lt;br /&gt;
&lt;br /&gt;
    Array *instance_nodes = new Array(POINTER_HASH) ;&lt;br /&gt;
    HierTreeNode *root ;&lt;br /&gt;
    MapIter mi ;&lt;br /&gt;
    FOREACH_MAP_ITEM(top_ht_nodes, mi, 0, &amp;amp;root) {&lt;br /&gt;
        if (!root) continue ;&lt;br /&gt;
        Array path_name_stack ;&lt;br /&gt;
        path_name_stack.InsertLast(root-&amp;gt;GetName()) ;&lt;br /&gt;
        TraverseAndCollect(root, instance_nodes, &amp;amp;path_name_stack) ;&lt;br /&gt;
        (void) path_name_stack.RemoveLast() ;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    return 0 ;&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Testcase:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
interface i;&lt;br /&gt;
  bit b;&lt;br /&gt;
endinterface&lt;br /&gt;
&lt;br /&gt;
module m0 (i ip [-1:0]);&lt;br /&gt;
endmodule&lt;br /&gt;
&lt;br /&gt;
module m1 (i ip [ 1:0]);&lt;br /&gt;
  assert property (m0i.ip[-1].b == ip[1].b);&lt;br /&gt;
endmodule&lt;br /&gt;
&lt;br /&gt;
module top;&lt;br /&gt;
  i ii [1:0] ();&lt;br /&gt;
  m0 m0i (ii);&lt;br /&gt;
  m1 m1i (ii);&lt;br /&gt;
endmodule&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&lt;br /&gt;
-- Analyzing Verilog file 'test.v' (VERI-1482)&lt;br /&gt;
HierId ii full path nodes:  (top)  (ii)&lt;br /&gt;
HierId ii full path nodes:  (top)  (ii)&lt;br /&gt;
HierId m0i.ip[(-1)].b full path nodes:  (top)  (m0i)  (ii {ip})  [1 {-1}]&lt;br /&gt;
HierId ip[1].b full path nodes:  (top)  (m1i)  (ii {ip})  [1 {1}]&lt;br /&gt;
 &amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hoa</name></author>	</entry>

	</feed>