Skip to content

Commit e920bab

Browse files
committed
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.
1 parent dd53b12 commit e920bab

4 files changed

Lines changed: 11 additions & 20 deletions

File tree

py/compile.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3127,7 +3127,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
31273127
}
31283128

31293129
if (comp->pass > MP_PASS_SCOPE) {
3130-
EMIT_INLINE_ASM_ARG(start_pass, comp->pass, comp->scope_cur, &comp->compile_error);
3130+
EMIT_INLINE_ASM_ARG(start_pass, comp->pass, &comp->compile_error);
31313131
}
31323132

31333133
// get the function definition parse node
@@ -3258,6 +3258,13 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
32583258

32593259
if (comp->pass > MP_PASS_SCOPE) {
32603260
EMIT_INLINE_ASM_ARG(end_pass, type_sig);
3261+
3262+
if (comp->pass == MP_PASS_EMIT) {
3263+
void *f = mp_asm_base_get_code((mp_asm_base_t*)comp->emit_inline_asm);
3264+
mp_emit_glue_assign_native(comp->scope_cur->raw_code, MP_CODE_NATIVE_ASM,
3265+
f, mp_asm_base_get_code_size((mp_asm_base_t*)comp->emit_inline_asm),
3266+
NULL, comp->scope_cur->num_pos_args, 0, type_sig);
3267+
}
32613268
}
32623269

32633270
if (comp->compile_error != MP_OBJ_NULL) {

py/emit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ void mp_emit_bc_end_except_handler(emit_t *emit);
262262
typedef struct _emit_inline_asm_t emit_inline_asm_t;
263263

264264
typedef struct _emit_inline_asm_method_table_t {
265-
void (*start_pass)(emit_inline_asm_t *emit, pass_kind_t pass, scope_t *scope, mp_obj_t *error_slot);
265+
void (*start_pass)(emit_inline_asm_t *emit, pass_kind_t pass, mp_obj_t *error_slot);
266266
void (*end_pass)(emit_inline_asm_t *emit, mp_uint_t type_sig);
267267
mp_uint_t (*count_params)(emit_inline_asm_t *emit, mp_uint_t n_params, mp_parse_node_t *pn_params);
268268
bool (*label)(emit_inline_asm_t *emit, mp_uint_t label_num, qstr label_id);

py/emitinlinethumb.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ typedef enum {
4545
struct _emit_inline_asm_t {
4646
asm_thumb_t as;
4747
uint16_t pass;
48-
scope_t *scope;
4948
mp_obj_t *error_slot;
5049
mp_uint_t max_num_labels;
5150
qstr *label_lookup;
@@ -74,9 +73,8 @@ void emit_inline_thumb_free(emit_inline_asm_t *emit) {
7473
m_del_obj(emit_inline_asm_t, emit);
7574
}
7675

77-
STATIC void emit_inline_thumb_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, scope_t *scope, mp_obj_t *error_slot) {
76+
STATIC void emit_inline_thumb_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, mp_obj_t *error_slot) {
7877
emit->pass = pass;
79-
emit->scope = scope;
8078
emit->error_slot = error_slot;
8179
if (emit->pass == MP_PASS_CODE_SIZE) {
8280
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
8886
STATIC void emit_inline_thumb_end_pass(emit_inline_asm_t *emit, mp_uint_t type_sig) {
8987
asm_thumb_exit(&emit->as);
9088
asm_thumb_end_pass(&emit->as);
91-
92-
if (emit->pass == MP_PASS_EMIT) {
93-
void *f = mp_asm_base_get_code(&emit->as.base);
94-
mp_emit_glue_assign_native(emit->scope->raw_code, MP_CODE_NATIVE_ASM, f,
95-
mp_asm_base_get_code_size(&emit->as.base), NULL, emit->scope->num_pos_args, 0, type_sig);
96-
}
9789
}
9890

9991
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) {

py/emitinlinextensa.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
struct _emit_inline_asm_t {
3939
asm_xtensa_t as;
4040
uint16_t pass;
41-
scope_t *scope;
4241
mp_obj_t *error_slot;
4342
mp_uint_t max_num_labels;
4443
qstr *label_lookup;
@@ -67,9 +66,8 @@ void emit_inline_xtensa_free(emit_inline_asm_t *emit) {
6766
m_del_obj(emit_inline_asm_t, emit);
6867
}
6968

70-
STATIC void emit_inline_xtensa_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, scope_t *scope, mp_obj_t *error_slot) {
69+
STATIC void emit_inline_xtensa_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, mp_obj_t *error_slot) {
7170
emit->pass = pass;
72-
emit->scope = scope;
7371
emit->error_slot = error_slot;
7472
if (emit->pass == MP_PASS_CODE_SIZE) {
7573
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
8179
STATIC void emit_inline_xtensa_end_pass(emit_inline_asm_t *emit, mp_uint_t type_sig) {
8280
asm_xtensa_exit(&emit->as);
8381
asm_xtensa_end_pass(&emit->as);
84-
85-
if (emit->pass == MP_PASS_EMIT) {
86-
void *f = mp_asm_base_get_code(&emit->as.base);
87-
mp_emit_glue_assign_native(emit->scope->raw_code, MP_CODE_NATIVE_ASM, f,
88-
mp_asm_base_get_code_size(&emit->as.base), NULL, emit->scope->num_pos_args, 0, type_sig);
89-
}
9082
}
9183

9284
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) {

0 commit comments

Comments
 (0)