rename target to polkavm

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2024-05-02 08:47:44 +02:00
parent 9fc24af355
commit 336fc63f1d
112 changed files with 876 additions and 873 deletions
@@ -35,7 +35,7 @@ pub struct FunctionDefinition {
/// The function body block.
pub body: Block,
/// The function LLVM attributes encoded in the identifier.
pub attributes: BTreeSet<revive_llvm_context::EraVMAttribute>,
pub attributes: BTreeSet<revive_llvm_context::PolkaVMAttribute>,
}
impl FunctionDefinition {
@@ -95,7 +95,7 @@ impl FunctionDefinition {
let (mut arguments, next) = Identifier::parse_typed_list(lexer, None)?;
if identifier
.inner
.contains(revive_llvm_context::EraVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX)
.contains(revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX)
{
if arguments.is_empty() {
return Err(ParserError::InvalidNumberOfArguments {
@@ -110,7 +110,7 @@ impl FunctionDefinition {
arguments.remove(0);
}
if identifier.inner.contains(
revive_llvm_context::EraVMFunction::ZKSYNC_NEAR_CALL_ABI_EXCEPTION_HANDLER,
revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_EXCEPTION_HANDLER,
) && !arguments.is_empty()
{
return Err(ParserError::InvalidNumberOfArguments {
@@ -181,7 +181,7 @@ impl FunctionDefinition {
/// Gets the list of LLVM attributes provided in the function name.
pub fn get_llvm_attributes(
identifier: &Identifier,
) -> Result<BTreeSet<revive_llvm_context::EraVMAttribute>, Error> {
) -> Result<BTreeSet<revive_llvm_context::PolkaVMAttribute>, Error> {
let mut valid_attributes = BTreeSet::new();
let llvm_begin = identifier.inner.find(Self::LLVM_ATTRIBUTE_PREFIX);
@@ -198,7 +198,7 @@ impl FunctionDefinition {
let mut invalid_attributes = BTreeSet::new();
for value in attribute_string.split('_') {
match revive_llvm_context::EraVMAttribute::try_from(value) {
match revive_llvm_context::PolkaVMAttribute::try_from(value) {
Ok(attribute) => valid_attributes.insert(attribute),
Err(value) => invalid_attributes.insert(value),
};
@@ -216,13 +216,13 @@ impl FunctionDefinition {
}
}
impl<D> revive_llvm_context::EraVMWriteLLVM<D> for FunctionDefinition
impl<D> revive_llvm_context::PolkaVMWriteLLVM<D> for FunctionDefinition
where
D: revive_llvm_context::EraVMDependency + Clone,
D: revive_llvm_context::PolkaVMDependency + Clone,
{
fn declare(
&mut self,
context: &mut revive_llvm_context::EraVMContext<D>,
context: &mut revive_llvm_context::PolkaVMContext<D>,
) -> anyhow::Result<()> {
let argument_types: Vec<_> = self
.arguments
@@ -237,7 +237,7 @@ where
argument_types,
self.result.len(),
self.identifier
.starts_with(revive_llvm_context::EraVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX),
.starts_with(revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX),
);
let function = context.add_function(
@@ -246,7 +246,7 @@ where
self.result.len(),
Some(inkwell::module::Linkage::Private),
)?;
revive_llvm_context::EraVMFunction::set_attributes(
revive_llvm_context::PolkaVMFunction::set_attributes(
context.llvm(),
function.borrow().declaration(),
self.attributes.clone().into_iter().collect(),
@@ -254,22 +254,22 @@ where
);
function
.borrow_mut()
.set_yul_data(revive_llvm_context::EraVMFunctionYulData::default());
.set_yul_data(revive_llvm_context::PolkaVMFunctionYulData::default());
Ok(())
}
fn into_llvm(
mut self,
context: &mut revive_llvm_context::EraVMContext<D>,
context: &mut revive_llvm_context::PolkaVMContext<D>,
) -> anyhow::Result<()> {
context.set_current_function(self.identifier.as_str())?;
let r#return = context.current_function().borrow().r#return();
context.set_basic_block(context.current_function().borrow().entry_block());
match r#return {
revive_llvm_context::EraVMFunctionReturn::None => {}
revive_llvm_context::EraVMFunctionReturn::Primitive { pointer } => {
revive_llvm_context::PolkaVMFunctionReturn::None => {}
revive_llvm_context::PolkaVMFunctionReturn::Primitive { pointer } => {
let identifier = self.result.pop().expect("Always exists");
let r#type = identifier.r#type.unwrap_or_default();
context.build_store(pointer, r#type.into_llvm(context).const_zero())?;
@@ -278,7 +278,7 @@ where
.borrow_mut()
.insert_stack_pointer(identifier.inner, pointer);
}
revive_llvm_context::EraVMFunctionReturn::Compound { pointer, .. } => {
revive_llvm_context::PolkaVMFunctionReturn::Compound { pointer, .. } => {
for (index, identifier) in self.result.into_iter().enumerate() {
let r#type = identifier.r#type.unwrap_or_default().into_llvm(context);
let pointer = context.build_gep(
@@ -317,10 +317,10 @@ where
.insert_stack_pointer(argument.inner.clone(), pointer);
if self
.identifier
.starts_with(revive_llvm_context::EraVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX)
.starts_with(revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX)
&& matches!(
context.current_function().borrow().r#return(),
revive_llvm_context::EraVMFunctionReturn::Compound { .. }
revive_llvm_context::PolkaVMFunctionReturn::Compound { .. }
)
&& context.is_system_mode()
{
@@ -346,21 +346,21 @@ where
context.set_basic_block(context.current_function().borrow().return_block());
match context.current_function().borrow().r#return() {
revive_llvm_context::EraVMFunctionReturn::None => {
revive_llvm_context::PolkaVMFunctionReturn::None => {
context.build_return(None);
}
revive_llvm_context::EraVMFunctionReturn::Primitive { pointer } => {
revive_llvm_context::PolkaVMFunctionReturn::Primitive { pointer } => {
let return_value = context.build_load(pointer, "return_value")?;
context.build_return(Some(&return_value));
}
revive_llvm_context::EraVMFunctionReturn::Compound { pointer, .. }
revive_llvm_context::PolkaVMFunctionReturn::Compound { pointer, .. }
if context.current_function().borrow().name().starts_with(
revive_llvm_context::EraVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX,
revive_llvm_context::PolkaVMFunction::ZKSYNC_NEAR_CALL_ABI_PREFIX,
) =>
{
context.build_return(Some(&pointer.value));
}
revive_llvm_context::EraVMFunctionReturn::Compound { pointer, .. } => {
revive_llvm_context::PolkaVMFunctionReturn::Compound { pointer, .. } => {
let return_value = context.build_load(pointer, "return_value")?;
context.build_return(Some(&return_value));
}