1
- #[ cfg( feature= "master" ) ]
1
+ #[ cfg( feature = "master" ) ]
2
2
use gccjit:: FnAttribute ;
3
3
use gccjit:: { FunctionType , GlobalKind , ToRValue } ;
4
4
use rustc_ast:: expand:: allocator:: {
5
- alloc_error_handler_name , default_fn_name, global_fn_name, AllocatorKind , AllocatorTy ,
6
- ALLOCATOR_METHODS , NO_ALLOC_SHIM_IS_UNSTABLE ,
5
+ default_fn_name, global_fn_name, AllocatorKind , AllocatorTy , ALLOCATOR_METHODS ,
6
+ NO_ALLOC_SHIM_IS_UNSTABLE ,
7
7
} ;
8
8
use rustc_middle:: bug;
9
9
use rustc_middle:: ty:: TyCtxt ;
10
10
use rustc_session:: config:: OomStrategy ;
11
11
12
12
use crate :: GccContext ;
13
13
14
- pub ( crate ) unsafe fn codegen ( tcx : TyCtxt < ' _ > , mods : & mut GccContext , _module_name : & str , kind : AllocatorKind , alloc_error_handler_kind : AllocatorKind ) {
14
+ pub ( crate ) unsafe fn codegen (
15
+ tcx : TyCtxt < ' _ > ,
16
+ mods : & mut GccContext ,
17
+ _module_name : & str ,
18
+ kind : AllocatorKind ,
19
+ ) {
15
20
let context = & mods. context ;
16
- let usize =
17
- match tcx. sess . target . pointer_width {
18
- 16 => context. new_type :: < u16 > ( ) ,
19
- 32 => context. new_type :: < u32 > ( ) ,
20
- 64 => context. new_type :: < u64 > ( ) ,
21
- tws => bug ! ( "Unsupported target word size for int: {}" , tws) ,
22
- } ;
21
+ let usize = match tcx. sess . target . pointer_width {
22
+ 16 => context. new_type :: < u16 > ( ) ,
23
+ 32 => context. new_type :: < u32 > ( ) ,
24
+ 64 => context. new_type :: < u64 > ( ) ,
25
+ tws => bug ! ( "Unsupported target word size for int: {}" , tws) ,
26
+ } ;
23
27
let i8 = context. new_type :: < i8 > ( ) ;
24
28
let i8p = i8. make_pointer ( ) ;
25
29
let void = context. new_type :: < ( ) > ( ) ;
@@ -49,25 +53,43 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam
49
53
} ;
50
54
let name = global_fn_name ( method. name ) ;
51
55
52
- let args: Vec < _ > = types. iter ( ) . enumerate ( )
56
+ let args: Vec < _ > = types
57
+ . iter ( )
58
+ . enumerate ( )
53
59
. map ( |( index, typ) | context. new_parameter ( None , * typ, & format ! ( "param{}" , index) ) )
54
60
. collect ( ) ;
55
- let func = context. new_function ( None , FunctionType :: Exported , output. unwrap_or ( void) , & args, name, false ) ;
61
+ let func = context. new_function (
62
+ None ,
63
+ FunctionType :: Exported ,
64
+ output. unwrap_or ( void) ,
65
+ & args,
66
+ name,
67
+ false ,
68
+ ) ;
56
69
57
70
if tcx. sess . target . options . default_hidden_visibility {
58
- #[ cfg( feature= "master" ) ]
71
+ #[ cfg( feature = "master" ) ]
59
72
func. add_attribute ( FnAttribute :: Visibility ( gccjit:: Visibility :: Hidden ) ) ;
60
73
}
61
74
if tcx. sess . must_emit_unwind_tables ( ) {
62
75
// TODO(antoyo): emit unwind tables.
63
76
}
64
77
65
78
let callee = default_fn_name ( method. name ) ;
66
- let args: Vec < _ > = types. iter ( ) . enumerate ( )
79
+ let args: Vec < _ > = types
80
+ . iter ( )
81
+ . enumerate ( )
67
82
. map ( |( index, typ) | context. new_parameter ( None , * typ, & format ! ( "param{}" , index) ) )
68
83
. collect ( ) ;
69
- let callee = context. new_function ( None , FunctionType :: Extern , output. unwrap_or ( void) , & args, callee, false ) ;
70
- #[ cfg( feature="master" ) ]
84
+ let callee = context. new_function (
85
+ None ,
86
+ FunctionType :: Extern ,
87
+ output. unwrap_or ( void) ,
88
+ & args,
89
+ callee,
90
+ false ,
91
+ ) ;
92
+ #[ cfg( feature = "master" ) ]
71
93
callee. add_attribute ( FnAttribute :: Visibility ( gccjit:: Visibility :: Hidden ) ) ;
72
94
73
95
let block = func. new_block ( "entry" ) ;
@@ -81,8 +103,7 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam
81
103
//llvm::LLVMSetTailCall(ret, True);
82
104
if output. is_some ( ) {
83
105
block. end_with_return ( None , ret) ;
84
- }
85
- else {
106
+ } else {
86
107
block. end_with_void_return ( None ) ;
87
108
}
88
109
@@ -91,37 +112,6 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam
91
112
}
92
113
}
93
114
94
- let types = [ usize, usize] ;
95
- let name = "__rust_alloc_error_handler" . to_string ( ) ;
96
- let args: Vec < _ > = types. iter ( ) . enumerate ( )
97
- . map ( |( index, typ) | context. new_parameter ( None , * typ, & format ! ( "param{}" , index) ) )
98
- . collect ( ) ;
99
- let func = context. new_function ( None , FunctionType :: Exported , void, & args, name, false ) ;
100
-
101
- if tcx. sess . target . default_hidden_visibility {
102
- #[ cfg( feature="master" ) ]
103
- func. add_attribute ( FnAttribute :: Visibility ( gccjit:: Visibility :: Hidden ) ) ;
104
- }
105
-
106
- let callee = alloc_error_handler_name ( alloc_error_handler_kind) ;
107
- let args: Vec < _ > = types. iter ( ) . enumerate ( )
108
- . map ( |( index, typ) | context. new_parameter ( None , * typ, & format ! ( "param{}" , index) ) )
109
- . collect ( ) ;
110
- let callee = context. new_function ( None , FunctionType :: Extern , void, & args, callee, false ) ;
111
- #[ cfg( feature="master" ) ]
112
- callee. add_attribute ( FnAttribute :: Visibility ( gccjit:: Visibility :: Hidden ) ) ;
113
-
114
- let block = func. new_block ( "entry" ) ;
115
-
116
- let args = args
117
- . iter ( )
118
- . enumerate ( )
119
- . map ( |( i, _) | func. get_param ( i as i32 ) . to_rvalue ( ) )
120
- . collect :: < Vec < _ > > ( ) ;
121
- let _ret = context. new_call ( None , callee, & args) ;
122
- //llvm::LLVMSetTailCall(ret, True);
123
- block. end_with_void_return ( None ) ;
124
-
125
115
let name = OomStrategy :: SYMBOL . to_string ( ) ;
126
116
let global = context. new_global ( None , GlobalKind :: Exported , i8, name) ;
127
117
let value = tcx. sess . opts . unstable_opts . oom . should_panic ( ) ;
0 commit comments