2021-11-19 13:56:30 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -eo pipefail
|
|
|
|
|
|
|
|
# shellcheck source=scripts/common.sh
|
|
|
|
source "${REPO_ROOT}/scripts/common.sh"
|
2023-06-01 14:39:11 +00:00
|
|
|
# shellcheck source=scripts/common_cmdline.sh
|
|
|
|
source "${REPO_ROOT}/scripts/common_cmdline.sh"
|
2021-11-19 13:56:30 +00:00
|
|
|
|
|
|
|
function test_via_ir_equivalence()
|
|
|
|
{
|
|
|
|
(( $# <= 2 )) || fail "This function accepts at most two arguments."
|
|
|
|
local solidity_file="$1"
|
|
|
|
local optimize_flag="$2"
|
|
|
|
[[ $optimize_flag == --optimize || $optimize_flag == "" ]] || assertFail "The second argument must be --optimize if present."
|
|
|
|
|
|
|
|
local output_file_prefix
|
2023-06-01 18:10:42 +00:00
|
|
|
output_file_prefix=$(basename "$solidity_file" .sol)
|
2021-11-19 13:56:30 +00:00
|
|
|
|
2023-06-01 16:51:42 +00:00
|
|
|
SOLTMPDIR=$(mktemp -d -t "cmdline-test-via-ir-equivalence-${output_file_prefix}-XXXXXX")
|
|
|
|
pushd "$SOLTMPDIR" > /dev/null
|
|
|
|
|
2021-11-19 13:56:30 +00:00
|
|
|
local optimizer_flags=()
|
|
|
|
[[ $optimize_flag == "" ]] || optimizer_flags+=("$optimize_flag")
|
|
|
|
[[ $optimize_flag == "" ]] || output_file_prefix+="_optimize"
|
|
|
|
|
2023-06-01 14:39:11 +00:00
|
|
|
msg_on_error --no-stderr \
|
|
|
|
"$SOLC" --ir-optimized --debug-info location "${optimizer_flags[@]}" "$solidity_file" |
|
|
|
|
stripCLIDecorations |
|
|
|
|
split_on_empty_lines_into_numbered_files "$output_file_prefix" ".yul"
|
2021-11-19 13:56:30 +00:00
|
|
|
|
|
|
|
local asm_output_two_stage asm_output_via_ir
|
|
|
|
|
|
|
|
for yul_file in $(find . -name "${output_file_prefix}*.yul" | sort -V); do
|
|
|
|
asm_output_two_stage+=$(
|
2023-06-01 14:39:11 +00:00
|
|
|
msg_on_error --no-stderr \
|
2023-05-17 12:03:16 +00:00
|
|
|
"$SOLC" --strict-assembly --asm "${optimizer_flags[@]}" --no-optimize-yul "$yul_file" |
|
|
|
|
stripCLIDecorations
|
2021-11-19 13:56:30 +00:00
|
|
|
)
|
|
|
|
done
|
|
|
|
|
|
|
|
asm_output_via_ir=$(
|
2023-06-01 14:39:11 +00:00
|
|
|
msg_on_error --no-stderr \
|
|
|
|
"$SOLC" --via-ir --asm --debug-info location "${optimizer_flags[@]}" "$solidity_file" |
|
|
|
|
stripCLIDecorations
|
2021-11-19 13:56:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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 "${output_file_prefix}*.yul" | sort -V); do
|
|
|
|
bin_output_two_stage+=$(
|
2023-06-01 14:39:11 +00:00
|
|
|
msg_on_error --no-stderr \
|
2023-05-17 12:03:16 +00:00
|
|
|
"$SOLC" --strict-assembly --bin "${optimizer_flags[@]}" "$yul_file" --no-optimize-yul |
|
|
|
|
stripCLIDecorations
|
2021-11-19 13:56:30 +00:00
|
|
|
)
|
|
|
|
done
|
|
|
|
|
|
|
|
bin_output_via_ir=$(
|
2023-06-01 14:39:11 +00:00
|
|
|
msg_on_error --no-stderr \
|
|
|
|
"$SOLC" --via-ir --bin "${optimizer_flags[@]}" "$solidity_file" | stripCLIDecorations
|
2021-11-19 13:56:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
diff_values "$bin_output_two_stage" "$bin_output_via_ir" --ignore-space-change --ignore-blank-lines
|
|
|
|
|
|
|
|
popd > /dev/null
|
|
|
|
rm -r "$SOLTMPDIR"
|
|
|
|
}
|
|
|
|
|
2023-06-01 16:44:23 +00:00
|
|
|
externalContracts=(
|
|
|
|
externalTests/solc-js/DAO/TokenCreation.sol
|
|
|
|
libsolidity/semanticTests/externalContracts/_prbmath/PRBMathSD59x18.sol
|
|
|
|
libsolidity/semanticTests/externalContracts/_prbmath/PRBMathUD60x18.sol
|
|
|
|
libsolidity/semanticTests/externalContracts/_stringutils/stringutils.sol
|
|
|
|
libsolidity/semanticTests/externalContracts/deposit_contract.sol
|
|
|
|
libsolidity/semanticTests/externalContracts/FixedFeeRegistrar.sol
|
|
|
|
libsolidity/semanticTests/externalContracts/snark.sol
|
|
|
|
)
|
2021-11-19 13:56:30 +00:00
|
|
|
|
2023-06-01 16:44:23 +00:00
|
|
|
requiresOptimizer=(
|
|
|
|
externalTests/solc-js/DAO/TokenCreation.sol
|
|
|
|
libsolidity/semanticTests/externalContracts/deposit_contract.sol
|
|
|
|
libsolidity/semanticTests/externalContracts/FixedFeeRegistrar.sol
|
|
|
|
libsolidity/semanticTests/externalContracts/snark.sol
|
2021-11-19 13:56:30 +00:00
|
|
|
)
|
2023-06-01 16:44:23 +00:00
|
|
|
|
|
|
|
for contractFile in "${externalContracts[@]}"
|
|
|
|
do
|
|
|
|
if ! [[ "${requiresOptimizer[*]}" =~ $contractFile ]]
|
|
|
|
then
|
2023-06-01 18:10:42 +00:00
|
|
|
printTask " - ${contractFile}"
|
2023-06-01 16:44:23 +00:00
|
|
|
test_via_ir_equivalence "${REPO_ROOT}/test/${contractFile}"
|
|
|
|
fi
|
|
|
|
|
2023-06-01 18:10:42 +00:00
|
|
|
printTask " - ${contractFile} (optimized)"
|
2023-06-01 16:44:23 +00:00
|
|
|
test_via_ir_equivalence "${REPO_ROOT}/test/${contractFile}" --optimize
|
|
|
|
done
|