@@ -438,9 +438,18 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, qstr_window_t *qw) {
438
438
439
439
// Allocate constant table
440
440
size_t n_alloc = prelude .n_pos_args + prelude .n_kwonly_args + n_obj + n_raw_code ;
441
+ #if MICROPY_EMIT_MACHINE_CODE
441
442
if (kind != MP_CODE_BYTECODE ) {
442
443
++ n_alloc ; // additional entry for mp_fun_table
444
+ if (prelude .scope_flags & MP_SCOPE_FLAG_VIPERRODATA ) {
445
+ ++ n_alloc ; // additional entry for rodata
446
+ }
447
+ if (prelude .scope_flags & MP_SCOPE_FLAG_VIPERBSS ) {
448
+ ++ n_alloc ; // additional entry for BSS
449
+ }
443
450
}
451
+ #endif
452
+
444
453
const_table = m_new (mp_uint_t , n_alloc );
445
454
mp_uint_t * ct = const_table ;
446
455
@@ -454,6 +463,21 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, qstr_window_t *qw) {
454
463
if (kind != MP_CODE_BYTECODE ) {
455
464
// Populate mp_fun_table entry
456
465
* ct ++ = (mp_uint_t )(uintptr_t )& mp_fun_table ;
466
+
467
+ // Allocate and load rodata if needed
468
+ if (prelude .scope_flags & MP_SCOPE_FLAG_VIPERRODATA ) {
469
+ size_t size = read_uint (reader , NULL );
470
+ uint8_t * rodata = m_new (uint8_t , size );
471
+ read_bytes (reader , rodata , size );
472
+ * ct ++ = (uintptr_t )rodata ;
473
+ }
474
+
475
+ // Allocate BSS if needed
476
+ if (prelude .scope_flags & MP_SCOPE_FLAG_VIPERBSS ) {
477
+ size_t size = read_uint (reader , NULL );
478
+ uint8_t * bss = m_new0 (uint8_t , size );
479
+ * ct ++ = (uintptr_t )bss ;
480
+ }
457
481
}
458
482
#endif
459
483
@@ -469,6 +493,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, qstr_window_t *qw) {
469
493
// Create raw_code and return it
470
494
mp_raw_code_t * rc = mp_emit_glue_new_raw_code ();
471
495
if (kind == MP_CODE_BYTECODE ) {
496
+ // Assign bytecode to raw code object
472
497
mp_emit_glue_assign_bytecode (rc , fun_data ,
473
498
#if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS
474
499
fun_data_len ,
@@ -481,18 +506,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, qstr_window_t *qw) {
481
506
482
507
#if MICROPY_EMIT_MACHINE_CODE
483
508
} else {
484
- mp_uint_t * ct = & const_table [1 ];
485
- if (prelude .scope_flags & MP_SCOPE_FLAG_VIPERRODATA ) {
486
- size_t size = read_uint (reader , NULL );
487
- uint8_t * rodata = m_new (uint8_t , size );
488
- read_bytes (reader , rodata , size );
489
- * ct ++ = (uintptr_t )rodata ;
490
- }
491
- if (prelude .scope_flags & MP_SCOPE_FLAG_VIPERBSS ) {
492
- size_t size = read_uint (reader , NULL );
493
- uint8_t * bss = m_new0 (uint8_t , size );
494
- * ct ++ = (uintptr_t )bss ;
495
- }
509
+ // Relocate and commit code to executable address space
496
510
reloc_info_t ri = {reader , const_table };
497
511
#if defined(MP_PLAT_COMMIT_EXEC )
498
512
void * opt_ri = (prelude .scope_flags & MP_SCOPE_FLAG_VIPERRELOC ) ? & ri : NULL ;
@@ -503,6 +517,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, qstr_window_t *qw) {
503
517
}
504
518
#endif
505
519
520
+ // Assign native code to raw code object
506
521
mp_emit_glue_assign_native (rc , kind ,
507
522
fun_data , fun_data_len , const_table ,
508
523
#if MICROPY_PERSISTENT_CODE_SAVE
0 commit comments