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 godbolt.org, a site which offers Web access to various compilers: https://godbolt.org/g/eooaPP
API
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
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'['
Documentation
Documentation can be found here:
Metadata
Release files for ppci 0.5.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ppci-0.5.7.tar.gz | 520.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ppci-0.5.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.1 MB
Release files / ppci-0.5.7.tar.gz
| Download URL | ppci-0.5.7.tar.gz |
|---|---|
| Size | 520.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ef9dc403c2a3cc1b55e3174e730726f9d04b029287ff110a8417c5d2487f1d13
|
|
BLAKE2b-256 checksum How to use checksums |
458b13656dfc264f8acd91bccd7a8e35edb9e92183beb32b9e4d7b250a5f635d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.8
|
Release files / ppci-0.5.7-py3-none-any.whl
| Download URL | ppci-0.5.7-py3-none-any.whl |
|---|---|
| Size | 606.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6e598e348b4aeb6e6715ed53b82cb629334808726d59a8a2c3526b9e0790dbe
|
|
BLAKE2b-256 checksum How to use checksums |
0f1e70e5c95322b1ce448898ee5ca094457ac5ae176c8460606366fb93609648
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.8
|