cdisselkoen / llvm-ir

LLVM IR in natural Rust data structures
MIT License
539 stars 45 forks source link

Query for LLVM version? #13

Closed smoelius closed 3 years ago

smoelius commented 3 years ago

Is there a way to ask llvm-ir for the LLVM version it was configured for?

I am imagining something like:

pub fn llvm_version() -> u32 {
    if cfg!(feature = "llvm-8") {
        return 8;
    }
    ...
}

Clearly, this could be handled in the caller (since it chose the feature). But I am wondering if there is a way to handle this without having to do extra work in the caller.

cdisselkoen commented 3 years ago

Sure, this seems reasonable. Do you want to make a PR with the function you describe? We can probably just add this function directly to src/lib.rs.

cdisselkoen commented 3 years ago

Maybe we should return an &str instead of a u32. Currently all of the supported LLVM versions are integers, but maybe it's possible that in the future we want to support a version like 15-rc1 or 11.1 that is different from 15 or 11.