Skip to content

Commit 7f3bba0

Browse files
committed
Don't ignore output selection in assembly mode
1 parent 1e630fc commit 7f3bba0

File tree

29 files changed

+211
-16
lines changed

29 files changed

+211
-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
* SMTChecker: Output values for ``block.*``, ``msg.*`` and ``tx.*`` variables that are present in the called functions.
1112
* Standard JSON: Accept nested brackets in step sequences passed to ``settings.optimizer.details.yulDetails.optimizerSteps``.
1213
* Standard JSON: Add ``settings.debug.debugInfo`` option for selecting how much extra debug information should be included in the produced EVM assembly and Yul code.

solc/CommandLineInterface.cpp

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,34 +1013,54 @@ bool CommandLineInterface::assemble(yul::AssemblyStack::Language _language, yul:
10131013

10141014
yul::AssemblyStack& stack = assemblyStacks[src.first];
10151015

1016-
sout() << endl << "Pretty printed source:" << endl;
1017-
sout() << stack.print() << endl;
1016+
if (m_options.compiler.outputs.irOptimized)
1017+
{
1018+
// NOTE: This actually outputs unoptimized code when the optimizer is disabled but
1019+
// 'ir' output in StandardCompiler works the same way.
1020+
sout() << endl << "Pretty printed source:" << endl;
1021+
sout() << stack.print() << endl;
1022+
}
10181023

10191024
if (_language != yul::AssemblyStack::Language::Ewasm && _targetMachine == yul::AssemblyStack::Machine::Ewasm)
10201025
{
10211026
stack.translate(yul::AssemblyStack::Language::Ewasm);
10221027
stack.optimize();
10231028

1024-
sout() << endl << "==========================" << endl;
1025-
sout() << endl << "Translated source:" << endl;
1026-
sout() << stack.print() << endl;
1029+
// TODO: This isn't ewasm but it's only present when we're doing Yul->EWASM translation.
1030+
// It should get its own output flag in the future.
1031+
if (m_options.compiler.outputs.ewasm)
1032+
{
1033+
sout() << endl << "==========================" << endl;
1034+
sout() << endl << "Translated source:" << endl;
1035+
sout() << stack.print() << endl;
1036+
}
10271037
}
10281038

10291039
yul::MachineAssemblyObject object;
10301040
object = stack.assemble(_targetMachine);
10311041
object.bytecode->link(m_options.linker.libraries);
10321042

1033-
sout() << endl << "Binary representation:" << endl;
1034-
if (object.bytecode)
1035-
sout() << object.bytecode->toHex() << endl;
1036-
else
1037-
serr() << "No binary representation found." << endl;
1043+
if (m_options.compiler.outputs.binary)
1044+
{
1045+
sout() << endl << "Binary representation:" << endl;
1046+
if (object.bytecode)
1047+
sout() << object.bytecode->toHex() << endl;
1048+
else
1049+
serr() << "No binary representation found." << endl;
1050+
}
10381051

1039-
sout() << endl << "Text representation:" << endl;
1040-
if (!object.assembly.empty())
1041-
sout() << object.assembly << endl;
1042-
else
1043-
serr() << "No text representation found." << endl;
1052+
solAssert(_targetMachine == yul::AssemblyStack::Machine::Ewasm || _targetMachine == yul::AssemblyStack::Machine::EVM, "");
1053+
if (
1054+
(_targetMachine == yul::AssemblyStack::Machine::EVM && m_options.compiler.outputs.asm_) ||
1055+
(_targetMachine == yul::AssemblyStack::Machine::Ewasm && m_options.compiler.outputs.ewasm)
1056+
)
1057+
{
1058+
sout() << endl << "Text representation:" << endl;
1059+
if (!object.assembly.empty())
1060+
sout() << object.assembly << endl;
1061+
else
1062+
serr() << "No text representation found." << endl;
1063+
}
10441064
}
10451065

10461066
return true;

solc/CommandLineParser.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,20 @@ bool CommandLineParser::parseOutputSelection()
478478
CompilerOutputs::componentMap() |
479479
ranges::views::keys |
480480
ranges::to<set>();
481+
static set<string> const assemblerModeOutputs = {
482+
CompilerOutputs::componentName(&CompilerOutputs::asm_),
483+
CompilerOutputs::componentName(&CompilerOutputs::binary),
484+
CompilerOutputs::componentName(&CompilerOutputs::irOptimized),
485+
CompilerOutputs::componentName(&CompilerOutputs::ewasm),
486+
};
481487

482488
switch (_mode)
483489
{
484490
case InputMode::Compiler:
485491
case InputMode::CompilerWithASTImport:
486492
return contains(compilerModeOutputs, _outputName);
487493
case InputMode::Assembler:
494+
return contains(assemblerModeOutputs,_outputName);
488495
case InputMode::StandardJson:
489496
case InputMode::Linker:
490497
return false;
@@ -496,6 +503,16 @@ bool CommandLineParser::parseOutputSelection()
496503
for (auto&& [optionName, outputComponent]: CompilerOutputs::componentMap())
497504
m_options.compiler.outputs.*outputComponent = (m_args.count(optionName) > 0);
498505

506+
if (m_options.input.mode == InputMode::Assembler && m_options.compiler.outputs == CompilerOutputs{})
507+
{
508+
// In assembly mode keep the default outputs enabled for backwards-compatibility.
509+
// TODO: Remove this (must be done in a breaking release).
510+
m_options.compiler.outputs.asm_ = true;
511+
m_options.compiler.outputs.binary = true;
512+
m_options.compiler.outputs.irOptimized = true;
513+
m_options.compiler.outputs.ewasm = true;
514+
}
515+
499516
vector<string> unsupportedOutputs;
500517
for (auto&& [optionName, outputComponent]: CompilerOutputs::componentMap())
501518
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)