summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-01-14 00:38:33 +0000
committerDamien George <damien.p.george@gmail.com>2015-01-14 00:38:33 +0000
commitd9dc6fff211db1fb5947ec2003a1f650a8b80c4c (patch)
tree28a51a26ea33cdd5581554195c03fb4c7658fa8c
parentbc47c287dfe15909de6b76f19b8b0968ba54724a (diff)
downloadmicropython-d9dc6fff211db1fb5947ec2003a1f650a8b80c4c.tar.gz
micropython-d9dc6fff211db1fb5947ec2003a1f650a8b80c4c.zip
py: Allocate memory for assembled code at start of PASS_EMIT.
Previously was allocating at end of PASS_COMPUTE, and this pass was being run twice, so memory was being allocated twice.
-rw-r--r--py/asmarm.c16
-rw-r--r--py/asmthumb.c27
-rw-r--r--py/asmx64.c27
-rw-r--r--py/asmx86.c15
4 files changed, 31 insertions, 54 deletions
diff --git a/py/asmarm.c b/py/asmarm.c
index 0ca88fd97c..cf90d60c7b 100644
--- a/py/asmarm.c
+++ b/py/asmarm.c
@@ -70,20 +70,20 @@ void asm_arm_free(asm_arm_t *as, bool free_code) {
}
void asm_arm_start_pass(asm_arm_t *as, uint pass) {
- as->pass = pass;
- as->code_offset = 0;
if (pass == ASM_ARM_PASS_COMPUTE) {
memset(as->label_offsets, -1, as->max_num_labels * sizeof(mp_uint_t));
+ } else if (pass == ASM_ARM_PASS_EMIT) {
+ MP_PLAT_ALLOC_EXEC(as->code_offset, (void**)&as->code_base, &as->code_size);
+ if (as->code_base == NULL) {
+ assert(0);
+ }
}
+ as->pass = pass;
+ as->code_offset = 0;
}
void asm_arm_end_pass(asm_arm_t *as) {
- if (as->pass == ASM_ARM_PASS_COMPUTE) {
- MP_PLAT_ALLOC_EXEC(as->code_offset, (void**) &as->code_base, &as->code_size);
- if(as->code_base == NULL) {
- assert(0);
- }
- } else if(as->pass == ASM_ARM_PASS_EMIT) {
+ if (as->pass == ASM_ARM_PASS_EMIT) {
#ifdef __arm__
// flush I- and D-cache
asm volatile(
diff --git a/py/asmthumb.c b/py/asmthumb.c
index 14ba5a6fcd..7182d52fad 100644
--- a/py/asmthumb.c
+++ b/py/asmthumb.c
@@ -73,32 +73,21 @@ void asm_thumb_free(asm_thumb_t *as, bool free_code) {
}
void asm_thumb_start_pass(asm_thumb_t *as, uint pass) {
- as->pass = pass;
- as->code_offset = 0;
if (pass == ASM_THUMB_PASS_COMPUTE) {
memset(as->label_offsets, -1, as->max_num_labels * sizeof(mp_uint_t));
- }
-}
-
-void asm_thumb_end_pass(asm_thumb_t *as) {
- if (as->pass == ASM_THUMB_PASS_COMPUTE) {
- MP_PLAT_ALLOC_EXEC(as->code_offset, (void**) &as->code_base, &as->code_size);
- if(as->code_base == NULL) {
+ } else if (pass == ASM_THUMB_PASS_EMIT) {
+ MP_PLAT_ALLOC_EXEC(as->code_offset, (void**)&as->code_base, &as->code_size);
+ if (as->code_base == NULL) {
assert(0);
}
//printf("code_size: %u\n", as->code_size);
}
+ as->pass = pass;
+ as->code_offset = 0;
+}
- /*
- // check labels are resolved
- if (as->label != NULL)
- {
- int i;
- for (i = 0; i < as->label->len; ++i)
- if (g_array_index(as->label, Label, i).unresolved != NULL)
- return false;
- }
- */
+void asm_thumb_end_pass(asm_thumb_t *as) {
+ // could check labels are resolved...
}
// all functions must go through this one to emit bytes
diff --git a/py/asmx64.c b/py/asmx64.c
index b3c4eee069..222b280fb5 100644
--- a/py/asmx64.c
+++ b/py/asmx64.c
@@ -143,33 +143,22 @@ void asm_x64_free(asm_x64_t *as, bool free_code) {
}
void asm_x64_start_pass(asm_x64_t *as, uint pass) {
- as->pass = pass;
- as->code_offset = 0;
if (pass == ASM_X64_PASS_COMPUTE) {
// reset all labels
memset(as->label_offsets, -1, as->max_num_labels * sizeof(mp_uint_t));
- }
-}
-
-void asm_x64_end_pass(asm_x64_t *as) {
- if (as->pass == ASM_X64_PASS_COMPUTE) {
- MP_PLAT_ALLOC_EXEC(as->code_offset, (void**) &as->code_base, &as->code_size);
- if(as->code_base == NULL) {
+ } if (pass == ASM_X64_PASS_EMIT) {
+ MP_PLAT_ALLOC_EXEC(as->code_offset, (void**)&as->code_base, &as->code_size);
+ if (as->code_base == NULL) {
assert(0);
}
//printf("code_size: %u\n", as->code_size);
}
+ as->pass = pass;
+ as->code_offset = 0;
+}
- /*
- // check labels are resolved
- if (as->label != NULL)
- {
- int i;
- for (i = 0; i < as->label->len; ++i)
- if (g_array_index(as->label, Label, i).unresolved != NULL)
- return false;
- }
- */
+void asm_x64_end_pass(asm_x64_t *as) {
+ // could check labels are resolved...
}
// all functions must go through this one to emit bytes
diff --git a/py/asmx86.c b/py/asmx86.c
index 29ceaf8f87..d35712e235 100644
--- a/py/asmx86.c
+++ b/py/asmx86.c
@@ -131,21 +131,20 @@ void asm_x86_free(asm_x86_t *as, bool free_code) {
}
void asm_x86_start_pass(asm_x86_t *as, mp_uint_t pass) {
- as->pass = pass;
- as->code_offset = 0;
if (pass == ASM_X86_PASS_COMPUTE) {
// reset all labels
memset(as->label_offsets, -1, as->max_num_labels * sizeof(mp_uint_t));
+ } else if (pass == ASM_X86_PASS_EMIT) {
+ MP_PLAT_ALLOC_EXEC(as->code_offset, (void**)&as->code_base, &as->code_size);
+ if (as->code_base == NULL) {
+ assert(0);
+ }
}
+ as->pass = pass;
+ as->code_offset = 0;
}
void asm_x86_end_pass(asm_x86_t *as) {
- if (as->pass == ASM_X86_PASS_COMPUTE) {
- MP_PLAT_ALLOC_EXEC(as->code_offset, (void**) &as->code_base, &as->code_size);
- if(as->code_base == NULL) {
- assert(0);
- }
- }
}
// all functions must go through this one to emit bytes