aboutsummaryrefslogtreecommitdiff
path: root/py/asmbase.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-12-09 22:50:58 +1100
committerDamien George <damien.p.george@gmail.com>2016-12-09 22:50:58 +1100
commit155fdc74d5864266441887d6c88111159f401a62 (patch)
tree190638448b8cedcdfe43fa703b3bf72e3a38f333 /py/asmbase.c
parente920bab9768f71c7e22fcfc5af3e1c40f2db8eeb (diff)
py/asm: Remove need for dummy_data when doing initial assembler passes.
For all but the last pass the assembler only needs to count how much space is needed for the machine code, it doesn't actually need to emit anything. The dummy_data just uses unnecessary RAM and without it the code is not any more complex (and code size does not increase for Thumb and Xtensa archs).
Diffstat (limited to 'py/asmbase.c')
-rw-r--r--py/asmbase.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/py/asmbase.c b/py/asmbase.c
index 848730593..c941e917b 100644
--- a/py/asmbase.c
+++ b/py/asmbase.c
@@ -59,17 +59,16 @@ void mp_asm_base_start_pass(mp_asm_base_t *as, int pass) {
}
// all functions must go through this one to emit bytes
-// if as->pass < MP_ASM_PASS_EMIT, then this function returns dummy_data
+// 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
uint8_t *mp_asm_base_get_cur_to_write_bytes(mp_asm_base_t *as, size_t num_bytes_to_write) {
- if (as->pass < MP_ASM_PASS_EMIT) {
- as->code_offset += num_bytes_to_write;
- return as->dummy_data;
- } else {
+ uint8_t *c = NULL;
+ if (as->pass == MP_ASM_PASS_EMIT) {
assert(as->code_offset + num_bytes_to_write <= as->code_size);
- uint8_t *c = as->code_base + as->code_offset;
- as->code_offset += num_bytes_to_write;
- return c;
+ c = as->code_base + as->code_offset;
}
+ as->code_offset += num_bytes_to_write;
+ return c;
}
void mp_asm_base_label_assign(mp_asm_base_t *as, size_t label) {
@@ -92,8 +91,7 @@ void mp_asm_base_align(mp_asm_base_t* as, unsigned int align) {
// this function assumes a little endian machine
void mp_asm_base_data(mp_asm_base_t* as, unsigned int bytesize, uintptr_t val) {
uint8_t *c = mp_asm_base_get_cur_to_write_bytes(as, bytesize);
- // only write to the buffer in the emit pass (otherwise we may overflow dummy_data)
- if (as->pass == MP_ASM_PASS_EMIT) {
+ if (c != NULL) {
for (unsigned int i = 0; i < bytesize; i++) {
*c++ = val;
val >>= 8;