summaryrefslogtreecommitdiff
path: root/py/asmbase.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/asmbase.c')
-rw-r--r--py/asmbase.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/py/asmbase.c b/py/asmbase.c
index 4a3fd089c..da4273506 100644
--- a/py/asmbase.c
+++ b/py/asmbase.c
@@ -55,15 +55,20 @@ void mp_asm_base_start_pass(mp_asm_base_t *as, int pass) {
assert(as->code_base != NULL);
}
as->pass = pass;
+ as->suppress = false;
as->code_offset = 0;
}
// all functions must go through this one to emit bytes
// if as->pass < MP_ASM_PASS_EMIT, then this function just counts the number
// of bytes needed and returns NULL, and callers should not store any data
+// It also returns NULL if generated code should be suppressed at this point.
uint8_t *mp_asm_base_get_cur_to_write_bytes(void *as_in, size_t num_bytes_to_write) {
mp_asm_base_t *as = as_in;
uint8_t *c = NULL;
+ if (as->suppress) {
+ return c;
+ }
if (as->pass == MP_ASM_PASS_EMIT) {
assert(as->code_offset + num_bytes_to_write <= as->code_size);
c = as->code_base + as->code_offset;
@@ -74,6 +79,11 @@ uint8_t *mp_asm_base_get_cur_to_write_bytes(void *as_in, size_t num_bytes_to_wri
void mp_asm_base_label_assign(mp_asm_base_t *as, size_t label) {
assert(label < as->max_num_labels);
+
+ // Assiging a label ends any dead-code region, and all following machine
+ // code should be emitted (until another mp_asm_base_suppress_code() call).
+ as->suppress = false;
+
if (as->pass < MP_ASM_PASS_EMIT) {
// assign label offset
assert(as->label_offsets[label] == (size_t)-1);