Skip to content

Commit

Permalink
fix: dev: refactor symbol visibility, use ABC_DLL to expose public API
Browse files Browse the repository at this point in the history
* follow modern guidelines summarized in [1]
* set default visibility and visibility-inlines to hidden when
  using C++ namespace
* MSVC is hidden by default, so set GNU, LLVM, and AppleClang the same way
* use abc header defines to apply visibility rules on non-win32 platforms
* remove parallel args from tox Makefile commands in favor of posargs
  eg, ``tox -e abc -- -j4``

[1] https://gist.github.com/ax3l/ba17f4bb1edb5885a6bd01f58de4d542

Signed-off-by: Stephen L Arnold <[email protected]>
  • Loading branch information
sarnold committed Feb 24, 2025
1 parent 74413d0 commit 9b57427
Show file tree
Hide file tree
Showing 12 changed files with 348 additions and 326 deletions.
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# MSVC has symbols hidden by default. On GCC and Clang we need to explicitly
# set the visibility to hidden to achieve the same result and then manually
# expose what we need. This results in smaller abc dynamic library and thus
# a shorter loading time and higher performance.
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)

if(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
set(CLANG_DEFAULT_CXX_STDLIB libc++)
set(CLANG_DEFAULT_RTLIB compiler-rt)
Expand Down Expand Up @@ -75,6 +82,10 @@ option(COVERAGE_BUILD "Enable source-based LLVM code coverage" OFF)
option(ABC_SKIP_EXE "Skip building executable (build libs only)" OFF)
option(VENDOR_GTEST "download googletest" OFF)

#if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
#add_definitions(-DABC_DLL=__attribute__\(\(visibility\(\"default\"\)\)\))
#endif()

add_library(abc_interface INTERFACE)

set(ABC_HEADERS
Expand Down Expand Up @@ -161,7 +172,6 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang
target_compile_options(abc_interface
INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:-fpermissive>
$<$<COMPILE_LANGUAGE:CXX>:-fvisibility=hidden>
)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
Expand All @@ -172,6 +182,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
"_SCL_SECURE_NO_WARNINGS"
"_CRT_SECURE_NO_WARNINGS"
"_XKEYCHECK_H"
"_ALLOW_KEYWORD_MACROS=1"
)
set(CMAKE_DEBUG_POSTFIX d)
endif()
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ VPATH = $(ABCSRC)
PROG := abc
OS := $(shell uname -s)

VERSION ?= 1.1.0
VERSION ?= 1.2.0
SOVERSION ?= 1
SONAME := lib$(PROG).so.$(SOVERSION)

Expand Down Expand Up @@ -65,11 +65,13 @@ endif

# compile ABC using the C++ compiler and put everything in the namespace $(ABC_NAMESPACE)
ifdef ABC_USE_NAMESPACE
CFLAGS += -DABC_NAMESPACE=$(ABC_USE_NAMESPACE) -std=c++11 -fvisibility=hidden -fpermissive
CFLAGS += -DABC_DLL="__attribute__((visibility(\"default\")))" -DABC_NAMESPACE=$(ABC_USE_NAMESPACE) -std=c++17 -fvisibility=hidden -fvisibility-inlines-hidden -fpermissive
CXXFLAGS := $(CFLAGS)
CC := $(CXX)
DLIBS := -lstdc++
$(info $(MSG_PREFIX)Compiling in namespace $(ABC_NAMESPACE))
else
CXXFLAGS := $(CFLAGS)
ABC_USE_LIBSTDCXX := 1
endif

Expand Down
213 changes: 107 additions & 106 deletions src/aig/gia/gia.h

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions src/base/acb/acbTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Synopsis []
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - July 21, 2015.]
Expand Down Expand Up @@ -42,7 +42,7 @@ static int fForceZero = 0;
Synopsis []
Description []
SideEffects []
SeeAlso []
Expand Down Expand Up @@ -74,11 +74,11 @@ void Gia_ManSimTry( Gia_Man_t * pF, Gia_Man_t * pG )
int nBitsFx = Abc_TtCountOnesVec(pSimFx, nWords);
int nBitsF1 = Abc_TtCountOnesVecMask(pSimFx, pSimFb, nWords, 1);
int nBitsF0 = nWords*64 - nBitsFx - nBitsF1;

int nBitsGx = Abc_TtCountOnesVec(pSimGx, nWords);
int nBitsG1 = Abc_TtCountOnesVecMask(pSimGx, pSimGb, nWords, 1);
int nBitsG0 = nWords*64 - nBitsGx - nBitsG1;

printf( "Output %4d : ", i );

printf( " RF : " );
Expand Down Expand Up @@ -135,7 +135,7 @@ void Gia_ManSimTry( Gia_Man_t * pF, Gia_Man_t * pG )
Synopsis []
Description []
SideEffects []
SeeAlso []
Expand All @@ -145,15 +145,15 @@ void Gia_ManDualNot( Gia_Man_t * p, int LitA[2], int LitZ[2] )
{
LitZ[0] = Abc_LitNot(LitA[0]);
LitZ[1] = LitA[1];

if ( fForceZero ) LitZ[0] = Gia_ManHashAnd( p, LitZ[0], Abc_LitNot(LitZ[1]) );
}
// computes Z = XOR(A, B) where A, B, Z belong to {0,1,x} encoded as 0=00, 1=01, x=1-
void Gia_ManDualXor2( Gia_Man_t * p, int LitA[2], int LitB[2], int LitZ[2] )
{
LitZ[0] = Gia_ManHashXor( p, LitA[0], LitB[0] );
LitZ[1] = Gia_ManHashOr( p, LitA[1], LitB[1] );

if ( fForceZero ) LitZ[0] = Gia_ManHashAnd( p, LitZ[0], Abc_LitNot(LitZ[1]) );
}
void Gia_ManDualXorN( Gia_Man_t * p, int * pLits, int n, int LitZ[2] )
Expand Down Expand Up @@ -192,7 +192,7 @@ void Gia_ManDualAndN( Gia_Man_t * p, int * pLits, int n, int LitZ[2] )
LitZ[0] = Gia_ManHashAnd( p, LitZ[0], pLits[2*i] );
}
LitZ[1] = Gia_ManHashAnd( p, LitOne, Abc_LitNot(LitZero) );

if ( fForceZero ) LitZ[0] = Gia_ManHashAnd( p, LitZ[0], Abc_LitNot(LitZ[1]) );
}
/*
Expand All @@ -207,7 +207,7 @@ void Gia_ManDualDc( Gia_Man_t * p, int LitC[2], int LitD[2], int LitZ[2] )
LitZ[0] = LitC[0];
// LitZ[0] = Gia_ManHashMux( p, LitD[0], 0, LitC[0] );
LitZ[1] = Gia_ManHashOr(p, Gia_ManHashOr(p,LitD[0],LitD[1]), LitC[1] );

if ( fForceZero ) LitZ[0] = Gia_ManHashAnd( p, LitZ[0], Abc_LitNot(LitZ[1]) );
}
void Gia_ManDualMux( Gia_Man_t * p, int LitC[2], int LitT[2], int LitE[2], int LitZ[2] )
Expand Down Expand Up @@ -248,7 +248,7 @@ int Gia_ManDualCompare( Gia_Man_t * p, unsigned int LitF[2], unsigned int LitS[2
Synopsis []
Description []
SideEffects []
SeeAlso []
Expand All @@ -267,44 +267,44 @@ void Acb_ObjToGiaDual( Gia_Man_t * pNew, Acb_Ntk_t * p, int iObj, Vec_Int_t * vT
Vec_IntPushTwo( vTemp, pLits[0], pLits[1] );
}
Type = Acb_ObjType( p, iObj );
if ( Type == ABC_OPER_CONST_F )
if ( Type == ABC_OPER_CONST_F )
{
pRes[0] = 0;
pRes[1] = 0;
return;
}
if ( Type == ABC_OPER_CONST_T )
if ( Type == ABC_OPER_CONST_T )
{
pRes[0] = 1;
pRes[1] = 0;
return;
}
if ( Type == ABC_OPER_CONST_X )
if ( Type == ABC_OPER_CONST_X )
{
pRes[0] = 0;
pRes[1] = 1;
return;
}
if ( Type == ABC_OPER_BIT_BUF )
if ( Type == ABC_OPER_BIT_BUF )
{
pRes[0] = Vec_IntEntry(vTemp, 0);
pRes[1] = Vec_IntEntry(vTemp, 1);
return;
}
if ( Type == ABC_OPER_BIT_INV )
if ( Type == ABC_OPER_BIT_INV )
{
Gia_ManDualNot( pNew, Vec_IntArray(vTemp), pRes );
return;
}
if ( Type == ABC_OPER_TRI )
if ( Type == ABC_OPER_TRI )
{
// in the file inputs are ordered as follows: _DC \n6_5[9] ( .O(\108 ), .C(\96 ), .D(\107 ));
// in this code, we expect them as follows: void Gia_ManDualDc( Gia_Man_t * p, int LitC[2], int LitD[2], int LitZ[2] )
assert( Vec_IntSize(vTemp) == 4 );
Gia_ManDualDc( pNew, Vec_IntArray(vTemp), Vec_IntArray(vTemp) + 2, pRes );
return;
}
if ( Type == ABC_OPER_BIT_MUX )
if ( Type == ABC_OPER_BIT_MUX )
{
// in the file inputs are ordered as follows: _HMUX \U$1 ( .O(\282 ), .I0(1'b1), .I1(\277 ), .S(\281 ));
// in this code, we expect them as follows: void Gia_ManDualMux( Gia_Man_t * p, int LitC[2], int LitT[2], int LitE[2], int LitZ[2] )
Expand Down Expand Up @@ -386,7 +386,7 @@ Gia_Man_t * Acb_NtkGiaDeriveDual( Acb_Ntk_t * p )
Synopsis []
Description []
SideEffects []
SeeAlso []
Expand Down Expand Up @@ -443,7 +443,7 @@ Gia_Man_t * Acb_NtkGiaDeriveMiter( Gia_Man_t * pOne, Gia_Man_t * pTwo, int Type
{
int pLitsF[2] = { (int)Gia_ManCo(pOne, i)->Value, (int)Gia_ManCo(pOne, i+1)->Value };
int pLitsS[2] = { (int)Gia_ManCo(pTwo, i)->Value, (int)Gia_ManCo(pTwo, i+1)->Value };
Gia_ManAppendCo( pNew, Gia_ManDualCompare( pNew, pLitsF, pLitsS ) );
Gia_ManAppendCo( pNew, Gia_ManDualCompare( pNew, (unsigned int *)pLitsF, (unsigned int *)pLitsS ) );
}
}
Gia_ManHashStop( pNew );
Expand All @@ -458,7 +458,7 @@ Gia_Man_t * Acb_NtkGiaDeriveMiter( Gia_Man_t * pOne, Gia_Man_t * pTwo, int Type
Synopsis []
Description []
SideEffects []
SeeAlso []
Expand All @@ -475,7 +475,7 @@ void Acb_OutputFile( char * pFileName, Acb_Ntk_t * pNtkF, int * pModel )
}
if ( pModel == NULL )
fprintf( pFile, "EQ\n" );
else
else
{
/*
NEQ
Expand Down Expand Up @@ -521,7 +521,7 @@ int * Acb_NtkSolve( Gia_Man_t * p )
Synopsis [Various statistics.]
Description []
SideEffects []
SeeAlso []
Expand Down Expand Up @@ -549,7 +549,7 @@ void Acb_NtkPrintCecStats( Acb_Ntk_t * pNtk )
Synopsis [Changing the PI order.]
Description []
SideEffects []
SeeAlso []
Expand Down Expand Up @@ -601,7 +601,7 @@ int Acb_NtkCheckPiOrder( Acb_Ntk_t * pNtkF, Acb_Ntk_t * pNtkG )
Synopsis []
Description []
SideEffects []
SeeAlso []
Expand All @@ -621,7 +621,7 @@ void Acb_NtkRunTest( char * pFileNames[4], int fFancy, int fVerbose )
Acb_Ntk_t * pNtkG = Acb_VerilogSimpleRead( pFileNames[1], NULL );
if ( !pNtkF || !pNtkG )
return;

assert( Acb_NtkCiNum(pNtkF) == Acb_NtkCiNum(pNtkG) );
assert( Acb_NtkCoNum(pNtkF) == Acb_NtkCoNum(pNtkG) );

Expand Down
73 changes: 38 additions & 35 deletions src/base/main/abcapis.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
Synopsis [External declarations.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - September 29, 2012.]
Revision [$Id: abcapis.h,v 1.00 2012/09/29 00:00:00 alanmi Exp $]
***********************************************************************/

#ifndef MINI_AIG__abc_apis_h
#define MINI_AIG__abc_apis_h

Expand Down Expand Up @@ -51,70 +51,73 @@ typedef struct Abc_Frame_t_ Abc_Frame_t;
#endif
#else /* defined(WIN32) */
#define ABC_DLLIMPORT
#define ABC_DLLEXPORT __attribute__((visibility("default")))
#endif /* defined(WIN32) */

#ifndef ABC_DLL
#define ABC_DLL ABC_DLLIMPORT
#ifdef ABC_NAMESPACE
#define ABC_DLL ABC_DLLEXPORT
#else
#define ABC_DLL ABC_DLLIMPORT
#endif
#endif

#pragma GCC visibility push(default)
////////////////////////////////////////////////////////////////////////
/// FUNCTION DECLARATIONS ///
////////////////////////////////////////////////////////////////////////

// procedures to start and stop the ABC framework
extern ABC_DLL void Abc_Start();
extern ABC_DLL void Abc_Stop();
ABC_DLL extern void Abc_Start();
ABC_DLL extern void Abc_Stop();

// procedures to get the ABC framework (pAbc) and execute commands in it
extern ABC_DLL Abc_Frame_t * Abc_FrameGetGlobalFrame();
extern ABC_DLL int Cmd_CommandExecute( Abc_Frame_t * pAbc, const char * pCommandLine );
ABC_DLL extern Abc_Frame_t * Abc_FrameGetGlobalFrame();
ABC_DLL extern int Cmd_CommandExecute( Abc_Frame_t * pAbc, const char * pCommandLine );

// procedures to input/output 'mini AIG'
extern ABC_DLL void Abc_NtkInputMiniAig( Abc_Frame_t * pAbc, void * pMiniAig );
extern ABC_DLL void * Abc_NtkOutputMiniAig( Abc_Frame_t * pAbc );
extern ABC_DLL void Abc_FrameGiaInputMiniAig( Abc_Frame_t * pAbc, void * p );
extern ABC_DLL void * Abc_FrameGiaOutputMiniAig( Abc_Frame_t * pAbc );
extern ABC_DLL void Abc_NtkSetFlopNum( Abc_Frame_t * pAbc, int nFlops );
ABC_DLL extern void Abc_NtkInputMiniAig( Abc_Frame_t * pAbc, void * pMiniAig );
ABC_DLL extern void * Abc_NtkOutputMiniAig( Abc_Frame_t * pAbc );
ABC_DLL extern void Abc_FrameGiaInputMiniAig( Abc_Frame_t * pAbc, void * p );
ABC_DLL extern void * Abc_FrameGiaOutputMiniAig( Abc_Frame_t * pAbc );
ABC_DLL extern void Abc_NtkSetFlopNum( Abc_Frame_t * pAbc, int nFlops );

// procedures to input/output 'mini LUT'
extern ABC_DLL void Abc_FrameGiaInputMiniLut( Abc_Frame_t * pAbc, void * pMiniLut );
extern ABC_DLL void Abc_FrameGiaInputMiniLut2( Abc_Frame_t * pAbc, void * pMiniLut );
extern ABC_DLL void * Abc_FrameGiaOutputMiniLut( Abc_Frame_t * pAbc );
extern ABC_DLL char * Abc_FrameGiaOutputMiniLutAttr( Abc_Frame_t * pAbc, void * pMiniLut );
extern ABC_DLL int * Abc_FrameReadMiniLutSwitching( Abc_Frame_t * pAbc );
extern ABC_DLL int * Abc_FrameReadMiniLutSwitching2( Abc_Frame_t * pAbc, int nRandPiFactor );
extern ABC_DLL int * Abc_FrameReadMiniLutSwitchingPo( Abc_Frame_t * pAbc );
ABC_DLL extern void Abc_FrameGiaInputMiniLut( Abc_Frame_t * pAbc, void * pMiniLut );
ABC_DLL extern void Abc_FrameGiaInputMiniLut2( Abc_Frame_t * pAbc, void * pMiniLut );
ABC_DLL extern void * Abc_FrameGiaOutputMiniLut( Abc_Frame_t * pAbc );
ABC_DLL extern char * Abc_FrameGiaOutputMiniLutAttr( Abc_Frame_t * pAbc, void * pMiniLut );
ABC_DLL extern int * Abc_FrameReadMiniLutSwitching( Abc_Frame_t * pAbc );
ABC_DLL extern int * Abc_FrameReadMiniLutSwitching2( Abc_Frame_t * pAbc, int nRandPiFactor );
ABC_DLL extern int * Abc_FrameReadMiniLutSwitchingPo( Abc_Frame_t * pAbc );

// procedures to input/output NDR data-structure
extern ABC_DLL void Abc_FrameInputNdr( Abc_Frame_t * pAbc, void * pData );
extern ABC_DLL void * Abc_FrameOutputNdr( Abc_Frame_t * pAbc );
extern ABC_DLL int * Abc_FrameOutputNdrArray( Abc_Frame_t * pAbc );
ABC_DLL extern void Abc_FrameInputNdr( Abc_Frame_t * pAbc, void * pData );
ABC_DLL extern void * Abc_FrameOutputNdr( Abc_Frame_t * pAbc );
ABC_DLL extern int * Abc_FrameOutputNdrArray( Abc_Frame_t * pAbc );

// procedures to set CI/CO arrival/required times
extern ABC_DLL void Abc_NtkSetCiArrivalTime( Abc_Frame_t * pAbc, int iCi, float Rise, float Fall );
extern ABC_DLL void Abc_NtkSetCoRequiredTime( Abc_Frame_t * pAbc, int iCo, float Rise, float Fall );
ABC_DLL extern void Abc_NtkSetCiArrivalTime( Abc_Frame_t * pAbc, int iCi, float Rise, float Fall );
ABC_DLL extern void Abc_NtkSetCoRequiredTime( Abc_Frame_t * pAbc, int iCo, float Rise, float Fall );

// procedure to set AND-gate delay to tech-independent synthesis and mapping
extern ABC_DLL void Abc_NtkSetAndGateDelay( Abc_Frame_t * pAbc, float Delay );
ABC_DLL extern void Abc_NtkSetAndGateDelay( Abc_Frame_t * pAbc, float Delay );

// procedures to return the mapped network
extern ABC_DLL int * Abc_NtkOutputMiniMapping( Abc_Frame_t * pAbc );
extern ABC_DLL void Abc_NtkPrintMiniMapping( int * pArray );
extern ABC_DLL int * Abc_FrameReadArrayMapping( Abc_Frame_t * pAbc );
extern ABC_DLL int * Abc_FrameReadBoxes( Abc_Frame_t * pAbc );
ABC_DLL extern int * Abc_NtkOutputMiniMapping( Abc_Frame_t * pAbc );
ABC_DLL extern void Abc_NtkPrintMiniMapping( int * pArray );
ABC_DLL extern int * Abc_FrameReadArrayMapping( Abc_Frame_t * pAbc );
ABC_DLL extern int * Abc_FrameReadBoxes( Abc_Frame_t * pAbc );

// procedures to access verifization status and a counter-example
extern ABC_DLL int Abc_FrameReadProbStatus( Abc_Frame_t * pAbc );
extern ABC_DLL void * Abc_FrameReadCex( Abc_Frame_t * pAbc );
ABC_DLL extern int Abc_FrameReadProbStatus( Abc_Frame_t * pAbc );
ABC_DLL extern void * Abc_FrameReadCex( Abc_Frame_t * pAbc );

// procedure to set retiming data
extern ABC_DLL void Abc_FrameSetRetimingData( Abc_Frame_t * pAbc, int * pRst, int * pSet, int * pEna, int nRegs );
ABC_DLL extern void Abc_FrameSetRetimingData( Abc_Frame_t * pAbc, int * pRst, int * pSet, int * pEna, int nRegs );

// procedure to return sequential equivalences
extern ABC_DLL int * Abc_FrameReadMiniAigEquivClasses( Abc_Frame_t * pAbc );
ABC_DLL extern int * Abc_FrameReadMiniAigEquivClasses( Abc_Frame_t * pAbc );

#pragma GCC visibility pop
ABC_NAMESPACE_HEADER_END

#endif
Expand Down
Loading

0 comments on commit 9b57427

Please sign in to comment.