DownloadCurrent version: 1.0.6, September 27, 2016 (changes).
Here is the source code of spatch. It requires OCaml and optionally python 2.5 to 2.7 or python 3. If you plan to modify the SmPL grammar or you do a "make distclean", thus removing all generated files, then you will also need to install menhir.
The source code of the various releases is also available at github.
We also provide pre-compiled versions of spatch in various formats:
- Without Python binding
- With Python binding
- Native code dynamically linked.
- OCaml bytecode, which requires an OCaml runtime. The bytecode was generated using OCaml 4.01.0, but may work with other versions of OCaml.
- OCaml bytecode in an Ubuntu package on PPA.
Add the PPA to your system with the following command line: sudo add-apt-repository ppa:npalix/coccinelle
If you need to manually add the signing key, also run sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 84ACD041
- Slackware, thanks to Dimitris Zlatanidis
- Debian, thanks to Eugeniy Meshcheryakov
- Ubuntu See also the Ubuntu package on PPA, which contains a more recent version of Coccincelle.
- Fedora, thanks to Richard W.M. Jones and Michal Schmidt
- Arch Linux, thanks to Sylvain HENRY
- NetBSD, thanks to Thomas Klausner
opam update opam install coccinelle
./spatch -cocci_file foo.cocci foo.c .
The output is in the file
/tmp/foo.c which will contain
the result of applying the semantic patch foo.cocci
to the C file foo.c modulo a set of isomorphisms
contained in standard.iso (standard.iso is by default located in
It is also possible to apply spatch to all of the C files in a directory:
./spatch -cocci_file foo.cocci -dir foodir . If the
semantic patch is not working as expected, it can be useful to use the
-debug to get a
trace of the metavariable bindings used for each rule.
Alexander Færøy has made a vim mode for use with Coccinelle semantic patches.