mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-29 06:38:00 +00:00
Contract calls (#19)
This commit is contained in:
@@ -11,11 +11,6 @@ use crate::polkavm::context::function::Function;
|
||||
/// The functions are automatically linked to the LLVM implementations if the signatures match.
|
||||
#[derive(Debug)]
|
||||
pub struct LLVMRuntime<'ctx> {
|
||||
/// The LLVM personality function, used for exception handling.
|
||||
pub personality: FunctionDeclaration<'ctx>,
|
||||
/// The LLVM exception throwing function.
|
||||
pub cxa_throw: FunctionDeclaration<'ctx>,
|
||||
|
||||
/// The corresponding LLVM runtime function.
|
||||
pub shl: FunctionDeclaration<'ctx>,
|
||||
/// The corresponding LLVM runtime function.
|
||||
@@ -37,29 +32,6 @@ pub struct LLVMRuntime<'ctx> {
|
||||
/// The corresponding LLVM runtime function.
|
||||
pub sha3: FunctionDeclaration<'ctx>,
|
||||
|
||||
/// The corresponding LLVM runtime function.
|
||||
pub system_request: FunctionDeclaration<'ctx>,
|
||||
|
||||
/// The corresponding LLVM runtime function.
|
||||
//pub far_call: FunctionDeclaration<'ctx>,
|
||||
/// The corresponding LLVM runtime function.
|
||||
pub far_call_byref: FunctionDeclaration<'ctx>,
|
||||
|
||||
/// The corresponding LLVM runtime function.
|
||||
pub static_call: FunctionDeclaration<'ctx>,
|
||||
/// The corresponding LLVM runtime function.
|
||||
pub static_call_byref: FunctionDeclaration<'ctx>,
|
||||
|
||||
/// The corresponding LLVM runtime function.
|
||||
pub delegate_call: FunctionDeclaration<'ctx>,
|
||||
/// The corresponding LLVM runtime function.
|
||||
pub delegate_call_byref: FunctionDeclaration<'ctx>,
|
||||
|
||||
/// The corresponding LLVM runtime function.
|
||||
pub mimic_call: FunctionDeclaration<'ctx>,
|
||||
/// The corresponding LLVM runtime function.
|
||||
pub mimic_call_byref: FunctionDeclaration<'ctx>,
|
||||
|
||||
/// The corresponding LLVM runtime function.
|
||||
pub r#return: FunctionDeclaration<'ctx>,
|
||||
/// The corresponding LLVM runtime function.
|
||||
@@ -139,30 +111,6 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
module: &inkwell::module::Module<'ctx>,
|
||||
optimizer: &Optimizer,
|
||||
) -> Self {
|
||||
let personality = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_PERSONALITY,
|
||||
llvm.i32_type().fn_type(&[], false),
|
||||
None,
|
||||
);
|
||||
|
||||
let cxa_throw = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_CXA_THROW,
|
||||
llvm.void_type().fn_type(
|
||||
vec![
|
||||
llvm.ptr_type(AddressSpace::Stack.into())
|
||||
.as_basic_type_enum()
|
||||
.into();
|
||||
3
|
||||
]
|
||||
.as_slice(),
|
||||
false,
|
||||
),
|
||||
Some(inkwell::module::Linkage::External),
|
||||
);
|
||||
Function::set_cxa_throw_attributes(llvm, cxa_throw);
|
||||
|
||||
let shl = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_SHL,
|
||||
@@ -288,138 +236,6 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
false,
|
||||
);
|
||||
|
||||
let system_request = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_SYSTEM_REQUEST,
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.fn_type(
|
||||
vec![
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
llvm.ptr_type(AddressSpace::Stack.into())
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
]
|
||||
.as_slice(),
|
||||
false,
|
||||
),
|
||||
Some(inkwell::module::Linkage::External),
|
||||
);
|
||||
Function::set_default_attributes(llvm, system_request, optimizer);
|
||||
|
||||
let external_call_arguments: Vec<inkwell::types::BasicMetadataTypeEnum> = vec![
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into();
|
||||
crate::polkavm::context::function::runtime::entry::Entry::MANDATORY_ARGUMENTS_COUNT
|
||||
+ crate::polkavm::EXTRA_ABI_DATA_SIZE
|
||||
];
|
||||
let mut mimic_call_arguments = external_call_arguments.clone();
|
||||
mimic_call_arguments.push(
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
);
|
||||
|
||||
let mut external_call_arguments_by_ref: Vec<inkwell::types::BasicMetadataTypeEnum> = vec![
|
||||
llvm.ptr_type(AddressSpace::Generic.into())
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
];
|
||||
external_call_arguments_by_ref.extend::<Vec<inkwell::types::BasicMetadataTypeEnum>>(vec![
|
||||
llvm.custom_width_int_type(
|
||||
revive_common::BIT_LENGTH_WORD as u32
|
||||
)
|
||||
.as_basic_type_enum()
|
||||
.into();
|
||||
crate::polkavm::EXTRA_ABI_DATA_SIZE
|
||||
]);
|
||||
let mut mimic_call_arguments_by_ref = external_call_arguments_by_ref.clone();
|
||||
mimic_call_arguments_by_ref.push(
|
||||
llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32)
|
||||
.as_basic_type_enum()
|
||||
.into(),
|
||||
);
|
||||
|
||||
let external_call_result_type = llvm
|
||||
.struct_type(
|
||||
&[
|
||||
llvm.ptr_type(AddressSpace::Generic.into())
|
||||
.as_basic_type_enum(),
|
||||
llvm.bool_type().as_basic_type_enum(),
|
||||
],
|
||||
false,
|
||||
)
|
||||
.as_basic_type_enum();
|
||||
|
||||
//let far_call = Self::declare(
|
||||
// module,
|
||||
// Self::FUNCTION_FARCALL,
|
||||
// external_call_result_type.fn_type(external_call_arguments.as_slice(), false),
|
||||
// Some(inkwell::module::Linkage::External),
|
||||
//);
|
||||
//Function::set_default_attributes(llvm, far_call, optimizer);
|
||||
let static_call = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_STATICCALL,
|
||||
external_call_result_type.fn_type(external_call_arguments.as_slice(), false),
|
||||
Some(inkwell::module::Linkage::External),
|
||||
);
|
||||
Function::set_default_attributes(llvm, static_call, optimizer);
|
||||
let delegate_call = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_DELEGATECALL,
|
||||
external_call_result_type.fn_type(external_call_arguments.as_slice(), false),
|
||||
Some(inkwell::module::Linkage::External),
|
||||
);
|
||||
Function::set_default_attributes(llvm, delegate_call, optimizer);
|
||||
let mimic_call = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_MIMICCALL,
|
||||
external_call_result_type.fn_type(mimic_call_arguments.as_slice(), false),
|
||||
Some(inkwell::module::Linkage::External),
|
||||
);
|
||||
Function::set_default_attributes(llvm, mimic_call, optimizer);
|
||||
|
||||
let far_call_byref = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_FARCALL_BYREF,
|
||||
external_call_result_type.fn_type(external_call_arguments_by_ref.as_slice(), false),
|
||||
Some(inkwell::module::Linkage::External),
|
||||
);
|
||||
Function::set_default_attributes(llvm, far_call_byref, optimizer);
|
||||
let static_call_byref = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_STATICCALL_BYREF,
|
||||
external_call_result_type.fn_type(external_call_arguments_by_ref.as_slice(), false),
|
||||
Some(inkwell::module::Linkage::External),
|
||||
);
|
||||
Function::set_default_attributes(llvm, static_call_byref, optimizer);
|
||||
let delegate_call_byref = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_DELEGATECALL_BYREF,
|
||||
external_call_result_type.fn_type(external_call_arguments_by_ref.as_slice(), false),
|
||||
Some(inkwell::module::Linkage::External),
|
||||
);
|
||||
Function::set_default_attributes(llvm, delegate_call_byref, optimizer);
|
||||
let mimic_call_byref = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_MIMICCALL_BYREF,
|
||||
external_call_result_type.fn_type(mimic_call_arguments_by_ref.as_slice(), false),
|
||||
Some(inkwell::module::Linkage::External),
|
||||
);
|
||||
Function::set_default_attributes(llvm, mimic_call_byref, optimizer);
|
||||
|
||||
let r#return = Self::declare(
|
||||
module,
|
||||
Self::FUNCTION_RETURN,
|
||||
@@ -454,9 +270,6 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
Function::set_default_attributes(llvm, revert, optimizer);
|
||||
|
||||
Self {
|
||||
personality,
|
||||
cxa_throw,
|
||||
|
||||
shl,
|
||||
shr,
|
||||
sar,
|
||||
@@ -469,18 +282,6 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
|
||||
sha3,
|
||||
|
||||
system_request,
|
||||
|
||||
//far_call,
|
||||
static_call,
|
||||
delegate_call,
|
||||
mimic_call,
|
||||
|
||||
far_call_byref,
|
||||
static_call_byref,
|
||||
delegate_call_byref,
|
||||
mimic_call_byref,
|
||||
|
||||
r#return,
|
||||
revert,
|
||||
}
|
||||
@@ -506,42 +307,4 @@ impl<'ctx> LLVMRuntime<'ctx> {
|
||||
value.set_linkage(inkwell::module::Linkage::External);
|
||||
FunctionDeclaration::new(value.get_type(), value).into()
|
||||
}
|
||||
|
||||
/// Modifies the external call function with `is_byref` and `is_system` modifiers.
|
||||
pub fn modify(
|
||||
&self,
|
||||
function: FunctionDeclaration<'ctx>,
|
||||
is_byref: bool,
|
||||
) -> anyhow::Result<FunctionDeclaration<'ctx>> {
|
||||
let modified = if
|
||||
/*function == self.far_call {
|
||||
match is_byref {
|
||||
false => self.far_call,
|
||||
true => self.far_call_byref,
|
||||
}
|
||||
} else if */
|
||||
function == self.static_call {
|
||||
match is_byref {
|
||||
false => self.static_call,
|
||||
true => self.static_call_byref,
|
||||
}
|
||||
} else if function == self.delegate_call {
|
||||
match is_byref {
|
||||
false => self.delegate_call,
|
||||
true => self.delegate_call_byref,
|
||||
}
|
||||
} else if function == self.mimic_call {
|
||||
match is_byref {
|
||||
false => self.mimic_call,
|
||||
true => self.mimic_call_byref,
|
||||
}
|
||||
} else {
|
||||
anyhow::bail!(
|
||||
"Cannot modify an external call function `{}`",
|
||||
function.value.get_name().to_string_lossy()
|
||||
);
|
||||
};
|
||||
|
||||
Ok(modified)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,244 +0,0 @@
|
||||
//! The `default_call` function.
|
||||
|
||||
use inkwell::types::BasicType;
|
||||
|
||||
use crate::polkavm::context::function::declaration::Declaration as FunctionDeclaration;
|
||||
use crate::polkavm::context::function::llvm_runtime::LLVMRuntime;
|
||||
use crate::polkavm::context::function::Function;
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
use crate::polkavm::WriteLLVM;
|
||||
|
||||
/// The `default_call` function.
|
||||
/// Generates a default contract call, if the `msg.value` is zero.
|
||||
#[derive(Debug)]
|
||||
pub struct DefaultCall {
|
||||
/// The name of the inner function used for the low-level call.
|
||||
inner_name: String,
|
||||
/// The function name with the low-level function name as an element.
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
impl DefaultCall {
|
||||
/// The gas argument index.
|
||||
pub const ARGUMENT_INDEX_GAS: usize = 0;
|
||||
|
||||
/// The address argument index.
|
||||
pub const ARGUMENT_INDEX_ADDRESS: usize = 1;
|
||||
|
||||
/// The input offset argument index.
|
||||
pub const ARGUMENT_INDEX_INPUT_OFFSET: usize = 2;
|
||||
|
||||
/// The input length argument index.
|
||||
pub const ARGUMENT_INDEX_INPUT_LENGTH: usize = 3;
|
||||
|
||||
/// The output offset argument index.
|
||||
pub const ARGUMENT_INDEX_OUTPUT_OFFSET: usize = 4;
|
||||
|
||||
/// The output length argument index.
|
||||
pub const ARGUMENT_INDEX_OUTPUT_LENGTH: usize = 5;
|
||||
|
||||
/// A shortcut constructor.
|
||||
pub fn new(call_function: FunctionDeclaration) -> Self {
|
||||
let inner_name = call_function.value.get_name().to_string_lossy().to_string();
|
||||
let name = Self::name(call_function);
|
||||
|
||||
Self { inner_name, name }
|
||||
}
|
||||
|
||||
/// Returns the function name.
|
||||
pub fn name(call_function: FunctionDeclaration) -> String {
|
||||
let suffix = match call_function.value.get_name().to_string_lossy() {
|
||||
name if name == LLVMRuntime::FUNCTION_FARCALL => "far",
|
||||
name if name == LLVMRuntime::FUNCTION_STATICCALL => "static",
|
||||
name if name == LLVMRuntime::FUNCTION_DELEGATECALL => "delegate",
|
||||
name => panic!("Invalid low-level call inner function `{name}`"),
|
||||
};
|
||||
format!("__default_{suffix}_call")
|
||||
}
|
||||
|
||||
/// Returns the low-level call function.
|
||||
fn inner_function<'ctx, D>(&self, context: &Context<'ctx, D>) -> FunctionDeclaration<'ctx>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
match self.inner_name.as_str() {
|
||||
//name if name == LLVMRuntime::FUNCTION_FARCALL => context.llvm_runtime().far_call,
|
||||
name if name == LLVMRuntime::FUNCTION_STATICCALL => context.llvm_runtime().static_call,
|
||||
name if name == LLVMRuntime::FUNCTION_DELEGATECALL => {
|
||||
context.llvm_runtime().delegate_call
|
||||
}
|
||||
name => panic!("Invalid low-level call inner function `{name}`"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<D> WriteLLVM<D> for DefaultCall
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
let function_type = context.function_type(
|
||||
vec![
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
context.word_type().as_basic_type_enum(),
|
||||
],
|
||||
1,
|
||||
false,
|
||||
);
|
||||
let function = context.add_function(
|
||||
self.name.as_str(),
|
||||
function_type,
|
||||
1,
|
||||
Some(inkwell::module::Linkage::Private),
|
||||
)?;
|
||||
Function::set_frontend_runtime_attributes(
|
||||
context.llvm,
|
||||
function.borrow().declaration(),
|
||||
&context.optimizer,
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
context.set_current_function(self.name.as_str())?;
|
||||
|
||||
/*
|
||||
let gas = context
|
||||
.current_function()
|
||||
.borrow()
|
||||
.get_nth_param(Self::ARGUMENT_INDEX_GAS)
|
||||
.into_int_value();
|
||||
let address = context
|
||||
.current_function()
|
||||
.borrow()
|
||||
.get_nth_param(Self::ARGUMENT_INDEX_ADDRESS)
|
||||
.into_int_value();
|
||||
let input_offset = context
|
||||
.current_function()
|
||||
.borrow()
|
||||
.get_nth_param(Self::ARGUMENT_INDEX_INPUT_OFFSET)
|
||||
.into_int_value();
|
||||
let input_length = context
|
||||
.current_function()
|
||||
.borrow()
|
||||
.get_nth_param(Self::ARGUMENT_INDEX_INPUT_LENGTH)
|
||||
.into_int_value();
|
||||
let output_offset = context
|
||||
.current_function()
|
||||
.borrow()
|
||||
.get_nth_param(Self::ARGUMENT_INDEX_OUTPUT_OFFSET)
|
||||
.into_int_value();
|
||||
let output_length = context
|
||||
.current_function()
|
||||
.borrow()
|
||||
.get_nth_param(Self::ARGUMENT_INDEX_OUTPUT_LENGTH)
|
||||
.into_int_value();
|
||||
*/
|
||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||
|
||||
let status_code_result_pointer = context.build_alloca(
|
||||
context.word_type(),
|
||||
"contract_call_result_status_code_pointer",
|
||||
);
|
||||
/*
|
||||
context.build_store(status_code_result_pointer, context.field_const(0));
|
||||
|
||||
let abi_data = crate::polkavm::utils::abi_data(
|
||||
context,
|
||||
input_offset,
|
||||
input_length,
|
||||
Some(gas),
|
||||
AddressSpace::Heap,
|
||||
false,
|
||||
)?
|
||||
.into_int_value();
|
||||
|
||||
let result = context
|
||||
.build_call(
|
||||
self.inner_function(context),
|
||||
crate::polkavm::utils::external_call_arguments(
|
||||
context,
|
||||
abi_data.as_basic_value_enum(),
|
||||
address,
|
||||
vec![],
|
||||
None,
|
||||
)
|
||||
.as_slice(),
|
||||
"contract_call_external",
|
||||
)
|
||||
.expect("IntrinsicFunction always returns a flag");
|
||||
|
||||
let result_abi_data = context
|
||||
.builder()
|
||||
.build_extract_value(
|
||||
result.into_struct_value(),
|
||||
0,
|
||||
"contract_call_external_result_abi_data",
|
||||
)
|
||||
.expect("Always exists");
|
||||
let result_abi_data_pointer = Pointer::new(
|
||||
context.byte_type(),
|
||||
AddressSpace::Generic,
|
||||
result_abi_data.into_pointer_value(),
|
||||
);
|
||||
let result_abi_data_casted = result_abi_data_pointer.cast(context.field_type());
|
||||
|
||||
let result_status_code_boolean = context
|
||||
.builder()
|
||||
.build_extract_value(
|
||||
result.into_struct_value(),
|
||||
1,
|
||||
"contract_call_external_result_status_code_boolean",
|
||||
)
|
||||
.expect("Always exists");
|
||||
let result_status_code = context.builder().build_int_z_extend_or_bit_cast(
|
||||
result_status_code_boolean.into_int_value(),
|
||||
context.field_type(),
|
||||
"contract_call_external_result_status_code",
|
||||
)?;
|
||||
context.build_store(status_code_result_pointer, result_status_code);
|
||||
|
||||
let source = result_abi_data_casted;
|
||||
|
||||
let destination = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::Heap,
|
||||
context.byte_type(),
|
||||
output_offset,
|
||||
"contract_call_destination",
|
||||
);
|
||||
|
||||
context.build_memcpy_return_data(
|
||||
context.intrinsics().memory_copy_from_generic,
|
||||
destination,
|
||||
source,
|
||||
output_length,
|
||||
"contract_call_memcpy_from_child",
|
||||
);
|
||||
|
||||
context.write_abi_pointer(
|
||||
result_abi_data_pointer,
|
||||
crate::polkavm::GLOBAL_RETURN_DATA_POINTER,
|
||||
);
|
||||
context.write_abi_data_size(
|
||||
result_abi_data_pointer,
|
||||
crate::polkavm::GLOBAL_RETURN_DATA_SIZE,
|
||||
);
|
||||
*/
|
||||
context.build_unconditional_branch(context.current_function().borrow().return_block());
|
||||
|
||||
context.set_basic_block(context.current_function().borrow().return_block());
|
||||
let status_code_result =
|
||||
context.build_load(status_code_result_pointer, "contract_call_status_code")?;
|
||||
context.build_return(Some(&status_code_result));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -153,7 +153,7 @@ impl Entry {
|
||||
context.integer_const(crate::polkavm::XLEN, Self::MAX_CALLDATA_SIZE as u64),
|
||||
)?;
|
||||
context.build_runtime_call(
|
||||
runtime_api::INPUT,
|
||||
runtime_api::imports::INPUT,
|
||||
&[input_pointer_casted.into(), length_pointer_casted.into()],
|
||||
);
|
||||
|
||||
@@ -215,11 +215,11 @@ impl Entry {
|
||||
.ok_or_else(|| anyhow::anyhow!("Contract runtime code not found"))?;
|
||||
|
||||
context.set_basic_block(deploy_code_call_block);
|
||||
context.build_invoke(deploy_code.borrow().declaration, &[], "deploy_code_call");
|
||||
context.build_call(deploy_code.borrow().declaration, &[], "deploy_code_call");
|
||||
context.build_unconditional_branch(context.current_function().borrow().return_block());
|
||||
|
||||
context.set_basic_block(runtime_code_call_block);
|
||||
context.build_invoke(runtime_code.borrow().declaration, &[], "runtime_code_call");
|
||||
context.build_call(runtime_code.borrow().declaration, &[], "runtime_code_call");
|
||||
context.build_unconditional_branch(context.current_function().borrow().return_block());
|
||||
|
||||
Ok(())
|
||||
@@ -235,7 +235,7 @@ where
|
||||
let entry_function_type = context.function_type(entry_arguments, 0, false);
|
||||
context.add_function(Runtime::FUNCTION_ENTRY, entry_function_type, 0, None)?;
|
||||
|
||||
for symbol in runtime_api::EXPORTS {
|
||||
for symbol in runtime_api::exports::EXPORTS {
|
||||
context.declare_extern_function(symbol)?;
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ where
|
||||
true,
|
||||
);
|
||||
|
||||
context.set_current_function(runtime_api::DEPLOY)?;
|
||||
context.set_current_function(runtime_api::exports::DEPLOY)?;
|
||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||
|
||||
assert!(context
|
||||
@@ -268,7 +268,7 @@ where
|
||||
context.set_basic_block(context.current_function().borrow().return_block);
|
||||
context.build_unreachable();
|
||||
|
||||
context.set_current_function(runtime_api::CALL)?;
|
||||
context.set_current_function(runtime_api::exports::CALL)?;
|
||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||
|
||||
assert!(context
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
//! The front-end runtime functions.
|
||||
|
||||
pub mod default_call;
|
||||
pub mod deploy_code;
|
||||
pub mod entry;
|
||||
pub mod runtime_code;
|
||||
|
||||
use crate::polkavm::context::address_space::AddressSpace;
|
||||
use crate::polkavm::context::function::declaration::Declaration as FunctionDeclaration;
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
use crate::polkavm::WriteLLVM;
|
||||
|
||||
use self::default_call::DefaultCall;
|
||||
|
||||
/// The front-end runtime functions.
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -35,40 +28,4 @@ impl Runtime {
|
||||
pub fn new(_address_space: AddressSpace) -> Self {
|
||||
Self { _address_space }
|
||||
}
|
||||
|
||||
/// Returns the corresponding runtime function.
|
||||
pub fn default_call<'ctx, D>(
|
||||
context: &Context<'ctx, D>,
|
||||
call_function: FunctionDeclaration<'ctx>,
|
||||
) -> FunctionDeclaration<'ctx>
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
context
|
||||
.get_function(DefaultCall::name(call_function).as_str())
|
||||
.expect("Always exists")
|
||||
.borrow()
|
||||
.declaration()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D> WriteLLVM<D> for Runtime
|
||||
where
|
||||
D: Dependency + Clone,
|
||||
{
|
||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
//DefaultCall::new(context.llvm_runtime().far_call).declare(context)?;
|
||||
DefaultCall::new(context.llvm_runtime().static_call).declare(context)?;
|
||||
DefaultCall::new(context.llvm_runtime().delegate_call).declare(context)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
//DefaultCall::new(context.llvm_runtime().far_call).into_llvm(context)?;
|
||||
DefaultCall::new(context.llvm_runtime().static_call).into_llvm(context)?;
|
||||
DefaultCall::new(context.llvm_runtime().delegate_call).into_llvm(context)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user