diff options
| author | Damien George <damien.p.george@gmail.com> | 2018-05-22 22:33:26 +1000 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2018-05-23 00:35:16 +1000 |
| commit | 18e6358480e640fd94a9383d5fa7d9b8cc2b9f73 (patch) | |
| tree | 8fa4f37c9d5d072f8486b674b5038922d1cb25c0 /py/emitnative.c | |
| parent | 436e0d4c54ab22050072d392f0822e555bcc70f1 (diff) | |
py/emit: Combine setup with/except/finally into one emit function.
This patch reduces code size by:
bare-arm: -16
minimal x86: -156
unix x64: -288
unix nanbox: -184
stm32: -48
cc3200: -16
esp8266: -96
esp32: -16
The last 10 patches combined reduce code size by:
bare-arm: -164
minimal x86: -1260
unix x64: -3416
unix nanbox: -1616
stm32: -676
cc3200: -232
esp8266: -1144
esp32: -268
Diffstat (limited to 'py/emitnative.c')
| -rw-r--r-- | py/emitnative.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/py/emitnative.c b/py/emitnative.c index 331e4cf18..ad8f04aac 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -1617,6 +1617,21 @@ STATIC void emit_native_setup_with(emit_t *emit, mp_uint_t label) { // stack: (..., __exit__, self, as_value, nlr_buf, as_value) } +STATIC void emit_native_setup_block(emit_t *emit, mp_uint_t label, int kind) { + if (kind == MP_EMIT_SETUP_BLOCK_WITH) { + emit_native_setup_with(emit, label); + } else { + // Set up except and finally + emit_native_pre(emit); + // need to commit stack because we may jump elsewhere + need_stack_settled(emit); + emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_1, sizeof(nlr_buf_t) / sizeof(mp_uint_t)); // arg1 = pointer to nlr buf + emit_call(emit, MP_F_NLR_PUSH); + ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label); + emit_post(emit); + } +} + STATIC void emit_native_with_cleanup(emit_t *emit, mp_uint_t label) { // note: label+1 is available as an auxiliary label @@ -1686,20 +1701,6 @@ STATIC void emit_native_with_cleanup(emit_t *emit, mp_uint_t label) { emit_native_label_assign(emit, label + 1); } -STATIC void emit_native_setup_except(emit_t *emit, mp_uint_t label) { - emit_native_pre(emit); - // need to commit stack because we may jump elsewhere - need_stack_settled(emit); - emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_1, sizeof(nlr_buf_t) / sizeof(mp_uint_t)); // arg1 = pointer to nlr buf - emit_call(emit, MP_F_NLR_PUSH); - ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label); - emit_post(emit); -} - -STATIC void emit_native_setup_finally(emit_t *emit, mp_uint_t label) { - emit_native_setup_except(emit, label); -} - STATIC void emit_native_end_finally(emit_t *emit) { // logic: // exc = pop_stack @@ -2254,10 +2255,8 @@ const emit_method_table_t EXPORT_FUN(method_table) = { emit_native_pop_jump_if, emit_native_jump_if_or_pop, emit_native_unwind_jump, - emit_native_setup_with, + emit_native_setup_block, emit_native_with_cleanup, - emit_native_setup_except, - emit_native_setup_finally, emit_native_end_finally, emit_native_get_iter, emit_native_for_iter, |
