Skip to main content

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

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.

  1. Clone the repository

    git clone https://github.com/statycc/pymwp.git 
    cd pymwp
    
  2. 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
    
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymwp-0.5.5.tar.gz (67.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymwp-0.5.5-py3-none-any.whl (78.4 kB view details)

Uploaded Python 3

File details

Details for the file pymwp-0.5.5.tar.gz.

File metadata

  • Download URL: pymwp-0.5.5.tar.gz
  • Upload date:
  • Size: 67.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for pymwp-0.5.5.tar.gz
Algorithm Hash digest
SHA256 794ce0a747fbfd1295eba3dbc6095888c0c54193725393aafa956e9f69cfc0f9
MD5 d6d49fe4ce6b700011a4ee3a5d85acac
BLAKE2b-256 2916b8ee988db4471f2066a75a5efabb3a28070625a8c688d35287e8ffa85662

See more details on using hashes here.

File details

Details for the file pymwp-0.5.5-py3-none-any.whl.

File metadata

  • Download URL: pymwp-0.5.5-py3-none-any.whl
  • Upload date:
  • Size: 78.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for pymwp-0.5.5-py3-none-any.whl
Algorithm Hash digest
SHA256 abde666a15b2707aa17a894d36415a6e7136b3bbb96990b0f6bf872f49b3dc9f
MD5 a484b826fb91d3e9fc0b1390677942ad
BLAKE2b-256 b72e0f3fc706c9472dd41ffeb91b778622c1870e66d25912f24354b68a3b7ebc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page