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 sys
import json import json
import requests import requests
from datetime import datetime
def validate_github_token(): def validate_github_token():
"""Validate that GITHUB_TOKEN environment variable is set.""" """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}") print(f"Error fetching release data: {e}")
sys.exit(1) 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): def extract_build_hash(target_commitish):
"""Extract the first 8 characters of the commit hash.""" """Extract the first 8 characters of the commit hash."""
return f"commit.{target_commitish[:8]}" 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.""" """Generate JSON for a specific asset."""
version = release_data['tag_name'].lstrip('v') version = release_data['tag_name'].lstrip('v')
build = extract_build_hash(release_data['target_commitish']) build = extract_build_hash(release_data['target_commitish'])
long_version = f"{version}+{build}" long_version = f"{version}+{build}"
path = f"{asset['name']}+{long_version}"
# Get SHA256 checksum if available
sha256 = checksums.get(asset['name'], "")
return { return {
"path": path,
"name": asset['name'], "name": asset['name'],
"version": version, "version": version,
"build": build, "build": build,
"longVersion": long_version, "longVersion": long_version,
"url": asset['browser_download_url'], "url": asset['browser_download_url'],
"sha256": sha256, "firstSolcVersion": os.environ["FIRST_SOLC_VERSION"],
"firstSolcVersion": os.environ.get("FIRST_SOLC_VERSION", ""), "lastSolcVersion": os.environ["LAST_SOLC_VERSION"]
"lastSolcVersion": os.environ.get("LAST_SOLC_VERSION", "")
} }
def save_platform_json(platform_folder, asset_json, tag): 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 # Remove any existing entry with the same path
list_data['builds'] = [ list_data['builds'] = [
build for build in 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 # Add the new build
list_data['builds'].append(asset_json) list_data['builds'].append(asset_json)
# Update releases # Update releases
version = asset_json['version'] 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 # Update latest release
list_data['latestRelease'] = version list_data['latestRelease'] = version
@@ -141,9 +98,6 @@ def main():
# Fetch release data # Fetch release data
release_data = fetch_release_data(repo, tag) release_data = fetch_release_data(repo, tag)
# Fetch checksums
checksums = fetch_checksum_file(release_data)
# Mapping of asset names to platform folders # Mapping of asset names to platform folders
platform_mapping = { platform_mapping = {
'resolc-x86_64-unknown-linux-musl': 'linux', 'resolc-x86_64-unknown-linux-musl': 'linux',
@@ -157,7 +111,7 @@ def main():
platform_name = platform_mapping.get(asset['name']) platform_name = platform_mapping.get(asset['name'])
if platform_name: if platform_name:
platform_folder = os.path.join(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) save_platform_json(platform_folder, asset_json, tag)
print(f"Processed {asset['name']} for {platform_name}") 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-x86_64-unknown-linux-musl
chmod +x resolc-universal-apple-darwin 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 - uses: actions/create-github-app-token@v1
id: app-token id: app-token
with: with:
@@ -285,4 +276,3 @@ jobs:
resolc.js resolc.js
resolc.wasm resolc.wasm
resolc_web.js resolc_web.js
checksums.txt
+1 -14
View File
@@ -6,19 +6,6 @@ This is a development pre-release.
Supported `polkadot-sdk` rev:`c29e72a8628835e34deb6aa7db9a78a2e4eabcee` 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 ### Added
- Support for solc v0.8.29 - 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. - 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 ### 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. - 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 ### Fixed
- A missing byte swap for the create2 salt value. - A missing byte swap for the create2 salt value.
Generated
+17 -17
View File
@@ -4553,7 +4553,7 @@ checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104"
[[package]] [[package]]
name = "lld-sys" name = "lld-sys"
version = "0.1.0-dev.13" version = "0.1.0-dev.12"
dependencies = [ dependencies = [
"cc", "cc",
"libc", "libc",
@@ -8266,7 +8266,7 @@ dependencies = [
[[package]] [[package]]
name = "revive-benchmarks" name = "revive-benchmarks"
version = "0.1.0-dev.13" version = "0.1.0-dev.12"
dependencies = [ dependencies = [
"alloy-primitives", "alloy-primitives",
"criterion", "criterion",
@@ -8278,18 +8278,18 @@ dependencies = [
[[package]] [[package]]
name = "revive-build-utils" name = "revive-build-utils"
version = "0.1.0-dev.13" version = "0.1.0-dev.12"
[[package]] [[package]]
name = "revive-builtins" name = "revive-builtins"
version = "0.1.0-dev.13" version = "0.1.0-dev.12"
dependencies = [ dependencies = [
"revive-build-utils", "revive-build-utils",
] ]
[[package]] [[package]]
name = "revive-common" name = "revive-common"
version = "0.1.0-dev.13" version = "0.1.0-dev.12"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"serde", "serde",
@@ -8299,7 +8299,7 @@ dependencies = [
[[package]] [[package]]
name = "revive-differential" name = "revive-differential"
version = "0.1.0-dev.13" version = "0.1.0-dev.12"
dependencies = [ dependencies = [
"alloy-genesis", "alloy-genesis",
"alloy-primitives", "alloy-primitives",
@@ -8312,7 +8312,7 @@ dependencies = [
[[package]] [[package]]
name = "revive-integration" name = "revive-integration"
version = "0.1.0-dev.13" version = "0.1.0-dev.12"
dependencies = [ dependencies = [
"alloy-primitives", "alloy-primitives",
"alloy-sol-types", "alloy-sol-types",
@@ -8328,7 +8328,7 @@ dependencies = [
[[package]] [[package]]
name = "revive-linker" name = "revive-linker"
version = "0.1.0-dev.13" version = "0.1.0-dev.12"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"libc", "libc",
@@ -8340,7 +8340,7 @@ dependencies = [
[[package]] [[package]]
name = "revive-llvm-builder" name = "revive-llvm-builder"
version = "0.1.0-dev.13" version = "0.1.0-dev.12"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"assert_cmd", "assert_cmd",
@@ -8362,7 +8362,7 @@ dependencies = [
[[package]] [[package]]
name = "revive-llvm-context" name = "revive-llvm-context"
version = "0.1.0-dev.13" version = "0.1.0-dev.12"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"hex", "hex",
@@ -8384,7 +8384,7 @@ dependencies = [
[[package]] [[package]]
name = "revive-runner" name = "revive-runner"
version = "0.1.0-dev.13" version = "0.1.0-dev.12"
dependencies = [ dependencies = [
"alloy-primitives", "alloy-primitives",
"hex", "hex",
@@ -8400,7 +8400,7 @@ dependencies = [
[[package]] [[package]]
name = "revive-runtime-api" name = "revive-runtime-api"
version = "0.1.0-dev.13" version = "0.1.0-dev.12"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"inkwell", "inkwell",
@@ -8410,7 +8410,7 @@ dependencies = [
[[package]] [[package]]
name = "revive-solc-json-interface" name = "revive-solc-json-interface"
version = "0.1.0-dev.13" version = "0.1.0-dev.12"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"rayon", "rayon",
@@ -8422,7 +8422,7 @@ dependencies = [
[[package]] [[package]]
name = "revive-solidity" name = "revive-solidity"
version = "0.1.0-dev.13" version = "0.1.0-dev.12"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",
@@ -8449,7 +8449,7 @@ dependencies = [
[[package]] [[package]]
name = "revive-stdlib" name = "revive-stdlib"
version = "0.1.0-dev.13" version = "0.1.0-dev.12"
dependencies = [ dependencies = [
"inkwell", "inkwell",
"revive-build-utils", "revive-build-utils",
@@ -11117,9 +11117,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.44.2" version = "1.43.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6b88822cbe49de4185e3a4cbf8321dd487cf5fe0c5c65695fef6346371e9c48" checksum = "3d61fa4ffa3de412bfea335c6ecff681de2b609ba3c77ef3e00e521813a9ed9e"
dependencies = [ dependencies = [
"backtrace", "backtrace",
"bytes", "bytes",
+15 -15
View File
@@ -3,7 +3,7 @@ resolver = "2"
members = ["crates/*"] members = ["crates/*"]
[workspace.package] [workspace.package]
version = "0.1.0-dev.13" version = "0.1.0-dev.12"
authors = [ authors = [
"Cyrill Leutwiler <cyrill@parity.io>", "Cyrill Leutwiler <cyrill@parity.io>",
"Parity Technologies <admin@parity.io>", "Parity Technologies <admin@parity.io>",
@@ -14,20 +14,20 @@ repository = "https://github.com/paritytech/revive"
rust-version = "1.81.0" rust-version = "1.81.0"
[workspace.dependencies] [workspace.dependencies]
revive-benchmarks = { version = "0.1.0-dev.13", path = "crates/benchmarks" } revive-benchmarks = { version = "0.1.0-dev.12", path = "crates/benchmarks" }
revive-builtins = { version = "0.1.0-dev.13", path = "crates/builtins" } revive-builtins = { version = "0.1.0-dev.12", path = "crates/builtins" }
revive-common = { version = "0.1.0-dev.13", path = "crates/common" } revive-common = { version = "0.1.0-dev.12", path = "crates/common" }
revive-differential = { version = "0.1.0-dev.13", path = "crates/differential" } revive-differential = { version = "0.1.0-dev.12", path = "crates/differential" }
revive-integration = { version = "0.1.0-dev.13", path = "crates/integration" } revive-integration = { version = "0.1.0-dev.12", path = "crates/integration" }
revive-linker = { version = "0.1.0-dev.13", path = "crates/linker" } revive-linker = { version = "0.1.0-dev.12", path = "crates/linker" }
lld-sys = { version = "0.1.0-dev.13", path = "crates/lld-sys" } lld-sys = { version = "0.1.0-dev.12", path = "crates/lld-sys" }
revive-llvm-context = { version = "0.1.0-dev.13", path = "crates/llvm-context" } revive-llvm-context = { version = "0.1.0-dev.12", path = "crates/llvm-context" }
revive-runtime-api = { version = "0.1.0-dev.13", path = "crates/runtime-api" } revive-runtime-api = { version = "0.1.0-dev.12", path = "crates/runtime-api" }
revive-runner = { version = "0.1.0-dev.13", path = "crates/runner" } revive-runner = { version = "0.1.0-dev.12", path = "crates/runner" }
revive-solc-json-interface = { version = "0.1.0-dev.13", path = "crates/solc-json-interface" } revive-solc-json-interface = { version = "0.1.0-dev.12", path = "crates/solc-json-interface" }
revive-solidity = { version = "0.1.0-dev.13", path = "crates/solidity" } revive-solidity = { version = "0.1.0-dev.12", path = "crates/solidity" }
revive-stdlib = { version = "0.1.0-dev.13", path = "crates/stdlib" } revive-stdlib = { version = "0.1.0-dev.12", path = "crates/stdlib" }
revive-build-utils = { version = "0.1.0-dev.13", path = "crates/build-utils" } revive-build-utils = { version = "0.1.0-dev.12", path = "crates/build-utils" }
hex = "0.4.3" hex = "0.4.3"
cc = "1.2" 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 clone
RUN revive-llvm --target-env musl build --llvm-projects lld --llvm-projects clang 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 WORKDIR /opt/revive
RUN apt update && \ RUN apt update && \
+24 -24
View File
@@ -15,58 +15,58 @@
### Baseline ### Baseline
| | `EVM` | `PVMInterpreter` | | | `EVM` | `PVMInterpreter` |
|:--------|:-------------------------|:-------------------------------- | |:--------|:------------------------|:-------------------------------- |
| **`0`** | `10.08 us` (✅ **1.00x**) | `10.32 us` (**1.02x slower**) | | **`0`** | `3.36 us` (✅ **1.00x**) | `11.84 us` (*3.52x slower*) |
### OddPorduct ### OddPorduct
| | `EVM` | `PVMInterpreter` | | | `EVM` | `PVMInterpreter` |
|:-------------|:--------------------------|:-------------------------------- | |:-------------|:-------------------------|:-------------------------------- |
| **`10000`** | `3.60 ms` (✅ **1.00x**) | `1.57 ms` (🚀 **2.28x faster**) | | **`10000`** | `3.11 ms` (✅ **1.00x**) | `1.53 ms` (🚀 **2.03x faster**) |
| **`100000`** | `34.72 ms` (✅ **1.00x**) | `14.82 ms` (🚀 **2.34x faster**) | | **`100000`** | `30.70 ms` (✅ **1.00x**) | `15.54 ms` (🚀 **1.98x faster**) |
| **`300000`** | `105.01 ms` (✅ **1.00x**) | `44.11 ms` (🚀 **2.38x faster**) | | **`300000`** | `92.68 ms` (✅ **1.00x**) | `45.47 ms` (🚀 **2.04x faster**) |
### TriangleNumber ### TriangleNumber
| | `EVM` | `PVMInterpreter` | | | `EVM` | `PVMInterpreter` |
|:-------------|:-------------------------|:-------------------------------- | |:-------------|:-------------------------|:-------------------------------- |
| **`10000`** | `2.43 ms` (✅ **1.00x**) | `1.12 ms` (🚀 **2.17x faster**) | | **`10000`** | `2.29 ms` (✅ **1.00x**) | `1.09 ms` (🚀 **2.11x faster**) |
| **`100000`** | `24.20 ms` (✅ **1.00x**) | `10.86 ms` (🚀 **2.23x faster**) | | **`100000`** | `22.84 ms` (✅ **1.00x**) | `10.66 ms` (🚀 **2.14x faster**) |
| **`360000`** | `88.69 ms` (✅ **1.00x**) | `38.46 ms` (🚀 **2.31x faster**) | | **`360000`** | `82.29 ms` (✅ **1.00x**) | `37.01 ms` (🚀 **2.22x faster**) |
### FibonacciRecursive ### FibonacciRecursive
| | `EVM` | `PVMInterpreter` | | | `EVM` | `PVMInterpreter` |
|:---------|:--------------------------|:--------------------------------- | |:---------|:--------------------------|:--------------------------------- |
| **`12`** | `144.17 us` (✅ **1.00x**) | `150.85 us` (✅ **1.05x slower**) | | **`12`** | `135.67 us` (✅ **1.00x**) | `125.02 us` (✅ **1.09x faster**) |
| **`16`** | `938.71 us` (✅ **1.00x**) | `922.11 us` (✅ **1.02x faster**) | | **`16`** | `903.75 us` (✅ **1.00x**) | `762.79 us` (✅ **1.18x faster**) |
| **`20`** | `6.54 ms` (✅ **1.00x**) | `6.20 ms` (✅ **1.05x faster**) | | **`20`** | `6.12 ms` (✅ **1.00x**) | `4.96 ms` (✅ **1.23x faster**) |
| **`24`** | `45.73 ms` (✅ **1.00x**) | `41.98 ms` (✅ **1.09x faster**) | | **`24`** | `42.05 ms` (✅ **1.00x**) | `33.86 ms` (✅ **1.24x faster**) |
### FibonacciIterative ### FibonacciIterative
| | `EVM` | `PVMInterpreter` | | | `EVM` | `PVMInterpreter` |
|:----------|:-------------------------|:-------------------------------- | |:----------|:-------------------------|:-------------------------------- |
| **`64`** | `23.00 us` (✅ **1.00x**) | `31.88 us` (❌ *1.39x slower*) | | **`64`** | `15.04 us` (✅ **1.00x**) | `29.45 us` (❌ *1.96x slower*) |
| **`128`** | `35.28 us` (✅ **1.00x**) | `42.43 us` (❌ *1.20x slower*) | | **`128`** | `26.36 us` (✅ **1.00x**) | `42.19 us` (❌ *1.60x slower*) |
| **`256`** | `60.12 us` (✅ **1.00x**) | `61.20 us` (**1.02x slower**) | | **`256`** | `48.61 us` (✅ **1.00x**) | `65.71 us` (*1.35x slower*) |
### FibonacciBinet ### FibonacciBinet
| | `EVM` | `PVMInterpreter` | | | `EVM` | `PVMInterpreter` |
|:----------|:-------------------------|:-------------------------------- | |:----------|:-------------------------|:-------------------------------- |
| **`64`** | `23.01 us` (✅ **1.00x**) | `47.74 us` (❌ *2.07x slower*) | | **`64`** | `15.22 us` (✅ **1.00x**) | `41.46 us` (❌ *2.72x slower*) |
| **`128`** | `25.44 us` (✅ **1.00x**) | `49.67 us` (❌ *1.95x slower*) | | **`128`** | `17.05 us` (✅ **1.00x**) | `42.84 us` (❌ *2.51x slower*) |
| **`256`** | `28.66 us` (✅ **1.00x**) | `53.01 us` (❌ *1.85x slower*) | | **`256`** | `19.00 us` (✅ **1.00x**) | `44.36 us` (❌ *2.34x slower*) |
### SHA1 ### SHA1
| | `EVM` | `PVMInterpreter` | | | `EVM` | `PVMInterpreter` |
|:----------|:--------------------------|:--------------------------------- | |:----------|:--------------------------|:--------------------------------- |
| **`1`** | `135.87 us` (✅ **1.00x**) | `243.75 us` (❌ *1.79x slower*) | | **`1`** | `110.04 us` (✅ **1.00x**) | `216.11 us` (❌ *1.96x slower*) |
| **`64`** | `258.45 us` (✅ **1.00x**) | `355.70 us` (❌ *1.38x slower*) | | **`64`** | `209.04 us` (✅ **1.00x**) | `309.48 us` (❌ *1.48x slower*) |
| **`512`** | `1.10 ms` (✅ **1.00x**) | `1.09 ms` (✅ **1.01x faster**) | | **`512`** | `903.65 us` (✅ **1.00x**) | `980.49 us` (✅ **1.09x slower**) |
--- ---
Made with [criterion-table](https://github.com/nu11ptr/criterion-table) Made with [criterion-table](https://github.com/nu11ptr/criterion-table)
+8 -8
View File
@@ -1,10 +1,10 @@
{ {
"Baseline": 950, "Baseline": 1443,
"Computation": 2262, "Computation": 2788,
"DivisionArithmetics": 8915, "DivisionArithmetics": 9748,
"ERC20": 17233, "ERC20": 19150,
"Events": 1628, "Events": 2201,
"FibonacciIterative": 1485, "FibonacciIterative": 2041,
"Flipper": 2132, "Flipper": 2691,
"SHA1": 8381 "SHA1": 8997
} }
@@ -9,9 +9,6 @@ pub static XLEN: usize = revive_common::BIT_LENGTH_X32;
/// The calldata size global variable name. /// The calldata size global variable name.
pub static GLOBAL_CALLDATA_SIZE: &str = "calldatasize"; 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: /// The deployer call header size that consists of:
/// - bytecode hash (32 bytes) /// - bytecode hash (32 bytes)
pub const DEPLOYER_CALL_HEADER_SIZE: usize = revive_common::BYTE_LENGTH_WORD; pub const DEPLOYER_CALL_HEADER_SIZE: usize = revive_common::BYTE_LENGTH_WORD;
@@ -4,98 +4,61 @@
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Argument<'ctx> { pub struct Argument<'ctx> {
/// The actual LLVM operand. /// The actual LLVM operand.
pub value: Value<'ctx>, pub value: inkwell::values::BasicValueEnum<'ctx>,
/// The original AST value. Used mostly for string literals. /// The original AST value. Used mostly for string literals.
pub original: Option<String>, pub original: Option<String>,
/// The preserved constant value, if available. /// The preserved constant value, if available.
pub constant: Option<num::BigUint>, 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> { impl<'ctx> Argument<'ctx> {
/// A shortcut constructor for register arguments. /// The calldata offset argument index.
pub fn value(value: inkwell::values::BasicValueEnum<'ctx>) -> Self { 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 { Self {
value: Value::Register(value), value,
original: None, original: None,
constant: None, constant: None,
} }
} }
/// A shortcut constructor for stack arguments. /// A shortcut constructor.
pub fn pointer(pointer: crate::polkavm::context::Pointer<'ctx>, id: String) -> Self { pub fn new_with_original(
value: inkwell::values::BasicValueEnum<'ctx>,
original: String,
) -> Self {
Self { Self {
value: Value::Pointer { pointer, id }, value,
original: None, original: Some(original),
constant: None, constant: None,
} }
} }
/// Set the original decleratation value. /// A shortcut constructor.
pub fn with_original(mut self, original: String) -> Self { pub fn new_with_constant(
self.original = Some(original); value: inkwell::values::BasicValueEnum<'ctx>,
self constant: num::BigUint,
} ) -> Self {
Self {
/// Set the constant value. value,
pub fn with_constant(mut self, constant: num::BigUint) -> Self { original: None,
self.constant = Some(constant); constant: Some(constant),
self }
} }
/// Returns the inner LLVM value. /// Returns the inner LLVM value.
/// pub fn to_llvm(&self) -> inkwell::values::BasicValueEnum<'ctx> {
/// Panics if `self` is a pointer argument. self.value
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),
}
} }
} }
impl<'ctx> From<inkwell::values::BasicValueEnum<'ctx>> for Argument<'ctx> { impl<'ctx> From<inkwell::values::BasicValueEnum<'ctx>> for Argument<'ctx> {
fn from(value: inkwell::values::BasicValueEnum<'ctx>) -> Self { 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(), 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(()) Ok(())
} }
+15 -51
View File
@@ -750,9 +750,7 @@ where
address: inkwell::values::IntValue<'ctx>, address: inkwell::values::IntValue<'ctx>,
) -> anyhow::Result<Pointer<'ctx>> { ) -> anyhow::Result<Pointer<'ctx>> {
let address_type = self.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS); let address_type = self.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
let address_pointer = self let address_pointer = self.build_alloca_at_entry(address_type, "address_pointer");
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)?
.into();
let address_truncated = let address_truncated =
self.builder() self.builder()
.build_int_truncate(address, address_type, "address_truncated")?; .build_int_truncate(address, address_type, "address_truncated")?;
@@ -773,49 +771,27 @@ where
.into()) .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. /// 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, &self,
pointer: Pointer<'ctx>, pointer: Pointer<'ctx>,
name: &str, name: &str,
assignment_pointer: &mut Option<inkwell::values::PointerValue<'ctx>>, ) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> {
) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>> {
match pointer.address_space { match pointer.address_space {
AddressSpace::Heap => { AddressSpace::Heap => {
let name = <PolkaVMLoadHeapWordFunction as RuntimeFunction<D>>::NAME;
let declaration = let declaration =
<PolkaVMLoadHeapWordFunction as RuntimeFunction<D>>::declaration(self); <PolkaVMLoadHeapWordFunction as RuntimeFunction<D>>::declaration(self);
match assignment_pointer.take() { let arguments = [self
Some(assignment_pointer) => { .builder()
let arguments = [ .build_ptr_to_int(pointer.value, self.xlen_type(), "offset_ptrtoint")?
self.builder() .as_basic_value_enum()];
.build_ptr_to_int( Ok(self
pointer.value, .build_call(declaration, &arguments, "heap_load")
self.xlen_type(), .unwrap_or_else(|| {
"offset_ptrtoint", panic!("revive runtime function {name} should return a value")
)? }))
.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")?))
}
}
} }
AddressSpace::Stack => { AddressSpace::Stack => {
let value = self let value = self
@@ -828,23 +804,11 @@ where
.set_alignment(revive_common::BYTE_LENGTH_STACK_ALIGN as u32) .set_alignment(revive_common::BYTE_LENGTH_STACK_ALIGN as u32)
.expect("Alignment is valid"); .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. /// Builds a stack store instruction.
/// Sets the alignment to 256 bits for the stack and 1 bit for the heap, parent, and child. /// 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<()> pub fn build_store<V>(&self, pointer: Pointer<'ctx>, value: V) -> anyhow::Result<()>
@@ -2,8 +2,6 @@
use inkwell::values::BasicValueEnum; 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::runtime::RuntimeFunction;
use crate::polkavm::context::Context; use crate::polkavm::context::Context;
use crate::polkavm::Dependency; use crate::polkavm::Dependency;
@@ -19,13 +17,9 @@ where
const NAME: &'static str = "__revive_load_heap_word"; const NAME: &'static str = "__revive_load_heap_word";
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> { fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
context.void_type().fn_type( context
&[ .word_type()
context.xlen_type().into(), .fn_type(&[context.xlen_type().into()], false)
context.llvm().ptr_type(Default::default()).into(),
],
false,
)
} }
fn emit_body<'ctx>( fn emit_body<'ctx>(
@@ -33,7 +27,6 @@ where
context: &mut Context<'ctx, D>, context: &mut Context<'ctx, D>,
) -> anyhow::Result<Option<BasicValueEnum<'ctx>>> { ) -> anyhow::Result<Option<BasicValueEnum<'ctx>>> {
let offset = Self::paramater(context, 0).into_int_value(); let offset = Self::paramater(context, 0).into_int_value();
let assignment_pointer = Self::paramater(context, 1).into_pointer_value();
let length = context let length = context
.xlen_type() .xlen_type()
.const_int(revive_common::BYTE_LENGTH_WORD as u64, false); .const_int(revive_common::BYTE_LENGTH_WORD as u64, false);
@@ -49,11 +42,7 @@ where
.expect("Alignment is valid"); .expect("Alignment is valid");
let swapped_value = context.build_byte_swap(value)?; let swapped_value = context.build_byte_swap(value)?;
context.build_store( Ok(Some(swapped_value))
Pointer::new(context.word_type(), AddressSpace::Stack, assignment_pointer),
swapped_value,
)?;
Ok(None)
} }
} }
@@ -2,8 +2,6 @@
use inkwell::values::BasicValueEnum; 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::runtime::RuntimeFunction;
use crate::polkavm::context::Context; use crate::polkavm::context::Context;
use crate::polkavm::Dependency; use crate::polkavm::Dependency;
@@ -19,27 +17,20 @@ where
const NAME: &'static str = "__revive_load_storage_word"; const NAME: &'static str = "__revive_load_storage_word";
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> { fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
context.void_type().fn_type( context
&[ .word_type()
context.llvm().ptr_type(Default::default()).into(), .fn_type(&[context.word_type().into()], false)
context.llvm().ptr_type(Default::default()).into(),
],
false,
)
} }
fn emit_body<'ctx>( fn emit_body<'ctx>(
&self, &self,
context: &mut Context<'ctx, D>, context: &mut Context<'ctx, D>,
) -> anyhow::Result<Option<BasicValueEnum<'ctx>>> { ) -> anyhow::Result<Option<BasicValueEnum<'ctx>>> {
let key = Self::paramater(context, 0); Ok(Some(emit_load(
let assignment_pointer = Self::paramater(context, 1).into_pointer_value(); context,
let value = emit_load(context, key, false)?; Self::paramater(context, 0),
context.build_store( false,
Pointer::new(context.word_type(), AddressSpace::Stack, assignment_pointer), )?))
value,
)?;
Ok(None)
} }
} }
@@ -68,7 +59,7 @@ where
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> { fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
context context
.word_type() .word_type()
.fn_type(&[context.llvm().ptr_type(Default::default()).into()], false) .fn_type(&[context.word_type().into()], false)
} }
fn emit_body<'ctx>( fn emit_body<'ctx>(
@@ -103,10 +94,7 @@ where
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> { fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
context.void_type().fn_type( context.void_type().fn_type(
&[ &[context.word_type().into(), context.word_type().into()],
context.llvm().ptr_type(Default::default()).into(),
context.llvm().ptr_type(Default::default()).into(),
],
false, false,
) )
} }
@@ -150,10 +138,7 @@ where
fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> { fn r#type<'ctx>(context: &Context<'ctx, D>) -> inkwell::types::FunctionType<'ctx> {
context.void_type().fn_type( context.void_type().fn_type(
&[ &[context.word_type().into(), context.word_type().into()],
context.llvm().ptr_type(Default::default()).into(),
context.llvm().ptr_type(Default::default()).into(),
],
false, false,
) )
} }
@@ -188,17 +173,9 @@ where
fn emit_load<'ctx, D: Dependency + Clone>( fn emit_load<'ctx, D: Dependency + Clone>(
context: &mut Context<'ctx, D>, context: &mut Context<'ctx, D>,
key: BasicValueEnum<'ctx>, mut key: BasicValueEnum<'ctx>,
transient: bool, transient: bool,
) -> anyhow::Result<BasicValueEnum<'ctx>> { ) -> 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 { if !transient {
key = context.build_byte_swap(key)?; key = context.build_byte_swap(key)?;
} }
@@ -240,26 +217,10 @@ fn emit_load<'ctx, D: Dependency + Clone>(
fn emit_store<'ctx, D: Dependency + Clone>( fn emit_store<'ctx, D: Dependency + Clone>(
context: &mut Context<'ctx, D>, context: &mut Context<'ctx, D>,
key: BasicValueEnum<'ctx>, mut key: BasicValueEnum<'ctx>,
value: BasicValueEnum<'ctx>, mut value: BasicValueEnum<'ctx>,
transient: bool, transient: bool,
) -> anyhow::Result<()> { ) -> 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 { if !transient {
key = context.build_byte_swap(key)?; key = context.build_byte_swap(key)?;
value = context.build_byte_swap(value)?; 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 non_overflow_block = context.append_basic_block("shift_left_non_overflow");
let join_block = context.append_basic_block("shift_left_join"); 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( let condition_is_overflow = context.builder().build_int_compare(
inkwell::IntPredicate::UGT, inkwell::IntPredicate::UGT,
shift, shift,
@@ -72,6 +73,7 @@ where
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?; context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
context.set_basic_block(overflow_block); context.set_basic_block(overflow_block);
context.build_store(result_pointer, context.word_const(0))?;
context.build_unconditional_branch(join_block); context.build_unconditional_branch(join_block);
context.set_basic_block(non_overflow_block); context.set_basic_block(non_overflow_block);
@@ -79,17 +81,11 @@ where
context context
.builder() .builder()
.build_left_shift(value, shift, "shift_left_non_overflow_result")?; .build_left_shift(value, shift, "shift_left_non_overflow_result")?;
context.build_store(result_pointer, value)?;
context.build_unconditional_branch(join_block); context.build_unconditional_branch(join_block);
context.set_basic_block(join_block); context.set_basic_block(join_block);
let result = context context.build_load(result_pointer, "shift_left_result")
.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())
} }
/// Translates the bitwise shift right. /// Translates the bitwise shift right.
@@ -105,6 +101,7 @@ where
let non_overflow_block = context.append_basic_block("shift_right_non_overflow"); let non_overflow_block = context.append_basic_block("shift_right_non_overflow");
let join_block = context.append_basic_block("shift_right_join"); 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( let condition_is_overflow = context.builder().build_int_compare(
inkwell::IntPredicate::UGT, inkwell::IntPredicate::UGT,
shift, shift,
@@ -114,6 +111,7 @@ where
context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?; context.build_conditional_branch(condition_is_overflow, overflow_block, non_overflow_block)?;
context.set_basic_block(overflow_block); context.set_basic_block(overflow_block);
context.build_store(result_pointer, context.word_const(0))?;
context.build_unconditional_branch(join_block); context.build_unconditional_branch(join_block);
context.set_basic_block(non_overflow_block); context.set_basic_block(non_overflow_block);
@@ -123,17 +121,11 @@ where
false, false,
"shift_right_non_overflow_result", "shift_right_non_overflow_result",
)?; )?;
context.build_store(result_pointer, value)?;
context.build_unconditional_branch(join_block); context.build_unconditional_branch(join_block);
context.set_basic_block(join_block); context.set_basic_block(join_block);
let result = context context.build_load(result_pointer, "shift_right_result")
.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())
} }
/// Translates the arithmetic bitwise shift right. /// 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 non_overflow_block = context.append_basic_block("shift_right_arithmetic_non_overflow");
let join_block = context.append_basic_block("shift_right_arithmetic_join"); 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( let condition_is_overflow = context.builder().build_int_compare(
inkwell::IntPredicate::UGT, inkwell::IntPredicate::UGT,
shift, shift,
@@ -180,9 +174,11 @@ where
)?; )?;
context.set_basic_block(overflow_positive_block); context.set_basic_block(overflow_positive_block);
context.build_store(result_pointer, context.word_const(0))?;
context.build_unconditional_branch(join_block); context.build_unconditional_branch(join_block);
context.set_basic_block(overflow_negative_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.build_unconditional_branch(join_block);
context.set_basic_block(non_overflow_block); context.set_basic_block(non_overflow_block);
@@ -192,21 +188,11 @@ where
true, true,
"shift_right_arithmetic_non_overflow_result", "shift_right_arithmetic_non_overflow_result",
)?; )?;
context.build_store(result_pointer, value)?;
context.build_unconditional_branch(join_block); context.build_unconditional_branch(join_block);
context.set_basic_block(join_block); context.set_basic_block(join_block);
let result = context context.build_load(result_pointer, "shift_right_arithmetic_result")
.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())
} }
/// Translates the `byte` instruction, extracting the byte of `operand_2` /// Translates the `byte` instruction, extracting the byte of `operand_2`
+16 -16
View File
@@ -2,7 +2,6 @@
use inkwell::values::BasicValue; use inkwell::values::BasicValue;
use crate::polkavm::context::pointer::Pointer;
use crate::polkavm::context::Context; use crate::polkavm::context::Context;
use crate::polkavm::Dependency; use crate::polkavm::Dependency;
@@ -50,9 +49,7 @@ where
D: Dependency + Clone, D: Dependency + Clone,
{ {
let address_type = context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS); let address_type = context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
let address_pointer: Pointer<'_> = context let address_pointer = context.build_alloca_at_entry(address_type, "origin_address");
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)?
.into();
context.build_store(address_pointer, address_type.const_zero())?; context.build_store(address_pointer, address_type.const_zero())?;
context.build_runtime_call( context.build_runtime_call(
revive_runtime_api::polkavm_imports::ORIGIN, revive_runtime_api::polkavm_imports::ORIGIN,
@@ -100,13 +97,13 @@ where
D: Dependency + Clone, D: Dependency + Clone,
{ {
let output_pointer = context.build_alloca_at_entry(context.word_type(), "blockhash_out_ptr"); 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"); let index_ptr = context.build_alloca_at_entry(context.word_type(), "blockhash_index_ptr");
context.build_store(index_pointer, index)?; context.build_store(index_ptr, index)?;
context.build_runtime_call( context.build_runtime_call(
revive_runtime_api::polkavm_imports::BLOCK_HASH, 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(), output_pointer.to_int(context).into(),
], ],
); );
@@ -130,9 +127,10 @@ pub fn coinbase<'ctx, D>(
where where
D: Dependency + Clone, D: Dependency + Clone,
{ {
let pointer: Pointer<'_> = context let pointer = context.build_alloca_at_entry(
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)? context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
.into(); "coinbase_output",
);
context.build_runtime_call( context.build_runtime_call(
revive_runtime_api::polkavm_imports::BLOCK_AUTHOR, revive_runtime_api::polkavm_imports::BLOCK_AUTHOR,
&[pointer.to_int(context).into()], &[pointer.to_int(context).into()],
@@ -157,9 +155,10 @@ pub fn address<'ctx, D>(
where where
D: Dependency + Clone, D: Dependency + Clone,
{ {
let pointer: Pointer<'_> = context let pointer = context.build_alloca_at_entry(
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)? context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
.into(); "address_output",
);
context.build_runtime_call( context.build_runtime_call(
revive_runtime_api::polkavm_imports::ADDRESS, revive_runtime_api::polkavm_imports::ADDRESS,
&[pointer.to_int(context).into()], &[pointer.to_int(context).into()],
@@ -174,9 +173,10 @@ pub fn caller<'ctx, D>(
where where
D: Dependency + Clone, D: Dependency + Clone,
{ {
let pointer: Pointer<'_> = context let pointer = context.build_alloca_at_entry(
.get_global(crate::polkavm::GLOBAL_ADDRESS_SPILL_BUFFER)? context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS),
.into(); "address_output",
);
context.build_runtime_call( context.build_runtime_call(
revive_runtime_api::polkavm_imports::CALLER, revive_runtime_api::polkavm_imports::CALLER,
&[pointer.to_int(context).into()], &[pointer.to_int(context).into()],
+10 -6
View File
@@ -119,8 +119,10 @@ where
_ => error, _ => error,
})?; })?;
if contract_path.as_str() == parent { if contract_path.as_str() == parent {
return Ok(Argument::value(context.word_const(0).as_basic_value_enum()) return Ok(Argument::new_with_constant(
.with_constant(num::BigUint::zero())); context.word_const(0).as_basic_value_enum(),
num::BigUint::zero(),
));
} else if identifier.ends_with("_deployed") && code_type == CodeType::Runtime { } else if identifier.ends_with("_deployed") && code_type == CodeType::Runtime {
anyhow::bail!("type({}).runtimeCode is not supported", identifier); anyhow::bail!("type({}).runtimeCode is not supported", identifier);
} }
@@ -129,7 +131,7 @@ where
let hash_value = context let hash_value = context
.word_const_str_hex(hash_string.as_str()) .word_const_str_hex(hash_string.as_str())
.as_basic_value_enum(); .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 /// Translates the deploy call header size instruction. the header consists of
@@ -158,8 +160,10 @@ where
_ => error, _ => error,
})?; })?;
if contract_path.as_str() == parent { if contract_path.as_str() == parent {
return Ok(Argument::value(context.word_const(0).as_basic_value_enum()) return Ok(Argument::new_with_constant(
.with_constant(num::BigUint::zero())); context.word_const(0).as_basic_value_enum(),
num::BigUint::zero(),
));
} else if identifier.ends_with("_deployed") && code_type == CodeType::Runtime { } else if identifier.ends_with("_deployed") && code_type == CodeType::Runtime {
anyhow::bail!("type({}).runtimeCode is not supported", identifier); anyhow::bail!("type({}).runtimeCode is not supported", identifier);
} }
@@ -168,5 +172,5 @@ where
let size_value = context let size_value = context
.word_const(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE as u64) .word_const(crate::polkavm::DEPLOYER_CALL_HEADER_SIZE as u64)
.as_basic_value_enum(); .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 where
D: Dependency + Clone, 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_store(output_pointer, context.word_const(0))?;
context.build_runtime_call( context.build_runtime_call(
revive_runtime_api::polkavm_imports::VALUE_TRANSFERRED, revive_runtime_api::polkavm_imports::VALUE_TRANSFERRED,
@@ -46,7 +46,8 @@ where
D: Dependency + Clone, D: Dependency + Clone,
{ {
let address_pointer = context.build_address_argument_store(address)?; 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( let balance = context.builder().build_ptr_to_int(
balance_pointer.value, balance_pointer.value,
context.xlen_type(), context.xlen_type(),
@@ -68,7 +69,7 @@ pub fn self_balance<'ctx, D>(
where where
D: Dependency + Clone, 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( let balance = context.builder().build_ptr_to_int(
balance_pointer.value, balance_pointer.value,
context.xlen_type(), context.xlen_type(),
@@ -29,8 +29,7 @@ where
pub fn load<'ctx, D>( pub fn load<'ctx, D>(
context: &mut Context<'ctx, D>, context: &mut Context<'ctx, D>,
offset: inkwell::values::IntValue<'ctx>, offset: inkwell::values::IntValue<'ctx>,
assignment_pointer: &mut Option<inkwell::values::PointerValue<'ctx>>, ) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>>
where where
D: Dependency + Clone, D: Dependency + Clone,
{ {
@@ -41,7 +40,7 @@ where
offset, offset,
"memory_load_pointer", "memory_load_pointer",
); );
context.build_load_assign(pointer, "memory_load_result", assignment_pointer) context.build_load(pointer, "memory_load_result")
} }
/// Translates the `mstore` instruction. /// Translates the `mstore` instruction.
+15 -38
View File
@@ -3,7 +3,6 @@
use crate::polkavm::context::runtime::RuntimeFunction; use crate::polkavm::context::runtime::RuntimeFunction;
use crate::polkavm::context::Context; use crate::polkavm::context::Context;
use crate::polkavm::Dependency; use crate::polkavm::Dependency;
use crate::PolkaVMArgument;
use crate::PolkaVMLoadStorageWordFunction; use crate::PolkaVMLoadStorageWordFunction;
use crate::PolkaVMLoadTransientStorageWordFunction; use crate::PolkaVMLoadTransientStorageWordFunction;
use crate::PolkaVMStoreStorageWordFunction; use crate::PolkaVMStoreStorageWordFunction;
@@ -12,49 +11,30 @@ use crate::PolkaVMStoreTransientStorageWordFunction;
/// Translates the storage load. /// Translates the storage load.
pub fn load<'ctx, D>( pub fn load<'ctx, D>(
context: &mut Context<'ctx, D>, context: &mut Context<'ctx, D>,
position: &PolkaVMArgument<'ctx>, position: inkwell::values::IntValue<'ctx>,
assignment_pointer: &mut Option<inkwell::values::PointerValue<'ctx>>, ) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>>
where where
D: Dependency + Clone, 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); let declaration = <PolkaVMLoadStorageWordFunction as RuntimeFunction<D>>::declaration(context);
match assignment_pointer.take() { let arguments = [position.into()];
Some(assignment_pointer) => { Ok(context
let arguments = [ .build_call(declaration, &arguments, "storage_load")
position.as_pointer(context)?.value.into(), .unwrap_or_else(|| panic!("runtime function {name} should return a value")))
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")?))
}
}
} }
/// Translates the storage store. /// Translates the storage store.
pub fn store<'ctx, D>( pub fn store<'ctx, D>(
context: &mut Context<'ctx, D>, context: &mut Context<'ctx, D>,
position: &PolkaVMArgument<'ctx>, position: inkwell::values::IntValue<'ctx>,
value: &PolkaVMArgument<'ctx>, value: inkwell::values::IntValue<'ctx>,
) -> anyhow::Result<()> ) -> anyhow::Result<()>
where where
D: Dependency + Clone, D: Dependency + Clone,
{ {
let declaration = <PolkaVMStoreStorageWordFunction as RuntimeFunction<D>>::declaration(context); let declaration = <PolkaVMStoreStorageWordFunction as RuntimeFunction<D>>::declaration(context);
let arguments = [ let arguments = [position.into(), value.into()];
position.as_pointer(context)?.value.into(),
value.as_pointer(context)?.value.into(),
];
context.build_call(declaration, &arguments, "storage_store"); context.build_call(declaration, &arguments, "storage_store");
Ok(()) Ok(())
} }
@@ -62,13 +42,13 @@ where
/// Translates the transient storage load. /// Translates the transient storage load.
pub fn transient_load<'ctx, D>( pub fn transient_load<'ctx, D>(
context: &mut Context<'ctx, D>, context: &mut Context<'ctx, D>,
position: &PolkaVMArgument<'ctx>, position: inkwell::values::IntValue<'ctx>,
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>> ) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
where where
D: Dependency + Clone, D: Dependency + Clone,
{ {
let name = <PolkaVMLoadTransientStorageWordFunction as RuntimeFunction<D>>::NAME; let name = <PolkaVMLoadTransientStorageWordFunction as RuntimeFunction<D>>::NAME;
let arguments = [position.as_pointer(context)?.value.into()]; let arguments = [position.into()];
let declaration = let declaration =
<PolkaVMLoadTransientStorageWordFunction as RuntimeFunction<D>>::declaration(context); <PolkaVMLoadTransientStorageWordFunction as RuntimeFunction<D>>::declaration(context);
Ok(context Ok(context
@@ -79,18 +59,15 @@ where
/// Translates the transient storage store. /// Translates the transient storage store.
pub fn transient_store<'ctx, D>( pub fn transient_store<'ctx, D>(
context: &mut Context<'ctx, D>, context: &mut Context<'ctx, D>,
position: &PolkaVMArgument<'ctx>, position: inkwell::values::IntValue<'ctx>,
value: &PolkaVMArgument<'ctx>, value: inkwell::values::IntValue<'ctx>,
) -> anyhow::Result<()> ) -> anyhow::Result<()>
where where
D: Dependency + Clone, D: Dependency + Clone,
{ {
let declaration = let declaration =
<PolkaVMStoreTransientStorageWordFunction as RuntimeFunction<D>>::declaration(context); <PolkaVMStoreTransientStorageWordFunction as RuntimeFunction<D>>::declaration(context);
let arguments = [ let arguments = [position.into(), value.into()];
position.as_pointer(context)?.value.into(),
value.as_pointer(context)?.value.into(),
];
context.build_call(declaration, &arguments, "transient_storage_store"); context.build_call(declaration, &arguments, "transient_storage_store");
Ok(()) Ok(())
} }
+3 -8
View File
@@ -92,7 +92,7 @@ pub fn build_solidity_with_options(
SolcStandardJsonInputSettingsSelection::new_required(), SolcStandardJsonInputSettingsSelection::new_required(),
SolcStandardJsonInputSettingsOptimizer::new( SolcStandardJsonInputSettingsOptimizer::new(
solc_optimizer_enabled, solc_optimizer_enabled,
optimizer_settings.middle_end_as_string().chars().last(), None,
&solc_version.default, &solc_version.default,
false, false,
), ),
@@ -102,21 +102,16 @@ pub fn build_solidity_with_options(
let mut output = solc.standard_json(input, None, vec![], None)?; 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( let project = Project::try_from_standard_json_output(
&output, &output,
sources, sources,
libraries, libraries,
&solc_version, &solc_version,
&debug_config, &DEBUG_CONFIG,
)?; )?;
let build: crate::Build = 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)?; build.write_to_standard_json(&mut output, &solc_version)?;
Ok(output) Ok(output)
@@ -121,6 +121,11 @@ where
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
context.set_debug_location(self.location.line, 0, None)?; 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 { if self.bindings.len() == 1 {
let identifier = self.bindings.remove(0); let identifier = self.bindings.remove(0);
let pointer = context let pointer = context
@@ -134,31 +139,13 @@ where
identifier.inner, identifier.inner,
) )
})?; })?;
context.build_store(pointer, value.to_llvm())?;
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)?)?;
}
return Ok(()); return Ok(());
} }
let value = match self.initializer.into_llvm(context, &mut None)? { let llvm_type = value.to_llvm().into_struct_value().get_type();
Some(value) => value,
None => return Ok(()),
};
let value = value.access(context)?;
let llvm_type = value.into_struct_value().get_type();
let tuple_pointer = context.build_alloca(llvm_type, "assignment_pointer"); 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() { for (index, binding) in self.bindings.into_iter().enumerate() {
context.set_debug_location(self.location.line, 0, None)?; context.set_debug_location(self.location.line, 0, None)?;
@@ -184,7 +184,7 @@ where
block.into_llvm(context)?; block.into_llvm(context)?;
} }
Statement::Expression(expression) => { Statement::Expression(expression) => {
expression.into_llvm(context, &mut None)?; expression.into_llvm(context)?;
} }
Statement::VariableDeclaration(statement) => statement.into_llvm(context)?, Statement::VariableDeclaration(statement) => statement.into_llvm(context)?,
Statement::Assignment(statement) => statement.into_llvm(context)?, Statement::Assignment(statement) => statement.into_llvm(context)?,
@@ -118,7 +118,6 @@ impl FunctionCall {
pub fn into_llvm<'ctx, D>( pub fn into_llvm<'ctx, D>(
mut self, mut self,
context: &mut revive_llvm_context::PolkaVMContext<'ctx, D>, context: &mut revive_llvm_context::PolkaVMContext<'ctx, D>,
assignment_pointer: &mut Option<inkwell::values::PointerValue<'ctx>>,
) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>> ) -> anyhow::Result<Option<inkwell::values::BasicValueEnum<'ctx>>>
where where
D: revive_llvm_context::PolkaVMDependency + Clone, D: revive_llvm_context::PolkaVMDependency + Clone,
@@ -129,10 +128,7 @@ impl FunctionCall {
Name::UserDefined(name) => { Name::UserDefined(name) => {
let mut values = Vec::with_capacity(self.arguments.len()); let mut values = Vec::with_capacity(self.arguments.len());
for argument in self.arguments.into_iter().rev() { for argument in self.arguments.into_iter().rev() {
let value = argument let value = argument.into_llvm(context)?.expect("Always exists").value;
.into_llvm(context, &mut None)?
.expect("Always exists")
.access(context)?;
values.push(value); values.push(value);
} }
values.reverse(); values.reverse();
@@ -417,8 +413,8 @@ impl FunctionCall {
revive_llvm_context::polkavm_evm_memory::load( revive_llvm_context::polkavm_evm_memory::load(
context, context,
arguments[0].into_int_value(), arguments[0].into_int_value(),
assignment_pointer,
) )
.map(Some)
} }
Name::MStore => { Name::MStore => {
let arguments = self.pop_arguments_llvm::<D, 2>(context)?; let arguments = self.pop_arguments_llvm::<D, 2>(context)?;
@@ -465,33 +461,36 @@ impl FunctionCall {
} }
Name::SLoad => { 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( revive_llvm_context::polkavm_evm_storage::load(
context, context,
&arguments[0], arguments[0].into_int_value(),
assignment_pointer,
) )
.map(Some)
} }
Name::SStore => { 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( revive_llvm_context::polkavm_evm_storage::store(
context, context,
&arguments[0], arguments[0].into_int_value(),
&arguments[1], arguments[1].into_int_value(),
) )
.map(|_| None) .map(|_| None)
} }
Name::TLoad => { Name::TLoad => {
let arguments = self.pop_arguments::<D, 1>(context)?; let arguments = self.pop_arguments_llvm::<D, 1>(context)?;
revive_llvm_context::polkavm_evm_storage::transient_load(context, &arguments[0]) revive_llvm_context::polkavm_evm_storage::transient_load(
.map(Some) context,
arguments[0].into_int_value(),
)
.map(Some)
} }
Name::TStore => { 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( revive_llvm_context::polkavm_evm_storage::transient_store(
context, context,
&arguments[0], arguments[0].into_int_value(),
&arguments[1], arguments[1].into_int_value(),
) )
.map(|_| None) .map(|_| None)
} }
@@ -515,7 +514,7 @@ impl FunctionCall {
let offset = context.solidity_mut().allocate_immutable(key.as_str()) let offset = context.solidity_mut().allocate_immutable(key.as_str())
/ revive_common::BYTE_LENGTH_WORD; / revive_common::BYTE_LENGTH_WORD;
let index = context.xlen_type().const_int(offset as u64, false); 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) revive_llvm_context::polkavm_evm_immutable::store(context, index, value)
.map(|_| None) .map(|_| None)
} }
@@ -721,13 +720,13 @@ impl FunctionCall {
Name::Call => { Name::Call => {
let arguments = self.pop_arguments::<D, 7>(context)?; let arguments = self.pop_arguments::<D, 7>(context)?;
let gas = arguments[0].access(context)?.into_int_value(); let gas = arguments[0].value.into_int_value();
let address = arguments[1].access(context)?.into_int_value(); let address = arguments[1].value.into_int_value();
let value = arguments[2].access(context)?.into_int_value(); let value = arguments[2].value.into_int_value();
let input_offset = arguments[3].access(context)?.into_int_value(); let input_offset = arguments[3].value.into_int_value();
let input_size = arguments[4].access(context)?.into_int_value(); let input_size = arguments[4].value.into_int_value();
let output_offset = arguments[5].access(context)?.into_int_value(); let output_offset = arguments[5].value.into_int_value();
let output_size = arguments[6].access(context)?.into_int_value(); let output_size = arguments[6].value.into_int_value();
let simulation_address: Vec<Option<num::BigUint>> = arguments let simulation_address: Vec<Option<num::BigUint>> = arguments
.into_iter() .into_iter()
@@ -751,12 +750,12 @@ impl FunctionCall {
Name::StaticCall => { Name::StaticCall => {
let arguments = self.pop_arguments::<D, 6>(context)?; let arguments = self.pop_arguments::<D, 6>(context)?;
let gas = arguments[0].access(context)?.into_int_value(); let gas = arguments[0].value.into_int_value();
let address = arguments[1].access(context)?.into_int_value(); let address = arguments[1].value.into_int_value();
let input_offset = arguments[2].access(context)?.into_int_value(); let input_offset = arguments[2].value.into_int_value();
let input_size = arguments[3].access(context)?.into_int_value(); let input_size = arguments[3].value.into_int_value();
let output_offset = arguments[4].access(context)?.into_int_value(); let output_offset = arguments[4].value.into_int_value();
let output_size = arguments[5].access(context)?.into_int_value(); let output_size = arguments[5].value.into_int_value();
let simulation_address: Vec<Option<num::BigUint>> = arguments let simulation_address: Vec<Option<num::BigUint>> = arguments
.into_iter() .into_iter()
@@ -780,12 +779,12 @@ impl FunctionCall {
Name::DelegateCall => { Name::DelegateCall => {
let arguments = self.pop_arguments::<D, 6>(context)?; let arguments = self.pop_arguments::<D, 6>(context)?;
let gas = arguments[0].access(context)?.into_int_value(); let gas = arguments[0].value.into_int_value();
let address = arguments[1].access(context)?.into_int_value(); let address = arguments[1].value.into_int_value();
let input_offset = arguments[2].access(context)?.into_int_value(); let input_offset = arguments[2].value.into_int_value();
let input_size = arguments[3].access(context)?.into_int_value(); let input_size = arguments[3].value.into_int_value();
let output_offset = arguments[4].access(context)?.into_int_value(); let output_offset = arguments[4].value.into_int_value();
let output_size = arguments[5].access(context)?.into_int_value(); let output_size = arguments[5].value.into_int_value();
let simulation_address: Vec<Option<num::BigUint>> = arguments let simulation_address: Vec<Option<num::BigUint>> = arguments
.into_iter() .into_iter()
@@ -846,8 +845,7 @@ impl FunctionCall {
})?; })?;
revive_llvm_context::polkavm_evm_create::contract_hash(context, identifier) revive_llvm_context::polkavm_evm_create::contract_hash(context, identifier)
.and_then(|argument| argument.access(context)) .map(|argument| Some(argument.value))
.map(Some)
} }
Name::DataSize => { Name::DataSize => {
let mut arguments = self.pop_arguments::<D, 1>(context)?; 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) revive_llvm_context::polkavm_evm_create::header_size(context, identifier)
.and_then(|argument| argument.access(context)) .map(|argument| Some(argument.value))
.map(Some)
} }
Name::DataCopy => { Name::DataCopy => {
let arguments = self.pop_arguments_llvm::<D, 3>(context)?; let arguments = self.pop_arguments_llvm::<D, 3>(context)?;
@@ -992,12 +989,7 @@ impl FunctionCall {
{ {
let mut arguments = Vec::with_capacity(N); let mut arguments = Vec::with_capacity(N);
for expression in self.arguments.drain(0..N).rev() { for expression in self.arguments.drain(0..N).rev() {
arguments.push( arguments.push(expression.into_llvm(context)?.expect("Always exists").value);
expression
.into_llvm(context, &mut None)?
.expect("Always exists")
.access(context)?,
);
} }
arguments.reverse(); arguments.reverse();
@@ -1014,11 +1006,7 @@ impl FunctionCall {
{ {
let mut arguments = Vec::with_capacity(N); let mut arguments = Vec::with_capacity(N);
for expression in self.arguments.drain(0..N).rev() { for expression in self.arguments.drain(0..N).rev() {
arguments.push( arguments.push(expression.into_llvm(context)?.expect("Always exists"));
expression
.into_llvm(context, &mut None)?
.expect("Always exists"),
);
} }
arguments.reverse(); arguments.reverse();
@@ -97,7 +97,9 @@ impl Literal {
BooleanLiteral::True => num::BigUint::one(), 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) => { LexicalLiteral::Integer(inner) => {
let r#type = self.yul_type.unwrap_or_default().into_llvm(context); let r#type = self.yul_type.unwrap_or_default().into_llvm(context);
@@ -125,7 +127,9 @@ impl Literal {
} }
.expect("Always valid"); .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) => { LexicalLiteral::String(inner) => {
let string = inner.inner; let string = inner.inner;
@@ -196,10 +200,10 @@ impl Literal {
}; };
if hex_string.len() > revive_common::BYTE_LENGTH_WORD * 2 { 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(), r#type.const_zero().as_basic_value_enum(),
) string,
.with_original(string)); ));
} }
if hex_string.len() < revive_common::BYTE_LENGTH_WORD * 2 { if hex_string.len() < revive_common::BYTE_LENGTH_WORD * 2 {
@@ -216,7 +220,9 @@ impl Literal {
) )
.expect("The value is valid") .expect("The value is valid")
.as_basic_value_enum(); .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>( pub fn into_llvm<'ctx, D>(
self, self,
context: &mut revive_llvm_context::PolkaVMContext<'ctx, D>, context: &mut revive_llvm_context::PolkaVMContext<'ctx, D>,
assignment_pointer: &mut Option<inkwell::values::PointerValue<'ctx>>,
) -> anyhow::Result<Option<revive_llvm_context::PolkaVMArgument<'ctx>>> ) -> anyhow::Result<Option<revive_llvm_context::PolkaVMArgument<'ctx>>>
where where
D: revive_llvm_context::PolkaVMDependency + Clone, D: revive_llvm_context::PolkaVMDependency + Clone,
@@ -120,28 +119,36 @@ impl Expression {
}) })
.map(Some), .map(Some),
Self::Identifier(identifier) => { Self::Identifier(identifier) => {
let id = identifier.inner;
let pointer = context let pointer = context
.current_function() .current_function()
.borrow() .borrow()
.get_stack_pointer(&id) .get_stack_pointer(identifier.inner.as_str())
.ok_or_else(|| { .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 { match constant {
Some(constant) => argument.with_constant(constant), Some(constant) => Ok(Some(
_ => argument, revive_llvm_context::PolkaVMArgument::new_with_constant(value, constant),
})) )),
None => Ok(Some(value.into())),
}
} }
Self::FunctionCall(call) => Ok(call Self::FunctionCall(call) => Ok(call
.into_llvm(context, assignment_pointer)? .into_llvm(context)?
.map(revive_llvm_context::PolkaVMArgument::value)), .map(revive_llvm_context::PolkaVMArgument::new)),
} }
} }
} }
@@ -76,9 +76,9 @@ where
context.set_basic_block(condition_block); context.set_basic_block(condition_block);
let condition = self let condition = self
.condition .condition
.into_llvm(context, &mut None)? .into_llvm(context)?
.expect("Always exists") .expect("Always exists")
.access(context)? .to_llvm()
.into_int_value(); .into_int_value();
let condition = context.builder().build_int_z_extend_or_bit_cast( let condition = context.builder().build_int_z_extend_or_bit_cast(
condition, condition,
@@ -55,9 +55,9 @@ where
fn into_llvm(self, context: &mut revive_llvm_context::PolkaVMContext<D>) -> anyhow::Result<()> { fn into_llvm(self, context: &mut revive_llvm_context::PolkaVMContext<D>) -> anyhow::Result<()> {
let condition = self let condition = self
.condition .condition
.into_llvm(context, &mut None)? .into_llvm(context)?
.expect("Always exists") .expect("Always exists")
.access(context)? .to_llvm()
.into_int_value(); .into_int_value();
let condition = context.builder().build_int_z_extend_or_bit_cast( let condition = context.builder().build_int_z_extend_or_bit_cast(
condition, condition,
@@ -123,7 +123,7 @@ where
D: revive_llvm_context::PolkaVMDependency + Clone, D: revive_llvm_context::PolkaVMDependency + Clone,
{ {
fn into_llvm(self, context: &mut revive_llvm_context::PolkaVMContext<D>) -> anyhow::Result<()> { 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 self.cases.is_empty() {
if let Some(block) = self.default { if let Some(block) = self.default {
@@ -137,7 +137,7 @@ where
let mut branches = Vec::with_capacity(self.cases.len()); let mut branches = Vec::with_capacity(self.cases.len());
for (index, case) in self.cases.into_iter().enumerate() { 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 let expression_block = context
.append_basic_block(format!("switch_case_branch_{}_block", index + 1).as_str()); .append_basic_block(format!("switch_case_branch_{}_block", index + 1).as_str());
@@ -161,10 +161,7 @@ where
context.set_basic_block(current_block); context.set_basic_block(current_block);
context.builder().build_switch( context.builder().build_switch(
scrutinee scrutinee.expect("Always exists").to_llvm().into_int_value(),
.expect("Always exists")
.access(context)?
.into_int_value(),
default_block, default_block,
branches.as_slice(), branches.as_slice(),
)?; )?;
@@ -110,9 +110,8 @@ where
.borrow_mut() .borrow_mut()
.insert_stack_pointer(identifier.inner.clone(), pointer); .insert_stack_pointer(identifier.inner.clone(), pointer);
let mut assignment_pointer = Some(pointer.value);
let value = if let Some(expression) = self.expression { let value = if let Some(expression) = self.expression {
match expression.into_llvm(context, &mut assignment_pointer)? { match expression.into_llvm(context)? {
Some(mut value) => { Some(mut value) => {
if let Some(constant) = value.constant.take() { if let Some(constant) = value.constant.take() {
context context
@@ -122,16 +121,14 @@ where
.insert_constant(identifier.inner.clone(), constant); .insert_constant(identifier.inner.clone(), constant);
} }
value.access(context)? value.to_llvm()
} }
None => r#type.const_zero().as_basic_value_enum(), None => r#type.const_zero().as_basic_value_enum(),
} }
} else { } else {
r#type.const_zero().as_basic_value_enum() 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(()); return Ok(());
} }
@@ -159,7 +156,7 @@ where
None => return Ok(()), None => return Ok(()),
}; };
let location = expression.location(); let location = expression.location();
let expression = match expression.into_llvm(context, &mut None)? { let expression = match expression.into_llvm(context)? {
Some(expression) => expression, Some(expression) => expression,
None => return Ok(()), None => return Ok(()),
}; };
@@ -178,8 +175,7 @@ where
.collect::<Vec<inkwell::types::BasicTypeEnum<'ctx>>>() .collect::<Vec<inkwell::types::BasicTypeEnum<'ctx>>>()
.as_slice(), .as_slice(),
); );
let value = expression.access(context)?; if expression.value.get_type() != llvm_type.as_basic_type_enum() {
if value.get_type() != llvm_type.as_basic_type_enum() {
anyhow::bail!( anyhow::bail!(
"{} Assignment to {:?} received an invalid number of arguments", "{} Assignment to {:?} received an invalid number of arguments",
location, location,
@@ -187,7 +183,7 @@ where
); );
} }
let pointer = context.build_alloca(llvm_type, "bindings_pointer"); 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() { for (index, binding) in self.bindings.into_iter().enumerate() {
let pointer = context.build_gep( let pointer = context.build_gep(