| 110 | } |
| 111 | |
| 112 | void saveKernel(const string& funcName, const string& jit_ker, |
| 113 | const string& ext) { |
| 114 | static constexpr const char* saveJitKernelsEnvVarName = |
| 115 | "AF_JIT_KERNEL_TRACE"; |
| 116 | static const char* jitKernelsOutput = getenv(saveJitKernelsEnvVarName); |
| 117 | if (!jitKernelsOutput) { return; } |
| 118 | if (strcmp(jitKernelsOutput, "stdout") == 0) { |
| 119 | fputs(jit_ker.c_str(), stdout); |
| 120 | return; |
| 121 | } |
| 122 | if (strcmp(jitKernelsOutput, "stderr") == 0) { |
| 123 | fputs(jit_ker.c_str(), stderr); |
| 124 | return; |
| 125 | } |
| 126 | // Path to a folder |
| 127 | const string ffp = |
| 128 | string(jitKernelsOutput) + AF_PATH_SEPARATOR + funcName + ext; |
| 129 | |
| 130 | #if defined(OS_WIN) |
| 131 | FILE* f = fopen(ffp.c_str(), "w"); |
| 132 | #else |
| 133 | FILE* f = fopen(ffp.c_str(), "we"); |
| 134 | #endif |
| 135 | |
| 136 | if (!f) { |
| 137 | fprintf(stderr, "Cannot open file %s\n", ffp.c_str()); |
| 138 | return; |
| 139 | } |
| 140 | if (fputs(jit_ker.c_str(), f) == EOF) { |
| 141 | fprintf(stderr, "Failed to write kernel to file %s\n", ffp.c_str()); |
| 142 | } |
| 143 | fclose(f); |
| 144 | } |
| 145 | |
| 146 | #if defined(OS_WIN) |
| 147 | string getTemporaryDirectory() { |