Skip to content

Commit 841b820

Browse files
committed
Eliminate several uses of custom_width_int_type
1 parent c5c3f42 commit 841b820

File tree

2 files changed

+26
-52
lines changed

2 files changed

+26
-52
lines changed

src/emit/stylus/storage.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl StorageSlot for StylusTarget {
4242

4343
let slot_ptr = bin
4444
.builder
45-
.build_alloca(bin.context.custom_width_int_type(256), "slot_ptr")
45+
.build_alloca(bin.value_type(), "slot_ptr")
4646
.unwrap();
4747
if let Some(StorageType::Temporary(_)) = storage_type {
4848
call!("transient_load_bytes32", &[slot.into(), slot_ptr.into()]);
@@ -795,12 +795,15 @@ impl StorageSlot for StylusTarget {
795795
// load length
796796
bin.builder.build_store(slot_ptr, *slot).unwrap();
797797

798-
let slot_ty = bin.context.custom_width_int_type(256);
798+
let buf = bin.builder.build_alloca(bin.value_type(), "buf").unwrap();
799799

800-
let buf = bin.builder.build_alloca(slot_ty, "buf").unwrap();
801-
802-
let length =
803-
self.get_storage_type_int(bin, function, slot_ptr, slot_ty, &storage_type);
800+
let length = self.get_storage_type_int(
801+
bin,
802+
function,
803+
slot_ptr,
804+
bin.value_type(),
805+
&storage_type,
806+
);
804807

805808
// we need to hash the length slot in order to get the slot of the first
806809
// entry of the array

src/emit/stylus/target.rs

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,7 @@ impl<'a> TargetRuntime<'a> for StylusTarget {
160160

161161
let mut slot = next_slot(bin, slot, 32);
162162

163-
let slot_ptr = bin
164-
.builder
165-
.build_alloca(bin.context.custom_width_int_type(256), "slot")
166-
.unwrap();
163+
let slot_ptr = bin.builder.build_alloca(bin.value_type(), "slot").unwrap();
167164

168165
bin.emit_loop_cond_first_with_int(
169166
function,
@@ -173,11 +170,7 @@ impl<'a> TargetRuntime<'a> for StylusTarget {
173170
|i_chunk: IntValue<'a>, slot: &mut IntValue<'a>| {
174171
let i_chunk_as_u256 = bin
175172
.builder
176-
.build_int_z_extend(
177-
i_chunk,
178-
bin.context.custom_width_int_type(256),
179-
"i_chunk_as_u256",
180-
)
173+
.build_int_z_extend(i_chunk, bin.value_type(), "i_chunk_as_u256")
181174
.unwrap();
182175
let slot_plus_i_chunk = bin
183176
.builder
@@ -194,15 +187,15 @@ impl<'a> TargetRuntime<'a> for StylusTarget {
194187
let chunk = bin
195188
.builder
196189
.build_load(
197-
bin.context.custom_width_int_type(256),
190+
bin.value_type(),
198191
ptr_plus_offset(bin, data, offset),
199192
"chunk",
200193
)
201194
.unwrap();
202195

203196
let chunk_ptr = bin
204197
.builder
205-
.build_alloca(bin.context.custom_width_int_type(256), "chunk_ptr")
198+
.build_alloca(bin.value_type(), "chunk_ptr")
206199
.unwrap();
207200
bin.builder.build_store(chunk_ptr, chunk).unwrap();
208201
call!(
@@ -257,10 +250,7 @@ impl<'a> TargetRuntime<'a> for StylusTarget {
257250

258251
let mut slot = next_slot(bin, slot, 32);
259252

260-
let slot_ptr = bin
261-
.builder
262-
.build_alloca(bin.context.custom_width_int_type(256), "slot")
263-
.unwrap();
253+
let slot_ptr = bin.builder.build_alloca(bin.value_type(), "slot").unwrap();
264254

265255
bin.emit_loop_cond_first_with_int(
266256
function,
@@ -270,11 +260,7 @@ impl<'a> TargetRuntime<'a> for StylusTarget {
270260
|i_chunk: IntValue<'a>, slot: &mut IntValue<'a>| {
271261
let i_chunk_as_u256 = bin
272262
.builder
273-
.build_int_z_extend(
274-
i_chunk,
275-
bin.context.custom_width_int_type(256),
276-
"i_chunk_as_u256",
277-
)
263+
.build_int_z_extend(i_chunk, bin.value_type(), "i_chunk_as_u256")
278264
.unwrap();
279265
let slot_plus_i_chunk = bin
280266
.builder
@@ -286,12 +272,12 @@ impl<'a> TargetRuntime<'a> for StylusTarget {
286272

287273
let chunk_ptr = bin
288274
.builder
289-
.build_alloca(bin.context.custom_width_int_type(256), "chunk_ptr")
275+
.build_alloca(bin.value_type(), "chunk_ptr")
290276
.unwrap();
291277
call!("storage_load_bytes32", &[slot_ptr.into(), chunk_ptr.into()]);
292278
let chunk = bin
293279
.builder
294-
.build_load(bin.context.custom_width_int_type(256), chunk_ptr, "chunk")
280+
.build_load(bin.value_type(), chunk_ptr, "chunk")
295281
.unwrap();
296282

297283
let offset = bin
@@ -390,11 +376,7 @@ impl<'a> TargetRuntime<'a> for StylusTarget {
390376
.unwrap();
391377
let i_chunk_as_u256 = bin
392378
.builder
393-
.build_int_z_extend(
394-
i_chunk,
395-
bin.context.custom_width_int_type(256),
396-
"i_chunk_as_u256",
397-
)
379+
.build_int_z_extend(i_chunk, bin.value_type(), "i_chunk_as_u256")
398380
.unwrap();
399381
let slot_plus_i_chunk = bin
400382
.builder
@@ -405,7 +387,7 @@ impl<'a> TargetRuntime<'a> for StylusTarget {
405387
.unwrap();
406388
let chunk_ptr = bin
407389
.builder
408-
.build_alloca(bin.context.custom_width_int_type(256), "chunk_ptr")
390+
.build_alloca(bin.value_type(), "chunk_ptr")
409391
.unwrap();
410392
call!(
411393
"storage_load_bytes32",
@@ -527,7 +509,7 @@ impl<'a> TargetRuntime<'a> for StylusTarget {
527509
bin.builder.build_store(chunk_slot_ptr, chunk_slot).unwrap();
528510
let chunk_ptr = bin
529511
.builder
530-
.build_alloca(bin.context.custom_width_int_type(256), "chunk_ptr")
512+
.build_alloca(bin.value_type(), "chunk_ptr")
531513
.unwrap();
532514
call!(
533515
"storage_load_bytes32",
@@ -700,25 +682,17 @@ impl<'a> TargetRuntime<'a> for StylusTarget {
700682

701683
let code_len = bin.context.i32_type().const_int(code.len() as u64, false);
702684

703-
let value = bin
704-
.builder
705-
.build_alloca(bin.context.custom_width_int_type(256), "value") // TODO: maybe use bin.value_type() instead of custom width
706-
.unwrap();
685+
let value = bin.builder.build_alloca(bin.value_type(), "value").unwrap();
707686
bin.builder
708687
.build_store(
709688
value,
710-
contract_args
711-
.value
712-
.unwrap_or(bin.context.custom_width_int_type(256).const_zero()),
689+
contract_args.value.unwrap_or(bin.value_type().const_zero()),
713690
)
714691
.unwrap();
715692

716693
if let Some(salt) = contract_args.salt {
717694
// create2
718-
let salt_buf = bin
719-
.builder
720-
.build_alloca(bin.context.custom_width_int_type(256), "salt") // TODO: maybe use bin.value_type() instead of custom width
721-
.unwrap();
695+
let salt_buf = bin.builder.build_alloca(bin.value_type(), "salt").unwrap();
722696
bin.builder.build_store(salt_buf, salt).unwrap();
723697

724698
call!(
@@ -833,10 +807,7 @@ impl<'a> TargetRuntime<'a> for StylusTarget {
833807
vec![address.unwrap().into(), payload.into(), payload_len.into()];
834808

835809
if matches!(ty, CallTy::Regular) {
836-
let value = bin
837-
.builder
838-
.build_alloca(bin.context.custom_width_int_type(256), "value")
839-
.unwrap();
810+
let value = bin.builder.build_alloca(bin.value_type(), "value").unwrap();
840811
bin.builder
841812
.build_store(value, contract_args.value.unwrap())
842813
.unwrap();
@@ -958,7 +929,7 @@ impl<'a> TargetRuntime<'a> for StylusTarget {
958929
call!("block_basefee", &[basefee.into()], "block_basefee");
959930

960931
bin.builder
961-
.build_load(bin.context.custom_width_int_type(256), basefee, "basefee")
932+
.build_load(bin.value_type(), basefee, "basefee")
962933
.unwrap()
963934
}
964935
Expression::Builtin {
@@ -1498,7 +1469,7 @@ mod local {
14981469
) -> IntValue<'a> {
14991470
emit_context!(bin);
15001471

1501-
let ty = bin.context.custom_width_int_type(256);
1472+
let ty = bin.value_type();
15021473

15031474
let digest_ptr = bin.builder.build_alloca(ty, "digest").unwrap();
15041475

0 commit comments

Comments
 (0)