|
|
@@ -10,13 +10,12 @@ use crate::emit::{ContractArgs, TargetRuntime, Variable};
|
|
|
use crate::sema::ast;
|
|
|
use crate::sema::ast::{Function, Namespace, Type};
|
|
|
use crate::{codegen, emit_context};
|
|
|
-use inkwell::types::{BasicType, IntType};
|
|
|
+use inkwell::types::{BasicType, BasicTypeEnum, IntType};
|
|
|
use inkwell::values::{
|
|
|
- ArrayValue, BasicMetadataValueEnum, BasicValueEnum, CallableValue, FunctionValue, IntValue,
|
|
|
- PointerValue,
|
|
|
+ ArrayValue, BasicMetadataValueEnum, BasicValueEnum, FunctionValue, IntValue, PointerValue,
|
|
|
};
|
|
|
use inkwell::{AddressSpace, IntPredicate};
|
|
|
-use solang_parser::pt::{self, Loc};
|
|
|
+use solang_parser::pt::Loc;
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
@@ -26,15 +25,15 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
_function: FunctionValue,
|
|
|
slot: PointerValue,
|
|
|
dest: PointerValue,
|
|
|
+ dest_ty: BasicTypeEnum,
|
|
|
) {
|
|
|
emit_context!(binary);
|
|
|
|
|
|
let ret = seal_set_storage!(
|
|
|
- cast_byte_ptr!(slot).into(),
|
|
|
+ slot.into(),
|
|
|
i32_const!(32).into(),
|
|
|
- cast_byte_ptr!(dest).into(),
|
|
|
- dest.get_type()
|
|
|
- .get_element_type()
|
|
|
+ dest.into(),
|
|
|
+ dest_ty
|
|
|
.size_of()
|
|
|
.unwrap()
|
|
|
.const_cast(binary.context.i32_type(), false)
|
|
|
@@ -53,33 +52,32 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
) -> PointerValue<'a> {
|
|
|
emit_context!(binary);
|
|
|
|
|
|
- let ty = binary.llvm_type(
|
|
|
- &ast::Type::ExternalFunction {
|
|
|
- params: Vec::new(),
|
|
|
- mutability: ast::Mutability::Nonpayable(pt::Loc::Codegen),
|
|
|
- returns: Vec::new(),
|
|
|
- },
|
|
|
- ns,
|
|
|
- );
|
|
|
+ // This is the size of the external function struct
|
|
|
+ let len = ns.address_length + 4;
|
|
|
|
|
|
- let len = ty
|
|
|
- .size_of()
|
|
|
- .unwrap()
|
|
|
- .const_cast(binary.context.i32_type(), false);
|
|
|
-
|
|
|
- let ef = call!("__malloc", &[len.into()])
|
|
|
- .try_as_basic_value()
|
|
|
- .left()
|
|
|
- .unwrap()
|
|
|
- .into_pointer_value();
|
|
|
+ let ef = call!(
|
|
|
+ "__malloc",
|
|
|
+ &[binary
|
|
|
+ .context
|
|
|
+ .i32_type()
|
|
|
+ .const_int(len as u64, false)
|
|
|
+ .into()]
|
|
|
+ )
|
|
|
+ .try_as_basic_value()
|
|
|
+ .left()
|
|
|
+ .unwrap()
|
|
|
+ .into_pointer_value();
|
|
|
|
|
|
let scratch_len = binary.scratch_len.unwrap().as_pointer_value();
|
|
|
- binary.builder.build_store(scratch_len, len);
|
|
|
+ binary.builder.build_store(
|
|
|
+ scratch_len,
|
|
|
+ binary.context.i64_type().const_int(len as u64, false),
|
|
|
+ );
|
|
|
|
|
|
let ret = call!(
|
|
|
"seal_get_storage",
|
|
|
&[
|
|
|
- cast_byte_ptr!(slot).into(),
|
|
|
+ slot.into(),
|
|
|
i32_const!(32).into(),
|
|
|
ef.into(),
|
|
|
scratch_len.into()
|
|
|
@@ -94,9 +92,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
|
|
|
// TODO: decide behaviour if not exist
|
|
|
|
|
|
- binary
|
|
|
- .builder
|
|
|
- .build_pointer_cast(ef, ty.ptr_type(AddressSpace::default()), "function_type")
|
|
|
+ ef
|
|
|
}
|
|
|
|
|
|
fn set_storage_string(
|
|
|
@@ -127,12 +123,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
|
|
|
binary.builder.position_at_end(set_block);
|
|
|
|
|
|
- let ret = seal_set_storage!(
|
|
|
- cast_byte_ptr!(slot).into(),
|
|
|
- i32_const!(32).into(),
|
|
|
- cast_byte_ptr!(data).into(),
|
|
|
- len.into()
|
|
|
- );
|
|
|
+ let ret = seal_set_storage!(slot.into(), i32_const!(32).into(), data.into(), len.into());
|
|
|
|
|
|
log_return_code(binary, "seal_set_storage", ret);
|
|
|
|
|
|
@@ -140,14 +131,11 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
|
|
|
binary.builder.position_at_end(delete_block);
|
|
|
|
|
|
- let ret = call!(
|
|
|
- "seal_clear_storage",
|
|
|
- &[cast_byte_ptr!(slot).into(), i32_const!(32).into()]
|
|
|
- )
|
|
|
- .try_as_basic_value()
|
|
|
- .left()
|
|
|
- .unwrap()
|
|
|
- .into_int_value();
|
|
|
+ let ret = call!("seal_clear_storage", &[slot.into(), i32_const!(32).into()])
|
|
|
+ .try_as_basic_value()
|
|
|
+ .left()
|
|
|
+ .unwrap()
|
|
|
+ .into_int_value();
|
|
|
|
|
|
log_return_code(binary, "seal_clear_storage", ret);
|
|
|
|
|
|
@@ -171,7 +159,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
binary.builder.build_store(scratch_len, ty_len);
|
|
|
|
|
|
let exists = seal_get_storage!(
|
|
|
- cast_byte_ptr!(slot).into(),
|
|
|
+ slot.into(),
|
|
|
i32_const!(32).into(),
|
|
|
scratch_buf.into(),
|
|
|
scratch_len.into()
|
|
|
@@ -196,13 +184,10 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
|
|
|
binary.builder.position_at_end(retrieve_block);
|
|
|
|
|
|
- let dest = binary.builder.build_pointer_cast(
|
|
|
- binary.scratch.unwrap().as_pointer_value(),
|
|
|
- ty.ptr_type(AddressSpace::default()),
|
|
|
- "scratch_ty_buf",
|
|
|
- );
|
|
|
-
|
|
|
- let loaded_int = binary.builder.build_load(dest, "int");
|
|
|
+ let loaded_int =
|
|
|
+ binary
|
|
|
+ .builder
|
|
|
+ .build_load(ty, binary.scratch.unwrap().as_pointer_value(), "int");
|
|
|
|
|
|
binary.builder.build_unconditional_branch(done_storage);
|
|
|
|
|
|
@@ -231,7 +216,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
.build_store(scratch_len, i32_const!(SCRATCH_SIZE as u64));
|
|
|
|
|
|
let exists = seal_get_storage!(
|
|
|
- cast_byte_ptr!(slot).into(),
|
|
|
+ slot.into(),
|
|
|
i32_const!(32).into(),
|
|
|
scratch_buf.into(),
|
|
|
scratch_len.into()
|
|
|
@@ -266,7 +251,10 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
|
|
|
binary.builder.position_at_end(retrieve_block);
|
|
|
|
|
|
- let length = binary.builder.build_load(scratch_len, "string_len");
|
|
|
+ let length =
|
|
|
+ binary
|
|
|
+ .builder
|
|
|
+ .build_load(binary.context.i32_type(), scratch_len, "string_len");
|
|
|
|
|
|
let loaded_string = call!(
|
|
|
"vector_new",
|
|
|
@@ -321,7 +309,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
.build_store(scratch_len, i32_const!(SCRATCH_SIZE as u64));
|
|
|
|
|
|
let exists = seal_get_storage!(
|
|
|
- cast_byte_ptr!(slot_ptr).into(),
|
|
|
+ slot_ptr.into(),
|
|
|
i32_const!(32).into(),
|
|
|
scratch_buf.into(),
|
|
|
scratch_len.into()
|
|
|
@@ -340,7 +328,9 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
.builder
|
|
|
.build_select(
|
|
|
exists,
|
|
|
- binary.builder.build_load(scratch_len, "string_len"),
|
|
|
+ binary
|
|
|
+ .builder
|
|
|
+ .build_load(binary.context.i32_type(), scratch_len, "string_len"),
|
|
|
i32_zero!().into(),
|
|
|
"string_length",
|
|
|
)
|
|
|
@@ -373,13 +363,17 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
|
|
|
let offset = unsafe {
|
|
|
binary.builder.build_gep(
|
|
|
+ binary.context.i8_type().array_type(SCRATCH_SIZE),
|
|
|
binary.scratch.unwrap().as_pointer_value(),
|
|
|
&[i32_zero!(), index],
|
|
|
"data_offset",
|
|
|
)
|
|
|
};
|
|
|
|
|
|
- binary.builder.build_load(offset, "value").into_int_value()
|
|
|
+ binary
|
|
|
+ .builder
|
|
|
+ .build_load(binary.context.i8_type(), offset, "value")
|
|
|
+ .into_int_value()
|
|
|
}
|
|
|
|
|
|
fn set_storage_bytes_subscript(
|
|
|
@@ -404,7 +398,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
.build_store(scratch_len, i32_const!(SCRATCH_SIZE as u64));
|
|
|
|
|
|
let exists = seal_get_storage!(
|
|
|
- cast_byte_ptr!(slot_ptr).into(),
|
|
|
+ slot_ptr.into(),
|
|
|
i32_const!(32).into(),
|
|
|
scratch_buf.into(),
|
|
|
scratch_len.into()
|
|
|
@@ -423,7 +417,9 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
.builder
|
|
|
.build_select(
|
|
|
exists,
|
|
|
- binary.builder.build_load(scratch_len, "string_len"),
|
|
|
+ binary
|
|
|
+ .builder
|
|
|
+ .build_load(binary.context.i32_type(), scratch_len, "string_len"),
|
|
|
i32_zero!().into(),
|
|
|
"string_length",
|
|
|
)
|
|
|
@@ -455,6 +451,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
|
|
|
let offset = unsafe {
|
|
|
binary.builder.build_gep(
|
|
|
+ binary.context.i8_type().array_type(SCRATCH_SIZE),
|
|
|
binary.scratch.unwrap().as_pointer_value(),
|
|
|
&[i32_zero!(), index],
|
|
|
"data_offset",
|
|
|
@@ -465,7 +462,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
binary.builder.build_store(offset, val);
|
|
|
|
|
|
let ret = seal_set_storage!(
|
|
|
- cast_byte_ptr!(slot_ptr).into(),
|
|
|
+ slot_ptr.into(),
|
|
|
i32_const!(32).into(),
|
|
|
scratch_buf.into(),
|
|
|
length.into()
|
|
|
@@ -500,7 +497,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
.build_store(scratch_len, i32_const!(SCRATCH_SIZE as u64 - 1));
|
|
|
|
|
|
let exists = seal_get_storage!(
|
|
|
- cast_byte_ptr!(slot_ptr).into(),
|
|
|
+ slot_ptr.into(),
|
|
|
i32_const!(32).into(),
|
|
|
scratch_buf.into(),
|
|
|
scratch_len.into()
|
|
|
@@ -519,7 +516,9 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
.builder
|
|
|
.build_select(
|
|
|
exists,
|
|
|
- binary.builder.build_load(scratch_len, "string_len"),
|
|
|
+ binary
|
|
|
+ .builder
|
|
|
+ .build_load(binary.context.i32_type(), scratch_len, "string_len"),
|
|
|
i32_zero!().into(),
|
|
|
"string_length",
|
|
|
)
|
|
|
@@ -528,6 +527,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
// set the result
|
|
|
let offset = unsafe {
|
|
|
binary.builder.build_gep(
|
|
|
+ binary.context.i8_type().array_type(SCRATCH_SIZE),
|
|
|
binary.scratch.unwrap().as_pointer_value(),
|
|
|
&[i32_zero!(), length],
|
|
|
"data_offset",
|
|
|
@@ -542,7 +542,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
.build_int_add(length, i32_const!(1), "new_length");
|
|
|
|
|
|
let ret = seal_set_storage!(
|
|
|
- cast_byte_ptr!(slot_ptr).into(),
|
|
|
+ slot_ptr.into(),
|
|
|
i32_const!(32).into(),
|
|
|
scratch_buf.into(),
|
|
|
length.into()
|
|
|
@@ -558,7 +558,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
&self,
|
|
|
binary: &Binary<'a>,
|
|
|
function: FunctionValue<'a>,
|
|
|
- _ty: &ast::Type,
|
|
|
+ ty: &ast::Type,
|
|
|
slot: IntValue<'a>,
|
|
|
load: bool,
|
|
|
ns: &ast::Namespace,
|
|
|
@@ -576,7 +576,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
.build_store(scratch_len, i32_const!(SCRATCH_SIZE as u64));
|
|
|
|
|
|
let exists = seal_get_storage!(
|
|
|
- cast_byte_ptr!(slot_ptr).into(),
|
|
|
+ slot_ptr.into(),
|
|
|
i32_const!(32).into(),
|
|
|
scratch_buf.into(),
|
|
|
scratch_len.into()
|
|
|
@@ -595,7 +595,9 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
.builder
|
|
|
.build_select(
|
|
|
exists,
|
|
|
- binary.builder.build_load(scratch_len, "string_len"),
|
|
|
+ binary
|
|
|
+ .builder
|
|
|
+ .build_load(binary.context.i32_type(), scratch_len, "string_len"),
|
|
|
i32_zero!().into(),
|
|
|
"string_length",
|
|
|
)
|
|
|
@@ -635,19 +637,24 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
let val = if load {
|
|
|
let offset = unsafe {
|
|
|
binary.builder.build_gep(
|
|
|
+ binary.context.i8_type().array_type(SCRATCH_SIZE),
|
|
|
binary.scratch.unwrap().as_pointer_value(),
|
|
|
&[i32_zero!(), new_length],
|
|
|
"data_offset",
|
|
|
)
|
|
|
};
|
|
|
|
|
|
- Some(binary.builder.build_load(offset, "popped_value"))
|
|
|
+ Some(
|
|
|
+ binary
|
|
|
+ .builder
|
|
|
+ .build_load(binary.llvm_type(ty, ns), offset, "popped_value"),
|
|
|
+ )
|
|
|
} else {
|
|
|
None
|
|
|
};
|
|
|
|
|
|
let ret = seal_set_storage!(
|
|
|
- cast_byte_ptr!(slot_ptr).into(),
|
|
|
+ slot_ptr.into(),
|
|
|
i32_const!(32).into(),
|
|
|
scratch_buf.into(),
|
|
|
new_length.into()
|
|
|
@@ -679,7 +686,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
.build_store(scratch_len, i32_const!(SCRATCH_SIZE as u64));
|
|
|
|
|
|
let exists = seal_get_storage!(
|
|
|
- cast_byte_ptr!(slot_ptr).into(),
|
|
|
+ slot_ptr.into(),
|
|
|
i32_const!(32).into(),
|
|
|
scratch_buf.into(),
|
|
|
scratch_len.into()
|
|
|
@@ -698,7 +705,9 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
.builder
|
|
|
.build_select(
|
|
|
exists,
|
|
|
- binary.builder.build_load(scratch_len, "string_len"),
|
|
|
+ binary
|
|
|
+ .builder
|
|
|
+ .build_load(binary.context.i32_type(), scratch_len, "string_len"),
|
|
|
i32_zero!().into(),
|
|
|
"string_length",
|
|
|
)
|
|
|
@@ -740,11 +749,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
|
|
|
call!(
|
|
|
"seal_hash_keccak_256",
|
|
|
- &[
|
|
|
- cast_byte_ptr!(src).into(),
|
|
|
- length.into(),
|
|
|
- cast_byte_ptr!(dest).into()
|
|
|
- ]
|
|
|
+ &[src.into(), length.into(), dest.into()]
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -792,9 +797,9 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
false,
|
|
|
);
|
|
|
|
|
|
- let callable = CallableValue::try_from(asm).unwrap();
|
|
|
-
|
|
|
- binary.builder.build_call(callable, &[], "unreachable");
|
|
|
+ binary
|
|
|
+ .builder
|
|
|
+ .build_indirect_call(asm_fn, asm, &[], "unreachable");
|
|
|
|
|
|
binary.builder.build_unreachable();
|
|
|
}
|
|
|
@@ -804,24 +809,22 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
binary: &Binary<'b>,
|
|
|
function: FunctionValue,
|
|
|
args: &mut Vec<BasicValueEnum<'b>>,
|
|
|
- data: PointerValue<'b>,
|
|
|
+ mut data: PointerValue<'b>,
|
|
|
datalength: IntValue<'b>,
|
|
|
spec: &[ast::Parameter],
|
|
|
ns: &ast::Namespace,
|
|
|
) {
|
|
|
- let mut argsdata = binary.builder.build_pointer_cast(
|
|
|
- data,
|
|
|
- binary.context.i8_type().ptr_type(AddressSpace::default()),
|
|
|
- "",
|
|
|
- );
|
|
|
-
|
|
|
- let argsend = unsafe { binary.builder.build_gep(argsdata, &[datalength], "argsend") };
|
|
|
+ let argsend = unsafe {
|
|
|
+ binary
|
|
|
+ .builder
|
|
|
+ .build_gep(binary.context.i8_type(), data, &[datalength], "argsend")
|
|
|
+ };
|
|
|
|
|
|
for param in spec {
|
|
|
- args.push(self.decode_ty(binary, function, ¶m.ty, &mut argsdata, argsend, ns));
|
|
|
+ args.push(self.decode_ty(binary, function, ¶m.ty, &mut data, argsend, ns));
|
|
|
}
|
|
|
|
|
|
- self.check_overrun(binary, function, argsdata, argsend, true);
|
|
|
+ self.check_overrun(binary, function, data, argsend, true);
|
|
|
}
|
|
|
|
|
|
/// ABI encode into a vector for abi.encode* style builtin functions
|
|
|
@@ -882,43 +885,41 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
.unwrap()
|
|
|
.into_pointer_value();
|
|
|
|
|
|
- let v = binary.builder.build_pointer_cast(
|
|
|
- p,
|
|
|
- binary
|
|
|
- .module
|
|
|
- .get_struct_type("struct.vector")
|
|
|
- .unwrap()
|
|
|
- .ptr_type(AddressSpace::default()),
|
|
|
- "string",
|
|
|
- );
|
|
|
-
|
|
|
// if it's packed, we have the correct length already
|
|
|
if args.is_empty() {
|
|
|
let data_len = unsafe {
|
|
|
- binary
|
|
|
- .builder
|
|
|
- .build_gep(v, &[i32_zero!(), i32_zero!()], "data_len")
|
|
|
+ binary.builder.build_gep(
|
|
|
+ binary.module.get_struct_type("struct.vector").unwrap(),
|
|
|
+ p,
|
|
|
+ &[i32_zero!(), i32_zero!()],
|
|
|
+ "data_len",
|
|
|
+ )
|
|
|
};
|
|
|
|
|
|
binary.builder.build_store(data_len, length);
|
|
|
}
|
|
|
|
|
|
let data_size = unsafe {
|
|
|
- binary
|
|
|
- .builder
|
|
|
- .build_gep(v, &[i32_zero!(), i32_const!(1)], "data_size")
|
|
|
+ binary.builder.build_gep(
|
|
|
+ binary.module.get_struct_type("struct.vector").unwrap(),
|
|
|
+ p,
|
|
|
+ &[i32_zero!(), i32_const!(1)],
|
|
|
+ "data_size",
|
|
|
+ )
|
|
|
};
|
|
|
|
|
|
binary.builder.build_store(data_size, length);
|
|
|
|
|
|
let data = unsafe {
|
|
|
- binary
|
|
|
- .builder
|
|
|
- .build_gep(v, &[i32_zero!(), i32_const!(2)], "data")
|
|
|
+ binary.builder.build_gep(
|
|
|
+ binary.module.get_struct_type("struct.vector").unwrap(),
|
|
|
+ p,
|
|
|
+ &[i32_zero!(), i32_const!(2)],
|
|
|
+ "data",
|
|
|
+ )
|
|
|
};
|
|
|
|
|
|
// now encode each of the arguments
|
|
|
- let data = binary.builder.build_pointer_cast(data, byte_ptr!(), "");
|
|
|
|
|
|
let mut argsdata = data;
|
|
|
|
|
|
@@ -948,15 +949,18 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
);
|
|
|
|
|
|
let data_len = unsafe {
|
|
|
- binary
|
|
|
- .builder
|
|
|
- .build_gep(v, &[i32_zero!(), i32_zero!()], "data_len")
|
|
|
+ binary.builder.build_gep(
|
|
|
+ binary.module.get_struct_type("struct.vector").unwrap(),
|
|
|
+ p,
|
|
|
+ &[i32_zero!(), i32_zero!()],
|
|
|
+ "data_len",
|
|
|
+ )
|
|
|
};
|
|
|
|
|
|
binary.builder.build_store(data_len, length);
|
|
|
}
|
|
|
|
|
|
- v
|
|
|
+ p
|
|
|
}
|
|
|
|
|
|
/// ABI encode the return values for the function
|
|
|
@@ -1005,17 +1009,11 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
let mut argsdata = data;
|
|
|
|
|
|
if let Some(selector) = selector {
|
|
|
- binary.builder.build_store(
|
|
|
- binary.builder.build_pointer_cast(
|
|
|
- data,
|
|
|
- selector.get_type().ptr_type(AddressSpace::default()),
|
|
|
- "",
|
|
|
- ),
|
|
|
- selector,
|
|
|
- );
|
|
|
+ binary.builder.build_store(data, selector);
|
|
|
|
|
|
argsdata = unsafe {
|
|
|
binary.builder.build_gep(
|
|
|
+ binary.context.i8_type(),
|
|
|
data,
|
|
|
&[selector
|
|
|
.get_type()
|
|
|
@@ -1093,24 +1091,10 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
// salt
|
|
|
let salt_buf =
|
|
|
binary.build_alloca(function, binary.context.i8_type().array_type(36), "salt");
|
|
|
- let salt_buf = binary
|
|
|
- .builder
|
|
|
- .build_pointer_cast(salt_buf, byte_ptr!(), "salt_buf");
|
|
|
let salt_len = i32_const!(32);
|
|
|
|
|
|
if let Some(salt) = contract_args.salt {
|
|
|
- let salt_ty = ast::Type::Uint(256);
|
|
|
-
|
|
|
- binary.builder.build_store(
|
|
|
- binary.builder.build_pointer_cast(
|
|
|
- salt_buf,
|
|
|
- binary
|
|
|
- .llvm_type(&salt_ty, ns)
|
|
|
- .ptr_type(AddressSpace::default()),
|
|
|
- "salt",
|
|
|
- ),
|
|
|
- salt,
|
|
|
- );
|
|
|
+ binary.builder.build_store(salt_buf, salt);
|
|
|
} else {
|
|
|
let (ptr, len) = self.contract_unique_salt(binary, contract_no, ns);
|
|
|
|
|
|
@@ -1141,7 +1125,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
|
|
|
call!(
|
|
|
"seal_minimum_balance",
|
|
|
- &[cast_byte_ptr!(value_ptr).into(), scratch_len.into()],
|
|
|
+ &[value_ptr.into(), scratch_len.into()],
|
|
|
"minimum_balance"
|
|
|
);
|
|
|
}
|
|
|
@@ -1170,7 +1154,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
&[
|
|
|
codehash.into(),
|
|
|
gas.into(),
|
|
|
- cast_byte_ptr!(value_ptr, "value_transfer").into(),
|
|
|
+ value_ptr.into(),
|
|
|
encoded_args.into(),
|
|
|
encoded_args_len.into(),
|
|
|
address.into(),
|
|
|
@@ -1218,7 +1202,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
scratch_buf,
|
|
|
binary
|
|
|
.builder
|
|
|
- .build_load(scratch_len, "string_len")
|
|
|
+ .build_load(binary.context.i32_type(), scratch_len, "string_len")
|
|
|
.into_int_value(),
|
|
|
);
|
|
|
|
|
|
@@ -1264,7 +1248,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
i32_zero!().into(), // TODO implement flags (mostly used for proxy calls)
|
|
|
address.unwrap().into(),
|
|
|
gas.into(),
|
|
|
- cast_byte_ptr!(value_ptr, "value_transfer").into(),
|
|
|
+ value_ptr.into(),
|
|
|
payload.into(),
|
|
|
payload_len.into(),
|
|
|
scratch_buf.into(),
|
|
|
@@ -1303,7 +1287,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
scratch_buf,
|
|
|
binary
|
|
|
.builder
|
|
|
- .build_load(scratch_len, "string_len")
|
|
|
+ .build_load(binary.context.i32_type(), scratch_len, "string_len")
|
|
|
.into_int_value(),
|
|
|
);
|
|
|
|
|
|
@@ -1336,7 +1320,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
&[
|
|
|
address.into(),
|
|
|
i32_const!(ns.address_length as u64).into(),
|
|
|
- cast_byte_ptr!(value_ptr, "value_transfer").into(),
|
|
|
+ value_ptr.into(),
|
|
|
i32_const!(ns.value_length as u64).into()
|
|
|
]
|
|
|
)
|
|
|
@@ -1378,7 +1362,10 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
|
|
|
let (scratch_buf, scratch_len) = scratch_buf!();
|
|
|
|
|
|
- let length = binary.builder.build_load(scratch_len, "string_len");
|
|
|
+ let length =
|
|
|
+ binary
|
|
|
+ .builder
|
|
|
+ .build_load(binary.context.i32_type(), scratch_len, "string_len");
|
|
|
|
|
|
call!(
|
|
|
"vector_new",
|
|
|
@@ -1406,13 +1393,13 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
|
|
|
call!(
|
|
|
"seal_value_transferred",
|
|
|
- &[cast_byte_ptr!(value).into(), value_len.into()],
|
|
|
+ &[value.into(), value_len.into()],
|
|
|
"value_transferred"
|
|
|
);
|
|
|
|
|
|
binary
|
|
|
.builder
|
|
|
- .build_load(value, "value_transferred")
|
|
|
+ .build_load(binary.value_type(ns), value, "value_transferred")
|
|
|
.into_int_value()
|
|
|
}
|
|
|
|
|
|
@@ -1426,11 +1413,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
|
|
|
binary.builder.build_store(address, addr);
|
|
|
|
|
|
- call!(
|
|
|
- "seal_terminate",
|
|
|
- &[cast_byte_ptr!(address).into()],
|
|
|
- "terminated"
|
|
|
- );
|
|
|
+ call!("seal_terminate", &[address.into()], "terminated");
|
|
|
|
|
|
binary.builder.build_unreachable();
|
|
|
}
|
|
|
@@ -1471,14 +1454,17 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
|
|
|
call!(
|
|
|
"__beNtoleN",
|
|
|
- &[
|
|
|
- res.into(),
|
|
|
- cast_byte_ptr!(temp).into(),
|
|
|
- i32_const!(hashlen).into()
|
|
|
- ]
|
|
|
+ &[res.into(), temp.into(), i32_const!(hashlen).into()]
|
|
|
);
|
|
|
|
|
|
- binary.builder.build_load(temp, "hash").into_int_value()
|
|
|
+ binary
|
|
|
+ .builder
|
|
|
+ .build_load(
|
|
|
+ binary.llvm_type(&ast::Type::Bytes(hashlen as u8), ns),
|
|
|
+ temp,
|
|
|
+ "hash",
|
|
|
+ )
|
|
|
+ .into_int_value()
|
|
|
}
|
|
|
|
|
|
/// Emit event
|
|
|
@@ -1521,17 +1507,17 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
);
|
|
|
|
|
|
let mut dest = unsafe {
|
|
|
- binary
|
|
|
- .builder
|
|
|
- .build_gep(topic_buf, &[i32_const!(1)], "dest")
|
|
|
+ binary.builder.build_gep(
|
|
|
+ binary.context.i8_type(),
|
|
|
+ topic_buf,
|
|
|
+ &[i32_const!(1)],
|
|
|
+ "dest",
|
|
|
+ )
|
|
|
};
|
|
|
|
|
|
call!(
|
|
|
"__bzero8",
|
|
|
- &[
|
|
|
- cast_byte_ptr!(dest, "dest").into(),
|
|
|
- i32_const!(topic_count as u64 * 4).into()
|
|
|
- ]
|
|
|
+ &[dest.into(), i32_const!(topic_count as u64 * 4).into()]
|
|
|
);
|
|
|
|
|
|
for topic in topics.iter() {
|
|
|
@@ -1544,7 +1530,14 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
]
|
|
|
);
|
|
|
|
|
|
- dest = unsafe { binary.builder.build_gep(dest, &[i32_const!(32)], "dest") };
|
|
|
+ dest = unsafe {
|
|
|
+ binary.builder.build_gep(
|
|
|
+ binary.context.i8_type(),
|
|
|
+ dest,
|
|
|
+ &[i32_const!(32)],
|
|
|
+ "dest",
|
|
|
+ )
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
topic_buf
|
|
|
@@ -1599,14 +1592,8 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
call!($func, &[scratch_buf.into(), scratch_len.into()], $name);
|
|
|
|
|
|
binary.builder.build_load(
|
|
|
- binary.builder.build_pointer_cast(
|
|
|
- scratch_buf,
|
|
|
- binary
|
|
|
- .context
|
|
|
- .custom_width_int_type($width)
|
|
|
- .ptr_type(AddressSpace::default()),
|
|
|
- "",
|
|
|
- ),
|
|
|
+ binary.context.custom_width_int_type($width),
|
|
|
+ scratch_buf,
|
|
|
$name,
|
|
|
)
|
|
|
}};
|
|
|
@@ -1620,7 +1607,11 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
&[
|
|
|
binary
|
|
|
.builder
|
|
|
- .build_load(binary.calldata_len.as_pointer_value(), "calldata_len")
|
|
|
+ .build_load(
|
|
|
+ binary.context.i32_type(),
|
|
|
+ binary.calldata_len.as_pointer_value(),
|
|
|
+ "calldata_len"
|
|
|
+ )
|
|
|
.into(),
|
|
|
i32_const!(1).into(),
|
|
|
binary
|
|
|
@@ -1639,6 +1630,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
|
|
|
let data = unsafe {
|
|
|
binary.builder.build_gep(
|
|
|
+ binary.context.get_struct_type("struct.vector").unwrap(),
|
|
|
v.into_pointer_value(),
|
|
|
&[i32_zero!(), i32_const!(2)],
|
|
|
"",
|
|
|
@@ -1653,11 +1645,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
.build_store(scratch_len, i32_const!(SCRATCH_SIZE as u64));
|
|
|
|
|
|
// retrieve the data
|
|
|
- call!(
|
|
|
- "seal_input",
|
|
|
- &[cast_byte_ptr!(data).into(), scratch_len.into()],
|
|
|
- "data"
|
|
|
- );
|
|
|
+ call!("seal_input", &[data.into(), scratch_len.into()], "data");
|
|
|
|
|
|
v
|
|
|
}
|
|
|
@@ -1713,14 +1701,10 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
);
|
|
|
|
|
|
binary.builder.build_load(
|
|
|
- binary.builder.build_pointer_cast(
|
|
|
- scratch_buf,
|
|
|
- binary
|
|
|
- .context
|
|
|
- .custom_width_int_type(ns.value_length as u32 * 8)
|
|
|
- .ptr_type(AddressSpace::default()),
|
|
|
- "",
|
|
|
- ),
|
|
|
+ binary
|
|
|
+ .context
|
|
|
+ .custom_width_int_type(ns.value_length as u32 * 8),
|
|
|
+ scratch_buf,
|
|
|
"price",
|
|
|
)
|
|
|
}
|
|
|
@@ -1737,14 +1721,9 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
"caller"
|
|
|
);
|
|
|
|
|
|
- binary.builder.build_load(
|
|
|
- binary.builder.build_pointer_cast(
|
|
|
- scratch_buf,
|
|
|
- binary.address_type(ns).ptr_type(AddressSpace::default()),
|
|
|
- "",
|
|
|
- ),
|
|
|
- "caller",
|
|
|
- )
|
|
|
+ binary
|
|
|
+ .builder
|
|
|
+ .build_load(binary.address_type(ns), scratch_buf, "caller")
|
|
|
}
|
|
|
codegen::Expression::Builtin(_, _, codegen::Builtin::Value, _) => {
|
|
|
self.value_transferred(binary, ns).into()
|
|
|
@@ -1769,14 +1748,9 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
"address"
|
|
|
);
|
|
|
|
|
|
- binary.builder.build_load(
|
|
|
- binary.builder.build_pointer_cast(
|
|
|
- scratch_buf,
|
|
|
- binary.address_type(ns).ptr_type(AddressSpace::default()),
|
|
|
- "",
|
|
|
- ),
|
|
|
- "self_address",
|
|
|
- )
|
|
|
+ binary
|
|
|
+ .builder
|
|
|
+ .build_load(binary.address_type(ns), scratch_buf, "self_address")
|
|
|
}
|
|
|
codegen::Expression::Builtin(_, _, codegen::Builtin::Balance, _) => {
|
|
|
let (scratch_buf, scratch_len) = scratch_buf!();
|
|
|
@@ -1791,14 +1765,9 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
"balance"
|
|
|
);
|
|
|
|
|
|
- binary.builder.build_load(
|
|
|
- binary.builder.build_pointer_cast(
|
|
|
- scratch_buf,
|
|
|
- binary.value_type(ns).ptr_type(AddressSpace::default()),
|
|
|
- "",
|
|
|
- ),
|
|
|
- "balance",
|
|
|
- )
|
|
|
+ binary
|
|
|
+ .builder
|
|
|
+ .build_load(binary.value_type(ns), scratch_buf, "balance")
|
|
|
}
|
|
|
_ => unreachable!("{:?}", expr),
|
|
|
}
|
|
|
@@ -1853,6 +1822,7 @@ impl<'a> TargetRuntime<'a> for SubstrateTarget {
|
|
|
_function: FunctionValue<'a>,
|
|
|
_builtin_func: &Function,
|
|
|
_args: &[BasicMetadataValueEnum<'a>],
|
|
|
+ _first_arg_type: BasicTypeEnum,
|
|
|
_ns: &Namespace,
|
|
|
) -> BasicValueEnum<'a> {
|
|
|
unimplemented!()
|