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.
bf2ir
(source, target)¶ Compile brainfuck source into ir code
-
ppci.api.
bfcompile
(source, target, reporter=<ppci.utils.reporting.DummyReportGenerator object>)¶ Compile brainfuck source into binary format for the given target
-
ppci.api.
c3c
(sources, includes, march, reporter=<ppci.utils.reporting.DummyReportGenerator object>)¶ 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
-
ppci.api.
c3toir
(sources, includes, target, reporter=<ppci.utils.reporting.DummyReportGenerator object>)¶ Compile c3 sources to ir code using the includes and for the given target
-
ppci.api.
construct
(buildfile, targets=())¶ Construct the given buildfile. Raise task error if something goes wrong.
-
ppci.api.
fix_file
(f)¶ Determine if argument is a file like object or make it so!
-
ppci.api.
fix_object
(obj)¶ Try hard to load an object
-
ppci.api.
fix_target
(target_name)¶ Try to return an instance of the Target class. target_name can be in the form of arch:option1:option2
-
ppci.api.
fortran_to_ir
(source)¶ Translate fortran source into IR-code
-
ppci.api.
fortrancompile
(sources, target, reporter=<ppci.utils.reporting.DummyReportGenerator object>)¶ Compile fortran code to target
-
ppci.api.
ir_to_object
(ir_modules, march, reporter=<ppci.utils.reporting.DummyReportGenerator object>)¶ Translate the given list of IR-modules into object code for the given target
-
ppci.api.
ir_to_python
(ir_modules, f, reporter=<ppci.utils.reporting.DummyReportGenerator object>)¶ Convert ir-code to python code
-
ppci.api.
link
(objects, layout, march, use_runtime=False, partial_link=False, reporter=<ppci.utils.reporting.DummyReportGenerator object>)¶ 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.
optimize
(ir_module, reporter=<ppci.utils.reporting.DummyReportGenerator object>)¶ Run a bag of tricks against the ir-code. This is an in-place operation!