Skip to content

Commit

Permalink
chore: move code segment to era-compiler-common
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgar2017 committed Nov 1, 2024
1 parent 4b5306b commit 5049b0a
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 55 deletions.
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
30 changes: 15 additions & 15 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ hex = "=0.4.3"

zkevm_opcode_defs = "=0.150.6"

era-compiler-common = { git = "https://github.com/matter-labs/era-compiler-common", branch = "main" }
era-compiler-llvm-context = { git = "https://github.com/matter-labs/era-compiler-llvm-context", branch = "main" }
era-compiler-common = { git = "https://github.com/matter-labs/era-compiler-common", branch = "az-move-code-segment" }
era-compiler-llvm-context = { git = "https://github.com/matter-labs/era-compiler-llvm-context", branch = "az-move-code-segment" }

[dev-dependencies]
assert_cmd = "=2.0.16"
Expand Down
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

0 comments on commit 5049b0a

Please sign in to comment.