Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
self.block
}

fn append_block(cx: &'a CodegenCx<'gcc, 'tcx>, func: RValue<'gcc>, name: &str) -> Block<'gcc> {
let func = cx.rvalue_as_function(func);
fn append_block(_: &'a CodegenCx<'gcc, 'tcx>, func: Function<'gcc>, name: &str) -> Block<'gcc> {
func.new_block(name)
}

Expand Down
12 changes: 5 additions & 7 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
impl<'gcc, 'tcx> BackendTypes for CodegenCx<'gcc, 'tcx> {
type Value = RValue<'gcc>;
type Metadata = RValue<'gcc>;
// TODO(antoyo): change to Function<'gcc>.
type Function = RValue<'gcc>;
type Function = Function<'gcc>;

type BasicBlock = Block<'gcc>;
type Type = Type<'gcc>;
Expand All @@ -394,11 +393,10 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
&self.vtables
}

fn get_fn(&self, instance: Instance<'tcx>) -> RValue<'gcc> {
fn get_fn(&self, instance: Instance<'tcx>) -> Function<'gcc> {
let func = get_fn(self, instance);
*self.current_func.borrow_mut() = Some(func);
// FIXME(antoyo): this is a wrong cast. That requires changing the compiler API.
unsafe { std::mem::transmute(func) }
func
}

fn get_fn_addr(&self, instance: Instance<'tcx>) -> RValue<'gcc> {
Expand Down Expand Up @@ -487,11 +485,11 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
self.codegen_unit
}

fn set_frame_pointer_type(&self, _llfn: RValue<'gcc>) {
fn set_frame_pointer_type(&self, _llfn: Function<'gcc>) {
// TODO(antoyo)
}

fn apply_target_cpu_attr(&self, _llfn: RValue<'gcc>) {
fn apply_target_cpu_attr(&self, _llfn: Function<'gcc>) {
// TODO(antoyo)
}

Expand Down
6 changes: 3 additions & 3 deletions src/debuginfo.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ops::Range;
use std::sync::Arc;

use gccjit::{Location, RValue};
use gccjit::{Function, Location, RValue};
use rustc_abi::Size;
use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, VariableKind};
use rustc_codegen_ssa::traits::{DebugInfoBuilderMethods, DebugInfoCodegenMethods};
Expand Down Expand Up @@ -225,7 +225,7 @@ impl<'gcc, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
&self,
instance: Instance<'tcx>,
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
llfn: RValue<'gcc>,
llfn: Function<'gcc>,
mir: &mir::Body<'tcx>,
) -> Option<FunctionDebugContext<'tcx, Self::DIScope, Self::DILocation>> {
if self.sess().opts.debuginfo == DebugInfo::None {
Expand Down Expand Up @@ -276,7 +276,7 @@ impl<'gcc, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
&self,
_instance: Instance<'tcx>,
_fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
_maybe_definition_llfn: Option<RValue<'gcc>>,
_maybe_definition_llfn: Option<Function<'gcc>>,
) -> Self::DIScope {
// TODO(antoyo): implement.
}
Expand Down
5 changes: 2 additions & 3 deletions src/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
_fn_type: Type<'gcc>,
#[cfg(feature = "master")] callconv: Option<FnAttribute<'gcc>>,
#[cfg(not(feature = "master"))] callconv: Option<()>,
) -> RValue<'gcc> {
) -> Function<'gcc> {
// TODO(antoyo): use the fn_type parameter.
let const_string = self.context.new_type::<u8>().make_pointer().make_pointer();
let return_type = self.type_i32();
Expand All @@ -111,8 +111,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
// NOTE: it is needed to set the current_func here as well, because get_fn() is not called
// for the main function.
*self.current_func.borrow_mut() = Some(func);
// FIXME(antoyo): this is a wrong cast. That requires changing the compiler API.
unsafe { std::mem::transmute(func) }
func
}

pub fn declare_fn(&self, name: &str, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Function<'gcc> {
Expand Down
7 changes: 3 additions & 4 deletions src/intrinsic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1484,10 +1484,9 @@ fn gen_fn<'a, 'gcc, 'tcx>(
// FIXME(eddyb) find a nicer way to do this.
cx.linkage.set(FunctionType::Internal);
let func = cx.declare_fn(name, fn_abi);
let func_val = unsafe { std::mem::transmute::<Function<'gcc>, RValue<'gcc>>(func) };
cx.set_frame_pointer_type(func_val);
cx.apply_target_cpu_attr(func_val);
let block = Builder::append_block(cx, func_val, "entry-block");
cx.set_frame_pointer_type(func);
cx.apply_target_cpu_attr(func);
let block = Builder::append_block(cx, func, "entry-block");
let bx = Builder::build(cx, block);
codegen(bx);
(return_type, func)
Expand Down