Use bitcast for ptrtoint and inttoptr
This works now
This commit is contained in:
parent
b48ed38482
commit
07afdb8c0d
@ -904,11 +904,12 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn ptrtoint(&mut self, value: RValue<'gcc>, dest_ty: Type<'gcc>) -> RValue<'gcc> {
|
fn ptrtoint(&mut self, value: RValue<'gcc>, dest_ty: Type<'gcc>) -> RValue<'gcc> {
|
||||||
self.cx.ptrtoint(self.block, value, dest_ty)
|
let usize_value = self.cx.const_bitcast(value, self.cx.type_isize());
|
||||||
|
self.intcast(usize_value, dest_ty, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inttoptr(&mut self, value: RValue<'gcc>, dest_ty: Type<'gcc>) -> RValue<'gcc> {
|
fn inttoptr(&mut self, value: RValue<'gcc>, dest_ty: Type<'gcc>) -> RValue<'gcc> {
|
||||||
self.cx.inttoptr(self.block, value, dest_ty)
|
self.cx.const_bitcast(value, dest_ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bitcast(&mut self, value: RValue<'gcc>, dest_ty: Type<'gcc>) -> RValue<'gcc> {
|
fn bitcast(&mut self, value: RValue<'gcc>, dest_ty: Type<'gcc>) -> RValue<'gcc> {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use gccjit::LValue;
|
use gccjit::LValue;
|
||||||
use gccjit::{Block, RValue, Type, ToRValue};
|
use gccjit::{RValue, Type, ToRValue};
|
||||||
use rustc_codegen_ssa::mir::place::PlaceRef;
|
use rustc_codegen_ssa::mir::place::PlaceRef;
|
||||||
use rustc_codegen_ssa::traits::{
|
use rustc_codegen_ssa::traits::{
|
||||||
BaseTypeMethods,
|
BaseTypeMethods,
|
||||||
@ -45,27 +45,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
|
|||||||
global
|
global
|
||||||
// TODO(antoyo): set linkage.
|
// TODO(antoyo): set linkage.
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inttoptr(&self, block: Block<'gcc>, value: RValue<'gcc>, dest_ty: Type<'gcc>) -> RValue<'gcc> {
|
|
||||||
let func = block.get_function();
|
|
||||||
let local = func.new_local(None, value.get_type(), "intLocal");
|
|
||||||
block.add_assignment(None, local, value);
|
|
||||||
let value_address = local.get_address(None);
|
|
||||||
|
|
||||||
let ptr = self.context.new_cast(None, value_address, dest_ty.make_pointer());
|
|
||||||
ptr.dereference(None).to_rvalue()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn ptrtoint(&self, block: Block<'gcc>, value: RValue<'gcc>, dest_ty: Type<'gcc>) -> RValue<'gcc> {
|
|
||||||
// TODO(antoyo): when libgccjit allow casting from pointer to int, remove this.
|
|
||||||
let func = block.get_function();
|
|
||||||
let local = func.new_local(None, value.get_type(), "ptrLocal");
|
|
||||||
block.add_assignment(None, local, value);
|
|
||||||
let ptr_address = local.get_address(None);
|
|
||||||
|
|
||||||
let ptr = self.context.new_cast(None, ptr_address, dest_ty.make_pointer());
|
|
||||||
ptr.dereference(None).to_rvalue()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bytes_in_context<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, bytes: &[u8]) -> RValue<'gcc> {
|
pub fn bytes_in_context<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, bytes: &[u8]) -> RValue<'gcc> {
|
||||||
@ -202,12 +181,8 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let value = self.const_uint_big(self.type_ix(bitsize), data);
|
let value = self.const_uint_big(self.type_ix(bitsize), data);
|
||||||
if layout.value == Pointer {
|
|
||||||
self.inttoptr(self.current_block.borrow().expect("block"), value, ty)
|
|
||||||
} else {
|
|
||||||
self.const_bitcast(value, ty)
|
self.const_bitcast(value, ty)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Scalar::Ptr(ptr, _size) => {
|
Scalar::Ptr(ptr, _size) => {
|
||||||
let (alloc_id, offset) = ptr.into_parts();
|
let (alloc_id, offset) = ptr.into_parts();
|
||||||
let base_addr =
|
let base_addr =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user