11//! Code that is useful in various codegen modules.
22
3- use std:: fmt:: Write ;
4-
53use libc:: { c_char, c_uint} ;
64use rustc_ast:: Mutability ;
75use rustc_codegen_ssa:: traits:: * ;
@@ -10,9 +8,8 @@ use rustc_hir::def_id::DefId;
108use rustc_middle:: bug;
119use rustc_middle:: mir:: interpret:: { ConstAllocation , GlobalAlloc , Scalar } ;
1210use rustc_middle:: ty:: TyCtxt ;
13- use rustc_session:: cstore:: { DllCallingConvention , DllImport , PeImportNameType } ;
11+ use rustc_session:: cstore:: DllImport ;
1412use rustc_target:: abi:: { self , AddressSpace , HasDataLayout , Pointer } ;
15- use rustc_target:: spec:: Target ;
1613use tracing:: debug;
1714
1815use crate :: consts:: const_alloc_to_llvm;
@@ -379,64 +376,3 @@ pub(crate) fn get_dllimport<'tcx>(
379376 tcx. native_library ( id)
380377 . and_then ( |lib| lib. dll_imports . iter ( ) . find ( |di| di. name . as_str ( ) == name) )
381378}
382-
383- pub ( crate ) fn is_mingw_gnu_toolchain ( target : & Target ) -> bool {
384- target. vendor == "pc" && target. os == "windows" && target. env == "gnu" && target. abi . is_empty ( )
385- }
386-
387- pub ( crate ) fn i686_decorated_name (
388- dll_import : & DllImport ,
389- mingw : bool ,
390- disable_name_mangling : bool ,
391- ) -> String {
392- let name = dll_import. name . as_str ( ) ;
393-
394- let ( add_prefix, add_suffix) = match dll_import. import_name_type {
395- Some ( PeImportNameType :: NoPrefix ) => ( false , true ) ,
396- Some ( PeImportNameType :: Undecorated ) => ( false , false ) ,
397- _ => ( true , true ) ,
398- } ;
399-
400- // Worst case: +1 for disable name mangling, +1 for prefix, +4 for suffix (@@__).
401- let mut decorated_name = String :: with_capacity ( name. len ( ) + 6 ) ;
402-
403- if disable_name_mangling {
404- // LLVM uses a binary 1 ('\x01') prefix to a name to indicate that mangling needs to be disabled.
405- decorated_name. push ( '\x01' ) ;
406- }
407-
408- let prefix = if add_prefix && dll_import. is_fn {
409- match dll_import. calling_convention {
410- DllCallingConvention :: C | DllCallingConvention :: Vectorcall ( _) => None ,
411- DllCallingConvention :: Stdcall ( _) => ( !mingw
412- || dll_import. import_name_type == Some ( PeImportNameType :: Decorated ) )
413- . then_some ( '_' ) ,
414- DllCallingConvention :: Fastcall ( _) => Some ( '@' ) ,
415- }
416- } else if !dll_import. is_fn && !mingw {
417- // For static variables, prefix with '_' on MSVC.
418- Some ( '_' )
419- } else {
420- None
421- } ;
422- if let Some ( prefix) = prefix {
423- decorated_name. push ( prefix) ;
424- }
425-
426- decorated_name. push_str ( name) ;
427-
428- if add_suffix && dll_import. is_fn {
429- match dll_import. calling_convention {
430- DllCallingConvention :: C => { }
431- DllCallingConvention :: Stdcall ( arg_list_size)
432- | DllCallingConvention :: Fastcall ( arg_list_size) => {
433- write ! ( & mut decorated_name, "@{arg_list_size}" ) . unwrap ( ) ;
434- }
435- DllCallingConvention :: Vectorcall ( arg_list_size) => {
436- write ! ( & mut decorated_name, "@@{arg_list_size}" ) . unwrap ( ) ;
437- }
438- }
439- }
440-
441- decorated_name
442- }
0 commit comments