Try to keep source location during optimization.

This commit is contained in:
chriseth 2015-04-24 11:42:30 +02:00
parent b129a201db
commit cfe24c3c2a

View File

@ -22,6 +22,7 @@
#include <string> #include <string>
#include <tuple> #include <tuple>
#include <memory>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <test/libsolidity/solidityExecutionFramework.h> #include <test/libsolidity/solidityExecutionFramework.h>
@ -84,9 +85,20 @@ public:
AssemblyItems getCSE(AssemblyItems const& _input) AssemblyItems getCSE(AssemblyItems const& _input)
{ {
// add dummy locations to each item so that we can check that they are not deleted
AssemblyItems input = _input;
for (AssemblyItem& item: input)
item.setLocation(SourceLocation(1, 3, make_shared<string>("")));
eth::CommonSubexpressionEliminator cse; eth::CommonSubexpressionEliminator cse;
BOOST_REQUIRE(cse.feedItems(_input.begin(), _input.end()) == _input.end()); BOOST_REQUIRE(cse.feedItems(input.begin(), input.end()) == input.end());
return cse.getOptimizedItems(); AssemblyItems output = cse.getOptimizedItems();
for (AssemblyItem const& item: output)
{
BOOST_CHECK(item == Instruction::POP || !item.getLocation().isEmpty());
}
return output;
} }
void checkCSE(AssemblyItems const& _input, AssemblyItems const& _expectation) void checkCSE(AssemblyItems const& _input, AssemblyItems const& _expectation)