All Projects → windelbouwman → Ppci

windelbouwman / Ppci

Licence: bsd-2-clause
A compiler for ARM, X86, MSP430, xtensa and more implemented in pure Python

Programming Languages

python
139335 projects - #7 most used programming language
assembler
53 projects

Projects that are alternatives of or similar to Ppci

Capstone
Capstone disassembly/disassembler framework: Core (Arm, Arm64, BPF, EVM, M68K, M680X, MOS65xx, Mips, PPC, RISCV, Sparc, SystemZ, TMS320C64x, Web Assembly, X86, X86_64, XCore) + bindings.
Stars: ✭ 5,374 (+2459.05%)
Mutual labels:  arm, x86-64, riscv, webassembly
Shecc
A self-hosting and educational C compiler
Stars: ✭ 286 (+36.19%)
Mutual labels:  compiler, arm, riscv
Tengine
Tengine is a lite, high performance, modular inference engine for embedded device
Stars: ✭ 4,012 (+1810.48%)
Mutual labels:  arm, x86-64, riscv
Wag
WebAssembly compiler implemented in Go
Stars: ✭ 177 (-15.71%)
Mutual labels:  compiler, x86-64, webassembly
Lbforth
Self-hosting metacompiled Forth, bootstrapping from a few lines of C; targets Linux, Windows, ARM, RISC-V, 68000, PDP-11, asm.js.
Stars: ✭ 293 (+39.52%)
Mutual labels:  compiler, arm, riscv
interp
Interpreter experiment. Testing dispatch methods: Switching, Direct/Indirect Threaded Code, Tail-Calls and Inlining
Stars: ✭ 32 (-84.76%)
Mutual labels:  arm, x86-64, riscv
Unicorn
Unicorn CPU emulator framework (ARM, AArch64, M68K, Mips, Sparc, PowerPC, RiscV, X86)
Stars: ✭ 4,934 (+2249.52%)
Mutual labels:  arm, x86-64, riscv
Dynarmic
An ARM dynamic recompiler.
Stars: ✭ 475 (+126.19%)
Mutual labels:  compiler, arm, x86-64
Asterius
A Haskell to WebAssembly compiler
Stars: ✭ 1,799 (+756.67%)
Mutual labels:  compiler, webassembly
Rcore
Rust version of THU uCore OS. Linux compatible.
Stars: ✭ 2,175 (+935.71%)
Mutual labels:  x86-64, riscv
Naskah
Bahasa pemrograman dengan sintaks Bahasa Indonesia (Programming language with Indonesian syntax) 🇮🇩
Stars: ✭ 132 (-37.14%)
Mutual labels:  compiler, webassembly
Tina
Tina is a teeny tiny, header only, coroutine and job library.
Stars: ✭ 125 (-40.48%)
Mutual labels:  arm, x86-64
Docker Homebridge
Homebridge Docker. HomeKit support for the impatient using Docker on x86_64, Raspberry Pi (armhf) and ARM64. Includes ffmpeg + libfdk-aac.
Stars: ✭ 1,847 (+779.52%)
Mutual labels:  arm, x86-64
Grain
The Grain compiler toolchain and CLI. Home of the modern web staple. 🌾
Stars: ✭ 2,199 (+947.14%)
Mutual labels:  compiler, webassembly
Peachpy
x86-64 assembler embedded in Python
Stars: ✭ 1,592 (+658.1%)
Mutual labels:  compiler, x86-64
Docker Unms
This image is no longer maintained: https://github.com/oznu/docker-unms/issues/53
Stars: ✭ 145 (-30.95%)
Mutual labels:  arm, x86-64
Assemblyscript
A TypeScript-like language for WebAssembly.
Stars: ✭ 13,152 (+6162.86%)
Mutual labels:  compiler, webassembly
Keystone
Keystone assembler framework: Core (Arm, Arm64, Hexagon, Mips, PowerPC, Sparc, SystemZ & X86) + bindings
Stars: ✭ 1,654 (+687.62%)
Mutual labels:  arm, x86-64
Babygo
Go compiler made from scratch, which can compile itself. It's going to be the smallest and simplest go compiler in the world.
Stars: ✭ 143 (-31.9%)
Mutual labels:  compiler, x86-64
Wah
a slightly higher-level language superset of webassembly
Stars: ✭ 147 (-30%)
Mutual labels:  compiler, webassembly

Introduction

The PPCI (Pure Python Compiler Infrastructure) project is a compiler written entirely in the Python <https://www.python.org/>_ 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:

.. code:: bash

$ pip install ppci

Usage

An example of commandline usage:

.. code:: bash

$ 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:

.. code-block:: python

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

.. code-block:: python

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

.. code-block:: python

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

Functionality

  • Command line utilities <https://ppci.readthedocs.io/en/latest/reference/cli.html>_:
    • ppci-cc <https://ppci.readthedocs.io/en/latest/reference/cli.html#ppci-cc>_
    • ppci-ld <https://ppci.readthedocs.io/en/latest/reference/cli.html#ppci-ld>_
    • and many more.
  • Can be used with tools like make or other build tools.
  • Language support <https://ppci.readthedocs.io/en/latest/reference/lang/index.html>_:
    • C <https://ppci.readthedocs.io/en/latest/reference/lang/c.html>_
    • Pascal
    • Python
    • Basic
    • Brainfuck
    • C3 <https://ppci.readthedocs.io/en/latest/reference/lang/c3.html>_ (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 <https://ppci.readthedocs.io/en/latest/reference/wasm.html>_
    • JVM
    • OCaml bytecode
    • LLVM IR
    • DWARF debugging format
  • File formats <https://ppci.readthedocs.io/en/latest/reference/format/index.html>_:
    • 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:

.. warning::

**This project is in alpha state and not ready for production use!**

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|_

.. |codecov| image:: https://codecov.io/bb/windel/ppci/branch/default/graph/badge.svg .. _codecov: https://codecov.io/bb/windel/ppci/branch/default

.. |appveyor| image:: https://ci.appveyor.com/api/projects/status/h0h5huliflrac65o?svg=true .. _appveyor: https://ci.appveyor.com/project/WindelBouwman/ppci-786

.. |docstate| image:: https://readthedocs.org/projects/ppci/badge/?version=latest .. _docstate: https://ppci.readthedocs.io/en/latest

.. |travis| image:: https://travis-ci.org/windelbouwman/ppci.svg?branch=master .. _travis: https://travis-ci.org/windelbouwman/ppci

.. |codacygrade| image:: https://api.codacy.com/project/badge/Grade/a178be14a54243be81c27172031dc82c .. _codacygrade: https://www.codacy.com/app/windel-bouwman/ppci-mirror

.. |codacycoverage| image:: https://api.codacy.com/project/badge/Coverage/a178be14a54243be81c27172031dc82c .. _codacycoverage: https://www.codacy.com/app/windel-bouwman/ppci-mirror

.. |downloads| image:: https://anaconda.org/conda-forge/ppci/badges/downloads.svg .. _downloads: https://anaconda.org/conda-forge/ppci

.. |conda| image:: https://anaconda.org/conda-forge/ppci/badges/version.svg .. _conda: https://anaconda.org/conda-forge/ppci

.. |gitter| image:: https://badges.gitter.im/ppci-chat/Lobby.svg .. _gitter: https://gitter.im/ppci-chat/Lobby

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].