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/log.h"
32 #include "frontends/verific/verific.h"
36 #ifdef YOSYS_ENABLE_VERIFIC
39 #pragma clang diagnostic push
40 #pragma clang diagnostic ignored "-Woverloaded-virtual"
43 #include "veri_file.h"
44 #include "vhdl_file.h"
45 #include "hier_tree.h"
46 #include "VeriModule.h"
47 #include "VeriWrite.h"
48 #include "VhdlUnits.h"
49 #include "HierTreeNode.h"
53 #pragma clang diagnostic pop
56 #ifdef VERIFIC_NAMESPACE
57 using namespace Verific
;
62 #ifdef YOSYS_ENABLE_VERIFIC
66 bool verific_import_pending
;
67 string verific_error_msg
;
68 int verific_sva_fsm_limit
;
70 vector
<string
> verific_incdirs
, verific_libdirs
;
72 void msg_func(msg_type_t msg_type
, const char *message_id
, linefile_type linefile
, const char *msg
, va_list args
)
74 string message_prefix
= stringf("VERIFIC-%s [%s] ",
75 msg_type
== VERIFIC_NONE
? "NONE" :
76 msg_type
== VERIFIC_ERROR
? "ERROR" :
77 msg_type
== VERIFIC_WARNING
? "WARNING" :
78 msg_type
== VERIFIC_IGNORE
? "IGNORE" :
79 msg_type
== VERIFIC_INFO
? "INFO" :
80 msg_type
== VERIFIC_COMMENT
? "COMMENT" :
81 msg_type
== VERIFIC_PROGRAM_ERROR
? "PROGRAM_ERROR" : "UNKNOWN", message_id
);
83 string message
= linefile
? stringf("%s:%d: ", LineFile::GetFileName(linefile
), LineFile::GetLineNo(linefile
)) : "";
84 message
+= vstringf(msg
, args
);
86 if (msg_type
== VERIFIC_ERROR
|| msg_type
== VERIFIC_WARNING
|| msg_type
== VERIFIC_PROGRAM_ERROR
)
87 log_warning_noprefix("%s%s\n", message_prefix
.c_str(), message
.c_str());
89 log("%s%s\n", message_prefix
.c_str(), message
.c_str());
91 if (verific_error_msg
.empty() && (msg_type
== VERIFIC_ERROR
|| msg_type
== VERIFIC_PROGRAM_ERROR
))
92 verific_error_msg
= message
;
95 string
get_full_netlist_name(Netlist
*nl
)
97 if (nl
->NumOfRefs() == 1) {
98 Instance
*inst
= (Instance
*)nl
->GetReferences()->GetLast();
99 return get_full_netlist_name(inst
->Owner()) + "." + inst
->Name();
102 return nl
->CellBaseName();
105 // ==================================================================
107 VerificImporter::VerificImporter(bool mode_gates
, bool mode_keep
, bool mode_nosva
, bool mode_names
, bool mode_verific
, bool mode_autocover
) :
108 mode_gates(mode_gates
), mode_keep(mode_keep
), mode_nosva(mode_nosva
),
109 mode_names(mode_names
), mode_verific(mode_verific
), mode_autocover(mode_autocover
)
113 RTLIL::SigBit
VerificImporter::net_map_at(Net
*net
)
115 if (net
->IsExternalTo(netlist
))
116 log_error("Found external reference to '%s.%s' in netlist '%s', please use -flatten or -extnets.\n",
117 get_full_netlist_name(net
->Owner()).c_str(), net
->Name(), get_full_netlist_name(netlist
).c_str());
119 return net_map
.at(net
);
122 bool is_blackbox(Netlist
*nl
)
124 if (nl
->IsBlackBox())
127 const char *attr
= nl
->GetAttValue("blackbox");
128 if (attr
!= nullptr && strcmp(attr
, "0"))
134 RTLIL::IdString
VerificImporter::new_verific_id(Verific::DesignObj
*obj
)
136 std::string s
= stringf("$verific$%s", obj
->Name());
138 s
+= stringf("$%s:%d", Verific::LineFile::GetFileName(obj
->Linefile()), Verific::LineFile::GetLineNo(obj
->Linefile()));
139 s
+= stringf("$%d", autoidx
++);
143 void VerificImporter::import_attributes(dict
<RTLIL::IdString
, RTLIL::Const
> &attributes
, DesignObj
*obj
)
149 attributes
["\\src"] = stringf("%s:%d", LineFile::GetFileName(obj
->Linefile()), LineFile::GetLineNo(obj
->Linefile()));
151 // FIXME: Parse numeric attributes
152 FOREACH_ATTRIBUTE(obj
, mi
, attr
) {
153 if (attr
->Key()[0] == ' ' || attr
->Value() == nullptr)
155 attributes
[RTLIL::escape_id(attr
->Key())] = RTLIL::Const(std::string(attr
->Value()));
159 RTLIL::SigSpec
VerificImporter::operatorInput(Instance
*inst
)
162 for (int i
= int(inst
->InputSize())-1; i
>= 0; i
--)
163 if (inst
->GetInputBit(i
))
164 sig
.append(net_map_at(inst
->GetInputBit(i
)));
166 sig
.append(RTLIL::State::Sz
);
170 RTLIL::SigSpec
VerificImporter::operatorInput1(Instance
*inst
)
173 for (int i
= int(inst
->Input1Size())-1; i
>= 0; i
--)
174 if (inst
->GetInput1Bit(i
))
175 sig
.append(net_map_at(inst
->GetInput1Bit(i
)));
177 sig
.append(RTLIL::State::Sz
);
181 RTLIL::SigSpec
VerificImporter::operatorInput2(Instance
*inst
)
184 for (int i
= int(inst
->Input2Size())-1; i
>= 0; i
--)
185 if (inst
->GetInput2Bit(i
))
186 sig
.append(net_map_at(inst
->GetInput2Bit(i
)));
188 sig
.append(RTLIL::State::Sz
);
192 RTLIL::SigSpec
VerificImporter::operatorInport(Instance
*inst
, const char *portname
)
194 PortBus
*portbus
= inst
->View()->GetPortBus(portname
);
197 for (unsigned i
= 0; i
< portbus
->Size(); i
++) {
198 Net
*net
= inst
->GetNet(portbus
->ElementAtIndex(i
));
201 sig
.append(RTLIL::State::S0
);
202 else if (net
->IsPwr())
203 sig
.append(RTLIL::State::S1
);
205 sig
.append(net_map_at(net
));
207 sig
.append(RTLIL::State::Sz
);
211 Port
*port
= inst
->View()->GetPort(portname
);
212 log_assert(port
!= NULL
);
213 Net
*net
= inst
->GetNet(port
);
214 return net_map_at(net
);
218 RTLIL::SigSpec
VerificImporter::operatorOutput(Instance
*inst
, const pool
<Net
*, hash_ptr_ops
> *any_all_nets
)
221 RTLIL::Wire
*dummy_wire
= NULL
;
222 for (int i
= int(inst
->OutputSize())-1; i
>= 0; i
--)
223 if (inst
->GetOutputBit(i
) && (!any_all_nets
|| !any_all_nets
->count(inst
->GetOutputBit(i
)))) {
224 sig
.append(net_map_at(inst
->GetOutputBit(i
)));
227 if (dummy_wire
== NULL
)
228 dummy_wire
= module
->addWire(new_verific_id(inst
));
231 sig
.append(RTLIL::SigSpec(dummy_wire
, dummy_wire
->width
- 1));
236 bool VerificImporter::import_netlist_instance_gates(Instance
*inst
, RTLIL::IdString inst_name
)
238 if (inst
->Type() == PRIM_AND
) {
239 module
->addAndGate(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetOutput()));
243 if (inst
->Type() == PRIM_NAND
) {
244 RTLIL::SigSpec tmp
= module
->addWire(new_verific_id(inst
));
245 module
->addAndGate(new_verific_id(inst
), net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), tmp
);
246 module
->addNotGate(inst_name
, tmp
, net_map_at(inst
->GetOutput()));
250 if (inst
->Type() == PRIM_OR
) {
251 module
->addOrGate(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetOutput()));
255 if (inst
->Type() == PRIM_NOR
) {
256 RTLIL::SigSpec tmp
= module
->addWire(new_verific_id(inst
));
257 module
->addOrGate(new_verific_id(inst
), net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), tmp
);
258 module
->addNotGate(inst_name
, tmp
, net_map_at(inst
->GetOutput()));
262 if (inst
->Type() == PRIM_XOR
) {
263 module
->addXorGate(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetOutput()));
267 if (inst
->Type() == PRIM_XNOR
) {
268 module
->addXnorGate(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetOutput()));
272 if (inst
->Type() == PRIM_BUF
) {
273 auto outnet
= inst
->GetOutput();
274 if (!any_all_nets
.count(outnet
))
275 module
->addBufGate(inst_name
, net_map_at(inst
->GetInput()), net_map_at(outnet
));
279 if (inst
->Type() == PRIM_INV
) {
280 module
->addNotGate(inst_name
, net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()));
284 if (inst
->Type() == PRIM_MUX
) {
285 module
->addMuxGate(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetControl()), net_map_at(inst
->GetOutput()));
289 if (inst
->Type() == PRIM_TRI
) {
290 module
->addMuxGate(inst_name
, RTLIL::State::Sz
, net_map_at(inst
->GetInput()), net_map_at(inst
->GetControl()), net_map_at(inst
->GetOutput()));
294 if (inst
->Type() == PRIM_FADD
)
296 RTLIL::SigSpec a
= net_map_at(inst
->GetInput1()), b
= net_map_at(inst
->GetInput2()), c
= net_map_at(inst
->GetCin());
297 RTLIL::SigSpec x
= inst
->GetCout() ? net_map_at(inst
->GetCout()) : module
->addWire(new_verific_id(inst
));
298 RTLIL::SigSpec y
= inst
->GetOutput() ? net_map_at(inst
->GetOutput()) : module
->addWire(new_verific_id(inst
));
299 RTLIL::SigSpec tmp1
= module
->addWire(new_verific_id(inst
));
300 RTLIL::SigSpec tmp2
= module
->addWire(new_verific_id(inst
));
301 RTLIL::SigSpec tmp3
= module
->addWire(new_verific_id(inst
));
302 module
->addXorGate(new_verific_id(inst
), a
, b
, tmp1
);
303 module
->addXorGate(inst_name
, tmp1
, c
, y
);
304 module
->addAndGate(new_verific_id(inst
), tmp1
, c
, tmp2
);
305 module
->addAndGate(new_verific_id(inst
), a
, b
, tmp3
);
306 module
->addOrGate(new_verific_id(inst
), tmp2
, tmp3
, x
);
310 if (inst
->Type() == PRIM_DFFRS
)
312 VerificClocking
clocking(this, inst
->GetClock());
313 log_assert(clocking
.disable_sig
== State::S0
);
314 log_assert(clocking
.body_net
== nullptr);
316 if (inst
->GetSet()->IsGnd() && inst
->GetReset()->IsGnd())
317 clocking
.addDff(inst_name
, net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()));
318 else if (inst
->GetSet()->IsGnd())
319 clocking
.addAdff(inst_name
, net_map_at(inst
->GetReset()), net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()), State::S0
);
320 else if (inst
->GetReset()->IsGnd())
321 clocking
.addAdff(inst_name
, net_map_at(inst
->GetSet()), net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()), State::S1
);
323 clocking
.addDffsr(inst_name
, net_map_at(inst
->GetSet()), net_map_at(inst
->GetReset()),
324 net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()));
331 bool VerificImporter::import_netlist_instance_cells(Instance
*inst
, RTLIL::IdString inst_name
)
333 RTLIL::Cell
*cell
= nullptr;
335 if (inst
->Type() == PRIM_AND
) {
336 cell
= module
->addAnd(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetOutput()));
337 import_attributes(cell
->attributes
, inst
);
341 if (inst
->Type() == PRIM_NAND
) {
342 RTLIL::SigSpec tmp
= module
->addWire(new_verific_id(inst
));
343 cell
= module
->addAnd(new_verific_id(inst
), net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), tmp
);
344 import_attributes(cell
->attributes
, inst
);
345 cell
= module
->addNot(inst_name
, tmp
, net_map_at(inst
->GetOutput()));
346 import_attributes(cell
->attributes
, inst
);
350 if (inst
->Type() == PRIM_OR
) {
351 cell
= module
->addOr(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetOutput()));
352 import_attributes(cell
->attributes
, inst
);
356 if (inst
->Type() == PRIM_NOR
) {
357 RTLIL::SigSpec tmp
= module
->addWire(new_verific_id(inst
));
358 cell
= module
->addOr(new_verific_id(inst
), net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), tmp
);
359 import_attributes(cell
->attributes
, inst
);
360 cell
= module
->addNot(inst_name
, tmp
, net_map_at(inst
->GetOutput()));
361 import_attributes(cell
->attributes
, inst
);
365 if (inst
->Type() == PRIM_XOR
) {
366 cell
= module
->addXor(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetOutput()));
367 import_attributes(cell
->attributes
, inst
);
371 if (inst
->Type() == PRIM_XNOR
) {
372 cell
= module
->addXnor(inst_name
, net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), net_map_at(inst
->GetOutput()));
373 import_attributes(cell
->attributes
, inst
);
377 if (inst
->Type() == PRIM_INV
) {
378 cell
= module
->addNot(inst_name
, net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()));
379 import_attributes(cell
->attributes
, inst
);
383 if (inst
->Type() == PRIM_MUX
) {
384 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()));
385 import_attributes(cell
->attributes
, inst
);
389 if (inst
->Type() == PRIM_TRI
) {
390 cell
= module
->addMux(inst_name
, RTLIL::State::Sz
, net_map_at(inst
->GetInput()), net_map_at(inst
->GetControl()), net_map_at(inst
->GetOutput()));
391 import_attributes(cell
->attributes
, inst
);
395 if (inst
->Type() == PRIM_FADD
)
397 RTLIL::SigSpec a_plus_b
= module
->addWire(new_verific_id(inst
), 2);
398 RTLIL::SigSpec y
= inst
->GetOutput() ? net_map_at(inst
->GetOutput()) : module
->addWire(new_verific_id(inst
));
400 y
.append(net_map_at(inst
->GetCout()));
401 cell
= module
->addAdd(new_verific_id(inst
), net_map_at(inst
->GetInput1()), net_map_at(inst
->GetInput2()), a_plus_b
);
402 import_attributes(cell
->attributes
, inst
);
403 cell
= module
->addAdd(inst_name
, a_plus_b
, net_map_at(inst
->GetCin()), y
);
404 import_attributes(cell
->attributes
, inst
);
408 if (inst
->Type() == PRIM_DFFRS
)
410 VerificClocking
clocking(this, inst
->GetClock());
411 log_assert(clocking
.disable_sig
== State::S0
);
412 log_assert(clocking
.body_net
== nullptr);
414 if (inst
->GetSet()->IsGnd() && inst
->GetReset()->IsGnd())
415 cell
= clocking
.addDff(inst_name
, net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()));
416 else if (inst
->GetSet()->IsGnd())
417 cell
= clocking
.addAdff(inst_name
, net_map_at(inst
->GetReset()), net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()), RTLIL::State::S0
);
418 else if (inst
->GetReset()->IsGnd())
419 cell
= clocking
.addAdff(inst_name
, net_map_at(inst
->GetSet()), net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()), RTLIL::State::S1
);
421 cell
= clocking
.addDffsr(inst_name
, net_map_at(inst
->GetSet()), net_map_at(inst
->GetReset()),
422 net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()));
423 import_attributes(cell
->attributes
, inst
);
427 if (inst
->Type() == PRIM_DLATCHRS
)
429 if (inst
->GetSet()->IsGnd() && inst
->GetReset()->IsGnd())
430 cell
= module
->addDlatch(inst_name
, net_map_at(inst
->GetControl()), net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()));
432 cell
= module
->addDlatchsr(inst_name
, net_map_at(inst
->GetControl()), net_map_at(inst
->GetSet()), net_map_at(inst
->GetReset()),
433 net_map_at(inst
->GetInput()), net_map_at(inst
->GetOutput()));
434 import_attributes(cell
->attributes
, inst
);
438 #define IN operatorInput(inst)
439 #define IN1 operatorInput1(inst)
440 #define IN2 operatorInput2(inst)
441 #define OUT operatorOutput(inst)
442 #define FILTERED_OUT operatorOutput(inst, &any_all_nets)
443 #define SIGNED inst->View()->IsSigned()
445 if (inst
->Type() == OPER_ADDER
) {
446 RTLIL::SigSpec out
= OUT
;
447 if (inst
->GetCout() != NULL
)
448 out
.append(net_map_at(inst
->GetCout()));
449 if (inst
->GetCin()->IsGnd()) {
450 cell
= module
->addAdd(inst_name
, IN1
, IN2
, out
, SIGNED
);
451 import_attributes(cell
->attributes
, inst
);
453 RTLIL::SigSpec tmp
= module
->addWire(new_verific_id(inst
), GetSize(out
));
454 cell
= module
->addAdd(new_verific_id(inst
), IN1
, IN2
, tmp
, SIGNED
);
455 import_attributes(cell
->attributes
, inst
);
456 cell
= module
->addAdd(inst_name
, tmp
, net_map_at(inst
->GetCin()), out
, false);
457 import_attributes(cell
->attributes
, inst
);
462 if (inst
->Type() == OPER_MULTIPLIER
) {
463 cell
= module
->addMul(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
464 import_attributes(cell
->attributes
, inst
);
468 if (inst
->Type() == OPER_DIVIDER
) {
469 cell
= module
->addDiv(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
470 import_attributes(cell
->attributes
, inst
);
474 if (inst
->Type() == OPER_MODULO
) {
475 cell
= module
->addMod(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
476 import_attributes(cell
->attributes
, inst
);
480 if (inst
->Type() == OPER_REMAINDER
) {
481 cell
= module
->addMod(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
482 import_attributes(cell
->attributes
, inst
);
486 if (inst
->Type() == OPER_SHIFT_LEFT
) {
487 cell
= module
->addShl(inst_name
, IN1
, IN2
, OUT
, false);
488 import_attributes(cell
->attributes
, inst
);
492 if (inst
->Type() == OPER_ENABLED_DECODER
) {
494 vec
.append(net_map_at(inst
->GetControl()));
495 for (unsigned i
= 1; i
< inst
->OutputSize(); i
++) {
496 vec
.append(RTLIL::State::S0
);
498 cell
= module
->addShl(inst_name
, vec
, IN
, OUT
, false);
499 import_attributes(cell
->attributes
, inst
);
503 if (inst
->Type() == OPER_DECODER
) {
505 vec
.append(RTLIL::State::S1
);
506 for (unsigned i
= 1; i
< inst
->OutputSize(); i
++) {
507 vec
.append(RTLIL::State::S0
);
509 cell
= module
->addShl(inst_name
, vec
, IN
, OUT
, false);
510 import_attributes(cell
->attributes
, inst
);
514 if (inst
->Type() == OPER_SHIFT_RIGHT
) {
515 Net
*net_cin
= inst
->GetCin();
516 Net
*net_a_msb
= inst
->GetInput1Bit(0);
517 if (net_cin
->IsGnd())
518 cell
= module
->addShr(inst_name
, IN1
, IN2
, OUT
, false);
519 else if (net_cin
== net_a_msb
)
520 cell
= module
->addSshr(inst_name
, IN1
, IN2
, OUT
, true);
522 log_error("Can't import Verific OPER_SHIFT_RIGHT instance %s: carry_in is neither 0 nor msb of left input\n", inst
->Name());
523 import_attributes(cell
->attributes
, inst
);
527 if (inst
->Type() == OPER_REDUCE_AND
) {
528 cell
= module
->addReduceAnd(inst_name
, IN
, net_map_at(inst
->GetOutput()), SIGNED
);
529 import_attributes(cell
->attributes
, inst
);
533 if (inst
->Type() == OPER_REDUCE_OR
) {
534 cell
= module
->addReduceOr(inst_name
, IN
, net_map_at(inst
->GetOutput()), SIGNED
);
535 import_attributes(cell
->attributes
, inst
);
539 if (inst
->Type() == OPER_REDUCE_XOR
) {
540 cell
= module
->addReduceXor(inst_name
, IN
, net_map_at(inst
->GetOutput()), SIGNED
);
541 import_attributes(cell
->attributes
, inst
);
545 if (inst
->Type() == OPER_REDUCE_XNOR
) {
546 cell
= module
->addReduceXnor(inst_name
, IN
, net_map_at(inst
->GetOutput()), SIGNED
);
547 import_attributes(cell
->attributes
, inst
);
551 if (inst
->Type() == OPER_REDUCE_NOR
) {
552 SigSpec t
= module
->ReduceOr(new_verific_id(inst
), IN
, SIGNED
);
553 cell
= module
->addNot(inst_name
, t
, net_map_at(inst
->GetOutput()));
554 import_attributes(cell
->attributes
, inst
);
558 if (inst
->Type() == OPER_LESSTHAN
) {
559 Net
*net_cin
= inst
->GetCin();
560 if (net_cin
->IsGnd())
561 cell
= module
->addLt(inst_name
, IN1
, IN2
, net_map_at(inst
->GetOutput()), SIGNED
);
562 else if (net_cin
->IsPwr())
563 cell
= module
->addLe(inst_name
, IN1
, IN2
, net_map_at(inst
->GetOutput()), SIGNED
);
565 log_error("Can't import Verific OPER_LESSTHAN instance %s: carry_in is neither 0 nor 1\n", inst
->Name());
566 import_attributes(cell
->attributes
, inst
);
570 if (inst
->Type() == OPER_WIDE_AND
) {
571 cell
= module
->addAnd(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
572 import_attributes(cell
->attributes
, inst
);
576 if (inst
->Type() == OPER_WIDE_OR
) {
577 cell
= module
->addOr(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
578 import_attributes(cell
->attributes
, inst
);
582 if (inst
->Type() == OPER_WIDE_XOR
) {
583 cell
= module
->addXor(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
584 import_attributes(cell
->attributes
, inst
);
588 if (inst
->Type() == OPER_WIDE_XNOR
) {
589 cell
= module
->addXnor(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
590 import_attributes(cell
->attributes
, inst
);
594 if (inst
->Type() == OPER_WIDE_BUF
) {
595 cell
= module
->addPos(inst_name
, IN
, FILTERED_OUT
, SIGNED
);
596 import_attributes(cell
->attributes
, inst
);
600 if (inst
->Type() == OPER_WIDE_INV
) {
601 cell
= module
->addNot(inst_name
, IN
, OUT
, SIGNED
);
602 import_attributes(cell
->attributes
, inst
);
606 if (inst
->Type() == OPER_MINUS
) {
607 cell
= module
->addSub(inst_name
, IN1
, IN2
, OUT
, SIGNED
);
608 import_attributes(cell
->attributes
, inst
);
612 if (inst
->Type() == OPER_UMINUS
) {
613 cell
= module
->addNeg(inst_name
, IN
, OUT
, SIGNED
);
614 import_attributes(cell
->attributes
, inst
);
618 if (inst
->Type() == OPER_EQUAL
) {
619 cell
= module
->addEq(inst_name
, IN1
, IN2
, net_map_at(inst
->GetOutput()), SIGNED
);
620 import_attributes(cell
->attributes
, inst
);
624 if (inst
->Type() == OPER_NEQUAL
) {
625 cell
= module
->addNe(inst_name
, IN1
, IN2
, net_map_at(inst
->GetOutput()), SIGNED
);
626 import_attributes(cell
->attributes
, inst
);
630 if (inst
->Type() == OPER_WIDE_MUX
) {
631 cell
= module
->addMux(inst_name
, IN1
, IN2
, net_map_at(inst
->GetControl()), OUT
);
632 import_attributes(cell
->attributes
, inst
);
636 if (inst
->Type() == OPER_NTO1MUX
) {
637 cell
= module
->addShr(inst_name
, IN2
, IN1
, net_map_at(inst
->GetOutput()));
638 import_attributes(cell
->attributes
, inst
);
642 if (inst
->Type() == OPER_WIDE_NTO1MUX
)
644 SigSpec data
= IN2
, out
= OUT
;
646 int wordsize_bits
= ceil_log2(GetSize(out
));
647 int wordsize
= 1 << wordsize_bits
;
649 SigSpec sel
= {IN1
, SigSpec(State::S0
, wordsize_bits
)};
652 for (int i
= 0; i
< GetSize(data
); i
+= GetSize(out
)) {
653 SigSpec d
= data
.extract(i
, GetSize(out
));
654 d
.extend_u0(wordsize
);
655 padded_data
.append(d
);
658 cell
= module
->addShr(inst_name
, padded_data
, sel
, out
);
659 import_attributes(cell
->attributes
, inst
);
663 if (inst
->Type() == OPER_SELECTOR
)
665 cell
= module
->addPmux(inst_name
, State::S0
, IN2
, IN1
, net_map_at(inst
->GetOutput()));
666 import_attributes(cell
->attributes
, inst
);
670 if (inst
->Type() == OPER_WIDE_SELECTOR
)
673 cell
= module
->addPmux(inst_name
, SigSpec(State::S0
, GetSize(out
)), IN2
, IN1
, out
);
674 import_attributes(cell
->attributes
, inst
);
678 if (inst
->Type() == OPER_WIDE_TRI
) {
679 cell
= module
->addMux(inst_name
, RTLIL::SigSpec(RTLIL::State::Sz
, inst
->OutputSize()), IN
, net_map_at(inst
->GetControl()), OUT
);
680 import_attributes(cell
->attributes
, inst
);
684 if (inst
->Type() == OPER_WIDE_DFFRS
)
686 VerificClocking
clocking(this, inst
->GetClock());
687 log_assert(clocking
.disable_sig
== State::S0
);
688 log_assert(clocking
.body_net
== nullptr);
690 RTLIL::SigSpec sig_set
= operatorInport(inst
, "set");
691 RTLIL::SigSpec sig_reset
= operatorInport(inst
, "reset");
693 if (sig_set
.is_fully_const() && !sig_set
.as_bool() && sig_reset
.is_fully_const() && !sig_reset
.as_bool())
694 cell
= clocking
.addDff(inst_name
, IN
, OUT
);
696 cell
= clocking
.addDffsr(inst_name
, sig_set
, sig_reset
, IN
, OUT
);
697 import_attributes(cell
->attributes
, inst
);
711 void VerificImporter::merge_past_ffs_clock(pool
<RTLIL::Cell
*> &candidates
, SigBit clock
, bool clock_pol
)
713 bool keep_running
= true;
718 keep_running
= false;
720 dict
<SigBit
, pool
<RTLIL::Cell
*>> dbits_db
;
723 for (auto cell
: candidates
) {
724 SigBit bit
= sigmap(cell
->getPort("\\D"));
725 dbits_db
[bit
].insert(cell
);
729 dbits
.sort_and_unify();
731 for (auto chunk
: dbits
.chunks())
733 SigSpec sig_d
= chunk
;
735 if (chunk
.wire
== nullptr || GetSize(sig_d
) == 1)
738 SigSpec sig_q
= module
->addWire(NEW_ID
, GetSize(sig_d
));
739 RTLIL::Cell
*new_ff
= module
->addDff(NEW_ID
, clock
, sig_d
, sig_q
, clock_pol
);
742 log(" merging single-bit past_ffs into new %d-bit ff %s.\n", GetSize(sig_d
), log_id(new_ff
));
744 for (int i
= 0; i
< GetSize(sig_d
); i
++)
745 for (auto old_ff
: dbits_db
[sig_d
[i
]])
748 log(" replacing old ff %s on bit %d.\n", log_id(old_ff
), i
);
750 SigBit old_q
= old_ff
->getPort("\\Q");
751 SigBit new_q
= sig_q
[i
];
753 sigmap
.add(old_q
, new_q
);
754 module
->connect(old_q
, new_q
);
755 candidates
.erase(old_ff
);
756 module
->remove(old_ff
);
763 void VerificImporter::merge_past_ffs(pool
<RTLIL::Cell
*> &candidates
)
765 dict
<pair
<SigBit
, int>, pool
<RTLIL::Cell
*>> database
;
767 for (auto cell
: candidates
)
769 SigBit clock
= cell
->getPort("\\CLK");
770 bool clock_pol
= cell
->getParam("\\CLK_POLARITY").as_bool();
771 database
[make_pair(clock
, int(clock_pol
))].insert(cell
);
774 for (auto it
: database
)
775 merge_past_ffs_clock(it
.second
, it
.first
.first
, it
.first
.second
);
778 void VerificImporter::import_netlist(RTLIL::Design
*design
, Netlist
*nl
, std::set
<Netlist
*> &nl_todo
, bool top
)
780 std::string netlist_name
= top
? nl
->CellBaseName() : nl
->Owner()->Name();
781 std::string module_name
= nl
->IsOperator() ? "$verific$" + netlist_name
: RTLIL::escape_id(netlist_name
);
785 if (design
->has(module_name
)) {
786 if (!nl
->IsOperator() && !is_blackbox(nl
))
787 log_cmd_error("Re-definition of module `%s'.\n", netlist_name
.c_str());
791 module
= new RTLIL::Module
;
792 module
->name
= module_name
;
795 if (is_blackbox(nl
)) {
796 log("Importing blackbox module %s.\n", RTLIL::id2cstr(module
->name
));
797 module
->set_bool_attribute("\\blackbox");
799 log("Importing module %s.\n", RTLIL::id2cstr(module
->name
));
811 FOREACH_PORT_OF_NETLIST(nl
, mi
, port
)
817 log(" importing port %s.\n", port
->Name());
819 RTLIL::Wire
*wire
= module
->addWire(RTLIL::escape_id(port
->Name()));
820 import_attributes(wire
->attributes
, port
);
822 wire
->port_id
= nl
->IndexOf(port
) + 1;
824 if (port
->GetDir() == DIR_INOUT
|| port
->GetDir() == DIR_IN
)
825 wire
->port_input
= true;
826 if (port
->GetDir() == DIR_INOUT
|| port
->GetDir() == DIR_OUT
)
827 wire
->port_output
= true;
829 if (port
->GetNet()) {
830 net
= port
->GetNet();
831 if (net_map
.count(net
) == 0)
833 else if (wire
->port_input
)
834 module
->connect(net_map_at(net
), wire
);
836 module
->connect(wire
, net_map_at(net
));
840 FOREACH_PORTBUS_OF_NETLIST(nl
, mi
, portbus
)
843 log(" importing portbus %s.\n", portbus
->Name());
845 RTLIL::Wire
*wire
= module
->addWire(RTLIL::escape_id(portbus
->Name()), portbus
->Size());
846 wire
->start_offset
= min(portbus
->LeftIndex(), portbus
->RightIndex());
847 import_attributes(wire
->attributes
, portbus
);
849 if (portbus
->GetDir() == DIR_INOUT
|| portbus
->GetDir() == DIR_IN
)
850 wire
->port_input
= true;
851 if (portbus
->GetDir() == DIR_INOUT
|| portbus
->GetDir() == DIR_OUT
)
852 wire
->port_output
= true;
854 for (int i
= portbus
->LeftIndex();; i
+= portbus
->IsUp() ? +1 : -1) {
855 if (portbus
->ElementAtIndex(i
) && portbus
->ElementAtIndex(i
)->GetNet()) {
856 net
= portbus
->ElementAtIndex(i
)->GetNet();
857 RTLIL::SigBit
bit(wire
, i
- wire
->start_offset
);
858 if (net_map
.count(net
) == 0)
860 else if (wire
->port_input
)
861 module
->connect(net_map_at(net
), bit
);
863 module
->connect(bit
, net_map_at(net
));
865 if (i
== portbus
->RightIndex())
870 module
->fixup_ports();
872 dict
<Net
*, char, hash_ptr_ops
> init_nets
;
873 pool
<Net
*, hash_ptr_ops
> anyconst_nets
, anyseq_nets
;
874 pool
<Net
*, hash_ptr_ops
> allconst_nets
, allseq_nets
;
875 any_all_nets
.clear();
877 FOREACH_NET_OF_NETLIST(nl
, mi
, net
)
881 RTLIL::Memory
*memory
= new RTLIL::Memory
;
882 memory
->name
= RTLIL::escape_id(net
->Name());
883 log_assert(module
->count_id(memory
->name
) == 0);
884 module
->memories
[memory
->name
] = memory
;
886 int number_of_bits
= net
->Size();
887 int bits_in_word
= number_of_bits
;
888 FOREACH_PORTREF_OF_NET(net
, si
, pr
) {
889 if (pr
->GetInst()->Type() == OPER_READ_PORT
) {
890 bits_in_word
= min
<int>(bits_in_word
, pr
->GetInst()->OutputSize());
893 if (pr
->GetInst()->Type() == OPER_WRITE_PORT
|| pr
->GetInst()->Type() == OPER_CLOCKED_WRITE_PORT
) {
894 bits_in_word
= min
<int>(bits_in_word
, pr
->GetInst()->Input2Size());
897 log_error("Verific RamNet %s is connected to unsupported instance type %s (%s).\n",
898 net
->Name(), pr
->GetInst()->View()->Owner()->Name(), pr
->GetInst()->Name());
901 memory
->width
= bits_in_word
;
902 memory
->size
= number_of_bits
/ bits_in_word
;
904 const char *ascii_initdata
= net
->GetWideInitialValue();
905 if (ascii_initdata
) {
906 while (*ascii_initdata
!= 0 && *ascii_initdata
!= '\'')
908 if (*ascii_initdata
== '\'')
910 if (*ascii_initdata
!= 0) {
911 log_assert(*ascii_initdata
== 'b');
914 for (int word_idx
= 0; word_idx
< memory
->size
; word_idx
++) {
915 Const initval
= Const(State::Sx
, memory
->width
);
916 bool initval_valid
= false;
917 for (int bit_idx
= memory
->width
-1; bit_idx
>= 0; bit_idx
--) {
918 if (*ascii_initdata
== 0)
920 if (*ascii_initdata
== '0' || *ascii_initdata
== '1') {
921 initval
[bit_idx
] = (*ascii_initdata
== '0') ? State::S0
: State::S1
;
922 initval_valid
= true;
927 RTLIL::Cell
*cell
= module
->addCell(new_verific_id(net
), "$meminit");
928 cell
->parameters
["\\WORDS"] = 1;
929 if (net
->GetOrigTypeRange()->LeftRangeBound() < net
->GetOrigTypeRange()->RightRangeBound())
930 cell
->setPort("\\ADDR", word_idx
);
932 cell
->setPort("\\ADDR", memory
->size
- word_idx
- 1);
933 cell
->setPort("\\DATA", initval
);
934 cell
->parameters
["\\MEMID"] = RTLIL::Const(memory
->name
.str());
935 cell
->parameters
["\\ABITS"] = 32;
936 cell
->parameters
["\\WIDTH"] = memory
->width
;
937 cell
->parameters
["\\PRIORITY"] = RTLIL::Const(autoidx
-1);
944 if (net
->GetInitialValue())
945 init_nets
[net
] = net
->GetInitialValue();
947 const char *rand_const_attr
= net
->GetAttValue(" rand_const");
948 const char *rand_attr
= net
->GetAttValue(" rand");
950 const char *anyconst_attr
= net
->GetAttValue("anyconst");
951 const char *anyseq_attr
= net
->GetAttValue("anyseq");
953 const char *allconst_attr
= net
->GetAttValue("allconst");
954 const char *allseq_attr
= net
->GetAttValue("allseq");
956 if (rand_const_attr
!= nullptr && (!strcmp(rand_const_attr
, "1") || !strcmp(rand_const_attr
, "'1'"))) {
957 anyconst_nets
.insert(net
);
958 any_all_nets
.insert(net
);
960 else if (rand_attr
!= nullptr && (!strcmp(rand_attr
, "1") || !strcmp(rand_attr
, "'1'"))) {
961 anyseq_nets
.insert(net
);
962 any_all_nets
.insert(net
);
964 else if (anyconst_attr
!= nullptr && (!strcmp(anyconst_attr
, "1") || !strcmp(anyconst_attr
, "'1'"))) {
965 anyconst_nets
.insert(net
);
966 any_all_nets
.insert(net
);
968 else if (anyseq_attr
!= nullptr && (!strcmp(anyseq_attr
, "1") || !strcmp(anyseq_attr
, "'1'"))) {
969 anyseq_nets
.insert(net
);
970 any_all_nets
.insert(net
);
972 else if (allconst_attr
!= nullptr && (!strcmp(allconst_attr
, "1") || !strcmp(allconst_attr
, "'1'"))) {
973 allconst_nets
.insert(net
);
974 any_all_nets
.insert(net
);
976 else if (allseq_attr
!= nullptr && (!strcmp(allseq_attr
, "1") || !strcmp(allseq_attr
, "'1'"))) {
977 allseq_nets
.insert(net
);
978 any_all_nets
.insert(net
);
981 if (net_map
.count(net
)) {
983 log(" skipping net %s.\n", net
->Name());
990 RTLIL::IdString wire_name
= module
->uniquify(mode_names
|| net
->IsUserDeclared() ? RTLIL::escape_id(net
->Name()) : new_verific_id(net
));
993 log(" importing net %s as %s.\n", net
->Name(), log_id(wire_name
));
995 RTLIL::Wire
*wire
= module
->addWire(wire_name
);
996 import_attributes(wire
->attributes
, net
);
1001 FOREACH_NETBUS_OF_NETLIST(nl
, mi
, netbus
)
1003 bool found_new_net
= false;
1004 for (int i
= netbus
->LeftIndex();; i
+= netbus
->IsUp() ? +1 : -1) {
1005 net
= netbus
->ElementAtIndex(i
);
1006 if (net_map
.count(net
) == 0)
1007 found_new_net
= true;
1008 if (i
== netbus
->RightIndex())
1014 RTLIL::IdString wire_name
= module
->uniquify(mode_names
|| netbus
->IsUserDeclared() ? RTLIL::escape_id(netbus
->Name()) : new_verific_id(netbus
));
1016 if (verific_verbose
)
1017 log(" importing netbus %s as %s.\n", netbus
->Name(), log_id(wire_name
));
1019 RTLIL::Wire
*wire
= module
->addWire(wire_name
, netbus
->Size());
1020 wire
->start_offset
= min(netbus
->LeftIndex(), netbus
->RightIndex());
1021 import_attributes(wire
->attributes
, netbus
);
1023 RTLIL::Const initval
= Const(State::Sx
, GetSize(wire
));
1024 bool initval_valid
= false;
1026 for (int i
= netbus
->LeftIndex();; i
+= netbus
->IsUp() ? +1 : -1)
1028 if (netbus
->ElementAtIndex(i
))
1030 int bitidx
= i
- wire
->start_offset
;
1031 net
= netbus
->ElementAtIndex(i
);
1032 RTLIL::SigBit
bit(wire
, bitidx
);
1034 if (init_nets
.count(net
)) {
1035 if (init_nets
.at(net
) == '0')
1036 initval
.bits
.at(bitidx
) = State::S0
;
1037 if (init_nets
.at(net
) == '1')
1038 initval
.bits
.at(bitidx
) = State::S1
;
1039 initval_valid
= true;
1040 init_nets
.erase(net
);
1043 if (net_map
.count(net
) == 0)
1046 module
->connect(bit
, net_map_at(net
));
1049 if (i
== netbus
->RightIndex())
1054 wire
->attributes
["\\init"] = initval
;
1058 if (verific_verbose
)
1059 log(" skipping netbus %s.\n", netbus
->Name());
1062 SigSpec anyconst_sig
;
1064 SigSpec allconst_sig
;
1067 for (int i
= netbus
->RightIndex();; i
+= netbus
->IsUp() ? -1 : +1) {
1068 net
= netbus
->ElementAtIndex(i
);
1069 if (net
!= nullptr && anyconst_nets
.count(net
)) {
1070 anyconst_sig
.append(net_map_at(net
));
1071 anyconst_nets
.erase(net
);
1073 if (net
!= nullptr && anyseq_nets
.count(net
)) {
1074 anyseq_sig
.append(net_map_at(net
));
1075 anyseq_nets
.erase(net
);
1077 if (net
!= nullptr && allconst_nets
.count(net
)) {
1078 allconst_sig
.append(net_map_at(net
));
1079 allconst_nets
.erase(net
);
1081 if (net
!= nullptr && allseq_nets
.count(net
)) {
1082 allseq_sig
.append(net_map_at(net
));
1083 allseq_nets
.erase(net
);
1085 if (i
== netbus
->LeftIndex())
1089 if (GetSize(anyconst_sig
))
1090 module
->connect(anyconst_sig
, module
->Anyconst(new_verific_id(netbus
), GetSize(anyconst_sig
)));
1092 if (GetSize(anyseq_sig
))
1093 module
->connect(anyseq_sig
, module
->Anyseq(new_verific_id(netbus
), GetSize(anyseq_sig
)));
1095 if (GetSize(allconst_sig
))
1096 module
->connect(allconst_sig
, module
->Allconst(new_verific_id(netbus
), GetSize(allconst_sig
)));
1098 if (GetSize(allseq_sig
))
1099 module
->connect(allseq_sig
, module
->Allseq(new_verific_id(netbus
), GetSize(allseq_sig
)));
1102 for (auto it
: init_nets
)
1105 SigBit bit
= net_map_at(it
.first
);
1106 log_assert(bit
.wire
);
1108 if (bit
.wire
->attributes
.count("\\init"))
1109 initval
= bit
.wire
->attributes
.at("\\init");
1111 while (GetSize(initval
) < GetSize(bit
.wire
))
1112 initval
.bits
.push_back(State::Sx
);
1114 if (it
.second
== '0')
1115 initval
.bits
.at(bit
.offset
) = State::S0
;
1116 if (it
.second
== '1')
1117 initval
.bits
.at(bit
.offset
) = State::S1
;
1119 bit
.wire
->attributes
["\\init"] = initval
;
1122 for (auto net
: anyconst_nets
)
1123 module
->connect(net_map_at(net
), module
->Anyconst(new_verific_id(net
)));
1125 for (auto net
: anyseq_nets
)
1126 module
->connect(net_map_at(net
), module
->Anyseq(new_verific_id(net
)));
1128 pool
<Instance
*, hash_ptr_ops
> sva_asserts
;
1129 pool
<Instance
*, hash_ptr_ops
> sva_assumes
;
1130 pool
<Instance
*, hash_ptr_ops
> sva_covers
;
1131 pool
<Instance
*, hash_ptr_ops
> sva_triggers
;
1133 pool
<RTLIL::Cell
*> past_ffs
;
1135 FOREACH_INSTANCE_OF_NETLIST(nl
, mi
, inst
)
1137 RTLIL::IdString inst_name
= module
->uniquify(mode_names
|| inst
->IsUserDeclared() ? RTLIL::escape_id(inst
->Name()) : new_verific_id(inst
));
1139 if (verific_verbose
)
1140 log(" importing cell %s (%s) as %s.\n", inst
->Name(), inst
->View()->Owner()->Name(), log_id(inst_name
));
1143 goto import_verific_cells
;
1145 if (inst
->Type() == PRIM_PWR
) {
1146 module
->connect(net_map_at(inst
->GetOutput()), RTLIL::State::S1
);
1150 if (inst
->Type() == PRIM_GND
) {
1151 module
->connect(net_map_at(inst
->GetOutput()), RTLIL::State::S0
);
1155 if (inst
->Type() == PRIM_BUF
) {
1156 auto outnet
= inst
->GetOutput();
1157 if (!any_all_nets
.count(outnet
))
1158 module
->addBufGate(inst_name
, net_map_at(inst
->GetInput()), net_map_at(outnet
));
1162 if (inst
->Type() == PRIM_X
) {
1163 module
->connect(net_map_at(inst
->GetOutput()), RTLIL::State::Sx
);
1167 if (inst
->Type() == PRIM_Z
) {
1168 module
->connect(net_map_at(inst
->GetOutput()), RTLIL::State::Sz
);
1172 if (inst
->Type() == OPER_READ_PORT
)
1174 RTLIL::Memory
*memory
= module
->memories
.at(RTLIL::escape_id(inst
->GetInput()->Name()));
1175 int numchunks
= int(inst
->OutputSize()) / memory
->width
;
1176 int chunksbits
= ceil_log2(numchunks
);
1178 if ((numchunks
* memory
->width
) != int(inst
->OutputSize()) || (numchunks
& (numchunks
- 1)) != 0)
1179 log_error("Import of asymmetric memories of this type is not supported yet: %s %s\n", inst
->Name(), inst
->GetInput()->Name());
1181 for (int i
= 0; i
< numchunks
; i
++)
1183 RTLIL::SigSpec addr
= {operatorInput1(inst
), RTLIL::Const(i
, chunksbits
)};
1184 RTLIL::SigSpec data
= operatorOutput(inst
).extract(i
* memory
->width
, memory
->width
);
1186 RTLIL::Cell
*cell
= module
->addCell(numchunks
== 1 ? inst_name
:
1187 RTLIL::IdString(stringf("%s_%d", inst_name
.c_str(), i
)), "$memrd");
1188 cell
->parameters
["\\MEMID"] = memory
->name
.str();
1189 cell
->parameters
["\\CLK_ENABLE"] = false;
1190 cell
->parameters
["\\CLK_POLARITY"] = true;
1191 cell
->parameters
["\\TRANSPARENT"] = false;
1192 cell
->parameters
["\\ABITS"] = GetSize(addr
);
1193 cell
->parameters
["\\WIDTH"] = GetSize(data
);
1194 cell
->setPort("\\CLK", RTLIL::State::Sx
);
1195 cell
->setPort("\\EN", RTLIL::State::Sx
);
1196 cell
->setPort("\\ADDR", addr
);
1197 cell
->setPort("\\DATA", data
);
1202 if (inst
->Type() == OPER_WRITE_PORT
|| inst
->Type() == OPER_CLOCKED_WRITE_PORT
)
1204 RTLIL::Memory
*memory
= module
->memories
.at(RTLIL::escape_id(inst
->GetOutput()->Name()));
1205 int numchunks
= int(inst
->Input2Size()) / memory
->width
;
1206 int chunksbits
= ceil_log2(numchunks
);
1208 if ((numchunks
* memory
->width
) != int(inst
->Input2Size()) || (numchunks
& (numchunks
- 1)) != 0)
1209 log_error("Import of asymmetric memories of this type is not supported yet: %s %s\n", inst
->Name(), inst
->GetOutput()->Name());
1211 for (int i
= 0; i
< numchunks
; i
++)
1213 RTLIL::SigSpec addr
= {operatorInput1(inst
), RTLIL::Const(i
, chunksbits
)};
1214 RTLIL::SigSpec data
= operatorInput2(inst
).extract(i
* memory
->width
, memory
->width
);
1216 RTLIL::Cell
*cell
= module
->addCell(numchunks
== 1 ? inst_name
:
1217 RTLIL::IdString(stringf("%s_%d", inst_name
.c_str(), i
)), "$memwr");
1218 cell
->parameters
["\\MEMID"] = memory
->name
.str();
1219 cell
->parameters
["\\CLK_ENABLE"] = false;
1220 cell
->parameters
["\\CLK_POLARITY"] = true;
1221 cell
->parameters
["\\PRIORITY"] = 0;
1222 cell
->parameters
["\\ABITS"] = GetSize(addr
);
1223 cell
->parameters
["\\WIDTH"] = GetSize(data
);
1224 cell
->setPort("\\EN", RTLIL::SigSpec(net_map_at(inst
->GetControl())).repeat(GetSize(data
)));
1225 cell
->setPort("\\CLK", RTLIL::State::S0
);
1226 cell
->setPort("\\ADDR", addr
);
1227 cell
->setPort("\\DATA", data
);
1229 if (inst
->Type() == OPER_CLOCKED_WRITE_PORT
) {
1230 cell
->parameters
["\\CLK_ENABLE"] = true;
1231 cell
->setPort("\\CLK", net_map_at(inst
->GetClock()));
1238 if (import_netlist_instance_cells(inst
, inst_name
))
1240 if (inst
->IsOperator() && !verific_sva_prims
.count(inst
->Type()))
1241 log_warning("Unsupported Verific operator: %s (fallback to gate level implementation provided by verific)\n", inst
->View()->Owner()->Name());
1243 if (import_netlist_instance_gates(inst
, inst_name
))
1247 if (inst
->Type() == PRIM_SVA_ASSERT
|| inst
->Type() == PRIM_SVA_IMMEDIATE_ASSERT
)
1248 sva_asserts
.insert(inst
);
1250 if (inst
->Type() == PRIM_SVA_ASSUME
|| inst
->Type() == PRIM_SVA_IMMEDIATE_ASSUME
)
1251 sva_assumes
.insert(inst
);
1253 if (inst
->Type() == PRIM_SVA_COVER
|| inst
->Type() == PRIM_SVA_IMMEDIATE_COVER
)
1254 sva_covers
.insert(inst
);
1256 if (inst
->Type() == PRIM_SVA_TRIGGERED
)
1257 sva_triggers
.insert(inst
);
1259 if (inst
->Type() == OPER_SVA_STABLE
)
1261 VerificClocking
clocking(this, inst
->GetInput2Bit(0));
1262 log_assert(clocking
.disable_sig
== State::S0
);
1263 log_assert(clocking
.body_net
== nullptr);
1265 log_assert(inst
->Input1Size() == inst
->OutputSize());
1267 SigSpec sig_d
, sig_q
, sig_o
;
1268 sig_q
= module
->addWire(new_verific_id(inst
), inst
->Input1Size());
1270 for (int i
= int(inst
->Input1Size())-1; i
>= 0; i
--){
1271 sig_d
.append(net_map_at(inst
->GetInput1Bit(i
)));
1272 sig_o
.append(net_map_at(inst
->GetOutputBit(i
)));
1275 if (verific_verbose
) {
1276 log(" %sedge FF with D=%s, Q=%s, C=%s.\n", clocking
.posedge
? "pos" : "neg",
1277 log_signal(sig_d
), log_signal(sig_q
), log_signal(clocking
.clock_sig
));
1278 log(" XNOR with A=%s, B=%s, Y=%s.\n",
1279 log_signal(sig_d
), log_signal(sig_q
), log_signal(sig_o
));
1282 clocking
.addDff(new_verific_id(inst
), sig_d
, sig_q
);
1283 module
->addXnor(new_verific_id(inst
), sig_d
, sig_q
, sig_o
);
1289 if (inst
->Type() == PRIM_SVA_STABLE
)
1291 VerificClocking
clocking(this, inst
->GetInput2());
1292 log_assert(clocking
.disable_sig
== State::S0
);
1293 log_assert(clocking
.body_net
== nullptr);
1295 SigSpec sig_d
= net_map_at(inst
->GetInput1());
1296 SigSpec sig_o
= net_map_at(inst
->GetOutput());
1297 SigSpec sig_q
= module
->addWire(new_verific_id(inst
));
1299 if (verific_verbose
) {
1300 log(" %sedge FF with D=%s, Q=%s, C=%s.\n", clocking
.posedge
? "pos" : "neg",
1301 log_signal(sig_d
), log_signal(sig_q
), log_signal(clocking
.clock_sig
));
1302 log(" XNOR with A=%s, B=%s, Y=%s.\n",
1303 log_signal(sig_d
), log_signal(sig_q
), log_signal(sig_o
));
1306 clocking
.addDff(new_verific_id(inst
), sig_d
, sig_q
);
1307 module
->addXnor(new_verific_id(inst
), sig_d
, sig_q
, sig_o
);
1313 if (inst
->Type() == PRIM_SVA_PAST
)
1315 VerificClocking
clocking(this, inst
->GetInput2());
1316 log_assert(clocking
.disable_sig
== State::S0
);
1317 log_assert(clocking
.body_net
== nullptr);
1319 SigBit sig_d
= net_map_at(inst
->GetInput1());
1320 SigBit sig_q
= net_map_at(inst
->GetOutput());
1322 if (verific_verbose
)
1323 log(" %sedge FF with D=%s, Q=%s, C=%s.\n", clocking
.posedge
? "pos" : "neg",
1324 log_signal(sig_d
), log_signal(sig_q
), log_signal(clocking
.clock_sig
));
1326 past_ffs
.insert(clocking
.addDff(new_verific_id(inst
), sig_d
, sig_q
));
1332 if ((inst
->Type() == PRIM_SVA_ROSE
|| inst
->Type() == PRIM_SVA_FELL
))
1334 VerificClocking
clocking(this, inst
->GetInput2());
1335 log_assert(clocking
.disable_sig
== State::S0
);
1336 log_assert(clocking
.body_net
== nullptr);
1338 SigBit sig_d
= net_map_at(inst
->GetInput1());
1339 SigBit sig_o
= net_map_at(inst
->GetOutput());
1340 SigBit sig_q
= module
->addWire(new_verific_id(inst
));
1342 if (verific_verbose
)
1343 log(" %sedge FF with D=%s, Q=%s, C=%s.\n", clocking
.posedge
? "pos" : "neg",
1344 log_signal(sig_d
), log_signal(sig_q
), log_signal(clocking
.clock_sig
));
1346 clocking
.addDff(new_verific_id(inst
), sig_d
, sig_q
);
1347 module
->addEq(new_verific_id(inst
), {sig_q
, sig_d
}, Const(inst
->Type() == PRIM_SVA_ROSE
? 1 : 2, 2), sig_o
);
1353 if (!mode_keep
&& verific_sva_prims
.count(inst
->Type())) {
1354 if (verific_verbose
)
1355 log(" skipping SVA cell in non k-mode\n");
1359 if (inst
->Type() == PRIM_HDL_ASSERTION
)
1361 SigBit cond
= net_map_at(inst
->GetInput());
1363 if (verific_verbose
)
1364 log(" assert condition %s.\n", log_signal(cond
));
1366 const char *assume_attr
= nullptr; // inst->GetAttValue("assume");
1368 Cell
*cell
= nullptr;
1369 if (assume_attr
!= nullptr && !strcmp(assume_attr
, "1"))
1370 cell
= module
->addAssume(new_verific_id(inst
), cond
, State::S1
);
1372 cell
= module
->addAssert(new_verific_id(inst
), cond
, State::S1
);
1374 import_attributes(cell
->attributes
, inst
);
1378 if (inst
->IsPrimitive())
1381 log_error("Unsupported Verific primitive %s of type %s\n", inst
->Name(), inst
->View()->Owner()->Name());
1383 if (!verific_sva_prims
.count(inst
->Type()))
1384 log_warning("Unsupported Verific primitive %s of type %s\n", inst
->Name(), inst
->View()->Owner()->Name());
1387 import_verific_cells
:
1388 nl_todo
.insert(inst
->View());
1390 RTLIL::Cell
*cell
= module
->addCell(inst_name
, inst
->IsOperator() ?
1391 std::string("$verific$") + inst
->View()->Owner()->Name() : RTLIL::escape_id(inst
->View()->Owner()->Name()));
1393 if (inst
->IsPrimitive() && mode_keep
)
1394 cell
->attributes
["\\keep"] = 1;
1396 dict
<IdString
, vector
<SigBit
>> cell_port_conns
;
1398 if (verific_verbose
)
1399 log(" ports in verific db:\n");
1401 FOREACH_PORTREF_OF_INST(inst
, mi2
, pr
) {
1402 if (verific_verbose
)
1403 log(" .%s(%s)\n", pr
->GetPort()->Name(), pr
->GetNet()->Name());
1404 const char *port_name
= pr
->GetPort()->Name();
1405 int port_offset
= 0;
1406 if (pr
->GetPort()->Bus()) {
1407 port_name
= pr
->GetPort()->Bus()->Name();
1408 port_offset
= pr
->GetPort()->Bus()->IndexOf(pr
->GetPort()) -
1409 min(pr
->GetPort()->Bus()->LeftIndex(), pr
->GetPort()->Bus()->RightIndex());
1411 IdString port_name_id
= RTLIL::escape_id(port_name
);
1412 auto &sigvec
= cell_port_conns
[port_name_id
];
1413 if (GetSize(sigvec
) <= port_offset
) {
1414 SigSpec zwires
= module
->addWire(new_verific_id(inst
), port_offset
+1-GetSize(sigvec
));
1415 for (auto bit
: zwires
)
1416 sigvec
.push_back(bit
);
1418 sigvec
[port_offset
] = net_map_at(pr
->GetNet());
1421 if (verific_verbose
)
1422 log(" ports in yosys db:\n");
1424 for (auto &it
: cell_port_conns
) {
1425 if (verific_verbose
)
1426 log(" .%s(%s)\n", log_id(it
.first
), log_signal(it
.second
));
1427 cell
->setPort(it
.first
, it
.second
);
1433 for (auto inst
: sva_asserts
) {
1435 verific_import_sva_cover(this, inst
);
1436 verific_import_sva_assert(this, inst
);
1439 for (auto inst
: sva_assumes
)
1440 verific_import_sva_assume(this, inst
);
1442 for (auto inst
: sva_covers
)
1443 verific_import_sva_cover(this, inst
);
1445 for (auto inst
: sva_triggers
)
1446 verific_import_sva_trigger(this, inst
);
1448 merge_past_ffs(past_ffs
);
1452 // ==================================================================
1454 VerificClocking::VerificClocking(VerificImporter
*importer
, Net
*net
, bool sva_at_only
)
1456 module
= importer
->module
;
1458 log_assert(importer
!= nullptr);
1459 log_assert(net
!= nullptr);
1461 Instance
*inst
= net
->Driver();
1463 if (inst
!= nullptr && inst
->Type() == PRIM_SVA_AT
)
1465 net
= inst
->GetInput1();
1466 body_net
= inst
->GetInput2();
1468 inst
= net
->Driver();
1470 Instance
*body_inst
= body_net
->Driver();
1471 if (body_inst
!= nullptr && body_inst
->Type() == PRIM_SVA_DISABLE_IFF
) {
1472 disable_net
= body_inst
->GetInput1();
1473 disable_sig
= importer
->net_map_at(disable_net
);
1474 body_net
= body_inst
->GetInput2();
1483 // Use while() instead of if() to work around VIPER #13453
1484 while (inst
!= nullptr && inst
->Type() == PRIM_SVA_POSEDGE
)
1486 net
= inst
->GetInput();
1487 inst
= net
->Driver();;
1490 if (inst
!= nullptr && inst
->Type() == PRIM_INV
)
1492 net
= inst
->GetInput();
1493 inst
= net
->Driver();;
1497 // Detect clock-enable circuit
1499 if (inst
== nullptr || inst
->Type() != PRIM_AND
)
1502 Net
*net_dlatch
= inst
->GetInput1();
1503 Instance
*inst_dlatch
= net_dlatch
->Driver();
1505 if (inst_dlatch
== nullptr || inst_dlatch
->Type() != PRIM_DLATCHRS
)
1508 if (!inst_dlatch
->GetSet()->IsGnd() || !inst_dlatch
->GetReset()->IsGnd())
1511 Net
*net_enable
= inst_dlatch
->GetInput();
1512 Net
*net_not_clock
= inst_dlatch
->GetControl();
1514 if (net_enable
== nullptr || net_not_clock
== nullptr)
1517 Instance
*inst_not_clock
= net_not_clock
->Driver();
1519 if (inst_not_clock
== nullptr || inst_not_clock
->Type() != PRIM_INV
)
1522 Net
*net_clock1
= inst_not_clock
->GetInput();
1523 Net
*net_clock2
= inst
->GetInput2();
1525 if (net_clock1
== nullptr || net_clock1
!= net_clock2
)
1528 enable_net
= net_enable
;
1529 enable_sig
= importer
->net_map_at(enable_net
);
1532 inst
= net
->Driver();;
1535 // Detect condition expression
1537 if (body_net
== nullptr)
1540 Instance
*inst_mux
= body_net
->Driver();
1542 if (inst_mux
== nullptr || inst_mux
->Type() != PRIM_MUX
)
1545 if (!inst_mux
->GetInput1()->IsPwr())
1548 Net
*sva_net
= inst_mux
->GetInput2();
1549 if (!verific_is_sva_net(importer
, sva_net
))
1553 cond_net
= inst_mux
->GetControl();
1557 clock_sig
= importer
->net_map_at(clock_net
);
1559 const char *gclk_attr
= clock_net
->GetAttValue("gclk");
1560 if (gclk_attr
!= nullptr && (!strcmp(gclk_attr
, "1") || !strcmp(gclk_attr
, "'1'")))
1564 Cell
*VerificClocking::addDff(IdString name
, SigSpec sig_d
, SigSpec sig_q
, Const init_value
)
1566 log_assert(GetSize(sig_d
) == GetSize(sig_q
));
1568 if (GetSize(init_value
) != 0) {
1569 log_assert(GetSize(sig_q
) == GetSize(init_value
));
1570 if (sig_q
.is_wire()) {
1571 sig_q
.as_wire()->attributes
["\\init"] = init_value
;
1573 Wire
*w
= module
->addWire(NEW_ID
, GetSize(sig_q
));
1574 w
->attributes
["\\init"] = init_value
;
1575 module
->connect(sig_q
, w
);
1580 if (enable_sig
!= State::S1
)
1581 sig_d
= module
->Mux(NEW_ID
, sig_q
, sig_d
, enable_sig
);
1583 if (disable_sig
!= State::S0
) {
1584 log_assert(gclk
== false);
1585 log_assert(GetSize(sig_q
) == GetSize(init_value
));
1586 return module
->addAdff(name
, clock_sig
, disable_sig
, sig_d
, sig_q
, init_value
, posedge
);
1590 return module
->addFf(name
, sig_d
, sig_q
);
1592 return module
->addDff(name
, clock_sig
, sig_d
, sig_q
, posedge
);
1595 Cell
*VerificClocking::addAdff(IdString name
, RTLIL::SigSpec sig_arst
, SigSpec sig_d
, SigSpec sig_q
, Const arst_value
)
1597 log_assert(gclk
== false);
1598 log_assert(disable_sig
== State::S0
);
1600 if (enable_sig
!= State::S1
)
1601 sig_d
= module
->Mux(NEW_ID
, sig_q
, sig_d
, enable_sig
);
1603 return module
->addAdff(name
, clock_sig
, sig_arst
, sig_d
, sig_q
, arst_value
, posedge
);
1606 Cell
*VerificClocking::addDffsr(IdString name
, RTLIL::SigSpec sig_set
, RTLIL::SigSpec sig_clr
, SigSpec sig_d
, SigSpec sig_q
)
1608 log_assert(gclk
== false);
1609 log_assert(disable_sig
== State::S0
);
1611 if (enable_sig
!= State::S1
)
1612 sig_d
= module
->Mux(NEW_ID
, sig_q
, sig_d
, enable_sig
);
1614 return module
->addDffsr(name
, clock_sig
, sig_set
, sig_clr
, sig_d
, sig_q
, posedge
);
1617 // ==================================================================
1619 struct VerificExtNets
1621 int portname_cnt
= 0;
1623 // a map from Net to the same Net one level up in the design hierarchy
1624 std::map
<Net
*, Net
*> net_level_up_drive_up
;
1625 std::map
<Net
*, Net
*> net_level_up_drive_down
;
1627 Net
*route_up(Net
*net
, bool drive_up
, Net
*final_net
= nullptr)
1629 auto &net_level_up
= drive_up
? net_level_up_drive_up
: net_level_up_drive_down
;
1631 if (net_level_up
.count(net
) == 0)
1633 Netlist
*nl
= net
->Owner();
1635 // Simply return if Netlist is not unique
1636 log_assert(nl
->NumOfRefs() == 1);
1638 Instance
*up_inst
= (Instance
*)nl
->GetReferences()->GetLast();
1639 Netlist
*up_nl
= up_inst
->Owner();
1642 string name
= stringf("___extnets_%d", portname_cnt
++);
1643 Port
*new_port
= new Port(name
.c_str(), drive_up
? DIR_OUT
: DIR_IN
);
1645 net
->Connect(new_port
);
1647 // create new Net in up Netlist
1648 Net
*new_net
= final_net
;
1649 if (new_net
== nullptr || new_net
->Owner() != up_nl
) {
1650 new_net
= new Net(name
.c_str());
1651 up_nl
->Add(new_net
);
1653 up_inst
->Connect(new_port
, new_net
);
1655 net_level_up
[net
] = new_net
;
1658 return net_level_up
.at(net
);
1661 Net
*route_up(Net
*net
, bool drive_up
, Netlist
*dest
, Net
*final_net
= nullptr)
1663 while (net
->Owner() != dest
)
1664 net
= route_up(net
, drive_up
, final_net
);
1665 if (final_net
!= nullptr)
1666 log_assert(net
== final_net
);
1670 Netlist
*find_common_ancestor(Netlist
*A
, Netlist
*B
)
1672 std::set
<Netlist
*> ancestors_of_A
;
1674 Netlist
*cursor
= A
;
1676 ancestors_of_A
.insert(cursor
);
1677 if (cursor
->NumOfRefs() != 1)
1679 cursor
= ((Instance
*)cursor
->GetReferences()->GetLast())->Owner();
1684 if (ancestors_of_A
.count(cursor
))
1686 if (cursor
->NumOfRefs() != 1)
1688 cursor
= ((Instance
*)cursor
->GetReferences()->GetLast())->Owner();
1691 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());
1694 void run(Netlist
*nl
)
1700 vector
<tuple
<Instance
*, Port
*, Net
*>> todo_connect
;
1702 FOREACH_INSTANCE_OF_NETLIST(nl
, mi
, inst
)
1705 FOREACH_INSTANCE_OF_NETLIST(nl
, mi
, inst
)
1706 FOREACH_PORTREF_OF_INST(inst
, mi2
, pr
)
1708 Port
*port
= pr
->GetPort();
1709 Net
*net
= pr
->GetNet();
1711 if (!net
->IsExternalTo(nl
))
1714 if (verific_verbose
)
1715 log("Fixing external net reference on port %s.%s.%s:\n", get_full_netlist_name(nl
).c_str(), inst
->Name(), port
->Name());
1717 Netlist
*ext_nl
= net
->Owner();
1719 if (verific_verbose
)
1720 log(" external net owner: %s\n", get_full_netlist_name(ext_nl
).c_str());
1722 Netlist
*ca_nl
= find_common_ancestor(nl
, ext_nl
);
1724 if (verific_verbose
)
1725 log(" common ancestor: %s\n", get_full_netlist_name(ca_nl
).c_str());
1727 Net
*ca_net
= route_up(net
, !port
->IsOutput(), ca_nl
);
1728 Net
*new_net
= ca_net
;
1732 if (verific_verbose
)
1733 log(" net in common ancestor: %s\n", ca_net
->Name());
1735 string name
= stringf("___extnets_%d", portname_cnt
++);
1736 new_net
= new Net(name
.c_str());
1739 Net
*n
= route_up(new_net
, port
->IsOutput(), ca_nl
, ca_net
);
1740 log_assert(n
== ca_net
);
1743 if (verific_verbose
)
1744 log(" new local net: %s\n", new_net
->Name());
1746 log_assert(!new_net
->IsExternalTo(nl
));
1747 todo_connect
.push_back(tuple
<Instance
*, Port
*, Net
*>(inst
, port
, new_net
));
1750 for (auto it
: todo_connect
) {
1751 get
<0>(it
)->Disconnect(get
<1>(it
));
1752 get
<0>(it
)->Connect(get
<1>(it
), get
<2>(it
));
1757 void verific_import(Design
*design
, const std::map
<std::string
,std::string
> ¶meters
, std::string top
)
1759 verific_sva_fsm_limit
= 16;
1761 std::set
<Netlist
*> nl_todo
, nl_done
;
1763 VhdlLibrary
*vhdl_lib
= vhdl_file::GetLibrary("work", 1);
1764 VeriLibrary
*veri_lib
= veri_file::GetLibrary("work", 1);
1765 Array
*netlists
= NULL
;
1766 Array veri_libs
, vhdl_libs
;
1767 if (vhdl_lib
) vhdl_libs
.InsertLast(vhdl_lib
);
1768 if (veri_lib
) veri_libs
.InsertLast(veri_lib
);
1770 Map
verific_params(STRING_HASH
);
1771 for (auto i
: parameters
)
1772 verific_params
.Insert(i
.first
.c_str(), i
.second
.c_str());
1775 netlists
= hier_tree::ElaborateAll(&veri_libs
, &vhdl_libs
, &verific_params
);
1778 const Map
*tree_tops
= hier_tree::CreateHierarchicalTreeAll(&veri_libs
, &vhdl_libs
, &verific_params
);
1779 HierTreeNode
*node
= tree_tops
? static_cast<HierTreeNode
*>(tree_tops
->GetValue(top
.c_str())) : NULL
;
1781 Map
specific_tops(STRING_HASH
);
1782 specific_tops
.Insert(top
.c_str(), node
);
1784 if (node
->HasBindChild()) {
1787 FOREACH_MAP_ITEM(tree_tops
, mi
, &key
, &node
) {
1788 if (!node
->IsPackage()) continue;
1789 specific_tops
.Insert(key
, node
);
1793 netlists
= hier_tree::GenerateNetlists(&specific_tops
);
1795 hier_tree::DeleteHierarchicalTree();
1796 veri_file::DeleteInstantiatedClassValues();
1802 FOREACH_ARRAY_ITEM(netlists
, i
, nl
) {
1803 if (top
.empty() || nl
->CellBaseName() == top
)
1809 if (!verific_error_msg
.empty())
1810 log_error("%s\n", verific_error_msg
.c_str());
1812 VerificExtNets worker
;
1813 for (auto nl
: nl_todo
)
1816 while (!nl_todo
.empty()) {
1817 Netlist
*nl
= *nl_todo
.begin();
1818 if (nl_done
.count(nl
) == 0) {
1819 VerificImporter
importer(false, false, false, false, false, false);
1820 importer
.import_netlist(design
, nl
, nl_todo
, nl
->CellBaseName() == top
);
1829 verific_incdirs
.clear();
1830 verific_libdirs
.clear();
1831 verific_import_pending
= false;
1833 if (!verific_error_msg
.empty())
1834 log_error("%s\n", verific_error_msg
.c_str());
1838 #endif /* YOSYS_ENABLE_VERIFIC */
1840 PRIVATE_NAMESPACE_BEGIN
1842 #ifdef YOSYS_ENABLE_VERIFIC
1843 bool check_noverific_env()
1845 const char *e
= getenv("YOSYS_NOVERIFIC");
1854 struct VerificPass
: public Pass
{
1855 VerificPass() : Pass("verific", "load Verilog and VHDL designs using Verific") { }
1856 void help() YS_OVERRIDE
1858 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
1860 log(" verific {-vlog95|-vlog2k|-sv2005|-sv2009|-sv2012|-sv} <verilog-file>..\n");
1862 log("Load the specified Verilog/SystemVerilog files into Verific.\n");
1864 log("All files specified in one call to this command are one compilation unit.\n");
1865 log("Files passed to different calls to this command are treated as belonging to\n");
1866 log("different compilation units.\n");
1868 log("Additional -D<macro>[=<value>] options may be added after the option indicating\n");
1869 log("the language version (and before file names) to set additional verilog defines.\n");
1870 log("The macros SYNTHESIS and VERIFIC are defined implicitly.\n");
1873 log(" verific -formal <verilog-file>..\n");
1875 log("Like -sv, but define FORMAL instead of SYNTHESIS.\n");
1878 log(" verific {-vhdl87|-vhdl93|-vhdl2k|-vhdl2008|-vhdl} <vhdl-file>..\n");
1880 log("Load the specified VHDL files into Verific.\n");
1883 log(" verific -work <libname> {-sv|-vhdl|...} <hdl-file>\n");
1885 log("Load the specified Verilog/SystemVerilog/VHDL file into the specified library.\n");
1886 log("(default library when -work is not present: \"work\")\n");
1889 log(" verific -vlog-incdir <directory>..\n");
1891 log("Add Verilog include directories.\n");
1894 log(" verific -vlog-libdir <directory>..\n");
1896 log("Add Verilog library directories. Verific will search in this directories to\n");
1897 log("find undefined modules.\n");
1900 log(" verific -vlog-define <macro>[=<value>]..\n");
1902 log("Add Verilog defines.\n");
1905 log(" verific -vlog-undef <macro>..\n");
1907 log("Remove Verilog defines previously set with -vlog-define.\n");
1910 log(" verific -set-error <msg_id>..\n");
1911 log(" verific -set-warning <msg_id>..\n");
1912 log(" verific -set-info <msg_id>..\n");
1913 log(" verific -set-ignore <msg_id>..\n");
1915 log("Set message severity. <msg_id> is the string in square brackets when a message\n");
1916 log("is printed, such as VERI-1209.\n");
1919 log(" verific -import [options] <top-module>..\n");
1921 log("Elaborate the design for the specified top modules, import to Yosys and\n");
1922 log("reset the internal state of Verific.\n");
1924 log("Import options:\n");
1927 log(" Elaborate all modules, not just the hierarchy below the given top\n");
1928 log(" modules. With this option the list of modules to import is optional.\n");
1931 log(" Create a gate-level netlist.\n");
1934 log(" Flatten the design in Verific before importing.\n");
1937 log(" Resolve references to external nets by adding module ports as needed.\n");
1939 log(" -autocover\n");
1940 log(" Generate automatic cover statements for all asserts\n");
1942 log(" -chparam name value \n");
1943 log(" Elaborate the specified top modules (all modules when -all given) using\n");
1944 log(" this parameter value. Modules on which this parameter does not exist will\n");
1945 log(" cause Verific to produce a VERI-1928 or VHDL-1676 message. This option\n");
1946 log(" can be specified multiple times to override multiple parameters.\n");
1947 log(" String values must be passed in double quotes (\").\n");
1950 log(" Verbose log messages. (-vv is even more verbose than -v.)\n");
1952 log("The following additional import options are useful for debugging the Verific\n");
1953 log("bindings (for Yosys and/or Verific developers):\n");
1956 log(" Keep going after an unsupported verific primitive is found. The\n");
1957 log(" unsupported primitive is added as blockbox module to the design.\n");
1958 log(" This will also add all SVA related cells to the design parallel to\n");
1959 log(" the checker logic inferred by it.\n");
1962 log(" Import Verific netlist as-is without translating to Yosys cell types. \n");
1965 log(" Ignore SVA properties, do not infer checker logic.\n");
1968 log(" Maximum number of ctrl bits for SVA checker FSMs (default=16).\n");
1971 log(" Keep all Verific names on instances and nets. By default only\n");
1972 log(" user-declared names are preserved.\n");
1974 log(" -d <dump_file>\n");
1975 log(" Dump the Verific netlist as a verilog file.\n");
1977 log("Visit http://verific.com/ for more information on Verific.\n");
1980 #ifdef YOSYS_ENABLE_VERIFIC
1981 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) YS_OVERRIDE
1983 static bool set_verific_global_flags
= true;
1985 if (check_noverific_env())
1986 log_cmd_error("This version of Yosys is built without Verific support.\n");
1988 log_header(design
, "Executing VERIFIC (loading SystemVerilog and VHDL designs using Verific).\n");
1990 if (set_verific_global_flags
)
1992 Message::SetConsoleOutput(0);
1993 Message::RegisterCallBackMsg(msg_func
);
1995 RuntimeFlags::SetVar("db_preserve_user_nets", 1);
1996 RuntimeFlags::SetVar("db_allow_external_nets", 1);
1997 RuntimeFlags::SetVar("db_infer_wide_operators", 1);
1999 RuntimeFlags::SetVar("veri_extract_dualport_rams", 0);
2000 RuntimeFlags::SetVar("veri_extract_multiport_rams", 1);
2002 RuntimeFlags::SetVar("vhdl_extract_dualport_rams", 0);
2003 RuntimeFlags::SetVar("vhdl_extract_multiport_rams", 1);
2005 RuntimeFlags::SetVar("vhdl_support_variable_slice", 1);
2006 RuntimeFlags::SetVar("vhdl_ignore_assertion_statements", 0);
2008 // Workaround for VIPER #13851
2009 RuntimeFlags::SetVar("veri_create_name_for_unnamed_gen_block", 1);
2011 // WARNING: instantiating unknown module 'XYZ' (VERI-1063)
2012 Message::SetMessageType("VERI-1063", VERIFIC_ERROR
);
2014 #ifndef DB_PRESERVE_INITIAL_VALUE
2015 # warning Verific was built without DB_PRESERVE_INITIAL_VALUE.
2018 set_verific_global_flags
= false;
2021 verific_verbose
= 0;
2022 verific_sva_fsm_limit
= 16;
2024 const char *release_str
= Message::ReleaseString();
2025 time_t release_time
= Message::ReleaseDate();
2026 char *release_tmstr
= ctime(&release_time
);
2028 if (release_str
== nullptr)
2029 release_str
= "(no release string)";
2031 for (char *p
= release_tmstr
; *p
; p
++)
2032 if (*p
== '\n') *p
= 0;
2034 log("Built with Verific %s, released at %s.\n", release_str
, release_tmstr
);
2037 std::string work
= "work";
2039 if (GetSize(args
) > argidx
&& (args
[argidx
] == "-set-error" || args
[argidx
] == "-set-warning" ||
2040 args
[argidx
] == "-set-info" || args
[argidx
] == "-set-ignore"))
2042 msg_type_t new_type
;
2044 if (args
[argidx
] == "-set-error")
2045 new_type
= VERIFIC_ERROR
;
2046 else if (args
[argidx
] == "-set-warning")
2047 new_type
= VERIFIC_WARNING
;
2048 else if (args
[argidx
] == "-set-info")
2049 new_type
= VERIFIC_INFO
;
2050 else if (args
[argidx
] == "-set-ignore")
2051 new_type
= VERIFIC_IGNORE
;
2055 for (argidx
++; argidx
< GetSize(args
); argidx
++)
2056 Message::SetMessageType(args
[argidx
].c_str(), new_type
);
2061 if (GetSize(args
) > argidx
&& args
[argidx
] == "-vlog-incdir") {
2062 for (argidx
++; argidx
< GetSize(args
); argidx
++)
2063 verific_incdirs
.push_back(args
[argidx
]);
2067 if (GetSize(args
) > argidx
&& args
[argidx
] == "-vlog-libdir") {
2068 for (argidx
++; argidx
< GetSize(args
); argidx
++)
2069 verific_libdirs
.push_back(args
[argidx
]);
2073 if (GetSize(args
) > argidx
&& args
[argidx
] == "-vlog-define") {
2074 for (argidx
++; argidx
< GetSize(args
); argidx
++) {
2075 string name
= args
[argidx
];
2076 size_t equal
= name
.find('=');
2077 if (equal
!= std::string::npos
) {
2078 string value
= name
.substr(equal
+1);
2079 name
= name
.substr(0, equal
);
2080 veri_file::DefineCmdLineMacro(name
.c_str(), value
.c_str());
2082 veri_file::DefineCmdLineMacro(name
.c_str());
2088 if (GetSize(args
) > argidx
&& args
[argidx
] == "-vlog-undef") {
2089 for (argidx
++; argidx
< GetSize(args
); argidx
++) {
2090 string name
= args
[argidx
];
2091 veri_file::UndefineMacro(name
.c_str());
2096 for (; argidx
< GetSize(args
); argidx
++)
2098 if (args
[argidx
] == "-work" && argidx
+1 < GetSize(args
)) {
2099 work
= args
[++argidx
];
2105 if (GetSize(args
) > argidx
&& (args
[argidx
] == "-vlog95" || args
[argidx
] == "-vlog2k" || args
[argidx
] == "-sv2005" ||
2106 args
[argidx
] == "-sv2009" || args
[argidx
] == "-sv2012" || args
[argidx
] == "-sv" || args
[argidx
] == "-formal"))
2109 unsigned verilog_mode
;
2111 if (args
[argidx
] == "-vlog95")
2112 verilog_mode
= veri_file::VERILOG_95
;
2113 else if (args
[argidx
] == "-vlog2k")
2114 verilog_mode
= veri_file::VERILOG_2K
;
2115 else if (args
[argidx
] == "-sv2005")
2116 verilog_mode
= veri_file::SYSTEM_VERILOG_2005
;
2117 else if (args
[argidx
] == "-sv2009")
2118 verilog_mode
= veri_file::SYSTEM_VERILOG_2009
;
2119 else if (args
[argidx
] == "-sv2012" || args
[argidx
] == "-sv" || args
[argidx
] == "-formal")
2120 verilog_mode
= veri_file::SYSTEM_VERILOG
;
2124 veri_file::DefineMacro("VERIFIC");
2125 veri_file::DefineMacro(args
[argidx
] == "-formal" ? "FORMAL" : "SYNTHESIS");
2127 for (argidx
++; argidx
< GetSize(args
) && GetSize(args
[argidx
]) >= 2 && args
[argidx
].substr(0, 2) == "-D"; argidx
++) {
2128 std::string name
= args
[argidx
].substr(2);
2129 if (args
[argidx
] == "-D") {
2130 if (++argidx
>= GetSize(args
))
2132 name
= args
[argidx
];
2134 size_t equal
= name
.find('=');
2135 if (equal
!= std::string::npos
) {
2136 string value
= name
.substr(equal
+1);
2137 name
= name
.substr(0, equal
);
2138 veri_file::DefineMacro(name
.c_str(), value
.c_str());
2140 veri_file::DefineMacro(name
.c_str());
2144 for (auto &dir
: verific_incdirs
)
2145 veri_file::AddIncludeDir(dir
.c_str());
2146 for (auto &dir
: verific_libdirs
)
2147 veri_file::AddYDir(dir
.c_str());
2149 while (argidx
< GetSize(args
))
2150 file_names
.Insert(args
[argidx
++].c_str());
2152 if (!veri_file::AnalyzeMultipleFiles(&file_names
, verilog_mode
, work
.c_str(), veri_file::MFCU
))
2153 log_cmd_error("Reading Verilog/SystemVerilog sources failed.\n");
2155 verific_import_pending
= true;
2159 if (GetSize(args
) > argidx
&& args
[argidx
] == "-vhdl87") {
2160 vhdl_file::SetDefaultLibraryPath((proc_share_dirname() + "verific/vhdl_vdbs_1987").c_str());
2161 for (argidx
++; argidx
< GetSize(args
); argidx
++)
2162 if (!vhdl_file::Analyze(args
[argidx
].c_str(), work
.c_str(), vhdl_file::VHDL_87
))
2163 log_cmd_error("Reading `%s' in VHDL_87 mode failed.\n", args
[argidx
].c_str());
2164 verific_import_pending
= true;
2168 if (GetSize(args
) > argidx
&& args
[argidx
] == "-vhdl93") {
2169 vhdl_file::SetDefaultLibraryPath((proc_share_dirname() + "verific/vhdl_vdbs_1993").c_str());
2170 for (argidx
++; argidx
< GetSize(args
); argidx
++)
2171 if (!vhdl_file::Analyze(args
[argidx
].c_str(), work
.c_str(), vhdl_file::VHDL_93
))
2172 log_cmd_error("Reading `%s' in VHDL_93 mode failed.\n", args
[argidx
].c_str());
2173 verific_import_pending
= true;
2177 if (GetSize(args
) > argidx
&& args
[argidx
] == "-vhdl2k") {
2178 vhdl_file::SetDefaultLibraryPath((proc_share_dirname() + "verific/vhdl_vdbs_1993").c_str());
2179 for (argidx
++; argidx
< GetSize(args
); argidx
++)
2180 if (!vhdl_file::Analyze(args
[argidx
].c_str(), work
.c_str(), vhdl_file::VHDL_2K
))
2181 log_cmd_error("Reading `%s' in VHDL_2K mode failed.\n", args
[argidx
].c_str());
2182 verific_import_pending
= true;
2186 if (GetSize(args
) > argidx
&& (args
[argidx
] == "-vhdl2008" || args
[argidx
] == "-vhdl")) {
2187 vhdl_file::SetDefaultLibraryPath((proc_share_dirname() + "verific/vhdl_vdbs_2008").c_str());
2188 for (argidx
++; argidx
< GetSize(args
); argidx
++)
2189 if (!vhdl_file::Analyze(args
[argidx
].c_str(), work
.c_str(), vhdl_file::VHDL_2008
))
2190 log_cmd_error("Reading `%s' in VHDL_2008 mode failed.\n", args
[argidx
].c_str());
2191 verific_import_pending
= true;
2195 if (GetSize(args
) > argidx
&& args
[argidx
] == "-import")
2197 std::set
<Netlist
*> nl_todo
, nl_done
;
2198 bool mode_all
= false, mode_gates
= false, mode_keep
= false;
2199 bool mode_nosva
= false, mode_names
= false, mode_verific
= false;
2200 bool mode_autocover
= false;
2201 bool flatten
= false, extnets
= false;
2203 Map
parameters(STRING_HASH
);
2205 for (argidx
++; argidx
< GetSize(args
); argidx
++) {
2206 if (args
[argidx
] == "-all") {
2210 if (args
[argidx
] == "-gates") {
2214 if (args
[argidx
] == "-flatten") {
2218 if (args
[argidx
] == "-extnets") {
2222 if (args
[argidx
] == "-k") {
2226 if (args
[argidx
] == "-nosva") {
2230 if (args
[argidx
] == "-L" && argidx
+1 < GetSize(args
)) {
2231 verific_sva_fsm_limit
= atoi(args
[++argidx
].c_str());
2234 if (args
[argidx
] == "-n") {
2238 if (args
[argidx
] == "-autocover") {
2239 mode_autocover
= true;
2242 if (args
[argidx
] == "-chparam" && argidx
+2 < GetSize(args
)) {
2243 const std::string
&key
= args
[++argidx
];
2244 const std::string
&value
= args
[++argidx
];
2245 unsigned new_insertion
= parameters
.Insert(key
.c_str(), value
.c_str(),
2246 1 /* force_overwrite */);
2248 log_warning_noprefix("-chparam %s already specified: overwriting.\n", key
.c_str());
2251 if (args
[argidx
] == "-V") {
2252 mode_verific
= true;
2255 if (args
[argidx
] == "-v") {
2256 verific_verbose
= 1;
2259 if (args
[argidx
] == "-vv") {
2260 verific_verbose
= 2;
2263 if (args
[argidx
] == "-d" && argidx
+1 < GetSize(args
)) {
2264 dumpfile
= args
[++argidx
];
2270 if (argidx
> GetSize(args
) && args
[argidx
].substr(0, 1) == "-")
2271 cmd_error(args
, argidx
, "unknown option");
2275 log("Running hier_tree::ElaborateAll().\n");
2277 VhdlLibrary
*vhdl_lib
= vhdl_file::GetLibrary(work
.c_str(), 1);
2278 VeriLibrary
*veri_lib
= veri_file::GetLibrary(work
.c_str(), 1);
2280 Array veri_libs
, vhdl_libs
;
2281 if (vhdl_lib
) vhdl_libs
.InsertLast(vhdl_lib
);
2282 if (veri_lib
) veri_libs
.InsertLast(veri_lib
);
2284 Array
*netlists
= hier_tree::ElaborateAll(&veri_libs
, &vhdl_libs
, ¶meters
);
2288 FOREACH_ARRAY_ITEM(netlists
, i
, nl
)
2294 if (argidx
== GetSize(args
))
2295 log_cmd_error("No top module specified.\n");
2297 Array veri_modules
, vhdl_units
;
2298 for (; argidx
< GetSize(args
); argidx
++)
2300 const char *name
= args
[argidx
].c_str();
2302 VeriModule
*veri_module
= veri_file::GetModule(name
);
2304 log("Adding Verilog module '%s' to elaboration queue.\n", name
);
2305 veri_modules
.InsertLast(veri_module
);
2309 VhdlLibrary
*vhdl_lib
= vhdl_file::GetLibrary(work
.c_str(), 1);
2310 VhdlDesignUnit
*vhdl_unit
= vhdl_lib
->GetPrimUnit(name
);
2312 log("Adding VHDL unit '%s' to elaboration queue.\n", name
);
2313 vhdl_units
.InsertLast(vhdl_unit
);
2317 log_error("Can't find module/unit '%s'.\n", name
);
2320 log("Running hier_tree::Elaborate().\n");
2321 Array
*netlists
= hier_tree::Elaborate(&veri_modules
, &vhdl_units
, ¶meters
);
2325 FOREACH_ARRAY_ITEM(netlists
, i
, nl
)
2330 if (!verific_error_msg
.empty())
2334 for (auto nl
: nl_todo
)
2339 VerificExtNets worker
;
2340 for (auto nl
: nl_todo
)
2344 if (!dumpfile
.empty()) {
2345 VeriWrite veri_writer
;
2346 veri_writer
.WriteFile(dumpfile
.c_str(), Netlist::PresentDesign());
2349 while (!nl_todo
.empty()) {
2350 Netlist
*nl
= *nl_todo
.begin();
2351 if (nl_done
.count(nl
) == 0) {
2352 VerificImporter
importer(mode_gates
, mode_keep
, mode_nosva
,
2353 mode_names
, mode_verific
, mode_autocover
);
2354 importer
.import_netlist(design
, nl
, nl_todo
);
2363 verific_incdirs
.clear();
2364 verific_libdirs
.clear();
2365 verific_import_pending
= false;
2369 log_cmd_error("Missing or unsupported mode parameter.\n");
2372 if (!verific_error_msg
.empty())
2373 log_error("%s\n", verific_error_msg
.c_str());
2376 #else /* YOSYS_ENABLE_VERIFIC */
2377 void execute(std::vector
<std::string
>, RTLIL::Design
*) YS_OVERRIDE
{
2378 log_cmd_error("This version of Yosys is built without Verific support.\n");
2383 struct ReadPass
: public Pass
{
2384 ReadPass() : Pass("read", "load HDL designs") { }
2385 void help() YS_OVERRIDE
2387 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
2389 log(" read {-vlog95|-vlog2k|-sv2005|-sv2009|-sv2012|-sv|-formal} <verilog-file>..\n");
2391 log("Load the specified Verilog/SystemVerilog files. (Full SystemVerilog support\n");
2392 log("is only available via Verific.)\n");
2394 log("Additional -D<macro>[=<value>] options may be added after the option indicating\n");
2395 log("the language version (and before file names) to set additional verilog defines.\n");
2398 log(" read {-vhdl87|-vhdl93|-vhdl2k|-vhdl2008|-vhdl} <vhdl-file>..\n");
2400 log("Load the specified VHDL files. (Requires Verific.)\n");
2403 log(" read -define <macro>[=<value>]..\n");
2405 log("Set global Verilog/SystemVerilog defines.\n");
2408 log(" read -undef <macro>..\n");
2410 log("Unset global Verilog/SystemVerilog defines.\n");
2413 log(" read -incdir <directory>\n");
2415 log("Add directory to global Verilog/SystemVerilog include directories.\n");
2418 log(" read -verific\n");
2419 log(" read -noverific\n");
2421 log("Subsequent calls to 'read' will either use or not use Verific. Calling 'read'\n");
2422 log("with -verific will result in an error on Yosys binaries that are built without\n");
2423 log("Verific support. The default is to use Verific if it is available.\n");
2426 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) YS_OVERRIDE
2428 #ifdef YOSYS_ENABLE_VERIFIC
2429 static bool verific_available
= !check_noverific_env();
2431 static bool verific_available
= false;
2433 static bool use_verific
= verific_available
;
2435 if (args
.size() < 2 || args
[1][0] != '-')
2436 log_cmd_error("Missing mode parameter.\n");
2438 if (args
[1] == "-verific" || args
[1] == "-noverific") {
2439 if (args
.size() != 2)
2440 log_cmd_error("Additional arguments to -verific/-noverific.\n");
2441 if (args
[1] == "-verific") {
2442 if (!verific_available
)
2443 log_cmd_error("This version of Yosys is built without Verific support.\n");
2446 use_verific
= false;
2451 if (args
.size() < 3)
2452 log_cmd_error("Missing file name parameter.\n");
2454 if (args
[1] == "-vlog95" || args
[1] == "-vlog2k") {
2456 args
[0] = "verific";
2458 args
[0] = "read_verilog";
2459 args
.erase(args
.begin()+1, args
.begin()+2);
2461 Pass::call(design
, args
);
2465 if (args
[1] == "-sv2005" || args
[1] == "-sv2009" || args
[1] == "-sv2012" || args
[1] == "-sv" || args
[1] == "-formal") {
2467 args
[0] = "verific";
2469 args
[0] = "read_verilog";
2470 if (args
[1] == "-formal")
2471 args
.insert(args
.begin()+1, std::string());
2474 Pass::call(design
, args
);
2478 if (args
[1] == "-vhdl87" || args
[1] == "-vhdl93" || args
[1] == "-vhdl2k" || args
[1] == "-vhdl2008" || args
[1] == "-vhdl") {
2480 args
[0] = "verific";
2481 Pass::call(design
, args
);
2483 log_cmd_error("This version of Yosys is built without Verific support.\n");
2488 if (args
[1] == "-define") {
2490 args
[0] = "verific";
2491 args
[1] = "-vlog-define";
2492 Pass::call(design
, args
);
2494 args
[0] = "verilog_defines";
2495 args
.erase(args
.begin()+1, args
.begin()+2);
2496 for (int i
= 1; i
< GetSize(args
); i
++)
2497 args
[i
] = "-D" + args
[i
];
2498 Pass::call(design
, args
);
2502 if (args
[1] == "-undef") {
2504 args
[0] = "verific";
2505 args
[1] = "-vlog-undef";
2506 Pass::call(design
, args
);
2508 args
[0] = "verilog_defines";
2509 args
.erase(args
.begin()+1, args
.begin()+2);
2510 for (int i
= 1; i
< GetSize(args
); i
++)
2511 args
[i
] = "-U" + args
[i
];
2512 Pass::call(design
, args
);
2516 if (args
[1] == "-incdir") {
2518 args
[0] = "verific";
2519 args
[1] = "-vlog-incdir";
2520 Pass::call(design
, args
);
2522 args
[0] = "verilog_defaults";
2524 for (int i
= 2; i
< GetSize(args
); i
++)
2525 args
[i
] = "-I" + args
[i
];
2526 Pass::call(design
, args
);
2530 log_cmd_error("Missing or unsupported mode parameter.\n");
2534 PRIVATE_NAMESPACE_END