@@ -3,8 +3,8 @@ use super::{
3
3
fuel:: { checks, data_section:: DataSection } ,
4
4
ProgramABI , ProgramKind ,
5
5
} ;
6
- use crate :: asm_generation:: fuel:: data_section:: { Datum , Entry , EntryName } ;
7
- use crate :: asm_lang:: allocated_ops:: { AllocatedOp , AllocatedOpcode , FuelAsmData } ;
6
+ use crate :: asm_generation:: fuel:: data_section:: { DataId , Datum , Entry } ;
7
+ use crate :: asm_lang:: allocated_ops:: { AllocatedOp , AllocatedOpcode } ;
8
8
use crate :: decl_engine:: DeclRefFunction ;
9
9
use crate :: source_map:: SourceMap ;
10
10
use crate :: BuildConfig ;
@@ -16,6 +16,7 @@ use sway_error::handler::{ErrorEmitted, Handler};
16
16
use sway_types:: span:: Span ;
17
17
use sway_types:: SourceEngine ;
18
18
19
+ use either:: Either ;
19
20
use std:: { collections:: BTreeMap , fmt} ;
20
21
21
22
/// Represents an ASM set which has had register allocation, jump elimination, and optimization
@@ -111,7 +112,6 @@ fn to_bytecode_mut(
111
112
{
112
113
8
113
114
}
114
- AllocatedOpcode :: ConfigurablesOffsetPlaceholder => 8 ,
115
115
AllocatedOpcode :: DataSectionOffsetPlaceholder => 8 ,
116
116
AllocatedOpcode :: BLOB ( count) => count. value as u64 * 4 ,
117
117
AllocatedOpcode :: CFEI ( i) | AllocatedOpcode :: CFSI ( i) if i. value == 0 => 0 ,
@@ -141,29 +141,6 @@ fn to_bytecode_mut(
141
141
& ops_padded
142
142
} ;
143
143
144
- let mut offset_from_instr_start = 0 ;
145
- for op in ops. iter ( ) {
146
- match & op. opcode {
147
- AllocatedOpcode :: LoadDataId ( _reg, data_label)
148
- if !data_section
149
- . has_copy_type ( data_label)
150
- . expect ( "data label references non existent data -- internal error" ) =>
151
- {
152
- // For non-copy type loads, pre-insert pointers into the data_section so that
153
- // from this point on, the data_section remains immutable. This is necessary
154
- // so that when we take addresses of configurables, that address doesn't change
155
- // later on if a non-configurable is added to the data-section.
156
- let offset_bytes = data_section. data_id_to_offset ( data_label) as u64 ;
157
- // The -4 is because $pc is added in the *next* instruction.
158
- let pointer_offset_from_current_instr =
159
- offset_to_data_section_in_bytes - offset_from_instr_start + offset_bytes - 4 ;
160
- data_section. append_pointer ( pointer_offset_from_current_instr) ;
161
- }
162
- _ => ( ) ,
163
- }
164
- offset_from_instr_start += op_size_in_bytes ( data_section, op) ;
165
- }
166
-
167
144
let mut bytecode = Vec :: with_capacity ( offset_to_data_section_in_bytes as usize ) ;
168
145
169
146
if build_config. print_bytecode {
@@ -189,7 +166,7 @@ fn to_bytecode_mut(
189
166
offset_from_instr_start += op_size_in_bytes ( data_section, op) ;
190
167
191
168
match fuel_op {
192
- FuelAsmData :: DatasectionOffset ( data) => {
169
+ Either :: Right ( data) => {
193
170
if build_config. print_bytecode {
194
171
print ! ( "{}{:#010x} " , " " . repeat( indentation) , bytecode. len( ) ) ;
195
172
println ! (
@@ -205,23 +182,7 @@ fn to_bytecode_mut(
205
182
bytecode. extend ( data. iter ( ) . cloned ( ) ) ;
206
183
half_word_ix += 2 ;
207
184
}
208
- FuelAsmData :: ConfigurablesOffset ( data) => {
209
- if build_config. print_bytecode {
210
- print ! ( "{}{:#010x} " , " " . repeat( indentation) , bytecode. len( ) ) ;
211
- println ! (
212
- " ;; {:?}" ,
213
- data
214
- ) ;
215
- }
216
-
217
- // Static assert to ensure that we're only dealing with ConfigurablesOffsetPlaceholder,
218
- // a 1-word (8 bytes) data within the code. No other uses are known.
219
- let _: [ u8 ; 8 ] = data;
220
-
221
- bytecode. extend ( data. iter ( ) . cloned ( ) ) ;
222
- half_word_ix += 2 ;
223
- }
224
- FuelAsmData :: Instructions ( instructions) => {
185
+ Either :: Left ( instructions) => {
225
186
for instruction in instructions {
226
187
// Print original source span only once
227
188
if build_config. print_bytecode_spans {
@@ -334,9 +295,9 @@ fn to_bytecode_mut(
334
295
} ;
335
296
}
336
297
337
- for ( i, entry) in data_section. iter_all_entries ( ) . enumerate ( ) {
338
- let entry_offset = data_section. absolute_idx_to_offset ( i ) ;
339
- print_entry ( indentation, offset + entry_offset, & entry) ;
298
+ for ( i, entry) in data_section. value_pairs . iter ( ) . enumerate ( ) {
299
+ let entry_offset = data_section. data_id_to_offset ( & DataId ( i as u32 ) ) ;
300
+ print_entry ( indentation, offset + entry_offset, entry) ;
340
301
}
341
302
342
303
println ! ( ";; --- END OF TARGET BYTECODE ---\n " ) ;
@@ -345,19 +306,16 @@ fn to_bytecode_mut(
345
306
assert_eq ! ( half_word_ix * 4 , offset_to_data_section_in_bytes as usize ) ;
346
307
assert_eq ! ( bytecode. len( ) , offset_to_data_section_in_bytes as usize ) ;
347
308
348
- let num_nonconfigurables = data_section. non_configurables . len ( ) ;
349
309
let named_data_section_entries_offsets = data_section
350
- . configurables
310
+ . value_pairs
351
311
. iter ( )
352
312
. enumerate ( )
313
+ . filter ( |entry| entry. 1 . name . is_some ( ) )
353
314
. map ( |( id, entry) | {
354
- let EntryName :: Configurable ( name) = & entry. name else {
355
- panic ! ( "Non-configurable in configurables part of datasection" ) ;
356
- } ;
357
315
(
358
- name. clone ( ) ,
316
+ entry . name . as_ref ( ) . unwrap ( ) . clone ( ) ,
359
317
offset_to_data_section_in_bytes
360
- + data_section. absolute_idx_to_offset ( id + num_nonconfigurables ) as u64 ,
318
+ + data_section. raw_data_id_to_offset ( id as u32 ) as u64 ,
361
319
)
362
320
} )
363
321
. collect :: < BTreeMap < String , u64 > > ( ) ;
0 commit comments