ASTJSON: Export evm version

This commit is contained in:
Mathias Baumann 2020-01-14 12:46:47 +01:00
parent d577a768ab
commit adc4774d4a
18 changed files with 64 additions and 3 deletions

View File

@ -26,6 +26,8 @@
#include <libyul/AsmJsonConverter.h>
#include <libyul/AsmData.h>
#include <libyul/AsmPrinter.h>
#include <libyul/backends/evm/EVMDialect.h>
#include <libsolutil/JSON.h>
#include <libsolutil/UTF8.h>
@ -492,13 +494,16 @@ bool ASTJsonConverter::visit(ArrayTypeName const& _node)
bool ASTJsonConverter::visit(InlineAssembly const& _node)
{
vector<pair<string, Json::Value>> externalReferences;
for (auto const& it: _node.annotation().externalReferences)
if (it.first)
externalReferences.emplace_back(make_pair(
it.first->name.str(),
inlineAssemblyIdentifierToJson(it)
));
Json::Value externalReferencesJson = Json::arrayValue;
for (auto&& it: boost::range::sort(externalReferences))
externalReferencesJson.append(std::move(it.second));
@ -506,8 +511,10 @@ bool ASTJsonConverter::visit(InlineAssembly const& _node)
m_legacy ?
make_pair("operations", Json::Value(yul::AsmPrinter()(_node.operations()))) :
make_pair("AST", Json::Value(yul::AsmJsonConverter(sourceIndexFromLocation(_node.location()))(_node.operations()))),
make_pair("externalReferences", std::move(externalReferencesJson))
make_pair("externalReferences", std::move(externalReferencesJson)),
make_pair("evmVersion", dynamic_cast<solidity::yul::EVMDialect const&>(_node.dialect()).evmVersion().name())
});
return false;
}

View File

@ -124,6 +124,7 @@
}
]
},
"evmVersion": %EVMVERSION%,
"externalReferences": [],
"id": 3,
"nodeType": "InlineAssembly",

View File

@ -89,6 +89,7 @@
{
"attributes":
{
"evmVersion": %EVMVERSION%,
"externalReferences":
[
null

View File

@ -111,6 +111,7 @@
}
]
},
"evmVersion": %EVMVERSION%,
"externalReferences": [],
"id": 3,
"nodeType": "InlineAssembly",

View File

@ -89,6 +89,7 @@
{
"attributes":
{
"evmVersion": %EVMVERSION%,
"externalReferences":
[
null

View File

@ -61,6 +61,7 @@
}
]
},
"evmVersion": %EVMVERSION%,
"externalReferences": [],
"id": 3,
"nodeType": "InlineAssembly",

View File

@ -89,6 +89,7 @@
{
"attributes":
{
"evmVersion": %EVMVERSION%,
"externalReferences":
[
null

View File

@ -124,6 +124,7 @@
}
]
},
"evmVersion": %EVMVERSION%,
"externalReferences": [],
"id": 3,
"nodeType": "InlineAssembly",

View File

@ -89,6 +89,7 @@
{
"attributes":
{
"evmVersion": %EVMVERSION%,
"externalReferences":
[
null

View File

@ -176,6 +176,7 @@
}
]
},
"evmVersion": %EVMVERSION%,
"externalReferences":
[
{

View File

@ -166,6 +166,7 @@
{
"attributes":
{
"evmVersion": %EVMVERSION%,
"externalReferences":
[
{

View File

@ -65,6 +65,7 @@
}
]
},
"evmVersion": %EVMVERSION%,
"externalReferences": [],
"id": 3,
"nodeType": "InlineAssembly",

View File

@ -89,6 +89,7 @@
{
"attributes":
{
"evmVersion": %EVMVERSION%,
"externalReferences":
[
null

View File

@ -157,6 +157,7 @@
}
]
},
"evmVersion": %EVMVERSION%,
"externalReferences": [],
"id": 3,
"nodeType": "InlineAssembly",

View File

@ -89,6 +89,7 @@
{
"attributes":
{
"evmVersion": %EVMVERSION%,
"externalReferences":
[
null

View File

@ -107,6 +107,7 @@
}
]
},
"evmVersion": %EVMVERSION%,
"externalReferences":
[
{

View File

@ -135,6 +135,7 @@
{
"attributes":
{
"evmVersion": %EVMVERSION%,
"externalReferences":
[
{

View File

@ -15,6 +15,7 @@
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/algorithm/string/replace.hpp>
#include <test/libsolidity/ASTJSONTest.h>
#include <test/Options.h>
#include <libsolutil/AnsiColorized.h>
@ -38,6 +39,30 @@ using namespace std;
namespace fs = boost::filesystem;
using namespace boost::unit_test;
namespace
{
void replaceVersionWithTag(string& _input)
{
boost::algorithm::replace_all(
_input,
"\"" + solidity::test::Options::get().evmVersion().name() + "\"",
"%EVMVERSION%"
);
}
void replaceTagWithVersion(string& _input)
{
boost::algorithm::replace_all(
_input,
"%EVMVERSION%",
"\"" + solidity::test::Options::get().evmVersion().name() + "\""
);
}
}
ASTJSONTest::ASTJSONTest(string const& _filename)
{
if (!boost::algorithm::ends_with(_filename, ".sol"))
@ -126,6 +151,8 @@ TestCase::TestResult ASTJSONTest::run(ostream& _stream, string const& _linePrefi
bool resultsMatch = true;
replaceTagWithVersion(m_expectation);
if (m_expectation != m_result)
{
string nextIndentLevel = _linePrefix + " ";
@ -158,6 +185,8 @@ TestCase::TestResult ASTJSONTest::run(ostream& _stream, string const& _linePrefi
m_resultLegacy += "\n";
}
replaceTagWithVersion(m_expectationLegacy);
if (m_expectationLegacy != m_resultLegacy)
{
string nextIndentLevel = _linePrefix + " ";
@ -202,12 +231,21 @@ void ASTJSONTest::printUpdatedExpectations(std::ostream&, std::string const&) co
ofstream file(m_astFilename.c_str());
if (!file) BOOST_THROW_EXCEPTION(runtime_error("Cannot write AST expectation to \"" + m_astFilename + "\"."));
file.exceptions(ios::badbit);
file << m_result;
string replacedResult = m_result;
replaceVersionWithTag(replacedResult);
file << replacedResult;
file.flush();
file.close();
file.open(m_legacyAstFilename.c_str());
if (!file) BOOST_THROW_EXCEPTION(runtime_error("Cannot write legacy AST expectation to \"" + m_legacyAstFilename + "\"."));
file << m_resultLegacy;
string replacedResultLegacy = m_resultLegacy;
replaceVersionWithTag(replacedResultLegacy);
file << replacedResultLegacy;
file.flush();
file.close();
}