| author | |
| committer | |
| log | 2502cb242a0da5112c2cf9b0974ffd68aa27ecc8 |
| tree | 6bb374c66974e22e020e6f3d4999d1934d2c1286 |
| parent | cbc4e59e6805d27f0e889c0a9ff8488376cea5c0 |
| signature |
5 files changed, 122 insertions(+), 109 deletions(-)
lib/std/build.zig+10| ... | @@ -1155,6 +1155,9 @@ pub const LibExeObjStep = struct { | ... | @@ -1155,6 +1155,9 @@ pub const LibExeObjStep = struct { |
| 1155 | frameworks: BufSet, | 1155 | frameworks: BufSet, |
| 1156 | verbose_link: bool, | 1156 | verbose_link: bool, |
| 1157 | verbose_cc: bool, | 1157 | verbose_cc: bool, |
| 1158 | produce_ir: bool, | ||
| 1159 | produce_asm: bool, | ||
| 1160 | produce_bin: bool, | ||
| 1158 | disable_gen_h: bool, | 1161 | disable_gen_h: bool, |
| 1159 | bundle_compiler_rt: bool, | 1162 | bundle_compiler_rt: bool, |
| 1160 | disable_stack_probing: bool, | 1163 | disable_stack_probing: bool, |
| ... | @@ -1285,6 +1288,9 @@ pub const LibExeObjStep = struct { | ... | @@ -1285,6 +1288,9 @@ pub const LibExeObjStep = struct { |
| 1285 | .builder = builder, | 1288 | .builder = builder, |
| 1286 | .verbose_link = false, | 1289 | .verbose_link = false, |
| 1287 | .verbose_cc = false, | 1290 | .verbose_cc = false, |
| 1291 | .produce_ir = false, | ||
| 1292 | .produce_asm = false, | ||
| 1293 | .produce_bin = true, | ||
| 1288 | .build_mode = builtin.Mode.Debug, | 1294 | .build_mode = builtin.Mode.Debug, |
| 1289 | .is_dynamic = is_dynamic, | 1295 | .is_dynamic = is_dynamic, |
| 1290 | .kind = kind, | 1296 | .kind = kind, |
| ... | @@ -1941,6 +1947,10 @@ pub const LibExeObjStep = struct { | ... | @@ -1941,6 +1947,10 @@ pub const LibExeObjStep = struct { |
| 1941 | if (builder.verbose_link or self.verbose_link) zig_args.append("--verbose-link") catch unreachable; | 1947 | if (builder.verbose_link or self.verbose_link) zig_args.append("--verbose-link") catch unreachable; |
| 1942 | if (builder.verbose_cc or self.verbose_cc) zig_args.append("--verbose-cc") catch unreachable; | 1948 | if (builder.verbose_cc or self.verbose_cc) zig_args.append("--verbose-cc") catch unreachable; |
| 1943 | 1949 | ||
| 1950 | try zig_args.append(if (self.produce_ir) "-femit-llvm-ir" else "-fno-emit-llvm-ir"); | ||
| 1951 | try zig_args.append(if (self.produce_asm) "-femit-asm" else "-fno-emit-asm"); | ||
| 1952 | try zig_args.append(if (self.produce_bin) "-femit-bin" else "-fno-emit-bin"); | ||
| 1953 | |||
| 1944 | if (self.strip) { | 1954 | if (self.strip) { |
| 1945 | try zig_args.append("--strip"); | 1955 | try zig_args.append("--strip"); |
| 1946 | } | 1956 | } |
src/all_types.hpp+2-7| ... | @@ -1966,12 +1966,6 @@ enum CodeModel { | ... | @@ -1966,12 +1966,6 @@ enum CodeModel { |
| 1966 | CodeModelLarge, | 1966 | CodeModelLarge, |
| 1967 | }; | 1967 | }; |
| 1968 | 1968 | ||
| 1969 | enum EmitFileType { | ||
| 1970 | EmitFileTypeBinary, | ||
| 1971 | EmitFileTypeAssembly, | ||
| 1972 | EmitFileTypeLLVMIr, | ||
| 1973 | }; | ||
| 1974 | |||
| 1975 | struct LinkLib { | 1969 | struct LinkLib { |
| 1976 | Buf *name; | 1970 | Buf *name; |
| 1977 | Buf *path; | 1971 | Buf *path; |
| ... | @@ -2204,6 +2198,8 @@ struct CodeGen { | ... | @@ -2204,6 +2198,8 @@ struct CodeGen { |
| 2204 | bool verbose_cimport; | 2198 | bool verbose_cimport; |
| 2205 | bool verbose_cc; | 2199 | bool verbose_cc; |
| 2206 | bool verbose_llvm_cpu_features; | 2200 | bool verbose_llvm_cpu_features; |
| 2201 | bool emit_asm; | ||
| 2202 | bool emit_llvm_ir; | ||
| 2207 | bool error_during_imports; | 2203 | bool error_during_imports; |
| 2208 | bool generate_error_name_table; | 2204 | bool generate_error_name_table; |
| 2209 | bool enable_cache; // mutually exclusive with output_dir | 2205 | bool enable_cache; // mutually exclusive with output_dir |
| ... | @@ -2236,7 +2232,6 @@ struct CodeGen { | ... | @@ -2236,7 +2232,6 @@ struct CodeGen { |
| 2236 | size_t version_patch; | 2232 | size_t version_patch; |
| 2237 | const char *linker_script; | 2233 | const char *linker_script; |
| 2238 | 2234 | ||
| 2239 | EmitFileType emit_file_type; | ||
| 2240 | BuildMode build_mode; | 2235 | BuildMode build_mode; |
| 2241 | OutType out_type; | 2236 | OutType out_type; |
| 2242 | const ZigTarget *zig_target; | 2237 | const ZigTarget *zig_target; |
src/codegen.cpp+82-91| ... | @@ -121,10 +121,6 @@ void codegen_set_lib_version(CodeGen *g, size_t major, size_t minor, size_t patc | ... | @@ -121,10 +121,6 @@ void codegen_set_lib_version(CodeGen *g, size_t major, size_t minor, size_t patc |
| 121 | g->version_patch = patch; | 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 | void codegen_set_each_lib_rpath(CodeGen *g, bool each_lib_rpath) { | 124 | void codegen_set_each_lib_rpath(CodeGen *g, bool each_lib_rpath) { |
| 129 | g->each_lib_rpath = each_lib_rpath; | 125 | g->each_lib_rpath = each_lib_rpath; |
| 130 | } | 126 | } |
| ... | @@ -7919,6 +7915,14 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -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 | static void zig_llvm_emit_output(CodeGen *g) { | 7926 | static void zig_llvm_emit_output(CodeGen *g) { |
| 7923 | g->pass1_arena->destruct(&heap::c_allocator); | 7927 | g->pass1_arena->destruct(&heap::c_allocator); |
| 7924 | g->pass1_arena = nullptr; | 7928 | g->pass1_arena = nullptr; |
| ... | @@ -7927,48 +7931,40 @@ static void zig_llvm_emit_output(CodeGen *g) { | ... | @@ -7927,48 +7931,40 @@ static void zig_llvm_emit_output(CodeGen *g) { |
| 7927 | 7931 | ||
| 7928 | Buf *output_path = &g->o_file_output_path; | 7932 | Buf *output_path = &g->o_file_output_path; |
| 7929 | char *err_msg = nullptr; | 7933 | char *err_msg = nullptr; |
| 7930 | switch (g->emit_file_type) { | 7934 | if (!g->disable_bin_generation) { |
| 7931 | case EmitFileTypeBinary: | 7935 | if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), |
| 7932 | if (g->disable_bin_generation) | 7936 | ZigLLVM_EmitBinary, &err_msg, g->build_mode == BuildModeDebug, is_small, |
| 7933 | return; | 7937 | g->enable_time_report)) |
| 7934 | if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), | 7938 | { |
| 7935 | ZigLLVM_EmitBinary, &err_msg, g->build_mode == BuildModeDebug, is_small, | 7939 | zig_panic("unable to write object file %s: %s", buf_ptr(output_path), err_msg); |
| 7936 | g->enable_time_report)) | 7940 | } |
| 7937 | { | 7941 | validate_inline_fns(g); |
| 7938 | zig_panic("unable to write object file %s: %s", buf_ptr(output_path), err_msg); | 7942 | g->link_objects.append(output_path); |
| 7939 | } | 7943 | if (g->bundle_compiler_rt && (g->out_type == OutTypeObj || |
| 7940 | validate_inline_fns(g); | 7944 | (g->out_type == OutTypeLib && !g->is_dynamic))) |
| 7941 | g->link_objects.append(output_path); | 7945 | { |
| 7942 | if (g->bundle_compiler_rt && (g->out_type == OutTypeObj || | 7946 | zig_link_add_compiler_rt(g, g->sub_progress_node); |
| 7943 | (g->out_type == OutTypeLib && !g->is_dynamic))) | 7947 | } |
| 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(); | ||
| 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 | LLVMDisposeModule(g->module); | 7968 | LLVMDisposeModule(g->module); |
| 7973 | g->module = nullptr; | 7969 | g->module = nullptr; |
| 7974 | LLVMDisposeTargetData(g->target_data_ref); | 7970 | LLVMDisposeTargetData(g->target_data_ref); |
| ... | @@ -10497,53 +10493,48 @@ static void resolve_out_paths(CodeGen *g) { | ... | @@ -10497,53 +10493,48 @@ static void resolve_out_paths(CodeGen *g) { |
| 10497 | 10493 | ||
| 10498 | Buf *out_basename = buf_create_from_buf(g->root_out_name); | 10494 | Buf *out_basename = buf_create_from_buf(g->root_out_name); |
| 10499 | Buf *o_basename = buf_create_from_buf(g->root_out_name); | 10495 | Buf *o_basename = buf_create_from_buf(g->root_out_name); |
| 10500 | switch (g->emit_file_type) { | 10496 | if (!g->disable_bin_generation) { |
| 10501 | case EmitFileTypeBinary: { | 10497 | switch (g->out_type) { |
| 10502 | switch (g->out_type) { | 10498 | case OutTypeUnknown: |
| 10503 | case OutTypeUnknown: | 10499 | zig_unreachable(); |
| 10504 | zig_unreachable(); | 10500 | case OutTypeObj: |
| 10505 | case OutTypeObj: | 10501 | if (g->enable_cache && g->link_objects.length == 1 && !need_llvm_module(g)) { |
| 10506 | 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)); |
| 10507 | buf_init_from_buf(&g->output_file_path, g->link_objects.at(0)); | 10503 | return; |
| 10508 | return; | 10504 | } |
| 10509 | } | 10505 | if (need_llvm_module(g) && g->link_objects.length != 0 && !g->enable_cache && |
| 10510 | if (need_llvm_module(g) && g->link_objects.length != 0 && !g->enable_cache && | 10506 | buf_eql_buf(o_basename, out_basename)) |
| 10511 | buf_eql_buf(o_basename, out_basename)) | 10507 | { |
| 10512 | { | 10508 | // make it not collide with main output object |
| 10513 | // make it not collide with main output object | 10509 | buf_append_str(o_basename, ".root"); |
| 10514 | buf_append_str(o_basename, ".root"); | 10510 | } |
| 10515 | } | 10511 | buf_append_str(o_basename, target_o_file_ext(g->zig_target)); |
| 10516 | 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)); |
| 10517 | buf_append_str(out_basename, target_o_file_ext(g->zig_target)); | 10513 | break; |
| 10518 | break; | 10514 | case OutTypeExe: |
| 10519 | case OutTypeExe: | 10515 | buf_append_str(o_basename, target_o_file_ext(g->zig_target)); |
| 10520 | 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)); |
| 10521 | buf_append_str(out_basename, target_exe_file_ext(g->zig_target)); | 10517 | break; |
| 10522 | break; | 10518 | case OutTypeLib: |
| 10523 | case OutTypeLib: | 10519 | buf_append_str(o_basename, target_o_file_ext(g->zig_target)); |
| 10524 | buf_append_str(o_basename, target_o_file_ext(g->zig_target)); | 10520 | buf_resize(out_basename, 0); |
| 10525 | buf_resize(out_basename, 0); | 10521 | buf_append_str(out_basename, target_lib_file_prefix(g->zig_target)); |
| 10526 | buf_append_str(out_basename, target_lib_file_prefix(g->zig_target)); | 10522 | buf_append_buf(out_basename, g->root_out_name); |
| 10527 | 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, |
| 10528 | 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)); |
| 10529 | g->version_major, g->version_minor, g->version_patch)); | 10525 | break; |
| 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; | ||
| 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 | os_path_join(g->output_dir, o_basename, &g->o_file_output_path); | 10539 | os_path_join(g->output_dir, o_basename, &g->o_file_output_path); |
| 10549 | os_path_join(g->output_dir, out_basename, &g->output_file_path); | 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,7 +10699,7 @@ void codegen_build_and_link(CodeGen *g) { |
| 10708 | // If there is more than one object, we have to link them (with -r). | 10699 | // If there is more than one object, we have to link them (with -r). |
| 10709 | // Finally, if we didn't make an object from zig source, and we don't have caching enabled, | 10700 | // Finally, if we didn't make an object from zig source, and we don't have caching enabled, |
| 10710 | // then we have an object from C source that we must copy to the output dir which we do with a -r link. | 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 | (g->out_type != OutTypeObj || g->link_objects.length > 1 || | 10703 | (g->out_type != OutTypeObj || g->link_objects.length > 1 || |
| 10713 | (!need_llvm_module(g) && !g->enable_cache))) | 10704 | (!need_llvm_module(g) && !g->enable_cache))) |
| 10714 | { | 10705 | { |
src/codegen.hpp+3-1| ... | @@ -26,7 +26,9 @@ void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len); | ... | @@ -26,7 +26,9 @@ void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len); |
| 26 | void codegen_set_llvm_argv(CodeGen *codegen, const char **args, size_t len); | 26 | void codegen_set_llvm_argv(CodeGen *codegen, const char **args, size_t len); |
| 27 | void codegen_set_each_lib_rpath(CodeGen *codegen, bool each_lib_rpath); | 27 | void codegen_set_each_lib_rpath(CodeGen *codegen, bool each_lib_rpath); |
| 28 | 28 | ||
| 29 | void codegen_set_emit_file_type(CodeGen *g, EmitFileType emit_file_type); | 29 | void codegen_set_emit_asm(CodeGen *codegen, bool emit); |
| 30 | void codegen_set_emit_llvm_ir(CodeGen *codegen, bool emit); | ||
| 31 | |||
| 30 | void codegen_set_strip(CodeGen *codegen, bool strip); | 32 | void codegen_set_strip(CodeGen *codegen, bool strip); |
| 31 | void codegen_set_errmsg_color(CodeGen *codegen, ErrColor err_color); | 33 | void codegen_set_errmsg_color(CodeGen *codegen, ErrColor err_color); |
| 32 | void codegen_set_out_name(CodeGen *codegen, Buf *out_name); | 34 | void codegen_set_out_name(CodeGen *codegen, Buf *out_name); |
src/main.cpp+25-10| ... | @@ -376,7 +376,6 @@ static int main0(int argc, char **argv) { | ... | @@ -376,7 +376,6 @@ static int main0(int argc, char **argv) { |
| 376 | } | 376 | } |
| 377 | 377 | ||
| 378 | Cmd cmd = CmdNone; | 378 | Cmd cmd = CmdNone; |
| 379 | EmitFileType emit_file_type = EmitFileTypeBinary; | ||
| 380 | const char *in_file = nullptr; | 379 | const char *in_file = nullptr; |
| 381 | Buf *output_dir = nullptr; | 380 | Buf *output_dir = nullptr; |
| 382 | bool strip = false; | 381 | bool strip = false; |
| ... | @@ -425,6 +424,8 @@ static int main0(int argc, char **argv) { | ... | @@ -425,6 +424,8 @@ static int main0(int argc, char **argv) { |
| 425 | bool enable_dump_analysis = false; | 424 | bool enable_dump_analysis = false; |
| 426 | bool enable_doc_generation = false; | 425 | bool enable_doc_generation = false; |
| 427 | bool disable_bin_generation = false; | 426 | bool disable_bin_generation = false; |
| 427 | bool emit_asm = false; | ||
| 428 | bool emit_llvm_ir = false; | ||
| 428 | const char *cache_dir = nullptr; | 429 | const char *cache_dir = nullptr; |
| 429 | CliPkg *cur_pkg = heap::c_allocator.create<CliPkg>(); | 430 | CliPkg *cur_pkg = heap::c_allocator.create<CliPkg>(); |
| 430 | BuildMode build_mode = BuildModeDebug; | 431 | BuildMode build_mode = BuildModeDebug; |
| ... | @@ -701,6 +702,18 @@ static int main0(int argc, char **argv) { | ... | @@ -701,6 +702,18 @@ static int main0(int argc, char **argv) { |
| 701 | function_sections = true; | 702 | function_sections = true; |
| 702 | } else if (strcmp(arg, "--test-evented-io") == 0) { | 703 | } else if (strcmp(arg, "--test-evented-io") == 0) { |
| 703 | test_evented_io = true; | 704 | test_evented_io = true; |
| 705 | } else if (strcmp(arg, "-femit-bin") == 0) { | ||
| 706 | disable_bin_generation = false; | ||
| 707 | } else if (strcmp(arg, "-fno-emit-bin") == 0) { | ||
| 708 | disable_bin_generation = true; | ||
| 709 | } else if (strcmp(arg, "-femit-asm") == 0) { | ||
| 710 | emit_asm = true; | ||
| 711 | } else if (strcmp(arg, "-fno-emit-asm") == 0) { | ||
| 712 | emit_asm = false; | ||
| 713 | } else if (strcmp(arg, "-femit-llvm-ir") == 0) { | ||
| 714 | emit_llvm_ir = true; | ||
| 715 | } else if (strcmp(arg, "-fno-emit-llvm-ir") == 0) { | ||
| 716 | emit_llvm_ir = false; | ||
| 704 | } else if (i + 1 >= argc) { | 717 | } else if (i + 1 >= argc) { |
| 705 | fprintf(stderr, "Expected another argument after %s\n", arg); | 718 | fprintf(stderr, "Expected another argument after %s\n", arg); |
| 706 | return print_error_usage(arg0); | 719 | return print_error_usage(arg0); |
| ... | @@ -732,11 +745,11 @@ static int main0(int argc, char **argv) { | ... | @@ -732,11 +745,11 @@ static int main0(int argc, char **argv) { |
| 732 | } | 745 | } |
| 733 | } else if (strcmp(arg, "--emit") == 0) { | 746 | } else if (strcmp(arg, "--emit") == 0) { |
| 734 | if (strcmp(argv[i], "asm") == 0) { | 747 | if (strcmp(argv[i], "asm") == 0) { |
| 735 | emit_file_type = EmitFileTypeAssembly; | 748 | emit_asm = true; |
| 736 | } else if (strcmp(argv[i], "bin") == 0) { | 749 | } else if (strcmp(argv[i], "bin") == 0) { |
| 737 | emit_file_type = EmitFileTypeBinary; | 750 | disable_bin_generation = false; |
| 738 | } else if (strcmp(argv[i], "llvm-ir") == 0) { | 751 | } else if (strcmp(argv[i], "llvm-ir") == 0) { |
| 739 | emit_file_type = EmitFileTypeLLVMIr; | 752 | emit_llvm_ir = true; |
| 740 | } else { | 753 | } else { |
| 741 | fprintf(stderr, "--emit options are 'asm', 'bin', or 'llvm-ir'\n"); | 754 | fprintf(stderr, "--emit options are 'asm', 'bin', or 'llvm-ir'\n"); |
| 742 | return print_error_usage(arg0); | 755 | return print_error_usage(arg0); |
| ... | @@ -1026,8 +1039,8 @@ static int main0(int argc, char **argv) { | ... | @@ -1026,8 +1039,8 @@ static int main0(int argc, char **argv) { |
| 1026 | return print_error_usage(arg0); | 1039 | return print_error_usage(arg0); |
| 1027 | } | 1040 | } |
| 1028 | 1041 | ||
| 1029 | if (emit_file_type != EmitFileTypeBinary && in_file == nullptr) { | 1042 | if ((emit_asm || emit_llvm_ir) && in_file == nullptr) { |
| 1030 | fprintf(stderr, "A root source file is required when using `--emit asm` or `--emit llvm-ir`\n"); | 1043 | fprintf(stderr, "A root source file is required when using `-femit-asm` or `-femit-llvm-ir`\n"); |
| 1031 | return print_error_usage(arg0); | 1044 | return print_error_usage(arg0); |
| 1032 | } | 1045 | } |
| 1033 | 1046 | ||
| ... | @@ -1098,7 +1111,7 @@ static int main0(int argc, char **argv) { | ... | @@ -1098,7 +1111,7 @@ static int main0(int argc, char **argv) { |
| 1098 | { | 1111 | { |
| 1099 | fprintf(stderr, "Expected source file argument.\n"); | 1112 | fprintf(stderr, "Expected source file argument.\n"); |
| 1100 | return print_error_usage(arg0); | 1113 | return print_error_usage(arg0); |
| 1101 | } else if (cmd == CmdRun && emit_file_type != EmitFileTypeBinary) { | 1114 | } else if (cmd == CmdRun && disable_bin_generation) { |
| 1102 | fprintf(stderr, "Cannot run non-executable file.\n"); | 1115 | fprintf(stderr, "Cannot run non-executable file.\n"); |
| 1103 | return print_error_usage(arg0); | 1116 | return print_error_usage(arg0); |
| 1104 | } | 1117 | } |
| ... | @@ -1262,7 +1275,8 @@ static int main0(int argc, char **argv) { | ... | @@ -1262,7 +1275,8 @@ static int main0(int argc, char **argv) { |
| 1262 | 1275 | ||
| 1263 | 1276 | ||
| 1264 | if (cmd == CmdBuild || cmd == CmdRun) { | 1277 | if (cmd == CmdBuild || cmd == CmdRun) { |
| 1265 | codegen_set_emit_file_type(g, emit_file_type); | 1278 | codegen_set_emit_asm(g, emit_asm); |
| 1279 | codegen_set_emit_llvm_ir(g, emit_llvm_ir); | ||
| 1266 | 1280 | ||
| 1267 | g->enable_cache = get_cache_opt(enable_cache, cmd == CmdRun); | 1281 | g->enable_cache = get_cache_opt(enable_cache, cmd == CmdRun); |
| 1268 | codegen_build_and_link(g); | 1282 | codegen_build_and_link(g); |
| ... | @@ -1330,7 +1344,8 @@ static int main0(int argc, char **argv) { | ... | @@ -1330,7 +1344,8 @@ static int main0(int argc, char **argv) { |
| 1330 | codegen_print_timing_report(g, stderr); | 1344 | codegen_print_timing_report(g, stderr); |
| 1331 | return main_exit(root_progress_node, EXIT_SUCCESS); | 1345 | return main_exit(root_progress_node, EXIT_SUCCESS); |
| 1332 | } else if (cmd == CmdTest) { | 1346 | } else if (cmd == CmdTest) { |
| 1333 | codegen_set_emit_file_type(g, emit_file_type); | 1347 | codegen_set_emit_asm(g, emit_asm); |
| 1348 | codegen_set_emit_llvm_ir(g, emit_llvm_ir); | ||
| 1334 | 1349 | ||
| 1335 | ZigTarget native; | 1350 | ZigTarget native; |
| 1336 | get_native_target(&native); | 1351 | get_native_target(&native); |
| ... | @@ -1359,7 +1374,7 @@ static int main0(int argc, char **argv) { | ... | @@ -1359,7 +1374,7 @@ static int main0(int argc, char **argv) { |
| 1359 | Buf *test_exe_path = buf_alloc(); | 1374 | Buf *test_exe_path = buf_alloc(); |
| 1360 | *test_exe_path = os_path_resolve(&test_exe_path_unresolved, 1); | 1375 | *test_exe_path = os_path_resolve(&test_exe_path_unresolved, 1); |
| 1361 | 1376 | ||
| 1362 | if (emit_file_type != EmitFileTypeBinary) { | 1377 | if (disable_bin_generation) { |
| 1363 | fprintf(stderr, "Created %s but skipping execution because it is non executable.\n", | 1378 | fprintf(stderr, "Created %s but skipping execution because it is non executable.\n", |
| 1364 | buf_ptr(test_exe_path)); | 1379 | buf_ptr(test_exe_path)); |
| 1365 | return main_exit(root_progress_node, EXIT_SUCCESS); | 1380 | return main_exit(root_progress_node, EXIT_SUCCESS); |