Helpers for removing decorations form solc output

This commit is contained in:
Kamil Śliwak 2023-06-01 16:39:11 +02:00
parent 25c78be73e
commit e6716e3208
2 changed files with 42 additions and 15 deletions

View File

@ -103,3 +103,30 @@ function compileFull
false false
fi fi
} }
function stripCLIDecorations
{
sed -e '/^=======.*=======$/d' \
-e '/^Binary:$/d' \
-e '/^Binary of the runtime part:$/d' \
-e '/^Opcodes:$/d' \
-e '/^IR:$/d' \
-e '/^Optimized IR:$/d' \
-e '/^EVM assembly:$/d' \
-e '/^JSON AST (compact format):$/d' \
-e '/^Function signatures:$/d' \
-e '/^Contract Storage Layout:$/d' \
-e '/^Developer Documentation$/d' \
-e '/^User Documentation$/d' \
-e '/^Contract JSON ABI$/d' \
-e '/^Metadata:$/d' \
-e '/^EVM$/d' \
-e '/^Pretty printed source:$/d' \
-e '/^Text representation:$/d' \
-e '/^Binary representation:$/d'
}
function stripEmptyLines
{
sed -e '/^\s*$/d'
}

View File

@ -3,6 +3,8 @@ set -eo pipefail
# shellcheck source=scripts/common.sh # shellcheck source=scripts/common.sh
source "${REPO_ROOT}/scripts/common.sh" source "${REPO_ROOT}/scripts/common.sh"
# shellcheck source=scripts/common_cmdline.sh
source "${REPO_ROOT}/scripts/common_cmdline.sh"
function test_via_ir_equivalence() function test_via_ir_equivalence()
{ {
@ -21,24 +23,24 @@ function test_via_ir_equivalence()
[[ $optimize_flag == "" ]] || optimizer_flags+=("$optimize_flag") [[ $optimize_flag == "" ]] || optimizer_flags+=("$optimize_flag")
[[ $optimize_flag == "" ]] || output_file_prefix+="_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 \
sed '/^Optimized IR:$/d' | "$SOLC" --ir-optimized --debug-info location "${optimizer_flags[@]}" "$solidity_file" |
split_on_empty_lines_into_numbered_files "$output_file_prefix" ".yul" stripCLIDecorations |
split_on_empty_lines_into_numbered_files "$output_file_prefix" ".yul"
local asm_output_two_stage asm_output_via_ir local asm_output_two_stage asm_output_via_ir
for yul_file in $(find . -name "${output_file_prefix}*.yul" | sort -V); do for yul_file in $(find . -name "${output_file_prefix}*.yul" | sort -V); do
asm_output_two_stage+=$( asm_output_two_stage+=$(
msg_on_error --no-stderr "$SOLC" --strict-assembly --asm "${optimizer_flags[@]}" "$yul_file" | msg_on_error --no-stderr \
sed '/^Text representation:$/d' | "$SOLC" --strict-assembly --asm "${optimizer_flags[@]}" "$yul_file" | stripCLIDecorations
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 \
sed '/^EVM assembly:$/d' | "$SOLC" --via-ir --asm --debug-info location "${optimizer_flags[@]}" "$solidity_file" |
sed '/^=======/d' stripCLIDecorations
) )
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
@ -47,16 +49,14 @@ function test_via_ir_equivalence()
for yul_file in $(find . -name "${output_file_prefix}*.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 \
sed '/^Binary representation:$/d' | "$SOLC" --strict-assembly --bin "${optimizer_flags[@]}" "$yul_file" | stripCLIDecorations
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 \
sed '/^Binary:$/d' | "$SOLC" --via-ir --bin "${optimizer_flags[@]}" "$solidity_file" | stripCLIDecorations
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