Skip to main content

A compiler for ARM, X86, MSP430, xtensa and more implemented in pure Python

Project description

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 the following:

  • A compiler, an assembler, a linker and a build system

  • Language front-ends: Brainfuck, C, c3, WebAssembly

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

  • Other backends: WebAssembly, Python

You can try out PPCI at, a site which offers Web access to various compilers:


API example to compile c3 code:

>>> import io
>>> from ppci.api import c3c, link
>>> source_file = io.StringIO("""
... module main;
... function void print(string txt) {
... }
... function void main() {
...  print("Hello world");
... }""")
>>> obj = c3c([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

Example of the low level api usage:

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


Documentation can be found here:

gitter appveyor codecov docstate travis codacygrade codacycoverage downloads conda

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

ppci-0.5.7.tar.gz (520.2 kB view hashes)

Uploaded Source

Built Distribution

ppci-0.5.7-py3-none-any.whl (606.7 kB view hashes)

Uploaded Python 3

Supported by

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