implement the value opcode

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2024-04-17 18:05:51 +02:00
parent 09b905415b
commit b208daed7e
8 changed files with 78 additions and 4 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
//!
/// The LLVM framework version.
pub const LLVM_VERSION: semver::Version = semver::Version::new(15, 0, 4);
pub const LLVM_VERSION: semver::Version = semver::Version::new(18, 1, 4);
/// The EraVM version.
pub const ZKEVM_VERSION: semver::Version = semver::Version::new(1, 3, 2);
@@ -1480,6 +1480,12 @@ where
self.llvm.custom_width_int_type(crate::eravm::XLEN as u32)
}
/// Returns the runtime value width sized type.
pub fn value_type(&self) -> inkwell::types::IntType<'ctx> {
self.llvm
.custom_width_int_type(revive_common::BIT_LENGTH_VALUE as u32)
}
///
/// Returns the default field type.
///
+37 -1
View File
@@ -28,7 +28,43 @@ pub fn value<'ctx, D>(
where
D: Dependency + Clone,
{
Ok(context.integer_const(256, 0).as_basic_value_enum())
let output_pointer = context.build_alloca(context.value_type(), "output_pointer");
let output_pointer_casted = context.builder().build_ptr_to_int(
output_pointer.value,
context.xlen_type(),
"output_pointer_casted",
)?;
let output_length_pointer = context.build_alloca(context.xlen_type(), "output_len_pointer");
let output_length_pointer_casted = context.builder().build_ptr_to_int(
output_length_pointer.value,
context.xlen_type(),
"output_pointer_casted",
)?;
context.build_store(
output_length_pointer,
context.integer_const(crate::eravm::XLEN, revive_common::BYTE_LENGTH_VALUE as u64),
)?;
context.builder().build_call(
context
.module()
.get_function("value_transferred")
.expect("is declared"),
&[
output_pointer_casted.into(),
output_length_pointer_casted.into(),
],
"call_seal_value_transferred",
)?;
let value = context.build_load(output_pointer, "transferred_value")?;
let value_extended = context.builder().build_int_z_extend(
value.into_int_value(),
context.field_type(),
"transferred_value_extended",
)?;
Ok(value_extended.as_basic_value_enum())
}
///