1 /**CFile****************************************************************
2 
3   FileName    [abc.c]
4 
5   SystemName  [ABC: Logic synthesis and verification system.]
6 
7   PackageName [Network and node package.]
8 
9   Synopsis    [Command file.]
10 
11   Author      [Alan Mishchenko]
12 
13   Affiliation [UC Berkeley]
14 
15   Date        [Ver. 1.0. Started - June 20, 2005.]
16 
17   Revision    [$Id: abc.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "base/main/main.h"
23 #include "base/main/mainInt.h"
24 #include "proof/fraig/fraig.h"
25 #include "opt/fxu/fxu.h"
26 #include "opt/fxch/Fxch.h"
27 #include "opt/cut/cut.h"
28 #include "map/fpga/fpga.h"
29 #include "map/if/if.h"
30 #include "opt/sim/sim.h"
31 #include "opt/res/res.h"
32 #include "opt/lpk/lpk.h"
33 #include "aig/gia/giaAig.h"
34 #include "opt/dar/dar.h"
35 #include "opt/mfs/mfs.h"
36 #include "proof/fra/fra.h"
37 #include "aig/saig/saig.h"
38 #include "proof/int/int.h"
39 #include "proof/dch/dch.h"
40 #include "proof/ssw/ssw.h"
41 #include "opt/cgt/cgt.h"
42 #include "bool/kit/kit.h"
43 #include "map/amap/amap.h"
44 #include "opt/ret/retInt.h"
45 #include "sat/xsat/xsat.h"
46 #include "sat/satoko/satoko.h"
47 #include "sat/cnf/cnf.h"
48 #include "proof/cec/cec.h"
49 #include "proof/acec/acec.h"
50 #include "proof/pdr/pdr.h"
51 #include "misc/tim/tim.h"
52 #include "bdd/llb/llb.h"
53 #include "bdd/bbr/bbr.h"
54 #include "map/cov/cov.h"
55 #include "base/cmd/cmd.h"
56 #include "proof/abs/abs.h"
57 #include "sat/bmc/bmc.h"
58 #include "proof/ssc/ssc.h"
59 #include "opt/sfm/sfm.h"
60 #include "opt/sbd/sbd.h"
61 #include "bool/rpo/rpo.h"
62 #include "map/mpm/mpm.h"
63 #include "opt/fret/fretime.h"
64 #include "opt/nwk/nwkMerge.h"
65 #include "base/acb/acbPar.h"
66 
67 
68 #ifndef _WIN32
69 #include <unistd.h>
70 #endif
71 
72 ABC_NAMESPACE_IMPL_START
73 
74 ////////////////////////////////////////////////////////////////////////
75 ///                        DECLARATIONS                              ///
76 ////////////////////////////////////////////////////////////////////////
77 
78 //#define USE_MINISAT22
79 
80 static int Abc_CommandPrintStats             ( Abc_Frame_t * pAbc, int argc, char ** argv );
81 static int Abc_CommandPrintExdc              ( Abc_Frame_t * pAbc, int argc, char ** argv );
82 static int Abc_CommandPrintIo                ( Abc_Frame_t * pAbc, int argc, char ** argv );
83 static int Abc_CommandPrintLatch             ( Abc_Frame_t * pAbc, int argc, char ** argv );
84 static int Abc_CommandPrintFanio             ( Abc_Frame_t * pAbc, int argc, char ** argv );
85 static int Abc_CommandPrintMffc              ( Abc_Frame_t * pAbc, int argc, char ** argv );
86 static int Abc_CommandPrintFactor            ( Abc_Frame_t * pAbc, int argc, char ** argv );
87 static int Abc_CommandPrintLevel             ( Abc_Frame_t * pAbc, int argc, char ** argv );
88 static int Abc_CommandPrintSupport           ( Abc_Frame_t * pAbc, int argc, char ** argv );
89 static int Abc_CommandPrintMint              ( Abc_Frame_t * pAbc, int argc, char ** argv );
90 static int Abc_CommandPrintSymms             ( Abc_Frame_t * pAbc, int argc, char ** argv );
91 static int Abc_CommandPrintUnate             ( Abc_Frame_t * pAbc, int argc, char ** argv );
92 static int Abc_CommandPrintAuto              ( Abc_Frame_t * pAbc, int argc, char ** argv );
93 static int Abc_CommandPrintKMap              ( Abc_Frame_t * pAbc, int argc, char ** argv );
94 static int Abc_CommandPrintGates             ( Abc_Frame_t * pAbc, int argc, char ** argv );
95 static int Abc_CommandPrintSharing           ( Abc_Frame_t * pAbc, int argc, char ** argv );
96 static int Abc_CommandPrintXCut              ( Abc_Frame_t * pAbc, int argc, char ** argv );
97 static int Abc_CommandPrintDsd               ( Abc_Frame_t * pAbc, int argc, char ** argv );
98 static int Abc_CommandPrintCone              ( Abc_Frame_t * pAbc, int argc, char ** argv );
99 static int Abc_CommandPrintMiter             ( Abc_Frame_t * pAbc, int argc, char ** argv );
100 static int Abc_CommandPrintStatus            ( Abc_Frame_t * pAbc, int argc, char ** argv );
101 static int Abc_CommandPrintDelay             ( Abc_Frame_t * pAbc, int argc, char ** argv );
102 
103 static int Abc_CommandShow                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
104 static int Abc_CommandShowBdd                ( Abc_Frame_t * pAbc, int argc, char ** argv );
105 static int Abc_CommandShowCut                ( Abc_Frame_t * pAbc, int argc, char ** argv );
106 
107 static int Abc_CommandCollapse               ( Abc_Frame_t * pAbc, int argc, char ** argv );
108 static int Abc_CommandSatClp                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
109 static int Abc_CommandStrash                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
110 static int Abc_CommandBalance                ( Abc_Frame_t * pAbc, int argc, char ** argv );
111 static int Abc_CommandMuxStruct              ( Abc_Frame_t * pAbc, int argc, char ** argv );
112 static int Abc_CommandMulti                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
113 static int Abc_CommandRenode                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
114 static int Abc_CommandCleanup                ( Abc_Frame_t * pAbc, int argc, char ** argv );
115 static int Abc_CommandSweep                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
116 static int Abc_CommandFastExtract            ( Abc_Frame_t * pAbc, int argc, char ** argv );
117 static int Abc_CommandFxch                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
118 static int Abc_CommandEliminate              ( Abc_Frame_t * pAbc, int argc, char ** argv );
119 static int Abc_CommandDisjoint               ( Abc_Frame_t * pAbc, int argc, char ** argv );
120 static int Abc_CommandSparsify               ( Abc_Frame_t * pAbc, int argc, char ** argv );
121 static int Abc_CommandLutpack                ( Abc_Frame_t * pAbc, int argc, char ** argv );
122 static int Abc_CommandLutmin                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
123 //static int Abc_CommandImfs                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
124 static int Abc_CommandMfs                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
125 static int Abc_CommandMfs2                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
126 static int Abc_CommandMfs3                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
127 static int Abc_CommandMfse                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
128 static int Abc_CommandLogicPush              ( Abc_Frame_t * pAbc, int argc, char ** argv );
129 static int Abc_CommandTrace                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
130 static int Abc_CommandGlitch                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
131 static int Abc_CommandSpeedup                ( Abc_Frame_t * pAbc, int argc, char ** argv );
132 static int Abc_CommandPowerdown              ( Abc_Frame_t * pAbc, int argc, char ** argv );
133 static int Abc_CommandAddBuffs               ( Abc_Frame_t * pAbc, int argc, char ** argv );
134 static int Abc_CommandMerge                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
135 static int Abc_CommandTestDec                ( Abc_Frame_t * pAbc, int argc, char ** argv );
136 static int Abc_CommandTestNpn                ( Abc_Frame_t * pAbc, int argc, char ** argv );
137 static int Abc_CommandTestRPO                ( Abc_Frame_t * pAbc, int argc, char ** argv );
138 static int Abc_CommandTestTruth              ( Abc_Frame_t * pAbc, int argc, char ** argv );
139 static int Abc_CommandRunEco                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
140 static int Abc_CommandRunGen                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
141 static int Abc_CommandRunSim                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
142 static int Abc_CommandRunTest                ( Abc_Frame_t * pAbc, int argc, char ** argv );
143 
144 static int Abc_CommandRewrite                ( Abc_Frame_t * pAbc, int argc, char ** argv );
145 static int Abc_CommandRefactor               ( Abc_Frame_t * pAbc, int argc, char ** argv );
146 static int Abc_CommandRestructure            ( Abc_Frame_t * pAbc, int argc, char ** argv );
147 static int Abc_CommandResubstitute           ( Abc_Frame_t * pAbc, int argc, char ** argv );
148 static int Abc_CommandRr                     ( Abc_Frame_t * pAbc, int argc, char ** argv );
149 static int Abc_CommandCascade                ( Abc_Frame_t * pAbc, int argc, char ** argv );
150 static int Abc_CommandExtract                ( Abc_Frame_t * pAbc, int argc, char ** argv );
151 static int Abc_CommandVarMin                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
152 static int Abc_CommandFaultClasses           ( Abc_Frame_t * pAbc, int argc, char ** argv );
153 static int Abc_CommandExact                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
154 static int Abc_CommandBmsStart               ( Abc_Frame_t * pAbc, int argc, char ** argv );
155 static int Abc_CommandBmsStop                ( Abc_Frame_t * pAbc, int argc, char ** argv );
156 static int Abc_CommandBmsPs                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
157 static int Abc_CommandMajExact               ( Abc_Frame_t * pAbc, int argc, char ** argv );
158 static int Abc_CommandTwoExact               ( Abc_Frame_t * pAbc, int argc, char ** argv );
159 static int Abc_CommandLutExact               ( Abc_Frame_t * pAbc, int argc, char ** argv );
160 static int Abc_CommandAllExact               ( Abc_Frame_t * pAbc, int argc, char ** argv );
161 static int Abc_CommandTestExact              ( Abc_Frame_t * pAbc, int argc, char ** argv );
162 static int Abc_CommandMajGen                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
163 
164 static int Abc_CommandLogic                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
165 static int Abc_CommandComb                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
166 static int Abc_CommandMiter                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
167 static int Abc_CommandMiter2                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
168 static int Abc_CommandDemiter                ( Abc_Frame_t * pAbc, int argc, char ** argv );
169 static int Abc_CommandOrPos                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
170 static int Abc_CommandAndPos                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
171 static int Abc_CommandZeroPo                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
172 static int Abc_CommandSwapPos                ( Abc_Frame_t * pAbc, int argc, char ** argv );
173 static int Abc_CommandRemovePo               ( Abc_Frame_t * pAbc, int argc, char ** argv );
174 static int Abc_CommandDropSat                ( Abc_Frame_t * pAbc, int argc, char ** argv );
175 static int Abc_CommandAddPi                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
176 static int Abc_CommandAppend                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
177 static int Abc_CommandPutOnTop               ( Abc_Frame_t * pAbc, int argc, char ** argv );
178 static int Abc_CommandFrames                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
179 static int Abc_CommandDFrames                ( Abc_Frame_t * pAbc, int argc, char ** argv );
180 static int Abc_CommandSop                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
181 static int Abc_CommandBdd                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
182 static int Abc_CommandAig                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
183 static int Abc_CommandReorder                ( Abc_Frame_t * pAbc, int argc, char ** argv );
184 static int Abc_CommandBidec                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
185 static int Abc_CommandOrder                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
186 static int Abc_CommandMuxes                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
187 static int Abc_CommandCubes                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
188 static int Abc_CommandExpand                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
189 static int Abc_CommandSplitSop               ( Abc_Frame_t * pAbc, int argc, char ** argv );
190 static int Abc_CommandExtSeqDcs              ( Abc_Frame_t * pAbc, int argc, char ** argv );
191 static int Abc_CommandReach                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
192 static int Abc_CommandCone                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
193 static int Abc_CommandNode                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
194 static int Abc_CommandCof                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
195 static int Abc_CommandTopmost                ( Abc_Frame_t * pAbc, int argc, char ** argv );
196 static int Abc_CommandTopAnd                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
197 static int Abc_CommandTrim                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
198 static int Abc_CommandShortNames             ( Abc_Frame_t * pAbc, int argc, char ** argv );
199 static int Abc_CommandMoveNames              ( Abc_Frame_t * pAbc, int argc, char ** argv );
200 static int Abc_CommandExdcFree               ( Abc_Frame_t * pAbc, int argc, char ** argv );
201 static int Abc_CommandExdcGet                ( Abc_Frame_t * pAbc, int argc, char ** argv );
202 static int Abc_CommandExdcSet                ( Abc_Frame_t * pAbc, int argc, char ** argv );
203 static int Abc_CommandCareSet                ( Abc_Frame_t * pAbc, int argc, char ** argv );
204 static int Abc_CommandCut                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
205 static int Abc_CommandEspresso               ( Abc_Frame_t * pAbc, int argc, char ** argv );
206 static int Abc_CommandGen                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
207 static int Abc_CommandGenFsm                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
208 static int Abc_CommandCover                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
209 static int Abc_CommandDouble                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
210 static int Abc_CommandInter                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
211 static int Abc_CommandBb2Wb                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
212 static int Abc_CommandOutdec                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
213 static int Abc_CommandNodeDup                ( Abc_Frame_t * pAbc, int argc, char ** argv );
214 static int Abc_CommandTestColor              ( Abc_Frame_t * pAbc, int argc, char ** argv );
215 static int Abc_CommandTest                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
216 
217 static int Abc_CommandQuaVar                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
218 static int Abc_CommandQuaRel                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
219 static int Abc_CommandQuaReach               ( Abc_Frame_t * pAbc, int argc, char ** argv );
220 static int Abc_CommandSenseInput             ( Abc_Frame_t * pAbc, int argc, char ** argv );
221 static int Abc_CommandNpnLoad                ( Abc_Frame_t * pAbc, int argc, char ** argv );
222 static int Abc_CommandNpnSave                ( Abc_Frame_t * pAbc, int argc, char ** argv );
223 
224 static int Abc_CommandSendAig                ( Abc_Frame_t * pAbc, int argc, char ** argv );
225 static int Abc_CommandSendStatus             ( Abc_Frame_t * pAbc, int argc, char ** argv );
226 
227 static int Abc_CommandBackup                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
228 static int Abc_CommandRestore                ( Abc_Frame_t * pAbc, int argc, char ** argv );
229 
230 static int Abc_CommandMinisat                ( Abc_Frame_t * pAbc, int argc, char ** argv );
231 static int Abc_CommandMinisimp               ( Abc_Frame_t * pAbc, int argc, char ** argv );
232 
233 static int Abc_CommandIStrash                ( Abc_Frame_t * pAbc, int argc, char ** argv );
234 static int Abc_CommandICut                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
235 static int Abc_CommandIRewrite               ( Abc_Frame_t * pAbc, int argc, char ** argv );
236 static int Abc_CommandDRewrite               ( Abc_Frame_t * pAbc, int argc, char ** argv );
237 static int Abc_CommandDRefactor              ( Abc_Frame_t * pAbc, int argc, char ** argv );
238 static int Abc_CommandDc2                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
239 static int Abc_CommandDChoice                ( Abc_Frame_t * pAbc, int argc, char ** argv );
240 static int Abc_CommandDch                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
241 static int Abc_CommandDrwsat                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
242 static int Abc_CommandIRewriteSeq            ( Abc_Frame_t * pAbc, int argc, char ** argv );
243 static int Abc_CommandIResyn                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
244 static int Abc_CommandISat                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
245 static int Abc_CommandIFraig                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
246 static int Abc_CommandDFraig                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
247 static int Abc_CommandCSweep                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
248 static int Abc_CommandDProve                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
249 static int Abc_CommandAbSec                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
250 static int Abc_CommandSimSec                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
251 static int Abc_CommandMatch                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
252 //static int Abc_CommandHaig                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
253 static int Abc_CommandQbf                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
254 
255 static int Abc_CommandFraig                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
256 static int Abc_CommandFraigTrust             ( Abc_Frame_t * pAbc, int argc, char ** argv );
257 static int Abc_CommandFraigStore             ( Abc_Frame_t * pAbc, int argc, char ** argv );
258 static int Abc_CommandFraigRestore           ( Abc_Frame_t * pAbc, int argc, char ** argv );
259 static int Abc_CommandFraigClean             ( Abc_Frame_t * pAbc, int argc, char ** argv );
260 static int Abc_CommandFraigSweep             ( Abc_Frame_t * pAbc, int argc, char ** argv );
261 static int Abc_CommandFraigDress             ( Abc_Frame_t * pAbc, int argc, char ** argv );
262 static int Abc_CommandDumpEquiv              ( Abc_Frame_t * pAbc, int argc, char ** argv );
263 
264 static int Abc_CommandRecStart3              ( Abc_Frame_t * pAbc, int argc, char ** argv );
265 static int Abc_CommandRecStop3               ( Abc_Frame_t * pAbc, int argc, char ** argv );
266 static int Abc_CommandRecPs3                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
267 static int Abc_CommandRecAdd3                ( Abc_Frame_t * pAbc, int argc, char ** argv );
268 static int Abc_CommandRecDump3               ( Abc_Frame_t * pAbc, int argc, char ** argv );
269 static int Abc_CommandRecMerge3              ( Abc_Frame_t * pAbc, int argc, char ** argv );
270 
271 static int Abc_CommandMap                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
272 static int Abc_CommandAmap                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
273 static int Abc_CommandPhaseMap               ( Abc_Frame_t * pAbc, int argc, char ** argv );
274 static int Abc_CommandUnmap                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
275 static int Abc_CommandAttach                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
276 static int Abc_CommandSuperChoice            ( Abc_Frame_t * pAbc, int argc, char ** argv );
277 static int Abc_CommandSuperChoiceLut         ( Abc_Frame_t * pAbc, int argc, char ** argv );
278 static int Abc_CommandTimeScale              ( Abc_Frame_t * pAbc, int argc, char ** argv );
279 
280 //static int Abc_CommandFpga                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
281 //static int Abc_CommandFpgaFast               ( Abc_Frame_t * pAbc, int argc, char ** argv );
282 static int Abc_CommandIf                     ( Abc_Frame_t * pAbc, int argc, char ** argv );
283 static int Abc_CommandIfif                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
284 
285 static int Abc_CommandDsdSave                ( Abc_Frame_t * pAbc, int argc, char ** argv );
286 static int Abc_CommandDsdLoad                ( Abc_Frame_t * pAbc, int argc, char ** argv );
287 static int Abc_CommandDsdFree                ( Abc_Frame_t * pAbc, int argc, char ** argv );
288 static int Abc_CommandDsdPs                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
289 static int Abc_CommandDsdMatch               ( Abc_Frame_t * pAbc, int argc, char ** argv );
290 static int Abc_CommandDsdMerge               ( Abc_Frame_t * pAbc, int argc, char ** argv );
291 static int Abc_CommandDsdFilter              ( Abc_Frame_t * pAbc, int argc, char ** argv );
292 
293 static int Abc_CommandScut                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
294 static int Abc_CommandInit                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
295 static int Abc_CommandZero                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
296 static int Abc_CommandUndc                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
297 static int Abc_CommandOneHot                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
298 static int Abc_CommandPipe                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
299 static int Abc_CommandSeq                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
300 static int Abc_CommandUnseq                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
301 static int Abc_CommandRetime                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
302 static int Abc_CommandDRetime                ( Abc_Frame_t * pAbc, int argc, char ** argv );
303 static int Abc_CommandFlowRetime             ( Abc_Frame_t * pAbc, int argc, char ** argv );
304 static int Abc_CommandCRetime                ( Abc_Frame_t * pAbc, int argc, char ** argv );
305 static int Abc_CommandSeqFpga                ( Abc_Frame_t * pAbc, int argc, char ** argv );
306 static int Abc_CommandSeqMap                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
307 static int Abc_CommandSeqSweep               ( Abc_Frame_t * pAbc, int argc, char ** argv );
308 static int Abc_CommandSeqSweep2              ( Abc_Frame_t * pAbc, int argc, char ** argv );
309 static int Abc_CommandTestSeqSweep           ( Abc_Frame_t * pAbc, int argc, char ** argv );
310 static int Abc_CommandTestScorr              ( Abc_Frame_t * pAbc, int argc, char ** argv );
311 static int Abc_CommandLcorr                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
312 static int Abc_CommandSeqCleanup             ( Abc_Frame_t * pAbc, int argc, char ** argv );
313 static int Abc_CommandCycle                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
314 static int Abc_CommandXsim                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
315 static int Abc_CommandSim                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
316 static int Abc_CommandSim3                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
317 static int Abc_CommandDarPhase               ( Abc_Frame_t * pAbc, int argc, char ** argv );
318 static int Abc_CommandSynch                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
319 static int Abc_CommandClockGate              ( Abc_Frame_t * pAbc, int argc, char ** argv );
320 static int Abc_CommandExtWin                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
321 static int Abc_CommandInsWin                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
322 static int Abc_CommandSymFun                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
323 static int Abc_CommandPermute                ( Abc_Frame_t * pAbc, int argc, char ** argv );
324 static int Abc_CommandUnpermute              ( Abc_Frame_t * pAbc, int argc, char ** argv );
325 static int Abc_CommandCubeEnum               ( Abc_Frame_t * pAbc, int argc, char ** argv );
326 static int Abc_CommandPathEnum               ( Abc_Frame_t * pAbc, int argc, char ** argv );
327 static int Abc_CommandFunEnum                ( Abc_Frame_t * pAbc, int argc, char ** argv );
328 
329 static int Abc_CommandCec                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
330 static int Abc_CommandDCec                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
331 static int Abc_CommandDSec                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
332 static int Abc_CommandSat                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
333 static int Abc_CommandDSat                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
334 static int Abc_CommandXSat                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
335 static int Abc_CommandSatoko                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
336 static int Abc_CommandAbc9Satoko             ( Abc_Frame_t * pAbc, int argc, char ** argv );
337 static int Abc_CommandAbc9Sat3               ( Abc_Frame_t * pAbc, int argc, char ** argv );
338 static int Abc_CommandPSat                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
339 static int Abc_CommandProve                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
340 static int Abc_CommandIProve                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
341 static int Abc_CommandDebug                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
342 static int Abc_CommandEco                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
343 static int Abc_CommandBmc                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
344 static int Abc_CommandBmc2                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
345 static int Abc_CommandBmc3                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
346 static int Abc_CommandBmcInter               ( Abc_Frame_t * pAbc, int argc, char ** argv );
347 static int Abc_CommandIndcut                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
348 static int Abc_CommandEnlarge                ( Abc_Frame_t * pAbc, int argc, char ** argv );
349 static int Abc_CommandTempor                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
350 static int Abc_CommandInduction              ( Abc_Frame_t * pAbc, int argc, char ** argv );
351 static int Abc_CommandConstr                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
352 static int Abc_CommandUnfold                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
353 static int Abc_CommandFold                   ( Abc_Frame_t * pAbc, int argc, char ** argv );
354 static int Abc_CommandUnfold2                ( Abc_Frame_t * pAbc, int argc, char ** argv );
355 static int Abc_CommandFold2                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
356 static int Abc_CommandBm                     ( Abc_Frame_t * pAbc, int argc, char ** argv );
357 static int Abc_CommandBm2                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
358 static int Abc_CommandSaucy                  ( Abc_Frame_t * pAbc, int argc, char ** argv );
359 static int Abc_CommandTestCex                ( Abc_Frame_t * pAbc, int argc, char ** argv );
360 static int Abc_CommandPdr                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
361 #ifdef ABC_USE_CUDD
362 static int Abc_CommandReconcile              ( Abc_Frame_t * pAbc, int argc, char ** argv );
363 #endif
364 static int Abc_CommandCexSave                ( Abc_Frame_t * pAbc, int argc, char ** argv );
365 static int Abc_CommandCexLoad                ( Abc_Frame_t * pAbc, int argc, char ** argv );
366 static int Abc_CommandCexCut                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
367 static int Abc_CommandCexMerge               ( Abc_Frame_t * pAbc, int argc, char ** argv );
368 //static int Abc_CommandCexMin                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
369 static int Abc_CommandDualRail               ( Abc_Frame_t * pAbc, int argc, char ** argv );
370 static int Abc_CommandBlockPo                ( Abc_Frame_t * pAbc, int argc, char ** argv );
371 static int Abc_CommandIso                    ( Abc_Frame_t * pAbc, int argc, char ** argv );
372 
373 static int Abc_CommandTraceStart             ( Abc_Frame_t * pAbc, int argc, char ** argv );
374 static int Abc_CommandTraceCheck             ( Abc_Frame_t * pAbc, int argc, char ** argv );
375 
376 static int Abc_CommandAbcSave                ( Abc_Frame_t * pAbc, int argc, char ** argv );
377 static int Abc_CommandAbcLoad                ( Abc_Frame_t * pAbc, int argc, char ** argv );
378 
379 static int Abc_CommandAbc9Get                ( Abc_Frame_t * pAbc, int argc, char ** argv );
380 static int Abc_CommandAbc9Put                ( Abc_Frame_t * pAbc, int argc, char ** argv );
381 static int Abc_CommandAbc9Save               ( Abc_Frame_t * pAbc, int argc, char ** argv );
382 static int Abc_CommandAbc9Save2              ( Abc_Frame_t * pAbc, int argc, char ** argv );
383 static int Abc_CommandAbc9SaveAig            ( Abc_Frame_t * pAbc, int argc, char ** argv );
384 static int Abc_CommandAbc9Load               ( Abc_Frame_t * pAbc, int argc, char ** argv );
385 static int Abc_CommandAbc9Load2              ( Abc_Frame_t * pAbc, int argc, char ** argv );
386 static int Abc_CommandAbc9LoadAig            ( Abc_Frame_t * pAbc, int argc, char ** argv );
387 static int Abc_CommandAbc9Read               ( Abc_Frame_t * pAbc, int argc, char ** argv );
388 static int Abc_CommandAbc9ReadBlif           ( Abc_Frame_t * pAbc, int argc, char ** argv );
389 static int Abc_CommandAbc9ReadCBlif          ( Abc_Frame_t * pAbc, int argc, char ** argv );
390 static int Abc_CommandAbc9ReadStg            ( Abc_Frame_t * pAbc, int argc, char ** argv );
391 static int Abc_CommandAbc9ReadVer            ( Abc_Frame_t * pAbc, int argc, char ** argv );
392 static int Abc_CommandAbc9WriteVer           ( Abc_Frame_t * pAbc, int argc, char ** argv );
393 static int Abc_CommandAbc9Write              ( Abc_Frame_t * pAbc, int argc, char ** argv );
394 static int Abc_CommandAbc9WriteLut           ( Abc_Frame_t * pAbc, int argc, char ** argv );
395 static int Abc_CommandAbc9Ps                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
396 static int Abc_CommandAbc9PFan               ( Abc_Frame_t * pAbc, int argc, char ** argv );
397 static int Abc_CommandAbc9PSig               ( Abc_Frame_t * pAbc, int argc, char ** argv );
398 static int Abc_CommandAbc9Status             ( Abc_Frame_t * pAbc, int argc, char ** argv );
399 static int Abc_CommandAbc9MuxProfile         ( Abc_Frame_t * pAbc, int argc, char ** argv );
400 static int Abc_CommandAbc9MuxPos             ( Abc_Frame_t * pAbc, int argc, char ** argv );
401 static int Abc_CommandAbc9PrintTruth         ( Abc_Frame_t * pAbc, int argc, char ** argv );
402 static int Abc_CommandAbc9Unate              ( Abc_Frame_t * pAbc, int argc, char ** argv );
403 static int Abc_CommandAbc9Rex2Gia            ( Abc_Frame_t * pAbc, int argc, char ** argv );
404 static int Abc_CommandAbc9RexWalk            ( Abc_Frame_t * pAbc, int argc, char ** argv );
405 static int Abc_CommandAbc9Show               ( Abc_Frame_t * pAbc, int argc, char ** argv );
406 static int Abc_CommandAbc9SetRegNum          ( Abc_Frame_t * pAbc, int argc, char ** argv );
407 static int Abc_CommandAbc9Strash             ( Abc_Frame_t * pAbc, int argc, char ** argv );
408 static int Abc_CommandAbc9Topand             ( Abc_Frame_t * pAbc, int argc, char ** argv );
409 static int Abc_CommandAbc9Add1Hot            ( Abc_Frame_t * pAbc, int argc, char ** argv );
410 static int Abc_CommandAbc9Cof                ( Abc_Frame_t * pAbc, int argc, char ** argv );
411 static int Abc_CommandAbc9Trim               ( Abc_Frame_t * pAbc, int argc, char ** argv );
412 static int Abc_CommandAbc9Dfs                ( Abc_Frame_t * pAbc, int argc, char ** argv );
413 static int Abc_CommandAbc9Sim                ( Abc_Frame_t * pAbc, int argc, char ** argv );
414 static int Abc_CommandAbc9Sim3               ( Abc_Frame_t * pAbc, int argc, char ** argv );
415 static int Abc_CommandAbc9MLGen              ( Abc_Frame_t * pAbc, int argc, char ** argv );
416 static int Abc_CommandAbc9MLTest             ( Abc_Frame_t * pAbc, int argc, char ** argv );
417 static int Abc_CommandAbc9ReadSim            ( Abc_Frame_t * pAbc, int argc, char ** argv );
418 static int Abc_CommandAbc9WriteSim           ( Abc_Frame_t * pAbc, int argc, char ** argv );
419 static int Abc_CommandAbc9SimPat             ( Abc_Frame_t * pAbc, int argc, char ** argv );
420 static int Abc_CommandAbc9SimRsb             ( Abc_Frame_t * pAbc, int argc, char ** argv );
421 static int Abc_CommandAbc9Resim              ( Abc_Frame_t * pAbc, int argc, char ** argv );
422 static int Abc_CommandAbc9SpecI              ( Abc_Frame_t * pAbc, int argc, char ** argv );
423 static int Abc_CommandAbc9Equiv              ( Abc_Frame_t * pAbc, int argc, char ** argv );
424 static int Abc_CommandAbc9Equiv2             ( Abc_Frame_t * pAbc, int argc, char ** argv );
425 static int Abc_CommandAbc9Equiv3             ( Abc_Frame_t * pAbc, int argc, char ** argv );
426 static int Abc_CommandAbc9Semi               ( Abc_Frame_t * pAbc, int argc, char ** argv );
427 static int Abc_CommandAbc9Times              ( Abc_Frame_t * pAbc, int argc, char ** argv );
428 static int Abc_CommandAbc9Frames             ( Abc_Frame_t * pAbc, int argc, char ** argv );
429 static int Abc_CommandAbc9Retime             ( Abc_Frame_t * pAbc, int argc, char ** argv );
430 static int Abc_CommandAbc9Enable             ( Abc_Frame_t * pAbc, int argc, char ** argv );
431 static int Abc_CommandAbc9Dc2                ( Abc_Frame_t * pAbc, int argc, char ** argv );
432 static int Abc_CommandAbc9Dsd                ( Abc_Frame_t * pAbc, int argc, char ** argv );
433 static int Abc_CommandAbc9Bidec              ( Abc_Frame_t * pAbc, int argc, char ** argv );
434 static int Abc_CommandAbc9Shrink             ( Abc_Frame_t * pAbc, int argc, char ** argv );
435 static int Abc_CommandAbc9Fx                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
436 static int Abc_CommandAbc9Balance            ( Abc_Frame_t * pAbc, int argc, char ** argv );
437 static int Abc_CommandAbc9BalanceLut         ( Abc_Frame_t * pAbc, int argc, char ** argv );
438 static int Abc_CommandAbc9Syn2               ( Abc_Frame_t * pAbc, int argc, char ** argv );
439 static int Abc_CommandAbc9Syn3               ( Abc_Frame_t * pAbc, int argc, char ** argv );
440 static int Abc_CommandAbc9Syn4               ( Abc_Frame_t * pAbc, int argc, char ** argv );
441 static int Abc_CommandAbc9Synch2             ( Abc_Frame_t * pAbc, int argc, char ** argv );
442 static int Abc_CommandAbc9False              ( Abc_Frame_t * pAbc, int argc, char ** argv );
443 static int Abc_CommandAbc9Miter              ( Abc_Frame_t * pAbc, int argc, char ** argv );
444 static int Abc_CommandAbc9Miter2             ( Abc_Frame_t * pAbc, int argc, char ** argv );
445 static int Abc_CommandAbc9Append             ( Abc_Frame_t * pAbc, int argc, char ** argv );
446 static int Abc_CommandAbc9Scl                ( Abc_Frame_t * pAbc, int argc, char ** argv );
447 static int Abc_CommandAbc9Lcorr              ( Abc_Frame_t * pAbc, int argc, char ** argv );
448 static int Abc_CommandAbc9Scorr              ( Abc_Frame_t * pAbc, int argc, char ** argv );
449 static int Abc_CommandAbc9Choice             ( Abc_Frame_t * pAbc, int argc, char ** argv );
450 static int Abc_CommandAbc9Sat                ( Abc_Frame_t * pAbc, int argc, char ** argv );
451 static int Abc_CommandAbc9SatEnum            ( Abc_Frame_t * pAbc, int argc, char ** argv );
452 static int Abc_CommandAbc9Fraig              ( Abc_Frame_t * pAbc, int argc, char ** argv );
453 static int Abc_CommandAbc9CFraig             ( Abc_Frame_t * pAbc, int argc, char ** argv );
454 static int Abc_CommandAbc9Srm                ( Abc_Frame_t * pAbc, int argc, char ** argv );
455 static int Abc_CommandAbc9Srm2               ( Abc_Frame_t * pAbc, int argc, char ** argv );
456 static int Abc_CommandAbc9Filter             ( Abc_Frame_t * pAbc, int argc, char ** argv );
457 static int Abc_CommandAbc9Reduce             ( Abc_Frame_t * pAbc, int argc, char ** argv );
458 static int Abc_CommandAbc9EquivMark          ( Abc_Frame_t * pAbc, int argc, char ** argv );
459 static int Abc_CommandAbc9EquivFilter        ( Abc_Frame_t * pAbc, int argc, char ** argv );
460 static int Abc_CommandAbc9Cec                ( Abc_Frame_t * pAbc, int argc, char ** argv );
461 static int Abc_CommandAbc9Verify             ( Abc_Frame_t * pAbc, int argc, char ** argv );
462 static int Abc_CommandAbc9Sweep              ( Abc_Frame_t * pAbc, int argc, char ** argv );
463 static int Abc_CommandAbc9Force              ( Abc_Frame_t * pAbc, int argc, char ** argv );
464 static int Abc_CommandAbc9Embed              ( Abc_Frame_t * pAbc, int argc, char ** argv );
465 static int Abc_CommandAbc9Sopb               ( Abc_Frame_t * pAbc, int argc, char ** argv );
466 static int Abc_CommandAbc9Dsdb               ( Abc_Frame_t * pAbc, int argc, char ** argv );
467 static int Abc_CommandAbc9Flow               ( Abc_Frame_t * pAbc, int argc, char ** argv );
468 static int Abc_CommandAbc9Flow2              ( Abc_Frame_t * pAbc, int argc, char ** argv );
469 static int Abc_CommandAbc9Flow3              ( Abc_Frame_t * pAbc, int argc, char ** argv );
470 static int Abc_CommandAbc9If                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
471 static int Abc_CommandAbc9Iff                ( Abc_Frame_t * pAbc, int argc, char ** argv );
472 static int Abc_CommandAbc9Iiff               ( Abc_Frame_t * pAbc, int argc, char ** argv );
473 static int Abc_CommandAbc9If2                ( Abc_Frame_t * pAbc, int argc, char ** argv );
474 static int Abc_CommandAbc9Jf                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
475 static int Abc_CommandAbc9Kf                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
476 static int Abc_CommandAbc9Lf                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
477 static int Abc_CommandAbc9Mf                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
478 static int Abc_CommandAbc9Nf                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
479 static int Abc_CommandAbc9Of                 ( Abc_Frame_t * pAbc, int argc, char ** argv );
480 static int Abc_CommandAbc9Pack               ( Abc_Frame_t * pAbc, int argc, char ** argv );
481 static int Abc_CommandAbc9Edge               ( Abc_Frame_t * pAbc, int argc, char ** argv );
482 static int Abc_CommandAbc9SatLut             ( Abc_Frame_t * pAbc, int argc, char ** argv );
483 static int Abc_CommandAbc9Unmap              ( Abc_Frame_t * pAbc, int argc, char ** argv );
484 static int Abc_CommandAbc9Struct             ( Abc_Frame_t * pAbc, int argc, char ** argv );
485 static int Abc_CommandAbc9Trace              ( Abc_Frame_t * pAbc, int argc, char ** argv );
486 static int Abc_CommandAbc9Speedup            ( Abc_Frame_t * pAbc, int argc, char ** argv );
487 static int Abc_CommandAbc9Era                ( Abc_Frame_t * pAbc, int argc, char ** argv );
488 static int Abc_CommandAbc9Dch                ( Abc_Frame_t * pAbc, int argc, char ** argv );
489 static int Abc_CommandAbc9Rpm                ( Abc_Frame_t * pAbc, int argc, char ** argv );
490 static int Abc_CommandAbc9BackReach          ( Abc_Frame_t * pAbc, int argc, char ** argv );
491 static int Abc_CommandAbc9Posplit            ( Abc_Frame_t * pAbc, int argc, char ** argv );
492 static int Abc_CommandAbc9Permute            ( Abc_Frame_t * pAbc, int argc, char ** argv );
493 #ifdef ABC_USE_CUDD
494 static int Abc_CommandAbc9ReachM             ( Abc_Frame_t * pAbc, int argc, char ** argv );
495 static int Abc_CommandAbc9ReachP             ( Abc_Frame_t * pAbc, int argc, char ** argv );
496 static int Abc_CommandAbc9ReachN             ( Abc_Frame_t * pAbc, int argc, char ** argv );
497 static int Abc_CommandAbc9ReachY             ( Abc_Frame_t * pAbc, int argc, char ** argv );
498 #endif
499 static int Abc_CommandAbc9Undo               ( Abc_Frame_t * pAbc, int argc, char ** argv );
500 static int Abc_CommandAbc9Mesh               ( Abc_Frame_t * pAbc, int argc, char ** argv );
501 static int Abc_CommandAbc9Iso                ( Abc_Frame_t * pAbc, int argc, char ** argv );
502 static int Abc_CommandAbc9IsoNpn             ( Abc_Frame_t * pAbc, int argc, char ** argv );
503 static int Abc_CommandAbc9IsoSt              ( Abc_Frame_t * pAbc, int argc, char ** argv );
504 static int Abc_CommandAbc9CexInfo            ( Abc_Frame_t * pAbc, int argc, char ** argv );
505 static int Abc_CommandAbc9Cycle              ( Abc_Frame_t * pAbc, int argc, char ** argv );
506 static int Abc_CommandAbc9Cone               ( Abc_Frame_t * pAbc, int argc, char ** argv );
507 static int Abc_CommandAbc9Slice              ( Abc_Frame_t * pAbc, int argc, char ** argv );
508 static int Abc_CommandAbc9PoPart             ( Abc_Frame_t * pAbc, int argc, char ** argv );
509 static int Abc_CommandAbc9GroupProve         ( Abc_Frame_t * pAbc, int argc, char ** argv );
510 static int Abc_CommandAbc9MultiProve         ( Abc_Frame_t * pAbc, int argc, char ** argv );
511 static int Abc_CommandAbc9SplitProve         ( Abc_Frame_t * pAbc, int argc, char ** argv );
512 static int Abc_CommandAbc9Bmc                ( Abc_Frame_t * pAbc, int argc, char ** argv );
513 static int Abc_CommandAbc9SBmc               ( Abc_Frame_t * pAbc, int argc, char ** argv );
514 static int Abc_CommandAbc9ChainBmc           ( Abc_Frame_t * pAbc, int argc, char ** argv );
515 static int Abc_CommandAbc9BCore              ( Abc_Frame_t * pAbc, int argc, char ** argv );
516 static int Abc_CommandAbc9ICheck             ( Abc_Frame_t * pAbc, int argc, char ** argv );
517 static int Abc_CommandAbc9SatTest            ( Abc_Frame_t * pAbc, int argc, char ** argv );
518 static int Abc_CommandAbc9FFTest             ( Abc_Frame_t * pAbc, int argc, char ** argv );
519 static int Abc_CommandAbc9Qbf                ( Abc_Frame_t * pAbc, int argc, char ** argv );
520 static int Abc_CommandAbc9QVar               ( Abc_Frame_t * pAbc, int argc, char ** argv );
521 static int Abc_CommandAbc9GenQbf             ( Abc_Frame_t * pAbc, int argc, char ** argv );
522 static int Abc_CommandAbc9SatFx              ( Abc_Frame_t * pAbc, int argc, char ** argv );
523 static int Abc_CommandAbc9SatClp             ( Abc_Frame_t * pAbc, int argc, char ** argv );
524 static int Abc_CommandAbc9Inse               ( Abc_Frame_t * pAbc, int argc, char ** argv );
525 static int Abc_CommandAbc9Maxi               ( Abc_Frame_t * pAbc, int argc, char ** argv );
526 static int Abc_CommandAbc9Bmci               ( Abc_Frame_t * pAbc, int argc, char ** argv );
527 static int Abc_CommandAbc9PoXsim             ( Abc_Frame_t * pAbc, int argc, char ** argv );
528 static int Abc_CommandAbc9Demiter            ( Abc_Frame_t * pAbc, int argc, char ** argv );
529 static int Abc_CommandAbc9Fadds              ( Abc_Frame_t * pAbc, int argc, char ** argv );
530 static int Abc_CommandAbc9ATree              ( Abc_Frame_t * pAbc, int argc, char ** argv );
531 static int Abc_CommandAbc9Polyn              ( Abc_Frame_t * pAbc, int argc, char ** argv );
532 static int Abc_CommandAbc9Acec               ( Abc_Frame_t * pAbc, int argc, char ** argv );
533 static int Abc_CommandAbc9Anorm              ( Abc_Frame_t * pAbc, int argc, char ** argv );
534 static int Abc_CommandAbc9Decla              ( Abc_Frame_t * pAbc, int argc, char ** argv );
535 static int Abc_CommandAbc9Esop               ( Abc_Frame_t * pAbc, int argc, char ** argv );
536 static int Abc_CommandAbc9Exorcism           ( Abc_Frame_t * pAbc, int argc, char ** argv );
537 static int Abc_CommandAbc9Mfs                ( Abc_Frame_t * pAbc, int argc, char ** argv );
538 static int Abc_CommandAbc9Mfsd               ( Abc_Frame_t * pAbc, int argc, char ** argv );
539 static int Abc_CommandAbc9DeepSyn            ( Abc_Frame_t * pAbc, int argc, char ** argv );
540 //static int Abc_CommandAbc9PoPart2            ( Abc_Frame_t * pAbc, int argc, char ** argv );
541 //static int Abc_CommandAbc9CexCut             ( Abc_Frame_t * pAbc, int argc, char ** argv );
542 //static int Abc_CommandAbc9CexMerge           ( Abc_Frame_t * pAbc, int argc, char ** argv );
543 //static int Abc_CommandAbc9CexMin             ( Abc_Frame_t * pAbc, int argc, char ** argv );
544 
545 static int Abc_CommandAbc9AbsCreate          ( Abc_Frame_t * pAbc, int argc, char ** argv );
546 static int Abc_CommandAbc9AbsDerive          ( Abc_Frame_t * pAbc, int argc, char ** argv );
547 static int Abc_CommandAbc9AbsRefine          ( Abc_Frame_t * pAbc, int argc, char ** argv );
548 static int Abc_CommandAbc9GlaDerive          ( Abc_Frame_t * pAbc, int argc, char ** argv );
549 static int Abc_CommandAbc9GlaRefine          ( Abc_Frame_t * pAbc, int argc, char ** argv );
550 static int Abc_CommandAbc9GlaShrink          ( Abc_Frame_t * pAbc, int argc, char ** argv );
551 static int Abc_CommandAbc9Gla                ( Abc_Frame_t * pAbc, int argc, char ** argv );
552 static int Abc_CommandAbc9Vta                ( Abc_Frame_t * pAbc, int argc, char ** argv );
553 static int Abc_CommandAbc9Vta2Gla            ( Abc_Frame_t * pAbc, int argc, char ** argv );
554 static int Abc_CommandAbc9Gla2Vta            ( Abc_Frame_t * pAbc, int argc, char ** argv );
555 static int Abc_CommandAbc9Fla2Gla            ( Abc_Frame_t * pAbc, int argc, char ** argv );
556 static int Abc_CommandAbc9Gla2Fla            ( Abc_Frame_t * pAbc, int argc, char ** argv );
557 
558 static int Abc_CommandAbc9Gen                ( Abc_Frame_t * pAbc, int argc, char ** argv );
559 static int Abc_CommandAbc9Cfs                ( Abc_Frame_t * pAbc, int argc, char ** argv );
560 
561 static int Abc_CommandAbc9Test               ( Abc_Frame_t * pAbc, int argc, char ** argv );
562 
563 extern int Abc_CommandAbcLivenessToSafety    ( Abc_Frame_t * pAbc, int argc, char ** argv );
564 extern int Abc_CommandAbcLivenessToSafetySim ( Abc_Frame_t * pAbc, int argc, char ** argv );
565 extern int Abc_CommandAbcLivenessToSafetyWithLTL( Abc_Frame_t * pAbc, int argc, char ** argv );
566 extern int Abc_CommandCS_kLiveness           ( Abc_Frame_t * pAbc, int argc, char ** argv );
567 extern int Abc_CommandNChooseK               ( Abc_Frame_t * pAbc, int argc, char ** argv );
568 
569 extern Aig_Man_t * Abc_NtkToDar( Abc_Ntk_t * pNtk, int fExors, int fRegisters );
570 extern Abc_Ntk_t * Abc_NtkFromAigPhase( Aig_Man_t * pMan );
571 
572 ////////////////////////////////////////////////////////////////////////
573 ///                     FUNCTION DEFINITIONS                         ///
574 ////////////////////////////////////////////////////////////////////////
575 
576 /**Function*************************************************************
577 
578   Synopsis    []
579 
580   Description []
581 
582   SideEffects []
583 
584   SeeAlso     []
585 
586 ***********************************************************************/
Abc_FrameReplaceCex(Abc_Frame_t * pAbc,Abc_Cex_t ** ppCex)587 void Abc_FrameReplaceCex( Abc_Frame_t * pAbc, Abc_Cex_t ** ppCex )
588 {
589     // update CEX
590     ABC_FREE( pAbc->pCex );
591     pAbc->pCex = *ppCex;
592     *ppCex = NULL;
593     // remove CEX vector
594     if ( pAbc->vCexVec )
595     {
596         Vec_PtrFreeFree( pAbc->vCexVec );
597         pAbc->vCexVec = NULL;
598     }
599 }
600 
601 /**Function*************************************************************
602 
603   Synopsis    []
604 
605   Description []
606 
607   SideEffects []
608 
609   SeeAlso     []
610 
611 ***********************************************************************/
Abc_FrameReplaceCexVec(Abc_Frame_t * pAbc,Vec_Ptr_t ** pvCexVec)612 void Abc_FrameReplaceCexVec( Abc_Frame_t * pAbc, Vec_Ptr_t ** pvCexVec )
613 {
614     // update CEX vector
615     if ( pAbc->vCexVec )
616         Vec_PtrFreeFree( pAbc->vCexVec );
617     pAbc->vCexVec = *pvCexVec;
618     *pvCexVec = NULL;
619     // remove CEX
620     ABC_FREE( pAbc->pCex );
621 }
622 
623 /**Function*************************************************************
624 
625   Synopsis    []
626 
627   Description []
628 
629   SideEffects []
630 
631   SeeAlso     []
632 
633 ***********************************************************************/
Abc_FrameReplacePoEquivs(Abc_Frame_t * pAbc,Vec_Ptr_t ** pvPoEquivs)634 void Abc_FrameReplacePoEquivs( Abc_Frame_t * pAbc, Vec_Ptr_t ** pvPoEquivs )
635 {
636     if ( pAbc->vPoEquivs )
637         Vec_VecFree( (Vec_Vec_t *)pAbc->vPoEquivs );
638     pAbc->vPoEquivs = *pvPoEquivs;
639     *pvPoEquivs = NULL;
640 }
641 
642 /**Function*************************************************************
643 
644   Synopsis    []
645 
646   Description []
647 
648   SideEffects []
649 
650   SeeAlso     []
651 
652 ***********************************************************************/
Abc_FrameReplacePoStatuses(Abc_Frame_t * pAbc,Vec_Int_t ** pvStatuses)653 void Abc_FrameReplacePoStatuses( Abc_Frame_t * pAbc, Vec_Int_t ** pvStatuses )
654 {
655     if ( pAbc->vStatuses )
656         Vec_IntFree( pAbc->vStatuses );
657     pAbc->vStatuses = *pvStatuses;
658     *pvStatuses = NULL;
659 }
660 
661 /**Function*************************************************************
662 
663   Synopsis    [Derives array of statuses from the array of CEXes.]
664 
665   Description []
666 
667   SideEffects []
668 
669   SeeAlso     []
670 
671 ***********************************************************************/
Abc_FrameDeriveStatusArray(Vec_Ptr_t * vCexes)672 Vec_Int_t * Abc_FrameDeriveStatusArray( Vec_Ptr_t * vCexes )
673 {
674     Vec_Int_t * vStatuses;
675     Abc_Cex_t * pCex;
676     int i;
677     if ( vCexes == NULL )
678         return NULL;
679     vStatuses = Vec_IntAlloc( Vec_PtrSize(vCexes) );
680     Vec_IntFill( vStatuses, Vec_PtrSize(vCexes), -1 ); // assume UNDEC
681     Vec_PtrForEachEntry( Abc_Cex_t *, vCexes, pCex, i )
682         if ( pCex != NULL )
683             Vec_IntWriteEntry( vStatuses, i, 0 ); // set this output as SAT
684     return vStatuses;
685 }
Abc_FrameDeriveStatusArray2(Vec_Ptr_t * vCexes)686 Vec_Int_t * Abc_FrameDeriveStatusArray2( Vec_Ptr_t * vCexes )
687 {
688     Vec_Int_t * vStatuses;
689     Abc_Cex_t * pCex;
690     int i;
691     if ( vCexes == NULL )
692         return NULL;
693     vStatuses = Vec_IntAlloc( Vec_PtrSize(vCexes) );
694     Vec_IntFill( vStatuses, Vec_PtrSize(vCexes), -1 ); // assume UNDEC
695     Vec_PtrForEachEntry( Abc_Cex_t *, vCexes, pCex, i )
696         if ( pCex == (Abc_Cex_t *)(ABC_PTRINT_T)1 )
697         {
698             Vec_IntWriteEntry( vStatuses, i, 1 ); // set this output as UNSAT
699             Vec_PtrWriteEntry( vCexes, i, NULL );
700         }
701         else if ( pCex != NULL )
702             Vec_IntWriteEntry( vStatuses, i, 0 ); // set this output as SAT
703     return vStatuses;
704 }
705 
706 /**Function*************************************************************
707 
708   Synopsis    []
709 
710   Description []
711 
712   SideEffects []
713 
714   SeeAlso     []
715 
716 ***********************************************************************/
Abc_FrameClearDesign()717 void Abc_FrameClearDesign()
718 {
719 }
720 
721 /**Function*************************************************************
722 
723   Synopsis    []
724 
725   Description []
726 
727   SideEffects []
728 
729   SeeAlso     []
730 
731 ***********************************************************************/
Abc_FrameUpdateGia(Abc_Frame_t * pAbc,Gia_Man_t * pNew)732 void Abc_FrameUpdateGia( Abc_Frame_t * pAbc, Gia_Man_t * pNew )
733 {
734     if ( pNew == NULL )
735     {
736         Abc_Print( -1, "Abc_FrameUpdateGia(): Tranformation has failed.\n" );
737         return;
738     }
739     if ( Gia_ManPoNum(pNew) == 0 )
740         Abc_Print( 0, "The current GIA has no primary outputs. Some commands may not work correctly.\n" );
741     if ( pNew == pAbc->pGia )
742         return;
743     // transfer names
744     if (!pNew->vNamesIn && pAbc->pGia && pAbc->pGia->vNamesIn && Gia_ManCiNum(pNew) == Vec_PtrSize(pAbc->pGia->vNamesIn))
745     {
746         pNew->vNamesIn = pAbc->pGia->vNamesIn;
747         pAbc->pGia->vNamesIn = NULL;
748     }
749     if (!pNew->vNamesOut && pAbc->pGia && pAbc->pGia->vNamesOut && Gia_ManCoNum(pNew) == Vec_PtrSize(pAbc->pGia->vNamesOut))
750     {
751         pNew->vNamesOut = pAbc->pGia->vNamesOut;
752         pAbc->pGia->vNamesOut = NULL;
753     }
754     // update
755     if ( pAbc->pGia2 )
756         Gia_ManStop( pAbc->pGia2 );
757     pAbc->pGia2 = pAbc->pGia;
758     pAbc->pGia  = pNew;
759 }
760 
761 /**Function*************************************************************
762 
763   Synopsis    []
764 
765   Description []
766 
767   SideEffects []
768 
769   SeeAlso     []
770 
771 ***********************************************************************/
Abc_FrameGetGia(Abc_Frame_t * pAbc)772 Gia_Man_t * Abc_FrameGetGia( Abc_Frame_t * pAbc )
773 {
774     Gia_Man_t * pGia;
775     if ( pAbc->pGia2 )
776         Gia_ManStop( pAbc->pGia2 );
777     pAbc->pGia2 = NULL;
778     pGia = pAbc->pGia;
779     pAbc->pGia = NULL;
780     return pGia;
781 }
782 
783 
784 /**Function*************************************************************
785 
786   Synopsis    []
787 
788   Description []
789 
790   SideEffects []
791 
792   SeeAlso     []
793 
794 ***********************************************************************/
Abc_Init(Abc_Frame_t * pAbc)795 void Abc_Init( Abc_Frame_t * pAbc )
796 {
797     Cmd_CommandAdd( pAbc, "Printing",     "print_stats",   Abc_CommandPrintStats,       0 );
798     Cmd_CommandAdd( pAbc, "Printing",     "print_exdc",    Abc_CommandPrintExdc,        0 );
799     Cmd_CommandAdd( pAbc, "Printing",     "print_io",      Abc_CommandPrintIo,          0 );
800     Cmd_CommandAdd( pAbc, "Printing",     "print_latch",   Abc_CommandPrintLatch,       0 );
801     Cmd_CommandAdd( pAbc, "Printing",     "print_fanio",   Abc_CommandPrintFanio,       0 );
802     Cmd_CommandAdd( pAbc, "Printing",     "print_mffc",    Abc_CommandPrintMffc,        0 );
803     Cmd_CommandAdd( pAbc, "Printing",     "print_factor",  Abc_CommandPrintFactor,      0 );
804     Cmd_CommandAdd( pAbc, "Printing",     "print_level",   Abc_CommandPrintLevel,       0 );
805     Cmd_CommandAdd( pAbc, "Printing",     "print_supp",    Abc_CommandPrintSupport,     0 );
806     Cmd_CommandAdd( pAbc, "Printing",     "print_mint",    Abc_CommandPrintMint,        0 );
807     Cmd_CommandAdd( pAbc, "Printing",     "print_symm",    Abc_CommandPrintSymms,       0 );
808     Cmd_CommandAdd( pAbc, "Printing",     "print_unate",   Abc_CommandPrintUnate,       0 );
809     Cmd_CommandAdd( pAbc, "Printing",     "print_auto",    Abc_CommandPrintAuto,        0 );
810     Cmd_CommandAdd( pAbc, "Printing",     "print_kmap",    Abc_CommandPrintKMap,        0 );
811     Cmd_CommandAdd( pAbc, "Printing",     "print_gates",   Abc_CommandPrintGates,       0 );
812     Cmd_CommandAdd( pAbc, "Printing",     "print_sharing", Abc_CommandPrintSharing,     0 );
813     Cmd_CommandAdd( pAbc, "Printing",     "print_xcut",    Abc_CommandPrintXCut,        0 );
814     Cmd_CommandAdd( pAbc, "Printing",     "print_dsd",     Abc_CommandPrintDsd,         0 );
815     Cmd_CommandAdd( pAbc, "Printing",     "print_cone",    Abc_CommandPrintCone,        0 );
816     Cmd_CommandAdd( pAbc, "Printing",     "print_miter",   Abc_CommandPrintMiter,       0 );
817     Cmd_CommandAdd( pAbc, "Printing",     "print_status",  Abc_CommandPrintStatus,      0 );
818     Cmd_CommandAdd( pAbc, "Printing",     "print_delay",   Abc_CommandPrintDelay,       0 );
819 
820     Cmd_CommandAdd( pAbc, "Printing",     "show",          Abc_CommandShow,             0 );
821     Cmd_CommandAdd( pAbc, "Printing",     "show_bdd",      Abc_CommandShowBdd,          0 );
822     Cmd_CommandAdd( pAbc, "Printing",     "show_cut",      Abc_CommandShowCut,          0 );
823 
824     Cmd_CommandAdd( pAbc, "Synthesis",    "collapse",      Abc_CommandCollapse,         1 );
825     Cmd_CommandAdd( pAbc, "Synthesis",    "satclp",        Abc_CommandSatClp,           1 );
826     Cmd_CommandAdd( pAbc, "Synthesis",    "strash",        Abc_CommandStrash,           1 );
827     Cmd_CommandAdd( pAbc, "Synthesis",    "balance",       Abc_CommandBalance,          1 );
828     Cmd_CommandAdd( pAbc, "Synthesis",    "mux_struct",    Abc_CommandMuxStruct,        1 );
829     Cmd_CommandAdd( pAbc, "Synthesis",    "multi",         Abc_CommandMulti,            1 );
830     Cmd_CommandAdd( pAbc, "Synthesis",    "renode",        Abc_CommandRenode,           1 );
831     Cmd_CommandAdd( pAbc, "Synthesis",    "cleanup",       Abc_CommandCleanup,          1 );
832     Cmd_CommandAdd( pAbc, "Synthesis",    "sweep",         Abc_CommandSweep,            1 );
833     Cmd_CommandAdd( pAbc, "Synthesis",    "fx",            Abc_CommandFastExtract,      1 );
834     Cmd_CommandAdd( pAbc, "Synthesis",    "fxch",          Abc_CommandFxch,             1 );
835     Cmd_CommandAdd( pAbc, "Synthesis",    "eliminate",     Abc_CommandEliminate,        1 );
836     Cmd_CommandAdd( pAbc, "Synthesis",    "dsd",           Abc_CommandDisjoint,         1 );
837     Cmd_CommandAdd( pAbc, "Synthesis",    "sparsify",      Abc_CommandSparsify,         1 );
838     Cmd_CommandAdd( pAbc, "Synthesis",    "lutpack",       Abc_CommandLutpack,          1 );
839     Cmd_CommandAdd( pAbc, "Synthesis",    "lutmin",        Abc_CommandLutmin,           1 );
840 //    Cmd_CommandAdd( pAbc, "Synthesis",    "imfs",          Abc_CommandImfs,             1 );
841     Cmd_CommandAdd( pAbc, "Synthesis",    "mfs",           Abc_CommandMfs,              1 );
842     Cmd_CommandAdd( pAbc, "Synthesis",    "mfs2",          Abc_CommandMfs2,             1 );
843     Cmd_CommandAdd( pAbc, "Synthesis",    "mfs3",          Abc_CommandMfs3,             1 );
844     Cmd_CommandAdd( pAbc, "Synthesis",    "mfse",          Abc_CommandMfse,              1 );
845     Cmd_CommandAdd( pAbc, "Synthesis",    "logicpush",     Abc_CommandLogicPush,        1 );
846     Cmd_CommandAdd( pAbc, "Synthesis",    "trace",         Abc_CommandTrace,            0 );
847     Cmd_CommandAdd( pAbc, "Synthesis",    "glitch",        Abc_CommandGlitch,           0 );
848     Cmd_CommandAdd( pAbc, "Synthesis",    "speedup",       Abc_CommandSpeedup,          1 );
849     Cmd_CommandAdd( pAbc, "Synthesis",    "powerdown",     Abc_CommandPowerdown,        1 );
850     Cmd_CommandAdd( pAbc, "Synthesis",    "addbuffs",      Abc_CommandAddBuffs,         1 );
851     Cmd_CommandAdd( pAbc, "Synthesis",    "merge",         Abc_CommandMerge,            1 );
852     Cmd_CommandAdd( pAbc, "Synthesis",    "testdec",       Abc_CommandTestDec,          0 );
853     Cmd_CommandAdd( pAbc, "Synthesis",    "testnpn",       Abc_CommandTestNpn,          0 );
854     Cmd_CommandAdd( pAbc, "LogiCS",       "testrpo",       Abc_CommandTestRPO,          0 );
855     Cmd_CommandAdd( pAbc, "Synthesis",    "testtruth",     Abc_CommandTestTruth,        0 );
856     Cmd_CommandAdd( pAbc, "Synthesis",    "runeco",        Abc_CommandRunEco,           0 );
857     Cmd_CommandAdd( pAbc, "Synthesis",    "rungen",        Abc_CommandRunGen,           0 );
858     Cmd_CommandAdd( pAbc, "Synthesis",    "runsim",        Abc_CommandRunSim,           0 );
859     Cmd_CommandAdd( pAbc, "Synthesis",    "runtest",       Abc_CommandRunTest,          0 );
860 
861     Cmd_CommandAdd( pAbc, "Synthesis",    "rewrite",       Abc_CommandRewrite,          1 );
862     Cmd_CommandAdd( pAbc, "Synthesis",    "refactor",      Abc_CommandRefactor,         1 );
863 //    Cmd_CommandAdd( pAbc, "Synthesis",    "restructure",   Abc_CommandRestructure,      1 );
864     Cmd_CommandAdd( pAbc, "Synthesis",    "resub",         Abc_CommandResubstitute,     1 );
865 //    Cmd_CommandAdd( pAbc, "Synthesis",    "rr",            Abc_CommandRr,               1 );
866     Cmd_CommandAdd( pAbc, "Synthesis",    "cascade",       Abc_CommandCascade,          1 );
867     Cmd_CommandAdd( pAbc, "Synthesis",    "extract",       Abc_CommandExtract,          1 );
868     Cmd_CommandAdd( pAbc, "Synthesis",    "varmin",        Abc_CommandVarMin,           0 );
869     Cmd_CommandAdd( pAbc, "Synthesis",    "faultclasses",  Abc_CommandFaultClasses,     0 );
870     Cmd_CommandAdd( pAbc, "Synthesis",    "exact",         Abc_CommandExact,            1 );
871 
872     Cmd_CommandAdd( pAbc, "Exact synthesis", "bms_start",  Abc_CommandBmsStart,         0 );
873     Cmd_CommandAdd( pAbc, "Exact synthesis", "bms_stop",   Abc_CommandBmsStop,          0 );
874     Cmd_CommandAdd( pAbc, "Exact synthesis", "bms_ps",     Abc_CommandBmsPs,            0 );
875     Cmd_CommandAdd( pAbc, "Exact synthesis", "majexact",   Abc_CommandMajExact,         0 );
876     Cmd_CommandAdd( pAbc, "Exact synthesis", "twoexact",   Abc_CommandTwoExact,         0 );
877     Cmd_CommandAdd( pAbc, "Exact synthesis", "lutexact",   Abc_CommandLutExact,         0 );
878     Cmd_CommandAdd( pAbc, "Exact synthesis", "allexact",   Abc_CommandAllExact,         0 );
879     Cmd_CommandAdd( pAbc, "Exact synthesis", "testexact",  Abc_CommandTestExact,        0 );
880     Cmd_CommandAdd( pAbc, "Exact synthesis", "majgen",     Abc_CommandMajGen,           0 );
881 
882     Cmd_CommandAdd( pAbc, "Various",      "logic",         Abc_CommandLogic,            1 );
883     Cmd_CommandAdd( pAbc, "Various",      "comb",          Abc_CommandComb,             1 );
884     Cmd_CommandAdd( pAbc, "Various",      "miter",         Abc_CommandMiter,            1 );
885     Cmd_CommandAdd( pAbc, "Various",      "miter2",        Abc_CommandMiter2,           1 );
886     Cmd_CommandAdd( pAbc, "Various",      "demiter",       Abc_CommandDemiter,          1 );
887     Cmd_CommandAdd( pAbc, "Various",      "orpos",         Abc_CommandOrPos,            1 );
888     Cmd_CommandAdd( pAbc, "Various",      "andpos",        Abc_CommandAndPos,           1 );
889     Cmd_CommandAdd( pAbc, "Various",      "zeropo",        Abc_CommandZeroPo,           1 );
890     Cmd_CommandAdd( pAbc, "Various",      "swappos",       Abc_CommandSwapPos,          1 );
891     Cmd_CommandAdd( pAbc, "Various",      "removepo",      Abc_CommandRemovePo,         1 );
892     Cmd_CommandAdd( pAbc, "Various",      "dropsat",       Abc_CommandDropSat,          1 );
893     Cmd_CommandAdd( pAbc, "Various",      "addpi",         Abc_CommandAddPi,            1 );
894     Cmd_CommandAdd( pAbc, "Various",      "append",        Abc_CommandAppend,           1 );
895     Cmd_CommandAdd( pAbc, "Various",      "putontop",      Abc_CommandPutOnTop,         1 );
896     Cmd_CommandAdd( pAbc, "Various",      "frames",        Abc_CommandFrames,           1 );
897     Cmd_CommandAdd( pAbc, "Various",      "dframes",       Abc_CommandDFrames,          1 );
898     Cmd_CommandAdd( pAbc, "Various",      "sop",           Abc_CommandSop,              0 );
899     Cmd_CommandAdd( pAbc, "Various",      "bdd",           Abc_CommandBdd,              0 );
900     Cmd_CommandAdd( pAbc, "Various",      "aig",           Abc_CommandAig,              0 );
901     Cmd_CommandAdd( pAbc, "Various",      "reorder",       Abc_CommandReorder,          0 );
902     Cmd_CommandAdd( pAbc, "Various",      "bidec",         Abc_CommandBidec,            1 );
903     Cmd_CommandAdd( pAbc, "Various",      "order",         Abc_CommandOrder,            0 );
904     Cmd_CommandAdd( pAbc, "Various",      "muxes",         Abc_CommandMuxes,            1 );
905     Cmd_CommandAdd( pAbc, "Various",      "cubes",         Abc_CommandCubes,            1 );
906     Cmd_CommandAdd( pAbc, "Various",      "expand",        Abc_CommandExpand,           1 );
907     Cmd_CommandAdd( pAbc, "Various",      "splitsop",      Abc_CommandSplitSop,         1 );
908     Cmd_CommandAdd( pAbc, "Various",      "ext_seq_dcs",   Abc_CommandExtSeqDcs,        0 );
909     Cmd_CommandAdd( pAbc, "Various",      "reach",         Abc_CommandReach,            0 );
910     Cmd_CommandAdd( pAbc, "Various",      "cone",          Abc_CommandCone,             1 );
911     Cmd_CommandAdd( pAbc, "Various",      "node",          Abc_CommandNode,             1 );
912     Cmd_CommandAdd( pAbc, "Various",      "cof",           Abc_CommandCof,              1 );
913     Cmd_CommandAdd( pAbc, "Various",      "topmost",       Abc_CommandTopmost,          1 );
914     Cmd_CommandAdd( pAbc, "Various",      "topand",        Abc_CommandTopAnd,           1 );
915     Cmd_CommandAdd( pAbc, "Various",      "trim",          Abc_CommandTrim,             1 );
916     Cmd_CommandAdd( pAbc, "Various",      "short_names",   Abc_CommandShortNames,       0 );
917     Cmd_CommandAdd( pAbc, "Various",      "move_names",    Abc_CommandMoveNames,        0 );
918     Cmd_CommandAdd( pAbc, "Various",      "exdc_free",     Abc_CommandExdcFree,         1 );
919     Cmd_CommandAdd( pAbc, "Various",      "exdc_get",      Abc_CommandExdcGet,          1 );
920     Cmd_CommandAdd( pAbc, "Various",      "exdc_set",      Abc_CommandExdcSet,          1 );
921     Cmd_CommandAdd( pAbc, "Various",      "care_set",      Abc_CommandCareSet,          1 );
922     Cmd_CommandAdd( pAbc, "Various",      "cut",           Abc_CommandCut,              0 );
923     Cmd_CommandAdd( pAbc, "Various",      "espresso",      Abc_CommandEspresso,         1 );
924     Cmd_CommandAdd( pAbc, "Various",      "gen",           Abc_CommandGen,              0 );
925     Cmd_CommandAdd( pAbc, "Various",      "genfsm",        Abc_CommandGenFsm,           0 );
926     Cmd_CommandAdd( pAbc, "Various",      "cover",         Abc_CommandCover,            1 );
927     Cmd_CommandAdd( pAbc, "Various",      "double",        Abc_CommandDouble,           1 );
928     Cmd_CommandAdd( pAbc, "Various",      "inter",         Abc_CommandInter,            1 );
929     Cmd_CommandAdd( pAbc, "Various",      "bb2wb",         Abc_CommandBb2Wb,            0 );
930     Cmd_CommandAdd( pAbc, "Various",      "outdec",        Abc_CommandOutdec,           1 );
931     Cmd_CommandAdd( pAbc, "Various",      "nodedup",       Abc_CommandNodeDup,          1 );
932     Cmd_CommandAdd( pAbc, "Various",      "testcolor",     Abc_CommandTestColor,        0 );
933     Cmd_CommandAdd( pAbc, "Various",      "test",          Abc_CommandTest,             0 );
934 //    Cmd_CommandAdd( pAbc, "Various",      "qbf_solve",     Abc_CommandTest,               0 );
935 
936     Cmd_CommandAdd( pAbc, "Various",      "qvar",          Abc_CommandQuaVar,           1 );
937     Cmd_CommandAdd( pAbc, "Various",      "qrel",          Abc_CommandQuaRel,           1 );
938     Cmd_CommandAdd( pAbc, "Various",      "qreach",        Abc_CommandQuaReach,         1 );
939     Cmd_CommandAdd( pAbc, "Various",      "senseinput",    Abc_CommandSenseInput,       1 );
940     Cmd_CommandAdd( pAbc, "Various",      "npnload",       Abc_CommandNpnLoad,          0 );
941     Cmd_CommandAdd( pAbc, "Various",      "npnsave",       Abc_CommandNpnSave,          0 );
942 
943     Cmd_CommandAdd( pAbc, "Various",      "send_aig",      Abc_CommandSendAig,          0 );
944     Cmd_CommandAdd( pAbc, "Various",      "send_status",   Abc_CommandSendStatus,       0 );
945 
946     Cmd_CommandAdd( pAbc, "Various",      "backup",        Abc_CommandBackup,           0 );
947     Cmd_CommandAdd( pAbc, "Various",      "restore",       Abc_CommandRestore,          0 );
948 
949     Cmd_CommandAdd( pAbc, "Various",      "minisat",       Abc_CommandMinisat,          0 );
950     Cmd_CommandAdd( pAbc, "Various",      "minisimp",      Abc_CommandMinisimp,         0 );
951 
952     Cmd_CommandAdd( pAbc, "New AIG",      "istrash",       Abc_CommandIStrash,          1 );
953     Cmd_CommandAdd( pAbc, "New AIG",      "icut",          Abc_CommandICut,             0 );
954     Cmd_CommandAdd( pAbc, "New AIG",      "irw",           Abc_CommandIRewrite,         1 );
955     Cmd_CommandAdd( pAbc, "New AIG",      "drw",           Abc_CommandDRewrite,         1 );
956     Cmd_CommandAdd( pAbc, "New AIG",      "drf",           Abc_CommandDRefactor,        1 );
957     Cmd_CommandAdd( pAbc, "New AIG",      "dc2",           Abc_CommandDc2,              1 );
958     Cmd_CommandAdd( pAbc, "New AIG",      "dchoice",       Abc_CommandDChoice,          1 );
959     Cmd_CommandAdd( pAbc, "New AIG",      "dch",           Abc_CommandDch,              1 );
960     Cmd_CommandAdd( pAbc, "New AIG",      "drwsat",        Abc_CommandDrwsat,           1 );
961     Cmd_CommandAdd( pAbc, "New AIG",      "irws",          Abc_CommandIRewriteSeq,      1 );
962     Cmd_CommandAdd( pAbc, "New AIG",      "iresyn",        Abc_CommandIResyn,           1 );
963     Cmd_CommandAdd( pAbc, "New AIG",      "isat",          Abc_CommandISat,             1 );
964     Cmd_CommandAdd( pAbc, "New AIG",      "ifraig",        Abc_CommandIFraig,           1 );
965     Cmd_CommandAdd( pAbc, "New AIG",      "dfraig",        Abc_CommandDFraig,           1 );
966     Cmd_CommandAdd( pAbc, "New AIG",      "csweep",        Abc_CommandCSweep,           1 );
967 //    Cmd_CommandAdd( pAbc, "New AIG",      "haig",          Abc_CommandHaig,             1 );
968     Cmd_CommandAdd( pAbc, "New AIG",      "qbf",           Abc_CommandQbf,              0 );
969 
970     Cmd_CommandAdd( pAbc, "Fraiging",     "fraig",         Abc_CommandFraig,            1 );
971     Cmd_CommandAdd( pAbc, "Fraiging",     "fraig_trust",   Abc_CommandFraigTrust,       1 );
972     Cmd_CommandAdd( pAbc, "Fraiging",     "fraig_store",   Abc_CommandFraigStore,       0 );
973     Cmd_CommandAdd( pAbc, "Fraiging",     "fraig_restore", Abc_CommandFraigRestore,     1 );
974     Cmd_CommandAdd( pAbc, "Fraiging",     "fraig_clean",   Abc_CommandFraigClean,       0 );
975     Cmd_CommandAdd( pAbc, "Fraiging",     "fraig_sweep",   Abc_CommandFraigSweep,       1 );
976     Cmd_CommandAdd( pAbc, "Fraiging",     "dress",         Abc_CommandFraigDress,       1 );
977     Cmd_CommandAdd( pAbc, "Fraiging",     "dump_equiv",    Abc_CommandDumpEquiv,        0 );
978 
979     Cmd_CommandAdd( pAbc, "Choicing",     "rec_start3",    Abc_CommandRecStart3,        0 );
980     Cmd_CommandAdd( pAbc, "Choicing",     "rec_stop3",     Abc_CommandRecStop3,         0 );
981     Cmd_CommandAdd( pAbc, "Choicing",     "rec_ps3",       Abc_CommandRecPs3,           0 );
982     Cmd_CommandAdd( pAbc, "Choicing",     "rec_add3",      Abc_CommandRecAdd3,          0 );
983     Cmd_CommandAdd( pAbc, "Choicing",     "rec_dump3",     Abc_CommandRecDump3,         0 );
984     Cmd_CommandAdd( pAbc, "Choicing",     "rec_merge3",    Abc_CommandRecMerge3,        0 );
985 
986     Cmd_CommandAdd( pAbc, "SC mapping",   "map",           Abc_CommandMap,              1 );
987     Cmd_CommandAdd( pAbc, "SC mapping",   "amap",          Abc_CommandAmap,             1 );
988     Cmd_CommandAdd( pAbc, "SC mapping",   "phase_map",     Abc_CommandPhaseMap,         1 );
989     Cmd_CommandAdd( pAbc, "SC mapping",   "unmap",         Abc_CommandUnmap,            1 );
990     Cmd_CommandAdd( pAbc, "SC mapping",   "attach",        Abc_CommandAttach,           1 );
991     Cmd_CommandAdd( pAbc, "SC mapping",   "superc",        Abc_CommandSuperChoice,      1 );
992     Cmd_CommandAdd( pAbc, "SC mapping",   "supercl",       Abc_CommandSuperChoiceLut,   1 );
993     Cmd_CommandAdd( pAbc, "SC mapping",   "timescale",     Abc_CommandTimeScale,        0 );
994 
995 //    Cmd_CommandAdd( pAbc, "FPGA mapping", "fpga",          Abc_CommandFpga,             1 );
996 //    Cmd_CommandAdd( pAbc, "FPGA mapping", "ffpga",         Abc_CommandFpgaFast,         1 );
997     Cmd_CommandAdd( pAbc, "FPGA mapping", "if",            Abc_CommandIf,               1 );
998     Cmd_CommandAdd( pAbc, "FPGA mapping", "ifif",          Abc_CommandIfif,             1 );
999 
1000     Cmd_CommandAdd( pAbc, "DSD manager",  "dsd_save",      Abc_CommandDsdSave,          0 );
1001     Cmd_CommandAdd( pAbc, "DSD manager",  "dsd_load",      Abc_CommandDsdLoad,          0 );
1002     Cmd_CommandAdd( pAbc, "DSD manager",  "dsd_free",      Abc_CommandDsdFree,          0 );
1003     Cmd_CommandAdd( pAbc, "DSD manager",  "dsd_ps",        Abc_CommandDsdPs,            0 );
1004     Cmd_CommandAdd( pAbc, "DSD manager",  "dsd_match",     Abc_CommandDsdMatch,         0 );
1005     Cmd_CommandAdd( pAbc, "DSD manager",  "dsd_merge",     Abc_CommandDsdMerge,         0 );
1006     Cmd_CommandAdd( pAbc, "DSD manager",  "dsd_filter",    Abc_CommandDsdFilter,        0 );
1007 
1008 //    Cmd_CommandAdd( pAbc, "Sequential",   "scut",          Abc_CommandScut,             0 );
1009     Cmd_CommandAdd( pAbc, "Sequential",   "init",          Abc_CommandInit,             1 );
1010     Cmd_CommandAdd( pAbc, "Sequential",   "zero",          Abc_CommandZero,             1 );
1011     Cmd_CommandAdd( pAbc, "Sequential",   "undc",          Abc_CommandUndc,             1 );
1012     Cmd_CommandAdd( pAbc, "Sequential",   "onehot",        Abc_CommandOneHot,           1 );
1013 //    Cmd_CommandAdd( pAbc, "Sequential",   "pipe",          Abc_CommandPipe,             1 );
1014     Cmd_CommandAdd( pAbc, "Sequential",   "retime",        Abc_CommandRetime,           1 );
1015     Cmd_CommandAdd( pAbc, "Sequential",   "dretime",       Abc_CommandDRetime,          1 );
1016     Cmd_CommandAdd( pAbc, "Sequential",   "fretime",       Abc_CommandFlowRetime,       1 );
1017     Cmd_CommandAdd( pAbc, "Sequential",   "cretime",       Abc_CommandCRetime,          1 );
1018 //    Cmd_CommandAdd( pAbc, "Sequential",   "sfpga",         Abc_CommandSeqFpga,          1 );
1019 //    Cmd_CommandAdd( pAbc, "Sequential",   "smap",          Abc_CommandSeqMap,           1 );
1020     Cmd_CommandAdd( pAbc, "Sequential",   "ssweep",        Abc_CommandSeqSweep,         1 );
1021     Cmd_CommandAdd( pAbc, "Sequential",   "scorr",         Abc_CommandSeqSweep2,        1 );
1022     Cmd_CommandAdd( pAbc, "Sequential",   "testssw",       Abc_CommandTestSeqSweep,     0 );
1023     Cmd_CommandAdd( pAbc, "Sequential",   "testscorr",     Abc_CommandTestScorr,        0 );
1024     Cmd_CommandAdd( pAbc, "Sequential",   "lcorr",         Abc_CommandLcorr,            1 );
1025     Cmd_CommandAdd( pAbc, "Sequential",   "scleanup",      Abc_CommandSeqCleanup,       1 );
1026     Cmd_CommandAdd( pAbc, "Sequential",   "cycle",         Abc_CommandCycle,            1 );
1027     Cmd_CommandAdd( pAbc, "Sequential",   "xsim",          Abc_CommandXsim,             0 );
1028     Cmd_CommandAdd( pAbc, "Sequential",   "sim",           Abc_CommandSim,              0 );
1029     Cmd_CommandAdd( pAbc, "Sequential",   "sim3",          Abc_CommandSim3,             0 );
1030     Cmd_CommandAdd( pAbc, "Sequential",   "phase",         Abc_CommandDarPhase,         1 );
1031     Cmd_CommandAdd( pAbc, "Sequential",   "synch",         Abc_CommandSynch,            1 );
1032     Cmd_CommandAdd( pAbc, "Sequential",   "clockgate",     Abc_CommandClockGate,        1 );
1033     Cmd_CommandAdd( pAbc, "Sequential",   "extwin",        Abc_CommandExtWin,           1 );
1034     Cmd_CommandAdd( pAbc, "Sequential",   "inswin",        Abc_CommandInsWin,           1 );
1035     Cmd_CommandAdd( pAbc, "Sequential",   "symfun",        Abc_CommandSymFun,           0 );
1036     Cmd_CommandAdd( pAbc, "Sequential",   "permute",       Abc_CommandPermute,          1 );
1037     Cmd_CommandAdd( pAbc, "Sequential",   "unpermute",     Abc_CommandUnpermute,        1 );
1038     Cmd_CommandAdd( pAbc, "Sequential",   "cubeenum",      Abc_CommandCubeEnum,         0 );
1039     Cmd_CommandAdd( pAbc, "Sequential",   "pathenum",      Abc_CommandPathEnum,         0 );
1040     Cmd_CommandAdd( pAbc, "Sequential",   "funenum",       Abc_CommandFunEnum,          0 );
1041 
1042     Cmd_CommandAdd( pAbc, "Verification", "cec",           Abc_CommandCec,              0 );
1043     Cmd_CommandAdd( pAbc, "Verification", "dcec",          Abc_CommandDCec,             0 );
1044     Cmd_CommandAdd( pAbc, "Verification", "dsec",          Abc_CommandDSec,             0 );
1045     Cmd_CommandAdd( pAbc, "Verification", "dprove",        Abc_CommandDProve,           0 );
1046     Cmd_CommandAdd( pAbc, "Verification", "absec",         Abc_CommandAbSec,            0 );
1047     Cmd_CommandAdd( pAbc, "Verification", "simsec",        Abc_CommandSimSec,           0 );
1048     Cmd_CommandAdd( pAbc, "Verification", "match",         Abc_CommandMatch,            0 );
1049     Cmd_CommandAdd( pAbc, "Verification", "sat",           Abc_CommandSat,              0 );
1050     Cmd_CommandAdd( pAbc, "Verification", "dsat",          Abc_CommandDSat,             0 );
1051     Cmd_CommandAdd( pAbc, "Verification", "xsat",          Abc_CommandXSat,             0 );
1052     Cmd_CommandAdd( pAbc, "Verification", "satoko",        Abc_CommandSatoko,           0 );
1053     Cmd_CommandAdd( pAbc, "Verification", "&satoko",       Abc_CommandAbc9Satoko,       0 );
1054     Cmd_CommandAdd( pAbc, "Verification", "&sat3",         Abc_CommandAbc9Sat3,         0 );
1055     Cmd_CommandAdd( pAbc, "Verification", "psat",          Abc_CommandPSat,             0 );
1056     Cmd_CommandAdd( pAbc, "Verification", "prove",         Abc_CommandProve,            1 );
1057     Cmd_CommandAdd( pAbc, "Verification", "iprove",        Abc_CommandIProve,           1 );
1058     Cmd_CommandAdd( pAbc, "Verification", "debug",         Abc_CommandDebug,            0 );
1059     Cmd_CommandAdd( pAbc, "Verification", "eco",           Abc_CommandEco,              0 );
1060     Cmd_CommandAdd( pAbc, "Verification", "bmc",           Abc_CommandBmc,              0 );
1061     Cmd_CommandAdd( pAbc, "Verification", "bmc2",          Abc_CommandBmc2,             0 );
1062     Cmd_CommandAdd( pAbc, "Verification", "bmc3",          Abc_CommandBmc3,             1 );
1063     Cmd_CommandAdd( pAbc, "Verification", "int",           Abc_CommandBmcInter,         1 );
1064     Cmd_CommandAdd( pAbc, "Verification", "indcut",        Abc_CommandIndcut,           0 );
1065     Cmd_CommandAdd( pAbc, "Verification", "enlarge",       Abc_CommandEnlarge,          1 );
1066     Cmd_CommandAdd( pAbc, "Verification", "tempor",        Abc_CommandTempor,           1 );
1067     Cmd_CommandAdd( pAbc, "Verification", "ind",           Abc_CommandInduction,        0 );
1068     Cmd_CommandAdd( pAbc, "Verification", "constr",        Abc_CommandConstr,           0 );
1069     Cmd_CommandAdd( pAbc, "Verification", "unfold",        Abc_CommandUnfold,           1 );
1070     Cmd_CommandAdd( pAbc, "Verification", "fold",          Abc_CommandFold,             1 );
1071     Cmd_CommandAdd( pAbc, "Verification", "unfold2",       Abc_CommandUnfold2,          1 );    // jlong
1072     Cmd_CommandAdd( pAbc, "Verification", "fold2",         Abc_CommandFold2,            1 );    // jlong
1073     Cmd_CommandAdd( pAbc, "Verification", "bm",            Abc_CommandBm,               1 );
1074     Cmd_CommandAdd( pAbc, "Verification", "bm2",           Abc_CommandBm2,              1 );
1075     Cmd_CommandAdd( pAbc, "Verification", "saucy3",        Abc_CommandSaucy,            1 );
1076     Cmd_CommandAdd( pAbc, "Verification", "testcex",       Abc_CommandTestCex,          0 );
1077     Cmd_CommandAdd( pAbc, "Verification", "pdr",           Abc_CommandPdr,              0 );
1078 #ifdef ABC_USE_CUDD
1079     Cmd_CommandAdd( pAbc, "Verification", "reconcile",     Abc_CommandReconcile,        1 );
1080 #endif
1081     Cmd_CommandAdd( pAbc, "Verification", "cexsave",       Abc_CommandCexSave,          0 );
1082     Cmd_CommandAdd( pAbc, "Verification", "cexload",       Abc_CommandCexLoad,          0 );
1083     Cmd_CommandAdd( pAbc, "Verification", "cexcut",        Abc_CommandCexCut,           0 );
1084     Cmd_CommandAdd( pAbc, "Verification", "cexmerge",      Abc_CommandCexMerge,         0 );
1085 //    Cmd_CommandAdd( pAbc, "Verification", "cexmin",        Abc_CommandCexMin,           0 );
1086     Cmd_CommandAdd( pAbc, "Verification", "dualrail",      Abc_CommandDualRail,         1 );
1087     Cmd_CommandAdd( pAbc, "Verification", "blockpo",       Abc_CommandBlockPo,          1 );
1088     Cmd_CommandAdd( pAbc, "Verification", "iso",           Abc_CommandIso,              1 );
1089 
1090     Cmd_CommandAdd( pAbc, "Various",      "save",          Abc_CommandAbcSave,          0 );
1091     Cmd_CommandAdd( pAbc, "Various",      "load",          Abc_CommandAbcLoad,          0 );
1092 
1093     Cmd_CommandAdd( pAbc, "ABC9",         "&get",          Abc_CommandAbc9Get,          0 );
1094     Cmd_CommandAdd( pAbc, "ABC9",         "&put",          Abc_CommandAbc9Put,          0 );
1095     Cmd_CommandAdd( pAbc, "ABC9",         "&save",         Abc_CommandAbc9Save,         0 );
1096     Cmd_CommandAdd( pAbc, "ABC9",         "&save2",        Abc_CommandAbc9Save2,        0 );
1097     Cmd_CommandAdd( pAbc, "ABC9",         "&saveaig",      Abc_CommandAbc9SaveAig,      0 );
1098     Cmd_CommandAdd( pAbc, "ABC9",         "&load",         Abc_CommandAbc9Load,         0 );
1099     Cmd_CommandAdd( pAbc, "ABC9",         "&load2",        Abc_CommandAbc9Load2,        0 );
1100     Cmd_CommandAdd( pAbc, "ABC9",         "&loadaig",      Abc_CommandAbc9LoadAig,      0 );
1101     Cmd_CommandAdd( pAbc, "ABC9",         "&r",            Abc_CommandAbc9Read,         0 );
1102     Cmd_CommandAdd( pAbc, "ABC9",         "&read",         Abc_CommandAbc9Read,         0 );
1103     Cmd_CommandAdd( pAbc, "ABC9",         "&read_blif",    Abc_CommandAbc9ReadBlif,     0 );
1104     Cmd_CommandAdd( pAbc, "ABC9",         "&read_cblif",   Abc_CommandAbc9ReadCBlif,    0 );
1105     Cmd_CommandAdd( pAbc, "ABC9",         "&read_stg",     Abc_CommandAbc9ReadStg,      0 );
1106     Cmd_CommandAdd( pAbc, "ABC9",         "&read_ver",     Abc_CommandAbc9ReadVer,      0 );
1107     Cmd_CommandAdd( pAbc, "ABC9",         "&write_ver",    Abc_CommandAbc9WriteVer,     0 );
1108     Cmd_CommandAdd( pAbc, "ABC9",         "&w",            Abc_CommandAbc9Write,        0 );
1109     Cmd_CommandAdd( pAbc, "ABC9",         "&write",        Abc_CommandAbc9Write,        0 );
1110     Cmd_CommandAdd( pAbc, "ABC9",         "&wlut",         Abc_CommandAbc9WriteLut,     0 );
1111     Cmd_CommandAdd( pAbc, "ABC9",         "&ps",           Abc_CommandAbc9Ps,           0 );
1112     Cmd_CommandAdd( pAbc, "ABC9",         "&pfan",         Abc_CommandAbc9PFan,         0 );
1113     Cmd_CommandAdd( pAbc, "ABC9",         "&psig",         Abc_CommandAbc9PSig,         0 );
1114     Cmd_CommandAdd( pAbc, "ABC9",         "&status",       Abc_CommandAbc9Status,       0 );
1115     Cmd_CommandAdd( pAbc, "ABC9",         "&profile",      Abc_CommandAbc9MuxProfile,   0 );
1116     Cmd_CommandAdd( pAbc, "ABC9",         "&muxpos",       Abc_CommandAbc9MuxPos,       0 );
1117     Cmd_CommandAdd( pAbc, "ABC9",         "&print_truth",  Abc_CommandAbc9PrintTruth,   0 );
1118     Cmd_CommandAdd( pAbc, "ABC9",         "&unate",        Abc_CommandAbc9Unate,        0 );
1119     Cmd_CommandAdd( pAbc, "ABC9",         "&rex2gia",      Abc_CommandAbc9Rex2Gia,      0 );
1120     Cmd_CommandAdd( pAbc, "ABC9",         "&rexwalk",      Abc_CommandAbc9RexWalk,      0 );
1121     Cmd_CommandAdd( pAbc, "ABC9",         "&show",         Abc_CommandAbc9Show,         0 );
1122     Cmd_CommandAdd( pAbc, "ABC9",         "&setregnum",    Abc_CommandAbc9SetRegNum,    0 );
1123     Cmd_CommandAdd( pAbc, "ABC9",         "&st",           Abc_CommandAbc9Strash,       0 );
1124     Cmd_CommandAdd( pAbc, "ABC9",         "&topand",       Abc_CommandAbc9Topand,       0 );
1125     Cmd_CommandAdd( pAbc, "ABC9",         "&add1hot",      Abc_CommandAbc9Add1Hot,      0 );
1126     Cmd_CommandAdd( pAbc, "ABC9",         "&cof",          Abc_CommandAbc9Cof,          0 );
1127     Cmd_CommandAdd( pAbc, "ABC9",         "&trim",         Abc_CommandAbc9Trim,         0 );
1128     Cmd_CommandAdd( pAbc, "ABC9",         "&dfs",          Abc_CommandAbc9Dfs,          0 );
1129     Cmd_CommandAdd( pAbc, "ABC9",         "&sim",          Abc_CommandAbc9Sim,          0 );
1130     Cmd_CommandAdd( pAbc, "ABC9",         "&sim3",         Abc_CommandAbc9Sim3,         0 );
1131     Cmd_CommandAdd( pAbc, "ABC9",         "&mlgen",        Abc_CommandAbc9MLGen,        0 );
1132     Cmd_CommandAdd( pAbc, "ABC9",         "&mltest",       Abc_CommandAbc9MLTest,       0 );
1133     Cmd_CommandAdd( pAbc, "ABC9",         "&read_sim",     Abc_CommandAbc9ReadSim,      0 );
1134     Cmd_CommandAdd( pAbc, "ABC9",         "&write_sim",    Abc_CommandAbc9WriteSim,     0 );
1135     Cmd_CommandAdd( pAbc, "ABC9",         "&simpat",       Abc_CommandAbc9SimPat,       0 );
1136     Cmd_CommandAdd( pAbc, "ABC9",         "&simrsb",       Abc_CommandAbc9SimRsb,       0 );
1137     Cmd_CommandAdd( pAbc, "ABC9",         "&resim",        Abc_CommandAbc9Resim,        0 );
1138     Cmd_CommandAdd( pAbc, "ABC9",         "&speci",        Abc_CommandAbc9SpecI,        0 );
1139     Cmd_CommandAdd( pAbc, "ABC9",         "&equiv",        Abc_CommandAbc9Equiv,        0 );
1140     Cmd_CommandAdd( pAbc, "ABC9",         "&equiv2",       Abc_CommandAbc9Equiv2,       0 );
1141     Cmd_CommandAdd( pAbc, "ABC9",         "&equiv3",       Abc_CommandAbc9Equiv3,       0 );
1142     Cmd_CommandAdd( pAbc, "ABC9",         "&semi",         Abc_CommandAbc9Semi,         0 );
1143     Cmd_CommandAdd( pAbc, "ABC9",         "&times",        Abc_CommandAbc9Times,        0 );
1144     Cmd_CommandAdd( pAbc, "ABC9",         "&frames",       Abc_CommandAbc9Frames,       0 );
1145     Cmd_CommandAdd( pAbc, "ABC9",         "&retime",       Abc_CommandAbc9Retime,       0 );
1146     Cmd_CommandAdd( pAbc, "ABC9",         "&enable",       Abc_CommandAbc9Enable,       0 );
1147     Cmd_CommandAdd( pAbc, "ABC9",         "&dc2",          Abc_CommandAbc9Dc2,          0 );
1148     Cmd_CommandAdd( pAbc, "ABC9",         "&dsd",          Abc_CommandAbc9Dsd,          0 );
1149     Cmd_CommandAdd( pAbc, "ABC9",         "&bidec",        Abc_CommandAbc9Bidec,        0 );
1150     Cmd_CommandAdd( pAbc, "ABC9",         "&shrink",       Abc_CommandAbc9Shrink,       0 );
1151     Cmd_CommandAdd( pAbc, "ABC9",         "&fx",           Abc_CommandAbc9Fx,           0 );
1152     Cmd_CommandAdd( pAbc, "ABC9",         "&b",            Abc_CommandAbc9Balance,      0 );
1153     Cmd_CommandAdd( pAbc, "ABC9",         "&blut",         Abc_CommandAbc9BalanceLut,   0 );
1154     Cmd_CommandAdd( pAbc, "ABC9",         "&syn2",         Abc_CommandAbc9Syn2,         0 );
1155     Cmd_CommandAdd( pAbc, "ABC9",         "&syn3",         Abc_CommandAbc9Syn3,         0 );
1156     Cmd_CommandAdd( pAbc, "ABC9",         "&syn4",         Abc_CommandAbc9Syn4,         0 );
1157     Cmd_CommandAdd( pAbc, "ABC9",         "&synch2",       Abc_CommandAbc9Synch2,       0 );
1158     Cmd_CommandAdd( pAbc, "ABC9",         "&false",        Abc_CommandAbc9False,        0 );
1159     Cmd_CommandAdd( pAbc, "ABC9",         "&miter",        Abc_CommandAbc9Miter,        0 );
1160     Cmd_CommandAdd( pAbc, "ABC9",         "&miter2",       Abc_CommandAbc9Miter2,       0 );
1161     Cmd_CommandAdd( pAbc, "ABC9",         "&append",       Abc_CommandAbc9Append,       0 );
1162     Cmd_CommandAdd( pAbc, "ABC9",         "&scl",          Abc_CommandAbc9Scl,          0 );
1163     Cmd_CommandAdd( pAbc, "ABC9",         "&lcorr",        Abc_CommandAbc9Lcorr,        0 );
1164     Cmd_CommandAdd( pAbc, "ABC9",         "&scorr",        Abc_CommandAbc9Scorr,        0 );
1165     Cmd_CommandAdd( pAbc, "ABC9",         "&choice",       Abc_CommandAbc9Choice,       0 );
1166     Cmd_CommandAdd( pAbc, "ABC9",         "&sat",          Abc_CommandAbc9Sat,          0 );
1167     Cmd_CommandAdd( pAbc, "ABC9",         "&satenum",      Abc_CommandAbc9SatEnum,      0 );
1168     Cmd_CommandAdd( pAbc, "ABC9",         "&fraig",        Abc_CommandAbc9Fraig,        0 );
1169     Cmd_CommandAdd( pAbc, "ABC9",         "&cfraig",       Abc_CommandAbc9CFraig,       0 );
1170     Cmd_CommandAdd( pAbc, "ABC9",         "&srm",          Abc_CommandAbc9Srm,          0 );
1171     Cmd_CommandAdd( pAbc, "ABC9",         "&srm2",         Abc_CommandAbc9Srm2,         0 );
1172     Cmd_CommandAdd( pAbc, "ABC9",         "&filter",       Abc_CommandAbc9Filter,       0 );
1173     Cmd_CommandAdd( pAbc, "ABC9",         "&reduce",       Abc_CommandAbc9Reduce,       0 );
1174     Cmd_CommandAdd( pAbc, "ABC9",         "&equiv_mark",   Abc_CommandAbc9EquivMark,    0 );
1175     Cmd_CommandAdd( pAbc, "ABC9",         "&equiv_filter", Abc_CommandAbc9EquivFilter,  0 );
1176     Cmd_CommandAdd( pAbc, "ABC9",         "&cec",          Abc_CommandAbc9Cec,          0 );
1177     Cmd_CommandAdd( pAbc, "ABC9",         "&verify",       Abc_CommandAbc9Verify,       0 );
1178     Cmd_CommandAdd( pAbc, "ABC9",         "&sweep",        Abc_CommandAbc9Sweep,        0 );
1179     Cmd_CommandAdd( pAbc, "ABC9",         "&force",        Abc_CommandAbc9Force,        0 );
1180     Cmd_CommandAdd( pAbc, "ABC9",         "&embed",        Abc_CommandAbc9Embed,        0 );
1181     Cmd_CommandAdd( pAbc, "ABC9",         "&sopb",         Abc_CommandAbc9Sopb,         0 );
1182     Cmd_CommandAdd( pAbc, "ABC9",         "&dsdb",         Abc_CommandAbc9Dsdb,         0 );
1183     Cmd_CommandAdd( pAbc, "ABC9",         "&flow",         Abc_CommandAbc9Flow,         0 );
1184     Cmd_CommandAdd( pAbc, "ABC9",         "&flow2",        Abc_CommandAbc9Flow2,        0 );
1185     Cmd_CommandAdd( pAbc, "ABC9",         "&flow3",        Abc_CommandAbc9Flow3,        0 );
1186     Cmd_CommandAdd( pAbc, "ABC9",         "&if",           Abc_CommandAbc9If,           0 );
1187     Cmd_CommandAdd( pAbc, "ABC9",         "&iff",          Abc_CommandAbc9Iff,          0 );
1188     Cmd_CommandAdd( pAbc, "ABC9",         "&iiff",         Abc_CommandAbc9Iiff,         0 );
1189     Cmd_CommandAdd( pAbc, "ABC9",         "&if2",          Abc_CommandAbc9If2,          0 );
1190     Cmd_CommandAdd( pAbc, "ABC9",         "&jf",           Abc_CommandAbc9Jf,           0 );
1191     Cmd_CommandAdd( pAbc, "ABC9",         "&kf",           Abc_CommandAbc9Kf,           0 );
1192     Cmd_CommandAdd( pAbc, "ABC9",         "&lf",           Abc_CommandAbc9Lf,           0 );
1193     Cmd_CommandAdd( pAbc, "ABC9",         "&mf",           Abc_CommandAbc9Mf,           0 );
1194     Cmd_CommandAdd( pAbc, "ABC9",         "&nf",           Abc_CommandAbc9Nf,           0 );
1195     Cmd_CommandAdd( pAbc, "ABC9",         "&of",           Abc_CommandAbc9Of,           0 );
1196     Cmd_CommandAdd( pAbc, "ABC9",         "&pack",         Abc_CommandAbc9Pack,         0 );
1197     Cmd_CommandAdd( pAbc, "ABC9",         "&edge",         Abc_CommandAbc9Edge,         0 );
1198     Cmd_CommandAdd( pAbc, "ABC9",         "&satlut",       Abc_CommandAbc9SatLut,       0 );
1199     Cmd_CommandAdd( pAbc, "ABC9",         "&unmap",        Abc_CommandAbc9Unmap,        0 );
1200     Cmd_CommandAdd( pAbc, "ABC9",         "&struct",       Abc_CommandAbc9Struct,       0 );
1201     Cmd_CommandAdd( pAbc, "ABC9",         "&trace",        Abc_CommandAbc9Trace,        0 );
1202     Cmd_CommandAdd( pAbc, "ABC9",         "&speedup",      Abc_CommandAbc9Speedup,      0 );
1203     Cmd_CommandAdd( pAbc, "ABC9",         "&era",          Abc_CommandAbc9Era,          0 );
1204     Cmd_CommandAdd( pAbc, "ABC9",         "&dch",          Abc_CommandAbc9Dch,          0 );
1205     Cmd_CommandAdd( pAbc, "ABC9",         "&rpm",          Abc_CommandAbc9Rpm,          0 );
1206     Cmd_CommandAdd( pAbc, "ABC9",         "&back_reach",   Abc_CommandAbc9BackReach,    0 );
1207     Cmd_CommandAdd( pAbc, "ABC9",         "&posplit",      Abc_CommandAbc9Posplit,      0 );
1208     Cmd_CommandAdd( pAbc, "ABC9",         "&permute",      Abc_CommandAbc9Permute,      0 );
1209 #ifdef ABC_USE_CUDD
1210     Cmd_CommandAdd( pAbc, "ABC9",         "&reachm",       Abc_CommandAbc9ReachM,       0 );
1211     Cmd_CommandAdd( pAbc, "ABC9",         "&reachp",       Abc_CommandAbc9ReachP,       0 );
1212     Cmd_CommandAdd( pAbc, "ABC9",         "&reachn",       Abc_CommandAbc9ReachN,       0 );
1213     Cmd_CommandAdd( pAbc, "ABC9",         "&reachy",       Abc_CommandAbc9ReachY,       0 );
1214 #endif
1215     Cmd_CommandAdd( pAbc, "ABC9",         "&undo",         Abc_CommandAbc9Undo,         0 );
1216     Cmd_CommandAdd( pAbc, "ABC9",         "&mesh",         Abc_CommandAbc9Mesh,         0 );
1217     Cmd_CommandAdd( pAbc, "ABC9",         "&iso",          Abc_CommandAbc9Iso,          0 );
1218     Cmd_CommandAdd( pAbc, "ABC9",         "&isonpn",       Abc_CommandAbc9IsoNpn,       0 );
1219     Cmd_CommandAdd( pAbc, "ABC9",         "&isost",        Abc_CommandAbc9IsoSt,        0 );
1220     Cmd_CommandAdd( pAbc, "ABC9",         "&cexinfo",      Abc_CommandAbc9CexInfo,      0 );
1221     Cmd_CommandAdd( pAbc, "ABC9",         "&cycle",        Abc_CommandAbc9Cycle,        0 );
1222     Cmd_CommandAdd( pAbc, "ABC9",         "&cone",         Abc_CommandAbc9Cone,         0 );
1223     Cmd_CommandAdd( pAbc, "ABC9",         "&slice",        Abc_CommandAbc9Slice,        0 );
1224     Cmd_CommandAdd( pAbc, "ABC9",         "&popart",       Abc_CommandAbc9PoPart,       0 );
1225     Cmd_CommandAdd( pAbc, "ABC9",         "&gprove",       Abc_CommandAbc9GroupProve,   0 );
1226     Cmd_CommandAdd( pAbc, "ABC9",         "&mprove",       Abc_CommandAbc9MultiProve,   0 );
1227     Cmd_CommandAdd( pAbc, "ABC9",         "&splitprove",   Abc_CommandAbc9SplitProve,   0 );
1228     Cmd_CommandAdd( pAbc, "ABC9",         "&bmc",          Abc_CommandAbc9Bmc,          0 );
1229     Cmd_CommandAdd( pAbc, "ABC9",         "&bmcs",         Abc_CommandAbc9SBmc,         0 );
1230     Cmd_CommandAdd( pAbc, "ABC9",         "&chainbmc",     Abc_CommandAbc9ChainBmc,     0 );
1231     Cmd_CommandAdd( pAbc, "ABC9",         "&bcore",        Abc_CommandAbc9BCore,        0 );
1232     Cmd_CommandAdd( pAbc, "ABC9",         "&icheck",       Abc_CommandAbc9ICheck,       0 );
1233     Cmd_CommandAdd( pAbc, "ABC9",         "&sattest",      Abc_CommandAbc9SatTest,      0 );
1234     Cmd_CommandAdd( pAbc, "ABC9",         "&fftest",       Abc_CommandAbc9FFTest,       0 );
1235     Cmd_CommandAdd( pAbc, "ABC9",         "&qbf",          Abc_CommandAbc9Qbf,          0 );
1236     Cmd_CommandAdd( pAbc, "ABC9",         "&qvar",         Abc_CommandAbc9QVar,         0 );
1237     Cmd_CommandAdd( pAbc, "ABC9",         "&genqbf",       Abc_CommandAbc9GenQbf,       0 );
1238     Cmd_CommandAdd( pAbc, "ABC9",         "&satfx",        Abc_CommandAbc9SatFx,        0 );
1239     Cmd_CommandAdd( pAbc, "ABC9",         "&satclp",       Abc_CommandAbc9SatClp,       0 );
1240     Cmd_CommandAdd( pAbc, "ABC9",         "&inse",         Abc_CommandAbc9Inse,         0 );
1241     Cmd_CommandAdd( pAbc, "ABC9",         "&maxi",         Abc_CommandAbc9Maxi,         0 );
1242     Cmd_CommandAdd( pAbc, "ABC9",         "&bmci",         Abc_CommandAbc9Bmci,         0 );
1243     Cmd_CommandAdd( pAbc, "ABC9",         "&poxsim",       Abc_CommandAbc9PoXsim,       0 );
1244     Cmd_CommandAdd( pAbc, "ABC9",         "&demiter",      Abc_CommandAbc9Demiter,      0 );
1245     Cmd_CommandAdd( pAbc, "ABC9",         "&fadds",        Abc_CommandAbc9Fadds,        0 );
1246     Cmd_CommandAdd( pAbc, "ABC9",         "&atree",        Abc_CommandAbc9ATree,        0 );
1247     Cmd_CommandAdd( pAbc, "ABC9",         "&polyn",        Abc_CommandAbc9Polyn,        0 );
1248     Cmd_CommandAdd( pAbc, "ABC9",         "&acec",         Abc_CommandAbc9Acec,         0 );
1249     Cmd_CommandAdd( pAbc, "ABC9",         "&anorm",        Abc_CommandAbc9Anorm,        0 );
1250     Cmd_CommandAdd( pAbc, "ABC9",         "&decla",        Abc_CommandAbc9Decla,        0 );
1251     Cmd_CommandAdd( pAbc, "ABC9",         "&esop",         Abc_CommandAbc9Esop,         0 );
1252     Cmd_CommandAdd( pAbc, "ABC9",         "&exorcism",     Abc_CommandAbc9Exorcism,     0 );
1253     Cmd_CommandAdd( pAbc, "ABC9",         "&mfs",          Abc_CommandAbc9Mfs,          0 );
1254     Cmd_CommandAdd( pAbc, "ABC9",         "&mfsd",         Abc_CommandAbc9Mfsd,         0 );
1255     Cmd_CommandAdd( pAbc, "ABC9",         "&deepsyn",      Abc_CommandAbc9DeepSyn,      0 );
1256 //    Cmd_CommandAdd( pAbc, "ABC9",         "&popart2",      Abc_CommandAbc9PoPart2,      0 );
1257 //    Cmd_CommandAdd( pAbc, "ABC9",         "&cexcut",       Abc_CommandAbc9CexCut,       0 );
1258 //    Cmd_CommandAdd( pAbc, "ABC9",         "&cexmerge",     Abc_CommandAbc9CexMerge,     0 );
1259 //    Cmd_CommandAdd( pAbc, "ABC9",         "&cexmin",       Abc_CommandAbc9CexMin,       0 );
1260 
1261     Cmd_CommandAdd( pAbc, "Abstraction",  "&abs_create",   Abc_CommandAbc9AbsCreate,    0 );
1262     Cmd_CommandAdd( pAbc, "Abstraction",  "&abs_derive",   Abc_CommandAbc9AbsDerive,    0 );
1263     Cmd_CommandAdd( pAbc, "Abstraction",  "&abs_refine",   Abc_CommandAbc9AbsRefine,    0 );
1264     Cmd_CommandAdd( pAbc, "Abstraction",  "&gla_derive",   Abc_CommandAbc9GlaDerive,    0 );
1265     Cmd_CommandAdd( pAbc, "Abstraction",  "&gla_refine",   Abc_CommandAbc9GlaRefine,    0 );
1266     Cmd_CommandAdd( pAbc, "Abstraction",  "&gla_shrink",   Abc_CommandAbc9GlaShrink,    0 );
1267     Cmd_CommandAdd( pAbc, "Abstraction",  "&gla",          Abc_CommandAbc9Gla,          0 );
1268     Cmd_CommandAdd( pAbc, "Abstraction",  "&vta",          Abc_CommandAbc9Vta,          0 );
1269     Cmd_CommandAdd( pAbc, "Abstraction",  "&vta_gla",      Abc_CommandAbc9Vta2Gla,      0 );
1270     Cmd_CommandAdd( pAbc, "Abstraction",  "&gla_vta",      Abc_CommandAbc9Gla2Vta,      0 );
1271     Cmd_CommandAdd( pAbc, "Abstraction",  "&fla_gla",      Abc_CommandAbc9Fla2Gla,      0 );
1272     Cmd_CommandAdd( pAbc, "Abstraction",  "&gla_fla",      Abc_CommandAbc9Gla2Fla,      0 );
1273 
1274     Cmd_CommandAdd( pAbc, "Liveness",     "l2s",           Abc_CommandAbcLivenessToSafety,        0 );
1275     Cmd_CommandAdd( pAbc, "Liveness",     "l2ssim",        Abc_CommandAbcLivenessToSafetySim,     0 );
1276     Cmd_CommandAdd( pAbc, "Liveness",     "l3s",           Abc_CommandAbcLivenessToSafetyWithLTL, 0 );
1277     Cmd_CommandAdd( pAbc, "Liveness",     "kcs",           Abc_CommandCS_kLiveness,               0 );
1278     Cmd_CommandAdd( pAbc, "Liveness",     "nck",           Abc_CommandNChooseK,                   0 );
1279 
1280     Cmd_CommandAdd( pAbc, "ABC9",         "&gen",          Abc_CommandAbc9Gen,                    0 );
1281     Cmd_CommandAdd( pAbc, "ABC9",         "&cfs",          Abc_CommandAbc9Cfs,                    0 );
1282 
1283     Cmd_CommandAdd( pAbc, "ABC9",         "&test",         Abc_CommandAbc9Test,         0 );
1284     {
1285 //        extern Mf_ManTruthCount();
1286 //        Mf_ManTruthCount();
1287     }
1288 
1289     {
1290         extern void Dar_LibStart();
1291         Dar_LibStart();
1292     }
1293     {
1294 //        extern void Dau_DsdTest();
1295 //        Dau_DsdTest();
1296 //        extern void If_ManSatTest();
1297 //        If_ManSatTest();
1298     }
1299 
1300 //    if ( Sdm_ManCanRead() )
1301 //        Sdm_ManRead();
1302 }
1303 
1304 /**Function*************************************************************
1305 
1306   Synopsis    []
1307 
1308   Description []
1309 
1310   SideEffects []
1311 
1312   SeeAlso     []
1313 
1314 ***********************************************************************/
Abc_End(Abc_Frame_t * pAbc)1315 void Abc_End( Abc_Frame_t * pAbc )
1316 {
1317     extern Abc_Frame_t * Abc_FrameGetGlobalFrame();
1318     Abc_FrameClearDesign();
1319     Cnf_ManFree();
1320     {
1321         extern int Abc_NtkCompareAndSaveBest( Abc_Ntk_t * pNtk );
1322         Abc_NtkCompareAndSaveBest( NULL );
1323     }
1324     {
1325         extern void Dar_LibStop();
1326         Dar_LibStop();
1327     }
1328     {
1329         extern void Aig_RManQuit();
1330         Aig_RManQuit();
1331     }
1332     {
1333         extern void Npn_ManClean();
1334         Npn_ManClean();
1335     }
1336     {
1337         extern void Sdm_ManQuit();
1338         Sdm_ManQuit();
1339     }
1340     Abc_NtkFraigStoreClean();
1341     Gia_ManStopP( &pAbc->pGia );
1342     Gia_ManStopP( &pAbc->pGia2 );
1343     Gia_ManStopP( &pAbc->pGiaBest );
1344     Gia_ManStopP( &pAbc->pGiaBest2 );
1345     Gia_ManStopP( &pAbc->pGiaSaved );
1346     if ( Abc_NtkRecIsRunning3() )
1347         Abc_NtkRecStop3();
1348 }
1349 
1350 /**Function*************************************************************
1351 
1352   Synopsis    []
1353 
1354   Description []
1355 
1356   SideEffects []
1357 
1358   SeeAlso     []
1359 
1360 ***********************************************************************/
Abc_CommandPrintStats(Abc_Frame_t * pAbc,int argc,char ** argv)1361 int Abc_CommandPrintStats( Abc_Frame_t * pAbc, int argc, char ** argv )
1362 {
1363     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
1364     int fFactor;
1365     int fSaveBest;
1366     int fDumpResult;
1367     int fUseLutLib;
1368     int fPrintTime;
1369     int fPrintMuxes;
1370     int fPower;
1371     int fGlitch;
1372     int fSkipBuf;
1373     int fSkipSmall;
1374     int fPrintMem;
1375     int c;
1376 
1377     pNtk = Abc_FrameReadNtk(pAbc);
1378 
1379     // set the defaults
1380     fFactor   = 0;
1381     fSaveBest = 0;
1382     fDumpResult = 0;
1383     fUseLutLib = 0;
1384     fPrintTime = 0;
1385     fPrintMuxes = 0;
1386     fPower = 0;
1387     fGlitch = 0;
1388     fSkipBuf = 0;
1389     fSkipSmall = 0;
1390     fPrintMem = 0;
1391     Extra_UtilGetoptReset();
1392     while ( ( c = Extra_UtilGetopt( argc, argv, "fbdltmpgscuh" ) ) != EOF )
1393     {
1394         switch ( c )
1395         {
1396         case 'f':
1397             fFactor ^= 1;
1398             break;
1399         case 'b':
1400             fSaveBest ^= 1;
1401             break;
1402         case 'd':
1403             fDumpResult ^= 1;
1404             break;
1405         case 'l':
1406             fUseLutLib ^= 1;
1407             break;
1408         case 't':
1409             fPrintTime ^= 1;
1410             break;
1411         case 'm':
1412             fPrintMuxes ^= 1;
1413             break;
1414         case 'p':
1415             fPower ^= 1;
1416             break;
1417         case 'g':
1418             fGlitch ^= 1;
1419             break;
1420         case 's':
1421             fSkipBuf ^= 1;
1422             break;
1423         case 'c':
1424             fSkipSmall ^= 1;
1425             break;
1426         case 'u':
1427             fPrintMem ^= 1;
1428             break;
1429         case 'h':
1430             goto usage;
1431         default:
1432             goto usage;
1433         }
1434     }
1435 
1436     if ( pNtk == NULL )
1437     {
1438         Abc_Print( -1, "Empty network.\n" );
1439         return 1;
1440     }
1441     if ( !Abc_NtkIsLogic(pNtk) && fUseLutLib )
1442     {
1443         Abc_Print( -1, "Cannot print LUT delay for a non-logic network.\n" );
1444         return 1;
1445     }
1446     Abc_NtkPrintStats( pNtk, fFactor, fSaveBest, fDumpResult, fUseLutLib, fPrintMuxes, fPower, fGlitch, fSkipBuf, fSkipSmall, fPrintMem );
1447     if ( fPrintTime )
1448     {
1449         pAbc->TimeTotal += pAbc->TimeCommand;
1450         Abc_Print( 1, "elapse: %3.2f seconds, total: %3.2f seconds\n", pAbc->TimeCommand, pAbc->TimeTotal );
1451         pAbc->TimeCommand = 0.0;
1452     }
1453     return 0;
1454 
1455 usage:
1456     Abc_Print( -2, "usage: print_stats [-fbdltmpgscuh]\n" );
1457     Abc_Print( -2, "\t        prints the network statistics\n" );
1458     Abc_Print( -2, "\t-f    : toggles printing the literal count in the factored forms [default = %s]\n", fFactor? "yes": "no" );
1459     Abc_Print( -2, "\t-b    : toggles saving the best logic network in \"best.blif\" [default = %s]\n", fSaveBest? "yes": "no" );
1460     Abc_Print( -2, "\t-d    : toggles dumping statistics about the network into file [default = %s]\n", fDumpResult? "yes": "no" );
1461     Abc_Print( -2, "\t-l    : toggles printing delay of LUT mapping using LUT library [default = %s]\n", fSaveBest? "yes": "no" );
1462     Abc_Print( -2, "\t-t    : toggles printing runtime statistics [default = %s]\n", fPrintTime? "yes": "no" );
1463     Abc_Print( -2, "\t-m    : toggles printing MUX statistics [default = %s]\n", fPrintMuxes? "yes": "no" );
1464     Abc_Print( -2, "\t-p    : toggles printing power dissipation due to switching [default = %s]\n", fPower? "yes": "no" );
1465     Abc_Print( -2, "\t-g    : toggles printing percentage of increased power due to glitching [default = %s]\n", fGlitch? "yes": "no" );
1466     Abc_Print( -2, "\t-s    : toggles not counting single-output nodes as nodes [default = %s]\n", fSkipBuf? "yes": "no" );
1467     Abc_Print( -2, "\t-c    : toggles not counting constants and single-output nodes as nodes [default = %s]\n", fSkipSmall? "yes": "no" );
1468     Abc_Print( -2, "\t-u    : toggles printing memory usage [default = %s]\n", fPrintMem? "yes": "no" );
1469     Abc_Print( -2, "\t-h    : print the command usage\n");
1470     return 1;
1471 }
1472 
1473 /**Function*************************************************************
1474 
1475   Synopsis    []
1476 
1477   Description []
1478 
1479   SideEffects []
1480 
1481   SeeAlso     []
1482 
1483 ***********************************************************************/
Abc_CommandPrintExdc(Abc_Frame_t * pAbc,int argc,char ** argv)1484 int Abc_CommandPrintExdc( Abc_Frame_t * pAbc, int argc, char ** argv )
1485 {
1486     Abc_Ntk_t * pNtk, * pNtkTemp;
1487     double Percentage;
1488     int fShort;
1489     int c;
1490     int fPrintDc;
1491     extern double Abc_NtkSpacePercentage( Abc_Obj_t * pNode );
1492     pNtk = Abc_FrameReadNtk(pAbc);
1493 
1494     // set the defaults
1495     fShort  = 1;
1496     fPrintDc = 0;
1497     Extra_UtilGetoptReset();
1498     while ( ( c = Extra_UtilGetopt( argc, argv, "sdh" ) ) != EOF )
1499     {
1500         switch ( c )
1501         {
1502         case 's':
1503             fShort ^= 1;
1504             break;
1505         case 'd':
1506             fPrintDc ^= 1;
1507             break;
1508         case 'h':
1509             goto usage;
1510         default:
1511             goto usage;
1512         }
1513     }
1514 
1515     if ( pNtk == NULL )
1516     {
1517         Abc_Print( -1, "Empty network.\n" );
1518         return 1;
1519     }
1520     if ( pNtk->pExdc == NULL )
1521     {
1522         Abc_Print( -1, "Network has no EXDC.\n" );
1523         return 1;
1524     }
1525 
1526     if ( fPrintDc )
1527     {
1528         if ( !Abc_NtkIsStrash(pNtk->pExdc) )
1529         {
1530             pNtkTemp = Abc_NtkStrash(pNtk->pExdc, 0, 0, 0);
1531             Percentage = Abc_NtkSpacePercentage( Abc_ObjChild0( Abc_NtkPo(pNtkTemp, 0) ) );
1532             Abc_NtkDelete( pNtkTemp );
1533         }
1534         else
1535             Percentage = Abc_NtkSpacePercentage( Abc_ObjChild0( Abc_NtkPo(pNtk->pExdc, 0) ) );
1536 
1537         Abc_Print( 1, "EXDC network statistics: " );
1538         Abc_Print( 1, "(" );
1539         if ( Percentage > 0.05 && Percentage < 99.95 )
1540             Abc_Print( 1, "%.2f", Percentage );
1541         else if ( Percentage > 0.000005 && Percentage < 99.999995 )
1542             Abc_Print( 1, "%.6f", Percentage );
1543         else
1544             Abc_Print( 1, "%f", Percentage );
1545         Abc_Print( 1, " %% don't-cares)\n" );
1546     }
1547     else
1548         Abc_Print( 1, "EXDC network statistics: \n" );
1549     Abc_NtkPrintStats( pNtk->pExdc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
1550     return 0;
1551 
1552 usage:
1553     Abc_Print( -2, "usage: print_exdc [-dh]\n" );
1554     Abc_Print( -2, "\t        prints the EXDC network statistics\n" );
1555     Abc_Print( -2, "\t-d    : toggles printing don't-care percentage [default = %s]\n", fPrintDc? "yes": "no" );
1556     Abc_Print( -2, "\t-h    : print the command usage\n");
1557     return 1;
1558 }
1559 
1560 /**Function*************************************************************
1561 
1562   Synopsis    []
1563 
1564   Description []
1565 
1566   SideEffects []
1567 
1568   SeeAlso     []
1569 
1570 ***********************************************************************/
Abc_CommandPrintIo(Abc_Frame_t * pAbc,int argc,char ** argv)1571 int Abc_CommandPrintIo( Abc_Frame_t * pAbc, int argc, char ** argv )
1572 {
1573     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
1574     Abc_Obj_t * pNode;
1575     int c, fPrintFlops = 1;
1576 
1577     // set defaults
1578     Extra_UtilGetoptReset();
1579     while ( ( c = Extra_UtilGetopt( argc, argv, "fh" ) ) != EOF )
1580     {
1581         switch ( c )
1582         {
1583         case 'f':
1584             fPrintFlops ^= 1;
1585             break;
1586         case 'h':
1587             goto usage;
1588         default:
1589             goto usage;
1590         }
1591     }
1592 
1593     if ( pNtk == NULL )
1594     {
1595         Abc_Print( -1, "Empty network.\n" );
1596         return 1;
1597     }
1598 
1599     if ( argc > globalUtilOptind + 1 )
1600     {
1601         Abc_Print( -1, "Wrong number of auguments.\n" );
1602         goto usage;
1603     }
1604 
1605     if ( argc == globalUtilOptind + 1 )
1606     {
1607         pNode = Abc_NtkFindNode( pNtk, argv[globalUtilOptind] );
1608         if ( pNode == NULL )
1609         {
1610             Abc_Print( -1, "Cannot find node \"%s\".\n", argv[globalUtilOptind] );
1611             return 1;
1612         }
1613         Abc_NodePrintFanio( stdout, pNode );
1614         return 0;
1615     }
1616     // print the nodes
1617     Abc_NtkPrintIo( stdout, pNtk, fPrintFlops );
1618     return 0;
1619 
1620 usage:
1621     Abc_Print( -2, "usage: print_io [-fh] <node>\n" );
1622     Abc_Print( -2, "\t        prints the PIs/POs/flops or fanins/fanouts of a node\n" );
1623     Abc_Print( -2, "\t-f    : toggles printing flops [default = %s]\n", fPrintFlops? "yes": "no" );
1624     Abc_Print( -2, "\t-h    : print the command usage\n");
1625     Abc_Print( -2, "\tnode  : the node to print fanins/fanouts\n");
1626     return 1;
1627 }
1628 
1629 /**Function*************************************************************
1630 
1631   Synopsis    []
1632 
1633   Description []
1634 
1635   SideEffects []
1636 
1637   SeeAlso     []
1638 
1639 ***********************************************************************/
Abc_CommandPrintLatch(Abc_Frame_t * pAbc,int argc,char ** argv)1640 int Abc_CommandPrintLatch( Abc_Frame_t * pAbc, int argc, char ** argv )
1641 {
1642     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
1643     int c;
1644     int fPrintSccs;
1645     extern void Abc_NtkPrintSccs( Abc_Ntk_t * pNtk, int fVerbose );
1646 
1647     // set defaults
1648     fPrintSccs = 0;
1649     Extra_UtilGetoptReset();
1650     while ( ( c = Extra_UtilGetopt( argc, argv, "sh" ) ) != EOF )
1651     {
1652         switch ( c )
1653         {
1654         case 's':
1655             fPrintSccs ^= 1;
1656             break;
1657         case 'h':
1658             goto usage;
1659         default:
1660             goto usage;
1661         }
1662     }
1663 
1664     if ( pNtk == NULL )
1665     {
1666         Abc_Print( -1, "Empty network.\n" );
1667         return 1;
1668     }
1669     // print the nodes
1670     Abc_NtkPrintLatch( stdout, pNtk );
1671     if ( fPrintSccs )
1672         Abc_NtkPrintSccs( pNtk, 0 );
1673     return 0;
1674 
1675 usage:
1676     Abc_Print( -2, "usage: print_latch [-sh]\n" );
1677     Abc_Print( -2, "\t        prints information about latches\n" );
1678     Abc_Print( -2, "\t-s    : toggles printing SCCs of registers [default = %s]\n", fPrintSccs? "yes": "no" );
1679     Abc_Print( -2, "\t-h    : print the command usage\n");
1680     return 1;
1681 }
1682 
1683 /**Function*************************************************************
1684 
1685   Synopsis    []
1686 
1687   Description []
1688 
1689   SideEffects []
1690 
1691   SeeAlso     []
1692 
1693 ***********************************************************************/
Abc_CommandPrintFanio(Abc_Frame_t * pAbc,int argc,char ** argv)1694 int Abc_CommandPrintFanio( Abc_Frame_t * pAbc, int argc, char ** argv )
1695 {
1696     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
1697     int c;
1698     int fUseFanio = 0;
1699     int fUsePio   = 0;
1700     int fUseSupp  = 0;
1701     int fUseCone  = 0;
1702     int fMffc     = 0;
1703     int fVerbose  = 0;
1704     Extra_UtilGetoptReset();
1705     while ( ( c = Extra_UtilGetopt( argc, argv, "fiscmvh" ) ) != EOF )
1706     {
1707         switch ( c )
1708         {
1709         case 'f':
1710             fUseFanio ^= 1;
1711             break;
1712         case 'i':
1713             fUsePio ^= 1;
1714             break;
1715         case 's':
1716             fUseSupp ^= 1;
1717             break;
1718         case 'c':
1719             fUseCone ^= 1;
1720             break;
1721         case 'm':
1722             fMffc ^= 1;
1723             break;
1724         case 'v':
1725             fVerbose ^= 1;
1726             break;
1727         case 'h':
1728             goto usage;
1729         default:
1730             goto usage;
1731         }
1732     }
1733     if ( pNtk == NULL )
1734     {
1735         Abc_Print( -1, "Empty network.\n" );
1736         return 1;
1737     }
1738     // print the nodes
1739     if ( fMffc || !fVerbose )
1740         Abc_NtkPrintFanioNew( stdout, pNtk, fMffc );
1741     else
1742     {
1743         if ( fUseFanio + fUsePio + fUseSupp + fUseCone == 1 )
1744             Abc_NtkPrintFanio( stdout, pNtk, fUseFanio, fUsePio, fUseSupp, fUseCone );
1745         else
1746             printf( "Exactly one of the switches \"-f\", \"-i\", \"-s\", \"-c\" should be enabled.\n" );
1747     }
1748     return 0;
1749 
1750 usage:
1751     Abc_Print( -2, "usage: print_fanio [-fiscmvh]\n" );
1752     Abc_Print( -2, "\t        prints the statistics about different objects in the network\n" );
1753     Abc_Print( -2, "\t-f    : toggles considering fanins/fanouts of all nodes [default = %s]\n", fUseFanio? "yes": "no" );
1754     Abc_Print( -2, "\t-i    : toggles considering fanins/fanouts of CI/CO [default = %s]\n", fUsePio? "yes": "no" );
1755     Abc_Print( -2, "\t-s    : toggles considering TFO/TFI support sizes of CI/CO [default = %s]\n", fUseSupp? "yes": "no" );
1756     Abc_Print( -2, "\t-c    : toggles considering TFO/TFI cone sizes of CI/CO [default = %s]\n", fUseCone? "yes": "no" );
1757     Abc_Print( -2, "\t-m    : toggles printing MFFC sizes instead of fanouts [default = %s]\n", fMffc? "yes": "no" );
1758     Abc_Print( -2, "\t-v    : toggles verbose way of printing the stats [default = %s]\n", fVerbose? "yes": "no" );
1759     Abc_Print( -2, "\t-h    : print the command usage\n");
1760     return 1;
1761 }
1762 
1763 /**Function*************************************************************
1764 
1765   Synopsis    []
1766 
1767   Description []
1768 
1769   SideEffects []
1770 
1771   SeeAlso     []
1772 
1773 ***********************************************************************/
Abc_CommandPrintMffc(Abc_Frame_t * pAbc,int argc,char ** argv)1774 int Abc_CommandPrintMffc( Abc_Frame_t * pAbc, int argc, char ** argv )
1775 {
1776     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
1777     int c;
1778     extern void Abc_NtkPrintMffc( FILE * pFile, Abc_Ntk_t * pNtk );
1779 
1780     // set defaults
1781     Extra_UtilGetoptReset();
1782     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
1783     {
1784         switch ( c )
1785         {
1786         case 'h':
1787             goto usage;
1788         default:
1789             goto usage;
1790         }
1791     }
1792 
1793     if ( pNtk == NULL )
1794     {
1795         Abc_Print( -1, "Empty network.\n" );
1796         return 1;
1797     }
1798 
1799     // print the nodes
1800     Abc_NtkPrintMffc( stdout, pNtk );
1801     return 0;
1802 
1803 usage:
1804     Abc_Print( -2, "usage: print_mffc [-h]\n" );
1805     Abc_Print( -2, "\t        prints the MFFC of each node in the network\n" );
1806     Abc_Print( -2, "\t-h    : print the command usage\n");
1807     return 1;
1808 }
1809 
1810 /**Function*************************************************************
1811 
1812   Synopsis    []
1813 
1814   Description []
1815 
1816   SideEffects []
1817 
1818   SeeAlso     []
1819 
1820 ***********************************************************************/
Abc_CommandPrintFactor(Abc_Frame_t * pAbc,int argc,char ** argv)1821 int Abc_CommandPrintFactor( Abc_Frame_t * pAbc, int argc, char ** argv )
1822 {
1823     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
1824     Abc_Obj_t * pNode;
1825     int c;
1826     int fUseRealNames;
1827 
1828     // set defaults
1829     fUseRealNames = 1;
1830     Extra_UtilGetoptReset();
1831     while ( ( c = Extra_UtilGetopt( argc, argv, "nh" ) ) != EOF )
1832     {
1833         switch ( c )
1834         {
1835         case 'n':
1836             fUseRealNames ^= 1;
1837             break;
1838         case 'h':
1839             goto usage;
1840         default:
1841             goto usage;
1842         }
1843     }
1844 
1845     if ( pNtk == NULL )
1846     {
1847         Abc_Print( -1, "Empty network.\n" );
1848         return 1;
1849     }
1850 
1851     if ( !Abc_NtkIsSopLogic(pNtk) )
1852     {
1853         Abc_Print( -1, "Printing factored forms can be done for SOP networks.\n" );
1854         return 1;
1855     }
1856 
1857     if ( argc > globalUtilOptind + 1 )
1858     {
1859         Abc_Print( -1, "Wrong number of auguments.\n" );
1860         goto usage;
1861     }
1862 
1863     if ( argc == globalUtilOptind + 1 )
1864     {
1865         pNode = Abc_NtkFindNode( pNtk, argv[globalUtilOptind] );
1866         if ( pNode == NULL )
1867         {
1868             Abc_Print( -1, "Cannot find node \"%s\".\n", argv[globalUtilOptind] );
1869             return 1;
1870         }
1871         Abc_NodePrintFactor( stdout, pNode, fUseRealNames );
1872         return 0;
1873     }
1874     // print the nodes
1875     Abc_NtkPrintFactor( stdout, pNtk, fUseRealNames );
1876     return 0;
1877 
1878 usage:
1879     Abc_Print( -2, "usage: print_factor [-nh] <node>\n" );
1880     Abc_Print( -2, "\t        prints the factored forms of nodes\n" );
1881     Abc_Print( -2, "\t-n    : toggles real/dummy fanin names [default = %s]\n", fUseRealNames? "real": "dummy" );
1882     Abc_Print( -2, "\t-h    : print the command usage\n");
1883     Abc_Print( -2, "\tnode  : (optional) one node to consider\n");
1884     return 1;
1885 }
1886 
1887 /**Function*************************************************************
1888 
1889   Synopsis    []
1890 
1891   Description []
1892 
1893   SideEffects []
1894 
1895   SeeAlso     []
1896 
1897 ***********************************************************************/
Abc_CommandPrintLevel(Abc_Frame_t * pAbc,int argc,char ** argv)1898 int Abc_CommandPrintLevel( Abc_Frame_t * pAbc, int argc, char ** argv )
1899 {
1900     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
1901     Abc_Obj_t * pNode;
1902     int c;
1903     int fListNodes;
1904     int fProfile;
1905     int fVerbose;
1906 
1907     // set defaults
1908     fListNodes = 0;
1909     fProfile   = 1;
1910     fVerbose   = 0;
1911     Extra_UtilGetoptReset();
1912     while ( ( c = Extra_UtilGetopt( argc, argv, "npvh" ) ) != EOF )
1913     {
1914         switch ( c )
1915         {
1916         case 'n':
1917             fListNodes ^= 1;
1918             break;
1919         case 'p':
1920             fProfile ^= 1;
1921             break;
1922         case 'v':
1923             fVerbose ^= 1;
1924             break;
1925         case 'h':
1926             goto usage;
1927         default:
1928             goto usage;
1929         }
1930     }
1931 
1932     if ( pNtk == NULL )
1933     {
1934         Abc_Print( -1, "Empty network.\n" );
1935         return 1;
1936     }
1937 
1938     if ( !fProfile && !Abc_NtkIsStrash(pNtk) )
1939     {
1940         Abc_Print( -1, "This command works only for AIGs (run \"strash\").\n" );
1941         return 1;
1942     }
1943 
1944     if ( argc > globalUtilOptind + 1 )
1945     {
1946         Abc_Print( -1, "Wrong number of auguments.\n" );
1947         goto usage;
1948     }
1949 
1950     if ( argc == globalUtilOptind + 1 )
1951     {
1952         pNode = Abc_NtkFindNode( pNtk, argv[globalUtilOptind] );
1953         if ( pNode == NULL )
1954         {
1955             Abc_Print( -1, "Cannot find node \"%s\".\n", argv[globalUtilOptind] );
1956             return 1;
1957         }
1958         Abc_NodePrintLevel( stdout, pNode );
1959         return 0;
1960     }
1961     // process all COs
1962     Abc_NtkPrintLevel( stdout, pNtk, fProfile, fListNodes, fVerbose );
1963     return 0;
1964 
1965 usage:
1966     Abc_Print( -2, "usage: print_level [-npvh] <node>\n" );
1967     Abc_Print( -2, "\t        prints information about node level and cone size\n" );
1968     Abc_Print( -2, "\t-n    : toggles printing nodes by levels [default = %s]\n", fListNodes? "yes": "no" );
1969     Abc_Print( -2, "\t-p    : toggles printing level profile [default = %s]\n", fProfile? "yes": "no" );
1970     Abc_Print( -2, "\t-v    : enable verbose output [default = %s].\n", fVerbose? "yes": "no" );
1971     Abc_Print( -2, "\t-h    : print the command usage\n");
1972     Abc_Print( -2, "\tnode  : (optional) one node to consider\n");
1973     return 1;
1974 }
1975 
1976 /**Function*************************************************************
1977 
1978   Synopsis    []
1979 
1980   Description []
1981 
1982   SideEffects []
1983 
1984   SeeAlso     []
1985 
1986 ***********************************************************************/
Abc_CommandPrintSupport(Abc_Frame_t * pAbc,int argc,char ** argv)1987 int Abc_CommandPrintSupport( Abc_Frame_t * pAbc, int argc, char ** argv )
1988 {
1989     Vec_Ptr_t * vSuppFun;
1990     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
1991     int c;
1992     int fStruct;
1993     int fVerbose;
1994     int fVeryVerbose;
1995     extern Vec_Ptr_t * Sim_ComputeFunSupp( Abc_Ntk_t * pNtk, int fVerbose );
1996     extern void Abc_NtkPrintStrSupports( Abc_Ntk_t * pNtk, int fMatrix );
1997 
1998     // set defaults
1999     fStruct = 1;
2000     fVerbose = 0;
2001     fVeryVerbose = 0;
2002     Extra_UtilGetoptReset();
2003     while ( ( c = Extra_UtilGetopt( argc, argv, "svwh" ) ) != EOF )
2004     {
2005         switch ( c )
2006         {
2007         case 's':
2008             fStruct ^= 1;
2009             break;
2010         case 'v':
2011             fVerbose ^= 1;
2012             break;
2013         case 'w':
2014             fVeryVerbose ^= 1;
2015             break;
2016         case 'h':
2017             goto usage;
2018         default:
2019             goto usage;
2020         }
2021     }
2022 
2023     if ( pNtk == NULL )
2024     {
2025         Abc_Print( -1, "Empty network.\n" );
2026         return 1;
2027     }
2028 
2029     // print support information
2030     if ( fStruct )
2031     {
2032         Abc_NtkPrintStrSupports( pNtk, fVeryVerbose );
2033         return 0;
2034     }
2035 
2036     if ( !Abc_NtkIsComb(pNtk) )
2037     {
2038         Abc_Print( -1, "This command works only for combinational networks (run \"comb\").\n" );
2039         return 1;
2040     }
2041     if ( !Abc_NtkIsStrash(pNtk) )
2042     {
2043         Abc_Print( -1, "This command works only for AIGs (run \"strash\").\n" );
2044         return 1;
2045     }
2046     vSuppFun = Sim_ComputeFunSupp( pNtk, fVerbose );
2047     ABC_FREE( vSuppFun->pArray[0] );
2048     Vec_PtrFree( vSuppFun );
2049     return 0;
2050 
2051 usage:
2052     Abc_Print( -2, "usage: print_supp [-svwh]\n" );
2053     Abc_Print( -2, "\t        prints the supports of the CO nodes\n" );
2054     Abc_Print( -2, "\t-s    : toggle printing structural support only [default = %s].\n", fStruct? "yes": "no" );
2055     Abc_Print( -2, "\t-v    : enable verbose output [default = %s].\n", fVerbose? "yes": "no" );
2056     Abc_Print( -2, "\t-w    : enable printing CI/CO dependency matrix [default = %s].\n", fVeryVerbose? "yes": "no" );
2057     Abc_Print( -2, "\t-h    : print the command usage\n");
2058     return 1;
2059 }
2060 
2061 /**Function*************************************************************
2062 
2063   Synopsis    []
2064 
2065   Description []
2066 
2067   SideEffects []
2068 
2069   SeeAlso     []
2070 
2071 ***********************************************************************/
Abc_CommandPrintMint(Abc_Frame_t * pAbc,int argc,char ** argv)2072 int Abc_CommandPrintMint( Abc_Frame_t * pAbc, int argc, char ** argv )
2073 {
2074     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
2075     Abc_Obj_t * pObj;
2076     int c;
2077     int fVerbose;
2078 
2079     // set defaults
2080     fVerbose = 0;
2081     Extra_UtilGetoptReset();
2082     while ( ( c = Extra_UtilGetopt( argc, argv, "svwh" ) ) != EOF )
2083     {
2084         switch ( c )
2085         {
2086         case 'v':
2087             fVerbose ^= 1;
2088             break;
2089         case 'h':
2090             goto usage;
2091         default:
2092             goto usage;
2093         }
2094     }
2095     if ( pNtk == NULL )
2096     {
2097         Abc_Print( -1, "Empty network.\n" );
2098         return 1;
2099     }
2100     if ( Abc_NtkIsStrash(pNtk) )
2101     {
2102         Abc_Print( -1, "This command works only for logic networks (run \"clp\").\n" );
2103         return 1;
2104     }
2105     if ( !Abc_NtkHasBdd(pNtk) )
2106     {
2107         Abc_Print( -1, "This command works only for logic networks with local functions represented by BDDs.\n" );
2108         return 1;
2109     }
2110     Abc_NtkForEachNode( pNtk, pObj, c )
2111         printf( "ObjId %3d : SuppSize = %5d   MintCount = %32.0f\n", c, Abc_ObjFaninNum(pObj),
2112             Cudd_CountMinterm((DdManager *)pNtk->pManFunc, (DdNode *)pObj->pData, Abc_ObjFaninNum(pObj)) );
2113     return 0;
2114 
2115 usage:
2116     Abc_Print( -2, "usage: print_mint [-svwh]\n" );
2117     Abc_Print( -2, "\t        prints the number of on-set minterms in the PO functions\n" );
2118     Abc_Print( -2, "\t-v    : enable verbose output [default = %s].\n", fVerbose? "yes": "no" );
2119     Abc_Print( -2, "\t-h    : print the command usage\n");
2120     return 1;
2121 }
2122 
2123 /**Function*************************************************************
2124 
2125   Synopsis    []
2126 
2127   Description []
2128 
2129   SideEffects []
2130 
2131   SeeAlso     []
2132 
2133 ***********************************************************************/
Abc_CommandPrintSymms(Abc_Frame_t * pAbc,int argc,char ** argv)2134 int Abc_CommandPrintSymms( Abc_Frame_t * pAbc, int argc, char ** argv )
2135 {
2136     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
2137     int c;
2138     int fUseBdds;
2139     int fNaive;
2140     int fReorder;
2141     int fVerbose;
2142     extern void Abc_NtkSymmetries( Abc_Ntk_t * pNtk, int fUseBdds, int fNaive, int fReorder, int fVerbose );
2143 
2144     // set defaults
2145     fUseBdds = 0;
2146     fNaive   = 0;
2147     fReorder = 1;
2148     fVerbose = 0;
2149     Extra_UtilGetoptReset();
2150     while ( ( c = Extra_UtilGetopt( argc, argv, "bnrvh" ) ) != EOF )
2151     {
2152         switch ( c )
2153         {
2154         case 'b':
2155             fUseBdds ^= 1;
2156             break;
2157         case 'n':
2158             fNaive ^= 1;
2159             break;
2160         case 'r':
2161             fReorder ^= 1;
2162             break;
2163         case 'v':
2164             fVerbose ^= 1;
2165             break;
2166         case 'h':
2167             goto usage;
2168         default:
2169             goto usage;
2170         }
2171     }
2172     if ( pNtk == NULL )
2173     {
2174         Abc_Print( -1, "Empty network.\n" );
2175         return 1;
2176     }
2177     if ( !Abc_NtkIsComb(pNtk) )
2178     {
2179         Abc_Print( -1, "This command works only for combinational networks (run \"comb\").\n" );
2180         return 1;
2181     }
2182     if ( Abc_NtkIsStrash(pNtk) )
2183         Abc_NtkSymmetries( pNtk, fUseBdds, fNaive, fReorder, fVerbose );
2184     else
2185     {
2186         pNtk = Abc_NtkStrash( pNtk, 0, 0, 0 );
2187         Abc_NtkSymmetries( pNtk, fUseBdds, fNaive, fReorder, fVerbose );
2188         Abc_NtkDelete( pNtk );
2189     }
2190     return 0;
2191 
2192 usage:
2193     Abc_Print( -2, "usage: print_symm [-bnrvh]\n" );
2194     Abc_Print( -2, "\t         computes symmetries of the PO functions\n" );
2195     Abc_Print( -2, "\t-b     : toggle BDD-based or SAT-based computations [default = %s].\n", fUseBdds? "BDD": "SAT" );
2196     Abc_Print( -2, "\t-n     : enable naive BDD-based computation [default = %s].\n", fNaive? "yes": "no" );
2197     Abc_Print( -2, "\t-r     : enable dynamic BDD variable reordering [default = %s].\n", fReorder? "yes": "no" );
2198     Abc_Print( -2, "\t-v     : enable verbose output [default = %s].\n", fVerbose? "yes": "no" );
2199     Abc_Print( -2, "\t-h     : print the command usage\n");
2200     return 1;
2201 }
2202 
2203 /**Function*************************************************************
2204 
2205   Synopsis    []
2206 
2207   Description []
2208 
2209   SideEffects []
2210 
2211   SeeAlso     []
2212 
2213 ***********************************************************************/
Abc_CommandPrintUnate(Abc_Frame_t * pAbc,int argc,char ** argv)2214 int Abc_CommandPrintUnate( Abc_Frame_t * pAbc, int argc, char ** argv )
2215 {
2216     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
2217     int c;
2218     int fUseBdds;
2219     int fUseNaive;
2220     int fVerbose;
2221     extern void Abc_NtkPrintUnate( Abc_Ntk_t * pNtk, int fUseBdds, int fUseNaive, int fVerbose );
2222 
2223     // set defaults
2224     fUseBdds  = 1;
2225     fUseNaive = 0;
2226     fVerbose  = 0;
2227     Extra_UtilGetoptReset();
2228     while ( ( c = Extra_UtilGetopt( argc, argv, "bnvh" ) ) != EOF )
2229     {
2230         switch ( c )
2231         {
2232         case 'b':
2233             fUseBdds ^= 1;
2234             break;
2235         case 'n':
2236             fUseNaive ^= 1;
2237             break;
2238         case 'v':
2239             fVerbose ^= 1;
2240             break;
2241         case 'h':
2242             goto usage;
2243         default:
2244             goto usage;
2245         }
2246     }
2247     if ( pNtk == NULL )
2248     {
2249         Abc_Print( -1, "Empty network.\n" );
2250         return 1;
2251     }
2252     if ( !Abc_NtkIsStrash(pNtk) )
2253     {
2254         Abc_Print( -1, "This command works only for AIGs (run \"strash\").\n" );
2255         return 1;
2256     }
2257     Abc_NtkPrintUnate( pNtk, fUseBdds, fUseNaive, fVerbose );
2258     return 0;
2259 
2260 usage:
2261     Abc_Print( -2, "usage: print_unate [-bnvh]\n" );
2262     Abc_Print( -2, "\t         computes unate variables of the PO functions\n" );
2263     Abc_Print( -2, "\t-b     : toggle BDD-based or SAT-based computations [default = %s].\n", fUseBdds? "BDD": "SAT" );
2264     Abc_Print( -2, "\t-n     : toggle naive BDD-based computation [default = %s].\n", fUseNaive? "yes": "no" );
2265     Abc_Print( -2, "\t-v     : enable verbose output [default = %s].\n", fVerbose? "yes": "no" );
2266     Abc_Print( -2, "\t-h     : print the command usage\n");
2267     return 1;
2268 }
2269 
2270 /**Function*************************************************************
2271 
2272   Synopsis    []
2273 
2274   Description []
2275 
2276   SideEffects []
2277 
2278   SeeAlso     []
2279 
2280 ***********************************************************************/
Abc_CommandPrintAuto(Abc_Frame_t * pAbc,int argc,char ** argv)2281 int Abc_CommandPrintAuto( Abc_Frame_t * pAbc, int argc, char ** argv )
2282 {
2283     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
2284     int c;
2285     int Output;
2286     int fNaive;
2287     int fVerbose;
2288     extern void Abc_NtkAutoPrint( Abc_Ntk_t * pNtk, int Output, int fNaive, int fVerbose );
2289 
2290     // set defaults
2291     Output   = -1;
2292     fNaive   = 0;
2293     fVerbose = 0;
2294     Extra_UtilGetoptReset();
2295     while ( ( c = Extra_UtilGetopt( argc, argv, "Onvh" ) ) != EOF )
2296     {
2297         switch ( c )
2298         {
2299         case 'O':
2300             if ( globalUtilOptind >= argc )
2301             {
2302                 Abc_Print( -1, "Command line switch \"-O\" should be followed by an integer.\n" );
2303                 goto usage;
2304             }
2305             Output = atoi(argv[globalUtilOptind]);
2306             globalUtilOptind++;
2307             if ( Output < 0 )
2308                 goto usage;
2309             break;
2310         case 'n':
2311             fNaive ^= 1;
2312             break;
2313         case 'v':
2314             fVerbose ^= 1;
2315             break;
2316         case 'h':
2317             goto usage;
2318         default:
2319             goto usage;
2320         }
2321     }
2322     if ( pNtk == NULL )
2323     {
2324         Abc_Print( -1, "Empty network.\n" );
2325         return 1;
2326     }
2327     if ( !Abc_NtkIsStrash(pNtk) )
2328     {
2329         Abc_Print( -1, "This command works only for AIGs (run \"strash\").\n" );
2330         return 1;
2331     }
2332 
2333 
2334     Abc_NtkAutoPrint( pNtk, Output, fNaive, fVerbose );
2335     return 0;
2336 
2337 usage:
2338     Abc_Print( -2, "usage: print_auto [-O <num>] [-nvh]\n" );
2339     Abc_Print( -2, "\t           computes autosymmetries of the PO functions\n" );
2340     Abc_Print( -2, "\t-O <num> : (optional) the 0-based number of the output [default = all]\n");
2341     Abc_Print( -2, "\t-n       : enable naive BDD-based computation [default = %s].\n", fNaive? "yes": "no" );
2342     Abc_Print( -2, "\t-v       : enable verbose output [default = %s].\n", fVerbose? "yes": "no" );
2343     Abc_Print( -2, "\t-h       : print the command usage\n");
2344     return 1;
2345 }
2346 
2347 /**Function*************************************************************
2348 
2349   Synopsis    []
2350 
2351   Description []
2352 
2353   SideEffects []
2354 
2355   SeeAlso     []
2356 
2357 ***********************************************************************/
Abc_CommandPrintKMap(Abc_Frame_t * pAbc,int argc,char ** argv)2358 int Abc_CommandPrintKMap( Abc_Frame_t * pAbc, int argc, char ** argv )
2359 {
2360     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
2361     Abc_Obj_t * pNode;
2362     int c;
2363     int fUseRealNames;
2364 
2365     extern void Abc_NodePrintKMap( Abc_Obj_t * pNode, int fUseRealNames );
2366 
2367     // set defaults
2368     fUseRealNames = 1;
2369     Extra_UtilGetoptReset();
2370     while ( ( c = Extra_UtilGetopt( argc, argv, "nh" ) ) != EOF )
2371     {
2372         switch ( c )
2373         {
2374         case 'n':
2375             fUseRealNames ^= 1;
2376             break;
2377         case 'h':
2378             goto usage;
2379         default:
2380             goto usage;
2381         }
2382     }
2383     if ( argc == globalUtilOptind + 2 )
2384     {
2385         Abc_NtkShow6VarFunc( argv[globalUtilOptind], argv[globalUtilOptind+1] );
2386         return 0;
2387     }
2388 
2389     if ( pNtk == NULL )
2390     {
2391         Abc_Print( -1, "Empty network.\n" );
2392         return 1;
2393     }
2394     if ( !Abc_NtkIsLogic(pNtk) )
2395     {
2396         Abc_Print( -1, "Visualization of Karnaugh maps works for logic networks.\n" );
2397         return 1;
2398     }
2399     if ( argc > globalUtilOptind + 1 )
2400     {
2401         Abc_Print( -1, "Wrong number of auguments.\n" );
2402         goto usage;
2403     }
2404     if ( argc == globalUtilOptind )
2405     {
2406         pNode = Abc_ObjFanin0( Abc_NtkPo(pNtk, 0) );
2407         if ( !Abc_ObjIsNode(pNode) )
2408         {
2409             Abc_Print( -1, "The driver \"%s\" of the first PO is not an internal node.\n", Abc_ObjName(pNode) );
2410             return 1;
2411         }
2412     }
2413     else
2414     {
2415         pNode = Abc_NtkFindNode( pNtk, argv[globalUtilOptind] );
2416         if ( pNode == NULL )
2417         {
2418             Abc_Print( -1, "Cannot find node \"%s\".\n", argv[globalUtilOptind] );
2419             return 1;
2420         }
2421     }
2422     Abc_NtkToBdd(pNtk);
2423     Abc_NodePrintKMap( pNode, fUseRealNames );
2424     return 0;
2425 
2426 usage:
2427     Abc_Print( -2, "usage: print_kmap [-nh] <node>\n" );
2428     Abc_Print( -2, "\t        shows the truth table of the node\n" );
2429     Abc_Print( -2, "\t-n    : toggles real/dummy fanin names [default = %s]\n", fUseRealNames? "real": "dummy" );
2430     Abc_Print( -2, "\t-h    : print the command usage\n");
2431     Abc_Print( -2, "\t<node>: the node to consider (default = the driver of the first PO)\n");
2432     return 1;
2433 }
2434 
2435 /**Function*************************************************************
2436 
2437   Synopsis    []
2438 
2439   Description []
2440 
2441   SideEffects []
2442 
2443   SeeAlso     []
2444 
2445 ***********************************************************************/
Abc_CommandPrintGates(Abc_Frame_t * pAbc,int argc,char ** argv)2446 int Abc_CommandPrintGates( Abc_Frame_t * pAbc, int argc, char ** argv )
2447 {
2448     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
2449     int c;
2450     int fUseLibrary;
2451     int fUpdateProfile;
2452 
2453     extern void Abc_NtkPrintGates( Abc_Ntk_t * pNtk, int fUseLibrary, int fUpdateProfile );
2454 
2455     // set defaults
2456     fUseLibrary = 1;
2457     fUpdateProfile = 0;
2458     Extra_UtilGetoptReset();
2459     while ( ( c = Extra_UtilGetopt( argc, argv, "luh" ) ) != EOF )
2460     {
2461         switch ( c )
2462         {
2463         case 'l':
2464             fUseLibrary ^= 1;
2465             break;
2466         case 'u':
2467             fUpdateProfile ^= 1;
2468             break;
2469         case 'h':
2470             goto usage;
2471         default:
2472             goto usage;
2473         }
2474     }
2475 
2476     if ( pNtk == NULL )
2477     {
2478         Abc_Print( -1, "Empty network.\n" );
2479         return 1;
2480     }
2481     if ( Abc_NtkHasAig(pNtk) )
2482     {
2483         Abc_Print( -1, "Printing gates does not work for AIGs and sequential AIGs.\n" );
2484         return 1;
2485     }
2486 
2487     Abc_NtkPrintGates( pNtk, fUseLibrary, fUpdateProfile );
2488     return 0;
2489 
2490 usage:
2491     Abc_Print( -2, "usage: print_gates [-luh]\n" );
2492     Abc_Print( -2, "\t        prints statistics about gates used in the network\n" );
2493     Abc_Print( -2, "\t-l    : used library gate names (if mapped) [default = %s]\n", fUseLibrary? "yes": "no" );
2494     Abc_Print( -2, "\t-u    : update profile before printing it[default = %s]\n", fUpdateProfile? "yes": "no" );
2495     Abc_Print( -2, "\t-h    : print the command usage\n");
2496     return 1;
2497 }
2498 
2499 /**Function*************************************************************
2500 
2501   Synopsis    []
2502 
2503   Description []
2504 
2505   SideEffects []
2506 
2507   SeeAlso     []
2508 
2509 ***********************************************************************/
Abc_CommandPrintSharing(Abc_Frame_t * pAbc,int argc,char ** argv)2510 int Abc_CommandPrintSharing( Abc_Frame_t * pAbc, int argc, char ** argv )
2511 {
2512     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
2513     int c;
2514     int fUseLibrary;
2515 
2516     extern void Abc_NtkPrintSharing( Abc_Ntk_t * pNtk );
2517 
2518     // set defaults
2519     fUseLibrary = 1;
2520     Extra_UtilGetoptReset();
2521     while ( ( c = Extra_UtilGetopt( argc, argv, "lh" ) ) != EOF )
2522     {
2523         switch ( c )
2524         {
2525         case 'l':
2526             fUseLibrary ^= 1;
2527             break;
2528         case 'h':
2529             goto usage;
2530         default:
2531             goto usage;
2532         }
2533     }
2534 
2535     if ( pNtk == NULL )
2536     {
2537         Abc_Print( -1, "Empty network.\n" );
2538         return 1;
2539     }
2540     Abc_NtkPrintSharing( pNtk );
2541     return 0;
2542 
2543 usage:
2544     Abc_Print( -2, "usage: print_sharing [-h]\n" );
2545     Abc_Print( -2, "\t        prints the number of shared nodes in the TFI cones of the COs\n" );
2546 //    Abc_Print( -2, "\t-l    : used library gate names (if mapped) [default = %s]\n", fUseLibrary? "yes": "no" );
2547     Abc_Print( -2, "\t-h    : print the command usage\n");
2548     return 1;
2549 }
2550 
2551 /**Function*************************************************************
2552 
2553   Synopsis    []
2554 
2555   Description []
2556 
2557   SideEffects []
2558 
2559   SeeAlso     []
2560 
2561 ***********************************************************************/
Abc_CommandPrintXCut(Abc_Frame_t * pAbc,int argc,char ** argv)2562 int Abc_CommandPrintXCut( Abc_Frame_t * pAbc, int argc, char ** argv )
2563 {
2564     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
2565     int c;
2566     int fUseLibrary;
2567 
2568     extern int Abc_NtkCrossCut( Abc_Ntk_t * pNtk );
2569 
2570     // set defaults
2571     fUseLibrary = 1;
2572     Extra_UtilGetoptReset();
2573     while ( ( c = Extra_UtilGetopt( argc, argv, "lh" ) ) != EOF )
2574     {
2575         switch ( c )
2576         {
2577         case 'l':
2578             fUseLibrary ^= 1;
2579             break;
2580         case 'h':
2581             goto usage;
2582         default:
2583             goto usage;
2584         }
2585     }
2586 
2587     if ( pNtk == NULL )
2588     {
2589         Abc_Print( -1, "Empty network.\n" );
2590         return 1;
2591     }
2592     Abc_NtkCrossCut( pNtk );
2593     return 0;
2594 
2595 usage:
2596     Abc_Print( -2, "usage: print_xcut [-h]\n" );
2597     Abc_Print( -2, "\t        prints the size of the cross cut of the current network\n" );
2598 //    Abc_Print( -2, "\t-l    : used library gate names (if mapped) [default = %s]\n", fUseLibrary? "yes": "no" );
2599     Abc_Print( -2, "\t-h    : print the command usage\n");
2600     return 1;
2601 }
2602 
2603 /**Function*************************************************************
2604 
2605   Synopsis    []
2606 
2607   Description []
2608 
2609   SideEffects []
2610 
2611   SeeAlso     []
2612 
2613 ***********************************************************************/
Abc_CommandPrintDsd(Abc_Frame_t * pAbc,int argc,char ** argv)2614 int Abc_CommandPrintDsd( Abc_Frame_t * pAbc, int argc, char ** argv )
2615 {
2616     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
2617     int c;
2618     int fCofactor;
2619     int nCofLevel;
2620     int fProfile;
2621     int fPrintDec;
2622 
2623     extern void Kit_DsdTest( unsigned * pTruth, int nVars );
2624     extern void Kit_DsdPrintCofactors( unsigned * pTruth, int nVars, int nCofLevel, int fVerbose );
2625     extern void Dau_DecTrySets( word * p, int nVars, int fVerbose );
2626 
2627     // set defaults
2628     nCofLevel = 1;
2629     fCofactor = 0;
2630     fProfile  = 0;
2631     fPrintDec = 0;
2632     Extra_UtilGetoptReset();
2633     while ( ( c = Extra_UtilGetopt( argc, argv, "Npcdh" ) ) != EOF )
2634     {
2635         switch ( c )
2636         {
2637         case 'N':
2638             if ( globalUtilOptind >= argc )
2639             {
2640                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
2641                 goto usage;
2642             }
2643             nCofLevel = atoi(argv[globalUtilOptind]);
2644             globalUtilOptind++;
2645             if ( nCofLevel < 0 )
2646                 goto usage;
2647             break;
2648         case 'p':
2649             fProfile ^= 1;
2650             break;
2651         case 'c':
2652             fCofactor ^= 1;
2653             break;
2654         case 'd':
2655             fPrintDec ^= 1;
2656             break;
2657         case 'h':
2658             goto usage;
2659         default:
2660             goto usage;
2661         }
2662     }
2663 
2664     if ( pNtk == NULL )
2665     {
2666         Abc_Print( -1, "Empty network.\n" );
2667         return 1;
2668     }
2669     // get the truth table of the first output
2670     if ( !Abc_NtkIsLogic(pNtk) )
2671     {
2672         Abc_Print( -1, "Currently works only for logic networks.\n" );
2673         return 1;
2674     }
2675     Abc_NtkToAig( pNtk );
2676     // convert it to truth table
2677     {
2678         Abc_Obj_t * pObj = Abc_ObjFanin0( Abc_NtkPo(pNtk, 0) );
2679         Vec_Int_t * vMemory;
2680         unsigned * pTruth;
2681         if ( !Abc_ObjIsNode(pObj) )
2682         {
2683             Abc_Print( -1, "The fanin of the first PO node does not have a logic function.\n" );
2684             return 1;
2685         }
2686         if ( Abc_ObjFaninNum(pObj) > 16 )
2687         {
2688             Abc_Print( -1, "Currently works only for up to 16 inputs.\n" );
2689             return 1;
2690         }
2691         vMemory = Vec_IntAlloc(0);
2692         pTruth = Hop_ManConvertAigToTruth( (Hop_Man_t *)pNtk->pManFunc, Hop_Regular((Hop_Obj_t *)pObj->pData), Abc_ObjFaninNum(pObj), vMemory, 0 );
2693         if ( Hop_IsComplement((Hop_Obj_t *)pObj->pData) )
2694             Extra_TruthNot( pTruth, pTruth, Abc_ObjFaninNum(pObj) );
2695 //        Extra_PrintBinary( stdout, pTruth, 1 << Abc_ObjFaninNum(pObj) );
2696 //        Abc_Print( -1, "\n" );
2697         if ( fPrintDec )//&&Abc_ObjFaninNum(pObj) <= 6 )
2698         {
2699             word * pTruthW = (word *)pTruth;
2700             if ( Abc_ObjFaninNum(pObj) < 6 )
2701                 pTruthW[0] = Abc_Tt6Stretch( pTruthW[0], Abc_ObjFaninNum(pObj) );
2702             Dau_DecTrySets( (word *)pTruth, Abc_ObjFaninNum(pObj), 1 );
2703         }
2704         if ( fProfile )
2705             Kit_TruthPrintProfile( pTruth, Abc_ObjFaninNum(pObj) );
2706         else if ( fCofactor )
2707             Kit_DsdPrintCofactors( pTruth, Abc_ObjFaninNum(pObj), nCofLevel, 1 );
2708         else
2709             Kit_DsdTest( pTruth, Abc_ObjFaninNum(pObj) );
2710         Vec_IntFree( vMemory );
2711     }
2712     return 0;
2713 
2714 usage:
2715     Abc_Print( -2, "usage: print_dsd [-pcdh] [-N <num>]\n" );
2716     Abc_Print( -2, "\t           print DSD formula for a single-output function with less than 16 variables\n" );
2717     Abc_Print( -2, "\t-p       : toggle printing profile [default = %s]\n", fProfile? "yes": "no" );
2718     Abc_Print( -2, "\t-c       : toggle recursive cofactoring [default = %s]\n", fCofactor? "yes": "no" );
2719     Abc_Print( -2, "\t-d       : toggle printing decompositions [default = %s]\n", fPrintDec? "yes": "no" );
2720     Abc_Print( -2, "\t-N <num> : the number of levels to cofactor [default = %d]\n", nCofLevel );
2721     Abc_Print( -2, "\t-h       : print the command usage\n");
2722     return 1;
2723 }
2724 
2725 /**Function*************************************************************
2726 
2727   Synopsis    []
2728 
2729   Description []
2730 
2731   SideEffects []
2732 
2733   SeeAlso     []
2734 
2735 ***********************************************************************/
Abc_CommandPrintCone(Abc_Frame_t * pAbc,int argc,char ** argv)2736 int Abc_CommandPrintCone( Abc_Frame_t * pAbc, int argc, char ** argv )
2737 {
2738     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
2739     int c;
2740     int fUseLibrary;
2741 
2742     // set defaults
2743     fUseLibrary = 1;
2744     Extra_UtilGetoptReset();
2745     while ( ( c = Extra_UtilGetopt( argc, argv, "lh" ) ) != EOF )
2746     {
2747         switch ( c )
2748         {
2749         case 'l':
2750             fUseLibrary ^= 1;
2751             break;
2752         case 'h':
2753             goto usage;
2754         default:
2755             goto usage;
2756         }
2757     }
2758     if ( pNtk == NULL )
2759     {
2760         Abc_Print( -1, "Empty network.\n" );
2761         return 1;
2762     }
2763     if ( Abc_NtkLatchNum(pNtk) == 0 )
2764     {
2765         Abc_Print( -1, "The network is combinational.\n" );
2766         return 1;
2767     }
2768     Abc_NtkDarPrintCone( pNtk );
2769     return 0;
2770 
2771 usage:
2772     Abc_Print( -2, "usage: print_cone [-h]\n" );
2773     Abc_Print( -2, "\t        prints cones of influence info for each primary output\n" );
2774 //    Abc_Print( -2, "\t-l    : used library gate names (if mapped) [default = %s]\n", fUseLibrary? "yes": "no" );
2775     Abc_Print( -2, "\t-h    : print the command usage\n");
2776     return 1;
2777 }
2778 
2779 
2780 /**Function*************************************************************
2781 
2782   Synopsis    []
2783 
2784   Description []
2785 
2786   SideEffects []
2787 
2788   SeeAlso     []
2789 
2790 ***********************************************************************/
Abc_CommandPrintMiter(Abc_Frame_t * pAbc,int argc,char ** argv)2791 int Abc_CommandPrintMiter( Abc_Frame_t * pAbc, int argc, char ** argv )
2792 {
2793     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
2794     int c;
2795     int fUseLibrary;
2796 
2797     extern void Abc_NtkPrintMiter( Abc_Ntk_t * pNtk );
2798 
2799     // set defaults
2800     fUseLibrary = 1;
2801     Extra_UtilGetoptReset();
2802     while ( ( c = Extra_UtilGetopt( argc, argv, "lh" ) ) != EOF )
2803     {
2804         switch ( c )
2805         {
2806         case 'l':
2807             fUseLibrary ^= 1;
2808             break;
2809         case 'h':
2810             goto usage;
2811         default:
2812             goto usage;
2813         }
2814     }
2815     if ( pNtk == NULL )
2816     {
2817         Abc_Print( -1, "Empty network.\n" );
2818         return 1;
2819     }
2820     if ( !Abc_NtkIsStrash(pNtk) )
2821     {
2822         Abc_Print( -1, "The network is should be structurally hashed.\n" );
2823         return 1;
2824     }
2825     Abc_NtkPrintMiter( pNtk );
2826     return 0;
2827 
2828 usage:
2829     Abc_Print( -2, "usage: print_miter [-h]\n" );
2830     Abc_Print( -2, "\t        prints the status of the miter\n" );
2831     Abc_Print( -2, "\t-h    : print the command usage\n");
2832     return 1;
2833 }
2834 
2835 /**Function*************************************************************
2836 
2837   Synopsis    []
2838 
2839   Description []
2840 
2841   SideEffects []
2842 
2843   SeeAlso     []
2844 
2845 ***********************************************************************/
Abc_CommandPrintStatus(Abc_Frame_t * pAbc,int argc,char ** argv)2846 int Abc_CommandPrintStatus( Abc_Frame_t * pAbc, int argc, char ** argv )
2847 {
2848     extern void Abc_NtkDumpOneCexSpecial( FILE * pFile, Abc_Ntk_t * pNtk, Abc_Cex_t * pCex );
2849     extern void Abc_NtkPrintPoEquivs( Abc_Ntk_t * pNtk );
2850     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
2851     int c, fOutStatus = 0, fShort = 1;
2852     char * pLogFileName = NULL;
2853     // set defaults
2854     Extra_UtilGetoptReset();
2855     while ( ( c = Extra_UtilGetopt( argc, argv, "Losh" ) ) != EOF )
2856     {
2857         switch ( c )
2858         {
2859         case 'L':
2860             if ( globalUtilOptind >= argc )
2861             {
2862                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
2863                 goto usage;
2864             }
2865             pLogFileName = argv[globalUtilOptind];
2866             globalUtilOptind++;
2867             break;
2868         case 'o':
2869             fOutStatus ^= 1;
2870             break;
2871         case 's':
2872             fShort ^= 1;
2873             break;
2874         case 'h':
2875             goto usage;
2876         default:
2877             goto usage;
2878         }
2879     }
2880     if ( fOutStatus )
2881     {
2882         if ( pNtk == NULL )
2883         {
2884             Abc_Print( -1, "Empty network.\n" );
2885             return 1;
2886         }
2887         Abc_NtkPrintPoEquivs( pNtk );
2888         return 0;
2889     }
2890     if ( !pAbc->vStatuses )
2891         Abc_Print( 1,"Status = %d  Frames = %d   ", pAbc->Status, pAbc->nFrames );
2892     if ( pAbc->pCex == NULL && pAbc->vCexVec == NULL )
2893         Abc_Print( 1,"Cex is not defined.\n" );
2894     else
2895     {
2896         if ( pAbc->pCex )
2897             Abc_CexPrintStats( pAbc->pCex );
2898         if ( pAbc->vCexVec )
2899         {
2900             Abc_Cex_t * pTemp;
2901             int nCexes = 0;
2902             int Counter = 0;
2903             //printf( "\n" );
2904             Vec_PtrForEachEntry( Abc_Cex_t *, pAbc->vCexVec, pTemp, c )
2905             {
2906                 if ( pTemp == (void *)(ABC_PTRINT_T)1 )
2907                 {
2908                     Counter++;
2909                     continue;
2910                 }
2911                 if ( pTemp )
2912                 {
2913                     printf( "%4d : ", ++nCexes );
2914                     Abc_CexPrintStats( pTemp );
2915                 }
2916             }
2917 //            if ( Counter )
2918 //                printf( "In total, %d (out of %d) outputs are \"sat\" but CEXes are not recorded.\n", Counter, Vec_PtrSize(pAbc->vCexVec) );
2919         }
2920     }
2921     if ( pAbc->vStatuses )
2922     {
2923         if ( pLogFileName )
2924         {
2925             Abc_Cex_t * pTemp = NULL;
2926             FILE * pFile = fopen( pLogFileName, "wb" );
2927             if ( pFile == NULL )
2928             {
2929                 printf( "Cannot open file \"%s\" for writing.\n", pLogFileName );
2930                 return 0;
2931             }
2932             Vec_PtrForEachEntry( Abc_Cex_t *, pAbc->vCexVec, pTemp, c )
2933             {
2934                 int Status = Vec_IntEntry( pAbc->vStatuses, c );
2935                 if ( Status == -1 ) // undec
2936                     fprintf( pFile, "STATUS: ABORTED " );
2937                 else if ( Status == 0 )
2938                     fprintf( pFile, "STATUS: SAT " );
2939                 else if ( Status == 1 )
2940                     fprintf( pFile, "STATUS: UNSAT " );
2941                 fprintf( pFile, "%s\n", Abc_ObjName(Abc_NtkPo(pNtk, c)) );
2942                 if ( Status != 0 )
2943                     continue;
2944                 Abc_NtkDumpOneCexSpecial( pFile, pNtk, pTemp );
2945             }
2946             fclose( pFile );
2947         }
2948         else if ( fShort )
2949         {
2950             printf( "Status array contains %d SAT, %d UNSAT, and %d UNDEC entries (out of %d).",
2951                 Vec_IntCountEntry(pAbc->vStatuses, 0), Vec_IntCountEntry(pAbc->vStatuses, 1),
2952                 Vec_IntCountEntry(pAbc->vStatuses, -1), Vec_IntSize(pAbc->vStatuses) );
2953         }
2954         else
2955         {
2956             int i, Entry;
2957             Vec_IntForEachEntry( pAbc->vStatuses, Entry, i )
2958                 printf( "%d=%d  ", i, Entry );
2959         }
2960         printf( "\n" );
2961     }
2962     return 0;
2963 
2964 usage:
2965     Abc_Print( -2, "usage: print_status [-L file] [-osh]\n" );
2966     Abc_Print( -2, "\t          prints verification status\n" );
2967     Abc_Print( -2, "\t-L file : the log file name [default = %s]\n",  pLogFileName ? pLogFileName : "no logging" );
2968     Abc_Print( -2, "\t-o      : toggle printing output status [default = %s]\n", fOutStatus? "yes": "no" );
2969     Abc_Print( -2, "\t-s      : toggle using short print-out [default = %s]\n", fShort? "yes": "no" );
2970     Abc_Print( -2, "\t-h      : print the command usage\n");
2971     return 1;
2972 }
2973 
2974 /**Function*************************************************************
2975 
2976   Synopsis    []
2977 
2978   Description []
2979 
2980   SideEffects []
2981 
2982   SeeAlso     []
2983 
2984 ***********************************************************************/
Abc_CommandPrintDelay(Abc_Frame_t * pAbc,int argc,char ** argv)2985 int Abc_CommandPrintDelay( Abc_Frame_t * pAbc, int argc, char ** argv )
2986 {
2987     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
2988     Abc_Obj_t * pObjIn = NULL, * pObjOut = NULL;
2989     int c;
2990     // set defaults
2991     Extra_UtilGetoptReset();
2992     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
2993     {
2994         switch ( c )
2995         {
2996         case 'h':
2997             goto usage;
2998         default:
2999             goto usage;
3000         }
3001     }
3002     if ( pNtk == NULL )
3003     {
3004         Abc_Print( -1, "Empty network.\n" );
3005         return 1;
3006     }
3007     if ( !Abc_NtkIsMappedLogic(pNtk) )
3008     {
3009         Abc_Print( -1, "Delay trace works only for network mapped into standard cells.\n" );
3010         return 1;
3011     }
3012     if ( argc > globalUtilOptind + 2 )
3013     {
3014         Abc_Print( -1, "Wrong number of auguments.\n" );
3015         goto usage;
3016     }
3017     // collect the first name (PO name)
3018     if ( argc >= globalUtilOptind + 1 )
3019     {
3020         int Num = Nm_ManFindIdByName( pNtk->pManName, argv[globalUtilOptind], ABC_OBJ_PO );
3021         if ( Num < 0 )
3022             Num = Nm_ManFindIdByName( pNtk->pManName, argv[globalUtilOptind], ABC_OBJ_BI );
3023         if ( Num >= 0 )
3024             pObjOut = Abc_NtkObj( pNtk, Num );
3025         if ( pObjOut == NULL )
3026         {
3027             Abc_Print( 1, "Cannot find combinational output \"%s\".\n", argv[globalUtilOptind] );
3028             return 1;
3029         }
3030     }
3031     // collect the second name (PI name)
3032     if ( argc == globalUtilOptind + 2 )
3033     {
3034         int Num = Nm_ManFindIdByName( pNtk->pManName, argv[globalUtilOptind+1], ABC_OBJ_PI );
3035         if ( Num < 0 )
3036             Num = Nm_ManFindIdByName( pNtk->pManName, argv[globalUtilOptind+1], ABC_OBJ_BO );
3037         if ( Num >= 0 )
3038             pObjIn = Abc_NtkObj( pNtk, Num );
3039         if ( pObjIn == NULL )
3040         {
3041             Abc_Print( 1, "Cannot find combinational input \"%s\".\n", argv[globalUtilOptind+1] );
3042             return 1;
3043         }
3044     }
3045     Abc_NtkDelayTrace( pNtk, pObjOut, pObjIn, 1 );
3046     return 0;
3047 
3048 usage:
3049     Abc_Print( -2, "usage: print_delay [-h] <CO_name> <CI_name>\n" );
3050     Abc_Print( -2, "\t            prints one critical path of the mapped network\n" );
3051     Abc_Print( -2, "\t-h        : print the command usage\n");
3052     Abc_Print( -2, "\t<CO_name> : (optional) the sink of the critical path (primary output or flop input)\n");
3053     Abc_Print( -2, "\t<CI_name> : (optional) the source of the critical path (primary input or flop output)\n");
3054     Abc_Print( -2, "\t            (if CO and/or CI are not given, uses the most critical ones)\n");
3055     return 1;
3056 }
3057 
3058 /**Function*************************************************************
3059 
3060   Synopsis    []
3061 
3062   Description []
3063 
3064   SideEffects []
3065 
3066   SeeAlso     []
3067 
3068 ***********************************************************************/
Abc_CommandShow(Abc_Frame_t * pAbc,int argc,char ** argv)3069 int Abc_CommandShow( Abc_Frame_t * pAbc, int argc, char ** argv )
3070 {
3071     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
3072     int c;
3073     int fSeq;
3074     int fGateNames;
3075     int fUseReverse;
3076     int fFlopDep;
3077     extern void Abc_NtkShow( Abc_Ntk_t * pNtk, int fGateNames, int fSeq, int fUseReverse );
3078     extern void Abc_NtkShowFlopDependency( Abc_Ntk_t * pNtk );
3079 
3080     // set defaults
3081     fSeq        = 0;
3082     fGateNames  = 0;
3083     fUseReverse = 1;
3084     fFlopDep    = 0;
3085     Extra_UtilGetoptReset();
3086     while ( ( c = Extra_UtilGetopt( argc, argv, "rsgfh" ) ) != EOF )
3087     {
3088         switch ( c )
3089         {
3090         case 'r':
3091             fUseReverse ^= 1;
3092             break;
3093         case 's':
3094             fSeq ^= 1;
3095             break;
3096         case 'g':
3097             fGateNames ^= 1;
3098             break;
3099         case 'f':
3100             fFlopDep ^= 1;
3101             break;
3102         default:
3103             goto usage;
3104         }
3105     }
3106 
3107     if ( pNtk == NULL )
3108     {
3109         Abc_Print( -1, "Empty network.\n" );
3110         return 1;
3111     }
3112 
3113     if ( fFlopDep )
3114         Abc_NtkShowFlopDependency( pNtk );
3115     else
3116         Abc_NtkShow( pNtk, fGateNames, fSeq, fUseReverse );
3117     return 0;
3118 
3119 usage:
3120     Abc_Print( -2, "usage: show [-srgfh]\n" );
3121     Abc_Print( -2, "       visualizes the network structure using DOT and GSVIEW\n" );
3122 #ifdef WIN32
3123     Abc_Print( -2, "       \"dot.exe\" and \"gsview32.exe\" should be set in the paths\n" );
3124     Abc_Print( -2, "       (\"gsview32.exe\" may be in \"C:\\Program Files\\Ghostgum\\gsview\\\")\n" );
3125 #endif
3126     Abc_Print( -2, "\t-s    : toggles visualization of sequential networks [default = %s].\n", fSeq? "yes": "no" );
3127     Abc_Print( -2, "\t-r    : toggles ordering nodes in reverse order [default = %s].\n", fUseReverse? "yes": "no" );
3128     Abc_Print( -2, "\t-g    : toggles printing gate names for mapped network [default = %s].\n", fGateNames? "yes": "no" );
3129     Abc_Print( -2, "\t-f    : toggles visualizing flop dependency graph [default = %s].\n", fFlopDep? "yes": "no" );
3130     Abc_Print( -2, "\t-h    : print the command usage\n");
3131     return 1;
3132 }
3133 
3134 /**Function*************************************************************
3135 
3136   Synopsis    []
3137 
3138   Description []
3139 
3140   SideEffects []
3141 
3142   SeeAlso     []
3143 
3144 ***********************************************************************/
Abc_CommandShowBdd(Abc_Frame_t * pAbc,int argc,char ** argv)3145 int Abc_CommandShowBdd( Abc_Frame_t * pAbc, int argc, char ** argv )
3146 {
3147     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
3148     Abc_Obj_t * pNode;
3149     int c, fCompl = 0, fGlobal = 0;
3150     extern void Abc_NodeShowBdd( Abc_Obj_t * pNode, int fCompl );
3151     extern void Abc_NtkShowBdd( Abc_Ntk_t * pNtk, int fCompl );
3152 
3153     // set defaults
3154     Extra_UtilGetoptReset();
3155     while ( ( c = Extra_UtilGetopt( argc, argv, "cgh" ) ) != EOF )
3156     {
3157         switch ( c )
3158         {
3159         case 'c':
3160             fCompl ^= 1;
3161             break;
3162         case 'g':
3163             fGlobal ^= 1;
3164             break;
3165         case 'h':
3166             goto usage;
3167         default:
3168             goto usage;
3169         }
3170     }
3171 
3172     if ( pNtk == NULL )
3173     {
3174         Abc_Print( -1, "Empty network.\n" );
3175         return 1;
3176     }
3177 
3178     if ( fGlobal )
3179     {
3180         Abc_Ntk_t * pTemp = Abc_NtkIsStrash(pNtk) ? pNtk : Abc_NtkStrash(pNtk, 0, 0, 0);
3181         Abc_NtkShowBdd( pTemp, fCompl );
3182         if ( pTemp != pNtk )
3183             Abc_NtkDelete( pTemp );
3184         return 0;
3185     }
3186 
3187     if ( !Abc_NtkIsBddLogic(pNtk) )
3188     {
3189         Abc_Print( -1, "Visualizing BDDs can only be done for logic BDD networks (run \"bdd\").\n" );
3190         return 1;
3191     }
3192     if ( argc > globalUtilOptind + 1 )
3193     {
3194         Abc_Print( -1, "Wrong number of auguments.\n" );
3195         goto usage;
3196     }
3197     if ( argc == globalUtilOptind )
3198     {
3199         pNode = Abc_ObjFanin0( Abc_NtkPo(pNtk, 0) );
3200         if ( !Abc_ObjIsNode(pNode) )
3201         {
3202             Abc_Print( -1, "The driver \"%s\" of the first PO is not an internal node.\n", Abc_ObjName(pNode) );
3203             return 1;
3204         }
3205     }
3206     else
3207     {
3208         pNode = Abc_NtkFindNode( pNtk, argv[globalUtilOptind] );
3209         if ( pNode == NULL )
3210         {
3211             Abc_Print( -1, "Cannot find node \"%s\".\n", argv[globalUtilOptind] );
3212             return 1;
3213         }
3214     }
3215     Abc_NodeShowBdd( pNode, fCompl );
3216     return 0;
3217 
3218 usage:
3219     Abc_Print( -2, "usage: show_bdd [-cgh] <node>\n" );
3220     Abc_Print( -2, "       uses DOT and GSVIEW to visualize the global BDDs of primary outputs\n" );
3221     Abc_Print( -2, "       in terms of primary inputs or the local BDD of a node in terms of its fanins\n" );
3222 #ifdef WIN32
3223     Abc_Print( -2, "       \"dot.exe\" and \"gsview32.exe\" should be set in the paths\n" );
3224     Abc_Print( -2, "       (\"gsview32.exe\" may be in \"C:\\Program Files\\Ghostgum\\gsview\\\")\n" );
3225 #endif
3226     Abc_Print( -2, "\t<node>: (optional) the node to consider [default = the driver of the first PO]\n");
3227     Abc_Print( -2, "\t-c    : toggle visualizing BDD with complemented edges [default = %s].\n", fCompl? "yes": "no" );
3228     Abc_Print( -2, "\t-g    : toggle visualizing the global BDDs of primary outputs [default = %s].\n", fGlobal? "yes": "no" );
3229     Abc_Print( -2, "\t-h    : print the command usage\n");
3230     return 1;
3231 }
3232 
3233 /**Function*************************************************************
3234 
3235   Synopsis    []
3236 
3237   Description []
3238 
3239   SideEffects []
3240 
3241   SeeAlso     []
3242 
3243 ***********************************************************************/
Abc_CommandShowCut(Abc_Frame_t * pAbc,int argc,char ** argv)3244 int Abc_CommandShowCut( Abc_Frame_t * pAbc, int argc, char ** argv )
3245 {
3246     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
3247     Abc_Obj_t * pNode;
3248     int c;
3249     int nNodeSizeMax;
3250     int nConeSizeMax;
3251     extern void Abc_NodeShowCut( Abc_Obj_t * pNode, int nNodeSizeMax, int nConeSizeMax );
3252 
3253     // set defaults
3254     nNodeSizeMax = 10;
3255     nConeSizeMax = ABC_INFINITY;
3256     Extra_UtilGetoptReset();
3257     while ( ( c = Extra_UtilGetopt( argc, argv, "NCh" ) ) != EOF )
3258     {
3259         switch ( c )
3260         {
3261         case 'N':
3262             if ( globalUtilOptind >= argc )
3263             {
3264                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
3265                 goto usage;
3266             }
3267             nNodeSizeMax = atoi(argv[globalUtilOptind]);
3268             globalUtilOptind++;
3269             if ( nNodeSizeMax < 0 )
3270                 goto usage;
3271             break;
3272         case 'C':
3273             if ( globalUtilOptind >= argc )
3274             {
3275                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
3276                 goto usage;
3277             }
3278             nConeSizeMax = atoi(argv[globalUtilOptind]);
3279             globalUtilOptind++;
3280             if ( nConeSizeMax < 0 )
3281                 goto usage;
3282             break;
3283         case 'h':
3284             goto usage;
3285         default:
3286             goto usage;
3287         }
3288     }
3289 
3290     if ( pNtk == NULL )
3291     {
3292         Abc_Print( -1, "Empty network.\n" );
3293         return 1;
3294     }
3295 
3296     if ( !Abc_NtkIsStrash(pNtk) )
3297     {
3298         Abc_Print( -1, "Visualizing cuts only works for AIGs (run \"strash\").\n" );
3299         return 1;
3300     }
3301     if ( argc != globalUtilOptind + 1 )
3302     {
3303         Abc_Print( -1, "Wrong number of auguments.\n" );
3304         goto usage;
3305     }
3306 
3307     pNode = Abc_NtkFindNode( pNtk, argv[globalUtilOptind] );
3308     if ( pNode == NULL )
3309     {
3310         Abc_Print( -1, "Cannot find node \"%s\".\n", argv[globalUtilOptind] );
3311         return 1;
3312     }
3313     Abc_NodeShowCut( pNode, nNodeSizeMax, nConeSizeMax );
3314     return 0;
3315 
3316 usage:
3317     Abc_Print( -2, "usage: show_cut [-N <num>] [-C <num>] [-h] <node>\n" );
3318     Abc_Print( -2, "             visualizes the cut of a node using DOT and GSVIEW\n" );
3319 #ifdef WIN32
3320     Abc_Print( -2, "             \"dot.exe\" and \"gsview32.exe\" should be set in the paths\n" );
3321     Abc_Print( -2, "             (\"gsview32.exe\" may be in \"C:\\Program Files\\Ghostgum\\gsview\\\")\n" );
3322 #endif
3323     Abc_Print( -2, "\t-N <num> : the max size of the cut to be computed [default = %d]\n", nNodeSizeMax );
3324     Abc_Print( -2, "\t-C <num> : the max support of the containing cone [default = %d]\n", nConeSizeMax );
3325     Abc_Print( -2, "\t<node>   : the node to consider\n");
3326     Abc_Print( -2, "\t-h       : print the command usage\n");
3327     return 1;
3328 }
3329 
3330 
3331 /**Function*************************************************************
3332 
3333   Synopsis    []
3334 
3335   Description []
3336 
3337   SideEffects []
3338 
3339   SeeAlso     []
3340 
3341 ***********************************************************************/
Abc_CommandCollapse(Abc_Frame_t * pAbc,int argc,char ** argv)3342 int Abc_CommandCollapse( Abc_Frame_t * pAbc, int argc, char ** argv )
3343 {
3344     Abc_Ntk_t * pNtk, * pNtkRes;
3345     int fVerbose;
3346     int fBddSizeMax;
3347     int fDualRail;
3348     int fReorder;
3349     int fReverse;
3350     int c;
3351     char * pLogFileName = NULL;
3352     pNtk = Abc_FrameReadNtk(pAbc);
3353 
3354     // set defaults
3355     fVerbose = 0;
3356     fReorder = 1;
3357     fReverse = 0;
3358     fDualRail = 0;
3359     fBddSizeMax = ABC_INFINITY;
3360     Extra_UtilGetoptReset();
3361     while ( ( c = Extra_UtilGetopt( argc, argv, "BLrodvh" ) ) != EOF )
3362     {
3363         switch ( c )
3364         {
3365         case 'B':
3366             if ( globalUtilOptind >= argc )
3367             {
3368                 Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" );
3369                 goto usage;
3370             }
3371             fBddSizeMax = atoi(argv[globalUtilOptind]);
3372             globalUtilOptind++;
3373             if ( fBddSizeMax < 0 )
3374                 goto usage;
3375             break;
3376         case 'L':
3377             if ( globalUtilOptind >= argc )
3378             {
3379                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
3380                 goto usage;
3381             }
3382             pLogFileName = argv[globalUtilOptind];
3383             globalUtilOptind++;
3384             break;
3385         case 'r':
3386             fReorder ^= 1;
3387             break;
3388         case 'o':
3389             fReverse ^= 1;
3390             break;
3391         case 'd':
3392             fDualRail ^= 1;
3393             break;
3394         case 'v':
3395             fVerbose ^= 1;
3396             break;
3397         case 'h':
3398             goto usage;
3399         default:
3400             goto usage;
3401         }
3402     }
3403 
3404     if ( pNtk == NULL )
3405     {
3406         Abc_Print( -1, "Empty network.\n" );
3407         return 1;
3408     }
3409 
3410     if ( !Abc_NtkIsLogic(pNtk) && !Abc_NtkIsStrash(pNtk) )
3411     {
3412         Abc_Print( -1, "Can only collapse a logic network or an AIG.\n" );
3413         return 1;
3414     }
3415 
3416     // get the new network
3417     if ( Abc_NtkIsStrash(pNtk) )
3418         pNtkRes = Abc_NtkCollapse( pNtk, fBddSizeMax, fDualRail, fReorder, fReverse, fVerbose );
3419     else
3420     {
3421         pNtk = Abc_NtkStrash( pNtk, 0, 0, 0 );
3422         pNtkRes = Abc_NtkCollapse( pNtk, fBddSizeMax, fDualRail, fReorder, fReverse, fVerbose );
3423         Abc_NtkDelete( pNtk );
3424     }
3425     if ( pNtkRes == NULL )
3426     {
3427         Abc_Print( -1, "Collapsing has failed.\n" );
3428         return 1;
3429     }
3430     // replace the current network
3431     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
3432     if ( pLogFileName )
3433     {
3434         pAbc->pCex = NULL;
3435         pAbc->nFrames = -1;
3436         if ( Abc_NtkNodeNum(pNtkRes) == 0 )
3437             pAbc->Status =  1; // UNSAT
3438         else
3439             pAbc->Status = -1; // UNDEC
3440         Abc_NtkWriteLogFile( pLogFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, "collapse" );
3441     }
3442     return 0;
3443 
3444 usage:
3445     Abc_Print( -2, "usage: collapse [-B <num>] [-L file] [-rodvh]\n" );
3446     Abc_Print( -2, "\t          collapses the network by constructing global BDDs\n" );
3447     Abc_Print( -2, "\t-B <num>: limit on live BDD nodes during collapsing [default = %d]\n", fBddSizeMax );
3448     Abc_Print( -2, "\t-L file : the log file name [default = %s]\n",  pLogFileName ? pLogFileName : "no logging" );
3449     Abc_Print( -2, "\t-r      : toggles dynamic variable reordering [default = %s]\n", fReorder? "yes": "no" );
3450     Abc_Print( -2, "\t-o      : toggles reverse variable ordering [default = %s]\n", fReverse? "yes": "no" );
3451     Abc_Print( -2, "\t-d      : toggles dual-rail collapsing mode [default = %s]\n", fDualRail? "yes": "no" );
3452     Abc_Print( -2, "\t-v      : print verbose information [default = %s]\n", fVerbose? "yes": "no" );
3453     Abc_Print( -2, "\t-h      : print the command usage\n");
3454     return 1;
3455 }
3456 
3457 
3458 /**Function*************************************************************
3459 
3460   Synopsis    []
3461 
3462   Description []
3463 
3464   SideEffects []
3465 
3466   SeeAlso     []
3467 
3468 ***********************************************************************/
Abc_CommandSatClp(Abc_Frame_t * pAbc,int argc,char ** argv)3469 int Abc_CommandSatClp( Abc_Frame_t * pAbc, int argc, char ** argv )
3470 {
3471     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc), * pNtkRes;
3472     int nCubeLim   =        0;
3473     int nBTLimit   =  1000000;
3474     int nCostMax   = 20000000;
3475     int fCanon     = 0;
3476     int fReverse   = 0;
3477     int fCnfShared = 0;
3478     int fVerbose   = 0;
3479     int c;
3480 
3481     // set defaults
3482     Extra_UtilGetoptReset();
3483     while ( ( c = Extra_UtilGetopt( argc, argv, "CLZcrsvh" ) ) != EOF )
3484     {
3485         switch ( c )
3486         {
3487         case 'C':
3488             if ( globalUtilOptind >= argc )
3489             {
3490                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
3491                 goto usage;
3492             }
3493             nCubeLim = atoi(argv[globalUtilOptind]);
3494             globalUtilOptind++;
3495             if ( nCubeLim < 0 )
3496                 goto usage;
3497             break;
3498         case 'L':
3499             if ( globalUtilOptind >= argc )
3500             {
3501                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
3502                 goto usage;
3503             }
3504             nBTLimit = atoi(argv[globalUtilOptind]);
3505             globalUtilOptind++;
3506             if ( nBTLimit < 0 )
3507                 goto usage;
3508             break;
3509         case 'Z':
3510             if ( globalUtilOptind >= argc )
3511             {
3512                 Abc_Print( -1, "Command line switch \"-Z\" should be followed by an integer.\n" );
3513                 goto usage;
3514             }
3515             nCostMax = atoi(argv[globalUtilOptind]);
3516             globalUtilOptind++;
3517             if ( nCostMax < 0 )
3518                 goto usage;
3519             break;
3520         case 'c':
3521             fCanon ^= 1;
3522             break;
3523         case 'r':
3524             fReverse ^= 1;
3525             break;
3526         case 's':
3527             fCnfShared ^= 1;
3528             break;
3529         case 'v':
3530             fVerbose ^= 1;
3531             break;
3532         case 'h':
3533             goto usage;
3534         default:
3535             goto usage;
3536         }
3537     }
3538 
3539     if ( pNtk == NULL )
3540     {
3541         Abc_Print( -1, "Empty network.\n" );
3542         return 1;
3543     }
3544 
3545     if ( !Abc_NtkIsLogic(pNtk) && !Abc_NtkIsStrash(pNtk) )
3546     {
3547         Abc_Print( -1, "Can only collapse a logic network or an AIG.\n" );
3548         return 1;
3549     }
3550 
3551     // get the new network
3552     if ( Abc_NtkIsStrash(pNtk) )
3553         pNtkRes = Abc_NtkCollapseSat( pNtk, nCubeLim, nBTLimit, nCostMax, fCanon, fReverse, fCnfShared, fVerbose );
3554     else
3555     {
3556         pNtk = Abc_NtkStrash( pNtk, 0, 0, 0 );
3557         pNtkRes = Abc_NtkCollapseSat( pNtk, nCubeLim, nBTLimit, nCostMax, fCanon, fReverse, fCnfShared, fVerbose );
3558         Abc_NtkDelete( pNtk );
3559     }
3560     if ( pNtkRes == NULL )
3561     {
3562         Abc_Print( -1, "Collapsing has failed.\n" );
3563         return 0;
3564     }
3565     // replace the current network
3566     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
3567     return 0;
3568 
3569 usage:
3570     Abc_Print( -2, "usage: satclp [-CLZ num] [-crsvh]\n" );
3571     Abc_Print( -2, "\t         performs SAT based collapsing\n" );
3572     Abc_Print( -2, "\t-C num : the limit on the SOP size of one output [default = %d]\n",              nCubeLim );
3573     Abc_Print( -2, "\t-L num : the limit on the number of conflicts in one SAT call [default = %d]\n", nBTLimit );
3574     Abc_Print( -2, "\t-Z num : the limit on the cost of the largest output [default = %d]\n",          nCostMax );
3575     Abc_Print( -2, "\t-c     : toggles using canonical ISOP computation [default = %s]\n",             fCanon? "yes": "no" );
3576     Abc_Print( -2, "\t-r     : toggles using reverse veriable ordering [default = %s]\n",              fReverse? "yes": "no" );
3577     Abc_Print( -2, "\t-s     : toggles shared CNF computation (non-canonical only) [default = %s]\n",  fCnfShared? "yes": "no" );
3578     Abc_Print( -2, "\t-v     : toggles printing verbose information [default = %s]\n",                 fVerbose? "yes": "no" );
3579     Abc_Print( -2, "\t-h     : print the command usage\n");
3580     return 1;
3581 }
3582 
3583 /**Function*************************************************************
3584 
3585   Synopsis    []
3586 
3587   Description []
3588 
3589   SideEffects []
3590 
3591   SeeAlso     []
3592 
3593 ***********************************************************************/
Abc_CommandStrash(Abc_Frame_t * pAbc,int argc,char ** argv)3594 int Abc_CommandStrash( Abc_Frame_t * pAbc, int argc, char ** argv )
3595 {
3596     Abc_Ntk_t * pNtk, * pNtkRes;
3597     Abc_Obj_t * pObj;
3598     int c;
3599     int fAllNodes;
3600     int fRecord;
3601     int fCleanup;
3602     int fComplOuts;
3603     pNtk = Abc_FrameReadNtk(pAbc);
3604     // set defaults
3605     fAllNodes = 0;
3606     fCleanup  = 1;
3607     fRecord   = 0;
3608     fComplOuts= 0;
3609     Extra_UtilGetoptReset();
3610     while ( ( c = Extra_UtilGetopt( argc, argv, "acrih" ) ) != EOF )
3611     {
3612         switch ( c )
3613         {
3614         case 'a':
3615             fAllNodes ^= 1;
3616             break;
3617         case 'c':
3618             fCleanup ^= 1;
3619             break;
3620         case 'r':
3621             fRecord ^= 1;
3622             break;
3623         case 'i':
3624             fComplOuts ^= 1;
3625             break;
3626         case 'h':
3627             goto usage;
3628         default:
3629             goto usage;
3630         }
3631     }
3632 
3633     if ( pNtk == NULL )
3634     {
3635         Abc_Print( -1, "Empty network.\n" );
3636         return 1;
3637     }
3638 
3639     // get the new network
3640     pNtkRes = Abc_NtkStrash( pNtk, fAllNodes, fCleanup, fRecord );
3641     if ( pNtkRes == NULL )
3642     {
3643         Abc_Print( -1, "Strashing has failed.\n" );
3644         return 1;
3645     }
3646     if ( fComplOuts )
3647     Abc_NtkForEachPo( pNtkRes, pObj, c )
3648         Abc_ObjXorFaninC( pObj, 0 );
3649     // replace the current network
3650     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
3651     return 0;
3652 
3653 usage:
3654     Abc_Print( -2, "usage: strash [-acrih]\n" );
3655     Abc_Print( -2, "\t        transforms combinational logic into an AIG\n" );
3656     Abc_Print( -2, "\t-a    : toggles between using all nodes and DFS nodes [default = %s]\n", fAllNodes? "all": "DFS" );
3657     Abc_Print( -2, "\t-c    : toggles cleanup to remove the dagling AIG nodes [default = %s]\n", fCleanup? "all": "DFS" );
3658     Abc_Print( -2, "\t-r    : toggles using the record of AIG subgraphs [default = %s]\n", fRecord? "yes": "no" );
3659     Abc_Print( -2, "\t-i    : toggles complementing the POs of the AIG [default = %s]\n", fComplOuts? "yes": "no" );
3660     Abc_Print( -2, "\t-h    : print the command usage\n");
3661     return 1;
3662 }
3663 
3664 /**Function*************************************************************
3665 
3666   Synopsis    []
3667 
3668   Description []
3669 
3670   SideEffects []
3671 
3672   SeeAlso     []
3673 
3674 ***********************************************************************/
Abc_CommandBalance(Abc_Frame_t * pAbc,int argc,char ** argv)3675 int Abc_CommandBalance( Abc_Frame_t * pAbc, int argc, char ** argv )
3676 {
3677     Abc_Ntk_t * pNtk, * pNtkRes, * pNtkTemp;
3678     int c;
3679     int fDuplicate;
3680     int fSelective;
3681     int fUpdateLevel;
3682     int fExor;
3683     int fVerbose;
3684     pNtk = Abc_FrameReadNtk(pAbc);
3685 
3686     // set defaults
3687     fDuplicate   = 0;
3688     fSelective   = 0;
3689     fUpdateLevel = 1;
3690     fExor        = 0;
3691     fVerbose     = 0;
3692     Extra_UtilGetoptReset();
3693     while ( ( c = Extra_UtilGetopt( argc, argv, "ldsxvh" ) ) != EOF )
3694     {
3695         switch ( c )
3696         {
3697         case 'l':
3698             fUpdateLevel ^= 1;
3699             break;
3700         case 'd':
3701             fDuplicate ^= 1;
3702             break;
3703         case 's':
3704             fSelective ^= 1;
3705             break;
3706         case 'x':
3707             fExor ^= 1;
3708             break;
3709         case 'v':
3710             fVerbose ^= 1;
3711             break;
3712         case 'h':
3713             goto usage;
3714         default:
3715             goto usage;
3716         }
3717     }
3718 
3719     if ( pNtk == NULL )
3720     {
3721         Abc_Print( -1, "Empty network.\n" );
3722         return 1;
3723     }
3724     // get the new network
3725     if ( Abc_NtkIsStrash(pNtk) )
3726     {
3727         if ( fExor )
3728             pNtkRes = Abc_NtkBalanceExor( pNtk, fUpdateLevel, fVerbose );
3729         else
3730             pNtkRes = Abc_NtkBalance( pNtk, fDuplicate, fSelective, fUpdateLevel );
3731     }
3732     else
3733     {
3734         pNtkTemp = Abc_NtkStrash( pNtk, 0, 0, 0 );
3735         if ( pNtkTemp == NULL )
3736         {
3737             Abc_Print( -1, "Strashing before balancing has failed.\n" );
3738             return 1;
3739         }
3740         if ( fExor )
3741             pNtkRes = Abc_NtkBalanceExor( pNtkTemp, fUpdateLevel, fVerbose );
3742         else
3743             pNtkRes = Abc_NtkBalance( pNtkTemp, fDuplicate, fSelective, fUpdateLevel );
3744         Abc_NtkDelete( pNtkTemp );
3745     }
3746 
3747     // check if balancing worked
3748     if ( pNtkRes == NULL )
3749     {
3750         Abc_Print( -1, "Balancing has failed.\n" );
3751         return 1;
3752     }
3753     // replace the current network
3754     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
3755     return 0;
3756 
3757 usage:
3758     Abc_Print( -2, "usage: balance [-ldsxvh]\n" );
3759     Abc_Print( -2, "\t        transforms the current network into a well-balanced AIG\n" );
3760     Abc_Print( -2, "\t-l    : toggle minimizing the number of levels [default = %s]\n", fUpdateLevel? "yes": "no" );
3761     Abc_Print( -2, "\t-d    : toggle duplication of logic [default = %s]\n", fDuplicate? "yes": "no" );
3762     Abc_Print( -2, "\t-s    : toggle duplication on the critical paths [default = %s]\n", fSelective? "yes": "no" );
3763     Abc_Print( -2, "\t-x    : toggle balancing multi-input EXORs [default = %s]\n", fExor? "yes": "no" );
3764     Abc_Print( -2, "\t-v    : print verbose information [default = %s]\n", fVerbose? "yes": "no" );
3765     Abc_Print( -2, "\t-h    : print the command usage\n");
3766     return 1;
3767 }
3768 
3769 /**Function*************************************************************
3770 
3771   Synopsis    []
3772 
3773   Description []
3774 
3775   SideEffects []
3776 
3777   SeeAlso     []
3778 
3779 ***********************************************************************/
Abc_CommandMuxStruct(Abc_Frame_t * pAbc,int argc,char ** argv)3780 int Abc_CommandMuxStruct( Abc_Frame_t * pAbc, int argc, char ** argv )
3781 {
3782     Abc_Ntk_t * pNtk, * pNtkRes;
3783     int c;
3784     int fVerbose;
3785 
3786     extern Abc_Ntk_t * Abc_NtkMuxRestructure( Abc_Ntk_t * pNtk, int fVerbose );
3787     pNtk = Abc_FrameReadNtk(pAbc);
3788 
3789     // set defaults
3790     fVerbose     = 0;
3791     Extra_UtilGetoptReset();
3792     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
3793     {
3794         switch ( c )
3795         {
3796         case 'v':
3797             fVerbose ^= 1;
3798             break;
3799         case 'h':
3800             goto usage;
3801         default:
3802             goto usage;
3803         }
3804     }
3805 
3806     if ( pNtk == NULL )
3807     {
3808         Abc_Print( -1, "Empty network.\n" );
3809         return 1;
3810     }
3811     // get the new network
3812     if ( !Abc_NtkIsStrash(pNtk) )
3813     {
3814         Abc_Print( -1, "Does not work for a logic network.\n" );
3815         return 1;
3816     }
3817     // check if balancing worked
3818 //    pNtkRes = Abc_NtkMuxRestructure( pNtk, fVerbose );
3819     pNtkRes = NULL;
3820     if ( pNtkRes == NULL )
3821     {
3822         Abc_Print( -1, "MUX restructuring has failed.\n" );
3823         return 1;
3824     }
3825     // replace the current network
3826     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
3827     return 0;
3828 
3829 usage:
3830     Abc_Print( -2, "usage: mux_struct [-vh]\n" );
3831     Abc_Print( -2, "\t        performs MUX restructuring of the current network\n" );
3832     Abc_Print( -2, "\t-v    : print verbose information [default = %s]\n", fVerbose? "yes": "no" );
3833     Abc_Print( -2, "\t-h    : print the command usage\n");
3834     return 1;
3835 }
3836 
3837 /**Function*************************************************************
3838 
3839   Synopsis    []
3840 
3841   Description []
3842 
3843   SideEffects []
3844 
3845   SeeAlso     []
3846 
3847 ***********************************************************************/
Abc_CommandMulti(Abc_Frame_t * pAbc,int argc,char ** argv)3848 int Abc_CommandMulti( Abc_Frame_t * pAbc, int argc, char ** argv )
3849 {
3850     Abc_Ntk_t * pNtk, * pNtkRes;
3851     int nThresh, nFaninMax, c;
3852     int fCnf;
3853     int fMulti;
3854     int fSimple;
3855     int fFactor;
3856     extern Abc_Ntk_t * Abc_NtkMulti( Abc_Ntk_t * pNtk, int nThresh, int nFaninMax, int fCnf, int fMulti, int fSimple, int fFactor );
3857 
3858     pNtk = Abc_FrameReadNtk(pAbc);
3859 
3860     // set defaults
3861     nThresh   =  1;
3862     nFaninMax = 20;
3863     fCnf      =  0;
3864     fMulti    =  1;
3865     fSimple   =  0;
3866     fFactor   =  0;
3867     Extra_UtilGetoptReset();
3868     while ( ( c = Extra_UtilGetopt( argc, argv, "TFmcsfh" ) ) != EOF )
3869     {
3870         switch ( c )
3871         {
3872         case 'T':
3873             if ( globalUtilOptind >= argc )
3874             {
3875                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
3876                 goto usage;
3877             }
3878             nThresh = atoi(argv[globalUtilOptind]);
3879             globalUtilOptind++;
3880             if ( nThresh < 0 )
3881                 goto usage;
3882             break;
3883         case 'F':
3884             if ( globalUtilOptind >= argc )
3885             {
3886                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
3887                 goto usage;
3888             }
3889             nFaninMax = atoi(argv[globalUtilOptind]);
3890             globalUtilOptind++;
3891             if ( nFaninMax < 0 )
3892                 goto usage;
3893             break;
3894         case 'c':
3895             fCnf ^= 1;
3896             break;
3897         case 'm':
3898             fMulti ^= 1;
3899             break;
3900         case 's':
3901             fSimple ^= 1;
3902             break;
3903         case 'f':
3904             fFactor ^= 1;
3905             break;
3906         case 'h':
3907             goto usage;
3908         default:
3909             goto usage;
3910         }
3911     }
3912 
3913     if ( pNtk == NULL )
3914     {
3915         Abc_Print( -1, "Empty network.\n" );
3916         return 1;
3917     }
3918     if ( !Abc_NtkIsStrash(pNtk) )
3919     {
3920         Abc_Print( -1, "Cannot renode a network that is not an AIG (run \"strash\").\n" );
3921         return 1;
3922     }
3923 
3924     // get the new network
3925     pNtkRes = Abc_NtkMulti( pNtk, nThresh, nFaninMax, fCnf, fMulti, fSimple, fFactor );
3926     if ( pNtkRes == NULL )
3927     {
3928         Abc_Print( -1, "Renoding has failed.\n" );
3929         return 1;
3930     }
3931     // replace the current network
3932     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
3933     return 0;
3934 
3935 usage:
3936     Abc_Print( -2, "usage: multi [-TF <num>] [-msfch]\n" );
3937     Abc_Print( -2, "\t          transforms an AIG into a logic network by creating larger nodes\n" );
3938     Abc_Print( -2, "\t-F <num>: the maximum fanin size after renoding [default = %d]\n", nFaninMax );
3939     Abc_Print( -2, "\t-T <num>: the threshold for AIG node duplication [default = %d]\n", nThresh );
3940     Abc_Print( -2, "\t          (an AIG node is the root of a new node after renoding\n" );
3941     Abc_Print( -2, "\t          if this leads to duplication of no more than %d AIG nodes,\n", nThresh );
3942     Abc_Print( -2, "\t          that is, if [(numFanouts(Node)-1) * size(MFFC(Node))] <= %d)\n", nThresh );
3943     Abc_Print( -2, "\t-m      : creates multi-input AND graph [default = %s]\n", fMulti? "yes": "no" );
3944     Abc_Print( -2, "\t-s      : creates a simple AIG (no renoding) [default = %s]\n", fSimple? "yes": "no" );
3945     Abc_Print( -2, "\t-f      : creates a factor-cut network [default = %s]\n", fFactor? "yes": "no" );
3946     Abc_Print( -2, "\t-c      : performs renoding to derive the CNF [default = %s]\n", fCnf? "yes": "no" );
3947     Abc_Print( -2, "\t-h      : print the command usage\n");
3948     return 1;
3949 }
3950 
3951 /**Function*************************************************************
3952 
3953   Synopsis    []
3954 
3955   Description []
3956 
3957   SideEffects []
3958 
3959   SeeAlso     []
3960 
3961 ***********************************************************************/
Abc_CommandRenode(Abc_Frame_t * pAbc,int argc,char ** argv)3962 int Abc_CommandRenode( Abc_Frame_t * pAbc, int argc, char ** argv )
3963 {
3964     Abc_Ntk_t * pNtk, * pNtkRes;
3965     int nLutSize, nCutsMax, c;
3966     int nFlowIters, nAreaIters;
3967     int fArea;
3968     int fUseBdds;
3969     int fUseSops;
3970     int fUseCnfs;
3971     int fUseMv;
3972     int fVerbose;
3973     extern Abc_Ntk_t * Abc_NtkRenode( Abc_Ntk_t * pNtk, int nLutSize, int nCutsMax, int nFlowIters, int nAreaIters, int fArea, int fUseBdds, int fUseSops, int fUseCnfs, int fUseMv, int fVerbose );
3974 
3975     pNtk = Abc_FrameReadNtk(pAbc);
3976 
3977     // set defaults
3978     nLutSize   =  8;
3979     nCutsMax   =  4;
3980     nFlowIters =  1;
3981     nAreaIters =  1;
3982     fArea      =  0;
3983     fUseBdds   =  0;
3984     fUseSops   =  0;
3985     fUseCnfs   =  0;
3986     fUseMv     =  0;
3987     fVerbose   =  0;
3988     Extra_UtilGetoptReset();
3989     while ( ( c = Extra_UtilGetopt( argc, argv, "KCFAabscivh" ) ) != EOF )
3990     {
3991         switch ( c )
3992         {
3993         case 'K':
3994             if ( globalUtilOptind >= argc )
3995             {
3996                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
3997                 goto usage;
3998             }
3999             nLutSize = atoi(argv[globalUtilOptind]);
4000             globalUtilOptind++;
4001             if ( nLutSize < 0 )
4002                 goto usage;
4003             break;
4004         case 'C':
4005             if ( globalUtilOptind >= argc )
4006             {
4007                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
4008                 goto usage;
4009             }
4010             nCutsMax = atoi(argv[globalUtilOptind]);
4011             globalUtilOptind++;
4012             if ( nCutsMax < 0 )
4013                 goto usage;
4014             break;
4015         case 'F':
4016             if ( globalUtilOptind >= argc )
4017             {
4018                 Abc_Print( -1, "Command line switch \"-F\" should be followed by a positive integer.\n" );
4019                 goto usage;
4020             }
4021             nFlowIters = atoi(argv[globalUtilOptind]);
4022             globalUtilOptind++;
4023             if ( nFlowIters < 0 )
4024                 goto usage;
4025             break;
4026         case 'A':
4027             if ( globalUtilOptind >= argc )
4028             {
4029                 Abc_Print( -1, "Command line switch \"-A\" should be followed by a positive integer.\n" );
4030                 goto usage;
4031             }
4032             nAreaIters = atoi(argv[globalUtilOptind]);
4033             globalUtilOptind++;
4034             if ( nAreaIters < 0 )
4035                 goto usage;
4036             break;
4037         case 'a':
4038             fArea ^= 1;
4039             break;
4040         case 'b':
4041             fUseBdds ^= 1;
4042             break;
4043         case 's':
4044             fUseSops ^= 1;
4045             break;
4046         case 'c':
4047             fUseCnfs ^= 1;
4048             break;
4049         case 'i':
4050             fUseMv ^= 1;
4051             break;
4052         case 'v':
4053             fVerbose ^= 1;
4054             break;
4055         case 'h':
4056             goto usage;
4057         default:
4058             goto usage;
4059         }
4060     }
4061 
4062     if ( fUseBdds + fUseSops + fUseCnfs + fUseMv > 1 )
4063     {
4064         Abc_Print( -1, "Cannot optimize two parameters at the same time.\n" );
4065         return 1;
4066     }
4067 
4068     if ( nLutSize < 2 || nLutSize > IF_MAX_FUNC_LUTSIZE )
4069     {
4070         Abc_Print( -1, "Incorrect LUT size (%d).\n", nLutSize );
4071         return 1;
4072     }
4073 
4074     if ( nCutsMax < 1 || nCutsMax >= (1<<12) )
4075     {
4076         Abc_Print( -1, "Incorrect number of cuts.\n" );
4077         return 1;
4078     }
4079 
4080     if ( pNtk == NULL )
4081     {
4082         Abc_Print( -1, "Empty network.\n" );
4083         return 1;
4084     }
4085     if ( !Abc_NtkIsStrash(pNtk) )
4086     {
4087         Abc_Print( -1, "Cannot renode a network that is not an AIG (run \"strash\").\n" );
4088         return 1;
4089     }
4090 
4091     // get the new network
4092     pNtkRes = Abc_NtkRenode( pNtk, nLutSize, nCutsMax, nFlowIters, nAreaIters, fArea, fUseBdds, fUseSops, fUseCnfs, fUseMv, fVerbose );
4093     if ( pNtkRes == NULL )
4094     {
4095         Abc_Print( -1, "Renoding has failed.\n" );
4096         return 1;
4097     }
4098     // replace the current network
4099     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
4100     return 0;
4101 
4102 usage:
4103     Abc_Print( -2, "usage: renode [-KCFA <num>] [-sbciav]\n" );
4104     Abc_Print( -2, "\t          transforms the AIG into a logic network with larger nodes\n" );
4105     Abc_Print( -2, "\t          while minimizing the number of FF literals of the node SOPs\n" );
4106     Abc_Print( -2, "\t-K <num>: the max cut size for renoding (2 < num < %d) [default = %d]\n", IF_MAX_FUNC_LUTSIZE+1, nLutSize );
4107     Abc_Print( -2, "\t-C <num>: the max number of cuts used at a node (0 < num < 2^12) [default = %d]\n", nCutsMax );
4108     Abc_Print( -2, "\t-F <num>: the number of area flow recovery iterations (num >= 0) [default = %d]\n", nFlowIters );
4109     Abc_Print( -2, "\t-A <num>: the number of exact area recovery iterations (num >= 0) [default = %d]\n", nAreaIters );
4110     Abc_Print( -2, "\t-s      : toggles minimizing SOP cubes instead of FF lits [default = %s]\n", fUseSops? "yes": "no" );
4111     Abc_Print( -2, "\t-b      : toggles minimizing BDD nodes instead of FF lits [default = %s]\n", fUseBdds? "yes": "no" );
4112     Abc_Print( -2, "\t-c      : toggles minimizing CNF clauses instead of FF lits [default = %s]\n", fUseCnfs? "yes": "no" );
4113     Abc_Print( -2, "\t-i      : toggles minimizing MV-SOP instead of FF lits [default = %s]\n", fUseMv? "yes": "no" );
4114     Abc_Print( -2, "\t-a      : toggles area-oriented mapping [default = %s]\n", fArea? "yes": "no" );
4115     Abc_Print( -2, "\t-v      : print verbose information [default = %s]\n", fVerbose? "yes": "no" );
4116     Abc_Print( -2, "\t-h      : print the command usage\n");
4117     return 1;
4118 }
4119 
4120 /**Function*************************************************************
4121 
4122   Synopsis    []
4123 
4124   Description []
4125 
4126   SideEffects []
4127 
4128   SeeAlso     []
4129 
4130 ***********************************************************************/
Abc_CommandCleanup(Abc_Frame_t * pAbc,int argc,char ** argv)4131 int Abc_CommandCleanup( Abc_Frame_t * pAbc, int argc, char ** argv )
4132 {
4133     Abc_Ntk_t * pNtk, * pNtkRes;
4134     int c;
4135     int fCleanupPis;
4136     int fCleanupPos;
4137     int fVerbose;
4138 
4139     extern Abc_Ntk_t * Abc_NtkDarCleanupAig( Abc_Ntk_t * pNtk, int fCleanupPis, int fCleanupPos, int fVerbose );
4140 
4141     pNtk = Abc_FrameReadNtk(pAbc);
4142 
4143     // set defaults
4144     fCleanupPis = 1;
4145     fCleanupPos = 1;
4146     fVerbose    = 1;
4147     Extra_UtilGetoptReset();
4148     while ( ( c = Extra_UtilGetopt( argc, argv, "iovh" ) ) != EOF )
4149     {
4150         switch ( c )
4151         {
4152         case 'i':
4153             fCleanupPis ^= 1;
4154             break;
4155         case 'o':
4156             fCleanupPos ^= 1;
4157             break;
4158         case 'v':
4159             fVerbose ^= 1;
4160             break;
4161         case 'h':
4162             goto usage;
4163         default:
4164             goto usage;
4165         }
4166     }
4167 
4168     if ( pNtk == NULL )
4169     {
4170         Abc_Print( -1, "Empty network.\n" );
4171         return 1;
4172     }
4173     if ( Abc_NtkIsStrash(pNtk) )
4174     {
4175         if ( !fCleanupPis && !fCleanupPos )
4176         {
4177             Abc_Print( -1, "Cleanup for PIs and POs is not enabled.\n" );
4178             pNtkRes = Abc_NtkDup( pNtk );
4179         }
4180         else
4181             pNtkRes = Abc_NtkDarCleanupAig( pNtk, fCleanupPis, fCleanupPos, fVerbose );
4182     }
4183     else
4184     {
4185         Abc_NtkCleanup( pNtk, fVerbose );
4186         pNtkRes = Abc_NtkDup( pNtk );
4187     }
4188     if ( pNtkRes == NULL )
4189     {
4190         Abc_Print( -1, "Cleanup has failed.\n" );
4191         return 1;
4192     }
4193     // replace the current network
4194     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
4195     return 0;
4196 
4197 usage:
4198     Abc_Print( -2, "usage: cleanup [-iovh]\n" );
4199     Abc_Print( -2, "\t        for logic networks, removes dangling combinatinal logic\n" );
4200     Abc_Print( -2, "\t        for AIGs, removes PIs w/o fanout and POs driven by const-0\n" );
4201     Abc_Print( -2, "\t-i    : toggles removing PIs without fanout [default = %s]\n", fCleanupPis? "yes": "no" );
4202     Abc_Print( -2, "\t-o    : toggles removing POs with const-0 drivers [default = %s]\n", fCleanupPos? "yes": "no" );
4203     Abc_Print( -2, "\t-v    : print verbose information [default = %s]\n", fVerbose? "yes": "no" );
4204     Abc_Print( -2, "\t-h    : print the command usage\n");
4205     return 1;
4206 }
4207 
4208 /**Function*************************************************************
4209 
4210   Synopsis    []
4211 
4212   Description []
4213 
4214   SideEffects []
4215 
4216   SeeAlso     []
4217 
4218 ***********************************************************************/
Abc_CommandSweep(Abc_Frame_t * pAbc,int argc,char ** argv)4219 int Abc_CommandSweep( Abc_Frame_t * pAbc, int argc, char ** argv )
4220 {
4221     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
4222     int c;
4223     int fSingle = 0;
4224     int fVerbose = 0;
4225 
4226     // set defaults
4227     Extra_UtilGetoptReset();
4228     while ( ( c = Extra_UtilGetopt( argc, argv, "svh" ) ) != EOF )
4229     {
4230         switch ( c )
4231         {
4232         case 's':
4233             fSingle ^= 1;
4234             break;
4235         case 'v':
4236             fVerbose ^= 1;
4237             break;
4238         case 'h':
4239             goto usage;
4240         default:
4241             goto usage;
4242         }
4243     }
4244 
4245     if ( pNtk == NULL )
4246     {
4247         Abc_Print( -1, "Empty network.\n" );
4248         return 1;
4249     }
4250     if ( !Abc_NtkIsLogic(pNtk) )
4251     {
4252         Abc_Print( -1, "The classical (SIS-like) sweep can only be performed on a logic network.\n" );
4253         return 1;
4254     }
4255     // modify the current network
4256     if ( fSingle )
4257         Abc_NtkSweepBufsInvs( pNtk, fVerbose );
4258     else
4259         Abc_NtkSweep( pNtk, fVerbose );
4260     return 0;
4261 
4262 usage:
4263     Abc_Print( -2, "usage: sweep [-svh]\n" );
4264     Abc_Print( -2, "\t        removes dangling nodes; propagates constant, buffers, inverters\n" );
4265     Abc_Print( -2, "\t-s    : toggle sweeping buffers/inverters only [default = %s]\n", fSingle? "yes": "no" );
4266     Abc_Print( -2, "\t-v    : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
4267     Abc_Print( -2, "\t-h    : print the command usage\n");
4268     return 1;
4269 }
4270 
4271 
4272 /**Function*************************************************************
4273 
4274   Synopsis    []
4275 
4276   Description []
4277 
4278   SideEffects []
4279 
4280   SeeAlso     []
4281 
4282 ***********************************************************************/
Abc_CommandFastExtract(Abc_Frame_t * pAbc,int argc,char ** argv)4283 int Abc_CommandFastExtract( Abc_Frame_t * pAbc, int argc, char ** argv )
4284 {
4285     extern int Abc_NtkFxPerform( Abc_Ntk_t * pNtk, int nNewNodesMax, int nLitCountMax, int fCanonDivs, int fVerbose, int fVeryVerbose );
4286     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
4287     Fxu_Data_t Params, * p = &Params;
4288     int c, fNewAlgo = 1;
4289     int nPairsLimit = 1000000000;
4290     // set the defaults
4291     Abc_NtkSetDefaultFxParams( p );
4292     Extra_UtilGetoptReset();
4293     while ( (c = Extra_UtilGetopt(argc, argv, "SDNWMPsdzcnxvwh")) != EOF )
4294     {
4295         switch (c)
4296         {
4297             case 'S':
4298                 if ( globalUtilOptind >= argc )
4299                 {
4300                     Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
4301                     goto usage;
4302                 }
4303                 p->nSingleMax = atoi(argv[globalUtilOptind]);
4304                 globalUtilOptind++;
4305                 if ( p->nSingleMax < 0 )
4306                     goto usage;
4307                 break;
4308             case 'D':
4309                 if ( globalUtilOptind >= argc )
4310                 {
4311                     Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
4312                     goto usage;
4313                 }
4314                 p->nPairsMax = atoi(argv[globalUtilOptind]);
4315                 globalUtilOptind++;
4316                 if ( p->nPairsMax < 0 )
4317                     goto usage;
4318                 break;
4319             case 'N':
4320                 if ( globalUtilOptind >= argc )
4321                 {
4322                     Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
4323                     goto usage;
4324                 }
4325                 p->nNodesExt = atoi(argv[globalUtilOptind]);
4326                 globalUtilOptind++;
4327                 if ( p->nNodesExt < 0 )
4328                     goto usage;
4329                 break;
4330             case 'W':
4331                 if ( globalUtilOptind >= argc )
4332                 {
4333                     Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
4334                     goto usage;
4335                 }
4336                 p->WeightMin = atoi(argv[globalUtilOptind]);
4337                 globalUtilOptind++;
4338                 if ( p->WeightMin < 0 )
4339                     goto usage;
4340                 break;
4341             case 'M':
4342                 if ( globalUtilOptind >= argc )
4343                 {
4344                     Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
4345                     goto usage;
4346                 }
4347                 p->LitCountMax = atoi(argv[globalUtilOptind]);
4348                 globalUtilOptind++;
4349                 if ( p->LitCountMax < 0 )
4350                     goto usage;
4351                 break;
4352             case 'P':
4353                 if ( globalUtilOptind >= argc )
4354                 {
4355                     Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
4356                     goto usage;
4357                 }
4358                 nPairsLimit = atoi(argv[globalUtilOptind]);
4359                 globalUtilOptind++;
4360                 if ( nPairsLimit < 0 )
4361                     goto usage;
4362                 break;
4363             case 's':
4364                 p->fOnlyS ^= 1;
4365                 break;
4366             case 'd':
4367                 p->fOnlyD ^= 1;
4368                 break;
4369             case 'z':
4370                 p->fUse0 ^= 1;
4371                 break;
4372             case 'c':
4373                 p->fUseCompl ^= 1;
4374                 break;
4375             case 'n':
4376                 fNewAlgo ^= 1;
4377                 break;
4378             case 'x':
4379                 p->fCanonDivs ^= 1;
4380                 break;
4381             case 'v':
4382                 p->fVerbose ^= 1;
4383                 break;
4384             case 'w':
4385                 p->fVeryVerbose ^= 1;
4386                 break;
4387             case 'h':
4388                 goto usage;
4389                 break;
4390             default:
4391                 goto usage;
4392         }
4393     }
4394     if ( pNtk == NULL )
4395     {
4396         Abc_Print( -1, "Empty network.\n" );
4397         return 1;
4398     }
4399     if ( Abc_NtkNodeNum(pNtk) == 0 || Abc_NtkPiNum(pNtk) == 0 )
4400     {
4401         Abc_Print( 0, "The network does not have internal nodes.\n" );
4402         return 0;
4403     }
4404     if ( !Abc_NtkIsLogic(pNtk) )
4405     {
4406         Abc_Print( -1, "Fast extract can only be applied to a logic network (run \"renode\" or \"if\").\n" );
4407         return 1;
4408     }
4409     if ( !Abc_NtkIsSopLogic(pNtk) )
4410     {
4411         Abc_Print( -1, "Fast extract can only be applied to a logic network with SOP local functions (run \"bdd; sop\").\n" );
4412         return 1;
4413     }
4414     if ( Abc_NtkGetCubePairNum(pNtk) > nPairsLimit )
4415     {
4416         Abc_Print( -1, "Cannot perform \"fx\" because the number cube pairs exceeds the limit (%d).\n", nPairsLimit );
4417         return 1;
4418     }
4419 
4420     // the nodes to be merged are linked into the special linked list
4421     if ( fNewAlgo )
4422         Abc_NtkFxPerform( pNtk, p->nNodesExt, p->LitCountMax, p->fCanonDivs, p->fVerbose, p->fVeryVerbose );
4423     else
4424         Abc_NtkFastExtract( pNtk, p );
4425     Abc_NtkFxuFreeInfo( p );
4426     return 0;
4427 
4428 usage:
4429     Abc_Print( -2, "usage: fx [-SDNWMP <num>] [-sdzcnxvwh]\n");
4430     Abc_Print( -2, "\t           performs unate fast extract on the current network\n");
4431     Abc_Print( -2, "\t-S <num> : max number of single-cube divisors to consider [default = %d]\n", p->nSingleMax );
4432     Abc_Print( -2, "\t-D <num> : max number of double-cube divisors to consider [default = %d]\n", p->nPairsMax );
4433     Abc_Print( -2, "\t-N <num> : max number of divisors to extract during this run [default = %d]\n", p->nNodesExt );
4434     Abc_Print( -2, "\t-W <num> : lower bound on the weight of divisors to extract [default = %d]\n", p->WeightMin );
4435     Abc_Print( -2, "\t-M <num> : upper bound on literal count of divisors to extract [default = %d]\n", p->LitCountMax );
4436     Abc_Print( -2, "\t-P <num> : skip \"fx\" if cube pair count exceeds this limit [default = %d]\n", nPairsLimit );
4437     Abc_Print( -2, "\t-s       : use only single-cube divisors [default = %s]\n", p->fOnlyS? "yes": "no" );
4438     Abc_Print( -2, "\t-d       : use only double-cube divisors [default = %s]\n", p->fOnlyD? "yes": "no" );
4439     Abc_Print( -2, "\t-z       : use zero-weight divisors [default = %s]\n", p->fUse0? "yes": "no" );
4440     Abc_Print( -2, "\t-c       : use complement in the binary case [default = %s]\n", p->fUseCompl? "yes": "no" );
4441     Abc_Print( -2, "\t-n       : use new implementation of fast extract [default = %s]\n", fNewAlgo? "yes": "no" );
4442     Abc_Print( -2, "\t-x       : use only canonical divisors (AND, XOR, MUX) [default = %s]\n", p->fCanonDivs? "yes": "no" );
4443     Abc_Print( -2, "\t-v       : print verbose information [default = %s]\n", p->fVerbose? "yes": "no" );
4444     Abc_Print( -2, "\t-w       : print additional information [default = %s]\n", p->fVeryVerbose? "yes": "no" );
4445     Abc_Print( -2, "\t-h       : print the command usage\n");
4446     return 1;
4447 }
4448 
4449 /**Function*************************************************************
4450 
4451   Synopsis    []
4452 
4453   Description []
4454 
4455   SideEffects []
4456 
4457   SeeAlso     []
4458 
4459 ***********************************************************************/
Abc_CommandFxch(Abc_Frame_t * pAbc,int argc,char ** argv)4460 static int Abc_CommandFxch( Abc_Frame_t * pAbc, int argc, char ** argv )
4461 {
4462     extern int Abc_NtkFxchPerform( Abc_Ntk_t * pNtk, int nMaxDivExt, int fVerbose, int fVeryVerbose );
4463     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
4464 
4465     int c,
4466         nMaxDivExt = 0,
4467         fVerbose = 0,
4468         fVeryVerbose = 0;
4469 
4470     Extra_UtilGetoptReset();
4471     while ( (c = Extra_UtilGetopt(argc, argv, "Nvwh")) != EOF )
4472     {
4473         switch (c)
4474         {
4475             case 'N':
4476                 if ( globalUtilOptind >= argc )
4477                 {
4478                     Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
4479                     goto usage;
4480                 }
4481                 nMaxDivExt = atoi( argv[globalUtilOptind] );
4482                 globalUtilOptind++;
4483 
4484                 if ( nMaxDivExt < 0 )
4485                     goto usage;
4486                 break;
4487 
4488             case 'v':
4489                 fVerbose ^= 1;
4490                 break;
4491 
4492             case 'w':
4493                 fVeryVerbose ^= 1;
4494                 break;
4495 
4496             case 'h':
4497                 goto usage;
4498                 break;
4499 
4500             default:
4501                 goto usage;
4502         }
4503     }
4504 
4505     if ( pNtk == NULL )
4506     {
4507         Abc_Print( -1, "Empty network.\n" );
4508         return 1;
4509     }
4510     if ( Abc_NtkNodeNum( pNtk ) == 0 )
4511     {
4512         Abc_Print( -1, "The network does not have internal nodes.\n" );
4513         return 1;
4514     }
4515     if ( !Abc_NtkIsLogic( pNtk ) )
4516     {
4517         Abc_Print( -1, "Fast extract can only be applied to a logic network (run \"renode\" or \"if\").\n" );
4518         return 1;
4519     }
4520     if ( !Abc_NtkIsSopLogic( pNtk ) )
4521     {
4522         Abc_Print( -1, "Fast extract can only be applied to a logic network with SOP local functions (run \"bdd; sop\").\n" );
4523         return 1;
4524     }
4525 
4526     Abc_NtkFxchPerform( pNtk, nMaxDivExt, fVerbose, fVeryVerbose );
4527 
4528     return 0;
4529 
4530 usage:
4531     Abc_Print( -2, "usage: fxch [-N <num>] [-svwh]\n");
4532     Abc_Print( -2, "\t           performs fast extract with cube hashing on the current network\n");
4533     Abc_Print( -2, "\t-N <num> : max number of divisors to extract during this run [default = unused]\n" );
4534     Abc_Print( -2, "\t-v       : print verbose information [default = %s]\n", fVerbose? "yes": "no" );
4535     Abc_Print( -2, "\t-w       : print additional information [default = %s]\n", fVeryVerbose? "yes": "no" );
4536     Abc_Print( -2, "\t-h       : print the command usage\n");
4537     Abc_Print( -2, "\t\n" );
4538     Abc_Print( -2, "\t           This command was contributed by Bruno Schmitt from UFRGS in May 2016.\n" );
4539     Abc_Print( -2, "\t           The author can be contacted as boschmitt at inf.ufrgs.br\n" );
4540     return 1;
4541 }
4542 
4543 /**Function*************************************************************
4544 
4545   Synopsis    []
4546 
4547   Description []
4548 
4549   SideEffects []
4550 
4551   SeeAlso     []
4552 
4553 ***********************************************************************/
Abc_CommandEliminate(Abc_Frame_t * pAbc,int argc,char ** argv)4554 int Abc_CommandEliminate( Abc_Frame_t * pAbc, int argc, char ** argv )
4555 {
4556     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
4557     int ElimValue;
4558     int nMaxSize;
4559     int nIterMax;
4560     int fGreedy;
4561     int fReverse;
4562     int fSpecial;
4563     int fVerbose;
4564     int c;
4565     extern int Abc_NtkEliminate( Abc_Ntk_t * pNtk, int nMaxSize, int fReverse, int fVerbose );
4566     extern int Abc_NtkEliminate1( Abc_Ntk_t * pNtk, int ElimValue, int nMaxSize, int nIterMax, int fReverse, int fVerbose );
4567     extern int Abc_NtkEliminateSpecial( Abc_Ntk_t * pNtk, int nMaxSize, int fVerbose );
4568 
4569     // set the defaults
4570     ElimValue = -1;
4571     nMaxSize  = 12;
4572     nIterMax  =  1;
4573     fGreedy   =  0;
4574     fReverse  =  0;
4575     fSpecial  =  0;
4576     fVerbose  =  0;
4577     Extra_UtilGetoptReset();
4578     while ( (c = Extra_UtilGetopt(argc, argv, "VNIgrsvh")) != EOF )
4579     {
4580         switch (c)
4581         {
4582             case 'V':
4583                 if ( globalUtilOptind >= argc )
4584                 {
4585                     Abc_Print( -1, "Command line switch \"-V\" should be followed by an integer that is -1 or larger.\n" );
4586                     goto usage;
4587                 }
4588                 ElimValue = atoi(argv[globalUtilOptind]);
4589                 globalUtilOptind++;
4590                 if ( ElimValue < -1 )
4591                     goto usage;
4592                 break;
4593             case 'N':
4594                 if ( globalUtilOptind >= argc )
4595                 {
4596                     Abc_Print( -1, "Command line switch \"-N\" should be followed by a positive integer.\n" );
4597                     goto usage;
4598                 }
4599                 nMaxSize = atoi(argv[globalUtilOptind]);
4600                 globalUtilOptind++;
4601                 if ( nMaxSize <= 0 )
4602                     goto usage;
4603                 break;
4604             case 'I':
4605                 if ( globalUtilOptind >= argc )
4606                 {
4607                     Abc_Print( -1, "Command line switch \"-I\" should be followed by a positive integer.\n" );
4608                     goto usage;
4609                 }
4610                 nIterMax = atoi(argv[globalUtilOptind]);
4611                 globalUtilOptind++;
4612                 if ( nIterMax <= 0 )
4613                     goto usage;
4614                 break;
4615             case 'g':
4616                 fGreedy ^= 1;
4617                 break;
4618             case 'r':
4619                 fReverse ^= 1;
4620                 break;
4621             case 's':
4622                 fSpecial ^= 1;
4623                 break;
4624             case 'v':
4625                 fVerbose ^= 1;
4626                 break;
4627             case 'h':
4628                 goto usage;
4629                 break;
4630             default:
4631                 goto usage;
4632         }
4633     }
4634 
4635     if ( pNtk == NULL )
4636     {
4637         Abc_Print( -1, "Empty network.\n" );
4638         return 1;
4639     }
4640 
4641     if ( Abc_NtkNodeNum(pNtk) == 0 )
4642     {
4643         Abc_Print( -1, "The network does not have internal nodes.\n" );
4644         return 1;
4645     }
4646 
4647     if ( !Abc_NtkIsLogic(pNtk) )
4648     {
4649         Abc_Print( -1, "This command can only be applied to a logic network (run \"renode\" or \"if\").\n" );
4650         return 1;
4651     }
4652 
4653     if ( fSpecial )
4654         Abc_NtkEliminateSpecial( pNtk, 1000, fVerbose );
4655     else if ( fGreedy )
4656         Abc_NtkEliminate( pNtk, nMaxSize, fReverse, fVerbose );
4657     else
4658         Abc_NtkEliminate1( pNtk, ElimValue, nMaxSize, nIterMax, fReverse, fVerbose );
4659     return 0;
4660 
4661 usage:
4662     Abc_Print( -2, "usage: eliminate [-VNI <num>] [-grsvh]\n");
4663     Abc_Print( -2, "\t           traditional \"eliminate -1\", which collapses the node into its fanout\n");
4664     Abc_Print( -2, "\t           if the node's variable appears in the fanout's factored form only once\n");
4665     Abc_Print( -2, "\t-V <num> : the \"value\" parameter used by \"eliminate\" in SIS [default = %d]\n", ElimValue );
4666     Abc_Print( -2, "\t-N <num> : the maximum node support after collapsing [default = %d]\n", nMaxSize );
4667     Abc_Print( -2, "\t-I <num> : the maximum number of iterations [default = %d]\n", nIterMax );
4668     Abc_Print( -2, "\t-g       : toggle using greedy eliminate (without \"value\") [default = %s]\n", fGreedy? "yes": "no" );
4669     Abc_Print( -2, "\t-r       : use the reverse topological order [default = %s]\n", fReverse? "yes": "no" );
4670     Abc_Print( -2, "\t-s       : toggle eliminating similar nodes [default = %s]\n", fSpecial? "yes": "no" );
4671     Abc_Print( -2, "\t-v       : print verbose information [default = %s]\n", fVerbose? "yes": "no" );
4672     Abc_Print( -2, "\t-h       : print the command usage\n");
4673     return 1;
4674 }
4675 
4676 /**Function*************************************************************
4677 
4678   Synopsis    []
4679 
4680   Description []
4681 
4682   SideEffects []
4683 
4684   SeeAlso     []
4685 
4686 ***********************************************************************/
Abc_CommandDisjoint(Abc_Frame_t * pAbc,int argc,char ** argv)4687 int Abc_CommandDisjoint( Abc_Frame_t * pAbc, int argc, char ** argv )
4688 {
4689     Abc_Ntk_t * pNtk, * pNtkRes, * pNtkNew;
4690     int fGlobal, fRecursive, fVerbose, fPrint, fShort, c;
4691 
4692     extern Abc_Ntk_t * Abc_NtkDsdGlobal( Abc_Ntk_t * pNtk, int fVerbose, int fPrint, int fShort );
4693     extern int         Abc_NtkDsdLocal( Abc_Ntk_t * pNtk, int fVerbose, int fRecursive );
4694 
4695     pNtk = Abc_FrameReadNtk(pAbc);
4696     // set defaults
4697     fGlobal    = 1;
4698     fRecursive = 0;
4699     fVerbose   = 0;
4700     fPrint     = 0;
4701     fShort     = 0;
4702     Extra_UtilGetoptReset();
4703     while ( ( c = Extra_UtilGetopt( argc, argv, "grvpsh" ) ) != EOF )
4704     {
4705         switch ( c )
4706         {
4707             case 'g':
4708                 fGlobal ^= 1;
4709                 break;
4710             case 'r':
4711                 fRecursive ^= 1;
4712                 break;
4713             case 'v':
4714                 fVerbose ^= 1;
4715                 break;
4716             case 'p':
4717                 fPrint ^= 1;
4718                 break;
4719             case 's':
4720                 fShort ^= 1;
4721                 break;
4722             case 'h':
4723                 goto usage;
4724                 break;
4725             default:
4726                 goto usage;
4727         }
4728     }
4729 
4730     if ( pNtk == NULL )
4731     {
4732         Abc_Print( -1, "Empty network.\n" );
4733         return 1;
4734     }
4735 
4736     if ( fGlobal )
4737     {
4738 //        Abc_Print( 0, "Performing DSD of global functions of the network.\n" );
4739         // get the new network
4740         if ( !Abc_NtkIsStrash(pNtk) )
4741         {
4742             pNtkNew = Abc_NtkStrash( pNtk, 0, 0, 0 );
4743             pNtkRes = Abc_NtkDsdGlobal( pNtkNew, fVerbose, fPrint, fShort );
4744             Abc_NtkDelete( pNtkNew );
4745         }
4746         else
4747         {
4748             pNtkRes = Abc_NtkDsdGlobal( pNtk, fVerbose, fPrint, fShort );
4749         }
4750         if ( pNtkRes == NULL )
4751         {
4752             Abc_Print( -1, "Global DSD has failed.\n" );
4753             return 1;
4754         }
4755         // replace the current network
4756         Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
4757     }
4758     else if ( fRecursive )
4759     {
4760         if ( !Abc_NtkIsBddLogic( pNtk ) )
4761         {
4762             Abc_Print( -1, "This command is only applicable to logic BDD networks.\n" );
4763             return 1;
4764         }
4765         if ( fVerbose )
4766             Abc_Print( 1, "Performing recursive DSD and MUX decomposition of local functions.\n" );
4767         if ( !Abc_NtkDsdLocal( pNtk, fVerbose, fRecursive ) )
4768             Abc_Print( -1, "Recursive DSD has failed.\n" );
4769     }
4770     else
4771     {
4772         if ( !Abc_NtkIsBddLogic( pNtk ) )
4773         {
4774             Abc_Print( -1, "This command is only applicable to logic BDD networks (run \"bdd\").\n" );
4775             return 1;
4776         }
4777         if ( fVerbose )
4778             Abc_Print( 1, "Performing simple non-recursive DSD of local functions.\n" );
4779         if ( !Abc_NtkDsdLocal( pNtk, fVerbose, fRecursive ) )
4780             Abc_Print( -1, "Simple DSD of local functions has failed.\n" );
4781     }
4782     return 0;
4783 
4784 usage:
4785     Abc_Print( -2, "usage: dsd [-grvpsh]\n" );
4786     Abc_Print( -2, "\t     decomposes the network using disjoint-support decomposition\n" );
4787     Abc_Print( -2, "\t-g     : toggle DSD of global and local functions [default = %s]\n", fGlobal? "global": "local" );
4788     Abc_Print( -2, "\t-r     : toggle recursive DSD/MUX and simple DSD [default = %s]\n", fRecursive? "recursive DSD/MUX": "simple DSD" );
4789     Abc_Print( -2, "\t-v     : prints DSD statistics and runtime [default = %s]\n", fVerbose? "yes": "no" );
4790     Abc_Print( -2, "\t-p     : prints DSD structure to the standard output [default = %s]\n", fPrint? "yes": "no" );
4791     Abc_Print( -2, "\t-s     : use short PI names when printing DSD structure [default = %s]\n", fShort? "yes": "no" );
4792     Abc_Print( -2, "\t-h     : print the command usage\n");
4793     return 1;
4794 }
4795 
4796 /**Function*************************************************************
4797 
4798   Synopsis    []
4799 
4800   Description []
4801 
4802   SideEffects []
4803 
4804   SeeAlso     []
4805 
4806 ***********************************************************************/
Abc_CommandSparsify(Abc_Frame_t * pAbc,int argc,char ** argv)4807 int Abc_CommandSparsify( Abc_Frame_t * pAbc, int argc, char ** argv )
4808 {
4809     extern Abc_Ntk_t * Abc_NtkSparsify( Abc_Ntk_t * pNtk, int nPerc, int fVerbose );
4810     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc), * pNtkNew;
4811     int nPerc, fVerbose, c;
4812     // set defaults
4813     nPerc      = 10;
4814     fVerbose   =  0;
4815     Extra_UtilGetoptReset();
4816     while ( ( c = Extra_UtilGetopt( argc, argv, "Nvh" ) ) != EOF )
4817     {
4818         switch ( c )
4819         {
4820             case 'N':
4821                 if ( globalUtilOptind >= argc )
4822                 {
4823                     Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
4824                     goto usage;
4825                 }
4826                 nPerc = atoi(argv[globalUtilOptind]);
4827                 globalUtilOptind++;
4828                 if ( nPerc < 1 || nPerc > 100 )
4829                     goto usage;
4830                 break;
4831             case 'v':
4832                 fVerbose ^= 1;
4833                 break;
4834             case 'h':
4835                 goto usage;
4836                 break;
4837             default:
4838                 goto usage;
4839         }
4840     }
4841 
4842     if ( pNtk == NULL )
4843     {
4844         Abc_Print( -1, "Empty network.\n" );
4845         return 1;
4846     }
4847     if ( !Abc_NtkIsBddLogic( pNtk ) )
4848     {
4849         Abc_Print( -1, "This command is only applicable to logic BDD networks (run \"bdd\").\n" );
4850         return 1;
4851     }
4852     if ( Abc_NtkCiNum(pNtk) > 16 )
4853     {
4854         Abc_Print( -1, "The number of primary inputs is more than 16.\n" );
4855         return 1;
4856     }
4857     pNtkNew = Abc_NtkSparsify( pNtk, nPerc, fVerbose );
4858     if ( pNtkNew == NULL )
4859     {
4860         Abc_Print( -1, "Command has failed.\n" );
4861         return 1;
4862     }
4863     // replace the current network
4864     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkNew );
4865     return 0;
4866 
4867 usage:
4868     Abc_Print( -2, "usage: sparsify [-N num] [-vh]\n" );
4869     Abc_Print( -2, "\t           creates incompletely-specified function\n" );
4870     Abc_Print( -2, "\t-N <num> : the percentage of on-set and off-set minterms (1 <= num <= 100) [default = %d]\n", nPerc );
4871     Abc_Print( -2, "\t-v       : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
4872     Abc_Print( -2, "\t-h       : print the command usage\n");
4873     return 1;
4874 }
4875 
4876 /**Function*************************************************************
4877 
4878   Synopsis    []
4879 
4880   Description []
4881 
4882   SideEffects []
4883 
4884   SeeAlso     []
4885 
4886 ***********************************************************************/
Abc_CommandLutpack(Abc_Frame_t * pAbc,int argc,char ** argv)4887 int Abc_CommandLutpack( Abc_Frame_t * pAbc, int argc, char ** argv )
4888 {
4889     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
4890     Lpk_Par_t Pars, * pPars = &Pars;
4891     int c;
4892 
4893     pNtk = Abc_FrameReadNtk(pAbc);
4894     // set defaults
4895     memset( pPars, 0, sizeof(Lpk_Par_t) );
4896     pPars->nLutsMax     =  4; // (N) the maximum number of LUTs in the structure
4897     pPars->nLutsOver    =  3; // (Q) the maximum number of LUTs not in the MFFC
4898     pPars->nVarsShared  =  0; // (S) the maximum number of shared variables (crossbars)
4899     pPars->nGrowthLevel =  0; // (L) the maximum number of increased levels
4900     pPars->fSatur       =  1;
4901     pPars->fZeroCost    =  0;
4902     pPars->fFirst       =  0;
4903     pPars->fOldAlgo     =  0;
4904     pPars->fVerbose     =  0;
4905     pPars->fVeryVerbose =  0;
4906     Extra_UtilGetoptReset();
4907     while ( ( c = Extra_UtilGetopt( argc, argv, "NQSLszfovwh" ) ) != EOF )
4908     {
4909         switch ( c )
4910         {
4911         case 'N':
4912             if ( globalUtilOptind >= argc )
4913             {
4914                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
4915                 goto usage;
4916             }
4917             pPars->nLutsMax = atoi(argv[globalUtilOptind]);
4918             globalUtilOptind++;
4919             if ( pPars->nLutsMax < 2 || pPars->nLutsMax > 16 )
4920                 goto usage;
4921             break;
4922         case 'Q':
4923             if ( globalUtilOptind >= argc )
4924             {
4925                 Abc_Print( -1, "Command line switch \"-Q\" should be followed by an integer.\n" );
4926                 goto usage;
4927             }
4928             pPars->nLutsOver = atoi(argv[globalUtilOptind]);
4929             globalUtilOptind++;
4930             if ( pPars->nLutsOver < 0 || pPars->nLutsOver > 8 )
4931                 goto usage;
4932             break;
4933         case 'S':
4934             if ( globalUtilOptind >= argc )
4935             {
4936                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
4937                 goto usage;
4938             }
4939             pPars->nVarsShared = atoi(argv[globalUtilOptind]);
4940             globalUtilOptind++;
4941             if ( pPars->nVarsShared < 0 || pPars->nVarsShared > 4 )
4942                 goto usage;
4943             break;
4944         case 'L':
4945             if ( globalUtilOptind >= argc )
4946             {
4947                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
4948                 goto usage;
4949             }
4950             pPars->nGrowthLevel = atoi(argv[globalUtilOptind]);
4951             globalUtilOptind++;
4952             if ( pPars->nGrowthLevel < 0 || pPars->nGrowthLevel > ABC_INFINITY )
4953                 goto usage;
4954             break;
4955         case 's':
4956             pPars->fSatur ^= 1;
4957             break;
4958         case 'z':
4959             pPars->fZeroCost ^= 1;
4960             break;
4961         case 'f':
4962             pPars->fFirst ^= 1;
4963             break;
4964         case 'o':
4965             pPars->fOldAlgo ^= 1;
4966             break;
4967         case 'v':
4968             pPars->fVerbose ^= 1;
4969             break;
4970         case 'w':
4971             pPars->fVeryVerbose ^= 1;
4972             break;
4973         case 'h':
4974             goto usage;
4975         default:
4976             goto usage;
4977         }
4978     }
4979 
4980     if ( pNtk == NULL )
4981     {
4982         Abc_Print( -1, "Empty network.\n" );
4983         return 1;
4984     }
4985     if ( !Abc_NtkIsLogic(pNtk) )
4986     {
4987         Abc_Print( -1, "This command can only be applied to a logic network.\n" );
4988         return 1;
4989     }
4990     if ( pPars->nVarsShared < 0 || pPars->nVarsShared > 3 )
4991     {
4992         Abc_Print( -1, "The number of shared variables (%d) is not in the range 0 <= S <= 3.\n", pPars->nVarsShared );
4993         return 1;
4994     }
4995 
4996     // modify the current network
4997     if ( !Lpk_Resynthesize( pNtk, pPars ) )
4998     {
4999         Abc_Print( -1, "Resynthesis has failed.\n" );
5000         return 1;
5001     }
5002     return 0;
5003 
5004 usage:
5005     Abc_Print( -2, "usage: lutpack [-NQSL <num>] [-szfovwh]\n" );
5006     Abc_Print( -2, "\t           performs \"rewriting\" for LUT network;\n" );
5007     Abc_Print( -2, "\t           determines LUT size as the max fanin count of a node;\n" );
5008     Abc_Print( -2, "\t           if the network is not LUT-mapped, packs it into 6-LUTs\n" );
5009     Abc_Print( -2, "\t           (there is another command for resynthesis after LUT mapping, \"mfs2\")\n" );
5010     Abc_Print( -2, "\t-N <num> : the max number of LUTs in the structure (2 <= num) [default = %d]\n", pPars->nLutsMax );
5011     Abc_Print( -2, "\t-Q <num> : the max number of LUTs not in MFFC (0 <= num) [default = %d]\n", pPars->nLutsOver );
5012     Abc_Print( -2, "\t-S <num> : the max number of LUT inputs shared (0 <= num <= 3) [default = %d]\n", pPars->nVarsShared );
5013     Abc_Print( -2, "\t-L <num> : max level increase after resynthesis (0 <= num) [default = %d]\n", pPars->nGrowthLevel );
5014     Abc_Print( -2, "\t-s       : toggle iteration till saturation [default = %s]\n", pPars->fSatur? "yes": "no" );
5015     Abc_Print( -2, "\t-z       : toggle zero-cost replacements [default = %s]\n", pPars->fZeroCost? "yes": "no" );
5016     Abc_Print( -2, "\t-f       : toggle using only first node and first cut [default = %s]\n", pPars->fFirst? "yes": "no" );
5017     Abc_Print( -2, "\t-o       : toggle using old implementation [default = %s]\n", pPars->fOldAlgo? "yes": "no" );
5018     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", pPars->fVerbose? "yes": "no" );
5019     Abc_Print( -2, "\t-w       : toggle detailed printout of decomposed functions [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
5020     Abc_Print( -2, "\t-h       : print the command usage\n");
5021     return 1;
5022 }
5023 
5024 /**Function*************************************************************
5025 
5026   Synopsis    []
5027 
5028   Description []
5029 
5030   SideEffects []
5031 
5032   SeeAlso     []
5033 
5034 ***********************************************************************/
Abc_CommandLutmin(Abc_Frame_t * pAbc,int argc,char ** argv)5035 int Abc_CommandLutmin( Abc_Frame_t * pAbc, int argc, char ** argv )
5036 {
5037     Abc_Ntk_t * pNtk, * pNtkRes;
5038     int c;
5039     int nLutSize;
5040     int fVerbose;
5041     extern Abc_Ntk_t * Abc_NtkLutmin( Abc_Ntk_t * pNtk, int nLutSize, int fVerbose );
5042 
5043     pNtk = Abc_FrameReadNtk(pAbc);
5044     // set defaults
5045     nLutSize = 4;
5046     fVerbose = 0;
5047     Extra_UtilGetoptReset();
5048     while ( ( c = Extra_UtilGetopt( argc, argv, "Kvh" ) ) != EOF )
5049     {
5050         switch ( c )
5051         {
5052         case 'K':
5053             if ( globalUtilOptind >= argc )
5054             {
5055                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
5056                 goto usage;
5057             }
5058             nLutSize = atoi(argv[globalUtilOptind]);
5059             globalUtilOptind++;
5060             break;
5061         case 'v':
5062             fVerbose ^= 1;
5063             break;
5064         case 'h':
5065             goto usage;
5066         default:
5067             goto usage;
5068         }
5069     }
5070     if ( pNtk == NULL )
5071     {
5072         Abc_Print( -1, "Empty network.\n" );
5073         return 1;
5074     }
5075     // modify the current network
5076     pNtkRes = Abc_NtkLutmin( pNtk, nLutSize, fVerbose );
5077     if ( pNtkRes == NULL )
5078     {
5079         Abc_Print( -1, "The command has failed.\n" );
5080         return 1;
5081     }
5082     // replace the current network
5083     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
5084     return 0;
5085 
5086 usage:
5087     Abc_Print( -2, "usage: lutmin [-K <num>] [-vh]\n" );
5088     Abc_Print( -2, "\t           perform FPGA mapping while minimizing the LUT count\n" );
5089     Abc_Print( -2, "\t           as described in the paper T. Sasao and A. Mishchenko:\n" );
5090     Abc_Print( -2, "\t           \"On the number of LUTs to implement logic functions\".\n" );
5091     Abc_Print( -2, "\t-K <num> : the LUT size to use for the mapping (2 <= num) [default = %d]\n", nLutSize );
5092     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
5093     Abc_Print( -2, "\t-h       : print the command usage\n");
5094     return 1;
5095 }
5096 
5097 #if 0
5098 
5099 /**Function*************************************************************
5100 
5101   Synopsis    []
5102 
5103   Description []
5104 
5105   SideEffects []
5106 
5107   SeeAlso     []
5108 
5109 ***********************************************************************/
5110 int Abc_CommandImfs( Abc_Frame_t * pAbc, int argc, char ** argv )
5111 {
5112     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
5113     Res_Par_t Pars, * pPars = &Pars;
5114     int c;
5115 
5116     // set defaults
5117     pPars->nWindow      = 62;
5118     pPars->nCands       =  5;
5119     pPars->nSimWords    =  4;
5120     pPars->nGrowthLevel =  0;
5121     pPars->fArea        =  0;
5122     pPars->fVerbose     =  0;
5123     pPars->fVeryVerbose =  0;
5124     Extra_UtilGetoptReset();
5125     while ( ( c = Extra_UtilGetopt( argc, argv, "WSCLavwh" ) ) != EOF )
5126     {
5127         switch ( c )
5128         {
5129         case 'W':
5130             if ( globalUtilOptind >= argc )
5131             {
5132                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
5133                 goto usage;
5134             }
5135             pPars->nWindow = atoi(argv[globalUtilOptind]);
5136             globalUtilOptind++;
5137             if ( pPars->nWindow < 1 || pPars->nWindow > 99 )
5138                 goto usage;
5139             break;
5140         case 'S':
5141             if ( globalUtilOptind >= argc )
5142             {
5143                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
5144                 goto usage;
5145             }
5146             pPars->nSimWords = atoi(argv[globalUtilOptind]);
5147             globalUtilOptind++;
5148             if ( pPars->nSimWords < 1 || pPars->nSimWords > 256 )
5149                 goto usage;
5150             break;
5151         case 'C':
5152             if ( globalUtilOptind >= argc )
5153             {
5154                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
5155                 goto usage;
5156             }
5157             pPars->nCands = atoi(argv[globalUtilOptind]);
5158             globalUtilOptind++;
5159             if ( pPars->nCands < 0 || pPars->nCands > ABC_INFINITY )
5160                 goto usage;
5161             break;
5162         case 'L':
5163             if ( globalUtilOptind >= argc )
5164             {
5165                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
5166                 goto usage;
5167             }
5168             pPars->nGrowthLevel = atoi(argv[globalUtilOptind]);
5169             globalUtilOptind++;
5170             if ( pPars->nGrowthLevel < 0 || pPars->nGrowthLevel > ABC_INFINITY )
5171                 goto usage;
5172             break;
5173         case 'a':
5174             pPars->fArea ^= 1;
5175             break;
5176         case 'v':
5177             pPars->fVerbose ^= 1;
5178             break;
5179         case 'w':
5180             pPars->fVeryVerbose ^= 1;
5181             break;
5182         case 'h':
5183             goto usage;
5184         default:
5185             goto usage;
5186         }
5187     }
5188 
5189     if ( pNtk == NULL )
5190     {
5191         Abc_Print( -1, "Empty network.\n" );
5192         return 1;
5193     }
5194     if ( !Abc_NtkIsLogic(pNtk) )
5195     {
5196         Abc_Print( -1, "This command can only be applied to a logic network.\n" );
5197         return 1;
5198     }
5199 
5200     // modify the current network
5201     if ( !Abc_NtkResynthesize( pNtk, pPars ) )
5202     {
5203         Abc_Print( -1, "Resynthesis has failed.\n" );
5204         return 1;
5205     }
5206     return 0;
5207 
5208 usage:
5209     Abc_Print( -2, "usage: imfs [-W <NM>] [-LCS <num>] [-avwh]\n" );
5210     Abc_Print( -2, "\t           performs resubstitution-based resynthesis with interpolation\n" );
5211     Abc_Print( -2, "\t           (there is another command for resynthesis after LUT mapping, \"lutpack\")\n" );
5212     Abc_Print( -2, "\t-W <NM>  : fanin/fanout levels (NxM) of the window (00 <= NM <= 99) [default = %d%d]\n", pPars->nWindow/10, pPars->nWindow%10 );
5213     Abc_Print( -2, "\t-C <num> : the max number of resub candidates (1 <= n) [default = %d]\n", pPars->nCands );
5214     Abc_Print( -2, "\t-S <num> : the number of simulation words (1 <= n <= 256) [default = %d]\n", pPars->nSimWords );
5215     Abc_Print( -2, "\t-L <num> : the max increase in node level after resynthesis (0 <= num) [default = %d]\n", pPars->nGrowthLevel );
5216     Abc_Print( -2, "\t-a       : toggle optimization for area only [default = %s]\n", pPars->fArea? "yes": "no" );
5217     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", pPars->fVerbose? "yes": "no" );
5218     Abc_Print( -2, "\t-w       : toggle printout subgraph statistics [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
5219     Abc_Print( -2, "\t-h       : print the command usage\n");
5220     return 1;
5221 }
5222 
5223 #endif
5224 
5225 /**Function*************************************************************
5226 
5227   Synopsis    []
5228 
5229   Description []
5230 
5231   SideEffects []
5232 
5233   SeeAlso     []
5234 
5235 ***********************************************************************/
Abc_CommandMfs(Abc_Frame_t * pAbc,int argc,char ** argv)5236 int Abc_CommandMfs( Abc_Frame_t * pAbc, int argc, char ** argv )
5237 {
5238     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
5239     Mfs_Par_t Pars, * pPars = &Pars;
5240     int c;
5241     // set defaults
5242     Abc_NtkMfsParsDefault( pPars );
5243     Extra_UtilGetoptReset();
5244     while ( ( c = Extra_UtilGetopt( argc, argv, "WFDMLCdraestpgvwh" ) ) != EOF )
5245     {
5246         switch ( c )
5247         {
5248         case 'W':
5249             if ( globalUtilOptind >= argc )
5250             {
5251                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
5252                 goto usage;
5253             }
5254             pPars->nWinTfoLevs = atoi(argv[globalUtilOptind]);
5255             globalUtilOptind++;
5256             if ( pPars->nWinTfoLevs < 0 )
5257                 goto usage;
5258             break;
5259         case 'F':
5260             if ( globalUtilOptind >= argc )
5261             {
5262                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
5263                 goto usage;
5264             }
5265             pPars->nFanoutsMax = atoi(argv[globalUtilOptind]);
5266             globalUtilOptind++;
5267             if ( pPars->nFanoutsMax < 0 )
5268                 goto usage;
5269             break;
5270         case 'D':
5271             if ( globalUtilOptind >= argc )
5272             {
5273                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
5274                 goto usage;
5275             }
5276             pPars->nDepthMax = atoi(argv[globalUtilOptind]);
5277             globalUtilOptind++;
5278             if ( pPars->nDepthMax < 0 )
5279                 goto usage;
5280             break;
5281         case 'M':
5282             if ( globalUtilOptind >= argc )
5283             {
5284                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
5285                 goto usage;
5286             }
5287             pPars->nWinMax = atoi(argv[globalUtilOptind]);
5288             globalUtilOptind++;
5289             if ( pPars->nWinMax < 0 )
5290                 goto usage;
5291             break;
5292         case 'L':
5293             if ( globalUtilOptind >= argc )
5294             {
5295                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
5296                 goto usage;
5297             }
5298             pPars->nGrowthLevel = atoi(argv[globalUtilOptind]);
5299             globalUtilOptind++;
5300             if ( pPars->nGrowthLevel < 0 || pPars->nGrowthLevel > ABC_INFINITY )
5301                 goto usage;
5302             break;
5303         case 'C':
5304             if ( globalUtilOptind >= argc )
5305             {
5306                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
5307                 goto usage;
5308             }
5309             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
5310             globalUtilOptind++;
5311             if ( pPars->nBTLimit < 0 )
5312                 goto usage;
5313             break;
5314         case 'd':
5315             pPars->fRrOnly ^= 1;
5316             break;
5317         case 'r':
5318             pPars->fResub ^= 1;
5319             break;
5320         case 'a':
5321             pPars->fArea ^= 1;
5322             break;
5323         case 'e':
5324             pPars->fMoreEffort ^= 1;
5325             break;
5326         case 's':
5327             pPars->fSwapEdge ^= 1;
5328             break;
5329         case 't':
5330             pPars->fOneHotness ^= 1;
5331             break;
5332         case 'p':
5333             pPars->fPower ^= 1;
5334             break;
5335         case 'g':
5336             pPars->fGiaSat ^= 1;
5337             break;
5338         case 'v':
5339             pPars->fVerbose ^= 1;
5340             break;
5341         case 'w':
5342             pPars->fVeryVerbose ^= 1;
5343             break;
5344         case 'h':
5345             goto usage;
5346         default:
5347             goto usage;
5348         }
5349     }
5350 
5351     if ( pNtk == NULL )
5352     {
5353         Abc_Print( -1, "Empty network.\n" );
5354         return 1;
5355     }
5356     if ( !Abc_NtkIsLogic(pNtk) )
5357     {
5358         Abc_Print( -1, "This command can only be applied to a logic network.\n" );
5359         return 1;
5360     }
5361 
5362     // modify the current network
5363     if ( !Abc_NtkMfs( pNtk, pPars ) )
5364     {
5365         Abc_Print( -1, "Resynthesis has failed.\n" );
5366         return 1;
5367     }
5368     return 0;
5369 
5370 usage:
5371     Abc_Print( -2, "usage: mfs [-WFDMLC <num>] [-draestpgvh]\n" );
5372     Abc_Print( -2, "\t           performs don't-care-based optimization of logic networks\n" );
5373     Abc_Print( -2, "\t-W <num> : the number of levels in the TFO cone (0 <= num) [default = %d]\n", pPars->nWinTfoLevs );
5374     Abc_Print( -2, "\t-F <num> : the max number of fanouts to skip (1 <= num) [default = %d]\n", pPars->nFanoutsMax );
5375     Abc_Print( -2, "\t-D <num> : the max depth nodes to try (0 = no limit) [default = %d]\n", pPars->nDepthMax );
5376     Abc_Print( -2, "\t-M <num> : the max node count of windows to consider (0 = no limit) [default = %d]\n", pPars->nWinMax );
5377     Abc_Print( -2, "\t-L <num> : the max increase in node level after resynthesis (0 <= num) [default = %d]\n", pPars->nGrowthLevel );
5378     Abc_Print( -2, "\t-C <num> : the max number of conflicts in one SAT run (0 = no limit) [default = %d]\n", pPars->nBTLimit );
5379     Abc_Print( -2, "\t-d       : toggle performing redundancy removal [default = %s]\n", pPars->fRrOnly? "yes": "no" );
5380     Abc_Print( -2, "\t-r       : toggle resubstitution and dc-minimization [default = %s]\n", pPars->fResub? "resub": "dc-min" );
5381     Abc_Print( -2, "\t-a       : toggle minimizing area or area+edges [default = %s]\n", pPars->fArea? "area": "area+edges" );
5382     Abc_Print( -2, "\t-e       : toggle high-effort resubstitution [default = %s]\n", pPars->fMoreEffort? "yes": "no" );
5383     Abc_Print( -2, "\t-s       : toggle evaluation of edge swapping [default = %s]\n", pPars->fSwapEdge? "yes": "no" );
5384     Abc_Print( -2, "\t-t       : toggle using artificial one-hotness conditions [default = %s]\n", pPars->fOneHotness? "yes": "no" );
5385     Abc_Print( -2, "\t-p       : toggle power-aware optimization [default = %s]\n", pPars->fPower? "yes": "no" );
5386     Abc_Print( -2, "\t-g       : toggle using new SAT solver [default = %s]\n", pPars->fGiaSat? "yes": "no" );
5387     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n", pPars->fVerbose? "yes": "no" );
5388     Abc_Print( -2, "\t-w       : toggle printing detailed stats for each node [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
5389     Abc_Print( -2, "\t-h       : print the command usage\n");
5390     return 1;
5391 }
5392 
5393 /**Function*************************************************************
5394 
5395   Synopsis    []
5396 
5397   Description []
5398 
5399   SideEffects []
5400 
5401   SeeAlso     []
5402 
5403 ***********************************************************************/
Abc_CommandMfs2(Abc_Frame_t * pAbc,int argc,char ** argv)5404 int Abc_CommandMfs2( Abc_Frame_t * pAbc, int argc, char ** argv )
5405 {
5406     extern int Abc_NtkPerformMfs( Abc_Ntk_t * pNtk, Sfm_Par_t * pPars );
5407     extern int Abc_NtkMfsAfterICheck( Abc_Ntk_t * p, int nFrames, int nFramesAdd, Vec_Int_t * vFlops, Sfm_Par_t * pPars );
5408     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
5409     Sfm_Par_t Pars, * pPars = &Pars;
5410     int c, fIndDCs = 0, fUseAllFfs = 0, nFramesAdd = 0;
5411     // set defaults
5412     Sfm_ParSetDefault( pPars );
5413     Extra_UtilGetoptReset();
5414     while ( ( c = Extra_UtilGetopt( argc, argv, "WFDMLCZNIdaeijvwh" ) ) != EOF )
5415     {
5416         switch ( c )
5417         {
5418         case 'W':
5419             if ( globalUtilOptind >= argc )
5420             {
5421                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
5422                 goto usage;
5423             }
5424             pPars->nTfoLevMax = atoi(argv[globalUtilOptind]);
5425             globalUtilOptind++;
5426             if ( pPars->nTfoLevMax < 0 )
5427                 goto usage;
5428             break;
5429         case 'F':
5430             if ( globalUtilOptind >= argc )
5431             {
5432                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
5433                 goto usage;
5434             }
5435             pPars->nFanoutMax = atoi(argv[globalUtilOptind]);
5436             globalUtilOptind++;
5437             if ( pPars->nFanoutMax < 0 )
5438                 goto usage;
5439             break;
5440         case 'D':
5441             if ( globalUtilOptind >= argc )
5442             {
5443                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
5444                 goto usage;
5445             }
5446             pPars->nDepthMax = atoi(argv[globalUtilOptind]);
5447             globalUtilOptind++;
5448             if ( pPars->nDepthMax < 0 )
5449                 goto usage;
5450             break;
5451         case 'M':
5452             if ( globalUtilOptind >= argc )
5453             {
5454                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
5455                 goto usage;
5456             }
5457             pPars->nWinSizeMax = atoi(argv[globalUtilOptind]);
5458             globalUtilOptind++;
5459             if ( pPars->nWinSizeMax < 0 )
5460                 goto usage;
5461             break;
5462         case 'L':
5463             if ( globalUtilOptind >= argc )
5464             {
5465                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
5466                 goto usage;
5467             }
5468             pPars->nGrowthLevel = atoi(argv[globalUtilOptind]);
5469             globalUtilOptind++;
5470             if ( pPars->nGrowthLevel < -ABC_INFINITY || pPars->nGrowthLevel > ABC_INFINITY )
5471                 goto usage;
5472             break;
5473         case 'C':
5474             if ( globalUtilOptind >= argc )
5475             {
5476                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
5477                 goto usage;
5478             }
5479             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
5480             globalUtilOptind++;
5481             if ( pPars->nBTLimit < 0 )
5482                 goto usage;
5483             break;
5484         case 'Z':
5485             if ( globalUtilOptind >= argc )
5486             {
5487                 Abc_Print( -1, "Command line switch \"-Z\" should be followed by an integer.\n" );
5488                 goto usage;
5489             }
5490             pPars->nFirstFixed = atoi(argv[globalUtilOptind]);
5491             globalUtilOptind++;
5492             if ( pPars->nFirstFixed < 0 )
5493                 goto usage;
5494             break;
5495         case 'N':
5496             if ( globalUtilOptind >= argc )
5497             {
5498                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
5499                 goto usage;
5500             }
5501             pPars->nNodesMax = atoi(argv[globalUtilOptind]);
5502             globalUtilOptind++;
5503             if ( pPars->nNodesMax < 0 )
5504                 goto usage;
5505             break;
5506         case 'I':
5507             if ( globalUtilOptind >= argc )
5508             {
5509                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
5510                 goto usage;
5511             }
5512             nFramesAdd = atoi(argv[globalUtilOptind]);
5513             globalUtilOptind++;
5514             if ( nFramesAdd < 0 )
5515                 goto usage;
5516             break;
5517         case 'd':
5518             pPars->fRrOnly ^= 1;
5519             break;
5520         case 'a':
5521             pPars->fArea ^= 1;
5522             break;
5523         case 'e':
5524             pPars->fMoreEffort ^= 1;
5525             break;
5526         case 'i':
5527             fIndDCs ^= 1;
5528             break;
5529         case 'j':
5530             fUseAllFfs ^= 1;
5531             break;
5532         case 'v':
5533             pPars->fVerbose ^= 1;
5534             break;
5535         case 'w':
5536             pPars->fVeryVerbose ^= 1;
5537             break;
5538         case 'h':
5539             goto usage;
5540         default:
5541             goto usage;
5542         }
5543     }
5544     if ( pNtk == NULL )
5545     {
5546         Abc_Print( -1, "Empty network.\n" );
5547         return 1;
5548     }
5549     if ( !Abc_NtkIsLogic(pNtk) )
5550     {
5551         Abc_Print( -1, "This command can only be applied to a logic network.\n" );
5552         return 1;
5553     }
5554     if ( fIndDCs )
5555     {
5556         if ( fUseAllFfs )
5557         {
5558             pAbc->nIndFrames = 1;
5559             Vec_IntFreeP( &pAbc->vIndFlops );
5560             pAbc->vIndFlops = Vec_IntAlloc( Abc_NtkLatchNum(pNtk) );
5561             Vec_IntFill( pAbc->vIndFlops, Abc_NtkLatchNum(pNtk), 1 );
5562         }
5563         if ( pAbc->nIndFrames <= 0 )
5564         {
5565             Abc_Print( -1, "The number of k-inductive frames is not specified.\n" );
5566             return 0;
5567         }
5568         if ( pAbc->vIndFlops == NULL )
5569         {
5570             Abc_Print( -1, "The set of k-inductive flops is not specified.\n" );
5571             return 0;
5572         }
5573         if ( Vec_IntSize(pAbc->vIndFlops) != Abc_NtkLatchNum(pNtk) )
5574         {
5575             Abc_Print( -1, "The saved flop count (%d) does not match that of the current network (%d).\n",
5576                 Vec_IntSize(pAbc->vIndFlops), Abc_NtkLatchNum(pNtk) );
5577             return 0;
5578         }
5579         // modify the current network
5580         if ( !Abc_NtkMfsAfterICheck( pNtk, pAbc->nIndFrames, nFramesAdd, pAbc->vIndFlops, pPars ) )
5581         {
5582             Abc_Print( -1, "Resynthesis has failed.\n" );
5583             return 1;
5584         }
5585         if ( fUseAllFfs )
5586         {
5587             pAbc->nIndFrames = 0;
5588             Vec_IntFreeP( &pAbc->vIndFlops );
5589         }
5590     }
5591     else
5592     {
5593         // modify the current network
5594         if ( !Abc_NtkPerformMfs( pNtk, pPars ) )
5595         {
5596             Abc_Print( -1, "Resynthesis has failed.\n" );
5597             return 1;
5598         }
5599     }
5600     return 0;
5601 
5602 usage:
5603     Abc_Print( -2, "usage: mfs2 [-WFDMLCZNI <num>] [-daeijvwh]\n" );
5604     Abc_Print( -2, "\t           performs don't-care-based optimization of logic networks\n" );
5605     Abc_Print( -2, "\t-W <num> : the number of levels in the TFO cone (0 <= num) [default = %d]\n",             pPars->nTfoLevMax );
5606     Abc_Print( -2, "\t-F <num> : the max number of fanouts to skip (1 <= num) [default = %d]\n",                pPars->nFanoutMax );
5607     Abc_Print( -2, "\t-D <num> : the max depth nodes to try (0 = no limit) [default = %d]\n",                   pPars->nDepthMax );
5608     Abc_Print( -2, "\t-M <num> : the max node count of windows to consider (0 = no limit) [default = %d]\n",    pPars->nWinSizeMax );
5609     Abc_Print( -2, "\t-L <num> : the max increase in node level after resynthesis (0 <= num) [default = %d]\n", pPars->nGrowthLevel );
5610     Abc_Print( -2, "\t-C <num> : the max number of conflicts in one SAT run (0 = no limit) [default = %d]\n",   pPars->nBTLimit );
5611     Abc_Print( -2, "\t-Z <num> : treat the first <num> logic nodes as fixed (0 = none) [default = %d]\n",       pPars->nFirstFixed );
5612     Abc_Print( -2, "\t-N <num> : the max number of nodes to try (0 = all) [default = %d]\n",                    pPars->nNodesMax );
5613     Abc_Print( -2, "\t-d       : toggle performing redundancy removal [default = %s]\n",                        pPars->fRrOnly? "yes": "no" );
5614     Abc_Print( -2, "\t-a       : toggle minimizing area or area+edges [default = %s]\n",                        pPars->fArea? "area": "area+edges" );
5615     Abc_Print( -2, "\t-e       : toggle high-effort resubstitution [default = %s]\n",                           pPars->fMoreEffort? "yes": "no" );
5616     Abc_Print( -2, "\t-i       : toggle using inductive don't-cares [default = %s]\n",                          fIndDCs? "yes": "no" );
5617     Abc_Print( -2, "\t-j       : toggle using all flops when \"-i\" is enabled [default = %s]\n",               fUseAllFfs? "yes": "no" );
5618     Abc_Print( -2, "\t-I       : the number of additional frames inserted [default = %d]\n",                    nFramesAdd );
5619     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n",                        pPars->fVerbose? "yes": "no" );
5620     Abc_Print( -2, "\t-w       : toggle printing detailed stats for each node [default = %s]\n",                pPars->fVeryVerbose? "yes": "no" );
5621     Abc_Print( -2, "\t-h       : print the command usage\n");
5622     return 1;
5623 }
5624 
5625 /**Function*************************************************************
5626 
5627   Synopsis    []
5628 
5629   Description []
5630 
5631   SideEffects []
5632 
5633   SeeAlso     []
5634 
5635 ***********************************************************************/
Abc_CommandMfs3(Abc_Frame_t * pAbc,int argc,char ** argv)5636 int Abc_CommandMfs3( Abc_Frame_t * pAbc, int argc, char ** argv )
5637 {
5638     extern void Abc_NtkPerformMfs3( Abc_Ntk_t * pNtk, Sfm_Par_t * pPars );
5639     extern void Sfm_ParSetDefault3( Sfm_Par_t * pPars );
5640     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
5641     Sfm_Par_t Pars, * pPars = &Pars; int c;
5642     // set defaults
5643     Sfm_ParSetDefault3( pPars );
5644     Extra_UtilGetoptReset();
5645     while ( ( c = Extra_UtilGetopt( argc, argv, "IOVFKLHRMCNPWDEarmzoespdlvwh" ) ) != EOF )
5646     {
5647         switch ( c )
5648         {
5649         case 'I':
5650             if ( globalUtilOptind >= argc )
5651             {
5652                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
5653                 goto usage;
5654             }
5655             pPars->nTfiLevMax = atoi(argv[globalUtilOptind]);
5656             globalUtilOptind++;
5657             if ( pPars->nTfiLevMax < 1 )
5658             {
5659                 Abc_Print( -1, "The number of TFI levels (switch \"-I\") should be at least 1.\n" );
5660                 goto usage;
5661             }
5662             break;
5663         case 'O':
5664             if ( globalUtilOptind >= argc )
5665             {
5666                 Abc_Print( -1, "Command line switch \"-O\" should be followed by an integer.\n" );
5667                 goto usage;
5668             }
5669             pPars->nTfoLevMax = atoi(argv[globalUtilOptind]);
5670             globalUtilOptind++;
5671             if ( pPars->nTfoLevMax < 0 )
5672                 goto usage;
5673             break;
5674         case 'V':
5675             if ( globalUtilOptind >= argc )
5676             {
5677                 Abc_Print( -1, "Command line switch \"-V\" should be followed by an integer.\n" );
5678                 goto usage;
5679             }
5680             pPars->nTfiLevMax = pPars->nTfoLevMax = atoi(argv[globalUtilOptind]);
5681             globalUtilOptind++;
5682             if ( pPars->nTfiLevMax < 1 )
5683                 goto usage;
5684             break;
5685         case 'F':
5686             if ( globalUtilOptind >= argc )
5687             {
5688                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
5689                 goto usage;
5690             }
5691             pPars->nFanoutMax = atoi(argv[globalUtilOptind]);
5692             globalUtilOptind++;
5693             if ( pPars->nFanoutMax < 0 )
5694                 goto usage;
5695             break;
5696         case 'K':
5697             if ( globalUtilOptind >= argc )
5698             {
5699                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
5700                 goto usage;
5701             }
5702             pPars->nVarMax = atoi(argv[globalUtilOptind]);
5703             globalUtilOptind++;
5704             if ( pPars->nVarMax < 2 || pPars->nVarMax > 8 )
5705                 goto usage;
5706             break;
5707         case 'L':
5708             if ( globalUtilOptind >= argc )
5709             {
5710                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
5711                 goto usage;
5712             }
5713             pPars->nMffcMin = atoi(argv[globalUtilOptind]);
5714             globalUtilOptind++;
5715             if ( pPars->nMffcMin < 0 )
5716                 goto usage;
5717             break;
5718         case 'H':
5719             if ( globalUtilOptind >= argc )
5720             {
5721                 Abc_Print( -1, "Command line switch \"-H\" should be followed by an integer.\n" );
5722                 goto usage;
5723             }
5724             pPars->nMffcMax = atoi(argv[globalUtilOptind]);
5725             globalUtilOptind++;
5726             if ( pPars->nMffcMax < 0 )
5727                 goto usage;
5728             break;
5729         case 'R':
5730             if ( globalUtilOptind >= argc )
5731             {
5732                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
5733                 goto usage;
5734             }
5735             pPars->nDecMax = atoi(argv[globalUtilOptind]);
5736             globalUtilOptind++;
5737             if ( pPars->nDecMax < 0 )
5738                 goto usage;
5739             break;
5740         case 'M':
5741             if ( globalUtilOptind >= argc )
5742             {
5743                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
5744                 goto usage;
5745             }
5746             pPars->nWinSizeMax = atoi(argv[globalUtilOptind]);
5747             globalUtilOptind++;
5748             if ( pPars->nWinSizeMax < 0 )
5749                 goto usage;
5750             break;
5751         case 'C':
5752             if ( globalUtilOptind >= argc )
5753             {
5754                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
5755                 goto usage;
5756             }
5757             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
5758             globalUtilOptind++;
5759             if ( pPars->nBTLimit < 0 )
5760                 goto usage;
5761             break;
5762         case 'N':
5763             if ( globalUtilOptind >= argc )
5764             {
5765                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
5766                 goto usage;
5767             }
5768             pPars->nNodesMax = atoi(argv[globalUtilOptind]);
5769             globalUtilOptind++;
5770             if ( pPars->nNodesMax < 0 )
5771                 goto usage;
5772             break;
5773         case 'P':
5774             if ( globalUtilOptind >= argc )
5775             {
5776                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
5777                 goto usage;
5778             }
5779             pPars->iNodeOne = atoi(argv[globalUtilOptind]);
5780             globalUtilOptind++;
5781             if ( pPars->iNodeOne < 0 )
5782                 goto usage;
5783             break;
5784         case 'W':
5785             if ( globalUtilOptind >= argc )
5786             {
5787                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
5788                 goto usage;
5789             }
5790             pPars->nTimeWin = atoi(argv[globalUtilOptind]);
5791             globalUtilOptind++;
5792             if ( pPars->nTimeWin < 0 || pPars->nTimeWin > 100 )
5793                 goto usage;
5794             break;
5795         case 'D':
5796             if ( globalUtilOptind >= argc )
5797             {
5798                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
5799                 goto usage;
5800             }
5801             pPars->DeltaCrit = atoi(argv[globalUtilOptind]);
5802             globalUtilOptind++;
5803             if ( pPars->DeltaCrit < 0 )
5804                 goto usage;
5805             break;
5806         case 'E':
5807             if ( globalUtilOptind >= argc )
5808             {
5809                 Abc_Print( -1, "Command line switch \"-E\" should be followed by an integer.\n" );
5810                 goto usage;
5811             }
5812             pPars->DelAreaRatio = atoi(argv[globalUtilOptind]);
5813             globalUtilOptind++;
5814             if ( pPars->DelAreaRatio < 0 )
5815                 goto usage;
5816             break;
5817         case 'a':
5818             pPars->fArea ^= 1;
5819             break;
5820         case 'r':
5821             pPars->fAreaRev ^= 1;
5822             break;
5823         case 'm':
5824             pPars->fUseAndOr ^= 1;
5825             break;
5826         case 'z':
5827             pPars->fZeroCost ^= 1;
5828             break;
5829         case 'o':
5830             pPars->fRrOnly ^= 1;
5831             break;
5832         case 'e':
5833             pPars->fMoreEffort ^= 1;
5834             break;
5835         case 's':
5836             pPars->fUseSim ^= 1;
5837             break;
5838         case 'p':
5839             pPars->fPrintDecs ^= 1;
5840             break;
5841         case 'd':
5842             pPars->fDelayVerbose ^= 1;
5843             break;
5844         case 'l':
5845             pPars->fLibVerbose ^= 1;
5846             break;
5847         case 'v':
5848             pPars->fVerbose ^= 1;
5849             break;
5850         case 'w':
5851             pPars->fVeryVerbose ^= 1;
5852             break;
5853         case 'h':
5854             goto usage;
5855         default:
5856             goto usage;
5857         }
5858     }
5859     if ( pNtk == NULL )
5860     {
5861         Abc_Print( -1, "Empty network.\n" );
5862         return 1;
5863     }
5864     if ( !Abc_NtkIsMappedLogic(pNtk) )
5865     {
5866         Abc_Print( -1, "This command can only be applied to a mapped logic network.\n" );
5867         return 1;
5868     }
5869     // modify the current network
5870     Abc_NtkPerformMfs3( pNtk, pPars );
5871     return 0;
5872 
5873 usage:
5874     Abc_Print( -2, "usage: mfs3 [-IOVFKLHRMCNPWDE <num>] [-armzespdlvwh]\n" );
5875     Abc_Print( -2, "\t           performs don't-care-based optimization of mapped networks\n" );
5876     Abc_Print( -2, "\t-I <num> : the number of levels in the TFI cone (1 <= num) [default = %d]\n",             pPars->nTfiLevMax );
5877     Abc_Print( -2, "\t-O <num> : the number of levels in the TFO cone (0 <= num) [default = %d]\n",             pPars->nTfoLevMax );
5878     Abc_Print( -2, "\t-V <num> : the number of levels in the TFI/TFO cone (1 <= num) [default = %d]\n",         pPars->nTfiLevMax );
5879     Abc_Print( -2, "\t-F <num> : the max number of fanouts to skip (1 <= num) [default = %d]\n",                pPars->nFanoutMax );
5880     Abc_Print( -2, "\t-K <num> : the max number of variables (2 <= num <= 8 ) [default = %d]\n",                pPars->nVarMax );
5881     Abc_Print( -2, "\t-L <num> : the min size of max fanout-free cone (MFFC) (area-only) [default = %d]\n",     pPars->nMffcMin );
5882     Abc_Print( -2, "\t-H <num> : the max size of max fanout-free cone (MFFC) (area-only) [default = %d]\n",     pPars->nMffcMax );
5883     Abc_Print( -2, "\t-R <num> : the max number of decomposition rounds (1 <= num <= 4) [default = %d]\n",      pPars->nDecMax );
5884     Abc_Print( -2, "\t-M <num> : the max node count of windows to consider (0 = no limit) [default = %d]\n",    pPars->nWinSizeMax );
5885     Abc_Print( -2, "\t-C <num> : the max number of conflicts in one SAT run (0 = no limit) [default = %d]\n",   pPars->nBTLimit );
5886     Abc_Print( -2, "\t-N <num> : the max number of nodes to try (0 = all) [default = %d]\n",                    pPars->nNodesMax );
5887     Abc_Print( -2, "\t-P <num> : one particular node to try (0 = none) [default = %d]\n",                       pPars->iNodeOne );
5888     Abc_Print( -2, "\t-W <num> : size of timing window in percents (0 <= num <= 100) [default = %d]\n",         pPars->nTimeWin );
5889     Abc_Print( -2, "\t-D <num> : size of critical-timing delay-delta (in picoseconds) [default = %d]\n",        pPars->DeltaCrit );
5890     Abc_Print( -2, "\t-E <num> : delay-area tradeoff (in picoseconds per area-unit) [default = %d]\n",          pPars->DelAreaRatio );
5891     Abc_Print( -2, "\t-a       : toggle area minimization [default = %s]\n",                                    pPars->fArea? "yes": "no" );
5892     Abc_Print( -2, "\t-r       : toggle using reverse topo order for area minimization [default = %s]\n",       pPars->fAreaRev? "yes": "no" );
5893     Abc_Print( -2, "\t-m       : toggle detecting multi-input AND/OR gates [default = %s]\n",                   pPars->fUseAndOr? "yes": "no" );
5894     Abc_Print( -2, "\t-z       : toggle zero-cost replacements [default = %s]\n",                               pPars->fZeroCost? "yes": "no" );
5895     Abc_Print( -2, "\t-e       : toggle using more effort [default = %s]\n",                                    pPars->fMoreEffort? "yes": "no" );
5896     Abc_Print( -2, "\t-s       : toggle using simulation [default = %s]\n",                                     pPars->fUseSim? "yes": "no" );
5897     Abc_Print( -2, "\t-p       : toggle printing decompositions [default = %s]\n",                              pPars->fPrintDecs? "yes": "no" );
5898     Abc_Print( -2, "\t-d       : toggle printing delay profile statistics [default = %s]\n",                    pPars->fDelayVerbose? "yes": "no" );
5899     Abc_Print( -2, "\t-l       : toggle printing library usage statistics [default = %s]\n",                    pPars->fLibVerbose? "yes": "no" );
5900     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n",                        pPars->fVerbose? "yes": "no" );
5901     Abc_Print( -2, "\t-w       : toggle printing detailed stats for each node [default = %s]\n",                pPars->fVeryVerbose? "yes": "no" );
5902     Abc_Print( -2, "\t-h       : print the command usage\n");
5903     return 1;
5904 }
5905 
5906 /**Function*************************************************************
5907 
5908   Synopsis    []
5909 
5910   Description []
5911 
5912   SideEffects []
5913 
5914   SeeAlso     []
5915 
5916 ***********************************************************************/
Abc_CommandMfse(Abc_Frame_t * pAbc,int argc,char ** argv)5917 int Abc_CommandMfse( Abc_Frame_t * pAbc, int argc, char ** argv )
5918 {
5919     extern Abc_Ntk_t * Abc_NtkOptMfse( Abc_Ntk_t * pNtk, Acb_Par_t * pPars );
5920     Abc_Ntk_t * pNtkNew, * pNtk = Abc_FrameReadNtk(pAbc);
5921     Acb_Par_t Pars, * pPars = &Pars; int c;
5922     Acb_ParSetDefault( pPars );
5923     Extra_UtilGetoptReset();
5924     while ( ( c = Extra_UtilGetopt( argc, argv, "IOWFLCadvwh" ) ) != EOF )
5925     {
5926         switch ( c )
5927         {
5928         case 'I':
5929             if ( globalUtilOptind >= argc )
5930             {
5931                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
5932                 goto usage;
5933             }
5934             pPars->nTfiLevMax = atoi(argv[globalUtilOptind]);
5935             globalUtilOptind++;
5936             if ( pPars->nTfiLevMax < 0 )
5937                 goto usage;
5938             break;
5939         case 'O':
5940             if ( globalUtilOptind >= argc )
5941             {
5942                 Abc_Print( -1, "Command line switch \"-O\" should be followed by an integer.\n" );
5943                 goto usage;
5944             }
5945             pPars->nTfoLevMax = atoi(argv[globalUtilOptind]);
5946             globalUtilOptind++;
5947             if ( pPars->nTfoLevMax < 0 )
5948                 goto usage;
5949             break;
5950         case 'W':
5951             if ( globalUtilOptind >= argc )
5952             {
5953                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
5954                 goto usage;
5955             }
5956             pPars->nWinNodeMax = atoi(argv[globalUtilOptind]);
5957             globalUtilOptind++;
5958             if ( pPars->nWinNodeMax < 0 )
5959                 goto usage;
5960             break;
5961         case 'F':
5962             if ( globalUtilOptind >= argc )
5963             {
5964                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
5965                 goto usage;
5966             }
5967             pPars->nFanoutMax = atoi(argv[globalUtilOptind]);
5968             globalUtilOptind++;
5969             if ( pPars->nFanoutMax < 0 )
5970                 goto usage;
5971             break;
5972         case 'L':
5973             if ( globalUtilOptind >= argc )
5974             {
5975                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
5976                 goto usage;
5977             }
5978             pPars->nGrowthLevel = atoi(argv[globalUtilOptind]);
5979             globalUtilOptind++;
5980             if ( pPars->nGrowthLevel < -ABC_INFINITY || pPars->nGrowthLevel > ABC_INFINITY )
5981                 goto usage;
5982             break;
5983         case 'C':
5984             if ( globalUtilOptind >= argc )
5985             {
5986                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
5987                 goto usage;
5988             }
5989             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
5990             globalUtilOptind++;
5991             if ( pPars->nBTLimit < 0 )
5992                 goto usage;
5993             break;
5994         case 'a':
5995             pPars->fArea ^= 1;
5996             break;
5997         case 'd':
5998             pPars->fUseAshen ^= 1;
5999             break;
6000         case 'v':
6001             pPars->fVerbose ^= 1;
6002             break;
6003         case 'w':
6004             pPars->fVeryVerbose ^= 1;
6005             break;
6006         case 'h':
6007             goto usage;
6008         default:
6009             goto usage;
6010         }
6011     }
6012     if ( pNtk == NULL )
6013     {
6014         Abc_Print( -1, "Empty network.\n" );
6015         return 1;
6016     }
6017     if ( !Abc_NtkIsLogic(pNtk) )
6018     {
6019         Abc_Print( -1, "This command can only be applied to a logic network.\n" );
6020         return 1;
6021     }
6022     pPars->nLutSize = Abc_NtkGetFaninMax( pNtk );
6023     if ( pPars->nLutSize > 6 )
6024     {
6025         Abc_Print( -1, "Command is only applicable to LUT size no more than 6.\n" );
6026         return 1;
6027     }
6028     Abc_NtkToSop( pNtk, -1, ABC_INFINITY );
6029     pNtkNew = Abc_NtkOptMfse( pNtk, pPars );
6030     if ( pNtkNew == NULL )
6031     {
6032         Abc_Print( -1, "Command \"mfse\" has failed.\n" );
6033         return 1;
6034     }
6035     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkNew );
6036     return 0;
6037 
6038 usage:
6039     Abc_Print( -2, "usage: mfse [-IOWFLC <num>] [-advwh]\n" );
6040     Abc_Print( -2, "\t           performs don't-care-based optimization of logic networks\n" );
6041     Abc_Print( -2, "\t-I <num> : the number of levels in the TFI cone (2 <= num) [default = %d]\n",             pPars->nTfiLevMax );
6042     Abc_Print( -2, "\t-O <num> : the number of levels in the TFO cone (0 <= num) [default = %d]\n",             pPars->nTfoLevMax );
6043     Abc_Print( -2, "\t-W <num> : the max number of nodes in the window (1 <= num) [default = %d]\n",            pPars->nWinNodeMax );
6044     Abc_Print( -2, "\t-F <num> : the max number of fanouts to skip (1 <= num) [default = %d]\n",                pPars->nFanoutMax );
6045     Abc_Print( -2, "\t-L <num> : the max increase in node level after resynthesis (0 <= num) [default = %d]\n", pPars->nGrowthLevel );
6046     Abc_Print( -2, "\t-C <num> : the max number of conflicts in one SAT run (0 = no limit) [default = %d]\n",   pPars->nBTLimit );
6047     Abc_Print( -2, "\t-a       : toggle minimizing area [default = %s]\n",                                      pPars->fArea? "area": "delay" );
6048     Abc_Print( -2, "\t-d       : toggle using Ashenhurst decomposition [default = %s]\n",                       pPars->fUseAshen? "yes": "no" );
6049     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n",                        pPars->fVerbose? "yes": "no" );
6050     Abc_Print( -2, "\t-w       : toggle printing detailed stats for each node [default = %s]\n",                pPars->fVeryVerbose? "yes": "no" );
6051     Abc_Print( -2, "\t-h       : print the command usage\n");
6052     return 1;
6053 }
6054 
6055 /**Function*************************************************************
6056 
6057   Synopsis    []
6058 
6059   Description []
6060 
6061   SideEffects []
6062 
6063   SeeAlso     []
6064 
6065 ***********************************************************************/
Abc_CommandLogicPush(Abc_Frame_t * pAbc,int argc,char ** argv)6066 int Abc_CommandLogicPush( Abc_Frame_t * pAbc, int argc, char ** argv )
6067 {
6068     extern Abc_Ntk_t * Abc_NtkOptPush( Abc_Ntk_t * pNtk, int nLutSize, int fVerbose );
6069     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
6070     Abc_Ntk_t * pNtkRes;
6071     int nLutSize = 4;
6072     int fVerbose = 0;
6073     int c;
6074     Extra_UtilGetoptReset();
6075     while ( ( c = Extra_UtilGetopt( argc, argv, "Kvh" ) ) != EOF )
6076     {
6077         switch ( c )
6078         {
6079         case 'K':
6080             if ( globalUtilOptind >= argc )
6081             {
6082                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a positive integer.\n" );
6083                 goto usage;
6084             }
6085             nLutSize = atoi(argv[globalUtilOptind]);
6086             globalUtilOptind++;
6087             if ( nLutSize < 0 )
6088                 goto usage;
6089             break;
6090         case 'v':
6091             fVerbose ^= 1;
6092             break;
6093         case 'h':
6094             goto usage;
6095         default:
6096             goto usage;
6097         }
6098     }
6099     if ( pNtk == NULL )
6100     {
6101         Abc_Print( -1, "Empty network.\n" );
6102         return 1;
6103     }
6104     if ( !Abc_NtkIsLogic(pNtk) )
6105     {
6106         Abc_Print( -1, "This command can only be applied to a logic network.\n" );
6107         return 1;
6108     }
6109     nLutSize = Abc_MaxInt( nLutSize, Abc_NtkGetFaninMax(pNtk) );
6110     Abc_NtkToSop( pNtk, -1, ABC_INFINITY );
6111     pNtkRes = Abc_NtkOptPush( pNtk, nLutSize, fVerbose );
6112     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
6113     return 0;
6114 usage:
6115     Abc_Print( -2, "usage: logicpush [-K num] [-vh]\n" );
6116     Abc_Print( -2, "\t           performs logic pushing to reduce structural bias\n" );
6117     Abc_Print( -2, "\t-K <num> : the LUT size used in the mapping [default = %d]\n", nLutSize );
6118     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n", fVerbose? "yes": "no" );
6119     Abc_Print( -2, "\t-h       : print the command usage\n");
6120     return 1;
6121 }
6122 
6123 
6124 /**Function*************************************************************
6125 
6126   Synopsis    []
6127 
6128   Description []
6129 
6130   SideEffects []
6131 
6132   SeeAlso     []
6133 
6134 ***********************************************************************/
Abc_CommandTrace(Abc_Frame_t * pAbc,int argc,char ** argv)6135 int Abc_CommandTrace( Abc_Frame_t * pAbc, int argc, char ** argv )
6136 {
6137     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
6138     int c;
6139     int fUseLutLib;
6140     int fVerbose;
6141     extern void Abc_NtkDelayTracePrint( Abc_Ntk_t * pNtk, int fUseLutLib, int fVerbose );
6142 
6143     // set defaults
6144     fUseLutLib = 0;
6145     fVerbose   = 0;
6146     Extra_UtilGetoptReset();
6147     while ( ( c = Extra_UtilGetopt( argc, argv, "lvh" ) ) != EOF )
6148     {
6149         switch ( c )
6150         {
6151         case 'l':
6152             fUseLutLib ^= 1;
6153             break;
6154         case 'v':
6155             fVerbose ^= 1;
6156             break;
6157         case 'h':
6158             goto usage;
6159         default:
6160             goto usage;
6161         }
6162     }
6163 
6164     if ( pNtk == NULL )
6165     {
6166         Abc_Print( -1, "Empty network.\n" );
6167         return 1;
6168     }
6169     if ( !Abc_NtkIsLogic(pNtk) )
6170     {
6171         Abc_Print( -1, "This command can only be applied to a logic network.\n" );
6172         return 1;
6173     }
6174 
6175     // modify the current network
6176     Abc_NtkDelayTracePrint( pNtk, fUseLutLib, fVerbose );
6177     return 0;
6178 
6179 usage:
6180     Abc_Print( -2, "usage: trace [-lvh]\n" );
6181     Abc_Print( -2, "\t           performs delay trace of LUT-mapped network\n" );
6182     Abc_Print( -2, "\t-l       : toggle using unit- or LUT-library-delay model [default = %s]\n", fUseLutLib? "lib": "unit" );
6183     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n", fVerbose? "yes": "no" );
6184     Abc_Print( -2, "\t-h       : print the command usage\n");
6185     return 1;
6186 }
6187 
6188 /**Function*************************************************************
6189 
6190   Synopsis    []
6191 
6192   Description []
6193 
6194   SideEffects []
6195 
6196   SeeAlso     []
6197 
6198 ***********************************************************************/
Abc_CommandGlitch(Abc_Frame_t * pAbc,int argc,char ** argv)6199 int Abc_CommandGlitch( Abc_Frame_t * pAbc, int argc, char ** argv )
6200 {
6201     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
6202     int nPats    = 4000;
6203     int Prob     =    8;
6204     int fVerbose =    1;
6205     int c;
6206 
6207     // set defaults
6208     Extra_UtilGetoptReset();
6209     while ( ( c = Extra_UtilGetopt( argc, argv, "NPvh" ) ) != EOF )
6210     {
6211         switch ( c )
6212         {
6213         case 'N':
6214             if ( globalUtilOptind >= argc )
6215             {
6216                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
6217                 goto usage;
6218             }
6219             nPats = atoi(argv[globalUtilOptind]);
6220             globalUtilOptind++;
6221             if ( nPats < 1 )
6222                 goto usage;
6223             break;
6224         case 'P':
6225             if ( globalUtilOptind >= argc )
6226             {
6227                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
6228                 goto usage;
6229             }
6230             Prob = atoi(argv[globalUtilOptind]);
6231             globalUtilOptind++;
6232             if ( Prob < 1 )
6233                 goto usage;
6234             break;
6235         case 'v':
6236             fVerbose ^= 1;
6237             break;
6238         case 'h':
6239             goto usage;
6240         default:
6241             goto usage;
6242         }
6243     }
6244     if ( pNtk == NULL )
6245     {
6246         Abc_Print( -1, "Empty network.\n" );
6247         return 1;
6248     }
6249     if ( !Abc_NtkIsLogic(pNtk) )
6250     {
6251         Abc_Print( -1, "This command can only be applied to a mapped logic network.\n" );
6252         return 1;
6253     }
6254     if ( Abc_NtkIsMappedLogic(pNtk) || Abc_NtkGetFaninMax(pNtk) <= 6 )
6255         Abc_Print( 1, "Glitching adds %7.2f %% of signal transitions, compared to switching.\n", Abc_NtkMfsTotalGlitching(pNtk, nPats, Prob, fVerbose) );
6256     else
6257         printf( "Currently computes glitching only for K-LUT networks with K <= 6.\n" );
6258     return 0;
6259 
6260 usage:
6261     Abc_Print( -2, "usage: glitch [-NP <num>] [-vh]\n" );
6262     Abc_Print( -2, "\t           comparing glitching activity to switching activity\n" );
6263     Abc_Print( -2, "\t-N <num> : the number of random patterns to use (0 < num < 1000000) [default = %d]\n", nPats );
6264     Abc_Print( -2, "\t-P <num> : once in how many cycles an input changes its value [default = %d]\n", Prob );
6265     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n", fVerbose? "yes": "no" );
6266     Abc_Print( -2, "\t-h       : print the command usage\n");
6267     return 1;
6268 }
6269 
6270 /**Function*************************************************************
6271 
6272   Synopsis    []
6273 
6274   Description []
6275 
6276   SideEffects []
6277 
6278   SeeAlso     []
6279 
6280 ***********************************************************************/
Abc_CommandSpeedup(Abc_Frame_t * pAbc,int argc,char ** argv)6281 int Abc_CommandSpeedup( Abc_Frame_t * pAbc, int argc, char ** argv )
6282 {
6283     Abc_Ntk_t * pNtk, * pNtkRes;
6284     int c;
6285     int fUseLutLib;
6286     int Percentage;
6287     int Degree;
6288     int fVerbose;
6289     int fVeryVerbose;
6290     extern Abc_Ntk_t * Abc_NtkSpeedup( Abc_Ntk_t * pNtk, int fUseLutLib, int Percentage, int Degree, int fVerbose, int fVeryVerbose );
6291     pNtk = Abc_FrameReadNtk(pAbc);
6292 
6293     // set defaults
6294     fUseLutLib = 0;
6295     Percentage = 5;
6296     Degree     = 2;
6297     fVerbose   = 0;
6298     fVeryVerbose = 0;
6299     Extra_UtilGetoptReset();
6300     while ( ( c = Extra_UtilGetopt( argc, argv, "PNlvwh" ) ) != EOF )
6301     {
6302         switch ( c )
6303         {
6304         case 'P':
6305             if ( globalUtilOptind >= argc )
6306             {
6307                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
6308                 goto usage;
6309             }
6310             Percentage = atoi(argv[globalUtilOptind]);
6311             globalUtilOptind++;
6312             if ( Percentage < 1 || Percentage > 100 )
6313                 goto usage;
6314             break;
6315         case 'N':
6316             if ( globalUtilOptind >= argc )
6317             {
6318                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
6319                 goto usage;
6320             }
6321             Degree = atoi(argv[globalUtilOptind]);
6322             globalUtilOptind++;
6323             if ( Degree < 1 || Degree > 5 )
6324                 goto usage;
6325             break;
6326         case 'l':
6327             fUseLutLib ^= 1;
6328             break;
6329         case 'v':
6330             fVerbose ^= 1;
6331             break;
6332         case 'w':
6333             fVeryVerbose ^= 1;
6334             break;
6335         case 'h':
6336             goto usage;
6337         default:
6338             goto usage;
6339         }
6340     }
6341 
6342     if ( pNtk == NULL )
6343     {
6344         Abc_Print( -1, "Empty network.\n" );
6345         return 1;
6346     }
6347     if ( !Abc_NtkIsLogic(pNtk) )
6348     {
6349         Abc_Print( -1, "This command can only be applied to a logic network.\n" );
6350         return 1;
6351     }
6352 
6353     // modify the current network
6354     pNtkRes = Abc_NtkSpeedup( pNtk, fUseLutLib, Percentage, Degree, fVerbose, fVeryVerbose );
6355     if ( pNtkRes == NULL )
6356     {
6357         Abc_Print( -1, "The command has failed.\n" );
6358         return 1;
6359     }
6360     // replace the current network
6361     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
6362     return 0;
6363 
6364 usage:
6365     Abc_Print( -2, "usage: speedup [-PN <num>] [-lvwh]\n" );
6366     Abc_Print( -2, "\t           transforms LUT-mapped network into an AIG with choices;\n" );
6367     Abc_Print( -2, "\t           the choices are added to speedup the next round of mapping\n" );
6368     Abc_Print( -2, "\t-P <num> : delay delta defining critical path for library model [default = %d%%]\n", Percentage );
6369     Abc_Print( -2, "\t-N <num> : the max critical path degree for resynthesis (0 < num < 6) [default = %d]\n", Degree );
6370     Abc_Print( -2, "\t-l       : toggle using unit- or LUT-library-delay model [default = %s]\n", fUseLutLib? "lib" : "unit" );
6371     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n", fVerbose? "yes": "no" );
6372     Abc_Print( -2, "\t-w       : toggle printing detailed stats for each node [default = %s]\n", fVeryVerbose? "yes": "no" );
6373     Abc_Print( -2, "\t-h       : print the command usage\n");
6374     return 1;
6375 }
6376 
6377 /**Function*************************************************************
6378 
6379   Synopsis    []
6380 
6381   Description []
6382 
6383   SideEffects []
6384 
6385   SeeAlso     []
6386 
6387 ***********************************************************************/
Abc_CommandPowerdown(Abc_Frame_t * pAbc,int argc,char ** argv)6388 int Abc_CommandPowerdown( Abc_Frame_t * pAbc, int argc, char ** argv )
6389 {
6390     Abc_Ntk_t * pNtk, * pNtkRes;
6391     int c;
6392     int fUseLutLib;
6393     int Percentage;
6394     int Degree;
6395     int fVerbose;
6396     int fVeryVerbose;
6397     extern Abc_Ntk_t * Abc_NtkPowerdown( Abc_Ntk_t * pNtk, int fUseLutLib, int Percentage, int Degree, int fVerbose, int fVeryVerbose );
6398 
6399     pNtk = Abc_FrameReadNtk(pAbc);
6400     // set defaults
6401     fUseLutLib = 0;
6402     Percentage =10;
6403     Degree     = 2;
6404     fVerbose   = 0;
6405     fVeryVerbose = 0;
6406     Extra_UtilGetoptReset();
6407     while ( ( c = Extra_UtilGetopt( argc, argv, "PNlvwh" ) ) != EOF )
6408     {
6409         switch ( c )
6410         {
6411         case 'P':
6412             if ( globalUtilOptind >= argc )
6413             {
6414                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
6415                 goto usage;
6416             }
6417             Percentage = atoi(argv[globalUtilOptind]);
6418             globalUtilOptind++;
6419             if ( Percentage < 1 || Percentage > 100 )
6420                 goto usage;
6421             break;
6422         case 'N':
6423             if ( globalUtilOptind >= argc )
6424             {
6425                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
6426                 goto usage;
6427             }
6428             Degree = atoi(argv[globalUtilOptind]);
6429             globalUtilOptind++;
6430             if ( Degree < 1 || Degree > 5 )
6431                 goto usage;
6432             break;
6433         case 'l':
6434             fUseLutLib ^= 1;
6435             break;
6436         case 'v':
6437             fVerbose ^= 1;
6438             break;
6439         case 'w':
6440             fVeryVerbose ^= 1;
6441             break;
6442         case 'h':
6443             goto usage;
6444         default:
6445             goto usage;
6446         }
6447     }
6448 
6449     if ( pNtk == NULL )
6450     {
6451         Abc_Print( -1, "Empty network.\n" );
6452         return 1;
6453     }
6454     if ( !Abc_NtkIsLogic(pNtk) )
6455     {
6456         Abc_Print( -1, "This command can only be applied to a logic network.\n" );
6457         return 1;
6458     }
6459 
6460     // modify the current network
6461     pNtkRes = Abc_NtkPowerdown( pNtk, fUseLutLib, Percentage, Degree, fVerbose, fVeryVerbose );
6462     if ( pNtkRes == NULL )
6463     {
6464         Abc_Print( -1, "The command has failed.\n" );
6465         return 1;
6466     }
6467     // replace the current network
6468     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
6469     return 0;
6470 
6471 usage:
6472     Abc_Print( -2, "usage: powerdown [-PN <num>] [-vwh]\n" );
6473     Abc_Print( -2, "\t           transforms LUT-mapped network into an AIG with choices;\n" );
6474     Abc_Print( -2, "\t           the choices are added to power down the next round of mapping\n" );
6475     Abc_Print( -2, "\t-P <num> : switching propability delta defining power critical edges [default = %d%%]\n", Percentage );
6476     Abc_Print( -2, "\t           (e.g. 5% means hot wires switch with probability: 0.45 <= p <= 0.50 (max)\n" );
6477     Abc_Print( -2, "\t-N <num> : the max critical path degree for resynthesis (0 < num < 6) [default = %d]\n", Degree );
6478 //    Abc_Print( -2, "\t-l       : toggle using unit- or LUT-library-delay model [default = %s]\n", fUseLutLib? "lib" : "unit" );
6479     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n", fVerbose? "yes": "no" );
6480     Abc_Print( -2, "\t-w       : toggle printing detailed stats for each node [default = %s]\n", fVeryVerbose? "yes": "no" );
6481     Abc_Print( -2, "\t-h       : print the command usage\n");
6482     return 1;
6483 }
6484 
6485 /**Function*************************************************************
6486 
6487   Synopsis    []
6488 
6489   Description []
6490 
6491   SideEffects []
6492 
6493   SeeAlso     []
6494 
6495 ***********************************************************************/
Abc_CommandAddBuffs(Abc_Frame_t * pAbc,int argc,char ** argv)6496 int Abc_CommandAddBuffs( Abc_Frame_t * pAbc, int argc, char ** argv )
6497 {
6498     extern Abc_Ntk_t * Abc_NtkAddBuffs( Abc_Ntk_t * pNtk, int fDirect, int fReverse, int nImprove, int fVerbose );
6499     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
6500     Abc_Ntk_t * pNtkRes;
6501     int fDirect;
6502     int fReverse;
6503     int nImprove;
6504     int c, fVerbose;
6505 
6506     fDirect  = 0;
6507     fReverse = 0;
6508     nImprove = 1000;
6509     fVerbose = 0;
6510     Extra_UtilGetoptReset();
6511     while ( ( c = Extra_UtilGetopt( argc, argv, "Idrvh" ) ) != EOF )
6512     {
6513         switch ( c )
6514         {
6515         case 'I':
6516             if ( globalUtilOptind >= argc )
6517             {
6518                 Abc_Print( -1, "Command line switch \"-I\" should be followed by a positive integer.\n" );
6519                 goto usage;
6520             }
6521             nImprove = atoi(argv[globalUtilOptind]);
6522             globalUtilOptind++;
6523             if ( nImprove < 0 )
6524                 goto usage;
6525             break;
6526         case 'd':
6527             fDirect ^= 1;
6528             break;
6529         case 'r':
6530             fReverse ^= 1;
6531             break;
6532         case 'v':
6533             fVerbose ^= 1;
6534             break;
6535         case 'h':
6536             goto usage;
6537         default:
6538             goto usage;
6539         }
6540     }
6541 
6542     if ( pNtk == NULL )
6543     {
6544         Abc_Print( -1, "Empty network.\n" );
6545         return 1;
6546     }
6547     if ( !Abc_NtkIsLogic(pNtk) )
6548     {
6549         Abc_Print( -1, "This command can only be applied to a logic network.\n" );
6550         return 1;
6551     }
6552 
6553     // modify the current network
6554     pNtkRes = Abc_NtkAddBuffs( pNtk, fDirect, fReverse, nImprove, fVerbose );
6555     if ( pNtkRes == NULL )
6556     {
6557         Abc_Print( -1, "The command has failed.\n" );
6558         return 1;
6559     }
6560     // replace the current network
6561     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
6562     return 0;
6563 
6564 usage:
6565     Abc_Print( -2, "usage: addbuffs [-I num] [-drvh]\n" );
6566     Abc_Print( -2, "\t           adds buffers to create balanced CI/CO paths\n" );
6567     Abc_Print( -2, "\t-I <num> : the number of refinement iterations [default = %d]\n", nImprove );
6568     Abc_Print( -2, "\t-d       : toggle using only CI-to-CO levelized order [default = %s]\n", fDirect? "yes": "no" );
6569     Abc_Print( -2, "\t-r       : toggle using only CO-to-C1 levelized order [default = %s]\n", fReverse? "yes": "no" );
6570     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n", fVerbose? "yes": "no" );
6571     Abc_Print( -2, "\t-h       : print the command usage\n");
6572     return 1;
6573 }
6574 
6575 //#if 0
6576 /**Function*************************************************************
6577 
6578   Synopsis    []
6579 
6580   Description []
6581 
6582   SideEffects []
6583 
6584   SeeAlso     []
6585 
6586 ***********************************************************************/
Abc_CommandMerge(Abc_Frame_t * pAbc,int argc,char ** argv)6587 int Abc_CommandMerge( Abc_Frame_t * pAbc, int argc, char ** argv )
6588 {
6589     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
6590     Nwk_LMPars_t Pars, * pPars = &Pars;
6591     Vec_Int_t * vResult;
6592     int c;
6593     extern Vec_Int_t * Abc_NtkLutMerge( Abc_Ntk_t * pNtk, Nwk_LMPars_t * pPars );
6594     // set defaults
6595     memset( pPars, 0, sizeof(Nwk_LMPars_t) );
6596     pPars->nMaxLutSize    = 5;   // the max LUT size for merging (N=5)
6597     pPars->nMaxSuppSize   = 5;   // the max total support size after merging (S=5)
6598     pPars->nMaxDistance   = 3;   // the max number of nodes separating LUTs
6599     pPars->nMaxLevelDiff  = 2;   // the max difference in levels
6600     pPars->nMaxFanout     = 100; // the max number of fanouts to traverse
6601     pPars->fUseDiffSupp   = 0;   // enables the use of nodes with different support
6602     pPars->fUseTfiTfo     = 0;   // enables the use of TFO/TFO nodes as candidates
6603     pPars->fVeryVerbose   = 0;   // enables additional verbose output
6604     pPars->fVerbose       = 1;   // enables verbose output
6605     Extra_UtilGetoptReset();
6606     while ( ( c = Extra_UtilGetopt( argc, argv, "NSDLFscvwh" ) ) != EOF )
6607     {
6608         switch ( c )
6609         {
6610         case 'N':
6611             if ( globalUtilOptind >= argc )
6612             {
6613                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
6614                 goto usage;
6615             }
6616             pPars->nMaxLutSize = atoi(argv[globalUtilOptind]);
6617             globalUtilOptind++;
6618             if ( pPars->nMaxLutSize < 2 )
6619                 goto usage;
6620             break;
6621         case 'S':
6622             if ( globalUtilOptind >= argc )
6623             {
6624                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
6625                 goto usage;
6626             }
6627             pPars->nMaxSuppSize = atoi(argv[globalUtilOptind]);
6628             globalUtilOptind++;
6629             if ( pPars->nMaxSuppSize < 2 )
6630                 goto usage;
6631             break;
6632         case 'D':
6633             if ( globalUtilOptind >= argc )
6634             {
6635                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
6636                 goto usage;
6637             }
6638             pPars->nMaxDistance = atoi(argv[globalUtilOptind]);
6639             globalUtilOptind++;
6640             if ( pPars->nMaxDistance < 2 )
6641                 goto usage;
6642             break;
6643         case 'L':
6644             if ( globalUtilOptind >= argc )
6645             {
6646                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
6647                 goto usage;
6648             }
6649             pPars->nMaxLevelDiff = atoi(argv[globalUtilOptind]);
6650             globalUtilOptind++;
6651             if ( pPars->nMaxLevelDiff < 2 )
6652                 goto usage;
6653             break;
6654         case 'F':
6655             if ( globalUtilOptind >= argc )
6656             {
6657                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
6658                 goto usage;
6659             }
6660             pPars->nMaxFanout = atoi(argv[globalUtilOptind]);
6661             globalUtilOptind++;
6662             if ( pPars->nMaxFanout < 2 )
6663                 goto usage;
6664             break;
6665         case 's':
6666             pPars->fUseDiffSupp ^= 1;
6667             break;
6668         case 'c':
6669             pPars->fUseTfiTfo ^= 1;
6670             break;
6671         case 'w':
6672             pPars->fVeryVerbose ^= 1;
6673             break;
6674         case 'v':
6675             pPars->fVerbose ^= 1;
6676             break;
6677         case 'h':
6678             goto usage;
6679         default:
6680             goto usage;
6681         }
6682     }
6683     if ( pNtk == NULL || !Abc_NtkIsLogic(pNtk) )
6684     {
6685         Abc_Print( -1, "Abc_CommandMerge(): There is no mapped network to merge LUTs.\n" );
6686         return 1;
6687     }
6688 
6689     vResult = Abc_NtkLutMerge( pNtk, pPars );
6690     Vec_IntFree( vResult );
6691     return 0;
6692 
6693 usage:
6694     Abc_Print( -2, "usage: merge [-NSDLF <num>] [-scwvh]\n" );
6695     Abc_Print( -2, "\t           creates pairs of topologically-related LUTs\n" );
6696     Abc_Print( -2, "\t-N <num> : the max LUT size for merging (1 < num) [default = %d]\n", pPars->nMaxLutSize );
6697     Abc_Print( -2, "\t-S <num> : the max total support size after merging (1 < num) [default = %d]\n", pPars->nMaxSuppSize );
6698     Abc_Print( -2, "\t-D <num> : the max distance in terms of LUTs (0 < num) [default = %d]\n", pPars->nMaxDistance );
6699     Abc_Print( -2, "\t-L <num> : the max difference in levels (0 <= num) [default = %d]\n", pPars->nMaxLevelDiff );
6700     Abc_Print( -2, "\t-F <num> : the max number of fanouts to stop traversal (0 < num) [default = %d]\n", pPars->nMaxFanout );
6701     Abc_Print( -2, "\t-s       : toggle the use of nodes without support overlap [default = %s]\n", pPars->fUseDiffSupp? "yes" : "no" );
6702     Abc_Print( -2, "\t-c       : toggle the use of TFI/TFO nodes as candidates [default = %s]\n", pPars->fUseTfiTfo? "yes" : "no" );
6703     Abc_Print( -2, "\t-w       : toggle printing detailed stats for each node [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
6704     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n", pPars->fVerbose? "yes": "no" );
6705     Abc_Print( -2, "\t-h       : print the command usage\n");
6706     return 1;
6707 }
6708 //#endif
6709 
6710 
6711 
6712 /**Function*************************************************************
6713 
6714   Synopsis    []
6715 
6716   Description []
6717 
6718   SideEffects []
6719 
6720   SeeAlso     []
6721 
6722 ***********************************************************************/
Abc_CommandTestDec(Abc_Frame_t * pAbc,int argc,char ** argv)6723 int Abc_CommandTestDec( Abc_Frame_t * pAbc, int argc, char ** argv )
6724 {
6725     extern int Abc_DecTest( char * pFileName, int DecType, int nVarNum, int fVerbose );
6726     char * pFileName;
6727     int c;
6728     int fVerbose = 0;
6729     int DecType = 0;
6730     int nVarNum = -1;
6731     Extra_UtilGetoptReset();
6732     while ( ( c = Extra_UtilGetopt( argc, argv, "ANvh" ) ) != EOF )
6733     {
6734         switch ( c )
6735         {
6736         case 'A':
6737             if ( globalUtilOptind >= argc )
6738             {
6739                 Abc_Print( -1, "Command line switch \"-A\" should be followed by an integer.\n" );
6740                 goto usage;
6741             }
6742             DecType = atoi(argv[globalUtilOptind]);
6743             globalUtilOptind++;
6744             if ( DecType < 0 )
6745                 goto usage;
6746             break;
6747         case 'N':
6748             if ( globalUtilOptind >= argc )
6749             {
6750                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
6751                 goto usage;
6752             }
6753             nVarNum = atoi(argv[globalUtilOptind]);
6754             globalUtilOptind++;
6755             if ( nVarNum < 0 )
6756                 goto usage;
6757             break;
6758         case 'v':
6759             fVerbose ^= 1;
6760             break;
6761         case 'h':
6762             goto usage;
6763         default:
6764             goto usage;
6765         }
6766     }
6767     if ( argc != globalUtilOptind + 1 )
6768     {
6769         Abc_Print( 1,"Input file is not given.\n" );
6770         return 0;
6771     }
6772     if ( nVarNum >= 0 && nVarNum < 6 )
6773     {
6774         Abc_Print( 1,"The number of variables cannot be less than 6.\n" );
6775         return 0;
6776     }
6777     // get the output file name
6778     pFileName = argv[globalUtilOptind];
6779     // call the testbench
6780     Abc_DecTest( pFileName, DecType, nVarNum, fVerbose );
6781     return 0;
6782 
6783 usage:
6784     Abc_Print( -2, "usage: testdec [-AN <num>] [-vh] <file>\n" );
6785     Abc_Print( -2, "\t           testbench for Boolean decomposition algorithms\n" );
6786     Abc_Print( -2, "\t-A <num> : decomposition algorithm [default = %d]\n", DecType );
6787     Abc_Print( -2, "\t               0: none (reading and writing the file)\n" );
6788     Abc_Print( -2, "\t               1: algebraic factoring applied to ISOP\n" );
6789     Abc_Print( -2, "\t               2: bi-decomposition with cofactoring\n" );
6790     Abc_Print( -2, "\t               3: disjoint-support decomposition with cofactoring\n" );
6791     Abc_Print( -2, "\t               4: updated disjoint-support decomposition with cofactoring\n" );
6792     Abc_Print( -2, "\t               5: enumerating decomposable variable sets\n" );
6793     Abc_Print( -2, "\t               6: disjoint-support decomposition with cofactoring and boolean difference analysis\n" );
6794     Abc_Print( -2, "\t                  from V. Callegaro, F. S. Marranghello, M. G. A. Martins, R. P. Ribas and A. I. Reis,\n");
6795     Abc_Print( -2, "\t                  \"Bottom-up disjoint-support decomposition based on cofactor and boolean difference analysis,\" ICCD'15.\n" );
6796     Abc_Print( -2, "\t-N <num> : the number of support variables (binary files only) [default = unused]\n" );
6797     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
6798     Abc_Print( -2, "\t-h       : print the command usage\n");
6799     Abc_Print( -2, "\t<file>   : a text file with truth tables in hexadecimal, listed one per line,\n");
6800     Abc_Print( -2, "\t           or a binary file with an array of truth tables (in this case,\n");
6801     Abc_Print( -2, "\t           -N <num> is required to determine how many functions are stored)\n");
6802     return 1;
6803 }
6804 
6805 /**Function*************************************************************
6806 
6807   Synopsis    []
6808 
6809   Description []
6810 
6811   SideEffects []
6812 
6813   SeeAlso     []
6814 
6815 ***********************************************************************/
Abc_CommandTestNpn(Abc_Frame_t * pAbc,int argc,char ** argv)6816 int Abc_CommandTestNpn( Abc_Frame_t * pAbc, int argc, char ** argv )
6817 {
6818     extern int Abc_NpnTest( char * pFileName, int NpnType, int nVarNum, int fDumpRes, int fBinary, int fVerbose );
6819     char * pFileName;
6820     int c;
6821     int fVerbose = 0;
6822     int NpnType = 0;
6823     int nVarNum = -1;
6824     int fDumpRes = 0;
6825     int fBinary = 0;
6826     Extra_UtilGetoptReset();
6827     while ( ( c = Extra_UtilGetopt( argc, argv, "ANdbvh" ) ) != EOF )
6828     {
6829         switch ( c )
6830         {
6831         case 'A':
6832             if ( globalUtilOptind >= argc )
6833             {
6834                 Abc_Print( -1, "Command line switch \"-A\" should be followed by an integer.\n" );
6835                 goto usage;
6836             }
6837             NpnType = atoi(argv[globalUtilOptind]);
6838             globalUtilOptind++;
6839             if ( NpnType < 0 )
6840                 goto usage;
6841             break;
6842         case 'N':
6843             if ( globalUtilOptind >= argc )
6844             {
6845                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
6846                 goto usage;
6847             }
6848             nVarNum = atoi(argv[globalUtilOptind]);
6849             globalUtilOptind++;
6850             if ( nVarNum < 0 )
6851                 goto usage;
6852             break;
6853         case 'd':
6854             fDumpRes ^= 1;
6855             break;
6856         case 'b':
6857             fBinary ^= 1;
6858             break;
6859         case 'v':
6860             fVerbose ^= 1;
6861             break;
6862         case 'h':
6863             goto usage;
6864         default:
6865             goto usage;
6866         }
6867     }
6868     if ( argc != globalUtilOptind + 1 )
6869     {
6870         Abc_Print( 1,"Input file is not given.\n" );
6871         return 0;
6872     }
6873     if ( nVarNum >= 0 && nVarNum < 6 )
6874     {
6875         Abc_Print( 1,"The number of variables cannot be less than 6.\n" );
6876         return 0;
6877     }
6878     // get the output file name
6879     pFileName = argv[globalUtilOptind];
6880     // call the testbench
6881     Abc_NpnTest( pFileName, NpnType, nVarNum, fDumpRes, fBinary, fVerbose );
6882     return 0;
6883 
6884 usage:
6885     Abc_Print( -2, "usage: testnpn [-AN <num>] [-dbvh] <file>\n" );
6886     Abc_Print( -2, "\t           testbench for computing (semi-)canonical forms\n" );
6887     Abc_Print( -2, "\t           of completely-specified Boolean functions up to 16 varibles\n" );
6888     Abc_Print( -2, "\t-A <num> : semi-caninical form computation algorithm [default = %d]\n", NpnType );
6889     Abc_Print( -2, "\t               0: uniqifying truth tables\n" );
6890     Abc_Print( -2, "\t               1: exact NPN canonical form by brute-force enumeration\n" );
6891     Abc_Print( -2, "\t               2: semi-canonical form by counting 1s in cofactors\n" );
6892     Abc_Print( -2, "\t               3: Jake's hybrid semi-canonical form (fast)\n" );
6893     Abc_Print( -2, "\t               4: Jake's hybrid semi-canonical form (high-effort)\n" );
6894     Abc_Print( -2, "\t               5: new fast hybrid semi-canonical form\n" );
6895     Abc_Print( -2, "\t               6: new phase canonical form\n" );
6896     Abc_Print( -2, "\t               7: new hierarchical matching\n" );
6897     Abc_Print( -2, "\t               8: hierarchical matching            by XueGong Zhou at Fudan University, Shanghai\n" );
6898     Abc_Print( -2, "\t               9: adjustable algorithm (heuristic) by XueGong Zhou at Fudan University, Shanghai\n" );
6899     Abc_Print( -2, "\t              10: adjustable algorithm (exact)     by XueGong Zhou at Fudan University, Shanghai\n" );
6900     Abc_Print( -2, "\t              11: new cost-aware exact algorithm   by XueGong Zhou at Fudan University, Shanghai\n" );
6901     Abc_Print( -2, "\t-N <num> : the number of support variables (binary files only) [default = unused]\n" );
6902     Abc_Print( -2, "\t-d       : toggle dumping resulting functions into a file [default = %s]\n", fDumpRes? "yes": "no" );
6903     Abc_Print( -2, "\t-b       : toggle dumping in binary format [default = %s]\n", fBinary? "yes": "no" );
6904     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
6905     Abc_Print( -2, "\t-h       : print the command usage\n");
6906     Abc_Print( -2, "\t<file>   : a text file with truth tables in hexadecimal, listed one per line,\n");
6907     Abc_Print( -2, "\t           or a binary file with an array of truth tables (in this case,\n");
6908     Abc_Print( -2, "\t           -N <num> is required to determine how many functions are stored)\n");
6909     return 1;
6910 }
6911 
6912 /**Function*************************************************************
6913 
6914   Synopsis    []
6915 
6916   Description []
6917 
6918   SideEffects []
6919 
6920   SeeAlso     []
6921 
6922 ***********************************************************************/
Abc_CommandTestRPO(Abc_Frame_t * pAbc,int argc,char ** argv)6923 int Abc_CommandTestRPO(Abc_Frame_t * pAbc, int argc, char ** argv) {
6924     extern int Abc_RpoTest(char * pFileName, int nVarNum, int nThreshold, int fVerbose);
6925     char * pFileName;
6926     int c;
6927     int nVarNum = -1;
6928     int fVerbose = 0;
6929     int nThreshold = -1;
6930     Extra_UtilGetoptReset();
6931     while ((c = Extra_UtilGetopt(argc, argv, "TNvh")) != EOF) {
6932         switch (c) {
6933             case 'N':
6934                 if (globalUtilOptind >= argc) {
6935                     Abc_Print(-1, "Command line switch \"-N\" should be followed by an integer.\n");
6936                     goto usage;
6937                 }
6938                 nVarNum = atoi(argv[globalUtilOptind]);
6939                 globalUtilOptind++;
6940                 if (nVarNum < 0)
6941                     goto usage;
6942                 break;
6943             case 'T':
6944                 if (globalUtilOptind >= argc) {
6945                     Abc_Print(-1, "Command line switch \"-T\" should be followed by an integer.\n");
6946                     goto usage;
6947                 }
6948                 nThreshold = atoi(argv[globalUtilOptind]);
6949                 globalUtilOptind++;
6950                 if (nThreshold < 0)
6951                     goto usage;
6952                 break;
6953             case 'v':
6954                 fVerbose ^= 1;
6955                 break;
6956             case 'h':
6957                 goto usage;
6958             default:
6959                 goto usage;
6960         }
6961     }
6962     if (argc != globalUtilOptind + 1)
6963     {
6964         Abc_Print(1, "Input file is not given.\n");
6965         goto usage;
6966     }
6967     // get the output file name
6968     pFileName = argv[globalUtilOptind];
6969     // call the testbench
6970     Abc_RpoTest( pFileName, nVarNum, nThreshold, fVerbose );
6971     return 0;
6972 
6973 usage:
6974     Abc_Print(-2, "usage: testrpo [-NT <num>] [-vh] <file>\n");
6975     Abc_Print(-2, "\t           RPO algorithm developed and implemented by Mayler G. A. Martins,\n");
6976     Abc_Print(-2, "\t           Vinicius Callegaro, Renato P. Ribas and Andre' I. Reis\n");
6977     Abc_Print(-2, "\t           at Federal University of Rio Grande do Sul, Porto Alegre, Brazil\n");
6978     Abc_Print(-2, "\t-N <num> : the number of support variables (binary files only) [default = unused]\n");
6979     Abc_Print(-2, "\t-T <num> : the number of recursions accepted before abort [default = INFINITE]\n");
6980     Abc_Print(-2, "\t-v       : toggle verbose printout [default = %s]\n", fVerbose ? "yes" : "no");
6981     Abc_Print(-2, "\t-h       : print the command usage\n");
6982     Abc_Print(-2, "\t<file>   : a text file with truth tables in hexadecimal, listed one per line,\n");
6983     Abc_Print(-2, "\t           or a binary file with an array of truth tables (in this case,\n");
6984     Abc_Print(-2, "\t           -N <num> is required to determine how many functions are stored)\n");
6985     return 1;
6986 }
6987 
6988 /**Function*************************************************************
6989 
6990   Synopsis    []
6991 
6992   Description []
6993 
6994   SideEffects []
6995 
6996   SeeAlso     []
6997 
6998 ***********************************************************************/
Abc_CommandTestTruth(Abc_Frame_t * pAbc,int argc,char ** argv)6999 int Abc_CommandTestTruth( Abc_Frame_t * pAbc, int argc, char ** argv )
7000 {
7001     extern int * Kit_TruthTest( char * pFileName );
7002     int * pResult = NULL;
7003     int c, fVerbose = 0;
7004     Extra_UtilGetoptReset();
7005     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
7006     {
7007         switch ( c )
7008         {
7009         case 'v':
7010             fVerbose ^= 1;
7011             break;
7012         case 'h':
7013             goto usage;
7014         default:
7015             goto usage;
7016         }
7017     }
7018     if ( argc != globalUtilOptind + 1 )
7019     {
7020         Abc_Print( 1,"Input file is not given.\n" );
7021         return 0;
7022     }
7023     pResult = Kit_TruthTest( argv[globalUtilOptind] );
7024     ABC_FREE( pResult );
7025     return 0;
7026 
7027 usage:
7028     Abc_Print( -2, "usage: testtruth [-vh] <file>\n" );
7029     Abc_Print( -2, "\t           printing truth table stats\n" );
7030     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
7031     Abc_Print( -2, "\t-h       : print the command usage\n");
7032     return 1;
7033 }
7034 
7035 /**Function*************************************************************
7036 
7037   Synopsis    []
7038 
7039   Description []
7040 
7041   SideEffects []
7042 
7043   SeeAlso     []
7044 
7045 ***********************************************************************/
Abc_CommandRunEco(Abc_Frame_t * pAbc,int argc,char ** argv)7046 int Abc_CommandRunEco( Abc_Frame_t * pAbc, int argc, char ** argv )
7047 {
7048     extern void Acb_NtkRunEco( char * pFileNames[4], int fCheck, int fVerbose );
7049     char * pFileNames[4] = {NULL};
7050     int c, fCheck = 0, fVerbose = 0;
7051     Extra_UtilGetoptReset();
7052     while ( ( c = Extra_UtilGetopt( argc, argv, "cvh" ) ) != EOF )
7053     {
7054         switch ( c )
7055         {
7056         case 'c':
7057             fCheck ^= 1;
7058             break;
7059         case 'v':
7060             fVerbose ^= 1;
7061             break;
7062         case 'h':
7063             goto usage;
7064         default:
7065             goto usage;
7066         }
7067     }
7068 //    pArgvNew = argv + globalUtilOptind;
7069 //    nArgcNew = argc - globalUtilOptind;
7070     if ( argc - globalUtilOptind < 2 || argc - globalUtilOptind > 3 )
7071     {
7072         Abc_Print( 1, "Expecting three file names on the command line.\n" );
7073         goto usage;
7074     }
7075     for ( c = 0; c < argc - globalUtilOptind; c++ )
7076         pFileNames[c] = argv[globalUtilOptind+c];
7077     Acb_NtkRunEco( pFileNames, fCheck, fVerbose );
7078     return 0;
7079 
7080 usage:
7081     Abc_Print( -2, "usage: runeco [-cvh] <implementation> <specification> <weights>\n" );
7082     Abc_Print( -2, "\t         performs computation of patch functions during ECO,\n" );
7083     Abc_Print( -2, "\t         as described in the following paper: A. Q. Dao et al\n" );
7084     Abc_Print( -2, "\t         \"Efficient computation of ECO patch functions\", Proc. DAC\'18\n" );
7085     Abc_Print( -2, "\t         https://people.eecs.berkeley.edu/~alanmi/publications/2018/dac18_eco.pdf\n" );
7086     Abc_Print( -2, "\t         (currently only applicable to benchmarks from 2017 ICCAD CAD competition\n" );
7087     Abc_Print( -2, "\t         http://cad-contest-2017.el.cycu.edu.tw/Problem_A/default.html as follows:\n" );
7088     Abc_Print( -2, "\t         \"runeco unit1/F.v unit1/G.v unit1/weight.txt; cec -n out.v unit1/G.v\")\n" );
7089     Abc_Print( -2, "\t-c     : toggle checking that the problem has a solution [default = %s]\n", fCheck? "yes": "no" );
7090     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
7091     Abc_Print( -2, "\t-h     : print the command usage\n");
7092     return 1;
7093 }
7094 
7095 
7096 /**Function*************************************************************
7097 
7098   Synopsis    []
7099 
7100   Description []
7101 
7102   SideEffects []
7103 
7104   SeeAlso     []
7105 
7106 ***********************************************************************/
Abc_CommandRunGen(Abc_Frame_t * pAbc,int argc,char ** argv)7107 int Abc_CommandRunGen( Abc_Frame_t * pAbc, int argc, char ** argv )
7108 {
7109     extern void Acb_NtkRunGen( char * pFileNames[2], int fVerbose );
7110     char * pFileNames[4] = {NULL};
7111     int c, fVerbose = 0;
7112     Extra_UtilGetoptReset();
7113     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
7114     {
7115         switch ( c )
7116         {
7117         case 'v':
7118             fVerbose ^= 1;
7119             break;
7120         case 'h':
7121             goto usage;
7122         default:
7123             goto usage;
7124         }
7125     }
7126     if ( argc - globalUtilOptind != 2 )
7127     {
7128         Abc_Print( 1, "Expecting two file names on the command line.\n" );
7129         goto usage;
7130     }
7131     for ( c = 0; c < 2; c++ )
7132         pFileNames[c] = argv[globalUtilOptind+c];
7133     Acb_NtkRunGen( pFileNames, fVerbose );
7134     return 0;
7135 
7136 usage:
7137     Abc_Print( -2, "usage: rungen [-vh] <file1> <file2>\n" );
7138     Abc_Print( -2, "\t         experimental command\n" );
7139     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
7140     Abc_Print( -2, "\t-h     : print the command usage\n");
7141     return 1;
7142 }
7143 
7144 /**Function*************************************************************
7145 
7146   Synopsis    []
7147 
7148   Description []
7149 
7150   SideEffects []
7151 
7152   SeeAlso     []
7153 
7154 ***********************************************************************/
Abc_CommandRunSim(Abc_Frame_t * pAbc,int argc,char ** argv)7155 int Abc_CommandRunSim( Abc_Frame_t * pAbc, int argc, char ** argv )
7156 {
7157     extern void Acb_NtkRunSim( char * pFileName[4], int nWords, int nBeam, int LevL, int LevU, int fOrder, int fFancy, int fVerbose );
7158     char * pFileNames[4] = {NULL, NULL, "out.v", NULL};
7159     int c, nWords = 4, nBeam = 4, LevL = 0, LevU = 0, fOrder = 0, fFancy = 0, fVerbose = 0;
7160     Extra_UtilGetoptReset();
7161     while ( ( c = Extra_UtilGetopt( argc, argv, "WBLUofvh" ) ) != EOF )
7162     {
7163         switch ( c )
7164         {
7165         case 'W':
7166             if ( globalUtilOptind >= argc )
7167             {
7168                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
7169                 goto usage;
7170             }
7171             nWords = atoi(argv[globalUtilOptind]);
7172             globalUtilOptind++;
7173             if ( nWords < 0 )
7174                 goto usage;
7175             break;
7176         case 'B':
7177             if ( globalUtilOptind >= argc )
7178             {
7179                 Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" );
7180                 goto usage;
7181             }
7182             nBeam = atoi(argv[globalUtilOptind]);
7183             globalUtilOptind++;
7184             if ( nBeam < 0 )
7185                 goto usage;
7186             break;
7187         case 'L':
7188             if ( globalUtilOptind >= argc )
7189             {
7190                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
7191                 goto usage;
7192             }
7193             LevL = atoi(argv[globalUtilOptind]);
7194             globalUtilOptind++;
7195             if ( LevL < 0 )
7196                 goto usage;
7197             break;
7198         case 'U':
7199             if ( globalUtilOptind >= argc )
7200             {
7201                 Abc_Print( -1, "Command line switch \"-U\" should be followed by an integer.\n" );
7202                 goto usage;
7203             }
7204             LevU = atoi(argv[globalUtilOptind]);
7205             globalUtilOptind++;
7206             if ( LevU < 0 )
7207                 goto usage;
7208             break;
7209         case 'o':
7210             fOrder ^= 1;
7211             break;
7212         case 'f':
7213             fFancy ^= 1;
7214             break;
7215         case 'v':
7216             fVerbose ^= 1;
7217             break;
7218         case 'h':
7219             goto usage;
7220         default:
7221             goto usage;
7222         }
7223     }
7224     if ( argc - globalUtilOptind < 2 || argc - globalUtilOptind > 4 )
7225     {
7226         Abc_Print( 1, "Expecting two or three file names on the command line.\n" );
7227         goto usage;
7228     }
7229     Gia_ManRandom(1);
7230     for ( c = 0; c < argc - globalUtilOptind; c++ )
7231         pFileNames[c] = argv[globalUtilOptind+c];
7232     Acb_NtkRunSim( pFileNames, nWords, nBeam, LevL, LevU, fOrder, fFancy, fVerbose );
7233     return 0;
7234 
7235 usage:
7236     Abc_Print( -2, "usage: runsim [-WBLU] [-ofvh] [-N <num>] <file1> <file2> <file3>\n" );
7237     Abc_Print( -2, "\t           experimental simulation command\n" );
7238     Abc_Print( -2, "\t-W <num> : the number of words of simulation info [default = %d]\n", nWords );
7239     Abc_Print( -2, "\t-B <num> : the beam width parameter [default = %d]\n", nBeam );
7240     Abc_Print( -2, "\t-L <num> : the lower bound on level [default = %d]\n", LevL );
7241     Abc_Print( -2, "\t-U <num> : the upper bound on level [default = %d]\n", LevU );
7242     Abc_Print( -2, "\t-o       : toggle using a different node ordering [default = %s]\n", fOrder? "yes": "no" );
7243     Abc_Print( -2, "\t-f       : toggle using experimental feature [default = %s]\n",      fFancy? "yes": "no" );
7244     Abc_Print( -2, "\t-v       : toggle printing verbose information [default = %s]\n",    fVerbose? "yes": "no" );
7245     Abc_Print( -2, "\t-h       : print the command usage\n");
7246     return 1;
7247 }
7248 
7249 
7250 /**Function*************************************************************
7251 
7252   Synopsis    []
7253 
7254   Description []
7255 
7256   SideEffects []
7257 
7258   SeeAlso     []
7259 
7260 ***********************************************************************/
Abc_CommandRunTest(Abc_Frame_t * pAbc,int argc,char ** argv)7261 int Abc_CommandRunTest( Abc_Frame_t * pAbc, int argc, char ** argv )
7262 {
7263     extern void Acb_NtkRunTest( char * pFileNames[4], int fFancy, int fVerbose );
7264     char * pFileNames[4] = {NULL};
7265     int c, fFancy = 0, fVerbose = 0;
7266     Extra_UtilGetoptReset();
7267     while ( ( c = Extra_UtilGetopt( argc, argv, "fvh" ) ) != EOF )
7268     {
7269         switch ( c )
7270         {
7271         case 'f':
7272             fFancy ^= 1;
7273             break;
7274         case 'v':
7275             fVerbose ^= 1;
7276             break;
7277         case 'h':
7278             goto usage;
7279         default:
7280             goto usage;
7281         }
7282     }
7283     if ( argc - globalUtilOptind < 2 || argc - globalUtilOptind > 5 )
7284     {
7285         Abc_Print( 1, "Expecting two or three file names on the command line.\n" );
7286         goto usage;
7287     }
7288     for ( c = 0; c < argc - globalUtilOptind; c++ )
7289         pFileNames[c] = argv[globalUtilOptind+c];
7290     Acb_NtkRunTest( pFileNames, fFancy, fVerbose );
7291     return 0;
7292 
7293 usage:
7294     Abc_Print( -2, "usage: runtest [-fvh] <file1> <file2>\n" );
7295     Abc_Print( -2, "\t           experimental simulation command\n" );
7296     Abc_Print( -2, "\t-f       : toggle using experimental feature [default = %s]\n",      fFancy? "yes": "no" );
7297     Abc_Print( -2, "\t-v       : toggle printing verbose information [default = %s]\n",    fVerbose? "yes": "no" );
7298     Abc_Print( -2, "\t-h       : print the command usage\n");
7299     return 1;
7300 }
7301 
7302 
7303 
7304 /**Function*************************************************************
7305 
7306   Synopsis    []
7307 
7308   Description []
7309 
7310   SideEffects []
7311 
7312   SeeAlso     []
7313 
7314 ***********************************************************************/
Abc_CommandRewrite(Abc_Frame_t * pAbc,int argc,char ** argv)7315 int Abc_CommandRewrite( Abc_Frame_t * pAbc, int argc, char ** argv )
7316 {
7317     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
7318     int c;
7319     int fUpdateLevel;
7320     int fPrecompute;
7321     int fUseZeros;
7322     int fVerbose;
7323     int fVeryVerbose;
7324     int fPlaceEnable;
7325     // external functions
7326     extern void Rwr_Precompute();
7327 
7328     // set defaults
7329     fUpdateLevel = 1;
7330     fPrecompute  = 0;
7331     fUseZeros    = 0;
7332     fVerbose     = 0;
7333     fVeryVerbose = 0;
7334     fPlaceEnable = 0;
7335     Extra_UtilGetoptReset();
7336     while ( ( c = Extra_UtilGetopt( argc, argv, "lxzvwh" ) ) != EOF )
7337     {
7338         switch ( c )
7339         {
7340         case 'l':
7341             fUpdateLevel ^= 1;
7342             break;
7343         case 'x':
7344             fPrecompute ^= 1;
7345             break;
7346         case 'z':
7347             fUseZeros ^= 1;
7348             break;
7349         case 'v':
7350             fVerbose ^= 1;
7351             break;
7352         case 'w':
7353             fVeryVerbose ^= 1;
7354             break;
7355         case 'p':
7356             fPlaceEnable ^= 1;
7357             break;
7358         case 'h':
7359             goto usage;
7360         default:
7361             goto usage;
7362         }
7363     }
7364 
7365     if ( fPrecompute )
7366     {
7367         Rwr_Precompute();
7368         return 0;
7369     }
7370 
7371     if ( pNtk == NULL )
7372     {
7373         Abc_Print( -1, "Empty network.\n" );
7374         return 1;
7375     }
7376     if ( !Abc_NtkIsStrash(pNtk) )
7377     {
7378         Abc_Print( -1, "This command can only be applied to an AIG (run \"strash\").\n" );
7379         return 1;
7380     }
7381     if ( Abc_NtkGetChoiceNum(pNtk) )
7382     {
7383         Abc_Print( -1, "AIG resynthesis cannot be applied to AIGs with choice nodes.\n" );
7384         return 1;
7385     }
7386 
7387     // modify the current network
7388     if ( !Abc_NtkRewrite( pNtk, fUpdateLevel, fUseZeros, fVerbose, fVeryVerbose, fPlaceEnable ) )
7389     {
7390         Abc_Print( -1, "Rewriting has failed.\n" );
7391         return 1;
7392     }
7393     return 0;
7394 
7395 usage:
7396     Abc_Print( -2, "usage: rewrite [-lzvwh]\n" );
7397     Abc_Print( -2, "\t         performs technology-independent rewriting of the AIG\n" );
7398     Abc_Print( -2, "\t-l     : toggle preserving the number of levels [default = %s]\n", fUpdateLevel? "yes": "no" );
7399     Abc_Print( -2, "\t-z     : toggle using zero-cost replacements [default = %s]\n", fUseZeros? "yes": "no" );
7400     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
7401     Abc_Print( -2, "\t-w     : toggle printout subgraph statistics [default = %s]\n", fVeryVerbose? "yes": "no" );
7402 //    Abc_Print( -2, "\t-p     : toggle placement-aware rewriting [default = %s]\n", fPlaceEnable? "yes": "no" );
7403     Abc_Print( -2, "\t-h     : print the command usage\n");
7404     return 1;
7405 }
7406 
7407 /**Function*************************************************************
7408 
7409   Synopsis    []
7410 
7411   Description []
7412 
7413   SideEffects []
7414 
7415   SeeAlso     []
7416 
7417 ***********************************************************************/
Abc_CommandRefactor(Abc_Frame_t * pAbc,int argc,char ** argv)7418 int Abc_CommandRefactor( Abc_Frame_t * pAbc, int argc, char ** argv )
7419 {
7420     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
7421     int c;
7422     int nNodeSizeMax;
7423     int nConeSizeMax;
7424     int fUpdateLevel;
7425     int fUseZeros;
7426     int fUseDcs;
7427     int fVerbose;
7428     extern int Abc_NtkRefactor( Abc_Ntk_t * pNtk, int nNodeSizeMax, int nConeSizeMax, int fUpdateLevel, int fUseZeros, int fUseDcs, int fVerbose );
7429 
7430     // set defaults
7431     nNodeSizeMax = 10;
7432     nConeSizeMax = 16;
7433     fUpdateLevel =  1;
7434     fUseZeros    =  0;
7435     fUseDcs      =  0;
7436     fVerbose     =  0;
7437     Extra_UtilGetoptReset();
7438     while ( ( c = Extra_UtilGetopt( argc, argv, "Nlzvh" ) ) != EOF )
7439     {
7440         switch ( c )
7441         {
7442         case 'N':
7443             if ( globalUtilOptind >= argc )
7444             {
7445                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
7446                 goto usage;
7447             }
7448             nNodeSizeMax = atoi(argv[globalUtilOptind]);
7449             globalUtilOptind++;
7450             if ( nNodeSizeMax < 0 )
7451                 goto usage;
7452             break;
7453         case 'C':
7454             if ( globalUtilOptind >= argc )
7455             {
7456                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
7457                 goto usage;
7458             }
7459             nConeSizeMax = atoi(argv[globalUtilOptind]);
7460             globalUtilOptind++;
7461             if ( nConeSizeMax < 0 )
7462                 goto usage;
7463             break;
7464         case 'l':
7465             fUpdateLevel ^= 1;
7466             break;
7467         case 'z':
7468             fUseZeros ^= 1;
7469             break;
7470         case 'd':
7471             fUseDcs ^= 1;
7472             break;
7473         case 'v':
7474             fVerbose ^= 1;
7475             break;
7476         case 'h':
7477             goto usage;
7478         default:
7479             goto usage;
7480         }
7481     }
7482 
7483     if ( pNtk == NULL )
7484     {
7485         Abc_Print( -1, "Empty network.\n" );
7486         return 1;
7487     }
7488     if ( !Abc_NtkIsStrash(pNtk) )
7489     {
7490         Abc_Print( -1, "This command can only be applied to an AIG (run \"strash\").\n" );
7491         return 1;
7492     }
7493     if ( Abc_NtkGetChoiceNum(pNtk) )
7494     {
7495         Abc_Print( -1, "AIG resynthesis cannot be applied to AIGs with choice nodes.\n" );
7496         return 1;
7497     }
7498     if ( nNodeSizeMax > 15 )
7499     {
7500         Abc_Print( -1, "The cone size cannot exceed 15.\n" );
7501         return 1;
7502     }
7503 
7504     if ( fUseDcs && nNodeSizeMax >= nConeSizeMax )
7505     {
7506         Abc_Print( -1, "For don't-care to work, containing cone should be larger than collapsed node.\n" );
7507         return 1;
7508     }
7509 
7510     // modify the current network
7511     if ( !Abc_NtkRefactor( pNtk, nNodeSizeMax, nConeSizeMax, fUpdateLevel, fUseZeros, fUseDcs, fVerbose ) )
7512     {
7513         Abc_Print( -1, "Refactoring has failed.\n" );
7514         return 1;
7515     }
7516     return 0;
7517 
7518 usage:
7519     Abc_Print( -2, "usage: refactor [-N <num>] [-lzvh]\n" );
7520     Abc_Print( -2, "\t           performs technology-independent refactoring of the AIG\n" );
7521     Abc_Print( -2, "\t-N <num> : the max support of the collapsed node [default = %d]\n", nNodeSizeMax );
7522 //    Abc_Print( -2, "\t-C <num> : the max support of the containing cone [default = %d]\n", nConeSizeMax );
7523     Abc_Print( -2, "\t-l       : toggle preserving the number of levels [default = %s]\n", fUpdateLevel? "yes": "no" );
7524     Abc_Print( -2, "\t-z       : toggle using zero-cost replacements [default = %s]\n", fUseZeros? "yes": "no" );
7525 //    Abc_Print( -2, "\t-d       : toggle using don't-cares [default = %s]\n", fUseDcs? "yes": "no" );
7526     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
7527     Abc_Print( -2, "\t-h       : print the command usage\n");
7528     return 1;
7529 }
7530 
7531 /**Function*************************************************************
7532 
7533   Synopsis    []
7534 
7535   Description []
7536 
7537   SideEffects []
7538 
7539   SeeAlso     []
7540 
7541 ***********************************************************************/
Abc_CommandRestructure(Abc_Frame_t * pAbc,int argc,char ** argv)7542 int Abc_CommandRestructure( Abc_Frame_t * pAbc, int argc, char ** argv )
7543 {
7544     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
7545     int c;
7546     int nCutsMax;
7547     int fUpdateLevel;
7548     int fUseZeros;
7549     int fVerbose;
7550     extern int Abc_NtkRestructure( Abc_Ntk_t * pNtk, int nCutsMax, int fUpdateLevel, int fUseZeros, int fVerbose );
7551 
7552     // set defaults
7553     nCutsMax      =  5;
7554     fUpdateLevel =  0;
7555     fUseZeros    =  0;
7556     fVerbose     =  0;
7557     Extra_UtilGetoptReset();
7558     while ( ( c = Extra_UtilGetopt( argc, argv, "Klzvh" ) ) != EOF )
7559     {
7560         switch ( c )
7561         {
7562         case 'K':
7563             if ( globalUtilOptind >= argc )
7564             {
7565                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
7566                 goto usage;
7567             }
7568             nCutsMax = atoi(argv[globalUtilOptind]);
7569             globalUtilOptind++;
7570             if ( nCutsMax < 0 )
7571                 goto usage;
7572             break;
7573         case 'l':
7574             fUpdateLevel ^= 1;
7575             break;
7576         case 'z':
7577             fUseZeros ^= 1;
7578             break;
7579         case 'v':
7580             fVerbose ^= 1;
7581             break;
7582         case 'h':
7583             goto usage;
7584         default:
7585             goto usage;
7586         }
7587     }
7588 
7589     if ( pNtk == NULL )
7590     {
7591         Abc_Print( -1, "Empty network.\n" );
7592         return 1;
7593     }
7594     if ( nCutsMax < 4 || nCutsMax > CUT_SIZE_MAX )
7595     {
7596         Abc_Print( -1, "Can only compute the cuts for %d <= K <= %d.\n", 4, CUT_SIZE_MAX );
7597         return 1;
7598     }
7599     if ( !Abc_NtkIsStrash(pNtk) )
7600     {
7601         Abc_Print( -1, "This command can only be applied to an AIG (run \"strash\").\n" );
7602         return 1;
7603     }
7604     if ( Abc_NtkGetChoiceNum(pNtk) )
7605     {
7606         Abc_Print( -1, "AIG resynthesis cannot be applied to AIGs with choice nodes.\n" );
7607         return 1;
7608     }
7609 
7610     // modify the current network
7611     if ( !Abc_NtkRestructure( pNtk, nCutsMax, fUpdateLevel, fUseZeros, fVerbose ) )
7612     {
7613         Abc_Print( -1, "Refactoring has failed.\n" );
7614         return 1;
7615     }
7616     return 0;
7617 
7618 usage:
7619     Abc_Print( -2, "usage: restructure [-K <num>] [-lzvh]\n" );
7620     Abc_Print( -2, "\t           performs technology-independent restructuring of the AIG\n" );
7621     Abc_Print( -2, "\t-K <num> : the max cut size (%d <= num <= %d) [default = %d]\n",   CUT_SIZE_MIN, CUT_SIZE_MAX, nCutsMax );
7622     Abc_Print( -2, "\t-l       : toggle preserving the number of levels [default = %s]\n", fUpdateLevel? "yes": "no" );
7623     Abc_Print( -2, "\t-z       : toggle using zero-cost replacements [default = %s]\n", fUseZeros? "yes": "no" );
7624     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
7625     Abc_Print( -2, "\t-h       : print the command usage\n");
7626     return 1;
7627 }
7628 
7629 /**Function*************************************************************
7630 
7631   Synopsis    []
7632 
7633   Description []
7634 
7635   SideEffects []
7636 
7637   SeeAlso     []
7638 
7639 ***********************************************************************/
Abc_CommandResubstitute(Abc_Frame_t * pAbc,int argc,char ** argv)7640 int Abc_CommandResubstitute( Abc_Frame_t * pAbc, int argc, char ** argv )
7641 {
7642     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
7643     int RS_CUT_MIN =  4;
7644     int RS_CUT_MAX = 16;
7645     int c;
7646     int nCutsMax;
7647     int nNodesMax;
7648     int nLevelsOdc;
7649     int fUpdateLevel;
7650     int fUseZeros;
7651     int fVerbose;
7652     int fVeryVerbose;
7653     extern int Abc_NtkResubstitute( Abc_Ntk_t * pNtk, int nCutsMax, int nNodesMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose );
7654 
7655     // set defaults
7656     nCutsMax     =  8;
7657     nNodesMax    =  1;
7658     nLevelsOdc   =  0;
7659     fUpdateLevel =  1;
7660     fUseZeros    =  0;
7661     fVerbose     =  0;
7662     fVeryVerbose =  0;
7663     Extra_UtilGetoptReset();
7664     while ( ( c = Extra_UtilGetopt( argc, argv, "KNFlzvwh" ) ) != EOF )
7665     {
7666         switch ( c )
7667         {
7668         case 'K':
7669             if ( globalUtilOptind >= argc )
7670             {
7671                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
7672                 goto usage;
7673             }
7674             nCutsMax = atoi(argv[globalUtilOptind]);
7675             globalUtilOptind++;
7676             if ( nCutsMax < 0 )
7677                 goto usage;
7678             break;
7679         case 'N':
7680             if ( globalUtilOptind >= argc )
7681             {
7682                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
7683                 goto usage;
7684             }
7685             nNodesMax = atoi(argv[globalUtilOptind]);
7686             globalUtilOptind++;
7687             if ( nNodesMax < 0 )
7688                 goto usage;
7689             break;
7690         case 'F':
7691             if ( globalUtilOptind >= argc )
7692             {
7693                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
7694                 goto usage;
7695             }
7696             nLevelsOdc = atoi(argv[globalUtilOptind]);
7697             globalUtilOptind++;
7698             if ( nLevelsOdc < 0 )
7699                 goto usage;
7700             break;
7701         case 'l':
7702             fUpdateLevel ^= 1;
7703             break;
7704         case 'z':
7705             fUseZeros ^= 1;
7706             break;
7707         case 'v':
7708             fVerbose ^= 1;
7709             break;
7710         case 'w':
7711             fVeryVerbose ^= 1;
7712             break;
7713         case 'h':
7714             goto usage;
7715         default:
7716             goto usage;
7717         }
7718     }
7719 
7720     if ( pNtk == NULL )
7721     {
7722         Abc_Print( -1, "Empty network.\n" );
7723         return 1;
7724     }
7725     if ( nCutsMax < RS_CUT_MIN || nCutsMax > RS_CUT_MAX )
7726     {
7727         Abc_Print( -1, "Can only compute cuts for %d <= K <= %d.\n", RS_CUT_MIN, RS_CUT_MAX );
7728         return 1;
7729     }
7730     if ( nNodesMax < 0 || nNodesMax > 3 )
7731     {
7732         Abc_Print( -1, "Can only resubstitute at most 3 nodes.\n" );
7733         return 1;
7734     }
7735     if ( !Abc_NtkIsStrash(pNtk) )
7736     {
7737         Abc_Print( -1, "This command can only be applied to an AIG (run \"strash\").\n" );
7738         return 1;
7739     }
7740     if ( Abc_NtkGetChoiceNum(pNtk) )
7741     {
7742         Abc_Print( -1, "AIG resynthesis cannot be applied to AIGs with choice nodes.\n" );
7743         return 1;
7744     }
7745 
7746     // modify the current network
7747     if ( !Abc_NtkResubstitute( pNtk, nCutsMax, nNodesMax, nLevelsOdc, fUpdateLevel, fVerbose, fVeryVerbose ) )
7748     {
7749         Abc_Print( -1, "Refactoring has failed.\n" );
7750         return 1;
7751     }
7752     return 0;
7753 
7754 usage:
7755     Abc_Print( -2, "usage: resub [-KN <num>] [-lzvwh]\n" );
7756     Abc_Print( -2, "\t           performs technology-independent restructuring of the AIG\n" );
7757     Abc_Print( -2, "\t-K <num> : the max cut size (%d <= num <= %d) [default = %d]\n", RS_CUT_MIN, RS_CUT_MAX, nCutsMax );
7758     Abc_Print( -2, "\t-N <num> : the max number of nodes to add (0 <= num <= 3) [default = %d]\n", nNodesMax );
7759     Abc_Print( -2, "\t-F <num> : the number of fanout levels for ODC computation [default = %d]\n", nLevelsOdc );
7760     Abc_Print( -2, "\t-l       : toggle preserving the number of levels [default = %s]\n", fUpdateLevel? "yes": "no" );
7761     Abc_Print( -2, "\t-z       : toggle using zero-cost replacements [default = %s]\n", fUseZeros? "yes": "no" );
7762     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
7763     Abc_Print( -2, "\t-w       : toggle verbose printout of ODC computation [default = %s]\n", fVeryVerbose? "yes": "no" );
7764     Abc_Print( -2, "\t-h       : print the command usage\n");
7765     return 1;
7766 }
7767 
7768 /**Function*************************************************************
7769 
7770   Synopsis    []
7771 
7772   Description []
7773 
7774   SideEffects []
7775 
7776   SeeAlso     []
7777 
7778 ***********************************************************************/
Abc_CommandRr(Abc_Frame_t * pAbc,int argc,char ** argv)7779 int Abc_CommandRr( Abc_Frame_t * pAbc, int argc, char ** argv )
7780 {
7781     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
7782     int c, Window;
7783     int nFaninLevels;
7784     int nFanoutLevels;
7785     int fUseFanouts;
7786     int fVerbose;
7787     extern int Abc_NtkRR( Abc_Ntk_t * pNtk, int nFaninLevels, int nFanoutLevels, int fUseFanouts, int fVerbose );
7788 
7789     // set defaults
7790     nFaninLevels  = 3;
7791     nFanoutLevels = 3;
7792     fUseFanouts   = 0;
7793     fVerbose      = 0;
7794     Extra_UtilGetoptReset();
7795     while ( ( c = Extra_UtilGetopt( argc, argv, "Wfvh" ) ) != EOF )
7796     {
7797         switch ( c )
7798         {
7799         case 'W':
7800             if ( globalUtilOptind >= argc )
7801             {
7802                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
7803                 goto usage;
7804             }
7805             Window = atoi(argv[globalUtilOptind]);
7806             globalUtilOptind++;
7807             if ( Window < 0 )
7808                 goto usage;
7809             nFaninLevels  = Window / 10;
7810             nFanoutLevels = Window % 10;
7811             break;
7812         case 'f':
7813             fUseFanouts ^= 1;
7814             break;
7815         case 'v':
7816             fVerbose ^= 1;
7817             break;
7818         case 'h':
7819             goto usage;
7820         default:
7821             goto usage;
7822         }
7823     }
7824 
7825     printf( "This command is obsolete." );
7826     printf( "To perform pure redudancy removal, try \"mfs -r\".\n" );
7827     printf( "To perform something a little stronger try \"mfs2\"\n" );
7828     printf( "When working with an AIG, use \"logic\" before and \"strash\" after this command.\n" );
7829     return 0;
7830 
7831     if ( pNtk == NULL )
7832     {
7833         Abc_Print( -1, "Empty network.\n" );
7834         return 1;
7835     }
7836     if ( !Abc_NtkIsStrash(pNtk) )
7837     {
7838         Abc_Print( -1, "This command can only be applied to an AIG (run \"strash\").\n" );
7839         return 1;
7840     }
7841     if ( Abc_NtkGetChoiceNum(pNtk) )
7842     {
7843         Abc_Print( -1, "AIG resynthesis cannot be applied to AIGs with choice nodes.\n" );
7844         return 1;
7845     }
7846 
7847     // modify the current network
7848     if ( !Abc_NtkRR( pNtk, nFaninLevels, nFanoutLevels, fUseFanouts, fVerbose ) )
7849     {
7850         Abc_Print( -1, "Redundancy removal has failed.\n" );
7851         return 1;
7852     }
7853     return 0;
7854 
7855 usage:
7856     Abc_Print( -2, "usage: rr [-W NM] [-fvh]\n" );
7857     Abc_Print( -2, "\t         removes combinational redundancies in the current network\n" );
7858     Abc_Print( -2, "\t-W NM  : window size: TFI (N) and TFO (M) logic levels [default = %d%d]\n", nFaninLevels, nFanoutLevels );
7859     Abc_Print( -2, "\t-f     : toggle RR w.r.t. fanouts [default = %s]\n", fUseFanouts? "yes": "no" );
7860     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
7861     Abc_Print( -2, "\t-h     : print the command usage\n");
7862     return 1;
7863 }
7864 
7865 /**Function*************************************************************
7866 
7867   Synopsis    []
7868 
7869   Description []
7870 
7871   SideEffects []
7872 
7873   SeeAlso     []
7874 
7875 ***********************************************************************/
Abc_CommandCascade(Abc_Frame_t * pAbc,int argc,char ** argv)7876 int Abc_CommandCascade( Abc_Frame_t * pAbc, int argc, char ** argv )
7877 {
7878     Abc_Ntk_t * pNtk, * pNtkRes;
7879     int c, nLutSize;
7880     int fCheck;
7881     int fVerbose;
7882     extern Abc_Ntk_t * Abc_NtkCascade( Abc_Ntk_t * pNtk, int nLutSize, int fCheck, int fVerbose );
7883     pNtk = Abc_FrameReadNtk(pAbc);
7884 
7885     // set defaults
7886     nLutSize = 12;
7887     fCheck   = 0;
7888     fVerbose = 0;
7889     Extra_UtilGetoptReset();
7890     while ( ( c = Extra_UtilGetopt( argc, argv, "Kcvh" ) ) != EOF )
7891     {
7892         switch ( c )
7893         {
7894         case 'K':
7895             if ( globalUtilOptind >= argc )
7896             {
7897                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
7898                 goto usage;
7899             }
7900             nLutSize = atoi(argv[globalUtilOptind]);
7901             globalUtilOptind++;
7902             if ( nLutSize < 0 )
7903                 goto usage;
7904             break;
7905         case 'c':
7906             fCheck ^= 1;
7907             break;
7908         case 'v':
7909             fVerbose ^= 1;
7910             break;
7911         case 'h':
7912             goto usage;
7913         default:
7914             goto usage;
7915         }
7916     }
7917 
7918     if ( pNtk == NULL )
7919     {
7920         Abc_Print( -1, "Empty network.\n" );
7921         return 1;
7922     }
7923 
7924     if ( !Abc_NtkIsLogic(pNtk) && !Abc_NtkIsStrash(pNtk) )
7925     {
7926         Abc_Print( -1, "Can only collapse a logic network or an AIG.\n" );
7927         return 1;
7928     }
7929 
7930     // get the new network
7931     if ( Abc_NtkIsStrash(pNtk) )
7932         pNtkRes = Abc_NtkCascade( pNtk, nLutSize, fCheck, fVerbose );
7933     else
7934     {
7935         pNtk = Abc_NtkStrash( pNtk, 0, 0, 0 );
7936         pNtkRes = Abc_NtkCascade( pNtk, nLutSize, fCheck, fVerbose );
7937         Abc_NtkDelete( pNtk );
7938     }
7939     if ( pNtkRes == NULL )
7940     {
7941         Abc_Print( -1, "Cascade synthesis has failed.\n" );
7942         return 1;
7943     }
7944     // replace the current network
7945     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
7946     return 0;
7947 
7948 usage:
7949     Abc_Print( -2, "usage: cascade [-K <num>] [-cvh]\n" );
7950     Abc_Print( -2, "\t           performs LUT cascade synthesis for the current network\n" );
7951     Abc_Print( -2, "\t-K <num> : the number of LUT inputs [default = %d]\n", nLutSize );
7952     Abc_Print( -2, "\t-c       : check equivalence after synthesis [default = %s]\n", fCheck? "yes": "no" );
7953     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
7954     Abc_Print( -2, "\t-h       : print the command usage\n");
7955     Abc_Print( -2, "\t           \n");
7956     Abc_Print( -2, "  A lookup-table cascade is a programmable architecture developed by\n");
7957     Abc_Print( -2, "  Professor Tsutomu Sasao (sasao@cse.kyutech.ac.jp) at Kyushu Institute\n");
7958     Abc_Print( -2, "  of Technology. This work received Takeda Techno-Entrepreneurship Award:\n");
7959     Abc_Print( -2, "  http://www.lsi-cad.com/sasao/photo/takeda.html\n");
7960     return 1;
7961 }
7962 
7963 /**Function*************************************************************
7964 
7965   Synopsis    []
7966 
7967   Description []
7968 
7969   SideEffects []
7970 
7971   SeeAlso     []
7972 
7973 ***********************************************************************/
Abc_CommandExtract(Abc_Frame_t * pAbc,int argc,char ** argv)7974 int Abc_CommandExtract( Abc_Frame_t * pAbc, int argc, char ** argv )
7975 {
7976     extern Abc_Ntk_t * Abc_NtkShareXor( Abc_Ntk_t * pNtk, int nMultiSize, int fAnd, int fVerbose );
7977     Abc_Ntk_t * pNtk, * pNtkRes;
7978     int c, nMultiSize, fAnd, fVerbose;
7979     pNtk = Abc_FrameReadNtk(pAbc);
7980 
7981     // set defaults
7982     nMultiSize = 3;
7983     fAnd       = 0;
7984     fVerbose   = 0;
7985     Extra_UtilGetoptReset();
7986     while ( ( c = Extra_UtilGetopt( argc, argv, "Kavh" ) ) != EOF )
7987     {
7988         switch ( c )
7989         {
7990         case 'K':
7991             if ( globalUtilOptind >= argc )
7992             {
7993                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
7994                 goto usage;
7995             }
7996             nMultiSize = atoi(argv[globalUtilOptind]);
7997             globalUtilOptind++;
7998             if ( nMultiSize < 0 )
7999                 goto usage;
8000             break;
8001         case 'a':
8002             fAnd ^= 1;
8003             break;
8004         case 'v':
8005             fVerbose ^= 1;
8006             break;
8007         case 'h':
8008             goto usage;
8009         default:
8010             goto usage;
8011         }
8012     }
8013     if ( pNtk == NULL )
8014     {
8015         Abc_Print( -1, "Empty network.\n" );
8016         return 1;
8017     }
8018     if ( !Abc_NtkIsStrash(pNtk) )
8019     {
8020         Abc_Print( -1, "Can only collapse a logic network or an AIG.\n" );
8021         return 1;
8022     }
8023     // get the new network
8024     pNtkRes = Abc_NtkShareXor( pNtk, nMultiSize, fAnd, fVerbose );
8025     if ( pNtkRes == NULL )
8026     {
8027         Abc_Print( -1, "Cascade synthesis has failed.\n" );
8028         return 1;
8029     }
8030     // replace the current network
8031     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
8032     return 0;
8033 
8034 usage:
8035     Abc_Print( -2, "usage: extract [-K <num>] [-avh]\n" );
8036     Abc_Print( -2, "\t           extracts shared logic from multi-input gates\n" );
8037     Abc_Print( -2, "\t-K <num> : the minimum gate size to consider for extraction [default = %d]\n", nMultiSize );
8038     Abc_Print( -2, "\t-a       : toggle multi-input XOR vs multi-input AND [default = %s]\n", fAnd? "AND": "XOR" );
8039     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
8040     Abc_Print( -2, "\t-h       : print the command usage\n");
8041     return 1;
8042 }
8043 
8044 /**Function*************************************************************
8045 
8046   Synopsis    []
8047 
8048   Description []
8049 
8050   SideEffects []
8051 
8052   SeeAlso     []
8053 
8054 ***********************************************************************/
Abc_CommandVarMin(Abc_Frame_t * pAbc,int argc,char ** argv)8055 int Abc_CommandVarMin( Abc_Frame_t * pAbc, int argc, char ** argv )
8056 {
8057     extern void Abc_SuppTest( int nOnes, int nVars, int fUseSimple, int fCheck, int fVerbose );
8058     extern void Abc_SuppReadMinTest( char * pFileName );
8059     int nOnes      =  4;
8060     int nVars      = 20;
8061     int fUseSimple =  0;
8062     int fCheck     =  0;
8063     int fVerbose   =  0;
8064     int c;
8065     Extra_UtilGetoptReset();
8066     while ( ( c = Extra_UtilGetopt( argc, argv, "MNocvh" ) ) != EOF )
8067     {
8068         switch ( c )
8069         {
8070         case 'M':
8071             if ( globalUtilOptind >= argc )
8072             {
8073                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
8074                 goto usage;
8075             }
8076             nOnes = atoi(argv[globalUtilOptind]);
8077             globalUtilOptind++;
8078             if ( nOnes < 0 )
8079                 goto usage;
8080             break;
8081         case 'N':
8082             if ( globalUtilOptind >= argc )
8083             {
8084                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
8085                 goto usage;
8086             }
8087             nVars = atoi(argv[globalUtilOptind]);
8088             globalUtilOptind++;
8089             if ( nVars < 0 )
8090                 goto usage;
8091             break;
8092         case 'o':
8093             fUseSimple ^= 1;
8094             break;
8095         case 'c':
8096             fCheck ^= 1;
8097             break;
8098         case 'v':
8099             fVerbose ^= 1;
8100             break;
8101         case 'h':
8102             goto usage;
8103         default:
8104             goto usage;
8105         }
8106     }
8107     // get the file name
8108     if ( argc == globalUtilOptind + 1 )
8109     {
8110         Abc_SuppReadMinTest( argv[globalUtilOptind] );
8111         return 0;
8112     }
8113     Abc_SuppTest( nOnes, nVars, fUseSimple, fCheck, fVerbose );
8114     return 0;
8115 
8116 usage:
8117     Abc_Print( -2, "usage: varmin [-MN <num>] [-ocvh]\n" );
8118     Abc_Print( -2, "\t           performs support minimization\n" );
8119     Abc_Print( -2, "\t-M <num> : the number of ones in the combination [default = %d]\n", nOnes );
8120     Abc_Print( -2, "\t-N <num> : the number of variables in the problem [default = %d]\n", nVars );
8121     Abc_Print( -2, "\t-o       : toggle computing reduced difference matrix [default = %s]\n", fUseSimple? "yes": "no" );
8122     Abc_Print( -2, "\t-c       : toggle verifying the final result [default = %s]\n", fCheck? "yes": "no" );
8123     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
8124     Abc_Print( -2, "\t-h       : print the command usage\n");
8125     return 1;
8126 }
8127 
8128 /**Function*************************************************************
8129 
8130   Synopsis    []
8131 
8132   Description []
8133 
8134   SideEffects []
8135 
8136   SeeAlso     []
8137 
8138 ***********************************************************************/
Abc_CommandFaultClasses(Abc_Frame_t * pAbc,int argc,char ** argv)8139 int Abc_CommandFaultClasses( Abc_Frame_t * pAbc, int argc, char ** argv )
8140 {
8141     extern void Abc_NtkDetectClassesTest( Abc_Ntk_t * pNtk, int fSeq, int fVerbose, int fVeryVerbose );
8142     extern void Abc_NtkGenFaultList( Abc_Ntk_t * pNtk, char * pFileName, int fStuckAt );
8143     Abc_Ntk_t * pNtk;
8144     int c, fGen = 0, fStuckAt = 0, fSeq = 0, fVerbose = 0, fVeryVerbose = 0;
8145     pNtk = Abc_FrameReadNtk(pAbc);
8146     Extra_UtilGetoptReset();
8147     while ( ( c = Extra_UtilGetopt( argc, argv, "gcsvwh" ) ) != EOF )
8148     {
8149         switch ( c )
8150         {
8151         case 'g':
8152             fGen ^= 1;
8153             break;
8154         case 'c':
8155             fStuckAt ^= 1;
8156             break;
8157         case 's':
8158             fSeq ^= 1;
8159             break;
8160         case 'v':
8161             fVerbose ^= 1;
8162             break;
8163         case 'w':
8164             fVeryVerbose ^= 1;
8165             break;
8166         case 'h':
8167             goto usage;
8168         default:
8169             goto usage;
8170         }
8171     }
8172     if ( pNtk == NULL )
8173     {
8174         Abc_Print( -1, "Empty network.\n" );
8175         return 1;
8176     }
8177     if ( Abc_NtkIsStrash(pNtk) )
8178     {
8179         Abc_Print( -1, "Only applicable to a logic network.\n" );
8180         return 1;
8181     }
8182     if ( fGen )
8183     {
8184         char * pFileName = Extra_FileNameGenericAppend(Abc_NtkSpec(pNtk), "_faults.txt");
8185         Abc_NtkGenFaultList( pNtk, pFileName, fStuckAt );
8186     }
8187     else
8188         Abc_NtkDetectClassesTest( pNtk, fSeq, fVerbose, fVeryVerbose );
8189     return 0;
8190 
8191 usage:
8192     Abc_Print( -2, "usage: faultclasses [-gcsvwh]\n" );
8193     Abc_Print( -2, "\t           computes equivalence classes of faults in the given mapped netlist;\n" );
8194     Abc_Print( -2, "\t           the fault list with faults in the format: <fault_id> <node_name> <fault_name>\n" );
8195     Abc_Print( -2, "\t           should be read by command \"read_fins\" before calling this command\n" );
8196     Abc_Print( -2, "\t-g       : toggle generating a fault list for the current mapped network [default = %s]\n", fGen? "yes": "no" );
8197     Abc_Print( -2, "\t-c       : toggle using only stuck-at faults in the generated fault list [default = %s]\n", fStuckAt? "yes": "no" );
8198     Abc_Print( -2, "\t-s       : toggle detecting sequential equivalence classes [default = %s]\n", fSeq? "yes": "no" );
8199     Abc_Print( -2, "\t-v       : toggle verbose printout during computation [default = %s]\n", fVerbose? "yes": "no" );
8200     Abc_Print( -2, "\t-w       : toggle printing of resulting fault equivalence classes [default = %s]\n", fVeryVerbose? "yes": "no" );
8201     Abc_Print( -2, "\t-h       : print the command usage\n");
8202     return 1;
8203 }
8204 
8205 /**Function*************************************************************
8206 
8207   Synopsis    []
8208 
8209   Description []
8210 
8211   SideEffects []
8212 
8213   SeeAlso     []
8214 
8215 ***********************************************************************/
Abc_CommandExact(Abc_Frame_t * pAbc,int argc,char ** argv)8216 int Abc_CommandExact( Abc_Frame_t * pAbc, int argc, char ** argv )
8217 {
8218     extern Gia_Man_t * Gia_ManFindExact( word * pTruth, int nVars, int nFunc, int nMaxDepth, int * pArrivalTimes, int nBTLimit, int nStartGates, int fVerbose );
8219 
8220     int c, nMaxDepth = -1, fMakeAIG = 0, fTest = 0, fVerbose = 0, nVars = 0, nVarsTmp, nFunc = 0, nStartGates = 1, nBTLimit = 400000;
8221     char * p1, * p2;
8222     word pTruth[64];
8223     int pArrTimeProfile[8], fHasArrTimeProfile = 0;
8224     Abc_Ntk_t * pNtkRes;
8225     Gia_Man_t * pGiaRes;
8226 
8227     Extra_UtilGetoptReset();
8228     while ( ( c = Extra_UtilGetopt( argc, argv, "DASCatvh" ) ) != EOF )
8229     {
8230         switch ( c )
8231         {
8232         case 'D':
8233             if ( globalUtilOptind >= argc )
8234             {
8235                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
8236                 goto usage;
8237             }
8238             nMaxDepth = atoi(argv[globalUtilOptind]);
8239             globalUtilOptind++;
8240             if ( nMaxDepth < 0 )
8241                 goto usage;
8242             break;
8243         case 'A':
8244             if ( globalUtilOptind >= argc )
8245             {
8246                 Abc_Print( -1, "Command line switch \"-A\" should be followed by an integer.\n" );
8247                 goto usage;
8248             }
8249             fHasArrTimeProfile = 1;
8250             p1 = p2 = argv[globalUtilOptind++];
8251             while ( true ) {
8252                 if ( *p2 == ',' )
8253                 {
8254                     *p2 = '\0';
8255                     pArrTimeProfile[nVars++] = atoi( p1 );
8256                     *p2++ = ',';
8257                     p1 = p2;
8258                 }
8259                 else if ( *p2 == '\0' )
8260                 {
8261                     pArrTimeProfile[nVars++] = atoi( p1 );
8262                     break;
8263                 }
8264                 else
8265                     ++p2;
8266             }
8267             break;
8268         case 'S':
8269             if ( globalUtilOptind >= argc )
8270             {
8271                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
8272                 goto usage;
8273             }
8274             nStartGates = atoi(argv[globalUtilOptind]);
8275             globalUtilOptind++;
8276             if ( nStartGates < 1 )
8277                 goto usage;
8278             break;
8279         case 'C':
8280             if ( globalUtilOptind >= argc )
8281             {
8282                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
8283                 goto usage;
8284             }
8285             nBTLimit = atoi(argv[globalUtilOptind]);
8286             globalUtilOptind++;
8287             break;
8288         case 'a':
8289             fMakeAIG ^= 1;
8290             break;
8291         case 't':
8292             fTest ^= 1;
8293             break;
8294         case 'v':
8295             fVerbose ^= 1;
8296             break;
8297         case 'h':
8298             goto usage;
8299         default:
8300             goto usage;
8301         }
8302     }
8303 
8304     if ( fTest )
8305     {
8306         extern void Abc_ExactTest( int fVerbose );
8307         extern void Abc_ExactStoreTest( int fVerbose );
8308 
8309         printf( "run test suite, ignore all other settings\n" );
8310         Abc_ExactTest( fVerbose );
8311         Abc_ExactStoreTest( fVerbose );
8312         return 0;
8313     }
8314 
8315     if ( argc == globalUtilOptind )
8316         goto usage;
8317 
8318     memset( pTruth, 0, 64 * sizeof(word) );
8319     while ( globalUtilOptind < argc )
8320     {
8321         if ( nFunc == 16 )
8322         {
8323             Abc_Print( -1, "Too many functions (at most 16 supported).\n" );
8324             goto usage;
8325         }
8326         nVarsTmp = Abc_TtReadHex( &pTruth[nFunc << 2], argv[globalUtilOptind++] );
8327         nFunc++;
8328         if ( nVars == 0 )
8329             nVars = nVarsTmp;
8330         else if ( nVars > 8 )
8331         {
8332             Abc_Print( -1, "Only 8-variable functions are supported.\n" );
8333             goto usage;
8334         }
8335         else if ( nVars != nVarsTmp )
8336         {
8337             Abc_Print( -1, "All functions need to have the same size.\n" );
8338             goto usage;
8339         }
8340     }
8341 
8342     if ( fMakeAIG )
8343     {
8344         pGiaRes = Gia_ManFindExact( pTruth, nVars, nFunc, nMaxDepth, fHasArrTimeProfile ? pArrTimeProfile : NULL, nBTLimit, nStartGates - 1, fVerbose );
8345         if ( pGiaRes )
8346             Abc_FrameUpdateGia( pAbc, pGiaRes );
8347         else
8348             Abc_Print( 0, "Could not find AIG within given resource constraints, retry with different value for -C.\n" );
8349     }
8350     else
8351     {
8352         pNtkRes = Abc_NtkFindExact( pTruth, nVars, nFunc, nMaxDepth, fHasArrTimeProfile ? pArrTimeProfile : NULL, nBTLimit, nStartGates - 1, fVerbose );
8353         if ( pNtkRes )
8354         {
8355             Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
8356             Abc_FrameClearVerifStatus( pAbc );
8357         }
8358         else
8359             Abc_Print( 0, "Could not find network within given resource constraints, retry with different value for -C.\n" );
8360     }
8361     return 0;
8362 
8363 usage:
8364     Abc_Print( -2, "usage: exact [-DSC <num>] [-A <list>] [-atvh] <truth1> <truth2> ...\n" );
8365     Abc_Print( -2, "\t           finds optimum networks using SAT-based exact synthesis for hex truth tables <truth1> <truth2> ...\n" );
8366     Abc_Print( -2, "\t-D <num>  : constrain maximum depth (if too low, algorithm may not terminate)\n" );
8367     Abc_Print( -2, "\t-A <list> : input arrival times (comma separated list)\n" );
8368     Abc_Print( -2, "\t-S <num>  : number of start gates in search [default = %d]\n", nStartGates );
8369     Abc_Print( -2, "\t-C <num>  : the limit on the number of conflicts; turn off with 0 [default = %d]\n", nBTLimit );
8370     Abc_Print( -2, "\t-a        : toggle create AIG [default = %s]\n", fMakeAIG ? "yes" : "no" );
8371     Abc_Print( -2, "\t-t        : run test suite\n" );
8372     Abc_Print( -2, "\t-v        : toggle verbose printout [default = %s]\n", fVerbose ? "yes" : "no" );
8373     Abc_Print( -2, "\t-h        : print the command usage\n" );
8374     Abc_Print( -2, "\t\n" );
8375     Abc_Print( -2, "\t            This command was contributed by Mathias Soeken from EPFL in July 2016.\n" );
8376     Abc_Print( -2, "\t            The author can be contacted as mathias.soeken at epfl.ch\n" );
8377     return 1;
8378 }
8379 
8380 /**Function*************************************************************
8381 
8382   Synopsis    []
8383 
8384   Description []
8385 
8386   SideEffects []
8387 
8388   SeeAlso     []
8389 
8390 ***********************************************************************/
Abc_CommandBmsStart(Abc_Frame_t * pAbc,int argc,char ** argv)8391 int Abc_CommandBmsStart( Abc_Frame_t * pAbc, int argc, char ** argv )
8392 {
8393     extern int Abc_ExactIsRunning();
8394     extern void Abc_ExactStart( int nBTLimit, int fMakeAIG, int fVerbose, int fVeryVerbose, const char *pFilename );
8395 
8396     int c, fMakeAIG = 0, fVerbose = 0, fVeryVerbose = 0, nBTLimit = 100;
8397     char * pFilename = NULL;
8398 
8399     Extra_UtilGetoptReset();
8400     while ( ( c = Extra_UtilGetopt( argc, argv, "Cavwh" ) ) != EOF )
8401     {
8402         switch ( c )
8403         {
8404         case 'C':
8405             if ( globalUtilOptind >= argc )
8406             {
8407                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
8408                 goto usage;
8409             }
8410             nBTLimit = atoi(argv[globalUtilOptind]);
8411             globalUtilOptind++;
8412             break;
8413         case 'a':
8414             fMakeAIG ^= 1;
8415             break;
8416         case 'v':
8417             fVerbose ^= 1;
8418             break;
8419         case 'w':
8420             fVeryVerbose ^= 1;
8421             break;
8422         case 'h':
8423             goto usage;
8424         default:
8425             goto usage;
8426         }
8427     }
8428 
8429     if ( argc > globalUtilOptind )
8430     {
8431         pFilename = argv[globalUtilOptind++];
8432     }
8433 
8434     if ( Abc_ExactIsRunning() )
8435     {
8436         Abc_Print( -1, "BMS manager is already started." );
8437         return 1;
8438     }
8439 
8440     Abc_ExactStart( nBTLimit, fMakeAIG, fVerbose, fVeryVerbose, pFilename );
8441     return 0;
8442 
8443 usage:
8444     Abc_Print( -2, "usage: bms_start [-C <num>] [-avwh] [<file>]\n" );
8445     Abc_Print( -2, "\t           starts BMS manager for recording optimum networks\n" );
8446     Abc_Print( -2, "\t           if <file> is specified, store entries are read from that file\n" );
8447     Abc_Print( -2, "\t-C <num> : the limit on the number of conflicts [default = %d]\n", nBTLimit );
8448     Abc_Print( -2, "\t-a       : toggle create AIG [default = %s]\n", fMakeAIG ? "yes" : "no" );
8449     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", fVerbose ? "yes" : "no" );
8450     Abc_Print( -2, "\t-w       : toggle very verbose printout [default = %s]\n", fVeryVerbose ? "yes" : "no" );
8451     Abc_Print( -2, "\t-h       : print the command usage\n" );
8452     Abc_Print( -2, "\t\n" );
8453     Abc_Print( -2, "\t           This command was contributed by Mathias Soeken from EPFL in July 2016.\n" );
8454     Abc_Print( -2, "\t           The author can be contacted as mathias.soeken at epfl.ch\n" );
8455     return 1;
8456 }
8457 
8458 /**Function*************************************************************
8459 
8460   Synopsis    []
8461 
8462   Description []
8463 
8464   SideEffects []
8465 
8466   SeeAlso     []
8467 
8468 ***********************************************************************/
Abc_CommandBmsStop(Abc_Frame_t * pAbc,int argc,char ** argv)8469 int Abc_CommandBmsStop( Abc_Frame_t * pAbc, int argc, char ** argv )
8470 {
8471     extern int Abc_ExactIsRunning();
8472     extern void Abc_ExactStop( const char *pFilename );
8473 
8474     int c;
8475     char * pFilename = NULL;
8476 
8477     Extra_UtilGetoptReset();
8478     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
8479     {
8480         switch ( c )
8481         {
8482         case 'h':
8483             goto usage;
8484         default:
8485             goto usage;
8486         }
8487     }
8488 
8489     if ( argc > globalUtilOptind )
8490     {
8491         pFilename = argv[globalUtilOptind++];
8492     }
8493 
8494     if ( !Abc_ExactIsRunning() )
8495     {
8496         Abc_Print( -1, "BMS manager is not started." );
8497         return 1;
8498     }
8499 
8500     Abc_ExactStop( pFilename );
8501     return 0;
8502 
8503 usage:
8504     Abc_Print( -2, "usage: bms_stop [-C <num>] [-vh] [<file>]\n" );
8505     Abc_Print( -2, "\t           stops BMS manager for recording optimum networks\n" );
8506     Abc_Print( -2, "\t           if <file> is specified, store entries are written to that file\n" );
8507     Abc_Print( -2, "\t-h       : print the command usage\n" );
8508     Abc_Print( -2, "\t\n" );
8509     Abc_Print( -2, "\t           This command was contributed by Mathias Soeken from EPFL in July 2016.\n" );
8510     Abc_Print( -2, "\t           The author can be contacted as mathias.soeken at epfl.ch\n" );
8511     return 1;
8512 }
8513 
8514 /**Function*************************************************************
8515 
8516   Synopsis    []
8517 
8518   Description []
8519 
8520   SideEffects []
8521 
8522   SeeAlso     []
8523 
8524 ***********************************************************************/
Abc_CommandBmsPs(Abc_Frame_t * pAbc,int argc,char ** argv)8525 int Abc_CommandBmsPs( Abc_Frame_t * pAbc, int argc, char ** argv )
8526 {
8527     extern int Abc_ExactIsRunning();
8528     extern void Abc_ExactStats();
8529 
8530     int c;
8531 
8532     Extra_UtilGetoptReset();
8533     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
8534     {
8535         switch ( c )
8536         {
8537         case 'h':
8538             goto usage;
8539         default:
8540             goto usage;
8541         }
8542     }
8543 
8544     if ( !Abc_ExactIsRunning() )
8545     {
8546         Abc_Print( -1, "BMS manager is not started." );
8547         return 1;
8548     }
8549 
8550     Abc_ExactStats();
8551     return 0;
8552 
8553 usage:
8554     Abc_Print( -2, "usage: bms_ps [-h]\n" );
8555     Abc_Print( -2, "\t           shows statistics about BMS manager\n" );
8556     Abc_Print( -2, "\t-h       : print the command usage\n" );
8557     Abc_Print( -2, "\t\n" );
8558     Abc_Print( -2, "\t           This command was contributed by Mathias Soeken from EPFL in July 2016.\n" );
8559     Abc_Print( -2, "\t           The author can be contacted as mathias.soeken at epfl.ch\n" );
8560     return 1;
8561 }
8562 
8563 /**Function*************************************************************
8564 
8565   Synopsis    []
8566 
8567   Description []
8568 
8569   SideEffects []
8570 
8571   SeeAlso     []
8572 
8573 ***********************************************************************/
Abc_CommandMajExact(Abc_Frame_t * pAbc,int argc,char ** argv)8574 int Abc_CommandMajExact( Abc_Frame_t * pAbc, int argc, char ** argv )
8575 {
8576     extern int Maj_ManExactSynthesis( int nVars, int nNodes, int fUseConst, int fUseLine, int fVerbose );
8577     extern int Maj_ManExactSynthesis2( int nVars, int nNodes, int fUseConst, int fUseLine, int fUseRand, int nRands, int fVerbose );
8578     int c, nVars = 3, nNodes = 1, fUseConst = 0, fUseLine = 0, fGlucose = 0, fUseRand = 0, nRands = 0, fVerbose = 1;
8579     Extra_UtilGetoptReset();
8580     while ( ( c = Extra_UtilGetopt( argc, argv, "INRfcrgvh" ) ) != EOF )
8581     {
8582         switch ( c )
8583         {
8584         case 'I':
8585             if ( globalUtilOptind >= argc )
8586             {
8587                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
8588                 goto usage;
8589             }
8590             nVars = atoi(argv[globalUtilOptind]);
8591             globalUtilOptind++;
8592             if ( nVars < 0 )
8593                 goto usage;
8594             break;
8595         case 'N':
8596             if ( globalUtilOptind >= argc )
8597             {
8598                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
8599                 goto usage;
8600             }
8601             nNodes = atoi(argv[globalUtilOptind]);
8602             globalUtilOptind++;
8603             if ( nNodes < 0 )
8604                 goto usage;
8605             break;
8606         case 'R':
8607             if ( globalUtilOptind >= argc )
8608             {
8609                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
8610                 goto usage;
8611             }
8612             nRands = atoi(argv[globalUtilOptind]);
8613             globalUtilOptind++;
8614             if ( nRands < 0 )
8615                 goto usage;
8616             break;
8617         case 'f':
8618             fUseConst ^= 1;
8619             break;
8620         case 'c':
8621             fUseLine ^= 1;
8622             break;
8623         case 'r':
8624             fUseRand ^= 1;
8625             break;
8626         case 'g':
8627             fGlucose ^= 1;
8628             break;
8629         case 'v':
8630             fVerbose ^= 1;
8631             break;
8632         case 'h':
8633             goto usage;
8634         default:
8635             goto usage;
8636         }
8637     }
8638     if ( (nVars & 1) == 0 )
8639     {
8640         Abc_Print( -1, "Cannot sythesize MAJ gate with an even number of inputs (%d).\n", nVars );
8641         return 1;
8642     }
8643     if ( fGlucose )
8644         Maj_ManExactSynthesis( nVars, nNodes, fUseConst, fUseLine, fVerbose );
8645     else
8646         Maj_ManExactSynthesis2( nVars, nNodes, fUseConst, fUseLine, fUseRand, nRands, fVerbose );
8647     return 0;
8648 
8649 usage:
8650     Abc_Print( -2, "usage: majexact [-INR <num>] [-fcrgvh]\n" );
8651     Abc_Print( -2, "\t           exact synthesis of multi-input MAJ using MAJ3 gates\n" );
8652     Abc_Print( -2, "\t-I <num> : the number of input variables [default = %d]\n", nVars );
8653     Abc_Print( -2, "\t-N <num> : the number of MAJ3 nodes [default = %d]\n", nNodes );
8654     Abc_Print( -2, "\t-R <num> : the number of additional connections [default = %d]\n", nRands );
8655     Abc_Print( -2, "\t-f       : toggle using constant fanins [default = %s]\n", fUseConst ? "yes" : "no" );
8656     Abc_Print( -2, "\t-c       : toggle using cascade topology [default = %s]\n", fUseLine ? "yes" : "no" );
8657     Abc_Print( -2, "\t-r       : toggle using random topology [default = %s]\n", fUseRand ? "yes" : "no" );
8658     Abc_Print( -2, "\t-g       : toggle using Glucose 3.0 by Gilles Audemard and Laurent Simon [default = %s]\n", fGlucose ? "yes" : "no" );
8659     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", fVerbose ? "yes" : "no" );
8660     Abc_Print( -2, "\t-h       : print the command usage\n" );
8661     return 1;
8662 }
8663 
8664 /**Function*************************************************************
8665 
8666   Synopsis    []
8667 
8668   Description []
8669 
8670   SideEffects []
8671 
8672   SeeAlso     []
8673 
8674 ***********************************************************************/
Abc_CommandTwoExact(Abc_Frame_t * pAbc,int argc,char ** argv)8675 int Abc_CommandTwoExact( Abc_Frame_t * pAbc, int argc, char ** argv )
8676 {
8677     extern void Exa_ManExactSynthesis( Bmc_EsPar_t * pPars );
8678     extern void Exa_ManExactSynthesis2( Bmc_EsPar_t * pPars );
8679     int c;
8680     Bmc_EsPar_t Pars, * pPars = &Pars;
8681     Bmc_EsParSetDefault( pPars );
8682     Extra_UtilGetoptReset();
8683     while ( ( c = Extra_UtilGetopt( argc, argv, "INTaogvh" ) ) != EOF )
8684     {
8685         switch ( c )
8686         {
8687         case 'I':
8688             if ( globalUtilOptind >= argc )
8689             {
8690                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
8691                 goto usage;
8692             }
8693             pPars->nVars = atoi(argv[globalUtilOptind]);
8694             globalUtilOptind++;
8695             if ( pPars->nVars < 0 )
8696                 goto usage;
8697             break;
8698         case 'N':
8699             if ( globalUtilOptind >= argc )
8700             {
8701                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
8702                 goto usage;
8703             }
8704             pPars->nNodes = atoi(argv[globalUtilOptind]);
8705             globalUtilOptind++;
8706             if ( pPars->nNodes < 0 )
8707                 goto usage;
8708             break;
8709         case 'T':
8710             if ( globalUtilOptind >= argc )
8711             {
8712                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
8713                 goto usage;
8714             }
8715             pPars->RuntimeLim = atoi(argv[globalUtilOptind]);
8716             globalUtilOptind++;
8717             if ( pPars->RuntimeLim < 0 )
8718                 goto usage;
8719             break;
8720         case 'a':
8721             pPars->fOnlyAnd ^= 1;
8722             break;
8723         case 'o':
8724             pPars->fFewerVars ^= 1;
8725             break;
8726         case 'g':
8727             pPars->fGlucose ^= 1;
8728             break;
8729         case 'v':
8730             pPars->fVerbose ^= 1;
8731             break;
8732         case 'h':
8733             goto usage;
8734         default:
8735             goto usage;
8736         }
8737     }
8738     if ( argc == globalUtilOptind + 1 )
8739         pPars->pTtStr = argv[globalUtilOptind];
8740     if ( pPars->pTtStr == NULL )
8741     {
8742         Abc_Print( -1, "Truth table should be given on the command line.\n" );
8743         return 1;
8744     }
8745     if ( (1 << (pPars->nVars-2)) != (int)strlen(pPars->pTtStr) )
8746     {
8747         Abc_Print( -1, "Truth table is expected to have %d hex digits (instead of %d).\n", (1 << (pPars->nVars-2)), strlen(pPars->pTtStr) );
8748         return 1;
8749     }
8750     if ( pPars->nVars > pPars->nNodes * (2 - 1) + 1 )
8751     {
8752         Abc_Print( -1, "Function with %d variales cannot be implemented with %d two-input gates.\n", pPars->nVars, pPars->nNodes );
8753         return 1;
8754     }
8755     if ( pPars->nVars > 10 )
8756     {
8757         Abc_Print( -1, "Function should not have more than 10 inputs.\n" );
8758         return 1;
8759     }
8760     if ( pPars->fGlucose )
8761         Exa_ManExactSynthesis( pPars );
8762     else
8763         Exa_ManExactSynthesis2( pPars );
8764     return 0;
8765 
8766 usage:
8767     Abc_Print( -2, "usage: twoexact [-INT <num>] [-aogvh] <hex>\n" );
8768     Abc_Print( -2, "\t           exact synthesis of multi-input function using two-input gates\n" );
8769     Abc_Print( -2, "\t-I <num> : the number of input variables [default = %d]\n", pPars->nVars );
8770     Abc_Print( -2, "\t-N <num> : the number of two-input nodes [default = %d]\n", pPars->nNodes );
8771     Abc_Print( -2, "\t-T <num> : the runtime limit in seconds [default = %d]\n", pPars->RuntimeLim );
8772     Abc_Print( -2, "\t-a       : toggle using only AND-gates (without XOR-gates) [default = %s]\n", pPars->fOnlyAnd ? "yes" : "no" );
8773     Abc_Print( -2, "\t-o       : toggle using additional optimizations [default = %s]\n", pPars->fFewerVars ? "yes" : "no" );
8774     Abc_Print( -2, "\t-g       : toggle using Glucose 3.0 by Gilles Audemard and Laurent Simon [default = %s]\n", pPars->fGlucose ? "yes" : "no" );
8775     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", pPars->fVerbose ? "yes" : "no" );
8776     Abc_Print( -2, "\t-h       : print the command usage\n" );
8777     Abc_Print( -2, "\t<hex>    : truth table in hex notation\n" );
8778     Abc_Print( -2, "\t           \n" );
8779     Abc_Print( -2, "\t           For example, command line \"twoexact -g -I 5 -N 12 169AE443\"\n" );
8780     Abc_Print( -2, "\t           synthesizes the smallest circuit composed of two-input gates\n" );
8781     Abc_Print( -2, "\t           for the only NPN class of 5-input functions that requires 12 gates;\n" );
8782     Abc_Print( -2, "\t           all other functions can be realized with 11 two-input gates or less\n" );
8783     Abc_Print( -2, "\t           (see Section 7.1.2 \"Boolean evaluation\" in the book by Donald Knuth\n" );
8784     Abc_Print( -2, "\t           http://www.cs.utsa.edu/~wagner/knuth/fasc0c.pdf)\n" );
8785     return 1;
8786 }
8787 
8788 /**Function*************************************************************
8789 
8790   Synopsis    []
8791 
8792   Description []
8793 
8794   SideEffects []
8795 
8796   SeeAlso     []
8797 
8798 ***********************************************************************/
Abc_CommandLutExact(Abc_Frame_t * pAbc,int argc,char ** argv)8799 int Abc_CommandLutExact( Abc_Frame_t * pAbc, int argc, char ** argv )
8800 {
8801     extern void Exa3_ManExactSynthesis( Bmc_EsPar_t * pPars );
8802     extern void Exa3_ManExactSynthesis2( Bmc_EsPar_t * pPars );
8803     int c;
8804     Bmc_EsPar_t Pars, * pPars = &Pars;
8805     Bmc_EsParSetDefault( pPars );
8806     Extra_UtilGetoptReset();
8807     while ( ( c = Extra_UtilGetopt( argc, argv, "INKTiaogvh" ) ) != EOF )
8808     {
8809         switch ( c )
8810         {
8811         case 'I':
8812             if ( globalUtilOptind >= argc )
8813             {
8814                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
8815                 goto usage;
8816             }
8817             pPars->nVars = atoi(argv[globalUtilOptind]);
8818             globalUtilOptind++;
8819             if ( pPars->nVars < 0 )
8820                 goto usage;
8821             break;
8822         case 'N':
8823             if ( globalUtilOptind >= argc )
8824             {
8825                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
8826                 goto usage;
8827             }
8828             pPars->nNodes = atoi(argv[globalUtilOptind]);
8829             globalUtilOptind++;
8830             if ( pPars->nNodes < 0 )
8831                 goto usage;
8832             break;
8833        case 'K':
8834             if ( globalUtilOptind >= argc )
8835             {
8836                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
8837                 goto usage;
8838             }
8839             pPars->nLutSize = atoi(argv[globalUtilOptind]);
8840             globalUtilOptind++;
8841             if ( pPars->nLutSize < 0 )
8842                 goto usage;
8843             break;
8844         case 'T':
8845             if ( globalUtilOptind >= argc )
8846             {
8847                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
8848                 goto usage;
8849             }
8850             pPars->RuntimeLim = atoi(argv[globalUtilOptind]);
8851             globalUtilOptind++;
8852             if ( pPars->RuntimeLim < 0 )
8853                 goto usage;
8854             break;
8855         case 'i':
8856             pPars->fUseIncr ^= 1;
8857             break;
8858         case 'a':
8859             pPars->fOnlyAnd ^= 1;
8860             break;
8861         case 'o':
8862             pPars->fFewerVars ^= 1;
8863             break;
8864         case 'g':
8865             pPars->fGlucose ^= 1;
8866             break;
8867         case 'v':
8868             pPars->fVerbose ^= 1;
8869             break;
8870         case 'h':
8871             goto usage;
8872         default:
8873             goto usage;
8874         }
8875     }
8876     if ( argc == globalUtilOptind + 1 )
8877         pPars->pTtStr = argv[globalUtilOptind];
8878     if ( pPars->pTtStr == NULL )
8879     {
8880         Abc_Print( -1, "Truth table should be given on the command line.\n" );
8881         return 1;
8882     }
8883     if ( (1 << (pPars->nVars-2)) != (int)strlen(pPars->pTtStr) )
8884     {
8885         Abc_Print( -1, "Truth table is expected to have %d hex digits (instead of %d).\n", (1 << (pPars->nVars-2)), strlen(pPars->pTtStr) );
8886         return 1;
8887     }
8888     if ( pPars->nVars > pPars->nNodes * (pPars->nLutSize - 1) + 1 )
8889     {
8890         Abc_Print( -1, "Function with %d variales cannot be implemented with %d %d-input LUTs.\n", pPars->nVars, pPars->nNodes, pPars->nLutSize );
8891         return 1;
8892     }
8893     if ( pPars->nVars > 10 )
8894     {
8895         Abc_Print( -1, "Function should not have more than 10 inputs.\n" );
8896         return 1;
8897     }
8898     if ( pPars->nLutSize > 6 )
8899     {
8900         Abc_Print( -1, "Node size should not be more than 6 inputs.\n" );
8901         return 1;
8902     }
8903     if ( pPars->fGlucose )
8904         Exa3_ManExactSynthesis( pPars );
8905     else
8906         Exa3_ManExactSynthesis2( pPars );
8907     return 0;
8908 
8909 usage:
8910     Abc_Print( -2, "usage: lutexact [-INKT <num>] [-iaogvh] <hex>\n" );
8911     Abc_Print( -2, "\t           exact synthesis of I-input function using N K-input gates\n" );
8912     Abc_Print( -2, "\t-I <num> : the number of input variables [default = %d]\n", pPars->nVars );
8913     Abc_Print( -2, "\t-N <num> : the number of K-input nodes [default = %d]\n", pPars->nNodes );
8914     Abc_Print( -2, "\t-K <num> : the number of node fanins [default = %d]\n", pPars->nLutSize );
8915     Abc_Print( -2, "\t-T <num> : the runtime limit in seconds [default = %d]\n", pPars->RuntimeLim );
8916     Abc_Print( -2, "\t-i       : toggle using incremental solving [default = %s]\n", pPars->fUseIncr ? "yes" : "no" );
8917     Abc_Print( -2, "\t-a       : toggle using only AND-gates when K = 2 [default = %s]\n", pPars->fOnlyAnd ? "yes" : "no" );
8918     Abc_Print( -2, "\t-o       : toggle using additional optimizations [default = %s]\n", pPars->fFewerVars ? "yes" : "no" );
8919     Abc_Print( -2, "\t-g       : toggle using Glucose 3.0 by Gilles Audemard and Laurent Simon [default = %s]\n", pPars->fGlucose ? "yes" : "no" );
8920     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", pPars->fVerbose ? "yes" : "no" );
8921     Abc_Print( -2, "\t-h       : print the command usage\n" );
8922     Abc_Print( -2, "\t<hex>    : truth table in hex notation\n" );
8923     return 1;
8924 }
8925 
8926 /**Function*************************************************************
8927 
8928   Synopsis    []
8929 
8930   Description []
8931 
8932   SideEffects []
8933 
8934   SeeAlso     []
8935 
8936 ***********************************************************************/
Abc_CommandAllExact(Abc_Frame_t * pAbc,int argc,char ** argv)8937 int Abc_CommandAllExact( Abc_Frame_t * pAbc, int argc, char ** argv )
8938 {
8939     extern void Zyx_ManExactSynthesis( Bmc_EsPar_t * pPars );
8940     int c;
8941     Bmc_EsPar_t Pars, * pPars = &Pars;
8942     Bmc_EsParSetDefault( pPars );
8943     Extra_UtilGetoptReset();
8944     while ( ( c = Extra_UtilGetopt( argc, argv, "MINKiaoegvh" ) ) != EOF )
8945     {
8946         switch ( c )
8947         {
8948         case 'M':
8949             if ( globalUtilOptind >= argc )
8950             {
8951                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
8952                 goto usage;
8953             }
8954             pPars->nMajSupp = atoi(argv[globalUtilOptind]);
8955             globalUtilOptind++;
8956             if ( pPars->nMajSupp < 0 )
8957                 goto usage;
8958             break;
8959         case 'I':
8960             if ( globalUtilOptind >= argc )
8961             {
8962                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
8963                 goto usage;
8964             }
8965             pPars->nVars = atoi(argv[globalUtilOptind]);
8966             globalUtilOptind++;
8967             if ( pPars->nVars < 0 )
8968                 goto usage;
8969             break;
8970         case 'N':
8971             if ( globalUtilOptind >= argc )
8972             {
8973                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
8974                 goto usage;
8975             }
8976             pPars->nNodes = atoi(argv[globalUtilOptind]);
8977             globalUtilOptind++;
8978             if ( pPars->nNodes < 0 )
8979                 goto usage;
8980             break;
8981        case 'K':
8982             if ( globalUtilOptind >= argc )
8983             {
8984                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
8985                 goto usage;
8986             }
8987             pPars->nLutSize = atoi(argv[globalUtilOptind]);
8988             globalUtilOptind++;
8989             if ( pPars->nLutSize < 0 )
8990                 goto usage;
8991             break;
8992         case 'i':
8993             pPars->fUseIncr ^= 1;
8994             break;
8995         case 'a':
8996             pPars->fOnlyAnd ^= 1;
8997             break;
8998         case 'o':
8999             pPars->fOrderNodes ^= 1;
9000             break;
9001         case 'e':
9002             pPars->fEnumSols ^= 1;
9003             break;
9004         case 'g':
9005             pPars->fGlucose ^= 1;
9006             break;
9007         case 'v':
9008             pPars->fVerbose ^= 1;
9009             break;
9010         case 'h':
9011             goto usage;
9012         default:
9013             goto usage;
9014         }
9015     }
9016     if ( pPars->nMajSupp > 0 )
9017     {
9018         if ( pPars->nMajSupp != 5 && pPars->nMajSupp != 7 && pPars->nMajSupp != 9 )
9019         {
9020             Abc_Print( -1, "Currently only support majority with 5, 7 or 9 inputs.\n" );
9021             return 1;
9022         }
9023         pPars->nVars = pPars->nMajSupp;
9024         pPars->nLutSize = 3;
9025         pPars->fMajority = 1;
9026         pPars->fUseIncr = 1;
9027         if ( pPars->nNodes == 0 )
9028         {
9029             if ( pPars->nMajSupp == 5 )
9030                 pPars->nNodes = 4;
9031             if ( pPars->nMajSupp == 7 )
9032                 pPars->nNodes = 7;
9033             if ( pPars->nMajSupp == 9 )
9034                 pPars->nNodes = 10;
9035         }
9036     }
9037     else
9038     {
9039         if ( pPars->nVars == 0 )
9040         {
9041             Abc_Print( -1, "The number of variables (-I num) needs to be specified on the command line.\n" );
9042             return 1;
9043         }
9044         if ( pPars->nNodes == 0 )
9045         {
9046             Abc_Print( -1, "The number of nodes (-N num) needs to be specified on the command line.\n" );
9047             return 1;
9048         }
9049         if ( argc == globalUtilOptind + 1 )
9050             pPars->pTtStr = argv[globalUtilOptind];
9051         if ( pPars->pTtStr == NULL )
9052         {
9053             Abc_Print( -1, "Truth table should be given on the command line.\n" );
9054             return 1;
9055         }
9056         if ( (1 << (pPars->nVars-2)) != (int)strlen(pPars->pTtStr) )
9057         {
9058             Abc_Print( -1, "Truth table is expected to have %d hex digits (instead of %d).\n", (1 << (pPars->nVars-2)), strlen(pPars->pTtStr) );
9059             return 1;
9060         }
9061     }
9062     if ( pPars->nVars > pPars->nNodes * (pPars->nLutSize - 1) + 1 )
9063     {
9064         Abc_Print( -1, "Function with %d variales cannot be implemented with %d %d-input LUTs.\n", pPars->nVars, pPars->nNodes, pPars->nLutSize );
9065         return 1;
9066     }
9067     if ( pPars->nVars > 10 )
9068     {
9069         Abc_Print( -1, "Function should not have more than 10 inputs.\n" );
9070         return 1;
9071     }
9072     if ( pPars->nLutSize > 6 )
9073     {
9074         Abc_Print( -1, "Node size should not be more than 6 inputs.\n" );
9075         return 1;
9076     }
9077     if ( !pPars->fUseIncr )
9078     {
9079         if ( pPars->fMajority )
9080         {
9081             Abc_Print( -1, "Cannot synthesize majority in the non-incremental mode (use \'-i\').\n" );
9082             return 1;
9083         }
9084         if ( pPars->nLutSize > 3 )
9085         {
9086             Abc_Print( -1, "Cannot synthesize LUT4 and larger in non-incremental mode (use \'-i\').\n" );
9087             return 1;
9088         }
9089     }
9090     Zyx_ManExactSynthesis( pPars );
9091     return 0;
9092 
9093 usage:
9094     Abc_Print( -2, "usage: allexact [-MIKN <num>] [-iaoevh] <hex>\n" );
9095     Abc_Print( -2, "\t           exact synthesis of I-input function using N K-input gates\n" );
9096     Abc_Print( -2, "\t-M <num> : the majority support size (overrides -I and -K) [default = %d]\n", pPars->nMajSupp );
9097     Abc_Print( -2, "\t-I <num> : the number of input variables [default = %d]\n", pPars->nVars );
9098     Abc_Print( -2, "\t-K <num> : the number of node fanins [default = %d]\n", pPars->nLutSize );
9099     Abc_Print( -2, "\t-N <num> : the number of K-input nodes [default = %d]\n", pPars->nNodes );
9100     Abc_Print( -2, "\t-i       : toggle using incremental solving [default = %s]\n", pPars->fUseIncr ? "yes" : "no" );
9101     Abc_Print( -2, "\t-a       : toggle using only AND-gates when K = 2 [default = %s]\n", pPars->fOnlyAnd ? "yes" : "no" );
9102     Abc_Print( -2, "\t-o       : toggle using node ordering by fanins [default = %s]\n", pPars->fOrderNodes ? "yes" : "no" );
9103     Abc_Print( -2, "\t-e       : toggle enumerating all solutions [default = %s]\n", pPars->fEnumSols ? "yes" : "no" );
9104 //    Abc_Print( -2, "\t-g       : toggle using Glucose 3.0 by Gilles Audemard and Laurent Simon [default = %s]\n", pPars->fGlucose ? "yes" : "no" );
9105     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", pPars->fVerbose ? "yes" : "no" );
9106     Abc_Print( -2, "\t-h       : print the command usage\n" );
9107     Abc_Print( -2, "\t<hex>    : truth table in hex notation\n" );
9108     return 1;
9109 }
9110 
9111 /**Function*************************************************************
9112 
9113   Synopsis    []
9114 
9115   Description []
9116 
9117   SideEffects []
9118 
9119   SeeAlso     []
9120 
9121 ***********************************************************************/
Abc_CommandTestExact(Abc_Frame_t * pAbc,int argc,char ** argv)9122 int Abc_CommandTestExact( Abc_Frame_t * pAbc, int argc, char ** argv )
9123 {
9124     extern void Zyx_TestExact( char * pFileName );
9125     char * pFileName = NULL;
9126     int c, fVerbose = 0;
9127     Extra_UtilGetoptReset();
9128     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
9129     {
9130         switch ( c )
9131         {
9132        case 'v':
9133             fVerbose ^= 1;
9134             break;
9135         case 'h':
9136             goto usage;
9137         default:
9138             goto usage;
9139         }
9140     }
9141     if ( argc == globalUtilOptind + 1 )
9142         pFileName = argv[globalUtilOptind];
9143     if ( pFileName == NULL )
9144     {
9145         Abc_Print( -1, "File name is not given on the command line.\n" );
9146         return 1;
9147     }
9148     Zyx_TestExact( pFileName );
9149     return 0;
9150 
9151 usage:
9152     Abc_Print( -2, "usage: testexact <file>\n" );
9153     Abc_Print( -2, "\t           tests solution of the exact synthesis problem\n" );
9154     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", fVerbose ? "yes" : "no" );
9155     Abc_Print( -2, "\t-h       : print the command usage\n" );
9156     Abc_Print( -2, "\t<file>   : file name in the specified format\n" );
9157     return 1;
9158 }
9159 
9160 /**Function*************************************************************
9161 
9162   Synopsis    []
9163 
9164   Description []
9165 
9166   SideEffects []
9167 
9168   SeeAlso     []
9169 
9170 ***********************************************************************/
Abc_CommandMajGen(Abc_Frame_t * pAbc,int argc,char ** argv)9171 int Abc_CommandMajGen( Abc_Frame_t * pAbc, int argc, char ** argv )
9172 {
9173     extern int Gem_Enumerate( int nVars, int fDump, int fVerbose );
9174     int c, nVars = 8, fDump = 0, fVerbose = 0;
9175     Extra_UtilGetoptReset();
9176     while ( ( c = Extra_UtilGetopt( argc, argv, "Ndvh" ) ) != EOF )
9177     {
9178         switch ( c )
9179         {
9180         case 'N':
9181             if ( globalUtilOptind >= argc )
9182             {
9183                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
9184                 goto usage;
9185             }
9186             nVars = atoi(argv[globalUtilOptind]);
9187             globalUtilOptind++;
9188             if ( nVars < 0 )
9189                 goto usage;
9190             break;
9191         case 'd':
9192             fDump ^= 1;
9193             break;
9194         case 'v':
9195             fVerbose ^= 1;
9196             break;
9197         case 'h':
9198             goto usage;
9199         default:
9200             goto usage;
9201         }
9202     }
9203     Gem_Enumerate( nVars, fDump, fVerbose );
9204     return 0;
9205 
9206 usage:
9207     Abc_Print( -2, "usage: majgen [-N <num>] [-dvh]>\n" );
9208     Abc_Print( -2, "\t           generates networks for majority gates\n" );
9209     Abc_Print( -2, "\t-N <num> : the maximum number of variables [default = %d]\n", nVars );
9210     Abc_Print( -2, "\t-d       : toggle dumping functions into a file [default = %s]\n", fVerbose ? "yes" : "no" );
9211     Abc_Print( -2, "\t-v       : toggle verbose printout [default = %s]\n", fVerbose ? "yes" : "no" );
9212     Abc_Print( -2, "\t-h       : print the command usage\n" );
9213     return 1;
9214 }
9215 
9216 /**Function*************************************************************
9217 
9218   Synopsis    []
9219 
9220   Description []
9221 
9222   SideEffects []
9223 
9224   SeeAlso     []
9225 
9226 ***********************************************************************/
Abc_CommandLogic(Abc_Frame_t * pAbc,int argc,char ** argv)9227 int Abc_CommandLogic( Abc_Frame_t * pAbc, int argc, char ** argv )
9228 {
9229     Abc_Ntk_t * pNtk, * pNtkRes;
9230     int c;
9231 
9232     pNtk = Abc_FrameReadNtk(pAbc);
9233     // set defaults
9234     Extra_UtilGetoptReset();
9235     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
9236     {
9237         switch ( c )
9238         {
9239         case 'h':
9240             goto usage;
9241         default:
9242             goto usage;
9243         }
9244     }
9245 
9246     if ( pNtk == NULL )
9247     {
9248         Abc_Print( -1, "Empty network.\n" );
9249         return 1;
9250     }
9251 
9252     if ( !Abc_NtkIsStrash( pNtk ) )
9253     {
9254         Abc_Print( -1, "This command is only applicable to strashed networks.\n" );
9255         return 1;
9256     }
9257 
9258     // get the new network
9259     pNtkRes = Abc_NtkToLogic( pNtk );
9260     if ( pNtkRes == NULL )
9261     {
9262         Abc_Print( -1, "Converting to a logic network has failed.\n" );
9263         return 1;
9264     }
9265     // replace the current network
9266     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
9267     return 0;
9268 
9269 usage:
9270     Abc_Print( -2, "usage: logic [-h]\n" );
9271     Abc_Print( -2, "\t        transforms an AIG into a logic network with SOPs\n" );
9272     Abc_Print( -2, "\t-h    : print the command usage\n");
9273     return 1;
9274 }
9275 
9276 /**Function*************************************************************
9277 
9278   Synopsis    []
9279 
9280   Description []
9281 
9282   SideEffects []
9283 
9284   SeeAlso     []
9285 
9286 ***********************************************************************/
Abc_CommandComb(Abc_Frame_t * pAbc,int argc,char ** argv)9287 int Abc_CommandComb( Abc_Frame_t * pAbc, int argc, char ** argv )
9288 {
9289     Abc_Ntk_t * pNtk, * pNtkRes;
9290     int c;
9291     int fRemoveLatches;
9292     int nLatchesToAdd;
9293     extern void Abc_NtkMakeSeq( Abc_Ntk_t * pNtk, int nLatchesToAdd );
9294 
9295     pNtk = Abc_FrameReadNtk(pAbc);
9296     // set defaults
9297     fRemoveLatches = 0;
9298     nLatchesToAdd = 0;
9299     Extra_UtilGetoptReset();
9300     while ( ( c = Extra_UtilGetopt( argc, argv, "Llh" ) ) != EOF )
9301     {
9302         switch ( c )
9303         {
9304         case 'L':
9305             if ( globalUtilOptind >= argc )
9306             {
9307                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
9308                 goto usage;
9309             }
9310             nLatchesToAdd = atoi(argv[globalUtilOptind]);
9311             globalUtilOptind++;
9312             if ( nLatchesToAdd < 0 )
9313                 goto usage;
9314             break;
9315         case 'l':
9316             fRemoveLatches ^= 1;
9317             break;
9318         case 'h':
9319             goto usage;
9320         default:
9321             goto usage;
9322         }
9323     }
9324 
9325     if ( pNtk == NULL )
9326     {
9327         Abc_Print( -1, "Empty network.\n" );
9328         return 1;
9329     }
9330     if ( Abc_NtkIsComb(pNtk) && nLatchesToAdd == 0 )
9331     {
9332         Abc_Print( -1, "The network is already combinational.\n" );
9333         return 0;
9334     }
9335     if ( !Abc_NtkIsComb(pNtk) && nLatchesToAdd != 0 )
9336     {
9337         Abc_Print( -1, "The network is already combinational.\n" );
9338         return 0;
9339     }
9340 
9341     // get the new network
9342     pNtkRes = Abc_NtkDup( pNtk );
9343     if ( nLatchesToAdd )
9344         Abc_NtkMakeSeq( pNtkRes, nLatchesToAdd );
9345     else
9346         Abc_NtkMakeComb( pNtkRes, fRemoveLatches );
9347     // replace the current network
9348     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
9349     return 0;
9350 
9351 usage:
9352     Abc_Print( -2, "usage: comb [-L <num>] [-lh]\n" );
9353     Abc_Print( -2, "\t           converts comb network into seq, and vice versa\n" );
9354     Abc_Print( -2, "\t-L <num> : number of latches to add to comb network (0 = do not add) [default = %d]\n", nLatchesToAdd );
9355     Abc_Print( -2, "\t-l       : toggle converting latches to PIs/POs or removing them [default = %s]\n", fRemoveLatches? "remove": "convert" );
9356     Abc_Print( -2, "\t-h       : print the command usage\n");
9357     return 1;
9358 }
9359 
9360 /**Function*************************************************************
9361 
9362   Synopsis    []
9363 
9364   Description []
9365 
9366   SideEffects []
9367 
9368   SeeAlso     []
9369 
9370 ***********************************************************************/
Abc_CommandMiter(Abc_Frame_t * pAbc,int argc,char ** argv)9371 int Abc_CommandMiter( Abc_Frame_t * pAbc, int argc, char ** argv )
9372 {
9373     char Buffer[32];
9374     Abc_Ntk_t * pNtk, * pNtk1, * pNtk2, * pNtkRes;
9375     int fDelete1, fDelete2;
9376     char ** pArgvNew;
9377     int nArgcNew;
9378     int c;
9379     int fCheck;
9380     int fComb;
9381     int fImplic;
9382     int fMulti;
9383     int nPartSize;
9384     int fTrans;
9385     int fIgnoreNames;
9386 
9387     pNtk = Abc_FrameReadNtk(pAbc);
9388 
9389     // set defaults
9390     fComb  = 0;
9391     fCheck = 1;
9392     fImplic = 0;
9393     fMulti = 0;
9394     nPartSize = 0;
9395     fTrans = 0;
9396     fIgnoreNames = 0;
9397     Extra_UtilGetoptReset();
9398     while ( ( c = Extra_UtilGetopt( argc, argv, "Pcmitnh" ) ) != EOF )
9399     {
9400         switch ( c )
9401         {
9402         case 'P':
9403             if ( globalUtilOptind >= argc )
9404             {
9405                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
9406                 goto usage;
9407             }
9408             nPartSize = atoi(argv[globalUtilOptind]);
9409             globalUtilOptind++;
9410             if ( nPartSize < 0 )
9411                 goto usage;
9412             break;
9413         case 'c':
9414             fComb ^= 1;
9415             break;
9416         case 'm':
9417             fMulti ^= 1;
9418             break;
9419         case 'i':
9420             fImplic ^= 1;
9421             break;
9422         case 't':
9423             fTrans ^= 1;
9424             break;
9425         case 'n':
9426             fIgnoreNames ^= 1;
9427             break;
9428         default:
9429             goto usage;
9430         }
9431     }
9432 
9433     if ( fTrans )
9434     {
9435         if ( (Abc_NtkPoNum(pNtk) & 1) == 1 )
9436         {
9437             Abc_Print( -1, "Abc_CommandMiter(): The number of outputs should be even.\n" );
9438             return 0;
9439         }
9440         // replace the current network
9441         pNtkRes = Abc_NtkDupTransformMiter( pNtk );
9442         Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
9443         Abc_Print( 1, "The miter (current network) is transformed by XORing POs pair-wise.\n" );
9444         return 0;
9445     }
9446 
9447     pArgvNew = argv + globalUtilOptind;
9448     nArgcNew = argc - globalUtilOptind;
9449     if ( !Abc_NtkPrepareTwoNtks( stdout, pNtk, pArgvNew, nArgcNew, &pNtk1, &pNtk2, &fDelete1, &fDelete2, 1 ) )
9450         return 1;
9451 
9452     if ( fIgnoreNames )
9453     {
9454         if ( !fDelete1 )
9455         {
9456             pNtk1 = Abc_NtkStrash( pNtk1, 0, 1, 0 );
9457             fDelete1 = 1;
9458         }
9459         if ( !fDelete2 )
9460         {
9461             pNtk2 = Abc_NtkStrash( pNtk2, 0, 1, 0 );
9462             fDelete2 = 1;
9463         }
9464         Abc_NtkShortNames( pNtk1 );
9465         Abc_NtkShortNames( pNtk2 );
9466     }
9467     // compute the miter
9468     pNtkRes = Abc_NtkMiter( pNtk1, pNtk2, fComb, nPartSize, fImplic, fMulti );
9469     if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
9470     if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
9471 
9472     // get the new network
9473     if ( pNtkRes == NULL )
9474     {
9475         Abc_Print( -1, "Miter computation has failed.\n" );
9476         return 0;
9477     }
9478     // replace the current network
9479     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
9480     return 0;
9481 
9482 usage:
9483     if ( nPartSize == 0 )
9484         strcpy( Buffer, "unused" );
9485     else
9486         sprintf(Buffer, "%d", nPartSize );
9487     Abc_Print( -2, "usage: miter [-P <num>] [-cimtnh] <file1> <file2>\n" );
9488     Abc_Print( -2, "\t           computes the miter of the two circuits\n" );
9489     Abc_Print( -2, "\t-P <num> : output partition size [default = %s]\n", Buffer );
9490     Abc_Print( -2, "\t-c       : toggles deriving combinational miter (latches as POs) [default = %s]\n", fComb? "yes": "no" );
9491     Abc_Print( -2, "\t-i       : toggles deriving implication miter (file1 => file2) [default = %s]\n", fImplic? "yes": "no" );
9492     Abc_Print( -2, "\t-m       : toggles creating multi-output miter [default = %s]\n", fMulti? "yes": "no" );
9493     Abc_Print( -2, "\t-t       : toggle XORing pair-wise POs of the miter [default = %s]\n", fTrans? "yes": "no" );
9494     Abc_Print( -2, "\t-n       : toggle ignoring names when matching CIs/COs [default = %s]\n", fIgnoreNames? "yes": "no" );
9495     Abc_Print( -2, "\t-h       : print the command usage\n");
9496     Abc_Print( -2, "\tfile1    : (optional) the file with the first network\n");
9497     Abc_Print( -2, "\tfile2    : (optional) the file with the second network\n");
9498     Abc_Print( -2, "\t           if no files are given, uses the current network and its spec\n");
9499     Abc_Print( -2, "\t           if one file is given, uses the current network and the file\n");
9500     return 1;
9501 }
9502 
9503 /**Function*************************************************************
9504 
9505   Synopsis    []
9506 
9507   Description []
9508 
9509   SideEffects []
9510 
9511   SeeAlso     []
9512 
9513 ***********************************************************************/
Abc_CommandMiter2(Abc_Frame_t * pAbc,int argc,char ** argv)9514 int Abc_CommandMiter2( Abc_Frame_t * pAbc, int argc, char ** argv )
9515 {
9516     extern Vec_Ptr_t * Abc_NtkReadNodeNames( Abc_Ntk_t * pNtk, char * pFileName );
9517     extern Abc_Ntk_t * Abc_NtkSpecialMiter( Abc_Ntk_t * pNtk, Vec_Ptr_t * vNodes );
9518 
9519     Abc_Ntk_t * pNtk, * pNtkRes;
9520     Vec_Ptr_t * vNodes;
9521     char * pFileName;
9522     int c, fVerbose = 0;
9523     pNtk = Abc_FrameReadNtk(pAbc);
9524 
9525     // set defaults
9526     Extra_UtilGetoptReset();
9527     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
9528     {
9529         switch ( c )
9530         {
9531         case 'v':
9532             fVerbose ^= 1;
9533             break;
9534         case 'h':
9535             goto usage;
9536         default:
9537             goto usage;
9538         }
9539     }
9540 
9541     // get the second network
9542     if ( argc != globalUtilOptind + 1 )
9543     {
9544         Abc_Print( -1, "The file with node names is not given.\n" );
9545         return 1;
9546     }
9547     if ( !Abc_NtkIsLogic(pNtk) )
9548     {
9549         Abc_Print( -1, "The base network should be logic network from BLIF file.\n" );
9550         return 1;
9551     }
9552     // read the second network
9553     pFileName = argv[globalUtilOptind];
9554     if ( (vNodes = Abc_NtkReadNodeNames(pNtk, pFileName)) == NULL )
9555     {
9556         Abc_Print( -1, "Cannot read node names from file \"%s\".\n", pFileName );
9557         return 1;
9558     }
9559     pNtkRes = Abc_NtkSpecialMiter( pNtk, vNodes );
9560     Vec_PtrFree( vNodes );
9561     // replace the current network
9562     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
9563     return 0;
9564 
9565 usage:
9566     Abc_Print( -2, "usage: miter2 [-h] <file>\n" );
9567     Abc_Print( -2, "\t         derives specialized miter\n" );
9568     Abc_Print( -2, "\t-h     : print the command usage\n");
9569     Abc_Print( -2, "\t<file> : file name with node names\n");
9570     return 1;
9571 }
9572 
9573 /**Function*************************************************************
9574 
9575   Synopsis    []
9576 
9577   Description []
9578 
9579   SideEffects []
9580 
9581   SeeAlso     []
9582 
9583 ***********************************************************************/
Abc_CommandDemiter(Abc_Frame_t * pAbc,int argc,char ** argv)9584 int Abc_CommandDemiter( Abc_Frame_t * pAbc, int argc, char ** argv )
9585 {
9586     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
9587     int c, fDual, fVerbose;
9588     extern int Abc_NtkDarDemiter( Abc_Ntk_t * pNtk );
9589     extern int Abc_NtkDarDemiterDual( Abc_Ntk_t * pNtk, int fVerbose );
9590     // set defaults
9591     fDual = 0;
9592     fVerbose = 1;
9593     Extra_UtilGetoptReset();
9594     while ( ( c = Extra_UtilGetopt( argc, argv, "dvh" ) ) != EOF )
9595     {
9596         switch ( c )
9597         {
9598         case 'd':
9599             fDual ^= 1;
9600             break;
9601         case 'v':
9602             fVerbose ^= 1;
9603             break;
9604         default:
9605             goto usage;
9606         }
9607     }
9608 
9609     if ( pNtk == NULL )
9610     {
9611         Abc_Print( -1, "Empty network.\n" );
9612         return 1;
9613     }
9614 
9615     if ( !Abc_NtkIsStrash(pNtk) )
9616     {
9617         Abc_Print( -1, "The network is not strashed.\n" );
9618         return 1;
9619     }
9620 
9621     if ( fDual )
9622     {
9623         if ( (Abc_NtkPoNum(pNtk) & 1) )
9624         {
9625             Abc_Print( -1, "The number of POs should be even.\n" );
9626             return 0;
9627         }
9628         if ( !Abc_NtkDarDemiterDual( pNtk, fVerbose ) )
9629         {
9630             Abc_Print( -1, "Demitering has failed.\n" );
9631             return 1;
9632         }
9633         return 0;
9634     }
9635 /*
9636     if ( Abc_NtkPoNum(pNtk) != 1 )
9637     {
9638         Abc_Print( -1, "The network is not a single-output miter.\n" );
9639         return 1;
9640     }
9641     if ( !Abc_NodeIsExorType(Abc_ObjFanin0(Abc_NtkPo(pNtk,0))) )
9642     {
9643         Abc_Print( -1, "The miter's PO is not an EXOR.\n" );
9644         return 1;
9645     }
9646     if ( !Abc_NtkDemiter( pNtk ) )
9647     {
9648         Abc_Print( -1, "Demitering has failed.\n" );
9649         return 1;
9650     }
9651 */
9652     // get the new network
9653     if ( !Abc_NtkDarDemiter( pNtk ) )
9654     {
9655         Abc_Print( -1, "Demitering has failed.\n" );
9656         return 1;
9657     }
9658     // replace the current network
9659 //    Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
9660     return 0;
9661 
9662 usage:
9663     Abc_Print( -2, "usage: demiter [-dvh]\n" );
9664     Abc_Print( -2, "\t        splits sequential miter into two circuits\n" );
9665     Abc_Print( -2, "\t-d    : expects a dual-output miter (without XORs) [default = %s]\n", fDual? "yes": "no" );
9666     Abc_Print( -2, "\t-v    : toggles outputting verbose information [default = %s]\n", fVerbose? "yes": "no" );
9667     Abc_Print( -2, "\t-h    : print the command usage\n");
9668     return 1;
9669 }
9670 
9671 /**Function*************************************************************
9672 
9673   Synopsis    []
9674 
9675   Description []
9676 
9677   SideEffects []
9678 
9679   SeeAlso     []
9680 
9681 ***********************************************************************/
Abc_CommandOrPos(Abc_Frame_t * pAbc,int argc,char ** argv)9682 int Abc_CommandOrPos( Abc_Frame_t * pAbc, int argc, char ** argv )
9683 {
9684     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);//, * pNtkRes;
9685     int fReverse = 0;
9686     int fComb = 0;
9687     int fXor = 0;
9688     int c;
9689     extern int Abc_NtkCombinePos( Abc_Ntk_t * pNtk, int fAnd, int fXor );
9690 
9691     // set defaults
9692     Extra_UtilGetoptReset();
9693     while ( ( c = Extra_UtilGetopt( argc, argv, "rxh" ) ) != EOF )
9694     {
9695         switch ( c )
9696         {
9697         case 'r':
9698             fReverse ^= 1;
9699             break;
9700         case 'x':
9701             fXor ^= 1;
9702             break;
9703         case 'c':
9704             fComb ^= 1;
9705             break;
9706         default:
9707             goto usage;
9708         }
9709     }
9710 
9711     if ( pNtk == NULL )
9712     {
9713         Abc_Print( -1, "Empty network.\n" );
9714         return 1;
9715     }
9716     if ( !Abc_NtkIsStrash(pNtk) )
9717     {
9718         Abc_Print( -1, "The network is not strashed.\n" );
9719         return 1;
9720     }
9721     // get the new network
9722     if ( fReverse )
9723     {
9724         extern Aig_Man_t * Abc_NtkToDarBmc( Abc_Ntk_t * pNtk, Vec_Int_t ** pvMap );
9725         Aig_Man_t * pMan = Abc_NtkToDarBmc( pNtk, NULL );
9726         Abc_Ntk_t * pNtkRes = Abc_NtkFromAigPhase( pMan );
9727         Aig_ManStop( pMan );
9728         // perform expansion
9729         if ( Abc_NtkPoNum(pNtk) != Abc_NtkPoNum(pNtkRes) )
9730             Abc_Print( 1,"Expanded %d outputs into %d outputs using OR decomposition.\n", Abc_NtkPoNum(pNtk), Abc_NtkPoNum(pNtkRes) );
9731         else
9732             Abc_Print( 1,"The output(s) cannot be structurally decomposed.\n" );
9733         // clear counter-example
9734         if ( pAbc->pCex )
9735             ABC_FREE( pAbc->pCex );
9736         // replace the current network
9737         ABC_FREE( pNtkRes->pName );
9738         pNtkRes->pName = Extra_UtilStrsav(pNtk->pName);
9739         Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
9740     }
9741     else
9742     {
9743         if ( !Abc_NtkCombinePos( pNtk, 0, fXor ) )
9744         {
9745             Abc_Print( -1, "ORing the POs has failed.\n" );
9746             return 1;
9747         }
9748         // update counter-example
9749         if ( pAbc->pCex )
9750             pAbc->pCex->iPo = 0;
9751         // replace the current network
9752     //    Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
9753     }
9754     return 0;
9755 
9756 usage:
9757     Abc_Print( -2, "usage: orpos [-rxh]\n" );
9758     Abc_Print( -2, "\t        creates single-output miter by ORing the POs of the current network\n" );
9759     Abc_Print( -2, "\t-r    : performs the reverse transform (OR decomposition) [default = %s]\n", fReverse? "yes": "no" );
9760     Abc_Print( -2, "\t-x    : toggles combining the PO using XOR [default = %s]\n", fXor? "yes": "no" );
9761     Abc_Print( -2, "\t-h    : print the command usage\n");
9762     return 1;
9763 }
9764 
9765 /**Function*************************************************************
9766 
9767   Synopsis    []
9768 
9769   Description []
9770 
9771   SideEffects []
9772 
9773   SeeAlso     []
9774 
9775 ***********************************************************************/
Abc_CommandAndPos(Abc_Frame_t * pAbc,int argc,char ** argv)9776 int Abc_CommandAndPos( Abc_Frame_t * pAbc, int argc, char ** argv )
9777 {
9778     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);//, * pNtkRes;
9779     int fComb = 0;
9780     int c;
9781 
9782     // set defaults
9783     Extra_UtilGetoptReset();
9784     while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
9785     {
9786         switch ( c )
9787         {
9788         case 'c':
9789             fComb ^= 1;
9790             break;
9791         default:
9792             goto usage;
9793         }
9794     }
9795 
9796     if ( pNtk == NULL )
9797     {
9798         Abc_Print( -1, "Empty network.\n" );
9799         return 1;
9800     }
9801 
9802     if ( !Abc_NtkIsStrash(pNtk) )
9803     {
9804         Abc_Print( -1, "The network is not strashed.\n" );
9805         return 1;
9806     }
9807 
9808     if ( Abc_NtkPoNum(pNtk) == 1 )
9809     {
9810         Abc_Print( -1, "The network already has one PO.\n" );
9811         return 1;
9812     }
9813 
9814     if ( Abc_NtkLatchNum(pNtk) )
9815     {
9816         Abc_Print( -1, "The miter has latches. ORing is not performed.\n" );
9817         return 1;
9818     }
9819 
9820     // get the new network
9821     if ( !Abc_NtkCombinePos( pNtk, 1, 0 ) )
9822     {
9823         Abc_Print( -1, "ANDing the POs has failed.\n" );
9824         return 1;
9825     }
9826     // replace the current network
9827 //    Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
9828     return 0;
9829 
9830 usage:
9831     Abc_Print( -2, "usage: andpos [-h]\n" );
9832     Abc_Print( -2, "\t        creates single-output miter by ANDing the POs of the current network\n" );
9833 //    Abc_Print( -2, "\t-c    : computes combinational miter (latches as POs) [default = %s]\n", fComb? "yes": "no" );
9834     Abc_Print( -2, "\t-h    : print the command usage\n");
9835     return 1;
9836 }
9837 
9838 /**Function*************************************************************
9839 
9840   Synopsis    []
9841 
9842   Description []
9843 
9844   SideEffects []
9845 
9846   SeeAlso     []
9847 
9848 ***********************************************************************/
Abc_CommandZeroPo(Abc_Frame_t * pAbc,int argc,char ** argv)9849 int Abc_CommandZeroPo( Abc_Frame_t * pAbc, int argc, char ** argv )
9850 {
9851     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);//, * pNtkRes = NULL;
9852     int c, iOutput = -1;
9853     int fSkipSweep = 0;
9854     int fUseConst1 = 0;
9855     extern void Abc_NtkDropOneOutput( Abc_Ntk_t * pNtk, int iOutput, int fSkipSweep, int fUseConst1 );
9856 
9857     // set defaults
9858     Extra_UtilGetoptReset();
9859     while ( ( c = Extra_UtilGetopt( argc, argv, "Nsoh" ) ) != EOF )
9860     {
9861         switch ( c )
9862         {
9863         case 'N':
9864             if ( globalUtilOptind >= argc )
9865             {
9866                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
9867                 goto usage;
9868             }
9869             iOutput = atoi(argv[globalUtilOptind]);
9870             globalUtilOptind++;
9871             if ( iOutput < 0 )
9872                 goto usage;
9873             break;
9874         case 's':
9875             fSkipSweep ^= 1;
9876             break;
9877         case 'o':
9878             fUseConst1 ^= 1;
9879             break;
9880         default:
9881             goto usage;
9882         }
9883     }
9884 
9885     if ( pNtk == NULL )
9886     {
9887         Abc_Print( -1, "Empty network.\n" );
9888         return 1;
9889     }
9890 
9891     if ( !Abc_NtkIsStrash(pNtk) )
9892     {
9893         Abc_Print( -1, "The network is not strashed.\n" );
9894         return 1;
9895     }
9896     if ( iOutput < 0 )
9897     {
9898         Abc_Print( -1, "The output index is not specified.\n" );
9899         return 1;
9900     }
9901     if ( iOutput >= Abc_NtkPoNum(pNtk) )
9902     {
9903         Abc_Print( -1, "The output index is larger than the allowed POs.\n" );
9904         return 1;
9905     }
9906 
9907     // get the new network
9908 //    pNtkRes = Abc_NtkDup( pNtk );
9909 //    Abc_NtkDropOneOutput( pNtkRes, iOutput );
9910 //    Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
9911     Abc_NtkDropOneOutput( pNtk, iOutput, fSkipSweep, fUseConst1 );
9912     return 0;
9913 
9914 usage:
9915     Abc_Print( -2, "usage: zeropo [-N <num>] [-soh]\n" );
9916     Abc_Print( -2, "\t           replaces the PO driver by constant 0\n" );
9917     Abc_Print( -2, "\t-N <num> : the zero-based index of the PO to replace [default = %d]\n", iOutput );
9918     Abc_Print( -2, "\t-s       : performs comb sweep after removimg a PO [default = %s]\n", !fSkipSweep? "yes": "no" );
9919     Abc_Print( -2, "\t-o       : toggles using const 1 instead of const 0 [default = %s]\n", fUseConst1? "yes": "no" );
9920     Abc_Print( -2, "\t-h       : print the command usage\n");
9921     return 1;
9922 }
9923 
9924 /**Function*************************************************************
9925 
9926   Synopsis    []
9927 
9928   Description []
9929 
9930   SideEffects []
9931 
9932   SeeAlso     []
9933 
9934 ***********************************************************************/
Abc_CommandSwapPos(Abc_Frame_t * pAbc,int argc,char ** argv)9935 int Abc_CommandSwapPos( Abc_Frame_t * pAbc, int argc, char ** argv )
9936 {
9937     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc), * pNtkRes;
9938     int c, iOutput = -1;
9939     extern void Abc_NtkSwapOneOutput( Abc_Ntk_t * pNtk, int iOutput );
9940 
9941     // set defaults
9942     Extra_UtilGetoptReset();
9943     while ( ( c = Extra_UtilGetopt( argc, argv, "Nh" ) ) != EOF )
9944     {
9945         switch ( c )
9946         {
9947         case 'N':
9948             if ( globalUtilOptind >= argc )
9949             {
9950                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
9951                 goto usage;
9952             }
9953             iOutput = atoi(argv[globalUtilOptind]);
9954             globalUtilOptind++;
9955             if ( iOutput < 0 )
9956                 goto usage;
9957             break;
9958         default:
9959             goto usage;
9960         }
9961     }
9962 
9963     if ( pNtk == NULL )
9964     {
9965         Abc_Print( -1, "Empty network.\n" );
9966         return 1;
9967     }
9968 
9969     if ( !Abc_NtkIsStrash(pNtk) )
9970     {
9971         Abc_Print( -1, "The network is not strashed.\n" );
9972         return 1;
9973     }
9974     if ( iOutput < 0 )
9975     {
9976         Abc_Print( -1, "The output index is not specified.\n" );
9977         return 1;
9978     }
9979     if ( iOutput >= Abc_NtkPoNum(pNtk) )
9980     {
9981         Abc_Print( -1, "The output index is larger than the allowed POs.\n" );
9982         return 1;
9983     }
9984 
9985     // get the new network
9986     pNtkRes = Abc_NtkDup( pNtk );
9987     Abc_NtkSwapOneOutput( pNtkRes, iOutput );
9988     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
9989     return 0;
9990 
9991 usage:
9992     Abc_Print( -2, "usage: swappos [-N <num>] [-h]\n" );
9993     Abc_Print( -2, "\t           swap the 0-th PO with the <num>-th PO\n" );
9994     Abc_Print( -2, "\t-N <num> : the zero-based index of the PO to swap [default = %d]\n", iOutput );
9995     Abc_Print( -2, "\t-h       : print the command usage\n");
9996     return 1;
9997 }
9998 
9999 /**Function*************************************************************
10000 
10001   Synopsis    []
10002 
10003   Description []
10004 
10005   SideEffects []
10006 
10007   SeeAlso     []
10008 
10009 ***********************************************************************/
Abc_CommandRemovePo(Abc_Frame_t * pAbc,int argc,char ** argv)10010 int Abc_CommandRemovePo( Abc_Frame_t * pAbc, int argc, char ** argv )
10011 {
10012     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);//, * pNtkRes = NULL;
10013     int c, iOutput = -1;
10014     int fRemoveConst0 = 1;
10015     extern void Abc_NtkRemovePo( Abc_Ntk_t * pNtk, int iOutput, int fRemoveConst0 );
10016 
10017     // set defaults
10018     Extra_UtilGetoptReset();
10019     while ( ( c = Extra_UtilGetopt( argc, argv, "Nzh" ) ) != EOF )
10020     {
10021         switch ( c )
10022         {
10023         case 'N':
10024             if ( globalUtilOptind >= argc )
10025             {
10026                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
10027                 goto usage;
10028             }
10029             iOutput = atoi(argv[globalUtilOptind]);
10030             globalUtilOptind++;
10031             if ( iOutput < 0 )
10032                 goto usage;
10033             break;
10034         case 'z':
10035             fRemoveConst0 ^= 1;
10036             break;
10037         default:
10038             goto usage;
10039         }
10040     }
10041 
10042     if ( pNtk == NULL )
10043     {
10044         Abc_Print( -1, "Empty network.\n" );
10045         return 1;
10046     }
10047 
10048     if ( !Abc_NtkIsStrash(pNtk) )
10049     {
10050         Abc_Print( -1, "The network is not strashed.\n" );
10051         return 1;
10052     }
10053     if ( iOutput < 0 )
10054     {
10055         Abc_Print( -1, "The output index is not specified.\n" );
10056         return 1;
10057     }
10058     if ( iOutput >= Abc_NtkPoNum(pNtk) )
10059     {
10060         Abc_Print( -1, "The output index is larger than the allowed POs.\n" );
10061         return 1;
10062     }
10063 
10064     // get the new network
10065 //    pNtkRes = Abc_NtkDup( pNtk );
10066 //    Abc_NtkRemovePo( pNtkRes, iOutput );
10067 //    Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
10068     Abc_NtkRemovePo( pNtk, iOutput, fRemoveConst0 );
10069     return 0;
10070 
10071 usage:
10072     Abc_Print( -2, "usage: removepo [-N <num>] [-zh]\n" );
10073     Abc_Print( -2, "\t           remove PO with number <num> if it is const0\n" );
10074     Abc_Print( -2, "\t-N <num> : the zero-based index of the PO to remove [default = %d]\n", iOutput );
10075     Abc_Print( -2, "\t-z       : toggle removing const1 instead of const0 [default = %s]\n", fRemoveConst0? "const0": "const1" );
10076     Abc_Print( -2, "\t-h       : print the command usage\n");
10077     return 1;
10078 }
10079 
10080 /**Function*************************************************************
10081 
10082   Synopsis    []
10083 
10084   Description []
10085 
10086   SideEffects []
10087 
10088   SeeAlso     []
10089 
10090 ***********************************************************************/
Abc_CommandDropSat(Abc_Frame_t * pAbc,int argc,char ** argv)10091 int Abc_CommandDropSat( Abc_Frame_t * pAbc, int argc, char ** argv )
10092 {
10093     extern void Abc_NtkDropSatOutputs( Abc_Ntk_t * pNtk, Vec_Ptr_t * vCexes, int fVerbose );
10094     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc), * pNtkRes = NULL;
10095     int fNoSweep = 0;
10096     int c, fVerbose = 0;
10097     Extra_UtilGetoptReset();
10098     while ( ( c = Extra_UtilGetopt( argc, argv, "svh" ) ) != EOF )
10099     {
10100         switch ( c )
10101         {
10102         case 's':
10103             fNoSweep ^= 1;
10104             break;
10105         case 'v':
10106             fVerbose ^= 1;
10107             break;
10108         case 'h':
10109         default:
10110             goto usage;
10111         }
10112     }
10113     if ( pNtk == NULL )
10114     {
10115         Abc_Print( -1, "Empty network.\n" );
10116         return 1;
10117     }
10118     if ( !Abc_NtkIsStrash(pNtk) )
10119     {
10120         Abc_Print( -1, "This command works only for AIGs (run \"strash\").\n" );
10121         return 1;
10122     }
10123     if ( pAbc->vCexVec == NULL )
10124     {
10125         Abc_Print( -1, "CEX array is not defined. Run \"bmc3 -az\", \"sim3 -az\", or \"pdr -az\".\n" );
10126         return 1;
10127     }
10128     if ( Vec_PtrSize(pAbc->vCexVec) != Abc_NtkPoNum(pNtk) )
10129     {
10130         Abc_Print( -1, "CEX array size (%d) does not match the number of outputs (%d).\n", Vec_PtrSize(pAbc->vCexVec), Abc_NtkPoNum(pNtk) );
10131         return 1;
10132     }
10133     Abc_NtkDropSatOutputs( pNtk, pAbc->vCexVec, fVerbose );
10134     if ( !fNoSweep )
10135     {
10136         pNtkRes = Abc_NtkDarLatchSweep( pNtk, 1, 1, 1, 0, -1, -1, 0, 0 );
10137         if ( pNtkRes == NULL )
10138         {
10139             Abc_Print( -1, "Removing SAT outputs has failed.\n" );
10140             return 1;
10141         }
10142         Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
10143     }
10144     return 0;
10145 
10146 usage:
10147     Abc_Print( -2, "usage: dropsat [-sh]\n" );
10148     Abc_Print( -2, "\t         replaces satisfiable POs by constant 0 and cleans up the AIG\n" );
10149     Abc_Print( -2, "\t-s     : toggles skipping sequential sweep [default = %s]\n", fNoSweep? "yes": "no" );
10150     Abc_Print( -2, "\t-v     : toggles verbose output [default = %s]\n", fVerbose? "yes": "no" );
10151     Abc_Print( -2, "\t-h     : print the command usage\n");
10152     return 1;
10153 }
10154 
10155 /**Function*************************************************************
10156 
10157   Synopsis    []
10158 
10159   Description []
10160 
10161   SideEffects []
10162 
10163   SeeAlso     []
10164 
10165 ***********************************************************************/
Abc_CommandAddPi(Abc_Frame_t * pAbc,int argc,char ** argv)10166 int Abc_CommandAddPi( Abc_Frame_t * pAbc, int argc, char ** argv )
10167 {
10168     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc), * pNtkRes;
10169     int c;
10170 
10171     // set defaults
10172     Extra_UtilGetoptReset();
10173     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
10174     {
10175         switch ( c )
10176         {
10177         case 'h':
10178         default:
10179             goto usage;
10180         }
10181     }
10182 
10183     if ( pNtk == NULL )
10184     {
10185         Abc_Print( -1, "Empty network.\n" );
10186         return 1;
10187     }
10188 
10189     // get the new network
10190     pNtkRes = Abc_NtkDup( pNtk );
10191     if ( Abc_NtkPiNum(pNtkRes) == 0 )
10192     {
10193         Abc_Obj_t * pObj = Abc_NtkCreatePi( pNtkRes );
10194         Abc_ObjAssignName( pObj, "dummy_pi", NULL );
10195         Abc_NtkOrderCisCos( pNtkRes );
10196     }
10197     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
10198     return 0;
10199 
10200 usage:
10201     Abc_Print( -2, "usage: addpi [-h]\n" );
10202     Abc_Print( -2, "\t         if the network has no PIs, add one dummy PI\n" );
10203     Abc_Print( -2, "\t-h     : print the command usage\n");
10204     return 1;
10205 }
10206 
10207 /**Function*************************************************************
10208 
10209   Synopsis    []
10210 
10211   Description []
10212 
10213   SideEffects []
10214 
10215   SeeAlso     []
10216 
10217 ***********************************************************************/
Abc_CommandAppend(Abc_Frame_t * pAbc,int argc,char ** argv)10218 int Abc_CommandAppend( Abc_Frame_t * pAbc, int argc, char ** argv )
10219 {
10220     Abc_Ntk_t * pNtk, * pNtk2;
10221     char * FileName;
10222     int fComb = 0;
10223     int c;
10224     pNtk = Abc_FrameReadNtk(pAbc);
10225 
10226     // set defaults
10227     Extra_UtilGetoptReset();
10228     while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
10229     {
10230         switch ( c )
10231         {
10232         case 'c':
10233             fComb ^= 1;
10234             break;
10235         default:
10236             goto usage;
10237         }
10238     }
10239 
10240     // get the second network
10241     if ( argc != globalUtilOptind + 1 )
10242     {
10243         Abc_Print( -1, "The network to append is not given.\n" );
10244         return 1;
10245     }
10246 
10247     if ( !Abc_NtkIsStrash(pNtk) )
10248     {
10249         Abc_Print( -1, "The base network should be strashed for the appending to work.\n" );
10250         return 1;
10251     }
10252 
10253     // read the second network
10254     FileName = argv[globalUtilOptind];
10255     pNtk2 = Io_Read( FileName, Io_ReadFileType(FileName), 1, 0 );
10256     if ( pNtk2 == NULL )
10257         return 1;
10258 
10259     // check if the second network is combinational
10260     if ( Abc_NtkLatchNum(pNtk2) )
10261     {
10262         Abc_NtkDelete( pNtk2 );
10263         Abc_Print( -1, "The second network has latches. Appending does not work for such networks.\n" );
10264         return 0;
10265     }
10266 
10267     // get the new network
10268     if ( !Abc_NtkAppend( pNtk, pNtk2, 1 ) )
10269     {
10270         Abc_NtkDelete( pNtk2 );
10271         Abc_Print( -1, "Appending the networks failed.\n" );
10272         return 1;
10273     }
10274     Abc_NtkDelete( pNtk2 );
10275     // sweep dangling logic
10276     Abc_AigCleanup( (Abc_Aig_t *)pNtk->pManFunc );
10277     // replace the current network
10278 //    Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
10279     return 0;
10280 
10281 usage:
10282     Abc_Print( -2, "usage: append [-h] <file>\n" );
10283     Abc_Print( -2, "\t         appends a combinational network on top of the current network\n" );
10284 //    Abc_Print( -2, "\t-c     : computes combinational miter (latches as POs) [default = %s]\n", fComb? "yes": "no" );
10285     Abc_Print( -2, "\t-h     : print the command usage\n");
10286     Abc_Print( -2, "\t<file> : file name with the second network\n");
10287     return 1;
10288 }
10289 
10290 /**Function*************************************************************
10291 
10292   Synopsis    []
10293 
10294   Description []
10295 
10296   SideEffects []
10297 
10298   SeeAlso     []
10299 
10300 ***********************************************************************/
Abc_CommandPutOnTop(Abc_Frame_t * pAbc,int argc,char ** argv)10301 int Abc_CommandPutOnTop( Abc_Frame_t * pAbc, int argc, char ** argv )
10302 {
10303     extern Abc_Ntk_t * Abc_NtkPutOnTop( Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtk2 );
10304 
10305     Abc_Ntk_t * pNtk, * pNtk2, * pNtkRes;
10306     char * FileName;
10307     int fComb = 0;
10308     int c;
10309     pNtk = Abc_FrameReadNtk(pAbc);
10310 
10311     // set defaults
10312     Extra_UtilGetoptReset();
10313     while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
10314     {
10315         switch ( c )
10316         {
10317         case 'c':
10318             fComb ^= 1;
10319             break;
10320         default:
10321             goto usage;
10322         }
10323     }
10324 
10325     // get the second network
10326     if ( argc != globalUtilOptind + 1 )
10327     {
10328         Abc_Print( -1, "The network to append is not given.\n" );
10329         return 1;
10330     }
10331 
10332     if ( !Abc_NtkIsLogic(pNtk) )
10333     {
10334         Abc_Print( -1, "The base network should be in the logic form.\n" );
10335         return 1;
10336     }
10337 
10338     // check if the second network is combinational
10339     if ( Abc_NtkLatchNum(pNtk) )
10340     {
10341         Abc_Print( -1, "The current network has latches. This command does not work for such networks.\n" );
10342         return 0;
10343     }
10344 
10345     // read the second network
10346     FileName = argv[globalUtilOptind];
10347     pNtk2 = Io_Read( FileName, Io_ReadFileType(FileName), 1, 0 );
10348     if ( pNtk2 == NULL )
10349         return 1;
10350 
10351     // check if the second network is combinational
10352     if ( Abc_NtkLatchNum(pNtk2) )
10353     {
10354         Abc_NtkDelete( pNtk2 );
10355         Abc_Print( -1, "The second network has latches. This command does not work for such networks.\n" );
10356         return 0;
10357     }
10358     // compare inputs/outputs
10359     if ( Abc_NtkPoNum(pNtk) != Abc_NtkPiNum(pNtk2) )
10360     {
10361         Abc_NtkDelete( pNtk2 );
10362         Abc_Print( -1, "The PO count (%d) of the first network is not equal to PI count (%d) of the second network.\n", Abc_NtkPoNum(pNtk), Abc_NtkPiNum(pNtk2) );
10363         return 0;
10364     }
10365 
10366     // get the new network
10367     pNtkRes = Abc_NtkPutOnTop( pNtk, pNtk2 );
10368     Abc_NtkDelete( pNtk2 );
10369     // replace the current network
10370     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
10371     return 0;
10372 
10373 usage:
10374     Abc_Print( -2, "usage: putontop [-h] <file>\n" );
10375     Abc_Print( -2, "\t         connects PIs of network in <file> to POs of current network\n" );
10376     Abc_Print( -2, "\t-h     : print the command usage\n");
10377     Abc_Print( -2, "\t<file> : file name with the second network\n");
10378     return 1;
10379 }
10380 
10381 /**Function*************************************************************
10382 
10383   Synopsis    []
10384 
10385   Description []
10386 
10387   SideEffects []
10388 
10389   SeeAlso     []
10390 
10391 ***********************************************************************/
Abc_CommandFrames(Abc_Frame_t * pAbc,int argc,char ** argv)10392 int Abc_CommandFrames( Abc_Frame_t * pAbc, int argc, char ** argv )
10393 {
10394     Abc_Ntk_t * pNtk, * pNtkTemp, * pNtkRes;
10395     int nFrames;
10396     int fInitial;
10397     int fVerbose;
10398     int c;
10399     pNtk = Abc_FrameReadNtk(pAbc);
10400 
10401     // set defaults
10402     nFrames  = 5;
10403     fInitial = 0;
10404     fVerbose = 0;
10405     Extra_UtilGetoptReset();
10406     while ( ( c = Extra_UtilGetopt( argc, argv, "Fivh" ) ) != EOF )
10407     {
10408         switch ( c )
10409         {
10410         case 'F':
10411             if ( globalUtilOptind >= argc )
10412             {
10413                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
10414                 goto usage;
10415             }
10416             nFrames = atoi(argv[globalUtilOptind]);
10417             globalUtilOptind++;
10418             if ( nFrames <= 0 )
10419                 goto usage;
10420             break;
10421         case 'i':
10422             fInitial ^= 1;
10423             break;
10424         case 'v':
10425             fVerbose ^= 1;
10426             break;
10427         case 'h':
10428             goto usage;
10429         default:
10430             goto usage;
10431         }
10432     }
10433 
10434     if ( pNtk == NULL )
10435     {
10436         Abc_Print( -1, "Empty network.\n" );
10437         return 1;
10438     }
10439 
10440     // get the new network
10441     if ( !Abc_NtkIsStrash(pNtk) )
10442     {
10443         pNtkTemp = Abc_NtkStrash( pNtk, 0, 0, 0 );
10444         pNtkRes  = Abc_NtkFrames( pNtkTemp, nFrames, fInitial, fVerbose );
10445         Abc_NtkDelete( pNtkTemp );
10446     }
10447     else
10448         pNtkRes  = Abc_NtkFrames( pNtk, nFrames, fInitial, fVerbose );
10449     if ( pNtkRes == NULL )
10450     {
10451         Abc_Print( -1, "Unrolling the network has failed.\n" );
10452         return 1;
10453     }
10454     // replace the current network
10455     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
10456     return 0;
10457 
10458 usage:
10459     Abc_Print( -2, "usage: frames [-F <num>] [-ivh]\n" );
10460     Abc_Print( -2, "\t           unrolls the network for a number of time frames\n" );
10461     Abc_Print( -2, "\t-F <num> : the number of frames to unroll [default = %d]\n", nFrames );
10462     Abc_Print( -2, "\t-i       : toggles initializing the first frame [default = %s]\n", fInitial? "yes": "no" );
10463     Abc_Print( -2, "\t-v       : toggles outputting verbose information [default = %s]\n", fVerbose? "yes": "no" );
10464     Abc_Print( -2, "\t-h       : print the command usage\n");
10465     return 1;
10466 }
10467 
10468 /**Function*************************************************************
10469 
10470   Synopsis    []
10471 
10472   Description []
10473 
10474   SideEffects []
10475 
10476   SeeAlso     []
10477 
10478 ***********************************************************************/
Abc_CommandDFrames(Abc_Frame_t * pAbc,int argc,char ** argv)10479 int Abc_CommandDFrames( Abc_Frame_t * pAbc, int argc, char ** argv )
10480 {
10481     Abc_Ntk_t * pNtk, * pNtkTemp, * pNtkRes;
10482     int nPrefix;
10483     int nFrames;
10484     int fInitial;
10485     int fVerbose;
10486     int c;
10487 
10488     extern Abc_Ntk_t * Abc_NtkDarFrames( Abc_Ntk_t * pNtk, int nPrefix, int nFrames, int fInitial, int fVerbose );
10489     pNtk = Abc_FrameReadNtk(pAbc);
10490 
10491     // set defaults
10492     nPrefix  = 5;
10493     nFrames  = 5;
10494     fInitial = 0;
10495     fVerbose = 0;
10496     Extra_UtilGetoptReset();
10497     while ( ( c = Extra_UtilGetopt( argc, argv, "NFivh" ) ) != EOF )
10498     {
10499         switch ( c )
10500         {
10501         case 'N':
10502             if ( globalUtilOptind >= argc )
10503             {
10504                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
10505                 goto usage;
10506             }
10507             nPrefix = atoi(argv[globalUtilOptind]);
10508             globalUtilOptind++;
10509             if ( nPrefix <= 0 )
10510                 goto usage;
10511             break;
10512         case 'F':
10513             if ( globalUtilOptind >= argc )
10514             {
10515                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
10516                 goto usage;
10517             }
10518             nFrames = atoi(argv[globalUtilOptind]);
10519             globalUtilOptind++;
10520             if ( nFrames <= 0 )
10521                 goto usage;
10522             break;
10523         case 'i':
10524             fInitial ^= 1;
10525             break;
10526         case 'v':
10527             fVerbose ^= 1;
10528             break;
10529         case 'h':
10530             goto usage;
10531         default:
10532             goto usage;
10533         }
10534     }
10535 
10536     if ( pNtk == NULL )
10537     {
10538         Abc_Print( -1, "Empty network.\n" );
10539         return 1;
10540     }
10541     if ( nPrefix > nFrames )
10542     {
10543         Abc_Print( -1, "Prefix (%d) cannot be more than the number of frames (%d).\n", nPrefix, nFrames );
10544         return 1;
10545     }
10546 
10547     // get the new network
10548     if ( !Abc_NtkIsStrash(pNtk) )
10549     {
10550         pNtkTemp = Abc_NtkStrash( pNtk, 0, 0, 0 );
10551         pNtkRes  = Abc_NtkDarFrames( pNtkTemp, nPrefix, nFrames, fInitial, fVerbose );
10552         Abc_NtkDelete( pNtkTemp );
10553     }
10554     else
10555         pNtkRes  = Abc_NtkDarFrames( pNtk, nPrefix, nFrames, fInitial, fVerbose );
10556     if ( pNtkRes == NULL )
10557     {
10558         Abc_Print( -1, "Unrolling the network has failed.\n" );
10559         return 1;
10560     }
10561     // replace the current network
10562     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
10563     return 0;
10564 
10565 usage:
10566     Abc_Print( -2, "usage: dframes [-NF <num>] [-ivh]\n" );
10567     Abc_Print( -2, "\t         unrolls the network with simplification\n" );
10568     Abc_Print( -2, "\t-N num : the number of frames to use as prefix [default = %d]\n", nPrefix );
10569     Abc_Print( -2, "\t-F num : the number of frames to unroll [default = %d]\n", nFrames );
10570     Abc_Print( -2, "\t-i     : toggles initializing the first frame [default = %s]\n", fInitial? "yes": "no" );
10571     Abc_Print( -2, "\t-v     : toggles outputting verbose information [default = %s]\n", fVerbose? "yes": "no" );
10572     Abc_Print( -2, "\t-h     : print the command usage\n");
10573     return 1;
10574 }
10575 
10576 
10577 
10578 /**Function*************************************************************
10579 
10580   Synopsis    []
10581 
10582   Description []
10583 
10584   SideEffects []
10585 
10586   SeeAlso     []
10587 
10588 ***********************************************************************/
Abc_CommandSop(Abc_Frame_t * pAbc,int argc,char ** argv)10589 int Abc_CommandSop( Abc_Frame_t * pAbc, int argc, char ** argv )
10590 {
10591     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
10592     int c, fMode = -1, nCubeLimit = 1000000;
10593 
10594     // set defaults
10595     Extra_UtilGetoptReset();
10596     while ( ( c = Extra_UtilGetopt( argc, argv, "Cdnh" ) ) != EOF )
10597     {
10598         switch ( c )
10599         {
10600         case 'C':
10601             if ( globalUtilOptind >= argc )
10602             {
10603                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
10604                 goto usage;
10605             }
10606             nCubeLimit = atoi(argv[globalUtilOptind]);
10607             globalUtilOptind++;
10608             if ( nCubeLimit < 0 )
10609                 goto usage;
10610             break;
10611         case 'd':
10612             fMode = 1;
10613             break;
10614         case 'n':
10615             fMode = 0;
10616             break;
10617         case 'h':
10618             goto usage;
10619         default:
10620             goto usage;
10621         }
10622     }
10623     if ( pNtk == NULL )
10624     {
10625         Abc_Print( -1, "Empty network.\n" );
10626         return 1;
10627     }
10628     if ( !Abc_NtkIsLogic(pNtk) )
10629     {
10630         Abc_Print( -1, "Converting to SOP is possible only for logic networks.\n" );
10631         return 1;
10632     }
10633     if ( !Abc_NtkToSop(pNtk, fMode, nCubeLimit) )
10634     {
10635         Abc_Print( -1, "Converting to SOP has failed.\n" );
10636         return 0;
10637     }
10638     return 0;
10639 
10640 usage:
10641     Abc_Print( -2, "usage: sop [-C num] [-dnh]\n" );
10642     Abc_Print( -2, "\t         converts node functions to SOP\n" );
10643     Abc_Print( -2, "\t-C num : the limit on the number of cubes at a node [default = %d]\n", nCubeLimit );
10644     Abc_Print( -2, "\t-d     : toggles using only positive polarity [default = %s]\n", fMode == 1 ? "yes": "no"  );
10645     Abc_Print( -2, "\t-n     : toggles using only negative polarity [default = %s]\n", fMode == 0 ? "yes": "no" );
10646     Abc_Print( -2, "\t-h     : print the command usage\n");
10647     return 1;
10648 }
10649 
10650 /**Function*************************************************************
10651 
10652   Synopsis    []
10653 
10654   Description []
10655 
10656   SideEffects []
10657 
10658   SeeAlso     []
10659 
10660 ***********************************************************************/
Abc_CommandBdd(Abc_Frame_t * pAbc,int argc,char ** argv)10661 int Abc_CommandBdd( Abc_Frame_t * pAbc, int argc, char ** argv )
10662 {
10663     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
10664     int fReorder = 1, fBdd2Sop = 0;
10665     int c;
10666 
10667     // set defaults
10668     Extra_UtilGetoptReset();
10669     while ( ( c = Extra_UtilGetopt( argc, argv, "rsh" ) ) != EOF )
10670     {
10671         switch ( c )
10672         {
10673         case 'r':
10674             fReorder ^= 1;
10675             break;
10676         case 's':
10677             fBdd2Sop ^= 1;
10678             break;
10679         case 'h':
10680             goto usage;
10681         default:
10682             goto usage;
10683         }
10684     }
10685     if ( pNtk == NULL )
10686     {
10687         Abc_Print( -1, "Empty network.\n" );
10688         return 1;
10689     }
10690     if ( !Abc_NtkIsLogic(pNtk) )
10691     {
10692         Abc_Print( -1, "Converting to BDD is possible only for logic networks.\n" );
10693         return 1;
10694     }
10695     if ( fBdd2Sop && Abc_NtkHasSop(pNtk) )
10696         return !Abc_NtkSopToBdd(pNtk);
10697     if ( Abc_NtkIsBddLogic(pNtk) )
10698     {
10699         Abc_Print( -1, "The logic network is already in the BDD form.\n" );
10700         return 0;
10701     }
10702     if ( !Abc_NtkToBdd(pNtk) )
10703     {
10704         Abc_Print( -1, "Converting to BDD has failed.\n" );
10705         return 1;
10706     }
10707     return 0;
10708 
10709 usage:
10710     Abc_Print( -2, "usage: bdd [-rsh]\n" );
10711     Abc_Print( -2, "\t         converts node functions to BDD\n" );
10712     Abc_Print( -2, "\t-r     : toggles enabling dynamic variable reordering [default = %s]\n", fReorder? "yes": "no" );
10713     Abc_Print( -2, "\t-s     : toggles constructing BDDs directly from SOPs [default = %s]\n", fBdd2Sop? "yes": "no" );
10714     Abc_Print( -2, "\t-h     : print the command usage\n");
10715     return 1;
10716 }
10717 
10718 /**Function*************************************************************
10719 
10720   Synopsis    []
10721 
10722   Description []
10723 
10724   SideEffects []
10725 
10726   SeeAlso     []
10727 
10728 ***********************************************************************/
Abc_CommandAig(Abc_Frame_t * pAbc,int argc,char ** argv)10729 int Abc_CommandAig( Abc_Frame_t * pAbc, int argc, char ** argv )
10730 {
10731     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
10732     int c;
10733 
10734     // set defaults
10735     Extra_UtilGetoptReset();
10736     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
10737     {
10738         switch ( c )
10739         {
10740         case 'h':
10741             goto usage;
10742         default:
10743             goto usage;
10744         }
10745     }
10746     if ( pNtk == NULL )
10747     {
10748         Abc_Print( -1, "Empty network.\n" );
10749         return 1;
10750     }
10751     if ( !Abc_NtkIsLogic(pNtk) )
10752     {
10753         Abc_Print( -1, "Converting to AIG is possible only for logic networks.\n" );
10754         return 1;
10755     }
10756     if ( Abc_NtkIsAigLogic(pNtk) )
10757     {
10758         Abc_Print( -1, "The logic network is already in the AIG form.\n" );
10759         return 0;
10760     }
10761     if ( !Abc_NtkToAig(pNtk) )
10762     {
10763         Abc_Print( -1, "Converting to AIG has failed.\n" );
10764         return 1;
10765     }
10766     return 0;
10767 
10768 usage:
10769     Abc_Print( -2, "usage: aig [-h]\n" );
10770     Abc_Print( -2, "\t         converts node functions to AIG\n" );
10771     Abc_Print( -2, "\t-h     : print the command usage\n");
10772     return 1;
10773 }
10774 
10775 /**Function*************************************************************
10776 
10777   Synopsis    []
10778 
10779   Description []
10780 
10781   SideEffects []
10782 
10783   SeeAlso     []
10784 
10785 ***********************************************************************/
Abc_CommandReorder(Abc_Frame_t * pAbc,int argc,char ** argv)10786 int Abc_CommandReorder( Abc_Frame_t * pAbc, int argc, char ** argv )
10787 {
10788     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
10789     int c;
10790     int fVerbose;
10791     extern void Abc_NtkBddReorder( Abc_Ntk_t * pNtk, int fVerbose );
10792 
10793     // set defaults
10794     fVerbose = 0;
10795     Extra_UtilGetoptReset();
10796     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
10797     {
10798         switch ( c )
10799         {
10800         case 'v':
10801             fVerbose ^= 1;
10802             break;
10803         case 'h':
10804             goto usage;
10805         default:
10806             goto usage;
10807         }
10808     }
10809 
10810     if ( pNtk == NULL )
10811     {
10812         Abc_Print( -1, "Empty network.\n" );
10813         return 1;
10814     }
10815 
10816     // get the new network
10817     if ( !Abc_NtkIsBddLogic(pNtk) )
10818     {
10819         Abc_Print( -1, "Variable reordering is possible when node functions are BDDs (run \"bdd\").\n" );
10820         return 1;
10821     }
10822     Abc_NtkBddReorder( pNtk, fVerbose );
10823     return 0;
10824 
10825 usage:
10826     Abc_Print( -2, "usage: reorder [-vh]\n" );
10827     Abc_Print( -2, "\t         reorders local functions of the nodes using sifting\n" );
10828     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
10829     Abc_Print( -2, "\t-h     : print the command usage\n");
10830     return 1;
10831 }
10832 
10833 /**Function*************************************************************
10834 
10835   Synopsis    []
10836 
10837   Description []
10838 
10839   SideEffects []
10840 
10841   SeeAlso     []
10842 
10843 ***********************************************************************/
Abc_CommandBidec(Abc_Frame_t * pAbc,int argc,char ** argv)10844 int Abc_CommandBidec( Abc_Frame_t * pAbc, int argc, char ** argv )
10845 {
10846     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
10847     int c;
10848     int fVerbose;
10849     extern void Abc_NtkBidecResyn( Abc_Ntk_t * pNtk, int fVerbose );
10850 
10851     // set defaults
10852     fVerbose = 0;
10853     Extra_UtilGetoptReset();
10854     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
10855     {
10856         switch ( c )
10857         {
10858         case 'v':
10859             fVerbose ^= 1;
10860             break;
10861         case 'h':
10862             goto usage;
10863         default:
10864             goto usage;
10865         }
10866     }
10867 
10868     if ( pNtk == NULL )
10869     {
10870         Abc_Print( -1, "Empty network.\n" );
10871         return 1;
10872     }
10873 
10874     // get the new network
10875     if ( !Abc_NtkIsAigLogic(pNtk) )
10876     {
10877         Abc_Print( -1, "Bi-decomposition only works when node functions are AIGs (run \"aig\").\n" );
10878         return 1;
10879     }
10880     Abc_NtkBidecResyn( pNtk, fVerbose );
10881     return 0;
10882 
10883 usage:
10884     Abc_Print( -2, "usage: bidec [-vh]\n" );
10885     Abc_Print( -2, "\t         applies bi-decomposition to local functions of the nodes\n" );
10886     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
10887     Abc_Print( -2, "\t-h     : print the command usage\n");
10888     return 1;
10889 }
10890 
10891 /**Function*************************************************************
10892 
10893   Synopsis    []
10894 
10895   Description []
10896 
10897   SideEffects []
10898 
10899   SeeAlso     []
10900 
10901 ***********************************************************************/
Abc_CommandOrder(Abc_Frame_t * pAbc,int argc,char ** argv)10902 int Abc_CommandOrder( Abc_Frame_t * pAbc, int argc, char ** argv )
10903 {
10904     FILE * pFile;
10905     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
10906     char * pFileName;
10907     int c;
10908     int fReverse;
10909     int fVerbose;
10910     extern void Abc_NtkImplementCiOrder( Abc_Ntk_t * pNtk, char * pFileName, int fReverse, int fVerbose );
10911     extern void Abc_NtkFindCiOrder( Abc_Ntk_t * pNtk, int fReverse, int fVerbose );
10912 
10913     // set defaults
10914     fReverse = 0;
10915     fVerbose = 0;
10916     Extra_UtilGetoptReset();
10917     while ( ( c = Extra_UtilGetopt( argc, argv, "rvh" ) ) != EOF )
10918     {
10919         switch ( c )
10920         {
10921         case 'r':
10922             fReverse ^= 1;
10923             break;
10924         case 'v':
10925             fVerbose ^= 1;
10926             break;
10927         case 'h':
10928             goto usage;
10929         default:
10930             goto usage;
10931         }
10932     }
10933 
10934     if ( pNtk == NULL )
10935     {
10936         Abc_Print( -1, "Empty network.\n" );
10937         return 1;
10938     }
10939 //    if ( Abc_NtkLatchNum(pNtk) > 0 )
10940 //    {
10941 //        Abc_Print( -1, "Currently this procedure does not work for sequential networks.\n" );
10942 //        return 1;
10943 //    }
10944 
10945     // if the var order file is given, implement this order
10946     pFileName = NULL;
10947     if ( argc == globalUtilOptind + 1 )
10948     {
10949         pFileName = argv[globalUtilOptind];
10950         pFile = fopen( pFileName, "r" );
10951         if ( pFile == NULL )
10952         {
10953             Abc_Print( -1, "Cannot open file \"%s\" with the BDD variable order.\n", pFileName );
10954             return 1;
10955         }
10956         fclose( pFile );
10957     }
10958     if ( pFileName )
10959         Abc_NtkImplementCiOrder( pNtk, pFileName, fReverse, fVerbose );
10960     else
10961         Abc_NtkFindCiOrder( pNtk, fReverse, fVerbose );
10962     return 0;
10963 
10964 usage:
10965     Abc_Print( -2, "usage: order [-rvh] <file>\n" );
10966     Abc_Print( -2, "\t         computes a good static CI variable order\n" );
10967     Abc_Print( -2, "\t-r     : toggle reverse ordering [default = %s]\n", fReverse? "yes": "no" );
10968     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
10969     Abc_Print( -2, "\t-h     : print the command usage\n");
10970     Abc_Print( -2, "\t<file> : (optional) file with the given variable order\n" );
10971     return 1;
10972 }
10973 
10974 /**Function*************************************************************
10975 
10976   Synopsis    []
10977 
10978   Description []
10979 
10980   SideEffects []
10981 
10982   SeeAlso     []
10983 
10984 ***********************************************************************/
Abc_CommandMuxes(Abc_Frame_t * pAbc,int argc,char ** argv)10985 int Abc_CommandMuxes( Abc_Frame_t * pAbc, int argc, char ** argv )
10986 {
10987     Abc_Ntk_t * pNtk, * pNtkRes;
10988     int c, fGlobal = 0, Limit = 1000000;
10989     pNtk = Abc_FrameReadNtk(pAbc);
10990     // set defaults
10991     Extra_UtilGetoptReset();
10992     while ( ( c = Extra_UtilGetopt( argc, argv, "Bgh" ) ) != EOF )
10993     {
10994         switch ( c )
10995         {
10996         case 'B':
10997             if ( globalUtilOptind >= argc )
10998             {
10999                 Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" );
11000                 goto usage;
11001             }
11002             Limit = atoi(argv[globalUtilOptind]);
11003             globalUtilOptind++;
11004             if ( Limit < 0 )
11005                 goto usage;
11006             break;
11007         case 'g':
11008             fGlobal ^= 1;
11009             break;
11010         case 'h':
11011             goto usage;
11012         default:
11013             goto usage;
11014         }
11015     }
11016 
11017     if ( pNtk == NULL )
11018     {
11019         Abc_Print( -1, "Empty network.\n" );
11020         return 1;
11021     }
11022 
11023     if ( fGlobal )
11024     {
11025         if ( !Abc_NtkIsStrash(pNtk) )
11026         {
11027             Abc_Print( -1, "The current network should be an AIG.\n" );
11028             return 1;
11029         }
11030     }
11031     else
11032     {
11033         if ( !Abc_NtkIsBddLogic(pNtk) )
11034         {
11035             Abc_Print( -1, "Only a BDD logic network can be converted to MUXes.\n" );
11036             return 1;
11037         }
11038     }
11039 
11040     // get the new network
11041     pNtkRes = Abc_NtkBddToMuxes( pNtk, fGlobal, Limit );
11042     if ( pNtkRes == NULL )
11043     {
11044         Abc_Print( 0, "Converting to MUXes has failed.\n" );
11045         return 0;
11046     }
11047     // replace the current network
11048     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
11049     return 0;
11050 
11051 usage:
11052     Abc_Print( -2, "usage: muxes [-B num] [-gh]\n" );
11053     Abc_Print( -2, "\t          converts the current network into a network derived by\n" );
11054     Abc_Print( -2, "\t          replacing all nodes by DAGs isomorphic to the local BDDs\n" );
11055     Abc_Print( -2, "\t-B <num>: limit on live BDD nodes during collapsing [default = %d]\n", Limit );
11056     Abc_Print( -2, "\t-g      : toggle visualizing the global BDDs of primary outputs [default = %s].\n", fGlobal? "yes": "no" );
11057     Abc_Print( -2, "\t-h      : print the command usage\n");
11058     return 1;
11059 }
11060 
11061 /**Function*************************************************************
11062 
11063   Synopsis    []
11064 
11065   Description []
11066 
11067   SideEffects []
11068 
11069   SeeAlso     []
11070 
11071 ***********************************************************************/
Abc_CommandCubes(Abc_Frame_t * pAbc,int argc,char ** argv)11072 int Abc_CommandCubes( Abc_Frame_t * pAbc, int argc, char ** argv )
11073 {
11074     extern Abc_Ntk_t * Abc_NtkSopToCubes( Abc_Ntk_t * pNtk, int fXor );
11075     Abc_Ntk_t * pNtk, * pNtkRes;
11076     int c, fXor = 0;
11077 
11078     pNtk = Abc_FrameReadNtk(pAbc);
11079     // set defaults
11080     Extra_UtilGetoptReset();
11081     while ( ( c = Extra_UtilGetopt( argc, argv, "xh" ) ) != EOF )
11082     {
11083         switch ( c )
11084         {
11085         case 'x':
11086             fXor ^= 1;
11087             break;
11088         case 'h':
11089             goto usage;
11090         default:
11091             goto usage;
11092         }
11093     }
11094 
11095     if ( pNtk == NULL )
11096     {
11097         Abc_Print( -1, "Empty network.\n" );
11098         return 1;
11099     }
11100 
11101     if ( !Abc_NtkIsSopLogic(pNtk) )
11102     {
11103         Abc_Print( -1, "Only a SOP logic network can be transformed into cubes.\n" );
11104         return 1;
11105     }
11106 
11107     // get the new network
11108     pNtkRes = Abc_NtkSopToCubes( pNtk, fXor );
11109     if ( pNtkRes == NULL )
11110     {
11111         Abc_Print( -1, "Converting to cubes has failed.\n" );
11112         return 1;
11113     }
11114     // replace the current network
11115     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
11116     return 0;
11117 
11118 usage:
11119     Abc_Print( -2, "usage: cubes [-xh]\n" );
11120     Abc_Print( -2, "\t        converts the current network into a network derived by creating\n" );
11121     Abc_Print( -2, "\t        a separate node for each product and sum in the local SOPs\n" );
11122     Abc_Print( -2, "\t-x    : toggle using XOR instead of OR [default = %s]\n", fXor? "yes": "no" );
11123     Abc_Print( -2, "\t-h    : print the command usage\n");
11124     return 1;
11125 }
11126 
11127 /**Function*************************************************************
11128 
11129   Synopsis    []
11130 
11131   Description []
11132 
11133   SideEffects []
11134 
11135   SeeAlso     []
11136 
11137 ***********************************************************************/
Abc_CommandExpand(Abc_Frame_t * pAbc,int argc,char ** argv)11138 int Abc_CommandExpand( Abc_Frame_t * pAbc, int argc, char ** argv )
11139 {
11140     extern void Abc_NtkExpandCubes( Abc_Ntk_t * pNtk, Gia_Man_t * pGia, int fVerbose );
11141     Abc_Ntk_t * pStrash, * pNtk2, * pNtk = Abc_FrameReadNtk(pAbc);
11142     Gia_Man_t * pGia; int c, fVerbose = 0;
11143     Extra_UtilGetoptReset();
11144     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
11145     {
11146         switch ( c )
11147         {
11148         case 'v':
11149             fVerbose ^= 1;
11150             break;
11151         case 'h':
11152             goto usage;
11153         default:
11154             goto usage;
11155         }
11156     }
11157     if ( pNtk == NULL )
11158     {
11159         Abc_Print( -1, "Empty network.\n" );
11160         return 1;
11161     }
11162     if ( !Abc_NtkIsSopLogic(pNtk) )
11163     {
11164         Abc_Print( -1, "Only a SOP logic network can be transformed into cubes.\n" );
11165         return 1;
11166     }
11167     if ( Abc_NtkLevel(pNtk) > 1 )
11168     {
11169         Abc_Print( -1, "The number of logic levels is more than 1 (collapse the network and try again).\n" );
11170         return 1;
11171     }
11172     // read the offset representation
11173     if ( argc != globalUtilOptind + 1 )
11174     {
11175         Abc_Print( 0, "Using the complement of the current network as its offset.\n" );
11176         pNtk2 = Abc_NtkDup( pNtk );
11177     }
11178     else
11179     {
11180         char * FileName = argv[globalUtilOptind];
11181         pNtk2 = Io_Read( FileName, Io_ReadFileType(FileName), 1, 0 );
11182         if ( pNtk2 == NULL )
11183         {
11184             Abc_Print( -1, "Failed to read the current network from file \"%s\".\n", FileName );
11185             return 1;
11186         }
11187     }
11188     // strash the network
11189     pStrash = Abc_NtkStrash( pNtk2, 0, 1, 0 );
11190     Abc_NtkDelete( pNtk2 );
11191     // convert it into an AIG
11192     pGia = Abc_NtkClpGia( pStrash );
11193     //Gia_AigerWrite( pGia, "aig_dump.aig", 0, 0, 0 );
11194     Abc_NtkDelete( pStrash );
11195     // get the new network
11196     Abc_NtkExpandCubes( pNtk, pGia, fVerbose );
11197     Gia_ManStop( pGia );
11198     return 0;
11199 
11200 usage:
11201     Abc_Print( -2, "usage: expand [-vh] <file>\n" );
11202     Abc_Print( -2, "\t        expands cubes against the offset\n" );
11203     Abc_Print( -2, "\t-v    : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
11204     Abc_Print( -2, "\t-h    : print the command usage\n");
11205     Abc_Print( -2, "\tfile  : (optional) representation of on-set plus dc-set\n");
11206 
11207     return 1;
11208 }
11209 
11210 /**Function*************************************************************
11211 
11212   Synopsis    []
11213 
11214   Description []
11215 
11216   SideEffects []
11217 
11218   SeeAlso     []
11219 
11220 ***********************************************************************/
Abc_CommandSplitSop(Abc_Frame_t * pAbc,int argc,char ** argv)11221 int Abc_CommandSplitSop( Abc_Frame_t * pAbc, int argc, char ** argv )
11222 {
11223     extern Abc_Ntk_t * Abc_NtkSplitSop( Abc_Ntk_t * pNtk, int nCubesMax, int fVerbose );
11224     Abc_Ntk_t * pNtk, * pNtkRes;
11225     int c, fVerbose = 0, nCubesMax = 100;
11226     pNtk = Abc_FrameReadNtk(pAbc);
11227     // set defaults
11228     Extra_UtilGetoptReset();
11229     while ( ( c = Extra_UtilGetopt( argc, argv, "Nvh" ) ) != EOF )
11230     {
11231         switch ( c )
11232         {
11233         case 'N':
11234             if ( globalUtilOptind >= argc )
11235             {
11236                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
11237                 goto usage;
11238             }
11239             nCubesMax = atoi(argv[globalUtilOptind]);
11240             globalUtilOptind++;
11241             if ( nCubesMax < 0 )
11242                 goto usage;
11243             break;
11244         case 'v':
11245             fVerbose ^= 1;
11246             break;
11247         case 'h':
11248             goto usage;
11249         default:
11250             goto usage;
11251         }
11252     }
11253 
11254     if ( pNtk == NULL )
11255     {
11256         Abc_Print( -1, "Empty network.\n" );
11257         return 1;
11258     }
11259 
11260     if ( !Abc_NtkIsSopLogic(pNtk) )
11261     {
11262         Abc_Print( -1, "Only a SOP logic network can be transformed into cubes.\n" );
11263         return 1;
11264     }
11265 
11266     // get the new network
11267     pNtkRes = Abc_NtkSplitSop( pNtk, nCubesMax, fVerbose );
11268     if ( pNtkRes == NULL )
11269     {
11270         Abc_Print( -1, "Converting to cubes has failed.\n" );
11271         return 1;
11272     }
11273     // replace the current network
11274     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
11275     return 0;
11276 
11277 usage:
11278     Abc_Print( -2, "usage: splitsop [-N num] [-vh]\n" );
11279     Abc_Print( -2, "\t         splits nodes whose SOP size is larger than the given one\n" );
11280     Abc_Print( -2, "\t-N num : the maximum number of cubes after splitting [default = %d]\n", nCubesMax );
11281     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
11282     Abc_Print( -2, "\t-h     : print the command usage\n");
11283     return 1;
11284 }
11285 
11286 
11287 /**Function*************************************************************
11288 
11289   Synopsis    []
11290 
11291   Description []
11292 
11293   SideEffects []
11294 
11295   SeeAlso     []
11296 
11297 ***********************************************************************/
Abc_CommandExtSeqDcs(Abc_Frame_t * pAbc,int argc,char ** argv)11298 int Abc_CommandExtSeqDcs( Abc_Frame_t * pAbc, int argc, char ** argv )
11299 {
11300     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
11301     int c;
11302     int fVerbose;
11303     extern int Abc_NtkExtractSequentialDcs( Abc_Ntk_t * pNet, int fVerbose );
11304 
11305     pNtk = Abc_FrameReadNtk(pAbc);
11306     // set defaults
11307     fVerbose = 0;
11308     Extra_UtilGetoptReset();
11309     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
11310     {
11311         switch ( c )
11312         {
11313         case 'v':
11314             fVerbose ^= 1;
11315             break;
11316         case 'h':
11317             goto usage;
11318         default:
11319             goto usage;
11320         }
11321     }
11322 
11323     if ( pNtk == NULL )
11324     {
11325         Abc_Print( -1, "Empty network.\n" );
11326         return 1;
11327     }
11328     if ( Abc_NtkLatchNum(pNtk) == 0 )
11329     {
11330         Abc_Print( -1, "The current network has no latches.\n" );
11331         return 0;
11332     }
11333     if ( !Abc_NtkIsStrash(pNtk) )
11334     {
11335         Abc_Print( -1, "Extracting sequential don't-cares works only for AIGs (run \"strash\").\n" );
11336         return 0;
11337     }
11338     if ( !Abc_NtkExtractSequentialDcs( pNtk, fVerbose ) )
11339     {
11340         Abc_Print( -1, "Extracting sequential don't-cares has failed.\n" );
11341         return 1;
11342     }
11343     return 0;
11344 
11345 usage:
11346     Abc_Print( -2, "usage: ext_seq_dcs [-vh]\n" );
11347     Abc_Print( -2, "\t         create EXDC network using unreachable states\n" );
11348     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
11349     Abc_Print( -2, "\t-h     : print the command usage\n");
11350     return 1;
11351 }
11352 
11353 /**Function*************************************************************
11354 
11355   Synopsis    []
11356 
11357   Description []
11358 
11359   SideEffects []
11360 
11361   SeeAlso     []
11362 
11363 ***********************************************************************/
Abc_CommandReach(Abc_Frame_t * pAbc,int argc,char ** argv)11364 int Abc_CommandReach( Abc_Frame_t * pAbc, int argc, char ** argv )
11365 {
11366     Saig_ParBbr_t Pars, * pPars = &Pars;
11367     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
11368     int c;
11369     char * pLogFileName = NULL;
11370 
11371     extern int Abc_NtkDarReach( Abc_Ntk_t * pNtk, Saig_ParBbr_t * pPars );
11372 
11373     // set defaults
11374     Bbr_ManSetDefaultParams( pPars );
11375     Extra_UtilGetoptReset();
11376     while ( ( c = Extra_UtilGetopt( argc, argv, "TBFLproyvh" ) ) != EOF )
11377     {
11378         switch ( c )
11379         {
11380         case 'T':
11381             if ( globalUtilOptind >= argc )
11382             {
11383                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
11384                 goto usage;
11385             }
11386             pPars->TimeLimit = atoi(argv[globalUtilOptind]);
11387             globalUtilOptind++;
11388             if ( pPars->TimeLimit < 0 )
11389                 goto usage;
11390             break;
11391         case 'B':
11392             if ( globalUtilOptind >= argc )
11393             {
11394                 Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" );
11395                 goto usage;
11396             }
11397             pPars->nBddMax = atoi(argv[globalUtilOptind]);
11398             globalUtilOptind++;
11399             if ( pPars->nBddMax < 0 )
11400                 goto usage;
11401             break;
11402         case 'F':
11403             if ( globalUtilOptind >= argc )
11404             {
11405                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
11406                 goto usage;
11407             }
11408             pPars->nIterMax = atoi(argv[globalUtilOptind]);
11409             globalUtilOptind++;
11410             if ( pPars->nIterMax < 0 )
11411                 goto usage;
11412             break;
11413         case 'L':
11414             if ( globalUtilOptind >= argc )
11415             {
11416                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
11417                 goto usage;
11418             }
11419             pLogFileName = argv[globalUtilOptind];
11420             globalUtilOptind++;
11421             break;
11422         case 'p':
11423             pPars->fPartition ^= 1;
11424             break;
11425         case 'r':
11426             pPars->fReorder ^= 1;
11427             break;
11428         case 'o':
11429             pPars->fReorderImage ^= 1;
11430             break;
11431         case 'y':
11432             pPars->fSkipOutCheck ^= 1;
11433             break;
11434         case 'v':
11435             pPars->fVerbose ^= 1;
11436             break;
11437         case 'h':
11438             goto usage;
11439         default:
11440             goto usage;
11441         }
11442     }
11443     if ( pNtk == NULL )
11444     {
11445         Abc_Print( -1, "Empty network.\n" );
11446         return 1;
11447     }
11448     if ( Abc_NtkLatchNum(pNtk) == 0 )
11449     {
11450         Abc_Print( -1, "The current network has no latches.\n" );
11451         return 0;
11452     }
11453     if ( !Abc_NtkIsStrash(pNtk) )
11454     {
11455         Abc_Print( -1, "Reachability analysis works only for AIGs (run \"strash\").\n" );
11456         return 1;
11457     }
11458     if ( pAbc->fBatchMode && (pAbc->Status == 0 || pAbc->Status == 1) )
11459     {
11460         Abc_Print( 1, "The miters is already solved; skipping the command.\n" );
11461         return 0;
11462     }
11463     pAbc->Status  = Abc_NtkDarReach( pNtk, pPars );
11464     pAbc->nFrames = pPars->iFrame;
11465     Abc_FrameReplaceCex( pAbc, &pNtk->pSeqModel );
11466     if ( pLogFileName )
11467         Abc_NtkWriteLogFile( pLogFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, "reach" );
11468     return 0;
11469 
11470 usage:
11471     Abc_Print( -2, "usage: reach [-TBF num] [-L file] [-proyvh]\n" );
11472     Abc_Print( -2, "\t         verifies sequential miter using BDD-based reachability\n" );
11473     Abc_Print( -2, "\t-T num : approximate time limit in seconds (0=infinite) [default = %d]\n", pPars->TimeLimit );
11474     Abc_Print( -2, "\t-B num : max number of nodes in the intermediate BDDs [default = %d]\n", pPars->nBddMax );
11475     Abc_Print( -2, "\t-F num : max number of reachability iterations [default = %d]\n", pPars->nIterMax );
11476     Abc_Print( -2, "\t-L file: the log file name [default = %s]\n", pLogFileName ? pLogFileName : "no logging" );
11477     Abc_Print( -2, "\t-p     : enable partitioned image computation [default = %s]\n", pPars->fPartition? "yes": "no" );
11478     Abc_Print( -2, "\t-r     : enable dynamic BDD variable reordering [default = %s]\n", pPars->fReorder? "yes": "no" );
11479     Abc_Print( -2, "\t-o     : toggles BDD variable reordering during image computation [default = %s]\n", pPars->fReorderImage? "yes": "no" );
11480     Abc_Print( -2, "\t-y     : skip checking property outputs [default = %s]\n", pPars->fSkipOutCheck? "yes": "no" );
11481     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
11482     Abc_Print( -2, "\t-h     : print the command usage\n");
11483     return 1;
11484 }
11485 
11486 /**Function*************************************************************
11487 
11488   Synopsis    []
11489 
11490   Description []
11491 
11492   SideEffects []
11493 
11494   SeeAlso     []
11495 
11496 ***********************************************************************/
Abc_CommandCone(Abc_Frame_t * pAbc,int argc,char ** argv)11497 int Abc_CommandCone( Abc_Frame_t * pAbc, int argc, char ** argv )
11498 {
11499     Abc_Ntk_t * pNtk, * pNtkRes;
11500     Abc_Obj_t * pNode, * pNodeCo;
11501     int c;
11502     int fUseAllCis;
11503     int fUseMffc;
11504     int fSeq;
11505     int Output;
11506     int nRange;
11507 
11508     extern Abc_Ntk_t * Abc_NtkMakeOnePo( Abc_Ntk_t * pNtk, int Output, int nRange );
11509 
11510     pNtk = Abc_FrameReadNtk(pAbc);
11511     // set defaults
11512     fUseAllCis = 0;
11513     fUseMffc = 0;
11514     fSeq = 0;
11515     Output = -1;
11516     nRange = -1;
11517     Extra_UtilGetoptReset();
11518     while ( ( c = Extra_UtilGetopt( argc, argv, "ORmash" ) ) != EOF )
11519     {
11520         switch ( c )
11521         {
11522         case 'O':
11523             if ( globalUtilOptind >= argc )
11524             {
11525                 Abc_Print( -1, "Command line switch \"-O\" should be followed by an integer.\n" );
11526                 goto usage;
11527             }
11528             Output = atoi(argv[globalUtilOptind]);
11529             globalUtilOptind++;
11530             if ( Output < 0 )
11531                 goto usage;
11532             break;
11533         case 'R':
11534             if ( globalUtilOptind >= argc )
11535             {
11536                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
11537                 goto usage;
11538             }
11539             nRange = atoi(argv[globalUtilOptind]);
11540             globalUtilOptind++;
11541             if ( nRange < 0 )
11542                 goto usage;
11543             break;
11544         case 'm':
11545             fUseMffc ^= 1;
11546             break;
11547         case 'a':
11548             fUseAllCis ^= 1;
11549             break;
11550         case 's':
11551             fSeq ^= 1;
11552             break;
11553         case 'h':
11554             goto usage;
11555         default:
11556             goto usage;
11557         }
11558     }
11559 
11560     if ( pNtk == NULL )
11561     {
11562         Abc_Print( -1, "Empty network.\n" );
11563         return 1;
11564     }
11565 
11566     if ( !Abc_NtkIsLogic(pNtk) && !Abc_NtkIsStrash(pNtk) )
11567     {
11568         Abc_Print( -1, "Currently can only be applied to the logic network or an AIG.\n" );
11569         return 1;
11570     }
11571 
11572     if ( argc > globalUtilOptind + 1 )
11573     {
11574         Abc_Print( -1, "Wrong number of auguments.\n" );
11575         goto usage;
11576     }
11577 
11578     pNodeCo = NULL;
11579     if ( argc == globalUtilOptind + 1 )
11580     {
11581         pNode = Abc_NtkFindNode( pNtk, argv[globalUtilOptind] );
11582         if ( pNode == NULL )
11583         {
11584             Abc_Print( -1, "Cannot find node \"%s\".\n", argv[globalUtilOptind] );
11585             return 1;
11586         }
11587         if ( fUseMffc )
11588             pNtkRes = Abc_NtkCreateMffc( pNtk, pNode, argv[globalUtilOptind] );
11589         else
11590             pNtkRes = Abc_NtkCreateCone( pNtk, pNode, argv[globalUtilOptind], fUseAllCis );
11591     }
11592     else
11593     {
11594         if ( Output == -1 )
11595         {
11596             Abc_Print( -1, "The node is not specified.\n" );
11597             return 1;
11598         }
11599         if ( Output >= Abc_NtkCoNum(pNtk) )
11600         {
11601             Abc_Print( -1, "The 0-based output number (%d) is larger than the number of outputs (%d).\n", Output, Abc_NtkCoNum(pNtk) );
11602             return 1;
11603         }
11604         pNodeCo = Abc_NtkCo( pNtk, Output );
11605         if ( fSeq )
11606             pNtkRes = Abc_NtkMakeOnePo( pNtk, Output, nRange );
11607         else if ( fUseMffc )
11608             pNtkRes = Abc_NtkCreateMffc( pNtk, Abc_ObjFanin0(pNodeCo), Abc_ObjName(pNodeCo) );
11609         else
11610             pNtkRes = Abc_NtkCreateCone( pNtk, Abc_ObjFanin0(pNodeCo), Abc_ObjName(pNodeCo), fUseAllCis );
11611     }
11612     if ( pNodeCo && Abc_ObjFaninC0(pNodeCo) && !fSeq )
11613     {
11614         Abc_NtkPo(pNtkRes, 0)->fCompl0  ^= 1;
11615 //        Abc_Print( -1, "The extracted cone represents the complement function of the CO.\n" );
11616     }
11617     if ( pNtkRes == NULL )
11618     {
11619         Abc_Print( -1, "Writing the logic cone of one node has failed.\n" );
11620         return 1;
11621     }
11622     // replace the current network
11623     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
11624     return 0;
11625 
11626 usage:
11627     Abc_Print( -2, "usage: cone [-OR num] [-amsh] <name>\n" );
11628     Abc_Print( -2, "\t         replaces the current network by one logic cone\n" );
11629     Abc_Print( -2, "\t-a     : toggle keeping all CIs or structral support only [default = %s]\n", fUseAllCis? "all": "structural" );
11630     Abc_Print( -2, "\t-m     : toggle keeping only MFFC or complete TFI cone [default = %s]\n", fUseMffc? "MFFC": "TFI cone" );
11631     Abc_Print( -2, "\t-s     : toggle comb or sequential cone (works with \"-O num\") [default = %s]\n", fSeq? "seq": "comb" );
11632     Abc_Print( -2, "\t-h     : print the command usage\n");
11633     Abc_Print( -2, "\t-O num : (optional) the 0-based number of the CO to extract\n");
11634     Abc_Print( -2, "\t-R num : (optional) the number of outputs to extract\n");
11635     Abc_Print( -2, "\tname   : (optional) the name of the node to extract\n");
11636     return 1;
11637 }
11638 
11639 /**Function*************************************************************
11640 
11641   Synopsis    []
11642 
11643   Description []
11644 
11645   SideEffects []
11646 
11647   SeeAlso     []
11648 
11649 ***********************************************************************/
Abc_CommandNode(Abc_Frame_t * pAbc,int argc,char ** argv)11650 int Abc_CommandNode( Abc_Frame_t * pAbc, int argc, char ** argv )
11651 {
11652     Abc_Ntk_t * pNtk, * pNtkRes;
11653     Abc_Obj_t * pNode;
11654     int c;
11655 
11656     pNtk = Abc_FrameReadNtk(pAbc);
11657     // set defaults
11658     Extra_UtilGetoptReset();
11659     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
11660     {
11661         switch ( c )
11662         {
11663        case 'h':
11664             goto usage;
11665         default:
11666             goto usage;
11667         }
11668     }
11669 
11670     if ( pNtk == NULL )
11671     {
11672         Abc_Print( -1, "Empty network.\n" );
11673         return 1;
11674     }
11675 
11676     if ( !Abc_NtkIsLogic(pNtk) )
11677     {
11678         Abc_Print( -1, "Currently can only be applied to a logic network.\n" );
11679         return 1;
11680     }
11681 
11682     if ( argc != globalUtilOptind + 1 )
11683     {
11684         Abc_Print( -1, "Wrong number of auguments.\n" );
11685         goto usage;
11686     }
11687 
11688     pNode = Abc_NtkFindNode( pNtk, argv[globalUtilOptind] );
11689     if ( pNode == NULL )
11690     {
11691         Abc_Print( -1, "Cannot find node \"%s\".\n", argv[globalUtilOptind] );
11692         return 1;
11693     }
11694 
11695     pNtkRes = Abc_NtkCreateFromNode( pNtk, pNode );
11696 //    pNtkRes = Abc_NtkDeriveFromBdd( pNtk->pManFunc, pNode->pData, NULL, NULL );
11697     if ( pNtkRes == NULL )
11698     {
11699         Abc_Print( -1, "Splitting one node has failed.\n" );
11700         return 1;
11701     }
11702     // replace the current network
11703     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
11704     return 0;
11705 
11706 usage:
11707     Abc_Print( -2, "usage: node [-h] <name>\n" );
11708     Abc_Print( -2, "\t         replaces the current network by the network composed of one node\n" );
11709     Abc_Print( -2, "\t-h     : print the command usage\n");
11710     Abc_Print( -2, "\tname   : the node name\n");
11711     return 1;
11712 }
11713 
11714 /**Function*************************************************************
11715 
11716   Synopsis    []
11717 
11718   Description []
11719 
11720   SideEffects []
11721 
11722   SeeAlso     []
11723 
11724 ***********************************************************************/
Abc_CommandCof(Abc_Frame_t * pAbc,int argc,char ** argv)11725 int Abc_CommandCof( Abc_Frame_t * pAbc, int argc, char ** argv )
11726 {
11727     Abc_Ntk_t * pNtk;
11728     Abc_Obj_t * pNode;
11729     int c, Const;
11730 
11731     pNtk = Abc_FrameReadNtk(pAbc);
11732     // set defaults
11733     Extra_UtilGetoptReset();
11734     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
11735     {
11736         switch ( c )
11737         {
11738        case 'h':
11739             goto usage;
11740         default:
11741             goto usage;
11742         }
11743     }
11744 
11745     if ( pNtk == NULL )
11746     {
11747         Abc_Print( -1, "Empty network.\n" );
11748         return 1;
11749     }
11750 
11751     if ( !Abc_NtkIsLogic(pNtk) )
11752     {
11753         Abc_Print( -1, "Currently can only be applied to a logic network.\n" );
11754         return 1;
11755     }
11756 
11757     if ( argc != globalUtilOptind + 2 )
11758     {
11759         Abc_Print( -1, "Wrong number of auguments.\n" );
11760         goto usage;
11761     }
11762     pNode = Abc_NtkFindCi( pNtk, argv[globalUtilOptind] );
11763     if ( pNode == NULL )
11764         pNode = Abc_NtkFindNode( pNtk, argv[globalUtilOptind] );
11765     if ( pNode == NULL )
11766     {
11767         Abc_Print( -1, "Cannot find node \"%s\".\n", argv[globalUtilOptind] );
11768         return 1;
11769     }
11770     Const = atoi( argv[globalUtilOptind+1] );
11771     if ( Const != 0 && Const != 1 )
11772     {
11773         Abc_Print( -1, "Constant should be 0 or 1.\n", argv[globalUtilOptind+1] );
11774         return 1;
11775     }
11776     Abc_ObjReplaceByConstant( pNode, Const );
11777     return 0;
11778 
11779 usage:
11780     Abc_Print( -2, "usage: cof [-h] <node> <const>\n" );
11781     Abc_Print( -2, "\t          replaces one node in a logic network by constant 0 or 1\n" );
11782     Abc_Print( -2, "\t-h      : print the command usage\n");
11783     Abc_Print( -2, "\t<node>  : the node to replace\n");
11784     Abc_Print( -2, "\t<const> : the constant to replace the node with\n");
11785     Abc_Print( -2, "\tname    : the node name\n");
11786     return 1;
11787 }
11788 
11789 
11790 /**Function*************************************************************
11791 
11792   Synopsis    []
11793 
11794   Description []
11795 
11796   SideEffects []
11797 
11798   SeeAlso     []
11799 
11800 ***********************************************************************/
Abc_CommandTopmost(Abc_Frame_t * pAbc,int argc,char ** argv)11801 int Abc_CommandTopmost( Abc_Frame_t * pAbc, int argc, char ** argv )
11802 {
11803     Abc_Ntk_t * pNtk, * pNtkRes;
11804     int c, nLevels;
11805     extern Abc_Ntk_t * Abc_NtkTopmost( Abc_Ntk_t * pNtk, int nLevels );
11806 
11807     pNtk = Abc_FrameReadNtk(pAbc);
11808     // set defaults
11809     nLevels = 10;
11810     Extra_UtilGetoptReset();
11811     while ( ( c = Extra_UtilGetopt( argc, argv, "Nh" ) ) != EOF )
11812     {
11813         switch ( c )
11814         {
11815         case 'N':
11816             if ( globalUtilOptind >= argc )
11817             {
11818                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
11819                 goto usage;
11820             }
11821             nLevels = atoi(argv[globalUtilOptind]);
11822             globalUtilOptind++;
11823             if ( nLevels < 0 )
11824                 goto usage;
11825             break;
11826         case 'h':
11827             goto usage;
11828         default:
11829             goto usage;
11830         }
11831     }
11832 
11833     if ( pNtk == NULL )
11834     {
11835         Abc_Print( -1, "Empty network.\n" );
11836         return 1;
11837     }
11838 
11839     if ( !Abc_NtkIsStrash(pNtk) )
11840     {
11841         Abc_Print( -1, "Currently only works for structurally hashed circuits.\n" );
11842         return 0;
11843     }
11844 
11845     if ( Abc_NtkLatchNum(pNtk) > 0 )
11846     {
11847         Abc_Print( -1, "Currently can only works for combinational circuits.\n" );
11848         return 0;
11849     }
11850     if ( Abc_NtkPoNum(pNtk) != 1 )
11851     {
11852         Abc_Print( -1, "Currently expects a single-output miter.\n" );
11853         return 0;
11854     }
11855 
11856     pNtkRes = Abc_NtkTopmost( pNtk, nLevels );
11857     if ( pNtkRes == NULL )
11858     {
11859         Abc_Print( -1, "The command has failed.\n" );
11860         return 1;
11861     }
11862     // replace the current network
11863     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
11864     return 0;
11865 
11866 usage:
11867     Abc_Print( -2, "usage: topmost [-N num] [-h]\n" );
11868     Abc_Print( -2, "\t         replaces the current network by several of its topmost levels\n" );
11869     Abc_Print( -2, "\t-N num : max number of levels [default = %d]\n", nLevels );
11870     Abc_Print( -2, "\t-h     : print the command usage\n");
11871     Abc_Print( -2, "\tname   : the node name\n");
11872     return 1;
11873 }
11874 
11875 /**Function*************************************************************
11876 
11877   Synopsis    []
11878 
11879   Description []
11880 
11881   SideEffects []
11882 
11883   SeeAlso     []
11884 
11885 ***********************************************************************/
Abc_CommandTopAnd(Abc_Frame_t * pAbc,int argc,char ** argv)11886 int Abc_CommandTopAnd( Abc_Frame_t * pAbc, int argc, char ** argv )
11887 {
11888     Abc_Ntk_t * pNtk, * pNtkRes;
11889     int c;
11890     extern Abc_Ntk_t * Abc_NtkTopAnd( Abc_Ntk_t * pNtk );
11891 
11892     pNtk = Abc_FrameReadNtk(pAbc);
11893     // set defaults
11894     Extra_UtilGetoptReset();
11895     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
11896     {
11897         switch ( c )
11898         {
11899         case 'h':
11900             goto usage;
11901         default:
11902             goto usage;
11903         }
11904     }
11905 
11906     if ( pNtk == NULL )
11907     {
11908         Abc_Print( -1, "Empty network.\n" );
11909         return 1;
11910     }
11911 
11912     if ( !Abc_NtkIsStrash(pNtk) )
11913     {
11914         Abc_Print( -1, "Currently only works for structurally hashed circuits.\n" );
11915         return 0;
11916     }
11917 
11918     if ( Abc_NtkLatchNum(pNtk) > 0 )
11919     {
11920         Abc_Print( -1, "Currently can only works for combinational circuits.\n" );
11921         return 0;
11922     }
11923     if ( Abc_NtkPoNum(pNtk) != 1 )
11924     {
11925         Abc_Print( -1, "Currently expects a single-output miter.\n" );
11926         return 0;
11927     }
11928     if ( Abc_ObjFaninC0(Abc_NtkPo(pNtk, 0)) )
11929     {
11930         Abc_Print( -1, "The PO driver is complemented. AND-decomposition is impossible.\n" );
11931         return 0;
11932     }
11933     if ( !Abc_ObjIsNode(Abc_ObjChild0(Abc_NtkPo(pNtk, 0))) )
11934     {
11935         Abc_Print( -1, "The PO driver is not a node. AND-decomposition is impossible.\n" );
11936         return 0;
11937     }
11938     pNtkRes = Abc_NtkTopAnd( pNtk );
11939     if ( pNtkRes == NULL )
11940     {
11941         Abc_Print( -1, "The command has failed.\n" );
11942         return 1;
11943     }
11944     // replace the current network
11945     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
11946     return 0;
11947 
11948 usage:
11949     Abc_Print( -2, "usage: topand [-h]\n" );
11950     Abc_Print( -2, "\t         performs AND-decomposition of single-output combinational miter\n" );
11951     Abc_Print( -2, "\t-h     : print the command usage\n");
11952     Abc_Print( -2, "\tname   : the node name\n");
11953     return 1;
11954 }
11955 
11956 /**Function*************************************************************
11957 
11958   Synopsis    []
11959 
11960   Description []
11961 
11962   SideEffects []
11963 
11964   SeeAlso     []
11965 
11966 ***********************************************************************/
Abc_CommandTrim(Abc_Frame_t * pAbc,int argc,char ** argv)11967 int Abc_CommandTrim( Abc_Frame_t * pAbc, int argc, char ** argv )
11968 {
11969     Abc_Ntk_t * pNtk, * pNtkRes;
11970     Gia_Man_t * pGia, * pNew;
11971     Aig_Man_t * pAig;
11972     int c;
11973     pNtk = Abc_FrameReadNtk(pAbc);
11974     Extra_UtilGetoptReset();
11975     while ( ( c = Extra_UtilGetopt( argc, argv, "Nh" ) ) != EOF )
11976     {
11977         switch ( c )
11978         {
11979         case 'h':
11980             goto usage;
11981         default:
11982             goto usage;
11983         }
11984     }
11985     if ( pNtk == NULL )
11986     {
11987         Abc_Print( -1, "Empty network.\n" );
11988         return 1;
11989     }
11990     if ( !Abc_NtkIsStrash(pNtk) )
11991     {
11992         Abc_Print( -1, "Trimming works only for AIGs (run \"strash\").\n" );
11993         return 1;
11994     }
11995     // convert to GIA
11996     pAig = Abc_NtkToDar( pNtk, 0, 1 );
11997     pGia = Gia_ManFromAigSimple( pAig );
11998     Aig_ManStop( pAig );
11999     // perform trimming
12000     pNew = Gia_ManDupTrimmed( pGia, 1, 1, 0, -1 );
12001     Gia_ManStop( pGia );
12002     // convert back
12003     pAig = Gia_ManToAigSimple( pNew );
12004     Gia_ManStop( pNew );
12005     pNtkRes = Abc_NtkFromAigPhase( pAig );
12006     Aig_ManStop( pAig );
12007     // duplicate the name and the spec
12008     ABC_FREE( pNtkRes->pName );
12009     ABC_FREE( pNtkRes->pSpec );
12010     pNtkRes->pName = Extra_UtilStrsav(pNtk->pName);
12011     pNtkRes->pSpec = Extra_UtilStrsav(pNtk->pSpec);
12012     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
12013     return 0;
12014 
12015 usage:
12016     Abc_Print( -2, "usage: trim [-h]\n" );
12017     Abc_Print( -2, "\t         removes POs fed by constants and PIs w/o fanout\n" );
12018     Abc_Print( -2, "\t-h     : print the command usage\n");
12019     return 1;
12020 }
12021 
12022 
12023 /**Function*************************************************************
12024 
12025   Synopsis    []
12026 
12027   Description []
12028 
12029   SideEffects []
12030 
12031   SeeAlso     []
12032 
12033 ***********************************************************************/
Abc_CommandShortNames(Abc_Frame_t * pAbc,int argc,char ** argv)12034 int Abc_CommandShortNames( Abc_Frame_t * pAbc, int argc, char ** argv )
12035 {
12036     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
12037     int c;
12038     // set defaults
12039     Extra_UtilGetoptReset();
12040     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
12041     {
12042         switch ( c )
12043         {
12044         case 'h':
12045             goto usage;
12046         default:
12047             goto usage;
12048         }
12049     }
12050 
12051     if ( pNtk == NULL )
12052     {
12053         Abc_Print( -1, "Empty network.\n" );
12054         return 1;
12055     }
12056     Abc_NtkShortNames( pNtk );
12057     return 0;
12058 
12059 usage:
12060     Abc_Print( -2, "usage: short_names [-h]\n" );
12061     Abc_Print( -2, "\t         replaces PI/PO/latch names by short char strings\n" );
12062     Abc_Print( -2, "\t-h     : print the command usage\n");
12063     return 1;
12064 }
12065 
12066 /**Function*************************************************************
12067 
12068   Synopsis    []
12069 
12070   Description []
12071 
12072   SideEffects []
12073 
12074   SeeAlso     []
12075 
12076 ***********************************************************************/
Abc_CommandMoveNames(Abc_Frame_t * pAbc,int argc,char ** argv)12077 int Abc_CommandMoveNames( Abc_Frame_t * pAbc, int argc, char ** argv )
12078 {
12079     extern void Abc_NtkMoveNames( Abc_Ntk_t * pNtk, Abc_Ntk_t * pOld );
12080     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
12081     Abc_Ntk_t * pNtk2;
12082     char * FileName;
12083     int c;
12084     // set defaults
12085     Extra_UtilGetoptReset();
12086     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
12087     {
12088         switch ( c )
12089         {
12090         case 'h':
12091             goto usage;
12092         default:
12093             goto usage;
12094         }
12095     }
12096 
12097     // get the second network
12098     if ( argc != globalUtilOptind + 1 )
12099     {
12100         Abc_Print( -1, "The network to take names from is not given.\n" );
12101         return 1;
12102     }
12103 
12104     // read the second network
12105     FileName = argv[globalUtilOptind];
12106     pNtk2 = Io_Read( FileName, Io_ReadFileType(FileName), 1, 0 );
12107     if ( pNtk2 == NULL )
12108         return 1;
12109 
12110     // compare inputs/outputs
12111     if ( Abc_NtkPiNum(pNtk) != Abc_NtkPiNum(pNtk2) )
12112     {
12113         Abc_NtkDelete( pNtk2 );
12114         Abc_Print( -1, "The PI count (%d) of the first network is not equal to PI count (%d) of the second network.\n", Abc_NtkPiNum(pNtk), Abc_NtkPiNum(pNtk2) );
12115         return 0;
12116     }
12117     // compare inputs/outputs
12118     if ( Abc_NtkPoNum(pNtk) != Abc_NtkPoNum(pNtk2) )
12119     {
12120         Abc_NtkDelete( pNtk2 );
12121         Abc_Print( -1, "The PO count (%d) of the first network is not equal to PO count (%d) of the second network.\n", Abc_NtkPoNum(pNtk), Abc_NtkPoNum(pNtk2) );
12122         return 0;
12123     }
12124     // compare inputs/outputs
12125     if ( Abc_NtkLatchNum(pNtk) != Abc_NtkLatchNum(pNtk2) )
12126     {
12127         Abc_NtkDelete( pNtk2 );
12128         Abc_Print( -1, "The flop count (%d) of the first network is not equal to flop count (%d) of the second network.\n", Abc_NtkLatchNum(pNtk), Abc_NtkLatchNum(pNtk2) );
12129         return 0;
12130     }
12131     Abc_NtkMoveNames( pNtk, pNtk2 );
12132     Abc_NtkDelete( pNtk2 );
12133     return 0;
12134 
12135 usage:
12136     Abc_Print( -2, "usage: move_names [-h] <file>\n" );
12137     Abc_Print( -2, "\t         moves PI/PO/latch names from the other network\n" );
12138     Abc_Print( -2, "\t-h     : print the command usage\n");
12139     Abc_Print( -2, "\t<file> : file with network that has required names\n");
12140     return 1;
12141 }
12142 
12143 /**Function*************************************************************
12144 
12145   Synopsis    []
12146 
12147   Description []
12148 
12149   SideEffects []
12150 
12151   SeeAlso     []
12152 
12153 ***********************************************************************/
Abc_CommandExdcFree(Abc_Frame_t * pAbc,int argc,char ** argv)12154 int Abc_CommandExdcFree( Abc_Frame_t * pAbc, int argc, char ** argv )
12155 {
12156     Abc_Ntk_t * pNtk, * pNtkRes;
12157     int c;
12158 
12159     pNtk = Abc_FrameReadNtk(pAbc);
12160     // set defaults
12161     Extra_UtilGetoptReset();
12162     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
12163     {
12164         switch ( c )
12165         {
12166         case 'h':
12167             goto usage;
12168         default:
12169             goto usage;
12170         }
12171     }
12172 
12173     if ( pNtk == NULL )
12174     {
12175         Abc_Print( -1, "Empty network.\n" );
12176         return 1;
12177     }
12178     if ( pNtk->pExdc == NULL )
12179     {
12180         Abc_Print( -1, "The network has no EXDC.\n" );
12181         return 1;
12182     }
12183 
12184     Abc_NtkDelete( pNtk->pExdc );
12185     pNtk->pExdc = NULL;
12186 
12187     // replace the current network
12188     pNtkRes = Abc_NtkDup( pNtk );
12189     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
12190     return 0;
12191 
12192 usage:
12193     Abc_Print( -2, "usage: exdc_free [-h]\n" );
12194     Abc_Print( -2, "\t         frees the EXDC network of the current network\n" );
12195     Abc_Print( -2, "\t-h     : print the command usage\n");
12196     return 1;
12197 }
12198 
12199 /**Function*************************************************************
12200 
12201   Synopsis    []
12202 
12203   Description []
12204 
12205   SideEffects []
12206 
12207   SeeAlso     []
12208 
12209 ***********************************************************************/
Abc_CommandExdcGet(Abc_Frame_t * pAbc,int argc,char ** argv)12210 int Abc_CommandExdcGet( Abc_Frame_t * pAbc, int argc, char ** argv )
12211 {
12212     Abc_Ntk_t * pNtk, * pNtkRes;
12213     int c;
12214 
12215     pNtk = Abc_FrameReadNtk(pAbc);
12216     // set defaults
12217     Extra_UtilGetoptReset();
12218     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
12219     {
12220         switch ( c )
12221         {
12222         case 'h':
12223             goto usage;
12224         default:
12225             goto usage;
12226         }
12227     }
12228 
12229     if ( pNtk == NULL )
12230     {
12231         Abc_Print( -1, "Empty network.\n" );
12232         return 1;
12233     }
12234     if ( pNtk->pExdc == NULL )
12235     {
12236         Abc_Print( -1, "The network has no EXDC.\n" );
12237         return 1;
12238     }
12239 
12240     // replace the current network
12241     pNtkRes = Abc_NtkDup( pNtk->pExdc );
12242     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
12243     return 0;
12244 
12245 usage:
12246     Abc_Print( -2, "usage: exdc_get [-h]\n" );
12247     Abc_Print( -2, "\t         replaces the current network by the EXDC of the current network\n" );
12248     Abc_Print( -2, "\t-h     : print the command usage\n");
12249     return 1;
12250 }
12251 
12252 /**Function*************************************************************
12253 
12254   Synopsis    []
12255 
12256   Description []
12257 
12258   SideEffects []
12259 
12260   SeeAlso     []
12261 
12262 ***********************************************************************/
Abc_CommandExdcSet(Abc_Frame_t * pAbc,int argc,char ** argv)12263 int Abc_CommandExdcSet( Abc_Frame_t * pAbc, int argc, char ** argv )
12264 {
12265     FILE * pFile;
12266     Abc_Ntk_t * pNtk, * pNtkNew, * pNtkRes;
12267     char * FileName;
12268     int c;
12269 
12270     pNtk = Abc_FrameReadNtk(pAbc);
12271     // set defaults
12272     Extra_UtilGetoptReset();
12273     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
12274     {
12275         switch ( c )
12276         {
12277         case 'h':
12278             goto usage;
12279         default:
12280             goto usage;
12281         }
12282     }
12283 
12284     if ( pNtk == NULL )
12285     {
12286         Abc_Print( -1, "Empty network.\n" );
12287         return 1;
12288     }
12289 
12290     if ( argc != globalUtilOptind + 1 )
12291     {
12292         goto usage;
12293     }
12294 
12295     // get the input file name
12296     FileName = argv[globalUtilOptind];
12297     if ( (pFile = fopen( FileName, "r" )) == NULL )
12298     {
12299         Abc_Print( -1, "Cannot open input file \"%s\". ", FileName );
12300         if ( (FileName = Extra_FileGetSimilarName( FileName, ".mv", ".blif", ".pla", ".eqn", ".bench" )) )
12301             Abc_Print( 1, "Did you mean \"%s\"?", FileName );
12302         Abc_Print( 1, "\n" );
12303         return 1;
12304     }
12305     fclose( pFile );
12306 
12307     // set the new network
12308     pNtkNew = Io_Read( FileName, Io_ReadFileType(FileName), 1, 0 );
12309     if ( pNtkNew == NULL )
12310     {
12311         Abc_Print( -1, "Reading network from file has failed.\n" );
12312         return 1;
12313     }
12314 
12315     // replace the EXDC
12316     if ( pNtk->pExdc )
12317     {
12318         Abc_NtkDelete( pNtk->pExdc );
12319         pNtk->pExdc = NULL;
12320     }
12321     pNtkRes = Abc_NtkDup( pNtk );
12322     pNtkRes->pExdc = pNtkNew;
12323 
12324     // replace the current network
12325     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
12326     return 0;
12327 
12328 usage:
12329     Abc_Print( -2, "usage: exdc_set [-h] <file>\n" );
12330     Abc_Print( -2, "\t         sets the network from file as EXDC for the current network\n" );
12331     Abc_Print( -2, "\t-h     : print the command usage\n");
12332     Abc_Print( -2, "\t<file> : file with the new EXDC network\n");
12333     return 1;
12334 }
12335 
12336 /**Function*************************************************************
12337 
12338   Synopsis    []
12339 
12340   Description []
12341 
12342   SideEffects []
12343 
12344   SeeAlso     []
12345 
12346 ***********************************************************************/
Abc_CommandCareSet(Abc_Frame_t * pAbc,int argc,char ** argv)12347 int Abc_CommandCareSet( Abc_Frame_t * pAbc, int argc, char ** argv )
12348 {
12349     FILE * pFile;
12350     Abc_Ntk_t * pNtk, * pNtkNew, * pNtkRes;
12351     char * FileName;
12352     int c;
12353 
12354     pNtk = Abc_FrameReadNtk(pAbc);
12355     // set defaults
12356     Extra_UtilGetoptReset();
12357     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
12358     {
12359         switch ( c )
12360         {
12361         case 'h':
12362             goto usage;
12363         default:
12364             goto usage;
12365         }
12366     }
12367 
12368     if ( pNtk == NULL )
12369     {
12370         Abc_Print( -1, "Empty network.\n" );
12371         return 1;
12372     }
12373 
12374     if ( argc != globalUtilOptind + 1 )
12375     {
12376         goto usage;
12377     }
12378 
12379     // get the input file name
12380     FileName = argv[globalUtilOptind];
12381     if ( (pFile = fopen( FileName, "r" )) == NULL )
12382     {
12383         Abc_Print( -1, "Cannot open input file \"%s\". ", FileName );
12384         if ( (FileName = Extra_FileGetSimilarName( FileName, ".mv", ".blif", ".pla", ".eqn", ".bench" )) )
12385             Abc_Print( 1, "Did you mean \"%s\"?", FileName );
12386         Abc_Print( 1, "\n" );
12387         return 1;
12388     }
12389     fclose( pFile );
12390 
12391     // set the new network
12392     pNtkNew = Io_Read( FileName, Io_ReadFileType(FileName), 1, 0 );
12393     if ( pNtkNew == NULL )
12394     {
12395         Abc_Print( -1, "Reading network from file has failed.\n" );
12396         return 1;
12397     }
12398 
12399     // replace the EXDC
12400     if ( pNtk->pExcare )
12401     {
12402         Abc_NtkDelete( (Abc_Ntk_t *)pNtk->pExcare );
12403         pNtk->pExcare = NULL;
12404     }
12405     pNtkRes = Abc_NtkDup( pNtk );
12406     pNtkRes->pExcare = pNtkNew;
12407 
12408     // replace the current network
12409     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
12410     return 0;
12411 
12412 usage:
12413     Abc_Print( -2, "usage: care_set [-h] <file>\n" );
12414     Abc_Print( -2, "\t         sets the network from file as a care for the current network\n" );
12415     Abc_Print( -2, "\t-h     : print the command usage\n");
12416     Abc_Print( -2, "\t<file> : file with the new care network\n");
12417     return 1;
12418 }
12419 
12420 /**Function*************************************************************
12421 
12422   Synopsis    []
12423 
12424   Description []
12425 
12426   SideEffects []
12427 
12428   SeeAlso     []
12429 
12430 ***********************************************************************/
Abc_CommandCut(Abc_Frame_t * pAbc,int argc,char ** argv)12431 int Abc_CommandCut( Abc_Frame_t * pAbc, int argc, char ** argv )
12432 {
12433     Cut_Params_t Params, * pParams = &Params;
12434     Cut_Man_t * pCutMan;
12435     Cut_Oracle_t * pCutOracle = NULL;
12436     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
12437     int c;
12438     int fOracle;
12439     extern Cut_Man_t * Abc_NtkCuts( Abc_Ntk_t * pNtk, Cut_Params_t * pParams );
12440     extern void Abc_NtkCutsOracle( Abc_Ntk_t * pNtk, Cut_Oracle_t * pCutOracle );
12441 
12442     // set defaults
12443     fOracle = 0;
12444     memset( pParams, 0, sizeof(Cut_Params_t) );
12445     pParams->nVarsMax    = 5;     // the max cut size ("k" of the k-feasible cuts)
12446     pParams->nKeepMax    = 1000;  // the max number of cuts kept at a node
12447     pParams->fTruth      = 1;     // compute truth tables
12448     pParams->fFilter     = 1;     // filter dominated cuts
12449     pParams->fDrop       = 0;     // drop cuts on the fly
12450     pParams->fDag        = 1;     // compute DAG cuts
12451     pParams->fTree       = 0;     // compute tree cuts
12452     pParams->fGlobal     = 0;     // compute global cuts
12453     pParams->fLocal      = 0;     // compute local cuts
12454     pParams->fFancy      = 0;     // compute something fancy
12455     pParams->fRecordAig  = 1;     // compute something fancy
12456     pParams->fMap        = 0;     // compute mapping delay
12457     pParams->fAdjust     = 0;     // removes useless fanouts
12458     pParams->fNpnSave    = 0;     // enables dumping truth tables
12459     pParams->fVerbose    = 0;     // the verbosiness flag
12460     Extra_UtilGetoptReset();
12461     while ( ( c = Extra_UtilGetopt( argc, argv, "KMtfdxyglzamjvosh" ) ) != EOF )
12462     {
12463         switch ( c )
12464         {
12465         case 'K':
12466             if ( globalUtilOptind >= argc )
12467             {
12468                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
12469                 goto usage;
12470             }
12471             pParams->nVarsMax = atoi(argv[globalUtilOptind]);
12472             globalUtilOptind++;
12473             if ( pParams->nVarsMax < 0 )
12474                 goto usage;
12475             break;
12476         case 'M':
12477             if ( globalUtilOptind >= argc )
12478             {
12479                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
12480                 goto usage;
12481             }
12482             pParams->nKeepMax = atoi(argv[globalUtilOptind]);
12483             globalUtilOptind++;
12484             if ( pParams->nKeepMax < 0 )
12485                 goto usage;
12486             break;
12487         case 't':
12488             pParams->fTruth ^= 1;
12489             break;
12490         case 'f':
12491             pParams->fFilter ^= 1;
12492             break;
12493         case 'd':
12494             pParams->fDrop ^= 1;
12495             break;
12496         case 'x':
12497             pParams->fDag ^= 1;
12498             break;
12499         case 'y':
12500             pParams->fTree ^= 1;
12501             break;
12502         case 'g':
12503             pParams->fGlobal ^= 1;
12504             break;
12505         case 'l':
12506             pParams->fLocal ^= 1;
12507             break;
12508         case 'z':
12509             pParams->fFancy ^= 1;
12510             break;
12511         case 'a':
12512             pParams->fRecordAig ^= 1;
12513             break;
12514         case 'm':
12515             pParams->fMap ^= 1;
12516             break;
12517         case 'j':
12518             pParams->fAdjust ^= 1;
12519             break;
12520         case 'v':
12521             pParams->fVerbose ^= 1;
12522             break;
12523         case 'o':
12524             fOracle ^= 1;
12525             break;
12526         case 's':
12527             pParams->fNpnSave ^= 1;
12528             break;
12529         case 'h':
12530             goto usage;
12531         default:
12532             goto usage;
12533         }
12534     }
12535 
12536     if ( pNtk == NULL )
12537     {
12538         Abc_Print( -1, "Empty network.\n" );
12539         return 1;
12540     }
12541     if ( !Abc_NtkIsStrash(pNtk) )
12542     {
12543         Abc_Print( -1, "Cut computation is available only for AIGs (run \"strash\").\n" );
12544         return 1;
12545     }
12546     if ( pParams->nVarsMax < CUT_SIZE_MIN || pParams->nVarsMax > CUT_SIZE_MAX )
12547     {
12548         Abc_Print( -1, "Can only compute the cuts for %d <= K <= %d.\n", CUT_SIZE_MIN, CUT_SIZE_MAX );
12549         return 1;
12550     }
12551     if ( pParams->fDag && pParams->fTree )
12552     {
12553         Abc_Print( -1, "Cannot compute both DAG cuts and tree cuts at the same time.\n" );
12554         return 1;
12555     }
12556 
12557     if ( pParams->fNpnSave )
12558     {
12559         pParams->nVarsMax = 6;
12560         pParams->fTruth = 1;
12561     }
12562 
12563     if ( fOracle )
12564         pParams->fRecord = 1;
12565     pCutMan = Abc_NtkCuts( pNtk, pParams );
12566     if ( fOracle )
12567         pCutOracle = Cut_OracleStart( pCutMan );
12568     Cut_ManStop( pCutMan );
12569     if ( fOracle )
12570     {
12571         assert(pCutOracle);
12572         Abc_NtkCutsOracle( pNtk, pCutOracle );
12573         Cut_OracleStop( pCutOracle );
12574     }
12575     return 0;
12576 
12577 usage:
12578     Abc_Print( -2, "usage: cut [-K num] [-M num] [-tfdcovamjsvh]\n" );
12579     Abc_Print( -2, "\t         computes k-feasible cuts for the AIG\n" );
12580     Abc_Print( -2, "\t-K num : max number of leaves (%d <= num <= %d) [default = %d]\n",     CUT_SIZE_MIN, CUT_SIZE_MAX, pParams->nVarsMax );
12581     Abc_Print( -2, "\t-M num : max number of cuts stored at a node [default = %d]\n",        pParams->nKeepMax );
12582     Abc_Print( -2, "\t-t     : toggle truth table computation [default = %s]\n",             pParams->fTruth?   "yes": "no" );
12583     Abc_Print( -2, "\t-f     : toggle filtering of duplicated/dominated [default = %s]\n",   pParams->fFilter?  "yes": "no" );
12584     Abc_Print( -2, "\t-d     : toggle dropping when fanouts are done [default = %s]\n",      pParams->fDrop?    "yes": "no" );
12585     Abc_Print( -2, "\t-x     : toggle computing only DAG cuts [default = %s]\n",             pParams->fDag?     "yes": "no" );
12586     Abc_Print( -2, "\t-y     : toggle computing only tree cuts [default = %s]\n",            pParams->fTree?    "yes": "no" );
12587     Abc_Print( -2, "\t-g     : toggle computing only global cuts [default = %s]\n",          pParams->fGlobal?  "yes": "no" );
12588     Abc_Print( -2, "\t-l     : toggle computing only local cuts [default = %s]\n",           pParams->fLocal?   "yes": "no" );
12589     Abc_Print( -2, "\t-z     : toggle fancy computations [default = %s]\n",                  pParams->fFancy?   "yes": "no" );
12590     Abc_Print( -2, "\t-a     : toggle recording cut functions [default = %s]\n",             pParams->fRecordAig?"yes": "no" );
12591     Abc_Print( -2, "\t-m     : toggle delay-oriented FPGA mapping [default = %s]\n",         pParams->fMap?     "yes": "no" );
12592     Abc_Print( -2, "\t-j     : toggle removing fanouts due to XOR/MUX [default = %s]\n",     pParams->fAdjust?  "yes": "no" );
12593     Abc_Print( -2, "\t-s     : toggle creating library of 6-var functions [default = %s]\n", pParams->fNpnSave?  "yes": "no" );
12594     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",        pParams->fVerbose? "yes": "no" );
12595     Abc_Print( -2, "\t-h     : print the command usage\n");
12596     return 1;
12597 }
12598 
12599 /**Function*************************************************************
12600 
12601   Synopsis    []
12602 
12603   Description []
12604 
12605   SideEffects []
12606 
12607   SeeAlso     []
12608 
12609 ***********************************************************************/
Abc_CommandScut(Abc_Frame_t * pAbc,int argc,char ** argv)12610 int Abc_CommandScut( Abc_Frame_t * pAbc, int argc, char ** argv )
12611 {
12612     Cut_Params_t Params, * pParams = &Params;
12613     Cut_Man_t * pCutMan;
12614     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
12615     int c;
12616     extern Cut_Man_t * Abc_NtkSeqCuts( Abc_Ntk_t * pNtk, Cut_Params_t * pParams );
12617 
12618     // set defaults
12619     memset( pParams, 0, sizeof(Cut_Params_t) );
12620     pParams->nVarsMax  = 5;     // the max cut size ("k" of the k-feasible cuts)
12621     pParams->nKeepMax  = 1000;  // the max number of cuts kept at a node
12622     pParams->fTruth    = 0;     // compute truth tables
12623     pParams->fFilter   = 1;     // filter dominated cuts
12624     pParams->fSeq      = 1;     // compute sequential cuts
12625     pParams->fVerbose  = 0;     // the verbosiness flag
12626     Extra_UtilGetoptReset();
12627     while ( ( c = Extra_UtilGetopt( argc, argv, "KMtvh" ) ) != EOF )
12628     {
12629         switch ( c )
12630         {
12631         case 'K':
12632             if ( globalUtilOptind >= argc )
12633             {
12634                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
12635                 goto usage;
12636             }
12637             pParams->nVarsMax = atoi(argv[globalUtilOptind]);
12638             globalUtilOptind++;
12639             if ( pParams->nVarsMax < 0 )
12640                 goto usage;
12641             break;
12642         case 'M':
12643             if ( globalUtilOptind >= argc )
12644             {
12645                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
12646                 goto usage;
12647             }
12648             pParams->nKeepMax = atoi(argv[globalUtilOptind]);
12649             globalUtilOptind++;
12650             if ( pParams->nKeepMax < 0 )
12651                 goto usage;
12652             break;
12653         case 't':
12654             pParams->fTruth ^= 1;
12655             break;
12656         case 'v':
12657             pParams->fVerbose ^= 1;
12658             break;
12659         case 'h':
12660             goto usage;
12661         default:
12662             goto usage;
12663         }
12664     }
12665 
12666     if ( pNtk == NULL )
12667     {
12668         Abc_Print( -1, "Empty network.\n" );
12669         return 1;
12670     }
12671 /*
12672     if ( !Abc_NtkIsSeq(pNtk) )
12673     {
12674         Abc_Print( -1, "Sequential cuts can be computed for sequential AIGs (run \"seq\").\n" );
12675         return 1;
12676     }
12677 */
12678     if ( pParams->nVarsMax < CUT_SIZE_MIN || pParams->nVarsMax > CUT_SIZE_MAX )
12679     {
12680         Abc_Print( -1, "Can only compute the cuts for %d <= K <= %d.\n", CUT_SIZE_MIN, CUT_SIZE_MAX );
12681         return 1;
12682     }
12683 
12684     pCutMan = Abc_NtkSeqCuts( pNtk, pParams );
12685     Cut_ManStop( pCutMan );
12686     return 0;
12687 
12688 usage:
12689     Abc_Print( -2, "usage: scut [-K num] [-M num] [-tvh]\n" );
12690     Abc_Print( -2, "\t         computes k-feasible cuts for the sequential AIG\n" );
12691     Abc_Print( -2, "\t-K num : max number of leaves (%d <= num <= %d) [default = %d]\n",   CUT_SIZE_MIN, CUT_SIZE_MAX, pParams->nVarsMax );
12692     Abc_Print( -2, "\t-M num : max number of cuts stored at a node [default = %d]\n",      pParams->nKeepMax );
12693     Abc_Print( -2, "\t-t     : toggle truth table computation [default = %s]\n",           pParams->fTruth?   "yes": "no" );
12694     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",      pParams->fVerbose? "yes": "no" );
12695     Abc_Print( -2, "\t-h     : print the command usage\n");
12696     return 1;
12697 }
12698 
12699 /**Function*************************************************************
12700 
12701   Synopsis    []
12702 
12703   Description []
12704 
12705   SideEffects []
12706 
12707   SeeAlso     []
12708 
12709 ***********************************************************************/
Abc_CommandEspresso(Abc_Frame_t * pAbc,int argc,char ** argv)12710 int Abc_CommandEspresso( Abc_Frame_t * pAbc, int argc, char ** argv )
12711 {
12712     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
12713     int c;
12714     int fVerbose;
12715     extern void Abc_NtkEspresso( Abc_Ntk_t * pNtk, int fVerbose );
12716 
12717     if ( argc == 2 && !strcmp(argv[1], "-h") )
12718     {
12719         Abc_Print( -2, "The espresso command is currently disabled.\n" );
12720         return 1;
12721     }
12722 
12723     Abc_Print( -1, "This command is currently disabled.\n" );
12724     return 0;
12725 
12726     // set defaults
12727     fVerbose = 0;
12728     Extra_UtilGetoptReset();
12729     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
12730     {
12731         switch ( c )
12732         {
12733         case 'v':
12734             fVerbose ^= 1;
12735             break;
12736         case 'h':
12737             goto usage;
12738         default:
12739             goto usage;
12740         }
12741     }
12742     if ( pNtk == NULL )
12743     {
12744         Abc_Print( -1, "Empty network.\n" );
12745         return 1;
12746     }
12747     if ( !Abc_NtkIsLogic(pNtk) )
12748     {
12749         Abc_Print( -1, "SOP minimization is possible for logic networks (run \"renode\").\n" );
12750         return 1;
12751     }
12752 //    Abc_NtkEspresso( pNtk, fVerbose );
12753     return 0;
12754 
12755 usage:
12756     Abc_Print( -2, "usage: espresso [-vh]\n" );
12757     Abc_Print( -2, "\t         minimizes SOPs of the local functions using Espresso\n" );
12758     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
12759     Abc_Print( -2, "\t-h     : print the command usage\n");
12760     return 1;
12761 }
12762 
12763 /**Function*************************************************************
12764 
12765   Synopsis    []
12766 
12767   Description []
12768 
12769   SideEffects []
12770 
12771   SeeAlso     []
12772 
12773 ***********************************************************************/
Abc_CommandGen(Abc_Frame_t * pAbc,int argc,char ** argv)12774 int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv )
12775 {
12776 //    Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
12777     int c;
12778     int nVars;    // the number of variables
12779     int nArgs;    // the number of arguments
12780     int nLutSize = -1; // the size of LUTs
12781     int nLuts = -1;    // the number of LUTs
12782     int fAdder;
12783     int fAdderTree;
12784     int fSorter;
12785     int fMesh;
12786     int fMulti;
12787     int fBooth;
12788     int fFpga;
12789     int fOneHot;
12790     int fRandom;
12791     int fVerbose;
12792     char * FileName;
12793     char Command[1000];
12794     extern void Abc_GenAdder( char * pFileName, int nVars );
12795     extern void Abc_GenSorter( char * pFileName, int nVars );
12796     extern void Abc_GenMesh( char * pFileName, int nVars );
12797     extern void Abc_GenMulti( char * pFileName, int nVars );
12798     extern void Abc_GenBooth( char * pFileName, int nVars );
12799     extern void Abc_GenFpga( char * pFileName, int nLutSize, int nLuts, int nVars );
12800     extern void Abc_GenOneHot( char * pFileName, int nVars );
12801     extern void Abc_GenRandom( char * pFileName, int nPis );
12802     extern void Abc_GenAdderTree( char * pFileName, int nArgs, int nBits );
12803 
12804     // set defaults
12805     nVars = 8;
12806     nArgs = 8;
12807     fAdder = 0;
12808     fAdderTree = 0;
12809     fSorter = 0;
12810     fMesh = 0;
12811     fMulti = 0;
12812     fBooth = 0;
12813     fFpga = 0;
12814     fOneHot = 0;
12815     fRandom = 0;
12816     fVerbose = 0;
12817     Extra_UtilGetoptReset();
12818     while ( ( c = Extra_UtilGetopt( argc, argv, "NAKLatsembfnrvh" ) ) != EOF )
12819     {
12820         switch ( c )
12821         {
12822         case 'N':
12823             if ( globalUtilOptind >= argc )
12824             {
12825                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
12826                 goto usage;
12827             }
12828             nVars = atoi(argv[globalUtilOptind]);
12829             globalUtilOptind++;
12830             if ( nVars < 0 )
12831                 goto usage;
12832             break;
12833         case 'A':
12834             if ( globalUtilOptind >= argc )
12835             {
12836                 Abc_Print( -1, "Command line switch \"-A\" should be followed by an integer.\n" );
12837                 goto usage;
12838             }
12839             nArgs = atoi(argv[globalUtilOptind]);
12840             globalUtilOptind++;
12841             if ( nArgs < 0 )
12842                 goto usage;
12843             break;
12844         case 'K':
12845             if ( globalUtilOptind >= argc )
12846             {
12847                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
12848                 goto usage;
12849             }
12850             nLutSize = atoi(argv[globalUtilOptind]);
12851             globalUtilOptind++;
12852             if ( nLutSize < 0 )
12853                 goto usage;
12854             break;
12855         case 'L':
12856             if ( globalUtilOptind >= argc )
12857             {
12858                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
12859                 goto usage;
12860             }
12861             nLuts = atoi(argv[globalUtilOptind]);
12862             globalUtilOptind++;
12863             if ( nLuts < 0 )
12864                 goto usage;
12865             break;
12866         case 'a':
12867             fAdder ^= 1;
12868             break;
12869         case 't':
12870             fAdderTree ^= 1;
12871             break;
12872         case 's':
12873             fSorter ^= 1;
12874             break;
12875         case 'e':
12876             fMesh ^= 1;
12877             break;
12878         case 'm':
12879             fMulti ^= 1;
12880             break;
12881         case 'b':
12882             fBooth ^= 1;
12883             break;
12884         case 'f':
12885             fFpga ^= 1;
12886             break;
12887         case 'n':
12888             fOneHot ^= 1;
12889             break;
12890         case 'r':
12891             fRandom ^= 1;
12892             break;
12893         case 'v':
12894             fVerbose ^= 1;
12895             break;
12896         case 'h':
12897             goto usage;
12898         default:
12899             goto usage;
12900         }
12901     }
12902 
12903     if ( argc != globalUtilOptind + 1 )
12904     {
12905         goto usage;
12906     }
12907     if ( nVars < 1 )
12908     {
12909         Abc_Print( -1, "The number of variables should be a positive integer.\n" );
12910         return 0;
12911     }
12912     // get the input file name
12913     FileName = argv[globalUtilOptind];
12914     if ( fAdder )
12915         Abc_GenAdder( FileName, nVars );
12916     else if ( fSorter )
12917         Abc_GenSorter( FileName, nVars );
12918     else if ( fMesh )
12919         Abc_GenMesh( FileName, nVars );
12920     else if ( fMulti )
12921         Abc_GenMulti( FileName, nVars );
12922     else if ( fBooth )
12923         Abc_GenBooth( FileName, nVars );
12924     else if ( fFpga )
12925         Abc_GenFpga( FileName, nLutSize, nLuts, nVars );
12926 //        Abc_GenFpga( FileName, 2, 2, 3 );
12927 //        Abc_GenFpga( FileName, 3, 2, 5 );
12928     else if ( fOneHot )
12929         Abc_GenOneHot( FileName, nVars );
12930     else if ( fRandom )
12931         Abc_GenRandom( FileName, nVars );
12932     else if ( fAdderTree )
12933     {
12934         printf( "Generating adder tree with %d arguments and %d bits.\n", nArgs, nVars );
12935         Abc_GenAdderTree( FileName, nArgs, nVars );
12936         sprintf( Command, "%%read %s; %%blast; &put", FileName );
12937         Cmd_CommandExecute( pAbc, Command );
12938         return 0;
12939     }
12940     else
12941     {
12942         Abc_Print( -1, "Type of circuit is not specified.\n" );
12943         return 0;
12944     }
12945     // read the file just produced
12946     sprintf(Command, "read %s", FileName );
12947     Cmd_CommandExecute( pAbc, Command );
12948     return 0;
12949 
12950 usage:
12951     Abc_Print( -2, "usage: gen [-NAKL num] [-atsembfnrvh] <file>\n" );
12952     Abc_Print( -2, "\t         generates simple circuits\n" );
12953     Abc_Print( -2, "\t-N num : the number of variables [default = %d]\n", nVars );
12954     Abc_Print( -2, "\t-A num : the number of agruments (for adder tree) [default = %d]\n", nArgs );
12955     Abc_Print( -2, "\t-K num : the LUT size (to be used with switch -f) [default = %d]\n", nLutSize );
12956     Abc_Print( -2, "\t-L num : the LUT count (to be used with switch -f) [default = %d]\n", nLuts );
12957     Abc_Print( -2, "\t-a     : generate ripple-carry adder [default = %s]\n", fAdder? "yes": "no" );
12958     Abc_Print( -2, "\t-t     : generate an adder tree [default = %s]\n", fAdderTree? "yes": "no" );
12959     Abc_Print( -2, "\t-s     : generate a sorter [default = %s]\n", fSorter? "yes": "no" );
12960     Abc_Print( -2, "\t-e     : generate a mesh [default = %s]\n", fMesh? "yes": "no" );
12961     Abc_Print( -2, "\t-m     : generate a multiplier [default = %s]\n", fMulti? "yes": "no" );
12962     Abc_Print( -2, "\t-b     : generate a signed Booth multiplier [default = %s]\n", fBooth? "yes": "no" );
12963     Abc_Print( -2, "\t-f     : generate a LUT FPGA structure [default = %s]\n", fFpga? "yes": "no" );
12964     Abc_Print( -2, "\t-n     : generate one-hotness conditions [default = %s]\n", fOneHot? "yes": "no" );
12965     Abc_Print( -2, "\t-r     : generate random single-output function [default = %s]\n", fRandom? "yes": "no" );
12966     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
12967     Abc_Print( -2, "\t-h     : print the command usage\n");
12968     Abc_Print( -2, "\t<file> : output file name\n");
12969     return 1;
12970 }
12971 
12972 /**Function*************************************************************
12973 
12974   Synopsis    []
12975 
12976   Description []
12977 
12978   SideEffects []
12979 
12980   SeeAlso     []
12981 
12982 ***********************************************************************/
Abc_CommandGenFsm(Abc_Frame_t * pAbc,int argc,char ** argv)12983 int Abc_CommandGenFsm( Abc_Frame_t * pAbc, int argc, char ** argv )
12984 {
12985     extern void Abc_GenFsm( char * pFileName, int nIns, int nOuts, int nStates, int nLines, int ProbI, int ProbO );
12986     int c, nIns, nOuts, nStates, nLines, ProbI, ProbO, fVerbose;
12987     char * FileName;
12988     // set defaults
12989     nIns     =   30;
12990     nOuts    =    1;
12991     nStates  =   20;
12992     nLines   =  100;
12993     ProbI    =   10;
12994     ProbO    =  100;
12995     fVerbose =    0;
12996     Extra_UtilGetoptReset();
12997     while ( ( c = Extra_UtilGetopt( argc, argv, "IOSLPQvh" ) ) != EOF )
12998     {
12999         switch ( c )
13000         {
13001         case 'I':
13002             if ( globalUtilOptind >= argc )
13003             {
13004                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
13005                 goto usage;
13006             }
13007             nIns = atoi(argv[globalUtilOptind]);
13008             globalUtilOptind++;
13009             if ( nIns < 0 )
13010                 goto usage;
13011             break;
13012         case 'O':
13013             if ( globalUtilOptind >= argc )
13014             {
13015                 Abc_Print( -1, "Command line switch \"-O\" should be followed by an integer.\n" );
13016                 goto usage;
13017             }
13018             nOuts = atoi(argv[globalUtilOptind]);
13019             globalUtilOptind++;
13020             if ( nOuts < 0 )
13021                 goto usage;
13022             break;
13023         case 'S':
13024             if ( globalUtilOptind >= argc )
13025             {
13026                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
13027                 goto usage;
13028             }
13029             nStates = atoi(argv[globalUtilOptind]);
13030             globalUtilOptind++;
13031             if ( nStates < 0 )
13032                 goto usage;
13033             break;
13034         case 'L':
13035             if ( globalUtilOptind >= argc )
13036             {
13037                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
13038                 goto usage;
13039             }
13040             nLines = atoi(argv[globalUtilOptind]);
13041             globalUtilOptind++;
13042             if ( nLines < 0 )
13043                 goto usage;
13044             break;
13045         case 'P':
13046             if ( globalUtilOptind >= argc )
13047             {
13048                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
13049                 goto usage;
13050             }
13051             ProbI = atoi(argv[globalUtilOptind]);
13052             globalUtilOptind++;
13053             if ( ProbI < 0 )
13054                 goto usage;
13055             break;
13056         case 'Q':
13057             if ( globalUtilOptind >= argc )
13058             {
13059                 Abc_Print( -1, "Command line switch \"-Q\" should be followed by an integer.\n" );
13060                 goto usage;
13061             }
13062             ProbO = atoi(argv[globalUtilOptind]);
13063             globalUtilOptind++;
13064             if ( ProbO < 0 )
13065                 goto usage;
13066             break;
13067         case 'v':
13068             fVerbose ^= 1;
13069             break;
13070         case 'h':
13071             goto usage;
13072         default:
13073             goto usage;
13074         }
13075     }
13076 
13077     if ( argc != globalUtilOptind + 1 )
13078     {
13079         goto usage;
13080     }
13081     if ( nIns < 1 || nStates < 1 || nLines < 1 || ProbI < 1 || ProbO < 1 )
13082     {
13083         Abc_Print( -1, "The number of inputs. states, lines, and probablity should be positive integers.\n" );
13084         goto usage;
13085     }
13086     // get the input file name
13087     FileName = argv[globalUtilOptind];
13088     Abc_GenFsm( FileName, nIns, nOuts, nStates, nLines, ProbI, ProbO );
13089     return 0;
13090 
13091 usage:
13092     Abc_Print( -2, "usage: genfsm [-IOSLPQ num] [-vh] <file>\n" );
13093     Abc_Print( -2, "\t         generates random FSM in KISS format\n" );
13094     Abc_Print( -2, "\t-I num : the number of input variables [default = %d]\n", nIns );
13095     Abc_Print( -2, "\t-O num : the number of output variables [default = %d]\n", nOuts );
13096     Abc_Print( -2, "\t-S num : the number of state variables [default = %d]\n", nStates );
13097     Abc_Print( -2, "\t-L num : the number of lines (product terms) [default = %d]\n", nLines );
13098     Abc_Print( -2, "\t-P num : percentage propability of a variable present in the input cube [default = %d]\n", ProbI );
13099     Abc_Print( -2, "\t-Q num : percentage propability of a variable present in the output cube [default = %d]\n", ProbO );
13100     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
13101     Abc_Print( -2, "\t-h     : print the command usage\n");
13102     Abc_Print( -2, "\t<file> : output file name\n");
13103     return 1;
13104 }
13105 
13106 /**Function*************************************************************
13107 
13108   Synopsis    []
13109 
13110   Description []
13111 
13112   SideEffects []
13113 
13114   SeeAlso     []
13115 
13116 ***********************************************************************/
Abc_CommandCover(Abc_Frame_t * pAbc,int argc,char ** argv)13117 int Abc_CommandCover( Abc_Frame_t * pAbc, int argc, char ** argv )
13118 {
13119     Abc_Ntk_t * pNtk, * pNtkRes;
13120     int c;
13121     int fVerbose;
13122     int fUseSop;
13123     int fUseEsop;
13124     int fUseInvs;
13125     int nFaninMax;
13126     int nCubesMax;
13127     pNtk = Abc_FrameReadNtk(pAbc);
13128 
13129     // set defaults
13130     fUseSop   =  1;
13131     fUseEsop  =  0;
13132     fVerbose  =  0;
13133     fUseInvs  =  1;
13134     nFaninMax =  8;
13135     nCubesMax =  8;
13136     Extra_UtilGetoptReset();
13137     while ( ( c = Extra_UtilGetopt( argc, argv, "IPsxivh" ) ) != EOF )
13138     {
13139         switch ( c )
13140         {
13141         case 'I':
13142             if ( globalUtilOptind >= argc )
13143             {
13144                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
13145                 goto usage;
13146             }
13147             nFaninMax = atoi(argv[globalUtilOptind]);
13148             globalUtilOptind++;
13149             if ( nFaninMax < 0 )
13150                 goto usage;
13151             break;
13152         case 'P':
13153             if ( globalUtilOptind >= argc )
13154             {
13155                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
13156                 goto usage;
13157             }
13158             nCubesMax = atoi(argv[globalUtilOptind]);
13159             globalUtilOptind++;
13160             if ( nCubesMax < 0 )
13161                 goto usage;
13162             break;
13163         case 's':
13164             fUseSop ^= 1;
13165             break;
13166         case 'x':
13167             fUseEsop ^= 1;
13168             break;
13169         case 'i':
13170             fUseInvs ^= 1;
13171             break;
13172         case 'v':
13173             fVerbose ^= 1;
13174             break;
13175         case 'h':
13176             goto usage;
13177         default:
13178             goto usage;
13179         }
13180     }
13181     if ( pNtk == NULL )
13182     {
13183         Abc_Print( -1, "Empty network.\n" );
13184         return 1;
13185     }
13186 
13187     if ( !Abc_NtkIsStrash(pNtk) )
13188     {
13189         Abc_Print( -1, "Only works for strashed networks.\n" );
13190         return 1;
13191     }
13192 
13193     // run the command
13194     pNtkRes = Abc_NtkSopEsopCover( pNtk, nFaninMax, nCubesMax, fUseEsop, fUseSop, fUseInvs, fVerbose );
13195     if ( pNtkRes == NULL )
13196     {
13197         Abc_Print( -1, "Command has failed.\n" );
13198         return 0;
13199     }
13200     // replace the current network
13201     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
13202     return 0;
13203 
13204 usage:
13205     Abc_Print( -2, "usage: cover [-IP num] [-sxvh]\n" );
13206     Abc_Print( -2, "\t         decomposition into a network of SOP/ESOP PLAs\n" );
13207     Abc_Print( -2, "\t         (this command is known to have bugs)\n");
13208     Abc_Print( -2, "\t-I num : maximum number of inputs [default = %d]\n", nFaninMax );
13209     Abc_Print( -2, "\t-P num : maximum number of products [default = %d]\n", nCubesMax );
13210     Abc_Print( -2, "\t-s     : toggle the use of SOPs [default = %s]\n", fUseSop? "yes": "no" );
13211     Abc_Print( -2, "\t-x     : toggle the use of ESOPs [default = %s]\n", fUseEsop? "yes": "no" );
13212 //    Abc_Print( -2, "\t-i     : toggle the use of interters [default = %s]\n", fUseInvs? "yes": "no" );
13213     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
13214     Abc_Print( -2, "\t-h     : print the command usage\n");
13215     return 1;
13216 }
13217 
13218 /**Function*************************************************************
13219 
13220   Synopsis    []
13221 
13222   Description []
13223 
13224   SideEffects []
13225 
13226   SeeAlso     []
13227 
13228 ***********************************************************************/
Abc_CommandInter(Abc_Frame_t * pAbc,int argc,char ** argv)13229 int Abc_CommandInter( Abc_Frame_t * pAbc, int argc, char ** argv )
13230 {
13231     Abc_Ntk_t * pNtk, * pNtk1, * pNtk2, * pNtkRes = NULL;
13232     char ** pArgvNew;
13233     int nArgcNew;
13234     int c, fDelete1, fDelete2;
13235     int fRelation;
13236     int fVerbose;
13237     extern Abc_Ntk_t * Abc_NtkInter( Abc_Ntk_t * pNtkOn, Abc_Ntk_t * pNtkOff, int fRelation, int fVerbose );
13238 
13239     pNtk = Abc_FrameReadNtk(pAbc);
13240     // set defaults
13241     fRelation = 0;
13242     fVerbose  = 0;
13243     Extra_UtilGetoptReset();
13244     while ( ( c = Extra_UtilGetopt( argc, argv, "rvh" ) ) != EOF )
13245     {
13246         switch ( c )
13247         {
13248         case 'r':
13249             fRelation ^= 1;
13250             break;
13251         case 'v':
13252             fVerbose ^= 1;
13253             break;
13254         case 'h':
13255             goto usage;
13256         default:
13257             goto usage;
13258         }
13259     }
13260 
13261     pArgvNew = argv + globalUtilOptind;
13262     nArgcNew = argc - globalUtilOptind;
13263     if ( !Abc_NtkPrepareTwoNtks( stdout, pNtk, pArgvNew, nArgcNew, &pNtk1, &pNtk2, &fDelete1, &fDelete2, 1 ) )
13264         return 1;
13265     if ( nArgcNew == 0 )
13266     {
13267         Abc_Obj_t * pObj;
13268         int i;
13269         Abc_Print( -1, "Deriving new circuit structure for the current network.\n" );
13270         Abc_NtkForEachPo( pNtk2, pObj, i )
13271             Abc_ObjXorFaninC( pObj, 0 );
13272     }
13273     if ( fRelation && Abc_NtkCoNum(pNtk1) != 1 )
13274     {
13275         Abc_Print( -1, "Computation of interplants as a relation only works for single-output functions.\n" );
13276         Abc_Print( -1, "Use command \"cone\" to extract one output cone from the multi-output network.\n" );
13277     }
13278     else
13279         pNtkRes = Abc_NtkInter( pNtk1, pNtk2, fRelation, fVerbose );
13280     if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
13281     if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
13282 
13283     if ( pNtkRes == NULL )
13284     {
13285         Abc_Print( -1, "Command has failed.\n" );
13286         return 0;
13287     }
13288     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
13289     return 0;
13290 
13291 usage:
13292     Abc_Print( -2, "usage: inter [-rvh] <onset.blif> <offset.blif>\n" );
13293     Abc_Print( -2, "\t         derives interpolant of two networks representing onset and offset;\n" );
13294     Abc_Print( -2, "\t-r     : toggle computing interpolant as a relation [default = %s]\n", fRelation? "yes": "no" );
13295     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
13296     Abc_Print( -2, "\t-h     : print the command usage\n");
13297     Abc_Print( -2, "\t         \n" );
13298     Abc_Print( -2, "\t         Comments:\n" );
13299     Abc_Print( -2, "\t         \n" );
13300     Abc_Print( -2, "\t         The networks given on the command line should have the same CIs/COs.\n" );
13301     Abc_Print( -2, "\t         If only one network is given on the command line, this network\n" );
13302     Abc_Print( -2, "\t         is assumed to be the offset, while the current network is the onset.\n" );
13303     Abc_Print( -2, "\t         If no network is given on the command line, the current network is\n" );
13304     Abc_Print( -2, "\t         assumed to be the onset and its complement is taken to be the offset.\n" );
13305     Abc_Print( -2, "\t         The resulting interpolant is stored as the current network.\n" );
13306     Abc_Print( -2, "\t         To verify that the interpolant agrees with the onset and the offset,\n" );
13307     Abc_Print( -2, "\t         save it in file \"inter.blif\" and run the following:\n" );
13308     Abc_Print( -2, "\t         (a) \"miter -i <onset.blif> <inter.blif>; iprove\"\n" );
13309     Abc_Print( -2, "\t         (b) \"miter -i <inter.blif> <offset_inv.blif>; iprove\"\n" );
13310     Abc_Print( -2, "\t         where <offset_inv.blif> is the network derived by complementing the\n" );
13311     Abc_Print( -2, "\t         outputs of <offset.blif>: \"r <offset.blif>; st -i; w <offset_inv.blif>\"\n" );
13312     return 1;
13313 }
13314 
13315 /**Function*************************************************************
13316 
13317   Synopsis    []
13318 
13319   Description []
13320 
13321   SideEffects []
13322 
13323   SeeAlso     []
13324 
13325 ***********************************************************************/
Abc_CommandDouble(Abc_Frame_t * pAbc,int argc,char ** argv)13326 int Abc_CommandDouble( Abc_Frame_t * pAbc, int argc, char ** argv )
13327 {
13328     Abc_Ntk_t * pNtk, * pNtkRes;
13329     int c;
13330     int nFrames;
13331     int fVerbose;
13332     extern Abc_Ntk_t * Abc_NtkDouble( Abc_Ntk_t * pNtk );
13333 
13334     pNtk = Abc_FrameReadNtk(pAbc);
13335     // set defaults
13336     nFrames    = 50;
13337     fVerbose   =  0;
13338     Extra_UtilGetoptReset();
13339     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
13340     {
13341         switch ( c )
13342         {
13343         case 'F':
13344             if ( globalUtilOptind >= argc )
13345             {
13346                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
13347                 goto usage;
13348             }
13349             nFrames = atoi(argv[globalUtilOptind]);
13350             globalUtilOptind++;
13351             if ( nFrames < 0 )
13352                 goto usage;
13353             break;
13354         case 'v':
13355             fVerbose ^= 1;
13356             break;
13357         case 'h':
13358             goto usage;
13359         default:
13360             goto usage;
13361         }
13362     }
13363     if ( pNtk == NULL )
13364     {
13365         Abc_Print( -1, "Empty network.\n" );
13366         return 1;
13367     }
13368 
13369     if ( !Abc_NtkIsSopLogic(pNtk) )
13370     {
13371         Abc_Print( -1, "Only works for logic SOP networks.\n" );
13372         return 1;
13373     }
13374 
13375     pNtkRes = Abc_NtkDouble( pNtk );
13376     if ( pNtkRes == NULL )
13377     {
13378         Abc_Print( -1, "Command has failed.\n" );
13379         return 0;
13380     }
13381     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
13382     return 0;
13383 
13384 usage:
13385     Abc_Print( -2, "usage: double [-vh]\n" );
13386     Abc_Print( -2, "\t         puts together two parallel copies of the current network\n" );
13387 //    Abc_Print( -2, "\t-F num : the number of frames to simulate [default = %d]\n", nFrames );
13388     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
13389     Abc_Print( -2, "\t-h     : print the command usage\n");
13390     return 1;
13391 }
13392 
13393 /**Function*************************************************************
13394 
13395   Synopsis    []
13396 
13397   Description []
13398 
13399   SideEffects []
13400 
13401   SeeAlso     []
13402 
13403 ***********************************************************************/
Abc_CommandBb2Wb(Abc_Frame_t * pAbc,int argc,char ** argv)13404 int Abc_CommandBb2Wb( Abc_Frame_t * pAbc, int argc, char ** argv )
13405 {
13406     extern void Abc_NtkConvertBb2Wb( char * pFileNameIn, char * pFileNameOut, int fSeq, int fVerbose );
13407     int c;
13408     int fSeq;
13409     int fVerbose;
13410     // set defaults
13411     fSeq = 0;
13412     fVerbose = 0;
13413     Extra_UtilGetoptReset();
13414     while ( ( c = Extra_UtilGetopt( argc, argv, "svh" ) ) != EOF )
13415     {
13416         switch ( c )
13417         {
13418         case 's':
13419             fSeq ^= 1;
13420             break;
13421         case 'v':
13422             fVerbose ^= 1;
13423             break;
13424         default:
13425             goto usage;
13426         }
13427     }
13428     if ( argc != globalUtilOptind + 2 )
13429     {
13430         Abc_Print( -1, "Expecting two files names on the command line.\n" );
13431         goto usage;
13432     }
13433     Abc_NtkConvertBb2Wb( argv[globalUtilOptind], argv[globalUtilOptind+1], fSeq, fVerbose );
13434     return 0;
13435 
13436 usage:
13437     Abc_Print( -2, "usage: bb2wb [-svh] <file_in> <file_out>\n" );
13438     Abc_Print( -2, "\t             replaces black boxes by white boxes with AND functions\n" );
13439     Abc_Print( -2, "\t             (file names should have standard extensions, e.g. \"blif\")\n" );
13440     Abc_Print( -2, "\t-s         : toggle using sequential white boxes [default = %s]\n", fSeq? "yes": "no" );
13441     Abc_Print( -2, "\t-v         : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
13442     Abc_Print( -2, "\t-h         : print the command usage\n");
13443     Abc_Print( -2, "\t<file_in>  : input file with design containing black boxes\n");
13444     Abc_Print( -2, "\t<file_out> : output file with design containing white boxes\n");
13445     return 1;
13446 }
13447 
13448 /**Function*************************************************************
13449 
13450   Synopsis    []
13451 
13452   Description []
13453 
13454   SideEffects []
13455 
13456   SeeAlso     []
13457 
13458 ***********************************************************************/
Abc_CommandOutdec(Abc_Frame_t * pAbc,int argc,char ** argv)13459 int Abc_CommandOutdec( Abc_Frame_t * pAbc, int argc, char ** argv )
13460 {
13461     extern Abc_Ntk_t * Abc_NtkDarOutdec( Abc_Ntk_t * pNtk, int nLits, int fVerbose );
13462     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
13463     Abc_Ntk_t * pNtkRes;
13464     int c, nLits = 1;
13465     int fVerbose = 0;
13466 
13467     // set defaults
13468     Extra_UtilGetoptReset();
13469     while ( ( c = Extra_UtilGetopt( argc, argv, "Lvh" ) ) != EOF )
13470     {
13471         switch ( c )
13472         {
13473         case 'L':
13474             if ( globalUtilOptind >= argc )
13475             {
13476                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
13477                 goto usage;
13478             }
13479             nLits = atoi(argv[globalUtilOptind]);
13480             globalUtilOptind++;
13481             if ( nLits < 1 || nLits > 2 )
13482             {
13483                 Abc_Print( 1,"Currently, command \"outdec\" works for 1-lit and 2-lit primes only.\n" );
13484                 goto usage;
13485             }
13486             break;
13487         case 'v':
13488             fVerbose ^= 1;
13489             break;
13490         case 'h':
13491             goto usage;
13492         default:
13493             goto usage;
13494         }
13495     }
13496     if ( pNtk == NULL )
13497     {
13498         Abc_Print( -1, "Empty network.\n" );
13499         return 1;
13500     }
13501     if ( !Abc_NtkIsStrash(pNtk) )
13502     {
13503         Abc_Print( -1, "Only works for strashed networks.\n" );
13504         return 1;
13505     }
13506     pNtkRes = Abc_NtkDarOutdec( pNtk, nLits, fVerbose );
13507     if ( pNtkRes == NULL )
13508     {
13509         Abc_Print( -1, "Command has failed.\n" );
13510         return 0;
13511     }
13512     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
13513     return 0;
13514 
13515 usage:
13516     Abc_Print( -2, "usage: outdec [-Lvh]\n" );
13517     Abc_Print( -2, "\t         performs prime decomposition of the first output\n" );
13518     Abc_Print( -2, "\t-L num : the number of literals in the primes [default = %d]\n", nLits );
13519     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
13520     Abc_Print( -2, "\t-h     : print the command usage\n");
13521     return 1;
13522 }
13523 
13524 /**Function*************************************************************
13525 
13526   Synopsis    []
13527 
13528   Description []
13529 
13530   SideEffects []
13531 
13532   SeeAlso     []
13533 
13534 ***********************************************************************/
Abc_CommandNodeDup(Abc_Frame_t * pAbc,int argc,char ** argv)13535 int Abc_CommandNodeDup( Abc_Frame_t * pAbc, int argc, char ** argv )
13536 {
13537     extern Abc_Ntk_t * Abc_NtkNodeDup( Abc_Ntk_t * pNtk, int nLimit, int fVerbose );
13538     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
13539     Abc_Ntk_t * pNtkRes;
13540     int c, nLimit = 30;
13541     int fVerbose = 0;
13542 
13543     // set defaults
13544     Extra_UtilGetoptReset();
13545     while ( ( c = Extra_UtilGetopt( argc, argv, "Nvh" ) ) != EOF )
13546     {
13547         switch ( c )
13548         {
13549         case 'N':
13550             if ( globalUtilOptind >= argc )
13551             {
13552                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
13553                 goto usage;
13554             }
13555             nLimit = atoi(argv[globalUtilOptind]);
13556             globalUtilOptind++;
13557             break;
13558         case 'v':
13559             fVerbose ^= 1;
13560             break;
13561         case 'h':
13562             goto usage;
13563         default:
13564             goto usage;
13565         }
13566     }
13567     if ( pNtk == NULL )
13568     {
13569         Abc_Print( -1, "Empty network.\n" );
13570         return 1;
13571     }
13572     if ( Abc_NtkIsStrash(pNtk) )
13573     {
13574         Abc_Print( -1, "Only works for logic networks.\n" );
13575         return 1;
13576     }
13577     if ( nLimit < 2 )
13578     {
13579         Abc_Print( -1, "The fanout limit should be more than 1.\n" );
13580         return 1;
13581     }
13582     pNtkRes = Abc_NtkNodeDup( pNtk, nLimit, fVerbose );
13583     if ( pNtkRes == NULL )
13584     {
13585         Abc_Print( -1, "Command has failed.\n" );
13586         return 0;
13587     }
13588     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
13589     return 0;
13590 
13591 usage:
13592     Abc_Print( -2, "usage: nodedup [-Nvh]\n" );
13593     Abc_Print( -2, "\t         duplicates internal nodes with high fanout\n" );
13594     Abc_Print( -2, "\t-N num : the number of fanouts to start duplication [default = %d]\n", nLimit );
13595     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
13596     Abc_Print( -2, "\t-h     : print the command usage\n");
13597     return 1;
13598 }
13599 
13600 /**Function*************************************************************
13601 
13602   Synopsis    []
13603 
13604   Description []
13605 
13606   SideEffects []
13607 
13608   SeeAlso     []
13609 
13610 ***********************************************************************/
Abc_CommandTestColor(Abc_Frame_t * pAbc,int argc,char ** argv)13611 int Abc_CommandTestColor( Abc_Frame_t * pAbc, int argc, char ** argv )
13612 {
13613     extern void Abc_ColorTest();
13614     Abc_ColorTest();
13615     return 1;
13616 }
13617 
13618 /**Function*************************************************************
13619 
13620   Synopsis    []
13621 
13622   Description []
13623 
13624   SideEffects []
13625 
13626   SeeAlso     []
13627 
13628 ***********************************************************************/
Abc_CommandTest(Abc_Frame_t * pAbc,int argc,char ** argv)13629 int Abc_CommandTest( Abc_Frame_t * pAbc, int argc, char ** argv )
13630 {
13631     extern void Dau_NetworkEnumTest();
13632     //Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
13633     int nCutMax      =  1;
13634     int nLeafMax     =  4;
13635     int nDivMax      =  2;
13636     int nDecMax      =  3;
13637     int nNumOnes     =  0;
13638     int fNewAlgo     =  0;
13639     int fNewOrder    =  0;
13640     int fVerbose     =  0;
13641     int fVeryVerbose =  0;
13642     int c;
13643     Extra_UtilGetoptReset();
13644     while ( ( c = Extra_UtilGetopt( argc, argv, "CKDNMaovwh" ) ) != EOF )
13645     {
13646         switch ( c )
13647         {
13648         case 'C':
13649             if ( globalUtilOptind >= argc )
13650             {
13651                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
13652                 goto usage;
13653             }
13654             nCutMax = atoi(argv[globalUtilOptind]);
13655             globalUtilOptind++;
13656             if ( nCutMax < 0 )
13657                 goto usage;
13658             break;
13659         case 'K':
13660             if ( globalUtilOptind >= argc )
13661             {
13662                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
13663                 goto usage;
13664             }
13665             nLeafMax = atoi(argv[globalUtilOptind]);
13666             globalUtilOptind++;
13667             if ( nLeafMax < 0 )
13668                 goto usage;
13669             break;
13670         case 'D':
13671             if ( globalUtilOptind >= argc )
13672             {
13673                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
13674                 goto usage;
13675             }
13676             nDivMax = atoi(argv[globalUtilOptind]);
13677             globalUtilOptind++;
13678             if ( nDivMax < 0 )
13679                 goto usage;
13680             break;
13681         case 'N':
13682             if ( globalUtilOptind >= argc )
13683             {
13684                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
13685                 goto usage;
13686             }
13687             nDecMax = atoi(argv[globalUtilOptind]);
13688             globalUtilOptind++;
13689             if ( nDecMax < 0 )
13690                 goto usage;
13691             break;
13692         case 'M':
13693             if ( globalUtilOptind >= argc )
13694             {
13695                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
13696                 goto usage;
13697             }
13698             nNumOnes = atoi(argv[globalUtilOptind]);
13699             globalUtilOptind++;
13700             if ( nNumOnes < 0 )
13701                 goto usage;
13702             break;
13703         case 'a':
13704             fNewAlgo ^= 1;
13705             break;
13706         case 'o':
13707             fNewOrder ^= 1;
13708             break;
13709         case 'v':
13710             fVerbose ^= 1;
13711             break;
13712         case 'w':
13713             fVeryVerbose ^= 1;
13714             break;
13715         case 'h':
13716             goto usage;
13717         default:
13718             goto usage;
13719         }
13720     }
13721 /*
13722     if ( pNtk == NULL )
13723     {
13724         Abc_Print( -1, "Empty network.\n" );
13725         return 1;
13726     }
13727 */
13728 /*
13729     if ( Abc_NtkIsStrash(pNtk) )
13730     {
13731         Abc_Print( -1, "This command works only for logic networks.\n" );
13732         return 1;
13733     }
13734 */
13735 /*
13736     if ( Abc_NtkLatchNum(pNtk) == 0 )
13737     {
13738         Abc_Print( -1, "Only works for sequential networks.\n" );
13739         return 1;
13740     }
13741 */
13742 
13743 /*
13744     if ( pNtk )
13745     {
13746         extern Abc_Ntk_t * Au_ManPerformTest( Abc_Ntk_t * p, int nCutMax, int nLeafMax, int nDivMax, int nDecMax, int fVerbose, int fVeryVerbose );
13747         Abc_Ntk_t * pNtkRes = Au_ManPerformTest( pNtk, nCutMax, nLeafMax, nDivMax, nDecMax, fVerbose, fVeryVerbose );
13748         if ( pNtkRes == NULL )
13749         {
13750             Abc_Print( -1, "Command has failed.\n" );
13751             return 1;
13752         }
13753         Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
13754     }
13755 */
13756 /*
13757     if ( pNtk )
13758     {
13759         Aig_Man_t * pAig = Abc_NtkToDar( pNtk, 0, 1 );
13760         Saig_ManBmcTerSimTestPo( pAig );
13761         Aig_ManStop( pAig );
13762     }
13763 */
13764 /*
13765     if ( !Abc_NtkIsTopo(pNtk) )
13766     {
13767         Abc_Print( -1, "Current network is not in a topological order.\n" );
13768         return 1;
13769     }
13770 */
13771 //    if ( pNtk )
13772 //        Abc_NtkMakeLegit( pNtk );
13773     {
13774 //        extern void Ifd_ManDsdTest();
13775 //        Ifd_ManDsdTest();
13776     }
13777 /*
13778     {
13779         extern void Abc_EnumerateCubeStates();
13780         extern void Abc_EnumerateCubeStatesZdd();
13781         if ( fNewAlgo )
13782             Abc_EnumerateCubeStatesZdd();
13783         else
13784             Abc_EnumerateCubeStates();
13785         return 0;
13786     }
13787 */
13788     {
13789 //        extern void Abc_EnumerateFuncs( int nDecMax, int nDivMax, int fVerbose );
13790 //        Abc_EnumerateFuncs( 4, 7, 0 );
13791     }
13792 /*
13793     if ( fNewAlgo )
13794     {
13795         extern void Abc_SuppTest( int nOnes, int nVars, int fUseSimple, int fCheck, int fVerbose );
13796         Abc_SuppTest( nNumOnes, nDecMax, fNewOrder, 0, fVerbose );
13797     }
13798     else
13799     {
13800         extern void Bmc_EcoMiterTest();
13801         Bmc_EcoMiterTest();
13802     }
13803 */
13804 
13805     {
13806 //        extern void Nf_ManPrepareLibraryTest();
13807 //        Nf_ManPrepareLibraryTest();
13808 //        return 0;
13809     }
13810 /*
13811     if ( pNtk )
13812     {
13813 //        extern Abc_Ntk_t * Abc_NtkBarBufsOnOffTest( Abc_Ntk_t * pNtk );
13814 //        Abc_Ntk_t * pNtkRes = Abc_NtkBarBufsOnOffTest( pNtk );
13815         extern Abc_Ntk_t * Abc_NtkPcmTest( Abc_Ntk_t * pNtk, int fNewAlgo, int fVerbose );
13816 //        extern Abc_Ntk_t * Abc_NtkPcmTestAig( Abc_Ntk_t * pNtk, int fVerbose );
13817         Abc_Ntk_t * pNtkRes;
13818 //        if ( Abc_NtkIsLogic(pNtk) )
13819             pNtkRes = Abc_NtkPcmTest( pNtk, fNewAlgo, fVerbose );
13820 //        else
13821 //            pNtkRes = Abc_NtkPcmTestAig( pNtk, fVerbose );
13822         if ( pNtkRes == NULL )
13823         {
13824             Abc_Print( -1, "Command has failed.\n" );
13825             return 1;
13826         }
13827         Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
13828     }
13829 */
13830 /*
13831     {
13832         extern void Abc_IsopTestNew();
13833         Abc_IsopTestNew();
13834     }
13835 */
13836     {
13837 //        extern void Cba_PrsReadBlifTest();
13838 //        Cba_PrsReadBlifTest();
13839     }
13840 //    Abc_NtkComputePaths( Abc_FrameReadNtk(pAbc) );
13841     //Dau_NetworkEnumTest();
13842     //Extra_SimulationTest( nDivMax, nNumOnes, fNewOrder );
13843     //Mnist_ExperimentWithScaling( nDecMax );
13844     //Extra_ReadForestTest();
13845     return 0;
13846 usage:
13847     Abc_Print( -2, "usage: test [-CKDNM] [-aovwh] <file_name>\n" );
13848     Abc_Print( -2, "\t         testbench for new procedures\n" );
13849     Abc_Print( -2, "\t-C num : the max number of cuts [default = %d]\n", nCutMax );
13850     Abc_Print( -2, "\t-K num : the max number of leaves [default = %d]\n", nLeafMax );
13851     Abc_Print( -2, "\t-D num : the max number of divisors [default = %d]\n", nDivMax );
13852     Abc_Print( -2, "\t-N num : the max number of node inputs [default = %d]\n", nDecMax );
13853     Abc_Print( -2, "\t-M num : the max number of ones in the vector [default = %d]\n", nNumOnes );
13854     Abc_Print( -2, "\t-a     : toggle using new algorithm [default = %s]\n", fNewAlgo? "yes": "no" );
13855     Abc_Print( -2, "\t-o     : toggle using new ordering [default = %s]\n", fNewOrder? "yes": "no" );
13856     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
13857     Abc_Print( -2, "\t-w     : toggle printing very verbose information [default = %s]\n", fVeryVerbose? "yes": "no" );
13858     Abc_Print( -2, "\t-h     : print the command usage\n");
13859     return 1;
13860 }
13861 
13862 /**Function*************************************************************
13863 
13864   Synopsis    []
13865 
13866   Description []
13867 
13868   SideEffects []
13869 
13870   SeeAlso     []
13871 
13872 ***********************************************************************/
Abc_CommandQuaVar(Abc_Frame_t * pAbc,int argc,char ** argv)13873 int Abc_CommandQuaVar( Abc_Frame_t * pAbc, int argc, char ** argv )
13874 {
13875     Abc_Ntk_t * pNtk, * pNtkRes;
13876     int c, iVar, fUniv, fVerbose, RetValue;
13877     extern int Abc_NtkQuantify( Abc_Ntk_t * pNtk, int fUniv, int iVar, int fVerbose );
13878 
13879     pNtk = Abc_FrameReadNtk(pAbc);
13880     // set defaults
13881     iVar = 0;
13882     fUniv = 0;
13883     fVerbose = 0;
13884     Extra_UtilGetoptReset();
13885     while ( ( c = Extra_UtilGetopt( argc, argv, "Iuvh" ) ) != EOF )
13886     {
13887         switch ( c )
13888         {
13889         case 'I':
13890             if ( globalUtilOptind >= argc )
13891             {
13892                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
13893                 goto usage;
13894             }
13895             iVar = atoi(argv[globalUtilOptind]);
13896             globalUtilOptind++;
13897             if ( iVar < 0 )
13898                 goto usage;
13899             break;
13900         case 'u':
13901             fUniv ^= 1;
13902             break;
13903         case 'v':
13904             fVerbose ^= 1;
13905             break;
13906         case 'h':
13907             goto usage;
13908         default:
13909             goto usage;
13910         }
13911     }
13912     if ( pNtk == NULL )
13913     {
13914         Abc_Print( -1, "Empty network.\n" );
13915         return 1;
13916     }
13917     if ( Abc_NtkGetChoiceNum( pNtk ) )
13918     {
13919         Abc_Print( -1, "This command cannot be applied to an AIG with choice nodes.\n" );
13920         return 1;
13921     }
13922 
13923     // get the strashed network
13924     pNtkRes = Abc_NtkStrash( pNtk, 0, 1, 0 );
13925     RetValue = Abc_NtkQuantify( pNtkRes, fUniv, iVar, fVerbose );
13926     // clean temporary storage for the cofactors
13927     Abc_NtkCleanData( pNtkRes );
13928     Abc_AigCleanup( (Abc_Aig_t *)pNtkRes->pManFunc );
13929     // check the result
13930     if ( !RetValue )
13931     {
13932         Abc_Print( -1, "Command has failed.\n" );
13933         return 0;
13934     }
13935     // replace the current network
13936     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
13937     return 0;
13938 
13939 usage:
13940     Abc_Print( -2, "usage: qvar [-I num] [-uvh]\n" );
13941     Abc_Print( -2, "\t         quantifies one variable using the AIG\n" );
13942     Abc_Print( -2, "\t-I num : the zero-based index of a variable to quantify [default = %d]\n", iVar );
13943     Abc_Print( -2, "\t-u     : toggle universal quantification [default = %s]\n", fUniv? "yes": "no" );
13944     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
13945     Abc_Print( -2, "\t-h     : print the command usage\n");
13946     return 1;
13947 }
13948 
13949 /**Function*************************************************************
13950 
13951   Synopsis    []
13952 
13953   Description []
13954 
13955   SideEffects []
13956 
13957   SeeAlso     []
13958 
13959 ***********************************************************************/
Abc_CommandQuaRel(Abc_Frame_t * pAbc,int argc,char ** argv)13960 int Abc_CommandQuaRel( Abc_Frame_t * pAbc, int argc, char ** argv )
13961 {
13962     Abc_Ntk_t * pNtk, * pNtkRes;
13963     int c, iVar, fInputs, fVerbose;
13964     extern Abc_Ntk_t * Abc_NtkTransRel( Abc_Ntk_t * pNtk, int fInputs, int fVerbose );
13965 
13966     pNtk = Abc_FrameReadNtk(pAbc);
13967     // set defaults
13968     iVar = 0;
13969     fInputs = 1;
13970     fVerbose = 0;
13971     Extra_UtilGetoptReset();
13972     while ( ( c = Extra_UtilGetopt( argc, argv, "Iqvh" ) ) != EOF )
13973     {
13974         switch ( c )
13975         {
13976         case 'I':
13977             if ( globalUtilOptind >= argc )
13978             {
13979                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
13980                 goto usage;
13981             }
13982             iVar = atoi(argv[globalUtilOptind]);
13983             globalUtilOptind++;
13984             if ( iVar < 0 )
13985                 goto usage;
13986             break;
13987         case 'q':
13988             fInputs ^= 1;
13989             break;
13990         case 'v':
13991             fVerbose ^= 1;
13992             break;
13993         case 'h':
13994             goto usage;
13995         default:
13996             goto usage;
13997         }
13998     }
13999     if ( pNtk == NULL )
14000     {
14001         Abc_Print( -1, "Empty network.\n" );
14002         return 1;
14003     }
14004     if ( Abc_NtkGetChoiceNum( pNtk ) )
14005     {
14006         Abc_Print( -1, "This command cannot be applied to an AIG with choice nodes.\n" );
14007         return 1;
14008     }
14009     if ( Abc_NtkIsComb(pNtk) )
14010     {
14011         Abc_Print( -1, "This command works only for sequential circuits.\n" );
14012         return 1;
14013     }
14014 
14015     // get the strashed network
14016     if ( !Abc_NtkIsStrash(pNtk) )
14017     {
14018         pNtk = Abc_NtkStrash( pNtk, 0, 1, 0 );
14019         pNtkRes = Abc_NtkTransRel( pNtk, fInputs, fVerbose );
14020         Abc_NtkDelete( pNtk );
14021     }
14022     else
14023         pNtkRes = Abc_NtkTransRel( pNtk, fInputs, fVerbose );
14024     // check if the result is available
14025     if ( pNtkRes == NULL )
14026     {
14027         Abc_Print( -1, "Command has failed.\n" );
14028         return 0;
14029     }
14030     // replace the current network
14031     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
14032     return 0;
14033 
14034 usage:
14035     Abc_Print( -2, "usage: qrel [-qvh]\n" );
14036     Abc_Print( -2, "\t         computes transition relation of the sequential network\n" );
14037 //    Abc_Print( -2, "\t-I num : the zero-based index of a variable to quantify [default = %d]\n", iVar );
14038     Abc_Print( -2, "\t-q     : perform quantification of inputs [default = %s]\n", fInputs? "yes": "no" );
14039     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
14040     Abc_Print( -2, "\t-h     : print the command usage\n");
14041     return 1;
14042 }
14043 
14044 /**Function*************************************************************
14045 
14046   Synopsis    []
14047 
14048   Description []
14049 
14050   SideEffects []
14051 
14052   SeeAlso     []
14053 
14054 ***********************************************************************/
Abc_CommandQuaReach(Abc_Frame_t * pAbc,int argc,char ** argv)14055 int Abc_CommandQuaReach( Abc_Frame_t * pAbc, int argc, char ** argv )
14056 {
14057     Abc_Ntk_t * pNtk, * pNtkRes;
14058     int c, nIters, fVerbose;
14059     extern Abc_Ntk_t * Abc_NtkReachability( Abc_Ntk_t * pNtk, int nIters, int fVerbose );
14060 
14061     pNtk = Abc_FrameReadNtk(pAbc);
14062     // set defaults
14063     nIters   = 256;
14064     fVerbose =   0;
14065     Extra_UtilGetoptReset();
14066     while ( ( c = Extra_UtilGetopt( argc, argv, "Ivh" ) ) != EOF )
14067     {
14068         switch ( c )
14069         {
14070         case 'I':
14071             if ( globalUtilOptind >= argc )
14072             {
14073                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
14074                 goto usage;
14075             }
14076             nIters = atoi(argv[globalUtilOptind]);
14077             globalUtilOptind++;
14078             if ( nIters < 0 )
14079                 goto usage;
14080             break;
14081         case 'v':
14082             fVerbose ^= 1;
14083             break;
14084         case 'h':
14085             goto usage;
14086         default:
14087             goto usage;
14088         }
14089     }
14090     if ( pNtk == NULL )
14091     {
14092         Abc_Print( -1, "Empty network.\n" );
14093         return 1;
14094     }
14095     if ( Abc_NtkGetChoiceNum( pNtk ) )
14096     {
14097         Abc_Print( -1, "This command cannot be applied to an AIG with choice nodes.\n" );
14098         return 1;
14099     }
14100     if ( !Abc_NtkIsComb(pNtk) )
14101     {
14102         Abc_Print( -1, "This command works only for combinational transition relations.\n" );
14103         return 1;
14104     }
14105     if ( !Abc_NtkIsStrash(pNtk) )
14106     {
14107         Abc_Print( -1, "This command works only for strashed networks.\n" );
14108         return 1;
14109     }
14110     if ( Abc_NtkPoNum(pNtk) > 1 )
14111     {
14112         Abc_Print( -1, "The transition relation should have one output.\n" );
14113         return 1;
14114     }
14115     if ( Abc_NtkPiNum(pNtk) % 2 != 0 )
14116     {
14117         Abc_Print( -1, "The transition relation should have an even number of inputs.\n" );
14118         return 1;
14119     }
14120 
14121     pNtkRes = Abc_NtkReachability( pNtk, nIters, fVerbose );
14122     if ( pNtkRes == NULL )
14123     {
14124         Abc_Print( -1, "Command has failed.\n" );
14125         return 0;
14126     }
14127     // replace the current network
14128     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
14129     return 0;
14130 
14131 usage:
14132     Abc_Print( -2, "usage: qreach [-I num] [-vh]\n" );
14133     Abc_Print( -2, "\t         computes unreachable states using AIG-based quantification\n" );
14134     Abc_Print( -2, "\t         assumes that the current network is a transition relation\n" );
14135     Abc_Print( -2, "\t         assumes that the initial state is composed of all zeros\n" );
14136     Abc_Print( -2, "\t-I num : the number of image computations to perform [default = %d]\n", nIters );
14137     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
14138     Abc_Print( -2, "\t-h     : print the command usage\n");
14139     return 1;
14140 }
14141 
14142 /**Function*************************************************************
14143 
14144   Synopsis    []
14145 
14146   Description []
14147 
14148   SideEffects []
14149 
14150   SeeAlso     []
14151 
14152 ***********************************************************************/
Abc_CommandSenseInput(Abc_Frame_t * pAbc,int argc,char ** argv)14153 int Abc_CommandSenseInput( Abc_Frame_t * pAbc, int argc, char ** argv )
14154 {
14155     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
14156     Vec_Int_t * vResult;
14157     int c, nConfLim, fVerbose;
14158 
14159     extern Vec_Int_t * Abc_NtkSensitivity( Abc_Ntk_t * pNtk, int nConfLim, int fVerbose );
14160     // set defaults
14161     nConfLim   = 1000;
14162     fVerbose   =    1;
14163     Extra_UtilGetoptReset();
14164     while ( ( c = Extra_UtilGetopt( argc, argv, "Cvh" ) ) != EOF )
14165     {
14166         switch ( c )
14167         {
14168         case 'C':
14169             if ( globalUtilOptind >= argc )
14170             {
14171                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
14172                 goto usage;
14173             }
14174             nConfLim = atoi(argv[globalUtilOptind]);
14175             globalUtilOptind++;
14176             if ( nConfLim < 0 )
14177                 goto usage;
14178             break;
14179         case 'v':
14180             fVerbose ^= 1;
14181             break;
14182         case 'h':
14183             goto usage;
14184         default:
14185             goto usage;
14186         }
14187     }
14188     if ( pNtk == NULL )
14189     {
14190         Abc_Print( -1, "Empty network.\n" );
14191         return 1;
14192     }
14193     if ( Abc_NtkGetChoiceNum( pNtk ) )
14194     {
14195         Abc_Print( -1, "This command cannot be applied to an AIG with choice nodes.\n" );
14196         return 1;
14197     }
14198     if ( !Abc_NtkIsComb(pNtk) )
14199     {
14200         Abc_Print( -1, "This command works only for combinational transition relations.\n" );
14201         return 1;
14202     }
14203     if ( !Abc_NtkIsStrash(pNtk) )
14204     {
14205         Abc_Print( -1, "This command works only for strashed networks.\n" );
14206         return 1;
14207     }
14208     if ( Abc_NtkPoNum(pNtk) < 2 )
14209     {
14210         Abc_Print( -1, "The network should have at least two outputs.\n" );
14211         return 1;
14212     }
14213 
14214     vResult = Abc_NtkSensitivity( pNtk, nConfLim, fVerbose );
14215     Vec_IntFree( vResult );
14216     return 0;
14217 
14218 usage:
14219     Abc_Print( -2, "usage: senseinput [-C num] [-vh]\n" );
14220     Abc_Print( -2, "\t         computes sensitivity of POs to PIs under constraint\n" );
14221     Abc_Print( -2, "\t         constraint should be represented as the last PO\n" );
14222     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", nConfLim );
14223     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
14224     Abc_Print( -2, "\t-h     : print the command usage\n");
14225     return 1;
14226 }
14227 
14228 
14229 /**Function*************************************************************
14230 
14231   Synopsis    []
14232 
14233   Description []
14234 
14235   SideEffects []
14236 
14237   SeeAlso     []
14238 
14239 ***********************************************************************/
Abc_CommandIStrash(Abc_Frame_t * pAbc,int argc,char ** argv)14240 int Abc_CommandIStrash( Abc_Frame_t * pAbc, int argc, char ** argv )
14241 {
14242     Abc_Ntk_t * pNtk, * pNtkRes, * pNtkTemp;
14243     int c;
14244     extern Abc_Ntk_t * Abc_NtkIvyStrash( Abc_Ntk_t * pNtk );
14245 
14246     pNtk = Abc_FrameReadNtk(pAbc);
14247     // set defaults
14248     Extra_UtilGetoptReset();
14249     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
14250     {
14251         switch ( c )
14252         {
14253         case 'h':
14254             goto usage;
14255         default:
14256             goto usage;
14257         }
14258     }
14259     if ( pNtk == NULL )
14260     {
14261         Abc_Print( -1, "Empty network.\n" );
14262         return 1;
14263     }
14264     if ( !Abc_NtkIsStrash(pNtk) )
14265     {
14266         pNtkTemp = Abc_NtkStrash( pNtk, 0, 1, 0 );
14267         pNtkRes = Abc_NtkIvyStrash( pNtkTemp );
14268         Abc_NtkDelete( pNtkTemp );
14269     }
14270     else
14271         pNtkRes = Abc_NtkIvyStrash( pNtk );
14272     if ( pNtkRes == NULL )
14273     {
14274         Abc_Print( -1, "Command has failed.\n" );
14275         return 0;
14276     }
14277     // replace the current network
14278     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
14279     return 0;
14280 
14281 usage:
14282     Abc_Print( -2, "usage: istrash [-h]\n" );
14283     Abc_Print( -2, "\t         perform sequential structural hashing\n" );
14284     Abc_Print( -2, "\t-h     : print the command usage\n");
14285     return 1;
14286 }
14287 
14288 /**Function*************************************************************
14289 
14290   Synopsis    []
14291 
14292   Description []
14293 
14294   SideEffects []
14295 
14296   SeeAlso     []
14297 
14298 ***********************************************************************/
Abc_CommandICut(Abc_Frame_t * pAbc,int argc,char ** argv)14299 int Abc_CommandICut( Abc_Frame_t * pAbc, int argc, char ** argv )
14300 {
14301     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
14302     int c, nInputs;
14303     extern void Abc_NtkIvyCuts( Abc_Ntk_t * pNtk, int nInputs );
14304 
14305     // set defaults
14306     nInputs = 5;
14307     Extra_UtilGetoptReset();
14308     while ( ( c = Extra_UtilGetopt( argc, argv, "Kh" ) ) != EOF )
14309     {
14310         switch ( c )
14311         {
14312         case 'K':
14313             if ( globalUtilOptind >= argc )
14314             {
14315                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
14316                 goto usage;
14317             }
14318             nInputs = atoi(argv[globalUtilOptind]);
14319             globalUtilOptind++;
14320             if ( nInputs < 0 )
14321                 goto usage;
14322             break;
14323         case 'h':
14324             goto usage;
14325         default:
14326             goto usage;
14327         }
14328     }
14329     if ( pNtk == NULL )
14330     {
14331         Abc_Print( -1, "Empty network.\n" );
14332         return 1;
14333     }
14334     if ( !Abc_NtkIsStrash(pNtk) )
14335     {
14336         Abc_Print( -1, "This command works only for strashed networks.\n" );
14337         return 1;
14338     }
14339 
14340     Abc_NtkIvyCuts( pNtk, nInputs );
14341     return 0;
14342 
14343 usage:
14344     Abc_Print( -2, "usage: icut [-K num] [-h]\n" );
14345     Abc_Print( -2, "\t         computes sequential cuts of the given size\n" );
14346     Abc_Print( -2, "\t-K num : the number of cut inputs (2 <= num <= 6) [default = %d]\n", nInputs );
14347     Abc_Print( -2, "\t-h     : print the command usage\n");
14348     return 1;
14349 }
14350 
14351 /**Function*************************************************************
14352 
14353   Synopsis    []
14354 
14355   Description []
14356 
14357   SideEffects []
14358 
14359   SeeAlso     []
14360 
14361 ***********************************************************************/
Abc_CommandIRewrite(Abc_Frame_t * pAbc,int argc,char ** argv)14362 int Abc_CommandIRewrite( Abc_Frame_t * pAbc, int argc, char ** argv )
14363 {
14364     Abc_Ntk_t * pNtk, * pNtkRes;
14365     int c, fUpdateLevel, fUseZeroCost, fVerbose;
14366     extern Abc_Ntk_t * Abc_NtkIvyRewrite( Abc_Ntk_t * pNtk, int fUpdateLevel, int fUseZeroCost, int fVerbose );
14367 
14368     pNtk = Abc_FrameReadNtk(pAbc);
14369     // set defaults
14370     fUpdateLevel = 1;
14371     fUseZeroCost = 0;
14372     fVerbose     = 0;
14373     Extra_UtilGetoptReset();
14374     while ( ( c = Extra_UtilGetopt( argc, argv, "lzvh" ) ) != EOF )
14375     {
14376         switch ( c )
14377         {
14378         case 'l':
14379             fUpdateLevel ^= 1;
14380             break;
14381         case 'z':
14382             fUseZeroCost ^= 1;
14383             break;
14384         case 'v':
14385             fVerbose ^= 1;
14386             break;
14387         case 'h':
14388             goto usage;
14389         default:
14390             goto usage;
14391         }
14392     }
14393     if ( pNtk == NULL )
14394     {
14395         Abc_Print( -1, "Empty network.\n" );
14396         return 1;
14397     }
14398     if ( !Abc_NtkIsStrash(pNtk) )
14399     {
14400         Abc_Print( -1, "This command works only for strashed networks.\n" );
14401         return 1;
14402     }
14403 
14404     pNtkRes = Abc_NtkIvyRewrite( pNtk, fUpdateLevel, fUseZeroCost, fVerbose );
14405     if ( pNtkRes == NULL )
14406     {
14407         Abc_Print( -1, "Command has failed.\n" );
14408         return 0;
14409     }
14410     // replace the current network
14411     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
14412     return 0;
14413 
14414 usage:
14415     Abc_Print( -2, "usage: irw [-lzvh]\n" );
14416     Abc_Print( -2, "\t         perform combinational AIG rewriting\n" );
14417     Abc_Print( -2, "\t-l     : toggle preserving the number of levels [default = %s]\n", fUpdateLevel? "yes": "no" );
14418     Abc_Print( -2, "\t-z     : toggle using zero-cost replacements [default = %s]\n", fUseZeroCost? "yes": "no" );
14419     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
14420     Abc_Print( -2, "\t-h     : print the command usage\n");
14421     return 1;
14422 }
14423 
14424 /**Function*************************************************************
14425 
14426   Synopsis    []
14427 
14428   Description []
14429 
14430   SideEffects []
14431 
14432   SeeAlso     []
14433 
14434 ***********************************************************************/
Abc_CommandDRewrite(Abc_Frame_t * pAbc,int argc,char ** argv)14435 int Abc_CommandDRewrite( Abc_Frame_t * pAbc, int argc, char ** argv )
14436 {
14437     Abc_Ntk_t * pNtk, * pNtkRes;
14438     Dar_RwrPar_t Pars, * pPars = &Pars;
14439     int c;
14440 
14441     extern Abc_Ntk_t * Abc_NtkDRewrite( Abc_Ntk_t * pNtk, Dar_RwrPar_t * pPars );
14442 
14443     pNtk = Abc_FrameReadNtk(pAbc);
14444     // set defaults
14445     Dar_ManDefaultRwrParams( pPars );
14446     Extra_UtilGetoptReset();
14447     while ( ( c = Extra_UtilGetopt( argc, argv, "CNflzrvwh" ) ) != EOF )
14448     {
14449         switch ( c )
14450         {
14451         case 'C':
14452             if ( globalUtilOptind >= argc )
14453             {
14454                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
14455                 goto usage;
14456             }
14457             pPars->nCutsMax = atoi(argv[globalUtilOptind]);
14458             globalUtilOptind++;
14459             if ( pPars->nCutsMax < 0 )
14460                 goto usage;
14461             break;
14462         case 'N':
14463             if ( globalUtilOptind >= argc )
14464             {
14465                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
14466                 goto usage;
14467             }
14468             pPars->nSubgMax = atoi(argv[globalUtilOptind]);
14469             globalUtilOptind++;
14470             if ( pPars->nSubgMax < 0 )
14471                 goto usage;
14472             break;
14473         case 'f':
14474             pPars->fFanout ^= 1;
14475             break;
14476         case 'l':
14477             pPars->fUpdateLevel ^= 1;
14478             break;
14479         case 'z':
14480             pPars->fUseZeros ^= 1;
14481             break;
14482         case 'r':
14483             pPars->fRecycle ^= 1;
14484             break;
14485         case 'v':
14486             pPars->fVerbose ^= 1;
14487             break;
14488         case 'w':
14489             pPars->fVeryVerbose ^= 1;
14490             break;
14491         case 'h':
14492             goto usage;
14493         default:
14494             goto usage;
14495         }
14496     }
14497     if ( pNtk == NULL )
14498     {
14499         Abc_Print( -1, "Empty network.\n" );
14500         return 1;
14501     }
14502     if ( !Abc_NtkIsStrash(pNtk) )
14503     {
14504         Abc_Print( -1, "This command works only for strashed networks.\n" );
14505         return 1;
14506     }
14507     pNtkRes = Abc_NtkDRewrite( pNtk, pPars );
14508     if ( pNtkRes == NULL )
14509     {
14510         Abc_Print( -1, "Command has failed.\n" );
14511         return 0;
14512     }
14513     // replace the current network
14514     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
14515     return 0;
14516 
14517 usage:
14518     Abc_Print( -2, "usage: drw [-C num] [-N num] [-lfzrvwh]\n" );
14519     Abc_Print( -2, "\t         performs combinational AIG rewriting\n" );
14520     Abc_Print( -2, "\t-C num : the max number of cuts at a node [default = %d]\n", pPars->nCutsMax );
14521     Abc_Print( -2, "\t-N num : the max number of subgraphs tried [default = %d]\n", pPars->nSubgMax );
14522     Abc_Print( -2, "\t-l     : toggle preserving the number of levels [default = %s]\n", pPars->fUpdateLevel? "yes": "no" );
14523     Abc_Print( -2, "\t-f     : toggle representing fanouts [default = %s]\n", pPars->fFanout? "yes": "no" );
14524     Abc_Print( -2, "\t-z     : toggle using zero-cost replacements [default = %s]\n", pPars->fUseZeros? "yes": "no" );
14525     Abc_Print( -2, "\t-r     : toggle using cut recycling [default = %s]\n", pPars->fRecycle? "yes": "no" );
14526     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", pPars->fVerbose? "yes": "no" );
14527     Abc_Print( -2, "\t-w     : toggle very verbose printout [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
14528     Abc_Print( -2, "\t-h     : print the command usage\n");
14529     return 1;
14530 }
14531 
14532 /**Function*************************************************************
14533 
14534   Synopsis    []
14535 
14536   Description []
14537 
14538   SideEffects []
14539 
14540   SeeAlso     []
14541 
14542 ***********************************************************************/
Abc_CommandDRefactor(Abc_Frame_t * pAbc,int argc,char ** argv)14543 int Abc_CommandDRefactor( Abc_Frame_t * pAbc, int argc, char ** argv )
14544 {
14545     Abc_Ntk_t * pNtk, * pNtkRes;
14546     Dar_RefPar_t Pars, * pPars = &Pars;
14547     int c;
14548 
14549     extern Abc_Ntk_t * Abc_NtkDRefactor( Abc_Ntk_t * pNtk, Dar_RefPar_t * pPars );
14550 
14551     pNtk = Abc_FrameReadNtk(pAbc);
14552     // set defaults
14553     Dar_ManDefaultRefParams( pPars );
14554     Extra_UtilGetoptReset();
14555     while ( ( c = Extra_UtilGetopt( argc, argv, "MKCelzvwh" ) ) != EOF )
14556     {
14557         switch ( c )
14558         {
14559         case 'M':
14560             if ( globalUtilOptind >= argc )
14561             {
14562                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
14563                 goto usage;
14564             }
14565             pPars->nMffcMin = atoi(argv[globalUtilOptind]);
14566             globalUtilOptind++;
14567             if ( pPars->nMffcMin < 0 )
14568                 goto usage;
14569             break;
14570         case 'K':
14571             if ( globalUtilOptind >= argc )
14572             {
14573                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
14574                 goto usage;
14575             }
14576             pPars->nLeafMax = atoi(argv[globalUtilOptind]);
14577             globalUtilOptind++;
14578             if ( pPars->nLeafMax < 0 )
14579                 goto usage;
14580             break;
14581         case 'C':
14582             if ( globalUtilOptind >= argc )
14583             {
14584                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
14585                 goto usage;
14586             }
14587             pPars->nCutsMax = atoi(argv[globalUtilOptind]);
14588             globalUtilOptind++;
14589             if ( pPars->nCutsMax < 0 )
14590                 goto usage;
14591             break;
14592         case 'e':
14593             pPars->fExtend ^= 1;
14594             break;
14595         case 'l':
14596             pPars->fUpdateLevel ^= 1;
14597             break;
14598         case 'z':
14599             pPars->fUseZeros ^= 1;
14600             break;
14601         case 'v':
14602             pPars->fVerbose ^= 1;
14603             break;
14604         case 'w':
14605             pPars->fVeryVerbose ^= 1;
14606             break;
14607         case 'h':
14608             goto usage;
14609         default:
14610             goto usage;
14611         }
14612     }
14613     if ( pNtk == NULL )
14614     {
14615         Abc_Print( -1, "Empty network.\n" );
14616         return 1;
14617     }
14618     if ( !Abc_NtkIsStrash(pNtk) )
14619     {
14620         Abc_Print( -1, "This command works only for strashed networks.\n" );
14621         return 1;
14622     }
14623     if ( pPars->nLeafMax < 4 || pPars->nLeafMax > 15 )
14624     {
14625         Abc_Print( -1, "This command only works for cut sizes 4 <= K <= 15.\n" );
14626         return 1;
14627     }
14628     pNtkRes = Abc_NtkDRefactor( pNtk, pPars );
14629     if ( pNtkRes == NULL )
14630     {
14631         Abc_Print( -1, "Command has failed.\n" );
14632         return 0;
14633     }
14634     // replace the current network
14635     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
14636     return 0;
14637 
14638 usage:
14639     Abc_Print( -2, "usage: drf [-M num] [-K num] [-C num] [-elzvwh]\n" );
14640     Abc_Print( -2, "\t         performs combinational AIG refactoring\n" );
14641     Abc_Print( -2, "\t-M num : the min MFFC size to attempt refactoring [default = %d]\n", pPars->nMffcMin );
14642     Abc_Print( -2, "\t-K num : the max number of cuts leaves [default = %d]\n", pPars->nLeafMax );
14643     Abc_Print( -2, "\t-C num : the max number of cuts to try at a node [default = %d]\n", pPars->nCutsMax );
14644     Abc_Print( -2, "\t-e     : toggle extending tbe cut below MFFC [default = %s]\n", pPars->fExtend? "yes": "no" );
14645     Abc_Print( -2, "\t-l     : toggle preserving the number of levels [default = %s]\n", pPars->fUpdateLevel? "yes": "no" );
14646     Abc_Print( -2, "\t-z     : toggle using zero-cost replacements [default = %s]\n", pPars->fUseZeros? "yes": "no" );
14647     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", pPars->fVerbose? "yes": "no" );
14648     Abc_Print( -2, "\t-w     : toggle very verbose printout [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
14649     Abc_Print( -2, "\t-h     : print the command usage\n");
14650     return 1;
14651 }
14652 
14653 /**Function*************************************************************
14654 
14655   Synopsis    []
14656 
14657   Description []
14658 
14659   SideEffects []
14660 
14661   SeeAlso     []
14662 
14663 ***********************************************************************/
Abc_CommandDc2(Abc_Frame_t * pAbc,int argc,char ** argv)14664 int Abc_CommandDc2( Abc_Frame_t * pAbc, int argc, char ** argv )
14665 {
14666     Abc_Ntk_t * pNtk, * pNtkRes;
14667     int fBalance, fVerbose, fUpdateLevel, fFanout, fPower, c;
14668 
14669     extern Abc_Ntk_t * Abc_NtkDC2( Abc_Ntk_t * pNtk, int fBalance, int fUpdateLevel, int fFanout, int fPower, int fVerbose );
14670 
14671     pNtk = Abc_FrameReadNtk(pAbc);
14672     // set defaults
14673     fBalance     = 0;
14674     fVerbose     = 0;
14675     fUpdateLevel = 0;
14676     fFanout      = 1;
14677     fPower       = 0;
14678     Extra_UtilGetoptReset();
14679     while ( ( c = Extra_UtilGetopt( argc, argv, "blfpvh" ) ) != EOF )
14680     {
14681         switch ( c )
14682         {
14683         case 'b':
14684             fBalance ^= 1;
14685             break;
14686         case 'l':
14687             fUpdateLevel ^= 1;
14688             break;
14689         case 'f':
14690             fFanout ^= 1;
14691             break;
14692         case 'p':
14693             fPower ^= 1;
14694             break;
14695         case 'v':
14696             fVerbose ^= 1;
14697             break;
14698         case 'h':
14699             goto usage;
14700         default:
14701             goto usage;
14702         }
14703     }
14704     if ( pNtk == NULL )
14705     {
14706         Abc_Print( -1, "Empty network.\n" );
14707         return 1;
14708     }
14709     if ( !Abc_NtkIsStrash(pNtk) )
14710     {
14711         Abc_Print( -1, "This command works only for strashed networks.\n" );
14712         return 1;
14713     }
14714     pNtkRes = Abc_NtkDC2( pNtk, fBalance, fUpdateLevel, fFanout, fPower, fVerbose );
14715     if ( pNtkRes == NULL )
14716     {
14717         Abc_Print( -1, "Command has failed.\n" );
14718         return 0;
14719     }
14720     // replace the current network
14721     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
14722     return 0;
14723 
14724 usage:
14725     Abc_Print( -2, "usage: dc2 [-blfpvh]\n" );
14726     Abc_Print( -2, "\t         performs combinational AIG optimization\n" );
14727     Abc_Print( -2, "\t-b     : toggle internal balancing [default = %s]\n", fBalance? "yes": "no" );
14728     Abc_Print( -2, "\t-l     : toggle updating level [default = %s]\n", fUpdateLevel? "yes": "no" );
14729     Abc_Print( -2, "\t-f     : toggle representing fanouts [default = %s]\n", fFanout? "yes": "no" );
14730     Abc_Print( -2, "\t-p     : toggle power-aware rewriting [default = %s]\n", fPower? "yes": "no" );
14731     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
14732     Abc_Print( -2, "\t-h     : print the command usage\n");
14733     return 1;
14734 }
14735 
14736 
14737 /**Function*************************************************************
14738 
14739   Synopsis    []
14740 
14741   Description []
14742 
14743   SideEffects []
14744 
14745   SeeAlso     []
14746 
14747 ***********************************************************************/
Abc_CommandDChoice(Abc_Frame_t * pAbc,int argc,char ** argv)14748 int Abc_CommandDChoice( Abc_Frame_t * pAbc, int argc, char ** argv )
14749 {
14750     Abc_Ntk_t * pNtk, * pNtkRes;
14751     int fBalance, fVerbose, fUpdateLevel, fConstruct, c;
14752     int nConfMax, nLevelMax;
14753 
14754     extern Abc_Ntk_t * Abc_NtkDChoice( Abc_Ntk_t * pNtk, int fBalance, int fUpdateLevel, int fConstruct, int nConfMax, int nLevelMax, int fVerbose );
14755 
14756     pNtk = Abc_FrameReadNtk(pAbc);
14757     // set defaults
14758     fBalance     = 1;
14759     fUpdateLevel = 1;
14760     fConstruct   = 0;
14761     nConfMax     = 1000;
14762     nLevelMax    = 0;
14763     fVerbose     = 0;
14764     Extra_UtilGetoptReset();
14765     while ( ( c = Extra_UtilGetopt( argc, argv, "CLblcvh" ) ) != EOF )
14766     {
14767         switch ( c )
14768         {
14769         case 'C':
14770             if ( globalUtilOptind >= argc )
14771             {
14772                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
14773                 goto usage;
14774             }
14775             nConfMax = atoi(argv[globalUtilOptind]);
14776             globalUtilOptind++;
14777             if ( nConfMax < 0 )
14778                 goto usage;
14779             break;
14780         case 'L':
14781             if ( globalUtilOptind >= argc )
14782             {
14783                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
14784                 goto usage;
14785             }
14786             nLevelMax = atoi(argv[globalUtilOptind]);
14787             globalUtilOptind++;
14788             if ( nLevelMax < 0 )
14789                 goto usage;
14790             break;
14791         case 'b':
14792             fBalance ^= 1;
14793             break;
14794         case 'l':
14795             fUpdateLevel ^= 1;
14796             break;
14797         case 'c':
14798             fConstruct ^= 1;
14799             break;
14800         case 'v':
14801             fVerbose ^= 1;
14802             break;
14803         case 'h':
14804             goto usage;
14805         default:
14806             goto usage;
14807         }
14808     }
14809     if ( pNtk == NULL )
14810     {
14811         Abc_Print( -1, "Empty network.\n" );
14812         return 1;
14813     }
14814     if ( !Abc_NtkIsStrash(pNtk) )
14815     {
14816         Abc_Print( -1, "This command works only for strashed networks.\n" );
14817         return 1;
14818     }
14819     pNtkRes = Abc_NtkDChoice( pNtk, fBalance, fUpdateLevel, fConstruct, nConfMax, nLevelMax, fVerbose );
14820     if ( pNtkRes == NULL )
14821     {
14822         Abc_Print( -1, "Command has failed.\n" );
14823         return 0;
14824     }
14825     // replace the current network
14826     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
14827     return 0;
14828 
14829 usage:
14830     Abc_Print( -2, "usage: dchoice [-C num] [-L num] [-blcvh]\n" );
14831     Abc_Print( -2, "\t         performs partitioned choicing using new AIG package\n" );
14832     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", nConfMax );
14833     Abc_Print( -2, "\t-L num : the max level of nodes to consider (0 = not used) [default = %d]\n", nLevelMax );
14834     Abc_Print( -2, "\t-b     : toggle internal balancing [default = %s]\n", fBalance? "yes": "no" );
14835     Abc_Print( -2, "\t-l     : toggle updating level [default = %s]\n", fUpdateLevel? "yes": "no" );
14836     Abc_Print( -2, "\t-c     : toggle constructive computation of choices [default = %s]\n", fConstruct? "yes": "no" );
14837     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
14838     Abc_Print( -2, "\t-h     : print the command usage\n");
14839     return 1;
14840 }
14841 
14842 /**Function*************************************************************
14843 
14844   Synopsis    []
14845 
14846   Description []
14847 
14848   SideEffects []
14849 
14850   SeeAlso     []
14851 
14852 ***********************************************************************/
Abc_CommandDch(Abc_Frame_t * pAbc,int argc,char ** argv)14853 int Abc_CommandDch( Abc_Frame_t * pAbc, int argc, char ** argv )
14854 {
14855     Dch_Pars_t Pars, * pPars = &Pars;
14856     Abc_Ntk_t * pNtk, * pNtkRes;
14857     int c;
14858     extern Abc_Ntk_t * Abc_NtkDch( Abc_Ntk_t * pNtk, Dch_Pars_t * pPars );
14859 
14860     pNtk = Abc_FrameReadNtk(pAbc);
14861     // set defaults
14862     Dch_ManSetDefaultParams( pPars );
14863     Extra_UtilGetoptReset();
14864     while ( ( c = Extra_UtilGetopt( argc, argv, "WCSsptgcfrvh" ) ) != EOF )
14865     {
14866         switch ( c )
14867         {
14868         case 'W':
14869             if ( globalUtilOptind >= argc )
14870             {
14871                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
14872                 goto usage;
14873             }
14874             pPars->nWords = atoi(argv[globalUtilOptind]);
14875             globalUtilOptind++;
14876             if ( pPars->nWords < 0 )
14877                 goto usage;
14878             break;
14879         case 'C':
14880             if ( globalUtilOptind >= argc )
14881             {
14882                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
14883                 goto usage;
14884             }
14885             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
14886             globalUtilOptind++;
14887             if ( pPars->nBTLimit < 0 )
14888                 goto usage;
14889             break;
14890         case 'S':
14891             if ( globalUtilOptind >= argc )
14892             {
14893                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
14894                 goto usage;
14895             }
14896             pPars->nSatVarMax = atoi(argv[globalUtilOptind]);
14897             globalUtilOptind++;
14898             if ( pPars->nSatVarMax < 0 )
14899                 goto usage;
14900             break;
14901         case 's':
14902             pPars->fSynthesis ^= 1;
14903             break;
14904         case 'p':
14905             pPars->fPower ^= 1;
14906             break;
14907         case 't':
14908             pPars->fSimulateTfo ^= 1;
14909             break;
14910         case 'g':
14911             pPars->fUseGia ^= 1;
14912             break;
14913         case 'c':
14914             pPars->fUseCSat ^= 1;
14915             break;
14916         case 'f':
14917             pPars->fLightSynth ^= 1;
14918             break;
14919         case 'r':
14920             pPars->fSkipRedSupp ^= 1;
14921             break;
14922         case 'v':
14923             pPars->fVerbose ^= 1;
14924             break;
14925         case 'h':
14926             goto usage;
14927         default:
14928             goto usage;
14929         }
14930     }
14931     if ( pNtk == NULL )
14932     {
14933         Abc_Print( -1, "Empty network.\n" );
14934         return 1;
14935     }
14936     if ( !Abc_NtkIsStrash(pNtk) )
14937     {
14938         Abc_Print( -1, "This command works only for strashed networks.\n" );
14939         return 1;
14940     }
14941     pNtkRes = Abc_NtkDch( pNtk, pPars );
14942     if ( pNtkRes == NULL )
14943     {
14944         Abc_Print( -1, "Command has failed.\n" );
14945         return 0;
14946     }
14947     // replace the current network
14948     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
14949     return 0;
14950 
14951 usage:
14952     Abc_Print( -2, "usage: dch [-WCS num] [-sptgcfrvh]\n" );
14953     Abc_Print( -2, "\t         computes structural choices using a new approach\n" );
14954     Abc_Print( -2, "\t-W num : the max number of simulation words [default = %d]\n", pPars->nWords );
14955     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", pPars->nBTLimit );
14956     Abc_Print( -2, "\t-S num : the max number of SAT variables [default = %d]\n", pPars->nSatVarMax );
14957     Abc_Print( -2, "\t-s     : toggle synthesizing three snapshots [default = %s]\n", pPars->fSynthesis? "yes": "no" );
14958     Abc_Print( -2, "\t-p     : toggle power-aware rewriting [default = %s]\n", pPars->fPower? "yes": "no" );
14959     Abc_Print( -2, "\t-t     : toggle simulation of the TFO classes [default = %s]\n", pPars->fSimulateTfo? "yes": "no" );
14960     Abc_Print( -2, "\t-g     : toggle using GIA to prove equivalences [default = %s]\n", pPars->fUseGia? "yes": "no" );
14961     Abc_Print( -2, "\t-c     : toggle using circuit-based SAT vs. MiniSat [default = %s]\n", pPars->fUseCSat? "yes": "no" );
14962     Abc_Print( -2, "\t-f     : toggle using faster logic synthesis [default = %s]\n", pPars->fLightSynth? "yes": "no" );
14963     Abc_Print( -2, "\t-r     : toggle skipping choices with redundant support [default = %s]\n", pPars->fSkipRedSupp? "yes": "no" );
14964     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", pPars->fVerbose? "yes": "no" );
14965     Abc_Print( -2, "\t-h     : print the command usage\n");
14966     return 1;
14967 }
14968 
14969 /**Function*************************************************************
14970 
14971   Synopsis    []
14972 
14973   Description []
14974 
14975   SideEffects []
14976 
14977   SeeAlso     []
14978 
14979 ***********************************************************************/
Abc_CommandDrwsat(Abc_Frame_t * pAbc,int argc,char ** argv)14980 int Abc_CommandDrwsat( Abc_Frame_t * pAbc, int argc, char ** argv )
14981 {
14982     Abc_Ntk_t * pNtk, * pNtkRes;
14983     int fBalance, fVerbose, c;
14984 
14985     extern Abc_Ntk_t * Abc_NtkDrwsat( Abc_Ntk_t * pNtk, int fBalance, int fVerbose );
14986 
14987     pNtk = Abc_FrameReadNtk(pAbc);
14988     // set defaults
14989     fBalance = 0;
14990     fVerbose = 0;
14991     Extra_UtilGetoptReset();
14992     while ( ( c = Extra_UtilGetopt( argc, argv, "bvh" ) ) != EOF )
14993     {
14994         switch ( c )
14995         {
14996         case 'b':
14997             fBalance ^= 1;
14998             break;
14999         case 'v':
15000             fVerbose ^= 1;
15001             break;
15002         case 'h':
15003             goto usage;
15004         default:
15005             goto usage;
15006         }
15007     }
15008     if ( pNtk == NULL )
15009     {
15010         Abc_Print( -1, "Empty network.\n" );
15011         return 1;
15012     }
15013     if ( !Abc_NtkIsStrash(pNtk) )
15014     {
15015         Abc_Print( -1, "This command works only for strashed networks.\n" );
15016         return 1;
15017     }
15018     pNtkRes = Abc_NtkDrwsat( pNtk, fBalance, fVerbose );
15019     if ( pNtkRes == NULL )
15020     {
15021         Abc_Print( -1, "Command has failed.\n" );
15022         return 0;
15023     }
15024     // replace the current network
15025     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
15026     return 0;
15027 
15028 usage:
15029     Abc_Print( -2, "usage: drwsat [-bvh]\n" );
15030     Abc_Print( -2, "\t         performs combinational AIG optimization for SAT\n" );
15031     Abc_Print( -2, "\t-b     : toggle internal balancing [default = %s]\n", fBalance? "yes": "no" );
15032     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
15033     Abc_Print( -2, "\t-h     : print the command usage\n");
15034     return 1;
15035 }
15036 
15037 /**Function*************************************************************
15038 
15039   Synopsis    []
15040 
15041   Description []
15042 
15043   SideEffects []
15044 
15045   SeeAlso     []
15046 
15047 ***********************************************************************/
Abc_CommandIRewriteSeq(Abc_Frame_t * pAbc,int argc,char ** argv)15048 int Abc_CommandIRewriteSeq( Abc_Frame_t * pAbc, int argc, char ** argv )
15049 {
15050     Abc_Ntk_t * pNtk, * pNtkRes;
15051     int c, fUpdateLevel, fUseZeroCost, fVerbose;
15052     extern Abc_Ntk_t * Abc_NtkIvyRewriteSeq( Abc_Ntk_t * pNtk, int fUseZeroCost, int fVerbose );
15053 
15054     pNtk = Abc_FrameReadNtk(pAbc);
15055     // set defaults
15056     fUpdateLevel = 0;
15057     fUseZeroCost = 0;
15058     fVerbose     = 0;
15059     Extra_UtilGetoptReset();
15060     while ( ( c = Extra_UtilGetopt( argc, argv, "lzvh" ) ) != EOF )
15061     {
15062         switch ( c )
15063         {
15064         case 'l':
15065             fUpdateLevel ^= 1;
15066             break;
15067         case 'z':
15068             fUseZeroCost ^= 1;
15069             break;
15070         case 'v':
15071             fVerbose ^= 1;
15072             break;
15073         case 'h':
15074             goto usage;
15075         default:
15076             goto usage;
15077         }
15078     }
15079     if ( pNtk == NULL )
15080     {
15081         Abc_Print( -1, "Empty network.\n" );
15082         return 1;
15083     }
15084     if ( !Abc_NtkIsStrash(pNtk) )
15085     {
15086         Abc_Print( -1, "This command works only for strashed networks.\n" );
15087         return 1;
15088     }
15089 
15090     pNtkRes = Abc_NtkIvyRewriteSeq( pNtk, fUseZeroCost, fVerbose );
15091     if ( pNtkRes == NULL )
15092     {
15093         Abc_Print( -1, "Command has failed.\n" );
15094         return 0;
15095     }
15096     // replace the current network
15097     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
15098     return 0;
15099 
15100 usage:
15101     Abc_Print( -2, "usage: irws [-zvh]\n" );
15102     Abc_Print( -2, "\t         perform sequential AIG rewriting\n" );
15103 //    Abc_Print( -2, "\t-l     : toggle preserving the number of levels [default = %s]\n", fUpdateLevel? "yes": "no" );
15104     Abc_Print( -2, "\t-z     : toggle using zero-cost replacements [default = %s]\n", fUseZeroCost? "yes": "no" );
15105     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
15106     Abc_Print( -2, "\t-h     : print the command usage\n");
15107     return 1;
15108 }
15109 
15110 /**Function*************************************************************
15111 
15112   Synopsis    []
15113 
15114   Description []
15115 
15116   SideEffects []
15117 
15118   SeeAlso     []
15119 
15120 ***********************************************************************/
Abc_CommandIResyn(Abc_Frame_t * pAbc,int argc,char ** argv)15121 int Abc_CommandIResyn( Abc_Frame_t * pAbc, int argc, char ** argv )
15122 {
15123     Abc_Ntk_t * pNtk, * pNtkRes;
15124     int c, fUpdateLevel, fVerbose;
15125     extern Abc_Ntk_t * Abc_NtkIvyResyn( Abc_Ntk_t * pNtk, int fUpdateLevel, int fVerbose );
15126 
15127     pNtk = Abc_FrameReadNtk(pAbc);
15128     // set defaults
15129     fUpdateLevel = 1;
15130     fVerbose     = 0;
15131     Extra_UtilGetoptReset();
15132     while ( ( c = Extra_UtilGetopt( argc, argv, "lzvh" ) ) != EOF )
15133     {
15134         switch ( c )
15135         {
15136         case 'l':
15137             fUpdateLevel ^= 1;
15138             break;
15139         case 'v':
15140             fVerbose ^= 1;
15141             break;
15142         case 'h':
15143             goto usage;
15144         default:
15145             goto usage;
15146         }
15147     }
15148     if ( pNtk == NULL )
15149     {
15150         Abc_Print( -1, "Empty network.\n" );
15151         return 1;
15152     }
15153     if ( !Abc_NtkIsStrash(pNtk) )
15154     {
15155         Abc_Print( -1, "This command works only for strashed networks.\n" );
15156         return 1;
15157     }
15158 
15159     pNtkRes = Abc_NtkIvyResyn( pNtk, fUpdateLevel, fVerbose );
15160     if ( pNtkRes == NULL )
15161     {
15162         Abc_Print( -1, "Command has failed.\n" );
15163         return 0;
15164     }
15165     // replace the current network
15166     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
15167     return 0;
15168 
15169 usage:
15170     Abc_Print( -2, "usage: iresyn [-lvh]\n" );
15171     Abc_Print( -2, "\t         performs combinational resynthesis\n" );
15172     Abc_Print( -2, "\t-l     : toggle preserving the number of levels [default = %s]\n", fUpdateLevel? "yes": "no" );
15173     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
15174     Abc_Print( -2, "\t-h     : print the command usage\n");
15175     return 1;
15176 }
15177 
15178 /**Function*************************************************************
15179 
15180   Synopsis    []
15181 
15182   Description []
15183 
15184   SideEffects []
15185 
15186   SeeAlso     []
15187 
15188 ***********************************************************************/
Abc_CommandISat(Abc_Frame_t * pAbc,int argc,char ** argv)15189 int Abc_CommandISat( Abc_Frame_t * pAbc, int argc, char ** argv )
15190 {
15191     Abc_Ntk_t * pNtk, * pNtkRes;
15192     int c, fUpdateLevel, fVerbose;
15193     int nConfLimit;
15194 
15195     extern Abc_Ntk_t * Abc_NtkIvySat( Abc_Ntk_t * pNtk, int nConfLimit, int fVerbose );
15196 
15197     pNtk = Abc_FrameReadNtk(pAbc);
15198     // set defaults
15199     nConfLimit   = 100000;
15200     fUpdateLevel = 1;
15201     fVerbose     = 0;
15202     Extra_UtilGetoptReset();
15203     while ( ( c = Extra_UtilGetopt( argc, argv, "Clzvh" ) ) != EOF )
15204     {
15205         switch ( c )
15206         {
15207         case 'C':
15208             if ( globalUtilOptind >= argc )
15209             {
15210                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
15211                 goto usage;
15212             }
15213             nConfLimit = atoi(argv[globalUtilOptind]);
15214             globalUtilOptind++;
15215             if ( nConfLimit < 0 )
15216                 goto usage;
15217             break;
15218         case 'l':
15219             fUpdateLevel ^= 1;
15220             break;
15221         case 'v':
15222             fVerbose ^= 1;
15223             break;
15224         case 'h':
15225             goto usage;
15226         default:
15227             goto usage;
15228         }
15229     }
15230     if ( pNtk == NULL )
15231     {
15232         Abc_Print( -1, "Empty network.\n" );
15233         return 1;
15234     }
15235     if ( !Abc_NtkIsStrash(pNtk) )
15236     {
15237         Abc_Print( -1, "This command works only for strashed networks.\n" );
15238         return 1;
15239     }
15240 
15241     pNtkRes = Abc_NtkIvySat( pNtk, nConfLimit, fVerbose );
15242     if ( pNtkRes == NULL )
15243     {
15244         Abc_Print( -1, "Command has failed.\n" );
15245         return 0;
15246     }
15247     // replace the current network
15248     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
15249     return 0;
15250 
15251 usage:
15252     Abc_Print( -2, "usage: isat [-C num] [-vh]\n" );
15253     Abc_Print( -2, "\t         tries to prove the miter constant 0\n" );
15254     Abc_Print( -2, "\t-C num : limit on the number of conflicts [default = %d]\n",    nConfLimit );
15255 //    Abc_Print( -2, "\t-l     : toggle preserving the number of levels [default = %s]\n", fUpdateLevel? "yes": "no" );
15256     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
15257     Abc_Print( -2, "\t-h     : print the command usage\n");
15258     return 1;
15259 }
15260 
15261 /**Function*************************************************************
15262 
15263   Synopsis    []
15264 
15265   Description []
15266 
15267   SideEffects []
15268 
15269   SeeAlso     []
15270 
15271 ***********************************************************************/
Abc_CommandIFraig(Abc_Frame_t * pAbc,int argc,char ** argv)15272 int Abc_CommandIFraig( Abc_Frame_t * pAbc, int argc, char ** argv )
15273 {
15274     Abc_Ntk_t * pNtk, * pNtkRes;
15275     int c, fProve, fVerbose, fDoSparse;
15276     int nConfLimit;
15277     int nPartSize;
15278     int nLevelMax;
15279 
15280     extern Abc_Ntk_t * Abc_NtkIvyFraig( Abc_Ntk_t * pNtk, int nConfLimit, int fDoSparse, int fProve, int fTransfer, int fVerbose );
15281     extern Abc_Ntk_t * Abc_NtkDarFraigPart( Abc_Ntk_t * pNtk, int nPartSize, int nConfLimit, int nLevelMax, int fVerbose );
15282 
15283     pNtk = Abc_FrameReadNtk(pAbc);
15284     // set defaults
15285     nPartSize    = 0;
15286     nLevelMax    = 0;
15287     nConfLimit   = 100;
15288     fDoSparse    = 0;
15289     fProve       = 0;
15290     fVerbose     = 0;
15291     Extra_UtilGetoptReset();
15292     while ( ( c = Extra_UtilGetopt( argc, argv, "PCLspvh" ) ) != EOF )
15293     {
15294         switch ( c )
15295         {
15296         case 'P':
15297             if ( globalUtilOptind >= argc )
15298             {
15299                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
15300                 goto usage;
15301             }
15302             nPartSize = atoi(argv[globalUtilOptind]);
15303             globalUtilOptind++;
15304             if ( nPartSize < 0 )
15305                 goto usage;
15306             break;
15307         case 'C':
15308             if ( globalUtilOptind >= argc )
15309             {
15310                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
15311                 goto usage;
15312             }
15313             nConfLimit = atoi(argv[globalUtilOptind]);
15314             globalUtilOptind++;
15315             if ( nConfLimit < 0 )
15316                 goto usage;
15317             break;
15318          case 'L':
15319             if ( globalUtilOptind >= argc )
15320             {
15321                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
15322                 goto usage;
15323             }
15324             nLevelMax = atoi(argv[globalUtilOptind]);
15325             globalUtilOptind++;
15326             if ( nLevelMax < 0 )
15327                 goto usage;
15328             break;
15329         case 's':
15330             fDoSparse ^= 1;
15331             break;
15332         case 'p':
15333             fProve ^= 1;
15334             break;
15335         case 'v':
15336             fVerbose ^= 1;
15337             break;
15338         case 'h':
15339             goto usage;
15340         default:
15341             goto usage;
15342         }
15343     }
15344     if ( pNtk == NULL )
15345     {
15346         Abc_Print( -1, "Empty network.\n" );
15347         return 1;
15348     }
15349     if ( !Abc_NtkIsStrash(pNtk) )
15350     {
15351         Abc_Print( -1, "This command works only for strashed networks.\n" );
15352         return 1;
15353     }
15354 
15355     if ( nPartSize > 0 )
15356         pNtkRes = Abc_NtkDarFraigPart( pNtk, nPartSize, nConfLimit, nLevelMax, fVerbose );
15357     else
15358         pNtkRes = Abc_NtkIvyFraig( pNtk, nConfLimit, fDoSparse, fProve, 0, fVerbose );
15359     if ( pNtkRes == NULL )
15360     {
15361         Abc_Print( -1, "Command has failed.\n" );
15362         return 0;
15363     }
15364     // replace the current network
15365     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
15366     return 0;
15367 
15368 usage:
15369     Abc_Print( -2, "usage: ifraig [-P num] [-C num] [-L num] [-spvh]\n" );
15370     Abc_Print( -2, "\t         performs fraiging using a new method\n" );
15371     Abc_Print( -2, "\t-P num : partition size (0 = partitioning is not used) [default = %d]\n", nPartSize );
15372     Abc_Print( -2, "\t-C num : limit on the number of conflicts [default = %d]\n", nConfLimit );
15373     Abc_Print( -2, "\t-L num : limit on node level to fraig (0 = fraig all nodes) [default = %d]\n", nLevelMax );
15374     Abc_Print( -2, "\t-s     : toggle considering sparse functions [default = %s]\n", fDoSparse? "yes": "no" );
15375     Abc_Print( -2, "\t-p     : toggle proving the miter outputs [default = %s]\n", fProve? "yes": "no" );
15376     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
15377     Abc_Print( -2, "\t-h     : print the command usage\n");
15378     return 1;
15379 }
15380 
15381 /**Function*************************************************************
15382 
15383   Synopsis    []
15384 
15385   Description []
15386 
15387   SideEffects []
15388 
15389   SeeAlso     []
15390 
15391 ***********************************************************************/
Abc_CommandDFraig(Abc_Frame_t * pAbc,int argc,char ** argv)15392 int Abc_CommandDFraig( Abc_Frame_t * pAbc, int argc, char ** argv )
15393 {
15394     Abc_Ntk_t * pNtk, * pNtkRes;
15395     int c, nConfLimit, fDoSparse, fProve, fSpeculate, fChoicing, fVerbose;
15396 
15397     extern Abc_Ntk_t * Abc_NtkDarFraig( Abc_Ntk_t * pNtk, int nConfLimit, int fDoSparse, int fProve, int fTransfer, int fSpeculate, int fChoicing, int fVerbose );
15398 
15399     pNtk = Abc_FrameReadNtk(pAbc);
15400     // set defaults
15401     nConfLimit   = 100;
15402     fDoSparse    = 1;
15403     fProve       = 0;
15404     fSpeculate   = 0;
15405     fChoicing    = 0;
15406     fVerbose     = 0;
15407     Extra_UtilGetoptReset();
15408     while ( ( c = Extra_UtilGetopt( argc, argv, "Csprcvh" ) ) != EOF )
15409     {
15410         switch ( c )
15411         {
15412         case 'C':
15413             if ( globalUtilOptind >= argc )
15414             {
15415                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
15416                 goto usage;
15417             }
15418             nConfLimit = atoi(argv[globalUtilOptind]);
15419             globalUtilOptind++;
15420             if ( nConfLimit < 0 )
15421                 goto usage;
15422             break;
15423         case 's':
15424             fDoSparse ^= 1;
15425             break;
15426         case 'p':
15427             fProve ^= 1;
15428             break;
15429         case 'r':
15430             fSpeculate ^= 1;
15431             break;
15432         case 'c':
15433             fChoicing ^= 1;
15434             break;
15435         case 'v':
15436             fVerbose ^= 1;
15437             break;
15438         case 'h':
15439             goto usage;
15440         default:
15441             goto usage;
15442         }
15443     }
15444     if ( pNtk == NULL )
15445     {
15446         Abc_Print( -1, "Empty network.\n" );
15447         return 1;
15448     }
15449     if ( !Abc_NtkIsStrash(pNtk) )
15450     {
15451         Abc_Print( -1, "This command works only for strashed networks.\n" );
15452         return 1;
15453     }
15454 
15455     pNtkRes = Abc_NtkDarFraig( pNtk, nConfLimit, fDoSparse, fProve, 0, fSpeculate, fChoicing, fVerbose );
15456     if ( pNtkRes == NULL )
15457     {
15458         Abc_Print( -1, "Command has failed.\n" );
15459         return 0;
15460     }
15461     // replace the current network
15462     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
15463     return 0;
15464 
15465 usage:
15466     Abc_Print( -2, "usage: dfraig [-C num] [-sprcvh]\n" );
15467     Abc_Print( -2, "\t         performs fraiging using a new method\n" );
15468     Abc_Print( -2, "\t-C num : limit on the number of conflicts [default = %d]\n", nConfLimit );
15469     Abc_Print( -2, "\t-s     : toggle considering sparse functions [default = %s]\n", fDoSparse? "yes": "no" );
15470     Abc_Print( -2, "\t-p     : toggle proving the miter outputs [default = %s]\n", fProve? "yes": "no" );
15471     Abc_Print( -2, "\t-r     : toggle speculative reduction [default = %s]\n", fSpeculate? "yes": "no" );
15472     Abc_Print( -2, "\t-c     : toggle accumulation of choices [default = %s]\n", fChoicing? "yes": "no" );
15473     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
15474     Abc_Print( -2, "\t-h     : print the command usage\n");
15475     return 1;
15476 }
15477 
15478 /**Function*************************************************************
15479 
15480   Synopsis    []
15481 
15482   Description []
15483 
15484   SideEffects []
15485 
15486   SeeAlso     []
15487 
15488 ***********************************************************************/
Abc_CommandCSweep(Abc_Frame_t * pAbc,int argc,char ** argv)15489 int Abc_CommandCSweep( Abc_Frame_t * pAbc, int argc, char ** argv )
15490 {
15491     Abc_Ntk_t * pNtk, * pNtkRes;
15492     int c, nCutsMax, nLeafMax, fVerbose;
15493 
15494     extern Abc_Ntk_t * Abc_NtkCSweep( Abc_Ntk_t * pNtk, int nCutsMax, int nLeafMax, int fVerbose );
15495 
15496     pNtk = Abc_FrameReadNtk(pAbc);
15497     // set defaults
15498     nCutsMax  =  8;
15499     nLeafMax  =  6;
15500     fVerbose  =  0;
15501     Extra_UtilGetoptReset();
15502     while ( ( c = Extra_UtilGetopt( argc, argv, "CKvh" ) ) != EOF )
15503     {
15504         switch ( c )
15505         {
15506         case 'C':
15507             if ( globalUtilOptind >= argc )
15508             {
15509                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
15510                 goto usage;
15511             }
15512             nCutsMax = atoi(argv[globalUtilOptind]);
15513             globalUtilOptind++;
15514             if ( nCutsMax < 0 )
15515                 goto usage;
15516             break;
15517         case 'K':
15518             if ( globalUtilOptind >= argc )
15519             {
15520                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
15521                 goto usage;
15522             }
15523             nLeafMax = atoi(argv[globalUtilOptind]);
15524             globalUtilOptind++;
15525             if ( nLeafMax < 0 )
15526                 goto usage;
15527             break;
15528         case 'v':
15529             fVerbose ^= 1;
15530             break;
15531         case 'h':
15532             goto usage;
15533         default:
15534             goto usage;
15535         }
15536     }
15537     if ( pNtk == NULL )
15538     {
15539         Abc_Print( -1, "Empty network.\n" );
15540         return 1;
15541     }
15542 
15543     if ( nCutsMax < 2 )
15544     {
15545         Abc_Print( -1, "The number of cuts cannot be less than 2.\n" );
15546         return 1;
15547     }
15548 
15549     if ( nLeafMax < 3 || nLeafMax > 16 )
15550     {
15551         Abc_Print( -1, "The number of leaves is infeasible.\n" );
15552         return 1;
15553     }
15554     if ( !Abc_NtkIsStrash(pNtk) )
15555     {
15556         Abc_Print( -1, "This command works only for strashed networks.\n" );
15557         return 1;
15558     }
15559 
15560     pNtkRes = Abc_NtkCSweep( pNtk, nCutsMax, nLeafMax, fVerbose );
15561     if ( pNtkRes == NULL )
15562     {
15563         Abc_Print( -1, "Command has failed.\n" );
15564         return 0;
15565     }
15566     // replace the current network
15567     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
15568     return 0;
15569 
15570 usage:
15571     Abc_Print( -2, "usage: csweep [-C num] [-K num] [-vh]\n" );
15572     Abc_Print( -2, "\t         performs cut sweeping using a new method\n" );
15573     Abc_Print( -2, "\t-C num : limit on the number of cuts (C >= 2) [default = %d]\n", nCutsMax );
15574     Abc_Print( -2, "\t-K num : limit on the cut size (3 <= K <= 16) [default = %d]\n", nLeafMax );
15575     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
15576     Abc_Print( -2, "\t-h     : print the command usage\n");
15577     return 1;
15578 }
15579 
15580 /**Function*************************************************************
15581 
15582   Synopsis    []
15583 
15584   Description []
15585 
15586   SideEffects []
15587 
15588   SeeAlso     []
15589 
15590 ***********************************************************************/
Abc_CommandIProve(Abc_Frame_t * pAbc,int argc,char ** argv)15591 int Abc_CommandIProve( Abc_Frame_t * pAbc, int argc, char ** argv )
15592 {
15593     Prove_Params_t Params, * pParams = &Params;
15594     Abc_Ntk_t * pNtk, * pNtkTemp;
15595     int c, RetValue, iOut = -1;
15596     char * pLogFileName = NULL;
15597     abctime clk;
15598 
15599     extern int Abc_NtkIvyProve( Abc_Ntk_t ** ppNtk, void * pPars );
15600 
15601     pNtk = Abc_FrameReadNtk(pAbc);
15602     // set defaults
15603     Prove_ParamsSetDefault( pParams );
15604     pParams->fUseRewriting = 1;
15605     pParams->fVerbose      = 0;
15606     Extra_UtilGetoptReset();
15607     while ( ( c = Extra_UtilGetopt( argc, argv, "NCFGMILrfbvh" ) ) != EOF )
15608     {
15609         switch ( c )
15610         {
15611         case 'N':
15612             if ( globalUtilOptind >= argc )
15613             {
15614                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
15615                 goto usage;
15616             }
15617             pParams->nItersMax = atoi(argv[globalUtilOptind]);
15618             globalUtilOptind++;
15619             if ( pParams->nItersMax < 0 )
15620                 goto usage;
15621             break;
15622         case 'C':
15623             if ( globalUtilOptind >= argc )
15624             {
15625                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
15626                 goto usage;
15627             }
15628             pParams->nMiteringLimitStart = atoi(argv[globalUtilOptind]);
15629             globalUtilOptind++;
15630             if ( pParams->nMiteringLimitStart < 0 )
15631                 goto usage;
15632             break;
15633         case 'F':
15634             if ( globalUtilOptind >= argc )
15635             {
15636                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
15637                 goto usage;
15638             }
15639             pParams->nFraigingLimitStart = atoi(argv[globalUtilOptind]);
15640             globalUtilOptind++;
15641             if ( pParams->nFraigingLimitStart < 0 )
15642                 goto usage;
15643             break;
15644         case 'G':
15645             if ( globalUtilOptind >= argc )
15646             {
15647                 Abc_Print( -1, "Command line switch \"-G\" should be followed by an integer.\n" );
15648                 goto usage;
15649             }
15650             pParams->nFraigingLimitMulti = (float)atoi(argv[globalUtilOptind]);
15651             globalUtilOptind++;
15652             if ( pParams->nFraigingLimitMulti < 0 )
15653                 goto usage;
15654             break;
15655         case 'M':
15656             if ( globalUtilOptind >= argc )
15657             {
15658                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
15659                 goto usage;
15660             }
15661             pParams->nMiteringLimitLast = atoi(argv[globalUtilOptind]);
15662             globalUtilOptind++;
15663             if ( pParams->nMiteringLimitLast < 0 )
15664                 goto usage;
15665             break;
15666         case 'I':
15667             if ( globalUtilOptind >= argc )
15668             {
15669                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
15670                 goto usage;
15671             }
15672             pParams->nTotalInspectLimit = atoi(argv[globalUtilOptind]);
15673             globalUtilOptind++;
15674             if ( pParams->nTotalInspectLimit < 0 )
15675                 goto usage;
15676             break;
15677         case 'L':
15678             if ( globalUtilOptind >= argc )
15679             {
15680                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
15681                 goto usage;
15682             }
15683             pLogFileName = argv[globalUtilOptind];
15684             globalUtilOptind++;
15685             break;
15686         case 'r':
15687             pParams->fUseRewriting ^= 1;
15688             break;
15689         case 'f':
15690             pParams->fUseFraiging ^= 1;
15691             break;
15692         case 'b':
15693             pParams->fUseBdds ^= 1;
15694             break;
15695         case 'v':
15696             pParams->fVerbose ^= 1;
15697             break;
15698         case 'h':
15699             goto usage;
15700         default:
15701             goto usage;
15702         }
15703     }
15704     if ( pNtk == NULL )
15705     {
15706         Abc_Print( -1, "Empty network.\n" );
15707         return 1;
15708     }
15709 
15710     if ( Abc_NtkLatchNum(pNtk) > 0 )
15711     {
15712         Abc_Print( -1, "The network has registers. Use \"dprove\".\n" );
15713         return 1;
15714     }
15715 
15716     clk = Abc_Clock();
15717 
15718     if ( Abc_NtkIsStrash(pNtk) )
15719         pNtkTemp = Abc_NtkDup( pNtk );
15720     else
15721         pNtkTemp = Abc_NtkStrash( pNtk, 0, 0, 0 );
15722 
15723     RetValue = Abc_NtkIvyProve( &pNtkTemp, pParams );
15724 
15725     // verify that the pattern is correct
15726     if ( RetValue == 0 )
15727     {
15728         Abc_Obj_t * pObj;
15729         int i;
15730         int * pSimInfo = Abc_NtkVerifySimulatePattern( pNtk, pNtkTemp->pModel );
15731         Abc_NtkForEachCo( pNtk, pObj, i )
15732             if ( pSimInfo[i] == 1 )
15733             {
15734                 iOut = i;
15735                 break;
15736             }
15737         if ( i == Abc_NtkCoNum(pNtk) )
15738             Abc_Print( 1, "ERROR in Abc_NtkMiterProve(): Generated counter-example is invalid.\n" );
15739         ABC_FREE( pSimInfo );
15740     }
15741     pAbc->Status = RetValue;
15742     if ( RetValue == -1 )
15743         Abc_Print( 1, "UNDECIDED      " );
15744     else if ( RetValue == 0 )
15745         Abc_Print( 1, "SATISFIABLE (output = %d) ", iOut );
15746     else
15747         Abc_Print( 1, "UNSATISFIABLE  " );
15748     //Abc_Print( -1, "\n" );
15749 
15750     Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
15751     // replace the current network
15752     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkTemp );
15753     // update counter example
15754     if ( RetValue == 0 && Abc_NtkLatchNum(pNtkTemp) == 0 )
15755     {
15756         Abc_Cex_t * pCex = Abc_CexDeriveFromCombModel( pNtkTemp->pModel, Abc_NtkPiNum(pNtkTemp), 0, iOut );
15757         Abc_FrameReplaceCex( pAbc, &pCex );
15758     }
15759     if ( pLogFileName )
15760         Abc_NtkWriteLogFile( pLogFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, "iprove" );
15761     return 0;
15762 
15763 usage:
15764     Abc_Print( -2, "usage: iprove [-NCFGMI num] [-L file] [-rfbvh]\n" );
15765     Abc_Print( -2, "\t         performs CEC using a new method\n" );
15766     Abc_Print( -2, "\t-N num : max number of iterations [default = %d]\n", pParams->nItersMax );
15767     Abc_Print( -2, "\t-C num : max starting number of conflicts in mitering [default = %d]\n", pParams->nMiteringLimitStart );
15768     Abc_Print( -2, "\t-F num : max starting number of conflicts in fraiging [default = %d]\n", pParams->nFraigingLimitStart );
15769     Abc_Print( -2, "\t-G num : multiplicative coefficient for fraiging [default = %d]\n", (int)pParams->nFraigingLimitMulti );
15770     Abc_Print( -2, "\t-M num : max last-gasp number of conflicts in mitering [default = %d]\n", pParams->nMiteringLimitLast );
15771     Abc_Print( -2, "\t-I num : max number of clause inspections in all SAT calls [default = %d]\n", (int)pParams->nTotalInspectLimit );
15772     Abc_Print( -2, "\t-L file: the log file name [default = %s]\n",                            pLogFileName ? pLogFileName : "no logging" );
15773     Abc_Print( -2, "\t-r     : toggle the use of rewriting [default = %s]\n", pParams->fUseRewriting? "yes": "no" );
15774     Abc_Print( -2, "\t-f     : toggle the use of FRAIGing [default = %s]\n", pParams->fUseFraiging? "yes": "no" );
15775     Abc_Print( -2, "\t-b     : toggle the use of BDDs [default = %s]\n", pParams->fUseBdds? "yes": "no" );
15776     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", pParams->fVerbose? "yes": "no" );
15777     Abc_Print( -2, "\t-h     : print the command usage\n");
15778     return 1;
15779 }
15780 
15781 /**Function*************************************************************
15782 
15783   Synopsis    []
15784 
15785   Description []
15786 
15787   SideEffects []
15788 
15789   SeeAlso     []
15790 
15791 ***********************************************************************/
15792 /*
15793 int Abc_CommandHaig( Abc_Frame_t * pAbc, int argc, char ** argv )
15794 {
15795     FILE * stdout, * pErr;
15796     Abc_Ntk_t * pNtk, * pNtkRes;
15797     int c;
15798     int nIters;
15799     int nSteps;
15800     int fRetimingOnly;
15801     int fAddBugs;
15802     int fUseCnf;
15803     int fVerbose;
15804 
15805     extern Abc_Ntk_t * Abc_NtkDarHaigRecord( Abc_Ntk_t * pNtk, int nIters, int nSteps, int fRetimingOnly, int fAddBugs, int fUseCnf, int fVerbose );
15806 
15807     pNtk = Abc_FrameReadNtk(pAbc);
15808 
15809 
15810 
15811     // set defaults
15812     nIters        = 3;
15813     nSteps        = 3000;
15814     fRetimingOnly = 0;
15815     fAddBugs      = 0;
15816     fUseCnf       = 0;
15817     fVerbose      = 0;
15818     Extra_UtilGetoptReset();
15819     while ( ( c = Extra_UtilGetopt( argc, argv, "ISrbcvh" ) ) != EOF )
15820     {
15821         switch ( c )
15822         {
15823         case 'I':
15824             if ( globalUtilOptind >= argc )
15825             {
15826                 Abc_Print( -1, "Command line switch \"-I\" should be followed by a positive integer.\n" );
15827                 goto usage;
15828             }
15829             nIters = atoi(argv[globalUtilOptind]);
15830             globalUtilOptind++;
15831             if ( nIters < 0 )
15832                 goto usage;
15833             break;
15834         case 'S':
15835             if ( globalUtilOptind >= argc )
15836             {
15837                 Abc_Print( -1, "Command line switch \"-S\" should be followed by a positive integer.\n" );
15838                 goto usage;
15839             }
15840             nSteps = atoi(argv[globalUtilOptind]);
15841             globalUtilOptind++;
15842             if ( nSteps < 0 )
15843                 goto usage;
15844             break;
15845         case 'r':
15846             fRetimingOnly ^= 1;
15847             break;
15848         case 'b':
15849             fAddBugs ^= 1;
15850             break;
15851         case 'c':
15852             fUseCnf ^= 1;
15853             break;
15854         case 'v':
15855             fUseCnf ^= 1;
15856             break;
15857         case 'h':
15858             goto usage;
15859         default:
15860             goto usage;
15861         }
15862     }
15863     if ( pNtk == NULL )
15864     {
15865         Abc_Print( -1, "Empty network.\n" );
15866         return 1;
15867     }
15868     if ( !Abc_NtkIsStrash(pNtk) )
15869     {
15870         Abc_Print( -1, "This command works only for strashed networks.\n" );
15871         return 1;
15872     }
15873 
15874     pNtkRes = Abc_NtkDarHaigRecord( pNtk, nIters, nSteps, fRetimingOnly, fAddBugs, fUseCnf, fVerbose );
15875     if ( pNtkRes == NULL )
15876     {
15877         Abc_Print( -1, "Command has failed.\n" );
15878         return 0;
15879     }
15880     // replace the current network
15881     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
15882     return 0;
15883 
15884 usage:
15885     Abc_Print( -2, "usage: haig [-IS num] [-rbcvh]\n" );
15886     Abc_Print( -2, "\t         run a few rounds of comb+seq synthesis to test HAIG recording\n" );
15887     Abc_Print( -2, "\t         the current network is set to be the result of synthesis performed\n" );
15888     Abc_Print( -2, "\t         (this network can be verified using command \"dsec\")\n" );
15889     Abc_Print( -2, "\t         HAIG is written out into the file \"haig.blif\"\n" );
15890     Abc_Print( -2, "\t         (this HAIG can be proved using \"r haig.blif; st; dprove -abc -F 16\")\n" );
15891     Abc_Print( -2, "\t-I num : the number of rounds of comb+seq synthesis [default = %d]\n", nIters );
15892     Abc_Print( -2, "\t-S num : the number of forward retiming moves performed [default = %d]\n", nSteps );
15893     Abc_Print( -2, "\t-r     : toggle the use of retiming only [default = %s]\n", fRetimingOnly? "yes": "no" );
15894     Abc_Print( -2, "\t-b     : toggle bug insertion [default = %s]\n", fAddBugs? "yes": "no" );
15895     Abc_Print( -2, "\t-c     : enable CNF-based proof (no speculative reduction) [default = %s]\n", fUseCnf? "yes": "no" );
15896     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
15897     Abc_Print( -2, "\t-h     : print the command usage\n");
15898     return 1;
15899 }
15900 */
15901 
15902 /**Function*************************************************************
15903 
15904   Synopsis    []
15905 
15906   Description []
15907 
15908   SideEffects []
15909 
15910   SeeAlso     []
15911 
15912 ***********************************************************************/
Abc_CommandQbf(Abc_Frame_t * pAbc,int argc,char ** argv)15913 int Abc_CommandQbf( Abc_Frame_t * pAbc, int argc, char ** argv )
15914 {
15915     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
15916     int c;
15917     int nPars;
15918     int nIters;
15919     int fDumpCnf;
15920     int fVerbose;
15921 
15922     extern void Abc_NtkQbf( Abc_Ntk_t * pNtk, int nPars, int nIters, int fDumpCnf, int fVerbose );
15923     // set defaults
15924     nPars    =  -1;
15925     nIters   = 500;
15926     fDumpCnf =   0;
15927     fVerbose =   0;
15928     Extra_UtilGetoptReset();
15929     while ( ( c = Extra_UtilGetopt( argc, argv, "PIdvh" ) ) != EOF )
15930     {
15931         switch ( c )
15932         {
15933         case 'P':
15934             if ( globalUtilOptind >= argc )
15935             {
15936                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
15937                 goto usage;
15938             }
15939             nPars = atoi(argv[globalUtilOptind]);
15940             globalUtilOptind++;
15941             if ( nPars < 0 )
15942                 goto usage;
15943             break;
15944         case 'I':
15945             if ( globalUtilOptind >= argc )
15946             {
15947                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
15948                 goto usage;
15949             }
15950             nIters = atoi(argv[globalUtilOptind]);
15951             globalUtilOptind++;
15952             if ( nIters < 0 )
15953                 goto usage;
15954             break;
15955         case 'd':
15956             fDumpCnf ^= 1;
15957             break;
15958         case 'v':
15959             fVerbose ^= 1;
15960             break;
15961         case 'h':
15962             goto usage;
15963         default:
15964             goto usage;
15965         }
15966     }
15967     if ( pNtk == NULL )
15968     {
15969         Abc_Print( -1, "Empty network.\n" );
15970         return 1;
15971     }
15972     if ( !Abc_NtkIsComb(pNtk) )
15973     {
15974         Abc_Print( -1, "Works only for combinational networks.\n" );
15975         return 1;
15976     }
15977     if ( Abc_NtkPoNum(pNtk) != 1 )
15978     {
15979         Abc_Print( -1, "The miter should have one primary output.\n" );
15980         return 1;
15981     }
15982     if ( !(nPars > 0 && nPars < Abc_NtkPiNum(pNtk)) )
15983     {
15984         Abc_Print( -1, "The number of parameter variables is invalid (should be > 0 and < PI num).\n" );
15985         return 1;
15986     }
15987     if ( Abc_NtkIsStrash(pNtk) )
15988         Abc_NtkQbf( pNtk, nPars, nIters, fDumpCnf, fVerbose );
15989     else
15990     {
15991         pNtk = Abc_NtkStrash( pNtk, 0, 1, 0 );
15992         Abc_NtkQbf( pNtk, nPars, nIters, fDumpCnf, fVerbose );
15993         Abc_NtkDelete( pNtk );
15994     }
15995     return 0;
15996 
15997 usage:
15998     Abc_Print( -2, "usage: qbf [-PI num] [-dvh]\n" );
15999     Abc_Print( -2, "\t         solves QBF problem EpVxM(p,x)\n" );
16000     Abc_Print( -2, "\t-P num : number of parameters p (should be the first PIs) [default = %d]\n", nPars );
16001     Abc_Print( -2, "\t-I num : quit after the given iteration even if unsolved [default = %d]\n", nIters );
16002     Abc_Print( -2, "\t-d     : toggle dumping QDIMACS file instead of solving [default = %s]\n", fDumpCnf? "yes": "no" );
16003     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
16004     Abc_Print( -2, "\t-h     : print the command usage\n");
16005     return 1;
16006 }
16007 
16008 /**Function*************************************************************
16009 
16010   Synopsis    []
16011 
16012   Description []
16013 
16014   SideEffects []
16015 
16016   SeeAlso     []
16017 
16018 ***********************************************************************/
Abc_CommandNpnLoad(Abc_Frame_t * pAbc,int argc,char ** argv)16019 int Abc_CommandNpnLoad( Abc_Frame_t * pAbc, int argc, char ** argv )
16020 {
16021     extern void Npn_ManLoad( char * pFileName );
16022     char * pFileName;
16023     int c;
16024     Extra_UtilGetoptReset();
16025     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
16026     {
16027         switch ( c )
16028         {
16029         case 'h':
16030             goto usage;
16031         default:
16032             goto usage;
16033         }
16034     }
16035     if ( argc != globalUtilOptind + 1 )
16036         goto usage;
16037     pFileName = argv[globalUtilOptind];
16038     Npn_ManLoad( pFileName );
16039     return 0;
16040 
16041 usage:
16042     Abc_Print( -2, "usage: npnload <filename>\n" );
16043     Abc_Print( -2, "\t         loads previously saved 6-input function library from file\n" );
16044     Abc_Print( -2, "\t-h     : print the command usage\n");
16045     return 1;
16046 }
16047 
16048 /**Function*************************************************************
16049 
16050   Synopsis    []
16051 
16052   Description []
16053 
16054   SideEffects []
16055 
16056   SeeAlso     []
16057 
16058 ***********************************************************************/
Abc_CommandNpnSave(Abc_Frame_t * pAbc,int argc,char ** argv)16059 int Abc_CommandNpnSave( Abc_Frame_t * pAbc, int argc, char ** argv )
16060 {
16061     extern void Npn_ManSave( char * pFileName );
16062     char * pFileName;
16063     int c;
16064     Extra_UtilGetoptReset();
16065     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
16066     {
16067         switch ( c )
16068         {
16069         case 'h':
16070             goto usage;
16071         default:
16072             goto usage;
16073         }
16074     }
16075     if ( argc != globalUtilOptind + 1 )
16076         goto usage;
16077     pFileName = argv[globalUtilOptind];
16078     Npn_ManSave( pFileName );
16079     return 0;
16080 
16081 usage:
16082     Abc_Print( -2, "usage: npnsave <filename>\n" );
16083     Abc_Print( -2, "\t         saves current 6-input function library into file\n" );
16084     Abc_Print( -2, "\t-h     : print the command usage\n");
16085     return 1;
16086 }
16087 
16088 
16089 /**Function*************************************************************
16090 
16091   Synopsis    []
16092 
16093   Description []
16094 
16095   SideEffects []
16096 
16097   SeeAlso     []
16098 
16099 ***********************************************************************/
Abc_CommandSendAig(Abc_Frame_t * pAbc,int argc,char ** argv)16100 int Abc_CommandSendAig( Abc_Frame_t * pAbc, int argc, char ** argv )
16101 {
16102 //    const int BRIDGE_NETLIST = 106;
16103 //    const int BRIDGE_ABS_NETLIST = 107;
16104 
16105     int c, fAndSpace = 1, fAbsNetlist = 0;
16106     Extra_UtilGetoptReset();
16107     while ( ( c = Extra_UtilGetopt( argc, argv, "ah" ) ) != EOF )
16108     {
16109         switch ( c )
16110         {
16111         case 'a':
16112             fAndSpace ^= 1;
16113             break;
16114         case 'b':
16115             fAbsNetlist ^= 1;
16116             break;
16117         case 'h':
16118             goto usage;
16119         default:
16120             goto usage;
16121         }
16122     }
16123     if ( !Abc_FrameIsBridgeMode() )
16124     {
16125         Abc_Print( -1, "The bridge mode is not available.\n" );
16126         return 1;
16127     }
16128     if ( fAndSpace )
16129     {
16130         if ( pAbc->pGia == NULL )
16131         {
16132             Abc_Print( -1, "There is no AIG in the &-space.\n" );
16133             return 1;
16134         }
16135         Gia_ManToBridgeAbsNetlist( stdout, pAbc->pGia, fAbsNetlist ? BRIDGE_ABS_NETLIST : BRIDGE_NETLIST );
16136     }
16137     else
16138     {
16139         Aig_Man_t * pAig;
16140         Gia_Man_t * pGia;
16141         if ( pAbc->pNtkCur == NULL )
16142         {
16143             Abc_Print( -1, "There is no network in the main-space.\n" );
16144             return 1;
16145         }
16146         if ( !Abc_NtkIsStrash(pAbc->pNtkCur) )
16147         {
16148             Abc_Print( -1, "The main-space network is not an AIG.\n" );
16149             return 1;
16150         }
16151         pAig = Abc_NtkToDar( pAbc->pNtkCur, 0, 1 );
16152         pGia = Gia_ManFromAig( pAig );
16153         Aig_ManStop( pAig );
16154         Gia_ManToBridgeAbsNetlist( stdout, pGia, fAbsNetlist ? BRIDGE_ABS_NETLIST : BRIDGE_NETLIST  );
16155         Gia_ManStop( pGia );
16156     }
16157     return 0;
16158 
16159 usage:
16160     Abc_Print( -2, "usage: send_aig -a\n" );
16161     Abc_Print( -2, "\t         sends current AIG to the bridge\n" );
16162     Abc_Print( -2, "\t-a     : toggle sending AIG from &-space [default = %s]\n", fAndSpace? "yes": "no" );
16163     Abc_Print( -2, "\t-b     : toggle sending netlist tagged as \"abstraction\". [default = %s]\n", fAbsNetlist? "yes": "no" );
16164     Abc_Print( -2, "\t-h     : print the command usage\n");
16165     return 1;
16166 }
16167 
16168 /**Function*************************************************************
16169 
16170   Synopsis    []
16171 
16172   Description []
16173 
16174   SideEffects []
16175 
16176   SeeAlso     []
16177 
16178 ***********************************************************************/
Abc_CommandSendStatus(Abc_Frame_t * pAbc,int argc,char ** argv)16179 int Abc_CommandSendStatus( Abc_Frame_t * pAbc, int argc, char ** argv )
16180 {
16181     extern int Gia_ManToBridgeResult( FILE * pFile, int Result, Abc_Cex_t * pCex, int iPoProved );
16182     int c;
16183     Extra_UtilGetoptReset();
16184     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
16185     {
16186         switch ( c )
16187         {
16188         case 'h':
16189             goto usage;
16190         default:
16191             goto usage;
16192         }
16193     }
16194     if ( !Abc_FrameIsBridgeMode() )
16195     {
16196         Abc_Print( -1, "The bridge mode is not available.\n" );
16197         return 1;
16198     }
16199     if ( pAbc->Status == 0 && pAbc->pCex == NULL )
16200     {
16201         Abc_Print( -1, "Status is \"sat\", but current CEX is not available.\n" );
16202         return 1;
16203     }
16204     Gia_ManToBridgeResult( stdout, pAbc->Status, pAbc->pCex, 0 );
16205     return 0;
16206 
16207 usage:
16208     Abc_Print( -2, "usage: send_status\n" );
16209     Abc_Print( -2, "\t         sends current status to the bridge\n" );
16210     Abc_Print( -2, "\t-h     : print the command usage\n");
16211     return 1;
16212 }
16213 
16214 
16215 /**Function*************************************************************
16216 
16217   Synopsis    []
16218 
16219   Description []
16220 
16221   SideEffects []
16222 
16223   SeeAlso     []
16224 
16225 ***********************************************************************/
Abc_CommandBackup(Abc_Frame_t * pAbc,int argc,char ** argv)16226 int Abc_CommandBackup( Abc_Frame_t * pAbc, int argc, char ** argv )
16227 {
16228     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
16229     int c;
16230     // set defaults
16231     Extra_UtilGetoptReset();
16232     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
16233     {
16234         switch ( c )
16235         {
16236         case 'h':
16237             goto usage;
16238         default:
16239             goto usage;
16240         }
16241     }
16242 
16243     if ( pNtk == NULL )
16244     {
16245         Abc_Print( -1, "Empty network.\n" );
16246         return 1;
16247     }
16248     if ( pAbc->pNtkBackup )
16249         Abc_NtkDelete( pAbc->pNtkBackup );
16250     pAbc->pNtkBackup = Abc_NtkDup( pNtk );
16251     return 0;
16252 
16253 usage:
16254     Abc_Print( -2, "usage: backup [-h]\n" );
16255     Abc_Print( -2, "\t        backs up the current network\n" );
16256     Abc_Print( -2, "\t-h    : print the command usage\n");
16257     return 1;
16258 }
Abc_CommandRestore(Abc_Frame_t * pAbc,int argc,char ** argv)16259 int Abc_CommandRestore( Abc_Frame_t * pAbc, int argc, char ** argv )
16260 {
16261     int c;
16262     // set defaults
16263     Extra_UtilGetoptReset();
16264     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
16265     {
16266         switch ( c )
16267         {
16268         case 'h':
16269             goto usage;
16270         default:
16271             goto usage;
16272         }
16273     }
16274 
16275     if ( pAbc->pNtkBackup == NULL )
16276     {
16277         Abc_Print( -1, "There is no backup network.\n" );
16278         return 1;
16279     }
16280     Abc_FrameReplaceCurrentNetwork( pAbc, Abc_NtkDup(pAbc->pNtkBackup) );
16281     pAbc->nFrames = -1;
16282     pAbc->Status = -1;
16283     return 0;
16284 
16285 usage:
16286     Abc_Print( -2, "usage: restore [-h]\n" );
16287     Abc_Print( -2, "\t        restores the current network\n" );
16288     Abc_Print( -2, "\t-h    : print the command usage\n");
16289     return 1;
16290 }
16291 
16292 /**Function*************************************************************
16293 
16294   Synopsis    []
16295 
16296   Description []
16297 
16298   SideEffects []
16299 
16300   SeeAlso     []
16301 
16302 ***********************************************************************/
Abc_CommandMinisat(Abc_Frame_t * pAbc,int argc,char ** argv)16303 int Abc_CommandMinisat( Abc_Frame_t * pAbc, int argc, char ** argv )
16304 {
16305 #ifdef USE_MINISAT22
16306     extern int MainSat(int argc, char** argv);
16307     MainSat( argc, argv );
16308 #else
16309     printf( "This command is currently disabled.\n" );
16310 #endif
16311     return 1;
16312 }
Abc_CommandMinisimp(Abc_Frame_t * pAbc,int argc,char ** argv)16313 int Abc_CommandMinisimp( Abc_Frame_t * pAbc, int argc, char ** argv )
16314 {
16315 #ifdef USE_MINISAT22
16316     extern int MainSimp(int argc, char** argv);
16317     MainSimp( argc, argv );
16318 #else
16319     printf( "This command is currently disabled.\n" );
16320 #endif
16321     return 1;
16322 }
16323 
16324 
16325 /**Function*************************************************************
16326 
16327   Synopsis    []
16328 
16329   Description []
16330 
16331   SideEffects []
16332 
16333   SeeAlso     []
16334 
16335 ***********************************************************************/
Abc_CommandFraig(Abc_Frame_t * pAbc,int argc,char ** argv)16336 int Abc_CommandFraig( Abc_Frame_t * pAbc, int argc, char ** argv )
16337 {
16338     char Buffer[100];
16339     Fraig_Params_t Params, * pParams = &Params;
16340     Abc_Ntk_t * pNtk, * pNtkRes;
16341     int fAllNodes;
16342     int fExdc;
16343     int c;
16344     int fPartition = 0;
16345     extern void Abc_NtkFraigPartitionedTime( Abc_Ntk_t * pNtk, void * pParams );
16346 
16347     pNtk = Abc_FrameReadNtk(pAbc);
16348     // set defaults
16349     fExdc     = 0;
16350     fAllNodes = 0;
16351     memset( pParams, 0, sizeof(Fraig_Params_t) );
16352     pParams->nPatsRand  = 2048; // the number of words of random simulation info
16353     pParams->nPatsDyna  = 2048; // the number of words of dynamic simulation info
16354     pParams->nBTLimit   =  100; // the max number of backtracks to perform
16355     pParams->fFuncRed   =    1; // performs only one level hashing
16356     pParams->fFeedBack  =    1; // enables solver feedback
16357     pParams->fDist1Pats =    1; // enables distance-1 patterns
16358     pParams->fDoSparse  =    1; // performs equiv tests for sparse functions
16359     pParams->fChoicing  =    0; // enables recording structural choices
16360     pParams->fTryProve  =    0; // tries to solve the final miter
16361     pParams->fVerbose   =    0; // the verbosiness flag
16362     pParams->fVerboseP  =    0; // the verbosiness flag
16363     Extra_UtilGetoptReset();
16364     while ( ( c = Extra_UtilGetopt( argc, argv, "RDCrscptvaeh" ) ) != EOF )
16365     {
16366         switch ( c )
16367         {
16368         case 'R':
16369             if ( globalUtilOptind >= argc )
16370             {
16371                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
16372                 goto usage;
16373             }
16374             pParams->nPatsRand = atoi(argv[globalUtilOptind]);
16375             globalUtilOptind++;
16376             if ( pParams->nPatsRand < 0 )
16377                 goto usage;
16378             break;
16379         case 'D':
16380             if ( globalUtilOptind >= argc )
16381             {
16382                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
16383                 goto usage;
16384             }
16385             pParams->nPatsDyna = atoi(argv[globalUtilOptind]);
16386             globalUtilOptind++;
16387             if ( pParams->nPatsDyna < 0 )
16388                 goto usage;
16389             break;
16390         case 'C':
16391             if ( globalUtilOptind >= argc )
16392             {
16393                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
16394                 goto usage;
16395             }
16396             pParams->nBTLimit = atoi(argv[globalUtilOptind]);
16397             globalUtilOptind++;
16398             if ( pParams->nBTLimit < 0 )
16399                 goto usage;
16400             break;
16401 
16402         case 'r':
16403             pParams->fFuncRed ^= 1;
16404             break;
16405         case 's':
16406             pParams->fDoSparse ^= 1;
16407             break;
16408         case 'c':
16409             pParams->fChoicing ^= 1;
16410             break;
16411         case 'p':
16412             pParams->fTryProve ^= 1;
16413             break;
16414         case 'v':
16415             pParams->fVerbose ^= 1;
16416             break;
16417         case 't':
16418             fPartition ^= 1;
16419             break;
16420         case 'a':
16421             fAllNodes ^= 1;
16422             break;
16423         case 'e':
16424             fExdc ^= 1;
16425             break;
16426         case 'h':
16427             goto usage;
16428         default:
16429             goto usage;
16430         }
16431     }
16432 
16433     if ( pNtk == NULL )
16434     {
16435         Abc_Print( -1, "Empty network.\n" );
16436         return 1;
16437     }
16438     if ( !Abc_NtkIsLogic(pNtk) && !Abc_NtkIsStrash(pNtk) )
16439     {
16440         Abc_Print( -1, "Can only fraig a logic network or an AIG.\n" );
16441         return 1;
16442     }
16443 
16444     // report the proof
16445     pParams->fVerboseP = pParams->fTryProve;
16446 
16447     // get the new network
16448     if ( fPartition )
16449     {
16450         pNtkRes = Abc_NtkDup( pNtk );
16451         if ( Abc_NtkIsStrash(pNtk) )
16452             Abc_NtkFraigPartitionedTime( pNtk, &Params );
16453         else
16454         {
16455             pNtk = Abc_NtkStrash( pNtk, fAllNodes, !fAllNodes, 0 );
16456             Abc_NtkFraigPartitionedTime( pNtk, &Params );
16457             Abc_NtkDelete( pNtk );
16458         }
16459     }
16460     else
16461     {
16462         if ( Abc_NtkIsStrash(pNtk) )
16463             pNtkRes = Abc_NtkFraig( pNtk, &Params, fAllNodes, fExdc );
16464         else
16465         {
16466             pNtk = Abc_NtkStrash( pNtk, fAllNodes, !fAllNodes, 0 );
16467             pNtkRes = Abc_NtkFraig( pNtk, &Params, fAllNodes, fExdc );
16468             Abc_NtkDelete( pNtk );
16469         }
16470     }
16471     if ( pNtkRes == NULL )
16472     {
16473         Abc_Print( -1, "Fraiging has failed.\n" );
16474         return 1;
16475     }
16476 
16477     if ( pParams->fTryProve ) // report the result
16478         Abc_NtkMiterReport( pNtkRes );
16479 
16480     // replace the current network
16481     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
16482     return 0;
16483 
16484 usage:
16485     sprintf(Buffer, "%d", pParams->nBTLimit );
16486     Abc_Print( -2, "usage: fraig [-R num] [-D num] [-C num] [-rscpvtah]\n" );
16487     Abc_Print( -2, "\t         transforms a logic network into a functionally reduced AIG\n" );
16488     Abc_Print( -2, "\t         (known bugs: takes an UNSAT miter and returns a SAT one)\n");
16489     Abc_Print( -2, "\t         (there are newer fraiging commands, \"ifraig\" and \"dfraig\")\n" );
16490     Abc_Print( -2, "\t-R num : number of random patterns (127 < num < 32769) [default = %d]\n",     pParams->nPatsRand );
16491     Abc_Print( -2, "\t-D num : number of systematic patterns (127 < num < 32769) [default = %d]\n", pParams->nPatsDyna );
16492     Abc_Print( -2, "\t-C num : number of backtracks for one SAT problem [default = %s]\n",    pParams->nBTLimit==-1? "infinity" : Buffer );
16493     Abc_Print( -2, "\t-r     : toggle functional reduction [default = %s]\n",                 pParams->fFuncRed? "yes": "no" );
16494     Abc_Print( -2, "\t-s     : toggle considering sparse functions [default = %s]\n",         pParams->fDoSparse? "yes": "no" );
16495     Abc_Print( -2, "\t-c     : toggle accumulation of choices [default = %s]\n",              pParams->fChoicing? "yes": "no" );
16496     Abc_Print( -2, "\t-p     : toggle proving the miter outputs [default = %s]\n",              pParams->fTryProve? "yes": "no" );
16497     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n",                       pParams->fVerbose?  "yes": "no" );
16498     Abc_Print( -2, "\t-e     : toggle functional sweeping using EXDC [default = %s]\n",       fExdc? "yes": "no" );
16499     Abc_Print( -2, "\t-a     : toggle between all nodes and DFS nodes [default = %s]\n",      fAllNodes? "all": "dfs" );
16500     Abc_Print( -2, "\t-t     : toggle using partitioned representation [default = %s]\n",     fPartition? "yes": "no" );
16501     Abc_Print( -2, "\t-h     : print the command usage\n");
16502     return 1;
16503 }
16504 
16505 /**Function*************************************************************
16506 
16507   Synopsis    []
16508 
16509   Description []
16510 
16511   SideEffects []
16512 
16513   SeeAlso     []
16514 
16515 ***********************************************************************/
Abc_CommandFraigTrust(Abc_Frame_t * pAbc,int argc,char ** argv)16516 int Abc_CommandFraigTrust( Abc_Frame_t * pAbc, int argc, char ** argv )
16517 {
16518     Abc_Ntk_t * pNtk, * pNtkRes;
16519     int c;
16520     int fDuplicate;
16521 
16522     pNtk = Abc_FrameReadNtk(pAbc);
16523     // set defaults
16524     fDuplicate = 0;
16525     Extra_UtilGetoptReset();
16526     while ( ( c = Extra_UtilGetopt( argc, argv, "dh" ) ) != EOF )
16527     {
16528         switch ( c )
16529         {
16530         case 'd':
16531             fDuplicate ^= 1;
16532             break;
16533         case 'h':
16534             goto usage;
16535         default:
16536             goto usage;
16537         }
16538     }
16539 
16540     if ( pNtk == NULL )
16541     {
16542         Abc_Print( -1, "Empty network.\n" );
16543         return 1;
16544     }
16545 
16546     // get the new network
16547     pNtkRes = Abc_NtkFraigTrust( pNtk );
16548     if ( pNtkRes == NULL )
16549     {
16550         Abc_Print( -1, "Fraiging in the trust mode has failed.\n" );
16551         return 1;
16552     }
16553     // replace the current network
16554     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
16555     return 0;
16556 
16557 usage:
16558     Abc_Print( -2, "usage: fraig_trust [-h]\n" );
16559     Abc_Print( -2, "\t        transforms the current network into an AIG assuming it is FRAIG with choices\n" );
16560 //    Abc_Print( -2, "\t-d    : toggle duplication of logic [default = %s]\n", fDuplicate? "yes": "no" );
16561     Abc_Print( -2, "\t-h    : print the command usage\n");
16562     return 1;
16563 }
16564 
16565 /**Function*************************************************************
16566 
16567   Synopsis    []
16568 
16569   Description []
16570 
16571   SideEffects []
16572 
16573   SeeAlso     []
16574 
16575 ***********************************************************************/
Abc_CommandFraigStore(Abc_Frame_t * pAbc,int argc,char ** argv)16576 int Abc_CommandFraigStore( Abc_Frame_t * pAbc, int argc, char ** argv )
16577 {
16578     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
16579     int c;
16580     int fDuplicate;
16581 
16582     // set defaults
16583     fDuplicate = 0;
16584     Extra_UtilGetoptReset();
16585     while ( ( c = Extra_UtilGetopt( argc, argv, "dh" ) ) != EOF )
16586     {
16587         switch ( c )
16588         {
16589         case 'd':
16590             fDuplicate ^= 1;
16591             break;
16592         case 'h':
16593             goto usage;
16594         default:
16595             goto usage;
16596         }
16597     }
16598 
16599     if ( pNtk == NULL )
16600     {
16601         Abc_Print( -1, "Empty network.\n" );
16602         return 1;
16603     }
16604 
16605     // get the new network
16606     if ( !Abc_NtkFraigStore( pNtk ) )
16607     {
16608         Abc_Print( -1, "Fraig storing has failed.\n" );
16609         return 1;
16610     }
16611     return 0;
16612 
16613 usage:
16614     Abc_Print( -2, "usage: fraig_store [-h]\n" );
16615     Abc_Print( -2, "\t        saves the current network in the AIG database\n" );
16616 //    Abc_Print( -2, "\t-d    : toggle duplication of logic [default = %s]\n", fDuplicate? "yes": "no" );
16617     Abc_Print( -2, "\t-h    : print the command usage\n");
16618     return 1;
16619 }
16620 
16621 /**Function*************************************************************
16622 
16623   Synopsis    []
16624 
16625   Description []
16626 
16627   SideEffects []
16628 
16629   SeeAlso     []
16630 
16631 ***********************************************************************/
Abc_CommandFraigRestore(Abc_Frame_t * pAbc,int argc,char ** argv)16632 int Abc_CommandFraigRestore( Abc_Frame_t * pAbc, int argc, char ** argv )
16633 {
16634     Abc_Ntk_t * pNtk, * pNtkRes;
16635     int c;
16636     int nPatsRand  =    0;    // the number of words of random simulation info
16637     int nPatsDyna  =    0;    // the number of words of dynamic simulation info
16638     int nBTLimit   = 1000;    // the max number of backtracks to perform
16639 
16640     pNtk = Abc_FrameReadNtk(pAbc);
16641     // set defaults
16642     Extra_UtilGetoptReset();
16643     while ( ( c = Extra_UtilGetopt( argc, argv, "RDCh" ) ) != EOF )
16644     {
16645         switch ( c )
16646         {
16647         case 'R':
16648             if ( globalUtilOptind >= argc )
16649             {
16650                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
16651                 goto usage;
16652             }
16653             nPatsRand = atoi(argv[globalUtilOptind]);
16654             globalUtilOptind++;
16655             if ( nPatsRand < 0 )
16656                 goto usage;
16657             break;
16658         case 'D':
16659             if ( globalUtilOptind >= argc )
16660             {
16661                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
16662                 goto usage;
16663             }
16664             nPatsDyna = atoi(argv[globalUtilOptind]);
16665             globalUtilOptind++;
16666             if ( nPatsDyna < 0 )
16667                 goto usage;
16668             break;
16669         case 'C':
16670             if ( globalUtilOptind >= argc )
16671             {
16672                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
16673                 goto usage;
16674             }
16675             nBTLimit = atoi(argv[globalUtilOptind]);
16676             globalUtilOptind++;
16677             if ( nBTLimit < 0 )
16678                 goto usage;
16679             break;
16680         case 'h':
16681             goto usage;
16682         default:
16683             goto usage;
16684         }
16685     }
16686 
16687     if ( pNtk == NULL )
16688     {
16689         Abc_Print( -1, "Empty network.\n" );
16690         return 1;
16691     }
16692 
16693     // get the new network
16694     pNtkRes = Abc_NtkFraigRestore( nPatsRand, nPatsDyna, nBTLimit );
16695     if ( pNtkRes == NULL )
16696     {
16697         Abc_Print( -1, "Fraig restoring has failed.\n" );
16698         return 1;
16699     }
16700     // replace the current network
16701     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
16702     return 0;
16703 
16704 usage:
16705     Abc_Print( -2, "usage: fraig_restore [-RDC num] [-h]\n" );
16706     Abc_Print( -2, "\t         makes the current network by fraiging the AIG database\n" );
16707     Abc_Print( -2, "\t-R num : number of random patterns (127 < num < 32769) [default = design-dependent]\n" );
16708     Abc_Print( -2, "\t-D num : number of systematic patterns (127 < num < 32769) [default = design-dependent]\n" );
16709     Abc_Print( -2, "\t-C num : number of backtracks for one SAT problem [default = %d]\n",  nBTLimit );
16710     Abc_Print( -2, "\t-h     : print the command usage\n");
16711     return 1;
16712 }
16713 
16714 /**Function*************************************************************
16715 
16716   Synopsis    []
16717 
16718   Description []
16719 
16720   SideEffects []
16721 
16722   SeeAlso     []
16723 
16724 ***********************************************************************/
Abc_CommandFraigClean(Abc_Frame_t * pAbc,int argc,char ** argv)16725 int Abc_CommandFraigClean( Abc_Frame_t * pAbc, int argc, char ** argv )
16726 {
16727 //    Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
16728     int c;
16729     int fDuplicate;
16730     // set defaults
16731     fDuplicate = 0;
16732     Extra_UtilGetoptReset();
16733     while ( ( c = Extra_UtilGetopt( argc, argv, "dh" ) ) != EOF )
16734     {
16735         switch ( c )
16736         {
16737         case 'd':
16738             fDuplicate ^= 1;
16739             break;
16740         case 'h':
16741             goto usage;
16742         default:
16743             goto usage;
16744         }
16745     }
16746     Abc_NtkFraigStoreClean();
16747     return 0;
16748 
16749 usage:
16750     Abc_Print( -2, "usage: fraig_clean [-h]\n" );
16751     Abc_Print( -2, "\t        cleans the internal FRAIG storage\n" );
16752 //    Abc_Print( -2, "\t-d    : toggle duplication of logic [default = %s]\n", fDuplicate? "yes": "no" );
16753     Abc_Print( -2, "\t-h    : print the command usage\n");
16754     return 1;
16755 }
16756 
16757 /**Function*************************************************************
16758 
16759   Synopsis    []
16760 
16761   Description []
16762 
16763   SideEffects []
16764 
16765   SeeAlso     []
16766 
16767 ***********************************************************************/
Abc_CommandFraigSweep(Abc_Frame_t * pAbc,int argc,char ** argv)16768 int Abc_CommandFraigSweep( Abc_Frame_t * pAbc, int argc, char ** argv )
16769 {
16770     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
16771     int c;
16772     int fUseInv;
16773     int fExdc;
16774     int fVerbose;
16775     int fVeryVerbose;
16776     extern int Abc_NtkFraigSweep( Abc_Ntk_t * pNtk, int fUseInv, int fExdc, int fVerbose, int fVeryVerbose );
16777     // set defaults
16778     fUseInv   = 1;
16779     fExdc     = 0;
16780     fVerbose  = 0;
16781     fVeryVerbose = 0;
16782     Extra_UtilGetoptReset();
16783     while ( ( c = Extra_UtilGetopt( argc, argv, "ievwh" ) ) != EOF )
16784     {
16785         switch ( c )
16786         {
16787         case 'i':
16788             fUseInv ^= 1;
16789             break;
16790         case 'e':
16791             fExdc ^= 1;
16792             break;
16793         case 'v':
16794             fVerbose ^= 1;
16795             break;
16796         case 'w':
16797             fVeryVerbose ^= 1;
16798             break;
16799         case 'h':
16800             goto usage;
16801         default:
16802             goto usage;
16803         }
16804     }
16805 
16806     if ( pNtk == NULL )
16807     {
16808         Abc_Print( -1, "Empty network.\n" );
16809         return 1;
16810     }
16811     if ( Abc_NtkIsStrash(pNtk) )
16812     {
16813         Abc_Print( -1, "Cannot sweep AIGs (use \"fraig\").\n" );
16814         return 1;
16815     }
16816     if ( !Abc_NtkIsLogic(pNtk) )
16817     {
16818         Abc_Print( -1, "Transform the current network into a logic network.\n" );
16819         return 1;
16820     }
16821     // modify the current network
16822     if ( !Abc_NtkFraigSweep( pNtk, fUseInv, fExdc, fVerbose, fVeryVerbose ) )
16823     {
16824         Abc_Print( -1, "Sweeping has failed.\n" );
16825         return 1;
16826     }
16827     return 0;
16828 
16829 usage:
16830     Abc_Print( -2, "usage: fraig_sweep [-evwh]\n" );
16831     Abc_Print( -2, "\t        performs technology-dependent sweep\n" );
16832     Abc_Print( -2, "\t-e    : toggle functional sweeping using EXDC [default = %s]\n", fExdc? "yes": "no" );
16833     Abc_Print( -2, "\t-v    : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
16834     Abc_Print( -2, "\t-w    : prints equivalence class information [default = %s]\n", fVeryVerbose? "yes": "no" );
16835     Abc_Print( -2, "\t-h    : print the command usage\n");
16836     return 1;
16837 }
16838 
16839 /**Function*************************************************************
16840 
16841   Synopsis    []
16842 
16843   Description []
16844 
16845   SideEffects []
16846 
16847   SeeAlso     []
16848 
16849 ***********************************************************************/
Abc_CommandFraigDress(Abc_Frame_t * pAbc,int argc,char ** argv)16850 int Abc_CommandFraigDress( Abc_Frame_t * pAbc, int argc, char ** argv )
16851 {
16852     extern void Abc_NtkDress( Abc_Ntk_t * pNtk, char * pFileName, int fVerbose );
16853     extern void Abc_NtkDress2( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nConflictLimit, int fVerbose );
16854     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc), * pNtk2;
16855     char * pFileName;
16856     int c;
16857     int nConfs;
16858     int fVerbose;
16859     // set defaults
16860     nConfs   = 1000;
16861     fVerbose =    0;
16862     Extra_UtilGetoptReset();
16863     while ( ( c = Extra_UtilGetopt( argc, argv, "Cvh" ) ) != EOF )
16864     {
16865         switch ( c )
16866         {
16867         case 'C':
16868             if ( globalUtilOptind >= argc )
16869             {
16870                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
16871                 goto usage;
16872             }
16873             nConfs = atoi(argv[globalUtilOptind]);
16874             globalUtilOptind++;
16875             if ( nConfs < 0 )
16876                 goto usage;
16877             break;
16878         case 'v':
16879             fVerbose ^= 1;
16880             break;
16881         case 'h':
16882             goto usage;
16883         default:
16884             goto usage;
16885         }
16886     }
16887     if ( pNtk == NULL )
16888     {
16889         Abc_Print( -1, "Empty network.\n" );
16890         return 1;
16891     }
16892     if ( Abc_NtkIsStrash(pNtk) )
16893     {
16894         Abc_Print( -1, "This command works only for logic networks.\n" );
16895         return 1;
16896     }
16897     if ( argc != globalUtilOptind && argc != globalUtilOptind + 1 )
16898         goto usage;
16899     if ( argc == globalUtilOptind && Abc_NtkSpec(pNtk) == NULL )
16900     {
16901         Abc_Print( -1, "The current network has no spec.\n" );
16902         return 1;
16903     }
16904     // get the input file name
16905     pFileName = (argc == globalUtilOptind + 1) ? argv[globalUtilOptind] : Abc_NtkSpec(pNtk);
16906     // modify the current network
16907 //    Abc_NtkDress( pNtk, pFileName, fVerbose );
16908     pNtk2 = Io_Read( pFileName, Io_ReadFileType(pFileName), 1, 0 );
16909     Abc_NtkDress2( pNtk, pNtk2, nConfs, fVerbose );
16910     Abc_NtkDelete( pNtk2 );
16911     return 0;
16912 
16913 usage:
16914     Abc_Print( -2, "usage: dress [-C num] [-vh] <file>\n" );
16915     Abc_Print( -2, "\t         transfers internal node names from file to the current network\n" );
16916     Abc_Print( -2, "\t<file> : network with names (if not given, the current network spec is used)\n" );
16917     Abc_Print( -2, "\t-C num : the maximum number of conflicts at each node [default = %d]\n", nConfs );
16918     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
16919     Abc_Print( -2, "\t-h     : print the command usage\n");
16920     return 1;
16921 }
16922 
16923 /**Function*************************************************************
16924 
16925   Synopsis    []
16926 
16927   Description []
16928 
16929   SideEffects []
16930 
16931   SeeAlso     []
16932 
16933 ***********************************************************************/
Abc_CommandDumpEquiv(Abc_Frame_t * pAbc,int argc,char ** argv)16934 int Abc_CommandDumpEquiv( Abc_Frame_t * pAbc, int argc, char ** argv )
16935 {
16936     extern void Abc_NtkDumpEquiv( Abc_Ntk_t * pNtks[2], char * pFileName, int nConfs, int fByName, int fVerbose );
16937     Abc_Ntk_t * pNtks[2] = {NULL};
16938     char * pFileName[2], * pFileNameOut;
16939     int c, nConfs = 1000, fByName = 1, fVerbose = 0;
16940     Extra_UtilGetoptReset();
16941     while ( ( c = Extra_UtilGetopt( argc, argv, "Cnvh" ) ) != EOF )
16942     {
16943         switch ( c )
16944         {
16945         case 'C':
16946             if ( globalUtilOptind >= argc )
16947             {
16948                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
16949                 goto usage;
16950             }
16951             nConfs = atoi(argv[globalUtilOptind]);
16952             globalUtilOptind++;
16953             if ( nConfs < 0 )
16954                 goto usage;
16955             break;
16956         case 'n':
16957             fByName ^= 1;
16958             break;
16959         case 'v':
16960             fVerbose ^= 1;
16961             break;
16962         case 'h':
16963             goto usage;
16964         default:
16965             goto usage;
16966         }
16967     }
16968     if ( argc != globalUtilOptind + 3 )
16969     {
16970         Abc_Print( -1, "Expecting three file names on the command line.\n" );
16971         goto usage;
16972     }
16973     pFileName[0] = argv[globalUtilOptind];
16974     pFileName[1] = argv[globalUtilOptind+1];
16975     pFileNameOut = argv[globalUtilOptind+2];
16976     for ( c = 0; c < 2; c++ )
16977     {
16978         pNtks[c] = Io_Read( pFileName[c], Io_ReadFileType(pFileName[c]), 1, 0 );
16979         if ( pNtks[c] == NULL )
16980             goto usage;
16981         Abc_NtkToAig( pNtks[c] );
16982     }
16983 //    if ( Abc_NtkCiNum(pNtks[0]) != Abc_NtkCiNum(pNtks[1]) )
16984 //        Abc_Print( -1, "The number of primary inputs of networks \"%s\" and \"%s\" does not match.\n", Abc_NtkName(pNtks[0]), Abc_NtkName(pNtks[1]) );
16985 //    else if ( Abc_NtkCoNum(pNtks[0]) != Abc_NtkCoNum(pNtks[1]) )
16986 //        Abc_Print( -1, "The number of primary outputs of networks \"%s\" and \"%s\" does not match.\n", Abc_NtkName(pNtks[0]), Abc_NtkName(pNtks[1]) );
16987 //    else
16988         Abc_NtkDumpEquiv( pNtks, pFileNameOut, nConfs, fByName, fVerbose );
16989     Abc_NtkDelete( pNtks[0] );
16990     Abc_NtkDelete( pNtks[1] );
16991     return 0;
16992 
16993 usage:
16994     Abc_Print( -2, "usage: dump_equiv [-C num] [-nvh] <file1.blif> <file2.blif> <file_dump_equiv.txt>\n" );
16995     Abc_Print( -2, "\t          computes equivalence classes of nodes in <file1> and <file2>\n" );
16996     Abc_Print( -2, "\t          By default this procedure performs matching of primary inputs by name.\n" );
16997     Abc_Print( -2, "\t          Those inputs that cannot be matched are treated as free variables.\n" );
16998     Abc_Print( -2, "\t          There is no effort to match primary outputs. Indeed, if two outputs\n" );
16999     Abc_Print( -2, "\t          are equivalent, they will belong to the same equivalence class in the end.\n" );
17000     Abc_Print( -2, "\t-C num  : the maximum number of conflicts at each node [default = %d]\n", nConfs );
17001     Abc_Print( -2, "\t-n      : enable matching of primary inputs by name [default = %s]\n", fByName? "yes": "no" );
17002     Abc_Print( -2, "\t-v      : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
17003     Abc_Print( -2, "\t-h      : print the command usage\n");
17004     Abc_Print( -2, "\t<file1> : first network whose nodes are considered\n" );
17005     Abc_Print( -2, "\t<file2> : second network whose nodes are considered\n" );
17006     Abc_Print( -2, "\t<file_dump_equiv> : text file with node equivalence classes\n" );
17007     return 1;
17008 }
17009 
17010 /**Function*************************************************************
17011 
17012   Synopsis    []
17013 
17014   Description []
17015 
17016   SideEffects []
17017 
17018   SeeAlso     []
17019 
17020 ***********************************************************************/
Abc_CommandRecStart3(Abc_Frame_t * pAbc,int argc,char ** argv)17021 int Abc_CommandRecStart3( Abc_Frame_t * pAbc, int argc, char ** argv )
17022 {
17023     char * FileName, * pTemp;
17024     char ** pArgvNew;
17025     int c, nArgcNew;
17026     FILE * pFile;
17027     Gia_Man_t * pGia = NULL;
17028     int nVars = 6;
17029     int nCuts = 32;
17030     int fFuncOnly = 0;
17031     int fVerbose = 0;
17032     Extra_UtilGetoptReset();
17033     while ( ( c = Extra_UtilGetopt( argc, argv, "KCfvh" ) ) != EOF )
17034     {
17035         switch ( c )
17036         {
17037         case 'K':
17038             if ( globalUtilOptind >= argc )
17039             {
17040                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
17041                 goto usage;
17042             }
17043             nVars = atoi(argv[globalUtilOptind]);
17044             globalUtilOptind++;
17045             if ( nVars < 1 )
17046                 goto usage;
17047             break;
17048         case 'C':
17049             if ( globalUtilOptind >= argc )
17050             {
17051                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
17052                 goto usage;
17053             }
17054             nCuts = atoi(argv[globalUtilOptind]);
17055             globalUtilOptind++;
17056             if ( nCuts < 1 )
17057                 goto usage;
17058             break;
17059         case 'f':
17060             fFuncOnly ^= 1;
17061             break;
17062         case 'v':
17063             fVerbose ^= 1;
17064             break;
17065         case 'h':
17066             goto usage;
17067         default:
17068             goto usage;
17069         }
17070     }
17071     if ( !(nVars >= 3 && nVars <= 16) )
17072     {
17073         Abc_Print( -1, "The range of allowed values is 3 <= K <= 16.\n" );
17074         return 0;
17075     }
17076     if ( Abc_NtkRecIsRunning3() )
17077     {
17078         Abc_Print( -1, "The AIG subgraph recording is already started.\n" );
17079         return 0;
17080     }
17081     pArgvNew = argv + globalUtilOptind;
17082     nArgcNew = argc - globalUtilOptind;
17083     if ( nArgcNew != 1 )
17084         Abc_Print( 1, "File name is not given on the command line. Starting a new record.\n" );
17085     else
17086     {
17087         // get the input file name
17088         FileName = pArgvNew[0];
17089         // fix the wrong symbol
17090         for ( pTemp = FileName; *pTemp; pTemp++ )
17091             if ( *pTemp == '>' )
17092                 *pTemp = '\\';
17093         if ( (pFile = fopen( FileName, "r" )) == NULL )
17094         {
17095             Abc_Print( -1, "Cannot open input file \"%s\". ", FileName );
17096             if ( (FileName = Extra_FileGetSimilarName( FileName, ".aig", NULL, NULL, NULL, NULL )) )
17097                 Abc_Print( 1, "Did you mean \"%s\"?", FileName );
17098             Abc_Print( 1, "\n" );
17099             return 1;
17100         }
17101         fclose( pFile );
17102         pGia = Gia_AigerRead( FileName, 0, 1, 0 );
17103         if ( pGia == NULL )
17104         {
17105             Abc_Print( -1, "Reading AIGER has failed.\n" );
17106             return 0;
17107         }
17108     }
17109     Abc_NtkRecStart3( pGia, nVars, nCuts, fFuncOnly, fVerbose );
17110     return 0;
17111 
17112 usage:
17113     Abc_Print( -2, "usage: rec_start3 [-K num] [-C num] [-fvh] <file>\n" );
17114     Abc_Print( -2, "\t         starts recording AIG subgraphs (should be called for\n" );
17115     Abc_Print( -2, "\t         an empty network or after reading in a previous record)\n" );
17116     Abc_Print( -2, "\t-K num : the largest number of inputs [default = %d]\n", nVars );
17117     Abc_Print( -2, "\t-C num : the max number of cuts used at a node (0 < num < 2^12) [default = %d]\n", nCuts );
17118     Abc_Print( -2, "\t-f     : toggles recording functions without AIG subgraphs [default = %s]\n", fFuncOnly? "yes": "no" );
17119     Abc_Print( -2, "\t-v     : toggles additional verbose output [default = %s]\n", fVerbose? "yes": "no" );
17120     Abc_Print( -2, "\t-h     : print the command usage\n");
17121     Abc_Print( -2, "\t<file> : AIGER file with the library\n");
17122     return 1;
17123 }
17124 
17125 
17126 /**Function*************************************************************
17127 
17128   Synopsis    []
17129 
17130   Description []
17131 
17132   SideEffects []
17133 
17134   SeeAlso     []
17135 
17136 ***********************************************************************/
Abc_CommandRecStop3(Abc_Frame_t * pAbc,int argc,char ** argv)17137 int Abc_CommandRecStop3( Abc_Frame_t * pAbc, int argc, char ** argv )
17138 {
17139     int c;
17140     Extra_UtilGetoptReset();
17141     while ( ( c = Extra_UtilGetopt( argc, argv, "dh" ) ) != EOF )
17142     {
17143         switch ( c )
17144         {
17145         case 'h':
17146             goto usage;
17147         default:
17148             goto usage;
17149         }
17150     }
17151     if ( !Abc_NtkRecIsRunning3() )
17152     {
17153         Abc_Print( -1, "This command works only after calling \"rec_start3\".\n" );
17154         return 0;
17155     }
17156     Abc_NtkRecStop3();
17157     return 0;
17158 
17159 usage:
17160     Abc_Print( -2, "usage: rec_stop3 [-h]\n" );
17161     Abc_Print( -2, "\t        cleans the internal storage for AIG subgraphs\n" );
17162     Abc_Print( -2, "\t-h    : print the command usage\n");
17163     return 1;
17164 }
17165 
17166 
17167 /**Function*************************************************************
17168 
17169   Synopsis    []
17170 
17171   Description []
17172 
17173   SideEffects []
17174 
17175   SeeAlso     []
17176 
17177 ***********************************************************************/
Abc_CommandRecPs3(Abc_Frame_t * pAbc,int argc,char ** argv)17178 int Abc_CommandRecPs3( Abc_Frame_t * pAbc, int argc, char ** argv )
17179 {
17180     int c, fPrintLib = 0;
17181     Extra_UtilGetoptReset();
17182     while ( ( c = Extra_UtilGetopt( argc, argv, "ph" ) ) != EOF )
17183     {
17184         switch ( c )
17185         {
17186         case 'p':
17187             fPrintLib ^= 1;
17188             break;
17189         case 'h':
17190             goto usage;
17191         default:
17192             goto usage;
17193         }
17194     }
17195     if ( !Abc_NtkRecIsRunning3() )
17196     {
17197         Abc_Print( -1, "This command works for AIGs only after calling \"rec_start2\".\n" );
17198         return 0;
17199     }
17200     Abc_NtkRecPs3(fPrintLib);
17201     return 0;
17202 
17203 usage:
17204     Abc_Print( -2, "usage: rec_ps3 [-h]\n" );
17205     Abc_Print( -2, "\t        prints statistics about the recorded AIG subgraphs\n" );
17206     Abc_Print( -2, "\t-h    : print the command usage\n");
17207     return 1;
17208 }
17209 
17210 
17211 /**Function*************************************************************
17212 
17213   Synopsis    []
17214 
17215   Description []
17216 
17217   SideEffects []
17218 
17219   SeeAlso     []
17220 
17221 ***********************************************************************/
Abc_CommandRecAdd3(Abc_Frame_t * pAbc,int argc,char ** argv)17222 int Abc_CommandRecAdd3( Abc_Frame_t * pAbc, int argc, char ** argv )
17223 {
17224     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
17225     int c;
17226     int fUseSOPB = 0;
17227     // set defaults
17228     Extra_UtilGetoptReset();
17229     while ( ( c = Extra_UtilGetopt( argc, argv, "gh" ) ) != EOF )
17230     {
17231         switch ( c )
17232         {
17233         case 'g':
17234             fUseSOPB = 1;
17235             break;
17236         case 'h':
17237             goto usage;
17238         default:
17239             goto usage;
17240         }
17241     }
17242     if ( !Abc_NtkIsStrash(pNtk) )
17243     {
17244         Abc_Print( -1, "This command works for AIGs.\n" );
17245         return 0;
17246     }
17247     if ( !Abc_NtkRecIsRunning3() )
17248     {
17249         Abc_Print( -1, "This command works for AIGs after calling \"rec_start2\".\n" );
17250         return 0;
17251     }
17252     Abc_NtkRecAdd3( pNtk, fUseSOPB );
17253     return 0;
17254 
17255 usage:
17256     Abc_Print( -2, "usage: rec_add3 [-h]\n" );
17257     Abc_Print( -2, "\t        adds subgraphs from the current network to the set\n" );
17258     Abc_Print( -2, "\t-h    : print the command usage\n");
17259     return 1;
17260 }
17261 
17262 
17263 /**Function*************************************************************
17264 
17265   Synopsis    []
17266 
17267   Description []
17268 
17269   SideEffects []
17270 
17271   SeeAlso     []
17272 
17273 ***********************************************************************/
Abc_CommandRecDump3(Abc_Frame_t * pAbc,int argc,char ** argv)17274 int Abc_CommandRecDump3( Abc_Frame_t * pAbc, int argc, char ** argv )
17275 {
17276     extern void Abc_NtkRecDumpTt3( char * pFileName, int fBinary );
17277     char * FileName;
17278     char ** pArgvNew;
17279     int nArgcNew;
17280     Gia_Man_t * pGia;
17281     int fAscii = 0;
17282     int fBinary = 0;
17283     int c;
17284 
17285     Extra_UtilGetoptReset();
17286     while ( ( c = Extra_UtilGetopt( argc, argv, "abh" ) ) != EOF )
17287     {
17288         switch ( c )
17289         {
17290         case 'a':
17291             fAscii ^= 1;
17292             break;
17293         case 'b':
17294             fBinary ^= 1;
17295             break;
17296         case 'h':
17297             goto usage;
17298         default:
17299             goto usage;
17300         }
17301     }
17302     if ( !Abc_NtkRecIsRunning3() )
17303     {
17304         Abc_Print( -1, "The AIG subgraph recording is not started.\n" );
17305         return 1;
17306     }
17307 
17308     pArgvNew = argv + globalUtilOptind;
17309     nArgcNew = argc - globalUtilOptind;
17310     if ( nArgcNew != 1 )
17311     {
17312         Abc_Print( -1, "File name is not given on the command line.\n" );
17313         return 1;
17314     }
17315     // get the input file name
17316     FileName = pArgvNew[0];
17317     if ( fAscii )
17318         Abc_NtkRecDumpTt3( FileName, 0 );
17319     else if ( fBinary )
17320         Abc_NtkRecDumpTt3( FileName, 1 );
17321     else
17322     {
17323         pGia = Abc_NtkRecGetGia3();
17324         if( pGia == NULL )
17325         {
17326             Abc_Print( 0, "Library AIG is not available.\n" );
17327             return 1;
17328         }
17329         if( Gia_ManPoNum(pGia) == 0 )
17330         {
17331             Abc_Print( 0, "No structure in the library.\n" );
17332             return 1;
17333         }
17334         Gia_AigerWrite( pGia, FileName, 0, 0, 0 );
17335     }
17336     return 0;
17337 
17338 usage:
17339     Abc_Print( -2, "usage: rec_dump3 [-abh] <file>\n" );
17340     Abc_Print( -2, "\t-h     : print the command usage\n");
17341     Abc_Print( -2, "\t-a     : toggles dumping TTs into an ASCII file [default = %s]\n", fAscii? "yes": "no" );
17342     Abc_Print( -2, "\t-b     : toggles dumping TTs into a binary file [default = %s]\n", fBinary? "yes": "no" );
17343     Abc_Print( -2, "\t<file> : AIGER file to write the library\n");
17344     return 1;
17345 }
17346 
17347 /**Function*************************************************************
17348 
17349   Synopsis    []
17350 
17351   Description []
17352 
17353   SideEffects []
17354 
17355   SeeAlso     []
17356 
17357 ***********************************************************************/
Abc_CommandRecMerge3(Abc_Frame_t * pAbc,int argc,char ** argv)17358 int Abc_CommandRecMerge3( Abc_Frame_t * pAbc, int argc, char ** argv )
17359 {
17360     int c;
17361     char * FileName, * pTemp;
17362     char ** pArgvNew;
17363     int nArgcNew;
17364     FILE * pFile;
17365     Gia_Man_t * pGia = NULL;
17366 
17367     // set defaults
17368     Extra_UtilGetoptReset();
17369     while ( ( c = Extra_UtilGetopt( argc, argv, "dh" ) ) != EOF )
17370     {
17371         switch ( c )
17372         {
17373         case 'h':
17374             goto usage;
17375         default:
17376             goto usage;
17377         }
17378     }
17379     if ( !Abc_NtkRecIsRunning3() )
17380     {
17381         Abc_Print( -1, "This command works for AIGs only after calling \"rec_start3\".\n" );
17382         return 0;
17383     }
17384     pArgvNew = argv + globalUtilOptind;
17385     nArgcNew = argc - globalUtilOptind;
17386     if ( nArgcNew != 1 )
17387     {
17388         Abc_Print( -1, "File name is not given on the command line.\n" );
17389         return 1;
17390     }
17391     else
17392     {
17393         // get the input file name
17394         FileName = pArgvNew[0];
17395         // fix the wrong symbol
17396         for ( pTemp = FileName; *pTemp; pTemp++ )
17397             if ( *pTemp == '>' )
17398                 *pTemp = '\\';
17399         if ( (pFile = fopen( FileName, "r" )) == NULL )
17400         {
17401             Abc_Print( -1, "Cannot open input file \"%s\". ", FileName );
17402             if ( (FileName = Extra_FileGetSimilarName( FileName, ".aig", NULL, NULL, NULL, NULL )) )
17403                 Abc_Print( 1, "Did you mean \"%s\"?", FileName );
17404             Abc_Print( 1, "\n" );
17405             return 1;
17406         }
17407         fclose( pFile );
17408         pGia = Gia_AigerRead( FileName, 0, 1, 0 );
17409         if ( pGia == NULL )
17410         {
17411             Abc_Print( -1, "Reading AIGER has failed.\n" );
17412             return 0;
17413         }
17414     }
17415     Abc_NtkRecLibMerge3(pGia);
17416     Gia_ManStop( pGia );
17417     return 0;
17418 
17419 usage:
17420     Abc_Print( -2, "usage: rec_merge3 [-h] <file>\n" );
17421     Abc_Print( -2, "\t         merge libraries\n" );
17422     Abc_Print( -2, "\t-h     : print the command usage\n");
17423     Abc_Print( -2, "\t<file> : AIGER file with the library\n");
17424     return 1;
17425 }
17426 
17427 
17428 /**Function*************************************************************
17429 
17430   Synopsis    []
17431 
17432   Description []
17433 
17434   SideEffects []
17435 
17436   SeeAlso     []
17437 
17438 ***********************************************************************/
Abc_CommandMap(Abc_Frame_t * pAbc,int argc,char ** argv)17439 int Abc_CommandMap( Abc_Frame_t * pAbc, int argc, char ** argv )
17440 {
17441     Abc_Ntk_t * pNtk, * pNtkRes;
17442     char Buffer[100];
17443     double DelayTarget;
17444     double AreaMulti;
17445     double DelayMulti;
17446     float LogFan = 0;
17447     float Slew = 0; // choose based on the library
17448     float Gain = 250;
17449     int nGatesMin = 0;
17450     int fAreaOnly;
17451     int fRecovery;
17452     int fSweep;
17453     int fSwitching;
17454     int fSkipFanout;
17455     int fUseProfile;
17456     int fUseBuffs;
17457     int fVerbose;
17458     int c;
17459     extern Abc_Ntk_t * Abc_NtkMap( Abc_Ntk_t * pNtk, double DelayTarget, double AreaMulti, double DelayMulti, float LogFan, float Slew, float Gain, int nGatesMin, int fRecovery, int fSwitching, int fSkipFanout, int fUseProfile, int fUseBuffs, int fVerbose );
17460     extern int Abc_NtkFraigSweep( Abc_Ntk_t * pNtk, int fUseInv, int fExdc, int fVerbose, int fVeryVerbose );
17461 
17462     pNtk = Abc_FrameReadNtk(pAbc);
17463     // set defaults
17464     DelayTarget =-1;
17465     AreaMulti   = 0;
17466     DelayMulti  = 0;
17467     fAreaOnly   = 0;
17468     fRecovery   = 1;
17469     fSweep      = 0;
17470     fSwitching  = 0;
17471     fSkipFanout = 0;
17472     fUseProfile = 0;
17473     fUseBuffs   = 0;
17474     fVerbose    = 0;
17475     Extra_UtilGetoptReset();
17476     while ( ( c = Extra_UtilGetopt( argc, argv, "DABFSGMarspfuovh" ) ) != EOF )
17477     {
17478         switch ( c )
17479         {
17480         case 'D':
17481             if ( globalUtilOptind >= argc )
17482             {
17483                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a floating point number.\n" );
17484                 goto usage;
17485             }
17486             DelayTarget = (float)atof(argv[globalUtilOptind]);
17487             globalUtilOptind++;
17488             if ( DelayTarget <= 0.0 )
17489                 goto usage;
17490             break;
17491         case 'A':
17492             if ( globalUtilOptind >= argc )
17493             {
17494                 Abc_Print( -1, "Command line switch \"-A\" should be followed by a floating point number.\n" );
17495                 goto usage;
17496             }
17497             AreaMulti = (float)atof(argv[globalUtilOptind]);
17498             globalUtilOptind++;
17499             break;
17500         case 'B':
17501             if ( globalUtilOptind >= argc )
17502             {
17503                 Abc_Print( -1, "Command line switch \"-B\" should be followed by a floating point number.\n" );
17504                 goto usage;
17505             }
17506             DelayMulti = (float)atof(argv[globalUtilOptind]);
17507             globalUtilOptind++;
17508             break;
17509         case 'F':
17510             if ( globalUtilOptind >= argc )
17511             {
17512                 Abc_Print( -1, "Command line switch \"-F\" should be followed by a floating point number.\n" );
17513                 goto usage;
17514             }
17515             LogFan = (float)atof(argv[globalUtilOptind]);
17516             globalUtilOptind++;
17517             if ( LogFan < 0.0 )
17518                 goto usage;
17519             break;
17520         case 'S':
17521             if ( globalUtilOptind >= argc )
17522             {
17523                 Abc_Print( -1, "Command line switch \"-S\" should be followed by a floating point number.\n" );
17524                 goto usage;
17525             }
17526             Slew = (float)atof(argv[globalUtilOptind]);
17527             globalUtilOptind++;
17528             if ( Slew <= 0.0 )
17529                 goto usage;
17530             break;
17531         case 'G':
17532             if ( globalUtilOptind >= argc )
17533             {
17534                 Abc_Print( -1, "Command line switch \"-G\" should be followed by a floating point number.\n" );
17535                 goto usage;
17536             }
17537             Gain = (float)atof(argv[globalUtilOptind]);
17538             globalUtilOptind++;
17539             if ( Gain <= 0.0 )
17540                 goto usage;
17541             break;
17542         case 'M':
17543             if ( globalUtilOptind >= argc )
17544             {
17545                 Abc_Print( -1, "Command line switch \"-M\" should be followed by a positive integer.\n" );
17546                 goto usage;
17547             }
17548             nGatesMin = atoi(argv[globalUtilOptind]);
17549             globalUtilOptind++;
17550             if ( nGatesMin < 0 )
17551                 goto usage;
17552             break;
17553         case 'a':
17554             fAreaOnly ^= 1;
17555             break;
17556         case 'r':
17557             fRecovery ^= 1;
17558             break;
17559         case 's':
17560             fSweep ^= 1;
17561             break;
17562         case 'p':
17563             fSwitching ^= 1;
17564             break;
17565         case 'f':
17566             fSkipFanout ^= 1;
17567             break;
17568         case 'u':
17569             fUseProfile ^= 1;
17570             break;
17571         case 'o':
17572             fUseBuffs ^= 1;
17573             break;
17574         case 'v':
17575             fVerbose ^= 1;
17576             break;
17577         case 'h':
17578             goto usage;
17579         default:
17580             goto usage;
17581         }
17582     }
17583 
17584     if ( pNtk == NULL )
17585     {
17586         Abc_Print( -1, "Empty network.\n" );
17587         return 1;
17588     }
17589 
17590     if ( fAreaOnly )
17591         DelayTarget = ABC_INFINITY;
17592 
17593     if ( !Abc_NtkIsStrash(pNtk) )
17594     {
17595         pNtk = Abc_NtkStrash( pNtk, 0, 0, 0 );
17596         if ( pNtk == NULL )
17597         {
17598             Abc_Print( -1, "Strashing before mapping has failed.\n" );
17599             return 1;
17600         }
17601         pNtk = Abc_NtkBalance( pNtkRes = pNtk, 0, 0, 1 );
17602         Abc_NtkDelete( pNtkRes );
17603         if ( pNtk == NULL )
17604         {
17605             Abc_Print( -1, "Balancing before mapping has failed.\n" );
17606             return 1;
17607         }
17608         Abc_Print( 0, "The network was strashed and balanced before mapping.\n" );
17609         // get the new network
17610         pNtkRes = Abc_NtkMap( pNtk, DelayTarget, AreaMulti, DelayMulti, LogFan, Slew, Gain, nGatesMin, fRecovery, fSwitching, fSkipFanout, fUseProfile, fUseBuffs, fVerbose );
17611         if ( pNtkRes == NULL )
17612         {
17613             Abc_NtkDelete( pNtk );
17614             Abc_Print( -1, "Mapping has failed.\n" );
17615             return 1;
17616         }
17617         Abc_NtkDelete( pNtk );
17618     }
17619     else
17620     {
17621         // get the new network
17622         pNtkRes = Abc_NtkMap( pNtk, DelayTarget, AreaMulti, DelayMulti, LogFan, Slew, Gain, nGatesMin, fRecovery, fSwitching, fSkipFanout, fUseProfile, fUseBuffs, fVerbose );
17623         if ( pNtkRes == NULL )
17624         {
17625             Abc_Print( -1, "Mapping has failed.\n" );
17626             return 1;
17627         }
17628     }
17629 
17630     if ( fSweep )
17631     {
17632         Abc_NtkFraigSweep( pNtkRes, 0, 0, 0, 0 );
17633         if ( Abc_NtkHasMapping(pNtkRes) )
17634         {
17635             pNtkRes = Abc_NtkDupDfs( pNtk = pNtkRes );
17636             Abc_NtkDelete( pNtk );
17637         }
17638     }
17639 
17640     // replace the current network
17641     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
17642     return 0;
17643 
17644 usage:
17645     if ( DelayTarget == -1 )
17646         sprintf(Buffer, "not used" );
17647     else
17648         sprintf(Buffer, "%.3f", DelayTarget );
17649     Abc_Print( -2, "usage: map [-DABFSG float] [-M num] [-arspfuovh]\n" );
17650     Abc_Print( -2, "\t           performs standard cell mapping of the current network\n" );
17651     Abc_Print( -2, "\t-D float : sets the global required times [default = %s]\n", Buffer );
17652     Abc_Print( -2, "\t-A float : \"area multiplier\" to bias gate selection [default = %.2f]\n", AreaMulti );
17653     Abc_Print( -2, "\t-B float : \"delay multiplier\" to bias gate selection [default = %.2f]\n", DelayMulti );
17654     Abc_Print( -2, "\t-F float : the logarithmic fanout delay parameter [default = %.2f]\n", LogFan );
17655     Abc_Print( -2, "\t-S float : the slew parameter used to generate the library [default = %.2f]\n", Slew );
17656     Abc_Print( -2, "\t-G float : the gain parameter used to generate the library [default = %.2f]\n", Gain );
17657     Abc_Print( -2, "\t-M num   : skip gate classes whose size is less than this [default = %d]\n", nGatesMin );
17658     Abc_Print( -2, "\t-a       : toggles area-only mapping [default = %s]\n", fAreaOnly? "yes": "no" );
17659     Abc_Print( -2, "\t-r       : toggles area recovery [default = %s]\n", fRecovery? "yes": "no" );
17660     Abc_Print( -2, "\t-s       : toggles sweep after mapping [default = %s]\n", fSweep? "yes": "no" );
17661     Abc_Print( -2, "\t-p       : optimizes power by minimizing switching [default = %s]\n", fSwitching? "yes": "no" );
17662     Abc_Print( -2, "\t-f       : do not use large gates to map high-fanout nodes [default = %s]\n", fSkipFanout? "yes": "no" );
17663     Abc_Print( -2, "\t-u       : use standard-cell profile [default = %s]\n", fUseProfile? "yes": "no" );
17664     Abc_Print( -2, "\t-o       : toggles using buffers to decouple combinational outputs [default = %s]\n", fUseBuffs? "yes": "no" );
17665     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n", fVerbose? "yes": "no" );
17666     Abc_Print( -2, "\t-h       : print the command usage\n");
17667     return 1;
17668 }
17669 
17670 /**Function*************************************************************
17671 
17672   Synopsis    []
17673 
17674   Description []
17675 
17676   SideEffects []
17677 
17678   SeeAlso     []
17679 
17680 ***********************************************************************/
Abc_CommandAmap(Abc_Frame_t * pAbc,int argc,char ** argv)17681 int Abc_CommandAmap( Abc_Frame_t * pAbc, int argc, char ** argv )
17682 {
17683     Amap_Par_t Pars, * pPars = &Pars;
17684     Abc_Ntk_t * pNtk, * pNtkRes;
17685     int fSweep;
17686     int c;
17687     extern Abc_Ntk_t * Abc_NtkDarAmap( Abc_Ntk_t * pNtk, Amap_Par_t * pPars );
17688     extern int Abc_NtkFraigSweep( Abc_Ntk_t * pNtk, int fUseInv, int fExdc, int fVerbose, int fVeryVerbose );
17689 
17690     pNtk = Abc_FrameReadNtk(pAbc);
17691     // set defaults
17692     fSweep = 0;
17693     Amap_ManSetDefaultParams( pPars );
17694     Extra_UtilGetoptReset();
17695     while ( ( c = Extra_UtilGetopt( argc, argv, "FACEQmxisvh" ) ) != EOF )
17696     {
17697         switch ( c )
17698         {
17699         case 'F':
17700             if ( globalUtilOptind >= argc )
17701             {
17702                 Abc_Print( -1, "Command line switch \"-F\" should be followed by a floating point number.\n" );
17703                 goto usage;
17704             }
17705             pPars->nIterFlow = atoi(argv[globalUtilOptind]);
17706             globalUtilOptind++;
17707             if ( pPars->nIterFlow < 0 )
17708                 goto usage;
17709             break;
17710         case 'A':
17711             if ( globalUtilOptind >= argc )
17712             {
17713                 Abc_Print( -1, "Command line switch \"-A\" should be followed by a floating point number.\n" );
17714                 goto usage;
17715             }
17716             pPars->nIterArea = atoi(argv[globalUtilOptind]);
17717             globalUtilOptind++;
17718             if ( pPars->nIterArea < 0 )
17719                 goto usage;
17720             break;
17721         case 'C':
17722             if ( globalUtilOptind >= argc )
17723             {
17724                 Abc_Print( -1, "Command line switch \"-C\" should be followed by a floating point number.\n" );
17725                 goto usage;
17726             }
17727             pPars->nCutsMax = atoi(argv[globalUtilOptind]);
17728             globalUtilOptind++;
17729             if ( pPars->nCutsMax < 0 )
17730                 goto usage;
17731             break;
17732         case 'E':
17733             if ( globalUtilOptind >= argc )
17734             {
17735                 Abc_Print( -1, "Command line switch \"-E\" should be followed by a floating point number.\n" );
17736                 goto usage;
17737             }
17738             pPars->fEpsilon = (float)atof(argv[globalUtilOptind]);
17739             globalUtilOptind++;
17740             if ( pPars->fEpsilon < 0.0 || pPars->fEpsilon > 1.0 )
17741                 goto usage;
17742             break;
17743         case 'Q':
17744             if ( globalUtilOptind >= argc )
17745             {
17746                 Abc_Print( -1, "Command line switch \"-Q\" should be followed by a floating point number.\n" );
17747                 goto usage;
17748             }
17749             pPars->fADratio = (float)atof(argv[globalUtilOptind]);
17750             globalUtilOptind++;
17751             if ( pPars->fADratio < 0.0 )
17752                 goto usage;
17753             break;
17754         case 'm':
17755             pPars->fUseMuxes ^= 1;
17756             break;
17757         case 'x':
17758             pPars->fUseXors ^= 1;
17759             break;
17760         case 'i':
17761             pPars->fFreeInvs ^= 1;
17762             break;
17763         case 's':
17764             fSweep ^= 1;
17765             break;
17766         case 'v':
17767             pPars->fVerbose ^= 1;
17768             break;
17769         case 'h':
17770             goto usage;
17771         default:
17772             goto usage;
17773         }
17774     }
17775 
17776     if ( pNtk == NULL )
17777     {
17778         Abc_Print( -1, "Empty network.\n" );
17779         return 1;
17780     }
17781 
17782     if ( !Abc_NtkIsStrash(pNtk) )
17783     {
17784         pNtk = Abc_NtkStrash( pNtk, 0, 0, 0 );
17785         if ( pNtk == NULL )
17786         {
17787             Abc_Print( -1, "Strashing before mapping has failed.\n" );
17788             return 1;
17789         }
17790         pNtk = Abc_NtkBalance( pNtkRes = pNtk, 0, 0, 1 );
17791         Abc_NtkDelete( pNtkRes );
17792         if ( pNtk == NULL )
17793         {
17794             Abc_Print( -1, "Balancing before mapping has failed.\n" );
17795             return 1;
17796         }
17797         Abc_Print( 0, "The network was strashed and balanced before mapping.\n" );
17798         // get the new network
17799         pNtkRes = Abc_NtkDarAmap( pNtk, pPars );
17800         if ( pNtkRes == NULL )
17801         {
17802             Abc_NtkDelete( pNtk );
17803             Abc_Print( -1, "Mapping has failed.\n" );
17804             return 1;
17805         }
17806         Abc_NtkDelete( pNtk );
17807     }
17808     else
17809     {
17810         // get the new network
17811         pNtkRes = Abc_NtkDarAmap( pNtk, pPars );
17812         if ( pNtkRes == NULL )
17813         {
17814             Abc_Print( -1, "Mapping has failed.\n" );
17815             return 1;
17816         }
17817     }
17818 
17819     if ( fSweep )
17820     {
17821         Abc_NtkFraigSweep( pNtkRes, 0, 0, 0, 0 );
17822         if ( Abc_NtkHasMapping(pNtkRes) )
17823         {
17824             pNtkRes = Abc_NtkDupDfs( pNtk = pNtkRes );
17825             Abc_NtkDelete( pNtk );
17826         }
17827     }
17828     // replace the current network
17829     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
17830     return 0;
17831 
17832 usage:
17833     Abc_Print( -2, "usage: amap [-FAC <num>] [-EQ <float>] [-mxisvh]\n" );
17834     Abc_Print( -2, "\t           performs standard cell mapping of the current network\n" );
17835     Abc_Print( -2, "\t-F num   : the number of iterations of area flow [default = %d]\n", pPars->nIterFlow );
17836     Abc_Print( -2, "\t-A num   : the number of iterations of exact area [default = %d]\n", pPars->nIterArea );
17837     Abc_Print( -2, "\t-C num   : the maximum number of cuts at a node [default = %d]\n", pPars->nCutsMax );
17838     Abc_Print( -2, "\t-E float : sets epsilon used for tie-breaking [default = %f]\n", pPars->fEpsilon );
17839     Abc_Print( -2, "\t-Q float : area/delay preference ratio [default = %.2f (area-only)] \n", pPars->fADratio );
17840     Abc_Print( -2, "\t-m       : toggles using MUX matching [default = %s]\n", pPars->fUseMuxes? "yes": "no" );
17841     Abc_Print( -2, "\t-x       : toggles using XOR matching [default = %s]\n", pPars->fUseXors? "yes": "no" );
17842     Abc_Print( -2, "\t-i       : toggles assuming inverters are free [default = %s]\n", pPars->fFreeInvs? "yes": "no" );
17843     Abc_Print( -2, "\t-s       : toggles sweep after mapping [default = %s]\n", fSweep? "yes": "no" );
17844     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
17845     Abc_Print( -2, "\t-h       : print the command usage\n");
17846     return 1;
17847 }
17848 
17849 /**Function*************************************************************
17850 
17851   Synopsis    []
17852 
17853   Description []
17854 
17855   SideEffects []
17856 
17857   SeeAlso     []
17858 
17859 ***********************************************************************/
Abc_CommandPhaseMap(Abc_Frame_t * pAbc,int argc,char ** argv)17860 int Abc_CommandPhaseMap( Abc_Frame_t * pAbc, int argc, char ** argv )
17861 {
17862     extern void Abc_NtkChangePerform( Abc_Ntk_t * pNtk, int fVerbose );
17863     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
17864     int fVerbose = 0, c;
17865     // set defaults
17866     Extra_UtilGetoptReset();
17867     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
17868     {
17869         switch ( c )
17870         {
17871         case 'v':
17872             fVerbose ^= 1;
17873             break;
17874         case 'h':
17875             goto usage;
17876         default:
17877             goto usage;
17878         }
17879     }
17880 
17881     if ( pNtk == NULL )
17882     {
17883         Abc_Print( -1, "Empty network.\n" );
17884         return 1;
17885     }
17886     if ( !Abc_NtkHasMapping(pNtk) )
17887     {
17888         Abc_Print( -1, "Cannot unmap the network that is not mapped.\n" );
17889         return 1;
17890     }
17891     Abc_NtkChangePerform( pNtk, fVerbose );
17892     return 0;
17893 
17894 usage:
17895     Abc_Print( -2, "usage: phase_map [-vh]\n" );
17896     Abc_Print( -2, "\t        tries to replace each gate by its complement (area-only)\n" );
17897     Abc_Print( -2, "\t-v    : toggles verbose output [default = %s]\n", fVerbose? "yes": "no" );
17898     Abc_Print( -2, "\t-h    : print the command usage\n");
17899     return 1;
17900 }
17901 
17902 
17903 /**Function*************************************************************
17904 
17905   Synopsis    []
17906 
17907   Description []
17908 
17909   SideEffects []
17910 
17911   SeeAlso     []
17912 
17913 ***********************************************************************/
Abc_CommandUnmap(Abc_Frame_t * pAbc,int argc,char ** argv)17914 int Abc_CommandUnmap( Abc_Frame_t * pAbc, int argc, char ** argv )
17915 {
17916     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
17917     int c;
17918     // set defaults
17919     Extra_UtilGetoptReset();
17920     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
17921     {
17922         switch ( c )
17923         {
17924         case 'h':
17925             goto usage;
17926         default:
17927             goto usage;
17928         }
17929     }
17930 
17931     if ( pNtk == NULL )
17932     {
17933         Abc_Print( -1, "Empty network.\n" );
17934         return 1;
17935     }
17936     if ( !Abc_NtkHasMapping(pNtk) )
17937     {
17938         Abc_Print( -1, "Cannot unmap the network that is not mapped.\n" );
17939         return 1;
17940     }
17941 
17942     // get the new network
17943     if ( !Abc_NtkMapToSop( pNtk ) )
17944     {
17945         Abc_Print( -1, "Unmapping has failed.\n" );
17946         return 1;
17947     }
17948     return 0;
17949 
17950 usage:
17951     Abc_Print( -2, "usage: unmap [-h]\n" );
17952     Abc_Print( -2, "\t        replaces the library gates by the logic nodes represented using SOPs\n" );
17953     Abc_Print( -2, "\t-h    : print the command usage\n");
17954     return 1;
17955 }
17956 
17957 /**Function*************************************************************
17958 
17959   Synopsis    []
17960 
17961   Description []
17962 
17963   SideEffects []
17964 
17965   SeeAlso     []
17966 
17967 ***********************************************************************/
Abc_CommandAttach(Abc_Frame_t * pAbc,int argc,char ** argv)17968 int Abc_CommandAttach( Abc_Frame_t * pAbc, int argc, char ** argv )
17969 {
17970     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
17971     int c;
17972     // set defaults
17973     Extra_UtilGetoptReset();
17974     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
17975     {
17976         switch ( c )
17977         {
17978         case 'h':
17979             goto usage;
17980         default:
17981             goto usage;
17982         }
17983     }
17984 
17985     if ( pNtk == NULL )
17986     {
17987         Abc_Print( -1, "Empty network.\n" );
17988         return 1;
17989     }
17990 
17991     if ( !Abc_NtkIsSopLogic(pNtk) )
17992     {
17993         Abc_Print( -1, "Can only attach gates if the nodes have SOP representations.\n" );
17994         return 1;
17995     }
17996 
17997     // get the new network
17998     if ( !Abc_NtkAttach( pNtk ) )
17999     {
18000         Abc_Print( -1, "Attaching gates has failed.\n" );
18001         return 1;
18002     }
18003     return 0;
18004 
18005 usage:
18006     Abc_Print( -2, "usage: attach [-h]\n" );
18007     Abc_Print( -2, "\t        replaces the SOP functions by the gates from the library\n" );
18008     Abc_Print( -2, "\t-h    : print the command usage\n");
18009     return 1;
18010 }
18011 
18012 
18013 /**Function*************************************************************
18014 
18015   Synopsis    []
18016 
18017   Description []
18018 
18019   SideEffects []
18020 
18021   SeeAlso     []
18022 
18023 ***********************************************************************/
Abc_CommandSuperChoice(Abc_Frame_t * pAbc,int argc,char ** argv)18024 int Abc_CommandSuperChoice( Abc_Frame_t * pAbc, int argc, char ** argv )
18025 {
18026     Abc_Ntk_t * pNtk, * pNtkRes;
18027     int c;
18028     extern Abc_Ntk_t * Abc_NtkSuperChoice( Abc_Ntk_t * pNtk );
18029 
18030     pNtk = Abc_FrameReadNtk(pAbc);
18031     // set defaults
18032     Extra_UtilGetoptReset();
18033     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
18034     {
18035         switch ( c )
18036         {
18037         case 'h':
18038             goto usage;
18039         default:
18040             goto usage;
18041         }
18042     }
18043 
18044     if ( pNtk == NULL )
18045     {
18046         Abc_Print( -1, "Empty network.\n" );
18047         return 1;
18048     }
18049 
18050     if ( !Abc_NtkIsStrash(pNtk) )
18051     {
18052         Abc_Print( -1, "Superchoicing works only for the AIG representation (run \"strash\").\n" );
18053         return 1;
18054     }
18055 
18056     // get the new network
18057     pNtkRes = Abc_NtkSuperChoice( pNtk );
18058     if ( pNtkRes == NULL )
18059     {
18060         Abc_Print( -1, "Superchoicing has failed.\n" );
18061         return 1;
18062     }
18063     // replace the current network
18064     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
18065     return 0;
18066 
18067 usage:
18068     Abc_Print( -2, "usage: superc [-h]\n" );
18069     Abc_Print( -2, "\t      performs superchoicing\n" );
18070     Abc_Print( -2, "\t      (accumulate: \"r file.blif; rsup; b; sc; f -ac; wb file_sc.blif\")\n" );
18071     Abc_Print( -2, "\t      (map without supergate library: \"r file_sc.blif; ft; map\")\n" );
18072     Abc_Print( -2, "\t-h  : print the command usage\n");
18073     return 1;
18074 }
18075 
18076 /**Function*************************************************************
18077 
18078   Synopsis    []
18079 
18080   Description []
18081 
18082   SideEffects []
18083 
18084   SeeAlso     []
18085 
18086 ***********************************************************************/
Abc_CommandSuperChoiceLut(Abc_Frame_t * pAbc,int argc,char ** argv)18087 int Abc_CommandSuperChoiceLut( Abc_Frame_t * pAbc, int argc, char ** argv )
18088 {
18089     Abc_Ntk_t * pNtk, * pNtkRes;
18090     int c;
18091     int nLutSize;
18092     int nCutSizeMax;
18093     int fVerbose;
18094     extern int Abc_NtkSuperChoiceLut( Abc_Ntk_t * pNtk, int nLutSize, int nCutSizeMax, int fVerbose );
18095 
18096     pNtk = Abc_FrameReadNtk(pAbc);
18097     // set defaults
18098     fVerbose = 1;
18099     nLutSize = 4;
18100     nCutSizeMax = 10;
18101     Extra_UtilGetoptReset();
18102     while ( ( c = Extra_UtilGetopt( argc, argv, "KNh" ) ) != EOF )
18103     {
18104         switch ( c )
18105         {
18106         case 'K':
18107             if ( globalUtilOptind >= argc )
18108             {
18109                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a positive integer.\n" );
18110                 goto usage;
18111             }
18112             nLutSize = atoi(argv[globalUtilOptind]);
18113             globalUtilOptind++;
18114             if ( nLutSize < 0 )
18115                 goto usage;
18116             break;
18117         case 'N':
18118             if ( globalUtilOptind >= argc )
18119             {
18120                 Abc_Print( -1, "Command line switch \"-N\" should be followed by a positive integer.\n" );
18121                 goto usage;
18122             }
18123             nCutSizeMax = atoi(argv[globalUtilOptind]);
18124             globalUtilOptind++;
18125             if ( nCutSizeMax < 0 )
18126                 goto usage;
18127             break;
18128         case 'v':
18129             fVerbose ^= 1;
18130             break;
18131         case 'h':
18132             goto usage;
18133         default:
18134             goto usage;
18135         }
18136     }
18137 
18138     if ( pNtk == NULL )
18139     {
18140         Abc_Print( -1, "Empty network.\n" );
18141         return 1;
18142     }
18143 
18144     if ( !Abc_NtkIsStrash(pNtk) )
18145     {
18146         Abc_Print( -1, "Superchoicing works only for the AIG representation (run \"strash\").\n" );
18147         return 1;
18148     }
18149 
18150     // convert the network into the SOP network
18151     pNtkRes = Abc_NtkToLogic( pNtk );
18152 
18153     // get the new network
18154     if ( !Abc_NtkSuperChoiceLut( pNtkRes, nLutSize, nCutSizeMax, fVerbose ) )
18155     {
18156         Abc_NtkDelete( pNtkRes );
18157         Abc_Print( -1, "Superchoicing has failed.\n" );
18158         return 1;
18159     }
18160     // replace the current network
18161     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
18162     return 0;
18163 
18164 usage:
18165     Abc_Print( -2, "usage: supercl [-K num] [-N num] [-vh]\n" );
18166     Abc_Print( -2, "\t        performs superchoicing for K-LUTs\n" );
18167     Abc_Print( -2, "\t        (accumulate: \"r file.blif; b; scl; f -ac; wb file_sc.blif\")\n" );
18168     Abc_Print( -2, "\t        (FPGA map: \"r file_sc.blif; ft; read_lut lutlibK; fpga\")\n" );
18169     Abc_Print( -2, "\t-K num : the number of LUT inputs [default = %d]\n", nLutSize );
18170     Abc_Print( -2, "\t-N num : the max size of the cut [default = %d]\n", nCutSizeMax );
18171     Abc_Print( -2, "\t-v     : toggles verbose output [default = %s]\n", fVerbose? "yes": "no" );
18172     Abc_Print( -2, "\t-h     : print the command usage\n");
18173     return 1;
18174 }
18175 
18176 /**Function*************************************************************
18177 
18178   Synopsis    []
18179 
18180   Description []
18181 
18182   SideEffects []
18183 
18184   SeeAlso     []
18185 
18186 ***********************************************************************/
Abc_CommandTimeScale(Abc_Frame_t * pAbc,int argc,char ** argv)18187 int Abc_CommandTimeScale( Abc_Frame_t * pAbc, int argc, char ** argv )
18188 {
18189     extern void Abc_NtkTimeScale( Abc_Ntk_t * pNtk, float Scale );
18190     Abc_Ntk_t * pNtk;
18191     float nTimeScale;
18192     int c, fVerbose;
18193 
18194     pNtk = Abc_FrameReadNtk(pAbc);
18195     // set defaults
18196     nTimeScale = (float)0.01;
18197     fVerbose = 0;
18198     Extra_UtilGetoptReset();
18199     while ( ( c = Extra_UtilGetopt( argc, argv, "Th" ) ) != EOF )
18200     {
18201         switch ( c )
18202         {
18203         case 'T':
18204             if ( globalUtilOptind >= argc )
18205             {
18206                 Abc_Print( -1, "Command line switch \"-T\" should be followed by a positive integer.\n" );
18207                 goto usage;
18208             }
18209             nTimeScale = atof(argv[globalUtilOptind]);
18210             globalUtilOptind++;
18211             if ( nTimeScale < 0 )
18212                 goto usage;
18213             break;
18214         case 'v':
18215             fVerbose ^= 1;
18216             break;
18217         case 'h':
18218             goto usage;
18219         default:
18220             goto usage;
18221         }
18222     }
18223 
18224     if ( pNtk == NULL )
18225     {
18226         Abc_Print( -1, "Empty network.\n" );
18227         return 1;
18228     }
18229     if ( pNtk->pManTime == NULL )
18230     {
18231         Abc_Print( -1, "Timing manager is not defined.\n" );
18232         return 1;
18233     }
18234     Abc_NtkTimeScale( pNtk, nTimeScale );
18235     return 0;
18236 
18237 usage:
18238     Abc_Print( -2, "usage: timescale [-T float] [-vh]\n" );
18239     Abc_Print( -2, "\t           scales timing information of the current network\n" );
18240     Abc_Print( -2, "\t-T float : multiplicative factor [default = %f]\n", nTimeScale );
18241     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n", fVerbose? "yes": "no" );
18242     Abc_Print( -2, "\t-h       : print the command usage\n");
18243     return 1;
18244 }
18245 
18246 /**Function*************************************************************
18247 
18248   Synopsis    []
18249 
18250   Description []
18251 
18252   SideEffects []
18253 
18254   SeeAlso     []
18255 
18256 ***********************************************************************/
18257 #if 0
18258 int Abc_CommandFpga( Abc_Frame_t * pAbc, int argc, char ** argv )
18259 {
18260     char Buffer[100];
18261     char LutSize[100];
18262     Abc_Ntk_t * pNtk, * pNtkRes;
18263     int c;
18264     int fRecovery;
18265     int fSwitching;
18266     int fLatchPaths;
18267     int fVerbose;
18268     int nLutSize;
18269     float DelayTarget;
18270 
18271     extern Abc_Ntk_t * Abc_NtkFpga( Abc_Ntk_t * pNtk, float DelayTarget, int fRecovery, int fSwitching, int fLatchPaths, int fVerbose );
18272 
18273     pNtk = Abc_FrameReadNtk(pAbc);
18274     // set defaults
18275     fRecovery   = 1;
18276     fSwitching  = 0;
18277     fLatchPaths = 0;
18278     fVerbose    = 0;
18279     DelayTarget =-1;
18280     nLutSize    =-1;
18281     Extra_UtilGetoptReset();
18282     while ( ( c = Extra_UtilGetopt( argc, argv, "aplvhDK" ) ) != EOF )
18283     {
18284         switch ( c )
18285         {
18286         case 'a':
18287             fRecovery ^= 1;
18288             break;
18289         case 'p':
18290             fSwitching ^= 1;
18291             break;
18292         case 'l':
18293             fLatchPaths ^= 1;
18294             break;
18295         case 'v':
18296             fVerbose ^= 1;
18297             break;
18298         case 'h':
18299             goto usage;
18300         case 'D':
18301             if ( globalUtilOptind >= argc )
18302             {
18303                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a floating point number.\n" );
18304                 goto usage;
18305             }
18306             DelayTarget = (float)atof(argv[globalUtilOptind]);
18307             globalUtilOptind++;
18308             if ( DelayTarget <= 0.0 )
18309                 goto usage;
18310             break;
18311         case 'K':
18312             if ( globalUtilOptind >= argc )
18313             {
18314                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a positive integer.\n" );
18315                 goto usage;
18316             }
18317             nLutSize = atoi(argv[globalUtilOptind]);
18318             globalUtilOptind++;
18319             if ( nLutSize < 0 )
18320                 goto usage;
18321             break;
18322         default:
18323             goto usage;
18324         }
18325     }
18326 
18327     if ( pNtk == NULL )
18328     {
18329         Abc_Print( -1, "Empty network.\n" );
18330         return 1;
18331     }
18332 
18333     // create the new LUT library
18334     if ( nLutSize >= 3 && nLutSize <= 10 )
18335         Fpga_SetSimpleLutLib( nLutSize );
18336 /*
18337     else
18338     {
18339         Abc_Print( -1, "Cannot perform FPGA mapping with LUT size %d.\n", nLutSize );
18340         return 1;
18341     }
18342 */
18343     if ( !Abc_NtkIsStrash(pNtk) )
18344     {
18345         // strash and balance the network
18346         pNtk = Abc_NtkStrash( pNtk, 0, 0, 0 );
18347         if ( pNtk == NULL )
18348         {
18349             Abc_Print( -1, "Strashing before FPGA mapping has failed.\n" );
18350             return 1;
18351         }
18352         pNtk = Abc_NtkBalance( pNtkRes = pNtk, 0, 0, 1 );
18353         Abc_NtkDelete( pNtkRes );
18354         if ( pNtk == NULL )
18355         {
18356             Abc_Print( -1, "Balancing before FPGA mapping has failed.\n" );
18357             return 1;
18358         }
18359         Abc_Print( 1, "The network was strashed and balanced before FPGA mapping.\n" );
18360         // get the new network
18361         pNtkRes = Abc_NtkFpga( pNtk, DelayTarget, fRecovery, fSwitching, fLatchPaths, fVerbose );
18362         if ( pNtkRes == NULL )
18363         {
18364             Abc_NtkDelete( pNtk );
18365             Abc_Print( -1, "FPGA mapping has failed.\n" );
18366             return 1;
18367         }
18368         Abc_NtkDelete( pNtk );
18369     }
18370     else
18371     {
18372         // get the new network
18373         pNtkRes = Abc_NtkFpga( pNtk, DelayTarget, fRecovery, fSwitching, fLatchPaths, fVerbose );
18374         if ( pNtkRes == NULL )
18375         {
18376             Abc_Print( -1, "FPGA mapping has failed.\n" );
18377             return 1;
18378         }
18379     }
18380     // replace the current network
18381     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
18382     return 0;
18383 
18384 usage:
18385     if ( DelayTarget == -1 )
18386         sprintf(Buffer, "best possible" );
18387     else
18388         sprintf(Buffer, "%.2f", DelayTarget );
18389     if ( nLutSize == -1 )
18390         sprintf(LutSize, "library" );
18391     else
18392         sprintf(LutSize, "%d", nLutSize );
18393     Abc_Print( -2, "usage: fpga [-D float] [-K num] [-aplvh]\n" );
18394     Abc_Print( -2, "\t           performs FPGA mapping of the current network\n" );
18395     Abc_Print( -2, "\t-a       : toggles area recovery [default = %s]\n", fRecovery? "yes": "no" );
18396     Abc_Print( -2, "\t-p       : optimizes power by minimizing switching activity [default = %s]\n", fSwitching? "yes": "no" );
18397     Abc_Print( -2, "\t-l       : optimizes latch paths for delay, other paths for area [default = %s]\n", fLatchPaths? "yes": "no" );
18398     Abc_Print( -2, "\t-D float : sets the required time for the mapping [default = %s]\n", Buffer );
18399     Abc_Print( -2, "\t-K num   : the number of LUT inputs (2 < num < 11) [default = %s]%s\n", LutSize, (nLutSize == -1 ? " (type \"print_lut\")" : "") );
18400     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n", fVerbose? "yes": "no" );
18401     Abc_Print( -2, "\t-h       : prints the command usage\n");
18402     return 1;
18403 }
18404 
18405 /**Function*************************************************************
18406 
18407   Synopsis    []
18408 
18409   Description []
18410 
18411   SideEffects []
18412 
18413   SeeAlso     []
18414 
18415 ***********************************************************************/
18416 int Abc_CommandFpgaFast( Abc_Frame_t * pAbc, int argc, char ** argv )
18417 {
18418     char Buffer[100];
18419     Abc_Ntk_t * pNtk, * pNtkRes;
18420     int c;
18421     int fRecovery;
18422     int fVerbose;
18423     int nLutSize;
18424     float DelayTarget;
18425 
18426     extern Abc_Ntk_t * Abc_NtkFpgaFast( Abc_Ntk_t * pNtk, int nLutSize, int fRecovery, int fVerbose );
18427 
18428     pNtk = Abc_FrameReadNtk(pAbc);
18429     // set defaults
18430     fRecovery   = 1;
18431     fVerbose    = 0;
18432     DelayTarget =-1;
18433     nLutSize    = 5;
18434     Extra_UtilGetoptReset();
18435     while ( ( c = Extra_UtilGetopt( argc, argv, "avhDK" ) ) != EOF )
18436     {
18437         switch ( c )
18438         {
18439         case 'a':
18440             fRecovery ^= 1;
18441             break;
18442         case 'v':
18443             fVerbose ^= 1;
18444             break;
18445         case 'h':
18446             goto usage;
18447         case 'D':
18448             if ( globalUtilOptind >= argc )
18449             {
18450                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a floating point number.\n" );
18451                 goto usage;
18452             }
18453             DelayTarget = (float)atof(argv[globalUtilOptind]);
18454             globalUtilOptind++;
18455             if ( DelayTarget <= 0.0 )
18456                 goto usage;
18457             break;
18458         case 'K':
18459             if ( globalUtilOptind >= argc )
18460             {
18461                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a positive integer.\n" );
18462                 goto usage;
18463             }
18464             nLutSize = atoi(argv[globalUtilOptind]);
18465             globalUtilOptind++;
18466             if ( nLutSize < 0 )
18467                 goto usage;
18468             break;
18469         default:
18470             goto usage;
18471         }
18472     }
18473 
18474     if ( pNtk == NULL )
18475     {
18476         Abc_Print( -1, "Empty network.\n" );
18477         return 1;
18478     }
18479 
18480     if ( !Abc_NtkIsStrash(pNtk) )
18481     {
18482         // strash and balance the network
18483         pNtk = Abc_NtkStrash( pNtk, 0, 0, 0 );
18484         if ( pNtk == NULL )
18485         {
18486             Abc_Print( -1, "Strashing before FPGA mapping has failed.\n" );
18487             return 1;
18488         }
18489         pNtk = Abc_NtkBalance( pNtkRes = pNtk, 0, 0, 1 );
18490         Abc_NtkDelete( pNtkRes );
18491         if ( pNtk == NULL )
18492         {
18493             Abc_Print( -1, "Balancing before FPGA mapping has failed.\n" );
18494             return 1;
18495         }
18496         Abc_Print( 1, "The network was strashed and balanced before FPGA mapping.\n" );
18497         // get the new network
18498         pNtkRes = Abc_NtkFpgaFast( pNtk, nLutSize, fRecovery, fVerbose );
18499         if ( pNtkRes == NULL )
18500         {
18501             Abc_NtkDelete( pNtk );
18502             Abc_Print( -1, "FPGA mapping has failed.\n" );
18503             return 1;
18504         }
18505         Abc_NtkDelete( pNtk );
18506     }
18507     else
18508     {
18509         // get the new network
18510         pNtkRes = Abc_NtkFpgaFast( pNtk, nLutSize, fRecovery, fVerbose );
18511         if ( pNtkRes == NULL )
18512         {
18513             Abc_Print( -1, "FPGA mapping has failed.\n" );
18514             return 1;
18515         }
18516     }
18517     // replace the current network
18518     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
18519     return 0;
18520 
18521 usage:
18522     if ( DelayTarget == -1 )
18523         sprintf(Buffer, "not used" );
18524     else
18525         sprintf(Buffer, "%.2f", DelayTarget );
18526     Abc_Print( -2, "usage: ffpga [-K num] [-avh]\n" );
18527     Abc_Print( -2, "\t           performs fast FPGA mapping of the current network\n" );
18528     Abc_Print( -2, "\t-a       : toggles area recovery [default = %s]\n", fRecovery? "yes": "no" );
18529 //    Abc_Print( -2, "\t-D float : sets the required time for the mapping [default = %s]\n", Buffer );
18530     Abc_Print( -2, "\t-K num   : the number of LUT inputs (2 < num < 32) [default = %d]\n", nLutSize );
18531     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n", fVerbose? "yes": "no" );
18532     Abc_Print( -2, "\t-h       : prints the command usage\n");
18533     return 1;
18534 }
18535 #endif
18536 
18537 /**Function*************************************************************
18538 
18539   Synopsis    []
18540 
18541   Description []
18542 
18543   SideEffects []
18544 
18545   SeeAlso     []
18546 
18547 ***********************************************************************/
Abc_CommandIf(Abc_Frame_t * pAbc,int argc,char ** argv)18548 int Abc_CommandIf( Abc_Frame_t * pAbc, int argc, char ** argv )
18549 {
18550     extern Abc_Ntk_t * Abc_NtkIf( Abc_Ntk_t * pNtk, If_Par_t * pPars );
18551     char Buffer[100], LutSize[100];
18552     Abc_Ntk_t * pNtk, * pNtkRes;
18553     If_Par_t Pars, * pPars = &Pars;
18554     int c;
18555     pNtk = Abc_FrameReadNtk(pAbc);
18556     If_ManSetDefaultPars( pPars );
18557     pPars->pLutLib = (If_LibLut_t *)Abc_FrameReadLibLut();
18558     Extra_UtilGetoptReset();
18559     while ( ( c = Extra_UtilGetopt( argc, argv, "KCFAGRNTXYDEWSqaflepmrsdbgxyuojiktncvh" ) ) != EOF )
18560     {
18561         switch ( c )
18562         {
18563         case 'K':
18564             if ( globalUtilOptind >= argc )
18565             {
18566                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a positive integer.\n" );
18567                 goto usage;
18568             }
18569             pPars->nLutSize = atoi(argv[globalUtilOptind]);
18570             globalUtilOptind++;
18571             if ( pPars->nLutSize < 0 )
18572                 goto usage;
18573             // if the LUT size is specified, disable library
18574             pPars->pLutLib = NULL;
18575             break;
18576         case 'C':
18577             if ( globalUtilOptind >= argc )
18578             {
18579                 Abc_Print( -1, "Command line switch \"-C\" should be followed by a positive integer.\n" );
18580                 goto usage;
18581             }
18582             pPars->nCutsMax = atoi(argv[globalUtilOptind]);
18583             globalUtilOptind++;
18584             if ( pPars->nCutsMax < 0 )
18585                 goto usage;
18586             break;
18587         case 'F':
18588             if ( globalUtilOptind >= argc )
18589             {
18590                 Abc_Print( -1, "Command line switch \"-F\" should be followed by a positive integer.\n" );
18591                 goto usage;
18592             }
18593             pPars->nFlowIters = atoi(argv[globalUtilOptind]);
18594             globalUtilOptind++;
18595             if ( pPars->nFlowIters < 0 )
18596                 goto usage;
18597             break;
18598         case 'A':
18599             if ( globalUtilOptind >= argc )
18600             {
18601                 Abc_Print( -1, "Command line switch \"-A\" should be followed by a positive integer.\n" );
18602                 goto usage;
18603             }
18604             pPars->nAreaIters = atoi(argv[globalUtilOptind]);
18605             globalUtilOptind++;
18606             if ( pPars->nAreaIters < 0 )
18607                 goto usage;
18608             break;
18609         case 'G':
18610             if ( globalUtilOptind >= argc )
18611             {
18612                 Abc_Print( -1, "Command line switch \"-G\" should be followed by a positive integer no less than 3.\n" );
18613                 goto usage;
18614             }
18615             pPars->nGateSize = atoi(argv[globalUtilOptind]);
18616             globalUtilOptind++;
18617             if ( pPars->nGateSize < 2 )
18618                 goto usage;
18619             break;
18620         case 'R':
18621             if ( globalUtilOptind >= argc )
18622             {
18623                 Abc_Print( 1, "Command line switch \"-R\" should be followed by a floating point number.\n" );
18624                 return 0;
18625             }
18626             pPars->nRelaxRatio = atoi(argv[globalUtilOptind]);
18627             globalUtilOptind++;
18628             if ( pPars->nRelaxRatio < 0 )
18629                 goto usage;
18630             break;
18631         case 'N':
18632             if ( globalUtilOptind >= argc )
18633             {
18634                 Abc_Print( -1, "Command line switch \"-N\" should be followed by a positive integer no less than 3.\n" );
18635                 goto usage;
18636             }
18637             pPars->nNonDecLimit = atoi(argv[globalUtilOptind]);
18638             globalUtilOptind++;
18639             if ( pPars->nNonDecLimit < 2 )
18640                 goto usage;
18641             break;
18642         case 'T':
18643             if ( globalUtilOptind >= argc )
18644             {
18645                 Abc_Print( -1, "Command line switch \"-T\" should be followed by a positive integer 0,1,or 2.\n" );
18646                 goto usage;
18647             }
18648             pPars->nStructType = atoi(argv[globalUtilOptind]);
18649             globalUtilOptind++;
18650             if ( pPars->nStructType < 0 || pPars->nStructType > 2 )
18651                 goto usage;
18652             break;
18653         case 'X':
18654             if ( globalUtilOptind >= argc )
18655             {
18656                 Abc_Print( -1, "Command line switch \"-X\" should be followed by a positive integer 0,1,or 2.\n" );
18657                 goto usage;
18658             }
18659             pPars->nAndDelay = atoi(argv[globalUtilOptind]);
18660             globalUtilOptind++;
18661             if ( pPars->nAndArea < 0 )
18662                 goto usage;
18663             break;
18664         case 'Y':
18665             if ( globalUtilOptind >= argc )
18666             {
18667                 Abc_Print( -1, "Command line switch \"-Y\" should be followed by a positive integer 0,1,or 2.\n" );
18668                 goto usage;
18669             }
18670             pPars->nAndArea = atoi(argv[globalUtilOptind]);
18671             globalUtilOptind++;
18672             if ( pPars->nAndDelay < 0 )
18673                 goto usage;
18674             break;
18675         case 'D':
18676             if ( globalUtilOptind >= argc )
18677             {
18678                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a floating point number.\n" );
18679                 goto usage;
18680             }
18681             pPars->DelayTarget = (float)atof(argv[globalUtilOptind]);
18682             globalUtilOptind++;
18683             if ( pPars->DelayTarget <= 0.0 )
18684                 goto usage;
18685             break;
18686         case 'E':
18687             if ( globalUtilOptind >= argc )
18688             {
18689                 Abc_Print( -1, "Command line switch \"-E\" should be followed by a floating point number.\n" );
18690                 goto usage;
18691             }
18692             pPars->Epsilon = (float)atof(argv[globalUtilOptind]);
18693             globalUtilOptind++;
18694             if ( pPars->Epsilon < 0.0 || pPars->Epsilon > 1.0 )
18695                 goto usage;
18696             break;
18697         case 'W':
18698             if ( globalUtilOptind >= argc )
18699             {
18700                 Abc_Print( -1, "Command line switch \"-W\" should be followed by a floating point number.\n" );
18701                 goto usage;
18702             }
18703             pPars->WireDelay = (float)atof(argv[globalUtilOptind]);
18704             globalUtilOptind++;
18705             if ( pPars->WireDelay < 0.0 )
18706                 goto usage;
18707             break;
18708         case 'S':
18709             if ( globalUtilOptind >= argc )
18710             {
18711                 Abc_Print( -1, "Command line switch \"-S\" should be followed by string.\n" );
18712                 goto usage;
18713             }
18714             pPars->pLutStruct = argv[globalUtilOptind];
18715             globalUtilOptind++;
18716             if ( strlen(pPars->pLutStruct) != 2 && strlen(pPars->pLutStruct) != 3 )
18717             {
18718                 Abc_Print( -1, "Command line switch \"-S\" should be followed by a 2- or 3-char string (e.g. \"44\" or \"555\").\n" );
18719                 goto usage;
18720             }
18721             break;
18722         case 'q':
18723             pPars->fPreprocess ^= 1;
18724             break;
18725         case 'a':
18726             pPars->fArea ^= 1;
18727             break;
18728         case 'r':
18729             pPars->fExpRed ^= 1;
18730             break;
18731         case 'f':
18732             pPars->fFancy ^= 1;
18733             break;
18734         case 'l':
18735             pPars->fLatchPaths ^= 1;
18736             break;
18737         case 'e':
18738             pPars->fEdge ^= 1;
18739             break;
18740         case 'p':
18741             pPars->fPower ^= 1;
18742             break;
18743         case 'm':
18744             pPars->fCutMin ^= 1;
18745             break;
18746         case 's':
18747             pPars->fDelayOptLut ^= 1;
18748             break;
18749         case 'd':
18750             pPars->fBidec ^= 1;
18751             break;
18752         case 'b':
18753             pPars->fUseBat ^= 1;
18754             break;
18755         case 'g':
18756             pPars->fDelayOpt ^= 1;
18757             break;
18758         case 'x':
18759             pPars->fDsdBalance ^= 1;
18760             break;
18761         case 'y':
18762             pPars->fUserRecLib ^= 1;
18763             break;
18764         case 'u':
18765             pPars->fUserSesLib ^= 1;
18766             break;
18767         case 'o':
18768             pPars->fUseBuffs ^= 1;
18769             break;
18770         case 'j':
18771             pPars->fEnableCheck07 ^= 1;
18772             break;
18773         case 'i':
18774             pPars->fUseCofVars ^= 1;
18775             break;
18776         case 'k':
18777             pPars->fUseDsdTune ^= 1;
18778             break;
18779         case 't':
18780             pPars->fDoAverage ^= 1;
18781             break;
18782         case 'n':
18783             pPars->fUseDsd ^= 1;
18784             break;
18785         case 'c':
18786             pPars->fUseTtPerm ^= 1;
18787             break;
18788         case 'v':
18789             pPars->fVerbose ^= 1;
18790             break;
18791         case 'h':
18792         default:
18793             goto usage;
18794         }
18795     }
18796     if ( pNtk == NULL )
18797     {
18798         Abc_Print( -1, "Empty network.\n" );
18799         return 1;
18800     }
18801     if ( pPars->nLutSize == -1 )
18802     {
18803         if ( pPars->pLutLib == NULL )
18804         {
18805             Abc_Print( -1, "The LUT library is not given.\n" );
18806             return 1;
18807         }
18808         pPars->nLutSize = pPars->pLutLib->LutMax;
18809     }
18810 
18811     if ( pPars->nLutSize < 2 || pPars->nLutSize > IF_MAX_LUTSIZE )
18812     {
18813         Abc_Print( -1, "Incorrect LUT size (%d).\n", pPars->nLutSize );
18814         return 1;
18815     }
18816 
18817     if ( pPars->nCutsMax < 1 || pPars->nCutsMax >= (1<<12) )
18818     {
18819         Abc_Print( -1, "Incorrect number of cuts.\n" );
18820         return 1;
18821     }
18822 
18823     // enable truth table computation if choices are selected
18824     if ( (c = Abc_NtkGetChoiceNum( pNtk )) )
18825     {
18826 //        if ( !Abc_FrameReadFlag("silentmode") )
18827 //            Abc_Print( 0, "Performing LUT mapping with %d choices.\n", c );
18828         pPars->fExpRed = 0;
18829     }
18830 
18831     if ( pPars->fUseBat )
18832     {
18833         if ( pPars->nLutSize < 4 || pPars->nLutSize > 6 )
18834         {
18835             Abc_Print( -1, "This feature only works for {4,5,6}-LUTs.\n" );
18836             return 1;
18837         }
18838         pPars->fCutMin = 1;
18839     }
18840 
18841     if ( pPars->fEnableCheck07 + pPars->fUseCofVars + pPars->fUseDsdTune + (pPars->pLutStruct != NULL) > 1 )
18842     {
18843         Abc_Print( -1, "Only one additional check can be performed at the same time.\n" );
18844         return 1;
18845     }
18846     if ( pPars->fEnableCheck07 )
18847     {
18848         if ( pPars->nLutSize < 6 || pPars->nLutSize > 7 )
18849         {
18850             Abc_Print( -1, "This feature only works for {6,7}-LUTs.\n" );
18851             return 1;
18852         }
18853         pPars->pFuncCell = If_CutPerformCheck07;
18854         pPars->fCutMin = 1;
18855     }
18856     if ( pPars->fUseCofVars )
18857     {
18858         if ( !(pPars->nLutSize & 1) )
18859         {
18860             Abc_Print( -1, "This feature only works for odd-sized LUTs.\n" );
18861             return 1;
18862         }
18863         pPars->fCutMin = 1;
18864     }
18865     if ( pPars->fUseDsdTune )
18866     {
18867         If_DsdMan_t * pDsdMan = (If_DsdMan_t *)Abc_FrameReadManDsd();
18868         if ( pDsdMan == NULL )
18869         {
18870             Abc_Print( -1, "DSD manager is not available.\n" );
18871             return 1;
18872         }
18873         if ( pPars->nLutSize > If_DsdManVarNum(pDsdMan) )
18874         {
18875             Abc_Print( -1, "LUT size (%d) is more than the number of variables in the DSD manager (%d).\n", pPars->nLutSize, If_DsdManVarNum(pDsdMan) );
18876             return 1;
18877         }
18878         if ( pPars->fDeriveLuts && If_DsdManGetCellStr(pDsdMan) == NULL )
18879         {
18880             Abc_Print( -1, "DSD manager is not matched with any particular cell.\n" );
18881             return 1;
18882         }
18883         pPars->fCutMin = 1;
18884         pPars->fUseDsd = 1;
18885         If_DsdManSetNewAsUseless( pDsdMan );
18886     }
18887     if ( pPars->pLutStruct )
18888     {
18889         if ( pPars->fDsdBalance )
18890         {
18891             Abc_Print( -1, "Incompatible options (-S and -x).\n" );
18892             return 1;
18893         }
18894         if ( pPars->nLutSize < 6 || pPars->nLutSize > 16 )
18895         {
18896             Abc_Print( -1, "This feature only works for [6;16]-LUTs.\n" );
18897             return 1;
18898         }
18899         pPars->pFuncCell = pPars->fDelayOptLut ? NULL : If_CutPerformCheck16;
18900         pPars->fCutMin = 1;
18901     }
18902 
18903     // enable truth table computation if cut minimization is selected
18904     if ( pPars->fCutMin )
18905     {
18906         pPars->fTruth = 1;
18907         pPars->fExpRed = 0;
18908     }
18909     // modify the subgraph recording
18910     if ( pPars->fUserRecLib || pPars->fUserSesLib )
18911     {
18912         pPars->fTruth      =  1;
18913         pPars->fCutMin     =  1;
18914         pPars->fExpRed     =  0;
18915         pPars->fUsePerm    =  1;
18916         pPars->pLutLib     =  NULL;
18917     }
18918     // modify for delay optimization
18919     if ( pPars->fDelayOpt || pPars->fDsdBalance || pPars->fDelayOptLut )
18920     {
18921         pPars->fTruth      =  1;
18922         pPars->fCutMin     =  1;
18923         pPars->fExpRed     =  0;
18924         pPars->fUseDsd     =  pPars->fDsdBalance || pPars->fDelayOptLut;
18925         pPars->pLutLib     =  NULL;
18926     }
18927     // modify for delay optimization
18928     if ( pPars->nGateSize > 0 )
18929     {
18930         pPars->fTruth      =  1;
18931         pPars->fCutMin     =  1;
18932         pPars->fExpRed     =  0;
18933         pPars->fUsePerm    =  1;
18934         pPars->pLutLib     =  NULL;
18935         pPars->nLutSize    =  pPars->nGateSize;
18936     }
18937 
18938     if ( pPars->fUseDsd || pPars->fUseTtPerm )
18939     {
18940         pPars->fTruth      =  1;
18941         pPars->fCutMin     =  1;
18942         pPars->fExpRed     =  0;
18943     }
18944 
18945     if ( pPars->fUseDsd )
18946     {
18947         int LutSize = (pPars->pLutStruct && pPars->pLutStruct[2] == 0)? pPars->pLutStruct[0] - '0' : 0;
18948         If_DsdMan_t * p = (If_DsdMan_t *)Abc_FrameReadManDsd();
18949         if ( pPars->pLutStruct && pPars->pLutStruct[2] != 0 )
18950         {
18951             printf( "DSD only works for LUT structures XY.\n" );
18952             return 0;
18953         }
18954         if ( p && pPars->nLutSize > If_DsdManVarNum(p) )
18955         {
18956             printf( "DSD manager has incompatible number of variables.\n" );
18957             return 0;
18958         }
18959         if ( p && LutSize != If_DsdManLutSize(p) && !pPars->fDsdBalance )
18960         {
18961             printf( "DSD manager has different LUT size.\n" );
18962             return 0;
18963         }
18964         if ( p == NULL )
18965         {
18966             if ( LutSize > DAU_MAX_VAR || pPars->nLutSize > DAU_MAX_VAR )
18967             {
18968                 printf( "Size of required DSD manager (%d) exceeds the precompiled limit (%d) (change parameter DAU_MAX_VAR).\n", LutSize, DAU_MAX_VAR );
18969                 return 0;
18970             }
18971             Abc_FrameSetManDsd( If_DsdManAlloc(pPars->nLutSize, LutSize) );
18972         }
18973     }
18974 
18975     if ( pPars->fUserRecLib )
18976     {
18977         if ( !Abc_NtkRecIsRunning3() )
18978         {
18979             printf( "LMS manager is not running (use \"rec_start3\").\n" );
18980             return 0;
18981         }
18982         if ( Abc_NtkRecInputNum3() != pPars->nLutSize )
18983         {
18984             printf( "The number of library inputs (%d) is different from the K parameters (%d).\n", Abc_NtkRecInputNum3(), pPars->nLutSize );
18985             return 0;
18986         }
18987     }
18988 
18989     if ( pPars->fUserSesLib )
18990     {
18991         if ( !Abc_ExactIsRunning() )
18992         {
18993             printf( "BMS manager is not running (use \"bms_start\").\n" );
18994             return 0;
18995         }
18996         if ( Abc_ExactInputNum() < pPars->nLutSize )
18997         {
18998             printf( "The number of library inputs (%d) is smaller than the K parameters (%d).\n", Abc_ExactInputNum(), pPars->nLutSize );
18999             return 0;
19000         }
19001     }
19002 
19003     // complain if truth tables are requested but the cut size is too large
19004     if ( pPars->fTruth && pPars->nLutSize > IF_MAX_FUNC_LUTSIZE )
19005     {
19006         Abc_Print( -1, "Truth tables cannot be computed for LUT larger than %d inputs.\n", IF_MAX_FUNC_LUTSIZE );
19007         return 1;
19008     }
19009 
19010     // disable cut-expansion if edge-based heuristics are selected
19011 //    if ( pPars->fEdge )
19012 //        pPars->fExpRed = 0;
19013 
19014     if ( !Abc_NtkIsStrash(pNtk) )
19015     {
19016         // strash and balance the network
19017         pNtk = Abc_NtkStrash( pNtk, 0, 0, 0 );
19018         if ( pNtk == NULL )
19019         {
19020             Abc_Print( -1, "Strashing before FPGA mapping has failed.\n" );
19021             return 1;
19022         }
19023         pNtk = Abc_NtkBalance( pNtkRes = pNtk, 0, 0, 1 );
19024         Abc_NtkDelete( pNtkRes );
19025         if ( pNtk == NULL )
19026         {
19027             Abc_Print( -1, "Balancing before FPGA mapping has failed.\n" );
19028             return 1;
19029         }
19030         if ( !Abc_FrameReadFlag("silentmode") )
19031             Abc_Print( 1, "The network was strashed and balanced before FPGA mapping.\n" );
19032         // get the new network
19033         pNtkRes = Abc_NtkIf( pNtk, pPars );
19034         if ( pNtkRes == NULL )
19035         {
19036             Abc_NtkDelete( pNtk );
19037             Abc_Print( -1, "FPGA mapping has failed.\n" );
19038             return 0;
19039         }
19040         Abc_NtkDelete( pNtk );
19041     }
19042     else
19043     {
19044         // get the new network
19045         pNtkRes = Abc_NtkIf( pNtk, pPars );
19046         if ( pNtkRes == NULL )
19047         {
19048             Abc_Print( -1, "FPGA mapping has failed.\n" );
19049             return 0;
19050         }
19051     }
19052     // replace the current network
19053     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
19054     return 0;
19055 
19056 usage:
19057     if ( pPars->DelayTarget == -1 )
19058         sprintf(Buffer, "best possible" );
19059     else
19060         sprintf(Buffer, "%.2f", pPars->DelayTarget );
19061     if ( pPars->nLutSize == -1 )
19062         sprintf(LutSize, "library" );
19063     else
19064         sprintf(LutSize, "%d", pPars->nLutSize );
19065     Abc_Print( -2, "usage: if [-KCFAGRNTXY num] [-DEW float] [-S str] [-qarlepmsdbgxyuojiktncvh]\n" );
19066     Abc_Print( -2, "\t           performs FPGA technology mapping of the network\n" );
19067     Abc_Print( -2, "\t-K num   : the number of LUT inputs (2 < num < %d) [default = %s]\n", IF_MAX_LUTSIZE+1, LutSize );
19068     Abc_Print( -2, "\t-C num   : the max number of priority cuts (0 < num < 2^12) [default = %d]\n", pPars->nCutsMax );
19069     Abc_Print( -2, "\t-F num   : the number of area flow recovery iterations (num >= 0) [default = %d]\n", pPars->nFlowIters );
19070     Abc_Print( -2, "\t-A num   : the number of exact area recovery iterations (num >= 0) [default = %d]\n", pPars->nAreaIters );
19071     Abc_Print( -2, "\t-G num   : the max AND/OR gate size for mapping (0 = unused) [default = %d]\n", pPars->nGateSize );
19072     Abc_Print( -2, "\t-R num   : the delay relaxation ratio (num >= 0) [default = %d]\n", pPars->nRelaxRatio );
19073     Abc_Print( -2, "\t-N num   : the max size of non-decomposable nodes [default = unused]\n", pPars->nNonDecLimit );
19074     Abc_Print( -2, "\t-T num   : the type of LUT structures [default = any]\n" );
19075     Abc_Print( -2, "\t-X num   : delay of AND-gate in LUT library units [default = %d]\n", pPars->nAndDelay );
19076     Abc_Print( -2, "\t-Y num   : area of AND-gate in LUT library units [default = %d]\n", pPars->nAndArea );
19077     Abc_Print( -2, "\t-D float : sets the delay constraint for the mapping [default = %s]\n", Buffer );
19078     Abc_Print( -2, "\t-E float : sets epsilon used for tie-breaking [default = %f]\n", pPars->Epsilon );
19079     Abc_Print( -2, "\t-W float : sets wire delay between adjects LUTs [default = %f]\n", pPars->WireDelay );
19080     Abc_Print( -2, "\t-S str   : string representing the LUT structure [default = %s]\n", pPars->pLutStruct ? pPars->pLutStruct : "not used" );
19081     Abc_Print( -2, "\t-q       : toggles preprocessing using several starting points [default = %s]\n", pPars->fPreprocess? "yes": "no" );
19082     Abc_Print( -2, "\t-a       : toggles area-oriented mapping [default = %s]\n", pPars->fArea? "yes": "no" );
19083     Abc_Print( -2, "\t-r       : enables expansion/reduction of the best cuts [default = %s]\n", pPars->fExpRed? "yes": "no" );
19084     Abc_Print( -2, "\t-l       : optimizes latch paths for delay, other paths for area [default = %s]\n", pPars->fLatchPaths? "yes": "no" );
19085     Abc_Print( -2, "\t-e       : uses edge-based cut selection heuristics [default = %s]\n", pPars->fEdge? "yes": "no" );
19086     Abc_Print( -2, "\t-p       : uses power-aware cut selection heuristics [default = %s]\n", pPars->fPower? "yes": "no" );
19087     Abc_Print( -2, "\t-m       : enables cut minimization by removing vacuous variables [default = %s]\n", pPars->fCutMin? "yes": "no" );
19088     Abc_Print( -2, "\t-s       : toggles delay-oriented mapping used with -S <NN> [default = %s]\n", pPars->fDelayOptLut? "yes": "no" );
19089     Abc_Print( -2, "\t-d       : toggles deriving local AIGs using bi-decomposition [default = %s]\n", pPars->fBidec? "yes": "no" );
19090     Abc_Print( -2, "\t-b       : toggles the use of one special feature [default = %s]\n", pPars->fUseBat? "yes": "no" );
19091     Abc_Print( -2, "\t-g       : toggles delay optimization by SOP balancing [default = %s]\n", pPars->fDelayOpt? "yes": "no" );
19092     Abc_Print( -2, "\t-x       : toggles delay optimization by DSD balancing [default = %s]\n", pPars->fDsdBalance? "yes": "no" );
19093     Abc_Print( -2, "\t-y       : toggles delay optimization with recorded library [default = %s]\n", pPars->fUserRecLib? "yes": "no" );
19094     Abc_Print( -2, "\t-u       : toggles delay optimization with SAT-based library [default = %s]\n", pPars->fUserSesLib? "yes": "no" );
19095     Abc_Print( -2, "\t-o       : toggles using buffers to decouple combinational outputs [default = %s]\n", pPars->fUseBuffs? "yes": "no" );
19096     Abc_Print( -2, "\t-j       : toggles enabling additional check [default = %s]\n", pPars->fEnableCheck07? "yes": "no" );
19097     Abc_Print( -2, "\t-i       : toggles using cofactoring variables [default = %s]\n", pPars->fUseCofVars? "yes": "no" );
19098     Abc_Print( -2, "\t-k       : toggles matching based on precomputed DSD manager [default = %s]\n", pPars->fUseDsdTune? "yes": "no" );
19099     Abc_Print( -2, "\t-t       : toggles optimizing average rather than maximum level [default = %s]\n", pPars->fDoAverage? "yes": "no" );
19100     Abc_Print( -2, "\t-n       : toggles computing DSDs of the cut functions [default = %s]\n", pPars->fUseDsd? "yes": "no" );
19101     Abc_Print( -2, "\t-c       : toggles computing truth tables in a new way [default = %s]\n", pPars->fUseTtPerm? "yes": "no" );
19102     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
19103     Abc_Print( -2, "\t-h       : prints the command usage\n");
19104     return 1;
19105 }
19106 
19107 /**Function*************************************************************
19108 
19109   Synopsis    []
19110 
19111   Description []
19112 
19113   SideEffects []
19114 
19115   SeeAlso     []
19116 
19117 ***********************************************************************/
Abc_CommandIfif(Abc_Frame_t * pAbc,int argc,char ** argv)19118 int Abc_CommandIfif( Abc_Frame_t * pAbc, int argc, char ** argv )
19119 {
19120     extern void Abc_NtkPerformIfif( Abc_Ntk_t * pNtk, Ifif_Par_t * pPars );
19121     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
19122     Ifif_Par_t Pars, * pPars = &Pars;
19123     int c, fError;
19124 
19125     pPars->nLutSize     =  -1;    // the LUT size
19126     pPars->pLutLib      = (If_LibLut_t *)Abc_FrameReadLibLut();       // the LUT library
19127     pPars->DelayWire    = (float)0.5;    // wire delay
19128     pPars->nDegree      =   0;    // structure degree
19129     pPars->fCascade     =   0;    // cascade
19130     pPars->fVerbose     =   0;    // verbose
19131     pPars->fVeryVerbose =   0;    // verbose
19132 
19133     Extra_UtilGetoptReset();
19134     while ( ( c = Extra_UtilGetopt( argc, argv, "DNcvwh" ) ) != EOF )
19135     {
19136         switch ( c )
19137         {
19138         case 'D':
19139             if ( globalUtilOptind >= argc )
19140             {
19141                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a floating point number.\n" );
19142                 goto usage;
19143             }
19144             pPars->DelayWire = atof(argv[globalUtilOptind]);
19145             globalUtilOptind++;
19146             if ( pPars->DelayWire < 0.0 )
19147                 goto usage;
19148             break;
19149         case 'N':
19150             if ( globalUtilOptind >= argc )
19151             {
19152                 Abc_Print( -1, "Command line switch \"-N\" should be followed by a floating point number.\n" );
19153                 goto usage;
19154             }
19155             pPars->nDegree = atoi(argv[globalUtilOptind]);
19156             globalUtilOptind++;
19157             if ( pPars->nDegree < 0 )
19158                 goto usage;
19159             break;
19160         case 'c':
19161             pPars->fCascade ^= 1;
19162             break;
19163         case 'v':
19164             pPars->fVerbose ^= 1;
19165             break;
19166         case 'w':
19167             pPars->fVeryVerbose ^= 1;
19168             break;
19169         case 'h':
19170             goto usage;
19171         default:
19172             goto usage;
19173         }
19174     }
19175 
19176     if ( pNtk == NULL )
19177     {
19178         Abc_Print( -1, "Empty network.\n" );
19179         return 1;
19180     }
19181     if ( !Abc_NtkIsLogic(pNtk) )
19182     {
19183         Abc_Print( -1, "Need mapped network.\n" );
19184         return 1;
19185     }
19186     if ( pPars->pLutLib == NULL )
19187     {
19188         Abc_Print( -1, "LUT library is not given.\n" );
19189         return 1;
19190     }
19191 
19192     pPars->nLutSize = Abc_NtkGetFaninMax( pNtk );
19193     if ( pPars->nLutSize > pPars->pLutLib->LutMax )
19194     {
19195         Abc_Print( -1, "The max node size (%d) exceeds the LUT size (%d).\n", pPars->nLutSize, pPars->pLutLib->LutMax );
19196         return 1;
19197     }
19198     if ( pPars->nLutSize < pPars->pLutLib->LutMax )
19199         Abc_Print( 0, "Node size (%d) is less than LUT size (%d).\n", pPars->nLutSize, pPars->pLutLib->LutMax );
19200     // check delay information
19201     fError = 0;
19202     for ( c = 0; c < pPars->pLutLib->LutMax; c++ )
19203     {
19204         pPars->pLutDelays[c] = ( pPars->pLutLib->fVarPinDelays ? pPars->pLutLib->pLutDelays[pPars->pLutLib->LutMax][c] : pPars->pLutLib->pLutDelays[pPars->pLutLib->LutMax][0] );
19205         if ( pPars->DelayWire >= pPars->pLutDelays[c] )
19206         {
19207             fError = 1;
19208             printf(" Wire delay (%.2f) exceeds pin+wire delay (%.2f) for pin %d in the LUT library.\n", pPars->DelayWire, pPars->pLutDelays[c], c );
19209         }
19210     }
19211     if ( fError )
19212         return 1;
19213 
19214     // call the mapper
19215     Abc_NtkPerformIfif( pNtk, pPars );
19216     return 0;
19217 
19218 usage:
19219     Abc_Print( -2, "usage: ifif [-DNcvwh]\n" );
19220     Abc_Print( -2, "\t           technology mapper into N-node K-LUT structures\n" );
19221     Abc_Print( -2, "\t           (takes a LUT network and maps it into a delay-optimal network\n" );
19222     Abc_Print( -2, "\t            of N-node K-LUT structures using the current LUT library)\n" );
19223     Abc_Print( -2, "\t-D float : wire delay (should be less than the LUT delay) [default = %.2f]\n", pPars->DelayWire );
19224     Abc_Print( -2, "\t-N num   : degree of the LUT structure [default = %d]\n", pPars->nDegree );
19225     Abc_Print( -2, "\t-c       : toggles using LUT cascade vs LUT cluster [default = %s]\n", pPars->fCascade? "cascade": "cluster" );
19226     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
19227     Abc_Print( -2, "\t-w       : toggles very verbose output [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
19228     Abc_Print( -2, "\t-h       : print the command usage\n");
19229     return 1;
19230 }
19231 
19232 /**Function*************************************************************
19233 
19234   Synopsis    []
19235 
19236   Description []
19237 
19238   SideEffects []
19239 
19240   SeeAlso     []
19241 
19242 ***********************************************************************/
Abc_CommandDsdSave(Abc_Frame_t * pAbc,int argc,char ** argv)19243 int Abc_CommandDsdSave( Abc_Frame_t * pAbc, int argc, char ** argv )
19244 {
19245     char * FileName;
19246     char ** pArgvNew;
19247     int nArgcNew;
19248     int c, fSecond = 0;
19249     Extra_UtilGetoptReset();
19250     while ( ( c = Extra_UtilGetopt( argc, argv, "bh" ) ) != EOF )
19251     {
19252         switch ( c )
19253         {
19254         case 'b':
19255             fSecond ^= 1;
19256             break;
19257         case 'h':
19258             goto usage;
19259         default:
19260             goto usage;
19261         }
19262     }
19263     pArgvNew = argv + globalUtilOptind;
19264     nArgcNew = argc - globalUtilOptind;
19265     if ( nArgcNew != 1 )
19266     {
19267         Abc_Print( -1, "File name is not given on the command line.\n" );
19268         return 1;
19269     }
19270     // get the input file name
19271     FileName = (nArgcNew == 1) ? pArgvNew[0] : NULL;
19272     if ( fSecond )
19273     {
19274         if ( !Abc_FrameReadManDsd2() )
19275         {
19276             Abc_Print( -1, "The DSD manager is not started.\n" );
19277             return 1;
19278         }
19279         If_DsdManSave( (If_DsdMan_t *)Abc_FrameReadManDsd2(), FileName );
19280     }
19281     else
19282     {
19283         if ( !Abc_FrameReadManDsd() )
19284         {
19285             Abc_Print( -1, "The DSD manager is not started.\n" );
19286             return 1;
19287         }
19288         If_DsdManSave( (If_DsdMan_t *)Abc_FrameReadManDsd(), FileName );
19289     }
19290     return 0;
19291 
19292 usage:
19293     Abc_Print( -2, "usage: dsd_save [-bh] <file>\n" );
19294     Abc_Print( -2, "\t         saves DSD manager into a file\n");
19295     Abc_Print( -2, "\t-b     : toggles processing second manager [default = %s]\n", fSecond? "yes": "no" );
19296     Abc_Print( -2, "\t-h     : print the command usage\n");
19297     Abc_Print( -2, "\t<file> : (optional) file name to write\n");
19298     return 1;
19299 }
19300 
19301 /**Function*************************************************************
19302 
19303   Synopsis    []
19304 
19305   Description []
19306 
19307   SideEffects []
19308 
19309   SeeAlso     []
19310 
19311 ***********************************************************************/
Abc_CommandDsdLoad(Abc_Frame_t * pAbc,int argc,char ** argv)19312 int Abc_CommandDsdLoad( Abc_Frame_t * pAbc, int argc, char ** argv )
19313 {
19314     char * FileName, * pTemp;
19315     char ** pArgvNew;
19316     int c, nArgcNew, fSecond = 0;
19317     FILE * pFile;
19318     If_DsdMan_t * pDsdMan;
19319     Extra_UtilGetoptReset();
19320     while ( ( c = Extra_UtilGetopt( argc, argv, "bh" ) ) != EOF )
19321     {
19322         switch ( c )
19323         {
19324         case 'b':
19325             fSecond ^= 1;
19326             break;
19327         case 'h':
19328             goto usage;
19329         default:
19330             goto usage;
19331         }
19332     }
19333     pArgvNew = argv + globalUtilOptind;
19334     nArgcNew = argc - globalUtilOptind;
19335     if ( nArgcNew != 1 )
19336     {
19337         Abc_Print( -1, "File name is not given on the command line.\n" );
19338         return 1;
19339     }
19340     // get the input file name
19341     FileName = pArgvNew[0];
19342     // fix the wrong symbol
19343     for ( pTemp = FileName; *pTemp; pTemp++ )
19344         if ( *pTemp == '>' )
19345             *pTemp = '\\';
19346     if ( (pFile = fopen( FileName, "r" )) == NULL )
19347     {
19348         Abc_Print( -1, "Cannot open input file \"%s\". ", FileName );
19349         if ( (FileName = Extra_FileGetSimilarName( FileName, ".aig", NULL, NULL, NULL, NULL )) )
19350             Abc_Print( 1, "Did you mean \"%s\"?", FileName );
19351         Abc_Print( 1, "\n" );
19352         return 1;
19353     }
19354     fclose( pFile );
19355     if ( fSecond )
19356     {
19357         Abc_FrameSetManDsd2( NULL );
19358         pDsdMan = If_DsdManLoad(FileName);
19359         if ( pDsdMan == NULL )
19360             return 1;
19361         Abc_FrameSetManDsd2( pDsdMan );
19362     }
19363     else
19364     {
19365         Abc_FrameSetManDsd( NULL );
19366         pDsdMan = If_DsdManLoad(FileName);
19367         if ( pDsdMan == NULL )
19368             return 1;
19369         Abc_FrameSetManDsd( pDsdMan );
19370     }
19371     return 0;
19372 
19373 usage:
19374     Abc_Print( -2, "usage: dsd_load [-bh] <file>\n" );
19375     Abc_Print( -2, "\t         loads DSD manager from file\n");
19376     Abc_Print( -2, "\t-b     : toggles processing second manager [default = %s]\n", fSecond? "yes": "no" );
19377     Abc_Print( -2, "\t-h     : print the command usage\n");
19378     Abc_Print( -2, "\t<file> : file name to read\n");
19379     return 1;
19380 }
19381 
19382 /**Function*************************************************************
19383 
19384   Synopsis    []
19385 
19386   Description []
19387 
19388   SideEffects []
19389 
19390   SeeAlso     []
19391 
19392 ***********************************************************************/
Abc_CommandDsdFree(Abc_Frame_t * pAbc,int argc,char ** argv)19393 int Abc_CommandDsdFree( Abc_Frame_t * pAbc, int argc, char ** argv )
19394 {
19395     int c, fSecond = 0;
19396     Extra_UtilGetoptReset();
19397     while ( ( c = Extra_UtilGetopt( argc, argv, "bh" ) ) != EOF )
19398     {
19399         switch ( c )
19400         {
19401         case 'b':
19402             fSecond ^= 1;
19403             break;
19404         case 'h':
19405             goto usage;
19406         default:
19407             goto usage;
19408         }
19409     }
19410     if ( fSecond )
19411     {
19412         if ( !Abc_FrameReadManDsd2() )
19413         {
19414             Abc_Print( -1, "The DSD manager is not started.\n" );
19415             return 0;
19416         }
19417         Abc_FrameSetManDsd2( NULL );
19418     }
19419     else
19420     {
19421         if ( !Abc_FrameReadManDsd() )
19422         {
19423             Abc_Print( -1, "The DSD manager is not started.\n" );
19424             return 0;
19425         }
19426         Abc_FrameSetManDsd( NULL );
19427     }
19428     return 0;
19429 
19430 usage:
19431     Abc_Print( -2, "usage: dsd_free [-bh]\n" );
19432     Abc_Print( -2, "\t         deletes DSD manager\n" );
19433     Abc_Print( -2, "\t-b     : toggles processing second manager [default = %s]\n", fSecond? "yes": "no" );
19434     Abc_Print( -2, "\t-h     : print the command usage\n");
19435     return 1;
19436 }
19437 
19438 /**Function*************************************************************
19439 
19440   Synopsis    []
19441 
19442   Description []
19443 
19444   SideEffects []
19445 
19446   SeeAlso     []
19447 
19448 ***********************************************************************/
Abc_CommandDsdPs(Abc_Frame_t * pAbc,int argc,char ** argv)19449 int Abc_CommandDsdPs( Abc_Frame_t * pAbc, int argc, char ** argv )
19450 {
19451     int c, Number = 0, Support = 0, fOccurs = 0, fTtDump = 0, fSecond = 0, fVerbose = 0;
19452     Extra_UtilGetoptReset();
19453     while ( ( c = Extra_UtilGetopt( argc, argv, "NSotbvh" ) ) != EOF )
19454     {
19455         switch ( c )
19456         {
19457         case 'N':
19458             if ( globalUtilOptind >= argc )
19459             {
19460                 Abc_Print( -1, "Command line switch \"-N\" should be followed by a floating point number.\n" );
19461                 goto usage;
19462             }
19463             Number = atoi(argv[globalUtilOptind]);
19464             globalUtilOptind++;
19465             if ( Number < 0 )
19466                 goto usage;
19467             break;
19468         case 'S':
19469             if ( globalUtilOptind >= argc )
19470             {
19471                 Abc_Print( -1, "Command line switch \"-S\" should be followed by a floating point number.\n" );
19472                 goto usage;
19473             }
19474             Support = atoi(argv[globalUtilOptind]);
19475             globalUtilOptind++;
19476             if ( Support < 0 )
19477                 goto usage;
19478             break;
19479         case 'o':
19480             fOccurs ^= 1;
19481             break;
19482         case 't':
19483             fTtDump ^= 1;
19484             break;
19485         case 'b':
19486             fSecond ^= 1;
19487             break;
19488         case 'v':
19489             fVerbose ^= 1;
19490             break;
19491         case 'h':
19492             goto usage;
19493         default:
19494             goto usage;
19495         }
19496     }
19497     if ( fSecond )
19498     {
19499         if ( !Abc_FrameReadManDsd2() )
19500         {
19501             Abc_Print( -1, "The DSD manager is not started.\n" );
19502             return 0;
19503         }
19504         If_DsdManPrint( (If_DsdMan_t *)Abc_FrameReadManDsd2(), NULL, Number, Support, fOccurs, fTtDump, fVerbose );
19505     }
19506     else
19507     {
19508         if ( !Abc_FrameReadManDsd() )
19509         {
19510             Abc_Print( -1, "The DSD manager is not started.\n" );
19511             return 0;
19512         }
19513         If_DsdManPrint( (If_DsdMan_t *)Abc_FrameReadManDsd(), NULL, Number, Support, fOccurs, fTtDump, fVerbose );
19514     }
19515     return 0;
19516 
19517 usage:
19518     Abc_Print( -2, "usage: dsd_ps [-NS num] [-obvh]\n" );
19519     Abc_Print( -2, "\t         prints statistics of the DSD manager\n" );
19520     Abc_Print( -2, "\t-N num : show structures whose ID divides by N [default = %d]\n",   Number );
19521     Abc_Print( -2, "\t-S num : show structures whose support size is S [default = %d]\n", Support );
19522     Abc_Print( -2, "\t-o     : toggles printing occurence distribution [default = %s]\n", fOccurs? "yes": "no" );
19523     Abc_Print( -2, "\t-t     : toggles dumping truth tables [default = %s]\n",            fTtDump? "yes": "no" );
19524     Abc_Print( -2, "\t-b     : toggles processing second manager [default = %s]\n",       fSecond? "yes": "no" );
19525     Abc_Print( -2, "\t-v     : toggles verbose output [default = %s]\n",                  fVerbose? "yes": "no" );
19526     Abc_Print( -2, "\t-h     : print the command usage\n");
19527     return 1;
19528 }
19529 
19530 /**Function*************************************************************
19531 
19532   Synopsis    []
19533 
19534   Description []
19535 
19536   SideEffects []
19537 
19538   SeeAlso     []
19539 
19540 ***********************************************************************/
Abc_CommandDsdMatch(Abc_Frame_t * pAbc,int argc,char ** argv)19541 int Abc_CommandDsdMatch( Abc_Frame_t * pAbc, int argc, char ** argv )
19542 {
19543     char * pStruct = NULL;
19544     int c, fVerbose = 0, fFast = 0, fAdd = 0, fSpec = 0, LutSize = 0, nConfls = 10000, nProcs = 1;
19545     If_DsdMan_t * pDsdMan = (If_DsdMan_t *)Abc_FrameReadManDsd();
19546     Extra_UtilGetoptReset();
19547     while ( ( c = Extra_UtilGetopt( argc, argv, "KCPSfasvh" ) ) != EOF )
19548     {
19549         switch ( c )
19550         {
19551         case 'K':
19552             if ( globalUtilOptind >= argc )
19553             {
19554                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a floating point number.\n" );
19555                 goto usage;
19556             }
19557             LutSize = atoi(argv[globalUtilOptind]);
19558             globalUtilOptind++;
19559             if ( LutSize < 4 || LutSize > 6 )
19560                 goto usage;
19561             break;
19562         case 'C':
19563             if ( globalUtilOptind >= argc )
19564             {
19565                 Abc_Print( -1, "Command line switch \"-C\" should be followed by a floating point number.\n" );
19566                 goto usage;
19567             }
19568             nConfls = atoi(argv[globalUtilOptind]);
19569             globalUtilOptind++;
19570             break;
19571         case 'P':
19572             if ( globalUtilOptind >= argc )
19573             {
19574                 Abc_Print( -1, "Command line switch \"-P\" should be followed by a floating point number.\n" );
19575                 goto usage;
19576             }
19577             nProcs = atoi(argv[globalUtilOptind]);
19578             globalUtilOptind++;
19579             break;
19580         case 'S':
19581             if ( globalUtilOptind >= argc )
19582             {
19583                 Abc_Print( -1, "Command line switch \"-S\" should be followed by string.\n" );
19584                 goto usage;
19585             }
19586             pStruct = argv[globalUtilOptind];
19587             globalUtilOptind++;
19588             break;
19589         case 'f':
19590             fFast ^= 1;
19591             break;
19592         case 'a':
19593             fAdd ^= 1;
19594             break;
19595         case 's':
19596             fSpec ^= 1;
19597             break;
19598         case 'v':
19599             fVerbose ^= 1;
19600             break;
19601         case 'h':
19602             goto usage;
19603         default:
19604             goto usage;
19605         }
19606     }
19607     if ( !Abc_FrameReadManDsd() )
19608     {
19609         Abc_Print( -1, "The DSD manager is not started.\n" );
19610         return 0;
19611     }
19612     if ( pStruct )
19613     {
19614         char * pStructCur = If_DsdManGetCellStr( pDsdMan );
19615         if ( pStructCur && strcmp(pStructCur, pStruct) )
19616         {
19617             Abc_Print( -1, "DSD manager matched with cell %s should be cleaned by \"dsd_filter -m\" before matching with cell %s.\n", pStructCur, pStruct );
19618             return 0;
19619         }
19620         Id_DsdManTuneStr( pDsdMan, pStruct, nConfls, nProcs, fVerbose );
19621     }
19622     else
19623         If_DsdManTune( pDsdMan, LutSize, fFast, fAdd, fSpec, fVerbose );
19624     return 0;
19625 
19626 usage:
19627     Abc_Print( -2, "usage: dsd_match [-KCP num] [-fasvh] [-S str]\n" );
19628     Abc_Print( -2, "\t         matches DSD structures with the given cell\n" );
19629     Abc_Print( -2, "\t-K num : LUT size used for tuning [default = %d]\n",        LutSize );
19630     Abc_Print( -2, "\t-C num : the maximum number of conflicts [default = %d]\n", nConfls );
19631     Abc_Print( -2, "\t-P num : the maximum number of processes [default = %d]\n", nProcs );
19632     Abc_Print( -2, "\t-f     : toggles using fast check [default = %s]\n",        fFast? "yes": "no" );
19633     Abc_Print( -2, "\t-a     : toggles adding tuning to the current one [default = %s]\n",    fAdd? "yes": "no" );
19634     Abc_Print( -2, "\t-s     : toggles using specialized check [default = %s]\n", fSpec? "yes": "no" );
19635     Abc_Print( -2, "\t-v     : toggles verbose output [default = %s]\n",          fVerbose? "yes": "no" );
19636     Abc_Print( -2, "\t-S str : string representing programmable cell [default = %s]\n", pStruct ? pStruct : "not used" );
19637     Abc_Print( -2, "\t-h     : print the command usage\n");
19638     return 1;
19639 }
19640 
19641 /**Function*************************************************************
19642 
19643   Synopsis    []
19644 
19645   Description []
19646 
19647   SideEffects []
19648 
19649   SeeAlso     []
19650 
19651 ***********************************************************************/
Abc_CommandDsdMerge(Abc_Frame_t * pAbc,int argc,char ** argv)19652 int Abc_CommandDsdMerge( Abc_Frame_t * pAbc, int argc, char ** argv )
19653 {
19654     char * FileName, * pTemp;
19655     char ** pArgvNew;
19656     int c, nArgcNew;
19657     FILE * pFile;
19658     If_DsdMan_t * pDsdMan;
19659     Extra_UtilGetoptReset();
19660     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
19661     {
19662         switch ( c )
19663         {
19664         case 'h':
19665             goto usage;
19666         default:
19667             goto usage;
19668         }
19669     }
19670     if ( !Abc_FrameReadManDsd() )
19671     {
19672         Abc_Print( -1, "The DSD manager is not started.\n" );
19673         return 0;
19674     }
19675     pArgvNew = argv + globalUtilOptind;
19676     nArgcNew = argc - globalUtilOptind;
19677     if ( nArgcNew != 1 )
19678     {
19679         Abc_Print( -1, "File name is not given on the command line.\n" );
19680         return 1;
19681     }
19682     // get the input file name
19683     FileName = pArgvNew[0];
19684     // fix the wrong symbol
19685     for ( pTemp = FileName; *pTemp; pTemp++ )
19686         if ( *pTemp == '>' )
19687             *pTemp = '\\';
19688     if ( (pFile = fopen( FileName, "r" )) == NULL )
19689     {
19690         Abc_Print( -1, "Cannot open input file \"%s\". ", FileName );
19691         if ( (FileName = Extra_FileGetSimilarName( FileName, ".aig", NULL, NULL, NULL, NULL )) )
19692             Abc_Print( 1, "Did you mean \"%s\"?", FileName );
19693         Abc_Print( 1, "\n" );
19694         return 1;
19695     }
19696     fclose( pFile );
19697     pDsdMan = If_DsdManLoad(FileName);
19698     if ( pDsdMan == NULL )
19699         return 1;
19700     If_DsdManMerge( (If_DsdMan_t *)Abc_FrameReadManDsd(), pDsdMan );
19701     If_DsdManFree( pDsdMan, 0 );
19702     return 0;
19703 
19704 usage:
19705     Abc_Print( -2, "usage: dsd_merge [-h] <file>\n" );
19706     Abc_Print( -2, "\t         merges DSD manager from file with the current one\n");
19707     Abc_Print( -2, "\t-h     : print the command usage\n");
19708     Abc_Print( -2, "\t<file> : file name to read\n");
19709     return 1;
19710 }
19711 
19712 /**Function*************************************************************
19713 
19714   Synopsis    []
19715 
19716   Description []
19717 
19718   SideEffects []
19719 
19720   SeeAlso     []
19721 
19722 ***********************************************************************/
Abc_CommandDsdFilter(Abc_Frame_t * pAbc,int argc,char ** argv)19723 int Abc_CommandDsdFilter( Abc_Frame_t * pAbc, int argc, char ** argv )
19724 {
19725     If_DsdMan_t * pDsd = (If_DsdMan_t *)Abc_FrameReadManDsd();
19726     int c, nLimit = 0, nLutSize = -1, fCleanOccur = 0, fCleanMarks = 0, fInvMarks = 0, fUnate = 0, fThresh = 0, fThreshHeuristic = 0, fVerbose = 0;
19727     Extra_UtilGetoptReset();
19728     while ( ( c = Extra_UtilGetopt( argc, argv, "LKomiutsvh" ) ) != EOF )
19729     {
19730         switch ( c )
19731         {
19732         case 'L':
19733             if ( globalUtilOptind >= argc )
19734             {
19735                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a floating point number.\n" );
19736                 goto usage;
19737             }
19738             nLimit = atoi(argv[globalUtilOptind]);
19739             globalUtilOptind++;
19740             break;
19741         case 'K':
19742             if ( globalUtilOptind >= argc )
19743             {
19744                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a floating point number.\n" );
19745                 goto usage;
19746             }
19747             nLutSize = atoi(argv[globalUtilOptind]);
19748             globalUtilOptind++;
19749             break;
19750         case 'o':
19751             fCleanOccur ^= 1;
19752             break;
19753         case 'm':
19754             fCleanMarks ^= 1;
19755             break;
19756         case 'i':
19757             fInvMarks ^= 1;
19758             break;
19759         case 'u':
19760             fUnate ^= 1;
19761             break;
19762         case 't':
19763             fThresh ^= 1;
19764             break;
19765         case 's':
19766             fThreshHeuristic ^= 1;
19767             break;
19768         case 'v':
19769             fVerbose ^= 1;
19770             break;
19771         case 'h':
19772             goto usage;
19773         default:
19774             goto usage;
19775         }
19776     }
19777     if ( pDsd == NULL )
19778     {
19779         Abc_Print( -1, "The DSD manager is not started.\n" );
19780         return 0;
19781     }
19782     if ( nLimit > 0 )
19783         Abc_FrameSetManDsd( If_DsdManFilter(pDsd, nLimit) );
19784     if ( nLutSize >= 0 )
19785         If_DsdManSetLutSize( pDsd, nLutSize );
19786     if ( fCleanOccur )
19787         If_DsdManCleanOccur( pDsd, fVerbose );
19788     if ( fCleanMarks )
19789         If_DsdManCleanMarks( pDsd, fVerbose );
19790     if ( fInvMarks )
19791         If_DsdManInvertMarks( pDsd, fVerbose );
19792 #ifdef ABC_USE_CUDD
19793     else if ( nLimit == 0 )
19794         Id_DsdManTuneThresh( pDsd, fUnate, fThresh, fThreshHeuristic, fVerbose );
19795 #endif
19796     return 0;
19797 
19798 usage:
19799     Abc_Print( -2, "usage: dsd_filter [-LK num] [-omiutsvh]\n" );
19800     Abc_Print( -2, "\t         filtering structured and modifying parameters of DSD manager\n" );
19801     Abc_Print( -2, "\t-L num : remove structures with fewer occurrences that this [default = %d]\n", nLimit );
19802     Abc_Print( -2, "\t-K num : new LUT size to set for the DSD manager [default = %d]\n",           nLutSize );
19803     Abc_Print( -2, "\t-o     : toggles cleaning occurrence counters [default = %s]\n",              fCleanOccur? "yes": "no" );
19804     Abc_Print( -2, "\t-m     : toggles cleaning matching marks [default = %s]\n",                   fCleanMarks? "yes": "no" );
19805     Abc_Print( -2, "\t-i     : toggles inverting matching marks [default = %s]\n",                  fInvMarks? "yes": "no" );
19806     Abc_Print( -2, "\t-u     : toggles marking unate functions [default = %s]\n",                   fUnate? "yes": "no" );
19807     Abc_Print( -2, "\t-t     : toggles marking threshold functions [default = %s]\n",               fThresh? "yes": "no" );
19808     Abc_Print( -2, "\t-s     : toggles marking threshold functions heuristically [default = %s]\n", fThreshHeuristic?"yes":"no");
19809     Abc_Print( -2, "\t-v     : toggles verbose output [default = %s]\n",                            fVerbose? "yes": "no" );
19810     Abc_Print( -2, "\t-h     : print the command usage\n");
19811     Abc_Print( -2, "\t        \n" );
19812     Abc_Print( -2, "\t         Option \"dsd_filter -s\" was contributed by Augusto Neutzling and Jody Matos from\n" );
19813     Abc_Print( -2, "\t         Federal University of Rio Grande do Sul, Brazil. The paper describing the method:\n" );
19814     Abc_Print( -2, "\t         A. Neutzling, J. M. Matos, A. Mishchenko, R. Ribas, and A. Reis,\n" );
19815     Abc_Print( -2, "\t         \"Threshold logic synthesis based on cut pruning\". Proc. ICCAD 2015.\n" );
19816 //    Abc_Print( -2, "\t        http://www.eecs.berkeley.edu/~alanmi/publications/2015/iccad15_thresh.pdf\n" );
19817     return 1;
19818 }
19819 
19820 
19821 
19822 /**Function*************************************************************
19823 
19824   Synopsis    []
19825 
19826   Description []
19827 
19828   SideEffects []
19829 
19830   SeeAlso     []
19831 
19832 ***********************************************************************/
Abc_CommandInit(Abc_Frame_t * pAbc,int argc,char ** argv)19833 int Abc_CommandInit( Abc_Frame_t * pAbc, int argc, char ** argv )
19834 {
19835     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
19836     Abc_Obj_t * pObj;
19837     char * pInitStr = NULL;
19838     int fZeros    = 0;
19839     int fOnes     = 0;
19840     int fRandom   = 0;
19841     int fDontCare = 0;
19842     int fUseCexCs = 0;
19843     int fUseCexNs = 0;
19844     int c, i;
19845     // set defaults
19846     Extra_UtilGetoptReset();
19847     while ( ( c = Extra_UtilGetopt( argc, argv, "Szordcnh" ) ) != EOF )
19848     {
19849         switch ( c )
19850         {
19851         case 'S':
19852             if ( globalUtilOptind >= argc )
19853             {
19854                 Abc_Print( -1, "Command line switch \"-S\" should be followed by a file name.\n" );
19855                 goto usage;
19856             }
19857             pInitStr = argv[globalUtilOptind];
19858             globalUtilOptind++;
19859             break;
19860         case 'z':
19861             fZeros ^= 1;
19862             break;
19863         case 'o':
19864             fOnes ^= 1;
19865             break;
19866         case 'r':
19867             fRandom ^= 1;
19868             break;
19869         case 'd':
19870             fDontCare ^= 1;
19871             break;
19872         case 'c':
19873             fUseCexCs ^= 1;
19874             break;
19875         case 'n':
19876             fUseCexNs ^= 1;
19877             break;
19878         case 'h':
19879             goto usage;
19880         default:
19881             goto usage;
19882         }
19883     }
19884 
19885     if ( pNtk == NULL )
19886     {
19887         Abc_Print( -1, "Empty network.\n" );
19888         return 1;
19889     }
19890 
19891     if ( Abc_NtkIsComb(pNtk) )
19892     {
19893         Abc_Print( 0, "The current network is combinational.\n" );
19894         return 0;
19895     }
19896 
19897     if ( pInitStr != NULL )
19898     {
19899         if ( (int)strlen(pInitStr) != Abc_NtkLatchNum(pNtk) )
19900         {
19901             Abc_Print( -1, "The length of init string (%d) differs from the number of flops (%d).\n", strlen(pInitStr), Abc_NtkLatchNum(pNtk) );
19902             return 1;
19903         }
19904         Abc_NtkForEachLatch( pNtk, pObj, i )
19905             if ( pInitStr[i] == '0' )
19906                 Abc_LatchSetInit0( pObj );
19907             else if ( pInitStr[i] == '1' )
19908                 Abc_LatchSetInit1( pObj );
19909             else
19910                 Abc_LatchSetInitDc( pObj );
19911         return 0;
19912     }
19913 
19914     if ( fZeros )
19915     {
19916         Abc_NtkForEachLatch( pNtk, pObj, i )
19917             Abc_LatchSetInit0( pObj );
19918     }
19919     else if ( fOnes )
19920     {
19921         Abc_NtkForEachLatch( pNtk, pObj, i )
19922             Abc_LatchSetInit1( pObj );
19923     }
19924     else if ( fRandom )
19925     {
19926         srand( time(NULL) );
19927         Abc_NtkForEachLatch( pNtk, pObj, i )
19928             if ( rand() & 1 )
19929                 Abc_LatchSetInit1( pObj );
19930             else
19931                 Abc_LatchSetInit0( pObj );
19932     }
19933     else if ( fDontCare )
19934     {
19935         Abc_NtkForEachLatch( pNtk, pObj, i )
19936             Abc_LatchSetInitDc( pObj );
19937     }
19938     else if ( fUseCexCs || fUseCexNs )
19939     {
19940         extern Vec_Int_t * Saig_ManReturnFailingState( Aig_Man_t * pMan, Abc_Cex_t * p, int fNextOne );
19941         Aig_Man_t * pMan;
19942         Vec_Int_t * vFailState;
19943         if ( fUseCexCs && fUseCexNs )
19944         {
19945             Abc_Print( -1, "The two options (-c and -n) are incompatible.\n" );
19946             return 0;
19947         }
19948         if ( !Abc_NtkIsStrash(pNtk) )
19949         {
19950             Abc_Print( -1, "The current network should be an AIG.\n" );
19951             return 0;
19952         }
19953         if ( pAbc->pCex == NULL )
19954         {
19955             Abc_Print( -1, "The current CEX is not available.\n" );
19956             return 0;
19957         }
19958         pMan = Abc_NtkToDar( pNtk, 0, 1 );
19959         vFailState = Saig_ManReturnFailingState( pMan, pAbc->pCex, fUseCexNs );
19960         //Vec_IntPrint( vFailState );
19961         Aig_ManStop( pMan );
19962         Abc_NtkForEachLatch( pNtk, pObj, i )
19963             if ( Vec_IntEntry( vFailState, i ) )
19964                 Abc_LatchSetInit1( pObj );
19965             else
19966                 Abc_LatchSetInit0( pObj );
19967         Vec_IntFree( vFailState );
19968     }
19969     else
19970         Abc_Print( -1, "The initial states remain unchanged.\n" );
19971     return 0;
19972 
19973 usage:
19974     Abc_Print( -2, "usage: init [-zordcnh] [-S <init_string>]\n" );
19975     Abc_Print( -2, "\t         resets initial states of all latches\n" );
19976     Abc_Print( -2, "\t-z     : set zeros initial states [default = %s]\n", fZeros? "yes": "no" );
19977     Abc_Print( -2, "\t-o     : set ones initial states [default = %s]\n", fOnes? "yes": "no" );
19978     Abc_Print( -2, "\t-d     : set don't-care initial states [default = %s]\n", fDontCare? "yes": "no" );
19979     Abc_Print( -2, "\t-r     : set random initial states [default = %s]\n", fRandom? "yes": "no" );
19980     Abc_Print( -2, "\t-c     : set failure current state from the CEX (and run \"zero\") [default = %s]\n", fUseCexCs? "yes": "no" );
19981     Abc_Print( -2, "\t-n     : set next state after failure from the CEX (and run \"zero\") [default = %s]\n", fUseCexNs? "yes": "no" );
19982     Abc_Print( -2, "\t-h     : print the command usage\n");
19983     Abc_Print( -2, "\t-S str : (optional) initial state  [default = unused]\n" );
19984     return 1;
19985 }
19986 
19987 /**Function*************************************************************
19988 
19989   Synopsis    []
19990 
19991   Description []
19992 
19993   SideEffects []
19994 
19995   SeeAlso     []
19996 
19997 ***********************************************************************/
Abc_CommandZero(Abc_Frame_t * pAbc,int argc,char ** argv)19998 int Abc_CommandZero( Abc_Frame_t * pAbc, int argc, char ** argv )
19999 {
20000     Abc_Ntk_t * pNtk, * pNtkRes;
20001     int c;
20002     pNtk = Abc_FrameReadNtk(pAbc);
20003     // set defaults
20004     Extra_UtilGetoptReset();
20005     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
20006     {
20007         switch ( c )
20008         {
20009         case 'h':
20010             goto usage;
20011         default:
20012             goto usage;
20013         }
20014     }
20015 
20016     if ( pNtk == NULL )
20017     {
20018         Abc_Print( -1, "Empty network.\n" );
20019         return 1;
20020     }
20021 
20022     if ( Abc_NtkIsComb(pNtk) )
20023     {
20024         Abc_Print( 0, "The current network is combinational.\n" );
20025         return 0;
20026     }
20027 
20028     if ( !Abc_NtkIsStrash(pNtk) )
20029     {
20030         Abc_Print( -1, "This command works only for AIGs.\n" );
20031         return 0;
20032     }
20033 
20034     // get the new network
20035     pNtkRes = Abc_NtkRestrashZero( pNtk, 0 );
20036     if ( pNtkRes == NULL )
20037     {
20038         Abc_Print( -1, "Converting to sequential AIG has failed.\n" );
20039         return 1;
20040     }
20041     // replace the current network
20042     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
20043     return 0;
20044 
20045 usage:
20046     Abc_Print( -2, "usage: zero [-h]\n" );
20047     Abc_Print( -2, "\t        converts latches to have const-0 initial value\n" );
20048     Abc_Print( -2, "\t-h    : print the command usage\n");
20049     return 1;
20050 }
20051 
20052 /**Function*************************************************************
20053 
20054   Synopsis    []
20055 
20056   Description []
20057 
20058   SideEffects []
20059 
20060   SeeAlso     []
20061 
20062 ***********************************************************************/
Abc_CommandUndc(Abc_Frame_t * pAbc,int argc,char ** argv)20063 int Abc_CommandUndc( Abc_Frame_t * pAbc, int argc, char ** argv )
20064 {
20065     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
20066     int c, fUseCex = 0;
20067     // set defaults
20068     Extra_UtilGetoptReset();
20069     while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
20070     {
20071         switch ( c )
20072         {
20073         case 'c':
20074             fUseCex ^= 1;
20075             break;
20076         case 'h':
20077             goto usage;
20078         default:
20079             goto usage;
20080         }
20081     }
20082 
20083     if ( pNtk == NULL )
20084     {
20085         Abc_Print( -1, "Empty network.\n" );
20086         return 1;
20087     }
20088 
20089     if ( fUseCex )
20090     {
20091         char * pInit;
20092         Abc_Cex_t * pTemp;
20093         int k, nFlopsX = 0;
20094         if ( pAbc->pCex == NULL )
20095         {
20096             Abc_Print( -1, "Current CEX is not available.\n" );
20097             return 1;
20098         }
20099         pInit = Abc_NtkCollectLatchValuesStr( pAbc->pNtkCur );
20100         // count the number of X-valued flops
20101         for ( k = 0; k < Abc_NtkLatchNum(pAbc->pNtkCur); k++ )
20102             nFlopsX += (int)(pInit[k] == 'x');
20103         // compare this value
20104         if ( Abc_NtkPiNum(pNtk) + nFlopsX != pAbc->pCex->nPis )
20105         {
20106             Abc_Print( -1, "The number of PIs (%d) plus X-valued flops (%d) in the original network does not match the number of PIs in the current CEX (%d).\n",
20107                 Abc_NtkPiNum(pNtk), Abc_NtkLatchNum(pNtk), pAbc->pCex->nPis );
20108             return 1;
20109         }
20110         pAbc->pCex = Abc_CexTransformUndc( pTemp = pAbc->pCex, pInit );
20111         assert( pAbc->pCex->nPis == Abc_NtkPiNum(pAbc->pNtkCur) );
20112         assert( pAbc->pCex->nRegs == Abc_NtkLatchNum(pAbc->pNtkCur) );
20113         Abc_CexFree( pTemp );
20114         ABC_FREE( pInit );
20115         return 0;
20116     }
20117 
20118     if ( Abc_NtkIsComb(pNtk) )
20119     {
20120         Abc_Print( 0, "The current network is combinational.\n" );
20121         return 0;
20122     }
20123 
20124     if ( !Abc_NtkIsLogic(pNtk) )
20125     {
20126         Abc_Print( -1, "This command works only for logic networks.\n" );
20127         return 0;
20128     }
20129 
20130     // get the new network
20131     Abc_NtkConvertDcLatches( pNtk );
20132     return 0;
20133 
20134 usage:
20135     Abc_Print( -2, "usage: undc [-ch]\n" );
20136     Abc_Print( -2, "\t        converts latches with DC init values into free PIs\n" );
20137     Abc_Print( -2, "\t-c    : toggles transforming CEX after \"logic;undc;st;zero\" [default = %s]\n", fUseCex? "yes": "no" );
20138     Abc_Print( -2, "\t-h    : print the command usage\n");
20139     return 1;
20140 }
20141 
20142 /**Function*************************************************************
20143 
20144   Synopsis    []
20145 
20146   Description []
20147 
20148   SideEffects []
20149 
20150   SeeAlso     []
20151 
20152 ***********************************************************************/
Abc_CommandOneHot(Abc_Frame_t * pAbc,int argc,char ** argv)20153 int Abc_CommandOneHot( Abc_Frame_t * pAbc, int argc, char ** argv )
20154 {
20155     Abc_Ntk_t * pNtk, * pNtkRes;
20156     int c;
20157     extern Abc_Ntk_t * Abc_NtkConvertOnehot( Abc_Ntk_t * pNtk );
20158 
20159     pNtk = Abc_FrameReadNtk(pAbc);
20160     // set defaults
20161     Extra_UtilGetoptReset();
20162     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
20163     {
20164         switch ( c )
20165         {
20166         case 'h':
20167             goto usage;
20168         default:
20169             goto usage;
20170         }
20171     }
20172     if ( pNtk == NULL )
20173     {
20174         Abc_Print( -1, "Empty network.\n" );
20175         return 1;
20176     }
20177     if ( Abc_NtkIsComb(pNtk) )
20178     {
20179         Abc_Print( 0, "The current network is combinational.\n" );
20180         return 0;
20181     }
20182     if ( !Abc_NtkIsLogic(pNtk) )
20183     {
20184         Abc_Print( -1, "This command works only for logic networks.\n" );
20185         return 0;
20186     }
20187     // get the new network
20188     pNtkRes = Abc_NtkConvertOnehot( pNtk );
20189     if ( pNtkRes == NULL )
20190     {
20191         Abc_Print( -1, "Converting to one-hot encoding has failed.\n" );
20192         return 1;
20193     }
20194     // replace the current network
20195     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
20196     return 0;
20197 
20198 usage:
20199     Abc_Print( -2, "usage: onehot [-h]\n" );
20200     Abc_Print( -2, "\t        converts natural encoding into one-hot encoding\n" );
20201     Abc_Print( -2, "\t-h    : print the command usage\n");
20202     return 1;
20203 }
20204 
20205 /**Function*************************************************************
20206 
20207   Synopsis    []
20208 
20209   Description []
20210 
20211   SideEffects []
20212 
20213   SeeAlso     []
20214 
20215 ***********************************************************************/
Abc_CommandPipe(Abc_Frame_t * pAbc,int argc,char ** argv)20216 int Abc_CommandPipe( Abc_Frame_t * pAbc, int argc, char ** argv )
20217 {
20218     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
20219     int c;
20220     int nLatches;
20221     extern void Abc_NtkLatchPipe( Abc_Ntk_t * pNtk, int nLatches );
20222     // set defaults
20223     nLatches = 5;
20224     Extra_UtilGetoptReset();
20225     while ( ( c = Extra_UtilGetopt( argc, argv, "Lh" ) ) != EOF )
20226     {
20227         switch ( c )
20228         {
20229         case 'L':
20230             if ( globalUtilOptind >= argc )
20231             {
20232                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a positive integer.\n" );
20233                 goto usage;
20234             }
20235             nLatches = atoi(argv[globalUtilOptind]);
20236             globalUtilOptind++;
20237             if ( nLatches < 0 )
20238                 goto usage;
20239             break;
20240         case 'h':
20241             goto usage;
20242         default:
20243             goto usage;
20244         }
20245     }
20246 
20247     if ( pNtk == NULL )
20248     {
20249         Abc_Print( -1, "Empty network.\n" );
20250         return 1;
20251     }
20252 
20253     if ( Abc_NtkIsComb(pNtk) )
20254     {
20255         Abc_Print( 0, "The current network is combinational.\n" );
20256         return 0;
20257     }
20258 
20259     // update the network
20260     Abc_NtkLatchPipe( pNtk, nLatches );
20261     return 0;
20262 
20263 usage:
20264     Abc_Print( -2, "usage: pipe [-L num] [-h]\n" );
20265     Abc_Print( -2, "\t         inserts the given number of latches at each PI for pipelining\n" );
20266     Abc_Print( -2, "\t-L num : the number of latches to insert [default = %d]\n", nLatches );
20267     Abc_Print( -2, "\t-h     : print the command usage\n");
20268     return 1;
20269 }
20270 
20271 /**Function*************************************************************
20272 
20273   Synopsis    []
20274 
20275   Description []
20276 
20277   SideEffects []
20278 
20279   SeeAlso     []
20280 
20281 ***********************************************************************/
Abc_CommandSeq(Abc_Frame_t * pAbc,int argc,char ** argv)20282 int Abc_CommandSeq( Abc_Frame_t * pAbc, int argc, char ** argv )
20283 {
20284     Abc_Ntk_t * pNtk, * pNtkRes;
20285     int c;
20286 
20287     pNtk = Abc_FrameReadNtk(pAbc);
20288     // set defaults
20289     Extra_UtilGetoptReset();
20290     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
20291     {
20292         switch ( c )
20293         {
20294         case 'h':
20295             goto usage;
20296         default:
20297             goto usage;
20298         }
20299     }
20300 
20301     if ( pNtk == NULL )
20302     {
20303         Abc_Print( -1, "Empty network.\n" );
20304         return 1;
20305     }
20306 
20307     if ( Abc_NtkLatchNum(pNtk) == 0 )
20308     {
20309         Abc_Print( -1, "The network has no latches.\n" );
20310         return 0;
20311     }
20312 
20313     if ( !Abc_NtkIsStrash(pNtk) )
20314     {
20315         Abc_Print( -1, "Conversion to sequential AIG works only for combinational AIGs (run \"strash\").\n" );
20316         return 1;
20317     }
20318 
20319     // get the new network
20320 //    pNtkRes = Abc_NtkAigToSeq( pNtk );
20321     pNtkRes = NULL;
20322     if ( pNtkRes == NULL )
20323     {
20324         Abc_Print( -1, "Converting to sequential AIG has failed.\n" );
20325         return 1;
20326     }
20327     // replace the current network
20328     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
20329     return 0;
20330 
20331 usage:
20332     Abc_Print( -2, "usage: seq [-h]\n" );
20333     Abc_Print( -2, "\t        converts AIG into sequential AIG\n" );
20334     Abc_Print( -2, "\t-h    : print the command usage\n");
20335     return 1;
20336 }
20337 
20338 /**Function*************************************************************
20339 
20340   Synopsis    []
20341 
20342   Description []
20343 
20344   SideEffects []
20345 
20346   SeeAlso     []
20347 
20348 ***********************************************************************/
Abc_CommandUnseq(Abc_Frame_t * pAbc,int argc,char ** argv)20349 int Abc_CommandUnseq( Abc_Frame_t * pAbc, int argc, char ** argv )
20350 {
20351     Abc_Ntk_t * pNtk, * pNtkRes;
20352     int c;
20353     int fShare;
20354 
20355     pNtk = Abc_FrameReadNtk(pAbc);
20356     // set defaults
20357     fShare = 1;
20358     Extra_UtilGetoptReset();
20359     while ( ( c = Extra_UtilGetopt( argc, argv, "sh" ) ) != EOF )
20360     {
20361         switch ( c )
20362         {
20363         case 's':
20364             fShare ^= 1;
20365             break;
20366         case 'h':
20367             goto usage;
20368         default:
20369             goto usage;
20370         }
20371     }
20372 
20373     if ( pNtk == NULL )
20374     {
20375         Abc_Print( -1, "Empty network.\n" );
20376         return 1;
20377     }
20378 /*
20379     if ( !Abc_NtkIsSeq(pNtk) )
20380     {
20381         Abc_Print( -1, "Conversion to combinational AIG works only for sequential AIG (run \"seq\").\n" );
20382         return 1;
20383     }
20384 */
20385     // share the latches on the fanout edges
20386 //    if ( fShare )
20387 //        Seq_NtkShareFanouts(pNtk);
20388 
20389     // get the new network
20390 //    pNtkRes = Abc_NtkSeqToLogicSop( pNtk );
20391     pNtkRes = NULL;
20392     if ( pNtkRes == NULL )
20393     {
20394         Abc_Print( -1, "Converting sequential AIG into an SOP logic network has failed.\n" );
20395         return 1;
20396     }
20397     // replace the current network
20398     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
20399     return 0;
20400 
20401 usage:
20402     Abc_Print( -2, "usage: unseq [-sh]\n" );
20403     Abc_Print( -2, "\t        converts sequential AIG into an SOP logic network\n" );
20404     Abc_Print( -2, "\t-s    : toggle sharing latches [default = %s]\n", fShare? "yes": "no" );
20405     Abc_Print( -2, "\t-h    : print the command usage\n");
20406     return 1;
20407 }
20408 
20409 /**Function*************************************************************
20410 
20411   Synopsis    []
20412 
20413   Description []
20414 
20415   SideEffects []
20416 
20417   SeeAlso     []
20418 
20419 ***********************************************************************/
Abc_CommandRetime(Abc_Frame_t * pAbc,int argc,char ** argv)20420 int Abc_CommandRetime( Abc_Frame_t * pAbc, int argc, char ** argv )
20421 {
20422     Abc_Ntk_t * pNtk, * pNtkRes;
20423     int c, nMaxIters;
20424     int fForward;
20425     int fBackward;
20426     int fOneStep;
20427     int fUseOldNames;
20428     int fVerbose;
20429     int Mode;
20430     int nDelayLim;
20431 
20432     pNtk = Abc_FrameReadNtk(pAbc);
20433     // set defaults
20434     Mode      =  5;
20435     nDelayLim =  0;
20436     fForward  =  0;
20437     fBackward =  0;
20438     fOneStep  =  0;
20439     fUseOldNames = 0;
20440     fVerbose  =  0;
20441     nMaxIters = 15;
20442     Extra_UtilGetoptReset();
20443     while ( ( c = Extra_UtilGetopt( argc, argv, "MDfbsovh" ) ) != EOF )
20444     {
20445         switch ( c )
20446         {
20447         case 'M':
20448             if ( globalUtilOptind >= argc )
20449             {
20450                 Abc_Print( -1, "Command line switch \"-M\" should be followed by a positive integer.\n" );
20451                 goto usage;
20452             }
20453             Mode = atoi(argv[globalUtilOptind]);
20454             globalUtilOptind++;
20455             if ( Mode < 0 )
20456                 goto usage;
20457             break;
20458         case 'D':
20459             if ( globalUtilOptind >= argc )
20460             {
20461                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a positive integer.\n" );
20462                 goto usage;
20463             }
20464             nDelayLim = atoi(argv[globalUtilOptind]);
20465             globalUtilOptind++;
20466             if ( nDelayLim < 0 )
20467                 goto usage;
20468             break;
20469         case 'f':
20470             fForward ^= 1;
20471             break;
20472         case 'b':
20473             fBackward ^= 1;
20474             break;
20475         case 's':
20476             fOneStep ^= 1;
20477             break;
20478         case 'o':
20479             fUseOldNames ^= 1;
20480             break;
20481         case 'v':
20482             fVerbose ^= 1;
20483             break;
20484         case 'h':
20485             goto usage;
20486         default:
20487             goto usage;
20488         }
20489     }
20490 
20491     if ( pNtk == NULL )
20492     {
20493         Abc_Print( -1, "Empty network.\n" );
20494         return 1;
20495     }
20496 
20497     if ( fForward && fBackward )
20498     {
20499         Abc_Print( -1, "Only one switch \"-f\" or \"-b\" can be selected at a time.\n" );
20500         return 1;
20501     }
20502 
20503     if ( !Abc_NtkLatchNum(pNtk) )
20504     {
20505 //        Abc_Print( -1, "The network has no latches. Retiming is not performed.\n" );
20506         return 0;
20507     }
20508 
20509     if ( Mode < 0 || Mode > 6 )
20510     {
20511         Abc_Print( -1, "The mode (%d) is incorrect. Retiming is not performed.\n", Mode );
20512         return 0;
20513     }
20514 
20515     if ( Abc_NtkIsStrash(pNtk) )
20516     {
20517         if ( Abc_NtkGetChoiceNum(pNtk) )
20518         {
20519             Abc_Print( -1, "Retiming with choice nodes is not implemented.\n" );
20520             return 0;
20521         }
20522         // convert the network into an SOP network
20523         pNtkRes = Abc_NtkToLogic( pNtk );
20524         // perform the retiming
20525         Abc_NtkRetime( pNtkRes, Mode, nDelayLim, fForward, fBackward, fOneStep, fUseOldNames, fVerbose );
20526         // replace the current network
20527         Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
20528         return 0;
20529     }
20530 
20531     // get the network in the SOP form
20532     if ( !Abc_NtkToSop(pNtk, -1, ABC_INFINITY) )
20533     {
20534         Abc_Print( -1, "Converting to SOPs has failed.\n" );
20535         return 0;
20536     }
20537 
20538     if ( !Abc_NtkIsLogic(pNtk) )
20539     {
20540         Abc_Print( -1, "The network is not a logic network. Retiming is not performed.\n" );
20541         return 0;
20542     }
20543 
20544     // perform the retiming
20545     Abc_NtkRetime( pNtk, Mode, nDelayLim, fForward, fBackward, fOneStep, fUseOldNames, fVerbose );
20546     return 0;
20547 
20548 usage:
20549     Abc_Print( -2, "usage: retime [-MD num] [-fbsovh]\n" );
20550     Abc_Print( -2, "\t         retimes the current network using one of the algorithms:\n" );
20551     Abc_Print( -2, "\t             1: most forward retiming\n" );
20552     Abc_Print( -2, "\t             2: most backward retiming\n" );
20553     Abc_Print( -2, "\t             3: forward and backward min-area retiming\n" );
20554     Abc_Print( -2, "\t             4: forward and backward min-delay retiming\n" );
20555     Abc_Print( -2, "\t             5: mode 3 followed by mode 4\n" );
20556     Abc_Print( -2, "\t             6: Pan's optimum-delay retiming using binary search\n" );
20557     Abc_Print( -2, "\t-M num : the retiming algorithm to use [default = %d]\n", Mode );
20558     Abc_Print( -2, "\t-D num : the minimum delay target (0=unused) [default = %d]\n", nDelayLim );
20559     Abc_Print( -2, "\t-f     : enables forward-only retiming in modes 3,4,5 [default = %s]\n", fForward? "yes": "no" );
20560     Abc_Print( -2, "\t-b     : enables backward-only retiming in modes 3,4,5 [default = %s]\n", fBackward? "yes": "no" );
20561     Abc_Print( -2, "\t-s     : enables retiming one step only in mode 4 [default = %s]\n", fOneStep? "yes": "no" );
20562     Abc_Print( -2, "\t-o     : enables usind old flop naming conventions [default = %s]\n", fUseOldNames? "yes": "no" );
20563     Abc_Print( -2, "\t-v     : enables verbose output [default = %s]\n", fVerbose? "yes": "no" );
20564     Abc_Print( -2, "\t-h     : print the command usage\n");
20565     return 1;
20566 //    Abc_Print( -2, "\t-I num : max number of iterations of l-value computation [default = %d]\n", nMaxIters );
20567 //    Abc_Print( -2, "\t-f     : toggle forward retiming (for AIGs) [default = %s]\n", fForward? "yes": "no" );
20568 //    Abc_Print( -2, "\t-b     : toggle backward retiming (for AIGs) [default = %s]\n", fBackward? "yes": "no" );
20569 //    Abc_Print( -2, "\t-i     : toggle computation of initial state [default = %s]\n", fInitial? "yes": "no" );
20570 }
20571 
20572 /**Function*************************************************************
20573 
20574   Synopsis    []
20575 
20576   Description []
20577 
20578   SideEffects []
20579 
20580   SeeAlso     []
20581 
20582 ***********************************************************************/
Abc_CommandDRetime(Abc_Frame_t * pAbc,int argc,char ** argv)20583 int Abc_CommandDRetime( Abc_Frame_t * pAbc, int argc, char ** argv )
20584 {
20585     Abc_Ntk_t * pNtk, * pNtkRes;
20586     int fMinArea;
20587     int fForwardOnly;
20588     int fBackwardOnly;
20589     int fInitial;
20590     int nStepsMax;
20591     int fFastAlgo;
20592     int fVerbose;
20593     int c, nMaxIters;
20594     extern Abc_Ntk_t * Abc_NtkDarRetime( Abc_Ntk_t * pNtk, int nStepsMax, int fVerbose );
20595     extern Abc_Ntk_t * Abc_NtkDarRetimeF( Abc_Ntk_t * pNtk, int nStepsMax, int fVerbose );
20596     extern Abc_Ntk_t * Abc_NtkDarRetimeMinArea( Abc_Ntk_t * pNtk, int nMaxIters, int fForwardOnly, int fBackwardOnly, int fInitial, int fVerbose );
20597     extern Abc_Ntk_t * Abc_NtkDarRetimeMostFwd( Abc_Ntk_t * pNtk, int nMaxIters, int fVerbose );
20598 
20599     pNtk = Abc_FrameReadNtk(pAbc);
20600     // set defaults
20601     fMinArea  = 1;
20602     fForwardOnly = 0;
20603     fBackwardOnly = 0;
20604     fInitial = 1;
20605     nStepsMax = 100000;
20606     fFastAlgo = 0;
20607     nMaxIters = 20;
20608     fVerbose  = 0;
20609     Extra_UtilGetoptReset();
20610     while ( ( c = Extra_UtilGetopt( argc, argv, "NSmfbiavh" ) ) != EOF )
20611     {
20612         switch ( c )
20613         {
20614         case 'N':
20615             if ( globalUtilOptind >= argc )
20616             {
20617                 Abc_Print( -1, "Command line switch \"-N\" should be followed by a positive integer.\n" );
20618                 goto usage;
20619             }
20620             nMaxIters = atoi(argv[globalUtilOptind]);
20621             globalUtilOptind++;
20622             if ( nMaxIters < 0 )
20623                 goto usage;
20624             break;
20625         case 'S':
20626             if ( globalUtilOptind >= argc )
20627             {
20628                 Abc_Print( -1, "Command line switch \"-S\" should be followed by a positive integer.\n" );
20629                 goto usage;
20630             }
20631             nStepsMax = atoi(argv[globalUtilOptind]);
20632             globalUtilOptind++;
20633             if ( nStepsMax < 0 )
20634                 goto usage;
20635             break;
20636         case 'm':
20637             fMinArea ^= 1;
20638             break;
20639         case 'f':
20640             fForwardOnly ^= 1;
20641             break;
20642         case 'b':
20643             fBackwardOnly ^= 1;
20644             break;
20645         case 'i':
20646             fInitial ^= 1;
20647             break;
20648         case 'a':
20649             fFastAlgo ^= 1;
20650             break;
20651         case 'v':
20652             fVerbose ^= 1;
20653             break;
20654         case 'h':
20655             goto usage;
20656         default:
20657             goto usage;
20658         }
20659     }
20660 
20661     if ( pNtk == NULL )
20662     {
20663         Abc_Print( -1, "Empty network.\n" );
20664         return 1;
20665     }
20666 
20667     if ( !Abc_NtkLatchNum(pNtk) )
20668     {
20669 //        Abc_Print( -1, "The network has no latches. Retiming is not performed.\n" );
20670         return 0;
20671     }
20672 
20673     if ( !Abc_NtkIsStrash(pNtk) )
20674     {
20675         Abc_Print( -1, "This command works only for structrally hashed networks. Run \"st\".\n" );
20676         return 0;
20677     }
20678 
20679     // perform the retiming
20680     if ( fMinArea )
20681         pNtkRes = Abc_NtkDarRetimeMinArea( pNtk, nMaxIters, fForwardOnly, fBackwardOnly, fInitial, fVerbose );
20682     else if ( fFastAlgo )
20683         pNtkRes = Abc_NtkDarRetime( pNtk, nStepsMax, fVerbose );
20684     else
20685 //        pNtkRes = Abc_NtkDarRetimeF( pNtk, nStepsMax, fVerbose );
20686         pNtkRes = Abc_NtkDarRetimeMostFwd( pNtk, nMaxIters, fVerbose );
20687     if ( pNtkRes == NULL )
20688     {
20689         Abc_Print( -1, "Retiming has failed.\n" );
20690         return 1;
20691     }
20692     // replace the current network
20693     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
20694     return 0;
20695 
20696 usage:
20697     Abc_Print( -2, "usage: dretime [-NS num] [-mfbiavh]\n" );
20698     Abc_Print( -2, "\t         new implementation of min-area (or most-forward) retiming\n" );
20699     Abc_Print( -2, "\t-m     : toggle min-area retiming and most-forward retiming [default = %s]\n", fMinArea? "min-area": "most-fwd" );
20700     Abc_Print( -2, "\t-f     : enables forward-only retiming [default = %s]\n", fForwardOnly? "yes": "no" );
20701     Abc_Print( -2, "\t-b     : enables backward-only retiming [default = %s]\n", fBackwardOnly? "yes": "no" );
20702     Abc_Print( -2, "\t-i     : enables init state computation [default = %s]\n", fInitial? "yes": "no" );
20703     Abc_Print( -2, "\t-N num : the max number of one-frame iterations to perform [default = %d]\n", nMaxIters );
20704     Abc_Print( -2, "\t-S num : the max number of forward retiming steps to perform [default = %d]\n", nStepsMax );
20705     Abc_Print( -2, "\t-a     : enables a fast most-forward algorithm [default = %s]\n", fFastAlgo? "yes": "no" );
20706     Abc_Print( -2, "\t-v     : enables verbose output [default = %s]\n", fVerbose? "yes": "no" );
20707     Abc_Print( -2, "\t-h     : print the command usage\n");
20708     return 1;
20709 }
20710 
20711 /**Function*************************************************************
20712 
20713   Synopsis    []
20714 
20715   Description []
20716 
20717   SideEffects []
20718 
20719   SeeAlso     []
20720 
20721 ***********************************************************************/
Abc_CommandFlowRetime(Abc_Frame_t * pAbc,int argc,char ** argv)20722 int Abc_CommandFlowRetime( Abc_Frame_t * pAbc, int argc, char ** argv )
20723 {
20724     Abc_Ntk_t * pNtk, * pNtkRes;
20725     int c, nMaxIters;
20726     int fForward;
20727     int fBackward;
20728     int fVerbose;
20729     int fComputeInit, fGuaranteeInit, fBlockConst;
20730     int fFastButConservative;
20731     int maxDelay;
20732 
20733     extern Abc_Ntk_t* Abc_FlowRetime_MinReg( Abc_Ntk_t * pNtk, int fVerbose,
20734                                              int fComputeInit, int fGuaranteeInit, int fBlockConst,
20735                                              int fForward, int fBackward, int nMaxIters,
20736                                              int maxDelay, int fFastButConservative);
20737 
20738     pNtk = Abc_FrameReadNtk(pAbc);
20739     // set defaults
20740     fForward  =  0;
20741     fFastButConservative = 0;
20742     fBackward =  0;
20743     fComputeInit =  1;
20744     fGuaranteeInit =  0;
20745     fVerbose  =  0;
20746     fBlockConst  =  0;
20747     nMaxIters = 999;
20748     maxDelay  = 0;
20749     Extra_UtilGetoptReset();
20750     while ( ( c = Extra_UtilGetopt( argc, argv, "MDfcgbkivh" ) ) != EOF )
20751     {
20752         switch ( c )
20753         {
20754         case 'M':
20755             if ( globalUtilOptind >= argc )
20756             {
20757                 Abc_Print( -1, "Command line switch \"-M\" should be followed by a positive integer.\n" );
20758                 goto usage;
20759             }
20760             nMaxIters = atoi(argv[globalUtilOptind]);
20761             globalUtilOptind++;
20762             if ( nMaxIters < 0 )
20763                 goto usage;
20764             break;
20765         case 'D':
20766             if ( globalUtilOptind >= argc )
20767             {
20768                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a positive integer.\n" );
20769                 goto usage;
20770             }
20771             maxDelay = atoi(argv[globalUtilOptind]);
20772             globalUtilOptind++;
20773             if ( maxDelay < 0 )
20774                 goto usage;
20775            break;
20776         case 'f':
20777             fForward ^= 1;
20778             break;
20779         case 'c':
20780             fFastButConservative ^= 1;
20781             break;
20782         case 'i':
20783             fComputeInit ^= 1;
20784             break;
20785         case 'b':
20786             fBackward ^= 1;
20787             break;
20788         case 'g':
20789             fGuaranteeInit ^= 1;
20790             break;
20791         case 'k':
20792             fBlockConst ^= 1;
20793             break;
20794         case 'v':
20795             fVerbose ^= 1;
20796             break;
20797         case 'h':
20798             goto usage;
20799         default:
20800             goto usage;
20801         }
20802     }
20803 
20804     if ( pNtk == NULL )
20805     {
20806         Abc_Print( -1, "Empty network.\n" );
20807         return 1;
20808     }
20809 
20810     if ( fForward && fBackward )
20811     {
20812         Abc_Print( -1, "Only one switch \"-f\" or \"-b\" can be selected at a time.\n" );
20813         return 1;
20814     }
20815 
20816     if ( fGuaranteeInit && !fComputeInit )
20817     {
20818       Abc_Print( -1, "Initial state guarantee (-g) requires initial state computation (-i).\n" );
20819       return 1;
20820     }
20821 
20822     if ( !Abc_NtkLatchNum(pNtk) )
20823     {
20824         Abc_Print( -1, "The network has no latches. Retiming is not performed.\n" );
20825         return 0;
20826     }
20827 
20828     if ( Abc_NtkGetChoiceNum(pNtk) )
20829       {
20830         Abc_Print( -1, "Retiming with choice nodes is not implemented.\n" );
20831         return 0;
20832       }
20833 
20834     // perform the retiming
20835     pNtkRes = Abc_FlowRetime_MinReg( pNtk, fVerbose, fComputeInit,
20836                                      fGuaranteeInit, fBlockConst,
20837                                      fForward, fBackward,
20838                                      nMaxIters, maxDelay, fFastButConservative );
20839 
20840     if (pNtkRes != pNtk)
20841       Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
20842 
20843     return 0;
20844 
20845 usage:
20846     Abc_Print( -2, "usage: fretime [-M num] [-D num] [-fbvih]\n" );
20847     Abc_Print( -2, "\t         retimes the current network using flow-based algorithm\n" );
20848     Abc_Print( -2, "\t-M num : the maximum number of iterations [default = %d]\n", nMaxIters );
20849     Abc_Print( -2, "\t-D num : the maximum delay [default = none]\n" );
20850     Abc_Print( -2, "\t-i     : enables init state computation [default = %s]\n", fComputeInit? "yes": "no" );
20851     Abc_Print( -2, "\t-k     : blocks retiming over const nodes [default = %s]\n", fBlockConst? "yes": "no" );
20852     Abc_Print( -2, "\t-g     : guarantees init state computation [default = %s]\n", fGuaranteeInit? "yes": "no" );
20853     Abc_Print( -2, "\t-c     : very fast (but conserv.) delay constraints [default = %s]\n", fFastButConservative? "yes": "no" );
20854     Abc_Print( -2, "\t-f     : enables forward-only retiming  [default = %s]\n", fForward? "yes": "no" );
20855     Abc_Print( -2, "\t-b     : enables backward-only retiming [default = %s]\n", fBackward? "yes": "no" );
20856     Abc_Print( -2, "\t-v     : enables verbose output [default = %s]\n", fVerbose? "yes": "no" );
20857     Abc_Print( -2, "\t-h     : print the command usage\n");
20858     return 1;
20859 }
20860 
20861 /**Function*************************************************************
20862 
20863   Synopsis    []
20864 
20865   Description []
20866 
20867   SideEffects []
20868 
20869   SeeAlso     []
20870 
20871 ***********************************************************************/
Abc_CommandCRetime(Abc_Frame_t * pAbc,int argc,char ** argv)20872 int Abc_CommandCRetime( Abc_Frame_t * pAbc, int argc, char ** argv )
20873 {
20874     Abc_Ntk_t * pNtk, * pNtkRes;
20875     int c;
20876     int fVerbose;
20877     extern Abc_Ntk_t * Abc_NtkCRetime( Abc_Ntk_t * pNtk, int fVerbose );
20878 
20879     pNtk = Abc_FrameReadNtk(pAbc);
20880     // set defaults
20881     fVerbose    = 0;
20882     Extra_UtilGetoptReset();
20883     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
20884     {
20885         switch ( c )
20886         {
20887         case 'v':
20888             fVerbose ^= 1;
20889             break;
20890         case 'h':
20891             goto usage;
20892         default:
20893             goto usage;
20894         }
20895     }
20896     if ( pNtk == NULL )
20897     {
20898         Abc_Print( -1, "Empty network.\n" );
20899         return 1;
20900     }
20901     if ( Abc_NtkIsStrash(pNtk) )
20902     {
20903         Abc_Print( -1, "Only works for logic networks.\n" );
20904         return 1;
20905     }
20906     if ( !Abc_NtkLatchNum(pNtk) )
20907     {
20908         Abc_Print( -1, "The network is combinational.\n" );
20909         return 0;
20910     }
20911     // modify the current network
20912     pNtkRes = Abc_NtkCRetime( pNtk, fVerbose );
20913     if ( pNtkRes == NULL )
20914     {
20915         Abc_Print( -1, "Sequential cleanup has failed.\n" );
20916         return 1;
20917     }
20918     // replace the current network
20919     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
20920     return 0;
20921 
20922 usage:
20923     Abc_Print( -2, "usage: cretime [-vh]\n" );
20924     Abc_Print( -2, "\t         performs most-forward retiming with equiv classes\n" );
20925     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
20926     Abc_Print( -2, "\t-h     : print the command usage\n");
20927     return 1;
20928 }
20929 
20930 /**Function*************************************************************
20931 
20932   Synopsis    []
20933 
20934   Description []
20935 
20936   SideEffects []
20937 
20938   SeeAlso     []
20939 
20940 ***********************************************************************/
Abc_CommandSeqFpga(Abc_Frame_t * pAbc,int argc,char ** argv)20941 int Abc_CommandSeqFpga( Abc_Frame_t * pAbc, int argc, char ** argv )
20942 {
20943     Abc_Ntk_t * pNtk, * pNtkNew, * pNtkRes;
20944     int c, nMaxIters;
20945     int fVerbose;
20946 
20947     pNtk = Abc_FrameReadNtk(pAbc);
20948     // set defaults
20949     nMaxIters = 15;
20950     fVerbose  =  0;
20951     Extra_UtilGetoptReset();
20952     while ( ( c = Extra_UtilGetopt( argc, argv, "Ivh" ) ) != EOF )
20953     {
20954         switch ( c )
20955         {
20956         case 'I':
20957             if ( globalUtilOptind >= argc )
20958             {
20959                 Abc_Print( -1, "Command line switch \"-I\" should be followed by a positive integer.\n" );
20960                 goto usage;
20961             }
20962             nMaxIters = atoi(argv[globalUtilOptind]);
20963             globalUtilOptind++;
20964             if ( nMaxIters < 0 )
20965                 goto usage;
20966             break;
20967         case 'v':
20968             fVerbose ^= 1;
20969             break;
20970         case 'h':
20971             goto usage;
20972         default:
20973             goto usage;
20974         }
20975     }
20976 
20977     if ( pNtk == NULL )
20978     {
20979         Abc_Print( -1, "Empty network.\n" );
20980         return 1;
20981     }
20982 
20983     if ( Abc_NtkHasAig(pNtk) )
20984     {
20985 /*
20986         // quit if there are choice nodes
20987         if ( Abc_NtkGetChoiceNum(pNtk) )
20988         {
20989             Abc_Print( -1, "Currently cannot map/retime networks with choice nodes.\n" );
20990             return 0;
20991         }
20992 */
20993 //        if ( Abc_NtkIsStrash(pNtk) )
20994 //            pNtkNew = Abc_NtkAigToSeq(pNtk);
20995 //        else
20996 //            pNtkNew = Abc_NtkDup(pNtk);
20997         pNtkNew = NULL;
20998     }
20999     else
21000     {
21001         // strash and balance the network
21002         pNtkNew = Abc_NtkStrash( pNtk, 0, 0, 0 );
21003         if ( pNtkNew == NULL )
21004         {
21005             Abc_Print( -1, "Strashing before FPGA mapping/retiming has failed.\n" );
21006             return 1;
21007         }
21008 
21009         pNtkNew = Abc_NtkBalance( pNtkRes = pNtkNew, 0, 0, 1 );
21010         Abc_NtkDelete( pNtkRes );
21011         if ( pNtkNew == NULL )
21012         {
21013             Abc_Print( -1, "Balancing before FPGA mapping has failed.\n" );
21014             return 1;
21015         }
21016 
21017         // convert into a sequential AIG
21018 //        pNtkNew = Abc_NtkAigToSeq( pNtkRes = pNtkNew );
21019         pNtkNew = NULL;
21020         Abc_NtkDelete( pNtkRes );
21021         if ( pNtkNew == NULL )
21022         {
21023             Abc_Print( -1, "Converting into a seq AIG before FPGA mapping/retiming has failed.\n" );
21024             return 1;
21025         }
21026 
21027         Abc_Print( 1, "The network was strashed and balanced before FPGA mapping/retiming.\n" );
21028     }
21029 
21030     // get the new network
21031 //    pNtkRes = Seq_NtkFpgaMapRetime( pNtkNew, nMaxIters, fVerbose );
21032     pNtkRes = NULL;
21033     if ( pNtkRes == NULL )
21034     {
21035 //        Abc_Print( -1, "Sequential FPGA mapping has failed.\n" );
21036         Abc_NtkDelete( pNtkNew );
21037         return 0;
21038     }
21039     Abc_NtkDelete( pNtkNew );
21040     // replace the current network
21041     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
21042     return 0;
21043 
21044 usage:
21045     Abc_Print( -2, "usage: sfpga [-I num] [-vh]\n" );
21046     Abc_Print( -2, "\t         performs integrated sequential FPGA mapping/retiming\n" );
21047     Abc_Print( -2, "\t-I num : max number of iterations of l-value computation [default = %d]\n", nMaxIters );
21048     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
21049     Abc_Print( -2, "\t-h     : print the command usage\n");
21050     return 1;
21051 }
21052 
21053 /**Function*************************************************************
21054 
21055   Synopsis    []
21056 
21057   Description []
21058 
21059   SideEffects []
21060 
21061   SeeAlso     []
21062 
21063 ***********************************************************************/
Abc_CommandSeqMap(Abc_Frame_t * pAbc,int argc,char ** argv)21064 int Abc_CommandSeqMap( Abc_Frame_t * pAbc, int argc, char ** argv )
21065 {
21066     Abc_Ntk_t * pNtk, * pNtkNew, * pNtkRes;
21067     int c, nMaxIters;
21068     int fVerbose;
21069 
21070     pNtk = Abc_FrameReadNtk(pAbc);
21071     // set defaults
21072     nMaxIters = 15;
21073     fVerbose  =  0;
21074     Extra_UtilGetoptReset();
21075     while ( ( c = Extra_UtilGetopt( argc, argv, "Ivh" ) ) != EOF )
21076     {
21077         switch ( c )
21078         {
21079         case 'I':
21080             if ( globalUtilOptind >= argc )
21081             {
21082                 Abc_Print( -1, "Command line switch \"-I\" should be followed by a positive integer.\n" );
21083                 goto usage;
21084             }
21085             nMaxIters = atoi(argv[globalUtilOptind]);
21086             globalUtilOptind++;
21087             if ( nMaxIters < 0 )
21088                 goto usage;
21089             break;
21090         case 'v':
21091             fVerbose ^= 1;
21092             break;
21093         case 'h':
21094             goto usage;
21095         default:
21096             goto usage;
21097         }
21098     }
21099 
21100     if ( pNtk == NULL )
21101     {
21102         Abc_Print( -1, "Empty network.\n" );
21103         return 1;
21104     }
21105 
21106     if ( Abc_NtkHasAig(pNtk) )
21107     {
21108 /*
21109         // quit if there are choice nodes
21110         if ( Abc_NtkGetChoiceNum(pNtk) )
21111         {
21112             Abc_Print( -1, "Currently cannot map/retime networks with choice nodes.\n" );
21113             return 0;
21114         }
21115 */
21116 //        if ( Abc_NtkIsStrash(pNtk) )
21117 //            pNtkNew = Abc_NtkAigToSeq(pNtk);
21118 //        else
21119 //            pNtkNew = Abc_NtkDup(pNtk);
21120         pNtkNew = NULL;
21121     }
21122     else
21123     {
21124         // strash and balance the network
21125         pNtkNew = Abc_NtkStrash( pNtk, 0, 0, 0 );
21126         if ( pNtkNew == NULL )
21127         {
21128             Abc_Print( -1, "Strashing before SC mapping/retiming has failed.\n" );
21129             return 1;
21130         }
21131 
21132         pNtkNew = Abc_NtkBalance( pNtkRes = pNtkNew, 0, 0, 1 );
21133         Abc_NtkDelete( pNtkRes );
21134         if ( pNtkNew == NULL )
21135         {
21136             Abc_Print( -1, "Balancing before SC mapping/retiming has failed.\n" );
21137             return 1;
21138         }
21139 
21140         // convert into a sequential AIG
21141 //        pNtkNew = Abc_NtkAigToSeq( pNtkRes = pNtkNew );
21142         pNtkNew = NULL;
21143         Abc_NtkDelete( pNtkRes );
21144         if ( pNtkNew == NULL )
21145         {
21146             Abc_Print( -1, "Converting into a seq AIG before SC mapping/retiming has failed.\n" );
21147             return 1;
21148         }
21149 
21150         Abc_Print( -1, "The network was strashed and balanced before SC mapping/retiming.\n" );
21151     }
21152 
21153     // get the new network
21154 //    pNtkRes = Seq_MapRetime( pNtkNew, nMaxIters, fVerbose );
21155     pNtkRes = NULL;
21156     if ( pNtkRes == NULL )
21157     {
21158 //        Abc_Print( -1, "Sequential FPGA mapping has failed.\n" );
21159         Abc_NtkDelete( pNtkNew );
21160         return 0;
21161     }
21162     Abc_NtkDelete( pNtkNew );
21163 
21164     // replace the current network
21165     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
21166     return 0;
21167 
21168 usage:
21169     Abc_Print( -2, "usage: smap [-I num] [-vh]\n" );
21170     Abc_Print( -2, "\t         performs integrated sequential standard-cell mapping/retiming\n" );
21171     Abc_Print( -2, "\t-I num : max number of iterations of l-value computation [default = %d]\n", nMaxIters );
21172     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
21173     Abc_Print( -2, "\t-h     : print the command usage\n");
21174     return 1;
21175 }
21176 
21177 /**Function*************************************************************
21178 
21179   Synopsis    []
21180 
21181   Description []
21182 
21183   SideEffects []
21184 
21185   SeeAlso     []
21186 
21187 ***********************************************************************/
Abc_CommandSeqSweep(Abc_Frame_t * pAbc,int argc,char ** argv)21188 int Abc_CommandSeqSweep( Abc_Frame_t * pAbc, int argc, char ** argv )
21189 {
21190     Abc_Ntk_t * pNtk, * pNtkRes;
21191     Fra_Ssw_t Pars, * pPars = &Pars;
21192     int c;
21193     extern Abc_Ntk_t * Abc_NtkDarSeqSweep( Abc_Ntk_t * pNtk, Fra_Ssw_t * pPars );
21194 
21195     pNtk = Abc_FrameReadNtk(pAbc);
21196     // set defaults
21197     pPars->nPartSize  = 0;
21198     pPars->nOverSize  = 0;
21199     pPars->nFramesP   = 0;
21200     pPars->nFramesK   = 1;
21201     pPars->nMaxImps   = 5000;
21202     pPars->nMaxLevs   = 0;
21203     pPars->fUseImps   = 0;
21204     pPars->fRewrite   = 0;
21205     pPars->fFraiging  = 0;
21206     pPars->fLatchCorr = 0;
21207     pPars->fWriteImps = 0;
21208     pPars->fUse1Hot   = 0;
21209     pPars->fVerbose   = 0;
21210     pPars->TimeLimit  = 0;
21211     Extra_UtilGetoptReset();
21212     while ( ( c = Extra_UtilGetopt( argc, argv, "PQNFILirfletvh" ) ) != EOF )
21213     {
21214         switch ( c )
21215         {
21216         case 'P':
21217             if ( globalUtilOptind >= argc )
21218             {
21219                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
21220                 goto usage;
21221             }
21222             pPars->nPartSize = atoi(argv[globalUtilOptind]);
21223             globalUtilOptind++;
21224             if ( pPars->nPartSize < 2 )
21225                 goto usage;
21226             break;
21227         case 'Q':
21228             if ( globalUtilOptind >= argc )
21229             {
21230                 Abc_Print( -1, "Command line switch \"-Q\" should be followed by an integer.\n" );
21231                 goto usage;
21232             }
21233             pPars->nOverSize = atoi(argv[globalUtilOptind]);
21234             globalUtilOptind++;
21235             if ( pPars->nOverSize < 0 )
21236                 goto usage;
21237             break;
21238         case 'N':
21239             if ( globalUtilOptind >= argc )
21240             {
21241                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
21242                 goto usage;
21243             }
21244             pPars->nFramesP = atoi(argv[globalUtilOptind]);
21245             globalUtilOptind++;
21246             if ( pPars->nFramesP < 0 )
21247                 goto usage;
21248             break;
21249         case 'F':
21250             if ( globalUtilOptind >= argc )
21251             {
21252                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
21253                 goto usage;
21254             }
21255             pPars->nFramesK = atoi(argv[globalUtilOptind]);
21256             globalUtilOptind++;
21257             if ( pPars->nFramesK <= 0 )
21258                 goto usage;
21259             break;
21260         case 'I':
21261             if ( globalUtilOptind >= argc )
21262             {
21263                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
21264                 goto usage;
21265             }
21266             pPars->nMaxImps = atoi(argv[globalUtilOptind]);
21267             globalUtilOptind++;
21268             if ( pPars->nMaxImps <= 0 )
21269                 goto usage;
21270             break;
21271         case 'L':
21272             if ( globalUtilOptind >= argc )
21273             {
21274                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
21275                 goto usage;
21276             }
21277             pPars->nMaxLevs = atoi(argv[globalUtilOptind]);
21278             globalUtilOptind++;
21279             if ( pPars->nMaxLevs <= 0 )
21280                 goto usage;
21281             break;
21282         case 'i':
21283             pPars->fUseImps ^= 1;
21284             break;
21285         case 'r':
21286             pPars->fRewrite ^= 1;
21287             break;
21288         case 'f':
21289             pPars->fFraiging ^= 1;
21290             break;
21291         case 'l':
21292             pPars->fLatchCorr ^= 1;
21293             break;
21294         case 'e':
21295             pPars->fWriteImps ^= 1;
21296             break;
21297         case 't':
21298             pPars->fUse1Hot ^= 1;
21299             break;
21300         case 'v':
21301             pPars->fVerbose ^= 1;
21302             break;
21303         case 'h':
21304             goto usage;
21305         default:
21306             goto usage;
21307         }
21308     }
21309 
21310     if ( pNtk == NULL )
21311     {
21312         Abc_Print( -1, "Empty network.\n" );
21313         return 1;
21314     }
21315 
21316     if ( Abc_NtkIsComb(pNtk) )
21317     {
21318         Abc_Print( 0, "The network is combinational (run \"fraig\" or \"fraig_sweep\").\n" );
21319         return 0;
21320     }
21321 
21322     if ( !Abc_NtkIsStrash(pNtk) )
21323     {
21324         Abc_Print( -1, "This command works only for structrally hashed networks. Run \"st\".\n" );
21325         return 0;
21326     }
21327 
21328     if ( pPars->nFramesK > 1 && pPars->fUse1Hot )
21329     {
21330         Abc_Print( -1, "Currrently can only use one-hotness for simple induction (K=1).\n" );
21331         return 0;
21332     }
21333 
21334     if ( pPars->nFramesP && pPars->fUse1Hot )
21335     {
21336         Abc_Print( -1, "Currrently can only use one-hotness without prefix.\n" );
21337         return 0;
21338     }
21339 
21340     // get the new network
21341     pNtkRes = Abc_NtkDarSeqSweep( pNtk, pPars );
21342     if ( pNtkRes == NULL )
21343     {
21344         Abc_Print( -1, "Sequential sweeping has failed.\n" );
21345         return 1;
21346     }
21347     // replace the current network
21348     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
21349     return 0;
21350 
21351 usage:
21352     Abc_Print( -2, "usage: ssweep [-PQNFL <num>] [-lrfetvh]\n" );
21353     Abc_Print( -2, "\t         performs sequential sweep using K-step induction\n" );
21354     Abc_Print( -2, "\t-P num : max partition size (0 = no partitioning) [default = %d]\n", pPars->nPartSize );
21355     Abc_Print( -2, "\t-Q num : partition overlap (0 = no overlap) [default = %d]\n", pPars->nOverSize );
21356     Abc_Print( -2, "\t-N num : number of time frames to use as the prefix [default = %d]\n", pPars->nFramesP );
21357     Abc_Print( -2, "\t-F num : number of time frames for induction (1=simple) [default = %d]\n", pPars->nFramesK );
21358     Abc_Print( -2, "\t-L num : max number of levels to consider (0=all) [default = %d]\n", pPars->nMaxLevs );
21359 //    Abc_Print( -2, "\t-I num : max number of implications to consider [default = %d]\n", pPars->nMaxImps );
21360 //    Abc_Print( -2, "\t-i     : toggle using implications [default = %s]\n", pPars->fUseImps? "yes": "no" );
21361     Abc_Print( -2, "\t-l     : toggle latch correspondence only [default = %s]\n", pPars->fLatchCorr? "yes": "no" );
21362     Abc_Print( -2, "\t-r     : toggle AIG rewriting [default = %s]\n", pPars->fRewrite? "yes": "no" );
21363     Abc_Print( -2, "\t-f     : toggle fraiging (combinational SAT sweeping) [default = %s]\n", pPars->fFraiging? "yes": "no" );
21364     Abc_Print( -2, "\t-e     : toggle writing implications as assertions [default = %s]\n", pPars->fWriteImps? "yes": "no" );
21365     Abc_Print( -2, "\t-t     : toggle using one-hotness conditions [default = %s]\n", pPars->fUse1Hot? "yes": "no" );
21366     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
21367     Abc_Print( -2, "\t-h     : print the command usage\n");
21368     return 1;
21369 }
21370 
21371 /**Function*************************************************************
21372 
21373   Synopsis    []
21374 
21375   Description []
21376 
21377   SideEffects []
21378 
21379   SeeAlso     []
21380 
21381 ***********************************************************************/
Abc_CommandSeqSweep2(Abc_Frame_t * pAbc,int argc,char ** argv)21382 int Abc_CommandSeqSweep2( Abc_Frame_t * pAbc, int argc, char ** argv )
21383 {
21384     Abc_Ntk_t * pNtk, * pNtkRes;
21385     Ssw_Pars_t Pars, * pPars = &Pars;
21386     int nConstrs = 0;
21387     int c;
21388     extern Abc_Ntk_t * Abc_NtkDarSeqSweep2( Abc_Ntk_t * pNtk, Ssw_Pars_t * pPars );
21389 
21390     pNtk = Abc_FrameReadNtk(pAbc);
21391     // set defaults
21392     Ssw_ManSetDefaultParams( pPars );
21393     Extra_UtilGetoptReset();
21394     while ( ( c = Extra_UtilGetopt( argc, argv, "PQFCLSIVMNcmplkodsefqvwh" ) ) != EOF )
21395     {
21396         switch ( c )
21397         {
21398         case 'P':
21399             if ( globalUtilOptind >= argc )
21400             {
21401                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
21402                 goto usage;
21403             }
21404             pPars->nPartSize = atoi(argv[globalUtilOptind]);
21405             globalUtilOptind++;
21406             if ( pPars->nPartSize < 2 )
21407                 goto usage;
21408             break;
21409         case 'Q':
21410             if ( globalUtilOptind >= argc )
21411             {
21412                 Abc_Print( -1, "Command line switch \"-Q\" should be followed by an integer.\n" );
21413                 goto usage;
21414             }
21415             pPars->nOverSize = atoi(argv[globalUtilOptind]);
21416             globalUtilOptind++;
21417             if ( pPars->nOverSize < 0 )
21418                 goto usage;
21419             break;
21420         case 'F':
21421             if ( globalUtilOptind >= argc )
21422             {
21423                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
21424                 goto usage;
21425             }
21426             pPars->nFramesK = atoi(argv[globalUtilOptind]);
21427             globalUtilOptind++;
21428             if ( pPars->nFramesK <= 0 )
21429                 goto usage;
21430             break;
21431         case 'C':
21432             if ( globalUtilOptind >= argc )
21433             {
21434                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
21435                 goto usage;
21436             }
21437             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
21438             globalUtilOptind++;
21439             if ( pPars->nBTLimit <= 0 )
21440                 goto usage;
21441             break;
21442         case 'L':
21443             if ( globalUtilOptind >= argc )
21444             {
21445                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
21446                 goto usage;
21447             }
21448             pPars->nMaxLevs = atoi(argv[globalUtilOptind]);
21449             globalUtilOptind++;
21450             if ( pPars->nMaxLevs <= 0 )
21451                 goto usage;
21452             break;
21453         case 'S':
21454             if ( globalUtilOptind >= argc )
21455             {
21456                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
21457                 goto usage;
21458             }
21459             pPars->nFramesAddSim = atoi(argv[globalUtilOptind]);
21460             globalUtilOptind++;
21461             if ( pPars->nFramesAddSim < 0 )
21462                 goto usage;
21463             break;
21464         case 'I':
21465             if ( globalUtilOptind >= argc )
21466             {
21467                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
21468                 goto usage;
21469             }
21470             pPars->nItersStop = atoi(argv[globalUtilOptind]);
21471             globalUtilOptind++;
21472             if ( pPars->nItersStop < 0 )
21473                 goto usage;
21474             break;
21475         case 'V':
21476             if ( globalUtilOptind >= argc )
21477             {
21478                 Abc_Print( -1, "Command line switch \"-V\" should be followed by an integer.\n" );
21479                 goto usage;
21480             }
21481             pPars->nSatVarMax2 = atoi(argv[globalUtilOptind]);
21482             globalUtilOptind++;
21483             if ( pPars->nSatVarMax2 < 0 )
21484                 goto usage;
21485             break;
21486         case 'M':
21487             if ( globalUtilOptind >= argc )
21488             {
21489                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
21490                 goto usage;
21491             }
21492             pPars->nRecycleCalls2 = atoi(argv[globalUtilOptind]);
21493             globalUtilOptind++;
21494             if ( pPars->nRecycleCalls2 < 0 )
21495                 goto usage;
21496             break;
21497         case 'N':
21498             if ( globalUtilOptind >= argc )
21499             {
21500                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
21501                 goto usage;
21502             }
21503             nConstrs = atoi(argv[globalUtilOptind]);
21504             globalUtilOptind++;
21505             if ( nConstrs < 0 )
21506                 goto usage;
21507             break;
21508         case 'c':
21509             pPars->fConstrs ^= 1;
21510             break;
21511         case 'm':
21512             pPars->fMergeFull ^= 1;
21513             break;
21514         case 'p':
21515             pPars->fPolarFlip ^= 1;
21516             break;
21517         case 'l':
21518             pPars->fLatchCorr ^= 1;
21519             break;
21520         case 'k':
21521             pPars->fConstCorr ^= 1;
21522             break;
21523         case 'o':
21524             pPars->fOutputCorr ^= 1;
21525             break;
21526 //        case 'f':
21527 //            pPars->fSemiFormal ^= 1;
21528 //            break;
21529         case 'd':
21530             pPars->fDynamic ^= 1;
21531             break;
21532         case 's':
21533             pPars->fLocalSim ^= 1;
21534             break;
21535         case 'e':
21536             pPars->fEquivDump ^= 1;
21537             break;
21538         case 'f':
21539             pPars->fEquivDump2 ^= 1;
21540             break;
21541         case 'q':
21542             pPars->fStopWhenGone ^= 1;
21543             break;
21544         case 'v':
21545             pPars->fVerbose ^= 1;
21546             break;
21547         case 'w':
21548             pPars->fFlopVerbose ^= 1;
21549             break;
21550         case 'h':
21551             goto usage;
21552         default:
21553             goto usage;
21554         }
21555     }
21556 
21557     if ( pNtk == NULL )
21558     {
21559         Abc_Print( -1, "Empty network.\n" );
21560         return 1;
21561     }
21562 
21563     if ( Abc_NtkIsComb(pNtk) )
21564     {
21565         Abc_Print( 0, "The network is combinational (run \"fraig\" or \"fraig_sweep\").\n" );
21566         return 0;
21567     }
21568 
21569     if ( !Abc_NtkIsStrash(pNtk) )
21570     {
21571         Abc_Print( 0, "This command works only for structrally hashed networks. Run \"st\".\n" );
21572         return 0;
21573     }
21574 
21575     if ( Abc_NtkPiNum(pNtk) == 0 )
21576     {
21577         Abc_Print( 0, "This command works only for designs with primary inputs.\n" );
21578         return 0;
21579     }
21580 
21581     // if constraints are to be used, network should have no constraints
21582     if ( nConstrs > 0 )
21583     {
21584         if ( Abc_NtkConstrNum(pNtk) > 0 )
21585         {
21586             Abc_Print( -1, "The network already has %d constraints.\n", Abc_NtkConstrNum(pNtk) );
21587             return 0;
21588         }
21589         else
21590         {
21591             Abc_Print( 0, "Setting the number of constraints to be %d.\n", nConstrs );
21592             pNtk->nConstrs = nConstrs;
21593         }
21594     }
21595 
21596     if ( pPars->fConstrs )
21597     {
21598         if ( Abc_NtkConstrNum(pNtk) == Abc_NtkPoNum(pNtk) )
21599         {
21600             Abc_Print( 0, "Command cannot be applied because the network has only constraint outputs (no primary outputs).\n" );
21601             return 0;
21602         }
21603         if ( Abc_NtkConstrNum(pNtk) > 0 )
21604             Abc_Print( 0, "Performing scorr with %d constraints.\n", Abc_NtkConstrNum(pNtk) );
21605         else
21606         {
21607             Abc_Print( 0, "Performing constraint-based scorr without constraints.\n" );
21608             pPars->fConstrs = 0;
21609         }
21610     }
21611     if ( pPars->fEquivDump && pPars->fEquivDump2 )
21612     {
21613         Abc_Print( 0, "Command line switches \'-e\' and \'-f\' cannot be used at the same time.\n" );
21614         return 0;
21615     }
21616 
21617     // get the new network
21618     pNtkRes = Abc_NtkDarSeqSweep2( pNtk, pPars );
21619     if ( pNtkRes == NULL )
21620     {
21621         Abc_Print( -1, "Sequential sweeping has failed.\n" );
21622         return 1;
21623     }
21624     // replace the current network
21625     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
21626     return 0;
21627 
21628 usage:
21629     Abc_Print( -2, "usage: scorr [-PQFCLSIVMN <num>] [-cmplkodsefqvwh]\n" );
21630     Abc_Print( -2, "\t         performs sequential sweep using K-step induction\n" );
21631     Abc_Print( -2, "\t-P num : max partition size (0 = no partitioning) [default = %d]\n", pPars->nPartSize );
21632     Abc_Print( -2, "\t-Q num : partition overlap (0 = no overlap) [default = %d]\n", pPars->nOverSize );
21633     Abc_Print( -2, "\t-F num : number of time frames for induction (1=simple) [default = %d]\n", pPars->nFramesK );
21634     Abc_Print( -2, "\t-C num : max number of conflicts at a node (0=inifinite) [default = %d]\n", pPars->nBTLimit );
21635     Abc_Print( -2, "\t-L num : max number of levels to consider (0=all) [default = %d]\n", pPars->nMaxLevs );
21636     Abc_Print( -2, "\t-N num : number of last POs treated as constraints (0=none) [default = %d]\n", pPars->fConstrs );
21637     Abc_Print( -2, "\t-S num : additional simulation frames for c-examples (0=none) [default = %d]\n", pPars->nFramesAddSim );
21638     Abc_Print( -2, "\t-I num : iteration number to stop and output SR-model (-1=none) [default = %d]\n", pPars->nItersStop );
21639     Abc_Print( -2, "\t-V num : min var num needed to recycle the SAT solver [default = %d]\n", pPars->nSatVarMax2 );
21640     Abc_Print( -2, "\t-M num : min call num needed to recycle the SAT solver [default = %d]\n", pPars->nRecycleCalls2 );
21641     Abc_Print( -2, "\t-N num : set last <num> POs to be constraints (use with -c) [default = %d]\n", nConstrs );
21642     Abc_Print( -2, "\t-c     : toggle using explicit constraints [default = %s]\n", pPars->fConstrs? "yes": "no" );
21643     Abc_Print( -2, "\t-m     : toggle full merge if constraints are present [default = %s]\n", pPars->fMergeFull? "yes": "no" );
21644     Abc_Print( -2, "\t-p     : toggle aligning polarity of SAT variables [default = %s]\n", pPars->fPolarFlip? "yes": "no" );
21645     Abc_Print( -2, "\t-l     : toggle doing latch correspondence [default = %s]\n", pPars->fLatchCorr? "yes": "no" );
21646     Abc_Print( -2, "\t-k     : toggle doing constant correspondence [default = %s]\n", pPars->fConstCorr? "yes": "no" );
21647     Abc_Print( -2, "\t-o     : toggle doing \'PO correspondence\' [default = %s]\n", pPars->fOutputCorr? "yes": "no" );
21648 //    Abc_Print( -2, "\t-f     : toggle filtering using iterative BMC [default = %s]\n", pPars->fSemiFormal? "yes": "no" );
21649     Abc_Print( -2, "\t-d     : toggle dynamic addition of constraints [default = %s]\n", pPars->fDynamic? "yes": "no" );
21650     Abc_Print( -2, "\t-s     : toggle local simulation in the cone of influence [default = %s]\n", pPars->fLocalSim? "yes": "no" );
21651     Abc_Print( -2, "\t-e     : toggle dumping disproved internal equivalences [default = %s]\n", pPars->fEquivDump? "yes": "no" );
21652     Abc_Print( -2, "\t-f     : toggle dumping proved internal equivalences [default = %s]\n", pPars->fEquivDump2? "yes": "no" );
21653     Abc_Print( -2, "\t-q     : toggle quitting when PO is not a constant candidate [default = %s]\n", pPars->fStopWhenGone? "yes": "no" );
21654     Abc_Print( -2, "\t-w     : toggle printout of flop equivalences [default = %s]\n", pPars->fFlopVerbose? "yes": "no" );
21655     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
21656     Abc_Print( -2, "\t-h     : print the command usage\n");
21657     return 1;
21658 }
21659 
21660 /**Function*************************************************************
21661 
21662   Synopsis    []
21663 
21664   Description []
21665 
21666   SideEffects []
21667 
21668   SeeAlso     []
21669 
21670 ***********************************************************************/
Abc_CommandTestSeqSweep(Abc_Frame_t * pAbc,int argc,char ** argv)21671 int Abc_CommandTestSeqSweep( Abc_Frame_t * pAbc, int argc, char ** argv )
21672 {
21673     char * pFileName;
21674     Fra_Ssw_t Pars, * pPars = &Pars;
21675     int c;
21676 //    extern Abc_Ntk_t * Abc_NtkDarSeqSweep( Abc_Ntk_t * pNtk, Fra_Ssw_t * pPars );
21677     extern int Fra_FraigInductionTest( char * pFileName, Fra_Ssw_t * pParams );
21678 
21679     // set defaults
21680     pPars->nPartSize  = 0;
21681     pPars->nOverSize  = 0;
21682     pPars->nFramesP   = 0;
21683     pPars->nFramesK   = 1;
21684     pPars->nMaxImps   = 5000;
21685     pPars->nMaxLevs   = 0;
21686     pPars->fUseImps   = 0;
21687     pPars->fRewrite   = 0;
21688     pPars->fFraiging  = 0;
21689     pPars->fLatchCorr = 0;
21690     pPars->fWriteImps = 0;
21691     pPars->fUse1Hot   = 0;
21692     pPars->fVerbose   = 0;
21693     pPars->TimeLimit  = 0;
21694     Extra_UtilGetoptReset();
21695     while ( ( c = Extra_UtilGetopt( argc, argv, "PQNFILirfletvh" ) ) != EOF )
21696     {
21697         switch ( c )
21698         {
21699         case 'P':
21700             if ( globalUtilOptind >= argc )
21701             {
21702                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
21703                 goto usage;
21704             }
21705             pPars->nPartSize = atoi(argv[globalUtilOptind]);
21706             globalUtilOptind++;
21707             if ( pPars->nPartSize < 2 )
21708                 goto usage;
21709             break;
21710         case 'Q':
21711             if ( globalUtilOptind >= argc )
21712             {
21713                 Abc_Print( -1, "Command line switch \"-Q\" should be followed by an integer.\n" );
21714                 goto usage;
21715             }
21716             pPars->nOverSize = atoi(argv[globalUtilOptind]);
21717             globalUtilOptind++;
21718             if ( pPars->nOverSize < 0 )
21719                 goto usage;
21720             break;
21721         case 'N':
21722             if ( globalUtilOptind >= argc )
21723             {
21724                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
21725                 goto usage;
21726             }
21727             pPars->nFramesP = atoi(argv[globalUtilOptind]);
21728             globalUtilOptind++;
21729             if ( pPars->nFramesP < 0 )
21730                 goto usage;
21731             break;
21732         case 'F':
21733             if ( globalUtilOptind >= argc )
21734             {
21735                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
21736                 goto usage;
21737             }
21738             pPars->nFramesK = atoi(argv[globalUtilOptind]);
21739             globalUtilOptind++;
21740             if ( pPars->nFramesK <= 0 )
21741                 goto usage;
21742             break;
21743         case 'I':
21744             if ( globalUtilOptind >= argc )
21745             {
21746                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
21747                 goto usage;
21748             }
21749             pPars->nMaxImps = atoi(argv[globalUtilOptind]);
21750             globalUtilOptind++;
21751             if ( pPars->nMaxImps <= 0 )
21752                 goto usage;
21753             break;
21754         case 'L':
21755             if ( globalUtilOptind >= argc )
21756             {
21757                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
21758                 goto usage;
21759             }
21760             pPars->nMaxLevs = atoi(argv[globalUtilOptind]);
21761             globalUtilOptind++;
21762             if ( pPars->nMaxLevs <= 0 )
21763                 goto usage;
21764             break;
21765         case 'i':
21766             pPars->fUseImps ^= 1;
21767             break;
21768         case 'r':
21769             pPars->fRewrite ^= 1;
21770             break;
21771         case 'f':
21772             pPars->fFraiging ^= 1;
21773             break;
21774         case 'l':
21775             pPars->fLatchCorr ^= 1;
21776             break;
21777         case 'e':
21778             pPars->fWriteImps ^= 1;
21779             break;
21780         case 't':
21781             pPars->fUse1Hot ^= 1;
21782             break;
21783         case 'v':
21784             pPars->fVerbose ^= 1;
21785             break;
21786         case 'h':
21787             goto usage;
21788         default:
21789             goto usage;
21790         }
21791     }
21792     // get the input file name
21793     if ( argc == globalUtilOptind + 1 )
21794         pFileName = argv[globalUtilOptind];
21795     else
21796     {
21797         Abc_Print( -1, "File name should be given on the command line.\n" );
21798         return 1;
21799     }
21800     Fra_FraigInductionTest( pFileName, pPars );
21801     return 0;
21802 
21803 usage:
21804     Abc_Print( -2, "usage: testssw [-PQNFL num] [-lrfetvh] <file>\n" );
21805     Abc_Print( -2, "\t         performs sequential sweep using K-step induction\n" );
21806     Abc_Print( -2, "\t         (outputs a file with a set of pairs of equivalent nodes)\n" );
21807     Abc_Print( -2, "\t-P num : max partition size (0 = no partitioning) [default = %d]\n", pPars->nPartSize );
21808     Abc_Print( -2, "\t-Q num : partition overlap (0 = no overlap) [default = %d]\n", pPars->nOverSize );
21809     Abc_Print( -2, "\t-N num : number of time frames to use as the prefix [default = %d]\n", pPars->nFramesP );
21810     Abc_Print( -2, "\t-F num : number of time frames for induction (1=simple) [default = %d]\n", pPars->nFramesK );
21811     Abc_Print( -2, "\t-L num : max number of levels to consider (0=all) [default = %d]\n", pPars->nMaxLevs );
21812 //    Abc_Print( -2, "\t-I num : max number of implications to consider [default = %d]\n", pPars->nMaxImps );
21813 //    Abc_Print( -2, "\t-i     : toggle using implications [default = %s]\n", pPars->fUseImps? "yes": "no" );
21814     Abc_Print( -2, "\t-l     : toggle latch correspondence only [default = %s]\n", pPars->fLatchCorr? "yes": "no" );
21815     Abc_Print( -2, "\t-r     : toggle AIG rewriting [default = %s]\n", pPars->fRewrite? "yes": "no" );
21816     Abc_Print( -2, "\t-f     : toggle fraiging (combinational SAT sweeping) [default = %s]\n", pPars->fFraiging? "yes": "no" );
21817     Abc_Print( -2, "\t-e     : toggle writing implications as assertions [default = %s]\n", pPars->fWriteImps? "yes": "no" );
21818     Abc_Print( -2, "\t-t     : toggle using one-hotness conditions [default = %s]\n", pPars->fUse1Hot? "yes": "no" );
21819     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
21820     Abc_Print( -2, "\t-h     : print the command usage\n");
21821     return 1;
21822 }
21823 
21824 /**Function*************************************************************
21825 
21826   Synopsis    []
21827 
21828   Description []
21829 
21830   SideEffects []
21831 
21832   SeeAlso     []
21833 
21834 ***********************************************************************/
Abc_CommandTestScorr(Abc_Frame_t * pAbc,int argc,char ** argv)21835 int Abc_CommandTestScorr( Abc_Frame_t * pAbc, int argc, char ** argv )
21836 {
21837     extern Abc_Ntk_t * Abc_NtkTestScorr( char * pFileNameIn, char * pFileNameOut, int nStepsMax, int nBTLimit, int fNewAlgo, int fFlopOnly, int fFfNdOnly, int fVerbose );
21838 
21839     Abc_Ntk_t * pNtkRes;
21840     int c;
21841     int nConfMax;
21842     int nStepsMax;
21843     int fNewAlgo;
21844     int fFlopOnly;
21845     int fFfNdOnly;
21846     int fVerbose;
21847     // set defaults
21848     nConfMax  = 100;
21849     nStepsMax =  -1;
21850     fNewAlgo  =   0;
21851     fFlopOnly =   0;
21852     fFfNdOnly =   0;
21853     fVerbose  =   0;
21854     Extra_UtilGetoptReset();
21855     while ( ( c = Extra_UtilGetopt( argc, argv, "CSnfsvh" ) ) != EOF )
21856     {
21857         switch ( c )
21858         {
21859         case 'C':
21860             if ( globalUtilOptind >= argc )
21861             {
21862                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
21863                 goto usage;
21864             }
21865             nConfMax = atoi(argv[globalUtilOptind]);
21866             globalUtilOptind++;
21867             if ( nConfMax < 0 )
21868                 goto usage;
21869             break;
21870         case 'S':
21871             if ( globalUtilOptind >= argc )
21872             {
21873                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
21874                 goto usage;
21875             }
21876             nStepsMax = atoi(argv[globalUtilOptind]);
21877             globalUtilOptind++;
21878             if ( nStepsMax < 0 )
21879                 goto usage;
21880             break;
21881         case 'n':
21882             fNewAlgo ^= 1;
21883             break;
21884         case 'f':
21885             fFlopOnly ^= 1;
21886             break;
21887         case 's':
21888             fFfNdOnly ^= 1;
21889             break;
21890         case 'v':
21891             fVerbose ^= 1;
21892             break;
21893         default:
21894             goto usage;
21895         }
21896     }
21897     if ( argc != globalUtilOptind + 2 )
21898     {
21899         Abc_Print( -1, "Expecting two files names on the command line.\n" );
21900         goto usage;
21901     }
21902     if ( fFlopOnly && fFfNdOnly )
21903     {
21904         Abc_Print( -1, "These two options (-f and -s) are incompatible.\n" );
21905         goto usage;
21906     }
21907     // get the new network
21908     pNtkRes = Abc_NtkTestScorr( argv[globalUtilOptind], argv[globalUtilOptind+1], nStepsMax, nConfMax, fNewAlgo, fFlopOnly, fFfNdOnly, fVerbose );
21909     if ( pNtkRes == NULL )
21910     {
21911         Abc_Print( -1, "Sequential sweeping has failed.\n" );
21912         return 1;
21913     }
21914     // replace the current network
21915     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
21916     return 0;
21917 
21918 usage:
21919     Abc_Print( -2, "usage: testscorr [-CS num] [-nfsvh] <file_in> <file_out>\n" );
21920     Abc_Print( -2, "\t             outputs the list of sequential equivalences into a file\n" );
21921     Abc_Print( -2, "\t             (if <file_in> is in BENCH, init state file should be the same directory)\n" );
21922     Abc_Print( -2, "\t-C num     : limit on the number of conflicts [default = %d]\n", nConfMax );
21923     Abc_Print( -2, "\t-S num     : limit on refinement iterations (-1=no limit, 0=after BMC, etc) [default = %d]\n", nStepsMax );
21924     Abc_Print( -2, "\t-n         : toggle between \"scorr\" and \"&scorr\" [default = %s]\n", fNewAlgo? "&scorr": "scorr" );
21925     Abc_Print( -2, "\t-f         : toggle reporting only flop/flop equivs [default = %s]\n", fFlopOnly? "yes": "no" );
21926     Abc_Print( -2, "\t-s         : toggle reporting only flop/flop and flop/node equivs [default = %s]\n", fFfNdOnly? "yes": "no" );
21927     Abc_Print( -2, "\t-v         : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
21928     Abc_Print( -2, "\t-h         : print the command usage\n");
21929     Abc_Print( -2, "\t<file_in>  : input file with design for sequential equivalence computation\n");
21930     Abc_Print( -2, "\t<file_out> : output file with the list of pairs of equivalent signals\n");
21931     return 1;
21932 }
21933 
21934 /**Function*************************************************************
21935 
21936   Synopsis    []
21937 
21938   Description []
21939 
21940   SideEffects []
21941 
21942   SeeAlso     []
21943 
21944 ***********************************************************************/
Abc_CommandLcorr(Abc_Frame_t * pAbc,int argc,char ** argv)21945 int Abc_CommandLcorr( Abc_Frame_t * pAbc, int argc, char ** argv )
21946 {
21947     Abc_Ntk_t * pNtk, * pNtkRes;
21948     int c;
21949     int nFramesP;
21950     int nConfMax;
21951     int nVarsMax;
21952     int fNewAlgor;
21953     int fVerbose;
21954     extern Abc_Ntk_t * Abc_NtkDarLcorr( Abc_Ntk_t * pNtk, int nFramesP, int nConfMax, int fVerbose );
21955     extern Abc_Ntk_t * Abc_NtkDarLcorrNew( Abc_Ntk_t * pNtk, int nVarsMax, int nConfMax, int fVerbose );
21956 
21957     pNtk = Abc_FrameReadNtk(pAbc);
21958 
21959 
21960 
21961     // set defaults
21962     nFramesP   =     0;
21963     nConfMax   =  1000;
21964     nVarsMax   =  1000;
21965     fNewAlgor  =     1;
21966     fVerbose   =     0;
21967     Extra_UtilGetoptReset();
21968     while ( ( c = Extra_UtilGetopt( argc, argv, "PCSnvh" ) ) != EOF )
21969     {
21970         switch ( c )
21971         {
21972         case 'P':
21973             if ( globalUtilOptind >= argc )
21974             {
21975                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
21976                 goto usage;
21977             }
21978             nFramesP = atoi(argv[globalUtilOptind]);
21979             globalUtilOptind++;
21980             if ( nFramesP < 0 )
21981                 goto usage;
21982             break;
21983         case 'C':
21984             if ( globalUtilOptind >= argc )
21985             {
21986                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
21987                 goto usage;
21988             }
21989             nConfMax = atoi(argv[globalUtilOptind]);
21990             globalUtilOptind++;
21991             if ( nConfMax < 0 )
21992                 goto usage;
21993             break;
21994         case 'S':
21995             if ( globalUtilOptind >= argc )
21996             {
21997                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
21998                 goto usage;
21999             }
22000             nVarsMax = atoi(argv[globalUtilOptind]);
22001             globalUtilOptind++;
22002             if ( nVarsMax < 0 )
22003                 goto usage;
22004             break;
22005         case 'n':
22006             fNewAlgor ^= 1;
22007             break;
22008         case 'v':
22009             fVerbose ^= 1;
22010             break;
22011         case 'h':
22012             goto usage;
22013         default:
22014             goto usage;
22015         }
22016     }
22017 
22018     if ( pNtk == NULL )
22019     {
22020         Abc_Print( -1, "Empty network.\n" );
22021         return 1;
22022     }
22023 
22024     if ( Abc_NtkIsComb(pNtk) )
22025     {
22026         Abc_Print( -1, "The network is combinational (run \"fraig\" or \"fraig_sweep\").\n" );
22027         return 0;
22028     }
22029 
22030     if ( !Abc_NtkIsStrash(pNtk) )
22031     {
22032         Abc_Print( -1, "This command works only for structrally hashed networks. Run \"st\".\n" );
22033         return 0;
22034     }
22035 
22036     // get the new network
22037     if ( fNewAlgor )
22038         pNtkRes = Abc_NtkDarLcorrNew( pNtk, nVarsMax, nConfMax, fVerbose );
22039     else
22040         pNtkRes = Abc_NtkDarLcorr( pNtk, nFramesP, nConfMax, fVerbose );
22041     if ( pNtkRes == NULL )
22042     {
22043         Abc_Print( -1, "Sequential sweeping has failed.\n" );
22044         return 1;
22045     }
22046     // replace the current network
22047     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
22048     return 0;
22049 
22050 usage:
22051     Abc_Print( -2, "usage: lcorr [-PCS num] [-nvh]\n" );
22052     Abc_Print( -2, "\t         computes latch correspondence using 1-step induction\n" );
22053     Abc_Print( -2, "\t-P num : number of time frames to use as the prefix [default = %d]\n", nFramesP );
22054     Abc_Print( -2, "\t-C num : limit on the number of conflicts [default = %d]\n", nConfMax );
22055     Abc_Print( -2, "\t-S num : the max number of SAT variables [default = %d]\n", nVarsMax );
22056     Abc_Print( -2, "\t-n     : toggle using new algorithm [default = %s]\n", fNewAlgor? "yes": "no" );
22057     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
22058     Abc_Print( -2, "\t-h     : print the command usage\n");
22059     return 1;
22060 }
22061 
22062 /**Function*************************************************************
22063 
22064   Synopsis    []
22065 
22066   Description []
22067 
22068   SideEffects []
22069 
22070   SeeAlso     []
22071 
22072 ***********************************************************************/
Abc_CommandSeqCleanup(Abc_Frame_t * pAbc,int argc,char ** argv)22073 int Abc_CommandSeqCleanup( Abc_Frame_t * pAbc, int argc, char ** argv )
22074 {
22075     Abc_Ntk_t * pNtk, * pNtkRes;
22076     int c;
22077     int fLatchConst  =   1;
22078     int fLatchEqual  =   1;
22079     int fSaveNames   =   1;
22080     int fUseMvSweep  =   0;
22081     int nFramesSymb  =   1;
22082     int nFramesSatur = 512;
22083     int fVerbose     =   0;
22084     int fVeryVerbose =   0;
22085     pNtk = Abc_FrameReadNtk(pAbc);
22086 
22087     // set defaults
22088     Extra_UtilGetoptReset();
22089     while ( ( c = Extra_UtilGetopt( argc, argv, "cenmFSvwh" ) ) != EOF )
22090     {
22091         switch ( c )
22092         {
22093         case 'c':
22094             fLatchConst ^= 1;
22095             break;
22096         case 'e':
22097             fLatchEqual ^= 1;
22098             break;
22099         case 'n':
22100             fSaveNames ^= 1;
22101             break;
22102         case 'm':
22103             fUseMvSweep ^= 1;
22104             break;
22105         case 'F':
22106             if ( globalUtilOptind >= argc )
22107             {
22108                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
22109                 goto usage;
22110             }
22111             nFramesSymb = atoi(argv[globalUtilOptind]);
22112             globalUtilOptind++;
22113             if ( nFramesSymb < 0 )
22114                 goto usage;
22115             break;
22116         case 'S':
22117             if ( globalUtilOptind >= argc )
22118             {
22119                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
22120                 goto usage;
22121             }
22122             nFramesSatur = atoi(argv[globalUtilOptind]);
22123             globalUtilOptind++;
22124             if ( nFramesSatur < 0 )
22125                 goto usage;
22126             break;
22127         case 'v':
22128             fVerbose ^= 1;
22129             break;
22130         case 'w':
22131             fVeryVerbose ^= 1;
22132             break;
22133         case 'h':
22134             goto usage;
22135         default:
22136             goto usage;
22137         }
22138     }
22139     if ( pNtk == NULL )
22140     {
22141         Abc_Print( -1, "Empty network.\n" );
22142         return 1;
22143     }
22144     if ( !Abc_NtkIsStrash(pNtk) )
22145     {
22146         Abc_Print( -1, "Only works for structrally hashed networks.\n" );
22147         return 1;
22148     }
22149     if ( !Abc_NtkLatchNum(pNtk) )
22150     {
22151         Abc_Print( -1, "The network is combinational.\n" );
22152         return 0;
22153     }
22154     // modify the current network
22155     pNtkRes = Abc_NtkDarLatchSweep( pNtk, fLatchConst, fLatchEqual, fSaveNames, fUseMvSweep, nFramesSymb, nFramesSatur, fVerbose, fVeryVerbose );
22156     if ( pNtkRes == NULL )
22157     {
22158         Abc_Print( -1, "Sequential cleanup has failed.\n" );
22159         return 1;
22160     }
22161     // replace the current network
22162     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
22163     return 0;
22164 
22165 usage:
22166     Abc_Print( -2, "usage: scleanup [-cenmFSvwh]\n" );
22167     Abc_Print( -2, "\t         performs sequential cleanup of the current network\n" );
22168     Abc_Print( -2, "\t         by removing nodes and latches that do not feed into POs\n" );
22169     Abc_Print( -2, "\t-c     : sweep stuck-at latches detected by ternary simulation [default = %s]\n", fLatchConst? "yes": "no" );
22170     Abc_Print( -2, "\t-e     : merge equal latches (same data inputs and init states) [default = %s]\n", fLatchEqual? "yes": "no" );
22171     Abc_Print( -2, "\t-n     : toggle preserving latch names [default = %s]\n", fSaveNames? "yes": "no" );
22172     Abc_Print( -2, "\t-m     : toggle using hybrid ternary/symbolic simulation [default = %s]\n", fUseMvSweep? "yes": "no" );
22173     Abc_Print( -2, "\t-F num : the number of first frames simulated symbolically [default = %d]\n", nFramesSymb );
22174     Abc_Print( -2, "\t-S num : the number of frames when symbolic saturation begins [default = %d]\n", nFramesSatur );
22175     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
22176     Abc_Print( -2, "\t-w     : toggle very verbose output [default = %s]\n", fVeryVerbose? "yes": "no" );
22177     Abc_Print( -2, "\t-h     : print the command usage\n");
22178     return 1;
22179 }
22180 
22181 /**Function*************************************************************
22182 
22183   Synopsis    []
22184 
22185   Description []
22186 
22187   SideEffects []
22188 
22189   SeeAlso     []
22190 
22191 ***********************************************************************/
Abc_CommandCycle(Abc_Frame_t * pAbc,int argc,char ** argv)22192 int Abc_CommandCycle( Abc_Frame_t * pAbc, int argc, char ** argv )
22193 {
22194     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
22195     int c;
22196     int nFrames;
22197     int fUseXval;
22198     int fVerbose;
22199     extern void Abc_NtkCycleInitState( Abc_Ntk_t * pNtk, int nFrames, int fUseXval, int fVerbose );
22200     extern void Abc_NtkCycleInitStateSop( Abc_Ntk_t * pNtk, int nFrames, int fVerbose );
22201     // set defaults
22202     nFrames    = 100;
22203     fUseXval   =   0;
22204     fVerbose   =   0;
22205     Extra_UtilGetoptReset();
22206     while ( ( c = Extra_UtilGetopt( argc, argv, "Fxvh" ) ) != EOF )
22207     {
22208         switch ( c )
22209         {
22210         case 'F':
22211             if ( globalUtilOptind >= argc )
22212             {
22213                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
22214                 goto usage;
22215             }
22216             nFrames = atoi(argv[globalUtilOptind]);
22217             globalUtilOptind++;
22218             if ( nFrames < 0 )
22219                 goto usage;
22220             break;
22221         case 'x':
22222             fUseXval ^= 1;
22223             break;
22224         case 'v':
22225             fVerbose ^= 1;
22226             break;
22227         case 'h':
22228             goto usage;
22229         default:
22230             goto usage;
22231         }
22232     }
22233     if ( pNtk == NULL )
22234     {
22235         Abc_Print( -1, "Empty network.\n" );
22236         return 1;
22237     }
22238 
22239     if ( !Abc_NtkIsStrash(pNtk) && !Abc_NtkIsSopLogic(pNtk) )
22240     {
22241         Abc_Print( -1, "Only works for strashed networks or logic SOP networks.\n" );
22242         return 1;
22243     }
22244     if ( !Abc_NtkLatchNum(pNtk) )
22245     {
22246         Abc_Print( -1, "The network is combinational.\n" );
22247         return 0;
22248     }
22249     if ( fUseXval && !Abc_NtkIsStrash(pNtk) )
22250     {
22251         Abc_Print( -1, "X-valued simulation only works for AIGs. Run \"strash\".\n" );
22252         return 0;
22253     }
22254     if ( fUseXval )
22255         Abc_NtkCycleInitState( pNtk, nFrames, 1, fVerbose );
22256     else if ( Abc_NtkIsStrash(pNtk) )
22257         Abc_NtkCycleInitState( pNtk, nFrames, 0, fVerbose );
22258     else
22259         Abc_NtkCycleInitStateSop( pNtk, nFrames, fVerbose );
22260     return 0;
22261 
22262 usage:
22263     Abc_Print( -2, "usage: cycle [-F num] [-xvh]\n" );
22264     Abc_Print( -2, "\t         cycles sequential circuit for the given number of timeframes\n" );
22265     Abc_Print( -2, "\t         to derive a new initial state (which may be on the envelope)\n" );
22266     Abc_Print( -2, "\t-F num : the number of frames to simulate [default = %d]\n", nFrames );
22267     Abc_Print( -2, "\t-x     : use x-valued primary inputs [default = %s]\n", fUseXval? "yes": "no" );
22268     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
22269     Abc_Print( -2, "\t-h     : print the command usage\n");
22270     return 1;
22271 }
22272 
22273 /**Function*************************************************************
22274 
22275   Synopsis    []
22276 
22277   Description []
22278 
22279   SideEffects []
22280 
22281   SeeAlso     []
22282 
22283 ***********************************************************************/
Abc_CommandXsim(Abc_Frame_t * pAbc,int argc,char ** argv)22284 int Abc_CommandXsim( Abc_Frame_t * pAbc, int argc, char ** argv )
22285 {
22286     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
22287     int c;
22288     int nFrames;
22289     int fXInputs;
22290     int fXState;
22291     int fVerbose;
22292     extern void Abc_NtkXValueSimulate( Abc_Ntk_t * pNtk, int nFrames, int fXInputs, int fXState, int fVerbose );
22293     // set defaults
22294     nFrames    = 10;
22295     fXInputs   =  0;
22296     fXState    =  0;
22297     fVerbose   =  0;
22298     Extra_UtilGetoptReset();
22299     while ( ( c = Extra_UtilGetopt( argc, argv, "Fisvh" ) ) != EOF )
22300     {
22301         switch ( c )
22302         {
22303         case 'F':
22304             if ( globalUtilOptind >= argc )
22305             {
22306                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
22307                 goto usage;
22308             }
22309             nFrames = atoi(argv[globalUtilOptind]);
22310             globalUtilOptind++;
22311             if ( nFrames < 0 )
22312                 goto usage;
22313             break;
22314         case 'i':
22315             fXInputs ^= 1;
22316             break;
22317         case 's':
22318             fXState ^= 1;
22319             break;
22320         case 'v':
22321             fVerbose ^= 1;
22322             break;
22323         case 'h':
22324             goto usage;
22325         default:
22326             goto usage;
22327         }
22328     }
22329     if ( pNtk == NULL )
22330     {
22331         Abc_Print( -1, "Empty network.\n" );
22332         return 1;
22333     }
22334 
22335     if ( !Abc_NtkIsStrash(pNtk) )
22336     {
22337         Abc_Print( -1, "Only works for strashed networks.\n" );
22338         return 1;
22339     }
22340     if ( !Abc_NtkLatchNum(pNtk) )
22341     {
22342         Abc_Print( -1, "The network is combinational.\n" );
22343         return 0;
22344     }
22345     Abc_NtkXValueSimulate( pNtk, nFrames, fXInputs, fXState, fVerbose );
22346     return 0;
22347 
22348 usage:
22349     Abc_Print( -2, "usage: xsim [-F num] [-isvh]\n" );
22350     Abc_Print( -2, "\t         performs X-valued simulation of the AIG\n" );
22351     Abc_Print( -2, "\t-F num : the number of frames to simulate [default = %d]\n", nFrames );
22352     Abc_Print( -2, "\t-i     : toggle X-valued representation of inputs [default = %s]\n", fXInputs? "yes": "no" );
22353     Abc_Print( -2, "\t-s     : toggle X-valued representation of state [default = %s]\n", fXState? "yes": "no" );
22354     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
22355     Abc_Print( -2, "\t-h     : print the command usage\n");
22356     return 1;
22357 }
22358 
22359 
22360 /**Function*************************************************************
22361 
22362   Synopsis    []
22363 
22364   Description []
22365 
22366   SideEffects []
22367 
22368   SeeAlso     []
22369 
22370 ***********************************************************************/
Abc_CommandSim(Abc_Frame_t * pAbc,int argc,char ** argv)22371 int Abc_CommandSim( Abc_Frame_t * pAbc, int argc, char ** argv )
22372 {
22373     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
22374     int c;
22375     int fNew;
22376     int fComb;
22377     int nFrames;
22378     int nWords;
22379     int TimeOut;
22380     int fMiter;
22381     int fVerbose;
22382     char * pFileSim;
22383     char * pLogFileName = NULL;
22384     extern int Abc_NtkDarSeqSim( Abc_Ntk_t * pNtk, int nFrames, int nWords, int TimeOut, int fNew, int fMiter, int fVerbose, char * pFileSim );
22385     // set defaults
22386     fNew       =  0;
22387     fComb      =  0;
22388     nFrames    = 32;
22389     nWords     =  8;
22390     TimeOut    = 30;
22391     fMiter     =  1;
22392     fVerbose   =  0;
22393     pFileSim   = NULL;
22394     Extra_UtilGetoptReset();
22395     while ( ( c = Extra_UtilGetopt( argc, argv, "FWTALnmvh" ) ) != EOF )
22396     {
22397         switch ( c )
22398         {
22399         case 'F':
22400             if ( globalUtilOptind >= argc )
22401             {
22402                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
22403                 goto usage;
22404             }
22405             nFrames = atoi(argv[globalUtilOptind]);
22406             globalUtilOptind++;
22407             if ( nFrames < 0 )
22408                 goto usage;
22409             break;
22410         case 'W':
22411             if ( globalUtilOptind >= argc )
22412             {
22413                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
22414                 goto usage;
22415             }
22416             nWords = atoi(argv[globalUtilOptind]);
22417             globalUtilOptind++;
22418             if ( nWords < 0 )
22419                 goto usage;
22420             break;
22421         case 'T':
22422             if ( globalUtilOptind >= argc )
22423             {
22424                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
22425                 goto usage;
22426             }
22427             TimeOut = atoi(argv[globalUtilOptind]);
22428             globalUtilOptind++;
22429             if ( TimeOut < 0 )
22430                 goto usage;
22431             break;
22432         case 'A':
22433             if ( globalUtilOptind >= argc )
22434             {
22435                 Abc_Print( -1, "Command line switch \"-A\" should be followed by a file name.\n" );
22436                 goto usage;
22437             }
22438             pFileSim = argv[globalUtilOptind];
22439             globalUtilOptind++;
22440             break;
22441         case 'L':
22442             if ( globalUtilOptind >= argc )
22443             {
22444                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
22445                 goto usage;
22446             }
22447             pLogFileName = argv[globalUtilOptind];
22448             globalUtilOptind++;
22449             break;
22450         case 'n':
22451             fNew ^= 1;
22452             break;
22453         case 'm':
22454             fMiter ^= 1;
22455             break;
22456         case 'v':
22457             fVerbose ^= 1;
22458             break;
22459         case 'h':
22460             goto usage;
22461         default:
22462             goto usage;
22463         }
22464     }
22465     if ( pNtk == NULL )
22466     {
22467         Abc_Print( -1, "Empty network.\n" );
22468         return 1;
22469     }
22470     if ( !Abc_NtkIsStrash(pNtk) )
22471     {
22472         Abc_Print( -1, "Only works for strashed networks.\n" );
22473         return 1;
22474     }
22475     if ( pFileSim != NULL && Abc_NtkLatchNum(pNtk) )
22476     {
22477         Abc_Print( -1, "Currently simulation with user-specified patterns works only for comb miters.\n" );
22478         return 1;
22479     }
22480     ABC_FREE( pNtk->pSeqModel );
22481     pAbc->Status = Abc_NtkDarSeqSim( pNtk, nFrames, nWords, TimeOut, fNew, fMiter, fVerbose, pFileSim );
22482     Abc_FrameReplaceCex( pAbc, &pNtk->pSeqModel );
22483     if ( pLogFileName )
22484         Abc_NtkWriteLogFile( pLogFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, "sim" );
22485     return 0;
22486 
22487 usage:
22488     Abc_Print( -2, "usage: sim [-FWT num] [-AL file] [-nmvh]\n" );
22489     Abc_Print( -2, "\t          performs random simulation of the sequential miter\n" );
22490     Abc_Print( -2, "\t-F num  : the number of frames to simulate [default = %d]\n", nFrames );
22491     Abc_Print( -2, "\t-W num  : the number of words to simulate [default = %d]\n", nWords );
22492     Abc_Print( -2, "\t-T num  : approximate runtime limit in seconds [default = %d]\n", TimeOut );
22493     Abc_Print( -2, "\t-A file : text file name with user's patterns [default = random simulation]\n" );
22494     Abc_Print( -2, "\t          (patterns are listed, one per line, as sequences of 0s and 1s)\n" );
22495     Abc_Print( -2, "\t-L file : the log file name [default = %s]\n",  pLogFileName ? pLogFileName : "no logging" );
22496     Abc_Print( -2, "\t-n      : toggle new vs. old implementation [default = %s]\n", fNew? "new": "old" );
22497     Abc_Print( -2, "\t-m      : toggle miter vs. any circuit [default = %s]\n", fMiter? "miter": "circuit" );
22498     Abc_Print( -2, "\t-v      : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
22499     Abc_Print( -2, "\t-h      : print the command usage\n");
22500     return 1;
22501 }
22502 
22503 
22504 /**Function*************************************************************
22505 
22506   Synopsis    []
22507 
22508   Description []
22509 
22510   SideEffects []
22511 
22512   SeeAlso     []
22513 
22514 ***********************************************************************/
Abc_CommandSim3(Abc_Frame_t * pAbc,int argc,char ** argv)22515 int Abc_CommandSim3( Abc_Frame_t * pAbc, int argc, char ** argv )
22516 {
22517     extern int Abc_NtkDarSeqSim3( Abc_Ntk_t * pNtk, Ssw_RarPars_t * pPars );
22518     Ssw_RarPars_t Pars, * pPars = &Pars;
22519     Abc_Ntk_t * pNtkRes, * pNtk = Abc_FrameReadNtk(pAbc);
22520     Vec_Ptr_t * vSeqModelVec;
22521     char * pLogFileName = NULL;
22522     int c;
22523     Ssw_RarSetDefaultParams( pPars );
22524     Extra_UtilGetoptReset();
22525     while ( ( c = Extra_UtilGetopt( argc, argv, "FWBRSNTGLadivzh" ) ) != EOF )
22526     {
22527         switch ( c )
22528         {
22529         case 'F':
22530             if ( globalUtilOptind >= argc )
22531             {
22532                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
22533                 goto usage;
22534             }
22535             pPars->nFrames = atoi(argv[globalUtilOptind]);
22536             globalUtilOptind++;
22537             if ( pPars->nFrames < 0 )
22538                 goto usage;
22539             break;
22540         case 'W':
22541             if ( globalUtilOptind >= argc )
22542             {
22543                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
22544                 goto usage;
22545             }
22546             pPars->nWords = atoi(argv[globalUtilOptind]);
22547             globalUtilOptind++;
22548             if ( pPars->nWords < 0 )
22549                 goto usage;
22550             break;
22551         case 'B':
22552             if ( globalUtilOptind >= argc )
22553             {
22554                 Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" );
22555                 goto usage;
22556             }
22557             pPars->nBinSize = atoi(argv[globalUtilOptind]);
22558             globalUtilOptind++;
22559             if ( pPars->nBinSize < 0 )
22560                 goto usage;
22561             break;
22562         case 'R':
22563             if ( globalUtilOptind >= argc )
22564             {
22565                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
22566                 goto usage;
22567             }
22568             pPars->nRounds = atoi(argv[globalUtilOptind]);
22569             globalUtilOptind++;
22570             if ( pPars->nRounds < 0 )
22571                 goto usage;
22572             break;
22573         case 'S':
22574             if ( globalUtilOptind >= argc )
22575             {
22576                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
22577                 goto usage;
22578             }
22579             pPars->nRestart = atoi(argv[globalUtilOptind]);
22580             globalUtilOptind++;
22581             if ( pPars->nRestart < 0 )
22582                 goto usage;
22583             break;
22584         case 'N':
22585             if ( globalUtilOptind >= argc )
22586             {
22587                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
22588                 goto usage;
22589             }
22590             pPars->nRandSeed = atoi(argv[globalUtilOptind]);
22591             globalUtilOptind++;
22592             if ( pPars->nRandSeed < 0 )
22593                 goto usage;
22594             break;
22595         case 'T':
22596             if ( globalUtilOptind >= argc )
22597             {
22598                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
22599                 goto usage;
22600             }
22601             pPars->TimeOut = atoi(argv[globalUtilOptind]);
22602             globalUtilOptind++;
22603             if ( pPars->TimeOut < 0 )
22604                 goto usage;
22605             break;
22606         case 'G':
22607             if ( globalUtilOptind >= argc )
22608             {
22609                 Abc_Print( -1, "Command line switch \"-G\" should be followed by an integer.\n" );
22610                 goto usage;
22611             }
22612             pPars->TimeOutGap = atoi(argv[globalUtilOptind]);
22613             globalUtilOptind++;
22614             if ( pPars->TimeOutGap < 0 )
22615                 goto usage;
22616             break;
22617         case 'L':
22618             if ( globalUtilOptind >= argc )
22619             {
22620                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
22621                 goto usage;
22622             }
22623             pLogFileName = argv[globalUtilOptind];
22624             globalUtilOptind++;
22625             break;
22626         case 'a':
22627             pPars->fSolveAll ^= 1;
22628             break;
22629         case 'd':
22630             pPars->fDropSatOuts ^= 1;
22631             break;
22632         case 'i':
22633             pPars->fSetLastState ^= 1;
22634             break;
22635         case 'v':
22636             pPars->fVerbose ^= 1;
22637             break;
22638         case 'z':
22639             pPars->fNotVerbose ^= 1;
22640             break;
22641         case 'h':
22642             goto usage;
22643         default:
22644             goto usage;
22645         }
22646     }
22647     if ( pNtk == NULL )
22648     {
22649         Abc_Print( -1, "Empty network.\n" );
22650         return 1;
22651     }
22652     if ( !Abc_NtkIsStrash(pNtk) )
22653     {
22654         Abc_Print( -1, "Only works for strashed networks.\n" );
22655         return 1;
22656     }
22657     if ( Abc_NtkLatchNum(pNtk) == 0 )
22658     {
22659         Abc_Print( -1, "Only works for sequential networks.\n" );
22660         return 1;
22661     }
22662     ABC_FREE( pNtk->pSeqModel );
22663     pAbc->Status = Abc_NtkDarSeqSim3( pNtk, pPars );
22664     Abc_FrameReplaceCex( pAbc, &pNtk->pSeqModel );
22665     vSeqModelVec = pNtk->vSeqModelVec;  pNtk->vSeqModelVec = NULL;
22666     if ( pPars->fSetLastState && pAbc->pNtkCur->pData )
22667     {
22668         Abc_Obj_t * pObj;
22669         Vec_Int_t * vInit = (Vec_Int_t *)pAbc->pNtkCur->pData;
22670         pAbc->pNtkCur->pData = NULL;
22671         Abc_NtkForEachLatch( pAbc->pNtkCur, pObj, c )
22672             if ( Vec_IntEntry(vInit, c) )
22673                 Abc_LatchSetInit1( pObj );
22674         Vec_IntFree( vInit );
22675         pNtkRes = Abc_NtkRestrashZero( pAbc->pNtkCur, 0 );
22676         if ( pNtkRes == NULL )
22677         {
22678             Abc_Print( -1, "Removing SAT outputs has failed.\n" );
22679             return 1;
22680         }
22681         Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
22682         pNtk = Abc_FrameReadNtk(pAbc);
22683     }
22684     if ( pPars->fSolveAll && pPars->fDropSatOuts )
22685     {
22686         if ( vSeqModelVec == NULL )
22687             Abc_Print( 1,"The array of counter-examples is not available.\n" );
22688         else if ( Vec_PtrSize(vSeqModelVec) != Abc_NtkPoNum(pNtk) )
22689             Abc_Print( 1,"The array size does not match the number of outputs.\n" );
22690         else
22691         {
22692             extern void Abc_NtkDropSatOutputs( Abc_Ntk_t * pNtk, Vec_Ptr_t * vCexes, int fVerbose );
22693             Abc_NtkDropSatOutputs( pNtk, vSeqModelVec, pPars->fVerbose );
22694             pNtkRes = Abc_NtkDarLatchSweep( pNtk, 1, 1, 1, 0, -1, -1, 0, 0 );
22695             if ( pNtkRes == NULL )
22696             {
22697                 Abc_Print( -1, "Removing SAT outputs has failed.\n" );
22698                 return 1;
22699             }
22700             Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
22701         }
22702     }
22703     if ( vSeqModelVec )
22704     {
22705         Abc_FrameReplaceCexVec( pAbc, &vSeqModelVec );
22706         pAbc->nFrames = -1;
22707     }
22708     if ( pLogFileName )
22709         Abc_NtkWriteLogFile( pLogFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, "sim3" );
22710     return 0;
22711 
22712 usage:
22713     Abc_Print( -2, "usage: sim3 [-FWBRSNTG num] [-L file] [-advzh]\n" );
22714     Abc_Print( -2, "\t         performs random simulation of the sequential miter\n" );
22715     Abc_Print( -2, "\t-F num : the number of frames to simulate [default = %d]\n",                         pPars->nFrames );
22716     Abc_Print( -2, "\t-W num : the number of words to simulate [default = %d]\n",                          pPars->nWords );
22717     Abc_Print( -2, "\t-B num : the number of flops in one bin [default = %d]\n",                           pPars->nBinSize );
22718     Abc_Print( -2, "\t-R num : the number of simulation rounds [default = %d]\n",                          pPars->nRounds );
22719     Abc_Print( -2, "\t-S num : the number of rounds before a restart [default = %d]\n",                    pPars->nRestart );
22720     Abc_Print( -2, "\t-N num : random number seed (1 <= num <= 1000) [default = %d]\n",                    pPars->nRandSeed );
22721     Abc_Print( -2, "\t-T num : approximate runtime limit in seconds [default = %d]\n",                     pPars->TimeOut );
22722     Abc_Print( -2, "\t-G num : approximate runtime gap in seconds since the last CEX [default = %d]\n",    pPars->TimeOutGap );
22723     Abc_Print( -2, "\t-L file: the log file name [default = %s]\n",                                          pLogFileName ? pLogFileName : "no logging" );
22724     Abc_Print( -2, "\t-a     : toggle solving all outputs (do not stop when one is SAT) [default = %s]\n", pPars->fSolveAll?    "yes": "no" );
22725     Abc_Print( -2, "\t-d     : toggle dropping (replacing by 0) SAT outputs [default = %s]\n",             pPars->fDropSatOuts? "yes": "no" );
22726     Abc_Print( -2, "\t-i     : toggle changing init state to a last rare state [default = %s]\n",          pPars->fVerbose?     "yes": "no" );
22727     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",                      pPars->fVerbose?     "yes": "no" );
22728     Abc_Print( -2, "\t-z     : toggle suppressing report about solved outputs [default = %s]\n",           pPars->fNotVerbose?  "yes": "no" );
22729     Abc_Print( -2, "\t-h     : print the command usage\n");
22730     return 1;
22731 }
22732 
22733 /**Function*************************************************************
22734 
22735   Synopsis    []
22736 
22737   Description []
22738 
22739   SideEffects []
22740 
22741   SeeAlso     []
22742 
22743 ***********************************************************************/
Abc_CommandDarPhase(Abc_Frame_t * pAbc,int argc,char ** argv)22744 int Abc_CommandDarPhase( Abc_Frame_t * pAbc, int argc, char ** argv )
22745 {
22746     Abc_Ntk_t * pNtk, * pNtkRes;
22747     int nFrames, nPref;
22748     int fIgnore;
22749     int fPrint;
22750     int fUpdateCex;
22751     int c, fVerbose;
22752     extern Abc_Ntk_t * Abc_NtkPhaseAbstract( Abc_Ntk_t * pNtk, int nFrames, int nPref, int fIgnore, int fPrint, int fVerbose );
22753 
22754     pNtk = Abc_FrameReadNtk(pAbc);
22755     // set defaults
22756     nFrames     = 0;
22757     nPref       = 0;
22758     fIgnore     = 0;
22759     fPrint      = 0;
22760     fUpdateCex  = 0;
22761     fVerbose    = 0;
22762     Extra_UtilGetoptReset();
22763     while ( ( c = Extra_UtilGetopt( argc, argv, "FPipcvh" ) ) != EOF )
22764     {
22765         switch ( c )
22766         {
22767         case 'F':
22768             if ( globalUtilOptind >= argc )
22769             {
22770                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
22771                 goto usage;
22772             }
22773             nFrames = atoi(argv[globalUtilOptind]);
22774             globalUtilOptind++;
22775             if ( nFrames < 0 )
22776                 goto usage;
22777             break;
22778         case 'P':
22779             if ( globalUtilOptind >= argc )
22780             {
22781                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
22782                 goto usage;
22783             }
22784             nPref = atoi(argv[globalUtilOptind]);
22785             globalUtilOptind++;
22786             if ( nPref < 0 )
22787                 goto usage;
22788             break;
22789         case 'i':
22790             fIgnore ^= 1;
22791             break;
22792         case 'p':
22793             fPrint ^= 1;
22794             break;
22795         case 'c':
22796             fUpdateCex ^= 1;
22797             break;
22798         case 'v':
22799             fVerbose ^= 1;
22800             break;
22801         case 'h':
22802             goto usage;
22803         default:
22804             goto usage;
22805         }
22806     }
22807     if ( pNtk == NULL )
22808     {
22809         Abc_Print( -1, "Empty network.\n" );
22810         return 1;
22811     }
22812     if ( !Abc_NtkIsStrash(pNtk) )
22813     {
22814         Abc_Print( -1, "Only works for structrally hashed networks.\n" );
22815         return 1;
22816     }
22817     if ( fUpdateCex )
22818     {
22819         Abc_Cex_t * pCexNew;
22820         if ( pAbc->pCex == NULL )
22821         {
22822             Abc_Print( -1, "Counter-example is not available.\n" );
22823             return 1;
22824         }
22825         if ( pAbc->pCex->nPis % Abc_NtkPiNum(pNtk) != 0 )
22826         {
22827             Abc_Print( -1, "PI count of the CEX is not a multiple of PI count of the current AIG.\n" );
22828             return 1;
22829         }
22830         pCexNew = Abc_CexTransformPhase( pAbc->pCex, Abc_NtkPiNum(pNtk), Abc_NtkPoNum(pNtk), Abc_NtkLatchNum(pNtk) );
22831         {
22832             Aig_Man_t * pAig = Abc_NtkToDar( pNtk, 0, 1 );
22833             Gia_Man_t * pGia = Gia_ManFromAig( pAig );
22834             int iPo = Gia_ManSetFailedPoCex( pGia, pCexNew );
22835             Gia_ManStop( pGia );
22836             Aig_ManStop( pAig );
22837             if ( iPo == -1 )
22838             {
22839                 Abc_Print( -1, "The counter-example does not fail any of the outputs of the original AIG.\n" );
22840                 return 1;
22841             }
22842         }
22843         Abc_FrameReplaceCex( pAbc, &pCexNew );
22844         return 0;
22845     }
22846     if ( !Abc_NtkLatchNum(pNtk) )
22847     {
22848         Abc_Print( -1, "The network is combinational.\n" );
22849         return 0;
22850     }
22851     if ( fPrint )
22852     {
22853         Abc_NtkPhaseAbstract( pNtk, 0, nPref, fIgnore, 1, fVerbose );
22854         return 0;
22855     }
22856     // modify the current network
22857     pNtkRes = Abc_NtkPhaseAbstract( pNtk, nFrames, nPref, fIgnore, 0, fVerbose );
22858     if ( pNtkRes == NULL )
22859     {
22860 //        Abc_Print( -1, "Phase abstraction has failed.\n" );
22861         return 0;
22862     }
22863     // replace the current network
22864     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
22865     return 0;
22866 
22867 usage:
22868     Abc_Print( -2, "usage: phase [-FP <num>] [-ipcvh]\n" );
22869     Abc_Print( -2, "\t         performs sequential cleanup of the current network\n" );
22870     Abc_Print( -2, "\t         by removing nodes and latches that do not feed into POs\n" );
22871     Abc_Print( -2, "\t-F num : the number of frames to abstract [default = %d]\n", nFrames );
22872     Abc_Print( -2, "\t-P num : the number of prefix frames to skip [default = %d]\n", nPref );
22873     Abc_Print( -2, "\t-i     : toggle ignoring the initial state [default = %s]\n", fIgnore? "yes": "no" );
22874     Abc_Print( -2, "\t-p     : toggle printing statistics about generators [default = %s]\n", fPrint? "yes": "no" );
22875     Abc_Print( -2, "\t-c     : update the current CEX derived for a new AIG after \"phase\"\n" );
22876     Abc_Print( -2, "\t         to match the current AIG (the one before \"phase\") [default = %s]\n", fUpdateCex? "yes": "no" );
22877     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
22878     Abc_Print( -2, "\t-h     : print the command usage\n");
22879     return 1;
22880 }
22881 
22882 /**Function*************************************************************
22883 
22884   Synopsis    []
22885 
22886   Description []
22887 
22888   SideEffects []
22889 
22890   SeeAlso     []
22891 
22892 ***********************************************************************/
Abc_CommandSynch(Abc_Frame_t * pAbc,int argc,char ** argv)22893 int Abc_CommandSynch( Abc_Frame_t * pAbc, int argc, char ** argv )
22894 {
22895     Abc_Ntk_t * pNtkRes, * pNtk1, * pNtk2, * pNtk;
22896     char ** pArgvNew;
22897     int nArgcNew;
22898     int fDelete1, fDelete2;
22899     int c;
22900     int nWords;
22901     int fVerbose;
22902 
22903     extern Abc_Ntk_t * Abc_NtkDarSynch( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nWords, int fVerbose );
22904     extern Abc_Ntk_t * Abc_NtkDarSynchOne( Abc_Ntk_t * pNtk, int nWords, int fVerbose );
22905 
22906     pNtk = Abc_FrameReadNtk(pAbc);
22907     // set defaults
22908     nWords   =  32;
22909     fVerbose =   1;
22910     Extra_UtilGetoptReset();
22911     while ( ( c = Extra_UtilGetopt( argc, argv, "Wvh" ) ) != EOF )
22912     {
22913         switch ( c )
22914         {
22915         case 'W':
22916             if ( globalUtilOptind >= argc )
22917             {
22918                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
22919                 goto usage;
22920             }
22921             nWords = atoi(argv[globalUtilOptind]);
22922             globalUtilOptind++;
22923             if ( nWords <= 0 )
22924                 goto usage;
22925             break;
22926         case 'v':
22927             fVerbose ^= 1;
22928             break;
22929         case 'h':
22930             goto usage;
22931         default:
22932             goto usage;
22933         }
22934     }
22935 
22936     pArgvNew = argv + globalUtilOptind;
22937     nArgcNew = argc - globalUtilOptind;
22938     if ( nArgcNew == 0 )
22939     {
22940         if ( pNtk == NULL )
22941         {
22942             Abc_Print( -1, "Empty network.\n" );
22943             return 1;
22944         }
22945         pNtkRes = Abc_NtkDarSynchOne( pNtk, nWords, fVerbose );
22946     }
22947     else
22948     {
22949         if ( !Abc_NtkPrepareTwoNtks( stdout, pNtk, pArgvNew, nArgcNew, &pNtk1, &pNtk2, &fDelete1, &fDelete2, 1 ) )
22950             return 1;
22951         if ( Abc_NtkLatchNum(pNtk1) == 0 || Abc_NtkLatchNum(pNtk2) == 0 )
22952         {
22953             if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
22954             if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
22955             Abc_Print( -1, "The network has no latches..\n" );
22956             return 0;
22957         }
22958 
22959         // modify the current network
22960         pNtkRes = Abc_NtkDarSynch( pNtk1, pNtk2, nWords, fVerbose );
22961         if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
22962         if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
22963     }
22964     if ( pNtkRes == NULL )
22965     {
22966         Abc_Print( -1, "Synchronization has failed.\n" );
22967         return 0;
22968     }
22969     // replace the current network
22970     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
22971     return 0;
22972 
22973 usage:
22974     Abc_Print( -2, "usage: synch [-W <num>] [-vh] <file1> <file2>\n" );
22975     Abc_Print( -2, "\t         derives and applies synchronization sequence\n" );
22976     Abc_Print( -2, "\t-W num : the number of simulation words [default = %d]\n", nWords );
22977     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
22978     Abc_Print( -2, "\t-h     : print the command usage\n");
22979     Abc_Print( -2, "\tfile1  : (optional) the file with the first design\n");
22980     Abc_Print( -2, "\tfile2  : (optional) the file with the second design\n\n");
22981     Abc_Print( -2, "\t         If no designs are given on the command line,\n" );
22982     Abc_Print( -2, "\t         assumes the current network has no initial state,\n" );
22983     Abc_Print( -2, "\t         derives synchronization sequence and applies it.\n\n" );
22984     Abc_Print( -2, "\t         If two designs are given on the command line\n" );
22985     Abc_Print( -2, "\t         assumes both of them have no initial state,\n" );
22986     Abc_Print( -2, "\t         derives sequences for both designs, synchorinizes\n" );
22987     Abc_Print( -2, "\t         them, and creates SEC miter comparing two designs.\n\n" );
22988     Abc_Print( -2, "\t         If only one design is given on the command line,\n" );
22989     Abc_Print( -2, "\t         considers the second design to be the current network,\n" );
22990     Abc_Print( -2, "\t         and derives SEC miter for them, as described above.\n" );
22991     return 1;
22992 }
22993 
22994 /**Function*************************************************************
22995 
22996   Synopsis    []
22997 
22998   Description []
22999 
23000   SideEffects []
23001 
23002   SeeAlso     []
23003 
23004 ***********************************************************************/
Abc_CommandClockGate(Abc_Frame_t * pAbc,int argc,char ** argv)23005 int Abc_CommandClockGate( Abc_Frame_t * pAbc, int argc, char ** argv )
23006 {
23007     Cgt_Par_t Pars, * pPars = &Pars;
23008     Abc_Ntk_t * pNtkRes, * pNtk, * pNtkCare;
23009     int c;
23010 
23011     extern Abc_Ntk_t * Abc_NtkDarClockGate( Abc_Ntk_t * pNtk, Abc_Ntk_t * pCare, Cgt_Par_t * pPars );
23012 
23013     pNtk = Abc_FrameReadNtk(pAbc);
23014     // set defaults
23015     Cgt_SetDefaultParams( pPars );
23016     Extra_UtilGetoptReset();
23017     while ( ( c = Extra_UtilGetopt( argc, argv, "LNDCVKavwh" ) ) != EOF )
23018     {
23019         switch ( c )
23020         {
23021         case 'L':
23022             if ( globalUtilOptind >= argc )
23023             {
23024                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
23025                 goto usage;
23026             }
23027             pPars->nLevelMax = atoi(argv[globalUtilOptind]);
23028             globalUtilOptind++;
23029             if ( pPars->nLevelMax <= 0 )
23030                 goto usage;
23031             break;
23032         case 'N':
23033             if ( globalUtilOptind >= argc )
23034             {
23035                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
23036                 goto usage;
23037             }
23038             pPars->nCandMax = atoi(argv[globalUtilOptind]);
23039             globalUtilOptind++;
23040             if ( pPars->nCandMax <= 0 )
23041                 goto usage;
23042             break;
23043         case 'D':
23044             if ( globalUtilOptind >= argc )
23045             {
23046                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
23047                 goto usage;
23048             }
23049             pPars->nOdcMax = atoi(argv[globalUtilOptind]);
23050             globalUtilOptind++;
23051             if ( pPars->nOdcMax <= 0 )
23052                 goto usage;
23053             break;
23054         case 'C':
23055             if ( globalUtilOptind >= argc )
23056             {
23057                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
23058                 goto usage;
23059             }
23060             pPars->nConfMax = atoi(argv[globalUtilOptind]);
23061             globalUtilOptind++;
23062             if ( pPars->nConfMax <= 0 )
23063                 goto usage;
23064             break;
23065         case 'V':
23066             if ( globalUtilOptind >= argc )
23067             {
23068                 Abc_Print( -1, "Command line switch \"-V\" should be followed by an integer.\n" );
23069                 goto usage;
23070             }
23071             pPars->nVarsMin = atoi(argv[globalUtilOptind]);
23072             globalUtilOptind++;
23073             if ( pPars->nVarsMin <= 0 )
23074                 goto usage;
23075             break;
23076         case 'K':
23077             if ( globalUtilOptind >= argc )
23078             {
23079                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
23080                 goto usage;
23081             }
23082             pPars->nFlopsMin = atoi(argv[globalUtilOptind]);
23083             globalUtilOptind++;
23084             if ( pPars->nFlopsMin <= 0 )
23085                 goto usage;
23086             break;
23087         case 'a':
23088             pPars->fAreaOnly ^= 1;
23089             break;
23090         case 'v':
23091             pPars->fVerbose ^= 1;
23092             break;
23093         case 'w':
23094             pPars->fVeryVerbose ^= 1;
23095             break;
23096         case 'h':
23097             goto usage;
23098         default:
23099             goto usage;
23100         }
23101     }
23102     if ( pNtk == NULL )
23103     {
23104         Abc_Print( -1, "Empty network.\n" );
23105         return 1;
23106     }
23107 
23108     if ( argc == globalUtilOptind + 1 )
23109     {
23110         pNtkCare = Io_Read( argv[globalUtilOptind], Io_ReadFileType(argv[globalUtilOptind]), 1, 0 );
23111         if ( pNtkCare == NULL )
23112         {
23113             Abc_Print( -1, "Reading care network has failed.\n" );
23114             return 1;
23115         }
23116         // modify the current network
23117         pNtkRes = Abc_NtkDarClockGate( pNtk, pNtkCare, pPars );
23118         Abc_NtkDelete( pNtkCare );
23119     }
23120     else if ( argc == globalUtilOptind )
23121     {
23122         pNtkRes = Abc_NtkDarClockGate( pNtk, NULL, pPars );
23123     }
23124     else
23125     {
23126         Abc_Print( -1, "Wrong number of arguments.\n" );
23127         return 0;
23128     }
23129     if ( pNtkRes == NULL )
23130     {
23131         Abc_Print( -1, "Clock gating has failed.\n" );
23132         return 0;
23133     }
23134     // replace the current network
23135     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
23136     return 0;
23137 
23138 usage:
23139     Abc_Print( -2, "usage: clockgate [-LNDCVK <num>] [-avwh] <file>\n" );
23140     Abc_Print( -2, "\t         sequential clock gating with observability don't-cares\n" );
23141     Abc_Print( -2, "\t-L num : max level number of a clock gate [default = %d]\n", pPars->nLevelMax );
23142     Abc_Print( -2, "\t-N num : max number of candidates for a flop [default = %d]\n", pPars->nCandMax );
23143     Abc_Print( -2, "\t-D num : max number of ODC levels to consider [default = %d]\n", pPars->nOdcMax );
23144     Abc_Print( -2, "\t-C num : max number of conflicts at a node [default = %d]\n", pPars->nConfMax );
23145     Abc_Print( -2, "\t-V num : min number of vars to recycle SAT solver [default = %d]\n", pPars->nVarsMin );
23146     Abc_Print( -2, "\t-K num : min number of flops to recycle SAT solver [default = %d]\n", pPars->nFlopsMin );
23147     Abc_Print( -2, "\t-a     : toggle minimizing area-only [default = %s]\n", pPars->fAreaOnly? "yes": "no" );
23148     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
23149     Abc_Print( -2, "\t-w     : toggle even more detailed output [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
23150     Abc_Print( -2, "\t-h     : print the command usage\n");
23151     Abc_Print( -2, "\tfile   : (optional) constraints for primary inputs and register outputs\n");
23152     return 1;
23153 }
23154 
23155 /**Function*************************************************************
23156 
23157   Synopsis    []
23158 
23159   Description []
23160 
23161   SideEffects []
23162 
23163   SeeAlso     []
23164 
23165 ***********************************************************************/
Abc_CommandExtWin(Abc_Frame_t * pAbc,int argc,char ** argv)23166 int Abc_CommandExtWin( Abc_Frame_t * pAbc, int argc, char ** argv )
23167 {
23168     Abc_Ntk_t * pNtkRes, * pNtk;
23169     int c;
23170     int nObjId;
23171     int nDist;
23172     int fVerbose;
23173 
23174     extern Abc_Ntk_t * Abc_NtkDarExtWin( Abc_Ntk_t * pNtk, int nObjId, int nDist, int fVerbose );
23175 
23176     pNtk = Abc_FrameReadNtk(pAbc);
23177     // set defaults
23178     nObjId   = -1;
23179     nDist    =  5;
23180     fVerbose =  0;
23181     Extra_UtilGetoptReset();
23182     while ( ( c = Extra_UtilGetopt( argc, argv, "NDvh" ) ) != EOF )
23183     {
23184         switch ( c )
23185         {
23186         case 'N':
23187             if ( globalUtilOptind >= argc )
23188             {
23189                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
23190                 goto usage;
23191             }
23192             nObjId = atoi(argv[globalUtilOptind]);
23193             globalUtilOptind++;
23194             if ( nObjId <= 0 )
23195                 goto usage;
23196             break;
23197         case 'D':
23198             if ( globalUtilOptind >= argc )
23199             {
23200                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
23201                 goto usage;
23202             }
23203             nDist = atoi(argv[globalUtilOptind]);
23204             globalUtilOptind++;
23205             if ( nDist <= 0 )
23206                 goto usage;
23207             break;
23208         case 'v':
23209             fVerbose ^= 1;
23210             break;
23211         case 'h':
23212             goto usage;
23213         default:
23214             goto usage;
23215         }
23216     }
23217     if ( pNtk == NULL )
23218     {
23219         Abc_Print( -1, "Empty network.\n" );
23220         return 1;
23221     }
23222     if ( !Abc_NtkIsStrash(pNtk) )
23223     {
23224         Abc_Print( -1, "Only works for structrally hashed networks.\n" );
23225         return 1;
23226     }
23227 
23228     if ( argc != globalUtilOptind )
23229     {
23230         Abc_Print( -1, "Not enough command-line arguments.\n" );
23231         return 1;
23232     }
23233     // modify the current network
23234     pNtkRes = Abc_NtkDarExtWin( pNtk, nObjId, nDist, fVerbose );
23235     if ( pNtkRes == NULL )
23236     {
23237         Abc_Print( -1, "Extracting sequential window has failed.\n" );
23238         return 0;
23239     }
23240     // replace the current network
23241     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
23242     return 0;
23243 
23244 usage:
23245     Abc_Print( -2, "usage: extwin [-ND <num>] [-vh]\n" );
23246     Abc_Print( -2, "\t         extracts sequential window from the AIG\n" );
23247     Abc_Print( -2, "\t-N num : the ID of the object to use as the center [default = %d]\n", nObjId );
23248     Abc_Print( -2, "\t-D num : the \"radius\" of the window [default = %d]\n", nDist );
23249     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
23250     Abc_Print( -2, "\t-h     : print the command usage\n");
23251     return 1;
23252 }
23253 
23254 /**Function*************************************************************
23255 
23256   Synopsis    []
23257 
23258   Description []
23259 
23260   SideEffects []
23261 
23262   SeeAlso     []
23263 
23264 ***********************************************************************/
Abc_CommandInsWin(Abc_Frame_t * pAbc,int argc,char ** argv)23265 int Abc_CommandInsWin( Abc_Frame_t * pAbc, int argc, char ** argv )
23266 {
23267     Abc_Ntk_t * pNtkRes, * pNtk, * pNtkCare;
23268     int c;
23269     int nObjId;
23270     int nDist;
23271     int fVerbose;
23272 
23273     extern Abc_Ntk_t * Abc_NtkDarInsWin( Abc_Ntk_t * pNtk, Abc_Ntk_t * pWnd, int nObjId, int nDist, int fVerbose );
23274 
23275     pNtk = Abc_FrameReadNtk(pAbc);
23276     // set defaults
23277     nObjId   = -1;
23278     nDist    =  5;
23279     fVerbose =  0;
23280     Extra_UtilGetoptReset();
23281     while ( ( c = Extra_UtilGetopt( argc, argv, "NDvh" ) ) != EOF )
23282     {
23283         switch ( c )
23284         {
23285         case 'N':
23286             if ( globalUtilOptind >= argc )
23287             {
23288                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
23289                 goto usage;
23290             }
23291             nObjId = atoi(argv[globalUtilOptind]);
23292             globalUtilOptind++;
23293             if ( nObjId <= 0 )
23294                 goto usage;
23295             break;
23296         case 'D':
23297             if ( globalUtilOptind >= argc )
23298             {
23299                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
23300                 goto usage;
23301             }
23302             nDist = atoi(argv[globalUtilOptind]);
23303             globalUtilOptind++;
23304             if ( nDist <= 0 )
23305                 goto usage;
23306             break;
23307         case 'v':
23308             fVerbose ^= 1;
23309             break;
23310         case 'h':
23311             goto usage;
23312         default:
23313             goto usage;
23314         }
23315     }
23316     if ( pNtk == NULL )
23317     {
23318         Abc_Print( -1, "Empty network.\n" );
23319         return 1;
23320     }
23321     if ( !Abc_NtkIsStrash(pNtk) )
23322     {
23323         Abc_Print( -1, "Only works for structrally hashed networks.\n" );
23324         return 1;
23325     }
23326 
23327     if ( argc != globalUtilOptind + 1 )
23328     {
23329         Abc_Print( -1, "Not enough command-line arguments.\n" );
23330         return 1;
23331     }
23332     pNtkCare = Io_Read( argv[globalUtilOptind], Io_ReadFileType(argv[globalUtilOptind]), 1, 0 );
23333     if ( pNtkCare == NULL )
23334     {
23335         Abc_Print( -1, "Reading care network has failed.\n" );
23336         return 1;
23337     }
23338     if ( !Abc_NtkIsStrash(pNtkCare) )
23339     {
23340         Abc_Ntk_t * pNtkTemp;
23341         pNtkCare = Abc_NtkStrash( pNtkTemp = pNtkCare, 0, 1, 0 );
23342         Abc_NtkDelete( pNtkTemp );
23343     }
23344     // modify the current network
23345     pNtkRes = Abc_NtkDarInsWin( pNtk, pNtkCare, nObjId, nDist, fVerbose );
23346     Abc_NtkDelete( pNtkCare );
23347     if ( pNtkRes == NULL )
23348     {
23349         Abc_Print( -1, "Inserting sequential window has failed.\n" );
23350         return 0;
23351     }
23352     // replace the current network
23353     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
23354     return 0;
23355 
23356 usage:
23357     Abc_Print( -2, "usage: inswin [-ND <num>] [-vh] <file>\n" );
23358     Abc_Print( -2, "\t         inserts sequential window into the AIG\n" );
23359     Abc_Print( -2, "\t-N num : the ID of the object to use as the center [default = %d]\n", nObjId );
23360     Abc_Print( -2, "\t-D num : the \"radius\" of the window [default = %d]\n", nDist );
23361     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
23362     Abc_Print( -2, "\t-h     : print the command usage\n");
23363     Abc_Print( -2, "\tfile   : file with the AIG to be inserted\n");
23364     return 1;
23365 }
23366 
23367 
23368 /**Function*************************************************************
23369 
23370   Synopsis    []
23371 
23372   Description []
23373 
23374   SideEffects []
23375 
23376   SeeAlso     []
23377 
23378 ***********************************************************************/
Abc_CommandSymFun(Abc_Frame_t * pAbc,int argc,char ** argv)23379 int Abc_CommandSymFun( Abc_Frame_t * pAbc, int argc, char ** argv )
23380 {
23381     extern void Ntk_SymFunGenerate( int nVars, int fVerbose );
23382     word * pFun = NULL;
23383     char * pStr,  * pTruth, * pCommand;
23384     int c, k, nVars = -1, fVerbose = 0;
23385     Extra_UtilGetoptReset();
23386     while ( ( c = Extra_UtilGetopt( argc, argv, "Nvh" ) ) != EOF )
23387     {
23388         switch ( c )
23389         {
23390         case 'N':
23391             if ( globalUtilOptind >= argc )
23392             {
23393                 Abc_Print( -1, "Command line switch \"-N\" should be followed by a file name.\n" );
23394                 goto usage;
23395             }
23396             nVars = atoi(argv[globalUtilOptind]);
23397             globalUtilOptind++;
23398             break;
23399         case 'v':
23400             fVerbose ^= 1;
23401             break;
23402         case 'h':
23403             goto usage;
23404         default:
23405             Abc_Print( -2, "Unknown switch.\n");
23406             goto usage;
23407         }
23408     }
23409     if ( nVars != -1 )
23410     {
23411         if ( nVars < 1 || nVars > 16 )
23412         {
23413             printf( "Cannot generate functions for less than 1 and more than %d variables.\n", nVars );
23414             return 1;
23415         }
23416         Ntk_SymFunGenerate( nVars, fVerbose );
23417         return 0;
23418     }
23419     if ( argc != globalUtilOptind + 1 )
23420     {
23421         Abc_Print( -1, "Not enough command-line arguments.\n" );
23422         return 1;
23423     }
23424     // make sure the string is composed of N+1 zeros and ones
23425     pStr = argv[globalUtilOptind];
23426     nVars = strlen(pStr) - 1;
23427     for ( k = 0; k <= nVars; k++ )
23428         if ( pStr[k] != '0' && pStr[k] != '1' )
23429             break;
23430     if ( k <= nVars )
23431     {
23432         Abc_Print( -1, "The string should be composed of zeros and ones.\n" );
23433         return 1;
23434     }
23435     // generate and print one function
23436     pFun = Abc_TtSymFunGenerate( pStr, nVars );
23437     pTruth = ABC_CALLOC( char, nVars > 2 ? (1 << (nVars-2)) + 1 : 2 );
23438     Extra_PrintHexadecimalString( pTruth, (unsigned *)pFun, nVars );
23439     ABC_FREE( pFun );
23440     if ( fVerbose )
23441     {
23442         if ( nVars > 6 )
23443             printf( "Generated truth table of the %d-variable function and set it as the current network.\n", nVars );
23444         else
23445             printf( "Generated truth table of the %d-variable function (%s) and set it as the current network\n", nVars, pTruth );
23446     }
23447     else if ( nVars <= 8 )
23448         printf( "%s\n", pTruth );
23449     // read the truth table to be the current network in ABC
23450     pCommand = ABC_CALLOC( char, strlen(pTruth) + 100 );
23451     sprintf( pCommand, "read_truth %s", pTruth );
23452     Cmd_CommandExecute( pAbc, pCommand );
23453     ABC_FREE( pCommand );
23454     ABC_FREE( pTruth );
23455     return 0;
23456 
23457 usage:
23458     Abc_Print( -2, "usage: symfun [-N num] [-vh] <ones>\n" );
23459     Abc_Print( -2, "\t           generated a single-output symmetric function\n" );
23460     Abc_Print( -2, "\t-N <num> : prints truth tables of all N-var symmetric functions [default = not used]\n" );
23461     Abc_Print( -2, "\t-v       : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
23462     Abc_Print( -2, "\t-h       : print the command usage\n");
23463     Abc_Print( -2, "\t<ones>   : the string of N+1 zeros and ones, where N is the number of variables\n" );
23464     Abc_Print( -2, "\t           For example, to get 3-input NAND-gate, use \"symfun 1000\".\n" );
23465     Abc_Print( -2, "\t           To get 5-input majority gate, use \"symfun 000111\".\n" );
23466 
23467     return 1;
23468 }
23469 /**Function*************************************************************
23470 
23471   Synopsis    []
23472 
23473   Description []
23474 
23475   SideEffects []
23476 
23477   SeeAlso     []
23478 
23479 ***********************************************************************/
Abc_CommandPermute(Abc_Frame_t * pAbc,int argc,char ** argv)23480 int Abc_CommandPermute( Abc_Frame_t * pAbc, int argc, char ** argv )
23481 {
23482     extern Abc_Ntk_t * Abc_NtkRestrashRandom( Abc_Ntk_t * pNtk );
23483     extern void Abc_NtkPermutePiUsingFanout( Abc_Ntk_t * pNtk );
23484     Abc_Ntk_t * pNtk = pAbc->pNtkCur, * pNtkRes = NULL;
23485     char * pFlopPermFile = NULL;
23486     int fInputs = 1;
23487     int fOutputs = 1;
23488     int fFlops = 1;
23489     int fNodes = 1;
23490     int fFanout = 0;
23491     int c;
23492     Extra_UtilGetoptReset();
23493     while ( ( c = Extra_UtilGetopt( argc, argv, "Fiofnxh" ) ) != EOF )
23494     {
23495         switch ( c )
23496         {
23497         case 'F':
23498             if ( globalUtilOptind >= argc )
23499             {
23500                 Abc_Print( -1, "Command line switch \"-F\" should be followed by a file name.\n" );
23501                 goto usage;
23502             }
23503             pFlopPermFile = argv[globalUtilOptind];
23504             globalUtilOptind++;
23505             break;
23506         case 'i':
23507             fInputs ^= 1;
23508             break;
23509         case 'o':
23510             fOutputs ^= 1;
23511             break;
23512         case 'f':
23513             fFlops ^= 1;
23514             break;
23515         case 'n':
23516             fNodes ^= 1;
23517             break;
23518         case 'x':
23519             fFanout ^= 1;
23520             break;
23521         case 'h':
23522             goto usage;
23523         default:
23524             Abc_Print( -2, "Unknown switch.\n");
23525             goto usage;
23526         }
23527     }
23528     if ( pNtk == NULL )
23529     {
23530         Abc_Print( -1, "Empty network.\n" );
23531         return 1;
23532     }
23533     if ( fFanout )
23534     {
23535         if ( Abc_NtkLatchNum(pNtk) )
23536         {
23537             Abc_Print( -1, "Currently \"permute -x\" works only for combinational networks.\n" );
23538             return 1;
23539         }
23540         Abc_NtkPermutePiUsingFanout( pNtk );
23541         return 0;
23542     }
23543     if ( fNodes && !Abc_NtkIsStrash(pNtk) )
23544     {
23545         Abc_Print( -1, "To permute nodes, the network should be structurally hashed.\n" );
23546         return 1;
23547     }
23548     if ( fNodes )
23549         pNtkRes = Abc_NtkRestrashRandom( pNtk );
23550     else
23551         pNtkRes = Abc_NtkDup( pNtk );
23552     if ( pNtkRes == NULL )
23553     {
23554         Abc_Print( -1, "Command \"permute\" has failed.\n" );
23555         return 1;
23556     }
23557     Abc_NtkPermute( pNtkRes, fInputs, fOutputs, fFlops, pFlopPermFile );
23558     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
23559     return 0;
23560 
23561 usage:
23562     Abc_Print( -2, "usage: permute [-iofnxh] [-F filename]\n" );
23563     Abc_Print( -2, "\t                performs random permutation of inputs/outputs/flops\n" );
23564     Abc_Print( -2, "\t-i            : toggle permuting primary inputs [default = %s]\n", fInputs? "yes": "no" );
23565     Abc_Print( -2, "\t-o            : toggle permuting primary outputs [default = %s]\n", fOutputs? "yes": "no" );
23566     Abc_Print( -2, "\t-f            : toggle permuting flip-flops [default = %s]\n", fFlops? "yes": "no" );
23567     Abc_Print( -2, "\t-n            : toggle deriving new topological ordering of nodes [default = %s]\n", fNodes? "yes": "no" );
23568     Abc_Print( -2, "\t-x            : toggle permuting inputs based on their fanout count [default = %s]\n", fFanout? "yes": "no" );
23569     Abc_Print( -2, "\t-h            : print the command usage\n");
23570     Abc_Print( -2, "\t-F <filename> : (optional) file with the flop permutation\n" );
23571     return 1;
23572 }
23573 
23574 /**Function*************************************************************
23575 
23576   Synopsis    []
23577 
23578   Description []
23579 
23580   SideEffects []
23581 
23582   SeeAlso     []
23583 
23584 ***********************************************************************/
Abc_CommandUnpermute(Abc_Frame_t * pAbc,int argc,char ** argv)23585 int Abc_CommandUnpermute( Abc_Frame_t * pAbc, int argc, char ** argv )
23586 {
23587     Abc_Ntk_t * pNtk = pAbc->pNtkCur, * pNtkRes = NULL;
23588     int c;
23589     Extra_UtilGetoptReset();
23590     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
23591     {
23592         switch ( c )
23593         {
23594         case 'h':
23595             goto usage;
23596         default:
23597             Abc_Print( -2, "Unknown switch.\n");
23598             goto usage;
23599         }
23600     }
23601     if ( pNtk == NULL )
23602     {
23603         Abc_Print( -1, "Empty network.\n" );
23604         return 1;
23605     }
23606     pNtkRes = Abc_NtkDup( pNtk );
23607     if ( pNtkRes == NULL )
23608     {
23609         Abc_Print( -1, "Command \"unpermute\" has failed.\n" );
23610         return 1;
23611     }
23612     Abc_NtkUnpermute( pNtkRes );
23613     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
23614     return 0;
23615 
23616 usage:
23617     Abc_Print( -2, "usage: unpermute [-h]\n" );
23618     Abc_Print( -2, "\t        restores inputs/outputs/flops before the last permutation\n" );
23619     Abc_Print( -2, "\t-h    : print the command usage\n");
23620     return 1;
23621 }
23622 
23623 /**Function*************************************************************
23624 
23625   Synopsis    []
23626 
23627   Description []
23628 
23629   SideEffects []
23630 
23631   SeeAlso     []
23632 
23633 ***********************************************************************/
Abc_CommandCubeEnum(Abc_Frame_t * pAbc,int argc,char ** argv)23634 int Abc_CommandCubeEnum( Abc_Frame_t * pAbc, int argc, char ** argv )
23635 {
23636     extern void Abc_EnumerateCubeStates();
23637     extern void Abc_EnumerateCubeStatesZdd();
23638     int c, fZddAlgo = 0, fVerbose = 0;
23639     Extra_UtilGetoptReset();
23640     while ( ( c = Extra_UtilGetopt( argc, argv, "zvh" ) ) != EOF )
23641     {
23642         switch ( c )
23643         {
23644         case 'z':
23645             fZddAlgo ^= 1;
23646             break;
23647         case 'v':
23648             fVerbose ^= 1;
23649             break;
23650         case 'h':
23651             goto usage;
23652         default:
23653             Abc_Print( -2, "Unknown switch.\n");
23654             goto usage;
23655         }
23656     }
23657     if ( fZddAlgo )
23658         Abc_EnumerateCubeStatesZdd();
23659     else
23660         Abc_EnumerateCubeStates();
23661     return 0;
23662 
23663 usage:
23664     Abc_Print( -2, "usage: cubeenum [-vh]\n" );
23665     Abc_Print( -2, "\t         enumerates reachable states of 2x2x2 cube\n" );
23666     Abc_Print( -2, "\t         (http://en.wikipedia.org/wiki/Pocket_Cube)\n" );
23667     Abc_Print( -2, "\t-z     : toggle using ZDD-based algorithm [default = %s]\n", fZddAlgo? "yes": "no" );
23668     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
23669     Abc_Print( -2, "\t-h     : print the command usage\n");
23670     return 1;
23671 }
23672 
23673 /**Function*************************************************************
23674 
23675   Synopsis    []
23676 
23677   Description []
23678 
23679   SideEffects []
23680 
23681   SeeAlso     []
23682 
23683 ***********************************************************************/
Abc_CommandPathEnum(Abc_Frame_t * pAbc,int argc,char ** argv)23684 int Abc_CommandPathEnum( Abc_Frame_t * pAbc, int argc, char ** argv )
23685 {
23686     extern void Abc_EnumerateFrontierTest( int nSize );
23687     int c, nSize = 4, fZddAlgo = 0, fVerbose = 0;
23688     Extra_UtilGetoptReset();
23689     while ( ( c = Extra_UtilGetopt( argc, argv, "Nzvh" ) ) != EOF )
23690     {
23691         switch ( c )
23692         {
23693         case 'N':
23694             if ( globalUtilOptind >= argc )
23695             {
23696                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
23697                 goto usage;
23698             }
23699             nSize = atoi(argv[globalUtilOptind]);
23700             globalUtilOptind++;
23701             if ( nSize < 0 )
23702                 goto usage;
23703             break;
23704         case 'z':
23705             fZddAlgo ^= 1;
23706             break;
23707         case 'v':
23708             fVerbose ^= 1;
23709             break;
23710         case 'h':
23711             goto usage;
23712         default:
23713             Abc_Print( -2, "Unknown switch.\n");
23714             goto usage;
23715         }
23716     }
23717     Abc_EnumerateFrontierTest( nSize );
23718     return 0;
23719 
23720 usage:
23721     Abc_Print( -2, "usage: pathenum [-N num] [-vh]\n" );
23722     Abc_Print( -2, "\t         enumerates self-avoiding paths on the NxN grid\n" );
23723     Abc_Print( -2, "\t-N num : the size of the grid to consider [default = %d]\n", nSize );
23724 //    Abc_Print( -2, "\t-z     : toggle using ZDD-based algorithm [default = %s]\n", fZddAlgo? "yes": "no" );
23725     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
23726     Abc_Print( -2, "\t-h     : print the command usage\n");
23727     return 1;
23728 }
23729 
23730 /**Function*************************************************************
23731 
23732   Synopsis    []
23733 
23734   Description []
23735 
23736   SideEffects []
23737 
23738   SeeAlso     []
23739 
23740 ***********************************************************************/
Abc_CommandFunEnum(Abc_Frame_t * pAbc,int argc,char ** argv)23741 int Abc_CommandFunEnum( Abc_Frame_t * pAbc, int argc, char ** argv )
23742 {
23743     extern void Dtt_EnumerateLf( int nVars, int nNodeMax, int fDelay, int fMulti, int fVerbose, char* pFileName );
23744     extern void Dau_FunctionEnum( int nInputs, int nVars, int nNodeMax, int fUseTwo, int fReduce, int fVerbose );
23745     extern Gia_Man_t * Dau_ConstructAigFromFile( char * pFileName );
23746     int c, nInputs = 4, nVars = 4, nNodeMax = 32, fUseTwo = 0, fReduce = 0, fSimple = 0, fDelay = 0, fMulti = 0, fDump = 0, fVerbose = 0;
23747     Extra_UtilGetoptReset();
23748     while ( ( c = Extra_UtilGetopt( argc, argv, "SIMtrldmpvh" ) ) != EOF )
23749     {
23750         switch ( c )
23751         {
23752         case 'S':
23753             if ( globalUtilOptind >= argc )
23754             {
23755                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
23756                 goto usage;
23757             }
23758             nInputs = atoi(argv[globalUtilOptind]);
23759             globalUtilOptind++;
23760             if ( nInputs < 0 )
23761                 goto usage;
23762             break;
23763         case 'I':
23764             if ( globalUtilOptind >= argc )
23765             {
23766                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
23767                 goto usage;
23768             }
23769             nVars = atoi(argv[globalUtilOptind]);
23770             globalUtilOptind++;
23771             if ( nVars < 0 )
23772                 goto usage;
23773             break;
23774         case 'M':
23775             if ( globalUtilOptind >= argc )
23776             {
23777                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
23778                 goto usage;
23779             }
23780             nNodeMax = atoi(argv[globalUtilOptind]);
23781             globalUtilOptind++;
23782             if ( nNodeMax < 0 )
23783                 goto usage;
23784             break;
23785         case 't':
23786             fUseTwo ^= 1;
23787             break;
23788         case 'r':
23789             fReduce ^= 1;
23790             break;
23791         case 'l':
23792             fSimple ^= 1;
23793             break;
23794         case 'd':
23795             fDelay ^= 1;
23796             break;
23797         case 'm':
23798             fMulti ^= 1;
23799             break;
23800         case 'p':
23801             fDump ^= 1;
23802             break;
23803         case 'v':
23804             fVerbose ^= 1;
23805             break;
23806         case 'h':
23807             goto usage;
23808         default:
23809             Abc_Print( -2, "Unknown switch.\n");
23810             goto usage;
23811         }
23812     }
23813     if ( fSimple || fDelay )
23814     {
23815         char Buffer[100];
23816         if ( nVars < 3 || nVars > 5 )
23817         {
23818             Abc_Print( -1, "The number of inputs should be 3 <= I <= 5.\n" );
23819             goto usage;
23820         }
23821         sprintf( Buffer, "Lflib%d.txt", nVars );
23822         Dtt_EnumerateLf( nVars, nNodeMax, fDelay, fMulti, fVerbose, fDump?Buffer:NULL );
23823         if ( fDump )
23824         {
23825             Gia_Man_t * pTemp;
23826             pTemp = Dau_ConstructAigFromFile( Buffer );
23827             Abc_FrameUpdateGia( pAbc, pTemp );
23828             Gia_DumpAiger( pTemp, "Lflib", nVars, 1 );
23829         }
23830     }
23831     else
23832     {
23833         if ( nVars < 2 || nVars > 6 )
23834         {
23835             Abc_Print( -1, "The number of inputs should be 2 <= I <= 6.\n" );
23836             goto usage;
23837         }
23838         if ( nInputs < nVars || nInputs > 6 )
23839         {
23840             Abc_Print( -1, "The intermediate support size should be I <= S <= 6.\n" );
23841             goto usage;
23842         }
23843         Dau_FunctionEnum( nInputs, nVars, nNodeMax, fUseTwo, fReduce, fVerbose );
23844     }
23845     return 0;
23846 
23847 usage:
23848     Abc_Print( -2, "usage: funenum [-SIM num] [-trldmvph]\n" );
23849     Abc_Print( -2, "\t         enumerates minimum 2-input-gate implementations\n" );
23850     Abc_Print( -2, "\t-S num : the maximum intermediate support size [default = %d]\n",     nInputs );
23851     Abc_Print( -2, "\t-I num : the number of inputs of Boolean functions [default = %d]\n", nVars );
23852     Abc_Print( -2, "\t-M num : the maximum number of 2-input gates [default = %d]\n",       nNodeMax );
23853     Abc_Print( -2, "\t-t     : toggle adding combination of two gates [default = %s]\n",    fUseTwo?  "yes": "no" );
23854     Abc_Print( -2, "\t-r     : toggle reducing the last level [default = %s]\n",            fReduce?  "yes": "no" );
23855     Abc_Print( -2, "\t-l     : toggle generating L(f) rather than C(f) [default = %s]\n",   fSimple?  "yes": "no" );
23856     Abc_Print( -2, "\t-d     : toggle generating D(f) rather than C(f) [default = %s]\n",   fDelay?   "yes": "no" );
23857     Abc_Print( -2, "\t-m     : toggle generating multiplicity statistics [default = %s]\n", fMulti?   "yes": "no" );
23858     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n",                     fVerbose? "yes": "no" );
23859     Abc_Print( -2, "\t-p     : toggle dumping result library (formula and AIG) [default = %s]\n",fDump?"yes": "no" );
23860     Abc_Print( -2, "\t-h     : print the command usage\n");
23861     return 1;
23862 }
23863 
23864 
23865 
23866 /**Function*************************************************************
23867 
23868   Synopsis    []
23869 
23870   Description []
23871 
23872   SideEffects []
23873 
23874   SeeAlso     []
23875 
23876 ***********************************************************************/
Abc_CommandCec(Abc_Frame_t * pAbc,int argc,char ** argv)23877 int Abc_CommandCec( Abc_Frame_t * pAbc, int argc, char ** argv )
23878 {
23879     char Buffer[16];
23880     Abc_Ntk_t * pNtk, * pNtk1, * pNtk2;
23881     int fDelete1, fDelete2;
23882     char ** pArgvNew;
23883     int nArgcNew;
23884     int c;
23885     int fSat;
23886     int fVerbose;
23887     int nSeconds;
23888     int nPartSize;
23889     int nConfLimit;
23890     int nInsLimit;
23891     int fPartition;
23892     int fIgnoreNames;
23893 
23894     extern void Abc_NtkCecSat( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nConfLimit, int nInsLimit );
23895     extern void Abc_NtkCecFraig( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nSeconds, int fVerbose );
23896     extern void Abc_NtkCecFraigPart( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nSeconds, int nPartSize, int fVerbose );
23897     extern void Abc_NtkCecFraigPartAuto( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nSeconds, int fVerbose );
23898 
23899     pNtk = Abc_FrameReadNtk(pAbc);
23900     // set defaults
23901     fSat     =  0;
23902     fVerbose =  0;
23903     nSeconds = 20;
23904     nPartSize  = 0;
23905     nConfLimit = 10000;
23906     nInsLimit  = 0;
23907     fPartition = 0;
23908     fIgnoreNames = 0;
23909     Extra_UtilGetoptReset();
23910     while ( ( c = Extra_UtilGetopt( argc, argv, "TCIPpsnvh" ) ) != EOF )
23911     {
23912         switch ( c )
23913         {
23914         case 'T':
23915             if ( globalUtilOptind >= argc )
23916             {
23917                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
23918                 goto usage;
23919             }
23920             nSeconds = atoi(argv[globalUtilOptind]);
23921             globalUtilOptind++;
23922             if ( nSeconds < 0 )
23923                 goto usage;
23924             break;
23925         case 'C':
23926             if ( globalUtilOptind >= argc )
23927             {
23928                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
23929                 goto usage;
23930             }
23931             nConfLimit = atoi(argv[globalUtilOptind]);
23932             globalUtilOptind++;
23933             if ( nConfLimit < 0 )
23934                 goto usage;
23935             break;
23936         case 'I':
23937             if ( globalUtilOptind >= argc )
23938             {
23939                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
23940                 goto usage;
23941             }
23942             nInsLimit = atoi(argv[globalUtilOptind]);
23943             globalUtilOptind++;
23944             if ( nInsLimit < 0 )
23945                 goto usage;
23946             break;
23947         case 'P':
23948             if ( globalUtilOptind >= argc )
23949             {
23950                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
23951                 goto usage;
23952             }
23953             nPartSize = atoi(argv[globalUtilOptind]);
23954             globalUtilOptind++;
23955             if ( nPartSize < 0 )
23956                 goto usage;
23957             break;
23958         case 'p':
23959             fPartition ^= 1;
23960             break;
23961         case 's':
23962             fSat ^= 1;
23963             break;
23964         case 'n':
23965             fIgnoreNames ^= 1;
23966             break;
23967         case 'v':
23968             fVerbose ^= 1;
23969             break;
23970         default:
23971             goto usage;
23972         }
23973     }
23974 
23975     if ( pNtk && pNtk->vPhases != NULL )
23976     {
23977         Abc_Print( -1, "Cannot compare networks with phases defined.\n" );
23978         return 1;
23979     }
23980 
23981     pArgvNew = argv + globalUtilOptind;
23982     nArgcNew = argc - globalUtilOptind;
23983     if ( !Abc_NtkPrepareTwoNtks( stdout, pNtk, pArgvNew, nArgcNew, &pNtk1, &pNtk2, &fDelete1, &fDelete2, 1 ) )
23984         return 1;
23985 
23986     if ( fIgnoreNames )
23987     {
23988         if ( !fDelete1 )
23989         {
23990             pNtk1 = Abc_NtkStrash( pNtk1, 0, 1, 0 );
23991             fDelete1 = 1;
23992         }
23993         if ( !fDelete2 )
23994         {
23995             pNtk2 = Abc_NtkStrash( pNtk2, 0, 1, 0 );
23996             fDelete2 = 1;
23997         }
23998         Abc_NtkShortNames( pNtk1 );
23999         Abc_NtkShortNames( pNtk2 );
24000     }
24001 
24002     // perform equivalence checking
24003     if ( fPartition )
24004         Abc_NtkCecFraigPartAuto( pNtk1, pNtk2, nSeconds, fVerbose );
24005     else if ( nPartSize )
24006         Abc_NtkCecFraigPart( pNtk1, pNtk2, nSeconds, nPartSize, fVerbose );
24007     else if ( fSat )
24008         Abc_NtkCecSat( pNtk1, pNtk2, nConfLimit, nInsLimit );
24009     else
24010         Abc_NtkCecFraig( pNtk1, pNtk2, nSeconds, fVerbose );
24011 
24012     if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
24013     if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
24014     return 0;
24015 
24016 usage:
24017     if ( nPartSize == 0 )
24018         strcpy( Buffer, "unused" );
24019     else
24020         sprintf(Buffer, "%d", nPartSize );
24021     Abc_Print( -2, "usage: cec [-T num] [-C num] [-I num] [-P num] [-psnvh] <file1> <file2>\n" );
24022     Abc_Print( -2, "\t         performs combinational equivalence checking\n" );
24023     Abc_Print( -2, "\t-T num : approximate runtime limit in seconds [default = %d]\n", nSeconds );
24024     Abc_Print( -2, "\t-C num : limit on the number of conflicts [default = %d]\n",    nConfLimit );
24025     Abc_Print( -2, "\t-I num : limit on the number of clause inspections [default = %d]\n", nInsLimit );
24026     Abc_Print( -2, "\t-P num : partition size for multi-output networks [default = %s]\n", Buffer );
24027     Abc_Print( -2, "\t-p     : toggle automatic partitioning [default = %s]\n", fPartition? "yes": "no" );
24028     Abc_Print( -2, "\t-s     : toggle \"SAT only\" and \"FRAIG + SAT\" [default = %s]\n", fSat? "SAT only": "FRAIG + SAT" );
24029     Abc_Print( -2, "\t-n     : toggle how CIs/COs are matched (by name or by order) [default = %s]\n", fIgnoreNames? "by order": "by name" );
24030     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
24031     Abc_Print( -2, "\t-h     : print the command usage\n");
24032     Abc_Print( -2, "\tfile1  : (optional) the file with the first network\n");
24033     Abc_Print( -2, "\tfile2  : (optional) the file with the second network\n");
24034     Abc_Print( -2, "\t         if no files are given, uses the current network and its spec\n");
24035     Abc_Print( -2, "\t         if one file is given, uses the current network and the file\n");
24036     return 1;
24037 }
24038 
24039 
24040 /**Function*************************************************************
24041 
24042   Synopsis    []
24043 
24044   Description []
24045 
24046   SideEffects []
24047 
24048   SeeAlso     []
24049 
24050 ***********************************************************************/
Abc_CommandDCec(Abc_Frame_t * pAbc,int argc,char ** argv)24051 int Abc_CommandDCec( Abc_Frame_t * pAbc, int argc, char ** argv )
24052 {
24053     Abc_Ntk_t * pNtk, * pNtk1, * pNtk2;
24054     int fDelete1, fDelete2;
24055     char ** pArgvNew;
24056     int nArgcNew;
24057     int c;
24058     int fSat;
24059     int fVerbose;
24060     int nSeconds;
24061     int nConfLimit;
24062     int nInsLimit;
24063     int fPartition;
24064     int fMiter;
24065 
24066     extern int Abc_NtkDSat( Abc_Ntk_t * pNtk, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, int nLearnedStart, int nLearnedDelta, int nLearnedPerce, int fAlignPol, int fAndOuts, int fNewSolver, int fVerbose );
24067     extern int Abc_NtkDarCec( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nConfLimit, int fPartition, int fVerbose );
24068 
24069     pNtk = Abc_FrameReadNtk(pAbc);
24070     // set defaults
24071     fSat     =  0;
24072     fVerbose =  0;
24073     nSeconds = 20;
24074     nConfLimit = 10000;
24075     nInsLimit  = 0;
24076     fPartition = 0;
24077     fMiter     = 0;
24078     Extra_UtilGetoptReset();
24079     while ( ( c = Extra_UtilGetopt( argc, argv, "TCIpmsvh" ) ) != EOF )
24080     {
24081         switch ( c )
24082         {
24083         case 'T':
24084             if ( globalUtilOptind >= argc )
24085             {
24086                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
24087                 goto usage;
24088             }
24089             nSeconds = atoi(argv[globalUtilOptind]);
24090             globalUtilOptind++;
24091             if ( nSeconds < 0 )
24092                 goto usage;
24093             break;
24094         case 'C':
24095             if ( globalUtilOptind >= argc )
24096             {
24097                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
24098                 goto usage;
24099             }
24100             nConfLimit = atoi(argv[globalUtilOptind]);
24101             globalUtilOptind++;
24102             if ( nConfLimit < 0 )
24103                 goto usage;
24104             break;
24105         case 'I':
24106             if ( globalUtilOptind >= argc )
24107             {
24108                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
24109                 goto usage;
24110             }
24111             nInsLimit = atoi(argv[globalUtilOptind]);
24112             globalUtilOptind++;
24113             if ( nInsLimit < 0 )
24114                 goto usage;
24115             break;
24116         case 'p':
24117             fPartition ^= 1;
24118             break;
24119         case 'm':
24120             fMiter ^= 1;
24121             break;
24122         case 's':
24123             fSat ^= 1;
24124             break;
24125         case 'v':
24126             fVerbose ^= 1;
24127             break;
24128         default:
24129             goto usage;
24130         }
24131     }
24132 
24133     pArgvNew = argv + globalUtilOptind;
24134     nArgcNew = argc - globalUtilOptind;
24135     if ( fMiter )
24136     {
24137         if ( pNtk == NULL )
24138         {
24139             Abc_Print( -1, "Empty network.\n" );
24140             return 1;
24141         }
24142         if ( Abc_NtkIsStrash(pNtk) )
24143         {
24144             pNtk1 = pNtk;
24145             fDelete1 = 0;
24146         }
24147         else
24148         {
24149             pNtk1 = Abc_NtkStrash( pNtk, 0, 1, 0 );
24150             fDelete1 = 1;
24151         }
24152         pNtk2 = NULL;
24153         fDelete2 = 0;
24154     }
24155     else
24156     {
24157         if ( !Abc_NtkPrepareTwoNtks( stdout, pNtk, pArgvNew, nArgcNew, &pNtk1, &pNtk2, &fDelete1, &fDelete2, 1 ) )
24158             return 1;
24159     }
24160 
24161     if ( (pNtk1 && Abc_NtkLatchNum(pNtk1)) || (pNtk2 && Abc_NtkLatchNum(pNtk2)) )
24162     {
24163         if ( pNtk1 && fDelete1 ) Abc_NtkDelete( pNtk1 );
24164         if ( pNtk2 && fDelete2 ) Abc_NtkDelete( pNtk2 );
24165         Abc_Print( -1, "Currently this command only works for networks without latches. Run \"comb\".\n" );
24166         return 1;
24167     }
24168 
24169     // perform equivalence checking
24170     if ( fSat && fMiter )
24171         Abc_NtkDSat( pNtk1, nConfLimit, nInsLimit, 0, 0, 0, 0, 0, 0, fVerbose );
24172     else
24173         Abc_NtkDarCec( pNtk1, pNtk2, nConfLimit, fPartition, fVerbose );
24174 
24175     if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
24176     if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
24177     return 0;
24178 
24179 usage:
24180     Abc_Print( -2, "usage: dcec [-T num] [-C num] [-I num] [-mpsvh] <file1> <file2>\n" );
24181     Abc_Print( -2, "\t         performs combinational equivalence checking\n" );
24182     Abc_Print( -2, "\t-T num : approximate runtime limit in seconds [default = %d]\n", nSeconds );
24183     Abc_Print( -2, "\t-C num : limit on the number of conflicts [default = %d]\n",    nConfLimit );
24184     Abc_Print( -2, "\t-I num : limit on the number of clause inspections [default = %d]\n", nInsLimit );
24185     Abc_Print( -2, "\t-m     : toggle working on two networks or a miter [default = %s]\n", fMiter? "miter": "two networks" );
24186     Abc_Print( -2, "\t-p     : toggle automatic partitioning [default = %s]\n", fPartition? "yes": "no" );
24187     Abc_Print( -2, "\t-s     : toggle \"SAT only\" (miter) or \"FRAIG + SAT\" [default = %s]\n", fSat? "SAT only": "FRAIG + SAT" );
24188     Abc_Print( -2, "\t-v     : toggles verbose output [default = %s]\n", fVerbose? "yes": "no" );
24189     Abc_Print( -2, "\t-h     : print the command usage\n");
24190     Abc_Print( -2, "\tfile1  : (optional) the file with the first network\n");
24191     Abc_Print( -2, "\tfile2  : (optional) the file with the second network\n");
24192     Abc_Print( -2, "\t         if no files are given, uses the current network and its spec\n");
24193     Abc_Print( -2, "\t         if one file is given, uses the current network and the file\n");
24194     return 1;
24195 }
24196 
24197 /**Function*************************************************************
24198 
24199   Synopsis    []
24200 
24201   Description []
24202 
24203   SideEffects []
24204 
24205   SeeAlso     []
24206 
24207 ***********************************************************************/
Abc_CommandDSec(Abc_Frame_t * pAbc,int argc,char ** argv)24208 int Abc_CommandDSec( Abc_Frame_t * pAbc, int argc, char ** argv )
24209 {
24210     Fra_Sec_t SecPar, * pSecPar = &SecPar;
24211     Abc_Ntk_t * pNtk, * pNtk1, * pNtk2;
24212     int fDelete1, fDelete2;
24213     char ** pArgvNew;
24214     int nArgcNew;
24215     int c, fCheck = 1;
24216     int fIgnoreNames;
24217 
24218     extern int Abc_NtkDarSec( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, Fra_Sec_t * p );
24219 
24220     pNtk = Abc_FrameReadNtk(pAbc);
24221     // set defaults
24222     Fra_SecSetDefaultParams( pSecPar );
24223     pSecPar->TimeLimit = 0;
24224     fIgnoreNames = 0;
24225     Extra_UtilGetoptReset();
24226     while ( ( c = Extra_UtilGetopt( argc, argv, "FTarmfncvwh" ) ) != EOF )
24227     {
24228         switch ( c )
24229         {
24230         case 'F':
24231             if ( globalUtilOptind >= argc )
24232             {
24233                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
24234                 goto usage;
24235             }
24236             pSecPar->nFramesMax = atoi(argv[globalUtilOptind]);
24237             globalUtilOptind++;
24238             if ( pSecPar->nFramesMax < 0 )
24239                 goto usage;
24240             break;
24241         case 'T':
24242             if ( globalUtilOptind >= argc )
24243             {
24244                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
24245                 goto usage;
24246             }
24247             pSecPar->TimeLimit = atoi(argv[globalUtilOptind]);
24248             globalUtilOptind++;
24249             if ( pSecPar->TimeLimit < 0 )
24250                 goto usage;
24251             break;
24252         case 'a':
24253             pSecPar->fPhaseAbstract ^= 1;
24254             break;
24255         case 'r':
24256             pSecPar->fRetimeFirst ^= 1;
24257             break;
24258         case 'm':
24259             pSecPar->fRetimeRegs ^= 1;
24260             break;
24261         case 'f':
24262             pSecPar->fFraiging ^= 1;
24263             break;
24264         case 'n':
24265             fIgnoreNames ^= 1;
24266             break;
24267         case 'c':
24268             fCheck ^= 1;
24269             break;
24270         case 'v':
24271             pSecPar->fVerbose ^= 1;
24272             break;
24273         case 'w':
24274             pSecPar->fVeryVerbose ^= 1;
24275             break;
24276         default:
24277             goto usage;
24278         }
24279     }
24280 
24281     pArgvNew = argv + globalUtilOptind;
24282     nArgcNew = argc - globalUtilOptind;
24283     if ( !Abc_NtkPrepareTwoNtks( stdout, pNtk, pArgvNew, nArgcNew, &pNtk1, &pNtk2, &fDelete1, &fDelete2, fCheck ) )
24284         return 1;
24285     if ( Abc_NtkLatchNum(pNtk1) == 0 || Abc_NtkLatchNum(pNtk2) == 0 )
24286     {
24287         if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
24288         if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
24289         Abc_Print( -1, "The network has no latches. Used combinational command \"cec\".\n" );
24290         return 0;
24291     }
24292 
24293     if ( fIgnoreNames )
24294     {
24295         if ( !fDelete1 )
24296         {
24297             pNtk1 = Abc_NtkStrash( pNtk1, 0, 1, 0 );
24298             fDelete1 = 1;
24299         }
24300         if ( !fDelete2 )
24301         {
24302             pNtk2 = Abc_NtkStrash( pNtk2, 0, 1, 0 );
24303             fDelete2 = 1;
24304         }
24305         Abc_NtkShortNames( pNtk1 );
24306         Abc_NtkShortNames( pNtk2 );
24307     }
24308 
24309     // perform verification
24310     pAbc->Status = Abc_NtkDarSec( pNtk1, pNtk2, pSecPar );
24311 
24312     if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
24313     if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
24314     return 0;
24315 
24316 usage:
24317     Abc_Print( -2, "usage: dsec [-F num] [-T num] [-armfncvwh] <file1> <file2>\n" );
24318     Abc_Print( -2, "\t         performs inductive sequential equivalence checking\n" );
24319     Abc_Print( -2, "\t-F num : the limit on the depth of induction [default = %d]\n", pSecPar->nFramesMax );
24320     Abc_Print( -2, "\t-T num : the approximate runtime limit (in seconds) [default = %d]\n", pSecPar->TimeLimit );
24321     Abc_Print( -2, "\t-a     : toggles the use of phase abstraction [default = %s]\n", pSecPar->fPhaseAbstract? "yes": "no" );
24322     Abc_Print( -2, "\t-r     : toggles forward retiming at the beginning [default = %s]\n", pSecPar->fRetimeFirst? "yes": "no" );
24323     Abc_Print( -2, "\t-m     : toggles min-register retiming [default = %s]\n", pSecPar->fRetimeRegs? "yes": "no" );
24324     Abc_Print( -2, "\t-f     : toggles the internal use of fraiging [default = %s]\n", pSecPar->fFraiging? "yes": "no" );
24325     Abc_Print( -2, "\t-n     : toggles how CIs/COs are matched (by name or by order) [default = %s]\n", fIgnoreNames? "by order": "by name" );
24326     Abc_Print( -2, "\t-c     : toggles performing internal netlist check [default = %s]\n", fCheck? "yes": "no" );
24327     Abc_Print( -2, "\t-v     : toggles verbose output [default = %s]\n", pSecPar->fVerbose? "yes": "no" );
24328     Abc_Print( -2, "\t-w     : toggles additional verbose output [default = %s]\n", pSecPar->fVeryVerbose? "yes": "no" );
24329     Abc_Print( -2, "\t-h     : print the command usage\n");
24330     Abc_Print( -2, "\tfile1  : (optional) the file with the first network\n");
24331     Abc_Print( -2, "\tfile2  : (optional) the file with the second network\n");
24332     Abc_Print( -2, "\t         if no files are given, uses the current network and its spec\n");
24333     Abc_Print( -2, "\t         if one file is given, uses the current network and the file\n");
24334     return 1;
24335 }
24336 
24337 /**Function*************************************************************
24338 
24339   Synopsis    []
24340 
24341   Description []
24342 
24343   SideEffects []
24344 
24345   SeeAlso     []
24346 
24347 ***********************************************************************/
Abc_CommandDProve(Abc_Frame_t * pAbc,int argc,char ** argv)24348 int Abc_CommandDProve( Abc_Frame_t * pAbc, int argc, char ** argv )
24349 {
24350     Fra_Sec_t SecPar, * pSecPar = &SecPar;
24351     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
24352     int c;
24353     char * pLogFileName = NULL;
24354     int nBmcFramesMax = 20;
24355     int nBmcConfMax = 2000;
24356 
24357     extern void Fra_SecSetDefaultParams( Fra_Sec_t * p );
24358     extern int Abc_NtkDarProve( Abc_Ntk_t * pNtk, Fra_Sec_t * pSecPar, int nBmcFramesMax, int nBmcConfMax );
24359     // set defaults
24360     Fra_SecSetDefaultParams( pSecPar );
24361 //    pSecPar->TimeLimit = 300;
24362     Extra_UtilGetoptReset();
24363     while ( ( c = Extra_UtilGetopt( argc, argv, "cbAEFCGDVBRTLarmfijkoupwvh" ) ) != EOF )
24364     {
24365         switch ( c )
24366         {
24367         case 'c':
24368             pSecPar->fTryComb ^= 1;
24369             break;
24370         case 'b':
24371             pSecPar->fTryBmc ^= 1;
24372             break;
24373         case 'A':
24374             if ( globalUtilOptind >= argc )
24375             {
24376                 Abc_Print( -1, "Command line switch \"-A\" should be followed by an integer.\n" );
24377                 goto usage;
24378             }
24379             nBmcFramesMax = atoi(argv[globalUtilOptind]);
24380             globalUtilOptind++;
24381             if ( nBmcFramesMax < 0 )
24382                 goto usage;
24383             break;
24384         case 'E':
24385             if ( globalUtilOptind >= argc )
24386             {
24387                 Abc_Print( -1, "Command line switch \"-E\" should be followed by an integer.\n" );
24388                 goto usage;
24389             }
24390             nBmcConfMax = atoi(argv[globalUtilOptind]);
24391             globalUtilOptind++;
24392             if ( nBmcConfMax < 0 )
24393                 goto usage;
24394             break;
24395         case 'F':
24396             if ( globalUtilOptind >= argc )
24397             {
24398                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
24399                 goto usage;
24400             }
24401             pSecPar->nFramesMax = atoi(argv[globalUtilOptind]);
24402             globalUtilOptind++;
24403             if ( pSecPar->nFramesMax < 0 )
24404                 goto usage;
24405             break;
24406         case 'C':
24407             if ( globalUtilOptind >= argc )
24408             {
24409                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
24410                 goto usage;
24411             }
24412             pSecPar->nBTLimit = atoi(argv[globalUtilOptind]);
24413             globalUtilOptind++;
24414             if ( pSecPar->nBTLimit < 0 )
24415                 goto usage;
24416             break;
24417         case 'G':
24418             if ( globalUtilOptind >= argc )
24419             {
24420                 Abc_Print( -1, "Command line switch \"-G\" should be followed by an integer.\n" );
24421                 goto usage;
24422             }
24423             pSecPar->nBTLimitGlobal = atoi(argv[globalUtilOptind]);
24424             globalUtilOptind++;
24425             if ( pSecPar->nBTLimitGlobal < 0 )
24426                 goto usage;
24427             break;
24428         case 'D':
24429             if ( globalUtilOptind >= argc )
24430             {
24431                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
24432                 goto usage;
24433             }
24434             pSecPar->nBTLimitInter = atoi(argv[globalUtilOptind]);
24435             globalUtilOptind++;
24436             if ( pSecPar->nBTLimitInter < 0 )
24437                 goto usage;
24438             break;
24439         case 'V':
24440             if ( globalUtilOptind >= argc )
24441             {
24442                 Abc_Print( -1, "Command line switch \"-V\" should be followed by an integer.\n" );
24443                 goto usage;
24444             }
24445             pSecPar->nBddVarsMax = atoi(argv[globalUtilOptind]);
24446             globalUtilOptind++;
24447             if ( pSecPar->nBddVarsMax < 0 )
24448                 goto usage;
24449             break;
24450         case 'B':
24451             if ( globalUtilOptind >= argc )
24452             {
24453                 Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" );
24454                 goto usage;
24455             }
24456             pSecPar->nBddMax = atoi(argv[globalUtilOptind]);
24457             globalUtilOptind++;
24458             if ( pSecPar->nBddMax < 0 )
24459                 goto usage;
24460             break;
24461         case 'R':
24462             if ( globalUtilOptind >= argc )
24463             {
24464                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
24465                 goto usage;
24466             }
24467             pSecPar->nBddIterMax = atoi(argv[globalUtilOptind]);
24468             globalUtilOptind++;
24469             if ( pSecPar->nBddIterMax < 0 )
24470                 goto usage;
24471             break;
24472         case 'T':
24473             if ( globalUtilOptind >= argc )
24474             {
24475                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
24476                 goto usage;
24477             }
24478             pSecPar->nPdrTimeout = atoi(argv[globalUtilOptind]);
24479             globalUtilOptind++;
24480             if ( pSecPar->nPdrTimeout < 0 )
24481                 goto usage;
24482             break;
24483         case 'L':
24484             if ( globalUtilOptind >= argc )
24485             {
24486                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
24487                 goto usage;
24488             }
24489             pLogFileName = argv[globalUtilOptind];
24490             globalUtilOptind++;
24491             break;
24492         case 'a':
24493             pSecPar->fPhaseAbstract ^= 1;
24494             break;
24495         case 'r':
24496             pSecPar->fRetimeFirst ^= 1;
24497             break;
24498         case 'm':
24499             pSecPar->fRetimeRegs ^= 1;
24500             break;
24501         case 'f':
24502             pSecPar->fFraiging ^= 1;
24503             break;
24504         case 'i':
24505             pSecPar->fInduction ^= 1;
24506             break;
24507         case 'j':
24508             pSecPar->fInterpolation ^= 1;
24509             break;
24510         case 'k':
24511             pSecPar->fInterSeparate ^= 1;
24512             break;
24513         case 'o':
24514             pSecPar->fReorderImage ^= 1;
24515             break;
24516         case 'u':
24517             pSecPar->fReadUnsolved ^= 1;
24518             break;
24519         case 'p':
24520             pSecPar->fUsePdr ^= 1;
24521             break;
24522         case 'w':
24523             pSecPar->fVeryVerbose ^= 1;
24524             break;
24525         case 'v':
24526             pSecPar->fVerbose ^= 1;
24527             break;
24528         default:
24529             goto usage;
24530         }
24531     }
24532     if ( pNtk == NULL )
24533     {
24534         Abc_Print( -1, "Empty network.\n" );
24535         return 1;
24536     }
24537     if ( !Abc_NtkIsStrash(pNtk) )
24538     {
24539         Abc_Print( -1, "This command works only for structrally hashed networks. Run \"st\".\n" );
24540         return 0;
24541     }
24542     if ( pAbc->fBatchMode && (pAbc->Status == 0 || pAbc->Status == 1) )
24543     {
24544         Abc_Print( 1, "The miters is already solved; skipping the command.\n" );
24545         return 0;
24546     }
24547 
24548     // perform verification
24549     pAbc->Status = Abc_NtkDarProve( pNtk, pSecPar, nBmcFramesMax, nBmcConfMax );
24550     Abc_FrameReplaceCex( pAbc, &pNtk->pSeqModel );
24551     if ( pLogFileName )
24552         Abc_NtkWriteLogFile( pLogFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, "dprove" );
24553 
24554     // read back the resulting unsolved reduced sequential miter
24555     if ( pSecPar->fReadUnsolved && pSecPar->nSMnumber >= 0 )
24556     {
24557         char FileName[100];
24558         sprintf(FileName, "sm%02d.aig", pSecPar->nSMnumber );
24559         pNtk = Io_Read( FileName, Io_ReadFileType(FileName), 1, 0 );
24560         if ( pNtk == NULL )
24561             Abc_Print( -1, "Cannot read back unsolved reduced sequential miter \"%s\",\n", FileName );
24562         else
24563             Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
24564     }
24565     return 0;
24566 
24567 usage:
24568     Abc_Print( -2, "usage: dprove [-AEFCGDVBRT num] [-L file] [-cbarmfijoupvwh]\n" );
24569     Abc_Print( -2, "\t         performs SEC on the sequential miter\n" );
24570     Abc_Print( -2, "\t-A num : the limit on the depth of BMC [default = %d]\n", nBmcFramesMax );
24571     Abc_Print( -2, "\t-E num : the conflict limit during BMC [default = %d]\n", nBmcConfMax );
24572     Abc_Print( -2, "\t-F num : the limit on the depth of induction [default = %d]\n", pSecPar->nFramesMax );
24573     Abc_Print( -2, "\t-C num : the conflict limit at a node during induction [default = %d]\n", pSecPar->nBTLimit );
24574     Abc_Print( -2, "\t-G num : the global conflict limit during induction [default = %d]\n", pSecPar->nBTLimitGlobal );
24575     Abc_Print( -2, "\t-D num : the conflict limit during interpolation [default = %d]\n", pSecPar->nBTLimitInter );
24576     Abc_Print( -2, "\t-V num : the flop count limit for BDD-based reachablity [default = %d]\n", pSecPar->nBddVarsMax );
24577     Abc_Print( -2, "\t-B num : the BDD size limit in BDD-based reachablity [default = %d]\n", pSecPar->nBddMax );
24578     Abc_Print( -2, "\t-R num : the max number of reachability iterations [default = %d]\n", pSecPar->nBddIterMax );
24579     Abc_Print( -2, "\t-T num : the timeout for property directed reachability [default = %d]\n", pSecPar->nPdrTimeout );
24580     Abc_Print( -2, "\t-L file: the log file name [default = %s]\n", pLogFileName ? pLogFileName : "no logging" );
24581     Abc_Print( -2, "\t-c     : toggles using CEC before attempting SEC [default = %s]\n", pSecPar->fTryComb? "yes": "no" );
24582     Abc_Print( -2, "\t-b     : toggles using BMC before attempting SEC [default = %s]\n", pSecPar->fTryBmc? "yes": "no" );
24583     Abc_Print( -2, "\t-a     : toggles the use of phase abstraction [default = %s]\n", pSecPar->fPhaseAbstract? "yes": "no" );
24584     Abc_Print( -2, "\t-r     : toggles forward retiming at the beginning [default = %s]\n", pSecPar->fRetimeFirst? "yes": "no" );
24585     Abc_Print( -2, "\t-m     : toggles min-register retiming [default = %s]\n", pSecPar->fRetimeRegs? "yes": "no" );
24586     Abc_Print( -2, "\t-f     : toggles the internal use of fraiging [default = %s]\n", pSecPar->fFraiging? "yes": "no" );
24587     Abc_Print( -2, "\t-i     : toggles the use of induction [default = %s]\n", pSecPar->fInduction? "yes": "no" );
24588     Abc_Print( -2, "\t-j     : toggles the use of interpolation [default = %s]\n", pSecPar->fInterpolation? "yes": "no" );
24589     Abc_Print( -2, "\t-k     : toggles applying interpolation to each output [default = %s]\n", pSecPar->fInterSeparate? "yes": "no" );
24590     Abc_Print( -2, "\t-o     : toggles using BDD variable reordering during image computation [default = %s]\n", pSecPar->fReorderImage? "yes": "no" );
24591     Abc_Print( -2, "\t-u     : toggles reading back unsolved reduced sequential miter [default = %s]\n", pSecPar->fReadUnsolved? "yes": "no" );
24592     Abc_Print( -2, "\t-p     : toggles trying property directed reachability in the end [default = %s]\n", pSecPar->fUsePdr? "yes": "no" );
24593     Abc_Print( -2, "\t-v     : toggles verbose output [default = %s]\n", pSecPar->fVerbose? "yes": "no" );
24594     Abc_Print( -2, "\t-w     : toggles additional verbose output [default = %s]\n", pSecPar->fVeryVerbose? "yes": "no" );
24595     Abc_Print( -2, "\t-h     : print the command usage\n");
24596     Abc_Print( -2, "\tCommand \"dprove\" can also be used for sequential synthesis (dprove -brjopu)\n");
24597     return 1;
24598 }
24599 
24600 /**Function*************************************************************
24601 
24602   Synopsis    []
24603 
24604   Description []
24605 
24606   SideEffects []
24607 
24608   SeeAlso     []
24609 
24610 ***********************************************************************/
Abc_CommandAbSec(Abc_Frame_t * pAbc,int argc,char ** argv)24611 int Abc_CommandAbSec( Abc_Frame_t * pAbc, int argc, char ** argv )
24612 {
24613     Abc_Ntk_t * pNtk, * pNtk1, * pNtk2;
24614     int fDelete1, fDelete2;
24615     char ** pArgvNew;
24616     int nArgcNew;
24617     int fMiter, nFrames, fVerbose, c;
24618 
24619     extern int Abc_NtkDarAbSec( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nFrames, int fVerbose );
24620 
24621     pNtk = Abc_FrameReadNtk(pAbc);
24622     // set defaults
24623     fMiter   = 1;
24624     nFrames  = 2;
24625     fVerbose = 0;
24626     Extra_UtilGetoptReset();
24627     while ( ( c = Extra_UtilGetopt( argc, argv, "Fmvh" ) ) != EOF )
24628     {
24629         switch ( c )
24630         {
24631         case 'F':
24632             if ( globalUtilOptind >= argc )
24633             {
24634                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
24635                 goto usage;
24636             }
24637             nFrames = atoi(argv[globalUtilOptind]);
24638             globalUtilOptind++;
24639             if ( nFrames < 0 )
24640                 goto usage;
24641             break;
24642         case 'm':
24643             fMiter ^= 1;
24644             break;
24645         case 'v':
24646             fVerbose ^= 1;
24647             break;
24648         default:
24649             goto usage;
24650         }
24651     }
24652 
24653     if ( fMiter )
24654     {
24655 //        pNtk = Io_Read( argv[globalUtilOptind], Io_ReadFileType(argv[globalUtilOptind]), 1, 0 );
24656         if ( argc == globalUtilOptind + 1 )
24657         {
24658             Abc_Print( -1, "The miter cannot be given on the command line. Use \"read\".\n" );
24659             return 0;
24660         }
24661         if ( !Abc_NtkIsStrash(pNtk) )
24662         {
24663             Abc_Print( -1, "The miter should be structurally hashed. Use \"st\"\n" );
24664             return 0;
24665         }
24666         if ( Abc_NtkDarAbSec( pNtk, NULL, nFrames, fVerbose ) == 1 )
24667             pAbc->Status = 1;
24668         else
24669             pAbc->Status = -1;
24670     }
24671     else
24672     {
24673         pArgvNew = argv + globalUtilOptind;
24674         nArgcNew = argc - globalUtilOptind;
24675         if ( !Abc_NtkPrepareTwoNtks( stdout, pNtk, pArgvNew, nArgcNew, &pNtk1, &pNtk2, &fDelete1, &fDelete2, 1 ) )
24676             return 1;
24677         if ( Abc_NtkLatchNum(pNtk1) == 0 || Abc_NtkLatchNum(pNtk2) == 0 )
24678         {
24679             if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
24680             if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
24681             Abc_Print( -1, "The network has no latches. Used combinational command \"cec\".\n" );
24682             return 0;
24683         }
24684         // perform verification
24685         if ( Abc_NtkDarAbSec( pNtk1, pNtk2, nFrames, fVerbose ) == 1 )
24686             pAbc->Status = 1;
24687         else
24688             pAbc->Status = -1;
24689         if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
24690         if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
24691     }
24692     return 0;
24693 
24694 usage:
24695     Abc_Print( -2, "usage: absec [-F num] [-mv] <file1> <file2>\n" );
24696     Abc_Print( -2, "\t         performs SEC by applying CEC to several timeframes\n" );
24697     Abc_Print( -2, "\t-F num : the total number of timeframes to use [default = %d]\n", nFrames );
24698     Abc_Print( -2, "\t-m     : toggles miter vs. two networks [default = %s]\n", fMiter? "miter": "two networks" );
24699     Abc_Print( -2, "\t-v     : toggles verbose output [default = %s]\n", fVerbose? "yes": "no" );
24700     Abc_Print( -2, "\tfile1  : (optional) the file with the first network\n");
24701     Abc_Print( -2, "\tfile2  : (optional) the file with the second network\n");
24702     Abc_Print( -2, "\t         if no files are given, uses the current network and its spec\n");
24703     Abc_Print( -2, "\t         if one file is given, uses the current network and the file\n");
24704     return 1;
24705 }
24706 
24707 /**Function*************************************************************
24708 
24709   Synopsis    []
24710 
24711   Description []
24712 
24713   SideEffects []
24714 
24715   SeeAlso     []
24716 
24717 ***********************************************************************/
Abc_CommandSimSec(Abc_Frame_t * pAbc,int argc,char ** argv)24718 int Abc_CommandSimSec( Abc_Frame_t * pAbc, int argc, char ** argv )
24719 {
24720     Ssw_Pars_t Pars, * pPars = &Pars;
24721     Abc_Ntk_t * pNtk, * pNtk1, * pNtk2;
24722     int fDelete1, fDelete2;
24723     char ** pArgvNew;
24724     int nArgcNew, c;
24725     int fMiter;
24726 
24727     extern int Abc_NtkDarSimSec( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, Ssw_Pars_t * pPars );
24728 
24729     pNtk = Abc_FrameReadNtk(pAbc);
24730     // set defaults
24731     fMiter = 1;
24732     Ssw_ManSetDefaultParams( pPars );
24733     pPars->fPartSigCorr = 1;
24734     pPars->fVerbose     = 1;
24735     Extra_UtilGetoptReset();
24736     while ( ( c = Extra_UtilGetopt( argc, argv, "FDcymvh" ) ) != EOF )
24737     {
24738         switch ( c )
24739         {
24740         case 'F':
24741             if ( globalUtilOptind >= argc )
24742             {
24743                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
24744                 goto usage;
24745             }
24746             pPars->nFramesK = atoi(argv[globalUtilOptind]);
24747             globalUtilOptind++;
24748             if ( pPars->nFramesK < 0 )
24749                 goto usage;
24750             break;
24751         case 'D':
24752             if ( globalUtilOptind >= argc )
24753             {
24754                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
24755                 goto usage;
24756             }
24757             pPars->nIsleDist = atoi(argv[globalUtilOptind]);
24758             globalUtilOptind++;
24759             if ( pPars->nIsleDist < 0 )
24760                 goto usage;
24761             break;
24762         case 'm':
24763             fMiter ^= 1;
24764             break;
24765         case 'c':
24766             pPars->fPartSigCorr ^= 1;
24767             break;
24768         case 'y':
24769             pPars->fDumpSRInit ^= 1;
24770             break;
24771         case 'v':
24772             pPars->fVerbose ^= 1;
24773             break;
24774         default:
24775             goto usage;
24776         }
24777     }
24778 
24779     if ( fMiter )
24780     {
24781 //        Abc_Ntk_t * pNtkA, * pNtkB;
24782         if ( !Abc_NtkIsStrash(pNtk) )
24783         {
24784             Abc_Print( -1, "This command works only for structrally hashed networks. Run \"st\".\n" );
24785             return 0;
24786         }
24787         Abc_NtkDarSimSec( pNtk, NULL, pPars );
24788 /*
24789         pNtkA = Abc_NtkDup( pNtk );
24790         pNtkB = Abc_NtkDup( pNtk );
24791         Abc_NtkDarSimSec( pNtkA, pNtkB, pPars );
24792         Abc_NtkDelete( pNtkA );
24793         Abc_NtkDelete( pNtkB );
24794 */
24795     }
24796     else
24797     {
24798         pArgvNew = argv + globalUtilOptind;
24799         nArgcNew = argc - globalUtilOptind;
24800         if ( !Abc_NtkPrepareTwoNtks( stdout, pNtk, pArgvNew, nArgcNew, &pNtk1, &pNtk2, &fDelete1, &fDelete2, 1 ) )
24801             return 1;
24802         if ( Abc_NtkLatchNum(pNtk1) == 0 || Abc_NtkLatchNum(pNtk2) == 0 )
24803         {
24804             if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
24805             if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
24806             Abc_Print( -1, "The network has no latches. Used combinational command \"cec\".\n" );
24807             return 0;
24808         }
24809         // perform verification
24810         Abc_NtkDarSimSec( pNtk1, pNtk2, pPars );
24811         if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
24812         if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
24813     }
24814     return 0;
24815 
24816 usage:
24817     Abc_Print( -2, "usage: simsec [-FD num] [-mcyv] <file1> <file2>\n" );
24818     Abc_Print( -2, "\t         performs SEC using structural similarity\n" );
24819     Abc_Print( -2, "\t-F num : the limit on the depth of induction [default = %d]\n", pPars->nFramesK );
24820     Abc_Print( -2, "\t-D num : the distance for extending islands [default = %d]\n", pPars->nIsleDist );
24821     Abc_Print( -2, "\t-m     : toggles miter vs. two networks [default = %s]\n", fMiter? "miter": "two networks" );
24822     Abc_Print( -2, "\t-c     : uses partial vs. full signal correspondence [default = %s]\n", pPars->fPartSigCorr? "partial": "full" );
24823     Abc_Print( -2, "\t-y     : dumps speculatively reduced miter of the classes [default = %s]\n", pPars->fDumpSRInit? "yes": "no" );
24824     Abc_Print( -2, "\t-v     : toggles verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
24825     Abc_Print( -2, "\tfile1  : (optional) the file with the first network\n");
24826     Abc_Print( -2, "\tfile2  : (optional) the file with the second network\n");
24827     Abc_Print( -2, "\t         if no files are given, uses the current network and its spec\n");
24828     Abc_Print( -2, "\t         if one file is given, uses the current network and the file\n");
24829     return 1;
24830 }
24831 
24832 /**Function*************************************************************
24833 
24834   Synopsis    []
24835 
24836   Description []
24837 
24838   SideEffects []
24839 
24840   SeeAlso     []
24841 
24842 ***********************************************************************/
Abc_CommandMatch(Abc_Frame_t * pAbc,int argc,char ** argv)24843 int Abc_CommandMatch( Abc_Frame_t * pAbc, int argc, char ** argv )
24844 {
24845     Abc_Ntk_t * pNtk, * pNtk1, * pNtk2, * pNtkRes;
24846     int fDelete1, fDelete2;
24847     char ** pArgvNew;
24848     int nArgcNew, c;
24849     int fMiter;
24850     int nDist;
24851     int fVerbose;
24852 
24853     extern Abc_Ntk_t * Abc_NtkDarMatch( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nDist, int fVerbose );
24854 
24855     pNtk = Abc_FrameReadNtk(pAbc);
24856     // set defaults
24857     fMiter = 0;
24858     nDist = 0;
24859     fVerbose = 1;
24860     Extra_UtilGetoptReset();
24861     while ( ( c = Extra_UtilGetopt( argc, argv, "Dmvh" ) ) != EOF )
24862     {
24863         switch ( c )
24864         {
24865         case 'D':
24866             if ( globalUtilOptind >= argc )
24867             {
24868                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
24869                 goto usage;
24870             }
24871             nDist = atoi(argv[globalUtilOptind]);
24872             globalUtilOptind++;
24873             if ( nDist < 0 )
24874                 goto usage;
24875             break;
24876         case 'm':
24877             fMiter ^= 1;
24878             break;
24879         case 'v':
24880             fVerbose ^= 1;
24881             break;
24882         default:
24883             goto usage;
24884         }
24885     }
24886 
24887     if ( fMiter )
24888     {
24889 //        Abc_Ntk_t * pNtkA, * pNtkB;
24890         if ( !Abc_NtkIsStrash(pNtk) )
24891         {
24892             Abc_Print( -1, "This command works only for structrally hashed networks. Run \"st\".\n" );
24893             return 0;
24894         }
24895         pNtkRes = Abc_NtkDarMatch( pNtk, NULL, nDist, fVerbose );
24896 /*
24897         pNtkA = Abc_NtkDup( pNtk );
24898         pNtkB = Abc_NtkDup( pNtk );
24899         Abc_NtkDarSimSec( pNtkA, pNtkB, pPars );
24900         Abc_NtkDelete( pNtkA );
24901         Abc_NtkDelete( pNtkB );
24902 */
24903     }
24904     else
24905     {
24906         pArgvNew = argv + globalUtilOptind;
24907         nArgcNew = argc - globalUtilOptind;
24908         if ( !Abc_NtkPrepareTwoNtks( stdout, pNtk, pArgvNew, nArgcNew, &pNtk1, &pNtk2, &fDelete1, &fDelete2, 1 ) )
24909             return 1;
24910         if ( Abc_NtkLatchNum(pNtk1) == 0 || Abc_NtkLatchNum(pNtk2) == 0 )
24911         {
24912             if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
24913             if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
24914             Abc_Print( -1, "The network has no latches. Used combinational command \"cec\".\n" );
24915             return 0;
24916         }
24917         // perform verification
24918         pNtkRes = Abc_NtkDarMatch( pNtk1, pNtk2, nDist, fVerbose );
24919         if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
24920         if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
24921     }
24922     if ( pNtkRes == NULL )
24923     {
24924         Abc_Print( -1, "Matching has failed.\n" );
24925         return 1;
24926     }
24927     // replace the current network
24928     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
24929     return 0;
24930 
24931 usage:
24932     Abc_Print( -2, "usage: match [-D num] [-mv] <file1> <file2>\n" );
24933     Abc_Print( -2, "\t         detects structural similarity using simulation\n" );
24934     Abc_Print( -2, "\t         replaces the current network by the miter of differences\n" );
24935     Abc_Print( -2, "\t-D num : the distance for extending differences [default = %d]\n", nDist );
24936     Abc_Print( -2, "\t-m     : toggles miter vs. two networks [default = %s]\n", fMiter? "miter": "two networks" );
24937     Abc_Print( -2, "\t-v     : toggles verbose output [default = %s]\n", fVerbose? "yes": "no" );
24938     Abc_Print( -2, "\tfile1  : (optional) the file with the first network\n");
24939     Abc_Print( -2, "\tfile2  : (optional) the file with the second network\n");
24940     Abc_Print( -2, "\t         if no files are given, uses the current network and its spec\n");
24941     Abc_Print( -2, "\t         if one file is given, uses the current network and the file\n");
24942     return 1;
24943 }
24944 
24945 /**Function*************************************************************
24946 
24947   Synopsis    []
24948 
24949   Description []
24950 
24951   SideEffects []
24952 
24953   SeeAlso     []
24954 
24955 ***********************************************************************/
Abc_CommandSat(Abc_Frame_t * pAbc,int argc,char ** argv)24956 int Abc_CommandSat( Abc_Frame_t * pAbc, int argc, char ** argv )
24957 {
24958     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
24959     int c;
24960     int RetValue;
24961     int fVerbose;
24962     int nConfLimit;
24963     int nInsLimit;
24964     abctime clk;
24965     // set defaults
24966     fVerbose   = 0;
24967     nConfLimit = 0;
24968     nInsLimit  = 0;
24969     Extra_UtilGetoptReset();
24970     while ( ( c = Extra_UtilGetopt( argc, argv, "CIvh" ) ) != EOF )
24971     {
24972         switch ( c )
24973         {
24974         case 'C':
24975             if ( globalUtilOptind >= argc )
24976             {
24977                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
24978                 goto usage;
24979             }
24980             nConfLimit = atoi(argv[globalUtilOptind]);
24981             globalUtilOptind++;
24982             if ( nConfLimit < 0 )
24983                 goto usage;
24984             break;
24985         case 'I':
24986             if ( globalUtilOptind >= argc )
24987             {
24988                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
24989                 goto usage;
24990             }
24991             nInsLimit = atoi(argv[globalUtilOptind]);
24992             globalUtilOptind++;
24993             if ( nInsLimit < 0 )
24994                 goto usage;
24995             break;
24996         case 'v':
24997             fVerbose ^= 1;
24998             break;
24999         case 'h':
25000             goto usage;
25001         default:
25002             goto usage;
25003         }
25004     }
25005 
25006     if ( pNtk == NULL )
25007     {
25008         Abc_Print( -1, "Empty network.\n" );
25009         return 1;
25010     }
25011     if ( Abc_NtkLatchNum(pNtk) > 0 )
25012     {
25013         Abc_Print( -1, "Currently can only solve the miter for combinational circuits.\n" );
25014         return 0;
25015     }
25016 
25017     clk = Abc_Clock();
25018     if ( Abc_NtkIsStrash(pNtk) )
25019     {
25020         RetValue = Abc_NtkMiterSat( pNtk, (ABC_INT64_T)nConfLimit, (ABC_INT64_T)nInsLimit, fVerbose, NULL, NULL );
25021     }
25022     else
25023     {
25024         assert( Abc_NtkIsLogic(pNtk) );
25025         Abc_NtkToBdd( pNtk );
25026         RetValue = Abc_NtkMiterSat( pNtk, (ABC_INT64_T)nConfLimit, (ABC_INT64_T)nInsLimit, fVerbose, NULL, NULL );
25027     }
25028 
25029     // verify that the pattern is correct
25030     if ( RetValue == 0 && Abc_NtkPoNum(pNtk) == 1 )
25031     {
25032         //int i;
25033         //Abc_Obj_t * pObj;
25034         int * pSimInfo = Abc_NtkVerifySimulatePattern( pNtk, pNtk->pModel );
25035         if ( pSimInfo[0] != 1 )
25036             Abc_Print( 1, "ERROR in Abc_NtkMiterSat(): Generated counter example is invalid.\n" );
25037         ABC_FREE( pSimInfo );
25038         /*
25039         // print model
25040         Abc_NtkForEachPi( pNtk, pObj, i )
25041         {
25042             Abc_Print( -1, "%d", (int)(pNtk->pModel[i] > 0) );
25043             if ( i == 70 )
25044                 break;
25045         }
25046         Abc_Print( -1, "\n" );
25047         */
25048     }
25049     pAbc->Status = RetValue;
25050     if ( RetValue == -1 )
25051         Abc_Print( 1, "UNDECIDED      " );
25052     else if ( RetValue == 0 )
25053         Abc_Print( 1, "SATISFIABLE    " );
25054     else
25055         Abc_Print( 1, "UNSATISFIABLE  " );
25056     //Abc_Print( -1, "\n" );
25057     Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
25058     return 0;
25059 
25060 usage:
25061     Abc_Print( -2, "usage: sat [-C num] [-I num] [-vh]\n" );
25062     Abc_Print( -2, "\t         solves the combinational miter using SAT solver MiniSat-1.14\n" );
25063     Abc_Print( -2, "\t         derives CNF from the current network and leave it unchanged\n" );
25064     Abc_Print( -2, "\t         (there is also a newer SAT solving command \"dsat\")\n" );
25065     Abc_Print( -2, "\t-C num : limit on the number of conflicts [default = %d]\n",    nConfLimit );
25066     Abc_Print( -2, "\t-I num : limit on the number of inspections [default = %d]\n", nInsLimit );
25067     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
25068     Abc_Print( -2, "\t-h     : print the command usage\n");
25069     return 1;
25070 }
25071 
25072 /**Function*************************************************************
25073 
25074   Synopsis    []
25075 
25076   Description []
25077 
25078   SideEffects []
25079 
25080   SeeAlso     []
25081 
25082 ***********************************************************************/
Abc_CommandDSat(Abc_Frame_t * pAbc,int argc,char ** argv)25083 int Abc_CommandDSat( Abc_Frame_t * pAbc, int argc, char ** argv )
25084 {
25085     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
25086     int c;
25087     int RetValue;
25088     int fAlignPol;
25089     int fAndOuts;
25090     int fNewSolver;
25091     int fSilent;
25092     int fShowPattern;
25093     int fVerbose;
25094     int nConfLimit;
25095     int nLearnedStart;
25096     int nLearnedDelta;
25097     int nLearnedPerce;
25098     int nInsLimit;
25099     abctime clk;
25100 
25101     extern int Abc_NtkDSat( Abc_Ntk_t * pNtk, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, int nLearnedStart, int nLearnedDelta, int nLearnedPerce, int fAlignPol, int fAndOuts, int fNewSolver, int fVerbose );
25102     // set defaults
25103     fAlignPol  = 0;
25104     fAndOuts   = 0;
25105     fNewSolver = 0;
25106     fSilent    = 0;
25107     fShowPattern = 0;
25108     fVerbose   = 0;
25109     nConfLimit = 0;
25110     nInsLimit  = 0;
25111     nLearnedStart = 0;
25112     nLearnedDelta = 0;
25113     nLearnedPerce = 0;
25114     Extra_UtilGetoptReset();
25115     while ( ( c = Extra_UtilGetopt( argc, argv, "CILDEpansvwh" ) ) != EOF )
25116     {
25117         switch ( c )
25118         {
25119         case 'C':
25120             if ( globalUtilOptind >= argc )
25121             {
25122                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
25123                 goto usage;
25124             }
25125             nConfLimit = atoi(argv[globalUtilOptind]);
25126             globalUtilOptind++;
25127             if ( nConfLimit < 0 )
25128                 goto usage;
25129             break;
25130         case 'I':
25131             if ( globalUtilOptind >= argc )
25132             {
25133                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
25134                 goto usage;
25135             }
25136             nInsLimit = atoi(argv[globalUtilOptind]);
25137             globalUtilOptind++;
25138             if ( nInsLimit < 0 )
25139                 goto usage;
25140             break;
25141         case 'L':
25142             if ( globalUtilOptind >= argc )
25143             {
25144                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
25145                 goto usage;
25146             }
25147             nLearnedStart = atoi(argv[globalUtilOptind]);
25148             globalUtilOptind++;
25149             if ( nLearnedStart < 0 )
25150                 goto usage;
25151             break;
25152         case 'D':
25153             if ( globalUtilOptind >= argc )
25154             {
25155                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
25156                 goto usage;
25157             }
25158             nLearnedDelta = atoi(argv[globalUtilOptind]);
25159             globalUtilOptind++;
25160             if ( nLearnedDelta < 0 )
25161                 goto usage;
25162             break;
25163         case 'E':
25164             if ( globalUtilOptind >= argc )
25165             {
25166                 Abc_Print( -1, "Command line switch \"-E\" should be followed by an integer.\n" );
25167                 goto usage;
25168             }
25169             nLearnedPerce = atoi(argv[globalUtilOptind]);
25170             globalUtilOptind++;
25171             if ( nLearnedPerce < 0 )
25172                 goto usage;
25173             break;
25174         case 'p':
25175             fAlignPol ^= 1;
25176             break;
25177         case 'a':
25178             fAndOuts ^= 1;
25179             break;
25180         case 'n':
25181             fNewSolver ^= 1;
25182             break;
25183         case 's':
25184             fSilent ^= 1;
25185             break;
25186         case 'v':
25187             fVerbose ^= 1;
25188             break;
25189         case 'w':
25190             fShowPattern ^= 1;
25191             break;
25192         case 'h':
25193             goto usage;
25194         default:
25195             goto usage;
25196         }
25197     }
25198 
25199     if ( argc == globalUtilOptind + 1 )
25200     {
25201         int * pModel = NULL;
25202         extern int Cnf_DataSolveFromFile( char * pFileName, int nConfLimit, int nLearnedStart, int nLearnedDelta, int nLearnedPerce, int fVerbose, int fShowPattern, int ** ppModel, int nPis );
25203         // get the input file name
25204         char * pFileName = argv[globalUtilOptind];
25205         FILE * pFile = fopen( pFileName, "rb" );
25206         if ( pFile == NULL )
25207         {
25208             printf( "Cannot open file \"%s\" for writing.\n", pFileName );
25209             return 0;
25210         }
25211         fclose( pFile );
25212         Cnf_DataSolveFromFile( pFileName, nConfLimit, nLearnedStart, nLearnedDelta, nLearnedPerce, fVerbose, fShowPattern, &pModel, pNtk ? Abc_NtkPiNum(pNtk) : 0 );
25213         if ( pModel && pNtk )
25214         {
25215             int * pSimInfo = Abc_NtkVerifySimulatePattern( pNtk, pModel );
25216             if ( pSimInfo[0] != 1 )
25217                 Abc_Print( 1, "ERROR in mapping PIs into SAT vars: Generated CEX is invalid.\n" );
25218             ABC_FREE( pSimInfo );
25219             pAbc->pCex = Abc_CexCreate( 0, Abc_NtkPiNum(pNtk), pModel, 0, 0, 0 );
25220         }
25221         ABC_FREE( pModel );
25222         return 0;
25223     }
25224     if ( pNtk == NULL )
25225     {
25226         Abc_Print( -1, "Empty network.\n" );
25227         return 1;
25228     }
25229     if ( Abc_NtkLatchNum(pNtk) > 0 )
25230     {
25231         Abc_Print( -1, "Currently can only solve the miter for combinational circuits.\n" );
25232         return 0;
25233     }
25234 
25235     if ( Abc_NtkPoNum(pNtk) != 1 )
25236     {
25237         Abc_Print( -1, "Currently expects a single-output miter.\n" );
25238         return 0;
25239     }
25240 
25241     if ( !Abc_NtkIsStrash(pNtk) )
25242     {
25243         Abc_Print( -1, "Currently only works for structurally hashed circuits.\n" );
25244         return 0;
25245     }
25246     clk = Abc_Clock();
25247     RetValue = Abc_NtkDSat( pNtk, (ABC_INT64_T)nConfLimit, (ABC_INT64_T)nInsLimit, nLearnedStart, nLearnedDelta, nLearnedPerce, fAlignPol, fAndOuts, fNewSolver, fVerbose );
25248     // verify that the pattern is correct
25249     if ( RetValue == 0 && Abc_NtkPoNum(pNtk) == 1 )
25250     {
25251         int * pSimInfo = Abc_NtkVerifySimulatePattern( pNtk, pNtk->pModel );
25252         if ( pSimInfo[0] != 1 )
25253             Abc_Print( 1, "ERROR in Abc_NtkMiterSat(): Generated counter example is invalid.\n" );
25254         ABC_FREE( pSimInfo );
25255         pAbc->pCex = Abc_CexCreate( 0, Abc_NtkPiNum(pNtk), pNtk->pModel, 0, 0, 0 );
25256     }
25257     pAbc->Status = RetValue;
25258     if ( !fSilent )
25259     {
25260         if ( RetValue == -1 )
25261             Abc_Print( 1, "UNDECIDED      " );
25262         else if ( RetValue == 0 )
25263             Abc_Print( 1, "SATISFIABLE    " );
25264         else
25265             Abc_Print( 1, "UNSATISFIABLE  " );
25266         Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
25267     }
25268     return 0;
25269 
25270 usage:
25271     Abc_Print( -2, "usage: dsat [-CILDE num] [-pansvh]\n" );
25272     Abc_Print( -2, "\t         solves the combinational miter using SAT solver MiniSat-1.14\n" );
25273     Abc_Print( -2, "\t         derives CNF from the current network and leaves it unchanged\n" );
25274     Abc_Print( -2, "\t-C num : limit on the number of conflicts [default = %d]\n",    nConfLimit );
25275     Abc_Print( -2, "\t-I num : limit on the number of inspections [default = %d]\n", nInsLimit );
25276     Abc_Print( -2, "\t-L num : starting value for learned clause removal [default = %d]\n", nLearnedStart );
25277     Abc_Print( -2, "\t-D num : delta value for learned clause removal [default = %d]\n", nLearnedDelta );
25278     Abc_Print( -2, "\t-E num : ratio percentage for learned clause removal [default = %d]\n", nLearnedPerce );
25279     Abc_Print( -2, "\t-p     : align polarity of SAT variables [default = %s]\n", fAlignPol? "yes": "no" );
25280     Abc_Print( -2, "\t-a     : toggle ANDing/ORing of miter outputs [default = %s]\n", fAndOuts? "ANDing": "ORing" );
25281     Abc_Print( -2, "\t-n     : toggle using new solver [default = %s]\n", fNewSolver? "yes": "no" );
25282     Abc_Print( -2, "\t-s     : enable silent computation (no reporting) [default = %s]\n", fSilent? "yes": "no" );
25283     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
25284     Abc_Print( -2, "\t-h     : print the command usage\n");
25285     return 1;
25286 }
25287 
25288 /**Function*************************************************************
25289 
25290   Synopsis    []
25291 
25292   Description []
25293 
25294   SideEffects []
25295 
25296   SeeAlso     []
25297 
25298 ***********************************************************************/
Abc_CommandXSat(Abc_Frame_t * pAbc,int argc,char ** argv)25299 int Abc_CommandXSat( Abc_Frame_t * pAbc, int argc, char ** argv )
25300 {
25301     abctime clk;
25302     int c;
25303     int fVerbose   = 0;
25304     int nConfLimit = 0;
25305     int nInsLimit  = 0;
25306     int nLearnedStart = 0;
25307     int nLearnedDelta = 0;
25308     int nLearnedPerce = 0;
25309     Extra_UtilGetoptReset();
25310     while ( ( c = Extra_UtilGetopt( argc, argv, "CILDEhv" ) ) != EOF )
25311     {
25312         switch ( c )
25313         {
25314         case 'C':
25315             if ( globalUtilOptind >= argc )
25316             {
25317                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
25318                 goto usage;
25319             }
25320             nConfLimit = atoi(argv[globalUtilOptind]);
25321             globalUtilOptind++;
25322             if ( nConfLimit < 0 )
25323                 goto usage;
25324             break;
25325         case 'I':
25326             if ( globalUtilOptind >= argc )
25327             {
25328                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
25329                 goto usage;
25330             }
25331             nInsLimit = atoi(argv[globalUtilOptind]);
25332             globalUtilOptind++;
25333             if ( nInsLimit < 0 )
25334                 goto usage;
25335             break;
25336         case 'L':
25337             if ( globalUtilOptind >= argc )
25338             {
25339                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
25340                 goto usage;
25341             }
25342             nLearnedStart = atoi(argv[globalUtilOptind]);
25343             globalUtilOptind++;
25344             if ( nLearnedStart < 0 )
25345                 goto usage;
25346             break;
25347         case 'D':
25348             if ( globalUtilOptind >= argc )
25349             {
25350                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
25351                 goto usage;
25352             }
25353             nLearnedDelta = atoi(argv[globalUtilOptind]);
25354             globalUtilOptind++;
25355             if ( nLearnedDelta < 0 )
25356                 goto usage;
25357             break;
25358         case 'E':
25359             if ( globalUtilOptind >= argc )
25360             {
25361                 Abc_Print( -1, "Command line switch \"-E\" should be followed by an integer.\n" );
25362                 goto usage;
25363             }
25364             nLearnedPerce = atoi(argv[globalUtilOptind]);
25365             globalUtilOptind++;
25366             if ( nLearnedPerce < 0 )
25367                 goto usage;
25368             break;
25369         case 'h':
25370             goto usage;
25371         case 'v':
25372             fVerbose ^= 1;
25373             break;
25374 
25375         default:
25376             goto usage;
25377         }
25378     }
25379 
25380     if ( argc == globalUtilOptind + 1 )
25381     {
25382         char * pFileName = argv[globalUtilOptind];
25383         xSAT_Solver_t * p;
25384         int status;
25385 
25386         FILE * pFile = fopen( pFileName, "rb" );
25387         if ( pFile == NULL )
25388         {
25389             printf( "Cannot open file \"%s\" for writing.\n", pFileName );
25390             return 0;
25391         }
25392         xSAT_SolverParseDimacs( pFile, &p );
25393 
25394         clk = Abc_Clock();
25395         status = xSAT_SolverSolve( p );
25396         fclose( pFile );
25397 
25398         xSAT_SolverPrintStats( p );
25399         if ( status == 0 )
25400             Abc_Print( 1, "UNDECIDED      " );
25401         else if ( status == 1 )
25402             Abc_Print( 1, "SATISFIABLE    " );
25403         else
25404             Abc_Print( 1, "UNSATISFIABLE  " );
25405 
25406         Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
25407 
25408         xSAT_SolverDestroy( p );
25409         return 0;
25410     }
25411 
25412 usage:
25413     Abc_Print( -2, "usage: xsat [-CILDE num] [-hv]<file>.cnf\n" );
25414     Abc_Print( -2, "\t         solves the combinational miter using SAT solver MiniSat-1.14\n" );
25415     Abc_Print( -2, "\t         derives CNF from the current network and leaves it unchanged\n" );
25416     Abc_Print( -2, "\t-C num : limit on the number of conflicts [default = %d]\n",    nConfLimit );
25417     Abc_Print( -2, "\t-I num : limit on the number of inspections [default = %d]\n", nInsLimit );
25418     Abc_Print( -2, "\t-L num : starting value for learned clause removal [default = %d]\n", nLearnedStart );
25419     Abc_Print( -2, "\t-D num : delta value for learned clause removal [default = %d]\n", nLearnedDelta );
25420     Abc_Print( -2, "\t-E num : ratio percentage for learned clause removal [default = %d]\n", nLearnedPerce );
25421     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
25422     Abc_Print( -2, "\t-h     : print the command usage\n");
25423     return 1;
25424 }
25425 
25426 /**Function*************************************************************
25427 
25428   Synopsis    []
25429 
25430   Description []
25431 
25432   SideEffects []
25433 
25434   SeeAlso     []
25435 
25436 ***********************************************************************/
Abc_CommandSatoko(Abc_Frame_t * pAbc,int argc,char ** argv)25437 int Abc_CommandSatoko( Abc_Frame_t * pAbc, int argc, char ** argv )
25438 {
25439     extern satoko_opts_t * Cmd_DeriveOptionFromSettings( int argc, char ** argv );
25440 
25441     // create default options
25442     satoko_opts_t opts, * popts;
25443     satoko_default_opts(&opts);
25444 
25445     // override default options
25446     popts = Cmd_DeriveOptionFromSettings( argc, argv );
25447     if ( popts == NULL )
25448         goto usage;
25449     memcpy( &opts, popts, sizeof(satoko_opts_t) );
25450     ABC_FREE( popts );
25451 
25452     if ( argc == globalUtilOptind + 1 )
25453     {
25454         abctime clk;
25455         char * pFileName = argv[globalUtilOptind];
25456         satoko_t * p;
25457         int status;
25458 
25459         status = satoko_parse_dimacs( pFileName, &p );
25460         satoko_configure(p, &opts);
25461 
25462         clk = Abc_Clock();
25463         if ( status == SATOKO_OK )
25464             status = satoko_solve( p );
25465 
25466         if ( status == SATOKO_UNDEC )
25467             Abc_Print( 1, "UNDECIDED      " );
25468         else if ( status == SATOKO_SAT )
25469             Abc_Print( 1, "SATISFIABLE    " );
25470         else
25471             Abc_Print( 1, "UNSATISFIABLE  " );
25472 
25473         Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
25474 
25475         satoko_destroy( p );
25476         return 0;
25477     }
25478 
25479 usage:
25480 #ifdef SATOKO_ACT_VAR_FIXED
25481     Abc_Print( -2, "usage: satoko [-CPDEFGHIJKLMNOQRSTU num] [-hv]<file>.cnf\n" );
25482 #else
25483     Abc_Print( -2, "usage: satoko [-CPDEFGHIJKLMNOQRS num] [-hv]<file>.cnf\n" );
25484 #endif
25485     Abc_Print( -2, "\t-C num : limit on the number of conflicts [default = %d]\n", opts.conf_limit );
25486     Abc_Print( -2, "\t-P num : limit on the number of propagations [default = %d]\n", opts.conf_limit );
25487     Abc_Print( -2, "\n\tConstants used for restart heuristic:\n");
25488     Abc_Print( -2, "\t-D num : Constant value used by restart heuristics in forcing restarts [default = %f]\n", opts.f_rst );
25489     Abc_Print( -2, "\t-E num : Constant value used by restart heuristics in  blocking restarts [default = %f]\n", opts.b_rst );
25490     Abc_Print( -2, "\t-F num : Lower bound n.of conflicts for start blocking restarts [default = %d]\n", opts.fst_block_rst );
25491     Abc_Print( -2, "\t-G num : Size of the moving avarege queue for LBD (force restart) [default = %d]\n", opts.sz_lbd_bqueue );
25492     Abc_Print( -2, "\t-H num : Size of the moving avarege queue for Trail size (block restart) [default = %d]\n", opts.sz_trail_bqueue );
25493     Abc_Print( -2, "\n\tConstants used for clause database reduction heuristic:\n");
25494     Abc_Print( -2, "\t-I num : N.of conflicts before first clause databese reduction [default = %d]\n", opts.n_conf_fst_reduce );
25495     Abc_Print( -2, "\t-J num : Increment to reduce [default = %d]\n", opts.inc_reduce );
25496     Abc_Print( -2, "\t-K num : Special increment to reduce [default = %d]\n", opts.inc_special_reduce );
25497     Abc_Print( -2, "\t-L num : Protecs clauses from deletion for one turn if its LBD is lower [default = %d]\n", opts.lbd_freeze_clause );
25498     Abc_Print( -2, "\t-M num : Percentage of learned clauses to remove [default = %d]\n", ( int )( 100 * opts.learnt_ratio ) );
25499     Abc_Print( -2, "\t-N num : Max percentage of garbage in clause database [default = %d]\n", ( int )( 100 * opts.garbage_max_ratio ) );
25500     Abc_Print( -2, "\n\tConstants used for binary resolution (clause minimization):\n");
25501     Abc_Print( -2, "\t-O num : Max clause size for binary resolution [default = %d]\n", opts.clause_max_sz_bin_resol );
25502     Abc_Print( -2, "\t-Q num : Min clause LBD for binary resolution [default = %d]\n", opts.clause_min_lbd_bin_resol );
25503     Abc_Print( -2, "\n\tConstants used for branching (VSIDS heuristic):\n");
25504     Abc_Print( -2, "\t-R num : Clause activity decay factor (when using float clause activity) [default = %f]\n", opts.clause_decay );
25505     Abc_Print( -2, "\t-S num : Varibale activity decay factor [default = %f]\n", opts.var_decay );
25506 #ifdef SATOKO_ACT_VAR_FIXED
25507     Abc_Print( -2, "\t-T num : Variable activity limit valeu [default = 0x%08X]\n", opts.var_act_limit );
25508     Abc_Print( -2, "\t-U num : Variable activity re-scale factor [default = 0x%08X]\n", opts.var_act_rescale );
25509 #endif
25510     Abc_Print( -2, "\n\t-v     : prints verbose information [default = %s]\n", opts.verbose? "yes": "no" );
25511     Abc_Print( -2, "\t-h     : print the command usage\n");
25512     return 1;
25513 }
25514 
25515 
25516 /**Function*************************************************************
25517 
25518   Synopsis    []
25519 
25520   Description []
25521 
25522   SideEffects []
25523 
25524   SeeAlso     []
25525 
25526 ***********************************************************************/
Abc_CommandAbc9Satoko(Abc_Frame_t * pAbc,int argc,char ** argv)25527 int Abc_CommandAbc9Satoko( Abc_Frame_t * pAbc, int argc, char ** argv )
25528 {
25529     extern void Gia_ManSatokoDimacs( char * pFileName, satoko_opts_t * opts );
25530     extern void Gia_ManSatokoCall( Gia_Man_t * p, satoko_opts_t * opts, int fSplit, int fIncrem );
25531     int c, fSplit = 0, fIncrem = 0;
25532 
25533     satoko_opts_t opts;
25534     satoko_default_opts(&opts);
25535     Extra_UtilGetoptReset();
25536     while ( ( c = Extra_UtilGetopt( argc, argv, "Csivh" ) ) != EOF )
25537     {
25538         switch ( c )
25539         {
25540         case 'C':
25541             if ( globalUtilOptind >= argc )
25542             {
25543                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
25544                 goto usage;
25545             }
25546             opts.conf_limit = atoi(argv[globalUtilOptind]);
25547             globalUtilOptind++;
25548             if ( opts.conf_limit < 0 )
25549                 goto usage;
25550             break;
25551         case 's':
25552             fSplit ^= 1;
25553             break;
25554         case 'i':
25555             fIncrem ^= 1;
25556             break;
25557         case 'v':
25558             opts.verbose ^= 1;
25559             break;
25560         case 'h':
25561             goto usage;
25562 
25563         default:
25564             goto usage;
25565         }
25566     }
25567     if ( argc == globalUtilOptind + 1 )
25568     {
25569         Gia_ManSatokoDimacs( argv[globalUtilOptind], &opts );
25570         return 0;
25571     }
25572     if ( pAbc->pGia == NULL )
25573     {
25574         Abc_Print( -1, "Abc_CommandAbc9Satoko(): There is no AIG.\n" );
25575         return 1;
25576     }
25577     Gia_ManSatokoCall( pAbc->pGia, &opts, fSplit, fIncrem );
25578     return 0;
25579 
25580 usage:
25581     Abc_Print( -2, "usage: &satoko [-C num] [-sivh] <file.cnf>\n" );
25582     Abc_Print( -2, "\t             run Satoko by Bruno Schmitt\n" );
25583     Abc_Print( -2, "\t-C num     : limit on the number of conflicts [default = %d]\n", opts.conf_limit );
25584     Abc_Print( -2, "\t-s         : split multi-output miter into individual outputs [default = %s]\n", fSplit? "yes": "no" );
25585     Abc_Print( -2, "\t-i         : split multi-output miter and solve incrementally [default = %s]\n", fIncrem? "yes": "no" );
25586     Abc_Print( -2, "\t-v         : prints verbose information [default = %s]\n", opts.verbose? "yes": "no" );
25587     Abc_Print( -2, "\t<file.cnf> : (optional) CNF file to solve\n");
25588     Abc_Print( -2, "\t-h         : print the command usage\n");
25589     return 1;
25590 }
25591 
25592 /**Function*************************************************************
25593 
25594   Synopsis    []
25595 
25596   Description []
25597 
25598   SideEffects []
25599 
25600   SeeAlso     []
25601 
25602 ***********************************************************************/
Abc_CommandAbc9Sat3(Abc_Frame_t * pAbc,int argc,char ** argv)25603 int Abc_CommandAbc9Sat3( Abc_Frame_t * pAbc, int argc, char ** argv )
25604 {
25605     extern void Gia_ManSat3Call( Gia_Man_t * p, int fSplit );
25606     int c, fSplit = 0, fIncrem = 0;
25607 
25608     satoko_opts_t opts;
25609     satoko_default_opts(&opts);
25610     Extra_UtilGetoptReset();
25611     while ( ( c = Extra_UtilGetopt( argc, argv, "Csivh" ) ) != EOF )
25612     {
25613         switch ( c )
25614         {
25615         case 'C':
25616             if ( globalUtilOptind >= argc )
25617             {
25618                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
25619                 goto usage;
25620             }
25621             opts.conf_limit = atoi(argv[globalUtilOptind]);
25622             globalUtilOptind++;
25623             if ( opts.conf_limit < 0 )
25624                 goto usage;
25625             break;
25626         case 's':
25627             fSplit ^= 1;
25628             break;
25629         case 'i':
25630             fIncrem ^= 1;
25631             break;
25632         case 'v':
25633             opts.verbose ^= 1;
25634             break;
25635         case 'h':
25636             goto usage;
25637 
25638         default:
25639             goto usage;
25640         }
25641     }
25642     if ( pAbc->pGia == NULL )
25643     {
25644         Abc_Print( -1, "Abc_CommandAbc9Sat3(): There is no AIG.\n" );
25645         return 1;
25646     }
25647     Gia_ManSat3Call( pAbc->pGia, fSplit );
25648     return 0;
25649 
25650 usage:
25651     Abc_Print( -2, "usage: &sat3 [-C num] [-sivh]\n" );
25652     Abc_Print( -2, "\t-C num : limit on the number of conflicts [default = %d]\n", opts.conf_limit );
25653     Abc_Print( -2, "\t-s     : split multi-output miter into individual outputs [default = %s]\n", fSplit? "yes": "no" );
25654     Abc_Print( -2, "\t-i     : split multi-output miter and solve incrementally [default = %s]\n", fIncrem? "yes": "no" );
25655     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", opts.verbose? "yes": "no" );
25656     Abc_Print( -2, "\t-h     : print the command usage\n");
25657     return 1;
25658 }
25659 
25660 /**Function*************************************************************
25661 
25662   Synopsis    []
25663 
25664   Description []
25665 
25666   SideEffects []
25667 
25668   SeeAlso     []
25669 
25670 ***********************************************************************/
Abc_CommandPSat(Abc_Frame_t * pAbc,int argc,char ** argv)25671 int Abc_CommandPSat( Abc_Frame_t * pAbc, int argc, char ** argv )
25672 {
25673     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
25674     int RetValue;
25675     int c;
25676     int nAlgo;
25677     int nPartSize;
25678     int nConfPart;
25679     int nConfTotal;
25680     int fAlignPol;
25681     int fSynthesize;
25682     int fVerbose;
25683     abctime clk;
25684 
25685     extern int Abc_NtkPartitionedSat( Abc_Ntk_t * pNtk, int nAlgo, int nPartSize, int nConfPart, int nConfTotal, int fAlignPol, int fSynthesize, int fVerbose );
25686     // set defaults
25687     nAlgo       =        0;
25688     nPartSize   =    10000;
25689     nConfPart   =        0;
25690     nConfTotal  =  1000000;
25691     fAlignPol   =        1;
25692     fSynthesize =        0;
25693     fVerbose    =        1;
25694     Extra_UtilGetoptReset();
25695     while ( ( c = Extra_UtilGetopt( argc, argv, "APCpsvh" ) ) != EOF )
25696     {
25697         switch ( c )
25698         {
25699         case 'A':
25700             if ( globalUtilOptind >= argc )
25701             {
25702                 Abc_Print( -1, "Command line switch \"-A\" should be followed by an integer.\n" );
25703                 goto usage;
25704             }
25705             nAlgo = atoi(argv[globalUtilOptind]);
25706             globalUtilOptind++;
25707             if ( nAlgo < 0 )
25708                 goto usage;
25709             break;
25710         case 'P':
25711             if ( globalUtilOptind >= argc )
25712             {
25713                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
25714                 goto usage;
25715             }
25716             nPartSize = atoi(argv[globalUtilOptind]);
25717             globalUtilOptind++;
25718             if ( nPartSize < 0 )
25719                 goto usage;
25720             break;
25721         case 'C':
25722             if ( globalUtilOptind >= argc )
25723             {
25724                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
25725                 goto usage;
25726             }
25727             nConfTotal = atoi(argv[globalUtilOptind]);
25728             globalUtilOptind++;
25729             if ( nConfTotal < 0 )
25730                 goto usage;
25731             break;
25732         case 'p':
25733             fAlignPol ^= 1;
25734             break;
25735         case 's':
25736             fSynthesize ^= 1;
25737             break;
25738         case 'v':
25739             fVerbose ^= 1;
25740             break;
25741         case 'h':
25742             goto usage;
25743         default:
25744             goto usage;
25745         }
25746     }
25747 
25748     if ( pNtk == NULL )
25749     {
25750         Abc_Print( -1, "Empty network.\n" );
25751         return 1;
25752     }
25753     if ( Abc_NtkLatchNum(pNtk) > 0 )
25754     {
25755         Abc_Print( -1, "Currently can only solve the miter for combinational circuits.\n" );
25756         return 0;
25757     }
25758     if ( !Abc_NtkIsStrash(pNtk) )
25759     {
25760         Abc_Print( -1, "Currently only works for structurally hashed circuits.\n" );
25761         return 0;
25762     }
25763 
25764     clk = Abc_Clock();
25765     RetValue = Abc_NtkPartitionedSat( pNtk, nAlgo, nPartSize, nConfPart, nConfTotal, fAlignPol, fSynthesize, fVerbose );
25766     // verify that the pattern is correct
25767     if ( RetValue == 0 && Abc_NtkPoNum(pNtk) == 1 )
25768     {
25769         //int i;
25770         //Abc_Obj_t * pObj;
25771         int * pSimInfo = Abc_NtkVerifySimulatePattern( pNtk, pNtk->pModel );
25772         if ( pSimInfo[0] != 1 )
25773             Abc_Print( 1, "ERROR in Abc_NtkMiterSat(): Generated counter example is invalid.\n" );
25774         ABC_FREE( pSimInfo );
25775         /*
25776         // print model
25777         Abc_NtkForEachPi( pNtk, pObj, i )
25778         {
25779             Abc_Print( -1, "%d", (int)(pNtk->pModel[i] > 0) );
25780             if ( i == 70 )
25781                 break;
25782         }
25783         Abc_Print( -1, "\n" );
25784         */
25785     }
25786 
25787     if ( RetValue == -1 )
25788         Abc_Print( 1, "UNDECIDED      " );
25789     else if ( RetValue == 0 )
25790         Abc_Print( 1, "SATISFIABLE    " );
25791     else
25792         Abc_Print( 1, "UNSATISFIABLE  " );
25793     //Abc_Print( -1, "\n" );
25794     Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
25795     return 0;
25796 
25797 usage:
25798     Abc_Print( -2, "usage: psat [-APC num] [-psvh]\n" );
25799     Abc_Print( -2, "\t         solves the combinational miter using partitioning\n" );
25800     Abc_Print( -2, "\t         (derives CNF from the current network and leave it unchanged)\n" );
25801     Abc_Print( -2, "\t         for multi-output miters, tries to prove that the AND of POs is always 0\n" );
25802     Abc_Print( -2, "\t         (if POs should be ORed instead of ANDed, use command \"orpos\")\n" );
25803     Abc_Print( -2, "\t-A num : partitioning algorithm [default = %d]\n", nAlgo );
25804     Abc_Print( -2, "\t         0 : no partitioning\n" );
25805     Abc_Print( -2, "\t         1 : partitioning by level\n" );
25806     Abc_Print( -2, "\t         2 : DFS post-order\n" );
25807     Abc_Print( -2, "\t         3 : DFS pre-order\n" );
25808     Abc_Print( -2, "\t         4 : bit-slicing\n" );
25809     Abc_Print( -2, "\t         partitions are ordered by level (high level first)\n" );
25810     Abc_Print( -2, "\t-P num : limit on the partition size [default = %d]\n", nPartSize );
25811     Abc_Print( -2, "\t-C num : limit on the number of conflicts [default = %d]\n", nConfTotal );
25812     Abc_Print( -2, "\t-p     : align polarity of SAT variables [default = %s]\n", fAlignPol? "yes": "no" );
25813     Abc_Print( -2, "\t-s     : apply logic synthesis to each partition [default = %s]\n", fSynthesize? "yes": "no" );
25814     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
25815     Abc_Print( -2, "\t-h     : print the command usage\n");
25816     return 1;
25817 }
25818 
25819 /**Function*************************************************************
25820 
25821   Synopsis    []
25822 
25823   Description []
25824 
25825   SideEffects []
25826 
25827   SeeAlso     []
25828 
25829 ***********************************************************************/
Abc_CommandProve(Abc_Frame_t * pAbc,int argc,char ** argv)25830 int Abc_CommandProve( Abc_Frame_t * pAbc, int argc, char ** argv )
25831 {
25832     Abc_Ntk_t * pNtk, * pNtkTemp;
25833     Prove_Params_t Params, * pParams = &Params;
25834     int c, RetValue;
25835     abctime clk;
25836 
25837     pNtk = Abc_FrameReadNtk(pAbc);
25838     // set defaults
25839     Prove_ParamsSetDefault( pParams );
25840     Extra_UtilGetoptReset();
25841     while ( ( c = Extra_UtilGetopt( argc, argv, "NCFGLIrfbvh" ) ) != EOF )
25842     {
25843         switch ( c )
25844         {
25845         case 'N':
25846             if ( globalUtilOptind >= argc )
25847             {
25848                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
25849                 goto usage;
25850             }
25851             pParams->nItersMax = atoi(argv[globalUtilOptind]);
25852             globalUtilOptind++;
25853             if ( pParams->nItersMax < 0 )
25854                 goto usage;
25855             break;
25856         case 'C':
25857             if ( globalUtilOptind >= argc )
25858             {
25859                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
25860                 goto usage;
25861             }
25862             pParams->nMiteringLimitStart = atoi(argv[globalUtilOptind]);
25863             globalUtilOptind++;
25864             if ( pParams->nMiteringLimitStart < 0 )
25865                 goto usage;
25866             break;
25867         case 'F':
25868             if ( globalUtilOptind >= argc )
25869             {
25870                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
25871                 goto usage;
25872             }
25873             pParams->nFraigingLimitStart = atoi(argv[globalUtilOptind]);
25874             globalUtilOptind++;
25875             if ( pParams->nFraigingLimitStart < 0 )
25876                 goto usage;
25877             break;
25878         case 'G':
25879             if ( globalUtilOptind >= argc )
25880             {
25881                 Abc_Print( -1, "Command line switch \"-G\" should be followed by an integer.\n" );
25882                 goto usage;
25883             }
25884             pParams->nFraigingLimitMulti = (float)atoi(argv[globalUtilOptind]);
25885             globalUtilOptind++;
25886             if ( pParams->nFraigingLimitMulti < 0 )
25887                 goto usage;
25888             break;
25889         case 'L':
25890             if ( globalUtilOptind >= argc )
25891             {
25892                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
25893                 goto usage;
25894             }
25895             pParams->nMiteringLimitLast = atoi(argv[globalUtilOptind]);
25896             globalUtilOptind++;
25897             if ( pParams->nMiteringLimitLast < 0 )
25898                 goto usage;
25899             break;
25900         case 'I':
25901             if ( globalUtilOptind >= argc )
25902             {
25903                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
25904                 goto usage;
25905             }
25906             pParams->nTotalInspectLimit = atoi(argv[globalUtilOptind]);
25907             globalUtilOptind++;
25908             if ( pParams->nTotalInspectLimit < 0 )
25909                 goto usage;
25910             break;
25911         case 'r':
25912             pParams->fUseRewriting ^= 1;
25913             break;
25914         case 'f':
25915             pParams->fUseFraiging ^= 1;
25916             break;
25917         case 'b':
25918             pParams->fUseBdds ^= 1;
25919             break;
25920         case 'v':
25921             pParams->fVerbose ^= 1;
25922             break;
25923         case 'h':
25924             goto usage;
25925         default:
25926             goto usage;
25927         }
25928     }
25929 
25930     if ( pNtk == NULL )
25931     {
25932         Abc_Print( -1, "Empty network.\n" );
25933         return 1;
25934     }
25935     if ( Abc_NtkLatchNum(pNtk) > 0 )
25936     {
25937         Abc_Print( -1, "Currently can only solve the miter for combinational circuits.\n" );
25938         return 0;
25939     }
25940     if ( Abc_NtkCoNum(pNtk) != 1 )
25941     {
25942         Abc_Print( -1, "Currently can only solve the miter with one output.\n" );
25943         return 0;
25944     }
25945     clk = Abc_Clock();
25946 
25947     if ( Abc_NtkIsStrash(pNtk) )
25948         pNtkTemp = Abc_NtkDup( pNtk );
25949     else
25950         pNtkTemp = Abc_NtkStrash( pNtk, 0, 0, 0 );
25951 
25952     RetValue = Abc_NtkMiterProve( &pNtkTemp, pParams );
25953 
25954     // verify that the pattern is correct
25955     if ( RetValue == 0 )
25956     {
25957         int * pSimInfo = Abc_NtkVerifySimulatePattern( pNtk, pNtkTemp->pModel );
25958         if ( pSimInfo[0] != 1 )
25959             Abc_Print( 1, "ERROR in Abc_NtkMiterProve(): Generated counter-example is invalid.\n" );
25960         ABC_FREE( pSimInfo );
25961     }
25962     pAbc->Status = RetValue;
25963     if ( RetValue == -1 )
25964         Abc_Print( 1, "UNDECIDED      " );
25965     else if ( RetValue == 0 )
25966         Abc_Print( 1, "SATISFIABLE    " );
25967     else
25968         Abc_Print( 1, "UNSATISFIABLE  " );
25969     //Abc_Print( -1, "\n" );
25970 
25971     Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
25972     // replace the current network
25973     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkTemp );
25974     return 0;
25975 
25976 usage:
25977     Abc_Print( -2, "usage: prove [-NCFGLI num] [-rfbvh]\n" );
25978     Abc_Print( -2, "\t         solves combinational miter by rewriting, FRAIGing, and SAT\n" );
25979     Abc_Print( -2, "\t         replaces the current network by the cone modified by rewriting\n" );
25980     Abc_Print( -2, "\t         (there is also newer CEC command \"iprove\")\n" );
25981     Abc_Print( -2, "\t-N num : max number of iterations [default = %d]\n", pParams->nItersMax );
25982     Abc_Print( -2, "\t-C num : max starting number of conflicts in mitering [default = %d]\n", pParams->nMiteringLimitStart );
25983     Abc_Print( -2, "\t-F num : max starting number of conflicts in fraiging [default = %d]\n", pParams->nFraigingLimitStart );
25984     Abc_Print( -2, "\t-G num : multiplicative coefficient for fraiging [default = %d]\n", (int)pParams->nFraigingLimitMulti );
25985     Abc_Print( -2, "\t-L num : max last-gasp number of conflicts in mitering [default = %d]\n", pParams->nMiteringLimitLast );
25986     Abc_Print( -2, "\t-I num : max number of clause inspections in all SAT calls [default = %d]\n", (int)pParams->nTotalInspectLimit );
25987     Abc_Print( -2, "\t-r     : toggle the use of rewriting [default = %s]\n", pParams->fUseRewriting? "yes": "no" );
25988     Abc_Print( -2, "\t-f     : toggle the use of FRAIGing [default = %s]\n", pParams->fUseFraiging? "yes": "no" );
25989     Abc_Print( -2, "\t-b     : toggle the use of BDDs [default = %s]\n", pParams->fUseBdds? "yes": "no" );
25990     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", pParams->fVerbose? "yes": "no" );
25991     Abc_Print( -2, "\t-h     : print the command usage\n");
25992     return 1;
25993 }
25994 
25995 /**Function*************************************************************
25996 
25997   Synopsis    []
25998 
25999   Description []
26000 
26001   SideEffects []
26002 
26003   SeeAlso     []
26004 
26005 ***********************************************************************/
Abc_CommandDebug(Abc_Frame_t * pAbc,int argc,char ** argv)26006 int Abc_CommandDebug( Abc_Frame_t * pAbc, int argc, char ** argv )
26007 {
26008     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
26009     int c;
26010     extern void Abc_NtkAutoDebug( Abc_Ntk_t * pNtk, int (*pFuncError) (Abc_Ntk_t *) );
26011     extern int Abc_NtkRetimeDebug( Abc_Ntk_t * pNtk );
26012     // set defaults
26013     Extra_UtilGetoptReset();
26014     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
26015     {
26016         switch ( c )
26017         {
26018         case 'h':
26019             goto usage;
26020         default:
26021             goto usage;
26022         }
26023     }
26024 
26025     if ( pNtk == NULL )
26026     {
26027         Abc_Print( -1, "Empty network.\n" );
26028         return 1;
26029     }
26030     if ( !Abc_NtkIsLogic(pNtk) )
26031     {
26032         Abc_Print( -1, "This command is applicable to logic networks.\n" );
26033         return 1;
26034     }
26035 
26036     Abc_NtkAutoDebug( pNtk, Abc_NtkRetimeDebug );
26037     return 0;
26038 
26039 usage:
26040     Abc_Print( -2, "usage: debug [-h]\n" );
26041     Abc_Print( -2, "\t        performs automated debugging of the given procedure\n" );
26042     Abc_Print( -2, "\t-h    : print the command usage\n");
26043     return 1;
26044 }
26045 
26046 /**Function*************************************************************
26047 
26048   Synopsis    []
26049 
26050   Description []
26051 
26052   SideEffects []
26053 
26054   SeeAlso     []
26055 
26056 ***********************************************************************/
Abc_CommandEco(Abc_Frame_t * pAbc,int argc,char ** argv)26057 int Abc_CommandEco( Abc_Frame_t * pAbc, int argc, char ** argv )
26058 {
26059     extern void Abc_NtkEco( char * pFileNames[3] );
26060     char * pFileNames[3] = {NULL};  int c;
26061     // set defaults
26062     Extra_UtilGetoptReset();
26063     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
26064     {
26065         switch ( c )
26066         {
26067         case 'h':
26068             goto usage;
26069         default:
26070             goto usage;
26071         }
26072     }
26073     if ( globalUtilOptind + 3 != argc )
26074     {
26075         Abc_Print( -1, "Expecting three file names on the command line.\n" );
26076         return 1;
26077     }
26078     for ( c = 0; c < 3; c++ )
26079         pFileNames[c] = argv[globalUtilOptind+c];
26080     Abc_NtkEco( pFileNames );
26081     return 0;
26082 
26083 usage:
26084     Abc_Print( -2, "usage: eco [-h]\n" );
26085     Abc_Print( -2, "\t        performs experimental ECO computation\n" );
26086     Abc_Print( -2, "\t-h    : print the command usage\n");
26087     return 1;
26088 }
26089 
26090 /**Function*************************************************************
26091 
26092   Synopsis    []
26093 
26094   Description []
26095 
26096   SideEffects []
26097 
26098   SeeAlso     []
26099 
26100 ***********************************************************************/
Abc_CommandBmc(Abc_Frame_t * pAbc,int argc,char ** argv)26101 int Abc_CommandBmc( Abc_Frame_t * pAbc, int argc, char ** argv )
26102 {
26103     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
26104     int c;
26105     int nFrames;
26106     int nSizeMax;
26107     int nBTLimit;
26108     int nBTLimitAll;
26109     int nNodeDelta;
26110     int fRewrite;
26111     int fNewAlgo;
26112     int nCofFanLit;
26113     int fVerbose;
26114     int iFrames;
26115     int fUseSatoko;
26116     char * pLogFileName = NULL;
26117 
26118     extern int Abc_NtkDarBmc( Abc_Ntk_t * pNtk, int nStart, int nFrames, int nSizeMax, int nNodeDelta, int nTimeOut, int nBTLimit, int nBTLimitAll, int fRewrite, int fNewAlgo, int fOrDecomp, int nCofFanLit, int fVerbose, int * piFrames, int fUseSatoko );
26119     // set defaults
26120     nFrames     =       20;
26121     nSizeMax    =   100000;
26122     nBTLimit    =        0;
26123     nBTLimitAll =        0;
26124     nNodeDelta  =     1000;
26125     fRewrite    =        0;
26126     fNewAlgo    =        1;
26127     nCofFanLit  =        0;
26128     fVerbose    =        0;
26129     fUseSatoko  =        0;
26130     Extra_UtilGetoptReset();
26131     while ( ( c = Extra_UtilGetopt( argc, argv, "FNCGDLrsvh" ) ) != EOF )
26132     {
26133         switch ( c )
26134         {
26135         case 'F':
26136             if ( globalUtilOptind >= argc )
26137             {
26138                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
26139                 goto usage;
26140             }
26141             nFrames = atoi(argv[globalUtilOptind]);
26142             globalUtilOptind++;
26143             if ( nFrames < 0 )
26144                 goto usage;
26145             break;
26146         case 'N':
26147             if ( globalUtilOptind >= argc )
26148             {
26149                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
26150                 goto usage;
26151             }
26152             nSizeMax = atoi(argv[globalUtilOptind]);
26153             globalUtilOptind++;
26154             if ( nSizeMax < 0 )
26155                 goto usage;
26156             break;
26157         case 'C':
26158             if ( globalUtilOptind >= argc )
26159             {
26160                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
26161                 goto usage;
26162             }
26163             nBTLimit = atoi(argv[globalUtilOptind]);
26164             globalUtilOptind++;
26165             if ( nBTLimit < 0 )
26166                 goto usage;
26167             break;
26168         case 'G':
26169             if ( globalUtilOptind >= argc )
26170             {
26171                 Abc_Print( -1, "Command line switch \"-G\" should be followed by an integer.\n" );
26172                 goto usage;
26173             }
26174             nBTLimitAll = atoi(argv[globalUtilOptind]);
26175             globalUtilOptind++;
26176             if ( nBTLimitAll < 0 )
26177                 goto usage;
26178             break;
26179         case 'D':
26180             if ( globalUtilOptind >= argc )
26181             {
26182                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
26183                 goto usage;
26184             }
26185             nNodeDelta = atoi(argv[globalUtilOptind]);
26186             globalUtilOptind++;
26187             if ( nNodeDelta < 0 )
26188                 goto usage;
26189             break;
26190 /*
26191         case 'L':
26192             if ( globalUtilOptind >= argc )
26193             {
26194                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
26195                 goto usage;
26196             }
26197             nCofFanLit = atoi(argv[globalUtilOptind]);
26198             globalUtilOptind++;
26199             if ( nCofFanLit < 0 )
26200                 goto usage;
26201             break;
26202 */
26203         case 'L':
26204             if ( globalUtilOptind >= argc )
26205             {
26206                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
26207                 goto usage;
26208             }
26209             pLogFileName = argv[globalUtilOptind];
26210             globalUtilOptind++;
26211             break;
26212         case 'r':
26213             fRewrite ^= 1;
26214             break;
26215         case 'a':
26216             fNewAlgo ^= 1;
26217             break;
26218         case 's':
26219             fUseSatoko ^= 1;
26220             break;
26221         case 'v':
26222             fVerbose ^= 1;
26223             break;
26224         case 'h':
26225             goto usage;
26226         default:
26227             goto usage;
26228         }
26229     }
26230     if ( pNtk == NULL )
26231     {
26232         Abc_Print( -1, "Empty network.\n" );
26233         return 1;
26234     }
26235     if ( !Abc_NtkIsStrash(pNtk) )
26236     {
26237         Abc_Print( -1, "Currently only works for structurally hashed circuits.\n" );
26238         return 0;
26239     }
26240     if ( Abc_NtkLatchNum(pNtk) == 0 )
26241     {
26242         Abc_Print( -1, "Does not work for combinational networks.\n" );
26243         return 0;
26244     }
26245     if ( pAbc->fBatchMode && (pAbc->Status == 0 || pAbc->Status == 1) )
26246     {
26247         Abc_Print( 1, "The miters is already solved; skipping the command.\n" );
26248         return 0;
26249     }
26250     pAbc->Status = Abc_NtkDarBmc( pNtk, 0, nFrames, nSizeMax, nNodeDelta, 0, nBTLimit, nBTLimitAll, fRewrite, fNewAlgo, 0, nCofFanLit, fVerbose, &iFrames, fUseSatoko );
26251     pAbc->nFrames = iFrames;
26252     Abc_FrameReplaceCex( pAbc, &pNtk->pSeqModel );
26253     if ( pLogFileName )
26254         Abc_NtkWriteLogFile( pLogFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, "bmc" );
26255     return 0;
26256 
26257 usage:
26258     Abc_Print( -2, "usage: bmc [-FNC num] [-L file] [-rcsvh]\n" );
26259     Abc_Print( -2, "\t         performs bounded model checking with static unrolling\n" );
26260     Abc_Print( -2, "\t-F num : the number of time frames [default = %d]\n", nFrames );
26261     Abc_Print( -2, "\t-N num : the max number of nodes in the frames [default = %d]\n", nSizeMax );
26262     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", nBTLimit );
26263 //    Abc_Print( -2, "\t-L num : the limit on fanout count of resets/enables to cofactor [default = %d]\n", nCofFanLit );
26264     Abc_Print( -2, "\t-L file: the log file name [default = %s]\n", pLogFileName ? pLogFileName : "no logging" );
26265     Abc_Print( -2, "\t-r     : toggle the use of rewriting [default = %s]\n", fRewrite? "yes": "no" );
26266 //    Abc_Print( -2, "\t-a     : toggle SAT sweeping and SAT solving [default = %s]\n", fNewAlgo? "SAT solving": "SAT sweeping" );
26267     Abc_Print( -2, "\t-s     : toggle using Satoko by Bruno Schmitt [default = %s]\n", fUseSatoko? "yes": "no" );
26268     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
26269     Abc_Print( -2, "\t-h     : print the command usage\n");
26270     return 1;
26271 }
26272 
26273 /**Function*************************************************************
26274 
26275   Synopsis    []
26276 
26277   Description []
26278 
26279   SideEffects []
26280 
26281   SeeAlso     []
26282 
26283 ***********************************************************************/
Abc_CommandBmc2(Abc_Frame_t * pAbc,int argc,char ** argv)26284 int Abc_CommandBmc2( Abc_Frame_t * pAbc, int argc, char ** argv )
26285 {
26286     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
26287     int c;
26288     int nStart;
26289     int nFrames;
26290     int nSizeMax;
26291     int nBTLimit;
26292     int nBTLimitAll;
26293     int nNodeDelta;
26294     int nTimeOut;
26295     int fRewrite;
26296     int fNewAlgo;
26297     int fOrDecomp;
26298     int fVerbose;
26299     int iFrames;
26300     int fUseSatoko;
26301     char * pLogFileName = NULL;
26302 
26303     extern int Abc_NtkDarBmc( Abc_Ntk_t * pNtk, int nStart, int nFrames, int nSizeMax, int nNodeDelta, int nTimeOut, int nBTLimit, int nBTLimitAll, int fRewrite, int fNewAlgo, int fOrDecomp, int nCofFanLit, int fVerbose, int * piFrames, int fUseSatoko );
26304 
26305     // set defaults
26306     nStart      =        0;
26307     nFrames     =        0;
26308     nSizeMax    =   200000;
26309     nBTLimit    =        0;
26310     nBTLimitAll =        0;
26311     nNodeDelta  =     2000;
26312     nTimeOut    =        0;
26313     fRewrite    =        0;
26314     fNewAlgo    =        0;
26315     fOrDecomp   =        0;
26316     fVerbose    =        0;
26317     fUseSatoko  =        0;
26318     Extra_UtilGetoptReset();
26319     while ( ( c = Extra_UtilGetopt( argc, argv, "SFNTCGDLrusvh" ) ) != EOF )
26320     {
26321         switch ( c )
26322         {
26323         case 'S':
26324             if ( globalUtilOptind >= argc )
26325             {
26326                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
26327                 goto usage;
26328             }
26329             nStart = atoi(argv[globalUtilOptind]);
26330             globalUtilOptind++;
26331             if ( nStart < 0 )
26332                 goto usage;
26333             break;
26334         case 'F':
26335             if ( globalUtilOptind >= argc )
26336             {
26337                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
26338                 goto usage;
26339             }
26340             nFrames = atoi(argv[globalUtilOptind]);
26341             globalUtilOptind++;
26342             if ( nFrames < 0 )
26343                 goto usage;
26344             break;
26345         case 'N':
26346             if ( globalUtilOptind >= argc )
26347             {
26348                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
26349                 goto usage;
26350             }
26351             nSizeMax = atoi(argv[globalUtilOptind]);
26352             globalUtilOptind++;
26353             if ( nSizeMax < 0 )
26354                 goto usage;
26355             break;
26356         case 'T':
26357             if ( globalUtilOptind >= argc )
26358             {
26359                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
26360                 goto usage;
26361             }
26362             nTimeOut = atoi(argv[globalUtilOptind]);
26363             globalUtilOptind++;
26364             if ( nTimeOut < 0 )
26365                 goto usage;
26366             break;
26367         case 'C':
26368             if ( globalUtilOptind >= argc )
26369             {
26370                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
26371                 goto usage;
26372             }
26373             nBTLimit = atoi(argv[globalUtilOptind]);
26374             globalUtilOptind++;
26375             if ( nBTLimit < 0 )
26376                 goto usage;
26377             break;
26378         case 'G':
26379             if ( globalUtilOptind >= argc )
26380             {
26381                 Abc_Print( -1, "Command line switch \"-G\" should be followed by an integer.\n" );
26382                 goto usage;
26383             }
26384             nBTLimitAll = atoi(argv[globalUtilOptind]);
26385             globalUtilOptind++;
26386             if ( nBTLimitAll < 0 )
26387                 goto usage;
26388             break;
26389         case 'D':
26390             if ( globalUtilOptind >= argc )
26391             {
26392                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
26393                 goto usage;
26394             }
26395             nNodeDelta = atoi(argv[globalUtilOptind]);
26396             globalUtilOptind++;
26397             if ( nNodeDelta < 0 )
26398                 goto usage;
26399             break;
26400         case 'L':
26401             if ( globalUtilOptind >= argc )
26402             {
26403                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
26404                 goto usage;
26405             }
26406             pLogFileName = argv[globalUtilOptind];
26407             globalUtilOptind++;
26408             break;
26409         case 'r':
26410             fRewrite ^= 1;
26411             break;
26412         case 'a':
26413             fNewAlgo ^= 1;
26414             break;
26415         case 'u':
26416             fOrDecomp ^= 1;
26417             break;
26418         case 's':
26419             fUseSatoko ^= 1;
26420             break;
26421         case 'v':
26422             fVerbose ^= 1;
26423             break;
26424         case 'h':
26425             goto usage;
26426         default:
26427             goto usage;
26428         }
26429     }
26430     if ( pNtk == NULL )
26431     {
26432         Abc_Print( -1, "Empty network.\n" );
26433         return 1;
26434     }
26435     if ( !Abc_NtkIsStrash(pNtk) )
26436     {
26437         Abc_Print( -1, "Currently only works for structurally hashed circuits.\n" );
26438         return 0;
26439     }
26440     if ( Abc_NtkLatchNum(pNtk) == 0 )
26441     {
26442         Abc_Print( -1, "Does not work for combinational networks.\n" );
26443         return 0;
26444     }
26445     if ( pAbc->fBatchMode && (pAbc->Status == 0 || pAbc->Status == 1) )
26446     {
26447         Abc_Print( 1, "The miters is already solved; skipping the command.\n" );
26448         return 0;
26449     }
26450     pAbc->Status = Abc_NtkDarBmc( pNtk, nStart, nFrames, nSizeMax, nNodeDelta, nTimeOut, nBTLimit, nBTLimitAll, fRewrite, fNewAlgo, fOrDecomp, 0, fVerbose, &iFrames, fUseSatoko );
26451     pAbc->nFrames = iFrames;
26452     Abc_FrameReplaceCex( pAbc, &pNtk->pSeqModel );
26453     if ( pLogFileName )
26454         Abc_NtkWriteLogFile( pLogFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, "bmc2" );
26455     return 0;
26456 
26457 usage:
26458     Abc_Print( -2, "usage: bmc2 [-SFTCGD num] [-L file] [-usvh]\n" );
26459     Abc_Print( -2, "\t         performs bounded model checking with dynamic unrolling\n" );
26460     Abc_Print( -2, "\t-S num : the starting time frame [default = %d]\n", nStart );
26461     Abc_Print( -2, "\t-F num : the max number of time frames (0 = unused) [default = %d]\n", nFrames );
26462     Abc_Print( -2, "\t-T num : approximate runtime limit in seconds [default = %d]\n", nTimeOut );
26463     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", nBTLimit );
26464     Abc_Print( -2, "\t-G num : the max number of conflicts globally [default = %d]\n", nBTLimitAll );
26465     Abc_Print( -2, "\t-D num : the delta in the number of nodes [default = %d]\n", nNodeDelta );
26466     Abc_Print( -2, "\t-L file: the log file name [default = %s]\n", pLogFileName ? pLogFileName : "no logging" );
26467     Abc_Print( -2, "\t-u     : toggle performing structural OR-decomposition [default = %s]\n", fOrDecomp? "yes": "no" );
26468     Abc_Print( -2, "\t-s     : toggle using Satoko by Bruno Schmitt [default = %s]\n", fUseSatoko? "yes": "no" );
26469     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
26470     Abc_Print( -2, "\t-h     : print the command usage\n");
26471     return 1;
26472 }
26473 
26474 /**Function*************************************************************
26475 
26476   Synopsis    []
26477 
26478   Description []
26479 
26480   SideEffects []
26481 
26482   SeeAlso     []
26483 
26484 ***********************************************************************/
Abc_CommandBmc3(Abc_Frame_t * pAbc,int argc,char ** argv)26485 int Abc_CommandBmc3( Abc_Frame_t * pAbc, int argc, char ** argv )
26486 {
26487     extern int Abc_NtkDarBmc3( Abc_Ntk_t * pNtk, Saig_ParBmc_t * pPars, int fOrDecomp );
26488     Saig_ParBmc_t Pars, * pPars = &Pars;
26489     Abc_Ntk_t * pNtkRes, * pNtk = Abc_FrameReadNtk(pAbc);
26490     Vec_Ptr_t * vSeqModelVec = NULL;
26491     Vec_Int_t * vStatuses = NULL;
26492     char * pLogFileName = NULL;
26493     int fOrDecomp = 0;
26494     int c;
26495     Saig_ParBmcSetDefaultParams( pPars );
26496     Extra_UtilGetoptReset();
26497     while ( ( c = Extra_UtilGetopt( argc, argv, "SFTHGCDJIPQRLWaxdursgvzh" ) ) != EOF )
26498     {
26499         switch ( c )
26500         {
26501         case 'S':
26502             if ( globalUtilOptind >= argc )
26503             {
26504                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
26505                 goto usage;
26506             }
26507             pPars->nStart = atoi(argv[globalUtilOptind]);
26508             globalUtilOptind++;
26509             if ( pPars->nStart < 0 )
26510                 goto usage;
26511             break;
26512         case 'F':
26513             if ( globalUtilOptind >= argc )
26514             {
26515                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
26516                 goto usage;
26517             }
26518             pPars->nFramesMax = atoi(argv[globalUtilOptind]);
26519             globalUtilOptind++;
26520             if ( pPars->nFramesMax < 0 )
26521                 goto usage;
26522             break;
26523         case 'T':
26524             if ( globalUtilOptind >= argc )
26525             {
26526                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
26527                 goto usage;
26528             }
26529             pPars->nTimeOut = atoi(argv[globalUtilOptind]);
26530             globalUtilOptind++;
26531             if ( pPars->nTimeOut < 0 )
26532                 goto usage;
26533             break;
26534         case 'H':
26535             if ( globalUtilOptind >= argc )
26536             {
26537                 Abc_Print( -1, "Command line switch \"-H\" should be followed by an integer.\n" );
26538                 goto usage;
26539             }
26540             pPars->nTimeOutOne = atoi(argv[globalUtilOptind]);
26541             globalUtilOptind++;
26542             if ( pPars->nTimeOutOne < 0 )
26543                 goto usage;
26544             break;
26545         case 'G':
26546             if ( globalUtilOptind >= argc )
26547             {
26548                 Abc_Print( -1, "Command line switch \"-G\" should be followed by an integer.\n" );
26549                 goto usage;
26550             }
26551             pPars->nTimeOutGap = atoi(argv[globalUtilOptind]);
26552             globalUtilOptind++;
26553             if ( pPars->nTimeOutGap < 0 )
26554                 goto usage;
26555             break;
26556         case 'C':
26557             if ( globalUtilOptind >= argc )
26558             {
26559                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
26560                 goto usage;
26561             }
26562             pPars->nConfLimit = atoi(argv[globalUtilOptind]);
26563             globalUtilOptind++;
26564             if ( pPars->nConfLimit < 0 )
26565                 goto usage;
26566             break;
26567         case 'D':
26568             if ( globalUtilOptind >= argc )
26569             {
26570                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
26571                 goto usage;
26572             }
26573             pPars->nConfLimitJump = atoi(argv[globalUtilOptind]);
26574             globalUtilOptind++;
26575             if ( pPars->nConfLimitJump < 0 )
26576                 goto usage;
26577             break;
26578         case 'J':
26579             if ( globalUtilOptind >= argc )
26580             {
26581                 Abc_Print( -1, "Command line switch \"-J\" should be followed by an integer.\n" );
26582                 goto usage;
26583             }
26584             pPars->nFramesJump = atoi(argv[globalUtilOptind]);
26585             globalUtilOptind++;
26586             if ( pPars->nFramesJump < 0 )
26587                 goto usage;
26588             break;
26589         case 'I':
26590             if ( globalUtilOptind >= argc )
26591             {
26592                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
26593                 goto usage;
26594             }
26595             pPars->nPisAbstract = atoi(argv[globalUtilOptind]);
26596             globalUtilOptind++;
26597             if ( pPars->nPisAbstract < 0 )
26598                 goto usage;
26599             break;
26600         case 'P':
26601             if ( globalUtilOptind >= argc )
26602             {
26603                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
26604                 goto usage;
26605             }
26606             pPars->nLearnedStart = atoi(argv[globalUtilOptind]);
26607             globalUtilOptind++;
26608             if ( pPars->nLearnedStart < 0 )
26609                 goto usage;
26610             break;
26611         case 'Q':
26612             if ( globalUtilOptind >= argc )
26613             {
26614                 Abc_Print( -1, "Command line switch \"-Q\" should be followed by an integer.\n" );
26615                 goto usage;
26616             }
26617             pPars->nLearnedDelta = atoi(argv[globalUtilOptind]);
26618             globalUtilOptind++;
26619             if ( pPars->nLearnedDelta < 0 )
26620                 goto usage;
26621             break;
26622         case 'R':
26623             if ( globalUtilOptind >= argc )
26624             {
26625                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
26626                 goto usage;
26627             }
26628             pPars->nLearnedPerce = atoi(argv[globalUtilOptind]);
26629             globalUtilOptind++;
26630             if ( pPars->nLearnedPerce < 0 )
26631                 goto usage;
26632             break;
26633         case 'L':
26634             if ( globalUtilOptind >= argc )
26635             {
26636                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
26637                 goto usage;
26638             }
26639             pLogFileName = argv[globalUtilOptind];
26640             globalUtilOptind++;
26641             break;
26642         case 'W':
26643             if ( globalUtilOptind >= argc )
26644             {
26645                 Abc_Print( -1, "Command line switch \"-W\" should be followed by a file name.\n" );
26646                 goto usage;
26647             }
26648             pPars->pLogFileName = argv[globalUtilOptind];
26649             globalUtilOptind++;
26650             break;
26651         case 'a':
26652             pPars->fSolveAll ^= 1;
26653             break;
26654         case 'x':
26655             pPars->fStoreCex ^= 1;
26656             break;
26657         case 'd':
26658             pPars->fDropSatOuts ^= 1;
26659             break;
26660         case 'u':
26661             fOrDecomp ^= 1;
26662             break;
26663         case 'r':
26664             pPars->fNoRestarts ^= 1;
26665             break;
26666         case 's':
26667             pPars->fUseSatoko ^= 1;
26668             break;
26669         case 'g':
26670             pPars->fUseGlucose ^= 1;
26671             break;
26672         case 'v':
26673             pPars->fVerbose ^= 1;
26674             break;
26675         case 'z':
26676             pPars->fNotVerbose ^= 1;
26677             break;
26678         case 'h':
26679             goto usage;
26680         default:
26681             goto usage;
26682         }
26683     }
26684     if ( pNtk == NULL )
26685     {
26686         Abc_Print( -1, "Empty network.\n" );
26687         return 1;
26688     }
26689     if ( !Abc_NtkIsStrash(pNtk) )
26690     {
26691         Abc_Print( -1, "Currently only works for structurally hashed circuits.\n" );
26692         return 0;
26693     }
26694     if ( Abc_NtkLatchNum(pNtk) == 0 )
26695     {
26696         Abc_Print( -1, "Does not work for combinational networks.\n" );
26697         return 0;
26698     }
26699     if ( Abc_NtkConstrNum(pNtk) > 0 )
26700     {
26701         Abc_Print( -1, "Constraints have to be folded (use \"fold\").\n" );
26702         return 0;
26703     }
26704     if ( pAbc->fBatchMode && (pAbc->Status == 0 || pAbc->Status == 1) )
26705     {
26706         Abc_Print( 1, "The miters is already solved; skipping the command.\n" );
26707         return 0;
26708     }
26709     pPars->fUseBridge = pAbc->fBridgeMode;
26710     pAbc->Status = Abc_NtkDarBmc3( pNtk, pPars, fOrDecomp );
26711     pAbc->nFrames = pNtk->vSeqModelVec ? -1 : pPars->iFrame;
26712     if ( pLogFileName )
26713         Abc_NtkWriteLogFile( pLogFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, "bmc3" );
26714     vSeqModelVec = pNtk->vSeqModelVec;  pNtk->vSeqModelVec = NULL;
26715     if ( pPars->fSolveAll && pPars->fDropSatOuts )
26716     {
26717         if ( vSeqModelVec == NULL )
26718             Abc_Print( 1,"The array of counter-examples is not available.\n" );
26719         else if ( Vec_PtrSize(vSeqModelVec) != Abc_NtkPoNum(pNtk) )
26720             Abc_Print( 1,"The array size does not match the number of outputs.\n" );
26721         else
26722         {
26723             extern void Abc_NtkDropSatOutputs( Abc_Ntk_t * pNtk, Vec_Ptr_t * vCexes, int fVerbose );
26724             Abc_NtkDropSatOutputs( pNtk, vSeqModelVec, pPars->fVerbose );
26725             pNtkRes = Abc_NtkDarLatchSweep( pNtk, 1, 1, 1, 0, -1, -1, 0, 0 );
26726             if ( pNtkRes == NULL )
26727             {
26728                 Abc_Print( -1, "Removing SAT outputs has failed.\n" );
26729                 return 1;
26730             }
26731             Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
26732         }
26733     }
26734     vStatuses = Abc_FrameDeriveStatusArray( vSeqModelVec );
26735     Abc_FrameReplacePoStatuses( pAbc, &vStatuses );
26736     if ( vSeqModelVec )
26737         Abc_FrameReplaceCexVec( pAbc, &vSeqModelVec );
26738     else
26739         Abc_FrameReplaceCex( pAbc, &pNtk->pSeqModel );
26740     return 0;
26741 
26742 usage:
26743     Abc_Print( -2, "usage: bmc3 [-SFTHGCDJIPQR num] [-LW file] [-axdursgvzh]\n" );
26744     Abc_Print( -2, "\t         performs bounded model checking with dynamic unrolling\n" );
26745     Abc_Print( -2, "\t-S num : the starting time frame [default = %d]\n", pPars->nStart );
26746     Abc_Print( -2, "\t-F num : the max number of time frames (0 = unused) [default = %d]\n",      pPars->nFramesMax );
26747     Abc_Print( -2, "\t-T num : runtime limit, in seconds [default = %d]\n",                       pPars->nTimeOut );
26748     Abc_Print( -2, "\t-H num : runtime limit per output, in miliseconds (with \"-a\") [default = %d]\n",    pPars->nTimeOutOne );
26749     Abc_Print( -2, "\t-G num : runtime gap since the last CEX, in seconds [default = %d]\n",      pPars->nTimeOutGap );
26750     Abc_Print( -2, "\t-C num : max conflicts at an output [default = %d]\n",                      pPars->nConfLimit );
26751     Abc_Print( -2, "\t-D num : max conflicts after jumping (0 = infinity) [default = %d]\n",      pPars->nConfLimitJump );
26752     Abc_Print( -2, "\t-J num : the number of timeframes to jump (0 = not used) [default = %d]\n", pPars->nFramesJump );
26753     Abc_Print( -2, "\t-I num : the number of PIs to abstract [default = %d]\n",                   pPars->nPisAbstract );
26754     Abc_Print( -2, "\t-P num : the max number of learned clauses to keep (0=unused) [default = %d]\n", pPars->nLearnedStart );
26755     Abc_Print( -2, "\t-Q num : delta value for learned clause removal [default = %d]\n",          pPars->nLearnedDelta );
26756     Abc_Print( -2, "\t-R num : percentage to keep for learned clause removal [default = %d]\n",   pPars->nLearnedPerce );
26757     Abc_Print( -2, "\t-L file: the log file name [default = %s]\n",                               pLogFileName ? pLogFileName : "no logging" );
26758     Abc_Print( -2, "\t-W file: the log file name with per-output details [default = %s]\n",       pPars->pLogFileName ? pPars->pLogFileName : "no logging" );
26759     Abc_Print( -2, "\t-a     : solve all outputs (do not stop when one is SAT) [default = %s]\n", pPars->fSolveAll? "yes": "no" );
26760     Abc_Print( -2, "\t-x     : toggle storing CEXes when solving all outputs [default = %s]\n",   pPars->fStoreCex? "yes": "no" );
26761     Abc_Print( -2, "\t-d     : toggle dropping (replacing by 0) SAT outputs [default = %s]\n",    pPars->fDropSatOuts? "yes": "no" );
26762     Abc_Print( -2, "\t-u     : toggle performing structural OR-decomposition [default = %s]\n",   fOrDecomp? "yes": "not" );
26763     Abc_Print( -2, "\t-r     : toggle disabling periodic restarts [default = %s]\n",              pPars->fNoRestarts? "yes": "no" );
26764     Abc_Print( -2, "\t-s     : toggle using Satoko by Bruno Schmitt [default = %s]\n", pPars->fUseSatoko? "yes": "no" );
26765     Abc_Print( -2, "\t-g     : toggle using Glucose 3.0 by Gilles Audemard and Laurent Simon [default = %s]\n",pPars->fUseGlucose? "yes": "no" );
26766     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n",                           pPars->fVerbose? "yes": "no" );
26767     Abc_Print( -2, "\t-z     : toggle suppressing report about solved outputs [default = %s]\n",  pPars->fNotVerbose? "yes": "no" );
26768     Abc_Print( -2, "\t-h     : print the command usage\n");
26769     return 1;
26770 }
26771 
26772 /**Function*************************************************************
26773 
26774   Synopsis    []
26775 
26776   Description []
26777 
26778   SideEffects []
26779 
26780   SeeAlso     []
26781 
26782 ***********************************************************************/
Abc_CommandBmcInter(Abc_Frame_t * pAbc,int argc,char ** argv)26783 int Abc_CommandBmcInter( Abc_Frame_t * pAbc, int argc, char ** argv )
26784 {
26785     Inter_ManParams_t Pars, * pPars = &Pars;
26786     Abc_Ntk_t * pNtkRes, * pNtk = Abc_FrameReadNtk(pAbc);
26787     int c;
26788     char * pLogFileName = NULL;
26789 
26790     extern int Abc_NtkDarBmcInter( Abc_Ntk_t * pNtk, Inter_ManParams_t * pPars, Abc_Ntk_t ** ppNtkRes );
26791     // set defaults
26792     Inter_ManSetDefaultParams( pPars );
26793     Extra_UtilGetoptReset();
26794     while ( ( c = Extra_UtilGetopt( argc, argv, "CFTKLIrtpomcgbqkdivh" ) ) != EOF )
26795     {
26796         switch ( c )
26797         {
26798         case 'C':
26799             if ( globalUtilOptind >= argc )
26800             {
26801                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
26802                 goto usage;
26803             }
26804             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
26805             globalUtilOptind++;
26806             if ( pPars->nBTLimit < 0 )
26807                 goto usage;
26808             break;
26809         case 'F':
26810             if ( globalUtilOptind >= argc )
26811             {
26812                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
26813                 goto usage;
26814             }
26815             pPars->nFramesMax = atoi(argv[globalUtilOptind]);
26816             globalUtilOptind++;
26817             if ( pPars->nFramesMax < 0 )
26818                 goto usage;
26819             break;
26820         case 'T':
26821             if ( globalUtilOptind >= argc )
26822             {
26823                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
26824                 goto usage;
26825             }
26826             pPars->nSecLimit = atoi(argv[globalUtilOptind]);
26827             globalUtilOptind++;
26828             if ( pPars->nSecLimit < 0 )
26829                 goto usage;
26830             break;
26831         case 'K':
26832             if ( globalUtilOptind >= argc )
26833             {
26834                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
26835                 goto usage;
26836             }
26837             pPars->nFramesK = atoi(argv[globalUtilOptind]);
26838             globalUtilOptind++;
26839             if ( pPars->nFramesK < 0 )
26840                 goto usage;
26841             break;
26842         case 'L':
26843             if ( globalUtilOptind >= argc )
26844             {
26845                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
26846                 goto usage;
26847             }
26848             pLogFileName = argv[globalUtilOptind];
26849             globalUtilOptind++;
26850             break;
26851         case 'I':
26852             if ( globalUtilOptind >= argc )
26853             {
26854                 Abc_Print( -1, "Command line switch \"-I\" should be followed by a file name.\n" );
26855                 goto usage;
26856             }
26857             pPars->pFileName = argv[globalUtilOptind];
26858             globalUtilOptind++;
26859             break;
26860         case 'r':
26861             pPars->fRewrite ^= 1;
26862             break;
26863         case 't':
26864             pPars->fTransLoop ^= 1;
26865             break;
26866         case 'p':
26867             pPars->fUsePudlak ^= 1;
26868             break;
26869         case 'o':
26870             pPars->fUseOther ^= 1;
26871             break;
26872         case 'm':
26873             pPars->fUseMiniSat ^= 1;
26874             break;
26875         case 'c':
26876             pPars->fCheckKstep ^= 1;
26877             break;
26878         case 'g':
26879             pPars->fUseBias ^= 1;
26880             break;
26881         case 'b':
26882             pPars->fUseBackward ^= 1;
26883             break;
26884         case 'q':
26885             pPars->fUseTwoFrames ^= 1;
26886             break;
26887         case 'k':
26888             pPars->fUseSeparate ^= 1;
26889             break;
26890         case 'd':
26891             pPars->fDropSatOuts ^= 1;
26892             break;
26893         case 'i':
26894             pPars->fDropInvar ^= 1;
26895             break;
26896         case 'v':
26897             pPars->fVerbose ^= 1;
26898             break;
26899         case 'h':
26900             goto usage;
26901         default:
26902             goto usage;
26903         }
26904     }
26905     if ( pNtk == NULL )
26906     {
26907         Abc_Print( -1, "Empty network.\n" );
26908         return 1;
26909     }
26910     if ( !Abc_NtkIsStrash(pNtk) )
26911     {
26912         Abc_Print( -1, "Currently only works for structurally hashed circuits.\n" );
26913         return 0;
26914     }
26915     if ( pAbc->fBatchMode && (pAbc->Status == 0 || pAbc->Status == 1) )
26916     {
26917         Abc_Print( 1, "The miters is already solved; skipping the command.\n" );
26918         return 0;
26919     }
26920     if ( Abc_NtkLatchNum(pNtk) == 0 )
26921     {
26922         Abc_Print( -1, "Does not work for combinational networks.\n" );
26923         return 0;
26924     }
26925     if ( Abc_NtkConstrNum(pNtk) > 0 )
26926     {
26927         Abc_Print( -1, "Cannot run interpolation with constraints. Use \"fold\".\n" );
26928         return 0;
26929     }
26930     if ( Abc_NtkPoNum(pNtk)-Abc_NtkConstrNum(pNtk) != 1 )
26931     {
26932         if ( Abc_NtkConstrNum(pNtk) > 0 )
26933         {
26934             Abc_Print( 1,"Cannot solve multiple-output miter with constraints.\n" );
26935             return 0;
26936         }
26937         if ( pPars->fUseSeparate )
26938         {
26939             Abc_Print( 0, "Each of %d outputs will be solved separately.\n", Abc_NtkPoNum(pNtk) );
26940             pAbc->Status = Abc_NtkDarBmcInter( pNtk, pPars, &pNtkRes );
26941             Abc_FrameReplaceCex( pAbc, &pNtk->pSeqModel );
26942             if ( pNtkRes == NULL )
26943             {
26944                 Abc_Print( -1, "Generating resulting network has failed.\n" );
26945                 return 0;
26946             }
26947             Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
26948         }
26949         else
26950         {
26951             Abc_Ntk_t * pNtkNew = Abc_NtkDup( pNtk );
26952             Abc_Print( 0, "All %d outputs will be ORed together.\n", Abc_NtkPoNum(pNtk) );
26953             if ( !Abc_NtkCombinePos( pNtkNew, 0, 0 ) )
26954             {
26955                 Abc_NtkDelete( pNtkNew );
26956                 Abc_Print( -1, "ORing outputs has failed.\n" );
26957                 return 0;
26958             }
26959             pAbc->Status = Abc_NtkDarBmcInter( pNtkNew, pPars, NULL );
26960             if ( pAbc->Status == 0 )
26961             {
26962                 Aig_Man_t * pMan = Abc_NtkToDar( pNtk, 0, 1 );
26963                 pNtkNew->pSeqModel->iPo = Saig_ManFindFailedPoCex( pMan, pNtkNew->pSeqModel );
26964                 Aig_ManStop( pMan );
26965             }
26966             Abc_FrameReplaceCex( pAbc, &pNtkNew->pSeqModel );
26967             Abc_NtkDelete( pNtkNew );
26968         }
26969         pAbc->nFrames = -1;
26970     }
26971     else
26972     {
26973         pAbc->Status  = Abc_NtkDarBmcInter( pNtk, pPars, NULL );
26974         pAbc->nFrames = pPars->iFrameMax;
26975         Abc_FrameReplaceCex( pAbc, &pNtk->pSeqModel );
26976     }
26977     if ( pLogFileName )
26978         Abc_NtkWriteLogFile( pLogFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, "int" );
26979     return 0;
26980 
26981 usage:
26982     Abc_Print( -2, "usage: int [-CFTK num] [-LI file] [-irtpomcgbqkdvh]\n" );
26983     Abc_Print( -2, "\t         uses interpolation to prove the property\n" );
26984     Abc_Print( -2, "\t-C num : the limit on conflicts for one SAT run [default = %d]\n", pPars->nBTLimit );
26985     Abc_Print( -2, "\t-F num : the limit on number of frames to unroll [default = %d]\n", pPars->nFramesMax );
26986     Abc_Print( -2, "\t-T num : the limit on runtime per output in seconds [default = %d]\n", pPars->nSecLimit );
26987     Abc_Print( -2, "\t-K num : the number of steps in inductive checking [default = %d]\n", pPars->nFramesK );
26988     Abc_Print( -2, "\t         (K = 1 works in all cases; K > 1 works without -t and -b)\n" );
26989     Abc_Print( -2, "\t-L file: the log file name [default = %s]\n", pLogFileName ? pLogFileName : "no logging" );
26990     Abc_Print( -2, "\t-I file: the file name for dumping interpolant [default = \"%s\"]\n", pPars->pFileName ? pPars->pFileName : "invar.aig" );
26991     Abc_Print( -2, "\t-i     : toggle dumping interpolant/invariant into a file [default = %s]\n", pPars->fDropInvar? "yes": "no" );
26992     Abc_Print( -2, "\t-r     : toggle rewriting of the unrolled timeframes [default = %s]\n", pPars->fRewrite? "yes": "no" );
26993     Abc_Print( -2, "\t-t     : toggle adding transition into the initial state [default = %s]\n", pPars->fTransLoop? "yes": "no" );
26994     Abc_Print( -2, "\t-p     : toggle using original Pudlak's interpolation procedure [default = %s]\n", pPars->fUsePudlak? "yes": "no" );
26995     Abc_Print( -2, "\t-o     : toggle using optimized Pudlak's interpolation procedure [default = %s]\n", pPars->fUseOther? "yes": "no" );
26996     Abc_Print( -2, "\t-m     : toggle using MiniSat-1.14p (now, Windows-only) [default = %s]\n", pPars->fUseMiniSat? "yes": "no" );
26997     Abc_Print( -2, "\t-c     : toggle using inductive containment check [default = %s]\n", pPars->fCheckKstep? "yes": "no" );
26998     Abc_Print( -2, "\t-g     : toggle using bias for global variables using SAT [default = %s]\n", pPars->fUseBias? "yes": "no" );
26999     Abc_Print( -2, "\t-b     : toggle using backward interpolation (works with -t) [default = %s]\n", pPars->fUseBackward? "yes": "no" );
27000     Abc_Print( -2, "\t-q     : toggle using property in two last timeframes [default = %s]\n", pPars->fUseTwoFrames? "yes": "no" );
27001     Abc_Print( -2, "\t-k     : toggle solving each output separately [default = %s]\n", pPars->fUseSeparate? "yes": "no" );
27002     Abc_Print( -2, "\t-d     : toggle dropping (replacing by 0) SAT outputs (with -k is used) [default = %s]\n", pPars->fDropSatOuts? "yes": "no" );
27003     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
27004     Abc_Print( -2, "\t-h     : print the command usage\n");
27005     return 1;
27006 }
27007 
27008 /**Function*************************************************************
27009 
27010   Synopsis    []
27011 
27012   Description []
27013 
27014   SideEffects []
27015 
27016   SeeAlso     []
27017 
27018 ***********************************************************************/
Abc_CommandIndcut(Abc_Frame_t * pAbc,int argc,char ** argv)27019 int Abc_CommandIndcut( Abc_Frame_t * pAbc, int argc, char ** argv )
27020 {
27021     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
27022     int nFrames;
27023     int nPref;
27024     int nClauses;
27025     int nLutSize;
27026     int nLevels;
27027     int nCutsMax;
27028     int nBatches;
27029     int fStepUp;
27030     int fBmc;
27031     int fRegs;
27032     int fTarget;
27033     int fVerbose;
27034     int fVeryVerbose;
27035     int c;
27036     extern int Abc_NtkDarClau( Abc_Ntk_t * pNtk, int nFrames, int nPref, int nClauses, int nLutSize, int nLevels, int nCutsMax, int nBatches, int fStepUp, int fBmc, int fRegs, int fTarget, int fVerbose, int fVeryVerbose );
27037     // set defaults
27038     nFrames      =    1;
27039     nPref        =    0;
27040     nClauses     = 5000;
27041     nLutSize     =    4;
27042     nLevels      =    8;
27043     nCutsMax     =   16;
27044     nBatches     =    1;
27045     fStepUp      =    0;
27046     fBmc         =    1;
27047     fRegs        =    1;
27048     fTarget      =    1;
27049     fVerbose     =    0;
27050     fVeryVerbose =    0;
27051     Extra_UtilGetoptReset();
27052     while ( ( c = Extra_UtilGetopt( argc, argv, "FPCMLNBsbrtvwh" ) ) != EOF )
27053     {
27054         switch ( c )
27055         {
27056         case 'F':
27057             if ( globalUtilOptind >= argc )
27058             {
27059                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
27060                 goto usage;
27061             }
27062             nFrames = atoi(argv[globalUtilOptind]);
27063             globalUtilOptind++;
27064             if ( nFrames < 0 )
27065                 goto usage;
27066             break;
27067         case 'P':
27068             if ( globalUtilOptind >= argc )
27069             {
27070                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
27071                 goto usage;
27072             }
27073             nPref = atoi(argv[globalUtilOptind]);
27074             globalUtilOptind++;
27075             if ( nPref < 0 )
27076                 goto usage;
27077             break;
27078         case 'C':
27079             if ( globalUtilOptind >= argc )
27080             {
27081                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
27082                 goto usage;
27083             }
27084             nClauses = atoi(argv[globalUtilOptind]);
27085             globalUtilOptind++;
27086             if ( nClauses < 0 )
27087                 goto usage;
27088             break;
27089         case 'M':
27090             if ( globalUtilOptind >= argc )
27091             {
27092                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
27093                 goto usage;
27094             }
27095             nLutSize = atoi(argv[globalUtilOptind]);
27096             globalUtilOptind++;
27097             if ( nLutSize < 0 )
27098                 goto usage;
27099             break;
27100         case 'L':
27101             if ( globalUtilOptind >= argc )
27102             {
27103                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
27104                 goto usage;
27105             }
27106             nLevels = atoi(argv[globalUtilOptind]);
27107             globalUtilOptind++;
27108             if ( nLevels < 0 )
27109                 goto usage;
27110             break;
27111         case 'N':
27112             if ( globalUtilOptind >= argc )
27113             {
27114                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
27115                 goto usage;
27116             }
27117             nCutsMax = atoi(argv[globalUtilOptind]);
27118             globalUtilOptind++;
27119             if ( nCutsMax < 0 )
27120                 goto usage;
27121             break;
27122         case 'B':
27123             if ( globalUtilOptind >= argc )
27124             {
27125                 Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" );
27126                 goto usage;
27127             }
27128             nBatches = atoi(argv[globalUtilOptind]);
27129             globalUtilOptind++;
27130             if ( nBatches < 0 )
27131                 goto usage;
27132             break;
27133         case 's':
27134             fStepUp ^= 1;
27135             break;
27136         case 'b':
27137             fBmc ^= 1;
27138             break;
27139         case 'r':
27140             fRegs ^= 1;
27141             break;
27142         case 't':
27143             fTarget ^= 1;
27144             break;
27145         case 'v':
27146             fVerbose ^= 1;
27147             break;
27148         case 'w':
27149             fVeryVerbose ^= 1;
27150             break;
27151         case 'h':
27152             goto usage;
27153         default:
27154             goto usage;
27155         }
27156     }
27157     if ( pNtk == NULL )
27158     {
27159         Abc_Print( -1, "Empty network.\n" );
27160         return 1;
27161     }
27162     if ( Abc_NtkIsComb(pNtk) )
27163     {
27164         Abc_Print( -1, "The network is combinational.\n" );
27165         return 0;
27166     }
27167     if ( !Abc_NtkIsStrash(pNtk) )
27168     {
27169         Abc_Print( -1, "Currently only works for structurally hashed circuits.\n" );
27170         return 0;
27171     }
27172     if ( nLutSize > 12 )
27173     {
27174         Abc_Print( -1, "The cut size should be not exceed 12.\n" );
27175         return 0;
27176     }
27177     Abc_NtkDarClau( pNtk, nFrames, nPref, nClauses, nLutSize, nLevels, nCutsMax, nBatches, fStepUp, fBmc, fRegs, fTarget, fVerbose, fVeryVerbose );
27178     return 0;
27179 usage:
27180     Abc_Print( -2, "usage: indcut [-FPCMLNB num] [-sbrtvh]\n" );
27181     Abc_Print( -2, "\t         K-step induction strengthened with cut properties\n" );
27182     Abc_Print( -2, "\t-F num : number of time frames for induction (1=simple) [default = %d]\n", nFrames );
27183     Abc_Print( -2, "\t-P num : number of time frames in the prefix (0=no prefix) [default = %d]\n", nPref );
27184     Abc_Print( -2, "\t-C num : the max number of clauses to use for strengthening [default = %d]\n", nClauses );
27185     Abc_Print( -2, "\t-M num : the cut size (2 <= M <= 12) [default = %d]\n", nLutSize );
27186     Abc_Print( -2, "\t-L num : the max number of levels for cut computation [default = %d]\n", nLevels );
27187     Abc_Print( -2, "\t-N num : the max number of cuts to compute at a node [default = %d]\n", nCutsMax );
27188     Abc_Print( -2, "\t-B num : the max number of invariant batches to try [default = %d]\n", nBatches );
27189     Abc_Print( -2, "\t-s     : toggle increment cut size in each batch [default = %s]\n", fStepUp? "yes": "no" );
27190     Abc_Print( -2, "\t-b     : toggle enabling BMC check [default = %s]\n", fBmc? "yes": "no" );
27191     Abc_Print( -2, "\t-r     : toggle enabling register clauses [default = %s]\n", fRegs? "yes": "no" );
27192     Abc_Print( -2, "\t-t     : toggle proving target / computing don't-cares [default = %s]\n", fTarget? "yes": "no" );
27193     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
27194 //    Abc_Print( -2, "\t-w     : toggle printing very verbose information [default = %s]\n", fVeryVerbose? "yes": "no" );
27195     Abc_Print( -2, "\t-h     : print the command usage\n");
27196     return 1;
27197 }
27198 
27199 /**Function*************************************************************
27200 
27201   Synopsis    []
27202 
27203   Description []
27204 
27205   SideEffects []
27206 
27207   SeeAlso     []
27208 
27209 ***********************************************************************/
Abc_CommandEnlarge(Abc_Frame_t * pAbc,int argc,char ** argv)27210 int Abc_CommandEnlarge( Abc_Frame_t * pAbc, int argc, char ** argv )
27211 {
27212     Abc_Ntk_t * pNtk, * pNtkRes;
27213     int nFrames;
27214     int fVerbose;
27215     int c;
27216     extern Abc_Ntk_t * Abc_NtkDarEnlarge( Abc_Ntk_t * pNtk, int nFrames, int fVerbose );
27217 
27218     pNtk = Abc_FrameReadNtk(pAbc);
27219     // set defaults
27220     nFrames      = 5;
27221     fVerbose     = 0;
27222     Extra_UtilGetoptReset();
27223     while ( ( c = Extra_UtilGetopt( argc, argv, "Fvh" ) ) != EOF )
27224     {
27225         switch ( c )
27226         {
27227         case 'F':
27228             if ( globalUtilOptind >= argc )
27229             {
27230                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
27231                 goto usage;
27232             }
27233             nFrames = atoi(argv[globalUtilOptind]);
27234             globalUtilOptind++;
27235             if ( nFrames < 1 )
27236                 goto usage;
27237             break;
27238         case 'v':
27239             fVerbose ^= 1;
27240             break;
27241         case 'h':
27242             goto usage;
27243         default:
27244             goto usage;
27245         }
27246     }
27247     if ( pNtk == NULL )
27248     {
27249         Abc_Print( -1, "Empty network.\n" );
27250         return 1;
27251     }
27252     if ( Abc_NtkIsComb(pNtk) )
27253     {
27254         Abc_Print( -1, "The network is combinational.\n" );
27255         return 0;
27256     }
27257     if ( !Abc_NtkIsStrash(pNtk) )
27258     {
27259         Abc_Print( -1, "Currently only works for structurally hashed circuits.\n" );
27260         return 0;
27261     }
27262 
27263     // modify the current network
27264     pNtkRes = Abc_NtkDarEnlarge( pNtk, nFrames, fVerbose );
27265     if ( pNtkRes == NULL )
27266     {
27267         Abc_Print( -1, "Target enlargement has failed.\n" );
27268         return 1;
27269     }
27270     // replace the current network
27271     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
27272     return 0;
27273 usage:
27274     Abc_Print( -2, "usage: enlarge [-F <num>] [-vh]\n" );
27275     Abc_Print( -2, "\t           performs structural K-step target enlargement\n" );
27276     Abc_Print( -2, "\t-F <num> : the number of timeframes to unroll (<num> > 0) [default = %d]\n", nFrames );
27277     Abc_Print( -2, "\t-v       : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
27278     Abc_Print( -2, "\t-h       : print the command usage\n");
27279     return 1;
27280 }
27281 
27282 /**Function*************************************************************
27283 
27284   Synopsis    []
27285 
27286   Description []
27287 
27288   SideEffects []
27289 
27290   SeeAlso     []
27291 
27292 ***********************************************************************/
Abc_CommandTempor(Abc_Frame_t * pAbc,int argc,char ** argv)27293 int Abc_CommandTempor( Abc_Frame_t * pAbc, int argc, char ** argv )
27294 {
27295     extern Abc_Ntk_t * Abc_NtkDarTempor( Abc_Ntk_t * pNtk, int nFrames, int TimeOut, int nConfLimit, int fUseBmc, int fUseTransSigs, int fVerbose, int fVeryVerbose );
27296     Abc_Ntk_t * pNtkRes, * pNtk = Abc_FrameReadNtk(pAbc);
27297     int nFrames       =       0;
27298     int TimeOut       =     300;
27299     int nConfMax      =  100000;
27300     int fUseBmc       =       1;
27301     int fUseTransSigs =       0;
27302     int fUpdateCex    =       0;
27303     int fVerbose      =       0;
27304     int fVeryVerbose  =       0;
27305     int c;
27306     Extra_UtilGetoptReset();
27307     while ( ( c = Extra_UtilGetopt( argc, argv, "FTCbscvwh" ) ) != EOF )
27308     {
27309         switch ( c )
27310         {
27311         case 'F':
27312             if ( globalUtilOptind >= argc )
27313             {
27314                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
27315                 goto usage;
27316             }
27317             nFrames = atoi(argv[globalUtilOptind]);
27318             globalUtilOptind++;
27319             if ( nFrames < 0 )
27320                 goto usage;
27321             break;
27322         case 'T':
27323             if ( globalUtilOptind >= argc )
27324             {
27325                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
27326                 goto usage;
27327             }
27328             TimeOut = atoi(argv[globalUtilOptind]);
27329             globalUtilOptind++;
27330             if ( TimeOut < 0 )
27331                 goto usage;
27332             break;
27333         case 'C':
27334             if ( globalUtilOptind >= argc )
27335             {
27336                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
27337                 goto usage;
27338             }
27339             nConfMax = atoi(argv[globalUtilOptind]);
27340             globalUtilOptind++;
27341             if ( nConfMax < 0 )
27342                 goto usage;
27343             break;
27344         case 'b':
27345             fUseBmc ^= 1;
27346             break;
27347         case 's':
27348             fUseTransSigs ^= 1;
27349             break;
27350         case 'c':
27351             fUpdateCex ^= 1;
27352             break;
27353         case 'v':
27354             fVerbose ^= 1;
27355             break;
27356         case 'w':
27357             fVeryVerbose ^= 1;
27358             break;
27359         case 'h':
27360         default:
27361             goto usage;
27362         }
27363     }
27364     if ( pNtk == NULL )
27365     {
27366         Abc_Print( -2, "There is no current network.\n");
27367         return 0;
27368     }
27369     if ( !Abc_NtkIsStrash(pNtk) )
27370     {
27371         Abc_Print( -2, "The current network is not an AIG (run \"strash\").\n");
27372         return 0;
27373     }
27374     if ( Abc_NtkLatchNum(pNtk) == 0 )
27375     {
27376         Abc_Print( 0, "The current network is combinational.\n");
27377         return 0;
27378     }
27379     if ( Abc_NtkPiNum(pNtk) == 0 )
27380     {
27381         Abc_Print( 0, "The current network does not have primary inputs. Use \"addpi\".\n");
27382         return 0;
27383     }
27384     if ( fUpdateCex )
27385     {
27386         Abc_Cex_t * pCexNew;
27387         if ( pAbc->pCex == NULL )
27388         {
27389             Abc_Print( -1, "Counter-example is not available.\n" );
27390             return 1;
27391         }
27392         if ( pAbc->pCex->nPis % Abc_NtkPiNum(pNtk) != 0 )
27393         {
27394             Abc_Print( -1, "PI count of the CEX is not a multiple of PI count of the current AIG.\n" );
27395             return 1;
27396         }
27397         pCexNew = Abc_CexTransformTempor( pAbc->pCex, Abc_NtkPiNum(pNtk), Abc_NtkPoNum(pNtk), Abc_NtkLatchNum(pNtk) );
27398         Abc_FrameReplaceCex( pAbc, &pCexNew );
27399         return 0;
27400     }
27401     // modify the current network
27402     pNtkRes = Abc_NtkDarTempor( pNtk, nFrames, TimeOut, nConfMax, fUseBmc, fUseTransSigs, fVerbose, fVeryVerbose );
27403     if ( pNtkRes == NULL )
27404     {
27405         Abc_Print( -1, "Temporal decomposition has failed.\n" );
27406         return 1;
27407     }
27408     // replace the current network
27409     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
27410     return 0;
27411 
27412 usage:
27413     Abc_Print( -2, "usage: tempor [-FTC <num>] [-bscvwh]\n" );
27414     Abc_Print( -2, "\t           performs temporal decomposition\n" );
27415     Abc_Print( -2, "\t-F <num> : init logic timeframe count (0 = use leading length) [default = %d]\n", nFrames );
27416     Abc_Print( -2, "\t-T <num> : runtime limit in seconds for BMC (0=unused) [default = %d]\n", TimeOut );
27417     Abc_Print( -2, "\t-C <num> : max number of SAT conflicts in BMC (0=unused) [default = %d]\n", nConfMax );
27418     Abc_Print( -2, "\t-b       : toggle running BMC2 on the init frames [default = %s]\n", fUseBmc? "yes": "no" );
27419     Abc_Print( -2, "\t-s       : toggle using transient signals [default = %s]\n", fUseTransSigs? "yes": "no" );
27420     Abc_Print( -2, "\t-c       : update the current CEX derived for a new AIG after \"tempor\"\n" );
27421     Abc_Print( -2, "\t           to match the current AIG (the one before \"tempor\") [default = %s]\n", fUpdateCex? "yes": "no" );
27422     Abc_Print( -2, "\t-v       : toggle printing verbose output [default = %s]\n", fVerbose? "yes": "no" );
27423     Abc_Print( -2, "\t-w       : toggle printing ternary state space [default = %s]\n", fVeryVerbose? "yes": "no" );
27424     Abc_Print( -2, "\t-h       : print the command usage\n");
27425     return 1;
27426 }
27427 
27428 /**Function*************************************************************
27429 
27430   Synopsis    []
27431 
27432   Description []
27433 
27434   SideEffects []
27435 
27436   SeeAlso     []
27437 
27438 ***********************************************************************/
Abc_CommandInduction(Abc_Frame_t * pAbc,int argc,char ** argv)27439 int Abc_CommandInduction( Abc_Frame_t * pAbc, int argc, char ** argv )
27440 {
27441     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
27442     int nTimeOut;
27443     int nFramesMax;
27444     int nConfMax;
27445     int fUnique;
27446     int fUniqueAll;
27447     int fGetCex;
27448     int fVerbose;
27449     int fVeryVerbose;
27450     int c;
27451     extern int Abc_NtkDarInduction( Abc_Ntk_t * pNtk, int nTimeOut, int nFramesMax, int nConfMax, int fUnique, int fUniqueAll, int fGetCex, int fVerbose, int fVeryVerbose );
27452     // set defaults
27453     nTimeOut     =     0;
27454     nFramesMax   =     0;
27455     nConfMax     =     0;
27456     fUnique      =     0;
27457     fUniqueAll   =     0;
27458     fGetCex      =     0;
27459     fVerbose     =     0;
27460     fVeryVerbose =     0;
27461     Extra_UtilGetoptReset();
27462     while ( ( c = Extra_UtilGetopt( argc, argv, "FCTuaxvwh" ) ) != EOF )
27463     {
27464         switch ( c )
27465         {
27466         case 'F':
27467             if ( globalUtilOptind >= argc )
27468             {
27469                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
27470                 goto usage;
27471             }
27472             nFramesMax = atoi(argv[globalUtilOptind]);
27473             globalUtilOptind++;
27474             if ( nFramesMax < 0 )
27475                 goto usage;
27476             break;
27477         case 'C':
27478             if ( globalUtilOptind >= argc )
27479             {
27480                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
27481                 goto usage;
27482             }
27483             nConfMax = atoi(argv[globalUtilOptind]);
27484             globalUtilOptind++;
27485             if ( nConfMax < 0 )
27486                 goto usage;
27487             break;
27488         case 'T':
27489             if ( globalUtilOptind >= argc )
27490             {
27491                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
27492                 goto usage;
27493             }
27494             nTimeOut = atoi(argv[globalUtilOptind]);
27495             globalUtilOptind++;
27496             if ( nTimeOut < 0 )
27497                 goto usage;
27498             break;
27499         case 'u':
27500             fUnique ^= 1;
27501             break;
27502         case 'a':
27503             fUniqueAll ^= 1;
27504             break;
27505         case 'x':
27506             fGetCex ^= 1;
27507             break;
27508         case 'v':
27509             fVerbose ^= 1;
27510             break;
27511         case 'w':
27512             fVeryVerbose ^= 1;
27513             break;
27514         case 'h':
27515             goto usage;
27516         default:
27517             goto usage;
27518         }
27519     }
27520     if ( pNtk == NULL )
27521     {
27522         Abc_Print( -1, "Empty network.\n" );
27523         return 1;
27524     }
27525     if ( Abc_NtkIsComb(pNtk) )
27526     {
27527         Abc_Print( -1, "The network is combinational.\n" );
27528         return 0;
27529     }
27530     if ( !Abc_NtkIsStrash(pNtk) )
27531     {
27532         Abc_Print( -1, "Currently only works for structurally hashed circuits.\n" );
27533         return 0;
27534     }
27535     if ( Abc_NtkPoNum(pNtk) != 1 )
27536     {
27537         Abc_Print( -1, "Currently this command works only for single-output miter.\n" );
27538         return 0;
27539     }
27540     if ( fUnique && fUniqueAll )
27541     {
27542         Abc_Print( -1, "Only one of the options, \"-u\" or \"-a\", should be selected.\n" );
27543         return 0;
27544     }
27545 
27546     // modify the current network
27547     pAbc->Status = Abc_NtkDarInduction( pNtk, nTimeOut, nFramesMax, nConfMax, fUnique, fUniqueAll, fGetCex, fVerbose, fVeryVerbose );
27548     if ( fGetCex )
27549     {
27550         Abc_FrameReplaceCex( pAbc, &pNtk->pSeqModel );
27551         Abc_Print( 1,"The current CEX in ABC is set to be the CEX to induction.\n" );
27552     }
27553     return 0;
27554 usage:
27555     Abc_Print( -2, "usage: ind [-FCT num] [-uaxvwh]\n" );
27556     Abc_Print( -2, "\t         runs the inductive case of the K-step induction\n" );
27557     Abc_Print( -2, "\t-F num : the max number of timeframes [default = %d]\n", nFramesMax );
27558     Abc_Print( -2, "\t-C num : the max number of conflicts by SAT solver [default = %d]\n", nConfMax );
27559     Abc_Print( -2, "\t-T num : the limit on runtime per output in seconds [default = %d]\n", nTimeOut );
27560     Abc_Print( -2, "\t-u     : toggle adding uniqueness constraints on demand [default = %s]\n", fUnique? "yes": "no" );
27561     Abc_Print( -2, "\t-a     : toggle adding uniqueness constraints always [default = %s]\n", fUniqueAll? "yes": "no" );
27562     Abc_Print( -2, "\t-x     : toggle returning CEX to induction for the top frame [default = %s]\n", fGetCex? "yes": "no" );
27563     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
27564     Abc_Print( -2, "\t-w     : toggle printing additional verbose information [default = %s]\n", fVeryVerbose? "yes": "no" );
27565     Abc_Print( -2, "\t-h     : print the command usage\n");
27566     return 1;
27567 }
27568 
27569 /**Function*************************************************************
27570 
27571   Synopsis    []
27572 
27573   Description []
27574 
27575   SideEffects []
27576 
27577   SeeAlso     []
27578 
27579 ***********************************************************************/
Abc_CommandConstr(Abc_Frame_t * pAbc,int argc,char ** argv)27580 int Abc_CommandConstr( Abc_Frame_t * pAbc, int argc, char ** argv )
27581 {
27582     Abc_Ntk_t * pNtk;
27583     int c;
27584     int nFrames;
27585     int nConfs;
27586     int nProps;
27587     int fRemove;
27588     int fStruct;
27589     int fInvert;
27590     int fOldAlgo;
27591     int fVerbose;
27592     int nConstrs;
27593     extern void Abc_NtkDarConstr( Abc_Ntk_t * pNtk, int nFrames, int nConfs, int nProps, int fStruct, int fOldAlgo, int fVerbose );
27594 
27595     pNtk = Abc_FrameReadNtk(pAbc);
27596     // set defaults
27597     nFrames   =      1;
27598     nConfs    =   1000;
27599     nProps    =   1000;
27600     fRemove   =      0;
27601     fStruct   =      0;
27602     fInvert   =      0;
27603     fOldAlgo  =      0;
27604     fVerbose  =      0;
27605     nConstrs  =     -1;
27606     Extra_UtilGetoptReset();
27607     while ( ( c = Extra_UtilGetopt( argc, argv, "FCPNrsiavh" ) ) != EOF )
27608     {
27609         switch ( c )
27610         {
27611         case 'F':
27612             if ( globalUtilOptind >= argc )
27613             {
27614                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
27615                 goto usage;
27616             }
27617             nFrames = atoi(argv[globalUtilOptind]);
27618             globalUtilOptind++;
27619             if ( nFrames < 0 )
27620                 goto usage;
27621             break;
27622         case 'C':
27623             if ( globalUtilOptind >= argc )
27624             {
27625                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
27626                 goto usage;
27627             }
27628             nConfs = atoi(argv[globalUtilOptind]);
27629             globalUtilOptind++;
27630             if ( nConfs < 0 )
27631                 goto usage;
27632             break;
27633         case 'P':
27634             if ( globalUtilOptind >= argc )
27635             {
27636                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
27637                 goto usage;
27638             }
27639             nProps = atoi(argv[globalUtilOptind]);
27640             globalUtilOptind++;
27641             if ( nProps < 0 )
27642                 goto usage;
27643             break;
27644         case 'N':
27645             if ( globalUtilOptind >= argc )
27646             {
27647                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
27648                 goto usage;
27649             }
27650             nConstrs = atoi(argv[globalUtilOptind]);
27651             globalUtilOptind++;
27652             if ( nConstrs < 0 )
27653                 goto usage;
27654             break;
27655         case 'r':
27656             fRemove ^= 1;
27657             break;
27658         case 's':
27659             fStruct ^= 1;
27660             break;
27661         case 'i':
27662             fInvert ^= 1;
27663             break;
27664         case 'a':
27665             fOldAlgo ^= 1;
27666             break;
27667         case 'v':
27668             fVerbose ^= 1;
27669             break;
27670         case 'h':
27671             goto usage;
27672         default:
27673             goto usage;
27674         }
27675     }
27676     if ( pNtk == NULL )
27677     {
27678         Abc_Print( -1, "Empty network.\n" );
27679         return 1;
27680     }
27681     if ( !Abc_NtkIsStrash(pNtk) )
27682     {
27683         Abc_Print( -1, "Currently only works for structurally hashed circuits.\n" );
27684         return 0;
27685     }
27686     if ( fRemove )
27687     {
27688         if ( Abc_NtkConstrNum(pNtk) == 0 )
27689         {
27690             Abc_Print( -1, "Constraints are not defined.\n" );
27691             return 0;
27692         }
27693         Abc_Print( 1, "Constraints are converted to be primary outputs.\n" );
27694         pNtk->nConstrs = 0;
27695         return 0;
27696     }
27697     // consider the case of manual constraint definition
27698     if ( nConstrs >= 0 )
27699     {
27700         if ( Abc_NtkIsComb(pNtk) )
27701             Abc_Print( 0, "The network is combinational.\n" );
27702         if ( Abc_NtkConstrNum(pNtk) > 0 )
27703             Abc_Print( 0, "The network currently has %d constraints.\n", Abc_NtkConstrNum(pNtk) );
27704         if ( nConstrs >= Abc_NtkPoNum(pNtk) )
27705         {
27706             Abc_Print( -1, "The number of constraints specified (%d) should be less than POs (%d).\n", nConstrs, Abc_NtkPoNum(pNtk) );
27707             return 0;
27708         }
27709         Abc_Print( 1, "Setting the last %d POs as constraint outputs.\n", nConstrs );
27710         pNtk->nConstrs = nConstrs;
27711         return 0;
27712     }
27713     // consider the case of already defined constraints
27714     if ( Abc_NtkConstrNum(pNtk) > 0 )
27715     {
27716         extern void Abc_NtkDarConstrProfile( Abc_Ntk_t * pNtk, int fVerbose );
27717         if ( fInvert )
27718         {
27719             Abc_NtkInvertConstraints( pNtk );
27720             if ( Abc_NtkConstrNum(pNtk) == 1 )
27721                 Abc_Print( 1, "The output of %d constraint is complemented.\n", Abc_NtkConstrNum(pNtk) );
27722             else
27723                 Abc_Print( 1, "The outputs of %d constraints are complemented.\n", Abc_NtkConstrNum(pNtk) );
27724         }
27725         if ( fVerbose )
27726             Abc_NtkDarConstrProfile( pNtk, fVerbose );
27727         return 0;
27728     }
27729     if ( Abc_NtkIsComb(pNtk) )
27730     {
27731         Abc_Print( -1, "The network is combinational.\n" );
27732         return 0;
27733     }
27734     // detect constraints using functional/structural methods
27735     Abc_NtkDarConstr( pNtk, nFrames, nConfs, nProps, fStruct, fOldAlgo, fVerbose );
27736     return 0;
27737 usage:
27738     Abc_Print( -2, "usage: constr [-FCPN num] [-risavh]\n" );
27739     Abc_Print( -2, "\t         a toolkit for constraint manipulation\n" );
27740     Abc_Print( -2, "\t         if constraints are absent, detect them functionally\n" );
27741     Abc_Print( -2, "\t         if constraints are present, profiles them using random simulation\n" );
27742     Abc_Print( -2, "\t         (constraints fail when any of them becomes 1 in any timeframe)\n" );
27743     Abc_Print( -2, "\t-F num : the max number of timeframes to consider [default = %d]\n", nFrames );
27744     Abc_Print( -2, "\t-C num : the max number of conflicts in SAT solving [default = %d]\n", nConfs );
27745     Abc_Print( -2, "\t-P num : the max number of propagations in SAT solving [default = %d]\n", nProps );
27746     Abc_Print( -2, "\t-N num : manually set the last <num> POs to be constraints [default = %d]\n", nConstrs );
27747     Abc_Print( -2, "\t-r     : manually remove the constraints [default = %s]\n", fRemove? "yes": "no" );
27748     Abc_Print( -2, "\t-i     : toggle inverting already defined constraints [default = %s]\n", fInvert? "yes": "no" );
27749     Abc_Print( -2, "\t-s     : toggle using structural detection methods [default = %s]\n", fStruct? "yes": "no" );
27750     Abc_Print( -2, "\t-a     : toggle fast implication detection [default = %s]\n", !fOldAlgo? "yes": "no" );
27751     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
27752     Abc_Print( -2, "\t-h     : print the command usage\n");
27753     return 1;
27754 }
27755 
27756 /**Function*************************************************************
27757 
27758   Synopsis    []
27759 
27760   Description []
27761 
27762   SideEffects []
27763 
27764   SeeAlso     []
27765 
27766 ***********************************************************************/
Abc_CommandUnfold(Abc_Frame_t * pAbc,int argc,char ** argv)27767 int Abc_CommandUnfold( Abc_Frame_t * pAbc, int argc, char ** argv )
27768 {
27769     Abc_Ntk_t * pNtk, * pNtkRes;
27770     int nFrames;
27771     int nConfs;
27772     int nProps;
27773     int fStruct;
27774     int fOldAlgo;
27775     int fVerbose;
27776     int c;
27777     extern Abc_Ntk_t * Abc_NtkDarUnfold( Abc_Ntk_t * pNtk, int nFrames, int nConfs, int nProps, int fStruct, int fOldAlgo, int fVerbose );
27778     pNtk = Abc_FrameReadNtk(pAbc);
27779     // set defaults
27780     nFrames   =      1;
27781     nConfs    =   1000;
27782     nProps    =   1000;
27783     fStruct   =      0;
27784     fOldAlgo  =      0;
27785     fVerbose  =      0;
27786     Extra_UtilGetoptReset();
27787     while ( ( c = Extra_UtilGetopt( argc, argv, "FCPsavh" ) ) != EOF )
27788     {
27789         switch ( c )
27790         {
27791         case 'F':
27792             if ( globalUtilOptind >= argc )
27793             {
27794                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
27795                 goto usage;
27796             }
27797             nFrames = atoi(argv[globalUtilOptind]);
27798             globalUtilOptind++;
27799             if ( nFrames < 0 )
27800                 goto usage;
27801             break;
27802         case 'C':
27803             if ( globalUtilOptind >= argc )
27804             {
27805                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
27806                 goto usage;
27807             }
27808             nConfs = atoi(argv[globalUtilOptind]);
27809             globalUtilOptind++;
27810             if ( nConfs < 0 )
27811                 goto usage;
27812             break;
27813         case 'P':
27814             if ( globalUtilOptind >= argc )
27815             {
27816                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
27817                 goto usage;
27818             }
27819             nProps = atoi(argv[globalUtilOptind]);
27820             globalUtilOptind++;
27821             if ( nProps < 0 )
27822                 goto usage;
27823             break;
27824         case 's':
27825             fStruct ^= 1;
27826             break;
27827         case 'a':
27828             fOldAlgo ^= 1;
27829             break;
27830         case 'v':
27831             fVerbose ^= 1;
27832             break;
27833         case 'h':
27834             goto usage;
27835         default:
27836             goto usage;
27837         }
27838     }
27839     if ( pNtk == NULL )
27840     {
27841         Abc_Print( -1, "Empty network.\n" );
27842         return 1;
27843     }
27844     if ( Abc_NtkIsComb(pNtk) && Abc_NtkPoNum(pNtk) > 1 )
27845     {
27846         Abc_Print( -1, "Combinational miter has more than one PO.\n" );
27847         return 0;
27848     }
27849     if ( Abc_NtkIsComb(pNtk) )
27850     {
27851         extern Gia_Man_t * Gia_ManDupWithConstr( Gia_Man_t * p );
27852         Gia_Man_t * pNew;
27853         Aig_Man_t * pAig = Abc_NtkToDar( pNtk, 0, 0 );
27854         Gia_Man_t * pGia = Gia_ManFromAigSimple( pAig );
27855         Aig_ManStop( pAig );
27856         pNew = Gia_ManDupWithConstr( pGia );
27857         Gia_ManStop( pGia );
27858         if ( pNew == NULL )
27859         {
27860             Abc_Print( -1, "Cannot extract constrains from the miter.\n" );
27861             return 0;
27862         }
27863         pAig = Gia_ManToAigSimple( pNew );
27864         Gia_ManStop( pNew );
27865         pNtkRes = Abc_NtkFromAigPhase( pAig );
27866         Aig_ManStop( pAig );
27867         ABC_FREE( pNtkRes->pName );
27868         pNtkRes->pName = Extra_UtilStrsav( pNtk->pName );
27869         // replace the current network
27870         Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
27871         return 0;
27872     }
27873     if ( !Abc_NtkIsStrash(pNtk) )
27874     {
27875         Abc_Print( -1, "Currently only works for structurally hashed circuits.\n" );
27876         return 0;
27877     }
27878     if ( Abc_NtkConstrNum(pNtk) > 0 )
27879     {
27880         Abc_Print( -1, "Constraints are already extracted.\n" );
27881         return 0;
27882     }
27883     if ( Abc_NtkPoNum(pNtk) > 1 && !fStruct )
27884     {
27885         Abc_Print( -1, "Functional constraint extraction works for single-output miters (use \"orpos\").\n" );
27886         return 0;
27887     }
27888     // modify the current network
27889     pNtkRes = Abc_NtkDarUnfold( pNtk, nFrames, nConfs, nProps, fStruct, fOldAlgo, fVerbose );
27890     if ( pNtkRes == NULL )
27891     {
27892         Abc_Print( 1,"Transformation has failed.\n" );
27893         return 0;
27894     }
27895     // replace the current network
27896     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
27897     return 0;
27898 usage:
27899     Abc_Print( -2, "usage: unfold [-FCP num] [-savh]\n" );
27900     Abc_Print( -2, "\t         unfold hidden constraints as separate outputs\n" );
27901     Abc_Print( -2, "\t-F num : the max number of timeframes to consider [default = %d]\n", nFrames );
27902     Abc_Print( -2, "\t-C num : the max number of conflicts in SAT solving [default = %d]\n", nConfs );
27903     Abc_Print( -2, "\t-P num : the max number of constraint propagations [default = %d]\n", nProps );
27904     Abc_Print( -2, "\t-s     : toggle detecting structural constraints [default = %s]\n", fStruct? "yes": "no" );
27905     Abc_Print( -2, "\t-a     : toggle fast implication detection [default = %s]\n", !fOldAlgo? "yes": "no" );
27906     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
27907     Abc_Print( -2, "\t-h     : print the command usage\n");
27908     return 1;
27909 }
27910 
27911 /**Function*************************************************************
27912 
27913   Synopsis    []
27914 
27915   Description []
27916 
27917   SideEffects []
27918 
27919   SeeAlso     []
27920 
27921 ***********************************************************************/
Abc_CommandFold(Abc_Frame_t * pAbc,int argc,char ** argv)27922 int Abc_CommandFold( Abc_Frame_t * pAbc, int argc, char ** argv )
27923 {
27924     Abc_Ntk_t * pNtk, * pNtkRes;
27925     int fCompl;
27926     int fVerbose;
27927     int c;
27928     extern Abc_Ntk_t * Abc_NtkDarFold( Abc_Ntk_t * pNtk, int fCompl, int fVerbose );
27929     pNtk = Abc_FrameReadNtk(pAbc);
27930     // set defaults
27931     fCompl    =   0;
27932     fVerbose  =   0;
27933     Extra_UtilGetoptReset();
27934     while ( ( c = Extra_UtilGetopt( argc, argv, "cvh" ) ) != EOF )
27935     {
27936         switch ( c )
27937         {
27938         case 'c':
27939             fCompl ^= 1;
27940             break;
27941         case 'v':
27942             fVerbose ^= 1;
27943             break;
27944         case 'h':
27945             goto usage;
27946         default:
27947             goto usage;
27948         }
27949     }
27950     if ( pNtk == NULL )
27951     {
27952         Abc_Print( -1, "Empty network.\n" );
27953         return 1;
27954     }
27955     if ( !Abc_NtkIsStrash(pNtk) )
27956     {
27957         Abc_Print( -1, "Currently only works for structurally hashed circuits.\n" );
27958         return 0;
27959     }
27960     if ( Abc_NtkConstrNum(pNtk) == 0 )
27961     {
27962         Abc_Print( 0, "The network has no constraints.\n" );
27963         return 0;
27964     }
27965     if ( Abc_NtkConstrNum(pNtk) == Abc_NtkPoNum(pNtk) )
27966     {
27967         Abc_Print( 0, "The network has no primary outputs (only constraints).\n" );
27968         return 0;
27969     }
27970     if ( Abc_NtkIsComb(pNtk) )
27971         Abc_Print( 0, "The network is combinational.\n" );
27972     // modify the current network
27973     pNtkRes = Abc_NtkDarFold( pNtk, fCompl, fVerbose );
27974     if ( pNtkRes == NULL )
27975     {
27976         Abc_Print( 1,"Transformation has failed.\n" );
27977         return 0;
27978     }
27979     // replace the current network
27980     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
27981     return 0;
27982 usage:
27983     Abc_Print( -2, "usage: fold [-cvh]\n" );
27984     Abc_Print( -2, "\t         folds constraints represented as separate outputs\n" );
27985     Abc_Print( -2, "\t         (constraints fail when any of them becomes 1 in any timeframe)\n" );
27986     Abc_Print( -2, "\t-c     : toggle complementing constraints while folding [default = %s]\n", fCompl? "yes": "no" );
27987     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
27988     Abc_Print( -2, "\t-h     : print the command usage\n");
27989     return 1;
27990 }
27991 
27992 /**Function*************************************************************
27993 
27994   Synopsis    []
27995 
27996   Description []
27997 
27998   SideEffects []
27999 
28000   SeeAlso     []
28001 
28002 ***********************************************************************/
Abc_CommandBm(Abc_Frame_t * pAbc,int argc,char ** argv)28003 int Abc_CommandBm( Abc_Frame_t * pAbc, int argc, char ** argv )
28004 {
28005     FILE * pOut, * pErr;
28006     Abc_Ntk_t *pNtk, *pNtk1, *pNtk2;
28007     int fDelete1, fDelete2;
28008     char ** pArgvNew;
28009     int c, nArgcNew;
28010     int p_equivalence = FALSE;
28011     extern void bmGateWay( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int p_equivalence );
28012 
28013     pNtk = Abc_FrameReadNtk(pAbc);
28014     pOut = Abc_FrameReadOut(pAbc);
28015     pErr = Abc_FrameReadErr(pAbc);
28016 
28017     Extra_UtilGetoptReset();
28018     while ( ( c = Extra_UtilGetopt( argc, argv, "Ph" ) ) != EOF )
28019     {
28020         switch ( c )
28021         {
28022         case 'h':
28023             goto usage;
28024         case 'P':
28025             p_equivalence = 1;
28026             break;
28027         default:
28028             Abc_Print( -2, "Unknown switch.\n");
28029             goto usage;
28030         }
28031     }
28032 
28033     pArgvNew = argv + globalUtilOptind;
28034     nArgcNew = argc - globalUtilOptind;
28035     if ( !Abc_NtkPrepareTwoNtks( pErr, pNtk, pArgvNew, nArgcNew , &pNtk1, &pNtk2, &fDelete1, &fDelete2, 1 ) )
28036         return 1;
28037 
28038     if( (unsigned)Abc_NtkPiNum(pNtk1) != (unsigned)Abc_NtkPiNum(pNtk2) || (unsigned)Abc_NtkPoNum(pNtk1) != (unsigned)Abc_NtkPoNum(pNtk2) )
28039     {
28040         Abc_Print( -2, "Mismatch in the number of inputs or outputs\n");
28041         if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
28042         if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
28043         return 1;
28044     }
28045 
28046     bmGateWay( pNtk1, pNtk2, p_equivalence );
28047 
28048     if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
28049     if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
28050     return 0;
28051 
28052 usage:
28053     Abc_Print( -2, "usage: bm [-P] <file1> <file2>\n" );
28054     Abc_Print( -2, "\t        performs Boolean matching (P-equivalence & PP-equivalence)\n" );
28055     Abc_Print( -2, "\t        for equivalent circuits, I/O matches are printed in IOmatch.txt\n" );
28056     Abc_Print( -2, "\t-P    : performs P-equivalnce checking\n");
28057     Abc_Print( -2, "\t        default is PP-equivalence checking (when -P is not provided)\n" );
28058     Abc_Print( -2, "\t-h    : print the command usage\n");
28059     Abc_Print( -2, "\tfile1 : the file with the first network\n");
28060     Abc_Print( -2, "\tfile2 : the file with the second network\n");
28061 
28062     Abc_Print( -2, "\t        \n" );
28063     Abc_Print( -2, "\t        This command was contributed by Hadi Katebi from U Michigan.\n" );
28064     Abc_Print( -2, "\t        The paper describing the method: H. Katebi and I. L. Markov.\n" );
28065     Abc_Print( -2, "\t        \"Large-scale Boolean matching\". Proc. DATE 2010. \n" );
28066     Abc_Print( -2, "\t        http://www.eecs.umich.edu/~imarkov/pubs/conf/date10-match.pdf\n" );
28067 //    Abc_Print( -2, "\t        \n" );
28068 
28069     return 1;
28070 }
28071 
28072 /**Function*************************************************************
28073 
28074   Synopsis    []
28075 
28076   Description []
28077 
28078   SideEffects []
28079 
28080   SeeAlso     []
28081 
28082 ***********************************************************************/
Abc_CommandBm2(Abc_Frame_t * pAbc,int argc,char ** argv)28083 int Abc_CommandBm2( Abc_Frame_t * pAbc, int argc, char ** argv )
28084 {
28085     FILE * pOut, * pErr;
28086     Abc_Ntk_t *pNtk, *pNtk1, *pNtk2;
28087     int fDelete1, fDelete2;
28088     Abc_Obj_t * pObj;
28089     char ** pArgvNew;
28090     int c, nArgcNew, i;
28091 
28092     extern void saucyGateWay( Abc_Ntk_t * pNtk, Abc_Obj_t * pNodePo, FILE * gFile, int fBooleanMatching,
28093                               int fLookForSwaps, int fFixOutputs, int fFixInputs, int fQuiet, int fPrintTree);
28094 
28095     pNtk = Abc_FrameReadNtk(pAbc);
28096     pOut = Abc_FrameReadOut(pAbc);
28097     pErr = Abc_FrameReadErr(pAbc);
28098 
28099     Extra_UtilGetoptReset();
28100     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
28101     {
28102         switch ( c )
28103         {
28104         case 'h':
28105             goto usage;
28106         default:
28107             Abc_Print( -2, "Unknown switch.\n");
28108             goto usage;
28109         }
28110     }
28111 
28112     pArgvNew = argv + globalUtilOptind;
28113     nArgcNew = argc - globalUtilOptind;
28114     if ( !Abc_NtkPrepareTwoNtks( pErr, pNtk, pArgvNew, nArgcNew , &pNtk1, &pNtk2, &fDelete1, &fDelete2, 1 ) )
28115         return 1;
28116 
28117     if( (unsigned)Abc_NtkPiNum(pNtk1) != (unsigned)Abc_NtkPiNum(pNtk2) ||
28118         (unsigned)Abc_NtkPoNum(pNtk1) != (unsigned)Abc_NtkPoNum(pNtk2) )
28119     {
28120         Abc_Print( -2, "Mismatch in the number of inputs or outputs\n");
28121         Abc_Print( -2, "*** Networks are NOT equivalent ***\n");
28122         if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
28123         if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
28124         return 1;
28125     }
28126 
28127     Abc_NtkPermute(pNtk2, 1, 1, 0, NULL );
28128     Abc_NtkShortNames(pNtk2);
28129 
28130     Abc_NtkForEachCi( pNtk1, pObj, i ) {
28131         char * newName = Abc_ObjNamePrefix( pObj, "N1:" );
28132         Nm_ManDeleteIdName( pNtk1->pManName, pObj->Id);
28133         Abc_ObjAssignName( pObj, newName, NULL );
28134     }
28135     Abc_NtkForEachCo( pNtk1, pObj, i ) {
28136         char * newName = Abc_ObjNamePrefix( pObj, "N1:" );
28137         Nm_ManDeleteIdName( pNtk1->pManName, pObj->Id);
28138         Abc_ObjAssignName( pObj, newName, NULL );
28139     }
28140 
28141     Abc_NtkForEachCi( pNtk2, pObj, i ) {
28142         char * newName = Abc_ObjNamePrefix( pObj, "N2:" );
28143         Nm_ManDeleteIdName( pNtk2->pManName, pObj->Id);
28144         Abc_ObjAssignName( pObj, newName, NULL );
28145     }
28146     Abc_NtkForEachCo( pNtk2, pObj, i ) {
28147         char * newName = Abc_ObjNamePrefix( pObj, "N2:" );
28148         Nm_ManDeleteIdName( pNtk2->pManName, pObj->Id);
28149         Abc_ObjAssignName( pObj, newName, NULL );
28150     }
28151 
28152     Abc_NtkAppend( pNtk1, pNtk2, 1 );
28153     saucyGateWay( pNtk1, NULL, NULL, 1, 0, 0, 0, 0, 0);
28154 
28155     if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
28156     if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
28157     return 0;
28158 
28159 usage:
28160     Abc_Print( -2, "usage: bm2  <file1> <file2>\n" );
28161     Abc_Print( -2, "\t        performs Boolean matching (PP-equivalence)\n" );
28162     Abc_Print( -2, "\t        for equivalent circuits, permutation that maps one circuit\n" );
28163     Abc_Print( -2, "\t        to another is printed to standard output (PIs and POs of the\n" );
28164     Abc_Print( -2, "\t        first network have prefix \"N1:\", while PIs and POs of the\n" );
28165     Abc_Print( -2, "\t        second network have prefix \"N2:\")\n" );
28166     Abc_Print( -2, "\t-h    : print the command usage\n");
28167     Abc_Print( -2, "\tfile1 : the file with the first network\n");
28168     Abc_Print( -2, "\tfile2 : the file with the second network\n");
28169 
28170     Abc_Print( -2, "\t        \n" );
28171     Abc_Print( -2, "\t        This command was contributed by Hadi Katebi from U Michigan.\n" );
28172     Abc_Print( -2, "\t        The paper describing the method: H. Katebi, K. Sakallah and\n");
28173     Abc_Print( -2, "\t        I. L. Markov.\n" );
28174     Abc_Print( -2, "\t        \"Generalized Boolean Symmetries Through Nested Partition\n");
28175     Abc_Print( -2, "\t        Refinement\". Proc. ICCAD 2013. \n" );
28176     //Abc_Print( -2, "\t        http://www.eecs.umich.edu/~imarkov/pubs/conf/date10-match.pdf\n" );
28177 //    Abc_Print( -2, "\t        \n" );
28178 
28179     return 1;
28180 }
28181 
28182 /**Function*************************************************************
28183 
28184   Synopsis    []
28185 
28186   Description []
28187 
28188   SideEffects []
28189 
28190   SeeAlso     []
28191 
28192 ***********************************************************************/
Abc_CommandSaucy(Abc_Frame_t * pAbc,int argc,char ** argv)28193 int Abc_CommandSaucy( Abc_Frame_t * pAbc, int argc, char ** argv )
28194 {
28195     Abc_Ntk_t *pNtk;
28196     char * outputName = NULL;
28197     FILE * gFile = NULL;
28198     int fOutputsOneAtTime = 0;
28199     int fFixOutputs = 0;
28200     int fFixInputs = 0;
28201     int fLookForSwaps = 0;
28202     int fQuiet = 0;
28203     int fPrintTree = 0;
28204     int c;
28205 
28206     extern void saucyGateWay( Abc_Ntk_t * pNtk, Abc_Obj_t * pNodePo, FILE * gFile, int fBooleanMatching,
28207                               int fLookForSwaps, int fFixOutputs, int fFixInputs, int fQuiet, int fPrintTree);
28208 
28209     Extra_UtilGetoptReset();
28210     while ( ( c = Extra_UtilGetopt( argc, argv, "OFiosqvh" ) ) != EOF )
28211     {
28212         switch ( c )
28213         {
28214         case 'O':
28215             if ( globalUtilOptind >= argc )
28216             {
28217                 Abc_Print( -1, "Command line switch \"-O\" should be followed by an output name or the keyword all.\n" );
28218                 goto usage;
28219             }
28220             outputName = argv[globalUtilOptind];
28221             if ( !strcmp(argv[globalUtilOptind], "all") )
28222                 fOutputsOneAtTime ^= 1;
28223             globalUtilOptind++;
28224             break;
28225         case 'F':
28226             if ( globalUtilOptind >= argc )
28227             {
28228                 Abc_Print( -1, "Command line switch \"-F\" should be followed by a file name.\n" );
28229                 goto usage;
28230             }
28231             if ( (gFile = fopen( argv[globalUtilOptind], "w" )) == NULL )
28232             {
28233                 Abc_Print( -1, "Cannot create output file \"%s\". ", argv[globalUtilOptind] );
28234                 return 1;
28235             }
28236             globalUtilOptind++;
28237             break;
28238         case 'i':
28239             fFixOutputs ^= 1;
28240             break;
28241         case 'o':
28242             fFixInputs ^= 1;
28243             break;
28244         case 's':
28245             fLookForSwaps ^= 1;
28246             break;
28247         case 'q':
28248             fQuiet ^= 1;
28249             break;
28250         case 'v':
28251             fPrintTree ^= 1;
28252             break;
28253         case 'h':
28254             goto usage;
28255         default:
28256             Abc_Print( -2, "Unknown switch.\n");
28257             goto usage;
28258         }
28259     }
28260 
28261     pNtk = Abc_FrameReadNtk(pAbc);
28262 
28263     if ( pNtk == NULL )
28264     {
28265         Abc_Print( -1, "Empty network.\n" );
28266         return 1;
28267     }
28268     if ( !Abc_NtkIsStrash(pNtk) )
28269     {
28270         Abc_Print( -1, "This command works only for AIGs (run \"strash\").\n" );
28271         return 1;
28272     }
28273 
28274     pNtk = Abc_NtkDup( pNtk );
28275     Abc_NtkOrderObjsByName( pNtk, 1 );
28276 
28277     if (fOutputsOneAtTime) {
28278         int i;
28279         Abc_Obj_t * pNodePo;
28280         FILE * hadi = fopen("hadi.txt", "w");
28281         Abc_NtkForEachPo( pNtk, pNodePo, i ) {
28282             printf("Ouput %s\n\n", Abc_ObjName(pNodePo));
28283             saucyGateWay( pNtk, pNodePo, gFile, 0, fLookForSwaps, fFixOutputs, fFixInputs, fQuiet, fPrintTree );
28284             printf("----------------------------------------\n");
28285         }
28286         fclose(hadi);
28287     } else if (outputName != NULL) {
28288         int i;
28289         Abc_Obj_t * pNodePo;
28290         Abc_NtkForEachPo( pNtk, pNodePo, i ) {
28291             if (!strcmp(Abc_ObjName(pNodePo), outputName)) {
28292                 saucyGateWay( pNtk, pNodePo, gFile, 0, fLookForSwaps, fFixOutputs, fFixInputs, fQuiet, fPrintTree );
28293                 Abc_NtkDelete( pNtk );
28294                 return 0;
28295             }
28296         }
28297         Abc_Print( -1, "Output not found\n" );
28298         return 1;
28299     } else
28300         saucyGateWay( pNtk, NULL, gFile, 0, fLookForSwaps, fFixOutputs, fFixInputs, fQuiet, fPrintTree );
28301 
28302     if (gFile != NULL) fclose(gFile);
28303     Abc_NtkDelete( pNtk );
28304     return 0;
28305 
28306 usage:
28307     Abc_Print( -2, "usage: saucy3 [-O <name>] [-F <file>] [-iosqvh]\n\n" );
28308     Abc_Print( -2, "\t            computes functional symmetries of the netowrk\n" );
28309     Abc_Print( -2, "\t            prints symmetry generators to the standard output\n" );
28310     Abc_Print( -2, "\t-O <name> : (optional) compute symmetries only for output given by name\n");
28311     Abc_Print( -2, "\t            only inputs in the output cone are permuted\n");
28312     Abc_Print( -2, "\t            (special case) name=all, compute symmetries for each\n" );
28313     Abc_Print( -2, "\t            output, but only one output at a time\n" );
28314     Abc_Print( -2, "\t            [default = compute symmetries by permuting all I/Os]\n" );
28315     Abc_Print( -2, "\t-F <file> : print symmetry generators to file [default = stdout]\n");
28316     Abc_Print( -2, "\t-i        : permute just the inputs (fix the outputs) [default = no]\n");
28317     Abc_Print( -2, "\t-o        : permute just the outputs (fix the inputs) [default = no]\n");
28318     Abc_Print( -2, "\t-s        : only look for swaps of inputs [default = no]\n");
28319     Abc_Print( -2, "\t-q        : quiet (do not print symmetry generators) [default = no]\n");
28320     Abc_Print( -2, "\t-v        : verbose (print the search tree) [default = no]\n");
28321     Abc_Print( -2, "\t-h        : print the command usage\n");
28322 
28323     Abc_Print( -2, "\t            \n" );
28324     Abc_Print( -2, "\t            This command was contributed by Hadi Katebi from U Michigan.\n" );
28325     Abc_Print( -2, "\t            The paper describing the method: H. Katebi, K. Sakallah and\n");
28326     Abc_Print( -2, "\t            I. L. Markov.\n" );
28327     Abc_Print( -2, "\t            \"Generalized Boolean Symmetries Through Nested Partition\n");
28328     Abc_Print( -2, "\t            Refinement\". Proc. ICCAD 2013. \n" );
28329     //Abc_Print( -2, "\t          http://www.eecs.umich.edu/~imarkov/pubs/conf/date10-match.pdf\n" );
28330     Abc_Print( -2, "\t            Saucy webpage: http://vlsicad.eecs.umich.edu/BK/SAUCY/\n" );
28331 
28332     return 1;
28333 }
28334 
28335 /**Function*************************************************************
28336 
28337   Synopsis    []
28338 
28339   Description []
28340 
28341   SideEffects []
28342 
28343   SeeAlso     []
28344 
28345 ***********************************************************************/
Abc_CommandTestCex(Abc_Frame_t * pAbc,int argc,char ** argv)28346 int Abc_CommandTestCex( Abc_Frame_t * pAbc, int argc, char ** argv )
28347 {
28348     Abc_Ntk_t * pNtk;
28349     int c;
28350     int nOutputs = 0;
28351     int fCheckAnd = 1;
28352     Extra_UtilGetoptReset();
28353     while ( ( c = Extra_UtilGetopt( argc, argv, "Oah" ) ) != EOF )
28354     {
28355         switch ( c )
28356         {
28357         case 'O':
28358             if ( globalUtilOptind >= argc )
28359             {
28360                 Abc_Print( -1, "Command line switch \"-O\" should be followed by an integer.\n" );
28361                 goto usage;
28362             }
28363             nOutputs = atoi(argv[globalUtilOptind]);
28364             globalUtilOptind++;
28365             if ( nOutputs < 0 )
28366                 goto usage;
28367             break;
28368         case 'a':
28369             fCheckAnd ^= 1;
28370             break;
28371         case 'h':
28372             goto usage;
28373         default:
28374             Abc_Print( -2, "Unknown switch.\n");
28375             goto usage;
28376         }
28377     }
28378 
28379     if ( pAbc->pCex == NULL )
28380     {
28381         Abc_Print( 1, "There is no current cex.\n");
28382         return 0;
28383     }
28384 
28385     if ( !fCheckAnd )
28386     {
28387         // check the main AIG
28388         pNtk = Abc_FrameReadNtk(pAbc);
28389         if ( pNtk == NULL )
28390             Abc_Print( 1, "Main AIG: There is no current network.\n");
28391         else if ( !Abc_NtkIsStrash(pNtk) )
28392             Abc_Print( 1, "Main AIG: The current network is not an AIG.\n");
28393         else if ( Abc_NtkPiNum(pNtk) != pAbc->pCex->nPis )
28394             Abc_Print( 1, "Main AIG: The number of PIs (%d) is different from cex (%d).\n", Abc_NtkPiNum(pNtk), pAbc->pCex->nPis );
28395         else
28396         {
28397             extern int Abc_NtkVerifyCex( Abc_Ntk_t * pNtk, Abc_Cex_t * p );
28398             int iPoOld = pAbc->pCex->iPo;
28399             pAbc->pCex->iPo = Abc_NtkVerifyCex( pNtk, pAbc->pCex );
28400             if ( pAbc->pCex->iPo == -1 )
28401                 Abc_Print( 1, "Main AIG: The cex does not fail any outputs.\n" );
28402             else if ( iPoOld != pAbc->pCex->iPo )
28403                 Abc_Print( 1, "Main AIG: The cex refined PO %d instead of PO %d.\n", pAbc->pCex->iPo, iPoOld );
28404             else
28405                 Abc_Print( 1, "Main AIG: The cex is correct.\n" );
28406         }
28407     }
28408     else
28409     {
28410         // check the AND AIG
28411         if ( pAbc->pGia == NULL )
28412             Abc_Print( 1, "And  AIG: There is no current network.\n");
28413         else if ( Gia_ManPiNum(pAbc->pGia) != pAbc->pCex->nPis )
28414             Abc_Print( 1, "And  AIG: The number of PIs (%d) is different from cex (%d).\n", Gia_ManPiNum(pAbc->pGia), pAbc->pCex->nPis );
28415         else
28416         {
28417             int iPoOld = pAbc->pCex->iPo;
28418             pAbc->pCex->iPo = Gia_ManFindFailedPoCex( pAbc->pGia, pAbc->pCex, nOutputs );
28419             if ( pAbc->pCex->iPo == -1 )
28420                 Abc_Print( 1, "And  AIG: The cex does not fail any outputs.\n" );
28421             else if ( iPoOld != pAbc->pCex->iPo )
28422                 Abc_Print( 1, "And  AIG: The cex refined PO %d instead of PO %d.\n", pAbc->pCex->iPo, iPoOld );
28423             else
28424                 Abc_Print( 1, "And  AIG: The cex is correct.\n" );
28425         }
28426     }
28427     return 0;
28428 
28429 usage:
28430     Abc_Print( -2, "usage: testcex [-O num] [-ah]\n" );
28431     Abc_Print( -2, "\t         tests the current cex against the current AIG or the &-AIG\n" );
28432     Abc_Print( -2, "\t-O num : the number of real POs in the PO list [default = %d]\n", nOutputs );
28433     Abc_Print( -2, "\t-a     : toggle checking the current AIG or the &-AIG [default = %s]\n", fCheckAnd ? "&-AIG": "current AIG" );
28434     Abc_Print( -2, "\t-h     : print the command usage\n");
28435     return 1;
28436 }
28437 
28438 /**Function*************************************************************
28439 
28440   Synopsis    []
28441 
28442   Description []
28443 
28444   SideEffects []
28445 
28446   SeeAlso     []
28447 
28448 ***********************************************************************/
Abc_CommandPdr(Abc_Frame_t * pAbc,int argc,char ** argv)28449 int Abc_CommandPdr( Abc_Frame_t * pAbc, int argc, char ** argv )
28450 {
28451     extern int Abc_NtkDarPdr( Abc_Ntk_t * pNtk, Pdr_Par_t * pPars );
28452     Pdr_Par_t Pars, * pPars = &Pars;
28453     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc), * pNtkUsed, * pNtkFlop = NULL;
28454     char * pLogFileName = NULL;
28455     int c;
28456     Pdr_ManSetDefaultParams( pPars );
28457     Extra_UtilGetoptReset();
28458     while ( ( c = Extra_UtilGetopt( argc, argv, "MFCDQTHGSLIaxrmuyfqipdegjonctkvwzh" ) ) != EOF )
28459     {
28460         switch ( c )
28461         {
28462         case 'M':
28463             if ( globalUtilOptind >= argc )
28464             {
28465                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
28466                 goto usage;
28467             }
28468             pPars->nRecycle = atoi(argv[globalUtilOptind]);
28469             globalUtilOptind++;
28470             if ( pPars->nRecycle < 0 )
28471                 goto usage;
28472             break;
28473         case 'F':
28474             if ( globalUtilOptind >= argc )
28475             {
28476                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
28477                 goto usage;
28478             }
28479             pPars->nFrameMax = atoi(argv[globalUtilOptind]);
28480             globalUtilOptind++;
28481             if ( pPars->nFrameMax < 0 )
28482                 goto usage;
28483             break;
28484         case 'C':
28485             if ( globalUtilOptind >= argc )
28486             {
28487                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
28488                 goto usage;
28489             }
28490             pPars->nConfLimit = atoi(argv[globalUtilOptind]);
28491             globalUtilOptind++;
28492             if ( pPars->nConfLimit < 0 )
28493                 goto usage;
28494             break;
28495         case 'D':
28496             if ( globalUtilOptind >= argc )
28497             {
28498                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
28499                 goto usage;
28500             }
28501             pPars->nConfGenLimit = atoi(argv[globalUtilOptind]);
28502             globalUtilOptind++;
28503             if ( pPars->nConfGenLimit < 0 )
28504                 goto usage;
28505             break;
28506         case 'Q':
28507             if ( globalUtilOptind >= argc )
28508             {
28509                 Abc_Print( -1, "Command line switch \"-Q\" should be followed by an integer.\n" );
28510                 goto usage;
28511             }
28512             pPars->nRestLimit = atoi(argv[globalUtilOptind]);
28513             globalUtilOptind++;
28514             if ( pPars->nRestLimit < 0 )
28515                 goto usage;
28516             break;
28517         case 'T':
28518             if ( globalUtilOptind >= argc )
28519             {
28520                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
28521                 goto usage;
28522             }
28523             pPars->nTimeOut = atoi(argv[globalUtilOptind]);
28524             globalUtilOptind++;
28525             if ( pPars->nTimeOut < 0 )
28526                 goto usage;
28527             break;
28528         case 'H':
28529             if ( globalUtilOptind >= argc )
28530             {
28531                 Abc_Print( -1, "Command line switch \"-H\" should be followed by an integer.\n" );
28532                 goto usage;
28533             }
28534             pPars->nTimeOutOne = atoi(argv[globalUtilOptind]);
28535             globalUtilOptind++;
28536             if ( pPars->nTimeOutOne < 0 )
28537                 goto usage;
28538             break;
28539         case 'G':
28540             if ( globalUtilOptind >= argc )
28541             {
28542                 Abc_Print( -1, "Command line switch \"-G\" should be followed by an integer.\n" );
28543                 goto usage;
28544             }
28545             pPars->nTimeOutGap = atoi(argv[globalUtilOptind]);
28546             globalUtilOptind++;
28547             if ( pPars->nTimeOutGap < 0 )
28548                 goto usage;
28549             break;
28550         case 'S':
28551             if ( globalUtilOptind >= argc )
28552             {
28553                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
28554                 goto usage;
28555             }
28556             pPars->nRandomSeed = atoi(argv[globalUtilOptind]);
28557             globalUtilOptind++;
28558             if ( pPars->nRandomSeed < 0 )
28559                 goto usage;
28560             break;
28561         case 'L':
28562             if ( globalUtilOptind >= argc )
28563             {
28564                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
28565                 goto usage;
28566             }
28567             pLogFileName = argv[globalUtilOptind];
28568             globalUtilOptind++;
28569             break;
28570         case 'I':
28571             if ( globalUtilOptind >= argc )
28572             {
28573                 Abc_Print( -1, "Command line switch \"-I\" should be followed by a file name.\n" );
28574                 goto usage;
28575             }
28576             pPars->pInvFileName = argv[globalUtilOptind];
28577             globalUtilOptind++;
28578             break;
28579         case 'a':
28580             pPars->fSolveAll ^= 1;
28581             break;
28582         case 'x':
28583             pPars->fStoreCex ^= 1;
28584             break;
28585         case 'r':
28586             pPars->fTwoRounds ^= 1;
28587             break;
28588         case 'm':
28589             pPars->fMonoCnf ^= 1;
28590             break;
28591         case 'u':
28592             pPars->fNewXSim ^= 1;
28593             break;
28594         case 'y':
28595             pPars->fFlopPrio ^= 1;
28596             break;
28597         case 'f':
28598             pPars->fFlopOrder ^= 1;
28599             break;
28600         case 'q':
28601             pPars->fShortest ^= 1;
28602             break;
28603         case 'i':
28604             pPars->fShiftStart ^= 1;
28605             break;
28606         case 'p':
28607             pPars->fReuseProofOblig ^= 1;
28608             break;
28609         case 'd':
28610             pPars->fDumpInv ^= 1;
28611             break;
28612         case 'e':
28613             pPars->fUseSupp ^= 1;
28614             break;
28615         case 'g':
28616             pPars->fSkipGeneral ^= 1;
28617             break;
28618         case 'j':
28619             pPars->fSimpleGeneral ^= 1;
28620             break;
28621         case 'o':
28622             pPars->fUsePropOut ^= 1;
28623             break;
28624         case 'n':
28625             pPars->fSkipDown ^= 1;
28626             break;
28627         case 'c':
28628             pPars->fCtgs ^= 1;
28629             break;
28630         case 't':
28631             pPars->fUseAbs ^= 1;
28632             break;
28633         case 'k':
28634             pPars->fUseSimpleRef ^= 1;
28635             break;
28636         case 'v':
28637             pPars->fVerbose ^= 1;
28638             break;
28639         case 'w':
28640             pPars->fVeryVerbose ^= 1;
28641             break;
28642         case 'z':
28643             pPars->fNotVerbose ^= 1;
28644             break;
28645         case 'h':
28646         default:
28647             goto usage;
28648         }
28649     }
28650     if ( pNtk == NULL )
28651     {
28652         Abc_Print( -2, "There is no current network.\n");
28653         return 0;
28654     }
28655     if ( !Abc_NtkIsStrash(pNtk) )
28656     {
28657         Abc_Print( -2, "The current network is not an AIG (run \"strash\").\n");
28658         return 0;
28659     }
28660     if ( pAbc->fBatchMode && (pAbc->Status == 0 || pAbc->Status == 1) )
28661     {
28662         Abc_Print( 1, "The miters is already solved; skipping the command.\n" );
28663         return 0;
28664     }
28665     if ( Abc_NtkLatchNum(pNtk) == 0 )
28666     {
28667         pNtkFlop = Abc_NtkDup( pNtk );
28668         Abc_NtkAddLatch( pNtkFlop, Abc_AigConst1(pNtkFlop), ABC_INIT_ONE );
28669     }
28670     // run the procedure
28671     pPars->fUseBridge = pAbc->fBridgeMode;
28672     pNtkUsed = pNtkFlop ? pNtkFlop : pNtk;
28673     pAbc->Status  = Abc_NtkDarPdr( pNtkUsed, pPars );
28674     pAbc->nFrames = pNtkUsed->vSeqModelVec ? -1 : pPars->iFrame;
28675     Abc_FrameReplacePoStatuses( pAbc, &pPars->vOutMap );
28676     if ( pNtkUsed->vSeqModelVec )
28677         Abc_FrameReplaceCexVec( pAbc, &pNtkUsed->vSeqModelVec );
28678     else
28679         Abc_FrameReplaceCex( pAbc, &pNtkUsed->pSeqModel );
28680     if ( pNtkFlop ) Abc_NtkDelete( pNtkFlop );
28681     if ( pLogFileName )
28682         Abc_NtkWriteLogFile( pLogFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, "pdr" );
28683     return 0;
28684 
28685 usage:
28686     Abc_Print( -2, "usage: pdr [-MFCDQTHGS <num>] [-LI <file>] [-axrmuyfqipdegjonctkvwzh]\n" );
28687     Abc_Print( -2, "\t         model checking using property directed reachability (aka IC3)\n" );
28688     Abc_Print( -2, "\t         pioneered by Aaron R. Bradley (http://theory.stanford.edu/~arbrad/)\n" );
28689     Abc_Print( -2, "\t         with improvements by Niklas Een (http://een.se/niklas/)\n" );
28690     Abc_Print( -2, "\t-M num : limit on unused vars to trigger SAT solver recycling [default = %d]\n",       pPars->nRecycle );
28691     Abc_Print( -2, "\t-F num : limit on timeframes explored to stop computation [default = %d]\n",           pPars->nFrameMax );
28692     Abc_Print( -2, "\t-C num : limit on conflicts in one SAT call (0 = no limit) [default = %d]\n",          pPars->nConfLimit );
28693     Abc_Print( -2, "\t-D num : limit on conflicts during ind-generalization (0 = no limit) [default = %d]\n",pPars->nConfGenLimit );
28694     Abc_Print( -2, "\t-Q num : limit on proof obligations before a restart (0 = no limit) [default = %d]\n", pPars->nRestLimit );
28695     Abc_Print( -2, "\t-T num : runtime limit, in seconds (0 = no limit) [default = %d]\n",                   pPars->nTimeOut );
28696     Abc_Print( -2, "\t-H num : runtime limit per output, in miliseconds (with \"-a\") [default = %d]\n",     pPars->nTimeOutOne );
28697     Abc_Print( -2, "\t-G num : runtime gap since the last CEX (0 = no limit) [default = %d]\n",              pPars->nTimeOutGap );
28698     Abc_Print( -2, "\t-S num : * value to seed the SAT solver with [default = %d]\n",                          pPars->nRandomSeed );
28699     Abc_Print( -2, "\t-L file: the log file name [default = %s]\n",                                          pLogFileName ? pLogFileName : "no logging" );
28700     Abc_Print( -2, "\t-I file: the invariant file name [default = %s]\n",                                    pPars->pInvFileName ? pPars->pInvFileName : "default name" );
28701     Abc_Print( -2, "\t-a     : toggle solving all outputs even if one of them is SAT [default = %s]\n",      pPars->fSolveAll? "yes": "no" );
28702     Abc_Print( -2, "\t-x     : toggle storing CEXes when solving all outputs [default = %s]\n",              pPars->fStoreCex? "yes": "no" );
28703     Abc_Print( -2, "\t-r     : toggle using more effort in generalization [default = %s]\n",                 pPars->fTwoRounds? "yes": "no" );
28704     Abc_Print( -2, "\t-m     : toggle using monolythic CNF computation [default = %s]\n",                    pPars->fMonoCnf? "yes": "no" );
28705     Abc_Print( -2, "\t-u     : toggle updated X-valued simulation [default = %s]\n",                         pPars->fNewXSim? "yes": "no" );
28706     Abc_Print( -2, "\t-y     : toggle using structural flop priorities [default = %s]\n",                    pPars->fFlopPrio? "yes": "no" );
28707     Abc_Print( -2, "\t-f     : toggle ordering flops by cost before generalization [default = %s]\n",        pPars->fFlopOrder? "yes": "no" );
28708     Abc_Print( -2, "\t-q     : toggle creating only shortest counter-examples [default = %s]\n",             pPars->fShortest? "yes": "no" );
28709     Abc_Print( -2, "\t-i     : toggle clause pushing from an intermediate timeframe [default = %s]\n",       pPars->fShiftStart? "yes": "no" );
28710     Abc_Print( -2, "\t-p     : toggle reusing proof-obligations in the last timeframe [default = %s]\n",     pPars->fReuseProofOblig? "yes": "no" );
28711     Abc_Print( -2, "\t-d     : toggle dumping invariant (valid if init state is all-0) [default = %s]\n",    pPars->fDumpInv? "yes": "no" );
28712     Abc_Print( -2, "\t-e     : toggle using only support variables in the invariant [default = %s]\n",       pPars->fUseSupp? "yes": "no" );
28713     Abc_Print( -2, "\t-g     : toggle skipping expensive generalization step [default = %s]\n",              pPars->fSkipGeneral? "yes": "no" );
28714     Abc_Print( -2, "\t-j     : toggle using simplified generalization step [default = %s]\n",                pPars->fSimpleGeneral? "yes": "no" );
28715     Abc_Print( -2, "\t-o     : toggle using property output as inductive hypothesis [default = %s]\n",       pPars->fUsePropOut? "yes": "no" );
28716     Abc_Print( -2, "\t-n     : * toggle skipping \'down\' in generalization [default = %s]\n",                 pPars->fSkipDown? "yes": "no" );
28717     Abc_Print( -2, "\t-c     : * toggle handling CTGs in \'down\' [default = %s]\n",                           pPars->fCtgs? "yes": "no" );
28718     Abc_Print( -2, "\t-t     : toggle using abstraction [default = %s]\n",                                   pPars->fUseAbs? "yes": "no" );
28719     Abc_Print( -2, "\t-k     : toggle using simplified refinement [default = %s]\n",                         pPars->fUseSimpleRef? "yes": "no" );
28720     Abc_Print( -2, "\t-v     : toggle printing optimization summary [default = %s]\n",                       pPars->fVerbose? "yes": "no" );
28721     Abc_Print( -2, "\t-w     : toggle printing detailed stats default = %s]\n",                              pPars->fVeryVerbose? "yes": "no" );
28722     Abc_Print( -2, "\t-z     : toggle suppressing report about solved outputs [default = %s]\n",             pPars->fNotVerbose? "yes": "no" );
28723     Abc_Print( -2, "\t-h     : print the command usage\n\n");
28724     Abc_Print( -2, "\t* Implementation of switches -S, -n, and -c is contributed by Zyad Hassan.\n");
28725     Abc_Print( -2, "\t  The theory and experiments supporting this work can be found in the following paper:\n");
28726     Abc_Print( -2, "\t  Zyad Hassan, Aaron R. Bradley, Fabio Somenzi, \"Better Generalization in IC3\", FMCAD 2013.\n");
28727     Abc_Print( -2, "\t  (http://www.cs.utexas.edu/users/hunt/FMCAD/FMCAD13/papers/85-Better-Generalization-IC3.pdf)\n");
28728 
28729 
28730 
28731     return 1;
28732 }
28733 
28734 #ifdef ABC_USE_CUDD
28735 
28736 /**Function*************************************************************
28737 
28738   Synopsis    []
28739 
28740   Description []
28741 
28742   SideEffects []
28743 
28744   SeeAlso     []
28745 
28746 ***********************************************************************/
Abc_CommandReconcile(Abc_Frame_t * pAbc,int argc,char ** argv)28747 int Abc_CommandReconcile( Abc_Frame_t * pAbc, int argc, char ** argv )
28748 {
28749     extern Abc_Cex_t * Llb4_Nonlin4NormalizeCex( Aig_Man_t * pAigOrg, Aig_Man_t * pAigRpm, Abc_Cex_t * pCexRpm );
28750     Abc_Cex_t * pCex;
28751     Abc_Ntk_t * pNtk1 = NULL, * pNtk2 = NULL;
28752     Aig_Man_t * pAig1 = NULL, * pAig2 = NULL;
28753     int c;
28754     Extra_UtilGetoptReset();
28755     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
28756     {
28757         switch ( c )
28758         {
28759         case 'h':
28760             goto usage;
28761         default:
28762             Abc_Print( -2, "Unknown switch.\n");
28763             goto usage;
28764         }
28765     }
28766 
28767     if ( argc != globalUtilOptind + 2 && argc != globalUtilOptind )
28768     {
28769         Abc_Print( 1,"Does not seen to have two files names as arguments.\n" );
28770         return 1;
28771     }
28772     if ( pAbc->pCex == NULL )
28773     {
28774         Abc_Print( 1,"There is no current counter-example.\n" );
28775         return 1;
28776     }
28777 
28778     if ( argc == globalUtilOptind + 2 )
28779     {
28780         // derive networks
28781         pNtk1 = Io_Read( argv[globalUtilOptind], Io_ReadFileType(argv[globalUtilOptind]), 1, 0 );
28782         if ( pNtk1 == NULL )
28783             return 1;
28784         pNtk2 = Io_Read( argv[globalUtilOptind+1], Io_ReadFileType(argv[globalUtilOptind+1]), 1, 0 );
28785         if ( pNtk2 == NULL )
28786         {
28787             Abc_NtkDelete( pNtk1 );
28788             return 1;
28789         }
28790         // create counter-examples
28791         pAig1 = Abc_NtkToDar( pNtk1, 0, 0 );
28792         pAig2 = Abc_NtkToDar( pNtk2, 0, 0 );
28793     }
28794     else if ( argc == globalUtilOptind )
28795     {
28796         if ( pAbc->pNtkCur == NULL )
28797         {
28798             Abc_Print( 1, "There is no AIG in the main-space.\n");
28799             return 0;
28800         }
28801         if ( pAbc->pGia == NULL )
28802         {
28803             Abc_Print( 1, "There is no AIG in the &-space.\n");
28804             return 0;
28805         }
28806         // create counter-examples
28807         pAig1 = Abc_NtkToDar( pAbc->pNtkCur, 0, 0 );
28808         pAig2 = Gia_ManToAigSimple( pAbc->pGia );
28809     }
28810     else assert( 0 );
28811     pCex = Llb4_Nonlin4NormalizeCex( pAig1, pAig2, pAbc->pCex );
28812     Aig_ManStop( pAig1 );
28813     Aig_ManStop( pAig2 );
28814     if ( pNtk2 )  Abc_NtkDelete( pNtk2 );
28815     if ( pCex == NULL )
28816     {
28817         Abc_Print( 1,"Counter-example computation has failed.\n" );
28818         if ( pNtk1 )  Abc_NtkDelete( pNtk1 );
28819         return 1;
28820     }
28821 
28822     // replace the current network
28823     if ( pNtk1 )
28824         Abc_FrameReplaceCurrentNetwork( pAbc, pNtk1 );
28825     // update the counter-example
28826     pAbc->nFrames = pCex->iFrame;
28827     Abc_FrameReplaceCex( pAbc, &pCex );
28828     return 0;
28829 
28830 usage:
28831     Abc_Print( -2, "usage: reconcile [-h] <fileOrigin> <fileReparam>\n" );
28832     Abc_Print( -2, "\t        reconciles current CEX with <fileOrigin>\n" );
28833     Abc_Print( -2, "\t        More specifically:\n" );
28834     Abc_Print( -2, "\t        (i) assumes that <fileReparam> is an AIG derived by input\n" );
28835     Abc_Print( -2, "\t        reparametrization of <fileOrigin> without seq synthesis;\n" );
28836     Abc_Print( -2, "\t        (ii) assumes that current CEX is valid for <fileReparam>;\n" );
28837     Abc_Print( -2, "\t        (iii) derives new CEX for <fileOrigin> and sets this CEX\n" );
28838     Abc_Print( -2, "\t        and <fileOrigin> to be current CEX and current network\n" );
28839     Abc_Print( -2, "\t<fileOrigin>   : file name with the original AIG\n");
28840     Abc_Print( -2, "\t<fileReparam>  : file name with the reparametrized AIG\n");
28841     Abc_Print( -2, "\t        (if both file names are not given on the command line,\n");
28842     Abc_Print( -2, "\t        original/reparam AIG has to be in the main-space/&-space)\n");
28843     Abc_Print( -2, "\t-h    : print the command usage\n");
28844     return 1;
28845 }
28846 
28847 #endif
28848 
28849 /**Function*************************************************************
28850 
28851   Synopsis    []
28852 
28853   Description []
28854 
28855   SideEffects []
28856 
28857   SeeAlso     []
28858 
28859 ***********************************************************************/
Abc_CommandCexSave(Abc_Frame_t * pAbc,int argc,char ** argv)28860 int Abc_CommandCexSave( Abc_Frame_t * pAbc, int argc, char ** argv )
28861 {
28862     int c;
28863     Extra_UtilGetoptReset();
28864     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
28865     {
28866         switch ( c )
28867         {
28868         case 'h':
28869             goto usage;
28870         default:
28871             goto usage;
28872         }
28873     }
28874     if ( pAbc->pCex == NULL )
28875     {
28876         Abc_Print( -1, "Current CEX is not available..\n" );
28877         return 1;
28878     }
28879     ABC_FREE( pAbc->pCex2 );
28880     pAbc->pCex2 = Abc_CexDup( pAbc->pCex, -1 );
28881     return 0;
28882 
28883 usage:
28884     Abc_Print( -2, "usage: cexsave [-h]\n" );
28885     Abc_Print( -2, "\t        saves the current CEX into the internal storage\n" );
28886     Abc_Print( -2, "\t-h    : print the command usage\n");
28887     return 1;
28888 }
28889 
28890 /**Function*************************************************************
28891 
28892   Synopsis    []
28893 
28894   Description []
28895 
28896   SideEffects []
28897 
28898   SeeAlso     []
28899 
28900 ***********************************************************************/
Abc_CommandCexLoad(Abc_Frame_t * pAbc,int argc,char ** argv)28901 int Abc_CommandCexLoad( Abc_Frame_t * pAbc, int argc, char ** argv )
28902 {
28903     int c;
28904     Extra_UtilGetoptReset();
28905     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
28906     {
28907         switch ( c )
28908         {
28909         case 'h':
28910             goto usage;
28911         default:
28912             goto usage;
28913         }
28914     }
28915     if ( pAbc->pCex2 == NULL )
28916     {
28917         Abc_Print( -1, "Saved CEX is not available.\n" );
28918         return 1;
28919     }
28920     ABC_FREE( pAbc->pCex );
28921     pAbc->pCex = Abc_CexDup( pAbc->pCex2, -1 );
28922     // update status
28923     pAbc->nFrames = pAbc->pCex2->iFrame;
28924     pAbc->Status = 0;
28925     return 0;
28926 
28927 usage:
28928     Abc_Print( -2, "usage: cexload [-h]\n" );
28929     Abc_Print( -2, "\t        loads the current CEX from the internal storage\n" );
28930     Abc_Print( -2, "\t-h    : print the command usage\n");
28931     return 1;
28932 }
28933 
28934 
28935 /**Function*************************************************************
28936 
28937   Synopsis    []
28938 
28939   Description []
28940 
28941   SideEffects []
28942 
28943   SeeAlso     []
28944 
28945 ***********************************************************************/
Abc_CommandCexCut(Abc_Frame_t * pAbc,int argc,char ** argv)28946 int Abc_CommandCexCut( Abc_Frame_t * pAbc, int argc, char ** argv )
28947 {
28948     Abc_Ntk_t * pNtkNew;
28949     int c, iFrStart = 0;
28950     int iFrStop     = ABC_INFINITY;
28951     int fCombOnly   = 0;
28952     int fUseOne     = 0;
28953     int fAllFrames  = 0;
28954     int fVerbose    = 0;
28955     Extra_UtilGetoptReset();
28956     while ( ( c = Extra_UtilGetopt( argc, argv, "FGcnmvh" ) ) != EOF )
28957     {
28958         switch ( c )
28959         {
28960         case 'F':
28961             if ( globalUtilOptind >= argc )
28962             {
28963                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
28964                 goto usage;
28965             }
28966             iFrStart = atoi(argv[globalUtilOptind]);
28967             globalUtilOptind++;
28968             if ( iFrStart < 0 )
28969                 goto usage;
28970             break;
28971         case 'G':
28972             if ( globalUtilOptind >= argc )
28973             {
28974                 Abc_Print( -1, "Command line switch \"-G\" should be followed by an integer.\n" );
28975                 goto usage;
28976             }
28977             iFrStop = atoi(argv[globalUtilOptind]);
28978             globalUtilOptind++;
28979             if ( iFrStop < 0 )
28980                 goto usage;
28981             break;
28982         case 'c':
28983             fCombOnly ^= 1;
28984             break;
28985         case 'n':
28986             fUseOne ^= 1;
28987             break;
28988         case 'm':
28989             fAllFrames ^= 1;
28990             break;
28991         case 'v':
28992             fVerbose ^= 1;
28993             break;
28994         case 'h':
28995             goto usage;
28996         default:
28997             Abc_Print( -2, "Unknown switch.\n");
28998             goto usage;
28999         }
29000     }
29001 
29002     if ( pAbc->pCex == NULL )
29003     {
29004         Abc_Print( 1, "There is no current cex.\n");
29005         return 0;
29006     }
29007     if ( pAbc->pNtkCur == NULL )
29008     {
29009         Abc_Print( 1, "There is no AIG in the &-space.\n");
29010         return 0;
29011     }
29012     if ( !Abc_NtkIsStrash(pAbc->pNtkCur) )
29013     {
29014         Abc_Print( 1, "Current network is not an AIG.\n");
29015         return 0;
29016     }
29017     if ( iFrStop == ABC_INFINITY )
29018         iFrStop = pAbc->pCex->iFrame;
29019 
29020     {
29021         Aig_Man_t * pAig = Abc_NtkToDar( pAbc->pNtkCur, 0, 1 );
29022         Aig_Man_t * pAigNew = Bmc_AigTargetStates( pAig, pAbc->pCex, iFrStart, iFrStop, fCombOnly, fUseOne, fAllFrames, fVerbose );
29023         Aig_ManStop( pAig );
29024         if ( pAigNew == NULL )
29025         {
29026             Abc_Print( 1, "Command has failed.\n");
29027             return 0;
29028         }
29029         pNtkNew = Abc_NtkFromAigPhase( pAigNew );
29030         pNtkNew->pName = Extra_UtilStrsav( pAbc->pNtkCur->pName );
29031         Aig_ManStop( pAigNew );
29032         // update the network
29033         Abc_FrameReplaceCurrentNetwork( pAbc, pNtkNew );
29034     }
29035 /*
29036     pGiaNew = Bmc_GiaTargetStates( pAbc->pGia, pAbc->pCex, iFrStart, iFrStop, fCombOnly, fUseOne, fVerbose );
29037     if ( pGiaNew == NULL )
29038     {
29039         Abc_Print( 1, "Command has failed.\n");
29040         return 0;
29041     }
29042     Abc_FrameUpdateGia( pAbc, pGiaNew );
29043 */
29044     return 0;
29045 
29046 usage:
29047     Abc_Print( -2, "usage: cexcut [-FG num] [-cnmvh]\n" );
29048     Abc_Print( -2, "\t         creates logic for bad states using the current CEX\n" );
29049     Abc_Print( -2, "\t-F num : 0-based number of the starting frame [default = %d]\n", iFrStart );
29050     Abc_Print( -2, "\t-G num : 0-based number of the ending frame [default = %d]\n",   iFrStop );
29051     Abc_Print( -2, "\t-c     : toggle outputting unate combinational circuit [default = %s]\n",  fCombOnly? "yes": "no" );
29052     Abc_Print( -2, "\t-n     : toggle generating only one bad state [default = %s]\n", fUseOne? "yes": "no" );
29053     Abc_Print( -2, "\t-m     : toggle generating bad states for all frames after G [default = %s]\n", fAllFrames? "yes": "no" );
29054     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",  fVerbose? "yes": "no" );
29055     Abc_Print( -2, "\t-h     : print the command usage\n");
29056     return 1;
29057 }
29058 
29059 /**Function*************************************************************
29060 
29061   Synopsis    []
29062 
29063   Description []
29064 
29065   SideEffects []
29066 
29067   SeeAlso     []
29068 
29069 ***********************************************************************/
Abc_CommandCexMerge(Abc_Frame_t * pAbc,int argc,char ** argv)29070 int Abc_CommandCexMerge( Abc_Frame_t * pAbc, int argc, char ** argv )
29071 {
29072     Abc_Cex_t * pCexNew;
29073     int c;
29074     int iFrStart = 0;
29075     int iFrStop  = ABC_INFINITY;
29076     int fVerbose = 0;
29077     Extra_UtilGetoptReset();
29078     while ( ( c = Extra_UtilGetopt( argc, argv, "FGvh" ) ) != EOF )
29079     {
29080         switch ( c )
29081         {
29082         case 'F':
29083             if ( globalUtilOptind >= argc )
29084             {
29085                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
29086                 goto usage;
29087             }
29088             iFrStart = atoi(argv[globalUtilOptind]);
29089             globalUtilOptind++;
29090             if ( iFrStart < 0 )
29091                 goto usage;
29092             break;
29093         case 'G':
29094             if ( globalUtilOptind >= argc )
29095             {
29096                 Abc_Print( -1, "Command line switch \"-G\" should be followed by an integer.\n" );
29097                 goto usage;
29098             }
29099             iFrStop = atoi(argv[globalUtilOptind]);
29100             globalUtilOptind++;
29101             if ( iFrStop < 0 )
29102                 goto usage;
29103             break;
29104         case 'v':
29105             fVerbose ^= 1;
29106             break;
29107         case 'h':
29108             goto usage;
29109         default:
29110             Abc_Print( -2, "Unknown switch.\n");
29111             goto usage;
29112         }
29113     }
29114 
29115     if ( pAbc->pCex == NULL )
29116     {
29117         Abc_Print( 1, "There is no current cex.\n");
29118         return 0;
29119     }
29120     if ( pAbc->pCex2 == NULL )
29121     {
29122         Abc_Print( 1, "There is no saved cex.\n");
29123         return 0;
29124     }
29125     if ( iFrStop - iFrStart + pAbc->pCex->iPo < pAbc->pCex->iFrame )
29126     {
29127         Abc_Print( 1, "Current CEX does not allow to shorten the saved CEX.\n");
29128         return 0;
29129     }
29130     pCexNew = Abc_CexMerge( pAbc->pCex2, pAbc->pCex, iFrStart, iFrStop );
29131     if ( pCexNew == NULL )
29132     {
29133         Abc_Print( 1, "Merging CEXes has failed.\n");
29134         return 0;
29135     }
29136     // replace the saved CEX
29137     ABC_FREE( pAbc->pCex2 );
29138     pAbc->pCex2 = pCexNew;
29139     return 0;
29140 
29141 usage:
29142     Abc_Print( -2, "usage: cexmerge [-FG num] [-vh]\n" );
29143     Abc_Print( -2, "\t         merges the current CEX into the saved one\n" );
29144     Abc_Print( -2, "\t         and sets the resulting CEX as the saved one\n" );
29145     Abc_Print( -2, "\t-F num : 0-based number of the starting frame [default = %d]\n", iFrStart );
29146     Abc_Print( -2, "\t-G num : 0-based number of the ending frame [default = %d]\n",   iFrStop );
29147     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
29148     Abc_Print( -2, "\t-h     : print the command usage\n");
29149     return 1;
29150 }
29151 
29152 /**Function*************************************************************
29153 
29154   Synopsis    []
29155 
29156   Description []
29157 
29158   SideEffects []
29159 
29160   SeeAlso     []
29161 
29162 ***********************************************************************/
Abc_CommandCexMin(Abc_Frame_t * pAbc,int argc,char ** argv)29163 int Abc_CommandCexMin( Abc_Frame_t * pAbc, int argc, char ** argv )
29164 {
29165     Abc_Ntk_t * pNtk;
29166     Abc_Cex_t * vCexNew = NULL;
29167     int c;
29168     int nConfLimit = 1000;
29169     int nRounds    =    1;
29170     int fVerbose   =    0;
29171     Extra_UtilGetoptReset();
29172     while ( ( c = Extra_UtilGetopt( argc, argv, "CRvh" ) ) != EOF )
29173     {
29174         switch ( c )
29175         {
29176         case 'C':
29177             if ( globalUtilOptind >= argc )
29178             {
29179                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
29180                 goto usage;
29181             }
29182             nConfLimit = atoi(argv[globalUtilOptind]);
29183             globalUtilOptind++;
29184             if ( nConfLimit < 0 )
29185                 goto usage;
29186             break;
29187         case 'R':
29188             if ( globalUtilOptind >= argc )
29189             {
29190                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
29191                 goto usage;
29192             }
29193             nRounds = atoi(argv[globalUtilOptind]);
29194             globalUtilOptind++;
29195             if ( nRounds < 0 )
29196                 goto usage;
29197             break;
29198         case 'v':
29199             fVerbose ^= 1;
29200             break;
29201         case 'h':
29202             goto usage;
29203         default:
29204             Abc_Print( -2, "Unknown switch.\n");
29205             goto usage;
29206         }
29207     }
29208 
29209     if ( pAbc->pCex == NULL )
29210     {
29211         Abc_Print( 1, "There is no current cex.\n");
29212         return 0;
29213     }
29214 
29215     // check the main AIG
29216     pNtk = Abc_FrameReadNtk(pAbc);
29217     if ( pNtk == NULL )
29218         Abc_Print( 1, "Main AIG: There is no current network.\n");
29219     else if ( !Abc_NtkIsStrash(pNtk) )
29220         Abc_Print( 1, "Main AIG: The current network is not an AIG.\n");
29221     else if ( Abc_NtkPiNum(pNtk) != pAbc->pCex->nPis )
29222         Abc_Print( 1, "Main AIG: The number of PIs (%d) is different from cex (%d).\n", Abc_NtkPiNum(pNtk), pAbc->pCex->nPis );
29223 //      else if ( Abc_NtkLatchNum(pNtk) != pAbc->pCex->nRegs )
29224 //          Abc_Print( 1, "Main AIG: The number of registers (%d) is different from cex (%d).\n", Abc_NtkLatchNum(pNtk), pAbc->pCex->nRegs );
29225 //      else if ( Abc_NtkPoNum(pNtk) <= pAbc->pCex->iPo )
29226 //          Abc_Print( 1, "Main AIG: The number of POs (%d) is less than the PO index in cex (%d).\n", Abc_NtkPoNum(pNtk), pAbc->pCex->iPo );
29227     else
29228     {
29229         Aig_Man_t * pAig = Abc_NtkToDar( pNtk, 0, 1 );
29230         Gia_Man_t * pGia = Gia_ManFromAigSimple( pAig );
29231 //        if ( !Gia_ManVerifyCex( pGia, pAbc->pCex, 0 ) )
29232         int iPoOld = pAbc->pCex->iPo;
29233         pAbc->pCex->iPo = Gia_ManFindFailedPoCex( pGia, pAbc->pCex, 0 );
29234         Gia_ManStop( pGia );
29235         if ( pAbc->pCex->iPo == -1 )
29236         {
29237             pAbc->pCex->iPo = iPoOld;
29238             Abc_Print( -1, "Main AIG: The cex does not fail any outputs.\n" );
29239             return 0;
29240         }
29241         else if ( iPoOld != pAbc->pCex->iPo )
29242             Abc_Print( 0, "Main AIG: The cex refined PO %d instead of PO %d.\n", pAbc->pCex->iPo, iPoOld );
29243         // perform minimization
29244         vCexNew = Saig_ManCexMinPerform( pAig, pAbc->pCex );
29245         Aig_ManStop( pAig );
29246         Abc_CexFree( vCexNew );
29247 //        Abc_FrameReplaceCex( pAbc, &vCexNew );
29248 
29249 //        Abc_Print( 1,"Implementation of this command is not finished.\n" );
29250     }
29251     return 0;
29252 
29253 usage:
29254     Abc_Print( -2, "usage: cexmin [-CR num] [-vh]\n" );
29255     Abc_Print( -2, "\t         reduces the length of the counter-example\n" );
29256     Abc_Print( -2, "\t-C num : the maximum number of conflicts [default = %d]\n", nConfLimit );
29257     Abc_Print( -2, "\t-R num : the number of minimization rounds [default = %d]\n", nRounds );
29258     Abc_Print( -2, "\t-v     : toggle printing optimization summary [default = %s]\n", fVerbose? "yes": "no" );
29259     Abc_Print( -2, "\t-h     : print the command usage\n");
29260     return 1;
29261 }
29262 
29263 /**Function*************************************************************
29264 
29265   Synopsis    []
29266 
29267   Description []
29268 
29269   SideEffects []
29270 
29271   SeeAlso     []
29272 
29273 ***********************************************************************/
Abc_CommandDualRail(Abc_Frame_t * pAbc,int argc,char ** argv)29274 int Abc_CommandDualRail( Abc_Frame_t * pAbc, int argc, char ** argv )
29275 {
29276     extern Vec_Int_t * Abc_NtkFindDcLatches( Abc_Ntk_t * pNtk );
29277     Abc_Ntk_t * pNtk, * pNtkNew = NULL;
29278     Aig_Man_t * pAig, * pAigNew;
29279     Vec_Int_t * vDcFlops = NULL;
29280     int c;
29281     int nDualPis   = 0;
29282     int fDualFfs   = 0;
29283     int fDualDcFfs = 0;
29284     int fMiterFfs  = 0;
29285     int fComplPo   = 0;
29286     int fCheckZero = 0;
29287     int fCheckOne  = 0;
29288     int fVerbose   = 0;
29289     Extra_UtilGetoptReset();
29290     while ( ( c = Extra_UtilGetopt( argc, argv, "Itxfczovh" ) ) != EOF )
29291     {
29292         switch ( c )
29293         {
29294         case 'I':
29295             if ( globalUtilOptind >= argc )
29296             {
29297                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
29298                 goto usage;
29299             }
29300             nDualPis = atoi(argv[globalUtilOptind]);
29301             globalUtilOptind++;
29302             if ( nDualPis < 0 )
29303                 goto usage;
29304             break;
29305         case 't':
29306             fDualFfs ^= 1;
29307             break;
29308         case 'x':
29309             fDualDcFfs ^= 1;
29310             break;
29311         case 'f':
29312             fMiterFfs ^= 1;
29313             break;
29314         case 'c':
29315             fComplPo ^= 1;
29316             break;
29317         case 'z':
29318             fCheckZero ^= 1;
29319             break;
29320         case 'o':
29321             fCheckOne ^= 1;
29322             break;
29323         case 'v':
29324             fVerbose ^= 1;
29325             break;
29326         case 'h':
29327             goto usage;
29328         default:
29329             Abc_Print( -2, "Unknown switch.\n");
29330             goto usage;
29331         }
29332     }
29333 
29334     // check the main AIG
29335     pNtk = Abc_FrameReadNtk(pAbc);
29336     if ( pNtk == NULL )
29337     {
29338         Abc_Print( 1, "Main AIG: There is no current network.\n");
29339         return 0;
29340     }
29341     if ( !Abc_NtkIsStrash(pNtk) )
29342     {
29343         Abc_Print( 1, "Main AIG: The current network is not an AIG.\n");
29344         return 0;
29345     }
29346 
29347     if ( fDualDcFfs )
29348         vDcFlops = Abc_NtkFindDcLatches( pNtk );
29349 
29350     // transform
29351     pAig = Abc_NtkToDar( pNtk, 0, 1 );
29352     pAigNew = Saig_ManDupDual( pAig, vDcFlops, nDualPis, fDualFfs, fMiterFfs, fComplPo, fCheckZero, fCheckOne );
29353     Aig_ManStop( pAig );
29354     pNtkNew = Abc_NtkFromAigPhase( pAigNew );
29355     pNtkNew->pName = Extra_UtilStrsav(pNtk->pName);
29356     Aig_ManStop( pAigNew );
29357     Vec_IntFreeP( &vDcFlops );
29358 
29359     // replace the current network
29360     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkNew );
29361     return 0;
29362 
29363 usage:
29364     Abc_Print( -2, "usage: dualrail [-I num] [-txfczovh]\n" );
29365     Abc_Print( -2, "\t         transforms the current AIG into a dual-rail miter\n" );
29366     Abc_Print( -2, "\t         expressing the property \"at least one PO has ternary value\"\n" );
29367     Abc_Print( -2, "\t         (to compute an initialization sequence, use switches \"-tfc\")\n" );
29368     Abc_Print( -2, "\t-I num : the number of first PIs interpreted as ternary [default = %d]\n", nDualPis );
29369     Abc_Print( -2, "\t-t     : toggle ternary flop init values for all flops [default = %s]\n", fDualFfs? "yes": "const0 init values" );
29370     Abc_Print( -2, "\t-x     : toggle ternary flop init values for DC-valued flops [default = %s]\n", fDualDcFfs? "yes": "const0 init values" );
29371     Abc_Print( -2, "\t-f     : toggle mitering flops instead of POs [default = %s]\n", fMiterFfs? "flops": "POs" );
29372     Abc_Print( -2, "\t-c     : toggle complementing the miter output [default = %s]\n", fComplPo? "yes": "no" );
29373     Abc_Print( -2, "\t-z     : toggle checking PO==0 instead of PO==X [default = %s]\n", fCheckZero? "yes": "no" );
29374     Abc_Print( -2, "\t-o     : toggle checking PO==1 instead of PO==X [default = %s]\n", fCheckOne? "yes": "no" );
29375     Abc_Print( -2, "\t-v     : toggle printing optimization summary [default = %s]\n", fVerbose? "yes": "no" );
29376     Abc_Print( -2, "\t-h     : print the command usage\n");
29377     return 1;
29378 }
29379 
29380 /**Function*************************************************************
29381 
29382   Synopsis    []
29383 
29384   Description []
29385 
29386   SideEffects []
29387 
29388   SeeAlso     []
29389 
29390 ***********************************************************************/
Abc_CommandBlockPo(Abc_Frame_t * pAbc,int argc,char ** argv)29391 int Abc_CommandBlockPo( Abc_Frame_t * pAbc, int argc, char ** argv )
29392 {
29393     Abc_Ntk_t * pNtk, * pNtkNew = NULL;
29394     Aig_Man_t * pAig;
29395     int c;
29396     int nCycles = 0;
29397     int fVerbose = 0;
29398     Extra_UtilGetoptReset();
29399     while ( ( c = Extra_UtilGetopt( argc, argv, "Fvh" ) ) != EOF )
29400     {
29401         switch ( c )
29402         {
29403         case 'F':
29404             if ( globalUtilOptind >= argc )
29405             {
29406                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
29407                 goto usage;
29408             }
29409             nCycles = atoi(argv[globalUtilOptind]);
29410             globalUtilOptind++;
29411             if ( nCycles < 0 )
29412                 goto usage;
29413             break;
29414         case 'v':
29415             fVerbose ^= 1;
29416             break;
29417         case 'h':
29418             goto usage;
29419         default:
29420             Abc_Print( -2, "Unknown switch.\n");
29421             goto usage;
29422         }
29423     }
29424 
29425     // check the main AIG
29426     pNtk = Abc_FrameReadNtk(pAbc);
29427     if ( pNtk == NULL )
29428     {
29429         Abc_Print( 1, "Main AIG: There is no current network.\n");
29430         return 0;
29431     }
29432     if ( !Abc_NtkIsStrash(pNtk) )
29433     {
29434         Abc_Print( 1, "Main AIG: The current network is not an AIG.\n");
29435         return 0;
29436     }
29437     if ( nCycles == 0 )
29438     {
29439         Abc_Print( 1, "The number of time frame is 0. The circuit is left unchanged.\n" );
29440         return 0;
29441     }
29442 
29443     // transform
29444     pAig = Abc_NtkToDar( pNtk, 0, 1 );
29445     Saig_ManBlockPo( pAig, nCycles );
29446     pNtkNew = Abc_NtkFromAigPhase( pAig );
29447     Aig_ManStop( pAig );
29448     // transfer the name
29449     pNtkNew->pName = Extra_UtilStrsav(pNtk->pName);
29450     pNtkNew->pSpec = Extra_UtilStrsav(pNtk->pSpec);
29451     // replace the current network
29452     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkNew );
29453     return 0;
29454 
29455 usage:
29456     Abc_Print( -2, "usage: blockpo [-F num] [-fvh]\n" );
29457     Abc_Print( -2, "\t         forces the miter outputs to be \"true\" in the first F frames\n" );
29458     Abc_Print( -2, "\t-F num : the number of time frames [default = %d]\n", nCycles );
29459     Abc_Print( -2, "\t-v     : toggle printing optimization summary [default = %s]\n", fVerbose? "yes": "no" );
29460     Abc_Print( -2, "\t-h     : print the command usage\n");
29461     return 1;
29462 }
29463 
29464 /**Function*************************************************************
29465 
29466   Synopsis    []
29467 
29468   Description []
29469 
29470   SideEffects []
29471 
29472   SeeAlso     []
29473 
29474 ***********************************************************************/
Abc_CommandIso(Abc_Frame_t * pAbc,int argc,char ** argv)29475 int Abc_CommandIso( Abc_Frame_t * pAbc, int argc, char ** argv )
29476 {
29477     Abc_Ntk_t * pNtk, * pNtkNew = NULL;
29478     Aig_Man_t * pAig, * pTemp;
29479     Vec_Ptr_t * vPosEquivs = NULL;
29480     int c, fVerbose = 0;
29481     Extra_UtilGetoptReset();
29482     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
29483     {
29484         switch ( c )
29485         {
29486         case 'v':
29487             fVerbose ^= 1;
29488             break;
29489         case 'h':
29490             goto usage;
29491         default:
29492             Abc_Print( -2, "Unknown switch.\n");
29493             goto usage;
29494         }
29495     }
29496 
29497     // check the main AIG
29498     pNtk = Abc_FrameReadNtk(pAbc);
29499     if ( pNtk == NULL )
29500     {
29501         Abc_Print( 1, "Main AIG: There is no current network.\n");
29502         return 0;
29503     }
29504     if ( !Abc_NtkIsStrash(pNtk) )
29505     {
29506         Abc_Print( 1, "Main AIG: The current network is not an AIG.\n");
29507         return 0;
29508     }
29509     if ( Abc_NtkPoNum(pNtk) == 1 )
29510     {
29511         Abc_Print( 1, "Current AIG has only one PO. Transformation is not performed.\n");
29512         return 0;
29513     }
29514 
29515     // transform
29516     pAig = Abc_NtkToDar( pNtk, 0, 1 );
29517     pTemp = Saig_ManIsoReduce( pAig, &vPosEquivs, fVerbose );
29518     pNtkNew = Abc_NtkFromAigPhase( pTemp );
29519     pNtkNew->pName = Extra_UtilStrsav(pNtk->pName);
29520     Aig_ManStop( pTemp );
29521     Aig_ManStop( pAig );
29522 
29523     // update the internal storage of PO equivalences
29524     Abc_FrameReplacePoEquivs( pAbc, &vPosEquivs );
29525 
29526     // replace the current network
29527     Abc_FrameReplaceCurrentNetwork( pAbc, pNtkNew );
29528     return 0;
29529 
29530 usage:
29531     Abc_Print( -2, "usage: iso [-vh]\n" );
29532     Abc_Print( -2, "\t         removes POs with isomorphic sequential COI\n" );
29533     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
29534     Abc_Print( -2, "\t-h     : print the command usage\n");
29535     return 1;
29536 }
29537 
29538 /**Function*************************************************************
29539 
29540   Synopsis    []
29541 
29542   Description []
29543 
29544   SideEffects []
29545 
29546   SeeAlso     []
29547 
29548 ***********************************************************************/
Abc_CommandTraceStart(Abc_Frame_t * pAbc,int argc,char ** argv)29549 int Abc_CommandTraceStart( Abc_Frame_t * pAbc, int argc, char ** argv )
29550 {
29551     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
29552     int c;
29553     // set defaults
29554     Extra_UtilGetoptReset();
29555     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
29556     {
29557         switch ( c )
29558         {
29559         case 'h':
29560             goto usage;
29561         default:
29562             goto usage;
29563         }
29564     }
29565 
29566     if ( pNtk == NULL )
29567     {
29568         Abc_Print( -1, "Empty network.\n" );
29569         return 1;
29570     }
29571     if ( !Abc_NtkIsStrash(pNtk) )
29572     {
29573         Abc_Print( -1, "This command is applicable to AIGs.\n" );
29574         return 1;
29575     }
29576 /*
29577     Abc_HManStart();
29578     if ( !Abc_HManPopulate( pNtk ) )
29579     {
29580         Abc_Print( -1, "Failed to start the tracing database.\n" );
29581         return 1;
29582     }
29583 */
29584     return 0;
29585 
29586 usage:
29587     Abc_Print( -2, "usage: trace_start [-h]\n" );
29588     Abc_Print( -2, "\t        starts verification tracing\n" );
29589     Abc_Print( -2, "\t-h    : print the command usage\n");
29590     return 1;
29591 }
29592 
29593 /**Function*************************************************************
29594 
29595   Synopsis    []
29596 
29597   Description []
29598 
29599   SideEffects []
29600 
29601   SeeAlso     []
29602 
29603 ***********************************************************************/
Abc_CommandTraceCheck(Abc_Frame_t * pAbc,int argc,char ** argv)29604 int Abc_CommandTraceCheck( Abc_Frame_t * pAbc, int argc, char ** argv )
29605 {
29606     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
29607     int c;
29608     // set defaults
29609     Extra_UtilGetoptReset();
29610     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
29611     {
29612         switch ( c )
29613         {
29614         case 'h':
29615             goto usage;
29616         default:
29617             goto usage;
29618         }
29619     }
29620 
29621     if ( pNtk == NULL )
29622     {
29623         Abc_Print( -1, "Empty network.\n" );
29624         return 1;
29625     }
29626     if ( !Abc_NtkIsStrash(pNtk) )
29627     {
29628         Abc_Print( -1, "This command is applicable to AIGs.\n" );
29629         return 1;
29630     }
29631 /*
29632     if ( !Abc_HManIsRunning(pNtk) )
29633     {
29634         Abc_Print( -1, "The tracing database is not available.\n" );
29635         return 1;
29636     }
29637 
29638     if ( !Abc_HManVerify( 1, pNtk->Id ) )
29639         Abc_Print( -1, "Verification failed.\n" );
29640     Abc_HManStop();
29641 */
29642     return 0;
29643 
29644 usage:
29645     Abc_Print( -2, "usage: trace_check [-h]\n" );
29646     Abc_Print( -2, "\t        checks the current network using verification trace\n" );
29647     Abc_Print( -2, "\t-h    : print the command usage\n");
29648     return 1;
29649 }
29650 
29651 
29652 
29653 
29654 /**Function*************************************************************
29655 
29656   Synopsis    [Compares to versions of the design and finds the best.]
29657 
29658   Description []
29659 
29660   SideEffects []
29661 
29662   SeeAlso     []
29663 
29664 ***********************************************************************/
Abc_NtkCompareWithBest(Abc_Ntk_t * pBest,Abc_Ntk_t * p,float * pnBestNtkArea,float * pnBestNtkDelay,int * pnBestNtkNodes,int * pnBestNtkLevels,int fArea)29665 static inline int Abc_NtkCompareWithBest( Abc_Ntk_t * pBest, Abc_Ntk_t * p,
29666     float * pnBestNtkArea,  float * pnBestNtkDelay,
29667     int *   pnBestNtkNodes, int *   pnBestNtkLevels, int fArea )
29668 {
29669     float nNtkArea   = (float)Abc_NtkGetMappedArea(p);
29670     float nNtkDelay  = (float)Abc_NtkDelayTrace(p, NULL, NULL, 0);
29671     int   nNtkNodes  = Abc_NtkNodeNum(p);
29672     int   nNtkLevels = Abc_NtkLevel(p);
29673 
29674     if ( pBest == NULL ||
29675          Abc_NtkPiNum(pBest)    != Abc_NtkPiNum(p)    ||
29676          Abc_NtkPoNum(pBest)    != Abc_NtkPoNum(p)    ||
29677          Abc_NtkLatchNum(pBest) != Abc_NtkLatchNum(p) ||
29678          strcmp(Abc_NtkName(pBest), Abc_NtkName(p))   ||
29679          (!fArea && (*pnBestNtkLevels > nNtkLevels || (*pnBestNtkLevels == nNtkLevels && *pnBestNtkDelay > nNtkDelay ))) ||
29680          ( fArea && (*pnBestNtkNodes  > nNtkNodes  || (*pnBestNtkNodes  == nNtkNodes  && *pnBestNtkArea  > nNtkArea  )))
29681        )
29682     {
29683         *pnBestNtkArea   = nNtkArea;
29684         *pnBestNtkDelay  = nNtkDelay;
29685         *pnBestNtkNodes  = nNtkNodes;
29686         *pnBestNtkLevels = nNtkLevels;
29687         printf( "\nUpdating the best network (Area = %10.2f  Delay = %10.2f  Nodes = %6d  Level = %6d).\n\n",
29688             nNtkArea, nNtkDelay, nNtkNodes, nNtkLevels );
29689         return 1;
29690     }
29691     return 0;
29692 }
29693 
29694 /**Function*************************************************************
29695 
29696   Synopsis    []
29697 
29698   Description []
29699 
29700   SideEffects []
29701 
29702   SeeAlso     []
29703 
29704 ***********************************************************************/
Abc_CommandAbcSave(Abc_Frame_t * pAbc,int argc,char ** argv)29705 int Abc_CommandAbcSave( Abc_Frame_t * pAbc, int argc, char ** argv )
29706 {
29707     int c, fArea = 0;
29708     Extra_UtilGetoptReset();
29709     while ( ( c = Extra_UtilGetopt( argc, argv, "ah" ) ) != EOF )
29710     {
29711         switch ( c )
29712         {
29713         case 'a':
29714             fArea ^= 1;
29715             break;
29716         case 'h':
29717             goto usage;
29718         default:
29719             goto usage;
29720         }
29721     }
29722     if ( pAbc->pNtkCur == NULL )
29723     {
29724         Abc_Print( -1, "Empty network.\n" );
29725         return 1;
29726     }
29727     if ( !Abc_NtkHasMapping(pAbc->pNtkCur) )
29728     {
29729         Abc_Print( -1, "Network has no mapping.\n" );
29730         return 1;
29731     }
29732     if ( !Abc_NtkCompareWithBest( pAbc->pNtkBest, pAbc->pNtkCur,
29733              &pAbc->nBestNtkArea,  &pAbc->nBestNtkDelay,
29734              &pAbc->nBestNtkNodes, &pAbc->nBestNtkLevels, fArea ) )
29735         return 0;
29736     // save the design as best
29737     if ( pAbc->pNtkBest ) Abc_NtkDelete( pAbc->pNtkBest );
29738     pAbc->pNtkBest = Abc_NtkDup(pAbc->pNtkCur);
29739     return 0;
29740 
29741 usage:
29742     Abc_Print( -2, "usage: save [-ah]\n" );
29743     Abc_Print( -2, "\t        compares and possibly saves network with mapping\n" );
29744     Abc_Print( -2, "\t-a    : toggle using area as the primary metric [default = %s]\n", fArea? "yes": "no" );
29745     Abc_Print( -2, "\t-h    : print the command usage\n");
29746     return 1;
29747 }
29748 
29749 /**Function*************************************************************
29750 
29751   Synopsis    []
29752 
29753   Description []
29754 
29755   SideEffects []
29756 
29757   SeeAlso     []
29758 
29759 ***********************************************************************/
Abc_CommandAbcLoad(Abc_Frame_t * pAbc,int argc,char ** argv)29760 int Abc_CommandAbcLoad( Abc_Frame_t * pAbc, int argc, char ** argv )
29761 {
29762     int c;
29763     Extra_UtilGetoptReset();
29764     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
29765     {
29766         switch ( c )
29767         {
29768         case 'h':
29769             goto usage;
29770         default:
29771             goto usage;
29772         }
29773     }
29774     // restore from best
29775     if ( pAbc->pNtkBest == NULL )
29776     {
29777         Abc_Print( -1, "Abc_CommandAbcLoad(): There is no best design saved.\n" );
29778         return 1;
29779     }
29780     if ( pAbc->pNtkCur ) Abc_NtkDelete( pAbc->pNtkCur );
29781     pAbc->pNtkCur = Abc_NtkDup(pAbc->pNtkBest);
29782     return 0;
29783 
29784 usage:
29785     Abc_Print( -2, "usage: load [-h]\n" );
29786     Abc_Print( -2, "\t        loads mapped network previously saved by \"save\"\n" );
29787     Abc_Print( -2, "\t-h    : print the command usage\n");
29788     return 1;
29789 }
29790 
29791 /**Function*************************************************************
29792 
29793   Synopsis    []
29794 
29795   Description []
29796 
29797   SideEffects []
29798 
29799   SeeAlso     []
29800 
29801 ***********************************************************************/
Abc_CommandAbc9Read(Abc_Frame_t * pAbc,int argc,char ** argv)29802 int Abc_CommandAbc9Read( Abc_Frame_t * pAbc, int argc, char ** argv )
29803 {
29804     extern void Abc3_ReadShowHie( char * pFileName, int fFlat );
29805     Gia_Man_t * pAig = NULL;
29806     FILE * pFile;
29807     char ** pArgvNew;
29808     char * FileName, * pTemp;
29809     int c, nArgcNew;
29810     int fMiniAig = 0;
29811     int fMiniLut = 0;
29812     int fVerbose = 0;
29813     int fGiaSimple = 0;
29814     int fSkipStrash = 0;
29815     Extra_UtilGetoptReset();
29816     while ( ( c = Extra_UtilGetopt( argc, argv, "csmlvh" ) ) != EOF )
29817     {
29818         switch ( c )
29819         {
29820         case 'c':
29821             fGiaSimple ^= 1;
29822             break;
29823         case 's':
29824             fSkipStrash ^= 1;
29825             break;
29826         case 'm':
29827             fMiniAig ^= 1;
29828             break;
29829         case 'l':
29830             fMiniLut ^= 1;
29831             break;
29832         case 'v':
29833             fVerbose ^= 1;
29834             break;
29835         default:
29836             goto usage;
29837         }
29838     }
29839     pArgvNew = argv + globalUtilOptind;
29840     nArgcNew = argc - globalUtilOptind;
29841     if ( nArgcNew != 1 )
29842     {
29843         Abc_Print( -1, "There is no file name.\n" );
29844         return 1;
29845     }
29846 
29847     // get the input file name
29848     FileName = pArgvNew[0];
29849     // fix the wrong symbol
29850     for ( pTemp = FileName; *pTemp; pTemp++ )
29851         if ( *pTemp == '>' )
29852             *pTemp = '\\';
29853     if ( (pFile = fopen( FileName, "r" )) == NULL )
29854     {
29855         Abc_Print( -1, "Cannot open input file \"%s\". ", FileName );
29856         if ( (FileName = Extra_FileGetSimilarName( FileName, ".aig", ".blif", ".pla", ".eqn", ".bench" )) )
29857             Abc_Print( 1, "Did you mean \"%s\"?", FileName );
29858         Abc_Print( 1, "\n" );
29859         return 1;
29860     }
29861     fclose( pFile );
29862 
29863     if ( fMiniAig )
29864         pAig = Gia_ManReadMiniAig( FileName );
29865     else if ( fMiniLut )
29866         pAig = Gia_ManReadMiniLut( FileName );
29867 //    else if ( Extra_FileIsType( FileName, ".v", NULL, NULL ) )
29868 //        Abc3_ReadShowHie( FileName, fSkipStrash );
29869     else
29870         pAig = Gia_AigerRead( FileName, fGiaSimple, fSkipStrash, 0 );
29871     if ( pAig )
29872         Abc_FrameUpdateGia( pAbc, pAig );
29873     return 0;
29874 
29875 usage:
29876     Abc_Print( -2, "usage: &r [-csmlvh] <file>\n" );
29877     Abc_Print( -2, "\t         reads the current AIG from the AIGER file\n" );
29878     Abc_Print( -2, "\t-c     : toggles reading simple AIG [default = %s]\n", fGiaSimple? "yes": "no" );
29879     Abc_Print( -2, "\t-s     : toggles structural hashing while reading [default = %s]\n", !fSkipStrash? "yes": "no" );
29880     Abc_Print( -2, "\t-m     : toggles reading MiniAIG rather than AIGER file [default = %s]\n", fMiniAig? "yes": "no" );
29881     Abc_Print( -2, "\t-l     : toggles reading MiniLUT rather than AIGER file [default = %s]\n", fMiniLut? "yes": "no" );
29882     Abc_Print( -2, "\t-v     : toggles additional verbose output [default = %s]\n", fVerbose? "yes": "no" );
29883     Abc_Print( -2, "\t-h     : print the command usage\n");
29884     Abc_Print( -2, "\t<file> : the file name\n");
29885     return 1;
29886 }
29887 
29888 /**Function*************************************************************
29889 
29890   Synopsis    []
29891 
29892   Description []
29893 
29894   SideEffects []
29895 
29896   SeeAlso     []
29897 
29898 ***********************************************************************/
Abc_CommandAbc9ReadBlif(Abc_Frame_t * pAbc,int argc,char ** argv)29899 int Abc_CommandAbc9ReadBlif( Abc_Frame_t * pAbc, int argc, char ** argv )
29900 {
29901     extern Gia_Man_t * Abc_NtkHieCecTest( char * pFileName, int fVerbose );
29902     Gia_Man_t * pAig;
29903     FILE * pFile;
29904     char ** pArgvNew;
29905     char * FileName, * pTemp;
29906     int nArgcNew;
29907     int c, fVerbose = 0;
29908     Extra_UtilGetoptReset();
29909     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
29910     {
29911         switch ( c )
29912         {
29913         case 'v':
29914             fVerbose ^= 1;
29915             break;
29916         default:
29917             goto usage;
29918         }
29919     }
29920     pArgvNew = argv + globalUtilOptind;
29921     nArgcNew = argc - globalUtilOptind;
29922     if ( nArgcNew != 1 )
29923     {
29924         Abc_Print( -1, "There is no file name.\n" );
29925         return 1;
29926     }
29927 
29928     // get the input file name
29929     FileName = pArgvNew[0];
29930     // fix the wrong symbol
29931     for ( pTemp = FileName; *pTemp; pTemp++ )
29932         if ( *pTemp == '>' )
29933             *pTemp = '\\';
29934     if ( (pFile = fopen( FileName, "r" )) == NULL )
29935     {
29936         Abc_Print( -1, "Cannot open input file \"%s\". ", FileName );
29937         if ( (FileName = Extra_FileGetSimilarName( FileName, ".blif", NULL, NULL, NULL, NULL )) )
29938             Abc_Print( 1, "Did you mean \"%s\"?", FileName );
29939         Abc_Print( 1, "\n" );
29940         return 1;
29941     }
29942     fclose( pFile );
29943 
29944     pAig = Abc_NtkHieCecTest( FileName, fVerbose );
29945     Abc_FrameUpdateGia( pAbc, pAig );
29946     return 0;
29947 
29948 usage:
29949     Abc_Print( -2, "usage: &read_blif [-vh] <file>\n" );
29950     Abc_Print( -2, "\t         a specialized reader for hierarchical BLIF files\n" );
29951     Abc_Print( -2, "\t         (for general-purpose BLIFs, please use \"read_blif\")\n" );
29952     Abc_Print( -2, "\t-v     : toggles additional verbose output [default = %s]\n", fVerbose? "yes": "no" );
29953     Abc_Print( -2, "\t-h     : print the command usage\n");
29954     Abc_Print( -2, "\t<file> : the file name\n");
29955     return 1;
29956 }
29957 
29958 /**Function*************************************************************
29959 
29960   Synopsis    []
29961 
29962   Description []
29963 
29964   SideEffects []
29965 
29966   SeeAlso     []
29967 
29968 ***********************************************************************/
Abc_CommandAbc9ReadCBlif(Abc_Frame_t * pAbc,int argc,char ** argv)29969 int Abc_CommandAbc9ReadCBlif( Abc_Frame_t * pAbc, int argc, char ** argv )
29970 {
29971     extern Gia_Man_t * Abc_NtkHieCecTest2( char * pFileName, char * pModelName, int fVerbose );
29972     Gia_Man_t * pAig;
29973     FILE * pFile;
29974     char ** pArgvNew;
29975     char * FileName, * pTemp;
29976     char * pModelName = NULL;
29977     int nArgcNew;
29978     int c, fVerbose = 0;
29979     Extra_UtilGetoptReset();
29980     while ( ( c = Extra_UtilGetopt( argc, argv, "Mvh" ) ) != EOF )
29981     {
29982         switch ( c )
29983         {
29984         case 'M':
29985             if ( globalUtilOptind >= argc )
29986             {
29987                 Abc_Print( -1, "Command line switch \"-M\" should be followed by a file name.\n" );
29988                 goto usage;
29989             }
29990             pModelName = argv[globalUtilOptind];
29991             globalUtilOptind++;
29992             break;
29993         case 'v':
29994             fVerbose ^= 1;
29995             break;
29996         default:
29997             goto usage;
29998         }
29999     }
30000     pArgvNew = argv + globalUtilOptind;
30001     nArgcNew = argc - globalUtilOptind;
30002     if ( nArgcNew != 1 )
30003     {
30004         Abc_Print( -1, "There is no file name.\n" );
30005         return 1;
30006     }
30007 
30008     // get the input file name
30009     FileName = pArgvNew[0];
30010     // fix the wrong symbol
30011     for ( pTemp = FileName; *pTemp; pTemp++ )
30012         if ( *pTemp == '>' )
30013             *pTemp = '\\';
30014     if ( (pFile = fopen( FileName, "r" )) == NULL )
30015     {
30016         Abc_Print( -1, "Cannot open input file \"%s\". ", FileName );
30017         if ( (FileName = Extra_FileGetSimilarName( FileName, ".cblif", NULL, NULL, NULL, NULL )) )
30018             Abc_Print( 1, "Did you mean \"%s\"?", FileName );
30019         Abc_Print( 1, "\n" );
30020         return 1;
30021     }
30022     fclose( pFile );
30023 
30024     pAig = Abc_NtkHieCecTest2( FileName, pModelName, fVerbose );
30025     Abc_FrameUpdateGia( pAbc, pAig );
30026     return 0;
30027 
30028 usage:
30029     Abc_Print( -2, "usage: &read_cblif [-M name] [-vh] <file>\n" );
30030     Abc_Print( -2, "\t         reads CBLIF file and collapse it into an AIG\n" );
30031     Abc_Print( -2, "\t-M name: module name to collapse [default = <root_module>]\n" );
30032     Abc_Print( -2, "\t-v     : toggles additional verbose output [default = %s]\n", fVerbose? "yes": "no" );
30033     Abc_Print( -2, "\t-h     : print the command usage\n");
30034     Abc_Print( -2, "\t<file> : the file name\n");
30035     return 1;
30036 }
30037 
30038 /**Function*************************************************************
30039 
30040   Synopsis    []
30041 
30042   Description []
30043 
30044   SideEffects []
30045 
30046   SeeAlso     []
30047 
30048 ***********************************************************************/
Abc_CommandAbc9ReadStg(Abc_Frame_t * pAbc,int argc,char ** argv)30049 int Abc_CommandAbc9ReadStg( Abc_Frame_t * pAbc, int argc, char ** argv )
30050 {
30051     Gia_Man_t * pAig;
30052     FILE * pFile;
30053     char * FileName, ** pArgvNew;
30054     int c, nArgcNew;
30055     int kHot = 1;
30056     int fVerbose = 0;
30057     Extra_UtilGetoptReset();
30058     while ( ( c = Extra_UtilGetopt( argc, argv, "Kvh" ) ) != EOF )
30059     {
30060         switch ( c )
30061         {
30062         case 'K':
30063             if ( globalUtilOptind >= argc )
30064             {
30065                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
30066                 goto usage;
30067             }
30068             kHot = atoi(argv[globalUtilOptind]);
30069             globalUtilOptind++;
30070             if ( kHot < 1 || kHot > 5 )
30071                 goto usage;
30072             break;
30073         case 'v':
30074             fVerbose ^= 1;
30075             break;
30076         default:
30077             goto usage;
30078         }
30079     }
30080     pArgvNew = argv + globalUtilOptind;
30081     nArgcNew = argc - globalUtilOptind;
30082     if ( nArgcNew != 1 )
30083     {
30084         Abc_Print( -1, "There is no file name.\n" );
30085         return 1;
30086     }
30087 
30088     // get the input file name
30089     FileName = pArgvNew[0];
30090     if ( (pFile = fopen( FileName, "r" )) == NULL )
30091     {
30092         Abc_Print( -1, "Cannot open input file \"%s\". ", FileName );
30093         return 1;
30094     }
30095     fclose( pFile );
30096 
30097     pAig = Gia_ManStgRead( FileName, kHot, fVerbose );
30098     Abc_FrameUpdateGia( pAbc, pAig );
30099     return 0;
30100 
30101 usage:
30102     Abc_Print( -2, "usage: &read_stg [-K <num>] [-vh] <file>\n" );
30103     Abc_Print( -2, "\t         reads STG file and generates K-hot-encoded AIG\n" );
30104     Abc_Print( -2, "\t-K num : the K parameter for hotness of the encoding (1 <= K <= 5) [default = %d]\n", kHot );
30105     Abc_Print( -2, "\t-v     : toggles printing state codes [default = %s]\n", fVerbose? "yes": "no" );
30106     Abc_Print( -2, "\t-h     : print the command usage\n");
30107     Abc_Print( -2, "\t<file> : the file name\n");
30108     return 1;
30109 }
30110 
30111 /**Function*************************************************************
30112 
30113   Synopsis    []
30114 
30115   Description []
30116 
30117   SideEffects []
30118 
30119   SeeAlso     []
30120 
30121 ***********************************************************************/
Abc_CommandAbc9ReadVer(Abc_Frame_t * pAbc,int argc,char ** argv)30122 int Abc_CommandAbc9ReadVer( Abc_Frame_t * pAbc, int argc, char ** argv )
30123 {
30124     Abc_Ntk_t * pNtk;
30125     Gia_Man_t * pAig;
30126     FILE * pFile;
30127     char ** pArgvNew;
30128     char * pFileName, * pTemp;
30129     int nArgcNew;
30130     int c, fVerbose = 0;
30131     Extra_UtilGetoptReset();
30132     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
30133     {
30134         switch ( c )
30135         {
30136         case 'v':
30137             fVerbose ^= 1;
30138             break;
30139         default:
30140             goto usage;
30141         }
30142     }
30143     pArgvNew = argv + globalUtilOptind;
30144     nArgcNew = argc - globalUtilOptind;
30145     if ( nArgcNew != 1 )
30146     {
30147         Abc_Print( -1, "There is no file name.\n" );
30148         return 1;
30149     }
30150 
30151     // get the input file name
30152     pFileName = pArgvNew[0];
30153     // fix the wrong symbol
30154     for ( pTemp = pFileName; *pTemp; pTemp++ )
30155         if ( *pTemp == '>' )
30156             *pTemp = '\\';
30157     if ( (pFile = fopen( pFileName, "r" )) == NULL )
30158     {
30159         Abc_Print( -1, "Cannot open input file \"%s\". ", pFileName );
30160         if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".v", ".blif", NULL, NULL, NULL )) )
30161             Abc_Print( 1, "Did you mean \"%s\"?", pFileName );
30162         Abc_Print( 1, "\n" );
30163         return 1;
30164     }
30165     fclose( pFile );
30166     // read hierarchical Verilog
30167     pNtk = Io_ReadNetlist( pFileName, Io_ReadFileType(pFileName), 0 );
30168     if ( pNtk == NULL )
30169     {
30170         Abc_Print( -1, "Reading hierarchical Verilog has failed.\n" );
30171         return 1;
30172     }
30173     pAig = Abc_NtkFlattenHierarchyGia( pNtk, NULL, fVerbose );
30174     Abc_NtkDelete( pNtk );
30175     Abc_FrameUpdateGia( pAbc, pAig );
30176     return 0;
30177 
30178 usage:
30179     Abc_Print( -2, "usage: &read_ver [-vh] <file>\n" );
30180     Abc_Print( -2, "\t         a specialized reader for hierarchical Verilog files\n" );
30181     Abc_Print( -2, "\t-v     : toggles additional verbose output [default = %s]\n", fVerbose? "yes": "no" );
30182     Abc_Print( -2, "\t-h     : print the command usage\n");
30183     Abc_Print( -2, "\t<file> : the file name\n");
30184     return 1;
30185 }
30186 
30187 /**Function*************************************************************
30188 
30189   Synopsis    []
30190 
30191   Description []
30192 
30193   SideEffects []
30194 
30195   SeeAlso     []
30196 
30197 ***********************************************************************/
Abc_CommandAbc9Get(Abc_Frame_t * pAbc,int argc,char ** argv)30198 int Abc_CommandAbc9Get( Abc_Frame_t * pAbc, int argc, char ** argv )
30199 {
30200     extern Aig_Man_t * Abc_NtkToDarChoices( Abc_Ntk_t * pNtk );
30201     extern Vec_Ptr_t * Abc_NtkCollectCiNames( Abc_Ntk_t * pNtk );
30202     extern Vec_Ptr_t * Abc_NtkCollectCoNames( Abc_Ntk_t * pNtk );
30203     Abc_Ntk_t * pStrash;
30204     Aig_Man_t * pAig;
30205     Gia_Man_t * pGia, * pTemp;
30206     char * pInits;
30207     int c, fGiaSimple = 0, fMapped = 0, fNames = 0, fVerbose = 0;
30208     Extra_UtilGetoptReset();
30209     while ( ( c = Extra_UtilGetopt( argc, argv, "cmnvh" ) ) != EOF )
30210     {
30211         switch ( c )
30212         {
30213         case 'c':
30214             fGiaSimple ^= 1;
30215             break;
30216         case 'm':
30217             fMapped ^= 1;
30218             break;
30219         case 'n':
30220             fNames ^= 1;
30221             break;
30222         case 'v':
30223             fVerbose ^= 1;
30224             break;
30225         default:
30226             goto usage;
30227         }
30228     }
30229     if ( pAbc->pNtkCur == NULL )
30230     {
30231         Abc_Print( -1, "There is no current network\n" );
30232         return 1;
30233     }
30234     if ( !Abc_NtkIsStrash( pAbc->pNtkCur ) )
30235     {
30236         if ( fGiaSimple || fMapped )
30237         {
30238             assert( Abc_NtkIsLogic(pAbc->pNtkCur) );
30239             Abc_NtkToAig( pAbc->pNtkCur );
30240             pGia = Abc_NtkAigToGia( pAbc->pNtkCur, fGiaSimple );
30241         }
30242         else
30243         {
30244             // derive comb GIA
30245             pStrash = Abc_NtkStrash( pAbc->pNtkCur, 0, 1, 0 );
30246             pAig = Abc_NtkToDar( pStrash, 0, 0 );
30247             Abc_NtkDelete( pStrash );
30248             pGia = Gia_ManFromAig( pAig );
30249             Aig_ManStop( pAig );
30250             // perform undc/zero
30251             pInits = Abc_NtkCollectLatchValuesStr( pAbc->pNtkCur );
30252             pGia = Gia_ManDupZeroUndc( pTemp = pGia, pInits, 0, 0, fVerbose );
30253             Gia_ManStop( pTemp );
30254             ABC_FREE( pInits );
30255         }
30256     }
30257     else
30258     {
30259         if ( Abc_NtkGetChoiceNum(pAbc->pNtkCur) )
30260             pAig = Abc_NtkToDarChoices( pAbc->pNtkCur );
30261         else
30262             pAig = Abc_NtkToDar( pAbc->pNtkCur, 0, 1 );
30263         pGia = Gia_ManFromAig( pAig );
30264         Aig_ManStop( pAig );
30265     }
30266     // copy names
30267     if ( fNames )
30268     {
30269         pGia->vNamesIn  = Abc_NtkCollectCiNames( pAbc->pNtkCur );
30270         pGia->vNamesOut = Abc_NtkCollectCoNames( pAbc->pNtkCur );
30271     }
30272     // copy user timing information
30273     if ( pAbc->pNtkCur->pManTime != NULL )
30274     {
30275         Abc_Ntk_t * pNtk = pAbc->pNtkCur;
30276         Vec_FltFreeP( &pGia->vInArrs );
30277         Vec_FltFreeP( &pGia->vOutReqs );
30278         pGia->DefInArrs  = Abc_NtkReadDefaultArrivalWorst(pNtk);
30279         pGia->DefOutReqs = Abc_NtkReadDefaultRequiredWorst(pNtk);
30280         pGia->vInArrs  = Vec_FltAllocArray( Abc_NtkGetCiArrivalFloats(pNtk), Abc_NtkCiNum(pNtk) );
30281         pGia->vOutReqs = Vec_FltAllocArray( Abc_NtkGetCoRequiredFloats(pNtk), Abc_NtkCoNum(pNtk) );
30282         pGia->And2Delay = pNtk->AndGateDelay;
30283     }
30284     Abc_FrameUpdateGia( pAbc, pGia );
30285     return 0;
30286 
30287 usage:
30288     Abc_Print( -2, "usage: &get [-cmnvh] <file>\n" );
30289     Abc_Print( -2, "\t         converts the current network into GIA and moves it to the &-space\n" );
30290     Abc_Print( -2, "\t         (if the network is a sequential logic network, normalizes the flops\n" );
30291     Abc_Print( -2, "\t         to have const-0 initial values, equivalent to \"undc; st; zero\")\n" );
30292     Abc_Print( -2, "\t-c     : toggles allowing simple GIA to be imported [default = %s]\n", fGiaSimple? "yes": "no" );
30293     Abc_Print( -2, "\t-m     : toggles preserving the current mapping [default = %s]\n", fMapped? "yes": "no" );
30294     Abc_Print( -2, "\t-n     : toggles saving CI/CO names of the AIG [default = %s]\n", fNames? "yes": "no" );
30295     Abc_Print( -2, "\t-v     : toggles additional verbose output [default = %s]\n", fVerbose? "yes": "no" );
30296     Abc_Print( -2, "\t-h     : print the command usage\n");
30297     Abc_Print( -2, "\t<file> : the file name\n");
30298     return 1;
30299 }
30300 
30301 /**Function*************************************************************
30302 
30303   Synopsis    []
30304 
30305   Description []
30306 
30307   SideEffects []
30308 
30309   SeeAlso     []
30310 
30311 ***********************************************************************/
Abc_CommandAbc9Put(Abc_Frame_t * pAbc,int argc,char ** argv)30312 int Abc_CommandAbc9Put( Abc_Frame_t * pAbc, int argc, char ** argv )
30313 {
30314     extern Abc_Ntk_t * Abc_NtkFromDarChoices( Abc_Ntk_t * pNtkOld, Aig_Man_t * pMan );
30315     extern void Abc_NtkRedirectCiCo( Abc_Ntk_t * pNtk );
30316     extern Abc_Ntk_t * Abc_NtkFromCellMappedGia( Gia_Man_t * p, int fUseBuffs );
30317     extern Abc_Ntk_t * Abc_NtkFromMappedGia( Gia_Man_t * p, int fFindEnables, int fUseBuffs );
30318 
30319     Aig_Man_t * pMan;
30320     Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
30321     int fStatusClear = 1;
30322     int fFindEnables = 0;
30323     int fUseBuffs    = 0;
30324     int c, fVerbose  = 0;
30325 
30326     Extra_UtilGetoptReset();
30327     while ( ( c = Extra_UtilGetopt( argc, argv, "seovh" ) ) != EOF )
30328     {
30329         switch ( c )
30330         {
30331         case 's':
30332             fStatusClear ^= 1;
30333             break;
30334         case 'e':
30335             fFindEnables ^= 1;
30336             break;
30337         case 'o':
30338             fUseBuffs ^= 1;
30339             break;
30340         case 'v':
30341             fVerbose ^= 1;
30342             break;
30343         case 'h':
30344             goto usage;
30345         default:
30346             goto usage;
30347         }
30348     }
30349     if ( pAbc->pGia == NULL )
30350     {
30351         Abc_Print( -1, "Empty network.\n" );
30352         return 1;
30353     }
30354     if ( fFindEnables )
30355         pNtk = Abc_NtkFromMappedGia( pAbc->pGia, 1, fUseBuffs );
30356     else if ( Gia_ManHasCellMapping(pAbc->pGia) )
30357         pNtk = Abc_NtkFromCellMappedGia( pAbc->pGia, fUseBuffs );
30358     else if ( Gia_ManHasMapping(pAbc->pGia) || pAbc->pGia->pMuxes )
30359         pNtk = Abc_NtkFromMappedGia( pAbc->pGia, 0, fUseBuffs );
30360     else if ( Gia_ManHasDangling(pAbc->pGia) == 0 )
30361     {
30362         pMan = Gia_ManToAig( pAbc->pGia, 0 );
30363         pNtk = Abc_NtkFromAigPhase( pMan );
30364         pNtk->pName = Extra_UtilStrsav(pMan->pName);
30365         Aig_ManStop( pMan );
30366     }
30367     else
30368     {
30369         Abc_Ntk_t * pNtkNoCh;
30370 //        Abc_Print( -1, "Transforming AIG with %d choice nodes.\n", Gia_ManEquivCountClasses(pAbc->pGia) );
30371         // create network without choices
30372         pMan = Gia_ManToAig( pAbc->pGia, 0 );
30373         pNtkNoCh = Abc_NtkFromAigPhase( pMan );
30374         pNtkNoCh->pName = Extra_UtilStrsav(pMan->pName);
30375         Aig_ManStop( pMan );
30376         // derive network with choices
30377         pMan = Gia_ManToAig( pAbc->pGia, 1 );
30378         pNtk = Abc_NtkFromDarChoices( pNtkNoCh, pMan );
30379         Abc_NtkDelete( pNtkNoCh );
30380         Aig_ManStop( pMan );
30381     }
30382     // transfer PI names to pNtk
30383     if ( pAbc->pGia->vNamesIn )
30384     {
30385         Abc_Obj_t * pObj;
30386         int i;
30387         Abc_NtkForEachCi( pNtk, pObj, i ) {
30388             if (i < Vec_PtrSize(pAbc->pGia->vNamesIn)) {
30389                 Nm_ManDeleteIdName(pNtk->pManName, pObj->Id);
30390                 Abc_ObjAssignName( pObj, (char *)Vec_PtrEntry(pAbc->pGia->vNamesIn, i), NULL );
30391             }
30392         }
30393     }
30394     // transfer PO names to pNtk
30395     if ( pAbc->pGia->vNamesOut )
30396     {
30397         char pSuffix[100];
30398         Abc_Obj_t * pObj;
30399         int i, nDigits = Abc_Base10Log( Abc_NtkLatchNum(pNtk) );
30400         Abc_NtkForEachCo( pNtk, pObj, i ) {
30401             if (i < Vec_PtrSize(pAbc->pGia->vNamesOut)) {
30402                 Nm_ManDeleteIdName(pNtk->pManName, pObj->Id);
30403                 if ( Abc_ObjIsPo(pObj) )
30404                     Abc_ObjAssignName( pObj, (char *)Vec_PtrEntry(pAbc->pGia->vNamesOut, i), NULL );
30405                 else
30406                 {
30407                     assert( i >= Abc_NtkPoNum(pNtk) );
30408                     sprintf( pSuffix, "_li%0*d", nDigits, i-Abc_NtkPoNum(pNtk) );
30409                     Abc_ObjAssignName( pObj, (char *)Vec_PtrEntry(pAbc->pGia->vNamesOut, i), pSuffix );
30410                 }
30411             }
30412         }
30413     }
30414 
30415     // decouple CI/CO with the same name
30416     if ( pAbc->pGia->vNamesIn || pAbc->pGia->vNamesOut )
30417         Abc_NtkRedirectCiCo( pNtk );
30418 
30419     // transfer timing information
30420     if ( pAbc->pGia->vInArrs || pAbc->pGia->vOutReqs )
30421     {
30422         Abc_Obj_t * pObj; int i;
30423         Abc_NtkTimeInitialize( pNtk, NULL );
30424         Abc_NtkTimeSetDefaultArrival( pNtk, pAbc->pGia->DefInArrs, pAbc->pGia->DefInArrs );
30425         Abc_NtkTimeSetDefaultRequired( pNtk, pAbc->pGia->DefOutReqs, pAbc->pGia->DefOutReqs );
30426         if ( pAbc->pGia->vInArrs )
30427             Abc_NtkForEachCi( pNtk, pObj, i )
30428                 Abc_NtkTimeSetArrival( pNtk, Abc_ObjId(pObj), Vec_FltEntry(pAbc->pGia->vInArrs, i), Vec_FltEntry(pAbc->pGia->vInArrs, i) );
30429         if ( pAbc->pGia->vOutReqs )
30430             Abc_NtkForEachCo( pNtk, pObj, i )
30431                 Abc_NtkTimeSetRequired( pNtk, Abc_ObjId(pObj), Vec_FltEntry(pAbc->pGia->vOutReqs, i), Vec_FltEntry(pAbc->pGia->vOutReqs, i) );
30432     }
30433 
30434     // replace the current network
30435     Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
30436     if ( fStatusClear )
30437         Abc_FrameClearVerifStatus( pAbc );
30438     return 0;
30439 
30440 usage:
30441     Abc_Print( -2, "usage: &put [-seovh]\n" );
30442     Abc_Print( -2, "\t         transfer the current network into the old ABC\n" );
30443     Abc_Print( -2, "\t-s     : toggle clearning verification status [default = %s]\n", fStatusClear? "yes": "no" );
30444     Abc_Print( -2, "\t-e     : toggle extracting MUXes for flop enables [default = %s]\n", fFindEnables? "yes": "no" );
30445     Abc_Print( -2, "\t-o     : toggles using buffers to decouple combinational outputs [default = %s]\n", fUseBuffs? "yes": "no" );
30446     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
30447     Abc_Print( -2, "\t-h     : print the command usage\n");
30448     return 1;
30449 }
30450 
30451 
30452 /**Function*************************************************************
30453 
30454   Synopsis    [Compares to versions of the design and finds the best.]
30455 
30456   Description []
30457 
30458   SideEffects []
30459 
30460   SeeAlso     []
30461 
30462 ***********************************************************************/
Gia_ManCompareWithBest(Gia_Man_t * pBest,Gia_Man_t * p,int * pnBestLuts,int * pnBestEdges,int * pnBestLevels,int fArea)30463 static inline int Gia_ManCompareWithBest( Gia_Man_t * pBest, Gia_Man_t * p, int * pnBestLuts, int * pnBestEdges, int * pnBestLevels, int fArea )
30464 {
30465     int nCurLuts, nCurEdges, nCurLevels;
30466     Gia_ManLutParams( p, &nCurLuts, &nCurEdges, &nCurLevels );
30467     if ( pBest == NULL ||
30468          Gia_ManPiNum(pBest) != Gia_ManPiNum(p) ||
30469          Gia_ManPoNum(pBest) != Gia_ManPoNum(p) ||
30470          Gia_ManRegNum(pBest) != Gia_ManRegNum(p) ||
30471          strcmp(Gia_ManName(pBest), Gia_ManName(p)) ||
30472          (!fArea && (*pnBestLevels > nCurLevels || (*pnBestLevels == nCurLevels && 2*(*pnBestLuts) + *pnBestEdges > 2*nCurLuts + nCurEdges))) ||
30473          ( fArea && (*pnBestLuts   > nCurLuts   || (*pnBestLuts   == nCurLuts   && *pnBestLevels > nCurLevels)))
30474        )
30475     {
30476         *pnBestLuts = nCurLuts;
30477         *pnBestEdges = nCurEdges;
30478         *pnBestLevels = nCurLevels;
30479         //printf( "\nUpdating best (%d %d %d).\n\n", nCurLuts, nCurEdges, nCurLevels );
30480         return 1;
30481     }
30482     return 0;
30483 }
30484 
30485 /**Function*************************************************************
30486 
30487   Synopsis    []
30488 
30489   Description []
30490 
30491   SideEffects []
30492 
30493   SeeAlso     []
30494 
30495 ***********************************************************************/
Abc_CommandAbc9Save(Abc_Frame_t * pAbc,int argc,char ** argv)30496 int Abc_CommandAbc9Save( Abc_Frame_t * pAbc, int argc, char ** argv )
30497 {
30498     int c, fArea = 0;
30499     Extra_UtilGetoptReset();
30500     while ( ( c = Extra_UtilGetopt( argc, argv, "ah" ) ) != EOF )
30501     {
30502         switch ( c )
30503         {
30504         case 'a':
30505             fArea ^= 1;
30506             break;
30507         case 'h':
30508             goto usage;
30509         default:
30510             goto usage;
30511         }
30512     }
30513     if ( pAbc->pGia == NULL )
30514     {
30515         Abc_Print( -1, "Empty network.\n" );
30516         return 1;
30517     }
30518     if ( !Gia_ManHasMapping(pAbc->pGia) )
30519     {
30520         Abc_Print( -1, "GIA has no mapping.\n" );
30521         return 1;
30522     }
30523     if ( !Gia_ManCompareWithBest( pAbc->pGiaBest, pAbc->pGia, &pAbc->nBestLuts, &pAbc->nBestEdges, &pAbc->nBestLevels, fArea ) )
30524         return 0;
30525     // save the design as best
30526     Gia_ManStopP( &pAbc->pGiaBest );
30527     pAbc->pGiaBest = Gia_ManDupWithAttributes( pAbc->pGia );
30528     return 0;
30529 
30530 usage:
30531     Abc_Print( -2, "usage: &save [-ah]\n" );
30532     Abc_Print( -2, "\t        compares and possibly saves AIG with mapping\n" );
30533     Abc_Print( -2, "\t-a    : toggle using area as the primary metric [default = %s]\n", fArea? "yes": "no" );
30534     Abc_Print( -2, "\t-h    : print the command usage\n");
30535     return 1;
30536 }
30537 
30538 /**Function*************************************************************
30539 
30540   Synopsis    []
30541 
30542   Description []
30543 
30544   SideEffects []
30545 
30546   SeeAlso     []
30547 
30548 ***********************************************************************/
Abc_CommandAbc9Save2(Abc_Frame_t * pAbc,int argc,char ** argv)30549 int Abc_CommandAbc9Save2( Abc_Frame_t * pAbc, int argc, char ** argv )
30550 {
30551     int c, fArea = 0;
30552     Extra_UtilGetoptReset();
30553     while ( ( c = Extra_UtilGetopt( argc, argv, "ah" ) ) != EOF )
30554     {
30555         switch ( c )
30556         {
30557         case 'a':
30558             fArea ^= 1;
30559             break;
30560         case 'h':
30561             goto usage;
30562         default:
30563             goto usage;
30564         }
30565     }
30566     if ( pAbc->pGia == NULL )
30567     {
30568         Abc_Print( -1, "Empty network.\n" );
30569         return 1;
30570     }
30571     if ( !Gia_ManHasMapping(pAbc->pGia) )
30572     {
30573         Abc_Print( -1, "GIA has no mapping.\n" );
30574         return 1;
30575     }
30576     if ( !Gia_ManCompareWithBest( pAbc->pGiaBest2, pAbc->pGia, &pAbc->nBestLuts2, &pAbc->nBestEdges2, &pAbc->nBestLevels2, fArea ) )
30577         return 0;
30578     // save the design as best
30579     Gia_ManStopP( &pAbc->pGiaBest2 );
30580     pAbc->pGiaBest2 = Gia_ManDupWithAttributes( pAbc->pGia );
30581     return 0;
30582 
30583 usage:
30584     Abc_Print( -2, "usage: &save2 [-ah]\n" );
30585     Abc_Print( -2, "\t        compares and possibly saves AIG with mapping\n" );
30586     Abc_Print( -2, "\t-a    : toggle using area as the primary metric [default = %s]\n", fArea? "yes": "no" );
30587     Abc_Print( -2, "\t-h    : print the command usage\n");
30588     return 1;
30589 }
30590 
30591 /**Function*************************************************************
30592 
30593   Synopsis    []
30594 
30595   Description []
30596 
30597   SideEffects []
30598 
30599   SeeAlso     []
30600 
30601 ***********************************************************************/
Abc_CommandAbc9SaveAig(Abc_Frame_t * pAbc,int argc,char ** argv)30602 int Abc_CommandAbc9SaveAig( Abc_Frame_t * pAbc, int argc, char ** argv )
30603 {
30604     int c;
30605     Extra_UtilGetoptReset();
30606     while ( ( c = Extra_UtilGetopt( argc, argv, "ah" ) ) != EOF )
30607     {
30608         switch ( c )
30609         {
30610         case 'h':
30611             goto usage;
30612         default:
30613             goto usage;
30614         }
30615     }
30616     if ( pAbc->pGia == NULL )
30617     {
30618         Abc_Print( -1, "Empty network.\n" );
30619         return 1;
30620     }
30621     // save the design as best
30622     Gia_ManStopP( &pAbc->pGiaSaved );
30623     pAbc->pGiaSaved = Gia_ManDupWithAttributes( pAbc->pGia );
30624     return 0;
30625 
30626 usage:
30627     Abc_Print( -2, "usage: &saveaig [-ah]\n" );
30628     Abc_Print( -2, "\t        saves the current AIG into the internal storage\n" );
30629     Abc_Print( -2, "\t-h    : print the command usage\n");
30630     return 1;
30631 }
30632 
30633 /**Function*************************************************************
30634 
30635   Synopsis    []
30636 
30637   Description []
30638 
30639   SideEffects []
30640 
30641   SeeAlso     []
30642 
30643 ***********************************************************************/
Abc_CommandAbc9Load(Abc_Frame_t * pAbc,int argc,char ** argv)30644 int Abc_CommandAbc9Load( Abc_Frame_t * pAbc, int argc, char ** argv )
30645 {
30646     int c;
30647     Extra_UtilGetoptReset();
30648     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
30649     {
30650         switch ( c )
30651         {
30652         case 'h':
30653             goto usage;
30654         default:
30655             goto usage;
30656         }
30657     }
30658     // restore from best
30659     if ( pAbc->pGiaBest == NULL )
30660     {
30661         Abc_Print( -1, "Abc_CommandAbc9Load(): There is no best design saved.\n" );
30662         return 1;
30663     }
30664     Gia_ManStopP( &pAbc->pGia );
30665     pAbc->pGia = Gia_ManDupWithAttributes( pAbc->pGiaBest );
30666     return 0;
30667 
30668 usage:
30669     Abc_Print( -2, "usage: &load [-h]\n" );
30670     Abc_Print( -2, "\t        loads AIG with mapping previously saved by &save\n" );
30671     Abc_Print( -2, "\t        (after loading the previously saved AIG can be loaded again)\n" );
30672     Abc_Print( -2, "\t-h    : print the command usage\n");
30673     return 1;
30674 }
30675 
30676 /**Function*************************************************************
30677 
30678   Synopsis    []
30679 
30680   Description []
30681 
30682   SideEffects []
30683 
30684   SeeAlso     []
30685 
30686 ***********************************************************************/
Abc_CommandAbc9Load2(Abc_Frame_t * pAbc,int argc,char ** argv)30687 int Abc_CommandAbc9Load2( Abc_Frame_t * pAbc, int argc, char ** argv )
30688 {
30689     int c;
30690     Extra_UtilGetoptReset();
30691     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
30692     {
30693         switch ( c )
30694         {
30695         case 'h':
30696             goto usage;
30697         default:
30698             goto usage;
30699         }
30700     }
30701     // restore from best
30702     if ( pAbc->pGiaBest2 == NULL )
30703     {
30704         Abc_Print( -1, "Abc_CommandAbc9Load2(): There is no best design saved.\n" );
30705         return 1;
30706     }
30707     Gia_ManStopP( &pAbc->pGia );
30708     pAbc->pGia = pAbc->pGiaBest2;
30709     pAbc->pGiaBest2 = NULL;
30710     pAbc->nBestLuts2 = 0;
30711     pAbc->nBestEdges2 = 0;
30712     pAbc->nBestLevels2 = 0;
30713     return 0;
30714 
30715 usage:
30716     Abc_Print( -2, "usage: &load2 [-h]\n" );
30717     Abc_Print( -2, "\t        loads AIG with mapping previously saved by &save2\n" );
30718     Abc_Print( -2, "\t        (after loading the previously saved AIG cannot be loaded again)\n" );
30719     Abc_Print( -2, "\t-h    : print the command usage\n");
30720     return 1;
30721 }
30722 
30723 /**Function*************************************************************
30724 
30725   Synopsis    []
30726 
30727   Description []
30728 
30729   SideEffects []
30730 
30731   SeeAlso     []
30732 
30733 ***********************************************************************/
Abc_CommandAbc9LoadAig(Abc_Frame_t * pAbc,int argc,char ** argv)30734 int Abc_CommandAbc9LoadAig( Abc_Frame_t * pAbc, int argc, char ** argv )
30735 {
30736     int c;
30737     Extra_UtilGetoptReset();
30738     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
30739     {
30740         switch ( c )
30741         {
30742         case 'h':
30743             goto usage;
30744         default:
30745             goto usage;
30746         }
30747     }
30748     // restore from best
30749     if ( pAbc->pGiaSaved == NULL )
30750     {
30751         Abc_Print( -1, "Abc_CommandAbc9LoadAig(): There is no design saved.\n" );
30752         return 1;
30753     }
30754     Gia_ManStopP( &pAbc->pGia );
30755     pAbc->pGia = Gia_ManDupWithAttributes( pAbc->pGiaSaved );
30756     return 0;
30757 
30758 usage:
30759     Abc_Print( -2, "usage: &loadaig [-h]\n" );
30760     Abc_Print( -2, "\t        loads AIG previously saved by &saveaig\n" );
30761     Abc_Print( -2, "\t-h    : print the command usage\n");
30762     return 1;
30763 }
30764 
30765 /**Function*************************************************************
30766 
30767   Synopsis    []
30768 
30769   Description []
30770 
30771   SideEffects []
30772 
30773   SeeAlso     []
30774 
30775 ***********************************************************************/
Abc_CommandAbc9WriteVer(Abc_Frame_t * pAbc,int argc,char ** argv)30776 int Abc_CommandAbc9WriteVer( Abc_Frame_t * pAbc, int argc, char ** argv )
30777 {
30778     char * pFileSpec = NULL;
30779     Abc_Ntk_t * pNtkSpec = NULL;
30780     char * pFileName;
30781     char ** pArgvNew;
30782     int c, nArgcNew;
30783     int fVerbose = 0;
30784     Extra_UtilGetoptReset();
30785     while ( ( c = Extra_UtilGetopt( argc, argv, "Svh" ) ) != EOF )
30786     {
30787         switch ( c )
30788         {
30789         case 'S':
30790             if ( globalUtilOptind >= argc )
30791             {
30792                 Abc_Print( -1, "Command line switch \"-S\" should be followed by a file name.\n" );
30793                 goto usage;
30794             }
30795             pFileSpec = argv[globalUtilOptind];
30796             globalUtilOptind++;
30797             break;
30798         case 'v':
30799             fVerbose ^= 1;
30800             break;
30801         case 'h':
30802             goto usage;
30803         default:
30804             goto usage;
30805         }
30806     }
30807     pArgvNew = argv + globalUtilOptind;
30808     nArgcNew = argc - globalUtilOptind;
30809     if ( nArgcNew != 1 )
30810     {
30811         Abc_Print( -1, "Expecting output file name on the command line.\n" );
30812         return 1;
30813     }
30814     pFileName = argv[globalUtilOptind];
30815     if ( pAbc->pNtkCur == NULL )
30816     {
30817         Abc_Print( -1, "There is no mapped file to write.\n" );
30818         return 1;
30819     }
30820     if ( pFileSpec == NULL )
30821     {
30822         Abc_Print( -1, "The specification file is not given.\n" );
30823         return 1;
30824     }
30825     pNtkSpec = Io_ReadNetlist( pFileSpec, Io_ReadFileType(pFileSpec), 0 );
30826     if ( pNtkSpec == NULL )
30827     {
30828         Abc_Print( -1, "Reading hierarchical Verilog for the specification has failed.\n" );
30829         return 1;
30830     }
30831     Abc_NtkInsertHierarchyGia( pNtkSpec, pAbc->pNtkCur, fVerbose );
30832     Io_WriteVerilog( pNtkSpec, pFileName, 0 );
30833     Abc_NtkDelete( pNtkSpec );
30834     return 0;
30835 
30836 usage:
30837     Abc_Print( -2, "usage: &write_ver [-S <file>] [-vh] <file>\n" );
30838     Abc_Print( -2, "\t          writes hierarchical Verilog after mapping\n" );
30839     Abc_Print( -2, "\t-S file : file name for the original hierarchical design (required)\n" );
30840     Abc_Print( -2, "\t-v      : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
30841     Abc_Print( -2, "\t-h      : print the command usage\n");
30842     Abc_Print( -2, "\t<file>  : the file name\n");
30843     return 1;
30844 }
30845 
30846 /**Function*************************************************************
30847 
30848   Synopsis    []
30849 
30850   Description []
30851 
30852   SideEffects []
30853 
30854   SeeAlso     []
30855 
30856 ***********************************************************************/
Abc_CommandAbc9Write(Abc_Frame_t * pAbc,int argc,char ** argv)30857 int Abc_CommandAbc9Write( Abc_Frame_t * pAbc, int argc, char ** argv )
30858 {
30859     char * pFileName;
30860     char ** pArgvNew;
30861     int c, nArgcNew;
30862     int fUnique = 0;
30863     int fVerilog = 0;
30864     int fMiniAig = 0;
30865     int fMiniLut = 0;
30866     int fWriteNewLine = 0;
30867     int fVerbose = 0;
30868     Extra_UtilGetoptReset();
30869     while ( ( c = Extra_UtilGetopt( argc, argv, "upmlnvh" ) ) != EOF )
30870     {
30871         switch ( c )
30872         {
30873         case 'u':
30874             fUnique ^= 1;
30875             break;
30876         case 'p':
30877             fVerilog ^= 1;
30878             break;
30879         case 'm':
30880             fMiniAig ^= 1;
30881             break;
30882         case 'l':
30883             fMiniLut ^= 1;
30884             break;
30885         case 'n':
30886             fWriteNewLine ^= 1;
30887             break;
30888         case 'v':
30889             fVerbose ^= 1;
30890             break;
30891         case 'h':
30892             goto usage;
30893         default:
30894             goto usage;
30895         }
30896     }
30897     pArgvNew = argv + globalUtilOptind;
30898     nArgcNew = argc - globalUtilOptind;
30899     if ( nArgcNew != 1 )
30900     {
30901         Abc_Print( -1, "There is no file name.\n" );
30902         return 1;
30903     }
30904     if ( pAbc->pGia == NULL )
30905     {
30906         Abc_Print( -1, "Abc_CommandAbc9Write(): There is no AIG to write.\n" );
30907         return 1;
30908     }
30909     pFileName = argv[globalUtilOptind];
30910     if ( fUnique )
30911     {
30912         Gia_Man_t * pGia = Gia_ManIsoCanonicize( pAbc->pGia, fVerbose );
30913         Gia_AigerWriteSimple( pGia, pFileName );
30914         Gia_ManStop( pGia );
30915     }
30916     else if ( fVerilog )
30917         Gia_ManDumpVerilog( pAbc->pGia, pFileName, NULL );
30918     else if ( fMiniAig )
30919         Gia_ManWriteMiniAig( pAbc->pGia, pFileName );
30920     else if ( fMiniLut )
30921         Gia_ManWriteMiniLut( pAbc->pGia, pFileName );
30922     else
30923         Gia_AigerWrite( pAbc->pGia, pFileName, 0, 0, fWriteNewLine );
30924     return 0;
30925 
30926 usage:
30927     Abc_Print( -2, "usage: &w [-upmlnvh] <file>\n" );
30928     Abc_Print( -2, "\t         writes the current AIG into the AIGER file\n" );
30929     Abc_Print( -2, "\t-u     : toggle writing canonical AIG structure [default = %s]\n", fUnique? "yes" : "no" );
30930     Abc_Print( -2, "\t-p     : toggle writing Verilog with 'and' and 'not' [default = %s]\n", fVerilog? "yes" : "no" );
30931     Abc_Print( -2, "\t-m     : toggle writing MiniAIG rather than AIGER [default = %s]\n", fMiniAig? "yes" : "no" );
30932     Abc_Print( -2, "\t-l     : toggle writing MiniLUT rather than AIGER [default = %s]\n", fMiniLut? "yes" : "no" );
30933     Abc_Print( -2, "\t-n     : toggle writing \'\\n\' after \'c\' in the AIGER file [default = %s]\n", fWriteNewLine? "yes": "no" );
30934     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
30935     Abc_Print( -2, "\t-h     : print the command usage\n");
30936     Abc_Print( -2, "\t<file> : the file name\n");
30937     return 1;
30938 }
30939 
30940 /**Function*************************************************************
30941 
30942   Synopsis    []
30943 
30944   Description []
30945 
30946   SideEffects []
30947 
30948   SeeAlso     []
30949 
30950 ***********************************************************************/
Abc_CommandAbc9WriteLut(Abc_Frame_t * pAbc,int argc,char ** argv)30951 int Abc_CommandAbc9WriteLut( Abc_Frame_t * pAbc, int argc, char ** argv )
30952 {
30953     extern void Gia_AigerWriteLut( Gia_Man_t * pGia, char * pFileName );
30954     char * pFileName;
30955     char ** pArgvNew;
30956     int c, nArgcNew;
30957     int fVerbose = 0;
30958     Extra_UtilGetoptReset();
30959     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
30960     {
30961         switch ( c )
30962         {
30963         case 'v':
30964             fVerbose ^= 1;
30965             break;
30966         case 'h':
30967             goto usage;
30968         default:
30969             goto usage;
30970         }
30971     }
30972     pArgvNew = argv + globalUtilOptind;
30973     nArgcNew = argc - globalUtilOptind;
30974     if ( nArgcNew != 1 )
30975     {
30976         Abc_Print( -1, "There is no file name.\n" );
30977         return 1;
30978     }
30979     pFileName = argv[globalUtilOptind];
30980     if ( pAbc->pGia == NULL )
30981     {
30982         Abc_Print( -1, "Abc_CommandAbc9WriteLut(): There is no AIG to write.\n" );
30983         return 1;
30984     }
30985     if ( !Gia_ManHasMapping(pAbc->pGia) )
30986     {
30987         Abc_Print( -1, "Abc_CommandAbc9WriteLut(): AIG has no mapping.\n" );
30988         return 1;
30989     }
30990     Gia_AigerWriteLut( pAbc->pGia, pFileName );
30991     return 0;
30992 
30993 usage:
30994     Abc_Print( -2, "usage: &wlut [-umvh] <file>\n" );
30995     Abc_Print( -2, "\t         writes the the current LUT mapping into a binary file\n" );
30996     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
30997     Abc_Print( -2, "\t-h     : print the command usage\n");
30998     Abc_Print( -2, "\t<file> : the file name\n");
30999     return 1;
31000 }
31001 
31002 /**Function*************************************************************
31003 
31004   Synopsis    []
31005 
31006   Description []
31007 
31008   SideEffects []
31009 
31010   SeeAlso     []
31011 
31012 ***********************************************************************/
Abc_CommandAbc9Ps(Abc_Frame_t * pAbc,int argc,char ** argv)31013 int Abc_CommandAbc9Ps( Abc_Frame_t * pAbc, int argc, char ** argv )
31014 {
31015     Gps_Par_t Pars, * pPars = &Pars;
31016     int c, fBest = 0;
31017     memset( pPars, 0, sizeof(Gps_Par_t) );
31018     Extra_UtilGetoptReset();
31019     while ( ( c = Extra_UtilGetopt( argc, argv, "Dtpcnlmaszxbh" ) ) != EOF )
31020     {
31021         switch ( c )
31022         {
31023         case 't':
31024             pPars->fTents ^= 1;
31025             break;
31026         case 'p':
31027             pPars->fSwitch ^= 1;
31028             break;
31029         case 'c':
31030             pPars->fCut ^= 1;
31031             break;
31032         case 'n':
31033             pPars->fNpn ^= 1;
31034             break;
31035         case 'l':
31036             pPars->fLutProf ^= 1;
31037             break;
31038         case 'm':
31039             pPars->fMuxXor ^= 1;
31040             break;
31041         case 'a':
31042             pPars->fMiter ^= 1;
31043             break;
31044         case 's':
31045             pPars->fSlacks ^= 1;
31046             break;
31047         case 'z':
31048             pPars->fSkipMap ^= 1;
31049             break;
31050         case 'x':
31051             pPars->fNoColor ^= 1;
31052             break;
31053         case 'D':
31054             if ( globalUtilOptind >= argc )
31055             {
31056                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a file name.\n" );
31057                 goto usage;
31058             }
31059             pPars->pDumpFile = argv[globalUtilOptind];
31060             globalUtilOptind++;
31061             break;
31062         case 'b':
31063             fBest ^= 1;
31064             break;
31065         case 'h':
31066             goto usage;
31067         default:
31068             goto usage;
31069         }
31070     }
31071     if ( fBest )
31072     {
31073         if ( pAbc->pGiaBest == NULL )
31074         {
31075             Abc_Print( -1, "Abc_CommandAbc9Ps(): There is no AIG.\n" );
31076             return 1;
31077         }
31078         Gia_ManPrintStats( pAbc->pGiaBest, pPars );
31079     }
31080     else
31081     {
31082         if ( pAbc->pGia == NULL )
31083         {
31084             Abc_Print( -1, "Abc_CommandAbc9Ps(): There is no AIG.\n" );
31085             return 1;
31086         }
31087         Gia_ManPrintStats( pAbc->pGia, pPars );
31088     }
31089     return 0;
31090 
31091 usage:
31092     Abc_Print( -2, "usage: &ps [-tpcnlmaszxbh] [-D file]\n" );
31093     Abc_Print( -2, "\t          prints stats of the current AIG\n" );
31094     Abc_Print( -2, "\t-t      : toggle printing BMC tents [default = %s]\n",                pPars->fTents? "yes": "no" );
31095     Abc_Print( -2, "\t-p      : toggle printing switching activity [default = %s]\n",       pPars->fSwitch? "yes": "no" );
31096     Abc_Print( -2, "\t-c      : toggle printing the size of frontier cut [default = %s]\n", pPars->fCut? "yes": "no" );
31097     Abc_Print( -2, "\t-n      : toggle printing NPN classes of functions [default = %s]\n", pPars->fNpn? "yes": "no" );
31098     Abc_Print( -2, "\t-l      : toggle printing LUT size profile [default = %s]\n",         pPars->fLutProf? "yes": "no" );
31099     Abc_Print( -2, "\t-m      : toggle printing MUX/XOR statistics [default = %s]\n",       pPars->fMuxXor? "yes": "no" );
31100     Abc_Print( -2, "\t-a      : toggle printing miter statistics [default = %s]\n",         pPars->fMiter? "yes": "no" );
31101     Abc_Print( -2, "\t-s      : toggle printing slack distribution [default = %s]\n",       pPars->fSlacks? "yes": "no" );
31102     Abc_Print( -2, "\t-z      : skip mapping statistics even if mapped [default = %s]\n",   pPars->fSkipMap? "yes": "no" );
31103     Abc_Print( -2, "\t-n      : toggle using no color in the printout [default = %s]\n",    pPars->fNoColor? "yes": "no" );
31104     Abc_Print( -2, "\t-x      : toggle printing saved AIG statistics [default = %s]\n",     fBest? "yes": "no" );
31105     Abc_Print( -2, "\t-D file : file name to dump statistics [default = none]\n" );
31106     Abc_Print( -2, "\t-h      : print the command usage\n");
31107     return 1;
31108 }
31109 
31110 /**Function*************************************************************
31111 
31112   Synopsis    []
31113 
31114   Description []
31115 
31116   SideEffects []
31117 
31118   SeeAlso     []
31119 
31120 ***********************************************************************/
Abc_CommandAbc9PFan(Abc_Frame_t * pAbc,int argc,char ** argv)31121 int Abc_CommandAbc9PFan( Abc_Frame_t * pAbc, int argc, char ** argv )
31122 {
31123     int c;
31124     int nNodes = 0;
31125     Extra_UtilGetoptReset();
31126     while ( ( c = Extra_UtilGetopt( argc, argv, "Nh" ) ) != EOF )
31127     {
31128         switch ( c )
31129         {
31130         case 'N':
31131             if ( globalUtilOptind >= argc )
31132             {
31133                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
31134                 goto usage;
31135             }
31136             nNodes = atoi(argv[globalUtilOptind]);
31137             globalUtilOptind++;
31138             if ( nNodes < 0 )
31139                 goto usage;
31140             break;
31141         case 'h':
31142             goto usage;
31143         default:
31144             goto usage;
31145         }
31146     }
31147     if ( pAbc->pGia == NULL )
31148     {
31149         Abc_Print( -1, "Abc_CommandAbc9PFan(): There is no AIG.\n" );
31150         return 1;
31151     }
31152     Gia_ManPrintFanio( pAbc->pGia, nNodes );
31153     return 0;
31154 
31155 usage:
31156     Abc_Print( -2, "usage: &pfan [-N num] [-h]\n" );
31157     Abc_Print( -2, "\t         prints fanin/fanout statistics\n" );
31158     Abc_Print( -2, "\t-N num : the number of high-fanout nodes to explore [default = %d]\n", nNodes );
31159     Abc_Print( -2, "\t-h     : print the command usage\n");
31160     return 1;
31161 }
31162 
31163 /**Function*************************************************************
31164 
31165   Synopsis    []
31166 
31167   Description []
31168 
31169   SideEffects []
31170 
31171   SeeAlso     []
31172 
31173 ***********************************************************************/
Abc_CommandAbc9PSig(Abc_Frame_t * pAbc,int argc,char ** argv)31174 int Abc_CommandAbc9PSig( Abc_Frame_t * pAbc, int argc, char ** argv )
31175 {
31176     int c;
31177     int fSetReset = 1;
31178     Extra_UtilGetoptReset();
31179     while ( ( c = Extra_UtilGetopt( argc, argv, "rh" ) ) != EOF )
31180     {
31181         switch ( c )
31182         {
31183         case 'r':
31184             fSetReset ^= 1;
31185             break;
31186         case 'h':
31187             goto usage;
31188         default:
31189             goto usage;
31190         }
31191     }
31192     if ( pAbc->pGia == NULL )
31193     {
31194         Abc_Print( -1, "Abc_CommandAbc9PSigs(): There is no AIG.\n" );
31195         return 1;
31196     }
31197     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
31198     {
31199         Abc_Print( -1, "Abc_CommandAbc9PSigs(): Works only for sequential circuits.\n" );
31200         return 1;
31201     }
31202     Gia_ManDetectSeqSignals( pAbc->pGia, fSetReset, 1 );
31203     return 0;
31204 
31205 usage:
31206     Abc_Print( -2, "usage: &psig [-rh]\n" );
31207     Abc_Print( -2, "\t         prints enable/set/reset statistics\n" );
31208     Abc_Print( -2, "\t-r     : toggle printing set/reset signals [default = %s]\n", fSetReset? "yes": "no" );
31209     Abc_Print( -2, "\t-h     : print the command usage\n");
31210     return 1;
31211 }
31212 
31213 /**Function*************************************************************
31214 
31215   Synopsis    []
31216 
31217   Description []
31218 
31219   SideEffects []
31220 
31221   SeeAlso     []
31222 
31223 ***********************************************************************/
Abc_CommandAbc9Status(Abc_Frame_t * pAbc,int argc,char ** argv)31224 int Abc_CommandAbc9Status( Abc_Frame_t * pAbc, int argc, char ** argv )
31225 {
31226     int c;
31227     Extra_UtilGetoptReset();
31228     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
31229     {
31230         switch ( c )
31231         {
31232         case 'h':
31233             goto usage;
31234         default:
31235             goto usage;
31236         }
31237     }
31238     if ( pAbc->pGia == NULL )
31239     {
31240         Abc_Print( -1, "Abc_CommandAbc9Status(): There is no AIG.\n" );
31241         return 1;
31242     }
31243     Gia_ManPrintMiterStatus( pAbc->pGia );
31244     return 0;
31245 
31246 usage:
31247     Abc_Print( -2, "usage: &status [-h]\n" );
31248     Abc_Print( -2, "\t         prints status of the miter\n" );
31249     Abc_Print( -2, "\t-h     : print the command usage\n");
31250     return 1;
31251 }
31252 
31253 /**Function*************************************************************
31254 
31255   Synopsis    []
31256 
31257   Description []
31258 
31259   SideEffects []
31260 
31261   SeeAlso     []
31262 
31263 ***********************************************************************/
Abc_CommandAbc9MuxProfile(Abc_Frame_t * pAbc,int argc,char ** argv)31264 int Abc_CommandAbc9MuxProfile( Abc_Frame_t * pAbc, int argc, char ** argv )
31265 {
31266     extern void Gia_ManMuxProfiling( Gia_Man_t * p );
31267     extern void Gia_ManProfileStructures( Gia_Man_t * p, int nLimit, int fVerbose );
31268     extern void Acec_StatsCollect( Gia_Man_t * p, int fVerbose );
31269     extern void Acec_ManProfile( Gia_Man_t * p, int fVerbose );
31270     int c, fNpn = 0, fMuxes = 0, fAdders = 0, nLimit = 0, fVerbose = 0;
31271     Extra_UtilGetoptReset();
31272     while ( ( c = Extra_UtilGetopt( argc, argv, "Nnmavh" ) ) != EOF )
31273     {
31274         switch ( c )
31275         {
31276         case 'N':
31277             if ( globalUtilOptind >= argc )
31278             {
31279                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
31280                 goto usage;
31281             }
31282             nLimit = atoi(argv[globalUtilOptind]);
31283             globalUtilOptind++;
31284             if ( nLimit < 0 )
31285                 goto usage;
31286             break;
31287         case 'n':
31288             fNpn ^= 1;
31289             break;
31290         case 'm':
31291             fMuxes ^= 1;
31292             break;
31293         case 'a':
31294             fAdders ^= 1;
31295             break;
31296         case 'v':
31297             fVerbose ^= 1;
31298             break;
31299         case 'h':
31300             goto usage;
31301         default:
31302             goto usage;
31303         }
31304     }
31305     if ( pAbc->pGia == NULL )
31306     {
31307         Abc_Print( -1, "Abc_CommandAbc9MuxProfile(): There is no AIG.\n" );
31308         return 1;
31309     }
31310     if ( fNpn )
31311     {
31312         if ( !Gia_ManHasMapping(pAbc->pGia) || Gia_ManLutSizeMax(pAbc->pGia) >= 4 )
31313         {
31314             Abc_Print( -1, "Abc_CommandAbc9MuxProfile(): Expecting AIG mapped into 3-LUTs.\n" );
31315             return 1;
31316         }
31317         Acec_StatsCollect( pAbc->pGia, fVerbose );
31318     }
31319     else if ( fMuxes )
31320         Gia_ManMuxProfiling( pAbc->pGia );
31321     else if ( fAdders )
31322         Acec_ManProfile( pAbc->pGia, fVerbose );
31323     else
31324         Gia_ManProfileStructures( pAbc->pGia, nLimit, fVerbose );
31325     return 0;
31326 
31327 usage:
31328     Abc_Print( -2, "usage: &profile [-N num] [-nmavh]\n" );
31329     Abc_Print( -2, "\t         profile gate structures appearing in the AIG\n" );
31330     Abc_Print( -2, "\t-N num : limit on class size to show [default = %d]\n", nLimit );
31331     Abc_Print( -2, "\t-n     : toggle profiling NPN-classes (for 3-LUT mapped AIGs) [default = %s]\n", fNpn? "yes": "no" );
31332     Abc_Print( -2, "\t-m     : toggle profiling MUX structures [default = %s]\n", fMuxes? "yes": "no" );
31333     Abc_Print( -2, "\t-a     : toggle profiling adder structures [default = %s]\n", fAdders? "yes": "no" );
31334     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
31335     Abc_Print( -2, "\t-h     : print the command usage\n");
31336     return 1;
31337 }
31338 
31339 /**Function*************************************************************
31340 
31341   Synopsis    []
31342 
31343   Description []
31344 
31345   SideEffects []
31346 
31347   SeeAlso     []
31348 
31349 ***********************************************************************/
Abc_CommandAbc9MuxPos(Abc_Frame_t * pAbc,int argc,char ** argv)31350 int Abc_CommandAbc9MuxPos( Abc_Frame_t * pAbc, int argc, char ** argv )
31351 {
31352     extern Gia_Man_t * Gia_ManDupWithMuxPos( Gia_Man_t * p );
31353     Gia_Man_t * pGia;
31354     int c, fVerbose = 0;
31355     Extra_UtilGetoptReset();
31356     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
31357     {
31358         switch ( c )
31359         {
31360         case 'v':
31361             fVerbose ^= 1;
31362             break;
31363         case 'h':
31364             goto usage;
31365         default:
31366             goto usage;
31367         }
31368     }
31369     if ( pAbc->pGia == NULL )
31370     {
31371         Abc_Print( -1, "Abc_CommandAbc9MuxPos(): There is no AIG.\n" );
31372         return 1;
31373     }
31374     pGia = Gia_ManDupWithMuxPos( pAbc->pGia );
31375     Abc_FrameUpdateGia( pAbc, pGia );
31376     return 0;
31377 
31378 usage:
31379     Abc_Print( -2, "usage: &muxpos [-vh]\n" );
31380     Abc_Print( -2, "\t         create additional POs to preserve MUXes\n" );
31381     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
31382     Abc_Print( -2, "\t-h     : print the command usage\n");
31383     return 1;
31384 }
31385 
31386 
31387 /**Function*************************************************************
31388 
31389   Synopsis    []
31390 
31391   Description []
31392 
31393   SideEffects []
31394 
31395   SeeAlso     []
31396 
31397 ***********************************************************************/
Abc_CommandAbc9PrintTruth(Abc_Frame_t * pAbc,int argc,char ** argv)31398 int Abc_CommandAbc9PrintTruth( Abc_Frame_t * pAbc, int argc, char ** argv )
31399 {
31400     extern word Gia_LutComputeTruth6Simple( Gia_Man_t * p, int iPo );
31401     int i, c, iOutNum = 0, nOutRange = -1, fVerbose = 0; word Truth;
31402     Extra_UtilGetoptReset();
31403     while ( ( c = Extra_UtilGetopt( argc, argv, "ORvh" ) ) != EOF )
31404     {
31405         switch ( c )
31406         {
31407         case 'O':
31408             if ( globalUtilOptind >= argc )
31409             {
31410                 Abc_Print( -1, "Command line switch \"-O\" should be followed by an integer.\n" );
31411                 goto usage;
31412             }
31413             iOutNum = atoi(argv[globalUtilOptind]);
31414             globalUtilOptind++;
31415             if ( iOutNum < 0 )
31416                 goto usage;
31417             break;
31418         case 'R':
31419             if ( globalUtilOptind >= argc )
31420             {
31421                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
31422                 goto usage;
31423             }
31424             nOutRange = atoi(argv[globalUtilOptind]);
31425             globalUtilOptind++;
31426             if ( nOutRange < 0 )
31427                 goto usage;
31428             break;
31429         case 'v':
31430             fVerbose ^= 1;
31431             break;
31432         case 'h':
31433             goto usage;
31434         default:
31435             goto usage;
31436         }
31437     }
31438     if ( pAbc->pGia == NULL )
31439     {
31440         Abc_Print( -1, "Abc_CommandAbc9PrintTruth(): There is no AIG.\n" );
31441         return 1;
31442     }
31443     if ( Gia_ManPiNum(pAbc->pGia) > 6 )
31444     {
31445         Abc_Print( -1, "The number of inputs of the AIG exceeds 6.\n" );
31446         return 1;
31447     }
31448     if ( iOutNum < 0 || iOutNum + nOutRange > Gia_ManPoNum(pAbc->pGia) )
31449     {
31450         Abc_Print( -1, "Abc_CommandAbc9PrintTruth(): Range of outputs to extract is incorrect.\n" );
31451         return 1;
31452     }
31453     if ( nOutRange == -1 )
31454         nOutRange = Gia_ManCoNum(pAbc->pGia);
31455     for ( i = iOutNum; i < iOutNum + nOutRange; i++ )
31456     {
31457         Truth = Gia_LutComputeTruth6Simple( pAbc->pGia, i );
31458         printf( "Output %8d : ", i );
31459         Extra_PrintHex( stdout, (unsigned *)&Truth, Gia_ManCiNum(pAbc->pGia) );
31460         printf( "\n" );
31461     }
31462     return 0;
31463 
31464 usage:
31465     Abc_Print( -2, "usage: &print_truth [-OR num] [-vh]\n" );
31466     Abc_Print( -2, "\t         prints truth tables of outputs in hex notation\n" );
31467     Abc_Print( -2, "\t-O num : the index of first PO to print [default = %d]\n", iOutNum );
31468     Abc_Print( -2, "\t-R num : (optional) the number of outputs to extract [default = all]\n" );
31469     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
31470     Abc_Print( -2, "\t-h     : print the command usage\n");
31471     return 1;
31472 }
31473 
31474 /**Function*************************************************************
31475 
31476   Synopsis    []
31477 
31478   Description []
31479 
31480   SideEffects []
31481 
31482   SeeAlso     []
31483 
31484 ***********************************************************************/
Abc_CommandAbc9Unate(Abc_Frame_t * pAbc,int argc,char ** argv)31485 int Abc_CommandAbc9Unate( Abc_Frame_t * pAbc, int argc, char ** argv )
31486 {
31487     extern void Gia_ManCheckUnateTest( Gia_Man_t * p, int fComputeAll, int fVerbose );
31488     int c, fComputeAll = 0, fVerbose = 0;
31489     Extra_UtilGetoptReset();
31490     while ( ( c = Extra_UtilGetopt( argc, argv, "avh" ) ) != EOF )
31491     {
31492         switch ( c )
31493         {
31494         case 'a':
31495             fComputeAll ^= 1;
31496             break;
31497         case 'v':
31498             fVerbose ^= 1;
31499             break;
31500         case 'h':
31501             goto usage;
31502         default:
31503             goto usage;
31504         }
31505     }
31506     if ( pAbc->pGia == NULL )
31507     {
31508         Abc_Print( -1, "Abc_CommandAbc9Unate(): There is no AIG.\n" );
31509         return 1;
31510     }
31511     Gia_ManCheckUnateTest( pAbc->pGia, fComputeAll, fVerbose );
31512     return 0;
31513 
31514 usage:
31515     Abc_Print( -2, "usage: &unate [-avh]\n" );
31516     Abc_Print( -2, "\t         prints info about unatements of CO funcs in terms of CI vars\n" );
31517     Abc_Print( -2, "\t-a     : toggle using efficient computation for all pairs [default = %s]\n", fComputeAll? "yes": "no" );
31518     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
31519     Abc_Print( -2, "\t-h     : print the command usage\n");
31520     return 1;
31521 }
31522 
31523 /**Function*************************************************************
31524 
31525   Synopsis    []
31526 
31527   Description []
31528 
31529   SideEffects []
31530 
31531   SeeAlso     []
31532 
31533 ***********************************************************************/
Abc_CommandAbc9Rex2Gia(Abc_Frame_t * pAbc,int argc,char ** argv)31534 int Abc_CommandAbc9Rex2Gia( Abc_Frame_t * pAbc, int argc, char ** argv )
31535 {
31536     extern Gia_Man_t * Gia_ManRex2Gia( char * pStr, int fOrder, int fVerbose );
31537     Gia_Man_t * pGia = NULL;
31538     char * pStr = NULL;
31539     char ** pArgvNew;
31540     int nArgcNew;
31541     int c, fOrder = 1, fVerbose = 0;
31542     Extra_UtilGetoptReset();
31543     while ( ( c = Extra_UtilGetopt( argc, argv, "avh" ) ) != EOF )
31544     {
31545         switch ( c )
31546         {
31547         case 'a':
31548             fOrder ^= 1;
31549             break;
31550         case 'v':
31551             fVerbose ^= 1;
31552             break;
31553         case 'h':
31554             goto usage;
31555         default:
31556             goto usage;
31557         }
31558     }
31559     pArgvNew = argv + globalUtilOptind;
31560     nArgcNew = argc - globalUtilOptind;
31561     if ( nArgcNew != 1 )
31562     {
31563         Abc_Print( -1, "No regular expression is entered on the command line.\n" );
31564         return 1;
31565     }
31566     pStr = pArgvNew[0];
31567     pGia = Gia_ManRex2Gia( pStr, fOrder, fVerbose );
31568     if ( pGia )
31569         Abc_FrameUpdateGia( pAbc, pGia );
31570     return 0;
31571 
31572 usage:
31573     Abc_Print( -2, "usage: &rex2gia [-avh] [string]\n" );
31574     Abc_Print( -2, "\t         converts a regular expression into a sequential AIG\n" );
31575     Abc_Print( -2, "\t-a     : toggle ordering input symbols alphabetically [default = %s]\n", fOrder? "yes": "no" );
31576     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
31577     Abc_Print( -2, "\t-h     : print the command usage\n");
31578     Abc_Print( -2, "\tstring : representation of a regular expression\n");
31579     Abc_Print( -2, "\t         Special symbols: parentheses \'(\' and \')\', Kleene closure \'*\', union \'|'\n");
31580     Abc_Print( -2, "\t         All other characters are treated as symbols of the input alphabet.\n");
31581     Abc_Print( -2, "\t         For example, ((A*B|AC)D) is defined over the alphabet {A, B, C, D}\n");
31582     Abc_Print( -2, "\t         and generates the following language: {BD, ABD, AABD, AAABD, ..., ACD}\n");
31583     Abc_Print( -2, "\t         A known limitation:  For the command to work correctly, each two-input union\n");
31584     Abc_Print( -2, "\t         should have a dedicated pair of parentheses: ((A|B)|C) rather than (A|B|C)\n");
31585     return 1;
31586 }
31587 
31588 /**Function*************************************************************
31589 
31590   Synopsis    []
31591 
31592   Description []
31593 
31594   SideEffects []
31595 
31596   SeeAlso     []
31597 
31598 ***********************************************************************/
Abc_CommandAbc9RexWalk(Abc_Frame_t * pAbc,int argc,char ** argv)31599 int Abc_CommandAbc9RexWalk( Abc_Frame_t * pAbc, int argc, char ** argv )
31600 {
31601     extern void Gia_ManAutomWalk( Gia_Man_t * p, int nSteps, int nWalks, int fVerbose );
31602     int c, nSteps = 50, nWalks = 5, fVerbose = 0;
31603     Extra_UtilGetoptReset();
31604     while ( ( c = Extra_UtilGetopt( argc, argv, "SRvh" ) ) != EOF )
31605     {
31606         switch ( c )
31607         {
31608         case 'S':
31609             if ( globalUtilOptind >= argc )
31610             {
31611                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
31612                 goto usage;
31613             }
31614             nSteps = atoi(argv[globalUtilOptind]);
31615             globalUtilOptind++;
31616             if ( nSteps < 0 )
31617                 goto usage;
31618             break;
31619         case 'R':
31620             if ( globalUtilOptind >= argc )
31621             {
31622                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
31623                 goto usage;
31624             }
31625             nWalks = atoi(argv[globalUtilOptind]);
31626             globalUtilOptind++;
31627             if ( nWalks < 0 )
31628                 goto usage;
31629             break;
31630         case 'v':
31631             fVerbose ^= 1;
31632             break;
31633         case 'h':
31634             goto usage;
31635         default:
31636             goto usage;
31637         }
31638     }
31639     if ( pAbc->pGia == NULL )
31640     {
31641         Abc_Print( -1, "Abc_CommandAbc9Show(): There is no AIG.\n" );
31642         return 1;
31643     }
31644     Gia_ManAutomWalk( pAbc->pGia, nSteps, nWalks, fVerbose );
31645     return 0;
31646 
31647 usage:
31648     Abc_Print( -2, "usage: &rexwalk [-SR] [-vh]\n" );
31649     Abc_Print( -2, "\t         performs simulation of an AIG representing a regular expression\n" );
31650     Abc_Print( -2, "\t-S num : the number of steps to take [default = %d]\n", nSteps );
31651     Abc_Print( -2, "\t-R num : the number of walks to make [default = %d]\n", nWalks );
31652     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
31653     Abc_Print( -2, "\t-h     : print the command usage\n");
31654     return 1;
31655 }
31656 
31657 /**Function*************************************************************
31658 
31659   Synopsis    []
31660 
31661   Description []
31662 
31663   SideEffects []
31664 
31665   SeeAlso     []
31666 
31667 ***********************************************************************/
Abc_CommandAbc9Show(Abc_Frame_t * pAbc,int argc,char ** argv)31668 int Abc_CommandAbc9Show( Abc_Frame_t * pAbc, int argc, char ** argv )
31669 {
31670     Vec_Int_t * vBold = NULL;
31671     int c, fAdders = 0, fFadds = 0, fPath = 0;
31672     Extra_UtilGetoptReset();
31673     while ( ( c = Extra_UtilGetopt( argc, argv, "afph" ) ) != EOF )
31674     {
31675         switch ( c )
31676         {
31677         case 'a':
31678             fAdders ^= 1;
31679             break;
31680         case 'f':
31681             fFadds ^= 1;
31682             break;
31683         case 'p':
31684             fPath ^= 1;
31685             break;
31686         case 'h':
31687             goto usage;
31688         default:
31689             goto usage;
31690         }
31691     }
31692     if ( pAbc->pGia == NULL )
31693     {
31694         Abc_Print( -1, "Abc_CommandAbc9Show(): There is no AIG.\n" );
31695         return 1;
31696     }
31697     if ( Gia_ManBufNum(pAbc->pGia) )
31698     {
31699         Abc_Print( -1, "Abc_CommandAbc9Show(): Cannot show GIA with barrier buffers.\n" );
31700         return 1;
31701     }
31702     if ( !fAdders && Gia_ManHasMapping(pAbc->pGia) )
31703     {
31704         vBold = Vec_IntAlloc( 100 );
31705         Gia_ManForEachLut( pAbc->pGia, c )
31706             Vec_IntPush( vBold, c );
31707     }
31708     Gia_ManShow( pAbc->pGia, vBold, fAdders, fFadds, fPath );
31709     Vec_IntFreeP( &vBold );
31710     return 0;
31711 
31712 usage:
31713     Abc_Print( -2, "usage: &show [-afph]\n" );
31714     Abc_Print( -2, "\t        shows the current GIA using GSView\n" );
31715     Abc_Print( -2, "\t-a    : toggle visualazing adders [default = %s]\n", fAdders? "yes": "no" );
31716     Abc_Print( -2, "\t-f    : toggle showing only full-adders with \"-a\" [default = %s]\n", fFadds? "yes": "no" );
31717     Abc_Print( -2, "\t-p    : toggle showing the critical path of a LUT mapping [default = %s]\n", fPath? "yes": "no" );
31718     Abc_Print( -2, "\t-h    : print the command usage\n");
31719     return 1;
31720 }
31721 
31722 /**Function*************************************************************
31723 
31724   Synopsis    []
31725 
31726   Description []
31727 
31728   SideEffects []
31729 
31730   SeeAlso     []
31731 
31732 ***********************************************************************/
Abc_CommandAbc9SetRegNum(Abc_Frame_t * pAbc,int argc,char ** argv)31733 int Abc_CommandAbc9SetRegNum( Abc_Frame_t * pAbc, int argc, char ** argv )
31734 {
31735     int c, nRegNum = 0;
31736     Extra_UtilGetoptReset();
31737     while ( ( c = Extra_UtilGetopt( argc, argv, "Nh" ) ) != EOF )
31738     {
31739         switch ( c )
31740         {
31741         case 'N':
31742             if ( globalUtilOptind >= argc )
31743             {
31744                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
31745                 goto usage;
31746             }
31747             nRegNum = atoi(argv[globalUtilOptind]);
31748             globalUtilOptind++;
31749             if ( nRegNum < 0 )
31750                 goto usage;
31751             break;
31752         case 'h':
31753             goto usage;
31754         default:
31755             goto usage;
31756         }
31757     }
31758     if ( pAbc->pGia == NULL )
31759     {
31760         Abc_Print( -1, "Abc_CommandAbc9SetRegNum(): There is no AIG.\n" );
31761         return 1;
31762     }
31763     if ( nRegNum >= Gia_ManCiNum(pAbc->pGia) )
31764     {
31765         Abc_Print( -1, "Abc_CommandAbc9SetRegNum(): The number of registers should be less than the number of CIs.\n" );
31766         return 1;
31767     }
31768     if ( nRegNum >= Gia_ManCoNum(pAbc->pGia) )
31769     {
31770         Abc_Print( -1, "Abc_CommandAbc9SetRegNum(): The number of registers should be less than the number of COs.\n" );
31771         return 1;
31772     }
31773     pAbc->pGia->nRegs = nRegNum;
31774     return 0;
31775 
31776 usage:
31777     Abc_Print( -2, "usage: &setregnum [-N num] [-h]\n" );
31778     Abc_Print( -2, "\t         manually sets the number of registers to combine the last PI/PO pairs\n" );
31779     Abc_Print( -2, "\t-N num : set the number of registers to be the given number [default = %d]\n", nRegNum );
31780     Abc_Print( -2, "\t-h     : print the command usage\n");
31781     return 1;
31782 }
31783 
31784 /**Function*************************************************************
31785 
31786   Synopsis    []
31787 
31788   Description []
31789 
31790   SideEffects []
31791 
31792   SeeAlso     []
31793 
31794 ***********************************************************************/
Abc_CommandAbc9Strash(Abc_Frame_t * pAbc,int argc,char ** argv)31795 int Abc_CommandAbc9Strash( Abc_Frame_t * pAbc, int argc, char ** argv )
31796 {
31797     extern Gia_Man_t * Gia_ManDupMuxRestructure( Gia_Man_t * p );
31798     Gia_Man_t * pTemp;
31799     int c, Limit = 2;
31800     int fAddStrash = 0;
31801     int fCollapse = 0;
31802     int fAddMuxes = 0;
31803     int fStrMuxes = 0;
31804     int fRehashMap = 0;
31805     Extra_UtilGetoptReset();
31806     while ( ( c = Extra_UtilGetopt( argc, argv, "Lacmrsh" ) ) != EOF )
31807     {
31808         switch ( c )
31809         {
31810         case 'L':
31811             if ( globalUtilOptind >= argc )
31812             {
31813                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
31814                 goto usage;
31815             }
31816             Limit = atoi(argv[globalUtilOptind]);
31817             globalUtilOptind++;
31818             if ( Limit < 0 )
31819                 goto usage;
31820             break;
31821         case 'a':
31822             fAddStrash ^= 1;
31823             break;
31824         case 'c':
31825             fCollapse ^= 1;
31826             break;
31827         case 'm':
31828             fAddMuxes ^= 1;
31829             break;
31830         case 'r':
31831             fRehashMap ^= 1;
31832             break;
31833         case 's':
31834             fStrMuxes ^= 1;
31835             break;
31836         case 'h':
31837             goto usage;
31838         default:
31839             goto usage;
31840         }
31841     }
31842     if ( pAbc->pGia == NULL )
31843     {
31844         Abc_Print( -1, "Abc_CommandAbc9Strash(): There is no AIG.\n" );
31845         return 1;
31846     }
31847     if ( fStrMuxes )
31848     {
31849         if ( Gia_ManHasMapping(pAbc->pGia) )
31850             Abc_Print( 0, "Restructing the current AIG destroys the LUT mapping.\n" );
31851         Vec_IntFreeP( &pAbc->pGia->vMapping );
31852         pTemp = Gia_ManDupMuxRestructure( pAbc->pGia );
31853         Abc_Print( 1, "Finished AIG restructing to enable efficient mapping of 4:1 MUXes into 4-LUTs.\n" );
31854     }
31855     else if ( Gia_ManHasMapping(pAbc->pGia) && fRehashMap )
31856     {
31857         pTemp = Gia_ManDupHashMapping( pAbc->pGia );
31858         Gia_ManTransferPacking( pTemp, pAbc->pGia );
31859         Gia_ManTransferTiming( pTemp, pAbc->pGia );
31860     }
31861     else if ( Gia_ManHasMapping(pAbc->pGia) && pAbc->pGia->vConfigs )
31862         pTemp = (Gia_Man_t *)If_ManDeriveGiaFromCells( pAbc->pGia );
31863     else if ( Gia_ManHasMapping(pAbc->pGia) )
31864         pTemp = (Gia_Man_t *)Dsm_ManDeriveGia( pAbc->pGia, fAddMuxes ); // delay-oriented unmapping
31865     else if ( fAddMuxes )
31866     {
31867         if ( pAbc->pGia->pMuxes )
31868         {
31869             Abc_Print( -1, "Abc_CommandAbc9Strash(): The AIG already has MUXes.\n" );
31870             return 1;
31871         }
31872         pTemp = Gia_ManDupMuxes( pAbc->pGia, Limit );
31873         if ( !Abc_FrameReadFlag("silentmode") )
31874             printf( "Generated AND/XOR/MUX graph.\n" );
31875     }
31876     else if ( fCollapse && pAbc->pGia->pAigExtra )
31877     {
31878         assert( !Gia_ManBufNum(pAbc->pGia) );
31879         if ( Gia_ManIsSeqWithBoxes(pAbc->pGia) || Gia_ManRegBoxNum(pAbc->pGia) )
31880         {
31881             Gia_Man_t * pUnshuffled = Gia_ManDupUnshuffleInputs( pAbc->pGia );
31882             Gia_ManTransferTiming( pUnshuffled, pAbc->pGia );
31883             pTemp = Gia_ManDupCollapse( pUnshuffled, pUnshuffled->pAigExtra, NULL, Gia_ManRegBoxNum(pUnshuffled) > 0 );
31884             Gia_ManTransferTiming( pAbc->pGia, pUnshuffled );
31885             Gia_ManStop( pUnshuffled );
31886         }
31887         else
31888             pTemp = Gia_ManDupCollapse( pAbc->pGia, pAbc->pGia->pAigExtra, NULL, 0 );
31889         if ( !Abc_FrameReadFlag("silentmode") )
31890             printf( "Collapsed AIG with boxes and logic of the boxes.\n" );
31891     }
31892     else if ( pAbc->pGia->pMuxes )
31893     {
31894         pTemp = Gia_ManDupNoMuxes( pAbc->pGia, 0 );
31895         if ( !Abc_FrameReadFlag("silentmode") )
31896             printf( "Generated AIG from AND/XOR/MUX graph.\n" );
31897     }
31898     else
31899     {
31900         pTemp = Gia_ManRehash( pAbc->pGia, fAddStrash );
31901 //        if ( !Abc_FrameReadFlag("silentmode") )
31902 //            printf( "Rehashed the current AIG.\n" );
31903     }
31904     if ( !(fCollapse && pAbc->pGia->pAigExtra) )
31905     {
31906         Gia_ManTransferTiming( pTemp, pAbc->pGia );
31907         pAbc->pGia->vConfigs = pTemp->vConfigs;     pTemp->vConfigs = NULL;
31908         pAbc->pGia->pCellStr = pTemp->pCellStr;     pTemp->pCellStr = NULL;
31909     }
31910     Abc_FrameUpdateGia( pAbc, pTemp );
31911     return 0;
31912 
31913 usage:
31914     Abc_Print( -2, "usage: &st [-L num] [-acmrsh]\n" );
31915     Abc_Print( -2, "\t         performs structural hashing\n" );
31916     Abc_Print( -2, "\t-a     : toggle additional hashing [default = %s]\n", fAddStrash? "yes": "no" );
31917     Abc_Print( -2, "\t-c     : toggle collapsing hierarchical AIG [default = %s]\n", fCollapse? "yes": "no" );
31918     Abc_Print( -2, "\t-m     : toggle converting to larger gates [default = %s]\n", fAddMuxes? "yes": "no" );
31919     Abc_Print( -2, "\t-L num : create MUX when sum of refs does not exceed this limit [default = %d]\n", Limit );
31920     Abc_Print( -2, "\t         (use L = 1 to create AIG with XORs but without MUXes)\n" );
31921     Abc_Print( -2, "\t-r     : toggle rehashing AIG while preserving mapping [default = %s]\n", fRehashMap? "yes": "no" );
31922     Abc_Print( -2, "\t-s     : toggle using MUX restructuring [default = %s]\n", fStrMuxes? "yes": "no" );
31923     Abc_Print( -2, "\t-h     : print the command usage\n");
31924     return 1;
31925 }
31926 
31927 /**Function*************************************************************
31928 
31929   Synopsis    []
31930 
31931   Description []
31932 
31933   SideEffects []
31934 
31935   SeeAlso     []
31936 
31937 ***********************************************************************/
Abc_CommandAbc9Topand(Abc_Frame_t * pAbc,int argc,char ** argv)31938 int Abc_CommandAbc9Topand( Abc_Frame_t * pAbc, int argc, char ** argv )
31939 {
31940     Gia_Man_t * pTemp;
31941     int c, fVerbose = 1;
31942     Extra_UtilGetoptReset();
31943     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
31944     {
31945         switch ( c )
31946         {
31947         case 'v':
31948             fVerbose ^= 1;
31949             break;
31950         case 'h':
31951             goto usage;
31952         default:
31953             goto usage;
31954         }
31955     }
31956     if ( pAbc->pGia == NULL )
31957     {
31958         Abc_Print( -1, "Abc_CommandAbc9Topand(): There is no AIG.\n" );
31959         return 1;
31960     }
31961     if ( Gia_ManRegNum(pAbc->pGia) > 0 )
31962     {
31963         Abc_Print( -1, "Abc_CommandAbc9Topand(): Can only be applied to a combinational miter.\n" );
31964         return 1;
31965     }
31966     pTemp = Gia_ManDupTopAnd( pAbc->pGia, fVerbose );
31967     Abc_FrameUpdateGia( pAbc, pTemp );
31968     return 0;
31969 
31970 usage:
31971     Abc_Print( -2, "usage: &topand [-vh]\n" );
31972     Abc_Print( -2, "\t        performs AND decomposition for combinational miter\n" );
31973     Abc_Print( -2, "\t-v    : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
31974     Abc_Print( -2, "\t-h    : print the command usage\n");
31975     return 1;
31976 }
31977 
31978 /**Function*************************************************************
31979 
31980   Synopsis    []
31981 
31982   Description []
31983 
31984   SideEffects []
31985 
31986   SeeAlso     []
31987 
31988 ***********************************************************************/
Abc_CommandAbc9Add1Hot(Abc_Frame_t * pAbc,int argc,char ** argv)31989 int Abc_CommandAbc9Add1Hot( Abc_Frame_t * pAbc, int argc, char ** argv )
31990 {
31991     Gia_Man_t * pTemp;
31992     int c, fVerbose = 1;
31993     Extra_UtilGetoptReset();
31994     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
31995     {
31996         switch ( c )
31997         {
31998         case 'v':
31999             fVerbose ^= 1;
32000             break;
32001         case 'h':
32002             goto usage;
32003         default:
32004             goto usage;
32005         }
32006     }
32007     if ( pAbc->pGia == NULL )
32008     {
32009         Abc_Print( -1, "Abc_CommandAbc9Add1Hot(): There is no AIG.\n" );
32010         return 1;
32011     }
32012     pTemp = Gia_ManDupOneHot( pAbc->pGia );
32013     Abc_FrameUpdateGia( pAbc, pTemp );
32014     return 0;
32015 
32016 usage:
32017     Abc_Print( -2, "usage: &add1hot [-vh]\n" );
32018     Abc_Print( -2, "\t        adds 1-hotness constraints as additional primary outputs\n" );
32019     Abc_Print( -2, "\t-v    : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
32020     Abc_Print( -2, "\t-h    : print the command usage\n");
32021     return 1;
32022 }
32023 
32024 /**Function*************************************************************
32025 
32026   Synopsis    []
32027 
32028   Description []
32029 
32030   SideEffects []
32031 
32032   SeeAlso     []
32033 
32034 ***********************************************************************/
Abc_CommandAbc9Cof(Abc_Frame_t * pAbc,int argc,char ** argv)32035 int Abc_CommandAbc9Cof( Abc_Frame_t * pAbc, int argc, char ** argv )
32036 {
32037     Gia_Man_t * pTemp;
32038     int c, fVerbose = 0;
32039     int iVar = 0, nLimFan = 0;
32040     Extra_UtilGetoptReset();
32041     while ( ( c = Extra_UtilGetopt( argc, argv, "VLvh" ) ) != EOF )
32042     {
32043         switch ( c )
32044         {
32045         case 'V':
32046             if ( globalUtilOptind >= argc )
32047             {
32048                 Abc_Print( -1, "Command line switch \"-V\" should be followed by an integer.\n" );
32049                 goto usage;
32050             }
32051             iVar = atoi(argv[globalUtilOptind]);
32052             globalUtilOptind++;
32053             if ( iVar < 0 )
32054                 goto usage;
32055             break;
32056         case 'L':
32057             if ( globalUtilOptind >= argc )
32058             {
32059                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
32060                 goto usage;
32061             }
32062             nLimFan = atoi(argv[globalUtilOptind]);
32063             globalUtilOptind++;
32064             if ( nLimFan < 0 )
32065                 goto usage;
32066             break;
32067         case 'v':
32068             fVerbose ^= 1;
32069             break;
32070         case 'h':
32071             goto usage;
32072         default:
32073             goto usage;
32074         }
32075     }
32076     if ( pAbc->pGia == NULL )
32077     {
32078         Abc_Print( -1, "Abc_CommandAbc9Cof(): There is no AIG.\n" );
32079         return 1;
32080     }
32081     if ( nLimFan )
32082     {
32083         Abc_Print( -1, "Cofactoring all variables whose fanout count is higher than %d.\n", nLimFan );
32084         pTemp = Gia_ManDupCofAll( pAbc->pGia, nLimFan, fVerbose );
32085         Abc_FrameUpdateGia( pAbc, pTemp );
32086     }
32087     else if ( iVar )
32088     {
32089         Abc_Print( -1, "Cofactoring one variable with object ID %d.\n", iVar );
32090         pTemp = Gia_ManDupCof( pAbc->pGia, iVar );
32091         Abc_FrameUpdateGia( pAbc, pTemp );
32092     }
32093     else
32094     {
32095         Abc_Print( -1, "One of the parameters, -V <num> or -L <num>, should be set on the command line.\n" );
32096         goto usage;
32097     }
32098     return 0;
32099 
32100 usage:
32101     Abc_Print( -2, "usage: &cof [-VL num] [-vh]\n" );
32102     Abc_Print( -2, "\t         performs cofactoring w.r.t. variable(s)\n" );
32103     Abc_Print( -2, "\t-V num : the zero-based ID of one variable to cofactor [default = %d]\n", iVar );
32104     Abc_Print( -2, "\t-L num : cofactor vars with fanout count higher than this [default = %d]\n", nLimFan );
32105     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
32106     Abc_Print( -2, "\t-h     : print the command usage\n");
32107     return 1;
32108 }
32109 
32110 /**Function*************************************************************
32111 
32112   Synopsis    []
32113 
32114   Description []
32115 
32116   SideEffects []
32117 
32118   SeeAlso     []
32119 
32120 ***********************************************************************/
Abc_CommandAbc9Trim(Abc_Frame_t * pAbc,int argc,char ** argv)32121 int Abc_CommandAbc9Trim( Abc_Frame_t * pAbc, int argc, char ** argv )
32122 {
32123     Gia_Man_t * pTemp, * pTemp2;
32124     int c;
32125     int OutValue = -1;
32126     int fTrimCis = 1;
32127     int fTrimCos = 1;
32128     int fDualOut = 0;
32129     int fPoFedByPi = 0;
32130     Extra_UtilGetoptReset();
32131     while ( ( c = Extra_UtilGetopt( argc, argv, "Viocdh" ) ) != EOF )
32132     {
32133         switch ( c )
32134         {
32135         case 'V':
32136             if ( globalUtilOptind >= argc )
32137             {
32138                 Abc_Print( -1, "Command line switch \"-V\" should be followed by an integer.\n" );
32139                 goto usage;
32140             }
32141             OutValue = atoi(argv[globalUtilOptind]);
32142             globalUtilOptind++;
32143             if ( OutValue < 0 )
32144                 goto usage;
32145             break;
32146         case 'i':
32147             fTrimCis ^= 1;
32148             break;
32149         case 'o':
32150             fTrimCos ^= 1;
32151             break;
32152         case 'c':
32153             fPoFedByPi ^= 1;
32154             break;
32155         case 'd':
32156             fDualOut ^= 1;
32157             break;
32158         case 'h':
32159             goto usage;
32160         default:
32161             goto usage;
32162         }
32163     }
32164     if ( pAbc->pGia == NULL )
32165     {
32166         Abc_Print( -1, "Abc_CommandAbc9Trim(): There is no AIG.\n" );
32167         return 1;
32168     }
32169     pTemp = Gia_ManDupTrimmed( pAbc->pGia, fTrimCis, fTrimCos, fDualOut, OutValue );
32170     if ( fPoFedByPi )
32171     {
32172         extern Gia_Man_t * Gia_ManDupTrimmed2( Gia_Man_t * p );
32173         pTemp = Gia_ManDupTrimmed2( pTemp2 = pTemp );
32174         Gia_ManStop( pTemp2 );
32175     }
32176     Abc_FrameUpdateGia( pAbc, pTemp );
32177     return 0;
32178 
32179 usage:
32180     Abc_Print( -2, "usage: &trim [-V num] [-iocdh]\n" );
32181     Abc_Print( -2, "\t         removes PIs without fanout and PO driven by constants\n" );
32182     Abc_Print( -2, "\t-V num : the value (0 or 1) of POs to remove [default = both]\n" );
32183     Abc_Print( -2, "\t-i     : toggle removing PIs [default = %s]\n", fTrimCis? "yes": "no" );
32184     Abc_Print( -2, "\t-o     : toggle removing POs [default = %s]\n", fTrimCos? "yes": "no" );
32185     Abc_Print( -2, "\t-c     : toggle additionally removing POs fed by PIs [default = %s]\n", fPoFedByPi? "yes": "no" );
32186     Abc_Print( -2, "\t-d     : toggle using dual-output miter [default = %s]\n", fDualOut? "yes": "no" );
32187     Abc_Print( -2, "\t-h     : print the command usage\n");
32188     return 1;
32189 }
32190 
32191 /**Function*************************************************************
32192 
32193   Synopsis    []
32194 
32195   Description []
32196 
32197   SideEffects []
32198 
32199   SeeAlso     []
32200 
32201 ***********************************************************************/
Abc_CommandAbc9Dfs(Abc_Frame_t * pAbc,int argc,char ** argv)32202 int Abc_CommandAbc9Dfs( Abc_Frame_t * pAbc, int argc, char ** argv )
32203 {
32204     Gia_Man_t * pTemp;
32205     int c;
32206     int fNormal  = 0;
32207     int fReverse = 0;
32208     int fVerbose = 0;
32209     Extra_UtilGetoptReset();
32210     while ( ( c = Extra_UtilGetopt( argc, argv, "nrvh" ) ) != EOF )
32211     {
32212         switch ( c )
32213         {
32214         case 'n':
32215             fNormal ^= 1;
32216             break;
32217         case 'r':
32218             fReverse ^= 1;
32219             break;
32220         case 'v':
32221             fVerbose ^= 1;
32222             break;
32223         case 'h':
32224             goto usage;
32225         default:
32226             goto usage;
32227         }
32228     }
32229     if ( pAbc->pGia == NULL )
32230     {
32231         Abc_Print( -1, "Abc_CommandAbc9Dfs(): There is no AIG.\n" );
32232         return 1;
32233     }
32234     if ( fNormal )
32235     {
32236         pTemp = Gia_ManDupOrderAiger( pAbc->pGia );
32237         if ( fVerbose )
32238             Abc_Print( -1, "AIG objects are reordered as follows: CIs, ANDs, COs.\n" );
32239     }
32240     else if ( fReverse )
32241     {
32242         pTemp = Gia_ManDupOrderDfsReverse( pAbc->pGia );
32243         if ( fVerbose )
32244             Abc_Print( -1, "AIG objects are reordered in the reserve DFS order.\n" );
32245     }
32246     else
32247     {
32248         pTemp = Gia_ManDupOrderDfs( pAbc->pGia );
32249         if ( fVerbose )
32250             Abc_Print( -1, "AIG objects are reordered in the DFS order.\n" );
32251     }
32252     Abc_FrameUpdateGia( pAbc, pTemp );
32253     return 0;
32254 
32255 usage:
32256     Abc_Print( -2, "usage: &dfs [-nrvh]\n" );
32257     Abc_Print( -2, "\t        orders objects in the DFS order\n" );
32258     Abc_Print( -2, "\t-n    : toggle using normalized ordering [default = %s]\n", fNormal? "yes": "no" );
32259     Abc_Print( -2, "\t-r    : toggle using reverse DFS ordering [default = %s]\n", fReverse? "yes": "no" );
32260     Abc_Print( -2, "\t-v    : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
32261     Abc_Print( -2, "\t-h    : print the command usage\n");
32262     return 1;
32263 }
32264 
32265 /**Function*************************************************************
32266 
32267   Synopsis    []
32268 
32269   Description []
32270 
32271   SideEffects []
32272 
32273   SeeAlso     []
32274 
32275 ***********************************************************************/
Abc_CommandAbc9Sim(Abc_Frame_t * pAbc,int argc,char ** argv)32276 int Abc_CommandAbc9Sim( Abc_Frame_t * pAbc, int argc, char ** argv )
32277 {
32278     Gia_ParSim_t Pars, * pPars = &Pars;
32279     char * pFileName = NULL;
32280     int c;
32281     Gia_ManSimSetDefaultParams( pPars );
32282     Extra_UtilGetoptReset();
32283     while ( ( c = Extra_UtilGetopt( argc, argv, "FWNTImvh" ) ) != EOF )
32284     {
32285         switch ( c )
32286         {
32287         case 'F':
32288             if ( globalUtilOptind >= argc )
32289             {
32290                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
32291                 goto usage;
32292             }
32293             pPars->nIters = atoi(argv[globalUtilOptind]);
32294             globalUtilOptind++;
32295             if ( pPars->nIters < 0 )
32296                 goto usage;
32297             break;
32298         case 'W':
32299             if ( globalUtilOptind >= argc )
32300             {
32301                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
32302                 goto usage;
32303             }
32304             pPars->nWords = atoi(argv[globalUtilOptind]);
32305             globalUtilOptind++;
32306             if ( pPars->nWords < 0 )
32307                 goto usage;
32308             break;
32309         case 'N':
32310             if ( globalUtilOptind >= argc )
32311             {
32312                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
32313                 goto usage;
32314             }
32315             pPars->RandSeed = atoi(argv[globalUtilOptind]);
32316             globalUtilOptind++;
32317             if ( pPars->RandSeed < 0 )
32318                 goto usage;
32319             break;
32320         case 'T':
32321             if ( globalUtilOptind >= argc )
32322             {
32323                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
32324                 goto usage;
32325             }
32326             pPars->TimeLimit = atoi(argv[globalUtilOptind]);
32327             globalUtilOptind++;
32328             if ( pPars->TimeLimit < 0 )
32329                 goto usage;
32330             break;
32331         case 'I':
32332             if ( globalUtilOptind >= argc )
32333             {
32334                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
32335                 goto usage;
32336             }
32337             pFileName = argv[globalUtilOptind];
32338             globalUtilOptind++;
32339             if ( pFileName == NULL )
32340                 goto usage;
32341             break;
32342         case 'm':
32343             pPars->fCheckMiter ^= 1;
32344             break;
32345         case 'v':
32346             pPars->fVerbose ^= 1;
32347             break;
32348         case 'h':
32349             goto usage;
32350         default:
32351             goto usage;
32352         }
32353     }
32354     if ( pAbc->pGia == NULL )
32355     {
32356         Abc_Print( -1, "Abc_CommandAbc9Sim(): There is no AIG.\n" );
32357         return 1;
32358     }
32359     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
32360     {
32361         Abc_Print( -1, "The network is combinational.\n" );
32362         return 0;
32363     }
32364     if ( pFileName != NULL )
32365     {
32366         extern void Gia_ManSimSimulatePattern( Gia_Man_t * p, char * pFileIn, char * pFileOut );
32367         char pFileNameOut[1000];
32368         char * pNameGeneric = Extra_FileNameGeneric(pFileName);
32369         assert( strlen(pNameGeneric) < 900 );
32370         sprintf( pFileNameOut, "%s_out.%s", pNameGeneric, Extra_FileNameExtension(pFileName) );
32371         ABC_FREE( pNameGeneric );
32372         Gia_ManSimSimulatePattern( pAbc->pGia, pFileName, pFileNameOut );
32373         return 1;
32374     }
32375 
32376     pAbc->nFrames = -1;
32377     if ( Gia_ManSimSimulate( pAbc->pGia, pPars ) )
32378         pAbc->Status =  0;
32379     else
32380         pAbc->Status = -1;
32381     Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexSeq );
32382 //    if ( pLogFileName )
32383 //        Abc_NtkWriteLogFile( pLogFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, "&sim" );
32384     return 0;
32385 
32386 usage:
32387     Abc_Print( -2, "usage: &sim [-FWNT num] [-mvh] -I <file>\n" );
32388     Abc_Print( -2, "\t         performs random simulation of the sequential miter\n" );
32389     Abc_Print( -2, "\t         (if candidate equivalences are defined, performs refinement)\n" );
32390     Abc_Print( -2, "\t-F num : the number of frames to simulate [default = %d]\n", pPars->nIters );
32391     Abc_Print( -2, "\t-W num : the number of words to simulate [default = %d]\n", pPars->nWords );
32392     Abc_Print( -2, "\t-N num : random number seed (1 <= num <= 1000) [default = %d]\n", pPars->RandSeed );
32393     Abc_Print( -2, "\t-T num : approximate runtime limit in seconds [default = %d]\n", pPars->TimeLimit );
32394     Abc_Print( -2, "\t-m     : toggle miter vs. any circuit [default = %s]\n", pPars->fCheckMiter? "miter": "circuit" );
32395     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
32396     Abc_Print( -2, "\t-h     : print the command usage\n");
32397     Abc_Print( -2, "\t-I file: (optional) file with input patterns (one line per frame, as many as PIs)\n");
32398     return 1;
32399 }
32400 
32401 /**Function*************************************************************
32402 
32403   Synopsis    []
32404 
32405   Description []
32406 
32407   SideEffects []
32408 
32409   SeeAlso     []
32410 
32411 ***********************************************************************/
Abc_CommandAbc9Sim3(Abc_Frame_t * pAbc,int argc,char ** argv)32412 int Abc_CommandAbc9Sim3( Abc_Frame_t * pAbc, int argc, char ** argv )
32413 {
32414     extern int Ssw_RarSimulateGia( Gia_Man_t * p, Ssw_RarPars_t * pPars );
32415     Ssw_RarPars_t Pars, * pPars = &Pars;
32416     int c;
32417     Ssw_RarSetDefaultParams( pPars );
32418     // parse command line
32419     Extra_UtilGetoptReset();
32420     while ( ( c = Extra_UtilGetopt( argc, argv, "FWBRSNTGgvh" ) ) != EOF )
32421     {
32422         switch ( c )
32423         {
32424         case 'F':
32425             if ( globalUtilOptind >= argc )
32426             {
32427                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
32428                 goto usage;
32429             }
32430             pPars->nFrames = atoi(argv[globalUtilOptind]);
32431             globalUtilOptind++;
32432             if ( pPars->nFrames < 0 )
32433                 goto usage;
32434             break;
32435         case 'W':
32436             if ( globalUtilOptind >= argc )
32437             {
32438                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
32439                 goto usage;
32440             }
32441             pPars->nWords = atoi(argv[globalUtilOptind]);
32442             globalUtilOptind++;
32443             if ( pPars->nWords < 0 )
32444                 goto usage;
32445             break;
32446         case 'B':
32447             if ( globalUtilOptind >= argc )
32448             {
32449                 Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" );
32450                 goto usage;
32451             }
32452             pPars->nBinSize = atoi(argv[globalUtilOptind]);
32453             globalUtilOptind++;
32454             if ( pPars->nBinSize < 0 )
32455                 goto usage;
32456             break;
32457         case 'R':
32458             if ( globalUtilOptind >= argc )
32459             {
32460                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
32461                 goto usage;
32462             }
32463             pPars->nRounds = atoi(argv[globalUtilOptind]);
32464             globalUtilOptind++;
32465             if ( pPars->nRounds < 0 )
32466                 goto usage;
32467             break;
32468         case 'S':
32469             if ( globalUtilOptind >= argc )
32470             {
32471                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
32472                 goto usage;
32473             }
32474             pPars->nRestart = atoi(argv[globalUtilOptind]);
32475             globalUtilOptind++;
32476             if ( pPars->nRestart < 0 )
32477                 goto usage;
32478             break;
32479         case 'N':
32480             if ( globalUtilOptind >= argc )
32481             {
32482                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
32483                 goto usage;
32484             }
32485             pPars->nRandSeed = atoi(argv[globalUtilOptind]);
32486             globalUtilOptind++;
32487             if ( pPars->nRandSeed < 0 )
32488                 goto usage;
32489             break;
32490         case 'T':
32491             if ( globalUtilOptind >= argc )
32492             {
32493                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
32494                 goto usage;
32495             }
32496             pPars->TimeOut = atoi(argv[globalUtilOptind]);
32497             globalUtilOptind++;
32498             if ( pPars->TimeOut < 0 )
32499                 goto usage;
32500             break;
32501         case 'G':
32502             if ( globalUtilOptind >= argc )
32503             {
32504                 Abc_Print( -1, "Command line switch \"-G\" should be followed by an integer.\n" );
32505                 goto usage;
32506             }
32507             pPars->TimeOutGap = atoi(argv[globalUtilOptind]);
32508             globalUtilOptind++;
32509             if ( pPars->TimeOutGap < 0 )
32510                 goto usage;
32511             break;
32512         case 'g':
32513             pPars->fUseFfGrouping ^= 1;
32514             break;
32515         case 'v':
32516             pPars->fVerbose ^= 1;
32517             break;
32518         case 'h':
32519             goto usage;
32520         default:
32521             goto usage;
32522         }
32523     }
32524     if ( pAbc->pGia == NULL )
32525     {
32526         Abc_Print( -1, "Abc_CommandAbc9Sim3(): There is no AIG.\n" );
32527         return 1;
32528     }
32529     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
32530     {
32531         Abc_Print( -1, "Abc_CommandAbc9Sim3(): This command works only for sequential AIGs.\n" );
32532         return 0;
32533     }
32534     pAbc->Status = Ssw_RarSimulateGia( pAbc->pGia, pPars );
32535     Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexSeq );
32536     return 0;
32537 
32538 usage:
32539     Abc_Print( -2, "usage: &sim3 [-FWBRNT num] [-gvh]\n" );
32540     Abc_Print( -2, "\t         performs random simulation of the sequential miter\n" );
32541     Abc_Print( -2, "\t-F num : the number of frames to simulate [default = %d]\n",       pPars->nFrames );
32542     Abc_Print( -2, "\t-W num : the number of words to simulate [default = %d]\n",        pPars->nWords );
32543     Abc_Print( -2, "\t-B num : the number of flops in one bin [default = %d]\n",         pPars->nBinSize );
32544     Abc_Print( -2, "\t-R num : the number of simulation rounds [default = %d]\n",        pPars->nRounds );
32545     Abc_Print( -2, "\t-S num : the number of rounds before a restart [default = %d]\n",  pPars->nRestart );
32546     Abc_Print( -2, "\t-N num : random number seed (1 <= num <= 1000) [default = %d]\n",  pPars->nRandSeed );
32547     Abc_Print( -2, "\t-T num : approximate runtime limit in seconds [default = %d]\n",   pPars->TimeOut );
32548     Abc_Print( -2, "\t-g     : toggle heuristic flop grouping [default = %s]\n",    pPars->fUseFfGrouping? "yes": "no" );
32549     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",    pPars->fVerbose? "yes": "no" );
32550     Abc_Print( -2, "\t-h     : print the command usage\n");
32551     return 1;
32552 }
32553 
32554 /**Function*************************************************************
32555 
32556   Synopsis    []
32557 
32558   Description []
32559 
32560   SideEffects []
32561 
32562   SeeAlso     []
32563 
32564 ***********************************************************************/
Abc_CommandAbc9MLGen(Abc_Frame_t * pAbc,int argc,char ** argv)32565 int Abc_CommandAbc9MLGen( Abc_Frame_t * pAbc, int argc, char ** argv )
32566 {
32567     extern void Gia_ManDumpFiles( Gia_Man_t * p, int nCexesT, int nCexesV, int Seed, char * pFileName );
32568     extern void Gia_ManDumpPlaFiles( Gia_Man_t * p, int nCexesT, int nCexesV, int Seed, char * pFileName );
32569     int c, Seed = 0, nWords = 10, fBinData = 0, fVerbose = 0;
32570     char * pFileName = NULL;
32571     char ** pArgvNew;
32572     int nArgcNew;
32573     Extra_UtilGetoptReset();
32574     while ( ( c = Extra_UtilGetopt( argc, argv, "WSbvh" ) ) != EOF )
32575     {
32576         switch ( c )
32577         {
32578         case 'W':
32579             if ( globalUtilOptind >= argc )
32580             {
32581                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
32582                 goto usage;
32583             }
32584             nWords = atoi(argv[globalUtilOptind]);
32585             globalUtilOptind++;
32586             if ( nWords < 0 )
32587                 goto usage;
32588             break;
32589         case 'S':
32590             if ( globalUtilOptind >= argc )
32591             {
32592                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
32593                 goto usage;
32594             }
32595             Seed = atoi(argv[globalUtilOptind]);
32596             globalUtilOptind++;
32597             if ( Seed < 0 )
32598                 goto usage;
32599             break;
32600         case 'b':
32601             fBinData ^= 1;
32602             break;
32603         case 'v':
32604             fVerbose ^= 1;
32605             break;
32606         case 'h':
32607             goto usage;
32608         default:
32609             goto usage;
32610         }
32611     }
32612     if ( pAbc->pGia == NULL )
32613     {
32614         Abc_Print( -1, "Abc_CommandAbc9MLGen(): There is no AIG.\n" );
32615         return 1;
32616     }
32617     if ( Gia_ManRegNum(pAbc->pGia) > 0 )
32618     {
32619         Abc_Print( -1, "Abc_CommandAbc9MLGen(): This command works only for combinational AIGs.\n" );
32620         return 0;
32621     }
32622     Vec_WrdFreeP( &pAbc->pGia->vSimsPi );
32623     pArgvNew = argv + globalUtilOptind;
32624     nArgcNew = argc - globalUtilOptind;
32625     if ( nArgcNew == 0 )
32626         printf( "Default file names will be used.\n" );
32627     else
32628         pFileName = pArgvNew[0];
32629     if ( nArgcNew != 0 && nArgcNew != 1 )
32630     {
32631         Abc_Print( -1, "File name is not given on the command line.\n" );
32632         return 1;
32633     }
32634     if ( fBinData )
32635         Gia_ManDumpFiles( pAbc->pGia, nWords, nWords, Seed, pFileName );
32636     else
32637         Gia_ManDumpPlaFiles( pAbc->pGia, nWords, nWords, Seed, pFileName );
32638     return 0;
32639 
32640 usage:
32641     Abc_Print( -2, "usage: &mlgen [-WS num] [-bvh] <file>\n" );
32642     Abc_Print( -2, "\t         generates data files for machine learning\n" );
32643     Abc_Print( -2, "\t-W num : the number of words to simulate [default = %d]\n", nWords );
32644     Abc_Print( -2, "\t-S num : the random seed for simulation data (num < 10000) [default = %d]\n", Seed );
32645     Abc_Print( -2, "\t-b     : toggle using binary data files [default = %s]\n", fBinData? "yes": "no" );
32646     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
32647     Abc_Print( -2, "\t-h     : print the command usage\n");
32648     Abc_Print( -2, "\t<file> : file to store the simulation info\n");
32649     return 1;
32650 }
32651 
32652 /**Function*************************************************************
32653 
32654   Synopsis    []
32655 
32656   Description []
32657 
32658   SideEffects []
32659 
32660   SeeAlso     []
32661 
32662 ***********************************************************************/
Abc_CommandAbc9MLTest(Abc_Frame_t * pAbc,int argc,char ** argv)32663 int Abc_CommandAbc9MLTest( Abc_Frame_t * pAbc, int argc, char ** argv )
32664 {
32665     extern void Gia_ManTestOneFile( Gia_Man_t * p, char * pFileName, char * pDumpFile );
32666     int c, fVerbose = 0;
32667     char * pDumpFile = NULL;
32668     char ** pArgvNew;
32669     int nArgcNew;
32670     Extra_UtilGetoptReset();
32671     while ( ( c = Extra_UtilGetopt( argc, argv, "Dvh" ) ) != EOF )
32672     {
32673         switch ( c )
32674         {
32675         case 'D':
32676             if ( globalUtilOptind >= argc )
32677             {
32678                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a file name.\n" );
32679                 goto usage;
32680             }
32681             pDumpFile = argv[globalUtilOptind];
32682             globalUtilOptind++;
32683             break;
32684         case 'v':
32685             fVerbose ^= 1;
32686             break;
32687         case 'h':
32688             goto usage;
32689         default:
32690             goto usage;
32691         }
32692     }
32693     if ( pAbc->pGia == NULL )
32694     {
32695         Abc_Print( -1, "Abc_CommandAbc9MLTest(): There is no AIG.\n" );
32696         return 1;
32697     }
32698     if ( Gia_ManRegNum(pAbc->pGia) > 0 )
32699     {
32700         Abc_Print( -1, "Abc_CommandAbc9MLTest(): This command works only for combinational AIGs.\n" );
32701         return 0;
32702     }
32703     Vec_WrdFreeP( &pAbc->pGia->vSimsPi );
32704     pArgvNew = argv + globalUtilOptind;
32705     nArgcNew = argc - globalUtilOptind;
32706     if ( nArgcNew != 1 )
32707     {
32708         Abc_Print( -1, "Abc_CommandAbc9MLTest(): Expecting data file name on the command line.\n" );
32709         return 0;
32710     }
32711     Gia_ManTestOneFile( pAbc->pGia, pArgvNew[0], pDumpFile );
32712     return 0;
32713 
32714 usage:
32715     Abc_Print( -2, "usage: &mltest [-vh] [-D file] <file>\n" );
32716     Abc_Print( -2, "\t          testing command for machine learning data\n" );
32717     Abc_Print( -2, "\t-v      : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
32718     Abc_Print( -2, "\t-h      : print the command usage\n");
32719     Abc_Print( -2, "\t-D file : file name to dump statistics [default = none]\n" );
32720     Abc_Print( -2, "\tfile    : file with input simulation info\n");
32721     return 1;
32722 }
32723 
32724 /**Function*************************************************************
32725 
32726   Synopsis    []
32727 
32728   Description []
32729 
32730   SideEffects []
32731 
32732   SeeAlso     []
32733 
32734 ***********************************************************************/
Abc_CommandAbc9ReadSim(Abc_Frame_t * pAbc,int argc,char ** argv)32735 int Abc_CommandAbc9ReadSim( Abc_Frame_t * pAbc, int argc, char ** argv )
32736 {
32737     extern Vec_Wrd_t * Gia_ManSimPatRead( char * pFileName );
32738     int c, fOutputs = 0, nWords = 4, fVerbose = 0;
32739     char ** pArgvNew;
32740     int nArgcNew;
32741     Extra_UtilGetoptReset();
32742     while ( ( c = Extra_UtilGetopt( argc, argv, "Wovh" ) ) != EOF )
32743     {
32744         switch ( c )
32745         {
32746         case 'W':
32747             if ( globalUtilOptind >= argc )
32748             {
32749                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
32750                 goto usage;
32751             }
32752             nWords = atoi(argv[globalUtilOptind]);
32753             globalUtilOptind++;
32754             if ( nWords < 0 )
32755                 goto usage;
32756             break;
32757         case 'o':
32758             fOutputs ^= 1;
32759             break;
32760         case 'v':
32761             fVerbose ^= 1;
32762             break;
32763         case 'h':
32764             goto usage;
32765         default:
32766             goto usage;
32767         }
32768     }
32769     if ( pAbc->pGia == NULL )
32770     {
32771         Abc_Print( -1, "Abc_CommandAbc9ReadSim(): There is no AIG.\n" );
32772         return 1;
32773     }
32774     if ( Gia_ManRegNum(pAbc->pGia) > 0 )
32775     {
32776         Abc_Print( -1, "Abc_CommandAbc9ReadSim(): This command works only for combinational AIGs.\n" );
32777         return 0;
32778     }
32779     pArgvNew = argv + globalUtilOptind;
32780     nArgcNew = argc - globalUtilOptind;
32781     if ( nArgcNew == 0 )
32782     {
32783         Gia_ManRandom( 1 );
32784         pAbc->pGia->vSimsPi = Vec_WrdStartRandom( Gia_ManCiNum(pAbc->pGia) * nWords );
32785         printf( "Generated %d random patterns (%d 64-bit words) for each input of the AIG.\n", 64*nWords, nWords );
32786         return 0;
32787     }
32788     if ( nArgcNew != 1 )
32789     {
32790         Abc_Print( -1, "File name is not given on the command line.\n" );
32791         return 1;
32792     }
32793     if ( fOutputs )
32794     {
32795         Vec_WrdFreeP( &pAbc->pGia->vSimsPo );
32796         pAbc->pGia->vSimsPo = Gia_ManSimPatRead( pArgvNew[0] );
32797         if ( Vec_WrdSize(pAbc->pGia->vSimsPo) % Gia_ManCoNum(pAbc->pGia) != 0 )
32798         {
32799             Vec_WrdFreeP( &pAbc->pGia->vSimsPo );
32800             Abc_Print( -1, "File size (%d words) does not match the number of AIG inputs (%d %% %d != %d).\n",
32801                 Vec_WrdSize(pAbc->pGia->vSimsPo), Vec_WrdSize(pAbc->pGia->vSimsPo), Gia_ManCiNum(pAbc->pGia),
32802                 Vec_WrdSize(pAbc->pGia->vSimsPo) % Gia_ManCiNum(pAbc->pGia) );
32803             return 1;
32804         }
32805         pAbc->pGia->nSimWords = Vec_WrdSize(pAbc->pGia->vSimsPo) / Gia_ManCoNum(pAbc->pGia);
32806     }
32807     else
32808     {
32809         Vec_WrdFreeP( &pAbc->pGia->vSimsPi );
32810         pAbc->pGia->vSimsPi = Gia_ManSimPatRead( pArgvNew[0] );
32811         if ( Vec_WrdSize(pAbc->pGia->vSimsPi) % Gia_ManCiNum(pAbc->pGia) != 0 )
32812         {
32813             Vec_WrdFreeP( &pAbc->pGia->vSimsPi );
32814             Abc_Print( -1, "File size (%d words) does not match the number of AIG inputs (%d %% %d != %d).\n",
32815                 Vec_WrdSize(pAbc->pGia->vSimsPi), Vec_WrdSize(pAbc->pGia->vSimsPi), Gia_ManCiNum(pAbc->pGia),
32816                 Vec_WrdSize(pAbc->pGia->vSimsPi) % Gia_ManCiNum(pAbc->pGia) );
32817             return 1;
32818         }
32819         pAbc->pGia->nSimWords = Vec_WrdSize(pAbc->pGia->vSimsPi) / Gia_ManCiNum(pAbc->pGia);
32820     }
32821     return 0;
32822 
32823 usage:
32824     Abc_Print( -2, "usage: &read_sim [-W num] [-ovh] <file>\n" );
32825     Abc_Print( -2, "\t         reads simulation patterns from file\n" );
32826     Abc_Print( -2, "\t-W num : the number of words to simulate [default = %d]\n", nWords );
32827     Abc_Print( -2, "\t-o     : toggle reading output information [default = %s]\n", fOutputs? "yes": "no" );
32828     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
32829     Abc_Print( -2, "\t-h     : print the command usage\n");
32830     Abc_Print( -2, "\t<file> : file to store the simulation info\n");
32831     return 1;
32832 }
32833 
32834 /**Function*************************************************************
32835 
32836   Synopsis    []
32837 
32838   Description []
32839 
32840   SideEffects []
32841 
32842   SeeAlso     []
32843 
32844 ***********************************************************************/
Abc_CommandAbc9WriteSim(Abc_Frame_t * pAbc,int argc,char ** argv)32845 int Abc_CommandAbc9WriteSim( Abc_Frame_t * pAbc, int argc, char ** argv )
32846 {
32847     extern void Gia_ManSimPatWrite( char * pFileName, Vec_Wrd_t * vSimsIn, int nWords );
32848     int c, fOutputs = 0, fVerbose = 0;
32849     char ** pArgvNew;
32850     int nArgcNew;
32851     Extra_UtilGetoptReset();
32852     while ( ( c = Extra_UtilGetopt( argc, argv, "ovh" ) ) != EOF )
32853     {
32854         switch ( c )
32855         {
32856         case 'o':
32857             fOutputs ^= 1;
32858             break;
32859         case 'v':
32860             fVerbose ^= 1;
32861             break;
32862         case 'h':
32863             goto usage;
32864         default:
32865             goto usage;
32866         }
32867     }
32868     if ( pAbc->pGia == NULL )
32869     {
32870         Abc_Print( -1, "Abc_CommandAbc9WriteSim(): There is no AIG.\n" );
32871         return 1;
32872     }
32873     if ( Gia_ManRegNum(pAbc->pGia) > 0 )
32874     {
32875         Abc_Print( -1, "Abc_CommandAbc9WriteSim(): This command works only for combinational AIGs.\n" );
32876         return 0;
32877     }
32878     if ( (fOutputs ? pAbc->pGia->vSimsPo : pAbc->pGia->vSimsPi) == NULL )
32879     {
32880         Abc_Print( -1, "Abc_CommandAbc9WriteSim(): Does not have simulation information available.\n" );
32881         return 0;
32882     }
32883     pArgvNew = argv + globalUtilOptind;
32884     nArgcNew = argc - globalUtilOptind;
32885     if ( nArgcNew != 1 )
32886     {
32887         Abc_Print( -1, "File name is not given on the command line.\n" );
32888         return 1;
32889     }
32890     if ( fOutputs )
32891     {
32892         assert( Vec_WrdSize(pAbc->pGia->vSimsPo) % Gia_ManCoNum(pAbc->pGia) == 0 );
32893         Gia_ManSimPatWrite( pArgvNew[0], pAbc->pGia->vSimsPo, Vec_WrdSize(pAbc->pGia->vSimsPo) / Gia_ManCoNum(pAbc->pGia) );
32894     }
32895     else
32896     {
32897         assert( Vec_WrdSize(pAbc->pGia->vSimsPi) % Gia_ManCiNum(pAbc->pGia) == 0 );
32898         Gia_ManSimPatWrite( pArgvNew[0], pAbc->pGia->vSimsPi, Vec_WrdSize(pAbc->pGia->vSimsPi) / Gia_ManCiNum(pAbc->pGia) );
32899     }
32900     return 0;
32901 
32902 usage:
32903     Abc_Print( -2, "usage: &write_sim [-vh] <file>\n" );
32904     Abc_Print( -2, "\t         writes simulation patterns into a file\n" );
32905     Abc_Print( -2, "\t-o     : toggle writing output information [default = %s]\n", fOutputs? "yes": "no" );
32906     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
32907     Abc_Print( -2, "\t-h     : print the command usage\n");
32908     Abc_Print( -2, "\t<file> : file to store the simulation info\n");
32909     return 1;
32910 }
32911 
32912 /**Function*************************************************************
32913 
32914   Synopsis    []
32915 
32916   Description []
32917 
32918   SideEffects []
32919 
32920   SeeAlso     []
32921 
32922 ***********************************************************************/
Abc_CommandAbc9SimPat(Abc_Frame_t * pAbc,int argc,char ** argv)32923 int Abc_CommandAbc9SimPat( Abc_Frame_t * pAbc, int argc, char ** argv )
32924 {
32925     extern void Gia_ManSimPat( Gia_Man_t * pGia, int nWords, int fVerbose );
32926     int c, nWords = 4, fVerbose = 0;
32927     Extra_UtilGetoptReset();
32928     while ( ( c = Extra_UtilGetopt( argc, argv, "Wvh" ) ) != EOF )
32929     {
32930         switch ( c )
32931         {
32932         case 'W':
32933             if ( globalUtilOptind >= argc )
32934             {
32935                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
32936                 goto usage;
32937             }
32938             nWords = atoi(argv[globalUtilOptind]);
32939             globalUtilOptind++;
32940             if ( nWords < 0 )
32941                 goto usage;
32942             break;
32943         case 'v':
32944             fVerbose ^= 1;
32945             break;
32946         case 'h':
32947             goto usage;
32948         default:
32949             goto usage;
32950         }
32951     }
32952     if ( pAbc->pGia == NULL )
32953     {
32954         Abc_Print( -1, "Abc_CommandAbc9SimPat(): There is no AIG.\n" );
32955         return 1;
32956     }
32957     if ( Gia_ManRegNum(pAbc->pGia) > 0 )
32958     {
32959         Abc_Print( -1, "Abc_CommandAbc9SimPat(): This command works only for combinational AIGs.\n" );
32960         return 0;
32961     }
32962     if ( pAbc->pGia->vSimsPi == NULL )
32963     {
32964         Abc_Print( -1, "Abc_CommandAbc9SimPat(): Does not have simulation information available.\n" );
32965         return 0;
32966     }
32967     Gia_ManSimPat( pAbc->pGia, nWords, fVerbose );
32968     return 0;
32969 
32970 usage:
32971     Abc_Print( -2, "usage: &simpat [-W num] [-vh]\n" );
32972     Abc_Print( -2, "\t         performs simulation of the AIG\n" );
32973     Abc_Print( -2, "\t-W num : the number of frames to simulate [default = %d]\n", nWords );
32974     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
32975     Abc_Print( -2, "\t-h     : print the command usage\n");
32976     return 1;
32977 }
32978 
32979 /**Function*************************************************************
32980 
32981   Synopsis    []
32982 
32983   Description []
32984 
32985   SideEffects []
32986 
32987   SeeAlso     []
32988 
32989 ***********************************************************************/
Abc_CommandAbc9SimRsb(Abc_Frame_t * pAbc,int argc,char ** argv)32990 int Abc_CommandAbc9SimRsb( Abc_Frame_t * pAbc, int argc, char ** argv )
32991 {
32992     extern void Gia_ManSimRsb( Gia_Man_t * p, int nCands, int fVerbose );
32993     int c, nCands = 32, fVerbose = 0;
32994     Extra_UtilGetoptReset();
32995     while ( ( c = Extra_UtilGetopt( argc, argv, "Nvh" ) ) != EOF )
32996     {
32997         switch ( c )
32998         {
32999         case 'N':
33000             if ( globalUtilOptind >= argc )
33001             {
33002                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
33003                 goto usage;
33004             }
33005             nCands = atoi(argv[globalUtilOptind]);
33006             globalUtilOptind++;
33007             if ( nCands < 0 )
33008                 goto usage;
33009             break;
33010         case 'v':
33011             fVerbose ^= 1;
33012             break;
33013         case 'h':
33014             goto usage;
33015         default:
33016             goto usage;
33017         }
33018     }
33019     if ( pAbc->pGia == NULL )
33020     {
33021         Abc_Print( -1, "Abc_CommandAbc9SimRsb(): There is no AIG.\n" );
33022         return 1;
33023     }
33024     if ( Gia_ManRegNum(pAbc->pGia) > 0 )
33025     {
33026         Abc_Print( -1, "Abc_CommandAbc9SimRsb(): This command works only for combinational AIGs.\n" );
33027         return 0;
33028     }
33029     if ( pAbc->pGia->vSimsPi == NULL )
33030     {
33031         Abc_Print( -1, "Abc_CommandAbc9SimRsb(): Does not have simulation information available.\n" );
33032         return 0;
33033     }
33034     Gia_ManSimRsb( pAbc->pGia, nCands, fVerbose );
33035     return 0;
33036 
33037 usage:
33038     Abc_Print( -2, "usage: &simrsb [-N num] [-vh]\n" );
33039     Abc_Print( -2, "\t         performs resubstitution\n" );
33040     Abc_Print( -2, "\t-C num : the number of candidates to try [default = %d]\n", nCands );
33041     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
33042     Abc_Print( -2, "\t-h     : print the command usage\n");
33043     return 1;
33044 }
33045 
33046 /**Function*************************************************************
33047 
33048   Synopsis    []
33049 
33050   Description []
33051 
33052   SideEffects []
33053 
33054   SeeAlso     []
33055 
33056 ***********************************************************************/
Abc_CommandAbc9Resim(Abc_Frame_t * pAbc,int argc,char ** argv)33057 int Abc_CommandAbc9Resim( Abc_Frame_t * pAbc, int argc, char ** argv )
33058 {
33059     Cec_ParSim_t Pars, * pPars = &Pars;
33060     int c, RetValue;
33061     Cec_ManSimSetDefaultParams( pPars );
33062     Extra_UtilGetoptReset();
33063     while ( ( c = Extra_UtilGetopt( argc, argv, "Fmvh" ) ) != EOF )
33064     {
33065         switch ( c )
33066         {
33067         case 'F':
33068             if ( globalUtilOptind >= argc )
33069             {
33070                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
33071                 goto usage;
33072             }
33073             pPars->nFrames = atoi(argv[globalUtilOptind]);
33074             globalUtilOptind++;
33075             if ( pPars->nFrames < 0 )
33076                 goto usage;
33077             break;
33078         case 'm':
33079             pPars->fCheckMiter ^= 1;
33080             break;
33081         case 'v':
33082             pPars->fVerbose ^= 1;
33083             break;
33084         case 'h':
33085             goto usage;
33086         default:
33087             goto usage;
33088         }
33089     }
33090     if ( pAbc->pGia == NULL )
33091     {
33092         Abc_Print( -1, "Abc_CommandAbc9Resim(): There is no AIG.\n" );
33093         return 1;
33094     }
33095     RetValue = Cec_ManSeqResimulateCounter( pAbc->pGia, pPars, pAbc->pCex );
33096     pAbc->Status  = RetValue ? 0 : -1;
33097     pAbc->nFrames = pAbc->pCex->iFrame;
33098 //    Abc_FrameReplaceCex( pAbc, &pAbc->pCex );
33099     return 0;
33100 
33101 usage:
33102     Abc_Print( -2, "usage: &resim [-F num] [-mvh]\n" );
33103     Abc_Print( -2, "\t         resimulates equivalence classes using counter-example\n" );
33104     Abc_Print( -2, "\t-F num : the number of additinal frames to simulate [default = %d]\n", pPars->nFrames );
33105     Abc_Print( -2, "\t-m     : toggle miter vs. any circuit [default = %s]\n", pPars->fCheckMiter? "miter": "circuit" );
33106     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
33107     Abc_Print( -2, "\t-h     : print the command usage\n");
33108     return 1;
33109 }
33110 
33111 /**Function*************************************************************
33112 
33113   Synopsis    []
33114 
33115   Description []
33116 
33117   SideEffects []
33118 
33119   SeeAlso     []
33120 
33121 ***********************************************************************/
Abc_CommandAbc9SpecI(Abc_Frame_t * pAbc,int argc,char ** argv)33122 int Abc_CommandAbc9SpecI( Abc_Frame_t * pAbc, int argc, char ** argv )
33123 {
33124     extern int Gia_CommandSpecI( Gia_Man_t * pGia, int nFrames, int nBTLimit, int fUseStart, int fCheckMiter, int fVerbose );
33125     int nFrames     =   100;
33126     int nBTLimit    = 25000;
33127     int fUseStart   =     1;
33128     int fCheckMiter =     1;
33129     int fVerbose    =     0;
33130     int c;
33131     Extra_UtilGetoptReset();
33132     while ( ( c = Extra_UtilGetopt( argc, argv, "FCfmvh" ) ) != EOF )
33133     {
33134         switch ( c )
33135         {
33136         case 'F':
33137             if ( globalUtilOptind >= argc )
33138             {
33139                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
33140                 goto usage;
33141             }
33142             nFrames = atoi(argv[globalUtilOptind]);
33143             globalUtilOptind++;
33144             if ( nFrames < 0 )
33145                 goto usage;
33146             break;
33147         case 'C':
33148             if ( globalUtilOptind >= argc )
33149             {
33150                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
33151                 goto usage;
33152             }
33153             nBTLimit = atoi(argv[globalUtilOptind]);
33154             globalUtilOptind++;
33155             if ( nBTLimit < 0 )
33156                 goto usage;
33157             break;
33158         case 'f':
33159             fUseStart ^= 1;
33160             break;
33161         case 'm':
33162             fCheckMiter ^= 1;
33163             break;
33164         case 'v':
33165             fVerbose ^= 1;
33166             break;
33167         case 'h':
33168             goto usage;
33169         default:
33170             goto usage;
33171         }
33172     }
33173     if ( pAbc->pGia == NULL )
33174     {
33175         Abc_Print( -1, "Abc_CommandAbc9SpecI(): There is no AIG.\n" );
33176         return 1;
33177     }
33178     Gia_CommandSpecI( pAbc->pGia, nFrames, nBTLimit, fUseStart, fCheckMiter, fVerbose );
33179     return 0;
33180 
33181 usage:
33182     Abc_Print( -2, "usage: &speci [-FC num] [-fmvh]\n" );
33183     Abc_Print( -2, "\t         refines equivalence classes using speculative reduction\n" );
33184     Abc_Print( -2, "\t-F num : the max number of time frames [default = %d]\n", nFrames );
33185     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", nBTLimit );
33186     Abc_Print( -2, "\t-f     : toggle starting BMC from a later frame [default = %s]\n", fUseStart? "yes": "no" );
33187     Abc_Print( -2, "\t-m     : toggle miter vs. any circuit [default = %s]\n", fCheckMiter? "miter": "circuit" );
33188     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
33189     Abc_Print( -2, "\t-h     : print the command usage\n");
33190     return 1;
33191 }
33192 
33193 
33194 
33195 /**Function*************************************************************
33196 
33197   Synopsis    []
33198 
33199   Description []
33200 
33201   SideEffects []
33202 
33203   SeeAlso     []
33204 
33205 ***********************************************************************/
Abc_CommandAbc9Equiv(Abc_Frame_t * pAbc,int argc,char ** argv)33206 int Abc_CommandAbc9Equiv( Abc_Frame_t * pAbc, int argc, char ** argv )
33207 {
33208     Cec_ParSim_t Pars, * pPars = &Pars;
33209     int c;
33210     Cec_ManSimSetDefaultParams( pPars );
33211     Extra_UtilGetoptReset();
33212     while ( ( c = Extra_UtilGetopt( argc, argv, "WFRSTsmdvh" ) ) != EOF )
33213     {
33214         switch ( c )
33215         {
33216         case 'W':
33217             if ( globalUtilOptind >= argc )
33218             {
33219                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
33220                 goto usage;
33221             }
33222             pPars->nWords = atoi(argv[globalUtilOptind]);
33223             globalUtilOptind++;
33224             if ( pPars->nWords < 0 )
33225                 goto usage;
33226             break;
33227         case 'F':
33228             if ( globalUtilOptind >= argc )
33229             {
33230                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
33231                 goto usage;
33232             }
33233             pPars->nFrames = atoi(argv[globalUtilOptind]);
33234             globalUtilOptind++;
33235             if ( pPars->nFrames < 0 )
33236                 goto usage;
33237             break;
33238         case 'R':
33239             if ( globalUtilOptind >= argc )
33240             {
33241                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
33242                 goto usage;
33243             }
33244             pPars->nRounds = atoi(argv[globalUtilOptind]);
33245             globalUtilOptind++;
33246             if ( pPars->nRounds < 0 )
33247                 goto usage;
33248             break;
33249         case 'S':
33250             if ( globalUtilOptind >= argc )
33251             {
33252                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
33253                 goto usage;
33254             }
33255             pPars->nNonRefines = atoi(argv[globalUtilOptind]);
33256             globalUtilOptind++;
33257             if ( pPars->nNonRefines < 0 )
33258                 goto usage;
33259             break;
33260         case 'T':
33261             if ( globalUtilOptind >= argc )
33262             {
33263                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
33264                 goto usage;
33265             }
33266             pPars->TimeLimit = atoi(argv[globalUtilOptind]);
33267             globalUtilOptind++;
33268             if ( pPars->TimeLimit < 0 )
33269                 goto usage;
33270             break;
33271         case 's':
33272             pPars->fSeqSimulate ^= 1;
33273             break;
33274         case 'm':
33275             pPars->fCheckMiter ^= 1;
33276             break;
33277         case 'd':
33278             pPars->fDualOut ^= 1;
33279             break;
33280         case 'v':
33281             pPars->fVerbose ^= 1;
33282             break;
33283         case 'h':
33284             goto usage;
33285         default:
33286             goto usage;
33287         }
33288     }
33289     if ( pAbc->pGia == NULL )
33290     {
33291         Abc_Print( -1, "Abc_CommandAbc9Equiv(): There is no AIG.\n" );
33292         return 1;
33293     }
33294     Cec_ManSimulation( pAbc->pGia, pPars );
33295     return 0;
33296 
33297 usage:
33298     Abc_Print( -2, "usage: &equiv [-WFRST num] [-smdvh]\n" );
33299     Abc_Print( -2, "\t         computes candidate equivalence classes\n" );
33300     Abc_Print( -2, "\t-W num : the number of words to simulate [default = %d]\n", pPars->nWords );
33301     Abc_Print( -2, "\t-F num : the number of frames to simulate [default = %d]\n", pPars->nFrames );
33302     Abc_Print( -2, "\t-R num : the max number of simulation rounds [default = %d]\n", pPars->nRounds );
33303     Abc_Print( -2, "\t-S num : the max number of rounds w/o refinement to stop [default = %d]\n", pPars->nNonRefines );
33304     Abc_Print( -2, "\t-T num : approximate runtime limit in seconds [default = %d]\n", pPars->TimeLimit );
33305     Abc_Print( -2, "\t-s     : toggle seq vs. comb simulation [default = %s]\n", pPars->fSeqSimulate? "yes": "no" );
33306     Abc_Print( -2, "\t-m     : toggle miter vs. any circuit [default = %s]\n", pPars->fCheckMiter? "miter": "circuit" );
33307     Abc_Print( -2, "\t-d     : toggle using two POs intead of XOR [default = %s]\n", pPars->fDualOut? "yes": "no" );
33308     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
33309     Abc_Print( -2, "\t-h     : print the command usage\n");
33310     return 1;
33311 }
33312 
33313 /**Function*************************************************************
33314 
33315   Synopsis    []
33316 
33317   Description []
33318 
33319   SideEffects []
33320 
33321   SeeAlso     []
33322 
33323 ***********************************************************************/
Abc_CommandAbc9Equiv2(Abc_Frame_t * pAbc,int argc,char ** argv)33324 int Abc_CommandAbc9Equiv2( Abc_Frame_t * pAbc, int argc, char ** argv )
33325 {
33326     extern void Ssw_SignalFilterGia( Gia_Man_t * p, int nFramesMax, int nConfMax, int nRounds, int TimeLimit, int TimeLimit2, Abc_Cex_t * pCex, int fLatchOnly, int fVerbose );
33327     int nFramesMax =   20;
33328     int nConfMax   =  500;
33329     int nRounds    =   10;
33330     int TimeLimit  =    0;
33331     int TimeLimit2 =    0;
33332     int fUseCex    =    0;
33333     int fLatchOnly =    0;
33334     int fVerbose   =    0;
33335     int c;
33336     Extra_UtilGetoptReset();
33337     while ( ( c = Extra_UtilGetopt( argc, argv, "FCRTSxlvh" ) ) != EOF )
33338     {
33339         switch ( c )
33340         {
33341         case 'F':
33342             if ( globalUtilOptind >= argc )
33343             {
33344                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
33345                 goto usage;
33346             }
33347             nFramesMax = atoi(argv[globalUtilOptind]);
33348             globalUtilOptind++;
33349             if ( nFramesMax < 0 )
33350                 goto usage;
33351             break;
33352         case 'C':
33353             if ( globalUtilOptind >= argc )
33354             {
33355                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
33356                 goto usage;
33357             }
33358             nConfMax = atoi(argv[globalUtilOptind]);
33359             globalUtilOptind++;
33360             if ( nConfMax < 0 )
33361                 goto usage;
33362             break;
33363         case 'R':
33364             if ( globalUtilOptind >= argc )
33365             {
33366                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
33367                 goto usage;
33368             }
33369             nRounds = atoi(argv[globalUtilOptind]);
33370             globalUtilOptind++;
33371             if ( nRounds < 0 )
33372                 goto usage;
33373             break;
33374         case 'T':
33375             if ( globalUtilOptind >= argc )
33376             {
33377                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
33378                 goto usage;
33379             }
33380             TimeLimit = atoi(argv[globalUtilOptind]);
33381             globalUtilOptind++;
33382             if ( TimeLimit < 0 )
33383                 goto usage;
33384             break;
33385         case 'S':
33386             if ( globalUtilOptind >= argc )
33387             {
33388                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
33389                 goto usage;
33390             }
33391             TimeLimit2 = atoi(argv[globalUtilOptind]);
33392             globalUtilOptind++;
33393             if ( TimeLimit2 < 0 )
33394                 goto usage;
33395             break;
33396         case 'x':
33397             fUseCex ^= 1;
33398             break;
33399         case 'l':
33400             fLatchOnly ^= 1;
33401             break;
33402         case 'v':
33403             fVerbose ^= 1;
33404             break;
33405         case 'h':
33406             goto usage;
33407         default:
33408             goto usage;
33409         }
33410     }
33411     if ( pAbc->pGia == NULL )
33412     {
33413         Abc_Print( -1, "Abc_CommandAbc9Equiv2(): There is no AIG.\n" );
33414         return 1;
33415     }
33416     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
33417     {
33418         Abc_Print( 0, "Abc_CommandAbc9Equiv2(): There is no flops. Nothing is done.\n" );
33419         return 0;
33420     }
33421     if ( fUseCex )
33422     {
33423         if ( pAbc->pCex == NULL )
33424         {
33425             Abc_Print( 0, "Abc_CommandAbc9Equiv2(): Counter-example is not available.\n" );
33426             return 0;
33427         }
33428         if ( pAbc->pCex->nPis != Gia_ManPiNum(pAbc->pGia) )
33429         {
33430             Abc_Print( -1, "Abc_CommandAbc9Equiv2(): The number of PIs differs in cex (%d) and in AIG (%d).\n",
33431                 pAbc->pCex->nPis, Gia_ManPiNum(pAbc->pGia) );
33432             return 1;
33433         }
33434     }
33435     Ssw_SignalFilterGia( pAbc->pGia, nFramesMax, nConfMax, nRounds, TimeLimit, TimeLimit2, fUseCex? pAbc->pCex: NULL, fLatchOnly, fVerbose );
33436     pAbc->Status  = -1;
33437 //    pAbc->nFrames = pAbc->pCex->iFrame;
33438 //    Abc_FrameReplaceCex( pAbc, &pAbc->pCex );
33439     return 0;
33440 
33441 usage:
33442     Abc_Print( -2, "usage: &equiv2 [-FCRTS num] [-xlvh]\n" );
33443     Abc_Print( -2, "\t         computes candidate equivalence classes\n" );
33444     Abc_Print( -2, "\t-F num : the max number of frames for BMC [default = %d]\n", nFramesMax );
33445     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", nConfMax );
33446     Abc_Print( -2, "\t-R num : the max number of BMC rounds [default = %d]\n", nRounds );
33447     Abc_Print( -2, "\t-T num : runtime limit in seconds for all rounds [default = %d]\n", TimeLimit );
33448     Abc_Print( -2, "\t-S num : runtime limit in seconds for one round [default = %d]\n", TimeLimit2 );
33449     Abc_Print( -2, "\t-x     : toggle using the current cex to perform refinement [default = %s]\n", fUseCex? "yes": "no" );
33450     Abc_Print( -2, "\t-l     : toggle considering only latch output equivalences [default = %s]\n", fLatchOnly? "yes": "no" );
33451     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
33452     Abc_Print( -2, "\t-h     : print the command usage\n");
33453     return 1;
33454 }
33455 
33456 /**Function*************************************************************
33457 
33458   Synopsis    []
33459 
33460   Description []
33461 
33462   SideEffects []
33463 
33464   SeeAlso     []
33465 
33466 ***********************************************************************/
Abc_CommandAbc9Equiv3(Abc_Frame_t * pAbc,int argc,char ** argv)33467 int Abc_CommandAbc9Equiv3( Abc_Frame_t * pAbc, int argc, char ** argv )
33468 {
33469     extern int Ssw_RarSignalFilterGia( Gia_Man_t * p, Ssw_RarPars_t * pPars );
33470     Ssw_RarPars_t Pars, * pPars = &Pars;
33471     int c;
33472     Ssw_RarSetDefaultParams( pPars );
33473     Extra_UtilGetoptReset();
33474     while ( ( c = Extra_UtilGetopt( argc, argv, "FWBRSNTmxlvh" ) ) != EOF )
33475     {
33476         switch ( c )
33477         {
33478         case 'F':
33479             if ( globalUtilOptind >= argc )
33480             {
33481                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
33482                 goto usage;
33483             }
33484             pPars->nFrames = atoi(argv[globalUtilOptind]);
33485             globalUtilOptind++;
33486             if ( pPars->nFrames < 0 )
33487                 goto usage;
33488             break;
33489         case 'W':
33490             if ( globalUtilOptind >= argc )
33491             {
33492                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
33493                 goto usage;
33494             }
33495             pPars->nWords = atoi(argv[globalUtilOptind]);
33496             globalUtilOptind++;
33497             if ( pPars->nWords < 0 )
33498                 goto usage;
33499             break;
33500         case 'B':
33501             if ( globalUtilOptind >= argc )
33502             {
33503                 Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" );
33504                 goto usage;
33505             }
33506             pPars->nBinSize = atoi(argv[globalUtilOptind]);
33507             globalUtilOptind++;
33508             if ( pPars->nBinSize < 0 )
33509                 goto usage;
33510             break;
33511         case 'R':
33512             if ( globalUtilOptind >= argc )
33513             {
33514                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
33515                 goto usage;
33516             }
33517             pPars->nRounds = atoi(argv[globalUtilOptind]);
33518             globalUtilOptind++;
33519             if ( pPars->nRounds < 0 )
33520                 goto usage;
33521             break;
33522         case 'S':
33523             if ( globalUtilOptind >= argc )
33524             {
33525                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
33526                 goto usage;
33527             }
33528             pPars->nRestart = atoi(argv[globalUtilOptind]);
33529             globalUtilOptind++;
33530             if ( pPars->nRestart < 0 )
33531                 goto usage;
33532             break;
33533         case 'N':
33534             if ( globalUtilOptind >= argc )
33535             {
33536                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
33537                 goto usage;
33538             }
33539             pPars->nRandSeed = atoi(argv[globalUtilOptind]);
33540             globalUtilOptind++;
33541             if ( pPars->nRandSeed < 0 )
33542                 goto usage;
33543             break;
33544         case 'T':
33545             if ( globalUtilOptind >= argc )
33546             {
33547                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
33548                 goto usage;
33549             }
33550             pPars->TimeOut = atoi(argv[globalUtilOptind]);
33551             globalUtilOptind++;
33552             if ( pPars->TimeOut < 0 )
33553                 goto usage;
33554             break;
33555         case 'm':
33556             pPars->fMiter ^= 1;
33557             break;
33558         case 'x':
33559             pPars->fUseCex ^= 1;
33560             break;
33561         case 'l':
33562             pPars->fLatchOnly ^= 1;
33563             break;
33564         case 'v':
33565             pPars->fVerbose ^= 1;
33566             break;
33567         case 'h':
33568             goto usage;
33569         default:
33570             goto usage;
33571         }
33572     }
33573     if ( pAbc->pGia == NULL )
33574     {
33575         Abc_Print( -1, "Abc_CommandAbc9Equiv3(): There is no AIG.\n" );
33576         return 1;
33577     }
33578     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
33579     {
33580         Abc_Print( 0, "Abc_CommandAbc9Equiv3(): There is no flops. Nothing is done.\n" );
33581         return 0;
33582     }
33583     if ( pPars->fUseCex )
33584     {
33585         if ( pPars->fMiter )
33586         {
33587             Abc_Print( 0, "Abc_CommandAbc9Equiv3(): Considering the miter as a circuit because the CEX is given.\n" );
33588             pPars->fMiter = 0;
33589         }
33590         if ( pAbc->pCex == NULL )
33591         {
33592             Abc_Print( 0, "Abc_CommandAbc9Equiv3(): Counter-example is not available.\n" );
33593             return 0;
33594         }
33595         if ( pAbc->pCex->nPis != Gia_ManPiNum(pAbc->pGia) )
33596         {
33597             Abc_Print( -1, "Abc_CommandAbc9Equiv3(): The number of PIs differs in cex (%d) and in AIG (%d).\n",
33598                 pAbc->pCex->nPis, Gia_ManPiNum(pAbc->pGia) );
33599             return 1;
33600         }
33601         pPars->pCex = pAbc->pCex;
33602     }
33603     pAbc->Status = Ssw_RarSignalFilterGia( pAbc->pGia, pPars );
33604 //    pAbc->nFrames = pAbc->pGia->pCexSeq->iFrame;
33605     Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexSeq );
33606     return 0;
33607 
33608 usage:
33609     Abc_Print( -2, "usage: &equiv3 [-FWRSNT num] [-mxlvh]\n" );
33610     Abc_Print( -2, "\t         computes candidate equivalence classes\n" );
33611     Abc_Print( -2, "\t-F num : the max number of frames for BMC [default = %d]\n",                   pPars->nFrames );
33612     Abc_Print( -2, "\t-W num : the number of words to simulate [default = %d]\n",                    pPars->nWords );
33613     Abc_Print( -2, "\t-R num : the max number of simulation rounds [default = %d]\n",                pPars->nRounds );
33614     Abc_Print( -2, "\t-S num : the number of rounds before a restart [default = %d]\n",              pPars->nRestart );
33615     Abc_Print( -2, "\t-N num : random number seed (1 <= num <= 1000) [default = %d]\n",              pPars->nRandSeed );
33616     Abc_Print( -2, "\t-T num : runtime limit in seconds for all rounds [default = %d]\n",            pPars->TimeOut );
33617     Abc_Print( -2, "\t-m     : toggle miter vs. any circuit [default = %s]\n",                       pPars->fMiter? "miter": "circuit" );
33618     Abc_Print( -2, "\t-x     : toggle using the current CEX to perform refinement [default = %s]\n", pPars->fUseCex? "yes": "no" );
33619     Abc_Print( -2, "\t-l     : toggle considering only latch output equivalences [default = %s]\n",  pPars->fLatchOnly? "yes": "no" );
33620     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",                pPars->fVerbose? "yes": "no" );
33621     Abc_Print( -2, "\t-h     : print the command usage\n");
33622     return 1;
33623 }
33624 
33625 
33626 /**Function*************************************************************
33627 
33628   Synopsis    []
33629 
33630   Description []
33631 
33632   SideEffects []
33633 
33634   SeeAlso     []
33635 
33636 ***********************************************************************/
Abc_CommandAbc9Semi(Abc_Frame_t * pAbc,int argc,char ** argv)33637 int Abc_CommandAbc9Semi( Abc_Frame_t * pAbc, int argc, char ** argv )
33638 {
33639     Cec_ParSmf_t Pars, * pPars = &Pars;
33640     int c;
33641     Cec_ManSmfSetDefaultParams( pPars );
33642     Extra_UtilGetoptReset();
33643     while ( ( c = Extra_UtilGetopt( argc, argv, "WRFSMCTmdvh" ) ) != EOF )
33644     {
33645         switch ( c )
33646         {
33647         case 'W':
33648             if ( globalUtilOptind >= argc )
33649             {
33650                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
33651                 goto usage;
33652             }
33653             pPars->nWords = atoi(argv[globalUtilOptind]);
33654             globalUtilOptind++;
33655             if ( pPars->nWords < 0 )
33656                 goto usage;
33657             break;
33658         case 'R':
33659             if ( globalUtilOptind >= argc )
33660             {
33661                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
33662                 goto usage;
33663             }
33664             pPars->nRounds = atoi(argv[globalUtilOptind]);
33665             globalUtilOptind++;
33666             if ( pPars->nRounds < 0 )
33667                 goto usage;
33668             break;
33669         case 'F':
33670             if ( globalUtilOptind >= argc )
33671             {
33672                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
33673                 goto usage;
33674             }
33675             pPars->nFrames = atoi(argv[globalUtilOptind]);
33676             globalUtilOptind++;
33677             if ( pPars->nFrames < 0 )
33678                 goto usage;
33679             break;
33680         case 'S':
33681             if ( globalUtilOptind >= argc )
33682             {
33683                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
33684                 goto usage;
33685             }
33686             pPars->nNonRefines = atoi(argv[globalUtilOptind]);
33687             globalUtilOptind++;
33688             if ( pPars->nNonRefines < 0 )
33689                 goto usage;
33690             break;
33691         case 'M':
33692             if ( globalUtilOptind >= argc )
33693             {
33694                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
33695                 goto usage;
33696             }
33697             pPars->nMinOutputs = atoi(argv[globalUtilOptind]);
33698             globalUtilOptind++;
33699             if ( pPars->nMinOutputs < 0 )
33700                 goto usage;
33701             break;
33702         case 'C':
33703             if ( globalUtilOptind >= argc )
33704             {
33705                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
33706                 goto usage;
33707             }
33708             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
33709             globalUtilOptind++;
33710             if ( pPars->nBTLimit < 0 )
33711                 goto usage;
33712             break;
33713         case 'T':
33714             if ( globalUtilOptind >= argc )
33715             {
33716                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
33717                 goto usage;
33718             }
33719             pPars->TimeLimit = atoi(argv[globalUtilOptind]);
33720             globalUtilOptind++;
33721             if ( pPars->TimeLimit < 0 )
33722                 goto usage;
33723             break;
33724         case 'm':
33725             pPars->fCheckMiter ^= 1;
33726             break;
33727         case 'd':
33728             pPars->fDualOut ^= 1;
33729             break;
33730         case 'v':
33731             pPars->fVerbose ^= 1;
33732             break;
33733         case 'h':
33734             goto usage;
33735         default:
33736             goto usage;
33737         }
33738     }
33739     if ( pAbc->pGia == NULL )
33740     {
33741         Abc_Print( -1, "Abc_CommandAbc9Resim(): There is no AIG.\n" );
33742         return 1;
33743     }
33744     Cec_ManSeqSemiformal( pAbc->pGia, pPars );
33745     return 0;
33746 
33747 usage:
33748     Abc_Print( -2, "usage: &semi [-WRFSMCT num] [-mdvh]\n" );
33749     Abc_Print( -2, "\t         performs semiformal refinement of equivalence classes\n" );
33750     Abc_Print( -2, "\t-W num : the number of words to simulate [default = %d]\n", pPars->nWords );
33751     Abc_Print( -2, "\t-R num : the max number of rounds to simulate [default = %d]\n", pPars->nRounds );
33752     Abc_Print( -2, "\t-F num : the max number of frames to unroll [default = %d]\n", pPars->nFrames );
33753     Abc_Print( -2, "\t-S num : the max number of rounds w/o refinement to stop [default = %d]\n", pPars->nNonRefines );
33754     Abc_Print( -2, "\t-M num : the min number of outputs of bounded SRM [default = %d]\n", pPars->nMinOutputs );
33755     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", pPars->nBTLimit );
33756     Abc_Print( -2, "\t-T num : approximate runtime limit in seconds [default = %d]\n", pPars->TimeLimit );
33757     Abc_Print( -2, "\t-m     : toggle miter vs. any circuit [default = %s]\n", pPars->fCheckMiter? "miter": "circuit" );
33758     Abc_Print( -2, "\t-d     : toggle using two POs intead of XOR [default = %s]\n", pPars->fDualOut? "yes": "no" );
33759     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
33760     Abc_Print( -2, "\t-h     : print the command usage\n");
33761     return 1;
33762 }
33763 
33764 
33765 /**Function*************************************************************
33766 
33767   Synopsis    []
33768 
33769   Description []
33770 
33771   SideEffects []
33772 
33773   SeeAlso     []
33774 
33775 ***********************************************************************/
Abc_CommandAbc9Times(Abc_Frame_t * pAbc,int argc,char ** argv)33776 int Abc_CommandAbc9Times( Abc_Frame_t * pAbc, int argc, char ** argv )
33777 {
33778     Gia_Man_t * pTemp;
33779     int c, nTimes = 2, fVerbose = 0;
33780     Extra_UtilGetoptReset();
33781     while ( ( c = Extra_UtilGetopt( argc, argv, "Nvh" ) ) != EOF )
33782     {
33783         switch ( c )
33784         {
33785         case 'N':
33786             if ( globalUtilOptind >= argc )
33787             {
33788                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
33789                 goto usage;
33790             }
33791             nTimes = atoi(argv[globalUtilOptind]);
33792             globalUtilOptind++;
33793             if ( nTimes < 0 )
33794                 goto usage;
33795             break;
33796         case 'v':
33797             fVerbose ^= 1;
33798             break;
33799         case 'h':
33800             goto usage;
33801         default:
33802             goto usage;
33803         }
33804     }
33805     if ( pAbc->pGia == NULL )
33806     {
33807         Abc_Print( -1, "Abc_CommandAbc9Times(): There is no AIG.\n" );
33808         return 1;
33809     }
33810     pTemp = Gia_ManDupTimes( pAbc->pGia, nTimes );
33811     Abc_FrameUpdateGia( pAbc, pTemp );
33812     return 0;
33813 
33814 usage:
33815     Abc_Print( -2, "usage: &times [-N <num>] [-vh]\n" );
33816     Abc_Print( -2, "\t         creates several \"parallel\" copies of the design\n" );
33817     Abc_Print( -2, "\t-N num : number of copies to create [default = %d]\n", nTimes );
33818     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
33819     Abc_Print( -2, "\t-h     : print the command usage\n");
33820     return 1;
33821 }
33822 
33823 /**Function*************************************************************
33824 
33825   Synopsis    []
33826 
33827   Description []
33828 
33829   SideEffects []
33830 
33831   SeeAlso     []
33832 
33833 ***********************************************************************/
Abc_CommandAbc9Frames(Abc_Frame_t * pAbc,int argc,char ** argv)33834 int Abc_CommandAbc9Frames( Abc_Frame_t * pAbc, int argc, char ** argv )
33835 {
33836     extern Gia_Man_t * Gia_ManFrames2( Gia_Man_t * pAig, Gia_ParFra_t * pPars );
33837 
33838     Gia_Man_t * pTemp;
33839     Gia_ParFra_t Pars, * pPars = &Pars;
33840     int c;
33841     int nCofFanLit = 0;
33842     int fNewAlgo = 0;
33843     int fInitSpecial = 0;
33844     Gia_ManFraSetDefaultParams( pPars );
33845     Extra_UtilGetoptReset();
33846     while ( ( c = Extra_UtilGetopt( argc, argv, "FLsoibavh" ) ) != EOF )
33847     {
33848         switch ( c )
33849         {
33850         case 'F':
33851             if ( globalUtilOptind >= argc )
33852             {
33853                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
33854                 goto usage;
33855             }
33856             pPars->nFrames = atoi(argv[globalUtilOptind]);
33857             globalUtilOptind++;
33858             if ( pPars->nFrames < 0 )
33859                 goto usage;
33860             break;
33861         case 'L':
33862             if ( globalUtilOptind >= argc )
33863             {
33864                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
33865                 goto usage;
33866             }
33867             nCofFanLit = atoi(argv[globalUtilOptind]);
33868             globalUtilOptind++;
33869             if ( nCofFanLit < 0 )
33870                 goto usage;
33871             break;
33872         case 's':
33873             pPars->fDisableSt ^= 1;
33874             break;
33875         case 'o':
33876             pPars->fOrPos ^= 1;
33877             break;
33878         case 'i':
33879             pPars->fInit ^= 1;
33880             break;
33881         case 'b':
33882             fInitSpecial ^= 1;
33883             break;
33884         case 'a':
33885             fNewAlgo ^= 1;
33886             break;
33887         case 'v':
33888             pPars->fVerbose ^= 1;
33889             break;
33890         case 'h':
33891             goto usage;
33892         default:
33893             goto usage;
33894         }
33895     }
33896     if ( pAbc->pGia == NULL )
33897     {
33898         Abc_Print( -1, "Abc_CommandAbc9Frames(): There is no AIG.\n" );
33899         return 1;
33900     }
33901     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
33902     {
33903         Abc_Print( -1, "The network is combinational.\n" );
33904         return 0;
33905     }
33906     if ( fInitSpecial )
33907         pTemp = Gia_ManFramesInitSpecial( pAbc->pGia, pPars->nFrames, pPars->fVerbose );
33908     else if ( nCofFanLit )
33909         pTemp = Gia_ManUnrollAndCofactor( pAbc->pGia, pPars->nFrames, nCofFanLit, pPars->fVerbose );
33910     else if ( fNewAlgo )
33911         pTemp = Gia_ManFrames2( pAbc->pGia, pPars );
33912     else
33913         pTemp = Gia_ManFrames( pAbc->pGia, pPars );
33914     Abc_FrameUpdateGia( pAbc, pTemp );
33915     return 0;
33916 
33917 usage:
33918     Abc_Print( -2, "usage: &frames [-FL <num>] [-soibavh]\n" );
33919     Abc_Print( -2, "\t         unrolls the design for several timeframes\n" );
33920     Abc_Print( -2, "\t-F num : the number of frames to unroll [default = %d]\n", pPars->nFrames );
33921     Abc_Print( -2, "\t-L num : the limit on fanout count of resets/enables to cofactor [default = %d]\n", nCofFanLit );
33922     Abc_Print( -2, "\t-s     : toggle disabling structural hashing [default = %s]\n", pPars->fDisableSt? "yes": "no" );
33923     Abc_Print( -2, "\t-o     : toggle ORing corresponding POs [default = %s]\n", pPars->fOrPos? "yes": "no" );
33924     Abc_Print( -2, "\t-i     : toggle initializing registers [default = %s]\n", pPars->fInit? "yes": "no" );
33925     Abc_Print( -2, "\t-b     : toggle computing special AIG for BMC [default = %s]\n", fInitSpecial? "yes": "no" );
33926     Abc_Print( -2, "\t-a     : toggle using new algorithm [default = %s]\n", fNewAlgo? "yes": "no" );
33927     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
33928     Abc_Print( -2, "\t-h     : print the command usage\n");
33929     return 1;
33930 }
33931 
33932 /**Function*************************************************************
33933 
33934   Synopsis    []
33935 
33936   Description []
33937 
33938   SideEffects []
33939 
33940   SeeAlso     []
33941 
33942 ***********************************************************************/
Abc_CommandAbc9Retime(Abc_Frame_t * pAbc,int argc,char ** argv)33943 int Abc_CommandAbc9Retime( Abc_Frame_t * pAbc, int argc, char ** argv )
33944 {
33945     Gia_Man_t * pTemp;
33946     int c;
33947     int nMaxIters = 100;
33948     int fVerbose  =   0;
33949     Extra_UtilGetoptReset();
33950     while ( ( c = Extra_UtilGetopt( argc, argv, "Nvh" ) ) != EOF )
33951     {
33952         switch ( c )
33953         {
33954         case 'N':
33955             if ( globalUtilOptind >= argc )
33956             {
33957                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
33958                 goto usage;
33959             }
33960             nMaxIters = atoi(argv[globalUtilOptind]);
33961             globalUtilOptind++;
33962             if ( nMaxIters < 0 )
33963                 goto usage;
33964             break;
33965         case 'v':
33966             fVerbose ^= 1;
33967             break;
33968         case 'h':
33969             goto usage;
33970         default:
33971             goto usage;
33972         }
33973     }
33974     if ( pAbc->pGia == NULL )
33975     {
33976         Abc_Print( -1, "Abc_CommandAbc9Retime(): There is no AIG.\n" );
33977         return 1;
33978     }
33979     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
33980     {
33981         Abc_Print( -1, "The network is combinational.\n" );
33982         return 0;
33983     }
33984     pTemp = Gia_ManRetimeForward( pAbc->pGia, nMaxIters, fVerbose );
33985     Abc_FrameUpdateGia( pAbc, pTemp );
33986     return 0;
33987 
33988 usage:
33989     Abc_Print( -2, "usage: &retime [-N <num>] [-vh]\n" );
33990     Abc_Print( -2, "\t         performs most-forward retiming\n" );
33991     Abc_Print( -2, "\t-N num : the number of incremental iterations [default = %d]\n", nMaxIters );
33992     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
33993     Abc_Print( -2, "\t-h     : print the command usage\n");
33994     return 1;
33995 }
33996 
33997 /**Function*************************************************************
33998 
33999   Synopsis    []
34000 
34001   Description []
34002 
34003   SideEffects []
34004 
34005   SeeAlso     []
34006 
34007 ***********************************************************************/
Abc_CommandAbc9Enable(Abc_Frame_t * pAbc,int argc,char ** argv)34008 int Abc_CommandAbc9Enable( Abc_Frame_t * pAbc, int argc, char ** argv )
34009 {
34010     Gia_Man_t * pTemp;
34011     int c;
34012     int fRemove  = 0;
34013     int fVerbose = 0;
34014     Extra_UtilGetoptReset();
34015     while ( ( c = Extra_UtilGetopt( argc, argv, "rvh" ) ) != EOF )
34016     {
34017         switch ( c )
34018         {
34019         case 'r':
34020             fRemove ^= 1;
34021             break;
34022         case 'v':
34023             fVerbose ^= 1;
34024             break;
34025         case 'h':
34026             goto usage;
34027         default:
34028             goto usage;
34029         }
34030     }
34031     if ( pAbc->pGia == NULL )
34032     {
34033         Abc_Print( -1, "Abc_CommandAbc9Enable(): There is no AIG.\n" );
34034         return 1;
34035     }
34036     if ( fRemove )
34037         pTemp = Gia_ManRemoveEnables( pAbc->pGia );
34038     else
34039         pTemp = Gia_ManDupSelf( pAbc->pGia );
34040     Abc_FrameUpdateGia( pAbc, pTemp );
34041     return 0;
34042 
34043 usage:
34044     Abc_Print( -2, "usage: &enable [-rvh]\n" );
34045     Abc_Print( -2, "\t         adds or removes flop enable signals\n" );
34046     Abc_Print( -2, "\t-r     : toggle adding vs. removing enables [default = %s]\n", fRemove? "remove": "add" );
34047     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
34048     Abc_Print( -2, "\t-h     : print the command usage\n");
34049     return 1;
34050 }
34051 
34052 /**Function*************************************************************
34053 
34054   Synopsis    []
34055 
34056   Description []
34057 
34058   SideEffects []
34059 
34060   SeeAlso     []
34061 
34062 ***********************************************************************/
Abc_CommandAbc9Dc2(Abc_Frame_t * pAbc,int argc,char ** argv)34063 int Abc_CommandAbc9Dc2( Abc_Frame_t * pAbc, int argc, char ** argv )
34064 {
34065     Gia_Man_t * pTemp;
34066     int c, fVerbose = 0;
34067     int fUpdateLevel = 1;
34068     Extra_UtilGetoptReset();
34069     while ( ( c = Extra_UtilGetopt( argc, argv, "lvh" ) ) != EOF )
34070     {
34071         switch ( c )
34072         {
34073         case 'l':
34074             fUpdateLevel ^= 1;
34075             break;
34076         case 'v':
34077             fVerbose ^= 1;
34078             break;
34079         case 'h':
34080             goto usage;
34081         default:
34082             goto usage;
34083         }
34084     }
34085     if ( pAbc->pGia == NULL )
34086     {
34087         Abc_Print( -1, "Abc_CommandAbc9Dc2(): There is no AIG.\n" );
34088         return 1;
34089     }
34090     pTemp = Gia_ManCompress2( pAbc->pGia, fUpdateLevel, fVerbose );
34091     Abc_FrameUpdateGia( pAbc, pTemp );
34092     return 0;
34093 
34094 usage:
34095     Abc_Print( -2, "usage: &dc2 [-lvh]\n" );
34096     Abc_Print( -2, "\t         performs heavy rewriting of the AIG\n" );
34097     Abc_Print( -2, "\t-l     : toggle level update during rewriting [default = %s]\n", fUpdateLevel? "yes": "no" );
34098     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
34099     Abc_Print( -2, "\t-h     : print the command usage\n");
34100     return 1;
34101 }
34102 
34103 /**Function*************************************************************
34104 
34105   Synopsis    []
34106 
34107   Description []
34108 
34109   SideEffects []
34110 
34111   SeeAlso     []
34112 
34113 ***********************************************************************/
Abc_CommandAbc9Dsd(Abc_Frame_t * pAbc,int argc,char ** argv)34114 int Abc_CommandAbc9Dsd( Abc_Frame_t * pAbc, int argc, char ** argv )
34115 {
34116     extern Gia_Man_t * Gia_ManCollapseTest( Gia_Man_t * p, int fVerbose );
34117     Gia_Man_t * pTemp;
34118     int c, fVerbose = 0;
34119     int fUpdateLevel = 1;
34120     Extra_UtilGetoptReset();
34121     while ( ( c = Extra_UtilGetopt( argc, argv, "lvh" ) ) != EOF )
34122     {
34123         switch ( c )
34124         {
34125         case 'l':
34126             fUpdateLevel ^= 1;
34127             break;
34128         case 'v':
34129             fVerbose ^= 1;
34130             break;
34131         case 'h':
34132             goto usage;
34133         default:
34134             goto usage;
34135         }
34136     }
34137     if ( pAbc->pGia == NULL )
34138     {
34139         Abc_Print( -1, "Abc_CommandAbc9Dsd(): There is no AIG.\n" );
34140         return 1;
34141     }
34142     pTemp = Gia_ManCollapseTest( pAbc->pGia, fVerbose );
34143     Abc_FrameUpdateGia( pAbc, pTemp );
34144     return 0;
34145 
34146 usage:
34147     Abc_Print( -2, "usage: &dsd [-vh]\n" );
34148     Abc_Print( -2, "\t         performs DSD-based collapsing\n" );
34149 //    Abc_Print( -2, "\t-l     : toggle level update during rewriting [default = %s]\n", fUpdateLevel? "yes": "no" );
34150     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
34151     Abc_Print( -2, "\t-h     : print the command usage\n");
34152     return 1;
34153 }
34154 
34155 /**Function*************************************************************
34156 
34157   Synopsis    []
34158 
34159   Description []
34160 
34161   SideEffects []
34162 
34163   SeeAlso     []
34164 
34165 ***********************************************************************/
Abc_CommandAbc9Bidec(Abc_Frame_t * pAbc,int argc,char ** argv)34166 int Abc_CommandAbc9Bidec( Abc_Frame_t * pAbc, int argc, char ** argv )
34167 {
34168     Gia_Man_t * pTemp;
34169     int c, fVerbose = 0;
34170     int fUpdateLevel = 1;
34171     Extra_UtilGetoptReset();
34172     while ( ( c = Extra_UtilGetopt( argc, argv, "lvh" ) ) != EOF )
34173     {
34174         switch ( c )
34175         {
34176         case 'l':
34177             fUpdateLevel ^= 1;
34178             break;
34179         case 'v':
34180             fVerbose ^= 1;
34181             break;
34182         case 'h':
34183             goto usage;
34184         default:
34185             goto usage;
34186         }
34187     }
34188     if ( pAbc->pGia == NULL )
34189     {
34190         Abc_Print( -1, "Abc_CommandAbc9Bidec(): There is no AIG.\n" );
34191         return 1;
34192     }
34193     if ( !Gia_ManHasMapping(pAbc->pGia) )
34194     {
34195         Abc_Print( -1, "Abc_CommandAbc9Bidec(): Mapping of the AIG is not defined.\n" );
34196         return 1;
34197     }
34198     pTemp = Gia_ManPerformBidec( pAbc->pGia, fVerbose );
34199     Abc_FrameUpdateGia( pAbc, pTemp );
34200     return 0;
34201 
34202 usage:
34203     Abc_Print( -2, "usage: &bidec [-vh]\n" );
34204     Abc_Print( -2, "\t         performs heavy rewriting of the AIG\n" );
34205 //    Abc_Print( -2, "\t-l     : toggle level update during rewriting [default = %s]\n", fUpdateLevel? "yes": "no" );
34206     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
34207     Abc_Print( -2, "\t-h     : print the command usage\n");
34208     return 1;
34209 }
34210 
34211 /**Function*************************************************************
34212 
34213   Synopsis    []
34214 
34215   Description []
34216 
34217   SideEffects []
34218 
34219   SeeAlso     []
34220 
34221 ***********************************************************************/
Abc_CommandAbc9Shrink(Abc_Frame_t * pAbc,int argc,char ** argv)34222 int Abc_CommandAbc9Shrink( Abc_Frame_t * pAbc, int argc, char ** argv )
34223 {
34224     Gia_Man_t * pTemp = NULL;
34225     int nLutSize;
34226     int c,fVerbose = 0;
34227     int fKeepLevel = 0;
34228     int nFanoutMax = 50;
34229     Extra_UtilGetoptReset();
34230     while ( ( c = Extra_UtilGetopt( argc, argv, "Nlvh" ) ) != EOF )
34231     {
34232         switch ( c )
34233         {
34234         case 'N':
34235             if ( globalUtilOptind >= argc )
34236             {
34237                 Abc_Print( -1, "Command line switch \"-N\" should be followed by a char string.\n" );
34238                 goto usage;
34239             }
34240             nFanoutMax = atoi(argv[globalUtilOptind]);
34241             globalUtilOptind++;
34242             if ( nFanoutMax < 0 )
34243                 goto usage;
34244             break;
34245         case 'l':
34246             fKeepLevel ^= 1;
34247             break;
34248         case 'v':
34249             fVerbose ^= 1;
34250             break;
34251         case 'h':
34252             goto usage;
34253         default:
34254             goto usage;
34255         }
34256     }
34257     if ( pAbc->pGia == NULL )
34258     {
34259         Abc_Print( -1, "Abc_CommandAbc9Shrink(): There is no AIG.\n" );
34260         return 1;
34261     }
34262     if ( !Gia_ManHasMapping(pAbc->pGia) )
34263     {
34264         Abc_Print( -1, "Abc_CommandAbc9Shrink(): Mapping of the AIG is not defined.\n" );
34265         return 1;
34266     }
34267     nLutSize = Gia_ManLutSizeMax( pAbc->pGia );
34268     if ( nLutSize <= 4 )
34269         pTemp = Gia_ManMapShrink4( pAbc->pGia, fKeepLevel, fVerbose );
34270     else if ( nLutSize <= 6 )
34271         pTemp = Gia_ManMapShrink6( pAbc->pGia, nFanoutMax, fKeepLevel, fVerbose );
34272     else
34273         Abc_Print( -1, "Abc_CommandAbc9Shrink(): Works only for 4-LUTs and 6-LUTs.\n" );
34274     if ( pTemp )
34275         Abc_FrameUpdateGia( pAbc, pTemp );
34276     return 0;
34277 
34278 usage:
34279     Abc_Print( -2, "usage: &shrink [-N num] [-lvh]\n" );
34280     Abc_Print( -2, "\t         performs fast shrinking using current mapping\n" );
34281     Abc_Print( -2, "\t-N num : the max fanout count to skip a divisor [default = %d]\n", nFanoutMax );
34282     Abc_Print( -2, "\t-l     : toggle level update during shrinking [default = %s]\n", fKeepLevel? "yes": "no" );
34283     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
34284     Abc_Print( -2, "\t-h     : print the command usage\n");
34285     return 1;
34286 }
34287 
34288 /**Function*************************************************************
34289 
34290   Synopsis    []
34291 
34292   Description []
34293 
34294   SideEffects []
34295 
34296   SeeAlso     []
34297 
34298 ***********************************************************************/
Abc_CommandAbc9Fx(Abc_Frame_t * pAbc,int argc,char ** argv)34299 int Abc_CommandAbc9Fx( Abc_Frame_t * pAbc, int argc, char ** argv )
34300 {
34301     Gia_Man_t * pTemp;
34302     int nNewNodesMax = 1000000;
34303     int LitCountMax  =       0;
34304     int fReverse     =       0;
34305     int c, fVerbose  =       0;
34306     int fVeryVerbose =       0;
34307     // set the defaults
34308     Extra_UtilGetoptReset();
34309     while ( (c = Extra_UtilGetopt(argc, argv, "NMrvwh")) != EOF )
34310     {
34311         switch (c)
34312         {
34313             case 'N':
34314                 if ( globalUtilOptind >= argc )
34315                 {
34316                     Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
34317                     goto usage;
34318                 }
34319                 nNewNodesMax = atoi(argv[globalUtilOptind]);
34320                 globalUtilOptind++;
34321                 if ( nNewNodesMax < 0 )
34322                     goto usage;
34323                 break;
34324             case 'M':
34325                 if ( globalUtilOptind >= argc )
34326                 {
34327                     Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
34328                     goto usage;
34329                 }
34330                 LitCountMax = atoi(argv[globalUtilOptind]);
34331                 globalUtilOptind++;
34332                 if ( LitCountMax < 0 )
34333                     goto usage;
34334                 break;
34335             case 'r':
34336                 fReverse ^= 1;
34337                 break;
34338             case 'v':
34339                 fVerbose ^= 1;
34340                 break;
34341             case 'w':
34342                 fVeryVerbose ^= 1;
34343                 break;
34344             case 'h':
34345                 goto usage;
34346                 break;
34347             default:
34348                 goto usage;
34349         }
34350     }
34351     if ( pAbc->pGia == NULL )
34352     {
34353         Abc_Print( -1, "Abc_CommandAbc9Shrink(): There is no AIG.\n" );
34354         return 1;
34355     }
34356     if ( !Gia_ManHasMapping(pAbc->pGia) )
34357     {
34358         Abc_Print( -1, "Abc_CommandAbc9Shrink(): Mapping of the AIG is not defined.\n" );
34359         return 1;
34360     }
34361     pTemp = Gia_ManPerformFx( pAbc->pGia, nNewNodesMax, LitCountMax, fReverse, fVerbose, fVeryVerbose );
34362     if ( pTemp != NULL )
34363         Abc_FrameUpdateGia( pAbc, pTemp );
34364     else
34365         Abc_Print( -1, "Abc_CommandAbc9Fx(): Command has failed.\n" );
34366     return 0;
34367 
34368 usage:
34369     Abc_Print( -2, "usage: &fx [-NM <num>] [-vh]\n");
34370     Abc_Print( -2, "\t           extract shared logic using the classical \"fast_extract\" algorithm\n");
34371     Abc_Print( -2, "\t-N <num> : max number of divisors to extract during this run [default = %d]\n", nNewNodesMax );
34372     Abc_Print( -2, "\t-M <num> : upper bound on literal count of divisors to extract [default = %d]\n", LitCountMax );
34373     Abc_Print( -2, "\t-r       : reversing variable order during ISOP computation [default = %s]\n", fReverse? "yes": "no" );
34374     Abc_Print( -2, "\t-v       : print verbose information [default = %s]\n", fVerbose? "yes": "no" );
34375     Abc_Print( -2, "\t-w       : toggle printing additional information [default = %s]\n", fVeryVerbose? "yes": "no" );
34376     Abc_Print( -2, "\t-h       : print the command usage\n");
34377     return 1;
34378 }
34379 
34380 /**Function*************************************************************
34381 
34382   Synopsis    []
34383 
34384   Description []
34385 
34386   SideEffects []
34387 
34388   SeeAlso     []
34389 
34390 ***********************************************************************/
Abc_CommandAbc9Balance(Abc_Frame_t * pAbc,int argc,char ** argv)34391 int Abc_CommandAbc9Balance( Abc_Frame_t * pAbc, int argc, char ** argv )
34392 {
34393     Gia_Man_t * pTemp = NULL;
34394     int nNewNodesMax = ABC_INFINITY;
34395     int fDelayOnly   = 0;
34396     int fSimpleAnd   = 0;
34397     int fStrict      = 0;
34398     int fKeepLevel   = 0;
34399     int c, fVerbose  = 0;
34400     int fVeryVerbose = 0;
34401     Extra_UtilGetoptReset();
34402     while ( ( c = Extra_UtilGetopt( argc, argv, "Ndaslvwh" ) ) != EOF )
34403     {
34404         switch ( c )
34405         {
34406         case 'N':
34407             if ( globalUtilOptind >= argc )
34408             {
34409                 Abc_Print( -1, "Command line switch \"-N\" should be followed by a char string.\n" );
34410                 goto usage;
34411             }
34412             nNewNodesMax = atoi(argv[globalUtilOptind]);
34413             globalUtilOptind++;
34414             if ( nNewNodesMax < 0 )
34415                 goto usage;
34416             break;
34417         case 'd':
34418             fDelayOnly ^= 1;
34419             break;
34420         case 'a':
34421             fSimpleAnd ^= 1;
34422             break;
34423         case 's':
34424             fStrict ^= 1;
34425             break;
34426         case 'l':
34427             fKeepLevel ^= 1;
34428             break;
34429         case 'v':
34430             fVerbose ^= 1;
34431             break;
34432         case 'w':
34433             fVeryVerbose ^= 1;
34434             break;
34435         case 'h':
34436             goto usage;
34437         default:
34438             goto usage;
34439         }
34440     }
34441     if ( pAbc->pGia == NULL )
34442     {
34443         Abc_Print( -1, "Abc_CommandAbc9Balance(): There is no AIG.\n" );
34444         return 1;
34445     }
34446     if ( fDelayOnly )
34447         pTemp = Gia_ManBalance( pAbc->pGia, fSimpleAnd, fStrict, fVerbose );
34448     else
34449         pTemp = Gia_ManAreaBalance( pAbc->pGia, fSimpleAnd, nNewNodesMax, fVerbose, fVeryVerbose );
34450     Abc_FrameUpdateGia( pAbc, pTemp );
34451     return 0;
34452 
34453 usage:
34454     Abc_Print( -2, "usage: &b [-N num] [-dasvwh]\n" );
34455     Abc_Print( -2, "\t         performs AIG balancing to reduce delay and area\n" );
34456     Abc_Print( -2, "\t-N num : the max fanout count to skip a divisor [default = %d]\n", nNewNodesMax );
34457     Abc_Print( -2, "\t-d     : toggle delay only balancing [default = %s]\n", fDelayOnly? "yes": "no" );
34458     Abc_Print( -2, "\t-a     : toggle using AND instead of AND/XOR/MUX [default = %s]\n", fSimpleAnd? "yes": "no" );
34459     Abc_Print( -2, "\t-s     : toggle strict control of area in delay-mode (\"&b -d\") [default = %s]\n", fStrict? "yes": "no" );
34460     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
34461     Abc_Print( -2, "\t-w     : toggle printing additional information [default = %s]\n", fVeryVerbose? "yes": "no" );
34462     Abc_Print( -2, "\t-h     : print the command usage\n");
34463     return 1;
34464 }
34465 
34466 /**Function*************************************************************
34467 
34468   Synopsis    []
34469 
34470   Description []
34471 
34472   SideEffects []
34473 
34474   SeeAlso     []
34475 
34476 ***********************************************************************/
Abc_CommandAbc9BalanceLut(Abc_Frame_t * pAbc,int argc,char ** argv)34477 int Abc_CommandAbc9BalanceLut( Abc_Frame_t * pAbc, int argc, char ** argv )
34478 {
34479     extern Gia_Man_t * Gia_ManBalanceLut( Gia_Man_t * p, int nLutSize, int nCutNum, int fVerbose );
34480     extern Gia_Man_t * Gia_ManLutBalance( Gia_Man_t * p, int nLutSize, int fUseMuxes, int fRecursive, int fOptArea, int fVerbose );
34481     Gia_Man_t * pTemp = NULL;
34482     int fUseOld      = 0;
34483     int nLutSize     = 6;
34484     int nCutNum      = 8;
34485     int fUseMuxes    = 1;
34486     int fRecursive   = 1;
34487     int fOptArea     = 1;
34488     int c, fVerbose  = 0;
34489     int fVeryVerbose = 0;
34490     Extra_UtilGetoptReset();
34491     while ( ( c = Extra_UtilGetopt( argc, argv, "KCnmravwh" ) ) != EOF )
34492     {
34493         switch ( c )
34494         {
34495         case 'K':
34496             if ( globalUtilOptind >= argc )
34497             {
34498                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a char string.\n" );
34499                 goto usage;
34500             }
34501             nLutSize = atoi(argv[globalUtilOptind]);
34502             globalUtilOptind++;
34503             if ( nLutSize < 0 )
34504                 goto usage;
34505             break;
34506         case 'C':
34507             if ( globalUtilOptind >= argc )
34508             {
34509                 Abc_Print( -1, "Command line switch \"-C\" should be followed by a char string.\n" );
34510                 goto usage;
34511             }
34512             nCutNum = atoi(argv[globalUtilOptind]);
34513             globalUtilOptind++;
34514             if ( nCutNum < 0 )
34515                 goto usage;
34516             break;
34517         case 'n':
34518             fUseOld ^= 1;
34519             break;
34520         case 'm':
34521             fUseMuxes ^= 1;
34522             break;
34523         case 'r':
34524             fRecursive ^= 1;
34525             break;
34526         case 'a':
34527             fOptArea ^= 1;
34528             break;
34529         case 'v':
34530             fVerbose ^= 1;
34531             break;
34532         case 'w':
34533             fVeryVerbose ^= 1;
34534             break;
34535         case 'h':
34536             goto usage;
34537         default:
34538             goto usage;
34539         }
34540     }
34541     if ( pAbc->pGia == NULL )
34542     {
34543         Abc_Print( -1, "Abc_CommandAbc9BalanceLut(): There is no AIG.\n" );
34544         return 1;
34545     }
34546     if ( fUseOld )
34547         pTemp = Gia_ManBalanceLut( pAbc->pGia, nLutSize, nCutNum, fVerbose );
34548     else
34549         pTemp = Gia_ManLutBalance( pAbc->pGia, nLutSize, fUseMuxes, fRecursive, fOptArea, fVerbose );
34550     Abc_FrameUpdateGia( pAbc, pTemp );
34551     return 0;
34552 
34553 usage:
34554     Abc_Print( -2, "usage: &blut [-KC num] [-mravh]\n" );
34555     Abc_Print( -2, "\t           performs AIG balancing for the given LUT size\n" );
34556     Abc_Print( -2, "\t-K num   : LUT size for the mapping (2 <= K <= %d) [default = %d]\n", 6, nLutSize );
34557     Abc_Print( -2, "\t-C num   : the max number of priority cuts (1 <= C <= %d) [default = %d]\n", 8, nCutNum );
34558     Abc_Print( -2, "\t-m       : toggle performing MUX restructuring [default = %s]\n", fUseMuxes? "yes": "no" );
34559     Abc_Print( -2, "\t-r       : toggle performing recursive restructuring [default = %s]\n", fRecursive? "yes": "no" );
34560     Abc_Print( -2, "\t-a       : toggle performing area-oriented restructuring [default = %s]\n", fOptArea? "yes": "no" );
34561     Abc_Print( -2, "\t-v       : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
34562 //    Abc_Print( -2, "\t-w       : toggle printing additional information [default = %s]\n", fVeryVerbose? "yes": "no" );
34563     Abc_Print( -2, "\t-h       : print the command usage\n");
34564     return 1;
34565 }
34566 
34567 /**Function*************************************************************
34568 
34569   Synopsis    []
34570 
34571   Description []
34572 
34573   SideEffects []
34574 
34575   SeeAlso     []
34576 
34577 ***********************************************************************/
Abc_CommandAbc9Syn2(Abc_Frame_t * pAbc,int argc,char ** argv)34578 int Abc_CommandAbc9Syn2( Abc_Frame_t * pAbc, int argc, char ** argv )
34579 {
34580     Gia_Man_t * pTemp;
34581     int c, fVerbose  =  0;
34582     int fOldAlgo     =  0;
34583     int fCoarsen     =  1;
34584     int fCutMin      =  0;
34585     int nRelaxRatio  = 20;
34586     int fDelayMin    =  0;
34587     int fVeryVerbose =  0;
34588     Extra_UtilGetoptReset();
34589     while ( ( c = Extra_UtilGetopt( argc, argv, "Rakmdvwh" ) ) != EOF )
34590     {
34591         switch ( c )
34592         {
34593         case 'R':
34594             if ( globalUtilOptind >= argc )
34595             {
34596                 Abc_Print( 1, "Command line switch \"-R\" should be followed by a floating point number.\n" );
34597                 return 0;
34598             }
34599             nRelaxRatio = atoi(argv[globalUtilOptind]);
34600             globalUtilOptind++;
34601             if ( nRelaxRatio < 0 )
34602                 goto usage;
34603             break;
34604         case 'a':
34605             fOldAlgo ^= 1;
34606             break;
34607         case 'k':
34608             fCoarsen ^= 1;
34609             break;
34610         case 'm':
34611             fCutMin ^= 1;
34612             break;
34613         case 'd':
34614             fDelayMin ^= 1;
34615             break;
34616         case 'v':
34617             fVerbose ^= 1;
34618             break;
34619         case 'w':
34620             fVeryVerbose ^= 1;
34621             break;
34622         case 'h':
34623             goto usage;
34624         default:
34625             goto usage;
34626         }
34627     }
34628     if ( pAbc->pGia == NULL )
34629     {
34630         Abc_Print( -1, "Abc_CommandAbc9Syn2(): There is no AIG.\n" );
34631         return 1;
34632     }
34633     if ( fDelayMin )
34634     {
34635         If_DsdMan_t * p = (If_DsdMan_t *)Abc_FrameReadManDsd();
34636         if ( p && If_DsdManVarNum(p) < 6 )
34637         {
34638             printf( "DSD manager has incompatible number of variables. Delay minimization is not performed.\n" );
34639             fDelayMin = 0;
34640         }
34641     }
34642     pTemp = Gia_ManAigSyn2( pAbc->pGia, fOldAlgo, fCoarsen, fCutMin, nRelaxRatio, fDelayMin, fVerbose, fVeryVerbose );
34643     Abc_FrameUpdateGia( pAbc, pTemp );
34644     return 0;
34645 
34646 usage:
34647     Abc_Print( -2, "usage: &syn2 [-R num] [-akmdvh]\n" );
34648     Abc_Print( -2, "\t           performs AIG optimization\n" );
34649     Abc_Print( -2, "\t-R num   : the delay relaxation ratio (num >= 0) [default = %d]\n",   nRelaxRatio );
34650     Abc_Print( -2, "\t-a       : toggles using the old algorithm [default = %s]\n",         fOldAlgo? "yes": "no" );
34651     Abc_Print( -2, "\t-k       : toggles coarsening the subject graph [default = %s]\n",    fCoarsen? "yes": "no" );
34652     Abc_Print( -2, "\t-m       : toggles cut minimization [default = %s]\n",                fCutMin? "yes": "no" );
34653     Abc_Print( -2, "\t-d       : toggles additional delay optimization [default = %s]\n",   fDelayMin? "yes": "no" );
34654     Abc_Print( -2, "\t-v       : toggles printing verbose information [default = %s]\n",    fVerbose? "yes": "no" );
34655     Abc_Print( -2, "\t-w       : toggles printing additional information [default = %s]\n", fVeryVerbose? "yes": "no" );
34656     Abc_Print( -2, "\t-h       : print the command usage\n");
34657     return 1;
34658 }
34659 
34660 /**Function*************************************************************
34661 
34662   Synopsis    []
34663 
34664   Description []
34665 
34666   SideEffects []
34667 
34668   SeeAlso     []
34669 
34670 ***********************************************************************/
Abc_CommandAbc9Synch2(Abc_Frame_t * pAbc,int argc,char ** argv)34671 int Abc_CommandAbc9Synch2( Abc_Frame_t * pAbc, int argc, char ** argv )
34672 {
34673     extern Gia_Man_t * Gia_ManAigSynch2( Gia_Man_t * p, void * pPars, int nLutSize, int nRelaxRatio );
34674     Gia_Man_t * pTemp;
34675     Dch_Pars_t Pars, * pPars = &Pars;
34676     int c, nLutSize = 6;
34677     int nRelaxRatio = 20;
34678     // set defaults
34679     Dch_ManSetDefaultParams( pPars );
34680     pPars->nBTLimit = 100;
34681     Extra_UtilGetoptReset();
34682     while ( ( c = Extra_UtilGetopt( argc, argv, "WCSKRfrvh" ) ) != EOF )
34683     {
34684         switch ( c )
34685         {
34686         case 'W':
34687             if ( globalUtilOptind >= argc )
34688             {
34689                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
34690                 goto usage;
34691             }
34692             pPars->nWords = atoi(argv[globalUtilOptind]);
34693             globalUtilOptind++;
34694             if ( pPars->nWords < 0 )
34695                 goto usage;
34696             break;
34697         case 'C':
34698             if ( globalUtilOptind >= argc )
34699             {
34700                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
34701                 goto usage;
34702             }
34703             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
34704             globalUtilOptind++;
34705             if ( pPars->nBTLimit < 0 )
34706                 goto usage;
34707             break;
34708         case 'S':
34709             if ( globalUtilOptind >= argc )
34710             {
34711                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
34712                 goto usage;
34713             }
34714             pPars->nSatVarMax = atoi(argv[globalUtilOptind]);
34715             globalUtilOptind++;
34716             if ( pPars->nSatVarMax < 0 )
34717                 goto usage;
34718             break;
34719         case 'K':
34720             if ( globalUtilOptind >= argc )
34721             {
34722                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a char string.\n" );
34723                 goto usage;
34724             }
34725             nLutSize = atoi(argv[globalUtilOptind]);
34726             globalUtilOptind++;
34727             if ( nLutSize < 0 )
34728                 goto usage;
34729             break;
34730         case 'R':
34731             if ( globalUtilOptind >= argc )
34732             {
34733                 Abc_Print( 1, "Command line switch \"-R\" should be followed by a floating point number.\n" );
34734                 return 0;
34735             }
34736             nRelaxRatio = atoi(argv[globalUtilOptind]);
34737             globalUtilOptind++;
34738             if ( nRelaxRatio < 0 )
34739                 goto usage;
34740             break;
34741         case 'f':
34742             pPars->fLightSynth ^= 1;
34743             break;
34744         case 'r':
34745             pPars->fSkipRedSupp ^= 1;
34746             break;
34747         case 'v':
34748             pPars->fVerbose ^= 1;
34749             break;
34750         case 'h':
34751             goto usage;
34752         default:
34753             goto usage;
34754         }
34755     }
34756     if ( pAbc->pGia == NULL )
34757     {
34758         Abc_Print( -1, "Abc_CommandAbc9Dch(): There is no AIG.\n" );
34759         return 1;
34760     }
34761     pTemp = Gia_ManAigSynch2( pAbc->pGia, pPars, nLutSize, nRelaxRatio );
34762     Abc_FrameUpdateGia( pAbc, pTemp );
34763     return 0;
34764 
34765 usage:
34766     Abc_Print( -2, "usage: &synch2 [-WCSKR num] [-frvh]\n" );
34767     Abc_Print( -2, "\t         computes structural choices using a new approach\n" );
34768     Abc_Print( -2, "\t-W num : the max number of simulation words [default = %d]\n", pPars->nWords );
34769     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", pPars->nBTLimit );
34770     Abc_Print( -2, "\t-S num : the max number of SAT variables [default = %d]\n", pPars->nSatVarMax );
34771     Abc_Print( -2, "\t-K num : the target LUT size for downstream mapping [default = %d]\n", nLutSize );
34772     Abc_Print( -2, "\t-R num : the delay relaxation ratio (num >= 0) [default = %d]\n",   nRelaxRatio );
34773     Abc_Print( -2, "\t-f     : toggle using lighter logic synthesis [default = %s]\n", pPars->fLightSynth? "yes": "no" );
34774     Abc_Print( -2, "\t-r     : toggle skipping choices with redundant support [default = %s]\n", pPars->fSkipRedSupp? "yes": "no" );
34775     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", pPars->fVerbose? "yes": "no" );
34776     Abc_Print( -2, "\t-h     : print the command usage\n");
34777     return 1;
34778 }
34779 
34780 /**Function*************************************************************
34781 
34782   Synopsis    []
34783 
34784   Description []
34785 
34786   SideEffects []
34787 
34788   SeeAlso     []
34789 
34790 ***********************************************************************/
Abc_CommandAbc9Syn3(Abc_Frame_t * pAbc,int argc,char ** argv)34791 int Abc_CommandAbc9Syn3( Abc_Frame_t * pAbc, int argc, char ** argv )
34792 {
34793     Gia_Man_t * pTemp;
34794     int c, fVerbose = 0;
34795     int fVeryVerbose = 0;
34796     Extra_UtilGetoptReset();
34797     while ( ( c = Extra_UtilGetopt( argc, argv, "vwh" ) ) != EOF )
34798     {
34799         switch ( c )
34800         {
34801         case 'v':
34802             fVerbose ^= 1;
34803             break;
34804         case 'w':
34805             fVeryVerbose ^= 1;
34806             break;
34807         case 'h':
34808             goto usage;
34809         default:
34810             goto usage;
34811         }
34812     }
34813     if ( pAbc->pGia == NULL )
34814     {
34815         Abc_Print( -1, "Abc_CommandAbc9Syn3(): There is no AIG.\n" );
34816         return 1;
34817     }
34818     pTemp = Gia_ManAigSyn3( pAbc->pGia, fVerbose, fVeryVerbose );
34819     Abc_FrameUpdateGia( pAbc, pTemp );
34820     return 0;
34821 
34822 usage:
34823     Abc_Print( -2, "usage: &syn3 [-lvh]\n" );
34824     Abc_Print( -2, "\t         performs AIG optimization\n" );
34825     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
34826     Abc_Print( -2, "\t-w     : toggle printing additional information [default = %s]\n", fVeryVerbose? "yes": "no" );
34827     Abc_Print( -2, "\t-h     : print the command usage\n");
34828     return 1;
34829 }
34830 
34831 /**Function*************************************************************
34832 
34833   Synopsis    []
34834 
34835   Description []
34836 
34837   SideEffects []
34838 
34839   SeeAlso     []
34840 
34841 ***********************************************************************/
Abc_CommandAbc9Syn4(Abc_Frame_t * pAbc,int argc,char ** argv)34842 int Abc_CommandAbc9Syn4( Abc_Frame_t * pAbc, int argc, char ** argv )
34843 {
34844     Gia_Man_t * pTemp;
34845     int c, fVerbose = 0;
34846     int fVeryVerbose = 0;
34847     Extra_UtilGetoptReset();
34848     while ( ( c = Extra_UtilGetopt( argc, argv, "vwh" ) ) != EOF )
34849     {
34850         switch ( c )
34851         {
34852         case 'v':
34853             fVerbose ^= 1;
34854             break;
34855         case 'w':
34856             fVeryVerbose ^= 1;
34857             break;
34858         case 'h':
34859             goto usage;
34860         default:
34861             goto usage;
34862         }
34863     }
34864     if ( pAbc->pGia == NULL )
34865     {
34866         Abc_Print( -1, "Abc_CommandAbc9Syn4(): There is no AIG.\n" );
34867         return 1;
34868     }
34869     pTemp = Gia_ManAigSyn4( pAbc->pGia, fVerbose, fVeryVerbose );
34870     Abc_FrameUpdateGia( pAbc, pTemp );
34871     return 0;
34872 
34873 usage:
34874     Abc_Print( -2, "usage: &syn4 [-lvh]\n" );
34875     Abc_Print( -2, "\t         performs AIG optimization\n" );
34876     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
34877     Abc_Print( -2, "\t-w     : toggle printing additional information [default = %s]\n", fVeryVerbose? "yes": "no" );
34878     Abc_Print( -2, "\t-h     : print the command usage\n");
34879     return 1;
34880 }
34881 
34882 /**Function*************************************************************
34883 
34884   Synopsis    []
34885 
34886   Description []
34887 
34888   SideEffects []
34889 
34890   SeeAlso     []
34891 
34892 ***********************************************************************/
Abc_CommandAbc9False(Abc_Frame_t * pAbc,int argc,char ** argv)34893 int Abc_CommandAbc9False( Abc_Frame_t * pAbc, int argc, char ** argv )
34894 {
34895     extern Gia_Man_t * Gia_ManCheckFalse( Gia_Man_t * p, int nSlackMax, int nTimeOut, int fVerbose, int fVeryVerbose );
34896     Gia_Man_t * pTemp;
34897     int nSlackMax = 0;
34898     int nTimeOut = 0;
34899     int c, fVerbose = 0;
34900     int fVeryVerbose = 0;
34901     Extra_UtilGetoptReset();
34902     while ( ( c = Extra_UtilGetopt( argc, argv, "STvwh" ) ) != EOF )
34903     {
34904         switch ( c )
34905         {
34906         case 'S':
34907             if ( globalUtilOptind >= argc )
34908             {
34909                 Abc_Print( -1, "Command line switch \"-S\" should be followed by a char string.\n" );
34910                 goto usage;
34911             }
34912             nSlackMax = atoi(argv[globalUtilOptind]);
34913             globalUtilOptind++;
34914             if ( nSlackMax < 0 )
34915                 goto usage;
34916             break;
34917         case 'T':
34918             if ( globalUtilOptind >= argc )
34919             {
34920                 Abc_Print( -1, "Command line switch \"-T\" should be followed by a char string.\n" );
34921                 goto usage;
34922             }
34923             nTimeOut = atoi(argv[globalUtilOptind]);
34924             globalUtilOptind++;
34925             if ( nTimeOut < 0 )
34926                 goto usage;
34927             break;
34928         case 'v':
34929             fVerbose ^= 1;
34930             break;
34931         case 'w':
34932             fVeryVerbose ^= 1;
34933             break;
34934         case 'h':
34935             goto usage;
34936         default:
34937             goto usage;
34938         }
34939     }
34940     if ( pAbc->pGia == NULL )
34941     {
34942         Abc_Print( -1, "Abc_CommandAbc9False(): There is no AIG.\n" );
34943         return 1;
34944     }
34945     pTemp = Gia_ManCheckFalse( pAbc->pGia, nSlackMax, nTimeOut, fVerbose, fVeryVerbose );
34946     Abc_FrameUpdateGia( pAbc, pTemp );
34947     return 0;
34948 
34949 usage:
34950     Abc_Print( -2, "usage: &false [-ST num] [-vwh]\n" );
34951     Abc_Print( -2, "\t         detecting and elimintation false paths\n" );
34952     Abc_Print( -2, "\t-S num : maximum slack to identify false paths [default = %d]\n",  nSlackMax );
34953     Abc_Print( -2, "\t-T num : approximate runtime limit in seconds [default = %d]\n",   nTimeOut );
34954     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",    fVerbose? "yes": "no" );
34955     Abc_Print( -2, "\t-w     : toggle printing additional information [default = %s]\n", fVeryVerbose? "yes": "no" );
34956     Abc_Print( -2, "\t-h     : print the command usage\n");
34957     return 1;
34958 }
34959 
34960 /**Function*************************************************************
34961 
34962   Synopsis    []
34963 
34964   Description []
34965 
34966   SideEffects []
34967 
34968   SeeAlso     []
34969 
34970 ***********************************************************************/
Abc_CommandAbc9Miter(Abc_Frame_t * pAbc,int argc,char ** argv)34971 int Abc_CommandAbc9Miter( Abc_Frame_t * pAbc, int argc, char ** argv )
34972 {
34973     FILE * pFile;
34974     Gia_Man_t * pAux;
34975     Gia_Man_t * pSecond;
34976     char * FileName, * pTemp;
34977     char ** pArgvNew;
34978     int nArgcNew;
34979     int c;
34980     int nInsDup  = 0;
34981     int fDualOut = 0;
34982     int fSeq     = 0;
34983     int fTrans   = 0;
34984     int fTransX  = 0;
34985     int fConvert = 0;
34986     int fTransZ  = 0;
34987     int fVerbose = 0;
34988     Extra_UtilGetoptReset();
34989     while ( ( c = Extra_UtilGetopt( argc, argv, "Idstxyzvh" ) ) != EOF )
34990     {
34991         switch ( c )
34992         {
34993         case 'I':
34994             if ( globalUtilOptind >= argc )
34995             {
34996                 Abc_Print( -1, "Command line switch \"-I\" should be followed by a char string.\n" );
34997                 goto usage;
34998             }
34999             nInsDup = atoi(argv[globalUtilOptind]);
35000             globalUtilOptind++;
35001             if ( nInsDup < 0 )
35002                 goto usage;
35003             break;
35004         case 'd':
35005             fDualOut ^= 1;
35006             break;
35007         case 's':
35008             fSeq ^= 1;
35009             break;
35010         case 't':
35011             fTrans ^= 1;
35012             break;
35013         case 'x':
35014             fTransX ^= 1;
35015             break;
35016         case 'y':
35017             fConvert ^= 1;
35018             break;
35019         case 'z':
35020             fTransZ ^= 1;
35021             break;
35022         case 'v':
35023             fVerbose ^= 1;
35024             break;
35025         case 'h':
35026             goto usage;
35027         default:
35028             goto usage;
35029         }
35030     }
35031     if ( fTrans || fTransX || fTransZ || fConvert )
35032     {
35033         if ( pAbc->pGia == NULL )
35034         {
35035             Abc_Print( -1, "Abc_CommandAbc9Miter(): There is no AIG.\n" );
35036             return 1;
35037         }
35038         if ( (Gia_ManPoNum(pAbc->pGia) & 1) == 1 )
35039         {
35040             Abc_Print( -1, "Abc_CommandAbc9Miter(): The number of outputs should be even.\n" );
35041             return 0;
35042         }
35043         if ( fTrans )
35044         {
35045             pAux = Gia_ManTransformMiter( pAbc->pGia );
35046             Abc_Print( 1, "The miter (current AIG) is transformed by XORing POs pair-wise.\n" );
35047         }
35048         else if ( fTransX )
35049         {
35050             pAux = Gia_ManTransformMiter2( pAbc->pGia );
35051             Abc_Print( 1, "The miter (current AIG) is transformed by XORing POs of two word-level outputs.\n" );
35052         }
35053         else if ( fTransZ )
35054         {
35055             extern Gia_Man_t * Gia_ManTransformDualOutput( Gia_Man_t * p );
35056             pAux = Gia_ManTransformDualOutput( pAbc->pGia );
35057             Abc_Print( 1, "The dual-output miter (current AIG) is transformed by ordering sides.\n" );
35058         }
35059         else
35060         {
35061             pAux = Gia_ManTransformTwoWord2DualOutput( pAbc->pGia );
35062             Abc_Print( 1, "The miter (current AIG) is transformed from two-word to dual-output.\n" );
35063         }
35064         Abc_FrameUpdateGia( pAbc, pAux );
35065         return 0;
35066     }
35067 
35068     pArgvNew = argv + globalUtilOptind;
35069     nArgcNew = argc - globalUtilOptind;
35070     if ( nArgcNew != 1 )
35071     {
35072         Abc_Print( -1, "File name is not given on the command line.\n" );
35073         return 1;
35074     }
35075 
35076     // get the input file name
35077     FileName = pArgvNew[0];
35078     // fix the wrong symbol
35079     for ( pTemp = FileName; *pTemp; pTemp++ )
35080         if ( *pTemp == '>' )
35081             *pTemp = '\\';
35082     if ( (pFile = fopen( FileName, "r" )) == NULL )
35083     {
35084         Abc_Print( -1, "Cannot open input file \"%s\". ", FileName );
35085         if ( (FileName = Extra_FileGetSimilarName( FileName, ".aig", NULL, NULL, NULL, NULL )) )
35086             Abc_Print( 1, "Did you mean \"%s\"?", FileName );
35087         Abc_Print( 1, "\n" );
35088         return 1;
35089     }
35090     fclose( pFile );
35091     pSecond = Gia_AigerRead( FileName, 0, 0, 0 );
35092     if ( pSecond == NULL )
35093     {
35094         Abc_Print( -1, "Reading AIGER has failed.\n" );
35095         return 0;
35096     }
35097     // compute the miter
35098     pAux = Gia_ManMiter( pAbc->pGia, pSecond, nInsDup, fDualOut, fSeq, 0, fVerbose );
35099     Gia_ManStop( pSecond );
35100     Abc_FrameUpdateGia( pAbc, pAux );
35101     return 0;
35102 
35103 usage:
35104     Abc_Print( -2, "usage: &miter [-I num] [-dstxyzvh] <file>\n" );
35105     Abc_Print( -2, "\t         creates miter of two designs (current AIG vs. <file>)\n" );
35106     Abc_Print( -2, "\t-I num : the number of last PIs to replicate [default = %d]\n", nInsDup );
35107     Abc_Print( -2, "\t-d     : toggle creating dual-output miter [default = %s]\n", fDualOut? "yes": "no" );
35108     Abc_Print( -2, "\t-s     : toggle creating sequential miter [default = %s]\n", fSeq? "yes": "no" );
35109     Abc_Print( -2, "\t-t     : toggle XORing POs of dual-output miter [default = %s]\n", fTrans? "yes": "no" );
35110     Abc_Print( -2, "\t-x     : toggle XORing POs of two-word miter [default = %s]\n", fTransX? "yes": "no" );
35111     Abc_Print( -2, "\t-y     : toggle convering two-word miter into dual-output miter [default = %s]\n", fConvert? "yes": "no" );
35112     Abc_Print( -2, "\t-z     : toggle odering sides of the dual-output miter [default = %s]\n", fTransZ? "yes": "no" );
35113     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
35114     Abc_Print( -2, "\t-h     : print the command usage\n");
35115     Abc_Print( -2, "\t<file> : AIGER file with the design to miter\n");
35116     return 1;
35117 }
35118 
35119 /**Function*************************************************************
35120 
35121   Synopsis    []
35122 
35123   Description []
35124 
35125   SideEffects []
35126 
35127   SeeAlso     []
35128 
35129 ***********************************************************************/
Abc_CommandAbc9Miter2(Abc_Frame_t * pAbc,int argc,char ** argv)35130 int Abc_CommandAbc9Miter2( Abc_Frame_t * pAbc, int argc, char ** argv )
35131 {
35132     FILE * pFile;
35133     Gia_Man_t * pAux;
35134     char * FileName, * pTemp, * pInit;
35135     char ** pArgvNew;
35136     int nArgcNew;
35137     int c, fVerbose = 0;
35138     Extra_UtilGetoptReset();
35139     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
35140     {
35141         switch ( c )
35142         {
35143         case 'v':
35144             fVerbose ^= 1;
35145             break;
35146         case 'h':
35147             goto usage;
35148         default:
35149             goto usage;
35150         }
35151     }
35152     pArgvNew = argv + globalUtilOptind;
35153     nArgcNew = argc - globalUtilOptind;
35154     if ( nArgcNew != 1 )
35155     {
35156         Abc_Print( -1, "File name is not given on the command line.\n" );
35157         return 1;
35158     }
35159     // get the input file name
35160     FileName = pArgvNew[0];
35161     // fix the wrong symbol
35162     for ( pTemp = FileName; *pTemp; pTemp++ )
35163         if ( *pTemp == '>' )
35164             *pTemp = '\\';
35165     if ( (pFile = fopen( FileName, "r" )) == NULL )
35166     {
35167         Abc_Print( -1, "Cannot open input file \"%s\". ", FileName );
35168         if ( (FileName = Extra_FileGetSimilarName( FileName, ".aig", NULL, NULL, NULL, NULL )) )
35169             Abc_Print( 1, "Did you mean \"%s\"?", FileName );
35170         Abc_Print( 1, "\n" );
35171         return 1;
35172     }
35173     fclose( pFile );
35174     // extract string
35175     pInit = Extra_FileReadContents( FileName );
35176     Extra_StringClean( pInit, "01xX" );
35177     if ( (int)strlen(pInit) != Gia_ManCiNum(pAbc->pGia) )
35178     {
35179         Abc_Print( -1, "Init string length (%d) differs from PI and flop count (%d).\n", strlen(pInit), Gia_ManCiNum(pAbc->pGia) );
35180         ABC_FREE( pInit );
35181         return 1;
35182     }
35183     // compute the miter
35184     pAux = Gia_ManMiter2( pAbc->pGia, pInit, fVerbose );
35185     ABC_FREE( pInit );
35186     Abc_FrameUpdateGia( pAbc, pAux );
35187     return 0;
35188 
35189 usage:
35190     Abc_Print( -2, "usage: &miter2 [-vh] <file>\n" );
35191     Abc_Print( -2, "\t         creates miter of two copies of the design\n" );
35192     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
35193     Abc_Print( -2, "\t-h     : print the command usage\n");
35194     Abc_Print( -2, "\t<file> : file name with flop initial values (0/1/x/X) [default = required]\n" );
35195     return 1;
35196 }
35197 
35198 /**Function*************************************************************
35199 
35200   Synopsis    []
35201 
35202   Description []
35203 
35204   SideEffects []
35205 
35206   SeeAlso     []
35207 
35208 ***********************************************************************/
Abc_CommandAbc9Append(Abc_Frame_t * pAbc,int argc,char ** argv)35209 int Abc_CommandAbc9Append( Abc_Frame_t * pAbc, int argc, char ** argv )
35210 {
35211     FILE * pFile;
35212     Gia_Man_t * pSecond;
35213     char * FileName, * pTemp;
35214     char ** pArgvNew;
35215     int nArgcNew;
35216     int c;
35217     int fVerbose = 0;
35218     Extra_UtilGetoptReset();
35219     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
35220     {
35221         switch ( c )
35222         {
35223         case 'v':
35224             fVerbose ^= 1;
35225             break;
35226         case 'h':
35227             goto usage;
35228         default:
35229             goto usage;
35230         }
35231     }
35232 
35233     pArgvNew = argv + globalUtilOptind;
35234     nArgcNew = argc - globalUtilOptind;
35235     if ( nArgcNew != 1 )
35236     {
35237         Abc_Print( -1, "File name is not given on the command line.\n" );
35238         return 1;
35239     }
35240 
35241     // get the input file name
35242     FileName = pArgvNew[0];
35243     // fix the wrong symbol
35244     for ( pTemp = FileName; *pTemp; pTemp++ )
35245         if ( *pTemp == '>' )
35246             *pTemp = '\\';
35247     if ( (pFile = fopen( FileName, "r" )) == NULL )
35248     {
35249         Abc_Print( -1, "Cannot open input file \"%s\". ", FileName );
35250         if ( (FileName = Extra_FileGetSimilarName( FileName, ".aig", NULL, NULL, NULL, NULL )) )
35251             Abc_Print( 1, "Did you mean \"%s\"?", FileName );
35252         Abc_Print( 1, "\n" );
35253         return 1;
35254     }
35255     fclose( pFile );
35256     pSecond = Gia_AigerRead( FileName, 0, 0, 0 );
35257     if ( pSecond == NULL )
35258     {
35259         Abc_Print( -1, "Reading AIGER has failed.\n" );
35260         return 0;
35261     }
35262     // compute the miter
35263     Gia_ManDupAppend( pAbc->pGia, pSecond );
35264     Gia_ManStop( pSecond );
35265     return 0;
35266 
35267 usage:
35268     Abc_Print( -2, "usage: &append [-vh] <file>\n" );
35269     Abc_Print( -2, "\t         appends <file> to the current AIG using new PIs and POs\n" );
35270     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
35271     Abc_Print( -2, "\t-h     : print the command usage\n");
35272     Abc_Print( -2, "\t<file> : AIGER file with the design to miter\n");
35273     return 1;
35274 }
35275 
35276 /**Function*************************************************************
35277 
35278   Synopsis    []
35279 
35280   Description []
35281 
35282   SideEffects []
35283 
35284   SeeAlso     []
35285 
35286 ***********************************************************************/
Abc_CommandAbc9Scl(Abc_Frame_t * pAbc,int argc,char ** argv)35287 int Abc_CommandAbc9Scl( Abc_Frame_t * pAbc, int argc, char ** argv )
35288 {
35289     Gia_Man_t * pTemp;
35290     int c;
35291     int fConst = 1;
35292     int fEquiv = 1;
35293     int fVerbose = 0;
35294     int fVerboseFlops = 0;
35295     Extra_UtilGetoptReset();
35296     while ( ( c = Extra_UtilGetopt( argc, argv, "cevwh" ) ) != EOF )
35297     {
35298         switch ( c )
35299         {
35300         case 'c':
35301             fConst ^= 1;
35302             break;
35303         case 'e':
35304             fEquiv ^= 1;
35305             break;
35306         case 'v':
35307             fVerbose ^= 1;
35308             break;
35309         case 'w':
35310             fVerboseFlops ^= 1;
35311             break;
35312         default:
35313             goto usage;
35314         }
35315     }
35316     if ( pAbc->pGia == NULL )
35317     {
35318         Abc_Print( -1, "Abc_CommandAbc9Scl(): There is no AIG.\n" );
35319         return 1;
35320     }
35321     if ( Gia_ManBoxNum(pAbc->pGia) && Gia_ManRegBoxNum(pAbc->pGia) )
35322     {
35323         if ( pAbc->pGia->pAigExtra == NULL )
35324         {
35325             printf( "Timing manager is given but there is no GIA of boxes.\n" );
35326             return 0;
35327         }
35328         pTemp = Gia_ManSweepWithBoxes( pAbc->pGia, NULL, NULL, fConst, fEquiv, fVerbose, fVerboseFlops );
35329         Abc_FrameUpdateGia( pAbc, pTemp );
35330         return 0;
35331     }
35332     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
35333     {
35334         Abc_Print( -1, "The network is combinational.\n" );
35335         return 0;
35336     }
35337     pTemp = Gia_ManSeqStructSweep( pAbc->pGia, fConst, fEquiv, fVerbose );
35338     Abc_FrameUpdateGia( pAbc, pTemp );
35339     return 0;
35340 
35341 usage:
35342     Abc_Print( -2, "usage: &scl [-cevwh]\n" );
35343     Abc_Print( -2, "\t         performs structural sequential cleanup\n" );
35344     Abc_Print( -2, "\t-c     : toggle removing stuck-at constant registers [default = %s]\n", fConst? "yes": "no" );
35345     Abc_Print( -2, "\t-e     : toggle removing equivalent-driver registers [default = %s]\n", fEquiv? "yes": "no" );
35346     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
35347     Abc_Print( -2, "\t-w     : toggle printing verbose info about equivalent flops [default = %s]\n", fVerboseFlops? "yes": "no" );
35348     Abc_Print( -2, "\t-h     : print the command usage\n");
35349     return 1;
35350 }
35351 
35352 /**Function*************************************************************
35353 
35354   Synopsis    []
35355 
35356   Description []
35357 
35358   SideEffects []
35359 
35360   SeeAlso     []
35361 
35362 ***********************************************************************/
Abc_CommandAbc9Lcorr(Abc_Frame_t * pAbc,int argc,char ** argv)35363 int Abc_CommandAbc9Lcorr( Abc_Frame_t * pAbc, int argc, char ** argv )
35364 {
35365     Cec_ParCor_t Pars, * pPars = &Pars;
35366     Gia_Man_t * pTemp;
35367     int c;
35368     Cec_ManCorSetDefaultParams( pPars );
35369     pPars->fLatchCorr = 1;
35370     Extra_UtilGetoptReset();
35371     while ( ( c = Extra_UtilGetopt( argc, argv, "FCPrcvwh" ) ) != EOF )
35372     {
35373         switch ( c )
35374         {
35375         case 'F':
35376             if ( globalUtilOptind >= argc )
35377             {
35378                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
35379                 goto usage;
35380             }
35381             pPars->nFrames = atoi(argv[globalUtilOptind]);
35382             globalUtilOptind++;
35383             if ( pPars->nFrames < 0 )
35384                 goto usage;
35385             break;
35386         case 'C':
35387             if ( globalUtilOptind >= argc )
35388             {
35389                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
35390                 goto usage;
35391             }
35392             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
35393             globalUtilOptind++;
35394             if ( pPars->nBTLimit < 0 )
35395                 goto usage;
35396             break;
35397         case 'P':
35398             if ( globalUtilOptind >= argc )
35399             {
35400                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
35401                 goto usage;
35402             }
35403             pPars->nPrefix = atoi(argv[globalUtilOptind]);
35404             globalUtilOptind++;
35405             if ( pPars->nPrefix < 0 )
35406                 goto usage;
35407             break;
35408         case 'r':
35409             pPars->fUseRings ^= 1;
35410             break;
35411         case 'c':
35412             pPars->fUseCSat ^= 1;
35413             break;
35414         case 'v':
35415             pPars->fVerbose ^= 1;
35416             break;
35417         case 'w':
35418             pPars->fVerboseFlops ^= 1;
35419             break;
35420         default:
35421             goto usage;
35422         }
35423     }
35424     if ( pAbc->pGia == NULL )
35425     {
35426         Abc_Print( -1, "Abc_CommandAbc9Lcorr(): There is no AIG.\n" );
35427         return 1;
35428     }
35429     if ( Gia_ManBoxNum(pAbc->pGia) && Gia_ManRegBoxNum(pAbc->pGia) )
35430     {
35431         if ( pAbc->pGia->pAigExtra == NULL )
35432         {
35433             printf( "Timing manager is given but there is no GIA of boxes.\n" );
35434             return 0;
35435         }
35436         pTemp = Gia_ManSweepWithBoxes( pAbc->pGia, NULL, pPars, 0, 0, pPars->fVerbose, pPars->fVerboseFlops );
35437         Abc_FrameUpdateGia( pAbc, pTemp );
35438         return 0;
35439     }
35440     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
35441     {
35442         Abc_Print( -1, "The network is combinational.\n" );
35443         return 0;
35444     }
35445     pTemp = Cec_ManLSCorrespondence( pAbc->pGia, pPars );
35446     Abc_FrameUpdateGia( pAbc, pTemp );
35447     return 0;
35448 
35449 usage:
35450     Abc_Print( -2, "usage: &lcorr [-FCP num] [-rcvwh]\n" );
35451     Abc_Print( -2, "\t         performs latch correpondence computation\n" );
35452     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", pPars->nBTLimit );
35453     Abc_Print( -2, "\t-F num : the number of timeframes in inductive case [default = %d]\n", pPars->nFrames );
35454     Abc_Print( -2, "\t-P num : the number of timeframes in the prefix [default = %d]\n", pPars->nPrefix );
35455     Abc_Print( -2, "\t-r     : toggle using implication rings during refinement [default = %s]\n", pPars->fUseRings? "yes": "no" );
35456     Abc_Print( -2, "\t-c     : toggle using circuit-based SAT solver [default = %s]\n", pPars->fUseCSat? "yes": "no" );
35457     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
35458     Abc_Print( -2, "\t-w     : toggle printing verbose info about equivalent flops [default = %s]\n", pPars->fVerboseFlops? "yes": "no" );
35459     Abc_Print( -2, "\t-h     : print the command usage\n");
35460     return 1;
35461 }
35462 
35463 /**Function*************************************************************
35464 
35465   Synopsis    []
35466 
35467   Description []
35468 
35469   SideEffects []
35470 
35471   SeeAlso     []
35472 
35473 ***********************************************************************/
Abc_CommandAbc9Scorr(Abc_Frame_t * pAbc,int argc,char ** argv)35474 int Abc_CommandAbc9Scorr( Abc_Frame_t * pAbc, int argc, char ** argv )
35475 {
35476     extern Gia_Man_t * Gia_ManScorrDivideTest( Gia_Man_t * p, Cec_ParCor_t * pPars );
35477     Cec_ParCor_t Pars, * pPars = &Pars;
35478     Gia_Man_t * pTemp;
35479     int fPartition = 0;
35480     int c;
35481     Cec_ManCorSetDefaultParams( pPars );
35482     Extra_UtilGetoptReset();
35483     while ( ( c = Extra_UtilGetopt( argc, argv, "FCPpkrecqwvh" ) ) != EOF )
35484     {
35485         switch ( c )
35486         {
35487         case 'F':
35488             if ( globalUtilOptind >= argc )
35489             {
35490                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
35491                 goto usage;
35492             }
35493             pPars->nFrames = atoi(argv[globalUtilOptind]);
35494             globalUtilOptind++;
35495             if ( pPars->nFrames < 0 )
35496                 goto usage;
35497             break;
35498         case 'C':
35499             if ( globalUtilOptind >= argc )
35500             {
35501                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
35502                 goto usage;
35503             }
35504             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
35505             globalUtilOptind++;
35506             if ( pPars->nBTLimit < 0 )
35507                 goto usage;
35508             break;
35509         case 'P':
35510             if ( globalUtilOptind >= argc )
35511             {
35512                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
35513                 goto usage;
35514             }
35515             pPars->nPrefix = atoi(argv[globalUtilOptind]);
35516             globalUtilOptind++;
35517             if ( pPars->nPrefix < 0 )
35518                 goto usage;
35519             break;
35520         case 'p':
35521             fPartition ^= 1;
35522             break;
35523         case 'k':
35524             pPars->fConstCorr ^= 1;
35525             break;
35526         case 'r':
35527             pPars->fUseRings ^= 1;
35528             break;
35529         case 'e':
35530             pPars->fMakeChoices ^= 1;
35531             break;
35532         case 'c':
35533             pPars->fUseCSat ^= 1;
35534             break;
35535         case 'q':
35536             pPars->fStopWhenGone ^= 1;
35537             break;
35538         case 'w':
35539             pPars->fVerboseFlops ^= 1;
35540             break;
35541         case 'v':
35542             pPars->fVerbose ^= 1;
35543             break;
35544         default:
35545             goto usage;
35546         }
35547     }
35548     if ( pAbc->pGia == NULL )
35549     {
35550         Abc_Print( -1, "Abc_CommandAbc9Scorr(): There is no AIG.\n" );
35551         return 1;
35552     }
35553     if ( Gia_ManBoxNum(pAbc->pGia) && Gia_ManRegBoxNum(pAbc->pGia) )
35554     {
35555         if ( pAbc->pGia->pAigExtra == NULL )
35556         {
35557             printf( "Timing manager is given but there is no GIA of boxes.\n" );
35558             return 0;
35559         }
35560         pTemp = Gia_ManSweepWithBoxes( pAbc->pGia, NULL, pPars, 0, 0, pPars->fVerbose, pPars->fVerboseFlops );
35561         Abc_FrameUpdateGia( pAbc, pTemp );
35562         return 0;
35563     }
35564     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
35565     {
35566         Abc_Print( 0, "The network is combinational.\n" );
35567         return 0;
35568     }
35569     if ( fPartition )
35570         pTemp = Gia_ManScorrDivideTest( pAbc->pGia, pPars );
35571     else
35572         pTemp = Cec_ManLSCorrespondence( pAbc->pGia, pPars );
35573     Abc_FrameUpdateGia( pAbc, pTemp );
35574     return 0;
35575 
35576 usage:
35577     Abc_Print( -2, "usage: &scorr [-FCP num] [-pkrecqwvh]\n" );
35578     Abc_Print( -2, "\t         performs signal correpondence computation\n" );
35579     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", pPars->nBTLimit );
35580     Abc_Print( -2, "\t-F num : the number of timeframes in inductive case [default = %d]\n", pPars->nFrames );
35581     Abc_Print( -2, "\t-P num : the number of timeframes in the prefix [default = %d]\n", pPars->nPrefix );
35582     Abc_Print( -2, "\t-p     : toggle using partitioning for the input AIG [default = %s]\n", fPartition? "yes": "no" );
35583     Abc_Print( -2, "\t-k     : toggle using constant correspondence [default = %s]\n", pPars->fConstCorr? "yes": "no" );
35584     Abc_Print( -2, "\t-r     : toggle using implication rings during refinement [default = %s]\n", pPars->fUseRings? "yes": "no" );
35585     Abc_Print( -2, "\t-e     : toggle using equivalences as choices [default = %s]\n", pPars->fMakeChoices? "yes": "no" );
35586     Abc_Print( -2, "\t-c     : toggle using circuit-based SAT solver [default = %s]\n", pPars->fUseCSat? "yes": "no" );
35587     Abc_Print( -2, "\t-q     : toggle quitting when PO is not a constant candidate [default = %s]\n", pPars->fStopWhenGone? "yes": "no" );
35588     Abc_Print( -2, "\t-w     : toggle printing verbose info about equivalent flops [default = %s]\n", pPars->fVerboseFlops? "yes": "no" );
35589     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
35590     Abc_Print( -2, "\t-h     : print the command usage\n");
35591     return 1;
35592 }
35593 
35594 /**Function*************************************************************
35595 
35596   Synopsis    []
35597 
35598   Description []
35599 
35600   SideEffects []
35601 
35602   SeeAlso     []
35603 
35604 ***********************************************************************/
Abc_CommandAbc9Choice(Abc_Frame_t * pAbc,int argc,char ** argv)35605 int Abc_CommandAbc9Choice( Abc_Frame_t * pAbc, int argc, char ** argv )
35606 {
35607     Cec_ParChc_t Pars, * pPars = &Pars;
35608     Gia_Man_t * pTemp;
35609     int c;
35610     Cec_ManChcSetDefaultParams( pPars );
35611     Extra_UtilGetoptReset();
35612     while ( ( c = Extra_UtilGetopt( argc, argv, "Ccvh" ) ) != EOF )
35613     {
35614         switch ( c )
35615         {
35616         case 'C':
35617             if ( globalUtilOptind >= argc )
35618             {
35619                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
35620                 goto usage;
35621             }
35622             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
35623             globalUtilOptind++;
35624             if ( pPars->nBTLimit < 0 )
35625                 goto usage;
35626             break;
35627         case 'c':
35628             pPars->fUseCSat ^= 1;
35629             break;
35630         case 'v':
35631             pPars->fVerbose ^= 1;
35632             break;
35633         default:
35634             goto usage;
35635         }
35636     }
35637     if ( pAbc->pGia == NULL )
35638     {
35639         Abc_Print( -1, "Abc_CommandAbc9Choice(): There is no AIG.\n" );
35640         return 1;
35641     }
35642     pTemp = Cec_ManChoiceComputation( pAbc->pGia, pPars );
35643     Abc_FrameUpdateGia( pAbc, pTemp );
35644     return 0;
35645 
35646 usage:
35647     Abc_Print( -2, "usage: &choice [-C num] [-cvh]\n" );
35648     Abc_Print( -2, "\t         performs computation of structural choices\n" );
35649     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", pPars->nBTLimit );
35650     Abc_Print( -2, "\t-c     : toggle using circuit-based SAT solver [default = %s]\n", pPars->fUseCSat? "yes": "no" );
35651     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
35652     Abc_Print( -2, "\t-h     : print the command usage\n");
35653     return 1;
35654 }
35655 
35656 /**Function*************************************************************
35657 
35658   Synopsis    []
35659 
35660   Description []
35661 
35662   SideEffects []
35663 
35664   SeeAlso     []
35665 
35666 ***********************************************************************/
Abc_CommandAbc9Sat(Abc_Frame_t * pAbc,int argc,char ** argv)35667 int Abc_CommandAbc9Sat( Abc_Frame_t * pAbc, int argc, char ** argv )
35668 {
35669     extern Vec_Int_t * Cbs2_ManSolveMiterNc( Gia_Man_t * pAig, int nConfs, Vec_Str_t ** pvStatus, int fVerbose );
35670     Cec_ParSat_t ParsSat, * pPars = &ParsSat;
35671     Gia_Man_t * pTemp;
35672     int c;
35673     int fNewSolver = 0, fCSat = 0;
35674     Cec_ManSatSetDefaultParams( pPars );
35675     Extra_UtilGetoptReset();
35676     while ( ( c = Extra_UtilGetopt( argc, argv, "CSNanmtcxvh" ) ) != EOF )
35677     {
35678         switch ( c )
35679         {
35680         case 'C':
35681             if ( globalUtilOptind >= argc )
35682             {
35683                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
35684                 goto usage;
35685             }
35686             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
35687             globalUtilOptind++;
35688             if ( pPars->nBTLimit < 0 )
35689                 goto usage;
35690             break;
35691         case 'S':
35692             if ( globalUtilOptind >= argc )
35693             {
35694                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
35695                 goto usage;
35696             }
35697             pPars->nSatVarMax = atoi(argv[globalUtilOptind]);
35698             globalUtilOptind++;
35699             if ( pPars->nSatVarMax < 0 )
35700                 goto usage;
35701             break;
35702         case 'N':
35703             if ( globalUtilOptind >= argc )
35704             {
35705                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
35706                 goto usage;
35707             }
35708             pPars->nCallsRecycle = atoi(argv[globalUtilOptind]);
35709             globalUtilOptind++;
35710             if ( pPars->nCallsRecycle < 0 )
35711                 goto usage;
35712             break;
35713         case 'a':
35714             pPars->fSaveCexes ^= 1;
35715             break;
35716         case 'n':
35717             pPars->fNonChrono ^= 1;
35718             break;
35719         case 'm':
35720             pPars->fCheckMiter ^= 1;
35721             break;
35722         case 't':
35723             pPars->fLearnCls ^= 1;
35724             break;
35725         case 'c':
35726             fCSat ^= 1;
35727             break;
35728         case 'x':
35729             fNewSolver ^= 1;
35730             break;
35731         case 'v':
35732             pPars->fVerbose ^= 1;
35733             break;
35734         default:
35735             goto usage;
35736         }
35737     }
35738     if ( pAbc->pGia == NULL )
35739     {
35740         Abc_Print( -1, "Abc_CommandAbc9Sat(): There is no AIG.\n" );
35741         return 1;
35742     }
35743     if ( fCSat )
35744     {
35745         Vec_Int_t * vCounters;
35746         Vec_Str_t * vStatus;
35747         if ( fNewSolver )
35748             vCounters = Cbs2_ManSolveMiterNc( pAbc->pGia, pPars->nBTLimit, &vStatus, pPars->fVerbose );
35749         else if ( pPars->fLearnCls )
35750             vCounters = Tas_ManSolveMiterNc( pAbc->pGia, pPars->nBTLimit, &vStatus, pPars->fVerbose );
35751         else if ( pPars->fNonChrono )
35752             vCounters = Cbs_ManSolveMiterNc( pAbc->pGia, pPars->nBTLimit, &vStatus, pPars->fVerbose );
35753         else
35754             vCounters = Cbs_ManSolveMiter( pAbc->pGia, pPars->nBTLimit, &vStatus, pPars->fVerbose );
35755         Vec_IntFree( vCounters );
35756         Vec_StrFree( vStatus );
35757     }
35758     else
35759     {
35760         pTemp = Cec_ManSatSolving( pAbc->pGia, pPars );
35761         Abc_FrameUpdateGia( pAbc, pTemp );
35762     }
35763     if ( pAbc->pGia->vSeqModelVec )
35764     {
35765         Vec_Int_t * vStatuses = Abc_FrameDeriveStatusArray2( pAbc->pGia->vSeqModelVec );
35766         Abc_FrameReplacePoStatuses( pAbc, &vStatuses );
35767         Abc_FrameReplaceCexVec( pAbc, &pAbc->pGia->vSeqModelVec );
35768     }
35769     return 0;
35770 
35771 usage:
35772     Abc_Print( -2, "usage: &sat [-CSN <num>] [-anmctxvh]\n" );
35773     Abc_Print( -2, "\t         performs SAT solving for the combinational outputs\n" );
35774     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", pPars->nBTLimit );
35775     Abc_Print( -2, "\t-S num : the min number of variables to recycle the solver [default = %d]\n", pPars->nSatVarMax );
35776     Abc_Print( -2, "\t-N num : the min number of calls to recycle the solver [default = %d]\n", pPars->nCallsRecycle );
35777     Abc_Print( -2, "\t-a     : toggle solving all outputs and saving counter-examples [default = %s]\n", pPars->fSaveCexes? "yes": "no" );
35778     Abc_Print( -2, "\t-n     : toggle using non-chronological backtracking [default = %s]\n", pPars->fNonChrono? "yes": "no" );
35779     Abc_Print( -2, "\t-m     : toggle miter vs. any circuit [default = %s]\n", pPars->fCheckMiter? "miter": "circuit" );
35780     Abc_Print( -2, "\t-c     : toggle using circuit-based SAT solver [default = %s]\n", fCSat? "yes": "no" );
35781     Abc_Print( -2, "\t-t     : toggle using learning in curcuit-based solver [default = %s]\n", pPars->fLearnCls? "yes": "no" );
35782     Abc_Print( -2, "\t-x     : toggle using new solver [default = %s]\n", fNewSolver? "yes": "no" );
35783     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
35784     Abc_Print( -2, "\t-h     : print the command usage\n");
35785     return 1;
35786 }
35787 
35788 /**Function*************************************************************
35789 
35790   Synopsis    []
35791 
35792   Description []
35793 
35794   SideEffects []
35795 
35796   SeeAlso     []
35797 
35798 ***********************************************************************/
Abc_CommandAbc9SatEnum(Abc_Frame_t * pAbc,int argc,char ** argv)35799 int Abc_CommandAbc9SatEnum( Abc_Frame_t * pAbc, int argc, char ** argv )
35800 {
35801     extern int Gia_ManSatEnum( Gia_Man_t * p, int nConfLimit, int nTimeOut, int fVerbose );
35802     int c, nConfLimit = 0, nTimeOut = 0, fVerbose = 0;
35803     Extra_UtilGetoptReset();
35804     while ( ( c = Extra_UtilGetopt( argc, argv, "CTvh" ) ) != EOF )
35805     {
35806         switch ( c )
35807         {
35808         case 'C':
35809             if ( globalUtilOptind >= argc )
35810             {
35811                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
35812                 goto usage;
35813             }
35814             nConfLimit = atoi(argv[globalUtilOptind]);
35815             globalUtilOptind++;
35816             if ( nConfLimit < 0 )
35817                 goto usage;
35818             break;
35819         case 'T':
35820             if ( globalUtilOptind >= argc )
35821             {
35822                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
35823                 goto usage;
35824             }
35825             nTimeOut = atoi(argv[globalUtilOptind]);
35826             globalUtilOptind++;
35827             if ( nTimeOut < 0 )
35828                 goto usage;
35829             break;
35830         case 'v':
35831             fVerbose ^= 1;
35832             break;
35833         default:
35834             goto usage;
35835         }
35836     }
35837     if ( pAbc->pGia == NULL )
35838     {
35839         Abc_Print( -1, "Abc_CommandAbc9SatEnum(): There is no AIG.\n" );
35840         return 1;
35841     }
35842     Gia_ManSatEnum( pAbc->pGia, nConfLimit, nTimeOut, fVerbose );
35843     return 0;
35844 
35845 usage:
35846     Abc_Print( -2, "usage: &satenum [-CT <num>] [-vh]\n" );
35847     Abc_Print( -2, "\t         enumerates solutions of the combinational miter\n" );
35848     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", nConfLimit );
35849     Abc_Print( -2, "\t-T num : global timeout [default = %d]\n", nTimeOut );
35850     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",   fVerbose? "yes": "no" );
35851     Abc_Print( -2, "\t-h     : print the command usage\n");
35852     return 1;
35853 }
35854 
35855 /**Function*************************************************************
35856 
35857   Synopsis    []
35858 
35859   Description []
35860 
35861   SideEffects []
35862 
35863   SeeAlso     []
35864 
35865 ***********************************************************************/
Abc_CommandAbc9Fraig(Abc_Frame_t * pAbc,int argc,char ** argv)35866 int Abc_CommandAbc9Fraig( Abc_Frame_t * pAbc, int argc, char ** argv )
35867 {
35868     extern Gia_Man_t * Cec2_ManSimulateTest( Gia_Man_t * p, Cec_ParFra_t * pPars );
35869     extern Gia_Man_t * Cec3_ManSimulateTest( Gia_Man_t * p, Cec_ParFra_t * pPars );
35870     Cec_ParFra_t ParsFra, * pPars = &ParsFra;
35871     Gia_Man_t * pTemp;
35872     int c, fUseAlgo = 0, fUseAlgoG = 0;
35873     Cec_ManFraSetDefaultParams( pPars );
35874     pPars->fSatSweeping = 1;
35875     Extra_UtilGetoptReset();
35876     while ( ( c = Extra_UtilGetopt( argc, argv, "WRILDCrmdckngwvh" ) ) != EOF )
35877     {
35878         switch ( c )
35879         {
35880         case 'W':
35881             if ( globalUtilOptind >= argc )
35882             {
35883                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
35884                 goto usage;
35885             }
35886             pPars->nWords = atoi(argv[globalUtilOptind]);
35887             globalUtilOptind++;
35888             if ( pPars->nWords < 0 )
35889                 goto usage;
35890             break;
35891         case 'R':
35892             if ( globalUtilOptind >= argc )
35893             {
35894                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
35895                 goto usage;
35896             }
35897             pPars->nRounds = atoi(argv[globalUtilOptind]);
35898             globalUtilOptind++;
35899             if ( pPars->nRounds < 0 )
35900                 goto usage;
35901             break;
35902         case 'I':
35903             if ( globalUtilOptind >= argc )
35904             {
35905                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
35906                 goto usage;
35907             }
35908             pPars->nItersMax = atoi(argv[globalUtilOptind]);
35909             globalUtilOptind++;
35910             if ( pPars->nItersMax < 0 )
35911                 goto usage;
35912             break;
35913         case 'L':
35914             if ( globalUtilOptind >= argc )
35915             {
35916                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
35917                 goto usage;
35918             }
35919             pPars->nLevelMax = atoi(argv[globalUtilOptind]);
35920             globalUtilOptind++;
35921             if ( pPars->nLevelMax < 0 )
35922                 goto usage;
35923             break;
35924         case 'D':
35925             if ( globalUtilOptind >= argc )
35926             {
35927                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
35928                 goto usage;
35929             }
35930             pPars->nDepthMax = atoi(argv[globalUtilOptind]);
35931             globalUtilOptind++;
35932             if ( pPars->nDepthMax < 0 )
35933                 goto usage;
35934             break;
35935         case 'C':
35936             if ( globalUtilOptind >= argc )
35937             {
35938                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
35939                 goto usage;
35940             }
35941             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
35942             globalUtilOptind++;
35943             if ( pPars->nBTLimit < 0 )
35944                 goto usage;
35945             break;
35946         case 'r':
35947             pPars->fRewriting ^= 1;
35948             break;
35949         case 'm':
35950             pPars->fCheckMiter ^= 1;
35951             break;
35952         case 'd':
35953             pPars->fDualOut ^= 1;
35954             break;
35955         case 'c':
35956             pPars->fRunCSat ^= 1;
35957             break;
35958         case 'k':
35959             pPars->fUseCones ^= 1;
35960             break;
35961         case 'n':
35962             fUseAlgo ^= 1;
35963             break;
35964         case 'g':
35965             fUseAlgoG ^= 1;
35966             break;
35967         case 'w':
35968             pPars->fVeryVerbose ^= 1;
35969             break;
35970         case 'v':
35971             pPars->fVerbose ^= 1;
35972             break;
35973         default:
35974             goto usage;
35975         }
35976     }
35977     if ( pAbc->pGia == NULL )
35978     {
35979         Abc_Print( -1, "Abc_CommandAbc9Fraig(): There is no AIG.\n" );
35980         return 1;
35981     }
35982     if ( fUseAlgo )
35983         pTemp = Cec2_ManSimulateTest( pAbc->pGia, pPars );
35984     else if ( fUseAlgoG )
35985         pTemp = Cec3_ManSimulateTest( pAbc->pGia, pPars );
35986     else
35987         pTemp = Cec_ManSatSweeping( pAbc->pGia, pPars, 0 );
35988     Abc_FrameUpdateGia( pAbc, pTemp );
35989     return 0;
35990 
35991 usage:
35992     Abc_Print( -2, "usage: &fraig [-WRILDC <num>] [-rmdckngwvh]\n" );
35993     Abc_Print( -2, "\t         performs combinational SAT sweeping\n" );
35994     Abc_Print( -2, "\t-W num : the number of simulation words [default = %d]\n", pPars->nWords );
35995     Abc_Print( -2, "\t-R num : the number of simulation rounds [default = %d]\n", pPars->nRounds );
35996     Abc_Print( -2, "\t-I num : the number of sweeping iterations [default = %d]\n", pPars->nItersMax );
35997     Abc_Print( -2, "\t-L num : the max number of levels of nodes to consider [default = %d]\n", pPars->nLevelMax );
35998     Abc_Print( -2, "\t-D num : the max number of steps of speculative reduction [default = %d]\n", pPars->nDepthMax );
35999     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", pPars->nBTLimit );
36000     Abc_Print( -2, "\t-r     : toggle the use of AIG rewriting [default = %s]\n", pPars->fRewriting? "yes": "no" );
36001     Abc_Print( -2, "\t-m     : toggle miter vs. any circuit [default = %s]\n", pPars->fCheckMiter? "miter": "circuit" );
36002     Abc_Print( -2, "\t-d     : toggle using double output miters [default = %s]\n", pPars->fDualOut? "yes": "no" );
36003     Abc_Print( -2, "\t-c     : toggle using circuit-based solver [default = %s]\n", pPars->fRunCSat? "yes": "no" );
36004     Abc_Print( -2, "\t-k     : toggle using logic cones in the SAT solver [default = %s]\n", pPars->fUseCones? "yes": "no" );
36005     Abc_Print( -2, "\t-n     : toggle using new implementation [default = %s]\n", fUseAlgo? "yes": "no" );
36006     Abc_Print( -2, "\t-g     : toggle using another new implementation [default = %s]\n", fUseAlgoG? "yes": "no" );
36007     Abc_Print( -2, "\t-w     : toggle printing even more verbose information [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
36008     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
36009     Abc_Print( -2, "\t-h     : print the command usage\n");
36010     return 1;
36011 }
36012 
36013 /**Function*************************************************************
36014 
36015   Synopsis    []
36016 
36017   Description []
36018 
36019   SideEffects []
36020 
36021   SeeAlso     []
36022 
36023 ***********************************************************************/
Abc_CommandAbc9CFraig(Abc_Frame_t * pAbc,int argc,char ** argv)36024 int Abc_CommandAbc9CFraig( Abc_Frame_t * pAbc, int argc, char ** argv )
36025 {
36026     Gia_Man_t * pTemp;
36027     int c;
36028     Ssc_Pars_t Pars, * pPars = &Pars;
36029     Ssc_ManSetDefaultParams( pPars );
36030     Extra_UtilGetoptReset();
36031     while ( ( c = Extra_UtilGetopt( argc, argv, "WCacvh" ) ) != EOF )
36032     {
36033         switch ( c )
36034         {
36035         case 'W':
36036             if ( globalUtilOptind >= argc )
36037             {
36038                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
36039                 goto usage;
36040             }
36041             pPars->nWords = atoi(argv[globalUtilOptind]);
36042             globalUtilOptind++;
36043             if ( pPars->nWords < 0 )
36044                 goto usage;
36045             break;
36046         case 'C':
36047             if ( globalUtilOptind >= argc )
36048             {
36049                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
36050                 goto usage;
36051             }
36052             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
36053             globalUtilOptind++;
36054             if ( pPars->nBTLimit < 0 )
36055                 goto usage;
36056             break;
36057         case 'a':
36058             pPars->fAppend ^= 1;
36059             break;
36060         case 'c':
36061             pPars->fVerify ^= 1;
36062             break;
36063         case 'v':
36064             pPars->fVerbose ^= 1;
36065             break;
36066         default:
36067             goto usage;
36068         }
36069     }
36070     if ( pAbc->pGia == NULL )
36071     {
36072         Abc_Print( -1, "Abc_CommandAbc9CFraig(): There is no AIG.\n" );
36073         return 1;
36074     }
36075     pTemp = Ssc_PerformSweepingConstr( pAbc->pGia, pPars );
36076     Abc_FrameUpdateGia( pAbc, pTemp );
36077     return 0;
36078 
36079 usage:
36080     Abc_Print( -2, "usage: &cfraig [-WC <num>] [-acvh]\n" );
36081     Abc_Print( -2, "\t         performs combinational SAT sweeping under constraints\n" );
36082     Abc_Print( -2, "\t         which are present in the AIG or set manually using \"constr\"\n" );
36083     Abc_Print( -2, "\t         (constraints are listed as last POs and true when they are 0)\n" );
36084     Abc_Print( -2, "\t-W num : the number of simulation words [default = %d]\n", pPars->nWords );
36085     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", pPars->nBTLimit );
36086     Abc_Print( -2, "\t-a     : toggle appending constraints to the result [default = %s]\n", pPars->fAppend? "yes": "no" );
36087     Abc_Print( -2, "\t-c     : toggle performing internal verification [default = %s]\n", pPars->fVerify? "yes": "no" );
36088     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
36089     Abc_Print( -2, "\t-h     : print the command usage\n");
36090     return 1;
36091 }
36092 
36093 /**Function*************************************************************
36094 
36095   Synopsis    []
36096 
36097   Description []
36098 
36099   SideEffects []
36100 
36101   SeeAlso     []
36102 
36103 ***********************************************************************/
Abc_CommandAbc9Srm(Abc_Frame_t * pAbc,int argc,char ** argv)36104 int Abc_CommandAbc9Srm( Abc_Frame_t * pAbc, int argc, char ** argv )
36105 {
36106     char * pFileNameIn = NULL;
36107     char pFileName[10] = "gsrm.aig", pFileName2[10] = "gsyn.aig";
36108     Gia_Man_t * pTemp, * pAux;
36109     int c, fVerbose = 0;
36110     int fSynthesis = 0;
36111     int fSpeculate = 1;
36112     int fSkipSome = 0;
36113     int fDualOut = 0;
36114     Extra_UtilGetoptReset();
36115     while ( ( c = Extra_UtilGetopt( argc, argv, "Adrsfvh" ) ) != EOF )
36116     {
36117         switch ( c )
36118         {
36119         case 'A':
36120             if ( globalUtilOptind >= argc )
36121             {
36122                 Abc_Print( -1, "Command line switch \"-A\" should be followed by a file name.\n" );
36123                 goto usage;
36124             }
36125             pFileNameIn = argv[globalUtilOptind];
36126             globalUtilOptind++;
36127             break;
36128         case 'd':
36129             fDualOut ^= 1;
36130             break;
36131         case 'r':
36132             fSynthesis ^= 1;
36133             break;
36134         case 's':
36135             fSpeculate ^= 1;
36136             break;
36137         case 'f':
36138             fSkipSome ^= 1;
36139             break;
36140         case 'v':
36141             fVerbose ^= 1;
36142             break;
36143         case 'h':
36144             goto usage;
36145         default:
36146             goto usage;
36147         }
36148     }
36149     if ( pAbc->pGia == NULL )
36150     {
36151         Abc_Print( -1, "Abc_CommandAbc9Srm(): There is no AIG.\n" );
36152         return 1;
36153     }
36154     sprintf(pFileName,  "gsrm%s.aig", fSpeculate? "" : "s" );
36155     sprintf(pFileName2, "gsyn%s.aig", fSpeculate? "" : "s" );
36156     pTemp = Gia_ManSpecReduce( pAbc->pGia, fDualOut, fSynthesis, fSpeculate, fSkipSome, fVerbose );
36157     if ( pTemp )
36158     {
36159         if ( fSpeculate )
36160         {
36161             pTemp = Gia_ManSeqStructSweep( pAux = pTemp, 1, 1, 0 );
36162             Gia_ManStop( pAux );
36163         }
36164         Gia_AigerWrite( pTemp, pFileNameIn ? pFileNameIn : pFileName, 0, 0, 0 );
36165         Abc_Print( 1, "Speculatively reduced model was written into file \"%s\".\n", pFileName );
36166         Gia_ManPrintStatsShort( pTemp );
36167         Gia_ManStop( pTemp );
36168     }
36169     if ( fSynthesis )
36170     {
36171         pTemp = Gia_ManEquivReduce( pAbc->pGia, 1, fDualOut, 0, fVerbose );
36172         if ( pTemp )
36173         {
36174             pTemp = Gia_ManSeqStructSweep( pAux = pTemp, 1, 1, 0 );
36175             Gia_ManStop( pAux );
36176 
36177             Gia_AigerWrite( pTemp, pFileName2, 0, 0, 0 );
36178             Abc_Print( 1, "Reduced original network was written into file \"%s\".\n", pFileName2 );
36179             Gia_ManPrintStatsShort( pTemp );
36180             Gia_ManStop( pTemp );
36181         }
36182     }
36183     return 0;
36184 
36185 usage:
36186     Abc_Print( -2, "usage: &srm [-A file] [-drsfvh]\n" );
36187     Abc_Print( -2, "\t          writes speculatively reduced model into file \"%s\"\n", pFileName );
36188     Abc_Print( -2, "\t-A file : file name for dumping speculative-reduced model [default = \"gsrm.aig\"]\n" );
36189     Abc_Print( -2, "\t-d      : toggle creating dual-output miter [default = %s]\n", fDualOut? "yes": "no" );
36190     Abc_Print( -2, "\t-r      : toggle writing reduced network for synthesis [default = %s]\n", fSynthesis? "yes": "no" );
36191     Abc_Print( -2, "\t-s      : toggle using speculation at the internal nodes [default = %s]\n", fSpeculate? "yes": "no" );
36192     Abc_Print( -2, "\t-f      : toggle filtering to remove redundant equivalences [default = %s]\n", fSkipSome? "yes": "no" );
36193     Abc_Print( -2, "\t-v      : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
36194     Abc_Print( -2, "\t-h      : print the command usage\n");
36195     return 1;
36196 }
36197 
36198 
36199 /**Function*************************************************************
36200 
36201   Synopsis    []
36202 
36203   Description []
36204 
36205   SideEffects []
36206 
36207   SeeAlso     []
36208 
36209 ***********************************************************************/
Abc_CommandAbc9Srm2(Abc_Frame_t * pAbc,int argc,char ** argv)36210 int Abc_CommandAbc9Srm2( Abc_Frame_t * pAbc, int argc, char ** argv )
36211 {
36212     char pFileName[10], * pFileName1, * pFileName2;
36213     Gia_Man_t * pTemp, * pAux;
36214     int fLatchA = 0, fLatchB = 0;
36215     int c, fVerbose = 0;
36216     Extra_UtilGetoptReset();
36217     while ( ( c = Extra_UtilGetopt( argc, argv, "abvh" ) ) != EOF )
36218     {
36219         switch ( c )
36220         {
36221         case 'a':
36222             fLatchA ^= 1;
36223             break;
36224         case 'b':
36225             fLatchB ^= 1;
36226             break;
36227         case 'v':
36228             fVerbose ^= 1;
36229             break;
36230         case 'h':
36231             goto usage;
36232         default:
36233             goto usage;
36234         }
36235     }
36236     if ( pAbc->pGia == NULL )
36237     {
36238         Abc_Print( -1, "Abc_CommandAbc9Srm2(): There is no AIG.\n" );
36239         return 1;
36240     }
36241     if ( pAbc->pGia->pReprs == NULL || pAbc->pGia->pNexts == NULL )
36242     {
36243         Abc_Print( -1, "Equivalences are not defined.\n" );
36244         return 0;
36245     }
36246     if ( argc != globalUtilOptind + 2 )
36247     {
36248         Abc_Print( -1, "Abc_CommandAbc9Srm2(): Expecting two file names on the command line.\n" );
36249         return 1;
36250     }
36251     // get the input file name
36252     pFileName1 = argv[globalUtilOptind];
36253     pFileName2 = argv[globalUtilOptind+1];
36254     // create file name
36255     sprintf(pFileName,  "gsrm.aig" );
36256     pTemp = Gia_ManDup( pAbc->pGia );
36257     // copy equivalences
36258     pTemp->pReprs = ABC_ALLOC( Gia_Rpr_t, Gia_ManObjNum(pTemp) );
36259     memcpy( pTemp->pReprs, pAbc->pGia->pReprs, sizeof(Gia_Rpr_t) * Gia_ManObjNum(pTemp) );
36260     pTemp->pNexts = ABC_ALLOC( int, Gia_ManObjNum(pTemp) );
36261     memcpy( pTemp->pNexts, pAbc->pGia->pNexts, sizeof(int) * Gia_ManObjNum(pTemp) );
36262 //Gia_ManPrintStats( pTemp, 0 );
36263     // filter the classes
36264     if ( !Gia_ManFilterEquivsForSpeculation( pTemp, pFileName1, pFileName2, fLatchA, fLatchB ) )
36265     {
36266         Gia_ManStop( pTemp );
36267         Abc_Print( -1, "Filtering equivalences has failed.\n" );
36268         return 1;
36269     }
36270 //Gia_ManPrintStats( pTemp, 0 );
36271     pTemp = Gia_ManSpecReduce( pAux = pTemp, 0, 0, 1, 0, 0 );
36272     Gia_ManStop( pAux );
36273     if ( pTemp )
36274     {
36275         pTemp = Gia_ManSeqStructSweep( pAux = pTemp, 1, 1, 0 );
36276         Gia_ManStop( pAux );
36277 
36278         Gia_AigerWrite( pTemp, pFileName, 0, 0, 0 );
36279         Abc_Print( 1, "Speculatively reduced model was written into file \"%s\".\n", pFileName );
36280         Gia_ManPrintStatsShort( pTemp );
36281         Gia_ManStop( pTemp );
36282     }
36283     return 0;
36284 
36285 usage:
36286     Abc_Print( -2, "usage: &srm2 [-abvh] <PartA_FileName> <PartB_FileName>\n" );
36287     Abc_Print( -2, "\t         writes speculatively reduced model into file \"%s\"\n", pFileName );
36288     Abc_Print( -2, "\t         only preserves equivalences across PartA and PartB\n" );
36289     Abc_Print( -2, "\t-a     : toggle using latches only in PartA [default = %s]\n", fLatchA? "yes": "no" );
36290     Abc_Print( -2, "\t-b     : toggle using latches only in PartB [default = %s]\n", fLatchB? "yes": "no" );
36291     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
36292     Abc_Print( -2, "\t-h     : print the command usage\n");
36293     return 1;
36294 }
36295 
36296 /**Function*************************************************************
36297 
36298   Synopsis    []
36299 
36300   Description []
36301 
36302   SideEffects []
36303 
36304   SeeAlso     []
36305 
36306 ***********************************************************************/
Abc_CommandAbc9Filter(Abc_Frame_t * pAbc,int argc,char ** argv)36307 int Abc_CommandAbc9Filter( Abc_Frame_t * pAbc, int argc, char ** argv )
36308 {
36309     char * pFileName1 = NULL, * pFileName2 = NULL;
36310     int fFlopsOnly = 0, fFlopsWith = 0, fUseRiDrivers = 0;
36311     int c, fVerbose = 0;
36312     Extra_UtilGetoptReset();
36313     while ( ( c = Extra_UtilGetopt( argc, argv, "fgivh" ) ) != EOF )
36314     {
36315         switch ( c )
36316         {
36317         case 'f':
36318             fFlopsOnly ^= 1;
36319             break;
36320         case 'g':
36321             fFlopsWith ^= 1;
36322             break;
36323         case 'i':
36324             fUseRiDrivers ^= 1;
36325             break;
36326         case 'v':
36327             fVerbose ^= 1;
36328             break;
36329         case 'h':
36330             goto usage;
36331         default:
36332             goto usage;
36333         }
36334     }
36335     if ( pAbc->pGia == NULL )
36336     {
36337         Abc_Print( -1, "Abc_CommandAbc9Srm2(): There is no AIG.\n" );
36338         return 1;
36339     }
36340     if ( pAbc->pGia->pReprs == NULL || pAbc->pGia->pNexts == NULL )
36341     {
36342         Abc_Print( -1, "Equivalences are not defined.\n" );
36343         return 0;
36344     }
36345     if ( argc != globalUtilOptind && argc != globalUtilOptind + 2 )
36346     {
36347         Abc_Print( -1, "Abc_CommandAbc9Srm2(): Expecting two file names on the command line.\n" );
36348         return 1;
36349     }
36350     // filter using one of the choices
36351     if ( fFlopsOnly ^ fFlopsWith )
36352         Gia_ManFilterEquivsUsingLatches( pAbc->pGia, fFlopsOnly, fFlopsWith, fUseRiDrivers );
36353     // get the input file name
36354     if ( argc == globalUtilOptind + 2 )
36355     {
36356         pFileName1 = argv[globalUtilOptind];
36357         pFileName2 = argv[globalUtilOptind+1];
36358         if ( !Gia_ManFilterEquivsUsingParts( pAbc->pGia, pFileName1, pFileName2 ) )
36359         {
36360             Abc_Print( -1, "Filtering equivalences using PartA and PartB has failed.\n" );
36361             return 1;
36362         }
36363     }
36364     return 0;
36365 
36366 usage:
36367     Abc_Print( -2, "usage: &filter [-fgivh] <PartA_FileName> <PartB_FileName>\n" );
36368     Abc_Print( -2, "\t         performs filtering of equivalence classes\n" );
36369     Abc_Print( -2, "\t         (if Parts A/B are given, removes classes composed of one part)\n" );
36370     Abc_Print( -2, "\t-f     : toggle removing all elements except flops [default = %s]\n", fFlopsOnly? "yes": "no" );
36371     Abc_Print( -2, "\t-g     : toggle removing classes without flops [default = %s]\n", fFlopsWith? "yes": "no" );
36372     Abc_Print( -2, "\t-i     : toggle using flop inputs instead of flop outputs [default = %s]\n", fUseRiDrivers? "yes": "no" );
36373     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
36374     Abc_Print( -2, "\t-h     : print the command usage\n");
36375     return 1;
36376 }
36377 
36378 /**Function*************************************************************
36379 
36380   Synopsis    []
36381 
36382   Description []
36383 
36384   SideEffects []
36385 
36386   SeeAlso     []
36387 
36388 ***********************************************************************/
Abc_CommandAbc9Reduce(Abc_Frame_t * pAbc,int argc,char ** argv)36389 int Abc_CommandAbc9Reduce( Abc_Frame_t * pAbc, int argc, char ** argv )
36390 {
36391     Gia_Man_t * pTemp, * pTemp2;
36392     int c, fVerbose = 0;
36393     int fUseAll = 0;
36394     int fDualOut = 0;
36395     Extra_UtilGetoptReset();
36396     while ( ( c = Extra_UtilGetopt( argc, argv, "advh" ) ) != EOF )
36397     {
36398         switch ( c )
36399         {
36400         case 'a':
36401             fUseAll ^= 1;
36402             break;
36403         case 'd':
36404             fDualOut ^= 1;
36405             break;
36406         case 'v':
36407             fVerbose ^= 1;
36408             break;
36409         case 'h':
36410             goto usage;
36411         default:
36412             goto usage;
36413         }
36414     }
36415     if ( pAbc->pGia == NULL )
36416     {
36417         Abc_Print( -1, "Abc_CommandAbc9Reduce(): There is no AIG.\n" );
36418         return 1;
36419     }
36420     if ( fUseAll )
36421     {
36422         pTemp = Gia_ManEquivReduce( pAbc->pGia, fUseAll, fDualOut, 0, fVerbose );
36423         pTemp = Gia_ManSeqStructSweep( pTemp2 = pTemp, 1, 1, 0 );
36424         Gia_ManStop( pTemp2 );
36425     }
36426     else
36427         pTemp = Gia_ManEquivReduceAndRemap( pAbc->pGia, 1, fDualOut );
36428     Abc_FrameUpdateGia( pAbc, pTemp );
36429     return 0;
36430 
36431 usage:
36432     Abc_Print( -2, "usage: &reduce [-advh]\n" );
36433     Abc_Print( -2, "\t         reduces the circuit using equivalence classes\n" );
36434     Abc_Print( -2, "\t-a     : toggle merging all equivalences [default = %s]\n", fUseAll? "yes": "no" );
36435     Abc_Print( -2, "\t-d     : toggle using dual-output merging [default = %s]\n", fDualOut? "yes": "no" );
36436     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
36437     Abc_Print( -2, "\t-h     : print the command usage\n");
36438     return 1;
36439 }
36440 
36441 /**Function*************************************************************
36442 
36443   Synopsis    []
36444 
36445   Description []
36446 
36447   SideEffects []
36448 
36449   SeeAlso     []
36450 
36451 ***********************************************************************/
Abc_CommandAbc9EquivMark(Abc_Frame_t * pAbc,int argc,char ** argv)36452 int Abc_CommandAbc9EquivMark( Abc_Frame_t * pAbc, int argc, char ** argv )
36453 {
36454     extern void Gia_ManEquivMark( Gia_Man_t * p, char * pFileName, int fSkipSome, int fVerbose );
36455     char * pFileName;
36456     int c, fVerbose = 0;
36457     int fSkipSome = 0;
36458     Extra_UtilGetoptReset();
36459     while ( ( c = Extra_UtilGetopt( argc, argv, "fvh" ) ) != EOF )
36460     {
36461         switch ( c )
36462         {
36463         case 'f':
36464             fSkipSome ^= 1;
36465             break;
36466         case 'v':
36467             fVerbose ^= 1;
36468             break;
36469         case 'h':
36470             goto usage;
36471         default:
36472             goto usage;
36473         }
36474     }
36475     if ( pAbc->pGia == NULL )
36476     {
36477         Abc_Print( -1, "Abc_CommandAbc9EquivMark(): There is no AIG.\n" );
36478         return 1;
36479     }
36480     if ( argc != globalUtilOptind + 1 )
36481         goto usage;
36482     // get the input file name
36483     pFileName = argv[globalUtilOptind];
36484     // mark equivalences
36485     Gia_ManEquivMark( pAbc->pGia, pFileName, fSkipSome, fVerbose );
36486     return 0;
36487 
36488 usage:
36489     Abc_Print( -2, "usage: &equiv_mark [-fvh] <miter.aig>\n" );
36490     Abc_Print( -2, "\t              marks equivalences using an external miter\n" );
36491     Abc_Print( -2, "\t-f          : toggle the use of filtered equivalences [default = %s]\n", fSkipSome? "yes": "no" );
36492     Abc_Print( -2, "\t-v          : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
36493     Abc_Print( -2, "\t-h          : print the command usage\n");
36494     Abc_Print( -2, "\t<miter.aig> : file with the external miter to read\n");
36495     Abc_Print( -2, "\t              \n" );
36496     Abc_Print( -2, "\t              The external miter should be generated by &srm -s\n" );
36497     Abc_Print( -2, "\t              and (partially) solved by any verification engine(s).\n" );
36498     Abc_Print( -2, "\t              The external miter should have as many POs as\n" );
36499     Abc_Print( -2, "\t              the number of POs in the current AIG plus\n" );
36500     Abc_Print( -2, "\t              the number of equivalences in the current AIG.\n" );
36501     Abc_Print( -2, "\t              If some POs are proved, the corresponding equivs\n" );
36502     Abc_Print( -2, "\t              are marked as proved, to be reduced by &reduce.\n" );
36503     return 1;
36504 }
36505 
36506 /**Function*************************************************************
36507 
36508   Synopsis    []
36509 
36510   Description []
36511 
36512   SideEffects []
36513 
36514   SeeAlso     []
36515 
36516 ***********************************************************************/
Abc_CommandAbc9EquivFilter(Abc_Frame_t * pAbc,int argc,char ** argv)36517 int Abc_CommandAbc9EquivFilter( Abc_Frame_t * pAbc, int argc, char ** argv )
36518 {
36519     extern void Gia_ManEquivFilter( Gia_Man_t * p, Vec_Int_t * vPoIds, int fVerbose );
36520     int c, fVerbose = 0;
36521     Extra_UtilGetoptReset();
36522     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
36523     {
36524         switch ( c )
36525         {
36526         case 'v':
36527             fVerbose ^= 1;
36528             break;
36529         case 'h':
36530             goto usage;
36531         default:
36532             goto usage;
36533         }
36534     }
36535     if ( pAbc->pGia == NULL )
36536     {
36537         Abc_Print( -1, "Abc_CommandAbc9EquivFilter(): There is no AIG.\n" );
36538         return 1;
36539     }
36540     Gia_ManEquivFilter( pAbc->pGia, pAbc->vAbcObjIds, fVerbose );
36541     return 0;
36542 
36543 usage:
36544     Abc_Print( -2, "usage: &equiv_filter [-vh]\n" );
36545     Abc_Print( -2, "\t              filters equivalence candidates after disproving some SRM outputs\n" );
36546     Abc_Print( -2, "\t              (the array of disproved outputs should be given as pAbc->vAbcObjIds)\n" );
36547     Abc_Print( -2, "\t-v          : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
36548     Abc_Print( -2, "\t-h          : print the command usage\n");
36549     return 1;
36550 }
36551 
36552 /**Function*************************************************************
36553 
36554   Synopsis    []
36555 
36556   Description []
36557 
36558   SideEffects []
36559 
36560   SeeAlso     []
36561 
36562 ***********************************************************************/
Abc_CommandAbc9Cec(Abc_Frame_t * pAbc,int argc,char ** argv)36563 int Abc_CommandAbc9Cec( Abc_Frame_t * pAbc, int argc, char ** argv )
36564 {
36565     Cec_ParCec_t ParsCec, * pPars = &ParsCec;
36566     FILE * pFile;
36567     Gia_Man_t * pGias[2] = {NULL, NULL}, * pMiter;
36568     char ** pArgvNew;
36569     int c, nArgcNew, fMiter = 0, fDualOutput = 0, fDumpMiter = 0;
36570     Cec_ManCecSetDefaultParams( pPars );
36571     Extra_UtilGetoptReset();
36572     while ( ( c = Extra_UtilGetopt( argc, argv, "CTnmdasvh" ) ) != EOF )
36573     {
36574         switch ( c )
36575         {
36576         case 'C':
36577             if ( globalUtilOptind >= argc )
36578             {
36579                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
36580                 goto usage;
36581             }
36582             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
36583             globalUtilOptind++;
36584             if ( pPars->nBTLimit < 0 )
36585                 goto usage;
36586             break;
36587         case 'T':
36588             if ( globalUtilOptind >= argc )
36589             {
36590                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
36591                 goto usage;
36592             }
36593             pPars->TimeLimit = atoi(argv[globalUtilOptind]);
36594             globalUtilOptind++;
36595             if ( pPars->TimeLimit < 0 )
36596                 goto usage;
36597             break;
36598         case 'n':
36599             pPars->fNaive ^= 1;
36600             break;
36601         case 'm':
36602             fMiter ^= 1;
36603             break;
36604         case 'd':
36605             fDualOutput ^= 1;
36606             break;
36607         case 'a':
36608             fDumpMiter ^= 1;
36609             break;
36610         case 's':
36611             pPars->fSilent ^= 1;
36612             break;
36613         case 'v':
36614             pPars->fVerbose ^= 1;
36615             break;
36616         case 'h':
36617             goto usage;
36618         default:
36619             goto usage;
36620         }
36621     }
36622     pArgvNew = argv + globalUtilOptind;
36623     nArgcNew = argc - globalUtilOptind;
36624     if ( fMiter )
36625     {
36626         if ( pAbc->pGia == NULL || nArgcNew != 0 )
36627         {
36628             Abc_Print( -1, "Abc_CommandAbc9Cec(): A miter cannot be given as an argument of command &cec and should be entered using &r.\n" );
36629             return 1;
36630         }
36631         if ( fDualOutput )
36632         {
36633             if ( Gia_ManPoNum(pAbc->pGia) & 1 )
36634             {
36635                 Abc_Print( -1, "The dual-output miter should have an even number of outputs.\n" );
36636                 return 1;
36637             }
36638             if ( !pPars->fSilent )
36639             Abc_Print( 1, "Assuming the current network is a double-output miter.\n" );
36640             pAbc->Status = Cec_ManVerify( pAbc->pGia, pPars );
36641         }
36642         else
36643         {
36644             Gia_Man_t * pTemp;
36645             if ( !pPars->fSilent )
36646             Abc_Print( 1, "Assuming the current network is a single-output miter.\n" );
36647             pTemp = Gia_ManDemiterToDual( pAbc->pGia );
36648             pAbc->Status = Cec_ManVerify( pTemp, pPars );
36649             ABC_SWAP( Abc_Cex_t *, pAbc->pGia->pCexComb, pTemp->pCexComb );
36650             Gia_ManStop( pTemp );
36651         }
36652         Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexComb );
36653         return 0;
36654     }
36655     if ( nArgcNew > 2 )
36656     {
36657         Abc_Print( -1, "Abc_CommandAbc9Cec(): Wrong number of command-line arguments.\n" );
36658         return 1;
36659     }
36660     if ( nArgcNew == 2 )
36661     {
36662         char * pFileNames[2] = { pArgvNew[0], pArgvNew[1] }, * pTemp;
36663         int n;
36664         for ( n = 0; n < 2; n++ )
36665         {
36666             // fix the wrong symbol
36667             for ( pTemp = pFileNames[n]; *pTemp; pTemp++ )
36668                 if ( *pTemp == '>' )
36669                     *pTemp = '\\';
36670             if ( (pFile = fopen( pFileNames[n], "r" )) == NULL )
36671             {
36672                 Abc_Print( -1, "Cannot open input file \"%s\". ", pFileNames[n] );
36673                 if ( (pFileNames[n] = Extra_FileGetSimilarName( pFileNames[n], ".aig", NULL, NULL, NULL, NULL )) )
36674                     Abc_Print( 1, "Did you mean \"%s\"?", pFileNames[n] );
36675                 Abc_Print( 1, "\n" );
36676                 return 1;
36677             }
36678             fclose( pFile );
36679             pGias[n] = Gia_AigerRead( pFileNames[n], 0, 0, 0 );
36680             if ( pGias[n] == NULL )
36681             {
36682                 Abc_Print( -1, "Reading AIGER from file \"%s\" has failed.\n", pFileNames[n] );
36683                 return 0;
36684             }
36685         }
36686     }
36687     else
36688     {
36689         char * FileName, * pTemp;
36690         if ( pAbc->pGia == NULL )
36691         {
36692             Abc_Print( -1, "Abc_CommandAbc9Cec(): There is no current AIG.\n" );
36693             return 1;
36694         }
36695         pGias[0] = pAbc->pGia;
36696         if ( nArgcNew == 1 )
36697             FileName = pArgvNew[0];
36698         else
36699         {
36700             assert( nArgcNew == 0 );
36701             if ( pAbc->pGia->pSpec == NULL )
36702             {
36703                 Abc_Print( -1, "File name is not given on the command line.\n" );
36704                 return 1;
36705             }
36706             FileName = pAbc->pGia->pSpec;
36707         }
36708         // fix the wrong symbol
36709         for ( pTemp = FileName; *pTemp; pTemp++ )
36710             if ( *pTemp == '>' )
36711                 *pTemp = '\\';
36712         if ( (pFile = fopen( FileName, "r" )) == NULL )
36713         {
36714             Abc_Print( -1, "Cannot open input file \"%s\". ", FileName );
36715             if ( (FileName = Extra_FileGetSimilarName( FileName, ".aig", NULL, NULL, NULL, NULL )) )
36716                 Abc_Print( 1, "Did you mean \"%s\"?", FileName );
36717             Abc_Print( 1, "\n" );
36718             return 1;
36719         }
36720         fclose( pFile );
36721         pGias[1] = Gia_AigerRead( FileName, 0, 0, 0 );
36722         if ( pGias[1] == NULL )
36723         {
36724             Abc_Print( -1, "Reading AIGER has failed.\n" );
36725             return 0;
36726         }
36727     }
36728     // compute the miter
36729     pMiter = Gia_ManMiter( pGias[0], pGias[1], 0, 1, 0, 0, pPars->fVerbose );
36730     if ( pMiter )
36731     {
36732         if ( fDumpMiter )
36733         {
36734             Abc_Print( 0, "The verification miter is written into file \"%s\".\n", "cec_miter.aig" );
36735             Gia_AigerWrite( pMiter, "cec_miter.aig", 0, 0, 0 );
36736         }
36737         pAbc->Status = Cec_ManVerify( pMiter, pPars );
36738         Abc_FrameReplaceCex( pAbc, &pGias[0]->pCexComb );
36739         Gia_ManStop( pMiter );
36740     }
36741     if ( pGias[0] != pAbc->pGia )
36742         Gia_ManStop( pGias[0] );
36743     Gia_ManStop( pGias[1] );
36744     return 0;
36745 
36746 usage:
36747     Abc_Print( -2, "usage: &cec [-CT num] [-nmdasvh]\n" );
36748     Abc_Print( -2, "\t         new combinational equivalence checker\n" );
36749     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", pPars->nBTLimit );
36750     Abc_Print( -2, "\t-T num : approximate runtime limit in seconds [default = %d]\n", pPars->TimeLimit );
36751     Abc_Print( -2, "\t-n     : toggle using naive SAT-based checking [default = %s]\n", pPars->fNaive? "yes":"no");
36752     Abc_Print( -2, "\t-m     : toggle miter vs. two circuits [default = %s]\n", fMiter? "miter":"two circuits");
36753     Abc_Print( -2, "\t-d     : toggle using dual output miter [default = %s]\n", fDualOutput? "yes":"no");
36754     Abc_Print( -2, "\t-a     : toggle writing dual-output miter [default = %s]\n", fDumpMiter? "yes":"no");
36755     Abc_Print( -2, "\t-s     : toggle silent operation [default = %s]\n", pPars->fSilent ? "yes":"no");
36756     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", pPars->fVerbose? "yes":"no");
36757     Abc_Print( -2, "\t-h     : print the command usage\n");
36758     return 1;
36759 }
36760 
36761 /**Function*************************************************************
36762 
36763   Synopsis    []
36764 
36765   Description []
36766 
36767   SideEffects []
36768 
36769   SeeAlso     []
36770 
36771 ***********************************************************************/
Abc_CommandAbc9Verify(Abc_Frame_t * pAbc,int argc,char ** argv)36772 int Abc_CommandAbc9Verify( Abc_Frame_t * pAbc, int argc, char ** argv )
36773 {
36774     char * pFileSpec = NULL;
36775     int c, nBTLimit = 1000, nTimeLim = 0, fSeq = 0, fDumpFiles = 0, fVerbose = 0;
36776     Extra_UtilGetoptReset();
36777     while ( ( c = Extra_UtilGetopt( argc, argv, "CTsdvh" ) ) != EOF )
36778     {
36779         switch ( c )
36780         {
36781         case 'C':
36782             if ( globalUtilOptind >= argc )
36783             {
36784                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
36785                 goto usage;
36786             }
36787             nBTLimit = atoi(argv[globalUtilOptind]);
36788             globalUtilOptind++;
36789             if ( nBTLimit < 0 )
36790                 goto usage;
36791             break;
36792         case 'T':
36793             if ( globalUtilOptind >= argc )
36794             {
36795                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
36796                 goto usage;
36797             }
36798             nTimeLim = atoi(argv[globalUtilOptind]);
36799             globalUtilOptind++;
36800             if ( nTimeLim < 0 )
36801                 goto usage;
36802             break;
36803         case 's':
36804             fSeq ^= 1;
36805             break;
36806         case 'd':
36807             fDumpFiles ^= 1;
36808             break;
36809         case 'v':
36810             fVerbose ^= 1;
36811             break;
36812         case 'h':
36813             goto usage;
36814         default:
36815             goto usage;
36816         }
36817     }
36818     if ( argc == globalUtilOptind + 1 )
36819     {
36820         pFileSpec = argv[globalUtilOptind];
36821         Extra_FileNameCorrectPath( pFileSpec );
36822         printf( "Taking spec from file \"%s\".\n", pFileSpec );
36823     }
36824     Gia_ManVerifyWithBoxes( pAbc->pGia, nBTLimit, nTimeLim, fSeq, fDumpFiles, fVerbose, pFileSpec );
36825     return 0;
36826 
36827 usage:
36828     Abc_Print( -2, "usage: &verify [-CT num] [-sdvh] <file>\n" );
36829     Abc_Print( -2, "\t         performs verification of combinational design\n" );
36830     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", nBTLimit );
36831     Abc_Print( -2, "\t-T num : approximate runtime limit in seconds [default = %d]\n",  nTimeLim );
36832     Abc_Print( -2, "\t-s     : toggle using sequential verification [default = %s]\n",  fSeq? "yes":"no");
36833     Abc_Print( -2, "\t-d     : toggle dumping AIGs to be compared [default = %s]\n",    fDumpFiles? "yes":"no");
36834     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n",                 fVerbose? "yes":"no");
36835     Abc_Print( -2, "\t-h     : print the command usage\n");
36836     Abc_Print( -2, "\t<file> : optional file name with the spec [default = not used]\n" );
36837     return 1;
36838 }
36839 
36840 /**Function*************************************************************
36841 
36842   Synopsis    []
36843 
36844   Description []
36845 
36846   SideEffects []
36847 
36848   SeeAlso     []
36849 
36850 ***********************************************************************/
Abc_CommandAbc9Sweep(Abc_Frame_t * pAbc,int argc,char ** argv)36851 int Abc_CommandAbc9Sweep( Abc_Frame_t * pAbc, int argc, char ** argv )
36852 {
36853     Gia_Man_t * pTemp;
36854     Dch_Pars_t Pars, * pPars = &Pars;
36855     int c;
36856     Dch_ManSetDefaultParams( pPars );
36857     Extra_UtilGetoptReset();
36858     while ( ( c = Extra_UtilGetopt( argc, argv, "WCStvh" ) ) != EOF )
36859     {
36860         switch ( c )
36861         {
36862         case 'W':
36863             if ( globalUtilOptind >= argc )
36864             {
36865                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
36866                 goto usage;
36867             }
36868             pPars->nWords = atoi(argv[globalUtilOptind]);
36869             globalUtilOptind++;
36870             if ( pPars->nWords < 0 )
36871                 goto usage;
36872             break;
36873         case 'C':
36874             if ( globalUtilOptind >= argc )
36875             {
36876                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
36877                 goto usage;
36878             }
36879             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
36880             globalUtilOptind++;
36881             if ( pPars->nBTLimit < 0 )
36882                 goto usage;
36883             break;
36884         case 'S':
36885             if ( globalUtilOptind >= argc )
36886             {
36887                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
36888                 goto usage;
36889             }
36890             pPars->nSatVarMax = atoi(argv[globalUtilOptind]);
36891             globalUtilOptind++;
36892             if ( pPars->nSatVarMax < 0 )
36893                 goto usage;
36894             break;
36895         case 't':
36896             pPars->fSimulateTfo ^= 1;
36897             break;
36898         case 'v':
36899             pPars->fVerbose ^= 1;
36900             break;
36901         case 'h':
36902             goto usage;
36903         default:
36904             goto usage;
36905         }
36906     }
36907     if ( pAbc->pGia == NULL )
36908     {
36909         Abc_Print( -1, "Abc_CommandAbc9Sweep(): There is no AIG.\n" );
36910         return 1;
36911     }
36912     if ( Gia_ManBoxNum(pAbc->pGia) && pAbc->pGia->pAigExtra == NULL )
36913     {
36914         printf( "Timing manager is given but there is no GIA of boxes.\n" );
36915         return 0;
36916     }
36917     if ( Gia_ManBoxNum(pAbc->pGia) )
36918         pTemp = Gia_ManSweepWithBoxes( pAbc->pGia, pPars, NULL, 0, 0, pPars->fVerbose, 0 );
36919     else
36920         pTemp = Gia_ManFraigSweepSimple( pAbc->pGia, pPars );
36921     Abc_FrameUpdateGia( pAbc, pTemp );
36922     return 0;
36923 
36924 usage:
36925     Abc_Print( -2, "usage: &sweep [-WCS num] [-tvh]\n" );
36926     Abc_Print( -2, "\t         performs SAT sweeping for AIG with boxes\n" );
36927     Abc_Print( -2, "\t-W num : the max number of simulation words [default = %d]\n", pPars->nWords );
36928     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", pPars->nBTLimit );
36929     Abc_Print( -2, "\t-S num : the max number of SAT variables [default = %d]\n", pPars->nSatVarMax );
36930     Abc_Print( -2, "\t-t     : toggle simulation of the TFO classes [default = %s]\n", pPars->fSimulateTfo? "yes": "no" );
36931     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", pPars->fVerbose? "yes": "no" );
36932     Abc_Print( -2, "\t-h     : print the command usage\n");
36933     return 1;
36934 }
36935 
36936 
36937 /**Function*************************************************************
36938 
36939   Synopsis    []
36940 
36941   Description []
36942 
36943   SideEffects []
36944 
36945   SeeAlso     []
36946 
36947 ***********************************************************************/
Abc_CommandAbc9Force(Abc_Frame_t * pAbc,int argc,char ** argv)36948 int Abc_CommandAbc9Force( Abc_Frame_t * pAbc, int argc, char ** argv )
36949 {
36950     int nIters     = 20;
36951     int fClustered =  1;
36952     int fVerbose   =  1;
36953     int c;
36954     Extra_UtilGetoptReset();
36955     while ( ( c = Extra_UtilGetopt( argc, argv, "Icvh" ) ) != EOF )
36956     {
36957         switch ( c )
36958         {
36959         case 'I':
36960             if ( globalUtilOptind >= argc )
36961             {
36962                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
36963                 goto usage;
36964             }
36965             nIters = atoi(argv[globalUtilOptind]);
36966             globalUtilOptind++;
36967             if ( nIters < 0 )
36968                 goto usage;
36969             break;
36970         case 'c':
36971             fClustered ^= 1;
36972             break;
36973         case 'v':
36974             fVerbose ^= 1;
36975             break;
36976         case 'h':
36977             goto usage;
36978         default:
36979             goto usage;
36980         }
36981     }
36982     if ( pAbc->pGia == NULL )
36983     {
36984         Abc_Print( -1, "Abc_CommandAbc9Force(): There is no AIG.\n" );
36985         return 1;
36986     }
36987     For_ManExperiment( pAbc->pGia, nIters, fClustered, fVerbose );
36988     return 0;
36989 
36990 usage:
36991     Abc_Print( -2, "usage: &force [-I <num>] [-cvh]\n" );
36992     Abc_Print( -2, "\t         one-dimensional placement algorithm FORCE introduced by\n" );
36993     Abc_Print( -2, "\t         F. A. Aloul, I. L. Markov, and K. A. Sakallah (GLSVLSI�03).\n" );
36994     Abc_Print( -2, "\t-I num : the number of refinement iterations [default = %d]\n", nIters );
36995     Abc_Print( -2, "\t-c     : toggle clustered representation [default = %s]\n", fClustered? "yes":"no");
36996     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes":"no");
36997     Abc_Print( -2, "\t-h     : print the command usage\n");
36998     return 1;
36999 }
37000 
37001 /**Function*************************************************************
37002 
37003   Synopsis    []
37004 
37005   Description []
37006 
37007   SideEffects []
37008 
37009   SeeAlso     []
37010 
37011 ***********************************************************************/
Abc_CommandAbc9Embed(Abc_Frame_t * pAbc,int argc,char ** argv)37012 int Abc_CommandAbc9Embed( Abc_Frame_t * pAbc, int argc, char ** argv )
37013 {
37014     Emb_Par_t Pars, * pPars = &Pars;
37015     int c;
37016     pPars->nDims      = 30;
37017     pPars->nIters     = 10;
37018     pPars->nSols      =  2;
37019     pPars->fRefine    =  0;
37020     pPars->fCluster   =  0;
37021     pPars->fDump      =  0;
37022     pPars->fDumpLarge =  0;
37023     pPars->fShowImage =  0;
37024     pPars->fVerbose   =  0;
37025     Extra_UtilGetoptReset();
37026     while ( ( c = Extra_UtilGetopt( argc, argv, "DIrcdlsvh" ) ) != EOF )
37027     {
37028         switch ( c )
37029         {
37030         case 'D':
37031             if ( globalUtilOptind >= argc )
37032             {
37033                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
37034                 goto usage;
37035             }
37036             pPars->nDims = atoi(argv[globalUtilOptind]);
37037             globalUtilOptind++;
37038             if ( pPars->nDims < 0 )
37039                 goto usage;
37040             break;
37041         case 'I':
37042             if ( globalUtilOptind >= argc )
37043             {
37044                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
37045                 goto usage;
37046             }
37047             pPars->nIters = atoi(argv[globalUtilOptind]);
37048             globalUtilOptind++;
37049             if ( pPars->nIters < 0 )
37050                 goto usage;
37051             break;
37052         case 'r':
37053             pPars->fRefine ^= 1;
37054             break;
37055         case 'c':
37056             pPars->fCluster ^= 1;
37057             break;
37058         case 'd':
37059             pPars->fDump ^= 1;
37060             break;
37061         case 'l':
37062             pPars->fDumpLarge ^= 1;
37063             break;
37064         case 's':
37065             pPars->fShowImage ^= 1;
37066             break;
37067         case 'v':
37068             pPars->fVerbose ^= 1;
37069             break;
37070         case 'h':
37071             goto usage;
37072         default:
37073             goto usage;
37074         }
37075     }
37076     if ( pAbc->pGia == NULL )
37077     {
37078         Abc_Print( -1, "Abc_CommandAbc9Embed(): There is no AIG.\n" );
37079         return 1;
37080     }
37081     Gia_ManSolveProblem( pAbc->pGia, pPars );
37082     return 0;
37083 
37084 usage:
37085     Abc_Print( -2, "usage: &embed [-DI <num>] [-rdlscvh]\n" );
37086     Abc_Print( -2, "\t         fast placement based on high-dimensional embedding from\n" );
37087     Abc_Print( -2, "\t         D. Harel and Y. Koren, \"Graph drawing by high-dimensional\n" );
37088     Abc_Print( -2, "\t         embedding\", J. Graph Algs & Apps, 2004, Vol 8(2), pp. 195-217\n" );
37089     Abc_Print( -2, "\t-D num : the number of dimensions for embedding [default = %d]\n", pPars->nDims );
37090     Abc_Print( -2, "\t-I num : the number of refinement iterations [default = %d]\n", pPars->nIters );
37091     Abc_Print( -2, "\t-r     : toggle the use of refinement [default = %s]\n", pPars->fRefine? "yes":"no");
37092     Abc_Print( -2, "\t-c     : toggle clustered representation [default = %s]\n", pPars->fCluster? "yes":"no");
37093     Abc_Print( -2, "\t-d     : toggle dumping placement into a Gnuplot file [default = %s]\n", pPars->fDump? "yes":"no");
37094     Abc_Print( -2, "\t-l     : toggle dumping Gnuplot for large placement [default = %s]\n", pPars->fDumpLarge? "yes":"no");
37095     Abc_Print( -2, "\t-s     : toggle showing image if Gnuplot is installed [default = %s]\n", pPars->fShowImage? "yes":"no");
37096     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", pPars->fVerbose? "yes":"no");
37097     Abc_Print( -2, "\t-h     : print the command usage\n");
37098     return 1;
37099 }
37100 
37101 /**Function*************************************************************
37102 
37103   Synopsis    []
37104 
37105   Description []
37106 
37107   SideEffects []
37108 
37109   SeeAlso     []
37110 
37111 ***********************************************************************/
Abc_CommandAbc9Sopb(Abc_Frame_t * pAbc,int argc,char ** argv)37112 int Abc_CommandAbc9Sopb( Abc_Frame_t * pAbc, int argc, char ** argv )
37113 {
37114     Gia_Man_t * pTemp;
37115     int nLevelMax   = 0;
37116     int nTimeWindow = 0;
37117     int nCutNum     = 8;
37118     int nRelaxRatio = 0;
37119     int c, fVerbose = 0;
37120     Extra_UtilGetoptReset();
37121     while ( ( c = Extra_UtilGetopt( argc, argv, "LWCRvh" ) ) != EOF )
37122     {
37123         switch ( c )
37124         {
37125         case 'L':
37126             if ( globalUtilOptind >= argc )
37127             {
37128                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
37129                 goto usage;
37130             }
37131             nLevelMax = atoi(argv[globalUtilOptind]);
37132             globalUtilOptind++;
37133             if ( nLevelMax < 0 )
37134                 goto usage;
37135             break;
37136         case 'W':
37137             if ( globalUtilOptind >= argc )
37138             {
37139                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
37140                 goto usage;
37141             }
37142             nTimeWindow = atoi(argv[globalUtilOptind]);
37143             globalUtilOptind++;
37144             if ( nTimeWindow < 0 )
37145                 goto usage;
37146             break;
37147         case 'C':
37148             if ( globalUtilOptind >= argc )
37149             {
37150                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
37151                 goto usage;
37152             }
37153             nCutNum = atoi(argv[globalUtilOptind]);
37154             globalUtilOptind++;
37155             if ( nCutNum < 0 )
37156                 goto usage;
37157             break;
37158         case 'R':
37159             if ( globalUtilOptind >= argc )
37160             {
37161                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
37162                 goto usage;
37163             }
37164             nRelaxRatio = atoi(argv[globalUtilOptind]);
37165             globalUtilOptind++;
37166             if ( nRelaxRatio < 0 )
37167                 goto usage;
37168             break;
37169         case 'v':
37170             fVerbose ^= 1;
37171             break;
37172         case 'h':
37173             goto usage;
37174         default:
37175             goto usage;
37176         }
37177     }
37178     if ( pAbc->pGia == NULL )
37179     {
37180         Abc_Print( -1, "Abc_CommandAbc9Sopb(): There is no AIG.\n" );
37181         return 1;
37182     }
37183     if ( nLevelMax || nTimeWindow )
37184         pTemp = Gia_ManPerformSopBalanceWin( pAbc->pGia, nLevelMax, nTimeWindow, nCutNum, nRelaxRatio, fVerbose );
37185     else
37186         pTemp = Gia_ManPerformSopBalance( pAbc->pGia, nCutNum, nRelaxRatio, fVerbose );
37187     Abc_FrameUpdateGia( pAbc, pTemp );
37188     return 0;
37189 
37190 usage:
37191     Abc_Print( -2, "usage: &sopb [-LWCR num] [-vh]\n" );
37192     Abc_Print( -2, "\t         performs SOP balancing\n" );
37193     Abc_Print( -2, "\t-L num : optimize paths above this level [default = %d]\n", nLevelMax );
37194     Abc_Print( -2, "\t-W num : optimize paths falling into this window [default = %d]\n", nTimeWindow );
37195     Abc_Print( -2, "\t-C num : the number of cuts at a node [default = %d]\n", nCutNum );
37196     Abc_Print( -2, "\t-R num : the delay relaxation ratio (num >= 0) [default = %d]\n", nRelaxRatio );
37197     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
37198     Abc_Print( -2, "\t-h     : print the command usage\n");
37199     return 1;
37200 }
37201 
37202 /**Function*************************************************************
37203 
37204   Synopsis    []
37205 
37206   Description []
37207 
37208   SideEffects []
37209 
37210   SeeAlso     []
37211 
37212 ***********************************************************************/
Abc_CommandAbc9Dsdb(Abc_Frame_t * pAbc,int argc,char ** argv)37213 int Abc_CommandAbc9Dsdb( Abc_Frame_t * pAbc, int argc, char ** argv )
37214 {
37215     Gia_Man_t * pTemp;
37216     int nLevelMax   = 0;
37217     int nTimeWindow = 0;
37218     int nLutSize    = 6;
37219     int nCutNum     = 8;
37220     int nRelaxRatio = 0;
37221     int c, fVerbose = 0;
37222     Extra_UtilGetoptReset();
37223     while ( ( c = Extra_UtilGetopt( argc, argv, "LWKCRvh" ) ) != EOF )
37224     {
37225         switch ( c )
37226         {
37227         case 'L':
37228             if ( globalUtilOptind >= argc )
37229             {
37230                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
37231                 goto usage;
37232             }
37233             nLevelMax = atoi(argv[globalUtilOptind]);
37234             globalUtilOptind++;
37235             if ( nLevelMax < 0 )
37236                 goto usage;
37237             break;
37238         case 'W':
37239             if ( globalUtilOptind >= argc )
37240             {
37241                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
37242                 goto usage;
37243             }
37244             nTimeWindow = atoi(argv[globalUtilOptind]);
37245             globalUtilOptind++;
37246             if ( nTimeWindow < 0 )
37247                 goto usage;
37248             break;
37249         case 'K':
37250             if ( globalUtilOptind >= argc )
37251             {
37252                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
37253                 goto usage;
37254             }
37255             nLutSize = atoi(argv[globalUtilOptind]);
37256             globalUtilOptind++;
37257             if ( nLutSize < 0 )
37258                 goto usage;
37259             break;
37260          case 'C':
37261             if ( globalUtilOptind >= argc )
37262             {
37263                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
37264                 goto usage;
37265             }
37266             nCutNum = atoi(argv[globalUtilOptind]);
37267             globalUtilOptind++;
37268             if ( nCutNum < 0 )
37269                 goto usage;
37270             break;
37271         case 'R':
37272             if ( globalUtilOptind >= argc )
37273             {
37274                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
37275                 goto usage;
37276             }
37277             nRelaxRatio = atoi(argv[globalUtilOptind]);
37278             globalUtilOptind++;
37279             if ( nRelaxRatio < 0 )
37280                 goto usage;
37281             break;
37282         case 'v':
37283             fVerbose ^= 1;
37284             break;
37285         case 'h':
37286             goto usage;
37287         default:
37288             goto usage;
37289         }
37290     }
37291     if ( pAbc->pGia == NULL )
37292     {
37293         Abc_Print( -1, "Abc_CommandAbc9Dsdb(): There is no AIG.\n" );
37294         return 1;
37295     }
37296     if ( nLutSize > DAU_MAX_VAR )
37297     {
37298         printf( "Abc_CommandAbc9Dsdb(): Size of the required DSD manager (%d) exceeds the precompiled limit (%d) (change parameter DAU_MAX_VAR).\n", nLutSize, DAU_MAX_VAR );
37299         return 0;
37300     }
37301     if ( Abc_FrameReadManDsd2() && nLutSize > If_DsdManVarNum((If_DsdMan_t*)Abc_FrameReadManDsd2()) )
37302     {
37303         printf( "Abc_CommandAbc9Dsdb(): Incompatible size of the DSD manager (run \"dsd_free -b\").\n" );
37304         return 0;
37305     }
37306     if ( nLevelMax || nTimeWindow )
37307         pTemp = Gia_ManPerformDsdBalanceWin( pAbc->pGia, nLevelMax, nTimeWindow, nLutSize, nCutNum, nRelaxRatio, fVerbose );
37308     else
37309         pTemp = Gia_ManPerformDsdBalance( pAbc->pGia, nLutSize, nCutNum, nRelaxRatio, fVerbose );
37310     Abc_FrameUpdateGia( pAbc, pTemp );
37311     return 0;
37312 
37313 usage:
37314     Abc_Print( -2, "usage: &dsdb [-LWKCR num] [-vh]\n" );
37315     Abc_Print( -2, "\t         performs DSD balancing\n" );
37316     Abc_Print( -2, "\t-L num : optimize paths above this level [default = %d]\n", nLevelMax );
37317     Abc_Print( -2, "\t-W num : optimize paths falling into this window [default = %d]\n", nTimeWindow );
37318     Abc_Print( -2, "\t-K num : the number of LUT inputs (LUT size) [default = %d]\n", nLutSize );
37319     Abc_Print( -2, "\t-C num : the number of cuts at a node [default = %d]\n", nCutNum );
37320     Abc_Print( -2, "\t-R num : the delay relaxation ratio (num >= 0) [default = %d]\n", nRelaxRatio );
37321     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
37322     Abc_Print( -2, "\t-h     : print the command usage\n");
37323     return 1;
37324 }
37325 
37326 /**Function*************************************************************
37327 
37328   Synopsis    []
37329 
37330   Description []
37331 
37332   SideEffects []
37333 
37334   SeeAlso     []
37335 
37336 ***********************************************************************/
Abc_CommandAbc9Flow(Abc_Frame_t * pAbc,int argc,char ** argv)37337 int Abc_CommandAbc9Flow( Abc_Frame_t * pAbc, int argc, char ** argv )
37338 {
37339     extern void Gia_ManPerformFlow( int fIsMapped, int nAnds, int nLevels, int nLutSize, int nCutNum, int fMinAve, int fUseMfs, int fVerbose );
37340     int nLutSize    =  6;
37341     int nCutNum     =  8;
37342     int fMinAve     =  0;
37343     int fUseMfs     =  0;
37344     int c, fVerbose =  0;
37345     Extra_UtilGetoptReset();
37346     while ( ( c = Extra_UtilGetopt( argc, argv, "KCtmvh" ) ) != EOF )
37347     {
37348         switch ( c )
37349         {
37350         case 'K':
37351             if ( globalUtilOptind >= argc )
37352             {
37353                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
37354                 goto usage;
37355             }
37356             nLutSize = atoi(argv[globalUtilOptind]);
37357             globalUtilOptind++;
37358             if ( nLutSize < 0 )
37359                 goto usage;
37360             break;
37361          case 'C':
37362             if ( globalUtilOptind >= argc )
37363             {
37364                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
37365                 goto usage;
37366             }
37367             nCutNum = atoi(argv[globalUtilOptind]);
37368             globalUtilOptind++;
37369             if ( nCutNum < 0 )
37370                 goto usage;
37371             break;
37372         case 't':
37373             fMinAve ^= 1;
37374             break;
37375         case 'm':
37376             fUseMfs ^= 1;
37377             break;
37378         case 'v':
37379             fVerbose ^= 1;
37380             break;
37381         case 'h':
37382             goto usage;
37383         default:
37384             goto usage;
37385         }
37386     }
37387     if ( pAbc->pGia == NULL )
37388     {
37389         Abc_Print( -1, "Abc_CommandAbc9Flow(): There is no AIG.\n" );
37390         return 1;
37391     }
37392     Gia_ManPerformFlow( Gia_ManHasMapping(pAbc->pGia), Gia_ManAndNum(pAbc->pGia), Gia_ManLevelNum(pAbc->pGia), nLutSize, nCutNum, fMinAve, fUseMfs, fVerbose );
37393     return 0;
37394 
37395 usage:
37396     Abc_Print( -2, "usage: &flow [-KC num] [-tmvh]\n" );
37397     Abc_Print( -2, "\t         integration optimization and mapping flow\n" );
37398     Abc_Print( -2, "\t-K num : the number of LUT inputs (LUT size) [default = %d]\n", nLutSize );
37399     Abc_Print( -2, "\t-C num : the number of cuts at a node [default = %d]\n", nCutNum );
37400     Abc_Print( -2, "\t-t     : toggle minimizing average rather than max delay [default = %s]\n", fMinAve? "yes": "no" );
37401     Abc_Print( -2, "\t-m     : toggle using \"mfs2\" in the script [default = %s]\n", fUseMfs? "yes": "no" );
37402     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
37403     Abc_Print( -2, "\t-h     : print the command usage\n");
37404     return 1;
37405 }
37406 
37407 /**Function*************************************************************
37408 
37409   Synopsis    []
37410 
37411   Description []
37412 
37413   SideEffects []
37414 
37415   SeeAlso     []
37416 
37417 ***********************************************************************/
Abc_CommandAbc9Flow2(Abc_Frame_t * pAbc,int argc,char ** argv)37418 int Abc_CommandAbc9Flow2( Abc_Frame_t * pAbc, int argc, char ** argv )
37419 {
37420     extern void Gia_ManPerformFlow2( int fIsMapped, int nAnds, int nLevels, int nLutSize, int nCutNum, int fBalance, int fMinAve, int fUseMfs, int fVerbose );
37421     int nLutSize    =  6;
37422     int nCutNum     =  8;
37423     int fBalance    =  0;
37424     int fMinAve     =  0;
37425     int fUseMfs     =  0;
37426     int c, fVerbose =  0;
37427     Extra_UtilGetoptReset();
37428     while ( ( c = Extra_UtilGetopt( argc, argv, "KCbtmvh" ) ) != EOF )
37429     {
37430         switch ( c )
37431         {
37432         case 'K':
37433             if ( globalUtilOptind >= argc )
37434             {
37435                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
37436                 goto usage;
37437             }
37438             nLutSize = atoi(argv[globalUtilOptind]);
37439             globalUtilOptind++;
37440             if ( nLutSize < 0 )
37441                 goto usage;
37442             break;
37443          case 'C':
37444             if ( globalUtilOptind >= argc )
37445             {
37446                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
37447                 goto usage;
37448             }
37449             nCutNum = atoi(argv[globalUtilOptind]);
37450             globalUtilOptind++;
37451             if ( nCutNum < 0 )
37452                 goto usage;
37453             break;
37454         case 'b':
37455             fBalance ^= 1;
37456             break;
37457         case 't':
37458             fMinAve ^= 1;
37459             break;
37460         case 'm':
37461             fUseMfs ^= 1;
37462             break;
37463         case 'v':
37464             fVerbose ^= 1;
37465             break;
37466         case 'h':
37467             goto usage;
37468         default:
37469             goto usage;
37470         }
37471     }
37472     if ( pAbc->pGia == NULL )
37473     {
37474         Abc_Print( -1, "Abc_CommandAbc9Flow2(): There is no AIG.\n" );
37475         return 1;
37476     }
37477     Gia_ManPerformFlow2( Gia_ManHasMapping(pAbc->pGia), Gia_ManAndNum(pAbc->pGia), Gia_ManLevelNum(pAbc->pGia), nLutSize, nCutNum, fBalance, fMinAve, fUseMfs, fVerbose );
37478     return 0;
37479 
37480 usage:
37481     Abc_Print( -2, "usage: &flow2 [-KC num] [-btmvh]\n" );
37482     Abc_Print( -2, "\t         integration optimization and mapping flow\n" );
37483     Abc_Print( -2, "\t-K num : the number of LUT inputs (LUT size) [default = %d]\n", nLutSize );
37484     Abc_Print( -2, "\t-C num : the number of cuts at a node [default = %d]\n", nCutNum );
37485     Abc_Print( -2, "\t-b     : toggle using SOP balancing during synthesis [default = %s]\n", fBalance? "yes": "no" );
37486     Abc_Print( -2, "\t-t     : toggle minimizing average (not maximum) level [default = %s]\n", fMinAve? "yes": "no" );
37487     Abc_Print( -2, "\t-m     : toggle using \"mfs2\" in the script [default = %s]\n", fUseMfs? "yes": "no" );
37488     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
37489     Abc_Print( -2, "\t-h     : print the command usage\n");
37490     return 1;
37491 }
37492 
37493 /**Function*************************************************************
37494 
37495   Synopsis    []
37496 
37497   Description []
37498 
37499   SideEffects []
37500 
37501   SeeAlso     []
37502 
37503 ***********************************************************************/
Abc_CommandAbc9Flow3(Abc_Frame_t * pAbc,int argc,char ** argv)37504 int Abc_CommandAbc9Flow3( Abc_Frame_t * pAbc, int argc, char ** argv )
37505 {
37506     extern void Gia_ManPerformFlow3( int nLutSize, int nCutNum, int fBalance, int fMinAve, int fUseMfs, int fUseLutLib, int fVerbose );
37507     int nLutSize    =  6;
37508     int nCutNum     =  8;
37509     int fBalance    =  0;
37510     int fMinAve     =  0;
37511     int fUseMfs     =  1;
37512     int fUseLutLib  =  0;
37513     int c, fVerbose =  0;
37514     Extra_UtilGetoptReset();
37515     while ( ( c = Extra_UtilGetopt( argc, argv, "KCbtmlvh" ) ) != EOF )
37516     {
37517         switch ( c )
37518         {
37519         case 'K':
37520             if ( globalUtilOptind >= argc )
37521             {
37522                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
37523                 goto usage;
37524             }
37525             nLutSize = atoi(argv[globalUtilOptind]);
37526             globalUtilOptind++;
37527             if ( nLutSize < 0 )
37528                 goto usage;
37529             break;
37530          case 'C':
37531             if ( globalUtilOptind >= argc )
37532             {
37533                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
37534                 goto usage;
37535             }
37536             nCutNum = atoi(argv[globalUtilOptind]);
37537             globalUtilOptind++;
37538             if ( nCutNum < 0 )
37539                 goto usage;
37540             break;
37541         case 'b':
37542             fBalance ^= 1;
37543             break;
37544         case 't':
37545             fMinAve ^= 1;
37546             break;
37547         case 'm':
37548             fUseMfs ^= 1;
37549             break;
37550         case 'l':
37551             fUseLutLib ^= 1;
37552             break;
37553         case 'v':
37554             fVerbose ^= 1;
37555             break;
37556         case 'h':
37557             goto usage;
37558         default:
37559             goto usage;
37560         }
37561     }
37562     if ( pAbc->pGia == NULL )
37563     {
37564         Abc_Print( -1, "Abc_CommandAbc9Flow3(): There is no AIG.\n" );
37565         return 1;
37566     }
37567     if ( fUseLutLib && Abc_FrameReadLibLut() == NULL )
37568     {
37569         Abc_Print( -1, "Abc_CommandAbc9Flow3(): Please enter LUT library using \'read_lut\'.\n" );
37570         return 1;
37571     }
37572     Gia_ManPerformFlow3( nLutSize, nCutNum, fBalance, fMinAve, fUseMfs, fUseLutLib, fVerbose );
37573     return 0;
37574 
37575 usage:
37576     Abc_Print( -2, "usage: &flow3 [-KC num] [-btmlvh]\n" );
37577     Abc_Print( -2, "\t         integration optimization and mapping flow\n" );
37578     Abc_Print( -2, "\t-K num : the number of LUT inputs (LUT size) [default = %d]\n",           nLutSize );
37579     Abc_Print( -2, "\t-C num : the number of cuts at a node [default = %d]\n",                  nCutNum );
37580     Abc_Print( -2, "\t-b     : toggle using SOP balancing during synthesis [default = %s]\n",   fBalance? "yes": "no" );
37581     Abc_Print( -2, "\t-t     : toggle minimizing average (not maximum) level [default = %s]\n", fMinAve? "yes": "no" );
37582     Abc_Print( -2, "\t-m     : toggle using \"mfs2\" in the script [default = %s]\n",           fUseMfs? "yes": "no" );
37583     Abc_Print( -2, "\t-l     : toggle using previously entered LUT library [default = %s]\n",   fUseLutLib? "yes": "no" );
37584     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",           fVerbose? "yes": "no" );
37585     Abc_Print( -2, "\t-h     : print the command usage\n");
37586     return 1;
37587 }
37588 
37589 /**Function*************************************************************
37590 
37591   Synopsis    []
37592 
37593   Description []
37594 
37595   SideEffects []
37596 
37597   SeeAlso     []
37598 
37599 ***********************************************************************/
Abc_CommandAbc9If(Abc_Frame_t * pAbc,int argc,char ** argv)37600 int Abc_CommandAbc9If( Abc_Frame_t * pAbc, int argc, char ** argv )
37601 {
37602     char Buffer[200];
37603     char LutSize[200];
37604     Gia_Man_t * pNew;
37605     If_Par_t Pars, * pPars = &Pars;
37606     int c;
37607     // set defaults
37608     Gia_ManSetIfParsDefault( pPars );
37609     if ( pAbc->pLibLut == NULL )
37610     {
37611         Abc_Print( -1, "LUT library is not given. Using default LUT library.\n" );
37612         pAbc->pLibLut = If_LibLutSetSimple( 6 );
37613     }
37614     pPars->pLutLib = (If_LibLut_t *)pAbc->pLibLut;
37615     Extra_UtilGetoptReset();
37616     while ( ( c = Extra_UtilGetopt( argc, argv, "KCFAGRDEWSTXYqalepmrsdbgxyofuijkztncvwh" ) ) != EOF )
37617     {
37618         switch ( c )
37619         {
37620         case 'K':
37621             if ( globalUtilOptind >= argc )
37622             {
37623                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a positive integer.\n" );
37624                 goto usage;
37625             }
37626             pPars->nLutSize = atoi(argv[globalUtilOptind]);
37627             globalUtilOptind++;
37628             if ( pPars->nLutSize < 0 )
37629                 goto usage;
37630             // if the LUT size is specified, disable library
37631             pPars->pLutLib = NULL;
37632             break;
37633         case 'C':
37634             if ( globalUtilOptind >= argc )
37635             {
37636                 Abc_Print( -1, "Command line switch \"-C\" should be followed by a positive integer.\n" );
37637                 goto usage;
37638             }
37639             pPars->nCutsMax = atoi(argv[globalUtilOptind]);
37640             globalUtilOptind++;
37641             if ( pPars->nCutsMax < 0 )
37642                 goto usage;
37643             break;
37644         case 'F':
37645             if ( globalUtilOptind >= argc )
37646             {
37647                 Abc_Print( -1, "Command line switch \"-F\" should be followed by a positive integer.\n" );
37648                 goto usage;
37649             }
37650             pPars->nFlowIters = atoi(argv[globalUtilOptind]);
37651             globalUtilOptind++;
37652             if ( pPars->nFlowIters < 0 )
37653                 goto usage;
37654             break;
37655         case 'A':
37656             if ( globalUtilOptind >= argc )
37657             {
37658                 Abc_Print( -1, "Command line switch \"-A\" should be followed by a positive integer.\n" );
37659                 goto usage;
37660             }
37661             pPars->nAreaIters = atoi(argv[globalUtilOptind]);
37662             globalUtilOptind++;
37663             if ( pPars->nAreaIters < 0 )
37664                 goto usage;
37665             break;
37666         case 'G':
37667             if ( globalUtilOptind >= argc )
37668             {
37669                 Abc_Print( -1, "Command line switch \"-G\" should be followed by a positive integer no less than 3.\n" );
37670                 goto usage;
37671             }
37672             pPars->nGateSize = atoi(argv[globalUtilOptind]);
37673             globalUtilOptind++;
37674             if ( pPars->nGateSize < 2 )
37675                 goto usage;
37676             break;
37677         case 'R':
37678             if ( globalUtilOptind >= argc )
37679             {
37680                 Abc_Print( 1, "Command line switch \"-R\" should be followed by a floating point number.\n" );
37681                 return 0;
37682             }
37683             pPars->nRelaxRatio = atoi(argv[globalUtilOptind]);
37684             globalUtilOptind++;
37685             if ( pPars->nRelaxRatio < 0 )
37686                 goto usage;
37687             break;
37688         case 'T':
37689             if ( globalUtilOptind >= argc )
37690             {
37691                 Abc_Print( -1, "Command line switch \"-T\" should be followed by a positive integer 0,1,or 2.\n" );
37692                 goto usage;
37693             }
37694             pPars->nStructType = atoi(argv[globalUtilOptind]);
37695             globalUtilOptind++;
37696             if ( pPars->nStructType < 0 || pPars->nStructType > 2 )
37697                 goto usage;
37698             break;
37699         case 'X':
37700             if ( globalUtilOptind >= argc )
37701             {
37702                 Abc_Print( -1, "Command line switch \"-X\" should be followed by a positive integer 0,1,or 2.\n" );
37703                 goto usage;
37704             }
37705             pPars->nAndDelay = atoi(argv[globalUtilOptind]);
37706             globalUtilOptind++;
37707             if ( pPars->nAndArea < 0 )
37708                 goto usage;
37709             break;
37710         case 'Y':
37711             if ( globalUtilOptind >= argc )
37712             {
37713                 Abc_Print( -1, "Command line switch \"-Y\" should be followed by a positive integer 0,1,or 2.\n" );
37714                 goto usage;
37715             }
37716             pPars->nAndArea = atoi(argv[globalUtilOptind]);
37717             globalUtilOptind++;
37718             if ( pPars->nAndDelay < 0 )
37719                 goto usage;
37720             break;
37721         case 'D':
37722             if ( globalUtilOptind >= argc )
37723             {
37724                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a floating point number.\n" );
37725                 goto usage;
37726             }
37727             pPars->DelayTarget = (float)atof(argv[globalUtilOptind]);
37728             globalUtilOptind++;
37729             if ( pPars->DelayTarget <= 0.0 )
37730                 goto usage;
37731             break;
37732         case 'E':
37733             if ( globalUtilOptind >= argc )
37734             {
37735                 Abc_Print( -1, "Command line switch \"-E\" should be followed by a floating point number.\n" );
37736                 goto usage;
37737             }
37738             pPars->Epsilon = (float)atof(argv[globalUtilOptind]);
37739             globalUtilOptind++;
37740             if ( pPars->Epsilon < 0.0 || pPars->Epsilon > 1.0 )
37741                 goto usage;
37742             break;
37743         case 'W':
37744             if ( globalUtilOptind >= argc )
37745             {
37746                 Abc_Print( -1, "Command line switch \"-W\" should be followed by a floating point number.\n" );
37747                 goto usage;
37748             }
37749             pPars->WireDelay = (float)atof(argv[globalUtilOptind]);
37750             globalUtilOptind++;
37751             if ( pPars->WireDelay < 0.0 )
37752                 goto usage;
37753             break;
37754         case 'S':
37755             if ( globalUtilOptind >= argc )
37756             {
37757                 Abc_Print( -1, "Command line switch \"-S\" should be followed by string.\n" );
37758                 goto usage;
37759             }
37760             pPars->pLutStruct = argv[globalUtilOptind];
37761             globalUtilOptind++;
37762             if ( strlen(pPars->pLutStruct) != 2 && strlen(pPars->pLutStruct) != 3 )
37763             {
37764                 Abc_Print( -1, "Command line switch \"-S\" should be followed by a 2- or 3-char string (e.g. \"44\" or \"555\").\n" );
37765                 goto usage;
37766             }
37767             break;
37768         case 'q':
37769             pPars->fPreprocess ^= 1;
37770             break;
37771         case 'a':
37772             pPars->fArea ^= 1;
37773             break;
37774         case 'r':
37775             pPars->fExpRed ^= 1;
37776             break;
37777         case 'l':
37778             pPars->fLut6Filter ^= 1;
37779             break;
37780         case 'e':
37781             pPars->fEdge ^= 1;
37782             break;
37783         case 'p':
37784             pPars->fPower ^= 1;
37785             break;
37786         case 'm':
37787             pPars->fCutMin ^= 1;
37788             break;
37789         case 's':
37790             pPars->fDelayOptLut ^= 1;
37791             break;
37792         case 'd':
37793             pPars->fUse34Spec ^= 1;
37794             break;
37795         case 'b':
37796             pPars->fUseBat ^= 1;
37797             break;
37798         case 'g':
37799             pPars->fDelayOpt ^= 1;
37800             break;
37801         case 'x':
37802             pPars->fDsdBalance ^= 1;
37803             break;
37804         case 'y':
37805             pPars->fUserRecLib ^= 1;
37806             break;
37807         case 'o':
37808             pPars->fUseBuffs ^= 1;
37809             break;
37810         case 'f':
37811             pPars->fEnableCheck75 ^= 1;
37812             break;
37813         case 'u':
37814             pPars->fEnableCheck75u ^= 1;
37815             break;
37816         case 'i':
37817             pPars->fUseCofVars ^= 1;
37818             break;
37819 //        case 'j':
37820 //            pPars->fEnableCheck07 ^= 1;
37821 //            break;
37822         case 'j':
37823             pPars->fUseAndVars ^= 1;
37824             break;
37825         case 'k':
37826             pPars->fUseDsdTune ^= 1;
37827             break;
37828         case 'z':
37829             pPars->fDeriveLuts ^= 1;
37830             break;
37831         case 't':
37832             pPars->fDoAverage ^= 1;
37833             break;
37834         case 'n':
37835             pPars->fUseDsd ^= 1;
37836             break;
37837         case 'c':
37838             pPars->fUseTtPerm ^= 1;
37839             break;
37840         case 'v':
37841             pPars->fVerbose ^= 1;
37842             break;
37843         case 'w':
37844             pPars->fVerboseTrace ^= 1;
37845             break;
37846         case 'h':
37847             pPars->fHashMapping ^= 1;
37848             break;
37849         default:
37850             goto usage;
37851         }
37852     }
37853 
37854     if ( pAbc->pGia == NULL )
37855     {
37856         if ( !Abc_FrameReadFlag("silentmode") )
37857         Abc_Print( -1, "Empty GIA network.\n" );
37858         return 0;
37859     }
37860     if ( Gia_ManBufNum(pAbc->pGia) )
37861     {
37862         Abc_Print( -1, "This command does not work with barrier buffers.\n" );
37863         return 1;
37864     }
37865     if ( Gia_ManHasMapping(pAbc->pGia) )
37866     {
37867         Abc_Print( -1, "Current AIG has mapping. Run \"&st\".\n" );
37868         return 1;
37869     }
37870 
37871     if ( pPars->nLutSize == -1 )
37872     {
37873         if ( pPars->pLutLib == NULL )
37874         {
37875             Abc_Print( -1, "The LUT library is not given.\n" );
37876             return 1;
37877         }
37878         // get LUT size from the library
37879         pPars->nLutSize = pPars->pLutLib->LutMax;
37880         // if variable pin delay, force truth table computation
37881 //        if ( pPars->pLutLib->fVarPinDelays )
37882 //            pPars->fTruth = 1;
37883     }
37884 
37885     if ( pPars->nLutSize < 2 || pPars->nLutSize > IF_MAX_LUTSIZE )
37886     {
37887         Abc_Print( -1, "Incorrect LUT size (%d).\n", pPars->nLutSize );
37888         return 1;
37889     }
37890 
37891     if ( pPars->nCutsMax < 1 || pPars->nCutsMax >= (1<<12) )
37892     {
37893         Abc_Print( -1, "Incorrect number of cuts.\n" );
37894         return 1;
37895     }
37896 
37897     // enable truth table computation if choices are selected
37898     if ( Gia_ManHasChoices(pAbc->pGia) )
37899     {
37900 //        if ( !Abc_FrameReadFlag("silentmode") )
37901 //            Abc_Print( 0, "Performing LUT mapping with choices.\n" );
37902         pPars->fExpRed = 0;
37903     }
37904 
37905     if ( pPars->fUseBat )
37906     {
37907         if ( pPars->nLutSize < 4 || pPars->nLutSize > 6 )
37908         {
37909             Abc_Print( -1, "This feature only works for {4,5,6}-LUTs.\n" );
37910             return 1;
37911         }
37912         pPars->fCutMin = 1;
37913     }
37914 
37915     if ( pPars->fEnableCheck07 + pPars->fUseCofVars + pPars->fUseDsdTune + pPars->fEnableCheck75 + pPars->fEnableCheck75u + (pPars->pLutStruct != NULL) > 1 )
37916     {
37917         Abc_Print( -1, "Only one additional check can be performed at the same time.\n" );
37918         return 1;
37919     }
37920     if ( pPars->fEnableCheck07 )
37921     {
37922         if ( pPars->nLutSize < 6 || pPars->nLutSize > 7 )
37923         {
37924             Abc_Print( -1, "This feature only works for {6,7}-LUTs.\n" );
37925             return 1;
37926         }
37927         pPars->pFuncCell = If_CutPerformCheck07;
37928         pPars->fCutMin = 1;
37929     }
37930     if ( pPars->fUseCofVars )
37931     {
37932         if ( !(pPars->nLutSize & 1) )
37933         {
37934             Abc_Print( -1, "This feature only works for odd-sized LUTs.\n" );
37935             return 1;
37936         }
37937         pPars->fCutMin = 1;
37938     }
37939     if ( pPars->fUseAndVars )
37940         pPars->fCutMin = 1;
37941     if ( pPars->fUseDsdTune )
37942     {
37943         If_DsdMan_t * pDsdMan = (If_DsdMan_t *)Abc_FrameReadManDsd();
37944         if ( pDsdMan == NULL )
37945         {
37946             Abc_Print( -1, "DSD manager is not available.\n" );
37947             return 1;
37948         }
37949         if ( pPars->nLutSize > If_DsdManVarNum(pDsdMan) )
37950         {
37951             Abc_Print( -1, "LUT size (%d) is more than the number of variables in the DSD manager (%d).\n", pPars->nLutSize, If_DsdManVarNum(pDsdMan) );
37952             return 1;
37953         }
37954         if ( pPars->fDeriveLuts && If_DsdManGetCellStr(pDsdMan) == NULL )
37955         {
37956             Abc_Print( -1, "DSD manager is not matched with any particular cell.\n" );
37957             return 1;
37958         }
37959         pPars->fCutMin = 1;
37960         pPars->fUseDsd = 1;
37961         If_DsdManSetNewAsUseless( pDsdMan );
37962     }
37963     if ( pPars->fEnableCheck75 || pPars->fEnableCheck75u )
37964     {
37965         if ( pPars->fEnableCheck75 && pPars->fEnableCheck75u )
37966         {
37967             Abc_Print( -1, "Switches -f and -u are not compatible.\n" );
37968             return 1;
37969         }
37970         if ( pPars->nLutSize < 5 || pPars->nLutSize > 8 )
37971         {
37972             Abc_Print( -1, "This feature only works for {6,7,8}-LUTs.\n" );
37973             return 1;
37974         }
37975         pPars->pFuncCell = If_CutPerformCheck75;
37976         pPars->fCutMin = 1;
37977     }
37978     if ( pPars->pLutStruct )
37979     {
37980         if ( pPars->fDsdBalance )
37981         {
37982             Abc_Print( -1, "Incompatible options (-S and -x).\n" );
37983             return 1;
37984         }
37985         if ( pPars->nLutSize < 6 || pPars->nLutSize > 16 )
37986         {
37987             Abc_Print( -1, "This feature only works for [6;16]-LUTs.\n" );
37988             return 1;
37989         }
37990         pPars->pFuncCell = pPars->fDelayOptLut ? NULL : If_CutPerformCheck16;
37991         pPars->fCutMin = 1;
37992     }
37993 
37994     if ( pPars->fUse34Spec )
37995     {
37996         pPars->fTruth    = 1;
37997         pPars->fCutMin   = 1;
37998         pPars->nLutSize  = 4;
37999     }
38000 
38001     // enable truth table computation if cut minimization is selected
38002     if ( pPars->fCutMin || pPars->fDeriveLuts )
38003     {
38004         pPars->fTruth = 1;
38005         pPars->fExpRed = 0;
38006         if ( pPars->pLutStruct == NULL && !pPars->fUseDsdTune )
38007             pPars->fDeriveLuts = 1;
38008     }
38009     // modify the subgraph recording
38010     if ( pPars->fUserRecLib )
38011     {
38012         pPars->fTruth      =  1;
38013         pPars->fCutMin     =  1;
38014         pPars->fExpRed     =  0;
38015         pPars->fUsePerm    =  1;
38016         pPars->pLutLib     =  NULL;
38017     }
38018     // modify for delay optimization
38019     if ( pPars->fDelayOpt || pPars->fDsdBalance || pPars->fDelayOptLut )
38020     {
38021         pPars->fTruth      =  1;
38022         pPars->fCutMin     =  1;
38023         pPars->fExpRed     =  0;
38024         pPars->fUseDsd     =  pPars->fDsdBalance || pPars->fDelayOptLut;
38025         pPars->pLutLib     =  NULL;
38026     }
38027     // modify for delay optimization
38028     if ( pPars->nGateSize > 0 )
38029     {
38030         pPars->fTruth      =  1;
38031         pPars->fCutMin     =  1;
38032         pPars->fExpRed     =  0;
38033         pPars->fUsePerm    =  1;
38034         pPars->pLutLib     =  NULL;
38035         pPars->nLutSize    =  pPars->nGateSize;
38036     }
38037 
38038     if ( pPars->fUseDsd || pPars->fUseTtPerm || pPars->fLut6Filter )
38039     {
38040         pPars->fTruth      =  1;
38041         pPars->fCutMin     =  1;
38042         pPars->fExpRed     =  0;
38043     }
38044 
38045     if ( pPars->fUseDsd )
38046     {
38047         int LutSize = (pPars->pLutStruct && pPars->pLutStruct[2] == 0)? pPars->pLutStruct[0] - '0' : 0;
38048         If_DsdMan_t * p = (If_DsdMan_t *)Abc_FrameReadManDsd();
38049         if ( pPars->pLutStruct && pPars->pLutStruct[2] != 0 )
38050         {
38051             printf( "DSD only works for LUT structures XY.\n" );
38052             return 0;
38053         }
38054         if ( p && pPars->nLutSize > If_DsdManVarNum(p) )
38055         {
38056             printf( "DSD manager has incompatible number of variables.\n" );
38057             return 0;
38058         }
38059         if ( p && LutSize != If_DsdManLutSize(p) && !pPars->fDsdBalance )
38060         {
38061             printf( "DSD manager has different LUT size.\n" );
38062             return 0;
38063         }
38064         if ( p == NULL )
38065         {
38066             if ( LutSize > DAU_MAX_VAR || pPars->nLutSize > DAU_MAX_VAR )
38067             {
38068                 printf( "Size of required DSD manager (%d) exceeds the precompiled limit (%d) (change parameter DAU_MAX_VAR).\n", LutSize, DAU_MAX_VAR );
38069                 return 0;
38070             }
38071             Abc_FrameSetManDsd( If_DsdManAlloc(pPars->nLutSize, LutSize) );
38072         }
38073     }
38074 
38075     if ( pPars->fUserRecLib )
38076     {
38077         if ( !Abc_NtkRecIsRunning3() )
38078         {
38079             printf( "LMS manager is not running (use \"rec_start3\").\n" );
38080             return 0;
38081         }
38082         if ( Abc_NtkRecInputNum3() != pPars->nLutSize )
38083         {
38084             printf( "The number of library inputs (%d) different from the K parameters (%d).\n", Abc_NtkRecInputNum3(), pPars->nLutSize );
38085             return 0;
38086         }
38087     }
38088 
38089     // complain if truth tables are requested but the cut size is too large
38090     if ( pPars->fTruth && pPars->nLutSize > IF_MAX_FUNC_LUTSIZE )
38091     {
38092         Abc_Print( -1, "Truth tables cannot be computed for LUT larger than %d inputs.\n", IF_MAX_FUNC_LUTSIZE );
38093         return 1;
38094     }
38095     if ( pAbc->pGia->pManTime && pAbc->pLibBox == NULL )
38096     {
38097         Abc_Print( -1, "Design has boxes but box library is not entered.\n" );
38098         return 1;
38099     }
38100 
38101     // add wire delay to LUT library delays
38102     if ( pPars->WireDelay > 0 && pPars->pLutLib )
38103     {
38104         int i, k;
38105         for ( i = 0; i <= pPars->pLutLib->LutMax; i++ )
38106             for ( k = 0; k <= i; k++ )
38107                 pPars->pLutLib->pLutDelays[i][k] += pPars->WireDelay;
38108     }
38109     // perform mapping
38110     pNew = Gia_ManPerformMapping( pAbc->pGia, pPars );
38111     // subtract wire delay from LUT library delays
38112     if ( pPars->WireDelay > 0 && pPars->pLutLib )
38113     {
38114         int i, k;
38115         for ( i = 0; i <= pPars->pLutLib->LutMax; i++ )
38116             for ( k = 0; k <= i; k++ )
38117                 pPars->pLutLib->pLutDelays[i][k] -= pPars->WireDelay;
38118     }
38119     if ( pNew == NULL )
38120     {
38121         Abc_Print( -1, "Abc_CommandAbc9If(): Mapping of GIA has failed.\n" );
38122         return 1;
38123     }
38124     Abc_FrameUpdateGia( pAbc, pNew );
38125     return 0;
38126 
38127 usage:
38128     if ( pPars->DelayTarget == -1 )
38129         sprintf(Buffer, "best possible" );
38130     else
38131         sprintf(Buffer, "%.2f", pPars->DelayTarget );
38132     if ( pPars->nLutSize == -1 )
38133         sprintf(LutSize, "library" );
38134     else
38135         sprintf(LutSize, "%d", pPars->nLutSize );
38136     Abc_Print( -2, "usage: &if [-KCFAGRTXY num] [-DEW float] [-S str] [-qarlepmsdbgxyofuijkztnchvw]\n" );
38137     Abc_Print( -2, "\t           performs FPGA technology mapping of the network\n" );
38138     Abc_Print( -2, "\t-K num   : the number of LUT inputs (2 < num < %d) [default = %s]\n", IF_MAX_LUTSIZE+1, LutSize );
38139     Abc_Print( -2, "\t-C num   : the max number of priority cuts (0 < num < 2^12) [default = %d]\n", pPars->nCutsMax );
38140     Abc_Print( -2, "\t-F num   : the number of area flow recovery iterations (num >= 0) [default = %d]\n", pPars->nFlowIters );
38141     Abc_Print( -2, "\t-A num   : the number of exact area recovery iterations (num >= 0) [default = %d]\n", pPars->nAreaIters );
38142     Abc_Print( -2, "\t-G num   : the max AND/OR gate size for mapping (0 = unused) [default = %d]\n", pPars->nGateSize );
38143     Abc_Print( -2, "\t-R num   : the delay relaxation ratio (num >= 0) [default = %d]\n", pPars->nRelaxRatio );
38144     Abc_Print( -2, "\t-T num   : the type of LUT structures [default = any]\n", pPars->nStructType );
38145     Abc_Print( -2, "\t-X num   : delay of AND-gate in LUT library units [default = %d]\n", pPars->nAndDelay );
38146     Abc_Print( -2, "\t-Y num   : area of AND-gate in LUT library units [default = %d]\n", pPars->nAndArea );
38147     Abc_Print( -2, "\t-D float : sets the delay constraint for the mapping [default = %s]\n", Buffer );
38148     Abc_Print( -2, "\t-E float : sets epsilon used for tie-breaking [default = %f]\n", pPars->Epsilon );
38149     Abc_Print( -2, "\t-W float : sets wire delay between adjects LUTs [default = %f]\n", pPars->WireDelay );
38150     Abc_Print( -2, "\t-S str   : string representing the LUT structure [default = %s]\n", pPars->pLutStruct ? pPars->pLutStruct : "not used" );
38151     Abc_Print( -2, "\t-q       : toggles preprocessing using several starting points [default = %s]\n", pPars->fPreprocess? "yes": "no" );
38152     Abc_Print( -2, "\t-a       : toggles area-oriented mapping [default = %s]\n", pPars->fArea? "yes": "no" );
38153     Abc_Print( -2, "\t-r       : enables expansion/reduction of the best cuts [default = %s]\n", pPars->fExpRed? "yes": "no" );
38154 //    Abc_Print( -2, "\t-l       : optimizes latch paths for delay, other paths for area [default = %s]\n", pPars->fLatchPaths? "yes": "no" );
38155     Abc_Print( -2, "\t-l       : toggle restricting the type of 6-input lookup tables [default = %s]\n", pPars->fLut6Filter? "yes": "no" );
38156     Abc_Print( -2, "\t-e       : uses edge-based cut selection heuristics [default = %s]\n", pPars->fEdge? "yes": "no" );
38157     Abc_Print( -2, "\t-p       : uses power-aware cut selection heuristics [default = %s]\n", pPars->fPower? "yes": "no" );
38158     Abc_Print( -2, "\t-m       : enables cut minimization by removing vacuous variables [default = %s]\n", pPars->fCutMin? "yes": "no" );
38159     Abc_Print( -2, "\t-s       : toggles delay-oriented mapping used with -S <NN> [default = %s]\n", pPars->fDelayOptLut? "yes": "no" );
38160     Abc_Print( -2, "\t-d       : toggles deriving specialized matching step [default = %s]\n", pPars->fUse34Spec? "yes": "no" );
38161     Abc_Print( -2, "\t-b       : toggles the use of one special feature [default = %s]\n", pPars->fUseBat? "yes": "no" );
38162     Abc_Print( -2, "\t-g       : toggles delay optimization by SOP balancing [default = %s]\n", pPars->fDelayOpt? "yes": "no" );
38163     Abc_Print( -2, "\t-x       : toggles delay optimization by DSD balancing [default = %s]\n", pPars->fDsdBalance? "yes": "no" );
38164     Abc_Print( -2, "\t-y       : toggles delay optimization with recorded library [default = %s]\n", pPars->fUserRecLib? "yes": "no" );
38165     Abc_Print( -2, "\t-o       : toggles using buffers to decouple combinational outputs [default = %s]\n", pPars->fUseBuffs? "yes": "no" );
38166     Abc_Print( -2, "\t-f       : toggles enabling additional check [default = %s]\n", pPars->fEnableCheck75? "yes": "no" );
38167     Abc_Print( -2, "\t-u       : toggles enabling additional check [default = %s]\n", pPars->fEnableCheck75u? "yes": "no" );
38168     Abc_Print( -2, "\t-i       : toggles using cofactoring variables [default = %s]\n", pPars->fUseCofVars? "yes": "no" );
38169 //    Abc_Print( -2, "\t-j       : toggles enabling additional check [default = %s]\n", pPars->fEnableCheck07? "yes": "no" );
38170     Abc_Print( -2, "\t-j       : toggles using AND bi-decomposition [default = %s]\n", pPars->fUseAndVars? "yes": "no" );
38171     Abc_Print( -2, "\t-k       : toggles matching based on precomputed DSD manager [default = %s]\n", pPars->fUseDsdTune? "yes": "no" );
38172     Abc_Print( -2, "\t-z       : toggles deriving LUTs when mapping into LUT structures [default = %s]\n", pPars->fDeriveLuts? "yes": "no" );
38173     Abc_Print( -2, "\t-t       : toggles optimizing average rather than maximum level [default = %s]\n", pPars->fDoAverage? "yes": "no" );
38174     Abc_Print( -2, "\t-n       : toggles computing DSDs of the cut functions [default = %s]\n", pPars->fUseDsd? "yes": "no" );
38175     Abc_Print( -2, "\t-c       : toggles computing truth tables in a new way [default = %s]\n", pPars->fUseTtPerm? "yes": "no" );
38176     Abc_Print( -2, "\t-h       : toggles rehashing AIG after mapping [default = %s]\n", pPars->fHashMapping? "yes": "no" );
38177     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
38178     Abc_Print( -2, "\t-w       : toggles printing delay trace [default = %s]\n", pPars->fVerboseTrace? "yes": "no" );
38179     return 1;
38180 }
38181 
38182 /**Function*************************************************************
38183 
38184   Synopsis    []
38185 
38186   Description []
38187 
38188   SideEffects []
38189 
38190   SeeAlso     []
38191 
38192 ***********************************************************************/
Abc_CommandAbc9Iff(Abc_Frame_t * pAbc,int argc,char ** argv)38193 int Abc_CommandAbc9Iff( Abc_Frame_t * pAbc, int argc, char ** argv )
38194 {
38195     extern void Gia_ManIffTest( Gia_Man_t * pGia, If_LibLut_t * pLib, int fVerbose );
38196     int c, fVerbose = 0;
38197     Extra_UtilGetoptReset();
38198     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
38199     {
38200         switch ( c )
38201         {
38202         case 'v':
38203             fVerbose ^= 1;
38204             break;
38205         case 'h':
38206             goto usage;
38207         default:
38208             goto usage;
38209         }
38210     }
38211     if ( pAbc->pGia == NULL )
38212     {
38213         Abc_Print( -1, "Abc_CommandAbc9Iff(): There is no AIG to map.\n" );
38214         return 1;
38215     }
38216     if ( !Gia_ManHasMapping(pAbc->pGia) )
38217     {
38218         Abc_Print( -1, "Abc_CommandAbc9Iff(): Mapping of the AIG is not defined.\n" );
38219         return 1;
38220     }
38221     if ( pAbc->pLibLut == NULL )
38222     {
38223         Abc_Print( -1, "Abc_CommandAbc9Iff(): LUT library is not defined.\n" );
38224         return 1;
38225     }
38226     Gia_ManIffTest( pAbc->pGia, (If_LibLut_t *)pAbc->pLibLut, fVerbose );
38227     return 0;
38228 
38229 usage:
38230     Abc_Print( -2, "usage: &iff [-vh]\n" );
38231     Abc_Print( -2, "\t           performs structural mapping into LUT structures\n" );
38232     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n", fVerbose? "yes": "no" );
38233     Abc_Print( -2, "\t-h       : print the command usage\n");
38234     return 1;
38235 }
38236 
38237 /**Function*************************************************************
38238 
38239   Synopsis    []
38240 
38241   Description []
38242 
38243   SideEffects []
38244 
38245   SeeAlso     []
38246 
38247 ***********************************************************************/
Abc_CommandAbc9Iiff(Abc_Frame_t * pAbc,int argc,char ** argv)38248 int Abc_CommandAbc9Iiff( Abc_Frame_t * pAbc, int argc, char ** argv )
38249 {
38250     extern Gia_Man_t * Gia_ManIiffTest( char * pFileName, Gia_Man_t * pGia, int nLutSize, int nNumCuts, int fUseGates, int fUseCells, int fUseLuts, int fVerbose );
38251     char * pFileName = NULL;
38252     int nLutSize     =  8;
38253     int nNumCuts     = 12;
38254     int fUseGates    =  0;
38255     int fUseCells    =  0;
38256     int fUseLuts     =  0;
38257     int c, fVerbose  =  0;
38258     Gia_Man_t * pNew;
38259     Extra_UtilGetoptReset();
38260     while ( ( c = Extra_UtilGetopt( argc, argv, "KCgclvh" ) ) != EOF )
38261     {
38262         switch ( c )
38263         {
38264         case 'K':
38265             if ( globalUtilOptind >= argc )
38266             {
38267                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a positive integer.\n" );
38268                 goto usage;
38269             }
38270             nLutSize = atoi(argv[globalUtilOptind]);
38271             globalUtilOptind++;
38272             break;
38273         case 'C':
38274             if ( globalUtilOptind >= argc )
38275             {
38276                 Abc_Print( -1, "Command line switch \"-C\" should be followed by a positive integer.\n" );
38277                 goto usage;
38278             }
38279             nNumCuts = atoi(argv[globalUtilOptind]);
38280             globalUtilOptind++;
38281             break;
38282         case 'g':
38283             fUseGates ^= 1;
38284             break;
38285         case 'c':
38286             fUseCells ^= 1;
38287             break;
38288         case 'l':
38289             fUseLuts ^= 1;
38290             break;
38291         case 'v':
38292             fVerbose ^= 1;
38293             break;
38294         case 'h':
38295             goto usage;
38296         default:
38297             goto usage;
38298         }
38299     }
38300     if ( argc == globalUtilOptind + 1 )
38301         pFileName = argv[globalUtilOptind];
38302     if ( pAbc->pGia == NULL )
38303     {
38304         Abc_Print( -1, "Abc_CommandAbc9Iiff(): There is no AIG to map.\n" );
38305         return 1;
38306     }
38307     pNew = Gia_ManIiffTest( pFileName, pAbc->pGia, nLutSize, nNumCuts, fUseGates, fUseCells, fUseLuts, fVerbose );
38308     if ( pNew == NULL )
38309     {
38310         Abc_Print( -1, "Abc_CommandAbc9Iiff(): Mapping has failed.\n" );
38311         return 1;
38312     }
38313     Abc_FrameUpdateGia( pAbc, pNew );
38314     return 0;
38315 
38316 usage:
38317     Abc_Print( -2, "usage: &iiff [-KC num] [-gclvh] <file>\n" );
38318     Abc_Print( -2, "\t           performs techology mapping\n" );
38319     Abc_Print( -2, "\t-K num   : the maximum LUT size [default = %d]\n",  nLutSize );
38320     Abc_Print( -2, "\t-C num   : the maximum cut count [default = %d]\n", nNumCuts );
38321     Abc_Print( -2, "\t-g       : toggle using gates [default = %s]\n",    fUseGates? "yes": "no" );
38322     Abc_Print( -2, "\t-c       : toggle using cells [default = %s]\n",    fUseCells? "yes": "no" );
38323     Abc_Print( -2, "\t-l       : toggle using LUTs  [default = %s]\n",    fUseLuts? "yes": "no" );
38324     Abc_Print( -2, "\t-v       : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
38325     Abc_Print( -2, "\t-h       : print the command usage\n");
38326     Abc_Print( -2, "\t<file>   : (optional) output file name\n");
38327     return 1;
38328 }
38329 
38330 
38331 /**Function*************************************************************
38332 
38333   Synopsis    []
38334 
38335   Description []
38336 
38337   SideEffects []
38338 
38339   SeeAlso     []
38340 
38341 ***********************************************************************/
Abc_CommandAbc9If2(Abc_Frame_t * pAbc,int argc,char ** argv)38342 int Abc_CommandAbc9If2( Abc_Frame_t * pAbc, int argc, char ** argv )
38343 {
38344     extern Abc_Ntk_t * Mpm_ManCellMapping( Gia_Man_t * p, Mpm_Par_t * pPars, void * pMio );
38345     extern Gia_Man_t * Mpm_ManLutMapping( Gia_Man_t * p, Mpm_Par_t * pPars );
38346     char Buffer[200];
38347     Abc_Ntk_t * pTemp;
38348     Gia_Man_t * pNew;
38349     Mpm_Par_t Pars, * pPars = &Pars;
38350     int c, nLutSize = 6;
38351     // set defaults
38352     Mpm_ManSetParsDefault( pPars );
38353     Extra_UtilGetoptReset();
38354     while ( ( c = Extra_UtilGetopt( argc, argv, "KCDtmzrcuxvwh" ) ) != EOF )
38355     {
38356         switch ( c )
38357         {
38358         case 'K':
38359             if ( globalUtilOptind >= argc )
38360             {
38361                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a positive integer.\n" );
38362                 goto usage;
38363             }
38364             nLutSize = atoi(argv[globalUtilOptind]);
38365             globalUtilOptind++;
38366             if ( nLutSize < 2 || nLutSize > 16 )
38367             {
38368                 Abc_Print( -1, "LUT size %d is not supported.\n", nLutSize );
38369                 goto usage;
38370             }
38371             break;
38372         case 'C':
38373             if ( globalUtilOptind >= argc )
38374             {
38375                 Abc_Print( -1, "Command line switch \"-C\" should be followed by a positive integer.\n" );
38376                 goto usage;
38377             }
38378             pPars->nNumCuts = atoi(argv[globalUtilOptind]);
38379             globalUtilOptind++;
38380             if ( pPars->nNumCuts < 0 )
38381                 goto usage;
38382             break;
38383         case 'D':
38384             if ( globalUtilOptind >= argc )
38385             {
38386                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a floating point number.\n" );
38387                 goto usage;
38388             }
38389             pPars->DelayTarget = atoi(argv[globalUtilOptind]);
38390             globalUtilOptind++;
38391             if ( pPars->DelayTarget <= 0.0 )
38392                 goto usage;
38393             break;
38394         case 't':
38395             pPars->fUseGates ^= 1;
38396             break;
38397         case 'm':
38398             pPars->fCutMin ^= 1;
38399             break;
38400         case 'z':
38401             pPars->fDeriveLuts ^= 1;
38402             break;
38403         case 'r':
38404             pPars->fOneRound ^= 1;
38405             break;
38406         case 'c':
38407             pPars->fMap4Cnf ^= 1;
38408             break;
38409         case 'u':
38410             pPars->fMap4Aig ^= 1;
38411             break;
38412         case 'x':
38413             pPars->fMap4Gates ^= 1;
38414             break;
38415         case 'v':
38416             pPars->fVerbose ^= 1;
38417             break;
38418         case 'w':
38419             pPars->fVeryVerbose ^= 1;
38420             break;
38421         case 'h':
38422         default:
38423             goto usage;
38424         }
38425     }
38426 
38427     if ( pAbc->pGia == NULL )
38428     {
38429         Abc_Print( -1, "Empty GIA network.\n" );
38430         return 1;
38431     }
38432 
38433     if ( pPars->fMap4Cnf )
38434         pPars->fUseDsd = 1;
38435     if ( pPars->fCutMin )
38436         pPars->fUseDsd = 1;
38437 //        pPars->fUseTruth = 1;
38438     if ( pPars->fMap4Gates )
38439     {
38440         pPars->fUseDsd = 1;
38441         if ( pAbc->pLibScl == NULL )
38442         {
38443             Abc_Print( -1, "There is no SCL library available.\n" );
38444             return 1;
38445         }
38446         pPars->pScl = pAbc->pLibScl;
38447     }
38448     if ( pPars->fUseDsd || pPars->fUseTruth )
38449         pPars->fDeriveLuts = 1;
38450     if ( pPars->fUseDsd && nLutSize != 6 )
38451     {
38452         Abc_Print( -1, "Currently DSD can only be used with 6-input cuts.\n" );
38453         return 1;
38454     }
38455     // perform mapping
38456     assert( pPars->pLib == NULL );
38457     if ( pPars->fMap4Gates )
38458     {
38459         if ( Abc_FrameReadLibGen() == NULL )
38460         {
38461             Abc_Print( -1, "There is no GENLIB library available.\n" );
38462             return 1;
38463         }
38464         pPars->pLib = Mpm_LibLutSetSimple( nLutSize );
38465         pTemp = Mpm_ManCellMapping( pAbc->pGia, pPars, Abc_FrameReadLibGen() );
38466         Mpm_LibLutFree( pPars->pLib );
38467         if ( pTemp == NULL )
38468         {
38469             Abc_Print( -1, "Abc_CommandAbc9If2(): Mapping into standard cells has failed.\n" );
38470             return 1;
38471         }
38472         Abc_FrameReplaceCurrentNetwork( pAbc, pTemp );
38473     }
38474     else
38475     {
38476         pPars->pLib = Mpm_LibLutSetSimple( nLutSize );
38477         pNew = Mpm_ManLutMapping( pAbc->pGia, pPars );
38478         Mpm_LibLutFree( pPars->pLib );
38479         if ( pNew == NULL )
38480         {
38481             Abc_Print( -1, "Abc_CommandAbc9If2(): Mapping into LUTs has failed.\n" );
38482             return 1;
38483         }
38484         Abc_FrameUpdateGia( pAbc, pNew );
38485     }
38486     return 0;
38487 
38488 usage:
38489     if ( pPars->DelayTarget == -1 )
38490         sprintf(Buffer, "best possible" );
38491     else
38492         sprintf(Buffer, "%d", pPars->DelayTarget );
38493     Abc_Print( -2, "usage: &if2 [-KCD num] [-tmzrcuxvwh]\n" );
38494     Abc_Print( -2, "\t           performs technology mapping of the network\n" );
38495     Abc_Print( -2, "\t-K num   : sets the LUT size for the mapping [default = %d]\n", nLutSize );
38496     Abc_Print( -2, "\t-C num   : the max number of priority cuts (0 < num < 2^12) [default = %d]\n", pPars->nNumCuts );
38497     Abc_Print( -2, "\t-D num   : sets the delay constraint for the mapping [default = %s]\n", Buffer );
38498     Abc_Print( -2, "\t-t       : enables using AND/XOR/MUX nodes instead of simple AIG [default = %s]\n", pPars->fUseGates? "yes": "no" );
38499     Abc_Print( -2, "\t-m       : enables cut minimization by removing vacuous variables [default = %s]\n", pPars->fCutMin? "yes": "no" );
38500     Abc_Print( -2, "\t-z       : toggles deriving LUTs when mapping into LUT structures [default = %s]\n", pPars->fDeriveLuts? "yes": "no" );
38501     Abc_Print( -2, "\t-r       : toggles using one round of mapping [default = %s]\n", pPars->fOneRound? "yes": "no" );
38502     Abc_Print( -2, "\t-c       : toggles mapping for CNF computation [default = %s]\n", pPars->fMap4Cnf? "yes": "no" );
38503     Abc_Print( -2, "\t-u       : toggles mapping for AIG computation [default = %s]\n", pPars->fMap4Aig? "yes": "no" );
38504     Abc_Print( -2, "\t-x       : toggles mapping for standard cells [default = %s]\n", pPars->fMap4Gates? "yes": "no" );
38505     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
38506     Abc_Print( -2, "\t-w       : toggles very verbose output [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
38507     Abc_Print( -2, "\t-h       : prints the command usage\n");
38508     return 1;
38509 }
38510 
38511 /**Function*************************************************************
38512 
38513   Synopsis    []
38514 
38515   Description []
38516 
38517   SideEffects []
38518 
38519   SeeAlso     []
38520 
38521 ***********************************************************************/
Abc_CommandAbc9Jf(Abc_Frame_t * pAbc,int argc,char ** argv)38522 int Abc_CommandAbc9Jf( Abc_Frame_t * pAbc, int argc, char ** argv )
38523 {
38524     char Buffer[200];
38525     Jf_Par_t Pars, * pPars = &Pars;
38526     Gia_Man_t * pNew; int c;
38527     Jf_ManSetDefaultPars( pPars );
38528     Extra_UtilGetoptReset();
38529     while ( ( c = Extra_UtilGetopt( argc, argv, "KCDWaekmdcgvwh" ) ) != EOF )
38530     {
38531         switch ( c )
38532         {
38533         case 'K':
38534             if ( globalUtilOptind >= argc )
38535             {
38536                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a positive integer.\n" );
38537                 goto usage;
38538             }
38539             pPars->nLutSize = atoi(argv[globalUtilOptind]);
38540             globalUtilOptind++;
38541             if ( pPars->nLutSize < 2 || pPars->nLutSize > pPars->nLutSizeMax )
38542             {
38543                 Abc_Print( -1, "LUT size %d is not supported.\n", pPars->nLutSize );
38544                 goto usage;
38545             }
38546             break;
38547         case 'C':
38548             if ( globalUtilOptind >= argc )
38549             {
38550                 Abc_Print( -1, "Command line switch \"-C\" should be followed by a positive integer.\n" );
38551                 goto usage;
38552             }
38553             pPars->nCutNum = atoi(argv[globalUtilOptind]);
38554             globalUtilOptind++;
38555             if ( pPars->nCutNum < 1 || pPars->nCutNum > pPars->nCutNumMax )
38556             {
38557                 Abc_Print( -1, "This number of cuts (%d) is not supported.\n", pPars->nCutNum );
38558                 goto usage;
38559             }
38560             break;
38561         case 'D':
38562             if ( globalUtilOptind >= argc )
38563             {
38564                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a floating point number.\n" );
38565                 goto usage;
38566             }
38567             pPars->DelayTarget = atoi(argv[globalUtilOptind]);
38568             globalUtilOptind++;
38569             if ( pPars->DelayTarget <= 0.0 )
38570                 goto usage;
38571             break;
38572         case 'W':
38573             if ( globalUtilOptind >= argc )
38574             {
38575                 Abc_Print( -1, "Command line switch \"-W\" should be followed by a positive integer.\n" );
38576                 goto usage;
38577             }
38578             pPars->nVerbLimit = atoi(argv[globalUtilOptind]);
38579             globalUtilOptind++;
38580             if ( pPars->nVerbLimit < 0 )
38581                 goto usage;
38582             break;
38583         case 'a':
38584             pPars->fAreaOnly ^= 1;
38585             break;
38586         case 'e':
38587             pPars->fOptEdge ^= 1;
38588             break;
38589         case 'k':
38590             pPars->fCoarsen ^= 1;
38591             break;
38592         case 'm':
38593             pPars->fCutMin ^= 1;
38594             break;
38595         case 'd':
38596             pPars->fFuncDsd ^= 1;
38597             break;
38598         case 'c':
38599             pPars->fGenCnf ^= 1;
38600             break;
38601         case 'g':
38602             pPars->fPureAig ^= 1;
38603             break;
38604         case 'v':
38605             pPars->fVerbose ^= 1;
38606             break;
38607         case 'w':
38608             pPars->fVeryVerbose ^= 1;
38609             break;
38610         case 'h':
38611         default:
38612             goto usage;
38613         }
38614     }
38615 
38616     if ( pAbc->pGia == NULL )
38617     {
38618         Abc_Print( -1, "Empty GIA network.\n" );
38619         return 1;
38620     }
38621     if ( Gia_ManBufNum(pAbc->pGia) )
38622     {
38623         Abc_Print( -1, "Abc_CommandAbc9Jf(): This command does not work with barrier buffers.\n" );
38624         return 1;
38625     }
38626     if ( (pPars->fFuncDsd || pPars->fGenCnf) && pPars->nLutSize > 6 )
38627     {
38628         Abc_Print( -1, "Abc_CommandAbc9Jf(): DSD computation works for LUT6 or less.\n" );
38629         return 1;
38630     }
38631 
38632     if ( (pPars->fFuncDsd || pPars->fGenCnf) && !Sdm_ManCanRead() )
38633     {
38634         Abc_Print( -1, "Abc_CommandAbc9Jf(): Cannot input DSD data from file.\n" );
38635         return 1;
38636     }
38637 
38638     pNew = Jf_ManPerformMapping( pAbc->pGia, pPars );
38639     if ( pNew == NULL )
38640     {
38641         Abc_Print( -1, "Abc_CommandAbc9Jf(): Mapping into LUTs has failed.\n" );
38642         return 1;
38643     }
38644     Abc_FrameUpdateGia( pAbc, pNew );
38645     return 0;
38646 
38647 usage:
38648     if ( pPars->DelayTarget == -1 )
38649         sprintf(Buffer, "best possible" );
38650     else
38651         sprintf(Buffer, "%d", pPars->DelayTarget );
38652     Abc_Print( -2, "usage: &jf [-KCDW num] [-akmdcgvwh]\n" );
38653     Abc_Print( -2, "\t           performs technology mapping of the network\n" );
38654     Abc_Print( -2, "\t-K num   : LUT size for the mapping (2 <= K <= %d) [default = %d]\n", pPars->nLutSizeMax, pPars->nLutSize );
38655     Abc_Print( -2, "\t-C num   : the max number of priority cuts (1 <= C <= %d) [default = %d]\n", pPars->nCutNumMax, pPars->nCutNum );
38656     Abc_Print( -2, "\t-D num   : sets the delay constraint for the mapping [default = %s]\n", Buffer );
38657     Abc_Print( -2, "\t-W num   : min frequency when printing functions with \"-w\" [default = %d]\n", pPars->nVerbLimit );
38658     Abc_Print( -2, "\t-a       : toggles area-oriented mapping [default = %s]\n", pPars->fAreaOnly? "yes": "no" );
38659     Abc_Print( -2, "\t-e       : toggles edge vs node minimization [default = %s]\n", pPars->fOptEdge? "yes": "no" );
38660     Abc_Print( -2, "\t-k       : toggles coarsening the subject graph [default = %s]\n", pPars->fCoarsen? "yes": "no" );
38661     Abc_Print( -2, "\t-m       : toggles cut minimization [default = %s]\n", pPars->fCutMin? "yes": "no" );
38662     Abc_Print( -2, "\t-d       : toggles using DSD to represent cut functions [default = %s]\n", pPars->fFuncDsd? "yes": "no" );
38663     Abc_Print( -2, "\t-c       : toggles mapping for CNF generation [default = %s]\n", pPars->fGenCnf? "yes": "no" );
38664     Abc_Print( -2, "\t-g       : toggles generating AIG without mapping [default = %s]\n", pPars->fPureAig? "yes": "no" );
38665     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
38666     Abc_Print( -2, "\t-w       : toggles very verbose output [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
38667     Abc_Print( -2, "\t-h       : prints the command usage\n");
38668     return 1;
38669 }
38670 
38671 /**Function*************************************************************
38672 
38673   Synopsis    []
38674 
38675   Description []
38676 
38677   SideEffects []
38678 
38679   SeeAlso     []
38680 
38681 ***********************************************************************/
Abc_CommandAbc9Kf(Abc_Frame_t * pAbc,int argc,char ** argv)38682 int Abc_CommandAbc9Kf( Abc_Frame_t * pAbc, int argc, char ** argv )
38683 {
38684     extern void Kf_ManSetDefaultPars( Jf_Par_t * pPars );
38685     extern Gia_Man_t * Kf_ManPerformMapping( Gia_Man_t * pGia, Jf_Par_t * pPars );
38686     char Buffer[200];
38687     Jf_Par_t Pars, * pPars = &Pars;
38688     Gia_Man_t * pNew; int c;
38689     Kf_ManSetDefaultPars( pPars );
38690     Extra_UtilGetoptReset();
38691     while ( ( c = Extra_UtilGetopt( argc, argv, "KCPDWaekmdcgtsvwh" ) ) != EOF )
38692     {
38693         switch ( c )
38694         {
38695         case 'K':
38696             if ( globalUtilOptind >= argc )
38697             {
38698                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a positive integer.\n" );
38699                 goto usage;
38700             }
38701             pPars->nLutSize = atoi(argv[globalUtilOptind]);
38702             globalUtilOptind++;
38703             if ( pPars->nLutSize < 2 || pPars->nLutSize > pPars->nLutSizeMax )
38704             {
38705                 Abc_Print( -1, "LUT size %d is not supported.\n", pPars->nLutSize );
38706                 goto usage;
38707             }
38708             break;
38709         case 'C':
38710             if ( globalUtilOptind >= argc )
38711             {
38712                 Abc_Print( -1, "Command line switch \"-C\" should be followed by a positive integer.\n" );
38713                 goto usage;
38714             }
38715             pPars->nCutNum = atoi(argv[globalUtilOptind]);
38716             globalUtilOptind++;
38717             if ( pPars->nCutNum < 1 || pPars->nCutNum > pPars->nCutNumMax )
38718             {
38719                 Abc_Print( -1, "This number of cuts (%d) is not supported.\n", pPars->nCutNum );
38720                 goto usage;
38721             }
38722             break;
38723         case 'P':
38724             if ( globalUtilOptind >= argc )
38725             {
38726                 Abc_Print( -1, "Command line switch \"-P\" should be followed by a positive integer.\n" );
38727                 goto usage;
38728             }
38729             pPars->nProcNum = atoi(argv[globalUtilOptind]);
38730             globalUtilOptind++;
38731             if ( pPars->nProcNum < 0 )
38732                 goto usage;
38733             break;
38734         case 'D':
38735             if ( globalUtilOptind >= argc )
38736             {
38737                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a floating point number.\n" );
38738                 goto usage;
38739             }
38740             pPars->DelayTarget = atoi(argv[globalUtilOptind]);
38741             globalUtilOptind++;
38742             if ( pPars->DelayTarget <= 0.0 )
38743                 goto usage;
38744             break;
38745         case 'W':
38746             if ( globalUtilOptind >= argc )
38747             {
38748                 Abc_Print( -1, "Command line switch \"-W\" should be followed by a positive integer.\n" );
38749                 goto usage;
38750             }
38751             pPars->nVerbLimit = atoi(argv[globalUtilOptind]);
38752             globalUtilOptind++;
38753             if ( pPars->nVerbLimit < 0 )
38754                 goto usage;
38755             break;
38756         case 'a':
38757             pPars->fAreaOnly ^= 1;
38758             break;
38759         case 'e':
38760             pPars->fOptEdge ^= 1;
38761             break;
38762         case 'k':
38763             pPars->fCoarsen ^= 1;
38764             break;
38765         case 'm':
38766             pPars->fCutMin ^= 1;
38767             break;
38768         case 'd':
38769             pPars->fFuncDsd ^= 1;
38770             break;
38771         case 'c':
38772             pPars->fGenCnf ^= 1;
38773             break;
38774         case 'g':
38775             pPars->fPureAig ^= 1;
38776             break;
38777         case 't':
38778             pPars->fCutHashing ^= 1;
38779             break;
38780         case 's':
38781             pPars->fCutSimple ^= 1;
38782             break;
38783         case 'v':
38784             pPars->fVerbose ^= 1;
38785             break;
38786         case 'w':
38787             pPars->fVeryVerbose ^= 1;
38788             break;
38789         case 'h':
38790         default:
38791             goto usage;
38792         }
38793     }
38794 
38795     if ( pAbc->pGia == NULL )
38796     {
38797         Abc_Print( -1, "Empty GIA network.\n" );
38798         return 1;
38799     }
38800 
38801     pNew = Kf_ManPerformMapping( pAbc->pGia, pPars );
38802     if ( pNew == NULL )
38803     {
38804         Abc_Print( -1, "Abc_CommandAbc9Kf(): Mapping into LUTs has failed.\n" );
38805         return 1;
38806     }
38807     Abc_FrameUpdateGia( pAbc, pNew );
38808     return 0;
38809 
38810 usage:
38811     if ( pPars->DelayTarget == -1 )
38812         sprintf(Buffer, "best possible" );
38813     else
38814         sprintf(Buffer, "%d", pPars->DelayTarget );
38815     Abc_Print( -2, "usage: &kf [-KCPDW num] [-akmdcgtsvwh]\n" );
38816     Abc_Print( -2, "\t           performs technology mapping of the network\n" );
38817     Abc_Print( -2, "\t-K num   : LUT size for the mapping (2 <= K <= %d) [default = %d]\n", pPars->nLutSizeMax, pPars->nLutSize );
38818     Abc_Print( -2, "\t-C num   : the max number of priority cuts (1 <= C <= %d) [default = %d]\n", pPars->nCutNumMax, pPars->nCutNum );
38819     Abc_Print( -2, "\t-P num   : the number of cut computation processes (0 <= P <= %d) [default = %d]\n", pPars->nProcNumMax, pPars->nProcNum );
38820     Abc_Print( -2, "\t-D num   : sets the delay constraint for the mapping [default = %s]\n", Buffer );
38821     Abc_Print( -2, "\t-W num   : min frequency when printing functions with \"-w\" [default = %d]\n", pPars->nVerbLimit );
38822     Abc_Print( -2, "\t-a       : toggles area-oriented mapping [default = %s]\n", pPars->fAreaOnly? "yes": "no" );
38823     Abc_Print( -2, "\t-e       : toggles edge vs node minimization [default = %s]\n", pPars->fOptEdge? "yes": "no" );
38824     Abc_Print( -2, "\t-k       : toggles coarsening the subject graph [default = %s]\n", pPars->fCoarsen? "yes": "no" );
38825     Abc_Print( -2, "\t-m       : toggles cut minimization [default = %s]\n", pPars->fCutMin? "yes": "no" );
38826     Abc_Print( -2, "\t-d       : toggles using DSD to represent cut functions [default = %s]\n", pPars->fFuncDsd? "yes": "no" );
38827     Abc_Print( -2, "\t-c       : toggles mapping for CNF generation [default = %s]\n", pPars->fGenCnf? "yes": "no" );
38828     Abc_Print( -2, "\t-g       : toggles generating AIG without mapping [default = %s]\n", pPars->fPureAig? "yes": "no" );
38829     Abc_Print( -2, "\t-t       : toggles cut computation using hash table [default = %s]\n", pPars->fCutHashing? "yes": "no" );
38830     Abc_Print( -2, "\t-s       : toggles cut computation using a simple method [default = %s]\n", pPars->fCutSimple? "yes": "no" );
38831     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
38832     Abc_Print( -2, "\t-w       : toggles very verbose output [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
38833     Abc_Print( -2, "\t-h       : prints the command usage\n");
38834     return 1;
38835 }
38836 
38837 /**Function*************************************************************
38838 
38839   Synopsis    []
38840 
38841   Description []
38842 
38843   SideEffects []
38844 
38845   SeeAlso     []
38846 
38847 ***********************************************************************/
Abc_CommandAbc9Lf(Abc_Frame_t * pAbc,int argc,char ** argv)38848 int Abc_CommandAbc9Lf( Abc_Frame_t * pAbc, int argc, char ** argv )
38849 {
38850     char Buffer[200];
38851     Jf_Par_t Pars, * pPars = &Pars;
38852     Gia_Man_t * pNew; int c;
38853     Lf_ManSetDefaultPars( pPars );
38854     Extra_UtilGetoptReset();
38855     while ( ( c = Extra_UtilGetopt( argc, argv, "KCFARLEDWMekmupstgvwh" ) ) != EOF )
38856     {
38857         switch ( c )
38858         {
38859         case 'K':
38860             if ( globalUtilOptind >= argc )
38861             {
38862                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a positive integer.\n" );
38863                 goto usage;
38864             }
38865             pPars->nLutSize = atoi(argv[globalUtilOptind]);
38866             globalUtilOptind++;
38867             if ( pPars->nLutSize < 2 || pPars->nLutSize > pPars->nLutSizeMax )
38868             {
38869                 Abc_Print( -1, "LUT size %d is not supported.\n", pPars->nLutSize );
38870                 goto usage;
38871             }
38872             break;
38873         case 'C':
38874             if ( globalUtilOptind >= argc )
38875             {
38876                 Abc_Print( -1, "Command line switch \"-C\" should be followed by a positive integer.\n" );
38877                 goto usage;
38878             }
38879             pPars->nCutNum = atoi(argv[globalUtilOptind]);
38880             globalUtilOptind++;
38881             if ( pPars->nCutNum < 1 || pPars->nCutNum > pPars->nCutNumMax )
38882             {
38883                 Abc_Print( -1, "This number of cuts (%d) is not supported.\n", pPars->nCutNum );
38884                 goto usage;
38885             }
38886             break;
38887         case 'F':
38888             if ( globalUtilOptind >= argc )
38889             {
38890                 Abc_Print( -1, "Command line switch \"-F\" should be followed by a positive integer.\n" );
38891                 goto usage;
38892             }
38893             pPars->nRounds = atoi(argv[globalUtilOptind]);
38894             globalUtilOptind++;
38895             if ( pPars->nRounds < 0 )
38896                 goto usage;
38897             break;
38898         case 'A':
38899             if ( globalUtilOptind >= argc )
38900             {
38901                 Abc_Print( -1, "Command line switch \"-A\" should be followed by a positive integer.\n" );
38902                 goto usage;
38903             }
38904             pPars->nRoundsEla = atoi(argv[globalUtilOptind]);
38905             globalUtilOptind++;
38906             if ( pPars->nRoundsEla < 0 )
38907                 goto usage;
38908             break;
38909         case 'R':
38910             if ( globalUtilOptind >= argc )
38911             {
38912                 Abc_Print( 1, "Command line switch \"-R\" should be followed by a floating point number.\n" );
38913                 return 0;
38914             }
38915             pPars->nRelaxRatio = atoi(argv[globalUtilOptind]);
38916             globalUtilOptind++;
38917             if ( pPars->nRelaxRatio < 0 )
38918                 goto usage;
38919             break;
38920         case 'L':
38921             if ( globalUtilOptind >= argc )
38922             {
38923                 Abc_Print( 1, "Command line switch \"-R\" should be followed by a floating point number.\n" );
38924                 return 0;
38925             }
38926             pPars->nCoarseLimit = atoi(argv[globalUtilOptind]);
38927             globalUtilOptind++;
38928             if ( pPars->nCoarseLimit < 0 )
38929                 goto usage;
38930             break;
38931         case 'E':
38932             if ( globalUtilOptind >= argc )
38933             {
38934                 Abc_Print( 1, "Command line switch \"-E\" should be followed by a floating point number.\n" );
38935                 return 0;
38936             }
38937             pPars->nAreaTuner = atoi(argv[globalUtilOptind]);
38938             globalUtilOptind++;
38939             if ( pPars->nAreaTuner < 0 )
38940                 goto usage;
38941             break;
38942         case 'D':
38943             if ( globalUtilOptind >= argc )
38944             {
38945                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a floating point number.\n" );
38946                 goto usage;
38947             }
38948             pPars->DelayTarget = atoi(argv[globalUtilOptind]);
38949             globalUtilOptind++;
38950             if ( pPars->DelayTarget <= 0.0 )
38951                 goto usage;
38952             break;
38953         case 'W':
38954             if ( globalUtilOptind >= argc )
38955             {
38956                 Abc_Print( -1, "Command line switch \"-W\" should be followed by a positive integer.\n" );
38957                 goto usage;
38958             }
38959             pPars->nVerbLimit = atoi(argv[globalUtilOptind]);
38960             globalUtilOptind++;
38961             if ( pPars->nVerbLimit < 0 )
38962                 goto usage;
38963             break;
38964         case 'M':
38965             if ( globalUtilOptind >= argc )
38966             {
38967                 Abc_Print( -1, "Command line switch \"-M\" should be followed by a positive integer.\n" );
38968                 goto usage;
38969             }
38970             pPars->nLutSizeMux = atoi(argv[globalUtilOptind]);
38971             globalUtilOptind++;
38972             if ( pPars->nLutSizeMux < 2 || pPars->nLutSizeMux > pPars->nLutSizeMax )
38973             {
38974                 Abc_Print( -1, "LUT size %d is not supported.\n", pPars->nLutSizeMux );
38975                 goto usage;
38976             }
38977             break;
38978         case 'a':
38979             pPars->fAreaOnly ^= 1;
38980             break;
38981         case 'e':
38982             pPars->fOptEdge ^= 1;
38983             break;
38984         case 'k':
38985             pPars->fCoarsen ^= 1;
38986             break;
38987         case 'm':
38988             pPars->fCutMin ^= 1;
38989             break;
38990         case 'u':
38991             pPars->fUseMux7 ^= 1;
38992             break;
38993         case 'p':
38994             pPars->fPower ^= 1;
38995             break;
38996         case 's':
38997             pPars->fPureAig ^= 1;
38998             break;
38999         case 't':
39000             pPars->fDoAverage ^= 1;
39001             break;
39002         case 'g':
39003             pPars->fCutGroup ^= 1;
39004             break;
39005         case 'v':
39006             pPars->fVerbose ^= 1;
39007             break;
39008         case 'w':
39009             pPars->fVeryVerbose ^= 1;
39010             break;
39011         case 'h':
39012         default:
39013             goto usage;
39014         }
39015     }
39016 
39017     if ( pAbc->pGia == NULL )
39018     {
39019         Abc_Print( -1, "Empty GIA network.\n" );
39020         return 1;
39021     }
39022     if ( Gia_ManHasMapping(pAbc->pGia) )
39023     {
39024         Abc_Print( -1, "Current AIG has mapping. Run \"&st\".\n" );
39025         return 1;
39026     }
39027     if ( pPars->nLutSizeMux && pPars->fUseMux7 )
39028     {
39029         Abc_Print( -1, "Flags \"-M\" and \"-u\" are incompatible.\n" );
39030         return 1;
39031     }
39032     if ( pPars->fCutGroup )
39033     {
39034         if ( pPars->nLutSize < 4 || pPars->nLutSize > 6 )
39035         {
39036             Abc_Print( -1, "This feature works only for LUT size equal to 4, 5, and 6.\n" );
39037             return 1;
39038         }
39039         printf( "Using cut grouping for %d-LUTs. Considering cuts up to %d.\n", pPars->nLutSize, 2*pPars->nLutSize + 1 );
39040         pPars->nLutSize = 2*pPars->nLutSize + 1;
39041     }
39042     pNew = Lf_ManPerformMapping( pAbc->pGia, pPars );
39043     if ( pNew == NULL )
39044     {
39045         Abc_Print( -1, "Abc_CommandAbc9Lf(): Mapping into LUTs has failed.\n" );
39046         return 1;
39047     }
39048     Abc_FrameUpdateGia( pAbc, pNew );
39049     return 0;
39050 
39051 usage:
39052     if ( pPars->DelayTarget == -1 )
39053         sprintf(Buffer, "best possible" );
39054     else
39055         sprintf(Buffer, "%d", pPars->DelayTarget );
39056     Abc_Print( -2, "usage: &lf [-KCFARLEDM num] [-kmupstgvwh]\n" );
39057     Abc_Print( -2, "\t           performs technology mapping of the network\n" );
39058     Abc_Print( -2, "\t-K num   : LUT size for the mapping (2 <= K <= %d) [default = %d]\n", pPars->nLutSizeMax, pPars->nLutSize );
39059     Abc_Print( -2, "\t-C num   : the max number of priority cuts (1 <= C <= %d) [default = %d]\n", pPars->nCutNumMax, pPars->nCutNum );
39060     Abc_Print( -2, "\t-F num   : the number of area flow rounds [default = %d]\n", pPars->nRounds );
39061     Abc_Print( -2, "\t-A num   : the number of exact area rounds [default = %d]\n", pPars->nRoundsEla );
39062     Abc_Print( -2, "\t-R num   : the delay relaxation ratio (num >= 0) [default = %d]\n", pPars->nRelaxRatio );
39063     Abc_Print( -2, "\t-L num   : the fanout limit for coarsening XOR/MUX (num >= 2) [default = %d]\n", pPars->nCoarseLimit );
39064     Abc_Print( -2, "\t-E num   : the area/edge tradeoff parameter (0 <= num <= 100) [default = %d]\n", pPars->nAreaTuner );
39065     Abc_Print( -2, "\t-D num   : sets the delay constraint for the mapping [default = %s]\n", Buffer );
39066     Abc_Print( -2, "\t-M num   : LUT size when cofactoring is performed (0 <= num <= 100) [default = %d]\n", pPars->nLutSizeMux );
39067 //    Abc_Print( -2, "\t-a       : toggles area-oriented mapping [default = %s]\n", pPars->fAreaOnly? "yes": "no" );
39068     Abc_Print( -2, "\t-e       : toggles edge vs node minimization [default = %s]\n", pPars->fOptEdge? "yes": "no" );
39069     Abc_Print( -2, "\t-k       : toggles coarsening the subject graph [default = %s]\n", pPars->fCoarsen? "yes": "no" );
39070     Abc_Print( -2, "\t-m       : toggles cut minimization [default = %s]\n", pPars->fCutMin? "yes": "no" );
39071     Abc_Print( -2, "\t-u       : toggles using additional MUXes [default = %s]\n", pPars->fUseMux7? "yes": "no" );
39072     Abc_Print( -2, "\t-p       : toggles power-aware cut selection heuristics [default = %s]\n", pPars->fPower? "yes": "no" );
39073     Abc_Print( -2, "\t-s       : toggles generating AIG without mapping [default = %s]\n", pPars->fPureAig? "yes": "no" );
39074     Abc_Print( -2, "\t-t       : toggles optimizing average rather than maximum level [default = %s]\n", pPars->fDoAverage? "yes": "no" );
39075     Abc_Print( -2, "\t-g       : toggles using cut splitting [default = %s]\n", pPars->fCutGroup? "yes": "no" );
39076     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
39077     Abc_Print( -2, "\t-w       : toggles very verbose output [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
39078     Abc_Print( -2, "\t-h       : prints the command usage\n");
39079     return 1;
39080 }
39081 
39082 /**Function*************************************************************
39083 
39084   Synopsis    []
39085 
39086   Description []
39087 
39088   SideEffects []
39089 
39090   SeeAlso     []
39091 
39092 ***********************************************************************/
Abc_CommandAbc9Mf(Abc_Frame_t * pAbc,int argc,char ** argv)39093 int Abc_CommandAbc9Mf( Abc_Frame_t * pAbc, int argc, char ** argv )
39094 {
39095     char Buffer[200];
39096     Jf_Par_t Pars, * pPars = &Pars;
39097     Gia_Man_t * pNew; int c;
39098     Mf_ManSetDefaultPars( pPars );
39099     Extra_UtilGetoptReset();
39100     while ( ( c = Extra_UtilGetopt( argc, argv, "KCFARLEDWaekmcgvwh" ) ) != EOF )
39101     {
39102         switch ( c )
39103         {
39104         case 'K':
39105             if ( globalUtilOptind >= argc )
39106             {
39107                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a positive integer.\n" );
39108                 goto usage;
39109             }
39110             pPars->nLutSize = atoi(argv[globalUtilOptind]);
39111             globalUtilOptind++;
39112             if ( pPars->nLutSize < 2 || pPars->nLutSize > pPars->nLutSizeMax )
39113             {
39114                 Abc_Print( -1, "LUT size %d is not supported.\n", pPars->nLutSize );
39115                 goto usage;
39116             }
39117             break;
39118         case 'C':
39119             if ( globalUtilOptind >= argc )
39120             {
39121                 Abc_Print( -1, "Command line switch \"-C\" should be followed by a positive integer.\n" );
39122                 goto usage;
39123             }
39124             pPars->nCutNum = atoi(argv[globalUtilOptind]);
39125             globalUtilOptind++;
39126             if ( pPars->nCutNum < 1 || pPars->nCutNum > pPars->nCutNumMax )
39127             {
39128                 Abc_Print( -1, "This number of cuts (%d) is not supported.\n", pPars->nCutNum );
39129                 goto usage;
39130             }
39131             break;
39132         case 'F':
39133             if ( globalUtilOptind >= argc )
39134             {
39135                 Abc_Print( -1, "Command line switch \"-F\" should be followed by a positive integer.\n" );
39136                 goto usage;
39137             }
39138             pPars->nRounds = atoi(argv[globalUtilOptind]);
39139             globalUtilOptind++;
39140             if ( pPars->nRounds < 0 )
39141                 goto usage;
39142             break;
39143         case 'A':
39144             if ( globalUtilOptind >= argc )
39145             {
39146                 Abc_Print( -1, "Command line switch \"-A\" should be followed by a positive integer.\n" );
39147                 goto usage;
39148             }
39149             pPars->nRoundsEla = atoi(argv[globalUtilOptind]);
39150             globalUtilOptind++;
39151             if ( pPars->nRoundsEla < 0 )
39152                 goto usage;
39153             break;
39154         case 'R':
39155             if ( globalUtilOptind >= argc )
39156             {
39157                 Abc_Print( 1, "Command line switch \"-R\" should be followed by a floating point number.\n" );
39158                 return 0;
39159             }
39160             pPars->nRelaxRatio = atoi(argv[globalUtilOptind]);
39161             globalUtilOptind++;
39162             if ( pPars->nRelaxRatio < 0 )
39163                 goto usage;
39164             break;
39165         case 'L':
39166             if ( globalUtilOptind >= argc )
39167             {
39168                 Abc_Print( 1, "Command line switch \"-R\" should be followed by a floating point number.\n" );
39169                 return 0;
39170             }
39171             pPars->nCoarseLimit = atoi(argv[globalUtilOptind]);
39172             globalUtilOptind++;
39173             if ( pPars->nCoarseLimit < 0 )
39174                 goto usage;
39175             break;
39176         case 'E':
39177             if ( globalUtilOptind >= argc )
39178             {
39179                 Abc_Print( 1, "Command line switch \"-E\" should be followed by a floating point number.\n" );
39180                 return 0;
39181             }
39182             pPars->nAreaTuner = atoi(argv[globalUtilOptind]);
39183             globalUtilOptind++;
39184             if ( pPars->nAreaTuner < 0 )
39185                 goto usage;
39186             break;
39187         case 'D':
39188             if ( globalUtilOptind >= argc )
39189             {
39190                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a floating point number.\n" );
39191                 goto usage;
39192             }
39193             pPars->DelayTarget = atoi(argv[globalUtilOptind]);
39194             globalUtilOptind++;
39195             if ( pPars->DelayTarget <= 0.0 )
39196                 goto usage;
39197             break;
39198         case 'W':
39199             if ( globalUtilOptind >= argc )
39200             {
39201                 Abc_Print( -1, "Command line switch \"-W\" should be followed by a positive integer.\n" );
39202                 goto usage;
39203             }
39204             pPars->nVerbLimit = atoi(argv[globalUtilOptind]);
39205             globalUtilOptind++;
39206             if ( pPars->nVerbLimit < 0 )
39207                 goto usage;
39208             break;
39209         case 'a':
39210             pPars->fAreaOnly ^= 1;
39211             break;
39212         case 'e':
39213             pPars->fOptEdge ^= 1;
39214             break;
39215         case 'k':
39216             pPars->fCoarsen ^= 1;
39217             break;
39218         case 'm':
39219             pPars->fCutMin ^= 1;
39220             break;
39221         case 'c':
39222             pPars->fGenCnf ^= 1;
39223             break;
39224         case 'g':
39225             pPars->fPureAig ^= 1;
39226             break;
39227         case 'v':
39228             pPars->fVerbose ^= 1;
39229             break;
39230         case 'w':
39231             pPars->fVeryVerbose ^= 1;
39232             break;
39233         case 'h':
39234         default:
39235             goto usage;
39236         }
39237     }
39238 
39239     if ( pAbc->pGia == NULL )
39240     {
39241         Abc_Print( -1, "Empty GIA network.\n" );
39242         return 1;
39243     }
39244 
39245     pNew = Mf_ManPerformMapping( pAbc->pGia, pPars );
39246     if ( pNew == NULL )
39247     {
39248         Abc_Print( -1, "Abc_CommandAbc9Lf(): Mapping into LUTs has failed.\n" );
39249         return 1;
39250     }
39251     if ( pPars->fGenCnf )
39252         Cnf_DataFree( (Cnf_Dat_t*)pAbc->pGia->pData ), pAbc->pGia->pData = NULL;
39253     Abc_FrameUpdateGia( pAbc, pNew );
39254     return 0;
39255 
39256 usage:
39257     if ( pPars->DelayTarget == -1 )
39258         sprintf(Buffer, "best possible" );
39259     else
39260         sprintf(Buffer, "%d", pPars->DelayTarget );
39261     Abc_Print( -2, "usage: &mf [-KCFARLED num] [-akmcgvwh]\n" );
39262     Abc_Print( -2, "\t           performs technology mapping of the network\n" );
39263     Abc_Print( -2, "\t-K num   : LUT size for the mapping (2 <= K <= %d) [default = %d]\n", pPars->nLutSizeMax, pPars->nLutSize );
39264     Abc_Print( -2, "\t-C num   : the max number of priority cuts (1 <= C <= %d) [default = %d]\n", pPars->nCutNumMax, pPars->nCutNum );
39265     Abc_Print( -2, "\t-F num   : the number of area flow rounds [default = %d]\n", pPars->nRounds );
39266     Abc_Print( -2, "\t-A num   : the number of exact area rounds [default = %d]\n", pPars->nRoundsEla );
39267     Abc_Print( -2, "\t-R num   : the delay relaxation ratio (num >= 0) [default = %d]\n", pPars->nRelaxRatio );
39268     Abc_Print( -2, "\t-L num   : the fanout limit for coarsening XOR/MUX (num >= 2) [default = %d]\n", pPars->nCoarseLimit );
39269     Abc_Print( -2, "\t-E num   : the area/edge tradeoff parameter (0 <= num <= 100) [default = %d]\n", pPars->nAreaTuner );
39270     Abc_Print( -2, "\t-D num   : sets the delay constraint for the mapping [default = %s]\n", Buffer );
39271     Abc_Print( -2, "\t-a       : toggles area-oriented mapping [default = %s]\n", pPars->fAreaOnly? "yes": "no" );
39272     Abc_Print( -2, "\t-e       : toggles edge vs node minimization [default = %s]\n", pPars->fOptEdge? "yes": "no" );
39273     Abc_Print( -2, "\t-k       : toggles coarsening the subject graph [default = %s]\n", pPars->fCoarsen? "yes": "no" );
39274     Abc_Print( -2, "\t-m       : toggles cut minimization [default = %s]\n", pPars->fCutMin? "yes": "no" );
39275     Abc_Print( -2, "\t-c       : toggles mapping for CNF generation [default = %s]\n", pPars->fGenCnf? "yes": "no" );
39276     Abc_Print( -2, "\t-g       : toggles generating AIG without mapping [default = %s]\n", pPars->fPureAig? "yes": "no" );
39277     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
39278     Abc_Print( -2, "\t-w       : toggles very verbose output [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
39279     Abc_Print( -2, "\t-h       : prints the command usage\n");
39280     return 1;
39281 }
39282 
39283 /**Function*************************************************************
39284 
39285   Synopsis    []
39286 
39287   Description []
39288 
39289   SideEffects []
39290 
39291   SeeAlso     []
39292 
39293 ***********************************************************************/
Abc_CommandAbc9Nf(Abc_Frame_t * pAbc,int argc,char ** argv)39294 int Abc_CommandAbc9Nf( Abc_Frame_t * pAbc, int argc, char ** argv )
39295 {
39296     extern void Nf_ManSetDefaultPars( Jf_Par_t * pPars );
39297     extern Gia_Man_t * Nf_ManPerformMapping( Gia_Man_t * pGia, Jf_Par_t * pPars );
39298     extern Gia_Man_t * Pf_ManPerformMapping( Gia_Man_t * pGia, Jf_Par_t * pPars );
39299     char Buffer[200];
39300     Jf_Par_t Pars, * pPars = &Pars;
39301     Gia_Man_t * pNew; int c;
39302     Nf_ManSetDefaultPars( pPars );
39303     Extra_UtilGetoptReset();
39304     while ( ( c = Extra_UtilGetopt( argc, argv, "KCFARLEDQWakpqfvwh" ) ) != EOF )
39305     {
39306         switch ( c )
39307         {
39308         case 'K':
39309             if ( globalUtilOptind >= argc )
39310             {
39311                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a positive integer.\n" );
39312                 goto usage;
39313             }
39314             pPars->nLutSize = atoi(argv[globalUtilOptind]);
39315             globalUtilOptind++;
39316             if ( pPars->nLutSize < 2 || pPars->nLutSize > pPars->nLutSizeMax )
39317             {
39318                 Abc_Print( -1, "LUT size %d is not supported.\n", pPars->nLutSize );
39319                 goto usage;
39320             }
39321             break;
39322         case 'C':
39323             if ( globalUtilOptind >= argc )
39324             {
39325                 Abc_Print( -1, "Command line switch \"-C\" should be followed by a positive integer.\n" );
39326                 goto usage;
39327             }
39328             pPars->nCutNum = atoi(argv[globalUtilOptind]);
39329             globalUtilOptind++;
39330             if ( pPars->nCutNum < 1 || pPars->nCutNum > pPars->nCutNumMax )
39331             {
39332                 Abc_Print( -1, "This number of cuts (%d) is not supported.\n", pPars->nCutNum );
39333                 goto usage;
39334             }
39335             break;
39336         case 'F':
39337             if ( globalUtilOptind >= argc )
39338             {
39339                 Abc_Print( -1, "Command line switch \"-F\" should be followed by a positive integer.\n" );
39340                 goto usage;
39341             }
39342             pPars->nRounds = atoi(argv[globalUtilOptind]);
39343             globalUtilOptind++;
39344             if ( pPars->nRounds < 0 )
39345                 goto usage;
39346             break;
39347         case 'A':
39348             if ( globalUtilOptind >= argc )
39349             {
39350                 Abc_Print( -1, "Command line switch \"-A\" should be followed by a positive integer.\n" );
39351                 goto usage;
39352             }
39353             pPars->nRoundsEla = atoi(argv[globalUtilOptind]);
39354             globalUtilOptind++;
39355             if ( pPars->nRoundsEla < 0 )
39356                 goto usage;
39357             break;
39358         case 'R':
39359             if ( globalUtilOptind >= argc )
39360             {
39361                 Abc_Print( 1, "Command line switch \"-R\" should be followed by an integer number.\n" );
39362                 return 0;
39363             }
39364             pPars->nRelaxRatio = atoi(argv[globalUtilOptind]);
39365             globalUtilOptind++;
39366             if ( pPars->nRelaxRatio < 0 )
39367                 goto usage;
39368             break;
39369         case 'L':
39370             if ( globalUtilOptind >= argc )
39371             {
39372                 Abc_Print( 1, "Command line switch \"-R\" should be followed by an integer number.\n" );
39373                 return 0;
39374             }
39375             pPars->nCoarseLimit = atoi(argv[globalUtilOptind]);
39376             globalUtilOptind++;
39377             if ( pPars->nCoarseLimit < 0 )
39378                 goto usage;
39379             break;
39380         case 'E':
39381             if ( globalUtilOptind >= argc )
39382             {
39383                 Abc_Print( 1, "Command line switch \"-E\" should be followed by an integer number.\n" );
39384                 return 0;
39385             }
39386             pPars->nAreaTuner = atoi(argv[globalUtilOptind]);
39387             globalUtilOptind++;
39388             if ( pPars->nAreaTuner < 0 )
39389                 goto usage;
39390             break;
39391         case 'D':
39392             if ( globalUtilOptind >= argc )
39393             {
39394                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer number.\n" );
39395                 goto usage;
39396             }
39397             pPars->DelayTarget = atoi(argv[globalUtilOptind]);
39398             globalUtilOptind++;
39399             if ( pPars->DelayTarget <= 0 )
39400                 goto usage;
39401             break;
39402         case 'Q':
39403             if ( globalUtilOptind >= argc )
39404             {
39405                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer number.\n" );
39406                 goto usage;
39407             }
39408             pPars->nReqTimeFlex = atoi(argv[globalUtilOptind]);
39409             globalUtilOptind++;
39410             if ( pPars->nReqTimeFlex < 0 )
39411                 goto usage;
39412             break;
39413         case 'W':
39414             if ( globalUtilOptind >= argc )
39415             {
39416                 Abc_Print( -1, "Command line switch \"-W\" should be followed by a positive integer.\n" );
39417                 goto usage;
39418             }
39419             pPars->nVerbLimit = atoi(argv[globalUtilOptind]);
39420             globalUtilOptind++;
39421             if ( pPars->nVerbLimit < 0 )
39422                 goto usage;
39423             break;
39424         case 'a':
39425             pPars->fAreaOnly ^= 1;
39426             break;
39427         case 'k':
39428             pPars->fCoarsen ^= 1;
39429             break;
39430         case 'p':
39431             pPars->fPinPerm ^= 1;
39432             break;
39433         case 'q':
39434             pPars->fPinQuick ^= 1;
39435             break;
39436         case 'f':
39437             pPars->fPinFilter ^= 1;
39438             break;
39439         case 'v':
39440             pPars->fVerbose ^= 1;
39441             break;
39442         case 'w':
39443             pPars->fVeryVerbose ^= 1;
39444             break;
39445         case 'h':
39446         default:
39447             goto usage;
39448         }
39449     }
39450     if ( pAbc->pGia == NULL )
39451     {
39452         Abc_Print( -1, "Empty GIA network.\n" );
39453         return 1;
39454     }
39455     if ( Abc_FrameReadLibGen() == NULL )
39456     {
39457         Abc_Print( -1, "Current library is not available.\n" );
39458         return 1;
39459     }
39460 //    if ( pPars->fAreaOnly )
39461 //        pNew = Pf_ManPerformMapping( pAbc->pGia, pPars );
39462 //    else
39463         pNew = Nf_ManPerformMapping( pAbc->pGia, pPars );
39464     if ( pNew == NULL )
39465     {
39466         Abc_Print( -1, "Abc_CommandAbc9Nf(): Mapping into LUTs has failed.\n" );
39467         return 1;
39468     }
39469     Abc_FrameUpdateGia( pAbc, pNew );
39470     return 0;
39471 
39472 usage:
39473     if ( pPars->DelayTarget == -1 )
39474         sprintf(Buffer, "best possible" );
39475     else
39476         sprintf(Buffer, "%d", pPars->DelayTarget );
39477     Abc_Print( -2, "usage: &nf [-KCFARLEDQ num] [-akpqfvwh]\n" );
39478     Abc_Print( -2, "\t           performs technology mapping of the network\n" );
39479     Abc_Print( -2, "\t-K num   : LUT size for the mapping (2 <= K <= %d) [default = %d]\n",                  pPars->nLutSizeMax, pPars->nLutSize );
39480     Abc_Print( -2, "\t-C num   : the max number of priority cuts (1 <= C <= %d) [default = %d]\n",           pPars->nCutNumMax, pPars->nCutNum );
39481     Abc_Print( -2, "\t-F num   : the number of area flow rounds [default = %d]\n",                           pPars->nRounds );
39482     Abc_Print( -2, "\t-A num   : the number of exact area rounds (when \'-a\' is used) [default = %d]\n",    pPars->nRoundsEla );
39483     Abc_Print( -2, "\t-R num   : the delay relaxation ratio (num >= 0) [default = %d]\n",                    pPars->nRelaxRatio );
39484     Abc_Print( -2, "\t-L num   : the fanout limit for coarsening XOR/MUX (num >= 2) [default = %d]\n",       pPars->nCoarseLimit );
39485     Abc_Print( -2, "\t-E num   : the area/edge tradeoff parameter (0 <= num <= 100) [default = %d]\n",       pPars->nAreaTuner );
39486     Abc_Print( -2, "\t-D num   : sets the delay constraint for the mapping [default = %s]\n",                Buffer );
39487     Abc_Print( -2, "\t-Q num   : internal parameter impacting area of the mapping [default = %d]\n",         pPars->nReqTimeFlex );
39488     Abc_Print( -2, "\t-a       : toggles SAT-based area-oriented mapping (experimental) [default = %s]\n",   pPars->fAreaOnly? "yes": "no" );
39489     Abc_Print( -2, "\t-k       : toggles coarsening the subject graph [default = %s]\n",                     pPars->fCoarsen? "yes": "no" );
39490     Abc_Print( -2, "\t-p       : toggles pin permutation (more matches - better quality) [default = %s]\n",  pPars->fPinPerm? "yes": "no" );
39491     Abc_Print( -2, "\t-q       : toggles quick mapping (fewer matches - worse quality) [default = %s]\n",    pPars->fPinQuick? "yes": "no" );
39492     Abc_Print( -2, "\t-f       : toggles filtering matches (useful with unit delay model) [default = %s]\n", pPars->fPinFilter? "yes": "no" );
39493     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n",                                   pPars->fVerbose? "yes": "no" );
39494     Abc_Print( -2, "\t-w       : toggles very verbose output [default = %s]\n",                              pPars->fVeryVerbose? "yes": "no" );
39495     Abc_Print( -2, "\t-h       : prints the command usage\n");
39496     return 1;
39497 }
39498 
39499 /**Function*************************************************************
39500 
39501   Synopsis    []
39502 
39503   Description []
39504 
39505   SideEffects []
39506 
39507   SeeAlso     []
39508 
39509 ***********************************************************************/
Abc_CommandAbc9Of(Abc_Frame_t * pAbc,int argc,char ** argv)39510 int Abc_CommandAbc9Of( Abc_Frame_t * pAbc, int argc, char ** argv )
39511 {
39512     extern void Of_ManSetDefaultPars( Jf_Par_t * pPars );
39513     extern Gia_Man_t * Of_ManPerformMapping( Gia_Man_t * pGia, Jf_Par_t * pPars );
39514     char Buffer[200];
39515     Jf_Par_t Pars, * pPars = &Pars;
39516     Gia_Man_t * pNew; int c;
39517     Of_ManSetDefaultPars( pPars );
39518     Extra_UtilGetoptReset();
39519     while ( ( c = Extra_UtilGetopt( argc, argv, "KCFARLEDNMQekmpgtvwh" ) ) != EOF )
39520     {
39521         switch ( c )
39522         {
39523         case 'K':
39524             if ( globalUtilOptind >= argc )
39525             {
39526                 Abc_Print( -1, "Command line switch \"-K\" should be followed by a positive integer.\n" );
39527                 goto usage;
39528             }
39529             pPars->nLutSize = atoi(argv[globalUtilOptind]);
39530             globalUtilOptind++;
39531             if ( pPars->nLutSize < 2 || pPars->nLutSize > pPars->nLutSizeMax )
39532             {
39533                 Abc_Print( -1, "LUT size %d is not supported.\n", pPars->nLutSize );
39534                 goto usage;
39535             }
39536             break;
39537         case 'C':
39538             if ( globalUtilOptind >= argc )
39539             {
39540                 Abc_Print( -1, "Command line switch \"-C\" should be followed by a positive integer.\n" );
39541                 goto usage;
39542             }
39543             pPars->nCutNum = atoi(argv[globalUtilOptind]);
39544             globalUtilOptind++;
39545             if ( pPars->nCutNum < 1 || pPars->nCutNum > pPars->nCutNumMax )
39546             {
39547                 Abc_Print( -1, "This number of cuts (%d) is not supported.\n", pPars->nCutNum );
39548                 goto usage;
39549             }
39550             break;
39551         case 'F':
39552             if ( globalUtilOptind >= argc )
39553             {
39554                 Abc_Print( -1, "Command line switch \"-F\" should be followed by a positive integer.\n" );
39555                 goto usage;
39556             }
39557             pPars->nRounds = atoi(argv[globalUtilOptind]);
39558             globalUtilOptind++;
39559             if ( pPars->nRounds < 0 )
39560                 goto usage;
39561             break;
39562         case 'A':
39563             if ( globalUtilOptind >= argc )
39564             {
39565                 Abc_Print( -1, "Command line switch \"-A\" should be followed by a positive integer.\n" );
39566                 goto usage;
39567             }
39568             pPars->nRoundsEla = atoi(argv[globalUtilOptind]);
39569             globalUtilOptind++;
39570             if ( pPars->nRoundsEla < 0 )
39571                 goto usage;
39572             break;
39573         case 'R':
39574             if ( globalUtilOptind >= argc )
39575             {
39576                 Abc_Print( 1, "Command line switch \"-R\" should be followed by a floating point number.\n" );
39577                 return 0;
39578             }
39579             pPars->nRelaxRatio = atoi(argv[globalUtilOptind]);
39580             globalUtilOptind++;
39581             if ( pPars->nRelaxRatio < 0 )
39582                 goto usage;
39583             break;
39584         case 'L':
39585             if ( globalUtilOptind >= argc )
39586             {
39587                 Abc_Print( 1, "Command line switch \"-R\" should be followed by a floating point number.\n" );
39588                 return 0;
39589             }
39590             pPars->nCoarseLimit = atoi(argv[globalUtilOptind]);
39591             globalUtilOptind++;
39592             if ( pPars->nCoarseLimit < 0 )
39593                 goto usage;
39594             break;
39595         case 'E':
39596             if ( globalUtilOptind >= argc )
39597             {
39598                 Abc_Print( 1, "Command line switch \"-E\" should be followed by a floating point number.\n" );
39599                 return 0;
39600             }
39601             pPars->nAreaTuner = atoi(argv[globalUtilOptind]);
39602             globalUtilOptind++;
39603             if ( pPars->nAreaTuner < 0 )
39604                 goto usage;
39605             break;
39606         case 'D':
39607             if ( globalUtilOptind >= argc )
39608             {
39609                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a floating point number.\n" );
39610                 goto usage;
39611             }
39612             pPars->DelayTarget = atoi(argv[globalUtilOptind]);
39613             globalUtilOptind++;
39614             if ( pPars->DelayTarget <= 0.0 )
39615                 goto usage;
39616             break;
39617         case 'N':
39618             if ( globalUtilOptind >= argc )
39619             {
39620                 Abc_Print( -1, "Command line switch \"-N\" should be followed by a positive integer.\n" );
39621                 goto usage;
39622             }
39623             pPars->nDelayLut1 = atoi(argv[globalUtilOptind]);
39624             globalUtilOptind++;
39625             if ( pPars->nDelayLut1 < 0 )
39626                 goto usage;
39627             break;
39628         case 'M':
39629             if ( globalUtilOptind >= argc )
39630             {
39631                 Abc_Print( -1, "Command line switch \"-M\" should be followed by a positive integer.\n" );
39632                 goto usage;
39633             }
39634             pPars->nDelayLut2 = atoi(argv[globalUtilOptind]);
39635             globalUtilOptind++;
39636             if ( pPars->nDelayLut2 < 0 )
39637                 goto usage;
39638             break;
39639         case 'Q':
39640             if ( globalUtilOptind >= argc )
39641             {
39642                 Abc_Print( -1, "Command line switch \"-Q\" should be followed by a positive integer.\n" );
39643                 goto usage;
39644             }
39645             pPars->nFastEdges = atoi(argv[globalUtilOptind]);
39646             globalUtilOptind++;
39647             if ( pPars->nFastEdges < 0 )
39648                 goto usage;
39649             break;
39650         case 'e':
39651             pPars->fOptEdge ^= 1;
39652             break;
39653         case 'k':
39654             pPars->fCoarsen ^= 1;
39655             break;
39656         case 'm':
39657             pPars->fCutMin ^= 1;
39658             break;
39659         case 'p':
39660             pPars->fPower ^= 1;
39661             break;
39662         case 'g':
39663             pPars->fPureAig ^= 1;
39664             break;
39665         case 't':
39666             pPars->fDoAverage ^= 1;
39667             break;
39668         case 'v':
39669             pPars->fVerbose ^= 1;
39670             break;
39671         case 'w':
39672             pPars->fVeryVerbose ^= 1;
39673             break;
39674         case 'h':
39675         default:
39676             goto usage;
39677         }
39678     }
39679 
39680     if ( pAbc->pGia == NULL )
39681     {
39682         Abc_Print( -1, "Empty GIA network.\n" );
39683         return 1;
39684     }
39685     if ( Gia_ManHasMapping(pAbc->pGia) )
39686     {
39687         Abc_Print( -1, "Current AIG has mapping. Run \"&st\".\n" );
39688         return 1;
39689     }
39690 
39691     pNew = Of_ManPerformMapping( pAbc->pGia, pPars );
39692     if ( pNew == NULL )
39693     {
39694         Abc_Print( -1, "Abc_CommandAbc9Of(): Mapping into LUTs has failed.\n" );
39695         return 1;
39696     }
39697     Abc_FrameUpdateGia( pAbc, pNew );
39698     return 0;
39699 
39700 usage:
39701     if ( pPars->DelayTarget == -1 )
39702         sprintf(Buffer, "best possible" );
39703     else
39704         sprintf(Buffer, "%d", pPars->DelayTarget );
39705     Abc_Print( -2, "usage: &of [-KCFARLEDNMQ num] [-kmpgtvwh]\n" );
39706     Abc_Print( -2, "\t           performs technology mapping of the network\n" );
39707     Abc_Print( -2, "\t-K num   : LUT size for the mapping (2 <= K <= %d) [default = %d]\n", pPars->nLutSizeMax, pPars->nLutSize );
39708     Abc_Print( -2, "\t-C num   : the max number of priority cuts (1 <= C <= %d) [default = %d]\n", pPars->nCutNumMax, pPars->nCutNum );
39709     Abc_Print( -2, "\t-F num   : the number of area flow rounds [default = %d]\n", pPars->nRounds );
39710     Abc_Print( -2, "\t-A num   : the number of exact area rounds [default = %d]\n", pPars->nRoundsEla );
39711     Abc_Print( -2, "\t-R num   : the delay relaxation ratio (num >= 0) [default = %d]\n", pPars->nRelaxRatio );
39712     Abc_Print( -2, "\t-L num   : the fanout limit for coarsening XOR/MUX (num >= 2) [default = %d]\n", pPars->nCoarseLimit );
39713     Abc_Print( -2, "\t-E num   : the area/edge tradeoff parameter (0 <= num <= 100) [default = %d]\n", pPars->nAreaTuner );
39714     Abc_Print( -2, "\t-D num   : sets the delay constraint for the mapping [default = %s]\n", Buffer );
39715     Abc_Print( -2, "\t-N num   : delay of the first LUT [default = %d]\n", pPars->nDelayLut1 );
39716     Abc_Print( -2, "\t-M num   : delay of the second LUT [default = %d]\n", pPars->nDelayLut2 );
39717     Abc_Print( -2, "\t-Q num   : the number of fast non-routable edges [default = %d]\n", pPars->nFastEdges );
39718     Abc_Print( -2, "\t-e       : toggles edge vs node minimization [default = %s]\n", pPars->fOptEdge? "yes": "no" );
39719     Abc_Print( -2, "\t-k       : toggles coarsening the subject graph [default = %s]\n", pPars->fCoarsen? "yes": "no" );
39720     Abc_Print( -2, "\t-m       : toggles cut minimization [default = %s]\n", pPars->fCutMin? "yes": "no" );
39721     Abc_Print( -2, "\t-p       : toggles power-aware cut selection heuristics [default = %s]\n", pPars->fPower? "yes": "no" );
39722     Abc_Print( -2, "\t-g       : toggles generating AIG without mapping [default = %s]\n", pPars->fPureAig? "yes": "no" );
39723     Abc_Print( -2, "\t-t       : toggles optimizing average rather than maximum level [default = %s]\n", pPars->fDoAverage? "yes": "no" );
39724     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
39725     Abc_Print( -2, "\t-w       : toggles very verbose output [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
39726     Abc_Print( -2, "\t-h       : prints the command usage\n");
39727     return 1;
39728 }
39729 
39730 /**Function*************************************************************
39731 
39732   Synopsis    []
39733 
39734   Description []
39735 
39736   SideEffects []
39737 
39738   SeeAlso     []
39739 
39740 ***********************************************************************/
Abc_CommandAbc9Pack(Abc_Frame_t * pAbc,int argc,char ** argv)39741 int Abc_CommandAbc9Pack( Abc_Frame_t * pAbc, int argc, char ** argv )
39742 {
39743     extern void Gia_ManLutPacking( Gia_Man_t * p, int nBlock, int DelayRoute, int DelayDir, int fVerbose );
39744     int c, nBlock = 2, DelayRoute = 10, DelayDir = 2, fVerbose = 0;
39745     Extra_UtilGetoptReset();
39746     while ( ( c = Extra_UtilGetopt( argc, argv, "NRDvh" ) ) != EOF )
39747     {
39748         switch ( c )
39749         {
39750         case 'N':
39751             if ( globalUtilOptind >= argc )
39752             {
39753                 Abc_Print( -1, "Command line switch \"-N\" should be followed by a positive integer.\n" );
39754                 goto usage;
39755             }
39756             nBlock = atoi(argv[globalUtilOptind]);
39757             globalUtilOptind++;
39758             if ( nBlock < 2 )
39759             {
39760                 Abc_Print( -1, "LUT block size (%d) should be more than 1.\n", nBlock );
39761                 goto usage;
39762             }
39763             break;
39764         case 'R':
39765             if ( globalUtilOptind >= argc )
39766             {
39767                 Abc_Print( -1, "Command line switch \"-N\" should be followed by a positive integer.\n" );
39768                 goto usage;
39769             }
39770             DelayRoute = atoi(argv[globalUtilOptind]);
39771             globalUtilOptind++;
39772             if ( DelayRoute <= 0 )
39773             {
39774                 Abc_Print( -1, "Rounting delay (%d) should be more than 0.\n", DelayRoute);
39775                 goto usage;
39776             }
39777             break;
39778         case 'D':
39779             if ( globalUtilOptind >= argc )
39780             {
39781                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a positive integer.\n" );
39782                 goto usage;
39783             }
39784             DelayDir = atoi(argv[globalUtilOptind]);
39785             globalUtilOptind++;
39786             if ( DelayDir <= 0 )
39787             {
39788                 Abc_Print( -1, "Direct delay (%d) should be more than 0.\n", DelayRoute);
39789                 goto usage;
39790             }
39791             break;
39792         case 'v':
39793             fVerbose ^= 1;
39794             break;
39795         case 'h':
39796         default:
39797             goto usage;
39798         }
39799     }
39800 
39801     if ( pAbc->pGia == NULL )
39802     {
39803         Abc_Print( -1, "Empty GIA network.\n" );
39804         return 1;
39805     }
39806     if ( !Gia_ManHasMapping(pAbc->pGia) )
39807     {
39808         Abc_Print( -1, "Current AIG has no mapping. Run \"&if\".\n" );
39809         return 1;
39810     }
39811     if ( Gia_ManLutSizeMax(pAbc->pGia) > 6 )
39812         Abc_Print( 0, "Current AIG has mapping into %d-LUTs.\n", Gia_ManLutSizeMax(pAbc->pGia) );
39813     else
39814         Gia_ManLutPacking( pAbc->pGia, nBlock, DelayRoute, DelayDir, fVerbose );
39815     return 0;
39816 
39817 usage:
39818     Abc_Print( -2, "usage: &pack [-NRD num] [-vh]\n" );
39819     Abc_Print( -2, "\t           performs packing for the LUT mapped network\n" );
39820     Abc_Print( -2, "\t-N num   : the number of LUTs in the block [default = %d]\n", nBlock );
39821     Abc_Print( -2, "\t-R num   : the routable delay of a LUT [default = %d]\n", DelayRoute );
39822     Abc_Print( -2, "\t-D num   : the direct (non-routable) delay of a LUT [default = %d]\n", DelayDir );
39823     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n", fVerbose? "yes": "no" );
39824     Abc_Print( -2, "\t-h       : prints the command usage\n");
39825     return 1;
39826 }
39827 
39828 /**Function*************************************************************
39829 
39830   Synopsis    []
39831 
39832   Description []
39833 
39834   SideEffects []
39835 
39836   SeeAlso     []
39837 
39838 ***********************************************************************/
Abc_CommandAbc9Edge(Abc_Frame_t * pAbc,int argc,char ** argv)39839 int Abc_CommandAbc9Edge( Abc_Frame_t * pAbc, int argc, char ** argv )
39840 {
39841     extern int Edg_ManAssignEdgeNew( Gia_Man_t * p, int nEdges, int fVerbose );
39842     extern void Seg_ManComputeDelay( Gia_Man_t * pGia, int Delay, int nFanouts, int fTwo, int fVerbose );
39843     extern void Sle_ManExplore( Gia_Man_t * pGia, int nBTLimit, int DelayInit, int fDynamic, int fTwoEdges, int fVerbose );
39844 
39845     int c, nBTLimit = 0, DelayMax = 0, nFanouts = 0, nEdges = 1, fReverse = 0, fUsePack = 0, fUseOld = 0, fMapping = 0, fDynamic = 1, fVerbose = 0;
39846     Extra_UtilGetoptReset();
39847     while ( ( c = Extra_UtilGetopt( argc, argv, "CDFErpomdvh" ) ) != EOF )
39848     {
39849         switch ( c )
39850         {
39851             case 'C':
39852                 if ( globalUtilOptind >= argc )
39853                 {
39854                     Abc_Print( -1, "Command line switch \"-C\" should be followed by a positive integer.\n" );
39855                     goto usage;
39856                 }
39857                 nBTLimit = atoi(argv[globalUtilOptind]);
39858                 globalUtilOptind++;
39859                 break;
39860             case 'D':
39861                 if ( globalUtilOptind >= argc )
39862                 {
39863                     Abc_Print( -1, "Command line switch \"-D\" should be followed by a positive integer.\n" );
39864                     goto usage;
39865                 }
39866                 DelayMax = atoi(argv[globalUtilOptind]);
39867                 globalUtilOptind++;
39868                 break;
39869             case 'F':
39870                 if ( globalUtilOptind >= argc )
39871                 {
39872                     Abc_Print( -1, "Command line switch \"-F\" should be followed by a positive integer.\n" );
39873                     goto usage;
39874                 }
39875                 nFanouts = atoi(argv[globalUtilOptind]);
39876                 globalUtilOptind++;
39877                 break;
39878             case 'E':
39879                 if ( globalUtilOptind >= argc )
39880                 {
39881                     Abc_Print( -1, "Command line switch \"-E\" should be followed by a positive integer.\n" );
39882                     goto usage;
39883                 }
39884                 nEdges = atoi(argv[globalUtilOptind]);
39885                 globalUtilOptind++;
39886                 if ( nEdges != 1 && nEdges != 2 )
39887                 {
39888                     Abc_Print( -1, "Edge limit (%d) should be 1 or 2.\n", nEdges );
39889                     goto usage;
39890                 }
39891                 break;
39892             case 'r':
39893                 fReverse ^= 1;
39894                 break;
39895             case 'p':
39896                 fUsePack ^= 1;
39897                 break;
39898             case 'o':
39899                 fUseOld ^= 1;
39900                 break;
39901             case 'm':
39902                 fMapping ^= 1;
39903                 break;
39904             case 'd':
39905                 fDynamic ^= 1;
39906                 break;
39907             case 'v':
39908                 fVerbose ^= 1;
39909                 break;
39910             case 'h':
39911             default:
39912             goto usage;
39913         }
39914     }
39915     if ( pAbc->pGia == NULL )
39916     {
39917         Abc_Print( -1, "Empty GIA network.\n" );
39918         return 1;
39919     }
39920     if ( fMapping )
39921     {
39922         Sle_ManExplore( pAbc->pGia, nBTLimit, DelayMax, fDynamic, nEdges==2, fVerbose );
39923         return 0;
39924     }
39925     if ( !Gia_ManHasMapping(pAbc->pGia) )
39926     {
39927         Abc_Print( -1, "Current AIG has no mapping. Run \"&if\".\n" );
39928         return 1;
39929     }
39930     if ( Gia_ManLutSizeMax(pAbc->pGia) > 6 )
39931     {
39932         Abc_Print( 0, "Current AIG has mapping into %d-LUTs.\n", Gia_ManLutSizeMax(pAbc->pGia) );
39933         return 0;
39934     }
39935     if ( fUsePack )
39936     {
39937         if ( pAbc->pGia->vPacking == NULL )
39938         {
39939             Abc_Print( -1, "Packing information is not present.\n" );
39940             return 0;
39941         }
39942         Gia_ManConvertPackingToEdges( pAbc->pGia );
39943         return 0;
39944     }
39945     if ( !fUseOld )
39946     {
39947         //Edg_ManAssignEdgeNew( pAbc->pGia, nEdges, fVerbose );
39948         Seg_ManComputeDelay( pAbc->pGia, DelayMax, nFanouts, nEdges==2, fVerbose );
39949         return 0;
39950     }
39951     if ( pAbc->pGia->pManTime && fReverse )
39952     {
39953         Abc_Print( 0, "Reverse computation does not work when boxes are present.\n" );
39954         return 0;
39955     }
39956     if ( fReverse )
39957         DelayMax = Gia_ManComputeEdgeDelay2( pAbc->pGia );
39958     else
39959         DelayMax = Gia_ManComputeEdgeDelay( pAbc->pGia, nEdges == 2 );
39960     //printf( "The number of edges = %d.  Delay = %d.\n", Gia_ManEvalEdgeCount(pAbc->pGia), DelayMax );
39961     return 0;
39962 
39963 usage:
39964     Abc_Print( -2, "usage: &edge [-CDFE num] [-rpomdvh]\n" );
39965     Abc_Print( -2, "\t           find edge assignment of the LUT-mapped network\n" );
39966     Abc_Print( -2, "\t-C num   : the SAT solver conflict limit (0 = unused) [default = %d]\n", nBTLimit );
39967     Abc_Print( -2, "\t-D num   : the upper bound on delay [default = %d]\n", DelayMax );
39968     Abc_Print( -2, "\t-F num   : skip using edge if fanout higher than this [default = %d]\n", nFanouts );
39969     Abc_Print( -2, "\t-E num   : the limit on the number of edges (1 <= num <= 2) [default = %d]\n", nEdges );
39970     Abc_Print( -2, "\t-r       : toggles using reverse order [default = %s]\n", fReverse? "yes": "no" );
39971     Abc_Print( -2, "\t-p       : toggles deriving edges from packing [default = %s]\n", fUsePack? "yes": "no" );
39972     Abc_Print( -2, "\t-o       : toggles using old algorithm [default = %s]\n", fUseOld? "yes": "no" );
39973     Abc_Print( -2, "\t-m       : toggles combining edge assignment with mapping [default = %s]\n", fMapping? "yes": "no" );
39974     Abc_Print( -2, "\t-d       : toggles dynamic addition of clauses [default = %s]\n", fDynamic? "yes": "no" );
39975     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n", fVerbose? "yes": "no" );
39976     Abc_Print( -2, "\t-h       : prints the command usage\n");
39977     return 1;
39978 }
39979 
39980 /**Function*************************************************************
39981 
39982   Synopsis    []
39983 
39984   Description []
39985 
39986   SideEffects []
39987 
39988   SeeAlso     []
39989 
39990 ***********************************************************************/
Abc_CommandAbc9SatLut(Abc_Frame_t * pAbc,int argc,char ** argv)39991 int Abc_CommandAbc9SatLut( Abc_Frame_t * pAbc, int argc, char ** argv )
39992 {
39993     extern void Gia_ManLutSat( Gia_Man_t * p, int LutSize, int nNumber, int nImproves, int nBTLimit, int DelayMax, int nEdges, int fDelay, int fReverse, int fVerbose, int fVeryVerbose );
39994     int c, LutSize = 0, nNumber = 32, nImproves = 0, nBTLimit = 100, DelayMax = 0, nEdges = 0;
39995     int fDelay = 0, fReverse = 0, fVeryVerbose = 0, fVerbose = 0;
39996     Extra_UtilGetoptReset();
39997     while ( ( c = Extra_UtilGetopt( argc, argv, "NICDQdrwvh" ) ) != EOF )
39998     {
39999         switch ( c )
40000         {
40001         case 'N':
40002             if ( globalUtilOptind >= argc )
40003             {
40004                 Abc_Print( -1, "Command line switch \"-N\" should be followed by a positive integer.\n" );
40005                 goto usage;
40006             }
40007             nNumber = atoi(argv[globalUtilOptind]);
40008             if ( nNumber > 128 )
40009             {
40010                 Abc_Print( -1, "The number of AIG nodes should not exceed 128.\n" );
40011                 goto usage;
40012             }
40013             globalUtilOptind++;
40014             break;
40015         case 'I':
40016             if ( globalUtilOptind >= argc )
40017             {
40018                 Abc_Print( -1, "Command line switch \"-I\" should be followed by a positive integer.\n" );
40019                 goto usage;
40020             }
40021             nImproves = atoi(argv[globalUtilOptind]);
40022             globalUtilOptind++;
40023             break;
40024         case 'C':
40025             if ( globalUtilOptind >= argc )
40026             {
40027                 Abc_Print( -1, "Command line switch \"-C\" should be followed by a positive integer.\n" );
40028                 goto usage;
40029             }
40030             nBTLimit = atoi(argv[globalUtilOptind]);
40031             globalUtilOptind++;
40032             break;
40033         case 'D':
40034             if ( globalUtilOptind >= argc )
40035             {
40036                 Abc_Print( -1, "Command line switch \"-D\" should be followed by a positive integer.\n" );
40037                 goto usage;
40038             }
40039             DelayMax = atoi(argv[globalUtilOptind]);
40040             globalUtilOptind++;
40041             break;
40042         case 'Q':
40043             if ( globalUtilOptind >= argc )
40044             {
40045                 Abc_Print( -1, "Command line switch \"-Q\" should be followed by a positive integer.\n" );
40046                 goto usage;
40047             }
40048             nEdges = atoi(argv[globalUtilOptind]);
40049             globalUtilOptind++;
40050             break;
40051         case 'd':
40052             fDelay ^= 1;
40053             break;
40054         case 'r':
40055             fReverse ^= 1;
40056             break;
40057         case 'w':
40058             fVeryVerbose ^= 1;
40059             break;
40060         case 'v':
40061             fVerbose ^= 1;
40062             break;
40063         case 'h':
40064         default:
40065             goto usage;
40066         }
40067     }
40068 
40069     if ( pAbc->pGia == NULL )
40070     {
40071         Abc_Print( -1, "Empty GIA network.\n" );
40072         return 1;
40073     }
40074     if ( !Gia_ManHasMapping(pAbc->pGia) )
40075     {
40076         Abc_Print( -1, "Current AIG has no mapping. Run \"&if\".\n" );
40077         return 1;
40078     }
40079     LutSize = Gia_ManLutSizeMax(pAbc->pGia);
40080     if ( LutSize > 6 )
40081         Abc_Print( 0, "Current AIG is mapped into %d-LUTs (only 6-LUT mapping is currently supported).\n", Gia_ManLutSizeMax(pAbc->pGia) );
40082     else
40083         Gia_ManLutSat( pAbc->pGia, LutSize, nNumber, nImproves, nBTLimit, DelayMax, nEdges, fDelay, fReverse, fVerbose, fVeryVerbose );
40084     return 0;
40085 
40086 usage:
40087     Abc_Print( -2, "usage: &satlut [-NICDQ num] [-drwvh]\n" );
40088     Abc_Print( -2, "\t           performs SAT-based remapping of the LUT-mapped network\n" );
40089     Abc_Print( -2, "\t-N num   : the limit on AIG nodes in the window (num <= 128) [default = %d]\n", nNumber );
40090     Abc_Print( -2, "\t-I num   : the limit on the number of improved windows [default = %d]\n", nImproves );
40091     Abc_Print( -2, "\t-C num   : the limit on the number of conflicts [default = %d]\n", nBTLimit );
40092     Abc_Print( -2, "\t-D num   : the user-specified required times at the outputs [default = %d]\n", DelayMax );
40093     Abc_Print( -2, "\t-Q num   : the maximum number of edges [default = %d]\n", nEdges );
40094     Abc_Print( -2, "\t-d       : toggles delay optimization [default = %s]\n", fDelay? "yes": "no" );
40095     Abc_Print( -2, "\t-r       : toggles using reverse search [default = %s]\n", fReverse? "yes": "no" );
40096     Abc_Print( -2, "\t-v       : toggles verbose output [default = %s]\n", fVerbose? "yes": "no" );
40097     Abc_Print( -2, "\t-h       : prints the command usage\n");
40098     return 1;
40099 }
40100 
40101 /**Function*************************************************************
40102 
40103   Synopsis    []
40104 
40105   Description []
40106 
40107   SideEffects []
40108 
40109   SeeAlso     []
40110 
40111 ***********************************************************************/
Abc_CommandAbc9Unmap(Abc_Frame_t * pAbc,int argc,char ** argv)40112 int Abc_CommandAbc9Unmap( Abc_Frame_t * pAbc, int argc, char ** argv )
40113 {
40114     extern void Gia_ManTestStruct( Gia_Man_t * p );
40115     int c, fVerbose = 0;
40116     Extra_UtilGetoptReset();
40117     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
40118     {
40119         switch ( c )
40120         {
40121         case 'v':
40122             fVerbose ^= 1;
40123             break;
40124         case 'h':
40125             goto usage;
40126         default:
40127             goto usage;
40128         }
40129     }
40130     if ( pAbc->pGia == NULL )
40131     {
40132         Abc_Print( -1, "Abc_CommandAbc9Struct(): There is no AIG to map.\n" );
40133         return 1;
40134     }
40135     Vec_IntFreeP( &pAbc->pGia->vMapping );
40136     Vec_IntFreeP( &pAbc->pGia->vPacking );
40137     Vec_IntFreeP( &pAbc->pGia->vCellMapping );
40138     Vec_IntFreeP( &pAbc->pGia->vEdge1 );
40139     Vec_IntFreeP( &pAbc->pGia->vEdge2 );
40140     return 0;
40141 
40142 usage:
40143     Abc_Print( -2, "usage: &unmap [-vh]\n" );
40144     Abc_Print( -2, "\t           removes mapping from the current network\n" );
40145     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n", fVerbose? "yes": "no" );
40146     Abc_Print( -2, "\t-h       : print the command usage\n");
40147     return 1;
40148 }
40149 
40150 /**Function*************************************************************
40151 
40152   Synopsis    []
40153 
40154   Description []
40155 
40156   SideEffects []
40157 
40158   SeeAlso     []
40159 
40160 ***********************************************************************/
Abc_CommandAbc9Struct(Abc_Frame_t * pAbc,int argc,char ** argv)40161 int Abc_CommandAbc9Struct( Abc_Frame_t * pAbc, int argc, char ** argv )
40162 {
40163     extern void Gia_ManTestStruct( Gia_Man_t * p );
40164     int c, fVerbose;
40165     // set defaults
40166     fVerbose   = 0;
40167     Extra_UtilGetoptReset();
40168     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
40169     {
40170         switch ( c )
40171         {
40172         case 'v':
40173             fVerbose ^= 1;
40174             break;
40175         case 'h':
40176             goto usage;
40177         default:
40178             goto usage;
40179         }
40180     }
40181     if ( pAbc->pGia == NULL )
40182     {
40183         Abc_Print( -1, "Abc_CommandAbc9Struct(): There is no AIG to map.\n" );
40184         return 1;
40185     }
40186     if ( !Gia_ManHasMapping(pAbc->pGia) )
40187     {
40188         Abc_Print( -1, "Abc_CommandAbc9Struct(): Mapping of the AIG is not defined.\n" );
40189         return 1;
40190     }
40191     if ( Gia_ManLutSizeMax(pAbc->pGia) >= 8 )
40192     {
40193         Abc_Print( -1, "Abc_CommandAbc9Struct(): Can only handle nodes with less than 8 inputs.\n" );
40194         return 1;
40195     }
40196     Gia_ManTestStruct( pAbc->pGia );
40197     return 0;
40198 
40199 usage:
40200     Abc_Print( -2, "usage: &struct [-vh]\n" );
40201     Abc_Print( -2, "\t           checks decomposition structures of the current mapping\n" );
40202     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n", fVerbose? "yes": "no" );
40203     Abc_Print( -2, "\t-h       : print the command usage\n");
40204     return 1;
40205 }
40206 
40207 
40208 /**Function*************************************************************
40209 
40210   Synopsis    []
40211 
40212   Description []
40213 
40214   SideEffects []
40215 
40216   SeeAlso     []
40217 
40218 ***********************************************************************/
Abc_CommandAbc9Trace(Abc_Frame_t * pAbc,int argc,char ** argv)40219 int Abc_CommandAbc9Trace( Abc_Frame_t * pAbc, int argc, char ** argv )
40220 {
40221     int c;
40222     int fUseLutLib;
40223     int fVerbose;
40224     // set defaults
40225     fUseLutLib = 0;
40226     fVerbose   = 0;
40227     Extra_UtilGetoptReset();
40228     while ( ( c = Extra_UtilGetopt( argc, argv, "lvh" ) ) != EOF )
40229     {
40230         switch ( c )
40231         {
40232         case 'l':
40233             fUseLutLib ^= 1;
40234             break;
40235         case 'v':
40236             fVerbose ^= 1;
40237             break;
40238         case 'h':
40239             goto usage;
40240         default:
40241             goto usage;
40242         }
40243     }
40244     if ( pAbc->pGia == NULL )
40245     {
40246         Abc_Print( -1, "Abc_CommandAbc9Speedup(): There is no AIG to map.\n" );
40247         return 1;
40248     }
40249     if ( !Gia_ManHasMapping(pAbc->pGia) )
40250     {
40251         Abc_Print( -1, "Abc_CommandAbc9Speedup(): Mapping of the AIG is not defined.\n" );
40252         return 1;
40253     }
40254     pAbc->pGia->pLutLib = fUseLutLib ? pAbc->pLibLut : NULL;
40255     Gia_ManDelayTraceLutPrint( pAbc->pGia, fVerbose );
40256     return 0;
40257 
40258 usage:
40259     Abc_Print( -2, "usage: &trace [-lvh]\n" );
40260     Abc_Print( -2, "\t           performs delay trace of LUT-mapped network\n" );
40261     Abc_Print( -2, "\t-l       : toggle using unit- or LUT-library-delay model [default = %s]\n", fUseLutLib? "lib": "unit" );
40262     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n", fVerbose? "yes": "no" );
40263     Abc_Print( -2, "\t-h       : print the command usage\n");
40264     return 1;
40265 }
40266 
40267 /**Function*************************************************************
40268 
40269   Synopsis    []
40270 
40271   Description []
40272 
40273   SideEffects []
40274 
40275   SeeAlso     []
40276 
40277 ***********************************************************************/
Abc_CommandAbc9Speedup(Abc_Frame_t * pAbc,int argc,char ** argv)40278 int Abc_CommandAbc9Speedup( Abc_Frame_t * pAbc, int argc, char ** argv )
40279 {
40280     Gia_Man_t * pTemp;
40281     int fUseLutLib;
40282     int Percentage;
40283     int Degree;
40284     int fVerbose;
40285     int c, fVeryVerbose;
40286 
40287     // set defaults
40288     fUseLutLib   = 0;
40289     Percentage   = 5;
40290     Degree       = 2;
40291     fVerbose     = 0;
40292     fVeryVerbose = 0;
40293     Extra_UtilGetoptReset();
40294     while ( ( c = Extra_UtilGetopt( argc, argv, "PNlvwh" ) ) != EOF )
40295     {
40296         switch ( c )
40297         {
40298         case 'P':
40299             if ( globalUtilOptind >= argc )
40300             {
40301                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
40302                 goto usage;
40303             }
40304             Percentage = atoi(argv[globalUtilOptind]);
40305             globalUtilOptind++;
40306             if ( Percentage < 1 || Percentage > 100 )
40307                 goto usage;
40308             break;
40309         case 'N':
40310             if ( globalUtilOptind >= argc )
40311             {
40312                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
40313                 goto usage;
40314             }
40315             Degree = atoi(argv[globalUtilOptind]);
40316             globalUtilOptind++;
40317             if ( Degree < 1 || Degree > 5 )
40318                 goto usage;
40319             break;
40320         case 'l':
40321             fUseLutLib ^= 1;
40322             break;
40323         case 'v':
40324             fVerbose ^= 1;
40325             break;
40326         case 'w':
40327             fVeryVerbose ^= 1;
40328             break;
40329         case 'h':
40330             goto usage;
40331         default:
40332             goto usage;
40333         }
40334     }
40335     if ( pAbc->pGia == NULL )
40336     {
40337         Abc_Print( -1, "Abc_CommandAbc9Speedup(): There is no AIG to map.\n" );
40338         return 1;
40339     }
40340     if ( !Gia_ManHasMapping(pAbc->pGia) )
40341     {
40342         Abc_Print( -1, "Abc_CommandAbc9Speedup(): Mapping of the AIG is not defined.\n" );
40343         return 1;
40344     }
40345     pAbc->pGia->pLutLib = fUseLutLib ? pAbc->pLibLut : NULL;
40346     pTemp = Gia_ManSpeedup( pAbc->pGia, Percentage, Degree, fVerbose, fVeryVerbose );
40347     Abc_FrameUpdateGia( pAbc, pTemp );
40348     return 0;
40349 
40350 usage:
40351     Abc_Print( -2, "usage: &speedup [-P num] [-N num] [-lvwh]\n" );
40352     Abc_Print( -2, "\t           transforms LUT-mapped network into an AIG with choices;\n" );
40353     Abc_Print( -2, "\t           the choices are added to speedup the next round of mapping\n" );
40354     Abc_Print( -2, "\t-P <num> : delay delta defining critical path for library model [default = %d%%]\n", Percentage );
40355     Abc_Print( -2, "\t-N <num> : the max critical path degree for resynthesis (0 < num < 6) [default = %d]\n", Degree );
40356     Abc_Print( -2, "\t-l       : toggle using unit- or LUT-library-delay model [default = %s]\n", fUseLutLib? "lib" : "unit" );
40357     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n", fVerbose? "yes": "no" );
40358     Abc_Print( -2, "\t-w       : toggle printing detailed stats for each node [default = %s]\n", fVeryVerbose? "yes": "no" );
40359     Abc_Print( -2, "\t-h       : print the command usage\n");
40360     return 1;
40361 }
40362 
40363 /**Function*************************************************************
40364 
40365   Synopsis    []
40366 
40367   Description []
40368 
40369   SideEffects []
40370 
40371   SeeAlso     []
40372 
40373 ***********************************************************************/
Abc_CommandAbc9Era(Abc_Frame_t * pAbc,int argc,char ** argv)40374 int Abc_CommandAbc9Era( Abc_Frame_t * pAbc, int argc, char ** argv )
40375 {
40376 //    Gia_Man_t * pTemp = NULL;
40377     int c, fVerbose = 0;
40378     int fUseCubes = 1;
40379     int fDumpFile = 0;
40380     int fMiter = 0;
40381     int nStatesMax = 1000000000;
40382     extern int Gia_ManCollectReachable( Gia_Man_t * pAig, int nStatesMax, int fMiter, int fDumpFile, int fVerbose );
40383     extern int Gia_ManArePerform( Gia_Man_t * pAig, int nStatesMax, int fMiter, int fVerbose );
40384 
40385     Extra_UtilGetoptReset();
40386     while ( ( c = Extra_UtilGetopt( argc, argv, "Smcdvh" ) ) != EOF )
40387     {
40388         switch ( c )
40389         {
40390         case 'S':
40391             if ( globalUtilOptind >= argc )
40392             {
40393                 Abc_Print( -1, "Command line switch \"-S\" should be followed by a positive integer.\n" );
40394                 goto usage;
40395             }
40396             nStatesMax = atoi(argv[globalUtilOptind]);
40397             globalUtilOptind++;
40398             if ( nStatesMax < 0 )
40399                 goto usage;
40400             break;
40401         case 'm':
40402             fMiter ^= 1;
40403             break;
40404         case 'c':
40405             fUseCubes ^= 1;
40406             break;
40407         case 'd':
40408             fDumpFile ^= 1;
40409             break;
40410         case 'v':
40411             fVerbose ^= 1;
40412             break;
40413         case 'h':
40414             goto usage;
40415         default:
40416             goto usage;
40417         }
40418     }
40419     if ( pAbc->pGia == NULL )
40420     {
40421         Abc_Print( -1, "Abc_CommandAbc9Era(): There is no AIG.\n" );
40422         return 1;
40423     }
40424     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
40425     {
40426         Abc_Print( -1, "Abc_CommandAbc9Era(): The network is combinational.\n" );
40427         return 1;
40428     }
40429     if ( !fUseCubes && Gia_ManPiNum(pAbc->pGia) > 12 )
40430     {
40431         Abc_Print( -1, "Abc_CommandAbc9Era(): The number of PIs (%d) should be no more than 12 when cubes are not used.\n", Gia_ManPiNum(pAbc->pGia) );
40432         return 1;
40433     }
40434     if ( fUseCubes && !fDumpFile )
40435         pAbc->Status = Gia_ManArePerform( pAbc->pGia, nStatesMax, fMiter, fVerbose );
40436     else
40437         pAbc->Status = Gia_ManCollectReachable( pAbc->pGia, nStatesMax, fMiter, fDumpFile, fVerbose );
40438     Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexSeq );
40439     return 0;
40440 
40441 usage:
40442     Abc_Print( -2, "usage: &era [-S num] [-mcdvh]\n" );
40443     Abc_Print( -2, "\t          explicit reachability analysis for small sequential AIGs\n" );
40444     Abc_Print( -2, "\t-S num  : the max number of states (num > 0) [default = %d]\n", nStatesMax );
40445     Abc_Print( -2, "\t-m      : stop when the miter output is 1 [default = %s]\n", fMiter? "yes": "no" );
40446     Abc_Print( -2, "\t-c      : use state cubes instead of state minterms [default = %s]\n", fUseCubes? "yes": "no" );
40447     Abc_Print( -2, "\t-d      : toggle dumping STG into a file [default = %s]\n", fDumpFile? "yes": "no" );
40448     Abc_Print( -2, "\t-v      : print verbose information [default = %s]\n", fVerbose? "yes": "no" );
40449     Abc_Print( -2, "\t-h      : print the command usage\n");
40450     return 1;
40451 }
40452 
40453 /**Function*************************************************************
40454 
40455   Synopsis    []
40456 
40457   Description []
40458 
40459   SideEffects []
40460 
40461   SeeAlso     []
40462 
40463 ***********************************************************************/
Abc_CommandAbc9Dch(Abc_Frame_t * pAbc,int argc,char ** argv)40464 int Abc_CommandAbc9Dch( Abc_Frame_t * pAbc, int argc, char ** argv )
40465 {
40466     extern Gia_Man_t * Gia_ManEquivReduce2( Gia_Man_t * p );
40467     Gia_Man_t * pTemp;
40468     Dch_Pars_t Pars, * pPars = &Pars;
40469     int c, fMinLevel = 0, fEquiv = 0;
40470     // set defaults
40471     Dch_ManSetDefaultParams( pPars );
40472     Extra_UtilGetoptReset();
40473     while ( ( c = Extra_UtilGetopt( argc, argv, "WCSsptfremvh" ) ) != EOF )
40474     {
40475         switch ( c )
40476         {
40477         case 'W':
40478             if ( globalUtilOptind >= argc )
40479             {
40480                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
40481                 goto usage;
40482             }
40483             pPars->nWords = atoi(argv[globalUtilOptind]);
40484             globalUtilOptind++;
40485             if ( pPars->nWords < 0 )
40486                 goto usage;
40487             break;
40488         case 'C':
40489             if ( globalUtilOptind >= argc )
40490             {
40491                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
40492                 goto usage;
40493             }
40494             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
40495             globalUtilOptind++;
40496             if ( pPars->nBTLimit < 0 )
40497                 goto usage;
40498             break;
40499         case 'S':
40500             if ( globalUtilOptind >= argc )
40501             {
40502                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
40503                 goto usage;
40504             }
40505             pPars->nSatVarMax = atoi(argv[globalUtilOptind]);
40506             globalUtilOptind++;
40507             if ( pPars->nSatVarMax < 0 )
40508                 goto usage;
40509             break;
40510         case 's':
40511             pPars->fSynthesis ^= 1;
40512             break;
40513         case 'p':
40514             pPars->fPower ^= 1;
40515             break;
40516         case 't':
40517             pPars->fSimulateTfo ^= 1;
40518             break;
40519         case 'f':
40520             pPars->fLightSynth ^= 1;
40521             break;
40522         case 'r':
40523             pPars->fSkipRedSupp ^= 1;
40524             break;
40525         case 'e':
40526             fEquiv ^= 1;
40527             break;
40528         case 'm':
40529             fMinLevel ^= 1;
40530             break;
40531         case 'v':
40532             pPars->fVerbose ^= 1;
40533             break;
40534         case 'h':
40535             goto usage;
40536         default:
40537             goto usage;
40538         }
40539     }
40540     if ( pAbc->pGia == NULL )
40541     {
40542         Abc_Print( -1, "Abc_CommandAbc9Dch(): There is no AIG.\n" );
40543         return 1;
40544     }
40545     if ( Gia_ManBufNum(pAbc->pGia) )
40546     {
40547         Abc_Print( -1, "Abc_CommandAbc9Dch(): This command does not work with barrier buffers.\n" );
40548         return 1;
40549     }
40550     if ( fEquiv )
40551     {
40552         Aig_Man_t * pNew = Gia_ManToAigSimple( pAbc->pGia );
40553         assert( Gia_ManObjNum(pAbc->pGia) == Aig_ManObjNum(pNew) );
40554         Dch_ComputeEquivalences( pNew, (Dch_Pars_t *)pPars );
40555         Gia_ManReprFromAigRepr( pNew, pAbc->pGia );
40556         Aig_ManStop( pNew );
40557         pTemp = Gia_ManEquivReduce( pAbc->pGia, 1, 0, 0, 0 );
40558     }
40559     else
40560     {
40561         pTemp = Gia_ManPerformDch( pAbc->pGia, pPars );
40562         Abc_FrameUpdateGia( pAbc, pTemp );
40563         if ( fMinLevel )
40564             pTemp = Gia_ManEquivReduce2( pAbc->pGia );
40565     }
40566     Abc_FrameUpdateGia( pAbc, pTemp );
40567     return 0;
40568 
40569 usage:
40570     Abc_Print( -2, "usage: &dch [-WCS num] [-sptfremvh]\n" );
40571     Abc_Print( -2, "\t         computes structural choices using a new approach\n" );
40572     Abc_Print( -2, "\t-W num : the max number of simulation words [default = %d]\n", pPars->nWords );
40573     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", pPars->nBTLimit );
40574     Abc_Print( -2, "\t-S num : the max number of SAT variables [default = %d]\n", pPars->nSatVarMax );
40575     Abc_Print( -2, "\t-s     : toggle synthesizing three snapshots [default = %s]\n", pPars->fSynthesis? "yes": "no" );
40576     Abc_Print( -2, "\t-p     : toggle power-aware rewriting [default = %s]\n", pPars->fPower? "yes": "no" );
40577     Abc_Print( -2, "\t-t     : toggle simulation of the TFO classes [default = %s]\n", pPars->fSimulateTfo? "yes": "no" );
40578     Abc_Print( -2, "\t-f     : toggle using lighter logic synthesis [default = %s]\n", pPars->fLightSynth? "yes": "no" );
40579     Abc_Print( -2, "\t-r     : toggle skipping choices with redundant support [default = %s]\n", pPars->fSkipRedSupp? "yes": "no" );
40580     Abc_Print( -2, "\t-e     : toggle computing and merging equivalences [default = %s]\n", fEquiv? "yes": "no" );
40581     Abc_Print( -2, "\t-m     : toggle minimizing logic level after merging equivalences [default = %s]\n", fMinLevel? "yes": "no" );
40582     Abc_Print( -2, "\t-v     : toggle verbose printout [default = %s]\n", pPars->fVerbose? "yes": "no" );
40583     Abc_Print( -2, "\t-h     : print the command usage\n");
40584     return 1;
40585 }
40586 
40587 
40588 /**Function*************************************************************
40589 
40590   Synopsis    []
40591 
40592   Description []
40593 
40594   SideEffects []
40595 
40596   SeeAlso     []
40597 
40598 ***********************************************************************/
Abc_CommandAbc9Rpm(Abc_Frame_t * pAbc,int argc,char ** argv)40599 int Abc_CommandAbc9Rpm( Abc_Frame_t * pAbc, int argc, char ** argv )
40600 {
40601     extern Gia_Man_t * Gia_ManDupReplaceCut( Gia_Man_t * p );
40602     Gia_Man_t * pTemp;
40603     int c, nCutMax   = 16;
40604     int fUseNaive    =  0;
40605     int fUseOldAlgo  =  0;
40606     int fVerbose     =  0;
40607     int fVeryVerbose =  0;
40608     Extra_UtilGetoptReset();
40609     while ( ( c = Extra_UtilGetopt( argc, argv, "Cnavwh" ) ) != EOF )
40610     {
40611         switch ( c )
40612         {
40613         case 'C':
40614             if ( globalUtilOptind >= argc )
40615             {
40616                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
40617                 goto usage;
40618             }
40619             nCutMax = atoi(argv[globalUtilOptind]);
40620             globalUtilOptind++;
40621             if ( nCutMax < 0 )
40622                 goto usage;
40623             break;
40624         case 'n':
40625             fUseNaive ^= 1;
40626             break;
40627         case 'a':
40628             fUseOldAlgo ^= 1;
40629             break;
40630         case 'v':
40631             fVerbose ^= 1;
40632             break;
40633         case 'w':
40634             fVeryVerbose ^= 1;
40635             break;
40636         case 'h':
40637             goto usage;
40638         default:
40639             goto usage;
40640         }
40641     }
40642     if ( pAbc->pGia == NULL )
40643     {
40644         Abc_Print( -1, "Abc_CommandAbc9Rpm(): There is no AIG.\n" );
40645         return 0;
40646     }
40647     if ( fUseNaive )
40648         pTemp = Gia_ManDupReplaceCut( pAbc->pGia );
40649     else if ( fUseOldAlgo )
40650         pTemp = Abs_RpmPerformOld( pAbc->pGia, fVerbose );
40651     else
40652         pTemp = Abs_RpmPerform( pAbc->pGia, nCutMax, fVerbose, fVeryVerbose );
40653     Abc_FrameUpdateGia( pAbc, pTemp );
40654     return 0;
40655 
40656 usage:
40657     Abc_Print( -2, "usage: &rpm [-C num] [-navwh]\n" );
40658     Abc_Print( -2, "\t         performs structural reparametrization\n" );
40659     Abc_Print( -2, "\t-C num : max cut size for testing range equivalence [default = %d]\n", nCutMax );
40660     Abc_Print( -2, "\t-n     : toggle using naive reparametrization [default = %s]\n", fUseNaive? "yes": "no" );
40661     Abc_Print( -2, "\t-a     : toggle using old algorithm [default = %s]\n", fUseOldAlgo? "yes": "no" );
40662     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
40663     Abc_Print( -2, "\t-w     : toggle printing more verbose information [default = %s]\n", fVeryVerbose? "yes": "no" );
40664     Abc_Print( -2, "\t-h     : print the command usage\n");
40665     return 1;
40666 }
40667 
40668 /**Function*************************************************************
40669 
40670   Synopsis    []
40671 
40672   Description []
40673 
40674   SideEffects []
40675 
40676   SeeAlso     []
40677 
40678 ***********************************************************************/
Abc_CommandAbc9BackReach(Abc_Frame_t * pAbc,int argc,char ** argv)40679 int Abc_CommandAbc9BackReach( Abc_Frame_t * pAbc, int argc, char ** argv )
40680 {
40681     extern Gia_Man_t * Gia_ManCofTest( Gia_Man_t * pGia, int nFrameMax, int nConfMax, int nTimeMax, int fVerbose );
40682 
40683     Gia_Man_t * pTemp = NULL;
40684     int c, fVerbose = 0;
40685     int nFrameMax = 1000000;
40686     int nConfMax  = 1000000;
40687     int nTimeMax  =      10;
40688     Extra_UtilGetoptReset();
40689     while ( ( c = Extra_UtilGetopt( argc, argv, "FCTvh" ) ) != EOF )
40690     {
40691         switch ( c )
40692         {
40693         case 'F':
40694             if ( globalUtilOptind >= argc )
40695             {
40696                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
40697                 goto usage;
40698             }
40699             nFrameMax = atoi(argv[globalUtilOptind]);
40700             globalUtilOptind++;
40701             if ( nFrameMax < 0 )
40702                 goto usage;
40703             break;
40704         case 'C':
40705             if ( globalUtilOptind >= argc )
40706             {
40707                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
40708                 goto usage;
40709             }
40710             nConfMax = atoi(argv[globalUtilOptind]);
40711             globalUtilOptind++;
40712             if ( nConfMax < 0 )
40713                 goto usage;
40714             break;
40715         case 'T':
40716             if ( globalUtilOptind >= argc )
40717             {
40718                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
40719                 goto usage;
40720             }
40721             nTimeMax = atoi(argv[globalUtilOptind]);
40722             globalUtilOptind++;
40723             if ( nTimeMax < 0 )
40724                 goto usage;
40725             break;
40726         case 'v':
40727             fVerbose ^= 1;
40728             break;
40729         case 'h':
40730             goto usage;
40731         default:
40732             goto usage;
40733         }
40734     }
40735     if ( pAbc->pGia == NULL )
40736     {
40737         Abc_Print( -1, "Abc_CommandAbc9BackReach(): There is no AIG.\n" );
40738         return 1;
40739     }
40740     if ( Gia_ManPoNum(pAbc->pGia) != 1 )
40741     {
40742         Abc_Print( -1, "Abc_CommandAbc9BackReach(): The number of POs is different from 1.\n" );
40743         return 1;
40744     }
40745     pTemp = Gia_ManCofTest( pAbc->pGia, nFrameMax, nConfMax, nTimeMax, fVerbose );
40746     Abc_FrameUpdateGia( pAbc, pTemp );
40747     return 0;
40748 
40749 usage:
40750     Abc_Print( -2, "usage: &back_reach [-FCT <num>] [-vh]\n" );
40751     Abc_Print( -2, "\t         performs backward reachability by circuit cofactoring\n" );
40752     Abc_Print( -2, "\t-F num : the limit on the depth of induction [default = %d]\n", nFrameMax );
40753     Abc_Print( -2, "\t-C num : the conflict limit at a node during induction [default = %d]\n", nConfMax );
40754     Abc_Print( -2, "\t-T num : the timeout for property directed reachability [default = %d]\n", nTimeMax );
40755     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
40756     Abc_Print( -2, "\t-h     : print the command usage\n");
40757     return 1;
40758 }
40759 
40760 /**Function*************************************************************
40761 
40762   Synopsis    []
40763 
40764   Description []
40765 
40766   SideEffects []
40767 
40768   SeeAlso     []
40769 
40770 ***********************************************************************/
Abc_CommandAbc9Posplit(Abc_Frame_t * pAbc,int argc,char ** argv)40771 int Abc_CommandAbc9Posplit( Abc_Frame_t * pAbc, int argc, char ** argv )
40772 {
40773     extern Aig_Man_t * Aig_ManSplit( Aig_Man_t * p, int nVars, int fVerbose );
40774     Aig_Man_t * pMan, * pAux;
40775     Gia_Man_t * pTemp = NULL;
40776     int c, nVars = 5, fVerbose = 0;
40777     Extra_UtilGetoptReset();
40778     while ( ( c = Extra_UtilGetopt( argc, argv, "Nvh" ) ) != EOF )
40779     {
40780         switch ( c )
40781         {
40782         case 'N':
40783             if ( globalUtilOptind >= argc )
40784             {
40785                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
40786                 goto usage;
40787             }
40788             nVars = atoi(argv[globalUtilOptind]);
40789             globalUtilOptind++;
40790             if ( nVars < 0 )
40791                 goto usage;
40792             break;
40793         case 'v':
40794             fVerbose ^= 1;
40795             break;
40796         case 'h':
40797             goto usage;
40798         default:
40799             goto usage;
40800         }
40801     }
40802     if ( pAbc->pGia == NULL )
40803     {
40804         Abc_Print( -1, "Abc_CommandAbc9Posplit(): There is no AIG.\n" );
40805         return 1;
40806     }
40807     pMan = Gia_ManToAigSimple( pAbc->pGia );
40808     pMan = Aig_ManSplit( pAux = pMan, nVars, fVerbose );
40809     Aig_ManStop( pAux );
40810     if ( pMan != NULL )
40811     {
40812         pTemp = Gia_ManFromAigSimple( pMan );
40813         Aig_ManStop( pMan );
40814         Abc_FrameUpdateGia( pAbc, pTemp );
40815     }
40816     return 0;
40817 
40818 usage:
40819     Abc_Print( -2, "usage: &posplit [-N num] [-vh]\n" );
40820     Abc_Print( -2, "\t         cofactors the property output w.r.t. a support subset\n" );
40821     Abc_Print( -2, "\t         (the OR of new PO functions is equal to the original property)\n" );
40822     Abc_Print( -2, "\t-N num : the number of random cofactoring variables [default = %d]\n", nVars );
40823     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
40824     Abc_Print( -2, "\t-h     : print the command usage\n");
40825     return 1;
40826 }
40827 
40828 /**Function*************************************************************
40829 
40830   Synopsis    []
40831 
40832   Description []
40833 
40834   SideEffects []
40835 
40836   SeeAlso     []
40837 
40838 ***********************************************************************/
Abc_CommandAbc9Permute(Abc_Frame_t * pAbc,int argc,char ** argv)40839 int Abc_CommandAbc9Permute( Abc_Frame_t * pAbc, int argc, char ** argv )
40840 {
40841     extern Gia_Man_t * Gia_ManDupPiPerm( Gia_Man_t * p );
40842     Gia_Man_t * pTemp;
40843     int c, fVerbose = 0;
40844     Extra_UtilGetoptReset();
40845     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
40846     {
40847         switch ( c )
40848         {
40849         case 'v':
40850             fVerbose ^= 1;
40851             break;
40852         case 'h':
40853             goto usage;
40854         default:
40855             goto usage;
40856         }
40857     }
40858     if ( pAbc->pGia == NULL )
40859     {
40860         Abc_Print( -1, "Abc_CommandAbc9Posplit(): There is no AIG.\n" );
40861         return 1;
40862     }
40863     pTemp = Gia_ManDupPiPerm( pAbc->pGia );
40864     Abc_FrameUpdateGia( pAbc, pTemp );
40865     return 0;
40866 
40867 usage:
40868     Abc_Print( -2, "usage: &permute [-vh]\n" );
40869     Abc_Print( -2, "\t         permutes primary inputs\n" );
40870     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
40871     Abc_Print( -2, "\t-h     : print the command usage\n");
40872     return 1;
40873 }
40874 
40875 #ifdef ABC_USE_CUDD
40876 
40877 /**Function*************************************************************
40878 
40879   Synopsis    []
40880 
40881   Description []
40882 
40883   SideEffects []
40884 
40885   SeeAlso     []
40886 
40887 ***********************************************************************/
Abc_CommandAbc9ReachM(Abc_Frame_t * pAbc,int argc,char ** argv)40888 int Abc_CommandAbc9ReachM( Abc_Frame_t * pAbc, int argc, char ** argv )
40889 {
40890 //    Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
40891     Gia_ParLlb_t Pars, * pPars = &Pars;
40892     char * pLogFileName = NULL;
40893     int c;
40894     extern int Llb_ManModelCheckGia( Gia_Man_t * pGia, Gia_ParLlb_t * pPars );
40895 
40896     // set defaults
40897     Llb_ManSetDefaultParams( pPars );
40898     Extra_UtilGetoptReset();
40899     while ( ( c = Extra_UtilGetopt( argc, argv, "TBFCHSLripcsyzvwh" ) ) != EOF )
40900     {
40901         switch ( c )
40902         {
40903         case 'T':
40904             if ( globalUtilOptind >= argc )
40905             {
40906                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
40907                 goto usage;
40908             }
40909             pPars->TimeLimit = atoi(argv[globalUtilOptind]);
40910             globalUtilOptind++;
40911             if ( pPars->TimeLimit < 0 )
40912                 goto usage;
40913             break;
40914         case 'B':
40915             if ( globalUtilOptind >= argc )
40916             {
40917                 Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" );
40918                 goto usage;
40919             }
40920             pPars->nBddMax = atoi(argv[globalUtilOptind]);
40921             globalUtilOptind++;
40922             if ( pPars->nBddMax < 0 )
40923                 goto usage;
40924             break;
40925         case 'F':
40926             if ( globalUtilOptind >= argc )
40927             {
40928                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
40929                 goto usage;
40930             }
40931             pPars->nIterMax = atoi(argv[globalUtilOptind]);
40932             globalUtilOptind++;
40933             if ( pPars->nIterMax < 0 )
40934                 goto usage;
40935             break;
40936         case 'C':
40937             if ( globalUtilOptind >= argc )
40938             {
40939                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
40940                 goto usage;
40941             }
40942             pPars->nClusterMax = atoi(argv[globalUtilOptind]);
40943             globalUtilOptind++;
40944             if ( pPars->nClusterMax < 0 )
40945                 goto usage;
40946             break;
40947         case 'H':
40948             if ( globalUtilOptind >= argc )
40949             {
40950                 Abc_Print( -1, "Command line switch \"-H\" should be followed by an integer.\n" );
40951                 goto usage;
40952             }
40953             pPars->nHintDepth = atoi(argv[globalUtilOptind]);
40954             globalUtilOptind++;
40955             if ( pPars->nHintDepth < 0 )
40956                 goto usage;
40957             break;
40958         case 'S':
40959             if ( globalUtilOptind >= argc )
40960             {
40961                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
40962                 goto usage;
40963             }
40964             pPars->HintFirst = atoi(argv[globalUtilOptind]);
40965             globalUtilOptind++;
40966             if ( pPars->HintFirst < 0 )
40967                 goto usage;
40968             break;
40969         case 'L':
40970             if ( globalUtilOptind >= argc )
40971             {
40972                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
40973                 goto usage;
40974             }
40975             pLogFileName = argv[globalUtilOptind];
40976             globalUtilOptind++;
40977             break;
40978         case 'r':
40979             pPars->fReorder ^= 1;
40980             break;
40981         case 'i':
40982             pPars->fIndConstr ^= 1;
40983             break;
40984         case 'p':
40985             pPars->fUsePivots ^= 1;
40986             break;
40987         case 'c':
40988             pPars->fCluster ^= 1;
40989             break;
40990         case 's':
40991             pPars->fSchedule ^= 1;
40992             break;
40993         case 'y':
40994             pPars->fSkipOutCheck ^= 1;
40995             break;
40996         case 'z':
40997             pPars->fSkipReach ^= 1;
40998             break;
40999         case 'v':
41000             pPars->fVerbose ^= 1;
41001             break;
41002         case 'w':
41003             pPars->fVeryVerbose ^= 1;
41004             break;
41005         case 'h':
41006             goto usage;
41007         default:
41008             goto usage;
41009         }
41010     }
41011     if ( pAbc->pGia == NULL )
41012     {
41013         Abc_Print( -1, "Abc_CommandAbc9ReachM(): There is no AIG.\n" );
41014         return 1;
41015     }
41016     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
41017     {
41018         Abc_Print( -1, "Abc_CommandAbc9ReachM(): The current AIG has no latches.\n" );
41019         return 0;
41020     }
41021     if ( Gia_ManObjNum(pAbc->pGia) >= (1<<16) )
41022     {
41023         Abc_Print( -1, "Abc_CommandAbc9ReachM(): Currently cannot handle AIGs with more than %d objects.\n", (1<<16) );
41024         return 0;
41025     }
41026     pAbc->Status  = Llb_ManModelCheckGia( pAbc->pGia, pPars );
41027     pAbc->nFrames = pPars->iFrame;
41028     Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexSeq );
41029     if ( pLogFileName )
41030         Abc_NtkWriteLogFile( pLogFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, "&reachm" );
41031     return 0;
41032 
41033 usage:
41034     Abc_Print( -2, "usage: &reachm [-TBFCHS num] [-L file] [-ripcsyzvwh]\n" );
41035     Abc_Print( -2, "\t         model checking via BDD-based reachability (dependence-matrix-based)\n" );
41036     Abc_Print( -2, "\t-T num : approximate time limit in seconds (0=infinite) [default = %d]\n", pPars->TimeLimit );
41037     Abc_Print( -2, "\t-B num : max number of nodes in the intermediate BDDs [default = %d]\n", pPars->nBddMax );
41038     Abc_Print( -2, "\t-F num : max number of reachability iterations [default = %d]\n", pPars->nIterMax );
41039     Abc_Print( -2, "\t-C num : max number of variables in a cluster [default = %d]\n", pPars->nClusterMax );
41040     Abc_Print( -2, "\t-H num : max number of hints to use [default = %d]\n", pPars->nHintDepth );
41041     Abc_Print( -2, "\t-S num : the number of the starting hint [default = %d]\n", pPars->HintFirst );
41042     Abc_Print( -2, "\t-L file: the log file name [default = %s]\n", pLogFileName ? pLogFileName : "no logging" );
41043     Abc_Print( -2, "\t-r     : enable dynamic BDD variable reordering [default = %s]\n", pPars->fReorder? "yes": "no" );
41044     Abc_Print( -2, "\t-i     : enable extraction of inductive constraints [default = %s]\n", pPars->fIndConstr? "yes": "no" );
41045     Abc_Print( -2, "\t-p     : enable partitions for internal cut-points [default = %s]\n", pPars->fUsePivots? "yes": "no" );
41046     Abc_Print( -2, "\t-c     : enable clustering of partitions [default = %s]\n", pPars->fCluster? "yes": "no" );
41047     Abc_Print( -2, "\t-s     : enable scheduling of clusters [default = %s]\n", pPars->fSchedule? "yes": "no" );
41048     Abc_Print( -2, "\t-y     : skip checking property outputs [default = %s]\n", pPars->fSkipOutCheck? "yes": "no" );
41049     Abc_Print( -2, "\t-z     : skip reachability (run preparation phase only) [default = %s]\n", pPars->fSkipReach? "yes": "no" );
41050     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
41051     Abc_Print( -2, "\t-w     : prints dependency matrix [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
41052     Abc_Print( -2, "\t-h     : print the command usage\n");
41053     return 1;
41054 }
41055 
41056 /**Function*************************************************************
41057 
41058   Synopsis    []
41059 
41060   Description []
41061 
41062   SideEffects []
41063 
41064   SeeAlso     []
41065 
41066 ***********************************************************************/
Abc_CommandAbc9ReachP(Abc_Frame_t * pAbc,int argc,char ** argv)41067 int Abc_CommandAbc9ReachP( Abc_Frame_t * pAbc, int argc, char ** argv )
41068 {
41069 //    Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
41070     Gia_ParLlb_t Pars, * pPars = &Pars;
41071     Aig_Man_t * pMan;
41072     char * pLogFileName = NULL;
41073     int c;
41074     extern int Llb_ManReachMinCut( Aig_Man_t * pAig, Gia_ParLlb_t * pPars );
41075 
41076     // set defaults
41077     Llb_ManSetDefaultParams( pPars );
41078     Extra_UtilGetoptReset();
41079     while ( ( c = Extra_UtilGetopt( argc, argv, "NBFTLrbyzdvwh" ) ) != EOF )
41080     {
41081         switch ( c )
41082         {
41083         case 'N':
41084             if ( globalUtilOptind >= argc )
41085             {
41086                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
41087                 goto usage;
41088             }
41089             pPars->nPartValue = atoi(argv[globalUtilOptind]);
41090             globalUtilOptind++;
41091             if ( pPars->nPartValue < 0 )
41092                 goto usage;
41093             break;
41094         case 'B':
41095             if ( globalUtilOptind >= argc )
41096             {
41097                 Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" );
41098                 goto usage;
41099             }
41100             pPars->nBddMax = atoi(argv[globalUtilOptind]);
41101             globalUtilOptind++;
41102             if ( pPars->nBddMax < 0 )
41103                 goto usage;
41104             break;
41105         case 'F':
41106             if ( globalUtilOptind >= argc )
41107             {
41108                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
41109                 goto usage;
41110             }
41111             pPars->nIterMax = atoi(argv[globalUtilOptind]);
41112             globalUtilOptind++;
41113             if ( pPars->nIterMax < 0 )
41114                 goto usage;
41115             break;
41116         case 'T':
41117             if ( globalUtilOptind >= argc )
41118             {
41119                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
41120                 goto usage;
41121             }
41122             pPars->TimeLimit = atoi(argv[globalUtilOptind]);
41123             globalUtilOptind++;
41124             if ( pPars->TimeLimit < 0 )
41125                 goto usage;
41126             break;
41127         case 'L':
41128             if ( globalUtilOptind >= argc )
41129             {
41130                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
41131                 goto usage;
41132             }
41133             pLogFileName = argv[globalUtilOptind];
41134             globalUtilOptind++;
41135             break;
41136         case 'r':
41137             pPars->fReorder ^= 1;
41138             break;
41139         case 'b':
41140             pPars->fBackward ^= 1;
41141             break;
41142         case 'y':
41143             pPars->fSkipOutCheck ^= 1;
41144             break;
41145         case 'z':
41146             pPars->fSkipReach ^= 1;
41147             break;
41148         case 'd':
41149             pPars->fDumpReached ^= 1;
41150             break;
41151         case 'v':
41152             pPars->fVerbose ^= 1;
41153             break;
41154         case 'w':
41155             pPars->fVeryVerbose ^= 1;
41156             break;
41157         case 'h':
41158             goto usage;
41159         default:
41160             goto usage;
41161         }
41162     }
41163     if ( pAbc->pGia == NULL )
41164     {
41165         Abc_Print( -1, "Abc_CommandAbc9ReachP(): There is no AIG.\n" );
41166         return 1;
41167     }
41168     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
41169     {
41170         Abc_Print( -1, "Abc_CommandAbc9ReachP(): The current AIG has no latches.\n" );
41171         return 0;
41172     }
41173     if ( Gia_ManObjNum(pAbc->pGia) >= (1<<16) )
41174     {
41175         Abc_Print( -1, "Abc_CommandAbc9ReachP(): Currently cannot handle AIGs with more than %d objects.\n", (1<<16) );
41176         return 0;
41177     }
41178     pMan          = Gia_ManToAigSimple( pAbc->pGia );
41179     pAbc->Status  = Llb_ManReachMinCut( pMan, pPars );
41180     pAbc->nFrames = pPars->iFrame;
41181     Abc_FrameReplaceCex( pAbc, &pMan->pSeqModel );
41182     if ( pLogFileName )
41183         Abc_NtkWriteLogFile( pLogFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, "&reachp" );
41184     Aig_ManStop( pMan );
41185     return 0;
41186 
41187 usage:
41188     Abc_Print( -2, "usage: &reachp [-NFT num] [-L file] [-rbyzdvwh]\n" );
41189     Abc_Print( -2, "\t         model checking via BDD-based reachability (partitioning-based)\n" );
41190     Abc_Print( -2, "\t-N num : partitioning value (MinVol=nANDs/N/2; MaxVol=nANDs/N) [default = %d]\n", pPars->nPartValue );
41191 //    Abc_Print( -2, "\t-B num : the BDD node increase when hints kick in [default = %d]\n", pPars->nBddMax );
41192     Abc_Print( -2, "\t-F num : max number of reachability iterations [default = %d]\n", pPars->nIterMax );
41193     Abc_Print( -2, "\t-T num : approximate time limit in seconds (0=infinite) [default = %d]\n", pPars->TimeLimit );
41194     Abc_Print( -2, "\t-L file: the log file name [default = %s]\n", pLogFileName ? pLogFileName : "no logging" );
41195     Abc_Print( -2, "\t-r     : enable additional BDD var reordering before image [default = %s]\n", pPars->fReorder? "yes": "no" );
41196     Abc_Print( -2, "\t-b     : perform backward reachability analysis [default = %s]\n", pPars->fBackward? "yes": "no" );
41197     Abc_Print( -2, "\t-y     : skip checking property outputs [default = %s]\n", pPars->fSkipOutCheck? "yes": "no" );
41198     Abc_Print( -2, "\t-z     : skip reachability (run preparation phase only) [default = %s]\n", pPars->fSkipReach? "yes": "no" );
41199     Abc_Print( -2, "\t-d     : dump BDD of reached states into file \"reached.blif\" [default = %s]\n", pPars->fDumpReached? "yes": "no" );
41200     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
41201     Abc_Print( -2, "\t-w     : prints additional information [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
41202     Abc_Print( -2, "\t-h     : print the command usage\n");
41203     return 1;
41204 }
41205 
41206 /**Function*************************************************************
41207 
41208   Synopsis    []
41209 
41210   Description []
41211 
41212   SideEffects []
41213 
41214   SeeAlso     []
41215 
41216 ***********************************************************************/
Abc_CommandAbc9ReachN(Abc_Frame_t * pAbc,int argc,char ** argv)41217 int Abc_CommandAbc9ReachN( Abc_Frame_t * pAbc, int argc, char ** argv )
41218 {
41219 //    Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
41220     Gia_ParLlb_t Pars, * pPars = &Pars;
41221     Aig_Man_t * pMan;
41222     char * pLogFileName = NULL;
41223     int c;
41224     extern int Llb_NonlinCoreReach( Aig_Man_t * pAig, Gia_ParLlb_t * pPars );
41225 
41226     // set defaults
41227     Llb_ManSetDefaultParams( pPars );
41228     Extra_UtilGetoptReset();
41229     while ( ( c = Extra_UtilGetopt( argc, argv, "BFTLryzvwh" ) ) != EOF )
41230     {
41231         switch ( c )
41232         {
41233         case 'B':
41234             if ( globalUtilOptind >= argc )
41235             {
41236                 Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" );
41237                 goto usage;
41238             }
41239             pPars->nBddMax = atoi(argv[globalUtilOptind]);
41240             globalUtilOptind++;
41241             if ( pPars->nBddMax < 0 )
41242                 goto usage;
41243             break;
41244         case 'F':
41245             if ( globalUtilOptind >= argc )
41246             {
41247                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
41248                 goto usage;
41249             }
41250             pPars->nIterMax = atoi(argv[globalUtilOptind]);
41251             globalUtilOptind++;
41252             if ( pPars->nIterMax < 0 )
41253                 goto usage;
41254             break;
41255         case 'T':
41256             if ( globalUtilOptind >= argc )
41257             {
41258                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
41259                 goto usage;
41260             }
41261             pPars->TimeLimit = atoi(argv[globalUtilOptind]);
41262             globalUtilOptind++;
41263             if ( pPars->TimeLimit < 0 )
41264                 goto usage;
41265             break;
41266         case 'L':
41267             if ( globalUtilOptind >= argc )
41268             {
41269                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
41270                 goto usage;
41271             }
41272             pLogFileName = argv[globalUtilOptind];
41273             globalUtilOptind++;
41274             break;
41275         case 'r':
41276             pPars->fReorder ^= 1;
41277             break;
41278         case 'y':
41279             pPars->fSkipOutCheck ^= 1;
41280             break;
41281         case 'z':
41282             pPars->fSkipReach ^= 1;
41283             break;
41284         case 'v':
41285             pPars->fVerbose ^= 1;
41286             break;
41287         case 'w':
41288             pPars->fVeryVerbose ^= 1;
41289             break;
41290         case 'h':
41291             goto usage;
41292         default:
41293             goto usage;
41294         }
41295     }
41296     if ( pAbc->pGia == NULL )
41297     {
41298         Abc_Print( -1, "Abc_CommandAbc9ReachN(): There is no AIG.\n" );
41299         return 1;
41300     }
41301     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
41302     {
41303         Abc_Print( -1, "Abc_CommandAbc9ReachN(): The current AIG has no latches.\n" );
41304         return 0;
41305     }
41306     if ( Gia_ManObjNum(pAbc->pGia) >= (1<<16) )
41307     {
41308         Abc_Print( -1, "Abc_CommandAbc9ReachN(): Currently cannot handle AIGs with more than %d objects.\n", (1<<16) );
41309         return 0;
41310     }
41311     pMan          = Gia_ManToAigSimple( pAbc->pGia );
41312     pAbc->Status  = Llb_NonlinCoreReach( pMan, pPars );
41313     pAbc->nFrames = pPars->iFrame;
41314     Abc_FrameReplaceCex( pAbc, &pMan->pSeqModel );
41315     if ( pLogFileName )
41316         Abc_NtkWriteLogFile( pLogFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, "&reachn" );
41317     Aig_ManStop( pMan );
41318     return 0;
41319 
41320 usage:
41321     Abc_Print( -2, "usage: &reachn [-BFT num] [-L file] [-ryzvh]\n" );
41322     Abc_Print( -2, "\t         model checking via BDD-based reachability (non-linear-QS-based)\n" );
41323     Abc_Print( -2, "\t-B num : the BDD node increase when hints kick in [default = %d]\n", pPars->nBddMax );
41324     Abc_Print( -2, "\t-F num : max number of reachability iterations [default = %d]\n", pPars->nIterMax );
41325     Abc_Print( -2, "\t-T num : approximate time limit in seconds (0=infinite) [default = %d]\n", pPars->TimeLimit );
41326     Abc_Print( -2, "\t-L file: the log file name [default = %s]\n", pLogFileName ? pLogFileName : "no logging" );
41327     Abc_Print( -2, "\t-r     : enable additional BDD var reordering before image [default = %s]\n", pPars->fReorder? "yes": "no" );
41328     Abc_Print( -2, "\t-y     : skip checking property outputs [default = %s]\n", pPars->fSkipOutCheck? "yes": "no" );
41329     Abc_Print( -2, "\t-z     : skip reachability (run preparation phase only) [default = %s]\n", pPars->fSkipReach? "yes": "no" );
41330     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
41331 //    Abc_Print( -2, "\t-w     : prints additional information [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
41332     Abc_Print( -2, "\t-h     : print the command usage\n");
41333     return 1;
41334 }
41335 
41336 /**Function*************************************************************
41337 
41338   Synopsis    []
41339 
41340   Description []
41341 
41342   SideEffects []
41343 
41344   SeeAlso     []
41345 
41346 ***********************************************************************/
Abc_CommandAbc9ReachY(Abc_Frame_t * pAbc,int argc,char ** argv)41347 int Abc_CommandAbc9ReachY( Abc_Frame_t * pAbc, int argc, char ** argv )
41348 {
41349 //    Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
41350     Gia_ParLlb_t Pars, * pPars = &Pars;
41351     Aig_Man_t * pMan;
41352     char * pLogFileName = NULL;
41353     int c;
41354 
41355     // set defaults
41356     Llb_ManSetDefaultParams( pPars );
41357     pPars->fCluster = 0;
41358     pPars->fReorder = 0;
41359     pPars->nBddMax     = 100;
41360     pPars->nClusterMax = 500;
41361     Extra_UtilGetoptReset();
41362     while ( ( c = Extra_UtilGetopt( argc, argv, "BCFTLbcryzvwh" ) ) != EOF )
41363     {
41364         switch ( c )
41365         {
41366         case 'B':
41367             if ( globalUtilOptind >= argc )
41368             {
41369                 Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" );
41370                 goto usage;
41371             }
41372             pPars->nBddMax = atoi(argv[globalUtilOptind]);
41373             globalUtilOptind++;
41374             if ( pPars->nBddMax < 0 )
41375                 goto usage;
41376             break;
41377         case 'C':
41378             if ( globalUtilOptind >= argc )
41379             {
41380                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
41381                 goto usage;
41382             }
41383             pPars->nClusterMax = atoi(argv[globalUtilOptind]);
41384             globalUtilOptind++;
41385             if ( pPars->nClusterMax < 0 )
41386                 goto usage;
41387             break;
41388         case 'F':
41389             if ( globalUtilOptind >= argc )
41390             {
41391                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
41392                 goto usage;
41393             }
41394             pPars->nIterMax = atoi(argv[globalUtilOptind]);
41395             globalUtilOptind++;
41396             if ( pPars->nIterMax < 0 )
41397                 goto usage;
41398             break;
41399         case 'T':
41400             if ( globalUtilOptind >= argc )
41401             {
41402                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
41403                 goto usage;
41404             }
41405             pPars->TimeLimit = atoi(argv[globalUtilOptind]);
41406             globalUtilOptind++;
41407             if ( pPars->TimeLimit < 0 )
41408                 goto usage;
41409             break;
41410         case 'L':
41411             if ( globalUtilOptind >= argc )
41412             {
41413                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
41414                 goto usage;
41415             }
41416             pLogFileName = argv[globalUtilOptind];
41417             globalUtilOptind++;
41418             break;
41419         case 'b':
41420             pPars->fBackward ^= 1;
41421             break;
41422         case 'c':
41423             pPars->fCluster ^= 1;
41424             break;
41425         case 'r':
41426             pPars->fReorder ^= 1;
41427             break;
41428         case 'y':
41429             pPars->fSkipOutCheck ^= 1;
41430             break;
41431         case 'z':
41432             pPars->fSkipReach ^= 1;
41433             break;
41434         case 'v':
41435             pPars->fVerbose ^= 1;
41436             break;
41437         case 'w':
41438             pPars->fVeryVerbose ^= 1;
41439             break;
41440         case 'h':
41441             goto usage;
41442         default:
41443             goto usage;
41444         }
41445     }
41446     if ( pAbc->pGia == NULL )
41447     {
41448         Abc_Print( -1, "Abc_CommandAbc9ReachN(): There is no AIG.\n" );
41449         return 1;
41450     }
41451     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
41452     {
41453         Abc_Print( -1, "Abc_CommandAbc9ReachN(): The current AIG has no latches.\n" );
41454         return 0;
41455     }
41456 /*
41457     if ( Gia_ManObjNum(pAbc->pGia) >= (1<<16) )
41458     {
41459         Abc_Print( -1, "Abc_CommandAbc9ReachN(): Currently cannot handle AIGs with more than %d objects.\n", (1<<16) );
41460         return 0;
41461     }
41462 */
41463     pMan          = Gia_ManToAigSimple( pAbc->pGia );
41464     pAbc->Status  = Llb_Nonlin4CoreReach( pMan, pPars );
41465     pAbc->nFrames = pPars->iFrame;
41466     Abc_FrameReplaceCex( pAbc, &pMan->pSeqModel );
41467     if ( pLogFileName )
41468         Abc_NtkWriteLogFile( pLogFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, "&reachy" );
41469     Aig_ManStop( pMan );
41470     return 0;
41471 
41472 usage:
41473     Abc_Print( -2, "usage: &reachy [-BCFT num] [-L file] [-bcryzvh]\n" );
41474     Abc_Print( -2, "\t         model checking via BDD-based reachability (non-linear-QS-based)\n" );
41475     Abc_Print( -2, "\t-B num : the max BDD size to introduce cut points [default = %d]\n", pPars->nBddMax );
41476     Abc_Print( -2, "\t-C num : the max BDD size to reparameterize/cluster [default = %d]\n", pPars->nClusterMax );
41477     Abc_Print( -2, "\t-F num : max number of reachability iterations [default = %d]\n", pPars->nIterMax );
41478     Abc_Print( -2, "\t-T num : approximate time limit in seconds (0=infinite) [default = %d]\n", pPars->TimeLimit );
41479     Abc_Print( -2, "\t-L file: the log file name [default = %s]\n", pLogFileName ? pLogFileName : "no logging" );
41480     Abc_Print( -2, "\t-b     : enable using backward enumeration [default = %s]\n", pPars->fBackward? "yes": "no" );
41481     Abc_Print( -2, "\t-c     : enable reparametrization clustering [default = %s]\n", pPars->fCluster? "yes": "no" );
41482     Abc_Print( -2, "\t-r     : enable additional BDD var reordering before image [default = %s]\n", pPars->fReorder? "yes": "no" );
41483     Abc_Print( -2, "\t-y     : skip checking property outputs [default = %s]\n", pPars->fSkipOutCheck? "yes": "no" );
41484     Abc_Print( -2, "\t-z     : skip reachability (run preparation phase only) [default = %s]\n", pPars->fSkipReach? "yes": "no" );
41485     Abc_Print( -2, "\t-v     : prints verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
41486 //    Abc_Print( -2, "\t-w     : prints additional information [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
41487     Abc_Print( -2, "\t-h     : print the command usage\n");
41488     return 1;
41489 }
41490 
41491 #endif
41492 
41493 /**Function*************************************************************
41494 
41495   Synopsis    []
41496 
41497   Description []
41498 
41499   SideEffects []
41500 
41501   SeeAlso     []
41502 
41503 ***********************************************************************/
Abc_CommandAbc9Undo(Abc_Frame_t * pAbc,int argc,char ** argv)41504 int Abc_CommandAbc9Undo( Abc_Frame_t * pAbc, int argc, char ** argv )
41505 {
41506     int c;
41507     // set defaults
41508     Extra_UtilGetoptReset();
41509     while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
41510     {
41511         switch ( c )
41512         {
41513         case 'h':
41514             goto usage;
41515         default:
41516             goto usage;
41517         }
41518     }
41519     if ( pAbc->pGia == NULL )
41520     {
41521         Abc_Print( -1, "Abc_CommandAbc9Undo(): There is no design.\n" );
41522         return 1;
41523     }
41524     if ( pAbc->pGia2 == NULL )
41525     {
41526         Abc_Print( -1, "Abc_CommandAbc9Undo(): There is no previously saved network.\n" );
41527         return 1;
41528     }
41529     Gia_ManStop( pAbc->pGia );
41530     pAbc->pGia = pAbc->pGia2;
41531     pAbc->pGia2 = NULL;
41532     return 0;
41533 
41534 usage:
41535     Abc_Print( -2, "usage: &undo [-h]\n" );
41536     Abc_Print( -2, "\t        reverses the previous AIG transformation\n" );
41537     Abc_Print( -2, "\t-h    : print the command usage\n");
41538     return 1;
41539 }
41540 
41541 /**Function*************************************************************
41542 
41543   Synopsis    []
41544 
41545   Description []
41546 
41547   SideEffects []
41548 
41549   SeeAlso     []
41550 
41551 ***********************************************************************/
Abc_CommandAbc9Mesh(Abc_Frame_t * pAbc,int argc,char ** argv)41552 int Abc_CommandAbc9Mesh( Abc_Frame_t * pAbc, int argc, char ** argv )
41553 {
41554     extern void Bmc_MeshTest( Gia_Man_t * p, int X, int Y, int T, int fVerbose );
41555     extern void Bmc_MeshTest2( Gia_Man_t * p, int X, int Y, int T, int fVerbose );
41556     int X =  4;
41557     int Y =  4;
41558     int T =  3;
41559     int fUseSatoko = 1;
41560     int c, fVerbose = 1;
41561     // set defaults
41562     Extra_UtilGetoptReset();
41563     while ( ( c = Extra_UtilGetopt( argc, argv, "XYTsh" ) ) != EOF )
41564     {
41565         switch ( c )
41566         {
41567         case 'X':
41568             if ( globalUtilOptind >= argc )
41569             {
41570                 Abc_Print( -1, "Command line switch \"-X\" should be followed by an integer.\n" );
41571                 goto usage;
41572             }
41573             X = atoi(argv[globalUtilOptind]);
41574             globalUtilOptind++;
41575             if ( X < 3 )
41576                 goto usage;
41577             break;
41578         case 'Y':
41579             if ( globalUtilOptind >= argc )
41580             {
41581                 Abc_Print( -1, "Command line switch \"-Y\" should be followed by an integer.\n" );
41582                 goto usage;
41583             }
41584             Y = atoi(argv[globalUtilOptind]);
41585             globalUtilOptind++;
41586             if ( Y < 3 )
41587                 goto usage;
41588             break;
41589         case 'T':
41590             if ( globalUtilOptind >= argc )
41591             {
41592                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
41593                 goto usage;
41594             }
41595             T = atoi(argv[globalUtilOptind]);
41596             globalUtilOptind++;
41597             if ( T < 2 )
41598                 goto usage;
41599             break;
41600         case 's':
41601             fUseSatoko ^= 1;
41602             break;
41603         case 'v':
41604             fVerbose ^= 1;
41605             break;
41606         case 'h':
41607             goto usage;
41608         default:
41609             goto usage;
41610         }
41611     }
41612     if ( pAbc->pGia == NULL )
41613     {
41614         Abc_Print( -1, "Abc_CommandAbc9Mesh(): There is no design.\n" );
41615         return 1;
41616     }
41617     if ( Gia_ManCoNum(pAbc->pGia) != 1 )
41618     {
41619         Abc_Print( -1, "Currently this command expects AIG with one output.\n" );
41620         return 1;
41621     }
41622     if ( Gia_ManCiNum(pAbc->pGia) > 20 )
41623     {
41624         Abc_Print( -1, "Currently this command expects AIG with no more than 20 nodes.\n" );
41625         return 1;
41626     }
41627     if ( Gia_ManLevelNum(pAbc->pGia) > T )
41628     {
41629         Abc_Print( -1, "The depth of the AIG (%d) cannot be larger than the latency (%d).\n", Gia_ManLevelNum(pAbc->pGia), T );
41630         return 1;
41631     }
41632     if ( fUseSatoko )
41633         Bmc_MeshTest( pAbc->pGia, X, Y, T, fVerbose );
41634     else
41635         Bmc_MeshTest2( pAbc->pGia, X, Y, T, fVerbose );
41636     return 0;
41637 
41638 usage:
41639     Abc_Print( -2, "usage: &mesh [-XYT num] [-sh]\n" );
41640     Abc_Print( -2, "\t         creates a mesh architecture for the given AIG\n" );
41641     Abc_Print( -2, "\t-X num : horizontal size of the mesh (X >= 3) [default = %d]\n", X );
41642     Abc_Print( -2, "\t-Y num : vertical size of the mesh (Y >= 3) [default = %d]\n", Y );
41643     Abc_Print( -2, "\t-T num : the latency of the mesh (T >= 2) [default = %d]\n", T );
41644     Abc_Print( -2, "\t-s     : toggle using new SAT solver Satoko [default = %s]\n", fUseSatoko? "yes": "no" );
41645     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
41646     Abc_Print( -2, "\t-h     : print the command usage\n");
41647     return 1;
41648 }
41649 
41650 /**Function*************************************************************
41651 
41652   Synopsis    []
41653 
41654   Description []
41655 
41656   SideEffects []
41657 
41658   SeeAlso     []
41659 
41660 ***********************************************************************/
Abc_CommandAbc9Iso(Abc_Frame_t * pAbc,int argc,char ** argv)41661 int Abc_CommandAbc9Iso( Abc_Frame_t * pAbc, int argc, char ** argv )
41662 {
41663     Gia_Man_t * pAig;
41664     Vec_Ptr_t * vPosEquivs;
41665 //    Vec_Ptr_t * vPiPerms;
41666     int c, fNewAlgo = 1, fEstimate = 0, fBetterQual = 0, fDualOut = 0, fVerbose = 0, fVeryVerbose = 0;
41667     Extra_UtilGetoptReset();
41668     while ( ( c = Extra_UtilGetopt( argc, argv, "neqdvwh" ) ) != EOF )
41669     {
41670         switch ( c )
41671         {
41672         case 'n':
41673             fNewAlgo ^= 1;
41674             break;
41675         case 'e':
41676             fEstimate ^= 1;
41677             break;
41678         case 'q':
41679             fBetterQual ^= 1;
41680             break;
41681         case 'd':
41682             fDualOut ^= 1;
41683             break;
41684         case 'v':
41685             fVerbose ^= 1;
41686             break;
41687         case 'w':
41688             fVeryVerbose ^= 1;
41689             break;
41690         case 'h':
41691             goto usage;
41692         default:
41693             goto usage;
41694         }
41695     }
41696     if ( pAbc->pGia == NULL )
41697     {
41698         Abc_Print( -1, "Abc_CommandAbc9Iso(): There is no AIG.\n" );
41699         return 1;
41700     }
41701     if ( Gia_ManPoNum(pAbc->pGia) == 1 )
41702     {
41703         Abc_Print( -1, "Abc_CommandAbc9Iso(): The AIG has only one PO. Isomorphism detection is not performed.\n" );
41704         return 1;
41705     }
41706     if ( fNewAlgo )
41707         pAig = Gia_ManIsoReduce2( pAbc->pGia, &vPosEquivs, NULL, fEstimate, fBetterQual, fDualOut, fVerbose, fVeryVerbose );
41708     else
41709         pAig = Gia_ManIsoReduce( pAbc->pGia, &vPosEquivs, NULL, fEstimate, fDualOut, fVerbose, fVeryVerbose );
41710 //    pAig = Gia_ManIsoReduce( pAbc->pGia, &vPosEquivs, &vPiPerms, 0, fDualOut, fVerbose, fVeryVerbose );
41711 //    Vec_VecFree( (Vec_Vec_t *)vPiPerms );
41712     if ( pAig == NULL )
41713     {
41714         Abc_Print( -1, "Abc_CommandAbc9Iso(): Transformation has failed.\n" );
41715         return 1;
41716     }
41717     // update the internal storage of PO equivalences
41718     Abc_FrameReplacePoEquivs( pAbc, &vPosEquivs );
41719     // update the AIG
41720     Abc_FrameUpdateGia( pAbc, pAig );
41721     return 0;
41722 
41723 usage:
41724     Abc_Print( -2, "usage: &iso [-neqdvwh]\n" );
41725     Abc_Print( -2, "\t         removes POs with isomorphic sequential COI\n" );
41726     Abc_Print( -2, "\t-n     : toggle using new fast algorithm [default = %s]\n", fNewAlgo? "yes": "no" );
41727     Abc_Print( -2, "\t-e     : toggle computing lower bound on equivalence classes [default = %s]\n", fEstimate? "yes": "no" );
41728     Abc_Print( -2, "\t-q     : toggle improving quality at the expense of runtime [default = %s]\n", fBetterQual? "yes": "no" );
41729     Abc_Print( -2, "\t-d     : toggle treating the current AIG as a dual-output miter [default = %s]\n", fDualOut? "yes": "no" );
41730     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
41731     Abc_Print( -2, "\t-w     : toggle printing very verbose information [default = %s]\n", fVeryVerbose? "yes": "no" );
41732     Abc_Print( -2, "\t-h     : print the command usage\n");
41733     return 1;
41734 }
41735 
41736 /**Function*************************************************************
41737 
41738   Synopsis    []
41739 
41740   Description []
41741 
41742   SideEffects []
41743 
41744   SeeAlso     []
41745 
41746 ***********************************************************************/
Abc_CommandAbc9IsoNpn(Abc_Frame_t * pAbc,int argc,char ** argv)41747 int Abc_CommandAbc9IsoNpn( Abc_Frame_t * pAbc, int argc, char ** argv )
41748 {
41749     extern Gia_Man_t * Gia_ManIsoNpnReduce( Gia_Man_t * p, Vec_Ptr_t ** pvPosEquivs, int fVerbose );
41750     Gia_Man_t * pAig;
41751     Vec_Ptr_t * vPosEquivs;
41752     int c, fVerbose = 0;
41753     Extra_UtilGetoptReset();
41754     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
41755     {
41756         switch ( c )
41757         {
41758         case 'v':
41759             fVerbose ^= 1;
41760             break;
41761         case 'h':
41762             goto usage;
41763         default:
41764             goto usage;
41765         }
41766     }
41767     if ( pAbc->pGia == NULL )
41768     {
41769         Abc_Print( -1, "Abc_CommandAbc9IsoNpn(): There is no AIG.\n" );
41770         return 1;
41771     }
41772     if ( Gia_ManPoNum(pAbc->pGia) == 1 )
41773     {
41774         Abc_Print( -1, "Abc_CommandAbc9IsoNpn(): The AIG has only one PO. Isomorphism detection is not performed.\n" );
41775         return 1;
41776     }
41777     if ( Gia_ManRegNum(pAbc->pGia) )
41778     {
41779         Abc_Print( -1, "Abc_CommandAbc9IsoNpn(): ISO-NPN does not work with sequential AIGs.\n" );
41780         return 1;
41781     }
41782     pAig = Gia_ManIsoNpnReduce( pAbc->pGia, &vPosEquivs, fVerbose );
41783     if ( pAig == NULL )
41784     {
41785         Abc_Print( -1, "Abc_CommandAbc9IsoNpn(): Transformation has failed.\n" );
41786         return 1;
41787     }
41788     // update the internal storage of PO equivalences
41789     Abc_FrameReplacePoEquivs( pAbc, &vPosEquivs );
41790     // update the AIG
41791     Abc_FrameUpdateGia( pAbc, pAig );
41792     return 0;
41793 
41794 usage:
41795     Abc_Print( -2, "usage: &isonpn [-vh]\n" );
41796     Abc_Print( -2, "\t         removes POs with functionally isomorphic combinational COI\n" );
41797     Abc_Print( -2, "\t         (currently ignores POs whose structural support is more than 16)\n" );
41798     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
41799     Abc_Print( -2, "\t-h     : print the command usage\n");
41800     return 1;
41801 }
41802 
41803 /**Function*************************************************************
41804 
41805   Synopsis    []
41806 
41807   Description []
41808 
41809   SideEffects []
41810 
41811   SeeAlso     []
41812 
41813 ***********************************************************************/
Abc_CommandAbc9IsoSt(Abc_Frame_t * pAbc,int argc,char ** argv)41814 int Abc_CommandAbc9IsoSt( Abc_Frame_t * pAbc, int argc, char ** argv )
41815 {
41816     extern Gia_Man_t * Gia_ManIsoStrashReduce( Gia_Man_t * p, Vec_Ptr_t ** pvPosEquivs, int fVerbose );
41817     Gia_Man_t * pAig;
41818     Vec_Ptr_t * vPosEquivs;
41819     int c, fVerbose = 0;
41820     Extra_UtilGetoptReset();
41821     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
41822     {
41823         switch ( c )
41824         {
41825         case 'v':
41826             fVerbose ^= 1;
41827             break;
41828         case 'h':
41829             goto usage;
41830         default:
41831             goto usage;
41832         }
41833     }
41834     if ( pAbc->pGia == NULL )
41835     {
41836         Abc_Print( -1, "Abc_CommandAbc9IsoSt(): There is no AIG.\n" );
41837         return 1;
41838     }
41839     if ( Gia_ManPoNum(pAbc->pGia) == 1 )
41840     {
41841         Abc_Print( -1, "Abc_CommandAbc9IsoSt(): The AIG has only one PO. Isomorphism detection is not performed.\n" );
41842         return 1;
41843     }
41844     if ( Gia_ManRegNum(pAbc->pGia) )
41845     {
41846         Abc_Print( -1, "Abc_CommandAbc9IsoSt(): ISO-ST does not work with sequential AIGs.\n" );
41847         return 1;
41848     }
41849     pAig = Gia_ManIsoStrashReduce( pAbc->pGia, &vPosEquivs, fVerbose );
41850     if ( pAig == NULL )
41851     {
41852         Abc_Print( -1, "Abc_CommandAbc9IsoSt(): Transformation has failed.\n" );
41853         return 1;
41854     }
41855     // update the internal storage of PO equivalences
41856     Abc_FrameReplacePoEquivs( pAbc, &vPosEquivs );
41857     // update the AIG
41858     Abc_FrameUpdateGia( pAbc, pAig );
41859     return 0;
41860 
41861 usage:
41862     Abc_Print( -2, "usage: &isost [-vh]\n" );
41863     Abc_Print( -2, "\t         removes POs with functionally isomorphic combinational COI\n" );
41864     Abc_Print( -2, "\t         (this command relies exclusively on structural hashing)\n" );
41865     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
41866     Abc_Print( -2, "\t-h     : print the command usage\n");
41867     return 1;
41868 }
41869 
41870 /**Function*************************************************************
41871 
41872   Synopsis    []
41873 
41874   Description []
41875 
41876   SideEffects []
41877 
41878   SeeAlso     []
41879 
41880 ***********************************************************************/
Abc_CommandAbc9CexInfo(Abc_Frame_t * pAbc,int argc,char ** argv)41881 int Abc_CommandAbc9CexInfo( Abc_Frame_t * pAbc, int argc, char ** argv )
41882 {
41883     extern void Bmc_CexTest( Gia_Man_t * p, Abc_Cex_t * pCex, int fVerbose );
41884     int c, fDualOut = 0, fVerbose = 0;
41885     Extra_UtilGetoptReset();
41886     while ( ( c = Extra_UtilGetopt( argc, argv, "dvh" ) ) != EOF )
41887     {
41888         switch ( c )
41889         {
41890         case 'd':
41891             fDualOut ^= 1;
41892             break;
41893         case 'v':
41894             fVerbose ^= 1;
41895             break;
41896         case 'h':
41897             goto usage;
41898         default:
41899             goto usage;
41900         }
41901     }
41902     if ( pAbc->pGia == NULL )
41903     {
41904         Abc_Print( -1, "Abc_CommandAbc9CexInfo(): There is no AIG.\n" );
41905         return 1;
41906     }
41907     if ( pAbc->pCex == NULL )
41908     {
41909         Abc_Print( -1, "Abc_CommandAbc9CexInfo(): There is no CEX.\n" );
41910         return 1;
41911     }
41912     Bmc_CexTest( pAbc->pGia, pAbc->pCex, fVerbose );
41913     return 0;
41914 
41915 usage:
41916     Abc_Print( -2, "usage: &cexinfo [-vh]\n" );
41917     Abc_Print( -2, "\t         prints information about the current counter-example\n" );
41918     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
41919     Abc_Print( -2, "\t-h     : print the command usage\n");
41920     return 1;
41921 }
41922 
41923 /**Function*************************************************************
41924 
41925   Synopsis    []
41926 
41927   Description []
41928 
41929   SideEffects []
41930 
41931   SeeAlso     []
41932 
41933 ***********************************************************************/
Abc_CommandAbc9Cycle(Abc_Frame_t * pAbc,int argc,char ** argv)41934 int Abc_CommandAbc9Cycle( Abc_Frame_t * pAbc, int argc, char ** argv )
41935 {
41936     Gia_Man_t * pTemp;
41937     int c, nFrames = 10, fUseCex = 0, fVerbose = 0;
41938     Extra_UtilGetoptReset();
41939     while ( ( c = Extra_UtilGetopt( argc, argv, "Fcvh" ) ) != EOF )
41940     {
41941         switch ( c )
41942         {
41943         case 'F':
41944             if ( globalUtilOptind >= argc )
41945             {
41946                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
41947                 goto usage;
41948             }
41949             nFrames = atoi(argv[globalUtilOptind]);
41950             globalUtilOptind++;
41951             if ( nFrames < 0 )
41952                 goto usage;
41953             break;
41954         case 'c':
41955             fUseCex ^= 1;
41956             break;
41957         case 'v':
41958             fVerbose ^= 1;
41959             break;
41960         case 'h':
41961             goto usage;
41962         default:
41963             goto usage;
41964         }
41965     }
41966     if ( pAbc->pGia == NULL )
41967     {
41968         Abc_Print( -1, "Abc_CommandAbc9Cycle(): There is no AIG.\n" );
41969         return 1;
41970     }
41971     pTemp = Gia_ManDupCycled( pAbc->pGia, fUseCex ? pAbc->pCex : NULL, nFrames );
41972     Abc_FrameUpdateGia( pAbc, pTemp );
41973     return 0;
41974 
41975 usage:
41976     Abc_Print( -2, "usage: &cycle [-F num] [-cvh]\n" );
41977     Abc_Print( -2, "\t         cycles sequential circuit for the given number of timeframes\n" );
41978     Abc_Print( -2, "\t         to derive a new initial state (which may be on the envelope)\n" );
41979     Abc_Print( -2, "\t-F num : the number of frames to simulate [default = %d]\n", nFrames );
41980     Abc_Print( -2, "\t-c     : toggle using PI values from the current CEX [default = %s]\n", fUseCex? "yes": "no" );
41981     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
41982     Abc_Print( -2, "\t-h     : print the command usage\n");
41983     return 1;
41984 }
41985 
41986 
41987 /**Function*************************************************************
41988 
41989   Synopsis    []
41990 
41991   Description []
41992 
41993   SideEffects []
41994 
41995   SeeAlso     []
41996 
41997 ***********************************************************************/
Abc_CommandAbc9Cone(Abc_Frame_t * pAbc,int argc,char ** argv)41998 int Abc_CommandAbc9Cone( Abc_Frame_t * pAbc, int argc, char ** argv )
41999 {
42000     Gia_Man_t * pTemp;
42001     Vec_Int_t * vPos;
42002     int c, iOutNum = -1, nOutRange = 1, iPartNum = -1, nLevelMax = 0, nTimeWindow = 0, fUseAllCis = 0, fExtractAll = 0, fVerbose = 0;
42003     Extra_UtilGetoptReset();
42004     while ( ( c = Extra_UtilGetopt( argc, argv, "ORPLWaevh" ) ) != EOF )
42005     {
42006         switch ( c )
42007         {
42008         case 'O':
42009             if ( globalUtilOptind >= argc )
42010             {
42011                 Abc_Print( -1, "Command line switch \"-O\" should be followed by an integer.\n" );
42012                 goto usage;
42013             }
42014             iOutNum = atoi(argv[globalUtilOptind]);
42015             globalUtilOptind++;
42016             if ( iOutNum < 0 )
42017                 goto usage;
42018             break;
42019         case 'R':
42020             if ( globalUtilOptind >= argc )
42021             {
42022                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
42023                 goto usage;
42024             }
42025             nOutRange = atoi(argv[globalUtilOptind]);
42026             globalUtilOptind++;
42027             if ( nOutRange < 0 )
42028                 goto usage;
42029             break;
42030         case 'P':
42031             if ( globalUtilOptind >= argc )
42032             {
42033                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
42034                 goto usage;
42035             }
42036             iPartNum = atoi(argv[globalUtilOptind]);
42037             globalUtilOptind++;
42038             if ( iPartNum < 0 )
42039                 goto usage;
42040             break;
42041         case 'L':
42042             if ( globalUtilOptind >= argc )
42043             {
42044                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
42045                 goto usage;
42046             }
42047             nLevelMax = atoi(argv[globalUtilOptind]);
42048             globalUtilOptind++;
42049             if ( nLevelMax < 0 )
42050                 goto usage;
42051             break;
42052         case 'W':
42053             if ( globalUtilOptind >= argc )
42054             {
42055                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
42056                 goto usage;
42057             }
42058             nTimeWindow = atoi(argv[globalUtilOptind]);
42059             globalUtilOptind++;
42060             if ( nTimeWindow < 0 )
42061                 goto usage;
42062             break;
42063         case 'a':
42064             fUseAllCis ^= 1;
42065             break;
42066         case 'e':
42067             fExtractAll ^= 1;
42068             break;
42069         case 'v':
42070             fVerbose ^= 1;
42071             break;
42072         case 'h':
42073             goto usage;
42074         default:
42075             goto usage;
42076         }
42077     }
42078     if ( pAbc->pGia == NULL )
42079     {
42080         Abc_Print( -1, "Abc_CommandAbc9Cone(): There is no AIG.\n" );
42081         return 1;
42082     }
42083     if ( fExtractAll )
42084     {
42085         char Buffer[1000];
42086         Gia_Obj_t * pObj;
42087         int i, nDigits = Abc_Base10Log(Gia_ManPoNum(pAbc->pGia));
42088         Gia_ManForEachPo( pAbc->pGia, pObj, i )
42089         {
42090             Gia_Man_t * pOne = Gia_ManDupDfsCone( pAbc->pGia, pObj );
42091             sprintf( Buffer, "%s_%0*d.aig", Extra_FileNameGeneric(pAbc->pGia->pSpec), nDigits, i );
42092             Gia_AigerWrite( pOne, Buffer, 0, 0, 0 );
42093             Gia_ManStop( pOne );
42094         }
42095         printf( "Dumped all outputs into individual AIGER files.\n" );
42096         return 0;
42097     }
42098     if ( nLevelMax || nTimeWindow )
42099     {
42100         if ( nLevelMax && nTimeWindow )
42101         {
42102             Abc_Print( -1, "Abc_CommandAbc9Cone(): Parameters -L (max level) and -W (timing window) cannot be specified at the same time.\n" );
42103             return 1;
42104         }
42105         else
42106         {
42107             pTemp = Gia_ManExtractWindow( pAbc->pGia, nLevelMax, nTimeWindow, fVerbose );
42108             Abc_FrameUpdateGia( pAbc, pTemp );
42109             return 0;
42110         }
42111     }
42112     if ( iPartNum >= 0 )
42113     {
42114         Vec_Int_t * vClass;
42115         Vec_Vec_t * vClasses = (Vec_Vec_t *)pAbc->vPoEquivs;
42116         if ( vClasses == NULL )
42117         {
42118             Abc_Print( -1, "Abc_CommandAbc9Cone(): Partitions are not defined.\n" );
42119             return 1;
42120         }
42121         if ( iPartNum >= Vec_VecSize(vClasses) )
42122         {
42123             Abc_Print( -1, "Abc_CommandAbc9Cone(): Partition index exceed the array size.\n" );
42124             return 1;
42125         }
42126         vClass = Vec_VecEntryInt( vClasses, iPartNum );
42127         pTemp = Gia_ManDupCones( pAbc->pGia, Vec_IntArray(vClass), Vec_IntSize(vClass), !fUseAllCis );
42128         if ( pTemp )
42129             Abc_FrameUpdateGia( pAbc, pTemp );
42130         return 0;
42131     }
42132     if ( iOutNum < 0 || iOutNum + nOutRange > Gia_ManPoNum(pAbc->pGia) )
42133     {
42134         Abc_Print( -1, "Abc_CommandAbc9Cone(): Range of outputs to extract is incorrect.\n" );
42135         return 1;
42136     }
42137     vPos = Vec_IntStartRange( iOutNum, nOutRange );
42138     pTemp = Gia_ManDupCones( pAbc->pGia, Vec_IntArray(vPos), nOutRange, !fUseAllCis );
42139     Vec_IntFree( vPos );
42140     if ( pTemp )
42141         Abc_FrameUpdateGia( pAbc, pTemp );
42142     return 0;
42143 
42144 usage:
42145     Abc_Print( -2, "usage: &cone [-ORPLW num] [-aevh]\n" );
42146     Abc_Print( -2, "\t         extracting multi-output sequential logic cones\n" );
42147     Abc_Print( -2, "\t-O num : the index of first PO to extract [default = %d]\n", iOutNum );
42148     Abc_Print( -2, "\t-R num : (optional) the number of outputs to extract [default = %d]\n", nOutRange );
42149     Abc_Print( -2, "\t-P num : (optional) the partition number to extract [default = %d]\n", iPartNum );
42150     Abc_Print( -2, "\t-L num : (optional) extract cones with higher level [default = %d]\n", nLevelMax );
42151     Abc_Print( -2, "\t-W num : (optional) extract cones falling into this window [default = %d]\n", nTimeWindow );
42152     Abc_Print( -2, "\t-a     : toggle keeping all CIs or structral support only [default = %s]\n", fUseAllCis? "all": "structural" );
42153     Abc_Print( -2, "\t-e     : toggle writing all outputs into individual files [default = %s]\n", fExtractAll? "yes": "no" );
42154     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
42155     Abc_Print( -2, "\t-h     : print the command usage\n");
42156     return 1;
42157 }
42158 
42159 /**Function*************************************************************
42160 
42161   Synopsis    []
42162 
42163   Description []
42164 
42165   SideEffects []
42166 
42167   SeeAlso     []
42168 
42169 ***********************************************************************/
Abc_CommandAbc9Slice(Abc_Frame_t * pAbc,int argc,char ** argv)42170 int Abc_CommandAbc9Slice( Abc_Frame_t * pAbc, int argc, char ** argv )
42171 {
42172     Gia_Man_t * pTemp;
42173     int c, nSuppSize = 6, fVerbose = 0;
42174     Extra_UtilGetoptReset();
42175     while ( ( c = Extra_UtilGetopt( argc, argv, "Svh" ) ) != EOF )
42176     {
42177         switch ( c )
42178         {
42179         case 'S':
42180             if ( globalUtilOptind >= argc )
42181             {
42182                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
42183                 goto usage;
42184             }
42185             nSuppSize = atoi(argv[globalUtilOptind]);
42186             globalUtilOptind++;
42187             if ( nSuppSize < 0 )
42188                 goto usage;
42189             break;
42190         case 'v':
42191             fVerbose ^= 1;
42192             break;
42193         case 'h':
42194             goto usage;
42195         default:
42196             goto usage;
42197         }
42198     }
42199     if ( pAbc->pGia == NULL )
42200     {
42201         Abc_Print( -1, "Abc_CommandAbc9Slice(): There is no AIG.\n" );
42202         return 1;
42203     }
42204     pTemp = Gia_ManDupSliced( pAbc->pGia, nSuppSize );
42205     Abc_FrameUpdateGia( pAbc, pTemp );
42206     return 0;
42207 
42208 usage:
42209     Abc_Print( -2, "usage: &slice [-S num] [-vh]\n" );
42210     Abc_Print( -2, "\t         cuts the lower part of the AIG with nodes using their support\n" );
42211     Abc_Print( -2, "\t-S num : the largest support size to keep in the slide [default = %d]\n", nSuppSize );
42212     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
42213     Abc_Print( -2, "\t-h     : print the command usage\n");
42214     return 1;
42215 }
42216 
42217 /**Function*************************************************************
42218 
42219   Synopsis    []
42220 
42221   Description []
42222 
42223   SideEffects []
42224 
42225   SeeAlso     []
42226 
42227 ***********************************************************************/
Abc_CommandAbc9PoPart(Abc_Frame_t * pAbc,int argc,char ** argv)42228 int Abc_CommandAbc9PoPart( Abc_Frame_t * pAbc, int argc, char ** argv )
42229 {
42230     extern Gia_Man_t * Gia_ManFindPoPartition( Gia_Man_t * p, int SelectShift, int fOnlyCis, int fSetLargest, int fVerbose, Vec_Ptr_t ** pvPosEquivs );
42231     Gia_Man_t * pTemp;
42232     Vec_Ptr_t * vPosEquivs = NULL;
42233     int c, SelectShift = 0, fOnlyCis = 0, fSetLargest = 0, fVerbose = 0;
42234     Extra_UtilGetoptReset();
42235     while ( ( c = Extra_UtilGetopt( argc, argv, "Simvh" ) ) != EOF )
42236     {
42237         switch ( c )
42238         {
42239         case 'S':
42240             if ( globalUtilOptind >= argc )
42241             {
42242                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
42243                 goto usage;
42244             }
42245             SelectShift = atoi(argv[globalUtilOptind]);
42246             globalUtilOptind++;
42247             if ( SelectShift < 0 )
42248                 goto usage;
42249             break;
42250         case 'i':
42251             fOnlyCis ^= 1;
42252             break;
42253         case 'm':
42254             fSetLargest ^= 1;
42255             break;
42256         case 'v':
42257             fVerbose ^= 1;
42258             break;
42259         case 'h':
42260             goto usage;
42261         default:
42262             goto usage;
42263         }
42264     }
42265     if ( pAbc->pGia == NULL )
42266     {
42267         Abc_Print( -1, "Abc_CommandAbc9PoPart(): There is no AIG.\n" );
42268         return 1;
42269     }
42270     pTemp = Gia_ManFindPoPartition( pAbc->pGia, SelectShift, fOnlyCis, fSetLargest, fVerbose, &vPosEquivs );
42271     if ( pTemp )
42272         Abc_FrameUpdateGia( pAbc, pTemp );
42273     Abc_FrameReplacePoEquivs( pAbc, &vPosEquivs );
42274     return 0;
42275 
42276 usage:
42277     Abc_Print( -2, "usage: &popart [-S num] [-imvh]\n" );
42278     Abc_Print( -2, "\t         partitioning of POs into equivalence classes\n" );
42279     Abc_Print( -2, "\t-S num : random seed to select the set of pivot nodes [default = %d]\n", SelectShift );
42280     Abc_Print( -2, "\t       : (if the seed is 0, the nodes with max fanout counts are used)\n" );
42281     Abc_Print( -2, "\t-i     : toggle allowing only CIs to be the pivots [default = %s]\n", fOnlyCis? "yes": "no" );
42282     Abc_Print( -2, "\t-m     : toggle using the largest part as the current network [default = %s]\n", fSetLargest? "yes": "no" );
42283     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
42284     Abc_Print( -2, "\t-h     : print the command usage\n");
42285     return 1;
42286 }
42287 
42288 /**Function*************************************************************
42289 
42290   Synopsis    []
42291 
42292   Description []
42293 
42294   SideEffects []
42295 
42296   SeeAlso     []
42297 
42298 ***********************************************************************/
Abc_CommandAbc9PoPart2(Abc_Frame_t * pAbc,int argc,char ** argv)42299 int Abc_CommandAbc9PoPart2( Abc_Frame_t * pAbc, int argc, char ** argv )
42300 {
42301     extern Gia_Man_t * Gia_ManFindPoPartition2( Gia_Man_t * p, int iStartNum, int nDelta, int nOutsMin, int nOutsMax, int fSetLargest, int fVerbose, Vec_Ptr_t ** pvPosEquivs );
42302     Gia_Man_t * pTemp = NULL;
42303     Vec_Ptr_t * vPosEquivs = NULL;
42304     int c, iStartNum = 0, nDelta = 10, nOutsMin = 100, nOutsMax = 1000, fSetLargest = 0, fVerbose = 0;
42305     Extra_UtilGetoptReset();
42306     while ( ( c = Extra_UtilGetopt( argc, argv, "SDLUmvh" ) ) != EOF )
42307     {
42308         switch ( c )
42309         {
42310         case 'S':
42311             if ( globalUtilOptind >= argc )
42312             {
42313                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
42314                 goto usage;
42315             }
42316             iStartNum = atoi(argv[globalUtilOptind]);
42317             globalUtilOptind++;
42318             if ( iStartNum < 0 )
42319                 goto usage;
42320             break;
42321         case 'D':
42322             if ( globalUtilOptind >= argc )
42323             {
42324                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
42325                 goto usage;
42326             }
42327             nDelta = atoi(argv[globalUtilOptind]);
42328             globalUtilOptind++;
42329             if ( nDelta < 0 )
42330                 goto usage;
42331             break;
42332         case 'L':
42333             if ( globalUtilOptind >= argc )
42334             {
42335                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
42336                 goto usage;
42337             }
42338             nOutsMin = atoi(argv[globalUtilOptind]);
42339             globalUtilOptind++;
42340             if ( nOutsMin < 0 )
42341                 goto usage;
42342             break;
42343         case 'U':
42344             if ( globalUtilOptind >= argc )
42345             {
42346                 Abc_Print( -1, "Command line switch \"-U\" should be followed by an integer.\n" );
42347                 goto usage;
42348             }
42349             nOutsMax = atoi(argv[globalUtilOptind]);
42350             globalUtilOptind++;
42351             if ( nOutsMax < 0 )
42352                 goto usage;
42353             break;
42354         case 'm':
42355             fSetLargest ^= 1;
42356             break;
42357         case 'v':
42358             fVerbose ^= 1;
42359             break;
42360         case 'h':
42361             goto usage;
42362         default:
42363             goto usage;
42364         }
42365     }
42366     if ( pAbc->pGia == NULL )
42367     {
42368         Abc_Print( -1, "Abc_CommandAbc9PoPart(): There is no AIG.\n" );
42369         return 1;
42370     }
42371     pTemp = Gia_ManFindPoPartition2( pAbc->pGia, iStartNum, nDelta, nOutsMin, nOutsMax, fSetLargest, fVerbose, &vPosEquivs );
42372     if ( pTemp )
42373         Abc_FrameUpdateGia( pAbc, pTemp );
42374     Abc_FrameReplacePoEquivs( pAbc, &vPosEquivs );
42375     return 0;
42376 
42377 usage:
42378     Abc_Print( -2, "usage: &popart2 [-SDLU num] [-mvh]\n" );
42379     Abc_Print( -2, "\t         extracting multi-output sequential logic cones\n" );
42380     Abc_Print( -2, "\t-S num : the index of the PO to start the cluster [default = %d]\n", iStartNum );
42381     Abc_Print( -2, "\t-D num : the max increase in flop count after adding one PO [default = %d]\n", nDelta );
42382     Abc_Print( -2, "\t-L num : the minimum number of POs in a cluster [default = %d]\n", nOutsMin );
42383     Abc_Print( -2, "\t-U num : the maximum number of POs in a cluster [default = %d]\n", nOutsMax );
42384     Abc_Print( -2, "\t-m     : toggle selecting the largest cluster [default = %s]\n", fSetLargest? "yes": "no" );
42385     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
42386     Abc_Print( -2, "\t-h     : print the command usage\n");
42387     return 1;
42388 }
42389 
42390 /**Function*************************************************************
42391 
42392   Synopsis    []
42393 
42394   Description []
42395 
42396   SideEffects []
42397 
42398   SeeAlso     []
42399 
42400 ***********************************************************************/
Abc_CommandAbc9GroupProve(Abc_Frame_t * pAbc,int argc,char ** argv)42401 int Abc_CommandAbc9GroupProve( Abc_Frame_t * pAbc, int argc, char ** argv )
42402 {
42403     extern Vec_Int_t * Gia_ManGroupProve( Gia_Man_t * p, char * pCommLine, int nGroupSize, int fVerbose );
42404     Vec_Int_t * vStatus;
42405     char * pCommLine = NULL;
42406     int c, nGroupSize = 1, fVerbose = 0;
42407     Extra_UtilGetoptReset();
42408     while ( ( c = Extra_UtilGetopt( argc, argv, "GSvh" ) ) != EOF )
42409     {
42410         switch ( c )
42411         {
42412         case 'G':
42413             if ( globalUtilOptind >= argc )
42414             {
42415                 Abc_Print( -1, "Command line switch \"-G\" should be followed by an integer.\n" );
42416                 goto usage;
42417             }
42418             nGroupSize = atoi(argv[globalUtilOptind]);
42419             globalUtilOptind++;
42420             if ( nGroupSize <= 0 )
42421                 goto usage;
42422             break;
42423         case 'S':
42424             if ( globalUtilOptind >= argc )
42425             {
42426                 Abc_Print( -1, "Command line switch \"-S\" should be followed by a file name.\n" );
42427                 goto usage;
42428             }
42429             pCommLine = argv[globalUtilOptind];
42430             globalUtilOptind++;
42431         case 'v':
42432             fVerbose ^= 1;
42433             break;
42434         case 'h':
42435             goto usage;
42436         default:
42437             goto usage;
42438         }
42439     }
42440     if ( pAbc->pGia == NULL )
42441     {
42442         Abc_Print( -1, "Abc_CommandAbc9GroupProve(): There is no AIG.\n" );
42443         return 1;
42444     }
42445     if ( pCommLine == NULL )
42446     {
42447         Abc_Print( -1, "Abc_CommandAbc9GroupProve(): Command line is not given.\n" );
42448         return 1;
42449     }
42450     vStatus = Gia_ManGroupProve( pAbc->pGia, pCommLine, nGroupSize, fVerbose );
42451     Vec_IntFree( vStatus );
42452     return 0;
42453 
42454 usage:
42455     Abc_Print( -2, "usage: &gprove [-GS num] [-vh]\n" );
42456     Abc_Print( -2, "\t         proves multi-output testcase by splitting outputs into groups\n" );
42457     Abc_Print( -2, "\t         (currently, group size more than one works only for \"bmc3\" and \"pdr\")\n" );
42458     Abc_Print( -2, "\t-G num : the size of one group [default = %d]\n", nGroupSize );
42459     Abc_Print( -2, "\t-S str : the command line to be executed for each group [default = %s]\n", pCommLine ? pCommLine : "none" );
42460     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
42461     Abc_Print( -2, "\t-h     : print the command usage\n");
42462     return 1;
42463 }
42464 
42465 /**Function*************************************************************
42466 
42467   Synopsis    []
42468 
42469   Description []
42470 
42471   SideEffects []
42472 
42473   SeeAlso     []
42474 
42475 ***********************************************************************/
Abc_CommandAbc9MultiProve(Abc_Frame_t * pAbc,int argc,char ** argv)42476 int Abc_CommandAbc9MultiProve( Abc_Frame_t * pAbc, int argc, char ** argv )
42477 {
42478     extern int Gia_ManMultiProve( Gia_Man_t * p, Bmc_MulPar_t * pPars );
42479     Vec_Int_t * vStatuses; int c;
42480     Bmc_MulPar_t Pars, * pPars = &Pars;
42481     memset( pPars, 0, sizeof(Bmc_MulPar_t) );
42482     pPars->TimeOutGlo =  30;
42483     pPars->TimeOutLoc =   2;
42484     pPars->TimeOutInc = 100;
42485     pPars->TimeOutGap =   0;
42486     pPars->TimePerOut =   0;
42487     Extra_UtilGetoptReset();
42488     while ( ( c = Extra_UtilGetopt( argc, argv, "TLMGHsdvwh" ) ) != EOF )
42489     {
42490         switch ( c )
42491         {
42492         case 'T':
42493             if ( globalUtilOptind >= argc )
42494             {
42495                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
42496                 goto usage;
42497             }
42498             pPars->TimeOutGlo = atoi(argv[globalUtilOptind]);
42499             globalUtilOptind++;
42500             if ( pPars->TimeOutGlo < 0 )
42501                 goto usage;
42502             break;
42503         case 'L':
42504             if ( globalUtilOptind >= argc )
42505             {
42506                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
42507                 goto usage;
42508             }
42509             pPars->TimeOutLoc = atoi(argv[globalUtilOptind]);
42510             globalUtilOptind++;
42511             if ( pPars->TimeOutLoc <= 0 )
42512                 goto usage;
42513             break;
42514         case 'M':
42515             if ( globalUtilOptind >= argc )
42516             {
42517                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
42518                 goto usage;
42519             }
42520             pPars->TimeOutInc = atoi(argv[globalUtilOptind]);
42521             globalUtilOptind++;
42522             if ( pPars->TimeOutInc <= 0 )
42523                 goto usage;
42524             break;
42525         case 'G':
42526             if ( globalUtilOptind >= argc )
42527             {
42528                 Abc_Print( -1, "Command line switch \"-G\" should be followed by an integer.\n" );
42529                 goto usage;
42530             }
42531             pPars->TimeOutGap = atoi(argv[globalUtilOptind]);
42532             globalUtilOptind++;
42533             if ( pPars->TimeOutGap <= 0 )
42534                 goto usage;
42535             break;
42536         case 'H':
42537             if ( globalUtilOptind >= argc )
42538             {
42539                 Abc_Print( -1, "Command line switch \"-H\" should be followed by an integer.\n" );
42540                 goto usage;
42541             }
42542             pPars->TimePerOut = atoi(argv[globalUtilOptind]);
42543             globalUtilOptind++;
42544             if ( pPars->TimePerOut <= 0 )
42545                 goto usage;
42546             break;
42547         case 's':
42548             pPars->fUseSyn ^= 1;
42549             break;
42550         case 'd':
42551             pPars->fDumpFinal ^= 1;
42552             break;
42553         case 'v':
42554             pPars->fVerbose ^= 1;
42555             break;
42556         case 'w':
42557             pPars->fVeryVerbose ^= 1;
42558             break;
42559         case 'h':
42560             goto usage;
42561         default:
42562             goto usage;
42563         }
42564     }
42565     if ( pAbc->pGia == NULL )
42566     {
42567         Abc_Print( -1, "Abc_CommandAbc9MultiProve(): There is no AIG.\n" );
42568         return 1;
42569     }
42570     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
42571     {
42572         Abc_Print( -1, "Abc_CommandAbc9MultiProve(): The problem is combinational.\n" );
42573         return 1;
42574     }
42575     pAbc->Status = Gia_ManMultiProve( pAbc->pGia, pPars );
42576     vStatuses = Abc_FrameDeriveStatusArray( pAbc->pGia->vSeqModelVec );
42577     Abc_FrameReplacePoStatuses( pAbc, &vStatuses );
42578     Abc_FrameReplaceCexVec( pAbc, &pAbc->pGia->vSeqModelVec );
42579     return 0;
42580 
42581 usage:
42582     Abc_Print( -2, "usage: &mprove [-TLMGH num] [-sdvwh]\n" );
42583     Abc_Print( -2, "\t         proves multi-output testcase by applying several engines\n" );
42584     Abc_Print( -2, "\t-T num : approximate global runtime limit in seconds [default = %d]\n",     pPars->TimeOutGlo );
42585     Abc_Print( -2, "\t-L num : approximate local runtime limit in seconds [default = %d]\n",      pPars->TimeOutLoc );
42586     Abc_Print( -2, "\t-M num : percentage of local runtime limit increase [default = %d]\n",      pPars->TimeOutInc );
42587     Abc_Print( -2, "\t-G num : approximate gap runtime limit in seconds [default = %d]\n",        pPars->TimeOutGap );
42588     Abc_Print( -2, "\t-H num : timeout per output in miliseconds [default = %d]\n",               pPars->TimePerOut );
42589     Abc_Print( -2, "\t-s     : toggle using combinational synthesis [default = %s]\n",            pPars->fUseSyn?      "yes": "no" );
42590     Abc_Print( -2, "\t-d     : toggle dumping invariant into a file [default = %s]\n",            pPars->fDumpFinal?   "yes": "no" );
42591     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",             pPars->fVerbose?     "yes": "no" );
42592     Abc_Print( -2, "\t-w     : toggle printing additional verbose information [default = %s]\n",  pPars->fVeryVerbose? "yes": "no" );
42593     Abc_Print( -2, "\t-h     : print the command usage\n");
42594     return 1;
42595 }
42596 
42597 /**Function*************************************************************
42598 
42599   Synopsis    []
42600 
42601   Description []
42602 
42603   SideEffects []
42604 
42605   SeeAlso     []
42606 
42607 ***********************************************************************/
Abc_CommandAbc9SplitProve(Abc_Frame_t * pAbc,int argc,char ** argv)42608 int Abc_CommandAbc9SplitProve( Abc_Frame_t * pAbc, int argc, char ** argv )
42609 {
42610     extern int Cec_GiaSplitTest( Gia_Man_t * p, int nProcs, int nTimeOut, int nIterMax, int LookAhead, int fVerbose, int fVeryVerbose, int fSilent );
42611     int c, nProcs = 1, nTimeOut = 10, nIterMax = 0, LookAhead = 1, fVerbose = 0, fVeryVerbose = 0, fSilent = 0;
42612     Extra_UtilGetoptReset();
42613     while ( ( c = Extra_UtilGetopt( argc, argv, "PTILsvwh" ) ) != EOF )
42614     {
42615         switch ( c )
42616         {
42617         case 'P':
42618             if ( globalUtilOptind >= argc )
42619             {
42620                 Abc_Print( -1, "Command line switch \"-P\" should be followed by a positive integer.\n" );
42621                 goto usage;
42622             }
42623             nProcs = atoi(argv[globalUtilOptind]);
42624             globalUtilOptind++;
42625             if ( nProcs <= 0 )
42626                 goto usage;
42627             break;
42628         case 'T':
42629             if ( globalUtilOptind >= argc )
42630             {
42631                 Abc_Print( -1, "Command line switch \"-T\" should be followed by a positive integer.\n" );
42632                 goto usage;
42633             }
42634             nTimeOut = atoi(argv[globalUtilOptind]);
42635             globalUtilOptind++;
42636             if ( nTimeOut <= 0 )
42637                 goto usage;
42638             break;
42639         case 'I':
42640             if ( globalUtilOptind >= argc )
42641             {
42642                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
42643                 goto usage;
42644             }
42645             nIterMax = atoi(argv[globalUtilOptind]);
42646             globalUtilOptind++;
42647             if ( nIterMax < 0 )
42648                 goto usage;
42649             break;
42650         case 'L':
42651             if ( globalUtilOptind >= argc )
42652             {
42653                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
42654                 goto usage;
42655             }
42656             LookAhead = atoi(argv[globalUtilOptind]);
42657             globalUtilOptind++;
42658             if ( LookAhead <= 0 || LookAhead > 100 )
42659             {
42660                 Abc_Print( -1, "Look-ahead value (\"-L <num>\") should be between 1 and 100.\n", LookAhead );
42661                 goto usage;
42662             }
42663             break;
42664         case 's':
42665             fSilent ^= 1;
42666             break;
42667         case 'v':
42668             fVerbose ^= 1;
42669             break;
42670         case 'w':
42671             fVeryVerbose ^= 1;
42672             break;
42673         case 'h':
42674             goto usage;
42675         default:
42676             goto usage;
42677         }
42678     }
42679     if ( pAbc->pGia == NULL )
42680     {
42681         Abc_Print( -1, "Abc_CommandAbc9SplitProve(): There is no AIG.\n" );
42682         return 1;
42683     }
42684     if ( Gia_ManRegNum(pAbc->pGia) > 0 )
42685     {
42686         Abc_Print( -1, "Abc_CommandAbc9SplitProve(): The problem is sequential.\n" );
42687         return 1;
42688     }
42689     pAbc->Status = Cec_GiaSplitTest( pAbc->pGia, nProcs, nTimeOut, nIterMax, LookAhead, fVerbose, fVeryVerbose, fSilent );
42690     pAbc->pCex = pAbc->pGia->pCexComb;  pAbc->pGia->pCexComb = NULL;
42691     return 0;
42692 
42693 usage:
42694     Abc_Print( -2, "usage: &splitprove [-PTIL num] [-svwh]\n" );
42695     Abc_Print( -2, "\t         proves CEC problem by case-splitting\n" );
42696     Abc_Print( -2, "\t-P num : the number of concurrent processes [default = %d]\n",          nProcs );
42697     Abc_Print( -2, "\t-T num : runtime limit in seconds per subproblem [default = %d]\n",     nTimeOut );
42698     Abc_Print( -2, "\t-I num : the max number of iterations (0 = infinity) [default = %d]\n", nIterMax );
42699     Abc_Print( -2, "\t-L num : maximum look-ahead during cofactoring [default = %d]\n",       LookAhead );
42700     Abc_Print( -2, "\t-s     : enable silent computation (no reporting) [default = %s]\n",    fSilent? "yes": "no" );
42701     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",         fVerbose? "yes": "no" );
42702     Abc_Print( -2, "\t-w     : toggle printing more verbose information [default = %s]\n",    fVeryVerbose? "yes": "no" );
42703     Abc_Print( -2, "\t-h     : print the command usage\n");
42704     return 1;
42705 }
42706 
42707 /**Function*************************************************************
42708 
42709   Synopsis    []
42710 
42711   Description []
42712 
42713   SideEffects []
42714 
42715   SeeAlso     []
42716 
42717 ***********************************************************************/
Abc_CommandAbc9Bmc(Abc_Frame_t * pAbc,int argc,char ** argv)42718 int Abc_CommandAbc9Bmc( Abc_Frame_t * pAbc, int argc, char ** argv )
42719 {
42720     int c;
42721     Bmc_AndPar_t Pars, * pPars = &Pars;
42722     memset( pPars, 0, sizeof(Bmc_AndPar_t) );
42723     pPars->nStart        =    0;  // starting timeframe
42724     pPars->nFramesMax    =    0;  // maximum number of timeframes
42725     pPars->nFramesAdd    =   50;  // the number of additional frames
42726     pPars->nConfLimit    =    0;  // maximum number of conflicts at a node
42727     pPars->nTimeOut      =    0;  // timeout in seconds
42728     pPars->nLutSize      =    6;  // max LUT size for CNF computation
42729     pPars->nProcs        =    1;  // the number of parallel solvers
42730     pPars->fLoadCnf      =    0;  // dynamic CNF loading
42731     pPars->fDumpFrames   =    0;  // dump unrolled timeframes
42732     pPars->fUseSynth     =    0;  // use synthesis
42733     pPars->fUseOldCnf    =    0;  // use old CNF construction
42734     pPars->fVerbose      =    0;  // verbose
42735     pPars->fVeryVerbose  =    0;  // very verbose
42736     pPars->fNotVerbose   =    0;  // skip line-by-line print-out
42737     pPars->iFrame        =    0;  // explored up to this frame
42738     pPars->nFailOuts     =    0;  // the number of failed outputs
42739     pPars->nDropOuts     =    0;  // the number of dropped outputs
42740     Extra_UtilGetoptReset();
42741     while ( ( c = Extra_UtilGetopt( argc, argv, "SFATKdscvwh" ) ) != EOF )
42742     {
42743         switch ( c )
42744         {
42745         case 'S':
42746             if ( globalUtilOptind >= argc )
42747             {
42748                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
42749                 goto usage;
42750             }
42751             pPars->nStart = atoi(argv[globalUtilOptind]);
42752             globalUtilOptind++;
42753             if ( pPars->nStart < 0 )
42754                 goto usage;
42755             break;
42756         case 'F':
42757             if ( globalUtilOptind >= argc )
42758             {
42759                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
42760                 goto usage;
42761             }
42762             pPars->nFramesMax = atoi(argv[globalUtilOptind]);
42763             globalUtilOptind++;
42764             if ( pPars->nFramesMax < 0 )
42765                 goto usage;
42766             break;
42767         case 'A':
42768             if ( globalUtilOptind >= argc )
42769             {
42770                 Abc_Print( -1, "Command line switch \"-A\" should be followed by an integer.\n" );
42771                 goto usage;
42772             }
42773             pPars->nFramesAdd = atoi(argv[globalUtilOptind]);
42774             globalUtilOptind++;
42775             if ( pPars->nFramesAdd < 0 )
42776                 goto usage;
42777             break;
42778         case 'T':
42779             if ( globalUtilOptind >= argc )
42780             {
42781                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
42782                 goto usage;
42783             }
42784             pPars->nTimeOut = atoi(argv[globalUtilOptind]);
42785             globalUtilOptind++;
42786             if ( pPars->nTimeOut < 0 )
42787                 goto usage;
42788             break;
42789         case 'K':
42790             if ( globalUtilOptind >= argc )
42791             {
42792                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
42793                 goto usage;
42794             }
42795             pPars->nLutSize = atoi(argv[globalUtilOptind]);
42796             globalUtilOptind++;
42797             if ( pPars->nLutSize < 0 )
42798                 goto usage;
42799             break;
42800         case 'd':
42801             pPars->fDumpFrames ^= 1;
42802             break;
42803         case 's':
42804             pPars->fUseSynth ^= 1;
42805             break;
42806         case 'c':
42807             pPars->fUseOldCnf ^= 1;
42808             break;
42809         case 'v':
42810             pPars->fVerbose ^= 1;
42811             break;
42812         case 'w':
42813             pPars->fVeryVerbose ^= 1;
42814             break;
42815         case 'h':
42816             goto usage;
42817         default:
42818             goto usage;
42819         }
42820     }
42821     if ( pAbc->pGia == NULL )
42822     {
42823         Abc_Print( -1, "Abc_CommandAbc9Bmc(): There is no AIG.\n" );
42824         return 0;
42825     }
42826     pAbc->Status  = Gia_ManBmcPerform( pAbc->pGia, pPars );
42827     pAbc->nFrames = pPars->iFrame;
42828     Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexSeq );
42829     return 0;
42830 
42831 usage:
42832     Abc_Print( -2, "usage: &bmc [-SFATK num] [-dscvwh]\n" );
42833     Abc_Print( -2, "\t         performs bounded model checking\n" );
42834     Abc_Print( -2, "\t-S num : the starting timeframe [default = %d]\n",                      pPars->nStart );
42835     Abc_Print( -2, "\t-F num : the maximum number of timeframes [default = %d]\n",            pPars->nFramesMax );
42836     Abc_Print( -2, "\t-A num : the number of additional frames to unroll [default = %d]\n",   pPars->nFramesAdd );
42837     Abc_Print( -2, "\t-T num : approximate timeout in seconds [default = %d]\n",              pPars->nTimeOut );
42838     Abc_Print( -2, "\t-K num : the maximum cut size for CNF computation [default = %d]\n",    pPars->nLutSize );
42839     Abc_Print( -2, "\t-d     : toggle dumping unfolded timeframes [default = %s]\n",          pPars->fDumpFrames?  "yes": "no" );
42840     Abc_Print( -2, "\t-s     : toggle synthesizing unrolled timeframes [default = %s]\n",     pPars->fUseSynth?    "yes": "no" );
42841     Abc_Print( -2, "\t-c     : toggle using old CNF computation [default = %s]\n",            pPars->fUseOldCnf?   "yes": "no" );
42842     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",         pPars->fVerbose?     "yes": "no" );
42843     Abc_Print( -2, "\t-w     : toggle printing information about unfolding [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
42844     Abc_Print( -2, "\t-h     : print the command usage\n");
42845     return 1;
42846 }
42847 
42848 /**Function*************************************************************
42849 
42850   Synopsis    []
42851 
42852   Description []
42853 
42854   SideEffects []
42855 
42856   SeeAlso     []
42857 
42858 ***********************************************************************/
Abc_CommandAbc9SBmc(Abc_Frame_t * pAbc,int argc,char ** argv)42859 int Abc_CommandAbc9SBmc( Abc_Frame_t * pAbc, int argc, char ** argv )
42860 {
42861     extern int Bmcs_ManPerform( Gia_Man_t * pGia, Bmc_AndPar_t * pPars );
42862     extern int Bmcg_ManPerform( Gia_Man_t * pGia, Bmc_AndPar_t * pPars );
42863     Bmc_AndPar_t Pars, * pPars = &Pars; int c;
42864     memset( pPars, 0, sizeof(Bmc_AndPar_t) );
42865     pPars->nStart        =    0;  // starting timeframe
42866     pPars->nFramesMax    =    0;  // maximum number of timeframes
42867     pPars->nFramesAdd    =    1;  // the number of additional frames
42868     pPars->nConfLimit    =    0;  // maximum number of conflicts at a node
42869     pPars->nTimeOut      =    0;  // timeout in seconds
42870     pPars->nLutSize      =    0;  // max LUT size for CNF computation
42871     pPars->nProcs        =    1;  // the number of parallel solvers
42872     pPars->fLoadCnf      =    0;  // dynamic CNF loading
42873     pPars->fDumpFrames   =    0;  // dump unrolled timeframes
42874     pPars->fUseSynth     =    0;  // use synthesis
42875     pPars->fUseOldCnf    =    0;  // use old CNF construction
42876     pPars->fUseGlucose   =    0;  // use Glucose 3.0
42877     pPars->fUseEliminate =    0;  // use variable elimination
42878     pPars->fVerbose      =    0;  // verbose
42879     pPars->fVeryVerbose  =    0;  // very verbose
42880     pPars->fNotVerbose   =    0;  // skip line-by-line print-out
42881     pPars->iFrame        =    0;  // explored up to this frame
42882     pPars->nFailOuts     =    0;  // the number of failed outputs
42883     pPars->nDropOuts     =    0;  // the number of dropped outputs
42884     pPars->pFuncOnFrameDone = pAbc->pFuncOnFrameDone; // frame done callback
42885 
42886     Extra_UtilGetoptReset();
42887     while ( ( c = Extra_UtilGetopt( argc, argv, "PCFATgevwh" ) ) != EOF )
42888     {
42889         switch ( c )
42890         {
42891         case 'P':
42892             if ( globalUtilOptind >= argc )
42893             {
42894                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
42895                 goto usage;
42896             }
42897             pPars->nProcs = atoi(argv[globalUtilOptind]);
42898             globalUtilOptind++;
42899             if ( pPars->nProcs < 0 )
42900                 goto usage;
42901             break;
42902         case 'C':
42903             if ( globalUtilOptind >= argc )
42904             {
42905                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
42906                 goto usage;
42907             }
42908             pPars->nConfLimit = atoi(argv[globalUtilOptind]);
42909             globalUtilOptind++;
42910             if ( pPars->nConfLimit < 0 )
42911                 goto usage;
42912             break;
42913         case 'F':
42914             if ( globalUtilOptind >= argc )
42915             {
42916                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
42917                 goto usage;
42918             }
42919             pPars->nFramesMax = atoi(argv[globalUtilOptind]);
42920             globalUtilOptind++;
42921             if ( pPars->nFramesMax < 0 )
42922                 goto usage;
42923             break;
42924         case 'A':
42925             if ( globalUtilOptind >= argc )
42926             {
42927                 Abc_Print( -1, "Command line switch \"-A\" should be followed by an integer.\n" );
42928                 goto usage;
42929             }
42930             pPars->nFramesAdd = atoi(argv[globalUtilOptind]);
42931             globalUtilOptind++;
42932             if ( pPars->nFramesAdd < 0 )
42933                 goto usage;
42934             break;
42935         case 'T':
42936             if ( globalUtilOptind >= argc )
42937             {
42938                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
42939                 goto usage;
42940             }
42941             pPars->nTimeOut = atoi(argv[globalUtilOptind]);
42942             globalUtilOptind++;
42943             if ( pPars->nTimeOut < 0 )
42944                 goto usage;
42945             break;
42946         case 'g':
42947             pPars->fUseGlucose ^= 1;
42948             break;
42949         case 'e':
42950             pPars->fUseEliminate ^= 1;
42951             break;
42952         case 'v':
42953             pPars->fVerbose ^= 1;
42954             break;
42955         case 'w':
42956             pPars->fVeryVerbose ^= 1;
42957             break;
42958         case 'h':
42959             goto usage;
42960         default:
42961             goto usage;
42962         }
42963     }
42964     if ( pAbc->pGia == NULL )
42965     {
42966         Abc_Print( -1, "Abc_CommandAbc9Bmcs(): There is no AIG.\n" );
42967         return 0;
42968     }
42969     if ( pPars->nProcs > 4 )
42970     {
42971         Abc_Print( -1, "Abc_CommandAbc9Bmcs(): Currently this command can run at most 4 concurrent solvers.\n" );
42972         return 0;
42973     }
42974     pAbc->Status  = pPars->fUseGlucose ? Bmcg_ManPerform(pAbc->pGia, pPars) : Bmcs_ManPerform(pAbc->pGia, pPars);
42975     pAbc->nFrames = pPars->iFrame;
42976     Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexSeq );
42977     return 0;
42978 
42979 usage:
42980     Abc_Print( -2, "usage: &bmcs [-PCFAT num] [-gevwh]\n" );
42981     Abc_Print( -2, "\t         performs bounded model checking\n" );
42982     Abc_Print( -2, "\t-P num : the number of parallel solvers [default = %d]\n",              pPars->nProcs );
42983     Abc_Print( -2, "\t-C num : the SAT solver conflict limit [default = %d]\n",               pPars->nConfLimit );
42984     Abc_Print( -2, "\t-F num : the maximum number of timeframes [default = %d]\n",            pPars->nFramesMax );
42985     Abc_Print( -2, "\t-A num : the number of additional frames to unroll [default = %d]\n",   pPars->nFramesAdd );
42986     Abc_Print( -2, "\t-T num : approximate timeout in seconds [default = %d]\n",              pPars->nTimeOut );
42987     Abc_Print( -2, "\t-g     : toggle using Glucose 3.0 by Gilles Audemard and Laurent Simon [default = %s]\n", pPars->fUseGlucose?  "Glucose" : "Satoko" );
42988     Abc_Print( -2, "\t-e     : toggle using variable eliminatation [default = %s]\n",         pPars->fUseEliminate?"yes": "no" );
42989     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",         pPars->fVerbose?     "yes": "no" );
42990     Abc_Print( -2, "\t-w     : toggle printing information about unfolding [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
42991     Abc_Print( -2, "\t-h     : print the command usage\n");
42992     return 1;
42993 }
42994 
42995 /**Function*************************************************************
42996 
42997   Synopsis    []
42998 
42999   Description []
43000 
43001   SideEffects []
43002 
43003   SeeAlso     []
43004 
43005 ***********************************************************************/
Abc_CommandAbc9ChainBmc(Abc_Frame_t * pAbc,int argc,char ** argv)43006 int Abc_CommandAbc9ChainBmc( Abc_Frame_t * pAbc, int argc, char ** argv )
43007 {
43008     extern int Bmc_ChainTest( Gia_Man_t * p, int nFrameMax, int nConfMax, int fVerbose, int fVeryVerbose, Vec_Ptr_t ** pvCexes );
43009     Vec_Ptr_t * vCexes = NULL;
43010     int nFrameMax    =  200;
43011     int nConfMax     =    0;
43012     int fVerbose     =    0;
43013     int fVeryVerbose =    0;
43014     int c;
43015     Extra_UtilGetoptReset();
43016     while ( ( c = Extra_UtilGetopt( argc, argv, "FCvwh" ) ) != EOF )
43017     {
43018         switch ( c )
43019         {
43020         case 'F':
43021             if ( globalUtilOptind >= argc )
43022             {
43023                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
43024                 goto usage;
43025             }
43026             nFrameMax = atoi(argv[globalUtilOptind]);
43027             globalUtilOptind++;
43028             if ( nFrameMax < 0 )
43029                 goto usage;
43030             break;
43031         case 'C':
43032             if ( globalUtilOptind >= argc )
43033             {
43034                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
43035                 goto usage;
43036             }
43037             nConfMax = atoi(argv[globalUtilOptind]);
43038             globalUtilOptind++;
43039             if ( nConfMax < 0 )
43040                 goto usage;
43041             break;
43042         case 'v':
43043             fVerbose ^= 1;
43044             break;
43045         case 'w':
43046             fVeryVerbose ^= 1;
43047             break;
43048         case 'h':
43049             goto usage;
43050         default:
43051             goto usage;
43052         }
43053     }
43054     if ( pAbc->pGia == NULL )
43055     {
43056         Abc_Print( -1, "Abc_CommandAbc9ChainBmc(): There is no AIG.\n" );
43057         return 0;
43058     }
43059     if ( !Gia_ManRegNum(pAbc->pGia) )
43060     {
43061         Abc_Print( -1, "Abc_CommandAbc9ChainBmc(): The AIG is combinational.\n" );
43062         return 0;
43063     }
43064     Bmc_ChainTest( pAbc->pGia, nFrameMax, nConfMax, fVerbose, fVeryVerbose, &vCexes );
43065     if ( vCexes ) Vec_PtrFreeFree( vCexes );
43066     //pAbc->Status  = ...;
43067     //pAbc->nFrames = pPars->iFrame;
43068     //Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexSeq );
43069     return 0;
43070 usage:
43071     Abc_Print( -2, "usage: &chainbmc [-FC <num>] [-vwh]\n" );
43072     Abc_Print( -2, "\t           runs a specialized flavor of BMC\n" );
43073     Abc_Print( -2, "\t-F <num> : the max number of timeframes (0 = unused) [default = %d]\n", nFrameMax );
43074     Abc_Print( -2, "\t-C <num> : the max number of conflicts (0 = unused) [default = %d]\n", nConfMax );
43075     Abc_Print( -2, "\t-v       : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
43076     Abc_Print( -2, "\t-w       : toggle printing even more information [default = %s]\n", fVeryVerbose? "yes": "no" );
43077     Abc_Print( -2, "\t-h       : print the command usage\n");
43078     return 1;
43079 }
43080 
43081 /**Function*************************************************************
43082 
43083   Synopsis    []
43084 
43085   Description []
43086 
43087   SideEffects []
43088 
43089   SeeAlso     []
43090 
43091 ***********************************************************************/
Abc_CommandAbc9BCore(Abc_Frame_t * pAbc,int argc,char ** argv)43092 int Abc_CommandAbc9BCore( Abc_Frame_t * pAbc, int argc, char ** argv )
43093 {
43094     int c;
43095     Bmc_BCorePar_t Pars, * pPars = &Pars;
43096     memset( pPars, 0, sizeof(Bmc_BCorePar_t) );
43097     pPars->iFrame        =   10;  // timeframe
43098     pPars->iOutput       =    0;  // property output
43099     pPars->nTimeOut      =    0;  // timeout in seconds
43100     pPars->pFilePivots   = NULL;  // file name with AIG IDs of pivot objects
43101     pPars->pFileProof    = NULL;  // file name to write the resulting proof
43102     pPars->fVerbose      =    0;  // verbose output
43103     Extra_UtilGetoptReset();
43104     while ( ( c = Extra_UtilGetopt( argc, argv, "FOTVvh" ) ) != EOF )
43105     {
43106         switch ( c )
43107         {
43108         case 'F':
43109             if ( globalUtilOptind >= argc )
43110             {
43111                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
43112                 goto usage;
43113             }
43114             pPars->iFrame = atoi(argv[globalUtilOptind]);
43115             globalUtilOptind++;
43116             if ( pPars->iFrame < 0 )
43117                 goto usage;
43118             break;
43119         case 'O':
43120             if ( globalUtilOptind >= argc )
43121             {
43122                 Abc_Print( -1, "Command line switch \"-O\" should be followed by an integer.\n" );
43123                 goto usage;
43124             }
43125             pPars->iOutput = atoi(argv[globalUtilOptind]);
43126             globalUtilOptind++;
43127             if ( pPars->iOutput < 0 )
43128                 goto usage;
43129             break;
43130         case 'T':
43131             if ( globalUtilOptind >= argc )
43132             {
43133                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
43134                 goto usage;
43135             }
43136             pPars->nTimeOut = atoi(argv[globalUtilOptind]);
43137             globalUtilOptind++;
43138             if ( pPars->nTimeOut < 0 )
43139                 goto usage;
43140             break;
43141         case 'V':
43142             if ( globalUtilOptind >= argc )
43143             {
43144                 Abc_Print( -1, "Command line switch \"-V\" should be followed by a file name.\n" );
43145                 goto usage;
43146             }
43147             pPars->pFilePivots = argv[globalUtilOptind];
43148             globalUtilOptind++;
43149             break;
43150         case 'v':
43151             pPars->fVerbose ^= 1;
43152             break;
43153         case 'h':
43154             goto usage;
43155         default:
43156             goto usage;
43157         }
43158     }
43159     if ( pAbc->pGia == NULL )
43160     {
43161         Abc_Print( -1, "Abc_CommandAbc9BCore(): There is no AIG.\n" );
43162         return 0;
43163     }
43164     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
43165     {
43166         Abc_Print( -1, "Abc_CommandAbc9BCore(): AIG has no registers.\n" );
43167         return 0;
43168     }
43169     // get the file name
43170     if ( pPars->pFilePivots != NULL )
43171     {
43172         FILE * pFile;
43173         pFile = fopen( pPars->pFilePivots, "r" );
43174         if ( pFile == NULL )
43175         {
43176             Abc_Print( -1, "Abc_CommandAbc9BCore(): Cannot open file \"%s\" with pivot node IDs.\n", pPars->pFilePivots );
43177             return 0;
43178         }
43179         fclose( pFile );
43180     }
43181     // get the file name
43182     if ( argc == globalUtilOptind + 1 )
43183     {
43184         FILE * pFile;
43185         pPars->pFileProof = argv[globalUtilOptind];
43186         pFile = fopen( pPars->pFileProof, "wb" );
43187         if ( pFile == NULL )
43188         {
43189             Abc_Print( -1, "Abc_CommandAbc9BCore(): Cannot open file \"%s\" for writing the proof.\n", pPars->pFileProof );
43190             return 0;
43191         }
43192         fclose( pFile );
43193     }
43194     Bmc_ManBCorePerform( pAbc->pGia, pPars );
43195     return 0;
43196 
43197 usage:
43198     Abc_Print( -2, "usage: &bcore [-FOTV num] [-vh] <file>\n" );
43199     Abc_Print( -2, "\t         records UNSAT core of the BMC instance\n" );
43200     Abc_Print( -2, "\t-F num : the zero-based index of a timeframe [default = %d]\n",         pPars->iFrame );
43201     Abc_Print( -2, "\t-O num : the zero-based index of a primary output [default = %d]\n",    pPars->iOutput );
43202     Abc_Print( -2, "\t-T num : approximate timeout in seconds [default = %d]\n",              pPars->nTimeOut );
43203     Abc_Print( -2, "\t-V file: file name with AIG IDs of pivot variables [default = no pivots]\n" );
43204     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",         pPars->fVerbose?     "yes": "no" );
43205     Abc_Print( -2, "\t-h     : print the command usage\n");
43206     Abc_Print( -2, "\t<file> : file name to write the resulting proof [default = stdout]\n");
43207     return 1;
43208 }
43209 
43210 /**Function*************************************************************
43211 
43212   Synopsis    []
43213 
43214   Description []
43215 
43216   SideEffects []
43217 
43218   SeeAlso     []
43219 
43220 ***********************************************************************/
Abc_CommandAbc9ICheck(Abc_Frame_t * pAbc,int argc,char ** argv)43221 int Abc_CommandAbc9ICheck( Abc_Frame_t * pAbc, int argc, char ** argv )
43222 {
43223     int c, nFramesMax = 1, nTimeOut = 0, fEmpty = 0, fSearch = 1, fReverse = 0, fBackTopo = 0, fDump = 0, fVerbose = 0;
43224     Extra_UtilGetoptReset();
43225     while ( ( c = Extra_UtilGetopt( argc, argv, "MTesrbdvh" ) ) != EOF )
43226     {
43227         switch ( c )
43228         {
43229         case 'M':
43230             if ( globalUtilOptind >= argc )
43231             {
43232                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
43233                 goto usage;
43234             }
43235             nFramesMax = atoi(argv[globalUtilOptind]);
43236             globalUtilOptind++;
43237             if ( nFramesMax <= 0 )
43238                 goto usage;
43239             break;
43240         case 'T':
43241             if ( globalUtilOptind >= argc )
43242             {
43243                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
43244                 goto usage;
43245             }
43246             nTimeOut = atoi(argv[globalUtilOptind]);
43247             globalUtilOptind++;
43248             if ( nTimeOut < 0 )
43249                 goto usage;
43250             break;
43251         case 'e':
43252             fEmpty ^= 1;
43253             break;
43254         case 's':
43255             fSearch ^= 1;
43256             break;
43257         case 'r':
43258             fReverse ^= 1;
43259             break;
43260         case 'b':
43261             fBackTopo ^= 1;
43262             break;
43263         case 'd':
43264             fDump ^= 1;
43265             break;
43266         case 'v':
43267             fVerbose ^= 1;
43268             break;
43269         case 'h':
43270             goto usage;
43271         default:
43272             goto usage;
43273         }
43274     }
43275     if ( pAbc->pGia == NULL )
43276     {
43277         Abc_Print( -1, "Abc_CommandAbc9ICheck(): There is no AIG.\n" );
43278         return 0;
43279     }
43280     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
43281     {
43282         Abc_Print( -1, "Abc_CommandAbc9ICheck(): The AIG is combinational.\n" );
43283         return 0;
43284     }
43285     Vec_IntFreeP( &pAbc->vIndFlops );
43286     if ( fSearch )
43287         pAbc->vIndFlops = Bmc_PerformISearch( pAbc->pGia, nFramesMax, nTimeOut, fReverse, fBackTopo, fDump, fVerbose );
43288     else
43289         Bmc_PerformICheck( pAbc->pGia, nFramesMax, nTimeOut, fEmpty, fVerbose );
43290     pAbc->nIndFrames = pAbc->vIndFlops ? nFramesMax : 0;
43291     return 0;
43292 
43293 usage:
43294     Abc_Print( -2, "usage: &icheck [-MT num] [-esrbdvh]\n" );
43295     Abc_Print( -2, "\t         performs specialized induction check\n" );
43296     Abc_Print( -2, "\t-M num : the number of timeframes used for induction [default = %d]\n",    nFramesMax );
43297     Abc_Print( -2, "\t-T num : approximate global runtime limit in seconds [default = %d]\n",    nTimeOut );
43298     Abc_Print( -2, "\t-e     : toggle using empty set of next-state functions [default = %s]\n", fEmpty? "yes": "no" );
43299     Abc_Print( -2, "\t-s     : toggle searching for a minimal subset [default = %s]\n",          fSearch? "yes": "no" );
43300     Abc_Print( -2, "\t-r     : toggle searching in the reverse order [default = %s]\n",          fReverse? "yes": "no" );
43301     Abc_Print( -2, "\t-b     : toggle searching in backward order from POs [default = %s]\n",    fBackTopo? "yes": "no" );
43302     Abc_Print( -2, "\t-d     : toggle printing out the resulting set [default = %s]\n",          fDump? "yes": "no" );
43303     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n",            fVerbose? "yes": "no" );
43304     Abc_Print( -2, "\t-h     : print the command usage\n");
43305     return 1;
43306 }
43307 
43308 /**Function*************************************************************
43309 
43310   Synopsis    []
43311 
43312   Description []
43313 
43314   SideEffects []
43315 
43316   SeeAlso     []
43317 
43318 ***********************************************************************/
Abc_CommandAbc9SatTest(Abc_Frame_t * pAbc,int argc,char ** argv)43319 int Abc_CommandAbc9SatTest( Abc_Frame_t * pAbc, int argc, char ** argv )
43320 {
43321     extern void Bmc_LoadTest( Gia_Man_t * pGia, int fLoadCnf, int fVerbose );
43322     int c, fLoadCnf = 0, fVerbose = 0;
43323     Extra_UtilGetoptReset();
43324     while ( ( c = Extra_UtilGetopt( argc, argv, "cvh" ) ) != EOF )
43325     {
43326         switch ( c )
43327         {
43328         case 'c':
43329             fLoadCnf ^= 1;
43330             break;
43331         case 'v':
43332             fVerbose ^= 1;
43333             break;
43334         case 'h':
43335             goto usage;
43336         default:
43337             goto usage;
43338         }
43339     }
43340     if ( pAbc->pGia == NULL )
43341     {
43342         Abc_Print( -1, "Abc_CommandAbc9SatTest(): There is no AIG.\n" );
43343         return 0;
43344     }
43345     Bmc_LoadTest( pAbc->pGia, fLoadCnf, fVerbose );
43346     return 0;
43347 
43348 usage:
43349     Abc_Print( -2, "usage: &sattest [-cvh]\n" );
43350     Abc_Print( -2, "\t         performs testing of dynamic CNF loading\n" );
43351     Abc_Print( -2, "\t-c     : toggle dynamic CNF loading [default = %s]\n",          fLoadCnf? "yes": "no" );
43352     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
43353     Abc_Print( -2, "\t-h     : print the command usage\n");
43354     return 1;
43355 }
43356 
43357 /**Function*************************************************************
43358 
43359   Synopsis    []
43360 
43361   Description []
43362 
43363   SideEffects []
43364 
43365   SeeAlso     []
43366 
43367 ***********************************************************************/
Abc_CommandAbc9FFTest(Abc_Frame_t * pAbc,int argc,char ** argv)43368 int Abc_CommandAbc9FFTest( Abc_Frame_t * pAbc, int argc, char ** argv )
43369 {
43370     extern void Gia_ParFfSetDefault( Bmc_ParFf_t * p );
43371     extern void Gia_ManFaultTest( Gia_Man_t * p, Gia_Man_t * pG, Bmc_ParFf_t * pPars );
43372     Bmc_ParFf_t Pars, * pPars = &Pars;
43373     char * pFileName = NULL, * pFileName2 = NULL;
43374     Gia_Man_t * pGold = NULL;
43375     int c;
43376     Gia_ParFfSetDefault( pPars );
43377     Extra_UtilGetoptReset();
43378     while ( ( c = Extra_UtilGetopt( argc, argv, "ATNKSGFkbsfcdeunvh" ) ) != EOF )
43379     {
43380         switch ( c )
43381         {
43382         case 'A':
43383             if ( globalUtilOptind >= argc )
43384             {
43385                 Abc_Print( -1, "Command line switch \"-A\" should be followed by an integer.\n" );
43386                 goto usage;
43387             }
43388             pPars->Algo = atoi(argv[globalUtilOptind]);
43389             globalUtilOptind++;
43390             if ( pPars->Algo < 0 || pPars->Algo > 4 )
43391                 goto usage;
43392             break;
43393         case 'T':
43394             if ( globalUtilOptind >= argc )
43395             {
43396                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
43397                 goto usage;
43398             }
43399             pPars->nTimeOut = atoi(argv[globalUtilOptind]);
43400             globalUtilOptind++;
43401             if ( pPars->nTimeOut < 0 )
43402                 goto usage;
43403             break;
43404         case 'N':
43405             if ( globalUtilOptind >= argc )
43406             {
43407                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
43408                 goto usage;
43409             }
43410             pPars->nIterCheck = atoi(argv[globalUtilOptind]);
43411             globalUtilOptind++;
43412             if ( pPars->nIterCheck < 0 )
43413                 goto usage;
43414             break;
43415         case 'K':
43416             if ( globalUtilOptind >= argc )
43417             {
43418                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
43419                 goto usage;
43420             }
43421             pPars->nCardConstr = atoi(argv[globalUtilOptind]);
43422             globalUtilOptind++;
43423             if ( pPars->nCardConstr <= 0 )
43424                 goto usage;
43425             break;
43426         case 'S':
43427             if ( globalUtilOptind >= argc )
43428             {
43429                 Abc_Print( -1, "Command line switch \"-S\" should be followed by a string.\n" );
43430                 goto usage;
43431             }
43432             pPars->pFormStr = argv[globalUtilOptind];
43433             globalUtilOptind++;
43434             break;
43435         case 'F':
43436             if ( globalUtilOptind >= argc )
43437             {
43438                 Abc_Print( -1, "Command line switch \"-F\" should be followed by a file name.\n" );
43439                 goto usage;
43440             }
43441             pFileName2 = argv[globalUtilOptind];
43442             globalUtilOptind++;
43443             break;
43444         case 'G':
43445             if ( globalUtilOptind >= argc )
43446             {
43447                 Abc_Print( -1, "Command line switch \"-G\" should be followed by a file name.\n" );
43448                 goto usage;
43449             }
43450             pFileName = argv[globalUtilOptind];
43451             globalUtilOptind++;
43452             break;
43453         case 'k':
43454             pPars->fNonStrict ^= 1;
43455             break;
43456         case 'b':
43457             pPars->fBasic ^= 1;
43458             break;
43459         case 's':
43460             pPars->fStartPats ^= 1;
43461             break;
43462         case 'f':
43463             pPars->fFfOnly ^= 1;
43464             break;
43465         case 'c':
43466             pPars->fCheckUntest ^= 1;
43467             break;
43468         case 'd':
43469             pPars->fDump ^= 1;
43470             break;
43471         case 'e':
43472             pPars->fDumpDelay ^= 1;
43473             break;
43474         case 'u':
43475             pPars->fDumpUntest ^= 1;
43476             break;
43477         case 'n':
43478             pPars->fDumpNewFaults ^= 1;
43479             break;
43480         case 'v':
43481             pPars->fVerbose ^= 1;
43482             break;
43483         case 'h':
43484             goto usage;
43485         default:
43486             goto usage;
43487         }
43488     }
43489     // read string from file
43490     if ( pFileName2 )
43491     {
43492         if ( !strcmp( Extra_FileNameExtension(pFileName2), "blif" ) )
43493         {
43494             extern char * Gia_DeriveFormula( Gia_Man_t * pGia, char ** ppNamesIn );
43495             Abc_Ntk_t * pNtk2 = Io_Read( pFileName2, Io_ReadFileType(pFileName2), 1, 0 );
43496             Abc_Ntk_t * pNtk3 = Abc_NtkStrash( pNtk2, 0, 0, 0 );
43497             Gia_Man_t * pGia  = Abc_NtkClpGia( pNtk3 );
43498             char ** ppNamesIn = Abc_NtkCollectCioNames( pNtk2, 0 );
43499             if ( Gia_ManCoNum(pGia) == 1 )
43500                 pPars->pFormStr = Gia_DeriveFormula( pGia, ppNamesIn );
43501             else
43502                 printf( "The formula BLIF file contains the network with more one output.\n" );
43503             ABC_FREE( ppNamesIn );
43504             Gia_ManStop( pGia );
43505             Abc_NtkDelete( pNtk2 );
43506             Abc_NtkDelete( pNtk3 );
43507             if ( pPars->pFormStr == NULL )
43508                 goto usage;
43509         }
43510         else
43511         {
43512             FILE * pFile = fopen( pFileName2, "r" );
43513             if ( pFile == NULL )
43514             {
43515                 Abc_Print( -1, "Abc_CommandAbc9FFTest(): File name \"%s\" with formula is invalid.\n", pFileName2 );
43516                 return 0;
43517             }
43518             pPars->pFormStr = Extra_FileRead(pFile);
43519             fclose( pFile );
43520             // skip spaces
43521             while ( 1 )
43522             {
43523                 int Len = strlen(pPars->pFormStr);
43524                 char Char = pPars->pFormStr[Len-1];
43525                 if ( Char == ' ' || Char == '\n' || Char == '\r' || Char == '\t' || Char == -51 )
43526                     pPars->pFormStr[Len-1] = '\0';
43527                 else
43528                     break;
43529             }
43530         }
43531         printf( "Using formula \"%s\" from file \"%s\".\n", pPars->pFormStr, pFileName2 );
43532     }
43533     if ( pPars->Algo == 0 && pPars->pFormStr == NULL )
43534     {
43535         Abc_Print( -1, "Formula string (-S <str>) should be selected when algorithm is 0 (-A 0).\n" );
43536         return 0;
43537     }
43538     if ( pPars->Algo != 0 && pPars->pFormStr != NULL )
43539     {
43540         Abc_Print( -1, "Algorithm should be 0 (-A 0) when formula string is selected (-S <str>).\n" );
43541         return 0;
43542     }
43543     // get the file name
43544     if ( argc == globalUtilOptind + 1 )
43545     {
43546         FILE * pFile;
43547         pPars->pFileName = argv[globalUtilOptind];
43548         pFile = fopen( pPars->pFileName, "r" );
43549         if ( pFile == NULL )
43550         {
43551             Abc_Print( -1, "Cannot open file \"%s\" with the input test patterns.\n", pPars->pFileName );
43552             return 0;
43553         }
43554         fclose( pFile );
43555     }
43556     // check other conditions
43557     if ( pAbc->pGia == NULL )
43558     {
43559         Abc_Print( -1, "Abc_CommandAbc9FFTest(): There is no AIG.\n" );
43560         return 0;
43561     }
43562     if ( Gia_ManRegNum(pAbc->pGia) == 0 && pPars->Algo == 1 )
43563     {
43564         Abc_Print( -1, "Abc_CommandAbc9FFTest(): For delay testing, AIG should be sequential.\n" );
43565         return 0;
43566     }
43567     // check if the file is valid
43568     if ( pFileName )
43569     {
43570         FILE * pFile = fopen( pFileName, "r" );
43571         if ( pFile == NULL )
43572         {
43573             Abc_Print( -1, "Abc_CommandAbc9FFTest(): File name \"%s\" with golden model is invalid.\n", pFileName );
43574             return 0;
43575         }
43576         fclose( pFile );
43577         pGold = Gia_AigerRead( pFileName, 0, 0, 0 );
43578         if ( pGold == NULL )
43579         {
43580             Abc_Print( -1, "Abc_CommandAbc9FFTest(): Cannot read file \"%s\" with golden model.\n", pFileName );
43581             return 0;
43582         }
43583         if ( Gia_ManPiNum(pAbc->pGia) != Gia_ManPiNum(pGold) )
43584         {
43585             Gia_ManStop( pGold );
43586             Abc_Print( -1, "Abc_CommandAbc9FFTest(): Old model and gold model have different number of PIs.\n" );
43587             return 0;
43588         }
43589         if ( Gia_ManPoNum(pAbc->pGia) != Gia_ManPoNum(pGold) )
43590         {
43591             Gia_ManStop( pGold );
43592             Abc_Print( -1, "Abc_CommandAbc9FFTest(): Old model and gold model have different number of POs.\n" );
43593             return 0;
43594         }
43595         printf( "Entered spec AIG from file \"%s\".\n", pFileName );
43596     }
43597     Gia_ManFaultTest( pAbc->pGia, pGold ? pGold : pAbc->pGia, pPars );
43598     Gia_ManStopP( &pGold );
43599     if ( pFileName2 )
43600         ABC_FREE( pPars->pFormStr );
43601     return 0;
43602 
43603 usage:
43604     Abc_Print( -2, "usage: &fftest [-ATNK num] [-kbsfcdeunvh] <file> [-GF file] [-S str]\n" );
43605     Abc_Print( -2, "\t          performs functional fault test generation\n" );
43606     Abc_Print( -2, "\t-A num  : selects fault model for all gates [default = %d]\n", pPars->Algo );
43607     Abc_Print( -2, "\t                0: fault model is not selected (use -S str)\n" );
43608     Abc_Print( -2, "\t                1: delay fault testing for sequential circuits\n" );
43609     Abc_Print( -2, "\t                2: traditional stuck-at fault: -S (((a&b)&~p)|q)\n" );
43610     Abc_Print( -2, "\t                3: complement fault: -S ((a&b)^p)\n" );
43611     Abc_Print( -2, "\t                4: functionally observable fault\n" );
43612     Abc_Print( -2, "\t-T num  : specifies approximate runtime limit in seconds [default = %d]\n",        pPars->nTimeOut );
43613     Abc_Print( -2, "\t-N num  : specifies iteration to check for fixed parameters [default = %d]\n",     pPars->nIterCheck );
43614     Abc_Print( -2, "\t-K num  : specifies cardinality constraint (num > 0) [default = unused]\n" );
43615     Abc_Print( -2, "\t-k      : toggles non-strict cardinality (n <= K, instead of n == K) [default = %s]\n",pPars->fNonStrict?  "yes": "no" );
43616     Abc_Print( -2, "\t-b      : toggles testing for single faults (the same as \"-K 1\") [default = %s]\n", pPars->fBasic?      "yes": "no" );
43617     Abc_Print( -2, "\t-s      : toggles starting with the all-0 and all-1 patterns [default = %s]\n",    pPars->fStartPats?  "yes": "no" );
43618     Abc_Print( -2, "\t-f      : toggles faults at flop inputs only with \"-A 1\" and \"-S str\" [default = %s]\n",          pPars->fFfOnly?     "yes": "no" );
43619     Abc_Print( -2, "\t-c      : toggles checking if there are untestable faults [default = %s]\n",       pPars->fCheckUntest? "yes": "no" );
43620     Abc_Print( -2, "\t-d      : toggles dumping test patterns into file \"<file>_tests.txt\" [default = %s]\n", pPars->fDump?       "yes": "no" );
43621     Abc_Print( -2, "\t-e      : toggles dumping test pattern pairs (delay faults only) [default = %s]\n", pPars->fDumpDelay? "yes": "no" );
43622     Abc_Print( -2, "\t-u      : toggles dumping untestable faults into \"<file>_untest.txt\" [default = %s]\n", pPars->fDumpUntest? "yes": "no" );
43623     Abc_Print( -2, "\t-n      : toggles dumping faults not detected by a given test set [default = %s]\n", pPars->fDumpNewFaults? "yes": "no" );
43624     Abc_Print( -2, "\t-v      : toggles printing verbose information [default = %s]\n",                  pPars->fVerbose?    "yes": "no" );
43625     Abc_Print( -2, "\t-h      : print the command usage\n");
43626     Abc_Print( -2, "\t<file>  : (optional) file name with input test patterns\n\n");
43627     Abc_Print( -2, "\t-G file : (optional) file name with the golden model\n\n");
43628     Abc_Print( -2, "\t-F file : (optional) file name with the fault model in BLIF format\n");
43629     Abc_Print( -2, "\t-S str  : (optional) string representing the fault model\n");
43630     Abc_Print( -2, "\t          The following notations are used:\n");
43631     Abc_Print( -2, "\t            Functional variables: {a,b} (both a and b are always present)\n");
43632     Abc_Print( -2, "\t            Parameter variables: {p,q,r,s,t,u,v,w} (any number from 1 to 8)\n");
43633     Abc_Print( -2, "\t            Boolean operators: AND(&), OR(|), XOR(^), MUX(?:), NOT(~)\n");
43634     Abc_Print( -2, "\t            Parentheses should be used around each operator. Spaces not allowed.\n");
43635     Abc_Print( -2, "\t            Complement (~) is only allowed before variables (use DeMorgan law).\n");
43636     Abc_Print( -2, "\t            Examples:\n");
43637     Abc_Print( -2, "\t              (((a&b)&~p)|q)        stuck-at-0/1 at the output\n");
43638     Abc_Print( -2, "\t              (((a&~p)|q)&b)        stuck-at-0/1 at input a\n");
43639     Abc_Print( -2, "\t              (((a|p)&(b|q))&~r)    stuck-at-1 at the inputs and stuck-at-0 at the output\n");
43640     Abc_Print( -2, "\t              (((a&~p)&(b&~q))|r)   stuck-at-0 at the inputs and stuck-at-1 at the output\n");
43641     Abc_Print( -2, "\t              ((a&b)^p)             complement at the output\n");
43642     Abc_Print( -2, "\t              (((a^p)&(b^q))^r)     complement at the inputs and at the output\n");
43643     Abc_Print( -2, "\t              (a?(b?~s:r):(b?q:p))  functionally observable fault at the output\n");
43644     Abc_Print( -2, "\t              (p?(a|b):(a&b))       replace AND by OR\n");
43645     Abc_Print( -2, "\t           If the BLIF file is used for the formula with option \'-F\', following rules apply:\n");
43646     Abc_Print( -2, "\t              - the network should be combinational and have exactly one primary output\n");
43647     Abc_Print( -2, "\t              - input names should have only one character:\n");
43648     Abc_Print( -2, "\t                {a, b} (for functional variables)\n");
43649     Abc_Print( -2, "\t                {p,q,r,s,t,u,v,w} (for parameter variables)\n");
43650     return 1;
43651 }
43652 
43653 /**Function*************************************************************
43654 
43655   Synopsis    []
43656 
43657   Description []
43658 
43659   SideEffects []
43660 
43661   SeeAlso     []
43662 
43663 ***********************************************************************/
Abc_CommandAbc9Qbf(Abc_Frame_t * pAbc,int argc,char ** argv)43664 int Abc_CommandAbc9Qbf( Abc_Frame_t * pAbc, int argc, char ** argv )
43665 {
43666     extern void Gia_QbfDumpFile( Gia_Man_t * pGia, int nPars );
43667     extern int Gia_QbfSolve( Gia_Man_t * pGia, int nPars, int nIterLimit, int nConfLimit, int nTimeOut, int fGlucose, int fVerbose );
43668     int c, nPars   = -1;
43669     int nIterLimit =  0;
43670     int nConfLimit =  0;
43671     int nTimeOut   =  0;
43672     int fDumpCnf   =  0;
43673     int fGlucose   =  0;
43674     int fVerbose   =  0;
43675     Extra_UtilGetoptReset();
43676     while ( ( c = Extra_UtilGetopt( argc, argv, "PICTdgvh" ) ) != EOF )
43677     {
43678         switch ( c )
43679         {
43680         case 'P':
43681             if ( globalUtilOptind >= argc )
43682             {
43683                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
43684                 goto usage;
43685             }
43686             nPars = atoi(argv[globalUtilOptind]);
43687             globalUtilOptind++;
43688             if ( nPars < 0 )
43689                 goto usage;
43690             break;
43691         case 'I':
43692             if ( globalUtilOptind >= argc )
43693             {
43694                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
43695                 goto usage;
43696             }
43697             nIterLimit = atoi(argv[globalUtilOptind]);
43698             globalUtilOptind++;
43699             if ( nIterLimit < 0 )
43700                 goto usage;
43701             break;
43702         case 'C':
43703             if ( globalUtilOptind >= argc )
43704             {
43705                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
43706                 goto usage;
43707             }
43708             nConfLimit = atoi(argv[globalUtilOptind]);
43709             globalUtilOptind++;
43710             if ( nConfLimit < 0 )
43711                 goto usage;
43712             break;
43713         case 'T':
43714             if ( globalUtilOptind >= argc )
43715             {
43716                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
43717                 goto usage;
43718             }
43719             nTimeOut = atoi(argv[globalUtilOptind]);
43720             globalUtilOptind++;
43721             if ( nTimeOut < 0 )
43722                 goto usage;
43723             break;
43724         case 'd':
43725             fDumpCnf ^= 1;
43726             break;
43727         case 'g':
43728             fGlucose ^= 1;
43729             break;
43730         case 'v':
43731             fVerbose ^= 1;
43732             break;
43733         case 'h':
43734             goto usage;
43735         default:
43736             goto usage;
43737         }
43738     }
43739     if ( pAbc->pGia == NULL )
43740     {
43741         Abc_Print( -1, "There is no current GIA.\n" );
43742         return 1;
43743     }
43744     if ( Gia_ManRegNum(pAbc->pGia) )
43745     {
43746         Abc_Print( -1, "Works only for combinational networks.\n" );
43747         return 1;
43748     }
43749     if ( Gia_ManPoNum(pAbc->pGia) != 1 )
43750     {
43751         Abc_Print( -1, "The miter should have one primary output.\n" );
43752         return 1;
43753     }
43754     if ( !(nPars > 0 && nPars < Gia_ManPiNum(pAbc->pGia)) )
43755     {
43756         Abc_Print( -1, "The number of parameter variables is invalid (should be > 0 and < PI num).\n" );
43757         return 1;
43758     }
43759     if ( fDumpCnf )
43760         Gia_QbfDumpFile( pAbc->pGia, nPars );
43761     else
43762         Gia_QbfSolve( pAbc->pGia, nPars, nIterLimit, nConfLimit, nTimeOut, fGlucose, fVerbose );
43763     return 0;
43764 
43765 usage:
43766     Abc_Print( -2, "usage: &qbf [-PICT num] [-dgvh]\n" );
43767     Abc_Print( -2, "\t         solves QBF problem EpVxM(p,x)\n" );
43768     Abc_Print( -2, "\t-P num : number of parameters p (should be the first PIs) [default = %d]\n", nPars );
43769     Abc_Print( -2, "\t-I num : quit after the given iteration even if unsolved [default = %d]\n", nIterLimit );
43770     Abc_Print( -2, "\t-C num : conflict limit per problem [default = %d]\n", nConfLimit );
43771     Abc_Print( -2, "\t-T num : global timeout [default = %d]\n", nTimeOut );
43772     Abc_Print( -2, "\t-d     : toggle dumping QDIMACS file instead of solving [default = %s]\n", fDumpCnf? "yes": "no" );
43773     Abc_Print( -2, "\t-g     : toggle using Glucose 3.0 by Gilles Audemard and Laurent Simon [default = %s]\n", fGlucose? "yes": "no" );
43774     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
43775     Abc_Print( -2, "\t-h     : print the command usage\n");
43776     return 1;
43777 }
43778 
43779 /**Function*************************************************************
43780 
43781   Synopsis    []
43782 
43783   Description []
43784 
43785   SideEffects []
43786 
43787   SeeAlso     []
43788 
43789 ***********************************************************************/
Abc_CommandAbc9QVar(Abc_Frame_t * pAbc,int argc,char ** argv)43790 int Abc_CommandAbc9QVar( Abc_Frame_t * pAbc, int argc, char ** argv )
43791 {
43792     extern Gia_Man_t * Gia_QbfQuantifyAll( Gia_Man_t * p, int nPars, int fAndAll, int fOrAll );
43793     Gia_Man_t * pTemp;
43794     int c, nPars   = -1;
43795     int fQuantU    =  0;
43796     int fQuantE    =  0;
43797     int fVerbose   =  0;
43798     Extra_UtilGetoptReset();
43799     while ( ( c = Extra_UtilGetopt( argc, argv, "Puevh" ) ) != EOF )
43800     {
43801         switch ( c )
43802         {
43803         case 'P':
43804             if ( globalUtilOptind >= argc )
43805             {
43806                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
43807                 goto usage;
43808             }
43809             nPars = atoi(argv[globalUtilOptind]);
43810             globalUtilOptind++;
43811             if ( nPars < 0 )
43812                 goto usage;
43813             break;
43814         case 'u':
43815             fQuantU ^= 1;
43816             break;
43817         case 'e':
43818             fQuantE ^= 1;
43819             break;
43820         case 'v':
43821             fVerbose ^= 1;
43822             break;
43823         case 'h':
43824             goto usage;
43825         default:
43826             goto usage;
43827         }
43828     }
43829     if ( pAbc->pGia == NULL )
43830     {
43831         Abc_Print( -1, "There is no current GIA.\n" );
43832         return 1;
43833     }
43834     if ( Gia_ManRegNum(pAbc->pGia) )
43835     {
43836         Abc_Print( -1, "Works only for combinational networks.\n" );
43837         return 1;
43838     }
43839     if ( !(nPars > 0 && nPars < Gia_ManPiNum(pAbc->pGia)) )
43840     {
43841         Abc_Print( -1, "The number of parameter variables is invalid (should be > 0 and < PI num).\n" );
43842         return 1;
43843     }
43844     pTemp = Gia_QbfQuantifyAll( pAbc->pGia, nPars, fQuantU, fQuantE );
43845     Abc_FrameUpdateGia( pAbc, pTemp );
43846     return 0;
43847 
43848 usage:
43849     Abc_Print( -2, "usage: &qvar [-P num] [-uevh]\n" );
43850     Abc_Print( -2, "\t         derives cofactors w.r.t. the last NumPi-<num> variables\n" );
43851     Abc_Print( -2, "\t-P num : number of parameters p (should be the first PIs) [default = %d]\n", nPars );
43852     Abc_Print( -2, "\t-u     : toggle ANDing cofactors (universal quantification) [default = %s]\n", fQuantU? "yes": "no" );
43853     Abc_Print( -2, "\t-e     : toggle ORing cofactors (existential quantification) [default = %s]\n", fQuantE? "yes": "no" );
43854     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
43855     Abc_Print( -2, "\t-h     : print the command usage\n");
43856     return 1;
43857 }
43858 
43859 /**Function*************************************************************
43860 
43861   Synopsis    []
43862 
43863   Description []
43864 
43865   SideEffects []
43866 
43867   SeeAlso     []
43868 
43869 ***********************************************************************/
Abc_CommandAbc9GenQbf(Abc_Frame_t * pAbc,int argc,char ** argv)43870 int Abc_CommandAbc9GenQbf( Abc_Frame_t * pAbc, int argc, char ** argv )
43871 {
43872     extern Gia_Man_t * Gia_GenQbfMiter( Gia_Man_t * pGia, int nFrames, int nLutNum, int nLutSize, char * pStr, int fUseOut, int fVerbose );
43873     int nFrames   =    1;
43874     int nLutNum   =    1;
43875     int nLutSize  =    6;
43876     char * pStr   = NULL;
43877     int fUseOut   =    0;
43878     int fVerbose  =    0;
43879     int c;
43880     Gia_Man_t * pTemp;
43881     Extra_UtilGetoptReset();
43882     while ( ( c = Extra_UtilGetopt( argc, argv, "FKNSovh" ) ) != EOF )
43883     {
43884         switch ( c )
43885         {
43886         case 'F':
43887             if ( globalUtilOptind >= argc )
43888             {
43889                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
43890                 goto usage;
43891             }
43892             nFrames = atoi(argv[globalUtilOptind]);
43893             globalUtilOptind++;
43894             if ( nFrames < 0 )
43895                 goto usage;
43896             break;
43897         case 'K':
43898             if ( globalUtilOptind >= argc )
43899             {
43900                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
43901                 goto usage;
43902             }
43903             nLutSize = atoi(argv[globalUtilOptind]);
43904             globalUtilOptind++;
43905             if ( nLutSize < 0 )
43906                 goto usage;
43907             break;
43908         case 'N':
43909             if ( globalUtilOptind >= argc )
43910             {
43911                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
43912                 goto usage;
43913             }
43914             nLutNum = atoi(argv[globalUtilOptind]);
43915             globalUtilOptind++;
43916             if ( nLutNum < 0 )
43917                 goto usage;
43918             break;
43919         case 'S':
43920             if ( globalUtilOptind >= argc )
43921             {
43922                 Abc_Print( -1, "Command line switch \"-S\" should be followed by a string.\n" );
43923                 goto usage;
43924             }
43925             pStr = Abc_UtilStrsav(argv[globalUtilOptind]);
43926             globalUtilOptind++;
43927             if ( pStr == NULL )
43928                 goto usage;
43929             break;
43930         case 'o':
43931             fUseOut ^= 1;
43932             break;
43933         case 'v':
43934             fVerbose ^= 1;
43935             break;
43936         case 'h':
43937             goto usage;
43938         default:
43939             goto usage;
43940         }
43941     }
43942     if ( pAbc->pGia == NULL )
43943     {
43944         Abc_Print( -1, "There is no current GIA.\n" );
43945         return 1;
43946     }
43947     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
43948     {
43949         Abc_Print( -1, "Works only for sequential networks.\n" );
43950         return 1;
43951     }
43952     if ( Gia_ManRegNum(pAbc->pGia) < nLutSize * nLutNum )
43953     {
43954         Abc_Print( -1, "The number of flops (%d) is less than required (%d).\n", Gia_ManRegNum(pAbc->pGia), nLutSize * nLutNum );
43955         return 1;
43956     }
43957     if ( nFrames != 1 || nLutNum != 1 )
43958     {
43959         Abc_Print( -1, "Currently this commands works for one frame and one LUT.\n" );
43960         return 1;
43961     }
43962     pTemp = Gia_GenQbfMiter( pAbc->pGia, nFrames, nLutNum, nLutSize, pStr, fUseOut, fVerbose );
43963     Abc_FrameUpdateGia( pAbc, pTemp );
43964     ABC_FREE( pStr );
43965     return 0;
43966 
43967 usage:
43968     Abc_Print( -2, "usage: &genqbf [-FKN num] [-ovh]\n" );
43969     Abc_Print( -2, "\t         generates QBF miter for computing an inductive invariant\n" );
43970     Abc_Print( -2, "\t-F num : the number of time frames for induction [default = %d]\n", nFrames );
43971     Abc_Print( -2, "\t-K num : the LUT size [default = %d]\n", nLutSize );
43972     Abc_Print( -2, "\t-N num : the number of LUTs [default = %d]\n", nLutNum );
43973     Abc_Print( -2, "\t-o     : toggle using the last output [default = %s]\n", fUseOut? "yes": "no" );
43974     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", fVerbose? "yes": "no" );
43975     Abc_Print( -2, "\t-h     : print the command usage\n");
43976     return 1;
43977 }
43978 
43979 /**Function*************************************************************
43980 
43981   Synopsis    []
43982 
43983   Description []
43984 
43985   SideEffects []
43986 
43987   SeeAlso     []
43988 
43989 ***********************************************************************/
Abc_CommandAbc9SatFx(Abc_Frame_t * pAbc,int argc,char ** argv)43990 int Abc_CommandAbc9SatFx( Abc_Frame_t * pAbc, int argc, char ** argv )
43991 {
43992     extern int Bmc_FxCompute( Gia_Man_t * p );
43993     extern int Bmc_FxComputeOne( Gia_Man_t * p, int nIterMax, int nDiv2Add );
43994     int nIterMax =  5;
43995     int nDiv2Add = 10;
43996     int c, fDec  =  1;
43997     int fVerbose =  0;
43998     Extra_UtilGetoptReset();
43999     while ( ( c = Extra_UtilGetopt( argc, argv, "IDdvh" ) ) != EOF )
44000     {
44001         switch ( c )
44002         {
44003         case 'I':
44004             if ( globalUtilOptind >= argc )
44005             {
44006                 Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" );
44007                 goto usage;
44008             }
44009             nIterMax = atoi(argv[globalUtilOptind]);
44010             globalUtilOptind++;
44011             if ( nIterMax < 0 )
44012                 goto usage;
44013             break;
44014         case 'D':
44015             if ( globalUtilOptind >= argc )
44016             {
44017                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
44018                 goto usage;
44019             }
44020             nDiv2Add = atoi(argv[globalUtilOptind]);
44021             globalUtilOptind++;
44022             if ( nDiv2Add < 0 )
44023                 goto usage;
44024             break;
44025         case 'd':
44026             fDec ^= 1;
44027             break;
44028         case 'v':
44029             fVerbose ^= 1;
44030             break;
44031         case 'h':
44032             goto usage;
44033         default:
44034             goto usage;
44035         }
44036     }
44037     if ( pAbc->pGia == NULL )
44038     {
44039         Abc_Print( -1, "Abc_CommandAbc9SatFx(): There is no AIG.\n" );
44040         return 0;
44041     }
44042     if ( fDec )
44043         Bmc_FxComputeOne( pAbc->pGia, nIterMax, nDiv2Add );
44044     else
44045         Bmc_FxCompute( pAbc->pGia );
44046     return 0;
44047 
44048 usage:
44049     Abc_Print( -2, "usage: &satfx [-ID num] [-dvh]\n" );
44050     Abc_Print( -2, "\t         performs SAT based shared logic extraction\n" );
44051     Abc_Print( -2, "\t-I num : the number of iterations of divisor extraction [default = %d]\n", nIterMax );
44052     Abc_Print( -2, "\t-D num : the number of divisors to extract in each iteration [default = %d]\n", nDiv2Add );
44053     Abc_Print( -2, "\t-d     : toggles decomposing the first output [default = %s]\n", fDec? "yes": "no" );
44054     Abc_Print( -2, "\t-v     : toggles printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
44055     Abc_Print( -2, "\t-h     : print the command usage\n");
44056     return 1;
44057 }
44058 
44059 /**Function*************************************************************
44060 
44061   Synopsis    []
44062 
44063   Description []
44064 
44065   SideEffects []
44066 
44067   SeeAlso     []
44068 
44069 ***********************************************************************/
Abc_CommandAbc9SatClp(Abc_Frame_t * pAbc,int argc,char ** argv)44070 int Abc_CommandAbc9SatClp( Abc_Frame_t * pAbc, int argc, char ** argv )
44071 {
44072     extern Vec_Str_t * Bmc_CollapseOne( Gia_Man_t * p, int nCubeLim, int nBTLimit, int fCanon, int fReverse, int fVerbose );
44073     int nCubeLim = 1000;
44074     int nBTLimit = 1000000;
44075     int fCanon   = 0;
44076     int fVerbose = 0;
44077     int c;
44078 
44079     Vec_Str_t * vSop;
44080     Extra_UtilGetoptReset();
44081     while ( ( c = Extra_UtilGetopt( argc, argv, "CLcvh" ) ) != EOF )
44082     {
44083         switch ( c )
44084         {
44085         case 'C':
44086             if ( globalUtilOptind >= argc )
44087             {
44088                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
44089                 goto usage;
44090             }
44091             nCubeLim = atoi(argv[globalUtilOptind]);
44092             globalUtilOptind++;
44093             if ( nCubeLim < 0 )
44094                 goto usage;
44095             break;
44096         case 'L':
44097             if ( globalUtilOptind >= argc )
44098             {
44099                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
44100                 goto usage;
44101             }
44102             nBTLimit = atoi(argv[globalUtilOptind]);
44103             globalUtilOptind++;
44104             if ( nBTLimit < 0 )
44105                 goto usage;
44106             break;
44107         case 'c':
44108             fCanon ^= 1;
44109             break;
44110         case 'v':
44111             fVerbose ^= 1;
44112             break;
44113         case 'h':
44114             goto usage;
44115         default:
44116             goto usage;
44117         }
44118     }
44119     if ( pAbc->pGia == NULL )
44120     {
44121         Abc_Print( -1, "Abc_CommandAbc9SatClp(): There is no AIG.\n" );
44122         return 0;
44123     }
44124     vSop = Bmc_CollapseOne( pAbc->pGia, nCubeLim, nBTLimit, fCanon, 0, fVerbose );
44125     Vec_StrFree( vSop );
44126     return 0;
44127 
44128 usage:
44129     Abc_Print( -2, "usage: &satclp [-CL num] [-cvh]\n" );
44130     Abc_Print( -2, "\t         performs SAT based collapsing\n" );
44131     Abc_Print( -2, "\t-C num : the limit on the SOP size of one output [default = %d]\n", nCubeLim );
44132     Abc_Print( -2, "\t-L num : the limit on the number of conflicts in one SAT call [default = %d]\n", nBTLimit );
44133     Abc_Print( -2, "\t-c     : toggles using canonical ISOP computation [default = %s]\n", fCanon? "yes": "no" );
44134     Abc_Print( -2, "\t-v     : toggles printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
44135     Abc_Print( -2, "\t-h     : print the command usage\n");
44136     return 1;
44137 }
44138 
44139 
44140 /**Function*************************************************************
44141 
44142   Synopsis    []
44143 
44144   Description []
44145 
44146   SideEffects []
44147 
44148   SeeAlso     []
44149 
44150 ***********************************************************************/
Abc_CommandAbc9Inse(Abc_Frame_t * pAbc,int argc,char ** argv)44151 int Abc_CommandAbc9Inse( Abc_Frame_t * pAbc, int argc, char ** argv )
44152 {
44153     extern Vec_Int_t * Gia_ManInseTest( Gia_Man_t * p, Vec_Int_t * vInit, int nFrames, int nWords, int nTimeOut, int fSim, int fVerbose );
44154     int c, nFrames = 10, nWords = 1000, nTimeOut = 0, fSim = 0, fVerbose = 0;
44155     Extra_UtilGetoptReset();
44156     while ( ( c = Extra_UtilGetopt( argc, argv, "FWTsvh" ) ) != EOF )
44157     {
44158         switch ( c )
44159         {
44160         case 'F':
44161             if ( globalUtilOptind >= argc )
44162             {
44163                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
44164                 goto usage;
44165             }
44166             nFrames = atoi(argv[globalUtilOptind]);
44167             globalUtilOptind++;
44168             if ( nFrames < 0 )
44169                 goto usage;
44170             break;
44171         case 'W':
44172             if ( globalUtilOptind >= argc )
44173             {
44174                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
44175                 goto usage;
44176             }
44177             nWords = atoi(argv[globalUtilOptind]);
44178             globalUtilOptind++;
44179             if ( nWords < 0 )
44180                 goto usage;
44181             break;
44182         case 'T':
44183             if ( globalUtilOptind >= argc )
44184             {
44185                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
44186                 goto usage;
44187             }
44188             nTimeOut = atoi(argv[globalUtilOptind]);
44189             globalUtilOptind++;
44190             if ( nTimeOut < 0 )
44191                 goto usage;
44192             break;
44193         case 's':
44194             fSim ^= 1;
44195             break;
44196         case 'v':
44197             fVerbose ^= 1;
44198             break;
44199         case 'h':
44200             goto usage;
44201         default:
44202             goto usage;
44203         }
44204     }
44205     if ( pAbc->pGia == NULL )
44206     {
44207         Abc_Print( -1, "Abc_CommandAbc9Inse(): There is no AIG.\n" );
44208         return 0;
44209     }
44210     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
44211     {
44212         Abc_Print( -1, "Abc_CommandAbc9Inse(): AIG is combinational.\n" );
44213         return 0;
44214     }
44215     if ( pAbc->pGia->vInitClasses != NULL )
44216     {
44217         Abc_Print( 1, "Abc_CommandAbc9Inse(): All-0 initial state is assumed.\n" );
44218         Vec_IntFreeP( &pAbc->pGia->vInitClasses );
44219     }
44220     pAbc->pGia->vInitClasses = Gia_ManInseTest( pAbc->pGia, NULL, nFrames, nWords, nTimeOut, fSim, fVerbose );
44221     return 0;
44222 
44223 usage:
44224     Abc_Print( -2, "usage: &inse [-FWT num] [-svh]\n" );
44225     Abc_Print( -2, "\t         experimental procedure\n" );
44226     Abc_Print( -2, "\t-F num : the number of timeframes [default = %d]\n",                    nFrames );
44227     Abc_Print( -2, "\t-W num : the number of machine words [default = %d]\n",                 nWords );
44228     Abc_Print( -2, "\t-T num : approximate global runtime limit in seconds [default = %d]\n", nTimeOut );
44229     Abc_Print( -2, "\t-s     : toggles using ternary simulation [default = %s]\n",            fSim?     "yes": "no" );
44230     Abc_Print( -2, "\t-v     : toggles printing verbose information [default = %s]\n",        fVerbose? "yes": "no" );
44231     Abc_Print( -2, "\t-h     : print the command usage\n");
44232     return 1;
44233 }
44234 
44235 /**Function*************************************************************
44236 
44237   Synopsis    []
44238 
44239   Description []
44240 
44241   SideEffects []
44242 
44243   SeeAlso     []
44244 
44245 ***********************************************************************/
Abc_CommandAbc9Maxi(Abc_Frame_t * pAbc,int argc,char ** argv)44246 int Abc_CommandAbc9Maxi( Abc_Frame_t * pAbc, int argc, char ** argv )
44247 {
44248     extern Vec_Int_t * Gia_ManMaxiTest( Gia_Man_t * p, Vec_Int_t * vInit, int nFrames, int nWords, int nTimeOut, int fSim, int fVerbose );
44249     Vec_Int_t * vTemp;
44250     int c, nFrames = 5, nWords = 1000, nTimeOut = 0, fSim = 0, fVerbose = 0;
44251     Extra_UtilGetoptReset();
44252     while ( ( c = Extra_UtilGetopt( argc, argv, "FWTsvh" ) ) != EOF )
44253     {
44254         switch ( c )
44255         {
44256         case 'F':
44257             if ( globalUtilOptind >= argc )
44258             {
44259                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
44260                 goto usage;
44261             }
44262             nFrames = atoi(argv[globalUtilOptind]);
44263             globalUtilOptind++;
44264             if ( nFrames < 0 )
44265                 goto usage;
44266             break;
44267         case 'W':
44268             if ( globalUtilOptind >= argc )
44269             {
44270                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
44271                 goto usage;
44272             }
44273             nWords = atoi(argv[globalUtilOptind]);
44274             globalUtilOptind++;
44275             if ( nWords < 0 )
44276                 goto usage;
44277             break;
44278         case 'T':
44279             if ( globalUtilOptind >= argc )
44280             {
44281                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
44282                 goto usage;
44283             }
44284             nTimeOut = atoi(argv[globalUtilOptind]);
44285             globalUtilOptind++;
44286             if ( nTimeOut < 0 )
44287                 goto usage;
44288             break;
44289         case 's':
44290             fSim ^= 1;
44291             break;
44292         case 'v':
44293             fVerbose ^= 1;
44294             break;
44295         case 'h':
44296             goto usage;
44297         default:
44298             goto usage;
44299         }
44300     }
44301     if ( pAbc->pGia == NULL )
44302     {
44303         Abc_Print( -1, "Abc_CommandAbc9Maxi(): There is no AIG.\n" );
44304         return 0;
44305     }
44306     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
44307     {
44308         Abc_Print( -1, "Abc_CommandAbc9Maxi(): AIG is combinational.\n" );
44309         return 0;
44310     }
44311     pAbc->pGia->vInitClasses = Gia_ManMaxiTest( pAbc->pGia, vTemp = pAbc->pGia->vInitClasses, nFrames, nWords, nTimeOut, fSim, fVerbose );
44312     Vec_IntFreeP( &vTemp );
44313     return 0;
44314 
44315 usage:
44316     Abc_Print( -2, "usage: &maxi [-FWT num] [-svh]\n" );
44317     Abc_Print( -2, "\t         experimental procedure\n" );
44318     Abc_Print( -2, "\t-F num : the number of timeframes [default = %d]\n",                    nFrames );
44319     Abc_Print( -2, "\t-W num : the number of machine words [default = %d]\n",                 nWords );
44320     Abc_Print( -2, "\t-T num : approximate global runtime limit in seconds [default = %d]\n", nTimeOut );
44321     Abc_Print( -2, "\t-s     : toggles using ternary simulation [default = %s]\n",            fSim?     "yes": "no" );
44322     Abc_Print( -2, "\t-v     : toggles printing verbose information [default = %s]\n",        fVerbose? "yes": "no" );
44323     Abc_Print( -2, "\t-h     : print the command usage\n");
44324     return 1;
44325 }
44326 
44327 /**Function*************************************************************
44328 
44329   Synopsis    []
44330 
44331   Description []
44332 
44333   SideEffects []
44334 
44335   SeeAlso     []
44336 
44337 ***********************************************************************/
Abc_CommandAbc9Bmci(Abc_Frame_t * pAbc,int argc,char ** argv)44338 int Abc_CommandAbc9Bmci( Abc_Frame_t * pAbc, int argc, char ** argv )
44339 {
44340     extern int Gia_ManBmciTest( Gia_Man_t * p, Vec_Int_t * vInit, int nFrames, int nWords, int nTimeOut, int fSim, int fVerbose );
44341     int c, nFrames = 1000, nWords = 1000, nTimeOut = 0, fSim = 0, fVerbose = 0;
44342     Extra_UtilGetoptReset();
44343     while ( ( c = Extra_UtilGetopt( argc, argv, "FWTsvh" ) ) != EOF )
44344     {
44345         switch ( c )
44346         {
44347         case 'F':
44348             if ( globalUtilOptind >= argc )
44349             {
44350                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
44351                 goto usage;
44352             }
44353             nFrames = atoi(argv[globalUtilOptind]);
44354             globalUtilOptind++;
44355             if ( nFrames < 0 )
44356                 goto usage;
44357             break;
44358         case 'W':
44359             if ( globalUtilOptind >= argc )
44360             {
44361                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
44362                 goto usage;
44363             }
44364             nWords = atoi(argv[globalUtilOptind]);
44365             globalUtilOptind++;
44366             if ( nWords < 0 )
44367                 goto usage;
44368             break;
44369         case 'T':
44370             if ( globalUtilOptind >= argc )
44371             {
44372                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
44373                 goto usage;
44374             }
44375             nTimeOut = atoi(argv[globalUtilOptind]);
44376             globalUtilOptind++;
44377             if ( nTimeOut < 0 )
44378                 goto usage;
44379             break;
44380         case 's':
44381             fSim ^= 1;
44382             break;
44383         case 'v':
44384             fVerbose ^= 1;
44385             break;
44386         case 'h':
44387             goto usage;
44388         default:
44389             goto usage;
44390         }
44391     }
44392     if ( pAbc->pGia == NULL )
44393     {
44394         Abc_Print( -1, "Abc_CommandAbc9Bmci(): There is no AIG.\n" );
44395         return 0;
44396     }
44397     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
44398     {
44399         Abc_Print( -1, "Abc_CommandAbc9Bmci(): AIG is combinational.\n" );
44400         return 0;
44401     }
44402     if ( pAbc->pGia->vInitClasses == NULL )
44403     {
44404         Abc_Print( -1, "Abc_CommandAbc9Bmci(): Init array is not given.\n" );
44405         return 0;
44406     }
44407     Gia_ManBmciTest( pAbc->pGia, pAbc->pGia->vInitClasses, nFrames, nWords, nTimeOut, fSim, fVerbose );
44408     return 0;
44409 
44410 usage:
44411     Abc_Print( -2, "usage: &bmci [-FWT num] [-svh]\n" );
44412     Abc_Print( -2, "\t         experimental procedure\n" );
44413     Abc_Print( -2, "\t-F num : the number of timeframes [default = %d]\n",                    nFrames );
44414     Abc_Print( -2, "\t-W num : the number of machine words [default = %d]\n",                 nWords );
44415     Abc_Print( -2, "\t-T num : approximate global runtime limit in seconds [default = %d]\n", nTimeOut );
44416     Abc_Print( -2, "\t-s     : toggles using ternary simulation [default = %s]\n",            fSim?     "yes": "no" );
44417     Abc_Print( -2, "\t-v     : toggles printing verbose information [default = %s]\n",        fVerbose? "yes": "no" );
44418     Abc_Print( -2, "\t-h     : print the command usage\n");
44419     return 1;
44420 }
44421 
44422 /**Function*************************************************************
44423 
44424   Synopsis    []
44425 
44426   Description []
44427 
44428   SideEffects []
44429 
44430   SeeAlso     []
44431 
44432 ***********************************************************************/
Abc_CommandAbc9PoXsim(Abc_Frame_t * pAbc,int argc,char ** argv)44433 int Abc_CommandAbc9PoXsim( Abc_Frame_t * pAbc, int argc, char ** argv )
44434 {
44435     extern Vec_Int_t * Gia_ManPoXSim( Gia_Man_t * p, int nFrames, int fVerbose );
44436     int c, nFrames = 1000, fVerbose = 0;
44437     Extra_UtilGetoptReset();
44438     while ( ( c = Extra_UtilGetopt( argc, argv, "Fvh" ) ) != EOF )
44439     {
44440         switch ( c )
44441         {
44442         case 'F':
44443             if ( globalUtilOptind >= argc )
44444             {
44445                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
44446                 goto usage;
44447             }
44448             nFrames = atoi(argv[globalUtilOptind]);
44449             globalUtilOptind++;
44450             if ( nFrames < 0 )
44451                 goto usage;
44452             break;
44453         case 'v':
44454             fVerbose ^= 1;
44455             break;
44456         case 'h':
44457             goto usage;
44458         default:
44459             goto usage;
44460         }
44461     }
44462     if ( pAbc->pGia == NULL )
44463     {
44464         Abc_Print( -1, "Abc_CommandAbc9Bmci(): There is no AIG.\n" );
44465         return 0;
44466     }
44467     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
44468     {
44469         Abc_Print( -1, "Abc_CommandAbc9Bmci(): AIG is combinational.\n" );
44470         return 0;
44471     }
44472     Vec_IntFreeP( &pAbc->vAbcObjIds );
44473     pAbc->vAbcObjIds = Gia_ManPoXSim( pAbc->pGia, nFrames, fVerbose );
44474     return 0;
44475 
44476 usage:
44477     Abc_Print( -2, "usage: &poxsim [-F num] [-vh]\n" );
44478     Abc_Print( -2, "\t         X-valued simulation of the multi-output sequential miter\n" );
44479     Abc_Print( -2, "\t-F num : the number of timeframes [default = %d]\n",                    nFrames );
44480     Abc_Print( -2, "\t-v     : toggles printing verbose information [default = %s]\n",        fVerbose? "yes": "no" );
44481     Abc_Print( -2, "\t-h     : print the command usage\n");
44482     return 1;
44483 }
44484 
44485 /**Function*************************************************************
44486 
44487   Synopsis    []
44488 
44489   Description []
44490 
44491   SideEffects []
44492 
44493   SeeAlso     []
44494 
44495 ***********************************************************************/
Abc_CommandAbc9Demiter(Abc_Frame_t * pAbc,int argc,char ** argv)44496 int Abc_CommandAbc9Demiter( Abc_Frame_t * pAbc, int argc, char ** argv )
44497 {
44498     Gia_Man_t * pTemp;
44499     int c, fDumpFiles = 0, fDumpFilesTwo = 0, fDual = 0, fVerbose = 0;
44500     Extra_UtilGetoptReset();
44501     while ( ( c = Extra_UtilGetopt( argc, argv, "ftdvh" ) ) != EOF )
44502     {
44503         switch ( c )
44504         {
44505         case 'f':
44506             fDumpFiles ^= 1;
44507             break;
44508         case 't':
44509             fDumpFilesTwo ^= 1;
44510             break;
44511         case 'd':
44512             fDual ^= 1;
44513             break;
44514         case 'v':
44515             fVerbose ^= 1;
44516             break;
44517         case 'h':
44518             goto usage;
44519         default:
44520             goto usage;
44521         }
44522     }
44523     if ( pAbc->pGia == NULL )
44524     {
44525         Abc_Print( -1, "Abc_CommandAbc9Demiter(): There is no AIG.\n" );
44526         return 0;
44527     }
44528     if ( fDumpFiles || fDumpFilesTwo )
44529     {
44530         char pName0[1000] = "miter_part0.aig";
44531         char pName1[1000] = "miter_part1.aig";
44532         Gia_Man_t * pPart1, * pPart2;
44533         if ( Gia_ManPoNum(pAbc->pGia) % 2 != 0 )
44534         {
44535             Abc_Print( -1, "Abc_CommandAbc9Demiter(): Does not look like a dual-output miter.\n" );
44536             return 0;
44537         }
44538         if ( fDumpFilesTwo )
44539             Gia_ManDemiterTwoWords( pAbc->pGia, &pPart1, &pPart2 );
44540         else
44541             Gia_ManDemiterDual( pAbc->pGia, &pPart1, &pPart2 );
44542         if ( pAbc->pGia->pSpec )
44543         {
44544             char * pGen = Extra_FileNameGeneric(pAbc->pGia->pSpec);
44545             sprintf( pName0, "%s_1.aig", pGen );
44546             sprintf( pName1, "%s_2.aig", pGen );
44547             ABC_FREE( pGen );
44548         }
44549         Gia_AigerWrite( pPart1, pName0, 0, 0, 0 );
44550         Gia_AigerWrite( pPart2, pName1, 0, 0, 0 );
44551         Gia_ManStop( pPart1 );
44552         Gia_ManStop( pPart2 );
44553         if ( fDumpFilesTwo )
44554             printf( "Two parts of the two-word miter are dumped into files \"%s\" and \"%s\".\n", pName0, pName1 );
44555         else
44556             printf( "Two parts of the dual-output miter are dumped into files \"%s\" and \"%s\".\n", pName0, pName1 );
44557         return 0;
44558     }
44559     if ( Gia_ManPoNum(pAbc->pGia) != 1 )
44560     {
44561         Abc_Print( -1, "Abc_CommandAbc9Demiter(): Miter should have one output.\n" );
44562         return 0;
44563     }
44564     if ( fDual )
44565         pTemp = Gia_ManDemiterToDual( pAbc->pGia );
44566     else
44567         pTemp = Gia_ManDupDemiter( pAbc->pGia, fVerbose );
44568     Abc_FrameUpdateGia( pAbc, pTemp );
44569     if ( fVerbose )
44570         Gia_ManPrintStatsMiter( pTemp, 0 );
44571     return 0;
44572 
44573 usage:
44574     Abc_Print( -2, "usage: &demiter [-ftdvh]\n" );
44575     Abc_Print( -2, "\t         decomposes a miter (by default, tries to extract an OR gate)\n" );
44576     Abc_Print( -2, "\t-f     : write files with two sides of a dual-output miter [default = %s]\n",  fDumpFiles? "yes": "no" );
44577     Abc_Print( -2, "\t-t     : write files with two sides of a two-word miter [default = %s]\n",  fDumpFilesTwo? "yes": "no" );
44578     Abc_Print( -2, "\t-d     : take single-output and decompose into dual-output [default = %s]\n",  fDual? "yes": "no" );
44579     Abc_Print( -2, "\t-v     : toggles printing verbose information [default = %s]\n",  fVerbose? "yes": "no" );
44580     Abc_Print( -2, "\t-h     : print the command usage\n");
44581     return 1;
44582 }
44583 
44584 /**Function*************************************************************
44585 
44586   Synopsis    []
44587 
44588   Description []
44589 
44590   SideEffects []
44591 
44592   SeeAlso     []
44593 
44594 ***********************************************************************/
Abc_CommandAbc9Fadds(Abc_Frame_t * pAbc,int argc,char ** argv)44595 int Abc_CommandAbc9Fadds( Abc_Frame_t * pAbc, int argc, char ** argv )
44596 {
44597     extern Gia_Man_t * Gia_ManDupWithNaturalBoxes( Gia_Man_t * p, int nFaddMin, int fVerbose );
44598     extern Gia_Man_t * Gia_ManDupWithArtificialBoxes( Gia_Man_t * p, int DelayC, int nPathMin, int nPathMax, int nPathLimit, int fUseFanout, int fXorTrick, int fIgnoreBoxDelays, int fVerbose );
44599     Gia_Man_t * pTemp, * pTemp2;
44600     int c, nFaddMin = 3, fUseNat = 0, fUseArt = 0, fVerbose = 0;
44601     int DelayC = 0, nPathMin = 3, nPathMax = 32, nPathLimit = 50, fUseFanout = 0, fUseXorTrick = 0, fIgnoreBoxDelays = 0;
44602     Extra_UtilGetoptReset();
44603     while ( ( c = Extra_UtilGetopt( argc, argv, "NBSLPnafxbvh" ) ) != EOF )
44604     {
44605         switch ( c )
44606         {
44607         case 'N':
44608             if ( globalUtilOptind >= argc )
44609             {
44610                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
44611                 goto usage;
44612             }
44613             nFaddMin = atoi(argv[globalUtilOptind]);
44614             globalUtilOptind++;
44615             if ( nFaddMin < 0 )
44616                 goto usage;
44617             break;
44618         case 'B':
44619             if ( globalUtilOptind >= argc )
44620             {
44621                 Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" );
44622                 goto usage;
44623             }
44624             DelayC = atoi(argv[globalUtilOptind]);
44625             globalUtilOptind++;
44626             if ( DelayC < 0 )
44627                 goto usage;
44628             break;
44629         case 'S':
44630             if ( globalUtilOptind >= argc )
44631             {
44632                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
44633                 goto usage;
44634             }
44635             nPathMin = atoi(argv[globalUtilOptind]);
44636             globalUtilOptind++;
44637             if ( nPathMin < 0 )
44638                 goto usage;
44639             break;
44640         case 'L':
44641             if ( globalUtilOptind >= argc )
44642             {
44643                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
44644                 goto usage;
44645             }
44646             nPathMax = atoi(argv[globalUtilOptind]);
44647             globalUtilOptind++;
44648             if ( nPathMax < 0 )
44649                 goto usage;
44650             break;
44651         case 'P':
44652             if ( globalUtilOptind >= argc )
44653             {
44654                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
44655                 goto usage;
44656             }
44657             nPathLimit = atoi(argv[globalUtilOptind]);
44658             globalUtilOptind++;
44659             if ( nPathLimit < 0 )
44660                 goto usage;
44661             break;
44662         case 'n':
44663             fUseNat ^= 1;
44664             break;
44665         case 'a':
44666             fUseArt ^= 1;
44667             break;
44668         case 'f':
44669             fUseFanout ^= 1;
44670             break;
44671         case 'x':
44672             fUseXorTrick ^= 1;
44673             break;
44674         case 'b':
44675             fIgnoreBoxDelays ^= 1;
44676             break;
44677         case 'v':
44678             fVerbose ^= 1;
44679             break;
44680         case 'h':
44681             goto usage;
44682         default:
44683             goto usage;
44684         }
44685     }
44686     if ( pAbc->pGia == NULL )
44687     {
44688         Abc_Print( -1, "Abc_CommandAbc9Fadds(): There is no AIG.\n" );
44689         return 0;
44690     }
44691     if ( fUseNat )
44692         pTemp = Gia_ManDupWithNaturalBoxes( pAbc->pGia, nFaddMin, fVerbose );
44693     else
44694     {
44695         pTemp = Gia_ManDup( pAbc->pGia );
44696         Gia_ManTransferTiming( pTemp, pAbc->pGia );
44697     }
44698     if ( fUseArt )
44699         pTemp2 = Gia_ManDupWithArtificialBoxes( pTemp, DelayC, nPathMin, nPathMax, nPathLimit, fUseFanout, fUseXorTrick, fIgnoreBoxDelays, fVerbose );
44700     else
44701     {
44702         pTemp2 = Gia_ManDup( pTemp );
44703         Gia_ManTransferTiming( pTemp2, pTemp );
44704     }
44705     Gia_ManStop( pTemp );
44706     Abc_FrameUpdateGia( pAbc, pTemp2 );
44707     return 0;
44708 usage:
44709     Abc_Print( -2, "usage: &fadds [-NBSLP num] [-nafxvh]\n" );
44710     Abc_Print( -2, "\t         detects full-adder chains and puts them into white boxes\n" );
44711     Abc_Print( -2, "\t-n     : toggles detecting natural full-adder chains [default = %s]\n",              fUseNat? "yes": "no" );
44712     Abc_Print( -2, "\t-N num : minimum length of a natural full-adder chain to detect [default = %d]\n",   nFaddMin );
44713     Abc_Print( -2, "\t-a     : toggles detecting artificial full-adder chains [default = %s]\n",           fUseArt? "yes": "no" );
44714     Abc_Print( -2, "\t-B num : full-adder box delay (percentage of AND-gate delay) [default = %d]\n",      DelayC );
44715     Abc_Print( -2, "\t-S num : minimum length of an artificial full-adder chain [default = %d]\n",         nPathMin );
44716     Abc_Print( -2, "\t-L num : maximum length of an artificial full-adder chain [default = %d]\n",         nPathMax );
44717     Abc_Print( -2, "\t-P num : maximum number of artificial full-adder chains to detect [default = %d]\n", nPathLimit );
44718     Abc_Print( -2, "\t-f     : toggles allowing external fanouts in artificial chains [default = %s]\n",   fUseFanout? "yes": "no" );
44719     Abc_Print( -2, "\t-x     : toggles using XOR to generate fanouts in artificial chains [default = %s]\n",   fUseXorTrick? "yes": "no" );
44720     Abc_Print( -2, "\t-b     : toggles ignoring boxes when computing delays [default = %s]\n",             fIgnoreBoxDelays? "yes": "no" );
44721     Abc_Print( -2, "\t-v     : toggles printing verbose information [default = %s]\n",                     fVerbose? "yes": "no" );
44722     Abc_Print( -2, "\t-h     : print the command usage\n");
44723     return 1;
44724 }
44725 
44726 /**Function*************************************************************
44727 
44728   Synopsis    []
44729 
44730   Description []
44731 
44732   SideEffects []
44733 
44734   SeeAlso     []
44735 
44736 ***********************************************************************/
Abc_CommandAbc9ATree(Abc_Frame_t * pAbc,int argc,char ** argv)44737 int Abc_CommandAbc9ATree( Abc_Frame_t * pAbc, int argc, char ** argv )
44738 {
44739     extern Gia_Man_t * Gia_PolynCoreDetectTest( Gia_Man_t * pGia, int fAddExtra, int fAddCones, int fVerbose );
44740     Gia_Man_t * pTemp = NULL;
44741     int c, fAddExtra = 0, fAddCones = 0, fVerbose = 0, fVeryVerbose = 0;
44742     Extra_UtilGetoptReset();
44743     while ( ( c = Extra_UtilGetopt( argc, argv, "ecvwh" ) ) != EOF )
44744     {
44745         switch ( c )
44746         {
44747         case 'e':
44748             fAddExtra ^= 1;
44749             break;
44750         case 'c':
44751             fAddCones ^= 1;
44752             break;
44753         case 'v':
44754             fVerbose ^= 1;
44755             break;
44756         case 'w':
44757             fVeryVerbose ^= 1;
44758             break;
44759         case 'h':
44760             goto usage;
44761         default:
44762             goto usage;
44763         }
44764     }
44765     if ( pAbc->pGia == NULL )
44766     {
44767         Abc_Print( -1, "Abc_CommandAbc9Esop(): There is no AIG.\n" );
44768         return 0;
44769     }
44770     pTemp = Gia_PolynCoreDetectTest( pAbc->pGia, fAddExtra, fAddCones, fVerbose );
44771     Abc_FrameUpdateGia( pAbc, pTemp );
44772     return 0;
44773 
44774 usage:
44775     Abc_Print( -2, "usage: &atree [-ecvwh]\n" );
44776     Abc_Print( -2, "\t         extracts adder tree rooting in primary outputs\n" );
44777     Abc_Print( -2, "\t-e     : toggles adding extra outputs [default = %s]\n",  fAddExtra? "yes": "no" );
44778     Abc_Print( -2, "\t-c     : toggles duplicating complete AIG [default = %s]\n",  fAddCones? "yes": "no" );
44779     Abc_Print( -2, "\t-v     : toggles printing verbose information [default = %s]\n",  fVerbose? "yes": "no" );
44780     Abc_Print( -2, "\t-w     : toggles printing very verbose information [default = %s]\n",  fVeryVerbose? "yes": "no" );
44781     Abc_Print( -2, "\t-h     : print the command usage\n");
44782     return 1;
44783 }
44784 
44785 /**Function*************************************************************
44786 
44787   Synopsis    []
44788 
44789   Description []
44790 
44791   SideEffects []
44792 
44793   SeeAlso     []
44794 
44795 ***********************************************************************/
Abc_CommandAbc9Polyn(Abc_Frame_t * pAbc,int argc,char ** argv)44796 int Abc_CommandAbc9Polyn( Abc_Frame_t * pAbc, int argc, char ** argv )
44797 {
44798     extern void Gia_PolynBuild2Test( Gia_Man_t * pGia, char * pSign, int nExtra, int fSigned, int fVerbose, int fVeryVerbose );
44799     Vec_Int_t * vOrder = NULL; char * pSign = NULL;
44800     int c, nExtra = 0, fOld = 0, fSimple = 1, fSigned = 0, fVerbose = 0, fVeryVerbose = 0;
44801     Extra_UtilGetoptReset();
44802     while ( ( c = Extra_UtilGetopt( argc, argv, "NSoasvwh" ) ) != EOF )
44803     {
44804         switch ( c )
44805         {
44806         case 'N':
44807             if ( globalUtilOptind >= argc )
44808             {
44809                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
44810                 goto usage;
44811             }
44812             nExtra = atoi(argv[globalUtilOptind]);
44813             globalUtilOptind++;
44814             if ( nExtra < 0 )
44815                 goto usage;
44816             break;
44817         case 'S':
44818             if ( globalUtilOptind >= argc )
44819             {
44820                 Abc_Print( -1, "Command line switch \"-S\" should be followed by a char string without spaces.\n" );
44821                 goto usage;
44822             }
44823             pSign = argv[globalUtilOptind];
44824             globalUtilOptind++;
44825             break;
44826         case 'o':
44827             fOld ^= 1;
44828             break;
44829         case 'a':
44830             fSimple ^= 1;
44831             break;
44832         case 's':
44833             fSigned ^= 1;
44834             break;
44835         case 'v':
44836             fVerbose ^= 1;
44837             break;
44838         case 'w':
44839             fVeryVerbose ^= 1;
44840             break;
44841         case 'h':
44842             goto usage;
44843         default:
44844             goto usage;
44845         }
44846     }
44847     if ( pAbc->pGia == NULL )
44848     {
44849         Abc_Print( -1, "Abc_CommandAbc9Esop(): There is no AIG.\n" );
44850         return 0;
44851     }
44852     if ( argc >= globalUtilOptind + 1 )
44853     {
44854         printf( "Trailing symbols on the command line (\"%s\").\n", argv[globalUtilOptind] );
44855         return 0;
44856     }
44857     if ( fOld )
44858     {
44859         vOrder = fSimple ? NULL : Gia_PolynReorder( pAbc->pGia, fVerbose, fVeryVerbose );
44860         Gia_PolynBuild( pAbc->pGia, vOrder, fSigned, fVerbose, fVeryVerbose );
44861         Vec_IntFreeP( &vOrder );
44862     }
44863     else
44864         Gia_PolynBuild2Test( pAbc->pGia, pSign, nExtra, fSigned, fVerbose, fVeryVerbose );
44865     return 0;
44866 
44867 usage:
44868     Abc_Print( -2, "usage: &polyn [-N num] [-oasvwh] [-S str]\n" );
44869     Abc_Print( -2, "\t         derives algebraic polynomial from AIG\n" );
44870     Abc_Print( -2, "\t-N num : the number of additional primary outputs (-1 = unused) [default = %d]\n", nExtra );
44871     Abc_Print( -2, "\t-o     : toggles old computation [default = %s]\n",  fOld? "yes": "no" );
44872     Abc_Print( -2, "\t-a     : toggles simple computation [default = %s]\n",  fSimple? "yes": "no" );
44873     Abc_Print( -2, "\t-s     : toggles signed computation [default = %s]\n",  fSigned? "yes": "no" );
44874     Abc_Print( -2, "\t-v     : toggles printing verbose information [default = %s]\n",  fVerbose? "yes": "no" );
44875     Abc_Print( -2, "\t-w     : toggles printing very verbose information [default = %s]\n",  fVeryVerbose? "yes": "no" );
44876     Abc_Print( -2, "\t-h     : print the command usage\n");
44877     Abc_Print( -2, "\t\n");
44878     Abc_Print( -2, "\t-S str : (optional) the output signature as a character string\n" );
44879     Abc_Print( -2, "\t         The format used to represent the output signature is very restrictive.\n" );
44880     Abc_Print( -2, "\t         It should be a string without spaces containing monomials in terms of\n" );
44881     Abc_Print( -2, "\t         inputs (i<num>) and outputs (o<num>) where <num> is 0-based. Coefficients\n" );
44882     Abc_Print( -2, "\t         are degrees of two, represented by log2 of their value: for example, \n" );
44883     Abc_Print( -2, "\t         \"2\" is 2^2 = 4, \"-4\" is -2^4=-16, \"-0\" is -2^0=-1, etc\n" );
44884     Abc_Print( -2, "\t         Two types of signature are accepted:\n" );
44885     Abc_Print( -2, "\t         (1) a sequence of monomials without parentheses (for example, \"-2*o0+1*o1+0*o2\")\n" );
44886     Abc_Print( -2, "\t         (2) a product of two sequences followed by a sum with a sequence\n" );
44887     Abc_Print( -2, "\t             (for example, \"(4*o0+2*o1+1*o2)*(4*i3+2*i4+1*i5)+(4*o3+2*o4+1*o5)\")\n" );
44888     Abc_Print( -2, "\t         Here is the signature of a signed 2-bit multiplier: \"(0*o0+1*o1+2*o2-3*o3)\"\n" );
44889     return 1;
44890 }
44891 
44892 /**Function*************************************************************
44893 
44894   Synopsis    []
44895 
44896   Description []
44897 
44898   SideEffects []
44899 
44900   SeeAlso     []
44901 
44902 ***********************************************************************/
Abc_CommandAbc9Acec(Abc_Frame_t * pAbc,int argc,char ** argv)44903 int Abc_CommandAbc9Acec( Abc_Frame_t * pAbc, int argc, char ** argv )
44904 {
44905     FILE * pFile;
44906     Acec_ParCec_t ParsCec, * pPars = &ParsCec;
44907     char ** pArgvNew;
44908     int c, nArgcNew;
44909     Acec_ManCecSetDefaultParams( pPars );
44910     Extra_UtilGetoptReset();
44911     while ( ( c = Extra_UtilGetopt( argc, argv, "CTmdtbvh" ) ) != EOF )
44912     {
44913         switch ( c )
44914         {
44915         case 'C':
44916             if ( globalUtilOptind >= argc )
44917             {
44918                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
44919                 goto usage;
44920             }
44921             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
44922             globalUtilOptind++;
44923             if ( pPars->nBTLimit < 0 )
44924                 goto usage;
44925             break;
44926         case 'T':
44927             if ( globalUtilOptind >= argc )
44928             {
44929                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
44930                 goto usage;
44931             }
44932             pPars->TimeLimit = atoi(argv[globalUtilOptind]);
44933             globalUtilOptind++;
44934             if ( pPars->TimeLimit < 0 )
44935                 goto usage;
44936             break;
44937         case 'm':
44938             pPars->fMiter ^= 1;
44939             break;
44940         case 'd':
44941             pPars->fDualOutput ^= 1;
44942             break;
44943         case 't':
44944             pPars->fTwoOutput ^= 1;
44945             break;
44946         case 'b':
44947             pPars->fBooth ^= 1;
44948             break;
44949         case 'v':
44950             pPars->fVerbose ^= 1;
44951             break;
44952         case 'h':
44953             goto usage;
44954         default:
44955             goto usage;
44956         }
44957     }
44958     if ( pPars->fMiter )
44959     {
44960         Gia_Man_t * pGia0, * pGia1, * pDual;
44961         if ( argc != globalUtilOptind )
44962         {
44963             Abc_Print( -1, "Abc_CommandAbc9Acec(): If the input is a miter, it cannot be given on the command line.\n" );
44964             return 1;
44965         }
44966         if ( pAbc->pGia == NULL )
44967         {
44968             Abc_Print( -1, "Abc_CommandAbc9Acec(): There is no AIG.\n" );
44969             return 1;
44970         }
44971         if ( pPars->fDualOutput )
44972         {
44973             if ( Gia_ManPoNum(pAbc->pGia) & 1 )
44974             {
44975                 Abc_Print( -1, "The dual-output miter should have an even number of outputs.\n" );
44976                 return 1;
44977             }
44978             if ( !pPars->fSilent )
44979             Abc_Print( 1, "Assuming the current network is a double-output miter. (Conflict limit = %d.)\n", pPars->nBTLimit );
44980             Gia_ManDemiterDual( pAbc->pGia, &pGia0, &pGia1 );
44981             pAbc->Status = Acec_Solve( pGia0, pGia1, pPars );
44982         }
44983         else if ( pPars->fTwoOutput )
44984         {
44985             if ( Gia_ManPoNum(pAbc->pGia) & 1 )
44986             {
44987                 Abc_Print( -1, "The two-output miter should have an even number of outputs.\n" );
44988                 return 1;
44989             }
44990             if ( !pPars->fSilent )
44991             Abc_Print( 1, "Assuming the current network is a two-word miter. (Conflict limit = %d.)\n", pPars->nBTLimit );
44992             Gia_ManDemiterTwoWords( pAbc->pGia, &pGia0, &pGia1 );
44993             pAbc->Status = Acec_Solve( pGia0, pGia1, pPars );
44994         }
44995         else // regular single- or multi-output miter
44996         {
44997             if ( !pPars->fSilent )
44998             Abc_Print( 1, "Assuming the current network is a regular single- or multi-output miter. (Conflict limit = %d.)\n", pPars->nBTLimit );
44999             pDual = Gia_ManDemiterToDual( pAbc->pGia );
45000             Gia_ManDemiterDual( pDual, &pGia0, &pGia1 );
45001             Gia_ManStop( pDual );
45002             pAbc->Status = Acec_Solve( pGia0, pGia1, pPars );
45003         }
45004         Abc_FrameReplaceCex( pAbc, &pGia0->pCexComb );
45005         Gia_ManStop( pGia0 );
45006         Gia_ManStop( pGia1 );
45007         return 0;
45008     }
45009 
45010     pArgvNew = argv + globalUtilOptind;
45011     nArgcNew = argc - globalUtilOptind;
45012     if ( nArgcNew == 0 || nArgcNew == 1 )
45013     {
45014         Gia_Man_t * pSecond;
45015         char * pTemp, * FileName = NULL;
45016         if ( nArgcNew == 0 )
45017         {
45018             FileName = pAbc->pGia->pSpec;
45019             if ( FileName == NULL )
45020             {
45021                 Abc_Print( -1, "File name is not given on the command line.\n" );
45022                 return 1;
45023             }
45024         }
45025         else // if ( nArgcNew == 1 )
45026         {
45027             FileName = pArgvNew[0];
45028             // fix the wrong symbol
45029             for ( pTemp = FileName; *pTemp; pTemp++ )
45030                 if ( *pTemp == '>' )
45031                     *pTemp = '\\';
45032             if ( (pFile = fopen( FileName, "r" )) == NULL )
45033             {
45034                 Abc_Print( -1, "Cannot open input file \"%s\". ", FileName );
45035                 if ( (FileName = Extra_FileGetSimilarName( FileName, ".aig", NULL, NULL, NULL, NULL )) )
45036                     Abc_Print( 1, "Did you mean \"%s\"?", FileName );
45037                 Abc_Print( 1, "\n" );
45038                 return 1;
45039             }
45040             fclose( pFile );
45041         }
45042         pSecond = Gia_AigerRead( FileName, 0, 0, 0 );
45043         if ( pSecond == NULL )
45044         {
45045             Abc_Print( -1, "Reading AIGER has failed.\n" );
45046             return 0;
45047         }
45048         pAbc->Status = Acec_Solve( pAbc->pGia, pSecond, pPars );
45049         Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexComb );
45050         Gia_ManStop( pSecond );
45051     }
45052     else if ( nArgcNew == 2 )
45053     {
45054         Gia_Man_t * pGias[2] = {NULL};  int i;
45055         char * pTemp, * FileName[2] = { pArgvNew[0], pArgvNew[1] };
45056         for ( i = 0; i < 2; i++ )
45057         {
45058             // fix the wrong symbol
45059             for ( pTemp = FileName[i]; *pTemp; pTemp++ )
45060                 if ( *pTemp == '>' )
45061                     *pTemp = '\\';
45062             if ( (pFile = fopen( FileName[i], "r" )) == NULL )
45063             {
45064                 Abc_Print( -1, "Cannot open input file \"%s\". ", FileName[i] );
45065                 if ( (FileName[i] = Extra_FileGetSimilarName( FileName[i], ".aig", NULL, NULL, NULL, NULL )) )
45066                     Abc_Print( 1, "Did you mean \"%s\"?", FileName[i] );
45067                 Abc_Print( 1, "\n" );
45068                 return 1;
45069             }
45070             fclose( pFile );
45071             pGias[i] = Gia_AigerRead( FileName[i], 0, 0, 0 );
45072             if ( pGias[i] == NULL )
45073             {
45074                 Abc_Print( -1, "Reading AIGER has failed.\n" );
45075                 return 0;
45076             }
45077         }
45078         pAbc->Status = Acec_Solve( pGias[0], pGias[1], pPars );
45079         Abc_FrameReplaceCex( pAbc, &pGias[0]->pCexComb );
45080         Gia_ManStop( pGias[0] );
45081         Gia_ManStop( pGias[1] );
45082     }
45083     else
45084     {
45085         Abc_Print( -1, "Too many command-line arguments.\n" );
45086         return 1;
45087     }
45088     return 0;
45089 
45090 usage:
45091     Abc_Print( -2, "usage: &acec [-CT num] [-mdtbvh] <file1> <file2>\n" );
45092     Abc_Print( -2, "\t         combinational equivalence checking for arithmetic circuits\n" );
45093     Abc_Print( -2, "\t-C num : the max number of conflicts at a node [default = %d]\n", pPars->nBTLimit );
45094     Abc_Print( -2, "\t-T num : approximate runtime limit in seconds [default = %d]\n", pPars->TimeLimit );
45095     Abc_Print( -2, "\t-m     : toggle miter vs. two circuits [default = %s]\n", pPars->fMiter? "miter":"two circuits");
45096     Abc_Print( -2, "\t-d     : toggle using dual output miter [default = %s]\n", pPars->fDualOutput? "yes":"no");
45097     Abc_Print( -2, "\t-t     : toggle using two-word miter [default = %s]\n", pPars->fTwoOutput? "yes":"no");
45098     Abc_Print( -2, "\t-b     : toggle working with Booth multipliers [default = %s]\n", pPars->fBooth? "yes":"no");
45099     Abc_Print( -2, "\t-v     : toggle verbose output [default = %s]\n", pPars->fVerbose? "yes":"no");
45100     Abc_Print( -2, "\t-h     : print the command usage\n");
45101     Abc_Print( -2, "\tfile1  : (optional) the file with the first network\n");
45102     Abc_Print( -2, "\tfile2  : (optional) the file with the second network\n");
45103     return 1;
45104 }
45105 
45106 /**Function*************************************************************
45107 
45108   Synopsis    []
45109 
45110   Description []
45111 
45112   SideEffects []
45113 
45114   SeeAlso     []
45115 
45116 ***********************************************************************/
Abc_CommandAbc9Anorm(Abc_Frame_t * pAbc,int argc,char ** argv)45117 int Abc_CommandAbc9Anorm( Abc_Frame_t * pAbc, int argc, char ** argv )
45118 {
45119     Gia_Man_t * pTemp;
45120     int c, fBooth = 0, fVerbose = 0;
45121     Extra_UtilGetoptReset();
45122     while ( ( c = Extra_UtilGetopt( argc, argv, "bvh" ) ) != EOF )
45123     {
45124         switch ( c )
45125         {
45126         case 'b':
45127             fBooth ^= 1;
45128             break;
45129         case 'v':
45130             fVerbose ^= 1;
45131             break;
45132         case 'h':
45133             goto usage;
45134         default:
45135             goto usage;
45136         }
45137     }
45138     if ( pAbc->pGia == NULL )
45139     {
45140         Abc_Print( -1, "Abc_CommandAbc9Anorm(): There is no AIG.\n" );
45141         return 0;
45142     }
45143     pTemp = Acec_Normalize( pAbc->pGia, fBooth, fVerbose );
45144     Abc_FrameUpdateGia( pAbc, pTemp );
45145     return 0;
45146 
45147 usage:
45148     Abc_Print( -2, "usage: &anorm [-bvh]\n" );
45149     Abc_Print( -2, "\t         normalize adder trees in the current AIG\n" );
45150     Abc_Print( -2, "\t-b     : toggles working with Booth multipliers [default = %s]\n",  fBooth? "yes": "no" );
45151     Abc_Print( -2, "\t-v     : toggles printing verbose information [default = %s]\n",  fVerbose? "yes": "no" );
45152     Abc_Print( -2, "\t-h     : print the command usage\n");
45153     return 1;
45154 }
45155 
45156 /**Function*************************************************************
45157 
45158   Synopsis    []
45159 
45160   Description []
45161 
45162   SideEffects []
45163 
45164   SeeAlso     []
45165 
45166 ***********************************************************************/
Abc_CommandAbc9Decla(Abc_Frame_t * pAbc,int argc,char ** argv)45167 int Abc_CommandAbc9Decla( Abc_Frame_t * pAbc, int argc, char ** argv )
45168 {
45169     Gia_Man_t * pTemp;
45170     int c, fBooth = 0, fVerbose = 0;
45171     Extra_UtilGetoptReset();
45172     while ( ( c = Extra_UtilGetopt( argc, argv, "bvh" ) ) != EOF )
45173     {
45174         switch ( c )
45175         {
45176         case 'b':
45177             fBooth ^= 1;
45178             break;
45179         case 'v':
45180             fVerbose ^= 1;
45181             break;
45182         case 'h':
45183             goto usage;
45184         default:
45185             goto usage;
45186         }
45187     }
45188     if ( pAbc->pGia == NULL )
45189     {
45190         Abc_Print( -1, "Abc_CommandAbc9Decla(): There is no AIG.\n" );
45191         return 0;
45192     }
45193     pTemp = Acec_ManDecla( pAbc->pGia, fBooth, fVerbose );
45194     Abc_FrameUpdateGia( pAbc, pTemp );
45195     return 0;
45196 
45197 usage:
45198     Abc_Print( -2, "usage: &decla [-bvh]\n" );
45199     Abc_Print( -2, "\t         removes carry look ahead adders\n" );
45200     Abc_Print( -2, "\t-b     : toggles working with Booth multipliers [default = %s]\n",  fBooth? "yes": "no" );
45201     Abc_Print( -2, "\t-v     : toggles printing verbose information [default = %s]\n",  fVerbose? "yes": "no" );
45202     Abc_Print( -2, "\t-h     : print the command usage\n");
45203     return 1;
45204 }
45205 
45206 
45207 /**Function*************************************************************
45208 
45209   Synopsis    []
45210 
45211   Description []
45212 
45213   SideEffects []
45214 
45215   SeeAlso     []
45216 
45217 ***********************************************************************/
Abc_CommandAbc9Esop(Abc_Frame_t * pAbc,int argc,char ** argv)45218 int Abc_CommandAbc9Esop( Abc_Frame_t * pAbc, int argc, char ** argv )
45219 {
45220     extern Gia_Man_t * Eso_ManCompute( Gia_Man_t * pGia, int fVerbose, Vec_Wec_t ** pvRes );
45221     Gia_Man_t * pTemp;
45222     int c, fVerbose = 0;
45223     Extra_UtilGetoptReset();
45224     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
45225     {
45226         switch ( c )
45227         {
45228         case 'v':
45229             fVerbose ^= 1;
45230             break;
45231         case 'h':
45232             goto usage;
45233         default:
45234             goto usage;
45235         }
45236     }
45237     if ( pAbc->pGia == NULL )
45238     {
45239         Abc_Print( -1, "Abc_CommandAbc9Esop(): There is no AIG.\n" );
45240         return 0;
45241     }
45242     pTemp = Eso_ManCompute( pAbc->pGia, fVerbose, NULL );
45243     Abc_FrameUpdateGia( pAbc, pTemp );
45244     return 0;
45245 
45246 usage:
45247     Abc_Print( -2, "usage: &esop [-vh]\n" );
45248     Abc_Print( -2, "\t         derives Exclusive Sum of Products from AIG\n" );
45249     Abc_Print( -2, "\t-v     : toggles printing verbose information [default = %s]\n",  fVerbose? "yes": "no" );
45250     Abc_Print( -2, "\t-h     : print the command usage\n");
45251     return 1;
45252 }
45253 
45254 /**Function*************************************************************
45255 
45256   Synopsis    []
45257 
45258   Description []
45259 
45260   SideEffects []
45261 
45262   SeeAlso     []
45263 
45264 ***********************************************************************/
Abc_CommandAbc9Exorcism(Abc_Frame_t * pAbc,int argc,char ** argv)45265 int Abc_CommandAbc9Exorcism( Abc_Frame_t * pAbc, int argc, char ** argv )
45266 {
45267     extern int Abc_ExorcismMain( Vec_Wec_t * vEsop, int nIns, int nOuts, char * pFileNameOut, int Quality, int Verbosity, int nCubesMax, int fUseQCost );
45268     extern Vec_Wec_t * Abc_ExorcismNtk2Esop( Abc_Ntk_t * pNtk );
45269 
45270     extern Gia_Man_t * Eso_ManCompute( Gia_Man_t * pGia, int fVerbose, Vec_Wec_t ** pvRes );
45271     Vec_Wec_t * vEsop = NULL;
45272     Abc_Ntk_t * pNtk = NULL;
45273     char * pFileNameIn = NULL;
45274     char * pFileNameOut = NULL;
45275     int c, Quality = 2, Verbosity = 0, nCubesMax = 20000, fUseQCost = 0, fVerbose = 0;
45276     int nInputs = -1, nOutputs = -1;
45277 
45278     Extra_UtilGetoptReset();
45279     while ( ( c = Extra_UtilGetopt( argc, argv, "QVCqvh" ) ) != EOF )
45280     {
45281         switch ( c )
45282         {
45283         case 'Q':
45284             if ( globalUtilOptind >= argc )
45285             {
45286                 Abc_Print( -1, "Command line switch \"-Q\" should be followed by an integer.\n" );
45287                 goto usage;
45288             }
45289             Quality = atoi(argv[globalUtilOptind]);
45290             globalUtilOptind++;
45291             if ( Quality < 0 )
45292                 goto usage;
45293             break;
45294         case 'V':
45295             if ( globalUtilOptind >= argc )
45296             {
45297                 Abc_Print( -1, "Command line switch \"-V\" should be followed by an integer.\n" );
45298                 goto usage;
45299             }
45300             Verbosity = atoi(argv[globalUtilOptind]);
45301             globalUtilOptind++;
45302             if ( Verbosity < 0 )
45303                 goto usage;
45304             break;
45305         case 'C':
45306             if ( globalUtilOptind >= argc )
45307             {
45308                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
45309                 goto usage;
45310             }
45311             nCubesMax = atoi(argv[globalUtilOptind]);
45312             globalUtilOptind++;
45313             if ( nCubesMax < 0 )
45314                 goto usage;
45315             break;
45316         case 'q':
45317             fUseQCost ^= 1;
45318             break;
45319         case 'v':
45320             fVerbose ^= 1;
45321             break;
45322         case 'h':
45323             goto usage;
45324         default:
45325             goto usage;
45326         }
45327     }
45328 
45329     if ( argc == globalUtilOptind + 2 )
45330     {
45331         pFileNameIn = argv[globalUtilOptind];
45332         pFileNameOut = argv[globalUtilOptind + 1];
45333     }
45334     else if ( argc == globalUtilOptind + 1 )
45335     {
45336         pFileNameOut = argv[globalUtilOptind];
45337     }
45338     else
45339     {
45340         Abc_Print( -1, "Abc_CommandAbc9Exorcism(): Argument error.\n" );
45341         goto usage;
45342     }
45343 
45344     if ( pAbc->pGia == NULL && pFileNameIn == NULL )
45345     {
45346       Abc_Print( -1, "Abc_CommandAbc9Exorcism(): There is neither an AIG nor an ESOP-PLA file.\n" );
45347       return 0;
45348     }
45349 
45350     if ( pFileNameIn )
45351     {
45352         pNtk = Io_ReadPla( pFileNameIn, 0, 0, 0, /* no preprocessing = */1, /* check = */1 );
45353         if ( pNtk == NULL )
45354         {
45355             printf( "Reading PLA file has failed.\n" );
45356             return 1;
45357         }
45358         nInputs = Abc_NtkCiNum( pNtk );
45359         nOutputs = Abc_NtkCoNum( pNtk );
45360         vEsop = Abc_ExorcismNtk2Esop( pNtk );
45361         if ( vEsop == NULL )
45362         {
45363             printf( "Converting PLA to ESOP failed.\n" );
45364             return 1;
45365         }
45366     }
45367     else if ( pAbc->pGia )
45368     {
45369         // generate starting cover
45370         nInputs = Gia_ManCiNum( pAbc->pGia );
45371         nOutputs = Gia_ManCoNum( pAbc->pGia );
45372         Eso_ManCompute( pAbc->pGia, fVerbose, &vEsop );
45373     }
45374 
45375     if ( vEsop )
45376     {
45377         // run minimization
45378         Abc_ExorcismMain( vEsop, nInputs, nOutputs, pFileNameOut, Quality, Verbosity, nCubesMax, fUseQCost );
45379         Vec_WecFree( vEsop );
45380     }
45381     return 0;
45382 
45383 usage:
45384     Abc_Print( -2, "usage: &exorcism [-Q N] [-V N] [-C N] -q [file_in] <file_out>\n" );
45385     Abc_Print( -2, "                     performs heuristic exclusive sum-of-project minimization\n" );
45386     Abc_Print( -2, "        -Q N       : minimization quality [default = %d]\n", Quality);
45387     Abc_Print( -2, "                     increasing this number improves quality and adds to runtime\n");
45388     Abc_Print( -2, "        -V N       : verbosity level [default = %d]\n", Verbosity);
45389     Abc_Print( -2, "                     0 = no output; 1 = outline; 2 = verbose\n");
45390     Abc_Print( -2, "        -C N       : maximum number of cubes in startign cover [default = %d]\n", nCubesMax );
45391     Abc_Print( -2, "        -q         : toggle using quantum cost [default = %s]\n", fUseQCost? "yes": "no" );
45392     Abc_Print( -2, "        [file_in]  : optional input file in ESOP-PLA format (otherwise current AIG is used)\n");
45393     Abc_Print( -2, "        <file_out> : output file in ESOP-PLA format\n");
45394     Abc_Print( -2, "\n" );
45395     return 1;
45396 }
45397 
45398 /**Function*************************************************************
45399 
45400   Synopsis    []
45401 
45402   Description []
45403 
45404   SideEffects []
45405 
45406   SeeAlso     []
45407 
45408 ***********************************************************************/
Abc_CommandAbc9Mfs(Abc_Frame_t * pAbc,int argc,char ** argv)45409 int Abc_CommandAbc9Mfs( Abc_Frame_t * pAbc, int argc, char ** argv )
45410 {
45411     extern Gia_Man_t * Gia_ManPerformMfs( Gia_Man_t * p, Sfm_Par_t * pPars );
45412     Gia_Man_t * pTemp; int c;
45413     Sfm_Par_t Pars, * pPars = &Pars;
45414     Sfm_ParSetDefault( pPars );
45415     pPars->nTfoLevMax  =    5;
45416     pPars->nDepthMax   =  100;
45417     pPars->nWinSizeMax = 2000;
45418     Extra_UtilGetoptReset();
45419     while ( ( c = Extra_UtilGetopt( argc, argv, "WFDMLCNdaebvwh" ) ) != EOF )
45420     {
45421         switch ( c )
45422         {
45423         case 'W':
45424             if ( globalUtilOptind >= argc )
45425             {
45426                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
45427                 goto usage;
45428             }
45429             pPars->nTfoLevMax = atoi(argv[globalUtilOptind]);
45430             globalUtilOptind++;
45431             if ( pPars->nTfoLevMax < 0 )
45432                 goto usage;
45433             break;
45434         case 'F':
45435             if ( globalUtilOptind >= argc )
45436             {
45437                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
45438                 goto usage;
45439             }
45440             pPars->nFanoutMax = atoi(argv[globalUtilOptind]);
45441             globalUtilOptind++;
45442             if ( pPars->nFanoutMax < 0 )
45443                 goto usage;
45444             break;
45445         case 'D':
45446             if ( globalUtilOptind >= argc )
45447             {
45448                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
45449                 goto usage;
45450             }
45451             pPars->nDepthMax = atoi(argv[globalUtilOptind]);
45452             globalUtilOptind++;
45453             if ( pPars->nDepthMax < 0 )
45454                 goto usage;
45455             break;
45456         case 'M':
45457             if ( globalUtilOptind >= argc )
45458             {
45459                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
45460                 goto usage;
45461             }
45462             pPars->nWinSizeMax = atoi(argv[globalUtilOptind]);
45463             globalUtilOptind++;
45464             if ( pPars->nWinSizeMax < 0 )
45465                 goto usage;
45466             break;
45467         case 'L':
45468             if ( globalUtilOptind >= argc )
45469             {
45470                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
45471                 goto usage;
45472             }
45473             pPars->nGrowthLevel = atoi(argv[globalUtilOptind]);
45474             globalUtilOptind++;
45475             if ( pPars->nGrowthLevel < 0 || pPars->nGrowthLevel > ABC_INFINITY )
45476                 goto usage;
45477             break;
45478         case 'C':
45479             if ( globalUtilOptind >= argc )
45480             {
45481                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
45482                 goto usage;
45483             }
45484             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
45485             globalUtilOptind++;
45486             if ( pPars->nBTLimit < 0 )
45487                 goto usage;
45488             break;
45489         case 'N':
45490             if ( globalUtilOptind >= argc )
45491             {
45492                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
45493                 goto usage;
45494             }
45495             pPars->nNodesMax = atoi(argv[globalUtilOptind]);
45496             globalUtilOptind++;
45497             if ( pPars->nNodesMax < 0 )
45498                 goto usage;
45499             break;
45500         case 'd':
45501             pPars->fRrOnly ^= 1;
45502             break;
45503         case 'a':
45504             pPars->fArea ^= 1;
45505             break;
45506         case 'e':
45507             pPars->fMoreEffort ^= 1;
45508             break;
45509         case 'b':
45510             pPars->fAllBoxes ^= 1;
45511             break;
45512         case 'v':
45513             pPars->fVerbose ^= 1;
45514             break;
45515         case 'w':
45516             pPars->fVeryVerbose ^= 1;
45517             break;
45518         case 'h':
45519             goto usage;
45520         default:
45521             goto usage;
45522         }
45523     }
45524     if ( pAbc->pGia == NULL )
45525     {
45526         Abc_Print( -1, "Abc_CommandAbc9Mfs(): There is no AIG.\n" );
45527         return 0;
45528     }
45529     if ( Gia_ManBufNum(pAbc->pGia) )
45530     {
45531         Abc_Print( -1, "Abc_CommandAbc9Mfs(): This command does not work with barrier buffers.\n" );
45532         return 1;
45533     }
45534     if ( !Gia_ManHasMapping(pAbc->pGia) )
45535     {
45536         Abc_Print( -1, "Abc_CommandAbc9Mfs(): The current AIG has no mapping.\n" );
45537         return 0;
45538     }
45539     if ( Gia_ManLutSizeMax(pAbc->pGia) > 15 )
45540     {
45541         Abc_Print( -1, "Abc_CommandAbc9Mfs(): The current mapping has nodes with more than 15 inputs. Cannot use \"mfs\".\n" );
45542         return 0;
45543     }
45544 /*
45545     if ( pAbc->pGia->pAigExtra && Gia_ManPiNum(pAbc->pGia->pAigExtra) > 6 )
45546     {
45547         Abc_Print( -1, "Abc_CommandAbc9Mfs(): The current white-boxes have more than 6 inputs. Cannot use \"mfs\".\n" );
45548         return 0;
45549     }
45550 */
45551     pTemp = Gia_ManPerformMfs( pAbc->pGia, pPars );
45552     Abc_FrameUpdateGia( pAbc, pTemp );
45553     return 0;
45554 
45555 usage:
45556     Abc_Print( -2, "usage: &mfs [-WFDMLCN <num>] [-daebvwh]\n" );
45557     Abc_Print( -2, "\t           performs don't-care-based optimization of logic networks\n" );
45558     Abc_Print( -2, "\t-W <num> : the number of levels in the TFO cone (0 <= num) [default = %d]\n",             pPars->nTfoLevMax );
45559     Abc_Print( -2, "\t-F <num> : the max number of fanouts to skip (1 <= num) [default = %d]\n",                pPars->nFanoutMax );
45560     Abc_Print( -2, "\t-D <num> : the max depth nodes to try (0 = no limit) [default = %d]\n",                   pPars->nDepthMax );
45561     Abc_Print( -2, "\t-M <num> : the max node count of windows to consider (0 = no limit) [default = %d]\n",    pPars->nWinSizeMax );
45562     Abc_Print( -2, "\t-L <num> : the max increase in node level after resynthesis (0 <= num) [default = %d]\n", pPars->nGrowthLevel );
45563     Abc_Print( -2, "\t-C <num> : the max number of conflicts in one SAT run (0 = no limit) [default = %d]\n",   pPars->nBTLimit );
45564     Abc_Print( -2, "\t-N <num> : the max number of nodes to try (0 = all) [default = %d]\n",                    pPars->nNodesMax );
45565     Abc_Print( -2, "\t-d       : toggle performing redundancy removal [default = %s]\n",                        pPars->fRrOnly? "yes": "no" );
45566     Abc_Print( -2, "\t-a       : toggle minimizing area or area+edges [default = %s]\n",                        pPars->fArea? "area": "area+edges" );
45567     Abc_Print( -2, "\t-e       : toggle high-effort resubstitution [default = %s]\n",                           pPars->fMoreEffort? "yes": "no" );
45568     Abc_Print( -2, "\t-b       : toggle preserving all white boxes [default = %s]\n",                           pPars->fAllBoxes? "yes": "no" );
45569     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n",                        pPars->fVerbose? "yes": "no" );
45570     Abc_Print( -2, "\t-w       : toggle printing detailed stats for each node [default = %s]\n",                pPars->fVeryVerbose? "yes": "no" );
45571     Abc_Print( -2, "\t-h       : print the command usage\n");
45572     return 1;
45573 }
45574 
45575 /**Function*************************************************************
45576 
45577   Synopsis    []
45578 
45579   Description []
45580 
45581   SideEffects []
45582 
45583   SeeAlso     []
45584 
45585 ***********************************************************************/
Abc_CommandAbc9Mfsd(Abc_Frame_t * pAbc,int argc,char ** argv)45586 int Abc_CommandAbc9Mfsd( Abc_Frame_t * pAbc, int argc, char ** argv )
45587 {
45588     extern Gia_Man_t * Sbd_NtkPerform( Gia_Man_t * pGia, Sbd_Par_t * pPars );
45589     Gia_Man_t * pTemp; int c;
45590     Sbd_Par_t Pars, * pPars = &Pars;
45591     Sbd_ParSetDefault( pPars );
45592     Extra_UtilGetoptReset();
45593     while ( ( c = Extra_UtilGetopt( argc, argv, "KSNPWFMCmcdpvwh" ) ) != EOF )
45594     {
45595         switch ( c )
45596         {
45597         case 'K':
45598             if ( globalUtilOptind >= argc )
45599             {
45600                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
45601                 goto usage;
45602             }
45603             pPars->nLutSize = atoi(argv[globalUtilOptind]);
45604             globalUtilOptind++;
45605             if ( pPars->nLutSize < 0 )
45606                 goto usage;
45607             break;
45608         case 'S':
45609             if ( globalUtilOptind >= argc )
45610             {
45611                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
45612                 goto usage;
45613             }
45614             pPars->nLutNum = atoi(argv[globalUtilOptind]);
45615             globalUtilOptind++;
45616             if ( pPars->nLutNum < 0 )
45617                 goto usage;
45618             break;
45619         case 'N':
45620             if ( globalUtilOptind >= argc )
45621             {
45622                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
45623                 goto usage;
45624             }
45625             pPars->nCutSize = atoi(argv[globalUtilOptind]);
45626             globalUtilOptind++;
45627             if ( pPars->nCutSize < 0 )
45628                 goto usage;
45629             break;
45630         case 'P':
45631             if ( globalUtilOptind >= argc )
45632             {
45633                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
45634                 goto usage;
45635             }
45636             pPars->nCutNum = atoi(argv[globalUtilOptind]);
45637             globalUtilOptind++;
45638             if ( pPars->nCutNum < 0 )
45639                 goto usage;
45640             break;
45641         case 'W':
45642             if ( globalUtilOptind >= argc )
45643             {
45644                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
45645                 goto usage;
45646             }
45647             pPars->nTfoLevels = atoi(argv[globalUtilOptind]);
45648             globalUtilOptind++;
45649             if ( pPars->nTfoLevels < 0 )
45650                 goto usage;
45651             break;
45652         case 'F':
45653             if ( globalUtilOptind >= argc )
45654             {
45655                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
45656                 goto usage;
45657             }
45658             pPars->nTfoFanMax = atoi(argv[globalUtilOptind]);
45659             globalUtilOptind++;
45660             if ( pPars->nTfoFanMax < 0 )
45661                 goto usage;
45662             break;
45663         case 'M':
45664             if ( globalUtilOptind >= argc )
45665             {
45666                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
45667                 goto usage;
45668             }
45669             pPars->nWinSizeMax = atoi(argv[globalUtilOptind]);
45670             globalUtilOptind++;
45671             if ( pPars->nWinSizeMax < 0 )
45672                 goto usage;
45673             break;
45674         case 'C':
45675             if ( globalUtilOptind >= argc )
45676             {
45677                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
45678                 goto usage;
45679             }
45680             pPars->nBTLimit = atoi(argv[globalUtilOptind]);
45681             globalUtilOptind++;
45682             if ( pPars->nBTLimit < 0 )
45683                 goto usage;
45684             break;
45685         case 'm':
45686             pPars->fMapping ^= 1;
45687             break;
45688         case 'c':
45689             pPars->fMoreCuts ^= 1;
45690             break;
45691         case 'd':
45692             pPars->fFindDivs ^= 1;
45693             break;
45694         case 'p':
45695             pPars->fUsePath ^= 1;
45696             break;
45697         case 'v':
45698             pPars->fVerbose ^= 1;
45699             break;
45700         case 'w':
45701             pPars->fVeryVerbose ^= 1;
45702             break;
45703         case 'h':
45704             goto usage;
45705         default:
45706             goto usage;
45707         }
45708     }
45709     if ( pAbc->pGia == NULL )
45710     {
45711         Abc_Print( -1, "Abc_CommandAbc9Mfsd(): There is no AIG.\n" );
45712         return 0;
45713     }
45714     if ( Gia_ManBufNum(pAbc->pGia) )
45715     {
45716         Abc_Print( -1, "Abc_CommandAbc9Mfsd(): This command does not work with barrier buffers.\n" );
45717         return 1;
45718     }
45719     if ( Gia_ManHasMapping(pAbc->pGia) )
45720         Abc_Print( 1, "The current AIG has mapping, which can be used to determine critical path if \"-p\" is selected.\n" );
45721     pTemp = Sbd_NtkPerform( pAbc->pGia, pPars );
45722     Abc_FrameUpdateGia( pAbc, pTemp );
45723     return 0;
45724 
45725 usage:
45726     Abc_Print( -2, "usage: &mfsd [-KSNPWFMC <num>] [-mcdpvwh]\n" );
45727     Abc_Print( -2, "\t           performs SAT-based delay-oriented AIG optimization\n" );
45728     Abc_Print( -2, "\t-K <num> : the LUT size for delay minimization (2 <= num <= 6) [default = %d]\n",         pPars->nLutSize );
45729     Abc_Print( -2, "\t-S <num> : the LUT structure size (1 <= num <= 2) [default = %d]\n",                      pPars->nLutNum );
45730     Abc_Print( -2, "\t-N <num> : the cut size considered for optimization (2 <= num <= 10) [default = %d]\n",   pPars->nCutSize );
45731     Abc_Print( -2, "\t-P <num> : the number of cuts computed at a node (1 <= num <= 500) [default = %d]\n",     pPars->nCutNum );
45732     Abc_Print( -2, "\t-W <num> : the number of levels in the TFO cone (0 <= num) [default = %d]\n",             pPars->nTfoLevels );
45733     Abc_Print( -2, "\t-F <num> : the max number of fanouts to skip (1 <= num) [default = %d]\n",                pPars->nTfoFanMax );
45734     Abc_Print( -2, "\t-M <num> : the max node count of windows to consider (0 = no limit) [default = %d]\n",    pPars->nWinSizeMax );
45735     Abc_Print( -2, "\t-C <num> : the max number of conflicts in one SAT run (0 = no limit) [default = %d]\n",   pPars->nBTLimit );
45736     Abc_Print( -2, "\t-m       : toggle generating delay-oriented mapping [default = %s]\n",                    pPars->fMapping? "yes": "no" );
45737     Abc_Print( -2, "\t-c       : toggle using several cuts at each node [default = %s]\n",                      pPars->fMoreCuts? "yes": "no" );
45738     Abc_Print( -2, "\t-d       : toggle additional search for good divisors [default = %s]\n",                  pPars->fFindDivs? "yes": "no" );
45739     Abc_Print( -2, "\t-p       : toggle optimizing critical path only [default = %s]\n",                        pPars->fUsePath? "yes": "no" );
45740     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n",                        pPars->fVerbose? "yes": "no" );
45741     Abc_Print( -2, "\t-w       : toggle printing detailed stats for each node [default = %s]\n",                pPars->fVeryVerbose? "yes": "no" );
45742     Abc_Print( -2, "\t-h       : print the command usage\n");
45743     return 1;
45744 }
45745 
45746 /**Function*************************************************************
45747 
45748   Synopsis    []
45749 
45750   Description []
45751 
45752   SideEffects []
45753 
45754   SeeAlso     []
45755 
45756 ***********************************************************************/
Abc_CommandAbc9DeepSyn(Abc_Frame_t * pAbc,int argc,char ** argv)45757 int Abc_CommandAbc9DeepSyn( Abc_Frame_t * pAbc, int argc, char ** argv )
45758 {
45759     extern Gia_Man_t * Gia_ManDeepSyn( Gia_Man_t * pGia, int TimeOut, int nAnds, int Seed, int fVerbose );
45760     Gia_Man_t * pTemp; int c, TimeOut = 0, nAnds = 0, Seed = 0, fVerbose = 0;
45761     Extra_UtilGetoptReset();
45762     while ( ( c = Extra_UtilGetopt( argc, argv, "TASvh" ) ) != EOF )
45763     {
45764         switch ( c )
45765         {
45766         case 'T':
45767             if ( globalUtilOptind >= argc )
45768             {
45769                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
45770                 goto usage;
45771             }
45772             TimeOut = atoi(argv[globalUtilOptind]);
45773             globalUtilOptind++;
45774             if ( TimeOut < 0 )
45775                 goto usage;
45776             break;
45777         case 'A':
45778             if ( globalUtilOptind >= argc )
45779             {
45780                 Abc_Print( -1, "Command line switch \"-A\" should be followed by an integer.\n" );
45781                 goto usage;
45782             }
45783             nAnds = atoi(argv[globalUtilOptind]);
45784             globalUtilOptind++;
45785             if ( nAnds < 0 )
45786                 goto usage;
45787             break;
45788         case 'S':
45789             if ( globalUtilOptind >= argc )
45790             {
45791                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
45792                 goto usage;
45793             }
45794             Seed = atoi(argv[globalUtilOptind]);
45795             globalUtilOptind++;
45796             if ( Seed < 0 )
45797                 goto usage;
45798             break;
45799         case 'v':
45800             fVerbose ^= 1;
45801             break;
45802         case 'h':
45803             goto usage;
45804         default:
45805             goto usage;
45806         }
45807     }
45808     if ( pAbc->pGia == NULL )
45809     {
45810         Abc_Print( -1, "Abc_CommandAbc9DeepSyn(): There is no AIG.\n" );
45811         return 0;
45812     }
45813     pTemp = Gia_ManDeepSyn( pAbc->pGia, TimeOut, nAnds, Seed, fVerbose );
45814     Abc_FrameUpdateGia( pAbc, pTemp );
45815     return 0;
45816 
45817 usage:
45818     Abc_Print( -2, "usage: &deepsyn [-TAS <num>] [-vh]\n" );
45819     Abc_Print( -2, "\t           performs synthesis\n" );
45820     Abc_Print( -2, "\t-T <num> : the timeout in seconds (0 = no timeout) [default = %d]\n",    TimeOut );
45821     Abc_Print( -2, "\t-A <num> : the number of nodes to stop (0 = no limit) [default = %d]\n", nAnds   );
45822     Abc_Print( -2, "\t-S <num> : user-specified random seed (0 <= num <= 100) [default = %d]\n", Seed   );
45823     Abc_Print( -2, "\t-v       : toggle printing optimization summary [default = %s]\n",       fVerbose? "yes": "no" );
45824     Abc_Print( -2, "\t-h       : print the command usage\n");
45825     return 1;
45826 }
45827 
45828 /**Function*************************************************************
45829 
45830   Synopsis    []
45831 
45832   Description []
45833 
45834   SideEffects []
45835 
45836   SeeAlso     []
45837 
45838 ***********************************************************************/
Abc_CommandAbc9CexCut(Abc_Frame_t * pAbc,int argc,char ** argv)45839 int Abc_CommandAbc9CexCut( Abc_Frame_t * pAbc, int argc, char ** argv )
45840 {
45841     return -1;
45842 }
45843 
45844 /**Function*************************************************************
45845 
45846   Synopsis    []
45847 
45848   Description []
45849 
45850   SideEffects []
45851 
45852   SeeAlso     []
45853 
45854 ***********************************************************************/
Abc_CommandAbc9CexMerge(Abc_Frame_t * pAbc,int argc,char ** argv)45855 int Abc_CommandAbc9CexMerge( Abc_Frame_t * pAbc, int argc, char ** argv )
45856 {
45857     Abc_Cex_t * pCexNew;
45858     int c;
45859     int iFrStart = 0;
45860     int iFrStop  = ABC_INFINITY;
45861     int fVerbose = 0;
45862     Extra_UtilGetoptReset();
45863     while ( ( c = Extra_UtilGetopt( argc, argv, "FGvh" ) ) != EOF )
45864     {
45865         switch ( c )
45866         {
45867         case 'F':
45868             if ( globalUtilOptind >= argc )
45869             {
45870                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
45871                 goto usage;
45872             }
45873             iFrStart = atoi(argv[globalUtilOptind]);
45874             globalUtilOptind++;
45875             if ( iFrStart < 0 )
45876                 goto usage;
45877             break;
45878         case 'G':
45879             if ( globalUtilOptind >= argc )
45880             {
45881                 Abc_Print( -1, "Command line switch \"-G\" should be followed by an integer.\n" );
45882                 goto usage;
45883             }
45884             iFrStop = atoi(argv[globalUtilOptind]);
45885             globalUtilOptind++;
45886             if ( iFrStop < 0 )
45887                 goto usage;
45888             break;
45889         case 'v':
45890             fVerbose ^= 1;
45891             break;
45892         case 'h':
45893             goto usage;
45894         default:
45895             Abc_Print( -2, "Unknown switch.\n");
45896             goto usage;
45897         }
45898     }
45899 
45900     if ( pAbc->pCex == NULL )
45901     {
45902         Abc_Print( 1, "There is no current cex.\n");
45903         return 0;
45904     }
45905     if ( pAbc->pCex2 == NULL )
45906     {
45907         Abc_Print( 1, "There is no saved cex.\n");
45908         return 0;
45909     }
45910     if ( iFrStop - iFrStart < pAbc->pCex->iFrame )
45911     {
45912         Abc_Print( 1, "Current CEX does not allow to shorten the saved CEX.\n");
45913         return 0;
45914     }
45915     pCexNew = Abc_CexMerge( pAbc->pCex2, pAbc->pCex, iFrStart, iFrStop );
45916     if ( pCexNew == NULL )
45917     {
45918         Abc_Print( 1, "Merging CEXes has failed.\n");
45919         return 0;
45920     }
45921     // replace the saved CEX
45922     ABC_FREE( pAbc->pCex2 );
45923     pAbc->pCex2 = pCexNew;
45924     return 0;
45925 
45926 usage:
45927     Abc_Print( -2, "usage: &cexmerge [-FG num] [-vh]\n" );
45928     Abc_Print( -2, "\t         merges the current CEX into the saved one\n" );
45929     Abc_Print( -2, "\t         and sets the resulting CEX as the saved one\n" );
45930     Abc_Print( -2, "\t-F num : 0-based number of the starting frame [default = %d]\n", iFrStart );
45931     Abc_Print( -2, "\t-G num : 0-based number of the ending frame [default = %d]\n",   iFrStop );
45932     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
45933     Abc_Print( -2, "\t-h     : print the command usage\n");
45934     return 1;
45935 }
45936 
45937 /**Function*************************************************************
45938 
45939   Synopsis    []
45940 
45941   Description []
45942 
45943   SideEffects []
45944 
45945   SeeAlso     []
45946 
45947 ***********************************************************************/
Abc_CommandAbc9CexMin(Abc_Frame_t * pAbc,int argc,char ** argv)45948 int Abc_CommandAbc9CexMin( Abc_Frame_t * pAbc, int argc, char ** argv )
45949 {
45950     extern Abc_Cex_t * Gia_ManCexMin( Gia_Man_t * p, Abc_Cex_t * pCex, int iFrameStart, int nRealPis, int fJustMax, int fUseAll, int fVerbose );
45951     Abc_Cex_t * pCexNew;
45952     int iFrameStart = 0;
45953     int nRealPis = -1;
45954     int fJustMax = 1;
45955     int fUseAll = 0;
45956     int c, fVerbose = 0;
45957     Extra_UtilGetoptReset();
45958     while ( ( c = Extra_UtilGetopt( argc, argv, "FNjavh" ) ) != EOF )
45959     {
45960         switch ( c )
45961         {
45962         case 'F':
45963             if ( globalUtilOptind >= argc )
45964             {
45965                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
45966                 goto usage;
45967             }
45968             iFrameStart = atoi(argv[globalUtilOptind]);
45969             globalUtilOptind++;
45970             if ( iFrameStart < 0 )
45971                 goto usage;
45972             break;
45973         case 'N':
45974             if ( globalUtilOptind >= argc )
45975             {
45976                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
45977                 goto usage;
45978             }
45979             nRealPis = atoi(argv[globalUtilOptind]);
45980             globalUtilOptind++;
45981             if ( nRealPis < 0 )
45982                 goto usage;
45983             break;
45984         case 'j':
45985             fJustMax ^= 1;
45986             break;
45987         case 'a':
45988             fUseAll ^= 1;
45989             break;
45990         case 'v':
45991             fVerbose ^= 1;
45992             break;
45993         case 'h':
45994             goto usage;
45995         default:
45996             goto usage;
45997         }
45998     }
45999     if ( pAbc->pGia == NULL )
46000     {
46001         Abc_Print( -1, "Abc_CommandAbc9CexMin(): There is no AIG.\n" );
46002         return 1;
46003     }
46004     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
46005     {
46006         Abc_Print( -1, "Abc_CommandAbc9CexMin(): The network is combinational.\n" );
46007         return 0;
46008     }
46009     if ( pAbc->pCex == NULL )
46010     {
46011         Abc_Print( -1, "Abc_CommandAbc9CexMin(): There is no counter-example.\n" );
46012         return 1;
46013     }
46014     pCexNew = Gia_ManCexMin( pAbc->pGia, pAbc->pCex, iFrameStart, nRealPis, fJustMax, fUseAll, fVerbose );
46015     if ( pCexNew )
46016         Abc_FrameReplaceCex( pAbc, &pCexNew );
46017     return 0;
46018 
46019 usage:
46020     Abc_Print( -2, "usage: &cexmin [-FN num] [-javh]\n" );
46021     Abc_Print( -2, "\t         minimizes a deep counter-example\n" );
46022     Abc_Print( -2, "\t-F num : starting timeframe for minimization [default = %d]\n", iFrameStart );
46023     Abc_Print( -2, "\t-N num : the number of real primary inputs [default = %d]\n", nRealPis );
46024     Abc_Print( -2, "\t-j     : toggle computing all justifying assignments [default = %s]\n", fJustMax? "yes": "no" );
46025     Abc_Print( -2, "\t-a     : toggle using all terminal objects [default = %s]\n", fUseAll? "yes": "no" );
46026     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
46027     Abc_Print( -2, "\t-h     : print the command usage\n");
46028     return 1;
46029 }
46030 
46031 
46032 /**Function*************************************************************
46033 
46034   Synopsis    []
46035 
46036   Description []
46037 
46038   SideEffects []
46039 
46040   SeeAlso     []
46041 
46042 ***********************************************************************/
Abc_CommandAbc9AbsCreate(Abc_Frame_t * pAbc,int argc,char ** argv)46043 int Abc_CommandAbc9AbsCreate( Abc_Frame_t * pAbc, int argc, char ** argv )
46044 {
46045     //Gia_Man_t * pTemp = NULL;
46046     char * pStr, * pFlopNum;
46047     int c, fVerbose = 0;
46048     Extra_UtilGetoptReset();
46049     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
46050     {
46051         switch ( c )
46052         {
46053         case 'v':
46054             fVerbose ^= 1;
46055             break;
46056         case 'h':
46057             goto usage;
46058         default:
46059             goto usage;
46060         }
46061     }
46062     if ( pAbc->pGia == NULL )
46063     {
46064         Abc_Print( -1, "Abc_CommandAbc9AbsCreate(): There is no AIG.\n" );
46065         return 1;
46066     }
46067     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
46068     {
46069         Abc_Print( -1, "The network is combinational.\n" );
46070         return 0;
46071     }
46072     if ( pAbc->pGia->vFlopClasses != NULL )
46073     {
46074         Abc_Print( -1, "Abstraction flop map is already defined.\n" );
46075         return 0;
46076     }
46077     pAbc->pGia->vFlopClasses = Vec_IntStart( Gia_ManRegNum(pAbc->pGia) );
46078     // read the flop list
46079     if ( argc != globalUtilOptind + 1 )
46080     {
46081         Abc_Print( -1, "Flop list should be specified on the command line.\n" );
46082         return 0;
46083     }
46084     pStr = argv[globalUtilOptind];
46085     // parse flop list
46086     pFlopNum = strtok( pStr, " ," );
46087     while ( pFlopNum )
46088     {
46089         int iFlop = atoi(pFlopNum);
46090         assert( iFlop >= 0 && iFlop < Gia_ManRegNum(pAbc->pGia) );
46091         Vec_IntWriteEntry( pAbc->pGia->vFlopClasses, iFlop, 1 );
46092         pFlopNum = strtok( NULL, " ," );
46093     }
46094     return 0;
46095 
46096 usage:
46097     Abc_Print( -2, "usage: &abs_create [-vh] <comma-separated_list_of_zero-based_flop_ids>\n" );
46098     Abc_Print( -2, "\t        creates new flop map by reading user's input\n" );
46099     Abc_Print( -2, "\t-v    : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
46100     Abc_Print( -2, "\t-h    : print the command usage\n");
46101     return 1;
46102 }
46103 
46104 /**Function*************************************************************
46105 
46106   Synopsis    []
46107 
46108   Description []
46109 
46110   SideEffects []
46111 
46112   SeeAlso     []
46113 
46114 ***********************************************************************/
Abc_CommandAbc9AbsDerive(Abc_Frame_t * pAbc,int argc,char ** argv)46115 int Abc_CommandAbc9AbsDerive( Abc_Frame_t * pAbc, int argc, char ** argv )
46116 {
46117     Gia_Man_t * pTemp = NULL;
46118     int c, fVerbose = 0;
46119     Extra_UtilGetoptReset();
46120     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
46121     {
46122         switch ( c )
46123         {
46124         case 'v':
46125             fVerbose ^= 1;
46126             break;
46127         case 'h':
46128             goto usage;
46129         default:
46130             goto usage;
46131         }
46132     }
46133     if ( pAbc->pGia == NULL )
46134     {
46135         Abc_Print( -1, "Abc_CommandAbc9AbsDerive(): There is no AIG.\n" );
46136         return 1;
46137     }
46138     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
46139     {
46140         Abc_Print( -1, "The network is combinational.\n" );
46141         return 0;
46142     }
46143     if ( pAbc->pGia->vFlopClasses == NULL )
46144     {
46145         Abc_Print( -1, "Abstraction flop map is missing.\n" );
46146         return 0;
46147     }
46148     pTemp = Gia_ManDupAbsFlops( pAbc->pGia, pAbc->pGia->vFlopClasses );
46149     Abc_FrameUpdateGia( pAbc, pTemp );
46150     return 0;
46151 
46152 usage:
46153     Abc_Print( -2, "usage: &abs_derive [-vh]\n" );
46154     Abc_Print( -2, "\t        derives abstracted model using the pre-computed flop map\n" );
46155     Abc_Print( -2, "\t-v    : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
46156     Abc_Print( -2, "\t-h    : print the command usage\n");
46157     return 1;
46158 }
46159 
46160 /**Function*************************************************************
46161 
46162   Synopsis    []
46163 
46164   Description []
46165 
46166   SideEffects []
46167 
46168   SeeAlso     []
46169 
46170 ***********************************************************************/
Abc_CommandAbc9AbsRefine(Abc_Frame_t * pAbc,int argc,char ** argv)46171 int Abc_CommandAbc9AbsRefine( Abc_Frame_t * pAbc, int argc, char ** argv )
46172 {
46173 //    Gia_Man_t * pTemp = NULL;
46174     int c;
46175     int nFfToAddMax = 0;
46176     int fTryFour    = 1;
46177     int fSensePath  = 0;
46178     int fVerbose    = 0;
46179 
46180     Extra_UtilGetoptReset();
46181     while ( ( c = Extra_UtilGetopt( argc, argv, "Mtsvh" ) ) != EOF )
46182     {
46183         switch ( c )
46184         {
46185         case 'M':
46186             if ( globalUtilOptind >= argc )
46187             {
46188                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
46189                 goto usage;
46190             }
46191             nFfToAddMax = atoi(argv[globalUtilOptind]);
46192             globalUtilOptind++;
46193             if ( nFfToAddMax < 0 )
46194                 goto usage;
46195             break;
46196         case 't':
46197             fTryFour ^= 1;
46198             break;
46199         case 's':
46200             fSensePath ^= 1;
46201             break;
46202         case 'v':
46203             fVerbose ^= 1;
46204             break;
46205         case 'h':
46206             goto usage;
46207         default:
46208             goto usage;
46209         }
46210     }
46211     if ( pAbc->pGia == NULL )
46212     {
46213         Abc_Print( -1, "Abc_CommandAbc9AbsRefine(): There is no AIG.\n" );
46214         return 1;
46215     }
46216     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
46217     {
46218         Abc_Print( -1, "The network is combinational.\n" );
46219         return 0;
46220     }
46221     if ( pAbc->pCex == NULL )
46222     {
46223         Abc_Print( -1, "Abc_CommandAbc9AbsRefine(): There is no counter-example.\n" );
46224         return 1;
46225     }
46226     pAbc->Status = Gia_ManCexAbstractionRefine( pAbc->pGia, pAbc->pCex, nFfToAddMax, fTryFour, fSensePath, fVerbose );
46227     Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexSeq );
46228     return 0;
46229 
46230 usage:
46231     Abc_Print( -2, "usage: &abs_refine [-M <num>] [-tsvh]\n" );
46232     Abc_Print( -2, "\t         refines the pre-computed flop map using the counter-example\n" );
46233     Abc_Print( -2, "\t-M num : the max number of flops to add (0 = not used) [default = %d]\n", nFfToAddMax );
46234     Abc_Print( -2, "\t-t     : toggle trying four abstractions instead of one [default = %s]\n", fTryFour? "yes": "no" );
46235     Abc_Print( -2, "\t-s     : toggle using the path sensitization algorithm [default = %s]\n", fSensePath? "yes": "no" );
46236     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
46237     Abc_Print( -2, "\t-h     : print the command usage\n");
46238     return 1;
46239 }
46240 
46241 
46242 /**Function*************************************************************
46243 
46244   Synopsis    []
46245 
46246   Description []
46247 
46248   SideEffects []
46249 
46250   SeeAlso     []
46251 
46252 ***********************************************************************/
Abc_CommandAbc9GlaDerive(Abc_Frame_t * pAbc,int argc,char ** argv)46253 int Abc_CommandAbc9GlaDerive( Abc_Frame_t * pAbc, int argc, char ** argv )
46254 {
46255     Gia_Man_t * pTemp = NULL;
46256     int c, fVerbose = 0;
46257     Extra_UtilGetoptReset();
46258     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
46259     {
46260         switch ( c )
46261         {
46262         case 'v':
46263             fVerbose ^= 1;
46264             break;
46265         case 'h':
46266             goto usage;
46267         default:
46268             goto usage;
46269         }
46270     }
46271     if ( pAbc->pGia == NULL )
46272     {
46273         Abc_Print( -1, "Abc_CommandAbc9GlaDerive(): There is no AIG.\n" );
46274         return 1;
46275     }
46276 /*
46277     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
46278     {
46279         Abc_Print( -1, "The network is combinational.\n" );
46280         return 0;
46281     }
46282 */
46283     if ( pAbc->fBatchMode && (pAbc->Status == 0 || pAbc->Status == 1) )
46284     {
46285         Abc_Print( 1, "The miters is already solved; skipping the command.\n" );
46286         return 0;
46287     }
46288     if ( pAbc->pGia->vGateClasses == NULL )
46289     {
46290         Abc_Print( -1, "Abstraction gate map is missing.\n" );
46291         return 0;
46292     }
46293     pTemp = Gia_ManDupAbsGates( pAbc->pGia, pAbc->pGia->vGateClasses );
46294     Gia_ManStop( pTemp );
46295     pTemp = Gia_ManDupAbsGates( pAbc->pGia, pAbc->pGia->vGateClasses );
46296     Abc_FrameUpdateGia( pAbc, pTemp );
46297 //    Abc_Print( 1,"This command is currently not enabled.\n" );
46298     return 0;
46299 
46300 usage:
46301     Abc_Print( -2, "usage: &gla_derive [-vh]\n" );
46302     Abc_Print( -2, "\t        derives abstracted model using the pre-computed gate map\n" );
46303     Abc_Print( -2, "\t-v    : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
46304     Abc_Print( -2, "\t-h    : print the command usage\n");
46305     return 1;
46306 }
46307 
46308 /**Function*************************************************************
46309 
46310   Synopsis    []
46311 
46312   Description []
46313 
46314   SideEffects []
46315 
46316   SeeAlso     []
46317 
46318 ***********************************************************************/
Abc_CommandAbc9GlaRefine(Abc_Frame_t * pAbc,int argc,char ** argv)46319 int Abc_CommandAbc9GlaRefine( Abc_Frame_t * pAbc, int argc, char ** argv )
46320 {
46321     extern int Gia_ManNewRefine( Gia_Man_t * p, Abc_Cex_t * pCex, int iFrameStart, int iFrameExtra, int fVerbose );
46322     int iFrameStart = 0;
46323     int iFrameExtra = 0;
46324     int fMinCut = 1;
46325     int c, fVerbose = 0;
46326     Extra_UtilGetoptReset();
46327     while ( ( c = Extra_UtilGetopt( argc, argv, "FGmvh" ) ) != EOF )
46328     {
46329         switch ( c )
46330         {
46331         case 'F':
46332             if ( globalUtilOptind >= argc )
46333             {
46334                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
46335                 goto usage;
46336             }
46337             iFrameStart = atoi(argv[globalUtilOptind]);
46338             globalUtilOptind++;
46339             if ( iFrameStart < 0 )
46340                 goto usage;
46341             break;
46342         case 'G':
46343             if ( globalUtilOptind >= argc )
46344             {
46345                 Abc_Print( -1, "Command line switch \"-G\" should be followed by an integer.\n" );
46346                 goto usage;
46347             }
46348             iFrameExtra = atoi(argv[globalUtilOptind]);
46349             globalUtilOptind++;
46350             if ( iFrameExtra < 0 )
46351                 goto usage;
46352             break;
46353         case 'm':
46354             fMinCut ^= 1;
46355             break;
46356         case 'v':
46357             fVerbose ^= 1;
46358             break;
46359         case 'h':
46360             goto usage;
46361         default:
46362             goto usage;
46363         }
46364     }
46365     if ( pAbc->pGia == NULL )
46366     {
46367         Abc_Print( -1, "Abc_CommandAbc9GlaRefine(): There is no AIG.\n" );
46368         return 1;
46369     }
46370     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
46371     {
46372         Abc_Print( -1, "The network is combinational.\n" );
46373         return 0;
46374     }
46375     if ( pAbc->pCex == NULL )
46376     {
46377         Abc_Print( -1, "Abc_CommandAbc9GlaRefine(): There is no counter-example.\n" );
46378         return 1;
46379     }
46380     pAbc->Status = Gia_ManNewRefine( pAbc->pGia, pAbc->pCex, iFrameStart, iFrameExtra, fVerbose );
46381     Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexSeq );
46382     return 0;
46383 
46384 usage:
46385     Abc_Print( -2, "usage: &gla_refine [-FG num] [-vh]\n" );
46386     Abc_Print( -2, "\t         refines the pre-computed gate map using the counter-example\n" );
46387     Abc_Print( -2, "\t-F num : starting timeframe for suffix refinement [default = %d]\n", iFrameStart );
46388     Abc_Print( -2, "\t-G num : the number of additional timeframes to try [default = %d]\n", iFrameExtra );
46389 //    Abc_Print( -2, "\t-m     : toggle using min-cut to derive the refinements [default = %s]\n", fMinCut? "yes": "no" );
46390     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
46391     Abc_Print( -2, "\t-h     : print the command usage\n");
46392     return 1;
46393 }
46394 
46395 /**Function*************************************************************
46396 
46397   Synopsis    []
46398 
46399   Description []
46400 
46401   SideEffects []
46402 
46403   SeeAlso     []
46404 
46405 ***********************************************************************/
Abc_CommandAbc9GlaShrink(Abc_Frame_t * pAbc,int argc,char ** argv)46406 int Abc_CommandAbc9GlaShrink( Abc_Frame_t * pAbc, int argc, char ** argv )
46407 {
46408     int fUsePdr = 0;
46409     int fUseSat = 1;
46410     int fUseBdd = 0;
46411     int nFrameMax = 0;
46412     int nTimeOut = 0;
46413     int c, fVerbose = 0;
46414     Extra_UtilGetoptReset();
46415     while ( ( c = Extra_UtilGetopt( argc, argv, "FTpsbvh" ) ) != EOF )
46416     {
46417         switch ( c )
46418         {
46419         case 'F':
46420             if ( globalUtilOptind >= argc )
46421             {
46422                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
46423                 goto usage;
46424             }
46425             nFrameMax = atoi(argv[globalUtilOptind]);
46426             globalUtilOptind++;
46427             if ( nFrameMax < 0 )
46428                 goto usage;
46429             break;
46430         case 'T':
46431             if ( globalUtilOptind >= argc )
46432             {
46433                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
46434                 goto usage;
46435             }
46436             nTimeOut = atoi(argv[globalUtilOptind]);
46437             globalUtilOptind++;
46438             if ( nTimeOut < 0 )
46439                 goto usage;
46440             break;
46441         case 'p':
46442             fUsePdr ^= 1;
46443             break;
46444         case 's':
46445             fUseSat ^= 1;
46446             break;
46447         case 'b':
46448             fUseBdd ^= 1;
46449             break;
46450         case 'v':
46451             fVerbose ^= 1;
46452             break;
46453         case 'h':
46454             goto usage;
46455         default:
46456             goto usage;
46457         }
46458     }
46459     if ( pAbc->pGia == NULL )
46460     {
46461         Abc_Print( -1, "Abc_CommandAbc9GlaShrink(): There is no AIG.\n" );
46462         return 1;
46463     }
46464     if ( pAbc->pGia->vGateClasses == NULL )
46465     {
46466         Abc_Print( -1, "Abc_CommandAbc9GlaShrink(): There is no gate-level abstraction.\n" );
46467         return 0;
46468     }
46469     Gia_ManShrinkGla( pAbc->pGia, nFrameMax, nTimeOut, fUsePdr, fUseSat, fUseBdd, fVerbose );
46470     return 0;
46471 
46472 usage:
46473     Abc_Print( -2, "usage: &gla_shrink [-FT num] [-psbvh]\n" );
46474     Abc_Print( -2, "\t         shrinks the abstraction by removing redundant objects\n" );
46475     Abc_Print( -2, "\t-F num : the maximum timeframe to check to [default = %d]\n", nFrameMax );
46476     Abc_Print( -2, "\t-T num : the timeout per call, in seconds [default = %d]\n", nTimeOut );
46477     Abc_Print( -2, "\t-p     : toggle using PDR for checking [default = %s]\n", fUsePdr? "yes": "no" );
46478     Abc_Print( -2, "\t-s     : toggle using BMC for checking [default = %s]\n", fUseSat? "yes": "no" );
46479     Abc_Print( -2, "\t-b     : toggle using BDDs for checking [default = %s]\n", fUseBdd? "yes": "no" );
46480     Abc_Print( -2, "\t-v     : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
46481     Abc_Print( -2, "\t-h     : print the command usage\n");
46482     return 1;
46483 }
46484 
46485 
46486 /**Function*************************************************************
46487 
46488   Synopsis    []
46489 
46490   Description []
46491 
46492   SideEffects []
46493 
46494   SeeAlso     []
46495 
46496 ***********************************************************************/
Abc_CommandAbc9Gla(Abc_Frame_t * pAbc,int argc,char ** argv)46497 int Abc_CommandAbc9Gla( Abc_Frame_t * pAbc, int argc, char ** argv )
46498 {
46499     Abs_Par_t Pars, * pPars = &Pars;
46500     int c, fNewAlgo = 1;
46501     char * pLogFileName = NULL;
46502     Abs_ParSetDefaults( pPars );
46503     Extra_UtilGetoptReset();
46504     while ( ( c = Extra_UtilGetopt( argc, argv, "FSCMDETRQPBALtfardmnscbpquwvh" ) ) != EOF )
46505     {
46506         switch ( c )
46507         {
46508         case 'F':
46509             if ( globalUtilOptind >= argc )
46510             {
46511                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
46512                 goto usage;
46513             }
46514             pPars->nFramesMax = atoi(argv[globalUtilOptind]);
46515             globalUtilOptind++;
46516             if ( pPars->nFramesMax < 0 )
46517                 goto usage;
46518             break;
46519         case 'S':
46520             if ( globalUtilOptind >= argc )
46521             {
46522                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
46523                 goto usage;
46524             }
46525             pPars->nFramesStart = atoi(argv[globalUtilOptind]);
46526             globalUtilOptind++;
46527             if ( pPars->nFramesStart < 0 )
46528                 goto usage;
46529             break;
46530         case 'C':
46531             if ( globalUtilOptind >= argc )
46532             {
46533                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
46534                 goto usage;
46535             }
46536             pPars->nConfLimit = atoi(argv[globalUtilOptind]);
46537             globalUtilOptind++;
46538             if ( pPars->nConfLimit < 0 )
46539                 goto usage;
46540             break;
46541         case 'M':
46542             if ( globalUtilOptind >= argc )
46543             {
46544                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
46545                 goto usage;
46546             }
46547             pPars->nLearnedStart = atoi(argv[globalUtilOptind]);
46548             globalUtilOptind++;
46549             if ( pPars->nLearnedStart < 0 )
46550                 goto usage;
46551             break;
46552         case 'D':
46553             if ( globalUtilOptind >= argc )
46554             {
46555                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
46556                 goto usage;
46557             }
46558             pPars->nLearnedDelta = atoi(argv[globalUtilOptind]);
46559             globalUtilOptind++;
46560             if ( pPars->nLearnedDelta < 0 )
46561                 goto usage;
46562             break;
46563         case 'E':
46564             if ( globalUtilOptind >= argc )
46565             {
46566                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
46567                 goto usage;
46568             }
46569             pPars->nLearnedPerce = atoi(argv[globalUtilOptind]);
46570             globalUtilOptind++;
46571             if ( pPars->nLearnedPerce < 0 )
46572                 goto usage;
46573             break;
46574         case 'T':
46575             if ( globalUtilOptind >= argc )
46576             {
46577                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
46578                 goto usage;
46579             }
46580             pPars->nTimeOut = atoi(argv[globalUtilOptind]);
46581             globalUtilOptind++;
46582             if ( pPars->nTimeOut < 0 )
46583                 goto usage;
46584             break;
46585         case 'R':
46586             if ( globalUtilOptind >= argc )
46587             {
46588                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
46589                 goto usage;
46590             }
46591             pPars->nRatioMin = atoi(argv[globalUtilOptind]);
46592             globalUtilOptind++;
46593             if ( pPars->nRatioMin < 0 )
46594                 goto usage;
46595             break;
46596         case 'Q':
46597             if ( globalUtilOptind >= argc )
46598             {
46599                 Abc_Print( -1, "Command line switch \"-Q\" should be followed by an integer.\n" );
46600                 goto usage;
46601             }
46602             pPars->nRatioMin2 = atoi(argv[globalUtilOptind]);
46603             globalUtilOptind++;
46604             if ( pPars->nRatioMin2 < 0 )
46605                 goto usage;
46606             break;
46607         case 'P':
46608             if ( globalUtilOptind >= argc )
46609             {
46610                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
46611                 goto usage;
46612             }
46613             pPars->nRatioMax = atoi(argv[globalUtilOptind]);
46614             globalUtilOptind++;
46615             if ( pPars->nRatioMax < 0 )
46616                 goto usage;
46617             break;
46618         case 'B':
46619             if ( globalUtilOptind >= argc )
46620             {
46621                 Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" );
46622                 goto usage;
46623             }
46624             pPars->nFramesNoChangeLim = atoi(argv[globalUtilOptind]);
46625             globalUtilOptind++;
46626             if ( pPars->nFramesNoChangeLim < 0 )
46627                 goto usage;
46628             break;
46629         case 'A':
46630             if ( globalUtilOptind >= argc )
46631             {
46632                 Abc_Print( -1, "Command line switch \"-A\" should be followed by a file name.\n" );
46633                 goto usage;
46634             }
46635             pPars->pFileVabs = argv[globalUtilOptind];
46636             globalUtilOptind++;
46637             break;
46638         case 'L':
46639             if ( globalUtilOptind >= argc )
46640             {
46641                 Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
46642                 goto usage;
46643             }
46644             pLogFileName = argv[globalUtilOptind];
46645             globalUtilOptind++;
46646             break;
46647         case 't':
46648             pPars->fUseTermVars ^= 1;
46649             break;
46650         case 'f':
46651             pPars->fPropFanout ^= 1;
46652             break;
46653         case 'a':
46654             pPars->fAddLayer ^= 1;
46655             break;
46656         case 'r':
46657             pPars->fNewRefine ^= 1;
46658             break;
46659         case 'd':
46660             pPars->fDumpVabs ^= 1;
46661             break;
46662         case 'm':
46663             pPars->fDumpMabs ^= 1;
46664             break;
46665         case 'n':
46666             fNewAlgo ^= 1;
46667             break;
46668         case 's':
46669             pPars->fUseSkip ^= 1;
46670             break;
46671         case 'c':
46672             pPars->fUseSimple ^= 1;
46673             break;
46674         case 'b':
46675             pPars->fSkipHash ^= 1;
46676             break;
46677         case 'p':
46678             pPars->fUseFullProof ^= 1;
46679             break;
46680         case 'q':
46681             pPars->fCallProver ^= 1;
46682             break;
46683         case 'u':
46684             pPars->fSimpProver ^= 1;
46685             break;
46686         case 'v':
46687             pPars->fVerbose ^= 1;
46688             break;
46689         case 'w':
46690             pPars->fVeryVerbose ^= 1;
46691             break;
46692         case 'h':
46693             goto usage;
46694         default:
46695             goto usage;
46696         }
46697     }
46698     if ( pAbc->pGia == NULL )
46699     {
46700         Abc_Print( -1, "There is no AIG.\n" );
46701         return 0;
46702     }
46703 /*
46704     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
46705     {
46706         Abc_Print( -1, "The network is combinational.\n" );
46707         return 0;
46708     }
46709 */
46710     if ( pPars->nFramesMax < 0 )
46711     {
46712         Abc_Print( 1, "The number of starting frames should be a positive integer.\n" );
46713         return 0;
46714     }
46715     if ( pPars->nFramesMax && pPars->nFramesStart > pPars->nFramesMax )
46716     {
46717         Abc_Print( 1, "The starting frame is larger than the max number of frames.\n" );
46718         return 0;
46719     }
46720     if ( Gia_ManPoNum(pAbc->pGia) == 1 )
46721     {
46722         if ( fNewAlgo )
46723             pAbc->Status = Gia_ManPerformGla( pAbc->pGia, pPars );
46724         else
46725             pAbc->Status  = Gia_ManPerformGlaOld( pAbc->pGia, pPars, 0 );
46726         pAbc->nFrames = pPars->iFrame;
46727         Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexSeq );
46728         if ( pLogFileName )
46729             Abc_NtkWriteLogFile( pLogFileName, pAbc->pCex, pAbc->Status, pAbc->nFrames, "&gla" );
46730     }
46731     else // iterate over outputs
46732     {
46733         Gia_Obj_t * pObj; int o, Status;
46734         Vec_Ptr_t * vSeqModelVec = Vec_PtrStart( Gia_ManPoNum(pAbc->pGia) );
46735         Vec_Int_t * vStatuses = Vec_IntAlloc( Gia_ManPoNum(pAbc->pGia) );
46736         Gia_ManForEachPo( pAbc->pGia, pObj, o )
46737         {
46738             Gia_Man_t * pOne = Gia_ManDupDfsOnePo( pAbc->pGia, o );
46739             if ( fNewAlgo )
46740                 Status = Gia_ManPerformGla( pOne, pPars );
46741             else
46742                 Status = Gia_ManPerformGlaOld( pOne, pPars, 0 );
46743             Vec_IntPush( vStatuses, Status );
46744             if ( pLogFileName )
46745                 Abc_NtkWriteLogFile( pLogFileName, pOne->pCexSeq, Status, pPars->iFrame, "&gla" );
46746             if ( pOne->pCexSeq )
46747                 Vec_PtrWriteEntry( vSeqModelVec, o, pOne->pCexSeq );
46748             pOne->pCexSeq = NULL;
46749             Gia_ManStop( pOne );
46750         }
46751         assert( Vec_IntSize(vStatuses) == Gia_ManPoNum(pAbc->pGia) );
46752         Abc_FrameReplaceCexVec( pAbc, &vSeqModelVec );
46753         Abc_FrameReplacePoStatuses( pAbc, &vStatuses );
46754         pAbc->nFrames = -1;
46755     }
46756     return 0;
46757 
46758 usage:
46759     Abc_Print( -2, "usage: &gla [-FSCMDETRQPB num] [-AL file] [-fardmnscbpquwvh]\n" );
46760     Abc_Print( -2, "\t          fixed-time-frame gate-level proof- and cex-based abstraction\n" );
46761     Abc_Print( -2, "\t-F num  : the max number of timeframes to unroll [default = %d]\n", pPars->nFramesMax );
46762     Abc_Print( -2, "\t-S num  : the starting time frame (0=unused) [default = %d]\n", pPars->nFramesStart );
46763     Abc_Print( -2, "\t-C num  : the max number of SAT solver conflicts (0=unused) [default = %d]\n", pPars->nConfLimit );
46764     Abc_Print( -2, "\t-M num  : the max number of learned clauses to keep (0=unused) [default = %d]\n", pPars->nLearnedStart );
46765     Abc_Print( -2, "\t-D num  : delta value for learned clause removal [default = %d]\n", pPars->nLearnedDelta );
46766     Abc_Print( -2, "\t-E num  : ratio percentage for learned clause removal [default = %d]\n", pPars->nLearnedPerce );
46767     Abc_Print( -2, "\t-T num  : an approximate timeout, in seconds [default = %d]\n", pPars->nTimeOut );
46768     Abc_Print( -2, "\t-R num  : stop when abstraction size exceeds num %% (0<=num<=100) [default = %d]\n", pPars->nRatioMin );
46769     Abc_Print( -2, "\t-Q num  : stop when abstraction size exceeds num %% during refinement (0<=num<=100) [default = %d]\n", pPars->nRatioMin2 );
46770     Abc_Print( -2, "\t-P num  : maximum percentage of added objects before a restart (0<=num<=100) [default = %d]\n", pPars->nRatioMax );
46771     Abc_Print( -2, "\t-B num  : the number of stable frames to call prover or dump abstraction [default = %d]\n", pPars->nFramesNoChangeLim );
46772     Abc_Print( -2, "\t-A file : file name for dumping abstrated model (&gla -d) or abstraction map (&gla -m)\n" );
46773     Abc_Print( -2, "\t-L file : the log file name [default = %s]\n", pLogFileName ? pLogFileName : "no logging" );
46774     Abc_Print( -2, "\t-f      : toggle propagating fanout implications [default = %s]\n", pPars->fPropFanout? "yes": "no" );
46775     Abc_Print( -2, "\t-a      : toggle refinement by adding one layers of gates [default = %s]\n", pPars->fAddLayer? "yes": "no" );
46776     Abc_Print( -2, "\t-r      : toggle using improved refinement heuristics [default = %s]\n", pPars->fNewRefine? "yes": "no" );
46777     Abc_Print( -2, "\t-d      : toggle dumping abstracted model into a file [default = %s]\n", pPars->fDumpVabs? "yes": "no" );
46778     Abc_Print( -2, "\t-m      : toggle dumping abstraction map into a file [default = %s]\n", pPars->fDumpMabs? "yes": "no" );
46779     Abc_Print( -2, "\t-n      : toggle using new algorithms [default = %s]\n", fNewAlgo? "yes": "no" );
46780     Abc_Print( -2, "\t-s      : toggle skipping previously proved timeframes [default = %s]\n", pPars->fUseSkip? "yes": "no" );
46781     Abc_Print( -2, "\t-c      : toggle using naive (2-input AND node) CNF encoding [default = %s]\n", pPars->fUseSimple? "yes": "no" );
46782     Abc_Print( -2, "\t-b      : toggle CNF construction without hashing [default = %s]\n", pPars->fSkipHash? "yes": "no" );
46783     Abc_Print( -2, "\t-p      : toggle using full-proof for UNSAT cores [default = %s]\n", pPars->fUseFullProof? "yes": "no" );
46784     Abc_Print( -2, "\t-q      : toggle calling the prover [default = %s]\n", pPars->fCallProver? "yes": "no" );
46785     Abc_Print( -2, "\t-u      : toggle enabling simplifation before calling the prover [default = %s]\n", pPars->fSimpProver? "yes": "no" );
46786     Abc_Print( -2, "\t-v      : toggle printing verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
46787     Abc_Print( -2, "\t-w      : toggle printing more verbose information [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
46788     Abc_Print( -2, "\t-h      : print the command usage\n");
46789     return 1;
46790 }
46791 
46792 
46793 /**Function*************************************************************
46794 
46795   Synopsis    []
46796 
46797   Description []
46798 
46799   SideEffects []
46800 
46801   SeeAlso     []
46802 
46803 ***********************************************************************/
Abc_CommandAbc9Vta(Abc_Frame_t * pAbc,int argc,char ** argv)46804 int Abc_CommandAbc9Vta( Abc_Frame_t * pAbc, int argc, char ** argv )
46805 {
46806     Abs_Par_t Pars, * pPars = &Pars;
46807     int c;
46808     Abs_ParSetDefaults( pPars );
46809     Extra_UtilGetoptReset();
46810     while ( ( c = Extra_UtilGetopt( argc, argv, "FSPCLDETRAtradvh" ) ) != EOF )
46811     {
46812         switch ( c )
46813         {
46814         case 'F':
46815             if ( globalUtilOptind >= argc )
46816             {
46817                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
46818                 goto usage;
46819             }
46820             pPars->nFramesMax = atoi(argv[globalUtilOptind]);
46821             globalUtilOptind++;
46822             if ( pPars->nFramesMax < 0 )
46823                 goto usage;
46824             break;
46825         case 'S':
46826             if ( globalUtilOptind >= argc )
46827             {
46828                 Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" );
46829                 goto usage;
46830             }
46831             pPars->nFramesStart = atoi(argv[globalUtilOptind]);
46832             globalUtilOptind++;
46833             if ( pPars->nFramesStart < 0 )
46834                 goto usage;
46835             break;
46836         case 'P':
46837             if ( globalUtilOptind >= argc )
46838             {
46839                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
46840                 goto usage;
46841             }
46842             pPars->nFramesPast = atoi(argv[globalUtilOptind]);
46843             globalUtilOptind++;
46844             if ( pPars->nFramesPast < 0 )
46845                 goto usage;
46846             break;
46847         case 'C':
46848             if ( globalUtilOptind >= argc )
46849             {
46850                 Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
46851                 goto usage;
46852             }
46853             pPars->nConfLimit = atoi(argv[globalUtilOptind]);
46854             globalUtilOptind++;
46855             if ( pPars->nConfLimit < 0 )
46856                 goto usage;
46857             break;
46858         case 'L':
46859             if ( globalUtilOptind >= argc )
46860             {
46861                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
46862                 goto usage;
46863             }
46864             pPars->nLearnedStart = atoi(argv[globalUtilOptind]);
46865             globalUtilOptind++;
46866             if ( pPars->nLearnedStart < 0 )
46867                 goto usage;
46868             break;
46869         case 'D':
46870             if ( globalUtilOptind >= argc )
46871             {
46872                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
46873                 goto usage;
46874             }
46875             pPars->nLearnedDelta = atoi(argv[globalUtilOptind]);
46876             globalUtilOptind++;
46877             if ( pPars->nLearnedDelta < 0 )
46878                 goto usage;
46879             break;
46880         case 'E':
46881             if ( globalUtilOptind >= argc )
46882             {
46883                 Abc_Print( -1, "Command line switch \"-E\" should be followed by an integer.\n" );
46884                 goto usage;
46885             }
46886             pPars->nLearnedPerce = atoi(argv[globalUtilOptind]);
46887             globalUtilOptind++;
46888             if ( pPars->nLearnedPerce < 0 )
46889                 goto usage;
46890             break;
46891         case 'T':
46892             if ( globalUtilOptind >= argc )
46893             {
46894                 Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
46895                 goto usage;
46896             }
46897             pPars->nTimeOut = atoi(argv[globalUtilOptind]);
46898             globalUtilOptind++;
46899             if ( pPars->nTimeOut < 0 )
46900                 goto usage;
46901             break;
46902         case 'R':
46903             if ( globalUtilOptind >= argc )
46904             {
46905                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
46906                 goto usage;
46907             }
46908             pPars->nRatioMin = atoi(argv[globalUtilOptind]);
46909             globalUtilOptind++;
46910             if ( pPars->nRatioMin < 0 )
46911                 goto usage;
46912             break;
46913         case 'A':
46914             if ( globalUtilOptind >= argc )
46915             {
46916                 Abc_Print( -1, "Command line switch \"-A\" should be followed by a file name.\n" );
46917                 goto usage;
46918             }
46919             pPars->pFileVabs = argv[globalUtilOptind];
46920             globalUtilOptind++;
46921             break;
46922         case 't':
46923             pPars->fUseTermVars ^= 1;
46924             break;
46925         case 'r':
46926             pPars->fUseRollback ^= 1;
46927             break;
46928         case 'a':
46929             pPars->fAddLayer ^= 1;
46930             break;
46931         case 'd':
46932             pPars->fDumpVabs ^= 1;
46933             break;
46934         case 'v':
46935             pPars->fVerbose ^= 1;
46936             break;
46937         case 'h':
46938             goto usage;
46939         default:
46940             goto usage;
46941         }
46942     }
46943     if ( pAbc->pGia == NULL )
46944     {
46945         Abc_Print( -1, "There is no AIG.\n" );
46946         return 0;
46947     }
46948     if ( Gia_ManRegNum(pAbc->pGia) == 0 )
46949     {
46950         Abc_Print( -1, "The network is combinational.\n" );
46951         return 0;
46952     }
46953     if ( Gia_ManPoNum(pAbc->pGia) > 1 )
46954     {
46955         Abc_Print( 1, "The network is more than one PO (run \"orpos\").\n" );
46956         return 0;
46957     }
46958     if ( pPars->nFramesMax < 0 )
46959     {
46960         Abc_Print( 1, "The number of starting frames should be a positive integer.\n" );
46961         return 0;
46962     }
46963     if ( pPars->nFramesMax && pPars->nFramesStart > pPars->nFramesMax )
46964     {
46965         Abc_Print( 1, "The starting frame is larger than the max number of frames.\n" );
46966         return 0;
46967     }
46968     pAbc->Status  = Gia_VtaPerform( pAbc->pGia, pPars );
46969     pAbc->nFrames = pPars->iFrame;
46970     Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexSeq );
46971     return 0;
46972 
46973 usage:
46974     Abc_Print( -2, "usage: &vta [-FSPCLDETR num] [-A file] [-tradvh]\n" );
46975     Abc_Print( -2, "\t          variable-time-frame gate-level proof- and cex-based abstraction\n" );
46976     Abc_Print( -2, "\t-F num  : the max number of timeframes to unroll [default = %d]\n", pPars->nFramesMax );
46977     Abc_Print( -2, "\t-S num  : the starting time frame (0=unused) [default = %d]\n", pPars->nFramesStart );
46978     Abc_Print( -2, "\t-P num  : the number of previous frames for UNSAT core [default = %d]\n", pPars->nFramesPast );
46979     Abc_Print( -2, "\t-C num  : the max number of SAT solver conflicts (0=unused) [default = %d]\n", pPars->nConfLimit );
46980     Abc_Print( -2, "\t-L num  : the max number of learned clauses to keep (0=unused) [default = %d]\n", pPars->nLearnedStart );
46981     Abc_Print( -2, "\t-D num  : delta value for learned clause removal [default = %d]\n", pPars->nLearnedDelta );
46982     Abc_Print( -2, "\t-E num  : ratio percentage for learned clause removal [default = %d]\n", pPars->nLearnedPerce );
46983     Abc_Print( -2, "\t-T num  : an approximate timeout, in seconds [default = %d]\n", pPars->nTimeOut );
46984     Abc_Print( -2, "\t-R num  : minimum percentage of abstracted objects (0<=num<=100) [default = %d]\n", pPars->nRatioMin );
46985     Abc_Print( -2, "\t-A file : file name for dumping abstrated model [default = \"vabs.aig\"]\n" );
46986     Abc_Print( -2, "\t-t      : toggle using terminal variables [default = %s]\n", pPars->fUseTermVars? "yes": "no" );
46987     Abc_Print( -2, "\t-r      : toggle using rollback after the starting frames [default = %s]\n", pPars->fUseRollback? "yes": "no" );
46988     Abc_Print( -2, "\t-a      : toggle refinement by adding one layers of gates [default = %s]\n", pPars->fAddLayer? "yes": "no" );
46989     Abc_Print( -2, "\t-d      : toggle dumping abstracted model into a file [default = %s]\n", pPars->fDumpVabs? "yes": "no" );
46990     Abc_Print( -2, "\t-v      : toggle printing verbose information [default = %s]\n", pPars->fVerbose? "yes": "no" );
46991     Abc_Print( -2, "\t-h      : print the command usage\n");
46992     return 1;
46993 }
46994 
46995 /**Function*************************************************************
46996 
46997   Synopsis    []
46998 
46999   Description []
47000 
47001   SideEffects []
47002 
47003   SeeAlso     []
47004 
47005 ***********************************************************************/
Abc_CommandAbc9Vta2Gla(Abc_Frame_t * pAbc,int argc,char ** argv)47006 int Abc_CommandAbc9Vta2Gla( Abc_Frame_t * pAbc, int argc, char ** argv )
47007 {
47008     int c, fVerbose = 0;
47009     Extra_UtilGetoptReset();
47010     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
47011     {
47012         switch ( c )
47013         {
47014         case 'v':
47015             fVerbose ^= 1;
47016             break;
47017         case 'h':
47018             goto usage;
47019         default:
47020             goto usage;
47021         }
47022     }
47023     if ( pAbc->pGia == NULL )
47024     {
47025         Abc_Print( -1, "Abc_CommandAbc9Vta2Gla(): There is no AIG.\n" );
47026         return 0;
47027     }
47028     if ( pAbc->pGia->vObjClasses == NULL )
47029     {
47030         Abc_Print( -1, "Abc_CommandAbc9Vta2Gla(): There is no variable-time-frame abstraction is defined.\n" );
47031         return 0;
47032     }
47033     Vec_IntFreeP( &pAbc->pGia->vGateClasses );
47034     pAbc->pGia->vGateClasses = Gia_VtaConvertToGla( pAbc->pGia, pAbc->pGia->vObjClasses );
47035     Vec_IntFreeP( &pAbc->pGia->vObjClasses );
47036     return 0;
47037 
47038 usage:
47039     Abc_Print( -2, "usage: &vta_gla [-vh]\n" );
47040     Abc_Print( -2, "\t        maps variable- into fixed-time-frame gate-level abstraction\n" );
47041     Abc_Print( -2, "\t-v    : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
47042     Abc_Print( -2, "\t-h    : print the command usage\n");
47043     return 1;
47044 }
47045 
47046 /**Function*************************************************************
47047 
47048   Synopsis    []
47049 
47050   Description []
47051 
47052   SideEffects []
47053 
47054   SeeAlso     []
47055 
47056 ***********************************************************************/
Abc_CommandAbc9Gla2Vta(Abc_Frame_t * pAbc,int argc,char ** argv)47057 int Abc_CommandAbc9Gla2Vta( Abc_Frame_t * pAbc, int argc, char ** argv )
47058 {
47059     int c, fVerbose = 0;
47060     int nFrames = pAbc->nFrames;
47061     Extra_UtilGetoptReset();
47062     while ( ( c = Extra_UtilGetopt( argc, argv, "Fvh" ) ) != EOF )
47063     {
47064         switch ( c )
47065         {
47066         case 'F':
47067             if ( globalUtilOptind >= argc )
47068             {
47069                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
47070                 goto usage;
47071             }
47072             nFrames = atoi(argv[globalUtilOptind]);
47073             globalUtilOptind++;
47074             if ( nFrames < 0 )
47075                 goto usage;
47076             break;
47077         case 'v':
47078             fVerbose ^= 1;
47079             break;
47080         case 'h':
47081             goto usage;
47082         default:
47083             goto usage;
47084         }
47085     }
47086     if ( pAbc->pGia == NULL )
47087     {
47088         Abc_Print( -1, "Abc_CommandAbc9Gla2Vta(): There is no AIG.\n" );
47089         return 0;
47090     }
47091     if ( pAbc->pGia->vGateClasses == NULL )
47092     {
47093         Abc_Print( -1, "Abc_CommandAbc9Gla2Vta(): There is no gate-level abstraction is defined.\n" );
47094         return 0;
47095     }
47096     if ( pAbc->nFrames < 1 )
47097     {
47098         Abc_Print( -1, "Abc_CommandAbc9Gla2Vta(): The number of timeframes (%d) should be a positive integer.\n", nFrames );
47099         return 0;
47100     }
47101     Vec_IntFreeP( &pAbc->pGia->vObjClasses );
47102     pAbc->pGia->vObjClasses = Gia_VtaConvertFromGla( pAbc->pGia, pAbc->pGia->vGateClasses, nFrames );
47103     Vec_IntFreeP( &pAbc->pGia->vGateClasses );
47104     return 0;
47105 
47106 usage:
47107     Abc_Print( -2, "usage: &gla_vta [-F num] [-vh]\n" );
47108     Abc_Print( -2, "\t          maps fixed- into variable-time-frame gate-level abstraction\n" );
47109     Abc_Print( -2, "\t-F num  : timeframes in the resulting variable-time-frame abstraction [default = %d]\n", nFrames );
47110     Abc_Print( -2, "\t-v      : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
47111     Abc_Print( -2, "\t-h      : print the command usage\n");
47112     return 1;
47113 }
47114 
47115 /**Function*************************************************************
47116 
47117   Synopsis    []
47118 
47119   Description []
47120 
47121   SideEffects []
47122 
47123   SeeAlso     []
47124 
47125 ***********************************************************************/
Abc_CommandAbc9Fla2Gla(Abc_Frame_t * pAbc,int argc,char ** argv)47126 int Abc_CommandAbc9Fla2Gla( Abc_Frame_t * pAbc, int argc, char ** argv )
47127 {
47128     int c, fVerbose = 0;
47129     Extra_UtilGetoptReset();
47130     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
47131     {
47132         switch ( c )
47133         {
47134         case 'v':
47135             fVerbose ^= 1;
47136             break;
47137         case 'h':
47138             goto usage;
47139         default:
47140             goto usage;
47141         }
47142     }
47143     if ( pAbc->pGia == NULL )
47144     {
47145         Abc_Print( -1, "Abc_CommandAbc9Fla2Gla(): There is no AIG.\n" );
47146         return 0;
47147     }
47148     if ( pAbc->pGia->vFlopClasses == NULL )
47149     {
47150         Abc_Print( -1, "Abc_CommandAbc9Fla2Gla(): There is no gate-level abstraction is defined.\n" );
47151         return 0;
47152     }
47153     Vec_IntFreeP( &pAbc->pGia->vGateClasses );
47154     pAbc->pGia->vGateClasses = Gia_FlaConvertToGla( pAbc->pGia, pAbc->pGia->vFlopClasses );
47155     Vec_IntFreeP( &pAbc->pGia->vFlopClasses );
47156     return 0;
47157 
47158 usage:
47159     Abc_Print( -2, "usage: &fla_gla [-vh]\n" );
47160     Abc_Print( -2, "\t          maps flop-level into gate-level abstraction\n" );
47161     Abc_Print( -2, "\t-v      : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
47162     Abc_Print( -2, "\t-h      : print the command usage\n");
47163     return 1;
47164 }
47165 
47166 /**Function*************************************************************
47167 
47168   Synopsis    []
47169 
47170   Description []
47171 
47172   SideEffects []
47173 
47174   SeeAlso     []
47175 
47176 ***********************************************************************/
Abc_CommandAbc9Gla2Fla(Abc_Frame_t * pAbc,int argc,char ** argv)47177 int Abc_CommandAbc9Gla2Fla( Abc_Frame_t * pAbc, int argc, char ** argv )
47178 {
47179     int c, fVerbose = 0;
47180     Extra_UtilGetoptReset();
47181     while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
47182     {
47183         switch ( c )
47184         {
47185         case 'v':
47186             fVerbose ^= 1;
47187             break;
47188         case 'h':
47189             goto usage;
47190         default:
47191             goto usage;
47192         }
47193     }
47194     if ( pAbc->pGia == NULL )
47195     {
47196         Abc_Print( -1, "Abc_CommandAbc9Gla2Fla(): There is no AIG.\n" );
47197         return 0;
47198     }
47199     if ( pAbc->pGia->vGateClasses == NULL )
47200     {
47201         Abc_Print( -1, "Abc_CommandAbc9Gla2Fla(): There is no gate-level abstraction is defined.\n" );
47202         return 0;
47203     }
47204     Vec_IntFreeP( &pAbc->pGia->vFlopClasses );
47205     pAbc->pGia->vFlopClasses = Gia_GlaConvertToFla( pAbc->pGia, pAbc->pGia->vGateClasses );
47206     Vec_IntFreeP( &pAbc->pGia->vGateClasses );
47207     return 0;
47208 
47209 usage:
47210     Abc_Print( -2, "usage: &gla_fla [-vh]\n" );
47211     Abc_Print( -2, "\t          maps gate-level into flop-level abstraction\n" );
47212     Abc_Print( -2, "\t-v      : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
47213     Abc_Print( -2, "\t-h      : print the command usage\n");
47214     return 1;
47215 }
47216 
47217 
47218 /**Function*************************************************************
47219 
47220   Synopsis    []
47221 
47222   Description []
47223 
47224   SideEffects []
47225 
47226   SeeAlso     []
47227 
47228 ***********************************************************************/
Abc_CommandAbc9Gen(Abc_Frame_t * pAbc,int argc,char ** argv)47229 int Abc_CommandAbc9Gen( Abc_Frame_t * pAbc, int argc, char ** argv )
47230 {
47231     extern Gia_Man_t * Extra_CommandGen( int Algo, int LutSize, int nLuts, int nLevels, int Limit, int nBestTries, int Multi, int fXor, int fVerbose );
47232     Gia_Man_t * pTemp = NULL;
47233     int Algo        =   0;
47234     int LutSize     =   6;
47235     int nLuts       = 256;
47236     int nLevels     =   8;
47237     int Limit       =   0;
47238     int nBestTries  =   1;
47239     int Multi       =   0;
47240     int fXor        =   1;
47241     int c, fVerbose =   0;
47242     Extra_UtilGetoptReset();
47243     while ( ( c = Extra_UtilGetopt( argc, argv, "AKNDLBMxvh" ) ) != EOF )
47244     {
47245         switch ( c )
47246         {
47247         case 'A':
47248             if ( globalUtilOptind >= argc )
47249             {
47250                 Abc_Print( -1, "Command line switch \"-A\" should be followed by an integer.\n" );
47251                 goto usage;
47252             }
47253             Algo = atoi(argv[globalUtilOptind]);
47254             globalUtilOptind++;
47255             if ( Algo < 0 )
47256                 goto usage;
47257             break;
47258         case 'K':
47259             if ( globalUtilOptind >= argc )
47260             {
47261                 Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
47262                 goto usage;
47263             }
47264             LutSize = atoi(argv[globalUtilOptind]);
47265             globalUtilOptind++;
47266             if ( LutSize < 0 )
47267                 goto usage;
47268             break;
47269         case 'N':
47270             if ( globalUtilOptind >= argc )
47271             {
47272                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
47273                 goto usage;
47274             }
47275             nLuts = atoi(argv[globalUtilOptind]);
47276             globalUtilOptind++;
47277             if ( nLuts < 0 )
47278                 goto usage;
47279             break;
47280         case 'D':
47281             if ( globalUtilOptind >= argc )
47282             {
47283                 Abc_Print( -1, "Command line switch \"-D\" should be followed by an integer.\n" );
47284                 goto usage;
47285             }
47286             nLevels = atoi(argv[globalUtilOptind]);
47287             globalUtilOptind++;
47288             if ( nLevels < 0 )
47289                 goto usage;
47290             break;
47291         case 'L':
47292             if ( globalUtilOptind >= argc )
47293             {
47294                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
47295                 goto usage;
47296             }
47297             Limit = atoi(argv[globalUtilOptind]);
47298             globalUtilOptind++;
47299             if ( Limit < 0 )
47300                 goto usage;
47301             break;
47302         case 'B':
47303             if ( globalUtilOptind >= argc )
47304             {
47305                 Abc_Print( -1, "Command line switch \"-B\" should be followed by an integer.\n" );
47306                 goto usage;
47307             }
47308             nBestTries = atoi(argv[globalUtilOptind]);
47309             globalUtilOptind++;
47310             if ( nBestTries < 0 )
47311                 goto usage;
47312             break;
47313         case 'M':
47314             if ( globalUtilOptind >= argc )
47315             {
47316                 Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
47317                 goto usage;
47318             }
47319             Multi = atoi(argv[globalUtilOptind]);
47320             globalUtilOptind++;
47321             if ( Multi < 0 )
47322                 goto usage;
47323             break;
47324         case 'x':
47325             fXor ^= 1;
47326             break;
47327         case 'v':
47328             fVerbose ^= 1;
47329             break;
47330         case 'h':
47331             goto usage;
47332         default:
47333             goto usage;
47334         }
47335     }
47336     pTemp = Extra_CommandGen( Algo, LutSize, nLuts, nLevels, Limit, nBestTries, Multi, fXor, fVerbose );
47337     Abc_FrameUpdateGia( pAbc, pTemp );
47338     return 0;
47339 
47340 usage:
47341     Abc_Print( -2, "usage: &gen [-AKNDLBMxvh]\n" );
47342     Abc_Print( -2, "\t          generates network\n" );
47343     Abc_Print( -2, "\t-A num  : the generation algorithm [default = %d]\n",                 Algo );
47344     Abc_Print( -2, "\t-K num  : the number of LUT inputs [default = %d]\n",                 LutSize );
47345     Abc_Print( -2, "\t-N num  : the number of LUTs on one level [default = %d]\n",          nLuts );
47346     Abc_Print( -2, "\t-D num  : the number of LUT levels [default = %d]\n",                 nLevels );
47347     Abc_Print( -2, "\t-L num  : limit below which we randomize [default = %d]\n",           Limit );
47348     Abc_Print( -2, "\t-B num  : select best fanins among this many tries [default = %d]\n", nBestTries );
47349     Abc_Print( -2, "\t-M num  : the multiplier type (1=array, 2=booth) [default = %d]\n",   Multi );
47350     Abc_Print( -2, "\t-x      : toggle using XOR gates [default = %s]\n",                   fXor? "yes": "no" );
47351     Abc_Print( -2, "\t-v      : toggle printing verbose information [default = %s]\n",      fVerbose? "yes": "no" );
47352     Abc_Print( -2, "\t-h      : print the command usage\n");
47353     return 1;
47354 }
47355 
47356 /**Function*************************************************************
47357 
47358   Synopsis    []
47359 
47360   Description []
47361 
47362   SideEffects []
47363 
47364   SeeAlso     []
47365 
47366 ***********************************************************************/
Abc_CommandAbc9Cfs(Abc_Frame_t * pAbc,int argc,char ** argv)47367 int Abc_CommandAbc9Cfs( Abc_Frame_t * pAbc, int argc, char ** argv )
47368 {
47369     extern void Extra_CommandCfs( Gia_Man_t * pGia, int Limit, int Reps, int UnseenUse, int RareUse, int fReplaceRare, int fConstSim, int fDagNodes, float FlipProb, int fVerbose );
47370     int Limit       =   0;
47371     int Reps        =   1;
47372     int UnseenUse   =   2;
47373     int RareUse     =   2;
47374     int fReplaceRare=   0;
47375     int fConstSim   =   0;
47376     int fDagNodes   =   0;
47377     float FlipProb  =   0;
47378     int c, fVerbose =   0;
47379     Extra_UtilGetoptReset();
47380     while ( ( c = Extra_UtilGetopt( argc, argv, "LNURPrcdvh" ) ) != EOF )
47381     {
47382         switch ( c )
47383         {
47384         case 'L':
47385             if ( globalUtilOptind >= argc )
47386             {
47387                 Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" );
47388                 goto usage;
47389             }
47390             Limit = atoi(argv[globalUtilOptind]);
47391             globalUtilOptind++;
47392             if ( Limit < 0 )
47393                 goto usage;
47394             break;
47395         case 'N':
47396             if ( globalUtilOptind >= argc )
47397             {
47398                 Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
47399                 goto usage;
47400             }
47401             Reps = atoi(argv[globalUtilOptind]);
47402             globalUtilOptind++;
47403             if ( Reps < 0 )
47404                 goto usage;
47405             break;
47406         case 'U':
47407             if ( globalUtilOptind >= argc )
47408             {
47409                 Abc_Print( -1, "Command line switch \"-U\" should be followed by an integer.\n" );
47410                 goto usage;
47411             }
47412             UnseenUse = atoi(argv[globalUtilOptind]);
47413             globalUtilOptind++;
47414             if ( UnseenUse < 0 )
47415                 goto usage;
47416             break;
47417         case 'R':
47418             if ( globalUtilOptind >= argc )
47419             {
47420                 Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
47421                 goto usage;
47422             }
47423             RareUse = atoi(argv[globalUtilOptind]);
47424             globalUtilOptind++;
47425             if ( RareUse < 0 )
47426                 goto usage;
47427             break;
47428         case 'P':
47429             if ( globalUtilOptind >= argc )
47430             {
47431                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
47432                 goto usage;
47433             }
47434             FlipProb = atof(argv[globalUtilOptind]);
47435             globalUtilOptind++;
47436             if ( FlipProb < 0 )
47437                 goto usage;
47438             break;
47439         case 'r':
47440             fReplaceRare ^= 1;
47441             break;
47442         case 'c':
47443             fConstSim ^= 1;
47444             break;
47445         case 'd':
47446             fDagNodes ^= 1;
47447             break;
47448         case 'v':
47449             fVerbose ^= 1;
47450             break;
47451         case 'h':
47452             goto usage;
47453         default:
47454             goto usage;
47455         }
47456     }
47457     if ( pAbc->pGia == NULL )
47458     {
47459         Abc_Print( -1, "Abc_CommandAbc9Cfs(): There is no AIG.\n" );
47460         return 1;
47461     }
47462     Extra_CommandCfs( pAbc->pGia, Limit, Reps, UnseenUse, RareUse, fReplaceRare, fConstSim, fDagNodes, FlipProb, fVerbose );
47463     return 0;
47464 
47465 usage:
47466     Abc_Print( -2, "usage: &cfs [-LNURPrcdvh]\n" );
47467     Abc_Print( -2, "\t          performs simulation\n" );
47468     Abc_Print( -2, "\t-L num  : the limit on the number of occurrences [default = %d]\n",  Limit );
47469     Abc_Print( -2, "\t-N num  : the number of repetions of each pattern [default = %d]\n", Reps );
47470     Abc_Print( -2, "\t-U num  : what to do with unseen patterns [default = %d]\n",         UnseenUse );
47471     Abc_Print( -2, "\t-R num  : what to do with rare patterns [default = %d]\n",           RareUse );
47472     Abc_Print( -2, "\t-P num  : base2-log of ramdom flip probability [default = %f]\n",    FlipProb );
47473     Abc_Print( -2, "\t-r      : toggle replacing rare patterns [default = %s]\n",          fReplaceRare? "yes": "no" );
47474     Abc_Print( -2, "\t-c      : toggle inserting constants [default = %s]\n",              fConstSim? "yes": "no" );
47475     Abc_Print( -2, "\t-d      : toggle using only DAG nodes [default = %s]\n",             fDagNodes? "yes": "no" );
47476     Abc_Print( -2, "\t-v      : toggle printing verbose information [default = %s]\n",     fVerbose? "yes": "no" );
47477     Abc_Print( -2, "\t-h      : print the command usage\n");
47478     return 1;
47479 }
47480 
47481 
47482 /**Function*************************************************************
47483 
47484   Synopsis    []
47485 
47486   Description []
47487 
47488   SideEffects []
47489 
47490   SeeAlso     []
47491 
47492 ***********************************************************************/
Abc_CommandAbc9Test(Abc_Frame_t * pAbc,int argc,char ** argv)47493 int Abc_CommandAbc9Test( Abc_Frame_t * pAbc, int argc, char ** argv )
47494 {
47495     int c, fVerbose = 0;
47496     int nFrames = 5;
47497     int fSwitch = 0;
47498     int nWords = 1000;
47499     int nProcs = 2;
47500     Extra_UtilGetoptReset();
47501     while ( ( c = Extra_UtilGetopt( argc, argv, "WPFsvh" ) ) != EOF )
47502     {
47503         switch ( c )
47504         {
47505         case 'W':
47506             if ( globalUtilOptind >= argc )
47507             {
47508                 Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
47509                 goto usage;
47510             }
47511             nWords = atoi(argv[globalUtilOptind]);
47512             globalUtilOptind++;
47513             if ( nWords < 0 )
47514                 goto usage;
47515             break;
47516         case 'P':
47517             if ( globalUtilOptind >= argc )
47518             {
47519                 Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" );
47520                 goto usage;
47521             }
47522             nProcs = atoi(argv[globalUtilOptind]);
47523             globalUtilOptind++;
47524             if ( nProcs < 0 )
47525                 goto usage;
47526             break;
47527         case 'F':
47528             if ( globalUtilOptind >= argc )
47529             {
47530                 Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
47531                 goto usage;
47532             }
47533             nFrames = atoi(argv[globalUtilOptind]);
47534             globalUtilOptind++;
47535             if ( nFrames < 0 )
47536                 goto usage;
47537             break;
47538         case 's':
47539             fSwitch ^= 1;
47540             break;
47541         case 'v':
47542             fVerbose ^= 1;
47543             break;
47544         case 'h':
47545             goto usage;
47546         default:
47547             goto usage;
47548         }
47549     }
47550 //    if ( pAbc->pGia == NULL )
47551 //    {
47552 //        Abc_Print( -1, "Abc_CommandAbc9Test(): There is no AIG.\n" );
47553 //        return 1;
47554 //    }
47555 //    Abc_FrameUpdateGia( pAbc, Abc_Procedure(pAbc->pGia) );
47556     return 0;
47557 usage:
47558     Abc_Print( -2, "usage: &test [-FW num] [-svh]\n" );
47559     Abc_Print( -2, "\t        testing various procedures\n" );
47560     Abc_Print( -2, "\t-F num: the number of timeframes [default = %d]\n", nFrames );
47561     Abc_Print( -2, "\t-W num: the number of machine words [default = %d]\n", nWords );
47562     Abc_Print( -2, "\t-s    : toggle enable (yes) vs. disable (no) [default = %s]\n", fSwitch? "yes": "no" );
47563     Abc_Print( -2, "\t-v    : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
47564     Abc_Print( -2, "\t-h    : print the command usage\n");
47565     return 1;
47566 }
47567 
47568 ////////////////////////////////////////////////////////////////////////
47569 ///                       END OF FILE                                ///
47570 ////////////////////////////////////////////////////////////////////////
47571 
47572 #include "abciUnfold2.c"
47573 ABC_NAMESPACE_IMPL_END
47574