2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of Bison, the GNU Compiler Compiler.
6 Bison is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 Bison is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Bison; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
27 relation_print (relation_t relation
, size_t size
, FILE *out
)
31 for (i
= 0; i
< size
; ++i
)
33 fprintf (out
, "%3d: ", i
);
35 for (j
= 0; relation
[i
][j
] != -1; ++j
)
36 fprintf (out
, "%3d ", relation
[i
][j
]);
43 /*---------------------------------------------------------------.
44 | digraph & traverse. |
46 | The following variables are used as common storage between the |
48 `---------------------------------------------------------------*/
51 static relation_nodes_t INDEX
;
52 static relation_nodes_t VERTICES
;
64 INDEX
[i
] = height
= top
;
67 for (j
= 0; R
[i
][j
] >= 0; ++j
)
69 if (INDEX
[R
[i
][j
]] == 0)
72 if (INDEX
[i
] > INDEX
[R
[i
][j
]])
73 INDEX
[i
] = INDEX
[R
[i
][j
]];
75 bitset_or (F
[i
], F
[i
], F
[R
[i
][j
]]);
78 if (INDEX
[i
] == height
)
87 bitset_copy (F
[j
], F
[i
]);
93 relation_digraph (relation_t relation
, size_t size
,
99 INDEX
= XCALLOC (relation_node_t
, size
+ 1);
100 VERTICES
= XCALLOC (relation_node_t
, size
+ 1);
106 for (i
= 0; i
< size
; i
++)
109 for (i
= 0; i
< size
; i
++)
110 if (INDEX
[i
] == 0 && R
[i
])
120 /*-------------------------------------------.
121 | Destructively transpose R_ARG, of size N. |
122 `-------------------------------------------*/
125 relation_transpose (relation_t
*R_arg
, int n
)
128 relation_t new_R
= XCALLOC (relation_nodes_t
, n
);
129 /* END_R[I] -- next entry of NEW_R[I]. */
130 relation_t end_R
= XCALLOC (relation_nodes_t
, n
);
131 /* NEDGES[I] -- total size of NEW_R[I]. */
132 int *nedges
= XCALLOC (int, n
);
137 fputs ("relation_transpose: input\n", stderr
);
138 relation_print (*R_arg
, n
, stderr
);
142 for (i
= 0; i
< n
; i
++)
144 for (j
= 0; (*R_arg
)[i
][j
] >= 0; ++j
)
145 ++nedges
[(*R_arg
)[i
][j
]];
148 for (i
= 0; i
< n
; i
++)
151 relation_node_t
*sp
= XCALLOC (relation_node_t
, nedges
[i
] + 1);
158 for (i
= 0; i
< n
; i
++)
160 for (j
= 0; (*R_arg
)[i
][j
] >= 0; ++j
)
162 *end_R
[(*R_arg
)[i
][j
]] = i
;
163 ++end_R
[(*R_arg
)[i
][j
]];
169 /* Free the input: it is replaced with the result. */
170 for (i
= 0; i
< n
; i
++)
176 fputs ("relation_transpose: output\n", stderr
);
177 relation_print (new_R
, n
, stderr
);