mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #12898 from ethereum/via-ir-equivalence-tests
Create split_on_empty_lines_into_numbered_files function in scripts/common.sh
This commit is contained in:
commit
c71d0aec83
@ -246,3 +246,12 @@ function first_word
|
|||||||
|
|
||||||
echo "$words" | cut -d " " -f 1
|
echo "$words" | cut -d " " -f 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function reads from stdin. Therefore it has to be used with pipes.
|
||||||
|
function split_on_empty_lines_into_numbered_files
|
||||||
|
{
|
||||||
|
path_prefix="${1}"
|
||||||
|
path_suffix="${2}"
|
||||||
|
|
||||||
|
awk -v RS= "{print > (\"${path_prefix}_\"NR \"${path_suffix}\")}"
|
||||||
|
}
|
||||||
|
@ -310,6 +310,9 @@ function test_solc_assembly_output
|
|||||||
|
|
||||||
function test_via_ir_equivalence()
|
function test_via_ir_equivalence()
|
||||||
{
|
{
|
||||||
|
SOLTMPDIR=$(mktemp -d)
|
||||||
|
pushd "$SOLTMPDIR"
|
||||||
|
|
||||||
(( $# <= 2 )) || fail "This function accepts at most two arguments."
|
(( $# <= 2 )) || fail "This function accepts at most two arguments."
|
||||||
|
|
||||||
if [[ $2 != --optimize ]] && [[ $2 != "" ]]
|
if [[ $2 != --optimize ]] && [[ $2 != "" ]]
|
||||||
@ -320,56 +323,54 @@ function test_via_ir_equivalence()
|
|||||||
local solidity_file="$1"
|
local solidity_file="$1"
|
||||||
local optimize_flag="$2"
|
local optimize_flag="$2"
|
||||||
|
|
||||||
filename=$(basename "$1" .sol)
|
output_file_prefix=$(basename "$1" .sol)
|
||||||
|
|
||||||
local optimizer_flags=()
|
local optimizer_flags=()
|
||||||
[[ $optimize_flag == "" ]] || optimizer_flags+=("$optimize_flag")
|
[[ $optimize_flag == "" ]] || optimizer_flags+=("$optimize_flag")
|
||||||
[[ $optimize_flag == "" ]] || filename+="_optimize"
|
[[ $optimize_flag == "" ]] || output_file_prefix+="_optimize"
|
||||||
|
|
||||||
msg_on_error --no-stderr "$SOLC" --ir-optimized --debug-info location "${optimizer_flags[@]}" "$solidity_file" |
|
msg_on_error --no-stderr "$SOLC" --ir-optimized --debug-info location "${optimizer_flags[@]}" "$solidity_file" |
|
||||||
sed '/^Optimized IR:$/d' |
|
sed '/^Optimized IR:$/d' |
|
||||||
awk -v RS= "{print > (\"${filename}_\"NR \".yul\")}"
|
split_on_empty_lines_into_numbered_files $output_file_prefix ".yul"
|
||||||
|
|
||||||
for yul_file in $(find . -name "$filename*.yul" | sort -V); do
|
for yul_file in $(find . -name "${output_file_prefix}*.yul" | sort -V); do
|
||||||
msg_on_error --no-stderr "$SOLC" --strict-assembly --asm "${optimizer_flags[@]}" "$yul_file" |
|
msg_on_error --no-stderr "$SOLC" --strict-assembly --asm "${optimizer_flags[@]}" "$yul_file" |
|
||||||
sed '/^======= <stdin>/d' |
|
sed '/^Text representation:$/d' > "${yul_file/.yul/.asm}"
|
||||||
sed '/^Text representation:$/d' >> "${yul_file/.yul/.asm}"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
local asm_output_two_stage asm_output_via_ir
|
local asm_output_two_stage asm_output_via_ir
|
||||||
for asm_file in $(find . -name "$filename*.asm" | sort -V); do
|
for asm_file in $(find . -name "${output_file_prefix}*.asm" | sort -V); do
|
||||||
asm_output_two_stage+=$(sed '/^asm_output_two_stage:$/d' "$asm_file" | sed '/^=======/d')
|
asm_output_two_stage+=$(sed '/^asm_output_two_stage:$/d' "$asm_file" | sed '/^=======/d')
|
||||||
done
|
done
|
||||||
|
|
||||||
asm_output_via_ir=$(
|
asm_output_via_ir=$(
|
||||||
msg_on_error --no-stderr "$SOLC" --via-ir --asm --debug-info location "${optimizer_flags[@]}" "$solidity_file" |
|
msg_on_error --no-stderr "$SOLC" --via-ir --asm --debug-info location "${optimizer_flags[@]}" "$solidity_file" |
|
||||||
sed '/^======= <stdin>/d' |
|
sed '/^EVM assembly:$/d' |
|
||||||
sed '/^EVM assembly:$/d' |
|
sed '/^=======/d'
|
||||||
sed '/^asm_output_via_ir/d' |
|
|
||||||
sed '/^=======/d'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
diff_values "$asm_output_two_stage" "$asm_output_via_ir" --ignore-space-change --ignore-blank-lines
|
diff_values "$asm_output_two_stage" "$asm_output_via_ir" --ignore-space-change --ignore-blank-lines
|
||||||
|
|
||||||
local bin_output_two_stage bin_output_via_ir
|
local bin_output_two_stage bin_output_via_ir
|
||||||
|
|
||||||
for yul_file in $(find . -name "$filename*.yul" | sort -V); do
|
for yul_file in $(find . -name "${output_file_prefix}*.yul" | sort -V); do
|
||||||
bin_output_two_stage+=$(
|
bin_output_two_stage+=$(
|
||||||
msg_on_error --no-stderr "$SOLC" --strict-assembly --bin "${optimizer_flags[@]}" "$yul_file" |
|
msg_on_error --no-stderr "$SOLC" --strict-assembly --bin "${optimizer_flags[@]}" "$yul_file" |
|
||||||
sed '/^======= <stdin>/d' |
|
sed '/^Binary representation:$/d' |
|
||||||
sed '/^Binary representation:$/d' |
|
sed '/^=======/d'
|
||||||
sed '/^=======/d'
|
|
||||||
)
|
)
|
||||||
done
|
done
|
||||||
|
|
||||||
bin_output_via_ir=$(
|
bin_output_via_ir=$(
|
||||||
msg_on_error --no-stderr "$SOLC" --via-ir --bin "${optimizer_flags[@]}" "$solidity_file" |
|
msg_on_error --no-stderr "$SOLC" --via-ir --bin "${optimizer_flags[@]}" "$solidity_file" |
|
||||||
sed '/^======= <stdin>/d' |
|
|
||||||
sed '/^Binary:$/d' |
|
sed '/^Binary:$/d' |
|
||||||
sed '/^=======/d'
|
sed '/^=======/d'
|
||||||
)
|
)
|
||||||
|
|
||||||
diff_values "$bin_output_two_stage" "$bin_output_via_ir" --ignore-space-change --ignore-blank-lines
|
diff_values "$bin_output_two_stage" "$bin_output_via_ir" --ignore-space-change --ignore-blank-lines
|
||||||
|
|
||||||
|
popd
|
||||||
|
rm -r "$SOLTMPDIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
## RUN
|
## RUN
|
||||||
@ -598,10 +599,7 @@ printTask "Testing assemble, yul, strict-assembly and optimize..."
|
|||||||
)
|
)
|
||||||
|
|
||||||
printTask "Testing the eqivalence of --via-ir and a two-stage compilation..."
|
printTask "Testing the eqivalence of --via-ir and a two-stage compilation..."
|
||||||
SOLTMPDIR=$(mktemp -d)
|
|
||||||
(
|
(
|
||||||
cd "$SOLTMPDIR"
|
|
||||||
|
|
||||||
externalContracts=(
|
externalContracts=(
|
||||||
externalTests/solc-js/DAO/TokenCreation.sol
|
externalTests/solc-js/DAO/TokenCreation.sol
|
||||||
libsolidity/semanticTests/externalContracts/_prbmath/PRBMathSD59x18.sol
|
libsolidity/semanticTests/externalContracts/_prbmath/PRBMathSD59x18.sol
|
||||||
@ -631,7 +629,6 @@ SOLTMPDIR=$(mktemp -d)
|
|||||||
test_via_ir_equivalence "${REPO_ROOT}/test/${contractFile}" --optimize
|
test_via_ir_equivalence "${REPO_ROOT}/test/${contractFile}" --optimize
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
rm -r "$SOLTMPDIR"
|
|
||||||
|
|
||||||
printTask "Testing standard input..."
|
printTask "Testing standard input..."
|
||||||
SOLTMPDIR=$(mktemp -d)
|
SOLTMPDIR=$(mktemp -d)
|
||||||
|
Loading…
Reference in New Issue
Block a user