Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
updated patch file to work with static variables. This probably needs some
authormarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 20 Jan 2011 10:43:09 +0000 (10:43 +0000)
committermarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 20 Jan 2011 10:43:09 +0000 (10:43 +0000)
testing, and maybe we should rename the .cocci file, and maybe roll all of this
into smpicc, possibly with a command line switch to output revised source
instead of compiling it.

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9446 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/smpi/patch_source.sh
src/smpi/replace_globals.cocci

index fa085bb..89e981b 100755 (executable)
@@ -2,7 +2,7 @@
 INFILE="$1"
 OUTFILE="$2"
 SPFILE="replace_globals.cocci"
 INFILE="$1"
 OUTFILE="$2"
 SPFILE="replace_globals.cocci"
-TMPFILE=`mktemp`
+TMPFILE=`mktemp ${OUTFILE}.XXXX`
 
 trap "rm -f ${TMPFILE}" EXIT
 spatch -sp_file ${SPFILE} ${INFILE} -o ${TMPFILE} >/dev/null 2>/dev/null
 
 trap "rm -f ${TMPFILE}" EXIT
 spatch -sp_file ${SPFILE} ${INFILE} -o ${TMPFILE} >/dev/null 2>/dev/null
index 5b80e5c..da0e6ab 100644 (file)
@@ -18,75 +18,111 @@ position p;
 @@
 T@p func(...);
 
 @@
 T@p func(...);
 
-// Define a local variable as one whose declaration is encased in brackets
+// define a local variable declaration as one at some level of nesting
 @localvardecl@
 type T;
 identifier var;
 position p;
 expression E;
 @@
 @localvardecl@
 type T;
 identifier var;
 position p;
 expression E;
 @@
-{
 <...
 <...
-(
+( // default case
 T@p
 var
 ;
 T@p
 var
 ;
-|
+| // variable has initializer
 T@p
 var = E
 ;
 )
 ...>
 T@p
 var = E
 ;
 )
 ...>
-}
 
 
-// global variable is one whose declaration is neither local nor a function
-// prototype
+// define a global variable declaration as one that is neither a function
+// prototype nor a local variable declaration
 @globalvardecl@
 type T;
 identifier var;
 @globalvardecl@
 type T;
 identifier var;
-position p != { localvardecl.p, funcproto.p };
+position p != { funcproto.p, localvardecl.p };
 expression value;
 // expression size;
 @@
 expression value;
 // expression size;
 @@
-(
+( // default case
 T@p 
 - var
 + *var = SMPI_VARINIT_GLOBAL(var, T)
 ;
 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)
 ;
 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)
 //;
 //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, { ... })
 //;
 //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 = ?
 //;
 //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?
 )
 
 )
 
-@rewritelocalaccess@
+// 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 idexpression lvar;
 identifier globalvardecl.var;
 @@
-{
 <...
 <...
-(
+( // local variable
 lvar
 lvar
-|
+| // rewrite access
 +SMPI_VARGET_GLOBAL(
 var
 +)
 )
 ...>
 +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 var;
+expression value;
+@@
+<...
+( // 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.var;
+@@
+( // declaration
+T
+var
+;
+| // rewrite access
++SMPI_VARGET_STATIC(
+var
++)
+)