1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 // Copyright 2018 Jacob Lifshay
4 use shader_compiler::backend::*;
6 use std::os::raw::c_char;
9 pub struct LLVM7Context(llvm_sys::prelude::LLVMContextRef);
11 impl Drop for LLVM7Context {
14 llvm_sys::core::LLVMContextDispose(self.0);
19 unsafe impl Send for LLVM7Context {}
21 impl<'a> Context<'a> for LLVM7Context {
22 type Module = LLVM7Module;
23 fn create_module(&self, name: &str) -> LLVM7Module {
24 let name = CString::new(name).unwrap();
26 LLVM7Module(llvm_sys::core::LLVMModuleCreateWithNameInContext(
35 pub struct LLVM7Module(llvm_sys::prelude::LLVMModuleRef);
37 impl Drop for LLVM7Module {
40 llvm_sys::core::LLVMDisposeModule(self.0);
45 impl<'a> Module<'a> for LLVM7Module {
46 fn set_source_file_name(&mut self, source_file_name: &str) {
48 llvm_sys::core::LLVMSetSourceFileName(
50 source_file_name.as_ptr() as *const c_char,
51 source_file_name.len(),
57 pub struct LLVM7ShaderCompiler;
59 impl ShaderCompiler for LLVM7ShaderCompiler {
60 fn name() -> &'static str {
63 fn run_with_user<SCU: ShaderCompilerUser>(shader_compiler_user: SCU) -> SCU::ReturnType {
64 let context = unsafe { LLVM7Context(llvm_sys::core::LLVMContextCreate()) };
65 shader_compiler_user.run_with_context(&context)