1
- use gccjit:: { Function , FunctionType , GlobalKind , RValue , ToRValue , Type } ;
1
+ use gccjit:: { Function , FunctionType , GlobalKind , LValue , RValue , ToRValue , Type } ;
2
2
use rustc_codegen_ssa:: traits:: { BaseTypeMethods , DeclareMethods } ;
3
3
use rustc_middle:: ty:: Ty ;
4
4
use rustc_target:: abi:: call:: FnAbi ;
@@ -18,6 +18,13 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
18
18
}
19
19
}
20
20
21
+ pub fn declare_unnamed_global ( & self , ty : Type < ' gcc > ) -> LValue < ' gcc > {
22
+ let index = self . global_gen_sym_counter . get ( ) ;
23
+ self . global_gen_sym_counter . set ( index + 1 ) ;
24
+ let name = format ! ( "global_{}_{}" , index, unit_name( & self . codegen_unit) ) ;
25
+ self . context . new_global ( None , GlobalKind :: Exported , ty, & name)
26
+ }
27
+
21
28
pub fn declare_global_with_linkage ( & self , name : & str , ty : Type < ' gcc > , linkage : GlobalKind ) -> RValue < ' gcc > {
22
29
//debug!("declare_global_with_linkage(name={:?})", name);
23
30
let global = self . context . new_global ( None , linkage, ty, name)
@@ -77,11 +84,8 @@ impl<'gcc, 'tcx> DeclareMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
77
84
}
78
85
79
86
fn define_private_global ( & self , ty : Type < ' gcc > ) -> RValue < ' gcc > {
80
- let index = self . global_gen_sym_counter . get ( ) ;
81
- self . global_gen_sym_counter . set ( index + 1 ) ;
82
- let name = format ! ( "global_{}_{}" , index, unit_name( & self . codegen_unit) ) ;
83
- self . context . new_global ( None , GlobalKind :: Exported , ty, & name)
84
- . get_address ( None )
87
+ let global = self . declare_unnamed_global ( ty) ;
88
+ global. get_address ( None )
85
89
}
86
90
87
91
fn get_declared_value ( & self , name : & str ) -> Option < RValue < ' gcc > > {
0 commit comments