@@ -189,6 +189,10 @@ void codegen_set_is_test(CodeGen *g, bool is_test_build) {
189
189
g->is_test_build = is_test_build;
190
190
}
191
191
192
+ void codegen_set_emit_file_type (CodeGen *g, EmitFileType emit_file_type) {
193
+ g->emit_file_type = emit_file_type;
194
+ }
195
+
192
196
void codegen_set_is_static (CodeGen *g, bool is_static) {
193
197
g->is_static = is_static;
194
198
}
@@ -4493,24 +4497,70 @@ static void do_code_gen(CodeGen *g) {
4493
4497
LLVMVerifyModule (g->module , LLVMAbortProcessAction, &error);
4494
4498
#endif
4495
4499
4496
- codegen_add_time_event (g, " LLVM Emit Object " );
4500
+ codegen_add_time_event (g, " LLVM Emit Output " );
4497
4501
4498
4502
char *err_msg = nullptr ;
4499
4503
Buf *o_basename = buf_create_from_buf (g->root_out_name );
4500
- const char *o_ext = target_o_file_ext (&g->zig_target );
4501
- buf_append_str (o_basename, o_ext);
4504
+
4505
+ switch (g->emit_file_type ) {
4506
+ case EmitFileTypeBinary:
4507
+ {
4508
+ const char *o_ext = target_o_file_ext (&g->zig_target );
4509
+ buf_append_str (o_basename, o_ext);
4510
+ break ;
4511
+ }
4512
+ case EmitFileTypeAssembly:
4513
+ {
4514
+ const char *asm_ext = target_asm_file_ext (&g->zig_target );
4515
+ buf_append_str (o_basename, asm_ext);
4516
+ break ;
4517
+ }
4518
+ case EmitFileTypeLLVMIr:
4519
+ {
4520
+ const char *llvm_ir_ext = target_llvm_ir_file_ext (&g->zig_target );
4521
+ buf_append_str (o_basename, llvm_ir_ext);
4522
+ break ;
4523
+ }
4524
+ default :
4525
+ zig_unreachable ();
4526
+ }
4527
+
4502
4528
Buf *output_path = buf_alloc ();
4503
4529
os_path_join (g->cache_dir , o_basename, output_path);
4504
4530
ensure_cache_dir (g);
4505
- if (ZigLLVMTargetMachineEmitToFile (g->target_machine , g->module , buf_ptr (output_path),
4506
- LLVMObjectFile, &err_msg, g->build_mode == BuildModeDebug))
4507
- {
4508
- zig_panic (" unable to write object file %s: %s" , buf_ptr (output_path), err_msg);
4509
- }
4510
4531
4511
- validate_inline_fns (g);
4532
+ switch (g->emit_file_type ) {
4533
+ case EmitFileTypeBinary:
4534
+ if (ZigLLVMTargetMachineEmitToFile (g->target_machine , g->module , buf_ptr (output_path),
4535
+ ZigLLVM_EmitBinary, &err_msg, g->build_mode == BuildModeDebug))
4536
+ {
4537
+ zig_panic (" unable to write object file %s: %s" , buf_ptr (output_path), err_msg);
4538
+ }
4539
+ validate_inline_fns (g);
4540
+ g->link_objects .append (output_path);
4541
+ break ;
4542
+
4543
+ case EmitFileTypeAssembly:
4544
+ if (ZigLLVMTargetMachineEmitToFile (g->target_machine , g->module , buf_ptr (output_path),
4545
+ ZigLLVM_EmitAssembly, &err_msg, g->build_mode == BuildModeDebug))
4546
+ {
4547
+ zig_panic (" unable to write assembly file %s: %s" , buf_ptr (output_path), err_msg);
4548
+ }
4549
+ validate_inline_fns (g);
4550
+ break ;
4551
+
4552
+ case EmitFileTypeLLVMIr:
4553
+ if (ZigLLVMTargetMachineEmitToFile (g->target_machine , g->module , buf_ptr (output_path),
4554
+ ZigLLVM_EmitLLVMIr, &err_msg, g->build_mode == BuildModeDebug))
4555
+ {
4556
+ zig_panic (" unable to write llvm-ir file %s: %s" , buf_ptr (output_path), err_msg);
4557
+ }
4558
+ validate_inline_fns (g);
4559
+ break ;
4512
4560
4513
- g->link_objects .append (output_path);
4561
+ default :
4562
+ zig_unreachable ();
4563
+ }
4514
4564
}
4515
4565
4516
4566
static const uint8_t int_sizes_in_bits[] = {
0 commit comments