Skip to content

Commit a1ddfcc

Browse files
committed
Wrap out-native code in preprocessor declarations.
1 parent eb19efb commit a1ddfcc

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

py/runtime.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "bc.h"
1111

1212
#if 0 // print debugging info
13+
#define DEBUG_PRINT (1)
14+
#define WRITE_NATIVE (1)
1315
#define DEBUG_printf(args...) printf(args)
1416
#define DEBUG_OP_printf(args...) printf(args)
1517
#else // don't print debugging info
@@ -357,7 +359,9 @@ py_obj_t py_builtin___build_class__(py_obj_t o_class_fun, py_obj_t o_class_name)
357359
return o;
358360
}
359361

362+
#ifdef WRITE_NATIVE
360363
FILE *fp_native = NULL;
364+
#endif
361365

362366
void rt_init() {
363367
q_append = qstr_from_str_static("append");
@@ -383,13 +387,17 @@ void rt_init() {
383387

384388
fun_list_append = rt_make_function_2(list_append);
385389

390+
#ifdef WRITE_NATIVE
386391
fp_native = fopen("out-native", "wb");
392+
#endif
387393
}
388394

389395
void rt_deinit() {
396+
#ifdef WRITE_NATIVE
390397
if (fp_native != NULL) {
391398
fclose(fp_native);
392399
}
400+
#endif
393401
}
394402

395403
int rt_get_new_unique_code_id() {
@@ -425,6 +433,7 @@ void rt_assign_native_code(int unique_code_id, py_fun_t fun, uint len, int n_arg
425433
unique_codes[unique_code_id].n_args = n_args;
426434
unique_codes[unique_code_id].u_native.fun = fun;
427435

436+
#ifdef DEBUG_PRINT
428437
DEBUG_printf("assign native code: id=%d fun=%p len=%u n_args=%d\n", unique_code_id, fun, len, n_args);
429438
byte *fun_data = (byte*)(((machine_uint_t)fun) & (~1)); // need to clear lower bit in case it's thumb code
430439
for (int i = 0; i < 128 && i < len; i++) {
@@ -435,10 +444,13 @@ void rt_assign_native_code(int unique_code_id, py_fun_t fun, uint len, int n_arg
435444
}
436445
DEBUG_printf("\n");
437446

447+
#ifdef WRITE_NATIVE
438448
if (fp_native != NULL) {
439449
fwrite(fun_data, len, 1, fp_native);
440450
fflush(fp_native);
441451
}
452+
#endif
453+
#endif
442454
}
443455

444456
void rt_assign_inline_asm_code(int unique_code_id, py_fun_t fun, uint len, int n_args) {
@@ -449,6 +461,7 @@ void rt_assign_inline_asm_code(int unique_code_id, py_fun_t fun, uint len, int n
449461
unique_codes[unique_code_id].n_args = n_args;
450462
unique_codes[unique_code_id].u_inline_asm.fun = fun;
451463

464+
#ifdef DEBUG_PRINT
452465
DEBUG_printf("assign inline asm code: id=%d fun=%p len=%u n_args=%d\n", unique_code_id, fun, len, n_args);
453466
byte *fun_data = (byte*)(((machine_uint_t)fun) & (~1)); // need to clear lower bit in case it's thumb code
454467
for (int i = 0; i < 128 && i < len; i++) {
@@ -459,9 +472,12 @@ void rt_assign_inline_asm_code(int unique_code_id, py_fun_t fun, uint len, int n
459472
}
460473
DEBUG_printf("\n");
461474

475+
#ifdef WRITE_NATIVE
462476
if (fp_native != NULL) {
463477
fwrite(fun_data, len, 1, fp_native);
464478
}
479+
#endif
480+
#endif
465481
}
466482

467483
bool py_obj_is_callable(py_obj_t o_in) {

0 commit comments

Comments
 (0)