@@ -44,20 +44,19 @@ typedef enum {
4444
4545struct _emit_inline_asm_t {
4646 uint16_t pass ;
47- uint16_t success ;
4847 scope_t * scope ;
48+ mp_obj_t * error_slot ;
4949 mp_uint_t max_num_labels ;
5050 qstr * label_lookup ;
5151 asm_thumb_t * as ;
5252};
5353
54- STATIC void emit_inline_thumb_error (emit_inline_asm_t * emit , const char * fmt , ...) {
55- printf ("SyntaxError: " );
56- emit -> success = false;
57- va_list ap ;
58- va_start (ap , fmt );
59- vprintf (fmt , ap );
60- va_end (ap );
54+ STATIC void emit_inline_thumb_error_msg (emit_inline_asm_t * emit , const char * msg ) {
55+ * emit -> error_slot = mp_obj_new_exception_msg (& mp_type_SyntaxError , msg );
56+ }
57+
58+ STATIC void emit_inline_thumb_error_exc (emit_inline_asm_t * emit , mp_obj_t exc ) {
59+ * emit -> error_slot = exc ;
6160}
6261
6362emit_inline_asm_t * emit_inline_thumb_new (mp_uint_t max_num_labels ) {
@@ -75,39 +74,37 @@ void emit_inline_thumb_free(emit_inline_asm_t *emit) {
7574 m_del_obj (emit_inline_asm_t , emit );
7675}
7776
78- STATIC void emit_inline_thumb_start_pass (emit_inline_asm_t * emit , pass_kind_t pass , scope_t * scope ) {
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 ) {
7978 emit -> pass = pass ;
80- emit -> success = true;
8179 emit -> scope = scope ;
80+ emit -> error_slot = error_slot ;
8281 asm_thumb_start_pass (emit -> as , pass == MP_PASS_EMIT ? ASM_THUMB_PASS_EMIT : ASM_THUMB_PASS_COMPUTE );
8382 asm_thumb_entry (emit -> as , 0 );
8483}
8584
86- STATIC bool emit_inline_thumb_end_pass (emit_inline_asm_t * emit ) {
85+ STATIC void emit_inline_thumb_end_pass (emit_inline_asm_t * emit ) {
8786 asm_thumb_exit (emit -> as );
8887 asm_thumb_end_pass (emit -> as );
8988
9089 if (emit -> pass == MP_PASS_EMIT ) {
9190 void * f = asm_thumb_get_code (emit -> as );
9291 mp_emit_glue_assign_native (emit -> scope -> raw_code , MP_CODE_NATIVE_ASM , f , asm_thumb_get_code_size (emit -> as ), emit -> scope -> num_pos_args , 0 );
9392 }
94-
95- return emit -> success ;
9693}
9794
9895STATIC mp_uint_t emit_inline_thumb_count_params (emit_inline_asm_t * emit , mp_uint_t n_params , mp_parse_node_t * pn_params ) {
9996 if (n_params > 4 ) {
100- emit_inline_thumb_error (emit , "can only have up to 4 parameters to inline thumb assembly\n " );
97+ emit_inline_thumb_error_msg (emit , "can only have up to 4 parameters to Thumb assembly" );
10198 return 0 ;
10299 }
103100 for (mp_uint_t i = 0 ; i < n_params ; i ++ ) {
104101 if (!MP_PARSE_NODE_IS_ID (pn_params [i ])) {
105- emit_inline_thumb_error (emit , "parameter to inline assembler must be an identifier\n " );
102+ emit_inline_thumb_error_msg (emit , "parameters must be registers in sequence r0 to r3 " );
106103 return 0 ;
107104 }
108105 const char * p = qstr_str (MP_PARSE_NODE_LEAF_ARG (pn_params [i ]));
109106 if (!(strlen (p ) == 2 && p [0 ] == 'r' && p [1 ] == '0' + i )) {
110- emit_inline_thumb_error (emit , "parameter %d to inline assembler must be r%d\n" , i + 1 , i );
107+ emit_inline_thumb_error_msg (emit , "parameters must be registers in sequence r0 to r3" );
111108 return 0 ;
112109 }
113110 }
@@ -161,26 +158,26 @@ STATIC mp_uint_t get_arg_reg(emit_inline_asm_t *emit, const char *op, mp_parse_n
161158 const reg_name_t * r = & reg_name_table [i ];
162159 if (reg_str [0 ] == r -> name [0 ] && reg_str [1 ] == r -> name [1 ] && reg_str [2 ] == r -> name [2 ] && (reg_str [2 ] == '\0' || reg_str [3 ] == '\0' )) {
163160 if (r -> reg > max_reg ) {
164- emit_inline_thumb_error (emit , "'%s' expects at most r%d\n " , op , max_reg );
161+ emit_inline_thumb_error_exc (emit , mp_obj_new_exception_msg_varg ( & mp_type_SyntaxError , "'%s' expects at most r%d" , op , max_reg ) );
165162 return 0 ;
166163 } else {
167164 return r -> reg ;
168165 }
169166 }
170167 }
171168 }
172- emit_inline_thumb_error (emit , "'%s' expects a register\n " , op );
169+ emit_inline_thumb_error_exc (emit , mp_obj_new_exception_msg_varg ( & mp_type_SyntaxError , "'%s' expects a register" , op ) );
173170 return 0 ;
174171}
175172
176173STATIC int get_arg_i (emit_inline_asm_t * emit , const char * op , mp_parse_node_t pn , int fit_mask ) {
177174 if (!MP_PARSE_NODE_IS_SMALL_INT (pn )) {
178- emit_inline_thumb_error (emit , "'%s' expects an integer\n " , op );
175+ emit_inline_thumb_error_exc (emit , mp_obj_new_exception_msg_varg ( & mp_type_SyntaxError , "'%s' expects an integer" , op ) );
179176 return 0 ;
180177 }
181178 int i = MP_PARSE_NODE_LEAF_SMALL_INT (pn );
182179 if ((i & (~fit_mask )) != 0 ) {
183- emit_inline_thumb_error (emit , "'%s' integer 0x%x does not fit in mask 0x%x\n " , op , i , fit_mask );
180+ emit_inline_thumb_error_exc (emit , mp_obj_new_exception_msg_varg ( & mp_type_SyntaxError , "'%s' integer 0x%x does not fit in mask 0x%x" , op , i , fit_mask ) );
184181 return 0 ;
185182 }
186183 return i ;
@@ -204,13 +201,13 @@ STATIC bool get_arg_addr(emit_inline_asm_t *emit, const char *op, mp_parse_node_
204201 return true;
205202
206203bad_arg :
207- emit_inline_thumb_error (emit , "'%s' expects an address of the form [a, b]\n " , op );
204+ emit_inline_thumb_error_exc (emit , mp_obj_new_exception_msg_varg ( & mp_type_SyntaxError , "'%s' expects an address of the form [a, b]" , op ) );
208205 return false;
209206}
210207
211208STATIC int get_arg_label (emit_inline_asm_t * emit , const char * op , mp_parse_node_t pn ) {
212209 if (!MP_PARSE_NODE_IS_ID (pn )) {
213- emit_inline_thumb_error (emit , "'%s' expects a label\n " , op );
210+ emit_inline_thumb_error_exc (emit , mp_obj_new_exception_msg_varg ( & mp_type_SyntaxError , "'%s' expects a label" , op ) );
214211 return 0 ;
215212 }
216213 qstr label_qstr = MP_PARSE_NODE_LEAF_ARG (pn );
@@ -221,7 +218,7 @@ STATIC int get_arg_label(emit_inline_asm_t *emit, const char *op, mp_parse_node_
221218 }
222219 // only need to have the labels on the last pass
223220 if (emit -> pass == MP_PASS_EMIT ) {
224- emit_inline_thumb_error (emit , "label '%s' not defined\n " , qstr_str (label_qstr ));
221+ emit_inline_thumb_error_exc (emit , mp_obj_new_exception_msg_varg ( & mp_type_SyntaxError , "label '%s' not defined" , qstr_str (label_qstr ) ));
225222 }
226223 return 0 ;
227224}
@@ -450,7 +447,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
450447 return ;
451448
452449unknown_op :
453- emit_inline_thumb_error (emit , "unsupported Thumb instruction '%s' with %d arguments\n " , op_str , n_args );
450+ emit_inline_thumb_error_exc (emit , mp_obj_new_exception_msg_varg ( & mp_type_SyntaxError , "unsupported Thumb instruction '%s' with %d arguments" , op_str , n_args ) );
454451}
455452
456453const emit_inline_asm_method_table_t emit_inline_thumb_method_table = {
0 commit comments