use libc::{c_uint, c_char};
-use syntax::symbol::LocalInternedString;
+use syntax::symbol::Symbol;
use syntax::ast::Mutability;
pub use crate::context::CodegenCx;
impl BackendTypes for CodegenCx<'ll, 'tcx> {
type Value = &'ll Value;
+ type FuncId = &'ll Value;
+
type BasicBlock = &'ll BasicBlock;
type Type = &'ll Type;
type Funclet = Funclet<'ll>;
fn const_cstr(
&self,
- s: LocalInternedString,
+ s: Symbol,
null_terminated: bool,
) -> &'ll Value {
unsafe {
return llval;
}
+ let s_str = s.as_str();
let sc = llvm::LLVMConstStringInContext(self.llcx,
- s.as_ptr() as *const c_char,
- s.len() as c_uint,
+ s_str.as_ptr() as *const c_char,
+ s_str.len() as c_uint,
!null_terminated as Bool);
let sym = self.generate_local_symbol_name("str");
let g = self.define_global(&sym[..], self.val_ty(sc)).unwrap_or_else(||{
}
}
- pub fn const_str_slice(&self, s: LocalInternedString) -> &'ll Value {
- let len = s.len();
+ pub fn const_str_slice(&self, s: Symbol) -> &'ll Value {
+ let len = s.as_str().len();
let cs = consts::ptrcast(self.const_cstr(s, false),
self.type_ptr_to(self.layout_of(self.tcx.mk_str()).llvm_type(self)));
self.const_fat_ptr(cs, self.const_usize(len as u64))
struct_in_context(self.llcx, elts, packed)
}
- fn const_to_uint(&self, v: &'ll Value) -> u64 {
- unsafe {
- llvm::LLVMConstIntGetZExtValue(v)
- }
- }
-
- fn is_const_integral(&self, v: &'ll Value) -> bool {
- unsafe {
- llvm::LLVMIsAConstantInt(v).is_some()
+ fn const_to_opt_uint(&self, v: &'ll Value) -> Option<u64> {
+ if is_const_integral(v) {
+ unsafe {
+ Some(llvm::LLVMConstIntGetZExtValue(v))
+ }
+ } else {
+ None
}
}
fn const_to_opt_u128(&self, v: &'ll Value, sign_ext: bool) -> Option<u128> {
unsafe {
- if self.is_const_integral(v) {
+ if is_const_integral(v) {
let (mut lo, mut hi) = (0u64, 0u64);
let success = llvm::LLVMRustConstInt128Get(v, sign_ext,
&mut hi, &mut lo);
offset: Size,
) -> PlaceRef<'tcx, &'ll Value> {
assert_eq!(alloc.align, layout.align.abi);
- let init = const_alloc_to_llvm(self, alloc);
- let base_addr = self.static_addr_of(init, alloc.align, None);
-
- let llval = unsafe { llvm::LLVMConstInBoundsGEP(
- self.const_bitcast(base_addr, self.type_i8p()),
- &self.const_usize(offset.bytes()),
- 1,
- )};
- let llval = self.const_bitcast(llval, self.type_ptr_to(layout.llvm_type(self)));
- PlaceRef::new_sized(llval, layout, alloc.align)
+ let llty = self.type_ptr_to(layout.llvm_type(self));
+ let llval = if layout.size == Size::ZERO {
+ let llval = self.const_usize(alloc.align.bytes());
+ unsafe { llvm::LLVMConstIntToPtr(llval, llty) }
+ } else {
+ let init = const_alloc_to_llvm(self, alloc);
+ let base_addr = self.static_addr_of(init, alloc.align, None);
+
+ let llval = unsafe { llvm::LLVMConstInBoundsGEP(
+ self.const_bitcast(base_addr, self.type_i8p()),
+ &self.const_usize(offset.bytes()),
+ 1,
+ )};
+ self.const_bitcast(llval, llty)
+ };
+ PlaceRef::new_sized(llval, layout)
}
fn const_ptrcast(&self, val: &'ll Value, ty: &'ll Type) -> &'ll Value {
fn hi_lo_to_u128(lo: u64, hi: u64) -> u128 {
((hi as u128) << 64) | (lo as u128)
}
+
+fn is_const_integral(v: &'ll Value) -> bool {
+ unsafe {
+ llvm::LLVMIsAConstantInt(v).is_some()
+ }
+}