2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
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.
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.
20 #include "kernel/yosys.h"
21 #include "kernel/sigtools.h"
22 #include "kernel/celltypes.h"
23 #include "kernel/log.h"
33 #include "frontends/verific/verific.h"
37 #ifdef YOSYS_ENABLE_VERIFIC
40 #pragma clang diagnostic push
41 #pragma clang diagnostic ignored "-Woverloaded-virtual"
44 #include "veri_file.h"
45 #include "vhdl_file.h"
46 #include "hier_tree.h"
47 #include "VeriModule.h"
48 #include "VeriWrite.h"
49 #include "VhdlUnits.h"
50 #include "VeriLibrary.h"
51 #include "VeriExtensions.h"
53 #ifndef SYMBIOTIC_VERIFIC_API_VERSION
54 # error "Only Symbiotic EDA flavored Verific is supported. Please contact office@symbioticeda.com for commercial support for Yosys+Verific."
57 #if SYMBIOTIC_VERIFIC_API_VERSION < 202006
58 # error "Please update your version of Symbiotic EDA flavored Verific."
62 #pragma clang diagnostic pop
65 #ifdef VERIFIC_NAMESPACE
66 using namespace Verific
;
71 #ifdef YOSYS_ENABLE_VERIFIC
75 bool verific_import_pending
;
76 string verific_error_msg
;
77 int verific_sva_fsm_limit
;
79 vector
<string
> verific_incdirs
, verific_libdirs
;
81 void msg_func(msg_type_t msg_type
, const char *message_id
, linefile_type linefile
, const char *msg
, va_list args
)
83 string message_prefix
= stringf("VERIFIC-%s [%s] ",
84 msg_type
== VERIFIC_NONE
? "NONE" :
85 msg_type
== VERIFIC_ERROR
? "ERROR" :
86 msg_type
== VERIFIC_WARNING
? "WARNING" :
87 msg_type
== VERIFIC_IGNORE
? "IGNORE" :
88 msg_type
== VERIFIC_INFO
? "INFO" :
89 msg_type
== VERIFIC_COMMENT
? "COMMENT" :
90 msg_type
== VERIFIC_PROGRAM_ERROR
? "PROGRAM_ERROR" : "UNKNOWN", message_id
);
92 string message
= linefile
? stringf("%s:%d: ", LineFile::GetFileName(linefile
), LineFile::GetLineNo(linefile
)) : "";
93 message
+= vstringf(msg
, args
);
95 if (msg_type
== VERIFIC_ERROR
|| msg_type
== VERIFIC_WARNING
|| msg_type
== VERIFIC_PROGRAM_ERROR
)
96 log_warning_noprefix("%s%s\n", message_prefix
.c_str(), message
.c_str());
98 log("%s%s\n", message_prefix
.c_str(), message
.c_str());
100 if (verific_error_msg
.empty() && (msg_type
== VERIFIC_ERROR
|| msg_type
== VERIFIC_PROGRAM_ERROR
))
101 verific_error_msg
= message
;
104 string
get_full_netlist_name(Netlist
*nl
)
106 if (nl
->NumOfRefs() == 1) {
107 Instance
*inst
= (Instance
*)nl
->GetReferences()->GetLast();
108 return get_full_netlist_name(inst
->Owner()) + "." + inst
->Name();
111 return nl
->CellBaseName();
114 // ==================================================================
116 VerificImporter::VerificImporter(bool mode_gates
, bool mode_keep
, bool mode_nosva
, bool mode_names
, bool mode_verific
, bool mode_autocover
, bool mode_fullinit
) :
117 mode_gates(mode_gates
), mode_keep(mode_keep
), mode_nosva(mode_nosva
),
118 mode_names(mode_names
), mode_verific(mode_verific
), mode_autocover(mode_autocover
),
119 mode_fullinit(mode_fullinit
)
123 RTLIL::SigBit
VerificImporter::net_map_at(Net
*net
)
125 if (net
->IsExternalTo(netlist
))
126 log_error("Found external reference to '%s.%s' in netlist '%s', please use -flatten or -extnets.\n",
127 get_full_netlist_name(net
->Owner()).c_str(), net
->Name(), get_full_netlist_name(netlist
).c_str());
129 return net_map
.at(net
);
132 bool is_blackbox(Netlist
*nl
)
134 if (nl
->IsBlackBox() || nl
->IsEmptyBox())
137 const char *attr
= nl
->GetAttValue("blackbox");
138 if (attr
!= nullptr && strcmp(attr
, "0"))
144 RTLIL::IdString
VerificImporter::new_verific_id(Verific::DesignObj
*obj
)
146 std::string s
= stringf("$verific$%s", obj
->Name());
148 s
+= stringf("$%s:%d", Verific::LineFile::GetFileName(obj
->Linefile()), Verific::LineFile::GetLineNo(obj
->Linefile()));
149 s
+= stringf("$%d", autoidx
++);
153 void VerificImporter::import_attributes(dict
<RTLIL::IdString
, RTLIL::Const
> &attributes
, DesignObj
*obj
, Netlist
*nl
)
159 attributes
[ID::src
] = stringf("%s:%d", LineFile::GetFileName(obj
->Linefile()), LineFile::GetLineNo(obj
->Linefile()));
161 // FIXME: Parse numeric attributes
162 FOREACH_ATTRIBUTE(obj
, mi
, attr
) {
163 if (attr
->Key()[0] == ' ' || attr
->Value() == nullptr)
165 attributes
[RTLIL::escape_id(attr
->Key())] = RTLIL::Const(std::string(attr
->Value()));
169 auto type_range
= nl
->GetTypeRange(obj
->Name());
172 if (!type_range
->IsTypeEnum())
174 if (nl
->IsFromVhdl() && strcmp(type_range
->GetTypeName(), "STD_LOGIC") == 0)
176 auto type_name
= type_range
->GetTypeName();
179 attributes
.emplace(ID::wiretype
, RTLIL::escape_id(type_name
));
183 FOREACH_MAP_ITEM(type_range
->GetEnumIdMap(), mi
, &k
, &v
) {
184 if (nl
->IsFromVerilog()) {
185 // Expect <decimal>'b<binary>
186 auto p
= strchr(v
, '\'');
191 for (auto q
= p
+2; *q
!= '\0'; q
++)
192 if (*q
!= '0' && *q
!= '1') {
198 log_error("Expected TypeRange value '%s' to be of form <decimal>'b<binary>.\n", v
);
199 attributes
.emplace(stringf("\\enum_value_%s", p
+2), RTLIL::escape_id(k
));
201 else if (nl
->IsFromVhdl()) {
209 for (; *q
!= '"'; q
++)
210 if (*q
!= '0' && *q
!= '1') {
214 if (p
&& *(q
+1) != '\0')
219 log_error("Expected TypeRange value '%s' to be of form \"<binary>\".\n", v
);
221 auto q
= (char*)malloc(l
+1-2);
222 strncpy(q
, p
+1, l
-2);
224 attributes
.emplace(stringf("\\enum_value_%s", q
), RTLIL::escape_id(k
));
231 RTLIL::SigSpec
VerificImporter::operatorInput(Instance
*inst
)
234 for (int i
= int(inst
->InputSize())-1; i
>= 0; i
--)
235 if (inst
->GetInputBit(i
))
236 sig
.append(net_map_at(inst
->GetInputBit(i
)));
238 sig
.append(RTLIL::State::Sz
);
242 RTLIL::SigSpec
VerificImporter::operatorInput1(Instance
*inst
)
245 for (int i
= int(inst
->Input1Size())-1; i
>= 0; i
--)
246 if (inst
->GetInput1Bit(i
))
247 sig
.append(net_map_at(inst
->GetInput1Bit(i
)));
249 sig
.append(RTLIL::State::Sz
);
253 RTLIL::SigSpec
VerificImporter::operatorInput2(Instance
*inst
)
256 for (int i
= int(inst
->Input2Size())-1; i
>= 0; i
--)
257 if (inst
->GetInput2Bit(i
))
258 sig
.append(net_map_at(inst
->GetInput2Bit(i
)));
260 sig
.append(RTLIL::State::Sz
);
264 RTLIL::SigSpec
VerificImporter::operatorInport(Instance
*inst
, const char *portname
)
266 PortBus
*portbus
= inst
->View()->GetPortBus(portname
);
269 for (unsigned i
= 0; i
< portbus
->Size(); i
++) {
270 Net
*net
= inst
->GetNet(portbus
->ElementAtIndex(i
));
273 sig
.append(RTLIL::State::S0
);
274 else if (net
->IsPwr())
275 sig
.append(RTLIL::State::S1
);
277 sig
.append(net_map_at(net
));
279 sig
.append(RTLIL::State::Sz
);
283 Port
*port
= inst
->View()->GetPort(portname
);
284 log_assert(port
!= NULL
);
285 Net
*net
= inst
->GetNet(port
);
286 return net_map_at(net
);
290 RTLIL::SigSpec
VerificImporter::operatorOutput(Instance
*inst
, const pool
<Net
*, hash_ptr_ops
> *any_all_nets
)
293 RTLIL::Wire
*dummy_wire
= NULL
;
294 for (int i
= int(inst
->OutputSize())-1; i
>= 0; i
--)
295 if (inst
->GetOutputBit(i
) && (!any_all_nets
|| !any_all_nets
->count(inst
->GetOutputBit(i
)))) {
296 sig
.append(net_map_at(inst
->GetOutputBit(i
)));
299 if (dummy_wire
== NULL
)
300 dummy_wire
= module
->addWire(new_verific_id(inst
));
303 sig
.append(RTLIL::SigSpec(dummy_wire
, dummy_wire
->width
- 1));
308 bool VerificImporter::import_netlist_instance_gates(Instance
*inst
, RTLIL::IdString inst_name
)
310 if (inst
->Type() == PRIM_AND
) {
311 module
->addAndGate(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetOutput()));
315 if (inst
->Type() == PRIM_NAND
) {
316 RTLIL::SigSpec tmp
= module
->addWire(new_verific_id(inst
));
317 module
->addAndGate(new_verific_id(inst
), net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), tmp
);
318 module
->addNotGate(inst_name
, tmp
, net_map_at(inst
->GetOutput()));
322 if (inst
->Type() == PRIM_OR
) {
323 module
->addOrGate(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetOutput()));
327 if (inst
->Type() == PRIM_NOR
) {
328 RTLIL::SigSpec tmp
= module
->addWire(new_verific_id(inst
));
329 module
->addOrGate(new_verific_id(inst
), net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), tmp
);
330 module
->addNotGate(inst_name
, tmp
, net_map_at(inst
->GetOutput()));
334 if (inst
->Type() == PRIM_XOR
) {
335 module
->addXorGate(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetOutput()));
339 if (inst
->Type() == PRIM_XNOR
) {
340 module
->addXnorGate(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetOutput()));
344 if (inst
->Type() == PRIM_BUF
) {
345 auto outnet
= inst
->GetOutput();
346 if (!any_all_nets
.count(outnet
))
347 module
->addBufGate(inst_name
, net_map_at(inst
->GetInput()), net_map_at(outnet
));
351 if (inst
->Type() == PRIM_INV
) {
352 module
->addNotGate(inst_name
, net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()));
356 if (inst
->Type() == PRIM_MUX
) {
357 module
->addMuxGate(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetControl()), net_map_at(inst
->GetOutput()));
361 if (inst
->Type() == PRIM_TRI
) {
362 module
->addMuxGate(inst_name
, RTLIL::State::Sz
, net_map_at(inst
->GetInput()), net_map_at(inst
->GetControl()), net_map_at(inst
->GetOutput()));
366 if (inst
->Type() == PRIM_FADD
)
368 RTLIL::SigSpec a
= net_map_at(inst
->GetInput1()), b
= net_map_at(inst
->GetInput2()), c
= net_map_at(inst
->GetCin());
369 RTLIL::SigSpec x
= inst
->GetCout() ? net_map_at(inst
->GetCout()) : module
->addWire(new_verific_id(inst
));
370 RTLIL::SigSpec y
= inst
->GetOutput() ? net_map_at(inst
->GetOutput()) : module
->addWire(new_verific_id(inst
));
371 RTLIL::SigSpec tmp1
= module
->addWire(new_verific_id(inst
));
372 RTLIL::SigSpec tmp2
= module
->addWire(new_verific_id(inst
));
373 RTLIL::SigSpec tmp3
= module
->addWire(new_verific_id(inst
));
374 module
->addXorGate(new_verific_id(inst
), a
, b
, tmp1
);
375 module
->addXorGate(inst_name
, tmp1
, c
, y
);
376 module
->addAndGate(new_verific_id(inst
), tmp1
, c
, tmp2
);
377 module
->addAndGate(new_verific_id(inst
), a
, b
, tmp3
);
378 module
->addOrGate(new_verific_id(inst
), tmp2
, tmp3
, x
);
382 if (inst
->Type() == PRIM_DFFRS
)
384 VerificClocking
clocking(this, inst
->GetClock());
385 log_assert(clocking
.disable_sig
== State::S0
);
386 log_assert(clocking
.body_net
== nullptr);
388 if (inst
->GetSet()->IsGnd() && inst
->GetReset()->IsGnd())
389 clocking
.addDff(inst_name
, net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()));
390 else if (inst
->GetSet()->IsGnd())
391 clocking
.addAdff(inst_name
, net_map_at(inst
->GetReset()), net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()), State::S0
);
392 else if (inst
->GetReset()->IsGnd())
393 clocking
.addAdff(inst_name
, net_map_at(inst
->GetSet()), net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()), State::S1
);
395 clocking
.addDffsr(inst_name
, net_map_at(inst
->GetSet()), net_map_at(inst
->GetReset()),
396 net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()));
403 bool VerificImporter::import_netlist_instance_cells(Instance
*inst
, RTLIL::IdString inst_name
)
405 RTLIL::Cell
*cell
= nullptr;
407 if (inst
->Type() == PRIM_AND
) {
408 cell
= module
->addAnd(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetOutput()));
409 import_attributes(cell
->attributes
, inst
);
413 if (inst
->Type() == PRIM_NAND
) {
414 RTLIL::SigSpec tmp
= module
->addWire(new_verific_id(inst
));
415 cell
= module
->addAnd(new_verific_id(inst
), net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), tmp
);
416 import_attributes(cell
->attributes
, inst
);
417 cell
= module
->addNot(inst_name
, tmp
, net_map_at(inst
->GetOutput()));
418 import_attributes(cell
->attributes
, inst
);
422 if (inst
->Type() == PRIM_OR
) {
423 cell
= module
->addOr(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetOutput()));
424 import_attributes(cell
->attributes
, inst
);
428 if (inst
->Type() == PRIM_NOR
) {
429 RTLIL::SigSpec tmp
= module
->addWire(new_verific_id(inst
));
430 cell
= module
->addOr(new_verific_id(inst
), net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), tmp
);
431 import_attributes(cell
->attributes
, inst
);
432 cell
= module
->addNot(inst_name
, tmp
, net_map_at(inst
->GetOutput()));
433 import_attributes(cell
->attributes
, inst
);
437 if (inst
->Type() == PRIM_XOR
) {
438 cell
= module
->addXor(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetOutput()));
439 import_attributes(cell
->attributes
, inst
);
443 if (inst
->Type() == PRIM_XNOR
) {
444 cell
= module
->addXnor(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetOutput()));
445 import_attributes(cell
->attributes
, inst
);
449 if (inst
->Type() == PRIM_INV
) {
450 cell
= module
->addNot(inst_name
, net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()));
451 import_attributes(cell
->attributes
, inst
);
455 if (inst
->Type() == PRIM_MUX
) {
456 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()));
457 import_attributes(cell
->attributes
, inst
);
461 if (inst
->Type() == PRIM_TRI
) {
462 cell
= module
->addMux(inst_name
, RTLIL::State::Sz
, net_map_at(inst
->GetInput()), net_map_at(inst
->GetControl()), net_map_at(inst
->GetOutput()));
463 import_attributes(cell
->attributes
, inst
);
467 if (inst
->Type() == PRIM_FADD
)
469 RTLIL::SigSpec a_plus_b
= module
->addWire(new_verific_id(inst
), 2);
470 RTLIL::SigSpec y
= inst
->GetOutput() ? net_map_at(inst
->GetOutput()) : module
->addWire(new_verific_id(inst
));
472 y
.append(net_map_at(inst
->GetCout()));
473 cell
= module
->addAdd(new_verific_id(inst
), net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), a_plus_b
);
474 import_attributes(cell
->attributes
, inst
);
475 cell
= module
->addAdd(inst_name
, a_plus_b
, net_map_at(inst
->GetCin()), y
);
476 import_attributes(cell
->attributes
, inst
);
480 if (inst
->Type() == PRIM_DFFRS
)
482 VerificClocking
clocking(this, inst
->GetClock());
483 log_assert(clocking
.disable_sig
== State::S0
);
484 log_assert(clocking
.body_net
== nullptr);
486 if (inst
->GetSet()->IsGnd() && inst
->GetReset()->IsGnd())
487 cell
= clocking
.addDff(inst_name
, net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()));
488 else if (inst
->GetSet()->IsGnd())
489 cell
= clocking
.addAdff(inst_name
, net_map_at(inst
->GetReset()), net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()), RTLIL::State::S0
);
490 else if (inst
->GetReset()->IsGnd())
491 cell
= clocking
.addAdff(inst_name
, net_map_at(inst
->GetSet()), net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()), RTLIL::State::S1
);
493 cell
= clocking
.addDffsr(inst_name
, net_map_at(inst
->GetSet()), net_map_at(inst
->GetReset()),
494 net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()));
495 import_attributes(cell
->attributes
, inst
);
499 if (inst
->Type() == PRIM_DLATCHRS
)
501 if (inst
->GetSet()->IsGnd() && inst
->GetReset()->IsGnd())
502 cell
= module
->addDlatch(inst_name
, net_map_at(inst
->GetControl()), net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()));
504 cell
= module
->addDlatchsr(inst_name
, net_map_at(inst
->GetControl()), net_map_at(inst
->GetSet()), net_map_at(inst
->GetReset()),
505 net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()));
506 import_attributes(cell
->attributes
, inst
);
510 #define IN operatorInput(inst)
511 #define IN1 operatorInput1(inst)
512 #define IN2 operatorInput2(inst)
513 #define OUT operatorOutput(inst)
514 #define FILTERED_OUT operatorOutput(inst, &any_all_nets)
515 #define SIGNED inst->View()->IsSigned()
517 if (inst
->Type() == OPER_ADDER
) {
518 RTLIL::SigSpec out
= OUT
;
519 if (inst
->GetCout() != NULL
)
520 out
.append(net_map_at(inst
->GetCout()));
521 if (inst
->GetCin()->IsGnd()) {
522 cell
= module
->addAdd(inst_name
, IN1
, IN2
, out
, SIGNED
);
523 import_attributes(cell
->attributes
, inst
);
525 RTLIL::SigSpec tmp
= module
->addWire(new_verific_id(inst
), GetSize(out
));
526 cell
= module
->addAdd(new_verific_id(inst
), IN1
, IN2
, tmp
, SIGNED
);
527 import_attributes(cell
->attributes
, inst
);
528 cell
= module
->addAdd(inst_name
, tmp
, net_map_at(inst
->GetCin()), out
, false);
529 import_attributes(cell
->attributes
, inst
);
534 if (inst
->Type() == OPER_MULTIPLIER
) {
535 cell
= module
->addMul(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
536 import_attributes(cell
->attributes
, inst
);
540 if (inst
->Type() == OPER_DIVIDER
) {
541 cell
= module
->addDiv(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
542 import_attributes(cell
->attributes
, inst
);
546 if (inst
->Type() == OPER_MODULO
) {
547 cell
= module
->addMod(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
548 import_attributes(cell
->attributes
, inst
);
552 if (inst
->Type() == OPER_REMAINDER
) {
553 cell
= module
->addMod(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
554 import_attributes(cell
->attributes
, inst
);
558 if (inst
->Type() == OPER_SHIFT_LEFT
) {
559 cell
= module
->addShl(inst_name
, IN1
, IN2
, OUT
, false);
560 import_attributes(cell
->attributes
, inst
);
564 if (inst
->Type() == OPER_ENABLED_DECODER
) {
566 vec
.append(net_map_at(inst
->GetControl()));
567 for (unsigned i
= 1; i
< inst
->OutputSize(); i
++) {
568 vec
.append(RTLIL::State::S0
);
570 cell
= module
->addShl(inst_name
, vec
, IN
, OUT
, false);
571 import_attributes(cell
->attributes
, inst
);
575 if (inst
->Type() == OPER_DECODER
) {
577 vec
.append(RTLIL::State::S1
);
578 for (unsigned i
= 1; i
< inst
->OutputSize(); i
++) {
579 vec
.append(RTLIL::State::S0
);
581 cell
= module
->addShl(inst_name
, vec
, IN
, OUT
, false);
582 import_attributes(cell
->attributes
, inst
);
586 if (inst
->Type() == OPER_SHIFT_RIGHT
) {
587 Net
*net_cin
= inst
->GetCin();
588 Net
*net_a_msb
= inst
->GetInput1Bit(0);
589 if (net_cin
->IsGnd())
590 cell
= module
->addShr(inst_name
, IN1
, IN2
, OUT
, false);
591 else if (net_cin
== net_a_msb
)
592 cell
= module
->addSshr(inst_name
, IN1
, IN2
, OUT
, true);
594 log_error("Can't import Verific OPER_SHIFT_RIGHT instance %s: carry_in is neither 0 nor msb of left input\n", inst
->Name());
595 import_attributes(cell
->attributes
, inst
);
599 if (inst
->Type() == OPER_REDUCE_AND
) {
600 cell
= module
->addReduceAnd(inst_name
, IN
, net_map_at(inst
->GetOutput()), SIGNED
);
601 import_attributes(cell
->attributes
, inst
);
605 if (inst
->Type() == OPER_REDUCE_NAND
) {
606 Wire
*tmp
= module
->addWire(NEW_ID
);
607 cell
= module
->addReduceAnd(inst_name
, IN
, tmp
, SIGNED
);
608 module
->addNot(NEW_ID
, tmp
, net_map_at(inst
->GetOutput()));
609 import_attributes(cell
->attributes
, inst
);
613 if (inst
->Type() == OPER_REDUCE_OR
) {
614 cell
= module
->addReduceOr(inst_name
, IN
, net_map_at(inst
->GetOutput()), SIGNED
);
615 import_attributes(cell
->attributes
, inst
);
619 if (inst
->Type() == OPER_REDUCE_XOR
) {
620 cell
= module
->addReduceXor(inst_name
, IN
, net_map_at(inst
->GetOutput()), SIGNED
);
621 import_attributes(cell
->attributes
, inst
);
625 if (inst
->Type() == OPER_REDUCE_XNOR
) {
626 cell
= module
->addReduceXnor(inst_name
, IN
, net_map_at(inst
->GetOutput()), SIGNED
);
627 import_attributes(cell
->attributes
, inst
);
631 if (inst
->Type() == OPER_REDUCE_NOR
) {
632 SigSpec t
= module
->ReduceOr(new_verific_id(inst
), IN
, SIGNED
);
633 cell
= module
->addNot(inst_name
, t
, net_map_at(inst
->GetOutput()));
634 import_attributes(cell
->attributes
, inst
);
638 if (inst
->Type() == OPER_LESSTHAN
) {
639 Net
*net_cin
= inst
->GetCin();
640 if (net_cin
->IsGnd())
641 cell
= module
->addLt(inst_name
, IN1
, IN2
, net_map_at(inst
->GetOutput()), SIGNED
);
642 else if (net_cin
->IsPwr())
643 cell
= module
->addLe(inst_name
, IN1
, IN2
, net_map_at(inst
->GetOutput()), SIGNED
);
645 log_error("Can't import Verific OPER_LESSTHAN instance %s: carry_in is neither 0 nor 1\n", inst
->Name());
646 import_attributes(cell
->attributes
, inst
);
650 if (inst
->Type() == OPER_WIDE_AND
) {
651 cell
= module
->addAnd(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
652 import_attributes(cell
->attributes
, inst
);
656 if (inst
->Type() == OPER_WIDE_OR
) {
657 cell
= module
->addOr(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
658 import_attributes(cell
->attributes
, inst
);
662 if (inst
->Type() == OPER_WIDE_XOR
) {
663 cell
= module
->addXor(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
664 import_attributes(cell
->attributes
, inst
);
668 if (inst
->Type() == OPER_WIDE_XNOR
) {
669 cell
= module
->addXnor(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
670 import_attributes(cell
->attributes
, inst
);
674 if (inst
->Type() == OPER_WIDE_BUF
) {
675 cell
= module
->addPos(inst_name
, IN
, FILTERED_OUT
, SIGNED
);
676 import_attributes(cell
->attributes
, inst
);
680 if (inst
->Type() == OPER_WIDE_INV
) {
681 cell
= module
->addNot(inst_name
, IN
, OUT
, SIGNED
);
682 import_attributes(cell
->attributes
, inst
);
686 if (inst
->Type() == OPER_MINUS
) {
687 cell
= module
->addSub(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
688 import_attributes(cell
->attributes
, inst
);
692 if (inst
->Type() == OPER_UMINUS
) {
693 cell
= module
->addNeg(inst_name
, IN
, OUT
, SIGNED
);
694 import_attributes(cell
->attributes
, inst
);
698 if (inst
->Type() == OPER_EQUAL
) {
699 cell
= module
->addEq(inst_name
, IN1
, IN2
, net_map_at(inst
->GetOutput()), SIGNED
);
700 import_attributes(cell
->attributes
, inst
);
704 if (inst
->Type() == OPER_NEQUAL
) {
705 cell
= module
->addNe(inst_name
, IN1
, IN2
, net_map_at(inst
->GetOutput()), SIGNED
);
706 import_attributes(cell
->attributes
, inst
);
710 if (inst
->Type() == OPER_WIDE_MUX
) {
711 cell
= module
->addMux(inst_name
, IN1
, IN2
, net_map_at(inst
->GetControl()), OUT
);
712 import_attributes(cell
->attributes
, inst
);
716 if (inst
->Type() == OPER_NTO1MUX
) {
717 cell
= module
->addShr(inst_name
, IN2
, IN1
, net_map_at(inst
->GetOutput()));
718 import_attributes(cell
->attributes
, inst
);
722 if (inst
->Type() == OPER_WIDE_NTO1MUX
)
724 SigSpec data
= IN2
, out
= OUT
;
726 int wordsize_bits
= ceil_log2(GetSize(out
));
727 int wordsize
= 1 << wordsize_bits
;
729 SigSpec sel
= {IN1
, SigSpec(State::S0
, wordsize_bits
)};
732 for (int i
= 0; i
< GetSize(data
); i
+= GetSize(out
)) {
733 SigSpec d
= data
.extract(i
, GetSize(out
));
734 d
.extend_u0(wordsize
);
735 padded_data
.append(d
);
738 cell
= module
->addShr(inst_name
, padded_data
, sel
, out
);
739 import_attributes(cell
->attributes
, inst
);
743 if (inst
->Type() == OPER_SELECTOR
)
745 cell
= module
->addPmux(inst_name
, State::S0
, IN2
, IN1
, net_map_at(inst
->GetOutput()));
746 import_attributes(cell
->attributes
, inst
);
750 if (inst
->Type() == OPER_WIDE_SELECTOR
)
753 cell
= module
->addPmux(inst_name
, SigSpec(State::S0
, GetSize(out
)), IN2
, IN1
, out
);
754 import_attributes(cell
->attributes
, inst
);
758 if (inst
->Type() == OPER_WIDE_TRI
) {
759 cell
= module
->addMux(inst_name
, RTLIL::SigSpec(RTLIL::State::Sz
, inst
->OutputSize()), IN
, net_map_at(inst
->GetControl()), OUT
);
760 import_attributes(cell
->attributes
, inst
);
764 if (inst
->Type() == OPER_WIDE_DFFRS
)
766 VerificClocking
clocking(this, inst
->GetClock());
767 log_assert(clocking
.disable_sig
== State::S0
);
768 log_assert(clocking
.body_net
== nullptr);
770 RTLIL::SigSpec sig_set
= operatorInport(inst
, "set");
771 RTLIL::SigSpec sig_reset
= operatorInport(inst
, "reset");
773 if (sig_set
.is_fully_const() && !sig_set
.as_bool() && sig_reset
.is_fully_const() && !sig_reset
.as_bool())
774 cell
= clocking
.addDff(inst_name
, IN
, OUT
);
776 cell
= clocking
.addDffsr(inst_name
, sig_set
, sig_reset
, IN
, OUT
);
777 import_attributes(cell
->attributes
, inst
);
791 void VerificImporter::merge_past_ffs_clock(pool
<RTLIL::Cell
*> &candidates
, SigBit clock
, bool clock_pol
)
793 bool keep_running
= true;
798 keep_running
= false;
800 dict
<SigBit
, pool
<RTLIL::Cell
*>> dbits_db
;
803 for (auto cell
: candidates
) {
804 SigBit bit
= sigmap(cell
->getPort(ID::D
));
805 dbits_db
[bit
].insert(cell
);
809 dbits
.sort_and_unify();
811 for (auto chunk
: dbits
.chunks())
813 SigSpec sig_d
= chunk
;
815 if (chunk
.wire
== nullptr || GetSize(sig_d
) == 1)
818 SigSpec sig_q
= module
->addWire(NEW_ID
, GetSize(sig_d
));
819 RTLIL::Cell
*new_ff
= module
->addDff(NEW_ID
, clock
, sig_d
, sig_q
, clock_pol
);
822 log(" merging single-bit past_ffs into new %d-bit ff %s.\n", GetSize(sig_d
), log_id(new_ff
));
824 for (int i
= 0; i
< GetSize(sig_d
); i
++)
825 for (auto old_ff
: dbits_db
[sig_d
[i
]])
828 log(" replacing old ff %s on bit %d.\n", log_id(old_ff
), i
);
830 SigBit old_q
= old_ff
->getPort(ID::Q
);
831 SigBit new_q
= sig_q
[i
];
833 sigmap
.add(old_q
, new_q
);
834 module
->connect(old_q
, new_q
);
835 candidates
.erase(old_ff
);
836 module
->remove(old_ff
);
843 void VerificImporter::merge_past_ffs(pool
<RTLIL::Cell
*> &candidates
)
845 dict
<pair
<SigBit
, int>, pool
<RTLIL::Cell
*>> database
;
847 for (auto cell
: candidates
)
849 SigBit clock
= cell
->getPort(ID::CLK
);
850 bool clock_pol
= cell
->getParam(ID::CLK_POLARITY
).as_bool();
851 database
[make_pair(clock
, int(clock_pol
))].insert(cell
);
854 for (auto it
: database
)
855 merge_past_ffs_clock(it
.second
, it
.first
.first
, it
.first
.second
);
858 void VerificImporter::import_netlist(RTLIL::Design
*design
, Netlist
*nl
, std::set
<Netlist
*> &nl_todo
, bool norename
)
860 std::string netlist_name
= nl
->GetAtt(" \\top") ? nl
->CellBaseName() : nl
->Owner()->Name();
861 std::string module_name
= netlist_name
;
863 if (nl
->IsOperator() || nl
->IsPrimitive()) {
864 module_name
= "$verific$" + module_name
;
866 if (!norename
&& *nl
->Name()) {
868 module_name
+= nl
->Name();
871 module_name
= "\\" + module_name
;
876 if (design
->has(module_name
)) {
877 if (!nl
->IsOperator() && !is_blackbox(nl
))
878 log_cmd_error("Re-definition of module `%s'.\n", netlist_name
.c_str());
882 module
= new RTLIL::Module
;
883 module
->name
= module_name
;
886 if (is_blackbox(nl
)) {
887 log("Importing blackbox module %s.\n", RTLIL::id2cstr(module
->name
));
888 module
->set_bool_attribute(ID::blackbox
);
890 log("Importing module %s.\n", RTLIL::id2cstr(module
->name
));
902 FOREACH_PORT_OF_NETLIST(nl
, mi
, port
)
908 log(" importing port %s.\n", port
->Name());
910 RTLIL::Wire
*wire
= module
->addWire(RTLIL::escape_id(port
->Name()));
911 import_attributes(wire
->attributes
, port
, nl
);
913 wire
->port_id
= nl
->IndexOf(port
) + 1;
915 if (port
->GetDir() == DIR_INOUT
|| port
->GetDir() == DIR_IN
)
916 wire
->port_input
= true;
917 if (port
->GetDir() == DIR_INOUT
|| port
->GetDir() == DIR_OUT
)
918 wire
->port_output
= true;
920 if (port
->GetNet()) {
921 net
= port
->GetNet();
922 if (net_map
.count(net
) == 0)
924 else if (wire
->port_input
)
925 module
->connect(net_map_at(net
), wire
);
927 module
->connect(wire
, net_map_at(net
));
931 FOREACH_PORTBUS_OF_NETLIST(nl
, mi
, portbus
)
934 log(" importing portbus %s.\n", portbus
->Name());
936 RTLIL::Wire
*wire
= module
->addWire(RTLIL::escape_id(portbus
->Name()), portbus
->Size());
937 wire
->start_offset
= min(portbus
->LeftIndex(), portbus
->RightIndex());
938 import_attributes(wire
->attributes
, portbus
, nl
);
940 if (portbus
->GetDir() == DIR_INOUT
|| portbus
->GetDir() == DIR_IN
)
941 wire
->port_input
= true;
942 if (portbus
->GetDir() == DIR_INOUT
|| portbus
->GetDir() == DIR_OUT
)
943 wire
->port_output
= true;
945 for (int i
= portbus
->LeftIndex();; i
+= portbus
->IsUp() ? +1 : -1) {
946 if (portbus
->ElementAtIndex(i
) && portbus
->ElementAtIndex(i
)->GetNet()) {
947 net
= portbus
->ElementAtIndex(i
)->GetNet();
948 RTLIL::SigBit
bit(wire
, i
- wire
->start_offset
);
949 if (net_map
.count(net
) == 0)
951 else if (wire
->port_input
)
952 module
->connect(net_map_at(net
), bit
);
954 module
->connect(bit
, net_map_at(net
));
956 if (i
== portbus
->RightIndex())
961 module
->fixup_ports();
963 dict
<Net
*, char, hash_ptr_ops
> init_nets
;
964 pool
<Net
*, hash_ptr_ops
> anyconst_nets
, anyseq_nets
;
965 pool
<Net
*, hash_ptr_ops
> allconst_nets
, allseq_nets
;
966 any_all_nets
.clear();
968 FOREACH_NET_OF_NETLIST(nl
, mi
, net
)
972 RTLIL::Memory
*memory
= new RTLIL::Memory
;
973 memory
->name
= RTLIL::escape_id(net
->Name());
974 log_assert(module
->count_id(memory
->name
) == 0);
975 module
->memories
[memory
->name
] = memory
;
977 int number_of_bits
= net
->Size();
978 number_of_bits
= 1 << ceil_log2(number_of_bits
);
979 int bits_in_word
= number_of_bits
;
980 FOREACH_PORTREF_OF_NET(net
, si
, pr
) {
981 if (pr
->GetInst()->Type() == OPER_READ_PORT
) {
982 bits_in_word
= min
<int>(bits_in_word
, pr
->GetInst()->OutputSize());
985 if (pr
->GetInst()->Type() == OPER_WRITE_PORT
|| pr
->GetInst()->Type() == OPER_CLOCKED_WRITE_PORT
) {
986 bits_in_word
= min
<int>(bits_in_word
, pr
->GetInst()->Input2Size());
989 log_error("Verific RamNet %s is connected to unsupported instance type %s (%s).\n",
990 net
->Name(), pr
->GetInst()->View()->Owner()->Name(), pr
->GetInst()->Name());
993 memory
->width
= bits_in_word
;
994 memory
->size
= number_of_bits
/ bits_in_word
;
996 const char *ascii_initdata
= net
->GetWideInitialValue();
997 if (ascii_initdata
) {
998 while (*ascii_initdata
!= 0 && *ascii_initdata
!= '\'')
1000 if (*ascii_initdata
== '\'')
1002 if (*ascii_initdata
!= 0) {
1003 log_assert(*ascii_initdata
== 'b');
1006 for (int word_idx
= 0; word_idx
< memory
->size
; word_idx
++) {
1007 Const initval
= Const(State::Sx
, memory
->width
);
1008 bool initval_valid
= false;
1009 for (int bit_idx
= memory
->width
-1; bit_idx
>= 0; bit_idx
--) {
1010 if (*ascii_initdata
== 0)
1012 if (*ascii_initdata
== '0' || *ascii_initdata
== '1') {
1013 initval
[bit_idx
] = (*ascii_initdata
== '0') ? State::S0
: State::S1
;
1014 initval_valid
= true;
1018 if (initval_valid
) {
1019 RTLIL::Cell
*cell
= module
->addCell(new_verific_id(net
), ID($meminit
));
1020 cell
->parameters
[ID::WORDS
] = 1;
1021 if (net
->GetOrigTypeRange()->LeftRangeBound() < net
->GetOrigTypeRange()->RightRangeBound())
1022 cell
->setPort(ID::ADDR
, word_idx
);
1024 cell
->setPort(ID::ADDR
, memory
->size
- word_idx
- 1);
1025 cell
->setPort(ID::DATA
, initval
);
1026 cell
->parameters
[ID::MEMID
] = RTLIL::Const(memory
->name
.str());
1027 cell
->parameters
[ID::ABITS
] = 32;
1028 cell
->parameters
[ID::WIDTH
] = memory
->width
;
1029 cell
->parameters
[ID::PRIORITY
] = RTLIL::Const(autoidx
-1);
1036 if (net
->GetInitialValue())
1037 init_nets
[net
] = net
->GetInitialValue();
1039 const char *rand_const_attr
= net
->GetAttValue(" rand_const");
1040 const char *rand_attr
= net
->GetAttValue(" rand");
1042 const char *anyconst_attr
= net
->GetAttValue("anyconst");
1043 const char *anyseq_attr
= net
->GetAttValue("anyseq");
1045 const char *allconst_attr
= net
->GetAttValue("allconst");
1046 const char *allseq_attr
= net
->GetAttValue("allseq");
1048 if (rand_const_attr
!= nullptr && (!strcmp(rand_const_attr
, "1") || !strcmp(rand_const_attr
, "'1'"))) {
1049 anyconst_nets
.insert(net
);
1050 any_all_nets
.insert(net
);
1052 else if (rand_attr
!= nullptr && (!strcmp(rand_attr
, "1") || !strcmp(rand_attr
, "'1'"))) {
1053 anyseq_nets
.insert(net
);
1054 any_all_nets
.insert(net
);
1056 else if (anyconst_attr
!= nullptr && (!strcmp(anyconst_attr
, "1") || !strcmp(anyconst_attr
, "'1'"))) {
1057 anyconst_nets
.insert(net
);
1058 any_all_nets
.insert(net
);
1060 else if (anyseq_attr
!= nullptr && (!strcmp(anyseq_attr
, "1") || !strcmp(anyseq_attr
, "'1'"))) {
1061 anyseq_nets
.insert(net
);
1062 any_all_nets
.insert(net
);
1064 else if (allconst_attr
!= nullptr && (!strcmp(allconst_attr
, "1") || !strcmp(allconst_attr
, "'1'"))) {
1065 allconst_nets
.insert(net
);
1066 any_all_nets
.insert(net
);
1068 else if (allseq_attr
!= nullptr && (!strcmp(allseq_attr
, "1") || !strcmp(allseq_attr
, "'1'"))) {
1069 allseq_nets
.insert(net
);
1070 any_all_nets
.insert(net
);
1073 if (net_map
.count(net
)) {
1074 if (verific_verbose
)
1075 log(" skipping net %s.\n", net
->Name());
1082 RTLIL::IdString wire_name
= module
->uniquify(mode_names
|| net
->IsUserDeclared() ? RTLIL::escape_id(net
->Name()) : new_verific_id(net
));
1084 if (verific_verbose
)
1085 log(" importing net %s as %s.\n", net
->Name(), log_id(wire_name
));
1087 RTLIL::Wire
*wire
= module
->addWire(wire_name
);
1088 import_attributes(wire
->attributes
, net
, nl
);
1090 net_map
[net
] = wire
;
1093 FOREACH_NETBUS_OF_NETLIST(nl
, mi
, netbus
)
1095 bool found_new_net
= false;
1096 for (int i
= netbus
->LeftIndex();; i
+= netbus
->IsUp() ? +1 : -1) {
1097 net
= netbus
->ElementAtIndex(i
);
1098 if (net_map
.count(net
) == 0)
1099 found_new_net
= true;
1100 if (i
== netbus
->RightIndex())
1106 RTLIL::IdString wire_name
= module
->uniquify(mode_names
|| netbus
->IsUserDeclared() ? RTLIL::escape_id(netbus
->Name()) : new_verific_id(netbus
));
1108 if (verific_verbose
)
1109 log(" importing netbus %s as %s.\n", netbus
->Name(), log_id(wire_name
));
1111 RTLIL::Wire
*wire
= module
->addWire(wire_name
, netbus
->Size());
1112 wire
->start_offset
= min(netbus
->LeftIndex(), netbus
->RightIndex());
1114 FOREACH_NET_OF_NETBUS(netbus
, mibus
, net
) {
1116 import_attributes(wire
->attributes
, net
, nl
);
1120 RTLIL::Const initval
= Const(State::Sx
, GetSize(wire
));
1121 bool initval_valid
= false;
1123 for (int i
= netbus
->LeftIndex();; i
+= netbus
->IsUp() ? +1 : -1)
1125 if (netbus
->ElementAtIndex(i
))
1127 int bitidx
= i
- wire
->start_offset
;
1128 net
= netbus
->ElementAtIndex(i
);
1129 RTLIL::SigBit
bit(wire
, bitidx
);
1131 if (init_nets
.count(net
)) {
1132 if (init_nets
.at(net
) == '0')
1133 initval
.bits
.at(bitidx
) = State::S0
;
1134 if (init_nets
.at(net
) == '1')
1135 initval
.bits
.at(bitidx
) = State::S1
;
1136 initval_valid
= true;
1137 init_nets
.erase(net
);
1140 if (net_map
.count(net
) == 0)
1143 module
->connect(bit
, net_map_at(net
));
1146 if (i
== netbus
->RightIndex())
1151 wire
->attributes
[ID::init
] = initval
;
1155 if (verific_verbose
)
1156 log(" skipping netbus %s.\n", netbus
->Name());
1159 SigSpec anyconst_sig
;
1161 SigSpec allconst_sig
;
1164 for (int i
= netbus
->RightIndex();; i
+= netbus
->IsUp() ? -1 : +1) {
1165 net
= netbus
->ElementAtIndex(i
);
1166 if (net
!= nullptr && anyconst_nets
.count(net
)) {
1167 anyconst_sig
.append(net_map_at(net
));
1168 anyconst_nets
.erase(net
);
1170 if (net
!= nullptr && anyseq_nets
.count(net
)) {
1171 anyseq_sig
.append(net_map_at(net
));
1172 anyseq_nets
.erase(net
);
1174 if (net
!= nullptr && allconst_nets
.count(net
)) {
1175 allconst_sig
.append(net_map_at(net
));
1176 allconst_nets
.erase(net
);
1178 if (net
!= nullptr && allseq_nets
.count(net
)) {
1179 allseq_sig
.append(net_map_at(net
));
1180 allseq_nets
.erase(net
);
1182 if (i
== netbus
->LeftIndex())
1186 if (GetSize(anyconst_sig
))
1187 module
->connect(anyconst_sig
, module
->Anyconst(new_verific_id(netbus
), GetSize(anyconst_sig
)));
1189 if (GetSize(anyseq_sig
))
1190 module
->connect(anyseq_sig
, module
->Anyseq(new_verific_id(netbus
), GetSize(anyseq_sig
)));
1192 if (GetSize(allconst_sig
))
1193 module
->connect(allconst_sig
, module
->Allconst(new_verific_id(netbus
), GetSize(allconst_sig
)));
1195 if (GetSize(allseq_sig
))
1196 module
->connect(allseq_sig
, module
->Allseq(new_verific_id(netbus
), GetSize(allseq_sig
)));
1199 for (auto it
: init_nets
)
1202 SigBit bit
= net_map_at(it
.first
);
1203 log_assert(bit
.wire
);
1205 if (bit
.wire
->attributes
.count(ID::init
))
1206 initval
= bit
.wire
->attributes
.at(ID::init
);
1208 while (GetSize(initval
) < GetSize(bit
.wire
))
1209 initval
.bits
.push_back(State::Sx
);
1211 if (it
.second
== '0')
1212 initval
.bits
.at(bit
.offset
) = State::S0
;
1213 if (it
.second
== '1')
1214 initval
.bits
.at(bit
.offset
) = State::S1
;
1216 bit
.wire
->attributes
[ID::init
] = initval
;
1219 for (auto net
: anyconst_nets
)
1220 module
->connect(net_map_at(net
), module
->Anyconst(new_verific_id(net
)));
1222 for (auto net
: anyseq_nets
)
1223 module
->connect(net_map_at(net
), module
->Anyseq(new_verific_id(net
)));
1225 pool
<Instance
*, hash_ptr_ops
> sva_asserts
;
1226 pool
<Instance
*, hash_ptr_ops
> sva_assumes
;
1227 pool
<Instance
*, hash_ptr_ops
> sva_covers
;
1228 pool
<Instance
*, hash_ptr_ops
> sva_triggers
;
1230 pool
<RTLIL::Cell
*> past_ffs
;
1232 FOREACH_INSTANCE_OF_NETLIST(nl
, mi
, inst
)
1234 RTLIL::IdString inst_name
= module
->uniquify(mode_names
|| inst
->IsUserDeclared() ? RTLIL::escape_id(inst
->Name()) : new_verific_id(inst
));
1236 if (verific_verbose
)
1237 log(" importing cell %s (%s) as %s.\n", inst
->Name(), inst
->View()->Owner()->Name(), log_id(inst_name
));
1240 goto import_verific_cells
;
1242 if (inst
->Type() == PRIM_PWR
) {
1243 module
->connect(net_map_at(inst
->GetOutput()), RTLIL::State::S1
);
1247 if (inst
->Type() == PRIM_GND
) {
1248 module
->connect(net_map_at(inst
->GetOutput()), RTLIL::State::S0
);
1252 if (inst
->Type() == PRIM_BUF
) {
1253 auto outnet
= inst
->GetOutput();
1254 if (!any_all_nets
.count(outnet
))
1255 module
->addBufGate(inst_name
, net_map_at(inst
->GetInput()), net_map_at(outnet
));
1259 if (inst
->Type() == PRIM_X
) {
1260 module
->connect(net_map_at(inst
->GetOutput()), RTLIL::State::Sx
);
1264 if (inst
->Type() == PRIM_Z
) {
1265 module
->connect(net_map_at(inst
->GetOutput()), RTLIL::State::Sz
);
1269 if (inst
->Type() == OPER_READ_PORT
)
1271 RTLIL::Memory
*memory
= module
->memories
.at(RTLIL::escape_id(inst
->GetInput()->Name()), nullptr);
1273 log_error("Memory net '%s' missing, possibly no driver, use verific -flatten.\n", inst
->GetInput()->Name());
1275 int numchunks
= int(inst
->OutputSize()) / memory
->width
;
1276 int chunksbits
= ceil_log2(numchunks
);
1278 for (int i
= 0; i
< numchunks
; i
++)
1280 RTLIL::SigSpec addr
= {operatorInput1(inst
), RTLIL::Const(i
, chunksbits
)};
1281 RTLIL::SigSpec data
= operatorOutput(inst
).extract(i
* memory
->width
, memory
->width
);
1283 RTLIL::Cell
*cell
= module
->addCell(numchunks
== 1 ? inst_name
:
1284 RTLIL::IdString(stringf("%s_%d", inst_name
.c_str(), i
)), ID($memrd
));
1285 cell
->parameters
[ID::MEMID
] = memory
->name
.str();
1286 cell
->parameters
[ID::CLK_ENABLE
] = false;
1287 cell
->parameters
[ID::CLK_POLARITY
] = true;
1288 cell
->parameters
[ID::TRANSPARENT
] = false;
1289 cell
->parameters
[ID::ABITS
] = GetSize(addr
);
1290 cell
->parameters
[ID::WIDTH
] = GetSize(data
);
1291 cell
->setPort(ID::CLK
, RTLIL::State::Sx
);
1292 cell
->setPort(ID::EN
, RTLIL::State::Sx
);
1293 cell
->setPort(ID::ADDR
, addr
);
1294 cell
->setPort(ID::DATA
, data
);
1299 if (inst
->Type() == OPER_WRITE_PORT
|| inst
->Type() == OPER_CLOCKED_WRITE_PORT
)
1301 RTLIL::Memory
*memory
= module
->memories
.at(RTLIL::escape_id(inst
->GetOutput()->Name()), nullptr);
1303 log_error("Memory net '%s' missing, possibly no driver, use verific -flatten.\n", inst
->GetInput()->Name());
1304 int numchunks
= int(inst
->Input2Size()) / memory
->width
;
1305 int chunksbits
= ceil_log2(numchunks
);
1307 for (int i
= 0; i
< numchunks
; i
++)
1309 RTLIL::SigSpec addr
= {operatorInput1(inst
), RTLIL::Const(i
, chunksbits
)};
1310 RTLIL::SigSpec data
= operatorInput2(inst
).extract(i
* memory
->width
, memory
->width
);
1312 RTLIL::Cell
*cell
= module
->addCell(numchunks
== 1 ? inst_name
:
1313 RTLIL::IdString(stringf("%s_%d", inst_name
.c_str(), i
)), ID($memwr
));
1314 cell
->parameters
[ID::MEMID
] = memory
->name
.str();
1315 cell
->parameters
[ID::CLK_ENABLE
] = false;
1316 cell
->parameters
[ID::CLK_POLARITY
] = true;
1317 cell
->parameters
[ID::PRIORITY
] = 0;
1318 cell
->parameters
[ID::ABITS
] = GetSize(addr
);
1319 cell
->parameters
[ID::WIDTH
] = GetSize(data
);
1320 cell
->setPort(ID::EN
, RTLIL::SigSpec(net_map_at(inst
->GetControl())).repeat(GetSize(data
)));
1321 cell
->setPort(ID::CLK
, RTLIL::State::S0
);
1322 cell
->setPort(ID::ADDR
, addr
);
1323 cell
->setPort(ID::DATA
, data
);
1325 if (inst
->Type() == OPER_CLOCKED_WRITE_PORT
) {
1326 cell
->parameters
[ID::CLK_ENABLE
] = true;
1327 cell
->setPort(ID::CLK
, net_map_at(inst
->GetClock()));
1334 if (import_netlist_instance_cells(inst
, inst_name
))
1336 if (inst
->IsOperator() && !verific_sva_prims
.count(inst
->Type()))
1337 log_warning("Unsupported Verific operator: %s (fallback to gate level implementation provided by verific)\n", inst
->View()->Owner()->Name());
1339 if (import_netlist_instance_gates(inst
, inst_name
))
1343 if (inst
->Type() == PRIM_SVA_ASSERT
|| inst
->Type() == PRIM_SVA_IMMEDIATE_ASSERT
)
1344 sva_asserts
.insert(inst
);
1346 if (inst
->Type() == PRIM_SVA_ASSUME
|| inst
->Type() == PRIM_SVA_IMMEDIATE_ASSUME
|| inst
->Type() == PRIM_SVA_RESTRICT
)
1347 sva_assumes
.insert(inst
);
1349 if (inst
->Type() == PRIM_SVA_COVER
|| inst
->Type() == PRIM_SVA_IMMEDIATE_COVER
)
1350 sva_covers
.insert(inst
);
1352 if (inst
->Type() == PRIM_SVA_TRIGGERED
)
1353 sva_triggers
.insert(inst
);
1355 if (inst
->Type() == OPER_SVA_STABLE
)
1357 VerificClocking
clocking(this, inst
->GetInput2Bit(0));
1358 log_assert(clocking
.disable_sig
== State::S0
);
1359 log_assert(clocking
.body_net
== nullptr);
1361 log_assert(inst
->Input1Size() == inst
->OutputSize());
1363 SigSpec sig_d
, sig_q
, sig_o
;
1364 sig_q
= module
->addWire(new_verific_id(inst
), inst
->Input1Size());
1366 for (int i
= int(inst
->Input1Size())-1; i
>= 0; i
--){
1367 sig_d
.append(net_map_at(inst
->GetInput1Bit(i
)));
1368 sig_o
.append(net_map_at(inst
->GetOutputBit(i
)));
1371 if (verific_verbose
) {
1372 log(" %sedge FF with D=%s, Q=%s, C=%s.\n", clocking
.posedge
? "pos" : "neg",
1373 log_signal(sig_d
), log_signal(sig_q
), log_signal(clocking
.clock_sig
));
1374 log(" XNOR with A=%s, B=%s, Y=%s.\n",
1375 log_signal(sig_d
), log_signal(sig_q
), log_signal(sig_o
));
1378 clocking
.addDff(new_verific_id(inst
), sig_d
, sig_q
);
1379 module
->addXnor(new_verific_id(inst
), sig_d
, sig_q
, sig_o
);
1385 if (inst
->Type() == PRIM_SVA_STABLE
)
1387 VerificClocking
clocking(this, inst
->GetInput2());
1388 log_assert(clocking
.disable_sig
== State::S0
);
1389 log_assert(clocking
.body_net
== nullptr);
1391 SigSpec sig_d
= net_map_at(inst
->GetInput1());
1392 SigSpec sig_o
= net_map_at(inst
->GetOutput());
1393 SigSpec sig_q
= module
->addWire(new_verific_id(inst
));
1395 if (verific_verbose
) {
1396 log(" %sedge FF with D=%s, Q=%s, C=%s.\n", clocking
.posedge
? "pos" : "neg",
1397 log_signal(sig_d
), log_signal(sig_q
), log_signal(clocking
.clock_sig
));
1398 log(" XNOR with A=%s, B=%s, Y=%s.\n",
1399 log_signal(sig_d
), log_signal(sig_q
), log_signal(sig_o
));
1402 clocking
.addDff(new_verific_id(inst
), sig_d
, sig_q
);
1403 module
->addXnor(new_verific_id(inst
), sig_d
, sig_q
, sig_o
);
1409 if (inst
->Type() == PRIM_SVA_PAST
)
1411 VerificClocking
clocking(this, inst
->GetInput2());
1412 log_assert(clocking
.disable_sig
== State::S0
);
1413 log_assert(clocking
.body_net
== nullptr);
1415 SigBit sig_d
= net_map_at(inst
->GetInput1());
1416 SigBit sig_q
= net_map_at(inst
->GetOutput());
1418 if (verific_verbose
)
1419 log(" %sedge FF with D=%s, Q=%s, C=%s.\n", clocking
.posedge
? "pos" : "neg",
1420 log_signal(sig_d
), log_signal(sig_q
), log_signal(clocking
.clock_sig
));
1422 past_ffs
.insert(clocking
.addDff(new_verific_id(inst
), sig_d
, sig_q
));
1428 if ((inst
->Type() == PRIM_SVA_ROSE
|| inst
->Type() == PRIM_SVA_FELL
))
1430 VerificClocking
clocking(this, inst
->GetInput2());
1431 log_assert(clocking
.disable_sig
== State::S0
);
1432 log_assert(clocking
.body_net
== nullptr);
1434 SigBit sig_d
= net_map_at(inst
->GetInput1());
1435 SigBit sig_o
= net_map_at(inst
->GetOutput());
1436 SigBit sig_q
= module
->addWire(new_verific_id(inst
));
1438 if (verific_verbose
)
1439 log(" %sedge FF with D=%s, Q=%s, C=%s.\n", clocking
.posedge
? "pos" : "neg",
1440 log_signal(sig_d
), log_signal(sig_q
), log_signal(clocking
.clock_sig
));
1442 clocking
.addDff(new_verific_id(inst
), sig_d
, sig_q
);
1443 module
->addEq(new_verific_id(inst
), {sig_q
, sig_d
}, Const(inst
->Type() == PRIM_SVA_ROSE
? 1 : 2, 2), sig_o
);
1449 if (inst
->Type() == PRIM_SEDA_INITSTATE
)
1451 SigBit initstate
= module
->Initstate(new_verific_id(inst
));
1452 SigBit sig_o
= net_map_at(inst
->GetOutput());
1453 module
->connect(sig_o
, initstate
);
1459 if (!mode_keep
&& verific_sva_prims
.count(inst
->Type())) {
1460 if (verific_verbose
)
1461 log(" skipping SVA cell in non k-mode\n");
1465 if (inst
->Type() == PRIM_HDL_ASSERTION
)
1467 SigBit cond
= net_map_at(inst
->GetInput());
1469 if (verific_verbose
)
1470 log(" assert condition %s.\n", log_signal(cond
));
1472 const char *assume_attr
= nullptr; // inst->GetAttValue("assume");
1474 Cell
*cell
= nullptr;
1475 if (assume_attr
!= nullptr && !strcmp(assume_attr
, "1"))
1476 cell
= module
->addAssume(new_verific_id(inst
), cond
, State::S1
);
1478 cell
= module
->addAssert(new_verific_id(inst
), cond
, State::S1
);
1480 import_attributes(cell
->attributes
, inst
);
1484 if (inst
->IsPrimitive())
1487 log_error("Unsupported Verific primitive %s of type %s\n", inst
->Name(), inst
->View()->Owner()->Name());
1489 if (!verific_sva_prims
.count(inst
->Type()))
1490 log_warning("Unsupported Verific primitive %s of type %s\n", inst
->Name(), inst
->View()->Owner()->Name());
1493 import_verific_cells
:
1494 nl_todo
.insert(inst
->View());
1496 std::string inst_type
= inst
->View()->Owner()->Name();
1498 if (inst
->View()->IsOperator() || inst
->View()->IsPrimitive()) {
1499 inst_type
= "$verific$" + inst_type
;
1501 if (*inst
->View()->Name()) {
1503 inst_type
+= inst
->View()->Name();
1506 inst_type
= "\\" + inst_type
;
1509 RTLIL::Cell
*cell
= module
->addCell(inst_name
, inst_type
);
1511 if (inst
->IsPrimitive() && mode_keep
)
1512 cell
->attributes
[ID::keep
] = 1;
1514 dict
<IdString
, vector
<SigBit
>> cell_port_conns
;
1516 if (verific_verbose
)
1517 log(" ports in verific db:\n");
1519 FOREACH_PORTREF_OF_INST(inst
, mi2
, pr
) {
1520 if (verific_verbose
)
1521 log(" .%s(%s)\n", pr
->GetPort()->Name(), pr
->GetNet()->Name());
1522 const char *port_name
= pr
->GetPort()->Name();
1523 int port_offset
= 0;
1524 if (pr
->GetPort()->Bus()) {
1525 port_name
= pr
->GetPort()->Bus()->Name();
1526 port_offset
= pr
->GetPort()->Bus()->IndexOf(pr
->GetPort()) -
1527 min(pr
->GetPort()->Bus()->LeftIndex(), pr
->GetPort()->Bus()->RightIndex());
1529 IdString port_name_id
= RTLIL::escape_id(port_name
);
1530 auto &sigvec
= cell_port_conns
[port_name_id
];
1531 if (GetSize(sigvec
) <= port_offset
) {
1532 SigSpec zwires
= module
->addWire(new_verific_id(inst
), port_offset
+1-GetSize(sigvec
));
1533 for (auto bit
: zwires
)
1534 sigvec
.push_back(bit
);
1536 sigvec
[port_offset
] = net_map_at(pr
->GetNet());
1539 if (verific_verbose
)
1540 log(" ports in yosys db:\n");
1542 for (auto &it
: cell_port_conns
) {
1543 if (verific_verbose
)
1544 log(" .%s(%s)\n", log_id(it
.first
), log_signal(it
.second
));
1545 cell
->setPort(it
.first
, it
.second
);
1551 for (auto inst
: sva_asserts
) {
1553 verific_import_sva_cover(this, inst
);
1554 verific_import_sva_assert(this, inst
);
1557 for (auto inst
: sva_assumes
)
1558 verific_import_sva_assume(this, inst
);
1560 for (auto inst
: sva_covers
)
1561 verific_import_sva_cover(this, inst
);
1563 for (auto inst
: sva_triggers
)
1564 verific_import_sva_trigger(this, inst
);
1566 merge_past_ffs(past_ffs
);
1571 pool
<SigBit
> non_ff_bits
;
1574 ff_types
.setup_internals_ff();
1575 ff_types
.setup_stdcells_mem();
1577 for (auto cell
: module
->cells())
1579 if (ff_types
.cell_known(cell
->type
))
1582 for (auto conn
: cell
->connections())
1584 if (!cell
->output(conn
.first
))
1587 for (auto bit
: conn
.second
)
1588 if (bit
.wire
!= nullptr)
1589 non_ff_bits
.insert(bit
);
1593 for (auto wire
: module
->wires())
1595 if (!wire
->attributes
.count(ID::init
))
1598 Const
&initval
= wire
->attributes
.at(ID::init
);
1599 for (int i
= 0; i
< GetSize(initval
); i
++)
1601 if (initval
[i
] != State::S0
&& initval
[i
] != State::S1
)
1604 if (non_ff_bits
.count(SigBit(wire
, i
)))
1605 initval
[i
] = State::Sx
;
1608 if (initval
.is_fully_undef())
1609 wire
->attributes
.erase(ID::init
);
1614 // ==================================================================
1616 VerificClocking::VerificClocking(VerificImporter
*importer
, Net
*net
, bool sva_at_only
)
1618 module
= importer
->module
;
1620 log_assert(importer
!= nullptr);
1621 log_assert(net
!= nullptr);
1623 Instance
*inst
= net
->Driver();
1625 if (inst
!= nullptr && inst
->Type() == PRIM_SVA_AT
)
1627 net
= inst
->GetInput1();
1628 body_net
= inst
->GetInput2();
1630 inst
= net
->Driver();
1632 Instance
*body_inst
= body_net
->Driver();
1633 if (body_inst
!= nullptr && body_inst
->Type() == PRIM_SVA_DISABLE_IFF
) {
1634 disable_net
= body_inst
->GetInput1();
1635 disable_sig
= importer
->net_map_at(disable_net
);
1636 body_net
= body_inst
->GetInput2();
1645 // Use while() instead of if() to work around VIPER #13453
1646 while (inst
!= nullptr && inst
->Type() == PRIM_SVA_POSEDGE
)
1648 net
= inst
->GetInput();
1649 inst
= net
->Driver();;
1652 if (inst
!= nullptr && inst
->Type() == PRIM_INV
)
1654 net
= inst
->GetInput();
1655 inst
= net
->Driver();;
1659 // Detect clock-enable circuit
1661 if (inst
== nullptr || inst
->Type() != PRIM_AND
)
1664 Net
*net_dlatch
= inst
->GetInput1();
1665 Instance
*inst_dlatch
= net_dlatch
->Driver();
1667 if (inst_dlatch
== nullptr || inst_dlatch
->Type() != PRIM_DLATCHRS
)
1670 if (!inst_dlatch
->GetSet()->IsGnd() || !inst_dlatch
->GetReset()->IsGnd())
1673 Net
*net_enable
= inst_dlatch
->GetInput();
1674 Net
*net_not_clock
= inst_dlatch
->GetControl();
1676 if (net_enable
== nullptr || net_not_clock
== nullptr)
1679 Instance
*inst_not_clock
= net_not_clock
->Driver();
1681 if (inst_not_clock
== nullptr || inst_not_clock
->Type() != PRIM_INV
)
1684 Net
*net_clock1
= inst_not_clock
->GetInput();
1685 Net
*net_clock2
= inst
->GetInput2();
1687 if (net_clock1
== nullptr || net_clock1
!= net_clock2
)
1690 enable_net
= net_enable
;
1691 enable_sig
= importer
->net_map_at(enable_net
);
1694 inst
= net
->Driver();;
1697 // Detect condition expression
1699 if (body_net
== nullptr)
1702 Instance
*inst_mux
= body_net
->Driver();
1704 if (inst_mux
== nullptr || inst_mux
->Type() != PRIM_MUX
)
1707 if (!inst_mux
->GetInput1()->IsPwr())
1710 Net
*sva_net
= inst_mux
->GetInput2();
1711 if (!verific_is_sva_net(importer
, sva_net
))
1715 cond_net
= inst_mux
->GetControl();
1719 clock_sig
= importer
->net_map_at(clock_net
);
1721 const char *gclk_attr
= clock_net
->GetAttValue("gclk");
1722 if (gclk_attr
!= nullptr && (!strcmp(gclk_attr
, "1") || !strcmp(gclk_attr
, "'1'")))
1726 Cell
*VerificClocking::addDff(IdString name
, SigSpec sig_d
, SigSpec sig_q
, Const init_value
)
1728 log_assert(GetSize(sig_d
) == GetSize(sig_q
));
1730 if (GetSize(init_value
) != 0) {
1731 log_assert(GetSize(sig_q
) == GetSize(init_value
));
1732 if (sig_q
.is_wire()) {
1733 sig_q
.as_wire()->attributes
[ID::init
] = init_value
;
1735 Wire
*w
= module
->addWire(NEW_ID
, GetSize(sig_q
));
1736 w
->attributes
[ID::init
] = init_value
;
1737 module
->connect(sig_q
, w
);
1742 if (enable_sig
!= State::S1
)
1743 sig_d
= module
->Mux(NEW_ID
, sig_q
, sig_d
, enable_sig
);
1745 if (disable_sig
!= State::S0
) {
1746 log_assert(gclk
== false);
1747 log_assert(GetSize(sig_q
) == GetSize(init_value
));
1748 return module
->addAdff(name
, clock_sig
, disable_sig
, sig_d
, sig_q
, init_value
, posedge
);
1752 return module
->addFf(name
, sig_d
, sig_q
);
1754 return module
->addDff(name
, clock_sig
, sig_d
, sig_q
, posedge
);
1757 Cell
*VerificClocking::addAdff(IdString name
, RTLIL::SigSpec sig_arst
, SigSpec sig_d
, SigSpec sig_q
, Const arst_value
)
1759 log_assert(gclk
== false);
1760 log_assert(disable_sig
== State::S0
);
1762 if (enable_sig
!= State::S1
)
1763 sig_d
= module
->Mux(NEW_ID
, sig_q
, sig_d
, enable_sig
);
1765 return module
->addAdff(name
, clock_sig
, sig_arst
, sig_d
, sig_q
, arst_value
, posedge
);
1768 Cell
*VerificClocking::addDffsr(IdString name
, RTLIL::SigSpec sig_set
, RTLIL::SigSpec sig_clr
, SigSpec sig_d
, SigSpec sig_q
)
1770 log_assert(gclk
== false);
1771 log_assert(disable_sig
== State::S0
);
1773 if (enable_sig
!= State::S1
)
1774 sig_d
= module
->Mux(NEW_ID
, sig_q
, sig_d
, enable_sig
);
1776 return module
->addDffsr(name
, clock_sig
, sig_set
, sig_clr
, sig_d
, sig_q
, posedge
);
1779 // ==================================================================
1781 struct VerificExtNets
1783 int portname_cnt
= 0;
1785 // a map from Net to the same Net one level up in the design hierarchy
1786 std::map
<Net
*, Net
*> net_level_up_drive_up
;
1787 std::map
<Net
*, Net
*> net_level_up_drive_down
;
1789 Net
*route_up(Net
*net
, bool drive_up
, Net
*final_net
= nullptr)
1791 auto &net_level_up
= drive_up
? net_level_up_drive_up
: net_level_up_drive_down
;
1793 if (net_level_up
.count(net
) == 0)
1795 Netlist
*nl
= net
->Owner();
1797 // Simply return if Netlist is not unique
1798 log_assert(nl
->NumOfRefs() == 1);
1800 Instance
*up_inst
= (Instance
*)nl
->GetReferences()->GetLast();
1801 Netlist
*up_nl
= up_inst
->Owner();
1804 string name
= stringf("___extnets_%d", portname_cnt
++);
1805 Port
*new_port
= new Port(name
.c_str(), drive_up
? DIR_OUT
: DIR_IN
);
1807 net
->Connect(new_port
);
1809 // create new Net in up Netlist
1810 Net
*new_net
= final_net
;
1811 if (new_net
== nullptr || new_net
->Owner() != up_nl
) {
1812 new_net
= new Net(name
.c_str());
1813 up_nl
->Add(new_net
);
1815 up_inst
->Connect(new_port
, new_net
);
1817 net_level_up
[net
] = new_net
;
1820 return net_level_up
.at(net
);
1823 Net
*route_up(Net
*net
, bool drive_up
, Netlist
*dest
, Net
*final_net
= nullptr)
1825 while (net
->Owner() != dest
)
1826 net
= route_up(net
, drive_up
, final_net
);
1827 if (final_net
!= nullptr)
1828 log_assert(net
== final_net
);
1832 Netlist
*find_common_ancestor(Netlist
*A
, Netlist
*B
)
1834 std::set
<Netlist
*> ancestors_of_A
;
1836 Netlist
*cursor
= A
;
1838 ancestors_of_A
.insert(cursor
);
1839 if (cursor
->NumOfRefs() != 1)
1841 cursor
= ((Instance
*)cursor
->GetReferences()->GetLast())->Owner();
1846 if (ancestors_of_A
.count(cursor
))
1848 if (cursor
->NumOfRefs() != 1)
1850 cursor
= ((Instance
*)cursor
->GetReferences()->GetLast())->Owner();
1853 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());
1856 void run(Netlist
*nl
)
1862 vector
<tuple
<Instance
*, Port
*, Net
*>> todo_connect
;
1864 FOREACH_INSTANCE_OF_NETLIST(nl
, mi
, inst
)
1867 FOREACH_INSTANCE_OF_NETLIST(nl
, mi
, inst
)
1868 FOREACH_PORTREF_OF_INST(inst
, mi2
, pr
)
1870 Port
*port
= pr
->GetPort();
1871 Net
*net
= pr
->GetNet();
1873 if (!net
->IsExternalTo(nl
))
1876 if (verific_verbose
)
1877 log("Fixing external net reference on port %s.%s.%s:\n", get_full_netlist_name(nl
).c_str(), inst
->Name(), port
->Name());
1879 Netlist
*ext_nl
= net
->Owner();
1881 if (verific_verbose
)
1882 log(" external net owner: %s\n", get_full_netlist_name(ext_nl
).c_str());
1884 Netlist
*ca_nl
= find_common_ancestor(nl
, ext_nl
);
1886 if (verific_verbose
)
1887 log(" common ancestor: %s\n", get_full_netlist_name(ca_nl
).c_str());
1889 Net
*ca_net
= route_up(net
, !port
->IsOutput(), ca_nl
);
1890 Net
*new_net
= ca_net
;
1894 if (verific_verbose
)
1895 log(" net in common ancestor: %s\n", ca_net
->Name());
1897 string name
= stringf("___extnets_%d", portname_cnt
++);
1898 new_net
= new Net(name
.c_str());
1901 Net
*n
= route_up(new_net
, port
->IsOutput(), ca_nl
, ca_net
);
1902 log_assert(n
== ca_net
);
1905 if (verific_verbose
)
1906 log(" new local net: %s\n", new_net
->Name());
1908 log_assert(!new_net
->IsExternalTo(nl
));
1909 todo_connect
.push_back(tuple
<Instance
*, Port
*, Net
*>(inst
, port
, new_net
));
1912 for (auto it
: todo_connect
) {
1913 get
<0>(it
)->Disconnect(get
<1>(it
));
1914 get
<0>(it
)->Connect(get
<1>(it
), get
<2>(it
));
1919 void verific_import(Design
*design
, const std::map
<std::string
,std::string
> ¶meters
, std::string top
)
1921 verific_sva_fsm_limit
= 16;
1923 std::set
<Netlist
*> nl_todo
, nl_done
;
1925 VhdlLibrary
*vhdl_lib
= vhdl_file::GetLibrary("work", 1);
1926 VeriLibrary
*veri_lib
= veri_file::GetLibrary("work", 1);
1927 Array
*netlists
= NULL
;
1928 Array veri_libs
, vhdl_libs
;
1929 if (vhdl_lib
) vhdl_libs
.InsertLast(vhdl_lib
);
1930 if (veri_lib
) veri_libs
.InsertLast(veri_lib
);
1932 Map
verific_params(STRING_HASH
);
1933 for (const auto &i
: parameters
)
1934 verific_params
.Insert(i
.first
.c_str(), i
.second
.c_str());
1936 InitialAssertionRewriter rw
;
1937 rw
.RegisterCallBack();
1940 netlists
= hier_tree::ElaborateAll(&veri_libs
, &vhdl_libs
, &verific_params
);
1943 Array veri_modules
, vhdl_units
;
1946 VeriModule
*veri_module
= veri_lib
->GetModule(top
.c_str(), 1);
1948 veri_modules
.InsertLast(veri_module
);
1951 // Also elaborate all root modules since they may contain bind statements
1953 FOREACH_VERILOG_MODULE_IN_LIBRARY(veri_lib
, mi
, veri_module
) {
1954 if (!veri_module
->IsRootModule()) continue;
1955 veri_modules
.InsertLast(veri_module
);
1960 VhdlDesignUnit
*vhdl_unit
= vhdl_lib
->GetPrimUnit(top
.c_str());
1962 vhdl_units
.InsertLast(vhdl_unit
);
1965 netlists
= hier_tree::Elaborate(&veri_modules
, &vhdl_units
, &verific_params
);
1971 FOREACH_ARRAY_ITEM(netlists
, i
, nl
) {
1972 if (top
.empty() && nl
->CellBaseName() != top
)
1974 nl
->AddAtt(new Att(" \\top", NULL
));
1980 if (!verific_error_msg
.empty())
1981 log_error("%s\n", verific_error_msg
.c_str());
1983 for (auto nl
: nl_todo
)
1984 nl
->ChangePortBusStructures(1 /* hierarchical */);
1986 VerificExtNets worker
;
1987 for (auto nl
: nl_todo
)
1990 while (!nl_todo
.empty()) {
1991 Netlist
*nl
= *nl_todo
.begin();
1992 if (nl_done
.count(nl
) == 0) {
1993 VerificImporter
importer(false, false, false, false, false, false, false);
1994 importer
.import_netlist(design
, nl
, nl_todo
, nl
->Owner()->Name() == top
);
2003 verific_incdirs
.clear();
2004 verific_libdirs
.clear();
2005 verific_import_pending
= false;
2007 if (!verific_error_msg
.empty())
2008 log_error("%s\n", verific_error_msg
.c_str());
2012 #endif /* YOSYS_ENABLE_VERIFIC */
2014 PRIVATE_NAMESPACE_BEGIN
2016 #ifdef YOSYS_ENABLE_VERIFIC
2017 bool check_noverific_env()
2019 const char *e
= getenv("YOSYS_NOVERIFIC");
2028 struct VerificPass
: public Pass
{
2029 VerificPass() : Pass("verific", "load Verilog and VHDL designs using Verific") { }
2030 void help() override
2032 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
2034 log(" verific {-vlog95|-vlog2k|-sv2005|-sv2009|-sv2012|-sv} <verilog-file>..\n");
2036 log("Load the specified Verilog/SystemVerilog files into Verific.\n");
2038 log("All files specified in one call to this command are one compilation unit.\n");
2039 log("Files passed to different calls to this command are treated as belonging to\n");
2040 log("different compilation units.\n");
2042 log("Additional -D<macro>[=<value>] options may be added after the option indicating\n");
2043 log("the language version (and before file names) to set additional verilog defines.\n");
2044 log("The macros SYNTHESIS and VERIFIC are defined implicitly.\n");
2047 log(" verific -formal <verilog-file>..\n");
2049 log("Like -sv, but define FORMAL instead of SYNTHESIS.\n");
2052 log(" verific {-vhdl87|-vhdl93|-vhdl2k|-vhdl2008|-vhdl} <vhdl-file>..\n");
2054 log("Load the specified VHDL files into Verific.\n");
2057 log(" verific [-work <libname>] {-sv|-vhdl|...} <hdl-file>\n");
2059 log("Load the specified Verilog/SystemVerilog/VHDL file into the specified library.\n");
2060 log("(default library when -work is not present: \"work\")\n");
2063 log(" verific [-L <libname>] {-sv|-vhdl|...} <hdl-file>\n");
2065 log("Look up external definitions in the specified library.\n");
2066 log("(-L may be used more than once)\n");
2069 log(" verific -vlog-incdir <directory>..\n");
2071 log("Add Verilog include directories.\n");
2074 log(" verific -vlog-libdir <directory>..\n");
2076 log("Add Verilog library directories. Verific will search in this directories to\n");
2077 log("find undefined modules.\n");
2080 log(" verific -vlog-define <macro>[=<value>]..\n");
2082 log("Add Verilog defines.\n");
2085 log(" verific -vlog-undef <macro>..\n");
2087 log("Remove Verilog defines previously set with -vlog-define.\n");
2090 log(" verific -set-error <msg_id>..\n");
2091 log(" verific -set-warning <msg_id>..\n");
2092 log(" verific -set-info <msg_id>..\n");
2093 log(" verific -set-ignore <msg_id>..\n");
2095 log("Set message severity. <msg_id> is the string in square brackets when a message\n");
2096 log("is printed, such as VERI-1209.\n");
2099 log(" verific -import [options] <top-module>..\n");
2101 log("Elaborate the design for the specified top modules, import to Yosys and\n");
2102 log("reset the internal state of Verific.\n");
2104 log("Import options:\n");
2107 log(" Elaborate all modules, not just the hierarchy below the given top\n");
2108 log(" modules. With this option the list of modules to import is optional.\n");
2111 log(" Create a gate-level netlist.\n");
2114 log(" Flatten the design in Verific before importing.\n");
2117 log(" Resolve references to external nets by adding module ports as needed.\n");
2119 log(" -autocover\n");
2120 log(" Generate automatic cover statements for all asserts\n");
2122 log(" -fullinit\n");
2123 log(" Keep all register initializations, even those for non-FF registers.\n");
2125 log(" -chparam name value \n");
2126 log(" Elaborate the specified top modules (all modules when -all given) using\n");
2127 log(" this parameter value. Modules on which this parameter does not exist will\n");
2128 log(" cause Verific to produce a VERI-1928 or VHDL-1676 message. This option\n");
2129 log(" can be specified multiple times to override multiple parameters.\n");
2130 log(" String values must be passed in double quotes (\").\n");
2133 log(" Verbose log messages. (-vv is even more verbose than -v.)\n");
2135 log("The following additional import options are useful for debugging the Verific\n");
2136 log("bindings (for Yosys and/or Verific developers):\n");
2139 log(" Keep going after an unsupported verific primitive is found. The\n");
2140 log(" unsupported primitive is added as blockbox module to the design.\n");
2141 log(" This will also add all SVA related cells to the design parallel to\n");
2142 log(" the checker logic inferred by it.\n");
2145 log(" Import Verific netlist as-is without translating to Yosys cell types. \n");
2148 log(" Ignore SVA properties, do not infer checker logic.\n");
2151 log(" Maximum number of ctrl bits for SVA checker FSMs (default=16).\n");
2154 log(" Keep all Verific names on instances and nets. By default only\n");
2155 log(" user-declared names are preserved.\n");
2157 log(" -d <dump_file>\n");
2158 log(" Dump the Verific netlist as a verilog file.\n");
2161 log("Use Symbiotic EDA Suite if you need Yosys+Verifc.\n");
2162 log("https://www.symbioticeda.com/seda-suite\n");
2164 log("Contact office@symbioticeda.com for free evaluation\n");
2165 log("binaries of Symbiotic EDA Suite.\n");
2168 #ifdef YOSYS_ENABLE_VERIFIC
2169 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) override
2171 static bool set_verific_global_flags
= true;
2173 if (check_noverific_env())
2174 log_cmd_error("This version of Yosys is built without Verific support.\n"
2176 "Use Symbiotic EDA Suite if you need Yosys+Verifc.\n"
2177 "https://www.symbioticeda.com/seda-suite\n"
2179 "Contact office@symbioticeda.com for free evaluation\n"
2180 "binaries of Symbiotic EDA Suite.\n");
2182 log_header(design
, "Executing VERIFIC (loading SystemVerilog and VHDL designs using Verific).\n");
2184 if (set_verific_global_flags
)
2186 Message::SetConsoleOutput(0);
2187 Message::RegisterCallBackMsg(msg_func
);
2189 RuntimeFlags::SetVar("db_preserve_user_nets", 1);
2190 RuntimeFlags::SetVar("db_allow_external_nets", 1);
2191 RuntimeFlags::SetVar("db_infer_wide_operators", 1);
2193 RuntimeFlags::SetVar("veri_extract_dualport_rams", 0);
2194 RuntimeFlags::SetVar("veri_extract_multiport_rams", 1);
2196 RuntimeFlags::SetVar("vhdl_extract_dualport_rams", 0);
2197 RuntimeFlags::SetVar("vhdl_extract_multiport_rams", 1);
2199 RuntimeFlags::SetVar("vhdl_support_variable_slice", 1);
2200 RuntimeFlags::SetVar("vhdl_ignore_assertion_statements", 0);
2202 RuntimeFlags::SetVar("veri_preserve_assignments", 1);
2203 RuntimeFlags::SetVar("vhdl_preserve_assignments", 1);
2205 // Workaround for VIPER #13851
2206 RuntimeFlags::SetVar("veri_create_name_for_unnamed_gen_block", 1);
2208 // WARNING: instantiating unknown module 'XYZ' (VERI-1063)
2209 Message::SetMessageType("VERI-1063", VERIFIC_ERROR
);
2211 // https://github.com/YosysHQ/yosys/issues/1055
2212 RuntimeFlags::SetVar("veri_elaborate_top_level_modules_having_interface_ports", 1) ;
2214 #ifndef DB_PRESERVE_INITIAL_VALUE
2215 # warning Verific was built without DB_PRESERVE_INITIAL_VALUE.
2218 set_verific_global_flags
= false;
2221 verific_verbose
= 0;
2222 verific_sva_fsm_limit
= 16;
2224 const char *release_str
= Message::ReleaseString();
2225 time_t release_time
= Message::ReleaseDate();
2226 char *release_tmstr
= ctime(&release_time
);
2228 if (release_str
== nullptr)
2229 release_str
= "(no release string)";
2231 for (char *p
= release_tmstr
; *p
; p
++)
2232 if (*p
== '\n') *p
= 0;
2234 log("Built with Verific %s, released at %s.\n", release_str
, release_tmstr
);
2237 std::string work
= "work";
2239 if (GetSize(args
) > argidx
&& (args
[argidx
] == "-set-error" || args
[argidx
] == "-set-warning" ||
2240 args
[argidx
] == "-set-info" || args
[argidx
] == "-set-ignore"))
2242 msg_type_t new_type
;
2244 if (args
[argidx
] == "-set-error")
2245 new_type
= VERIFIC_ERROR
;
2246 else if (args
[argidx
] == "-set-warning")
2247 new_type
= VERIFIC_WARNING
;
2248 else if (args
[argidx
] == "-set-info")
2249 new_type
= VERIFIC_INFO
;
2250 else if (args
[argidx
] == "-set-ignore")
2251 new_type
= VERIFIC_IGNORE
;
2255 for (argidx
++; argidx
< GetSize(args
); argidx
++)
2256 Message::SetMessageType(args
[argidx
].c_str(), new_type
);
2261 if (GetSize(args
) > argidx
&& args
[argidx
] == "-vlog-incdir") {
2262 for (argidx
++; argidx
< GetSize(args
); argidx
++)
2263 verific_incdirs
.push_back(args
[argidx
]);
2267 if (GetSize(args
) > argidx
&& args
[argidx
] == "-vlog-libdir") {
2268 for (argidx
++; argidx
< GetSize(args
); argidx
++)
2269 verific_libdirs
.push_back(args
[argidx
]);
2273 if (GetSize(args
) > argidx
&& args
[argidx
] == "-vlog-define") {
2274 for (argidx
++; argidx
< GetSize(args
); argidx
++) {
2275 string name
= args
[argidx
];
2276 size_t equal
= name
.find('=');
2277 if (equal
!= std::string::npos
) {
2278 string value
= name
.substr(equal
+1);
2279 name
= name
.substr(0, equal
);
2280 veri_file::DefineCmdLineMacro(name
.c_str(), value
.c_str());
2282 veri_file::DefineCmdLineMacro(name
.c_str());
2288 if (GetSize(args
) > argidx
&& args
[argidx
] == "-vlog-undef") {
2289 for (argidx
++; argidx
< GetSize(args
); argidx
++) {
2290 string name
= args
[argidx
];
2291 veri_file::UndefineMacro(name
.c_str());
2296 veri_file::RemoveAllLOptions();
2297 for (; argidx
< GetSize(args
); argidx
++)
2299 if (args
[argidx
] == "-work" && argidx
+1 < GetSize(args
)) {
2300 work
= args
[++argidx
];
2303 if (args
[argidx
] == "-L" && argidx
+1 < GetSize(args
)) {
2304 veri_file::AddLOption(args
[++argidx
].c_str());
2310 if (GetSize(args
) > argidx
&& (args
[argidx
] == "-vlog95" || args
[argidx
] == "-vlog2k" || args
[argidx
] == "-sv2005" ||
2311 args
[argidx
] == "-sv2009" || args
[argidx
] == "-sv2012" || args
[argidx
] == "-sv" || args
[argidx
] == "-formal"))
2314 unsigned verilog_mode
;
2316 if (args
[argidx
] == "-vlog95")
2317 verilog_mode
= veri_file::VERILOG_95
;
2318 else if (args
[argidx
] == "-vlog2k")
2319 verilog_mode
= veri_file::VERILOG_2K
;
2320 else if (args
[argidx
] == "-sv2005")
2321 verilog_mode
= veri_file::SYSTEM_VERILOG_2005
;
2322 else if (args
[argidx
] == "-sv2009")
2323 verilog_mode
= veri_file::SYSTEM_VERILOG_2009
;
2324 else if (args
[argidx
] == "-sv2012" || args
[argidx
] == "-sv" || args
[argidx
] == "-formal")
2325 verilog_mode
= veri_file::SYSTEM_VERILOG
;
2329 veri_file::DefineMacro("VERIFIC");
2330 veri_file::DefineMacro(args
[argidx
] == "-formal" ? "FORMAL" : "SYNTHESIS");
2332 for (argidx
++; argidx
< GetSize(args
) && GetSize(args
[argidx
]) >= 2 && args
[argidx
].compare(0, 2, "-D") == 0; argidx
++) {
2333 std::string name
= args
[argidx
].substr(2);
2334 if (args
[argidx
] == "-D") {
2335 if (++argidx
>= GetSize(args
))
2337 name
= args
[argidx
];
2339 size_t equal
= name
.find('=');
2340 if (equal
!= std::string::npos
) {
2341 string value
= name
.substr(equal
+1);
2342 name
= name
.substr(0, equal
);
2343 veri_file::DefineMacro(name
.c_str(), value
.c_str());
2345 veri_file::DefineMacro(name
.c_str());
2349 for (auto &dir
: verific_incdirs
)
2350 veri_file::AddIncludeDir(dir
.c_str());
2351 for (auto &dir
: verific_libdirs
)
2352 veri_file::AddYDir(dir
.c_str());
2354 while (argidx
< GetSize(args
))
2355 file_names
.Insert(args
[argidx
++].c_str());
2357 if (!veri_file::AnalyzeMultipleFiles(&file_names
, verilog_mode
, work
.c_str(), veri_file::MFCU
)) {
2358 verific_error_msg
.clear();
2359 log_cmd_error("Reading Verilog/SystemVerilog sources failed.\n");
2362 verific_import_pending
= true;
2366 if (GetSize(args
) > argidx
&& args
[argidx
] == "-vhdl87") {
2367 vhdl_file::SetDefaultLibraryPath((proc_share_dirname() + "verific/vhdl_vdbs_1987").c_str());
2368 for (argidx
++; argidx
< GetSize(args
); argidx
++)
2369 if (!vhdl_file::Analyze(args
[argidx
].c_str(), work
.c_str(), vhdl_file::VHDL_87
))
2370 log_cmd_error("Reading `%s' in VHDL_87 mode failed.\n", args
[argidx
].c_str());
2371 verific_import_pending
= true;
2375 if (GetSize(args
) > argidx
&& args
[argidx
] == "-vhdl93") {
2376 vhdl_file::SetDefaultLibraryPath((proc_share_dirname() + "verific/vhdl_vdbs_1993").c_str());
2377 for (argidx
++; argidx
< GetSize(args
); argidx
++)
2378 if (!vhdl_file::Analyze(args
[argidx
].c_str(), work
.c_str(), vhdl_file::VHDL_93
))
2379 log_cmd_error("Reading `%s' in VHDL_93 mode failed.\n", args
[argidx
].c_str());
2380 verific_import_pending
= true;
2384 if (GetSize(args
) > argidx
&& args
[argidx
] == "-vhdl2k") {
2385 vhdl_file::SetDefaultLibraryPath((proc_share_dirname() + "verific/vhdl_vdbs_1993").c_str());
2386 for (argidx
++; argidx
< GetSize(args
); argidx
++)
2387 if (!vhdl_file::Analyze(args
[argidx
].c_str(), work
.c_str(), vhdl_file::VHDL_2K
))
2388 log_cmd_error("Reading `%s' in VHDL_2K mode failed.\n", args
[argidx
].c_str());
2389 verific_import_pending
= true;
2393 if (GetSize(args
) > argidx
&& (args
[argidx
] == "-vhdl2008" || args
[argidx
] == "-vhdl")) {
2394 vhdl_file::SetDefaultLibraryPath((proc_share_dirname() + "verific/vhdl_vdbs_2008").c_str());
2395 for (argidx
++; argidx
< GetSize(args
); argidx
++)
2396 if (!vhdl_file::Analyze(args
[argidx
].c_str(), work
.c_str(), vhdl_file::VHDL_2008
))
2397 log_cmd_error("Reading `%s' in VHDL_2008 mode failed.\n", args
[argidx
].c_str());
2398 verific_import_pending
= true;
2402 if (GetSize(args
) > argidx
&& args
[argidx
] == "-import")
2404 std::set
<Netlist
*> nl_todo
, nl_done
;
2405 bool mode_all
= false, mode_gates
= false, mode_keep
= false;
2406 bool mode_nosva
= false, mode_names
= false, mode_verific
= false;
2407 bool mode_autocover
= false, mode_fullinit
= false;
2408 bool flatten
= false, extnets
= false;
2410 Map
parameters(STRING_HASH
);
2412 for (argidx
++; argidx
< GetSize(args
); argidx
++) {
2413 if (args
[argidx
] == "-all") {
2417 if (args
[argidx
] == "-gates") {
2421 if (args
[argidx
] == "-flatten") {
2425 if (args
[argidx
] == "-extnets") {
2429 if (args
[argidx
] == "-k") {
2433 if (args
[argidx
] == "-nosva") {
2437 if (args
[argidx
] == "-L" && argidx
+1 < GetSize(args
)) {
2438 verific_sva_fsm_limit
= atoi(args
[++argidx
].c_str());
2441 if (args
[argidx
] == "-n") {
2445 if (args
[argidx
] == "-autocover") {
2446 mode_autocover
= true;
2449 if (args
[argidx
] == "-fullinit") {
2450 mode_fullinit
= true;
2453 if (args
[argidx
] == "-chparam" && argidx
+2 < GetSize(args
)) {
2454 const std::string
&key
= args
[++argidx
];
2455 const std::string
&value
= args
[++argidx
];
2456 unsigned new_insertion
= parameters
.Insert(key
.c_str(), value
.c_str(),
2457 1 /* force_overwrite */);
2459 log_warning_noprefix("-chparam %s already specified: overwriting.\n", key
.c_str());
2462 if (args
[argidx
] == "-V") {
2463 mode_verific
= true;
2466 if (args
[argidx
] == "-v") {
2467 verific_verbose
= 1;
2470 if (args
[argidx
] == "-vv") {
2471 verific_verbose
= 2;
2474 if (args
[argidx
] == "-d" && argidx
+1 < GetSize(args
)) {
2475 dumpfile
= args
[++argidx
];
2481 if (argidx
> GetSize(args
) && args
[argidx
].compare(0, 1, "-") == 0)
2482 cmd_error(args
, argidx
, "unknown option");
2484 std::set
<std::string
> top_mod_names
;
2486 InitialAssertionRewriter rw
;
2487 rw
.RegisterCallBack();
2491 log("Running hier_tree::ElaborateAll().\n");
2493 VhdlLibrary
*vhdl_lib
= vhdl_file::GetLibrary(work
.c_str(), 1);
2494 VeriLibrary
*veri_lib
= veri_file::GetLibrary(work
.c_str(), 1);
2496 Array veri_libs
, vhdl_libs
;
2497 if (vhdl_lib
) vhdl_libs
.InsertLast(vhdl_lib
);
2498 if (veri_lib
) veri_libs
.InsertLast(veri_lib
);
2500 Array
*netlists
= hier_tree::ElaborateAll(&veri_libs
, &vhdl_libs
, ¶meters
);
2504 FOREACH_ARRAY_ITEM(netlists
, i
, nl
)
2510 if (argidx
== GetSize(args
))
2511 cmd_error(args
, argidx
, "No top module specified.\n");
2513 VeriLibrary
* veri_lib
= veri_file::GetLibrary(work
.c_str(), 1);
2514 VhdlLibrary
*vhdl_lib
= vhdl_file::GetLibrary(work
.c_str(), 1);
2516 Array veri_modules
, vhdl_units
;
2517 for (; argidx
< GetSize(args
); argidx
++)
2519 const char *name
= args
[argidx
].c_str();
2520 top_mod_names
.insert(name
);
2522 VeriModule
*veri_module
= veri_lib
? veri_lib
->GetModule(name
, 1) : nullptr;
2524 log("Adding Verilog module '%s' to elaboration queue.\n", name
);
2525 veri_modules
.InsertLast(veri_module
);
2529 VhdlDesignUnit
*vhdl_unit
= vhdl_lib
? vhdl_lib
->GetPrimUnit(name
) : nullptr;
2531 log("Adding VHDL unit '%s' to elaboration queue.\n", name
);
2532 vhdl_units
.InsertLast(vhdl_unit
);
2536 log_error("Can't find module/unit '%s'.\n", name
);
2540 // Also elaborate all root modules since they may contain bind statements
2542 VeriModule
*veri_module
;
2543 FOREACH_VERILOG_MODULE_IN_LIBRARY(veri_lib
, mi
, veri_module
) {
2544 if (!veri_module
->IsRootModule()) continue;
2545 veri_modules
.InsertLast(veri_module
);
2549 log("Running hier_tree::Elaborate().\n");
2550 Array
*netlists
= hier_tree::Elaborate(&veri_modules
, &vhdl_units
, ¶meters
);
2554 FOREACH_ARRAY_ITEM(netlists
, i
, nl
) {
2555 nl
->AddAtt(new Att(" \\top", NULL
));
2561 if (!verific_error_msg
.empty())
2565 for (auto nl
: nl_todo
)
2570 VerificExtNets worker
;
2571 for (auto nl
: nl_todo
)
2575 for (auto nl
: nl_todo
)
2576 nl
->ChangePortBusStructures(1 /* hierarchical */);
2578 if (!dumpfile
.empty()) {
2579 VeriWrite veri_writer
;
2580 veri_writer
.WriteFile(dumpfile
.c_str(), Netlist::PresentDesign());
2583 while (!nl_todo
.empty()) {
2584 Netlist
*nl
= *nl_todo
.begin();
2585 if (nl_done
.count(nl
) == 0) {
2586 VerificImporter
importer(mode_gates
, mode_keep
, mode_nosva
,
2587 mode_names
, mode_verific
, mode_autocover
, mode_fullinit
);
2588 importer
.import_netlist(design
, nl
, nl_todo
, top_mod_names
.count(nl
->Owner()->Name()));
2597 verific_incdirs
.clear();
2598 verific_libdirs
.clear();
2599 verific_import_pending
= false;
2603 cmd_error(args
, argidx
, "Missing or unsupported mode parameter.\n");
2606 if (!verific_error_msg
.empty())
2607 log_error("%s\n", verific_error_msg
.c_str());
2610 #else /* YOSYS_ENABLE_VERIFIC */
2611 void execute(std::vector
<std::string
>, RTLIL::Design
*) override
{
2612 log_cmd_error("This version of Yosys is built without Verific support.\n"
2614 "Use Symbiotic EDA Suite if you need Yosys+Verifc.\n"
2615 "https://www.symbioticeda.com/seda-suite\n"
2617 "Contact office@symbioticeda.com for free evaluation\n"
2618 "binaries of Symbiotic EDA Suite.\n");
2623 struct ReadPass
: public Pass
{
2624 ReadPass() : Pass("read", "load HDL designs") { }
2625 void help() override
2627 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
2629 log(" read {-vlog95|-vlog2k|-sv2005|-sv2009|-sv2012|-sv|-formal} <verilog-file>..\n");
2631 log("Load the specified Verilog/SystemVerilog files. (Full SystemVerilog support\n");
2632 log("is only available via Verific.)\n");
2634 log("Additional -D<macro>[=<value>] options may be added after the option indicating\n");
2635 log("the language version (and before file names) to set additional verilog defines.\n");
2638 log(" read {-vhdl87|-vhdl93|-vhdl2k|-vhdl2008|-vhdl} <vhdl-file>..\n");
2640 log("Load the specified VHDL files. (Requires Verific.)\n");
2643 log(" read -define <macro>[=<value>]..\n");
2645 log("Set global Verilog/SystemVerilog defines.\n");
2648 log(" read -undef <macro>..\n");
2650 log("Unset global Verilog/SystemVerilog defines.\n");
2653 log(" read -incdir <directory>\n");
2655 log("Add directory to global Verilog/SystemVerilog include directories.\n");
2658 log(" read -verific\n");
2659 log(" read -noverific\n");
2661 log("Subsequent calls to 'read' will either use or not use Verific. Calling 'read'\n");
2662 log("with -verific will result in an error on Yosys binaries that are built without\n");
2663 log("Verific support. The default is to use Verific if it is available.\n");
2666 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) override
2668 #ifdef YOSYS_ENABLE_VERIFIC
2669 static bool verific_available
= !check_noverific_env();
2671 static bool verific_available
= false;
2673 static bool use_verific
= verific_available
;
2675 if (args
.size() < 2 || args
[1][0] != '-')
2676 cmd_error(args
, 1, "Missing mode parameter.\n");
2678 if (args
[1] == "-verific" || args
[1] == "-noverific") {
2679 if (args
.size() != 2)
2680 cmd_error(args
, 1, "Additional arguments to -verific/-noverific.\n");
2681 if (args
[1] == "-verific") {
2682 if (!verific_available
)
2683 cmd_error(args
, 1, "This version of Yosys is built without Verific support.\n");
2686 use_verific
= false;
2691 if (args
.size() < 3)
2692 cmd_error(args
, 3, "Missing file name parameter.\n");
2694 if (args
[1] == "-vlog95" || args
[1] == "-vlog2k") {
2696 args
[0] = "verific";
2698 args
[0] = "read_verilog";
2701 Pass::call(design
, args
);
2705 if (args
[1] == "-sv2005" || args
[1] == "-sv2009" || args
[1] == "-sv2012" || args
[1] == "-sv" || args
[1] == "-formal") {
2707 args
[0] = "verific";
2709 args
[0] = "read_verilog";
2710 if (args
[1] == "-formal")
2711 args
.insert(args
.begin()+1, std::string());
2713 args
.insert(args
.begin()+1, "-defer");
2715 Pass::call(design
, args
);
2719 if (args
[1] == "-vhdl87" || args
[1] == "-vhdl93" || args
[1] == "-vhdl2k" || args
[1] == "-vhdl2008" || args
[1] == "-vhdl") {
2721 args
[0] = "verific";
2722 Pass::call(design
, args
);
2724 cmd_error(args
, 1, "This version of Yosys is built without Verific support.\n");
2729 if (args
[1] == "-define") {
2731 args
[0] = "verific";
2732 args
[1] = "-vlog-define";
2733 Pass::call(design
, args
);
2735 args
[0] = "verilog_defines";
2736 args
.erase(args
.begin()+1, args
.begin()+2);
2737 for (int i
= 1; i
< GetSize(args
); i
++)
2738 args
[i
] = "-D" + args
[i
];
2739 Pass::call(design
, args
);
2743 if (args
[1] == "-undef") {
2745 args
[0] = "verific";
2746 args
[1] = "-vlog-undef";
2747 Pass::call(design
, args
);
2749 args
[0] = "verilog_defines";
2750 args
.erase(args
.begin()+1, args
.begin()+2);
2751 for (int i
= 1; i
< GetSize(args
); i
++)
2752 args
[i
] = "-U" + args
[i
];
2753 Pass::call(design
, args
);
2757 if (args
[1] == "-incdir") {
2759 args
[0] = "verific";
2760 args
[1] = "-vlog-incdir";
2761 Pass::call(design
, args
);
2763 args
[0] = "verilog_defaults";
2765 for (int i
= 2; i
< GetSize(args
); i
++)
2766 args
[i
] = "-I" + args
[i
];
2767 Pass::call(design
, args
);
2771 cmd_error(args
, 1, "Missing or unsupported mode parameter.\n");
2775 PRIVATE_NAMESPACE_END