Fix for assertion error when expanding macro.
[iverilog.git] / symbol_search.cc
blobbc723d81d9cce00954f120a83181c43f6b671038
1 /*
2 * Copyright (c) 2003 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
8 * any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 #ifdef HAVE_CVS_IDENT
20 #ident "$Id: symbol_search.cc,v 1.7 2007/06/02 03:42:13 steve Exp $"
21 #endif
23 # include "netlist.h"
24 # include "netmisc.h"
25 # include <assert.h>
29 * Search for the hierarchical name.
31 NetScope*symbol_search(Design*des, NetScope*scope, pform_name_t path,
32 NetNet*&net,
33 const NetExpr*&par,
34 NetEvent*&eve,
35 const NetExpr*&ex1, const NetExpr*&ex2)
37 assert(scope);
39 /* Get the tail name of the object we are looking for. */
40 perm_string key = peek_tail_name(path);
41 path.pop_back();
43 /* Initialize output argument to cleared. */
44 net = 0;
45 par = 0;
46 eve = 0;
48 /* If the path has a scope part, then search for the specified
49 scope that we are supposed to search. */
50 if (! path.empty()) {
51 list<hname_t> path_list = eval_scope_path(des, scope, path);
52 assert(path_list.size() <= path.size());
54 // If eval_scope_path returns a short list, then some
55 // part of the scope was not found. Abort.
56 if (path_list.size() < path.size())
57 return 0;
59 scope = des->find_scope(scope, path_list);
62 while (scope) {
63 if ( (net = scope->find_signal(key)) )
64 return scope;
66 if ( (eve = scope->find_event(key)) )
67 return scope;
69 if ( (par = scope->get_parameter(key, ex1, ex2)) )
70 return scope;
72 if (scope->type() == NetScope::MODULE)
73 scope = 0;
74 else
75 scope = scope->parent();
78 return 0;