1 /*------------------------------------------------------------\
2 |                                                             |
3 | This file is part of the Alliance CAD System Copyright      |
4 | (C) Laboratoire LIP6 - D�partement ASIM Universite P&M Curie|
5 |                                                             |
6 | Home page      : http://www-asim.lip6.fr/alliance/          |
7 | E-mail         : mailto:alliance-users@asim.lip6.fr       |
8 |                                                             |
9 | This progam is  free software; you can redistribute it      |
10 | and/or modify it under the  terms of the GNU General Public |
11 | License as  published by the Free Software Foundation;      |
12 | either version 2 of the License, or (at your option) any    |
13 | later version.                                              |
14 |                                                             |
15 | Alliance VLSI  CAD System  is distributed  in the hope that |
16 | it  will be useful, but WITHOUT  ANY WARRANTY;              |
17 | without even the  implied warranty of MERCHANTABILITY or    |
18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General       |
19 | Public License for more details.                            |
20 |                                                             |
21 | You should have received a copy  of the GNU General Public  |
22 | License along with the GNU C Library; see the file COPYING. |
23 | If not, write to the Free Software Foundation, Inc.,        |
24 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                     |
25 |                                                             |
26 \------------------------------------------------------------*/
27 
28 /*------------------------------------------------------------\
29 |                                                             |
30 | Tool    :                     B2F                           |
31 |                                                             |
32 | File    :                  b2f_beh2fsm.c                    |
33 |                                                             |
34 | Author  :                 Jacomme Ludovic                   |
35 |                                                             |
36 | Date    :                   01.11.94                        |
37 |                                                             |
38 \------------------------------------------------------------*/
39 /*------------------------------------------------------------\
40 |                                                             |
41 |                         Include Files                       |
42 |                                                             |
43 \------------------------------------------------------------*/
44 
45 # include "mut.h"
46 # include "aut.h"
47 # include "abl.h"
48 # include "bdd.h"
49 # include "btr.h"
50 # include "btr.h"
51 # include "fsm.h"
52 # include "abe.h"
53 # include "abv.h"
54 # include "abt.h"
55 # include "ftl.h"
56 
57 # include <stdio.h>
58 # include <stdlib.h>
59 # include <string.h>
60 # include <memory.h>
61 # include "b2f_error.h"
62 # include "b2f_beh2fsm.h"
63 
64 /*------------------------------------------------------------\
65 |                                                             |
66 |                           Constants                         |
67 |                                                             |
68 \------------------------------------------------------------*/
69 /*------------------------------------------------------------\
70 |                                                             |
71 |                            Types                            |
72 |                                                             |
73 \------------------------------------------------------------*/
74 /*------------------------------------------------------------\
75 |                                                             |
76 |                          Variables                          |
77 |                                                             |
78 \------------------------------------------------------------*/
79 
80   static char          *B2fStateArray   = (char          *)0;
81   static char          *B2fStateName    = (char          *)0;
82   static long          *B2fStateIndex   = (long          *)0;
83   static authtable     *B2fHashState    = (authtable     *)0;
84   static authtable     *B2fHashOutput   = (authtable     *)0;
85 
86   static fsmstate_list *B2fCurrentState = (fsmstate_list *)0;
87   static fsmfig_list   *B2fFsmFigure    = (fsmfig_list   *)0;
88 
89   static btrvarfunc    *B2fLocalVarFunc   = (btrvarfunc *)0;
90   static long           B2fLocalNumberVar = 0;
91   static long           B2fLocalIndexVar  = 0;
92   static bddnode       *B2fLocalState     = (bddnode    *)0;
93 
94   static long           B2fNumberRegister = 0;
95   static char          *B2fRegisterName   = (char *)0;
96 
97 /*------------------------------------------------------------\
98 |                                                             |
99 |                          Functions                          |
100 |                                                             |
101 \------------------------------------------------------------*/
102 /*------------------------------------------------------------\
103 |                                                             |
104 |                        Convert State Name                   |
105 |                                                             |
106 \------------------------------------------------------------*/
107 
B2fConvertStateName(StateName)108 char *B2fConvertStateName( StateName )
109 
110   char *StateName;
111 {
112   long Index;
113   long Target;
114   long Sum;
115 
116   Target = 1;
117   Sum    = 0;
118 
119   for ( Index = 0; StateName[ Index ]; Index++ )
120   {
121     Sum = ( Sum << 1 ) + ( StateName[ Index ] - '0' );
122 
123     if ( ( Index & 0x3 ) == 0x3 )
124     {
125       if ( Sum > 9 ) B2fStateName[ Target++ ] = Sum + 'A' - 10;
126       else           B2fStateName[ Target++ ] = Sum + '0';
127 
128       Sum = 0;
129     }
130   }
131 
132   if ( Index & 0x3 )
133   {
134     if ( Sum > 9 ) B2fStateName[ Target++ ] = Sum + 'A' - 10;
135     else           B2fStateName[ Target++ ] = Sum + '0';
136   }
137 
138   B2fStateName[ Target ] = '\0';
139 
140   StateName = namealloc( B2fStateName );
141 
142   return( StateName );
143 }
144 
145 /*------------------------------------------------------------\
146 |                                                             |
147 |                        Treat Add State                      |
148 |                                                             |
149 \------------------------------------------------------------*/
150 
B2fAddFsmState(StateName)151 fsmstate_list *B2fAddFsmState( StateName )
152 
153   char *StateName;
154 {
155   authelem      *Element;
156   fsmstate_list *FsmState;
157 
158   StateName = B2fConvertStateName( StateName );
159   Element = searchauthelem( B2fHashState, StateName );
160 
161   if ( Element == (authelem *)0 )
162   {
163 # ifdef DEBUG
164 fprintf( stdout, "%s *\n", StateName );
165 # endif
166     FsmState = addfsmstate( B2fFsmFigure, StateName );
167     addauthelem( B2fHashState, StateName, (long)FsmState );
168   }
169   else
170   {
171 # ifdef DEBUG
172 fprintf( stdout, "%s\n", StateName );
173 # endif
174     FsmState = (fsmstate_list *)Element->VALUE;
175   }
176 
177   return( FsmState );
178 }
179 
180 /*------------------------------------------------------------\
181 |                                                             |
182 |                        Treat State Image                    |
183 |                                                             |
184 \------------------------------------------------------------*/
185 
B2fAddFsmCurrentState(BddNode)186 void B2fAddFsmCurrentState( BddNode )
187 
188   bddnode *BddNode;
189 {
190   long Index;
191 
192   if ( BddNode->INDEX < BDD_INDEX_MIN )
193   {
194     if ( BddNode->INDEX == BDD_INDEX_ONE )
195     {
196       B2fCurrentState = B2fAddFsmState( B2fStateArray );
197     }
198   }
199   else
200   {
201     Index = B2fStateIndex[ BddNode->INDEX - BDD_INDEX_MIN ];
202 
203     B2fStateArray[ Index ] = '1';
204     B2fAddFsmCurrentState( BddNode->HIGH );
205 
206     B2fStateArray[ Index ] = '0';
207     B2fAddFsmCurrentState( BddNode->LOW  );
208 
209     B2fStateArray[ Index ] = '*';
210   }
211 }
212 
213 /*------------------------------------------------------------\
214 |                                                             |
215 |                        Add Fsm Locout                       |
216 |                                                             |
217 \------------------------------------------------------------*/
218 
B2fAddFsmLocalOutput(FsmState,BddState)219 void B2fAddFsmLocalOutput( FsmState, BddState )
220 
221   fsmstate_list *FsmState;
222   bddnode       *BddState;
223 {
224   authelem    *Element;
225   fsmout_list *FsmOut;
226   bddnode     *BddOut;
227   chain_list  *ExprOut;
228 
229   if ( FsmState->LOCOUT == (fsmlocout_list *)0 )
230   {
231     for ( FsmOut  = B2fFsmFigure->OUT;
232           FsmOut != (fsmout_list *)0;
233           FsmOut  = FsmOut->NEXT )
234     {
235       Element = searchauthelem( B2fHashOutput, FsmOut->NAME );
236       BddOut  = (bddnode *)Element->VALUE;
237       BddOut  = cofactorbddnode( (bddsystem *)0, BddOut, BddState );
238       ExprOut = convertbddcircuitabl( (bddcircuit *)0, decbddrefext( BddOut ) );
239 
240       addfsmlocout( FsmState, FsmOut, ExprOut, (chain_list *)0 );
241     }
242   }
243 }
244 
245 /*------------------------------------------------------------\
246 |                                                             |
247 |                      B2f View Bdd Node                      |
248 |                                                             |
249 \------------------------------------------------------------*/
250 
B2fAddFsmNextState(BddNode)251 void B2fAddFsmNextState( BddNode )
252 
253   bddnode *BddNode;
254 {
255   fsmstate_list *NextState;
256   chain_list    *Expr;
257 
258   BddNode = cofactorbddnode( (bddsystem *)0, BddNode, B2fLocalState );
259   Expr = convertbddcircuitabl( (bddcircuit *)0, decbddrefext( BddNode ) );
260 
261   NextState = B2fAddFsmState( B2fStateArray );
262 
263   addfsmtrans( B2fFsmFigure, B2fCurrentState, NextState, Expr );
264 }
265 
266 /*------------------------------------------------------------\
267 |                                                             |
268 |                 Local B2f Image Transition Function         |
269 |                                                             |
270 \------------------------------------------------------------*/
271 
loc_imageb2ftransfunc(StateSet)272 static bddnode *loc_imageb2ftransfunc( StateSet )
273 
274   bddnode *StateSet;
275 {
276   btrvarfunc *VarFunc;
277   bddnode    *BddSetIn;
278   bddnode    *BddSetOut;
279   bddnode    *BddResult;
280   bddnode    *BddHigh;
281   bddnode    *BddLow;
282   long        Index;
283 
284   if ( StateSet->INDEX == BDD_INDEX_ZERO )
285   {
286     return( StateSet );
287   }
288 
289   VarFunc = &B2fLocalVarFunc[ B2fLocalIndexVar ];
290   Index   = B2fStateIndex[ VarFunc->VAR->INDEX - BDD_INDEX_MIN ];
291 
292   BddSetIn  = decbddrefext( applybddnodenot( (bddsystem *)0, StateSet ) );
293   BddSetIn  = applybddnode( (bddsystem *)0, ABL_OR  , VarFunc->FUNC, BddSetIn );
294   BddSetOut = applybddnode( (bddsystem *)0, ABL_NAND, VarFunc->FUNC, StateSet );
295 
296   B2fLocalIndexVar++;
297 
298   if ( B2fLocalIndexVar >= B2fLocalNumberVar )
299   {
300 /*
301 ** StateSet => Fn,  Rn
302 */
303     if ( BddSetIn->INDEX == BDD_INDEX_ONE )
304     {
305       B2fStateArray[ Index ] = '1';
306 
307       B2fAddFsmNextState( StateSet );
308 
309       BddResult = incbddrefext( VarFunc->VAR );
310     }
311     else
312 /*
313 ** StateSet => ! Fn, ! Rn
314 */
315     if ( BddSetOut->INDEX == BDD_INDEX_ONE )
316     {
317       B2fStateArray[ Index ] = '0';
318 
319       B2fAddFsmNextState( StateSet );
320 
321       BddResult = applybddnodenot( (bddsystem *)0, VarFunc->VAR );
322     }
323     else
324     {
325       BddSetOut = applybddnodenot( (bddsystem *)0, decbddrefext( BddSetOut ) );
326       BddSetIn  = applybddnodenot( (bddsystem *)0, decbddrefext( BddSetIn  ) );
327 
328       B2fStateArray[ Index ] = '0';
329 
330       B2fAddFsmNextState( BddSetIn );
331 
332       B2fStateArray[ Index ] = '1';
333 
334       B2fAddFsmNextState( BddSetOut );
335 
336       BddResult = BddLocalSystem->ONE;
337     }
338   }
339   else
340   {
341 /*
342 ** StateSet => Fi, Ri . Img( StateSet )
343 */
344     if ( BddSetIn->INDEX == BDD_INDEX_ONE )
345     {
346       B2fStateArray[ Index ] = '1';
347 
348       BddResult = decbddrefext( loc_imageb2ftransfunc( StateSet ) );
349       BddResult = applybddnode( (bddsystem *)0, ABL_AND, VarFunc->VAR, BddResult );
350     }
351     else
352 /*
353 ** StateSet => ! Fi, ! Ri . Img( StateSet )
354 */
355     if ( BddSetOut->INDEX == BDD_INDEX_ONE )
356     {
357       B2fStateArray[ Index ] = '0';
358 
359       BddLow  = loc_imageb2ftransfunc( StateSet );
360       BddHigh = applybddnodenot( (bddsystem *)0, VarFunc->VAR );
361 
362       BddResult = applybddnode( (bddsystem *)0, ABL_AND,
363                                 decbddrefext( BddHigh ),
364                                 decbddrefext( BddLow  ) );
365     }
366     else
367     {
368 /*
369 **  Ri . Img( StateSet . Fi ) +  ! Ri . Img( StateSet . ! Fi )
370 */
371       BddSetOut = applybddnodenot( (bddsystem *)0, decbddrefext( BddSetOut ) );
372       BddSetIn  = applybddnodenot( (bddsystem *)0, decbddrefext( BddSetIn  ) );
373 
374       B2fStateArray[ Index ] = '0';
375 
376       BddHigh = applybddnodenot( (bddsystem *)0, VarFunc->VAR );
377       BddLow  = loc_imageb2ftransfunc( BddSetIn  );
378       BddLow  = applybddnode( (bddsystem *)0, ABL_AND,
379                               decbddrefext( BddHigh ),
380                               decbddrefext( BddLow  ) );
381 
382       B2fStateArray[ Index ] = '1';
383 
384       BddHigh = decbddrefext( loc_imageb2ftransfunc( BddSetOut ) );
385       BddHigh = applybddnode( (bddsystem *)0, ABL_AND, VarFunc->VAR, BddHigh );
386 
387       BddResult = applybddnode( (bddsystem *)0, ABL_OR,
388                                 decbddrefext( BddHigh ),
389                                 decbddrefext( BddLow  ) );
390     }
391   }
392 
393   B2fStateArray[ Index ] = '*';
394 
395   B2fLocalIndexVar--;
396 
397   decbddrefext( BddSetIn  );
398   decbddrefext( BddSetOut );
399 
400   return( BddResult );
401 }
402 
403 /*------------------------------------------------------------\
404 |                                                             |
405 |                 B2f Image Transition Function               |
406 |                                                             |
407 \------------------------------------------------------------*/
408 
imageb2ftransfunc(TransFunc,StateSet)409 bddnode *imageb2ftransfunc( TransFunc, StateSet )
410 
411    btrtransfunc *TransFunc;
412    bddnode      *StateSet;
413 {
414   bddnode *BddResult;
415 
416   setbddlocalsystem( TransFunc->BDD_SYSTEM );
417 
418   B2fLocalVarFunc   = TransFunc->VAR_FUNC;
419   B2fLocalNumberVar = TransFunc->NUMBER_VAR;
420   B2fLocalIndexVar  = 0;
421   B2fLocalState     = StateSet;
422 
423   BddResult = loc_imageb2ftransfunc( StateSet );
424 
425   return( BddResult );
426 }
427 
428 /*------------------------------------------------------------\
429 |                                                             |
430 |                        Treat State Image                    |
431 |                                                             |
432 \------------------------------------------------------------*/
433 /*------------------------------------------------------------\
434 |                                                             |
435 |                    Treat Beh Initial State                  |
436 |                                                             |
437 \------------------------------------------------------------*/
438 
B2fTreatInitialState(BehFigure,FlagInitial,StringInitial)439 bddnode *B2fTreatInitialState( BehFigure, FlagInitial, StringInitial )
440 
441    befig_list *BehFigure;
442    int         FlagInitial;
443    char       *StringInitial;
444 {
445   bddnode      *BddCurrentSet;
446   bddnode      *BddNode;
447   bddnode      *BddReg;
448   bddnode      *BddReset;
449   ablexpr      *AblReset;
450   bereg_list   *BehReg;
451   binode_list  *BiNode;
452   authtable    *HashTable;
453   authelem     *Element;
454   char         *ScanString;
455   long          Value = 0;
456   int           Index;
457   int           Scan;
458   int           Length;
459   int           BitZero;
460   char          CurChar;
461   char          Buffer[ 512 ];
462 
463   BddReset      = BddLocalSystem->ZERO;
464   BddCurrentSet = BddLocalSystem->ONE;
465 
466   HashTable = createauthtable( 1000 );
467 /*
468 ** Convert the reset condition to Bdd
469 */
470   if ( FlagInitial == 'R' )
471   {
472     AblReset = strablexpr( StringInitial, ABL_VIEW_INFIX );
473 
474     if ( AblReset == (ablexpr *)0 )
475     {
476       B2fError( B2F_ILLEGAL_RESET_CONDITION, StringInitial );
477     }
478 
479     BddReset = addbddcircuitabl( (bddcircuit *)0, AblReset );
480   }
481   else
482   if ( FlagInitial == 'I' )
483 /*
484 ** Put the 'StringInitial' into hash table
485 */
486   {
487     for ( Scan = 0; StringInitial[ Scan ] != '\0'; Scan++ )
488     {
489       if ( StringInitial[ Scan ] == '0' ) Value = 0;
490       else
491       if ( StringInitial[ Scan ] == '1' ) Value = 1;
492       else
493       {
494         B2fError( B2F_BAD_INITIAL_STRING, StringInitial );
495       }
496 
497       Index = B2fNumberRegister - (Scan + 1);
498 
499       sprintf( Buffer, "%s %d", B2fRegisterName, Index );
500       addauthelem( HashTable, namealloc( Buffer ), Value );
501     }
502 
503     if ( Scan != B2fNumberRegister )
504     {
505       B2fError( B2F_BAD_INITIAL_STRING, StringInitial );
506     }
507   }
508   else
509   if ( ( FlagInitial == 'O' ) ||
510        ( FlagInitial == 'Z' ) )
511   {
512     if ( FlagInitial == 'O' ) Value = 0;
513     else                      Value = 1;
514 
515     for ( Index = 0; Index < B2fNumberRegister; Index++ )
516     {
517       sprintf( Buffer, "%s %d", B2fRegisterName, Index );
518       addauthelem( HashTable, namealloc( Buffer ), Value );
519     }
520 
521     Length     = strlen( StringInitial );
522     ScanString = StringInitial;
523 
524     for ( Scan = 0; Scan <= Length; Scan++ )
525     {
526       CurChar = StringInitial[ Scan ];
527 
528       if ( ( CurChar == ','  ) ||
529            ( CurChar == '\0' ) )
530       {
531         StringInitial[ Scan ] = '\0';
532         Index = atoi( ScanString );
533         StringInitial[ Scan ] = CurChar;
534 
535         if ( ( Index < 0                 ) ||
536              ( Index > B2fNumberRegister ) )
537         {
538           B2fError( B2F_BAD_INITIAL_STRING, StringInitial );
539         }
540 
541         sprintf( Buffer, "%s %d", B2fRegisterName, Index );
542         addauthelem( HashTable, namealloc( Buffer ), ! Value );
543 
544         ScanString = &StringInitial[ Scan + 1];
545       }
546     }
547   }
548 
549   for ( BehReg  = BehFigure->BEREG;
550         BehReg != (bereg_list *)0;
551         BehReg  = BehReg->NEXT )
552   {
553     BiNode  = BehReg->BINODE;
554     BddReg  = searchbddcircuitin( (bddcircuit *)0, BehReg->NAME );
555     BitZero = 1;
556 /*
557 ** Search the initial value of the register
558 */
559     if ( FlagInitial == 'R' )
560     {
561       BddNode = cofactorbddnode( (bddsystem *)0, BiNode->VALNODE, BddReset );
562 
563       if ( BddNode == BddLocalSystem->ONE  ) BitZero = 0;
564       else
565       if ( BddNode != BddLocalSystem->ZERO )
566       {
567         B2fError( B2F_ILLEGAL_RESET_CONDITION, StringInitial );
568       }
569     }
570     else
571     if ( ( FlagInitial == 'O' ) ||
572          ( FlagInitial == 'I' ) ||
573          ( FlagInitial == 'Z' ) )
574     {
575       Element = searchauthelem( HashTable, BehReg->NAME );
576 
577       if ( Element == (authelem *)0 )
578       {
579         B2fError( B2F_BAD_INITIAL_STRING, StringInitial );
580       }
581 
582       BitZero = ! Element->VALUE;
583     }
584 
585     if ( BitZero ) BddNode = applybddnodenot( (bddsystem *)0, BddReg );
586     else           BddNode = BddReg;
587 
588     BddCurrentSet = applybddnode( (bddsystem *)0, ABL_AND,
589                                   decbddrefext( BddCurrentSet ),
590                                   decbddrefext( BddNode       ) );
591   }
592 
593   destroyauthtable( HashTable );
594 
595 # ifdef DEBUG
596   addbddcircuitout( (bddcircuit *)0, "init", BddCurrentSet );
597   testbddcircuit( (bddcircuit *)0 );
598 # endif
599 
600   return( BddCurrentSet );
601 }
602 
603 /*------------------------------------------------------------\
604 |                                                             |
605 |                        Treat Beh State                      |
606 |                                                             |
607 \------------------------------------------------------------*/
608 
B2fTreatState(BehFigure,FlagInitial,StringInitial)609 void B2fTreatState( BehFigure, FlagInitial, StringInitial )
610 
611   befig_list  *BehFigure;
612   int          FlagInitial;
613   char        *StringInitial;
614 {
615   btrtransfunc *BtrTransFunc;
616   bddassoc     *BddAssoc;
617   bereg_list   *BehReg;
618   beout_list   *BehOut;
619   binode_list  *BiNode;
620   bddnode      *BddNode;
621   bddnode      *BddCurrentState;
622   bddnode      *BddCurrentSet;
623   bddnode      *BddReachedSet;
624   bddnode      *BddImageSet;
625   bddnode      *BddImage;
626   bddvar        Variable;
627   long          NumberIndex;
628   long          StateIndex;
629 
630   NumberIndex = BddLocalSystem->NUMBER_INDEX;
631 
632   B2fHashState  = createauthtable( 1000 );
633   B2fStateName  = (char *)autallocblock( ( ( B2fNumberRegister + 3 ) >> 2 ) + 2 );
634   B2fStateArray = (char *)autallocblock( B2fNumberRegister + 1 );
635   B2fStateName [ 0 ] = 's';
636 
637   memset( B2fStateArray, '*', B2fNumberRegister );
638   B2fStateIndex = (long *)autallocblock( sizeof( long ) * NumberIndex );
639 
640   BtrTransFunc  = createbtrtransfunc( (bddsystem *)0, B2fNumberRegister );
641   BddAssoc      = addbddassoc( (bddsystem *)0 );
642   StateIndex    = 0;
643 
644   BddCurrentSet = B2fTreatInitialState( BehFigure, FlagInitial, StringInitial );
645 
646   for ( BehReg  = BehFigure->BEREG;
647         BehReg != (bereg_list *)0;
648         BehReg  = BehReg->NEXT )
649   {
650     BiNode = BehReg->BINODE;
651 
652     BddNode = searchbddcircuitin( (bddcircuit *)0, BehReg->NAME );
653     addbtrtransfunc( BtrTransFunc, BddNode, BiNode->VALNODE );
654 
655     Variable = BddLocalSystem->INDEX_TO_VAR[ BddNode->INDEX ];
656     addbddnodeassoc( (bddsystem *)0, BddAssoc, Variable, BddLocalSystem->ONE );
657 
658     B2fStateIndex[ BddNode->INDEX - BDD_INDEX_MIN ] = StateIndex++;
659   }
660 
661   B2fHashOutput = createauthtable( B2fFsmFigure->NUMBER_OUT << 1 );
662 
663   for ( BehOut  = BehFigure->BEOUT;
664         BehOut != (beout_list *)0;
665         BehOut  = BehOut->NEXT )
666   {
667     addauthelem( B2fHashOutput, BehOut->NAME, (long)BehOut->NODE );
668   }
669 
670   B2fAddFsmCurrentState( BddCurrentSet );
671   B2fFsmFigure->FIRST_STATE = B2fCurrentState;
672   SetFsmFirstState( B2fCurrentState );
673 
674   B2fAddFsmLocalOutput( B2fCurrentState, BddCurrentSet );
675 
676   BddReachedSet = incbddrefext( BddCurrentSet );
677 
678   do
679   {
680     BddImageSet = BddLocalSystem->ZERO;
681 
682     do
683     {
684       BddCurrentState = satisfybddnodeassoc( (bddsystem *)0, BddCurrentSet, BddAssoc );
685 # ifdef DEBUG
686 fprintf( stdout, "CurrentState:\n" );
687 # endif
688       B2fAddFsmCurrentState( BddCurrentState );
689       B2fAddFsmLocalOutput( B2fCurrentState, BddCurrentState );
690 
691 # ifdef DEBUG
692 fprintf( stdout, "Image:\n" );
693 # endif
694       BddImage = imageb2ftransfunc( BtrTransFunc, BddCurrentState );
695       BddImageSet = applybddnode( (bddsystem *)0, ABL_OR,
696                                   decbddrefext( BddImageSet ),
697                                   decbddrefext( BddImage    ) );
698 
699       BddCurrentState = applybddnodenot( (bddsystem *)0, decbddrefext( BddCurrentState ) );
700       BddCurrentSet   = applybddnode( (bddsystem *)0, ABL_AND,
701                                       decbddrefext( BddCurrentSet   ),
702                                       decbddrefext( BddCurrentState ) );
703     }
704     while ( BddCurrentSet != BddLocalSystem->ZERO );
705 
706     BddCurrentSet = applybddnodenot( (bddsystem *)0, BddReachedSet );
707     BddCurrentSet = applybddnode( (bddsystem *)0, ABL_AND,
708                                   decbddrefext( BddImageSet   ),
709                                   decbddrefext( BddCurrentSet ) );
710 
711     BddReachedSet = applybddnode( (bddsystem *)0, ABL_OR,
712                                   decbddrefext( BddReachedSet ), BddCurrentSet );
713   }
714   while ( BddCurrentSet != BddLocalSystem->ZERO );
715 
716   decbddrefext( BddReachedSet );
717 
718   destroybtrtransfunc( BtrTransFunc );
719   delbddassoc( (bddsystem *)0, BddAssoc );
720 
721   autfreeblock( B2fStateArray );
722   autfreeblock( B2fStateName  );
723   autfreeblock( B2fStateIndex );
724 
725   destroyauthtable( B2fHashState  );
726   destroyauthtable( B2fHashOutput );
727 }
728 
729 /*------------------------------------------------------------\
730 |                                                             |
731 |                         Treat Beh Port                      |
732 |                                                             |
733 \------------------------------------------------------------*/
734 
B2fTreatPort(BehFigure)735 void B2fTreatPort( BehFigure )
736 
737   befig_list  *BehFigure;
738 {
739   bepor_list  *ScanPort;
740   char        *Vector;
741   long         Index;
742   int          FsmType = FSM_TYPE_BIT;
743 
744   for ( ScanPort  = BehFigure->BEPOR;
745         ScanPort != (bepor_list *)0;
746         ScanPort  = ScanPort->NEXT )
747   {
748     if ( ScanPort->DIRECTION == 'I' )
749     {
750       addfsmin( B2fFsmFigure, ScanPort->NAME );
751     }
752     else
753     {
754       addfsmout( B2fFsmFigure, ScanPort->NAME );
755     }
756 
757     Vector = vhdlablvector( ScanPort->NAME, &Index );
758 
759     switch ( ScanPort->TYPE )
760     {
761       case 'B' : if ( Vector != (char *)0 ) FsmType = FSM_TYPE_BIT_VEC;
762                  else                       FsmType = FSM_TYPE_BIT;
763       break;
764       case 'M' : if ( Vector != (char *)0 ) FsmType = FSM_TYPE_MUX_VEC;
765                  else                       FsmType = FSM_TYPE_MUX_BIT;
766       break;
767       case 'W' : if ( Vector != (char *)0 ) FsmType = FSM_TYPE_WOR_VEC;
768                  else                       FsmType = FSM_TYPE_WOR_BIT;
769       break;
770     }
771 
772     addfsmport( B2fFsmFigure, ScanPort->NAME, ScanPort->DIRECTION, FsmType );
773   }
774 }
775 
776 /*------------------------------------------------------------\
777 |                                                             |
778 |                         Treat Beh Register                  |
779 |                                                             |
780 \------------------------------------------------------------*/
781 
B2fTreatRegister(BehFigure)782 void B2fTreatRegister( BehFigure )
783 
784   befig_list  *BehFigure;
785 {
786   bereg_list  *ScanReg;
787   binode_list *BiNode;
788   bddnode     *BddNode;
789   chain_list  *Expr;
790   chain_list  *Support;
791   char        *RegName = NULL;
792   long         Index;
793 
794   B2fNumberRegister = 0;
795   B2fRegisterName   = (char *)0;
796   BddNode           = (bddnode    *)0;
797   Expr              = (chain_list *)0;
798 /*
799 ** Verify Register's conditions
800 */
801   for ( ScanReg  = BehFigure->BEREG;
802         ScanReg != (bereg_list *)0;
803         ScanReg  = ScanReg->NEXT )
804   {
805     RegName = vhdlablvector( ScanReg->NAME, &Index );
806 
807     if ( RegName == (char *)0 )
808     {
809       B2fError( B2F_REGISTER_NOT_A_VECTOR, ScanReg->NAME );
810     }
811 
812     BiNode = ScanReg->BINODE;
813 
814     if ( BddNode == (bddnode *)0 )
815     {
816       Expr    = ScanReg->BIABL->CNDABL;
817       BddNode = BiNode->CNDNODE;
818 
819       B2fRegisterName = RegName;
820     }
821     else
822     if ( BiNode->CNDNODE != BddNode )
823     {
824       B2fError( B2F_BAD_CONDITION_REGISTER, ScanReg->NAME );
825     }
826     else
827     if ( B2fRegisterName != RegName )
828     {
829       B2fError( B2F_BAD_REGISTER_NAME, B2fRegisterName );
830     }
831 
832     B2fNumberRegister = B2fNumberRegister + 1;
833   }
834 
835   if ( BddNode != (bddnode *)0 )
836   {
837     B2fFsmFigure->CLOCK_ABL = dupablexpr( Expr );
838     Support = getablexprsupport( Expr, ABL_SUPPORT_CHAIN );
839 
840     if ( ( Support       == (chain_list *)0 ) ||
841          ( Support->NEXT != (chain_list *)0 ) )
842     {
843       B2fError( B2F_BAD_CONDITION_REGISTER, RegName );
844     }
845 
846     B2fFsmFigure->CLOCK = (char *)Support->DATA;
847   }
848   else
849   {
850     B2fError( B2F_NO_REGISTER, BehFigure->NAME );
851   }
852 
853   B2fRegisterName   = RegName;
854 
855 # ifdef DEBUG
856   fprintf( stdout, "Found %ld registers\n", NumberReg );
857 # endif
858 }
859 
860 /*------------------------------------------------------------\
861 |                                                             |
862 |                        Beh To Fsm Figure                    |
863 |                                                             |
864 \------------------------------------------------------------*/
865 
B2fBeh2Fsm(BehFigure,FlagInitial,StringInitial)866 fsmfig_list *B2fBeh2Fsm( BehFigure, FlagInitial, StringInitial )
867 
868   befig_list *BehFigure;
869   char       *StringInitial;
870   int         FlagInitial;
871 {
872   bddcircuit  *BddCircuit;
873   bddsystem   *BddSystem;
874 
875   BddSystem = createbddsystem( 100, 1000, 100, 500000 );
876   reorderbddsystemdynamic( BddSystem, reorderbddsystemsimple, 10000, 100 );
877 
878   BehFigure->BEDLY = (beaux_list *)0;
879   beh_makbdd( BehFigure, 0, 0 );
880 
881   BddCircuit = (bddcircuit *)BehFigure->CIRCUI;
882 # ifdef DEBUG
883   testbddcircuit( BddCircuit );
884 # endif
885 
886   B2fFsmFigure = addfsmfig( BehFigure->NAME );
887 
888   B2fTreatPort( BehFigure );
889   B2fTreatRegister( BehFigure );
890   B2fTreatState( BehFigure, FlagInitial, StringInitial );
891 
892 # ifdef DEBUG
893   testbddcircuit( (bddcircuit *)0 );
894 # endif
895 
896   destroybddcircuit( BddCircuit );
897   destroybddsystem( BddSystem );
898 
899   return( B2fFsmFigure );
900 }
901