A C/C++ code instrumenter used in DEAD
Project description
dead-instrument
is the instrumenter used in DEAD.
To build just the clang tool
Prerequisites: cmake
, make
, clang/llvm
13/14.
mkdir build
cd build
cmake ..
cmake --build . [--parallel]
cmake --install . --prefix=/where/to/install/
Usage
cat test.c
int foo(int a) {
if (a == 0)
return 1;
else {
a = 5;
}
return a;
}
dead-instrument test.c --
cat test.c
void DCEMarker0_(void);
void DCEMarker1_(void);
int foo(int a) {
if (a == 0) {
DCEMarker1_();
return 1;
} else {
DCEMarker0_();
a = 5;
}
return a;
}
It is also possible to emit macros used for disabling parts of the code that have found to be dead:
./dead-instrument --emit-disable-macros test.c --
cat test.c
void DCEMarker0_(void);
void DCEMarker1_(void);
int foo(int a) {
#if !defined(DeleteBlockDCEMarker0_) || !defined(DeleteBlockDCEMarker1_)
#if !defined(DeleteBlockDCEMarker0_) && !defined(DeleteBlockDCEMarker1_)
if (
#endif
a == 0
#if !defined(DeleteBlockDCEMarker0_) && !defined(DeleteBlockDCEMarker1_)
)
#else
;
#endif
#ifndef DeleteBlockDCEMarker1_
{
DCEMarker1_();
return 1;
}
#endif
#if !defined(DeleteBlockDCEMarker0_) && !defined(DeleteBlockDCEMarker1_)
else
#endif
#ifndef DeleteBlockDCEMarker0_
{
DCEMarker0_();
a = 5;
}
#endif
#endif
return a;
}
gcc -E -P -DDeleteBlockDCEMarker0_ test.c | clang-format disabled_dead_code_macros_squashed
void DCEMarker0_(void);
void DCEMarker1_(void);
int foo(int a) {
a == 0;
{
DCEMarker1_();
return 1;
}
return a;
}
Python wrapper
pip install dead-instrumenter
To use the instrumenter in python import from dead_instrumenter.instrumenter import instrument_program
: instrument_program(program: diopter.SourceProgram) -> InstrumentedProgram
.
Building the python wrapper
Local build
./build_python_wheel_local.sh #this will build the current branch
pip install .
Docker based build
docker run --rm -e REVISION=REV -v `pwd`:/io theodort/manylinux-with-llvm:latest /io/build_python_wheel_docker.sh
This will build multiple wheels for REV
with multiple python versions.
The output is stored in the wheelhouse
directory.
The docker image is based on https://github.com/thetheodor/manylinux-with-llvm.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for dead_instrumenter-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79d8e5f51d8f671ebffed281719facf498e73442b3f46daca49124c044dea1ca |
|
MD5 | 0562c31f8241b28806814707b359af58 |
|
BLAKE2b-256 | 724346bf39b530132405eafbe4c20ed31de0cb8dcd6726425eb560831d24fc8c |
Hashes for dead_instrumenter-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5360f7d7479cf0b2f444f20461a2d612789b65e12a7c61c5ed9408d0aafd370 |
|
MD5 | 78da77e9623f0dcf497370d3e08bd429 |
|
BLAKE2b-256 | 96dd46b0e65f03809f951a58749767a4bbde4779c41537e479caf75089a54422 |