Skip to content

Commit b03f7f8

Browse files
committed
Refactored the codebase to use Function instead of RValue where possible.
1 parent 962a08f commit b03f7f8

File tree

5 files changed

+14
-19
lines changed

5 files changed

+14
-19
lines changed

src/builder.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
520520
self.block
521521
}
522522

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

src/context.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
375375
impl<'gcc, 'tcx> BackendTypes for CodegenCx<'gcc, 'tcx> {
376376
type Value = RValue<'gcc>;
377377
type Metadata = RValue<'gcc>;
378-
// TODO(antoyo): change to Function<'gcc>.
379-
type Function = RValue<'gcc>;
378+
type Function = Function<'gcc>;
380379

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

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

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

490-
fn set_frame_pointer_type(&self, _llfn: RValue<'gcc>) {
488+
fn set_frame_pointer_type(&self, _llfn: Function<'gcc>) {
491489
// TODO(antoyo)
492490
}
493491

494-
fn apply_target_cpu_attr(&self, _llfn: RValue<'gcc>) {
492+
fn apply_target_cpu_attr(&self, _llfn: Function<'gcc>) {
495493
// TODO(antoyo)
496494
}
497495

src/debuginfo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::ops::Range;
22
use std::sync::Arc;
33

4-
use gccjit::{Location, RValue};
4+
use gccjit::{Function, Location, RValue};
55
use rustc_abi::Size;
66
use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, VariableKind};
77
use rustc_codegen_ssa::traits::{DebugInfoBuilderMethods, DebugInfoCodegenMethods};
@@ -225,7 +225,7 @@ impl<'gcc, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
225225
&self,
226226
instance: Instance<'tcx>,
227227
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
228-
llfn: RValue<'gcc>,
228+
llfn: Function<'gcc>,
229229
mir: &mir::Body<'tcx>,
230230
) -> Option<FunctionDebugContext<'tcx, Self::DIScope, Self::DILocation>> {
231231
if self.sess().opts.debuginfo == DebugInfo::None {
@@ -276,7 +276,7 @@ impl<'gcc, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
276276
&self,
277277
_instance: Instance<'tcx>,
278278
_fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
279-
_maybe_definition_llfn: Option<RValue<'gcc>>,
279+
_maybe_definition_llfn: Option<Function<'gcc>>,
280280
) -> Self::DIScope {
281281
// TODO(antoyo): implement.
282282
}

src/declare.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
9494
_fn_type: Type<'gcc>,
9595
#[cfg(feature = "master")] callconv: Option<FnAttribute<'gcc>>,
9696
#[cfg(not(feature = "master"))] callconv: Option<()>,
97-
) -> RValue<'gcc> {
97+
) -> Function<'gcc> {
9898
// TODO(antoyo): use the fn_type parameter.
9999
let const_string = self.context.new_type::<u8>().make_pointer().make_pointer();
100100
let return_type = self.type_i32();
@@ -111,8 +111,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
111111
// NOTE: it is needed to set the current_func here as well, because get_fn() is not called
112112
// for the main function.
113113
*self.current_func.borrow_mut() = Some(func);
114-
// FIXME(antoyo): this is a wrong cast. That requires changing the compiler API.
115-
unsafe { std::mem::transmute(func) }
114+
func
116115
}
117116

118117
pub fn declare_fn(&self, name: &str, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Function<'gcc> {

src/intrinsic/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,10 +1484,9 @@ fn gen_fn<'a, 'gcc, 'tcx>(
14841484
// FIXME(eddyb) find a nicer way to do this.
14851485
cx.linkage.set(FunctionType::Internal);
14861486
let func = cx.declare_fn(name, fn_abi);
1487-
let func_val = unsafe { std::mem::transmute::<Function<'gcc>, RValue<'gcc>>(func) };
1488-
cx.set_frame_pointer_type(func_val);
1489-
cx.apply_target_cpu_attr(func_val);
1490-
let block = Builder::append_block(cx, func_val, "entry-block");
1487+
cx.set_frame_pointer_type(func);
1488+
cx.apply_target_cpu_attr(func);
1489+
let block = Builder::append_block(cx, func, "entry-block");
14911490
let bx = Builder::build(cx, block);
14921491
codegen(bx);
14931492
(return_type, func)

0 commit comments

Comments
 (0)