API

API

Instead of using the commandline, it is also possible to use the build functions of ppci via the buildfunctions.

For example to assemble, compile, link and objcopy, code could look like:

1
2
3
4
5
6
7
 from ppci.buildfunctions import assemble, c3compile, link, objcopy

 march = "thumb"
 o1 = assemble('start.asm', march)
 o2 = c3compile(['source_code.c3'], [], march)
 o3 = link([o2, o1], 'mem.ld', march)
 objcopy(o3, 'code', 'bin', 'output.bin')

buildfunctions module

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

ppci.buildfunctions.assemble(source, target)

Invoke the assembler on the given source, returns an object containing the output.

ppci.buildfunctions.bf2ir(source, target)

Compile brainfuck source into ir code

ppci.buildfunctions.bfcompile(source, target, reporter=<ppci.reporting.DummyReportGenerator object>)

Compile brainfuck source into binary format for the given target

ppci.buildfunctions.c3compile(sources, includes, target, reporter=<ppci.reporting.DummyReportGenerator object>)

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

ppci.buildfunctions.c3toir(sources, includes, target, reporter=<ppci.reporting.DummyReportGenerator object>)

Compile c3 sources to ir code using the includes and for the given target

ppci.buildfunctions.construct(buildfile, targets=())

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

ppci.buildfunctions.fix_file(f)

Determine if argument is a file like object or make it so!

ppci.buildfunctions.fix_object(o)

Try hard to load an object

ppci.buildfunctions.fix_target(tg)

Try to return an instance of the Target class

ppci.buildfunctions.get_compiler_rt_lib(target)

Gets the runtime for the compiler. Returns an object with the compiler runtime for the given target

ppci.buildfunctions.ir_to_object(ir_modules, target, reporter=<ppci.reporting.DummyReportGenerator object>)

Translate the given list of IR-modules into object code for the given target

ppci.buildfunctions.ir_to_python(ir_modules, f, reporter=<ppci.reporting.DummyReportGenerator object>)

Convert ir-code to python code

Links the iterable of objects into one using the given layout

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

Copy some parts of an object file to an output

ppci.buildfunctions.optimize(ir_module, reporter=<ppci.reporting.DummyReportGenerator object>)

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