Skip to content

Commit 1a19d9a

Browse files
committed
New CLI output in assembly mode: --ewasm-ir
1 parent affeff1 commit 1a19d9a

File tree

20 files changed

+73
-42
lines changed

20 files changed

+73
-42
lines changed

Changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Language Features:
77
Compiler Features:
88
* Commandline Interface: Accept nested brackets in step sequences passed to ``--yul-optimizations``.
99
* Commandline Interface: Add ``--debug-info`` option for selecting how much extra debug information should be included in the produced EVM assembly and Yul code.
10-
* Commandline Interface: Support ``--asm``, ``--bin``, ``--ir-optimized`` and ``--ewasm`` output selection options in assembler mode.
10+
* Commandline Interface: Support ``--asm``, ``--bin``, ``--ir-optimized``, ``--ewasm`` and ``--ewasm-ir`` output selection options in assembler mode.
1111
* Commandline Interface: Use different colors when printing errors, warnings and infos.
1212
* SMTChecker: Output values for ``block.*``, ``msg.*`` and ``tx.*`` variables that are present in the called functions.
1313
* 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``.

solc/CommandLineInterface.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,9 +1055,7 @@ bool CommandLineInterface::assemble(yul::AssemblyStack::Language _language, yul:
10551055
stack.translate(yul::AssemblyStack::Language::Ewasm);
10561056
stack.optimize();
10571057

1058-
// TODO: This isn't ewasm but it's only present when we're doing Yul->EWASM translation.
1059-
// It should get its own output flag in the future.
1060-
if (m_options.compiler.outputs.ewasm)
1058+
if (m_options.compiler.outputs.ewasmIR)
10611059
{
10621060
sout() << endl << "==========================" << endl;
10631061
sout() << endl << "Translated source:" << endl;

solc/CommandLineParser.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,17 @@ bool CommandLineParser::parseOutputSelection()
446446
{
447447
static auto outputSupported = [](InputMode _mode, string_view _outputName)
448448
{
449-
static set<string> const compilerModeOutputs =
449+
static set<string> const compilerModeOutputs = (
450450
CompilerOutputs::componentMap() |
451451
ranges::views::keys |
452-
ranges::to<set>();
452+
ranges::to<set>()
453+
) - set<string>{CompilerOutputs::componentName(&CompilerOutputs::ewasmIR)};
453454
static set<string> const assemblerModeOutputs = {
454455
CompilerOutputs::componentName(&CompilerOutputs::asm_),
455456
CompilerOutputs::componentName(&CompilerOutputs::binary),
456457
CompilerOutputs::componentName(&CompilerOutputs::irOptimized),
457458
CompilerOutputs::componentName(&CompilerOutputs::ewasm),
459+
CompilerOutputs::componentName(&CompilerOutputs::ewasmIR),
458460
};
459461

460462
switch (_mode)
@@ -487,6 +489,7 @@ bool CommandLineParser::parseOutputSelection()
487489
m_options.compiler.outputs.binary = true;
488490
m_options.compiler.outputs.irOptimized = true;
489491
m_options.compiler.outputs.ewasm = true;
492+
m_options.compiler.outputs.ewasmIR = true;
490493
}
491494

492495
vector<string> unsupportedOutputs;
@@ -709,6 +712,7 @@ General Information)").c_str(),
709712
(CompilerOutputs::componentName(&CompilerOutputs::ir).c_str(), "Intermediate Representation (IR) of all contracts (EXPERIMENTAL).")
710713
(CompilerOutputs::componentName(&CompilerOutputs::irOptimized).c_str(), "Optimized intermediate Representation (IR) of all contracts (EXPERIMENTAL).")
711714
(CompilerOutputs::componentName(&CompilerOutputs::ewasm).c_str(), "Ewasm text representation of all contracts (EXPERIMENTAL).")
715+
(CompilerOutputs::componentName(&CompilerOutputs::ewasmIR).c_str(), "Intermediate representation (IR) converted to a form that can be translated directly into Ewasm text representation (EXPERIMENTAL).")
712716
(CompilerOutputs::componentName(&CompilerOutputs::signatureHashes).c_str(), "Function signature hashes of the contracts.")
713717
(CompilerOutputs::componentName(&CompilerOutputs::natspecUser).c_str(), "Natspec user documentation of all contracts.")
714718
(CompilerOutputs::componentName(&CompilerOutputs::natspecDev).c_str(), "Natspec developer documentation of all contracts.")
@@ -923,11 +927,12 @@ bool CommandLineParser::processArgs()
923927
if (!checkMutuallyExclusive({g_strColor, g_strNoColor}))
924928
return false;
925929

926-
array<string, 8> const conflictingWithStopAfter{
930+
array<string, 9> const conflictingWithStopAfter{
927931
CompilerOutputs::componentName(&CompilerOutputs::binary),
928932
CompilerOutputs::componentName(&CompilerOutputs::ir),
929933
CompilerOutputs::componentName(&CompilerOutputs::irOptimized),
930934
CompilerOutputs::componentName(&CompilerOutputs::ewasm),
935+
CompilerOutputs::componentName(&CompilerOutputs::ewasmIR),
931936
g_strGas,
932937
CompilerOutputs::componentName(&CompilerOutputs::asm_),
933938
CompilerOutputs::componentName(&CompilerOutputs::asmJson),

solc/CommandLineParser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct CompilerOutputs
7878
{"ir", &CompilerOutputs::ir},
7979
{"ir-optimized", &CompilerOutputs::irOptimized},
8080
{"ewasm", &CompilerOutputs::ewasm},
81+
{"ewasm-ir", &CompilerOutputs::ewasmIR},
8182
{"hashes", &CompilerOutputs::signatureHashes},
8283
{"userdoc", &CompilerOutputs::natspecUser},
8384
{"devdoc", &CompilerOutputs::natspecDev},
@@ -97,6 +98,7 @@ struct CompilerOutputs
9798
bool ir = false;
9899
bool irOptimized = false;
99100
bool ewasm = false;
101+
bool ewasmIR = false;
100102
bool signatureHashes = false;
101103
bool natspecUser = false;
102104
bool natspecDev = false;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--assemble --optimize --yul-dialect evm --machine ewasm --ewasm-ir
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Warning: Yul is still experimental. Please use the output with care.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
let x := 42
3+
sstore(0, x)
4+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
======= evm_to_wasm_output_selection_ewasm_ir_only/input.yul (Ewasm) =======
3+
4+
==========================
5+
6+
Translated source:
7+
object "object" {
8+
code {
9+
function main()
10+
{
11+
let hi := i64.shl(i64.extend_i32_u(bswap32(i32.wrap_i64(0))), 32)
12+
let y := i64.or(hi, i64.extend_i32_u(bswap32(i32.wrap_i64(i64.shr_u(0, 32)))))
13+
i64.store(0:i32, y)
14+
i64.store(i32.add(0:i32, 8:i32), y)
15+
i64.store(i32.add(0:i32, 16:i32), y)
16+
i64.store(i32.add(0:i32, 24:i32), y)
17+
i64.store(32:i32, y)
18+
i64.store(i32.add(32:i32, 8:i32), y)
19+
i64.store(i32.add(32:i32, 16:i32), y)
20+
let hi_1 := i64.shl(i64.extend_i32_u(bswap32(i32.wrap_i64(42))), 32)
21+
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))))))
22+
eth.storageStore(0:i32, 32:i32)
23+
}
24+
function bswap16(x:i32) -> y:i32
25+
{
26+
y := i32.or(i32.and(i32.shl(x, 8:i32), 0xff00:i32), i32.and(i32.shr_u(x, 8:i32), 0xff:i32))
27+
}
28+
function bswap32(x:i32) -> y:i32
29+
{
30+
let hi:i32 := i32.shl(bswap16(x), 16:i32)
31+
y := i32.or(hi, bswap16(i32.shr_u(x, 16:i32)))
32+
}
33+
}
34+
}

test/cmdlineTests/evm_to_wasm_output_selection_ewasm_only/output

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,6 @@
11

22
======= evm_to_wasm_output_selection_ewasm_only/input.yul (Ewasm) =======
33

4-
==========================
5-
6-
Translated source:
7-
object "object" {
8-
code {
9-
function main()
10-
{
11-
let hi := i64.shl(i64.extend_i32_u(bswap32(i32.wrap_i64(0))), 32)
12-
let y := i64.or(hi, i64.extend_i32_u(bswap32(i32.wrap_i64(i64.shr_u(0, 32)))))
13-
i64.store(0:i32, y)
14-
i64.store(i32.add(0:i32, 8:i32), y)
15-
i64.store(i32.add(0:i32, 16:i32), y)
16-
i64.store(i32.add(0:i32, 24:i32), y)
17-
i64.store(32:i32, y)
18-
i64.store(i32.add(32:i32, 8:i32), y)
19-
i64.store(i32.add(32:i32, 16:i32), y)
20-
let hi_1 := i64.shl(i64.extend_i32_u(bswap32(i32.wrap_i64(42))), 32)
21-
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))))))
22-
eth.storageStore(0:i32, 32:i32)
23-
}
24-
function bswap16(x:i32) -> y:i32
25-
{
26-
y := i32.or(i32.and(i32.shl(x, 8:i32), 0xff00:i32), i32.and(i32.shr_u(x, 8:i32), 0xff:i32))
27-
}
28-
function bswap32(x:i32) -> y:i32
29-
{
30-
let hi:i32 := i32.shl(bswap16(x), 16:i32)
31-
y := i32.or(hi, bswap16(i32.shr_u(x, 16:i32)))
32-
}
33-
}
34-
}
35-
36-
374
Text representation:
385
(module
396
(import "ethereum" "storageStore" (func $eth.storageStore (param i32 i32)))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--optimize --ewasm-ir

0 commit comments

Comments
 (0)