yosys/frontends/verific/verific.h

114 lines
4.5 KiB
C
Raw Normal View History

/*
* yosys -- Yosys Open SYnthesis Suite
*
* Copyright (C) 2012 Claire Xenia Wolf <claire@yosyshq.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
#ifdef YOSYS_ENABLE_VERIFIC
#include "DataBase.h"
YOSYS_NAMESPACE_BEGIN
extern int verific_verbose;
extern bool verific_import_pending;
extern std::string verific_import(Design *design, const std::map<std::string,std::string> &parameters, std::string top = std::string());
extern pool<int> verific_sva_prims;
struct VerificImporter;
struct VerificClocking {
RTLIL::Module *module = nullptr;
Verific::Net *clock_net = nullptr;
Verific::Net *enable_net = nullptr;
Verific::Net *disable_net = nullptr;
Verific::Net *body_net = nullptr;
Verific::Net *cond_net = nullptr;
SigBit clock_sig = State::Sx;
SigBit enable_sig = State::S1;
SigBit disable_sig = State::S0;
bool posedge = true;
bool gclk = false;
bool cond_pol = true;
VerificClocking() { }
VerificClocking(VerificImporter *importer, Verific::Net *net, bool sva_at_only = false);
RTLIL::Cell *addDff(IdString name, SigSpec sig_d, SigSpec sig_q, Const init_value = Const());
RTLIL::Cell *addAdff(IdString name, RTLIL::SigSpec sig_arst, SigSpec sig_d, SigSpec sig_q, Const arst_value);
RTLIL::Cell *addDffsr(IdString name, RTLIL::SigSpec sig_set, RTLIL::SigSpec sig_clr, SigSpec sig_d, SigSpec sig_q);
RTLIL::Cell *addAldff(IdString name, RTLIL::SigSpec sig_aload, RTLIL::SigSpec sig_adata, SigSpec sig_d, SigSpec sig_q);
bool property_matches_sequence(const VerificClocking &seq) const {
if (clock_net != seq.clock_net)
return false;
if (enable_net != seq.enable_net)
return false;
if (posedge != seq.posedge)
return false;
return true;
}
};
struct VerificImporter
{
RTLIL::Module *module;
Verific::Netlist *netlist;
std::map<Verific::Net*, RTLIL::SigBit> net_map;
std::map<Verific::Net*, Verific::Net*> sva_posedge_map;
pool<Verific::Net*, hash_ptr_ops> any_all_nets;
bool mode_gates, mode_keep, mode_nosva, mode_names, mode_verific;
bool mode_autocover, mode_fullinit;
VerificImporter(bool mode_gates, bool mode_keep, bool mode_nosva, bool mode_names, bool mode_verific, bool mode_autocover, bool mode_fullinit);
RTLIL::SigBit net_map_at(Verific::Net *net);
RTLIL::IdString new_verific_id(Verific::DesignObj *obj);
void import_attributes(dict<RTLIL::IdString, RTLIL::Const> &attributes, Verific::DesignObj *obj, Verific::Netlist *nl = nullptr);
verific: Fixes incorrect aldff inference in verific importer The following SV module at HEAD imported with verific, ```systemverilog module my_module( input logic [4:0] a, input logic clk, input logic enable, output logic [4:0] z ); reg [4:0] pipeline_register; always @(posedge clk) begin pipeline_register <= enable ? a : pipeline_register; end assign z = pipeline_register; endmodule : my_module ``` results in the following output verilog ```systemverilog /* Generated by 0.36 */ (* top = 1 *) (* hdlname = "my_module" *) (* src = "/tmp/temp_directory_zTwd0l/my_input.v:2.12-2.21" *) module my_module(clk, enable, a, z); wire [4:0] _0_; (* src = "/tmp/temp_directory_zTwd0l/my_input.v:3.25-3.26" *) input [4:0] a; wire [4:0] a; (* src = "/tmp/temp_directory_zTwd0l/my_input.v:4.19-4.22" *) input clk; wire clk; (* src = "/tmp/temp_directory_zTwd0l/my_input.v:5.19-5.25" *) input enable; wire enable; (* src = "/tmp/temp_directory_zTwd0l/my_input.v:6.26-6.27" *) output [4:0] z; wire [4:0] z; (* src = "/tmp/temp_directory_zTwd0l/my_input.v:10.12-12.8" *) \$aldff #( .ALOAD_POLARITY(32'd1), .CLK_POLARITY(32'd1), .WIDTH(32'd5) ) _1_ ( .AD(5'hxx), .ALOAD(1'h0), .CLK(clk), .D(_0_), .Q(z) ); (* src = "/tmp/temp_directory_zTwd0l/my_input.v:11.28-11.58" *) \$mux #( .WIDTH(32'd5) ) _2_ ( .A(z), .B(a), .S(enable), .Y(_0_) ); endmodule ``` Yosys is incorrectly infering aldffs due to an incorrect conversion of logical 1 and 0 SigBits. My PR unifies the conversion of Verific::Net objects into SigBits using Yosys' internal representation of special signals like 0,1,x,z. After my PR these signals are correctly converted into DFFs. Signed-off-by: Ethan Mahintorabi <ethanmoon@google.com>
2024-02-05 01:10:25 -06:00
RTLIL::SigBit netToSigBit(Verific::Net *net);
RTLIL::SigSpec operatorInput(Verific::Instance *inst);
RTLIL::SigSpec operatorInput1(Verific::Instance *inst);
RTLIL::SigSpec operatorInput2(Verific::Instance *inst);
RTLIL::SigSpec operatorInport(Verific::Instance *inst, const char *portname);
RTLIL::SigSpec operatorInportCase(Verific::Instance *inst, const char *portname);
RTLIL::SigSpec operatorOutput(Verific::Instance *inst, const pool<Verific::Net*, hash_ptr_ops> *any_all_nets = nullptr);
bool import_netlist_instance_gates(Verific::Instance *inst, RTLIL::IdString inst_name);
bool import_netlist_instance_cells(Verific::Instance *inst, RTLIL::IdString inst_name);
void merge_past_ffs_clock(pool<RTLIL::Cell*> &candidates, SigBit clock, bool clock_pol);
void merge_past_ffs(pool<RTLIL::Cell*> &candidates);
void import_netlist(RTLIL::Design *design, Verific::Netlist *nl, std::map<std::string,Verific::Netlist*> &nl_todo, bool norename = false);
};
void verific_import_sva_assert(VerificImporter *importer, Verific::Instance *inst);
void verific_import_sva_assume(VerificImporter *importer, Verific::Instance *inst);
void verific_import_sva_cover(VerificImporter *importer, Verific::Instance *inst);
void verific_import_sva_trigger(VerificImporter *importer, Verific::Instance *inst);
bool verific_is_sva_net(VerificImporter *importer, Verific::Net *net);
extern int verific_sva_fsm_limit;
YOSYS_NAMESPACE_END
#endif