wip evm builtins

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
Cyrill Leutwiler
2025-07-03 15:36:11 +02:00
parent dfe56f9306
commit bb3b6ddb41
5 changed files with 91 additions and 15 deletions
@@ -176,10 +176,11 @@ impl FunctionCall {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
revive_llvm_context::polkavm_evm_arithmetic::addition(
context,
arguments[0].into_int_value(),
arguments[1].into_int_value(),
)
.map(Some)
bindings,
arguments[0].into_pointer_value(),
arguments[1].into_pointer_value(),
)?;
Ok(())
}
Name::Sub => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
@@ -998,10 +999,12 @@ impl FunctionCall {
D: revive_llvm_context::PolkaVMDependency + Clone,
{
let mut arguments = Vec::with_capacity(N);
for expression in self.arguments.drain(0..N).rev() {
for (index, expression) in self.arguments.drain(0..N).rev().enumerate() {
let name = format!("arg_{index}");
let pointer = context.build_alloca(context.word_type(), &name);
arguments.push(
expression
.into_llvm(context)?
.into_llvm(&[(name, pointer)], context)?
.expect("Always exists")
.access(context)?,
);
@@ -1020,8 +1023,14 @@ impl FunctionCall {
D: revive_llvm_context::PolkaVMDependency + Clone,
{
let mut arguments = Vec::with_capacity(N);
for expression in self.arguments.drain(0..N).rev() {
arguments.push(expression.into_llvm(context)?.expect("Always exists"));
for (index, expression) in self.arguments.drain(0..N).rev().enumerate() {
let name = format!("arg_{index}");
let pointer = context.build_alloca(context.word_type(), &name);
arguments.push(
expression
.into_llvm(&[(name, pointer)], context)?
.expect("Always exists"),
);
}
arguments.reverse();
@@ -204,6 +204,7 @@ where
revive_llvm_context::PolkaVMEventLogFunction::<3>.declare(context)?;
revive_llvm_context::PolkaVMEventLogFunction::<4>.declare(context)?;
revive_llvm_context::PolkaVMAdditionFunction.declare(context)?;
revive_llvm_context::PolkaVMDivisionFunction.declare(context)?;
revive_llvm_context::PolkaVMSignedDivisionFunction.declare(context)?;
revive_llvm_context::PolkaVMRemainderFunction.declare(context)?;
@@ -258,6 +259,7 @@ where
revive_llvm_context::PolkaVMEventLogFunction::<3>.into_llvm(context)?;
revive_llvm_context::PolkaVMEventLogFunction::<4>.into_llvm(context)?;
revive_llvm_context::PolkaVMAdditionFunction.into_llvm(context)?;
revive_llvm_context::PolkaVMDivisionFunction.into_llvm(context)?;
revive_llvm_context::PolkaVMSignedDivisionFunction.into_llvm(context)?;
revive_llvm_context::PolkaVMRemainderFunction.into_llvm(context)?;