@@ -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:: collector:: { self , MonoItemCollectionMode } ;
@@ -502,48 +501,50 @@ pub fn set_link_section(llval: &Value, attrs: &CodegenFnAttrs) {
502
501
503
502
/// Create the `main` function which will initialize the rust runtime and call
504
503
/// users main function.
505
- fn maybe_create_entry_wrapper ( cx : & CodegenCx < ' ll , ' _ , & ' ll Value > ) {
504
+ fn maybe_create_entry_wrapper < ' a , ' ll : ' a , ' tcx : ' ll , Bx : BuilderMethods < ' a , ' ll , ' tcx > > (
505
+ cx : & ' a Bx :: CodegenCx
506
+ ) {
506
507
let ( main_def_id, span) = match * cx. sess ( ) . entry_fn . borrow ( ) {
507
508
Some ( ( id, span, _) ) => {
508
- ( cx. tcx . hir . local_def_id ( id) , span)
509
+ ( cx. tcx ( ) . hir . local_def_id ( id) , span)
509
510
}
510
511
None => return ,
511
512
} ;
512
513
513
- let instance = Instance :: mono ( cx. tcx , main_def_id) ;
514
+ let instance = Instance :: mono ( * cx. tcx ( ) , main_def_id) ;
514
515
515
- if !cx. codegen_unit . contains_item ( & MonoItem :: Fn ( instance) ) {
516
+ if !cx. codegen_unit ( ) . contains_item ( & MonoItem :: Fn ( instance) ) {
516
517
// We want to create the wrapper in the same codegen unit as Rust's main
517
518
// function.
518
519
return ;
519
520
}
520
521
521
- let main_llfn = callee :: get_fn ( cx , instance) ;
522
+ let main_llfn = cx . get_fn ( instance) ;
522
523
523
524
let et = cx. sess ( ) . entry_fn . get ( ) . map ( |e| e. 2 ) ;
524
525
match et {
525
- Some ( EntryFnType :: Main ) => create_entry_fn ( cx, span, main_llfn, main_def_id, true ) ,
526
- Some ( EntryFnType :: Start ) => create_entry_fn ( cx, span, main_llfn, main_def_id, false ) ,
526
+ Some ( EntryFnType :: Main ) => create_entry_fn :: < Bx > ( cx, span, main_llfn, main_def_id, true ) ,
527
+ Some ( EntryFnType :: Start ) => create_entry_fn :: < Bx > ( cx, span, main_llfn, main_def_id, false ) ,
527
528
None => { } // Do nothing.
528
529
}
529
530
530
- fn create_entry_fn (
531
- cx : & CodegenCx < ' ll , ' _ , & ' ll Value > ,
531
+ fn create_entry_fn < ' a , ' ll : ' a , ' tcx : ' ll , Bx : BuilderMethods < ' a , ' ll , ' tcx > > (
532
+ cx : & ' a Bx :: CodegenCx ,
532
533
sp : Span ,
533
- rust_main : & ' ll Value ,
534
+ rust_main : < Bx :: CodegenCx as Backend < ' ll > > :: Value ,
534
535
rust_main_def_id : DefId ,
535
536
use_start_lang_item : bool ,
536
537
) {
537
538
let llfty =
538
539
cx. type_func ( & [ cx. type_int ( ) , cx. type_ptr_to ( cx. type_i8p ( ) ) ] , cx. type_int ( ) ) ;
539
540
540
- let main_ret_ty = cx. tcx . fn_sig ( rust_main_def_id) . output ( ) ;
541
+ let main_ret_ty = cx. tcx ( ) . fn_sig ( rust_main_def_id) . output ( ) ;
541
542
// Given that `main()` has no arguments,
542
543
// then its return type cannot have
543
544
// late-bound regions, since late-bound
544
545
// regions must appear in the argument
545
546
// listing.
546
- let main_ret_ty = cx. tcx . erase_regions (
547
+ let main_ret_ty = cx. tcx ( ) . erase_regions (
547
548
& main_ret_ty. no_late_bound_regions ( ) . unwrap ( ) ,
548
549
) ;
549
550
@@ -558,25 +559,25 @@ fn maybe_create_entry_wrapper(cx: &CodegenCx<'ll, '_, &'ll Value>) {
558
559
let llfn = cx. declare_cfn ( "main" , llfty) ;
559
560
560
561
// `main` should respect same config for frame pointer elimination as rest of code
561
- attributes :: set_frame_pointer_elimination ( cx , llfn) ;
562
- attributes :: apply_target_cpu_attr ( cx , llfn) ;
562
+ cx . set_frame_pointer_elimination ( llfn) ;
563
+ cx . apply_target_cpu_attr ( llfn) ;
563
564
564
- let bx = Builder :: new_block ( cx, llfn, "top" ) ;
565
+ let bx = Bx :: new_block ( & cx, llfn, "top" ) ;
565
566
566
- debuginfo :: gdb :: insert_reference_to_gdb_debug_scripts_section_global ( & bx ) ;
567
+ bx . insert_reference_to_gdb_debug_scripts_section_global ( ) ;
567
568
568
569
// Params from native main() used as args for rust start function
569
- let param_argc = get_param ( llfn, 0 ) ;
570
- let param_argv = get_param ( llfn, 1 ) ;
571
- let arg_argc = bx. intcast ( param_argc, cx. isize_ty , true ) ;
570
+ let param_argc = cx . get_param ( llfn, 0 ) ;
571
+ let param_argv = cx . get_param ( llfn, 1 ) ;
572
+ let arg_argc = bx. intcast ( param_argc, cx. type_isize ( ) , true ) ;
572
573
let arg_argv = param_argv;
573
574
574
575
let ( start_fn, args) = if use_start_lang_item {
575
- let start_def_id = cx. tcx . require_lang_item ( StartFnLangItem ) ;
576
+ let start_def_id = cx. tcx ( ) . require_lang_item ( StartFnLangItem ) ;
576
577
let start_fn = callee:: resolve_and_get_fn (
577
578
cx,
578
579
start_def_id,
579
- cx. tcx . intern_substs ( & [ main_ret_ty. into ( ) ] ) ,
580
+ cx. tcx ( ) . intern_substs ( & [ main_ret_ty. into ( ) ] ) ,
580
581
) ;
581
582
( start_fn, vec ! [ bx. pointercast( rust_main, cx. type_ptr_to( cx. type_i8p( ) ) ) ,
582
583
arg_argc, arg_argv] )
@@ -1212,7 +1213,7 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1212
1213
1213
1214
// If this codegen unit contains the main function, also create the
1214
1215
// wrapper here
1215
- maybe_create_entry_wrapper ( & cx) ;
1216
+ maybe_create_entry_wrapper :: < Builder < & Value > > ( & cx) ;
1216
1217
1217
1218
// Run replace-all-uses-with for statics that need it
1218
1219
for & ( old_g, new_g) in cx. statics_to_rauw . borrow ( ) . iter ( ) {
0 commit comments