mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-29 06:38:00 +00:00
Remove vyper and dead code (#23)
This commit is contained in:
@@ -7,7 +7,6 @@ pub mod intrinsics;
|
||||
pub mod llvm_runtime;
|
||||
pub mod r#return;
|
||||
pub mod runtime;
|
||||
pub mod vyper_data;
|
||||
pub mod yul_data;
|
||||
|
||||
use std::collections::HashMap;
|
||||
@@ -20,8 +19,6 @@ use crate::polkavm::context::pointer::Pointer;
|
||||
use self::declaration::Declaration;
|
||||
use self::evmla_data::EVMLAData;
|
||||
use self::r#return::Return;
|
||||
use self::runtime::Runtime;
|
||||
use self::vyper_data::VyperData;
|
||||
use self::yul_data::YulData;
|
||||
|
||||
/// The LLVM IR generator function.
|
||||
@@ -48,8 +45,6 @@ pub struct Function<'ctx> {
|
||||
yul_data: Option<YulData>,
|
||||
/// The EVM legacy assembly compiler data.
|
||||
evmla_data: Option<EVMLAData<'ctx>>,
|
||||
/// The Vyper data.
|
||||
vyper_data: Option<VyperData>,
|
||||
}
|
||||
|
||||
impl<'ctx> Function<'ctx> {
|
||||
@@ -82,7 +77,6 @@ impl<'ctx> Function<'ctx> {
|
||||
|
||||
yul_data: None,
|
||||
evmla_data: None,
|
||||
vyper_data: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,9 +89,9 @@ impl<'ctx> Function<'ctx> {
|
||||
pub fn is_name_external(name: &str) -> bool {
|
||||
name.starts_with("llvm.")
|
||||
|| (name.starts_with("__")
|
||||
&& name != Runtime::FUNCTION_ENTRY
|
||||
&& name != Runtime::FUNCTION_DEPLOY_CODE
|
||||
&& name != Runtime::FUNCTION_RUNTIME_CODE)
|
||||
&& name != self::runtime::FUNCTION_ENTRY
|
||||
&& name != self::runtime::FUNCTION_DEPLOY_CODE
|
||||
&& name != self::runtime::FUNCTION_RUNTIME_CODE)
|
||||
}
|
||||
|
||||
/// Checks whether the function is related to the near call ABI.
|
||||
@@ -330,29 +324,6 @@ impl<'ctx> Function<'ctx> {
|
||||
.expect("The EVM data must have been initialized")
|
||||
}
|
||||
|
||||
/// Sets the Vyper data.
|
||||
pub fn set_vyper_data(&mut self, data: VyperData) {
|
||||
self.vyper_data = Some(data);
|
||||
}
|
||||
|
||||
/// Returns the Vyper data reference.
|
||||
/// # Panics
|
||||
/// If the Vyper data has not been initialized.
|
||||
pub fn vyper(&self) -> &VyperData {
|
||||
self.vyper_data
|
||||
.as_ref()
|
||||
.expect("The Vyper data must have been initialized")
|
||||
}
|
||||
|
||||
/// Returns the Vyper data mutable reference.
|
||||
/// # Panics
|
||||
/// If the Vyper data has not been initialized.
|
||||
pub fn vyper_mut(&mut self) -> &mut VyperData {
|
||||
self.vyper_data
|
||||
.as_mut()
|
||||
.expect("The Vyper data must have been initialized")
|
||||
}
|
||||
|
||||
/// Sets the Yul data.
|
||||
pub fn set_yul_data(&mut self, data: YulData) {
|
||||
self.yul_data = Some(data);
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use crate::polkavm::context::address_space::AddressSpace;
|
||||
use crate::polkavm::context::code_type::CodeType;
|
||||
use crate::polkavm::context::function::runtime::Runtime;
|
||||
use crate::polkavm::context::pointer::Pointer;
|
||||
use crate::polkavm::context::function::runtime;
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
use crate::polkavm::WriteLLVM;
|
||||
@@ -47,7 +45,7 @@ where
|
||||
let function_type =
|
||||
context.function_type::<inkwell::types::BasicTypeEnum>(vec![], 0, false);
|
||||
context.add_function(
|
||||
Runtime::FUNCTION_DEPLOY_CODE,
|
||||
runtime::FUNCTION_DEPLOY_CODE,
|
||||
function_type,
|
||||
0,
|
||||
Some(inkwell::module::Linkage::External),
|
||||
@@ -57,26 +55,10 @@ where
|
||||
}
|
||||
|
||||
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
context.set_current_function(Runtime::FUNCTION_DEPLOY_CODE)?;
|
||||
context.set_current_function(runtime::FUNCTION_DEPLOY_CODE)?;
|
||||
|
||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||
context.set_code_type(CodeType::Deploy);
|
||||
if let Some(vyper) = context.vyper_data.as_ref() {
|
||||
for index in 0..vyper.immutables_size() / revive_common::BYTE_LENGTH_WORD {
|
||||
let offset = (crate::polkavm::r#const::HEAP_AUX_OFFSET_CONSTRUCTOR_RETURN_DATA
|
||||
as usize)
|
||||
+ (1 + index) * 2 * revive_common::BYTE_LENGTH_WORD;
|
||||
let value = index * revive_common::BYTE_LENGTH_WORD;
|
||||
let pointer = Pointer::new_with_offset(
|
||||
context,
|
||||
AddressSpace::HeapAuxiliary,
|
||||
context.word_type(),
|
||||
context.word_const(offset as u64),
|
||||
"immutable_index_initializer",
|
||||
);
|
||||
context.build_store(pointer, context.word_const(value as u64))?;
|
||||
}
|
||||
}
|
||||
|
||||
self.inner.into_llvm(context)?;
|
||||
match context
|
||||
|
||||
@@ -4,7 +4,7 @@ use inkwell::types::BasicType;
|
||||
use inkwell::values::BasicValue;
|
||||
|
||||
use crate::polkavm::context::address_space::AddressSpace;
|
||||
use crate::polkavm::context::function::runtime::Runtime;
|
||||
use crate::polkavm::context::function::runtime;
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::r#const::*;
|
||||
use crate::polkavm::Dependency;
|
||||
@@ -53,7 +53,7 @@ impl Entry {
|
||||
|
||||
context.set_global(
|
||||
crate::polkavm::GLOBAL_HEAP_MEMORY_POINTER,
|
||||
context.llvm().ptr_type(AddressSpace::Generic.into()),
|
||||
context.llvm().ptr_type(AddressSpace::Heap.into()),
|
||||
AddressSpace::Stack,
|
||||
context.xlen_type().get_undef(),
|
||||
);
|
||||
@@ -205,12 +205,12 @@ impl Entry {
|
||||
|
||||
let deploy_code = context
|
||||
.functions
|
||||
.get(Runtime::FUNCTION_DEPLOY_CODE)
|
||||
.get(runtime::FUNCTION_DEPLOY_CODE)
|
||||
.cloned()
|
||||
.ok_or_else(|| anyhow::anyhow!("Contract deploy code not found"))?;
|
||||
let runtime_code = context
|
||||
.functions
|
||||
.get(Runtime::FUNCTION_RUNTIME_CODE)
|
||||
.get(runtime::FUNCTION_RUNTIME_CODE)
|
||||
.cloned()
|
||||
.ok_or_else(|| anyhow::anyhow!("Contract runtime code not found"))?;
|
||||
|
||||
@@ -233,7 +233,7 @@ where
|
||||
fn declare(&mut self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
let entry_arguments = vec![context.bool_type().as_basic_type_enum()];
|
||||
let entry_function_type = context.function_type(entry_arguments, 0, false);
|
||||
context.add_function(Runtime::FUNCTION_ENTRY, entry_function_type, 0, None)?;
|
||||
context.add_function(runtime::FUNCTION_ENTRY, entry_function_type, 0, None)?;
|
||||
|
||||
for symbol in runtime_api::exports::EXPORTS {
|
||||
context.declare_extern_function(symbol)?;
|
||||
@@ -247,7 +247,7 @@ where
|
||||
/// The `entry` function loads calldata, sets globals and calls the runtime or deploy code.
|
||||
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
let entry = context
|
||||
.get_function(Runtime::FUNCTION_ENTRY)
|
||||
.get_function(runtime::FUNCTION_ENTRY)
|
||||
.expect("the entry function should already be declared")
|
||||
.borrow()
|
||||
.declaration;
|
||||
@@ -278,7 +278,7 @@ where
|
||||
context.set_basic_block(context.current_function().borrow().return_block);
|
||||
context.build_unreachable();
|
||||
|
||||
context.set_current_function(Runtime::FUNCTION_ENTRY)?;
|
||||
context.set_current_function(runtime::FUNCTION_ENTRY)?;
|
||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||
|
||||
Self::initialize_globals(context)?;
|
||||
|
||||
@@ -4,28 +4,11 @@ pub mod deploy_code;
|
||||
pub mod entry;
|
||||
pub mod runtime_code;
|
||||
|
||||
use crate::polkavm::context::address_space::AddressSpace;
|
||||
/// The main entry function name.
|
||||
pub const FUNCTION_ENTRY: &str = "__entry";
|
||||
|
||||
/// The front-end runtime functions.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Runtime {
|
||||
/// The address space where the calldata is allocated.
|
||||
/// Solidity uses the ordinary heap. Vyper uses the auxiliary heap.
|
||||
_address_space: AddressSpace,
|
||||
}
|
||||
/// The deploy code function name.
|
||||
pub const FUNCTION_DEPLOY_CODE: &str = "__deploy";
|
||||
|
||||
impl Runtime {
|
||||
/// The main entry function name.
|
||||
pub const FUNCTION_ENTRY: &'static str = "__entry";
|
||||
|
||||
/// The deploy code function name.
|
||||
pub const FUNCTION_DEPLOY_CODE: &'static str = "__deploy";
|
||||
|
||||
/// The runtime code function name.
|
||||
pub const FUNCTION_RUNTIME_CODE: &'static str = "__runtime";
|
||||
|
||||
/// A shortcut constructor.
|
||||
pub fn new(_address_space: AddressSpace) -> Self {
|
||||
Self { _address_space }
|
||||
}
|
||||
}
|
||||
/// The runtime code function name.
|
||||
pub const FUNCTION_RUNTIME_CODE: &str = "__runtime";
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use crate::polkavm::context::code_type::CodeType;
|
||||
use crate::polkavm::context::function::runtime::Runtime;
|
||||
use crate::polkavm::context::function::runtime;
|
||||
use crate::polkavm::context::Context;
|
||||
use crate::polkavm::Dependency;
|
||||
use crate::polkavm::WriteLLVM;
|
||||
@@ -45,7 +45,7 @@ where
|
||||
let function_type =
|
||||
context.function_type::<inkwell::types::BasicTypeEnum>(vec![], 0, false);
|
||||
context.add_function(
|
||||
Runtime::FUNCTION_RUNTIME_CODE,
|
||||
runtime::FUNCTION_RUNTIME_CODE,
|
||||
function_type,
|
||||
0,
|
||||
Some(inkwell::module::Linkage::External),
|
||||
@@ -55,7 +55,7 @@ where
|
||||
}
|
||||
|
||||
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||
context.set_current_function(Runtime::FUNCTION_RUNTIME_CODE)?;
|
||||
context.set_current_function(runtime::FUNCTION_RUNTIME_CODE)?;
|
||||
|
||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||
context.set_code_type(CodeType::Runtime);
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
//! The LLVM function Vyper data.
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// The LLVM function Vyper data.
|
||||
/// Describes some data that is only relevant to Vyper.
|
||||
#[derive(Debug)]
|
||||
pub struct VyperData {
|
||||
/// The block-local variables. They are still allocated at the beginning of the function,
|
||||
/// but their parent block must be known in order to pass the implicit arguments thereto.
|
||||
/// Is only used by the Vyper LLL IR compiler.
|
||||
label_arguments: HashMap<String, Vec<String>>,
|
||||
}
|
||||
|
||||
impl Default for VyperData {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
label_arguments: HashMap::with_capacity(Self::LABEL_ARGUMENTS_HASHMAP_INITIAL_CAPACITY),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl VyperData {
|
||||
/// The label arguments hashmap default capacity.
|
||||
const LABEL_ARGUMENTS_HASHMAP_INITIAL_CAPACITY: usize = 16;
|
||||
|
||||
/// A shortcut constructor.
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Returns the list of a Vyper label arguments.
|
||||
pub fn label_arguments(&self, label_name: &str) -> Option<Vec<String>> {
|
||||
self.label_arguments.get(label_name).cloned()
|
||||
}
|
||||
|
||||
/// Inserts arguments for the specified label.
|
||||
pub fn insert_label_arguments(&mut self, label_name: String, arguments: Vec<String>) {
|
||||
self.label_arguments.insert(label_name, arguments);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user