zoc: Treat linked LLVM IR as additional option --linked

This commit is contained in:
Joëlle van Essen 2025-03-27 12:28:17 +01:00
commit d3b61c9808
No known key found for this signature in database
GPG key ID: 28D3B5CDD4B43882

View file

@ -19,6 +19,10 @@ pub struct Options {
#[bpaf(external(output_type), optional)] #[bpaf(external(output_type), optional)]
output_type: Option<OutputType>, output_type: Option<OutputType>,
#[bpaf(long("linked"))]
/// Produce linked LLVM IR (in combination with --ll)
linked: bool,
#[bpaf(short('o'), argument("file"))] #[bpaf(short('o'), argument("file"))]
/// Output path /// Output path
output_path: Option<PathBuf>, output_path: Option<PathBuf>,
@ -43,6 +47,10 @@ fn main_core() -> Result<(), CompilerError> {
let output_type = opts.output_type.unwrap_or_default(); 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(); let ptx_path = Path::new(&opts.ptx_path).to_path_buf();
check_path(&ptx_path)?; check_path(&ptx_path)?;
@ -57,8 +65,13 @@ fn main_core() -> Result<(), CompilerError> {
let llvm = ptx_to_llvm(ptx).map_err(CompilerError::from)?; let llvm = ptx_to_llvm(ptx).map_err(CompilerError::from)?;
let output = match output_type { let output = match output_type {
OutputType::LlvmIrPreLinked => llvm.llvm_ir, OutputType::LlvmIr => {
OutputType::LlvmIrLinked => get_linked_bitcode(&llvm)?, if opts.linked {
get_linked_bitcode(&llvm)?
} else {
llvm.llvm_ir
}
}
OutputType::Elf => get_elf(&llvm)?, OutputType::Elf => get_elf(&llvm)?,
OutputType::Assembly => get_assembly(&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)] #[derive(Bpaf, Clone, Copy, Debug, Default, PartialEq)]
enum OutputType { enum OutputType {
/// Produce pre-linked LLVM IR /// Produce LLVM IR
#[bpaf(long("ll"))] #[bpaf(long("ll"))]
LlvmIrPreLinked, LlvmIr,
/// Produce linked LLVM IR
#[bpaf(long("linked-ll"))]
LlvmIrLinked,
/// Produce ELF binary (default) /// Produce ELF binary (default)
#[default] #[default]
Elf, Elf,
@ -171,7 +181,7 @@ enum OutputType {
impl OutputType { impl OutputType {
fn extension(self) -> String { fn extension(self) -> String {
match self { match self {
OutputType::LlvmIrPreLinked | OutputType::LlvmIrLinked => "ll", OutputType::LlvmIr => "ll",
OutputType::Assembly => "asm", OutputType::Assembly => "asm",
OutputType::Elf => "elf", OutputType::Elf => "elf",
} }
@ -184,8 +194,7 @@ impl FromStr for OutputType {
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
match s { match s {
"ll" => Ok(Self::LlvmIrPreLinked), "ll" => Ok(Self::LlvmIr),
"ll_linked" => Ok(Self::LlvmIrLinked),
"elf" => Ok(Self::Elf), "elf" => Ok(Self::Elf),
"asm" => Ok(Self::Assembly), "asm" => Ok(Self::Assembly),
_ => { _ => {