py/emitinline: Move common code for end of final pass to compiler.

This patch moves some common code from the individual inline assemblers to
the compiler, the code that calls the emit-glue to assign the machine code
to the functions scope.
This commit is contained in:
Damien George 2016-12-09 21:23:17 +11:00
parent dd53b12193
commit e920bab976
4 changed files with 11 additions and 20 deletions

View File

@ -3127,7 +3127,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
}
if (comp->pass > MP_PASS_SCOPE) {
EMIT_INLINE_ASM_ARG(start_pass, comp->pass, comp->scope_cur, &comp->compile_error);
EMIT_INLINE_ASM_ARG(start_pass, comp->pass, &comp->compile_error);
}
// get the function definition parse node
@ -3258,6 +3258,13 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
if (comp->pass > MP_PASS_SCOPE) {
EMIT_INLINE_ASM_ARG(end_pass, type_sig);
if (comp->pass == MP_PASS_EMIT) {
void *f = mp_asm_base_get_code((mp_asm_base_t*)comp->emit_inline_asm);
mp_emit_glue_assign_native(comp->scope_cur->raw_code, MP_CODE_NATIVE_ASM,
f, mp_asm_base_get_code_size((mp_asm_base_t*)comp->emit_inline_asm),
NULL, comp->scope_cur->num_pos_args, 0, type_sig);
}
}
if (comp->compile_error != MP_OBJ_NULL) {

View File

@ -262,7 +262,7 @@ void mp_emit_bc_end_except_handler(emit_t *emit);
typedef struct _emit_inline_asm_t emit_inline_asm_t;
typedef struct _emit_inline_asm_method_table_t {
void (*start_pass)(emit_inline_asm_t *emit, pass_kind_t pass, scope_t *scope, mp_obj_t *error_slot);
void (*start_pass)(emit_inline_asm_t *emit, pass_kind_t pass, mp_obj_t *error_slot);
void (*end_pass)(emit_inline_asm_t *emit, mp_uint_t type_sig);
mp_uint_t (*count_params)(emit_inline_asm_t *emit, mp_uint_t n_params, mp_parse_node_t *pn_params);
bool (*label)(emit_inline_asm_t *emit, mp_uint_t label_num, qstr label_id);

View File

@ -45,7 +45,6 @@ typedef enum {
struct _emit_inline_asm_t {
asm_thumb_t as;
uint16_t pass;
scope_t *scope;
mp_obj_t *error_slot;
mp_uint_t max_num_labels;
qstr *label_lookup;
@ -74,9 +73,8 @@ void emit_inline_thumb_free(emit_inline_asm_t *emit) {
m_del_obj(emit_inline_asm_t, emit);
}
STATIC void emit_inline_thumb_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, scope_t *scope, mp_obj_t *error_slot) {
STATIC void emit_inline_thumb_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, mp_obj_t *error_slot) {
emit->pass = pass;
emit->scope = scope;
emit->error_slot = error_slot;
if (emit->pass == MP_PASS_CODE_SIZE) {
memset(emit->label_lookup, 0, emit->max_num_labels * sizeof(qstr));
@ -88,12 +86,6 @@ STATIC void emit_inline_thumb_start_pass(emit_inline_asm_t *emit, pass_kind_t pa
STATIC void emit_inline_thumb_end_pass(emit_inline_asm_t *emit, mp_uint_t type_sig) {
asm_thumb_exit(&emit->as);
asm_thumb_end_pass(&emit->as);
if (emit->pass == MP_PASS_EMIT) {
void *f = mp_asm_base_get_code(&emit->as.base);
mp_emit_glue_assign_native(emit->scope->raw_code, MP_CODE_NATIVE_ASM, f,
mp_asm_base_get_code_size(&emit->as.base), NULL, emit->scope->num_pos_args, 0, type_sig);
}
}
STATIC mp_uint_t emit_inline_thumb_count_params(emit_inline_asm_t *emit, mp_uint_t n_params, mp_parse_node_t *pn_params) {

View File

@ -38,7 +38,6 @@
struct _emit_inline_asm_t {
asm_xtensa_t as;
uint16_t pass;
scope_t *scope;
mp_obj_t *error_slot;
mp_uint_t max_num_labels;
qstr *label_lookup;
@ -67,9 +66,8 @@ void emit_inline_xtensa_free(emit_inline_asm_t *emit) {
m_del_obj(emit_inline_asm_t, emit);
}
STATIC void emit_inline_xtensa_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, scope_t *scope, mp_obj_t *error_slot) {
STATIC void emit_inline_xtensa_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, mp_obj_t *error_slot) {
emit->pass = pass;
emit->scope = scope;
emit->error_slot = error_slot;
if (emit->pass == MP_PASS_CODE_SIZE) {
memset(emit->label_lookup, 0, emit->max_num_labels * sizeof(qstr));
@ -81,12 +79,6 @@ STATIC void emit_inline_xtensa_start_pass(emit_inline_asm_t *emit, pass_kind_t p
STATIC void emit_inline_xtensa_end_pass(emit_inline_asm_t *emit, mp_uint_t type_sig) {
asm_xtensa_exit(&emit->as);
asm_xtensa_end_pass(&emit->as);
if (emit->pass == MP_PASS_EMIT) {
void *f = mp_asm_base_get_code(&emit->as.base);
mp_emit_glue_assign_native(emit->scope->raw_code, MP_CODE_NATIVE_ASM, f,
mp_asm_base_get_code_size(&emit->as.base), NULL, emit->scope->num_pos_args, 0, type_sig);
}
}
STATIC mp_uint_t emit_inline_xtensa_count_params(emit_inline_asm_t *emit, mp_uint_t n_params, mp_parse_node_t *pn_params) {