Skip to content

Commit cdb0c25

Browse files
committed
emit: allow mpy-cross to exclude source lines
This would allow building debug FW without source line data.
1 parent 8c6dfa5 commit cdb0c25

4 files changed

Lines changed: 23 additions & 1 deletion

File tree

mpy-cross/main.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ static asm_rv32_backend_options_t rv32_options = { 0 };
5050
static uint emit_opt = MP_EMIT_OPT_NONE;
5151
mp_uint_t mp_verbose_flag = 0;
5252

53+
#if MICROPY_ENABLE_SOURCE_LINE
54+
static bool include_source_lines = true;
55+
#endif
56+
5357
// Heap size of GC heap (if enabled)
5458
// Make it larger on a 64 bit machine, because pointers are larger.
5559
long heap_size = 1024 * 1024 * (sizeof(mp_uint_t) / 4);
@@ -186,6 +190,14 @@ static void pre_process_options(int argc, char **argv) {
186190
emit_opt = MP_EMIT_OPT_NATIVE_PYTHON;
187191
} else if (strcmp(argv[a + 1], "emit=viper") == 0) {
188192
emit_opt = MP_EMIT_OPT_VIPER;
193+
#if MICROPY_ENABLE_SOURCE_LINE
194+
} else if (strcmp(argv[a + 1], "source-lines") == 0) {
195+
// Allow excluding source lines for debug builds.
196+
include_source_lines = true;
197+
} else if (strcmp(argv[a + 1], "no-source-lines") == 0) {
198+
// Allow excluding source lines for debug builds.
199+
include_source_lines = false;
200+
#endif
189201
#endif
190202
} else if (strncmp(argv[a + 1], "heapsize=", sizeof("heapsize=") - 1) == 0) {
191203
char *end;
@@ -305,6 +317,10 @@ MP_NOINLINE int main_(int argc, char **argv) {
305317
(void)emit_opt;
306318
#endif
307319

320+
#if MICROPY_ENABLE_SOURCE_LINE
321+
MP_STATE_VM(include_source_lines) = include_source_lines;
322+
#endif
323+
308324
// set default compiler configuration
309325
mp_dynamic_compiler.small_int_bits = 31;
310326
// don't support native emitter unless -march is specified

py/emitbc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ void mp_emit_bc_set_source_line(emit_t *emit, mp_uint_t source_line) {
430430
// If we compile with -O3, don't store line numbers.
431431
return;
432432
}
433-
if (source_line > emit->last_source_line) {
433+
if (MP_STATE_VM(include_source_lines) && source_line > emit->last_source_line) {
434434
mp_uint_t bytes_to_skip = emit->bytecode_offset - emit->last_source_line_offset;
435435
mp_uint_t lines_to_skip = source_line - emit->last_source_line;
436436
emit_write_code_info_bytes_lines(emit, bytes_to_skip, lines_to_skip);

py/mpstate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ typedef struct _mp_state_vm_t {
231231
#if MICROPY_EMIT_NATIVE
232232
uint8_t default_emit_opt; // one of MP_EMIT_OPT_xxx
233233
#endif
234+
#if MICROPY_ENABLE_SOURCE_LINE
235+
bool include_source_lines;
236+
#endif
234237
#endif
235238

236239
// size of the emergency exception buf, if it's dynamically allocated

py/runtime.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ void mp_init(void) {
105105
#if MICROPY_EMIT_NATIVE
106106
MP_STATE_VM(default_emit_opt) = MP_EMIT_OPT_NONE;
107107
#endif
108+
#if MICROPY_ENABLE_SOURCE_LINE
109+
MP_STATE_VM(include_source_lines) = true;
110+
#endif
108111
#endif
109112

110113
// init global module dict

0 commit comments

Comments
 (0)