14
14
//! item-path. This is used for unit testing the code that generates
15
15
//! paths etc in all kinds of annoying scenarios.
16
16
17
+ use asm;
17
18
use attributes;
18
19
use base;
19
20
use consts;
@@ -42,7 +43,8 @@ use std::iter;
42
43
pub enum TransItem < ' tcx > {
43
44
DropGlue ( DropGlueKind < ' tcx > ) ,
44
45
Fn ( Instance < ' tcx > ) ,
45
- Static ( NodeId )
46
+ Static ( NodeId ) ,
47
+ GlobalAsm ( NodeId ) ,
46
48
}
47
49
48
50
/// Describes how a translation item will be instantiated in object files.
@@ -93,6 +95,14 @@ impl<'a, 'tcx> TransItem<'tcx> {
93
95
span_bug ! ( item. span, "Mismatch between hir::Item type and TransItem type" )
94
96
}
95
97
}
98
+ TransItem :: GlobalAsm ( node_id) => {
99
+ let item = ccx. tcx ( ) . hir . expect_item ( node_id) ;
100
+ if let hir:: ItemGlobalAsm ( ref ga) = item. node {
101
+ asm:: trans_global_asm ( ccx, ga) ;
102
+ } else {
103
+ span_bug ! ( item. span, "Mismatch between hir::Item type and TransItem type" )
104
+ }
105
+ }
96
106
TransItem :: Fn ( instance) => {
97
107
let _task = ccx. tcx ( ) . dep_graph . in_task (
98
108
DepNode :: TransCrateItem ( instance. def ) ) ; // (*)
@@ -133,6 +143,7 @@ impl<'a, 'tcx> TransItem<'tcx> {
133
143
TransItem :: DropGlue ( dg) => {
134
144
TransItem :: predefine_drop_glue ( ccx, dg, linkage, & symbol_name) ;
135
145
}
146
+ TransItem :: GlobalAsm ( ..) => { }
136
147
}
137
148
138
149
debug ! ( "END PREDEFINING '{} ({})' in cgu {}" ,
@@ -235,14 +246,19 @@ impl<'a, 'tcx> TransItem<'tcx> {
235
246
} ;
236
247
symbol_names:: exported_name_from_type_and_prefix ( scx, dg. ty ( ) , prefix)
237
248
}
249
+ TransItem :: GlobalAsm ( node_id) => {
250
+ let def_id = scx. tcx ( ) . hir . local_def_id ( node_id) ;
251
+ format ! ( "global_asm_{:?}" , def_id)
252
+ }
238
253
}
239
254
}
240
255
241
256
pub fn is_from_extern_crate ( & self ) -> bool {
242
257
match * self {
243
258
TransItem :: Fn ( ref instance) => !instance. def . is_local ( ) ,
244
259
TransItem :: DropGlue ( ..) |
245
- TransItem :: Static ( ..) => false ,
260
+ TransItem :: Static ( ..) |
261
+ TransItem :: GlobalAsm ( ..) => false ,
246
262
}
247
263
}
248
264
@@ -261,6 +277,7 @@ impl<'a, 'tcx> TransItem<'tcx> {
261
277
}
262
278
TransItem :: DropGlue ( ..) => InstantiationMode :: LocalCopy ,
263
279
TransItem :: Static ( ..) => InstantiationMode :: GloballyShared ,
280
+ TransItem :: GlobalAsm ( ..) => InstantiationMode :: GloballyShared ,
264
281
}
265
282
}
266
283
@@ -270,15 +287,16 @@ impl<'a, 'tcx> TransItem<'tcx> {
270
287
instance. substs . types ( ) . next ( ) . is_some ( )
271
288
}
272
289
TransItem :: DropGlue ( ..) |
273
- TransItem :: Static ( ..) => false ,
290
+ TransItem :: Static ( ..) |
291
+ TransItem :: GlobalAsm ( ..) => false ,
274
292
}
275
293
}
276
294
277
295
pub fn explicit_linkage ( & self , tcx : TyCtxt < ' a , ' tcx , ' tcx > ) -> Option < llvm:: Linkage > {
278
296
let def_id = match * self {
279
297
TransItem :: Fn ( ref instance) => instance. def ,
280
298
TransItem :: Static ( node_id) => tcx. hir . local_def_id ( node_id) ,
281
- TransItem :: DropGlue ( ..) => return None ,
299
+ TransItem :: DropGlue ( ..) | TransItem :: GlobalAsm ( .. ) => return None ,
282
300
} ;
283
301
284
302
let attributes = tcx. get_attrs ( def_id) ;
@@ -320,6 +338,9 @@ impl<'a, 'tcx> TransItem<'tcx> {
320
338
let instance = Instance :: new ( def_id, tcx. intern_substs ( & [ ] ) ) ;
321
339
to_string_internal ( tcx, "static " , instance)
322
340
} ,
341
+ TransItem :: GlobalAsm ( ..) => {
342
+ "global_asm" . to_string ( )
343
+ }
323
344
} ;
324
345
325
346
fn to_string_internal < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
@@ -351,6 +372,9 @@ impl<'a, 'tcx> TransItem<'tcx> {
351
372
TransItem :: Static ( id) => {
352
373
format ! ( "Static({:?})" , id)
353
374
}
375
+ TransItem :: GlobalAsm ( id) => {
376
+ format ! ( "GlobalAsm({:?})" , id)
377
+ }
354
378
}
355
379
}
356
380
}
0 commit comments