Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
b6a32895
Commit
b6a32895
authored
Aug 12, 2017
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools/mpy-tool.py: Don't generate const_table if it's empty.
parent
bfc2092d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
22 deletions
+27
-22
tools/mpy-tool.py
tools/mpy-tool.py
+27
-22
No files found.
tools/mpy-tool.py
View file @
b6a32895
...
...
@@ -331,27 +331,29 @@ class RawCode:
# TODO
raise
FreezeError
(
self
,
'freezing of object %r is not implemented'
%
(
obj
,))
# generate constant table
print
(
'STATIC const mp_rom_obj_t const_table_data_%s[%u] = {'
%
(
self
.
escaped_name
,
len
(
self
.
qstrs
)
+
len
(
self
.
objs
)
+
len
(
self
.
raw_codes
)))
for
qst
in
self
.
qstrs
:
print
(
' MP_ROM_QSTR(%s),'
%
global_qstrs
[
qst
].
qstr_id
)
for
i
in
range
(
len
(
self
.
objs
)):
if
type
(
self
.
objs
[
i
])
is
float
:
print
(
'#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B'
)
print
(
' MP_ROM_PTR(&const_obj_%s_%u),'
%
(
self
.
escaped_name
,
i
))
print
(
'#elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C'
)
n
=
struct
.
unpack
(
'<I'
,
struct
.
pack
(
'<f'
,
self
.
objs
[
i
]))[
0
]
n
=
((
n
&
~
0x3
)
|
2
)
+
0x80800000
print
(
' (mp_rom_obj_t)(0x%08x),'
%
(
n
,))
print
(
'#else'
)
print
(
'#error "MICROPY_OBJ_REPR_D not supported with floats in frozen mpy files"'
)
print
(
'#endif'
)
else
:
print
(
' MP_ROM_PTR(&const_obj_%s_%u),'
%
(
self
.
escaped_name
,
i
))
for
rc
in
self
.
raw_codes
:
print
(
' MP_ROM_PTR(&raw_code_%s),'
%
rc
.
escaped_name
)
print
(
'};'
)
# generate constant table, if it has any entries
const_table_len
=
len
(
self
.
qstrs
)
+
len
(
self
.
objs
)
+
len
(
self
.
raw_codes
)
if
const_table_len
:
print
(
'STATIC const mp_rom_obj_t const_table_data_%s[%u] = {'
%
(
self
.
escaped_name
,
const_table_len
))
for
qst
in
self
.
qstrs
:
print
(
' MP_ROM_QSTR(%s),'
%
global_qstrs
[
qst
].
qstr_id
)
for
i
in
range
(
len
(
self
.
objs
)):
if
type
(
self
.
objs
[
i
])
is
float
:
print
(
'#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B'
)
print
(
' MP_ROM_PTR(&const_obj_%s_%u),'
%
(
self
.
escaped_name
,
i
))
print
(
'#elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C'
)
n
=
struct
.
unpack
(
'<I'
,
struct
.
pack
(
'<f'
,
self
.
objs
[
i
]))[
0
]
n
=
((
n
&
~
0x3
)
|
2
)
+
0x80800000
print
(
' (mp_rom_obj_t)(0x%08x),'
%
(
n
,))
print
(
'#else'
)
print
(
'#error "MICROPY_OBJ_REPR_D not supported with floats in frozen mpy files"'
)
print
(
'#endif'
)
else
:
print
(
' MP_ROM_PTR(&const_obj_%s_%u),'
%
(
self
.
escaped_name
,
i
))
for
rc
in
self
.
raw_codes
:
print
(
' MP_ROM_PTR(&raw_code_%s),'
%
rc
.
escaped_name
)
print
(
'};'
)
# generate module
if
self
.
simple_name
.
str
!=
'<module>'
:
...
...
@@ -362,7 +364,10 @@ class RawCode:
print
(
' .n_pos_args = %u,'
%
self
.
prelude
[
3
])
print
(
' .data.u_byte = {'
)
print
(
' .bytecode = bytecode_data_%s,'
%
self
.
escaped_name
)
print
(
' .const_table = (mp_uint_t*)const_table_data_%s,'
%
self
.
escaped_name
)
if
const_table_len
:
print
(
' .const_table = (mp_uint_t*)const_table_data_%s,'
%
self
.
escaped_name
)
else
:
print
(
' .const_table = NULL,'
)
print
(
' #if MICROPY_PERSISTENT_CODE_SAVE'
)
print
(
' .bc_len = %u,'
%
len
(
self
.
bytecode
))
print
(
' .n_obj = %u,'
%
len
(
self
.
objs
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment