The ppci (pure python compiler infrastructure) project is a compiler written entirely in python. It contains language front-ends as well as machine code generation functionality. With this library you can generate (working!) machine code within python!
The project contains the following:
A Compiler, an assembler, a linker and a build system
Language front-ends: Brainfuck, c3, C, WASM
Backends: 6500, arm, avr, msp430, openrisc, risc-v, stm8, x86_64, xtensa
You can try out ppci at godbolt.org: 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.6
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.6.tar.gz | 452.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ppci-0.5.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.1 MB
Release files / ppci-0.5.6.tar.gz
| Download URL | ppci-0.5.6.tar.gz |
|---|---|
| Size | 452.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d64c169529e039a7968a95c4dfc25cd7768e6629b8dc576df5e291c9f942660e
|
|
BLAKE2b-256 checksum How to use checksums |
b614d3d5d8cb4b66459d5dbf6476fbe506318f08cb01a20295e886ecec573f09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.7
|
Release files / ppci-0.5.6-py3-none-any.whl
| Download URL | ppci-0.5.6-py3-none-any.whl |
|---|---|
| Size | 641.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
56919798cba8d010d020724d6b1a05393f2209e3ecd11585141ca94103701d93
|
|
BLAKE2b-256 checksum How to use checksums |
4aab5a83de86c51346662223f10879709d5ee988b5a9301f98f45b358a1e64a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.7
|