@@ -590,6 +590,26 @@ fn finish_vtbl(cx: @local_ctxt, llmethods: [ValueRef], name: str) ->
590
590
ret gvar;
591
591
}
592
592
593
+ // begin_fn: Set up an LLVM function for backwarding and forwarding functions.
594
+ fn begin_fn ( cx : @local_ctxt , sp : span , m : @ty:: method ,
595
+ ty_params : [ ast:: ty_param ] , fn_name : str ) -> ValueRef {
596
+
597
+ // Create a local context that's aware of the name of the method we're
598
+ // creating.
599
+ let mcx: @local_ctxt = @{ path: cx. path + [ "method" , m. ident ] with * cx} ;
600
+
601
+ // Make up a name for the function.
602
+ let s: str =
603
+ mangle_internal_name_by_path_and_seq ( mcx. ccx , mcx. path , fn_name) ;
604
+
605
+ // Get the function's type and declare it.
606
+ let llfn_ty: TypeRef = type_of_meth ( cx. ccx , sp, m, ty_params) ;
607
+ let llfn: ValueRef =
608
+ decl_internal_fastcall_fn ( cx. ccx . llmod , s, llfn_ty) ;
609
+
610
+ ret llfn;
611
+ }
612
+
593
613
// process_bkwding_mthd: Create the backwarding function that appears in a
594
614
// backwarding vtable slot.
595
615
//
@@ -608,22 +628,7 @@ fn process_bkwding_mthd(cx: @local_ctxt, sp: span, m: @ty::method,
608
628
ty_params : [ ast:: ty_param ] , outer_obj_ty : ty:: t ,
609
629
_additional_field_tys : [ ty:: t ] ) -> ValueRef {
610
630
611
- // Create a local context that's aware of the name of the method we're
612
- // creating.
613
- let mcx: @local_ctxt = @{ path: cx. path + [ "method" , m. ident ] with * cx} ;
614
-
615
- // Make up a name for the backwarding function.
616
- let fn_name: str = "backwarding_fn" ;
617
- let s: str =
618
- mangle_internal_name_by_path_and_seq ( mcx. ccx , mcx. path , fn_name) ;
619
-
620
- // Get the backwarding function's type and declare it.
621
- let llbackwarding_fn_ty: TypeRef = type_of_meth ( cx. ccx , sp, m, ty_params) ;
622
- let llbackwarding_fn: ValueRef =
623
- decl_internal_fastcall_fn ( cx. ccx . llmod , s, llbackwarding_fn_ty) ;
624
-
625
- // Create a new function context and block context for the backwarding
626
- // function, holding onto a pointer to the first block.
631
+ let llbackwarding_fn = begin_fn ( cx, sp, m, ty_params, "backwarding_fn" ) ;
627
632
let fcx = new_fn_ctxt ( cx, sp, llbackwarding_fn) ;
628
633
let bcx = new_top_block_ctxt ( fcx) ;
629
634
let lltop = bcx. llbb ;
@@ -688,8 +693,8 @@ fn process_bkwding_mthd(cx: @local_ctxt, sp: span, m: @ty::method,
688
693
689
694
// Set up the three implicit arguments to the outer method we'll need to
690
695
// call.
691
- let self_arg = llself_obj_ptr ;
692
- let llouter_mthd_args : [ ValueRef ] = [ llretptr , fcx . lltaskptr , self_arg ] ;
696
+ let llouter_mthd_args : [ ValueRef ] = [ llretptr , fcx . lltaskptr ,
697
+ llself_obj_ptr ] ;
693
698
694
699
// Copy the explicit arguments that are being passed into the forwarding
695
700
// function (they're in fcx.llargs) to llouter_mthd_args.
@@ -728,22 +733,9 @@ fn process_fwding_mthd(cx: @local_ctxt, sp: span, m: @ty::method,
728
733
backwarding_vtbl : ValueRef ,
729
734
additional_field_tys : [ ty:: t ] ) -> ValueRef {
730
735
731
- // Create a local context that's aware of the name of the method we're
732
- // creating.
733
- let mcx: @local_ctxt = @{ path: cx. path + [ "method" , m. ident ] with * cx} ;
734
-
735
- // Make up a name for the forwarding function.
736
- let fn_name: str = "forwarding_fn" ;
737
- let s: str =
738
- mangle_internal_name_by_path_and_seq ( mcx. ccx , mcx. path , fn_name) ;
739
-
740
- // Get the forwarding function's type and declare it.
741
- let llforwarding_fn_ty = type_of_meth ( cx. ccx , sp, m, ty_params) ;
742
- let llforwarding_fn: ValueRef =
743
- decl_internal_fastcall_fn ( cx. ccx . llmod , s, llforwarding_fn_ty) ;
744
-
745
- // Create a new function context and block context for the forwarding
746
- // function, holding onto a pointer to the first block.
736
+ // Create a new function context and block context for the function,
737
+ // holding onto a pointer to the first block.
738
+ let llforwarding_fn = begin_fn ( cx, sp, m, ty_params, "forwarding_fn" ) ;
747
739
let fcx = new_fn_ctxt ( cx, sp, llforwarding_fn) ;
748
740
let bcx = new_top_block_ctxt ( fcx) ;
749
741
let lltop = bcx. llbb ;
0 commit comments