Remove stack annotations again.

This commit is contained in:
chriseth 2017-02-28 10:46:09 +01:00
parent 13fd569f76
commit 369005fc03
8 changed files with 4 additions and 132 deletions

View File

@ -127,36 +127,7 @@ bool AsmAnalyzer::operator()(Label const& _item)
));
return false;
}
bool success = true;
if (!_item.stackInfo.empty())
{
Scope::Label& label = boost::get<Scope::Label>(m_currentScope->identifiers[_item.name]);
if (_item.stackInfo.size() == 1)
try
{
label.stackAdjustment = boost::lexical_cast<int>(_item.stackInfo[0]);
label.resetStackHeight = false;
return true;
}
catch (boost::bad_lexical_cast const&)
{
// Interpret as variable name
}
label.resetStackHeight = true;
for (auto const& stackItem: _item.stackInfo)
if (!stackItem.empty())
if (!m_currentScope->registerVariable(stackItem))
{
//@TODO secondary location
m_errors.push_back(make_shared<Error>(
Error::Type::DeclarationError,
"Variable name " + stackItem + " already taken in this scope.",
_item.location
));
success = false;
}
}
return success;
return true;
}
bool AsmAnalyzer::operator()(FunctionalAssignment const& _assignment)

View File

@ -82,8 +82,6 @@ struct Scope
struct Label
{
size_t id = unassignedLabelId;
int stackAdjustment = 0;
bool resetStackHeight = false;
static const size_t errorLabelId = -1;
static const size_t unassignedLabelId = 0;
};

View File

@ -188,26 +188,6 @@ public:
solAssert(m_scope.identifiers.count(_label.name), "");
Scope::Label& label = boost::get<Scope::Label>(m_scope.identifiers[_label.name]);
assignLabelIdIfUnset(label);
if (label.resetStackHeight)
{
size_t numVariables = boost::range::count_if(
m_scope.identifiers | boost::adaptors::map_values,
[](Scope::Identifier const& var) { return var.type() == typeid(Scope::Variable) && boost::get<Scope::Variable>(var).active; }
);
numVariables += boost::count_if(_label.stackInfo, [](string const& s) { return !s.empty(); });
m_state.assembly.setDeposit(m_initialDeposit + numVariables);
}
else if (label.stackAdjustment != 0)
m_state.assembly.adjustDeposit(label.stackAdjustment);
int height = m_state.assembly.deposit();
for (auto const& identifier: _label.stackInfo | boost::adaptors::reversed)
if (!identifier.empty())
{
solAssert(m_scope.identifiers.count(identifier), "");
Scope::Variable& var = boost::get<Scope::Variable>(m_scope.identifiers[identifier]);
var.active = true;
var.stackHeight = --height;
}
m_state.assembly.append(eth::AssemblyItem(eth::Tag, label.id));
}
void operator()(assembly::Assignment const& _assignment)

View File

@ -42,8 +42,8 @@ struct Literal { SourceLocation location; bool isNumber; std::string value; };
/// External / internal identifier or label reference
struct Identifier { SourceLocation location; std::string name; };
struct FunctionalInstruction;
/// Jump label ("name:" or "name [x, y, z]:" or "name [-3]:")
struct Label { SourceLocation location; std::string name; std::vector<std::string> stackInfo; };
/// Jump label ("name:")
struct Label { SourceLocation location; std::string name; };
/// Assignemnt (":= x", moves stack top into x, potentially multiple slots)
struct Assignment { SourceLocation location; Identifier variableName; };
struct FunctionalAssignment;

View File

@ -121,42 +121,6 @@ assembly::Statement Parser::parseStatement()
return label;
}
}
case Token::LBrack:
{
if (statement.type() != typeid(assembly::Identifier))
fatalParserError("Label name must precede \"[\".");
assembly::Identifier const& identifier = boost::get<assembly::Identifier>(statement);
Label label = createWithLocation<Label>(identifier.location);
label.name = identifier.name;
m_scanner->next();
if (m_scanner->currentToken() == Token::Number)
{
label.stackInfo.push_back(m_scanner->currentLiteral());
m_scanner->next();
}
else if (m_scanner->currentToken() == Token::Sub)
{
m_scanner->next();
label.stackInfo.push_back("-" + m_scanner->currentLiteral());
expectToken(Token::Number);
}
else if (m_scanner->currentToken() != Token::RBrack)
while (true)
{
label.stackInfo.push_back(expectAsmIdentifier());
if (m_scanner->currentToken() == Token::RBrack)
break;
expectToken(Token::Comma);
}
// Push an empty string to signify that there were brackets, like in
// "name[]:", which just resets the stack height to the height of the local variables.
if (label.stackInfo.empty())
label.stackInfo.push_back("");
expectToken(Token::RBrack);
label.location.end = endPosition();
expectToken(Token::Colon);
return label;
}
default:
break;
}

View File

@ -94,11 +94,7 @@ string AsmPrinter::operator()(assembly::FunctionalInstruction const& _functional
string AsmPrinter::operator()(assembly::Label const& _label)
{
return _label.name + (
!_label.stackInfo.empty() ?
"[" + boost::algorithm::join(_label.stackInfo, ", ") + "]" :
string()
) + ":";
return _label.name + ":";
}
string AsmPrinter::operator()(assembly::Assignment const& _assignment)

View File

@ -200,11 +200,6 @@ BOOST_AUTO_TEST_CASE(blocks)
BOOST_CHECK(successParse("{ let x := 7 { let y := 3 } { let z := 2 } }"));
}
BOOST_AUTO_TEST_CASE(labels_with_stack_info)
{
BOOST_CHECK(successParse("{ x[-1]: y[a]: z[d, e]: h[100]: g[]: }"));
}
BOOST_AUTO_TEST_CASE(function_definitions)
{
BOOST_CHECK(successParse("{ function f() { } function g(a) -> (x) { } }"));
@ -249,11 +244,6 @@ BOOST_AUTO_TEST_CASE(print_label)
parsePrintCompare("{\n loop:\n jump(loop)\n}");
}
BOOST_AUTO_TEST_CASE(print_label_with_stack)
{
parsePrintCompare("{\n loop[x, y]:\n other[-2]:\n third[10]:\n}");
}
BOOST_AUTO_TEST_CASE(print_assignments)
{
parsePrintCompare("{\n let x := mul(2, 3)\n 7\n =: x\n x := add(1, 2)\n}");

View File

@ -7418,33 +7418,6 @@ BOOST_AUTO_TEST_CASE(inline_assembly_function_access)
BOOST_CHECK(callContractFunction("x()") == encodeArgs(u256(10)));
}
BOOST_AUTO_TEST_CASE(inline_assembly_labels_with_stack_info)
{
char const* sourceCode = R"(
contract C {
function f(uint y) {
assembly {
y 7
jump(fun)
exit[-1]:
y add
0 mstore
return(0, 0x20)
fun:
{
entry[a, b]:
a := div(a, b)
pop
jump(exit)
}
}
}
}
)";
compileAndRun(sourceCode, 0, "C");
BOOST_CHECK(callContractFunction("f(uint256)", u256(15)) == encodeArgs(15 / 7 + 15));
}
BOOST_AUTO_TEST_CASE(index_access_with_type_conversion)
{
// Test for a bug where higher order bits cleanup was not done for array index access.