From: Frederic Suter Date: Fri, 5 Feb 2016 13:00:57 +0000 (+0100) Subject: privatization with coccinelle is outdated X-Git-Tag: v3_13~973^2~6 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/791a79648c2a7246c2a7f7d434d79987c4c3b39c privatization with coccinelle is outdated --- diff --git a/include/smpi/smpi_cocci.h b/include/smpi/smpi_cocci.h deleted file mode 100644 index f938a9bdf2..0000000000 --- a/include/smpi/smpi_cocci.h +++ /dev/null @@ -1,77 +0,0 @@ -/* Copyright (c) 2011-2014. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#ifndef SMPI_COCCI_H -#define SMPI_COCCI_H - -#include - -/* Macros used by coccinelle-generated code */ - -#define SMPI_VARINIT_GLOBAL(name,type) \ -type *name = NULL; \ -static void __attribute__((constructor)) __preinit_##name(void) { \ - if(!name) \ - name = (type*)calloc(smpi_global_size(), sizeof(type)); \ -} \ -static void __attribute__((destructor)) __postfini_##name(void) { \ - free(name); \ - name = NULL; \ -} - -#define SMPI_VARINIT_GLOBAL_AND_SET(name,type,expr) \ -type *name = NULL; \ -static void __attribute__((constructor)) __preinit_##name(void) { \ - size_t size = smpi_global_size(); \ - size_t i; \ - type value = expr; \ - if(!name) { \ - name = (type*)malloc(size * sizeof(type)); \ - for(i = 0; i < size; i++) { \ - name[i] = value; \ - } \ - } \ -} \ -static void __attribute__((destructor)) __postfini_##name(void) { \ - free(name); \ - name = NULL; \ -} - -#define SMPI_VARGET_GLOBAL(name) name[smpi_process_index()] - -/* The following handle local static variables */ -/** @brief Make sure that the passed pointer is freed on process exit. - * - * This function is rather internal, mainly used for the - * privatization of global variables through coccinelle. - */ -XBT_PUBLIC(void) smpi_register_static(void* arg, void_f_pvoid_t free_fn); - -XBT_PUBLIC(void) smpi_free_static(void); - -#define SMPI_VARINIT_STATIC(name,type) \ -static type *name = NULL; \ -if(!name) { \ - name = (type*)calloc(smpi_global_size(), sizeof(type)); \ - smpi_register_static(name, xbt_free_f); \ -} - -#define SMPI_VARINIT_STATIC_AND_SET(name,type,expr) \ -static type *name = NULL; \ -if(!name) { \ - size_t size = smpi_global_size(); \ - size_t i; \ - type value = expr; \ - name = (type*)malloc(size * sizeof(type)); \ - for(i = 0; i < size; i++) { \ - name[i] = value; \ - } \ - smpi_register_static(name, xbt_free_f); \ -} - -#define SMPI_VARGET_STATIC(name) name[smpi_process_index()] - -#endif diff --git a/src/smpi/fixsrc.pl b/src/smpi/fixsrc.pl deleted file mode 100755 index 8844d208c5..0000000000 --- a/src/smpi/fixsrc.pl +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env perl - -# Copyright (c) 2011, 2014. The SimGrid Team. -# All rights reserved. - -# This program is free software; you can redistribute it and/or modify it -# under the terms of the license (GNU LGPL) which comes with this package. - -# Add include for mandatory header file -print "#include \n"; - -# FIXME: here we make the assumption that people don't do things like put -# multiple statements on the same line after a declaration, but separated by -# semicolons. It's a reasonable assumption for the time being, but technically -# it could cause problems for some code. - -OUTER: while ($line = ) { - if ($line =~ /SMPI_VARINIT/) { - do { - chomp $line; # kill carriage return - $line =~ s/\s+/ /g; # remove excessive whitespace added by spatch - while ($line =~ s/(SMPI_VARINIT[A-Z0-9_]*?\(.*?\))//) { - print "$1\n"; - } - - # if varinit continues on to next line - if ($line =~ /SMPI_VARINIT/) { - # should only happen for bad code... - if (!($nextline = )) { - last OUTER; - } - $line .= $nextline; - - } - } while ($line =~ /SMPI_VARINIT/); - } else { - print $line; - } -} diff --git a/src/smpi/myprintloc.cocci b/src/smpi/myprintloc.cocci deleted file mode 100644 index bea1b79f30..0000000000 --- a/src/smpi/myprintloc.cocci +++ /dev/null @@ -1,122 +0,0 @@ - -@r@ -/* Matching a declaration, ie rewriting site candidate - Disqualify the candidate - ----------------- */ -type T; -position p1; -identifier id; -@@ - -T id@p1; - - - - -@funcdecl@ -# Matching a /function/ declaration. -# Disqualify the candidate -#----------------- -type T; -position r.p1; -identifier id; -@@ - T id@p1(...) {...} - - - - -@funcproto@ -# Matching a function prototype w/o body. -# Disqualify the candidate -#----------------- -type T; -position r.p1; -identifier id; -@@ - T id@p1(...); - -@localdeclaration@ -# Matching a declaration at the top level of a function. -# Disqualify the candidate -#----------------- -type T1,T2; -position r.p1; -identifier id1,id2; -@@ - -T1 id1(...) { - ... - T2 id2@p1; - ... -} - -@localinnerdeclaration@ -# The next rule is there to make sure that we are not speaking of a -# local variable declared in an inner block. I don't like it at all: -# It is redundent and gives false negative on the foreach macros that -# get often declared in the code. Example in examples/gras/spawn.c: -# -# int server() { -# ... -# xbt_dynar_foreach(chunk->primes,cursor,data) { -# char number[100]; -# ... -# } -# ... -# } -# -# Do I really need to complicate this rule further to add every macro -# that we use in our C, or can it be merged with the previous one by -# saying something like "in a function, at whatever level of nesting"? - -type T1,T2; -position r.p1; -identifier id1,id2; -expression e1,e2,e3; -@@ - -T1 id1(...) { - ... -( - for (e1;e2;e3) { ... T2 id2@p1; ... } -| - for (;e2;e3) { ... T2 id2@p1; ... } -| - for (e1;;e3) { ... T2 id2@p1; ... } -| - for (e1;e2;) { ... T2 id2@p1; ... } -| - for (e1;;) { ... T2 id2@p1; ... } -| - for (;e2;) { ... T2 id2@p1; ... } -| - for (;;e3) { ... T2 id2@p1; ... } -| - for (;;) { ... T2 id2@p1; ... } -| - while (e1) { ... T2 id2@p1; ... } -| - do { ... T2 id2@p1; ... } while (e1); -) - ... -} - - - -@script:python depends on r - && !funcdecl - && !funcproto - && !localdeclaration - && !localinnerdeclaration@ - -# This rule is only a debugging rule, to print the sites where the -# change must be applied - -p1 << r.p1; -T << r.T; -id << r.id; -@@ - -c1 = cocci.combine(id,p1) -print "1. symbol %s of type \"%s\" at %s:%s" % (id,T,c1.location.line,c1.location.column) diff --git a/src/smpi/private.h b/src/smpi/private.h index 6f657207d9..44528e6804 100644 --- a/src/smpi/private.h +++ b/src/smpi/private.h @@ -15,7 +15,6 @@ #include "simgrid/simix.h" #include "src/include/smpi/smpi_interface.h" #include "smpi/smpi.h" -#include "smpi/smpi_cocci.h" #include "src/instr/instr_private.h" SG_BEGIN_DECL() diff --git a/src/smpi/replace_globals.cocci b/src/smpi/replace_globals.cocci deleted file mode 100644 index 00a6ca5fff..0000000000 --- a/src/smpi/replace_globals.cocci +++ /dev/null @@ -1,134 +0,0 @@ -// FIXME: seems like cocci has problems manipulating the declarations, at least -// when there is more than one on the same line. We already need perl to split -// up the declarations after the fact, is there another tool we can use to patch -// up and match the declarations? In that case we could consider dropping cocci, -// or just using it to alter global variable accesses. -// -// FIXME: problems -// - array declarations not properly matched...can fix, but then can't have -// multiple declarations on one line -// - does not match array initializers -// - probably won't fix structure declarations with initialization either - -// Function prototype looks like variable dec, but has parentheses -@funcproto@ -type T; -identifier func; -position p; -@@ -T@p func(...); - -// define a local variable declaration as one at some level of nesting -@localvardecl@ -type T; -identifier var; -position p; -expression E; -@@ -<... -( // default case -T@p -var -; -| // variable has initializer -T@p -var = E -; -) -...> - -// define a global variable declaration as one that is neither a function -// prototype nor a local variable declaration -@globalvardecl@ -type T; -identifier var; -position p != { funcproto.p, localvardecl.p }; -expression value; -// expression size; -@@ -( // default case -T@p -- var -+ *var = SMPI_VARINIT_GLOBAL(var, T) -; -| // variable has initializer (not a struct or array) -T@p -- var = value -+ *var = SMPI_VARINIT_GLOBAL_AND_SET(var, T, value) -; -//| // array of specified size -//T@p // FIXME: matches, but complains if more than one decl on a line... -//- var[size] -//+ *var[size] = SMPI_VARINIT_GLOBAL_ARRAY(T, size) -//; -//| // array of specified size with initializer -//T@p // FIXME: how to match initializer? -//- var[size] = { ... } -//+ *var[] = SMPI_VARINIT_GLOBAL_ARRAY_AND_SET(T, size, { ... }) -//; -//| // array without specified size, but with initializer -//T@p // FIXME: how to match initializer? how to figure out size? -//- var[] = { ... } -//+ *var[] = SMPI_VARINIT_GLOBAL_ARRAY_AND_SET(T, size, { ... }) // size = ? -//; -//| struct with initializer? -) - -// rewrite access to global variables based on name, but avoid the declaration -// and local variables that might have the same name -@rewriteglobalaccess@ -type T; -local idexpression lvar; -identifier globalvardecl.var; -@@ -<... -( // local variable -lvar -| // rewrite access -+SMPI_VARGET_GLOBAL( -var -+) -) -...> - -// define a local static variable declaration as one at some level of nesting -// starting with the word static (exceptions?) -@staticvardecl@ -type T; -identifier func, var; -expression value; -@@ -func(...) { -... -( // default case -static T -- var -+ *var = SMPI_VARINIT_STATIC(T, var) -; -| // variable has initializer (not a struct or array) -T -- var = value -+ *var = SMPI_VARINIT_STATIC_AND_SET(var, T, value) -; -) -... -} - -// -@rewritestaticaccess@ -type T; -identifier staticvardecl.func, staticvardecl.var; -@@ -func(...) { -<... -( // declaration -T -var -; -| // rewrite access -+SMPI_VARGET_STATIC( -var -+) -) -...> -} diff --git a/src/smpi/replace_static.cocci b/src/smpi/replace_static.cocci deleted file mode 100644 index cda1de2e53..0000000000 --- a/src/smpi/replace_static.cocci +++ /dev/null @@ -1,67 +0,0 @@ -// FIXME: why can't I just define a static local vardecl the same way as a -// normal local vardecl? - -// Function prototype looks like variable dec, but has parentheses -@funcproto@ -type T; -identifier func; -position p; -@@ -T@p func(...); - -// Define a local variable as one whose declaration is encased in brackets -@localvardecl@ -type T; -identifier var; -position p; -expression E; -@@ -{ -<... -( -T@p -var -; -| -T@p -var = E -; -) -...> -} - -// global variable is one whose declaration is neither local nor a function -// prototype -@globalvardecl@ -type T; -identifier var; -position p != { localvardecl.p, funcproto.p }; -expression value; -// expression size; -@@ -( -T@p var; -| -T@p var = value; -) - -// local static decl is a nonglobal static decl... -@localstaticvardecl@ -type T; -identifier var; -position p != globalvardecl.p; -expression value; -@@ -( -static T@p -- var -+ *var = SMPI_VARINIT_STATIC(var, T) -; -| -static T@p -- var = value -+ *var = SMPI_VARINIT_STATIC_AND_SET(var, T, value) -; -) - -// FIXME: add varaccess... diff --git a/teshsuite/smpi/mpich3-test/coll/allgatherv4.c b/teshsuite/smpi/mpich3-test/coll/allgatherv4.c index 2af91af50e..65e73f5f3b 100644 --- a/teshsuite/smpi/mpich3-test/coll/allgatherv4.c +++ b/teshsuite/smpi/mpich3-test/coll/allgatherv4.c @@ -7,7 +7,6 @@ #include "mpi.h" #include "mpitest.h" -#include "smpi_cocci.h" #include #include #ifdef HAVE_SYS_TIME_H diff --git a/teshsuite/smpi/mpich3-test/coll/allgatherv4_manual.c b/teshsuite/smpi/mpich3-test/coll/allgatherv4_manual.c index 60bf0a4ebe..4249a92524 100644 --- a/teshsuite/smpi/mpich3-test/coll/allgatherv4_manual.c +++ b/teshsuite/smpi/mpich3-test/coll/allgatherv4_manual.c @@ -7,7 +7,6 @@ #include "mpi.h" #include "mpitest.h" -#include "smpi_cocci.h" #include #include #ifdef HAVE_SYS_TIME_H diff --git a/teshsuite/smpi/mpich3-test/coll/allred.c b/teshsuite/smpi/mpich3-test/coll/allred.c index bf13e8aa55..3caf57ec81 100644 --- a/teshsuite/smpi/mpich3-test/coll/allred.c +++ b/teshsuite/smpi/mpich3-test/coll/allred.c @@ -10,7 +10,6 @@ #include "mpi.h" #include "mpitest.h" -#include "smpi_cocci.h" #include #include #include diff --git a/teshsuite/smpi/mpich3-test/util/mtest_manual.c b/teshsuite/smpi/mpich3-test/util/mtest_manual.c index e922072ddf..e0813e7671 100644 --- a/teshsuite/smpi/mpich3-test/util/mtest_manual.c +++ b/teshsuite/smpi/mpich3-test/util/mtest_manual.c @@ -7,7 +7,6 @@ #include "mpi.h" #include "mpitestconf.h" #include "mpitest.h" -#include "smpi_cocci.h" #if defined(HAVE_STDIO_H) || defined(STDC_HEADERS) #include #endif diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index ad8c50b592..e4926ca286 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -679,7 +679,6 @@ set(headers_to_install include/simgrid/plugins/energy.h include/smpi/mpi.h include/smpi/smpi.h - include/smpi/smpi_cocci.h include/smpi/smpi_main.h include/surf/simgrid_dtd.h include/surf/surf_routing.h