@@ -30,7 +30,7 @@ use super::CachedModuleCodegen;
30
30
31
31
use abi;
32
32
use back:: write:: { self , OngoingCodegen } ;
33
- use llvm:: { self , get_param } ;
33
+ use llvm;
34
34
use metadata;
35
35
use rustc:: dep_graph:: cgu_reuse_tracker:: CguReuse ;
36
36
use rustc:: hir:: def_id:: { CrateNum , DefId , LOCAL_CRATE } ;
@@ -50,7 +50,6 @@ use rustc::session::Session;
50
50
use rustc_incremental;
51
51
use allocator;
52
52
use mir:: place:: PlaceRef ;
53
- use attributes;
54
53
use builder:: { Builder , MemFlags } ;
55
54
use callee;
56
55
use rustc_mir:: monomorphize:: item:: DefPathBasedNames ;
@@ -495,48 +494,50 @@ pub fn set_link_section(llval: &Value, attrs: &CodegenFnAttrs) {
495
494
496
495
/// Create the `main` function which will initialize the rust runtime and call
497
496
/// users main function.
498
- fn maybe_create_entry_wrapper ( cx : & CodegenCx ) {
497
+ fn maybe_create_entry_wrapper < ' a , ' tcx : ' a , Bx : BuilderMethods < ' a , ' tcx > > (
498
+ cx : & ' a Bx :: CodegenCx
499
+ ) {
499
500
let ( main_def_id, span) = match * cx. sess ( ) . entry_fn . borrow ( ) {
500
501
Some ( ( id, span, _) ) => {
501
- ( cx. tcx . hir . local_def_id ( id) , span)
502
+ ( cx. tcx ( ) . hir . local_def_id ( id) , span)
502
503
}
503
504
None => return ,
504
505
} ;
505
506
506
- let instance = Instance :: mono ( cx. tcx , main_def_id) ;
507
+ let instance = Instance :: mono ( cx. tcx ( ) , main_def_id) ;
507
508
508
- if !cx. codegen_unit . contains_item ( & MonoItem :: Fn ( instance) ) {
509
+ if !cx. codegen_unit ( ) . contains_item ( & MonoItem :: Fn ( instance) ) {
509
510
// We want to create the wrapper in the same codegen unit as Rust's main
510
511
// function.
511
512
return ;
512
513
}
513
514
514
- let main_llfn = callee :: get_fn ( cx , instance) ;
515
+ let main_llfn = cx . get_fn ( instance) ;
515
516
516
517
let et = cx. sess ( ) . entry_fn . get ( ) . map ( |e| e. 2 ) ;
517
518
match et {
518
- Some ( EntryFnType :: Main ) => create_entry_fn ( cx, span, main_llfn, main_def_id, true ) ,
519
- Some ( EntryFnType :: Start ) => create_entry_fn ( cx, span, main_llfn, main_def_id, false ) ,
519
+ Some ( EntryFnType :: Main ) => create_entry_fn :: < Bx > ( cx, span, main_llfn, main_def_id, true ) ,
520
+ Some ( EntryFnType :: Start ) => create_entry_fn :: < Bx > ( cx, span, main_llfn, main_def_id, false ) ,
520
521
None => { } // Do nothing.
521
522
}
522
523
523
- fn create_entry_fn (
524
- cx : & CodegenCx < ' ll , ' _ > ,
524
+ fn create_entry_fn < ' a , ' tcx : ' a , Bx : BuilderMethods < ' a , ' tcx > > (
525
+ cx : & ' a Bx :: CodegenCx ,
525
526
sp : Span ,
526
- rust_main : & ' ll Value ,
527
+ rust_main : Bx :: Value ,
527
528
rust_main_def_id : DefId ,
528
529
use_start_lang_item : bool ,
529
530
) {
530
531
let llfty =
531
532
cx. type_func ( & [ cx. type_int ( ) , cx. type_ptr_to ( cx. type_i8p ( ) ) ] , cx. type_int ( ) ) ;
532
533
533
- let main_ret_ty = cx. tcx . fn_sig ( rust_main_def_id) . output ( ) ;
534
+ let main_ret_ty = cx. tcx ( ) . fn_sig ( rust_main_def_id) . output ( ) ;
534
535
// Given that `main()` has no arguments,
535
536
// then its return type cannot have
536
537
// late-bound regions, since late-bound
537
538
// regions must appear in the argument
538
539
// listing.
539
- let main_ret_ty = cx. tcx . erase_regions (
540
+ let main_ret_ty = cx. tcx ( ) . erase_regions (
540
541
& main_ret_ty. no_bound_vars ( ) . unwrap ( ) ,
541
542
) ;
542
543
@@ -551,25 +552,25 @@ fn maybe_create_entry_wrapper(cx: &CodegenCx) {
551
552
let llfn = cx. declare_cfn ( "main" , llfty) ;
552
553
553
554
// `main` should respect same config for frame pointer elimination as rest of code
554
- attributes :: set_frame_pointer_elimination ( cx , llfn) ;
555
- attributes :: apply_target_cpu_attr ( cx , llfn) ;
555
+ cx . set_frame_pointer_elimination ( llfn) ;
556
+ cx . apply_target_cpu_attr ( llfn) ;
556
557
557
- let bx = Builder :: new_block ( cx, llfn, "top" ) ;
558
+ let bx = Bx :: new_block ( & cx, llfn, "top" ) ;
558
559
559
- debuginfo :: gdb :: insert_reference_to_gdb_debug_scripts_section_global ( & bx ) ;
560
+ bx . insert_reference_to_gdb_debug_scripts_section_global ( ) ;
560
561
561
562
// Params from native main() used as args for rust start function
562
- let param_argc = get_param ( llfn, 0 ) ;
563
- let param_argv = get_param ( llfn, 1 ) ;
564
- let arg_argc = bx. intcast ( param_argc, cx. isize_ty , true ) ;
563
+ let param_argc = cx . get_param ( llfn, 0 ) ;
564
+ let param_argv = cx . get_param ( llfn, 1 ) ;
565
+ let arg_argc = bx. intcast ( param_argc, cx. type_isize ( ) , true ) ;
565
566
let arg_argv = param_argv;
566
567
567
568
let ( start_fn, args) = if use_start_lang_item {
568
- let start_def_id = cx. tcx . require_lang_item ( StartFnLangItem ) ;
569
+ let start_def_id = cx. tcx ( ) . require_lang_item ( StartFnLangItem ) ;
569
570
let start_fn = callee:: resolve_and_get_fn (
570
571
cx,
571
572
start_def_id,
572
- cx. tcx . intern_substs ( & [ main_ret_ty. into ( ) ] ) ,
573
+ cx. tcx ( ) . intern_substs ( & [ main_ret_ty. into ( ) ] ) ,
573
574
) ;
574
575
( start_fn, vec ! [ bx. pointercast( rust_main, cx. type_ptr_to( cx. type_i8p( ) ) ) ,
575
576
arg_argc, arg_argv] )
@@ -1112,7 +1113,7 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1112
1113
1113
1114
// If this codegen unit contains the main function, also create the
1114
1115
// wrapper here
1115
- maybe_create_entry_wrapper ( & cx) ;
1116
+ maybe_create_entry_wrapper :: < Builder < & Value > > ( & cx) ;
1116
1117
1117
1118
// Run replace-all-uses-with for statics that need it
1118
1119
for & ( old_g, new_g) in cx. statics_to_rauw . borrow ( ) . iter ( ) {
0 commit comments