Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move code segment to era-compiler-common #123

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# The `zkvyper` changelog

## [Unreleased]

### Changed

- Updated to Rust v1.82.0

## [1.5.7] - 2024-10-31

### Added
Expand Down
32 changes: 16 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
profile = "default"
channel = "1.80.1"
channel = "1.82.0"
40 changes: 20 additions & 20 deletions src/project/contract/vyper/expression/instruction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,13 +1076,13 @@ impl Instruction {
let arguments = Self::translate_arguments_llvm::<D, 1>(arguments, context)?;

match context
.code_type()
.code_segment()
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{
era_compiler_llvm_context::CodeType::Deploy => {
era_compiler_common::CodeSegment::Deploy => {
Ok(Some(context.field_const(0).as_basic_value_enum()))
}
era_compiler_llvm_context::CodeType::Runtime => {
era_compiler_common::CodeSegment::Runtime => {
era_compiler_llvm_context::eravm_evm_calldata::load(
context,
arguments[0].into_int_value(),
Expand All @@ -1093,13 +1093,13 @@ impl Instruction {
}
Self::CALLDATASIZE => {
match context
.code_type()
.code_segment()
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{
era_compiler_llvm_context::CodeType::Deploy => {
era_compiler_common::CodeSegment::Deploy => {
Ok(Some(context.field_const(0).as_basic_value_enum()))
}
era_compiler_llvm_context::CodeType::Runtime => {
era_compiler_common::CodeSegment::Runtime => {
era_compiler_llvm_context::eravm_evm_calldata::size(context).map(Some)
}
}
Expand All @@ -1108,13 +1108,13 @@ impl Instruction {
let arguments = Self::translate_arguments_llvm::<D, 3>(arguments, context)?;

let source_offset = match context
.code_type()
.code_segment()
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{
era_compiler_llvm_context::CodeType::Deploy => {
era_compiler_common::CodeSegment::Deploy => {
era_compiler_llvm_context::eravm_evm_calldata::size(context)?
}
era_compiler_llvm_context::CodeType::Runtime => {
era_compiler_common::CodeSegment::Runtime => {
arguments[1].into_int_value().as_basic_value_enum()
}
}
Expand All @@ -1132,17 +1132,17 @@ impl Instruction {
Self::DLOAD(arguments) => {
let arguments = Self::translate_arguments_llvm::<D, 1>(arguments, context)?;

match context.code_type() {
match context.code_segment() {
None => {
panic!("code part is undefined");
}
Some(era_compiler_llvm_context::CodeType::Deploy) => {
Some(era_compiler_common::CodeSegment::Deploy) => {
era_compiler_llvm_context::eravm_evm_calldata::load(
context,
arguments[0].into_int_value(),
)
}
Some(era_compiler_llvm_context::CodeType::Runtime) => {
Some(era_compiler_common::CodeSegment::Runtime) => {
era_compiler_llvm_context::eravm_evm_immutable::load(
context,
arguments[0].into_int_value(),
Expand All @@ -1154,21 +1154,21 @@ impl Instruction {
Self::DLOADBYTES(arguments) => {
let arguments = Self::translate_arguments_llvm::<D, 3>(arguments, context)?;

match context.code_type() {
match context.code_segment() {
None => {
anyhow::bail!(
"Immutables are not available if the contract part is undefined"
);
}
Some(era_compiler_llvm_context::CodeType::Deploy) => {
Some(era_compiler_common::CodeSegment::Deploy) => {
era_compiler_llvm_context::eravm_evm_calldata::copy(
context,
arguments[0].into_int_value(),
arguments[1].into_int_value(),
arguments[2].into_int_value(),
)
}
Some(era_compiler_llvm_context::CodeType::Runtime) => immutable::load_bytes(
Some(era_compiler_common::CodeSegment::Runtime) => immutable::load_bytes(
context,
arguments[0].into_int_value(),
arguments[1].into_int_value(),
Expand All @@ -1180,13 +1180,13 @@ impl Instruction {

Self::CODESIZE => {
match context
.code_type()
.code_segment()
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{
era_compiler_llvm_context::CodeType::Deploy => {
era_compiler_common::CodeSegment::Deploy => {
era_compiler_llvm_context::eravm_evm_calldata::size(context).map(Some)
}
era_compiler_llvm_context::CodeType::Runtime => {
era_compiler_common::CodeSegment::Runtime => {
let code_source =
era_compiler_llvm_context::eravm_general::code_source(context)?;
era_compiler_llvm_context::eravm_evm_ext_code::size(
Expand All @@ -1198,8 +1198,8 @@ impl Instruction {
}
}
Self::CODECOPY(arguments) => {
if let era_compiler_llvm_context::CodeType::Runtime = context
.code_type()
if let era_compiler_common::CodeSegment::Runtime = context
.code_segment()
.ok_or_else(|| anyhow::anyhow!("The contract code part type is undefined"))?
{
anyhow::bail!(
Expand Down
26 changes: 9 additions & 17 deletions src/project/contract/vyper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,39 +324,31 @@ where
.extract_functions()?
.into_iter()
.map(|(label, expression)| {
(
label,
expression,
era_compiler_llvm_context::CodeType::Deploy,
)
(label, expression, era_compiler_common::CodeSegment::Deploy)
})
.collect::<Vec<(String, Expression, era_compiler_llvm_context::CodeType)>>();
.collect::<Vec<(String, Expression, era_compiler_common::CodeSegment)>>();
function_expressions.extend(
runtime_code
.extract_functions()?
.into_iter()
.map(|(label, expression)| {
(
label,
expression,
era_compiler_llvm_context::CodeType::Runtime,
)
(label, expression, era_compiler_common::CodeSegment::Runtime)
})
.collect::<Vec<(String, Expression, era_compiler_llvm_context::CodeType)>>(),
.collect::<Vec<(String, Expression, era_compiler_common::CodeSegment)>>(),
);

let mut functions = Vec::with_capacity(function_expressions.capacity());
for (label, expression, code_type) in function_expressions.into_iter() {
for (label, expression, code_segment) in function_expressions.into_iter() {
functions.push((
Function::new(Expression::safe_label(label.as_str()), expression),
code_type,
code_segment,
));
}
for (function, _code_type) in functions.iter_mut() {
for (function, _code_segment) in functions.iter_mut() {
function.declare(context)?;
}
for (function, code_type) in functions.into_iter() {
context.set_code_type(code_type);
for (function, code_segment) in functions.into_iter() {
context.set_code_segment(code_segment);
function.into_llvm(context)?;
}

Expand Down