Skip to content

Commit affeff1

Browse files
committed
Don't ignore output selection in assembly mode
1 parent dd0ff19 commit affeff1

File tree

29 files changed

+213
-16
lines changed

29 files changed

+213
-16
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +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.
1011
* Commandline Interface: Use different colors when printing errors, warnings and infos.
1112
* SMTChecker: Output values for ``block.*``, ``msg.*`` and ``tx.*`` variables that are present in the called functions.
1213
* 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: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,34 +1042,54 @@ bool CommandLineInterface::assemble(yul::AssemblyStack::Language _language, yul:
10421042

10431043
yul::AssemblyStack& stack = assemblyStacks[src.first];
10441044

1045-
sout() << endl << "Pretty printed source:" << endl;
1046-
sout() << stack.print() << endl;
1045+
if (m_options.compiler.outputs.irOptimized)
1046+
{
1047+
// NOTE: This actually outputs unoptimized code when the optimizer is disabled but
1048+
// 'ir' output in StandardCompiler works the same way.
1049+
sout() << endl << "Pretty printed source:" << endl;
1050+
sout() << stack.print() << endl;
1051+
}
10471052

10481053
if (_language != yul::AssemblyStack::Language::Ewasm && _targetMachine == yul::AssemblyStack::Machine::Ewasm)
10491054
{
10501055
stack.translate(yul::AssemblyStack::Language::Ewasm);
10511056
stack.optimize();
10521057

1053-
sout() << endl << "==========================" << endl;
1054-
sout() << endl << "Translated source:" << endl;
1055-
sout() << stack.print() << endl;
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)
1061+
{
1062+
sout() << endl << "==========================" << endl;
1063+
sout() << endl << "Translated source:" << endl;
1064+
sout() << stack.print() << endl;
1065+
}
10561066
}
10571067

10581068
yul::MachineAssemblyObject object;
10591069
object = stack.assemble(_targetMachine);
10601070
object.bytecode->link(m_options.linker.libraries);
10611071

1062-
sout() << endl << "Binary representation:" << endl;
1063-
if (object.bytecode)
1064-
sout() << object.bytecode->toHex() << endl;
1065-
else
1066-
serr() << "No binary representation found." << endl;
1072+
if (m_options.compiler.outputs.binary)
1073+
{
1074+
sout() << endl << "Binary representation:" << endl;
1075+
if (object.bytecode)
1076+
sout() << object.bytecode->toHex() << endl;
1077+
else
1078+
serr() << "No binary representation found." << endl;
1079+
}
10671080

1068-
sout() << endl << "Text representation:" << endl;
1069-
if (!object.assembly.empty())
1070-
sout() << object.assembly << endl;
1071-
else
1072-
serr() << "No text representation found." << endl;
1081+
solAssert(_targetMachine == yul::AssemblyStack::Machine::Ewasm || _targetMachine == yul::AssemblyStack::Machine::EVM, "");
1082+
if (
1083+
(_targetMachine == yul::AssemblyStack::Machine::EVM && m_options.compiler.outputs.asm_) ||
1084+
(_targetMachine == yul::AssemblyStack::Machine::Ewasm && m_options.compiler.outputs.ewasm)
1085+
)
1086+
{
1087+
sout() << endl << "Text representation:" << endl;
1088+
if (!object.assembly.empty())
1089+
sout() << object.assembly << endl;
1090+
else
1091+
serr() << "No text representation found." << endl;
1092+
}
10731093
}
10741094

10751095
return true;

solc/CommandLineParser.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,12 @@ bool CommandLineParser::parseOutputSelection()
450450
CompilerOutputs::componentMap() |
451451
ranges::views::keys |
452452
ranges::to<set>();
453+
static set<string> const assemblerModeOutputs = {
454+
CompilerOutputs::componentName(&CompilerOutputs::asm_),
455+
CompilerOutputs::componentName(&CompilerOutputs::binary),
456+
CompilerOutputs::componentName(&CompilerOutputs::irOptimized),
457+
CompilerOutputs::componentName(&CompilerOutputs::ewasm),
458+
};
453459

454460
switch (_mode)
455461
{
@@ -461,6 +467,7 @@ bool CommandLineParser::parseOutputSelection()
461467
case InputMode::CompilerWithASTImport:
462468
return contains(compilerModeOutputs, _outputName);
463469
case InputMode::Assembler:
470+
return contains(assemblerModeOutputs, _outputName);
464471
case InputMode::StandardJson:
465472
case InputMode::Linker:
466473
return false;
@@ -472,6 +479,16 @@ bool CommandLineParser::parseOutputSelection()
472479
for (auto&& [optionName, outputComponent]: CompilerOutputs::componentMap())
473480
m_options.compiler.outputs.*outputComponent = (m_args.count(optionName) > 0);
474481

482+
if (m_options.input.mode == InputMode::Assembler && m_options.compiler.outputs == CompilerOutputs{})
483+
{
484+
// In assembly mode keep the default outputs enabled for backwards-compatibility.
485+
// TODO: Remove this (must be done in a breaking release).
486+
m_options.compiler.outputs.asm_ = true;
487+
m_options.compiler.outputs.binary = true;
488+
m_options.compiler.outputs.irOptimized = true;
489+
m_options.compiler.outputs.ewasm = true;
490+
}
491+
475492
vector<string> unsupportedOutputs;
476493
for (auto&& [optionName, outputComponent]: CompilerOutputs::componentMap())
477494
if (m_options.compiler.outputs.*outputComponent && !outputSupported(m_options.input.mode, optionName))
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 --asm
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
======= evm_to_wasm_output_selection_asm_only/input.yul (Ewasm) =======
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
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+
}

0 commit comments

Comments
 (0)