Implementation of MWP analysis on C code in Python.
Project description
pymwp is a tool for automatically performing static analysis on programs written in C. It analyzes resource usage and determines if a program's variables growth rates are no more than polynomially related to their inputs sizes.
For example,
int main(int X1, int X2, int X3){
X1 = X2 + X3;
X1 = X1 + X1;
}
is satisfactory because—between the initial variable values (Xi
) and the final values (Xi'
)—all variables have a polynomially bounded data-flow (omitting constants):
X1' ≤ X2+X3
and X2' ≤ X2
and X3' ≤ X3
. pymwp derives this bound automatically (⯈ demo).
However, program
int main(int X1, int X2, int X3){
X1 = 1;
while (X2 > 0){ X1 = X1 + X1; }
}
fails the analysis, because X1
grows exponentially (X1'
= $2^{\texttt{X2}}$).
pymwp reports a program is infinite when no polynomial bound can be derived (⯈ demo).
pymwp is inspired by "A Flow Calculus of mwp-Bounds for Complexity Analysis". Try our online demo to see it action. For more details, see pymwp documentation, particularly supported C language features.
Documentation and Demo
Documentation: statycc.github.io/pymwp
Demo: online demo and input examples
Publication: "pymwp: A Static Analyzer Determining Polynomial Growth Bounds", also on HAL.
Tool user guide: statycc.github.io/.github/pymwp with detailed examples and discussion.
The user guide is the ideal place to start for a general and interactive introduction to pymwp.
Installation
Install the latest release from PyPI
pip install pymwp
How to Use
Command-Line Use
To analyze a C file, run in terminal:
pymwp path/to_some_file.c
For a list of available command options and help, run:
pymwp
Use in Python Scripts
You can also use pymwp by importing it in a Python script. See modules documentation for details and examples.
Running from source
If you want to use the latest stable version—possibly ahead of the latest release, and with special evaluation utilities and input examples—use pymwp directly from source.
-
Clone the repository
git clone https://github.com/statycc/pymwp.git cd pymwp
-
Set up Python runtime environment of preference
:a: Using Python venv↗
Create and activate a virtual environment (POSIX bash/zsh):
python3 -m venv venv source venv/bin/activate
Install required packages:
python -m pip install -r requirements.txt
For development, install dev-dependencies instead:
python -m pip install -r requirements-dev.txt
:b: Using Docker↗
Build a container -- also installs dev-dependencies:
docker build . -t pymwp
Run the container:
docker run --rm -v "$(pwd):$(pwd)" pymwp
-
Run the analysis
From project root run:
python -m pymwp path/to_some_file.c
for example:
python -m pymwp c_files/basics/if.c
for all available options and help, run:
python -m pymwp
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 Distribution
Built Distribution
File details
Details for the file pymwp-0.5.0.tar.gz
.
File metadata
- Download URL: pymwp-0.5.0.tar.gz
- Upload date:
- Size: 65.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c908bcadd6ba18970dfa79f628f5495a20963c31948d8ef290a2c3744915bdb |
|
MD5 | 05f3c04ce39d2e35c59ea59e2b508d27 |
|
BLAKE2b-256 | 5d2fc65c43dcbdc6ff1087180e66c0d54ac6ab9b93649aa8ef6ce169b1328de9 |
File details
Details for the file pymwp-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: pymwp-0.5.0-py3-none-any.whl
- Upload date:
- Size: 77.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5705cb9f7f0f4af3276098b8b98e9d9eca27eef7314827a4b0f23d952a86275 |
|
MD5 | ec8062f18ffb6e751fda3d583c19831b |
|
BLAKE2b-256 | baa4c4339c01f3d6ee3a4c300aa0dbcdab87f6c2fccdf3804b5dfd64f1825266 |