Api

Instead of using the commandline, it is also possible to use ppci api. For example to assemble, compile, link and objcopy the msp430 blinky example project:

>>> from ppci.api import asm, c3c, link, objcopy
>>> march = "msp430"
>>> o1 = asm('examples/msp430/blinky/boot.asm', march)
>>> o2 = c3c(['examples/msp430/blinky/blinky.c3'], [], march)
>>> o3 = link([o2, o1], 'examples/msp430/blinky/msp430.mmap', march)
>>> objcopy(o3, 'flash', 'hex', 'blinky_msp430.hex')

api module

This module contains a set of handy functions to invoke compilation, linking and assembling.

ppci.api.asm(source, march)

Assemble the given source for machine march.

source can be a filename or a file like object. march can be a machine instance or a string indicating the target.

For example:

>>> import io
>>> from ppci.api import asm
>>> source_file = io.StringIO("db 0x77")
>>> obj = asm(source_file, 'arm')
>>> print(obj)
CodeObject of 1 bytes
ppci.api.c3c(sources, includes, march, reporter=None, debug=False)

Compile a set of sources into binary format for the given target.

For example:

>>> import io
>>> from ppci.api import c3c
>>> source_file = io.StringIO("module main; var int a;")
>>> obj = c3c([source_file], [], 'arm')
>>> print(obj)
CodeObject of 4 bytes

Links the iterable of objects into one using the given layout.

ppci.api.objcopy(obj, image_name, fmt, output_filename)

Copy some parts of an object file to an output

ppci.api.bfcompile(source, target, reporter=None)

Compile brainfuck source into binary format for the given target

source can be a filename or a file like object. march can be a machine instance or a string indicating the target.

For example:

>>> import io
>>> from ppci.api import bfcompile
>>> source_file = io.StringIO(">>[-]<<[->>+<<]")
>>> obj = bfcompile(source_file, 'arm')
ppci.api.construct(buildfile, targets=())

Construct the given buildfile. Raise task error if something goes wrong.

ppci.api.optimize(ir_module, reporter=None, debug_db=None)

Run a bag of tricks against the ir-code. This is an in-place operation!

ppci.api.get_arch(arch)

Try to return an architecture instance. arch can be a string in the form of arch:option1:option2