diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-18 20:09:26 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-18 20:09:43 +0000 |
| commit | e007eb629f422fb96fa8da81e2f79e7d0301c866 (patch) | |
| tree | 9515587e8f68e1200b6a14dbf59ffd704fa8e75d /src/main.c | |
| parent | c385307e5d6ea84a726f878d2129da19ae1e8e5b (diff) | |
Fixed 'zc run' for '--cuda'.
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 38 |
1 files changed, 23 insertions, 15 deletions
@@ -152,7 +152,7 @@ int main(int argc, char **argv) { strcpy(g_config.cc, "nvcc"); g_config.use_cuda = 1; - g_config.use_cpp = 1; // CUDA implies C++ mode + g_config.use_cpp = 1; // CUDA implies C++ mode. } else if (strcmp(arg, "--check") == 0) { @@ -270,11 +270,22 @@ int main(int argc, char **argv) return 0; } - // Codegen to C - FILE *out = fopen("out.c", "w"); + // Determine temporary filename based on mode + const char *temp_source_file = "out.c"; + if (g_config.use_cuda) + { + temp_source_file = "out.cu"; + } + else if (g_config.use_cpp) + { + temp_source_file = "out.cpp"; + } + + // Codegen to C/C++/CUDA + FILE *out = fopen(temp_source_file, "w"); if (!out) { - perror("fopen out.c"); + perror("fopen temp output"); return 1; } @@ -285,10 +296,10 @@ int main(int argc, char **argv) { if (g_config.output_file) { - // If user specified -o, rename out.c to that - if (rename("out.c", g_config.output_file) != 0) + // If user specified -o, rename temp file to that + if (rename(temp_source_file, g_config.output_file) != 0) { - perror("rename out.c"); + perror("rename output"); return 1; } if (!g_config.quiet) @@ -300,7 +311,7 @@ int main(int argc, char **argv) { if (!g_config.quiet) { - printf("[zc] Transpiled to out.c\n"); + printf("[zc] Transpiled to %s\n", temp_source_file); } } // Done, no C compilation @@ -311,12 +322,9 @@ int main(int argc, char **argv) char cmd[8192]; char *outfile = g_config.output_file ? g_config.output_file : "a.out"; - // TCC-specific adjustments? - // Already handled by user passing --cc tcc - - snprintf(cmd, sizeof(cmd), "%s %s %s %s %s -o %s out.c -lm %s -I./src %s", g_config.cc, + snprintf(cmd, sizeof(cmd), "%s %s %s %s %s -o %s %s -lm %s -I./src %s", g_config.cc, g_config.gcc_flags, g_cflags, g_config.is_freestanding ? "-ffreestanding" : "", "", - outfile, g_parser_ctx->has_async ? "-lpthread" : "", g_link_flags); + outfile, temp_source_file, g_parser_ctx->has_async ? "-lpthread" : "", g_link_flags); if (g_config.verbose) { @@ -329,7 +337,7 @@ int main(int argc, char **argv) printf("C compilation failed.\n"); if (!g_config.emit_c) { - remove("out.c"); + remove(temp_source_file); } return 1; } @@ -337,7 +345,7 @@ int main(int argc, char **argv) if (!g_config.emit_c) { // remove("out.c"); // Keep it for debugging for now or follow flag - remove("out.c"); + remove(temp_source_file); } if (g_config.mode_run) |
