ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cmd.c File Reference
#include <unistd.h>
#include <dirent.h>
#include "base/abc/abc.h"
#include "base/main/mainInt.h"
#include "cmdInt.h"
#include "misc/util/utilSignal.h"
Include dependency graph for cmd.c:

Go to the source code of this file.

Functions

int Cmd_CommandAbcLoadPlugIn (Abc_Frame_t *pAbc, int argc, char **argv)
 
void Cmd_Init (Abc_Frame_t *pAbc)
 FUNCTION DEFINITIONS ///.
 
void Cmd_End (Abc_Frame_t *pAbc)
 
Vec_Ptr_tCmdReturnFileNames (char *pDirStr)
 
void Gia_ManGnuplotShow (char *pPlotFileName)
 

Function Documentation

◆ Cmd_CommandAbcLoadPlugIn()

int Cmd_CommandAbcLoadPlugIn ( Abc_Frame_t * pAbc,
int argc,
char ** argv )
extern

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 631 of file cmdPlugin.c.

632{
633 int fPath, fVerbose;
634 int fd = -1, RetValue = -1, c;
635 FILE * pFile = NULL;
636 char * pStrDirBin = NULL, * pStrSection = NULL;
637 Vec_Str_t * sCommandLine = NULL;
638 char * pTempFile = NULL;
639 char pBuffer[1000];
640
641 // set defaults
642 fPath = 0;
643 fVerbose = 0;
644
646 while ( ( c = Extra_UtilGetopt( argc, argv, "vph" ) ) != EOF )
647 {
648 switch ( c )
649 {
650 case 'p':
651 fPath ^= 1;
652 break;
653 case 'v':
654 fVerbose ^= 1;
655 break;
656 default:
657 goto usage;
658 }
659 }
660
661 if ( argc != globalUtilOptind + 2 )
662 goto usage;
663
664 pStrDirBin = argv[argc-2];
665 pStrSection = argv[argc-1];
666
667 // check if the file exists
668 if ( !fPath )
669 {
670 FILE* pFile = fopen( pStrDirBin, "r" );
671
672 if ( !pFile )
673 {
674 Abc_Print( ABC_ERROR, "Cannot run the binary \"%s\". File does not exist.\n", pStrDirBin );
675 goto cleanup;
676 }
677
678 fclose( pFile );
679 }
680
681 // create temp file
682 fd = Util_SignalTmpFile( "__abctmp_", ".txt", &pTempFile );
683
684 if ( fd == -1 )
685 {
686 Abc_Print( ABC_ERROR, "Cannot create a temporary file.\n" );
687 goto cleanup;
688 }
689
690#ifdef WIN32
691 _close( fd );
692#else
693 close( fd );
694#endif
695
696 // get command list
697 sCommandLine = Vec_StrAlloc(1000);
698
699 Vec_StrPrintF(sCommandLine, "%s -abc -list-commands > %s", pStrDirBin, pTempFile );
700 Vec_StrPush(sCommandLine, '\0');
701
702 if(fVerbose)
703 {
704 Abc_Print(ABC_VERBOSE, "Running command %s\n", Vec_StrArray(sCommandLine));
705 }
706
707 RetValue = Util_SignalSystem( Vec_StrArray(sCommandLine) );
708
709 if ( RetValue != 0 )
710 {
711 Abc_Print( ABC_ERROR, "Command \"%s\" failed.\n", Vec_StrArray(sCommandLine) );
712 goto cleanup;
713 }
714
715 // create commands
716 pFile = fopen( pTempFile, "r" );
717
718 if ( pFile == NULL )
719 {
720 Abc_Print( -1, "Cannot open file with the list of commands.\n" );
721
722 RetValue = -1;
723 goto cleanup;
724 }
725
726 while ( fgets( pBuffer, 1000, pFile ) != NULL )
727 {
728 if ( pBuffer[strlen(pBuffer)-1] == '\n' )
729 pBuffer[strlen(pBuffer)-1] = 0;
730
731 Cmd_CommandAdd( pAbc, pStrSection, pBuffer, Cmd_CommandAbcPlugIn, 1 );
732
733 Vec_PtrPush( pAbc->vPlugInComBinPairs, Extra_UtilStrsav(pBuffer) );
734 Vec_PtrPush( pAbc->vPlugInComBinPairs, Extra_UtilStrsav(pStrDirBin) );
735
736 if ( fVerbose )
737 {
738 Abc_Print(ABC_VERBOSE, "Creating command %s with binary %s\n", pBuffer, pStrDirBin);
739 }
740 }
741
742cleanup:
743
744 if( pFile )
745 fclose( pFile );
746
747 if( pTempFile )
748 Util_SignalTmpFileRemove( pTempFile, 0 );
749
750 Vec_StrFreeP(&sCommandLine);
751
752 ABC_FREE( pTempFile );
753
754 return RetValue;
755
756usage:
757
758 Abc_Print( -2, "usage: load_plugin [-pvh] <plugin_dir\\binary_name> <section_name>\n" );
759 Abc_Print( -2, "\t loads external binary as a plugin\n" );
760 Abc_Print( -2, "\t-p : toggle searching the command in PATH [default = %s].\n", fPath? "yes": "no" );
761 Abc_Print( -2, "\t-v : enable verbose output [default = %s].\n", fVerbose? "yes": "no" );
762 Abc_Print( -2, "\t-h : print the command usage\n");
763
764 return 1;
765}
@ ABC_ERROR
Definition abc_global.h:376
@ ABC_VERBOSE
Definition abc_global.h:379
#define ABC_FREE(obj)
Definition abc_global.h:267
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
int Cmd_CommandAbcPlugIn(Abc_Frame_t *pAbc, int argc, char **argv)
Definition cmdPlugin.c:412
void Cmd_CommandAdd(Abc_Frame_t *pAbc, const char *sGroup, const char *sName, Cmd_CommandFuncType pFunc, int fChanges)
Definition cmdApi.c:63
int globalUtilOptind
char * Extra_UtilStrsav(const char *s)
int Extra_UtilGetopt(int argc, char *argv[], const char *optstring)
ABC_DLL void Extra_UtilGetoptReset()
usage()
Definition main.c:626
ABC_NAMESPACE_IMPL_START int Util_SignalSystem(const char *cmd)
DECLARATIONS ///.
Definition utilSignal.c:44
void Util_SignalTmpFileRemove(const char *fname, int fLeave)
Definition utilSignal.c:60
int Util_SignalTmpFile(const char *prefix, const char *suffix, char **out_name)
INCLUDES ///.
Definition utilSignal.c:55
int strlen()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cmd_End()

void Cmd_End ( Abc_Frame_t * pAbc)

Function********************************************************************

Synopsis [Ends the command package.]

Description [Ends the command package. Tables are freed.]

SideEffects []

SeeAlso []

Definition at line 139 of file cmd.c.

140{
141 st__generator * gen;
142 char * pKey, * pValue;
144
145// st__free_table( pAbc->tCommands, (void (*)()) 0, CmdCommandFree );
146// st__free_table( pAbc->tAliases, (void (*)()) 0, CmdCommandAliasFree );
147// st__free_table( pAbc->tFlags, free, free );
148
149 st__foreach_item( pAbc->tCommands, gen, (const char **)&pKey, (char **)&pValue )
150 CmdCommandFree( (Abc_Command *)pValue );
151 st__free_table( pAbc->tCommands );
152
153 st__foreach_item( pAbc->tAliases, gen, (const char **)&pKey, (char **)&pValue )
154 CmdCommandAliasFree( (Abc_Alias *)pValue );
155 st__free_table( pAbc->tAliases );
156
157 st__foreach_item( pAbc->tFlags, gen, (const char **)&pKey, (char **)&pValue )
158 ABC_FREE( pKey ), ABC_FREE( pValue );
159 st__free_table( pAbc->tFlags );
160
161 Vec_PtrFreeFree( pAbc->aHistory );
162}
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
void CmdCommandAliasFree(Abc_Alias *pAlias)
Definition cmdAlias.c:113
void CmdCommandFree(Abc_Command *pCommand)
Definition cmdUtils.c:539
void Cmd_HistoryWrite(Abc_Frame_t *p, int Limit)
Definition cmdHist.c:134
struct MvAlias Abc_Alias
Definition cmd.h:40
typedefABC_NAMESPACE_HEADER_START struct MvCommand Abc_Command
INCLUDES ///.
Definition cmd.h:39
void st__free_table(st__table *table)
Definition st.c:81
#define st__foreach_item(table, gen, key, value)
Definition st.h:107
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cmd_Init()

void Cmd_Init ( Abc_Frame_t * pAbc)

FUNCTION DEFINITIONS ///.

MACRO DEFINITIONS ///.

Function********************************************************************

Synopsis [Initializes the command package.]

SideEffects [Commands are added to the command table.]

SeeAlso [Cmd_End]

Definition at line 85 of file cmd.c.

86{
87 pAbc->tCommands = st__init_table(strcmp, st__strhash);
88 pAbc->tAliases = st__init_table(strcmp, st__strhash);
89 pAbc->tFlags = st__init_table(strcmp, st__strhash);
90 pAbc->aHistory = Vec_PtrAlloc( 100 );
91 Cmd_HistoryRead( pAbc );
92
93 Cmd_CommandAdd( pAbc, "Basic", "time", CmdCommandTime, 0 );
94 Cmd_CommandAdd( pAbc, "Basic", "sleep", CmdCommandSleep, 0 );
95 Cmd_CommandAdd( pAbc, "Basic", "echo", CmdCommandEcho, 0 );
96 Cmd_CommandAdd( pAbc, "Basic", "quit", CmdCommandQuit, 0 );
97 Cmd_CommandAdd( pAbc, "Basic", "abcrc", CmdCommandAbcrc, 0 );
98 Cmd_CommandAdd( pAbc, "Basic", "history", CmdCommandHistory, 0 );
99 Cmd_CommandAdd( pAbc, "Basic", "alias", CmdCommandAlias, 0 );
100 Cmd_CommandAdd( pAbc, "Basic", "unalias", CmdCommandUnalias, 0 );
101 Cmd_CommandAdd( pAbc, "Basic", "help", CmdCommandHelp, 0 );
102 Cmd_CommandAdd( pAbc, "Basic", "source", CmdCommandSource, 0 );
103 Cmd_CommandAdd( pAbc, "Basic", "set", CmdCommandSetVariable, 0 );
104 Cmd_CommandAdd( pAbc, "Basic", "unset", CmdCommandUnsetVariable, 0 );
105 Cmd_CommandAdd( pAbc, "Basic", "undo", CmdCommandUndo, 0 );
106 Cmd_CommandAdd( pAbc, "Basic", "recall", CmdCommandRecall, 0 );
107 Cmd_CommandAdd( pAbc, "Basic", "empty", CmdCommandEmpty, 0 );
108#if defined(WIN32)
109 Cmd_CommandAdd( pAbc, "Basic", "scandir", CmdCommandScanDir, 0 );
110 Cmd_CommandAdd( pAbc, "Basic", "renamefiles", CmdCommandRenameFiles, 0 );
111 Cmd_CommandAdd( pAbc, "Basic", "ls", CmdCommandLs, 0 );
112 Cmd_CommandAdd( pAbc, "Basic", "scrgen", CmdCommandScrGen, 0 );
113#else
114 Cmd_CommandAdd( pAbc, "Basic", "scrgen", CmdCommandScrGenLinux, 0 );
115#endif
116 Cmd_CommandAdd( pAbc, "Basic", "version", CmdCommandVersion, 0 );
117 Cmd_CommandAdd( pAbc, "Basic", "sgen", CmdCommandSGen, 0 );
118
119 Cmd_CommandAdd( pAbc, "Various", "sis", CmdCommandSis, 1 );
120 Cmd_CommandAdd( pAbc, "Various", "mvsis", CmdCommandMvsis, 1 );
121 Cmd_CommandAdd( pAbc, "Various", "capo", CmdCommandCapo, 0 );
122 Cmd_CommandAdd( pAbc, "Various", "starter", CmdCommandStarter, 0 );
123 Cmd_CommandAdd( pAbc, "Various", "autotuner", CmdCommandAutoTuner, 0 );
124
125 Cmd_CommandAdd( pAbc, "Various", "load_plugin", Cmd_CommandAbcLoadPlugIn, 0 );
126}
int Cmd_CommandAbcLoadPlugIn(Abc_Frame_t *pAbc, int argc, char **argv)
Definition cmdPlugin.c:631
void Cmd_HistoryRead(Abc_Frame_t *p)
Definition cmdHist.c:103
int st__strhash(const char *string, int modulus)
Definition st.c:449
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition st.c:72
int strcmp()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CmdReturnFileNames()

Vec_Ptr_t * CmdReturnFileNames ( char * pDirStr)

Definition at line 1908 of file cmd.c.

1909{
1910 Vec_Ptr_t * vRes = Vec_PtrAlloc( 100 );
1911 struct dirent **namelist;
1912 int num_files = scandir(pDirStr, &namelist, NULL, alphasort);
1913 if (num_files == -1) {
1914 printf("Error opening directory.\n");
1915 return NULL;
1916 }
1917 for (int i = 0; i < num_files; i++) {
1918 char * pExt = strstr(namelist[i]->d_name, ".");
1919 if ( !pExt || !strcmp(pExt, ".") || !strcmp(pExt, "..") || !strcmp(pExt, ".s") || !strcmp(pExt, ".txt") )
1920 continue;
1921 Vec_PtrPush( vRes, Abc_UtilStrsav(namelist[i]->d_name) );
1922 free(namelist[i]);
1923 }
1924 free(namelist);
1925 return vRes;
1926}
char * strstr()
VOID_HACK free()
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
Here is the call graph for this function:

◆ Gia_ManGnuplotShow()

void Gia_ManGnuplotShow ( char * pPlotFileName)

Function*************************************************************

Synopsis [Computes dimentions of the graph.]

Description []

SideEffects []

SeeAlso []

Definition at line 2368 of file cmd.c.

2369{
2370 FILE * pFile;
2371 void * pAbc;
2372 char * pProgNameGnuplotWin = "wgnuplot.exe";
2373 char * pProgNameGnuplotUnix = "gnuplot";
2374 char * pProgNameGnuplot = NULL;
2375
2376 // read in the Capo plotting output
2377 if ( (pFile = fopen( pPlotFileName, "r" )) == NULL )
2378 {
2379 fprintf( stdout, "Cannot open the plot file \"%s\".\n\n", pPlotFileName );
2380 return;
2381 }
2382 fclose( pFile );
2383
2384 pAbc = Abc_FrameGetGlobalFrame();
2385
2386 // get the names from the plotting software
2387 if ( Cmd_FlagReadByName((Abc_Frame_t *)pAbc, "gnuplotwin") )
2388 pProgNameGnuplotWin = Cmd_FlagReadByName((Abc_Frame_t *)pAbc, "gnuplotwin");
2389 if ( Cmd_FlagReadByName((Abc_Frame_t *)pAbc, "gnuplotunix") )
2390 pProgNameGnuplotUnix = Cmd_FlagReadByName((Abc_Frame_t *)pAbc, "gnuplotunix");
2391
2392 // check if Gnuplot is available
2393 if ( (pFile = fopen( pProgNameGnuplotWin, "r" )) )
2394 pProgNameGnuplot = pProgNameGnuplotWin;
2395 else if ( (pFile = fopen( pProgNameGnuplotUnix, "r" )) )
2396 pProgNameGnuplot = pProgNameGnuplotUnix;
2397 else if ( pFile == NULL )
2398 {
2399 fprintf( stdout, "Cannot find \"%s\" or \"%s\" in the current directory.\n", pProgNameGnuplotWin, pProgNameGnuplotUnix );
2400 return;
2401 }
2402 fclose( pFile );
2403
2404 // spawn the viewer
2405#ifdef WIN32
2406 if ( _spawnl( _P_NOWAIT, pProgNameGnuplot, pProgNameGnuplot, pPlotFileName, NULL ) == -1 )
2407 {
2408 fprintf( stdout, "Cannot find \"%s\".\n", pProgNameGnuplot );
2409 return;
2410 }
2411#else
2412 {
2413 char Command[1000];
2414 sprintf( Command, "%s %s ", pProgNameGnuplot, pPlotFileName );
2415#if defined(__wasm)
2416 if ( 1 )
2417#else
2418 if ( system( Command ) == -1 )
2419#endif
2420 {
2421 fprintf( stdout, "Cannot execute \"%s\".\n", Command );
2422 return;
2423 }
2424 }
2425#endif
2426}
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
Definition abcapis.h:38
ABC_DLL Abc_Frame_t * Abc_FrameGetGlobalFrame()
Definition mainFrame.c:643
char * Cmd_FlagReadByName(Abc_Frame_t *pAbc, char *flag)
DECLARATIONS ///.
Definition cmdFlag.c:47
int system()
char * sprintf()
Here is the call graph for this function:
Here is the caller graph for this function: