mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
New CLI output in assembly mode: --ewasm-ir
This commit is contained in:
parent
affeff18f5
commit
1a19d9a5cf
@ -7,7 +7,7 @@ Language Features:
|
||||
Compiler Features:
|
||||
* Commandline Interface: Accept nested brackets in step sequences passed to ``--yul-optimizations``.
|
||||
* Commandline Interface: Add ``--debug-info`` option for selecting how much extra debug information should be included in the produced EVM assembly and Yul code.
|
||||
* Commandline Interface: Support ``--asm``, ``--bin``, ``--ir-optimized`` and ``--ewasm`` output selection options in assembler mode.
|
||||
* Commandline Interface: Support ``--asm``, ``--bin``, ``--ir-optimized``, ``--ewasm`` and ``--ewasm-ir`` output selection options in assembler mode.
|
||||
* Commandline Interface: Use different colors when printing errors, warnings and infos.
|
||||
* SMTChecker: Output values for ``block.*``, ``msg.*`` and ``tx.*`` variables that are present in the called functions.
|
||||
* SMTChecker: Report contract invariants and reentrancy properties. This can be enabled via the CLI option ``--model-checker-invariants`` or the Standard JSON option ``settings.modelChecker.invariants``.
|
||||
|
@ -1055,9 +1055,7 @@ bool CommandLineInterface::assemble(yul::AssemblyStack::Language _language, yul:
|
||||
stack.translate(yul::AssemblyStack::Language::Ewasm);
|
||||
stack.optimize();
|
||||
|
||||
// TODO: This isn't ewasm but it's only present when we're doing Yul->EWASM translation.
|
||||
// It should get its own output flag in the future.
|
||||
if (m_options.compiler.outputs.ewasm)
|
||||
if (m_options.compiler.outputs.ewasmIR)
|
||||
{
|
||||
sout() << endl << "==========================" << endl;
|
||||
sout() << endl << "Translated source:" << endl;
|
||||
|
@ -446,15 +446,17 @@ bool CommandLineParser::parseOutputSelection()
|
||||
{
|
||||
static auto outputSupported = [](InputMode _mode, string_view _outputName)
|
||||
{
|
||||
static set<string> const compilerModeOutputs =
|
||||
static set<string> const compilerModeOutputs = (
|
||||
CompilerOutputs::componentMap() |
|
||||
ranges::views::keys |
|
||||
ranges::to<set>();
|
||||
ranges::to<set>()
|
||||
) - set<string>{CompilerOutputs::componentName(&CompilerOutputs::ewasmIR)};
|
||||
static set<string> const assemblerModeOutputs = {
|
||||
CompilerOutputs::componentName(&CompilerOutputs::asm_),
|
||||
CompilerOutputs::componentName(&CompilerOutputs::binary),
|
||||
CompilerOutputs::componentName(&CompilerOutputs::irOptimized),
|
||||
CompilerOutputs::componentName(&CompilerOutputs::ewasm),
|
||||
CompilerOutputs::componentName(&CompilerOutputs::ewasmIR),
|
||||
};
|
||||
|
||||
switch (_mode)
|
||||
@ -487,6 +489,7 @@ bool CommandLineParser::parseOutputSelection()
|
||||
m_options.compiler.outputs.binary = true;
|
||||
m_options.compiler.outputs.irOptimized = true;
|
||||
m_options.compiler.outputs.ewasm = true;
|
||||
m_options.compiler.outputs.ewasmIR = true;
|
||||
}
|
||||
|
||||
vector<string> unsupportedOutputs;
|
||||
@ -709,6 +712,7 @@ General Information)").c_str(),
|
||||
(CompilerOutputs::componentName(&CompilerOutputs::ir).c_str(), "Intermediate Representation (IR) of all contracts (EXPERIMENTAL).")
|
||||
(CompilerOutputs::componentName(&CompilerOutputs::irOptimized).c_str(), "Optimized intermediate Representation (IR) of all contracts (EXPERIMENTAL).")
|
||||
(CompilerOutputs::componentName(&CompilerOutputs::ewasm).c_str(), "Ewasm text representation of all contracts (EXPERIMENTAL).")
|
||||
(CompilerOutputs::componentName(&CompilerOutputs::ewasmIR).c_str(), "Intermediate representation (IR) converted to a form that can be translated directly into Ewasm text representation (EXPERIMENTAL).")
|
||||
(CompilerOutputs::componentName(&CompilerOutputs::signatureHashes).c_str(), "Function signature hashes of the contracts.")
|
||||
(CompilerOutputs::componentName(&CompilerOutputs::natspecUser).c_str(), "Natspec user documentation of all contracts.")
|
||||
(CompilerOutputs::componentName(&CompilerOutputs::natspecDev).c_str(), "Natspec developer documentation of all contracts.")
|
||||
@ -923,11 +927,12 @@ bool CommandLineParser::processArgs()
|
||||
if (!checkMutuallyExclusive({g_strColor, g_strNoColor}))
|
||||
return false;
|
||||
|
||||
array<string, 8> const conflictingWithStopAfter{
|
||||
array<string, 9> const conflictingWithStopAfter{
|
||||
CompilerOutputs::componentName(&CompilerOutputs::binary),
|
||||
CompilerOutputs::componentName(&CompilerOutputs::ir),
|
||||
CompilerOutputs::componentName(&CompilerOutputs::irOptimized),
|
||||
CompilerOutputs::componentName(&CompilerOutputs::ewasm),
|
||||
CompilerOutputs::componentName(&CompilerOutputs::ewasmIR),
|
||||
g_strGas,
|
||||
CompilerOutputs::componentName(&CompilerOutputs::asm_),
|
||||
CompilerOutputs::componentName(&CompilerOutputs::asmJson),
|
||||
|
@ -78,6 +78,7 @@ struct CompilerOutputs
|
||||
{"ir", &CompilerOutputs::ir},
|
||||
{"ir-optimized", &CompilerOutputs::irOptimized},
|
||||
{"ewasm", &CompilerOutputs::ewasm},
|
||||
{"ewasm-ir", &CompilerOutputs::ewasmIR},
|
||||
{"hashes", &CompilerOutputs::signatureHashes},
|
||||
{"userdoc", &CompilerOutputs::natspecUser},
|
||||
{"devdoc", &CompilerOutputs::natspecDev},
|
||||
@ -97,6 +98,7 @@ struct CompilerOutputs
|
||||
bool ir = false;
|
||||
bool irOptimized = false;
|
||||
bool ewasm = false;
|
||||
bool ewasmIR = false;
|
||||
bool signatureHashes = false;
|
||||
bool natspecUser = false;
|
||||
bool natspecDev = false;
|
||||
|
@ -0,0 +1 @@
|
||||
--assemble --optimize --yul-dialect evm --machine ewasm --ewasm-ir
|
@ -0,0 +1 @@
|
||||
Warning: Yul is still experimental. Please use the output with care.
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
let x := 42
|
||||
sstore(0, x)
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
|
||||
======= evm_to_wasm_output_selection_ewasm_ir_only/input.yul (Ewasm) =======
|
||||
|
||||
==========================
|
||||
|
||||
Translated source:
|
||||
object "object" {
|
||||
code {
|
||||
function main()
|
||||
{
|
||||
let hi := i64.shl(i64.extend_i32_u(bswap32(i32.wrap_i64(0))), 32)
|
||||
let y := i64.or(hi, i64.extend_i32_u(bswap32(i32.wrap_i64(i64.shr_u(0, 32)))))
|
||||
i64.store(0:i32, y)
|
||||
i64.store(i32.add(0:i32, 8:i32), y)
|
||||
i64.store(i32.add(0:i32, 16:i32), y)
|
||||
i64.store(i32.add(0:i32, 24:i32), y)
|
||||
i64.store(32:i32, y)
|
||||
i64.store(i32.add(32:i32, 8:i32), y)
|
||||
i64.store(i32.add(32:i32, 16:i32), y)
|
||||
let hi_1 := i64.shl(i64.extend_i32_u(bswap32(i32.wrap_i64(42))), 32)
|
||||
i64.store(i32.add(32:i32, 24:i32), i64.or(hi_1, i64.extend_i32_u(bswap32(i32.wrap_i64(i64.shr_u(42, 32))))))
|
||||
eth.storageStore(0:i32, 32:i32)
|
||||
}
|
||||
function bswap16(x:i32) -> y:i32
|
||||
{
|
||||
y := i32.or(i32.and(i32.shl(x, 8:i32), 0xff00:i32), i32.and(i32.shr_u(x, 8:i32), 0xff:i32))
|
||||
}
|
||||
function bswap32(x:i32) -> y:i32
|
||||
{
|
||||
let hi:i32 := i32.shl(bswap16(x), 16:i32)
|
||||
y := i32.or(hi, bswap16(i32.shr_u(x, 16:i32)))
|
||||
}
|
||||
}
|
||||
}
|
@ -1,39 +1,6 @@
|
||||
|
||||
======= evm_to_wasm_output_selection_ewasm_only/input.yul (Ewasm) =======
|
||||
|
||||
==========================
|
||||
|
||||
Translated source:
|
||||
object "object" {
|
||||
code {
|
||||
function main()
|
||||
{
|
||||
let hi := i64.shl(i64.extend_i32_u(bswap32(i32.wrap_i64(0))), 32)
|
||||
let y := i64.or(hi, i64.extend_i32_u(bswap32(i32.wrap_i64(i64.shr_u(0, 32)))))
|
||||
i64.store(0:i32, y)
|
||||
i64.store(i32.add(0:i32, 8:i32), y)
|
||||
i64.store(i32.add(0:i32, 16:i32), y)
|
||||
i64.store(i32.add(0:i32, 24:i32), y)
|
||||
i64.store(32:i32, y)
|
||||
i64.store(i32.add(32:i32, 8:i32), y)
|
||||
i64.store(i32.add(32:i32, 16:i32), y)
|
||||
let hi_1 := i64.shl(i64.extend_i32_u(bswap32(i32.wrap_i64(42))), 32)
|
||||
i64.store(i32.add(32:i32, 24:i32), i64.or(hi_1, i64.extend_i32_u(bswap32(i32.wrap_i64(i64.shr_u(42, 32))))))
|
||||
eth.storageStore(0:i32, 32:i32)
|
||||
}
|
||||
function bswap16(x:i32) -> y:i32
|
||||
{
|
||||
y := i32.or(i32.and(i32.shl(x, 8:i32), 0xff00:i32), i32.and(i32.shr_u(x, 8:i32), 0xff:i32))
|
||||
}
|
||||
function bswap32(x:i32) -> y:i32
|
||||
{
|
||||
let hi:i32 := i32.shl(bswap16(x), 16:i32)
|
||||
y := i32.or(hi, bswap16(i32.shr_u(x, 16:i32)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Text representation:
|
||||
(module
|
||||
(import "ethereum" "storageStore" (func $eth.storageStore (param i32 i32)))
|
||||
|
1
test/cmdlineTests/output_selection_ewasm_ir_only/args
Normal file
1
test/cmdlineTests/output_selection_ewasm_ir_only/args
Normal file
@ -0,0 +1 @@
|
||||
--optimize --ewasm-ir
|
1
test/cmdlineTests/output_selection_ewasm_ir_only/err
Normal file
1
test/cmdlineTests/output_selection_ewasm_ir_only/err
Normal file
@ -0,0 +1 @@
|
||||
The following outputs are not supported in compiler mode: --ewasm-ir.
|
1
test/cmdlineTests/output_selection_ewasm_ir_only/exit
Normal file
1
test/cmdlineTests/output_selection_ewasm_ir_only/exit
Normal file
@ -0,0 +1 @@
|
||||
1
|
@ -0,0 +1,4 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
pragma solidity *;
|
||||
|
||||
contract C {}
|
@ -1 +1 @@
|
||||
--ast-compact-json --asm --asm-json --opcodes --bin --bin-runtime --abi --ir --ir-optimized --ewasm --hashes --userdoc --devdoc --metadata --storage-layout
|
||||
--ast-compact-json --asm --asm-json --opcodes --bin --bin-runtime --abi --ir --ir-optimized --ewasm --ewasm-ir --hashes --userdoc --devdoc --metadata --storage-layout
|
||||
|
@ -1 +1 @@
|
||||
The following outputs are not supported in standard JSON mode: --abi, --asm, --asm-json, --ast-compact-json, --bin, --bin-runtime, --devdoc, --ewasm, --hashes, --ir, --ir-optimized, --metadata, --opcodes, --storage-layout, --userdoc.
|
||||
The following outputs are not supported in standard JSON mode: --abi, --asm, --asm-json, --ast-compact-json, --bin, --bin-runtime, --devdoc, --ewasm, --ewasm-ir, --hashes, --ir, --ir-optimized, --metadata, --opcodes, --storage-layout, --userdoc.
|
||||
|
@ -0,0 +1 @@
|
||||
--strict-assembly --optimize --ewasm-ir
|
@ -0,0 +1 @@
|
||||
Warning: Yul is still experimental. Please use the output with care.
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
let x := 42
|
||||
sstore(0, x)
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
|
||||
======= strict_asm_output_selection_ewasm_ir_only/input.yul (EVM) =======
|
@ -198,7 +198,9 @@ BOOST_AUTO_TEST_CASE(cli_mode_options)
|
||||
true, true, true, true, true,
|
||||
true, true, true, true, true,
|
||||
true, true, true, true, true,
|
||||
true,
|
||||
};
|
||||
expectedOptions.compiler.outputs.ewasmIR = false;
|
||||
expectedOptions.compiler.estimateGas = true;
|
||||
expectedOptions.compiler.combinedJsonRequests = {
|
||||
true, true, true, true, true,
|
||||
@ -301,6 +303,7 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options)
|
||||
"--bin",
|
||||
"--ir-optimized",
|
||||
"--ewasm",
|
||||
"--ewasm-ir",
|
||||
};
|
||||
commandLine += assemblyOptions;
|
||||
if (expectedLanguage == AssemblyStack::Language::StrictAssembly || expectedLanguage == AssemblyStack::Language::Ewasm)
|
||||
@ -341,6 +344,7 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options)
|
||||
expectedOptions.compiler.outputs.binary = true;
|
||||
expectedOptions.compiler.outputs.irOptimized = true;
|
||||
expectedOptions.compiler.outputs.ewasm = true;
|
||||
expectedOptions.compiler.outputs.ewasmIR = true;
|
||||
if (expectedLanguage == AssemblyStack::Language::StrictAssembly || expectedLanguage == AssemblyStack::Language::Ewasm)
|
||||
{
|
||||
expectedOptions.optimizer.enabled = true;
|
||||
|
Loading…
Reference in New Issue
Block a user