Change some debugging/output messages for native code generation.

This commit is contained in:
Damien 2013-11-17 13:16:36 +00:00
parent 6d4f3462c4
commit 0446a0d76d
3 changed files with 38 additions and 17 deletions

View File

@ -74,7 +74,7 @@ void asm_thumb_end_pass(asm_thumb_t *as) {
// calculate size of code in bytes // calculate size of code in bytes
as->code_size = as->code_offset; as->code_size = as->code_offset;
as->code_base = m_new(byte, as->code_size); as->code_base = m_new(byte, as->code_size);
printf("code_size: %u\n", as->code_size); //printf("code_size: %u\n", as->code_size);
} }
/* /*

View File

@ -1409,7 +1409,7 @@ void compile_for_stmt(compiler_t *comp, py_parse_node_struct_t *pns) {
// this bit optimises: for <x> in range(...), turning it into an explicitly incremented variable // this bit optimises: for <x> in range(...), turning it into an explicitly incremented variable
// this is actually slower, but uses no heap memory // this is actually slower, but uses no heap memory
// for viper it will be much, much faster // for viper it will be much, much faster
if (PY_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[1], PN_power)) { if (/*comp->scope_cur->emit_options == EMIT_OPT_VIPER &&*/ PY_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[1], PN_power)) {
py_parse_node_struct_t *pns_it = (py_parse_node_struct_t*)pns->nodes[1]; py_parse_node_struct_t *pns_it = (py_parse_node_struct_t*)pns->nodes[1];
if (PY_PARSE_NODE_IS_ID(pns_it->nodes[0]) && PY_PARSE_NODE_IS_STRUCT_KIND(pns_it->nodes[1], PN_trailer_paren) && PY_PARSE_NODE_IS_NULL(pns_it->nodes[2])) { if (PY_PARSE_NODE_IS_ID(pns_it->nodes[0]) && PY_PARSE_NODE_IS_STRUCT_KIND(pns_it->nodes[1], PN_trailer_paren) && PY_PARSE_NODE_IS_NULL(pns_it->nodes[2])) {
py_parse_node_t pn_range_args = ((py_parse_node_struct_t*)pns_it->nodes[1])->nodes[0]; py_parse_node_t pn_range_args = ((py_parse_node_struct_t*)pns_it->nodes[1])->nodes[0];

View File

@ -17,7 +17,7 @@
#if 0 // print debugging info #if 0 // print debugging info
#define DEBUG_PRINT (1) #define DEBUG_PRINT (1)
#define WRITE_NATIVE (1) #define WRITE_CODE (1)
#define DEBUG_printf(args...) printf(args) #define DEBUG_printf(args...) printf(args)
#define DEBUG_OP_printf(args...) printf(args) #define DEBUG_OP_printf(args...) printf(args)
#else // don't print debugging info #else // don't print debugging info
@ -932,8 +932,8 @@ py_obj_t py_builtin_range(py_obj_t o_arg) {
return py_obj_new_range(0, py_obj_get_int(o_arg), 1); return py_obj_new_range(0, py_obj_get_int(o_arg), 1);
} }
#ifdef WRITE_NATIVE #ifdef WRITE_CODE
FILE *fp_native = NULL; FILE *fp_write_code = NULL;
#endif #endif
void rt_init(void) { void rt_init(void) {
@ -974,15 +974,15 @@ void rt_init(void) {
fun_list_append = rt_make_function_2(rt_list_append); fun_list_append = rt_make_function_2(rt_list_append);
fun_gen_instance_next = rt_make_function_1(rt_gen_instance_next); fun_gen_instance_next = rt_make_function_1(rt_gen_instance_next);
#ifdef WRITE_NATIVE #ifdef WRITE_CODE
fp_native = fopen("out-native", "wb"); fp_write_code = fopen("out-code", "wb");
#endif #endif
} }
void rt_deinit(void) { void rt_deinit(void) {
#ifdef WRITE_NATIVE #ifdef WRITE_CODE
if (fp_native != NULL) { if (fp_write_code != NULL) {
fclose(fp_native); fclose(fp_write_code);
} }
#endif #endif
} }
@ -1016,7 +1016,26 @@ void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, i
unique_codes[unique_code_id].u_byte.code = code; unique_codes[unique_code_id].u_byte.code = code;
unique_codes[unique_code_id].u_byte.len = len; unique_codes[unique_code_id].u_byte.len = len;
printf("byte code: %d bytes\n", len);
#ifdef DEBUG_PRINT
DEBUG_printf("assign byte code: id=%d code=%p len=%u n_args=%d\n", unique_code_id, code, len, n_args); DEBUG_printf("assign byte code: id=%d code=%p len=%u n_args=%d\n", unique_code_id, code, len, n_args);
for (int i = 0; i < 128 && i < len; i++) {
if (i > 0 && i % 16 == 0) {
DEBUG_printf("\n");
}
DEBUG_printf(" %02x", code[i]);
}
DEBUG_printf("\n");
py_un_byte_code(code, len);
#ifdef WRITE_CODE
if (fp_write_code != NULL) {
fwrite(code, len, 1, fp_write_code);
fflush(fp_write_code);
}
#endif
#endif
} }
void rt_assign_native_code(int unique_code_id, py_fun_t fun, uint len, int n_args) { void rt_assign_native_code(int unique_code_id, py_fun_t fun, uint len, int n_args) {
@ -1030,6 +1049,8 @@ void rt_assign_native_code(int unique_code_id, py_fun_t fun, uint len, int n_arg
unique_codes[unique_code_id].is_generator = false; unique_codes[unique_code_id].is_generator = false;
unique_codes[unique_code_id].u_native.fun = fun; unique_codes[unique_code_id].u_native.fun = fun;
printf("native code: %d bytes\n", len);
#ifdef DEBUG_PRINT #ifdef DEBUG_PRINT
DEBUG_printf("assign native code: id=%d fun=%p len=%u n_args=%d\n", unique_code_id, fun, len, n_args); DEBUG_printf("assign native code: id=%d fun=%p len=%u n_args=%d\n", unique_code_id, fun, len, n_args);
byte *fun_data = (byte*)(((machine_uint_t)fun) & (~1)); // need to clear lower bit in case it's thumb code byte *fun_data = (byte*)(((machine_uint_t)fun) & (~1)); // need to clear lower bit in case it's thumb code
@ -1041,10 +1062,10 @@ void rt_assign_native_code(int unique_code_id, py_fun_t fun, uint len, int n_arg
} }
DEBUG_printf("\n"); DEBUG_printf("\n");
#ifdef WRITE_NATIVE #ifdef WRITE_CODE
if (fp_native != NULL) { if (fp_write_code != NULL) {
fwrite(fun_data, len, 1, fp_native); fwrite(fun_data, len, 1, fp_write_code);
fflush(fp_native); fflush(fp_write_code);
} }
#endif #endif
#endif #endif
@ -1072,9 +1093,9 @@ void rt_assign_inline_asm_code(int unique_code_id, py_fun_t fun, uint len, int n
} }
DEBUG_printf("\n"); DEBUG_printf("\n");
#ifdef WRITE_NATIVE #ifdef WRITE_CODE
if (fp_native != NULL) { if (fp_write_code != NULL) {
fwrite(fun_data, len, 1, fp_native); fwrite(fun_data, len, 1, fp_write_code);
} }
#endif #endif
#endif #endif