X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=pbqp_node.c;h=b324e49b359d99d53e624f0963e74d445034a827;hb=6c2d6c360d082f09aca2c2b332c047789a75b81f;hp=9e6044e7e1004f71e5b3f9b5328b4f525069e3a8;hpb=3bdce993078b47054b3f5c6ee1302a983fd3976c;p=libfirm diff --git a/pbqp_node.c b/pbqp_node.c index 9e6044e7e..b324e49b3 100644 --- a/pbqp_node.c +++ b/pbqp_node.c @@ -1,3 +1,31 @@ +/* + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * + * This file is part of libFirm. + * + * This file may be distributed and/or modified under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation and appearing in the file LICENSE.GPL included in the + * packaging of this file. + * + * Licensees holding valid libFirm Professional Edition licenses may use + * this file in accordance with the libFirm Commercial License. + * Agreement provided with the Software. + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +/** + * @file + * @brief PBQP nodes. + * @date 02.10.2008 + * @author Sebastian Buchwald + * @version $Id$ + */ +#include "config.h" + #include "adt/array.h" #include "assert.h" @@ -72,7 +100,7 @@ unsigned pbqp_node_get_degree(pbqp_node *node) return ARR_LEN(node->edges); } -pbqp_node *pbqp_node_deep_copy(pbqp *pbqp, pbqp_node_bucket old_bucket, pbqp_node *node) +pbqp_node *pbqp_node_deep_copy(pbqp *pbqp, pbqp_node_bucket new_bucket, pbqp_node *node) { unsigned edge_index; unsigned edge_length = pbqp_node_get_degree(node); @@ -90,8 +118,17 @@ pbqp_node *pbqp_node_deep_copy(pbqp *pbqp, pbqp_node_bucket old_bucket, pbqp_nod unsigned is_copied = other_index < node->bucket_index; if (is_copied) { - edge->src = copy; - edge_copy = edge; + pbqp_node *other_copy = new_bucket[other_index]; + unsigned degree = pbqp_node_get_degree(other_copy); + unsigned index; + + for (index = 0; index < degree; ++index) { + if (other_copy->edges[index]->src == node) { + edge_copy = other_copy->edges[index]; + edge_copy->src = copy; + break; + } + } } else { edge_copy = pbqp_edge_deep_copy(pbqp, edge, copy, edge->tgt); } @@ -100,8 +137,17 @@ pbqp_node *pbqp_node_deep_copy(pbqp *pbqp, pbqp_node_bucket old_bucket, pbqp_nod unsigned is_copied = other_index < node->bucket_index; if (is_copied) { - edge->tgt = copy; - edge_copy = edge; + pbqp_node *other_copy = new_bucket[other_index]; + unsigned degree = pbqp_node_get_degree(other_copy); + unsigned index; + + for (index = 0; index < degree; ++index) { + if (other_copy->edges[index]->tgt == node) { + edge_copy = other_copy->edges[index]; + edge_copy->tgt = copy; + break; + } + } } else { edge_copy = pbqp_edge_deep_copy(pbqp, edge, edge->src, copy); }