LCOV - code coverage report
Current view: top level - py - showbc.c (source / functions) Hit Total Coverage
Test: unix_coverage_v1.22.0-343-g7b050b366.info Lines: 305 310 98.4 %
Date: 2024-04-25 17:00:48 Functions: 3 3 100.0 %
Branches: 154 201 76.6 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * This file is part of the MicroPython 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                 :            : 
      27                 :            : #include <stdio.h>
      28                 :            : #include <assert.h>
      29                 :            : 
      30                 :            : #include "py/bc0.h"
      31                 :            : #include "py/emitglue.h"
      32                 :            : 
      33                 :            : #if MICROPY_DEBUG_PRINTERS
      34                 :            : 
      35                 :            : #define DECODE_UINT { \
      36                 :            :         unum = 0; \
      37                 :            :         do { \
      38                 :            :             unum = (unum << 7) + (*ip & 0x7f); \
      39                 :            :         } while ((*ip++ & 0x80) != 0); \
      40                 :            : }
      41                 :            : 
      42                 :            : #define DECODE_ULABEL \
      43                 :            :     do { \
      44                 :            :         if (ip[0] & 0x80) { \
      45                 :            :             unum = ((ip[0] & 0x7f) | (ip[1] << 7)); \
      46                 :            :             ip += 2; \
      47                 :            :         } else { \
      48                 :            :             unum = ip[0]; \
      49                 :            :             ip += 1; \
      50                 :            :         } \
      51                 :            :     } while (0)
      52                 :            : 
      53                 :            : #define DECODE_SLABEL \
      54                 :            :     do { \
      55                 :            :         if (ip[0] & 0x80) { \
      56                 :            :             unum = ((ip[0] & 0x7f) | (ip[1] << 7)) - 0x4000; \
      57                 :            :             ip += 2; \
      58                 :            :         } else { \
      59                 :            :             unum = ip[0] - 0x40; \
      60                 :            :             ip += 1; \
      61                 :            :         } \
      62                 :            :     } while (0)
      63                 :            : 
      64                 :            : #if MICROPY_EMIT_BYTECODE_USES_QSTR_TABLE
      65                 :            : 
      66                 :            : #define DECODE_QSTR \
      67                 :            :     DECODE_UINT; \
      68                 :            :     qst = qstr_table[unum]
      69                 :            : 
      70                 :            : #else
      71                 :            : 
      72                 :            : #define DECODE_QSTR \
      73                 :            :     DECODE_UINT; \
      74                 :            :     qst = unum;
      75                 :            : 
      76                 :            : #endif
      77                 :            : 
      78                 :            : #define DECODE_PTR \
      79                 :            :     DECODE_UINT; \
      80                 :            :     unum = (mp_uint_t)(uintptr_t)child_table[unum]
      81                 :            : 
      82                 :            : #define DECODE_OBJ \
      83                 :            :     DECODE_UINT; \
      84                 :            :     unum = (mp_uint_t)obj_table[unum]
      85                 :            : 
      86                 :         42 : void mp_bytecode_print(const mp_print_t *print, const mp_raw_code_t *rc, size_t fun_data_len, const mp_module_constants_t *cm) {
      87                 :         42 :     const byte *ip_start = rc->fun_data;
      88                 :         42 :     const byte *ip = rc->fun_data;
      89                 :            : 
      90                 :            :     // Decode prelude
      91         [ +  + ]:         54 :     MP_BC_PRELUDE_SIG_DECODE(ip);
      92         [ +  + ]:         44 :     MP_BC_PRELUDE_SIZE_DECODE(ip);
      93                 :         42 :     const byte *code_info = ip;
      94                 :            : 
      95                 :         42 :     qstr block_name = mp_decode_uint(&code_info);
      96                 :            :     #if MICROPY_EMIT_BYTECODE_USES_QSTR_TABLE
      97                 :         42 :     block_name = cm->qstr_table[block_name];
      98                 :         42 :     qstr source_file = cm->qstr_table[0];
      99                 :            :     #else
     100                 :            :     qstr source_file = cm->source_file;
     101                 :            :     #endif
     102                 :         42 :     mp_printf(print, "File %s, code block '%s' (descriptor: %p, bytecode @%p %u bytes)\n",
     103                 :            :         qstr_str(source_file), qstr_str(block_name), rc, ip_start, (unsigned)fun_data_len);
     104                 :            : 
     105                 :            :     // raw bytecode dump
     106                 :         42 :     size_t prelude_size = ip - ip_start + n_info + n_cell;
     107                 :         42 :     mp_printf(print, "Raw bytecode (code_info_size=%u, bytecode_size=%u):\n",
     108                 :            :         (unsigned)prelude_size, (unsigned)(fun_data_len - prelude_size));
     109         [ +  + ]:       2386 :     for (size_t i = 0; i < fun_data_len; i++) {
     110   [ +  +  +  + ]:       2344 :         if (i > 0 && i % 16 == 0) {
     111                 :        124 :             mp_printf(print, "\n");
     112                 :            :         }
     113                 :       2344 :         mp_printf(print, " %02x", ip_start[i]);
     114                 :            :     }
     115                 :         42 :     mp_printf(print, "\n");
     116                 :            : 
     117                 :            :     // bytecode prelude: arg names (as qstr objects)
     118                 :         42 :     mp_printf(print, "arg names:");
     119         [ +  + ]:         78 :     for (mp_uint_t i = 0; i < n_pos_args + n_kwonly_args; i++) {
     120                 :         36 :         qstr qst = mp_decode_uint(&code_info);
     121                 :            :         #if MICROPY_EMIT_BYTECODE_USES_QSTR_TABLE
     122                 :         36 :         qst = cm->qstr_table[qst];
     123                 :            :         #endif
     124                 :         36 :         mp_printf(print, " %s", qstr_str(qst));
     125                 :            :     }
     126                 :         42 :     mp_printf(print, "\n");
     127                 :            : 
     128                 :         42 :     mp_printf(print, "(N_STATE %u)\n", (unsigned)n_state);
     129                 :         42 :     mp_printf(print, "(N_EXC_STACK %u)\n", (unsigned)n_exc_stack);
     130                 :            : 
     131                 :            :     // skip over code_info
     132                 :         42 :     ip += n_info;
     133                 :         42 :     const byte *line_info_top = ip;
     134                 :            : 
     135                 :            :     // bytecode prelude: initialise closed over variables
     136         [ +  + ]:         50 :     for (size_t i = 0; i < n_cell; ++i) {
     137                 :          8 :         uint local_num = *ip++;
     138                 :          8 :         mp_printf(print, "(INIT_CELL %u)\n", local_num);
     139                 :            :     }
     140                 :            : 
     141                 :            :     // print out line number info
     142                 :            :     {
     143                 :         42 :         mp_int_t bc = 0;
     144                 :         42 :         mp_uint_t source_line = 1;
     145                 :         42 :         mp_printf(print, "  bc=" INT_FMT " line=" UINT_FMT "\n", bc, source_line);
     146         [ +  + ]:        398 :         for (const byte *ci = code_info; ci < line_info_top;) {
     147         [ +  + ]:        356 :             if ((ci[0] & 0x80) == 0) {
     148                 :            :                 // 0b0LLBBBBB encoding
     149                 :        318 :                 bc += ci[0] & 0x1f;
     150                 :        318 :                 source_line += ci[0] >> 5;
     151                 :        318 :                 ci += 1;
     152                 :            :             } else {
     153                 :            :                 // 0b1LLLBBBB 0bLLLLLLLL encoding (l's LSB in second byte)
     154                 :         38 :                 bc += ci[0] & 0xf;
     155                 :         38 :                 source_line += ((ci[0] << 4) & 0x700) | ci[1];
     156                 :         38 :                 ci += 2;
     157                 :            :             }
     158                 :        356 :             mp_printf(print, "  bc=" INT_FMT " line=" UINT_FMT "\n", bc, source_line);
     159                 :            :         }
     160                 :            :     }
     161                 :         42 :     mp_bytecode_print2(print, ip, fun_data_len - prelude_size, rc->children, cm);
     162                 :         42 : }
     163                 :            : 
     164                 :       1202 : const byte *mp_bytecode_print_str(const mp_print_t *print, const byte *ip_start, const byte *ip, mp_raw_code_t *const *child_table, const mp_module_constants_t *cm) {
     165                 :            :     #if MICROPY_EMIT_BYTECODE_USES_QSTR_TABLE
     166                 :       1202 :     const qstr_short_t *qstr_table = cm->qstr_table;
     167                 :            :     #endif
     168                 :       1202 :     const mp_obj_t *obj_table = cm->obj_table;
     169                 :       1202 :     mp_uint_t unum;
     170                 :       1202 :     qstr qst;
     171                 :            : 
     172   [ +  +  +  +  :       1202 :     switch (*ip++) {
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  -  +  +  
             +  +  +  + ]
     173                 :          4 :         case MP_BC_LOAD_CONST_FALSE:
     174                 :          4 :             mp_printf(print, "LOAD_CONST_FALSE");
     175                 :          4 :             break;
     176                 :            : 
     177                 :         56 :         case MP_BC_LOAD_CONST_NONE:
     178                 :         56 :             mp_printf(print, "LOAD_CONST_NONE");
     179                 :         56 :             break;
     180                 :            : 
     181                 :          2 :         case MP_BC_LOAD_CONST_TRUE:
     182                 :          2 :             mp_printf(print, "LOAD_CONST_TRUE");
     183                 :          2 :             break;
     184                 :            : 
     185                 :          6 :         case MP_BC_LOAD_CONST_SMALL_INT: {
     186                 :          6 :             mp_int_t num = 0;
     187         [ +  + ]:          6 :             if ((ip[0] & 0x40) != 0) {
     188                 :            :                 // Number is negative
     189                 :          2 :                 num--;
     190                 :            :             }
     191                 :         12 :             do {
     192                 :         12 :                 num = ((mp_uint_t)num << 7) | (*ip & 0x7f);
     193         [ +  + ]:         12 :             } while ((*ip++ & 0x80) != 0);
     194                 :          6 :             mp_printf(print, "LOAD_CONST_SMALL_INT " INT_FMT, num);
     195                 :          6 :             break;
     196                 :            :         }
     197                 :            : 
     198                 :            :         case MP_BC_LOAD_CONST_STRING:
     199         [ -  + ]:         36 :             DECODE_QSTR;
     200                 :         36 :             mp_printf(print, "LOAD_CONST_STRING '%s'", qstr_str(qst));
     201                 :         36 :             break;
     202                 :            : 
     203                 :            :         case MP_BC_LOAD_CONST_OBJ:
     204         [ -  + ]:         34 :             DECODE_OBJ;
     205                 :         34 :             mp_printf(print, "LOAD_CONST_OBJ %p=", MP_OBJ_TO_PTR(unum));
     206                 :         34 :             mp_obj_print_helper(print, (mp_obj_t)unum, PRINT_REPR);
     207                 :         34 :             break;
     208                 :            : 
     209                 :         10 :         case MP_BC_LOAD_NULL:
     210                 :         10 :             mp_printf(print, "LOAD_NULL");
     211                 :         10 :             break;
     212                 :            : 
     213                 :            :         case MP_BC_LOAD_FAST_N:
     214         [ -  + ]:          4 :             DECODE_UINT;
     215                 :          4 :             mp_printf(print, "LOAD_FAST_N " UINT_FMT, unum);
     216                 :          4 :             break;
     217                 :            : 
     218                 :            :         case MP_BC_LOAD_DEREF:
     219         [ -  + ]:         56 :             DECODE_UINT;
     220                 :         56 :             mp_printf(print, "LOAD_DEREF " UINT_FMT, unum);
     221                 :         56 :             break;
     222                 :            : 
     223                 :            :         case MP_BC_LOAD_NAME:
     224         [ -  + ]:         36 :             DECODE_QSTR;
     225                 :         36 :             mp_printf(print, "LOAD_NAME %s", qstr_str(qst));
     226                 :         36 :             break;
     227                 :            : 
     228                 :            :         case MP_BC_LOAD_GLOBAL:
     229         [ -  + ]:         14 :             DECODE_QSTR;
     230                 :         14 :             mp_printf(print, "LOAD_GLOBAL %s", qstr_str(qst));
     231                 :         14 :             break;
     232                 :            : 
     233                 :            :         case MP_BC_LOAD_ATTR:
     234         [ -  + ]:          4 :             DECODE_QSTR;
     235                 :          4 :             mp_printf(print, "LOAD_ATTR %s", qstr_str(qst));
     236                 :          4 :             break;
     237                 :            : 
     238                 :            :         case MP_BC_LOAD_METHOD:
     239         [ -  + ]:         10 :             DECODE_QSTR;
     240                 :         10 :             mp_printf(print, "LOAD_METHOD %s", qstr_str(qst));
     241                 :         10 :             break;
     242                 :            : 
     243                 :            :         case MP_BC_LOAD_SUPER_METHOD:
     244         [ -  + ]:          2 :             DECODE_QSTR;
     245                 :          2 :             mp_printf(print, "LOAD_SUPER_METHOD %s", qstr_str(qst));
     246                 :          2 :             break;
     247                 :            : 
     248                 :          2 :         case MP_BC_LOAD_BUILD_CLASS:
     249                 :          2 :             mp_printf(print, "LOAD_BUILD_CLASS");
     250                 :          2 :             break;
     251                 :            : 
     252                 :          6 :         case MP_BC_LOAD_SUBSCR:
     253                 :          6 :             mp_printf(print, "LOAD_SUBSCR");
     254                 :          6 :             break;
     255                 :            : 
     256                 :            :         case MP_BC_STORE_FAST_N:
     257         [ -  + ]:          8 :             DECODE_UINT;
     258                 :          8 :             mp_printf(print, "STORE_FAST_N " UINT_FMT, unum);
     259                 :          8 :             break;
     260                 :            : 
     261                 :            :         case MP_BC_STORE_DEREF:
     262         [ -  + ]:         16 :             DECODE_UINT;
     263                 :         16 :             mp_printf(print, "STORE_DEREF " UINT_FMT, unum);
     264                 :         16 :             break;
     265                 :            : 
     266                 :            :         case MP_BC_STORE_NAME:
     267         [ -  + ]:         52 :             DECODE_QSTR;
     268                 :         52 :             mp_printf(print, "STORE_NAME %s", qstr_str(qst));
     269                 :         52 :             break;
     270                 :            : 
     271                 :            :         case MP_BC_STORE_GLOBAL:
     272         [ -  + ]:          2 :             DECODE_QSTR;
     273                 :          2 :             mp_printf(print, "STORE_GLOBAL %s", qstr_str(qst));
     274                 :          2 :             break;
     275                 :            : 
     276                 :            :         case MP_BC_STORE_ATTR:
     277         [ -  + ]:          2 :             DECODE_QSTR;
     278                 :          2 :             mp_printf(print, "STORE_ATTR %s", qstr_str(qst));
     279                 :          2 :             break;
     280                 :            : 
     281                 :          4 :         case MP_BC_STORE_SUBSCR:
     282                 :          4 :             mp_printf(print, "STORE_SUBSCR");
     283                 :          4 :             break;
     284                 :            : 
     285                 :            :         case MP_BC_DELETE_FAST:
     286         [ -  + ]:          2 :             DECODE_UINT;
     287                 :          2 :             mp_printf(print, "DELETE_FAST " UINT_FMT, unum);
     288                 :          2 :             break;
     289                 :            : 
     290                 :            :         case MP_BC_DELETE_DEREF:
     291         [ -  + ]:          2 :             DECODE_UINT;
     292                 :          2 :             mp_printf(print, "DELETE_DEREF " UINT_FMT, unum);
     293                 :          2 :             break;
     294                 :            : 
     295                 :            :         case MP_BC_DELETE_NAME:
     296         [ -  + ]:          2 :             DECODE_QSTR;
     297                 :          2 :             mp_printf(print, "DELETE_NAME %s", qstr_str(qst));
     298                 :          2 :             break;
     299                 :            : 
     300                 :            :         case MP_BC_DELETE_GLOBAL:
     301         [ -  + ]:          2 :             DECODE_QSTR;
     302                 :          2 :             mp_printf(print, "DELETE_GLOBAL %s", qstr_str(qst));
     303                 :          2 :             break;
     304                 :            : 
     305                 :         40 :         case MP_BC_DUP_TOP:
     306                 :         40 :             mp_printf(print, "DUP_TOP");
     307                 :         40 :             break;
     308                 :            : 
     309                 :          2 :         case MP_BC_DUP_TOP_TWO:
     310                 :          2 :             mp_printf(print, "DUP_TOP_TWO");
     311                 :          2 :             break;
     312                 :            : 
     313                 :         88 :         case MP_BC_POP_TOP:
     314                 :         88 :             mp_printf(print, "POP_TOP");
     315                 :         88 :             break;
     316                 :            : 
     317                 :          6 :         case MP_BC_ROT_TWO:
     318                 :          6 :             mp_printf(print, "ROT_TWO");
     319                 :          6 :             break;
     320                 :            : 
     321                 :          6 :         case MP_BC_ROT_THREE:
     322                 :          6 :             mp_printf(print, "ROT_THREE");
     323                 :          6 :             break;
     324                 :            : 
     325                 :         38 :         case MP_BC_JUMP:
     326         [ -  + ]:         38 :             DECODE_SLABEL;
     327                 :         38 :             mp_printf(print, "JUMP " UINT_FMT, (mp_uint_t)(ip + unum - ip_start));
     328                 :         38 :             break;
     329                 :            : 
     330                 :         10 :         case MP_BC_POP_JUMP_IF_TRUE:
     331         [ -  + ]:         10 :             DECODE_SLABEL;
     332                 :         10 :             mp_printf(print, "POP_JUMP_IF_TRUE " UINT_FMT, (mp_uint_t)(ip + unum - ip_start));
     333                 :         10 :             break;
     334                 :            : 
     335                 :         32 :         case MP_BC_POP_JUMP_IF_FALSE:
     336         [ -  + ]:         32 :             DECODE_SLABEL;
     337                 :         32 :             mp_printf(print, "POP_JUMP_IF_FALSE " UINT_FMT, (mp_uint_t)(ip + unum - ip_start));
     338                 :         32 :             break;
     339                 :            : 
     340                 :          2 :         case MP_BC_JUMP_IF_TRUE_OR_POP:
     341         [ -  + ]:          2 :             DECODE_ULABEL;
     342                 :          2 :             mp_printf(print, "JUMP_IF_TRUE_OR_POP " UINT_FMT, (mp_uint_t)(ip + unum - ip_start));
     343                 :          2 :             break;
     344                 :            : 
     345                 :          4 :         case MP_BC_JUMP_IF_FALSE_OR_POP:
     346         [ -  + ]:          4 :             DECODE_ULABEL;
     347                 :          4 :             mp_printf(print, "JUMP_IF_FALSE_OR_POP " UINT_FMT, (mp_uint_t)(ip + unum - ip_start));
     348                 :          4 :             break;
     349                 :            : 
     350                 :          2 :         case MP_BC_SETUP_WITH:
     351         [ -  + ]:          2 :             DECODE_ULABEL; // loop-like labels are always forward
     352                 :          2 :             mp_printf(print, "SETUP_WITH " UINT_FMT, (mp_uint_t)(ip + unum - ip_start));
     353                 :          2 :             break;
     354                 :            : 
     355                 :          2 :         case MP_BC_WITH_CLEANUP:
     356                 :          2 :             mp_printf(print, "WITH_CLEANUP");
     357                 :          2 :             break;
     358                 :            : 
     359                 :          2 :         case MP_BC_UNWIND_JUMP:
     360         [ -  + ]:          2 :             DECODE_SLABEL;
     361                 :          2 :             mp_printf(print, "UNWIND_JUMP " UINT_FMT " %d", (mp_uint_t)(ip + unum - ip_start), *ip);
     362                 :          2 :             ip += 1;
     363                 :          2 :             break;
     364                 :            : 
     365                 :          6 :         case MP_BC_SETUP_EXCEPT:
     366         [ -  + ]:          6 :             DECODE_ULABEL; // except labels are always forward
     367                 :          6 :             mp_printf(print, "SETUP_EXCEPT " UINT_FMT, (mp_uint_t)(ip + unum - ip_start));
     368                 :          6 :             break;
     369                 :            : 
     370                 :          2 :         case MP_BC_SETUP_FINALLY:
     371         [ -  + ]:          2 :             DECODE_ULABEL; // except labels are always forward
     372                 :          2 :             mp_printf(print, "SETUP_FINALLY " UINT_FMT, (mp_uint_t)(ip + unum - ip_start));
     373                 :          2 :             break;
     374                 :            : 
     375                 :         10 :         case MP_BC_END_FINALLY:
     376                 :            :             // if TOS is an exception, reraises the exception (3 values on TOS)
     377                 :            :             // if TOS is an integer, does something else
     378                 :            :             // if TOS is None, just pops it and continues
     379                 :            :             // else error
     380                 :         10 :             mp_printf(print, "END_FINALLY");
     381                 :         10 :             break;
     382                 :            : 
     383                 :          4 :         case MP_BC_GET_ITER:
     384                 :          4 :             mp_printf(print, "GET_ITER");
     385                 :          4 :             break;
     386                 :            : 
     387                 :          8 :         case MP_BC_GET_ITER_STACK:
     388                 :          8 :             mp_printf(print, "GET_ITER_STACK");
     389                 :          8 :             break;
     390                 :            : 
     391                 :         10 :         case MP_BC_FOR_ITER:
     392         [ -  + ]:         10 :             DECODE_ULABEL; // the jump offset if iteration finishes; for labels are always forward
     393                 :         10 :             mp_printf(print, "FOR_ITER " UINT_FMT, (mp_uint_t)(ip + unum - ip_start));
     394                 :         10 :             break;
     395                 :            : 
     396                 :          8 :         case MP_BC_POP_EXCEPT_JUMP:
     397         [ -  + ]:          8 :             DECODE_ULABEL; // these labels are always forward
     398                 :          8 :             mp_printf(print, "POP_EXCEPT_JUMP " UINT_FMT, (mp_uint_t)(ip + unum - ip_start));
     399                 :          8 :             break;
     400                 :            : 
     401                 :            :         case MP_BC_BUILD_TUPLE:
     402         [ -  + ]:         12 :             DECODE_UINT;
     403                 :         12 :             mp_printf(print, "BUILD_TUPLE " UINT_FMT, unum);
     404                 :         12 :             break;
     405                 :            : 
     406                 :            :         case MP_BC_BUILD_LIST:
     407         [ -  + ]:          4 :             DECODE_UINT;
     408                 :          4 :             mp_printf(print, "BUILD_LIST " UINT_FMT, unum);
     409                 :          4 :             break;
     410                 :            : 
     411                 :            :         case MP_BC_BUILD_MAP:
     412         [ -  + ]:          6 :             DECODE_UINT;
     413                 :          6 :             mp_printf(print, "BUILD_MAP " UINT_FMT, unum);
     414                 :          6 :             break;
     415                 :            : 
     416                 :          2 :         case MP_BC_STORE_MAP:
     417                 :          2 :             mp_printf(print, "STORE_MAP");
     418                 :          2 :             break;
     419                 :            : 
     420                 :            :         case MP_BC_BUILD_SET:
     421         [ -  + ]:          2 :             DECODE_UINT;
     422                 :          2 :             mp_printf(print, "BUILD_SET " UINT_FMT, unum);
     423                 :          2 :             break;
     424                 :            : 
     425                 :            :         #if MICROPY_PY_BUILTINS_SLICE
     426                 :            :         case MP_BC_BUILD_SLICE:
     427         [ -  + ]:          2 :             DECODE_UINT;
     428                 :          2 :             mp_printf(print, "BUILD_SLICE " UINT_FMT, unum);
     429                 :          2 :             break;
     430                 :            :         #endif
     431                 :            : 
     432                 :            :         case MP_BC_STORE_COMP:
     433         [ -  + ]:          4 :             DECODE_UINT;
     434                 :          4 :             mp_printf(print, "STORE_COMP " UINT_FMT, unum);
     435                 :          4 :             break;
     436                 :            : 
     437                 :            :         case MP_BC_UNPACK_SEQUENCE:
     438         [ -  + ]:          2 :             DECODE_UINT;
     439                 :          2 :             mp_printf(print, "UNPACK_SEQUENCE " UINT_FMT, unum);
     440                 :          2 :             break;
     441                 :            : 
     442                 :            :         case MP_BC_UNPACK_EX:
     443         [ -  + ]:          2 :             DECODE_UINT;
     444                 :          2 :             mp_printf(print, "UNPACK_EX " UINT_FMT, unum);
     445                 :          2 :             break;
     446                 :            : 
     447                 :            :         case MP_BC_MAKE_FUNCTION:
     448         [ -  + ]:         20 :             DECODE_PTR;
     449                 :         20 :             mp_printf(print, "MAKE_FUNCTION %p", (void *)(uintptr_t)unum);
     450                 :         20 :             break;
     451                 :            : 
     452                 :            :         case MP_BC_MAKE_FUNCTION_DEFARGS:
     453         [ -  + ]:          2 :             DECODE_PTR;
     454                 :          2 :             mp_printf(print, "MAKE_FUNCTION_DEFARGS %p", (void *)(uintptr_t)unum);
     455                 :          2 :             break;
     456                 :            : 
     457                 :            :         case MP_BC_MAKE_CLOSURE: {
     458         [ -  + ]:          8 :             DECODE_PTR;
     459                 :          8 :             mp_uint_t n_closed_over = *ip++;
     460                 :          8 :             mp_printf(print, "MAKE_CLOSURE %p " UINT_FMT, (void *)(uintptr_t)unum, n_closed_over);
     461                 :          8 :             break;
     462                 :            :         }
     463                 :            : 
     464                 :            :         case MP_BC_MAKE_CLOSURE_DEFARGS: {
     465         [ -  + ]:          2 :             DECODE_PTR;
     466                 :          2 :             mp_uint_t n_closed_over = *ip++;
     467                 :          2 :             mp_printf(print, "MAKE_CLOSURE_DEFARGS %p " UINT_FMT, (void *)(uintptr_t)unum, n_closed_over);
     468                 :          2 :             break;
     469                 :            :         }
     470                 :            : 
     471                 :            :         case MP_BC_CALL_FUNCTION:
     472         [ +  + ]:         44 :             DECODE_UINT;
     473                 :         42 :             mp_printf(print, "CALL_FUNCTION n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
     474                 :         42 :             break;
     475                 :            : 
     476                 :            :         case MP_BC_CALL_FUNCTION_VAR_KW:
     477         [ -  + ]:          2 :             DECODE_UINT;
     478                 :          2 :             mp_printf(print, "CALL_FUNCTION_VAR_KW n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
     479                 :          2 :             break;
     480                 :            : 
     481                 :            :         case MP_BC_CALL_METHOD:
     482         [ +  + ]:         12 :             DECODE_UINT;
     483                 :         10 :             mp_printf(print, "CALL_METHOD n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
     484                 :         10 :             break;
     485                 :            : 
     486                 :            :         case MP_BC_CALL_METHOD_VAR_KW:
     487         [ -  + ]:          2 :             DECODE_UINT;
     488                 :          2 :             mp_printf(print, "CALL_METHOD_VAR_KW n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
     489                 :          2 :             break;
     490                 :            : 
     491                 :         46 :         case MP_BC_RETURN_VALUE:
     492                 :         46 :             mp_printf(print, "RETURN_VALUE");
     493                 :         46 :             break;
     494                 :            : 
     495                 :          2 :         case MP_BC_RAISE_LAST:
     496                 :          2 :             mp_printf(print, "RAISE_LAST");
     497                 :          2 :             break;
     498                 :            : 
     499                 :          6 :         case MP_BC_RAISE_OBJ:
     500                 :          6 :             mp_printf(print, "RAISE_OBJ");
     501                 :          6 :             break;
     502                 :            : 
     503                 :          0 :         case MP_BC_RAISE_FROM:
     504                 :          0 :             mp_printf(print, "RAISE_FROM");
     505                 :          0 :             break;
     506                 :            : 
     507                 :          6 :         case MP_BC_YIELD_VALUE:
     508                 :          6 :             mp_printf(print, "YIELD_VALUE");
     509                 :          6 :             break;
     510                 :            : 
     511                 :          2 :         case MP_BC_YIELD_FROM:
     512                 :          2 :             mp_printf(print, "YIELD_FROM");
     513                 :          2 :             break;
     514                 :            : 
     515                 :            :         case MP_BC_IMPORT_NAME:
     516         [ -  + ]:         10 :             DECODE_QSTR;
     517                 :         10 :             mp_printf(print, "IMPORT_NAME '%s'", qstr_str(qst));
     518                 :         10 :             break;
     519                 :            : 
     520                 :            :         case MP_BC_IMPORT_FROM:
     521         [ -  + ]:          4 :             DECODE_QSTR;
     522                 :          4 :             mp_printf(print, "IMPORT_FROM '%s'", qstr_str(qst));
     523                 :          4 :             break;
     524                 :            : 
     525                 :          2 :         case MP_BC_IMPORT_STAR:
     526                 :          2 :             mp_printf(print, "IMPORT_STAR");
     527                 :          2 :             break;
     528                 :            : 
     529                 :        344 :         default:
     530         [ +  + ]:        344 :             if (ip[-1] < MP_BC_LOAD_CONST_SMALL_INT_MULTI + 64) {
     531                 :         80 :                 mp_printf(print, "LOAD_CONST_SMALL_INT " INT_FMT, (mp_int_t)ip[-1] - MP_BC_LOAD_CONST_SMALL_INT_MULTI - 16);
     532         [ +  + ]:        264 :             } else if (ip[-1] < MP_BC_LOAD_FAST_MULTI + 16) {
     533                 :        116 :                 mp_printf(print, "LOAD_FAST " UINT_FMT, (mp_uint_t)ip[-1] - MP_BC_LOAD_FAST_MULTI);
     534         [ +  + ]:        148 :             } else if (ip[-1] < MP_BC_STORE_FAST_MULTI + 16) {
     535                 :        108 :                 mp_printf(print, "STORE_FAST " UINT_FMT, (mp_uint_t)ip[-1] - MP_BC_STORE_FAST_MULTI);
     536         [ +  + ]:         40 :             } else if (ip[-1] < MP_BC_UNARY_OP_MULTI + MP_UNARY_OP_NUM_BYTECODE) {
     537                 :          6 :                 mp_uint_t op = ip[-1] - MP_BC_UNARY_OP_MULTI;
     538                 :          6 :                 mp_printf(print, "UNARY_OP " UINT_FMT " %s", op, qstr_str(mp_unary_op_method_name[op]));
     539         [ +  - ]:         34 :             } else if (ip[-1] < MP_BC_BINARY_OP_MULTI + MP_BINARY_OP_NUM_BYTECODE) {
     540                 :         34 :                 mp_uint_t op = ip[-1] - MP_BC_BINARY_OP_MULTI;
     541                 :         34 :                 mp_printf(print, "BINARY_OP " UINT_FMT " %s", op, qstr_str(mp_binary_op_method_name[op]));
     542                 :            :             } else {
     543                 :          0 :                 mp_printf(print, "code %p, byte code 0x%02x not implemented\n", ip - 1, ip[-1]);
     544                 :          0 :                 assert(0);
     545                 :            :                 return ip;
     546                 :            :             }
     547                 :            :             break;
     548                 :            :     }
     549                 :            : 
     550                 :       1202 :     return ip;
     551                 :            : }
     552                 :            : 
     553                 :         42 : void mp_bytecode_print2(const mp_print_t *print, const byte *ip, size_t len, mp_raw_code_t *const *child_table, const mp_module_constants_t *cm) {
     554                 :         42 :     const byte *ip_start = ip;
     555         [ +  + ]:       1244 :     while (ip < ip_start + len) {
     556                 :       1202 :         mp_printf(print, "%02u ", (uint)(ip - ip_start));
     557                 :       1202 :         ip = mp_bytecode_print_str(print, ip_start, ip, child_table, cm);
     558                 :       1202 :         mp_printf(print, "\n");
     559                 :            :     }
     560                 :         42 : }
     561                 :            : 
     562                 :            : #endif // MICROPY_DEBUG_PRINTERS

Generated by: LCOV version 1.15-5-g462f71d