- Notifications
You must be signed in to change notification settings - Fork 25
/
Copy path__init__.py
43 lines (32 loc) · 1.21 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#
# This file is part of the micropython-esp32-ulp project,
# https://github.com/micropython/micropython-esp32-ulp
#
# SPDX-FileCopyrightText: 2018-2023, the micropython-esp32-ulp authors, see AUTHORS file.
# SPDX-License-Identifier: MIT
from .utilimportgarbage_collect
from .preprocessimportpreprocess
from .assembleimportAssembler
from .linkimportmake_binary
garbage_collect('after import')
defsrc_to_binary_ext(src, cpu):
assembler=Assembler(cpu)
src=preprocess(src)
assembler.assemble(src, remove_comments=False) # comments already removed by preprocessor
garbage_collect('before symbols export')
addrs_syms=assembler.symbols.export()
text, data, bss_len=assembler.fetch()
returnmake_binary(text, data, bss_len), addrs_syms
defsrc_to_binary(src, cpu):
binary, addrs_syms=src_to_binary_ext(src, cpu)
foraddr, syminaddrs_syms:
print('%04d %s'% (addr, sym))
returnbinary
defassemble_file(filename, cpu):
withopen(filename) asf:
src=f.read()
binary=src_to_binary(src, cpu)
iffilename.endswith('.s') orfilename.endswith('.S'):
filename=filename[:-2]
withopen(filename+'.ulp', 'wb') asf:
f.write(binary)