Skip to content

Commit dd0f837

Browse files
committed
Don't ignore output selection in assembly mode
1 parent cd22574 commit dd0f837

File tree

30 files changed

+211
-17
lines changed

30 files changed

+211
-17
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Language Features:
66

77
Compiler Features:
88
* Commandline Interface: Accept nested brackets in step sequences passed to ``--yul-optimizations``.
9+
* Commandline Interface: Support ``--asm``, ``--bin``, ``--ir-optimized`` and ``--ewasm`` output selection options in assembler mode.
910
* SMTChecker: Output values for ``block.*``, ``msg.*`` and ``tx.*`` variables that are present in the called functions.
1011
* Standard JSON: Accept nested brackets in step sequences passed to ``settings.optimizer.details.yulDetails.optimizerSteps``.
1112

solc/CommandLineInterface.cpp

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

10081008
yul::AssemblyStack& stack = assemblyStacks[src.first];
10091009

1010-
sout() << endl << "Pretty printed source:" << endl;
1011-
sout() << stack.print() << endl;
1010+
if (m_options.compiler.outputs.irOptimized)
1011+
{
1012+
// NOTE: This actually outputs unoptimized code when the optimizer is disabled but
1013+
// 'ir' output in StandardCompiler works the same way.
1014+
sout() << endl << "Pretty printed source:" << endl;
1015+
sout() << stack.print() << endl;
1016+
}
10121017

10131018
if (_language != yul::AssemblyStack::Language::Ewasm && _targetMachine == yul::AssemblyStack::Machine::Ewasm)
10141019
{
10151020
stack.translate(yul::AssemblyStack::Language::Ewasm);
10161021
stack.optimize();
10171022

1018-
sout() << endl << "==========================" << endl;
1019-
sout() << endl << "Translated source:" << endl;
1020-
sout() << stack.print() << endl;
1023+
// TODO: This isn't ewasm but it's only present when we're doing Yul->EWASM translation.
1024+
// It should get its own output flag in the future.
1025+
if (m_options.compiler.outputs.ewasm)
1026+
{
1027+
sout() << endl << "==========================" << endl;
1028+
sout() << endl << "Translated source:" << endl;
1029+
sout() << stack.print() << endl;
1030+
}
10211031
}
10221032

10231033
yul::MachineAssemblyObject object;
10241034
object = stack.assemble(_targetMachine);
10251035
object.bytecode->link(m_options.linker.libraries);
10261036

1027-
sout() << endl << "Binary representation:" << endl;
1028-
if (object.bytecode)
1029-
sout() << object.bytecode->toHex() << endl;
1030-
else
1031-
serr() << "No binary representation found." << endl;
1037+
if (m_options.compiler.outputs.binary)
1038+
{
1039+
sout() << endl << "Binary representation:" << endl;
1040+
if (object.bytecode)
1041+
sout() << object.bytecode->toHex() << endl;
1042+
else
1043+
serr() << "No binary representation found." << endl;
1044+
}
10321045

1033-
sout() << endl << "Text representation:" << endl;
1034-
if (!object.assembly.empty())
1035-
sout() << object.assembly << endl;
1036-
else
1037-
serr() << "No text representation found." << endl;
1046+
solAssert(_targetMachine == yul::AssemblyStack::Machine::Ewasm || _targetMachine == yul::AssemblyStack::Machine::EVM, "");
1047+
if (
1048+
(_targetMachine == yul::AssemblyStack::Machine::EVM && m_options.compiler.outputs.asm_) ||
1049+
(_targetMachine == yul::AssemblyStack::Machine::Ewasm && m_options.compiler.outputs.ewasm)
1050+
)
1051+
{
1052+
sout() << endl << "Text representation:" << endl;
1053+
if (!object.assembly.empty())
1054+
sout() << object.assembly << endl;
1055+
else
1056+
serr() << "No text representation found." << endl;
1057+
}
10381058
}
10391059

10401060
return true;

solc/CommandLineParser.cpp

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

480486
switch (_mode)
481487
{
482488
case InputMode::Compiler:
483489
case InputMode::CompilerWithASTImport:
484490
return contains(compilerModeOutputs, _outputName);
485491
case InputMode::Assembler:
492+
return contains(assemblerModeOutputs,_outputName);
486493
case InputMode::StandardJson:
487494
case InputMode::Linker:
488495
return false;
@@ -494,6 +501,16 @@ bool CommandLineParser::parseOutputSelection()
494501
for (auto&& [optionName, outputComponent]: CompilerOutputs::componentMap())
495502
m_options.compiler.outputs.*outputComponent = (m_args.count(optionName) > 0);
496503

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