Mercurial > lcfOS
diff python/ppci/buildfunctions.py @ 383:173e20a47fda
Added linker description loader
author | Windel Bouwman |
---|---|
date | Sun, 27 Apr 2014 17:40:39 +0200 |
parents | 6df89163e114 |
children | d056b552d3f4 |
line wrap: on
line diff
--- a/python/ppci/buildfunctions.py Sun Apr 27 12:24:21 2014 +0200 +++ b/python/ppci/buildfunctions.py Sun Apr 27 17:40:39 2014 +0200 @@ -12,11 +12,12 @@ from .codegen import CodeGenerator from .transform import CleanPass, RemoveAddZero from .linker import Linker +from .layout import Layout, load_layout from .target.target_list import targets from .outstream import BinaryAndLoggingStream from .objectfile import ObjectFile, load_object from . import DiagnosticsManager, CompilerError - +from .tasks import TaskError def fix_target(tg): """ Try to return an instance of the Target class """ @@ -49,6 +50,19 @@ raise TaskError('Cannot use {} as objectfile'.format(o)) +def fix_layout(l): + if isinstance(l, Layout): + return l + elif hasattr(l, 'read'): + # Assume file handle + return load_layout(l) + elif isinstance(l, str): + with open(l, 'r') as f: + return load_layout(f) + else: + raise TaskError('Cannot use {} as layout'.format(l)) + + def assemble(source, target): """ Invoke the assembler on the given source, returns an object containing the output. """ @@ -111,6 +125,7 @@ def link(objects, layout): """ Links the iterable of objects into one using the given layout """ objects = list(map(fix_object, objects)) + layout = fix_layout(layout) linker = Linker() output_obj = linker.link(objects, layout) return output_obj