def visit_Instance(self, node):
        params = [ (k, self.replace_visitor.visit(v)) for k, v in node.params ]
        ports = [ (k, self.replace_visitor.visit(v)) for k, v in node.ports ]
        node.params = params
        node.ports = ports

        inst_const_dict = OrderedDict()
        for k, v in params:
            inst_const_dict[k] = v

        if isinstance(node.module, (module.StubModule, str)):
            return node

        mod = copy.deepcopy(node.module)
        prev_name = mod.name
        new_name = prev_name

        while True:
            if new_name not in self.submodule:
                self.submodule[new_name] = mod
                self.mod.submodule[new_name] = mod
                mod.name = new_name
                break

            new_name = '_'.join([prev_name, 'copy', str(ModuleReplaceVisitor.tmp_count)])
            ModuleReplaceVisitor.tmp_count += 1
        
        mvisitor = ModuleReplaceVisitor(mod, inst_const_dict, self.submodule)
        mod = mvisitor.resolve()
        node.module = mod
        
        return node
dataset/ETHPy150Open PyHDI/veriloggen/veriloggen/resolver/resolver.py/ModuleReplaceVisitor.visit_Instance/original