[ewasm] add ewasm bytecode compare support.

This commit is contained in:
Alexander Arlt 2020-12-19 14:48:38 -05:00
parent 158154bac3
commit aa40583f1d
2 changed files with 49 additions and 34 deletions

View File

@ -902,7 +902,9 @@ jobs:
- checkout - checkout
- attach_workspace: - attach_workspace:
at: build at: build
- run: scripts/bytecodecompare/storebytecode.sh && cp -v report.txt bytecode-report-ubuntu.txt - run:
no_output_timeout: 60m
command: scripts/bytecodecompare/storebytecode.sh && cp -v report.txt bytecode-report-ubuntu.txt
- store_artifacts: - store_artifacts:
path: report.txt path: report.txt
- persist_to_workspace: - persist_to_workspace:
@ -919,7 +921,9 @@ jobs:
- checkout - checkout
- attach_workspace: - attach_workspace:
at: . at: .
- run: scripts/bytecodecompare/storebytecode.sh && cp -v report.txt bytecode-report-osx.txt - run:
no_output_timeout: 60m
command: scripts/bytecodecompare/storebytecode.sh && cp -v report.txt bytecode-report-osx.txt
- store_artifacts: - store_artifacts:
path: report.txt path: report.txt
- persist_to_workspace: - persist_to_workspace:
@ -936,7 +940,9 @@ jobs:
- attach_workspace: - attach_workspace:
at: build at: build
- run: python scripts\isolate_tests.py test\ - run: python scripts\isolate_tests.py test\
- run: python scripts\bytecodecompare\prepare_report.py build\solc\Release\solc.exe - run:
no_output_timeout: 60m
command: python scripts\bytecodecompare\prepare_report.py build\solc\Release\solc.exe
- run: cp report.txt bytecode-report-windows.txt - run: cp report.txt bytecode-report-windows.txt
- store_artifacts: - store_artifacts:
path: report.txt path: report.txt
@ -954,7 +960,9 @@ jobs:
- checkout - checkout
- attach_workspace: - attach_workspace:
at: emscripten_build/libsolc at: emscripten_build/libsolc
- run: scripts/bytecodecompare/storebytecode.sh && cp -v report.txt bytecode-report-emscripten.txt - run:
no_output_timeout: 60m
command: scripts/bytecodecompare/storebytecode.sh && cp -v report.txt bytecode-report-emscripten.txt
- store_artifacts: - store_artifacts:
path: report.txt path: report.txt
- persist_to_workspace: - persist_to_workspace:

View File

@ -10,34 +10,41 @@ REPORT_FILE = open("report.txt", mode="w", encoding='utf8', newline='\n')
for optimize in [False, True]: for optimize in [False, True]:
for f in sorted(glob.glob("*.sol")): for f in sorted(glob.glob("*.sol")):
sources = {} for output_type in [['evm.bytecode.object', 'metadata'], ['ewasm.wast', 'ewasm.wasm', 'metadata']]:
sources[f] = {'content': open(f, mode='r', encoding='utf8').read()} sources = {}
input_json = { sources[f] = {'content': open(f, mode='r', encoding='utf8').read()}
'language': 'Solidity', input_json = {
'sources': sources, 'language': 'Solidity',
'settings': { 'sources': sources,
'optimizer': { 'settings': {
'enabled': optimize 'optimizer': {
}, 'enabled': optimize
'outputSelection': {'*': {'*': ['evm.bytecode.object', 'metadata']}}, },
'modelChecker': { "engine": 'none' } 'outputSelection': {'*': {'*': output_type}},
'modelChecker': {"engine": 'none'}
}
} }
} args = [SOLC_BIN, '--standard-json']
args = [SOLC_BIN, '--standard-json'] if optimize:
if optimize: args += ['--optimize']
args += ['--optimize'] proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (out, err) = proc.communicate(json.dumps(input_json).encode('utf-8'))
(out, err) = proc.communicate(json.dumps(input_json).encode('utf-8')) try:
try: result = json.loads(out.decode('utf-8').strip())
result = json.loads(out.decode('utf-8').strip()) for filename in sorted(result['contracts'].keys()):
for filename in sorted(result['contracts'].keys()): for contractName in sorted(result['contracts'][filename].keys()):
for contractName in sorted(result['contracts'][filename].keys()): outputType = ""
contractData = result['contracts'][filename][contractName] if 'ewasm.wast' in output_type:
if 'evm' in contractData and 'bytecode' in contractData['evm']: outputType = "(ewasm)"
REPORT_FILE.write(filename + ':' + contractName + ' ' + contractData = result['contracts'][filename][contractName]
contractData['evm']['bytecode']['object'] + '\n') if 'evm' in contractData and 'bytecode' in contractData['evm']:
else: REPORT_FILE.write(filename + ':' + contractName + ' ' +
REPORT_FILE.write(filename + ':' + contractName + ' NO BYTECODE\n') contractData['evm']['bytecode']['object'] + '\n')
REPORT_FILE.write(filename + ':' + contractName + ' ' + contractData['metadata'] + '\n') elif 'ewasm' in contractData and 'wasm' in contractData['ewasm']:
except KeyError: REPORT_FILE.write(filename + ':' + contractName + outputType +
REPORT_FILE.write(f + ": ERROR\n") contractData['ewasm']['wasm'] + '\n')
else:
REPORT_FILE.write(filename + ':' + contractName + outputType + ' NO BYTECODE\n')
REPORT_FILE.write(filename + ':' + contractName + outputType + ' ' + contractData['metadata'] + '\n')
except KeyError:
REPORT_FILE.write(f + ": ERROR\n")