cpython/Python/assemble.c

#include <stdbool.h>

#include "Python.h"
#include "pycore_code.h"            // write_location_entry_start()
#include "pycore_compile.h"
#include "pycore_instruction_sequence.h"
#include "pycore_opcode_utils.h"    // IS_BACKWARDS_JUMP_OPCODE
#include "pycore_opcode_metadata.h" // is_pseudo_target, _PyOpcode_Caches
#include "pycore_symtable.h"        // _Py_SourceLocation


#define DEFAULT_CODE_SIZE
#define DEFAULT_LNOTAB_SIZE
#define DEFAULT_CNOTAB_SIZE

#undef SUCCESS
#undef ERROR
#define SUCCESS
#define ERROR

#define RETURN_IF_ERROR(X)

location;
instruction;
instr_sequence;

static inline bool
same_location(location a, location b)
{}

static int
instr_size(instruction *instr)
{}

struct assembler {};

static int
assemble_init(struct assembler *a, int firstlineno)
{}

static void
assemble_free(struct assembler *a)
{}

static inline void
write_except_byte(struct assembler *a, int byte) {}

#define CONTINUATION_BIT

static void
assemble_emit_exception_table_item(struct assembler *a, int value, int msb)
{}

/* See Objects/exception_handling_notes.txt for details of layout */
#define MAX_SIZE_OF_ENTRY

static int
assemble_emit_exception_table_entry(struct assembler *a, int start, int end,
                                    int handler_offset,
                                    _PyExceptHandlerInfo *handler)
{}

static int
assemble_exception_table(struct assembler *a, instr_sequence *instrs)
{}


/* Code location emitting code. See locations.md for a description of the format. */

#define MSB

static void
write_location_byte(struct assembler* a, int val)
{}


static uint8_t *
location_pointer(struct assembler* a)
{}

static void
write_location_first_byte(struct assembler* a, int code, int length)
{}

static void
write_location_varint(struct assembler* a, unsigned int val)
{}


static void
write_location_signed_varint(struct assembler* a, int val)
{}

static void
write_location_info_short_form(struct assembler* a, int length, int column, int end_column)
{}

static void
write_location_info_oneline_form(struct assembler* a, int length, int line_delta, int column, int end_column)
{}

static void
write_location_info_long_form(struct assembler* a, location loc, int length)
{}

static void
write_location_info_none(struct assembler* a, int length)
{}

static void
write_location_info_no_column(struct assembler* a, int length, int line_delta)
{}

#define THEORETICAL_MAX_ENTRY_SIZE


static int
write_location_info_entry(struct assembler* a, location loc, int isize)
{}

static int
assemble_emit_location(struct assembler* a, location loc, int isize)
{}

static int
assemble_location_info(struct assembler *a, instr_sequence *instrs,
                       int firstlineno)
{}

static void
write_instr(_Py_CODEUNIT *codestr, instruction *instr, int ilen)
{}

/* assemble_emit_instr()
   Extend the bytecode with a new instruction.
   Update lnotab if necessary.
*/

static int
assemble_emit_instr(struct assembler *a, instruction *instr)
{}

static int
assemble_emit(struct assembler *a, instr_sequence *instrs,
              int first_lineno, PyObject *const_cache)
{}

static PyObject *
dict_keys_inorder(PyObject *dict, Py_ssize_t offset)
{}

// This is in codeobject.c.
extern void _Py_set_localsplus_info(int, PyObject *, unsigned char,
                                   PyObject *, PyObject *);

static int
compute_localsplus_info(_PyCompile_CodeUnitMetadata *umd, int nlocalsplus,
                        PyObject *names, PyObject *kinds)
{}

static PyCodeObject *
makecode(_PyCompile_CodeUnitMetadata *umd, struct assembler *a, PyObject *const_cache,
         PyObject *constslist, int maxdepth, int nlocalsplus, int code_flags,
         PyObject *filename)
{}

static int
resolve_jump_offsets(instr_sequence *instrs)
{}

static int
resolve_unconditional_jumps(instr_sequence *instrs)
{}

PyCodeObject *
_PyAssemble_MakeCodeObject(_PyCompile_CodeUnitMetadata *umd, PyObject *const_cache,
                           PyObject *consts, int maxdepth, instr_sequence *instrs,
                           int nlocalsplus, int code_flags, PyObject *filename)
{}