@@ -7,8 +7,8 @@ use super::{
7
7
MethodRefIdx , NodeIdx , RootIdx , SigIdx , StaticFieldDesc , StaticFieldIdx , StringIdx , Type ,
8
8
TypeIdx ,
9
9
} ;
10
- use crate :: { asm:: Assembly as V1Asm , utilis:: encode, v2:: MethodImpl } ;
11
10
use crate :: { config, IString } ;
11
+ use crate :: { utilis:: encode, v2:: MethodImpl } ;
12
12
use fxhash:: { hash64, FxHashMap , FxHashSet } ;
13
13
14
14
use serde:: { Deserialize , Serialize } ;
@@ -33,6 +33,7 @@ pub struct Assembly {
33
33
fields : BiMap < FieldIdx , FieldDesc > ,
34
34
statics : BiMap < StaticFieldIdx , StaticFieldDesc > ,
35
35
method_defs : FxHashMap < MethodDefIdx , MethodDef > ,
36
+ sections : FxHashMap < String , Vec < u8 > > ,
36
37
// Cache containing information about the stack usage of a CIL node.
37
38
//#[serde(skip)]
38
39
//cache: CachedAssemblyInfo<NodeIdx, NonMaxU32, StackUsage>,
@@ -416,6 +417,7 @@ impl Assembly {
416
417
Access :: Public ,
417
418
None ,
418
419
None ,
420
+ true ,
419
421
) ;
420
422
let cref = class_def. ref_to ( ) ;
421
423
let cref = self . class_refs . alloc ( cref) ;
@@ -540,6 +542,7 @@ impl Assembly {
540
542
Access :: Public ,
541
543
None ,
542
544
None ,
545
+ true ,
543
546
) ;
544
547
545
548
let Some ( cref) = self . get_prealllocated_class_ref ( class_def. ref_to ( ) ) else {
@@ -685,7 +688,7 @@ impl Assembly {
685
688
}
686
689
/// Converts the old assembly repr to the new one.
687
690
#[ must_use]
688
- pub fn from_v1 ( v1 : & V1Asm ) -> Self {
691
+ pub fn from_v1 ( v1 : & Assembly ) -> Self {
689
692
let mut empty: Assembly = v1. clone ( ) ;
690
693
let rust_void = empty. alloc_string ( "RustVoid" ) ;
691
694
empty. class_def ( ClassDef :: new (
@@ -698,6 +701,7 @@ impl Assembly {
698
701
Access :: Public ,
699
702
None ,
700
703
None ,
704
+ true ,
701
705
) ) ;
702
706
703
707
#[ cfg( debug_assertions) ]
@@ -1023,10 +1027,11 @@ impl Assembly {
1023
1027
}
1024
1028
}
1025
1029
assert_eq ! ( self . alloc_string( MAIN_MODULE ) , original_str) ;
1030
+ self . sections . extend ( other. sections ) ;
1026
1031
self
1027
1032
}
1028
1033
1029
- pub ( crate ) fn method_defs ( & self ) -> & FxHashMap < MethodDefIdx , MethodDef > {
1034
+ pub fn method_defs ( & self ) -> & FxHashMap < MethodDefIdx , MethodDef > {
1030
1035
& self . method_defs
1031
1036
}
1032
1037
@@ -1172,26 +1177,29 @@ impl Assembly {
1172
1177
pub fn split_to_parts ( & self , parts : u32 ) -> impl Iterator < Item = Self > + use < ' _ > {
1173
1178
let lib_name = StringIdx :: from_index ( std:: num:: NonZeroU32 :: new ( 1 ) . unwrap ( ) ) ;
1174
1179
let div = ( self . method_refs . len ( ) . div_ceil ( parts as usize ) ) as u32 ;
1180
+ // Into 1st. Only split out the methods where it is known, for sure, that they don't access any statics.
1175
1181
( 0 ..parts) . map ( move |rem| {
1176
1182
let mut part = self . clone ( ) ;
1177
1183
part. method_defs . iter_mut ( ) . for_each ( |( idx, def) | {
1178
- if idx. as_bimap_index ( ) . get ( ) / div != rem {
1179
- /*if let MethodImpl::MethodBody {
1180
- blocks: _,
1181
- locals: _,
1182
- } = def.resolved_implementation(self).clone()
1183
- {
1184
+ if def. accesses_statics ( self ) {
1185
+ if 0 != rem {
1184
1186
* def. implementation_mut ( ) = MethodImpl :: Extern {
1185
1187
lib : lib_name,
1186
1188
preserve_errno : false ,
1187
1189
}
1188
- }*/
1190
+ }
1191
+ } else if idx. as_bimap_index ( ) . get ( ) / div != rem {
1189
1192
* def. implementation_mut ( ) = MethodImpl :: Extern {
1190
1193
lib : lib_name,
1191
1194
preserve_errno : false ,
1192
1195
}
1193
1196
}
1194
1197
} ) ;
1198
+ if 0 != rem {
1199
+ part. class_defs
1200
+ . iter_mut ( )
1201
+ . for_each ( |( _, def) | * def. static_fields_mut ( ) = vec ! [ ] ) ;
1202
+ }
1195
1203
part. eliminate_dead_types ( ) ;
1196
1204
//part.eliminate_dead_fns(true);
1197
1205
part = part. link_gc ( ) ;
@@ -1267,6 +1275,40 @@ impl Assembly {
1267
1275
clone = clone. link ( self ) ;
1268
1276
clone
1269
1277
}
1278
+ pub ( crate ) fn ptr_size ( & self ) -> u32 {
1279
+ 8
1280
+ }
1281
+ pub ( crate ) fn sizeof_type ( & self , field_tpe : Type ) -> u32 {
1282
+ match field_tpe {
1283
+ Type :: Ref ( _) | Type :: Ptr ( _) => self . ptr_size ( ) ,
1284
+ Type :: Int ( int) => int
1285
+ . size ( )
1286
+ . unwrap_or ( self . ptr_size ( ) . try_into ( ) . unwrap ( ) )
1287
+ . into ( ) ,
1288
+ Type :: ClassRef ( class_ref_idx) => self [ self . class_ref_to_def ( class_ref_idx) . unwrap ( ) ]
1289
+ . explict_size ( )
1290
+ . unwrap ( )
1291
+ . into ( ) ,
1292
+ Type :: Float ( float) => float. size ( ) . into ( ) ,
1293
+ Type :: PlatformString => self . ptr_size ( ) ,
1294
+ Type :: PlatformChar => 1 ,
1295
+ Type :: PlatformGeneric ( _, generic_kind) => todo ! ( ) ,
1296
+ Type :: PlatformObject => self . ptr_size ( ) ,
1297
+ Type :: Bool => 1 ,
1298
+ Type :: Void => 0 ,
1299
+ Type :: PlatformArray { elem, dims } => todo ! ( ) ,
1300
+ Type :: FnPtr ( sig_idx) => self . ptr_size ( ) ,
1301
+ Type :: SIMDVector ( simdvector) => ( simdvector. bits ( ) / 8 ) . into ( ) ,
1302
+ }
1303
+ }
1304
+
1305
+ pub fn add_section ( & mut self , arg : & str , packed_metadata : impl Into < Vec < u8 > > ) {
1306
+ self . sections . insert ( arg. into ( ) , packed_metadata. into ( ) ) ;
1307
+ }
1308
+
1309
+ pub ( crate ) fn get_section ( & self , arg : & str ) -> Option < & Vec < u8 > > {
1310
+ self . sections . get ( arg)
1311
+ }
1270
1312
}
1271
1313
/// An initializer, which runs before everything else. By convention, it is used to initialize static / const data. Should not execute any user code
1272
1314
pub const CCTOR : & str = ".cctor" ;
0 commit comments