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 Library General|
11 | Public 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 | Tool    :                     Vex                           |
30 |                                                             |
31 | File    :                   vexis.c                         |
32 |                                                             |
33 | Date    :                   03.12.96                        |
34 |                                                             |
35 | Author  :               Jacomme Ludovic                     |
36 |                                                             |
37 \------------------------------------------------------------*/
38 /*------------------------------------------------------------\
39 |                                                             |
40 |                         Include Files                       |
41 |                                                             |
42 \------------------------------------------------------------*/
43 
44 # include "mut.h"
45 # include "aut.h"
46 # include "vex.h"
47 
48 # include <stdio.h>
49 # include "vexis.h"
50 # include "vexerror.h"
51 
52 /*------------------------------------------------------------\
53 |                                                             |
54 |                           Constants                         |
55 |                                                             |
56 \------------------------------------------------------------*/
57 /*------------------------------------------------------------\
58 |                                                             |
59 |                            Types                            |
60 |                                                             |
61 \------------------------------------------------------------*/
62 /*------------------------------------------------------------\
63 |                                                             |
64 |                          Varivexes                          |
65 |                                                             |
66 \------------------------------------------------------------*/
67 
68   short VexOperBinary[ VEX_MAX_OPERATOR ] =
69   {
70     3, /* VEX_CONCAT    */
71     0, /* VEX_NOT       */
72     0, /* VEX_NEG       */
73     0, /* VEX_EVENT     */
74     3, /* VEX_OR        */
75     3, /* VEX_AND       */
76     3, /* VEX_XOR       */
77     3, /* VEX_NOR       */
78     3, /* VEX_NAND      */
79     3, /* VEX_NXOR      */
80     2, /* VEX_EQ        */
81     2, /* VEX_NE        */
82     2, /* VEX_LT        */
83     2, /* VEX_LE        */
84     2, /* VEX_GT        */
85     2, /* VEX_GE        */
86     3, /* VEX_ADD       */
87     2, /* VEX_SUB       */
88     3, /* VEX_MUL       */
89     2, /* VEX_DIV       */
90     2, /* VEX_EXP       */
91     2, /* VEX_MOD       */
92     2, /* VEX_REM       */
93     3, /* VEX_TO        */
94     3, /* VEX_DOWNTO    */
95     2, /* VEX_INDEX     */
96     0, /* VEX_LEFT      */
97     0, /* VEX_RIGHT     */
98     0, /* VEX_LOW       */
99     0, /* VEX_HIGH      */
100     0, /* VEX_LENGTH    */
101     0, /* VEX_RANGE     */
102     0, /* VEX_REV_RANGE */
103     0, /* VEX_DRIVER    */
104     2, /* VEX_IFT       */
105     4, /* VEX_ARRAY     */
106     3, /* VEX_INDEX_N   */
107     0, /* VEX_OTHERS    */
108     2, /* VEX_NUM_BIT   */
109     0, /* VEX_ABS       */
110     0, /* VEX_AF        */
111     0, /* VEX_AG        */
112     0, /* VEX_AX        */
113     2, /* VEX_AU        */
114     0, /* VEX_EF        */
115     0, /* VEX_EG        */
116     0, /* VEX_EX        */
117     2, /* VEX_EU        */
118     2, /* VEX_EQUIV     */
119     2  /* VEX_IMPLY     */
120   };
121 
122   short VexOperArith[ VEX_MAX_OPERATOR ] =
123   {
124     0, /* VEX_CONCAT    */
125     0, /* VEX_NOT       */
126     1, /* VEX_NEG       */
127     0, /* VEX_EVENT     */
128     0, /* VEX_OR        */
129     0, /* VEX_AND       */
130     0, /* VEX_XOR       */
131     0, /* VEX_NOR       */
132     0, /* VEX_NAND      */
133     0, /* VEX_NXOR      */
134     1, /* VEX_EQ        */
135     1, /* VEX_NE        */
136     1, /* VEX_LT        */
137     1, /* VEX_LE        */
138     1, /* VEX_GT        */
139     1, /* VEX_GE        */
140     1, /* VEX_ADD       */
141     1, /* VEX_SUB       */
142     1, /* VEX_MUL       */
143     1, /* VEX_DIV       */
144     1, /* VEX_EXP       */
145     1, /* VEX_MOD       */
146     1, /* VEX_REM       */
147     0, /* VEX_TO        */
148     0, /* VEX_DOWNTO    */
149     0, /* VEX_INDEX     */
150     0, /* VEX_LEFT      */
151     0, /* VEX_RIGHT     */
152     0, /* VEX_LOW       */
153     0, /* VEX_HIGH      */
154     0, /* VEX_LENGTH    */
155     0, /* VEX_RANGE     */
156     0, /* VEX_REV_RANGE */
157     0, /* VEX_DRIVER    */
158     0, /* VEX_IFT       */
159     0, /* VEX_ARRAY     */
160     0, /* VEX_INDEX_N   */
161     1, /* VEX_OTHERS    */
162     0, /* VEX_NUM_BIT   */
163     1, /* VEX_ABS       */
164     0, /* AF            */
165     0, /* AG            */
166     0, /* AX            */
167     0, /* AU            */
168     0, /* EF            */
169     0, /* EG            */
170     0, /* EX            */
171     0, /* EU            */
172     0, /* EQUIV         */
173     0  /* IMPLY         */
174   };
175 
176   short VexOperNegative[ VEX_MAX_OPERATOR ] =
177   {
178     0, /* VEX_CONCAT    */
179     1, /* VEX_NOT       */
180     0, /* VEX_NEG       */
181     0, /* VEX_EVENT     */
182     0, /* VEX_OR        */
183     0, /* VEX_AND       */
184     0, /* VEX_XOR       */
185     1, /* VEX_NOR       */
186     1, /* VEX_NAND      */
187     1, /* VEX_NXOR      */
188     0, /* VEX_EQ        */
189     0, /* VEX_NE        */
190     0, /* VEX_LT        */
191     0, /* VEX_LE        */
192     0, /* VEX_GT        */
193     0, /* VEX_GE        */
194     0, /* VEX_ADD       */
195     0, /* VEX_SUB       */
196     0, /* VEX_MUL       */
197     0, /* VEX_DIV       */
198     0, /* VEX_EXP       */
199     0, /* VEX_MOD       */
200     0, /* VEX_REM       */
201     0, /* VEX_TO        */
202     0, /* VEX_DOWNTO    */
203     0, /* VEX_INDEX     */
204     0, /* VEX_LEFT      */
205     0, /* VEX_RIGHT     */
206     0, /* VEX_LOW       */
207     0, /* VEX_HIGH      */
208     0, /* VEX_LENGTH    */
209     0, /* VEX_RANGE     */
210     0, /* VEX_REV_RANGE */
211     0, /* VEX_DRIVER    */
212     0, /* VEX_IFT       */
213     0, /* VEX_ARRAY     */
214     0, /* VEX_INDEX_N   */
215     0, /* VEX_OTHERS    */
216     0, /* VEX_NUM_BIT   */
217     0, /* VEX_ABS       */
218     0, /* AF            */
219     0, /* AG            */
220     0, /* AX            */
221     0, /* AU            */
222     0, /* EF            */
223     0, /* EG            */
224     0, /* EX            */
225     0, /* EU            */
226     0, /* EQUIV         */
227     0  /* IMPLY         */
228   };
229 
230   short VexTypeDivisible[ VEX_MAX_TYPE ] =
231   {
232     0, /* SEVERITY          */
233     0, /* BOOLEAN           */
234     0, /* CHARACTER         */
235     1, /* STRING            */
236     0, /* BIT               */
237     0, /* INTEGER           */
238     0, /* NATURAL           */
239     1, /* BIT_VECTOR        */
240     0, /* STD_ULOGIC        */
241     0, /* STD_LOGIC         */
242     1, /* STD_ULOGIC_VECTOR */
243     1, /* STD_LOGIC_VECTOR  */
244     0, /* X01               */
245     0, /* X01Z              */
246     0, /* UX01              */
247     0, /* UX01Z             */
248     1, /* UNSIGNED          */
249     1, /* SIGNED            */
250     0, /* SMALL_INT         */
251     0, /* REG_BIT           */
252     1, /* REG_VECTOR        */
253     0, /* MUX_BIT           */
254     1, /* MUX_VECTOR        */
255     0, /* WOR_BIT           */
256     1, /* WOR_VECTOR        */
257     0, /* ENUMERATE         */
258     1  /* ARRAY             */
259   };
260 
261   short VexTypeVector[ VEX_MAX_TYPE ] =
262   {
263     0, /* SEVERITY          */
264     0, /* BOOLEAN           */
265     0, /* CHARACTER         */
266     1, /* STRING            */
267     0, /* BIT               */
268     1, /* INTEGER           */
269     1, /* NATURAL           */
270     1, /* BIT_VECTOR        */
271     0, /* STD_ULOGIC        */
272     0, /* STD_LOGIC         */
273     1, /* STD_ULOGIC_VECTOR */
274     1, /* STD_LOGIC_VECTOR  */
275     0, /* X01               */
276     0, /* X01Z              */
277     0, /* UX01              */
278     0, /* UX01Z             */
279     1, /* UNSIGNED          */
280     1, /* SIGNED            */
281     0, /* SMALL_INT         */
282     0, /* REG_BIT           */
283     1, /* REG_VECTOR        */
284     0, /* MUX_BIT           */
285     1, /* MUX_VECTOR        */
286     0, /* WOR_BIT           */
287     1, /* WOR_VECTOR        */
288     1, /* ENUMERATE         */
289     1  /* ARRAY             */
290   };
291 
292   static char *VexIsName = (char *)0;
293   static long  VexIsOper = (long  )0;
294 
295 /*------------------------------------------------------------\
296 |                                                             |
297 |                          Functions                          |
298 |                                                             |
299 \------------------------------------------------------------*/
300 /*------------------------------------------------------------\
301 |                                                             |
302 |                        Is  Functions                        |
303 |                                                             |
304 \------------------------------------------------------------*/
305 /*------------------------------------------------------------\
306 |                                                             |
307 |                     Is Vex Type Vector                      |
308 |                                                             |
309 \------------------------------------------------------------*/
310 
isvextypevector(Type)311 int isvextypevector( Type )
312 
313   int Type;
314 {
315   if ( ( Type < 0             ) ||
316        ( Type >= VEX_MAX_TYPE ) )
317   {
318     return( -1 );
319   }
320 
321   return( VexTypeVector[ Type ] );
322 }
323 
324 /*------------------------------------------------------------\
325 |                                                             |
326 |                     Is Vex Type Divisible                   |
327 |                                                             |
328 \------------------------------------------------------------*/
329 
isvextypedivisible(Type)330 int isvextypedivisible( Type )
331 
332   int Type;
333 {
334   if ( ( Type < 0             ) ||
335        ( Type >= VEX_MAX_TYPE ) )
336   {
337     return( -1 );
338   }
339 
340   return( VexTypeDivisible[ Type ] );
341 }
342 
343 /*------------------------------------------------------------\
344 |                                                             |
345 |                     Is Vex Positive Operator                |
346 |                                                             |
347 \------------------------------------------------------------*/
348 
isvexpositiveoper(Oper)349 int isvexpositiveoper( Oper )
350 
351   long  Oper;
352 {
353   if ( ( Oper < 0                 ) ||
354        ( Oper >= VEX_MAX_OPERATOR ) )
355   {
356     return( -1 );
357   }
358 
359   return( ! VexOperNegative[ Oper ] );
360 }
361 
362 /*------------------------------------------------------------\
363 |                                                             |
364 |                     Is Vex Negative Operator                |
365 |                                                             |
366 \------------------------------------------------------------*/
367 
isvexnegativeoper(Oper)368 int isvexnegativeoper( Oper )
369 
370   long  Oper;
371 {
372   if ( ( Oper < 0                 ) ||
373        ( Oper >= VEX_MAX_OPERATOR ) )
374   {
375     return( -1 );
376   }
377 
378   return( VexOperNegative[ Oper ] );
379 }
380 
381 /*------------------------------------------------------------\
382 |                                                             |
383 |                     Is Vex Unary Operator                   |
384 |                                                             |
385 \------------------------------------------------------------*/
386 
isvexunaryoper(Oper)387 int isvexunaryoper( Oper )
388 
389   long  Oper;
390 {
391   if ( ( Oper < 0                 ) ||
392        ( Oper >= VEX_MAX_OPERATOR ) )
393   {
394     return( -1 );
395   }
396 
397   return( ! VexOperBinary[ Oper ] );
398 }
399 
400 /*------------------------------------------------------------\
401 |                                                             |
402 |                     Is Vex Binary Operator                  |
403 |                                                             |
404 \------------------------------------------------------------*/
405 
isvexbinaryoper(Oper)406 int isvexbinaryoper( Oper )
407 
408   long  Oper;
409 {
410   if ( ( Oper < 0                 ) ||
411        ( Oper >= VEX_MAX_OPERATOR ) )
412   {
413     return( -1 );
414   }
415 
416   return( VexOperBinary[ Oper ] );
417 }
418 
419 /*------------------------------------------------------------\
420 |                                                             |
421 |                     Is Vex Ternary Operator                 |
422 |                                                             |
423 \------------------------------------------------------------*/
424 
isvexternaryoper(Oper)425 int isvexternaryoper( Oper )
426 
427   long  Oper;
428 {
429   if ( ( Oper < 0                 ) ||
430        ( Oper >= VEX_MAX_OPERATOR ) )
431   {
432     return( -1 );
433   }
434 
435   return( VexOperBinary[ Oper ] == 3 );
436 }
437 
438 /*------------------------------------------------------------\
439 |                                                             |
440 |                     Is Local Operator In Expr               |
441 |                                                             |
442 \------------------------------------------------------------*/
443 
loc_isvexoperinexpr(Expr)444 static int loc_isvexoperinexpr( Expr )
445 
446   vexexpr *Expr;
447 {
448   chain_list *ScanOper;
449 
450   if ( IsVexNodeAtom( Expr ) )
451   {
452     return( 0 );
453   }
454 
455   if ( IsVexNodeOper( Expr ) )
456   {
457     if ( GetVexOperValue( Expr ) == VexIsOper )
458     {
459       return( 1 );
460     }
461   }
462 
463   for ( ScanOper  = Expr->OPERAND;
464         ScanOper != (chain_list *)0;
465         ScanOper  = ScanOper->NEXT )
466   {
467     if ( loc_isvexoperinexpr( GetVexOperand( ScanOper ) ) )
468     {
469       return( 1 );
470     }
471   }
472 
473   return( 0 );
474 }
475 
476 /*------------------------------------------------------------\
477 |                                                             |
478 |                     Is Vex Operator In Expr                 |
479 |                                                             |
480 \------------------------------------------------------------*/
481 
isvexoperinexpr(Expr,Oper)482 int isvexoperinexpr( Expr, Oper )
483 
484   vexexpr *Expr;
485   long     Oper;
486 {
487   VexIsOper = Oper;
488 
489   return( loc_isvexoperinexpr( Expr ) );
490 }
491 
492 /*------------------------------------------------------------\
493 |                                                             |
494 |              Is Local Arithmetic Operator In Expr           |
495 |                                                             |
496 \------------------------------------------------------------*/
497 
loc_isvexarithoperinexpr(Expr)498 static int loc_isvexarithoperinexpr( Expr )
499 
500   vexexpr *Expr;
501 {
502   chain_list *ScanOper;
503   vexexpr    *Operand1;
504   vexexpr    *Operand2;
505   long        Oper;
506 
507   if ( IsVexNodeAtom( Expr ) )
508   {
509     return( 0 );
510   }
511 
512   if ( IsVexNodeOper( Expr ) )
513   {
514     Oper = GetVexOperValue( Expr );
515 
516     if ( VexOperArith[ Oper ] )
517     {
518       if ( ( Oper == VEX_EQ ) ||
519            ( Oper == VEX_NE ) )
520       {
521         Operand1 = GetVexOperand( Expr->OPERAND );
522         Operand2 = GetVexOperand( Expr->OPERAND->NEXT );
523 
524         if ( Operand1->WIDTH == Operand2->WIDTH )
525         {
526           return( 0 );
527         }
528       }
529 
530       return( 1 );
531     }
532   }
533 
534   for ( ScanOper  = Expr->OPERAND;
535         ScanOper != (chain_list *)0;
536         ScanOper  = ScanOper->NEXT )
537   {
538     if ( loc_isvexarithoperinexpr( GetVexOperand( ScanOper ) ) )
539     {
540       return( 1 );
541     }
542   }
543 
544   return( 0 );
545 }
546 
547 /*------------------------------------------------------------\
548 |                                                             |
549 |                 Is Vex Arithmetic Operator In Expr          |
550 |                                                             |
551 \------------------------------------------------------------*/
552 
isvexarithoperinexpr(Expr)553 int isvexarithoperinexpr( Expr )
554 
555   vexexpr *Expr;
556 {
557   return( loc_isvexarithoperinexpr( Expr ) );
558 }
559 
560 
561 /*------------------------------------------------------------\
562 |                                                             |
563 |                     Is Local Name In Expr                   |
564 |                                                             |
565 \------------------------------------------------------------*/
566 
loc_isvexnameinexpr(Expr)567 static int loc_isvexnameinexpr( Expr )
568 
569   vexexpr *Expr;
570 {
571   chain_list *ScanOper;
572 
573   if ( IsVexNodeAtom( Expr ) )
574   {
575     if ( GetVexAtomValue( Expr ) == VexIsName ) return( 1 );
576 
577     return( 0 );
578   }
579 
580   for ( ScanOper  = Expr->OPERAND;
581         ScanOper != (chain_list *)0;
582         ScanOper  = ScanOper->NEXT )
583   {
584     if ( loc_isvexnameinexpr( GetVexOperand( ScanOper ) ) )
585     {
586       return( 1 );
587     }
588   }
589 
590   return( 0 );
591 }
592 
593 /*------------------------------------------------------------\
594 |                                                             |
595 |                     Is Vex Name In Expr                     |
596 |                                                             |
597 \------------------------------------------------------------*/
598 
isvexnameinexpr(Expr,Name)599 int isvexnameinexpr( Expr, Name )
600 
601   vexexpr *Expr;
602   char    *Name;
603 {
604   VexIsName = namealloc( Name );
605 
606   return( loc_isvexnameinexpr( Expr ) );
607 }
608 
609 /*------------------------------------------------------------\
610 |                                                             |
611 |                     Is Vex Equal Expr                       |
612 |                                                             |
613 \------------------------------------------------------------*/
614 
isvexequalexpr(Expr1,Expr2)615 int isvexequalexpr( Expr1, Expr2 )
616 
617   vexexpr *Expr1;
618   vexexpr *Expr2;
619 {
620   chain_list  *ScanOper1;
621   chain_list  *ScanOper2;
622 
623   if ( ( Expr1 == (vexexpr *)0 ) ||
624        ( Expr2 == (vexexpr *)0 ) )
625   {
626     return( 0 );
627   }
628 
629   if ( ( Expr1->VALUE != Expr2->VALUE ) ||
630        ( Expr1->TYPE  != Expr2->TYPE  ) ||
631        ( Expr1->LEFT  != Expr2->LEFT  ) ||
632        ( Expr1->RIGHT != Expr2->RIGHT ) )
633   {
634     return( 0 );
635   }
636 
637 
638   if ( ! IsVexNodeAtom( Expr1 ) )
639   {
640     ScanOper1 = Expr1->OPERAND;
641     ScanOper2 = Expr2->OPERAND;
642 
643     while ( ( ScanOper1 != (chain_list *)0 ) &&
644             ( ScanOper2 != (chain_list *)0 ) )
645     {
646       if ( ! isvexequalexpr( GetVexOperand( ScanOper1 ),
647                              GetVexOperand( ScanOper2 ) ) )
648       {
649         return( 0 );
650       }
651 
652       ScanOper1 = ScanOper1->NEXT;
653       ScanOper2 = ScanOper2->NEXT;
654     }
655 
656     if ( ( ScanOper1 != (chain_list *)0 ) ||
657          ( ScanOper2 != (chain_list *)0 ) )
658     {
659       return( 0 );
660     }
661   }
662 
663   return( 1 );
664 }
665