/home/travis/build/MoarVM/MoarVM/src/jit/log.c
Line | Count | Source (jump to first uncovered line) |
1 | | #include "moar.h" |
2 | | |
3 | | /* inline this? maybe */ |
4 | 2.12M | void MVM_jit_log(MVMThreadContext *tc, const char * fmt, ...) { |
5 | 2.12M | va_list args; |
6 | 2.12M | va_start(args, fmt); |
7 | 2.12M | if (tc->instance->jit_log_fh) { |
8 | 0 | vfprintf(tc->instance->jit_log_fh, fmt, args); |
9 | 0 | } |
10 | 2.12M | va_end(args); |
11 | 2.12M | } |
12 | | |
13 | 0 | void MVM_jit_log_bytecode(MVMThreadContext *tc, MVMJitCode *code) { |
14 | 0 | /* Filename format: moar-jit-%d.bin. number can consume at most 10 |
15 | 0 | * bytes, moar-jit-.bin is 13 bytes, one byte for the zero at the |
16 | 0 | * end, one byte for the directory separator is 25 bytes, plus the |
17 | 0 | * length of the bytecode directory itself */ |
18 | 0 | char * filename = MVM_malloc(strlen(tc->instance->jit_bytecode_dir) + 25); |
19 | 0 | FILE * out; |
20 | 0 | sprintf(filename, "%s/moar-jit-%04d.bin", tc->instance->jit_bytecode_dir, code->seq_nr); |
21 | 0 | out = fopen(filename, "w"); |
22 | 0 | if (out) { |
23 | 0 | fwrite(code->func_ptr, sizeof(char), code->size, out); |
24 | 0 | fclose(out); |
25 | 0 | if (tc->instance->jit_bytecode_map) { |
26 | 0 | char *frame_name = MVM_string_utf8_encode_C_string(tc, code->sf->body.name); |
27 | 0 | char *frame_cuuid = MVM_string_utf8_encode_C_string(tc, code->sf->body.cuuid); |
28 | 0 | /* I'd like to add linenumber and filename information, but it's really a lot of work at this point */ |
29 | 0 | fprintf(tc->instance->jit_bytecode_map, "%s\t%s\t%s\n", filename, frame_name, frame_cuuid); |
30 | 0 | MVM_free(frame_name); |
31 | 0 | MVM_free(frame_cuuid); |
32 | 0 | } |
33 | 0 | } else { |
34 | 0 | MVM_jit_log(tc, "ERROR: could dump bytecode in %s\n", filename); |
35 | 0 | } |
36 | 0 | MVM_free(filename); |
37 | 0 | } |