mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-14 08:51:02 +00:00
remove near calls
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
This commit is contained in:
@@ -48,12 +48,6 @@ pub struct Function<'ctx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'ctx> Function<'ctx> {
|
impl<'ctx> Function<'ctx> {
|
||||||
/// The near call ABI function prefix.
|
|
||||||
pub const ZKSYNC_NEAR_CALL_ABI_PREFIX: &'static str = "ZKSYNC_NEAR_CALL";
|
|
||||||
|
|
||||||
/// The near call ABI exception handler name.
|
|
||||||
pub const ZKSYNC_NEAR_CALL_ABI_EXCEPTION_HANDLER: &'static str = "ZKSYNC_CATCH_NEAR_CALL";
|
|
||||||
|
|
||||||
/// The stack hashmap default capacity.
|
/// The stack hashmap default capacity.
|
||||||
const STACK_HASHMAP_INITIAL_CAPACITY: usize = 64;
|
const STACK_HASHMAP_INITIAL_CAPACITY: usize = 64;
|
||||||
|
|
||||||
|
|||||||
@@ -433,12 +433,6 @@ where
|
|||||||
let pointer = self.build_alloca(self.word_type(), "return_pointer");
|
let pointer = self.build_alloca(self.word_type(), "return_pointer");
|
||||||
FunctionReturn::primitive(pointer)
|
FunctionReturn::primitive(pointer)
|
||||||
}
|
}
|
||||||
size if name.starts_with(Function::ZKSYNC_NEAR_CALL_ABI_PREFIX) => {
|
|
||||||
let first_argument = value.get_first_param().expect("Always exists");
|
|
||||||
let r#type = self.structure_type(vec![self.word_type(); size].as_slice());
|
|
||||||
let pointer = first_argument.into_pointer_value();
|
|
||||||
FunctionReturn::compound(Pointer::new(r#type, AddressSpace::Stack, pointer), size)
|
|
||||||
}
|
|
||||||
size => {
|
size => {
|
||||||
self.set_basic_block(entry_block);
|
self.set_basic_block(entry_block);
|
||||||
let pointer = self.build_alloca(
|
let pointer = self.build_alloca(
|
||||||
|
|||||||
@@ -125,13 +125,6 @@ impl FunctionCall {
|
|||||||
let location = self.location;
|
let location = self.location;
|
||||||
|
|
||||||
match self.name {
|
match self.name {
|
||||||
Name::UserDefined(name)
|
|
||||||
if name.starts_with(
|
|
||||||
revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX,
|
|
||||||
) =>
|
|
||||||
{
|
|
||||||
unimplemented!();
|
|
||||||
}
|
|
||||||
Name::UserDefined(name) => {
|
Name::UserDefined(name) => {
|
||||||
let mut values = Vec::with_capacity(self.arguments.len());
|
let mut values = Vec::with_capacity(self.arguments.len());
|
||||||
for argument in self.arguments.into_iter().rev() {
|
for argument in self.arguments.into_iter().rev() {
|
||||||
|
|||||||
@@ -92,37 +92,7 @@ impl FunctionDefinition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (mut arguments, next) = Identifier::parse_typed_list(lexer, None)?;
|
let (arguments, next) = Identifier::parse_typed_list(lexer, None)?;
|
||||||
if identifier
|
|
||||||
.inner
|
|
||||||
.contains(revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX)
|
|
||||||
{
|
|
||||||
if arguments.is_empty() {
|
|
||||||
return Err(ParserError::InvalidNumberOfArguments {
|
|
||||||
location,
|
|
||||||
identifier: identifier.inner,
|
|
||||||
expected: 1,
|
|
||||||
found: arguments.len(),
|
|
||||||
}
|
|
||||||
.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
arguments.remove(0);
|
|
||||||
}
|
|
||||||
if identifier
|
|
||||||
.inner
|
|
||||||
.contains(revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_EXCEPTION_HANDLER)
|
|
||||||
&& !arguments.is_empty()
|
|
||||||
{
|
|
||||||
return Err(ParserError::InvalidNumberOfArguments {
|
|
||||||
location,
|
|
||||||
identifier: identifier.inner,
|
|
||||||
expected: 0,
|
|
||||||
found: arguments.len(),
|
|
||||||
}
|
|
||||||
.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
match crate::yul::parser::take_or_next(next, lexer)? {
|
match crate::yul::parser::take_or_next(next, lexer)? {
|
||||||
Token {
|
Token {
|
||||||
lexeme: Lexeme::Symbol(Symbol::ParenthesisRight),
|
lexeme: Lexeme::Symbol(Symbol::ParenthesisRight),
|
||||||
@@ -305,22 +275,12 @@ where
|
|||||||
yul_type.into_llvm(context)
|
yul_type.into_llvm(context)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
for (mut index, argument) in self.arguments.iter().enumerate() {
|
for (index, argument) in self.arguments.iter().enumerate() {
|
||||||
let pointer = context.build_alloca(argument_types[index], argument.inner.as_str());
|
let pointer = context.build_alloca(argument_types[index], argument.inner.as_str());
|
||||||
context
|
context
|
||||||
.current_function()
|
.current_function()
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.insert_stack_pointer(argument.inner.clone(), pointer);
|
.insert_stack_pointer(argument.inner.clone(), pointer);
|
||||||
if self
|
|
||||||
.identifier
|
|
||||||
.starts_with(revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX)
|
|
||||||
&& matches!(
|
|
||||||
context.current_function().borrow().r#return(),
|
|
||||||
revive_llvm_context::PolkaVMFunctionReturn::Compound { .. }
|
|
||||||
)
|
|
||||||
{
|
|
||||||
index += 1;
|
|
||||||
}
|
|
||||||
context.build_store(
|
context.build_store(
|
||||||
pointer,
|
pointer,
|
||||||
context.current_function().borrow().get_nth_param(index),
|
context.current_function().borrow().get_nth_param(index),
|
||||||
@@ -348,13 +308,6 @@ where
|
|||||||
let return_value = context.build_load(pointer, "return_value")?;
|
let return_value = context.build_load(pointer, "return_value")?;
|
||||||
context.build_return(Some(&return_value));
|
context.build_return(Some(&return_value));
|
||||||
}
|
}
|
||||||
revive_llvm_context::PolkaVMFunctionReturn::Compound { pointer, .. }
|
|
||||||
if context.current_function().borrow().name().starts_with(
|
|
||||||
revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX,
|
|
||||||
) =>
|
|
||||||
{
|
|
||||||
context.build_return(Some(&pointer.value));
|
|
||||||
}
|
|
||||||
revive_llvm_context::PolkaVMFunctionReturn::Compound { pointer, .. } => {
|
revive_llvm_context::PolkaVMFunctionReturn::Compound { pointer, .. } => {
|
||||||
let return_value = context.build_load(pointer, "return_value")?;
|
let return_value = context.build_load(pointer, "return_value")?;
|
||||||
context.build_return(Some(&return_value));
|
context.build_return(Some(&return_value));
|
||||||
@@ -518,80 +471,6 @@ object "Test" {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn error_invalid_number_of_arguments_near_call_abi() {
|
|
||||||
let input = r#"
|
|
||||||
object "Test" {
|
|
||||||
code {
|
|
||||||
{
|
|
||||||
return(0, 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
object "Test_deployed" {
|
|
||||||
code {
|
|
||||||
{
|
|
||||||
return(0, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
function ZKSYNC_NEAR_CALL_test() -> result {
|
|
||||||
result := 42
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#;
|
|
||||||
|
|
||||||
let mut lexer = Lexer::new(input.to_owned());
|
|
||||||
let result = Object::parse(&mut lexer, None);
|
|
||||||
assert_eq!(
|
|
||||||
result,
|
|
||||||
Err(Error::InvalidNumberOfArguments {
|
|
||||||
location: Location::new(14, 22),
|
|
||||||
identifier: "ZKSYNC_NEAR_CALL_test".to_owned(),
|
|
||||||
expected: 1,
|
|
||||||
found: 0,
|
|
||||||
}
|
|
||||||
.into())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn error_invalid_number_of_arguments_near_call_abi_catch() {
|
|
||||||
let input = r#"
|
|
||||||
object "Test" {
|
|
||||||
code {
|
|
||||||
{
|
|
||||||
return(0, 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
object "Test_deployed" {
|
|
||||||
code {
|
|
||||||
{
|
|
||||||
return(0, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
function ZKSYNC_CATCH_NEAR_CALL(length) {
|
|
||||||
revert(0, length)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#;
|
|
||||||
|
|
||||||
let mut lexer = Lexer::new(input.to_owned());
|
|
||||||
let result = Object::parse(&mut lexer, None);
|
|
||||||
assert_eq!(
|
|
||||||
result,
|
|
||||||
Err(Error::InvalidNumberOfArguments {
|
|
||||||
location: Location::new(14, 22),
|
|
||||||
identifier: "ZKSYNC_CATCH_NEAR_CALL".to_owned(),
|
|
||||||
expected: 0,
|
|
||||||
found: 1,
|
|
||||||
}
|
|
||||||
.into())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_reserved_identifier() {
|
fn error_reserved_identifier() {
|
||||||
let input = r#"
|
let input = r#"
|
||||||
|
|||||||
Reference in New Issue
Block a user