Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
commiting some more automatic source patching stuff, and renamed some of the
authormarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 18 Jan 2011 10:07:54 +0000 (10:07 +0000)
committermarkls <markls@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 18 Jan 2011 10:07:54 +0000 (10:07 +0000)
macros for purely arbitrary aesthetic reasons. Eventually this all needs to
cleanly rolled into smpicc, but for now we're just testing and don't want to
break anyting...

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

include/smpi/smpi_cocci.h
src/smpi/fixsrc.pl [new file with mode: 0755]
src/smpi/patch_source.sh [new file with mode: 0755]
src/smpi/replace_globals.cocci

index 29daeec..1cce1a6 100644 (file)
@@ -9,8 +9,8 @@
 
 /* Macros used by coccinelle-generated code */
 
 
 /* Macros used by coccinelle-generated code */
 
-#define SMPI_INITIALIZE_GLOBAL(name,type)                       \
-   NULL;                                                        \
+#define SMPI_VARINIT_GLOBAL(name,type)                       \
+type *name = NULL;                                                        \
 void __attribute__((weak,constructor)) __preinit_##name(void) { \
    if(!name)                                                    \
       name = (type*)malloc(smpi_global_size() * sizeof(type));  \
 void __attribute__((weak,constructor)) __preinit_##name(void) { \
    if(!name)                                                    \
       name = (type*)malloc(smpi_global_size() * sizeof(type));  \
@@ -20,8 +20,8 @@ void __attribute__((weak,destructor)) __postfini_##name(void) { \
    name = NULL;                                                 \
 }
 
    name = NULL;                                                 \
 }
 
-#define SMPI_INITIALIZE_AND_SET_GLOBAl(name,type,expr)          \
-   NULL;                                                        \
+#define SMPI_VARINIT_GLOBAL_AND_SET(name,type,expr)          \
+type *name = NULL;                                                        \
 void __attribute__((weak,constructor)) __preinit_##name(void) { \
    size_t size = smpi_global_size();                            \
    size_t i;                                                    \
 void __attribute__((weak,constructor)) __preinit_##name(void) { \
    size_t size = smpi_global_size();                            \
    size_t i;                                                    \
@@ -38,6 +38,6 @@ void __attribute__((weak,destructor)) __postfini_##name(void) { \
    name = NULL;                                                 \
 }
 
    name = NULL;                                                 \
 }
 
-#define SMPI_GLOBAL_VAR_LOCAL_ACCESS(name) name[smpi_process_index()]
+#define SMPI_VARGET_GLOBAL(name) name[smpi_process_index()]
 
 #endif
 
 #endif
diff --git a/src/smpi/fixsrc.pl b/src/smpi/fixsrc.pl
new file mode 100755 (executable)
index 0000000..096c720
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+
+# FIXME: here we make the assumption that people don't do things like put
+# multiple statements 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 = <STDIN>) {
+    if ($line =~ /#include <mpi\.h>/) {
+        print "#include <smpi.h>\n";
+        print "#include <smpi_cocci.h>\n";
+    } elsif ($line =~ /SMPI_VARINIT/) {
+        do {
+            chomp $line;
+            $line =~ s/\s+/ /g;
+            while ($line =~ s/(SMPI_VARINIT[A-Z0-9_]*?\(.*?\))//) {
+                print "$1\n";
+            } 
+            if ($line =~ /SMPI_VARINIT/) {
+                # should only happen for bad code...
+                if (!($nextline = <STDIN>)) {
+                    last OUTER;
+                }
+                $line .= $nextline;
+
+            }
+        } while ($line =~ /SMPI_VARINIT/);
+    } else {
+        print $line;
+    }
+}
diff --git a/src/smpi/patch_source.sh b/src/smpi/patch_source.sh
new file mode 100755 (executable)
index 0000000..9b43196
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/bash
+INFILE="$1"
+OUTFILE="$2"
+SPFILE="replace_globals.cocci"
+spatch -sp_file ${SPFILE} $1 -o $2.tmp >/dev/null 2>/dev/null
+./fixsrc.pl < $2.tmp > $2
+rm $2.tmp
index c112eb8..4608a2a 100644 (file)
@@ -1,6 +1,14 @@
+// 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
 // FIXME: problems
-//   - does not want to match dynamic arrays...
+//   - array declarations not properly matched...can fix, but then can't have
+//   multiple declarations on one line
 //   - does not match array initializers
 //   - does not match array initializers
+//   - probably won't fix structure declarations with initialization either
 
 // Function prototype looks like variable dec, but has parentheses
 @funcproto@
 
 // Function prototype looks like variable dec, but has parentheses
 @funcproto@
@@ -38,33 +46,33 @@ type T;
 identifier var;
 position p != { localvardecl.p, funcproto.p };
 expression value;
 identifier var;
 position p != { localvardecl.p, funcproto.p };
 expression value;
-constant size;
+expression size;
 @@
 (
 T@p 
 - var
 @@
 (
 T@p 
 - var
-+ *var = SMPI_INITIALIZE_GLOBAL(var, T)
++ *var = SMPI_VARINIT_GLOBAL(var, T)
 ;
 |
 T@p
 - var = value 
 ;
 |
 T@p
 - var = value 
-+ *var = SMPI_INITIALIZE_AND_SET_GLOBAL(var, T, value)
-;
-|
-T@p
-- var[]
-+ *var[] = SMPI_INITIALIZE_GLOBAL_ARRAY(T, size)
-;
-|
-T@p
-- var[size]
-+ *var[] = SMPI_INITIALIZE_GLOBAL_STATIC_ARRAY(T, size)
-;
-|
-T@p
-- var[size] = { ... }
-+ *var[] = SMPI_INITIALIZE_AND_SET_GLOBAL_STATIC_ARRAY(T, size)
++ *var = SMPI_VARINIT_GLOBAL_AND_SET(var, T, value)
 ;
 ;
+//|
+//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: how to match initializer?
+//- var[size] = { ... }
+//+ *var[] = SMPI_VARINIT_GLOBAL_ARRAY_AND_SET(T, size, { ... })
+//;
+//|
+//T@p // FIXME: how to match initializer? how to figure out size?
+//- var[] = { ... }
+//+ *var[] = SMPI_VARINIT_GLOBAL_ARRAY_AND_SET(T, size, { ... }) // size = ?
+//;
 )
 
 @rewritelocalaccess@
 )
 
 @rewritelocalaccess@
@@ -76,7 +84,7 @@ identifier globalvardecl.var;
 (
 lvar
 |
 (
 lvar
 |
-+SMPI_GLOBAL_VAR_LOCAL_ACCESS(
++SMPI_VARGET_GLOBAL(
 var
 +)
 )
 var
 +)
 )