1
- use gccjit:: { Context , FunctionType , GlobalKind , ToRValue , Type } ;
1
+ use gccjit:: GlobalKind ;
2
2
#[ cfg( feature = "master" ) ]
3
- use gccjit:: { FnAttribute , VarAttribute } ;
4
- use rustc_ast:: expand:: allocator:: {
5
- ALLOCATOR_METHODS , AllocatorKind , AllocatorTy , NO_ALLOC_SHIM_IS_UNSTABLE ,
6
- alloc_error_handler_name, default_fn_name, global_fn_name,
7
- } ;
8
- use rustc_middle:: bug;
3
+ use gccjit:: VarAttribute ;
4
+ use rustc_ast:: expand:: allocator:: NO_ALLOC_SHIM_IS_UNSTABLE ;
9
5
use rustc_middle:: ty:: TyCtxt ;
10
6
use rustc_session:: config:: OomStrategy ;
11
7
12
8
use crate :: GccContext ;
13
9
#[ cfg( feature = "master" ) ]
14
10
use crate :: base:: symbol_visibility_to_gcc;
15
11
16
- pub ( crate ) unsafe fn codegen (
17
- tcx : TyCtxt < ' _ > ,
18
- mods : & mut GccContext ,
19
- _module_name : & str ,
20
- kind : AllocatorKind ,
21
- alloc_error_handler_kind : AllocatorKind ,
22
- ) {
12
+ pub ( crate ) unsafe fn codegen ( tcx : TyCtxt < ' _ > , mods : & mut GccContext , _module_name : & str ) {
23
13
let context = & mods. context ;
24
- let usize = match tcx. sess . target . pointer_width {
25
- 16 => context. new_type :: < u16 > ( ) ,
26
- 32 => context. new_type :: < u32 > ( ) ,
27
- 64 => context. new_type :: < u64 > ( ) ,
28
- tws => bug ! ( "Unsupported target word size for int: {}" , tws) ,
29
- } ;
30
14
let i8 = context. new_type :: < i8 > ( ) ;
31
- let i8p = i8. make_pointer ( ) ;
32
-
33
- if kind == AllocatorKind :: Default {
34
- for method in ALLOCATOR_METHODS {
35
- let mut types = Vec :: with_capacity ( method. inputs . len ( ) ) ;
36
- for input in method. inputs . iter ( ) {
37
- match input. ty {
38
- AllocatorTy :: Layout => {
39
- types. push ( usize) ;
40
- types. push ( usize) ;
41
- }
42
- AllocatorTy :: Ptr => types. push ( i8p) ,
43
- AllocatorTy :: Usize => types. push ( usize) ,
44
-
45
- AllocatorTy :: ResultPtr | AllocatorTy :: Unit => panic ! ( "invalid allocator arg" ) ,
46
- }
47
- }
48
- let output = match method. output {
49
- AllocatorTy :: ResultPtr => Some ( i8p) ,
50
- AllocatorTy :: Unit => None ,
51
-
52
- AllocatorTy :: Layout | AllocatorTy :: Usize | AllocatorTy :: Ptr => {
53
- panic ! ( "invalid allocator output" )
54
- }
55
- } ;
56
- let from_name = global_fn_name ( method. name ) ;
57
- let to_name = default_fn_name ( method. name ) ;
58
-
59
- create_wrapper_function ( tcx, context, & from_name, & to_name, & types, output) ;
60
- }
61
- }
62
-
63
- // FIXME(bjorn3): Add noreturn attribute
64
- create_wrapper_function (
65
- tcx,
66
- context,
67
- "__rust_alloc_error_handler" ,
68
- alloc_error_handler_name ( alloc_error_handler_kind) ,
69
- & [ usize, usize] ,
70
- None ,
71
- ) ;
72
15
73
16
let name = OomStrategy :: SYMBOL . to_string ( ) ;
74
17
let global = context. new_global ( None , GlobalKind :: Exported , i8, name) ;
@@ -89,71 +32,3 @@ pub(crate) unsafe fn codegen(
89
32
let value = context. new_rvalue_from_int ( i8, 0 ) ;
90
33
global. global_set_initializer_rvalue ( value) ;
91
34
}
92
-
93
- fn create_wrapper_function (
94
- tcx : TyCtxt < ' _ > ,
95
- context : & Context < ' _ > ,
96
- from_name : & str ,
97
- to_name : & str ,
98
- types : & [ Type < ' _ > ] ,
99
- output : Option < Type < ' _ > > ,
100
- ) {
101
- let void = context. new_type :: < ( ) > ( ) ;
102
-
103
- let args: Vec < _ > = types
104
- . iter ( )
105
- . enumerate ( )
106
- . map ( |( index, typ) | context. new_parameter ( None , * typ, format ! ( "param{}" , index) ) )
107
- . collect ( ) ;
108
- let func = context. new_function (
109
- None ,
110
- FunctionType :: Exported ,
111
- output. unwrap_or ( void) ,
112
- & args,
113
- from_name,
114
- false ,
115
- ) ;
116
-
117
- #[ cfg( feature = "master" ) ]
118
- func. add_attribute ( FnAttribute :: Visibility ( symbol_visibility_to_gcc (
119
- tcx. sess . default_visibility ( ) ,
120
- ) ) ) ;
121
-
122
- if tcx. sess . must_emit_unwind_tables ( ) {
123
- // TODO(antoyo): emit unwind tables.
124
- }
125
-
126
- let args: Vec < _ > = types
127
- . iter ( )
128
- . enumerate ( )
129
- . map ( |( index, typ) | context. new_parameter ( None , * typ, format ! ( "param{}" , index) ) )
130
- . collect ( ) ;
131
- let callee = context. new_function (
132
- None ,
133
- FunctionType :: Extern ,
134
- output. unwrap_or ( void) ,
135
- & args,
136
- to_name,
137
- false ,
138
- ) ;
139
- #[ cfg( feature = "master" ) ]
140
- callee. add_attribute ( FnAttribute :: Visibility ( gccjit:: Visibility :: Hidden ) ) ;
141
-
142
- let block = func. new_block ( "entry" ) ;
143
-
144
- let args = args
145
- . iter ( )
146
- . enumerate ( )
147
- . map ( |( i, _) | func. get_param ( i as i32 ) . to_rvalue ( ) )
148
- . collect :: < Vec < _ > > ( ) ;
149
- let ret = context. new_call ( None , callee, & args) ;
150
- //llvm::LLVMSetTailCall(ret, True);
151
- if output. is_some ( ) {
152
- block. end_with_return ( None , ret) ;
153
- } else {
154
- block. end_with_void_return ( None ) ;
155
- }
156
-
157
- // TODO(@Commeownist): Check if we need to emit some extra debugging info in certain circumstances
158
- // as described in https://github.com./rust-lang/rust/commit/77a96ed5646f7c3ee8897693decc4626fe380643
159
- }
0 commit comments