Skip to content
Newer
Older
100644 185 lines (163 sloc) 5.25 KB
da7956a Fix name search in elab_lval.
steve authored Sep 19, 2003
1 /*
3aaacd4 @caryr Do not search up for a symbol if a hierarchical path was given.
caryr authored Apr 11, 2010
2 * Copyright (c) 2003-2010 Stephen Williams (steve@icarus.com)
174177d @steveicarus Rework symbol search to work incrementally.
authored Aug 25, 2012
3 * Copyright CERN 2012 / Stephen Williams (steve@icarus.com)
da7956a Fix name search in elab_lval.
steve authored Sep 19, 2003
4 *
5 * This source code is free software; you can redistribute it
6 * and/or modify it in source code form under the terms of the GNU
7 * General Public License as published by the Free Software
8 * Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
f5aafc3 @arunpersaud updated FSF-address
arunpersaud authored Aug 28, 2012
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
da7956a Fix name search in elab_lval.
steve authored Sep 19, 2003
19 */
20
21 # include "netlist.h"
c7d97f4 Properly evaluate scope path expressions.
steve authored Jun 2, 2007
22 # include "netmisc.h"
174177d @steveicarus Rework symbol search to work incrementally.
authored Aug 26, 2012
23 # include "ivl_assert.h"
da7956a Fix name search in elab_lval.
steve authored Sep 19, 2003
24
25
26 /*
27 * Search for the hierarchical name.
28 */
174177d @steveicarus Rework symbol search to work incrementally.
authored Aug 26, 2012
29 struct symbol_search_results {
30 inline symbol_search_results() {
31 scope = 0;
32 net = 0;
33 par_val = 0;
34 par_msb = 0;
35 par_lsb = 0;
36 eve = 0;
37 }
38
39 inline bool is_scope() const {
40 if (net) return false;
41 if (eve) return false;
42 if (par_val) return false;
43 if (scope) return true;
44 return false;
45 }
016d64e @caryr Remove spacing errors.
caryr authored Sep 24, 2012
46
174177d @steveicarus Rework symbol search to work incrementally.
authored Aug 26, 2012
47 // Scope where symbol was located. This is set in all cases,
48 // assuming the search succeeded.
49 NetScope*scope;
50 // If this was a net, the signal itself.
51 NetNet*net;
52 // If this was a parameter, the value expression and the
53 // optional value dimensions.
54 const NetExpr*par_val;
55 const NetExpr*par_msb;
56 const NetExpr*par_lsb;
57 // If this is a named event, ...
58 NetEvent*eve;
59 };
60
61 bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
62 pform_name_t path, struct symbol_search_results*res,
63 NetScope*start_scope = 0)
da7956a Fix name search in elab_lval.
steve authored Sep 19, 2003
64 {
65 assert(scope);
174177d @steveicarus Rework symbol search to work incrementally.
authored Aug 26, 2012
66 bool prefix_scope = false;
67 bool recurse_flag = false;
68 name_component_t path_tail = path.back();
ddd36ec Rework the heirarchical identifier parse syntax and pform
steve authored May 24, 2007
69 path.pop_back();
da7956a Fix name search in elab_lval.
steve authored Sep 19, 2003
70
174177d @steveicarus Rework symbol search to work incrementally.
authored Aug 26, 2012
71 // If this is a recursive call, then we need to know that so
72 // that we can enable the search for scopes. Set the
73 // recurse_flag to true if this is a recurse.
74 if (start_scope==0)
75 start_scope = scope;
76 else
77 recurse_flag = true;
824f29a @steveicarus Better errors for invalid scope path
authored Jul 22, 2007
78
174177d @steveicarus Rework symbol search to work incrementally.
authored Aug 26, 2012
79 // If there are components ahead of the tail, symbol_search
80 // recursively. Ideally, the result is a scope that we search
81 // for the tail key, but there are other special cases as well.
82 if (path.size() > 0) {
83 symbol_search_results recurse;
84 bool flag = symbol_search(li, des, scope, path, &recurse, start_scope);
85 if (! flag)
86 return false;
824f29a @steveicarus Better errors for invalid scope path
authored Jul 23, 2007
87
174177d @steveicarus Rework symbol search to work incrementally.
authored Aug 26, 2012
88 // The prefix is found to be a scope, so switch to that
89 // scoke, set the hier_path to turn of upwards searches,
90 // and continue our search for the tail.
91 if (recurse.is_scope()) {
92 scope = recurse.scope;
93 prefix_scope = true;
18edf2f Rework of automatic task/function support.
Martin Whitaker authored Oct 28, 2008
94
174177d @steveicarus Rework symbol search to work incrementally.
authored Aug 26, 2012
95 if (scope->is_auto() && li) {
96 cerr << li->get_fileline() << ": error: Hierarchical "
97 "reference to automatically allocated item "
98 "`" << path_tail.name << "' in path `" << path << "'" << endl;
99 des->errors += 1;
100 }
101 }
c7d97f4 Properly evaluate scope path expressions.
steve authored Jun 2, 2007
102 }
da7956a Fix name search in elab_lval.
steve authored Sep 19, 2003
103
104 while (scope) {
174177d @steveicarus Rework symbol search to work incrementally.
authored Aug 26, 2012
105 if (NetNet*net = scope->find_signal(path_tail.name)) {
106 res->scope = scope;
107 res->net = net;
108 return true;
109 }
110
111 if (NetEvent*eve = scope->find_event(path_tail.name)) {
112 res->scope = scope;
113 res->eve = eve;
114 return true;
115 }
da7956a Fix name search in elab_lval.
steve authored Sep 19, 2003
116
174177d @steveicarus Rework symbol search to work incrementally.
authored Aug 26, 2012
117 if (const NetExpr*par = scope->get_parameter(des, path_tail.name, res->par_msb, res->par_lsb)) {
118 res->scope = scope;
119 res->par_val = par;
120 return true;
121 }
da7956a Fix name search in elab_lval.
steve authored Sep 19, 2003
122
174177d @steveicarus Rework symbol search to work incrementally.
authored Aug 26, 2012
123 if (recurse_flag) {
124 bool flag = false;
125 hname_t path_item = eval_path_component(des, start_scope, path_tail, flag);
126 if (flag) {
127 cerr << li->get_fileline() << ": XXXXX: Errors evaluating scope index" << endl;
a14b8c5 @steveicarus Clean up Design::find_scope method use.
authored Aug 25, 2012
128 } else if (NetScope*chld = des->find_scope(scope, path_item)) {
174177d @steveicarus Rework symbol search to work incrementally.
authored Aug 26, 2012
129 res->scope = chld;
130 return true;
131 }
132 }
da7956a Fix name search in elab_lval.
steve authored Sep 19, 2003
133
174177d @steveicarus Rework symbol search to work incrementally.
authored Aug 26, 2012
134 // Don't scan up past a module boundary.
135 if (scope->type()==NetScope::MODULE && !scope->nested_module())
136 break;
137 // Don't scan up if we are searching within a prefixed scope.
138 if (prefix_scope)
139 break;
140
141 scope = scope->parent();
da7956a Fix name search in elab_lval.
steve authored Sep 19, 2003
142 }
143
174177d @steveicarus Rework symbol search to work incrementally.
authored Aug 26, 2012
144 // Last chance: this is a single name, so it might be the name
145 // of a root scope. Ask the design if this is a root
146 // scope. This is only possible if there is no prefix.
147 if (prefix_scope==false) {
148 hname_t path_item (path_tail.name);
a14b8c5 @steveicarus Clean up Design::find_scope method use.
authored Aug 26, 2012
149 scope = des->find_scope(path_item);
174177d @steveicarus Rework symbol search to work incrementally.
authored Aug 26, 2012
150 if (scope) {
151 res->scope = scope;
152 return true;
153 }
154 }
155
156 return false;
157 }
158
159 /*
160 * Compatibility version. Remove me!
161 */
162 NetScope*symbol_search(const LineInfo*li, Design*des, NetScope*scope,
163 pform_name_t path,
164 NetNet*&net,
165 const NetExpr*&par,
166 NetEvent*&eve,
167 const NetExpr*&ex1, const NetExpr*&ex2)
168 {
169 symbol_search_results recurse;
170 bool flag = symbol_search(li, des, scope, path, &recurse);
171 if (! flag) {
172 return 0;
173 }
174
175 if (recurse.is_scope())
176 return recurse.scope;
177
178 net = recurse.net;
179 par = recurse.par_val;
180 ex1 = recurse.par_msb;
181 ex2 = recurse.par_lsb;
182 eve = recurse.eve;
183 return recurse.scope;
da7956a Fix name search in elab_lval.
steve authored Sep 19, 2003
184 }
Something went wrong with that request. Please try again.