mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-27 06:58:00 +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> {
|
||||
/// 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.
|
||||
const STACK_HASHMAP_INITIAL_CAPACITY: usize = 64;
|
||||
|
||||
|
||||
@@ -433,12 +433,6 @@ where
|
||||
let pointer = self.build_alloca(self.word_type(), "return_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 => {
|
||||
self.set_basic_block(entry_block);
|
||||
let pointer = self.build_alloca(
|
||||
|
||||
@@ -125,13 +125,6 @@ impl FunctionCall {
|
||||
let location = self.location;
|
||||
|
||||
match self.name {
|
||||
Name::UserDefined(name)
|
||||
if name.starts_with(
|
||||
revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX,
|
||||
) =>
|
||||
{
|
||||
unimplemented!();
|
||||
}
|
||||
Name::UserDefined(name) => {
|
||||
let mut values = Vec::with_capacity(self.arguments.len());
|
||||
for argument in self.arguments.into_iter().rev() {
|
||||
|
||||
@@ -92,37 +92,7 @@ impl FunctionDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
let (mut 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());
|
||||
}
|
||||
|
||||
let (arguments, next) = Identifier::parse_typed_list(lexer, None)?;
|
||||
match crate::yul::parser::take_or_next(next, lexer)? {
|
||||
Token {
|
||||
lexeme: Lexeme::Symbol(Symbol::ParenthesisRight),
|
||||
@@ -305,22 +275,12 @@ where
|
||||
yul_type.into_llvm(context)
|
||||
})
|
||||
.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());
|
||||
context
|
||||
.current_function()
|
||||
.borrow_mut()
|
||||
.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(
|
||||
pointer,
|
||||
context.current_function().borrow().get_nth_param(index),
|
||||
@@ -348,13 +308,6 @@ where
|
||||
let return_value = context.build_load(pointer, "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, .. } => {
|
||||
let return_value = context.build_load(pointer, "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]
|
||||
fn error_reserved_identifier() {
|
||||
let input = r#"
|
||||
|
||||
Reference in New Issue
Block a user