@@ -86,6 +86,16 @@ typedef enum {
8686#endif
8787#endif
8888
89+ #if MICROPY_EMIT_INLINE_ASM
90+ // define macros for inline assembler
91+ #if MICROPY_EMIT_INLINE_THUMB
92+ #define ASM_DECORATOR_QSTR MP_QSTR_asm_thumb
93+ #define ASM_EMITTER (f ) emit_inline_thumb_##f
94+ #else
95+ #error "unknown asm emitter"
96+ #endif
97+ #endif
98+
8999#define EMIT_INLINE_ASM (fun ) (comp->emit_inline_asm_method_table->fun(comp->emit_inline_asm))
90100#define EMIT_INLINE_ASM_ARG (fun , ...) (comp->emit_inline_asm_method_table->fun(comp->emit_inline_asm, __VA_ARGS__))
91101
@@ -120,7 +130,7 @@ typedef struct _compiler_t {
120130 const emit_method_table_t * emit_method_table ; // current emit method table
121131 #endif
122132
123- #if MICROPY_EMIT_INLINE_THUMB
133+ #if MICROPY_EMIT_INLINE_ASM
124134 emit_inline_asm_t * emit_inline_asm ; // current emitter for inline asm
125135 const emit_inline_asm_method_table_t * emit_inline_asm_method_table ; // current emit method table for inline asm
126136 #endif
@@ -767,10 +777,10 @@ STATIC bool compile_built_in_decorator(compiler_t *comp, int name_len, mp_parse_
767777 } else if (attr == MP_QSTR_viper ) {
768778 * emit_options = MP_EMIT_OPT_VIPER ;
769779#endif
770- #if MICROPY_EMIT_INLINE_THUMB
771- } else if (attr == MP_QSTR_asm_thumb ) {
772- * emit_options = MP_EMIT_OPT_ASM_THUMB ;
773- #endif
780+ #if MICROPY_EMIT_INLINE_ASM
781+ } else if (attr == ASM_DECORATOR_QSTR ) {
782+ * emit_options = MP_EMIT_OPT_ASM ;
783+ #endif
774784 } else {
775785 compile_syntax_error (comp , name_nodes [1 ], "invalid micropython decorator" );
776786 }
@@ -3100,7 +3110,7 @@ STATIC void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
31003110 assert (comp -> cur_except_level == 0 );
31013111}
31023112
3103- #if MICROPY_EMIT_INLINE_THUMB
3113+ #if MICROPY_EMIT_INLINE_ASM
31043114// requires 3 passes: SCOPE, CODE_SIZE, EMIT
31053115STATIC void compile_scope_inline_asm (compiler_t * comp , scope_t * scope , pass_kind_t pass ) {
31063116 comp -> pass = pass ;
@@ -3357,10 +3367,10 @@ mp_raw_code_t *mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_f
33573367 uint max_num_labels = 0 ;
33583368 for (scope_t * s = comp -> scope_head ; s != NULL && comp -> compile_error == MP_OBJ_NULL ; s = s -> next ) {
33593369 if (false) {
3360- #if MICROPY_EMIT_INLINE_THUMB
3361- } else if (s -> emit_options == MP_EMIT_OPT_ASM_THUMB ) {
3370+ #if MICROPY_EMIT_INLINE_ASM
3371+ } else if (s -> emit_options == MP_EMIT_OPT_ASM ) {
33623372 compile_scope_inline_asm (comp , s , MP_PASS_SCOPE );
3363- #endif
3373+ #endif
33643374 } else {
33653375 compile_scope (comp , s , MP_PASS_SCOPE );
33663376 }
@@ -3382,28 +3392,24 @@ mp_raw_code_t *mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_f
33823392 // compile pass 2 and 3
33833393#if MICROPY_EMIT_NATIVE
33843394 emit_t * emit_native = NULL ;
3385- #endif
3386- #if MICROPY_EMIT_INLINE_THUMB
3387- emit_inline_asm_t * emit_inline_thumb = NULL ;
33883395#endif
33893396 for (scope_t * s = comp -> scope_head ; s != NULL && comp -> compile_error == MP_OBJ_NULL ; s = s -> next ) {
33903397 if (false) {
33913398 // dummy
33923399
3393- #if MICROPY_EMIT_INLINE_THUMB
3394- } else if (s -> emit_options == MP_EMIT_OPT_ASM_THUMB ) {
3395- // inline assembly for thumb
3396- if (emit_inline_thumb == NULL ) {
3397- emit_inline_thumb = emit_inline_thumb_new (max_num_labels );
3400+ #if MICROPY_EMIT_INLINE_ASM
3401+ } else if (s -> emit_options == MP_EMIT_OPT_ASM ) {
3402+ // inline assembly
3403+ if (comp -> emit_inline_asm == NULL ) {
3404+ comp -> emit_inline_asm = ASM_EMITTER ( new ) (max_num_labels );
33983405 }
33993406 comp -> emit = NULL ;
3400- comp -> emit_inline_asm = emit_inline_thumb ;
3401- comp -> emit_inline_asm_method_table = & emit_inline_thumb_method_table ;
3407+ comp -> emit_inline_asm_method_table = & ASM_EMITTER (method_table );
34023408 compile_scope_inline_asm (comp , s , MP_PASS_CODE_SIZE );
34033409 if (comp -> compile_error == MP_OBJ_NULL ) {
34043410 compile_scope_inline_asm (comp , s , MP_PASS_EMIT );
34053411 }
3406- #endif
3412+ #endif
34073413
34083414 } else {
34093415
@@ -3463,11 +3469,11 @@ mp_raw_code_t *mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_f
34633469 NATIVE_EMITTER (free )(emit_native );
34643470 }
34653471#endif
3466- #if MICROPY_EMIT_INLINE_THUMB
3467- if (emit_inline_thumb != NULL ) {
3468- emit_inline_thumb_free ( emit_inline_thumb );
3472+ #if MICROPY_EMIT_INLINE_ASM
3473+ if (comp -> emit_inline_asm != NULL ) {
3474+ ASM_EMITTER ( free )( comp -> emit_inline_asm );
34693475 }
3470- #endif
3476+ #endif
34713477
34723478 // free the parse tree
34733479 mp_parse_tree_clear (parse_tree );
0 commit comments