-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.cpp
More file actions
165 lines (157 loc) · 4.5 KB
/
init.cpp
File metadata and controls
165 lines (157 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* Copyright (c) 2025 Chair for Design Automation, TUM
* All rights reserved.
*
* SPDX-License-Identifier: MIT
*
* Licensed under the MIT License
*/
#include "base/main/main.h"
#include "base/main/mainInt.h"
#include "sat/bmc/bmc.h"
extern "C"
{
#include "pexact.h"
}
#include "errno.h"
#include "stdio.h"
namespace
{
const int DECIMAL_BASE = 10;
const int STEPSIZE_75 = 75;
int RunPexact( int searchMode, Bmc_EsPar_t * pPars )
{
int status = 0;
if ( searchMode == 0 )
{
status = PexaManExactPowerSynthesisBasePower( pPars );
} else if ( searchMode == 1 )
{
status = PexaManExactPowerSynthesisBasePowerBDD( pPars );
} else if ( searchMode == 2 )
{
status = PexaManExactPowerSynthesisBasePowerBDDBinary( pPars, STEPSIZE_75 );
}
return status;
}
/**
* @brief Pexact command.
*
* @details Extracts command input information, initializes Bmc_EsPar_t struct and finally executes
* the exact synthesis command from pexact.c.
*
* @param pAbc Abc frame.
* @param argc Arg count.
* @param argv Arg array
*/
int PexactCommand( Abc_Frame_t * pAbc, int argc, char ** argv )
{
int c;
char * pEnd;
Bmc_EsPar_t pars;
Bmc_EsPar_t * pPars = &pars;
Bmc_EsParSetDefault( pPars );
Extra_UtilGetoptReset();
Abc_FrameInit( pAbc );
int searchMode = 0; // Default search mode
long parsedSearchMode = 0;
while ( ( c = Extra_UtilGetopt( argc, argv, "IM" ) ) != EOF )
{
switch ( c )
{
case 'I': {
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
goto usage;
}
pPars->nVars = strtol( argv[globalUtilOptind], &pEnd, DECIMAL_BASE );
globalUtilOptind++;
break;
}
case 'M': {
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
goto usage;
}
errno = 0;
parsedSearchMode = strtol( argv[globalUtilOptind], &pEnd, DECIMAL_BASE );
if ( pEnd == argv[globalUtilOptind] || *pEnd != '\0' || errno == ERANGE || parsedSearchMode < 0 || parsedSearchMode > 2 )
{
Abc_Print( -1, "Invalid search mode. Valid values are 0 (queue search), 1 (free search), and 2 (binary search).\n" );
goto usage;
}
searchMode = ( int )parsedSearchMode;
globalUtilOptind++;
break;
}
default: {
goto usage;
}
}
}
if ( argc == globalUtilOptind + 1 )
{
if ( strstr( argv[globalUtilOptind], "." ) )
{
return 0;
}
pPars->pTtStr = argv[globalUtilOptind];
}
if ( pPars->pTtStr == NULL )
{
Abc_Print( -1, "Truth table should be given on the command line.\n" );
return 1;
}
if ( pPars->nVars >= 2 && ( 1 << ( pPars->nVars - 2 ) ) != ( int )strlen( pPars->pTtStr ) )
{
Abc_Print( -1, "Truth table is expected to have %d hex digits (instead of %d).\n", ( 1 << ( pPars->nVars - 2 ) ), strlen( pPars->pTtStr ) );
return 1;
}
if ( ( pPars->nVars ) > 4 )
{
Abc_Print( -1, "Function should not have more than 4 inputs.\n" );
return 1;
}
return RunPexact( searchMode, pPars );
usage:
Abc_Print( -2, "usage: pexact [-I <num>] [-M <num>] <hex>\n" );
Abc_Print( -2, "\t exact synthesis of multi-input function using two-input gates\n" );
Abc_Print( -2, "\t-I <num> : the number of input variables [default = %d]\n", pPars->nVars );
Abc_Print( -2, "\t-M <num> : search space exploration mode 0: queue search; 1: free search; 2: binary search [default = 0]\n" );
return 1;
}
/**
* @brief Abc startup initialization.
*
* @details Called during ABC startup.
*
* @param pAbc Abc frame.
*/
void Init( Abc_Frame_t * pAbc )
{
Cmd_CommandAdd( pAbc, "pexact", "pexact", PexactCommand, 0 );
}
/**
* @brief Destructor.
*
* @param pAbc Abc frame.
*/
void Destroy( Abc_Frame_t * pAbc )
{
}
Abc_FrameInitializer_t s_frameInitializer = { Init, Destroy };
/**
* @brief Register struct.
*
* @details register the initializer a constructor of a global object
* called before main (and ABC startup)
*/
struct Register_t_ {
Register_t_()
{
Abc_FrameAddInitializer( &s_frameInitializer );
}
} s_pexactRegister;
} // unnamed namespace