From d747dab846b3f846fe378976b4c0ab26b6026fbb Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 23 Aug 2013 11:16:31 +0200 Subject: [PATCH] extract out pet_clang_base_type into separate file We will also want to use it from scop_plus.cc. Signed-off-by: Sven Verdoolaege --- Makefile.am | 2 ++ clang.cc | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ clang.h | 8 ++++++++ scan.cc | 20 ++------------------ 4 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 clang.cc create mode 100644 clang.h diff --git a/Makefile.am b/Makefile.am index a150429..f3f9461 100644 --- a/Makefile.am +++ b/Makefile.am @@ -34,6 +34,8 @@ AM_CXXFLAGS = $(INCLUDES) $(CLANG_CXXFLAGS) @ISL_CFLAGS@ AM_LDFLAGS = $(CLANG_LDFLAGS) libpet_la_SOURCES = \ + clang.h \ + clang.cc \ options.h \ options.c \ print.c \ diff --git a/clang.cc b/clang.cc new file mode 100644 index 0000000..fca093b --- /dev/null +++ b/clang.cc @@ -0,0 +1,53 @@ +/* + * Copyright 2011 Leiden University. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY LEIDEN UNIVERSITY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LEIDEN UNIVERSITY OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as + * representing official policies, either expressed or implied, of + * Leiden University. + */ + +#include "clang.h" + +using namespace clang; + +/* Return the element type of the given array type. + */ +QualType pet_clang_base_type(QualType qt) +{ + const Type *type = qt.getTypePtr(); + + if (type->isPointerType()) + return pet_clang_base_type(type->getPointeeType()); + if (type->isArrayType()) { + const ArrayType *atype; + type = type->getCanonicalTypeInternal().getTypePtr(); + atype = cast(type); + return pet_clang_base_type(atype->getElementType()); + } + return qt; +} diff --git a/clang.h b/clang.h new file mode 100644 index 0000000..8592ed8 --- /dev/null +++ b/clang.h @@ -0,0 +1,8 @@ +#ifndef PET_CLANG_H +#define PET_CLANG_H + +#include + +clang::QualType pet_clang_base_type(clang::QualType qt); + +#endif diff --git a/scan.cc b/scan.cc index 97dcebe..82c2a6a 100644 --- a/scan.cc +++ b/scan.cc @@ -47,6 +47,7 @@ #include #include +#include "clang.h" #include "options.h" #include "scan.h" #include "scop.h" @@ -899,23 +900,6 @@ static int extract_depth(__isl_keep isl_multi_pw_aff *index) return array_depth(decl->getType().getTypePtr()); } -/* Return the element type of the given array type. - */ -static QualType base_type(QualType qt) -{ - const Type *type = qt.getTypePtr(); - - if (type->isPointerType()) - return base_type(type->getPointeeType()); - if (type->isArrayType()) { - const ArrayType *atype; - type = type->getCanonicalTypeInternal().getTypePtr(); - atype = cast(type); - return base_type(atype->getElementType()); - } - return qt; -} - /* Extract an index expression from a reference to a variable. * If the variable has name "A", then the returned index expression * is of the form @@ -5114,7 +5098,7 @@ struct pet_array *PetScan::extract_array(isl_ctx *ctx, ValueDecl *decl) QualType qt = get_array_type(decl); const Type *type = qt.getTypePtr(); int depth = array_depth(type); - QualType base = base_type(qt); + QualType base = pet_clang_base_type(qt); string name; isl_id *id; isl_space *dim; -- 2.11.4.GIT