Browse Source

Incorporate emit_thumb into new emit framework.

pull/3/head
Damien 11 years ago
parent
commit
5bfb759980
  1. 2
      py/Makefile
  2. 102
      py/asmthumb.c
  3. 2
      py/asmthumb.h
  4. 8
      py/compile.c
  5. 346
      py/emitthumb.c

2
py/Makefile

@ -1,5 +1,5 @@
CC = gcc
CFLAGS = -Wall -ansi -std=gnu99 -Os -DEMIT_ENABLE_CPY -DEMIT_ENABLE_X64 #-DNDEBUG
CFLAGS = -Wall -ansi -std=gnu99 -Os -DEMIT_ENABLE_CPY -DEMIT_ENABLE_X64 -DEMIT_ENABLE_THUMB #-DNDEBUG
LDFLAGS =
SRC = \

102
py/asmthumb.c

@ -28,7 +28,7 @@ struct _asm_thumb_t {
uint stack_adjust;
};
asm_thumb_t *asm_thumb_new() {
asm_thumb_t *asm_thumb_new(uint max_num_labels) {
asm_thumb_t *as;
as = m_new(asm_thumb_t, 1);
@ -36,7 +36,8 @@ asm_thumb_t *asm_thumb_new() {
as->code_offset = 0;
as->code_size = 0;
as->code_base = NULL;
as->label_offsets = NULL;
as->max_num_labels = max_num_labels;
as->label_offsets = m_new(int, max_num_labels);
as->num_locals = 0;
return as;
@ -65,23 +66,13 @@ void asm_thumb_start_pass(asm_thumb_t *as, int pass) {
as->pass = pass;
as->code_offset = 0;
as->next_label = 1;
if (pass == ASM_THUMB_PASS_1) {
as->max_num_labels = 0;
} else {
if (pass == ASM_THUMB_PASS_2) {
memset(as->label_offsets, -1, as->max_num_labels * sizeof(int));
}
if (pass == ASM_THUMB_PASS_2) {
memset(as->label_offsets, -1, as->max_num_labels * sizeof(int));
}
}
void asm_thumb_end_pass(asm_thumb_t *as) {
if (as->pass == ASM_THUMB_PASS_1) {
// calculate number of labels need
if (as->next_label > as->max_num_labels) {
as->max_num_labels = as->next_label;
}
as->label_offsets = m_new(int, as->max_num_labels);
} else if (as->pass == ASM_THUMB_PASS_2) {
if (as->pass == ASM_THUMB_PASS_2) {
// calculate size of code in bytes
as->code_size = as->code_offset;
as->code_base = m_new(byte, as->code_size);
@ -226,20 +217,23 @@ int asm_thumb_label_new(asm_thumb_t *as) {
}
void asm_thumb_label_assign(asm_thumb_t *as, int label) {
if (as->pass > ASM_THUMB_PASS_1) {
assert(label < as->max_num_labels);
if (as->pass == ASM_THUMB_PASS_2) {
// assign label offset
assert(as->label_offsets[label] == -1);
as->label_offsets[label] = as->code_offset;
} else if (as->pass == ASM_THUMB_PASS_3) {
// ensure label offset has not changed from PASS_2 to PASS_3
//printf("l%d: (at %d=%ld)\n", label, as->label_offsets[label], as->code_offset);
assert(as->label_offsets[label] == as->code_offset);
}
assert(label < as->max_num_labels);
if (as->pass == ASM_THUMB_PASS_2) {
// assign label offset
assert(as->label_offsets[label] == -1);
as->label_offsets[label] = as->code_offset;
} else if (as->pass == ASM_THUMB_PASS_3) {
// ensure label offset has not changed from PASS_2 to PASS_3
//printf("l%d: (at %d=%ld)\n", label, as->label_offsets[label], as->code_offset);
assert(as->label_offsets[label] == as->code_offset);
}
}
static int get_label_dest(asm_thumb_t *as, int label) {
assert(label < as->max_num_labels);
return as->label_offsets[label];
}
// the i8 value will be zero extended into the r32 register!
void asm_thumb_mov_reg_i8(asm_thumb_t *as, uint rlo_dest, int i8) {
assert(rlo_dest < REG_R8);
@ -339,23 +333,21 @@ void asm_thumb_ite_ge(asm_thumb_t *as) {
#define OP_BW_LO(byte_offset) (0xb800 | (((byte_offset) >> 1) & 0x07ff))
void asm_thumb_b_label(asm_thumb_t *as, int label) {
if (as->pass > ASM_THUMB_PASS_1) {
int dest = as->label_offsets[label];
int rel = dest - as->code_offset;
rel -= 4; // account for instruction prefetch, PC is 4 bytes ahead of this instruction
if (dest >= 0 && rel <= -4) {
// is a backwards jump, so we know the size of the jump on the first pass
// calculate rel assuming 12 bit relative jump
if (SIGNED_FIT12(rel)) {
asm_thumb_write_op16(as, OP_B(rel));
} else {
goto large_jump;
}
int dest = get_label_dest(as, label);
int rel = dest - as->code_offset;
rel -= 4; // account for instruction prefetch, PC is 4 bytes ahead of this instruction
if (dest >= 0 && rel <= -4) {
// is a backwards jump, so we know the size of the jump on the first pass
// calculate rel assuming 12 bit relative jump
if (SIGNED_FIT12(rel)) {
asm_thumb_write_op16(as, OP_B(rel));
} else {
// is a forwards jump, so need to assume it's large
large_jump:
asm_thumb_write_op32(as, OP_BW_HI(rel), OP_BW_LO(rel));
goto large_jump;
}
} else {
// is a forwards jump, so need to assume it's large
large_jump:
asm_thumb_write_op32(as, OP_BW_HI(rel), OP_BW_LO(rel));
}
}
@ -372,23 +364,21 @@ void asm_thumb_cmp_reg_bz_label(asm_thumb_t *as, uint rlo, int label) {
asm_thumb_write_op16(as, OP_CMP_REG_IMM(rlo, 0));
// branch if equal
if (as->pass > ASM_THUMB_PASS_1) {
int dest = as->label_offsets[label];
int rel = dest - as->code_offset;
rel -= 4; // account for instruction prefetch, PC is 4 bytes ahead of this instruction
if (dest >= 0 && rel <= -4) {
// is a backwards jump, so we know the size of the jump on the first pass
// calculate rel assuming 12 bit relative jump
if (SIGNED_FIT9(rel)) {
asm_thumb_write_op16(as, OP_BEQ(rel));
} else {
goto large_jump;
}
int dest = get_label_dest(as, label);
int rel = dest - as->code_offset;
rel -= 4; // account for instruction prefetch, PC is 4 bytes ahead of this instruction
if (dest >= 0 && rel <= -4) {
// is a backwards jump, so we know the size of the jump on the first pass
// calculate rel assuming 12 bit relative jump
if (SIGNED_FIT9(rel)) {
asm_thumb_write_op16(as, OP_BEQ(rel));
} else {
// is a forwards jump, so need to assume it's large
large_jump:
asm_thumb_write_op32(as, OP_BEQW_HI(rel), OP_BEQW_LO(rel));
goto large_jump;
}
} else {
// is a forwards jump, so need to assume it's large
large_jump:
asm_thumb_write_op32(as, OP_BEQW_HI(rel), OP_BEQW_LO(rel));
}
}

2
py/asmthumb.h

@ -28,7 +28,7 @@
typedef struct _asm_thumb_t asm_thumb_t;
asm_thumb_t *asm_thumb_new();
asm_thumb_t *asm_thumb_new(uint max_num_labels);
void asm_thumb_free(asm_thumb_t *as, bool free_code);
void asm_thumb_start_pass(asm_thumb_t *as, int pass);
void asm_thumb_end_pass(asm_thumb_t *as);

8
py/compile.c

@ -30,6 +30,7 @@ typedef enum {
#define EMIT_OPT_NONE (0)
#define EMIT_OPT_BYTE_CODE (1)
#define EMIT_OPT_NATIVE_PYTHON (2)
#define EMIT_OPT_ASM_THUMB (3)
typedef struct _compiler_t {
qstr qstr___class__;
@ -41,6 +42,7 @@ typedef struct _compiler_t {
qstr qstr_assertion_error;
qstr qstr_micropython;
qstr qstr_native;
qstr qstr_asm_thumb;
pass_kind_t pass;
@ -759,6 +761,8 @@ static bool compile_built_in_decorator(compiler_t *comp, int name_len, py_parse_
qstr attr = PY_PARSE_NODE_LEAF_ARG(name_nodes[1]);
if (attr == comp->qstr_native) {
*emit_options = EMIT_OPT_NATIVE_PYTHON;
} else if (attr == comp->qstr_asm_thumb) {
*emit_options = EMIT_OPT_ASM_THUMB;
} else {
printf("SyntaxError: invalid micropython decorator\n");
}
@ -2551,6 +2555,7 @@ void py_compile(py_parse_node_t pn) {
comp->qstr_assertion_error = qstr_from_str_static("AssertionError");
comp->qstr_micropython = qstr_from_str_static("micropython");
comp->qstr_native = qstr_from_str_static("native");
comp->qstr_asm_thumb = qstr_from_str_static("asm_thumb");
comp->max_num_labels = 0;
comp->break_label = 0;
@ -2588,6 +2593,9 @@ void py_compile(py_parse_node_t pn) {
comp->emit_method_table = &emit_x64_method_table;
break;
//case EMIT_OPT_ASM_THUMB:
//if (em
default:
if (emit_bc == NULL) {
emit_bc = emit_bc_new(comp->max_num_labels);

346
py/emitthumb.c

@ -14,7 +14,7 @@
#include "emit.h"
#include "asmthumb.h"
#ifdef EMIT_DO_THUMB
#ifdef EMIT_ENABLE_THUMB
#define REG_LOCAL_1 (REG_R4)
#define REG_LOCAL_2 (REG_R5)
@ -28,7 +28,7 @@ typedef enum {
NEED_TO_PUSH_I32,
} need_to_push_t;
struct _emitter_t {
struct _emit_t {
int pass;
int stack_start;
int stack_size;
@ -43,14 +43,18 @@ struct _emitter_t {
bool do_native_types;
};
emitter_t *emit_new() {
emitter_t *emit = m_new(emitter_t, 1);
emit->as = asm_thumb_new();
emit->do_native_types = true;
emit_t *emit_thumb_new(uint max_num_labels) {
emit_t *emit = m_new(emit_t, 1);
emit->as = asm_thumb_new(max_num_labels);
emit->do_native_types = false;
return emit;
}
void emit_start_pass(emitter_t *emit, pass_kind_t pass, scope_t *scope) {
static void emit_thumb_set_native_types(emit_t *emit, bool do_native_types) {
emit->do_native_types = do_native_types;
}
static void emit_thumb_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
emit->pass = pass;
emit->stack_start = 0;
emit->stack_size = 0;
@ -91,7 +95,7 @@ void emit_start_pass(emitter_t *emit, pass_kind_t pass, scope_t *scope) {
asm_thumb_mov_reg_i32(emit->as, REG_R7, (machine_uint_t)rt_fun_table);
}
void emit_end_pass(emitter_t *emit) {
static void emit_thumb_end_pass(emit_t *emit) {
if (!emit->last_emit_was_return_value) {
asm_thumb_exit(emit->as);
}
@ -108,19 +112,19 @@ void emit_end_pass(emitter_t *emit) {
}
}
bool emit_last_emit_was_return_value(emitter_t *emit) {
static bool emit_thumb_last_emit_was_return_value(emit_t *emit) {
return emit->last_emit_was_return_value;
}
int emit_get_stack_size(emitter_t *emit) {
static int emit_thumb_get_stack_size(emit_t *emit) {
return emit->stack_size;
}
void emit_set_stack_size(emitter_t *emit, int size) {
static void emit_thumb_set_stack_size(emit_t *emit, int size) {
emit->stack_size = size;
}
static void adjust_stack(emitter_t *emit, int stack_size_delta) {
static void adjust_stack(emit_t *emit, int stack_size_delta) {
emit->stack_size += stack_size_delta;
assert(emit->stack_size >= 0);
if (emit->pass > PASS_1 && emit->stack_size > emit->scope->stack_size) {
@ -128,7 +132,7 @@ static void adjust_stack(emitter_t *emit, int stack_size_delta) {
}
}
static void stack_settle(emitter_t *emit) {
static void stack_settle(emit_t *emit) {
switch (emit->need_to_push) {
case NEED_TO_PUSH_NOTHING:
break;
@ -147,17 +151,17 @@ static void stack_settle(emitter_t *emit) {
emit->need_to_push = NEED_TO_PUSH_NOTHING;
}
static void emit_pre_raw(emitter_t *emit, int stack_size_delta) {
static void emit_pre_raw(emit_t *emit, int stack_size_delta) {
adjust_stack(emit, stack_size_delta);
emit->last_emit_was_return_value = false;
}
static void emit_pre(emitter_t *emit) {
static void emit_pre(emit_t *emit) {
stack_settle(emit);
emit_pre_raw(emit, 0);
}
static void emit_pre_pop_reg(emitter_t *emit, int reg_dest) {
static void emit_pre_pop_reg(emit_t *emit, int reg_dest) {
switch (emit->need_to_push) {
case NEED_TO_PUSH_NOTHING:
asm_thumb_mov_reg_local(emit->as, reg_dest, emit->stack_start + emit->stack_size - 1);
@ -179,47 +183,47 @@ static void emit_pre_pop_reg(emitter_t *emit, int reg_dest) {
emit->need_to_push = NEED_TO_PUSH_NOTHING;
}
static void emit_pre_pop_reg_reg(emitter_t *emit, int rega, int regb) {
static void emit_pre_pop_reg_reg(emit_t *emit, int rega, int regb) {
emit_pre_pop_reg(emit, rega);
asm_thumb_mov_reg_local(emit->as, regb, emit->stack_start + emit->stack_size - 1);
adjust_stack(emit, -1);
}
static void emit_pre_pop_reg_reg_reg(emitter_t *emit, int rega, int regb, int regc) {
static void emit_pre_pop_reg_reg_reg(emit_t *emit, int rega, int regb, int regc) {
emit_pre_pop_reg(emit, rega);
asm_thumb_mov_reg_local(emit->as, regb, emit->stack_start + emit->stack_size - 1);
asm_thumb_mov_reg_local(emit->as, regc, emit->stack_start + emit->stack_size - 2);
adjust_stack(emit, -2);
}
static void emit_post(emitter_t *emit) {
static void emit_post(emit_t *emit) {
}
static void emit_post_push_reg(emitter_t *emit, int reg) {
static void emit_post_push_reg(emit_t *emit, int reg) {
emit->need_to_push = NEED_TO_PUSH_REG;
emit->last_reg = reg;
}
static void emit_post_push_i32(emitter_t *emit, int32_t i32) {
static void emit_post_push_i32(emit_t *emit, int32_t i32) {
emit->need_to_push = NEED_TO_PUSH_I32;
emit->last_i32 = i32;
}
static void emit_post_push_reg_reg(emitter_t *emit, int rega, int regb) {
static void emit_post_push_reg_reg(emit_t *emit, int rega, int regb) {
asm_thumb_mov_local_reg(emit->as, emit->stack_start + emit->stack_size, rega);
emit->need_to_push = NEED_TO_PUSH_REG;
emit->last_reg = regb;
adjust_stack(emit, 1);
}
static void emit_post_push_reg_reg_reg(emitter_t *emit, int rega, int regb, int regc) {
static void emit_post_push_reg_reg_reg(emit_t *emit, int rega, int regb, int regc) {
asm_thumb_mov_local_reg(emit->as, emit->stack_start + emit->stack_size, rega);
asm_thumb_mov_local_reg(emit->as, emit->stack_start + emit->stack_size + 1, regb);
asm_thumb_mov_local_reg(emit->as, emit->stack_start + emit->stack_size + 2, regc);
adjust_stack(emit, 3);
}
static void emit_post_push_reg_reg_reg_reg(emitter_t *emit, int rega, int regb, int regc, int regd) {
static void emit_post_push_reg_reg_reg_reg(emit_t *emit, int rega, int regb, int regc, int regd) {
asm_thumb_mov_local_reg(emit->as, emit->stack_start + emit->stack_size, rega);
asm_thumb_mov_local_reg(emit->as, emit->stack_start + emit->stack_size + 1, regb);
asm_thumb_mov_local_reg(emit->as, emit->stack_start + emit->stack_size + 2, regc);
@ -227,44 +231,52 @@ static void emit_post_push_reg_reg_reg_reg(emitter_t *emit, int rega, int regb,
adjust_stack(emit, 4);
}
static void emit_get_stack_pointer_to_reg_for_pop(emitter_t *emit, int reg_dest, int n_pop) {
static void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, int reg_dest, int n_pop) {
asm_thumb_mov_reg_local_addr(emit->as, reg_dest, emit->stack_start + emit->stack_size - 1);
adjust_stack(emit, -n_pop);
}
static void emit_get_stack_pointer_to_reg_for_push(emitter_t *emit, int reg_dest, int n_push) {
static void emit_get_stack_pointer_to_reg_for_push(emit_t *emit, int reg_dest, int n_push) {
asm_thumb_mov_reg_local_addr(emit->as, reg_dest, emit->stack_start + emit->stack_size + n_push - 1);
adjust_stack(emit, n_push);
}
static void emit_call(emitter_t *emit, rt_fun_kind_t fun_kind) {
static void emit_call(emit_t *emit, rt_fun_kind_t fun_kind) {
asm_thumb_bl_ind(emit->as, rt_fun_table[fun_kind], fun_kind, REG_R3);
}
static void emit_call_with_i32_arg(emitter_t *emit, rt_fun_kind_t fun_kind, int32_t arg_val, int arg_reg) {
static void emit_call_with_i32_arg(emit_t *emit, rt_fun_kind_t fun_kind, int32_t arg_val, int arg_reg) {
asm_thumb_mov_reg_i32_optimised(emit->as, arg_reg, arg_val);
asm_thumb_bl_ind(emit->as, rt_fun_table[fun_kind], fun_kind, REG_R3);
}
int emit_label_new(emitter_t *emit) {
return asm_thumb_label_new(emit->as);
static void emit_thumb_load_id(emit_t *emit, qstr qstr) {
emit_common_load_id(emit, &emit_thumb_method_table, emit->scope, qstr);
}
static void emit_thumb_store_id(emit_t *emit, qstr qstr) {
emit_common_store_id(emit, &emit_thumb_method_table, emit->scope, qstr);
}
void emit_label_assign(emitter_t *emit, int l) {
static void emit_thumb_delete_id(emit_t *emit, qstr qstr) {
emit_common_delete_id(emit, &emit_thumb_method_table, emit->scope, qstr);
}
static void emit_thumb_label_assign(emit_t *emit, int l) {
asm_thumb_label_assign(emit->as, l);
}
void emit_import_name(emitter_t *emit, qstr qstr) {
static void emit_thumb_import_name(emit_t *emit, qstr qstr) {
assert(0);
}
void emit_import_from(emitter_t *emit, qstr qstr) {
static void emit_thumb_import_from(emit_t *emit, qstr qstr) {
assert(0);
}
void emit_import_star(emitter_t *emit) {
static void emit_thumb_import_star(emit_t *emit) {
assert(0);
}
void emit_load_const_tok(emitter_t *emit, py_token_kind_t tok) {
static void emit_thumb_load_const_tok(emit_t *emit, py_token_kind_t tok) {
emit_pre(emit);
py_obj_t o;
switch (tok) {
@ -276,7 +288,7 @@ void emit_load_const_tok(emitter_t *emit, py_token_kind_t tok) {
emit_post_push_i32(emit, (machine_uint_t)o);
}
void emit_load_const_small_int(emitter_t *emit, int arg) {
static void emit_thumb_load_const_small_int(emit_t *emit, int arg) {
emit_pre(emit);
if (emit->do_native_types) {
emit_post_push_i32(emit, arg);
@ -285,42 +297,42 @@ void emit_load_const_small_int(emitter_t *emit, int arg) {
}
}
void emit_load_const_int(emitter_t *emit, qstr qstr) {
static void emit_thumb_load_const_int(emit_t *emit, qstr qstr) {
assert(0);
}
void emit_load_const_dec(emitter_t *emit, qstr qstr) {
static void emit_thumb_load_const_dec(emit_t *emit, qstr qstr) {
assert(0);
}
void emit_load_const_id(emitter_t *emit, qstr qstr) {
static void emit_thumb_load_const_id(emit_t *emit, qstr qstr) {
assert(0);
}
void emit_load_const_str(emitter_t *emit, qstr qstr, bool bytes) {
static void emit_thumb_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
emit_pre(emit);
emit_call_with_i32_arg(emit, RT_F_LOAD_CONST_STR, qstr, REG_ARG_1);
emit_post_push_reg(emit, REG_RET);
}
void emit_load_const_verbatim_start(emitter_t *emit) {
static void emit_thumb_load_const_verbatim_start(emit_t *emit) {
assert(0);
}
void emit_load_const_verbatim_int(emitter_t *emit, int val) {
static void emit_thumb_load_const_verbatim_int(emit_t *emit, int val) {
assert(0);
}
void emit_load_const_verbatim_str(emitter_t *emit, const char *str) {
static void emit_thumb_load_const_verbatim_str(emit_t *emit, const char *str) {
assert(0);
}
void emit_load_const_verbatim_strn(emitter_t *emit, const char *str, int len) {
static void emit_thumb_load_const_verbatim_strn(emit_t *emit, const char *str, int len) {
assert(0);
}
void emit_load_const_verbatim_quoted_str(emitter_t *emit, qstr qstr, bool bytes) {
static void emit_thumb_load_const_verbatim_quoted_str(emit_t *emit, qstr qstr, bool bytes) {
assert(0);
}
void emit_load_const_verbatim_end(emitter_t *emit) {
static void emit_thumb_load_const_verbatim_end(emit_t *emit) {
assert(0);
}
void emit_load_fast(emitter_t *emit, qstr qstr, int local_num) {
static void emit_thumb_load_fast(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit);
if (local_num == 0) {
emit_post_push_reg(emit, REG_LOCAL_1);
@ -334,42 +346,42 @@ void emit_load_fast(emitter_t *emit, qstr qstr, int local_num) {
}
}
void emit_load_name(emitter_t *emit, qstr qstr) {
static void emit_thumb_load_name(emit_t *emit, qstr qstr) {
emit_pre(emit);
emit_call_with_i32_arg(emit, RT_F_LOAD_NAME, qstr, REG_ARG_1);
emit_post_push_reg(emit, REG_RET);
}
void emit_load_global(emitter_t *emit, qstr qstr) {
static void emit_thumb_load_global(emit_t *emit, qstr qstr) {
emit_pre(emit);
emit_call_with_i32_arg(emit, RT_F_LOAD_GLOBAL, qstr, REG_ARG_1);
emit_post_push_reg(emit, REG_RET);
}
void emit_load_deref(emitter_t *emit, qstr qstr) {
static void emit_thumb_load_deref(emit_t *emit, qstr qstr) {
assert(0);
}
void emit_load_closure(emitter_t *emit, qstr qstr) {
static void emit_thumb_load_closure(emit_t *emit, qstr qstr) {
assert(0);
}
void emit_load_attr(emitter_t *emit, qstr qstr) {
static void emit_thumb_load_attr(emit_t *emit, qstr qstr) {
emit_pre_pop_reg(emit, REG_ARG_1); // arg1 = base
emit_call_with_i32_arg(emit, RT_F_LOAD_ATTR, qstr, REG_ARG_2); // arg2 = attribute name
emit_post_push_reg(emit, REG_RET);
}
void emit_load_method(emitter_t *emit, qstr qstr) {
static void emit_thumb_load_method(emit_t *emit, qstr qstr) {
emit_pre_pop_reg(emit, REG_ARG_1); // arg1 = base
emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_3, 2); // arg3 = dest ptr
emit_call_with_i32_arg(emit, RT_F_LOAD_METHOD, qstr, REG_ARG_2); // arg2 = method name
}
void emit_load_build_class(emitter_t *emit) {
static void emit_thumb_load_build_class(emit_t *emit) {
assert(0);
} // basically load __build_class__ from builtins
void emit_store_fast(emitter_t *emit, qstr qstr, int local_num) {
static void emit_thumb_store_fast(emit_t *emit, qstr qstr, int local_num) {
if (local_num == 0) {
emit_pre_pop_reg(emit, REG_LOCAL_1);
} else if (local_num == 1) {
@ -383,81 +395,81 @@ void emit_store_fast(emitter_t *emit, qstr qstr, int local_num) {
emit_post(emit);
}
void emit_store_name(emitter_t *emit, qstr qstr) {
static void emit_thumb_store_name(emit_t *emit, qstr qstr) {
emit_pre_pop_reg(emit, REG_ARG_2);
emit_call_with_i32_arg(emit, RT_F_STORE_NAME, qstr, REG_ARG_1); // arg1 = name
emit_post(emit);
}
void emit_store_global(emitter_t *emit, qstr qstr) {
static void emit_thumb_store_global(emit_t *emit, qstr qstr) {
assert(0);
}
void emit_store_deref(emitter_t *emit, qstr qstr) {
static void emit_thumb_store_deref(emit_t *emit, qstr qstr) {
assert(0);
}
void emit_store_attr(emitter_t *emit, qstr qstr) {
static void emit_thumb_store_attr(emit_t *emit, qstr qstr) {
assert(0);
}
void emit_store_locals(emitter_t *emit) {
static void emit_thumb_store_locals(emit_t *emit) {
assert(0);
}
void emit_store_subscr(emitter_t *emit) {
static void emit_thumb_store_subscr(emit_t *emit) {
emit_pre_pop_reg_reg_reg(emit, REG_ARG_2, REG_ARG_1, REG_ARG_3); // index, base, value to store
emit_call(emit, RT_F_STORE_SUBSCR);
}
void emit_delete_fast(emitter_t *emit, qstr qstr, int local_num) {
static void emit_thumb_delete_fast(emit_t *emit, qstr qstr, int local_num) {
assert(0);
}
void emit_delete_name(emitter_t *emit, qstr qstr) {
static void emit_thumb_delete_name(emit_t *emit, qstr qstr) {
assert(0);
}
void emit_delete_global(emitter_t *emit, qstr qstr) {
static void emit_thumb_delete_global(emit_t *emit, qstr qstr) {
assert(0);
}
void emit_delete_deref(emitter_t *emit, qstr qstr) {
static void emit_thumb_delete_deref(emit_t *emit, qstr qstr) {
assert(0);
}
void emit_delete_attr(emitter_t *emit, qstr qstr) {
static void emit_thumb_delete_attr(emit_t *emit, qstr qstr) {
assert(0);
}
void emit_delete_subscr(emitter_t *emit) {
static void emit_thumb_delete_subscr(emit_t *emit) {
assert(0);
}
void emit_dup_top(emitter_t *emit) {
static void emit_thumb_dup_top(emit_t *emit) {
emit_pre_pop_reg(emit, REG_R0);
emit_post_push_reg_reg(emit, REG_R0, REG_R0);
}
void emit_dup_top_two(emitter_t *emit) {
static void emit_thumb_dup_top_two(emit_t *emit) {
emit_pre_pop_reg_reg(emit, REG_R0, REG_R1);
emit_post_push_reg_reg_reg_reg(emit, REG_R1, REG_R0, REG_R1, REG_R0);
}
void emit_pop_top(emitter_t *emit) {
static void emit_thumb_pop_top(emit_t *emit) {
emit_pre_pop_reg(emit, REG_R0);
emit_post(emit);
}
void emit_rot_two(emitter_t *emit) {
static void emit_thumb_rot_two(emit_t *emit) {
assert(0);
}
void emit_rot_three(emitter_t *emit) {
static void emit_thumb_rot_three(emit_t *emit) {
emit_pre_pop_reg_reg_reg(emit, REG_R0, REG_R1, REG_R2);
emit_post_push_reg_reg_reg(emit, REG_R0, REG_R2, REG_R1);
}
void emit_jump(emitter_t *emit, int label) {
static void emit_thumb_jump(emit_t *emit, int label) {
emit_pre(emit);
asm_thumb_b_label(emit->as, label);
emit_post(emit);
}
void emit_pop_jump_if_false(emitter_t *emit, int label) {
static void emit_thumb_pop_jump_if_false(emit_t *emit, int label) {
if (emit->do_native_types) {
emit_pre_pop_reg(emit, REG_RET);
asm_thumb_cmp_reg_bz_label(emit->as, REG_RET, label);
@ -470,124 +482,124 @@ void emit_pop_jump_if_false(emitter_t *emit, int label) {
}
}
void emit_pop_jump_if_true(emitter_t *emit, int label) {
static void emit_thumb_pop_jump_if_true(emit_t *emit, int label) {
assert(0);
}
void emit_jump_if_true_or_pop(emitter_t *emit, int label) {
static void emit_thumb_jump_if_true_or_pop(emit_t *emit, int label) {
assert(0);
}
void emit_jump_if_false_or_pop(emitter_t *emit, int label) {
static void emit_thumb_jump_if_false_or_pop(emit_t *emit, int label) {
assert(0);
}
void emit_setup_loop(emitter_t *emit, int label) {
static void emit_thumb_setup_loop(emit_t *emit, int label) {
emit_pre(emit);
emit_post(emit);
}
void emit_break_loop(emitter_t *emit, int label) {
static void emit_thumb_break_loop(emit_t *emit, int label) {
assert(0);
}
void emit_continue_loop(emitter_t *emit, int label) {
static void emit_thumb_continue_loop(emit_t *emit, int label) {
assert(0);
}
void emit_setup_with(emitter_t *emit, int label) {
static void emit_thumb_setup_with(emit_t *emit, int label) {
assert(0);
}
void emit_with_cleanup(emitter_t *emit) {
static void emit_thumb_with_cleanup(emit_t *emit) {
assert(0);
}
void emit_setup_except(emitter_t *emit, int label) {
static void emit_thumb_setup_except(emit_t *emit, int label) {
assert(0);
}
void emit_setup_finally(emitter_t *emit, int label) {
static void emit_thumb_setup_finally(emit_t *emit, int label) {
assert(0);
}
void emit_end_finally(emitter_t *emit) {
static void emit_thumb_end_finally(emit_t *emit) {
assert(0);
}
void emit_get_iter(emitter_t *emit) {
static void emit_thumb_get_iter(emit_t *emit) {
assert(0);
} // tos = getiter(tos)
void emit_for_iter(emitter_t *emit, int label) {
static void emit_thumb_for_iter(emit_t *emit, int label) {
assert(0);
}
void emit_for_iter_end(emitter_t *emit) {
static void emit_thumb_for_iter_end(emit_t *emit) {
assert(0);
}
void emit_pop_except(emitter_t *emit) {
static void emit_thumb_pop_except(emit_t *emit) {
assert(0);
}
void emit_unary_op(emitter_t *emit, rt_unary_op_t op) {
static void emit_thumb_unary_op(emit_t *emit, rt_unary_op_t op) {
emit_pre_pop_reg(emit, REG_ARG_2);
emit_call_with_i32_arg(emit, RT_F_UNARY_OP, op, REG_ARG_1);
emit_post_push_reg(emit, REG_RET);
}
void emit_build_tuple(emitter_t *emit, int n_args) {
static void emit_thumb_build_tuple(emit_t *emit, int n_args) {
assert(0);
}
void emit_build_list(emitter_t *emit, int n_args) {
static void emit_thumb_build_list(emit_t *emit, int n_args) {
emit_pre(emit);
emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items in reverse order
emit_call_with_i32_arg(emit, RT_F_BUILD_LIST, n_args, REG_ARG_1);
emit_post_push_reg(emit, REG_RET); // new list
}
void emit_list_append(emitter_t *emit, int list_index) {
static void emit_thumb_list_append(emit_t *emit, int list_index) {
assert(0);
}
void emit_build_map(emitter_t *emit, int n_args) {
static void emit_thumb_build_map(emit_t *emit, int n_args) {
emit_pre(emit);
emit_call_with_i32_arg(emit, RT_F_BUILD_MAP, n_args, REG_ARG_1);
emit_post_push_reg(emit, REG_RET); // new map
}
void emit_store_map(emitter_t *emit) {
static void emit_thumb_store_map(emit_t *emit) {
emit_pre_pop_reg_reg_reg(emit, REG_ARG_2, REG_ARG_3, REG_ARG_1); // key, value, map
emit_call(emit, RT_F_STORE_MAP);
emit_post_push_reg(emit, REG_RET); // map
}
void emit_map_add(emitter_t *emit, int map_index) {
static void emit_thumb_map_add(emit_t *emit, int map_index) {
assert(0);
}
void emit_build_set(emitter_t *emit, int n_args) {
static void emit_thumb_build_set(emit_t *emit, int n_args) {
emit_pre(emit);
emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items in reverse order
emit_call_with_i32_arg(emit, RT_F_BUILD_SET, n_args, REG_ARG_1);
emit_post_push_reg(emit, REG_RET); // new set
}
void emit_set_add(emitter_t *emit, int set_index) {
static void emit_thumb_set_add(emit_t *emit, int set_index) {
assert(0);
}
void emit_build_slice(emitter_t *emit, int n_args) {
static void emit_thumb_build_slice(emit_t *emit, int n_args) {
assert(0);
}
void emit_unpack_sequence(emitter_t *emit, int n_args) {
static void emit_thumb_unpack_sequence(emit_t *emit, int n_args) {
assert(0);
}
void emit_unpack_ex(emitter_t *emit, int n_left, int n_right) {
static void emit_thumb_unpack_ex(emit_t *emit, int n_left, int n_right) {
assert(0);
}
void emit_make_function(emitter_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
static void emit_thumb_make_function(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
assert(n_default_params == 0 && n_dict_params == 0);
emit_pre(emit);
emit_call_with_i32_arg(emit, RT_F_MAKE_FUNCTION_FROM_ID, scope->unique_code_id, REG_ARG_1);
emit_post_push_reg(emit, REG_RET);
}
void emit_make_closure(emitter_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
static void emit_thumb_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
assert(0);
}
void emit_call_function(emitter_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
static void emit_thumb_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg);
if (n_positional == 0) {
emit_pre_pop_reg(emit, REG_ARG_1); // the function
@ -604,7 +616,7 @@ void emit_call_function(emitter_t *emit, int n_positional, int n_keyword, bool h
emit_post_push_reg(emit, REG_RET);
}
void emit_call_method(emitter_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
static void emit_thumb_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg);
if (n_positional == 0) {
emit_pre_pop_reg_reg(emit, REG_ARG_2, REG_ARG_1); // the self object (or NULL), the method
@ -618,12 +630,12 @@ void emit_call_method(emitter_t *emit, int n_positional, int n_keyword, bool hav
emit_post_push_reg(emit, REG_RET);
}
void emit_pop_block(emitter_t *emit) {
static void emit_thumb_pop_block(emit_t *emit) {
emit_pre(emit);
emit_post(emit);
}
void emit_binary_op(emitter_t *emit, rt_binary_op_t op) {
static void emit_thumb_binary_op(emit_t *emit, rt_binary_op_t op) {
if (emit->do_native_types) {
emit_pre_pop_reg_reg(emit, REG_ARG_2, REG_ARG_1);
asm_thumb_add_reg_reg_reg(emit->as, REG_RET, REG_ARG_1, REG_ARG_2);
@ -635,7 +647,7 @@ void emit_binary_op(emitter_t *emit, rt_binary_op_t op) {
}
}
void emit_compare_op(emitter_t *emit, rt_compare_op_t op) {
static void emit_thumb_compare_op(emit_t *emit, rt_compare_op_t op) {
if (emit->do_native_types) {
emit_pre_pop_reg_reg(emit, REG_ARG_2, REG_ARG_1);
asm_thumb_cmp_reg_reg(emit->as, REG_ARG_1, REG_ARG_2);
@ -650,21 +662,117 @@ void emit_compare_op(emitter_t *emit, rt_compare_op_t op) {
}
}
void emit_return_value(emitter_t *emit) {
static void emit_thumb_return_value(emit_t *emit) {
emit_pre_pop_reg(emit, REG_RET);
emit->last_emit_was_return_value = true;
//asm_thumb_call_ind(emit->as, 0, REG_R0); to seg fault for debugging with gdb
asm_thumb_exit(emit->as);
}
void emit_raise_varargs(emitter_t *emit, int n_args) {
assert(0);
}
void emit_yield_value(emitter_t *emit) {
assert(0);
}
void emit_yield_from(emitter_t *emit) {
assert(0);
}
static void emit_thumb_raise_varargs(emit_t *emit, int n_args) {
assert(0);
}
static void emit_thumb_yield_value(emit_t *emit) {
assert(0);
}
static void emit_thumb_yield_from(emit_t *emit) {
assert(0);
}
const emit_method_table_t emit_thumb_method_table = {
emit_thumb_set_native_types,
emit_thumb_start_pass,
emit_thumb_end_pass,
emit_thumb_last_emit_was_return_value,
emit_thumb_get_stack_size,
emit_thumb_set_stack_size,
emit_thumb_load_id,
emit_thumb_store_id,
emit_thumb_delete_id,
emit_thumb_label_assign,
emit_thumb_import_name,
emit_thumb_import_from,
emit_thumb_import_star,
emit_thumb_load_const_tok,
emit_thumb_load_const_small_int,
emit_thumb_load_const_int,
emit_thumb_load_const_dec,
emit_thumb_load_const_id,
emit_thumb_load_const_str,
emit_thumb_load_const_verbatim_start,
emit_thumb_load_const_verbatim_int,
emit_thumb_load_const_verbatim_str,
emit_thumb_load_const_verbatim_strn,
emit_thumb_load_const_verbatim_quoted_str,
emit_thumb_load_const_verbatim_end,
emit_thumb_load_fast,
emit_thumb_load_name,
emit_thumb_load_global,
emit_thumb_load_deref,
emit_thumb_load_closure,
emit_thumb_load_attr,
emit_thumb_load_method,
emit_thumb_load_build_class,
emit_thumb_store_fast,
emit_thumb_store_name,
emit_thumb_store_global,
emit_thumb_store_deref,
emit_thumb_store_attr,
emit_thumb_store_locals,
emit_thumb_store_subscr,
emit_thumb_delete_fast,
emit_thumb_delete_name,
emit_thumb_delete_global,
emit_thumb_delete_deref,
emit_thumb_delete_attr,
emit_thumb_delete_subscr,
emit_thumb_dup_top,
emit_thumb_dup_top_two,
emit_thumb_pop_top,
emit_thumb_rot_two,
emit_thumb_rot_three,
emit_thumb_jump,
emit_thumb_pop_jump_if_true,
emit_thumb_pop_jump_if_false,
emit_thumb_jump_if_true_or_pop,
emit_thumb_jump_if_false_or_pop,
emit_thumb_setup_loop,
emit_thumb_break_loop,
emit_thumb_continue_loop,
emit_thumb_setup_with,
emit_thumb_with_cleanup,
emit_thumb_setup_except,
emit_thumb_setup_finally,
emit_thumb_end_finally,
emit_thumb_get_iter,
emit_thumb_for_iter,
emit_thumb_for_iter_end,
emit_thumb_pop_block,
emit_thumb_pop_except,
emit_thumb_unary_op,
emit_thumb_binary_op,
emit_thumb_compare_op,
emit_thumb_build_tuple,
emit_thumb_build_list,
emit_thumb_list_append,
emit_thumb_build_map,
emit_thumb_store_map,
emit_thumb_map_add,
emit_thumb_build_set,
emit_thumb_set_add,
emit_thumb_build_slice,
emit_thumb_unpack_sequence,
emit_thumb_unpack_ex,
emit_thumb_make_function,
emit_thumb_make_closure,
emit_thumb_call_function,
emit_thumb_call_method,
emit_thumb_return_value,
emit_thumb_raise_varargs,
emit_thumb_yield_value,
emit_thumb_yield_from,
};
#endif // EMIT_DO_THUMB
#endif // EMIT_ENABLE_THUMB

Loading…
Cancel
Save