1 | #include "mdd.h" |
---|
2 | |
---|
3 | /* |
---|
4 | * MDD Package |
---|
5 | * |
---|
6 | * $Id: mdd_substit.c,v 1.10 2002/08/24 21:48:15 fabio Exp $ |
---|
7 | * |
---|
8 | * Author: Timothy Kam |
---|
9 | * |
---|
10 | * Copyright 1992 by the Regents of the University of California. |
---|
11 | * |
---|
12 | * All rights reserved. Permission to use, copy, modify and distribute |
---|
13 | * this software is hereby granted, provided that the above copyright |
---|
14 | * notice and this permission notice appear in all copies. This software |
---|
15 | * is made available as is, with no warranties. |
---|
16 | */ |
---|
17 | |
---|
18 | array_t * |
---|
19 | mdd_substitute_array( |
---|
20 | mdd_manager *mgr, |
---|
21 | array_t *fn_array, |
---|
22 | array_t *old_mvars, |
---|
23 | array_t *new_mvars) |
---|
24 | { |
---|
25 | array_t *new_fn_array; |
---|
26 | mdd_t *new_fn, *fn; |
---|
27 | int i; |
---|
28 | |
---|
29 | new_fn_array = array_alloc(mdd_t *, 0); |
---|
30 | arrayForEachItem(mdd_t *, fn_array, i, fn) { |
---|
31 | new_fn = mdd_substitute(mgr, fn, old_mvars, new_mvars); |
---|
32 | array_insert(mdd_t *, new_fn_array, i, new_fn); |
---|
33 | } |
---|
34 | |
---|
35 | return(new_fn_array); |
---|
36 | } |
---|
37 | |
---|
38 | mdd_t * |
---|
39 | mdd_substitute( |
---|
40 | mdd_manager *mgr, |
---|
41 | mdd_t *fn, |
---|
42 | array_t *old_mvars, |
---|
43 | array_t *new_mvars) |
---|
44 | { |
---|
45 | array_t *old_bdd_vars, *new_bdd_vars; |
---|
46 | int i, j, old_mv_no, new_mv_no, no_mvar; |
---|
47 | mvar_type old_mv, new_mv; |
---|
48 | mdd_t *top; |
---|
49 | array_t *mvar_list = mdd_ret_mvar_list(mgr); |
---|
50 | bdd_t *varBdd; |
---|
51 | |
---|
52 | old_bdd_vars = array_alloc( bdd_t *, 0); |
---|
53 | new_bdd_vars = array_alloc( bdd_t *, 0); |
---|
54 | |
---|
55 | no_mvar = array_n(old_mvars); |
---|
56 | if (no_mvar != array_n(new_mvars)) |
---|
57 | fail("mdd_substitute: arrays contains different no. of mvars.\n"); |
---|
58 | |
---|
59 | for (i=0; i<no_mvar; i++) { |
---|
60 | old_mv_no = array_fetch(int, old_mvars, i); |
---|
61 | old_mv = array_fetch(mvar_type, mvar_list, old_mv_no); |
---|
62 | if (old_mv.status == MDD_BUNDLED) { |
---|
63 | (void) fprintf(stderr, |
---|
64 | "\nmdd_substitute: bundled variable %s used\n",old_mv.name); |
---|
65 | fail(""); |
---|
66 | } |
---|
67 | |
---|
68 | new_mv_no = array_fetch(int, new_mvars, i); |
---|
69 | new_mv = array_fetch(mvar_type, mvar_list, new_mv_no); |
---|
70 | if (new_mv.status == MDD_BUNDLED) { |
---|
71 | (void) fprintf(stderr, |
---|
72 | "\nmdd_substitute: bundled variable %s used\n",new_mv.name); |
---|
73 | fail(""); |
---|
74 | } |
---|
75 | |
---|
76 | if (old_mv.values != new_mv.values) |
---|
77 | fail("mdd_substitute: mvars have different no. of values\n"); |
---|
78 | |
---|
79 | for (j=0; j<old_mv.encode_length; j++) { |
---|
80 | varBdd = bdd_get_variable( mgr, mdd_ret_bvar_id(&old_mv,j) ); |
---|
81 | array_insert_last( bdd_t *, old_bdd_vars, varBdd ); |
---|
82 | |
---|
83 | varBdd = bdd_get_variable( mgr, mdd_ret_bvar_id(&new_mv, j) ); |
---|
84 | array_insert_last( bdd_t *, new_bdd_vars, varBdd); |
---|
85 | } |
---|
86 | } |
---|
87 | top = bdd_substitute(fn, old_bdd_vars, new_bdd_vars); |
---|
88 | |
---|
89 | for(j=0; j<array_n(old_bdd_vars); j++) { |
---|
90 | varBdd = array_fetch(bdd_t*,old_bdd_vars,j); |
---|
91 | bdd_free(varBdd); |
---|
92 | } |
---|
93 | array_free(old_bdd_vars); |
---|
94 | for(j=0; j<array_n(new_bdd_vars); j++) { |
---|
95 | varBdd = array_fetch(bdd_t*,new_bdd_vars,j); |
---|
96 | bdd_free(varBdd); |
---|
97 | } |
---|
98 | array_free(new_bdd_vars); |
---|
99 | |
---|
100 | return top; |
---|
101 | } |
---|
102 | |
---|
103 | /*---------------------------------------------------------------------------*/ |
---|
104 | /* Static function prototypes */ |
---|
105 | /*---------------------------------------------------------------------------*/ |
---|
106 | |
---|