OpenScop  0.9.0
names.c
Go to the documentation of this file.
00001 
00002     /*+-----------------------------------------------------------------**
00003      **                       OpenScop Library                          **
00004      **-----------------------------------------------------------------**
00005      **                      extensions/names.c                         **
00006      **-----------------------------------------------------------------**
00007      **                   First version: 18/04/2011                     **
00008      **-----------------------------------------------------------------**
00009 
00010  
00011  *****************************************************************************
00012  * OpenScop: Structures and formats for polyhedral tools to talk together    *
00013  *****************************************************************************
00014  *    ,___,,_,__,,__,,__,,__,,_,__,,_,__,,__,,___,_,__,,_,__,                *
00015  *    /   / /  //  //  //  // /   / /  //  //   / /  // /  /|,_,             *
00016  *   /   / /  //  //  //  // /   / /  //  //   / /  // /  / / /\             *
00017  *  |~~~|~|~~~|~~~|~~~|~~~|~|~~~|~|~~~|~~~|~~~|~|~~~|~|~~~|/_/  \            *
00018  *  | G |C| P | = | L | P |=| = |C| = | = | = |=| = |=| C |\  \ /\           *
00019  *  | R |l| o | = | e | l |=| = |a| = | = | = |=| = |=| L | \# \ /\          *
00020  *  | A |a| l | = | t | u |=| = |n| = | = | = |=| = |=| o | |\# \  \         *
00021  *  | P |n| l | = | s | t |=| = |d| = | = | = | |   |=| o | | \# \  \        *
00022  *  | H | | y |   | e | o | | = |l|   |   | = | |   | | G | |  \  \  \       *
00023  *  | I | |   |   | e |   | |   | |   |   |   | |   | |   | |   \  \  \      *
00024  *  | T | |   |   |   |   | |   | |   |   |   | |   | |   | |    \  \  \     *
00025  *  | E | |   |   |   |   | |   | |   |   |   | |   | |   | |     \  \  \    *
00026  *  | * |*| * | * | * | * |*| * |*| * | * | * |*| * |*| * | /      \* \  \   *
00027  *  | O |p| e | n | S | c |o| p |-| L | i | b |r| a |r| y |/        \  \ /   *
00028  *  '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---'          '--'    *
00029  *                                                                           *
00030  * Copyright (C) 2008 University Paris-Sud 11 and INRIA                      *
00031  *                                                                           *
00032  * (3-clause BSD license)                                                    *
00033  * Redistribution and use in source  and binary forms, with or without       *
00034  * modification, are permitted provided that the following conditions        *
00035  * are met:                                                                  *
00036  *                                                                           *
00037  * 1. Redistributions of source code must retain the above copyright notice, *
00038  *    this list of conditions and the following disclaimer.                  *
00039  * 2. Redistributions in binary form must reproduce the above copyright      *
00040  *    notice, this list of conditions and the following disclaimer in the    *
00041  *    documentation and/or other materials provided with the distribution.   *
00042  * 3. The name of the author may not be used to endorse or promote products  *
00043  *    derived from this software without specific prior written permission.  *
00044  *                                                                           *
00045  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR      *
00046  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES *
00047  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.   *
00048  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,          *
00049  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT  *
00050  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
00051  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY     *
00052  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT       *
00053  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF  *
00054  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.         *
00055  *                                                                           *
00056  * OpenScop Library, a library to manipulate OpenScop formats and data       *
00057  * structures. Written by:                                                   *
00058  * Cedric Bastoul     <Cedric.Bastoul@u-psud.fr> and                         *
00059  * Louis-Noel Pouchet <Louis-Noel.pouchet@inria.fr>                          *
00060  *                                                                           *
00061  *****************************************************************************/
00062 
00063 #include <stdlib.h>
00064 #include <stdio.h>
00065 #include <string.h>
00066 
00067 #include <osl/macros.h>
00068 #include <osl/strings.h>
00069 #include <osl/names.h>
00070 
00071 
00072 /*+***************************************************************************
00073  *                          Structure display function                       *
00074  *****************************************************************************/
00075 
00076 
00087 void osl_names_idump(FILE * file, osl_names_p names, int level) {
00088   int j;
00089 
00090   // Go to the right level.
00091   for (j = 0; j < level; j++)
00092     fprintf(file, "|\t");
00093 
00094   if (names != NULL)
00095     fprintf(file, "+-- osl_names_t\n");
00096   else
00097     fprintf(file, "+-- NULL names\n");
00098 
00099   if (names != NULL) {
00100     // A blank line.
00101     for (j = 0; j <= level+1; j++)
00102       fprintf(file, "|\t");
00103     fprintf(file, "\n");
00104     
00105     // Print the various names.
00106     osl_strings_idump(file, names->parameters, level + 1);
00107     osl_strings_idump(file, names->iterators,  level + 1);
00108     osl_strings_idump(file, names->scatt_dims, level + 1);
00109     osl_strings_idump(file, names->local_dims, level + 1);
00110     osl_strings_idump(file, names->arrays,     level + 1);
00111   }
00112 
00113   // The last line.
00114   for (j = 0; j <= level; j++)
00115     fprintf(file, "|\t");
00116   fprintf(file, "\n");
00117 }
00118 
00119 
00127 void osl_names_dump(FILE * file, osl_names_p names) {
00128   osl_names_idump(file, names, 0);
00129 }
00130 
00131 
00132 /*****************************************************************************
00133  *                               Reading function                            *
00134  *****************************************************************************/
00135 
00136 
00137 /*+***************************************************************************
00138  *                    Memory allocation/deallocation function                *
00139  *****************************************************************************/
00140 
00141 
00150 osl_names_p osl_names_malloc() {
00151   osl_names_p names;
00152 
00153   OSL_malloc(names, osl_names_p, sizeof(osl_names_t));
00154   names->parameters = NULL;
00155   names->iterators  = NULL;
00156   names->scatt_dims = NULL;
00157   names->local_dims = NULL;
00158   names->arrays     = NULL;
00159 
00160   return names;
00161 }
00162 
00163 
00172 void osl_names_free(osl_names_p names) {
00173   if (names != NULL) {
00174     osl_strings_free(names->parameters);
00175     osl_strings_free(names->iterators);
00176     osl_strings_free(names->scatt_dims);
00177     osl_strings_free(names->local_dims);
00178     osl_strings_free(names->arrays);
00179 
00180     free(names);
00181   }
00182 }
00183 
00184 
00185 /*+***************************************************************************
00186  *                            Processing functions                           *
00187  *****************************************************************************/
00188 
00189 
00206 osl_names_p osl_names_generate(
00207     char * parameter_prefix, int nb_parameters,
00208     char * iterator_prefix,  int nb_iterators,
00209     char * scatt_dim_prefix, int nb_scatt_dims,
00210     char * local_dim_prefix, int nb_local_dims,
00211     char * array_prefix,     int nb_arrays) {
00212   osl_names_p names = osl_names_malloc();
00213 
00214   names->parameters= osl_strings_generate(parameter_prefix,nb_parameters);
00215   names->iterators = osl_strings_generate(iterator_prefix, nb_iterators);
00216   names->scatt_dims= osl_strings_generate(scatt_dim_prefix,nb_scatt_dims);
00217   names->local_dims= osl_strings_generate(local_dim_prefix,nb_local_dims);
00218   names->arrays    = osl_strings_generate(array_prefix,    nb_arrays);
00219   
00220   return names;
00221 }
00222 
00230 osl_names_p osl_names_clone(osl_names_p names) {
00231   osl_names_p clone = NULL;
00232   
00233   if (names != NULL) {
00234     clone = osl_names_malloc();
00235     clone->parameters = osl_strings_clone(names->parameters);
00236     clone->iterators  = osl_strings_clone(names->iterators);
00237     clone->scatt_dims = osl_strings_clone(names->scatt_dims);
00238     clone->local_dims = osl_strings_clone(names->local_dims);
00239     clone->arrays     = osl_strings_clone(names->arrays);
00240   }
00241   return clone;
00242 }