1414//! item-path. This is used for unit testing the code that generates
1515//! paths etc in all kinds of annoying scenarios.
1616
17+ use asm;
1718use attributes;
1819use base;
1920use consts;
@@ -42,7 +43,8 @@ use std::iter;
4243pub enum TransItem < ' tcx > {
4344 DropGlue ( DropGlueKind < ' tcx > ) ,
4445 Fn ( Instance < ' tcx > ) ,
45- Static ( NodeId )
46+ Static ( NodeId ) ,
47+ GlobalAsm ( NodeId ) ,
4648}
4749
4850/// Describes how a translation item will be instantiated in object files.
@@ -93,6 +95,14 @@ impl<'a, 'tcx> TransItem<'tcx> {
9395 span_bug ! ( item. span, "Mismatch between hir::Item type and TransItem type" )
9496 }
9597 }
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+ }
96106 TransItem :: Fn ( instance) => {
97107 let _task = ccx. tcx ( ) . dep_graph . in_task (
98108 DepNode :: TransCrateItem ( instance. def ) ) ; // (*)
@@ -133,6 +143,7 @@ impl<'a, 'tcx> TransItem<'tcx> {
133143 TransItem :: DropGlue ( dg) => {
134144 TransItem :: predefine_drop_glue ( ccx, dg, linkage, & symbol_name) ;
135145 }
146+ TransItem :: GlobalAsm ( ..) => { }
136147 }
137148
138149 debug ! ( "END PREDEFINING '{} ({})' in cgu {}" ,
@@ -235,14 +246,19 @@ impl<'a, 'tcx> TransItem<'tcx> {
235246 } ;
236247 symbol_names:: exported_name_from_type_and_prefix ( scx, dg. ty ( ) , prefix)
237248 }
249+ TransItem :: GlobalAsm ( node_id) => {
250+ let def_id = scx. tcx ( ) . hir . local_def_id ( node_id) ;
251+ format ! ( "global_asm_{:?}" , def_id)
252+ }
238253 }
239254 }
240255
241256 pub fn is_from_extern_crate ( & self ) -> bool {
242257 match * self {
243258 TransItem :: Fn ( ref instance) => !instance. def . is_local ( ) ,
244259 TransItem :: DropGlue ( ..) |
245- TransItem :: Static ( ..) => false ,
260+ TransItem :: Static ( ..) |
261+ TransItem :: GlobalAsm ( ..) => false ,
246262 }
247263 }
248264
@@ -261,6 +277,7 @@ impl<'a, 'tcx> TransItem<'tcx> {
261277 }
262278 TransItem :: DropGlue ( ..) => InstantiationMode :: LocalCopy ,
263279 TransItem :: Static ( ..) => InstantiationMode :: GloballyShared ,
280+ TransItem :: GlobalAsm ( ..) => InstantiationMode :: GloballyShared ,
264281 }
265282 }
266283
@@ -270,15 +287,16 @@ impl<'a, 'tcx> TransItem<'tcx> {
270287 instance. substs . types ( ) . next ( ) . is_some ( )
271288 }
272289 TransItem :: DropGlue ( ..) |
273- TransItem :: Static ( ..) => false ,
290+ TransItem :: Static ( ..) |
291+ TransItem :: GlobalAsm ( ..) => false ,
274292 }
275293 }
276294
277295 pub fn explicit_linkage ( & self , tcx : TyCtxt < ' a , ' tcx , ' tcx > ) -> Option < llvm:: Linkage > {
278296 let def_id = match * self {
279297 TransItem :: Fn ( ref instance) => instance. def ,
280298 TransItem :: Static ( node_id) => tcx. hir . local_def_id ( node_id) ,
281- TransItem :: DropGlue ( ..) => return None ,
299+ TransItem :: DropGlue ( ..) | TransItem :: GlobalAsm ( .. ) => return None ,
282300 } ;
283301
284302 let attributes = tcx. get_attrs ( def_id) ;
@@ -320,6 +338,9 @@ impl<'a, 'tcx> TransItem<'tcx> {
320338 let instance = Instance :: new ( def_id, tcx. intern_substs ( & [ ] ) ) ;
321339 to_string_internal ( tcx, "static " , instance)
322340 } ,
341+ TransItem :: GlobalAsm ( ..) => {
342+ "global_asm" . to_string ( )
343+ }
323344 } ;
324345
325346 fn to_string_internal < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
@@ -351,6 +372,9 @@ impl<'a, 'tcx> TransItem<'tcx> {
351372 TransItem :: Static ( id) => {
352373 format ! ( "Static({:?})" , id)
353374 }
375+ TransItem :: GlobalAsm ( id) => {
376+ format ! ( "GlobalAsm({:?})" , id)
377+ }
354378 }
355379 }
356380}
0 commit comments