mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-14 18:01:05 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 199b6145f2 | |||
| 36f9345c22 | |||
| 33d589ea7f | |||
| fdc44db1be | |||
| 76f815f33b | |||
| a293264028 | |||
| 7bf9d49166 | |||
| d5b9c489ea |
@@ -0,0 +1,6 @@
|
|||||||
|
FROM revive-llvm
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
RUN RUSTFLAGS='-L /app/llvm18.0/lib/unknown -L /usr/lib -L /app/llvm18.0/lib' REVIVE_INSTALL_DIR='/app/release/revive/' make install-revive
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
FROM alpine:3.20.3
|
||||||
|
|
||||||
|
ARG RUST_VERSION=stable
|
||||||
|
|
||||||
|
RUN apk add bash git cmake make ninja python3 ncurses-static curl
|
||||||
|
RUN ninja --version
|
||||||
|
|
||||||
|
COPY build-llvm.sh .
|
||||||
|
|
||||||
|
RUN bash -c ./build-llvm.sh
|
||||||
|
|
||||||
|
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain ${RUST_VERSION}
|
||||||
|
ENV PATH=/root/.cargo/bin:/llvm18.0/bin:${PATH}
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
RUN REVIVE_INSTALL_DIR=$(pwd)/target/release
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
name: Build revive-wasm
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: ["main"]
|
|
||||||
pull_request:
|
|
||||||
branches: ["main"]
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
REVIVE_WASM_INSTALL_DIR: ${{ github.workspace }}/target/wasm32-unknown-emscripten/release
|
|
||||||
EMSCRIPTEN_VERSION: 3.1.64
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-revive-wasm:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: bash
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Cache LLVM build
|
|
||||||
id: cache-llvm
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
llvm18.0-emscripten
|
|
||||||
# Use a unique key based on LLVM version or configuration files to avoid cache invalidation
|
|
||||||
key: llvm-build-${{ runner.os }}-${{ hashFiles('clone-llvm.sh', 'emscripten-build-llvm.sh') }}
|
|
||||||
|
|
||||||
- name: Install Dependencies
|
|
||||||
run: |
|
|
||||||
sudo apt-get update && sudo apt-get install -y cmake ninja-build libncurses5
|
|
||||||
rustup target add wasm32-unknown-emscripten
|
|
||||||
# Install LLVM required for the compiler runtime, runtime-api and stdlib
|
|
||||||
curl -sSL --output llvm.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.4/clang+llvm-18.1.4-x86_64-linux-gnu-ubuntu-18.04.tar.xz
|
|
||||||
tar Jxf llvm.tar.xz
|
|
||||||
mv clang+llvm-18.1.4-x86_64-linux-gnu-ubuntu-18.04 llvm18/
|
|
||||||
echo "$(pwd)/llvm18/bin" >> $GITHUB_PATH
|
|
||||||
# Install Emscripten
|
|
||||||
git clone https://github.com/emscripten-core/emsdk.git
|
|
||||||
cd emsdk
|
|
||||||
./emsdk install ${{ env.EMSCRIPTEN_VERSION }}
|
|
||||||
./emsdk activate ${{ env.EMSCRIPTEN_VERSION }}
|
|
||||||
|
|
||||||
- run: |
|
|
||||||
rustup show
|
|
||||||
cargo --version
|
|
||||||
rustup +nightly show
|
|
||||||
cargo +nightly --version
|
|
||||||
cmake --version
|
|
||||||
bash --version
|
|
||||||
llvm-config --version
|
|
||||||
|
|
||||||
- name: Build LLVM
|
|
||||||
if: steps.cache-llvm.outputs.cache-hit != 'true'
|
|
||||||
run: |
|
|
||||||
export EMSDK_ROOT=${PWD}/emsdk
|
|
||||||
./emscripten-build-llvm.sh
|
|
||||||
|
|
||||||
- name: Use Cached LLVM
|
|
||||||
if: steps.cache-llvm.outputs.cache-hit == 'true'
|
|
||||||
run: |
|
|
||||||
echo "Using cached LLVM"
|
|
||||||
|
|
||||||
- name: Build revive
|
|
||||||
run: |
|
|
||||||
export LLVM_LINK_PREFIX=${PWD}/llvm18.0-emscripten
|
|
||||||
source ./emsdk/emsdk_env.sh
|
|
||||||
make install-wasm
|
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: revive-wasm
|
|
||||||
path: |
|
|
||||||
${{ env.REVIVE_WASM_INSTALL_DIR }}/resolc.js
|
|
||||||
${{ env.REVIVE_WASM_INSTALL_DIR }}/resolc.wasm
|
|
||||||
retention-days: 1
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
name: Release
|
||||||
|
run-name: Release ${{ github.ref_name }}
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "[0-9]+.[0-9]+.[0-9]+"
|
||||||
|
- "[0-9]+.[0-9]+.[0-9]+-[a-zA-Z0-9]+"
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
CreateRelease:
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- name: Release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
draft: true
|
||||||
|
make_latest: true
|
||||||
|
|
||||||
|
Release:
|
||||||
|
needs: [CreateRelease]
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
steps:
|
||||||
|
- name: build llvm
|
||||||
|
run: docker build -t revive-llvm:latest --progress=plain -f --build-arg RUST_VERSION=1.80 .github/Dockerfile-llvm
|
||||||
|
|
||||||
|
- name: build revive
|
||||||
|
run: docker build -t revive:latest --progress=plain -f .github/Dockerfile
|
||||||
|
|
||||||
|
- name: get binary
|
||||||
|
run: docker run --rm revive:latest -v output:/app/output cp /app/release/revive/resolc /app/output
|
||||||
|
|
||||||
|
# docker push revive:latest
|
||||||
|
|
||||||
|
- run: gh release upload ${{ github.ref_name }} output/resolc --clobber
|
||||||
@@ -3,8 +3,6 @@ name: Build
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["main"]
|
branches: ["main"]
|
||||||
pull_request:
|
|
||||||
branches: ["main"]
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
name: Test
|
||||||
|
run-name: Test ${{ github.ref_name }}
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, synchronize, reopened, ready_for_review]
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Release:
|
||||||
|
# runs-on: ubuntu-20.04
|
||||||
|
runs-on: parity-large
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: build llvm
|
||||||
|
run: docker build -t revive-llvm:latest --progress=plain --build-arg RUST_VERSION=1.80 -f .github/Dockerfile-llvm .
|
||||||
|
|
||||||
|
- name: build revive
|
||||||
|
run: docker build -t revive:latest --progress=plain -f .github/Dockerfile
|
||||||
|
|
||||||
|
- name: get binary
|
||||||
|
run: docker run --rm revive:latest -v output:/app/output cp /app/release/revive/resolc /app/output .
|
||||||
|
|
||||||
|
# docker push revive:latest
|
||||||
|
|
||||||
|
- run: gh release upload ${{ github.ref_name }} output/resolc
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
/*.s
|
/*.s
|
||||||
/llvm-project
|
/llvm-project
|
||||||
/llvm18.0
|
/llvm18.0
|
||||||
/llvm18.0-emscripten
|
|
||||||
node_modules
|
node_modules
|
||||||
artifacts
|
artifacts
|
||||||
tmp
|
tmp
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
# Changelog
|
|
||||||
|
|
||||||
## Unreleased
|
|
||||||
|
|
||||||
## v0.1.0-dev.6
|
|
||||||
|
|
||||||
This is a development pre-release.
|
|
||||||
|
|
||||||
# Added
|
|
||||||
- Implement the `BLOCKHASH` opcode.
|
|
||||||
- Implement delegate calls.
|
|
||||||
- Implement the `GASPRICE` opcode. Currently hard-coded to return `1`.
|
|
||||||
- The ELF shared object contract artifact is dumped into the debug output directory.
|
|
||||||
- Initial support for emitting debug info (opt in via the `-g` flag)
|
|
||||||
|
|
||||||
# Changed
|
|
||||||
- resolc now emits 64bit PolkaVM blobs, reducing contract code size and execution time.
|
|
||||||
- The RISC-V bit-manipulation target feature (`zbb`) is enabled.
|
|
||||||
|
|
||||||
# Fixed
|
|
||||||
- Compilation to Wasm (for usage in node and web browsers)
|
|
||||||
|
|
||||||
|
|
||||||
## v0.1.0-dev.5
|
|
||||||
|
|
||||||
This is development pre-release.
|
|
||||||
|
|
||||||
# Added
|
|
||||||
- Implement the `CODESIZE` and `EXTCODESIZE` opcodes.
|
|
||||||
|
|
||||||
# Changed
|
|
||||||
- Include the full revive version in the contract metadata.
|
|
||||||
|
|
||||||
# Fixed
|
|
||||||
|
|
||||||
## v0.1.0-dev-4
|
|
||||||
|
|
||||||
This is development pre-release.
|
|
||||||
|
|
||||||
# Added
|
|
||||||
- Support the `ORIGIN` opcode.
|
|
||||||
|
|
||||||
# Changed
|
|
||||||
- Update polkavm to `v0.14.0`.
|
|
||||||
- Enable the `a`, `fast-unaligned-access` and `xtheadcondmov` LLVM target features, decreasing the code size for some contracts.
|
|
||||||
|
|
||||||
# Fixed
|
|
||||||
Generated
+851
-1178
File diff suppressed because it is too large
Load Diff
+19
-20
@@ -3,7 +3,7 @@ resolver = "2"
|
|||||||
members = ["crates/*"]
|
members = ["crates/*"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.1.0-dev.6"
|
version = "0.1.0"
|
||||||
authors = [
|
authors = [
|
||||||
"Cyrill Leutwiler <cyrill@parity.io>",
|
"Cyrill Leutwiler <cyrill@parity.io>",
|
||||||
"Parity Technologies <admin@parity.io>",
|
"Parity Technologies <admin@parity.io>",
|
||||||
@@ -14,18 +14,18 @@ repository = "https://github.com/paritytech/revive"
|
|||||||
rust-version = "1.80.0"
|
rust-version = "1.80.0"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
revive-benchmarks = { version = "0.1.0-dev.6", path = "crates/benchmarks" }
|
revive-benchmarks = { version = "0.1.0", path = "crates/benchmarks" }
|
||||||
revive-builtins = { version = "0.1.0-dev.6", path = "crates/builtins" }
|
revive-builtins = { version = "0.1.0", path = "crates/builtins" }
|
||||||
revive-common = { version = "0.1.0-dev.6", path = "crates/common" }
|
revive-common = { version = "0.1.0", path = "crates/common" }
|
||||||
revive-differential = { version = "0.1.0-dev.6", path = "crates/differential" }
|
revive-differential = { version = "0.1.0", path = "crates/differential" }
|
||||||
revive-integration = { version = "0.1.0-dev.6", path = "crates/integration" }
|
revive-integration = { version = "0.1.0", path = "crates/integration" }
|
||||||
revive-linker = { version = "0.1.0-dev.6", path = "crates/linker" }
|
revive-linker = { version = "0.1.0", path = "crates/linker" }
|
||||||
lld-sys = { version = "0.1.0-dev.6", path = "crates/lld-sys" }
|
lld-sys = { version = "0.1.0", path = "crates/lld-sys" }
|
||||||
revive-llvm-context = { version = "0.1.0-dev.6", path = "crates/llvm-context" }
|
revive-llvm-context = { version = "0.1.0", path = "crates/llvm-context" }
|
||||||
revive-runtime-api = { version = "0.1.0-dev.6", path = "crates/runtime-api" }
|
revive-runtime-api = { version = "0.1.0", path = "crates/runtime-api" }
|
||||||
revive-runner = { version = "0.1.0-dev.6", path = "crates/runner" }
|
revive-runner = { version = "0.1.0", path = "crates/runner" }
|
||||||
revive-solidity = { version = "0.1.0-dev.6", path = "crates/solidity" }
|
revive-solidity = { version = "0.1.0", path = "crates/solidity" }
|
||||||
revive-stdlib = { version = "0.1.0-dev.6", path = "crates/stdlib" }
|
revive-stdlib = { version = "0.1.0", path = "crates/stdlib" }
|
||||||
|
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
petgraph = "0.6"
|
petgraph = "0.6"
|
||||||
@@ -51,10 +51,10 @@ path-slash = "0.2"
|
|||||||
rayon = "1.8"
|
rayon = "1.8"
|
||||||
clap = { version = "4", default-features = false, features = ["derive"] }
|
clap = { version = "4", default-features = false, features = ["derive"] }
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
polkavm-common = "0.17"
|
polkavm-common = "0.13"
|
||||||
polkavm-linker = "0.17"
|
polkavm-linker = "0.13"
|
||||||
polkavm-disassembler = "0.17"
|
polkavm-disassembler = "0.13"
|
||||||
polkavm = "0.17"
|
polkavm = "0.13"
|
||||||
alloy-primitives = { version = "0.8", features = ["serde"] }
|
alloy-primitives = { version = "0.8", features = ["serde"] }
|
||||||
alloy-sol-types = "0.8"
|
alloy-sol-types = "0.8"
|
||||||
alloy-genesis = "0.3"
|
alloy-genesis = "0.3"
|
||||||
@@ -67,12 +67,11 @@ log = { version = "0.4" }
|
|||||||
# polkadot-sdk and friends
|
# polkadot-sdk and friends
|
||||||
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
|
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
|
||||||
scale-info = { version = "2.11.1", default-features = false }
|
scale-info = { version = "2.11.1", default-features = false }
|
||||||
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "447902eff4a574e66894ad60cb41999b05bf5e84" }
|
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "aeebf2f383390f2f86527d70212162d5dbea8b93" }
|
||||||
|
|
||||||
# llvm
|
# llvm
|
||||||
[workspace.dependencies.inkwell]
|
[workspace.dependencies.inkwell]
|
||||||
git = "https://github.com/TheDan64/inkwell.git"
|
version = "0.5"
|
||||||
rev = "7b410298b6a93450adaa90b1841d5805a3038f12"
|
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["serde", "llvm18-0", "no-libffi-linking", "target-riscv"]
|
features = ["serde", "llvm18-0", "no-libffi-linking", "target-riscv"]
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,5 @@
|
|||||||
.PHONY: install format test test-solidity test-cli test-integration test-workspace clean docs docs-build
|
.PHONY: install format test test-solidity test-cli test-integration test-workspace clean docs docs-build
|
||||||
|
|
||||||
RUSTFLAGS_EMSCRIPTEN := \
|
|
||||||
-Clink-arg=-sEXPORTED_FUNCTIONS=_main,_free,_malloc \
|
|
||||||
-Clink-arg=-sNO_INVOKE_RUN \
|
|
||||||
-Clink-arg=-sEXIT_RUNTIME \
|
|
||||||
-Clink-arg=-sINITIAL_MEMORY=64MB \
|
|
||||||
-Clink-arg=-sTOTAL_MEMORY=3GB \
|
|
||||||
-Clink-arg=-sALLOW_MEMORY_GROWTH \
|
|
||||||
-Clink-arg=-sEXPORTED_RUNTIME_METHODS=FS,callMain,stringToNewUTF8,cwrap \
|
|
||||||
-Clink-arg=-sMODULARIZE \
|
|
||||||
-Clink-arg=-sEXPORT_NAME=createRevive \
|
|
||||||
-Clink-arg=-sWASM_ASYNC_COMPILATION=0 \
|
|
||||||
-Clink-arg=--js-library=js/embed/soljson_interface.js \
|
|
||||||
-Clink-arg=--pre-js=js/embed/pre.js
|
|
||||||
|
|
||||||
install: install-bin install-npm
|
install: install-bin install-npm
|
||||||
|
|
||||||
install-bin:
|
install-bin:
|
||||||
@@ -22,10 +8,6 @@ install-bin:
|
|||||||
install-npm:
|
install-npm:
|
||||||
npm install && npm fund
|
npm install && npm fund
|
||||||
|
|
||||||
install-wasm:
|
|
||||||
RUSTFLAGS='$(RUSTFLAGS_EMSCRIPTEN)' cargo build --target wasm32-unknown-emscripten -p revive-solidity --release --no-default-features
|
|
||||||
npm install
|
|
||||||
|
|
||||||
# install-revive: Build and install to the directory specified in REVIVE_INSTALL_DIR
|
# install-revive: Build and install to the directory specified in REVIVE_INSTALL_DIR
|
||||||
ifeq ($(origin REVIVE_INSTALL_DIR), undefined)
|
ifeq ($(origin REVIVE_INSTALL_DIR), undefined)
|
||||||
REVIVE_INSTALL_DIR=`pwd`/release/revive-debian
|
REVIVE_INSTALL_DIR=`pwd`/release/revive-debian
|
||||||
@@ -76,6 +58,4 @@ clean:
|
|||||||
rm -rf node_modules ; \
|
rm -rf node_modules ; \
|
||||||
rm -rf crates/solidity/src/tests/cli-tests/artifacts ; \
|
rm -rf crates/solidity/src/tests/cli-tests/artifacts ; \
|
||||||
cargo uninstall revive-solidity ; \
|
cargo uninstall revive-solidity ; \
|
||||||
rm -f package-lock.json ; \
|
rm -f package-lock.json
|
||||||
rm -rf js/dist ; \
|
|
||||||
rm -f js/src/resolc.{wasm,js}
|
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||

|

|
||||||
[](https://contracts.polkadot.io)
|
|
||||||
|
|
||||||
# revive
|
# revive
|
||||||
|
|
||||||
YUL and EVM assembly recompiler to LLVM, targetting RISC-V on [PolkaVM](https://github.com/koute/polkavm).
|
YUL and EVM assembly recompiler to LLVM, targetting RISC-V on [PolkaVM](https://github.com/koute/polkavm).
|
||||||
|
|
||||||
Visit [contracts.polkadot.io](https://contracts.polkadot.io) to learn more about contracts on Polkadot!
|
[Frontend](https://github.com/matter-labs/era-compiler-solidity) and [code generator](https://github.com/matter-labs/era-compiler-llvm-context) are based of ZKSync `zksolc`.
|
||||||
|
|
||||||
## Status
|
## Status
|
||||||
|
|
||||||
This is experimental software in active development and not ready just yet for production usage. Please do report any compiler related issues or missing features that are [not yet known to us](https://contracts.polkadot.io/known_issues/) here.
|
This is experimental software in active development and not ready just yet for production usage.
|
||||||
|
|
||||||
Discussion around the development is hosted on the [Polkadot Forum](https://forum.polkadot.network/t/contracts-update-solidity-on-polkavm/6949#a-new-solidity-compiler-1).
|
Discussion around the development is hosted on the [Polkadot Forum](https://forum.polkadot.network/t/contracts-update-solidity-on-polkavm/6949#a-new-solidity-compiler-1).
|
||||||
|
|
||||||
@@ -28,25 +27,7 @@ resolc --version
|
|||||||
|
|
||||||
### LLVM
|
### LLVM
|
||||||
|
|
||||||
`revive` requires a build of LLVM 18.1.4 or later including `compiler-rt`. Use the provided [build-llvm.sh](build-llvm.sh) build script to compile a compatible LLVM build locally in `$PWD/llvm18.0` (don't forget to add that to `$PATH` afterwards).
|
`revive` requires a build of LLVM 18.1.4 or later including `compiler-rt`. Use the provided [build-llvm.sh](build-llvm.sh) build script to compile a compatible LLVM build locally in `$PWD/llvm18.0` (don't forget to add that to `$PATH` afterwards).
|
||||||
|
|
||||||
### Cross-compilation to WASM
|
|
||||||
|
|
||||||
Cross-compiles the Revive compiler to WASM for running it in a Node.js or browser environment.
|
|
||||||
|
|
||||||
Install [emscripten](https://emscripten.org/docs/getting_started/downloads.html). Tested on version 3.1.64.
|
|
||||||
To build resolc.js execute:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
bash build-llvm.sh
|
|
||||||
export PATH=${PWD}/llvm18.0/bin:$PATH
|
|
||||||
export EMSDK_ROOT=<PATH_TO_EMSCRIPTEN_SDK>
|
|
||||||
bash emscripten-build-llvm.sh
|
|
||||||
source $EMSDK_ROOT/emsdk_env.sh
|
|
||||||
export LLVM_LINK_PREFIX=${PWD}/llvm18.0-emscripten
|
|
||||||
export PATH=$PATH:$PWD/llvm18.0-emscripten/bin/
|
|
||||||
make install-wasm
|
|
||||||
```
|
|
||||||
|
|
||||||
### Development
|
### Development
|
||||||
|
|
||||||
@@ -54,15 +35,4 @@ Please consult the [Makefile](Makefile) targets to learn how to run tests and be
|
|||||||
Ensure that your branch passes `make test` locally when submitting a pull request.
|
Ensure that your branch passes `make test` locally when submitting a pull request.
|
||||||
|
|
||||||
## Design overview
|
## Design overview
|
||||||
|
|
||||||
`revive` uses [solc](https://github.com/ethereum/solidity/), the Ethereum Solidity compiler, as the [Solidity frontend](crates/solidity/src/lib.rs) to process smart contracts written in Solidity. The YUL IR code (or legacy EVM assembly as a fallback for older `solc` versions) emitted by `solc` is then translated to LLVM IR, targetting [Polkadots `revive` pallet](https://docs.rs/pallet-revive/latest/pallet_revive/trait.SyscallDoc.html).
|
`revive` uses [solc](https://github.com/ethereum/solidity/), the Ethereum Solidity compiler, as the [Solidity frontend](crates/solidity/src/lib.rs) to process smart contracts written in Solidity. The YUL IR code (or legacy EVM assembly as a fallback for older `solc` versions) emitted by `solc` is then translated to LLVM IR, targetting [Polkadots `revive` pallet](https://docs.rs/pallet-revive/latest/pallet_revive/trait.SyscallDoc.html).
|
||||||
[Frontend](https://github.com/matter-labs/era-compiler-solidity) and [code generator](https://github.com/matter-labs/era-compiler-llvm-context) are based of ZKSync `zksolc`.
|
|
||||||
|
|
||||||
## Tests
|
|
||||||
|
|
||||||
Before running the tests, ensure that Geth (Go Ethereum) is installed on your system. Follow the installation guide here: [Installing Geth](https://geth.ethereum.org/docs/getting-started/installing-geth).
|
|
||||||
Once Geth is installed, you can run the tests using the following command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
make test
|
|
||||||
```
|
|
||||||
|
|||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
# Release checklist
|
|
||||||
|
|
||||||
Prior to the first stable release we neither have formal release processes nor do we follow a fixed release schedule.
|
|
||||||
|
|
||||||
To create a new pre-release:
|
|
||||||
|
|
||||||
1. Merge a release PR which updates the `-dev.X` versions in the workspace `Cargo.toml` and updates the `CHANGELOG.md` accordingly
|
|
||||||
2. Push a release tag to `main`
|
|
||||||
3. Manually trigger the `Build revive-debian` action
|
|
||||||
4. Create a __pre-release__ from the tag and manually upload the build artifact generated by the action
|
|
||||||
5. Update the [contract-docs](https://github.com/paritytech/contract-docs/) accordingly
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
# Known issues
|
|
||||||
|
|
||||||
The following is known and we are either working on it or it is a hard limitation. Please do not open a new issue.
|
|
||||||
|
|
||||||
## Release
|
|
||||||
|
|
||||||
`0.1.0-dev-2`
|
|
||||||
|
|
||||||
## Missing features
|
|
||||||
|
|
||||||
- [Libraries with public functions are not supported](https://github.com/paritytech/revive/issues/91)
|
|
||||||
- [Automatic import resolution is not supported](https://github.com/paritytech/revive/issues/98)
|
|
||||||
- The emulated EVM linear contract memory is limited to 64kb in size. Will be fixed with support for metered dynamic memory.
|
|
||||||
- [The contract calldata is currently limited to 1kb in size](https://github.com/paritytech/revive/issues/57)
|
|
||||||
- [EIP-4844 opcodes are not supported](https://github.com/paritytech/revive/issues/64)
|
|
||||||
- [Delegate calls are not supported](https://github.com/paritytech/revive/issues/67)
|
|
||||||
- [The `blockhash` opcode is not supported](https://github.com/paritytech/revive/issues/61)
|
|
||||||
- [The `extcodesize` opcode is not supported](https://github.com/paritytech/revive/issues/58)
|
|
||||||
- [The `origin` opcode is not supported](https://github.com/paritytech/revive/issues/59)
|
|
||||||
- [Gas limits for contract calls are ignored](https://github.com/paritytech/revive/issues/60)
|
|
||||||
- [Gas related opcodes are not supported](https://github.com/paritytech/revive/issues/60)
|
|
||||||
- IPFS metadata hashes are not supported
|
|
||||||
- [Compiled contract artifacts can exceed the pallet static memory limit and fail to deploy](https://github.com/paritytech/revive/issues/96).
|
|
||||||
- [Transfers to inexistant accounts will fail if the transferred value lies below the ED.](https://github.com/paritytech/revive/issues/83) Will be fixed in the pallet to make the ED completely transparent for contracts.
|
|
||||||
|
|
||||||
## Wontfix
|
|
||||||
|
|
||||||
Please consult our documentation to learn more about Solidity and EVM features likely to remain unsupported (and why they will not be supported).
|
|
||||||
|
|
||||||
TODO: Insert link to the relevant documentation section.
|
|
||||||
+7
-3
@@ -5,13 +5,17 @@ set -euo pipefail
|
|||||||
INSTALL_DIR="${PWD}/llvm18.0"
|
INSTALL_DIR="${PWD}/llvm18.0"
|
||||||
mkdir -p ${INSTALL_DIR}
|
mkdir -p ${INSTALL_DIR}
|
||||||
|
|
||||||
|
|
||||||
|
# Clone LLVM 18 (any revision after commit bd32aaa is supposed to work)
|
||||||
|
if [ ! -d "llvm-project" ]; then
|
||||||
|
git clone --depth 1 --branch release/18.x https://github.com/llvm/llvm-project.git
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Build LLVM, clang
|
# Build LLVM, clang
|
||||||
LLVM_SRC_PREFIX=${PWD}/llvm-project
|
LLVM_SRC_PREFIX=${PWD}/llvm-project
|
||||||
LLVM_SRC_DIR=${LLVM_SRC_PREFIX}/llvm
|
LLVM_SRC_DIR=${LLVM_SRC_PREFIX}/llvm
|
||||||
LLVM_BUILD_DIR=${PWD}/build/llvm
|
LLVM_BUILD_DIR=${PWD}/build/llvm
|
||||||
|
|
||||||
./clone-llvm.sh "${LLVM_SRC_PREFIX}"
|
|
||||||
|
|
||||||
if [ ! -d ${LLVM_BUILD_DIR} ] ; then
|
if [ ! -d ${LLVM_BUILD_DIR} ] ; then
|
||||||
mkdir -p ${LLVM_BUILD_DIR}
|
mkdir -p ${LLVM_BUILD_DIR}
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
# Default directory for cloning the llvm-project repository
|
|
||||||
DEFAULT_DIR="llvm-project"
|
|
||||||
|
|
||||||
# Check if a directory argument is provided
|
|
||||||
if [ $# -eq 1 ]; then
|
|
||||||
DIR=$1
|
|
||||||
else
|
|
||||||
DIR=$DEFAULT_DIR
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Clone LLVM 18 (any revision after commit bd32aaa is supposed to work)
|
|
||||||
if [ ! -d "${DIR}" ]; then
|
|
||||||
git clone --depth 1 --branch release/18.x https://github.com/llvm/llvm-project.git "${DIR}"
|
|
||||||
fi
|
|
||||||
@@ -17,56 +17,56 @@
|
|||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:--------|:------------------------|:-------------------------------- |
|
|:--------|:------------------------|:-------------------------------- |
|
||||||
| **`0`** | `3.36 us` (✅ **1.00x**) | `11.84 us` (❌ *3.52x slower*) |
|
| **`0`** | `5.97 us` (✅ **1.00x**) | `27.04 us` (❌ *4.53x slower*) |
|
||||||
|
|
||||||
### OddPorduct
|
### OddPorduct
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:-------------|:-------------------------|:-------------------------------- |
|
|:-------------|:--------------------------|:-------------------------------- |
|
||||||
| **`10000`** | `3.11 ms` (✅ **1.00x**) | `1.53 ms` (🚀 **2.03x faster**) |
|
| **`10000`** | `4.26 ms` (✅ **1.00x**) | `2.88 ms` (✅ **1.48x faster**) |
|
||||||
| **`100000`** | `30.70 ms` (✅ **1.00x**) | `15.54 ms` (🚀 **1.98x faster**) |
|
| **`100000`** | `42.37 ms` (✅ **1.00x**) | `28.35 ms` (✅ **1.49x faster**) |
|
||||||
| **`300000`** | `92.68 ms` (✅ **1.00x**) | `45.47 ms` (🚀 **2.04x faster**) |
|
| **`300000`** | `127.88 ms` (✅ **1.00x**) | `88.43 ms` (✅ **1.45x faster**) |
|
||||||
|
|
||||||
### TriangleNumber
|
### TriangleNumber
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:-------------|:-------------------------|:-------------------------------- |
|
|:-------------|:--------------------------|:-------------------------------- |
|
||||||
| **`10000`** | `2.29 ms` (✅ **1.00x**) | `1.09 ms` (🚀 **2.11x faster**) |
|
| **`10000`** | `2.85 ms` (✅ **1.00x**) | `2.37 ms` (✅ **1.20x faster**) |
|
||||||
| **`100000`** | `22.84 ms` (✅ **1.00x**) | `10.66 ms` (🚀 **2.14x faster**) |
|
| **`100000`** | `27.85 ms` (✅ **1.00x**) | `23.01 ms` (✅ **1.21x faster**) |
|
||||||
| **`360000`** | `82.29 ms` (✅ **1.00x**) | `37.01 ms` (🚀 **2.22x faster**) |
|
| **`360000`** | `103.01 ms` (✅ **1.00x**) | `83.66 ms` (✅ **1.23x faster**) |
|
||||||
|
|
||||||
### FibonacciRecursive
|
### FibonacciRecursive
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:---------|:--------------------------|:--------------------------------- |
|
|:---------|:--------------------------|:--------------------------------- |
|
||||||
| **`12`** | `135.67 us` (✅ **1.00x**) | `125.02 us` (✅ **1.09x faster**) |
|
| **`12`** | `195.19 us` (✅ **1.00x**) | `333.53 us` (❌ *1.71x slower*) |
|
||||||
| **`16`** | `903.75 us` (✅ **1.00x**) | `762.79 us` (✅ **1.18x faster**) |
|
| **`16`** | `1.22 ms` (✅ **1.00x**) | `1.97 ms` (❌ *1.62x slower*) |
|
||||||
| **`20`** | `6.12 ms` (✅ **1.00x**) | `4.96 ms` (✅ **1.23x faster**) |
|
| **`20`** | `8.14 ms` (✅ **1.00x**) | `13.20 ms` (❌ *1.62x slower*) |
|
||||||
| **`24`** | `42.05 ms` (✅ **1.00x**) | `33.86 ms` (✅ **1.24x faster**) |
|
| **`24`** | `55.09 ms` (✅ **1.00x**) | `88.56 ms` (❌ *1.61x slower*) |
|
||||||
|
|
||||||
### FibonacciIterative
|
### FibonacciIterative
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:----------|:-------------------------|:-------------------------------- |
|
|:----------|:-------------------------|:--------------------------------- |
|
||||||
| **`64`** | `15.04 us` (✅ **1.00x**) | `29.45 us` (❌ *1.96x slower*) |
|
| **`64`** | `33.39 us` (✅ **1.00x**) | `86.02 us` (❌ *2.58x slower*) |
|
||||||
| **`128`** | `26.36 us` (✅ **1.00x**) | `42.19 us` (❌ *1.60x slower*) |
|
| **`128`** | `52.91 us` (✅ **1.00x**) | `126.38 us` (❌ *2.39x slower*) |
|
||||||
| **`256`** | `48.61 us` (✅ **1.00x**) | `65.71 us` (❌ *1.35x slower*) |
|
| **`256`** | `82.33 us` (✅ **1.00x**) | `208.74 us` (❌ *2.54x slower*) |
|
||||||
|
|
||||||
### FibonacciBinet
|
### FibonacciBinet
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:----------|:-------------------------|:-------------------------------- |
|
|:----------|:-------------------------|:--------------------------------- |
|
||||||
| **`64`** | `15.22 us` (✅ **1.00x**) | `41.46 us` (❌ *2.72x slower*) |
|
| **`64`** | `32.29 us` (✅ **1.00x**) | `161.75 us` (❌ *5.01x slower*) |
|
||||||
| **`128`** | `17.05 us` (✅ **1.00x**) | `42.84 us` (❌ *2.51x slower*) |
|
| **`128`** | `36.02 us` (✅ **1.00x**) | `172.59 us` (❌ *4.79x slower*) |
|
||||||
| **`256`** | `19.00 us` (✅ **1.00x**) | `44.36 us` (❌ *2.34x slower*) |
|
| **`256`** | `41.21 us` (✅ **1.00x**) | `185.30 us` (❌ *4.50x slower*) |
|
||||||
|
|
||||||
### SHA1
|
### SHA1
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:----------|:--------------------------|:--------------------------------- |
|
|:----------|:--------------------------|:--------------------------------- |
|
||||||
| **`1`** | `110.04 us` (✅ **1.00x**) | `216.11 us` (❌ *1.96x slower*) |
|
| **`1`** | `160.17 us` (✅ **1.00x**) | `403.46 us` (❌ *2.52x slower*) |
|
||||||
| **`64`** | `209.04 us` (✅ **1.00x**) | `309.48 us` (❌ *1.48x slower*) |
|
| **`64`** | `286.69 us` (✅ **1.00x**) | `479.79 us` (❌ *1.67x slower*) |
|
||||||
| **`512`** | `903.65 us` (✅ **1.00x**) | `980.49 us` (✅ **1.09x slower**) |
|
| **`512`** | `1.18 ms` (✅ **1.00x**) | `1.37 ms` (❌ *1.16x slower*) |
|
||||||
|
|
||||||
---
|
---
|
||||||
Made with [criterion-table](https://github.com/nu11ptr/criterion-table)
|
Made with [criterion-table](https://github.com/nu11ptr/criterion-table)
|
||||||
|
|||||||
@@ -8,4 +8,7 @@ authors.workspace = true
|
|||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
description = "compiler builtins for the revive compiler"
|
description = "compiler builtins for the revive compiler"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
riscv-64 = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
use std::{env, fs, io::Read, path::Path, process::Command};
|
use std::{env, fs, io::Read, path::Path, process::Command};
|
||||||
|
|
||||||
|
#[cfg(not(feature = "riscv-64"))]
|
||||||
|
pub const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv32.a";
|
||||||
|
#[cfg(feature = "riscv-64")]
|
||||||
pub const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv64.a";
|
pub const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv64.a";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ description = "Shared constants of the revive compiler"
|
|||||||
[lib]
|
[lib]
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
|
[features]
|
||||||
|
riscv-64 = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
serde = { workspace = true, features = ["derive"] }
|
serde = { workspace = true, features = ["derive"] }
|
||||||
|
|||||||
@@ -41,6 +41,3 @@ pub static EXTENSION_POLKAVM_ASSEMBLY: &str = "pvmasm";
|
|||||||
|
|
||||||
/// The PolkaVM bytecode file extension.
|
/// The PolkaVM bytecode file extension.
|
||||||
pub static EXTENSION_POLKAVM_BINARY: &str = "pvm";
|
pub static EXTENSION_POLKAVM_BINARY: &str = "pvm";
|
||||||
|
|
||||||
/// The ELF shared object file extension.
|
|
||||||
pub static EXTENSION_SHARED_OBJECT: &str = "so";
|
|
||||||
|
|||||||
@@ -557,7 +557,6 @@ allocated bytes: 3711"#;
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore] // https://github.com/ethereum/go-ethereum/issues/30778
|
|
||||||
fn bench_flipper() {
|
fn bench_flipper() {
|
||||||
let log_runtime = Evm::default()
|
let log_runtime = Evm::default()
|
||||||
.code_blob(EVM_BIN_RUNTIME_FIXTURE.as_bytes().to_vec())
|
.code_blob(EVM_BIN_RUNTIME_FIXTURE.as_bytes().to_vec())
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"Baseline": 1073,
|
"Baseline": 989,
|
||||||
"Computation": 2469,
|
"Computation": 4153,
|
||||||
"DivisionArithmetics": 15041,
|
"DivisionArithmetics": 40614,
|
||||||
"ERC20": 23282,
|
"ERC20": 47343,
|
||||||
"Events": 1615,
|
"Events": 1781,
|
||||||
"FibonacciIterative": 1676,
|
"FibonacciIterative": 3035,
|
||||||
"Flipper": 2378,
|
"Flipper": 3393,
|
||||||
"SHA1": 17076
|
"SHA1": 33553
|
||||||
}
|
}
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
pragma solidity ^0.8;
|
|
||||||
|
|
||||||
/* runner.json
|
|
||||||
{
|
|
||||||
"differential": false,
|
|
||||||
"actions": [
|
|
||||||
{
|
|
||||||
"Instantiate": {
|
|
||||||
"code": {
|
|
||||||
"Solidity": {
|
|
||||||
"contract": "BlockHash"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"data": "4545454545454545454545454545454545454545454545454545454545454545"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
contract BlockHash {
|
|
||||||
constructor(bytes32 expected) payable {
|
|
||||||
assert(blockhash(0) == expected);
|
|
||||||
assert(blockhash(1) == 0);
|
|
||||||
assert(
|
|
||||||
blockhash(
|
|
||||||
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
|
|
||||||
) == 0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
pragma solidity ^0.8;
|
|
||||||
|
|
||||||
/* runner.json
|
|
||||||
{
|
|
||||||
"differential": true,
|
|
||||||
"actions": [
|
|
||||||
{
|
|
||||||
"Upload": {
|
|
||||||
"code": {
|
|
||||||
"Solidity": {
|
|
||||||
"contract": "Logic"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Instantiate": {
|
|
||||||
"code": {
|
|
||||||
"Solidity": {
|
|
||||||
"contract": "Tester"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Call": {
|
|
||||||
"dest": {
|
|
||||||
"Instantiated": 0
|
|
||||||
},
|
|
||||||
"value": 123,
|
|
||||||
"data": "6466414b0000000000000000000000000000000000000000000000000000000000000020"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
contract Logic {
|
|
||||||
// NOTE: storage layout must be the same as contract Tester
|
|
||||||
uint256 public num;
|
|
||||||
address public sender;
|
|
||||||
uint256 public value;
|
|
||||||
|
|
||||||
uint public immutable multiplier = 4;
|
|
||||||
|
|
||||||
event DidSetVars();
|
|
||||||
|
|
||||||
function setVars(uint256 _num) public payable returns (uint256) {
|
|
||||||
num = _num * multiplier;
|
|
||||||
sender = msg.sender;
|
|
||||||
value = msg.value;
|
|
||||||
emit DidSetVars();
|
|
||||||
return _num;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
contract Tester {
|
|
||||||
uint256 public num;
|
|
||||||
address public sender;
|
|
||||||
uint256 public value;
|
|
||||||
|
|
||||||
uint public immutable multiplier = 2;
|
|
||||||
|
|
||||||
function setVars(uint256 _num) public payable returns (bool, bytes memory) {
|
|
||||||
Logic impl = new Logic();
|
|
||||||
|
|
||||||
// Tester's storage is set, Logic is not modified.
|
|
||||||
(bool success, bytes memory data) = address(impl).delegatecall(
|
|
||||||
abi.encodeWithSignature("setVars(uint256)", _num)
|
|
||||||
);
|
|
||||||
|
|
||||||
assert(success);
|
|
||||||
assert(impl.num() == 0);
|
|
||||||
assert(impl.sender() == address(0));
|
|
||||||
assert(impl.value() == 0);
|
|
||||||
assert(num == _num * 4);
|
|
||||||
assert(sender == msg.sender);
|
|
||||||
assert(value == msg.value);
|
|
||||||
|
|
||||||
return (success, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,27 +4,11 @@ pragma solidity ^0.8;
|
|||||||
|
|
||||||
/* runner.json
|
/* runner.json
|
||||||
{
|
{
|
||||||
"differential": true,
|
|
||||||
"actions": [
|
"actions": [
|
||||||
{
|
{
|
||||||
"Upload": {
|
"Instantiate": {}
|
||||||
"code": {
|
}
|
||||||
"Solidity": {
|
]
|
||||||
"contract": "ERC20"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Instantiate": {
|
|
||||||
"code": {
|
|
||||||
"Solidity": {
|
|
||||||
"contract": "ERC20Tester"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -98,26 +82,3 @@ contract ERC20 is IERC20 {
|
|||||||
emit Transfer(msg.sender, address(0), amount);
|
emit Transfer(msg.sender, address(0), amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract ERC20Tester {
|
|
||||||
constructor() {
|
|
||||||
address BOB = address(0xffffffffffffffffffffffffffffffffffffff);
|
|
||||||
ERC20 token = new ERC20();
|
|
||||||
assert(token.decimals() == 18);
|
|
||||||
|
|
||||||
token.mint(300);
|
|
||||||
assert(token.balanceOf(address(this)) == 300);
|
|
||||||
token.transfer(BOB, 100);
|
|
||||||
assert(token.balanceOf(address(this)) == 200);
|
|
||||||
assert(token.balanceOf(BOB) == 100);
|
|
||||||
|
|
||||||
token.approve(address(this), 100);
|
|
||||||
|
|
||||||
token.transferFrom(address(this), BOB, 100);
|
|
||||||
assert(token.balanceOf(BOB) == 200);
|
|
||||||
assert(token.balanceOf(address(this)) == 100);
|
|
||||||
|
|
||||||
token.burn(100);
|
|
||||||
assert(token.balanceOf(address(this)) == 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
pragma solidity ^0.8;
|
|
||||||
|
|
||||||
/* runner.json
|
|
||||||
{
|
|
||||||
"differential": false,
|
|
||||||
"actions": [
|
|
||||||
{
|
|
||||||
"Instantiate": {
|
|
||||||
"code": {
|
|
||||||
"Solidity": {
|
|
||||||
"contract": "GasPrice"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"VerifyCall": {
|
|
||||||
"success": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
contract GasPrice {
|
|
||||||
constructor() payable {
|
|
||||||
assert(tx.gasprice == 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -22,14 +22,6 @@ pragma solidity ^0.8;
|
|||||||
},
|
},
|
||||||
"data": "fabc9efaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
"data": "fabc9efaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"Call": {
|
|
||||||
"dest": {
|
|
||||||
"Instantiated": 0
|
|
||||||
},
|
|
||||||
"data": "558b9f9bffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -38,18 +30,10 @@ pragma solidity ^0.8;
|
|||||||
contract Storage {
|
contract Storage {
|
||||||
function transient(uint value) public returns (uint ret) {
|
function transient(uint value) public returns (uint ret) {
|
||||||
assembly {
|
assembly {
|
||||||
let slot := 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00
|
let slot := 123
|
||||||
tstore(slot, value)
|
tstore(slot, value)
|
||||||
let success := call(0, 0, 0, 0, 0, 0, 0)
|
let success := call(0, 0, 0, 0, 0, 0, 0)
|
||||||
ret := tload(slot)
|
ret := tload(slot)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function persistent(uint value) public returns (uint ret) {
|
|
||||||
assembly {
|
|
||||||
let slot := 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00
|
|
||||||
sstore(slot, value)
|
|
||||||
ret := sload(slot)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
|
||||||
pragma solidity ^0.8.0;
|
|
||||||
|
|
||||||
/* runner.json
|
|
||||||
{
|
|
||||||
"differential": true,
|
|
||||||
"actions": [
|
|
||||||
{
|
|
||||||
"Upload": {
|
|
||||||
"code": {
|
|
||||||
"Solidity": {
|
|
||||||
"contract": "TransactionOrigin"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Instantiate": {
|
|
||||||
"code": {
|
|
||||||
"Solidity": {
|
|
||||||
"contract": "TransactionTester"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Call": {
|
|
||||||
"dest": {
|
|
||||||
"Instantiated": 0
|
|
||||||
},
|
|
||||||
"data": "f8a8fd6d"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
contract TransactionTester {
|
|
||||||
constructor() payable {
|
|
||||||
assert(tx.origin == new TransactionOrigin().test());
|
|
||||||
}
|
|
||||||
|
|
||||||
function test() public payable returns (address ret) {
|
|
||||||
ret = tx.origin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
contract TransactionOrigin {
|
|
||||||
function test() public payable returns (address ret) {
|
|
||||||
assert(msg.sender != tx.origin);
|
|
||||||
|
|
||||||
ret = tx.origin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+24
-112
@@ -43,10 +43,6 @@ test_spec!(call, "Caller", "Call.sol");
|
|||||||
test_spec!(transfer, "Transfer", "Transfer.sol");
|
test_spec!(transfer, "Transfer", "Transfer.sol");
|
||||||
test_spec!(return_data_oob, "ReturnDataOob", "ReturnDataOob.sol");
|
test_spec!(return_data_oob, "ReturnDataOob", "ReturnDataOob.sol");
|
||||||
test_spec!(immutables, "Immutables", "Immutables.sol");
|
test_spec!(immutables, "Immutables", "Immutables.sol");
|
||||||
test_spec!(transaction, "Transaction", "Transaction.sol");
|
|
||||||
test_spec!(block_hash, "BlockHash", "BlockHash.sol");
|
|
||||||
test_spec!(delegate, "Delegate", "Delegate.sol");
|
|
||||||
test_spec!(gas_price, "GasPrice", "GasPrice.sol");
|
|
||||||
|
|
||||||
fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> {
|
fn instantiate(path: &str, contract: &str) -> Vec<SpecsAction> {
|
||||||
vec![Instantiate {
|
vec![Instantiate {
|
||||||
@@ -324,114 +320,6 @@ fn ext_code_hash() {
|
|||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn ext_code_size() {
|
|
||||||
let alice = Address::from(ALICE.0);
|
|
||||||
let own_address = alice.create(0);
|
|
||||||
let baseline_address = alice.create2([0u8; 32], keccak256(Contract::baseline().pvm_runtime));
|
|
||||||
|
|
||||||
let own_code_size = U256::from(
|
|
||||||
Contract::ext_code_size(Default::default())
|
|
||||||
.pvm_runtime
|
|
||||||
.len(),
|
|
||||||
);
|
|
||||||
let baseline_code_size = U256::from(Contract::baseline().pvm_runtime.len());
|
|
||||||
|
|
||||||
Specs {
|
|
||||||
actions: vec![
|
|
||||||
// Instantiate the test contract
|
|
||||||
instantiate("contracts/ExtCode.sol", "ExtCode").remove(0),
|
|
||||||
// Instantiate the baseline contract
|
|
||||||
Instantiate {
|
|
||||||
origin: TestAddress::Alice,
|
|
||||||
value: 0,
|
|
||||||
gas_limit: Some(GAS_LIMIT),
|
|
||||||
storage_deposit_limit: None,
|
|
||||||
code: Code::Solidity {
|
|
||||||
path: Some("contracts/Baseline.sol".into()),
|
|
||||||
contract: "Baseline".to_string(),
|
|
||||||
solc_optimizer: None,
|
|
||||||
pipeline: None,
|
|
||||||
},
|
|
||||||
data: vec![],
|
|
||||||
salt: OptionalHex::from([0; 32]),
|
|
||||||
},
|
|
||||||
// Alice is not a contract and returns a code size of 0
|
|
||||||
Call {
|
|
||||||
origin: TestAddress::Alice,
|
|
||||||
dest: TestAddress::Instantiated(0),
|
|
||||||
value: 0,
|
|
||||||
gas_limit: None,
|
|
||||||
storage_deposit_limit: None,
|
|
||||||
data: Contract::ext_code_size(alice).calldata,
|
|
||||||
},
|
|
||||||
VerifyCall(VerifyCallExpectation {
|
|
||||||
success: true,
|
|
||||||
output: OptionalHex::from([0u8; 32].to_vec()),
|
|
||||||
gas_consumed: None,
|
|
||||||
}),
|
|
||||||
// Unknown address returns a code size of 0
|
|
||||||
Call {
|
|
||||||
origin: TestAddress::Alice,
|
|
||||||
dest: TestAddress::Instantiated(0),
|
|
||||||
value: 0,
|
|
||||||
gas_limit: None,
|
|
||||||
storage_deposit_limit: None,
|
|
||||||
data: Contract::ext_code_size(Address::from([0xff; 20])).calldata,
|
|
||||||
},
|
|
||||||
VerifyCall(VerifyCallExpectation {
|
|
||||||
success: true,
|
|
||||||
output: OptionalHex::from([0u8; 32].to_vec()),
|
|
||||||
gas_consumed: None,
|
|
||||||
}),
|
|
||||||
// Own address via extcodesize returns own code size
|
|
||||||
Call {
|
|
||||||
origin: TestAddress::Alice,
|
|
||||||
dest: TestAddress::Instantiated(0),
|
|
||||||
value: 0,
|
|
||||||
gas_limit: None,
|
|
||||||
storage_deposit_limit: None,
|
|
||||||
data: Contract::ext_code_size(own_address).calldata,
|
|
||||||
},
|
|
||||||
VerifyCall(VerifyCallExpectation {
|
|
||||||
success: true,
|
|
||||||
output: OptionalHex::from(own_code_size.to_be_bytes::<32>().to_vec()),
|
|
||||||
gas_consumed: None,
|
|
||||||
}),
|
|
||||||
// Own address via codesize returns own code size
|
|
||||||
Call {
|
|
||||||
origin: TestAddress::Alice,
|
|
||||||
dest: TestAddress::Instantiated(0),
|
|
||||||
value: 0,
|
|
||||||
gas_limit: None,
|
|
||||||
storage_deposit_limit: None,
|
|
||||||
data: Contract::code_size().calldata,
|
|
||||||
},
|
|
||||||
VerifyCall(VerifyCallExpectation {
|
|
||||||
success: true,
|
|
||||||
output: OptionalHex::from(own_code_size.to_be_bytes::<32>().to_vec()),
|
|
||||||
gas_consumed: None,
|
|
||||||
}),
|
|
||||||
// Baseline address returns the baseline code size
|
|
||||||
Call {
|
|
||||||
origin: TestAddress::Alice,
|
|
||||||
dest: TestAddress::Instantiated(0),
|
|
||||||
value: 0,
|
|
||||||
gas_limit: None,
|
|
||||||
storage_deposit_limit: None,
|
|
||||||
data: Contract::ext_code_size(baseline_address).calldata,
|
|
||||||
},
|
|
||||||
VerifyCall(VerifyCallExpectation {
|
|
||||||
success: true,
|
|
||||||
output: OptionalHex::from(baseline_code_size.to_be_bytes::<32>().to_vec()),
|
|
||||||
gas_consumed: None,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// These test were implement for the mock-runtime and need to be ported yet.
|
// These test were implement for the mock-runtime and need to be ported yet.
|
||||||
|
|
||||||
@@ -460,4 +348,28 @@ fn create2_failure() {
|
|||||||
|
|
||||||
assert_eq!(output.flags, ReturnFlags::Revert);
|
assert_eq!(output.flags, ReturnFlags::Revert);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ext_code_size() {
|
||||||
|
let contract = Contract::ext_code_size(Transaction::default_address());
|
||||||
|
let (_, output) = assert_success(&contract, false);
|
||||||
|
let received = U256::from_be_slice(&output.data);
|
||||||
|
let expected = U256::from(contract.pvm_runtime.len());
|
||||||
|
assert_eq!(received, expected);
|
||||||
|
|
||||||
|
let contract = Contract::ext_code_size(Default::default());
|
||||||
|
let (_, output) = assert_success(&contract, false);
|
||||||
|
let received = U256::from_be_slice(&output.data);
|
||||||
|
let expected = U256::ZERO;
|
||||||
|
assert_eq!(received, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn code_size() {
|
||||||
|
let contract = Contract::code_size();
|
||||||
|
let (_, output) = assert_success(&contract, false);
|
||||||
|
let expected = U256::from(contract.pvm_runtime.len());
|
||||||
|
let received = U256::from_be_slice(&output.data);
|
||||||
|
assert_eq!(expected, received);
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ repository.workspace = true
|
|||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
description = "revive compiler linker utils"
|
description = "revive compiler linker utils"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
riscv-64 = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
inkwell = { workspace = true }
|
inkwell = { workspace = true }
|
||||||
tempfile = { workspace = true }
|
tempfile = { workspace = true }
|
||||||
|
|||||||
@@ -8,7 +8,14 @@ SECTIONS {
|
|||||||
.text : { KEEP(*(.text.polkavm_export)) *(.text .text.*) }
|
.text : { KEEP(*(.text.polkavm_export)) *(.text .text.*) }
|
||||||
}"#;
|
}"#;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "riscv-64"))]
|
||||||
|
const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv32.a";
|
||||||
|
#[cfg(feature = "riscv-64")]
|
||||||
const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv64.a";
|
const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv64.a";
|
||||||
|
|
||||||
|
#[cfg(not(feature = "riscv-64"))]
|
||||||
|
const BUILTINS_LIB_NAME: &str = "clang_rt.builtins-riscv32";
|
||||||
|
#[cfg(feature = "riscv-64")]
|
||||||
const BUILTINS_LIB_NAME: &str = "clang_rt.builtins-riscv64";
|
const BUILTINS_LIB_NAME: &str = "clang_rt.builtins-riscv64";
|
||||||
|
|
||||||
fn invoke_lld(cmd_args: &[&str]) -> bool {
|
fn invoke_lld(cmd_args: &[&str]) -> bool {
|
||||||
@@ -22,9 +29,9 @@ fn invoke_lld(cmd_args: &[&str]) -> bool {
|
|||||||
unsafe { LLDELFLink(args.as_ptr(), args.len()) == 0 }
|
unsafe { LLDELFLink(args.as_ptr(), args.len()) == 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn polkavm_linker<T: AsRef<[u8]>>(code: T, strip_binary: bool) -> anyhow::Result<Vec<u8>> {
|
fn polkavm_linker<T: AsRef<[u8]>>(code: T) -> anyhow::Result<Vec<u8>> {
|
||||||
let mut config = polkavm_linker::Config::default();
|
let mut config = polkavm_linker::Config::default();
|
||||||
config.set_strip(strip_binary);
|
config.set_strip(true);
|
||||||
config.set_optimize(true);
|
config.set_optimize(true);
|
||||||
|
|
||||||
polkavm_linker::program_from_elf(config, code.as_ref())
|
polkavm_linker::program_from_elf(config, code.as_ref())
|
||||||
@@ -72,5 +79,10 @@ pub fn link<T: AsRef<[u8]>>(input: T) -> anyhow::Result<Vec<u8>> {
|
|||||||
return Err(anyhow::anyhow!("ld.lld failed"));
|
return Err(anyhow::anyhow!("ld.lld failed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(fs::read(&output_path)?)
|
if env::var("PVM_LINKER_DUMP_SO").is_ok() {
|
||||||
|
fs::copy(&output_path, "/tmp/out.so")?;
|
||||||
|
};
|
||||||
|
|
||||||
|
let blob = fs::read(&output_path)?;
|
||||||
|
polkavm_linker(blob)
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-76
@@ -1,19 +1,5 @@
|
|||||||
use std::{
|
fn llvm_config(arg: &str) -> String {
|
||||||
env,
|
let output = std::process::Command::new("llvm-config")
|
||||||
path::{Path, PathBuf},
|
|
||||||
};
|
|
||||||
|
|
||||||
const LLVM_LINK_PREFIX: &str = "LLVM_LINK_PREFIX";
|
|
||||||
|
|
||||||
fn locate_llvm_config() -> PathBuf {
|
|
||||||
let prefix = env::var_os(LLVM_LINK_PREFIX)
|
|
||||||
.map(|p| PathBuf::from(p).join("bin"))
|
|
||||||
.unwrap_or_default();
|
|
||||||
prefix.join("llvm-config")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn llvm_config(llvm_config_path: &Path, arg: &str) -> String {
|
|
||||||
let output = std::process::Command::new(llvm_config_path)
|
|
||||||
.args([arg])
|
.args([arg])
|
||||||
.output()
|
.output()
|
||||||
.unwrap_or_else(|_| panic!("`llvm-config {arg}` failed"));
|
.unwrap_or_else(|_| panic!("`llvm-config {arg}` failed"));
|
||||||
@@ -22,11 +8,8 @@ fn llvm_config(llvm_config_path: &Path, arg: &str) -> String {
|
|||||||
.unwrap_or_else(|_| panic!("output of `llvm-config {arg}` should be utf8"))
|
.unwrap_or_else(|_| panic!("output of `llvm-config {arg}` should be utf8"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_rustc_link_flags(llvm_config_path: &Path) {
|
fn set_rustc_link_flags() {
|
||||||
println!(
|
println!("cargo:rustc-link-search=native={}", llvm_config("--libdir"));
|
||||||
"cargo:rustc-link-search=native={}",
|
|
||||||
llvm_config(llvm_config_path, "--libdir")
|
|
||||||
);
|
|
||||||
|
|
||||||
for lib in [
|
for lib in [
|
||||||
"lldELF",
|
"lldELF",
|
||||||
@@ -39,70 +22,19 @@ fn set_rustc_link_flags(llvm_config_path: &Path) {
|
|||||||
"LLVMTargetParser",
|
"LLVMTargetParser",
|
||||||
"LLVMBinaryFormat",
|
"LLVMBinaryFormat",
|
||||||
"LLVMDemangle",
|
"LLVMDemangle",
|
||||||
// The `llvm-sys` crate relies on `llvm-config` to obtain a list of required LLVM libraries
|
|
||||||
// during the build process. This works well in typical native environments, where `llvm-config`
|
|
||||||
// can accurately list the necessary libraries.
|
|
||||||
// However, when cross-compiling to WebAssembly using Emscripten, `llvm-config` fails to recognize
|
|
||||||
// JavaScript-based libraries, making it necessary to manually inject the required dependencies.
|
|
||||||
"LLVMRISCVDisassembler",
|
|
||||||
"LLVMRISCVAsmParser",
|
|
||||||
"LLVMRISCVCodeGen",
|
|
||||||
"LLVMRISCVDesc",
|
|
||||||
"LLVMRISCVInfo",
|
|
||||||
"LLVMExecutionEngine",
|
|
||||||
"LLVMOption",
|
|
||||||
"LLVMMCDisassembler",
|
|
||||||
"LLVMPasses",
|
|
||||||
"LLVMHipStdPar",
|
|
||||||
"LLVMCFGuard",
|
|
||||||
"LLVMCoroutines",
|
|
||||||
"LLVMipo",
|
|
||||||
"LLVMVectorize",
|
|
||||||
"LLVMInstrumentation",
|
|
||||||
"LLVMFrontendOpenMP",
|
|
||||||
"LLVMFrontendOffloading",
|
|
||||||
"LLVMGlobalISel",
|
|
||||||
"LLVMAsmPrinter",
|
|
||||||
"LLVMSelectionDAG",
|
|
||||||
"LLVMCodeGen",
|
|
||||||
"LLVMTarget",
|
|
||||||
"LLVMObjCARCOpts",
|
|
||||||
"LLVMCodeGenTypes",
|
|
||||||
"LLVMIRPrinter",
|
|
||||||
"LLVMScalarOpts",
|
|
||||||
"LLVMInstCombine",
|
|
||||||
"LLVMAggressiveInstCombine",
|
|
||||||
"LLVMTransformUtils",
|
|
||||||
"LLVMBitWriter",
|
|
||||||
"LLVMAnalysis",
|
|
||||||
"LLVMProfileData",
|
|
||||||
"LLVMDebugInfoDWARF",
|
|
||||||
"LLVMObject",
|
|
||||||
"LLVMMCParser",
|
|
||||||
"LLVMIRReader",
|
|
||||||
"LLVMAsmParser",
|
|
||||||
"LLVMMC",
|
|
||||||
"LLVMDebugInfoCodeView",
|
|
||||||
"LLVMBitReader",
|
|
||||||
"LLVMRemarks",
|
|
||||||
"LLVMBitstreamReader",
|
|
||||||
] {
|
] {
|
||||||
println!("cargo:rustc-link-lib=static={lib}");
|
println!("cargo:rustc-link-lib=static={lib}");
|
||||||
}
|
}
|
||||||
|
|
||||||
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
|
#[cfg(target_os = "linux")]
|
||||||
if target_os == "linux" {
|
{
|
||||||
println!("cargo:rustc-link-lib=dylib=stdc++");
|
println!("cargo:rustc-link-lib=dylib=stdc++");
|
||||||
println!("cargo:rustc-link-lib=tinfo");
|
println!("cargo:rustc-link-lib=tinfo");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("cargo:rerun-if-env-changed={}", LLVM_LINK_PREFIX);
|
llvm_config("--cxxflags")
|
||||||
|
|
||||||
let llvm_config_path = locate_llvm_config();
|
|
||||||
|
|
||||||
llvm_config(&llvm_config_path, "--cxxflags")
|
|
||||||
.split_whitespace()
|
.split_whitespace()
|
||||||
.fold(&mut cc::Build::new(), |builder, flag| builder.flag(flag))
|
.fold(&mut cc::Build::new(), |builder, flag| builder.flag(flag))
|
||||||
.flag("-Wno-unused-parameter")
|
.flag("-Wno-unused-parameter")
|
||||||
@@ -110,7 +42,7 @@ fn main() {
|
|||||||
.file("src/linker.cpp")
|
.file("src/linker.cpp")
|
||||||
.compile("liblinker.a");
|
.compile("liblinker.a");
|
||||||
|
|
||||||
set_rustc_link_flags(&llvm_config_path);
|
set_rustc_link_flags();
|
||||||
|
|
||||||
println!("cargo:rerun-if-changed=build.rs");
|
println!("cargo:rerun-if-changed=build.rs");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ description = "Shared front end code of the revive PolkaVM compilers"
|
|||||||
[lib]
|
[lib]
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
|
[features]
|
||||||
|
riscv-zbb = []
|
||||||
|
riscv-64 = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
semver = { workspace = true }
|
semver = { workspace = true }
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ pub enum IRType {
|
|||||||
LLVM,
|
LLVM,
|
||||||
/// Whether to dump the assembly code.
|
/// Whether to dump the assembly code.
|
||||||
Assembly,
|
Assembly,
|
||||||
/// Whether to dump the ELF shared object
|
|
||||||
SO,
|
|
||||||
/// Whether to jump JSON
|
/// Whether to jump JSON
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
JSON,
|
JSON,
|
||||||
@@ -33,7 +31,6 @@ impl IRType {
|
|||||||
Self::Assembly => revive_common::EXTENSION_POLKAVM_ASSEMBLY,
|
Self::Assembly => revive_common::EXTENSION_POLKAVM_ASSEMBLY,
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
Self::JSON => revive_common::EXTENSION_JSON,
|
Self::JSON => revive_common::EXTENSION_JSON,
|
||||||
Self::SO => revive_common::EXTENSION_SHARED_OBJECT,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,52 +13,41 @@ use self::ir_type::IRType;
|
|||||||
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
|
||||||
pub struct DebugConfig {
|
pub struct DebugConfig {
|
||||||
/// The directory to dump the IRs to.
|
/// The directory to dump the IRs to.
|
||||||
pub output_directory: Option<PathBuf>,
|
pub output_directory: PathBuf,
|
||||||
/// Whether debug info should be emitted.
|
|
||||||
pub emit_debug_info: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DebugConfig {
|
impl DebugConfig {
|
||||||
/// A shortcut constructor.
|
/// A shortcut constructor.
|
||||||
pub const fn new(output_directory: Option<PathBuf>, emit_debug_info: bool) -> Self {
|
pub fn new(output_directory: PathBuf) -> Self {
|
||||||
Self {
|
Self { output_directory }
|
||||||
output_directory,
|
|
||||||
emit_debug_info,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dumps the Yul IR.
|
/// Dumps the Yul IR.
|
||||||
pub fn dump_yul(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
pub fn dump_yul(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
||||||
if let Some(output_directory) = self.output_directory.as_ref() {
|
let mut file_path = self.output_directory.to_owned();
|
||||||
let mut file_path = output_directory.to_owned();
|
let full_file_name = Self::full_file_name(contract_path, None, IRType::Yul);
|
||||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::Yul);
|
file_path.push(full_file_name);
|
||||||
file_path.push(full_file_name);
|
std::fs::write(file_path, code)?;
|
||||||
std::fs::write(file_path, code)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dumps the EVM legacy assembly IR.
|
/// Dumps the EVM legacy assembly IR.
|
||||||
pub fn dump_evmla(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
pub fn dump_evmla(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
||||||
if let Some(output_directory) = self.output_directory.as_ref() {
|
let mut file_path = self.output_directory.to_owned();
|
||||||
let mut file_path = output_directory.to_owned();
|
let full_file_name = Self::full_file_name(contract_path, None, IRType::EVMLA);
|
||||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::EVMLA);
|
file_path.push(full_file_name);
|
||||||
file_path.push(full_file_name);
|
std::fs::write(file_path, code)?;
|
||||||
std::fs::write(file_path, code)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dumps the Ethereal IR.
|
/// Dumps the Ethereal IR.
|
||||||
pub fn dump_ethir(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
pub fn dump_ethir(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
||||||
if let Some(output_directory) = self.output_directory.as_ref() {
|
let mut file_path = self.output_directory.to_owned();
|
||||||
let mut file_path = output_directory.to_owned();
|
let full_file_name = Self::full_file_name(contract_path, None, IRType::EthIR);
|
||||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::EthIR);
|
file_path.push(full_file_name);
|
||||||
file_path.push(full_file_name);
|
std::fs::write(file_path, code)?;
|
||||||
std::fs::write(file_path, code)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -69,15 +58,12 @@ impl DebugConfig {
|
|||||||
contract_path: &str,
|
contract_path: &str,
|
||||||
module: &inkwell::module::Module,
|
module: &inkwell::module::Module,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
if let Some(output_directory) = self.output_directory.as_ref() {
|
let llvm_code = module.print_to_string().to_string();
|
||||||
let llvm_code = module.print_to_string().to_string();
|
|
||||||
|
|
||||||
let mut file_path = output_directory.to_owned();
|
let mut file_path = self.output_directory.to_owned();
|
||||||
let full_file_name =
|
let full_file_name = Self::full_file_name(contract_path, Some("unoptimized"), IRType::LLVM);
|
||||||
Self::full_file_name(contract_path, Some("unoptimized"), IRType::LLVM);
|
file_path.push(full_file_name);
|
||||||
file_path.push(full_file_name);
|
std::fs::write(file_path, llvm_code)?;
|
||||||
std::fs::write(file_path, llvm_code)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -88,39 +74,22 @@ impl DebugConfig {
|
|||||||
contract_path: &str,
|
contract_path: &str,
|
||||||
module: &inkwell::module::Module,
|
module: &inkwell::module::Module,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
if let Some(output_directory) = self.output_directory.as_ref() {
|
let llvm_code = module.print_to_string().to_string();
|
||||||
let llvm_code = module.print_to_string().to_string();
|
|
||||||
|
|
||||||
let mut file_path = output_directory.to_owned();
|
let mut file_path = self.output_directory.to_owned();
|
||||||
let full_file_name =
|
let full_file_name = Self::full_file_name(contract_path, Some("optimized"), IRType::LLVM);
|
||||||
Self::full_file_name(contract_path, Some("optimized"), IRType::LLVM);
|
file_path.push(full_file_name);
|
||||||
file_path.push(full_file_name);
|
std::fs::write(file_path, llvm_code)?;
|
||||||
std::fs::write(file_path, llvm_code)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dumps the assembly.
|
/// Dumps the assembly.
|
||||||
pub fn dump_assembly(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
pub fn dump_assembly(&self, contract_path: &str, code: &str) -> anyhow::Result<()> {
|
||||||
if let Some(output_directory) = self.output_directory.as_ref() {
|
let mut file_path = self.output_directory.to_owned();
|
||||||
let mut file_path = output_directory.to_owned();
|
let full_file_name = Self::full_file_name(contract_path, None, IRType::Assembly);
|
||||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::Assembly);
|
file_path.push(full_file_name);
|
||||||
file_path.push(full_file_name);
|
std::fs::write(file_path, code)?;
|
||||||
std::fs::write(file_path, code)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Dumps the code object.
|
|
||||||
pub fn dump_object(&self, contract_path: &str, code: &[u8]) -> anyhow::Result<()> {
|
|
||||||
if let Some(output_directory) = self.output_directory.as_ref() {
|
|
||||||
let mut file_path = output_directory.to_owned();
|
|
||||||
let full_file_name = Self::full_file_name(contract_path, None, IRType::SO);
|
|
||||||
file_path.push(full_file_name);
|
|
||||||
std::fs::write(file_path, code)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -133,12 +102,10 @@ impl DebugConfig {
|
|||||||
contract_suffix: Option<&str>,
|
contract_suffix: Option<&str>,
|
||||||
stage_json: &Vec<u8>,
|
stage_json: &Vec<u8>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
if let Some(output_directory) = self.output_directory.as_ref() {
|
let mut file_path = self.output_directory.to_owned();
|
||||||
let mut file_path = output_directory.to_owned();
|
let full_file_name = Self::full_file_name(contract_path, contract_suffix, IRType::JSON);
|
||||||
let full_file_name = Self::full_file_name(contract_path, contract_suffix, IRType::JSON);
|
file_path.push(full_file_name);
|
||||||
file_path.push(full_file_name);
|
std::fs::write(file_path, stage_json)?;
|
||||||
std::fs::write(file_path, stage_json)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ pub use self::polkavm::context::argument::Argument as PolkaVMArgument;
|
|||||||
pub use self::polkavm::context::attribute::Attribute as PolkaVMAttribute;
|
pub use self::polkavm::context::attribute::Attribute as PolkaVMAttribute;
|
||||||
pub use self::polkavm::context::build::Build as PolkaVMBuild;
|
pub use self::polkavm::context::build::Build as PolkaVMBuild;
|
||||||
pub use self::polkavm::context::code_type::CodeType as PolkaVMCodeType;
|
pub use self::polkavm::context::code_type::CodeType as PolkaVMCodeType;
|
||||||
pub use self::polkavm::context::debug_info::DebugInfo;
|
|
||||||
pub use self::polkavm::context::evmla_data::EVMLAData as PolkaVMContextEVMLAData;
|
pub use self::polkavm::context::evmla_data::EVMLAData as PolkaVMContextEVMLAData;
|
||||||
pub use self::polkavm::context::function::block::evmla_data::key::Key as PolkaVMFunctionBlockKey;
|
pub use self::polkavm::context::function::block::evmla_data::key::Key as PolkaVMFunctionBlockKey;
|
||||||
pub use self::polkavm::context::function::block::evmla_data::EVMLAData as PolkaVMFunctionBlockEVMLAData;
|
pub use self::polkavm::context::function::block::evmla_data::EVMLAData as PolkaVMFunctionBlockEVMLAData;
|
||||||
@@ -61,6 +60,7 @@ pub use self::polkavm::evm::return_data as polkavm_evm_return_data;
|
|||||||
pub use self::polkavm::evm::storage as polkavm_evm_storage;
|
pub use self::polkavm::evm::storage as polkavm_evm_storage;
|
||||||
pub use self::polkavm::metadata_hash::MetadataHash as PolkaVMMetadataHash;
|
pub use self::polkavm::metadata_hash::MetadataHash as PolkaVMMetadataHash;
|
||||||
pub use self::polkavm::r#const as polkavm_const;
|
pub use self::polkavm::r#const as polkavm_const;
|
||||||
|
pub use self::polkavm::utils as polkavm_utils;
|
||||||
pub use self::polkavm::Dependency as PolkaVMDependency;
|
pub use self::polkavm::Dependency as PolkaVMDependency;
|
||||||
pub use self::polkavm::DummyDependency as PolkaVMDummyDependency;
|
pub use self::polkavm::DummyDependency as PolkaVMDummyDependency;
|
||||||
pub use self::polkavm::DummyLLVMWritable as PolkaVMDummyLLVMWritable;
|
pub use self::polkavm::DummyLLVMWritable as PolkaVMDummyLLVMWritable;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use itertools::Itertools;
|
|||||||
|
|
||||||
use self::size_level::SizeLevel;
|
use self::size_level::SizeLevel;
|
||||||
|
|
||||||
/// The LLVM optimizer and code-gen settings.
|
/// The LLVM optimizer settings.
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Eq)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Eq)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
/// The middle-end optimization level.
|
/// The middle-end optimization level.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/// The LLVM framework version.
|
/// The LLVM framework version.
|
||||||
pub const LLVM_VERSION: semver::Version = semver::Version::new(18, 1, 4);
|
pub const LLVM_VERSION: semver::Version = semver::Version::new(18, 1, 4);
|
||||||
|
|
||||||
/// The pointer width sized type.
|
/// The register width sized type
|
||||||
pub static XLEN: usize = revive_common::BIT_LENGTH_X32;
|
pub static XLEN: usize = revive_common::BIT_LENGTH_X32;
|
||||||
|
|
||||||
/// The heap memory pointer pointer global variable name.
|
/// The heap memory pointer pointer global variable name.
|
||||||
|
|||||||
@@ -1,43 +1,7 @@
|
|||||||
//! The LLVM debug information.
|
//! The LLVM debug information.
|
||||||
|
|
||||||
use std::cell::RefCell;
|
|
||||||
|
|
||||||
use inkwell::debug_info::AsDIScope;
|
use inkwell::debug_info::AsDIScope;
|
||||||
use inkwell::debug_info::DIScope;
|
use num::Zero;
|
||||||
|
|
||||||
/// Debug info scope stack
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct ScopeStack<'ctx> {
|
|
||||||
stack: Vec<DIScope<'ctx>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Abstract the type of the DIScope stack.
|
|
||||||
impl<'ctx> ScopeStack<'ctx> {
|
|
||||||
pub fn from(item: DIScope<'ctx>) -> Self {
|
|
||||||
Self { stack: vec![item] }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the top of the scope stack, or None if the stack is empty.
|
|
||||||
pub fn top(&self) -> Option<DIScope<'ctx>> {
|
|
||||||
self.stack.last().copied()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Push a scope onto the stack.
|
|
||||||
pub fn push(&mut self, scope: DIScope<'ctx>) {
|
|
||||||
self.stack.push(scope)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pop the scope at the top of the stack and return it.
|
|
||||||
/// Return None if the stack is empty.
|
|
||||||
pub fn pop(&mut self) -> Option<DIScope<'ctx>> {
|
|
||||||
self.stack.pop()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the number of scopes on the stack.
|
|
||||||
pub fn len(&self) -> usize {
|
|
||||||
self.stack.len()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The LLVM debug information.
|
/// The LLVM debug information.
|
||||||
pub struct DebugInfo<'ctx> {
|
pub struct DebugInfo<'ctx> {
|
||||||
@@ -45,8 +9,6 @@ pub struct DebugInfo<'ctx> {
|
|||||||
compile_unit: inkwell::debug_info::DICompileUnit<'ctx>,
|
compile_unit: inkwell::debug_info::DICompileUnit<'ctx>,
|
||||||
/// The debug info builder.
|
/// The debug info builder.
|
||||||
builder: inkwell::debug_info::DebugInfoBuilder<'ctx>,
|
builder: inkwell::debug_info::DebugInfoBuilder<'ctx>,
|
||||||
/// Enclosing debug info scopes.
|
|
||||||
scope_stack: RefCell<ScopeStack<'ctx>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ctx> DebugInfo<'ctx> {
|
impl<'ctx> DebugInfo<'ctx> {
|
||||||
@@ -73,43 +35,19 @@ impl<'ctx> DebugInfo<'ctx> {
|
|||||||
Self {
|
Self {
|
||||||
compile_unit,
|
compile_unit,
|
||||||
builder,
|
builder,
|
||||||
scope_stack: RefCell::new(ScopeStack::from(compile_unit.as_debug_info_scope())),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prepare an LLVM-IR module for debug-info generation
|
|
||||||
pub fn initialize_module(
|
|
||||||
&self,
|
|
||||||
llvm: &'ctx inkwell::context::Context,
|
|
||||||
module: &inkwell::module::Module<'ctx>,
|
|
||||||
) {
|
|
||||||
let debug_metadata_value = llvm
|
|
||||||
.i32_type()
|
|
||||||
.const_int(inkwell::debug_info::debug_metadata_version() as u64, false);
|
|
||||||
module.add_basic_value_flag(
|
|
||||||
"Debug Info Version",
|
|
||||||
inkwell::module::FlagBehavior::Warning,
|
|
||||||
debug_metadata_value,
|
|
||||||
);
|
|
||||||
self.push_scope(self.compilation_unit().get_file().as_debug_info_scope());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Finalize debug-info for an LLVM-IR module.
|
|
||||||
pub fn finalize_module(&self) {
|
|
||||||
self.builder().finalize()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a function info.
|
/// Creates a function info.
|
||||||
pub fn create_function(
|
pub fn create_function(
|
||||||
&self,
|
&self,
|
||||||
name: &str,
|
name: &str,
|
||||||
) -> anyhow::Result<inkwell::debug_info::DISubprogram<'ctx>> {
|
) -> anyhow::Result<inkwell::debug_info::DISubprogram<'ctx>> {
|
||||||
let flags = inkwell::debug_info::DIFlagsConstants::ZERO;
|
|
||||||
let subroutine_type = self.builder.create_subroutine_type(
|
let subroutine_type = self.builder.create_subroutine_type(
|
||||||
self.compile_unit.get_file(),
|
self.compile_unit.get_file(),
|
||||||
Some(self.create_word_type(Some(flags))?.as_type()),
|
Some(self.create_type(revive_common::BIT_LENGTH_FIELD)?),
|
||||||
&[],
|
&[],
|
||||||
flags,
|
inkwell::debug_info::DIFlags::zero(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let function = self.builder.create_function(
|
let function = self.builder.create_function(
|
||||||
@@ -122,7 +60,7 @@ impl<'ctx> DebugInfo<'ctx> {
|
|||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
1,
|
1,
|
||||||
flags,
|
inkwell::debug_info::DIFlags::zero(),
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -136,55 +74,24 @@ impl<'ctx> DebugInfo<'ctx> {
|
|||||||
Ok(function)
|
Ok(function)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates primitive integer type debug-info.
|
/// Creates a primitive type info.
|
||||||
pub fn create_primitive_type(
|
pub fn create_type(
|
||||||
&self,
|
&self,
|
||||||
bit_length: usize,
|
bit_length: usize,
|
||||||
flags: Option<inkwell::debug_info::DIFlags>,
|
) -> anyhow::Result<inkwell::debug_info::DIType<'ctx>> {
|
||||||
) -> anyhow::Result<inkwell::debug_info::DIBasicType<'ctx>> {
|
|
||||||
let di_flags = flags.unwrap_or(inkwell::debug_info::DIFlagsConstants::ZERO);
|
|
||||||
let di_encoding: u32 = 0;
|
|
||||||
let type_name = String::from("U") + bit_length.to_string().as_str();
|
|
||||||
self.builder
|
self.builder
|
||||||
.create_basic_type(type_name.as_str(), bit_length as u64, di_encoding, di_flags)
|
.create_basic_type(
|
||||||
|
"U256",
|
||||||
|
bit_length as u64,
|
||||||
|
0,
|
||||||
|
inkwell::debug_info::DIFlags::zero(),
|
||||||
|
)
|
||||||
|
.map(|basic_type| basic_type.as_type())
|
||||||
.map_err(|error| anyhow::anyhow!("Debug info error: {}", error))
|
.map_err(|error| anyhow::anyhow!("Debug info error: {}", error))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the debug-info model of word-sized integer types.
|
/// Finalizes the builder.
|
||||||
pub fn create_word_type(
|
pub fn finalize(&self) {
|
||||||
&self,
|
self.builder.finalize();
|
||||||
flags: Option<inkwell::debug_info::DIFlags>,
|
|
||||||
) -> anyhow::Result<inkwell::debug_info::DIBasicType<'ctx>> {
|
|
||||||
self.create_primitive_type(revive_common::BIT_LENGTH_WORD, flags)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the DIBuilder.
|
|
||||||
pub fn builder(&self) -> &inkwell::debug_info::DebugInfoBuilder<'ctx> {
|
|
||||||
&self.builder
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the compilation unit. {
|
|
||||||
pub fn compilation_unit(&self) -> &inkwell::debug_info::DICompileUnit<'ctx> {
|
|
||||||
&self.compile_unit
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Push a debug-info scope onto the stack.
|
|
||||||
pub fn push_scope(&self, scope: DIScope<'ctx>) {
|
|
||||||
self.scope_stack.borrow_mut().push(scope)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pop the top of the debug-info scope stack and return it.
|
|
||||||
pub fn pop_scope(&self) -> Option<DIScope<'ctx>> {
|
|
||||||
self.scope_stack.borrow_mut().pop()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the top of the debug-info scope stack.
|
|
||||||
pub fn top_scope(&self) -> Option<DIScope<'ctx>> {
|
|
||||||
self.scope_stack.borrow().top()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the number of debug-info scopes on the scope stack.
|
|
||||||
pub fn num_scopes(&self) -> usize {
|
|
||||||
self.scope_stack.borrow().len()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,4 @@ impl<'ctx> Declaration<'ctx> {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
Self { r#type, value }
|
Self { r#type, value }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn function_value(&self) -> inkwell::values::FunctionValue<'ctx> {
|
|
||||||
self.value
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ pub mod yul_data;
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use inkwell::debug_info::AsDIScope;
|
|
||||||
|
|
||||||
use crate::optimizer::settings::size_level::SizeLevel;
|
use crate::optimizer::settings::size_level::SizeLevel;
|
||||||
use crate::optimizer::Optimizer;
|
use crate::optimizer::Optimizer;
|
||||||
use crate::polkavm::context::attribute::Attribute;
|
use crate::polkavm::context::attribute::Attribute;
|
||||||
@@ -96,14 +94,6 @@ impl<'ctx> Function<'ctx> {
|
|||||||
self.declaration
|
self.declaration
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the debug-info scope.
|
|
||||||
pub fn get_debug_scope(&self) -> Option<inkwell::debug_info::DIScope<'ctx>> {
|
|
||||||
self.declaration()
|
|
||||||
.function_value()
|
|
||||||
.get_subprogram()
|
|
||||||
.map(|scp| scp.as_debug_info_scope())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the N-th parameter of the function.
|
/// Returns the N-th parameter of the function.
|
||||||
pub fn get_nth_param(&self, index: usize) -> inkwell::values::BasicValueEnum<'ctx> {
|
pub fn get_nth_param(&self, index: usize) -> inkwell::values::BasicValueEnum<'ctx> {
|
||||||
self.declaration()
|
self.declaration()
|
||||||
|
|||||||
@@ -54,14 +54,12 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||||
context.set_current_function(runtime::FUNCTION_DEPLOY_CODE, None)?;
|
context.set_current_function(runtime::FUNCTION_DEPLOY_CODE)?;
|
||||||
|
|
||||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||||
context.set_code_type(CodeType::Deploy);
|
context.set_code_type(CodeType::Deploy);
|
||||||
|
|
||||||
self.inner.into_llvm(context)?;
|
self.inner.into_llvm(context)?;
|
||||||
context.set_debug_location(0, 0, None)?;
|
|
||||||
|
|
||||||
match context
|
match context
|
||||||
.basic_block()
|
.basic_block()
|
||||||
.get_last_instruction()
|
.get_last_instruction()
|
||||||
@@ -74,11 +72,8 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
context.set_basic_block(context.current_function().borrow().return_block());
|
context.set_basic_block(context.current_function().borrow().return_block());
|
||||||
context.set_debug_location(0, 0, None)?;
|
|
||||||
context.build_return(None);
|
context.build_return(None);
|
||||||
|
|
||||||
context.pop_debug_scope();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,18 @@ impl Entry {
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
|
context.declare_global(
|
||||||
|
revive_runtime_api::immutable_data::GLOBAL_IMMUTABLE_DATA_POINTER,
|
||||||
|
context.word_type().array_type(0),
|
||||||
|
AddressSpace::Stack,
|
||||||
|
);
|
||||||
|
|
||||||
|
context.declare_global(
|
||||||
|
revive_runtime_api::immutable_data::GLOBAL_IMMUTABLE_DATA_SIZE,
|
||||||
|
context.xlen_type(),
|
||||||
|
AddressSpace::Stack,
|
||||||
|
);
|
||||||
|
|
||||||
let calldata_type = context.array_type(context.byte_type(), Self::MAX_CALLDATA_SIZE);
|
let calldata_type = context.array_type(context.byte_type(), Self::MAX_CALLDATA_SIZE);
|
||||||
context.set_global(
|
context.set_global(
|
||||||
crate::polkavm::GLOBAL_CALLDATA_POINTER,
|
crate::polkavm::GLOBAL_CALLDATA_POINTER,
|
||||||
@@ -125,8 +137,6 @@ impl Entry {
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
context.set_debug_location(0, 0, None)?;
|
|
||||||
|
|
||||||
let is_deploy = context
|
let is_deploy = context
|
||||||
.current_function()
|
.current_function()
|
||||||
.borrow()
|
.borrow()
|
||||||
@@ -185,18 +195,6 @@ where
|
|||||||
Some(inkwell::module::Linkage::External),
|
Some(inkwell::module::Linkage::External),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
context.declare_global(
|
|
||||||
revive_runtime_api::immutable_data::GLOBAL_IMMUTABLE_DATA_POINTER,
|
|
||||||
context.word_type().array_type(0),
|
|
||||||
AddressSpace::Stack,
|
|
||||||
);
|
|
||||||
|
|
||||||
context.declare_global(
|
|
||||||
revive_runtime_api::immutable_data::GLOBAL_IMMUTABLE_DATA_SIZE,
|
|
||||||
context.xlen_type(),
|
|
||||||
AddressSpace::Stack,
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +214,7 @@ where
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
context.set_current_function(runtime::FUNCTION_ENTRY, None)?;
|
context.set_current_function(runtime::FUNCTION_ENTRY)?;
|
||||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||||
|
|
||||||
Self::initialize_globals(context)?;
|
Self::initialize_globals(context)?;
|
||||||
@@ -227,8 +225,6 @@ where
|
|||||||
context.set_basic_block(context.current_function().borrow().return_block());
|
context.set_basic_block(context.current_function().borrow().return_block());
|
||||||
context.build_unreachable();
|
context.build_unreachable();
|
||||||
|
|
||||||
context.pop_debug_scope();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||||
context.set_current_function(runtime::FUNCTION_LOAD_IMMUTABLE_DATA, None)?;
|
context.set_current_function(runtime::FUNCTION_LOAD_IMMUTABLE_DATA)?;
|
||||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||||
|
|
||||||
let immutable_data_size_pointer = context
|
let immutable_data_size_pointer = context
|
||||||
@@ -111,8 +111,6 @@ where
|
|||||||
context.set_basic_block(return_block);
|
context.set_basic_block(return_block);
|
||||||
context.build_return(None);
|
context.build_return(None);
|
||||||
|
|
||||||
context.pop_debug_scope();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,14 +54,11 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
fn into_llvm(self, context: &mut Context<D>) -> anyhow::Result<()> {
|
||||||
context.set_current_function(runtime::FUNCTION_RUNTIME_CODE, None)?;
|
context.set_current_function(runtime::FUNCTION_RUNTIME_CODE)?;
|
||||||
|
|
||||||
context.set_basic_block(context.current_function().borrow().entry_block());
|
context.set_basic_block(context.current_function().borrow().entry_block());
|
||||||
context.set_code_type(CodeType::Runtime);
|
context.set_code_type(CodeType::Runtime);
|
||||||
|
|
||||||
self.inner.into_llvm(context)?;
|
self.inner.into_llvm(context)?;
|
||||||
context.set_debug_location(0, 0, None)?;
|
|
||||||
|
|
||||||
match context
|
match context
|
||||||
.basic_block()
|
.basic_block()
|
||||||
.get_last_instruction()
|
.get_last_instruction()
|
||||||
@@ -76,8 +73,6 @@ where
|
|||||||
context.set_basic_block(context.current_function().borrow().return_block());
|
context.set_basic_block(context.current_function().borrow().return_block());
|
||||||
context.build_unreachable();
|
context.build_unreachable();
|
||||||
|
|
||||||
context.pop_debug_scope();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ pub mod argument;
|
|||||||
pub mod attribute;
|
pub mod attribute;
|
||||||
pub mod build;
|
pub mod build;
|
||||||
pub mod code_type;
|
pub mod code_type;
|
||||||
pub mod debug_info;
|
// pub mod debug_info;
|
||||||
pub mod evmla_data;
|
pub mod evmla_data;
|
||||||
pub mod function;
|
pub mod function;
|
||||||
pub mod global;
|
pub mod global;
|
||||||
@@ -21,8 +21,6 @@ use std::cell::RefCell;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use inkwell::debug_info::AsDIScope;
|
|
||||||
use inkwell::debug_info::DIScope;
|
|
||||||
use inkwell::types::BasicType;
|
use inkwell::types::BasicType;
|
||||||
use inkwell::values::BasicValue;
|
use inkwell::values::BasicValue;
|
||||||
|
|
||||||
@@ -37,7 +35,7 @@ use self::address_space::AddressSpace;
|
|||||||
use self::attribute::Attribute;
|
use self::attribute::Attribute;
|
||||||
use self::build::Build;
|
use self::build::Build;
|
||||||
use self::code_type::CodeType;
|
use self::code_type::CodeType;
|
||||||
use self::debug_info::DebugInfo;
|
// use self::debug_info::DebugInfo;
|
||||||
use self::evmla_data::EVMLAData;
|
use self::evmla_data::EVMLAData;
|
||||||
use self::function::declaration::Declaration as FunctionDeclaration;
|
use self::function::declaration::Declaration as FunctionDeclaration;
|
||||||
use self::function::intrinsics::Intrinsics;
|
use self::function::intrinsics::Intrinsics;
|
||||||
@@ -87,9 +85,9 @@ where
|
|||||||
/// Whether to append the metadata hash at the end of bytecode.
|
/// Whether to append the metadata hash at the end of bytecode.
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
/// The debug info of the current module.
|
/// The debug info of the current module.
|
||||||
debug_info: Option<DebugInfo<'ctx>>,
|
// debug_info: DebugInfo<'ctx>,
|
||||||
/// The debug configuration telling whether to dump the needed IRs.
|
/// The debug configuration telling whether to dump the needed IRs.
|
||||||
debug_config: DebugConfig,
|
debug_config: Option<DebugConfig>,
|
||||||
|
|
||||||
/// The Solidity data.
|
/// The Solidity data.
|
||||||
solidity_data: Option<SolidityData>,
|
solidity_data: Option<SolidityData>,
|
||||||
@@ -140,7 +138,7 @@ where
|
|||||||
for import in revive_runtime_api::polkavm_imports::IMPORTS {
|
for import in revive_runtime_api::polkavm_imports::IMPORTS {
|
||||||
module
|
module
|
||||||
.get_function(import)
|
.get_function(import)
|
||||||
.unwrap_or_else(|| panic!("{import} import should be declared"))
|
.expect("should be declared")
|
||||||
.set_linkage(inkwell::module::Linkage::External);
|
.set_linkage(inkwell::module::Linkage::External);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,9 +163,8 @@ where
|
|||||||
|
|
||||||
fn link_immutable_data(&self, contract_path: &str) -> anyhow::Result<()> {
|
fn link_immutable_data(&self, contract_path: &str) -> anyhow::Result<()> {
|
||||||
let size = self.solidity().immutables_size() as u32;
|
let size = self.solidity().immutables_size() as u32;
|
||||||
let immutables = revive_runtime_api::immutable_data::module(self.llvm(), size);
|
let exports = revive_runtime_api::immutable_data::module(self.llvm(), size);
|
||||||
|
self.module.link_in_module(exports).map_err(|error| {
|
||||||
self.module.link_in_module(immutables).map_err(|error| {
|
|
||||||
anyhow::anyhow!(
|
anyhow::anyhow!(
|
||||||
"The contract `{}` immutable data module linking error: {}",
|
"The contract `{}` immutable data module linking error: {}",
|
||||||
contract_path,
|
contract_path,
|
||||||
@@ -203,16 +200,6 @@ where
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Configure the revive datalayout.
|
|
||||||
fn set_data_layout(
|
|
||||||
llvm: &'ctx inkwell::context::Context,
|
|
||||||
module: &inkwell::module::Module<'ctx>,
|
|
||||||
) {
|
|
||||||
let source_module = revive_stdlib::module(llvm, "revive_stdlib").unwrap();
|
|
||||||
let data_layout = source_module.get_data_layout();
|
|
||||||
module.set_data_layout(&data_layout);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Initializes a new LLVM context.
|
/// Initializes a new LLVM context.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
llvm: &'ctx inkwell::context::Context,
|
llvm: &'ctx inkwell::context::Context,
|
||||||
@@ -220,9 +207,8 @@ where
|
|||||||
optimizer: Optimizer,
|
optimizer: Optimizer,
|
||||||
dependency_manager: Option<D>,
|
dependency_manager: Option<D>,
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: DebugConfig,
|
debug_config: Option<DebugConfig>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::set_data_layout(llvm, &module);
|
|
||||||
Self::link_stdlib_module(llvm, &module);
|
Self::link_stdlib_module(llvm, &module);
|
||||||
Self::link_polkavm_imports(llvm, &module);
|
Self::link_polkavm_imports(llvm, &module);
|
||||||
Self::set_polkavm_stack_size(llvm, &module, Self::POLKAVM_STACK_SIZE);
|
Self::set_polkavm_stack_size(llvm, &module, Self::POLKAVM_STACK_SIZE);
|
||||||
@@ -230,11 +216,6 @@ where
|
|||||||
|
|
||||||
let intrinsics = Intrinsics::new(llvm, &module);
|
let intrinsics = Intrinsics::new(llvm, &module);
|
||||||
let llvm_runtime = LLVMRuntime::new(llvm, &module, &optimizer);
|
let llvm_runtime = LLVMRuntime::new(llvm, &module, &optimizer);
|
||||||
let debug_info = debug_config.emit_debug_info.then(|| {
|
|
||||||
let debug_info = DebugInfo::new(&module);
|
|
||||||
debug_info.initialize_module(llvm, &module);
|
|
||||||
debug_info
|
|
||||||
});
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
llvm,
|
llvm,
|
||||||
@@ -251,8 +232,7 @@ where
|
|||||||
|
|
||||||
dependency_manager,
|
dependency_manager,
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
|
// debug_info,
|
||||||
debug_info,
|
|
||||||
debug_config,
|
debug_config,
|
||||||
|
|
||||||
solidity_data: None,
|
solidity_data: None,
|
||||||
@@ -273,11 +253,11 @@ where
|
|||||||
self.link_immutable_data(contract_path)?;
|
self.link_immutable_data(contract_path)?;
|
||||||
|
|
||||||
let target_machine = TargetMachine::new(Target::PVM, self.optimizer.settings())?;
|
let target_machine = TargetMachine::new(Target::PVM, self.optimizer.settings())?;
|
||||||
self.module().set_triple(&target_machine.get_triple());
|
target_machine.set_target_data(self.module());
|
||||||
|
|
||||||
self.debug_config
|
|
||||||
.dump_llvm_ir_unoptimized(contract_path, self.module())?;
|
|
||||||
|
|
||||||
|
if let Some(ref debug_config) = self.debug_config {
|
||||||
|
debug_config.dump_llvm_ir_unoptimized(contract_path, self.module())?;
|
||||||
|
}
|
||||||
self.verify().map_err(|error| {
|
self.verify().map_err(|error| {
|
||||||
anyhow::anyhow!(
|
anyhow::anyhow!(
|
||||||
"The contract `{}` unoptimized LLVM IR verification error: {}",
|
"The contract `{}` unoptimized LLVM IR verification error: {}",
|
||||||
@@ -295,10 +275,9 @@ where
|
|||||||
error
|
error
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
if let Some(ref debug_config) = self.debug_config {
|
||||||
self.debug_config
|
debug_config.dump_llvm_ir_optimized(contract_path, self.module())?;
|
||||||
.dump_llvm_ir_optimized(contract_path, self.module())?;
|
}
|
||||||
|
|
||||||
self.verify().map_err(|error| {
|
self.verify().map_err(|error| {
|
||||||
anyhow::anyhow!(
|
anyhow::anyhow!(
|
||||||
"The contract `{}` optimized LLVM IR verification error: {}",
|
"The contract `{}` optimized LLVM IR verification error: {}",
|
||||||
@@ -317,17 +296,11 @@ where
|
|||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let shared_object = revive_linker::link(buffer.as_slice())?;
|
let bytecode = revive_linker::link(buffer.as_slice())?;
|
||||||
|
|
||||||
self.debug_config
|
|
||||||
.dump_object(contract_path, &shared_object)?;
|
|
||||||
|
|
||||||
let polkavm_bytecode =
|
|
||||||
revive_linker::polkavm_linker(shared_object, !self.debug_config().emit_debug_info)?;
|
|
||||||
|
|
||||||
let build = match crate::polkavm::build_assembly_text(
|
let build = match crate::polkavm::build_assembly_text(
|
||||||
contract_path,
|
contract_path,
|
||||||
&polkavm_bytecode,
|
&bytecode,
|
||||||
metadata_hash,
|
metadata_hash,
|
||||||
self.debug_config(),
|
self.debug_config(),
|
||||||
) {
|
) {
|
||||||
@@ -449,21 +422,6 @@ where
|
|||||||
) -> anyhow::Result<Rc<RefCell<Function<'ctx>>>> {
|
) -> anyhow::Result<Rc<RefCell<Function<'ctx>>>> {
|
||||||
let value = self.module().add_function(name, r#type, linkage);
|
let value = self.module().add_function(name, r#type, linkage);
|
||||||
|
|
||||||
if self.debug_info().is_some() {
|
|
||||||
self.builder().unset_current_debug_location();
|
|
||||||
let func_scope = match value.get_subprogram() {
|
|
||||||
None => {
|
|
||||||
let fn_name = value.get_name().to_str()?;
|
|
||||||
let scp = self.build_function_debug_info(fn_name, 0)?;
|
|
||||||
value.set_subprogram(scp);
|
|
||||||
scp
|
|
||||||
}
|
|
||||||
Some(scp) => scp,
|
|
||||||
};
|
|
||||||
self.push_debug_scope(func_scope.as_debug_info_scope());
|
|
||||||
self.set_debug_location(0, 0, Some(func_scope.as_debug_info_scope()))?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let entry_block = self.llvm.append_basic_block(value, "entry");
|
let entry_block = self.llvm.append_basic_block(value, "entry");
|
||||||
let return_block = self.llvm.append_basic_block(value, "return");
|
let return_block = self.llvm.append_basic_block(value, "return");
|
||||||
|
|
||||||
@@ -497,8 +455,6 @@ where
|
|||||||
let function = Rc::new(RefCell::new(function));
|
let function = Rc::new(RefCell::new(function));
|
||||||
self.functions.insert(name.to_string(), function.clone());
|
self.functions.insert(name.to_string(), function.clone());
|
||||||
|
|
||||||
self.pop_debug_scope();
|
|
||||||
|
|
||||||
Ok(function)
|
Ok(function)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -514,95 +470,15 @@ where
|
|||||||
.expect("Must be declared before use")
|
.expect("Must be declared before use")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the current active function. If debug-info generation is enabled,
|
/// Sets the current active function.
|
||||||
/// constructs a debug-scope and pushes in on the scope-stack.
|
pub fn set_current_function(&mut self, name: &str) -> anyhow::Result<()> {
|
||||||
pub fn set_current_function(&mut self, name: &str, line: Option<u32>) -> anyhow::Result<()> {
|
|
||||||
let function = self.functions.get(name).cloned().ok_or_else(|| {
|
let function = self.functions.get(name).cloned().ok_or_else(|| {
|
||||||
anyhow::anyhow!("Failed to activate an undeclared function `{}`", name)
|
anyhow::anyhow!("Failed to activate an undeclared function `{}`", name)
|
||||||
})?;
|
})?;
|
||||||
self.current_function = Some(function);
|
self.current_function = Some(function);
|
||||||
|
|
||||||
if let Some(scope) = self.current_function().borrow().get_debug_scope() {
|
|
||||||
self.push_debug_scope(scope);
|
|
||||||
}
|
|
||||||
self.set_debug_location(line.unwrap_or_default(), 0, None)?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builds a debug-info scope for a function.
|
|
||||||
pub fn build_function_debug_info(
|
|
||||||
&self,
|
|
||||||
name: &str,
|
|
||||||
line_no: u32,
|
|
||||||
) -> anyhow::Result<inkwell::debug_info::DISubprogram<'ctx>> {
|
|
||||||
let Some(debug_info) = self.debug_info() else {
|
|
||||||
anyhow::bail!("expected debug-info builders");
|
|
||||||
};
|
|
||||||
let builder = debug_info.builder();
|
|
||||||
let file = debug_info.compilation_unit().get_file();
|
|
||||||
let scope = file.as_debug_info_scope();
|
|
||||||
let flags = inkwell::debug_info::DIFlagsConstants::PUBLIC;
|
|
||||||
let return_type = debug_info.create_word_type(Some(flags))?.as_type();
|
|
||||||
let subroutine_type = builder.create_subroutine_type(file, Some(return_type), &[], flags);
|
|
||||||
|
|
||||||
Ok(builder.create_function(
|
|
||||||
scope,
|
|
||||||
name,
|
|
||||||
None,
|
|
||||||
file,
|
|
||||||
line_no,
|
|
||||||
subroutine_type,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
1,
|
|
||||||
flags,
|
|
||||||
false,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the debug info location.
|
|
||||||
///
|
|
||||||
/// No-op if the emitting debug info is disabled.
|
|
||||||
///
|
|
||||||
/// If `scope` is `None` the top scope will be used.
|
|
||||||
pub fn set_debug_location(
|
|
||||||
&self,
|
|
||||||
line: u32,
|
|
||||||
column: u32,
|
|
||||||
scope: Option<DIScope<'ctx>>,
|
|
||||||
) -> anyhow::Result<()> {
|
|
||||||
let Some(debug_info) = self.debug_info() else {
|
|
||||||
return Ok(());
|
|
||||||
};
|
|
||||||
let scope = match scope {
|
|
||||||
Some(scp) => scp,
|
|
||||||
None => debug_info.top_scope().expect("expected a debug-info scope"),
|
|
||||||
};
|
|
||||||
let location =
|
|
||||||
debug_info
|
|
||||||
.builder()
|
|
||||||
.create_debug_location(self.llvm(), line, column, scope, None);
|
|
||||||
|
|
||||||
self.builder().set_current_debug_location(location);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pushes a debug-info scope to the stack.
|
|
||||||
pub fn push_debug_scope(&self, scope: DIScope<'ctx>) {
|
|
||||||
if let Some(debug_info) = self.debug_info() {
|
|
||||||
debug_info.push_scope(scope);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pops the top of the debug-info scope stack.
|
|
||||||
pub fn pop_debug_scope(&self) {
|
|
||||||
if let Some(debug_info) = self.debug_info() {
|
|
||||||
debug_info.pop_scope();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pushes a new loop context to the stack.
|
/// Pushes a new loop context to the stack.
|
||||||
pub fn push_loop(
|
pub fn push_loop(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -672,14 +548,9 @@ where
|
|||||||
.expect("The dependency manager is unset")
|
.expect("The dependency manager is unset")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the debug info.
|
|
||||||
pub fn debug_info(&self) -> Option<&DebugInfo<'ctx>> {
|
|
||||||
self.debug_info.as_ref()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the debug config reference.
|
/// Returns the debug config reference.
|
||||||
pub fn debug_config(&self) -> &DebugConfig {
|
pub fn debug_config(&self) -> Option<&DebugConfig> {
|
||||||
&self.debug_config
|
self.debug_config.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Appends a new basic block to the current function.
|
/// Appends a new basic block to the current function.
|
||||||
@@ -798,10 +669,22 @@ where
|
|||||||
self.build_byte_swap(value)
|
self.build_byte_swap(value)
|
||||||
}
|
}
|
||||||
AddressSpace::Storage | AddressSpace::TransientStorage => {
|
AddressSpace::Storage | AddressSpace::TransientStorage => {
|
||||||
|
let storage_key_value = self.builder().build_ptr_to_int(
|
||||||
|
pointer.value,
|
||||||
|
self.word_type(),
|
||||||
|
"storage_ptr_to_int",
|
||||||
|
)?;
|
||||||
|
let storage_key_pointer = self.build_alloca(self.word_type(), "storage_key");
|
||||||
|
let storage_key_pointer_casted = self.builder().build_ptr_to_int(
|
||||||
|
storage_key_pointer.value,
|
||||||
|
self.xlen_type(),
|
||||||
|
"storage_key_pointer_casted",
|
||||||
|
)?;
|
||||||
|
self.builder()
|
||||||
|
.build_store(storage_key_pointer.value, storage_key_value)?;
|
||||||
|
|
||||||
let storage_value_pointer =
|
let storage_value_pointer =
|
||||||
self.build_alloca(self.word_type(), "storage_value_pointer");
|
self.build_alloca(self.word_type(), "storage_value_pointer");
|
||||||
self.build_store(storage_value_pointer, self.word_const(0))?;
|
|
||||||
|
|
||||||
let storage_value_length_pointer =
|
let storage_value_length_pointer =
|
||||||
self.build_alloca(self.xlen_type(), "storage_value_length_pointer");
|
self.build_alloca(self.xlen_type(), "storage_value_length_pointer");
|
||||||
self.build_store(
|
self.build_store(
|
||||||
@@ -815,7 +698,7 @@ where
|
|||||||
revive_runtime_api::polkavm_imports::GET_STORAGE,
|
revive_runtime_api::polkavm_imports::GET_STORAGE,
|
||||||
&[
|
&[
|
||||||
self.xlen_type().const_int(transient as u64, false).into(),
|
self.xlen_type().const_int(transient as u64, false).into(),
|
||||||
pointer.to_int(self).into(),
|
storage_key_pointer_casted.into(),
|
||||||
self.xlen_type().const_all_ones().into(),
|
self.xlen_type().const_all_ones().into(),
|
||||||
storage_value_pointer.to_int(self).into(),
|
storage_value_pointer.to_int(self).into(),
|
||||||
storage_value_length_pointer.to_int(self).into(),
|
storage_value_length_pointer.to_int(self).into(),
|
||||||
@@ -884,6 +767,18 @@ where
|
|||||||
self.word_type().as_basic_type_enum()
|
self.word_type().as_basic_type_enum()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let storage_key_value = self.builder().build_ptr_to_int(
|
||||||
|
pointer.value,
|
||||||
|
self.word_type(),
|
||||||
|
"storage_ptr_to_int",
|
||||||
|
)?;
|
||||||
|
let storage_key_pointer = self.build_alloca(self.word_type(), "storage_key");
|
||||||
|
let storage_key_pointer_casted = self.builder().build_ptr_to_int(
|
||||||
|
storage_key_pointer.value,
|
||||||
|
self.xlen_type(),
|
||||||
|
"storage_key_pointer_casted",
|
||||||
|
)?;
|
||||||
|
|
||||||
let storage_value_pointer = self.build_alloca(self.word_type(), "storage_value");
|
let storage_value_pointer = self.build_alloca(self.word_type(), "storage_value");
|
||||||
let storage_value_pointer_casted = self.builder().build_ptr_to_int(
|
let storage_value_pointer_casted = self.builder().build_ptr_to_int(
|
||||||
storage_value_pointer.value,
|
storage_value_pointer.value,
|
||||||
@@ -891,6 +786,8 @@ where
|
|||||||
"storage_value_pointer_casted",
|
"storage_value_pointer_casted",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
self.builder()
|
||||||
|
.build_store(storage_key_pointer.value, storage_key_value)?;
|
||||||
self.builder()
|
self.builder()
|
||||||
.build_store(storage_value_pointer.value, value)?;
|
.build_store(storage_value_pointer.value, value)?;
|
||||||
|
|
||||||
@@ -900,7 +797,7 @@ where
|
|||||||
revive_runtime_api::polkavm_imports::SET_STORAGE,
|
revive_runtime_api::polkavm_imports::SET_STORAGE,
|
||||||
&[
|
&[
|
||||||
self.xlen_type().const_int(transient as u64, false).into(),
|
self.xlen_type().const_int(transient as u64, false).into(),
|
||||||
pointer.to_int(self).into(),
|
storage_key_pointer_casted.into(),
|
||||||
self.xlen_type().const_all_ones().into(),
|
self.xlen_type().const_all_ones().into(),
|
||||||
storage_value_pointer_casted.into(),
|
storage_value_pointer_casted.into(),
|
||||||
self.integer_const(crate::polkavm::XLEN, 32).into(),
|
self.integer_const(crate::polkavm::XLEN, 32).into(),
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ pub fn create_context(
|
|||||||
let module = llvm.create_module("test");
|
let module = llvm.create_module("test");
|
||||||
let optimizer = Optimizer::new(optimizer_settings);
|
let optimizer = Optimizer::new(optimizer_settings);
|
||||||
|
|
||||||
Context::<DummyDependency>::new(llvm, module, optimizer, None, true, Default::default())
|
Context::<DummyDependency>::new(llvm, module, optimizer, None, true, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const REENTRANT_CALL_FLAG: u32 = 0b0000_1000;
|
|||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn call<'ctx, D>(
|
pub fn call<'ctx, D>(
|
||||||
context: &mut Context<'ctx, D>,
|
context: &mut Context<'ctx, D>,
|
||||||
gas: inkwell::values::IntValue<'ctx>,
|
_gas: inkwell::values::IntValue<'ctx>,
|
||||||
address: inkwell::values::IntValue<'ctx>,
|
address: inkwell::values::IntValue<'ctx>,
|
||||||
value: Option<inkwell::values::IntValue<'ctx>>,
|
value: Option<inkwell::values::IntValue<'ctx>>,
|
||||||
input_offset: inkwell::values::IntValue<'ctx>,
|
input_offset: inkwell::values::IntValue<'ctx>,
|
||||||
@@ -40,7 +40,7 @@ where
|
|||||||
// TODO: What to supply here? Is there a weight to gas?
|
// TODO: What to supply here? Is there a weight to gas?
|
||||||
let _gas = context
|
let _gas = context
|
||||||
.builder()
|
.builder()
|
||||||
.build_int_truncate(gas, context.integer_type(64), "gas")?;
|
.build_int_truncate(_gas, context.integer_type(64), "gas")?;
|
||||||
|
|
||||||
let input_pointer = context.build_heap_gep(input_offset, input_length)?;
|
let input_pointer = context.build_heap_gep(input_offset, input_length)?;
|
||||||
let output_pointer = context.build_heap_gep(output_offset, output_length)?;
|
let output_pointer = context.build_heap_gep(output_offset, output_length)?;
|
||||||
@@ -90,7 +90,7 @@ where
|
|||||||
let is_success = context.builder().build_int_compare(
|
let is_success = context.builder().build_int_compare(
|
||||||
inkwell::IntPredicate::EQ,
|
inkwell::IntPredicate::EQ,
|
||||||
success,
|
success,
|
||||||
context.integer_const(revive_common::BIT_LENGTH_X64, 0),
|
context.xlen_type().const_zero(),
|
||||||
"is_success",
|
"is_success",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -102,84 +102,20 @@ where
|
|||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn delegate_call<'ctx, D>(
|
pub fn delegate_call<'ctx, D>(
|
||||||
context: &mut Context<'ctx, D>,
|
_context: &mut Context<'ctx, D>,
|
||||||
gas: inkwell::values::IntValue<'ctx>,
|
_gas: inkwell::values::IntValue<'ctx>,
|
||||||
address: inkwell::values::IntValue<'ctx>,
|
_address: inkwell::values::IntValue<'ctx>,
|
||||||
input_offset: inkwell::values::IntValue<'ctx>,
|
_value: Option<inkwell::values::IntValue<'ctx>>,
|
||||||
input_length: inkwell::values::IntValue<'ctx>,
|
_input_offset: inkwell::values::IntValue<'ctx>,
|
||||||
output_offset: inkwell::values::IntValue<'ctx>,
|
_input_length: inkwell::values::IntValue<'ctx>,
|
||||||
output_length: inkwell::values::IntValue<'ctx>,
|
_output_offset: inkwell::values::IntValue<'ctx>,
|
||||||
|
_output_length: inkwell::values::IntValue<'ctx>,
|
||||||
_constants: Vec<Option<num::BigUint>>,
|
_constants: Vec<Option<num::BigUint>>,
|
||||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let address_pointer = context.build_address_argument_store(address)?;
|
todo!()
|
||||||
|
|
||||||
let input_offset = context.safe_truncate_int_to_xlen(input_offset)?;
|
|
||||||
let input_length = context.safe_truncate_int_to_xlen(input_length)?;
|
|
||||||
let output_offset = context.safe_truncate_int_to_xlen(output_offset)?;
|
|
||||||
let output_length = context.safe_truncate_int_to_xlen(output_length)?;
|
|
||||||
|
|
||||||
// TODO: What to supply here? Is there a weight to gas?
|
|
||||||
let _gas = context
|
|
||||||
.builder()
|
|
||||||
.build_int_truncate(gas, context.integer_type(64), "gas")?;
|
|
||||||
|
|
||||||
let input_pointer = context.build_heap_gep(input_offset, input_length)?;
|
|
||||||
let output_pointer = context.build_heap_gep(output_offset, output_length)?;
|
|
||||||
|
|
||||||
let output_length_pointer = context.build_alloca_at_entry(context.xlen_type(), "output_length");
|
|
||||||
context.build_store(output_length_pointer, output_length)?;
|
|
||||||
|
|
||||||
let flags = context.xlen_type().const_int(0u64, false);
|
|
||||||
|
|
||||||
let argument_type = revive_runtime_api::calling_convention::delegate_call(context.llvm());
|
|
||||||
let argument_pointer = context.build_alloca_at_entry(argument_type, "delegate_call_arguments");
|
|
||||||
let arguments = &[
|
|
||||||
flags.as_basic_value_enum(),
|
|
||||||
address_pointer.value.as_basic_value_enum(),
|
|
||||||
context
|
|
||||||
.integer_const(revive_common::BIT_LENGTH_X64, 0)
|
|
||||||
.as_basic_value_enum(),
|
|
||||||
context
|
|
||||||
.integer_const(revive_common::BIT_LENGTH_X64, 0)
|
|
||||||
.as_basic_value_enum(),
|
|
||||||
context.sentinel_pointer().value.as_basic_value_enum(),
|
|
||||||
input_pointer.value.as_basic_value_enum(),
|
|
||||||
input_length.as_basic_value_enum(),
|
|
||||||
output_pointer.value.as_basic_value_enum(),
|
|
||||||
output_length_pointer.value.as_basic_value_enum(),
|
|
||||||
];
|
|
||||||
revive_runtime_api::calling_convention::spill(
|
|
||||||
context.builder(),
|
|
||||||
argument_pointer.value,
|
|
||||||
argument_type,
|
|
||||||
arguments,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let name = revive_runtime_api::polkavm_imports::DELEGATE_CALL;
|
|
||||||
let argument_pointer = context.builder().build_ptr_to_int(
|
|
||||||
argument_pointer.value,
|
|
||||||
context.xlen_type(),
|
|
||||||
"delegate_call_argument_pointer",
|
|
||||||
)?;
|
|
||||||
let success = context
|
|
||||||
.build_runtime_call(name, &[argument_pointer.into()])
|
|
||||||
.unwrap_or_else(|| panic!("{name} should return a value"))
|
|
||||||
.into_int_value();
|
|
||||||
|
|
||||||
let is_success = context.builder().build_int_compare(
|
|
||||||
inkwell::IntPredicate::EQ,
|
|
||||||
success,
|
|
||||||
context.integer_const(revive_common::BIT_LENGTH_X64, 0),
|
|
||||||
"is_success",
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(context
|
|
||||||
.builder()
|
|
||||||
.build_int_z_extend(is_success, context.word_type(), "success")?
|
|
||||||
.as_basic_value_enum())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the Yul `linkersymbol` instruction.
|
/// Translates the Yul `linkersymbol` instruction.
|
||||||
|
|||||||
@@ -17,29 +17,22 @@ where
|
|||||||
|
|
||||||
/// Translates the `gas_price` instruction.
|
/// Translates the `gas_price` instruction.
|
||||||
pub fn gas_price<'ctx, D>(
|
pub fn gas_price<'ctx, D>(
|
||||||
context: &mut Context<'ctx, D>,
|
_context: &mut Context<'ctx, D>,
|
||||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
Ok(context.word_const(1).as_basic_value_enum())
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `tx.origin` instruction.
|
/// Translates the `tx.origin` instruction.
|
||||||
pub fn origin<'ctx, D>(
|
pub fn origin<'ctx, D>(
|
||||||
context: &mut Context<'ctx, D>,
|
_context: &mut Context<'ctx, D>,
|
||||||
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
) -> anyhow::Result<inkwell::values::BasicValueEnum<'ctx>>
|
||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let address_type = context.integer_type(revive_common::BIT_LENGTH_ETH_ADDRESS);
|
todo!()
|
||||||
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,
|
|
||||||
&[address_pointer.to_int(context).into()],
|
|
||||||
);
|
|
||||||
context.build_load_address(address_pointer)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `chain_id` instruction.
|
/// Translates the `chain_id` instruction.
|
||||||
@@ -74,24 +67,13 @@ where
|
|||||||
|
|
||||||
/// Translates the `block_hash` instruction.
|
/// Translates the `block_hash` instruction.
|
||||||
pub fn block_hash<'ctx, D>(
|
pub fn block_hash<'ctx, D>(
|
||||||
context: &mut Context<'ctx, D>,
|
_context: &mut Context<'ctx, D>,
|
||||||
index: inkwell::values::IntValue<'ctx>,
|
_index: 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 output_pointer = context.build_alloca_at_entry(context.word_type(), "blockhash_out_ptr");
|
todo!()
|
||||||
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_ptr.to_int(context).into(),
|
|
||||||
output_pointer.to_int(context).into(),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
context.build_byte_swap(context.build_load(output_pointer, "block_hash")?)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `difficulty` instruction.
|
/// Translates the `difficulty` instruction.
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
//! Translates the external code operations.
|
//! Translates the external code operations.
|
||||||
|
|
||||||
|
use inkwell::values::BasicValue;
|
||||||
|
|
||||||
use crate::polkavm::context::Context;
|
use crate::polkavm::context::Context;
|
||||||
use crate::polkavm::Dependency;
|
use crate::polkavm::Dependency;
|
||||||
|
|
||||||
@@ -12,23 +14,37 @@ pub fn size<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let address = match address {
|
let address_pointer = match address {
|
||||||
Some(address) => address,
|
Some(address) => {
|
||||||
None => super::context::address(context)?.into_int_value(),
|
let address_pointer = context.build_alloca(context.word_type(), "value");
|
||||||
|
context.build_store(address_pointer, address)?;
|
||||||
|
address_pointer
|
||||||
|
}
|
||||||
|
None => context.sentinel_pointer(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let address_pointer = context.build_address_argument_store(address)?;
|
let address_pointer_casted = context.builder().build_ptr_to_int(
|
||||||
let output_pointer = context.build_alloca_at_entry(context.word_type(), "output_pointer");
|
address_pointer.value,
|
||||||
|
context.xlen_type(),
|
||||||
|
"address_pointer",
|
||||||
|
)?;
|
||||||
|
let value = context
|
||||||
|
.build_runtime_call(
|
||||||
|
revive_runtime_api::polkavm_imports::CODE_SIZE,
|
||||||
|
&[address_pointer_casted.into()],
|
||||||
|
)
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
panic!(
|
||||||
|
"{} should return a value",
|
||||||
|
revive_runtime_api::polkavm_imports::CODE_SIZE
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.into_int_value();
|
||||||
|
|
||||||
context.build_runtime_call(
|
Ok(context
|
||||||
revive_runtime_api::polkavm_imports::CODE_SIZE,
|
.builder()
|
||||||
&[
|
.build_int_z_extend(value, context.word_type(), "extcodesize")?
|
||||||
address_pointer.to_int(context).into(),
|
.as_basic_value_enum())
|
||||||
output_pointer.to_int(context).into(),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
context.build_load(output_pointer, "code_size")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the `extcodehash` instruction.
|
/// Translates the `extcodehash` instruction.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
//! Translates the storage operations.
|
//! Translates the storage operations.
|
||||||
|
|
||||||
use crate::polkavm::context::address_space::AddressSpace;
|
use crate::polkavm::context::address_space::AddressSpace;
|
||||||
|
use crate::polkavm::context::pointer::Pointer;
|
||||||
use crate::polkavm::context::Context;
|
use crate::polkavm::context::Context;
|
||||||
use crate::polkavm::Dependency;
|
use crate::polkavm::Dependency;
|
||||||
|
|
||||||
@@ -12,10 +13,14 @@ pub fn load<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let mut slot_ptr = context.build_alloca_at_entry(context.word_type(), "slot_pointer");
|
let position_pointer = Pointer::new_with_offset(
|
||||||
slot_ptr.address_space = AddressSpace::Storage;
|
context,
|
||||||
context.builder().build_store(slot_ptr.value, position)?;
|
AddressSpace::Storage,
|
||||||
context.build_load(slot_ptr, "storage_load_value")
|
context.word_type(),
|
||||||
|
position,
|
||||||
|
"storage_load_position_pointer",
|
||||||
|
);
|
||||||
|
context.build_load(position_pointer, "storage_load_value")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the storage store.
|
/// Translates the storage store.
|
||||||
@@ -27,10 +32,14 @@ pub fn store<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let mut slot_ptr = context.build_alloca_at_entry(context.word_type(), "slot_pointer");
|
let position_pointer = Pointer::new_with_offset(
|
||||||
slot_ptr.address_space = AddressSpace::Storage;
|
context,
|
||||||
context.builder().build_store(slot_ptr.value, position)?;
|
AddressSpace::Storage,
|
||||||
context.build_store(slot_ptr, value)?;
|
context.word_type(),
|
||||||
|
position,
|
||||||
|
"storage_store_position_pointer",
|
||||||
|
);
|
||||||
|
context.build_store(position_pointer, value)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,10 +51,14 @@ pub fn transient_load<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let mut slot_ptr = context.build_alloca_at_entry(context.word_type(), "slot_pointer");
|
let position_pointer = Pointer::new_with_offset(
|
||||||
slot_ptr.address_space = AddressSpace::TransientStorage;
|
context,
|
||||||
context.builder().build_store(slot_ptr.value, position)?;
|
AddressSpace::TransientStorage,
|
||||||
context.build_load(slot_ptr, "transient_storage_load_value")
|
context.word_type(),
|
||||||
|
position,
|
||||||
|
"transient_storage_load_position_pointer",
|
||||||
|
);
|
||||||
|
context.build_load(position_pointer, "transient_storage_load_value")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the transient storage store.
|
/// Translates the transient storage store.
|
||||||
@@ -57,9 +70,13 @@ pub fn transient_store<'ctx, D>(
|
|||||||
where
|
where
|
||||||
D: Dependency + Clone,
|
D: Dependency + Clone,
|
||||||
{
|
{
|
||||||
let mut slot_ptr = context.build_alloca_at_entry(context.word_type(), "slot_pointer");
|
let position_pointer = Pointer::new_with_offset(
|
||||||
slot_ptr.address_space = AddressSpace::TransientStorage;
|
context,
|
||||||
context.builder().build_store(slot_ptr.value, position)?;
|
AddressSpace::TransientStorage,
|
||||||
context.build_store(slot_ptr, value)?;
|
context.word_type(),
|
||||||
|
position,
|
||||||
|
"transient_storage_store_position_pointer",
|
||||||
|
);
|
||||||
|
context.build_store(position_pointer, value)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ pub mod r#const;
|
|||||||
pub mod context;
|
pub mod context;
|
||||||
pub mod evm;
|
pub mod evm;
|
||||||
pub mod metadata_hash;
|
pub mod metadata_hash;
|
||||||
|
pub mod utils;
|
||||||
|
|
||||||
pub use self::r#const::*;
|
pub use self::r#const::*;
|
||||||
|
use self::utils::keccak256;
|
||||||
|
|
||||||
use crate::debug_config::DebugConfig;
|
use crate::debug_config::DebugConfig;
|
||||||
use crate::optimizer::settings::Settings as OptimizerSettings;
|
use crate::optimizer::settings::Settings as OptimizerSettings;
|
||||||
@@ -13,7 +15,6 @@ use crate::optimizer::settings::Settings as OptimizerSettings;
|
|||||||
use anyhow::Context as AnyhowContext;
|
use anyhow::Context as AnyhowContext;
|
||||||
use polkavm_common::program::ProgramBlob;
|
use polkavm_common::program::ProgramBlob;
|
||||||
use polkavm_disassembler::{Disassembler, DisassemblyFormat};
|
use polkavm_disassembler::{Disassembler, DisassemblyFormat};
|
||||||
use sha3::Digest;
|
|
||||||
|
|
||||||
use self::context::build::Build;
|
use self::context::build::Build;
|
||||||
use self::context::Context;
|
use self::context::Context;
|
||||||
@@ -28,7 +29,7 @@ pub fn build_assembly_text(
|
|||||||
contract_path: &str,
|
contract_path: &str,
|
||||||
bytecode: &[u8],
|
bytecode: &[u8],
|
||||||
metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_WORD]>,
|
metadata_hash: Option<[u8; revive_common::BYTE_LENGTH_WORD]>,
|
||||||
debug_config: &DebugConfig,
|
debug_config: Option<&DebugConfig>,
|
||||||
) -> anyhow::Result<Build> {
|
) -> anyhow::Result<Build> {
|
||||||
let program_blob = ProgramBlob::parse(bytecode.into())
|
let program_blob = ProgramBlob::parse(bytecode.into())
|
||||||
.map_err(anyhow::Error::msg)
|
.map_err(anyhow::Error::msg)
|
||||||
@@ -48,13 +49,15 @@ pub fn build_assembly_text(
|
|||||||
format!("Failed to convert disassembled code to string for contract: {contract_path}")
|
format!("Failed to convert disassembled code to string for contract: {contract_path}")
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
debug_config.dump_assembly(contract_path, &assembly_text)?;
|
if let Some(debug_config) = debug_config {
|
||||||
|
debug_config.dump_assembly(contract_path, &assembly_text)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Build::new(
|
Ok(Build::new(
|
||||||
assembly_text.to_owned(),
|
assembly_text.to_owned(),
|
||||||
metadata_hash,
|
metadata_hash,
|
||||||
bytecode.to_owned(),
|
bytecode.to_owned(),
|
||||||
hex::encode(sha3::Keccak256::digest(bytecode)),
|
keccak256(bytecode),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +98,7 @@ pub trait Dependency {
|
|||||||
path: &str,
|
path: &str,
|
||||||
optimizer_settings: OptimizerSettings,
|
optimizer_settings: OptimizerSettings,
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: DebugConfig,
|
debug_config: Option<DebugConfig>,
|
||||||
) -> anyhow::Result<String>;
|
) -> anyhow::Result<String>;
|
||||||
|
|
||||||
/// Resolves a full contract path.
|
/// Resolves a full contract path.
|
||||||
@@ -115,7 +118,7 @@ impl Dependency for DummyDependency {
|
|||||||
_path: &str,
|
_path: &str,
|
||||||
_optimizer_settings: OptimizerSettings,
|
_optimizer_settings: OptimizerSettings,
|
||||||
_include_metadata_hash: bool,
|
_include_metadata_hash: bool,
|
||||||
_debug_config: DebugConfig,
|
_debug_config: Option<DebugConfig>,
|
||||||
) -> anyhow::Result<String> {
|
) -> anyhow::Result<String> {
|
||||||
Ok(String::new())
|
Ok(String::new())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
//! Some LLVM IR generator utilies.
|
||||||
|
|
||||||
|
use crate::polkavm::context::Context;
|
||||||
|
use crate::polkavm::Dependency;
|
||||||
|
|
||||||
|
/// Clamps `value` to `max_value`, if `value` is bigger than `max_value`.
|
||||||
|
pub fn clamp<'ctx, D>(
|
||||||
|
context: &mut Context<'ctx, D>,
|
||||||
|
value: inkwell::values::IntValue<'ctx>,
|
||||||
|
max_value: inkwell::values::IntValue<'ctx>,
|
||||||
|
name: &str,
|
||||||
|
) -> anyhow::Result<inkwell::values::IntValue<'ctx>>
|
||||||
|
where
|
||||||
|
D: Dependency + Clone,
|
||||||
|
{
|
||||||
|
let in_bounds_block = context.append_basic_block(format!("{name}_is_bounds_block").as_str());
|
||||||
|
let join_block = context.append_basic_block(format!("{name}_join_block").as_str());
|
||||||
|
|
||||||
|
let pointer = context.build_alloca(context.word_type(), format!("{name}_pointer").as_str());
|
||||||
|
context.build_store(pointer, max_value)?;
|
||||||
|
|
||||||
|
let is_in_bounds = context.builder().build_int_compare(
|
||||||
|
inkwell::IntPredicate::ULE,
|
||||||
|
value,
|
||||||
|
max_value,
|
||||||
|
format!("{name}_is_in_bounds").as_str(),
|
||||||
|
)?;
|
||||||
|
context.build_conditional_branch(is_in_bounds, in_bounds_block, join_block)?;
|
||||||
|
|
||||||
|
context.set_basic_block(in_bounds_block);
|
||||||
|
context.build_store(pointer, value)?;
|
||||||
|
context.build_unconditional_branch(join_block);
|
||||||
|
|
||||||
|
context.set_basic_block(join_block);
|
||||||
|
let result = context.build_load(pointer, name)?;
|
||||||
|
Ok(result.into_int_value())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Computes the `keccak256` hash for `preimage`.
|
||||||
|
pub fn keccak256(preimage: &[u8]) -> String {
|
||||||
|
use sha3::Digest;
|
||||||
|
|
||||||
|
let hash_bytes = sha3::Keccak256::digest(preimage);
|
||||||
|
hash_bytes
|
||||||
|
.into_iter()
|
||||||
|
.map(|byte| format!("{byte:02x}"))
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join("")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn keccak256() {
|
||||||
|
assert_eq!(
|
||||||
|
super::keccak256("zksync".as_bytes()),
|
||||||
|
"0238fb1ab06c28c32885f9a4842207ac480c2467df26b6c58e201679628c5a5b"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,16 +20,28 @@ pub struct TargetMachine {
|
|||||||
|
|
||||||
impl TargetMachine {
|
impl TargetMachine {
|
||||||
/// The LLVM target name.
|
/// The LLVM target name.
|
||||||
|
#[cfg(not(feature = "riscv-64"))]
|
||||||
|
pub const VM_TARGET_NAME: &'static str = "riscv32";
|
||||||
|
#[cfg(feature = "riscv-64")]
|
||||||
pub const VM_TARGET_NAME: &'static str = "riscv64";
|
pub const VM_TARGET_NAME: &'static str = "riscv64";
|
||||||
|
|
||||||
/// The LLVM target triple.
|
/// The LLVM target triple.
|
||||||
|
#[cfg(not(feature = "riscv-64"))]
|
||||||
|
pub const VM_TARGET_TRIPLE: &'static str = "riscv32-unknown-unknown-elf";
|
||||||
|
#[cfg(feature = "riscv-64")]
|
||||||
pub const VM_TARGET_TRIPLE: &'static str = "riscv64-unknown-unknown-elf";
|
pub const VM_TARGET_TRIPLE: &'static str = "riscv64-unknown-unknown-elf";
|
||||||
|
|
||||||
|
/// The LLVM target cpu
|
||||||
|
#[cfg(not(feature = "riscv-64"))]
|
||||||
|
pub const VM_TARGET_CPU: &'static str = "generic-rv32";
|
||||||
|
#[cfg(feature = "riscv-64")]
|
||||||
pub const VM_TARGET_CPU: &'static str = "generic-rv64";
|
pub const VM_TARGET_CPU: &'static str = "generic-rv64";
|
||||||
|
|
||||||
/// LLVM target features.
|
/// LLVM target features.
|
||||||
pub const VM_FEATURES: &'static str =
|
#[cfg(feature = "riscv-zbb")]
|
||||||
"+e,+m,+a,+c,+zbb,+auipc-addi-fusion,+ld-add-fusion,+lui-addi-fusion,+xtheadcondmov";
|
pub const VM_FEATURES: &'static str = "+zbb,+e,+m,+c";
|
||||||
|
#[cfg(not(feature = "riscv-zbb"))]
|
||||||
|
pub const VM_FEATURES: &'static str = "+e,+m,+c";
|
||||||
|
|
||||||
/// A shortcut constructor.
|
/// A shortcut constructor.
|
||||||
/// A separate instance for every optimization level is created.
|
/// A separate instance for every optimization level is created.
|
||||||
@@ -58,6 +70,12 @@ impl TargetMachine {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the target-specific data in the module.
|
||||||
|
pub fn set_target_data(&self, module: &inkwell::module::Module) {
|
||||||
|
module.set_triple(&self.target_machine.get_triple());
|
||||||
|
module.set_data_layout(&self.target_machine.get_target_data().get_data_layout());
|
||||||
|
}
|
||||||
|
|
||||||
/// Writes the LLVM module to a memory buffer.
|
/// Writes the LLVM module to a memory buffer.
|
||||||
pub fn write_to_memory_buffer(
|
pub fn write_to_memory_buffer(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ impl Target {
|
|||||||
/// Returns the target name.
|
/// Returns the target name.
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
|
#[cfg(not(feature = "riscv-64"))]
|
||||||
|
Self::PVM => "riscv32",
|
||||||
|
#[cfg(feature = "riscv-64")]
|
||||||
Self::PVM => "riscv64",
|
Self::PVM => "riscv64",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,6 +23,9 @@ impl Target {
|
|||||||
/// Returns the target triple.
|
/// Returns the target triple.
|
||||||
pub fn triple(&self) -> &str {
|
pub fn triple(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
|
#[cfg(not(feature = "riscv-64"))]
|
||||||
|
Self::PVM => "riscv32-unknown-unknown-elf",
|
||||||
|
#[cfg(feature = "riscv-64")]
|
||||||
Self::PVM => "riscv64-unknown-unknown-elf",
|
Self::PVM => "riscv64-unknown-unknown-elf",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,6 +43,9 @@ impl FromStr for Target {
|
|||||||
|
|
||||||
fn from_str(string: &str) -> Result<Self, Self::Err> {
|
fn from_str(string: &str) -> Result<Self, Self::Err> {
|
||||||
match string {
|
match string {
|
||||||
|
#[cfg(not(feature = "riscv-64"))]
|
||||||
|
"riscv32" => Ok(Self::PVM),
|
||||||
|
#[cfg(feature = "riscv-64")]
|
||||||
"riscv64" => Ok(Self::PVM),
|
"riscv64" => Ok(Self::PVM),
|
||||||
_ => Err(anyhow::anyhow!(
|
_ => Err(anyhow::anyhow!(
|
||||||
"Unknown target `{}`. Supported targets: {:?}",
|
"Unknown target `{}`. Supported targets: {:?}",
|
||||||
@@ -50,6 +59,9 @@ impl FromStr for Target {
|
|||||||
impl std::fmt::Display for Target {
|
impl std::fmt::Display for Target {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
#[cfg(not(feature = "riscv-64"))]
|
||||||
|
Target::PVM => write!(f, "riscv32"),
|
||||||
|
#[cfg(feature = "riscv-64")]
|
||||||
Target::PVM => write!(f, "riscv64"),
|
Target::PVM => write!(f, "riscv64"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -55,7 +55,7 @@ pub const BOB: H160 = H160([2u8; 20]);
|
|||||||
/// The charlie test account
|
/// The charlie test account
|
||||||
pub const CHARLIE: H160 = H160([3u8; 20]);
|
pub const CHARLIE: H160 = H160([3u8; 20]);
|
||||||
/// Default gas limit
|
/// Default gas limit
|
||||||
pub const GAS_LIMIT: Weight = Weight::from_parts(100_000_000_000_000, 3 * 1024 * 1024 * 1024);
|
pub const GAS_LIMIT: Weight = Weight::from_parts(100_000_000_000, 3 * 1024 * 1024);
|
||||||
/// Default deposit limit
|
/// Default deposit limit
|
||||||
pub const DEPOSIT_LIMIT: Balance = 10_000_000;
|
pub const DEPOSIT_LIMIT: Balance = 10_000_000;
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ impl ExtBuilder {
|
|||||||
Self {
|
Self {
|
||||||
balance_genesis_config: value
|
balance_genesis_config: value
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(address, balance)| (AccountId::to_fallback_account_id(address), *balance))
|
.map(|(address, balance)| (AccountId::to_account_id(address), *balance))
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,7 +246,7 @@ pub enum Code {
|
|||||||
/// A contract blob
|
/// A contract blob
|
||||||
Bytes(Vec<u8>),
|
Bytes(Vec<u8>),
|
||||||
/// Pre-existing contract hash
|
/// Pre-existing contract hash
|
||||||
Hash(crate::runtime::Hash),
|
Hash(Hash),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Code {
|
impl Default for Code {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use frame_support::runtime;
|
use frame_support::runtime;
|
||||||
|
|
||||||
use pallet_revive::AccountId32Mapper;
|
|
||||||
use polkadot_sdk::*;
|
use polkadot_sdk::*;
|
||||||
use polkadot_sdk::{
|
use polkadot_sdk::{
|
||||||
polkadot_sdk_frame::{log, runtime::prelude::*},
|
polkadot_sdk_frame::{log, runtime::prelude::*},
|
||||||
@@ -8,7 +7,7 @@ use polkadot_sdk::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub type Balance = u128;
|
pub type Balance = u128;
|
||||||
pub type AccountId = pallet_revive::AccountId32Mapper<Runtime>;
|
pub type AccountId = pallet_revive::DefaultAddressMapper;
|
||||||
pub type Block = frame_system::mocking::MockBlock<Runtime>;
|
pub type Block = frame_system::mocking::MockBlock<Runtime>;
|
||||||
pub type Hash = <Runtime as frame_system::Config>::Hash;
|
pub type Hash = <Runtime as frame_system::Config>::Hash;
|
||||||
pub type EventRecord =
|
pub type EventRecord =
|
||||||
@@ -75,7 +74,7 @@ impl pallet_revive::Config for Runtime {
|
|||||||
type ChainExtension = ();
|
type ChainExtension = ();
|
||||||
type DepositPerByte = DepositPerByte;
|
type DepositPerByte = DepositPerByte;
|
||||||
type DepositPerItem = DepositPerItem;
|
type DepositPerItem = DepositPerItem;
|
||||||
type AddressMapper = AccountId32Mapper<Self>;
|
type AddressMapper = AccountId;
|
||||||
type RuntimeMemory = ConstU32<{ 512 * 1024 * 1024 }>;
|
type RuntimeMemory = ConstU32<{ 512 * 1024 * 1024 }>;
|
||||||
type PVFMemory = ConstU32<{ 1024 * 1024 * 1024 }>;
|
type PVFMemory = ConstU32<{ 1024 * 1024 * 1024 }>;
|
||||||
type UnsafeUnstableInterface = UnstableInterface;
|
type UnsafeUnstableInterface = UnstableInterface;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
|
use pallet_revive::AddressMapper;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ repository.workspace = true
|
|||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
description = "Implements the low level runtime API bindings with pallet contracts"
|
description = "Implements the low level runtime API bindings with pallet contracts"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
riscv-64 = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
inkwell = { workspace = true, features = ["target-riscv", "no-libffi-linking", "llvm18-0"] }
|
inkwell = { workspace = true, features = ["target-riscv", "no-libffi-linking", "llvm18-0"] }
|
||||||
|
|||||||
@@ -1,8 +1,23 @@
|
|||||||
use std::{env, fs, path::Path, process::Command};
|
use std::{env, fs, path::Path, process::Command};
|
||||||
|
|
||||||
|
#[cfg(not(feature = "riscv-64"))]
|
||||||
|
const TARGET_TRIPLE_FLAG: &str = "-triple=riscv32-unknown-unknown-elf";
|
||||||
|
#[cfg(feature = "riscv-64")]
|
||||||
const TARGET_TRIPLE_FLAG: &str = "-triple=riscv64-unknown-unknown-elf";
|
const TARGET_TRIPLE_FLAG: &str = "-triple=riscv64-unknown-unknown-elf";
|
||||||
|
|
||||||
|
#[cfg(not(feature = "riscv-64"))]
|
||||||
|
const TARGET_FLAG: &str = "--target=riscv32";
|
||||||
|
#[cfg(feature = "riscv-64")]
|
||||||
const TARGET_FLAG: &str = "--target=riscv64";
|
const TARGET_FLAG: &str = "--target=riscv64";
|
||||||
const TARGET_ARCH_FLAG: &str = "-march=rv64emac";
|
|
||||||
|
#[cfg(not(feature = "riscv-64"))]
|
||||||
|
const TARGET_ARCH_FLAG: &str = "-march=rv32em";
|
||||||
|
#[cfg(feature = "riscv-64")]
|
||||||
|
const TARGET_ARCH_FLAG: &str = "-march=rv64em";
|
||||||
|
|
||||||
|
#[cfg(not(feature = "riscv-64"))]
|
||||||
|
const TARGET_ABI_FLAG: &str = "-mabi=ilp32e";
|
||||||
|
#[cfg(feature = "riscv-64")]
|
||||||
const TARGET_ABI_FLAG: &str = "-mabi=lp64e";
|
const TARGET_ABI_FLAG: &str = "-mabi=lp64e";
|
||||||
|
|
||||||
const IMPORTS_SOUCE: &str = "src/polkavm_imports.c";
|
const IMPORTS_SOUCE: &str = "src/polkavm_imports.c";
|
||||||
@@ -21,10 +36,6 @@ fn compile(source_path: &str, bitcode_path: &str) {
|
|||||||
TARGET_TRIPLE_FLAG,
|
TARGET_TRIPLE_FLAG,
|
||||||
TARGET_ARCH_FLAG,
|
TARGET_ARCH_FLAG,
|
||||||
TARGET_ABI_FLAG,
|
TARGET_ABI_FLAG,
|
||||||
"-Xclang",
|
|
||||||
"-target-feature",
|
|
||||||
"-Xclang",
|
|
||||||
"+fast-unaligned-access,+xtheadcondmov",
|
|
||||||
"-fno-exceptions",
|
"-fno-exceptions",
|
||||||
"-ffreestanding",
|
"-ffreestanding",
|
||||||
"-Wall",
|
"-Wall",
|
||||||
|
|||||||
@@ -52,29 +52,29 @@ pub fn instantiate(context: &Context) -> StructType {
|
|||||||
context.struct_type(
|
context.struct_type(
|
||||||
&[
|
&[
|
||||||
// code_hash_ptr: u32,
|
// code_hash_ptr: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||||
// ref_time_limit: u64,
|
// ref_time_limit: u64,
|
||||||
context.i64_type().as_basic_type_enum(),
|
context.i64_type().as_basic_type_enum(),
|
||||||
// proof_size_limit: u64,
|
// proof_size_limit: u64,
|
||||||
context.i64_type().as_basic_type_enum(),
|
context.i64_type().as_basic_type_enum(),
|
||||||
// deposit_ptr: u32,
|
// deposit_ptr: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||||
// value_ptr: u32,
|
// value_ptr: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||||
// input_data_ptr: u32,
|
// input_data_ptr: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||||
// input_data_len: u32,
|
// input_data_len: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// address_ptr: u32,
|
// address_ptr: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||||
// output_ptr: u32,
|
// output_ptr: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||||
// output_len_ptr: u32,
|
// output_len_ptr: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||||
// salt_ptr: u32,
|
// salt_ptr: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||||
],
|
],
|
||||||
false,
|
true,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,51 +85,24 @@ pub fn call(context: &Context) -> StructType {
|
|||||||
// flags: u32,
|
// flags: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// address_ptr:
|
// address_ptr:
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||||
// ref_time_limit: u64,
|
// ref_time_limit: u64,
|
||||||
context.i64_type().as_basic_type_enum(),
|
context.i64_type().as_basic_type_enum(),
|
||||||
// proof_size_limit: u64,
|
// proof_size_limit: u64,
|
||||||
context.i64_type().as_basic_type_enum(),
|
context.i64_type().as_basic_type_enum(),
|
||||||
// deposit_ptr: u32,
|
// deposit_ptr: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||||
// value_ptr: u32,
|
// value_ptr: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||||
// input_data_ptr: u32,
|
// input_data_ptr: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||||
// input_data_len: u32,
|
// input_data_len: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// output_ptr: u32,
|
// output_ptr: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||||
// output_len_ptr: u32,
|
// output_len_ptr: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.ptr_type(Default::default()).as_basic_type_enum(),
|
||||||
],
|
],
|
||||||
false,
|
true,
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a packed struct argument type for the `delegate_call` API.
|
|
||||||
pub fn delegate_call(context: &Context) -> StructType {
|
|
||||||
context.struct_type(
|
|
||||||
&[
|
|
||||||
// flags: u32,
|
|
||||||
context.i32_type().as_basic_type_enum(),
|
|
||||||
// address_ptr:
|
|
||||||
context.i32_type().as_basic_type_enum(),
|
|
||||||
// ref_time_limit: u64,
|
|
||||||
context.i64_type().as_basic_type_enum(),
|
|
||||||
// proof_size_limit: u64,
|
|
||||||
context.i64_type().as_basic_type_enum(),
|
|
||||||
// deposit_ptr: u32,
|
|
||||||
context.i32_type().as_basic_type_enum(),
|
|
||||||
// input_data_ptr: u32,
|
|
||||||
context.i32_type().as_basic_type_enum(),
|
|
||||||
// input_data_len: u32,
|
|
||||||
context.i32_type().as_basic_type_enum(),
|
|
||||||
// output_ptr: u32,
|
|
||||||
context.i32_type().as_basic_type_enum(),
|
|
||||||
// output_len_ptr: u32,
|
|
||||||
context.i32_type().as_basic_type_enum(),
|
|
||||||
],
|
|
||||||
false,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,7 @@
|
|||||||
|
|
||||||
#define POLKAVM_REGS_FOR_TY_void 0
|
#define POLKAVM_REGS_FOR_TY_void 0
|
||||||
#define POLKAVM_REGS_FOR_TY_i32 1
|
#define POLKAVM_REGS_FOR_TY_i32 1
|
||||||
#ifdef _LP64
|
#define POLKAVM_REGS_FOR_TY_i64 2
|
||||||
#define POLKAVM_REGS_FOR_TY_i64 1
|
|
||||||
#else
|
|
||||||
#define POLKAVM_REGS_FOR_TY_i64 2
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define POLKAVM_REGS_FOR_TY_int8_t POLKAVM_REGS_FOR_TY_i32
|
#define POLKAVM_REGS_FOR_TY_int8_t POLKAVM_REGS_FOR_TY_i32
|
||||||
#define POLKAVM_REGS_FOR_TY_uint8_t POLKAVM_REGS_FOR_TY_i32
|
#define POLKAVM_REGS_FOR_TY_uint8_t POLKAVM_REGS_FOR_TY_i32
|
||||||
@@ -111,26 +107,6 @@ struct PolkaVM_Metadata {
|
|||||||
unsigned char output_regs;
|
unsigned char output_regs;
|
||||||
} __attribute__ ((packed));
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
#ifdef _LP64
|
|
||||||
#define POLKAVM_EXPORT_DEF() \
|
|
||||||
".quad %[metadata]\n" \
|
|
||||||
".quad %[function]\n"
|
|
||||||
#else
|
|
||||||
#define POLKAVM_EXPORT_DEF() \
|
|
||||||
".word %[metadata]\n" \
|
|
||||||
".word %[function]\n"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _LP64
|
|
||||||
#define POLKAVM_IMPORT_DEF() \
|
|
||||||
".word 0x0000000b\n" \
|
|
||||||
".quad %[metadata]\n"
|
|
||||||
#else
|
|
||||||
#define POLKAVM_IMPORT_DEF() \
|
|
||||||
".word 0x0000000b\n" \
|
|
||||||
".word %[metadata]\n"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define POLKAVM_EXPORT(arg_return_ty, fn_name, ...) \
|
#define POLKAVM_EXPORT(arg_return_ty, fn_name, ...) \
|
||||||
static struct PolkaVM_Metadata POLKAVM_JOIN(fn_name, __EXPORT_METADATA) __attribute__ ((section(".polkavm_metadata"))) = { \
|
static struct PolkaVM_Metadata POLKAVM_JOIN(fn_name, __EXPORT_METADATA) __attribute__ ((section(".polkavm_metadata"))) = { \
|
||||||
1, 0, sizeof(#fn_name) - 1, #fn_name, POLKAVM_COUNT_REGS(__VA_ARGS__), POLKAVM_COUNT_REGS(arg_return_ty) \
|
1, 0, sizeof(#fn_name) - 1, #fn_name, POLKAVM_COUNT_REGS(__VA_ARGS__), POLKAVM_COUNT_REGS(arg_return_ty) \
|
||||||
@@ -139,7 +115,8 @@ static void __attribute__ ((naked, used)) POLKAVM_UNIQUE(polkavm_export_dummy)()
|
|||||||
__asm__( \
|
__asm__( \
|
||||||
".pushsection .polkavm_exports,\"R\",@note\n" \
|
".pushsection .polkavm_exports,\"R\",@note\n" \
|
||||||
".byte 1\n" \
|
".byte 1\n" \
|
||||||
POLKAVM_EXPORT_DEF() \
|
".word %[metadata]\n" \
|
||||||
|
".word %[function]\n" \
|
||||||
".popsection\n" \
|
".popsection\n" \
|
||||||
: \
|
: \
|
||||||
: \
|
: \
|
||||||
@@ -153,9 +130,10 @@ static void __attribute__ ((naked, used)) POLKAVM_UNIQUE(polkavm_export_dummy)()
|
|||||||
static struct PolkaVM_Metadata POLKAVM_JOIN(fn_name, __IMPORT_METADATA) __attribute__ ((section(".polkavm_metadata"))) = { \
|
static struct PolkaVM_Metadata POLKAVM_JOIN(fn_name, __IMPORT_METADATA) __attribute__ ((section(".polkavm_metadata"))) = { \
|
||||||
1, 0, sizeof(#fn_name) - 1, #fn_name, POLKAVM_COUNT_REGS(__VA_ARGS__), POLKAVM_COUNT_REGS(arg_return_ty) \
|
1, 0, sizeof(#fn_name) - 1, #fn_name, POLKAVM_COUNT_REGS(__VA_ARGS__), POLKAVM_COUNT_REGS(arg_return_ty) \
|
||||||
}; \
|
}; \
|
||||||
static arg_return_ty __attribute__ ((used, naked)) fn_name(POLKAVM_IMPORT_ARGS_IMPL(__VA_ARGS__)) { \
|
static arg_return_ty __attribute__ ((naked, used)) fn_name(POLKAVM_IMPORT_ARGS_IMPL(__VA_ARGS__)) { \
|
||||||
__asm__( \
|
__asm__( \
|
||||||
POLKAVM_IMPORT_DEF() \
|
".word 0x0000000b\n" \
|
||||||
|
".word %[metadata]\n" \
|
||||||
"ret\n" \
|
"ret\n" \
|
||||||
: \
|
: \
|
||||||
: \
|
: \
|
||||||
|
|||||||
@@ -70,19 +70,15 @@ POLKAVM_IMPORT(void, balance, uint32_t)
|
|||||||
|
|
||||||
POLKAVM_IMPORT(void, balance_of, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, balance_of, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, block_hash, uint32_t, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, block_number, uint32_t)
|
POLKAVM_IMPORT(void, block_number, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint64_t, call, uint32_t)
|
POLKAVM_IMPORT(uint32_t, call, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint64_t, delegate_call, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, caller, uint32_t)
|
POLKAVM_IMPORT(void, caller, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, chain_id, uint32_t)
|
POLKAVM_IMPORT(void, chain_id, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, code_size, uint32_t, uint32_t)
|
POLKAVM_IMPORT(uint32_t, code_size, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, code_hash, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, code_hash, uint32_t, uint32_t)
|
||||||
|
|
||||||
@@ -90,21 +86,19 @@ POLKAVM_IMPORT(void, deposit_event, uint32_t, uint32_t, uint32_t, uint32_t)
|
|||||||
|
|
||||||
POLKAVM_IMPORT(void, get_immutable_data, uint32_t, uint32_t);
|
POLKAVM_IMPORT(void, get_immutable_data, uint32_t, uint32_t);
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint64_t, get_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(uint32_t, get_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, hash_keccak_256, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, hash_keccak_256, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, input, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, input, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint64_t, instantiate, uint32_t)
|
POLKAVM_IMPORT(uint32_t, instantiate, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, now, uint32_t)
|
POLKAVM_IMPORT(void, now, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, origin, uint32_t)
|
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, seal_return, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, seal_return, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint64_t, set_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(uint32_t, set_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, return_data_copy, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, return_data_copy, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
@@ -113,5 +107,3 @@ POLKAVM_IMPORT(void, return_data_size, uint32_t)
|
|||||||
POLKAVM_IMPORT(void, set_immutable_data, uint32_t, uint32_t);
|
POLKAVM_IMPORT(void, set_immutable_data, uint32_t, uint32_t);
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, value_transferred, uint32_t)
|
POLKAVM_IMPORT(void, value_transferred, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, weight_to_fee, uint64_t, uint64_t, uint32_t);
|
|
||||||
|
|||||||
@@ -20,14 +20,10 @@ pub static BALANCE: &str = "balance";
|
|||||||
|
|
||||||
pub static BALANCE_OF: &str = "balance_of";
|
pub static BALANCE_OF: &str = "balance_of";
|
||||||
|
|
||||||
pub static BLOCK_HASH: &str = "block_hash";
|
|
||||||
|
|
||||||
pub static BLOCK_NUMBER: &str = "block_number";
|
pub static BLOCK_NUMBER: &str = "block_number";
|
||||||
|
|
||||||
pub static CALL: &str = "call";
|
pub static CALL: &str = "call";
|
||||||
|
|
||||||
pub static DELEGATE_CALL: &str = "delegate_call";
|
|
||||||
|
|
||||||
pub static CALLER: &str = "caller";
|
pub static CALLER: &str = "caller";
|
||||||
|
|
||||||
pub static CHAIN_ID: &str = "chain_id";
|
pub static CHAIN_ID: &str = "chain_id";
|
||||||
@@ -50,8 +46,6 @@ pub static INSTANTIATE: &str = "instantiate";
|
|||||||
|
|
||||||
pub static NOW: &str = "now";
|
pub static NOW: &str = "now";
|
||||||
|
|
||||||
pub static ORIGIN: &str = "origin";
|
|
||||||
|
|
||||||
pub static RETURN: &str = "seal_return";
|
pub static RETURN: &str = "seal_return";
|
||||||
|
|
||||||
pub static SET_STORAGE: &str = "set_storage";
|
pub static SET_STORAGE: &str = "set_storage";
|
||||||
@@ -64,20 +58,16 @@ pub static SET_IMMUTABLE_DATA: &str = "set_immutable_data";
|
|||||||
|
|
||||||
pub static VALUE_TRANSFERRED: &str = "value_transferred";
|
pub static VALUE_TRANSFERRED: &str = "value_transferred";
|
||||||
|
|
||||||
pub static WEIGHT_TO_FEE: &str = "weight_to_fee";
|
|
||||||
|
|
||||||
/// All imported runtime API symbols.
|
/// All imported runtime API symbols.
|
||||||
/// Useful for configuring common attributes and linkage.
|
/// Useful for configuring common attributes and linkage.
|
||||||
pub static IMPORTS: [&str; 28] = [
|
pub static IMPORTS: [&str; 24] = [
|
||||||
SBRK,
|
SBRK,
|
||||||
MEMORY_SIZE,
|
MEMORY_SIZE,
|
||||||
ADDRESS,
|
ADDRESS,
|
||||||
BALANCE,
|
BALANCE,
|
||||||
BALANCE_OF,
|
BALANCE_OF,
|
||||||
BLOCK_HASH,
|
|
||||||
BLOCK_NUMBER,
|
BLOCK_NUMBER,
|
||||||
CALL,
|
CALL,
|
||||||
DELEGATE_CALL,
|
|
||||||
CALLER,
|
CALLER,
|
||||||
CHAIN_ID,
|
CHAIN_ID,
|
||||||
CODE_SIZE,
|
CODE_SIZE,
|
||||||
@@ -89,14 +79,12 @@ pub static IMPORTS: [&str; 28] = [
|
|||||||
INPUT,
|
INPUT,
|
||||||
INSTANTIATE,
|
INSTANTIATE,
|
||||||
NOW,
|
NOW,
|
||||||
ORIGIN,
|
|
||||||
RETURN,
|
RETURN,
|
||||||
RETURNDATACOPY,
|
RETURNDATACOPY,
|
||||||
RETURNDATASIZE,
|
RETURNDATASIZE,
|
||||||
SET_IMMUTABLE_DATA,
|
SET_IMMUTABLE_DATA,
|
||||||
SET_STORAGE,
|
SET_STORAGE,
|
||||||
VALUE_TRANSFERRED,
|
VALUE_TRANSFERRED,
|
||||||
WEIGHT_TO_FEE,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/// Creates a LLVM module from the [BITCODE].
|
/// Creates a LLVM module from the [BITCODE].
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ thiserror = { workspace = true }
|
|||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
which = { workspace = true }
|
which = { workspace = true }
|
||||||
path-slash = { workspace = true }
|
path-slash = { workspace = true }
|
||||||
rayon = { workspace = true, optional = true }
|
rayon = { workspace = true }
|
||||||
|
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
@@ -41,13 +41,6 @@ inkwell = { workspace = true }
|
|||||||
revive-common = { workspace = true }
|
revive-common = { workspace = true }
|
||||||
revive-llvm-context = { workspace = true }
|
revive-llvm-context = { workspace = true }
|
||||||
|
|
||||||
|
|
||||||
[target.'cfg(target_env = "musl")'.dependencies]
|
[target.'cfg(target_env = "musl")'.dependencies]
|
||||||
mimalloc = { version = "*", default-features = false }
|
mimalloc = { version = "*", default-features = false }
|
||||||
|
|
||||||
[target.'cfg(target_os = "emscripten")'.dependencies]
|
|
||||||
libc = { workspace = true }
|
|
||||||
inkwell = { workspace = true, features = ["target-riscv", "llvm18-0-no-llvm-linking"]}
|
|
||||||
|
|
||||||
[features]
|
|
||||||
parallel = ["rayon"]
|
|
||||||
default = ["parallel"]
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
fn main() {
|
|
||||||
let git_rev = std::process::Command::new("git")
|
|
||||||
.args(["rev-parse", "--short", "HEAD"])
|
|
||||||
.output()
|
|
||||||
.map(|out| String::from_utf8(out.stdout).unwrap_or_default())
|
|
||||||
.unwrap_or("unknown".to_owned());
|
|
||||||
|
|
||||||
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", git_rev.trim());
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,6 @@ use std::path::Path;
|
|||||||
use crate::solc::combined_json::CombinedJson;
|
use crate::solc::combined_json::CombinedJson;
|
||||||
use crate::solc::standard_json::output::Output as StandardJsonOutput;
|
use crate::solc::standard_json::output::Output as StandardJsonOutput;
|
||||||
use crate::solc::version::Version as SolcVersion;
|
use crate::solc::version::Version as SolcVersion;
|
||||||
use crate::ResolcVersion;
|
|
||||||
|
|
||||||
use self::contract::Contract;
|
use self::contract::Contract;
|
||||||
|
|
||||||
@@ -41,7 +40,11 @@ impl Build {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Writes all contracts assembly and bytecode to the combined JSON.
|
/// Writes all contracts assembly and bytecode to the combined JSON.
|
||||||
pub fn write_to_combined_json(self, combined_json: &mut CombinedJson) -> anyhow::Result<()> {
|
pub fn write_to_combined_json(
|
||||||
|
self,
|
||||||
|
combined_json: &mut CombinedJson,
|
||||||
|
resolc_version: &semver::Version,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
for (path, contract) in self.contracts.into_iter() {
|
for (path, contract) in self.contracts.into_iter() {
|
||||||
let combined_json_contract = combined_json
|
let combined_json_contract = combined_json
|
||||||
.contracts
|
.contracts
|
||||||
@@ -58,7 +61,7 @@ impl Build {
|
|||||||
contract.write_to_combined_json(combined_json_contract)?;
|
contract.write_to_combined_json(combined_json_contract)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
combined_json.revive_version = Some(ResolcVersion::default().long);
|
combined_json.zk_version = Some(resolc_version.to_string());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -68,6 +71,7 @@ impl Build {
|
|||||||
mut self,
|
mut self,
|
||||||
standard_json: &mut StandardJsonOutput,
|
standard_json: &mut StandardJsonOutput,
|
||||||
solc_version: &SolcVersion,
|
solc_version: &SolcVersion,
|
||||||
|
resolc_version: &semver::Version,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let contracts = match standard_json.contracts.as_mut() {
|
let contracts = match standard_json.contracts.as_mut() {
|
||||||
Some(contracts) => contracts,
|
Some(contracts) => contracts,
|
||||||
@@ -86,7 +90,7 @@ impl Build {
|
|||||||
|
|
||||||
standard_json.version = Some(solc_version.default.to_string());
|
standard_json.version = Some(solc_version.default.to_string());
|
||||||
standard_json.long_version = Some(solc_version.long.to_owned());
|
standard_json.long_version = Some(solc_version.long.to_owned());
|
||||||
standard_json.revive_version = Some(ResolcVersion::default().long);
|
standard_json.zk_version = Some(resolc_version.to_string());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ use std::collections::HashSet;
|
|||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use sha3::Digest;
|
|
||||||
|
|
||||||
use crate::evmla::ethereal_ir::entry_link::EntryLink;
|
use crate::evmla::ethereal_ir::entry_link::EntryLink;
|
||||||
use crate::evmla::ethereal_ir::EtherealIR;
|
use crate::evmla::ethereal_ir::EtherealIR;
|
||||||
@@ -46,7 +45,7 @@ impl Assembly {
|
|||||||
/// Gets the contract `keccak256` hash.
|
/// Gets the contract `keccak256` hash.
|
||||||
pub fn keccak256(&self) -> String {
|
pub fn keccak256(&self) -> String {
|
||||||
let json = serde_json::to_vec(self).expect("Always valid");
|
let json = serde_json::to_vec(self).expect("Always valid");
|
||||||
hex::encode(sha3::Keccak256::digest(json.as_slice()))
|
revive_llvm_context::polkavm_utils::keccak256(json.as_slice())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the full contract path.
|
/// Sets the full contract path.
|
||||||
@@ -213,10 +212,9 @@ where
|
|||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let full_path = self.full_path().to_owned();
|
let full_path = self.full_path().to_owned();
|
||||||
|
|
||||||
context
|
if let Some(debug_config) = context.debug_config() {
|
||||||
.debug_config()
|
debug_config.dump_evmla(full_path.as_str(), self.to_string().as_str())?;
|
||||||
.dump_evmla(full_path.as_str(), self.to_string().as_str())?;
|
}
|
||||||
|
|
||||||
let deploy_code_blocks = EtherealIR::get_blocks(
|
let deploy_code_blocks = EtherealIR::get_blocks(
|
||||||
context.evmla().version.to_owned(),
|
context.evmla().version.to_owned(),
|
||||||
revive_llvm_context::PolkaVMCodeType::Deploy,
|
revive_llvm_context::PolkaVMCodeType::Deploy,
|
||||||
@@ -230,11 +228,9 @@ where
|
|||||||
.ok_or_else(|| anyhow::anyhow!("Runtime code data not found"))?
|
.ok_or_else(|| anyhow::anyhow!("Runtime code data not found"))?
|
||||||
.remove("0")
|
.remove("0")
|
||||||
.expect("Always exists");
|
.expect("Always exists");
|
||||||
|
if let Some(debug_config) = context.debug_config() {
|
||||||
context
|
debug_config.dump_evmla(full_path.as_str(), data.to_string().as_str())?;
|
||||||
.debug_config()
|
}
|
||||||
.dump_evmla(full_path.as_str(), data.to_string().as_str())?;
|
|
||||||
|
|
||||||
let runtime_code_instructions = match data {
|
let runtime_code_instructions = match data {
|
||||||
Data::Assembly(assembly) => assembly
|
Data::Assembly(assembly) => assembly
|
||||||
.code
|
.code
|
||||||
@@ -257,11 +253,9 @@ where
|
|||||||
blocks.extend(runtime_code_blocks);
|
blocks.extend(runtime_code_blocks);
|
||||||
let mut ethereal_ir =
|
let mut ethereal_ir =
|
||||||
EtherealIR::new(context.evmla().version.to_owned(), extra_metadata, blocks)?;
|
EtherealIR::new(context.evmla().version.to_owned(), extra_metadata, blocks)?;
|
||||||
|
if let Some(debug_config) = context.debug_config() {
|
||||||
context
|
debug_config.dump_ethir(full_path.as_str(), ethereal_ir.to_string().as_str())?;
|
||||||
.debug_config()
|
}
|
||||||
.dump_ethir(full_path.as_str(), ethereal_ir.to_string().as_str())?;
|
|
||||||
|
|
||||||
ethereal_ir.declare(context)?;
|
ethereal_ir.declare(context)?;
|
||||||
ethereal_ir.into_llvm(context)?;
|
ethereal_ir.into_llvm(context)?;
|
||||||
|
|
||||||
|
|||||||
@@ -1096,6 +1096,7 @@ where
|
|||||||
context,
|
context,
|
||||||
gas,
|
gas,
|
||||||
address,
|
address,
|
||||||
|
None,
|
||||||
input_offset,
|
input_offset,
|
||||||
input_size,
|
input_size,
|
||||||
output_offset,
|
output_offset,
|
||||||
|
|||||||
@@ -1175,7 +1175,7 @@ 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<()> {
|
||||||
context.set_current_function(self.name.as_str(), None)?;
|
context.set_current_function(self.name.as_str())?;
|
||||||
|
|
||||||
for (key, blocks) in self.blocks.iter() {
|
for (key, blocks) in self.blocks.iter() {
|
||||||
for (index, block) in blocks.iter().enumerate() {
|
for (index, block) in blocks.iter().enumerate() {
|
||||||
@@ -1297,8 +1297,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context.pop_debug_scope();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+31
-33
@@ -7,7 +7,6 @@ pub(crate) mod missing_libraries;
|
|||||||
pub(crate) mod process;
|
pub(crate) mod process;
|
||||||
pub(crate) mod project;
|
pub(crate) mod project;
|
||||||
pub(crate) mod solc;
|
pub(crate) mod solc;
|
||||||
pub(crate) mod version;
|
|
||||||
pub(crate) mod warning;
|
pub(crate) mod warning;
|
||||||
pub(crate) mod yul;
|
pub(crate) mod yul;
|
||||||
|
|
||||||
@@ -15,22 +14,15 @@ pub use self::build::contract::Contract as ContractBuild;
|
|||||||
pub use self::build::Build;
|
pub use self::build::Build;
|
||||||
pub use self::missing_libraries::MissingLibraries;
|
pub use self::missing_libraries::MissingLibraries;
|
||||||
pub use self::process::input::Input as ProcessInput;
|
pub use self::process::input::Input as ProcessInput;
|
||||||
#[cfg(not(target_os = "emscripten"))]
|
|
||||||
pub use self::process::native_process::NativeProcess;
|
|
||||||
pub use self::process::output::Output as ProcessOutput;
|
pub use self::process::output::Output as ProcessOutput;
|
||||||
#[cfg(target_os = "emscripten")]
|
pub use self::process::run as run_process;
|
||||||
pub use self::process::worker_process::WorkerProcess;
|
pub use self::process::EXECUTABLE;
|
||||||
pub use self::process::Process;
|
|
||||||
pub use self::project::contract::Contract as ProjectContract;
|
pub use self::project::contract::Contract as ProjectContract;
|
||||||
pub use self::project::Project;
|
pub use self::project::Project;
|
||||||
pub use self::r#const::*;
|
pub use self::r#const::*;
|
||||||
pub use self::solc::combined_json::contract::Contract as SolcCombinedJsonContract;
|
pub use self::solc::combined_json::contract::Contract as SolcCombinedJsonContract;
|
||||||
pub use self::solc::combined_json::CombinedJson as SolcCombinedJson;
|
pub use self::solc::combined_json::CombinedJson as SolcCombinedJson;
|
||||||
pub use self::solc::pipeline::Pipeline as SolcPipeline;
|
pub use self::solc::pipeline::Pipeline as SolcPipeline;
|
||||||
#[cfg(not(target_os = "emscripten"))]
|
|
||||||
pub use self::solc::solc_compiler::SolcCompiler;
|
|
||||||
#[cfg(target_os = "emscripten")]
|
|
||||||
pub use self::solc::soljson_compiler::SoljsonCompiler;
|
|
||||||
pub use self::solc::standard_json::input::language::Language as SolcStandardJsonInputLanguage;
|
pub use self::solc::standard_json::input::language::Language as SolcStandardJsonInputLanguage;
|
||||||
pub use self::solc::standard_json::input::settings::metadata::Metadata as SolcStandardJsonInputSettingsMetadata;
|
pub use self::solc::standard_json::input::settings::metadata::Metadata as SolcStandardJsonInputSettingsMetadata;
|
||||||
pub use self::solc::standard_json::input::settings::optimizer::Optimizer as SolcStandardJsonInputSettingsOptimizer;
|
pub use self::solc::standard_json::input::settings::optimizer::Optimizer as SolcStandardJsonInputSettingsOptimizer;
|
||||||
@@ -45,10 +37,9 @@ pub use self::solc::standard_json::output::contract::evm::EVM as SolcStandardJso
|
|||||||
pub use self::solc::standard_json::output::contract::Contract as SolcStandardJsonOutputContract;
|
pub use self::solc::standard_json::output::contract::Contract as SolcStandardJsonOutputContract;
|
||||||
pub use self::solc::standard_json::output::Output as SolcStandardJsonOutput;
|
pub use self::solc::standard_json::output::Output as SolcStandardJsonOutput;
|
||||||
pub use self::solc::version::Version as SolcVersion;
|
pub use self::solc::version::Version as SolcVersion;
|
||||||
pub use self::solc::Compiler;
|
pub use self::solc::Compiler as SolcCompiler;
|
||||||
pub use self::version::Version as ResolcVersion;
|
|
||||||
pub use self::warning::Warning;
|
pub use self::warning::Warning;
|
||||||
#[cfg(not(target_os = "emscripten"))]
|
|
||||||
pub mod test_utils;
|
pub mod test_utils;
|
||||||
pub mod tests;
|
pub mod tests;
|
||||||
|
|
||||||
@@ -56,12 +47,12 @@ use std::collections::BTreeSet;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
/// Runs the Yul mode.
|
/// Runs the Yul mode.
|
||||||
pub fn yul<T: Compiler>(
|
pub fn yul(
|
||||||
input_files: &[PathBuf],
|
input_files: &[PathBuf],
|
||||||
solc: &mut T,
|
solc: &mut SolcCompiler,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: revive_llvm_context::DebugConfig,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<Build> {
|
) -> anyhow::Result<Build> {
|
||||||
let path = match input_files.len() {
|
let path = match input_files.len() {
|
||||||
1 => input_files.first().expect("Always exists"),
|
1 => input_files.first().expect("Always exists"),
|
||||||
@@ -72,10 +63,10 @@ pub fn yul<T: Compiler>(
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
if solc.version()?.default != solc::LAST_SUPPORTED_VERSION {
|
if solc.version()?.default != SolcCompiler::LAST_SUPPORTED_VERSION {
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"The Yul mode is only supported with the most recent version of the Solidity compiler: {}",
|
"The Yul mode is only supported with the most recent version of the Solidity compiler: {}",
|
||||||
solc::LAST_SUPPORTED_VERSION,
|
SolcCompiler::LAST_SUPPORTED_VERSION,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +83,7 @@ pub fn llvm_ir(
|
|||||||
input_files: &[PathBuf],
|
input_files: &[PathBuf],
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: revive_llvm_context::DebugConfig,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<Build> {
|
) -> anyhow::Result<Build> {
|
||||||
let path = match input_files.len() {
|
let path = match input_files.len() {
|
||||||
1 => input_files.first().expect("Always exists"),
|
1 => input_files.first().expect("Always exists"),
|
||||||
@@ -112,10 +103,10 @@ pub fn llvm_ir(
|
|||||||
|
|
||||||
/// Runs the standard output mode.
|
/// Runs the standard output mode.
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn standard_output<T: Compiler>(
|
pub fn standard_output(
|
||||||
input_files: &[PathBuf],
|
input_files: &[PathBuf],
|
||||||
libraries: Vec<String>,
|
libraries: Vec<String>,
|
||||||
solc: &mut T,
|
solc: &mut SolcCompiler,
|
||||||
evm_version: Option<revive_common::EVMVersion>,
|
evm_version: Option<revive_common::EVMVersion>,
|
||||||
solc_optimizer_enabled: bool,
|
solc_optimizer_enabled: bool,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
@@ -126,7 +117,7 @@ pub fn standard_output<T: Compiler>(
|
|||||||
allow_paths: Option<String>,
|
allow_paths: Option<String>,
|
||||||
remappings: Option<BTreeSet<String>>,
|
remappings: Option<BTreeSet<String>>,
|
||||||
suppressed_warnings: Option<Vec<Warning>>,
|
suppressed_warnings: Option<Vec<Warning>>,
|
||||||
debug_config: revive_llvm_context::DebugConfig,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<Build> {
|
) -> anyhow::Result<Build> {
|
||||||
let solc_version = solc.version()?;
|
let solc_version = solc.version()?;
|
||||||
let solc_pipeline = SolcPipeline::new(&solc_version, force_evmla);
|
let solc_pipeline = SolcPipeline::new(&solc_version, force_evmla);
|
||||||
@@ -185,7 +176,7 @@ pub fn standard_output<T: Compiler>(
|
|||||||
libraries,
|
libraries,
|
||||||
solc_pipeline,
|
solc_pipeline,
|
||||||
&solc_version,
|
&solc_version,
|
||||||
&debug_config,
|
debug_config.as_ref(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
||||||
@@ -195,17 +186,18 @@ pub fn standard_output<T: Compiler>(
|
|||||||
|
|
||||||
/// Runs the standard JSON mode.
|
/// Runs the standard JSON mode.
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn standard_json<T: Compiler>(
|
pub fn standard_json(
|
||||||
solc: &mut T,
|
solc: &mut SolcCompiler,
|
||||||
detect_missing_libraries: bool,
|
detect_missing_libraries: bool,
|
||||||
force_evmla: bool,
|
force_evmla: bool,
|
||||||
base_path: Option<String>,
|
base_path: Option<String>,
|
||||||
include_paths: Vec<String>,
|
include_paths: Vec<String>,
|
||||||
allow_paths: Option<String>,
|
allow_paths: Option<String>,
|
||||||
debug_config: revive_llvm_context::DebugConfig,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let solc_version = solc.version()?;
|
let solc_version = solc.version()?;
|
||||||
let solc_pipeline = SolcPipeline::new(&solc_version, force_evmla);
|
let solc_pipeline = SolcPipeline::new(&solc_version, force_evmla);
|
||||||
|
let resolc_version = semver::Version::parse(env!("CARGO_PKG_VERSION")).expect("Always valid");
|
||||||
|
|
||||||
let solc_input = SolcStandardJsonInput::try_from_stdin(solc_pipeline)?;
|
let solc_input = SolcStandardJsonInput::try_from_stdin(solc_pipeline)?;
|
||||||
let source_code_files = solc_input
|
let source_code_files = solc_input
|
||||||
@@ -247,15 +239,19 @@ pub fn standard_json<T: Compiler>(
|
|||||||
libraries,
|
libraries,
|
||||||
solc_pipeline,
|
solc_pipeline,
|
||||||
&solc_version,
|
&solc_version,
|
||||||
&debug_config,
|
debug_config.as_ref(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if detect_missing_libraries {
|
if detect_missing_libraries {
|
||||||
let missing_libraries = project.get_missing_libraries();
|
let missing_libraries = project.get_missing_libraries();
|
||||||
missing_libraries.write_to_standard_json(&mut solc_output, &solc_version)?;
|
missing_libraries.write_to_standard_json(
|
||||||
|
&mut solc_output,
|
||||||
|
&solc_version,
|
||||||
|
&resolc_version,
|
||||||
|
)?;
|
||||||
} else {
|
} else {
|
||||||
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
let build = project.compile(optimizer_settings, include_metadata_hash, debug_config)?;
|
||||||
build.write_to_standard_json(&mut solc_output, &solc_version)?;
|
build.write_to_standard_json(&mut solc_output, &solc_version, &resolc_version)?;
|
||||||
}
|
}
|
||||||
serde_json::to_writer(std::io::stdout(), &solc_output)?;
|
serde_json::to_writer(std::io::stdout(), &solc_output)?;
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
@@ -263,11 +259,11 @@ pub fn standard_json<T: Compiler>(
|
|||||||
|
|
||||||
/// Runs the combined JSON mode.
|
/// Runs the combined JSON mode.
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn combined_json<T: Compiler>(
|
pub fn combined_json(
|
||||||
format: String,
|
format: String,
|
||||||
input_files: &[PathBuf],
|
input_files: &[PathBuf],
|
||||||
libraries: Vec<String>,
|
libraries: Vec<String>,
|
||||||
solc: &mut T,
|
solc: &mut SolcCompiler,
|
||||||
evm_version: Option<revive_common::EVMVersion>,
|
evm_version: Option<revive_common::EVMVersion>,
|
||||||
solc_optimizer_enabled: bool,
|
solc_optimizer_enabled: bool,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
@@ -278,10 +274,12 @@ pub fn combined_json<T: Compiler>(
|
|||||||
allow_paths: Option<String>,
|
allow_paths: Option<String>,
|
||||||
remappings: Option<BTreeSet<String>>,
|
remappings: Option<BTreeSet<String>>,
|
||||||
suppressed_warnings: Option<Vec<Warning>>,
|
suppressed_warnings: Option<Vec<Warning>>,
|
||||||
debug_config: revive_llvm_context::DebugConfig,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
output_directory: Option<PathBuf>,
|
output_directory: Option<PathBuf>,
|
||||||
overwrite: bool,
|
overwrite: bool,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
|
let resolc_version = semver::Version::parse(env!("CARGO_PKG_VERSION")).expect("Always valid");
|
||||||
|
|
||||||
let build = standard_output(
|
let build = standard_output(
|
||||||
input_files,
|
input_files,
|
||||||
libraries,
|
libraries,
|
||||||
@@ -300,7 +298,7 @@ pub fn combined_json<T: Compiler>(
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
let mut combined_json = solc.combined_json(input_files, format.as_str())?;
|
let mut combined_json = solc.combined_json(input_files, format.as_str())?;
|
||||||
build.write_to_combined_json(&mut combined_json)?;
|
build.write_to_combined_json(&mut combined_json, &resolc_version)?;
|
||||||
|
|
||||||
match output_directory {
|
match output_directory {
|
||||||
Some(output_directory) => {
|
Some(output_directory) => {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ use std::collections::HashSet;
|
|||||||
|
|
||||||
use crate::solc::standard_json::output::Output as StandardJsonOutput;
|
use crate::solc::standard_json::output::Output as StandardJsonOutput;
|
||||||
use crate::solc::version::Version as SolcVersion;
|
use crate::solc::version::Version as SolcVersion;
|
||||||
use crate::ResolcVersion;
|
|
||||||
|
|
||||||
/// The missing Solidity libraries.
|
/// The missing Solidity libraries.
|
||||||
pub struct MissingLibraries {
|
pub struct MissingLibraries {
|
||||||
@@ -24,6 +23,7 @@ impl MissingLibraries {
|
|||||||
mut self,
|
mut self,
|
||||||
standard_json: &mut StandardJsonOutput,
|
standard_json: &mut StandardJsonOutput,
|
||||||
solc_version: &SolcVersion,
|
solc_version: &SolcVersion,
|
||||||
|
resolc_version: &semver::Version,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let contracts = match standard_json.contracts.as_mut() {
|
let contracts = match standard_json.contracts.as_mut() {
|
||||||
Some(contracts) => contracts,
|
Some(contracts) => contracts,
|
||||||
@@ -43,7 +43,7 @@ impl MissingLibraries {
|
|||||||
|
|
||||||
standard_json.version = Some(solc_version.default.to_string());
|
standard_json.version = Some(solc_version.default.to_string());
|
||||||
standard_json.long_version = Some(solc_version.long.to_owned());
|
standard_json.long_version = Some(solc_version.long.to_owned());
|
||||||
standard_json.revive_version = Some(ResolcVersion::default().long);
|
standard_json.zk_version = Some(resolc_version.to_string());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ pub struct Input {
|
|||||||
/// The optimizer settings.
|
/// The optimizer settings.
|
||||||
pub optimizer_settings: revive_llvm_context::OptimizerSettings,
|
pub optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
/// The debug output config.
|
/// The debug output config.
|
||||||
pub debug_config: revive_llvm_context::DebugConfig,
|
pub debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Input {
|
impl Input {
|
||||||
@@ -29,7 +29,7 @@ impl Input {
|
|||||||
project: Project,
|
project: Project,
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
debug_config: revive_llvm_context::DebugConfig,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
contract,
|
contract,
|
||||||
|
|||||||
@@ -1,68 +1,125 @@
|
|||||||
//! Process for compiling a single compilation unit.
|
//! Process for compiling a single compilation unit.
|
||||||
|
|
||||||
pub mod input;
|
pub mod input;
|
||||||
#[cfg(not(target_os = "emscripten"))]
|
|
||||||
pub mod native_process;
|
|
||||||
pub mod output;
|
pub mod output;
|
||||||
#[cfg(target_os = "emscripten")]
|
|
||||||
pub mod worker_process;
|
|
||||||
|
|
||||||
use std::io::{Read, Write};
|
use std::io::Read;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
|
|
||||||
use self::input::Input;
|
use self::input::Input;
|
||||||
use self::output::Output;
|
use self::output::Output;
|
||||||
|
|
||||||
pub trait Process {
|
/// The overriden executable name used when the compiler is run as a library.
|
||||||
/// Read input from `stdin`, compile a contract, and write the output to `stdout`.
|
pub static EXECUTABLE: OnceCell<PathBuf> = OnceCell::new();
|
||||||
fn run(input_file: Option<&mut std::fs::File>) -> anyhow::Result<()> {
|
|
||||||
let mut stdin = std::io::stdin();
|
|
||||||
let mut stdout = std::io::stdout();
|
|
||||||
let mut stderr = std::io::stderr();
|
|
||||||
|
|
||||||
let mut buffer = Vec::with_capacity(16384);
|
/// Read input from `stdin`, compile a contract, and write the output to `stdout`.
|
||||||
match input_file {
|
pub fn run(input_file: Option<&mut std::fs::File>) -> anyhow::Result<()> {
|
||||||
Some(ins) => {
|
let mut stdin = std::io::stdin();
|
||||||
if let Err(error) = ins.read_to_end(&mut buffer) {
|
let mut stdout = std::io::stdout();
|
||||||
anyhow::bail!("Failed to read recursive process input file: {:?}", error);
|
let mut stderr = std::io::stderr();
|
||||||
}
|
|
||||||
}
|
let mut buffer = Vec::with_capacity(16384);
|
||||||
None => {
|
match input_file {
|
||||||
if let Err(error) = stdin.read_to_end(&mut buffer) {
|
Some(ins) => {
|
||||||
anyhow::bail!(
|
if let Err(error) = ins.read_to_end(&mut buffer) {
|
||||||
"Failed to read recursive process input from stdin: {:?}",
|
anyhow::bail!("Failed to read recursive process input file: {:?}", error);
|
||||||
error
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
None => {
|
||||||
let input: Input = revive_common::deserialize_from_slice(buffer.as_slice())?;
|
if let Err(error) = stdin.read_to_end(&mut buffer) {
|
||||||
let result = input.contract.compile(
|
anyhow::bail!(
|
||||||
input.project,
|
"Failed to read recursive process input from stdin: {:?}",
|
||||||
input.optimizer_settings,
|
error
|
||||||
input.include_metadata_hash,
|
)
|
||||||
input.debug_config,
|
|
||||||
);
|
|
||||||
|
|
||||||
match result {
|
|
||||||
Ok(build) => {
|
|
||||||
let output = Output::new(build);
|
|
||||||
let json = serde_json::to_vec(&output).expect("Always valid");
|
|
||||||
stdout
|
|
||||||
.write_all(json.as_slice())
|
|
||||||
.expect("Stdout writing error");
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
Err(error) => {
|
|
||||||
let message = error.to_string();
|
|
||||||
stderr
|
|
||||||
.write_all(message.as_bytes())
|
|
||||||
.expect("Stderr writing error");
|
|
||||||
Err(error)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs this process recursively to compile a single contract.
|
let input: Input = revive_common::deserialize_from_slice(buffer.as_slice())?;
|
||||||
fn call(input: Input) -> anyhow::Result<Output>;
|
let result = input.contract.compile(
|
||||||
|
input.project,
|
||||||
|
input.optimizer_settings,
|
||||||
|
input.include_metadata_hash,
|
||||||
|
input.debug_config,
|
||||||
|
);
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Ok(build) => {
|
||||||
|
let output = Output::new(build);
|
||||||
|
let json = serde_json::to_vec(&output).expect("Always valid");
|
||||||
|
stdout
|
||||||
|
.write_all(json.as_slice())
|
||||||
|
.expect("Stdout writing error");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Err(error) => {
|
||||||
|
let message = error.to_string();
|
||||||
|
stderr
|
||||||
|
.write_all(message.as_bytes())
|
||||||
|
.expect("Stderr writing error");
|
||||||
|
Err(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Runs this process recursively to compile a single contract.
|
||||||
|
pub fn call(input: Input) -> anyhow::Result<Output> {
|
||||||
|
let input_json = serde_json::to_vec(&input).expect("Always valid");
|
||||||
|
|
||||||
|
let executable = match EXECUTABLE.get() {
|
||||||
|
Some(executable) => executable.to_owned(),
|
||||||
|
None => std::env::current_exe()?,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut command = Command::new(executable.as_path());
|
||||||
|
command.stdin(std::process::Stdio::piped());
|
||||||
|
command.stdout(std::process::Stdio::piped());
|
||||||
|
command.stderr(std::process::Stdio::piped());
|
||||||
|
command.arg("--recursive-process");
|
||||||
|
let process = command.spawn().map_err(|error| {
|
||||||
|
anyhow::anyhow!("{:?} subprocess spawning error: {:?}", executable, error)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
if let Some(dbg_config) = &input.debug_config {
|
||||||
|
dbg_config
|
||||||
|
.dump_stage_output(&input.contract.path, Some("stage"), &input_json)
|
||||||
|
.map_err(|error| {
|
||||||
|
anyhow::anyhow!(
|
||||||
|
"{:?} failed to log the recursive process output: {:?}",
|
||||||
|
executable,
|
||||||
|
error,
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
|
||||||
|
process
|
||||||
|
.stdin
|
||||||
|
.as_ref()
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("{:?} stdin getting error", executable))?
|
||||||
|
.write_all(input_json.as_slice())
|
||||||
|
.map_err(|error| anyhow::anyhow!("{:?} stdin writing error: {:?}", executable, error))?;
|
||||||
|
let output = process.wait_with_output().map_err(|error| {
|
||||||
|
anyhow::anyhow!("{:?} subprocess output error: {:?}", executable, error)
|
||||||
|
})?;
|
||||||
|
if !output.status.success() {
|
||||||
|
anyhow::bail!(
|
||||||
|
"{}",
|
||||||
|
String::from_utf8_lossy(output.stderr.as_slice()).to_string(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let output: Output =
|
||||||
|
revive_common::deserialize_from_slice(output.stdout.as_slice()).map_err(|error| {
|
||||||
|
anyhow::anyhow!(
|
||||||
|
"{:?} subprocess output parsing error: {}",
|
||||||
|
executable,
|
||||||
|
error,
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
Ok(output)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,76 +0,0 @@
|
|||||||
//! Process for compiling a single compilation unit.
|
|
||||||
|
|
||||||
use std::io::Write;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::process::Command;
|
|
||||||
|
|
||||||
use once_cell::sync::OnceCell;
|
|
||||||
|
|
||||||
use super::Input;
|
|
||||||
use super::Output;
|
|
||||||
use super::Process;
|
|
||||||
|
|
||||||
/// The overriden executable name used when the compiler is run as a library.
|
|
||||||
pub static EXECUTABLE: OnceCell<PathBuf> = OnceCell::new();
|
|
||||||
|
|
||||||
pub struct NativeProcess;
|
|
||||||
|
|
||||||
impl Process for NativeProcess {
|
|
||||||
fn call(input: Input) -> anyhow::Result<Output> {
|
|
||||||
let input_json = serde_json::to_vec(&input).expect("Always valid");
|
|
||||||
|
|
||||||
let executable = match EXECUTABLE.get() {
|
|
||||||
Some(executable) => executable.to_owned(),
|
|
||||||
None => std::env::current_exe()?,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut command = Command::new(executable.as_path());
|
|
||||||
command.stdin(std::process::Stdio::piped());
|
|
||||||
command.stdout(std::process::Stdio::piped());
|
|
||||||
command.stderr(std::process::Stdio::piped());
|
|
||||||
command.arg("--recursive-process");
|
|
||||||
let process = command.spawn().map_err(|error| {
|
|
||||||
anyhow::anyhow!("{:?} subprocess spawning error: {:?}", executable, error)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
input
|
|
||||||
.debug_config
|
|
||||||
.dump_stage_output(&input.contract.path, Some("stage"), &input_json)
|
|
||||||
.map_err(|error| {
|
|
||||||
anyhow::anyhow!(
|
|
||||||
"{:?} failed to log the recursive process output: {:?}",
|
|
||||||
executable,
|
|
||||||
error,
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
process
|
|
||||||
.stdin
|
|
||||||
.as_ref()
|
|
||||||
.ok_or_else(|| anyhow::anyhow!("{:?} stdin getting error", executable))?
|
|
||||||
.write_all(input_json.as_slice())
|
|
||||||
.map_err(|error| {
|
|
||||||
anyhow::anyhow!("{:?} stdin writing error: {:?}", executable, error)
|
|
||||||
})?;
|
|
||||||
let output = process.wait_with_output().map_err(|error| {
|
|
||||||
anyhow::anyhow!("{:?} subprocess output error: {:?}", executable, error)
|
|
||||||
})?;
|
|
||||||
if !output.status.success() {
|
|
||||||
anyhow::bail!(
|
|
||||||
"{}",
|
|
||||||
String::from_utf8_lossy(output.stderr.as_slice()).to_string(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let output: Output = revive_common::deserialize_from_slice(output.stdout.as_slice())
|
|
||||||
.map_err(|error| {
|
|
||||||
anyhow::anyhow!(
|
|
||||||
"{:?} subprocess output parsing error: {}",
|
|
||||||
executable,
|
|
||||||
error,
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
Ok(output)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
//! Process for compiling a single compilation unit using Web Workers.
|
|
||||||
|
|
||||||
use std::ffi::{c_char, c_void, CStr, CString};
|
|
||||||
|
|
||||||
use super::Input;
|
|
||||||
use super::Output;
|
|
||||||
use super::Process;
|
|
||||||
|
|
||||||
use anyhow::Context;
|
|
||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
struct Error {
|
|
||||||
message: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
struct Success {
|
|
||||||
data: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
#[serde(tag = "type", rename_all = "snake_case")]
|
|
||||||
enum Response {
|
|
||||||
Success(Success),
|
|
||||||
Error(Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct WorkerProcess;
|
|
||||||
|
|
||||||
impl Process for WorkerProcess {
|
|
||||||
fn call(input: Input) -> anyhow::Result<Output> {
|
|
||||||
let input_json = serde_json::to_vec(&input).expect("Always valid");
|
|
||||||
let input_str = String::from_utf8(input_json).expect("Input shall be valid");
|
|
||||||
// Prepare the input string for the Emscripten function
|
|
||||||
let input_cstring = CString::new(input_str).expect("CString allocation failed");
|
|
||||||
|
|
||||||
// Call the Emscripten function
|
|
||||||
let output_ptr =
|
|
||||||
unsafe { resolc_compile(input_cstring.as_ptr(), input_cstring.as_bytes().len()) };
|
|
||||||
|
|
||||||
// Convert the output pointer back to a Rust string
|
|
||||||
let output_str = unsafe {
|
|
||||||
CStr::from_ptr(output_ptr)
|
|
||||||
.to_str()
|
|
||||||
.with_context(|| "Failed to convert C string to Rust string")
|
|
||||||
.map(str::to_owned)
|
|
||||||
};
|
|
||||||
unsafe { libc::free(output_ptr as *mut c_void) };
|
|
||||||
let output_str = output_str?;
|
|
||||||
let response: Response = serde_json::from_str(&output_str)
|
|
||||||
.map_err(|error| anyhow::anyhow!("Worker output parsing error: {}", error,))?;
|
|
||||||
match response {
|
|
||||||
Response::Success(out) => {
|
|
||||||
let output: Output = revive_common::deserialize_from_slice(out.data.as_bytes())
|
|
||||||
.map_err(|error| {
|
|
||||||
anyhow::anyhow!("resolc.js subprocess output parsing error: {}", error,)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
Ok(output)
|
|
||||||
}
|
|
||||||
Response::Error(err) => anyhow::bail!("Worker error: {}", err.message,),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
fn resolc_compile(input_ptr: *const c_char, input_len: usize) -> *const c_char;
|
|
||||||
}
|
|
||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::ResolcVersion;
|
|
||||||
|
|
||||||
/// The Solidity contract metadata.
|
/// The Solidity contract metadata.
|
||||||
/// Is used to append the metadata hash to the contract bytecode.
|
/// Is used to append the metadata hash to the contract bytecode.
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
@@ -11,11 +9,11 @@ pub struct Metadata {
|
|||||||
/// The `solc` metadata.
|
/// The `solc` metadata.
|
||||||
pub solc_metadata: serde_json::Value,
|
pub solc_metadata: serde_json::Value,
|
||||||
/// The `solc` version.
|
/// The `solc` version.
|
||||||
pub solc_version: String,
|
pub solc_version: semver::Version,
|
||||||
/// The pallet revive edition.
|
/// The zkVM `solc` edition.
|
||||||
pub revive_pallet_version: Option<semver::Version>,
|
pub solc_zkvm_edition: Option<semver::Version>,
|
||||||
/// The PolkaVM compiler version.
|
/// The PolkaVM compiler version.
|
||||||
pub revive_version: String,
|
pub zk_version: semver::Version,
|
||||||
/// The PolkaVM compiler optimizer settings.
|
/// The PolkaVM compiler optimizer settings.
|
||||||
pub optimizer_settings: revive_llvm_context::OptimizerSettings,
|
pub optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
}
|
}
|
||||||
@@ -24,15 +22,16 @@ impl Metadata {
|
|||||||
/// A shortcut constructor.
|
/// A shortcut constructor.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
solc_metadata: serde_json::Value,
|
solc_metadata: serde_json::Value,
|
||||||
solc_version: String,
|
solc_version: semver::Version,
|
||||||
revive_pallet_version: Option<semver::Version>,
|
solc_zkvm_edition: Option<semver::Version>,
|
||||||
|
zk_version: semver::Version,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
solc_metadata,
|
solc_metadata,
|
||||||
solc_version,
|
solc_version,
|
||||||
revive_pallet_version,
|
solc_zkvm_edition,
|
||||||
revive_version: ResolcVersion::default().long,
|
zk_version,
|
||||||
optimizer_settings,
|
optimizer_settings,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ impl Contract {
|
|||||||
project: Project,
|
project: Project,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: revive_llvm_context::DebugConfig,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<ContractBuild> {
|
) -> anyhow::Result<ContractBuild> {
|
||||||
let llvm = inkwell::context::Context::create();
|
let llvm = inkwell::context::Context::create();
|
||||||
let optimizer = revive_llvm_context::Optimizer::new(optimizer_settings);
|
let optimizer = revive_llvm_context::Optimizer::new(optimizer_settings);
|
||||||
@@ -89,8 +89,9 @@ impl Contract {
|
|||||||
|
|
||||||
let metadata = Metadata::new(
|
let metadata = Metadata::new(
|
||||||
self.metadata_json.take(),
|
self.metadata_json.take(),
|
||||||
version.long.clone(),
|
version.default.clone(),
|
||||||
version.l2_revision.clone(),
|
version.l2_revision.clone(),
|
||||||
|
semver::Version::parse(env!("CARGO_PKG_VERSION")).expect("Always valid"),
|
||||||
optimizer.settings().to_owned(),
|
optimizer.settings().to_owned(),
|
||||||
);
|
);
|
||||||
let metadata_json = serde_json::to_value(&metadata).expect("Always valid");
|
let metadata_json = serde_json::to_value(&metadata).expect("Always valid");
|
||||||
@@ -104,7 +105,6 @@ impl Contract {
|
|||||||
|
|
||||||
let module = match self.ir {
|
let module = match self.ir {
|
||||||
IR::LLVMIR(ref llvm_ir) => {
|
IR::LLVMIR(ref llvm_ir) => {
|
||||||
// Create the output module
|
|
||||||
let memory_buffer =
|
let memory_buffer =
|
||||||
inkwell::memory_buffer::MemoryBuffer::create_from_memory_range_copy(
|
inkwell::memory_buffer::MemoryBuffer::create_from_memory_range_copy(
|
||||||
llvm_ir.source.as_bytes(),
|
llvm_ir.source.as_bytes(),
|
||||||
@@ -115,7 +115,6 @@ impl Contract {
|
|||||||
}
|
}
|
||||||
_ => llvm.create_module(self.path.as_str()),
|
_ => llvm.create_module(self.path.as_str()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut context = revive_llvm_context::PolkaVMContext::new(
|
let mut context = revive_llvm_context::PolkaVMContext::new(
|
||||||
&llvm,
|
&llvm,
|
||||||
module,
|
module,
|
||||||
@@ -153,10 +152,6 @@ impl Contract {
|
|||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if let Some(debug_info) = context.debug_info() {
|
|
||||||
debug_info.finalize_module()
|
|
||||||
}
|
|
||||||
|
|
||||||
let build = context.build(self.path.as_str(), metadata_hash)?;
|
let build = context.build(self.path.as_str(), metadata_hash)?;
|
||||||
|
|
||||||
Ok(ContractBuild::new(
|
Ok(ContractBuild::new(
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ use std::collections::HashMap;
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
#[cfg(feature = "parallel")]
|
use rayon::iter::IntoParallelIterator;
|
||||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
use rayon::iter::ParallelIterator;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use sha3::Digest;
|
use sha3::Digest;
|
||||||
@@ -17,10 +17,9 @@ use crate::build::contract::Contract as ContractBuild;
|
|||||||
use crate::build::Build;
|
use crate::build::Build;
|
||||||
use crate::missing_libraries::MissingLibraries;
|
use crate::missing_libraries::MissingLibraries;
|
||||||
use crate::process::input::Input as ProcessInput;
|
use crate::process::input::Input as ProcessInput;
|
||||||
use crate::process::Process;
|
|
||||||
use crate::project::contract::ir::IR;
|
use crate::project::contract::ir::IR;
|
||||||
use crate::solc::version::Version as SolcVersion;
|
use crate::solc::version::Version as SolcVersion;
|
||||||
use crate::solc::Compiler;
|
use crate::solc::Compiler as SolcCompiler;
|
||||||
use crate::yul::lexer::Lexer;
|
use crate::yul::lexer::Lexer;
|
||||||
use crate::yul::parser::statement::object::Object;
|
use crate::yul::parser::statement::object::Object;
|
||||||
|
|
||||||
@@ -64,33 +63,21 @@ impl Project {
|
|||||||
self,
|
self,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: revive_llvm_context::DebugConfig,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<Build> {
|
) -> anyhow::Result<Build> {
|
||||||
let project = self.clone();
|
let project = self.clone();
|
||||||
#[cfg(feature = "parallel")]
|
let results: BTreeMap<String, anyhow::Result<ContractBuild>> = self
|
||||||
let iter = self.contracts.into_par_iter();
|
.contracts
|
||||||
#[cfg(not(feature = "parallel"))]
|
.into_par_iter()
|
||||||
let iter = self.contracts.into_iter();
|
|
||||||
|
|
||||||
let results: BTreeMap<String, anyhow::Result<ContractBuild>> = iter
|
|
||||||
.map(|(full_path, contract)| {
|
.map(|(full_path, contract)| {
|
||||||
let process_input = ProcessInput::new(
|
let process_output = crate::process::call(ProcessInput::new(
|
||||||
contract,
|
contract,
|
||||||
project.clone(),
|
project.clone(),
|
||||||
include_metadata_hash,
|
include_metadata_hash,
|
||||||
optimizer_settings.clone(),
|
optimizer_settings.clone(),
|
||||||
debug_config.clone(),
|
debug_config.clone(),
|
||||||
);
|
));
|
||||||
let process_output = {
|
|
||||||
#[cfg(target_os = "emscripten")]
|
|
||||||
{
|
|
||||||
crate::WorkerProcess::call(process_input)
|
|
||||||
}
|
|
||||||
#[cfg(not(target_os = "emscripten"))]
|
|
||||||
{
|
|
||||||
crate::NativeProcess::call(process_input)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
(full_path, process_output.map(|output| output.build))
|
(full_path, process_output.map(|output| output.build))
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
@@ -168,9 +155,9 @@ impl Project {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Parses the Yul source code file and returns the source data.
|
/// Parses the Yul source code file and returns the source data.
|
||||||
pub fn try_from_yul_path<T: Compiler>(
|
pub fn try_from_yul_path(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
solc_validator: Option<&T>,
|
solc_validator: Option<&SolcCompiler>,
|
||||||
) -> anyhow::Result<Self> {
|
) -> anyhow::Result<Self> {
|
||||||
let source_code = std::fs::read_to_string(path)
|
let source_code = std::fs::read_to_string(path)
|
||||||
.map_err(|error| anyhow::anyhow!("Yul file {:?} reading error: {}", path, error))?;
|
.map_err(|error| anyhow::anyhow!("Yul file {:?} reading error: {}", path, error))?;
|
||||||
@@ -179,16 +166,16 @@ impl Project {
|
|||||||
|
|
||||||
/// Parses the test Yul source code string and returns the source data.
|
/// Parses the test Yul source code string and returns the source data.
|
||||||
/// Only for integration testing purposes.
|
/// Only for integration testing purposes.
|
||||||
pub fn try_from_yul_string<T: Compiler>(
|
pub fn try_from_yul_string(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
source_code: &str,
|
source_code: &str,
|
||||||
solc_validator: Option<&T>,
|
solc_validator: Option<&SolcCompiler>,
|
||||||
) -> anyhow::Result<Self> {
|
) -> anyhow::Result<Self> {
|
||||||
if let Some(solc) = solc_validator {
|
if let Some(solc) = solc_validator {
|
||||||
solc.validate_yul(path)?;
|
solc.validate_yul(path)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let source_version = SolcVersion::new_simple(crate::solc::LAST_SUPPORTED_VERSION);
|
let source_version = SolcVersion::new_simple(SolcCompiler::LAST_SUPPORTED_VERSION);
|
||||||
let path = path.to_string_lossy().to_string();
|
let path = path.to_string_lossy().to_string();
|
||||||
let source_hash = sha3::Keccak256::digest(source_code.as_bytes()).into();
|
let source_hash = sha3::Keccak256::digest(source_code.as_bytes()).into();
|
||||||
|
|
||||||
@@ -251,7 +238,7 @@ impl revive_llvm_context::PolkaVMDependency for Project {
|
|||||||
identifier: &str,
|
identifier: &str,
|
||||||
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
optimizer_settings: revive_llvm_context::OptimizerSettings,
|
||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: revive_llvm_context::DebugConfig,
|
debug_config: Option<revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<String> {
|
) -> anyhow::Result<String> {
|
||||||
let contract_path = project.resolve_path(identifier)?;
|
let contract_path = project.resolve_path(identifier)?;
|
||||||
let contract = project
|
let contract = project
|
||||||
|
|||||||
@@ -138,11 +138,6 @@ pub struct Arguments {
|
|||||||
#[structopt(long = "suppress-warnings")]
|
#[structopt(long = "suppress-warnings")]
|
||||||
pub suppress_warnings: Option<Vec<String>>,
|
pub suppress_warnings: Option<Vec<String>>,
|
||||||
|
|
||||||
/// Generate source based debug information in the output code file. This only has an effect
|
|
||||||
/// with the LLVM-IR code generator and is ignored otherwise.
|
|
||||||
#[structopt(short = 'g')]
|
|
||||||
pub emit_source_debug_info: bool,
|
|
||||||
|
|
||||||
/// Dump all IRs to files in the specified directory.
|
/// Dump all IRs to files in the specified directory.
|
||||||
/// Only for testing and debugging.
|
/// Only for testing and debugging.
|
||||||
#[structopt(long = "debug-output-dir")]
|
#[structopt(long = "debug-output-dir")]
|
||||||
|
|||||||
@@ -4,11 +4,8 @@ pub mod arguments;
|
|||||||
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use revive_solidity::Process;
|
|
||||||
|
|
||||||
use self::arguments::Arguments;
|
use self::arguments::Arguments;
|
||||||
|
|
||||||
#[cfg(feature = "parallel")]
|
|
||||||
/// The rayon worker stack size.
|
/// The rayon worker stack size.
|
||||||
const RAYON_WORKER_STACK_SIZE: usize = 16 * 1024 * 1024;
|
const RAYON_WORKER_STACK_SIZE: usize = 16 * 1024 * 1024;
|
||||||
|
|
||||||
@@ -34,9 +31,10 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
if arguments.version {
|
if arguments.version {
|
||||||
println!(
|
println!(
|
||||||
"{} version {}",
|
"{} v{} (LLVM build {:?})",
|
||||||
env!("CARGO_PKG_DESCRIPTION"),
|
env!("CARGO_PKG_DESCRIPTION"),
|
||||||
revive_solidity::ResolcVersion::default().long
|
env!("CARGO_PKG_VERSION"),
|
||||||
|
inkwell::support::get_llvm_version()
|
||||||
);
|
);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -49,7 +47,6 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "parallel")]
|
|
||||||
rayon::ThreadPoolBuilder::new()
|
rayon::ThreadPoolBuilder::new()
|
||||||
.stack_size(RAYON_WORKER_STACK_SIZE)
|
.stack_size(RAYON_WORKER_STACK_SIZE)
|
||||||
.build_global()
|
.build_global()
|
||||||
@@ -61,34 +58,20 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
if let Some(fname) = arguments.recursive_process_input {
|
if let Some(fname) = arguments.recursive_process_input {
|
||||||
let mut infile = std::fs::File::open(fname)?;
|
let mut infile = std::fs::File::open(fname)?;
|
||||||
#[cfg(target_os = "emscripten")]
|
return revive_solidity::run_process(Some(&mut infile));
|
||||||
{
|
|
||||||
return revive_solidity::WorkerProcess::run(Some(&mut infile));
|
|
||||||
}
|
|
||||||
#[cfg(not(target_os = "emscripten"))]
|
|
||||||
{
|
|
||||||
return revive_solidity::NativeProcess::run(Some(&mut infile));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(target_os = "emscripten")]
|
|
||||||
{
|
|
||||||
return revive_solidity::WorkerProcess::run(None);
|
|
||||||
}
|
|
||||||
#[cfg(not(target_os = "emscripten"))]
|
|
||||||
{
|
|
||||||
return revive_solidity::NativeProcess::run(None);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return revive_solidity::run_process(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
let debug_config = match arguments.debug_output_directory {
|
let debug_config = match arguments.debug_output_directory {
|
||||||
Some(ref debug_output_directory) => {
|
Some(ref debug_output_directory) => {
|
||||||
std::fs::create_dir_all(debug_output_directory.as_path())?;
|
std::fs::create_dir_all(debug_output_directory.as_path())?;
|
||||||
revive_llvm_context::DebugConfig::new(
|
Some(revive_llvm_context::DebugConfig::new(
|
||||||
Some(debug_output_directory.to_owned()),
|
debug_output_directory.to_owned(),
|
||||||
arguments.emit_source_debug_info,
|
))
|
||||||
)
|
|
||||||
}
|
}
|
||||||
None => revive_llvm_context::DebugConfig::new(None, arguments.emit_source_debug_info),
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let (input_files, remappings) = arguments.split_input_files_and_remappings()?;
|
let (input_files, remappings) = arguments.split_input_files_and_remappings()?;
|
||||||
@@ -100,19 +83,11 @@ fn main_inner() -> anyhow::Result<()> {
|
|||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut solc = {
|
let mut solc = revive_solidity::SolcCompiler::new(
|
||||||
#[cfg(target_os = "emscripten")]
|
arguments
|
||||||
{
|
.solc
|
||||||
revive_solidity::SoljsonCompiler { version: None }
|
.unwrap_or_else(|| revive_solidity::SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned()),
|
||||||
}
|
)?;
|
||||||
|
|
||||||
#[cfg(not(target_os = "emscripten"))]
|
|
||||||
{
|
|
||||||
revive_solidity::SolcCompiler::new(arguments.solc.unwrap_or_else(|| {
|
|
||||||
revive_solidity::SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned()
|
|
||||||
}))?
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let evm_version = match arguments.evm_version {
|
let evm_version = match arguments.evm_version {
|
||||||
Some(evm_version) => Some(revive_common::EVMVersion::try_from(evm_version.as_str())?),
|
Some(evm_version) => Some(revive_common::EVMVersion::try_from(evm_version.as_str())?),
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ pub struct CombinedJson {
|
|||||||
pub version: String,
|
pub version: String,
|
||||||
/// The `resolc` compiler version.
|
/// The `resolc` compiler version.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub revive_version: Option<String>,
|
pub zk_version: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CombinedJson {
|
impl CombinedJson {
|
||||||
|
|||||||
+266
-24
@@ -2,13 +2,10 @@
|
|||||||
|
|
||||||
pub mod combined_json;
|
pub mod combined_json;
|
||||||
pub mod pipeline;
|
pub mod pipeline;
|
||||||
#[cfg(not(target_os = "emscripten"))]
|
|
||||||
pub mod solc_compiler;
|
|
||||||
#[cfg(target_os = "emscripten")]
|
|
||||||
pub mod soljson_compiler;
|
|
||||||
pub mod standard_json;
|
pub mod standard_json;
|
||||||
pub mod version;
|
pub mod version;
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
@@ -18,40 +15,285 @@ use self::standard_json::input::Input as StandardJsonInput;
|
|||||||
use self::standard_json::output::Output as StandardJsonOutput;
|
use self::standard_json::output::Output as StandardJsonOutput;
|
||||||
use self::version::Version;
|
use self::version::Version;
|
||||||
|
|
||||||
/// The first version of `solc` with the support of standard JSON interface.
|
|
||||||
pub const FIRST_SUPPORTED_VERSION: semver::Version = semver::Version::new(0, 4, 12);
|
|
||||||
|
|
||||||
/// The first version of `solc`, where Yul codegen is considered robust enough.
|
|
||||||
pub const FIRST_YUL_VERSION: semver::Version = semver::Version::new(0, 8, 0);
|
|
||||||
|
|
||||||
/// The first version of `solc`, where `--via-ir` codegen mode is supported.
|
|
||||||
pub const FIRST_VIA_IR_VERSION: semver::Version = semver::Version::new(0, 8, 13);
|
|
||||||
|
|
||||||
/// The last supported version of `solc`.
|
|
||||||
pub const LAST_SUPPORTED_VERSION: semver::Version = semver::Version::new(0, 8, 28);
|
|
||||||
|
|
||||||
/// The Solidity compiler.
|
/// The Solidity compiler.
|
||||||
pub trait Compiler {
|
pub struct Compiler {
|
||||||
|
/// The binary executable name.
|
||||||
|
pub executable: String,
|
||||||
|
/// The lazily-initialized compiler version.
|
||||||
|
pub version: Option<Version>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Compiler {
|
||||||
|
/// The default executable name.
|
||||||
|
pub const DEFAULT_EXECUTABLE_NAME: &'static str = "solc";
|
||||||
|
|
||||||
|
/// The first version of `solc` with the support of standard JSON interface.
|
||||||
|
pub const FIRST_SUPPORTED_VERSION: semver::Version = semver::Version::new(0, 4, 12);
|
||||||
|
|
||||||
|
/// The first version of `solc`, where Yul codegen is considered robust enough.
|
||||||
|
pub const FIRST_YUL_VERSION: semver::Version = semver::Version::new(0, 8, 0);
|
||||||
|
|
||||||
|
/// The first version of `solc`, where `--via-ir` codegen mode is supported.
|
||||||
|
pub const FIRST_VIA_IR_VERSION: semver::Version = semver::Version::new(0, 8, 13);
|
||||||
|
|
||||||
|
/// The last supported version of `solc`.
|
||||||
|
pub const LAST_SUPPORTED_VERSION: semver::Version = semver::Version::new(0, 8, 28);
|
||||||
|
|
||||||
|
/// A shortcut constructor.
|
||||||
|
/// Different tools may use different `executable` names. For example, the integration tester
|
||||||
|
/// uses `solc-<version>` format.
|
||||||
|
pub fn new(executable: String) -> anyhow::Result<Self> {
|
||||||
|
if let Err(error) = which::which(executable.as_str()) {
|
||||||
|
anyhow::bail!(
|
||||||
|
"The `{executable}` executable not found in ${{PATH}}: {}",
|
||||||
|
error
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Ok(Self {
|
||||||
|
executable,
|
||||||
|
version: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Compiles the Solidity `--standard-json` input into Yul IR.
|
/// Compiles the Solidity `--standard-json` input into Yul IR.
|
||||||
fn standard_json(
|
pub fn standard_json(
|
||||||
&mut self,
|
&mut self,
|
||||||
input: StandardJsonInput,
|
mut input: StandardJsonInput,
|
||||||
pipeline: Pipeline,
|
pipeline: Pipeline,
|
||||||
base_path: Option<String>,
|
base_path: Option<String>,
|
||||||
include_paths: Vec<String>,
|
include_paths: Vec<String>,
|
||||||
allow_paths: Option<String>,
|
allow_paths: Option<String>,
|
||||||
) -> anyhow::Result<StandardJsonOutput>;
|
) -> anyhow::Result<StandardJsonOutput> {
|
||||||
|
let version = self.version()?;
|
||||||
|
|
||||||
|
let mut command = std::process::Command::new(self.executable.as_str());
|
||||||
|
command.stdin(std::process::Stdio::piped());
|
||||||
|
command.stdout(std::process::Stdio::piped());
|
||||||
|
command.arg("--standard-json");
|
||||||
|
|
||||||
|
if let Some(base_path) = base_path {
|
||||||
|
command.arg("--base-path");
|
||||||
|
command.arg(base_path);
|
||||||
|
}
|
||||||
|
for include_path in include_paths.into_iter() {
|
||||||
|
command.arg("--include-path");
|
||||||
|
command.arg(include_path);
|
||||||
|
}
|
||||||
|
if let Some(allow_paths) = allow_paths {
|
||||||
|
command.arg("--allow-paths");
|
||||||
|
command.arg(allow_paths);
|
||||||
|
}
|
||||||
|
|
||||||
|
input.normalize(&version.default);
|
||||||
|
|
||||||
|
let suppressed_warnings = input.suppressed_warnings.take().unwrap_or_default();
|
||||||
|
|
||||||
|
let input_json = serde_json::to_vec(&input).expect("Always valid");
|
||||||
|
|
||||||
|
let process = command.spawn().map_err(|error| {
|
||||||
|
anyhow::anyhow!("{} subprocess spawning error: {:?}", self.executable, error)
|
||||||
|
})?;
|
||||||
|
process
|
||||||
|
.stdin
|
||||||
|
.as_ref()
|
||||||
|
.ok_or_else(|| anyhow::anyhow!("{} stdin getting error", self.executable))?
|
||||||
|
.write_all(input_json.as_slice())
|
||||||
|
.map_err(|error| {
|
||||||
|
anyhow::anyhow!("{} stdin writing error: {:?}", self.executable, error)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let output = process.wait_with_output().map_err(|error| {
|
||||||
|
anyhow::anyhow!("{} subprocess output error: {:?}", self.executable, error)
|
||||||
|
})?;
|
||||||
|
if !output.status.success() {
|
||||||
|
anyhow::bail!(
|
||||||
|
"{} error: {}",
|
||||||
|
self.executable,
|
||||||
|
String::from_utf8_lossy(output.stderr.as_slice()).to_string()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut output: StandardJsonOutput =
|
||||||
|
revive_common::deserialize_from_slice(output.stdout.as_slice()).map_err(|error| {
|
||||||
|
anyhow::anyhow!(
|
||||||
|
"{} subprocess output parsing error: {}\n{}",
|
||||||
|
self.executable,
|
||||||
|
error,
|
||||||
|
revive_common::deserialize_from_slice::<serde_json::Value>(
|
||||||
|
output.stdout.as_slice()
|
||||||
|
)
|
||||||
|
.map(|json| serde_json::to_string_pretty(&json).expect("Always valid"))
|
||||||
|
.unwrap_or_else(
|
||||||
|
|_| String::from_utf8_lossy(output.stdout.as_slice()).to_string()
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
output.preprocess_ast(&version, pipeline, suppressed_warnings.as_slice())?;
|
||||||
|
|
||||||
|
Ok(output)
|
||||||
|
}
|
||||||
|
|
||||||
/// The `solc --combined-json abi,hashes...` mirror.
|
/// The `solc --combined-json abi,hashes...` mirror.
|
||||||
fn combined_json(
|
pub fn combined_json(
|
||||||
&self,
|
&self,
|
||||||
paths: &[PathBuf],
|
paths: &[PathBuf],
|
||||||
combined_json_argument: &str,
|
combined_json_argument: &str,
|
||||||
) -> anyhow::Result<CombinedJson>;
|
) -> anyhow::Result<CombinedJson> {
|
||||||
|
let mut command = std::process::Command::new(self.executable.as_str());
|
||||||
|
command.args(paths);
|
||||||
|
|
||||||
|
let mut combined_json_flags = Vec::new();
|
||||||
|
let mut combined_json_fake_flag_pushed = false;
|
||||||
|
let mut filtered_flags = Vec::with_capacity(3);
|
||||||
|
for flag in combined_json_argument.split(',') {
|
||||||
|
match flag {
|
||||||
|
flag @ "asm" | flag @ "bin" | flag @ "bin-runtime" => filtered_flags.push(flag),
|
||||||
|
flag => combined_json_flags.push(flag),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if combined_json_flags.is_empty() {
|
||||||
|
combined_json_flags.push("ast");
|
||||||
|
combined_json_fake_flag_pushed = true;
|
||||||
|
}
|
||||||
|
command.arg("--combined-json");
|
||||||
|
command.arg(combined_json_flags.join(","));
|
||||||
|
|
||||||
|
let output = command.output().map_err(|error| {
|
||||||
|
anyhow::anyhow!("{} subprocess error: {:?}", self.executable, error)
|
||||||
|
})?;
|
||||||
|
if !output.status.success() {
|
||||||
|
println!("{}", String::from_utf8_lossy(output.stdout.as_slice()));
|
||||||
|
println!("{}", String::from_utf8_lossy(output.stderr.as_slice()));
|
||||||
|
anyhow::bail!(
|
||||||
|
"{} error: {}",
|
||||||
|
self.executable,
|
||||||
|
String::from_utf8_lossy(output.stdout.as_slice()).to_string()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut combined_json: CombinedJson =
|
||||||
|
revive_common::deserialize_from_slice(output.stdout.as_slice()).map_err(|error| {
|
||||||
|
anyhow::anyhow!(
|
||||||
|
"{} subprocess output parsing error: {}\n{}",
|
||||||
|
self.executable,
|
||||||
|
error,
|
||||||
|
revive_common::deserialize_from_slice::<serde_json::Value>(
|
||||||
|
output.stdout.as_slice()
|
||||||
|
)
|
||||||
|
.map(|json| serde_json::to_string_pretty(&json).expect("Always valid"))
|
||||||
|
.unwrap_or_else(
|
||||||
|
|_| String::from_utf8_lossy(output.stdout.as_slice()).to_string()
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
for filtered_flag in filtered_flags.into_iter() {
|
||||||
|
for (_path, contract) in combined_json.contracts.iter_mut() {
|
||||||
|
match filtered_flag {
|
||||||
|
"asm" => contract.asm = Some(serde_json::Value::Null),
|
||||||
|
"bin" => contract.bin = Some("".to_owned()),
|
||||||
|
"bin-runtime" => contract.bin_runtime = Some("".to_owned()),
|
||||||
|
_ => continue,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if combined_json_fake_flag_pushed {
|
||||||
|
combined_json.source_list = None;
|
||||||
|
combined_json.sources = None;
|
||||||
|
}
|
||||||
|
combined_json.remove_evm();
|
||||||
|
|
||||||
|
Ok(combined_json)
|
||||||
|
}
|
||||||
|
|
||||||
/// The `solc` Yul validator.
|
/// The `solc` Yul validator.
|
||||||
fn validate_yul(&self, path: &Path) -> anyhow::Result<()>;
|
pub fn validate_yul(&self, path: &Path) -> anyhow::Result<()> {
|
||||||
|
let mut command = std::process::Command::new(self.executable.as_str());
|
||||||
|
command.arg("--strict-assembly");
|
||||||
|
command.arg(path);
|
||||||
|
|
||||||
|
let output = command.output().map_err(|error| {
|
||||||
|
anyhow::anyhow!("{} subprocess error: {:?}", self.executable, error)
|
||||||
|
})?;
|
||||||
|
if !output.status.success() {
|
||||||
|
anyhow::bail!(
|
||||||
|
"{} error: {}",
|
||||||
|
self.executable,
|
||||||
|
String::from_utf8_lossy(output.stderr.as_slice()).to_string()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// The `solc --version` mini-parser.
|
/// The `solc --version` mini-parser.
|
||||||
fn version(&mut self) -> anyhow::Result<Version>;
|
pub fn version(&mut self) -> anyhow::Result<Version> {
|
||||||
|
if let Some(version) = self.version.as_ref() {
|
||||||
|
return Ok(version.to_owned());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut command = std::process::Command::new(self.executable.as_str());
|
||||||
|
command.arg("--version");
|
||||||
|
let output = command.output().map_err(|error| {
|
||||||
|
anyhow::anyhow!("{} subprocess error: {:?}", self.executable, error)
|
||||||
|
})?;
|
||||||
|
if !output.status.success() {
|
||||||
|
anyhow::bail!(
|
||||||
|
"{} error: {}",
|
||||||
|
self.executable,
|
||||||
|
String::from_utf8_lossy(output.stderr.as_slice()).to_string()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let stdout = String::from_utf8_lossy(output.stdout.as_slice());
|
||||||
|
let long = stdout
|
||||||
|
.lines()
|
||||||
|
.nth(1)
|
||||||
|
.ok_or_else(|| {
|
||||||
|
anyhow::anyhow!("{} version parsing: not enough lines", self.executable)
|
||||||
|
})?
|
||||||
|
.split(' ')
|
||||||
|
.nth(1)
|
||||||
|
.ok_or_else(|| {
|
||||||
|
anyhow::anyhow!(
|
||||||
|
"{} version parsing: not enough words in the 2nd line",
|
||||||
|
self.executable
|
||||||
|
)
|
||||||
|
})?
|
||||||
|
.to_owned();
|
||||||
|
let default: semver::Version = long
|
||||||
|
.split('+')
|
||||||
|
.next()
|
||||||
|
.ok_or_else(|| {
|
||||||
|
anyhow::anyhow!("{} version parsing: metadata dropping", self.executable)
|
||||||
|
})?
|
||||||
|
.parse()
|
||||||
|
.map_err(|error| anyhow::anyhow!("{} version parsing: {}", self.executable, error))?;
|
||||||
|
|
||||||
|
let l2_revision: Option<semver::Version> = stdout
|
||||||
|
.lines()
|
||||||
|
.nth(2)
|
||||||
|
.and_then(|line| line.split(' ').nth(1))
|
||||||
|
.and_then(|line| line.split('-').nth(1))
|
||||||
|
.and_then(|version| version.parse().ok());
|
||||||
|
|
||||||
|
let version = Version::new(long, default, l2_revision);
|
||||||
|
if version.default < Self::FIRST_SUPPORTED_VERSION {
|
||||||
|
anyhow::bail!(
|
||||||
|
"`solc` versions <{} are not supported, found {}",
|
||||||
|
Self::FIRST_SUPPORTED_VERSION,
|
||||||
|
version.default
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if version.default > Self::LAST_SUPPORTED_VERSION {
|
||||||
|
anyhow::bail!(
|
||||||
|
"`solc` versions >{} are not supported, found {}",
|
||||||
|
Self::LAST_SUPPORTED_VERSION,
|
||||||
|
version.default
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.version = Some(version.clone());
|
||||||
|
|
||||||
|
Ok(version)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::solc::version::Version as SolcVersion;
|
use crate::solc::version::Version as SolcVersion;
|
||||||
|
use crate::solc::Compiler as SolcCompiler;
|
||||||
|
|
||||||
/// The Solidity compiler pipeline type.
|
/// The Solidity compiler pipeline type.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||||
@@ -18,7 +19,7 @@ pub enum Pipeline {
|
|||||||
impl Pipeline {
|
impl Pipeline {
|
||||||
/// We always use EVMLA for Solidity <=0.7, or if the user does not want to compile via Yul.
|
/// We always use EVMLA for Solidity <=0.7, or if the user does not want to compile via Yul.
|
||||||
pub fn new(solc_version: &SolcVersion, force_evmla: bool) -> Self {
|
pub fn new(solc_version: &SolcVersion, force_evmla: bool) -> Self {
|
||||||
if solc_version.default < crate::solc::FIRST_YUL_VERSION || force_evmla {
|
if solc_version.default < SolcCompiler::FIRST_YUL_VERSION || force_evmla {
|
||||||
Self::EVMLA
|
Self::EVMLA
|
||||||
} else {
|
} else {
|
||||||
Self::Yul
|
Self::Yul
|
||||||
|
|||||||
@@ -1,286 +0,0 @@
|
|||||||
//! The Solidity compiler.
|
|
||||||
|
|
||||||
use std::io::Write;
|
|
||||||
use std::path::Path;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use crate::solc::combined_json::CombinedJson;
|
|
||||||
use crate::solc::pipeline::Pipeline;
|
|
||||||
use crate::solc::standard_json::input::Input as StandardJsonInput;
|
|
||||||
use crate::solc::standard_json::output::Output as StandardJsonOutput;
|
|
||||||
use crate::solc::version::Version;
|
|
||||||
|
|
||||||
use super::Compiler;
|
|
||||||
|
|
||||||
/// The Solidity compiler.
|
|
||||||
pub struct SolcCompiler {
|
|
||||||
/// The binary executable name.
|
|
||||||
pub executable: String,
|
|
||||||
/// The lazily-initialized compiler version.
|
|
||||||
pub version: Option<Version>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SolcCompiler {
|
|
||||||
/// The default executable name.
|
|
||||||
pub const DEFAULT_EXECUTABLE_NAME: &'static str = "solc";
|
|
||||||
|
|
||||||
/// A shortcut constructor.
|
|
||||||
/// Different tools may use different `executable` names. For example, the integration tester
|
|
||||||
/// uses `solc-<version>` format.
|
|
||||||
pub fn new(executable: String) -> anyhow::Result<Self> {
|
|
||||||
if let Err(error) = which::which(executable.as_str()) {
|
|
||||||
anyhow::bail!(
|
|
||||||
"The `{executable}` executable not found in ${{PATH}}: {}",
|
|
||||||
error
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Ok(Self {
|
|
||||||
executable,
|
|
||||||
version: None,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Compiler for SolcCompiler {
|
|
||||||
/// Compiles the Solidity `--standard-json` input into Yul IR.
|
|
||||||
fn standard_json(
|
|
||||||
&mut self,
|
|
||||||
mut input: StandardJsonInput,
|
|
||||||
pipeline: Pipeline,
|
|
||||||
base_path: Option<String>,
|
|
||||||
include_paths: Vec<String>,
|
|
||||||
allow_paths: Option<String>,
|
|
||||||
) -> anyhow::Result<StandardJsonOutput> {
|
|
||||||
let version = self.version()?;
|
|
||||||
|
|
||||||
let mut command = std::process::Command::new(self.executable.as_str());
|
|
||||||
command.stdin(std::process::Stdio::piped());
|
|
||||||
command.stdout(std::process::Stdio::piped());
|
|
||||||
command.arg("--standard-json");
|
|
||||||
|
|
||||||
if let Some(base_path) = base_path {
|
|
||||||
command.arg("--base-path");
|
|
||||||
command.arg(base_path);
|
|
||||||
}
|
|
||||||
for include_path in include_paths.into_iter() {
|
|
||||||
command.arg("--include-path");
|
|
||||||
command.arg(include_path);
|
|
||||||
}
|
|
||||||
if let Some(allow_paths) = allow_paths {
|
|
||||||
command.arg("--allow-paths");
|
|
||||||
command.arg(allow_paths);
|
|
||||||
}
|
|
||||||
|
|
||||||
input.normalize(&version.default);
|
|
||||||
|
|
||||||
let suppressed_warnings = input.suppressed_warnings.take().unwrap_or_default();
|
|
||||||
|
|
||||||
let input_json = serde_json::to_vec(&input).expect("Always valid");
|
|
||||||
|
|
||||||
let process = command.spawn().map_err(|error| {
|
|
||||||
anyhow::anyhow!("{} subprocess spawning error: {:?}", self.executable, error)
|
|
||||||
})?;
|
|
||||||
process
|
|
||||||
.stdin
|
|
||||||
.as_ref()
|
|
||||||
.ok_or_else(|| anyhow::anyhow!("{} stdin getting error", self.executable))?
|
|
||||||
.write_all(input_json.as_slice())
|
|
||||||
.map_err(|error| {
|
|
||||||
anyhow::anyhow!("{} stdin writing error: {:?}", self.executable, error)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let output = process.wait_with_output().map_err(|error| {
|
|
||||||
anyhow::anyhow!("{} subprocess output error: {:?}", self.executable, error)
|
|
||||||
})?;
|
|
||||||
if !output.status.success() {
|
|
||||||
anyhow::bail!(
|
|
||||||
"{} error: {}",
|
|
||||||
self.executable,
|
|
||||||
String::from_utf8_lossy(output.stderr.as_slice()).to_string()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut output: StandardJsonOutput =
|
|
||||||
revive_common::deserialize_from_slice(output.stdout.as_slice()).map_err(|error| {
|
|
||||||
anyhow::anyhow!(
|
|
||||||
"{} subprocess output parsing error: {}\n{}",
|
|
||||||
self.executable,
|
|
||||||
error,
|
|
||||||
revive_common::deserialize_from_slice::<serde_json::Value>(
|
|
||||||
output.stdout.as_slice()
|
|
||||||
)
|
|
||||||
.map(|json| serde_json::to_string_pretty(&json).expect("Always valid"))
|
|
||||||
.unwrap_or_else(
|
|
||||||
|_| String::from_utf8_lossy(output.stdout.as_slice()).to_string()
|
|
||||||
),
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
output.preprocess_ast(&version, pipeline, suppressed_warnings.as_slice())?;
|
|
||||||
|
|
||||||
Ok(output)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The `solc --combined-json abi,hashes...` mirror.
|
|
||||||
fn combined_json(
|
|
||||||
&self,
|
|
||||||
paths: &[PathBuf],
|
|
||||||
combined_json_argument: &str,
|
|
||||||
) -> anyhow::Result<CombinedJson> {
|
|
||||||
let mut command = std::process::Command::new(self.executable.as_str());
|
|
||||||
command.args(paths);
|
|
||||||
|
|
||||||
let mut combined_json_flags = Vec::new();
|
|
||||||
let mut combined_json_fake_flag_pushed = false;
|
|
||||||
let mut filtered_flags = Vec::with_capacity(3);
|
|
||||||
for flag in combined_json_argument.split(',') {
|
|
||||||
match flag {
|
|
||||||
flag @ "asm" | flag @ "bin" | flag @ "bin-runtime" => filtered_flags.push(flag),
|
|
||||||
flag => combined_json_flags.push(flag),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if combined_json_flags.is_empty() {
|
|
||||||
combined_json_flags.push("ast");
|
|
||||||
combined_json_fake_flag_pushed = true;
|
|
||||||
}
|
|
||||||
command.arg("--combined-json");
|
|
||||||
command.arg(combined_json_flags.join(","));
|
|
||||||
|
|
||||||
let output = command.output().map_err(|error| {
|
|
||||||
anyhow::anyhow!("{} subprocess error: {:?}", self.executable, error)
|
|
||||||
})?;
|
|
||||||
if !output.status.success() {
|
|
||||||
println!("{}", String::from_utf8_lossy(output.stdout.as_slice()));
|
|
||||||
println!("{}", String::from_utf8_lossy(output.stderr.as_slice()));
|
|
||||||
anyhow::bail!(
|
|
||||||
"{} error: {}",
|
|
||||||
self.executable,
|
|
||||||
String::from_utf8_lossy(output.stdout.as_slice()).to_string()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut combined_json: CombinedJson =
|
|
||||||
revive_common::deserialize_from_slice(output.stdout.as_slice()).map_err(|error| {
|
|
||||||
anyhow::anyhow!(
|
|
||||||
"{} subprocess output parsing error: {}\n{}",
|
|
||||||
self.executable,
|
|
||||||
error,
|
|
||||||
revive_common::deserialize_from_slice::<serde_json::Value>(
|
|
||||||
output.stdout.as_slice()
|
|
||||||
)
|
|
||||||
.map(|json| serde_json::to_string_pretty(&json).expect("Always valid"))
|
|
||||||
.unwrap_or_else(
|
|
||||||
|_| String::from_utf8_lossy(output.stdout.as_slice()).to_string()
|
|
||||||
),
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
for filtered_flag in filtered_flags.into_iter() {
|
|
||||||
for (_path, contract) in combined_json.contracts.iter_mut() {
|
|
||||||
match filtered_flag {
|
|
||||||
"asm" => contract.asm = Some(serde_json::Value::Null),
|
|
||||||
"bin" => contract.bin = Some("".to_owned()),
|
|
||||||
"bin-runtime" => contract.bin_runtime = Some("".to_owned()),
|
|
||||||
_ => continue,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if combined_json_fake_flag_pushed {
|
|
||||||
combined_json.source_list = None;
|
|
||||||
combined_json.sources = None;
|
|
||||||
}
|
|
||||||
combined_json.remove_evm();
|
|
||||||
|
|
||||||
Ok(combined_json)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The `solc` Yul validator.
|
|
||||||
fn validate_yul(&self, path: &Path) -> anyhow::Result<()> {
|
|
||||||
let mut command = std::process::Command::new(self.executable.as_str());
|
|
||||||
command.arg("--strict-assembly");
|
|
||||||
command.arg(path);
|
|
||||||
|
|
||||||
let output = command.output().map_err(|error| {
|
|
||||||
anyhow::anyhow!("{} subprocess error: {:?}", self.executable, error)
|
|
||||||
})?;
|
|
||||||
if !output.status.success() {
|
|
||||||
anyhow::bail!(
|
|
||||||
"{} error: {}",
|
|
||||||
self.executable,
|
|
||||||
String::from_utf8_lossy(output.stderr.as_slice()).to_string()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The `solc --version` mini-parser.
|
|
||||||
fn version(&mut self) -> anyhow::Result<Version> {
|
|
||||||
if let Some(version) = self.version.as_ref() {
|
|
||||||
return Ok(version.to_owned());
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut command = std::process::Command::new(self.executable.as_str());
|
|
||||||
command.arg("--version");
|
|
||||||
let output = command.output().map_err(|error| {
|
|
||||||
anyhow::anyhow!("{} subprocess error: {:?}", self.executable, error)
|
|
||||||
})?;
|
|
||||||
if !output.status.success() {
|
|
||||||
anyhow::bail!(
|
|
||||||
"{} error: {}",
|
|
||||||
self.executable,
|
|
||||||
String::from_utf8_lossy(output.stderr.as_slice()).to_string()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let stdout = String::from_utf8_lossy(output.stdout.as_slice());
|
|
||||||
let long = stdout
|
|
||||||
.lines()
|
|
||||||
.nth(1)
|
|
||||||
.ok_or_else(|| {
|
|
||||||
anyhow::anyhow!("{} version parsing: not enough lines", self.executable)
|
|
||||||
})?
|
|
||||||
.split(' ')
|
|
||||||
.nth(1)
|
|
||||||
.ok_or_else(|| {
|
|
||||||
anyhow::anyhow!(
|
|
||||||
"{} version parsing: not enough words in the 2nd line",
|
|
||||||
self.executable
|
|
||||||
)
|
|
||||||
})?
|
|
||||||
.to_owned();
|
|
||||||
let default: semver::Version = long
|
|
||||||
.split('+')
|
|
||||||
.next()
|
|
||||||
.ok_or_else(|| {
|
|
||||||
anyhow::anyhow!("{} version parsing: metadata dropping", self.executable)
|
|
||||||
})?
|
|
||||||
.parse()
|
|
||||||
.map_err(|error| anyhow::anyhow!("{} version parsing: {}", self.executable, error))?;
|
|
||||||
|
|
||||||
let l2_revision: Option<semver::Version> = stdout
|
|
||||||
.lines()
|
|
||||||
.nth(2)
|
|
||||||
.and_then(|line| line.split(' ').nth(1))
|
|
||||||
.and_then(|line| line.split('-').nth(1))
|
|
||||||
.and_then(|version| version.parse().ok());
|
|
||||||
|
|
||||||
let version = Version::new(long, default, l2_revision);
|
|
||||||
if version.default < super::FIRST_SUPPORTED_VERSION {
|
|
||||||
anyhow::bail!(
|
|
||||||
"`solc` versions <{} are not supported, found {}",
|
|
||||||
super::FIRST_SUPPORTED_VERSION,
|
|
||||||
version.default
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if version.default > super::LAST_SUPPORTED_VERSION {
|
|
||||||
anyhow::bail!(
|
|
||||||
"`solc` versions >{} are not supported, found {}",
|
|
||||||
super::LAST_SUPPORTED_VERSION,
|
|
||||||
version.default
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.version = Some(version.clone());
|
|
||||||
|
|
||||||
Ok(version)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
//! The Solidity compiler.
|
|
||||||
|
|
||||||
use std::path::Path;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use crate::solc::combined_json::CombinedJson;
|
|
||||||
use crate::solc::pipeline::Pipeline;
|
|
||||||
use crate::solc::standard_json::input::Input as StandardJsonInput;
|
|
||||||
use crate::solc::standard_json::output::Output as StandardJsonOutput;
|
|
||||||
use crate::solc::version::Version;
|
|
||||||
use anyhow::Context;
|
|
||||||
use std::ffi::{c_char, c_void, CStr, CString};
|
|
||||||
|
|
||||||
use super::Compiler;
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
fn soljson_version() -> *const c_char;
|
|
||||||
fn soljson_compile(inputPtr: *const c_char, inputLen: usize) -> *const c_char;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The Solidity compiler.
|
|
||||||
pub struct SoljsonCompiler {
|
|
||||||
/// The lazily-initialized compiler version.
|
|
||||||
pub version: Option<Version>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Compiler for SoljsonCompiler {
|
|
||||||
/// Compiles the Solidity `--standard-json` input into Yul IR.
|
|
||||||
fn standard_json(
|
|
||||||
&mut self,
|
|
||||||
mut input: StandardJsonInput,
|
|
||||||
pipeline: Pipeline,
|
|
||||||
_base_path: Option<String>,
|
|
||||||
_include_paths: Vec<String>,
|
|
||||||
_allow_paths: Option<String>,
|
|
||||||
) -> anyhow::Result<StandardJsonOutput> {
|
|
||||||
let version = self.version()?;
|
|
||||||
let suppressed_warnings = input.suppressed_warnings.take().unwrap_or_default();
|
|
||||||
|
|
||||||
let input_json = serde_json::to_string(&input).expect("Always valid");
|
|
||||||
let out = Self::compile_standard_json(input_json)?;
|
|
||||||
let mut output: StandardJsonOutput = revive_common::deserialize_from_slice(out.as_bytes())
|
|
||||||
.map_err(|error| {
|
|
||||||
anyhow::anyhow!(
|
|
||||||
"Soljson output parsing error: {}\n{}",
|
|
||||||
error,
|
|
||||||
revive_common::deserialize_from_slice::<serde_json::Value>(out.as_bytes())
|
|
||||||
.map(|json| serde_json::to_string_pretty(&json).expect("Always valid"))
|
|
||||||
.unwrap_or_else(|_| String::from_utf8_lossy(out.as_bytes()).to_string()),
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
output.preprocess_ast(&version, pipeline, suppressed_warnings.as_slice())?;
|
|
||||||
|
|
||||||
Ok(output)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn combined_json(
|
|
||||||
&self,
|
|
||||||
_paths: &[PathBuf],
|
|
||||||
_combined_json_argument: &str,
|
|
||||||
) -> anyhow::Result<CombinedJson> {
|
|
||||||
unimplemented!();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn validate_yul(&self, _path: &Path) -> anyhow::Result<()> {
|
|
||||||
unimplemented!();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn version(&mut self) -> anyhow::Result<Version> {
|
|
||||||
let version = Self::get_soljson_version()?;
|
|
||||||
let long = version.clone();
|
|
||||||
let default: semver::Version = version
|
|
||||||
.split('+')
|
|
||||||
.next()
|
|
||||||
.ok_or_else(|| anyhow::anyhow!("Soljson version parsing: metadata dropping"))?
|
|
||||||
.parse()
|
|
||||||
.map_err(|error| anyhow::anyhow!("Soljson version parsing: {}", error))?;
|
|
||||||
|
|
||||||
let l2_revision: Option<semver::Version> = version
|
|
||||||
.split('-')
|
|
||||||
.nth(1)
|
|
||||||
.and_then(|version| version.parse().ok());
|
|
||||||
|
|
||||||
let version = Version::new(long, default, l2_revision);
|
|
||||||
if version.default < super::FIRST_SUPPORTED_VERSION {
|
|
||||||
anyhow::bail!(
|
|
||||||
"`Soljson` versions <{} are not supported, found {}",
|
|
||||||
super::FIRST_SUPPORTED_VERSION,
|
|
||||||
version.default
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if version.default > super::LAST_SUPPORTED_VERSION {
|
|
||||||
anyhow::bail!(
|
|
||||||
"`Soljson` versions >{} are not supported, found {}",
|
|
||||||
super::LAST_SUPPORTED_VERSION,
|
|
||||||
version.default
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.version = Some(version.clone());
|
|
||||||
|
|
||||||
Ok(version)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SoljsonCompiler {
|
|
||||||
fn get_soljson_version() -> anyhow::Result<String> {
|
|
||||||
unsafe {
|
|
||||||
let version_ptr = soljson_version();
|
|
||||||
let version = CStr::from_ptr(version_ptr)
|
|
||||||
.to_str()
|
|
||||||
.with_context(|| "Failed to convert C string to Rust string")
|
|
||||||
.map(str::to_owned);
|
|
||||||
libc::free(version_ptr as *mut c_void);
|
|
||||||
Ok(version?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn compile_standard_json(input: String) -> anyhow::Result<String> {
|
|
||||||
let c_input = CString::new(input).unwrap();
|
|
||||||
let c_input_len = c_input.as_bytes().len();
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
let output_ptr = soljson_compile(c_input.as_ptr(), c_input_len);
|
|
||||||
let output_json = CStr::from_ptr(output_ptr)
|
|
||||||
.to_str()
|
|
||||||
.with_context(|| "Failed to convert C string to Rust string")
|
|
||||||
.map(str::to_owned);
|
|
||||||
libc::free(output_ptr as *mut c_void);
|
|
||||||
Ok(output_json?)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,8 +8,8 @@ use std::collections::BTreeMap;
|
|||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[cfg(feature = "parallel")]
|
use rayon::iter::IntoParallelIterator;
|
||||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
use rayon::iter::ParallelIterator;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
@@ -64,12 +64,8 @@ impl Input {
|
|||||||
via_ir: bool,
|
via_ir: bool,
|
||||||
suppressed_warnings: Option<Vec<Warning>>,
|
suppressed_warnings: Option<Vec<Warning>>,
|
||||||
) -> anyhow::Result<Self> {
|
) -> anyhow::Result<Self> {
|
||||||
#[cfg(feature = "parallel")]
|
let sources = paths
|
||||||
let iter = paths.into_par_iter(); // Parallel iterator
|
.into_par_iter()
|
||||||
|
|
||||||
#[cfg(not(feature = "parallel"))]
|
|
||||||
let iter = paths.iter(); // Sequential iterator
|
|
||||||
let sources = iter
|
|
||||||
.map(|path| {
|
.map(|path| {
|
||||||
let source = Source::try_from(path.as_path()).unwrap_or_else(|error| {
|
let source = Source::try_from(path.as_path()).unwrap_or_else(|error| {
|
||||||
panic!("Source code file {path:?} reading error: {error}")
|
panic!("Source code file {path:?} reading error: {error}")
|
||||||
@@ -110,12 +106,8 @@ impl Input {
|
|||||||
via_ir: bool,
|
via_ir: bool,
|
||||||
suppressed_warnings: Option<Vec<Warning>>,
|
suppressed_warnings: Option<Vec<Warning>>,
|
||||||
) -> anyhow::Result<Self> {
|
) -> anyhow::Result<Self> {
|
||||||
#[cfg(feature = "parallel")]
|
let sources = sources
|
||||||
let iter = sources.into_par_iter(); // Parallel iterator
|
.into_par_iter()
|
||||||
|
|
||||||
#[cfg(not(feature = "parallel"))]
|
|
||||||
let iter = sources.into_iter(); // Sequential iterator
|
|
||||||
let sources = iter
|
|
||||||
.map(|(path, content)| (path, Source::from(content)))
|
.map(|(path, content)| (path, Source::from(content)))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|||||||
@@ -35,9 +35,10 @@ impl Error {
|
|||||||
let message = r#"
|
let message = r#"
|
||||||
┌──────────────────────────────────────────────────────────────────────────────────────────────────┐
|
┌──────────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||||
│ Warning: It looks like you are using 'ecrecover' to validate a signature of a user account. │
|
│ Warning: It looks like you are using 'ecrecover' to validate a signature of a user account. │
|
||||||
│ Polkadot comes with native account abstraction support, therefore it is highly recommended NOT │
|
│ zkSync Era comes with native account abstraction support, therefore it is highly recommended NOT │
|
||||||
│ to rely on the fact that the account has an ECDSA private key attached to it since accounts might│
|
│ to rely on the fact that the account has an ECDSA private key attached to it since accounts might│
|
||||||
│ implement other signature schemes. │
|
│ implement other signature schemes. │
|
||||||
|
│ Read more about Account Abstraction at https://v2-docs.zksync.io/dev/developer-guides/aa.html │
|
||||||
└──────────────────────────────────────────────────────────────────────────────────────────────────┘"#
|
└──────────────────────────────────────────────────────────────────────────────────────────────────┘"#
|
||||||
.to_owned();
|
.to_owned();
|
||||||
|
|
||||||
@@ -108,9 +109,10 @@ impl Error {
|
|||||||
let message = r#"
|
let message = r#"
|
||||||
┌──────────────────────────────────────────────────────────────────────────────────────────────────┐
|
┌──────────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||||
│ Warning: You are checking for 'tx.origin' in your code, which might lead to unexpected behavior. │
|
│ Warning: You are checking for 'tx.origin' in your code, which might lead to unexpected behavior. │
|
||||||
│ Polkadot comes with native account abstraction support, and therefore the initiator of a │
|
│ zkSync Era comes with native account abstraction support, and therefore the initiator of a │
|
||||||
│ transaction might be different from the contract calling your code. It is highly recommended NOT │
|
│ transaction might be different from the contract calling your code. It is highly recommended NOT │
|
||||||
│ to rely on tx.origin, but use msg.sender instead. │
|
│ to rely on tx.origin, but use msg.sender instead. │
|
||||||
|
│ Read more about Account Abstraction at https://v2-docs.zksync.io/dev/developer-guides/aa.html │
|
||||||
└──────────────────────────────────────────────────────────────────────────────────────────────────┘"#
|
└──────────────────────────────────────────────────────────────────────────────────────────────────┘"#
|
||||||
.to_owned();
|
.to_owned();
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ pub struct Output {
|
|||||||
pub long_version: Option<String>,
|
pub long_version: Option<String>,
|
||||||
/// The `resolc` compiler version.
|
/// The `resolc` compiler version.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub revive_version: Option<String>,
|
pub zk_version: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Output {
|
impl Output {
|
||||||
@@ -56,7 +56,7 @@ impl Output {
|
|||||||
libraries: BTreeMap<String, BTreeMap<String, String>>,
|
libraries: BTreeMap<String, BTreeMap<String, String>>,
|
||||||
pipeline: SolcPipeline,
|
pipeline: SolcPipeline,
|
||||||
solc_version: &SolcVersion,
|
solc_version: &SolcVersion,
|
||||||
debug_config: &revive_llvm_context::DebugConfig,
|
debug_config: Option<&revive_llvm_context::DebugConfig>,
|
||||||
) -> anyhow::Result<Project> {
|
) -> anyhow::Result<Project> {
|
||||||
if let SolcPipeline::EVMLA = pipeline {
|
if let SolcPipeline::EVMLA = pipeline {
|
||||||
self.preprocess_dependencies()?;
|
self.preprocess_dependencies()?;
|
||||||
@@ -90,7 +90,9 @@ impl Output {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_config.dump_yul(full_path.as_str(), ir_optimized.as_str())?;
|
if let Some(debug_config) = debug_config {
|
||||||
|
debug_config.dump_yul(full_path.as_str(), ir_optimized.as_str())?;
|
||||||
|
}
|
||||||
|
|
||||||
let mut lexer = Lexer::new(ir_optimized.to_owned());
|
let mut lexer = Lexer::new(ir_optimized.to_owned());
|
||||||
let object = Object::parse(&mut lexer, None).map_err(|error| {
|
let object = Object::parse(&mut lexer, None).map_err(|error| {
|
||||||
|
|||||||
@@ -3,20 +3,20 @@ use std::collections::BTreeMap;
|
|||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::str::FromStr;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
use crate::project::Project;
|
use crate::project::Project;
|
||||||
use crate::solc::pipeline::Pipeline as SolcPipeline;
|
use crate::solc::pipeline::Pipeline as SolcPipeline;
|
||||||
use crate::solc::solc_compiler::SolcCompiler;
|
|
||||||
use crate::solc::standard_json::input::settings::optimizer::Optimizer as SolcStandardJsonInputSettingsOptimizer;
|
use crate::solc::standard_json::input::settings::optimizer::Optimizer as SolcStandardJsonInputSettingsOptimizer;
|
||||||
use crate::solc::standard_json::input::settings::selection::Selection as SolcStandardJsonInputSettingsSelection;
|
use crate::solc::standard_json::input::settings::selection::Selection as SolcStandardJsonInputSettingsSelection;
|
||||||
use crate::solc::standard_json::input::Input as SolcStandardJsonInput;
|
use crate::solc::standard_json::input::Input as SolcStandardJsonInput;
|
||||||
use crate::solc::standard_json::output::contract::evm::bytecode::Bytecode;
|
use crate::solc::standard_json::output::contract::evm::bytecode::Bytecode;
|
||||||
use crate::solc::standard_json::output::contract::evm::bytecode::DeployedBytecode;
|
use crate::solc::standard_json::output::contract::evm::bytecode::DeployedBytecode;
|
||||||
use crate::solc::standard_json::output::Output as SolcStandardJsonOutput;
|
use crate::solc::standard_json::output::Output as SolcStandardJsonOutput;
|
||||||
use crate::solc::Compiler;
|
use crate::solc::Compiler as SolcCompiler;
|
||||||
use crate::warning::Warning;
|
use crate::warning::Warning;
|
||||||
|
|
||||||
static PVM_BLOB_CACHE: Lazy<Mutex<HashMap<CachedBlob, Vec<u8>>>> = Lazy::new(Default::default);
|
static PVM_BLOB_CACHE: Lazy<Mutex<HashMap<CachedBlob, Vec<u8>>>> = Lazy::new(Default::default);
|
||||||
@@ -24,9 +24,6 @@ static EVM_BLOB_CACHE: Lazy<Mutex<HashMap<CachedBlob, Vec<u8>>>> = Lazy::new(Def
|
|||||||
static EVM_RUNTIME_BLOB_CACHE: Lazy<Mutex<HashMap<CachedBlob, Vec<u8>>>> =
|
static EVM_RUNTIME_BLOB_CACHE: Lazy<Mutex<HashMap<CachedBlob, Vec<u8>>>> =
|
||||||
Lazy::new(Default::default);
|
Lazy::new(Default::default);
|
||||||
|
|
||||||
const DEBUG_CONFIG: revive_llvm_context::DebugConfig =
|
|
||||||
revive_llvm_context::DebugConfig::new(None, true);
|
|
||||||
|
|
||||||
#[derive(Hash, PartialEq, Eq)]
|
#[derive(Hash, PartialEq, Eq)]
|
||||||
struct CachedBlob {
|
struct CachedBlob {
|
||||||
contract_name: String,
|
contract_name: String,
|
||||||
@@ -82,8 +79,7 @@ pub fn build_solidity_with_options(
|
|||||||
|
|
||||||
inkwell::support::enable_llvm_pretty_stack_trace();
|
inkwell::support::enable_llvm_pretty_stack_trace();
|
||||||
revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM);
|
revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM);
|
||||||
let _ = crate::process::native_process::EXECUTABLE
|
let _ = crate::process::EXECUTABLE.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME));
|
||||||
.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME));
|
|
||||||
|
|
||||||
let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?;
|
let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?;
|
||||||
let solc_version = solc.version()?;
|
let solc_version = solc.version()?;
|
||||||
@@ -107,11 +103,14 @@ pub fn build_solidity_with_options(
|
|||||||
|
|
||||||
let mut output = solc.standard_json(input, pipeline, None, vec![], None)?;
|
let mut output = solc.standard_json(input, pipeline, None, vec![], None)?;
|
||||||
|
|
||||||
let project =
|
let project = output.try_to_project(sources, libraries, pipeline, &solc_version, None)?;
|
||||||
output.try_to_project(sources, libraries, pipeline, &solc_version, &DEBUG_CONFIG)?;
|
|
||||||
|
|
||||||
let build: crate::Build = project.compile(optimizer_settings, false, DEBUG_CONFIG)?;
|
let build: crate::Build = project.compile(optimizer_settings, false, None)?;
|
||||||
build.write_to_standard_json(&mut output, &solc_version)?;
|
build.write_to_standard_json(
|
||||||
|
&mut output,
|
||||||
|
&solc_version,
|
||||||
|
&semver::Version::from_str(env!("CARGO_PKG_VERSION"))?,
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
@@ -128,8 +127,7 @@ pub fn build_solidity_with_options_evm(
|
|||||||
|
|
||||||
inkwell::support::enable_llvm_pretty_stack_trace();
|
inkwell::support::enable_llvm_pretty_stack_trace();
|
||||||
revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM);
|
revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM);
|
||||||
let _ = crate::process::native_process::EXECUTABLE
|
let _ = crate::process::EXECUTABLE.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME));
|
||||||
.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME));
|
|
||||||
|
|
||||||
let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?;
|
let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?;
|
||||||
let solc_version = solc.version()?;
|
let solc_version = solc.version()?;
|
||||||
@@ -182,8 +180,7 @@ pub fn build_solidity_and_detect_missing_libraries(
|
|||||||
|
|
||||||
inkwell::support::enable_llvm_pretty_stack_trace();
|
inkwell::support::enable_llvm_pretty_stack_trace();
|
||||||
revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM);
|
revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM);
|
||||||
let _ = crate::process::native_process::EXECUTABLE
|
let _ = crate::process::EXECUTABLE.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME));
|
||||||
.set(PathBuf::from(crate::r#const::DEFAULT_EXECUTABLE_NAME));
|
|
||||||
|
|
||||||
let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?;
|
let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?;
|
||||||
let solc_version = solc.version()?;
|
let solc_version = solc.version()?;
|
||||||
@@ -202,11 +199,14 @@ pub fn build_solidity_and_detect_missing_libraries(
|
|||||||
|
|
||||||
let mut output = solc.standard_json(input, pipeline, None, vec![], None)?;
|
let mut output = solc.standard_json(input, pipeline, None, vec![], None)?;
|
||||||
|
|
||||||
let project =
|
let project = output.try_to_project(sources, libraries, pipeline, &solc_version, None)?;
|
||||||
output.try_to_project(sources, libraries, pipeline, &solc_version, &DEBUG_CONFIG)?;
|
|
||||||
|
|
||||||
let missing_libraries = project.get_missing_libraries();
|
let missing_libraries = project.get_missing_libraries();
|
||||||
missing_libraries.write_to_standard_json(&mut output, &solc.version()?)?;
|
missing_libraries.write_to_standard_json(
|
||||||
|
&mut output,
|
||||||
|
&solc.version()?,
|
||||||
|
&semver::Version::from_str(env!("CARGO_PKG_VERSION"))?,
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(output)
|
Ok(output)
|
||||||
}
|
}
|
||||||
@@ -219,12 +219,9 @@ pub fn build_yul(source_code: &str) -> anyhow::Result<()> {
|
|||||||
revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM);
|
revive_llvm_context::initialize_target(revive_llvm_context::Target::PVM);
|
||||||
let optimizer_settings = revive_llvm_context::OptimizerSettings::none();
|
let optimizer_settings = revive_llvm_context::OptimizerSettings::none();
|
||||||
|
|
||||||
let project = Project::try_from_yul_string::<SolcCompiler>(
|
let project =
|
||||||
PathBuf::from("test.yul").as_path(),
|
Project::try_from_yul_string(PathBuf::from("test.yul").as_path(), source_code, None)?;
|
||||||
source_code,
|
let _build = project.compile(optimizer_settings, false, None)?;
|
||||||
None,
|
|
||||||
)?;
|
|
||||||
let _build = project.compile(optimizer_settings, false, DEBUG_CONFIG)?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -235,14 +232,14 @@ pub fn check_solidity_warning(
|
|||||||
warning_substring: &str,
|
warning_substring: &str,
|
||||||
libraries: BTreeMap<String, BTreeMap<String, String>>,
|
libraries: BTreeMap<String, BTreeMap<String, String>>,
|
||||||
pipeline: SolcPipeline,
|
pipeline: SolcPipeline,
|
||||||
skip_for_revive_edition: bool,
|
skip_for_zkvm_edition: bool,
|
||||||
suppressed_warnings: Option<Vec<Warning>>,
|
suppressed_warnings: Option<Vec<Warning>>,
|
||||||
) -> anyhow::Result<bool> {
|
) -> anyhow::Result<bool> {
|
||||||
check_dependencies();
|
check_dependencies();
|
||||||
|
|
||||||
let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?;
|
let mut solc = SolcCompiler::new(SolcCompiler::DEFAULT_EXECUTABLE_NAME.to_owned())?;
|
||||||
let solc_version = solc.version()?;
|
let solc_version = solc.version()?;
|
||||||
if skip_for_revive_edition && solc_version.l2_revision.is_some() {
|
if skip_for_zkvm_edition && solc_version.l2_revision.is_some() {
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,8 @@ import * as path from 'path';
|
|||||||
const outputDir = 'artifacts';
|
const outputDir = 'artifacts';
|
||||||
const binExtension = ':C.pvm';
|
const binExtension = ':C.pvm';
|
||||||
const asmExtension = ':C.pvmasm';
|
const asmExtension = ':C.pvmasm';
|
||||||
const llvmExtension = '.ll';
|
|
||||||
const contractSolFilename = 'contract.sol';
|
const contractSolFilename = 'contract.sol';
|
||||||
const contractYulFilename = 'contract.yul';
|
const contractYulFilename = 'contract.yul';
|
||||||
const contractOptimizedLLVMFilename = contractSolFilename + '.C.optimized';
|
|
||||||
const contractUnoptimizedLLVMFilename = contractSolFilename + '.C.unoptimized';
|
|
||||||
const pathToOutputDir = path.join(__dirname, '..', outputDir);
|
const pathToOutputDir = path.join(__dirname, '..', outputDir);
|
||||||
const pathToContracts = path.join(__dirname, '..', 'src', 'contracts');
|
const pathToContracts = path.join(__dirname, '..', 'src', 'contracts');
|
||||||
const pathToBasicYulContract = path.join(pathToContracts, 'yul', contractYulFilename);
|
const pathToBasicYulContract = path.join(pathToContracts, 'yul', contractYulFilename);
|
||||||
@@ -19,11 +16,8 @@ export const paths = {
|
|||||||
outputDir: outputDir,
|
outputDir: outputDir,
|
||||||
binExtension: binExtension,
|
binExtension: binExtension,
|
||||||
asmExtension: asmExtension,
|
asmExtension: asmExtension,
|
||||||
llvmExtension: llvmExtension,
|
|
||||||
contractSolFilename: contractSolFilename,
|
contractSolFilename: contractSolFilename,
|
||||||
contractYulFilename: contractYulFilename,
|
contractYulFilename: contractYulFilename,
|
||||||
contractOptimizedLLVMFilename: contractOptimizedLLVMFilename,
|
|
||||||
contractUnoptimizedLLVMFilename: contractUnoptimizedLLVMFilename,
|
|
||||||
pathToOutputDir: pathToOutputDir,
|
pathToOutputDir: pathToOutputDir,
|
||||||
pathToContracts: pathToContracts,
|
pathToContracts: pathToContracts,
|
||||||
pathToBasicSolContract: pathToBasicSolContract,
|
pathToBasicSolContract: pathToBasicSolContract,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { executeCommand, isFolderExist, isFileExist, isFileEmpty } from "../src/helper";
|
import {executeCommand, isFolderExist, isFileExist, isFileEmpty} from "../src/helper";
|
||||||
import { paths } from '../src/entities';
|
import { paths } from '../src/entities';
|
||||||
|
|
||||||
|
|
||||||
@@ -76,69 +76,3 @@ describe("Default run a command from the help", () => {
|
|||||||
expect(result.output).not.toMatch(/([Ee]rror|[Ww]arning|[Ff]ail)/i);
|
expect(result.output).not.toMatch(/([Ee]rror|[Ww]arning|[Ff]ail)/i);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Run resolc with source debug information", () => {
|
|
||||||
const commands = [
|
|
||||||
`resolc -g ${paths.pathToBasicSolContract} --bin --asm --output-dir "${paths.pathToOutputDir}"`,
|
|
||||||
`resolc --disable-solc-optimizer -g ${paths.pathToBasicSolContract} --bin --asm --output-dir "${paths.pathToOutputDir}"`
|
|
||||||
]; // potential issue on resolc with full path on Windows cmd`;
|
|
||||||
|
|
||||||
for (var idx in commands) {
|
|
||||||
const command = commands[idx];
|
|
||||||
const result = executeCommand(command);
|
|
||||||
|
|
||||||
it("Compiler run successful", () => {
|
|
||||||
expect(result.output).toMatch(/(Compiler run successful.)/i);
|
|
||||||
});
|
|
||||||
it("Exit code = 0", () => {
|
|
||||||
expect(result.exitCode).toBe(0);
|
|
||||||
});
|
|
||||||
it("Output dir is created", () => {
|
|
||||||
expect(isFolderExist(paths.pathToOutputDir)).toBe(true);
|
|
||||||
});
|
|
||||||
it("Output files are created", () => { // a bug on windows
|
|
||||||
expect(isFileExist(paths.pathToOutputDir, paths.contractSolFilename, paths.binExtension)).toBe(true);
|
|
||||||
expect(isFileExist(paths.pathToOutputDir, paths.contractSolFilename, paths.asmExtension)).toBe(true);
|
|
||||||
});
|
|
||||||
it("the output files are not empty", () => {
|
|
||||||
expect(isFileEmpty(paths.pathToSolBinOutputFile)).toBe(false);
|
|
||||||
expect(isFileEmpty(paths.pathToSolAsmOutputFile)).toBe(false);
|
|
||||||
});
|
|
||||||
it("No 'Error'/'Fail' in the output", () => {
|
|
||||||
expect(result.output).not.toMatch(/([Ee]rror|[Ff]ail)/i);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("Run resolc with source debug information, check LLVM debug-info", () => {
|
|
||||||
const commands = [
|
|
||||||
`resolc -g ${paths.pathToBasicSolContract} --debug-output-dir="${paths.pathToOutputDir}"`,
|
|
||||||
`resolc -g --disable-solc-optimizer ${paths.pathToBasicSolContract} --debug-output-dir="${paths.pathToOutputDir}"`
|
|
||||||
]; // potential issue on resolc with full path on Windows cmd`;
|
|
||||||
|
|
||||||
for (var idx in commands) {
|
|
||||||
const command = commands[idx];
|
|
||||||
const result = executeCommand(command);
|
|
||||||
|
|
||||||
it("Compiler run successful", () => {
|
|
||||||
expect(result.output).toMatch(/(Compiler run successful.)/i);
|
|
||||||
});
|
|
||||||
it("Exit code = 0", () => {
|
|
||||||
expect(result.exitCode).toBe(0);
|
|
||||||
});
|
|
||||||
it("Output dir is created", () => {
|
|
||||||
expect(isFolderExist(paths.pathToOutputDir)).toBe(true);
|
|
||||||
});
|
|
||||||
it("Output files are created", () => { // a bug on windows
|
|
||||||
expect(isFileExist(paths.pathToOutputDir, paths.contractOptimizedLLVMFilename, paths.llvmExtension)).toBe(true);
|
|
||||||
expect(isFileExist(paths.pathToOutputDir, paths.contractUnoptimizedLLVMFilename, paths.llvmExtension)).toBe(true);
|
|
||||||
});
|
|
||||||
it("the output files are not empty", () => {
|
|
||||||
expect(isFileEmpty(paths.pathToSolBinOutputFile)).toBe(false);
|
|
||||||
expect(isFileEmpty(paths.pathToSolAsmOutputFile)).toBe(false);
|
|
||||||
});
|
|
||||||
it("No 'Error'/'Fail' in the output", () => {
|
|
||||||
expect(result.output).not.toMatch(/([Ee]rror|[Ff]ail)/i);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
//! The resolc compiler version.
|
|
||||||
|
|
||||||
use serde::Deserialize;
|
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
/// The resolc compiler version.
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
||||||
pub struct Version {
|
|
||||||
/// The long version string.
|
|
||||||
pub long: String,
|
|
||||||
/// The short `semver`.
|
|
||||||
pub default: semver::Version,
|
|
||||||
/// The LLVM version string.
|
|
||||||
pub llvm: semver::Version,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Version {
|
|
||||||
fn default() -> Self {
|
|
||||||
let default = semver::Version::parse(env!("CARGO_PKG_VERSION")).expect("Always valid");
|
|
||||||
let commit = env!("GIT_COMMIT_HASH");
|
|
||||||
let (llvm_major, llvm_minor, llvm_patch) = inkwell::support::get_llvm_version();
|
|
||||||
let llvm = semver::Version::new(llvm_major as u64, llvm_minor as u64, llvm_patch as u64);
|
|
||||||
|
|
||||||
Self {
|
|
||||||
long: format!("{default}+commit.{commit}.llvm-{llvm}"),
|
|
||||||
default,
|
|
||||||
llvm,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -21,7 +21,7 @@ pub struct Lexer {
|
|||||||
/// The input source code.
|
/// The input source code.
|
||||||
input: String,
|
input: String,
|
||||||
/// The number of characters processed so far.
|
/// The number of characters processed so far.
|
||||||
offset: u32,
|
offset: usize,
|
||||||
/// The current location.
|
/// The current location.
|
||||||
location: Location,
|
location: Location,
|
||||||
/// The peeked lexeme, waiting to be fetched.
|
/// The peeked lexeme, waiting to be fetched.
|
||||||
@@ -48,17 +48,8 @@ impl Lexer {
|
|||||||
return Ok(peeked);
|
return Ok(peeked);
|
||||||
}
|
}
|
||||||
|
|
||||||
while self.offset
|
while self.offset < self.input.len() {
|
||||||
< self
|
let input = &self.input[self.offset..];
|
||||||
.input
|
|
||||||
.len()
|
|
||||||
.try_into()
|
|
||||||
.map_err(|_| Error::InvalidLexeme {
|
|
||||||
location: self.location,
|
|
||||||
sequence: Default::default(),
|
|
||||||
})?
|
|
||||||
{
|
|
||||||
let input = &self.input[(self.offset as usize)..];
|
|
||||||
|
|
||||||
if input.starts_with(|character| char::is_ascii_whitespace(&character)) {
|
if input.starts_with(|character| char::is_ascii_whitespace(&character)) {
|
||||||
if input.starts_with('\n') {
|
if input.starts_with('\n') {
|
||||||
@@ -110,13 +101,12 @@ impl Lexer {
|
|||||||
return Ok(token);
|
return Ok(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
let end = self.input[(self.offset as usize)..]
|
let end = self.input[self.offset..]
|
||||||
.find(char::is_whitespace)
|
.find(char::is_whitespace)
|
||||||
.unwrap_or(self.input.len());
|
.unwrap_or(self.input.len());
|
||||||
return Err(Error::InvalidLexeme {
|
return Err(Error::InvalidLexeme {
|
||||||
location: self.location,
|
location: self.location,
|
||||||
sequence: self.input[(self.offset as usize)..(self.offset as usize) + end]
|
sequence: self.input[self.offset..self.offset + end].to_owned(),
|
||||||
.to_owned(),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,20 +19,12 @@ impl Comment {
|
|||||||
let end_position = input.find(Self::END).unwrap_or(input.len());
|
let end_position = input.find(Self::END).unwrap_or(input.len());
|
||||||
let input = &input[..end_position];
|
let input = &input[..end_position];
|
||||||
|
|
||||||
let length = (end_position + Self::END.len())
|
let length = end_position + Self::END.len();
|
||||||
.try_into()
|
let lines = input.matches('\n').count();
|
||||||
.expect("the YUL should be of reasonable size");
|
|
||||||
let lines = input
|
|
||||||
.matches('\n')
|
|
||||||
.count()
|
|
||||||
.try_into()
|
|
||||||
.expect("the YUL should be of reasonable size");
|
|
||||||
let columns = match input.rfind('\n') {
|
let columns = match input.rfind('\n') {
|
||||||
Some(new_line) => end_position - (new_line + 1),
|
Some(new_line) => end_position - (new_line + 1),
|
||||||
None => end_position,
|
None => end_position,
|
||||||
}
|
};
|
||||||
.try_into()
|
|
||||||
.expect("the YUL should be of reasonable size");
|
|
||||||
|
|
||||||
Token::new(Location::new(lines, columns), Lexeme::Comment, length)
|
Token::new(Location::new(lines, columns), Lexeme::Comment, length)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,7 @@ impl Comment {
|
|||||||
/// Returns the comment's length, including the trimmed whitespace around it.
|
/// Returns the comment's length, including the trimmed whitespace around it.
|
||||||
pub fn parse(input: &str) -> Token {
|
pub fn parse(input: &str) -> Token {
|
||||||
let end_position = input.find(Self::END).unwrap_or(input.len());
|
let end_position = input.find(Self::END).unwrap_or(input.len());
|
||||||
let length = (end_position + Self::END.len())
|
let length = end_position + Self::END.len();
|
||||||
.try_into()
|
|
||||||
.expect("the YUL should be of reasonable size");
|
|
||||||
|
|
||||||
Token::new(Location::new(1, 1), Lexeme::Comment, length)
|
Token::new(Location::new(1, 1), Lexeme::Comment, length)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,10 +26,7 @@ impl Identifier {
|
|||||||
let end = input.find(Self::cannot_continue).unwrap_or(input.len());
|
let end = input.find(Self::cannot_continue).unwrap_or(input.len());
|
||||||
|
|
||||||
let inner = input[..end].to_string();
|
let inner = input[..end].to_string();
|
||||||
let length = inner
|
let length = inner.len();
|
||||||
.len()
|
|
||||||
.try_into()
|
|
||||||
.expect("the YUL should be of reasonable size");
|
|
||||||
|
|
||||||
if let Some(token) = Keyword::parse(inner.as_str()) {
|
if let Some(token) = Keyword::parse(inner.as_str()) {
|
||||||
return Some(token);
|
return Some(token);
|
||||||
|
|||||||
@@ -58,9 +58,6 @@ impl Keyword {
|
|||||||
if length != input.len() {
|
if length != input.len() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let length = length
|
|
||||||
.try_into()
|
|
||||||
.expect("the YUL should be of reasonable size");
|
|
||||||
|
|
||||||
Some(Token::new(Location::new(0, length), lexeme, length))
|
Some(Token::new(Location::new(0, length), lexeme, length))
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user