@@ -13,24 +13,16 @@ namespace Xamarin.Android.Tasks
13
13
partial class CompressedAssembliesNativeAssemblyGenerator : LlvmIrComposer
14
14
{
15
15
const string DescriptorsArraySymbolName = "compressed_assembly_descriptors" ;
16
- const string CompressedAssembliesSymbolName = "compressed_assemblies" ;
17
-
18
- sealed class CompressedAssemblyDescriptorContextDataProvider : NativeAssemblerStructContextDataProvider
19
- {
20
- public override string ? GetPointedToSymbolName ( object data , string fieldName )
21
- {
22
- if ( String . Compare ( "data" , fieldName , StringComparison . Ordinal ) != 0 ) {
23
- return null ;
24
- }
25
-
26
- var descriptor = EnsureType < CompressedAssemblyDescriptor > ( data ) ;
27
- return descriptor . BufferSymbolName ;
28
- }
29
- }
30
-
31
- // Order of fields and their type must correspond *exactly* to that in
32
- // src/monodroid/jni/xamarin-app.hh CompressedAssemblyDescriptor structure
33
- [ NativeAssemblerStructContextDataProvider ( typeof ( CompressedAssemblyDescriptorContextDataProvider ) ) ]
16
+ const string CompressedAssemblyCountSymbolName = "compressed_assembly_count" ;
17
+ const string UncompressedAssembliesBufferSymbolName = "uncompressed_assemblies_data_buffer" ;
18
+ const string UncompressedAssembliesBufferSizeSymbolName = "uncompressed_assemblies_data_size" ;
19
+
20
+ // Order of fields and their type must correspond *exactly* to that in:
21
+ //
22
+ // src/native/mono/xamarin-app-stub/xamarin-app.hh CompressedAssemblyDescriptor structure
23
+ // src/native/clr/include/xamarin-app.hh CompressedAssemblyDescriptor structure
24
+ //
25
+ //[NativeAssemblerStructContextDataProvider (typeof (CompressedAssemblyDescriptorContextDataProvider))]
34
26
sealed class CompressedAssemblyDescriptor
35
27
{
36
28
[ NativeAssembler ( Ignore = true ) ]
@@ -44,38 +36,11 @@ sealed class CompressedAssemblyDescriptor
44
36
45
37
public uint uncompressed_file_size ;
46
38
public bool loaded ;
47
-
48
- [ NativeAssembler ( UsesDataProvider = true ) , NativePointer ( PointsToSymbol = "" ) ]
49
- public byte data ;
50
- } ;
51
-
52
- sealed class CompressedAssembliesContextDataProvider : NativeAssemblerStructContextDataProvider
53
- {
54
- public override ulong GetBufferSize ( object data , string fieldName )
55
- {
56
- if ( String . Compare ( "descriptors" , fieldName , StringComparison . Ordinal ) != 0 ) {
57
- return 0 ;
58
- }
59
-
60
- var cas = EnsureType < CompressedAssemblies > ( data ) ;
61
- return cas . count ;
62
- }
63
- }
64
-
65
- // Order of fields and their type must correspond *exactly* to that in
66
- // src/monodroid/jni/xamarin-app.hh CompressedAssemblies structure
67
- [ NativeAssemblerStructContextDataProvider ( typeof ( CompressedAssembliesContextDataProvider ) ) ]
68
- sealed class CompressedAssemblies
69
- {
70
- public uint count ;
71
-
72
- [ NativeAssembler ( UsesDataProvider = true ) , NativePointer ( PointsToSymbol = DescriptorsArraySymbolName ) ]
73
- public CompressedAssemblyDescriptor descriptors ;
39
+ public uint buffer_offset ;
74
40
} ;
75
41
76
42
IDictionary < AndroidTargetArch , Dictionary < string , CompressedAssemblyInfo > > ? archAssemblies ;
77
43
StructureInfo compressedAssemblyDescriptorStructureInfo ;
78
- StructureInfo compressedAssembliesStructureInfo ;
79
44
Dictionary < AndroidTargetArch , List < StructureInstance < CompressedAssemblyDescriptor > > > archData = new Dictionary < AndroidTargetArch , List < StructureInstance < CompressedAssemblyDescriptor > > > ( ) ;
80
45
81
46
public CompressedAssembliesNativeAssemblyGenerator ( TaskLoggingHelper log , IDictionary < AndroidTargetArch , Dictionary < string , CompressedAssemblyInfo > > ? archAssemblies )
@@ -95,8 +60,10 @@ void InitCompressedAssemblies (out List<LlvmIrGlobalVariable>? compressedAssembl
95
60
return ;
96
61
}
97
62
98
- buffers = new List < LlvmIrGlobalVariable > ( ) ;
63
+ buffers = new ( ) ;
99
64
foreach ( var kvpArch in archAssemblies ) {
65
+ uint bufferSize = 0 ;
66
+
100
67
foreach ( var kvp in kvpArch . Value ) {
101
68
CompressedAssemblyInfo info = kvp . Value ;
102
69
@@ -105,25 +72,30 @@ void InitCompressedAssemblies (out List<LlvmIrGlobalVariable>? compressedAssembl
105
72
archData . Add ( info . TargetArch , descriptors ) ;
106
73
}
107
74
108
- string bufferName = $ "__compressedAssemblyData_{ info . DescriptorIndex } ";
109
75
var descriptor = new CompressedAssemblyDescriptor {
110
76
Index = info . DescriptorIndex ,
111
- BufferSymbolName = bufferName ,
112
77
AssemblyName = info . AssemblyName ,
113
78
uncompressed_file_size = info . FileSize ,
114
79
loaded = false ,
115
- data = 0
80
+ buffer_offset = bufferSize ,
116
81
} ;
117
-
82
+ bufferSize += info . FileSize ;
118
83
descriptors . Add ( new StructureInstance < CompressedAssemblyDescriptor > ( compressedAssemblyDescriptorStructureInfo , descriptor ) ) ;
119
-
120
- var buffer = new LlvmIrGlobalVariable ( typeof ( List < byte > ) , descriptor . BufferSymbolName , LlvmIrVariableOptions . LocalWritable ) {
121
- ArrayItemCount = descriptor . uncompressed_file_size ,
122
- TargetArch = info . TargetArch ,
123
- ZeroInitializeArray = true ,
124
- } ;
125
- buffers . Add ( buffer ) ;
126
84
}
85
+
86
+ var variable = new LlvmIrGlobalVariable ( typeof ( uint ) , UncompressedAssembliesBufferSizeSymbolName ) {
87
+ Options = LlvmIrVariableOptions . GlobalConstant ,
88
+ TargetArch = kvpArch . Key ,
89
+ Value = bufferSize ,
90
+ } ;
91
+ buffers . Add ( variable ) ;
92
+
93
+ variable = new LlvmIrGlobalVariable ( typeof ( List < byte > ) , UncompressedAssembliesBufferSymbolName , LlvmIrVariableOptions . GlobalWritable ) {
94
+ ArrayItemCount = bufferSize ,
95
+ TargetArch = kvpArch . Key ,
96
+ ZeroInitializeArray = true ,
97
+ } ;
98
+ buffers . Add ( variable ) ;
127
99
}
128
100
129
101
compressedAssemblies = new List < LlvmIrGlobalVariable > ( ) ;
@@ -132,16 +104,16 @@ void InitCompressedAssemblies (out List<LlvmIrGlobalVariable>? compressedAssembl
132
104
List < StructureInstance < CompressedAssemblyDescriptor > > descriptors = kvp . Value ;
133
105
descriptors . Sort ( ( StructureInstance < CompressedAssemblyDescriptor > a , StructureInstance < CompressedAssemblyDescriptor > b ) => a . Instance . Index . CompareTo ( b . Instance . Index ) ) ;
134
106
135
- var variable = new LlvmIrGlobalVariable ( typeof ( StructureInstance < CompressedAssemblies > ) , CompressedAssembliesSymbolName ) {
136
- Options = LlvmIrVariableOptions . GlobalWritable ,
107
+ var variable = new LlvmIrGlobalVariable ( typeof ( uint ) , CompressedAssemblyCountSymbolName ) {
108
+ Options = LlvmIrVariableOptions . GlobalConstant ,
137
109
TargetArch = kvp . Key ,
138
- Value = new StructureInstance < CompressedAssemblies > ( compressedAssembliesStructureInfo , new CompressedAssemblies { count = ( uint ) descriptors . Count , } ) ,
110
+ Value = ( uint ) descriptors . Count ,
139
111
} ;
140
112
compressedAssemblies . Add ( variable ) ;
141
113
142
114
variable = new LlvmIrGlobalVariable ( typeof ( List < StructureInstance < CompressedAssemblyDescriptor > > ) , DescriptorsArraySymbolName ) {
143
115
GetArrayItemCommentCallback = GetCompressedAssemblyDescriptorsItemComment ,
144
- Options = LlvmIrVariableOptions . LocalWritable ,
116
+ Options = LlvmIrVariableOptions . GlobalWritable ,
145
117
TargetArch = kvp . Key ,
146
118
Value = descriptors ,
147
119
} ;
@@ -162,21 +134,17 @@ out List<LlvmIrGlobalVariable>? buffers
162
134
) ;
163
135
164
136
if ( archData . Count == 0 ) {
165
- module . AddGlobalVariable (
166
- typeof ( StructureInstance < CompressedAssemblies > ) ,
167
- CompressedAssembliesSymbolName ,
168
- new StructureInstance < CompressedAssemblies > ( compressedAssembliesStructureInfo , new CompressedAssemblies ( ) ) { IsZeroInitialized = true } ,
169
- LlvmIrVariableOptions . GlobalWritable
170
- ) ;
137
+ var emptyBufferVar = new LlvmIrGlobalVariable ( typeof ( List < byte > ) , UncompressedAssembliesBufferSymbolName , LlvmIrVariableOptions . GlobalWritable ) {
138
+ ArrayItemCount = 0 ,
139
+ ZeroInitializeArray = true ,
140
+ } ;
141
+ module . Add ( emptyBufferVar ) ;
171
142
return ;
172
143
}
173
144
174
145
module . Add ( compressedAssemblies ) ;
175
146
module . Add ( compressedAssemblyDescriptors ) ;
176
-
177
- module . Add ( new LlvmIrGroupDelimiterVariable ( ) ) ;
178
147
module . Add ( buffers ) ;
179
- module . Add ( new LlvmIrGroupDelimiterVariable ( ) ) ;
180
148
}
181
149
182
150
string ? GetCompressedAssemblyDescriptorsItemComment ( LlvmIrVariable v , LlvmIrModuleTarget target , ulong index , object ? value , object ? callerState )
@@ -202,7 +170,6 @@ List<StructureInstance<CompressedAssemblyDescriptor>> GetArchDescriptors (LlvmIr
202
170
void MapStructures ( LlvmIrModule module )
203
171
{
204
172
compressedAssemblyDescriptorStructureInfo = module . MapStructure < CompressedAssemblyDescriptor > ( ) ;
205
- compressedAssembliesStructureInfo = module . MapStructure < CompressedAssemblies > ( ) ;
206
173
}
207
174
}
208
175
}
0 commit comments