+++ /dev/null
-/* 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 <xbt/misc.h>
-
-/* 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
+++ /dev/null
-#!/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 <smpi_cocci.h>\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 = <STDIN>) {
- 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 = <STDIN>)) {
- last OUTER;
- }
- $line .= $nextline;
-
- }
- } while ($line =~ /SMPI_VARINIT/);
- } else {
- print $line;
- }
-}
+++ /dev/null
-
-@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)
#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()
+++ /dev/null
-// 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
-+)
-)
-...>
-}
+++ /dev/null
-// 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...
#include "mpi.h"
#include "mpitest.h"
-#include "smpi_cocci.h"
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_SYS_TIME_H
#include "mpi.h"
#include "mpitest.h"
-#include "smpi_cocci.h"
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_SYS_TIME_H
#include "mpi.h"
#include "mpitest.h"
-#include "smpi_cocci.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mpi.h"
#include "mpitestconf.h"
#include "mpitest.h"
-#include "smpi_cocci.h"
#if defined(HAVE_STDIO_H) || defined(STDC_HEADERS)
#include <stdio.h>
#endif
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