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
|
||||
}
|
||||
|
||||
# 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()
|
||||
{
|
||||
SOLTMPDIR=$(mktemp -d)
|
||||
pushd "$SOLTMPDIR"
|
||||
|
||||
(( $# <= 2 )) || fail "This function accepts at most two arguments."
|
||||
|
||||
if [[ $2 != --optimize ]] && [[ $2 != "" ]]
|
||||
@ -320,56 +323,54 @@ function test_via_ir_equivalence()
|
||||
local solidity_file="$1"
|
||||
local optimize_flag="$2"
|
||||
|
||||
filename=$(basename "$1" .sol)
|
||||
output_file_prefix=$(basename "$1" .sol)
|
||||
|
||||
local optimizer_flags=()
|
||||
[[ $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" |
|
||||
sed '/^Optimized IR:$/d' |
|
||||
awk -v RS= "{print > (\"${filename}_\"NR \".yul\")}"
|
||||
sed '/^Optimized IR:$/d' |
|
||||
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" |
|
||||
sed '/^======= <stdin>/d' |
|
||||
sed '/^Text representation:$/d' >> "${yul_file/.yul/.asm}"
|
||||
sed '/^Text representation:$/d' > "${yul_file/.yul/.asm}"
|
||||
done
|
||||
|
||||
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')
|
||||
done
|
||||
|
||||
asm_output_via_ir=$(
|
||||
msg_on_error --no-stderr "$SOLC" --via-ir --asm --debug-info location "${optimizer_flags[@]}" "$solidity_file" |
|
||||
sed '/^======= <stdin>/d' |
|
||||
sed '/^EVM assembly:$/d' |
|
||||
sed '/^asm_output_via_ir/d' |
|
||||
sed '/^=======/d'
|
||||
sed '/^EVM assembly:$/d' |
|
||||
sed '/^=======/d'
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
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+=$(
|
||||
msg_on_error --no-stderr "$SOLC" --strict-assembly --bin "${optimizer_flags[@]}" "$yul_file" |
|
||||
sed '/^======= <stdin>/d' |
|
||||
sed '/^Binary representation:$/d' |
|
||||
sed '/^=======/d'
|
||||
sed '/^Binary representation:$/d' |
|
||||
sed '/^=======/d'
|
||||
)
|
||||
done
|
||||
|
||||
bin_output_via_ir=$(
|
||||
msg_on_error --no-stderr "$SOLC" --via-ir --bin "${optimizer_flags[@]}" "$solidity_file" |
|
||||
sed '/^======= <stdin>/d' |
|
||||
sed '/^Binary:$/d' |
|
||||
sed '/^=======/d'
|
||||
)
|
||||
|
||||
diff_values "$bin_output_two_stage" "$bin_output_via_ir" --ignore-space-change --ignore-blank-lines
|
||||
|
||||
popd
|
||||
rm -r "$SOLTMPDIR"
|
||||
}
|
||||
|
||||
## 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..."
|
||||
SOLTMPDIR=$(mktemp -d)
|
||||
(
|
||||
cd "$SOLTMPDIR"
|
||||
|
||||
externalContracts=(
|
||||
externalTests/solc-js/DAO/TokenCreation.sol
|
||||
libsolidity/semanticTests/externalContracts/_prbmath/PRBMathSD59x18.sol
|
||||
@ -631,7 +629,6 @@ SOLTMPDIR=$(mktemp -d)
|
||||
test_via_ir_equivalence "${REPO_ROOT}/test/${contractFile}" --optimize
|
||||
done
|
||||
)
|
||||
rm -r "$SOLTMPDIR"
|
||||
|
||||
printTask "Testing standard input..."
|
||||
SOLTMPDIR=$(mktemp -d)
|
||||
|
Loading…
Reference in New Issue
Block a user