11
11
#include < util/cmdline.h>
12
12
#include < util/suffix.h>
13
13
#include < util/unicode.h>
14
+ #include < util/cout_message.h>
14
15
15
16
#include " verilog_parser.h"
16
17
#include " verilog_preprocessor.h"
@@ -36,7 +37,16 @@ class verilog_indexer_parsert
36
37
protected:
37
38
using idt = verilog_indexert::idt;
38
39
verilog_indexert &indexer;
39
- void rModule ();
40
+
41
+ // modules, classes, primitives, packages, interfaces
42
+ void rModule (verilog_indexert::idt::kindt, int end_token);
43
+
44
+ void rConstruct (); // always, initial, ...
45
+ void rDeclaration (); // reg, wire, input, typedef ...
46
+ void rTaskFunction (); // task ... endtask
47
+ void rContinuousAssign (); // assign
48
+ void rGenerate (); // generate ... endgenerate
49
+ void rModuleInstance (); // module instance(...);
40
50
41
51
struct tokent
42
52
{
@@ -50,6 +60,8 @@ class verilog_indexer_parsert
50
60
{
51
61
return kind == TOK_NON_TYPE_IDENTIFIER;
52
62
}
63
+ bool operator ==(int other) const { return kind == other; }
64
+ bool operator !=(int other) const { return kind != other; }
53
65
};
54
66
55
67
const tokent &next_token ()
@@ -94,11 +106,17 @@ std::string verilog_indexert::preprocess(const std::string &file_name)
94
106
return std::string ();
95
107
}
96
108
97
- null_message_handlert message_handler;
109
+ console_message_handlert message_handler;
98
110
verilog_preprocessort preprocessor (
99
111
in_stream, preprocessed, message_handler, file_name);
100
112
101
- preprocessor.preprocessor ();
113
+ try
114
+ {
115
+ preprocessor.preprocessor ();
116
+ }
117
+ catch (...)
118
+ {
119
+ }
102
120
103
121
return preprocessed.str ();
104
122
}
@@ -130,26 +148,99 @@ void verilog_indexer_parsert::rDescription()
130
148
auto &token = next_token ();
131
149
if (token.is_eof ())
132
150
break ;
133
- if (token.text == " module" )
134
- rModule ();
151
+ if (token == TOK_MODULE)
152
+ rModule (verilog_indexert::idt::MODULE, TOK_ENDMODULE);
153
+ else if (token == TOK_CLASS)
154
+ rModule (verilog_indexert::idt::CLASS, TOK_ENDCLASS);
155
+ else if (token == TOK_PRIMITIVE)
156
+ rModule (verilog_indexert::idt::PRIMITIVE, TOK_ENDPRIMITIVE);
157
+ else if (token == TOK_INTERFACE)
158
+ rModule (verilog_indexert::idt::INTERFACE, TOK_ENDINTERFACE);
159
+ else if (token == TOK_PACKAGE)
160
+ rModule (verilog_indexert::idt::PACKAGE, TOK_ENDPACKAGE);
161
+ else if (token == TOK_TYPEDEF)
162
+ rDeclaration ();
135
163
}
136
164
}
137
165
138
- void verilog_indexer_parsert::rModule ()
166
+ // / Covers the various 'definition-like' constructs in SystemVerilog, i.e.,
167
+ // / modules, interfaces, classes, primitives, packages
168
+ void verilog_indexer_parsert::rModule (verilog_indexert::idt::kindt kind, int end_token)
139
169
{
140
170
auto name = next_token ();
141
- if (name.is_identifier ())
171
+ if (!name.is_identifier ())
172
+ return ; // give up
173
+
174
+ idt id;
175
+ id.kind = verilog_indexert::idt::MODULE;
176
+ id.name = name.text ;
177
+ id.file_name = verilog_parser.get_file ();
178
+ indexer.add (std::move (id));
179
+
180
+ // now look for the 'endmodule', given as end_token
181
+ while (peek () != YYEOF)
142
182
{
143
- idt id;
144
- id.kind = verilog_indexert::idt::MODULE;
145
- id.name = name.text ;
146
- id.file_name = verilog_parser.get_file ();
147
- indexer.add (std::move (id));
183
+ auto &token = peek ();
184
+ if (token == end_token)
185
+ {
186
+ next_token ();
187
+ break ; // done with the module
188
+ }
189
+ else if (token == TOK_ALWAYS || token == TOK_ALWAYS_FF || token == TOK_ALWAYS_COMB || token == TOK_ALWAYS_LATCH || token == TOK_FINAL)
190
+ rConstruct ();
191
+ else if (token == TOK_VAR || token == TOK_WIRE || token == TOK_REG || token == TOK_INPUT || token == TOK_INOUT || token == TOK_OUTPUT || token == TOK_GENVAR || token == TOK_TYPEDEF || token == TOK_ENUM)
192
+ rDeclaration ();
193
+ else if (token == TOK_FUNCTION || token == TOK_TASK)
194
+ rTaskFunction ();
195
+ else if (token == TOK_ASSIGN)
196
+ rContinuousAssign ();
197
+ else if (token == TOK_GENERATE)
198
+ rGenerate ();
199
+ else if (token.is_identifier ())
200
+ {
201
+ // declaration, label, module instance
202
+ rModuleInstance ();
203
+ }
204
+ else
205
+ {
206
+ // something else
207
+ next_token ();
208
+ std::cout << " ELSE: " << token.text << " \n " ;
209
+ }
148
210
}
149
211
}
150
212
151
- std::vector<std::filesystem::path> verilog_files ()
213
+ void verilog_indexer_parsert::rConstruct ()
152
214
{
215
+ next_token ();
216
+ }
217
+
218
+ void verilog_indexer_parsert::rDeclaration ()
219
+ {
220
+ next_token ();
221
+ }
222
+
223
+ void verilog_indexer_parsert::rTaskFunction ()
224
+ {
225
+ next_token ();
226
+ }
227
+
228
+ void verilog_indexer_parsert::rContinuousAssign ()
229
+ {
230
+ next_token ();
231
+ }
232
+
233
+ void verilog_indexer_parsert::rGenerate ()
234
+ {
235
+ next_token ();
236
+ }
237
+
238
+ void verilog_indexer_parsert::rModuleInstance ()
239
+ {
240
+ next_token ();
241
+ }
242
+
243
+ std::vector<std::filesystem::path> verilog_files () {
153
244
std::vector<std::filesystem::path> result;
154
245
155
246
auto current = std::filesystem::current_path ();
0 commit comments