Mercurial > lcfOS
comparison 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 |
comparison
equal
deleted
inserted
replaced
382:0c44e494ef58 | 383:173e20a47fda |
---|---|
10 from .c3 import Builder | 10 from .c3 import Builder |
11 from .irutils import Verifier | 11 from .irutils import Verifier |
12 from .codegen import CodeGenerator | 12 from .codegen import CodeGenerator |
13 from .transform import CleanPass, RemoveAddZero | 13 from .transform import CleanPass, RemoveAddZero |
14 from .linker import Linker | 14 from .linker import Linker |
15 from .layout import Layout, load_layout | |
15 from .target.target_list import targets | 16 from .target.target_list import targets |
16 from .outstream import BinaryAndLoggingStream | 17 from .outstream import BinaryAndLoggingStream |
17 from .objectfile import ObjectFile, load_object | 18 from .objectfile import ObjectFile, load_object |
18 from . import DiagnosticsManager, CompilerError | 19 from . import DiagnosticsManager, CompilerError |
19 | 20 from .tasks import TaskError |
20 | 21 |
21 def fix_target(tg): | 22 def fix_target(tg): |
22 """ Try to return an instance of the Target class """ | 23 """ Try to return an instance of the Target class """ |
23 if isinstance(tg, Target): | 24 if isinstance(tg, Target): |
24 return tg | 25 return tg |
45 elif isinstance(o, str): | 46 elif isinstance(o, str): |
46 with open(o, 'r') as f: | 47 with open(o, 'r') as f: |
47 return load_object(f) | 48 return load_object(f) |
48 else: | 49 else: |
49 raise TaskError('Cannot use {} as objectfile'.format(o)) | 50 raise TaskError('Cannot use {} as objectfile'.format(o)) |
51 | |
52 | |
53 def fix_layout(l): | |
54 if isinstance(l, Layout): | |
55 return l | |
56 elif hasattr(l, 'read'): | |
57 # Assume file handle | |
58 return load_layout(l) | |
59 elif isinstance(l, str): | |
60 with open(l, 'r') as f: | |
61 return load_layout(f) | |
62 else: | |
63 raise TaskError('Cannot use {} as layout'.format(l)) | |
50 | 64 |
51 | 65 |
52 def assemble(source, target): | 66 def assemble(source, target): |
53 """ Invoke the assembler on the given source, returns an object containing | 67 """ Invoke the assembler on the given source, returns an object containing |
54 the output. """ | 68 the output. """ |
109 | 123 |
110 | 124 |
111 def link(objects, layout): | 125 def link(objects, layout): |
112 """ Links the iterable of objects into one using the given layout """ | 126 """ Links the iterable of objects into one using the given layout """ |
113 objects = list(map(fix_object, objects)) | 127 objects = list(map(fix_object, objects)) |
128 layout = fix_layout(layout) | |
114 linker = Linker() | 129 linker = Linker() |
115 output_obj = linker.link(objects, layout) | 130 output_obj = linker.link(objects, layout) |
116 return output_obj | 131 return output_obj |
117 | 132 |
118 | 133 |