| ... | ... | @@ -121,10 +121,6 @@ void codegen_set_lib_version(CodeGen *g, size_t major, size_t minor, size_t patc |
| 121 | 121 | g->version_patch = patch; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | | void codegen_set_emit_file_type(CodeGen *g, EmitFileType emit_file_type) { |
| 125 | | g->emit_file_type = emit_file_type; |
| 126 | | } |
| 127 | | |
| 128 | 124 | void codegen_set_each_lib_rpath(CodeGen *g, bool each_lib_rpath) { |
| 129 | 125 | g->each_lib_rpath = each_lib_rpath; |
| 130 | 126 | } |
| ... | ... | @@ -7919,6 +7915,14 @@ static void do_code_gen(CodeGen *g) { |
| 7919 | 7915 | } |
| 7920 | 7916 | } |
| 7921 | 7917 | |
| 7918 | void codegen_set_emit_asm(CodeGen *g, bool emit) { |
| 7919 | g->emit_asm = emit; |
| 7920 | } |
| 7921 | |
| 7922 | void codegen_set_emit_llvm_ir(CodeGen *g, bool emit) { |
| 7923 | g->emit_llvm_ir = emit; |
| 7924 | } |
| 7925 | |
| 7922 | 7926 | static void zig_llvm_emit_output(CodeGen *g) { |
| 7923 | 7927 | g->pass1_arena->destruct(&heap::c_allocator); |
| 7924 | 7928 | g->pass1_arena = nullptr; |
| ... | ... | @@ -7927,48 +7931,40 @@ static void zig_llvm_emit_output(CodeGen *g) { |
| 7927 | 7931 | |
| 7928 | 7932 | Buf *output_path = &g->o_file_output_path; |
| 7929 | 7933 | char *err_msg = nullptr; |
| 7930 | | switch (g->emit_file_type) { |
| 7931 | | case EmitFileTypeBinary: |
| 7932 | | if (g->disable_bin_generation) |
| 7933 | | return; |
| 7934 | | if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), |
| 7935 | | ZigLLVM_EmitBinary, &err_msg, g->build_mode == BuildModeDebug, is_small, |
| 7936 | | g->enable_time_report)) |
| 7937 | | { |
| 7938 | | zig_panic("unable to write object file %s: %s", buf_ptr(output_path), err_msg); |
| 7939 | | } |
| 7940 | | validate_inline_fns(g); |
| 7941 | | g->link_objects.append(output_path); |
| 7942 | | if (g->bundle_compiler_rt && (g->out_type == OutTypeObj || |
| 7943 | | (g->out_type == OutTypeLib && !g->is_dynamic))) |
| 7944 | | { |
| 7945 | | zig_link_add_compiler_rt(g, g->sub_progress_node); |
| 7946 | | } |
| 7947 | | break; |
| 7948 | | |
| 7949 | | case EmitFileTypeAssembly: |
| 7950 | | if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), |
| 7951 | | ZigLLVM_EmitAssembly, &err_msg, g->build_mode == BuildModeDebug, is_small, |
| 7952 | | g->enable_time_report)) |
| 7953 | | { |
| 7954 | | zig_panic("unable to write assembly file %s: %s", buf_ptr(output_path), err_msg); |
| 7955 | | } |
| 7956 | | validate_inline_fns(g); |
| 7957 | | break; |
| 7958 | | |
| 7959 | | case EmitFileTypeLLVMIr: |
| 7960 | | if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), |
| 7961 | | ZigLLVM_EmitLLVMIr, &err_msg, g->build_mode == BuildModeDebug, is_small, |
| 7962 | | g->enable_time_report)) |
| 7963 | | { |
| 7964 | | zig_panic("unable to write llvm-ir file %s: %s", buf_ptr(output_path), err_msg); |
| 7965 | | } |
| 7966 | | validate_inline_fns(g); |
| 7967 | | break; |
| 7968 | | |
| 7969 | | default: |
| 7970 | | zig_unreachable(); |
| 7934 | if (!g->disable_bin_generation) { |
| 7935 | if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), |
| 7936 | ZigLLVM_EmitBinary, &err_msg, g->build_mode == BuildModeDebug, is_small, |
| 7937 | g->enable_time_report)) |
| 7938 | { |
| 7939 | zig_panic("unable to write object file %s: %s", buf_ptr(output_path), err_msg); |
| 7940 | } |
| 7941 | validate_inline_fns(g); |
| 7942 | g->link_objects.append(output_path); |
| 7943 | if (g->bundle_compiler_rt && (g->out_type == OutTypeObj || |
| 7944 | (g->out_type == OutTypeLib && !g->is_dynamic))) |
| 7945 | { |
| 7946 | zig_link_add_compiler_rt(g, g->sub_progress_node); |
| 7947 | } |
| 7971 | 7948 | } |
| 7949 | if (g->emit_asm) { |
| 7950 | if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), |
| 7951 | ZigLLVM_EmitAssembly, &err_msg, g->build_mode == BuildModeDebug, is_small, |
| 7952 | g->enable_time_report)) |
| 7953 | { |
| 7954 | zig_panic("unable to write assembly file %s: %s", buf_ptr(output_path), err_msg); |
| 7955 | } |
| 7956 | validate_inline_fns(g); |
| 7957 | } |
| 7958 | if (g->emit_llvm_ir) { |
| 7959 | if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), |
| 7960 | ZigLLVM_EmitLLVMIr, &err_msg, g->build_mode == BuildModeDebug, is_small, |
| 7961 | g->enable_time_report)) |
| 7962 | { |
| 7963 | zig_panic("unable to write llvm-ir file %s: %s", buf_ptr(output_path), err_msg); |
| 7964 | } |
| 7965 | validate_inline_fns(g); |
| 7966 | } |
| 7967 | |
| 7972 | 7968 | LLVMDisposeModule(g->module); |
| 7973 | 7969 | g->module = nullptr; |
| 7974 | 7970 | LLVMDisposeTargetData(g->target_data_ref); |
| ... | ... | @@ -10497,53 +10493,48 @@ static void resolve_out_paths(CodeGen *g) { |
| 10497 | 10493 | |
| 10498 | 10494 | Buf *out_basename = buf_create_from_buf(g->root_out_name); |
| 10499 | 10495 | Buf *o_basename = buf_create_from_buf(g->root_out_name); |
| 10500 | | switch (g->emit_file_type) { |
| 10501 | | case EmitFileTypeBinary: { |
| 10502 | | switch (g->out_type) { |
| 10503 | | case OutTypeUnknown: |
| 10504 | | zig_unreachable(); |
| 10505 | | case OutTypeObj: |
| 10506 | | if (g->enable_cache && g->link_objects.length == 1 && !need_llvm_module(g)) { |
| 10507 | | buf_init_from_buf(&g->output_file_path, g->link_objects.at(0)); |
| 10508 | | return; |
| 10509 | | } |
| 10510 | | if (need_llvm_module(g) && g->link_objects.length != 0 && !g->enable_cache && |
| 10511 | | buf_eql_buf(o_basename, out_basename)) |
| 10512 | | { |
| 10513 | | // make it not collide with main output object |
| 10514 | | buf_append_str(o_basename, ".root"); |
| 10515 | | } |
| 10516 | | buf_append_str(o_basename, target_o_file_ext(g->zig_target)); |
| 10517 | | buf_append_str(out_basename, target_o_file_ext(g->zig_target)); |
| 10518 | | break; |
| 10519 | | case OutTypeExe: |
| 10520 | | buf_append_str(o_basename, target_o_file_ext(g->zig_target)); |
| 10521 | | buf_append_str(out_basename, target_exe_file_ext(g->zig_target)); |
| 10522 | | break; |
| 10523 | | case OutTypeLib: |
| 10524 | | buf_append_str(o_basename, target_o_file_ext(g->zig_target)); |
| 10525 | | buf_resize(out_basename, 0); |
| 10526 | | buf_append_str(out_basename, target_lib_file_prefix(g->zig_target)); |
| 10527 | | buf_append_buf(out_basename, g->root_out_name); |
| 10528 | | buf_append_str(out_basename, target_lib_file_ext(g->zig_target, !g->is_dynamic, |
| 10529 | | g->version_major, g->version_minor, g->version_patch)); |
| 10530 | | break; |
| 10531 | | } |
| 10532 | | break; |
| 10533 | | } |
| 10534 | | case EmitFileTypeAssembly: { |
| 10535 | | const char *asm_ext = target_asm_file_ext(g->zig_target); |
| 10536 | | buf_append_str(o_basename, asm_ext); |
| 10537 | | buf_append_str(out_basename, asm_ext); |
| 10538 | | break; |
| 10539 | | } |
| 10540 | | case EmitFileTypeLLVMIr: { |
| 10541 | | const char *llvm_ir_ext = target_llvm_ir_file_ext(g->zig_target); |
| 10542 | | buf_append_str(o_basename, llvm_ir_ext); |
| 10543 | | buf_append_str(out_basename, llvm_ir_ext); |
| 10544 | | break; |
| 10496 | if (!g->disable_bin_generation) { |
| 10497 | switch (g->out_type) { |
| 10498 | case OutTypeUnknown: |
| 10499 | zig_unreachable(); |
| 10500 | case OutTypeObj: |
| 10501 | if (g->enable_cache && g->link_objects.length == 1 && !need_llvm_module(g)) { |
| 10502 | buf_init_from_buf(&g->output_file_path, g->link_objects.at(0)); |
| 10503 | return; |
| 10504 | } |
| 10505 | if (need_llvm_module(g) && g->link_objects.length != 0 && !g->enable_cache && |
| 10506 | buf_eql_buf(o_basename, out_basename)) |
| 10507 | { |
| 10508 | // make it not collide with main output object |
| 10509 | buf_append_str(o_basename, ".root"); |
| 10510 | } |
| 10511 | buf_append_str(o_basename, target_o_file_ext(g->zig_target)); |
| 10512 | buf_append_str(out_basename, target_o_file_ext(g->zig_target)); |
| 10513 | break; |
| 10514 | case OutTypeExe: |
| 10515 | buf_append_str(o_basename, target_o_file_ext(g->zig_target)); |
| 10516 | buf_append_str(out_basename, target_exe_file_ext(g->zig_target)); |
| 10517 | break; |
| 10518 | case OutTypeLib: |
| 10519 | buf_append_str(o_basename, target_o_file_ext(g->zig_target)); |
| 10520 | buf_resize(out_basename, 0); |
| 10521 | buf_append_str(out_basename, target_lib_file_prefix(g->zig_target)); |
| 10522 | buf_append_buf(out_basename, g->root_out_name); |
| 10523 | buf_append_str(out_basename, target_lib_file_ext(g->zig_target, !g->is_dynamic, |
| 10524 | g->version_major, g->version_minor, g->version_patch)); |
| 10525 | break; |
| 10545 | 10526 | } |
| 10546 | 10527 | } |
| 10528 | else if (g->emit_asm) { |
| 10529 | const char *asm_ext = target_asm_file_ext(g->zig_target); |
| 10530 | buf_append_str(o_basename, asm_ext); |
| 10531 | buf_append_str(out_basename, asm_ext); |
| 10532 | } |
| 10533 | else if (g->emit_llvm_ir) { |
| 10534 | const char *llvm_ir_ext = target_llvm_ir_file_ext(g->zig_target); |
| 10535 | buf_append_str(o_basename, llvm_ir_ext); |
| 10536 | buf_append_str(out_basename, llvm_ir_ext); |
| 10537 | } |
| 10547 | 10538 | |
| 10548 | 10539 | os_path_join(g->output_dir, o_basename, &g->o_file_output_path); |
| 10549 | 10540 | os_path_join(g->output_dir, out_basename, &g->output_file_path); |
| ... | ... | @@ -10708,7 +10699,7 @@ void codegen_build_and_link(CodeGen *g) { |
| 10708 | 10699 | // If there is more than one object, we have to link them (with -r). |
| 10709 | 10700 | // Finally, if we didn't make an object from zig source, and we don't have caching enabled, |
| 10710 | 10701 | // then we have an object from C source that we must copy to the output dir which we do with a -r link. |
| 10711 | | if (!g->disable_bin_generation && g->emit_file_type == EmitFileTypeBinary && |
| 10702 | if (!g->disable_bin_generation && |
| 10712 | 10703 | (g->out_type != OutTypeObj || g->link_objects.length > 1 || |
| 10713 | 10704 | (!need_llvm_module(g) && !g->enable_cache))) |
| 10714 | 10705 | { |