Compare commits

..

15 Commits

Author SHA1 Message Date
Alexander Samusev 9ddddc989d Merge branch 'main' into as-release-json 2025-04-07 13:24:07 +02:00
alvicsam 5992ad0043 nit 2025-04-07 13:11:09 +02:00
alvicsam 2fd96f6188 updated release.md 2025-04-07 11:18:19 +02:00
alvicsam 06d324259c revert mimalloc to * 2025-04-04 14:24:47 +02:00
alvicsam 7669320e31 downgrade lockfile 2025-04-04 13:04:58 +02:00
alvicsam ea0ff27c6f use --locked 2025-04-04 12:52:24 +02:00
alvicsam 60e41a9210 upd cargo.lock 2025-04-04 12:47:49 +02:00
alvicsam 0089d58d85 downgrade mimalloc crate 2025-04-04 12:37:43 +02:00
Alexander Samusev 09c8f64eef Merge branch 'main' into as-release-json 2025-04-04 11:20:14 +02:00
alvicsam 4e6c562fac rename the releaseworkflow 2025-04-04 11:17:26 +02:00
alvicsam 12a8685f11 fix notice 2025-04-04 11:14:08 +02:00
alvicsam ce1766dc64 skip check in PRs 2025-04-04 11:11:05 +02:00
alvicsam 2c1097ef36 rm my ref from workflow 2025-04-04 10:46:05 +02:00
alvicsam a5ad9a917a add environment to generate_versions 2025-04-04 10:39:33 +02:00
alvicsam c929dc9b03 ci: update release flow and publish list.json 2025-04-03 15:32:26 +02:00
30 changed files with 297 additions and 557 deletions
+9 -55
View File
@@ -2,6 +2,7 @@ import os
import sys
import json
import requests
from datetime import datetime
def validate_github_token():
"""Validate that GITHUB_TOKEN environment variable is set."""
@@ -26,70 +27,26 @@ def fetch_release_data(repo, tag):
print(f"Error fetching release data: {e}")
sys.exit(1)
def fetch_checksum_file(release_data):
"""
Fetch the checksum.txt file from the release assets
and parse it into a dictionary mapping file names to their SHA256 checksums.
"""
checksums = {}
# Find the checksum.txt asset URL
checksum_asset = None
for asset in release_data['assets']:
if asset['name'] == 'checksums.txt':
checksum_asset = asset
break
if not checksum_asset:
print("Warning: checksum.txt file not found in release assets.")
return checksums
# Download the checksum file
headers = {
'Authorization': f"Bearer {os.environ['GITHUB_TOKEN']}",
'Accept': 'application/octet-stream'
}
try:
response = requests.get(checksum_asset['browser_download_url'], headers=headers)
response.raise_for_status()
# Parse checksum file
for line in response.text.splitlines():
if line.strip():
checksum, filename = line.strip().split(None, 1)
checksums[filename] = checksum
return checksums
except requests.RequestException as e:
print(f"Error fetching checksum file: {e}")
return checksums
except Exception as e:
print(f"Error parsing checksum file: {e}")
return checksums
def extract_build_hash(target_commitish):
"""Extract the first 8 characters of the commit hash."""
return f"commit.{target_commitish[:8]}"
def generate_asset_json(release_data, asset, checksums):
def generate_asset_json(release_data, asset):
"""Generate JSON for a specific asset."""
version = release_data['tag_name'].lstrip('v')
build = extract_build_hash(release_data['target_commitish'])
long_version = f"{version}+{build}"
# Get SHA256 checksum if available
sha256 = checksums.get(asset['name'], "")
path = f"{asset['name']}+{long_version}"
return {
"path": path,
"name": asset['name'],
"version": version,
"build": build,
"longVersion": long_version,
"url": asset['browser_download_url'],
"sha256": sha256,
"firstSolcVersion": os.environ.get("FIRST_SOLC_VERSION", ""),
"lastSolcVersion": os.environ.get("LAST_SOLC_VERSION", "")
"firstSolcVersion": os.environ["FIRST_SOLC_VERSION"],
"lastSolcVersion": os.environ["LAST_SOLC_VERSION"]
}
def save_platform_json(platform_folder, asset_json, tag):
@@ -112,14 +69,14 @@ def save_platform_json(platform_folder, asset_json, tag):
# Remove any existing entry with the same path
list_data['builds'] = [
build for build in list_data['builds']
if build['version'] != asset_json['version']
if build['path'] != asset_json['path']
]
# Add the new build
list_data['builds'].append(asset_json)
# Update releases
version = asset_json['version']
list_data['releases'][version] = f"{asset_json['name']}+{asset_json['longVersion']}"
list_data['releases'][version] = asset_json['path']
# Update latest release
list_data['latestRelease'] = version
@@ -141,9 +98,6 @@ def main():
# Fetch release data
release_data = fetch_release_data(repo, tag)
# Fetch checksums
checksums = fetch_checksum_file(release_data)
# Mapping of asset names to platform folders
platform_mapping = {
'resolc-x86_64-unknown-linux-musl': 'linux',
@@ -157,7 +111,7 @@ def main():
platform_name = platform_mapping.get(asset['name'])
if platform_name:
platform_folder = os.path.join(platform_name)
asset_json = generate_asset_json(release_data, asset, checksums)
asset_json = generate_asset_json(release_data, asset)
save_platform_json(platform_folder, asset_json, tag)
print(f"Processed {asset['name']} for {platform_name}")
-10
View File
@@ -249,15 +249,6 @@ jobs:
chmod +x resolc-x86_64-unknown-linux-musl
chmod +x resolc-universal-apple-darwin
- name: Create sha-256 checksum
run: |
shasum -a 256 resolc-x86_64-unknown-linux-musl > checksums.txt
shasum -a 256 resolc-universal-apple-darwin >> checksums.txt
shasum -a 256 resolc-x86_64-pc-windows-msvc.exe >> checksums.txt
shasum -a 256 resolc.js >> checksums.txt
shasum -a 256 resolc.wasm >> checksums.txt
shasum -a 256 resolc_web.js >> checksums.txt
- uses: actions/create-github-app-token@v1
id: app-token
with:
@@ -285,4 +276,3 @@ jobs:
resolc.js
resolc.wasm
resolc_web.js
checksums.txt
+1 -14
View File
@@ -6,19 +6,6 @@ This is a development pre-release.
Supported `polkadot-sdk` rev:`c29e72a8628835e34deb6aa7db9a78a2e4eabcee`
### Added
### Changed
### Fixed
- Constructors avoid storing zero sized immutable data on exit.
## v0.1.0-dev.13
This is a development pre-release.
Supported `polkadot-sdk` rev:`c29e72a8628835e34deb6aa7db9a78a2e4eabcee`
### Added
- Support for solc v0.8.29
- Decouples the solc JSON-input-output type definitions from the Solidity fronted and expose them via a dedicated crate.
@@ -27,7 +14,7 @@ Supported `polkadot-sdk` rev:`c29e72a8628835e34deb6aa7db9a78a2e4eabcee`
### Changed
- Storage keys and values are big endian. This was a pre-mature optimization because for the contract itself it this is a no-op and thus not observable. However we should consider the storage layout as part of the contract ABI. The endianness of transient storage values are still kept as-is.
- Running `resolc` using webkit is no longer supported.
- Runner `resolc` using webkit is no longer supported.
### Fixed
- A missing byte swap for the create2 salt value.
Generated
+17 -17
View File
@@ -4553,7 +4553,7 @@ checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104"
[[package]]
name = "lld-sys"
version = "0.1.0-dev.13"
version = "0.1.0-dev.12"
dependencies = [
"cc",
"libc",
@@ -8266,7 +8266,7 @@ dependencies = [
[[package]]
name = "revive-benchmarks"
version = "0.1.0-dev.13"
version = "0.1.0-dev.12"
dependencies = [
"alloy-primitives",
"criterion",
@@ -8278,18 +8278,18 @@ dependencies = [
[[package]]
name = "revive-build-utils"
version = "0.1.0-dev.13"
version = "0.1.0-dev.12"
[[package]]
name = "revive-builtins"
version = "0.1.0-dev.13"
version = "0.1.0-dev.12"
dependencies = [
"revive-build-utils",
]
[[package]]
name = "revive-common"
version = "0.1.0-dev.13"
version = "0.1.0-dev.12"
dependencies = [
"anyhow",
"serde",
@@ -8299,7 +8299,7 @@ dependencies = [
[[package]]
name = "revive-differential"
version = "0.1.0-dev.13"
version = "0.1.0-dev.12"
dependencies = [
"alloy-genesis",
"alloy-primitives",
@@ -8312,7 +8312,7 @@ dependencies = [
[[package]]
name = "revive-integration"
version = "0.1.0-dev.13"
version = "0.1.0-dev.12"
dependencies = [
"alloy-primitives",
"alloy-sol-types",
@@ -8328,7 +8328,7 @@ dependencies = [
[[package]]
name = "revive-linker"
version = "0.1.0-dev.13"
version = "0.1.0-dev.12"
dependencies = [
"anyhow",
"libc",
@@ -8340,7 +8340,7 @@ dependencies = [
[[package]]
name = "revive-llvm-builder"
version = "0.1.0-dev.13"
version = "0.1.0-dev.12"
dependencies = [
"anyhow",
"assert_cmd",
@@ -8362,7 +8362,7 @@ dependencies = [
[[package]]
name = "revive-llvm-context"
version = "0.1.0-dev.13"
version = "0.1.0-dev.12"
dependencies = [
"anyhow",
"hex",
@@ -8384,7 +8384,7 @@ dependencies = [
[[package]]
name = "revive-runner"
version = "0.1.0-dev.13"
version = "0.1.0-dev.12"
dependencies = [
"alloy-primitives",
"hex",
@@ -8400,7 +8400,7 @@ dependencies = [
[[package]]
name = "revive-runtime-api"
version = "0.1.0-dev.13"
version = "0.1.0-dev.12"
dependencies = [
"anyhow",
"inkwell",
@@ -8410,7 +8410,7 @@ dependencies = [
[[package]]
name = "revive-solc-json-interface"
version = "0.1.0-dev.13"
version = "0.1.0-dev.12"
dependencies = [
"anyhow",
"rayon",
@@ -8422,7 +8422,7 @@ dependencies = [
[[package]]
name = "revive-solidity"
version = "0.1.0-dev.13"
version = "0.1.0-dev.12"
dependencies = [
"anyhow",
"clap",
@@ -8449,7 +8449,7 @@ dependencies = [
[[package]]
name = "revive-stdlib"
version = "0.1.0-dev.13"
version = "0.1.0-dev.12"
dependencies = [
"inkwell",
"revive-build-utils",
@@ -11117,9 +11117,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.44.2"
version = "1.43.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6b88822cbe49de4185e3a4cbf8321dd487cf5fe0c5c65695fef6346371e9c48"
checksum = "3d61fa4ffa3de412bfea335c6ecff681de2b609ba3c77ef3e00e521813a9ed9e"
dependencies = [
"backtrace",
"bytes",
+15 -15
View File
@@ -3,7 +3,7 @@ resolver = "2"
members = ["crates/*"]
[workspace.package]
version = "0.1.0-dev.13"
version = "0.1.0-dev.12"
authors = [
"Cyrill Leutwiler <cyrill@parity.io>",
"Parity Technologies <admin@parity.io>",
@@ -14,20 +14,20 @@ repository = "https://github.com/paritytech/revive"
rust-version = "1.81.0"
[workspace.dependencies]
revive-benchmarks = { version = "0.1.0-dev.13", path = "crates/benchmarks" }
revive-builtins = { version = "0.1.0-dev.13", path = "crates/builtins" }
revive-common = { version = "0.1.0-dev.13", path = "crates/common" }
revive-differential = { version = "0.1.0-dev.13", path = "crates/differential" }
revive-integration = { version = "0.1.0-dev.13", path = "crates/integration" }
revive-linker = { version = "0.1.0-dev.13", path = "crates/linker" }
lld-sys = { version = "0.1.0-dev.13", path = "crates/lld-sys" }
revive-llvm-context = { version = "0.1.0-dev.13", path = "crates/llvm-context" }
revive-runtime-api = { version = "0.1.0-dev.13", path = "crates/runtime-api" }
revive-runner = { version = "0.1.0-dev.13", path = "crates/runner" }
revive-solc-json-interface = { version = "0.1.0-dev.13", path = "crates/solc-json-interface" }
revive-solidity = { version = "0.1.0-dev.13", path = "crates/solidity" }
revive-stdlib = { version = "0.1.0-dev.13", path = "crates/stdlib" }
revive-build-utils = { version = "0.1.0-dev.13", path = "crates/build-utils" }
revive-benchmarks = { version = "0.1.0-dev.12", path = "crates/benchmarks" }
revive-builtins = { version = "0.1.0-dev.12", path = "crates/builtins" }
revive-common = { version = "0.1.0-dev.12", path = "crates/common" }
revive-differential = { version = "0.1.0-dev.12", path = "crates/differential" }
revive-integration = { version = "0.1.0-dev.12", path = "crates/integration" }
revive-linker = { version = "0.1.0-dev.12", path = "crates/linker" }
lld-sys = { version = "0.1.0-dev.12", path = "crates/lld-sys" }
revive-llvm-context = { version = "0.1.0-dev.12", path = "crates/llvm-context" }
revive-runtime-api = { version = "0.1.0-dev.12", path = "crates/runtime-api" }
revive-runner = { version = "0.1.0-dev.12", path = "crates/runner" }
revive-solc-json-interface = { version = "0.1.0-dev.12", path = "crates/solc-json-interface" }
revive-solidity = { version = "0.1.0-dev.12", path = "crates/solidity" }
revive-stdlib = { version = "0.1.0-dev.12", path = "crates/stdlib" }
revive-build-utils = { version = "0.1.0-dev.12", path = "crates/build-utils" }
hex = "0.4.3"
cc = "1.2"
+1 -1
View File
@@ -11,7 +11,7 @@ RUN make install-llvm-builder
RUN revive-llvm --target-env musl clone
RUN revive-llvm --target-env musl build --llvm-projects lld --llvm-projects clang
FROM messense/rust-musl-cross@sha256:68b86bc7cb2867259e6b233415a665ff4469c28b57763e78c3bfea1c68091561 AS resolc-builder
FROM messense/rust-musl-cross:x86_64-musl AS resolc-builder
WORKDIR /opt/revive
RUN apt update && \
+24 -24
View File
@@ -15,58 +15,58 @@
### Baseline
| | `EVM` | `PVMInterpreter` |
|:--------|:-------------------------|:-------------------------------- |
| **`0`** | `10.08 us` (✅ **1.00x**) | `10.32 us` (**1.02x slower**) |
| | `EVM` | `PVMInterpreter` |
|:--------|:------------------------|:-------------------------------- |
| **`0`** | `3.36 us` (✅ **1.00x**) | `11.84 us` (*3.52x slower*) |
### OddPorduct
| | `EVM` | `PVMInterpreter` |
|:-------------|:--------------------------|:-------------------------------- |
| **`10000`** | `3.60 ms` (✅ **1.00x**) | `1.57 ms` (🚀 **2.28x faster**) |
| **`100000`** | `34.72 ms` (✅ **1.00x**) | `14.82 ms` (🚀 **2.34x faster**) |
| **`300000`** | `105.01 ms` (✅ **1.00x**) | `44.11 ms` (🚀 **2.38x faster**) |
| | `EVM` | `PVMInterpreter` |
|:-------------|:-------------------------|:-------------------------------- |
| **`10000`** | `3.11 ms` (✅ **1.00x**) | `1.53 ms` (🚀 **2.03x faster**) |
| **`100000`** | `30.70 ms` (✅ **1.00x**) | `15.54 ms` (🚀 **1.98x faster**) |
| **`300000`** | `92.68 ms` (✅ **1.00x**) | `45.47 ms` (🚀 **2.04x faster**) |
### TriangleNumber
| | `EVM` | `PVMInterpreter` |
|:-------------|:-------------------------|:-------------------------------- |
| **`10000`** | `2.43 ms` (✅ **1.00x**) | `1.12 ms` (🚀 **2.17x faster**) |
| **`100000`** | `24.20 ms` (✅ **1.00x**) | `10.86 ms` (🚀 **2.23x faster**) |
| **`360000`** | `88.69 ms` (✅ **1.00x**) | `38.46 ms` (🚀 **2.31x faster**) |
| **`10000`** | `2.29 ms` (✅ **1.00x**) | `1.09 ms` (🚀 **2.11x faster**) |
| **`100000`** | `22.84 ms` (✅ **1.00x**) | `10.66 ms` (🚀 **2.14x faster**) |
| **`360000`** | `82.29 ms` (✅ **1.00x**) | `37.01 ms` (🚀 **2.22x faster**) |
### FibonacciRecursive
| | `EVM` | `PVMInterpreter` |
|:---------|:--------------------------|:--------------------------------- |
| **`12`** | `144.17 us` (✅ **1.00x**) | `150.85 us` (✅ **1.05x slower**) |
| **`16`** | `938.71 us` (✅ **1.00x**) | `922.11 us` (✅ **1.02x faster**) |
| **`20`** | `6.54 ms` (✅ **1.00x**) | `6.20 ms` (✅ **1.05x faster**) |
| **`24`** | `45.73 ms` (✅ **1.00x**) | `41.98 ms` (✅ **1.09x faster**) |
| **`12`** | `135.67 us` (✅ **1.00x**) | `125.02 us` (✅ **1.09x faster**) |
| **`16`** | `903.75 us` (✅ **1.00x**) | `762.79 us` (✅ **1.18x faster**) |
| **`20`** | `6.12 ms` (✅ **1.00x**) | `4.96 ms` (✅ **1.23x faster**) |
| **`24`** | `42.05 ms` (✅ **1.00x**) | `33.86 ms` (✅ **1.24x faster**) |
### FibonacciIterative
| | `EVM` | `PVMInterpreter` |
|:----------|:-------------------------|:-------------------------------- |
| **`64`** | `23.00 us` (✅ **1.00x**) | `31.88 us` (❌ *1.39x slower*) |
| **`128`** | `35.28 us` (✅ **1.00x**) | `42.43 us` (❌ *1.20x slower*) |
| **`256`** | `60.12 us` (✅ **1.00x**) | `61.20 us` (**1.02x slower**) |
| **`64`** | `15.04 us` (✅ **1.00x**) | `29.45 us` (❌ *1.96x slower*) |
| **`128`** | `26.36 us` (✅ **1.00x**) | `42.19 us` (❌ *1.60x slower*) |
| **`256`** | `48.61 us` (✅ **1.00x**) | `65.71 us` (*1.35x slower*) |
### FibonacciBinet
| | `EVM` | `PVMInterpreter` |
|:----------|:-------------------------|:-------------------------------- |
| **`64`** | `23.01 us` (✅ **1.00x**) | `47.74 us` (❌ *2.07x slower*) |
| **`128`** | `25.44 us` (✅ **1.00x**) | `49.67 us` (❌ *1.95x slower*) |
| **`256`** | `28.66 us` (✅ **1.00x**) | `53.01 us` (❌ *1.85x slower*) |
| **`64`** | `15.22 us` (✅ **1.00x**) | `41.46 us` (❌ *2.72x slower*) |
| **`128`** | `17.05 us` (✅ **1.00x**) | `42.84 us` (❌ *2.51x slower*) |
| **`256`** | `19.00 us` (✅ **1.00x**) | `44.36 us` (❌ *2.34x slower*) |
### SHA1
| | `EVM` | `PVMInterpreter` |
|:----------|:--------------------------|:--------------------------------- |
| **`1`** | `135.87 us` (✅ **1.00x**) | `243.75 us` (❌ *1.79x slower*) |
| **`64`** | `258.45 us` (✅ **1.00x**) | `355.70 us` (❌ *1.38x slower*) |
| **`512`** | `1.10 ms` (✅ **1.00x**) | `1.09 ms` (✅ **1.01x faster**) |
| **`1`** | `110.04 us` (✅ **1.00x**) | `216.11 us` (❌ *1.96x slower*) |
| **`64`** | `209.04 us` (✅ **1.00x**) | `309.48 us` (❌ *1.48x slower*) |
| **`512`** | `903.65 us` (✅ **1.00x**) | `980.49 us` (✅ **1.09x slower**) |
---
Made with [criterion-table](https://github.com/nu11ptr/criterion-table)
+8 -8
View File
@@ -1,10 +1,10 @@
{
"Baseline": 950,
"Computation": 2262,
"DivisionArithmetics": 8915,
"ERC20": 17233,
"Events": 1628,
"FibonacciIterative": 1485,
"Flipper": 2132,
"SHA1": 8381
"Baseline": 1443,
"Computation": 2788,
"DivisionArithmetics": 9748,
"ERC20": 19150,
"Events": 2201,
"FibonacciIterative": 2041,
"Flipper": 2691,
"SHA1": 8997
}
@@ -9,9 +9,6 @@ pub static XLEN: usize = revive_common::BIT_LENGTH_X32;
/// The calldata size global variable name.
pub static GLOBAL_CALLDATA_SIZE: &str = "calldatasize";
/// The spill buffer global variable name.
pub static GLOBAL_ADDRESS_SPILL_BUFFER: &str = "address_spill_buffer";
/// The deployer call header size that consists of:
/// - bytecode hash (32 bytes)
pub const DEPLOYER_CALL_HEADER_SIZE: usize = revive_common::BYTE_LENGTH_WORD;
@@ -4,98 +4,61 @@
#[derive(Debug, Clone)]
pub struct Argument<'ctx> {
/// The actual LLVM operand.
pub value: Value<'ctx>,
pub value: inkwell::values::BasicValueEnum<'ctx>,
/// The original AST value. Used mostly for string literals.
pub original: Option<String>,
/// The preserved constant value, if available.
pub constant: Option<num::BigUint>,
}
/// The function argument can be either a pointer or a integer value.
/// This disambiguation allows for lazy loading of variables.
#[derive(Clone, Debug)]
pub enum Value<'ctx> {
Register(inkwell::values::BasicValueEnum<'ctx>),
Pointer {
pointer: crate::polkavm::context::Pointer<'ctx>,
id: String,
},
}
impl<'ctx> Argument<'ctx> {
/// A shortcut constructor for register arguments.
pub fn value(value: inkwell::values::BasicValueEnum<'ctx>) -> Self {
/// The calldata offset argument index.
pub const ARGUMENT_INDEX_CALLDATA_OFFSET: usize = 0;
/// The calldata length argument index.
pub const ARGUMENT_INDEX_CALLDATA_LENGTH: usize = 1;
/// A shortcut constructor.
pub fn new(value: inkwell::values::BasicValueEnum<'ctx>) -> Self {
Self {
value: Value::Register(value),
value,
original: None,
constant: None,
}
}
/// A shortcut constructor for stack arguments.
pub fn pointer(pointer: crate::polkavm::context::Pointer<'ctx>, id: String) -> Self {
/// A shortcut constructor.
pub fn new_with_original(
value: inkwell::values::BasicValueEnum<'ctx>,
original: String,
) -> Self {
Self {
value: Value::Pointer { pointer, id },
original: None,
value,
original: Some(original),
constant: None,
}
}
/// Set the original decleratation value.
pub fn with_original(mut self, original: String) -> Self {
self.original = Some(original);
self
}
/// Set the constant value.
pub fn with_constant(mut self, constant: num::BigUint) -> Self {
self.constant = Some(constant);
self
/// A shortcut constructor.
pub fn new_with_constant(
value: inkwell::values::BasicValueEnum<'ctx>,
constant: num::BigUint,
) -> Self {
Self {
value,
original: None,
constant: Some(constant),
}
}
/// Returns the inner LLVM value.
///
/// Panics if `self` is a pointer argument.
pub fn _to_llvm_value(&self) -> inkwell::values::BasicValueEnum<'ctx> {
match &self.value {
Value::Register(value) => *value,
Value::Pointer { .. } => unreachable!("invalid register value access"),
}
}
/// Access the underlying value.
///
/// Will emit a stack load if `self` is a pointer argument.
pub fn access<D: crate::polkavm::Dependency + Clone>(
&self,
context: &crate::polkavm::context::Context<'ctx, D>,
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> {
match &self.value {
Value::Register(value) => Ok(*value),
Value::Pointer { pointer, id } => context.build_load(*pointer, id),
}
}
/// Access the underlying value.
///
/// Will emit a stack load if `self` is a pointer argument.
pub fn as_pointer<D: crate::polkavm::Dependency + Clone>(
&self,
context: &crate::polkavm::context::Context<'ctx, D>,
) -> anyhow::Result<crate::polkavm::context::Pointer<'ctx>> {
match &self.value {
Value::Register(value) => {
let pointer = context.build_alloca_at_entry(context.word_type(), "pvm_arg");
context.build_store(pointer, *value)?;
Ok(pointer)
}
Value::Pointer { pointer, .. } => Ok(*pointer),
}
pub fn to_llvm(&self) -> inkwell::values::BasicValueEnum<'ctx> {
self.value
}
}
impl<'ctx> From<inkwell::values::BasicValueEnum<'ctx>> for Argument<'ctx> {
fn from(value: inkwell::values::BasicValueEnum<'ctx>) -> Self {
Self::value(value)
Self::new(value)
}
}
@@ -31,14 +31,6 @@ impl Entry {
context.xlen_type().get_undef(),
);
let address_type = context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
context.set_global(
crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER,
address_type,
AddressSpace::Stack,
address_type.const_zero(),
);
Ok(())
}
+15 -51
View File
@@ -750,9 +750,7 @@ where
address: inkwell::values::IntValue<'ctx>,
) -> anyhow::Result<Pointer<'ctx>> {
let address_type = self.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
let address_pointer = self
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)?
.into();
let address_pointer = self.build_alloca_at_entry(address_type, "address_pointer");
let address_truncated =
self.builder()
.build_int_truncate(address, address_type, "address_truncated")?;
@@ -773,49 +771,27 @@ where
.into())
}
/// Builds a stack load instruction with a direct assignment.
/// Builds a stack load instruction.
/// Sets the alignment to 256 bits for the stack and 1 bit for the heap, parent, and child.
pub fn build_load_assign(
pub fn build_load(
&self,
pointer: Pointer<'ctx>,
name: &str,
assignment_pointer: &mut Option<inkwell::values::PointerValue<'ctx>>,
) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>> {
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> {
match pointer.address_space {
AddressSpace::Heap => {
let name = <PolkaVMLoadHeapWordFunction as RuntimeFunction<D>>::NAME;
let declaration =
<PolkaVMLoadHeapWordFunction as RuntimeFunction<D>>::declaration(self);
match assignment_pointer.take() {
Some(assignment_pointer) => {
let arguments = [
self.builder()
.build_ptr_to_int(
pointer.value,
self.xlen_type(),
"offset_ptrtoint",
)?
.as_basic_value_enum(),
assignment_pointer.into(),
];
self.build_call(declaration, &arguments, "heap_load");
Ok(None)
}
None => {
let pointer = self.build_alloca_at_entry(self.word_type(), "pointer");
let arguments = [
self.builder()
.build_ptr_to_int(
pointer.value,
self.xlen_type(),
"offset_ptrtoint",
)?
.as_basic_value_enum(),
pointer.value.into(),
];
self.build_call(declaration, &arguments, "heap_load");
Ok(Some(self.build_load(pointer, "storage_value")?))
}
}
let arguments = [self
.builder()
.build_ptr_to_int(pointer.value, self.xlen_type(), "offset_ptrtoint")?
.as_basic_value_enum()];
Ok(self
.build_call(declaration, &arguments, "heap_load")
.unwrap_or_else(|| {
panic!("revive runtime function {name} should return a value")
}))
}
AddressSpace::Stack => {
let value = self
@@ -828,23 +804,11 @@ where
.set_alignment(revive_common::BYTE_LENGTH_STACK_ALIGN as u32)
.expect("Alignment is valid");
Ok(Some(value))
Ok(value)
}
}
}
/// Builds a stack load instruction.
/// Sets the alignment to 256 bits for the stack and 1 bit for the heap, parent, and child.
pub fn build_load(
&self,
pointer: Pointer<'ctx>,
name: &str,
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> {
Ok(self
.build_load_assign(pointer, name, &mut None)?
.expect("without an assignment pointer loads return a value"))
}
/// Builds a stack store instruction.
/// Sets the alignment to 256 bits for the stack and 1 bit for the heap, parent, and child.
pub fn build_store<V>(&self, pointer: Pointer<'ctx>, value: V) -> anyhow::Result<()>
@@ -2,8 +2,6 @@
use inkwell::values::BasicValueEnum;
use crate::polkavm::context::address_space::AddressSpace;
use crate::polkavm::context::pointer::Pointer;
use crate::polkavm::context::runtime::RuntimeFunction;
use crate::polkavm::context::Context;
use crate::polkavm::Dependency;
@@ -19,13 +17,9 @@ where
const NAME: &'static str = "__revive_load_heap_word";
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
context.void_type().fn_type(
&[
context.xlen_type().into(),
context.llvm().ptr_type(Default::default()).into(),
],
false,
)
context
.word_type()
.fn_type(&[context.xlen_type().into()], false)
}
fn emit_body<'ctx>(
@@ -33,7 +27,6 @@ where
context: &mut Context<'ctx, D>,
) -> anyhow::Result<Option<BasicValueEnum<'ctx>>> {
let offset = Self::paramater(context, 0).into_int_value();
let assignment_pointer = Self::paramater(context, 1).into_pointer_value();
let length = context
.xlen_type()
.const_int(revive_common::BYTE_LENGTH_WORD as u64, false);
@@ -49,11 +42,7 @@ where
.expect("Alignment is valid");
let swapped_value = context.build_byte_swap(value)?;
context.build_store(
Pointer::new(context.word_type(), AddressSpace::Stack, assignment_pointer),
swapped_value,
)?;
Ok(None)
Ok(Some(swapped_value))
}
}
@@ -2,8 +2,6 @@
use inkwell::values::BasicValueEnum;
use crate::polkavm::context::address_space::AddressSpace;
use crate::polkavm::context::pointer::Pointer;
use crate::polkavm::context::runtime::RuntimeFunction;
use crate::polkavm::context::Context;
use crate::polkavm::Dependency;
@@ -19,27 +17,20 @@ where
const NAME: &'static str = "__revive_load_storage_word";
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
context.void_type().fn_type(
&[
context.llvm().ptr_type(Default::default()).into(),
context.llvm().ptr_type(Default::default()).into(),
],
false,
)
context
.word_type()
.fn_type(&[context.word_type().into()], false)
}
fn emit_body<'ctx>(
&self,
context: &mut Context<'ctx, D>,
) -> anyhow::Result<Option<BasicValueEnum<'ctx>>> {
let key = Self::paramater(context, 0);
let assignment_pointer = Self::paramater(context, 1).into_pointer_value();
let value = emit_load(context, key, false)?;
context.build_store(
Pointer::new(context.word_type(), AddressSpace::Stack, assignment_pointer),
value,
)?;
Ok(None)
Ok(Some(emit_load(
context,
Self::paramater(context, 0),
false,
)?))
}
}
@@ -68,7 +59,7 @@ where
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
context
.word_type()
.fn_type(&[context.llvm().ptr_type(Default::default()).into()], false)
.fn_type(&[context.word_type().into()], false)
}
fn emit_body<'ctx>(
@@ -103,10 +94,7 @@ where
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
context.void_type().fn_type(
&[
context.llvm().ptr_type(Default::default()).into(),
context.llvm().ptr_type(Default::default()).into(),
],
&[context.word_type().into(), context.word_type().into()],
false,
)
}
@@ -150,10 +138,7 @@ where
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
context.void_type().fn_type(
&[
context.llvm().ptr_type(Default::default()).into(),
context.llvm().ptr_type(Default::default()).into(),
],
&[context.word_type().into(), context.word_type().into()],
false,
)
}
@@ -188,17 +173,9 @@ where
fn emit_load<'ctx, D: Dependency + Clone>(
context: &mut Context<'ctx, D>,
key: BasicValueEnum<'ctx>,
mut key: BasicValueEnum<'ctx>,
transient: bool,
) -> anyhow::Result<BasicValueEnum<'ctx>> {
let mut key = context.build_load(
super::Pointer::new(
context.word_type(),
Default::default(),
key.into_pointer_value(),
),
"key",
)?;
if !transient {
key = context.build_byte_swap(key)?;
}
@@ -240,26 +217,10 @@ fn emit_load<'ctx, D: Dependency + Clone>(
fn emit_store<'ctx, D: Dependency + Clone>(
context: &mut Context<'ctx, D>,
key: BasicValueEnum<'ctx>,
value: BasicValueEnum<'ctx>,
mut key: BasicValueEnum<'ctx>,
mut value: BasicValueEnum<'ctx>,
transient: bool,
) -> anyhow::Result<()> {
let mut key = context.build_load(
super::Pointer::new(
context.word_type(),
Default::default(),
key.into_pointer_value(),
),
"key",
)?;
let mut value = context.build_load(
super::Pointer::new(
context.word_type(),
Default::default(),
value.into_pointer_value(),
),
"key",
)?;
if !transient {
key = context.build_byte_swap(key)?;
value = context.build_byte_swap(value)?;
+14 -28
View File
@@ -63,6 +63,7 @@ where
let non_overflow_block = context.append_basic_block("shift_left_non_overflow");
let join_block = context.append_basic_block("shift_left_join");
let result_pointer = context.build_alloca(context.word_type(), "shift_left_result_pointer");
let condition_is_overflow = context.builder().build_int_compare(
inkwell::IntPredicate::UGT,
shift,
@@ -72,6 +73,7 @@ where
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
context.set_basic_block(overflow_block);
context.build_store(result_pointer, context.word_const(0))?;
context.build_unconditional_branch(join_block);
context.set_basic_block(non_overflow_block);
@@ -79,17 +81,11 @@ where
context
.builder()
.build_left_shift(value, shift, "shift_left_non_overflow_result")?;
context.build_store(result_pointer, value)?;
context.build_unconditional_branch(join_block);
context.set_basic_block(join_block);
let result = context
.builder()
.build_phi(context.word_type(), "shift_left_value")?;
result.add_incoming(&[
(&value, non_overflow_block),
(&context.word_const(0), overflow_block),
]);
Ok(result.as_basic_value())
context.build_load(result_pointer, "shift_left_result")
}
/// Translates the bitwise shift right.
@@ -105,6 +101,7 @@ where
let non_overflow_block = context.append_basic_block("shift_right_non_overflow");
let join_block = context.append_basic_block("shift_right_join");
let result_pointer = context.build_alloca(context.word_type(), "shift_right_result_pointer");
let condition_is_overflow = context.builder().build_int_compare(
inkwell::IntPredicate::UGT,
shift,
@@ -114,6 +111,7 @@ where
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
context.set_basic_block(overflow_block);
context.build_store(result_pointer, context.word_const(0))?;
context.build_unconditional_branch(join_block);
context.set_basic_block(non_overflow_block);
@@ -123,17 +121,11 @@ where
false,
"shift_right_non_overflow_result",
)?;
context.build_store(result_pointer, value)?;
context.build_unconditional_branch(join_block);
context.set_basic_block(join_block);
let result = context
.builder()
.build_phi(context.word_type(), "shift_right_value")?;
result.add_incoming(&[
(&value, non_overflow_block),
(&context.word_const(0), overflow_block),
]);
Ok(result.as_basic_value())
context.build_load(result_pointer, "shift_right_result")
}
/// Translates the arithmetic bitwise shift right.
@@ -153,6 +145,8 @@ where
let non_overflow_block = context.append_basic_block("shift_right_arithmetic_non_overflow");
let join_block = context.append_basic_block("shift_right_arithmetic_join");
let result_pointer =
context.build_alloca(context.word_type(), "shift_right_arithmetic_result_pointer");
let condition_is_overflow = context.builder().build_int_compare(
inkwell::IntPredicate::UGT,
shift,
@@ -180,9 +174,11 @@ where
)?;
context.set_basic_block(overflow_positive_block);
context.build_store(result_pointer, context.word_const(0))?;
context.build_unconditional_branch(join_block);
context.set_basic_block(overflow_negative_block);
context.build_store(result_pointer, context.word_type().const_all_ones())?;
context.build_unconditional_branch(join_block);
context.set_basic_block(non_overflow_block);
@@ -192,21 +188,11 @@ where
true,
"shift_right_arithmetic_non_overflow_result",
)?;
context.build_store(result_pointer, value)?;
context.build_unconditional_branch(join_block);
context.set_basic_block(join_block);
let result = context
.builder()
.build_phi(context.word_type(), "shift_arithmetic_right_value")?;
result.add_incoming(&[
(&value, non_overflow_block),
(
&context.word_type().const_all_ones(),
overflow_negative_block,
),
(&context.word_const(0), overflow_block),
]);
Ok(result.as_basic_value())
context.build_load(result_pointer, "shift_right_arithmetic_result")
}
/// Translates the `byte` instruction, extracting the byte of `operand_2`
+16 -16
View File
@@ -2,7 +2,6 @@
use inkwell::values::BasicValue;
use crate::polkavm::context::pointer::Pointer;
use crate::polkavm::context::Context;
use crate::polkavm::Dependency;
@@ -50,9 +49,7 @@ where
D: Dependency + Clone,
{
let address_type = context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
let address_pointer: Pointer<'_> = context
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)?
.into();
let address_pointer = context.build_alloca_at_entry(address_type, "origin_address");
context.build_store(address_pointer, address_type.const_zero())?;
context.build_runtime_call(
revive_runtime_api::polkavm_imports::ORIGIN,
@@ -100,13 +97,13 @@ where
D: Dependency + Clone,
{
let output_pointer = context.build_alloca_at_entry(context.word_type(), "blockhash_out_ptr");
let index_pointer = context.build_alloca_at_entry(context.word_type(), "blockhash_index_ptr");
context.build_store(index_pointer, index)?;
let index_ptr = context.build_alloca_at_entry(context.word_type(), "blockhash_index_ptr");
context.build_store(index_ptr, index)?;
context.build_runtime_call(
revive_runtime_api::polkavm_imports::BLOCK_HASH,
&[
index_pointer.to_int(context).into(),
index_ptr.to_int(context).into(),
output_pointer.to_int(context).into(),
],
);
@@ -130,9 +127,10 @@ pub fn coinbase<'ctx, D>(
where
D: Dependency + Clone,
{
let pointer: Pointer<'_> = context
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)?
.into();
let pointer = context.build_alloca_at_entry(
context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
"coinbase_output",
);
context.build_runtime_call(
revive_runtime_api::polkavm_imports::BLOCK_AUTHOR,
&[pointer.to_int(context).into()],
@@ -157,9 +155,10 @@ pub fn address<'ctx, D>(
where
D: Dependency + Clone,
{
let pointer: Pointer<'_> = context
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)?
.into();
let pointer = context.build_alloca_at_entry(
context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
"address_output",
);
context.build_runtime_call(
revive_runtime_api::polkavm_imports::ADDRESS,
&[pointer.to_int(context).into()],
@@ -174,9 +173,10 @@ pub fn caller<'ctx, D>(
where
D: Dependency + Clone,
{
let pointer: Pointer<'_> = context
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)?
.into();
let pointer = context.build_alloca_at_entry(
context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
"address_output",
);
context.build_runtime_call(
revive_runtime_api::polkavm_imports::CALLER,
&[pointer.to_int(context).into()],
+10 -6
View File
@@ -119,8 +119,10 @@ where
_ => error,
})?;
if contract_path.as_str() == parent {
return Ok(Argument::value(context.word_const(0).as_basic_value_enum())
.with_constant(num::BigUint::zero()));
return Ok(Argument::new_with_constant(
context.word_const(0).as_basic_value_enum(),
num::BigUint::zero(),
));
} else if identifier.ends_with("_deployed") && code_type == CodeType::Runtime {
anyhow::bail!("type({}).runtimeCode is not supported", identifier);
}
@@ -129,7 +131,7 @@ where
let hash_value = context
.word_const_str_hex(hash_string.as_str())
.as_basic_value_enum();
Ok(Argument::value(hash_value).with_original(hash_string))
Ok(Argument::new_with_original(hash_value, hash_string))
}
/// Translates the deploy call header size instruction. the header consists of
@@ -158,8 +160,10 @@ where
_ => error,
})?;
if contract_path.as_str() == parent {
return Ok(Argument::value(context.word_const(0).as_basic_value_enum())
.with_constant(num::BigUint::zero()));
return Ok(Argument::new_with_constant(
context.word_const(0).as_basic_value_enum(),
num::BigUint::zero(),
));
} else if identifier.ends_with("_deployed") && code_type == CodeType::Runtime {
anyhow::bail!("type({}).runtimeCode is not supported", identifier);
}
@@ -168,5 +172,5 @@ where
let size_value = context
.word_const(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE as u64)
.as_basic_value_enum();
Ok(Argument::value(size_value).with_constant(size_bigint))
Ok(Argument::new_with_constant(size_value, size_bigint))
}
@@ -28,7 +28,7 @@ pub fn value<'ctx, D>(
where
D: Dependency + Clone,
{
let output_pointer = context.build_alloca_at_entry(context.value_type(), "value_transferred");
let output_pointer = context.build_alloca(context.value_type(), "value_transferred");
context.build_store(output_pointer, context.word_const(0))?;
context.build_runtime_call(
revive_runtime_api::polkavm_imports::VALUE_TRANSFERRED,
@@ -46,7 +46,8 @@ where
D: Dependency + Clone,
{
let address_pointer = context.build_address_argument_store(address)?;
let balance_pointer = context.build_alloca_at_entry(context.word_type(), "balance_pointer");
let balance_pointer = context.build_alloca(context.word_type(), "balance_pointer");
let balance = context.builder().build_ptr_to_int(
balance_pointer.value,
context.xlen_type(),
@@ -68,7 +69,7 @@ pub fn self_balance<'ctx, D>(
where
D: Dependency + Clone,
{
let balance_pointer = context.build_alloca_at_entry(context.word_type(), "balance_pointer");
let balance_pointer = context.build_alloca(context.word_type(), "balance_pointer");
let balance = context.builder().build_ptr_to_int(
balance_pointer.value,
context.xlen_type(),
@@ -29,8 +29,7 @@ where
pub fn load<'ctx, D>(
context: &mut Context<'ctx, D>,
offset: inkwell::values::IntValue<'ctx>,
assignment_pointer: &mut Option<inkwell::values::PointerValue<'ctx>>,
) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>>
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
where
D: Dependency + Clone,
{
@@ -41,7 +40,7 @@ where
offset,
"memory_load_pointer",
);
context.build_load_assign(pointer, "memory_load_result", assignment_pointer)
context.build_load(pointer, "memory_load_result")
}
/// Translates the `mstore` instruction.
+15 -38
View File
@@ -3,7 +3,6 @@
use crate::polkavm::context::runtime::RuntimeFunction;
use crate::polkavm::context::Context;
use crate::polkavm::Dependency;
use crate::PolkaVMArgument;
use crate::PolkaVMLoadStorageWordFunction;
use crate::PolkaVMLoadTransientStorageWordFunction;
use crate::PolkaVMStoreStorageWordFunction;
@@ -12,49 +11,30 @@ use crate::PolkaVMStoreTransientStorageWordFunction;
/// Translates the storage load.
pub fn load<'ctx, D>(
context: &mut Context<'ctx, D>,
position: &PolkaVMArgument<'ctx>,
assignment_pointer: &mut Option<inkwell::values::PointerValue<'ctx>>,
) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>>
position: inkwell::values::IntValue<'ctx>,
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
where
D: Dependency + Clone,
{
let _name = <PolkaVMLoadStorageWordFunction as RuntimeFunction<D>>::NAME;
let name = <PolkaVMLoadStorageWordFunction as RuntimeFunction<D>>::NAME;
let declaration = <PolkaVMLoadStorageWordFunction as RuntimeFunction<D>>::declaration(context);
match assignment_pointer.take() {
Some(assignment_pointer) => {
let arguments = [
position.as_pointer(context)?.value.into(),
assignment_pointer.into(),
];
context.build_call(declaration, &arguments, "storage_load");
Ok(None)
}
None => {
let pointer = context.build_alloca_at_entry(context.word_type(), "pointer");
let arguments = [
position.as_pointer(context)?.value.into(),
pointer.value.into(),
];
context.build_call(declaration, &arguments, "storage_load");
Ok(Some(context.build_load(pointer, "storage_value")?))
}
}
let arguments = [position.into()];
Ok(context
.build_call(declaration, &arguments, "storage_load")
.unwrap_or_else(|| panic!("runtime function {name} should return a value")))
}
/// Translates the storage store.
pub fn store<'ctx, D>(
context: &mut Context<'ctx, D>,
position: &PolkaVMArgument<'ctx>,
value: &PolkaVMArgument<'ctx>,
position: inkwell::values::IntValue<'ctx>,
value: inkwell::values::IntValue<'ctx>,
) -> anyhow::Result<()>
where
D: Dependency + Clone,
{
let declaration = <PolkaVMStoreStorageWordFunction as RuntimeFunction<D>>::declaration(context);
let arguments = [
position.as_pointer(context)?.value.into(),
value.as_pointer(context)?.value.into(),
];
let arguments = [position.into(), value.into()];
context.build_call(declaration, &arguments, "storage_store");
Ok(())
}
@@ -62,13 +42,13 @@ where
/// Translates the transient storage load.
pub fn transient_load<'ctx, D>(
context: &mut Context<'ctx, D>,
position: &PolkaVMArgument<'ctx>,
position: inkwell::values::IntValue<'ctx>,
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
where
D: Dependency + Clone,
{
let name = <PolkaVMLoadTransientStorageWordFunction as RuntimeFunction<D>>::NAME;
let arguments = [position.as_pointer(context)?.value.into()];
let arguments = [position.into()];
let declaration =
<PolkaVMLoadTransientStorageWordFunction as RuntimeFunction<D>>::declaration(context);
Ok(context
@@ -79,18 +59,15 @@ where
/// Translates the transient storage store.
pub fn transient_store<'ctx, D>(
context: &mut Context<'ctx, D>,
position: &PolkaVMArgument<'ctx>,
value: &PolkaVMArgument<'ctx>,
position: inkwell::values::IntValue<'ctx>,
value: inkwell::values::IntValue<'ctx>,
) -> anyhow::Result<()>
where
D: Dependency + Clone,
{
let declaration =
<PolkaVMStoreTransientStorageWordFunction as RuntimeFunction<D>>::declaration(context);
let arguments = [
position.as_pointer(context)?.value.into(),
value.as_pointer(context)?.value.into(),
];
let arguments = [position.into(), value.into()];
context.build_call(declaration, &arguments, "transient_storage_store");
Ok(())
}
+3 -8
View File
@@ -92,7 +92,7 @@ pub fn build_solidity_with_options(
SolcStandardJsonInputSettingsSelection::new_required(),
SolcStandardJsonInputSettingsOptimizer::new(
solc_optimizer_enabled,
optimizer_settings.middle_end_as_string().chars().last(),
None,
&solc_version.default,
false,
),
@@ -102,21 +102,16 @@ pub fn build_solidity_with_options(
let mut output = solc.standard_json(input, None, vec![], None)?;
let debug_config = revive_llvm_context::DebugConfig::new(
None,
optimizer_settings.middle_end_as_string() != "z",
);
let project = Project::try_from_standard_json_output(
&output,
sources,
libraries,
&solc_version,
&debug_config,
&DEBUG_CONFIG,
)?;
let build: crate::Build =
project.compile(optimizer_settings, false, debug_config, Default::default())?;
project.compile(optimizer_settings, false, DEBUG_CONFIG, Default::default())?;
build.write_to_standard_json(&mut output, &solc_version)?;
Ok(output)
@@ -121,6 +121,11 @@ where
) -> anyhow::Result<()> {
context.set_debug_location(self.location.line, 0, None)?;
let value = match self.initializer.into_llvm(context)? {
Some(value) => value,
None => return Ok(()),
};
if self.bindings.len() == 1 {
let identifier = self.bindings.remove(0);
let pointer = context
@@ -134,31 +139,13 @@ where
identifier.inner,
)
})?;
let mut assignment_pointer = Some(pointer.value);
let value = match self
.initializer
.into_llvm(context, &mut assignment_pointer)?
{
Some(value) => value,
None => return Ok(()),
};
if assignment_pointer.is_some() {
context.build_store(pointer, value.access(context)?)?;
}
context.build_store(pointer, value.to_llvm())?;
return Ok(());
}
let value = match self.initializer.into_llvm(context, &mut None)? {
Some(value) => value,
None => return Ok(()),
};
let value = value.access(context)?;
let llvm_type = value.into_struct_value().get_type();
let llvm_type = value.to_llvm().into_struct_value().get_type();
let tuple_pointer = context.build_alloca(llvm_type, "assignment_pointer");
context.build_store(tuple_pointer, value)?;
context.build_store(tuple_pointer, value.to_llvm())?;
for (index, binding) in self.bindings.into_iter().enumerate() {
context.set_debug_location(self.location.line, 0, None)?;
@@ -184,7 +184,7 @@ where
block.into_llvm(context)?;
}
Statement::Expression(expression) => {
expression.into_llvm(context, &mut None)?;
expression.into_llvm(context)?;
}
Statement::VariableDeclaration(statement) => statement.into_llvm(context)?,
Statement::Assignment(statement) => statement.into_llvm(context)?,
@@ -118,7 +118,6 @@ impl FunctionCall {
pub fn into_llvm<'ctx, D>(
mut self,
context: &mut revive_llvm_context::PolkaVMContext<'ctx, D>,
assignment_pointer: &mut Option<inkwell::values::PointerValue<'ctx>>,
) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>>
where
D: revive_llvm_context::PolkaVMDependency + Clone,
@@ -129,10 +128,7 @@ impl FunctionCall {
Name::UserDefined(name) => {
let mut values = Vec::with_capacity(self.arguments.len());
for argument in self.arguments.into_iter().rev() {
let value = argument
.into_llvm(context, &mut None)?
.expect("Always exists")
.access(context)?;
let value = argument.into_llvm(context)?.expect("Always exists").value;
values.push(value);
}
values.reverse();
@@ -417,8 +413,8 @@ impl FunctionCall {
revive_llvm_context::polkavm_evm_memory::load(
context,
arguments[0].into_int_value(),
assignment_pointer,
)
.map(Some)
}
Name::MStore => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
@@ -465,33 +461,36 @@ impl FunctionCall {
}
Name::SLoad => {
let arguments = self.pop_arguments::<D, 1>(context)?;
let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
revive_llvm_context::polkavm_evm_storage::load(
context,
&arguments[0],
assignment_pointer,
arguments[0].into_int_value(),
)
.map(Some)
}
Name::SStore => {
let arguments = self.pop_arguments::<D, 2>(context)?;
let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
revive_llvm_context::polkavm_evm_storage::store(
context,
&arguments[0],
&arguments[1],
arguments[0].into_int_value(),
arguments[1].into_int_value(),
)
.map(|_| None)
}
Name::TLoad => {
let arguments = self.pop_arguments::<D, 1>(context)?;
revive_llvm_context::polkavm_evm_storage::transient_load(context, &arguments[0])
.map(Some)
let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
revive_llvm_context::polkavm_evm_storage::transient_load(
context,
arguments[0].into_int_value(),
)
.map(Some)
}
Name::TStore => {
let arguments = self.pop_arguments::<D, 2>(context)?;
let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
revive_llvm_context::polkavm_evm_storage::transient_store(
context,
&arguments[0],
&arguments[1],
arguments[0].into_int_value(),
arguments[1].into_int_value(),
)
.map(|_| None)
}
@@ -515,7 +514,7 @@ impl FunctionCall {
let offset = context.solidity_mut().allocate_immutable(key.as_str())
/ revive_common::BYTE_LENGTH_WORD;
let index = context.xlen_type().const_int(offset as u64, false);
let value = arguments[2].access(context)?.into_int_value();
let value = arguments[2].value.into_int_value();
revive_llvm_context::polkavm_evm_immutable::store(context, index, value)
.map(|_| None)
}
@@ -721,13 +720,13 @@ impl FunctionCall {
Name::Call => {
let arguments = self.pop_arguments::<D, 7>(context)?;
let gas = arguments[0].access(context)?.into_int_value();
let address = arguments[1].access(context)?.into_int_value();
let value = arguments[2].access(context)?.into_int_value();
let input_offset = arguments[3].access(context)?.into_int_value();
let input_size = arguments[4].access(context)?.into_int_value();
let output_offset = arguments[5].access(context)?.into_int_value();
let output_size = arguments[6].access(context)?.into_int_value();
let gas = arguments[0].value.into_int_value();
let address = arguments[1].value.into_int_value();
let value = arguments[2].value.into_int_value();
let input_offset = arguments[3].value.into_int_value();
let input_size = arguments[4].value.into_int_value();
let output_offset = arguments[5].value.into_int_value();
let output_size = arguments[6].value.into_int_value();
let simulation_address: Vec<Option<num::BigUint>> = arguments
.into_iter()
@@ -751,12 +750,12 @@ impl FunctionCall {
Name::StaticCall => {
let arguments = self.pop_arguments::<D, 6>(context)?;
let gas = arguments[0].access(context)?.into_int_value();
let address = arguments[1].access(context)?.into_int_value();
let input_offset = arguments[2].access(context)?.into_int_value();
let input_size = arguments[3].access(context)?.into_int_value();
let output_offset = arguments[4].access(context)?.into_int_value();
let output_size = arguments[5].access(context)?.into_int_value();
let gas = arguments[0].value.into_int_value();
let address = arguments[1].value.into_int_value();
let input_offset = arguments[2].value.into_int_value();
let input_size = arguments[3].value.into_int_value();
let output_offset = arguments[4].value.into_int_value();
let output_size = arguments[5].value.into_int_value();
let simulation_address: Vec<Option<num::BigUint>> = arguments
.into_iter()
@@ -780,12 +779,12 @@ impl FunctionCall {
Name::DelegateCall => {
let arguments = self.pop_arguments::<D, 6>(context)?;
let gas = arguments[0].access(context)?.into_int_value();
let address = arguments[1].access(context)?.into_int_value();
let input_offset = arguments[2].access(context)?.into_int_value();
let input_size = arguments[3].access(context)?.into_int_value();
let output_offset = arguments[4].access(context)?.into_int_value();
let output_size = arguments[5].access(context)?.into_int_value();
let gas = arguments[0].value.into_int_value();
let address = arguments[1].value.into_int_value();
let input_offset = arguments[2].value.into_int_value();
let input_size = arguments[3].value.into_int_value();
let output_offset = arguments[4].value.into_int_value();
let output_size = arguments[5].value.into_int_value();
let simulation_address: Vec<Option<num::BigUint>> = arguments
.into_iter()
@@ -846,8 +845,7 @@ impl FunctionCall {
})?;
revive_llvm_context::polkavm_evm_create::contract_hash(context, identifier)
.and_then(|argument| argument.access(context))
.map(Some)
.map(|argument| Some(argument.value))
}
Name::DataSize => {
let mut arguments = self.pop_arguments::<D, 1>(context)?;
@@ -857,8 +855,7 @@ impl FunctionCall {
})?;
revive_llvm_context::polkavm_evm_create::header_size(context, identifier)
.and_then(|argument| argument.access(context))
.map(Some)
.map(|argument| Some(argument.value))
}
Name::DataCopy => {
let arguments = self.pop_arguments_llvm::<D, 3>(context)?;
@@ -992,12 +989,7 @@ impl FunctionCall {
{
let mut arguments = Vec::with_capacity(N);
for expression in self.arguments.drain(0..N).rev() {
arguments.push(
expression
.into_llvm(context, &mut None)?
.expect("Always exists")
.access(context)?,
);
arguments.push(expression.into_llvm(context)?.expect("Always exists").value);
}
arguments.reverse();
@@ -1014,11 +1006,7 @@ impl FunctionCall {
{
let mut arguments = Vec::with_capacity(N);
for expression in self.arguments.drain(0..N).rev() {
arguments.push(
expression
.into_llvm(context, &mut None)?
.expect("Always exists"),
);
arguments.push(expression.into_llvm(context)?.expect("Always exists"));
}
arguments.reverse();
@@ -97,7 +97,9 @@ impl Literal {
BooleanLiteral::True => num::BigUint::one(),
};
Ok(revive_llvm_context::PolkaVMArgument::value(value).with_constant(constant))
Ok(revive_llvm_context::PolkaVMArgument::new_with_constant(
value, constant,
))
}
LexicalLiteral::Integer(inner) => {
let r#type = self.yul_type.unwrap_or_default().into_llvm(context);
@@ -125,7 +127,9 @@ impl Literal {
}
.expect("Always valid");
Ok(revive_llvm_context::PolkaVMArgument::value(value).with_constant(constant))
Ok(revive_llvm_context::PolkaVMArgument::new_with_constant(
value, constant,
))
}
LexicalLiteral::String(inner) => {
let string = inner.inner;
@@ -196,10 +200,10 @@ impl Literal {
};
if hex_string.len() > revive_common::BYTE_LENGTH_WORD * 2 {
return Ok(revive_llvm_context::PolkaVMArgument::value(
return Ok(revive_llvm_context::PolkaVMArgument::new_with_original(
r#type.const_zero().as_basic_value_enum(),
)
.with_original(string));
string,
));
}
if hex_string.len() < revive_common::BYTE_LENGTH_WORD * 2 {
@@ -216,7 +220,9 @@ impl Literal {
)
.expect("The value is valid")
.as_basic_value_enum();
Ok(revive_llvm_context::PolkaVMArgument::value(value).with_original(string))
Ok(revive_llvm_context::PolkaVMArgument::new_with_original(
value, string,
))
}
}
}
@@ -101,7 +101,6 @@ impl Expression {
pub fn into_llvm<'ctx, D>(
self,
context: &mut revive_llvm_context::PolkaVMContext<'ctx, D>,
assignment_pointer: &mut Option<inkwell::values::PointerValue<'ctx>>,
) -> anyhow::Result<Option<revive_llvm_context::PolkaVMArgument<'ctx>>>
where
D: revive_llvm_context::PolkaVMDependency + Clone,
@@ -120,28 +119,36 @@ impl Expression {
})
.map(Some),
Self::Identifier(identifier) => {
let id = identifier.inner;
let pointer = context
.current_function()
.borrow()
.get_stack_pointer(&id)
.get_stack_pointer(identifier.inner.as_str())
.ok_or_else(|| {
anyhow::anyhow!("{} Undeclared variable `{}`", identifier.location, id)
anyhow::anyhow!(
"{} Undeclared variable `{}`",
identifier.location,
identifier.inner,
)
})?;
let constant = context.current_function().borrow().yul().get_constant(&id);
let constant = context
.current_function()
.borrow()
.yul()
.get_constant(identifier.inner.as_str());
let argument = revive_llvm_context::PolkaVMArgument::pointer(pointer, id);
let value = context.build_load(pointer, identifier.inner.as_str())?;
Ok(Some(match constant {
Some(constant) => argument.with_constant(constant),
_ => argument,
}))
match constant {
Some(constant) => Ok(Some(
revive_llvm_context::PolkaVMArgument::new_with_constant(value, constant),
)),
None => Ok(Some(value.into())),
}
}
Self::FunctionCall(call) => Ok(call
.into_llvm(context, assignment_pointer)?
.map(revive_llvm_context::PolkaVMArgument::value)),
.into_llvm(context)?
.map(revive_llvm_context::PolkaVMArgument::new)),
}
}
}
@@ -76,9 +76,9 @@ where
context.set_basic_block(condition_block);
let condition = self
.condition
.into_llvm(context, &mut None)?
.into_llvm(context)?
.expect("Always exists")
.access(context)?
.to_llvm()
.into_int_value();
let condition = context.builder().build_int_z_extend_or_bit_cast(
condition,
@@ -55,9 +55,9 @@ where
fn into_llvm(self, context: &mut revive_llvm_context::PolkaVMContext<D>) -> anyhow::Result<()> {
let condition = self
.condition
.into_llvm(context, &mut None)?
.into_llvm(context)?
.expect("Always exists")
.access(context)?
.to_llvm()
.into_int_value();
let condition = context.builder().build_int_z_extend_or_bit_cast(
condition,
@@ -123,7 +123,7 @@ where
D: revive_llvm_context::PolkaVMDependency + Clone,
{
fn into_llvm(self, context: &mut revive_llvm_context::PolkaVMContext<D>) -> anyhow::Result<()> {
let scrutinee = self.expression.into_llvm(context, &mut None)?;
let scrutinee = self.expression.into_llvm(context)?;
if self.cases.is_empty() {
if let Some(block) = self.default {
@@ -137,7 +137,7 @@ where
let mut branches = Vec::with_capacity(self.cases.len());
for (index, case) in self.cases.into_iter().enumerate() {
let constant = case.literal.into_llvm(context)?.access(context)?;
let constant = case.literal.into_llvm(context)?.to_llvm();
let expression_block = context
.append_basic_block(format!("switch_case_branch_{}_block", index + 1).as_str());
@@ -161,10 +161,7 @@ where
context.set_basic_block(current_block);
context.builder().build_switch(
scrutinee
.expect("Always exists")
.access(context)?
.into_int_value(),
scrutinee.expect("Always exists").to_llvm().into_int_value(),
default_block,
branches.as_slice(),
)?;
@@ -110,9 +110,8 @@ where
.borrow_mut()
.insert_stack_pointer(identifier.inner.clone(), pointer);
let mut assignment_pointer = Some(pointer.value);
let value = if let Some(expression) = self.expression {
match expression.into_llvm(context, &mut assignment_pointer)? {
match expression.into_llvm(context)? {
Some(mut value) => {
if let Some(constant) = value.constant.take() {
context
@@ -122,16 +121,14 @@ where
.insert_constant(identifier.inner.clone(), constant);
}
value.access(context)?
value.to_llvm()
}
None => r#type.const_zero().as_basic_value_enum(),
}
} else {
r#type.const_zero().as_basic_value_enum()
};
if assignment_pointer.is_some() {
context.build_store(pointer, value)?;
}
context.build_store(pointer, value)?;
return Ok(());
}
@@ -159,7 +156,7 @@ where
None => return Ok(()),
};
let location = expression.location();
let expression = match expression.into_llvm(context, &mut None)? {
let expression = match expression.into_llvm(context)? {
Some(expression) => expression,
None => return Ok(()),
};
@@ -178,8 +175,7 @@ where
.collect::<Vec<inkwell::types::BasicTypeEnum<'ctx>>>()
.as_slice(),
);
let value = expression.access(context)?;
if value.get_type() != llvm_type.as_basic_type_enum() {
if expression.value.get_type() != llvm_type.as_basic_type_enum() {
anyhow::bail!(
"{} Assignment to {:?} received an invalid number of arguments",
location,
@@ -187,7 +183,7 @@ where
);
}
let pointer = context.build_alloca(llvm_type, "bindings_pointer");
context.build_store(pointer, value)?;
context.build_store(pointer, expression.to_llvm())?;
for (index, binding) in self.bindings.into_iter().enumerate() {
let pointer = context.build_gep(