| ... | ... | @@ -10392,6 +10392,61 @@ static void resolve_out_paths(CodeGen *g) { |
| 10392 | 10392 | } |
| 10393 | 10393 | } |
| 10394 | 10394 | |
| 10395 | static void output_type_information(CodeGen *g) { |
| 10396 | if (g->enable_dump_analysis) { |
| 10397 | const char *analysis_json_filename = buf_ptr(buf_sprintf("%s" OS_SEP "%s-analysis.json", |
| 10398 | buf_ptr(g->output_dir), buf_ptr(g->root_out_name))); |
| 10399 | FILE *f = fopen(analysis_json_filename, "wb"); |
| 10400 | if (f == nullptr) { |
| 10401 | fprintf(stderr, "Unable to open '%s': %s\n", analysis_json_filename, strerror(errno)); |
| 10402 | exit(1); |
| 10403 | } |
| 10404 | zig_print_analysis_dump(g, f, " ", "\n"); |
| 10405 | if (fclose(f) != 0) { |
| 10406 | fprintf(stderr, "Unable to write '%s': %s\n", analysis_json_filename, strerror(errno)); |
| 10407 | exit(1); |
| 10408 | } |
| 10409 | } |
| 10410 | if (g->enable_doc_generation) { |
| 10411 | Error err; |
| 10412 | Buf *doc_dir_path = buf_sprintf("%s" OS_SEP "docs", buf_ptr(g->output_dir)); |
| 10413 | if ((err = os_make_path(doc_dir_path))) { |
| 10414 | fprintf(stderr, "Unable to create directory %s: %s\n", buf_ptr(doc_dir_path), err_str(err)); |
| 10415 | exit(1); |
| 10416 | } |
| 10417 | Buf *index_html_src_path = buf_sprintf("%s" OS_SEP "special" OS_SEP "docs" OS_SEP "index.html", |
| 10418 | buf_ptr(g->zig_std_dir)); |
| 10419 | Buf *index_html_dest_path = buf_sprintf("%s" OS_SEP "index.html", buf_ptr(doc_dir_path)); |
| 10420 | Buf *main_js_src_path = buf_sprintf("%s" OS_SEP "special" OS_SEP "docs" OS_SEP "main.js", |
| 10421 | buf_ptr(g->zig_std_dir)); |
| 10422 | Buf *main_js_dest_path = buf_sprintf("%s" OS_SEP "main.js", buf_ptr(doc_dir_path)); |
| 10423 | |
| 10424 | if ((err = os_copy_file(index_html_src_path, index_html_dest_path))) { |
| 10425 | fprintf(stderr, "Unable to copy %s to %s: %s\n", buf_ptr(index_html_src_path), |
| 10426 | buf_ptr(index_html_dest_path), err_str(err)); |
| 10427 | exit(1); |
| 10428 | } |
| 10429 | if ((err = os_copy_file(main_js_src_path, main_js_dest_path))) { |
| 10430 | fprintf(stderr, "Unable to copy %s to %s: %s\n", buf_ptr(main_js_src_path), |
| 10431 | buf_ptr(main_js_dest_path), err_str(err)); |
| 10432 | exit(1); |
| 10433 | } |
| 10434 | const char *data_js_filename = buf_ptr(buf_sprintf("%s" OS_SEP "data.js", buf_ptr(doc_dir_path))); |
| 10435 | FILE *f = fopen(data_js_filename, "wb"); |
| 10436 | if (f == nullptr) { |
| 10437 | fprintf(stderr, "Unable to open '%s': %s\n", data_js_filename, strerror(errno)); |
| 10438 | exit(1); |
| 10439 | } |
| 10440 | fprintf(f, "zigAnalysis="); |
| 10441 | zig_print_analysis_dump(g, f, "", ""); |
| 10442 | fprintf(f, ";"); |
| 10443 | if (fclose(f) != 0) { |
| 10444 | fprintf(stderr, "Unable to write '%s': %s\n", data_js_filename, strerror(errno)); |
| 10445 | exit(1); |
| 10446 | } |
| 10447 | } |
| 10448 | } |
| 10449 | |
| 10395 | 10450 | void codegen_build_and_link(CodeGen *g) { |
| 10396 | 10451 | Error err; |
| 10397 | 10452 | assert(g->out_type != OutTypeUnknown); |
| ... | ... | @@ -10466,6 +10521,10 @@ void codegen_build_and_link(CodeGen *g) { |
| 10466 | 10521 | } |
| 10467 | 10522 | resolve_out_paths(g); |
| 10468 | 10523 | |
| 10524 | if (g->enable_dump_analysis || g->enable_doc_generation) { |
| 10525 | output_type_information(g); |
| 10526 | } |
| 10527 | |
| 10469 | 10528 | if (need_llvm_module(g)) { |
| 10470 | 10529 | codegen_add_time_event(g, "Code Generation"); |
| 10471 | 10530 | { |
| ... | ... | @@ -10493,57 +10552,6 @@ void codegen_build_and_link(CodeGen *g) { |
| 10493 | 10552 | gen_h_file(g); |
| 10494 | 10553 | } |
| 10495 | 10554 | } |
| 10496 | | if (g->enable_dump_analysis) { |
| 10497 | | const char *analysis_json_filename = buf_ptr(buf_sprintf("%s" OS_SEP "%s-analysis.json", |
| 10498 | | buf_ptr(g->output_dir), buf_ptr(g->root_out_name))); |
| 10499 | | FILE *f = fopen(analysis_json_filename, "wb"); |
| 10500 | | if (f == nullptr) { |
| 10501 | | fprintf(stderr, "Unable to open '%s': %s\n", analysis_json_filename, strerror(errno)); |
| 10502 | | exit(1); |
| 10503 | | } |
| 10504 | | zig_print_analysis_dump(g, f, " ", "\n"); |
| 10505 | | if (fclose(f) != 0) { |
| 10506 | | fprintf(stderr, "Unable to write '%s': %s\n", analysis_json_filename, strerror(errno)); |
| 10507 | | exit(1); |
| 10508 | | } |
| 10509 | | } |
| 10510 | | if (g->enable_doc_generation) { |
| 10511 | | Buf *doc_dir_path = buf_sprintf("%s" OS_SEP "docs", buf_ptr(g->output_dir)); |
| 10512 | | if ((err = os_make_path(doc_dir_path))) { |
| 10513 | | fprintf(stderr, "Unable to create directory %s: %s\n", buf_ptr(doc_dir_path), err_str(err)); |
| 10514 | | exit(1); |
| 10515 | | } |
| 10516 | | Buf *index_html_src_path = buf_sprintf("%s" OS_SEP "special" OS_SEP "docs" OS_SEP "index.html", |
| 10517 | | buf_ptr(g->zig_std_dir)); |
| 10518 | | Buf *index_html_dest_path = buf_sprintf("%s" OS_SEP "index.html", buf_ptr(doc_dir_path)); |
| 10519 | | Buf *main_js_src_path = buf_sprintf("%s" OS_SEP "special" OS_SEP "docs" OS_SEP "main.js", |
| 10520 | | buf_ptr(g->zig_std_dir)); |
| 10521 | | Buf *main_js_dest_path = buf_sprintf("%s" OS_SEP "main.js", buf_ptr(doc_dir_path)); |
| 10522 | | |
| 10523 | | if ((err = os_copy_file(index_html_src_path, index_html_dest_path))) { |
| 10524 | | fprintf(stderr, "Unable to copy %s to %s: %s\n", buf_ptr(index_html_src_path), |
| 10525 | | buf_ptr(index_html_dest_path), err_str(err)); |
| 10526 | | exit(1); |
| 10527 | | } |
| 10528 | | if ((err = os_copy_file(main_js_src_path, main_js_dest_path))) { |
| 10529 | | fprintf(stderr, "Unable to copy %s to %s: %s\n", buf_ptr(main_js_src_path), |
| 10530 | | buf_ptr(main_js_dest_path), err_str(err)); |
| 10531 | | exit(1); |
| 10532 | | } |
| 10533 | | const char *data_js_filename = buf_ptr(buf_sprintf("%s" OS_SEP "data.js", buf_ptr(doc_dir_path))); |
| 10534 | | FILE *f = fopen(data_js_filename, "wb"); |
| 10535 | | if (f == nullptr) { |
| 10536 | | fprintf(stderr, "Unable to open '%s': %s\n", data_js_filename, strerror(errno)); |
| 10537 | | exit(1); |
| 10538 | | } |
| 10539 | | fprintf(f, "zigAnalysis="); |
| 10540 | | zig_print_analysis_dump(g, f, "", ""); |
| 10541 | | fprintf(f, ";"); |
| 10542 | | if (fclose(f) != 0) { |
| 10543 | | fprintf(stderr, "Unable to write '%s': %s\n", data_js_filename, strerror(errno)); |
| 10544 | | exit(1); |
| 10545 | | } |
| 10546 | | } |
| 10547 | 10555 | |
| 10548 | 10556 | // If we're outputting assembly or llvm IR we skip linking. |
| 10549 | 10557 | // If we're making a library or executable we must link. |