2014-03-09 20:40:04 +01:00
/*
* yosys - - Yosys Open SYnthesis Suite
*
2021-06-08 00:39:36 +02:00
* Copyright ( C ) 2012 Claire Xenia Wolf < claire @ yosyshq . com >
2015-07-02 11:14:30 +02:00
*
2014-03-09 20:40:04 +01:00
* 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 .
2015-07-02 11:14:30 +02:00
*
2014-03-09 20:40:04 +01:00
* 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 .
*
*/
2014-07-31 13:19:47 +02:00
# include "kernel/yosys.h"
2014-03-09 20:40:04 +01:00
# include "kernel/sigtools.h"
2019-08-07 15:31:49 +02:00
# include "kernel/celltypes.h"
2014-03-09 20:40:04 +01:00
# include "kernel/log.h"
2024-12-11 15:35:43 +01:00
# include "kernel/utils.h"
2020-09-30 09:16:59 +02:00
# include "libs/sha1/sha1.h"
2014-03-09 20:40:04 +01:00
# include <stdlib.h>
# include <stdio.h>
# include <string.h>
2014-10-16 18:06:54 +02:00
# ifndef _WIN32
# include <unistd.h>
# include <dirent.h>
# endif
2014-03-09 20:40:04 +01:00
2018-02-18 13:52:49 +01:00
# include "frontends/verific/verific.h"
2014-07-31 13:19:47 +02:00
USING_YOSYS_NAMESPACE
2014-03-13 17:34:31 +01:00
# ifdef YOSYS_ENABLE_VERIFIC
2014-03-09 20:40:04 +01:00
2017-07-24 13:57:16 +02:00
# ifdef __clang__
2014-03-14 11:46:13 +01:00
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Woverloaded-virtual"
2017-07-24 13:57:16 +02:00
# endif
2014-03-14 11:46:13 +01:00
2024-06-11 08:57:02 +02:00
# include "Array.h"
# include "RuntimeFlags.h"
2024-05-21 17:08:07 +02:00
# ifdef VERIFIC_HIER_TREE_SUPPORT
2018-03-08 13:26:33 +01:00
# include "hier_tree.h"
2024-05-21 17:08:07 +02:00
# endif
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
# include "veri_file.h"
2014-03-14 11:46:13 +01:00
# include "VeriModule.h"
2017-07-24 13:57:16 +02:00
# include "VeriWrite.h"
2019-03-13 23:40:00 +01:00
# include "VeriLibrary.h"
2022-11-25 13:02:11 +01:00
# include "VeriExpression.h"
2024-06-07 14:58:33 +02:00
# endif
2021-02-12 10:08:43 +01:00
2021-10-20 10:02:58 +02:00
# ifdef VERIFIC_VHDL_SUPPORT
# include "vhdl_file.h"
2024-07-18 16:56:52 +02:00
# include "VhdlIdDef.h"
2021-10-20 10:02:58 +02:00
# include "VhdlUnits.h"
2023-10-12 09:17:06 +02:00
# include "NameSpace.h"
2021-10-20 10:02:58 +02:00
# endif
2022-10-04 09:18:44 +02:00
# ifdef VERIFIC_EDIF_SUPPORT
# include "edif_file.h"
# endif
2022-10-31 10:15:05 +01:00
# ifdef VERIFIC_LIBERTY_SUPPORT
# include "synlib_file.h"
2022-10-31 10:51:28 +01:00
# include "SynlibGroup.h"
2022-10-31 10:15:05 +01:00
# endif
2022-06-04 08:39:50 +02:00
# include "VerificStream.h"
# include "FileSystem.h"
2021-08-20 10:19:04 +02:00
# ifdef YOSYSHQ_VERIFIC_EXTENSIONS
2022-06-30 11:19:01 +02:00
# include "VerificExtensions.h"
2021-08-20 10:19:04 +02:00
# endif
2014-03-09 20:40:04 +01:00
2021-01-20 20:48:10 +01:00
# ifndef YOSYSHQ_VERIFIC_API_VERSION
2024-05-21 17:08:07 +02:00
# warning "Only YosysHQ flavored Verific is fully supported. Please contact office@yosyshq.com for commercial support for Yosys+Verific."
# else
2023-09-05 11:52:21 +02:00
# if YOSYSHQ_VERIFIC_API_VERSION < 20230901
2021-01-20 20:48:10 +01:00
# error "Please update your version of YosysHQ flavored Verific."
2019-06-02 10:14:50 +02:00
# endif
2024-05-21 17:08:07 +02:00
# endif
2024-06-11 08:57:02 +02:00
# if !defined(VERIFIC_VHDL_SUPPORT) && !defined(VERIFIC_SYSTEMVERILOG_SUPPORT)
# error "At least one of HDL languages must be enabled."
# endif
2017-07-24 13:57:16 +02:00
# ifdef __clang__
2014-03-14 11:46:13 +01:00
# pragma clang diagnostic pop
2017-07-24 13:57:16 +02:00
# endif
2014-03-14 11:46:13 +01:00
2014-03-09 20:40:04 +01:00
# ifdef VERIFIC_NAMESPACE
2018-02-18 13:52:49 +01:00
using namespace Verific ;
2014-03-09 20:40:04 +01:00
# endif
2017-02-04 13:36:00 +01:00
# endif
# ifdef YOSYS_ENABLE_VERIFIC
2018-02-18 13:52:49 +01:00
YOSYS_NAMESPACE_BEGIN
2017-02-04 13:36:00 +01:00
2018-03-01 11:40:43 +01:00
int verific_verbose ;
2018-06-20 23:45:01 +02:00
bool verific_import_pending ;
2017-10-05 14:38:32 +02:00
string verific_error_msg ;
2018-09-04 20:06:10 +02:00
int verific_sva_fsm_limit ;
2017-10-04 18:56:28 +02:00
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2022-06-09 08:57:48 +02:00
vector < string > verific_incdirs , verific_libdirs , verific_libexts ;
2024-06-07 14:58:33 +02:00
# endif
2018-07-16 18:46:06 +02:00
2017-02-04 13:36:00 +01:00
void msg_func ( msg_type_t msg_type , const char * message_id , linefile_type linefile , const char * msg , va_list args )
2014-03-09 20:40:04 +01:00
{
2017-10-05 14:38:32 +02:00
string message_prefix = stringf ( " VERIFIC-%s [%s] " ,
2014-03-09 20:40:04 +01:00
msg_type = = VERIFIC_NONE ? " NONE " :
msg_type = = VERIFIC_ERROR ? " ERROR " :
msg_type = = VERIFIC_WARNING ? " WARNING " :
msg_type = = VERIFIC_IGNORE ? " IGNORE " :
msg_type = = VERIFIC_INFO ? " INFO " :
msg_type = = VERIFIC_COMMENT ? " COMMENT " :
2025-07-30 10:51:54 +02:00
msg_type = = VERIFIC_PROGRAM_ERROR ? " PROGRAM_ERROR " : " UNKNOWN " , message_id ? message_id : " " ) ;
2017-02-11 11:39:50 +01:00
2017-10-05 14:38:32 +02:00
string message = linefile ? stringf ( " %s:%d: " , LineFile : : GetFileName ( linefile ) , LineFile : : GetLineNo ( linefile ) ) : " " ;
2017-02-11 11:39:50 +01:00
message + = vstringf ( msg , args ) ;
2023-06-12 10:01:01 +02:00
if ( log_verific_callback ) {
2025-08-20 00:45:26 +02:00
string full_message = stringf ( " %s%s \n " , message_prefix , message ) ;
2024-05-21 17:08:07 +02:00
# ifdef VERIFIC_LINEFILE_INCLUDES_COLUMNS
2023-11-03 08:06:16 +01:00
log_verific_callback ( int ( msg_type ) , message_id , LineFile : : GetFileName ( linefile ) ,
linefile ? linefile - > GetLeftLine ( ) : 0 , linefile ? linefile - > GetLeftCol ( ) : 0 ,
linefile ? linefile - > GetRightLine ( ) : 0 , linefile ? linefile - > GetRightCol ( ) : 0 , full_message . c_str ( ) ) ;
2024-05-21 17:08:07 +02:00
# else
log_verific_callback ( int ( msg_type ) , message_id , LineFile : : GetFileName ( linefile ) ,
linefile ? LineFile : : GetLineNo ( linefile ) : 0 , 0 ,
linefile ? LineFile : : GetLineNo ( linefile ) : 0 , 0 , full_message . c_str ( ) ) ;
# endif
2023-06-12 10:01:01 +02:00
} else {
if ( msg_type = = VERIFIC_ERROR | | msg_type = = VERIFIC_WARNING | | msg_type = = VERIFIC_PROGRAM_ERROR )
2025-09-17 01:02:16 +02:00
log_warning_noprefix ( " %s%s \n " , message_prefix , message ) ;
2023-06-12 10:01:01 +02:00
else
2025-09-11 07:25:26 +02:00
log ( " %s%s \n " , message_prefix , message ) ;
2023-06-12 10:01:01 +02:00
}
2017-10-05 14:38:32 +02:00
if ( verific_error_msg . empty ( ) & & ( msg_type = = VERIFIC_ERROR | | msg_type = = VERIFIC_PROGRAM_ERROR ) )
verific_error_msg = message ;
2014-03-09 20:40:04 +01:00
}
2023-11-01 08:13:27 +01:00
void set_verific_logging ( void ( * cb ) ( int msg_type , const char * message_id , const char * file_path , unsigned int left_line , unsigned int left_col , unsigned int right_line , unsigned int right_col , const char * msg ) )
2023-06-12 10:01:01 +02:00
{
Message : : SetConsoleOutput ( 0 ) ;
Message : : RegisterCallBackMsg ( msg_func ) ;
log_verific_callback = cb ;
}
2017-07-25 14:53:11 +02:00
string get_full_netlist_name ( Netlist * nl )
{
if ( nl - > NumOfRefs ( ) = = 1 ) {
Instance * inst = ( Instance * ) nl - > GetReferences ( ) - > GetLast ( ) ;
return get_full_netlist_name ( inst - > Owner ( ) ) + " . " + inst - > Name ( ) ;
}
return nl - > CellBaseName ( ) ;
}
2025-10-03 12:57:49 +02:00
std : : string format_src_location ( DesignObj * obj )
{
2025-10-13 09:11:46 +02:00
if ( obj = = nullptr | | ! obj - > Linefile ( ) )
2025-10-03 12:57:49 +02:00
return std : : string ( ) ;
# ifdef VERIFIC_LINEFILE_INCLUDES_COLUMNS
2025-10-13 09:11:46 +02:00
return stringf ( " %s:%d.%d-%d.%d " , LineFile : : GetFileName ( obj - > Linefile ( ) ) , obj - > Linefile ( ) - > GetLeftLine ( ) , obj - > Linefile ( ) - > GetLeftCol ( ) , obj - > Linefile ( ) - > GetRightLine ( ) , obj - > Linefile ( ) - > GetRightCol ( ) ) ;
2025-10-03 12:57:49 +02:00
# else
2025-10-13 09:11:46 +02:00
return stringf ( " %s:%d " , LineFile : : GetFileName ( obj - > Linefile ( ) ) , LineFile : : GetLineNo ( obj - > Linefile ( ) ) ) ;
2025-10-03 12:57:49 +02:00
# endif
}
std : : string announce_src_location ( DesignObj * obj )
{
std : : string loc = format_src_location ( obj ) ;
if ( loc . empty ( ) )
return std : : string ( ) ;
return loc + " : " ;
}
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2022-06-04 08:39:50 +02:00
class YosysStreamCallBackHandler : public VerificStreamCallBackHandler
{
public :
2023-07-24 16:18:21 +02:00
YosysStreamCallBackHandler ( ) : VerificStreamCallBackHandler ( ) { }
virtual ~ YosysStreamCallBackHandler ( ) { }
virtual verific_stream * GetSysCallStream ( const char * file_path )
{
if ( ! file_path ) return nullptr ;
linefile_type src_loc = GetFromLocation ( ) ;
char * this_file_name = nullptr ;
if ( src_loc & & ! FileSystem : : IsAbsolutePath ( file_path ) ) {
const char * src_file_name = LineFile : : GetFileName ( src_loc ) ;
char * dir_name = FileSystem : : DirectoryPath ( src_file_name ) ;
if ( dir_name ) {
this_file_name = Strings : : save ( dir_name , " / " , file_path ) ;
Strings : : free ( dir_name ) ;
file_path = this_file_name ;
}
}
verific_stream * strm = new verific_ifstream ( file_path ) ;
Strings : : free ( this_file_name ) ;
return strm ;
}
2022-06-04 08:39:50 +02:00
} ;
2022-09-07 09:48:19 +02:00
YosysStreamCallBackHandler verific_read_cb ;
2024-06-07 14:58:33 +02:00
# endif
2022-09-07 09:48:19 +02:00
2018-02-18 13:52:49 +01:00
// ==================================================================
2017-07-27 11:40:07 +02:00
2025-09-24 18:47:54 +02:00
VerificImporter : : VerificImporter ( bool mode_gates , bool mode_keep , bool mode_nosva , bool mode_sva_continue , bool mode_names , bool mode_verific , bool mode_autocover , bool mode_fullinit ) :
mode_gates ( mode_gates ) , mode_keep ( mode_keep ) , mode_nosva ( mode_nosva ) , mode_sva_continue ( mode_sva_continue ) ,
2019-08-07 15:31:49 +02:00
mode_names ( mode_names ) , mode_verific ( mode_verific ) , mode_autocover ( mode_autocover ) ,
mode_fullinit ( mode_fullinit )
2014-03-09 20:40:04 +01:00
{
2018-02-18 13:52:49 +01:00
}
2017-07-24 11:29:06 +02:00
2018-02-18 13:52:49 +01:00
RTLIL : : SigBit VerificImporter : : net_map_at ( Net * net )
{
if ( net - > IsExternalTo ( netlist ) )
log_error ( " Found external reference to '%s.%s' in netlist '%s', please use -flatten or -extnets. \n " ,
get_full_netlist_name ( net - > Owner ( ) ) . c_str ( ) , net - > Name ( ) , get_full_netlist_name ( netlist ) . c_str ( ) ) ;
2014-03-09 20:40:04 +01:00
2018-02-18 13:52:49 +01:00
return net_map . at ( net ) ;
}
2017-07-24 11:29:06 +02:00
2018-10-07 19:48:42 +02:00
bool is_blackbox ( Netlist * nl )
{
2019-11-20 12:56:31 +01:00
if ( nl - > IsBlackBox ( ) | | nl - > IsEmptyBox ( ) )
2018-10-07 19:48:42 +02:00
return true ;
const char * attr = nl - > GetAttValue ( " blackbox " ) ;
if ( attr ! = nullptr & & strcmp ( attr , " 0 " ) )
return true ;
return false ;
}
2018-12-18 16:01:22 +01:00
RTLIL : : IdString VerificImporter : : new_verific_id ( Verific : : DesignObj * obj )
{
std : : string s = stringf ( " $verific$%s " , obj - > Name ( ) ) ;
if ( obj - > Linefile ( ) )
2025-08-20 00:45:26 +02:00
s + = stringf ( " $%s:%d " , RTLIL : : encode_filename ( Verific : : LineFile : : GetFileName ( obj - > Linefile ( ) ) ) , Verific : : LineFile : : GetLineNo ( obj - > Linefile ( ) ) ) ;
2018-12-18 16:01:22 +01:00
s + = stringf ( " $%d " , autoidx + + ) ;
return s ;
}
2024-03-19 09:15:04 +01:00
static const RTLIL : : Const extract_vhdl_boolean ( std : : string & val )
{
if ( val = = " false " )
return RTLIL : : Const : : from_string ( " 0 " ) ;
if ( val = = " true " )
return RTLIL : : Const : : from_string ( " 1 " ) ;
log_error ( " Expecting VHDL boolean value. \n " ) ;
}
static const RTLIL : : Const extract_vhdl_bit ( std : : string & val , std : : string & typ )
{
if ( val . size ( ) = = 3 & & val [ 0 ] = = ' \' ' & & val . back ( ) = = ' \' ' )
return RTLIL : : Const : : from_string ( val . substr ( 1 , val . size ( ) - 2 ) ) ;
2025-09-11 07:25:26 +02:00
log_error ( " Error parsing VHDL %s. \n " , typ ) ;
2024-03-19 09:15:04 +01:00
}
static const RTLIL : : Const extract_vhdl_bit_vector ( std : : string & val , std : : string & typ )
{
if ( val . size ( ) > 1 & & val [ 0 ] = = ' \" ' & & val . back ( ) = = ' \" ' ) {
RTLIL : : Const c = RTLIL : : Const : : from_string ( val . substr ( 1 , val . size ( ) - 2 ) ) ;
if ( typ = = " signed " )
c . flags | = RTLIL : : CONST_FLAG_SIGNED ;
return c ;
}
2025-09-11 07:25:26 +02:00
log_error ( " Error parsing VHDL %s. \n " , typ ) ;
2024-03-19 09:15:04 +01:00
}
static const RTLIL : : Const extract_vhdl_integer ( std : : string & val )
{
char * end ;
2025-08-29 05:34:17 +02:00
return RTLIL : : Const ( ( int ) std : : strtol ( val . c_str ( ) , & end , 10 ) ) ;
2024-03-19 09:15:04 +01:00
}
static const RTLIL : : Const extract_vhdl_char ( std : : string & val )
{
if ( val . size ( ) = = 3 & & val [ 0 ] = = ' \" ' & & val . back ( ) = = ' \" ' )
2025-08-29 05:34:17 +02:00
return RTLIL : : Const ( ( int ) val [ 1 ] ) ;
2024-03-19 09:15:04 +01:00
log_error ( " Error parsing VHDL character. \n " ) ;
}
static const RTLIL : : Const extract_real_value ( std : : string & val )
{
2024-10-09 19:39:45 +02:00
RTLIL : : Const c ( val ) ;
2024-03-19 09:15:04 +01:00
c . flags | = RTLIL : : CONST_FLAG_REAL ;
return c ;
}
static const RTLIL : : Const extract_vhdl_string ( std : : string & val )
{
if ( ! ( val . size ( ) > 1 & & val [ 0 ] = = ' \" ' & & val . back ( ) = = ' \" ' ) )
log_error ( " Error parsing VHDL string. \n " ) ;
return RTLIL : : Const ( val . substr ( 1 , val . size ( ) - 2 ) ) ;
}
static const RTLIL : : Const extract_vhdl_const ( const char * value , bool output_signed )
{
RTLIL : : Const c ;
char * end ;
int decimal ;
bool is_signed = false ;
std : : string val = std : : string ( value ) ;
if ( val . size ( ) > 1 & & val [ 0 ] = = ' \" ' & & val . back ( ) = = ' \" ' ) {
std : : string data = val . substr ( 1 , val . size ( ) - 2 ) ;
bool isBinary = std : : all_of ( data . begin ( ) , data . end ( ) , [ ] ( char c ) { return c = = ' 1 ' | | c = = ' 0 ' ; } ) ;
if ( isBinary )
c = RTLIL : : Const : : from_string ( data ) ;
else
c = RTLIL : : Const ( data ) ;
} else if ( val . size ( ) = = 3 & & val [ 0 ] = = ' \' ' & & val . back ( ) = = ' \' ' ) {
c = RTLIL : : Const : : from_string ( val . substr ( 1 , val . size ( ) - 2 ) ) ;
} else if ( ( value [ 0 ] = = ' - ' | | ( value [ 0 ] > = ' 0 ' & & value [ 0 ] < = ' 9 ' ) ) & &
( ( decimal = std : : strtol ( value , & end , 10 ) ) , ! end [ 0 ] ) ) {
is_signed = output_signed ;
2025-08-29 05:34:17 +02:00
c = RTLIL : : Const ( ( int ) decimal ) ;
2024-03-19 09:15:04 +01:00
} else if ( val = = " false " ) {
c = RTLIL : : Const : : from_string ( " 0 " ) ;
} else if ( val = = " true " ) {
c = RTLIL : : Const : : from_string ( " 1 " ) ;
} else {
2024-10-09 19:39:45 +02:00
c = RTLIL : : Const ( val ) ;
2024-03-19 09:15:04 +01:00
log_warning ( " encoding value '%s' as string. \n " , value ) ;
}
if ( is_signed )
c . flags | = RTLIL : : CONST_FLAG_SIGNED ;
return c ;
}
static const RTLIL : : Const extract_verilog_const ( const char * value , bool allow_string , bool output_signed )
{
RTLIL : : Const c ;
char * end ;
int decimal ;
bool is_signed = false ;
size_t found ;
std : : string val = std : : string ( value ) ;
if ( allow_string & & val . size ( ) > 1 & & val [ 0 ] = = ' \" ' & & val . back ( ) = = ' \" ' ) {
c = RTLIL : : Const ( val . substr ( 1 , val . size ( ) - 2 ) ) ;
} else if ( ( found = val . find ( " 'sb " ) ) ! = std : : string : : npos ) {
is_signed = output_signed ;
c = RTLIL : : Const : : from_string ( val . substr ( found + 3 ) ) ;
} else if ( ( found = val . find ( " 'b " ) ) ! = std : : string : : npos ) {
c = RTLIL : : Const : : from_string ( val . substr ( found + 2 ) ) ;
} else if ( ( value [ 0 ] = = ' - ' | | ( value [ 0 ] > = ' 0 ' & & value [ 0 ] < = ' 9 ' ) ) & &
( ( decimal = std : : strtol ( value , & end , 10 ) ) , ! end [ 0 ] ) ) {
is_signed = output_signed ;
2025-08-29 05:34:17 +02:00
c = RTLIL : : Const ( ( int ) decimal ) ;
2024-03-19 09:15:04 +01:00
} else if ( allow_string ) {
c = RTLIL : : Const ( val ) ;
} else {
2024-10-09 19:39:45 +02:00
c = RTLIL : : Const ( val ) ;
2024-03-19 09:15:04 +01:00
log_warning ( " encoding value '%s' as string. \n " , value ) ;
}
if ( is_signed )
c . flags | = RTLIL : : CONST_FLAG_SIGNED ;
return c ;
}
2022-09-28 14:45:39 +02:00
// When used as attributes or parameter values Verific constants come already processed.
// - Real string values are already under quotes
// - Numeric values with specified width are always converted to binary
// - Rest of user defined values are handled as 32bit integers
// - There could be some internal values that are strings without quotes
// so we check if value is all digits or not
//
2023-03-14 19:13:18 +01:00
// Note: For signed values, verific uses <len>'sb<bits> and decimal values can
// also be negative.
2024-03-14 10:37:11 +01:00
static const RTLIL : : Const verific_const ( const char * type_name , const char * value , DesignObj * obj , bool allow_string = true , bool output_signed = false )
2022-09-28 08:51:26 +02:00
{
std : : string val = std : : string ( value ) ;
2024-03-19 09:15:04 +01:00
// VHDL
2024-03-11 09:30:58 +01:00
if ( obj - > IsFromVhdl ( ) ) {
2024-03-18 10:35:01 +01:00
if ( type_name ) {
2024-03-19 09:15:04 +01:00
std : : string typ = std : : string ( type_name ) ;
transform ( typ . begin ( ) , typ . end ( ) , typ . begin ( ) , : : tolower ) ;
if ( typ = = " integer " | | typ = = " natural " | | typ = = " positive " ) return extract_vhdl_integer ( val ) ;
else if ( typ = = " boolean " ) return extract_vhdl_boolean ( val ) ;
else if ( typ = = " bit " | | typ = = " std_logic " | | typ = = " std_ulogic " ) return extract_vhdl_bit ( val , typ ) ;
else if ( typ = = " character " ) return extract_vhdl_char ( val ) ;
else if ( typ = = " bit_vector " | | typ = = " std_logic_vector " | | typ = = " std_ulogic_vector " | |
typ = = " unsigned " | | typ = = " signed " ) return extract_vhdl_bit_vector ( val , typ ) ;
else if ( typ = = " real " ) return extract_real_value ( val ) ;
else if ( typ = = " string " ) return extract_vhdl_string ( val ) ;
else {
2024-03-18 10:35:01 +01:00
if ( val . size ( ) > 1 & & val [ 0 ] = = ' \" ' & & val . back ( ) = = ' \" ' )
2024-03-19 09:15:04 +01:00
return RTLIL : : Const ( val . substr ( 1 , val . size ( ) - 2 ) ) ;
2024-03-18 10:35:01 +01:00
else if ( val . size ( ) = = 3 & & val [ 0 ] = = ' \' ' & & val . back ( ) = = ' \' ' )
2024-03-19 09:15:04 +01:00
return RTLIL : : Const ( val . substr ( 1 , val . size ( ) - 2 ) ) ;
2024-03-18 10:35:01 +01:00
else
2024-03-19 09:15:04 +01:00
return RTLIL : : Const ( val ) ;
2024-03-18 10:35:01 +01:00
}
2024-03-19 09:15:04 +01:00
} else extract_vhdl_const ( value , output_signed ) ;
2023-11-08 17:10:40 +01:00
}
2024-03-19 09:15:04 +01:00
// SystemVerilog
if ( type_name & & strcmp ( type_name , " real " ) = = 0 ) {
return extract_real_value ( val ) ;
} else
return extract_verilog_const ( value , allow_string , output_signed ) ;
2022-09-28 08:51:26 +02:00
}
2024-05-21 17:08:07 +02:00
# ifdef YOSYSHQ_VERIFIC_API_VERSION
2023-06-21 17:09:28 +02:00
static const std : : string verific_unescape ( const char * value )
{
std : : string val = std : : string ( value ) ;
if ( val . size ( ) > 1 & & val [ 0 ] = = ' \" ' & & val . back ( ) = = ' \" ' )
return val . substr ( 1 , val . size ( ) - 2 ) ;
return value ;
}
2024-05-21 17:08:07 +02:00
# endif
2023-06-21 17:09:28 +02:00
2024-12-12 11:42:39 +01:00
void VerificImporter : : import_attributes ( dict < RTLIL : : IdString , RTLIL : : Const > & attributes , DesignObj * obj , Netlist * nl , int wire_width_hint )
2018-02-18 13:52:49 +01:00
{
2023-11-14 15:05:24 +01:00
if ( ! obj )
return ;
2018-02-18 13:52:49 +01:00
MapIter mi ;
Att * attr ;
2017-07-24 11:29:06 +02:00
2018-02-18 13:52:49 +01:00
if ( obj - > Linefile ( ) )
2025-10-03 12:57:49 +02:00
attributes [ ID : : src ] = format_src_location ( obj ) ;
2017-07-24 11:29:06 +02:00
2018-04-06 21:23:47 +02:00
FOREACH_ATTRIBUTE ( obj , mi , attr ) {
if ( attr - > Key ( ) [ 0 ] = = ' ' | | attr - > Value ( ) = = nullptr )
continue ;
2024-03-14 10:37:11 +01:00
attributes [ RTLIL : : escape_id ( attr - > Key ( ) ) ] = verific_const ( nullptr , attr - > Value ( ) , obj ) ;
2018-04-06 21:23:47 +02:00
}
2020-04-27 17:43:54 +02:00
if ( nl ) {
auto type_range = nl - > GetTypeRange ( obj - > Name ( ) ) ;
if ( ! type_range )
return ;
2024-12-11 16:11:02 +01:00
if ( nl - > IsFromVhdl ( ) & & type_range - > IsTypeScalar ( ) ) {
2024-08-21 16:21:29 +02:00
const long long bottom_bound = type_range - > GetScalarRangeLeftBound ( ) ;
const long long top_bound = type_range - > GetScalarRangeRightBound ( ) ;
2024-12-12 11:42:39 +01:00
int bit_width = type_range - > LeftRangeBound ( ) + 1 ;
if ( bit_width < = 0 ) { // VHDL null range
if ( wire_width_hint > = 0 )
bit_width = wire_width_hint ;
else
bit_width = 64 ; //fallback, currently largest integer width that verific will allow (in vhdl2019 mode)
} else {
if ( wire_width_hint > = 0 ) log_assert ( bit_width = = wire_width_hint ) ;
}
2024-08-21 16:21:29 +02:00
RTLIL : : Const bottom_const ( bottom_bound , bit_width ) ;
RTLIL : : Const top_const ( top_bound , bit_width ) ;
if ( bottom_bound < 0 | | top_bound < 0 ) {
bottom_const . flags | = RTLIL : : CONST_FLAG_SIGNED ;
top_const . flags | = RTLIL : : CONST_FLAG_SIGNED ;
}
attributes . emplace ( ID ( bottom_bound ) , bottom_const ) ;
attributes . emplace ( ID ( top_bound ) , top_const ) ;
}
2020-04-27 17:43:54 +02:00
if ( ! type_range - > IsTypeEnum ( ) )
return ;
2021-10-20 10:02:58 +02:00
# ifdef VERIFIC_VHDL_SUPPORT
2020-04-28 00:17:13 +02:00
if ( nl - > IsFromVhdl ( ) & & strcmp ( type_range - > GetTypeName ( ) , " STD_LOGIC " ) = = 0 )
return ;
2021-10-20 10:02:58 +02:00
# endif
2020-04-30 16:48:47 +02:00
auto type_name = type_range - > GetTypeName ( ) ;
if ( ! type_name )
return ;
attributes . emplace ( ID : : wiretype , RTLIL : : escape_id ( type_name ) ) ;
2020-04-27 17:43:54 +02:00
MapIter mi ;
const char * k , * v ;
FOREACH_MAP_ITEM ( type_range - > GetEnumIdMap ( ) , mi , & k , & v ) {
2020-04-28 00:17:13 +02:00
if ( nl - > IsFromVerilog ( ) ) {
2024-03-14 10:37:11 +01:00
auto const value = verific_const ( type_name , v , nl , false ) ;
2023-03-14 19:13:18 +01:00
2025-08-20 00:45:26 +02:00
attributes . emplace ( stringf ( " \\ enum_value_%s " , value . as_string ( ) ) , RTLIL : : escape_id ( k ) ) ;
2020-04-28 00:17:13 +02:00
}
2021-10-20 10:02:58 +02:00
# ifdef VERIFIC_VHDL_SUPPORT
2020-04-28 00:17:13 +02:00
else if ( nl - > IsFromVhdl ( ) ) {
2020-08-30 12:25:23 +02:00
// Expect "<binary>" or plain <binary>
2020-04-28 00:17:13 +02:00
auto p = v ;
if ( p ) {
2020-08-30 12:25:23 +02:00
if ( * p ! = ' " ' ) {
2020-08-30 13:33:03 +02:00
auto l = strlen ( p ) ;
auto q = ( char * ) malloc ( l + 1 ) ;
strncpy ( q , p , l ) ;
q [ l ] = ' \0 ' ;
for ( char * ptr = q ; * ptr ; + + ptr ) * ptr = tolower ( * ptr ) ;
attributes . emplace ( stringf ( " \\ enum_value_%s " , q ) , RTLIL : : escape_id ( k ) ) ;
2020-08-30 12:25:23 +02:00
} else {
2020-04-28 00:17:13 +02:00
auto * q = p + 1 ;
for ( ; * q ! = ' " ' ; q + + )
if ( * q ! = ' 0 ' & & * q ! = ' 1 ' ) {
p = nullptr ;
break ;
}
if ( p & & * ( q + 1 ) ! = ' \0 ' )
2020-04-27 17:43:54 +02:00
p = nullptr ;
2020-08-30 12:25:23 +02:00
if ( p ! = nullptr )
{
auto l = strlen ( p ) ;
auto q = ( char * ) malloc ( l + 1 - 2 ) ;
strncpy ( q , p + 1 , l - 2 ) ;
q [ l - 2 ] = ' \0 ' ;
attributes . emplace ( stringf ( " \\ enum_value_%s " , q ) , RTLIL : : escape_id ( k ) ) ;
free ( q ) ;
}
2020-04-28 00:17:13 +02:00
}
}
if ( p = = nullptr )
2025-10-03 12:57:49 +02:00
log_error ( " %sExpected TypeRange value '%s' to be of form \" <binary> \" or <binary>. \n " , announce_src_location ( obj ) , v ) ;
2020-04-27 17:43:54 +02:00
}
2021-10-20 10:02:58 +02:00
# endif
2020-04-27 17:43:54 +02:00
}
}
2018-02-18 13:52:49 +01:00
}
2017-07-24 11:29:06 +02:00
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 08:10:25 +01:00
RTLIL : : SigBit VerificImporter : : netToSigBit ( Verific : : Net * net ) {
if ( net & & net - > IsGnd ( ) )
return RTLIL : : State : : S0 ;
else if ( net & & net - > IsPwr ( ) )
return RTLIL : : State : : S1 ;
else if ( net & & net - > IsX ( ) )
return RTLIL : : State : : Sx ;
else if ( net )
2024-02-05 08:23:04 +01:00
return net_map_at ( net ) ;
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 08:10:25 +01:00
else
return RTLIL : : State : : Sz ;
}
2018-02-18 13:52:49 +01:00
RTLIL : : SigSpec VerificImporter : : operatorInput ( Instance * inst )
{
RTLIL : : SigSpec sig ;
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 08:10:25 +01:00
for ( int i = int ( inst - > InputSize ( ) ) - 1 ; i > = 0 ; i - - ) {
Net * net = inst - > GetInputBit ( i ) ;
sig . append ( netToSigBit ( net ) ) ;
}
2018-02-18 13:52:49 +01:00
return sig ;
}
2014-03-10 12:06:57 +01:00
2018-02-18 13:52:49 +01:00
RTLIL : : SigSpec VerificImporter : : operatorInput1 ( Instance * inst )
{
RTLIL : : SigSpec sig ;
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 08:10:25 +01:00
for ( int i = int ( inst - > Input1Size ( ) ) - 1 ; i > = 0 ; i - - ) {
Net * net = inst - > GetInput1Bit ( i ) ;
sig . append ( netToSigBit ( net ) ) ;
}
2018-02-18 13:52:49 +01:00
return sig ;
}
2014-03-10 12:06:57 +01:00
2018-02-18 13:52:49 +01:00
RTLIL : : SigSpec VerificImporter : : operatorInput2 ( Instance * inst )
{
RTLIL : : SigSpec sig ;
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 08:10:25 +01:00
for ( int i = int ( inst - > Input2Size ( ) ) - 1 ; i > = 0 ; i - - ) {
Net * net = inst - > GetInput2Bit ( i ) ;
sig . append ( netToSigBit ( net ) ) ;
}
2018-02-18 13:52:49 +01:00
return sig ;
}
2014-03-10 12:06:57 +01:00
2018-02-18 13:52:49 +01:00
RTLIL : : SigSpec VerificImporter : : operatorInport ( Instance * inst , const char * portname )
{
PortBus * portbus = inst - > View ( ) - > GetPortBus ( portname ) ;
if ( portbus ) {
2014-03-17 02:43:53 +01:00
RTLIL : : SigSpec sig ;
2018-02-18 13:52:49 +01:00
for ( unsigned i = 0 ; i < portbus - > Size ( ) ; i + + ) {
Net * net = inst - > GetNet ( portbus - > ElementAtIndex ( i ) ) ;
if ( net ) {
2023-02-08 09:22:48 +01:00
if ( net - > IsConstant ( ) ) {
if ( net - > IsGnd ( ) )
sig . append ( RTLIL : : State : : S0 ) ;
else if ( net - > IsPwr ( ) )
sig . append ( RTLIL : : State : : S1 ) ;
else if ( net - > IsX ( ) )
sig . append ( RTLIL : : State : : Sx ) ;
else
sig . append ( RTLIL : : State : : Sz ) ;
}
2018-02-18 13:52:49 +01:00
else
sig . append ( net_map_at ( net ) ) ;
} else
2014-03-17 02:43:53 +01:00
sig . append ( RTLIL : : State : : Sz ) ;
2018-02-18 13:52:49 +01:00
}
2014-03-17 02:43:53 +01:00
return sig ;
2018-02-18 13:52:49 +01:00
} else {
Port * port = inst - > View ( ) - > GetPort ( portname ) ;
log_assert ( port ! = NULL ) ;
Net * net = inst - > GetNet ( port ) ;
return net_map_at ( net ) ;
2014-03-17 02:43:53 +01:00
}
2018-02-18 13:52:49 +01:00
}
2014-03-17 02:43:53 +01:00
2023-02-08 09:22:48 +01:00
RTLIL : : SigSpec VerificImporter : : operatorInportCase ( Instance * inst , const char * portname )
{
PortBus * portbus = inst - > View ( ) - > GetPortBus ( portname ) ;
if ( portbus ) {
RTLIL : : SigSpec sig ;
for ( unsigned i = 0 ; i < portbus - > Size ( ) ; i + + ) {
Net * net = inst - > GetNet ( portbus - > ElementAtIndex ( i ) ) ;
if ( net ) {
if ( net - > IsConstant ( ) ) {
if ( net - > IsGnd ( ) )
sig . append ( RTLIL : : State : : S0 ) ;
else if ( net - > IsPwr ( ) )
sig . append ( RTLIL : : State : : S1 ) ;
else
sig . append ( RTLIL : : State : : Sa ) ;
}
else
sig . append ( net_map_at ( net ) ) ;
} else
sig . append ( RTLIL : : State : : Sa ) ;
}
return sig ;
} else {
Port * port = inst - > View ( ) - > GetPort ( portname ) ;
log_assert ( port ! = NULL ) ;
Net * net = inst - > GetNet ( port ) ;
return net_map_at ( net ) ;
}
}
2024-10-01 15:12:03 +02:00
RTLIL : : SigSpec VerificImporter : : operatorOutput ( Instance * inst , const pool < Net * > * any_all_nets )
2018-02-18 13:52:49 +01:00
{
RTLIL : : SigSpec sig ;
RTLIL : : Wire * dummy_wire = NULL ;
for ( int i = int ( inst - > OutputSize ( ) ) - 1 ; i > = 0 ; i - - )
2018-05-24 17:07:06 +02:00
if ( inst - > GetOutputBit ( i ) & & ( ! any_all_nets | | ! any_all_nets - > count ( inst - > GetOutputBit ( i ) ) ) ) {
2018-02-18 13:52:49 +01:00
sig . append ( net_map_at ( inst - > GetOutputBit ( i ) ) ) ;
dummy_wire = NULL ;
} else {
if ( dummy_wire = = NULL )
2018-12-18 16:01:22 +01:00
dummy_wire = module - > addWire ( new_verific_id ( inst ) ) ;
2014-03-10 12:06:57 +01:00
else
2018-02-18 13:52:49 +01:00
dummy_wire - > width + + ;
sig . append ( RTLIL : : SigSpec ( dummy_wire , dummy_wire - > width - 1 ) ) ;
}
return sig ;
}
2014-03-14 11:46:13 +01:00
2018-02-18 13:52:49 +01:00
bool VerificImporter : : import_netlist_instance_gates ( Instance * inst , RTLIL : : IdString inst_name )
{
if ( inst - > Type ( ) = = PRIM_AND ) {
module - > addAndGate ( inst_name , net_map_at ( inst - > GetInput1 ( ) ) , net_map_at ( inst - > GetInput2 ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
return true ;
2014-03-17 14:42:07 +01:00
}
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_NAND ) {
2018-12-18 16:01:22 +01:00
RTLIL : : SigSpec tmp = module - > addWire ( new_verific_id ( inst ) ) ;
module - > addAndGate ( new_verific_id ( inst ) , net_map_at ( inst - > GetInput1 ( ) ) , net_map_at ( inst - > GetInput2 ( ) ) , tmp ) ;
2018-02-18 13:52:49 +01:00
module - > addNotGate ( inst_name , tmp , net_map_at ( inst - > GetOutput ( ) ) ) ;
return true ;
2014-03-14 11:46:13 +01:00
}
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_OR ) {
module - > addOrGate ( inst_name , net_map_at ( inst - > GetInput1 ( ) ) , net_map_at ( inst - > GetInput2 ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
return true ;
2016-02-13 08:19:30 +01:00
}
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_NOR ) {
2018-12-18 16:01:22 +01:00
RTLIL : : SigSpec tmp = module - > addWire ( new_verific_id ( inst ) ) ;
module - > addOrGate ( new_verific_id ( inst ) , net_map_at ( inst - > GetInput1 ( ) ) , net_map_at ( inst - > GetInput2 ( ) ) , tmp ) ;
2018-02-18 13:52:49 +01:00
module - > addNotGate ( inst_name , tmp , net_map_at ( inst - > GetOutput ( ) ) ) ;
return true ;
}
2014-03-14 11:46:13 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_XOR ) {
module - > addXorGate ( inst_name , net_map_at ( inst - > GetInput1 ( ) ) , net_map_at ( inst - > GetInput2 ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
return true ;
}
2014-03-14 11:46:13 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_XNOR ) {
module - > addXnorGate ( inst_name , net_map_at ( inst - > GetInput1 ( ) ) , net_map_at ( inst - > GetInput2 ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
return true ;
}
2014-03-17 14:42:07 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_BUF ) {
2018-05-25 15:41:45 +02:00
auto outnet = inst - > GetOutput ( ) ;
if ( ! any_all_nets . count ( outnet ) )
module - > addBufGate ( inst_name , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( outnet ) ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-14 11:46:13 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_INV ) {
module - > addNotGate ( inst_name , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
return true ;
}
2014-03-17 14:42:07 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_MUX ) {
module - > addMuxGate ( inst_name , net_map_at ( inst - > GetInput1 ( ) ) , net_map_at ( inst - > GetInput2 ( ) ) , net_map_at ( inst - > GetControl ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
return true ;
}
2014-03-14 11:46:13 +01:00
2021-10-14 13:04:32 +02:00
if ( ( inst - > Type ( ) = = PRIM_TRI ) | | ( inst - > Type ( ) = = PRIM_BUFIF1 ) ) {
2018-02-18 13:52:49 +01:00
module - > addMuxGate ( inst_name , RTLIL : : State : : Sz , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetControl ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
return true ;
2014-03-14 11:46:13 +01:00
}
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_FADD )
2017-02-04 13:36:00 +01:00
{
2018-02-18 13:52:49 +01:00
RTLIL : : SigSpec a = net_map_at ( inst - > GetInput1 ( ) ) , b = net_map_at ( inst - > GetInput2 ( ) ) , c = net_map_at ( inst - > GetCin ( ) ) ;
2018-12-18 16:01:22 +01:00
RTLIL : : SigSpec x = inst - > GetCout ( ) ? net_map_at ( inst - > GetCout ( ) ) : module - > addWire ( new_verific_id ( inst ) ) ;
RTLIL : : SigSpec y = inst - > GetOutput ( ) ? net_map_at ( inst - > GetOutput ( ) ) : module - > addWire ( new_verific_id ( inst ) ) ;
RTLIL : : SigSpec tmp1 = module - > addWire ( new_verific_id ( inst ) ) ;
RTLIL : : SigSpec tmp2 = module - > addWire ( new_verific_id ( inst ) ) ;
RTLIL : : SigSpec tmp3 = module - > addWire ( new_verific_id ( inst ) ) ;
module - > addXorGate ( new_verific_id ( inst ) , a , b , tmp1 ) ;
2018-02-18 13:52:49 +01:00
module - > addXorGate ( inst_name , tmp1 , c , y ) ;
2018-12-18 16:01:22 +01:00
module - > addAndGate ( new_verific_id ( inst ) , tmp1 , c , tmp2 ) ;
module - > addAndGate ( new_verific_id ( inst ) , a , b , tmp3 ) ;
module - > addOrGate ( new_verific_id ( inst ) , tmp2 , tmp3 , x ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-14 11:46:13 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_DFFRS )
{
2018-03-04 13:48:53 +01:00
VerificClocking clocking ( this , inst - > GetClock ( ) ) ;
log_assert ( clocking . disable_sig = = State : : S0 ) ;
log_assert ( clocking . body_net = = nullptr ) ;
2018-02-18 13:52:49 +01:00
if ( inst - > GetSet ( ) - > IsGnd ( ) & & inst - > GetReset ( ) - > IsGnd ( ) )
2018-03-04 13:48:53 +01:00
clocking . addDff ( inst_name , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
2018-02-18 13:52:49 +01:00
else if ( inst - > GetSet ( ) - > IsGnd ( ) )
2018-03-04 13:48:53 +01:00
clocking . addAdff ( inst_name , net_map_at ( inst - > GetReset ( ) ) , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) , State : : S0 ) ;
2018-02-18 13:52:49 +01:00
else if ( inst - > GetReset ( ) - > IsGnd ( ) )
2018-03-04 13:48:53 +01:00
clocking . addAdff ( inst_name , net_map_at ( inst - > GetSet ( ) ) , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) , State : : S1 ) ;
2018-02-18 13:52:49 +01:00
else
2018-03-04 13:48:53 +01:00
clocking . addDffsr ( inst_name , net_map_at ( inst - > GetSet ( ) ) , net_map_at ( inst - > GetReset ( ) ) ,
2018-02-18 13:52:49 +01:00
net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
return true ;
}
2014-03-14 11:46:13 +01:00
2021-10-08 17:24:45 +02:00
if ( inst - > Type ( ) = = PRIM_DLATCHRS )
{
if ( inst - > GetSet ( ) - > IsGnd ( ) & & inst - > GetReset ( ) - > IsGnd ( ) )
module - > addDlatch ( inst_name , net_map_at ( inst - > GetControl ( ) ) , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
else
module - > addDlatchsr ( inst_name , net_map_at ( inst - > GetControl ( ) ) , net_map_at ( inst - > GetSet ( ) ) , net_map_at ( inst - > GetReset ( ) ) ,
net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
return true ;
}
2021-10-08 16:21:25 +02:00
if ( inst - > Type ( ) = = PRIM_DFF )
{
VerificClocking clocking ( this , inst - > GetClock ( ) ) ;
log_assert ( clocking . disable_sig = = State : : S0 ) ;
log_assert ( clocking . body_net = = nullptr ) ;
2021-10-08 17:24:45 +02:00
if ( inst - > GetAsyncCond ( ) - > IsGnd ( ) )
2021-10-08 16:21:25 +02:00
clocking . addDff ( inst_name , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
else
clocking . addAldff ( inst_name , net_map_at ( inst - > GetAsyncCond ( ) ) , net_map_at ( inst - > GetAsyncVal ( ) ) ,
net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
return true ;
}
2021-10-21 05:42:47 +02:00
if ( inst - > Type ( ) = = PRIM_DLATCH )
{
2021-10-21 12:13:35 +02:00
if ( inst - > GetAsyncCond ( ) - > IsGnd ( ) ) {
module - > addDlatch ( inst_name , net_map_at ( inst - > GetControl ( ) ) , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
} else {
RTLIL : : SigSpec sig_set = module - > And ( NEW_ID , net_map_at ( inst - > GetAsyncCond ( ) ) , net_map_at ( inst - > GetAsyncVal ( ) ) ) ;
RTLIL : : SigSpec sig_clr = module - > And ( NEW_ID , net_map_at ( inst - > GetAsyncCond ( ) ) , module - > Not ( NEW_ID , net_map_at ( inst - > GetAsyncVal ( ) ) ) ) ;
module - > addDlatchsr ( inst_name , net_map_at ( inst - > GetControl ( ) ) , sig_set , sig_clr , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
}
2021-10-21 05:42:47 +02:00
return true ;
}
2021-10-08 17:24:45 +02:00
2018-02-18 13:52:49 +01:00
return false ;
}
2014-03-17 14:42:07 +01:00
2018-02-18 13:52:49 +01:00
bool VerificImporter : : import_netlist_instance_cells ( Instance * inst , RTLIL : : IdString inst_name )
{
2018-12-18 16:01:22 +01:00
RTLIL : : Cell * cell = nullptr ;
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_AND ) {
2018-12-18 16:01:22 +01:00
cell = module - > addAnd ( inst_name , net_map_at ( inst - > GetInput1 ( ) ) , net_map_at ( inst - > GetInput2 ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-17 02:43:53 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_NAND ) {
2018-12-18 16:01:22 +01:00
RTLIL : : SigSpec tmp = module - > addWire ( new_verific_id ( inst ) ) ;
cell = module - > addAnd ( new_verific_id ( inst ) , net_map_at ( inst - > GetInput1 ( ) ) , net_map_at ( inst - > GetInput2 ( ) ) , tmp ) ;
import_attributes ( cell - > attributes , inst ) ;
cell = module - > addNot ( inst_name , tmp , net_map_at ( inst - > GetOutput ( ) ) ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-14 11:46:13 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_OR ) {
2018-12-18 16:01:22 +01:00
cell = module - > addOr ( inst_name , net_map_at ( inst - > GetInput1 ( ) ) , net_map_at ( inst - > GetInput2 ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-14 11:46:13 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_NOR ) {
2018-12-18 16:01:22 +01:00
RTLIL : : SigSpec tmp = module - > addWire ( new_verific_id ( inst ) ) ;
cell = module - > addOr ( new_verific_id ( inst ) , net_map_at ( inst - > GetInput1 ( ) ) , net_map_at ( inst - > GetInput2 ( ) ) , tmp ) ;
import_attributes ( cell - > attributes , inst ) ;
cell = module - > addNot ( inst_name , tmp , net_map_at ( inst - > GetOutput ( ) ) ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-14 11:46:13 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_XOR ) {
2018-12-18 16:01:22 +01:00
cell = module - > addXor ( inst_name , net_map_at ( inst - > GetInput1 ( ) ) , net_map_at ( inst - > GetInput2 ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-14 11:46:13 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_XNOR ) {
2018-12-18 16:01:22 +01:00
cell = module - > addXnor ( inst_name , net_map_at ( inst - > GetInput1 ( ) ) , net_map_at ( inst - > GetInput2 ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-09 20:40:04 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_INV ) {
2018-12-18 16:01:22 +01:00
cell = module - > addNot ( inst_name , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-09 20:40:04 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_MUX ) {
2018-12-18 16:01:22 +01:00
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 ( ) ) ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-09 20:40:04 +01:00
2021-10-14 13:04:32 +02:00
if ( ( inst - > Type ( ) = = PRIM_TRI ) | | ( inst - > Type ( ) = = PRIM_BUFIF1 ) ) {
2018-12-18 16:01:22 +01:00
cell = module - > addMux ( inst_name , RTLIL : : State : : Sz , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetControl ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
2017-02-04 13:36:00 +01:00
}
2014-03-09 20:40:04 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_FADD )
2017-07-29 00:07:02 +02:00
{
2018-12-18 16:01:22 +01:00
RTLIL : : SigSpec a_plus_b = module - > addWire ( new_verific_id ( inst ) , 2 ) ;
RTLIL : : SigSpec y = inst - > GetOutput ( ) ? net_map_at ( inst - > GetOutput ( ) ) : module - > addWire ( new_verific_id ( inst ) ) ;
2018-02-18 13:52:49 +01:00
if ( inst - > GetCout ( ) )
y . append ( net_map_at ( inst - > GetCout ( ) ) ) ;
2018-12-18 16:01:22 +01:00
cell = module - > addAdd ( new_verific_id ( inst ) , net_map_at ( inst - > GetInput1 ( ) ) , net_map_at ( inst - > GetInput2 ( ) ) , a_plus_b ) ;
import_attributes ( cell - > attributes , inst ) ;
cell = module - > addAdd ( inst_name , a_plus_b , net_map_at ( inst - > GetCin ( ) ) , y ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
2017-07-29 00:07:02 +02:00
}
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_DFFRS )
2017-07-29 00:07:02 +02:00
{
2018-03-04 13:48:53 +01:00
VerificClocking clocking ( this , inst - > GetClock ( ) ) ;
log_assert ( clocking . disable_sig = = State : : S0 ) ;
log_assert ( clocking . body_net = = nullptr ) ;
2018-02-18 13:52:49 +01:00
if ( inst - > GetSet ( ) - > IsGnd ( ) & & inst - > GetReset ( ) - > IsGnd ( ) )
2018-12-18 16:01:22 +01:00
cell = clocking . addDff ( inst_name , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
2018-02-18 13:52:49 +01:00
else if ( inst - > GetSet ( ) - > IsGnd ( ) )
2018-12-18 16:01:22 +01:00
cell = clocking . addAdff ( inst_name , net_map_at ( inst - > GetReset ( ) ) , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) , RTLIL : : State : : S0 ) ;
2018-02-18 13:52:49 +01:00
else if ( inst - > GetReset ( ) - > IsGnd ( ) )
2018-12-18 16:01:22 +01:00
cell = clocking . addAdff ( inst_name , net_map_at ( inst - > GetSet ( ) ) , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) , RTLIL : : State : : S1 ) ;
2018-02-18 13:52:49 +01:00
else
2018-12-18 16:01:22 +01:00
cell = clocking . addDffsr ( inst_name , net_map_at ( inst - > GetSet ( ) ) , net_map_at ( inst - > GetReset ( ) ) ,
2018-02-18 13:52:49 +01:00
net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
2018-12-18 16:01:22 +01:00
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
2017-07-29 00:07:02 +02:00
}
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_DLATCHRS )
2014-03-09 20:40:04 +01:00
{
2018-02-18 13:52:49 +01:00
if ( inst - > GetSet ( ) - > IsGnd ( ) & & inst - > GetReset ( ) - > IsGnd ( ) )
2018-12-18 16:01:22 +01:00
cell = module - > addDlatch ( inst_name , net_map_at ( inst - > GetControl ( ) ) , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
2018-02-18 13:52:49 +01:00
else
2018-12-18 16:01:22 +01:00
cell = module - > addDlatchsr ( inst_name , net_map_at ( inst - > GetControl ( ) ) , net_map_at ( inst - > GetSet ( ) ) , net_map_at ( inst - > GetReset ( ) ) ,
2018-02-18 13:52:49 +01:00
net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
2018-12-18 16:01:22 +01:00
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-09 20:40:04 +01:00
2021-10-08 17:24:45 +02:00
if ( inst - > Type ( ) = = PRIM_DFF )
{
VerificClocking clocking ( this , inst - > GetClock ( ) ) ;
log_assert ( clocking . disable_sig = = State : : S0 ) ;
log_assert ( clocking . body_net = = nullptr ) ;
if ( inst - > GetAsyncCond ( ) - > IsGnd ( ) )
cell = clocking . addDff ( inst_name , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
else
cell = clocking . addAldff ( inst_name , net_map_at ( inst - > GetAsyncCond ( ) ) , net_map_at ( inst - > GetAsyncVal ( ) ) ,
net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
import_attributes ( cell - > attributes , inst ) ;
return true ;
}
2021-10-21 05:42:47 +02:00
if ( inst - > Type ( ) = = PRIM_DLATCH )
{
if ( inst - > GetAsyncCond ( ) - > IsGnd ( ) ) {
cell = module - > addDlatch ( inst_name , net_map_at ( inst - > GetControl ( ) ) , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
} else {
RTLIL : : SigSpec sig_set = module - > And ( NEW_ID , net_map_at ( inst - > GetAsyncCond ( ) ) , net_map_at ( inst - > GetAsyncVal ( ) ) ) ;
RTLIL : : SigSpec sig_clr = module - > And ( NEW_ID , net_map_at ( inst - > GetAsyncCond ( ) ) , module - > Not ( NEW_ID , net_map_at ( inst - > GetAsyncVal ( ) ) ) ) ;
cell = module - > addDlatchsr ( inst_name , net_map_at ( inst - > GetControl ( ) ) , sig_set , sig_clr , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( inst - > GetOutput ( ) ) ) ;
}
import_attributes ( cell - > attributes , inst ) ;
return true ;
}
2021-10-08 17:24:45 +02:00
2018-02-18 13:52:49 +01:00
# define IN operatorInput(inst)
# define IN1 operatorInput1(inst)
# define IN2 operatorInput2(inst)
# define OUT operatorOutput(inst)
2018-05-24 17:07:06 +02:00
# define FILTERED_OUT operatorOutput(inst, &any_all_nets)
2018-02-18 13:52:49 +01:00
# define SIGNED inst->View()->IsSigned()
if ( inst - > Type ( ) = = OPER_ADDER ) {
RTLIL : : SigSpec out = OUT ;
if ( inst - > GetCout ( ) ! = NULL )
out . append ( net_map_at ( inst - > GetCout ( ) ) ) ;
if ( inst - > GetCin ( ) - > IsGnd ( ) ) {
2018-12-18 16:01:22 +01:00
cell = module - > addAdd ( inst_name , IN1 , IN2 , out , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2017-07-22 16:16:44 +02:00
} else {
2018-12-18 16:01:22 +01:00
RTLIL : : SigSpec tmp = module - > addWire ( new_verific_id ( inst ) , GetSize ( out ) ) ;
cell = module - > addAdd ( new_verific_id ( inst ) , IN1 , IN2 , tmp , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
cell = module - > addAdd ( inst_name , tmp , net_map_at ( inst - > GetCin ( ) ) , out , false ) ;
import_attributes ( cell - > attributes , inst ) ;
2017-12-10 00:26:26 +01:00
}
2018-02-18 13:52:49 +01:00
return true ;
}
2017-12-10 00:26:26 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_MULTIPLIER ) {
2018-12-18 16:01:22 +01:00
cell = module - > addMul ( inst_name , IN1 , IN2 , OUT , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-09 20:40:04 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_DIVIDER ) {
2018-12-18 16:01:22 +01:00
cell = module - > addDiv ( inst_name , IN1 , IN2 , OUT , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2017-02-04 13:36:00 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_MODULO ) {
2018-12-18 16:01:22 +01:00
cell = module - > addMod ( inst_name , IN1 , IN2 , OUT , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-09 20:40:04 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_REMAINDER ) {
2018-12-18 16:01:22 +01:00
cell = module - > addMod ( inst_name , IN1 , IN2 , OUT , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-09 20:40:04 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_SHIFT_LEFT ) {
2018-12-18 16:01:22 +01:00
cell = module - > addShl ( inst_name , IN1 , IN2 , OUT , false ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-09 20:40:04 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_ENABLED_DECODER ) {
RTLIL : : SigSpec vec ;
vec . append ( net_map_at ( inst - > GetControl ( ) ) ) ;
for ( unsigned i = 1 ; i < inst - > OutputSize ( ) ; i + + ) {
vec . append ( RTLIL : : State : : S0 ) ;
2014-03-09 20:40:04 +01:00
}
2018-12-18 16:01:22 +01:00
cell = module - > addShl ( inst_name , vec , IN , OUT , false ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-09 20:40:04 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_DECODER ) {
RTLIL : : SigSpec vec ;
vec . append ( RTLIL : : State : : S1 ) ;
for ( unsigned i = 1 ; i < inst - > OutputSize ( ) ; i + + ) {
vec . append ( RTLIL : : State : : S0 ) ;
2017-02-04 13:36:00 +01:00
}
2018-12-18 16:01:22 +01:00
cell = module - > addShl ( inst_name , vec , IN , OUT , false ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-09 20:40:04 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_SHIFT_RIGHT ) {
Net * net_cin = inst - > GetCin ( ) ;
Net * net_a_msb = inst - > GetInput1Bit ( 0 ) ;
if ( net_cin - > IsGnd ( ) )
2018-12-18 16:01:22 +01:00
cell = module - > addShr ( inst_name , IN1 , IN2 , OUT , false ) ;
2018-02-18 13:52:49 +01:00
else if ( net_cin = = net_a_msb )
2018-12-18 16:01:22 +01:00
cell = module - > addSshr ( inst_name , IN1 , IN2 , OUT , true ) ;
2018-02-18 13:52:49 +01:00
else
2025-10-03 12:57:49 +02:00
log_error ( " %sCan't import Verific OPER_SHIFT_RIGHT instance %s: carry_in is neither 0 nor msb of left input \n " , announce_src_location ( inst ) , inst - > Name ( ) ) ;
2018-12-18 16:01:22 +01:00
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2017-02-04 13:36:00 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_REDUCE_AND ) {
2018-12-18 16:01:22 +01:00
cell = module - > addReduceAnd ( inst_name , IN , net_map_at ( inst - > GetOutput ( ) ) , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2017-02-11 11:40:18 +01:00
2020-01-30 18:01:13 +01:00
if ( inst - > Type ( ) = = OPER_REDUCE_NAND ) {
Wire * tmp = module - > addWire ( NEW_ID ) ;
cell = module - > addReduceAnd ( inst_name , IN , tmp , SIGNED ) ;
module - > addNot ( NEW_ID , tmp , net_map_at ( inst - > GetOutput ( ) ) ) ;
import_attributes ( cell - > attributes , inst ) ;
return true ;
}
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_REDUCE_OR ) {
2018-12-18 16:01:22 +01:00
cell = module - > addReduceOr ( inst_name , IN , net_map_at ( inst - > GetOutput ( ) ) , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2017-02-11 11:40:18 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_REDUCE_XOR ) {
2018-12-18 16:01:22 +01:00
cell = module - > addReduceXor ( inst_name , IN , net_map_at ( inst - > GetOutput ( ) ) , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2017-02-11 11:40:18 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_REDUCE_XNOR ) {
2018-12-18 16:01:22 +01:00
cell = module - > addReduceXnor ( inst_name , IN , net_map_at ( inst - > GetOutput ( ) ) , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2017-02-11 11:40:18 +01:00
2018-02-26 15:26:01 +01:00
if ( inst - > Type ( ) = = OPER_REDUCE_NOR ) {
2018-12-18 16:01:22 +01:00
SigSpec t = module - > ReduceOr ( new_verific_id ( inst ) , IN , SIGNED ) ;
cell = module - > addNot ( inst_name , t , net_map_at ( inst - > GetOutput ( ) ) ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-26 15:26:01 +01:00
return true ;
}
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_LESSTHAN ) {
Net * net_cin = inst - > GetCin ( ) ;
if ( net_cin - > IsGnd ( ) )
2018-12-18 16:01:22 +01:00
cell = module - > addLt ( inst_name , IN1 , IN2 , net_map_at ( inst - > GetOutput ( ) ) , SIGNED ) ;
2018-02-18 13:52:49 +01:00
else if ( net_cin - > IsPwr ( ) )
2018-12-18 16:01:22 +01:00
cell = module - > addLe ( inst_name , IN1 , IN2 , net_map_at ( inst - > GetOutput ( ) ) , SIGNED ) ;
2018-02-18 13:52:49 +01:00
else
2025-10-03 12:57:49 +02:00
log_error ( " %sCan't import Verific OPER_LESSTHAN instance %s: carry_in is neither 0 nor 1 \n " , announce_src_location ( inst ) , inst - > Name ( ) ) ;
2018-12-18 16:01:22 +01:00
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2017-02-11 11:40:18 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_WIDE_AND ) {
2018-12-18 16:01:22 +01:00
cell = module - > addAnd ( inst_name , IN1 , IN2 , OUT , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2017-02-09 12:53:46 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_WIDE_OR ) {
2018-12-18 16:01:22 +01:00
cell = module - > addOr ( inst_name , IN1 , IN2 , OUT , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2017-02-09 12:53:46 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_WIDE_XOR ) {
2018-12-18 16:01:22 +01:00
cell = module - > addXor ( inst_name , IN1 , IN2 , OUT , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-09 20:40:04 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_WIDE_XNOR ) {
2018-12-18 16:01:22 +01:00
cell = module - > addXnor ( inst_name , IN1 , IN2 , OUT , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2017-07-29 00:07:02 +02:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_WIDE_BUF ) {
2018-12-18 16:01:22 +01:00
cell = module - > addPos ( inst_name , IN , FILTERED_OUT , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-09 20:40:04 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_WIDE_INV ) {
2018-12-18 16:01:22 +01:00
cell = module - > addNot ( inst_name , IN , OUT , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-09 20:40:04 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_MINUS ) {
2018-12-18 16:01:22 +01:00
cell = module - > addSub ( inst_name , IN1 , IN2 , OUT , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-09 20:40:04 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_UMINUS ) {
2018-12-18 16:01:22 +01:00
cell = module - > addNeg ( inst_name , IN , OUT , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2014-03-09 20:40:04 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_EQUAL ) {
2018-12-18 16:01:22 +01:00
cell = module - > addEq ( inst_name , IN1 , IN2 , net_map_at ( inst - > GetOutput ( ) ) , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2017-02-04 13:36:00 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_NEQUAL ) {
2018-12-18 16:01:22 +01:00
cell = module - > addNe ( inst_name , IN1 , IN2 , net_map_at ( inst - > GetOutput ( ) ) , SIGNED ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2015-11-16 12:38:56 +01:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_WIDE_MUX ) {
2018-12-18 16:01:22 +01:00
cell = module - > addMux ( inst_name , IN1 , IN2 , net_map_at ( inst - > GetControl ( ) ) , OUT ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2017-02-04 13:36:00 +01:00
2018-02-26 15:02:03 +01:00
if ( inst - > Type ( ) = = OPER_NTO1MUX ) {
2022-02-02 16:16:08 +01:00
cell = module - > addBmux ( inst_name , IN2 , IN1 , net_map_at ( inst - > GetOutput ( ) ) ) ;
2018-12-18 16:01:22 +01:00
import_attributes ( cell - > attributes , inst ) ;
2018-02-26 15:02:03 +01:00
return true ;
}
if ( inst - > Type ( ) = = OPER_WIDE_NTO1MUX )
{
2022-02-02 16:16:08 +01:00
cell = module - > addBmux ( inst_name , IN2 , IN1 , OUT ) ;
2018-12-18 16:01:22 +01:00
import_attributes ( cell - > attributes , inst ) ;
2018-02-26 15:02:03 +01:00
return true ;
}
2018-02-26 15:20:27 +01:00
if ( inst - > Type ( ) = = OPER_SELECTOR )
{
2018-12-18 16:01:22 +01:00
cell = module - > addPmux ( inst_name , State : : S0 , IN2 , IN1 , net_map_at ( inst - > GetOutput ( ) ) ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-26 15:20:27 +01:00
return true ;
}
if ( inst - > Type ( ) = = OPER_WIDE_SELECTOR )
{
SigSpec out = OUT ;
2018-12-18 16:01:22 +01:00
cell = module - > addPmux ( inst_name , SigSpec ( State : : S0 , GetSize ( out ) ) , IN2 , IN1 , out ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-26 15:20:27 +01:00
return true ;
}
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_WIDE_TRI ) {
2018-12-18 16:01:22 +01:00
cell = module - > addMux ( inst_name , RTLIL : : SigSpec ( RTLIL : : State : : Sz , inst - > OutputSize ( ) ) , IN , net_map_at ( inst - > GetControl ( ) ) , OUT ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-02-18 13:52:49 +01:00
return true ;
}
2015-11-16 12:38:56 +01:00
2018-03-04 13:48:53 +01:00
if ( inst - > Type ( ) = = OPER_WIDE_DFFRS )
{
VerificClocking clocking ( this , inst - > GetClock ( ) ) ;
log_assert ( clocking . disable_sig = = State : : S0 ) ;
log_assert ( clocking . body_net = = nullptr ) ;
2018-02-18 13:52:49 +01:00
RTLIL : : SigSpec sig_set = operatorInport ( inst , " set " ) ;
RTLIL : : SigSpec sig_reset = operatorInport ( inst , " reset " ) ;
2018-03-04 13:48:53 +01:00
2018-02-18 13:52:49 +01:00
if ( sig_set . is_fully_const ( ) & & ! sig_set . as_bool ( ) & & sig_reset . is_fully_const ( ) & & ! sig_reset . as_bool ( ) )
2018-12-18 16:01:22 +01:00
cell = clocking . addDff ( inst_name , IN , OUT ) ;
2018-02-18 13:52:49 +01:00
else
2018-12-18 16:01:22 +01:00
cell = clocking . addDffsr ( inst_name , sig_set , sig_reset , IN , OUT ) ;
import_attributes ( cell - > attributes , inst ) ;
2018-03-04 13:48:53 +01:00
2018-02-18 13:52:49 +01:00
return true ;
}
2017-02-04 13:36:00 +01:00
2021-10-21 05:42:47 +02:00
if ( inst - > Type ( ) = = OPER_WIDE_DLATCHRS )
{
RTLIL : : SigSpec sig_set = operatorInport ( inst , " set " ) ;
RTLIL : : SigSpec sig_reset = operatorInport ( inst , " reset " ) ;
if ( sig_set . is_fully_const ( ) & & ! sig_set . as_bool ( ) & & sig_reset . is_fully_const ( ) & & ! sig_reset . as_bool ( ) )
cell = module - > addDlatch ( inst_name , net_map_at ( inst - > GetControl ( ) ) , IN , OUT ) ;
else
cell = module - > addDlatchsr ( inst_name , net_map_at ( inst - > GetControl ( ) ) , sig_set , sig_reset , IN , OUT ) ;
import_attributes ( cell - > attributes , inst ) ;
return true ;
}
2021-10-08 17:24:45 +02:00
2021-10-08 16:21:25 +02:00
if ( inst - > Type ( ) = = OPER_WIDE_DFF )
{
VerificClocking clocking ( this , inst - > GetClock ( ) ) ;
log_assert ( clocking . disable_sig = = State : : S0 ) ;
log_assert ( clocking . body_net = = nullptr ) ;
RTLIL : : SigSpec sig_d = IN ;
RTLIL : : SigSpec sig_q = OUT ;
RTLIL : : SigSpec sig_adata = IN1 ;
RTLIL : : SigSpec sig_acond = IN2 ;
if ( sig_acond . is_fully_const ( ) & & ! sig_acond . as_bool ( ) ) {
cell = clocking . addDff ( inst_name , sig_d , sig_q ) ;
import_attributes ( cell - > attributes , inst ) ;
} else {
int offset = 0 , width = 0 ;
for ( offset = 0 ; offset < GetSize ( sig_acond ) ; offset + = width ) {
for ( width = 1 ; offset + width < GetSize ( sig_acond ) ; width + + )
if ( sig_acond [ offset ] ! = sig_acond [ offset + width ] ) break ;
2021-12-03 09:49:05 +01:00
cell = clocking . addAldff ( module - > uniquify ( inst_name ) , sig_acond [ offset ] , sig_adata . extract ( offset , width ) ,
2021-10-08 16:21:25 +02:00
sig_d . extract ( offset , width ) , sig_q . extract ( offset , width ) ) ;
import_attributes ( cell - > attributes , inst ) ;
}
}
return true ;
}
2021-10-21 05:42:47 +02:00
if ( inst - > Type ( ) = = OPER_WIDE_DLATCH )
{
RTLIL : : SigSpec sig_d = IN ;
RTLIL : : SigSpec sig_q = OUT ;
RTLIL : : SigSpec sig_adata = IN1 ;
RTLIL : : SigSpec sig_acond = IN2 ;
if ( sig_acond . is_fully_const ( ) & & ! sig_acond . as_bool ( ) ) {
cell = module - > addDlatch ( inst_name , net_map_at ( inst - > GetControl ( ) ) , sig_d , sig_q ) ;
import_attributes ( cell - > attributes , inst ) ;
} else {
int offset = 0 , width = 0 ;
for ( offset = 0 ; offset < GetSize ( sig_acond ) ; offset + = width ) {
for ( width = 1 ; offset + width < GetSize ( sig_acond ) ; width + + )
if ( sig_acond [ offset ] ! = sig_acond [ offset + width ] ) break ;
RTLIL : : SigSpec sig_set = module - > Mux ( NEW_ID , RTLIL : : SigSpec ( 0 , width ) , sig_adata . extract ( offset , width ) , sig_acond [ offset ] ) ;
RTLIL : : SigSpec sig_clr = module - > Mux ( NEW_ID , RTLIL : : SigSpec ( 0 , width ) , module - > Not ( NEW_ID , sig_adata . extract ( offset , width ) ) , sig_acond [ offset ] ) ;
2021-12-03 09:49:05 +01:00
cell = module - > addDlatchsr ( module - > uniquify ( inst_name ) , net_map_at ( inst - > GetControl ( ) ) , sig_set , sig_clr ,
2021-10-21 05:42:47 +02:00
sig_d . extract ( offset , width ) , sig_q . extract ( offset , width ) ) ;
import_attributes ( cell - > attributes , inst ) ;
}
}
return true ;
}
2021-10-08 17:24:45 +02:00
2023-02-06 09:28:23 +01:00
if ( inst - > Type ( ) = = OPER_WIDE_CASE_SELECT_BOX )
{
RTLIL : : SigSpec sig_out_val = operatorInport ( inst , " out_value " ) ;
RTLIL : : SigSpec sig_select = operatorInport ( inst , " select " ) ;
2023-02-08 09:22:48 +01:00
RTLIL : : SigSpec sig_select_values = operatorInportCase ( inst , " select_values " ) ;
2023-02-06 09:28:23 +01:00
RTLIL : : SigSpec sig_data_values = operatorInport ( inst , " data_values " ) ;
RTLIL : : SigSpec sig_data_default = operatorInport ( inst , " default_value " ) ;
RTLIL : : Process * proc = module - > addProcess ( new_verific_id ( inst ) ) ;
import_attributes ( proc - > attributes , inst ) ;
RTLIL : : CaseRule * current_case = & proc - > root_case ;
current_case = & proc - > root_case ;
RTLIL : : SwitchRule * sw = new RTLIL : : SwitchRule ;
sw - > signal = sig_select ;
current_case - > switches . push_back ( sw ) ;
2023-02-17 09:45:41 +01:00
unsigned select_width = inst - > InputSize ( ) ;
unsigned data_width = inst - > OutputSize ( ) ;
unsigned offset_data = 0 ;
unsigned offset_select = 0 ;
OperWideCaseSelector * selector = ( OperWideCaseSelector * ) inst - > View ( ) ;
for ( unsigned i = 0 ; i < selector - > GetNumBranches ( ) ; + + i ) {
SigSig action ( sig_out_val , sig_data_values . extract ( offset_data , data_width ) ) ;
2023-02-06 09:28:23 +01:00
offset_data + = data_width ;
2023-02-17 09:45:41 +01:00
for ( unsigned j = 0 ; j < selector - > GetNumConditions ( i ) ; + + j ) {
Array left_bound , right_bound ;
selector - > GetCondition ( i , j , & left_bound , & right_bound ) ;
SigSpec sel_left = sig_select_values . extract ( offset_select , select_width ) ;
offset_select + = select_width ;
if ( right_bound . Size ( ) ) {
SigSpec sel_right = sig_select_values . extract ( offset_select , select_width ) ;
offset_select + = select_width ;
log_assert ( sel_right . is_fully_const ( ) & & sel_right . is_fully_def ( ) ) ;
log_assert ( sel_left . is_fully_const ( ) & & sel_right . is_fully_def ( ) ) ;
int32_t left = sel_left . as_int ( ) ;
int32_t right = sel_right . as_int ( ) ;
int width = sel_left . size ( ) ;
for ( int32_t i = right ; i < left ; i + + ) {
RTLIL : : CaseRule * cs = new RTLIL : : CaseRule ;
cs - > compare . push_back ( RTLIL : : Const ( i , width ) ) ;
cs - > actions . push_back ( action ) ;
sw - > cases . push_back ( cs ) ;
}
}
RTLIL : : CaseRule * cs = new RTLIL : : CaseRule ;
cs - > compare . push_back ( sel_left ) ;
cs - > actions . push_back ( action ) ;
sw - > cases . push_back ( cs ) ;
}
2023-02-06 09:28:23 +01:00
}
RTLIL : : CaseRule * cs_default = new RTLIL : : CaseRule ;
cs_default - > actions . push_back ( SigSig ( sig_out_val , sig_data_default ) ) ;
sw - > cases . push_back ( cs_default ) ;
return true ;
}
2024-05-21 17:08:07 +02:00
# ifdef YOSYSHQ_VERIFIC_API_VERSION
2023-06-07 10:20:16 +02:00
if ( inst - > Type ( ) = = OPER_YOSYSHQ_SET_TAG )
{
RTLIL : : SigSpec sig_expr = operatorInport ( inst , " expr " ) ;
RTLIL : : SigSpec sig_set_mask = operatorInport ( inst , " set_mask " ) ;
RTLIL : : SigSpec sig_clr_mask = operatorInport ( inst , " clr_mask " ) ;
RTLIL : : SigSpec sig_o = operatorOutput ( inst ) ;
2023-06-21 17:09:28 +02:00
std : : string tag = inst - > GetAtt ( " tag " ) ? verific_unescape ( inst - > GetAttValue ( " tag " ) ) : " " ;
2023-06-07 10:20:16 +02:00
module - > connect ( sig_o , module - > SetTag ( new_verific_id ( inst ) , tag , sig_expr , sig_set_mask , sig_clr_mask ) ) ;
return true ;
}
if ( inst - > Type ( ) = = OPER_YOSYSHQ_GET_TAG )
{
2023-06-21 17:09:28 +02:00
std : : string tag = inst - > GetAtt ( " tag " ) ? verific_unescape ( inst - > GetAttValue ( " tag " ) ) : " " ;
2023-06-07 10:20:16 +02:00
module - > connect ( operatorOutput ( inst ) , module - > GetTag ( new_verific_id ( inst ) , tag , operatorInput ( inst ) ) ) ;
return true ;
}
if ( inst - > Type ( ) = = OPER_YOSYSHQ_OVERWRITE_TAG )
{
RTLIL : : SigSpec sig_signal = operatorInport ( inst , " signal " ) ;
RTLIL : : SigSpec sig_set_mask = operatorInport ( inst , " set_mask " ) ;
RTLIL : : SigSpec sig_clr_mask = operatorInport ( inst , " clr_mask " ) ;
2023-06-21 17:09:28 +02:00
std : : string tag = inst - > GetAtt ( " tag " ) ? verific_unescape ( inst - > GetAttValue ( " tag " ) ) : " " ;
2023-06-07 10:20:16 +02:00
module - > addOverwriteTag ( new_verific_id ( inst ) , tag , sig_signal , sig_set_mask , sig_clr_mask ) ;
return true ;
}
if ( inst - > Type ( ) = = OPER_YOSYSHQ_ORIGINAL_TAG )
{
2023-06-21 17:09:28 +02:00
std : : string tag = inst - > GetAtt ( " tag " ) ? verific_unescape ( inst - > GetAttValue ( " tag " ) ) : " " ;
2023-06-07 10:20:16 +02:00
module - > connect ( operatorOutput ( inst ) , module - > OriginalTag ( new_verific_id ( inst ) , tag , operatorInput ( inst ) ) ) ;
return true ;
}
2023-08-24 11:55:30 +02:00
if ( inst - > Type ( ) = = OPER_YOSYSHQ_FUTURE_FF )
{
module - > connect ( operatorOutput ( inst ) , module - > FutureFF ( new_verific_id ( inst ) , operatorInput ( inst ) ) ) ;
return true ;
}
2024-05-21 17:08:07 +02:00
# endif
2023-06-07 10:20:16 +02:00
2018-02-18 13:52:49 +01:00
# undef IN
# undef IN1
# undef IN2
# undef OUT
# undef SIGNED
2017-02-04 13:36:00 +01:00
2018-02-18 13:52:49 +01:00
return false ;
}
2017-07-26 18:00:01 +02:00
2018-02-18 13:52:49 +01:00
void VerificImporter : : merge_past_ffs_clock ( pool < RTLIL : : Cell * > & candidates , SigBit clock , bool clock_pol )
{
bool keep_running = true ;
SigMap sigmap ;
2017-07-26 18:00:01 +02:00
2018-02-18 13:52:49 +01:00
while ( keep_running )
{
keep_running = false ;
2017-07-26 18:00:01 +02:00
2018-02-18 13:52:49 +01:00
dict < SigBit , pool < RTLIL : : Cell * > > dbits_db ;
SigSpec dbits ;
2017-12-10 00:59:44 +01:00
2018-02-18 13:52:49 +01:00
for ( auto cell : candidates ) {
2020-04-02 18:51:32 +02:00
SigBit bit = sigmap ( cell - > getPort ( ID : : D ) ) ;
2018-02-18 13:52:49 +01:00
dbits_db [ bit ] . insert ( cell ) ;
dbits . append ( bit ) ;
}
2017-12-10 00:59:44 +01:00
2018-02-18 13:52:49 +01:00
dbits . sort_and_unify ( ) ;
2017-12-10 00:59:44 +01:00
2018-02-18 13:52:49 +01:00
for ( auto chunk : dbits . chunks ( ) )
{
SigSpec sig_d = chunk ;
2017-12-10 00:59:44 +01:00
2018-02-18 13:52:49 +01:00
if ( chunk . wire = = nullptr | | GetSize ( sig_d ) = = 1 )
continue ;
2018-02-01 12:51:49 +01:00
2018-02-18 13:52:49 +01:00
SigSpec sig_q = module - > addWire ( NEW_ID , GetSize ( sig_d ) ) ;
RTLIL : : Cell * new_ff = module - > addDff ( NEW_ID , clock , sig_d , sig_q , clock_pol ) ;
2018-02-01 12:51:49 +01:00
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2018-02-18 13:52:49 +01:00
log ( " merging single-bit past_ffs into new %d-bit ff %s. \n " , GetSize ( sig_d ) , log_id ( new_ff ) ) ;
2018-02-01 12:51:49 +01:00
2018-02-18 13:52:49 +01:00
for ( int i = 0 ; i < GetSize ( sig_d ) ; i + + )
for ( auto old_ff : dbits_db [ sig_d [ i ] ] )
{
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2018-02-18 13:52:49 +01:00
log ( " replacing old ff %s on bit %d. \n " , log_id ( old_ff ) , i ) ;
2018-02-01 12:51:49 +01:00
2020-04-02 18:51:32 +02:00
SigBit old_q = old_ff - > getPort ( ID : : Q ) ;
2018-02-18 13:52:49 +01:00
SigBit new_q = sig_q [ i ] ;
2018-02-01 12:51:49 +01:00
2018-02-18 13:52:49 +01:00
sigmap . add ( old_q , new_q ) ;
module - > connect ( old_q , new_q ) ;
candidates . erase ( old_ff ) ;
module - > remove ( old_ff ) ;
keep_running = true ;
2017-12-10 00:59:44 +01:00
}
2018-02-18 13:52:49 +01:00
}
}
}
2017-12-10 00:59:44 +01:00
2018-02-18 13:52:49 +01:00
void VerificImporter : : merge_past_ffs ( pool < RTLIL : : Cell * > & candidates )
{
dict < pair < SigBit , int > , pool < RTLIL : : Cell * > > database ;
2017-12-10 00:59:44 +01:00
2018-02-18 13:52:49 +01:00
for ( auto cell : candidates )
{
2022-04-29 14:35:02 +02:00
if ( cell - > type ! = ID ( $ dff ) ) continue ;
2020-04-02 18:51:32 +02:00
SigBit clock = cell - > getPort ( ID : : CLK ) ;
bool clock_pol = cell - > getParam ( ID : : CLK_POLARITY ) . as_bool ( ) ;
2018-02-18 13:52:49 +01:00
database [ make_pair ( clock , int ( clock_pol ) ) ] . insert ( cell ) ;
}
2017-12-10 00:59:44 +01:00
2018-02-18 13:52:49 +01:00
for ( auto it : database )
merge_past_ffs_clock ( it . second , it . first . first , it . first . second ) ;
}
2017-07-27 11:40:07 +02:00
2020-09-30 09:16:59 +02:00
static std : : string sha1_if_contain_spaces ( std : : string str )
{
if ( str . find_first_of ( ' ' ) ! = std : : string : : npos ) {
std : : size_t open = str . find_first_of ( ' ( ' ) ;
std : : size_t closed = str . find_last_of ( ' ) ' ) ;
if ( open ! = std : : string : : npos & & closed ! = std : : string : : npos ) {
std : : string content = str . substr ( open + 1 , closed - open - 1 ) ;
return str . substr ( 0 , open + 1 ) + sha1 ( content ) + str . substr ( closed ) ;
} else {
return sha1 ( str ) ;
}
}
return str ;
}
2022-03-25 13:44:16 +01:00
void VerificImporter : : import_netlist ( RTLIL : : Design * design , Netlist * nl , std : : map < std : : string , Netlist * > & nl_todo , bool norename )
2018-02-18 13:52:49 +01:00
{
2023-07-24 12:41:57 +02:00
std : : string netlist_name = nl - > GetAtt ( " \\ top " ) | | is_blackbox ( nl ) ? nl - > CellBaseName ( ) : nl - > Owner ( ) - > Name ( ) ;
2019-10-24 12:13:37 +02:00
std : : string module_name = netlist_name ;
2019-11-22 16:00:07 +01:00
if ( nl - > IsOperator ( ) | | nl - > IsPrimitive ( ) ) {
2019-10-24 12:13:37 +02:00
module_name = " $verific$ " + module_name ;
} else {
2023-07-24 12:41:57 +02:00
if ( ! norename & & * nl - > Name ( ) & & ! is_blackbox ( nl ) ) {
2019-10-24 12:13:37 +02:00
module_name + = " ( " ;
module_name + = nl - > Name ( ) ;
module_name + = " ) " ;
}
2020-09-30 09:16:59 +02:00
module_name = " \\ " + sha1_if_contain_spaces ( module_name ) ;
2019-10-24 12:13:37 +02:00
}
2017-07-27 11:40:07 +02:00
2025-04-14 15:24:11 +02:00
{
Array ram_nets ;
MapIter mem_mi ;
Net * mem_net ;
FOREACH_NET_OF_NETLIST ( nl , mem_mi , mem_net )
{
if ( ! mem_net - > IsRamNet ( ) ) continue ;
if ( mem_net - > GetAtt ( " mem2reg " ) )
ram_nets . Insert ( mem_net ) ;
}
unsigned i ;
FOREACH_ARRAY_ITEM ( & ram_nets , i , mem_net ) {
log ( " Bit blasting RAM for identifier '%s' \n " , mem_net - > Name ( ) ) ;
mem_net - > BlastNet ( ) ;
}
nl - > RemoveDanglingLogic ( 0 ) ;
}
2018-02-18 13:52:49 +01:00
netlist = nl ;
2017-07-27 11:40:07 +02:00
2018-02-18 13:52:49 +01:00
if ( design - > has ( module_name ) ) {
2018-10-07 19:48:42 +02:00
if ( ! nl - > IsOperator ( ) & & ! is_blackbox ( nl ) )
2025-09-17 00:59:08 +02:00
log_cmd_error ( " Re-definition of module `%s'. \n " , netlist_name ) ;
2018-02-18 13:52:49 +01:00
return ;
}
2017-07-27 11:40:07 +02:00
2018-02-18 13:52:49 +01:00
module = new RTLIL : : Module ;
module - > name = module_name ;
design - > add ( module ) ;
2017-07-27 11:40:07 +02:00
2018-10-07 19:48:42 +02:00
if ( is_blackbox ( nl ) ) {
2018-02-18 13:52:49 +01:00
log ( " Importing blackbox module %s. \n " , RTLIL : : id2cstr ( module - > name ) ) ;
2020-04-02 18:51:32 +02:00
module - > set_bool_attribute ( ID : : blackbox ) ;
2018-02-18 13:52:49 +01:00
} else {
log ( " Importing module %s. \n " , RTLIL : : id2cstr ( module - > name ) ) ;
}
2021-10-10 10:01:45 +02:00
import_attributes ( module - > attributes , nl , nl ) ;
2025-01-15 15:56:42 +01:00
if ( module - > name . isPublic ( ) )
module - > set_string_attribute ( ID : : hdlname , nl - > CellBaseName ( ) ) ;
2024-04-15 17:01:07 +02:00
module - > set_string_attribute ( ID ( library ) , nl - > Owner ( ) - > Owner ( ) - > Name ( ) ) ;
2023-10-12 09:17:06 +02:00
# ifdef VERIFIC_VHDL_SUPPORT
if ( nl - > IsFromVhdl ( ) ) {
NameSpace name_space ( 0 ) ;
char * architecture_name = name_space . ReName ( nl - > Name ( ) ) ;
module - > set_string_attribute ( ID ( architecture ) , ( architecture_name ) ? architecture_name : nl - > Name ( ) ) ;
}
# endif
2023-09-27 16:57:18 +02:00
const char * param_name ;
const char * param_value ;
MapIter mi ;
FOREACH_PARAMETER_OF_NETLIST ( nl , mi , param_name , param_value ) {
module - > avail_parameters ( RTLIL : : escape_id ( param_name ) ) ;
2024-03-14 10:37:11 +01:00
const TypeRange * tr = nl - > GetTypeRange ( param_name ) ;
2024-12-02 15:45:12 +01:00
const char * type_name = ( tr ) ? tr - > GetTypeName ( ) : nullptr ;
module - > parameter_default_values [ RTLIL : : escape_id ( param_name ) ] = verific_const ( type_name , param_value , nl ) ;
2023-09-27 16:57:18 +02:00
}
2017-07-26 18:00:01 +02:00
2018-02-18 13:52:49 +01:00
SetIter si ;
2023-09-27 16:57:18 +02:00
MapIter mi2 ;
2018-02-18 13:52:49 +01:00
Port * port ;
PortBus * portbus ;
Net * net ;
NetBus * netbus ;
Instance * inst ;
PortRef * pr ;
2022-12-15 08:17:53 +01:00
Att * attr ;
FOREACH_ATTRIBUTE ( nl , mi , attr ) {
if ( ! strcmp ( attr - > Key ( ) , " noblackbox " ) )
module - > set_bool_attribute ( ID : : blackbox , false ) ;
}
2017-10-04 18:56:28 +02:00
2018-02-18 13:52:49 +01:00
FOREACH_PORT_OF_NETLIST ( nl , mi , port )
{
if ( port - > Bus ( ) )
continue ;
2017-02-04 13:36:00 +01:00
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2018-02-18 13:52:49 +01:00
log ( " importing port %s. \n " , port - > Name ( ) ) ;
2017-07-24 11:29:06 +02:00
2018-02-18 13:52:49 +01:00
RTLIL : : Wire * wire = module - > addWire ( RTLIL : : escape_id ( port - > Name ( ) ) ) ;
2024-12-12 11:42:39 +01:00
import_attributes ( wire - > attributes , port , nl , 1 ) ;
2017-07-26 18:00:01 +02:00
2018-02-18 13:52:49 +01:00
wire - > port_id = nl - > IndexOf ( port ) + 1 ;
2017-07-26 18:00:01 +02:00
2018-02-18 13:52:49 +01:00
if ( port - > GetDir ( ) = = DIR_INOUT | | port - > GetDir ( ) = = DIR_IN )
wire - > port_input = true ;
if ( port - > GetDir ( ) = = DIR_INOUT | | port - > GetDir ( ) = = DIR_OUT )
wire - > port_output = true ;
2017-07-26 18:00:01 +02:00
2018-02-18 13:52:49 +01:00
if ( port - > GetNet ( ) ) {
net = port - > GetNet ( ) ;
if ( net_map . count ( net ) = = 0 )
net_map [ net ] = wire ;
else if ( wire - > port_input )
module - > connect ( net_map_at ( net ) , wire ) ;
else
module - > connect ( wire , net_map_at ( net ) ) ;
}
}
2017-07-29 00:07:02 +02:00
2018-02-18 13:52:49 +01:00
FOREACH_PORTBUS_OF_NETLIST ( nl , mi , portbus )
{
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2018-02-18 13:52:49 +01:00
log ( " importing portbus %s. \n " , portbus - > Name ( ) ) ;
RTLIL : : Wire * wire = module - > addWire ( RTLIL : : escape_id ( portbus - > Name ( ) ) , portbus - > Size ( ) ) ;
wire - > start_offset = min ( portbus - > LeftIndex ( ) , portbus - > RightIndex ( ) ) ;
2022-07-29 17:10:31 +02:00
wire - > upto = portbus - > IsUp ( ) ;
2024-12-12 11:42:39 +01:00
import_attributes ( wire - > attributes , portbus , nl , portbus - > Size ( ) ) ;
2025-05-12 13:23:02 +02:00
if ( portbus - > Size ( ) = = 1 )
wire - > set_bool_attribute ( ID : : single_bit_vector ) ;
2023-10-20 18:31:41 +02:00
SetIter si ;
Port * port ;
FOREACH_PORT_OF_PORTBUS ( portbus , si , port ) {
2025-10-23 22:46:11 +02:00
wire - > port_id = nl - > IndexOf ( port ) + 1 ;
2024-12-12 11:42:39 +01:00
import_attributes ( wire - > attributes , port - > GetNet ( ) , nl , portbus - > Size ( ) ) ;
2023-10-20 18:31:41 +02:00
break ;
}
2021-12-10 14:27:18 +01:00
bool portbus_input = portbus - > GetDir ( ) = = DIR_INOUT | | portbus - > GetDir ( ) = = DIR_IN ;
if ( portbus_input )
2018-02-18 13:52:49 +01:00
wire - > port_input = true ;
if ( portbus - > GetDir ( ) = = DIR_INOUT | | portbus - > GetDir ( ) = = DIR_OUT )
wire - > port_output = true ;
for ( int i = portbus - > LeftIndex ( ) ; ; i + = portbus - > IsUp ( ) ? + 1 : - 1 ) {
if ( portbus - > ElementAtIndex ( i ) & & portbus - > ElementAtIndex ( i ) - > GetNet ( ) ) {
2021-12-10 14:27:18 +01:00
bool bit_input = portbus_input ;
if ( portbus - > GetDir ( ) = = DIR_NONE ) {
2021-12-08 11:50:10 +01:00
Port * p = portbus - > ElementAtIndex ( i ) ;
2021-12-10 14:27:18 +01:00
bit_input = p - > GetDir ( ) = = DIR_INOUT | | p - > GetDir ( ) = = DIR_IN ;
if ( bit_input )
2021-12-08 11:50:10 +01:00
wire - > port_input = true ;
if ( p - > GetDir ( ) = = DIR_INOUT | | p - > GetDir ( ) = = DIR_OUT )
wire - > port_output = true ;
}
2018-02-18 13:52:49 +01:00
net = portbus - > ElementAtIndex ( i ) - > GetNet ( ) ;
2022-07-29 17:10:31 +02:00
int bitidx = wire - > upto ? ( wire - > width - 1 - ( i - wire - > start_offset ) ) : ( i - wire - > start_offset ) ;
RTLIL : : SigBit bit ( wire , bitidx ) ;
2018-02-18 13:52:49 +01:00
if ( net_map . count ( net ) = = 0 )
net_map [ net ] = bit ;
2021-12-10 14:27:18 +01:00
else if ( bit_input )
2018-02-18 13:52:49 +01:00
module - > connect ( net_map_at ( net ) , bit ) ;
else
module - > connect ( bit , net_map_at ( net ) ) ;
}
if ( i = = portbus - > RightIndex ( ) )
break ;
2017-07-27 11:54:45 +02:00
}
2014-03-09 20:40:04 +01:00
}
2018-02-18 13:52:49 +01:00
module - > fixup_ports ( ) ;
2017-07-27 11:40:07 +02:00
2024-10-01 15:12:03 +02:00
dict < Net * , char > init_nets ;
pool < Net * > anyconst_nets , anyseq_nets ;
pool < Net * > allconst_nets , allseq_nets ;
2018-05-24 17:07:06 +02:00
any_all_nets . clear ( ) ;
2018-02-18 13:52:49 +01:00
FOREACH_NET_OF_NETLIST ( nl , mi , net )
2017-07-28 17:37:09 +02:00
{
2018-02-18 13:52:49 +01:00
if ( net - > IsRamNet ( ) )
{
RTLIL : : Memory * memory = new RTLIL : : Memory ;
memory - > name = RTLIL : : escape_id ( net - > Name ( ) ) ;
log_assert ( module - > count_id ( memory - > name ) = = 0 ) ;
module - > memories [ memory - > name ] = memory ;
2022-09-21 15:48:40 +02:00
import_attributes ( memory - > attributes , net , nl ) ;
2018-02-18 13:52:49 +01:00
int number_of_bits = net - > Size ( ) ;
int bits_in_word = number_of_bits ;
FOREACH_PORTREF_OF_NET ( net , si , pr ) {
if ( pr - > GetInst ( ) - > Type ( ) = = OPER_READ_PORT ) {
bits_in_word = min < int > ( bits_in_word , pr - > GetInst ( ) - > OutputSize ( ) ) ;
continue ;
}
if ( pr - > GetInst ( ) - > Type ( ) = = OPER_WRITE_PORT | | pr - > GetInst ( ) - > Type ( ) = = OPER_CLOCKED_WRITE_PORT ) {
bits_in_word = min < int > ( bits_in_word , pr - > GetInst ( ) - > Input2Size ( ) ) ;
continue ;
}
2025-10-03 12:57:49 +02:00
log_error ( " %sVerific RamNet %s is connected to unsupported instance type %s (%s). \n " , announce_src_location ( pr - > GetInst ( ) ) ,
2018-02-18 13:52:49 +01:00
net - > Name ( ) , pr - > GetInst ( ) - > View ( ) - > Owner ( ) - > Name ( ) , pr - > GetInst ( ) - > Name ( ) ) ;
}
2017-07-28 17:37:09 +02:00
2018-02-18 13:52:49 +01:00
memory - > width = bits_in_word ;
memory - > size = number_of_bits / bits_in_word ;
const char * ascii_initdata = net - > GetWideInitialValue ( ) ;
if ( ascii_initdata ) {
while ( * ascii_initdata ! = 0 & & * ascii_initdata ! = ' \' ' )
ascii_initdata + + ;
if ( * ascii_initdata = = ' \' ' )
ascii_initdata + + ;
if ( * ascii_initdata ! = 0 ) {
log_assert ( * ascii_initdata = = ' b ' ) ;
ascii_initdata + + ;
}
for ( int word_idx = 0 ; word_idx < memory - > size ; word_idx + + ) {
Const initval = Const ( State : : Sx , memory - > width ) ;
bool initval_valid = false ;
for ( int bit_idx = memory - > width - 1 ; bit_idx > = 0 ; bit_idx - - ) {
if ( * ascii_initdata = = 0 )
break ;
if ( * ascii_initdata = = ' 0 ' | | * ascii_initdata = = ' 1 ' ) {
2025-10-13 09:47:18 +02:00
initval . set ( bit_idx , ( * ascii_initdata = = ' 0 ' ) ? State : : S0 : State : : S1 ) ;
2018-02-18 13:52:49 +01:00
initval_valid = true ;
}
ascii_initdata + + ;
}
if ( initval_valid ) {
2020-04-02 18:51:32 +02:00
RTLIL : : Cell * cell = module - > addCell ( new_verific_id ( net ) , ID ( $ meminit ) ) ;
cell - > parameters [ ID : : WORDS ] = 1 ;
2018-02-18 13:52:49 +01:00
if ( net - > GetOrigTypeRange ( ) - > LeftRangeBound ( ) < net - > GetOrigTypeRange ( ) - > RightRangeBound ( ) )
2020-04-02 18:51:32 +02:00
cell - > setPort ( ID : : ADDR , word_idx ) ;
2018-02-18 13:52:49 +01:00
else
2020-04-02 18:51:32 +02:00
cell - > setPort ( ID : : ADDR , memory - > size - word_idx - 1 ) ;
cell - > setPort ( ID : : DATA , initval ) ;
cell - > parameters [ ID : : MEMID ] = RTLIL : : Const ( memory - > name . str ( ) ) ;
cell - > parameters [ ID : : ABITS ] = 32 ;
cell - > parameters [ ID : : WIDTH ] = memory - > width ;
cell - > parameters [ ID : : PRIORITY ] = RTLIL : : Const ( autoidx - 1 ) ;
2018-02-18 13:52:49 +01:00
}
}
}
continue ;
2017-07-28 17:37:09 +02:00
}
2017-07-27 11:40:07 +02:00
2018-02-18 13:52:49 +01:00
if ( net - > GetInitialValue ( ) )
init_nets [ net ] = net - > GetInitialValue ( ) ;
2017-07-27 11:40:07 +02:00
2018-02-18 13:52:49 +01:00
const char * rand_const_attr = net - > GetAttValue ( " rand_const " ) ;
const char * rand_attr = net - > GetAttValue ( " rand " ) ;
2017-10-10 15:16:39 +02:00
2018-04-06 14:19:55 +02:00
const char * anyconst_attr = net - > GetAttValue ( " anyconst " ) ;
const char * anyseq_attr = net - > GetAttValue ( " anyseq " ) ;
const char * allconst_attr = net - > GetAttValue ( " allconst " ) ;
const char * allseq_attr = net - > GetAttValue ( " allseq " ) ;
2018-05-24 17:07:06 +02:00
if ( rand_const_attr ! = nullptr & & ( ! strcmp ( rand_const_attr , " 1 " ) | | ! strcmp ( rand_const_attr , " '1' " ) ) ) {
2018-02-18 13:52:49 +01:00
anyconst_nets . insert ( net ) ;
2018-05-24 17:07:06 +02:00
any_all_nets . insert ( net ) ;
}
else if ( rand_attr ! = nullptr & & ( ! strcmp ( rand_attr , " 1 " ) | | ! strcmp ( rand_attr , " '1' " ) ) ) {
2018-02-18 13:52:49 +01:00
anyseq_nets . insert ( net ) ;
2018-05-24 17:07:06 +02:00
any_all_nets . insert ( net ) ;
}
else if ( anyconst_attr ! = nullptr & & ( ! strcmp ( anyconst_attr , " 1 " ) | | ! strcmp ( anyconst_attr , " '1' " ) ) ) {
2018-04-06 14:19:55 +02:00
anyconst_nets . insert ( net ) ;
2018-05-24 17:07:06 +02:00
any_all_nets . insert ( net ) ;
}
else if ( anyseq_attr ! = nullptr & & ( ! strcmp ( anyseq_attr , " 1 " ) | | ! strcmp ( anyseq_attr , " '1' " ) ) ) {
2018-04-06 14:19:55 +02:00
anyseq_nets . insert ( net ) ;
2018-05-24 17:07:06 +02:00
any_all_nets . insert ( net ) ;
}
else if ( allconst_attr ! = nullptr & & ( ! strcmp ( allconst_attr , " 1 " ) | | ! strcmp ( allconst_attr , " '1' " ) ) ) {
2018-04-06 14:19:55 +02:00
allconst_nets . insert ( net ) ;
2018-05-24 17:07:06 +02:00
any_all_nets . insert ( net ) ;
}
else if ( allseq_attr ! = nullptr & & ( ! strcmp ( allseq_attr , " 1 " ) | | ! strcmp ( allseq_attr , " '1' " ) ) ) {
2018-04-06 14:19:55 +02:00
allseq_nets . insert ( net ) ;
2018-05-24 17:07:06 +02:00
any_all_nets . insert ( net ) ;
}
2018-04-06 14:19:55 +02:00
2018-02-18 13:52:49 +01:00
if ( net_map . count ( net ) ) {
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2018-02-18 13:52:49 +01:00
log ( " skipping net %s. \n " , net - > Name ( ) ) ;
continue ;
}
2018-02-18 13:28:08 +01:00
2018-02-18 13:52:49 +01:00
if ( net - > Bus ( ) )
continue ;
2018-02-18 13:28:08 +01:00
2018-12-18 16:01:22 +01:00
RTLIL : : IdString wire_name = module - > uniquify ( mode_names | | net - > IsUserDeclared ( ) ? RTLIL : : escape_id ( net - > Name ( ) ) : new_verific_id ( net ) ) ;
2017-10-10 15:16:39 +02:00
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2018-02-18 13:52:49 +01:00
log ( " importing net %s as %s. \n " , net - > Name ( ) , log_id ( wire_name ) ) ;
2017-10-10 15:16:39 +02:00
2018-02-18 13:52:49 +01:00
RTLIL : : Wire * wire = module - > addWire ( wire_name ) ;
2024-12-12 11:42:39 +01:00
import_attributes ( wire - > attributes , net , nl , 1 ) ;
2017-10-10 15:16:39 +02:00
2018-02-18 13:52:49 +01:00
net_map [ net ] = wire ;
}
2017-10-10 15:16:39 +02:00
2018-02-18 13:52:49 +01:00
FOREACH_NETBUS_OF_NETLIST ( nl , mi , netbus )
{
bool found_new_net = false ;
for ( int i = netbus - > LeftIndex ( ) ; ; i + = netbus - > IsUp ( ) ? + 1 : - 1 ) {
net = netbus - > ElementAtIndex ( i ) ;
if ( net_map . count ( net ) = = 0 )
found_new_net = true ;
if ( i = = netbus - > RightIndex ( ) )
break ;
}
2017-10-10 15:16:39 +02:00
2018-02-18 13:52:49 +01:00
if ( found_new_net )
{
2018-12-18 16:01:22 +01:00
RTLIL : : IdString wire_name = module - > uniquify ( mode_names | | netbus - > IsUserDeclared ( ) ? RTLIL : : escape_id ( netbus - > Name ( ) ) : new_verific_id ( netbus ) ) ;
2017-10-10 15:16:39 +02:00
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2018-02-18 13:52:49 +01:00
log ( " importing netbus %s as %s. \n " , netbus - > Name ( ) , log_id ( wire_name ) ) ;
2017-10-10 15:16:39 +02:00
2018-02-18 13:52:49 +01:00
RTLIL : : Wire * wire = module - > addWire ( wire_name , netbus - > Size ( ) ) ;
wire - > start_offset = min ( netbus - > LeftIndex ( ) , netbus - > RightIndex ( ) ) ;
2022-07-29 17:10:31 +02:00
wire - > upto = netbus - > IsUp ( ) ;
2020-06-24 11:01:06 +02:00
MapIter mibus ;
FOREACH_NET_OF_NETBUS ( netbus , mibus , net ) {
2020-06-26 20:11:01 +02:00
if ( net )
2024-12-12 11:42:39 +01:00
import_attributes ( wire - > attributes , net , nl , netbus - > Size ( ) ) ;
2020-06-25 09:18:53 +02:00
break ;
2020-06-24 11:01:06 +02:00
}
2024-12-12 11:42:39 +01:00
import_attributes ( wire - > attributes , netbus , nl , netbus - > Size ( ) ) ;
2025-05-12 13:23:02 +02:00
if ( netbus - > Size ( ) = = 1 )
wire - > set_bool_attribute ( ID : : single_bit_vector ) ;
2017-10-10 15:16:39 +02:00
2018-02-18 13:52:49 +01:00
RTLIL : : Const initval = Const ( State : : Sx , GetSize ( wire ) ) ;
bool initval_valid = false ;
2017-10-10 15:16:39 +02:00
2018-02-18 13:52:49 +01:00
for ( int i = netbus - > LeftIndex ( ) ; ; i + = netbus - > IsUp ( ) ? + 1 : - 1 )
{
if ( netbus - > ElementAtIndex ( i ) )
{
2022-07-29 17:10:31 +02:00
int bitidx = wire - > upto ? ( wire - > width - 1 - ( i - wire - > start_offset ) ) : ( i - wire - > start_offset ) ;
2018-02-18 13:52:49 +01:00
net = netbus - > ElementAtIndex ( i ) ;
RTLIL : : SigBit bit ( wire , bitidx ) ;
if ( init_nets . count ( net ) ) {
if ( init_nets . at ( net ) = = ' 0 ' )
2025-10-13 09:47:18 +02:00
initval . set ( bitidx , State : : S0 ) ;
2018-02-18 13:52:49 +01:00
if ( init_nets . at ( net ) = = ' 1 ' )
2025-10-13 09:47:18 +02:00
initval . set ( bitidx , State : : S1 ) ;
2018-02-18 13:52:49 +01:00
initval_valid = true ;
init_nets . erase ( net ) ;
}
2018-02-18 13:28:08 +01:00
2018-02-18 13:52:49 +01:00
if ( net_map . count ( net ) = = 0 )
net_map [ net ] = bit ;
else
module - > connect ( bit , net_map_at ( net ) ) ;
}
2017-12-10 01:10:03 +01:00
2018-02-18 13:52:49 +01:00
if ( i = = netbus - > RightIndex ( ) )
break ;
2017-10-10 15:16:39 +02:00
}
2018-02-18 13:52:49 +01:00
if ( initval_valid )
2020-04-02 18:51:32 +02:00
wire - > attributes [ ID : : init ] = initval ;
2017-10-10 15:16:39 +02:00
}
2018-02-18 13:52:49 +01:00
else
2017-10-10 15:16:39 +02:00
{
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2018-02-18 13:52:49 +01:00
log ( " skipping netbus %s. \n " , netbus - > Name ( ) ) ;
2017-12-10 01:10:03 +01:00
}
2018-02-18 13:52:49 +01:00
SigSpec anyconst_sig ;
SigSpec anyseq_sig ;
2018-04-06 14:19:55 +02:00
SigSpec allconst_sig ;
SigSpec allseq_sig ;
2018-02-18 13:52:49 +01:00
for ( int i = netbus - > RightIndex ( ) ; ; i + = netbus - > IsUp ( ) ? - 1 : + 1 ) {
net = netbus - > ElementAtIndex ( i ) ;
if ( net ! = nullptr & & anyconst_nets . count ( net ) ) {
anyconst_sig . append ( net_map_at ( net ) ) ;
anyconst_nets . erase ( net ) ;
2017-12-10 01:10:03 +01:00
}
2018-02-18 13:52:49 +01:00
if ( net ! = nullptr & & anyseq_nets . count ( net ) ) {
anyseq_sig . append ( net_map_at ( net ) ) ;
anyseq_nets . erase ( net ) ;
}
2018-04-06 14:19:55 +02:00
if ( net ! = nullptr & & allconst_nets . count ( net ) ) {
allconst_sig . append ( net_map_at ( net ) ) ;
allconst_nets . erase ( net ) ;
}
if ( net ! = nullptr & & allseq_nets . count ( net ) ) {
allseq_sig . append ( net_map_at ( net ) ) ;
allseq_nets . erase ( net ) ;
}
2018-02-18 13:52:49 +01:00
if ( i = = netbus - > LeftIndex ( ) )
break ;
2017-10-10 15:16:39 +02:00
}
2018-02-18 13:52:49 +01:00
if ( GetSize ( anyconst_sig ) )
2018-12-18 16:01:22 +01:00
module - > connect ( anyconst_sig , module - > Anyconst ( new_verific_id ( netbus ) , GetSize ( anyconst_sig ) ) ) ;
2018-02-18 13:52:49 +01:00
if ( GetSize ( anyseq_sig ) )
2018-12-18 16:01:22 +01:00
module - > connect ( anyseq_sig , module - > Anyseq ( new_verific_id ( netbus ) , GetSize ( anyseq_sig ) ) ) ;
2018-04-06 14:19:55 +02:00
if ( GetSize ( allconst_sig ) )
2018-12-18 16:01:22 +01:00
module - > connect ( allconst_sig , module - > Allconst ( new_verific_id ( netbus ) , GetSize ( allconst_sig ) ) ) ;
2018-04-06 14:19:55 +02:00
if ( GetSize ( allseq_sig ) )
2018-12-18 16:01:22 +01:00
module - > connect ( allseq_sig , module - > Allseq ( new_verific_id ( netbus ) , GetSize ( allseq_sig ) ) ) ;
2017-10-10 15:16:39 +02:00
}
2018-02-18 13:52:49 +01:00
for ( auto it : init_nets )
2017-10-10 15:16:39 +02:00
{
2018-02-18 13:52:49 +01:00
Const initval ;
SigBit bit = net_map_at ( it . first ) ;
log_assert ( bit . wire ) ;
2017-10-10 15:16:39 +02:00
2020-04-02 18:51:32 +02:00
if ( bit . wire - > attributes . count ( ID : : init ) )
initval = bit . wire - > attributes . at ( ID : : init ) ;
2017-07-26 18:00:01 +02:00
2025-10-13 09:57:22 +02:00
if ( GetSize ( initval ) < GetSize ( bit . wire ) )
initval . resize ( GetSize ( bit . wire ) , State : : Sx ) ;
2017-07-27 10:39:39 +02:00
2018-02-18 13:52:49 +01:00
if ( it . second = = ' 0 ' )
2025-10-13 09:47:18 +02:00
initval . set ( bit . offset , State : : S0 ) ;
2018-02-18 13:52:49 +01:00
if ( it . second = = ' 1 ' )
2025-10-13 09:47:18 +02:00
initval . set ( bit . offset , State : : S1 ) ;
2017-07-27 10:39:39 +02:00
2020-04-02 18:51:32 +02:00
bit . wire - > attributes [ ID : : init ] = initval ;
2018-02-18 13:52:49 +01:00
}
2017-07-27 10:39:39 +02:00
2018-02-18 13:52:49 +01:00
for ( auto net : anyconst_nets )
2018-12-18 16:01:22 +01:00
module - > connect ( net_map_at ( net ) , module - > Anyconst ( new_verific_id ( net ) ) ) ;
2017-07-27 10:39:39 +02:00
2018-02-18 13:52:49 +01:00
for ( auto net : anyseq_nets )
2018-12-18 16:01:22 +01:00
module - > connect ( net_map_at ( net ) , module - > Anyseq ( new_verific_id ( net ) ) ) ;
2017-07-27 10:39:39 +02:00
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2024-10-01 15:12:03 +02:00
pool < Instance * > sva_asserts ;
pool < Instance * > sva_assumes ;
pool < Instance * > sva_covers ;
pool < Instance * > sva_triggers ;
2024-06-07 14:58:33 +02:00
# endif
2017-07-27 10:39:39 +02:00
2018-02-18 13:52:49 +01:00
pool < RTLIL : : Cell * > past_ffs ;
2017-07-27 10:39:39 +02:00
2018-02-18 13:52:49 +01:00
FOREACH_INSTANCE_OF_NETLIST ( nl , mi , inst )
2017-07-26 18:00:01 +02:00
{
2018-12-18 16:01:22 +01:00
RTLIL : : IdString inst_name = module - > uniquify ( mode_names | | inst - > IsUserDeclared ( ) ? RTLIL : : escape_id ( inst - > Name ( ) ) : new_verific_id ( inst ) ) ;
2017-07-26 18:00:01 +02:00
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2018-02-18 13:52:49 +01:00
log ( " importing cell %s (%s) as %s. \n " , inst - > Name ( ) , inst - > View ( ) - > Owner ( ) - > Name ( ) , log_id ( inst_name ) ) ;
2017-07-28 17:37:09 +02:00
2018-03-07 19:40:34 +01:00
if ( mode_verific )
goto import_verific_cells ;
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_PWR ) {
module - > connect ( net_map_at ( inst - > GetOutput ( ) ) , RTLIL : : State : : S1 ) ;
continue ;
2017-07-27 10:39:39 +02:00
}
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_GND ) {
module - > connect ( net_map_at ( inst - > GetOutput ( ) ) , RTLIL : : State : : S0 ) ;
continue ;
}
2017-07-28 17:37:09 +02:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_BUF ) {
2018-05-24 17:07:06 +02:00
auto outnet = inst - > GetOutput ( ) ;
2018-05-25 15:41:45 +02:00
if ( ! any_all_nets . count ( outnet ) )
2018-05-24 17:07:06 +02:00
module - > addBufGate ( inst_name , net_map_at ( inst - > GetInput ( ) ) , net_map_at ( outnet ) ) ;
2018-02-18 13:52:49 +01:00
continue ;
2017-07-27 10:39:39 +02:00
}
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_X ) {
module - > connect ( net_map_at ( inst - > GetOutput ( ) ) , RTLIL : : State : : Sx ) ;
continue ;
}
if ( inst - > Type ( ) = = PRIM_Z ) {
module - > connect ( net_map_at ( inst - > GetOutput ( ) ) , RTLIL : : State : : Sz ) ;
continue ;
2017-07-27 10:39:39 +02:00
}
2017-07-26 18:00:01 +02:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = OPER_READ_PORT )
{
2020-06-10 11:27:44 +02:00
RTLIL : : Memory * memory = module - > memories . at ( RTLIL : : escape_id ( inst - > GetInput ( ) - > Name ( ) ) , nullptr ) ;
if ( ! memory )
2025-10-03 12:57:49 +02:00
log_error ( " %sMemory net '%s' missing, possibly no driver, use verific -flatten. \n " , announce_src_location ( inst ) , inst - > GetInput ( ) - > Name ( ) ) ;
2020-06-10 11:27:44 +02:00
2018-03-15 18:20:37 +01:00
int numchunks = int ( inst - > OutputSize ( ) ) / memory - > width ;
int chunksbits = ceil_log2 ( numchunks ) ;
2018-02-18 13:52:49 +01:00
2018-03-15 18:20:37 +01:00
for ( int i = 0 ; i < numchunks ; i + + )
{
RTLIL : : SigSpec addr = { operatorInput1 ( inst ) , RTLIL : : Const ( i , chunksbits ) } ;
RTLIL : : SigSpec data = operatorOutput ( inst ) . extract ( i * memory - > width , memory - > width ) ;
RTLIL : : Cell * cell = module - > addCell ( numchunks = = 1 ? inst_name :
2025-08-20 00:45:26 +02:00
RTLIL : : IdString ( stringf ( " %s_%d " , inst_name , i ) ) , ID ( $ memrd ) ) ;
2020-04-02 18:51:32 +02:00
cell - > parameters [ ID : : MEMID ] = memory - > name . str ( ) ;
cell - > parameters [ ID : : CLK_ENABLE ] = false ;
cell - > parameters [ ID : : CLK_POLARITY ] = true ;
cell - > parameters [ ID : : TRANSPARENT ] = false ;
cell - > parameters [ ID : : ABITS ] = GetSize ( addr ) ;
cell - > parameters [ ID : : WIDTH ] = GetSize ( data ) ;
2023-06-23 19:40:29 +02:00
import_attributes ( cell - > attributes , inst ) ;
2020-04-02 18:51:32 +02:00
cell - > setPort ( ID : : CLK , RTLIL : : State : : Sx ) ;
cell - > setPort ( ID : : EN , RTLIL : : State : : Sx ) ;
cell - > setPort ( ID : : ADDR , addr ) ;
cell - > setPort ( ID : : DATA , data ) ;
2018-03-15 18:20:37 +01:00
}
2018-02-18 13:52:49 +01:00
continue ;
}
if ( inst - > Type ( ) = = OPER_WRITE_PORT | | inst - > Type ( ) = = OPER_CLOCKED_WRITE_PORT )
2017-07-27 14:05:09 +02:00
{
2020-06-10 11:27:44 +02:00
RTLIL : : Memory * memory = module - > memories . at ( RTLIL : : escape_id ( inst - > GetOutput ( ) - > Name ( ) ) , nullptr ) ;
if ( ! memory )
2025-10-03 12:57:49 +02:00
log_error ( " %sMemory net '%s' missing, possibly no driver, use verific -flatten. \n " , announce_src_location ( inst ) , inst - > GetInput ( ) - > Name ( ) ) ;
2019-01-02 15:33:43 +01:00
int numchunks = int ( inst - > Input2Size ( ) ) / memory - > width ;
int chunksbits = ceil_log2 ( numchunks ) ;
for ( int i = 0 ; i < numchunks ; i + + )
{
RTLIL : : SigSpec addr = { operatorInput1 ( inst ) , RTLIL : : Const ( i , chunksbits ) } ;
RTLIL : : SigSpec data = operatorInput2 ( inst ) . extract ( i * memory - > width , memory - > width ) ;
RTLIL : : Cell * cell = module - > addCell ( numchunks = = 1 ? inst_name :
2025-08-20 00:45:26 +02:00
RTLIL : : IdString ( stringf ( " %s_%d " , inst_name , i ) ) , ID ( $ memwr ) ) ;
2020-04-02 18:51:32 +02:00
cell - > parameters [ ID : : MEMID ] = memory - > name . str ( ) ;
cell - > parameters [ ID : : CLK_ENABLE ] = false ;
cell - > parameters [ ID : : CLK_POLARITY ] = true ;
cell - > parameters [ ID : : PRIORITY ] = 0 ;
cell - > parameters [ ID : : ABITS ] = GetSize ( addr ) ;
cell - > parameters [ ID : : WIDTH ] = GetSize ( data ) ;
2023-06-23 19:40:29 +02:00
import_attributes ( cell - > attributes , inst ) ;
2020-04-02 18:51:32 +02:00
cell - > setPort ( ID : : EN , RTLIL : : SigSpec ( net_map_at ( inst - > GetControl ( ) ) ) . repeat ( GetSize ( data ) ) ) ;
cell - > setPort ( ID : : CLK , RTLIL : : State : : S0 ) ;
cell - > setPort ( ID : : ADDR , addr ) ;
cell - > setPort ( ID : : DATA , data ) ;
2019-01-02 15:33:43 +01:00
if ( inst - > Type ( ) = = OPER_CLOCKED_WRITE_PORT ) {
2020-04-02 18:51:32 +02:00
cell - > parameters [ ID : : CLK_ENABLE ] = true ;
cell - > setPort ( ID : : CLK , net_map_at ( inst - > GetClock ( ) ) ) ;
2019-01-02 15:33:43 +01:00
}
2018-02-18 13:52:49 +01:00
}
continue ;
}
2017-07-27 14:05:09 +02:00
2018-02-18 13:52:49 +01:00
if ( ! mode_gates ) {
if ( import_netlist_instance_cells ( inst , inst_name ) )
continue ;
if ( inst - > IsOperator ( ) & & ! verific_sva_prims . count ( inst - > Type ( ) ) )
2025-10-13 15:16:10 +02:00
log_warning ( " %sUnsupported Verific operator: %s (fallback to gate level implementation provided by verific) \n " , announce_src_location ( inst ) , inst - > View ( ) - > Owner ( ) - > Name ( ) ) ;
2018-02-18 13:52:49 +01:00
} else {
if ( import_netlist_instance_gates ( inst , inst_name ) )
continue ;
}
2017-07-27 14:05:09 +02:00
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_SVA_ASSERT | | inst - > Type ( ) = = PRIM_SVA_IMMEDIATE_ASSERT )
sva_asserts . insert ( inst ) ;
2017-07-27 14:05:09 +02:00
2019-10-21 12:39:28 +02:00
if ( inst - > Type ( ) = = PRIM_SVA_ASSUME | | inst - > Type ( ) = = PRIM_SVA_IMMEDIATE_ASSUME | | inst - > Type ( ) = = PRIM_SVA_RESTRICT )
2018-02-18 13:52:49 +01:00
sva_assumes . insert ( inst ) ;
2017-07-27 14:05:09 +02:00
2018-02-18 13:52:49 +01:00
if ( inst - > Type ( ) = = PRIM_SVA_COVER | | inst - > Type ( ) = = PRIM_SVA_IMMEDIATE_COVER )
sva_covers . insert ( inst ) ;
2017-07-27 14:05:09 +02:00
2018-03-04 19:29:26 +01:00
if ( inst - > Type ( ) = = PRIM_SVA_TRIGGERED )
sva_triggers . insert ( inst ) ;
2018-03-01 10:12:15 +01:00
if ( inst - > Type ( ) = = OPER_SVA_STABLE )
2017-07-27 14:05:09 +02:00
{
2018-03-04 13:48:53 +01:00
VerificClocking clocking ( this , inst - > GetInput2Bit ( 0 ) ) ;
2018-03-07 20:06:02 +01:00
log_assert ( clocking . disable_sig = = State : : S0 ) ;
log_assert ( clocking . body_net = = nullptr ) ;
2017-07-27 14:05:09 +02:00
2018-02-18 13:52:49 +01:00
log_assert ( inst - > Input1Size ( ) = = inst - > OutputSize ( ) ) ;
2017-07-27 14:05:09 +02:00
2022-05-11 12:55:53 +02:00
unsigned width = inst - > Input1Size ( ) ;
2017-07-27 14:05:09 +02:00
2022-05-11 12:55:53 +02:00
SigSpec sig_d , sig_dx , sig_qx , sig_o , sig_ox ;
sig_dx = module - > addWire ( new_verific_id ( inst ) , width * 2 ) ;
sig_qx = module - > addWire ( new_verific_id ( inst ) , width * 2 ) ;
sig_ox = module - > addWire ( new_verific_id ( inst ) , width * 2 ) ;
for ( int i = int ( width ) - 1 ; i > = 0 ; i - - ) {
2018-02-18 13:52:49 +01:00
sig_d . append ( net_map_at ( inst - > GetInput1Bit ( i ) ) ) ;
sig_o . append ( net_map_at ( inst - > GetOutputBit ( i ) ) ) ;
2017-07-27 14:05:09 +02:00
}
2018-02-28 11:45:04 +01:00
if ( verific_verbose ) {
2022-05-11 12:55:53 +02:00
for ( unsigned i = 0 ; i < width ; i + + ) {
log ( " NEX with A=%s, B=0, Y=%s. \n " ,
log_signal ( sig_d [ i ] ) , log_signal ( sig_dx [ i ] ) ) ;
log ( " EQX with A=%s, B=1, Y=%s. \n " ,
log_signal ( sig_d [ i ] ) , log_signal ( sig_dx [ i + width ] ) ) ;
}
2018-03-04 13:48:53 +01:00
log ( " %sedge FF with D=%s, Q=%s, C=%s. \n " , clocking . posedge ? " pos " : " neg " ,
2022-05-11 12:55:53 +02:00
log_signal ( sig_dx ) , log_signal ( sig_qx ) , log_signal ( clocking . clock_sig ) ) ;
2018-02-18 13:52:49 +01:00
log ( " XNOR with A=%s, B=%s, Y=%s. \n " ,
2022-05-11 12:55:53 +02:00
log_signal ( sig_dx ) , log_signal ( sig_qx ) , log_signal ( sig_ox ) ) ;
log ( " AND with A=%s, B=%s, Y=%s. \n " ,
log_signal ( sig_ox . extract ( 0 , width ) ) , log_signal ( sig_ox . extract ( width , width ) ) , log_signal ( sig_o ) ) ;
2018-02-18 13:52:49 +01:00
}
2017-07-26 18:00:01 +02:00
2022-05-11 12:55:53 +02:00
for ( unsigned i = 0 ; i < width ; i + + ) {
module - > addNex ( new_verific_id ( inst ) , sig_d [ i ] , State : : S0 , sig_dx [ i ] ) ;
module - > addEqx ( new_verific_id ( inst ) , sig_d [ i ] , State : : S1 , sig_dx [ i + width ] ) ;
}
Const qx_init = Const ( State : : S1 , width ) ;
2025-10-13 09:47:18 +02:00
qx_init . resize ( 2 * width , State : : S0 ) ;
2022-05-11 12:55:53 +02:00
clocking . addDff ( new_verific_id ( inst ) , sig_dx , sig_qx , qx_init ) ;
module - > addXnor ( new_verific_id ( inst ) , sig_dx , sig_qx , sig_ox ) ;
module - > addAnd ( new_verific_id ( inst ) , sig_ox . extract ( 0 , width ) , sig_ox . extract ( width , width ) , sig_o ) ;
2017-07-26 18:00:01 +02:00
2018-02-18 13:52:49 +01:00
if ( ! mode_keep )
continue ;
}
2018-01-23 17:42:40 +01:00
2018-03-01 10:12:15 +01:00
if ( inst - > Type ( ) = = PRIM_SVA_STABLE )
2018-02-18 13:52:49 +01:00
{
2018-03-04 13:48:53 +01:00
VerificClocking clocking ( this , inst - > GetInput2 ( ) ) ;
2018-03-07 20:06:02 +01:00
log_assert ( clocking . disable_sig = = State : : S0 ) ;
log_assert ( clocking . body_net = = nullptr ) ;
2017-07-26 18:00:01 +02:00
2018-02-18 13:52:49 +01:00
SigSpec sig_d = net_map_at ( inst - > GetInput1 ( ) ) ;
SigSpec sig_o = net_map_at ( inst - > GetOutput ( ) ) ;
2022-05-09 15:04:01 +02:00
SigSpec sig_dx = module - > addWire ( new_verific_id ( inst ) , 2 ) ;
SigSpec sig_qx = module - > addWire ( new_verific_id ( inst ) , 2 ) ;
2018-01-23 17:42:40 +01:00
2018-02-28 11:45:04 +01:00
if ( verific_verbose ) {
2022-05-09 15:04:01 +02:00
log ( " NEX with A=%s, B=0, Y=%s. \n " ,
log_signal ( sig_d ) , log_signal ( sig_dx [ 0 ] ) ) ;
log ( " EQX with A=%s, B=1, Y=%s. \n " ,
log_signal ( sig_d ) , log_signal ( sig_dx [ 1 ] ) ) ;
2018-03-04 13:48:53 +01:00
log ( " %sedge FF with D=%s, Q=%s, C=%s. \n " , clocking . posedge ? " pos " : " neg " ,
2022-05-09 15:04:01 +02:00
log_signal ( sig_dx ) , log_signal ( sig_qx ) , log_signal ( clocking . clock_sig ) ) ;
log ( " EQ with A=%s, B=%s, Y=%s. \n " ,
log_signal ( sig_dx ) , log_signal ( sig_qx ) , log_signal ( sig_o ) ) ;
2018-01-23 17:42:40 +01:00
}
2022-05-09 15:04:01 +02:00
module - > addNex ( new_verific_id ( inst ) , sig_d , State : : S0 , sig_dx [ 0 ] ) ;
module - > addEqx ( new_verific_id ( inst ) , sig_d , State : : S1 , sig_dx [ 1 ] ) ;
clocking . addDff ( new_verific_id ( inst ) , sig_dx , sig_qx , Const ( 1 , 2 ) ) ;
module - > addEq ( new_verific_id ( inst ) , sig_dx , sig_qx , sig_o ) ;
2018-01-23 17:42:40 +01:00
2018-02-18 13:52:49 +01:00
if ( ! mode_keep )
continue ;
}
2017-07-26 18:00:01 +02:00
2018-03-01 10:12:15 +01:00
if ( inst - > Type ( ) = = PRIM_SVA_PAST )
2018-02-18 13:52:49 +01:00
{
2018-03-04 13:48:53 +01:00
VerificClocking clocking ( this , inst - > GetInput2 ( ) ) ;
2018-03-07 20:06:02 +01:00
log_assert ( clocking . disable_sig = = State : : S0 ) ;
log_assert ( clocking . body_net = = nullptr ) ;
2017-07-26 18:00:01 +02:00
2018-02-18 13:52:49 +01:00
SigBit sig_d = net_map_at ( inst - > GetInput1 ( ) ) ;
SigBit sig_q = net_map_at ( inst - > GetOutput ( ) ) ;
2017-07-26 18:00:01 +02:00
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2018-03-04 13:48:53 +01:00
log ( " %sedge FF with D=%s, Q=%s, C=%s. \n " , clocking . posedge ? " pos " : " neg " ,
log_signal ( sig_d ) , log_signal ( sig_q ) , log_signal ( clocking . clock_sig ) ) ;
2017-07-26 18:00:01 +02:00
2018-12-18 16:01:22 +01:00
past_ffs . insert ( clocking . addDff ( new_verific_id ( inst ) , sig_d , sig_q ) ) ;
2017-10-12 11:59:11 +02:00
2018-02-18 13:52:49 +01:00
if ( ! mode_keep )
2017-10-12 11:59:11 +02:00
continue ;
2018-02-18 13:52:49 +01:00
}
2017-10-12 11:59:11 +02:00
2018-03-01 10:12:15 +01:00
if ( ( inst - > Type ( ) = = PRIM_SVA_ROSE | | inst - > Type ( ) = = PRIM_SVA_FELL ) )
{
2018-03-04 13:48:53 +01:00
VerificClocking clocking ( this , inst - > GetInput2 ( ) ) ;
2018-03-07 20:06:02 +01:00
log_assert ( clocking . disable_sig = = State : : S0 ) ;
log_assert ( clocking . body_net = = nullptr ) ;
2018-03-01 10:12:15 +01:00
SigBit sig_d = net_map_at ( inst - > GetInput1 ( ) ) ;
SigBit sig_o = net_map_at ( inst - > GetOutput ( ) ) ;
2018-12-18 16:01:22 +01:00
SigBit sig_q = module - > addWire ( new_verific_id ( inst ) ) ;
2022-05-09 15:04:01 +02:00
SigBit sig_d_no_x = module - > addWire ( new_verific_id ( inst ) ) ;
2018-03-01 10:12:15 +01:00
2022-05-09 15:04:01 +02:00
if ( verific_verbose ) {
log ( " EQX with A=%s, B=%d, Y=%s. \n " ,
log_signal ( sig_d ) , inst - > Type ( ) = = PRIM_SVA_ROSE , log_signal ( sig_d_no_x ) ) ;
2018-03-04 13:48:53 +01:00
log ( " %sedge FF with D=%s, Q=%s, C=%s. \n " , clocking . posedge ? " pos " : " neg " ,
2022-05-09 15:04:01 +02:00
log_signal ( sig_d_no_x ) , log_signal ( sig_q ) , log_signal ( clocking . clock_sig ) ) ;
log ( " EQ with A={%s, %s}, B={0, 1}, Y=%s. \n " ,
log_signal ( sig_q ) , log_signal ( sig_d_no_x ) , log_signal ( sig_o ) ) ;
}
2018-03-01 10:12:15 +01:00
2022-05-09 15:04:01 +02:00
module - > addEqx ( new_verific_id ( inst ) , sig_d , inst - > Type ( ) = = PRIM_SVA_ROSE ? State : : S1 : State : : S0 , sig_d_no_x ) ;
clocking . addDff ( new_verific_id ( inst ) , sig_d_no_x , sig_q , State : : S0 ) ;
module - > addEq ( new_verific_id ( inst ) , { sig_q , sig_d_no_x } , Const ( 1 , 2 ) , sig_o ) ;
2018-03-01 10:12:15 +01:00
if ( ! mode_keep )
continue ;
}
2024-06-07 14:58:33 +02:00
# endif
2018-03-01 10:12:15 +01:00
2024-05-21 17:08:07 +02:00
# ifdef YOSYSHQ_VERIFIC_API_VERSION
2021-01-20 20:48:10 +01:00
if ( inst - > Type ( ) = = PRIM_YOSYSHQ_INITSTATE )
2020-05-15 23:05:28 +02:00
{
2021-07-09 09:02:27 +02:00
if ( verific_verbose )
log ( " adding YosysHQ init state \n " ) ;
2020-05-15 23:05:28 +02:00
SigBit initstate = module - > Initstate ( new_verific_id ( inst ) ) ;
SigBit sig_o = net_map_at ( inst - > GetOutput ( ) ) ;
module - > connect ( sig_o , initstate ) ;
if ( ! mode_keep )
continue ;
}
2024-05-21 17:08:07 +02:00
# endif
2021-07-09 09:02:27 +02:00
2018-02-18 13:52:49 +01:00
if ( ! mode_keep & & verific_sva_prims . count ( inst - > Type ( ) ) ) {
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2018-02-18 13:52:49 +01:00
log ( " skipping SVA cell in non k-mode \n " ) ;
continue ;
}
2018-04-07 18:38:42 +02:00
if ( inst - > Type ( ) = = PRIM_HDL_ASSERTION )
2018-02-18 13:52:49 +01:00
{
2018-04-07 18:38:42 +02:00
SigBit cond = net_map_at ( inst - > GetInput ( ) ) ;
if ( verific_verbose )
log ( " assert condition %s. \n " , log_signal ( cond ) ) ;
2024-10-11 16:32:21 +02:00
Cell * cell = module - > addAssert ( new_verific_id ( inst ) , cond , State : : S1 ) ;
2018-04-07 18:38:42 +02:00
import_attributes ( cell - > attributes , inst ) ;
continue ;
}
2017-10-12 11:59:11 +02:00
2018-04-07 18:38:42 +02:00
if ( inst - > IsPrimitive ( ) )
{
2018-02-18 13:52:49 +01:00
if ( ! mode_keep )
2025-10-03 12:57:49 +02:00
log_error ( " %sUnsupported Verific primitive %s of type %s \n " , announce_src_location ( inst ) , inst - > Name ( ) , inst - > View ( ) - > Owner ( ) - > Name ( ) ) ;
2018-02-18 13:52:49 +01:00
if ( ! verific_sva_prims . count ( inst - > Type ( ) ) )
2025-10-03 12:57:49 +02:00
log_warning ( " %sUnsupported Verific primitive %s of type %s \n " , announce_src_location ( inst ) , inst - > Name ( ) , inst - > View ( ) - > Owner ( ) - > Name ( ) ) ;
2017-07-26 18:00:01 +02:00
}
2018-03-07 19:40:34 +01:00
import_verific_cells :
2023-07-24 12:41:57 +02:00
std : : string inst_type = is_blackbox ( inst - > View ( ) ) ? inst - > View ( ) - > CellBaseName ( ) : inst - > View ( ) - > Owner ( ) - > Name ( ) ;
2019-10-24 12:13:37 +02:00
2022-03-25 13:44:16 +01:00
nl_todo [ inst_type ] = inst - > View ( ) ;
2019-11-22 16:00:07 +01:00
if ( inst - > View ( ) - > IsOperator ( ) | | inst - > View ( ) - > IsPrimitive ( ) ) {
2019-10-24 12:13:37 +02:00
inst_type = " $verific$ " + inst_type ;
} else {
2023-07-24 12:41:57 +02:00
if ( * inst - > View ( ) - > Name ( ) & & ! is_blackbox ( inst - > View ( ) ) ) {
2019-10-24 12:13:37 +02:00
inst_type + = " ( " ;
inst_type + = inst - > View ( ) - > Name ( ) ;
inst_type + = " ) " ;
}
2020-09-30 09:16:59 +02:00
inst_type = " \\ " + sha1_if_contain_spaces ( inst_type ) ;
2019-10-24 12:13:37 +02:00
}
RTLIL : : Cell * cell = module - > addCell ( inst_name , inst_type ) ;
2024-02-12 09:53:47 +01:00
import_attributes ( cell - > attributes , inst ) ;
2017-07-26 18:00:01 +02:00
2018-02-18 13:52:49 +01:00
if ( inst - > IsPrimitive ( ) & & mode_keep )
2020-04-02 18:51:32 +02:00
cell - > attributes [ ID : : keep ] = 1 ;
2017-07-26 18:00:01 +02:00
2018-02-18 13:52:49 +01:00
dict < IdString , vector < SigBit > > cell_port_conns ;
2018-01-31 19:06:51 +01:00
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2018-02-18 13:52:49 +01:00
log ( " ports in verific db: \n " ) ;
2023-07-24 16:18:21 +02:00
const char * param_name ;
const char * param_value ;
2023-07-24 12:41:57 +02:00
if ( is_blackbox ( inst - > View ( ) ) ) {
2023-07-24 16:18:21 +02:00
FOREACH_PARAMETER_OF_INST ( inst , mi2 , param_name , param_value ) {
2024-03-14 10:37:11 +01:00
const TypeRange * tr = inst - > View ( ) - > GetTypeRange ( param_name ) ;
2024-12-02 15:45:12 +01:00
const char * type_name = ( tr ) ? tr - > GetTypeName ( ) : nullptr ;
cell - > setParam ( RTLIL : : escape_id ( param_name ) , verific_const ( type_name , param_value , inst - > View ( ) ) ) ;
2023-07-24 12:41:57 +02:00
}
}
2018-02-18 13:52:49 +01:00
FOREACH_PORTREF_OF_INST ( inst , mi2 , pr ) {
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2018-02-18 13:52:49 +01:00
log ( " .%s(%s) \n " , pr - > GetPort ( ) - > Name ( ) , pr - > GetNet ( ) - > Name ( ) ) ;
const char * port_name = pr - > GetPort ( ) - > Name ( ) ;
int port_offset = 0 ;
if ( pr - > GetPort ( ) - > Bus ( ) ) {
port_name = pr - > GetPort ( ) - > Bus ( ) - > Name ( ) ;
2024-05-08 03:09:52 +02:00
int msb_index = pr - > GetPort ( ) - > Bus ( ) - > LeftIndex ( ) ;
int lsb_index = pr - > GetPort ( ) - > Bus ( ) - > RightIndex ( ) ;
frontend: Fixes verific import around range order
Test Case
```
module packed_dimensions_range_ordering (
input wire [0:4-1] in,
output wire [4-1:0] out
);
assign out = in;
endmodule : packed_dimensions_range_ordering
module instanciates_packed_dimensions_range_ordering (
input wire [4-1:0] in,
output wire [4-1:0] out
);
packed_dimensions_range_ordering U0 (
.in (in),
.out(out)
);
endmodule : instanciates_packed_dimensions_range_ordering
```
```
// with verific, does not pass formal
module instanciates_packed_dimensions_range_ordering(in, out);
input [3:0] in;
wire [3:0] in;
output [3:0] out;
wire [3:0] out;
assign out = { in[0], in[1], in[2], in[3] };
endmodule
// with surelog, passes formal
module instanciates_packed_dimensions_range_ordering(in, out);
input [3:0] in;
wire [3:0] in;
output [3:0] out;
wire [3:0] out;
assign out = in;
endmodule
```
Signed-off-by: Ethan Mahintorabi <ethanmoon@google.com>
2024-05-08 03:00:06 +02:00
int index_of_port = pr - > GetPort ( ) - > Bus ( ) - > IndexOf ( pr - > GetPort ( ) ) ;
2024-05-08 03:09:52 +02:00
port_offset = index_of_port - min ( msb_index , lsb_index ) ;
frontend: Fixes verific import around range order
Test Case
```
module packed_dimensions_range_ordering (
input wire [0:4-1] in,
output wire [4-1:0] out
);
assign out = in;
endmodule : packed_dimensions_range_ordering
module instanciates_packed_dimensions_range_ordering (
input wire [4-1:0] in,
output wire [4-1:0] out
);
packed_dimensions_range_ordering U0 (
.in (in),
.out(out)
);
endmodule : instanciates_packed_dimensions_range_ordering
```
```
// with verific, does not pass formal
module instanciates_packed_dimensions_range_ordering(in, out);
input [3:0] in;
wire [3:0] in;
output [3:0] out;
wire [3:0] out;
assign out = { in[0], in[1], in[2], in[3] };
endmodule
// with surelog, passes formal
module instanciates_packed_dimensions_range_ordering(in, out);
input [3:0] in;
wire [3:0] in;
output [3:0] out;
wire [3:0] out;
assign out = in;
endmodule
```
Signed-off-by: Ethan Mahintorabi <ethanmoon@google.com>
2024-05-08 03:00:06 +02:00
// In cases where the msb order is flipped we need to make sure
// that the indicies match LSB = 0 order to match the std::vector
// to SigSpec LSB = 0 precondition.
2024-05-08 03:09:52 +02:00
if ( lsb_index > msb_index ) {
2024-05-08 22:28:37 +02:00
port_offset = abs ( port_offset - ( lsb_index - min ( msb_index , lsb_index ) ) ) ;
frontend: Fixes verific import around range order
Test Case
```
module packed_dimensions_range_ordering (
input wire [0:4-1] in,
output wire [4-1:0] out
);
assign out = in;
endmodule : packed_dimensions_range_ordering
module instanciates_packed_dimensions_range_ordering (
input wire [4-1:0] in,
output wire [4-1:0] out
);
packed_dimensions_range_ordering U0 (
.in (in),
.out(out)
);
endmodule : instanciates_packed_dimensions_range_ordering
```
```
// with verific, does not pass formal
module instanciates_packed_dimensions_range_ordering(in, out);
input [3:0] in;
wire [3:0] in;
output [3:0] out;
wire [3:0] out;
assign out = { in[0], in[1], in[2], in[3] };
endmodule
// with surelog, passes formal
module instanciates_packed_dimensions_range_ordering(in, out);
input [3:0] in;
wire [3:0] in;
output [3:0] out;
wire [3:0] out;
assign out = in;
endmodule
```
Signed-off-by: Ethan Mahintorabi <ethanmoon@google.com>
2024-05-08 03:00:06 +02:00
}
2018-02-18 13:52:49 +01:00
}
IdString port_name_id = RTLIL : : escape_id ( port_name ) ;
auto & sigvec = cell_port_conns [ port_name_id ] ;
if ( GetSize ( sigvec ) < = port_offset ) {
2018-12-18 16:01:22 +01:00
SigSpec zwires = module - > addWire ( new_verific_id ( inst ) , port_offset + 1 - GetSize ( sigvec ) ) ;
2018-02-18 13:52:49 +01:00
for ( auto bit : zwires )
sigvec . push_back ( bit ) ;
}
sigvec [ port_offset ] = net_map_at ( pr - > GetNet ( ) ) ;
2017-10-12 11:59:11 +02:00
}
2018-01-31 19:06:51 +01:00
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2018-02-18 13:52:49 +01:00
log ( " ports in yosys db: \n " ) ;
for ( auto & it : cell_port_conns ) {
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2018-02-18 13:52:49 +01:00
log ( " .%s(%s) \n " , log_id ( it . first ) , log_signal ( it . second ) ) ;
cell - > setPort ( it . first , it . second ) ;
}
2017-07-26 18:00:01 +02:00
}
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2018-02-18 13:52:49 +01:00
if ( ! mode_nosva )
{
2018-04-06 14:10:57 +02:00
for ( auto inst : sva_asserts ) {
if ( mode_autocover )
verific_import_sva_cover ( this , inst ) ;
2018-03-07 20:06:02 +01:00
verific_import_sva_assert ( this , inst ) ;
2018-04-06 14:10:57 +02:00
}
2018-02-18 13:28:08 +01:00
2018-02-18 13:52:49 +01:00
for ( auto inst : sva_assumes )
2018-03-07 20:06:02 +01:00
verific_import_sva_assume ( this , inst ) ;
2018-02-18 13:28:08 +01:00
2018-02-18 13:52:49 +01:00
for ( auto inst : sva_covers )
2018-03-07 20:06:02 +01:00
verific_import_sva_cover ( this , inst ) ;
2018-02-18 13:28:08 +01:00
2018-03-04 19:29:26 +01:00
for ( auto inst : sva_triggers )
2018-03-07 20:06:02 +01:00
verific_import_sva_trigger ( this , inst ) ;
2018-03-04 19:29:26 +01:00
2018-02-18 13:52:49 +01:00
merge_past_ffs ( past_ffs ) ;
}
2024-06-07 14:58:33 +02:00
# endif
2019-08-07 15:31:49 +02:00
if ( ! mode_fullinit )
{
pool < SigBit > non_ff_bits ;
CellTypes ff_types ;
ff_types . setup_internals_ff ( ) ;
ff_types . setup_stdcells_mem ( ) ;
for ( auto cell : module - > cells ( ) )
{
if ( ff_types . cell_known ( cell - > type ) )
continue ;
for ( auto conn : cell - > connections ( ) )
{
if ( ! cell - > output ( conn . first ) )
continue ;
for ( auto bit : conn . second )
if ( bit . wire ! = nullptr )
non_ff_bits . insert ( bit ) ;
}
}
for ( auto wire : module - > wires ( ) )
{
2020-04-02 18:51:32 +02:00
if ( ! wire - > attributes . count ( ID : : init ) )
2019-08-07 15:31:49 +02:00
continue ;
2020-04-02 18:51:32 +02:00
Const & initval = wire - > attributes . at ( ID : : init ) ;
2019-08-07 15:31:49 +02:00
for ( int i = 0 ; i < GetSize ( initval ) ; i + + )
{
if ( initval [ i ] ! = State : : S0 & & initval [ i ] ! = State : : S1 )
continue ;
if ( non_ff_bits . count ( SigBit ( wire , i ) ) )
2025-10-13 09:47:18 +02:00
initval . set ( i , State : : Sx ) ;
2019-08-07 15:31:49 +02:00
}
2023-06-21 13:21:34 +02:00
if ( wire - > port_input ) {
wire - > attributes [ ID : : defaultvalue ] = Const ( initval ) ;
wire - > attributes . erase ( ID : : init ) ;
} else if ( initval . is_fully_undef ( ) )
2020-04-02 18:51:32 +02:00
wire - > attributes . erase ( ID : : init ) ;
2019-08-07 15:31:49 +02:00
}
}
2025-09-24 18:47:54 +02:00
if ( num_sva_continue ) {
log_warning ( " Encountered %d items containing unsupported SVA! \n " , num_sva_continue ) ;
log_warning ( " Unsupported SVA imported as 'x and marked using the `unsupported_sva' attribute due to -sva-continue-on-err. \n " ) ;
}
num_sva_continue = 0 ;
2017-07-26 18:00:01 +02:00
}
2018-02-18 13:52:49 +01:00
// ==================================================================
2017-07-26 18:00:01 +02:00
2024-06-07 14:58:33 +02:00
VerificClocking : : VerificClocking ( VerificImporter * importer , Net * net , bool sva_at_only YS_MAYBE_UNUSED )
2017-07-26 18:00:01 +02:00
{
2018-03-04 13:48:53 +01:00
module = importer - > module ;
2018-02-18 13:52:49 +01:00
log_assert ( importer ! = nullptr ) ;
2018-03-04 13:48:53 +01:00
log_assert ( net ! = nullptr ) ;
2018-02-18 13:52:49 +01:00
2018-03-04 13:48:53 +01:00
Instance * inst = net - > Driver ( ) ;
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2023-04-21 16:51:42 +02:00
// Detect condition expression in sva_at_only mode
if ( sva_at_only )
do {
Instance * inst_mux = net - > Driver ( ) ;
2024-01-18 08:47:04 +01:00
if ( inst_mux = = nullptr | | inst_mux - > Type ( ) ! = PRIM_MUX )
2023-04-21 16:51:42 +02:00
break ;
bool pwr1 = inst_mux - > GetInput1 ( ) - > IsPwr ( ) ;
bool pwr2 = inst_mux - > GetInput2 ( ) - > IsPwr ( ) ;
if ( ! pwr1 & & ! pwr2 )
break ;
Net * sva_net = pwr1 ? inst_mux - > GetInput2 ( ) : inst_mux - > GetInput1 ( ) ;
if ( ! verific_is_sva_net ( importer , sva_net ) )
break ;
inst = sva_net - > Driver ( ) ;
cond_net = inst_mux - > GetControl ( ) ;
cond_pol = pwr1 ;
} while ( 0 ) ;
2018-03-04 13:48:53 +01:00
if ( inst ! = nullptr & & inst - > Type ( ) = = PRIM_SVA_AT )
2018-02-18 13:52:49 +01:00
{
2018-03-04 13:48:53 +01:00
net = inst - > GetInput1 ( ) ;
body_net = inst - > GetInput2 ( ) ;
inst = net - > Driver ( ) ;
2018-02-18 13:52:49 +01:00
2018-03-04 13:48:53 +01:00
Instance * body_inst = body_net - > Driver ( ) ;
if ( body_inst ! = nullptr & & body_inst - > Type ( ) = = PRIM_SVA_DISABLE_IFF ) {
disable_net = body_inst - > GetInput1 ( ) ;
disable_sig = importer - > net_map_at ( disable_net ) ;
body_net = body_inst - > GetInput2 ( ) ;
2018-02-18 13:52:49 +01:00
}
2018-03-04 13:48:53 +01:00
}
2018-03-26 13:04:10 +02:00
else
{
if ( sva_at_only )
return ;
}
2018-02-18 13:52:49 +01:00
2018-05-28 13:36:35 +02:00
// Use while() instead of if() to work around VIPER #13453
2018-05-24 18:13:38 +02:00
while ( inst ! = nullptr & & inst - > Type ( ) = = PRIM_SVA_POSEDGE )
2018-03-04 13:48:53 +01:00
{
net = inst - > GetInput ( ) ;
inst = net - > Driver ( ) ; ;
2018-02-18 13:52:49 +01:00
}
2024-06-07 14:58:33 +02:00
# endif
2018-03-04 13:48:53 +01:00
if ( inst ! = nullptr & & inst - > Type ( ) = = PRIM_INV )
{
net = inst - > GetInput ( ) ;
inst = net - > Driver ( ) ; ;
posedge = false ;
}
// Detect clock-enable circuit
do {
if ( inst = = nullptr | | inst - > Type ( ) ! = PRIM_AND )
break ;
Net * net_dlatch = inst - > GetInput1 ( ) ;
Instance * inst_dlatch = net_dlatch - > Driver ( ) ;
if ( inst_dlatch = = nullptr | | inst_dlatch - > Type ( ) ! = PRIM_DLATCHRS )
break ;
if ( ! inst_dlatch - > GetSet ( ) - > IsGnd ( ) | | ! inst_dlatch - > GetReset ( ) - > IsGnd ( ) )
break ;
Net * net_enable = inst_dlatch - > GetInput ( ) ;
Net * net_not_clock = inst_dlatch - > GetControl ( ) ;
if ( net_enable = = nullptr | | net_not_clock = = nullptr )
break ;
Instance * inst_not_clock = net_not_clock - > Driver ( ) ;
if ( inst_not_clock = = nullptr | | inst_not_clock - > Type ( ) ! = PRIM_INV )
break ;
Net * net_clock1 = inst_not_clock - > GetInput ( ) ;
Net * net_clock2 = inst - > GetInput2 ( ) ;
if ( net_clock1 = = nullptr | | net_clock1 ! = net_clock2 )
break ;
enable_net = net_enable ;
enable_sig = importer - > net_map_at ( enable_net ) ;
net = net_clock1 ;
inst = net - > Driver ( ) ; ;
} while ( 0 ) ;
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2018-03-07 20:06:02 +01:00
// Detect condition expression
do {
if ( body_net = = nullptr )
break ;
Instance * inst_mux = body_net - > Driver ( ) ;
if ( inst_mux = = nullptr | | inst_mux - > Type ( ) ! = PRIM_MUX )
break ;
2022-05-03 13:22:18 +02:00
bool pwr1 = inst_mux - > GetInput1 ( ) - > IsPwr ( ) ;
bool pwr2 = inst_mux - > GetInput2 ( ) - > IsPwr ( ) ;
if ( ! pwr1 & & ! pwr2 )
2018-03-07 20:06:02 +01:00
break ;
2022-05-03 13:22:18 +02:00
Net * sva_net = pwr1 ? inst_mux - > GetInput2 ( ) : inst_mux - > GetInput1 ( ) ;
2018-03-07 20:06:02 +01:00
if ( ! verific_is_sva_net ( importer , sva_net ) )
break ;
body_net = sva_net ;
cond_net = inst_mux - > GetControl ( ) ;
2022-05-03 13:22:18 +02:00
cond_pol = pwr1 ;
2018-03-07 20:06:02 +01:00
} while ( 0 ) ;
2024-06-07 14:58:33 +02:00
# endif
2018-03-07 20:06:02 +01:00
2018-03-04 13:48:53 +01:00
clock_net = net ;
clock_sig = importer - > net_map_at ( clock_net ) ;
2018-06-01 13:25:42 +02:00
const char * gclk_attr = clock_net - > GetAttValue ( " gclk " ) ;
if ( gclk_attr ! = nullptr & & ( ! strcmp ( gclk_attr , " 1 " ) | | ! strcmp ( gclk_attr , " '1' " ) ) )
gclk = true ;
2018-03-04 13:48:53 +01:00
}
Cell * VerificClocking : : addDff ( IdString name , SigSpec sig_d , SigSpec sig_q , Const init_value )
{
log_assert ( GetSize ( sig_d ) = = GetSize ( sig_q ) ) ;
2021-10-31 17:12:29 +01:00
auto set_init_attribute = [ & ] ( SigSpec & s ) {
if ( GetSize ( init_value ) = = 0 )
return ;
log_assert ( GetSize ( s ) = = GetSize ( init_value ) ) ;
if ( s . is_wire ( ) ) {
s . as_wire ( ) - > attributes [ ID : : init ] = init_value ;
2018-03-04 13:48:53 +01:00
} else {
2021-10-31 17:12:29 +01:00
Wire * w = module - > addWire ( NEW_ID , GetSize ( s ) ) ;
2020-04-02 18:51:32 +02:00
w - > attributes [ ID : : init ] = init_value ;
2021-10-31 17:12:29 +01:00
module - > connect ( s , w ) ;
s = w ;
2018-03-04 13:48:53 +01:00
}
2021-10-31 17:12:29 +01:00
} ;
2018-03-04 13:48:53 +01:00
if ( enable_sig ! = State : : S1 )
sig_d = module - > Mux ( NEW_ID , sig_q , sig_d , enable_sig ) ;
if ( disable_sig ! = State : : S0 ) {
log_assert ( GetSize ( sig_q ) = = GetSize ( init_value ) ) ;
2021-10-31 17:12:29 +01:00
if ( gclk ) {
Wire * pre_d = module - > addWire ( NEW_ID , GetSize ( sig_d ) ) ;
Wire * post_q_w = module - > addWire ( NEW_ID , GetSize ( sig_q ) ) ;
Const initval ( State : : Sx , GetSize ( sig_q ) ) ;
int offset = 0 ;
for ( auto c : sig_q . chunks ( ) ) {
if ( c . wire & & c . wire - > attributes . count ( ID : : init ) ) {
Const val = c . wire - > attributes . at ( ID : : init ) ;
for ( int i = 0 ; i < GetSize ( c ) ; i + + )
2025-10-13 09:47:18 +02:00
initval . set ( offset + i , val [ c . offset + i ] ) ;
2021-10-31 17:12:29 +01:00
}
offset + = GetSize ( c ) ;
}
if ( ! initval . is_fully_undef ( ) )
post_q_w - > attributes [ ID : : init ] = initval ;
module - > addMux ( NEW_ID , sig_d , init_value , disable_sig , pre_d ) ;
module - > addMux ( NEW_ID , post_q_w , init_value , disable_sig , sig_q ) ;
SigSpec post_q ( post_q_w ) ;
set_init_attribute ( post_q ) ;
return module - > addFf ( name , pre_d , post_q ) ;
}
set_init_attribute ( sig_q ) ;
2018-03-04 13:48:53 +01:00
return module - > addAdff ( name , clock_sig , disable_sig , sig_d , sig_q , init_value , posedge ) ;
}
2021-10-31 17:12:29 +01:00
if ( gclk ) {
set_init_attribute ( sig_q ) ;
2018-06-01 13:25:42 +02:00
return module - > addFf ( name , sig_d , sig_q ) ;
2021-10-31 17:12:29 +01:00
}
2018-06-01 13:25:42 +02:00
2021-10-31 17:12:29 +01:00
set_init_attribute ( sig_q ) ;
2018-03-04 13:48:53 +01:00
return module - > addDff ( name , clock_sig , sig_d , sig_q , posedge ) ;
}
Cell * VerificClocking : : addAdff ( IdString name , RTLIL : : SigSpec sig_arst , SigSpec sig_d , SigSpec sig_q , Const arst_value )
{
2018-06-01 13:25:42 +02:00
log_assert ( gclk = = false ) ;
2018-03-04 13:48:53 +01:00
log_assert ( disable_sig = = State : : S0 ) ;
2021-10-11 10:00:20 +02:00
// FIXME: Adffe
2018-03-04 13:48:53 +01:00
if ( enable_sig ! = State : : S1 )
sig_d = module - > Mux ( NEW_ID , sig_q , sig_d , enable_sig ) ;
return module - > addAdff ( name , clock_sig , sig_arst , sig_d , sig_q , arst_value , posedge ) ;
}
Cell * VerificClocking : : addDffsr ( IdString name , RTLIL : : SigSpec sig_set , RTLIL : : SigSpec sig_clr , SigSpec sig_d , SigSpec sig_q )
{
2018-06-01 13:25:42 +02:00
log_assert ( gclk = = false ) ;
2018-03-04 13:48:53 +01:00
log_assert ( disable_sig = = State : : S0 ) ;
2021-10-11 10:00:20 +02:00
// FIXME: Dffsre
2018-03-04 13:48:53 +01:00
if ( enable_sig ! = State : : S1 )
sig_d = module - > Mux ( NEW_ID , sig_q , sig_d , enable_sig ) ;
return module - > addDffsr ( name , clock_sig , sig_set , sig_clr , sig_d , sig_q , posedge ) ;
2017-07-26 18:00:01 +02:00
}
2021-10-08 16:21:25 +02:00
Cell * VerificClocking : : addAldff ( IdString name , RTLIL : : SigSpec sig_aload , RTLIL : : SigSpec sig_adata , SigSpec sig_d , SigSpec sig_q )
{
log_assert ( disable_sig = = State : : S0 ) ;
2021-10-11 10:00:20 +02:00
// FIXME: Aldffe
2021-10-08 16:21:25 +02:00
if ( enable_sig ! = State : : S1 )
sig_d = module - > Mux ( NEW_ID , sig_q , sig_d , enable_sig ) ;
2021-10-31 17:12:29 +01:00
if ( gclk ) {
Wire * pre_d = module - > addWire ( NEW_ID , GetSize ( sig_d ) ) ;
Wire * post_q = module - > addWire ( NEW_ID , GetSize ( sig_q ) ) ;
Const initval ( State : : Sx , GetSize ( sig_q ) ) ;
int offset = 0 ;
for ( auto c : sig_q . chunks ( ) ) {
if ( c . wire & & c . wire - > attributes . count ( ID : : init ) ) {
Const val = c . wire - > attributes . at ( ID : : init ) ;
for ( int i = 0 ; i < GetSize ( c ) ; i + + )
2025-10-13 09:47:18 +02:00
initval . set ( offset + i , val [ c . offset + i ] ) ;
2021-10-31 17:12:29 +01:00
}
offset + = GetSize ( c ) ;
}
if ( ! initval . is_fully_undef ( ) )
post_q - > attributes [ ID : : init ] = initval ;
module - > addMux ( NEW_ID , sig_d , sig_adata , sig_aload , pre_d ) ;
module - > addMux ( NEW_ID , post_q , sig_adata , sig_aload , sig_q ) ;
return module - > addFf ( name , pre_d , post_q ) ;
}
2021-10-08 16:21:25 +02:00
return module - > addAldff ( name , clock_sig , sig_aload , sig_d , sig_q , sig_adata , posedge ) ;
}
2017-10-10 15:16:39 +02:00
// ==================================================================
2017-07-25 14:53:11 +02:00
struct VerificExtNets
{
int portname_cnt = 0 ;
2017-07-25 15:13:22 +02:00
// a map from Net to the same Net one level up in the design hierarchy
2019-03-26 14:17:46 +01:00
std : : map < Net * , Net * > net_level_up_drive_up ;
std : : map < Net * , Net * > net_level_up_drive_down ;
2017-07-25 15:13:22 +02:00
2019-03-26 14:17:46 +01:00
Net * route_up ( Net * net , bool drive_up , Net * final_net = nullptr )
2017-07-25 14:53:11 +02:00
{
2019-03-26 14:17:46 +01:00
auto & net_level_up = drive_up ? net_level_up_drive_up : net_level_up_drive_down ;
2017-07-25 14:53:11 +02:00
if ( net_level_up . count ( net ) = = 0 )
{
Netlist * nl = net - > Owner ( ) ;
2017-07-25 15:13:22 +02:00
// Simply return if Netlist is not unique
2019-03-26 14:17:46 +01:00
log_assert ( nl - > NumOfRefs ( ) = = 1 ) ;
2017-07-25 14:53:11 +02:00
Instance * up_inst = ( Instance * ) nl - > GetReferences ( ) - > GetLast ( ) ;
Netlist * up_nl = up_inst - > Owner ( ) ;
// create new Port
string name = stringf ( " ___extnets_%d " , portname_cnt + + ) ;
2019-03-26 14:17:46 +01:00
Port * new_port = new Port ( name . c_str ( ) , drive_up ? DIR_OUT : DIR_IN ) ;
2017-07-25 14:53:11 +02:00
nl - > Add ( new_port ) ;
2022-04-01 12:07:15 +02:00
nl - > Buf ( net ) - > Connect ( new_port ) ;
2017-07-25 14:53:11 +02:00
// create new Net in up Netlist
2019-03-26 14:17:46 +01:00
Net * new_net = final_net ;
if ( new_net = = nullptr | | new_net - > Owner ( ) ! = up_nl ) {
new_net = new Net ( name . c_str ( ) ) ;
up_nl - > Add ( new_net ) ;
}
2017-07-25 14:53:11 +02:00
up_inst - > Connect ( new_port , new_net ) ;
net_level_up [ net ] = new_net ;
}
return net_level_up . at ( net ) ;
}
2019-03-26 14:17:46 +01:00
Net * route_up ( Net * net , bool drive_up , Netlist * dest , Net * final_net = nullptr )
{
while ( net - > Owner ( ) ! = dest )
net = route_up ( net , drive_up , final_net ) ;
if ( final_net ! = nullptr )
log_assert ( net = = final_net ) ;
return net ;
}
Netlist * find_common_ancestor ( Netlist * A , Netlist * B )
{
std : : set < Netlist * > ancestors_of_A ;
Netlist * cursor = A ;
while ( 1 ) {
ancestors_of_A . insert ( cursor ) ;
if ( cursor - > NumOfRefs ( ) ! = 1 )
break ;
cursor = ( ( Instance * ) cursor - > GetReferences ( ) - > GetLast ( ) ) - > Owner ( ) ;
}
cursor = B ;
while ( 1 ) {
if ( ancestors_of_A . count ( cursor ) )
return cursor ;
if ( cursor - > NumOfRefs ( ) ! = 1 )
break ;
cursor = ( ( Instance * ) cursor - > GetReferences ( ) - > GetLast ( ) ) - > Owner ( ) ;
}
2025-09-11 07:25:26 +02:00
log_error ( " No common ancestor found between %s and %s. \n " , get_full_netlist_name ( A ) , get_full_netlist_name ( B ) ) ;
2019-03-26 14:17:46 +01:00
}
2017-07-25 14:53:11 +02:00
void run ( Netlist * nl )
{
MapIter mi , mi2 ;
Instance * inst ;
PortRef * pr ;
vector < tuple < Instance * , Port * , Net * > > todo_connect ;
FOREACH_INSTANCE_OF_NETLIST ( nl , mi , inst )
run ( inst - > View ( ) ) ;
FOREACH_INSTANCE_OF_NETLIST ( nl , mi , inst )
FOREACH_PORTREF_OF_INST ( inst , mi2 , pr )
{
Port * port = pr - > GetPort ( ) ;
Net * net = pr - > GetNet ( ) ;
if ( ! net - > IsExternalTo ( nl ) )
continue ;
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2025-09-11 07:25:26 +02:00
log ( " Fixing external net reference on port %s.%s.%s: \n " , get_full_netlist_name ( nl ) , inst - > Name ( ) , port - > Name ( ) ) ;
2017-07-25 14:53:11 +02:00
2019-03-26 14:17:46 +01:00
Netlist * ext_nl = net - > Owner ( ) ;
2017-07-25 14:53:11 +02:00
2019-03-26 14:17:46 +01:00
if ( verific_verbose )
2025-09-11 07:25:26 +02:00
log ( " external net owner: %s \n " , get_full_netlist_name ( ext_nl ) ) ;
2019-03-26 14:17:46 +01:00
Netlist * ca_nl = find_common_ancestor ( nl , ext_nl ) ;
if ( verific_verbose )
2025-09-11 07:25:26 +02:00
log ( " common ancestor: %s \n " , get_full_netlist_name ( ca_nl ) ) ;
2019-03-26 14:17:46 +01:00
Net * ca_net = route_up ( net , ! port - > IsOutput ( ) , ca_nl ) ;
Net * new_net = ca_net ;
if ( ca_nl ! = nl )
{
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2019-03-26 14:17:46 +01:00
log ( " net in common ancestor: %s \n " , ca_net - > Name ( ) ) ;
string name = stringf ( " ___extnets_%d " , portname_cnt + + ) ;
new_net = new Net ( name . c_str ( ) ) ;
nl - > Add ( new_net ) ;
2020-06-19 03:32:48 +02:00
Net * n = route_up ( new_net , port - > IsOutput ( ) , ca_nl , ca_net ) ;
2019-03-26 14:17:46 +01:00
log_assert ( n = = ca_net ) ;
2017-07-25 14:53:11 +02:00
}
2018-02-28 11:45:04 +01:00
if ( verific_verbose )
2019-03-26 14:17:46 +01:00
log ( " new local net: %s \n " , new_net - > Name ( ) ) ;
log_assert ( ! new_net - > IsExternalTo ( nl ) ) ;
todo_connect . push_back ( tuple < Instance * , Port * , Net * > ( inst , port , new_net ) ) ;
2017-07-25 14:53:11 +02:00
}
for ( auto it : todo_connect ) {
get < 0 > ( it ) - > Disconnect ( get < 1 > ( it ) ) ;
get < 0 > ( it ) - > Connect ( get < 1 > ( it ) , get < 2 > ( it ) ) ;
}
}
} ;
2024-12-06 15:59:09 +01:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
static msg_type_t prev_1063 ;
# endif
# ifdef VERIFIC_VHDL_SUPPORT
static msg_type_t prev_1240 ;
static msg_type_t prev_1241 ;
# endif
void save_blackbox_msg_state ( )
{
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
prev_1063 = Message : : GetMessageType ( " VERI-1063 " ) ;
Message : : SetMessageType ( " VERI-1063 " , VERIFIC_INFO ) ;
# endif
# ifdef VERIFIC_VHDL_SUPPORT
prev_1240 = Message : : GetMessageType ( " VHDL-1240 " ) ;
prev_1241 = Message : : GetMessageType ( " VHDL-1241 " ) ;
Message : : SetMessageType ( " VHDL-1240 " , VERIFIC_INFO ) ;
Message : : SetMessageType ( " VHDL-1241 " , VERIFIC_INFO ) ;
# endif
}
void restore_blackbox_msg_state ( )
{
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
Message : : ClearMessageType ( " VERI-1063 " ) ;
if ( Message : : GetMessageType ( " VERI-1063 " ) ! = prev_1063 )
Message : : SetMessageType ( " VERI-1063 " , prev_1063 ) ;
# endif
# ifdef VERIFIC_VHDL_SUPPORT
Message : : ClearMessageType ( " VHDL-1240 " ) ;
Message : : ClearMessageType ( " VHDL-1241 " ) ;
if ( Message : : GetMessageType ( " VHDL-1240 " ) ! = prev_1240 )
Message : : SetMessageType ( " VHDL-1240 " , prev_1240 ) ;
if ( Message : : GetMessageType ( " VHDL-1241 " ) ! = prev_1241 )
Message : : SetMessageType ( " VHDL-1241 " , prev_1241 ) ;
# endif
}
2024-06-17 14:49:58 +02:00
void import_all ( const char * work , std : : map < std : : string , Netlist * > * nl_todo , Map * parameters , bool show_message , std : : string ppfile YS_MAYBE_UNUSED )
2018-06-20 23:45:01 +02:00
{
2024-06-17 14:49:58 +02:00
# ifdef YOSYSHQ_VERIFIC_EXTENSIONS
2024-12-06 15:59:09 +01:00
save_blackbox_msg_state ( ) ;
2024-06-17 14:49:58 +02:00
VerificExtensions : : ElaborateAndRewrite ( work , parameters ) ;
verific_error_msg . clear ( ) ;
2024-12-06 15:59:09 +01:00
restore_blackbox_msg_state ( ) ;
2024-06-17 14:49:58 +02:00
# endif
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
if ( ! ppfile . empty ( ) )
veri_file : : PrettyPrint ( ppfile . c_str ( ) , nullptr , work ) ;
# endif
2018-09-04 20:06:10 +02:00
2024-06-10 10:12:33 +02:00
Array vhdl_libs ;
2024-06-11 07:48:26 +02:00
# ifdef VERIFIC_VHDL_SUPPORT
2024-06-17 14:49:58 +02:00
VhdlLibrary * vhdl_lib = vhdl_file : : GetLibrary ( work , 1 ) ;
2019-03-13 01:02:04 +01:00
if ( vhdl_lib ) vhdl_libs . InsertLast ( vhdl_lib ) ;
2021-10-20 10:02:58 +02:00
# endif
2024-06-10 10:12:33 +02:00
Array veri_libs ;
2024-06-11 07:48:26 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2024-06-17 14:49:58 +02:00
VeriLibrary * veri_lib = veri_file : : GetLibrary ( work , 1 ) ;
2019-03-13 01:02:04 +01:00
if ( veri_lib ) veri_libs . InsertLast ( veri_lib ) ;
2024-06-07 14:58:33 +02:00
# endif
2019-03-13 01:02:04 +01:00
2024-05-21 17:08:07 +02:00
# ifdef VERIFIC_HIER_TREE_SUPPORT
2024-06-17 14:49:58 +02:00
if ( show_message )
log ( " Running hier_tree::ElaborateAll(). \n " ) ;
Array * netlists = hier_tree : : ElaborateAll ( & veri_libs , & vhdl_libs , parameters ) ;
Netlist * nl ;
int i ;
FOREACH_ARRAY_ITEM ( netlists , i , nl )
nl_todo - > emplace ( nl - > CellBaseName ( ) , nl ) ;
delete netlists ;
2024-05-21 17:08:07 +02:00
# else
2024-06-17 14:49:58 +02:00
if ( parameters - > Size ( ) )
log_warning ( " Please note that parameters are not propagated during import. \n " ) ;
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2024-06-17 14:49:58 +02:00
if ( show_message )
log ( " Running veri_file::ElaborateAll(). \n " ) ;
veri_file : : ElaborateAll ( work ) ;
2024-06-07 14:58:33 +02:00
# endif
# ifdef VERIFIC_VHDL_SUPPORT
2024-06-17 14:49:58 +02:00
if ( show_message )
log ( " Running vhdl_file::ElaborateAll(). \n " ) ;
vhdl_file : : ElaborateAll ( work ) ;
2024-06-07 14:58:33 +02:00
# endif
2024-06-17 14:49:58 +02:00
MapIter mi ;
Verific : : Cell * c ;
MapIter it ;
Library * l ;
FOREACH_LIBRARY_OF_LIBSET ( Libset : : Global ( ) , it , l ) {
if ( l = = Library : : Primitives ( ) | | l = = Library : : Operators ( ) ) continue ;
FOREACH_CELL_OF_LIBRARY ( l , mi , c ) {
MapIter ni ;
Netlist * nl ;
FOREACH_NETLIST_OF_CELL ( c , ni , nl ) {
if ( nl )
nl_todo - > emplace ( nl - > CellBaseName ( ) , nl ) ;
2024-05-21 17:08:07 +02:00
}
}
2019-03-13 01:02:04 +01:00
}
2024-06-17 14:49:58 +02:00
# endif
}
2024-07-29 15:50:38 +02:00
std : : set < std : : string > import_tops ( const char * work , std : : map < std : : string , Netlist * > * nl_todo , Map * parameters , bool show_message , std : : string ppfile YS_MAYBE_UNUSED , std : : vector < std : : string > & tops , std : : string * top = nullptr )
2024-06-17 14:49:58 +02:00
{
std : : set < std : : string > top_mod_names ;
Array * netlists = nullptr ;
# ifdef VERIFIC_VHDL_SUPPORT
VhdlLibrary * vhdl_lib = vhdl_file : : GetLibrary ( work , 1 ) ;
# endif
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
VeriLibrary * veri_lib = veri_file : : GetLibrary ( work , 1 ) ;
# endif
2023-10-05 16:40:43 +02:00
# ifdef YOSYSHQ_VERIFIC_EXTENSIONS
2024-06-17 14:49:58 +02:00
for ( int static_elaborate = 1 ; static_elaborate > = 0 ; static_elaborate - - )
2023-10-05 16:40:43 +02:00
# endif
2024-06-17 14:49:58 +02:00
{
Array vhdl_units ;
Array veri_modules ;
for ( std : : string n : tops )
2023-10-05 16:40:43 +02:00
{
2024-06-17 14:49:58 +02:00
const char * name = n . c_str ( ) ;
top_mod_names . insert ( name ) ;
2024-06-11 07:48:26 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2024-06-17 14:49:58 +02:00
VeriModule * veri_module = veri_lib ? veri_lib - > GetModule ( name , 1 ) : nullptr ;
if ( veri_module ) {
if ( veri_module - > IsConfiguration ( ) ) {
if ( show_message )
log ( " Adding Verilog configuration '%s' to elaboration queue. \n " , name ) ;
2023-10-05 16:40:43 +02:00
veri_modules . InsertLast ( veri_module ) ;
2024-06-17 14:49:58 +02:00
top_mod_names . erase ( name ) ;
VeriConfiguration * cfg = ( VeriConfiguration * ) veri_module ;
VeriName * module_name ;
int i ;
FOREACH_ARRAY_ITEM ( cfg - > GetTopModuleNames ( ) , i , module_name ) {
2023-10-05 16:40:43 +02:00
VeriLibrary * lib = veri_module - > GetLibrary ( ) ;
if ( module_name & & module_name - > IsHierName ( ) ) {
VeriName * prefix = module_name - > GetPrefix ( ) ;
const char * lib_name = ( prefix ) ? prefix - > GetName ( ) : 0 ;
2024-06-17 14:49:58 +02:00
if ( work ! = lib_name ) lib = veri_file : : GetLibrary ( lib_name , 1 ) ;
2023-10-05 16:40:43 +02:00
}
if ( lib & & module_name )
2024-06-17 14:49:58 +02:00
top_mod_names . insert ( lib - > GetModule ( module_name - > GetName ( ) , 1 ) - > GetName ( ) ) ;
2023-10-05 16:40:43 +02:00
}
2024-06-17 14:49:58 +02:00
} else {
if ( show_message )
log ( " Adding Verilog module '%s' to elaboration queue. \n " , name ) ;
veri_modules . InsertLast ( veri_module ) ;
2023-10-05 16:40:43 +02:00
}
2024-06-17 14:49:58 +02:00
continue ;
2019-03-13 01:02:04 +01:00
}
2024-06-07 14:58:33 +02:00
# endif
2024-06-11 07:48:26 +02:00
# ifdef VERIFIC_VHDL_SUPPORT
2024-06-17 14:49:58 +02:00
VhdlDesignUnit * vhdl_unit = vhdl_lib ? vhdl_lib - > GetPrimUnit ( name ) : nullptr ;
if ( vhdl_unit ) {
if ( show_message )
log ( " Adding VHDL unit '%s' to elaboration queue. \n " , name ) ;
vhdl_units . InsertLast ( vhdl_unit ) ;
2024-07-18 16:56:52 +02:00
if ( strcmp ( name , vhdl_unit - > Id ( ) - > OrigName ( ) ) ! = 0 ) {
top_mod_names . erase ( name ) ;
top_mod_names . insert ( vhdl_unit - > Id ( ) - > OrigName ( ) ) ;
2024-07-29 15:50:38 +02:00
if ( top & & * top = = name )
* top = vhdl_unit - > Id ( ) - > OrigName ( ) ;
2024-07-18 16:56:52 +02:00
}
2024-06-17 14:49:58 +02:00
continue ;
2023-10-05 16:40:43 +02:00
}
# endif
2024-06-17 14:49:58 +02:00
log_error ( " Can't find module/unit '%s'. \n " , name ) ;
}
2023-10-05 16:40:43 +02:00
# ifdef YOSYSHQ_VERIFIC_EXTENSIONS
2024-06-17 14:49:58 +02:00
if ( static_elaborate ) {
2024-12-06 15:59:09 +01:00
save_blackbox_msg_state ( ) ;
2024-06-17 14:49:58 +02:00
VerificExtensions : : ElaborateAndRewrite ( work , & veri_modules , & vhdl_units , parameters ) ;
verific_error_msg . clear ( ) ;
2024-12-06 15:59:09 +01:00
restore_blackbox_msg_state ( ) ;
2024-06-17 14:49:58 +02:00
# endif
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
if ( ! ppfile . empty ( ) )
veri_file : : PrettyPrint ( ppfile . c_str ( ) , nullptr , work ) ;
# endif
# ifdef YOSYSHQ_VERIFIC_EXTENSIONS
continue ;
}
# endif
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
const char * lib_name = nullptr ;
SetIter si ;
FOREACH_SET_ITEM ( veri_file : : GetAllLOptions ( ) , si , & lib_name ) {
VeriLibrary * veri_lib = veri_file : : GetLibrary ( lib_name , 0 ) ;
if ( veri_lib ) {
// Also elaborate all root modules since they may contain bind statements
MapIter mi ;
VeriModule * veri_module ;
FOREACH_VERILOG_MODULE_IN_LIBRARY ( veri_lib , mi , veri_module ) {
if ( ! veri_module - > IsRootModule ( ) ) continue ;
veri_modules . InsertLast ( veri_module ) ;
}
2023-10-05 16:40:43 +02:00
}
2024-06-17 14:49:58 +02:00
}
2021-10-20 10:02:58 +02:00
# endif
2024-05-21 17:08:07 +02:00
# ifdef VERIFIC_HIER_TREE_SUPPORT
2024-06-17 14:49:58 +02:00
if ( show_message )
log ( " Running hier_tree::Elaborate(). \n " ) ;
netlists = hier_tree : : Elaborate ( & veri_modules , & vhdl_units , parameters ) ;
2024-05-21 17:08:07 +02:00
# else
2024-06-07 14:58:33 +02:00
# if defined(VERIFIC_SYSTEMVERILOG_SUPPORT) && !defined(VERIFIC_VHDL_SUPPORT)
2024-06-17 14:49:58 +02:00
if ( show_message )
log ( " Running veri_file::ElaborateMultipleTop(). \n " ) ;
// SystemVerilog support only
netlists = veri_file : : ElaborateMultipleTop ( & veri_modules , parameters ) ;
2024-06-07 14:58:33 +02:00
# elif defined(VERIFIC_VHDL_SUPPORT) && !defined(VERIFIC_SYSTEMVERILOG_SUPPORT)
2024-06-17 14:49:58 +02:00
if ( show_message )
log ( " Running vhdl_file::Elaborate(). \n " ) ;
// VHDL support only
netlists = new Array ( top_mod_names . size ( ) ) ;
for ( auto & name : top_mod_names ) {
vhdl_file : : Elaborate ( name . c_str ( ) , work , 0 , parameters ) ;
2024-06-07 14:58:33 +02:00
netlists - > InsertLast ( Netlist : : PresentDesign ( ) ) ;
2024-06-17 14:49:58 +02:00
}
2024-06-11 08:57:02 +02:00
# elif defined(VERIFIC_SYSTEMVERILOG_SUPPORT) && defined(VERIFIC_VHDL_SUPPORT)
2024-06-17 14:49:58 +02:00
// Both SystemVerilog and VHDL support
if ( veri_modules . Size ( ) > 0 ) {
if ( show_message )
log ( " Running veri_file::ElaborateMultipleTop(). \n " ) ;
netlists = veri_file : : ElaborateMultipleTop ( & veri_modules , parameters ) ;
} else
netlists = new Array ( 1 ) ;
if ( vhdl_units . Size ( ) > 0 ) {
if ( show_message )
log ( " Running vhdl_file::Elaborate(). \n " ) ;
for ( auto & name : top_mod_names ) {
vhdl_file : : Elaborate ( name . c_str ( ) , work , 0 , parameters ) ;
2024-06-10 09:44:39 +02:00
netlists - > InsertLast ( Netlist : : PresentDesign ( ) ) ;
}
2024-06-17 14:49:58 +02:00
}
2024-06-11 08:57:02 +02:00
# else
2024-06-07 14:58:33 +02:00
# endif
2024-05-21 17:08:07 +02:00
# endif
2019-03-13 01:02:04 +01:00
}
Netlist * nl ;
int i ;
FOREACH_ARRAY_ITEM ( netlists , i , nl ) {
2023-01-17 12:58:08 +01:00
if ( ! nl ) continue ;
2024-06-17 14:49:58 +02:00
if ( ! top_mod_names . count ( nl - > CellBaseName ( ) ) )
2019-03-13 23:05:55 +01:00
continue ;
nl - > AddAtt ( new Att ( " \\ top " , NULL ) ) ;
2024-06-17 14:49:58 +02:00
nl_todo - > emplace ( nl - > CellBaseName ( ) , nl ) ;
2018-06-20 23:45:01 +02:00
}
2019-03-13 01:02:04 +01:00
delete netlists ;
2024-06-17 14:49:58 +02:00
return top_mod_names ;
}
2019-03-13 01:02:04 +01:00
2025-07-25 21:15:01 +02:00
static bool set_verific_global_flags = true ;
static bool already_imported = false ;
2024-06-17 14:49:58 +02:00
void verific_cleanup ( )
{
2022-06-30 11:19:01 +02:00
# ifdef YOSYSHQ_VERIFIC_EXTENSIONS
VerificExtensions : : Reset ( ) ;
# endif
2024-05-21 17:08:07 +02:00
# ifdef VERIFIC_HIER_TREE_SUPPORT
2022-03-30 17:25:53 +02:00
hier_tree : : DeleteHierarchicalTree ( ) ;
2024-05-21 17:08:07 +02:00
# endif
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2018-06-20 23:45:01 +02:00
veri_file : : Reset ( ) ;
2024-06-07 14:58:33 +02:00
# endif
2021-10-20 10:02:58 +02:00
# ifdef VERIFIC_VHDL_SUPPORT
2018-06-20 23:45:01 +02:00
vhdl_file : : Reset ( ) ;
2022-10-04 09:18:44 +02:00
# endif
# ifdef VERIFIC_EDIF_SUPPORT
edif_file : : Reset ( ) ;
2022-10-31 10:15:05 +01:00
# endif
# ifdef VERIFIC_LIBERTY_SUPPORT
synlib_file : : Reset ( ) ;
2021-10-20 10:02:58 +02:00
# endif
2018-06-20 23:45:01 +02:00
Libset : : Reset ( ) ;
2022-03-30 17:25:53 +02:00
Message : : Reset ( ) ;
RuntimeFlags : : DeleteAllFlags ( ) ;
2025-07-25 21:15:01 +02:00
set_verific_global_flags = true ;
2022-03-30 17:25:53 +02:00
LineFile : : DeleteAllLineFiles ( ) ;
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2018-07-16 18:46:06 +02:00
verific_incdirs . clear ( ) ;
verific_libdirs . clear ( ) ;
2022-06-09 08:57:48 +02:00
verific_libexts . clear ( ) ;
2024-06-07 14:58:33 +02:00
# endif
2018-06-20 23:45:01 +02:00
verific_import_pending = false ;
2024-06-17 14:49:58 +02:00
}
std : : string verific_import ( Design * design , const std : : map < std : : string , std : : string > & parameters , std : : string top )
{
verific_sva_fsm_limit = 16 ;
std : : map < std : : string , Netlist * > nl_todo , nl_done ;
Map verific_params ( STRING_HASH ) ;
for ( const auto & i : parameters )
verific_params . Insert ( i . first . c_str ( ) , i . second . c_str ( ) ) ;
std : : set < std : : string > top_mod_names ;
if ( top . empty ( ) ) {
import_all ( " work " , & nl_todo , & verific_params , false , " " ) ;
} else {
std : : vector < std : : string > tops ;
tops . push_back ( top ) ;
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
veri_file : : RemoveAllLOptions ( ) ;
veri_file : : AddLOption ( " work " ) ;
# endif
2024-07-29 15:50:38 +02:00
top_mod_names = import_tops ( " work " , & nl_todo , & verific_params , false , " " , tops , & top ) ;
2024-06-17 14:49:58 +02:00
}
2018-06-20 23:45:01 +02:00
2024-06-17 14:49:58 +02:00
if ( ! verific_error_msg . empty ( ) )
2025-09-11 07:25:26 +02:00
log_error ( " %s \n " , verific_error_msg ) ;
2024-06-17 14:49:58 +02:00
for ( auto nl : nl_todo )
nl . second - > ChangePortBusStructures ( 1 /* hierarchical */ ) ;
VerificExtNets worker ;
for ( auto nl : nl_todo )
worker . run ( nl . second ) ;
while ( ! nl_todo . empty ( ) ) {
auto it = nl_todo . begin ( ) ;
Netlist * nl = it - > second ;
if ( nl_done . count ( it - > first ) = = 0 ) {
2025-09-24 18:47:54 +02:00
VerificImporter importer ( false , false , false , false , false , false , false , false ) ;
2024-06-17 14:49:58 +02:00
nl_done [ it - > first ] = it - > second ;
importer . import_netlist ( design , nl , nl_todo , top_mod_names . count ( nl - > CellBaseName ( ) ) ) ;
}
nl_todo . erase ( it ) ;
}
verific_cleanup ( ) ;
2018-06-20 23:45:01 +02:00
if ( ! verific_error_msg . empty ( ) )
2025-09-11 07:25:26 +02:00
log_error ( " %s \n " , verific_error_msg ) ;
2022-11-25 13:02:11 +01:00
return top ;
2018-06-20 23:45:01 +02:00
}
2018-02-18 13:52:49 +01:00
YOSYS_NAMESPACE_END
2014-03-13 17:34:31 +01:00
# endif /* YOSYS_ENABLE_VERIFIC */
2014-03-09 20:40:04 +01:00
2018-02-18 13:52:49 +01:00
PRIVATE_NAMESPACE_BEGIN
2018-10-05 09:26:10 +02:00
# ifdef YOSYS_ENABLE_VERIFIC
2018-06-22 20:40:22 +02:00
bool check_noverific_env ( )
{
const char * e = getenv ( " YOSYS_NOVERIFIC " ) ;
if ( e = = nullptr )
return false ;
if ( atoi ( e ) = = 0 )
return false ;
return true ;
}
2018-10-05 09:26:10 +02:00
# endif
2018-06-22 20:40:22 +02:00
2014-03-09 20:40:04 +01:00
struct VerificPass : public Pass {
VerificPass ( ) : Pass ( " verific " , " load Verilog and VHDL designs using Verific " ) { }
2024-07-25 11:25:17 +02:00
# ifdef YOSYSHQ_VERIFIC_EXTENSIONS
void on_register ( ) override { VerificExtensions : : Reset ( ) ; }
# endif
2020-06-19 01:34:52 +02:00
void help ( ) override
2014-03-09 20:40:04 +01:00
{
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
log ( " \n " ) ;
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2017-07-28 15:32:54 +02:00
log ( " verific {-vlog95|-vlog2k|-sv2005|-sv2009|-sv2012|-sv} <verilog-file>.. \n " ) ;
2014-03-09 20:40:04 +01:00
log ( " \n " ) ;
log ( " Load the specified Verilog/SystemVerilog files into Verific. \n " ) ;
log ( " \n " ) ;
2018-03-14 20:22:11 +01:00
log ( " All files specified in one call to this command are one compilation unit. \n " ) ;
log ( " Files passed to different calls to this command are treated as belonging to \n " ) ;
log ( " different compilation units. \n " ) ;
log ( " \n " ) ;
2018-06-28 23:58:15 +02:00
log ( " Additional -D<macro>[=<value>] options may be added after the option indicating \n " ) ;
log ( " the language version (and before file names) to set additional verilog defines. \n " ) ;
2021-12-13 18:20:08 +01:00
log ( " The macros YOSYS, SYNTHESIS, and VERIFIC are defined implicitly. \n " ) ;
2018-06-28 23:58:15 +02:00
log ( " \n " ) ;
2014-03-09 20:40:04 +01:00
log ( " \n " ) ;
2018-06-29 10:02:27 +02:00
log ( " verific -formal <verilog-file>.. \n " ) ;
log ( " \n " ) ;
log ( " Like -sv, but define FORMAL instead of SYNTHESIS. \n " ) ;
log ( " \n " ) ;
2018-08-22 17:22:24 +02:00
log ( " \n " ) ;
2024-06-07 14:58:33 +02:00
# endif
2021-10-20 10:02:58 +02:00
# ifdef VERIFIC_VHDL_SUPPORT
2024-03-28 13:21:55 +01:00
log ( " verific {-vhdl87|-vhdl93|-vhdl2k|-vhdl2008|-vhdl2019|-vhdl} <vhdl-file>.. \n " ) ;
2014-03-09 20:40:04 +01:00
log ( " \n " ) ;
log ( " Load the specified VHDL files into Verific. \n " ) ;
log ( " \n " ) ;
log ( " \n " ) ;
2022-10-04 09:18:44 +02:00
# endif
# ifdef VERIFIC_EDIF_SUPPORT
log ( " verific {-edif} <edif-file>.. \n " ) ;
log ( " \n " ) ;
log ( " Load the specified EDIF files into Verific. \n " ) ;
log ( " \n " ) ;
log ( " \n " ) ;
2022-10-31 10:15:05 +01:00
# endif
# ifdef VERIFIC_LIBERTY_SUPPORT
log ( " verific {-liberty} <liberty-file>.. \n " ) ;
log ( " \n " ) ;
log ( " Load the specified Liberty files into Verific. \n " ) ;
2022-10-31 18:04:34 +01:00
log ( " Default library when -work is not present is one specified in liberty file. \n " ) ;
log ( " To use from SystemVerilog or VHDL use -L to specify liberty library. " ) ;
2022-10-31 10:15:05 +01:00
log ( " \n " ) ;
2022-10-31 10:51:28 +01:00
log ( " -lib \n " ) ;
log ( " only create empty blackbox modules \n " ) ;
log ( " \n " ) ;
2022-10-31 10:15:05 +01:00
log ( " \n " ) ;
2021-10-20 10:02:58 +02:00
# endif
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2022-05-23 19:57:21 +02:00
log ( " verific {-f|-F} [-vlog95|-vlog2k|-sv2005|-sv2009| \n " ) ;
log ( " -sv2012|-sv|-formal] <command-file> \n " ) ;
2021-06-16 11:21:44 +02:00
log ( " \n " ) ;
log ( " Load and execute the specified command file. \n " ) ;
2022-02-09 09:19:25 +01:00
log ( " Override verilog parsing mode can be set. \n " ) ;
log ( " The macros YOSYS, SYNTHESIS/FORMAL, and VERIFIC are defined implicitly. \n " ) ;
2021-06-16 11:21:44 +02:00
log ( " \n " ) ;
2022-05-23 19:35:14 +02:00
log ( " Command file parser supports following commands in file: \n " ) ;
log ( " +define+<MACRO>=<VALUE> - defines macro \n " ) ;
2022-05-23 19:57:21 +02:00
log ( " -u - upper case all identifier (makes Verilog parser \n " ) ;
log ( " case insensitive) \n " ) ;
2022-05-23 19:35:14 +02:00
log ( " -v <filepath> - register library name (file) \n " ) ;
log ( " -y <filepath> - register library name (directory) \n " ) ;
log ( " +incdir+<filepath> - specify include dir \n " ) ;
log ( " +libext+<filepath> - specify library extension \n " ) ;
log ( " +liborder+<id> - add library in ordered list \n " ) ;
2022-05-23 19:57:21 +02:00
log ( " +librescan - unresolved modules will be always searched \n " ) ;
log ( " starting with the first library specified \n " ) ;
log ( " by -y/-v options. \n " ) ;
2022-05-23 19:35:14 +02:00
log ( " -f/-file <filepath> - nested -f option \n " ) ;
log ( " -F <filepath> - nested -F option (relative path) \n " ) ;
log ( " parse files: \n " ) ;
log ( " <filepath> \n " ) ;
log ( " +systemverilogext+<filepath> \n " ) ;
log ( " +verilog1995ext+<filepath> \n " ) ;
log ( " +verilog2001ext+<filepath> \n " ) ;
2021-07-05 09:16:54 +02:00
log ( " \n " ) ;
2022-05-23 19:35:14 +02:00
log ( " analysis mode: \n " ) ;
2021-07-05 09:16:54 +02:00
log ( " -ams \n " ) ;
log ( " +v2k \n " ) ;
log ( " -sverilog \n " ) ;
log ( " \n " ) ;
2021-06-16 11:21:44 +02:00
log ( " \n " ) ;
2024-06-07 14:58:33 +02:00
# endif
2019-10-24 09:14:03 +02:00
log ( " verific [-work <libname>] {-sv|-vhdl|...} <hdl-file> \n " ) ;
2018-08-22 17:22:24 +02:00
log ( " \n " ) ;
log ( " Load the specified Verilog/SystemVerilog/VHDL file into the specified library. \n " ) ;
log ( " (default library when -work is not present: \" work \" ) \n " ) ;
log ( " \n " ) ;
log ( " \n " ) ;
2019-10-24 09:14:03 +02:00
log ( " verific [-L <libname>] {-sv|-vhdl|...} <hdl-file> \n " ) ;
log ( " \n " ) ;
log ( " Look up external definitions in the specified library. \n " ) ;
log ( " (-L may be used more than once) \n " ) ;
log ( " \n " ) ;
log ( " \n " ) ;
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2017-10-13 20:12:51 +02:00
log ( " verific -vlog-incdir <directory>.. \n " ) ;
log ( " \n " ) ;
log ( " Add Verilog include directories. \n " ) ;
log ( " \n " ) ;
log ( " \n " ) ;
2017-10-13 20:23:19 +02:00
log ( " verific -vlog-libdir <directory>.. \n " ) ;
log ( " \n " ) ;
log ( " Add Verilog library directories. Verific will search in this directories to \n " ) ;
log ( " find undefined modules. \n " ) ;
log ( " \n " ) ;
log ( " \n " ) ;
2022-06-09 08:57:48 +02:00
log ( " verific -vlog-libext <extension>.. \n " ) ;
log ( " \n " ) ;
log ( " Add Verilog library extensions, used when searching in library directories. \n " ) ;
log ( " \n " ) ;
log ( " \n " ) ;
2017-10-13 20:12:51 +02:00
log ( " verific -vlog-define <macro>[=<value>].. \n " ) ;
log ( " \n " ) ;
2018-06-29 10:02:27 +02:00
log ( " Add Verilog defines. \n " ) ;
2017-10-13 20:12:51 +02:00
log ( " \n " ) ;
log ( " \n " ) ;
2018-06-28 23:43:38 +02:00
log ( " verific -vlog-undef <macro>.. \n " ) ;
log ( " \n " ) ;
log ( " Remove Verilog defines previously set with -vlog-define. \n " ) ;
log ( " \n " ) ;
log ( " \n " ) ;
2024-06-07 14:58:33 +02:00
# endif
2018-08-16 11:49:17 +02:00
log ( " verific -set-error <msg_id>.. \n " ) ;
log ( " verific -set-warning <msg_id>.. \n " ) ;
log ( " verific -set-info <msg_id>.. \n " ) ;
log ( " verific -set-ignore <msg_id>.. \n " ) ;
log ( " \n " ) ;
log ( " Set message severity. <msg_id> is the string in square brackets when a message \n " ) ;
log ( " is printed, such as VERI-1209. \n " ) ;
2022-11-30 16:42:37 +01:00
log ( " Also errors, warnings, infos and comments could be used to set new severity for \n " ) ;
log ( " all messages of certain type. \n " ) ;
2018-08-16 11:49:17 +02:00
log ( " \n " ) ;
log ( " \n " ) ;
2022-11-25 14:27:30 +01:00
log ( " verific -import [options] <top>.. \n " ) ;
2014-03-09 20:40:04 +01:00
log ( " \n " ) ;
2022-11-25 14:27:30 +01:00
log ( " Elaborate the design for the specified top modules or configurations, import to \n " ) ;
log ( " Yosys and reset the internal state of Verific. \n " ) ;
2017-07-24 11:29:06 +02:00
log ( " \n " ) ;
2017-07-24 13:57:16 +02:00
log ( " Import options: \n " ) ;
log ( " \n " ) ;
2017-07-25 13:33:25 +02:00
log ( " -all \n " ) ;
log ( " Elaborate all modules, not just the hierarchy below the given top \n " ) ;
log ( " modules. With this option the list of modules to import is optional. \n " ) ;
log ( " \n " ) ;
2017-07-24 13:57:16 +02:00
log ( " -gates \n " ) ;
log ( " Create a gate-level netlist. \n " ) ;
2017-07-24 11:29:06 +02:00
log ( " \n " ) ;
2017-07-24 13:57:16 +02:00
log ( " -flatten \n " ) ;
log ( " Flatten the design in Verific before importing. \n " ) ;
2017-07-24 11:29:06 +02:00
log ( " \n " ) ;
2017-07-25 14:53:11 +02:00
log ( " -extnets \n " ) ;
log ( " Resolve references to external nets by adding module ports as needed. \n " ) ;
log ( " \n " ) ;
2024-01-30 16:33:44 +01:00
log ( " -no-split-complex-ports \n " ) ;
log ( " Complex ports (structs or arrays) are not split and remain packed as a single port. \n " ) ;
log ( " \n " ) ;
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2018-04-06 14:10:57 +02:00
log ( " -autocover \n " ) ;
log ( " Generate automatic cover statements for all asserts \n " ) ;
log ( " \n " ) ;
2024-06-07 14:58:33 +02:00
# endif
2019-08-07 15:31:49 +02:00
log ( " -fullinit \n " ) ;
log ( " Keep all register initializations, even those for non-FF registers. \n " ) ;
log ( " \n " ) ;
2022-10-14 16:54:57 +02:00
log ( " -cells \n " ) ;
log ( " Import all cell definitions from Verific loaded libraries even if they are \n " ) ;
2022-10-31 10:15:05 +01:00
log ( " unused in design. Useful with \" -edif \" and \" -liberty \" option. \n " ) ;
2022-10-14 16:54:57 +02:00
log ( " \n " ) ;
2019-03-09 02:54:01 +01:00
log ( " -chparam name value \n " ) ;
log ( " Elaborate the specified top modules (all modules when -all given) using \n " ) ;
2019-03-09 02:56:16 +01:00
log ( " this parameter value. Modules on which this parameter does not exist will \n " ) ;
log ( " cause Verific to produce a VERI-1928 or VHDL-1676 message. This option \n " ) ;
2019-03-09 02:54:01 +01:00
log ( " can be specified multiple times to override multiple parameters. \n " ) ;
log ( " String values must be passed in double quotes ( \" ). \n " ) ;
log ( " \n " ) ;
2018-03-01 11:40:43 +01:00
log ( " -v, -vv \n " ) ;
log ( " Verbose log messages. (-vv is even more verbose than -v.) \n " ) ;
2022-07-04 11:09:06 +02:00
log ( " \n " ) ;
2022-06-30 11:19:01 +02:00
log ( " -pp <filename> \n " ) ;
log ( " Pretty print design after elaboration to specified file. \n " ) ;
2017-07-24 13:57:16 +02:00
log ( " \n " ) ;
2017-07-28 17:37:09 +02:00
log ( " The following additional import options are useful for debugging the Verific \n " ) ;
log ( " bindings (for Yosys and/or Verific developers): \n " ) ;
log ( " \n " ) ;
2017-07-24 13:57:16 +02:00
log ( " -k \n " ) ;
log ( " Keep going after an unsupported verific primitive is found. The \n " ) ;
log ( " unsupported primitive is added as blockbox module to the design. \n " ) ;
2017-07-27 11:54:45 +02:00
log ( " This will also add all SVA related cells to the design parallel to \n " ) ;
log ( " the checker logic inferred by it. \n " ) ;
log ( " \n " ) ;
2018-03-07 19:40:34 +01:00
log ( " -V \n " ) ;
log ( " Import Verific netlist as-is without translating to Yosys cell types. \n " ) ;
log ( " \n " ) ;
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2017-10-10 15:16:39 +02:00
log ( " -nosva \n " ) ;
2017-10-20 13:14:04 +02:00
log ( " Ignore SVA properties, do not infer checker logic. \n " ) ;
2017-10-10 15:16:39 +02:00
log ( " \n " ) ;
2025-09-24 18:47:54 +02:00
log ( " -sva-continue-on-err \n " ) ;
log ( " Turns unsupported SVA from an error into a warning. Properties are imported \n " ) ;
log ( " with their trigger condition replaced with 'x and with an `unsupported_sva' \n " ) ;
log ( " attribute to produce a later error in SBY if they remain in the design. \n " ) ;
log ( " \n " ) ;
2018-09-04 20:06:10 +02:00
log ( " -L <int> \n " ) ;
log ( " Maximum number of ctrl bits for SVA checker FSMs (default=16). \n " ) ;
log ( " \n " ) ;
2024-06-07 14:58:33 +02:00
# endif
2017-07-27 11:54:45 +02:00
log ( " -n \n " ) ;
log ( " Keep all Verific names on instances and nets. By default only \n " ) ;
log ( " user-declared names are preserved. \n " ) ;
2017-07-24 13:57:16 +02:00
log ( " \n " ) ;
log ( " -d <dump_file> \n " ) ;
log ( " Dump the Verific netlist as a verilog file. \n " ) ;
2014-03-09 20:40:04 +01:00
log ( " \n " ) ;
2019-12-18 13:06:34 +01:00
log ( " \n " ) ;
2020-08-26 10:39:57 +02:00
log ( " verific [-work <libname>] -pp [options] <filename> [<module>].. \n " ) ;
log ( " \n " ) ;
log ( " Pretty print design (or just module) to the specified file from the \n " ) ;
log ( " specified library. (default library when -work is not present: \" work \" ) \n " ) ;
log ( " \n " ) ;
log ( " Pretty print options: \n " ) ;
log ( " \n " ) ;
log ( " -verilog \n " ) ;
log ( " Save output for Verilog/SystemVerilog design modules (default). \n " ) ;
log ( " \n " ) ;
log ( " -vhdl \n " ) ;
log ( " Save output for VHDL design units. \n " ) ;
2021-11-01 10:41:51 +01:00
log ( " \n " ) ;
log ( " \n " ) ;
log ( " verific -cfg [<name> [<value>]] \n " ) ;
log ( " \n " ) ;
log ( " Get/set Verific runtime flags. \n " ) ;
log ( " \n " ) ;
log ( " \n " ) ;
2022-06-30 11:19:01 +02:00
# if defined(YOSYS_ENABLE_VERIFIC) and defined(YOSYSHQ_VERIFIC_EXTENSIONS)
VerificExtensions : : Help ( ) ;
# endif
2021-01-20 20:48:10 +01:00
log ( " Use YosysHQ Tabby CAD Suite if you need Yosys+Verific. \n " ) ;
log ( " https://www.yosyshq.com/ \n " ) ;
2019-12-18 13:06:34 +01:00
log ( " \n " ) ;
2021-01-20 20:48:10 +01:00
log ( " Contact office@yosyshq.com for free evaluation \n " ) ;
log ( " binaries of YosysHQ Tabby CAD Suite. \n " ) ;
2014-03-09 20:40:04 +01:00
log ( " \n " ) ;
}
2014-03-13 17:34:31 +01:00
# ifdef YOSYS_ENABLE_VERIFIC
2022-09-28 15:56:46 +02:00
std : : string frontent_rewrite ( std : : vector < std : : string > & args , int & argidx , std : : vector < std : : string > & tmp_files )
{
std : : string filename = args [ argidx + + ] ;
//Accommodate heredocs with EOT marker spaced out from "<<", e.g. "<< EOT" vs. "<<EOT"
if ( filename = = " << " & & ( argidx < GetSize ( args ) ) ) {
filename + = args [ argidx + + ] ;
}
if ( filename . compare ( 0 , 2 , " << " ) = = 0 ) {
if ( filename . size ( ) < = 2 )
log_error ( " Missing EOT marker in here document! \n " ) ;
std : : string eot_marker = filename . substr ( 2 ) ;
if ( Frontend : : current_script_file = = nullptr )
filename = " <stdin> " ;
std : : string last_here_document ;
while ( 1 ) {
std : : string buffer ;
char block [ 4096 ] ;
while ( 1 ) {
if ( fgets ( block , 4096 , Frontend : : current_script_file = = nullptr ? stdin : Frontend : : current_script_file ) = = nullptr )
2025-09-11 07:25:26 +02:00
log_error ( " Unexpected end of file in here document '%s'! \n " , filename ) ;
2022-09-28 15:56:46 +02:00
buffer + = block ;
if ( buffer . size ( ) > 0 & & ( buffer [ buffer . size ( ) - 1 ] = = ' \n ' | | buffer [ buffer . size ( ) - 1 ] = = ' \r ' ) )
break ;
}
size_t indent = buffer . find_first_not_of ( " \t \r \n " ) ;
if ( indent ! = std : : string : : npos & & buffer . compare ( indent , eot_marker . size ( ) , eot_marker ) = = 0 )
break ;
last_here_document + = buffer ;
}
filename = make_temp_file ( ) ;
tmp_files . push_back ( filename ) ;
std : : ofstream file ( filename ) ;
file < < last_here_document ;
} else {
rewrite_filename ( filename ) ;
}
return filename ;
}
2023-07-31 09:18:54 +02:00
2024-12-06 15:59:09 +01:00
# ifdef VERIFIC_VHDL_SUPPORT
2023-07-24 12:41:57 +02:00
void add_units_to_map ( Map & map , std : : string work , bool flag_lib )
{
MapIter mi ;
VhdlPrimaryUnit * unit ;
2023-07-31 09:18:54 +02:00
if ( ! flag_lib ) return ;
VhdlLibrary * vhdl_lib = vhdl_file : : GetLibrary ( work . c_str ( ) , 1 ) ;
if ( vhdl_lib ) {
FOREACH_VHDL_PRIMARY_UNIT ( vhdl_lib , mi , unit ) {
if ( ! unit ) continue ;
map . Insert ( unit , unit ) ;
2023-07-24 12:41:57 +02:00
}
}
2024-12-06 15:59:09 +01:00
save_blackbox_msg_state ( ) ;
2023-07-24 12:41:57 +02:00
}
void set_units_to_blackbox ( Map & map , std : : string work , bool flag_lib )
{
MapIter mi ;
VhdlPrimaryUnit * unit ;
if ( ! flag_lib ) return ;
VhdlLibrary * vhdl_lib = vhdl_file : : GetLibrary ( work . c_str ( ) , 1 ) ;
FOREACH_VHDL_PRIMARY_UNIT ( vhdl_lib , mi , unit ) {
if ( ! unit ) continue ;
if ( ! map . GetValue ( unit ) ) {
unit - > SetCompileAsBlackbox ( ) ;
}
}
2024-12-06 15:59:09 +01:00
restore_blackbox_msg_state ( ) ;
2023-07-24 12:41:57 +02:00
}
# endif
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2023-07-24 12:41:57 +02:00
void add_modules_to_map ( Map & map , std : : string work , bool flag_lib )
{
MapIter mi ;
VeriModule * veri_module ;
2023-07-31 09:18:54 +02:00
if ( ! flag_lib ) return ;
VeriLibrary * veri_lib = veri_file : : GetLibrary ( work . c_str ( ) , 1 ) ;
if ( veri_lib ) {
FOREACH_VERILOG_MODULE_IN_LIBRARY ( veri_lib , mi , veri_module ) {
if ( ! veri_module ) continue ;
map . Insert ( veri_module , veri_module ) ;
2023-07-24 12:41:57 +02:00
}
}
2024-12-06 15:59:09 +01:00
save_blackbox_msg_state ( ) ;
2023-07-24 12:41:57 +02:00
}
void set_modules_to_blackbox ( Map & map , std : : string work , bool flag_lib )
{
MapIter mi ;
VeriModule * veri_module ;
if ( ! flag_lib ) return ;
VeriLibrary * veri_lib = veri_file : : GetLibrary ( work . c_str ( ) , 1 ) ;
FOREACH_VERILOG_MODULE_IN_LIBRARY ( veri_lib , mi , veri_module ) {
if ( ! veri_module ) continue ;
if ( ! map . GetValue ( veri_module ) ) {
veri_module - > SetCompileAsBlackbox ( ) ;
}
}
2025-04-01 17:35:59 +02:00
restore_blackbox_msg_state ( ) ;
2023-07-24 12:41:57 +02:00
}
2024-06-07 14:58:33 +02:00
# endif
2023-07-24 12:41:57 +02:00
2020-06-19 01:34:52 +02:00
void execute ( std : : vector < std : : string > args , RTLIL : : Design * design ) override
2014-03-09 20:40:04 +01:00
{
2022-06-21 18:06:16 +02:00
2018-06-22 20:40:22 +02:00
if ( check_noverific_env ( ) )
2019-12-18 13:06:34 +01:00
log_cmd_error ( " This version of Yosys is built without Verific support. \n "
" \n "
2021-01-20 20:48:10 +01:00
" Use YosysHQ Tabby CAD Suite if you need Yosys+Verific. \n "
" https://www.yosyshq.com/ \n "
2019-12-18 13:06:34 +01:00
" \n "
2021-01-20 20:48:10 +01:00
" Contact office@yosyshq.com for free evaluation \n "
" binaries of YosysHQ Tabby CAD Suite. \n " ) ;
2018-06-22 20:40:22 +02:00
2017-07-26 18:00:01 +02:00
log_header ( design , " Executing VERIFIC (loading SystemVerilog and VHDL designs using Verific). \n " ) ;
2014-03-09 20:40:04 +01:00
2022-06-21 18:06:16 +02:00
if ( set_verific_global_flags )
{
Message : : SetConsoleOutput ( 0 ) ;
Message : : RegisterCallBackMsg ( msg_func ) ;
RuntimeFlags : : SetVar ( " db_preserve_user_instances " , 1 ) ;
RuntimeFlags : : SetVar ( " db_preserve_user_nets " , 1 ) ;
RuntimeFlags : : SetVar ( " db_preserve_x " , 1 ) ;
RuntimeFlags : : SetVar ( " db_allow_external_nets " , 1 ) ;
RuntimeFlags : : SetVar ( " db_infer_wide_operators " , 1 ) ;
RuntimeFlags : : SetVar ( " db_infer_set_reset_registers " , 0 ) ;
2023-09-12 11:56:15 +02:00
// Properly respect order of read and write for rams
RuntimeFlags : : SetVar ( " db_change_inplace_ram_blocking_write_before_read " , 1 ) ;
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2022-06-21 18:06:16 +02:00
RuntimeFlags : : SetVar ( " veri_extract_dualport_rams " , 0 ) ;
RuntimeFlags : : SetVar ( " veri_extract_multiport_rams " , 1 ) ;
RuntimeFlags : : SetVar ( " veri_allow_any_ram_in_loop " , 1 ) ;
2025-07-02 11:54:19 +02:00
RuntimeFlags : : SetVar ( " veri_replace_const_exprs " , 1 ) ;
2024-06-07 14:58:33 +02:00
# endif
2022-06-21 18:06:16 +02:00
# ifdef VERIFIC_VHDL_SUPPORT
RuntimeFlags : : SetVar ( " vhdl_extract_dualport_rams " , 0 ) ;
RuntimeFlags : : SetVar ( " vhdl_extract_multiport_rams " , 1 ) ;
RuntimeFlags : : SetVar ( " vhdl_allow_any_ram_in_loop " , 1 ) ;
2025-07-02 11:54:19 +02:00
RuntimeFlags : : SetVar ( " vhdl_replace_const_exprs " , 1 ) ;
2022-06-21 18:06:16 +02:00
RuntimeFlags : : SetVar ( " vhdl_support_variable_slice " , 1 ) ;
RuntimeFlags : : SetVar ( " vhdl_ignore_assertion_statements " , 0 ) ;
RuntimeFlags : : SetVar ( " vhdl_preserve_assignments " , 1 ) ;
//RuntimeFlags::SetVar("vhdl_preserve_comments", 1);
RuntimeFlags : : SetVar ( " vhdl_preserve_drivers " , 1 ) ;
# endif
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2022-06-21 18:06:16 +02:00
RuntimeFlags : : SetVar ( " veri_preserve_assignments " , 1 ) ;
RuntimeFlags : : SetVar ( " veri_preserve_comments " , 1 ) ;
RuntimeFlags : : SetVar ( " veri_preserve_drivers " , 1 ) ;
// Workaround for VIPER #13851
RuntimeFlags : : SetVar ( " veri_create_name_for_unnamed_gen_block " , 1 ) ;
// WARNING: instantiating unknown module 'XYZ' (VERI-1063)
Message : : SetMessageType ( " VERI-1063 " , VERIFIC_ERROR ) ;
2025-06-06 16:30:50 +02:00
// Downgrade warnings about things that are normal
// VERIFIC-WARNING [VERI-1209] foo.sv:98: expression size 7 truncated to fit in target size 6
Message : : SetMessageType ( " VERI-1209 " , VERIFIC_INFO ) ;
// VERIFIC-WARNING [VERI-1142] foo.sv:55: system task 'display' is ignored for synthesis
Message : : SetMessageType ( " VERI-1142 " , VERIFIC_INFO ) ;
// VERIFIC-WARNING [VERI-2418] foo.svh:503: parameter 'all_cfgs_gp' declared inside package 'bp_common_pkg' shall be treated as localparam
Message : : SetMessageType ( " VERI-2418 " , VERIFIC_INFO ) ;
2022-06-21 18:06:16 +02:00
// https://github.com/YosysHQ/yosys/issues/1055
RuntimeFlags : : SetVar ( " veri_elaborate_top_level_modules_having_interface_ports " , 1 ) ;
2024-06-07 14:58:33 +02:00
# endif
2022-06-21 18:06:16 +02:00
RuntimeFlags : : SetVar ( " verific_produce_verbose_syntax_error_message " , 1 ) ;
# ifndef DB_PRESERVE_INITIAL_VALUE
# warning Verific was built without DB_PRESERVE_INITIAL_VALUE.
# endif
set_verific_global_flags = false ;
}
2018-07-22 18:44:05 +02:00
2018-03-01 11:40:43 +01:00
verific_verbose = 0 ;
2018-09-04 20:06:10 +02:00
verific_sva_fsm_limit = 16 ;
2018-02-28 11:45:04 +01:00
2017-07-04 20:01:30 +02:00
const char * release_str = Message : : ReleaseString ( ) ;
time_t release_time = Message : : ReleaseDate ( ) ;
char * release_tmstr = ctime ( & release_time ) ;
2022-09-28 15:56:46 +02:00
std : : vector < std : : string > tmp_files ;
2017-07-04 20:01:30 +02:00
if ( release_str = = nullptr )
release_str = " (no release string) " ;
for ( char * p = release_tmstr ; * p ; p + + )
if ( * p = = ' \n ' ) * p = 0 ;
log ( " Built with Verific %s, released at %s. \n " , release_str , release_tmstr ) ;
2017-07-22 16:16:44 +02:00
int argidx = 1 ;
2018-08-22 13:30:22 +02:00
std : : string work = " work " ;
2022-10-31 10:15:05 +01:00
bool is_work_set = false ;
2023-10-03 15:52:01 +02:00
( void ) is_work_set ;
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2022-09-07 09:48:19 +02:00
veri_file : : RegisterCallBackVerificStream ( & verific_read_cb ) ;
2024-06-07 14:58:33 +02:00
# endif
2018-08-16 11:49:17 +02:00
if ( GetSize ( args ) > argidx & & ( args [ argidx ] = = " -set-error " | | args [ argidx ] = = " -set-warning " | |
args [ argidx ] = = " -set-info " | | args [ argidx ] = = " -set-ignore " ) )
{
msg_type_t new_type ;
if ( args [ argidx ] = = " -set-error " )
new_type = VERIFIC_ERROR ;
else if ( args [ argidx ] = = " -set-warning " )
new_type = VERIFIC_WARNING ;
else if ( args [ argidx ] = = " -set-info " )
new_type = VERIFIC_INFO ;
else if ( args [ argidx ] = = " -set-ignore " )
new_type = VERIFIC_IGNORE ;
else
log_abort ( ) ;
2022-11-30 16:42:37 +01:00
for ( argidx + + ; argidx < GetSize ( args ) ; argidx + + ) {
2022-12-02 17:11:17 +01:00
if ( Strings : : compare ( args [ argidx ] . c_str ( ) , " errors " ) ) {
Message : : SetMessageType ( " VERI-1063 " , new_type ) ;
2022-11-30 16:42:37 +01:00
Message : : SetAllMessageType ( VERIFIC_ERROR , new_type ) ;
2022-12-02 17:11:17 +01:00
} else if ( Strings : : compare ( args [ argidx ] . c_str ( ) , " warnings " ) ) {
2022-11-30 16:42:37 +01:00
Message : : SetAllMessageType ( VERIFIC_WARNING , new_type ) ;
2022-12-02 17:11:17 +01:00
} else if ( Strings : : compare ( args [ argidx ] . c_str ( ) , " infos " ) ) {
2025-06-06 16:30:50 +02:00
Message : : SetMessageType ( " VERI-1209 " , new_type ) ;
Message : : SetMessageType ( " VERI-1142 " , new_type ) ;
Message : : SetMessageType ( " VERI-2418 " , new_type ) ;
2022-11-30 16:42:37 +01:00
Message : : SetAllMessageType ( VERIFIC_INFO , new_type ) ;
2022-12-02 17:11:17 +01:00
} else if ( Strings : : compare ( args [ argidx ] . c_str ( ) , " comments " ) ) {
2022-11-30 16:42:37 +01:00
Message : : SetAllMessageType ( VERIFIC_COMMENT , new_type ) ;
2022-12-02 17:11:17 +01:00
} else {
2022-11-30 16:42:37 +01:00
Message : : SetMessageType ( args [ argidx ] . c_str ( ) , new_type ) ;
2022-12-02 17:11:17 +01:00
}
2022-11-30 16:42:37 +01:00
}
2018-08-16 11:49:17 +02:00
goto check_error ;
}
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2017-10-13 20:12:51 +02:00
if ( GetSize ( args ) > argidx & & args [ argidx ] = = " -vlog-incdir " ) {
for ( argidx + + ; argidx < GetSize ( args ) ; argidx + + )
2018-07-16 18:46:06 +02:00
verific_incdirs . push_back ( args [ argidx ] ) ;
2017-10-13 20:12:51 +02:00
goto check_error ;
}
2017-10-13 20:23:19 +02:00
if ( GetSize ( args ) > argidx & & args [ argidx ] = = " -vlog-libdir " ) {
for ( argidx + + ; argidx < GetSize ( args ) ; argidx + + )
2018-07-16 18:46:06 +02:00
verific_libdirs . push_back ( args [ argidx ] ) ;
2017-10-13 20:23:19 +02:00
goto check_error ;
}
2022-06-09 08:57:48 +02:00
if ( GetSize ( args ) > argidx & & args [ argidx ] = = " -vlog-libext " ) {
for ( argidx + + ; argidx < GetSize ( args ) ; argidx + + )
verific_libexts . push_back ( args [ argidx ] ) ;
goto check_error ;
}
2017-10-13 20:12:51 +02:00
if ( GetSize ( args ) > argidx & & args [ argidx ] = = " -vlog-define " ) {
for ( argidx + + ; argidx < GetSize ( args ) ; argidx + + ) {
string name = args [ argidx ] ;
size_t equal = name . find ( ' = ' ) ;
if ( equal ! = std : : string : : npos ) {
string value = name . substr ( equal + 1 ) ;
name = name . substr ( 0 , equal ) ;
veri_file : : DefineCmdLineMacro ( name . c_str ( ) , value . c_str ( ) ) ;
} else {
veri_file : : DefineCmdLineMacro ( name . c_str ( ) ) ;
}
}
goto check_error ;
}
2018-06-28 23:43:38 +02:00
if ( GetSize ( args ) > argidx & & args [ argidx ] = = " -vlog-undef " ) {
for ( argidx + + ; argidx < GetSize ( args ) ; argidx + + ) {
string name = args [ argidx ] ;
veri_file : : UndefineMacro ( name . c_str ( ) ) ;
}
goto check_error ;
}
2019-10-24 09:14:03 +02:00
veri_file : : RemoveAllLOptions ( ) ;
2024-06-11 08:57:02 +02:00
# endif
2023-10-03 15:52:01 +02:00
for ( int i = argidx ; i < GetSize ( args ) ; i + + )
{
if ( args [ i ] = = " -work " & & i + 1 < GetSize ( args ) ) {
work = args [ + + i ] ;
is_work_set = true ;
continue ;
}
2024-06-11 08:57:02 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2023-10-03 15:52:01 +02:00
if ( args [ i ] = = " -L " & & i + 1 < GetSize ( args ) ) {
+ + i ;
continue ;
}
2024-06-11 08:57:02 +02:00
# endif
2023-10-03 15:52:01 +02:00
break ;
}
2024-06-11 08:57:02 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2023-10-03 15:52:01 +02:00
veri_file : : AddLOption ( work . c_str ( ) ) ;
2024-06-11 08:57:02 +02:00
# endif
2022-10-10 00:47:42 +02:00
for ( int i = argidx ; i < GetSize ( args ) ; i + + )
{
if ( args [ i ] = = " -work " & & i + 1 < GetSize ( args ) ) {
+ + i ;
continue ;
}
2024-06-11 08:57:02 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2022-10-10 00:47:42 +02:00
if ( args [ i ] = = " -L " & & i + 1 < GetSize ( args ) ) {
2023-10-03 15:52:01 +02:00
if ( args [ + + i ] = = work )
2022-10-10 00:47:42 +02:00
veri_file : : RemoveAllLOptions ( ) ;
continue ;
}
2024-06-11 08:57:02 +02:00
# endif
2022-10-10 00:47:42 +02:00
break ;
}
2018-08-22 13:30:22 +02:00
for ( ; argidx < GetSize ( args ) ; argidx + + )
{
if ( args [ argidx ] = = " -work " & & argidx + 1 < GetSize ( args ) ) {
work = args [ + + argidx ] ;
2022-10-31 10:15:05 +01:00
is_work_set = true ;
2018-08-22 13:30:22 +02:00
continue ;
}
2024-06-11 08:57:02 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2019-10-24 09:14:03 +02:00
if ( args [ argidx ] = = " -L " & & argidx + 1 < GetSize ( args ) ) {
veri_file : : AddLOption ( args [ + + argidx ] . c_str ( ) ) ;
continue ;
}
2024-06-11 08:57:02 +02:00
# endif
2018-08-22 13:30:22 +02:00
break ;
}
2024-06-11 08:57:02 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2021-06-16 11:21:44 +02:00
if ( GetSize ( args ) > argidx & & ( args [ argidx ] = = " -f " | | args [ argidx ] = = " -F " ) )
{
2022-05-23 19:13:45 +02:00
unsigned verilog_mode = veri_file : : UNDEFINED ;
2022-02-09 09:19:25 +01:00
bool is_formal = false ;
const char * filename = nullptr ;
2021-06-16 11:21:44 +02:00
Verific : : veri_file : : f_file_flags flags = ( args [ argidx ] = = " -f " ) ? veri_file : : F_FILE_NONE : veri_file : : F_FILE_CAPITAL ;
2022-02-09 09:19:25 +01:00
for ( argidx + + ; argidx < GetSize ( args ) ; argidx + + ) {
if ( args [ argidx ] = = " -vlog95 " ) {
verilog_mode = veri_file : : VERILOG_95 ;
continue ;
} else if ( args [ argidx ] = = " -vlog2k " ) {
verilog_mode = veri_file : : VERILOG_2K ;
continue ;
} else if ( args [ argidx ] = = " -sv2005 " ) {
verilog_mode = veri_file : : SYSTEM_VERILOG_2005 ;
continue ;
} else if ( args [ argidx ] = = " -sv2009 " ) {
verilog_mode = veri_file : : SYSTEM_VERILOG_2009 ;
continue ;
} else if ( args [ argidx ] = = " -sv2012 " | | args [ argidx ] = = " -sv " | | args [ argidx ] = = " -formal " ) {
verilog_mode = veri_file : : SYSTEM_VERILOG ;
if ( args [ argidx ] = = " -formal " ) is_formal = true ;
continue ;
} else if ( args [ argidx ] . compare ( 0 , 1 , " - " ) = = 0 ) {
cmd_error ( args , argidx , " unknown option " ) ;
goto check_error ;
}
if ( ! filename ) {
filename = args [ argidx ] . c_str ( ) ;
continue ;
} else {
log_cmd_error ( " Only one filename can be specified. \n " ) ;
}
}
if ( ! filename )
log_cmd_error ( " Filname must be specified. \n " ) ;
unsigned analysis_mode = verilog_mode ; // keep default as provided by user if not defined in file
Array * file_names = veri_file : : ProcessFFile ( filename , flags , analysis_mode ) ;
if ( analysis_mode ! = verilog_mode )
log_warning ( " Provided verilog mode differs from one specified in file. \n " ) ;
veri_file : : DefineMacro ( " YOSYS " ) ;
2021-06-16 11:21:44 +02:00
veri_file : : DefineMacro ( " VERIFIC " ) ;
2022-02-09 09:19:25 +01:00
veri_file : : DefineMacro ( is_formal ? " FORMAL " : " SYNTHESIS " ) ;
2021-06-16 11:21:44 +02:00
2022-05-23 19:13:45 +02:00
if ( ! veri_file : : AnalyzeMultipleFiles ( file_names , analysis_mode , work . c_str ( ) , veri_file : : MFCU ) ) {
2021-06-16 11:21:44 +02:00
verific_error_msg . clear ( ) ;
log_cmd_error ( " Reading Verilog/SystemVerilog sources failed. \n " ) ;
}
delete file_names ;
verific_import_pending = true ;
goto check_error ;
}
2018-03-14 20:22:11 +01:00
if ( GetSize ( args ) > argidx & & ( args [ argidx ] = = " -vlog95 " | | args [ argidx ] = = " -vlog2k " | | args [ argidx ] = = " -sv2005 " | |
2018-06-29 10:02:27 +02:00
args [ argidx ] = = " -sv2009 " | | args [ argidx ] = = " -sv2012 " | | args [ argidx ] = = " -sv " | | args [ argidx ] = = " -formal " ) )
2018-03-14 20:22:11 +01:00
{
Array file_names ;
unsigned verilog_mode ;
if ( args [ argidx ] = = " -vlog95 " )
verilog_mode = veri_file : : VERILOG_95 ;
else if ( args [ argidx ] = = " -vlog2k " )
verilog_mode = veri_file : : VERILOG_2K ;
else if ( args [ argidx ] = = " -sv2005 " )
verilog_mode = veri_file : : SYSTEM_VERILOG_2005 ;
else if ( args [ argidx ] = = " -sv2009 " )
verilog_mode = veri_file : : SYSTEM_VERILOG_2009 ;
2018-06-29 10:02:27 +02:00
else if ( args [ argidx ] = = " -sv2012 " | | args [ argidx ] = = " -sv " | | args [ argidx ] = = " -formal " )
2018-03-14 20:22:11 +01:00
verilog_mode = veri_file : : SYSTEM_VERILOG ;
else
log_abort ( ) ;
2014-03-09 20:40:04 +01:00
2021-12-13 18:20:08 +01:00
veri_file : : DefineMacro ( " YOSYS " ) ;
2018-06-29 10:02:27 +02:00
veri_file : : DefineMacro ( " VERIFIC " ) ;
veri_file : : DefineMacro ( args [ argidx ] = = " -formal " ? " FORMAL " : " SYNTHESIS " ) ;
2019-08-07 21:20:08 +02:00
for ( argidx + + ; argidx < GetSize ( args ) & & GetSize ( args [ argidx ] ) > = 2 & & args [ argidx ] . compare ( 0 , 2 , " -D " ) = = 0 ; argidx + + ) {
2018-06-28 23:58:15 +02:00
std : : string name = args [ argidx ] . substr ( 2 ) ;
if ( args [ argidx ] = = " -D " ) {
if ( + + argidx > = GetSize ( args ) )
break ;
name = args [ argidx ] ;
}
size_t equal = name . find ( ' = ' ) ;
if ( equal ! = std : : string : : npos ) {
string value = name . substr ( equal + 1 ) ;
name = name . substr ( 0 , equal ) ;
veri_file : : DefineMacro ( name . c_str ( ) , value . c_str ( ) ) ;
} else {
veri_file : : DefineMacro ( name . c_str ( ) ) ;
}
}
2018-07-16 18:46:06 +02:00
for ( auto & dir : verific_incdirs )
veri_file : : AddIncludeDir ( dir . c_str ( ) ) ;
for ( auto & dir : verific_libdirs )
veri_file : : AddYDir ( dir . c_str ( ) ) ;
2022-06-09 08:57:48 +02:00
for ( auto & ext : verific_libexts )
veri_file : : AddLibExt ( ext . c_str ( ) ) ;
2018-07-16 18:46:06 +02:00
2023-07-24 12:41:57 +02:00
bool flag_lib = false ;
2022-08-08 11:57:28 +02:00
while ( argidx < GetSize ( args ) ) {
2023-07-24 12:41:57 +02:00
if ( args [ argidx ] = = " -lib " ) {
flag_lib = true ;
argidx + + ;
continue ;
}
if ( args [ argidx ] . compare ( 0 , 1 , " - " ) = = 0 ) {
cmd_error ( args , argidx , " unknown option " ) ;
goto check_error ;
}
2022-09-28 15:56:46 +02:00
std : : string filename = frontent_rewrite ( args , argidx , tmp_files ) ;
2022-08-08 11:57:28 +02:00
file_names . Insert ( strdup ( filename . c_str ( ) ) ) ;
}
2023-07-24 12:41:57 +02:00
Map map ( POINTER_HASH ) ;
add_modules_to_map ( map , work , flag_lib ) ;
2020-07-29 15:28:33 +02:00
if ( ! veri_file : : AnalyzeMultipleFiles ( & file_names , verilog_mode , work . c_str ( ) , veri_file : : MFCU ) ) {
verific_error_msg . clear ( ) ;
2018-03-14 20:22:11 +01:00
log_cmd_error ( " Reading Verilog/SystemVerilog sources failed. \n " ) ;
2020-07-29 15:28:33 +02:00
}
2024-06-08 00:51:28 +02:00
char * fn ;
int i = 0 ;
FOREACH_ARRAY_ITEM ( & file_names , i , fn ) {
free ( fn ) ;
}
2023-07-24 12:41:57 +02:00
set_modules_to_blackbox ( map , work , flag_lib ) ;
2018-06-20 23:45:01 +02:00
verific_import_pending = true ;
2017-10-04 18:56:28 +02:00
goto check_error ;
2014-03-09 20:40:04 +01:00
}
2024-06-07 14:58:33 +02:00
# endif
2014-03-09 20:40:04 +01:00
2021-10-20 10:02:58 +02:00
# ifdef VERIFIC_VHDL_SUPPORT
2017-07-22 16:16:44 +02:00
if ( GetSize ( args ) > argidx & & args [ argidx ] = = " -vhdl87 " ) {
2015-11-12 19:28:14 +01:00
vhdl_file : : SetDefaultLibraryPath ( ( proc_share_dirname ( ) + " verific/vhdl_vdbs_1987 " ) . c_str ( ) ) ;
2023-07-24 12:41:57 +02:00
bool flag_lib = false ;
2024-06-07 14:58:33 +02:00
argidx + + ;
while ( argidx < GetSize ( args ) ) {
2023-07-24 12:41:57 +02:00
if ( args [ argidx ] = = " -lib " ) {
flag_lib = true ;
2024-06-07 14:58:33 +02:00
argidx + + ;
2023-07-24 12:41:57 +02:00
continue ;
}
if ( args [ argidx ] . compare ( 0 , 1 , " - " ) = = 0 ) {
cmd_error ( args , argidx , " unknown option " ) ;
goto check_error ;
}
Map map ( POINTER_HASH ) ;
add_units_to_map ( map , work , flag_lib ) ;
2022-09-28 15:56:46 +02:00
std : : string filename = frontent_rewrite ( args , argidx , tmp_files ) ;
2022-08-08 11:57:28 +02:00
if ( ! vhdl_file : : Analyze ( filename . c_str ( ) , work . c_str ( ) , vhdl_file : : VHDL_87 ) )
2025-09-17 00:59:08 +02:00
log_cmd_error ( " Reading `%s' in VHDL_87 mode failed. \n " , filename ) ;
2023-07-24 12:41:57 +02:00
set_units_to_blackbox ( map , work , flag_lib ) ;
2022-08-08 11:57:28 +02:00
}
2018-06-20 23:45:01 +02:00
verific_import_pending = true ;
2017-10-04 18:56:28 +02:00
goto check_error ;
2014-03-09 20:40:04 +01:00
}
2017-07-22 16:16:44 +02:00
if ( GetSize ( args ) > argidx & & args [ argidx ] = = " -vhdl93 " ) {
2014-03-13 17:34:31 +01:00
vhdl_file : : SetDefaultLibraryPath ( ( proc_share_dirname ( ) + " verific/vhdl_vdbs_1993 " ) . c_str ( ) ) ;
2023-07-24 12:41:57 +02:00
bool flag_lib = false ;
2024-06-07 14:58:33 +02:00
argidx + + ;
while ( argidx < GetSize ( args ) ) {
2023-07-24 12:41:57 +02:00
if ( args [ argidx ] = = " -lib " ) {
flag_lib = true ;
2024-06-07 14:58:33 +02:00
argidx + + ;
2023-07-24 12:41:57 +02:00
continue ;
}
if ( args [ argidx ] . compare ( 0 , 1 , " - " ) = = 0 ) {
cmd_error ( args , argidx , " unknown option " ) ;
goto check_error ;
}
Map map ( POINTER_HASH ) ;
add_units_to_map ( map , work , flag_lib ) ;
2022-09-28 15:56:46 +02:00
std : : string filename = frontent_rewrite ( args , argidx , tmp_files ) ;
2022-08-08 11:57:28 +02:00
if ( ! vhdl_file : : Analyze ( filename . c_str ( ) , work . c_str ( ) , vhdl_file : : VHDL_93 ) )
2025-09-17 00:59:08 +02:00
log_cmd_error ( " Reading `%s' in VHDL_93 mode failed. \n " , filename ) ;
2023-07-24 12:41:57 +02:00
set_units_to_blackbox ( map , work , flag_lib ) ;
2022-08-08 11:57:28 +02:00
}
2018-06-20 23:45:01 +02:00
verific_import_pending = true ;
2017-10-04 18:56:28 +02:00
goto check_error ;
2014-03-09 20:40:04 +01:00
}
2017-07-22 16:16:44 +02:00
if ( GetSize ( args ) > argidx & & args [ argidx ] = = " -vhdl2k " ) {
2014-03-13 17:34:31 +01:00
vhdl_file : : SetDefaultLibraryPath ( ( proc_share_dirname ( ) + " verific/vhdl_vdbs_1993 " ) . c_str ( ) ) ;
2023-07-24 12:41:57 +02:00
bool flag_lib = false ;
2024-06-07 14:58:33 +02:00
argidx + + ;
while ( argidx < GetSize ( args ) ) {
2023-07-24 12:41:57 +02:00
if ( args [ argidx ] = = " -lib " ) {
flag_lib = true ;
2024-06-07 14:58:33 +02:00
argidx + + ;
2023-07-24 12:41:57 +02:00
continue ;
}
if ( args [ argidx ] . compare ( 0 , 1 , " - " ) = = 0 ) {
cmd_error ( args , argidx , " unknown option " ) ;
goto check_error ;
}
Map map ( POINTER_HASH ) ;
add_units_to_map ( map , work , flag_lib ) ;
2022-09-28 15:56:46 +02:00
std : : string filename = frontent_rewrite ( args , argidx , tmp_files ) ;
2022-08-08 11:57:28 +02:00
if ( ! vhdl_file : : Analyze ( filename . c_str ( ) , work . c_str ( ) , vhdl_file : : VHDL_2K ) )
2025-09-17 00:59:08 +02:00
log_cmd_error ( " Reading `%s' in VHDL_2K mode failed. \n " , filename ) ;
2023-07-24 12:41:57 +02:00
set_units_to_blackbox ( map , work , flag_lib ) ;
2022-08-08 11:57:28 +02:00
}
2018-06-20 23:45:01 +02:00
verific_import_pending = true ;
2017-10-04 18:56:28 +02:00
goto check_error ;
2014-03-09 20:40:04 +01:00
}
2024-03-28 13:21:55 +01:00
if ( GetSize ( args ) > argidx & & ( args [ argidx ] = = " -vhdl2019 " ) ) {
vhdl_file : : SetDefaultLibraryPath ( ( proc_share_dirname ( ) + " verific/vhdl_vdbs_2019 " ) . c_str ( ) ) ;
bool flag_lib = false ;
2024-06-07 14:58:33 +02:00
argidx + + ;
while ( argidx < GetSize ( args ) ) {
2024-03-28 13:21:55 +01:00
if ( args [ argidx ] = = " -lib " ) {
flag_lib = true ;
2024-06-07 14:58:33 +02:00
argidx + + ;
2024-03-28 13:21:55 +01:00
continue ;
}
if ( args [ argidx ] . compare ( 0 , 1 , " - " ) = = 0 ) {
cmd_error ( args , argidx , " unknown option " ) ;
goto check_error ;
}
Map map ( POINTER_HASH ) ;
add_units_to_map ( map , work , flag_lib ) ;
std : : string filename = frontent_rewrite ( args , argidx , tmp_files ) ;
if ( ! vhdl_file : : Analyze ( filename . c_str ( ) , work . c_str ( ) , vhdl_file : : VHDL_2019 ) )
2025-09-17 00:59:08 +02:00
log_cmd_error ( " Reading `%s' in VHDL_2019 mode failed. \n " , filename ) ;
2024-03-28 13:21:55 +01:00
set_units_to_blackbox ( map , work , flag_lib ) ;
}
verific_import_pending = true ;
goto check_error ;
}
2017-07-28 15:32:54 +02:00
if ( GetSize ( args ) > argidx & & ( args [ argidx ] = = " -vhdl2008 " | | args [ argidx ] = = " -vhdl " ) ) {
2014-03-13 17:34:31 +01:00
vhdl_file : : SetDefaultLibraryPath ( ( proc_share_dirname ( ) + " verific/vhdl_vdbs_2008 " ) . c_str ( ) ) ;
2023-07-24 12:41:57 +02:00
bool flag_lib = false ;
2024-06-07 14:58:33 +02:00
argidx + + ;
while ( argidx < GetSize ( args ) ) {
2023-07-24 12:41:57 +02:00
if ( args [ argidx ] = = " -lib " ) {
flag_lib = true ;
2024-06-07 14:58:33 +02:00
argidx + + ;
2023-07-24 12:41:57 +02:00
continue ;
}
if ( args [ argidx ] . compare ( 0 , 1 , " - " ) = = 0 ) {
cmd_error ( args , argidx , " unknown option " ) ;
goto check_error ;
}
Map map ( POINTER_HASH ) ;
add_units_to_map ( map , work , flag_lib ) ;
2022-09-28 15:56:46 +02:00
std : : string filename = frontent_rewrite ( args , argidx , tmp_files ) ;
2022-08-08 11:57:28 +02:00
if ( ! vhdl_file : : Analyze ( filename . c_str ( ) , work . c_str ( ) , vhdl_file : : VHDL_2008 ) )
2025-09-17 00:59:08 +02:00
log_cmd_error ( " Reading `%s' in VHDL_2008 mode failed. \n " , filename ) ;
2023-07-24 12:41:57 +02:00
set_units_to_blackbox ( map , work , flag_lib ) ;
2022-08-08 11:57:28 +02:00
}
2018-06-20 23:45:01 +02:00
verific_import_pending = true ;
2017-10-04 18:56:28 +02:00
goto check_error ;
2014-03-09 20:40:04 +01:00
}
2021-10-20 10:02:58 +02:00
# endif
2022-10-04 09:18:44 +02:00
# ifdef VERIFIC_EDIF_SUPPORT
if ( GetSize ( args ) > argidx & & args [ argidx ] = = " -edif " ) {
edif_file edif ;
argidx + + ;
while ( argidx < GetSize ( args ) ) {
std : : string filename = frontent_rewrite ( args , argidx , tmp_files ) ;
if ( ! edif . Read ( filename . c_str ( ) ) )
2025-09-17 00:59:08 +02:00
log_cmd_error ( " Reading `%s' in EDIF mode failed. \n " , filename ) ;
2022-10-04 09:18:44 +02:00
}
goto check_error ;
}
2022-10-31 10:15:05 +01:00
# endif
# ifdef VERIFIC_LIBERTY_SUPPORT
if ( GetSize ( args ) > argidx & & args [ argidx ] = = " -liberty " ) {
2022-10-31 10:51:28 +01:00
bool flag_lib = false ;
for ( argidx + + ; argidx < GetSize ( args ) ; argidx + + ) {
if ( args [ argidx ] = = " -lib " ) {
flag_lib = true ;
continue ;
}
if ( args [ argidx ] . compare ( 0 , 1 , " - " ) = = 0 ) {
cmd_error ( args , argidx , " unknown option " ) ;
goto check_error ;
}
break ;
}
2022-10-31 10:15:05 +01:00
while ( argidx < GetSize ( args ) ) {
std : : string filename = frontent_rewrite ( args , argidx , tmp_files ) ;
if ( ! synlib_file : : Read ( filename . c_str ( ) , is_work_set ? work . c_str ( ) : nullptr ) )
2025-09-17 00:59:08 +02:00
log_cmd_error ( " Reading `%s' in LIBERTY mode failed. \n " , filename ) ;
2022-10-31 10:51:28 +01:00
SynlibLibrary * lib = synlib_file : : GetLastLibraryAnalyzed ( ) ;
if ( lib & & flag_lib ) {
MapIter mi ;
Verific : : Cell * c ;
FOREACH_CELL_OF_LIBRARY ( lib - > GetLibrary ( ) , mi , c ) {
MapIter ni ;
Netlist * nl ;
FOREACH_NETLIST_OF_CELL ( c , ni , nl ) {
if ( nl )
nl - > MakeBlackBox ( ) ;
}
}
}
2022-10-31 10:15:05 +01:00
}
goto check_error ;
}
2022-10-04 09:18:44 +02:00
# endif
2020-08-31 12:22:26 +02:00
if ( argidx < GetSize ( args ) & & args [ argidx ] = = " -pp " )
2020-08-26 10:39:57 +02:00
{
const char * filename = nullptr ;
const char * module = nullptr ;
bool mode_vhdl = false ;
for ( argidx + + ; argidx < GetSize ( args ) ; argidx + + ) {
2021-10-20 10:02:58 +02:00
# ifdef VERIFIC_VHDL_SUPPORT
2020-08-26 10:39:57 +02:00
if ( args [ argidx ] = = " -vhdl " ) {
mode_vhdl = true ;
continue ;
}
2021-10-20 10:02:58 +02:00
# endif
2020-08-26 10:39:57 +02:00
if ( args [ argidx ] = = " -verilog " ) {
mode_vhdl = false ;
continue ;
}
if ( args [ argidx ] . compare ( 0 , 1 , " - " ) = = 0 ) {
cmd_error ( args , argidx , " unknown option " ) ;
goto check_error ;
}
if ( ! filename ) {
filename = args [ argidx ] . c_str ( ) ;
continue ;
}
if ( module )
log_cmd_error ( " Only one module can be specified. \n " ) ;
module = args [ argidx ] . c_str ( ) ;
}
if ( argidx < GetSize ( args ) )
cmd_error ( args , argidx , " unknown option/parameter " ) ;
if ( ! filename )
log_cmd_error ( " Filname must be specified. \n " ) ;
if ( mode_vhdl )
2021-10-20 10:02:58 +02:00
# ifdef VERIFIC_VHDL_SUPPORT
2020-08-26 10:39:57 +02:00
vhdl_file : : PrettyPrint ( filename , module , work . c_str ( ) ) ;
2021-10-20 10:02:58 +02:00
# else
goto check_error ;
# endif
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2020-08-26 10:39:57 +02:00
else
veri_file : : PrettyPrint ( filename , module , work . c_str ( ) ) ;
2024-06-07 14:58:33 +02:00
# endif
2020-08-26 10:39:57 +02:00
goto check_error ;
}
2017-07-22 16:16:44 +02:00
if ( GetSize ( args ) > argidx & & args [ argidx ] = = " -import " )
2014-03-09 20:40:04 +01:00
{
2022-03-25 13:44:16 +01:00
std : : map < std : : string , Netlist * > nl_todo , nl_done ;
2017-07-22 16:16:44 +02:00
bool mode_all = false , mode_gates = false , mode_keep = false ;
2025-09-24 18:47:54 +02:00
bool mode_nosva = false , mode_sva_continue = false ;
bool mode_names = false , mode_verific = false ;
2019-08-07 15:31:49 +02:00
bool mode_autocover = false , mode_fullinit = false ;
2022-10-14 16:54:57 +02:00
bool flatten = false , extnets = false , mode_cells = false ;
2024-01-30 16:33:44 +01:00
bool split_complex_ports = true ;
2017-07-24 13:57:16 +02:00
string dumpfile ;
2022-06-30 11:19:01 +02:00
string ppfile ;
2019-03-09 02:54:01 +01:00
Map parameters ( STRING_HASH ) ;
2014-03-09 20:40:04 +01:00
2017-07-22 16:16:44 +02:00
for ( argidx + + ; argidx < GetSize ( args ) ; argidx + + ) {
2014-03-14 11:46:13 +01:00
if ( args [ argidx ] = = " -all " ) {
mode_all = true ;
continue ;
}
if ( args [ argidx ] = = " -gates " ) {
mode_gates = true ;
continue ;
}
2017-07-24 11:29:06 +02:00
if ( args [ argidx ] = = " -flatten " ) {
flatten = true ;
continue ;
}
2024-01-30 16:33:44 +01:00
if ( args [ argidx ] = = " -no-split-complex-ports " ) {
split_complex_ports = false ;
continue ;
}
2017-07-25 14:53:11 +02:00
if ( args [ argidx ] = = " -extnets " ) {
extnets = true ;
continue ;
}
2017-07-22 16:16:44 +02:00
if ( args [ argidx ] = = " -k " ) {
mode_keep = true ;
continue ;
}
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2017-07-27 11:54:45 +02:00
if ( args [ argidx ] = = " -nosva " ) {
mode_nosva = true ;
continue ;
}
2025-09-24 18:47:54 +02:00
if ( args [ argidx ] = = " -sva-continue-on-err " ) {
mode_sva_continue = true ;
continue ;
}
2018-09-04 20:06:10 +02:00
if ( args [ argidx ] = = " -L " & & argidx + 1 < GetSize ( args ) ) {
verific_sva_fsm_limit = atoi ( args [ + + argidx ] . c_str ( ) ) ;
continue ;
}
2018-04-06 14:10:57 +02:00
if ( args [ argidx ] = = " -autocover " ) {
mode_autocover = true ;
continue ;
}
2024-06-07 14:58:33 +02:00
# endif
2024-06-10 10:12:33 +02:00
if ( args [ argidx ] = = " -n " ) {
mode_names = true ;
continue ;
}
2019-08-07 15:31:49 +02:00
if ( args [ argidx ] = = " -fullinit " ) {
mode_fullinit = true ;
continue ;
}
2022-10-14 16:54:57 +02:00
if ( args [ argidx ] = = " -cells " ) {
mode_cells = true ;
continue ;
}
2019-03-09 02:54:01 +01:00
if ( args [ argidx ] = = " -chparam " & & argidx + 2 < GetSize ( args ) ) {
2019-03-13 20:42:18 +01:00
const std : : string & key = args [ + + argidx ] ;
const std : : string & value = args [ + + argidx ] ;
2019-03-09 02:54:01 +01:00
unsigned new_insertion = parameters . Insert ( key . c_str ( ) , value . c_str ( ) ,
2023-07-24 16:18:21 +02:00
1 /* force_overwrite */ ) ;
2019-03-09 02:54:01 +01:00
if ( ! new_insertion )
2025-09-17 01:02:16 +02:00
log_warning_noprefix ( " -chparam %s already specified: overwriting. \n " , key ) ;
2019-03-09 02:54:01 +01:00
continue ;
}
2018-03-07 19:40:34 +01:00
if ( args [ argidx ] = = " -V " ) {
mode_verific = true ;
continue ;
}
2017-07-24 11:29:06 +02:00
if ( args [ argidx ] = = " -v " ) {
2018-03-01 11:40:43 +01:00
verific_verbose = 1 ;
continue ;
}
if ( args [ argidx ] = = " -vv " ) {
verific_verbose = 2 ;
2017-07-24 11:29:06 +02:00
continue ;
}
2017-07-24 13:57:16 +02:00
if ( args [ argidx ] = = " -d " & & argidx + 1 < GetSize ( args ) ) {
dumpfile = args [ + + argidx ] ;
continue ;
}
2022-06-30 11:19:01 +02:00
if ( args [ argidx ] = = " -pp " & & argidx + 1 < GetSize ( args ) ) {
ppfile = args [ + + argidx ] ;
continue ;
}
2014-03-14 11:46:13 +01:00
break ;
}
2019-08-07 21:20:08 +02:00
if ( argidx > GetSize ( args ) & & args [ argidx ] . compare ( 0 , 1 , " - " ) = = 0 )
2014-09-06 08:47:06 +02:00
cmd_error ( args , argidx , " unknown option " ) ;
2014-03-14 11:46:13 +01:00
2025-07-09 15:58:35 +02:00
if ( ( unsigned long ) verific_sva_fsm_limit > = sizeof ( 1ull ) * 8 )
log_cmd_error ( " -L %d: limit too large; maximum allowed value is %zu. \n " , verific_sva_fsm_limit , sizeof ( 1ull ) * 8 - 1 ) ;
2025-07-25 21:15:01 +02:00
if ( already_imported )
log_warning ( " Note that all Verific flags were reset to defaults after last -import. \n " ) ;
2019-11-20 12:54:10 +01:00
std : : set < std : : string > top_mod_names ;
2023-10-05 16:28:17 +02:00
if ( mode_all )
{
2024-06-17 14:49:58 +02:00
import_all ( work . c_str ( ) , & nl_todo , & parameters , true , ppfile ) ;
2014-03-14 11:46:13 +01:00
}
else
2017-07-25 13:33:25 +02:00
{
2017-07-22 16:16:44 +02:00
if ( argidx = = GetSize ( args ) )
2019-11-19 22:25:38 +01:00
cmd_error ( args , argidx , " No top module specified. \n " ) ;
2014-03-09 20:40:04 +01:00
2024-06-17 14:49:58 +02:00
std : : vector < std : : string > tops ;
for ( int i = argidx ; i < GetSize ( args ) ; i + + )
tops . push_back ( args [ i ] . c_str ( ) ) ;
top_mod_names = import_tops ( work . c_str ( ) , & nl_todo , & parameters , true , ppfile , tops ) ;
2014-03-09 20:40:04 +01:00
}
2022-10-14 16:54:57 +02:00
if ( mode_cells ) {
log ( " Importing all cells. \n " ) ;
Libset * gls = Libset : : Global ( ) ;
MapIter it ;
Library * l ;
FOREACH_LIBRARY_OF_LIBSET ( gls , it , l ) {
MapIter mi ;
Verific : : Cell * c ;
FOREACH_CELL_OF_LIBRARY ( l , mi , c ) {
2022-10-14 17:41:24 +02:00
if ( ! mode_verific & & ( l = = Library : : Primitives ( ) | | l = = Library : : Operators ( ) ) ) continue ;
2022-10-14 16:54:57 +02:00
MapIter ni ;
if ( c - > NumOfNetlists ( ) = = 1 ) {
c - > GetFirstNetlist ( ) - > SetName ( " " ) ;
}
Netlist * nl ;
FOREACH_NETLIST_OF_CELL ( c , ni , nl ) {
if ( nl )
nl_todo . emplace ( nl - > CellBaseName ( ) , nl ) ;
}
}
}
}
2014-03-09 20:40:04 +01:00
2018-04-06 21:23:47 +02:00
if ( ! verific_error_msg . empty ( ) )
goto check_error ;
2017-07-24 11:29:06 +02:00
if ( flatten ) {
for ( auto nl : nl_todo )
2022-03-25 13:44:16 +01:00
nl . second - > Flatten ( ) ;
2017-07-24 11:29:06 +02:00
}
2017-07-25 14:53:11 +02:00
if ( extnets ) {
VerificExtNets worker ;
for ( auto nl : nl_todo )
2022-03-25 13:44:16 +01:00
worker . run ( nl . second ) ;
2017-07-25 14:53:11 +02:00
}
2017-07-24 13:57:16 +02:00
2024-01-30 16:33:44 +01:00
if ( split_complex_ports ) {
for ( auto nl : nl_todo )
nl . second - > ChangePortBusStructures ( 1 /* hierarchical */ ) ;
}
2020-01-24 19:12:52 +01:00
2024-06-07 14:58:33 +02:00
# ifdef VERIFIC_SYSTEMVERILOG_SUPPORT
2017-07-25 14:53:11 +02:00
if ( ! dumpfile . empty ( ) ) {
2017-07-24 13:57:16 +02:00
VeriWrite veri_writer ;
2017-07-25 14:53:11 +02:00
veri_writer . WriteFile ( dumpfile . c_str ( ) , Netlist : : PresentDesign ( ) ) ;
2017-07-24 13:57:16 +02:00
}
2024-06-07 14:58:33 +02:00
# endif
2014-03-09 20:40:04 +01:00
while ( ! nl_todo . empty ( ) ) {
2022-03-25 13:44:16 +01:00
auto it = nl_todo . begin ( ) ;
Netlist * nl = it - > second ;
if ( nl_done . count ( it - > first ) = = 0 ) {
2025-09-24 18:47:54 +02:00
VerificImporter importer ( mode_gates , mode_keep , mode_nosva , mode_sva_continue ,
2019-08-07 15:31:49 +02:00
mode_names , mode_verific , mode_autocover , mode_fullinit ) ;
2022-03-26 09:43:51 +01:00
nl_done [ it - > first ] = it - > second ;
2023-10-10 11:41:33 +02:00
importer . import_netlist ( design , nl , nl_todo , top_mod_names . count ( nl - > CellBaseName ( ) ) ) ;
2017-02-04 13:36:00 +01:00
}
2022-03-25 13:44:16 +01:00
nl_todo . erase ( it ) ;
2014-03-09 20:40:04 +01:00
}
2024-06-17 14:49:58 +02:00
verific_cleanup ( ) ;
2025-07-25 21:15:01 +02:00
already_imported = true ;
2017-10-04 18:56:28 +02:00
goto check_error ;
2014-03-09 20:40:04 +01:00
}
2021-11-01 10:41:51 +01:00
if ( argidx < GetSize ( args ) & & args [ argidx ] = = " -cfg " )
{
if ( argidx + 1 = = GetSize ( args ) ) {
MapIter mi ;
const char * k , * s ;
unsigned long v ;
pool < std : : string > lines ;
FOREACH_MAP_ITEM ( RuntimeFlags : : GetVarMap ( ) , mi , & k , & v ) {
lines . insert ( stringf ( " %s %lu " , k , v ) ) ;
}
FOREACH_MAP_ITEM ( RuntimeFlags : : GetStringVarMap ( ) , mi , & k , & s ) {
if ( s = = nullptr )
lines . insert ( stringf ( " %s NULL " , k ) ) ;
else
lines . insert ( stringf ( " %s \" %s \" " , k , s ) ) ;
}
lines . sort ( ) ;
for ( auto & line : lines )
2025-09-11 07:25:26 +02:00
log ( " verific -cfg %s \n " , line ) ;
2021-11-01 10:41:51 +01:00
goto check_error ;
}
if ( argidx + 2 = = GetSize ( args ) ) {
const char * k = args [ argidx + 1 ] . c_str ( ) ;
if ( RuntimeFlags : : HasUnsignedVar ( k ) ) {
log ( " verific -cfg %s %lu \n " , k , RuntimeFlags : : GetVar ( k ) ) ;
goto check_error ;
}
if ( RuntimeFlags : : HasStringVar ( k ) ) {
const char * s = RuntimeFlags : : GetStringVar ( k ) ;
if ( s = = nullptr )
log ( " verific -cfg %s NULL \n " , k ) ;
else
log ( " verific -cfg %s \" %s \" \n " , k , s ) ;
goto check_error ;
}
log_cmd_error ( " Can't find Verific Runtime flag '%s'. \n " , k ) ;
}
if ( argidx + 3 = = GetSize ( args ) ) {
const auto & k = args [ argidx + 1 ] , & v = args [ argidx + 2 ] ;
if ( v = = " NULL " ) {
RuntimeFlags : : SetStringVar ( k . c_str ( ) , nullptr ) ;
goto check_error ;
}
if ( v [ 0 ] = = ' " ' ) {
std : : string s = v . substr ( 1 , GetSize ( v ) - 2 ) ;
2024-11-12 19:46:26 +01:00
RuntimeFlags : : SetStringVar ( k . c_str ( ) , s . c_str ( ) ) ;
2021-11-01 10:41:51 +01:00
goto check_error ;
}
char * endptr ;
unsigned long n = strtol ( v . c_str ( ) , & endptr , 0 ) ;
if ( * endptr = = 0 ) {
RuntimeFlags : : SetVar ( k . c_str ( ) , n ) ;
goto check_error ;
}
}
}
2022-06-30 11:19:01 +02:00
# ifdef YOSYSHQ_VERIFIC_EXTENSIONS
if ( VerificExtensions : : Execute ( args , argidx , work ,
2023-07-24 16:18:21 +02:00
[ this ] ( const std : : vector < std : : string > & args , size_t argidx , std : : string msg )
2022-06-30 11:19:01 +02:00
{ cmd_error ( args , argidx , msg ) ; } ) ) {
goto check_error ;
}
# endif
2021-11-01 10:41:51 +01:00
2019-11-19 22:24:48 +01:00
cmd_error ( args , argidx , " Missing or unsupported mode parameter. \n " ) ;
2017-10-04 18:56:28 +02:00
check_error :
2022-09-28 15:56:46 +02:00
if ( tmp_files . size ( ) ) {
log ( " Removing temp files. \n " ) ;
for ( auto & fn : tmp_files ) {
remove ( fn . c_str ( ) ) ;
}
}
2017-10-05 14:38:32 +02:00
if ( ! verific_error_msg . empty ( ) )
2025-09-11 07:25:26 +02:00
log_error ( " %s \n " , verific_error_msg ) ;
2017-10-04 18:56:28 +02:00
2014-03-09 20:40:04 +01:00
}
2014-03-13 17:34:31 +01:00
# else /* YOSYS_ENABLE_VERIFIC */
2020-06-19 01:34:52 +02:00
void execute ( std : : vector < std : : string > , RTLIL : : Design * ) override {
2019-12-18 13:06:34 +01:00
log_cmd_error ( " This version of Yosys is built without Verific support. \n "
" \n "
2021-01-20 20:48:10 +01:00
" Use YosysHQ Tabby CAD Suite if you need Yosys+Verific. \n "
" https://www.yosyshq.com/ \n "
2019-12-18 13:06:34 +01:00
" \n "
2021-01-20 20:48:10 +01:00
" Contact office@yosyshq.com for free evaluation \n "
" binaries of YosysHQ Tabby CAD Suite. \n " ) ;
2014-03-09 20:40:04 +01:00
}
# endif
} VerificPass ;
2015-07-02 11:14:30 +02:00
2018-06-21 16:56:55 +02:00
struct ReadPass : public Pass {
ReadPass ( ) : Pass ( " read " , " load HDL designs " ) { }
2020-06-19 01:34:52 +02:00
void help ( ) override
2018-06-21 16:56:55 +02:00
{
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
log ( " \n " ) ;
2018-06-29 10:02:27 +02:00
log ( " read {-vlog95|-vlog2k|-sv2005|-sv2009|-sv2012|-sv|-formal} <verilog-file>.. \n " ) ;
2018-06-21 16:56:55 +02:00
log ( " \n " ) ;
log ( " Load the specified Verilog/SystemVerilog files. (Full SystemVerilog support \n " ) ;
log ( " is only available via Verific.) \n " ) ;
log ( " \n " ) ;
2018-06-28 23:58:15 +02:00
log ( " Additional -D<macro>[=<value>] options may be added after the option indicating \n " ) ;
log ( " the language version (and before file names) to set additional verilog defines. \n " ) ;
log ( " \n " ) ;
2018-06-21 16:56:55 +02:00
log ( " \n " ) ;
2021-10-20 10:02:58 +02:00
# ifdef VERIFIC_VHDL_SUPPORT
2024-03-28 13:21:55 +01:00
log ( " read {-vhdl87|-vhdl93|-vhdl2k|-vhdl2008|-vhdl2019|-vhdl} <vhdl-file>.. \n " ) ;
2018-06-21 16:56:55 +02:00
log ( " \n " ) ;
log ( " Load the specified VHDL files. (Requires Verific.) \n " ) ;
log ( " \n " ) ;
log ( " \n " ) ;
2022-10-04 09:18:44 +02:00
# endif
# ifdef VERIFIC_EDIF_SUPPORT
log ( " read {-edif} <edif-file>.. \n " ) ;
log ( " \n " ) ;
log ( " Load the specified EDIF files. (Requires Verific.) \n " ) ;
log ( " \n " ) ;
log ( " \n " ) ;
2021-10-20 10:02:58 +02:00
# endif
2022-10-31 10:15:05 +01:00
log ( " read {-liberty} <liberty-file>.. \n " ) ;
log ( " \n " ) ;
log ( " Load the specified Liberty files. \n " ) ;
log ( " \n " ) ;
2022-10-31 10:51:28 +01:00
log ( " -lib \n " ) ;
log ( " only create empty blackbox modules \n " ) ;
log ( " \n " ) ;
2022-10-31 10:15:05 +01:00
log ( " \n " ) ;
2021-06-16 11:21:44 +02:00
log ( " read {-f|-F} <command-file> \n " ) ;
log ( " \n " ) ;
2025-03-08 02:44:21 +01:00
log ( " Load and execute the specified command file. \n " ) ;
2021-07-05 09:16:54 +02:00
log ( " Check verific command for more information about supported commands in file. \n " ) ;
2021-06-16 11:21:44 +02:00
log ( " \n " ) ;
log ( " \n " ) ;
2018-06-21 16:56:55 +02:00
log ( " read -define <macro>[=<value>].. \n " ) ;
log ( " \n " ) ;
log ( " Set global Verilog/SystemVerilog defines. \n " ) ;
log ( " \n " ) ;
2018-06-28 23:43:38 +02:00
log ( " \n " ) ;
log ( " read -undef <macro>.. \n " ) ;
log ( " \n " ) ;
log ( " Unset global Verilog/SystemVerilog defines. \n " ) ;
log ( " \n " ) ;
2018-07-16 15:32:26 +02:00
log ( " \n " ) ;
log ( " read -incdir <directory> \n " ) ;
log ( " \n " ) ;
log ( " Add directory to global Verilog/SystemVerilog include directories. \n " ) ;
log ( " \n " ) ;
2019-03-27 14:03:35 +01:00
log ( " \n " ) ;
log ( " read -verific \n " ) ;
log ( " read -noverific \n " ) ;
log ( " \n " ) ;
log ( " Subsequent calls to 'read' will either use or not use Verific. Calling 'read' \n " ) ;
log ( " with -verific will result in an error on Yosys binaries that are built without \n " ) ;
log ( " Verific support. The default is to use Verific if it is available. \n " ) ;
log ( " \n " ) ;
2018-06-21 16:56:55 +02:00
}
2020-06-19 01:34:52 +02:00
void execute ( std : : vector < std : : string > args , RTLIL : : Design * design ) override
2018-06-21 16:56:55 +02:00
{
2019-03-27 14:03:35 +01:00
# ifdef YOSYS_ENABLE_VERIFIC
static bool verific_available = ! check_noverific_env ( ) ;
# else
static bool verific_available = false ;
# endif
static bool use_verific = verific_available ;
2019-03-01 05:34:42 +01:00
if ( args . size ( ) < 2 | | args [ 1 ] [ 0 ] ! = ' - ' )
2019-11-19 22:24:48 +01:00
cmd_error ( args , 1 , " Missing mode parameter. \n " ) ;
2018-06-21 16:56:55 +02:00
2019-03-27 14:03:35 +01:00
if ( args [ 1 ] = = " -verific " | | args [ 1 ] = = " -noverific " ) {
if ( args . size ( ) ! = 2 )
2019-11-19 22:24:48 +01:00
cmd_error ( args , 1 , " Additional arguments to -verific/-noverific. \n " ) ;
2019-03-27 14:03:35 +01:00
if ( args [ 1 ] = = " -verific " ) {
if ( ! verific_available )
2019-11-19 22:24:48 +01:00
cmd_error ( args , 1 , " This version of Yosys is built without Verific support. \n " ) ;
2019-03-27 14:03:35 +01:00
use_verific = true ;
} else {
use_verific = false ;
}
return ;
}
2018-06-21 16:56:55 +02:00
if ( args . size ( ) < 3 )
2019-11-19 22:24:48 +01:00
cmd_error ( args , 3 , " Missing file name parameter. \n " ) ;
2018-06-21 16:56:55 +02:00
2018-06-22 20:40:22 +02:00
if ( args [ 1 ] = = " -vlog95 " | | args [ 1 ] = = " -vlog2k " ) {
if ( use_verific ) {
args [ 0 ] = " verific " ;
} else {
args [ 0 ] = " read_verilog " ;
2019-07-29 10:29:36 +02:00
args [ 1 ] = " -defer " ;
2018-06-22 20:40:22 +02:00
}
2018-06-21 16:56:55 +02:00
Pass : : call ( design , args ) ;
return ;
}
2018-06-29 10:02:27 +02:00
if ( args [ 1 ] = = " -sv2005 " | | args [ 1 ] = = " -sv2009 " | | args [ 1 ] = = " -sv2012 " | | args [ 1 ] = = " -sv " | | args [ 1 ] = = " -formal " ) {
2018-06-22 20:40:22 +02:00
if ( use_verific ) {
args [ 0 ] = " verific " ;
} else {
args [ 0 ] = " read_verilog " ;
2018-06-29 10:02:27 +02:00
if ( args [ 1 ] = = " -formal " )
args . insert ( args . begin ( ) + 1 , std : : string ( ) ) ;
2018-06-22 20:40:22 +02:00
args [ 1 ] = " -sv " ;
2019-07-29 10:29:36 +02:00
args . insert ( args . begin ( ) + 1 , " -defer " ) ;
2018-06-22 20:40:22 +02:00
}
2018-06-21 16:56:55 +02:00
Pass : : call ( design , args ) ;
return ;
}
2021-10-20 10:02:58 +02:00
# ifdef VERIFIC_VHDL_SUPPORT
2024-03-28 13:21:55 +01:00
if ( args [ 1 ] = = " -vhdl87 " | | args [ 1 ] = = " -vhdl93 " | | args [ 1 ] = = " -vhdl2k " | | args [ 1 ] = = " -vhdl2008 " | | args [ 1 ] = = " -vhdl2019 " | | args [ 1 ] = = " -vhdl " ) {
2018-06-22 20:40:22 +02:00
if ( use_verific ) {
args [ 0 ] = " verific " ;
Pass : : call ( design , args ) ;
} else {
2019-11-19 22:24:48 +01:00
cmd_error ( args , 1 , " This version of Yosys is built without Verific support. \n " ) ;
2018-06-22 20:40:22 +02:00
}
2018-06-21 16:56:55 +02:00
return ;
}
2022-10-04 09:18:44 +02:00
# endif
# ifdef VERIFIC_EDIF_SUPPORT
if ( args [ 1 ] = = " -edif " ) {
if ( use_verific ) {
args [ 0 ] = " verific " ;
Pass : : call ( design , args ) ;
} else {
cmd_error ( args , 1 , " This version of Yosys is built without Verific support. \n " ) ;
}
return ;
}
2021-10-20 10:02:58 +02:00
# endif
2022-10-31 10:15:05 +01:00
if ( args [ 1 ] = = " -liberty " ) {
if ( use_verific ) {
args [ 0 ] = " verific " ;
} else {
args [ 0 ] = " read_liberty " ;
}
Pass : : call ( design , args ) ;
return ;
}
2021-06-16 11:21:44 +02:00
if ( args [ 1 ] = = " -f " | | args [ 1 ] = = " -F " ) {
if ( use_verific ) {
args [ 0 ] = " verific " ;
} else {
2025-03-11 23:50:44 +01:00
# if !defined(__wasm)
2025-03-08 02:44:21 +01:00
args [ 0 ] = " read_verilog_file_list " ;
2025-03-11 23:50:44 +01:00
# else
cmd_error ( args , 1 , " Command files are not supported on this platform. \n " ) ;
# endif
2021-06-16 11:21:44 +02:00
}
2025-03-08 02:44:21 +01:00
Pass : : call ( design , args ) ;
2021-06-16 11:21:44 +02:00
return ;
}
2018-06-21 16:56:55 +02:00
if ( args [ 1 ] = = " -define " ) {
2018-06-22 20:40:22 +02:00
if ( use_verific ) {
args [ 0 ] = " verific " ;
args [ 1 ] = " -vlog-define " ;
Pass : : call ( design , args ) ;
}
2018-06-21 16:56:55 +02:00
args [ 0 ] = " verilog_defines " ;
args . erase ( args . begin ( ) + 1 , args . begin ( ) + 2 ) ;
for ( int i = 1 ; i < GetSize ( args ) ; i + + )
args [ i ] = " -D " + args [ i ] ;
Pass : : call ( design , args ) ;
return ;
}
2018-06-28 23:43:38 +02:00
if ( args [ 1 ] = = " -undef " ) {
if ( use_verific ) {
args [ 0 ] = " verific " ;
args [ 1 ] = " -vlog-undef " ;
Pass : : call ( design , args ) ;
}
args [ 0 ] = " verilog_defines " ;
args . erase ( args . begin ( ) + 1 , args . begin ( ) + 2 ) ;
for ( int i = 1 ; i < GetSize ( args ) ; i + + )
args [ i ] = " -U " + args [ i ] ;
Pass : : call ( design , args ) ;
return ;
}
2018-07-16 15:32:26 +02:00
if ( args [ 1 ] = = " -incdir " ) {
if ( use_verific ) {
args [ 0 ] = " verific " ;
args [ 1 ] = " -vlog-incdir " ;
Pass : : call ( design , args ) ;
}
args [ 0 ] = " verilog_defaults " ;
args [ 1 ] = " -add " ;
2018-07-16 16:48:09 +02:00
for ( int i = 2 ; i < GetSize ( args ) ; i + + )
2018-07-16 15:32:26 +02:00
args [ i ] = " -I " + args [ i ] ;
Pass : : call ( design , args ) ;
return ;
}
2019-11-19 22:24:48 +01:00
cmd_error ( args , 1 , " Missing or unsupported mode parameter. \n " ) ;
2018-06-21 16:56:55 +02:00
}
} ReadPass ;
2017-02-04 13:36:00 +01:00
PRIVATE_NAMESPACE_END