20
20
#include "util.hpp"
21
21
#include "zig_llvm.h"
22
22
#include "userland.h"
23
+ #include "dump_analysis.hpp"
23
24
24
25
#include <stdio.h>
25
26
#include <errno.h>
@@ -1724,7 +1725,7 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
1724
1725
}
1725
1726
1726
1727
ATTRIBUTE_NORETURN
1727
- static void report_errors_and_exit (CodeGen *g) {
1728
+ void codegen_report_errors_and_exit (CodeGen *g) {
1728
1729
assert(g->errors.length != 0);
1729
1730
for (size_t i = 0; i < g->errors.length; i += 1) {
1730
1731
ErrorMsg *err = g->errors.at(i);
@@ -1735,7 +1736,7 @@ static void report_errors_and_exit(CodeGen *g) {
1735
1736
1736
1737
static void report_errors_and_maybe_exit(CodeGen *g) {
1737
1738
if (g->errors.length != 0) {
1738
- report_errors_and_exit (g);
1739
+ codegen_report_errors_and_exit (g);
1739
1740
}
1740
1741
}
1741
1742
@@ -1745,7 +1746,7 @@ static void give_up_with_c_abi_error(CodeGen *g, AstNode *source_node) {
1745
1746
buf_sprintf("TODO: support C ABI for more targets. https://github.com/ziglang/zig/issues/1481"));
1746
1747
add_error_note(g, msg, source_node,
1747
1748
buf_sprintf("pointers, integers, floats, bools, and enums work on all targets"));
1748
- report_errors_and_exit (g);
1749
+ codegen_report_errors_and_exit (g);
1749
1750
}
1750
1751
1751
1752
static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment) {
@@ -3456,7 +3457,7 @@ static bool value_is_all_undef(CodeGen *g, ConstExprValue *const_val) {
3456
3457
Error err;
3457
3458
if (const_val->special == ConstValSpecialLazy &&
3458
3459
(err = ir_resolve_lazy(g, nullptr, const_val)))
3459
- report_errors_and_exit (g);
3460
+ codegen_report_errors_and_exit (g);
3460
3461
3461
3462
switch (const_val->special) {
3462
3463
case ConstValSpecialLazy:
@@ -4253,7 +4254,7 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
4253
4254
ZigType *struct_type = (struct_ptr_type->id == ZigTypeIdPointer) ?
4254
4255
struct_ptr_type->data.pointer.child_type : struct_ptr_type;
4255
4256
if ((err = type_resolve(g, struct_type, ResolveStatusLLVMFull)))
4256
- report_errors_and_exit (g);
4257
+ codegen_report_errors_and_exit (g);
4257
4258
4258
4259
assert(field->gen_index != SIZE_MAX);
4259
4260
return LLVMBuildStructGEP(g->builder, struct_ptr, (unsigned)field->gen_index, "");
@@ -6625,7 +6626,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
6625
6626
check: switch (const_val->special) {
6626
6627
case ConstValSpecialLazy:
6627
6628
if ((err = ir_resolve_lazy(g, nullptr, const_val))) {
6628
- report_errors_and_exit (g);
6629
+ codegen_report_errors_and_exit (g);
6629
6630
}
6630
6631
goto check;
6631
6632
case ConstValSpecialRuntime:
@@ -10157,6 +10158,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
10157
10158
cache_bool(ch, g->have_stack_probing);
10158
10159
cache_bool(ch, g->is_dummy_so);
10159
10160
cache_bool(ch, g->function_sections);
10161
+ cache_bool(ch, g->enable_dump_analysis);
10160
10162
cache_buf_opt(ch, g->mmacosx_version_min);
10161
10163
cache_buf_opt(ch, g->mios_version_min);
10162
10164
cache_usize(ch, g->version_major);
@@ -10338,6 +10340,21 @@ void codegen_build_and_link(CodeGen *g) {
10338
10340
gen_h_file(g);
10339
10341
}
10340
10342
}
10343
+ if (g->enable_dump_analysis) {
10344
+ const char *analysis_json_filename = buf_ptr(buf_sprintf("%s" OS_SEP "%s-analysis.json",
10345
+ buf_ptr(g->output_dir), buf_ptr(g->root_out_name)));
10346
+ FILE *f = fopen(analysis_json_filename, "wb");
10347
+ if (f == nullptr) {
10348
+ fprintf(stderr, "Unable to open '%s': %s\n", analysis_json_filename, strerror(errno));
10349
+ exit(1);
10350
+ }
10351
+ zig_print_analysis_dump(g, f);
10352
+ if (fclose(f) != 0) {
10353
+ fprintf(stderr, "Unable to write '%s': %s\n", analysis_json_filename, strerror(errno));
10354
+ exit(1);
10355
+ }
10356
+
10357
+ }
10341
10358
10342
10359
// If we're outputting assembly or llvm IR we skip linking.
10343
10360
// If we're making a library or executable we must link.
0 commit comments