mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-25 07:07:57 +00:00
implement address and msg.sender
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
@@ -10,8 +10,12 @@ pub static DEPLOY: &str = "deploy";
|
||||
/// Useful for configuring common attributes and linkage.
|
||||
pub static EXPORTS: [&str; 2] = [CALL, DEPLOY];
|
||||
|
||||
pub static ADDRESS: &str = "address";
|
||||
|
||||
pub static BLOCK_NUMBER: &str = "block_number";
|
||||
|
||||
pub static CALLER: &str = "caller";
|
||||
|
||||
pub static GET_STORAGE: &str = "get_storage";
|
||||
|
||||
pub static HASH_KECCAK_256: &str = "hash_keccak_256";
|
||||
|
||||
@@ -621,9 +621,9 @@ where
|
||||
) -> (Pointer<'ctx>, Pointer<'ctx>) {
|
||||
let buffer_pointer = self.build_alloca(self.integer_type(bit_length), name);
|
||||
let symbol = match bit_length {
|
||||
256 => GLOBAL_I256_SIZE,
|
||||
128 => GLOBAL_I128_SIZE,
|
||||
64 => GLOBAL_I64_SIZE,
|
||||
revive_common::BIT_LENGTH_WORD => GLOBAL_I256_SIZE,
|
||||
revive_common::BIT_LENGTH_VALUE => GLOBAL_I128_SIZE,
|
||||
revive_common::BIT_LENGTH_BLOCK_NUMBER => GLOBAL_I64_SIZE,
|
||||
_ => unreachable!("invalid stack parameter bit width: {bit_length}"),
|
||||
};
|
||||
let length_pointer = self.get_global(symbol).expect("should be declared");
|
||||
|
||||
@@ -163,3 +163,41 @@ where
|
||||
.build_int_z_extend(heap_size, context.word_type(), "heap_size_extended")?
|
||||
.as_basic_value_enum())
|
||||
}
|
||||
|
||||
/// Translates the `address` instruction.
|
||||
pub fn address<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let (output_pointer, output_length_pointer) =
|
||||
context.build_stack_parameter(revive_common::BIT_LENGTH_WORD, "address_output");
|
||||
context.build_runtime_call(
|
||||
runtime_api::ADDRESS,
|
||||
&[
|
||||
output_pointer.to_int(context).into(),
|
||||
output_length_pointer.to_int(context).into(),
|
||||
],
|
||||
);
|
||||
context.build_load(output_pointer, "address")
|
||||
}
|
||||
|
||||
/// Translates the `caller` instruction.
|
||||
pub fn caller<'ctx, D>(
|
||||
context: &mut Context<'ctx, D>,
|
||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
let (output_pointer, output_length_pointer) =
|
||||
context.build_stack_parameter(revive_common::BIT_LENGTH_WORD, "caller_output");
|
||||
context.build_runtime_call(
|
||||
runtime_api::CALLER,
|
||||
&[
|
||||
output_pointer.to_int(context).into(),
|
||||
output_length_pointer.to_int(context).into(),
|
||||
],
|
||||
);
|
||||
context.build_load(output_pointer, "caller")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user