Created
July 8, 2021 12:52
-
-
Save ekpyron/2e4db1c8276265bd11850a3f01d011d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo '{"contracts": {"test.sol:C": {"asm": {".code": [],".data": {"0": | |
{".auxdata":"a26469706673582212205fe09eead890659ccd3f8dfd5c787234e5830f5efe2e01ab570bd5d3eb7ce18364736f6c6378263 | |
02e382e372d646576656c6f702e323032312e372e382b636f6d6d69742e30306330666361660057", | |
".code": [' > /tmp/test.asm | |
cat $1 | while read OP; do | |
if [[ $OP == PUSH* ]]; then | |
VALUE=$(echo $OP | cut -f 2 -d ' ') | |
echo "{\"begin\": 0,\"end\": 0,\"name\": \"PUSH\",\"source\": 0,\"value\": \"${VALUE}\"}," >> | |
/tmp/test.asm | |
else | |
echo "{\"begin\": 0,\"end\": 0,\"name\": \"$OP\",\"source\": 0}," >> /tmp/test.asm | |
fi | |
done | |
echo "{\"begin\": 0,\"end\": 0,\"name\": \"CALLVALUE\",\"source\": 0}" >> /tmp/test.asm | |
echo ']}}}}}, "version": "0.8.7-develop.2021.7.8+commit.00c0fcaf.Linux.g++"}' >> /tmp/test.asm | |
./gasol-asm.py /tmp/test.asm &> /dev/null | |
cat /tmp/gasol/solutions/C/disasm/block0_optimized.disasm_opt | sed -E 's/(PUSH[0-9]*) ([0-9a-zA-Z]*)/\1_\2/g' | |
| sed -e 's/ /\n/g' | sed -E 's/(PUSH[0-9]*)_([0-9a-zA-Z]*)/\1 \2/g' > /tmp/test.opt | |
OPT_NUM_OPS=$(cat /tmp/test.opt | head -n -1 | wc -l) | |
NUM_OPS=$(cat $1 | wc -l) | |
echo -n "Original $NUM_OPS operations; Optimized: $OPT_NUM_OPS operations: " | |
if [ $NUM_OPS == $OPT_NUM_OPS ]; then | |
echo "OPTIMAL" | |
else | |
echo "NON-OPTIMAL" | |
cat /tmp/test.opt | head -n -1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment