Remove YulStack::Machine enum.

This commit is contained in:
Alexander Arlt 2023-02-23 12:04:41 -05:00
parent 14d2ae2dfa
commit 206a2c183f
13 changed files with 31 additions and 70 deletions

View File

@ -171,20 +171,14 @@ void YulStack::optimize(Object& _object, bool _isCreation)
); );
} }
MachineAssemblyObject YulStack::assemble(Machine _machine) const MachineAssemblyObject YulStack::assemble() const
{ {
yulAssert(m_analysisSuccessful, ""); yulAssert(m_analysisSuccessful, "");
yulAssert(m_parserResult, ""); yulAssert(m_parserResult, "");
yulAssert(m_parserResult->code, ""); yulAssert(m_parserResult->code, "");
yulAssert(m_parserResult->analysisInfo, ""); yulAssert(m_parserResult->analysisInfo, "");
switch (_machine)
{
case Machine::EVM:
return assembleWithDeployed().first; return assembleWithDeployed().first;
}
// unreachable
return MachineAssemblyObject();
} }
std::pair<MachineAssemblyObject, MachineAssemblyObject> std::pair<MachineAssemblyObject, MachineAssemblyObject>

View File

@ -67,7 +67,6 @@ class YulStack: public langutil::CharStreamProvider
{ {
public: public:
enum class Language { Yul, Assembly, StrictAssembly }; enum class Language { Yul, Assembly, StrictAssembly };
enum class Machine { EVM };
YulStack(): YulStack():
YulStack( YulStack(
@ -106,7 +105,7 @@ public:
void optimize(); void optimize();
/// Run the assembly step (should only be called after parseAndAnalyze). /// Run the assembly step (should only be called after parseAndAnalyze).
MachineAssemblyObject assemble(Machine _machine) const; MachineAssemblyObject assemble() const;
/// Run the assembly step (should only be called after parseAndAnalyze). /// Run the assembly step (should only be called after parseAndAnalyze).
/// In addition to the value returned by @a assemble, returns /// In addition to the value returned by @a assemble, returns

View File

@ -691,7 +691,7 @@ void CommandLineInterface::processInput()
serveLSP(); serveLSP();
break; break;
case InputMode::Assembler: case InputMode::Assembler:
assembleYul(m_options.assembly.inputLanguage, m_options.assembly.targetMachine); assembleYul(m_options.assembly.inputLanguage);
break; break;
case InputMode::Linker: case InputMode::Linker:
link(); link();
@ -1066,7 +1066,7 @@ string CommandLineInterface::objectWithLinkRefsHex(evmasm::LinkerObject const& _
return out; return out;
} }
void CommandLineInterface::assembleYul(yul::YulStack::Language _language, yul::YulStack::Machine _targetMachine) void CommandLineInterface::assembleYul(yul::YulStack::Language _language)
{ {
solAssert(m_options.input.mode == InputMode::Assembler); solAssert(m_options.input.mode == InputMode::Assembler);
@ -1115,7 +1115,6 @@ void CommandLineInterface::assembleYul(yul::YulStack::Language _language, yul::Y
for (auto const& src: m_fileReader.sourceUnits()) for (auto const& src: m_fileReader.sourceUnits())
{ {
solAssert(_targetMachine == yul::YulStack::Machine::EVM);
string machine = "EVM"; string machine = "EVM";
sout() << endl << "======= " << src.first << " (" << machine << ") =======" << endl; sout() << endl << "======= " << src.first << " (" << machine << ") =======" << endl;
@ -1130,7 +1129,7 @@ void CommandLineInterface::assembleYul(yul::YulStack::Language _language, yul::Y
} }
yul::MachineAssemblyObject object; yul::MachineAssemblyObject object;
object = stack.assemble(_targetMachine); object = stack.assemble();
object.bytecode->link(m_options.linker.libraries); object.bytecode->link(m_options.linker.libraries);
if (m_options.compiler.outputs.binary) if (m_options.compiler.outputs.binary)
@ -1141,12 +1140,12 @@ void CommandLineInterface::assembleYul(yul::YulStack::Language _language, yul::Y
else else
serr() << "No binary representation found." << endl; serr() << "No binary representation found." << endl;
} }
if (m_options.compiler.outputs.astCompactJson) if (m_options.compiler.outputs.astCompactJson)
{ {
sout() << "AST:" << endl << endl; sout() << "AST:" << endl << endl;
sout() << util::jsonPrint(stack.astJson(), m_options.formatting.json) << endl; sout() << util::jsonPrint(stack.astJson(), m_options.formatting.json) << endl;
} }
solAssert(_targetMachine == yul::YulStack::Machine::EVM, "");
if (m_options.compiler.outputs.asm_) if (m_options.compiler.outputs.asm_)
{ {
sout() << endl << "Text representation:" << endl; sout() << endl << "Text representation:" << endl;

View File

@ -92,7 +92,7 @@ private:
/// @returns the full object with library placeholder hints in hex. /// @returns the full object with library placeholder hints in hex.
static std::string objectWithLinkRefsHex(evmasm::LinkerObject const& _obj); static std::string objectWithLinkRefsHex(evmasm::LinkerObject const& _obj);
void assembleYul(yul::YulStack::Language _language, yul::YulStack::Machine _targetMachine); void assembleYul(yul::YulStack::Language _language);
void outputCompilationResults(); void outputCompilationResults();

View File

@ -61,7 +61,6 @@ static string const g_strLicense = "license";
static string const g_strLibraries = "libraries"; static string const g_strLibraries = "libraries";
static string const g_strLink = "link"; static string const g_strLink = "link";
static string const g_strLSP = "lsp"; static string const g_strLSP = "lsp";
static string const g_strMachine = "machine";
static string const g_strNoCBORMetadata = "no-cbor-metadata"; static string const g_strNoCBORMetadata = "no-cbor-metadata";
static string const g_strMetadataHash = "metadata-hash"; static string const g_strMetadataHash = "metadata-hash";
static string const g_strMetadataLiteral = "metadata-literal"; static string const g_strMetadataLiteral = "metadata-literal";
@ -110,12 +109,6 @@ static string const g_strColor = "color";
static string const g_strNoColor = "no-color"; static string const g_strNoColor = "no-color";
static string const g_strErrorIds = "error-codes"; static string const g_strErrorIds = "error-codes";
/// Possible arguments to for --machine
static set<string> const g_machineArgs
{
g_strEVM
};
/// Possible arguments to for --yul-dialect /// Possible arguments to for --yul-dialect
static set<string> const g_yulDialectArgs static set<string> const g_yulDialectArgs
{ {
@ -234,7 +227,6 @@ bool CommandLineOptions::operator==(CommandLineOptions const& _other) const noex
output.stopAfter == _other.output.stopAfter && output.stopAfter == _other.output.stopAfter &&
output.eofVersion == _other.output.eofVersion && output.eofVersion == _other.output.eofVersion &&
input.mode == _other.input.mode && input.mode == _other.input.mode &&
assembly.targetMachine == _other.assembly.targetMachine &&
assembly.inputLanguage == _other.assembly.inputLanguage && assembly.inputLanguage == _other.assembly.inputLanguage &&
linker.libraries == _other.linker.libraries && linker.libraries == _other.linker.libraries &&
formatting.json == _other.formatting.json && formatting.json == _other.formatting.json &&
@ -644,19 +636,19 @@ General Information)").c_str(),
( (
g_strAssemble.c_str(), g_strAssemble.c_str(),
("Switch to assembly mode, ignoring all options except " ("Switch to assembly mode, ignoring all options except "
"--" + g_strMachine + ", --" + g_strYulDialect + ", --" + g_strOptimize + " and --" + g_strYulOptimizations + " " "--" + g_strYulDialect + ", --" + g_strOptimize + " and --" + g_strYulOptimizations + " "
"and assumes input is assembly.").c_str() "and assumes input is assembly.").c_str()
) )
( (
g_strYul.c_str(), g_strYul.c_str(),
("Switch to Yul mode, ignoring all options except " ("Switch to Yul mode, ignoring all options except "
"--" + g_strMachine + ", --" + g_strYulDialect + ", --" + g_strOptimize + " and --" + g_strYulOptimizations + " " "--" + g_strYulDialect + ", --" + g_strOptimize + " and --" + g_strYulOptimizations + " "
"and assumes input is Yul.").c_str() "and assumes input is Yul.").c_str()
) )
( (
g_strStrictAssembly.c_str(), g_strStrictAssembly.c_str(),
("Switch to strict assembly mode, ignoring all options except " ("Switch to strict assembly mode, ignoring all options except "
"--" + g_strMachine + ", --" + g_strYulDialect + ", --" + g_strOptimize + " and --" + g_strYulOptimizations + " " "--" + g_strYulDialect + ", --" + g_strOptimize + " and --" + g_strYulOptimizations + " "
"and assumes input is strict assembly.").c_str() "and assumes input is strict assembly.").c_str()
) )
( (
@ -675,11 +667,6 @@ General Information)").c_str(),
po::options_description assemblyModeOptions("Assembly Mode Options"); po::options_description assemblyModeOptions("Assembly Mode Options");
assemblyModeOptions.add_options() assemblyModeOptions.add_options()
(
g_strMachine.c_str(),
po::value<string>()->value_name(util::joinHumanReadable(g_machineArgs, ",")),
"Target machine in assembly or Yul mode."
)
( (
g_strYulDialect.c_str(), g_strYulDialect.c_str(),
po::value<string>()->value_name(util::joinHumanReadable(g_yulDialectArgs, ",")), po::value<string>()->value_name(util::joinHumanReadable(g_yulDialectArgs, ",")),
@ -1208,17 +1195,8 @@ void CommandLineParser::processArgs()
// switch to assembly mode // switch to assembly mode
using Input = yul::YulStack::Language; using Input = yul::YulStack::Language;
using Machine = yul::YulStack::Machine;
m_options.assembly.inputLanguage = m_args.count(g_strYul) ? Input::Yul : (m_args.count(g_strStrictAssembly) ? Input::StrictAssembly : Input::Assembly); m_options.assembly.inputLanguage = m_args.count(g_strYul) ? Input::Yul : (m_args.count(g_strStrictAssembly) ? Input::StrictAssembly : Input::Assembly);
if (m_args.count(g_strMachine))
{
string machine = m_args[g_strMachine].as<string>();
if (machine == g_strEVM)
m_options.assembly.targetMachine = Machine::EVM;
else
solThrow(CommandLineValidationError, "Invalid option for --" + g_strMachine + ": " + machine);
}
if (m_args.count(g_strYulDialect)) if (m_args.count(g_strYulDialect))
{ {
string dialect = m_args[g_strYulDialect].as<string>(); string dialect = m_args[g_strYulDialect].as<string>();
@ -1234,10 +1212,10 @@ void CommandLineParser::processArgs()
); );
return; return;
} }
else if (countEnabledOptions({g_strYulDialect, g_strMachine}) >= 1) else if (countEnabledOptions({g_strYulDialect}) >= 1)
solThrow( solThrow(
CommandLineValidationError, CommandLineValidationError,
"--" + g_strYulDialect + " and --" + g_strMachine + " are only valid in assembly mode." "--" + g_strYulDialect + " is only valid in assembly mode."
); );
if (m_args.count(g_strMetadataHash)) if (m_args.count(g_strMetadataHash))

View File

@ -191,7 +191,6 @@ struct CommandLineOptions
struct struct
{ {
yul::YulStack::Machine targetMachine = yul::YulStack::Machine::EVM;
yul::YulStack::Language inputLanguage = yul::YulStack::Language::StrictAssembly; yul::YulStack::Language inputLanguage = yul::YulStack::Language::StrictAssembly;
} assembly; } assembly;

View File

@ -1 +1 @@
--yul-dialect evm --machine evm --yul-dialect evm

View File

@ -1 +1 @@
--yul-dialect and --machine are only valid in assembly mode. --yul-dialect is only valid in assembly mode.

View File

@ -56,8 +56,7 @@ std::optional<Error> parseAndReturnFirstError(
string const& _source, string const& _source,
bool _assemble = false, bool _assemble = false,
bool _allowWarnings = true, bool _allowWarnings = true,
YulStack::Language _language = YulStack::Language::Assembly, YulStack::Language _language = YulStack::Language::Assembly
YulStack::Machine _machine = YulStack::Machine::EVM
) )
{ {
YulStack stack( YulStack stack(
@ -72,7 +71,7 @@ std::optional<Error> parseAndReturnFirstError(
{ {
success = stack.parseAndAnalyze("", _source); success = stack.parseAndAnalyze("", _source);
if (success && _assemble) if (success && _assemble)
stack.assemble(_machine); stack.assemble();
} }
catch (FatalError const&) catch (FatalError const&)
{ {
@ -104,17 +103,15 @@ bool successParse(
string const& _source, string const& _source,
bool _assemble = false, bool _assemble = false,
bool _allowWarnings = true, bool _allowWarnings = true,
YulStack::Language _language = YulStack::Language::Assembly, YulStack::Language _language = YulStack::Language::Assembly
YulStack::Machine _machine = YulStack::Machine::EVM
) )
{ {
return !parseAndReturnFirstError(_source, _assemble, _allowWarnings, _language, _machine); return !parseAndReturnFirstError(_source, _assemble, _allowWarnings, _language);
} }
bool successAssemble(string const& _source, bool _allowWarnings = true, YulStack::Language _language = YulStack::Language::Assembly) bool successAssemble(string const& _source, bool _allowWarnings = true, YulStack::Language _language = YulStack::Language::Assembly)
{ {
return return successParse(_source, true, _allowWarnings, _language);
successParse(_source, true, _allowWarnings, _language, YulStack::Machine::EVM);
} }
Error expectError( Error expectError(
@ -124,7 +121,6 @@ Error expectError(
YulStack::Language _language = YulStack::Language::Assembly YulStack::Language _language = YulStack::Language::Assembly
) )
{ {
auto error = parseAndReturnFirstError(_source, _assemble, _allowWarnings, _language); auto error = parseAndReturnFirstError(_source, _assemble, _allowWarnings, _language);
BOOST_REQUIRE(error); BOOST_REQUIRE(error);
return *error; return *error;

View File

@ -109,7 +109,7 @@ bytes SolidityExecutionFramework::multiSourceCompileContract(
try try
{ {
asmStack.optimize(); asmStack.optimize();
obj = std::move(*asmStack.assemble(yul::YulStack::Machine::EVM).bytecode); obj = std::move(*asmStack.assemble().bytecode);
obj.link(_libraryAddresses); obj.link(_libraryAddresses);
break; break;
} }

View File

@ -80,7 +80,7 @@ TestCase::TestResult ObjectCompilerTest::run(ostream& _stream, string const& _li
} }
stack.optimize(); stack.optimize();
MachineAssemblyObject obj = stack.assemble(YulStack::Machine::EVM); MachineAssemblyObject obj = stack.assemble();
solAssert(obj.bytecode, ""); solAssert(obj.bytecode, "");
solAssert(obj.sourceMappings, ""); solAssert(obj.sourceMappings, "");

View File

@ -247,19 +247,16 @@ BOOST_AUTO_TEST_CASE(via_ir_options)
BOOST_AUTO_TEST_CASE(assembly_mode_options) BOOST_AUTO_TEST_CASE(assembly_mode_options)
{ {
static vector<tuple<vector<string>, YulStack::Machine, YulStack::Language>> const allowedCombinations = { static vector<tuple<vector<string>, YulStack::Language>> const allowedCombinations = {
{{"--machine=evm", "--yul-dialect=evm", "--assemble"}, YulStack::Machine::EVM, YulStack::Language::StrictAssembly}, {{"--yul-dialect=evm", "--assemble"}, YulStack::Language::StrictAssembly},
{{"--machine=evm", "--yul-dialect=evm", "--yul"}, YulStack::Machine::EVM, YulStack::Language::StrictAssembly}, {{"--yul-dialect=evm", "--yul"}, YulStack::Language::StrictAssembly},
{{"--machine=evm", "--yul-dialect=evm", "--strict-assembly"}, YulStack::Machine::EVM, YulStack::Language::StrictAssembly}, {{"--yul-dialect=evm", "--strict-assembly"}, YulStack::Language::StrictAssembly},
{{"--machine=evm", "--assemble"}, YulStack::Machine::EVM, YulStack::Language::Assembly}, {{"--assemble"}, YulStack::Language::Assembly},
{{"--machine=evm", "--yul"}, YulStack::Machine::EVM, YulStack::Language::Yul}, {{"--yul"}, YulStack::Language::Yul},
{{"--machine=evm", "--strict-assembly"}, YulStack::Machine::EVM, YulStack::Language::StrictAssembly}, {{"--strict-assembly"}, YulStack::Language::StrictAssembly},
{{"--assemble"}, YulStack::Machine::EVM, YulStack::Language::Assembly},
{{"--yul"}, YulStack::Machine::EVM, YulStack::Language::Yul},
{{"--strict-assembly"}, YulStack::Machine::EVM, YulStack::Language::StrictAssembly},
}; };
for (auto const& [assemblyOptions, expectedMachine, expectedLanguage]: allowedCombinations) for (auto const& [assemblyOptions, expectedLanguage]: allowedCombinations)
{ {
vector<string> commandLine = { vector<string> commandLine = {
"solc", "solc",
@ -320,7 +317,6 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options)
expectedOptions.output.revertStrings = RevertStrings::Strip; expectedOptions.output.revertStrings = RevertStrings::Strip;
expectedOptions.output.debugInfoSelection = DebugInfoSelection::fromString("location"); expectedOptions.output.debugInfoSelection = DebugInfoSelection::fromString("location");
expectedOptions.formatting.json = JsonFormat {JsonFormat::Pretty, 1}; expectedOptions.formatting.json = JsonFormat {JsonFormat::Pretty, 1};
expectedOptions.assembly.targetMachine = expectedMachine;
expectedOptions.assembly.inputLanguage = expectedLanguage; expectedOptions.assembly.inputLanguage = expectedLanguage;
expectedOptions.linker.libraries = { expectedOptions.linker.libraries = {
{"dir1/file1.sol:L", h160("1234567890123456789012345678901234567890")}, {"dir1/file1.sol:L", h160("1234567890123456789012345678901234567890")},

View File

@ -50,7 +50,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
try try
{ {
MachineAssemblyObject obj = stack.assemble(YulStack::Machine::EVM); MachineAssemblyObject obj = stack.assemble();
solAssert(obj.bytecode, ""); solAssert(obj.bytecode, "");
} }
catch (StackTooDeepError const&) catch (StackTooDeepError const&)