summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-08-04 21:45:24 +1000
committerDamien George <damien.p.george@gmail.com>2018-08-04 21:45:24 +1000
commit4b1e8bdebdf5feb48a51dbf1e584735395069384 (patch)
treede290ad6014ebaedbcf3e589ef94cc448868b0f5
parent163bacd1e80363117d24be05043ca595a3d4c9cf (diff)
py/emitnative: Factor common code for native jump helper.
-rw-r--r--py/emitnative.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/py/emitnative.c b/py/emitnative.c
index 3bc637ac6..00d322d75 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -1520,7 +1520,7 @@ STATIC void emit_native_jump(emit_t *emit, mp_uint_t label) {
emit_post(emit);
}
-STATIC void emit_native_jump_helper(emit_t *emit, bool pop) {
+STATIC void emit_native_jump_helper(emit_t *emit, bool cond, mp_uint_t label, bool pop) {
vtype_kind_t vtype = peek_vtype(emit, 0);
if (vtype == VTYPE_PYOBJ) {
emit_pre_pop_reg(emit, &vtype, REG_ARG_1);
@@ -1545,29 +1545,26 @@ STATIC void emit_native_jump_helper(emit_t *emit, bool pop) {
}
// need to commit stack because we may jump elsewhere
need_stack_settled(emit);
-}
-
-STATIC void emit_native_pop_jump_if(emit_t *emit, bool cond, mp_uint_t label) {
- DEBUG_printf("pop_jump_if(cond=%u, label=" UINT_FMT ")\n", cond, label);
- emit_native_jump_helper(emit, true);
+ // Emit the jump
if (cond) {
ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label);
} else {
ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label);
}
+ if (!pop) {
+ adjust_stack(emit, -1);
+ }
emit_post(emit);
}
+STATIC void emit_native_pop_jump_if(emit_t *emit, bool cond, mp_uint_t label) {
+ DEBUG_printf("pop_jump_if(cond=%u, label=" UINT_FMT ")\n", cond, label);
+ emit_native_jump_helper(emit, cond, label, true);
+}
+
STATIC void emit_native_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label) {
DEBUG_printf("jump_if_or_pop(cond=%u, label=" UINT_FMT ")\n", cond, label);
- emit_native_jump_helper(emit, false);
- if (cond) {
- ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label);
- } else {
- ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label);
- }
- adjust_stack(emit, -1);
- emit_post(emit);
+ emit_native_jump_helper(emit, cond, label, false);
}
STATIC void emit_native_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) {