@@ -180,7 +180,7 @@ bool hashMatchesContent(std::string const& _hash, std::string const& _content)
180180
181181bool isArtifactRequested (Json const & _outputSelection, std::string const & _artifact, bool _wildcardMatchesExperimental)
182182{
183- static std::set<std::string> experimental{" ir" , " irAst" , " irOptimized" , " irOptimizedAst" };
183+ static std::set<std::string> experimental{" ir" , " irAst" , " irOptimized" , " irOptimizedAst" , " ethdebug " };
184184 for (auto const & selectedArtifactJson: _outputSelection)
185185 {
186186 std::string const & selectedArtifact = selectedArtifactJson.get <std::string>();
@@ -265,7 +265,7 @@ bool isBinaryRequested(Json const& _outputSelection)
265265 static std::vector<std::string> const outputsThatRequireBinaries = std::vector<std::string>{
266266 " *" ,
267267 " ir" , " irAst" , " irOptimized" , " irOptimizedAst" ,
268- " evm.gasEstimates" , " evm.legacyAssembly" , " evm.assembly"
268+ " evm.gasEstimates" , " evm.legacyAssembly" , " evm.assembly" , " ethdebug "
269269 } + evmObjectComponents (" bytecode" ) + evmObjectComponents (" deployedBytecode" );
270270
271271 for (auto const & fileRequests: _outputSelection)
@@ -295,6 +295,21 @@ bool isEvmBytecodeRequested(Json const& _outputSelection)
295295 return false ;
296296}
297297
298+ // / @returns true if ethdebug was requested.
299+ bool isEthdebugRequested (Json const & _outputSelection)
300+ {
301+ if (!_outputSelection.is_object ())
302+ return false ;
303+
304+ for (auto const & fileRequests: _outputSelection)
305+ for (auto const & requests: fileRequests)
306+ for (auto const & request: requests)
307+ if (request == " ethdebug" )
308+ return true ;
309+
310+ return false ;
311+ }
312+
298313// / @returns The IR output selection for CompilerStack, based on outputs requested in the JSON.
299314// / Note that as an exception, '*' does not yet match "ir", "irAst", "irOptimized" or "irOptimizedAst".
300315CompilerStack::IROutputSelection irOutputSelection (Json const & _outputSelection)
@@ -1172,6 +1187,30 @@ std::variant<StandardCompiler::InputsAndSettings, Json> StandardCompiler::parseI
11721187 ret.modelCheckerSettings .timeout = modelCheckerSettings[" timeout" ].get <Json::number_unsigned_t >();
11731188 }
11741189
1190+ if (isEthdebugRequested (ret.outputSelection ))
1191+ {
1192+ if (ret.language == " Solidity" && !ret.viaIR )
1193+ return formatError (Error::Type::FatalError, " general" , " ''ethdebug' can only be selected as output, if 'viaIR' was set." );
1194+
1195+ if (!ret.debugInfoSelection .has_value ())
1196+ {
1197+ ret.debugInfoSelection = DebugInfoSelection::Default ();
1198+ ret.debugInfoSelection ->enable (" ethdebug" );
1199+ }
1200+ else
1201+ {
1202+ if (!ret.debugInfoSelection ->ethdebug )
1203+ return formatError (Error::Type::FatalError, " general" , " 'ethdebug' need to be enabled in 'settings.debug.debugInfo', if 'ethdebug' was selected as output." );
1204+ }
1205+ }
1206+
1207+ if (
1208+ ret.debugInfoSelection .has_value () && ret.debugInfoSelection ->ethdebug &&
1209+ irOutputSelection (ret.outputSelection ) == CompilerStack::IROutputSelection::None &&
1210+ !isEthdebugRequested (ret.outputSelection )
1211+ )
1212+ return formatFatalError (Error::Type::FatalError, " 'settings.debug.debugInfo' can only include 'ethdebug', if output 'ir', 'irOptimized' and/or 'ethdebug' was selected." );
1213+
11751214 return {std::move (ret)};
11761215}
11771216
@@ -1429,8 +1468,8 @@ Json StandardCompiler::compileSolidity(StandardCompiler::InputsAndSettings _inpu
14291468
14301469 Json output;
14311470
1432- if (errors.size () > 0 )
1433- output[" errors" ] = std::move (errors);
1471+ if (! errors.empty () )
1472+ output[" errors" ] = std::move (errors);
14341473
14351474 if (!compilerStack.unhandledSMTLib2Queries ().empty ())
14361475 for (std::string const & query: compilerStack.unhandledSMTLib2Queries ())
@@ -1475,6 +1514,10 @@ Json StandardCompiler::compileSolidity(StandardCompiler::InputsAndSettings _inpu
14751514 if (isArtifactRequested (_inputsAndSettings.outputSelection , file, name, " devdoc" , wildcardMatchesExperimental))
14761515 contractData[" devdoc" ] = compilerStack.natspecDev (contractName);
14771516
1517+ // ethdebug
1518+ if (compilationSuccess && _inputsAndSettings.viaIR && isArtifactRequested (_inputsAndSettings.outputSelection , file, name, " ethdebug" , wildcardMatchesExperimental))
1519+ contractData[" ethdebug" ] = compilerStack.ethdebug (contractName);
1520+
14781521 // IR
14791522 if (compilationSuccess && isArtifactRequested (_inputsAndSettings.outputSelection , file, name, " ir" , wildcardMatchesExperimental))
14801523 contractData[" ir" ] = compilerStack.yulIR (contractName);
@@ -1698,6 +1741,9 @@ Json StandardCompiler::compileYul(InputsAndSettings _inputsAndSettings)
16981741 if (isArtifactRequested (_inputsAndSettings.outputSelection , sourceName, contractName, " evm.assembly" , wildcardMatchesExperimental))
16991742 output[" contracts" ][sourceName][contractName][" evm" ][" assembly" ] = object.assembly ->assemblyString (stack.debugInfoSelection ());
17001743
1744+ if (isEthdebugRequested (_inputsAndSettings.outputSelection ))
1745+ output[" ethdebug" ] = object.ethdebug ;
1746+
17011747 return output;
17021748}
17031749
0 commit comments