1# (C) Copyright 2019-2020 by Rocky Bernstein
2#
3#  This program is free software; you can redistribute it and/or
4#  modify it under the terms of the GNU General Public License
5#  as published by the Free Software Foundation; either version 2
6#  of the License, or (at your option) any later version.
7#
8#  This program is distributed in the hope that it will be useful,
9#  but WITHOUT ANY WARRANTY; without even the implied warranty of
10#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11#  GNU General Public License for more details.
12#
13#  You should have received a copy of the GNU General Public License
14#  along with this program; if not, write to the Free Software
15#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16"""
17CPython 1.0 bytecode opcodes
18
19This is used in bytecode disassembly. This is similar to the
20opcodes in Python's dis.py library.
21"""
22
23# This is used from outside this module
24from xdis.cross_dis import findlabels  # noqa
25
26import xdis.opcodes.opcode_11 as opcode_11
27from xdis.opcodes.base import (
28    extended_format_CALL_FUNCTION,
29    extended_format_RAISE_VARARGS_older,
30    extended_format_RETURN_VALUE,
31    format_RAISE_VARARGS_older,
32    init_opdata,
33    rm_op,
34    finalize_opcodes,
35    format_extended_arg,
36    # Although these aren't used here, they are exported
37    update_pj2,
38)
39
40version = 1.0
41python_implementation = "CPython"
42
43l = locals()
44init_opdata(l, opcode_11, version)
45
46# fmt: off
47# 1.0 - 1.1 bytecodes differences
48rm_op(l, "LOAD_GLOBALS", 84)
49rm_op(l, "EXEC_STMT", 85)
50# fmt: on
51
52update_pj2(globals(), l)
53
54opcode_arg_fmt = {
55    "EXTENDED_ARG": format_extended_arg,
56    "RAISE_VARARGS": format_RAISE_VARARGS_older,
57}
58
59finalize_opcodes(l)
60
61opcode_extended_fmt = {
62    "CALL_FUNCTION": extended_format_CALL_FUNCTION,
63    "RAISE_VARARGS": extended_format_RAISE_VARARGS_older,
64    "RETURN_VALUE": extended_format_RETURN_VALUE,
65}
66
67findlinestarts = opcode_11.findlinestarts
68