Damien George | 04b9147 | 2014-05-03 23:27:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the Micro Python project, http://micropython.org/ |
| 3 | * |
| 4 | * The MIT License (MIT) |
| 5 | * |
| 6 | * Copyright (c) 2013, 2014 Damien P. George |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | * of this software and associated documentation files (the "Software"), to deal |
| 10 | * in the Software without restriction, including without limitation the rights |
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | * copies of the Software, and to permit persons to whom the Software is |
| 13 | * furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included in |
| 16 | * all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | * THE SOFTWARE. |
| 25 | */ |
| 26 | |
Damien George | 51dfcb4 | 2015-01-01 20:27:54 +0000 | [diff] [blame] | 27 | #ifndef __MICROPY_INCLUDED_PY_EMIT_H__ |
| 28 | #define __MICROPY_INCLUDED_PY_EMIT_H__ |
| 29 | |
| 30 | #include "py/lexer.h" |
| 31 | #include "py/scope.h" |
| 32 | #include "py/runtime0.h" |
| 33 | |
Damien | 429d719 | 2013-10-04 19:53:11 +0100 | [diff] [blame] | 34 | /* Notes on passes: |
| 35 | * We don't know exactly the opcodes in pass 1 because they depend on the |
| 36 | * closing over of variables (LOAD_CLOSURE, BUILD_TUPLE, MAKE_CLOSURE), which |
| 37 | * depends on determining the scope of variables in each function, and this |
| 38 | * is not known until the end of pass 1. |
| 39 | * As a consequence, we don't know the maximum stack size until the end of pass 2. |
| 40 | * This is problematic for some emitters (x64) since they need to know the maximum |
Paul Sokolovsky | fe039b4 | 2014-01-06 17:49:21 +0200 | [diff] [blame] | 41 | * stack size to compile the entry to the function, and this affects code size. |
Damien | 429d719 | 2013-10-04 19:53:11 +0100 | [diff] [blame] | 42 | */ |
| 43 | |
| 44 | typedef enum { |
Damien George | 36db6bc | 2014-05-07 17:24:22 +0100 | [diff] [blame] | 45 | MP_PASS_SCOPE = 1, // work out id's and their kind, and number of labels |
| 46 | MP_PASS_STACK_SIZE = 2, // work out maximum stack size |
| 47 | MP_PASS_CODE_SIZE = 3, // work out code size and label offsets |
| 48 | MP_PASS_EMIT = 4, // emit code |
Damien | 429d719 | 2013-10-04 19:53:11 +0100 | [diff] [blame] | 49 | } pass_kind_t; |
| 50 | |
Damien George | 922ddd6 | 2014-04-09 12:43:17 +0100 | [diff] [blame] | 51 | #define MP_EMIT_STAR_FLAG_SINGLE (0x01) |
| 52 | #define MP_EMIT_STAR_FLAG_DOUBLE (0x02) |
| 53 | |
Damien George | 25c8464 | 2014-05-30 15:20:41 +0100 | [diff] [blame] | 54 | #define MP_EMIT_BREAK_FROM_FOR (0x8000) |
| 55 | |
Damien George | 2ac4af6 | 2014-08-15 16:45:41 +0100 | [diff] [blame] | 56 | #define MP_EMIT_NATIVE_TYPE_ENABLE (0) |
| 57 | #define MP_EMIT_NATIVE_TYPE_RETURN (1) |
| 58 | #define MP_EMIT_NATIVE_TYPE_ARG (2) |
| 59 | |
Damien | 415eb6f | 2013-10-05 12:19:06 +0100 | [diff] [blame] | 60 | typedef struct _emit_t emit_t; |
Damien | 429d719 | 2013-10-04 19:53:11 +0100 | [diff] [blame] | 61 | |
Damien George | 542bd6b | 2015-03-26 14:42:40 +0000 | [diff] [blame] | 62 | typedef struct _mp_emit_method_table_id_ops_t { |
| 63 | void (*fast)(emit_t *emit, qstr qst, mp_uint_t local_num); |
| 64 | void (*deref)(emit_t *emit, qstr qst, mp_uint_t local_num); |
| 65 | void (*name)(emit_t *emit, qstr qst); |
| 66 | void (*global)(emit_t *emit, qstr qst); |
| 67 | } mp_emit_method_table_id_ops_t; |
| 68 | |
Damien | 415eb6f | 2013-10-05 12:19:06 +0100 | [diff] [blame] | 69 | typedef struct _emit_method_table_t { |
Damien George | 2ac4af6 | 2014-08-15 16:45:41 +0100 | [diff] [blame] | 70 | void (*set_native_type)(emit_t *emit, mp_uint_t op, mp_uint_t arg1, qstr arg2); |
Damien | 415eb6f | 2013-10-05 12:19:06 +0100 | [diff] [blame] | 71 | void (*start_pass)(emit_t *emit, pass_kind_t pass, scope_t *scope); |
| 72 | void (*end_pass)(emit_t *emit); |
| 73 | bool (*last_emit_was_return_value)(emit_t *emit); |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 74 | void (*adjust_stack_size)(emit_t *emit, mp_int_t delta); |
Damien George | 4112590 | 2015-03-26 16:44:14 +0000 | [diff] [blame] | 75 | void (*set_source_line)(emit_t *emit, mp_uint_t line); |
Damien | 429d719 | 2013-10-04 19:53:11 +0100 | [diff] [blame] | 76 | |
Damien George | 542bd6b | 2015-03-26 14:42:40 +0000 | [diff] [blame] | 77 | mp_emit_method_table_id_ops_t load_id; |
| 78 | mp_emit_method_table_id_ops_t store_id; |
| 79 | mp_emit_method_table_id_ops_t delete_id; |
Damien | 4b03e77 | 2013-10-05 14:17:09 +0100 | [diff] [blame] | 80 | |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 81 | void (*label_assign)(emit_t *emit, mp_uint_t l); |
| 82 | void (*import_name)(emit_t *emit, qstr qst); |
| 83 | void (*import_from)(emit_t *emit, qstr qst); |
Damien | 415eb6f | 2013-10-05 12:19:06 +0100 | [diff] [blame] | 84 | void (*import_star)(emit_t *emit); |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 85 | void (*load_const_tok)(emit_t *emit, mp_token_kind_t tok); |
Damien George | 40f3c02 | 2014-07-03 13:25:24 +0100 | [diff] [blame] | 86 | void (*load_const_small_int)(emit_t *emit, mp_int_t arg); |
Damien George | 59fba2d | 2015-06-25 14:42:13 +0000 | [diff] [blame] | 87 | void (*load_const_str)(emit_t *emit, qstr qst); |
Damien George | 5d66b42 | 2015-11-27 12:41:25 +0000 | [diff] [blame] | 88 | void (*load_const_obj)(emit_t *emit, mp_obj_t obj); |
Damien George | 3558f62 | 2014-04-20 17:50:40 +0100 | [diff] [blame] | 89 | void (*load_null)(emit_t *emit); |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 90 | void (*load_attr)(emit_t *emit, qstr qst); |
| 91 | void (*load_method)(emit_t *emit, qstr qst); |
Damien | 415eb6f | 2013-10-05 12:19:06 +0100 | [diff] [blame] | 92 | void (*load_build_class)(emit_t *emit); |
Damien George | 729f7b4 | 2014-04-17 22:10:53 +0100 | [diff] [blame] | 93 | void (*load_subscr)(emit_t *emit); |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 94 | void (*store_attr)(emit_t *emit, qstr qst); |
Damien | 415eb6f | 2013-10-05 12:19:06 +0100 | [diff] [blame] | 95 | void (*store_subscr)(emit_t *emit); |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 96 | void (*delete_attr)(emit_t *emit, qstr qst); |
Damien | 415eb6f | 2013-10-05 12:19:06 +0100 | [diff] [blame] | 97 | void (*delete_subscr)(emit_t *emit); |
| 98 | void (*dup_top)(emit_t *emit); |
| 99 | void (*dup_top_two)(emit_t *emit); |
| 100 | void (*pop_top)(emit_t *emit); |
| 101 | void (*rot_two)(emit_t *emit); |
| 102 | void (*rot_three)(emit_t *emit); |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 103 | void (*jump)(emit_t *emit, mp_uint_t label); |
Damien George | 63f3832 | 2015-02-28 15:04:06 +0000 | [diff] [blame] | 104 | void (*pop_jump_if)(emit_t *emit, bool cond, mp_uint_t label); |
| 105 | void (*jump_if_or_pop)(emit_t *emit, bool cond, mp_uint_t label); |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 106 | void (*break_loop)(emit_t *emit, mp_uint_t label, mp_uint_t except_depth); |
| 107 | void (*continue_loop)(emit_t *emit, mp_uint_t label, mp_uint_t except_depth); |
| 108 | void (*setup_with)(emit_t *emit, mp_uint_t label); |
Damien George | ce8b4e8 | 2016-04-07 08:50:38 +0100 | [diff] [blame] | 109 | void (*with_cleanup)(emit_t *emit, mp_uint_t label); |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 110 | void (*setup_except)(emit_t *emit, mp_uint_t label); |
| 111 | void (*setup_finally)(emit_t *emit, mp_uint_t label); |
Damien | 415eb6f | 2013-10-05 12:19:06 +0100 | [diff] [blame] | 112 | void (*end_finally)(emit_t *emit); |
Damien George | 2326d52 | 2014-03-27 23:26:35 +0000 | [diff] [blame] | 113 | void (*get_iter)(emit_t *emit); |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 114 | void (*for_iter)(emit_t *emit, mp_uint_t label); |
Damien | 415eb6f | 2013-10-05 12:19:06 +0100 | [diff] [blame] | 115 | void (*for_iter_end)(emit_t *emit); |
| 116 | void (*pop_block)(emit_t *emit); |
| 117 | void (*pop_except)(emit_t *emit); |
Damien George | d17926d | 2014-03-30 13:35:08 +0100 | [diff] [blame] | 118 | void (*unary_op)(emit_t *emit, mp_unary_op_t op); |
| 119 | void (*binary_op)(emit_t *emit, mp_binary_op_t op); |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 120 | void (*build_tuple)(emit_t *emit, mp_uint_t n_args); |
| 121 | void (*build_list)(emit_t *emit, mp_uint_t n_args); |
| 122 | void (*list_append)(emit_t *emit, mp_uint_t list_stack_index); |
| 123 | void (*build_map)(emit_t *emit, mp_uint_t n_args); |
Damien | 415eb6f | 2013-10-05 12:19:06 +0100 | [diff] [blame] | 124 | void (*store_map)(emit_t *emit); |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 125 | void (*map_add)(emit_t *emit, mp_uint_t map_stack_index); |
Damien George | e37dcaa | 2014-12-27 17:07:16 +0000 | [diff] [blame] | 126 | #if MICROPY_PY_BUILTINS_SET |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 127 | void (*build_set)(emit_t *emit, mp_uint_t n_args); |
| 128 | void (*set_add)(emit_t *emit, mp_uint_t set_stack_index); |
Damien George | e37dcaa | 2014-12-27 17:07:16 +0000 | [diff] [blame] | 129 | #endif |
Damien George | 83204f3 | 2014-12-27 17:20:41 +0000 | [diff] [blame] | 130 | #if MICROPY_PY_BUILTINS_SLICE |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 131 | void (*build_slice)(emit_t *emit, mp_uint_t n_args); |
Damien George | 83204f3 | 2014-12-27 17:20:41 +0000 | [diff] [blame] | 132 | #endif |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 133 | void (*unpack_sequence)(emit_t *emit, mp_uint_t n_args); |
| 134 | void (*unpack_ex)(emit_t *emit, mp_uint_t n_left, mp_uint_t n_right); |
| 135 | void (*make_function)(emit_t *emit, scope_t *scope, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults); |
| 136 | void (*make_closure)(emit_t *emit, scope_t *scope, mp_uint_t n_closed_over, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults); |
| 137 | void (*call_function)(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags); |
| 138 | void (*call_method)(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags); |
Damien | 415eb6f | 2013-10-05 12:19:06 +0100 | [diff] [blame] | 139 | void (*return_value)(emit_t *emit); |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 140 | void (*raise_varargs)(emit_t *emit, mp_uint_t n_args); |
Damien | 415eb6f | 2013-10-05 12:19:06 +0100 | [diff] [blame] | 141 | void (*yield_value)(emit_t *emit); |
| 142 | void (*yield_from)(emit_t *emit); |
Damien George | 5f6a25f | 2014-04-20 18:02:27 +0100 | [diff] [blame] | 143 | |
Damien George | b601d95 | 2014-06-30 05:17:25 +0100 | [diff] [blame] | 144 | // these methods are used to control entry to/exit from an exception handler |
| 145 | // they may or may not emit code |
| 146 | void (*start_except_handler)(emit_t *emit); |
| 147 | void (*end_except_handler)(emit_t *emit); |
Damien | 415eb6f | 2013-10-05 12:19:06 +0100 | [diff] [blame] | 148 | } emit_method_table_t; |
| 149 | |
Damien George | 542bd6b | 2015-03-26 14:42:40 +0000 | [diff] [blame] | 150 | void mp_emit_common_get_id_for_load(scope_t *scope, qstr qst); |
| 151 | void mp_emit_common_get_id_for_modification(scope_t *scope, qstr qst); |
| 152 | void mp_emit_common_id_op(emit_t *emit, const mp_emit_method_table_id_ops_t *emit_method_table, scope_t *scope, qstr qst); |
Damien | 415eb6f | 2013-10-05 12:19:06 +0100 | [diff] [blame] | 153 | |
Damien | 6cdd3af | 2013-10-05 18:08:26 +0100 | [diff] [blame] | 154 | extern const emit_method_table_t emit_cpython_method_table; |
| 155 | extern const emit_method_table_t emit_bc_method_table; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 156 | extern const emit_method_table_t emit_native_x64_method_table; |
Damien George | c90f59e | 2014-09-06 23:06:36 +0100 | [diff] [blame] | 157 | extern const emit_method_table_t emit_native_x86_method_table; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 158 | extern const emit_method_table_t emit_native_thumb_method_table; |
Fabian Vogt | fe3d16e | 2014-08-16 22:55:53 +0200 | [diff] [blame] | 159 | extern const emit_method_table_t emit_native_arm_method_table; |
Damien | 6cdd3af | 2013-10-05 18:08:26 +0100 | [diff] [blame] | 160 | |
Damien George | 4112590 | 2015-03-26 16:44:14 +0000 | [diff] [blame] | 161 | extern const mp_emit_method_table_id_ops_t mp_emit_bc_method_table_load_id_ops; |
| 162 | extern const mp_emit_method_table_id_ops_t mp_emit_bc_method_table_store_id_ops; |
| 163 | extern const mp_emit_method_table_id_ops_t mp_emit_bc_method_table_delete_id_ops; |
| 164 | |
Damien George | a210c77 | 2015-03-26 15:49:53 +0000 | [diff] [blame] | 165 | emit_t *emit_cpython_new(void); |
| 166 | emit_t *emit_bc_new(void); |
Damien George | c8b60f0 | 2015-04-20 13:29:31 +0000 | [diff] [blame] | 167 | emit_t *emit_native_x64_new(mp_obj_t *error_slot, mp_uint_t max_num_labels); |
| 168 | emit_t *emit_native_x86_new(mp_obj_t *error_slot, mp_uint_t max_num_labels); |
| 169 | emit_t *emit_native_thumb_new(mp_obj_t *error_slot, mp_uint_t max_num_labels); |
| 170 | emit_t *emit_native_arm_new(mp_obj_t *error_slot, mp_uint_t max_num_labels); |
Damien | 826005c | 2013-10-05 23:17:28 +0100 | [diff] [blame] | 171 | |
Damien George | a210c77 | 2015-03-26 15:49:53 +0000 | [diff] [blame] | 172 | void emit_cpython_set_max_num_labels(emit_t* emit, mp_uint_t max_num_labels); |
| 173 | void emit_bc_set_max_num_labels(emit_t* emit, mp_uint_t max_num_labels); |
| 174 | |
| 175 | void emit_cpython_free(emit_t *emit); |
Damien George | 41d02b6 | 2014-01-24 22:42:28 +0000 | [diff] [blame] | 176 | void emit_bc_free(emit_t *emit); |
| 177 | void emit_native_x64_free(emit_t *emit); |
Damien George | c90f59e | 2014-09-06 23:06:36 +0100 | [diff] [blame] | 178 | void emit_native_x86_free(emit_t *emit); |
Damien George | 41d02b6 | 2014-01-24 22:42:28 +0000 | [diff] [blame] | 179 | void emit_native_thumb_free(emit_t *emit); |
Fabian Vogt | fe3d16e | 2014-08-16 22:55:53 +0200 | [diff] [blame] | 180 | void emit_native_arm_free(emit_t *emit); |
Damien George | 41d02b6 | 2014-01-24 22:42:28 +0000 | [diff] [blame] | 181 | |
Damien George | 4112590 | 2015-03-26 16:44:14 +0000 | [diff] [blame] | 182 | void mp_emit_bc_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope); |
| 183 | void mp_emit_bc_end_pass(emit_t *emit); |
| 184 | bool mp_emit_bc_last_emit_was_return_value(emit_t *emit); |
| 185 | void mp_emit_bc_adjust_stack_size(emit_t *emit, mp_int_t delta); |
| 186 | void mp_emit_bc_set_source_line(emit_t *emit, mp_uint_t line); |
| 187 | |
| 188 | void mp_emit_bc_load_fast(emit_t *emit, qstr qst, mp_uint_t local_num); |
| 189 | void mp_emit_bc_load_deref(emit_t *emit, qstr qst, mp_uint_t local_num); |
| 190 | void mp_emit_bc_load_name(emit_t *emit, qstr qst); |
| 191 | void mp_emit_bc_load_global(emit_t *emit, qstr qst); |
| 192 | void mp_emit_bc_store_fast(emit_t *emit, qstr qst, mp_uint_t local_num); |
| 193 | void mp_emit_bc_store_deref(emit_t *emit, qstr qst, mp_uint_t local_num); |
| 194 | void mp_emit_bc_store_name(emit_t *emit, qstr qst); |
| 195 | void mp_emit_bc_store_global(emit_t *emit, qstr qst); |
| 196 | void mp_emit_bc_delete_fast(emit_t *emit, qstr qst, mp_uint_t local_num); |
| 197 | void mp_emit_bc_delete_deref(emit_t *emit, qstr qst, mp_uint_t local_num); |
| 198 | void mp_emit_bc_delete_name(emit_t *emit, qstr qst); |
| 199 | void mp_emit_bc_delete_global(emit_t *emit, qstr qst); |
| 200 | |
| 201 | void mp_emit_bc_label_assign(emit_t *emit, mp_uint_t l); |
| 202 | void mp_emit_bc_import_name(emit_t *emit, qstr qst); |
| 203 | void mp_emit_bc_import_from(emit_t *emit, qstr qst); |
| 204 | void mp_emit_bc_import_star(emit_t *emit); |
| 205 | void mp_emit_bc_load_const_tok(emit_t *emit, mp_token_kind_t tok); |
| 206 | void mp_emit_bc_load_const_small_int(emit_t *emit, mp_int_t arg); |
Damien George | 59fba2d | 2015-06-25 14:42:13 +0000 | [diff] [blame] | 207 | void mp_emit_bc_load_const_str(emit_t *emit, qstr qst); |
Damien George | 5d66b42 | 2015-11-27 12:41:25 +0000 | [diff] [blame] | 208 | void mp_emit_bc_load_const_obj(emit_t *emit, mp_obj_t obj); |
Damien George | 4112590 | 2015-03-26 16:44:14 +0000 | [diff] [blame] | 209 | void mp_emit_bc_load_null(emit_t *emit); |
| 210 | void mp_emit_bc_load_attr(emit_t *emit, qstr qst); |
| 211 | void mp_emit_bc_load_method(emit_t *emit, qstr qst); |
| 212 | void mp_emit_bc_load_build_class(emit_t *emit); |
| 213 | void mp_emit_bc_load_subscr(emit_t *emit); |
| 214 | void mp_emit_bc_store_attr(emit_t *emit, qstr qst); |
| 215 | void mp_emit_bc_store_subscr(emit_t *emit); |
| 216 | void mp_emit_bc_delete_attr(emit_t *emit, qstr qst); |
| 217 | void mp_emit_bc_delete_subscr(emit_t *emit); |
| 218 | void mp_emit_bc_dup_top(emit_t *emit); |
| 219 | void mp_emit_bc_dup_top_two(emit_t *emit); |
| 220 | void mp_emit_bc_pop_top(emit_t *emit); |
| 221 | void mp_emit_bc_rot_two(emit_t *emit); |
| 222 | void mp_emit_bc_rot_three(emit_t *emit); |
| 223 | void mp_emit_bc_jump(emit_t *emit, mp_uint_t label); |
| 224 | void mp_emit_bc_pop_jump_if(emit_t *emit, bool cond, mp_uint_t label); |
| 225 | void mp_emit_bc_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label); |
| 226 | void mp_emit_bc_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_depth); |
| 227 | #define mp_emit_bc_break_loop mp_emit_bc_unwind_jump |
| 228 | #define mp_emit_bc_continue_loop mp_emit_bc_unwind_jump |
| 229 | void mp_emit_bc_setup_with(emit_t *emit, mp_uint_t label); |
Damien George | ce8b4e8 | 2016-04-07 08:50:38 +0100 | [diff] [blame] | 230 | void mp_emit_bc_with_cleanup(emit_t *emit, mp_uint_t label); |
Damien George | 4112590 | 2015-03-26 16:44:14 +0000 | [diff] [blame] | 231 | void mp_emit_bc_setup_except(emit_t *emit, mp_uint_t label); |
| 232 | void mp_emit_bc_setup_finally(emit_t *emit, mp_uint_t label); |
| 233 | void mp_emit_bc_end_finally(emit_t *emit); |
| 234 | void mp_emit_bc_get_iter(emit_t *emit); |
| 235 | void mp_emit_bc_for_iter(emit_t *emit, mp_uint_t label); |
| 236 | void mp_emit_bc_for_iter_end(emit_t *emit); |
| 237 | void mp_emit_bc_pop_block(emit_t *emit); |
| 238 | void mp_emit_bc_pop_except(emit_t *emit); |
| 239 | void mp_emit_bc_unary_op(emit_t *emit, mp_unary_op_t op); |
| 240 | void mp_emit_bc_binary_op(emit_t *emit, mp_binary_op_t op); |
| 241 | void mp_emit_bc_build_tuple(emit_t *emit, mp_uint_t n_args); |
| 242 | void mp_emit_bc_build_list(emit_t *emit, mp_uint_t n_args); |
| 243 | void mp_emit_bc_list_append(emit_t *emit, mp_uint_t list_stack_index); |
| 244 | void mp_emit_bc_build_map(emit_t *emit, mp_uint_t n_args); |
| 245 | void mp_emit_bc_store_map(emit_t *emit); |
| 246 | void mp_emit_bc_map_add(emit_t *emit, mp_uint_t map_stack_index); |
| 247 | #if MICROPY_PY_BUILTINS_SET |
| 248 | void mp_emit_bc_build_set(emit_t *emit, mp_uint_t n_args); |
| 249 | void mp_emit_bc_set_add(emit_t *emit, mp_uint_t set_stack_index); |
| 250 | #endif |
| 251 | #if MICROPY_PY_BUILTINS_SLICE |
| 252 | void mp_emit_bc_build_slice(emit_t *emit, mp_uint_t n_args); |
| 253 | #endif |
| 254 | void mp_emit_bc_unpack_sequence(emit_t *emit, mp_uint_t n_args); |
| 255 | void mp_emit_bc_unpack_ex(emit_t *emit, mp_uint_t n_left, mp_uint_t n_right); |
| 256 | void mp_emit_bc_make_function(emit_t *emit, scope_t *scope, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults); |
| 257 | void mp_emit_bc_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_closed_over, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults); |
| 258 | void mp_emit_bc_call_function(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags); |
| 259 | void mp_emit_bc_call_method(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags); |
| 260 | void mp_emit_bc_return_value(emit_t *emit); |
| 261 | void mp_emit_bc_raise_varargs(emit_t *emit, mp_uint_t n_args); |
| 262 | void mp_emit_bc_yield_value(emit_t *emit); |
| 263 | void mp_emit_bc_yield_from(emit_t *emit); |
| 264 | void mp_emit_bc_start_except_handler(emit_t *emit); |
| 265 | void mp_emit_bc_end_except_handler(emit_t *emit); |
| 266 | |
Damien | 826005c | 2013-10-05 23:17:28 +0100 | [diff] [blame] | 267 | typedef struct _emit_inline_asm_t emit_inline_asm_t; |
| 268 | |
| 269 | typedef struct _emit_inline_asm_method_table_t { |
Damien George | 8dfbd2d | 2015-02-13 01:00:51 +0000 | [diff] [blame] | 270 | void (*start_pass)(emit_inline_asm_t *emit, pass_kind_t pass, scope_t *scope, mp_obj_t *error_slot); |
Damien George | 8f54c08 | 2016-01-15 15:20:43 +0000 | [diff] [blame] | 271 | void (*end_pass)(emit_inline_asm_t *emit, mp_uint_t type_sig); |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 272 | mp_uint_t (*count_params)(emit_inline_asm_t *emit, mp_uint_t n_params, mp_parse_node_t *pn_params); |
Damien George | 9c5cabb | 2015-03-03 17:08:02 +0000 | [diff] [blame] | 273 | bool (*label)(emit_inline_asm_t *emit, mp_uint_t label_num, qstr label_id); |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 274 | void (*align)(emit_inline_asm_t *emit, mp_uint_t align); |
| 275 | void (*data)(emit_inline_asm_t *emit, mp_uint_t bytesize, mp_uint_t val); |
| 276 | void (*op)(emit_inline_asm_t *emit, qstr op, mp_uint_t n_args, mp_parse_node_t *pn_args); |
Damien | 826005c | 2013-10-05 23:17:28 +0100 | [diff] [blame] | 277 | } emit_inline_asm_method_table_t; |
| 278 | |
| 279 | extern const emit_inline_asm_method_table_t emit_inline_thumb_method_table; |
| 280 | |
Damien George | 7ff996c | 2014-09-08 23:05:16 +0100 | [diff] [blame] | 281 | emit_inline_asm_t *emit_inline_thumb_new(mp_uint_t max_num_labels); |
Damien George | 41d02b6 | 2014-01-24 22:42:28 +0000 | [diff] [blame] | 282 | void emit_inline_thumb_free(emit_inline_asm_t *emit); |
Paul Sokolovsky | 8ab6f90 | 2014-12-25 23:29:19 +0200 | [diff] [blame] | 283 | |
Paul Sokolovsky | 8a8c1fc | 2015-01-01 09:29:28 +0200 | [diff] [blame] | 284 | #if MICROPY_WARNINGS |
| 285 | void mp_emitter_warning(pass_kind_t pass, const char *msg); |
| 286 | #else |
| 287 | #define mp_emitter_warning(pass, msg) |
| 288 | #endif |
| 289 | |
Paul Sokolovsky | 8ab6f90 | 2014-12-25 23:29:19 +0200 | [diff] [blame] | 290 | #endif // __MICROPY_INCLUDED_PY_EMIT_H__ |