@@ -8,10 +8,10 @@ use rustc::session::config::{DebugInfo, OutputType};
8
8
use rustc_codegen_ssa:: back:: linker:: LinkerInfo ;
9
9
use rustc_codegen_ssa:: CrateInfo ;
10
10
11
- use cranelift_faerie:: * ;
12
-
13
11
use crate :: prelude:: * ;
14
12
13
+ use crate :: backend:: { Emit , WriteDebugInfo } ;
14
+
15
15
pub fn codegen_crate (
16
16
tcx : TyCtxt < ' _ > ,
17
17
metadata : EncodedMetadata ,
@@ -147,59 +147,57 @@ fn run_aot(
147
147
need_metadata_module : bool ,
148
148
) -> Box < CodegenResults > {
149
149
let new_module = |name : String | {
150
- let module: Module < FaerieBackend > = Module :: new (
151
- FaerieBuilder :: new (
152
- crate :: build_isa ( tcx. sess , true ) ,
153
- name + ".o" ,
154
- FaerieTrapCollection :: Disabled ,
155
- cranelift_module:: default_libcall_names ( ) ,
156
- )
157
- . unwrap ( ) ,
158
- ) ;
150
+ let module = crate :: backend:: make_module ( tcx. sess , name) ;
159
151
assert_eq ! ( pointer_ty( tcx) , module. target_config( ) . pointer_type( ) ) ;
160
152
module
161
153
} ;
162
154
163
- let emit_module = |kind : ModuleKind ,
164
- mut module : Module < FaerieBackend > ,
165
- debug : Option < DebugContext > | {
155
+ fn emit_module < B : Backend > (
156
+ tcx : TyCtxt < ' _ > ,
157
+ name : String ,
158
+ kind : ModuleKind ,
159
+ mut module : Module < B > ,
160
+ debug : Option < DebugContext > ,
161
+ ) -> CompiledModule
162
+ where B :: Product : Emit + WriteDebugInfo ,
163
+ {
166
164
module. finalize_definitions ( ) ;
167
- let mut artifact = module. finish ( ) . artifact ;
165
+ let mut product = module. finish ( ) ;
168
166
169
167
if let Some ( mut debug) = debug {
170
- debug. emit ( & mut artifact ) ;
168
+ debug. emit ( & mut product ) ;
171
169
}
172
170
173
171
let tmp_file = tcx
174
172
. output_filenames ( LOCAL_CRATE )
175
- . temp_path ( OutputType :: Object , Some ( & artifact . name ) ) ;
176
- let obj = artifact . emit ( ) . unwrap ( ) ;
173
+ . temp_path ( OutputType :: Object , Some ( & name) ) ;
174
+ let obj = product . emit ( ) ;
177
175
std:: fs:: write ( & tmp_file, obj) . unwrap ( ) ;
178
176
CompiledModule {
179
- name : artifact . name ,
177
+ name : name,
180
178
kind,
181
179
object : Some ( tmp_file) ,
182
180
bytecode : None ,
183
181
bytecode_compressed : None ,
184
182
}
185
183
} ;
186
184
187
- let mut faerie_module = new_module ( "some_file" . to_string ( ) ) ;
185
+ let mut module = new_module ( "some_file" . to_string ( ) ) ;
188
186
189
187
let mut debug = if tcx. sess . opts . debuginfo != DebugInfo :: None
190
188
// macOS debuginfo doesn't work yet (see #303)
191
189
&& !tcx. sess . target . target . options . is_like_osx
192
190
{
193
191
let debug = DebugContext :: new (
194
192
tcx,
195
- faerie_module . target_config ( ) . pointer_type ( ) . bytes ( ) as u8 ,
193
+ module . target_config ( ) . pointer_type ( ) . bytes ( ) as u8 ,
196
194
) ;
197
195
Some ( debug)
198
196
} else {
199
197
None
200
198
} ;
201
199
202
- codegen_cgus ( tcx, & mut faerie_module , & mut debug) ;
200
+ codegen_cgus ( tcx, & mut module , & mut debug) ;
203
201
204
202
tcx. sess . abort_if_errors ( ) ;
205
203
@@ -221,17 +219,14 @@ fn run_aot(
221
219
. as_str ( )
222
220
. to_string ( ) ;
223
221
224
- let mut metadata_artifact = faerie:: Artifact :: new (
225
- crate :: build_isa ( tcx. sess , true ) . triple ( ) . clone ( ) ,
226
- metadata_cgu_name. clone ( ) ,
227
- ) ;
228
- crate :: metadata:: write_metadata ( tcx, & mut metadata_artifact) ;
229
-
230
222
let tmp_file = tcx
231
223
. output_filenames ( LOCAL_CRATE )
232
224
. temp_path ( OutputType :: Metadata , Some ( & metadata_cgu_name) ) ;
233
225
234
- let obj = metadata_artifact. emit ( ) . unwrap ( ) ;
226
+ let obj = crate :: backend:: with_object ( tcx. sess , & metadata_cgu_name, |object| {
227
+ crate :: metadata:: write_metadata ( tcx, object) ;
228
+ } ) ;
229
+
235
230
std:: fs:: write ( & tmp_file, obj) . unwrap ( ) ;
236
231
237
232
( metadata_cgu_name, tmp_file)
@@ -251,12 +246,16 @@ fn run_aot(
251
246
Box :: new ( CodegenResults {
252
247
crate_name : tcx. crate_name ( LOCAL_CRATE ) ,
253
248
modules : vec ! [ emit_module(
249
+ tcx,
250
+ "some_file" . to_string( ) ,
254
251
ModuleKind :: Regular ,
255
- faerie_module ,
252
+ module ,
256
253
debug,
257
254
) ] ,
258
255
allocator_module : if created_alloc_shim {
259
256
Some ( emit_module (
257
+ tcx,
258
+ "allocator_shim" . to_string ( ) ,
260
259
ModuleKind :: Allocator ,
261
260
allocator_module,
262
261
None ,
0 commit comments