Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions mpy-cross/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
STATIC uint emit_opt = MP_EMIT_OPT_NONE;
mp_uint_t mp_verbose_flag = 0;

#if MICROPY_ENABLE_SOURCE_LINE
static bool include_source_lines = true;
#endif

// Heap size of GC heap (if enabled)
// Make it larger on a 64 bit machine, because pointers are larger.
long heap_size = 1024 * 1024 * (sizeof(mp_uint_t) / 4);
Expand Down Expand Up @@ -126,6 +130,12 @@ STATIC int usage(char **argv) {
" heapsize=<n> -- set the heap size for the GC (default %ld)\n"
, heap_size);
impl_opts_cnt++;
#if MICROPY_ENABLE_SOURCE_LINE
printf(
" source-lines -- include source line numbers (default)\n"
" no-source-lines -- exclude source line numbers\n");
impl_opts_cnt += 2;
#endif

if (impl_opts_cnt == 0) {
printf(" (none)\n");
Expand All @@ -149,6 +159,14 @@ STATIC void pre_process_options(int argc, char **argv) {
emit_opt = MP_EMIT_OPT_NATIVE_PYTHON;
} else if (strcmp(argv[a + 1], "emit=viper") == 0) {
emit_opt = MP_EMIT_OPT_VIPER;
#if MICROPY_ENABLE_SOURCE_LINE
} else if (strcmp(argv[a + 1], "source-lines") == 0) {
// Allow excluding source lines for debug builds.
include_source_lines = true;
Comment thread
cepetr marked this conversation as resolved.
} else if (strcmp(argv[a + 1], "no-source-lines") == 0) {
// Allow excluding source lines for debug builds.
include_source_lines = false;
#endif
#endif
} else if (strncmp(argv[a + 1], "heapsize=", sizeof("heapsize=") - 1) == 0) {
char *end;
Expand Down Expand Up @@ -201,6 +219,10 @@ MP_NOINLINE int main_(int argc, char **argv) {
(void)emit_opt;
#endif

#if MICROPY_ENABLE_SOURCE_LINE
MP_STATE_VM(include_source_lines) = include_source_lines;
#endif

// set default compiler configuration
mp_dynamic_compiler.small_int_bits = 31;
#if defined(__i386__)
Expand Down
2 changes: 1 addition & 1 deletion py/emitbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ void mp_emit_bc_set_source_line(emit_t *emit, mp_uint_t source_line) {
// If we compile with -O3, don't store line numbers.
return;
}
if (source_line > emit->last_source_line) {
if (MP_STATE_VM(include_source_lines) && source_line > emit->last_source_line) {
mp_uint_t bytes_to_skip = emit->bytecode_offset - emit->last_source_line_offset;
mp_uint_t lines_to_skip = source_line - emit->last_source_line;
emit_write_code_info_bytes_lines(emit, bytes_to_skip, lines_to_skip);
Expand Down
3 changes: 3 additions & 0 deletions py/mpstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ typedef struct _mp_state_vm_t {
#if MICROPY_EMIT_NATIVE
uint8_t default_emit_opt; // one of MP_EMIT_OPT_xxx
#endif
#if MICROPY_ENABLE_SOURCE_LINE
bool include_source_lines;
#endif
#endif

// size of the emergency exception buf, if it's dynamically allocated
Expand Down
3 changes: 3 additions & 0 deletions py/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ void mp_init(void) {
#if MICROPY_EMIT_NATIVE
MP_STATE_VM(default_emit_opt) = MP_EMIT_OPT_NONE;
#endif
#if MICROPY_ENABLE_SOURCE_LINE
MP_STATE_VM(include_source_lines) = true;
#endif
#endif

// init global module dict
Expand Down
Loading