diff options
| author | Denis Merigoux <denis.merigoux@gmail.com> | 2018-08-29 18:42:25 +0200 |
|---|---|---|
| committer | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2018-11-16 14:11:59 +0200 |
| commit | 4cc18d3de50b6540e53ddcfefb88dee9ed991264 (patch) | |
| tree | 7d7cc48d8ddff1b195f9b3caec2138a104b4dc12 /src/librustc_codegen_llvm/lib.rs | |
| parent | 3aee77277efbac0b9b14b2097ea8a2c449fb1fc3 (diff) | |
| download | rust-4cc18d3de50b6540e53ddcfefb88dee9ed991264.tar.gz rust-4cc18d3de50b6540e53ddcfefb88dee9ed991264.zip | |
CommonWriteMethods are not static any more
Diffstat (limited to 'src/librustc_codegen_llvm/lib.rs')
| -rw-r--r-- | src/librustc_codegen_llvm/lib.rs | 58 |
1 files changed, 52 insertions, 6 deletions
diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index 43942b0db85..2ef90c03c67 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -68,10 +68,15 @@ extern crate tempfile; extern crate memmap; use back::bytecode::RLIB_BYTECODE_EXTENSION; +use interfaces::{Backend, CommonWriteMethods}; +use value::Value; +use type_::Type; pub use llvm_util::target_features; use std::any::Any; use std::sync::mpsc; +use std::marker::PhantomData; +use libc::{c_uint, c_char}; use rustc_data_structures::sync::Lrc; use rustc::dep_graph::DepGraph; @@ -273,7 +278,7 @@ struct ModuleCodegen { /// as the crate name and disambiguator. /// We currently generate these names via CodegenUnit::build_cgu_name(). name: String, - module_llvm: ModuleLlvm, + module_llvm: ModuleLlvm<'static>, kind: ModuleKind, } @@ -315,16 +320,24 @@ impl ModuleCodegen { } } -struct ModuleLlvm { +struct ModuleLlvm<'ll> { llcx: &'static mut llvm::Context, llmod_raw: *const llvm::Module, tm: &'static mut llvm::TargetMachine, + phantom: PhantomData<&'ll ()> } -unsafe impl Send for ModuleLlvm { } -unsafe impl Sync for ModuleLlvm { } +impl<'ll> Backend for ModuleLlvm<'ll> { + type Value = &'ll Value; + type BasicBlock = &'ll llvm::BasicBlock; + type Type = &'ll Type; + type Context = &'ll llvm::Context; +} + +unsafe impl Send for ModuleLlvm<'ll> { } +unsafe impl Sync for ModuleLlvm<'ll> { } -impl ModuleLlvm { +impl ModuleLlvm<'ll> { fn new(sess: &Session, mod_name: &str) -> Self { unsafe { let llcx = llvm::LLVMRustContextCreate(sess.fewer_names()); @@ -334,6 +347,7 @@ impl ModuleLlvm { llmod_raw, llcx, tm: create_target_machine(sess, false), + phantom: PhantomData } } } @@ -345,7 +359,39 @@ impl ModuleLlvm { } } -impl Drop for ModuleLlvm { +impl CommonWriteMethods for ModuleLlvm<'ll> { + fn val_ty(&self, v: &'ll Value) -> &'ll Type { + unsafe { + llvm::LLVMTypeOf(v) + } + } + + fn c_bytes_in_context(&self, llcx: &'ll llvm::Context, bytes: &[u8]) -> &'ll Value { + unsafe { + let ptr = bytes.as_ptr() as *const c_char; + return llvm::LLVMConstStringInContext( + llcx, + ptr, + bytes.len() as c_uint, + llvm::True); + } + } + + fn c_struct_in_context( + &self, + llcx: &'a llvm::Context, + elts: &[&'a Value], + packed: bool, + ) -> &'a Value { + unsafe { + llvm::LLVMConstStructInContext(llcx, + elts.as_ptr(), elts.len() as c_uint, + packed as llvm::Bool) + } + } +} + +impl Drop for ModuleLlvm<'ll> { fn drop(&mut self) { unsafe { llvm::LLVMContextDispose(&mut *(self.llcx as *mut _)); |
