From cb986b581f9b9f0d3e8829875d31ca5e6dee8e41 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 3 Oct 2012 17:06:46 +0200 Subject: [PATCH] extract out pet_scop_add_array Signed-off-by: Sven Verdoolaege --- scan.cc | 14 +++----------- scop.c | 26 ++++++++++++++++++++++++++ scop.h | 3 +++ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/scan.cc b/scan.cc index 32160b5..89a856f 100644 --- a/scan.cc +++ b/scan.cc @@ -2052,7 +2052,6 @@ static struct pet_scop *scop_add_array(struct pet_scop *scop, { isl_ctx *ctx = isl_map_get_ctx(access); isl_space *dim; - struct pet_array **arrays; struct pet_array *array; if (!scop) @@ -2060,12 +2059,6 @@ static struct pet_scop *scop_add_array(struct pet_scop *scop, if (!ctx) goto error; - arrays = isl_realloc_array(ctx, scop->arrays, struct pet_array *, - scop->n_array + 1); - if (!arrays) - goto error; - scop->arrays = arrays; - array = isl_calloc_type(ctx, struct pet_array); if (!array) goto error; @@ -2083,11 +2076,10 @@ static struct pet_scop *scop_add_array(struct pet_scop *scop, array->element_size = ast_ctx.getTypeInfo(ast_ctx.IntTy).first / 8; array->uniquely_defined = 1; - scop->arrays[scop->n_array] = array; - scop->n_array++; - if (!array->extent || !array->context) - goto error; + array = pet_array_free(array); + + scop = pet_scop_add_array(scop, array); return scop; error: diff --git a/scop.c b/scop.c index f219582..034f414 100644 --- a/scop.c +++ b/scop.c @@ -3019,3 +3019,29 @@ struct pet_scop *pet_scop_reset_context(struct pet_scop *scop) return scop; } + +/* Append "array" to the arrays of "scop". + */ +struct pet_scop *pet_scop_add_array(struct pet_scop *scop, + struct pet_array *array) +{ + isl_ctx *ctx; + struct pet_array **arrays; + + if (!array || !scop) + goto error; + + ctx = isl_set_get_ctx(scop->context); + arrays = isl_realloc_array(ctx, scop->arrays, struct pet_array *, + scop->n_array + 1); + if (!arrays) + goto error; + scop->arrays = arrays; + scop->arrays[scop->n_array] = array; + scop->n_array++; + + return scop; +error: + pet_array_free(array); + return pet_scop_free(scop); +} diff --git a/scop.h b/scop.h index 954e712..aa6719b 100644 --- a/scop.h +++ b/scop.h @@ -99,6 +99,9 @@ struct pet_expr *pet_scop_get_skip_expr(struct pet_scop *scop, enum pet_skip type); void pet_scop_reset_skip(struct pet_scop *scop, enum pet_skip type); +struct pet_scop *pet_scop_add_array(struct pet_scop *scop, + struct pet_array *array); + #if defined(__cplusplus) } #endif -- 2.11.4.GIT