Skip to main content

The PPCI (Pure Python Compiler Infrastructure) project is a compiler written entirely in the Python programming language. It contains front-ends for various programming languages as well as machine code generation functionality. With this library you can generate (working!) machine code using Python (and thus very easy to explore, extend, etc.)!

The project contains:

  • Language frontends for C, Python, Pascal, Basic and Brainfuck

  • Code generation for several architectures: 6500, arm, avr, m68k, microblaze, msp430, openrisc, risc-v, stm8, x86_64, xtensa

  • Command line utilities, such as ppci-cc, ppci-ld and ppci-opt

  • WebAssembly, JVM, OCaml support

  • Support for ELF, EXE, S-record and hexfile formats

  • An intermediate representation (IR) which can be serialized in json

  • The project can be used as a library so you can script the compilation process

Installation

Since the compiler is a python package, you can install it with pip:

$ pip install ppci

Usage

An example of commandline usage:

$ cd examples/linux64/hello-make
$ ppci-cc -c -O1 -o hello.o hello.c
...
$ ppci-ld --entry main --layout linux64.ld hello.o -o hello
...
$ ./hello
Hello, World!

API example to compile C code:

>>> import io
>>> from ppci.api import cc, link
>>> source_file = io.StringIO("""
...  int printf(char* fmt) { }
...
...  void main() {
...     printf("Hello world!\n");
...  }
... """)
>>> obj = cc(source_file, 'arm')
>>> obj = link([obj])

Example how to assemble some assembly code:

>>> import io
>>> from ppci.api import asm
>>> source_file = io.StringIO("""section code
... pop rbx
... push r10
... mov rdi, 42""")
>>> obj = asm(source_file, 'x86_64')
>>> obj.get_section('code').data
bytearray(b'[ARH\xbf*\x00\x00\x00\x00\x00\x00\x00')

Example of the low level api usage:

>>> from ppci.arch.x86_64 import instructions, registers
>>> i = instructions.Pop(registers.rbx)
>>> i.encode()
b'['

Functionality

  • Command line utilities:
  • Can be used with tools like make or other build tools.

  • Language support:
    • C

    • Pascal

    • Python

    • Basic

    • Brainfuck

    • C3 (PPCI’s own systems language, intended to address some pitfalls of C)

  • CPU support:
    • 6500, arm, avr, m68k, microblaze, msp430, openrisc, risc-v, stm8, x86_64, xtensa

  • Support for:
    • WebAssembly

    • JVM

    • OCaml bytecode

    • LLVM IR

    • DWARF debugging format

  • File formats:
    • ELF files

    • COFF PE (EXE) files

    • hex files

    • S-record files

  • Uses well known human-readable and machine-processable formats like JSON and XML as its tools’ formats.

Documentation

Documentation can be found here:

You can try out PPCI at godbolt.org, a site which offers Web access to various compilers: https://godbolt.org/g/eooaPP

gitter appveyor codecov docstate travis codacygrade codacycoverage downloads conda

Release files for ppci 0.5.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ppci 0.5.8
File Size Uploaded
ppci-0.5.8.tar.gz 564.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ppci 0.5.8
File Interpreter ABI Platform
ppci-0.5.8-py3-none-any.whl Python 3 none any Details

Total release size: 1.2 MB

Release files / ppci-0.5.8.tar.gz

Download URL ppci-0.5.8.tar.gz
Size 564.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c4c3c2033cac5b97d994117d15e994db0fa17746a6fcd13629e1eb87e49a3934
BLAKE2b-256 checksum
How to use checksums
d557ec7df16b9a8341b3cc6897351f553531d6ee13421e811dd8f1f2f2f253c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.8

Release files / ppci-0.5.8-py3-none-any.whl

Download URL ppci-0.5.8-py3-none-any.whl
Size 682.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd35009946b3de79a590c799ea74f415f7151227e54f345bd193b034ef2cc561
BLAKE2b-256 checksum
How to use checksums
3bf2644170663569dd0bc44df59d2b89b1888f81815d8232b93fb7a0fce0f58f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.8

Release history Release notifications | RSS feed

This release

0.5.8 This release

2 release files

0.5.7

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

3 release files

0.5

2 release files

0.4.0

2 release files

0.3.0

1 release file

0.2.0

0.1.0

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page