From d3b61c9808e882c19798c97e67eb7fffebef1efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABlle=20van=20Essen?= Date: Thu, 27 Mar 2025 12:28:17 +0100 Subject: [PATCH] zoc: Treat linked LLVM IR as additional option --linked --- compiler/src/main.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/compiler/src/main.rs b/compiler/src/main.rs index 2d3fa8f..e032f8f 100644 --- a/compiler/src/main.rs +++ b/compiler/src/main.rs @@ -19,6 +19,10 @@ pub struct Options { #[bpaf(external(output_type), optional)] output_type: Option, + #[bpaf(long("linked"))] + /// Produce linked LLVM IR (in combination with --ll) + linked: bool, + #[bpaf(short('o'), argument("file"))] /// Output path output_path: Option, @@ -43,6 +47,10 @@ fn main_core() -> Result<(), CompilerError> { let output_type = opts.output_type.unwrap_or_default(); + if opts.linked && output_type != OutputType::LlvmIr { + println!("Warning: option --linked only makes sense when combined with --ll. Ignoring."); + } + let ptx_path = Path::new(&opts.ptx_path).to_path_buf(); check_path(&ptx_path)?; @@ -57,8 +65,13 @@ fn main_core() -> Result<(), CompilerError> { let llvm = ptx_to_llvm(ptx).map_err(CompilerError::from)?; let output = match output_type { - OutputType::LlvmIrPreLinked => llvm.llvm_ir, - OutputType::LlvmIrLinked => get_linked_bitcode(&llvm)?, + OutputType::LlvmIr => { + if opts.linked { + get_linked_bitcode(&llvm)? + } else { + llvm.llvm_ir + } + } OutputType::Elf => get_elf(&llvm)?, OutputType::Assembly => get_assembly(&llvm)?, }; @@ -154,12 +167,9 @@ fn write_to_file(content: &[u8], path: &Path) -> io::Result<()> { #[derive(Bpaf, Clone, Copy, Debug, Default, PartialEq)] enum OutputType { - /// Produce pre-linked LLVM IR + /// Produce LLVM IR #[bpaf(long("ll"))] - LlvmIrPreLinked, - /// Produce linked LLVM IR - #[bpaf(long("linked-ll"))] - LlvmIrLinked, + LlvmIr, /// Produce ELF binary (default) #[default] Elf, @@ -171,7 +181,7 @@ enum OutputType { impl OutputType { fn extension(self) -> String { match self { - OutputType::LlvmIrPreLinked | OutputType::LlvmIrLinked => "ll", + OutputType::LlvmIr => "ll", OutputType::Assembly => "asm", OutputType::Elf => "elf", } @@ -184,8 +194,7 @@ impl FromStr for OutputType { fn from_str(s: &str) -> Result { match s { - "ll" => Ok(Self::LlvmIrPreLinked), - "ll_linked" => Ok(Self::LlvmIrLinked), + "ll" => Ok(Self::LlvmIr), "elf" => Ok(Self::Elf), "asm" => Ok(Self::Assembly), _ => {