summaryrefslogtreecommitdiff
path: root/py/emitglue.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-02-21 15:18:33 +1100
committerDamien George <damien.p.george@gmail.com>2019-03-08 15:53:05 +1100
commit1396a026be78bc90ea18961ba6760f851b691b4c (patch)
tree4135ac73bcd2de56362d24895f8aec309666fce7 /py/emitglue.c
parent636ed0ff8d4d3c43f7d9fb2d8852073f99c1e6cf (diff)
py: Add support to save native, viper and asm code to .mpy files.
This commit adds support for saving and loading .mpy files that contain native code (native, viper and inline-asm). A lot of the ground work was already done for this in the form of removing pointers from generated native code. The changes here are mainly to link in qstr values to the native code, and change the format of .mpy files to contain native code blocks (possibly mixed with bytecode). A top-level summary: - @micropython.native, @micropython.viper and @micropython.asm_thumb/ asm_xtensa are now allowed in .py files when compiling to .mpy, and they work transparently to the user. - Entire .py files can be compiled to native via mpy-cross -X emit=native and for the most part the generated .mpy files should work the same as their bytecode version. - The .mpy file format is changed to 1) specify in the header if the file contains native code and if so the architecture (eg x86, ARMV7M, Xtensa); 2) for each function block the kind of code is specified (bytecode, native, viper, asm). - When native code is loaded from a .mpy file the native code must be modified (in place) to link qstr values in, just like bytecode (see py/persistentcode.c:arch_link_qstr() function). In addition, this now defines a public, native ABI for dynamically loadable native code generated by other languages, like C.
Diffstat (limited to 'py/emitglue.c')
-rw-r--r--py/emitglue.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/py/emitglue.c b/py/emitglue.c
index 996b79e17..c073258f0 100644
--- a/py/emitglue.c
+++ b/py/emitglue.c
@@ -89,8 +89,16 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code,
}
#if MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM
-void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void *fun_data, mp_uint_t fun_len, const mp_uint_t *const_table, mp_uint_t n_pos_args, mp_uint_t scope_flags, mp_uint_t type_sig) {
+void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void *fun_data, mp_uint_t fun_len, const mp_uint_t *const_table,
+ #if MICROPY_PERSISTENT_CODE_SAVE
+ uint16_t prelude_offset,
+ uint16_t n_obj, uint16_t n_raw_code,
+ uint16_t n_qstr, mp_qstr_link_entry_t *qstr_link,
+ #endif
+ mp_uint_t n_pos_args, mp_uint_t scope_flags, mp_uint_t type_sig) {
+
assert(kind == MP_CODE_NATIVE_PY || kind == MP_CODE_NATIVE_VIPER || kind == MP_CODE_NATIVE_ASM);
+
rc->kind = kind;
rc->scope_flags = scope_flags;
rc->n_pos_args = n_pos_args;
@@ -98,6 +106,15 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void
rc->const_table = const_table;
rc->type_sig = type_sig;
+ #if MICROPY_PERSISTENT_CODE_SAVE
+ rc->fun_data_len = fun_len;
+ rc->prelude_offset = prelude_offset;
+ rc->n_obj = n_obj;
+ rc->n_raw_code = n_raw_code;
+ rc->n_qstr= n_qstr;
+ rc->qstr_link = qstr_link;
+ #endif
+
#ifdef DEBUG_PRINT
DEBUG_printf("assign native: kind=%d fun=%p len=" UINT_FMT " n_pos_args=" UINT_FMT " flags=%x\n", kind, fun_data, fun_len, n_pos_args, (uint)scope_flags);
for (mp_uint_t i = 0; i < fun_len; i++) {