25
25
#include < libevmasm/EVMAssemblyStack.h>
26
26
27
27
#include < boost/algorithm/string/predicate.hpp>
28
- #include < boost/algorithm/string/split.hpp>
29
28
#include < boost/algorithm/string/trim.hpp>
30
29
31
30
#include < range/v3/view/map.hpp>
@@ -40,12 +39,12 @@ using namespace solidity::frontend::test;
40
39
using namespace solidity ::langutil;
41
40
using namespace solidity ::util;
42
41
43
- std::vector< std::string> const EVMAssemblyTest::c_outputLabels = {
44
- " InputAssemblyJSON" ,
45
- " Assembly" ,
46
- " Bytecode" ,
47
- " Opcodes" ,
48
- " SourceMappings" ,
42
+ std::map<EVMAssemblyTest::Output, std::string> const EVMAssemblyTest::c_outputLabels = {
43
+ {EVMAssemblyTest::Output::InputAssemblyJSON, " InputAssemblyJSON" } ,
44
+ {EVMAssemblyTest::Output::Assembly, " Assembly" } ,
45
+ {EVMAssemblyTest::Output::Bytecode, " Bytecode" } ,
46
+ {EVMAssemblyTest::Output::Opcodes, " Opcodes" } ,
47
+ {EVMAssemblyTest::Output::SourceMappings, " SourceMappings" } ,
49
48
};
50
49
51
50
std::unique_ptr<TestCase> EVMAssemblyTest::create (Config const & _config)
@@ -66,7 +65,11 @@ EVMAssemblyTest::EVMAssemblyTest(std::string const& _filename):
66
65
else
67
66
solThrow (ValidationError, " Not an assembly test: \" " + _filename + " \" . Allowed extensions: .asm, .asmjson." );
68
67
69
- m_selectedOutputs = m_reader.stringSetting (" outputs" , " Assembly,Bytecode,Opcodes,SourceMappings" );
68
+ m_selectedOutputs = m_reader.enumSetSetting (
69
+ " outputs" ,
70
+ c_outputLabels,
71
+ {Output::Assembly, Output::Bytecode, Output::Opcodes, Output::SourceMappings}
72
+ );
70
73
OptimisationPreset optimizationPreset = m_reader.enumSetting <OptimisationPreset>(
71
74
" optimizationPreset" ,
72
75
{
@@ -145,34 +148,29 @@ TestCase::TestResult EVMAssemblyTest::run(std::ostream& _stream, std::string con
145
148
}
146
149
soltestAssert (evmAssemblyStack.compilationSuccessful ());
147
150
148
- auto const produceOutput = [&](std::string const & _output) {
149
- if (_output == " InputAssemblyJSON" )
150
- return assemblyJSON;
151
- if (_output == " Assembly" )
152
- return evmAssemblyStack.assemblyString ({{m_reader.fileName ().filename ().string (), m_source}});
153
- if (_output == " Bytecode" )
154
- return util::toHex (evmAssemblyStack.object ().bytecode );
155
- if (_output == " Opcodes" )
156
- return disassemble (evmAssemblyStack.object ().bytecode , CommonOptions::get ().evmVersion ());
157
- if (_output == " SourceMappings" )
158
- return evmAssemblyStack.sourceMapping ();
159
- soltestAssert (false );
151
+ auto const produceOutput = [&](Output _output) {
152
+ switch (_output)
153
+ {
154
+ case Output::InputAssemblyJSON: return assemblyJSON;
155
+ case Output::Assembly: return evmAssemblyStack.assemblyString ({{m_reader.fileName ().filename ().string (), m_source}});
156
+ case Output::Bytecode: return util::toHex (evmAssemblyStack.object ().bytecode );
157
+ case Output::Opcodes: return disassemble (evmAssemblyStack.object ().bytecode , CommonOptions::get ().evmVersion ());
158
+ case Output::SourceMappings: return evmAssemblyStack.sourceMapping ();
159
+ }
160
160
unreachable ();
161
161
};
162
162
163
- std::set<std::string> selectedOutputSet;
164
- boost::split (selectedOutputSet, m_selectedOutputs, boost::is_any_of (" ," ));
165
- for (std::string const & output: c_outputLabels)
166
- if (selectedOutputSet.contains (output))
163
+ for (Output output: c_outputLabels | ranges::views::keys)
164
+ if (m_selectedOutputs.contains (output))
167
165
{
168
166
if (!m_obtainedResult.empty () && m_obtainedResult.back () != ' \n ' )
169
167
m_obtainedResult += " \n " ;
170
168
171
169
// Don't trim on the left to avoid stripping indentation.
172
170
std::string content = produceOutput (output);
173
171
boost::trim_right (content);
174
- std::string separator = (content.empty () ? " " : (output == " Assembly" ? " \n " : " " ));
175
- m_obtainedResult += output + " :" + separator + content;
172
+ std::string separator = (content.empty () ? " " : (output == Output:: Assembly ? " \n " : " " ));
173
+ m_obtainedResult += c_outputLabels. at ( output) + " :" + separator + content;
176
174
}
177
175
178
176
return checkResult (_stream, _linePrefix, _formatted);
0 commit comments