verific: Fix conditions of SVAs with explicit clocks within procedures
[yosys.git] / frontends / verific / verific.cc
1 /*
2 * yosys -- Yosys Open SYnthesis Suite
3 *
4 * Copyright (C) 2012 Claire Xenia Wolf <claire@yosyshq.com>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 */
19
20 #include "kernel/yosys.h"
21 #include "kernel/sigtools.h"
22 #include "kernel/celltypes.h"
23 #include "kernel/log.h"
24 #include "libs/sha1/sha1.h"
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28
29 #ifndef _WIN32
30 # include <unistd.h>
31 # include <dirent.h>
32 #endif
33
34 #include "frontends/verific/verific.h"
35
36 USING_YOSYS_NAMESPACE
37
38 #ifdef YOSYS_ENABLE_VERIFIC
39
40 #ifdef __clang__
41 #pragma clang diagnostic push
42 #pragma clang diagnostic ignored "-Woverloaded-virtual"
43 #endif
44
45 #include "veri_file.h"
46 #include "hier_tree.h"
47 #include "VeriModule.h"
48 #include "VeriWrite.h"
49 #include "VeriLibrary.h"
50
51 #ifdef VERIFIC_VHDL_SUPPORT
52 #include "vhdl_file.h"
53 #include "VhdlUnits.h"
54 #endif
55
56 #ifdef YOSYSHQ_VERIFIC_EXTENSIONS
57 #include "InitialAssertions.h"
58 #endif
59
60 #ifndef YOSYSHQ_VERIFIC_API_VERSION
61 # error "Only YosysHQ flavored Verific is supported. Please contact office@yosyshq.com for commercial support for Yosys+Verific."
62 #endif
63
64 #if YOSYSHQ_VERIFIC_API_VERSION < 20210801
65 # error "Please update your version of YosysHQ flavored Verific."
66 #endif
67
68 #ifdef __clang__
69 #pragma clang diagnostic pop
70 #endif
71
72 #ifdef VERIFIC_NAMESPACE
73 using namespace Verific;
74 #endif
75
76 #endif
77
78 #ifdef YOSYS_ENABLE_VERIFIC
79 YOSYS_NAMESPACE_BEGIN
80
81 int verific_verbose;
82 bool verific_import_pending;
83 string verific_error_msg;
84 int verific_sva_fsm_limit;
85
86 vector<string> verific_incdirs, verific_libdirs;
87
88 void msg_func(msg_type_t msg_type, const char *message_id, linefile_type linefile, const char *msg, va_list args)
89 {
90 string message_prefix = stringf("VERIFIC-%s [%s] ",
91 msg_type == VERIFIC_NONE ? "NONE" :
92 msg_type == VERIFIC_ERROR ? "ERROR" :
93 msg_type == VERIFIC_WARNING ? "WARNING" :
94 msg_type == VERIFIC_IGNORE ? "IGNORE" :
95 msg_type == VERIFIC_INFO ? "INFO" :
96 msg_type == VERIFIC_COMMENT ? "COMMENT" :
97 msg_type == VERIFIC_PROGRAM_ERROR ? "PROGRAM_ERROR" : "UNKNOWN", message_id);
98
99 string message = linefile ? stringf("%s:%d: ", LineFile::GetFileName(linefile), LineFile::GetLineNo(linefile)) : "";
100 message += vstringf(msg, args);
101
102 if (msg_type == VERIFIC_ERROR || msg_type == VERIFIC_WARNING || msg_type == VERIFIC_PROGRAM_ERROR)
103 log_warning_noprefix("%s%s\n", message_prefix.c_str(), message.c_str());
104 else
105 log("%s%s\n", message_prefix.c_str(), message.c_str());
106
107 if (verific_error_msg.empty() && (msg_type == VERIFIC_ERROR || msg_type == VERIFIC_PROGRAM_ERROR))
108 verific_error_msg = message;
109 }
110
111 string get_full_netlist_name(Netlist *nl)
112 {
113 if (nl->NumOfRefs() == 1) {
114 Instance *inst = (Instance*)nl->GetReferences()->GetLast();
115 return get_full_netlist_name(inst->Owner()) + "." + inst->Name();
116 }
117
118 return nl->CellBaseName();
119 }
120
121 // ==================================================================
122
123 VerificImporter::VerificImporter(bool mode_gates, bool mode_keep, bool mode_nosva, bool mode_names, bool mode_verific, bool mode_autocover, bool mode_fullinit) :
124 mode_gates(mode_gates), mode_keep(mode_keep), mode_nosva(mode_nosva),
125 mode_names(mode_names), mode_verific(mode_verific), mode_autocover(mode_autocover),
126 mode_fullinit(mode_fullinit)
127 {
128 }
129
130 RTLIL::SigBit VerificImporter::net_map_at(Net *net)
131 {
132 if (net->IsExternalTo(netlist))
133 log_error("Found external reference to '%s.%s' in netlist '%s', please use -flatten or -extnets.\n",
134 get_full_netlist_name(net->Owner()).c_str(), net->Name(), get_full_netlist_name(netlist).c_str());
135
136 return net_map.at(net);
137 }
138
139 bool is_blackbox(Netlist *nl)
140 {
141 if (nl->IsBlackBox() || nl->IsEmptyBox())
142 return true;
143
144 const char *attr = nl->GetAttValue("blackbox");
145 if (attr != nullptr && strcmp(attr, "0"))
146 return true;
147
148 return false;
149 }
150
151 RTLIL::IdString VerificImporter::new_verific_id(Verific::DesignObj *obj)
152 {
153 std::string s = stringf("$verific$%s", obj->Name());
154 if (obj->Linefile())
155 s += stringf("$%s:%d", Verific::LineFile::GetFileName(obj->Linefile()), Verific::LineFile::GetLineNo(obj->Linefile()));
156 s += stringf("$%d", autoidx++);
157 return s;
158 }
159
160 void VerificImporter::import_attributes(dict<RTLIL::IdString, RTLIL::Const> &attributes, DesignObj *obj, Netlist *nl)
161 {
162 MapIter mi;
163 Att *attr;
164
165 if (obj->Linefile())
166 attributes[ID::src] = stringf("%s:%d", LineFile::GetFileName(obj->Linefile()), LineFile::GetLineNo(obj->Linefile()));
167
168 // FIXME: Parse numeric attributes
169 FOREACH_ATTRIBUTE(obj, mi, attr) {
170 if (attr->Key()[0] == ' ' || attr->Value() == nullptr)
171 continue;
172 std::string val = std::string(attr->Value());
173 if (val.size()>1 && val[0]=='\"' && val.back()=='\"')
174 val = val.substr(1,val.size()-2);
175 attributes[RTLIL::escape_id(attr->Key())] = RTLIL::Const(val);
176 }
177
178 if (nl) {
179 auto type_range = nl->GetTypeRange(obj->Name());
180 if (!type_range)
181 return;
182 if (!type_range->IsTypeEnum())
183 return;
184 #ifdef VERIFIC_VHDL_SUPPORT
185 if (nl->IsFromVhdl() && strcmp(type_range->GetTypeName(), "STD_LOGIC") == 0)
186 return;
187 #endif
188 auto type_name = type_range->GetTypeName();
189 if (!type_name)
190 return;
191 attributes.emplace(ID::wiretype, RTLIL::escape_id(type_name));
192
193 MapIter mi;
194 const char *k, *v;
195 FOREACH_MAP_ITEM(type_range->GetEnumIdMap(), mi, &k, &v) {
196 if (nl->IsFromVerilog()) {
197 // Expect <decimal>'b<binary>
198 auto p = strchr(v, '\'');
199 if (p) {
200 if (*(p+1) != 'b')
201 p = nullptr;
202 else
203 for (auto q = p+2; *q != '\0'; q++)
204 if (*q != '0' && *q != '1' && *q != 'x' && *q != 'z') {
205 p = nullptr;
206 break;
207 }
208 }
209 if (p == nullptr)
210 log_error("Expected TypeRange value '%s' to be of form <decimal>'b<binary>.\n", v);
211 attributes.emplace(stringf("\\enum_value_%s", p+2), RTLIL::escape_id(k));
212 }
213 #ifdef VERIFIC_VHDL_SUPPORT
214 else if (nl->IsFromVhdl()) {
215 // Expect "<binary>" or plain <binary>
216 auto p = v;
217 if (p) {
218 if (*p != '"') {
219 auto l = strlen(p);
220 auto q = (char*)malloc(l+1);
221 strncpy(q, p, l);
222 q[l] = '\0';
223 for(char *ptr = q; *ptr; ++ptr )*ptr = tolower(*ptr);
224 attributes.emplace(stringf("\\enum_value_%s", q), RTLIL::escape_id(k));
225 } else {
226 auto *q = p+1;
227 for (; *q != '"'; q++)
228 if (*q != '0' && *q != '1') {
229 p = nullptr;
230 break;
231 }
232 if (p && *(q+1) != '\0')
233 p = nullptr;
234
235 if (p != nullptr)
236 {
237 auto l = strlen(p);
238 auto q = (char*)malloc(l+1-2);
239 strncpy(q, p+1, l-2);
240 q[l-2] = '\0';
241 attributes.emplace(stringf("\\enum_value_%s", q), RTLIL::escape_id(k));
242 free(q);
243 }
244 }
245 }
246 if (p == nullptr)
247 log_error("Expected TypeRange value '%s' to be of form \"<binary>\" or <binary>.\n", v);
248 }
249 #endif
250 }
251 }
252 }
253
254 RTLIL::SigSpec VerificImporter::operatorInput(Instance *inst)
255 {
256 RTLIL::SigSpec sig;
257 for (int i = int(inst->InputSize())-1; i >= 0; i--)
258 if (inst->GetInputBit(i))
259 sig.append(net_map_at(inst->GetInputBit(i)));
260 else
261 sig.append(RTLIL::State::Sz);
262 return sig;
263 }
264
265 RTLIL::SigSpec VerificImporter::operatorInput1(Instance *inst)
266 {
267 RTLIL::SigSpec sig;
268 for (int i = int(inst->Input1Size())-1; i >= 0; i--)
269 if (inst->GetInput1Bit(i))
270 sig.append(net_map_at(inst->GetInput1Bit(i)));
271 else
272 sig.append(RTLIL::State::Sz);
273 return sig;
274 }
275
276 RTLIL::SigSpec VerificImporter::operatorInput2(Instance *inst)
277 {
278 RTLIL::SigSpec sig;
279 for (int i = int(inst->Input2Size())-1; i >= 0; i--)
280 if (inst->GetInput2Bit(i))
281 sig.append(net_map_at(inst->GetInput2Bit(i)));
282 else
283 sig.append(RTLIL::State::Sz);
284 return sig;
285 }
286
287 RTLIL::SigSpec VerificImporter::operatorInport(Instance *inst, const char *portname)
288 {
289 PortBus *portbus = inst->View()->GetPortBus(portname);
290 if (portbus) {
291 RTLIL::SigSpec sig;
292 for (unsigned i = 0; i < portbus->Size(); i++) {
293 Net *net = inst->GetNet(portbus->ElementAtIndex(i));
294 if (net) {
295 if (net->IsGnd())
296 sig.append(RTLIL::State::S0);
297 else if (net->IsPwr())
298 sig.append(RTLIL::State::S1);
299 else
300 sig.append(net_map_at(net));
301 } else
302 sig.append(RTLIL::State::Sz);
303 }
304 return sig;
305 } else {
306 Port *port = inst->View()->GetPort(portname);
307 log_assert(port != NULL);
308 Net *net = inst->GetNet(port);
309 return net_map_at(net);
310 }
311 }
312
313 RTLIL::SigSpec VerificImporter::operatorOutput(Instance *inst, const pool<Net*, hash_ptr_ops> *any_all_nets)
314 {
315 RTLIL::SigSpec sig;
316 RTLIL::Wire *dummy_wire = NULL;
317 for (int i = int(inst->OutputSize())-1; i >= 0; i--)
318 if (inst->GetOutputBit(i) && (!any_all_nets || !any_all_nets->count(inst->GetOutputBit(i)))) {
319 sig.append(net_map_at(inst->GetOutputBit(i)));
320 dummy_wire = NULL;
321 } else {
322 if (dummy_wire == NULL)
323 dummy_wire = module->addWire(new_verific_id(inst));
324 else
325 dummy_wire->width++;
326 sig.append(RTLIL::SigSpec(dummy_wire, dummy_wire->width - 1));
327 }
328 return sig;
329 }
330
331 bool VerificImporter::import_netlist_instance_gates(Instance *inst, RTLIL::IdString inst_name)
332 {
333 if (inst->Type() == PRIM_AND) {
334 module->addAndGate(inst_name, net_map_at(inst->GetInput1()), net_map_at(inst->GetInput2()), net_map_at(inst->GetOutput()));
335 return true;
336 }
337
338 if (inst->Type() == PRIM_NAND) {
339 RTLIL::SigSpec tmp = module->addWire(new_verific_id(inst));
340 module->addAndGate(new_verific_id(inst), net_map_at(inst->GetInput1()), net_map_at(inst->GetInput2()), tmp);
341 module->addNotGate(inst_name, tmp, net_map_at(inst->GetOutput()));
342 return true;
343 }
344
345 if (inst->Type() == PRIM_OR) {
346 module->addOrGate(inst_name, net_map_at(inst->GetInput1()), net_map_at(inst->GetInput2()), net_map_at(inst->GetOutput()));
347 return true;
348 }
349
350 if (inst->Type() == PRIM_NOR) {
351 RTLIL::SigSpec tmp = module->addWire(new_verific_id(inst));
352 module->addOrGate(new_verific_id(inst), net_map_at(inst->GetInput1()), net_map_at(inst->GetInput2()), tmp);
353 module->addNotGate(inst_name, tmp, net_map_at(inst->GetOutput()));
354 return true;
355 }
356
357 if (inst->Type() == PRIM_XOR) {
358 module->addXorGate(inst_name, net_map_at(inst->GetInput1()), net_map_at(inst->GetInput2()), net_map_at(inst->GetOutput()));
359 return true;
360 }
361
362 if (inst->Type() == PRIM_XNOR) {
363 module->addXnorGate(inst_name, net_map_at(inst->GetInput1()), net_map_at(inst->GetInput2()), net_map_at(inst->GetOutput()));
364 return true;
365 }
366
367 if (inst->Type() == PRIM_BUF) {
368 auto outnet = inst->GetOutput();
369 if (!any_all_nets.count(outnet))
370 module->addBufGate(inst_name, net_map_at(inst->GetInput()), net_map_at(outnet));
371 return true;
372 }
373
374 if (inst->Type() == PRIM_INV) {
375 module->addNotGate(inst_name, net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
376 return true;
377 }
378
379 if (inst->Type() == PRIM_MUX) {
380 module->addMuxGate(inst_name, net_map_at(inst->GetInput1()), net_map_at(inst->GetInput2()), net_map_at(inst->GetControl()), net_map_at(inst->GetOutput()));
381 return true;
382 }
383
384 if ((inst->Type() == PRIM_TRI) || (inst->Type() == PRIM_BUFIF1)) {
385 module->addMuxGate(inst_name, RTLIL::State::Sz, net_map_at(inst->GetInput()), net_map_at(inst->GetControl()), net_map_at(inst->GetOutput()));
386 return true;
387 }
388
389 if (inst->Type() == PRIM_FADD)
390 {
391 RTLIL::SigSpec a = net_map_at(inst->GetInput1()), b = net_map_at(inst->GetInput2()), c = net_map_at(inst->GetCin());
392 RTLIL::SigSpec x = inst->GetCout() ? net_map_at(inst->GetCout()) : module->addWire(new_verific_id(inst));
393 RTLIL::SigSpec y = inst->GetOutput() ? net_map_at(inst->GetOutput()) : module->addWire(new_verific_id(inst));
394 RTLIL::SigSpec tmp1 = module->addWire(new_verific_id(inst));
395 RTLIL::SigSpec tmp2 = module->addWire(new_verific_id(inst));
396 RTLIL::SigSpec tmp3 = module->addWire(new_verific_id(inst));
397 module->addXorGate(new_verific_id(inst), a, b, tmp1);
398 module->addXorGate(inst_name, tmp1, c, y);
399 module->addAndGate(new_verific_id(inst), tmp1, c, tmp2);
400 module->addAndGate(new_verific_id(inst), a, b, tmp3);
401 module->addOrGate(new_verific_id(inst), tmp2, tmp3, x);
402 return true;
403 }
404
405 if (inst->Type() == PRIM_DFFRS)
406 {
407 VerificClocking clocking(this, inst->GetClock());
408 log_assert(clocking.disable_sig == State::S0);
409 log_assert(clocking.body_net == nullptr);
410
411 if (inst->GetSet()->IsGnd() && inst->GetReset()->IsGnd())
412 clocking.addDff(inst_name, net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
413 else if (inst->GetSet()->IsGnd())
414 clocking.addAdff(inst_name, net_map_at(inst->GetReset()), net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()), State::S0);
415 else if (inst->GetReset()->IsGnd())
416 clocking.addAdff(inst_name, net_map_at(inst->GetSet()), net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()), State::S1);
417 else
418 clocking.addDffsr(inst_name, net_map_at(inst->GetSet()), net_map_at(inst->GetReset()),
419 net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
420 return true;
421 }
422
423 if (inst->Type() == PRIM_DLATCHRS)
424 {
425 if (inst->GetSet()->IsGnd() && inst->GetReset()->IsGnd())
426 module->addDlatch(inst_name, net_map_at(inst->GetControl()), net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
427 else
428 module->addDlatchsr(inst_name, net_map_at(inst->GetControl()), net_map_at(inst->GetSet()), net_map_at(inst->GetReset()),
429 net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
430 return true;
431 }
432
433 if (inst->Type() == PRIM_DFF)
434 {
435 VerificClocking clocking(this, inst->GetClock());
436 log_assert(clocking.disable_sig == State::S0);
437 log_assert(clocking.body_net == nullptr);
438
439 if (inst->GetAsyncCond()->IsGnd())
440 clocking.addDff(inst_name, net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
441 else
442 clocking.addAldff(inst_name, net_map_at(inst->GetAsyncCond()), net_map_at(inst->GetAsyncVal()),
443 net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
444 return true;
445 }
446
447 if (inst->Type() == PRIM_DLATCH)
448 {
449 if (inst->GetAsyncCond()->IsGnd()) {
450 module->addDlatch(inst_name, net_map_at(inst->GetControl()), net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
451 } else {
452 RTLIL::SigSpec sig_set = module->And(NEW_ID, net_map_at(inst->GetAsyncCond()), net_map_at(inst->GetAsyncVal()));
453 RTLIL::SigSpec sig_clr = module->And(NEW_ID, net_map_at(inst->GetAsyncCond()), module->Not(NEW_ID, net_map_at(inst->GetAsyncVal())));
454 module->addDlatchsr(inst_name, net_map_at(inst->GetControl()), sig_set, sig_clr, net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
455 }
456 return true;
457 }
458
459 return false;
460 }
461
462 bool VerificImporter::import_netlist_instance_cells(Instance *inst, RTLIL::IdString inst_name)
463 {
464 RTLIL::Cell *cell = nullptr;
465
466 if (inst->Type() == PRIM_AND) {
467 cell = module->addAnd(inst_name, net_map_at(inst->GetInput1()), net_map_at(inst->GetInput2()), net_map_at(inst->GetOutput()));
468 import_attributes(cell->attributes, inst);
469 return true;
470 }
471
472 if (inst->Type() == PRIM_NAND) {
473 RTLIL::SigSpec tmp = module->addWire(new_verific_id(inst));
474 cell = module->addAnd(new_verific_id(inst), net_map_at(inst->GetInput1()), net_map_at(inst->GetInput2()), tmp);
475 import_attributes(cell->attributes, inst);
476 cell = module->addNot(inst_name, tmp, net_map_at(inst->GetOutput()));
477 import_attributes(cell->attributes, inst);
478 return true;
479 }
480
481 if (inst->Type() == PRIM_OR) {
482 cell = module->addOr(inst_name, net_map_at(inst->GetInput1()), net_map_at(inst->GetInput2()), net_map_at(inst->GetOutput()));
483 import_attributes(cell->attributes, inst);
484 return true;
485 }
486
487 if (inst->Type() == PRIM_NOR) {
488 RTLIL::SigSpec tmp = module->addWire(new_verific_id(inst));
489 cell = module->addOr(new_verific_id(inst), net_map_at(inst->GetInput1()), net_map_at(inst->GetInput2()), tmp);
490 import_attributes(cell->attributes, inst);
491 cell = module->addNot(inst_name, tmp, net_map_at(inst->GetOutput()));
492 import_attributes(cell->attributes, inst);
493 return true;
494 }
495
496 if (inst->Type() == PRIM_XOR) {
497 cell = module->addXor(inst_name, net_map_at(inst->GetInput1()), net_map_at(inst->GetInput2()), net_map_at(inst->GetOutput()));
498 import_attributes(cell->attributes, inst);
499 return true;
500 }
501
502 if (inst->Type() == PRIM_XNOR) {
503 cell = module->addXnor(inst_name, net_map_at(inst->GetInput1()), net_map_at(inst->GetInput2()), net_map_at(inst->GetOutput()));
504 import_attributes(cell->attributes, inst);
505 return true;
506 }
507
508 if (inst->Type() == PRIM_INV) {
509 cell = module->addNot(inst_name, net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
510 import_attributes(cell->attributes, inst);
511 return true;
512 }
513
514 if (inst->Type() == PRIM_MUX) {
515 cell = module->addMux(inst_name, net_map_at(inst->GetInput1()), net_map_at(inst->GetInput2()), net_map_at(inst->GetControl()), net_map_at(inst->GetOutput()));
516 import_attributes(cell->attributes, inst);
517 return true;
518 }
519
520 if ((inst->Type() == PRIM_TRI) || (inst->Type() == PRIM_BUFIF1)) {
521 cell = module->addMux(inst_name, RTLIL::State::Sz, net_map_at(inst->GetInput()), net_map_at(inst->GetControl()), net_map_at(inst->GetOutput()));
522 import_attributes(cell->attributes, inst);
523 return true;
524 }
525
526 if (inst->Type() == PRIM_FADD)
527 {
528 RTLIL::SigSpec a_plus_b = module->addWire(new_verific_id(inst), 2);
529 RTLIL::SigSpec y = inst->GetOutput() ? net_map_at(inst->GetOutput()) : module->addWire(new_verific_id(inst));
530 if (inst->GetCout())
531 y.append(net_map_at(inst->GetCout()));
532 cell = module->addAdd(new_verific_id(inst), net_map_at(inst->GetInput1()), net_map_at(inst->GetInput2()), a_plus_b);
533 import_attributes(cell->attributes, inst);
534 cell = module->addAdd(inst_name, a_plus_b, net_map_at(inst->GetCin()), y);
535 import_attributes(cell->attributes, inst);
536 return true;
537 }
538
539 if (inst->Type() == PRIM_DFFRS)
540 {
541 VerificClocking clocking(this, inst->GetClock());
542 log_assert(clocking.disable_sig == State::S0);
543 log_assert(clocking.body_net == nullptr);
544
545 if (inst->GetSet()->IsGnd() && inst->GetReset()->IsGnd())
546 cell = clocking.addDff(inst_name, net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
547 else if (inst->GetSet()->IsGnd())
548 cell = clocking.addAdff(inst_name, net_map_at(inst->GetReset()), net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()), RTLIL::State::S0);
549 else if (inst->GetReset()->IsGnd())
550 cell = clocking.addAdff(inst_name, net_map_at(inst->GetSet()), net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()), RTLIL::State::S1);
551 else
552 cell = clocking.addDffsr(inst_name, net_map_at(inst->GetSet()), net_map_at(inst->GetReset()),
553 net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
554 import_attributes(cell->attributes, inst);
555 return true;
556 }
557
558 if (inst->Type() == PRIM_DLATCHRS)
559 {
560 if (inst->GetSet()->IsGnd() && inst->GetReset()->IsGnd())
561 cell = module->addDlatch(inst_name, net_map_at(inst->GetControl()), net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
562 else
563 cell = module->addDlatchsr(inst_name, net_map_at(inst->GetControl()), net_map_at(inst->GetSet()), net_map_at(inst->GetReset()),
564 net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
565 import_attributes(cell->attributes, inst);
566 return true;
567 }
568
569 if (inst->Type() == PRIM_DFF)
570 {
571 VerificClocking clocking(this, inst->GetClock());
572 log_assert(clocking.disable_sig == State::S0);
573 log_assert(clocking.body_net == nullptr);
574
575 if (inst->GetAsyncCond()->IsGnd())
576 cell = clocking.addDff(inst_name, net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
577 else
578 cell = clocking.addAldff(inst_name, net_map_at(inst->GetAsyncCond()), net_map_at(inst->GetAsyncVal()),
579 net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
580 import_attributes(cell->attributes, inst);
581 return true;
582 }
583
584 if (inst->Type() == PRIM_DLATCH)
585 {
586 if (inst->GetAsyncCond()->IsGnd()) {
587 cell = module->addDlatch(inst_name, net_map_at(inst->GetControl()), net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
588 } else {
589 RTLIL::SigSpec sig_set = module->And(NEW_ID, net_map_at(inst->GetAsyncCond()), net_map_at(inst->GetAsyncVal()));
590 RTLIL::SigSpec sig_clr = module->And(NEW_ID, net_map_at(inst->GetAsyncCond()), module->Not(NEW_ID, net_map_at(inst->GetAsyncVal())));
591 cell = module->addDlatchsr(inst_name, net_map_at(inst->GetControl()), sig_set, sig_clr, net_map_at(inst->GetInput()), net_map_at(inst->GetOutput()));
592 }
593 import_attributes(cell->attributes, inst);
594 return true;
595 }
596
597 #define IN operatorInput(inst)
598 #define IN1 operatorInput1(inst)
599 #define IN2 operatorInput2(inst)
600 #define OUT operatorOutput(inst)
601 #define FILTERED_OUT operatorOutput(inst, &any_all_nets)
602 #define SIGNED inst->View()->IsSigned()
603
604 if (inst->Type() == OPER_ADDER) {
605 RTLIL::SigSpec out = OUT;
606 if (inst->GetCout() != NULL)
607 out.append(net_map_at(inst->GetCout()));
608 if (inst->GetCin()->IsGnd()) {
609 cell = module->addAdd(inst_name, IN1, IN2, out, SIGNED);
610 import_attributes(cell->attributes, inst);
611 } else {
612 RTLIL::SigSpec tmp = module->addWire(new_verific_id(inst), GetSize(out));
613 cell = module->addAdd(new_verific_id(inst), IN1, IN2, tmp, SIGNED);
614 import_attributes(cell->attributes, inst);
615 cell = module->addAdd(inst_name, tmp, net_map_at(inst->GetCin()), out, false);
616 import_attributes(cell->attributes, inst);
617 }
618 return true;
619 }
620
621 if (inst->Type() == OPER_MULTIPLIER) {
622 cell = module->addMul(inst_name, IN1, IN2, OUT, SIGNED);
623 import_attributes(cell->attributes, inst);
624 return true;
625 }
626
627 if (inst->Type() == OPER_DIVIDER) {
628 cell = module->addDiv(inst_name, IN1, IN2, OUT, SIGNED);
629 import_attributes(cell->attributes, inst);
630 return true;
631 }
632
633 if (inst->Type() == OPER_MODULO) {
634 cell = module->addMod(inst_name, IN1, IN2, OUT, SIGNED);
635 import_attributes(cell->attributes, inst);
636 return true;
637 }
638
639 if (inst->Type() == OPER_REMAINDER) {
640 cell = module->addMod(inst_name, IN1, IN2, OUT, SIGNED);
641 import_attributes(cell->attributes, inst);
642 return true;
643 }
644
645 if (inst->Type() == OPER_SHIFT_LEFT) {
646 cell = module->addShl(inst_name, IN1, IN2, OUT, false);
647 import_attributes(cell->attributes, inst);
648 return true;
649 }
650
651 if (inst->Type() == OPER_ENABLED_DECODER) {
652 RTLIL::SigSpec vec;
653 vec.append(net_map_at(inst->GetControl()));
654 for (unsigned i = 1; i < inst->OutputSize(); i++) {
655 vec.append(RTLIL::State::S0);
656 }
657 cell = module->addShl(inst_name, vec, IN, OUT, false);
658 import_attributes(cell->attributes, inst);
659 return true;
660 }
661
662 if (inst->Type() == OPER_DECODER) {
663 RTLIL::SigSpec vec;
664 vec.append(RTLIL::State::S1);
665 for (unsigned i = 1; i < inst->OutputSize(); i++) {
666 vec.append(RTLIL::State::S0);
667 }
668 cell = module->addShl(inst_name, vec, IN, OUT, false);
669 import_attributes(cell->attributes, inst);
670 return true;
671 }
672
673 if (inst->Type() == OPER_SHIFT_RIGHT) {
674 Net *net_cin = inst->GetCin();
675 Net *net_a_msb = inst->GetInput1Bit(0);
676 if (net_cin->IsGnd())
677 cell = module->addShr(inst_name, IN1, IN2, OUT, false);
678 else if (net_cin == net_a_msb)
679 cell = module->addSshr(inst_name, IN1, IN2, OUT, true);
680 else
681 log_error("Can't import Verific OPER_SHIFT_RIGHT instance %s: carry_in is neither 0 nor msb of left input\n", inst->Name());
682 import_attributes(cell->attributes, inst);
683 return true;
684 }
685
686 if (inst->Type() == OPER_REDUCE_AND) {
687 cell = module->addReduceAnd(inst_name, IN, net_map_at(inst->GetOutput()), SIGNED);
688 import_attributes(cell->attributes, inst);
689 return true;
690 }
691
692 if (inst->Type() == OPER_REDUCE_NAND) {
693 Wire *tmp = module->addWire(NEW_ID);
694 cell = module->addReduceAnd(inst_name, IN, tmp, SIGNED);
695 module->addNot(NEW_ID, tmp, net_map_at(inst->GetOutput()));
696 import_attributes(cell->attributes, inst);
697 return true;
698 }
699
700 if (inst->Type() == OPER_REDUCE_OR) {
701 cell = module->addReduceOr(inst_name, IN, net_map_at(inst->GetOutput()), SIGNED);
702 import_attributes(cell->attributes, inst);
703 return true;
704 }
705
706 if (inst->Type() == OPER_REDUCE_XOR) {
707 cell = module->addReduceXor(inst_name, IN, net_map_at(inst->GetOutput()), SIGNED);
708 import_attributes(cell->attributes, inst);
709 return true;
710 }
711
712 if (inst->Type() == OPER_REDUCE_XNOR) {
713 cell = module->addReduceXnor(inst_name, IN, net_map_at(inst->GetOutput()), SIGNED);
714 import_attributes(cell->attributes, inst);
715 return true;
716 }
717
718 if (inst->Type() == OPER_REDUCE_NOR) {
719 SigSpec t = module->ReduceOr(new_verific_id(inst), IN, SIGNED);
720 cell = module->addNot(inst_name, t, net_map_at(inst->GetOutput()));
721 import_attributes(cell->attributes, inst);
722 return true;
723 }
724
725 if (inst->Type() == OPER_LESSTHAN) {
726 Net *net_cin = inst->GetCin();
727 if (net_cin->IsGnd())
728 cell = module->addLt(inst_name, IN1, IN2, net_map_at(inst->GetOutput()), SIGNED);
729 else if (net_cin->IsPwr())
730 cell = module->addLe(inst_name, IN1, IN2, net_map_at(inst->GetOutput()), SIGNED);
731 else
732 log_error("Can't import Verific OPER_LESSTHAN instance %s: carry_in is neither 0 nor 1\n", inst->Name());
733 import_attributes(cell->attributes, inst);
734 return true;
735 }
736
737 if (inst->Type() == OPER_WIDE_AND) {
738 cell = module->addAnd(inst_name, IN1, IN2, OUT, SIGNED);
739 import_attributes(cell->attributes, inst);
740 return true;
741 }
742
743 if (inst->Type() == OPER_WIDE_OR) {
744 cell = module->addOr(inst_name, IN1, IN2, OUT, SIGNED);
745 import_attributes(cell->attributes, inst);
746 return true;
747 }
748
749 if (inst->Type() == OPER_WIDE_XOR) {
750 cell = module->addXor(inst_name, IN1, IN2, OUT, SIGNED);
751 import_attributes(cell->attributes, inst);
752 return true;
753 }
754
755 if (inst->Type() == OPER_WIDE_XNOR) {
756 cell = module->addXnor(inst_name, IN1, IN2, OUT, SIGNED);
757 import_attributes(cell->attributes, inst);
758 return true;
759 }
760
761 if (inst->Type() == OPER_WIDE_BUF) {
762 cell = module->addPos(inst_name, IN, FILTERED_OUT, SIGNED);
763 import_attributes(cell->attributes, inst);
764 return true;
765 }
766
767 if (inst->Type() == OPER_WIDE_INV) {
768 cell = module->addNot(inst_name, IN, OUT, SIGNED);
769 import_attributes(cell->attributes, inst);
770 return true;
771 }
772
773 if (inst->Type() == OPER_MINUS) {
774 cell = module->addSub(inst_name, IN1, IN2, OUT, SIGNED);
775 import_attributes(cell->attributes, inst);
776 return true;
777 }
778
779 if (inst->Type() == OPER_UMINUS) {
780 cell = module->addNeg(inst_name, IN, OUT, SIGNED);
781 import_attributes(cell->attributes, inst);
782 return true;
783 }
784
785 if (inst->Type() == OPER_EQUAL) {
786 cell = module->addEq(inst_name, IN1, IN2, net_map_at(inst->GetOutput()), SIGNED);
787 import_attributes(cell->attributes, inst);
788 return true;
789 }
790
791 if (inst->Type() == OPER_NEQUAL) {
792 cell = module->addNe(inst_name, IN1, IN2, net_map_at(inst->GetOutput()), SIGNED);
793 import_attributes(cell->attributes, inst);
794 return true;
795 }
796
797 if (inst->Type() == OPER_WIDE_MUX) {
798 cell = module->addMux(inst_name, IN1, IN2, net_map_at(inst->GetControl()), OUT);
799 import_attributes(cell->attributes, inst);
800 return true;
801 }
802
803 if (inst->Type() == OPER_NTO1MUX) {
804 cell = module->addBmux(inst_name, IN2, IN1, net_map_at(inst->GetOutput()));
805 import_attributes(cell->attributes, inst);
806 return true;
807 }
808
809 if (inst->Type() == OPER_WIDE_NTO1MUX)
810 {
811 cell = module->addBmux(inst_name, IN2, IN1, OUT);
812 import_attributes(cell->attributes, inst);
813 return true;
814 }
815
816 if (inst->Type() == OPER_SELECTOR)
817 {
818 cell = module->addPmux(inst_name, State::S0, IN2, IN1, net_map_at(inst->GetOutput()));
819 import_attributes(cell->attributes, inst);
820 return true;
821 }
822
823 if (inst->Type() == OPER_WIDE_SELECTOR)
824 {
825 SigSpec out = OUT;
826 cell = module->addPmux(inst_name, SigSpec(State::S0, GetSize(out)), IN2, IN1, out);
827 import_attributes(cell->attributes, inst);
828 return true;
829 }
830
831 if (inst->Type() == OPER_WIDE_TRI) {
832 cell = module->addMux(inst_name, RTLIL::SigSpec(RTLIL::State::Sz, inst->OutputSize()), IN, net_map_at(inst->GetControl()), OUT);
833 import_attributes(cell->attributes, inst);
834 return true;
835 }
836
837 if (inst->Type() == OPER_WIDE_DFFRS)
838 {
839 VerificClocking clocking(this, inst->GetClock());
840 log_assert(clocking.disable_sig == State::S0);
841 log_assert(clocking.body_net == nullptr);
842
843 RTLIL::SigSpec sig_set = operatorInport(inst, "set");
844 RTLIL::SigSpec sig_reset = operatorInport(inst, "reset");
845
846 if (sig_set.is_fully_const() && !sig_set.as_bool() && sig_reset.is_fully_const() && !sig_reset.as_bool())
847 cell = clocking.addDff(inst_name, IN, OUT);
848 else
849 cell = clocking.addDffsr(inst_name, sig_set, sig_reset, IN, OUT);
850 import_attributes(cell->attributes, inst);
851
852 return true;
853 }
854
855 if (inst->Type() == OPER_WIDE_DLATCHRS)
856 {
857 RTLIL::SigSpec sig_set = operatorInport(inst, "set");
858 RTLIL::SigSpec sig_reset = operatorInport(inst, "reset");
859
860 if (sig_set.is_fully_const() && !sig_set.as_bool() && sig_reset.is_fully_const() && !sig_reset.as_bool())
861 cell = module->addDlatch(inst_name, net_map_at(inst->GetControl()), IN, OUT);
862 else
863 cell = module->addDlatchsr(inst_name, net_map_at(inst->GetControl()), sig_set, sig_reset, IN, OUT);
864 import_attributes(cell->attributes, inst);
865
866 return true;
867 }
868
869 if (inst->Type() == OPER_WIDE_DFF)
870 {
871 VerificClocking clocking(this, inst->GetClock());
872 log_assert(clocking.disable_sig == State::S0);
873 log_assert(clocking.body_net == nullptr);
874
875 RTLIL::SigSpec sig_d = IN;
876 RTLIL::SigSpec sig_q = OUT;
877 RTLIL::SigSpec sig_adata = IN1;
878 RTLIL::SigSpec sig_acond = IN2;
879
880 if (sig_acond.is_fully_const() && !sig_acond.as_bool()) {
881 cell = clocking.addDff(inst_name, sig_d, sig_q);
882 import_attributes(cell->attributes, inst);
883 } else {
884 int offset = 0, width = 0;
885 for (offset = 0; offset < GetSize(sig_acond); offset += width) {
886 for (width = 1; offset+width < GetSize(sig_acond); width++)
887 if (sig_acond[offset] != sig_acond[offset+width]) break;
888 cell = clocking.addAldff(module->uniquify(inst_name), sig_acond[offset], sig_adata.extract(offset, width),
889 sig_d.extract(offset, width), sig_q.extract(offset, width));
890 import_attributes(cell->attributes, inst);
891 }
892 }
893
894 return true;
895 }
896
897 if (inst->Type() == OPER_WIDE_DLATCH)
898 {
899 RTLIL::SigSpec sig_d = IN;
900 RTLIL::SigSpec sig_q = OUT;
901 RTLIL::SigSpec sig_adata = IN1;
902 RTLIL::SigSpec sig_acond = IN2;
903
904 if (sig_acond.is_fully_const() && !sig_acond.as_bool()) {
905 cell = module->addDlatch(inst_name, net_map_at(inst->GetControl()), sig_d, sig_q);
906 import_attributes(cell->attributes, inst);
907 } else {
908 int offset = 0, width = 0;
909 for (offset = 0; offset < GetSize(sig_acond); offset += width) {
910 for (width = 1; offset+width < GetSize(sig_acond); width++)
911 if (sig_acond[offset] != sig_acond[offset+width]) break;
912 RTLIL::SigSpec sig_set = module->Mux(NEW_ID, RTLIL::SigSpec(0, width), sig_adata.extract(offset, width), sig_acond[offset]);
913 RTLIL::SigSpec sig_clr = module->Mux(NEW_ID, RTLIL::SigSpec(0, width), module->Not(NEW_ID, sig_adata.extract(offset, width)), sig_acond[offset]);
914 cell = module->addDlatchsr(module->uniquify(inst_name), net_map_at(inst->GetControl()), sig_set, sig_clr,
915 sig_d.extract(offset, width), sig_q.extract(offset, width));
916 import_attributes(cell->attributes, inst);
917 }
918 }
919
920 return true;
921 }
922
923 #undef IN
924 #undef IN1
925 #undef IN2
926 #undef OUT
927 #undef SIGNED
928
929 return false;
930 }
931
932 void VerificImporter::merge_past_ffs_clock(pool<RTLIL::Cell*> &candidates, SigBit clock, bool clock_pol)
933 {
934 bool keep_running = true;
935 SigMap sigmap;
936
937 while (keep_running)
938 {
939 keep_running = false;
940
941 dict<SigBit, pool<RTLIL::Cell*>> dbits_db;
942 SigSpec dbits;
943
944 for (auto cell : candidates) {
945 SigBit bit = sigmap(cell->getPort(ID::D));
946 dbits_db[bit].insert(cell);
947 dbits.append(bit);
948 }
949
950 dbits.sort_and_unify();
951
952 for (auto chunk : dbits.chunks())
953 {
954 SigSpec sig_d = chunk;
955
956 if (chunk.wire == nullptr || GetSize(sig_d) == 1)
957 continue;
958
959 SigSpec sig_q = module->addWire(NEW_ID, GetSize(sig_d));
960 RTLIL::Cell *new_ff = module->addDff(NEW_ID, clock, sig_d, sig_q, clock_pol);
961
962 if (verific_verbose)
963 log(" merging single-bit past_ffs into new %d-bit ff %s.\n", GetSize(sig_d), log_id(new_ff));
964
965 for (int i = 0; i < GetSize(sig_d); i++)
966 for (auto old_ff : dbits_db[sig_d[i]])
967 {
968 if (verific_verbose)
969 log(" replacing old ff %s on bit %d.\n", log_id(old_ff), i);
970
971 SigBit old_q = old_ff->getPort(ID::Q);
972 SigBit new_q = sig_q[i];
973
974 sigmap.add(old_q, new_q);
975 module->connect(old_q, new_q);
976 candidates.erase(old_ff);
977 module->remove(old_ff);
978 keep_running = true;
979 }
980 }
981 }
982 }
983
984 void VerificImporter::merge_past_ffs(pool<RTLIL::Cell*> &candidates)
985 {
986 dict<pair<SigBit, int>, pool<RTLIL::Cell*>> database;
987
988 for (auto cell : candidates)
989 {
990 if (cell->type != ID($dff)) continue;
991 SigBit clock = cell->getPort(ID::CLK);
992 bool clock_pol = cell->getParam(ID::CLK_POLARITY).as_bool();
993 database[make_pair(clock, int(clock_pol))].insert(cell);
994 }
995
996 for (auto it : database)
997 merge_past_ffs_clock(it.second, it.first.first, it.first.second);
998 }
999
1000 static std::string sha1_if_contain_spaces(std::string str)
1001 {
1002 if(str.find_first_of(' ') != std::string::npos) {
1003 std::size_t open = str.find_first_of('(');
1004 std::size_t closed = str.find_last_of(')');
1005 if (open != std::string::npos && closed != std::string::npos) {
1006 std::string content = str.substr(open + 1, closed - open - 1);
1007 return str.substr(0, open + 1) + sha1(content) + str.substr(closed);
1008 } else {
1009 return sha1(str);
1010 }
1011 }
1012 return str;
1013 }
1014
1015 void VerificImporter::import_netlist(RTLIL::Design *design, Netlist *nl, std::map<std::string,Netlist*> &nl_todo, bool norename)
1016 {
1017 std::string netlist_name = nl->GetAtt(" \\top") ? nl->CellBaseName() : nl->Owner()->Name();
1018 std::string module_name = netlist_name;
1019
1020 if (nl->IsOperator() || nl->IsPrimitive()) {
1021 module_name = "$verific$" + module_name;
1022 } else {
1023 if (!norename && *nl->Name()) {
1024 module_name += "(";
1025 module_name += nl->Name();
1026 module_name += ")";
1027 }
1028 module_name = "\\" + sha1_if_contain_spaces(module_name);
1029 }
1030
1031 netlist = nl;
1032
1033 if (design->has(module_name)) {
1034 if (!nl->IsOperator() && !is_blackbox(nl))
1035 log_cmd_error("Re-definition of module `%s'.\n", netlist_name.c_str());
1036 return;
1037 }
1038
1039 module = new RTLIL::Module;
1040 module->name = module_name;
1041 design->add(module);
1042
1043 if (is_blackbox(nl)) {
1044 log("Importing blackbox module %s.\n", RTLIL::id2cstr(module->name));
1045 module->set_bool_attribute(ID::blackbox);
1046 } else {
1047 log("Importing module %s.\n", RTLIL::id2cstr(module->name));
1048 }
1049 import_attributes(module->attributes, nl, nl);
1050
1051 SetIter si;
1052 MapIter mi, mi2;
1053 Port *port;
1054 PortBus *portbus;
1055 Net *net;
1056 NetBus *netbus;
1057 Instance *inst;
1058 PortRef *pr;
1059
1060 FOREACH_PORT_OF_NETLIST(nl, mi, port)
1061 {
1062 if (port->Bus())
1063 continue;
1064
1065 if (verific_verbose)
1066 log(" importing port %s.\n", port->Name());
1067
1068 RTLIL::Wire *wire = module->addWire(RTLIL::escape_id(port->Name()));
1069 import_attributes(wire->attributes, port, nl);
1070
1071 wire->port_id = nl->IndexOf(port) + 1;
1072
1073 if (port->GetDir() == DIR_INOUT || port->GetDir() == DIR_IN)
1074 wire->port_input = true;
1075 if (port->GetDir() == DIR_INOUT || port->GetDir() == DIR_OUT)
1076 wire->port_output = true;
1077
1078 if (port->GetNet()) {
1079 net = port->GetNet();
1080 if (net_map.count(net) == 0)
1081 net_map[net] = wire;
1082 else if (wire->port_input)
1083 module->connect(net_map_at(net), wire);
1084 else
1085 module->connect(wire, net_map_at(net));
1086 }
1087 }
1088
1089 FOREACH_PORTBUS_OF_NETLIST(nl, mi, portbus)
1090 {
1091 if (verific_verbose)
1092 log(" importing portbus %s.\n", portbus->Name());
1093
1094 RTLIL::Wire *wire = module->addWire(RTLIL::escape_id(portbus->Name()), portbus->Size());
1095 wire->start_offset = min(portbus->LeftIndex(), portbus->RightIndex());
1096 import_attributes(wire->attributes, portbus, nl);
1097
1098 bool portbus_input = portbus->GetDir() == DIR_INOUT || portbus->GetDir() == DIR_IN;
1099 if (portbus_input)
1100 wire->port_input = true;
1101 if (portbus->GetDir() == DIR_INOUT || portbus->GetDir() == DIR_OUT)
1102 wire->port_output = true;
1103
1104 for (int i = portbus->LeftIndex();; i += portbus->IsUp() ? +1 : -1) {
1105 if (portbus->ElementAtIndex(i) && portbus->ElementAtIndex(i)->GetNet()) {
1106 bool bit_input = portbus_input;
1107 if (portbus->GetDir() == DIR_NONE) {
1108 Port *p = portbus->ElementAtIndex(i);
1109 bit_input = p->GetDir() == DIR_INOUT || p->GetDir() == DIR_IN;
1110 if (bit_input)
1111 wire->port_input = true;
1112 if (p->GetDir() == DIR_INOUT || p->GetDir() == DIR_OUT)
1113 wire->port_output = true;
1114 }
1115 net = portbus->ElementAtIndex(i)->GetNet();
1116 RTLIL::SigBit bit(wire, i - wire->start_offset);
1117 if (net_map.count(net) == 0)
1118 net_map[net] = bit;
1119 else if (bit_input)
1120 module->connect(net_map_at(net), bit);
1121 else
1122 module->connect(bit, net_map_at(net));
1123 }
1124 if (i == portbus->RightIndex())
1125 break;
1126 }
1127 }
1128
1129 module->fixup_ports();
1130
1131 dict<Net*, char, hash_ptr_ops> init_nets;
1132 pool<Net*, hash_ptr_ops> anyconst_nets, anyseq_nets;
1133 pool<Net*, hash_ptr_ops> allconst_nets, allseq_nets;
1134 any_all_nets.clear();
1135
1136 FOREACH_NET_OF_NETLIST(nl, mi, net)
1137 {
1138 if (net->IsRamNet())
1139 {
1140 RTLIL::Memory *memory = new RTLIL::Memory;
1141 memory->name = RTLIL::escape_id(net->Name());
1142 log_assert(module->count_id(memory->name) == 0);
1143 module->memories[memory->name] = memory;
1144
1145 int number_of_bits = net->Size();
1146 int bits_in_word = number_of_bits;
1147 FOREACH_PORTREF_OF_NET(net, si, pr) {
1148 if (pr->GetInst()->Type() == OPER_READ_PORT) {
1149 bits_in_word = min<int>(bits_in_word, pr->GetInst()->OutputSize());
1150 continue;
1151 }
1152 if (pr->GetInst()->Type() == OPER_WRITE_PORT || pr->GetInst()->Type() == OPER_CLOCKED_WRITE_PORT) {
1153 bits_in_word = min<int>(bits_in_word, pr->GetInst()->Input2Size());
1154 continue;
1155 }
1156 log_error("Verific RamNet %s is connected to unsupported instance type %s (%s).\n",
1157 net->Name(), pr->GetInst()->View()->Owner()->Name(), pr->GetInst()->Name());
1158 }
1159
1160 memory->width = bits_in_word;
1161 memory->size = number_of_bits / bits_in_word;
1162
1163 const char *ascii_initdata = net->GetWideInitialValue();
1164 if (ascii_initdata) {
1165 while (*ascii_initdata != 0 && *ascii_initdata != '\'')
1166 ascii_initdata++;
1167 if (*ascii_initdata == '\'')
1168 ascii_initdata++;
1169 if (*ascii_initdata != 0) {
1170 log_assert(*ascii_initdata == 'b');
1171 ascii_initdata++;
1172 }
1173 for (int word_idx = 0; word_idx < memory->size; word_idx++) {
1174 Const initval = Const(State::Sx, memory->width);
1175 bool initval_valid = false;
1176 for (int bit_idx = memory->width-1; bit_idx >= 0; bit_idx--) {
1177 if (*ascii_initdata == 0)
1178 break;
1179 if (*ascii_initdata == '0' || *ascii_initdata == '1') {
1180 initval[bit_idx] = (*ascii_initdata == '0') ? State::S0 : State::S1;
1181 initval_valid = true;
1182 }
1183 ascii_initdata++;
1184 }
1185 if (initval_valid) {
1186 RTLIL::Cell *cell = module->addCell(new_verific_id(net), ID($meminit));
1187 cell->parameters[ID::WORDS] = 1;
1188 if (net->GetOrigTypeRange()->LeftRangeBound() < net->GetOrigTypeRange()->RightRangeBound())
1189 cell->setPort(ID::ADDR, word_idx);
1190 else
1191 cell->setPort(ID::ADDR, memory->size - word_idx - 1);
1192 cell->setPort(ID::DATA, initval);
1193 cell->parameters[ID::MEMID] = RTLIL::Const(memory->name.str());
1194 cell->parameters[ID::ABITS] = 32;
1195 cell->parameters[ID::WIDTH] = memory->width;
1196 cell->parameters[ID::PRIORITY] = RTLIL::Const(autoidx-1);
1197 }
1198 }
1199 }
1200 continue;
1201 }
1202
1203 if (net->GetInitialValue())
1204 init_nets[net] = net->GetInitialValue();
1205
1206 const char *rand_const_attr = net->GetAttValue(" rand_const");
1207 const char *rand_attr = net->GetAttValue(" rand");
1208
1209 const char *anyconst_attr = net->GetAttValue("anyconst");
1210 const char *anyseq_attr = net->GetAttValue("anyseq");
1211
1212 const char *allconst_attr = net->GetAttValue("allconst");
1213 const char *allseq_attr = net->GetAttValue("allseq");
1214
1215 if (rand_const_attr != nullptr && (!strcmp(rand_const_attr, "1") || !strcmp(rand_const_attr, "'1'"))) {
1216 anyconst_nets.insert(net);
1217 any_all_nets.insert(net);
1218 }
1219 else if (rand_attr != nullptr && (!strcmp(rand_attr, "1") || !strcmp(rand_attr, "'1'"))) {
1220 anyseq_nets.insert(net);
1221 any_all_nets.insert(net);
1222 }
1223 else if (anyconst_attr != nullptr && (!strcmp(anyconst_attr, "1") || !strcmp(anyconst_attr, "'1'"))) {
1224 anyconst_nets.insert(net);
1225 any_all_nets.insert(net);
1226 }
1227 else if (anyseq_attr != nullptr && (!strcmp(anyseq_attr, "1") || !strcmp(anyseq_attr, "'1'"))) {
1228 anyseq_nets.insert(net);
1229 any_all_nets.insert(net);
1230 }
1231 else if (allconst_attr != nullptr && (!strcmp(allconst_attr, "1") || !strcmp(allconst_attr, "'1'"))) {
1232 allconst_nets.insert(net);
1233 any_all_nets.insert(net);
1234 }
1235 else if (allseq_attr != nullptr && (!strcmp(allseq_attr, "1") || !strcmp(allseq_attr, "'1'"))) {
1236 allseq_nets.insert(net);
1237 any_all_nets.insert(net);
1238 }
1239
1240 if (net_map.count(net)) {
1241 if (verific_verbose)
1242 log(" skipping net %s.\n", net->Name());
1243 continue;
1244 }
1245
1246 if (net->Bus())
1247 continue;
1248
1249 RTLIL::IdString wire_name = module->uniquify(mode_names || net->IsUserDeclared() ? RTLIL::escape_id(net->Name()) : new_verific_id(net));
1250
1251 if (verific_verbose)
1252 log(" importing net %s as %s.\n", net->Name(), log_id(wire_name));
1253
1254 RTLIL::Wire *wire = module->addWire(wire_name);
1255 import_attributes(wire->attributes, net, nl);
1256
1257 net_map[net] = wire;
1258 }
1259
1260 FOREACH_NETBUS_OF_NETLIST(nl, mi, netbus)
1261 {
1262 bool found_new_net = false;
1263 for (int i = netbus->LeftIndex();; i += netbus->IsUp() ? +1 : -1) {
1264 net = netbus->ElementAtIndex(i);
1265 if (net_map.count(net) == 0)
1266 found_new_net = true;
1267 if (i == netbus->RightIndex())
1268 break;
1269 }
1270
1271 if (found_new_net)
1272 {
1273 RTLIL::IdString wire_name = module->uniquify(mode_names || netbus->IsUserDeclared() ? RTLIL::escape_id(netbus->Name()) : new_verific_id(netbus));
1274
1275 if (verific_verbose)
1276 log(" importing netbus %s as %s.\n", netbus->Name(), log_id(wire_name));
1277
1278 RTLIL::Wire *wire = module->addWire(wire_name, netbus->Size());
1279 wire->start_offset = min(netbus->LeftIndex(), netbus->RightIndex());
1280 MapIter mibus;
1281 FOREACH_NET_OF_NETBUS(netbus, mibus, net) {
1282 if (net)
1283 import_attributes(wire->attributes, net, nl);
1284 break;
1285 }
1286
1287 RTLIL::Const initval = Const(State::Sx, GetSize(wire));
1288 bool initval_valid = false;
1289
1290 for (int i = netbus->LeftIndex();; i += netbus->IsUp() ? +1 : -1)
1291 {
1292 if (netbus->ElementAtIndex(i))
1293 {
1294 int bitidx = i - wire->start_offset;
1295 net = netbus->ElementAtIndex(i);
1296 RTLIL::SigBit bit(wire, bitidx);
1297
1298 if (init_nets.count(net)) {
1299 if (init_nets.at(net) == '0')
1300 initval.bits.at(bitidx) = State::S0;
1301 if (init_nets.at(net) == '1')
1302 initval.bits.at(bitidx) = State::S1;
1303 initval_valid = true;
1304 init_nets.erase(net);
1305 }
1306
1307 if (net_map.count(net) == 0)
1308 net_map[net] = bit;
1309 else
1310 module->connect(bit, net_map_at(net));
1311 }
1312
1313 if (i == netbus->RightIndex())
1314 break;
1315 }
1316
1317 if (initval_valid)
1318 wire->attributes[ID::init] = initval;
1319 }
1320 else
1321 {
1322 if (verific_verbose)
1323 log(" skipping netbus %s.\n", netbus->Name());
1324 }
1325
1326 SigSpec anyconst_sig;
1327 SigSpec anyseq_sig;
1328 SigSpec allconst_sig;
1329 SigSpec allseq_sig;
1330
1331 for (int i = netbus->RightIndex();; i += netbus->IsUp() ? -1 : +1) {
1332 net = netbus->ElementAtIndex(i);
1333 if (net != nullptr && anyconst_nets.count(net)) {
1334 anyconst_sig.append(net_map_at(net));
1335 anyconst_nets.erase(net);
1336 }
1337 if (net != nullptr && anyseq_nets.count(net)) {
1338 anyseq_sig.append(net_map_at(net));
1339 anyseq_nets.erase(net);
1340 }
1341 if (net != nullptr && allconst_nets.count(net)) {
1342 allconst_sig.append(net_map_at(net));
1343 allconst_nets.erase(net);
1344 }
1345 if (net != nullptr && allseq_nets.count(net)) {
1346 allseq_sig.append(net_map_at(net));
1347 allseq_nets.erase(net);
1348 }
1349 if (i == netbus->LeftIndex())
1350 break;
1351 }
1352
1353 if (GetSize(anyconst_sig))
1354 module->connect(anyconst_sig, module->Anyconst(new_verific_id(netbus), GetSize(anyconst_sig)));
1355
1356 if (GetSize(anyseq_sig))
1357 module->connect(anyseq_sig, module->Anyseq(new_verific_id(netbus), GetSize(anyseq_sig)));
1358
1359 if (GetSize(allconst_sig))
1360 module->connect(allconst_sig, module->Allconst(new_verific_id(netbus), GetSize(allconst_sig)));
1361
1362 if (GetSize(allseq_sig))
1363 module->connect(allseq_sig, module->Allseq(new_verific_id(netbus), GetSize(allseq_sig)));
1364 }
1365
1366 for (auto it : init_nets)
1367 {
1368 Const initval;
1369 SigBit bit = net_map_at(it.first);
1370 log_assert(bit.wire);
1371
1372 if (bit.wire->attributes.count(ID::init))
1373 initval = bit.wire->attributes.at(ID::init);
1374
1375 while (GetSize(initval) < GetSize(bit.wire))
1376 initval.bits.push_back(State::Sx);
1377
1378 if (it.second == '0')
1379 initval.bits.at(bit.offset) = State::S0;
1380 if (it.second == '1')
1381 initval.bits.at(bit.offset) = State::S1;
1382
1383 bit.wire->attributes[ID::init] = initval;
1384 }
1385
1386 for (auto net : anyconst_nets)
1387 module->connect(net_map_at(net), module->Anyconst(new_verific_id(net)));
1388
1389 for (auto net : anyseq_nets)
1390 module->connect(net_map_at(net), module->Anyseq(new_verific_id(net)));
1391
1392 pool<Instance*, hash_ptr_ops> sva_asserts;
1393 pool<Instance*, hash_ptr_ops> sva_assumes;
1394 pool<Instance*, hash_ptr_ops> sva_covers;
1395 pool<Instance*, hash_ptr_ops> sva_triggers;
1396
1397 pool<RTLIL::Cell*> past_ffs;
1398
1399 FOREACH_INSTANCE_OF_NETLIST(nl, mi, inst)
1400 {
1401 RTLIL::IdString inst_name = module->uniquify(mode_names || inst->IsUserDeclared() ? RTLIL::escape_id(inst->Name()) : new_verific_id(inst));
1402
1403 if (verific_verbose)
1404 log(" importing cell %s (%s) as %s.\n", inst->Name(), inst->View()->Owner()->Name(), log_id(inst_name));
1405
1406 if (mode_verific)
1407 goto import_verific_cells;
1408
1409 if (inst->Type() == PRIM_PWR) {
1410 module->connect(net_map_at(inst->GetOutput()), RTLIL::State::S1);
1411 continue;
1412 }
1413
1414 if (inst->Type() == PRIM_GND) {
1415 module->connect(net_map_at(inst->GetOutput()), RTLIL::State::S0);
1416 continue;
1417 }
1418
1419 if (inst->Type() == PRIM_BUF) {
1420 auto outnet = inst->GetOutput();
1421 if (!any_all_nets.count(outnet))
1422 module->addBufGate(inst_name, net_map_at(inst->GetInput()), net_map_at(outnet));
1423 continue;
1424 }
1425
1426 if (inst->Type() == PRIM_X) {
1427 module->connect(net_map_at(inst->GetOutput()), RTLIL::State::Sx);
1428 continue;
1429 }
1430
1431 if (inst->Type() == PRIM_Z) {
1432 module->connect(net_map_at(inst->GetOutput()), RTLIL::State::Sz);
1433 continue;
1434 }
1435
1436 if (inst->Type() == OPER_READ_PORT)
1437 {
1438 RTLIL::Memory *memory = module->memories.at(RTLIL::escape_id(inst->GetInput()->Name()), nullptr);
1439 if (!memory)
1440 log_error("Memory net '%s' missing, possibly no driver, use verific -flatten.\n", inst->GetInput()->Name());
1441
1442 int numchunks = int(inst->OutputSize()) / memory->width;
1443 int chunksbits = ceil_log2(numchunks);
1444
1445 for (int i = 0; i < numchunks; i++)
1446 {
1447 RTLIL::SigSpec addr = {operatorInput1(inst), RTLIL::Const(i, chunksbits)};
1448 RTLIL::SigSpec data = operatorOutput(inst).extract(i * memory->width, memory->width);
1449
1450 RTLIL::Cell *cell = module->addCell(numchunks == 1 ? inst_name :
1451 RTLIL::IdString(stringf("%s_%d", inst_name.c_str(), i)), ID($memrd));
1452 cell->parameters[ID::MEMID] = memory->name.str();
1453 cell->parameters[ID::CLK_ENABLE] = false;
1454 cell->parameters[ID::CLK_POLARITY] = true;
1455 cell->parameters[ID::TRANSPARENT] = false;
1456 cell->parameters[ID::ABITS] = GetSize(addr);
1457 cell->parameters[ID::WIDTH] = GetSize(data);
1458 cell->setPort(ID::CLK, RTLIL::State::Sx);
1459 cell->setPort(ID::EN, RTLIL::State::Sx);
1460 cell->setPort(ID::ADDR, addr);
1461 cell->setPort(ID::DATA, data);
1462 }
1463 continue;
1464 }
1465
1466 if (inst->Type() == OPER_WRITE_PORT || inst->Type() == OPER_CLOCKED_WRITE_PORT)
1467 {
1468 RTLIL::Memory *memory = module->memories.at(RTLIL::escape_id(inst->GetOutput()->Name()), nullptr);
1469 if (!memory)
1470 log_error("Memory net '%s' missing, possibly no driver, use verific -flatten.\n", inst->GetInput()->Name());
1471 int numchunks = int(inst->Input2Size()) / memory->width;
1472 int chunksbits = ceil_log2(numchunks);
1473
1474 for (int i = 0; i < numchunks; i++)
1475 {
1476 RTLIL::SigSpec addr = {operatorInput1(inst), RTLIL::Const(i, chunksbits)};
1477 RTLIL::SigSpec data = operatorInput2(inst).extract(i * memory->width, memory->width);
1478
1479 RTLIL::Cell *cell = module->addCell(numchunks == 1 ? inst_name :
1480 RTLIL::IdString(stringf("%s_%d", inst_name.c_str(), i)), ID($memwr));
1481 cell->parameters[ID::MEMID] = memory->name.str();
1482 cell->parameters[ID::CLK_ENABLE] = false;
1483 cell->parameters[ID::CLK_POLARITY] = true;
1484 cell->parameters[ID::PRIORITY] = 0;
1485 cell->parameters[ID::ABITS] = GetSize(addr);
1486 cell->parameters[ID::WIDTH] = GetSize(data);
1487 cell->setPort(ID::EN, RTLIL::SigSpec(net_map_at(inst->GetControl())).repeat(GetSize(data)));
1488 cell->setPort(ID::CLK, RTLIL::State::S0);
1489 cell->setPort(ID::ADDR, addr);
1490 cell->setPort(ID::DATA, data);
1491
1492 if (inst->Type() == OPER_CLOCKED_WRITE_PORT) {
1493 cell->parameters[ID::CLK_ENABLE] = true;
1494 cell->setPort(ID::CLK, net_map_at(inst->GetClock()));
1495 }
1496 }
1497 continue;
1498 }
1499
1500 if (!mode_gates) {
1501 if (import_netlist_instance_cells(inst, inst_name))
1502 continue;
1503 if (inst->IsOperator() && !verific_sva_prims.count(inst->Type()))
1504 log_warning("Unsupported Verific operator: %s (fallback to gate level implementation provided by verific)\n", inst->View()->Owner()->Name());
1505 } else {
1506 if (import_netlist_instance_gates(inst, inst_name))
1507 continue;
1508 }
1509
1510 if (inst->Type() == PRIM_SVA_ASSERT || inst->Type() == PRIM_SVA_IMMEDIATE_ASSERT)
1511 sva_asserts.insert(inst);
1512
1513 if (inst->Type() == PRIM_SVA_ASSUME || inst->Type() == PRIM_SVA_IMMEDIATE_ASSUME || inst->Type() == PRIM_SVA_RESTRICT)
1514 sva_assumes.insert(inst);
1515
1516 if (inst->Type() == PRIM_SVA_COVER || inst->Type() == PRIM_SVA_IMMEDIATE_COVER)
1517 sva_covers.insert(inst);
1518
1519 if (inst->Type() == PRIM_SVA_TRIGGERED)
1520 sva_triggers.insert(inst);
1521
1522 if (inst->Type() == OPER_SVA_STABLE)
1523 {
1524 VerificClocking clocking(this, inst->GetInput2Bit(0));
1525 log_assert(clocking.disable_sig == State::S0);
1526 log_assert(clocking.body_net == nullptr);
1527
1528 log_assert(inst->Input1Size() == inst->OutputSize());
1529
1530 SigSpec sig_d, sig_q, sig_o;
1531 sig_q = module->addWire(new_verific_id(inst), inst->Input1Size());
1532
1533 for (int i = int(inst->Input1Size())-1; i >= 0; i--){
1534 sig_d.append(net_map_at(inst->GetInput1Bit(i)));
1535 sig_o.append(net_map_at(inst->GetOutputBit(i)));
1536 }
1537
1538 if (verific_verbose) {
1539 log(" %sedge FF with D=%s, Q=%s, C=%s.\n", clocking.posedge ? "pos" : "neg",
1540 log_signal(sig_d), log_signal(sig_q), log_signal(clocking.clock_sig));
1541 log(" XNOR with A=%s, B=%s, Y=%s.\n",
1542 log_signal(sig_d), log_signal(sig_q), log_signal(sig_o));
1543 }
1544
1545 clocking.addDff(new_verific_id(inst), sig_d, sig_q);
1546 module->addXnor(new_verific_id(inst), sig_d, sig_q, sig_o);
1547
1548 if (!mode_keep)
1549 continue;
1550 }
1551
1552 if (inst->Type() == PRIM_SVA_STABLE)
1553 {
1554 VerificClocking clocking(this, inst->GetInput2());
1555 log_assert(clocking.disable_sig == State::S0);
1556 log_assert(clocking.body_net == nullptr);
1557
1558 SigSpec sig_d = net_map_at(inst->GetInput1());
1559 SigSpec sig_o = net_map_at(inst->GetOutput());
1560 SigSpec sig_q = module->addWire(new_verific_id(inst));
1561
1562 if (verific_verbose) {
1563 log(" %sedge FF with D=%s, Q=%s, C=%s.\n", clocking.posedge ? "pos" : "neg",
1564 log_signal(sig_d), log_signal(sig_q), log_signal(clocking.clock_sig));
1565 log(" XNOR with A=%s, B=%s, Y=%s.\n",
1566 log_signal(sig_d), log_signal(sig_q), log_signal(sig_o));
1567 }
1568
1569 clocking.addDff(new_verific_id(inst), sig_d, sig_q);
1570 module->addXnor(new_verific_id(inst), sig_d, sig_q, sig_o);
1571
1572 if (!mode_keep)
1573 continue;
1574 }
1575
1576 if (inst->Type() == PRIM_SVA_PAST)
1577 {
1578 VerificClocking clocking(this, inst->GetInput2());
1579 log_assert(clocking.disable_sig == State::S0);
1580 log_assert(clocking.body_net == nullptr);
1581
1582 SigBit sig_d = net_map_at(inst->GetInput1());
1583 SigBit sig_q = net_map_at(inst->GetOutput());
1584
1585 if (verific_verbose)
1586 log(" %sedge FF with D=%s, Q=%s, C=%s.\n", clocking.posedge ? "pos" : "neg",
1587 log_signal(sig_d), log_signal(sig_q), log_signal(clocking.clock_sig));
1588
1589 past_ffs.insert(clocking.addDff(new_verific_id(inst), sig_d, sig_q));
1590
1591 if (!mode_keep)
1592 continue;
1593 }
1594
1595 if ((inst->Type() == PRIM_SVA_ROSE || inst->Type() == PRIM_SVA_FELL))
1596 {
1597 VerificClocking clocking(this, inst->GetInput2());
1598 log_assert(clocking.disable_sig == State::S0);
1599 log_assert(clocking.body_net == nullptr);
1600
1601 SigBit sig_d = net_map_at(inst->GetInput1());
1602 SigBit sig_o = net_map_at(inst->GetOutput());
1603 SigBit sig_q = module->addWire(new_verific_id(inst));
1604
1605 if (verific_verbose)
1606 log(" %sedge FF with D=%s, Q=%s, C=%s.\n", clocking.posedge ? "pos" : "neg",
1607 log_signal(sig_d), log_signal(sig_q), log_signal(clocking.clock_sig));
1608
1609 clocking.addDff(new_verific_id(inst), sig_d, sig_q);
1610 module->addEq(new_verific_id(inst), {sig_q, sig_d}, Const(inst->Type() == PRIM_SVA_ROSE ? 1 : 2, 2), sig_o);
1611
1612 if (!mode_keep)
1613 continue;
1614 }
1615
1616 if (inst->Type() == PRIM_YOSYSHQ_INITSTATE)
1617 {
1618 if (verific_verbose)
1619 log(" adding YosysHQ init state\n");
1620 SigBit initstate = module->Initstate(new_verific_id(inst));
1621 SigBit sig_o = net_map_at(inst->GetOutput());
1622 module->connect(sig_o, initstate);
1623
1624 if (!mode_keep)
1625 continue;
1626 }
1627
1628 if (!mode_keep && verific_sva_prims.count(inst->Type())) {
1629 if (verific_verbose)
1630 log(" skipping SVA cell in non k-mode\n");
1631 continue;
1632 }
1633
1634 if (inst->Type() == PRIM_HDL_ASSERTION)
1635 {
1636 SigBit cond = net_map_at(inst->GetInput());
1637
1638 if (verific_verbose)
1639 log(" assert condition %s.\n", log_signal(cond));
1640
1641 const char *assume_attr = nullptr; // inst->GetAttValue("assume");
1642
1643 Cell *cell = nullptr;
1644 if (assume_attr != nullptr && !strcmp(assume_attr, "1"))
1645 cell = module->addAssume(new_verific_id(inst), cond, State::S1);
1646 else
1647 cell = module->addAssert(new_verific_id(inst), cond, State::S1);
1648
1649 import_attributes(cell->attributes, inst);
1650 continue;
1651 }
1652
1653 if (inst->IsPrimitive())
1654 {
1655 if (!mode_keep)
1656 log_error("Unsupported Verific primitive %s of type %s\n", inst->Name(), inst->View()->Owner()->Name());
1657
1658 if (!verific_sva_prims.count(inst->Type()))
1659 log_warning("Unsupported Verific primitive %s of type %s\n", inst->Name(), inst->View()->Owner()->Name());
1660 }
1661
1662 import_verific_cells:
1663 std::string inst_type = inst->View()->Owner()->Name();
1664
1665 nl_todo[inst_type] = inst->View();
1666
1667 if (inst->View()->IsOperator() || inst->View()->IsPrimitive()) {
1668 inst_type = "$verific$" + inst_type;
1669 } else {
1670 if (*inst->View()->Name()) {
1671 inst_type += "(";
1672 inst_type += inst->View()->Name();
1673 inst_type += ")";
1674 }
1675 inst_type = "\\" + sha1_if_contain_spaces(inst_type);
1676 }
1677
1678 RTLIL::Cell *cell = module->addCell(inst_name, inst_type);
1679
1680 if (inst->IsPrimitive() && mode_keep)
1681 cell->attributes[ID::keep] = 1;
1682
1683 dict<IdString, vector<SigBit>> cell_port_conns;
1684
1685 if (verific_verbose)
1686 log(" ports in verific db:\n");
1687
1688 FOREACH_PORTREF_OF_INST(inst, mi2, pr) {
1689 if (verific_verbose)
1690 log(" .%s(%s)\n", pr->GetPort()->Name(), pr->GetNet()->Name());
1691 const char *port_name = pr->GetPort()->Name();
1692 int port_offset = 0;
1693 if (pr->GetPort()->Bus()) {
1694 port_name = pr->GetPort()->Bus()->Name();
1695 port_offset = pr->GetPort()->Bus()->IndexOf(pr->GetPort()) -
1696 min(pr->GetPort()->Bus()->LeftIndex(), pr->GetPort()->Bus()->RightIndex());
1697 }
1698 IdString port_name_id = RTLIL::escape_id(port_name);
1699 auto &sigvec = cell_port_conns[port_name_id];
1700 if (GetSize(sigvec) <= port_offset) {
1701 SigSpec zwires = module->addWire(new_verific_id(inst), port_offset+1-GetSize(sigvec));
1702 for (auto bit : zwires)
1703 sigvec.push_back(bit);
1704 }
1705 sigvec[port_offset] = net_map_at(pr->GetNet());
1706 }
1707
1708 if (verific_verbose)
1709 log(" ports in yosys db:\n");
1710
1711 for (auto &it : cell_port_conns) {
1712 if (verific_verbose)
1713 log(" .%s(%s)\n", log_id(it.first), log_signal(it.second));
1714 cell->setPort(it.first, it.second);
1715 }
1716 }
1717
1718 if (!mode_nosva)
1719 {
1720 for (auto inst : sva_asserts) {
1721 if (mode_autocover)
1722 verific_import_sva_cover(this, inst);
1723 verific_import_sva_assert(this, inst);
1724 }
1725
1726 for (auto inst : sva_assumes)
1727 verific_import_sva_assume(this, inst);
1728
1729 for (auto inst : sva_covers)
1730 verific_import_sva_cover(this, inst);
1731
1732 for (auto inst : sva_triggers)
1733 verific_import_sva_trigger(this, inst);
1734
1735 merge_past_ffs(past_ffs);
1736 }
1737
1738 if (!mode_fullinit)
1739 {
1740 pool<SigBit> non_ff_bits;
1741 CellTypes ff_types;
1742
1743 ff_types.setup_internals_ff();
1744 ff_types.setup_stdcells_mem();
1745
1746 for (auto cell : module->cells())
1747 {
1748 if (ff_types.cell_known(cell->type))
1749 continue;
1750
1751 for (auto conn : cell->connections())
1752 {
1753 if (!cell->output(conn.first))
1754 continue;
1755
1756 for (auto bit : conn.second)
1757 if (bit.wire != nullptr)
1758 non_ff_bits.insert(bit);
1759 }
1760 }
1761
1762 for (auto wire : module->wires())
1763 {
1764 if (!wire->attributes.count(ID::init))
1765 continue;
1766
1767 Const &initval = wire->attributes.at(ID::init);
1768 for (int i = 0; i < GetSize(initval); i++)
1769 {
1770 if (initval[i] != State::S0 && initval[i] != State::S1)
1771 continue;
1772
1773 if (non_ff_bits.count(SigBit(wire, i)))
1774 initval[i] = State::Sx;
1775 }
1776
1777 if (initval.is_fully_undef())
1778 wire->attributes.erase(ID::init);
1779 }
1780 }
1781 }
1782
1783 // ==================================================================
1784
1785 VerificClocking::VerificClocking(VerificImporter *importer, Net *net, bool sva_at_only)
1786 {
1787 module = importer->module;
1788
1789 log_assert(importer != nullptr);
1790 log_assert(net != nullptr);
1791
1792 Instance *inst = net->Driver();
1793
1794 if (inst != nullptr && inst->Type() == PRIM_SVA_AT)
1795 {
1796 net = inst->GetInput1();
1797 body_net = inst->GetInput2();
1798
1799 inst = net->Driver();
1800
1801 Instance *body_inst = body_net->Driver();
1802 if (body_inst != nullptr && body_inst->Type() == PRIM_SVA_DISABLE_IFF) {
1803 disable_net = body_inst->GetInput1();
1804 disable_sig = importer->net_map_at(disable_net);
1805 body_net = body_inst->GetInput2();
1806 }
1807 }
1808 else
1809 {
1810 if (sva_at_only)
1811 return;
1812 }
1813
1814 // Use while() instead of if() to work around VIPER #13453
1815 while (inst != nullptr && inst->Type() == PRIM_SVA_POSEDGE)
1816 {
1817 net = inst->GetInput();
1818 inst = net->Driver();;
1819 }
1820
1821 if (inst != nullptr && inst->Type() == PRIM_INV)
1822 {
1823 net = inst->GetInput();
1824 inst = net->Driver();;
1825 posedge = false;
1826 }
1827
1828 // Detect clock-enable circuit
1829 do {
1830 if (inst == nullptr || inst->Type() != PRIM_AND)
1831 break;
1832
1833 Net *net_dlatch = inst->GetInput1();
1834 Instance *inst_dlatch = net_dlatch->Driver();
1835
1836 if (inst_dlatch == nullptr || inst_dlatch->Type() != PRIM_DLATCHRS)
1837 break;
1838
1839 if (!inst_dlatch->GetSet()->IsGnd() || !inst_dlatch->GetReset()->IsGnd())
1840 break;
1841
1842 Net *net_enable = inst_dlatch->GetInput();
1843 Net *net_not_clock = inst_dlatch->GetControl();
1844
1845 if (net_enable == nullptr || net_not_clock == nullptr)
1846 break;
1847
1848 Instance *inst_not_clock = net_not_clock->Driver();
1849
1850 if (inst_not_clock == nullptr || inst_not_clock->Type() != PRIM_INV)
1851 break;
1852
1853 Net *net_clock1 = inst_not_clock->GetInput();
1854 Net *net_clock2 = inst->GetInput2();
1855
1856 if (net_clock1 == nullptr || net_clock1 != net_clock2)
1857 break;
1858
1859 enable_net = net_enable;
1860 enable_sig = importer->net_map_at(enable_net);
1861
1862 net = net_clock1;
1863 inst = net->Driver();;
1864 } while (0);
1865
1866 // Detect condition expression
1867 do {
1868 if (body_net == nullptr)
1869 break;
1870
1871 Instance *inst_mux = body_net->Driver();
1872
1873 if (inst_mux == nullptr || inst_mux->Type() != PRIM_MUX)
1874 break;
1875
1876 bool pwr1 = inst_mux->GetInput1()->IsPwr();
1877 bool pwr2 = inst_mux->GetInput2()->IsPwr();
1878
1879 if (!pwr1 && !pwr2)
1880 break;
1881
1882 Net *sva_net = pwr1 ? inst_mux->GetInput2() : inst_mux->GetInput1();
1883 if (!verific_is_sva_net(importer, sva_net))
1884 break;
1885
1886 body_net = sva_net;
1887 cond_net = inst_mux->GetControl();
1888 cond_pol = pwr1;
1889 } while (0);
1890
1891 clock_net = net;
1892 clock_sig = importer->net_map_at(clock_net);
1893
1894 const char *gclk_attr = clock_net->GetAttValue("gclk");
1895 if (gclk_attr != nullptr && (!strcmp(gclk_attr, "1") || !strcmp(gclk_attr, "'1'")))
1896 gclk = true;
1897 }
1898
1899 Cell *VerificClocking::addDff(IdString name, SigSpec sig_d, SigSpec sig_q, Const init_value)
1900 {
1901 log_assert(GetSize(sig_d) == GetSize(sig_q));
1902
1903 auto set_init_attribute = [&](SigSpec &s) {
1904 if (GetSize(init_value) == 0)
1905 return;
1906 log_assert(GetSize(s) == GetSize(init_value));
1907 if (s.is_wire()) {
1908 s.as_wire()->attributes[ID::init] = init_value;
1909 } else {
1910 Wire *w = module->addWire(NEW_ID, GetSize(s));
1911 w->attributes[ID::init] = init_value;
1912 module->connect(s, w);
1913 s = w;
1914 }
1915 };
1916
1917 if (enable_sig != State::S1)
1918 sig_d = module->Mux(NEW_ID, sig_q, sig_d, enable_sig);
1919
1920 if (disable_sig != State::S0) {
1921 log_assert(GetSize(sig_q) == GetSize(init_value));
1922
1923 if (gclk) {
1924 Wire *pre_d = module->addWire(NEW_ID, GetSize(sig_d));
1925 Wire *post_q_w = module->addWire(NEW_ID, GetSize(sig_q));
1926
1927 Const initval(State::Sx, GetSize(sig_q));
1928 int offset = 0;
1929 for (auto c : sig_q.chunks()) {
1930 if (c.wire && c.wire->attributes.count(ID::init)) {
1931 Const val = c.wire->attributes.at(ID::init);
1932 for (int i = 0; i < GetSize(c); i++)
1933 initval[offset+i] = val[c.offset+i];
1934 }
1935 offset += GetSize(c);
1936 }
1937
1938 if (!initval.is_fully_undef())
1939 post_q_w->attributes[ID::init] = initval;
1940
1941 module->addMux(NEW_ID, sig_d, init_value, disable_sig, pre_d);
1942 module->addMux(NEW_ID, post_q_w, init_value, disable_sig, sig_q);
1943
1944 SigSpec post_q(post_q_w);
1945 set_init_attribute(post_q);
1946 return module->addFf(name, pre_d, post_q);
1947 }
1948
1949 set_init_attribute(sig_q);
1950 return module->addAdff(name, clock_sig, disable_sig, sig_d, sig_q, init_value, posedge);
1951 }
1952
1953 if (gclk) {
1954 set_init_attribute(sig_q);
1955 return module->addFf(name, sig_d, sig_q);
1956 }
1957
1958 set_init_attribute(sig_q);
1959 return module->addDff(name, clock_sig, sig_d, sig_q, posedge);
1960 }
1961
1962 Cell *VerificClocking::addAdff(IdString name, RTLIL::SigSpec sig_arst, SigSpec sig_d, SigSpec sig_q, Const arst_value)
1963 {
1964 log_assert(gclk == false);
1965 log_assert(disable_sig == State::S0);
1966
1967 // FIXME: Adffe
1968 if (enable_sig != State::S1)
1969 sig_d = module->Mux(NEW_ID, sig_q, sig_d, enable_sig);
1970
1971 return module->addAdff(name, clock_sig, sig_arst, sig_d, sig_q, arst_value, posedge);
1972 }
1973
1974 Cell *VerificClocking::addDffsr(IdString name, RTLIL::SigSpec sig_set, RTLIL::SigSpec sig_clr, SigSpec sig_d, SigSpec sig_q)
1975 {
1976 log_assert(gclk == false);
1977 log_assert(disable_sig == State::S0);
1978
1979 // FIXME: Dffsre
1980 if (enable_sig != State::S1)
1981 sig_d = module->Mux(NEW_ID, sig_q, sig_d, enable_sig);
1982
1983 return module->addDffsr(name, clock_sig, sig_set, sig_clr, sig_d, sig_q, posedge);
1984 }
1985
1986 Cell *VerificClocking::addAldff(IdString name, RTLIL::SigSpec sig_aload, RTLIL::SigSpec sig_adata, SigSpec sig_d, SigSpec sig_q)
1987 {
1988 log_assert(disable_sig == State::S0);
1989
1990 // FIXME: Aldffe
1991 if (enable_sig != State::S1)
1992 sig_d = module->Mux(NEW_ID, sig_q, sig_d, enable_sig);
1993
1994 if (gclk) {
1995 Wire *pre_d = module->addWire(NEW_ID, GetSize(sig_d));
1996 Wire *post_q = module->addWire(NEW_ID, GetSize(sig_q));
1997
1998 Const initval(State::Sx, GetSize(sig_q));
1999 int offset = 0;
2000 for (auto c : sig_q.chunks()) {
2001 if (c.wire && c.wire->attributes.count(ID::init)) {
2002 Const val = c.wire->attributes.at(ID::init);
2003 for (int i = 0; i < GetSize(c); i++)
2004 initval[offset+i] = val[c.offset+i];
2005 }
2006 offset += GetSize(c);
2007 }
2008
2009 if (!initval.is_fully_undef())
2010 post_q->attributes[ID::init] = initval;
2011
2012 module->addMux(NEW_ID, sig_d, sig_adata, sig_aload, pre_d);
2013 module->addMux(NEW_ID, post_q, sig_adata, sig_aload, sig_q);
2014
2015 return module->addFf(name, pre_d, post_q);
2016 }
2017
2018 return module->addAldff(name, clock_sig, sig_aload, sig_d, sig_q, sig_adata, posedge);
2019 }
2020
2021 // ==================================================================
2022
2023 struct VerificExtNets
2024 {
2025 int portname_cnt = 0;
2026
2027 // a map from Net to the same Net one level up in the design hierarchy
2028 std::map<Net*, Net*> net_level_up_drive_up;
2029 std::map<Net*, Net*> net_level_up_drive_down;
2030
2031 Net *route_up(Net *net, bool drive_up, Net *final_net = nullptr)
2032 {
2033 auto &net_level_up = drive_up ? net_level_up_drive_up : net_level_up_drive_down;
2034
2035 if (net_level_up.count(net) == 0)
2036 {
2037 Netlist *nl = net->Owner();
2038
2039 // Simply return if Netlist is not unique
2040 log_assert(nl->NumOfRefs() == 1);
2041
2042 Instance *up_inst = (Instance*)nl->GetReferences()->GetLast();
2043 Netlist *up_nl = up_inst->Owner();
2044
2045 // create new Port
2046 string name = stringf("___extnets_%d", portname_cnt++);
2047 Port *new_port = new Port(name.c_str(), drive_up ? DIR_OUT : DIR_IN);
2048 nl->Add(new_port);
2049 nl->Buf(net)->Connect(new_port);
2050
2051 // create new Net in up Netlist
2052 Net *new_net = final_net;
2053 if (new_net == nullptr || new_net->Owner() != up_nl) {
2054 new_net = new Net(name.c_str());
2055 up_nl->Add(new_net);
2056 }
2057 up_inst->Connect(new_port, new_net);
2058
2059 net_level_up[net] = new_net;
2060 }
2061
2062 return net_level_up.at(net);
2063 }
2064
2065 Net *route_up(Net *net, bool drive_up, Netlist *dest, Net *final_net = nullptr)
2066 {
2067 while (net->Owner() != dest)
2068 net = route_up(net, drive_up, final_net);
2069 if (final_net != nullptr)
2070 log_assert(net == final_net);
2071 return net;
2072 }
2073
2074 Netlist *find_common_ancestor(Netlist *A, Netlist *B)
2075 {
2076 std::set<Netlist*> ancestors_of_A;
2077
2078 Netlist *cursor = A;
2079 while (1) {
2080 ancestors_of_A.insert(cursor);
2081 if (cursor->NumOfRefs() != 1)
2082 break;
2083 cursor = ((Instance*)cursor->GetReferences()->GetLast())->Owner();
2084 }
2085
2086 cursor = B;
2087 while (1) {
2088 if (ancestors_of_A.count(cursor))
2089 return cursor;
2090 if (cursor->NumOfRefs() != 1)
2091 break;
2092 cursor = ((Instance*)cursor->GetReferences()->GetLast())->Owner();
2093 }
2094
2095 log_error("No common ancestor found between %s and %s.\n", get_full_netlist_name(A).c_str(), get_full_netlist_name(B).c_str());
2096 }
2097
2098 void run(Netlist *nl)
2099 {
2100 MapIter mi, mi2;
2101 Instance *inst;
2102 PortRef *pr;
2103
2104 vector<tuple<Instance*, Port*, Net*>> todo_connect;
2105
2106 FOREACH_INSTANCE_OF_NETLIST(nl, mi, inst)
2107 run(inst->View());
2108
2109 FOREACH_INSTANCE_OF_NETLIST(nl, mi, inst)
2110 FOREACH_PORTREF_OF_INST(inst, mi2, pr)
2111 {
2112 Port *port = pr->GetPort();
2113 Net *net = pr->GetNet();
2114
2115 if (!net->IsExternalTo(nl))
2116 continue;
2117
2118 if (verific_verbose)
2119 log("Fixing external net reference on port %s.%s.%s:\n", get_full_netlist_name(nl).c_str(), inst->Name(), port->Name());
2120
2121 Netlist *ext_nl = net->Owner();
2122
2123 if (verific_verbose)
2124 log(" external net owner: %s\n", get_full_netlist_name(ext_nl).c_str());
2125
2126 Netlist *ca_nl = find_common_ancestor(nl, ext_nl);
2127
2128 if (verific_verbose)
2129 log(" common ancestor: %s\n", get_full_netlist_name(ca_nl).c_str());
2130
2131 Net *ca_net = route_up(net, !port->IsOutput(), ca_nl);
2132 Net *new_net = ca_net;
2133
2134 if (ca_nl != nl)
2135 {
2136 if (verific_verbose)
2137 log(" net in common ancestor: %s\n", ca_net->Name());
2138
2139 string name = stringf("___extnets_%d", portname_cnt++);
2140 new_net = new Net(name.c_str());
2141 nl->Add(new_net);
2142
2143 Net *n = route_up(new_net, port->IsOutput(), ca_nl, ca_net);
2144 log_assert(n == ca_net);
2145 }
2146
2147 if (verific_verbose)
2148 log(" new local net: %s\n", new_net->Name());
2149
2150 log_assert(!new_net->IsExternalTo(nl));
2151 todo_connect.push_back(tuple<Instance*, Port*, Net*>(inst, port, new_net));
2152 }
2153
2154 for (auto it : todo_connect) {
2155 get<0>(it)->Disconnect(get<1>(it));
2156 get<0>(it)->Connect(get<1>(it), get<2>(it));
2157 }
2158 }
2159 };
2160
2161 void verific_import(Design *design, const std::map<std::string,std::string> &parameters, std::string top)
2162 {
2163 verific_sva_fsm_limit = 16;
2164
2165 std::map<std::string,Netlist*> nl_todo, nl_done;
2166
2167 VeriLibrary *veri_lib = veri_file::GetLibrary("work", 1);
2168 Array *netlists = NULL;
2169 Array veri_libs, vhdl_libs;
2170 #ifdef VERIFIC_VHDL_SUPPORT
2171 VhdlLibrary *vhdl_lib = vhdl_file::GetLibrary("work", 1);
2172 if (vhdl_lib) vhdl_libs.InsertLast(vhdl_lib);
2173 #endif
2174 if (veri_lib) veri_libs.InsertLast(veri_lib);
2175
2176 Map verific_params(STRING_HASH);
2177 for (const auto &i : parameters)
2178 verific_params.Insert(i.first.c_str(), i.second.c_str());
2179
2180 #ifdef YOSYSHQ_VERIFIC_EXTENSIONS
2181 InitialAssertions::Rewrite("work", &verific_params);
2182 #endif
2183
2184 if (top.empty()) {
2185 netlists = hier_tree::ElaborateAll(&veri_libs, &vhdl_libs, &verific_params);
2186 }
2187 else {
2188 Array veri_modules, vhdl_units;
2189
2190 if (veri_lib) {
2191 VeriModule *veri_module = veri_lib->GetModule(top.c_str(), 1);
2192 if (veri_module) {
2193 veri_modules.InsertLast(veri_module);
2194 }
2195
2196 // Also elaborate all root modules since they may contain bind statements
2197 MapIter mi;
2198 FOREACH_VERILOG_MODULE_IN_LIBRARY(veri_lib, mi, veri_module) {
2199 if (!veri_module->IsRootModule()) continue;
2200 veri_modules.InsertLast(veri_module);
2201 }
2202 }
2203
2204 #ifdef VERIFIC_VHDL_SUPPORT
2205 if (vhdl_lib) {
2206 VhdlDesignUnit *vhdl_unit = vhdl_lib->GetPrimUnit(top.c_str());
2207 if (vhdl_unit)
2208 vhdl_units.InsertLast(vhdl_unit);
2209 }
2210 #endif
2211 netlists = hier_tree::Elaborate(&veri_modules, &vhdl_units, &verific_params);
2212 }
2213
2214 Netlist *nl;
2215 int i;
2216
2217 FOREACH_ARRAY_ITEM(netlists, i, nl) {
2218 if (!top.empty() && nl->CellBaseName() != top)
2219 continue;
2220 nl->AddAtt(new Att(" \\top", NULL));
2221 nl_todo.emplace(nl->CellBaseName(), nl);
2222 }
2223
2224 delete netlists;
2225
2226 if (!verific_error_msg.empty())
2227 log_error("%s\n", verific_error_msg.c_str());
2228
2229 for (auto nl : nl_todo)
2230 nl.second->ChangePortBusStructures(1 /* hierarchical */);
2231
2232 VerificExtNets worker;
2233 for (auto nl : nl_todo)
2234 worker.run(nl.second);
2235
2236 while (!nl_todo.empty()) {
2237 auto it = nl_todo.begin();
2238 Netlist *nl = it->second;
2239 if (nl_done.count(it->first) == 0) {
2240 VerificImporter importer(false, false, false, false, false, false, false);
2241 nl_done[it->first] = it->second;
2242 importer.import_netlist(design, nl, nl_todo, nl->Owner()->Name() == top);
2243 }
2244 nl_todo.erase(it);
2245 }
2246
2247 hier_tree::DeleteHierarchicalTree();
2248 veri_file::Reset();
2249 #ifdef VERIFIC_VHDL_SUPPORT
2250 vhdl_file::Reset();
2251 #endif
2252 Libset::Reset();
2253 Message::Reset();
2254 RuntimeFlags::DeleteAllFlags();
2255 LineFile::DeleteAllLineFiles();
2256 verific_incdirs.clear();
2257 verific_libdirs.clear();
2258 verific_import_pending = false;
2259
2260 if (!verific_error_msg.empty())
2261 log_error("%s\n", verific_error_msg.c_str());
2262 }
2263
2264 YOSYS_NAMESPACE_END
2265 #endif /* YOSYS_ENABLE_VERIFIC */
2266
2267 PRIVATE_NAMESPACE_BEGIN
2268
2269 #ifdef YOSYS_ENABLE_VERIFIC
2270 bool check_noverific_env()
2271 {
2272 const char *e = getenv("YOSYS_NOVERIFIC");
2273 if (e == nullptr)
2274 return false;
2275 if (atoi(e) == 0)
2276 return false;
2277 return true;
2278 }
2279 #endif
2280
2281 struct VerificPass : public Pass {
2282 VerificPass() : Pass("verific", "load Verilog and VHDL designs using Verific") { }
2283 void help() override
2284 {
2285 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
2286 log("\n");
2287 log(" verific {-vlog95|-vlog2k|-sv2005|-sv2009|-sv2012|-sv} <verilog-file>..\n");
2288 log("\n");
2289 log("Load the specified Verilog/SystemVerilog files into Verific.\n");
2290 log("\n");
2291 log("All files specified in one call to this command are one compilation unit.\n");
2292 log("Files passed to different calls to this command are treated as belonging to\n");
2293 log("different compilation units.\n");
2294 log("\n");
2295 log("Additional -D<macro>[=<value>] options may be added after the option indicating\n");
2296 log("the language version (and before file names) to set additional verilog defines.\n");
2297 log("The macros YOSYS, SYNTHESIS, and VERIFIC are defined implicitly.\n");
2298 log("\n");
2299 log("\n");
2300 log(" verific -formal <verilog-file>..\n");
2301 log("\n");
2302 log("Like -sv, but define FORMAL instead of SYNTHESIS.\n");
2303 log("\n");
2304 log("\n");
2305 #ifdef VERIFIC_VHDL_SUPPORT
2306 log(" verific {-vhdl87|-vhdl93|-vhdl2k|-vhdl2008|-vhdl} <vhdl-file>..\n");
2307 log("\n");
2308 log("Load the specified VHDL files into Verific.\n");
2309 log("\n");
2310 log("\n");
2311 #endif
2312 log(" verific {-f|-F} [-vlog95|-vlog2k|-sv2005|-sv2009|-sv2012|-sv|-formal] <command-file>\n");
2313 log("\n");
2314 log("Load and execute the specified command file.\n");
2315 log("Override verilog parsing mode can be set.\n");
2316 log("The macros YOSYS, SYNTHESIS/FORMAL, and VERIFIC are defined implicitly.\n");
2317 log("\n");
2318 log("Command file parser supports following commands:\n");
2319 log(" +define - defines macro\n");
2320 log(" -u - upper case all identifier (makes Verilog parser case insensitive)\n");
2321 log(" -v - register library name (file)\n");
2322 log(" -y - register library name (directory)\n");
2323 log(" +incdir - specify include dir\n");
2324 log(" +libext - specify library extension\n");
2325 log(" +liborder - add library in ordered list\n");
2326 log(" +librescan - unresolved modules will be always searched starting with the first\n");
2327 log(" library specified by -y/-v options.\n");
2328 log(" -f/-file - nested -f option\n");
2329 log(" -F - nested -F option\n");
2330 log("\n");
2331 log(" parse mode:\n");
2332 log(" -ams\n");
2333 log(" +systemverilogext\n");
2334 log(" +v2k\n");
2335 log(" +verilog1995ext\n");
2336 log(" +verilog2001ext\n");
2337 log(" -sverilog\n");
2338 log("\n");
2339 log("\n");
2340 log(" verific [-work <libname>] {-sv|-vhdl|...} <hdl-file>\n");
2341 log("\n");
2342 log("Load the specified Verilog/SystemVerilog/VHDL file into the specified library.\n");
2343 log("(default library when -work is not present: \"work\")\n");
2344 log("\n");
2345 log("\n");
2346 log(" verific [-L <libname>] {-sv|-vhdl|...} <hdl-file>\n");
2347 log("\n");
2348 log("Look up external definitions in the specified library.\n");
2349 log("(-L may be used more than once)\n");
2350 log("\n");
2351 log("\n");
2352 log(" verific -vlog-incdir <directory>..\n");
2353 log("\n");
2354 log("Add Verilog include directories.\n");
2355 log("\n");
2356 log("\n");
2357 log(" verific -vlog-libdir <directory>..\n");
2358 log("\n");
2359 log("Add Verilog library directories. Verific will search in this directories to\n");
2360 log("find undefined modules.\n");
2361 log("\n");
2362 log("\n");
2363 log(" verific -vlog-define <macro>[=<value>]..\n");
2364 log("\n");
2365 log("Add Verilog defines.\n");
2366 log("\n");
2367 log("\n");
2368 log(" verific -vlog-undef <macro>..\n");
2369 log("\n");
2370 log("Remove Verilog defines previously set with -vlog-define.\n");
2371 log("\n");
2372 log("\n");
2373 log(" verific -set-error <msg_id>..\n");
2374 log(" verific -set-warning <msg_id>..\n");
2375 log(" verific -set-info <msg_id>..\n");
2376 log(" verific -set-ignore <msg_id>..\n");
2377 log("\n");
2378 log("Set message severity. <msg_id> is the string in square brackets when a message\n");
2379 log("is printed, such as VERI-1209.\n");
2380 log("\n");
2381 log("\n");
2382 log(" verific -import [options] <top-module>..\n");
2383 log("\n");
2384 log("Elaborate the design for the specified top modules, import to Yosys and\n");
2385 log("reset the internal state of Verific.\n");
2386 log("\n");
2387 log("Import options:\n");
2388 log("\n");
2389 log(" -all\n");
2390 log(" Elaborate all modules, not just the hierarchy below the given top\n");
2391 log(" modules. With this option the list of modules to import is optional.\n");
2392 log("\n");
2393 log(" -gates\n");
2394 log(" Create a gate-level netlist.\n");
2395 log("\n");
2396 log(" -flatten\n");
2397 log(" Flatten the design in Verific before importing.\n");
2398 log("\n");
2399 log(" -extnets\n");
2400 log(" Resolve references to external nets by adding module ports as needed.\n");
2401 log("\n");
2402 log(" -autocover\n");
2403 log(" Generate automatic cover statements for all asserts\n");
2404 log("\n");
2405 log(" -fullinit\n");
2406 log(" Keep all register initializations, even those for non-FF registers.\n");
2407 log("\n");
2408 log(" -chparam name value \n");
2409 log(" Elaborate the specified top modules (all modules when -all given) using\n");
2410 log(" this parameter value. Modules on which this parameter does not exist will\n");
2411 log(" cause Verific to produce a VERI-1928 or VHDL-1676 message. This option\n");
2412 log(" can be specified multiple times to override multiple parameters.\n");
2413 log(" String values must be passed in double quotes (\").\n");
2414 log("\n");
2415 log(" -v, -vv\n");
2416 log(" Verbose log messages. (-vv is even more verbose than -v.)\n");
2417 log("\n");
2418 log("The following additional import options are useful for debugging the Verific\n");
2419 log("bindings (for Yosys and/or Verific developers):\n");
2420 log("\n");
2421 log(" -k\n");
2422 log(" Keep going after an unsupported verific primitive is found. The\n");
2423 log(" unsupported primitive is added as blockbox module to the design.\n");
2424 log(" This will also add all SVA related cells to the design parallel to\n");
2425 log(" the checker logic inferred by it.\n");
2426 log("\n");
2427 log(" -V\n");
2428 log(" Import Verific netlist as-is without translating to Yosys cell types. \n");
2429 log("\n");
2430 log(" -nosva\n");
2431 log(" Ignore SVA properties, do not infer checker logic.\n");
2432 log("\n");
2433 log(" -L <int>\n");
2434 log(" Maximum number of ctrl bits for SVA checker FSMs (default=16).\n");
2435 log("\n");
2436 log(" -n\n");
2437 log(" Keep all Verific names on instances and nets. By default only\n");
2438 log(" user-declared names are preserved.\n");
2439 log("\n");
2440 log(" -d <dump_file>\n");
2441 log(" Dump the Verific netlist as a verilog file.\n");
2442 log("\n");
2443 log("\n");
2444 log(" verific [-work <libname>] -pp [options] <filename> [<module>]..\n");
2445 log("\n");
2446 log("Pretty print design (or just module) to the specified file from the\n");
2447 log("specified library. (default library when -work is not present: \"work\")\n");
2448 log("\n");
2449 log("Pretty print options:\n");
2450 log("\n");
2451 log(" -verilog\n");
2452 log(" Save output for Verilog/SystemVerilog design modules (default).\n");
2453 log("\n");
2454 log(" -vhdl\n");
2455 log(" Save output for VHDL design units.\n");
2456 log("\n");
2457 log("\n");
2458 log(" verific -app <application>..\n");
2459 log("\n");
2460 log("Execute YosysHQ formal application on loaded Verilog files.\n");
2461 log("\n");
2462 log("Application options:\n");
2463 log("\n");
2464 log(" -module <module>\n");
2465 log(" Run formal application only on specified module.\n");
2466 log("\n");
2467 log(" -blacklist <filename[:lineno]>\n");
2468 log(" Do not run application on modules from files that match the filename\n");
2469 log(" or filename and line number if provided in such format.\n");
2470 log(" Parameter can also contain comma separated list of file locations.\n");
2471 log("\n");
2472 log(" -blfile <file>\n");
2473 log(" Do not run application on locations specified in file, they can represent filename\n");
2474 log(" or filename and location in file.\n");
2475 log("\n");
2476 log("Applications:\n");
2477 log("\n");
2478 #if defined(YOSYS_ENABLE_VERIFIC) && defined(YOSYSHQ_VERIFIC_FORMALAPPS)
2479 VerificFormalApplications vfa;
2480 log("%s\n",vfa.GetHelp().c_str());
2481 #else
2482 log(" WARNING: Applications only available in commercial build.\n");
2483
2484 #endif
2485 log("\n");
2486 log("\n");
2487 log(" verific -template <name> <top_module>..\n");
2488 log("\n");
2489 log("Generate template for specified top module of loaded design.\n");
2490 log("\n");
2491 log("Template options:\n");
2492 log("\n");
2493 log(" -out\n");
2494 log(" Specifies output file for generated template, by default output is stdout\n");
2495 log("\n");
2496 log(" -chparam name value \n");
2497 log(" Generate template using this parameter value. Otherwise default parameter\n");
2498 log(" values will be used for templat generate functionality. This option\n");
2499 log(" can be specified multiple times to override multiple parameters.\n");
2500 log(" String values must be passed in double quotes (\").\n");
2501 log("\n");
2502 log("Templates:\n");
2503 log("\n");
2504 #if defined(YOSYS_ENABLE_VERIFIC) && defined(YOSYSHQ_VERIFIC_TEMPLATES)
2505 VerificTemplateGenerator vfg;
2506 log("%s\n",vfg.GetHelp().c_str());
2507 #else
2508 log(" WARNING: Templates only available in commercial build.\n");
2509 log("\n");
2510 #endif
2511 log("\n");
2512 log("\n");
2513 log(" verific -cfg [<name> [<value>]]\n");
2514 log("\n");
2515 log("Get/set Verific runtime flags.\n");
2516 log("\n");
2517 log("\n");
2518 log("Use YosysHQ Tabby CAD Suite if you need Yosys+Verific.\n");
2519 log("https://www.yosyshq.com/\n");
2520 log("\n");
2521 log("Contact office@yosyshq.com for free evaluation\n");
2522 log("binaries of YosysHQ Tabby CAD Suite.\n");
2523 log("\n");
2524 }
2525 #ifdef YOSYS_ENABLE_VERIFIC
2526 void execute(std::vector<std::string> args, RTLIL::Design *design) override
2527 {
2528 static bool set_verific_global_flags = true;
2529
2530 if (check_noverific_env())
2531 log_cmd_error("This version of Yosys is built without Verific support.\n"
2532 "\n"
2533 "Use YosysHQ Tabby CAD Suite if you need Yosys+Verific.\n"
2534 "https://www.yosyshq.com/\n"
2535 "\n"
2536 "Contact office@yosyshq.com for free evaluation\n"
2537 "binaries of YosysHQ Tabby CAD Suite.\n");
2538
2539 log_header(design, "Executing VERIFIC (loading SystemVerilog and VHDL designs using Verific).\n");
2540
2541 if (set_verific_global_flags)
2542 {
2543 Message::SetConsoleOutput(0);
2544 Message::RegisterCallBackMsg(msg_func);
2545
2546 RuntimeFlags::SetVar("db_preserve_user_instances", 1);
2547 RuntimeFlags::SetVar("db_preserve_user_nets", 1);
2548 RuntimeFlags::SetVar("db_preserve_x", 1);
2549
2550 RuntimeFlags::SetVar("db_allow_external_nets", 1);
2551 RuntimeFlags::SetVar("db_infer_wide_operators", 1);
2552 RuntimeFlags::SetVar("db_infer_set_reset_registers", 0);
2553
2554 RuntimeFlags::SetVar("veri_extract_dualport_rams", 0);
2555 RuntimeFlags::SetVar("veri_extract_multiport_rams", 1);
2556 RuntimeFlags::SetVar("veri_allow_any_ram_in_loop", 1);
2557
2558 #ifdef VERIFIC_VHDL_SUPPORT
2559 RuntimeFlags::SetVar("vhdl_extract_dualport_rams", 0);
2560 RuntimeFlags::SetVar("vhdl_extract_multiport_rams", 1);
2561 RuntimeFlags::SetVar("vhdl_allow_any_ram_in_loop", 1);
2562
2563 RuntimeFlags::SetVar("vhdl_support_variable_slice", 1);
2564 RuntimeFlags::SetVar("vhdl_ignore_assertion_statements", 0);
2565
2566 RuntimeFlags::SetVar("vhdl_preserve_assignments", 1);
2567 //RuntimeFlags::SetVar("vhdl_preserve_comments", 1);
2568 RuntimeFlags::SetVar("vhdl_preserve_drivers", 1);
2569 #endif
2570 RuntimeFlags::SetVar("veri_preserve_assignments", 1);
2571 RuntimeFlags::SetVar("veri_preserve_comments", 1);
2572 RuntimeFlags::SetVar("veri_preserve_drivers", 1);
2573
2574 // Workaround for VIPER #13851
2575 RuntimeFlags::SetVar("veri_create_name_for_unnamed_gen_block", 1);
2576
2577 // WARNING: instantiating unknown module 'XYZ' (VERI-1063)
2578 Message::SetMessageType("VERI-1063", VERIFIC_ERROR);
2579
2580 // https://github.com/YosysHQ/yosys/issues/1055
2581 RuntimeFlags::SetVar("veri_elaborate_top_level_modules_having_interface_ports", 1) ;
2582
2583 RuntimeFlags::SetVar("verific_produce_verbose_syntax_error_message", 1);
2584
2585 #ifndef DB_PRESERVE_INITIAL_VALUE
2586 # warning Verific was built without DB_PRESERVE_INITIAL_VALUE.
2587 #endif
2588
2589 set_verific_global_flags = false;
2590 }
2591
2592 verific_verbose = 0;
2593 verific_sva_fsm_limit = 16;
2594
2595 const char *release_str = Message::ReleaseString();
2596 time_t release_time = Message::ReleaseDate();
2597 char *release_tmstr = ctime(&release_time);
2598
2599 if (release_str == nullptr)
2600 release_str = "(no release string)";
2601
2602 for (char *p = release_tmstr; *p; p++)
2603 if (*p == '\n') *p = 0;
2604
2605 log("Built with Verific %s, released at %s.\n", release_str, release_tmstr);
2606
2607 int argidx = 1;
2608 std::string work = "work";
2609
2610 if (GetSize(args) > argidx && (args[argidx] == "-set-error" || args[argidx] == "-set-warning" ||
2611 args[argidx] == "-set-info" || args[argidx] == "-set-ignore"))
2612 {
2613 msg_type_t new_type;
2614
2615 if (args[argidx] == "-set-error")
2616 new_type = VERIFIC_ERROR;
2617 else if (args[argidx] == "-set-warning")
2618 new_type = VERIFIC_WARNING;
2619 else if (args[argidx] == "-set-info")
2620 new_type = VERIFIC_INFO;
2621 else if (args[argidx] == "-set-ignore")
2622 new_type = VERIFIC_IGNORE;
2623 else
2624 log_abort();
2625
2626 for (argidx++; argidx < GetSize(args); argidx++)
2627 Message::SetMessageType(args[argidx].c_str(), new_type);
2628
2629 goto check_error;
2630 }
2631
2632 if (GetSize(args) > argidx && args[argidx] == "-vlog-incdir") {
2633 for (argidx++; argidx < GetSize(args); argidx++)
2634 verific_incdirs.push_back(args[argidx]);
2635 goto check_error;
2636 }
2637
2638 if (GetSize(args) > argidx && args[argidx] == "-vlog-libdir") {
2639 for (argidx++; argidx < GetSize(args); argidx++)
2640 verific_libdirs.push_back(args[argidx]);
2641 goto check_error;
2642 }
2643
2644 if (GetSize(args) > argidx && args[argidx] == "-vlog-define") {
2645 for (argidx++; argidx < GetSize(args); argidx++) {
2646 string name = args[argidx];
2647 size_t equal = name.find('=');
2648 if (equal != std::string::npos) {
2649 string value = name.substr(equal+1);
2650 name = name.substr(0, equal);
2651 veri_file::DefineCmdLineMacro(name.c_str(), value.c_str());
2652 } else {
2653 veri_file::DefineCmdLineMacro(name.c_str());
2654 }
2655 }
2656 goto check_error;
2657 }
2658
2659 if (GetSize(args) > argidx && args[argidx] == "-vlog-undef") {
2660 for (argidx++; argidx < GetSize(args); argidx++) {
2661 string name = args[argidx];
2662 veri_file::UndefineMacro(name.c_str());
2663 }
2664 goto check_error;
2665 }
2666
2667 veri_file::RemoveAllLOptions();
2668 for (; argidx < GetSize(args); argidx++)
2669 {
2670 if (args[argidx] == "-work" && argidx+1 < GetSize(args)) {
2671 work = args[++argidx];
2672 continue;
2673 }
2674 if (args[argidx] == "-L" && argidx+1 < GetSize(args)) {
2675 veri_file::AddLOption(args[++argidx].c_str());
2676 continue;
2677 }
2678 break;
2679 }
2680
2681 if (GetSize(args) > argidx && (args[argidx] == "-f" || args[argidx] == "-F"))
2682 {
2683 unsigned verilog_mode = veri_file::VERILOG_95; // default recommended by Verific
2684 bool is_formal = false;
2685 const char* filename = nullptr;
2686
2687 Verific::veri_file::f_file_flags flags = (args[argidx] == "-f") ? veri_file::F_FILE_NONE : veri_file::F_FILE_CAPITAL;
2688
2689 for (argidx++; argidx < GetSize(args); argidx++) {
2690 if (args[argidx] == "-vlog95") {
2691 verilog_mode = veri_file::VERILOG_95;
2692 continue;
2693 } else if (args[argidx] == "-vlog2k") {
2694 verilog_mode = veri_file::VERILOG_2K;
2695 continue;
2696 } else if (args[argidx] == "-sv2005") {
2697 verilog_mode = veri_file::SYSTEM_VERILOG_2005;
2698 continue;
2699 } else if (args[argidx] == "-sv2009") {
2700 verilog_mode = veri_file::SYSTEM_VERILOG_2009;
2701 continue;
2702 } else if (args[argidx] == "-sv2012" || args[argidx] == "-sv" || args[argidx] == "-formal") {
2703 verilog_mode = veri_file::SYSTEM_VERILOG;
2704 if (args[argidx] == "-formal") is_formal = true;
2705 continue;
2706 } else if (args[argidx].compare(0, 1, "-") == 0) {
2707 cmd_error(args, argidx, "unknown option");
2708 goto check_error;
2709 }
2710
2711 if (!filename) {
2712 filename = args[argidx].c_str();
2713 continue;
2714 } else {
2715 log_cmd_error("Only one filename can be specified.\n");
2716 }
2717 }
2718 if (!filename)
2719 log_cmd_error("Filname must be specified.\n");
2720
2721 unsigned analysis_mode = verilog_mode; // keep default as provided by user if not defined in file
2722 Array *file_names = veri_file::ProcessFFile(filename, flags, analysis_mode);
2723 if (analysis_mode != verilog_mode)
2724 log_warning("Provided verilog mode differs from one specified in file.\n");
2725
2726 veri_file::DefineMacro("YOSYS");
2727 veri_file::DefineMacro("VERIFIC");
2728 veri_file::DefineMacro(is_formal ? "FORMAL" : "SYNTHESIS");
2729
2730 if (!veri_file::AnalyzeMultipleFiles(file_names, verilog_mode, work.c_str(), veri_file::MFCU)) {
2731 verific_error_msg.clear();
2732 log_cmd_error("Reading Verilog/SystemVerilog sources failed.\n");
2733 }
2734
2735 delete file_names;
2736 verific_import_pending = true;
2737 goto check_error;
2738 }
2739
2740 if (GetSize(args) > argidx && (args[argidx] == "-vlog95" || args[argidx] == "-vlog2k" || args[argidx] == "-sv2005" ||
2741 args[argidx] == "-sv2009" || args[argidx] == "-sv2012" || args[argidx] == "-sv" || args[argidx] == "-formal"))
2742 {
2743 Array file_names;
2744 unsigned verilog_mode;
2745
2746 if (args[argidx] == "-vlog95")
2747 verilog_mode = veri_file::VERILOG_95;
2748 else if (args[argidx] == "-vlog2k")
2749 verilog_mode = veri_file::VERILOG_2K;
2750 else if (args[argidx] == "-sv2005")
2751 verilog_mode = veri_file::SYSTEM_VERILOG_2005;
2752 else if (args[argidx] == "-sv2009")
2753 verilog_mode = veri_file::SYSTEM_VERILOG_2009;
2754 else if (args[argidx] == "-sv2012" || args[argidx] == "-sv" || args[argidx] == "-formal")
2755 verilog_mode = veri_file::SYSTEM_VERILOG;
2756 else
2757 log_abort();
2758
2759 veri_file::DefineMacro("YOSYS");
2760 veri_file::DefineMacro("VERIFIC");
2761 veri_file::DefineMacro(args[argidx] == "-formal" ? "FORMAL" : "SYNTHESIS");
2762
2763 for (argidx++; argidx < GetSize(args) && GetSize(args[argidx]) >= 2 && args[argidx].compare(0, 2, "-D") == 0; argidx++) {
2764 std::string name = args[argidx].substr(2);
2765 if (args[argidx] == "-D") {
2766 if (++argidx >= GetSize(args))
2767 break;
2768 name = args[argidx];
2769 }
2770 size_t equal = name.find('=');
2771 if (equal != std::string::npos) {
2772 string value = name.substr(equal+1);
2773 name = name.substr(0, equal);
2774 veri_file::DefineMacro(name.c_str(), value.c_str());
2775 } else {
2776 veri_file::DefineMacro(name.c_str());
2777 }
2778 }
2779
2780 for (auto &dir : verific_incdirs)
2781 veri_file::AddIncludeDir(dir.c_str());
2782 for (auto &dir : verific_libdirs)
2783 veri_file::AddYDir(dir.c_str());
2784
2785 while (argidx < GetSize(args))
2786 file_names.Insert(args[argidx++].c_str());
2787
2788 if (!veri_file::AnalyzeMultipleFiles(&file_names, verilog_mode, work.c_str(), veri_file::MFCU)) {
2789 verific_error_msg.clear();
2790 log_cmd_error("Reading Verilog/SystemVerilog sources failed.\n");
2791 }
2792
2793 verific_import_pending = true;
2794 goto check_error;
2795 }
2796
2797 #ifdef VERIFIC_VHDL_SUPPORT
2798 if (GetSize(args) > argidx && args[argidx] == "-vhdl87") {
2799 vhdl_file::SetDefaultLibraryPath((proc_share_dirname() + "verific/vhdl_vdbs_1987").c_str());
2800 for (argidx++; argidx < GetSize(args); argidx++)
2801 if (!vhdl_file::Analyze(args[argidx].c_str(), work.c_str(), vhdl_file::VHDL_87))
2802 log_cmd_error("Reading `%s' in VHDL_87 mode failed.\n", args[argidx].c_str());
2803 verific_import_pending = true;
2804 goto check_error;
2805 }
2806
2807 if (GetSize(args) > argidx && args[argidx] == "-vhdl93") {
2808 vhdl_file::SetDefaultLibraryPath((proc_share_dirname() + "verific/vhdl_vdbs_1993").c_str());
2809 for (argidx++; argidx < GetSize(args); argidx++)
2810 if (!vhdl_file::Analyze(args[argidx].c_str(), work.c_str(), vhdl_file::VHDL_93))
2811 log_cmd_error("Reading `%s' in VHDL_93 mode failed.\n", args[argidx].c_str());
2812 verific_import_pending = true;
2813 goto check_error;
2814 }
2815
2816 if (GetSize(args) > argidx && args[argidx] == "-vhdl2k") {
2817 vhdl_file::SetDefaultLibraryPath((proc_share_dirname() + "verific/vhdl_vdbs_1993").c_str());
2818 for (argidx++; argidx < GetSize(args); argidx++)
2819 if (!vhdl_file::Analyze(args[argidx].c_str(), work.c_str(), vhdl_file::VHDL_2K))
2820 log_cmd_error("Reading `%s' in VHDL_2K mode failed.\n", args[argidx].c_str());
2821 verific_import_pending = true;
2822 goto check_error;
2823 }
2824
2825 if (GetSize(args) > argidx && (args[argidx] == "-vhdl2008" || args[argidx] == "-vhdl")) {
2826 vhdl_file::SetDefaultLibraryPath((proc_share_dirname() + "verific/vhdl_vdbs_2008").c_str());
2827 for (argidx++; argidx < GetSize(args); argidx++)
2828 if (!vhdl_file::Analyze(args[argidx].c_str(), work.c_str(), vhdl_file::VHDL_2008))
2829 log_cmd_error("Reading `%s' in VHDL_2008 mode failed.\n", args[argidx].c_str());
2830 verific_import_pending = true;
2831 goto check_error;
2832 }
2833 #endif
2834
2835 #ifdef YOSYSHQ_VERIFIC_FORMALAPPS
2836 if (argidx < GetSize(args) && args[argidx] == "-app")
2837 {
2838 if (!(argidx+1 < GetSize(args)))
2839 cmd_error(args, argidx, "No formal application specified.\n");
2840
2841 VerificFormalApplications vfa;
2842 auto apps = vfa.GetApps();
2843 std::string app = args[++argidx];
2844 std::vector<std::string> blacklists;
2845 if (apps.find(app) == apps.end())
2846 log_cmd_error("Application '%s' does not exist.\n", app.c_str());
2847
2848 FormalApplication *application = apps[app];
2849 application->setLogger([](std::string msg) { log("%s",msg.c_str()); } );
2850 VeriModule *selected_module = nullptr;
2851
2852 for (argidx++; argidx < GetSize(args); argidx++) {
2853 std::string error;
2854 if (application->checkParams(args, argidx, error)) {
2855 if (!error.empty())
2856 cmd_error(args, argidx, error);
2857 continue;
2858 }
2859
2860 if (args[argidx] == "-module" && argidx < GetSize(args)) {
2861 if (!(argidx+1 < GetSize(args)))
2862 cmd_error(args, argidx+1, "No module name specified.\n");
2863 std::string module = args[++argidx];
2864 VeriLibrary* veri_lib = veri_file::GetLibrary(work.c_str(), 1);
2865 selected_module = veri_lib ? veri_lib->GetModule(module.c_str(), 1) : nullptr;
2866 if (!selected_module) {
2867 log_error("Can't find module '%s'.\n", module.c_str());
2868 }
2869 continue;
2870 }
2871 if (args[argidx] == "-blacklist" && argidx < GetSize(args)) {
2872 if (!(argidx+1 < GetSize(args)))
2873 cmd_error(args, argidx+1, "No blacklist specified.\n");
2874
2875 std::string line = args[++argidx];
2876 std::string p;
2877 while (!(p = next_token(line, ",\t\r\n ")).empty())
2878 blacklists.push_back(p);
2879 continue;
2880 }
2881 if (args[argidx] == "-blfile" && argidx < GetSize(args)) {
2882 if (!(argidx+1 < GetSize(args)))
2883 cmd_error(args, argidx+1, "No blacklist file specified.\n");
2884 std::string fn = args[++argidx];
2885 std::ifstream f(fn);
2886 if (f.fail())
2887 log_cmd_error("Can't open blacklist file '%s'!\n", fn.c_str());
2888
2889 std::string line,p;
2890 while (std::getline(f, line)) {
2891 while (!(p = next_token(line, ",\t\r\n ")).empty())
2892 blacklists.push_back(p);
2893 }
2894 continue;
2895 }
2896 break;
2897 }
2898 if (argidx < GetSize(args))
2899 cmd_error(args, argidx, "unknown option/parameter");
2900
2901 application->setBlacklists(&blacklists);
2902 application->setSingleModuleMode(selected_module!=nullptr);
2903
2904 const char *err = application->validate();
2905 if (err)
2906 cmd_error(args, argidx, err);
2907
2908 MapIter mi;
2909 VeriLibrary *veri_lib = veri_file::GetLibrary(work.c_str(), 1);
2910 log("Running formal application '%s'.\n", app.c_str());
2911
2912 if (selected_module) {
2913 std::string out;
2914 if (!application->execute(selected_module, out))
2915 log_error("%s", out.c_str());
2916 }
2917 else {
2918 VeriModule *module ;
2919 FOREACH_VERILOG_MODULE_IN_LIBRARY(veri_lib, mi, module) {
2920 std::string out;
2921 if (!application->execute(module, out)) {
2922 log_error("%s", out.c_str());
2923 break;
2924 }
2925 }
2926 }
2927 goto check_error;
2928 }
2929 #endif
2930 if (argidx < GetSize(args) && args[argidx] == "-pp")
2931 {
2932 const char* filename = nullptr;
2933 const char* module = nullptr;
2934 bool mode_vhdl = false;
2935 for (argidx++; argidx < GetSize(args); argidx++) {
2936 #ifdef VERIFIC_VHDL_SUPPORT
2937 if (args[argidx] == "-vhdl") {
2938 mode_vhdl = true;
2939 continue;
2940 }
2941 #endif
2942 if (args[argidx] == "-verilog") {
2943 mode_vhdl = false;
2944 continue;
2945 }
2946
2947 if (args[argidx].compare(0, 1, "-") == 0) {
2948 cmd_error(args, argidx, "unknown option");
2949 goto check_error;
2950 }
2951
2952 if (!filename) {
2953 filename = args[argidx].c_str();
2954 continue;
2955 }
2956 if (module)
2957 log_cmd_error("Only one module can be specified.\n");
2958 module = args[argidx].c_str();
2959 }
2960
2961 if (argidx < GetSize(args))
2962 cmd_error(args, argidx, "unknown option/parameter");
2963
2964 if (!filename)
2965 log_cmd_error("Filname must be specified.\n");
2966
2967 if (mode_vhdl)
2968 #ifdef VERIFIC_VHDL_SUPPORT
2969 vhdl_file::PrettyPrint(filename, module, work.c_str());
2970 #else
2971 goto check_error;
2972 #endif
2973 else
2974 veri_file::PrettyPrint(filename, module, work.c_str());
2975 goto check_error;
2976 }
2977
2978 #ifdef YOSYSHQ_VERIFIC_TEMPLATES
2979 if (argidx < GetSize(args) && args[argidx] == "-template")
2980 {
2981 if (!(argidx+1 < GetSize(args)))
2982 cmd_error(args, argidx+1, "No template type specified.\n");
2983
2984 VerificTemplateGenerator vfg;
2985 auto gens = vfg.GetGenerators();
2986 std::string app = args[++argidx];
2987 if (gens.find(app) == gens.end())
2988 log_cmd_error("Template generator '%s' does not exist.\n", app.c_str());
2989 TemplateGenerator *generator = gens[app];
2990 if (!(argidx+1 < GetSize(args)))
2991 cmd_error(args, argidx+1, "No top module specified.\n");
2992 generator->setLogger([](std::string msg) { log("%s",msg.c_str()); } );
2993
2994 std::string module = args[++argidx];
2995 VeriLibrary* veri_lib = veri_file::GetLibrary(work.c_str(), 1);
2996 VeriModule *veri_module = veri_lib ? veri_lib->GetModule(module.c_str(), 1) : nullptr;
2997 if (!veri_module) {
2998 log_error("Can't find module/unit '%s'.\n", module.c_str());
2999 }
3000
3001 log("Template '%s' is running for module '%s'.\n", app.c_str(),module.c_str());
3002
3003 Map parameters(STRING_HASH);
3004 const char *out_filename = nullptr;
3005
3006 for (argidx++; argidx < GetSize(args); argidx++) {
3007 std::string error;
3008 if (generator->checkParams(args, argidx, error)) {
3009 if (!error.empty())
3010 cmd_error(args, argidx, error);
3011 continue;
3012 }
3013
3014 if (args[argidx] == "-chparam" && argidx < GetSize(args)) {
3015 if (!(argidx+1 < GetSize(args)))
3016 cmd_error(args, argidx+1, "No param name specified.\n");
3017 if (!(argidx+2 < GetSize(args)))
3018 cmd_error(args, argidx+2, "No param value specified.\n");
3019
3020 const std::string &key = args[++argidx];
3021 const std::string &value = args[++argidx];
3022 unsigned new_insertion = parameters.Insert(key.c_str(), value.c_str(),
3023 1 /* force_overwrite */);
3024 if (!new_insertion)
3025 log_warning_noprefix("-chparam %s already specified: overwriting.\n", key.c_str());
3026 continue;
3027 }
3028
3029 if (args[argidx] == "-out" && argidx < GetSize(args)) {
3030 if (!(argidx+1 < GetSize(args)))
3031 cmd_error(args, argidx+1, "No output file specified.\n");
3032 out_filename = args[++argidx].c_str();
3033 continue;
3034 }
3035
3036 break;
3037 }
3038 if (argidx < GetSize(args))
3039 cmd_error(args, argidx, "unknown option/parameter");
3040
3041 const char *err = generator->validate();
3042 if (err)
3043 cmd_error(args, argidx, err);
3044
3045 std::string val;
3046 if (!generator->generate(veri_module, val, &parameters))
3047 log_error("%s", val.c_str());
3048
3049 FILE *of = stdout;
3050 if (out_filename) {
3051 of = fopen(out_filename, "w");
3052 if (of == nullptr)
3053 log_error("Can't open '%s' for writing: %s\n", out_filename, strerror(errno));
3054 log("Writing output to '%s'\n",out_filename);
3055 }
3056 fprintf(of, "%s\n",val.c_str());
3057 fflush(of);
3058 if (of!=stdout)
3059 fclose(of);
3060 goto check_error;
3061 }
3062 #endif
3063 if (GetSize(args) > argidx && args[argidx] == "-import")
3064 {
3065 std::map<std::string,Netlist*> nl_todo, nl_done;
3066 bool mode_all = false, mode_gates = false, mode_keep = false;
3067 bool mode_nosva = false, mode_names = false, mode_verific = false;
3068 bool mode_autocover = false, mode_fullinit = false;
3069 bool flatten = false, extnets = false;
3070 string dumpfile;
3071 Map parameters(STRING_HASH);
3072
3073 for (argidx++; argidx < GetSize(args); argidx++) {
3074 if (args[argidx] == "-all") {
3075 mode_all = true;
3076 continue;
3077 }
3078 if (args[argidx] == "-gates") {
3079 mode_gates = true;
3080 continue;
3081 }
3082 if (args[argidx] == "-flatten") {
3083 flatten = true;
3084 continue;
3085 }
3086 if (args[argidx] == "-extnets") {
3087 extnets = true;
3088 continue;
3089 }
3090 if (args[argidx] == "-k") {
3091 mode_keep = true;
3092 continue;
3093 }
3094 if (args[argidx] == "-nosva") {
3095 mode_nosva = true;
3096 continue;
3097 }
3098 if (args[argidx] == "-L" && argidx+1 < GetSize(args)) {
3099 verific_sva_fsm_limit = atoi(args[++argidx].c_str());
3100 continue;
3101 }
3102 if (args[argidx] == "-n") {
3103 mode_names = true;
3104 continue;
3105 }
3106 if (args[argidx] == "-autocover") {
3107 mode_autocover = true;
3108 continue;
3109 }
3110 if (args[argidx] == "-fullinit") {
3111 mode_fullinit = true;
3112 continue;
3113 }
3114 if (args[argidx] == "-chparam" && argidx+2 < GetSize(args)) {
3115 const std::string &key = args[++argidx];
3116 const std::string &value = args[++argidx];
3117 unsigned new_insertion = parameters.Insert(key.c_str(), value.c_str(),
3118 1 /* force_overwrite */);
3119 if (!new_insertion)
3120 log_warning_noprefix("-chparam %s already specified: overwriting.\n", key.c_str());
3121 continue;
3122 }
3123 if (args[argidx] == "-V") {
3124 mode_verific = true;
3125 continue;
3126 }
3127 if (args[argidx] == "-v") {
3128 verific_verbose = 1;
3129 continue;
3130 }
3131 if (args[argidx] == "-vv") {
3132 verific_verbose = 2;
3133 continue;
3134 }
3135 if (args[argidx] == "-d" && argidx+1 < GetSize(args)) {
3136 dumpfile = args[++argidx];
3137 continue;
3138 }
3139 break;
3140 }
3141
3142 if (argidx > GetSize(args) && args[argidx].compare(0, 1, "-") == 0)
3143 cmd_error(args, argidx, "unknown option");
3144
3145 std::set<std::string> top_mod_names;
3146
3147 #ifdef YOSYSHQ_VERIFIC_EXTENSIONS
3148 InitialAssertions::Rewrite(work, &parameters);
3149 #endif
3150 if (mode_all)
3151 {
3152 log("Running hier_tree::ElaborateAll().\n");
3153
3154 VeriLibrary *veri_lib = veri_file::GetLibrary(work.c_str(), 1);
3155
3156 Array veri_libs, vhdl_libs;
3157 #ifdef VERIFIC_VHDL_SUPPORT
3158 VhdlLibrary *vhdl_lib = vhdl_file::GetLibrary(work.c_str(), 1);
3159 if (vhdl_lib) vhdl_libs.InsertLast(vhdl_lib);
3160 #endif
3161 if (veri_lib) veri_libs.InsertLast(veri_lib);
3162
3163 Array *netlists = hier_tree::ElaborateAll(&veri_libs, &vhdl_libs, &parameters);
3164 Netlist *nl;
3165 int i;
3166
3167 FOREACH_ARRAY_ITEM(netlists, i, nl)
3168 nl_todo.emplace(nl->CellBaseName(), nl);
3169 delete netlists;
3170 }
3171 else
3172 {
3173 if (argidx == GetSize(args))
3174 cmd_error(args, argidx, "No top module specified.\n");
3175
3176 VeriLibrary* veri_lib = veri_file::GetLibrary(work.c_str(), 1);
3177 #ifdef VERIFIC_VHDL_SUPPORT
3178 VhdlLibrary *vhdl_lib = vhdl_file::GetLibrary(work.c_str(), 1);
3179 #endif
3180
3181 Array veri_modules, vhdl_units;
3182 for (; argidx < GetSize(args); argidx++)
3183 {
3184 const char *name = args[argidx].c_str();
3185 top_mod_names.insert(name);
3186
3187 VeriModule *veri_module = veri_lib ? veri_lib->GetModule(name, 1) : nullptr;
3188 if (veri_module) {
3189 log("Adding Verilog module '%s' to elaboration queue.\n", name);
3190 veri_modules.InsertLast(veri_module);
3191 continue;
3192 }
3193 #ifdef VERIFIC_VHDL_SUPPORT
3194 VhdlDesignUnit *vhdl_unit = vhdl_lib ? vhdl_lib->GetPrimUnit(name) : nullptr;
3195 if (vhdl_unit) {
3196 log("Adding VHDL unit '%s' to elaboration queue.\n", name);
3197 vhdl_units.InsertLast(vhdl_unit);
3198 continue;
3199 }
3200 #endif
3201 log_error("Can't find module/unit '%s'.\n", name);
3202 }
3203
3204 if (veri_lib) {
3205 // Also elaborate all root modules since they may contain bind statements
3206 MapIter mi;
3207 VeriModule *veri_module;
3208 FOREACH_VERILOG_MODULE_IN_LIBRARY(veri_lib, mi, veri_module) {
3209 if (!veri_module->IsRootModule()) continue;
3210 veri_modules.InsertLast(veri_module);
3211 }
3212 }
3213
3214 log("Running hier_tree::Elaborate().\n");
3215 Array *netlists = hier_tree::Elaborate(&veri_modules, &vhdl_units, &parameters);
3216 Netlist *nl;
3217 int i;
3218
3219 FOREACH_ARRAY_ITEM(netlists, i, nl) {
3220 if (!top_mod_names.count(nl->CellBaseName()))
3221 continue;
3222 nl->AddAtt(new Att(" \\top", NULL));
3223 nl_todo.emplace(nl->CellBaseName(), nl);
3224 }
3225 delete netlists;
3226 }
3227
3228 if (!verific_error_msg.empty())
3229 goto check_error;
3230
3231 if (flatten) {
3232 for (auto nl : nl_todo)
3233 nl.second->Flatten();
3234 }
3235
3236 if (extnets) {
3237 VerificExtNets worker;
3238 for (auto nl : nl_todo)
3239 worker.run(nl.second);
3240 }
3241
3242 for (auto nl : nl_todo)
3243 nl.second->ChangePortBusStructures(1 /* hierarchical */);
3244
3245 if (!dumpfile.empty()) {
3246 VeriWrite veri_writer;
3247 veri_writer.WriteFile(dumpfile.c_str(), Netlist::PresentDesign());
3248 }
3249
3250 while (!nl_todo.empty()) {
3251 auto it = nl_todo.begin();
3252 Netlist *nl = it->second;
3253 if (nl_done.count(it->first) == 0) {
3254 VerificImporter importer(mode_gates, mode_keep, mode_nosva,
3255 mode_names, mode_verific, mode_autocover, mode_fullinit);
3256 nl_done[it->first] = it->second;
3257 importer.import_netlist(design, nl, nl_todo, top_mod_names.count(nl->Owner()->Name()));
3258 }
3259 nl_todo.erase(it);
3260 }
3261
3262 hier_tree::DeleteHierarchicalTree();
3263 veri_file::Reset();
3264 #ifdef VERIFIC_VHDL_SUPPORT
3265 vhdl_file::Reset();
3266 #endif
3267 Libset::Reset();
3268 Message::Reset();
3269 RuntimeFlags::DeleteAllFlags();
3270 LineFile::DeleteAllLineFiles();
3271 verific_incdirs.clear();
3272 verific_libdirs.clear();
3273 verific_import_pending = false;
3274 goto check_error;
3275 }
3276
3277 if (argidx < GetSize(args) && args[argidx] == "-cfg")
3278 {
3279 if (argidx+1 == GetSize(args)) {
3280 MapIter mi;
3281 const char *k, *s;
3282 unsigned long v;
3283 pool<std::string> lines;
3284 FOREACH_MAP_ITEM(RuntimeFlags::GetVarMap(), mi, &k, &v) {
3285 lines.insert(stringf("%s %lu", k, v));
3286 }
3287 FOREACH_MAP_ITEM(RuntimeFlags::GetStringVarMap(), mi, &k, &s) {
3288 if (s == nullptr)
3289 lines.insert(stringf("%s NULL", k));
3290 else
3291 lines.insert(stringf("%s \"%s\"", k, s));
3292 }
3293 lines.sort();
3294 for (auto &line : lines)
3295 log("verific -cfg %s\n", line.c_str());
3296 goto check_error;
3297 }
3298
3299 if (argidx+2 == GetSize(args)) {
3300 const char *k = args[argidx+1].c_str();
3301 if (RuntimeFlags::HasUnsignedVar(k)) {
3302 log("verific -cfg %s %lu\n", k, RuntimeFlags::GetVar(k));
3303 goto check_error;
3304 }
3305 if (RuntimeFlags::HasStringVar(k)) {
3306 const char *s = RuntimeFlags::GetStringVar(k);
3307 if (s == nullptr)
3308 log("verific -cfg %s NULL\n", k);
3309 else
3310 log("verific -cfg %s \"%s\"\n", k, s);
3311 goto check_error;
3312 }
3313 log_cmd_error("Can't find Verific Runtime flag '%s'.\n", k);
3314 }
3315
3316 if (argidx+3 == GetSize(args)) {
3317 const auto &k = args[argidx+1], &v = args[argidx+2];
3318 if (v == "NULL") {
3319 RuntimeFlags::SetStringVar(k.c_str(), nullptr);
3320 goto check_error;
3321 }
3322 if (v[0] == '"') {
3323 std::string s = v.substr(1, GetSize(v)-2);
3324 RuntimeFlags::SetStringVar(k.c_str(), v.c_str());
3325 goto check_error;
3326 }
3327 char *endptr;
3328 unsigned long n = strtol(v.c_str(), &endptr, 0);
3329 if (*endptr == 0) {
3330 RuntimeFlags::SetVar(k.c_str(), n);
3331 goto check_error;
3332 }
3333 }
3334 }
3335
3336 cmd_error(args, argidx, "Missing or unsupported mode parameter.\n");
3337
3338 check_error:
3339 if (!verific_error_msg.empty())
3340 log_error("%s\n", verific_error_msg.c_str());
3341
3342 }
3343 #else /* YOSYS_ENABLE_VERIFIC */
3344 void execute(std::vector<std::string>, RTLIL::Design *) override {
3345 log_cmd_error("This version of Yosys is built without Verific support.\n"
3346 "\n"
3347 "Use YosysHQ Tabby CAD Suite if you need Yosys+Verific.\n"
3348 "https://www.yosyshq.com/\n"
3349 "\n"
3350 "Contact office@yosyshq.com for free evaluation\n"
3351 "binaries of YosysHQ Tabby CAD Suite.\n");
3352 }
3353 #endif
3354 } VerificPass;
3355
3356 struct ReadPass : public Pass {
3357 ReadPass() : Pass("read", "load HDL designs") { }
3358 void help() override
3359 {
3360 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
3361 log("\n");
3362 log(" read {-vlog95|-vlog2k|-sv2005|-sv2009|-sv2012|-sv|-formal} <verilog-file>..\n");
3363 log("\n");
3364 log("Load the specified Verilog/SystemVerilog files. (Full SystemVerilog support\n");
3365 log("is only available via Verific.)\n");
3366 log("\n");
3367 log("Additional -D<macro>[=<value>] options may be added after the option indicating\n");
3368 log("the language version (and before file names) to set additional verilog defines.\n");
3369 log("\n");
3370 log("\n");
3371 #ifdef VERIFIC_VHDL_SUPPORT
3372 log(" read {-vhdl87|-vhdl93|-vhdl2k|-vhdl2008|-vhdl} <vhdl-file>..\n");
3373 log("\n");
3374 log("Load the specified VHDL files. (Requires Verific.)\n");
3375 log("\n");
3376 log("\n");
3377 #endif
3378 log(" read {-f|-F} <command-file>\n");
3379 log("\n");
3380 log("Load and execute the specified command file. (Requires Verific.)\n");
3381 log("Check verific command for more information about supported commands in file.\n");
3382 log("\n");
3383 log("\n");
3384 log(" read -define <macro>[=<value>]..\n");
3385 log("\n");
3386 log("Set global Verilog/SystemVerilog defines.\n");
3387 log("\n");
3388 log("\n");
3389 log(" read -undef <macro>..\n");
3390 log("\n");
3391 log("Unset global Verilog/SystemVerilog defines.\n");
3392 log("\n");
3393 log("\n");
3394 log(" read -incdir <directory>\n");
3395 log("\n");
3396 log("Add directory to global Verilog/SystemVerilog include directories.\n");
3397 log("\n");
3398 log("\n");
3399 log(" read -verific\n");
3400 log(" read -noverific\n");
3401 log("\n");
3402 log("Subsequent calls to 'read' will either use or not use Verific. Calling 'read'\n");
3403 log("with -verific will result in an error on Yosys binaries that are built without\n");
3404 log("Verific support. The default is to use Verific if it is available.\n");
3405 log("\n");
3406 }
3407 void execute(std::vector<std::string> args, RTLIL::Design *design) override
3408 {
3409 #ifdef YOSYS_ENABLE_VERIFIC
3410 static bool verific_available = !check_noverific_env();
3411 #else
3412 static bool verific_available = false;
3413 #endif
3414 static bool use_verific = verific_available;
3415
3416 if (args.size() < 2 || args[1][0] != '-')
3417 cmd_error(args, 1, "Missing mode parameter.\n");
3418
3419 if (args[1] == "-verific" || args[1] == "-noverific") {
3420 if (args.size() != 2)
3421 cmd_error(args, 1, "Additional arguments to -verific/-noverific.\n");
3422 if (args[1] == "-verific") {
3423 if (!verific_available)
3424 cmd_error(args, 1, "This version of Yosys is built without Verific support.\n");
3425 use_verific = true;
3426 } else {
3427 use_verific = false;
3428 }
3429 return;
3430 }
3431
3432 if (args.size() < 3)
3433 cmd_error(args, 3, "Missing file name parameter.\n");
3434
3435 if (args[1] == "-vlog95" || args[1] == "-vlog2k") {
3436 if (use_verific) {
3437 args[0] = "verific";
3438 } else {
3439 args[0] = "read_verilog";
3440 args[1] = "-defer";
3441 }
3442 Pass::call(design, args);
3443 return;
3444 }
3445
3446 if (args[1] == "-sv2005" || args[1] == "-sv2009" || args[1] == "-sv2012" || args[1] == "-sv" || args[1] == "-formal") {
3447 if (use_verific) {
3448 args[0] = "verific";
3449 } else {
3450 args[0] = "read_verilog";
3451 if (args[1] == "-formal")
3452 args.insert(args.begin()+1, std::string());
3453 args[1] = "-sv";
3454 args.insert(args.begin()+1, "-defer");
3455 }
3456 Pass::call(design, args);
3457 return;
3458 }
3459
3460 #ifdef VERIFIC_VHDL_SUPPORT
3461 if (args[1] == "-vhdl87" || args[1] == "-vhdl93" || args[1] == "-vhdl2k" || args[1] == "-vhdl2008" || args[1] == "-vhdl") {
3462 if (use_verific) {
3463 args[0] = "verific";
3464 Pass::call(design, args);
3465 } else {
3466 cmd_error(args, 1, "This version of Yosys is built without Verific support.\n");
3467 }
3468 return;
3469 }
3470 #endif
3471 if (args[1] == "-f" || args[1] == "-F") {
3472 if (use_verific) {
3473 args[0] = "verific";
3474 Pass::call(design, args);
3475 } else {
3476 cmd_error(args, 1, "This version of Yosys is built without Verific support.\n");
3477 }
3478 return;
3479 }
3480
3481 if (args[1] == "-define") {
3482 if (use_verific) {
3483 args[0] = "verific";
3484 args[1] = "-vlog-define";
3485 Pass::call(design, args);
3486 }
3487 args[0] = "verilog_defines";
3488 args.erase(args.begin()+1, args.begin()+2);
3489 for (int i = 1; i < GetSize(args); i++)
3490 args[i] = "-D" + args[i];
3491 Pass::call(design, args);
3492 return;
3493 }
3494
3495 if (args[1] == "-undef") {
3496 if (use_verific) {
3497 args[0] = "verific";
3498 args[1] = "-vlog-undef";
3499 Pass::call(design, args);
3500 }
3501 args[0] = "verilog_defines";
3502 args.erase(args.begin()+1, args.begin()+2);
3503 for (int i = 1; i < GetSize(args); i++)
3504 args[i] = "-U" + args[i];
3505 Pass::call(design, args);
3506 return;
3507 }
3508
3509 if (args[1] == "-incdir") {
3510 if (use_verific) {
3511 args[0] = "verific";
3512 args[1] = "-vlog-incdir";
3513 Pass::call(design, args);
3514 }
3515 args[0] = "verilog_defaults";
3516 args[1] = "-add";
3517 for (int i = 2; i < GetSize(args); i++)
3518 args[i] = "-I" + args[i];
3519 Pass::call(design, args);
3520 return;
3521 }
3522
3523 cmd_error(args, 1, "Missing or unsupported mode parameter.\n");
3524 }
3525 } ReadPass;
3526
3527 PRIVATE_NAMESPACE_END