Merge remote-tracking branch 'origin/develop' into develop_060

This commit is contained in:
chriseth
2019-12-03 21:17:15 +01:00
31 changed files with 202 additions and 232 deletions
+20 -20
View File
@@ -60,12 +60,12 @@ bool AsmAnalyzer::analyze(Block const& _block)
success = (*this)(_block);
if (!success)
solAssert(m_errorReporter.hasErrors(), "No success but no error.");
yulAssert(m_errorReporter.hasErrors(), "No success but no error.");
}
catch (FatalError const&)
{
// This FatalError con occur if the errorReporter has too many errors.
solAssert(!m_errorReporter.errors().empty(), "Fatal error detected, but no error is reported.");
yulAssert(!m_errorReporter.errors().empty(), "Fatal error detected, but no error is reported.");
}
return success && !m_errorReporter.hasErrors();
}
@@ -82,13 +82,13 @@ AsmAnalysisInfo AsmAnalyzer::analyzeStrictAssertCorrect(Dialect const& _dialect,
{},
_object.dataNames()
).analyze(*_object.code);
solAssert(success && errorList.empty(), "Invalid assembly/yul code.");
yulAssert(success && errorList.empty(), "Invalid assembly/yul code.");
return analysisInfo;
}
bool AsmAnalyzer::operator()(yul::Instruction const& _instruction)
{
solAssert(false, "The use of non-functional instructions is disallowed. Please use functional notation instead.");
yulAssert(false, "The use of non-functional instructions is disallowed. Please use functional notation instead.");
auto const& info = instructionInfo(_instruction.instruction);
m_stackHeight += info.ret - info.args;
m_info.stackHeightInfo[&_instruction] = m_stackHeight;
@@ -118,8 +118,8 @@ bool AsmAnalyzer::operator()(Literal const& _literal)
}
else if (_literal.kind == LiteralKind::Boolean)
{
solAssert(m_dialect.flavour == AsmFlavour::Yul, "");
solAssert(_literal.value == "true"_yulstring || _literal.value == "false"_yulstring, "");
yulAssert(m_dialect.flavour == AsmFlavour::Yul, "");
yulAssert(_literal.value == "true"_yulstring || _literal.value == "false"_yulstring, "");
}
m_info.stackHeightInfo[&_literal] = m_stackHeight;
return true;
@@ -127,7 +127,7 @@ bool AsmAnalyzer::operator()(Literal const& _literal)
bool AsmAnalyzer::operator()(Identifier const& _identifier)
{
solAssert(!_identifier.name.empty(), "");
yulAssert(!_identifier.name.empty(), "");
size_t numErrorsBefore = m_errorReporter.errors().size();
bool success = true;
if (m_currentScope->lookup(_identifier.name, GenericVisitor{
@@ -200,9 +200,9 @@ bool AsmAnalyzer::operator()(ExpressionStatement const& _statement)
bool AsmAnalyzer::operator()(Assignment const& _assignment)
{
solAssert(_assignment.value, "");
yulAssert(_assignment.value, "");
int const expectedItems = _assignment.variableNames.size();
solAssert(expectedItems >= 1, "");
yulAssert(expectedItems >= 1, "");
int const stackHeight = m_stackHeight;
bool success = std::visit(*this, *_assignment.value);
if ((m_stackHeight - stackHeight) != expectedItems)
@@ -269,9 +269,9 @@ bool AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
bool AsmAnalyzer::operator()(FunctionDefinition const& _funDef)
{
solAssert(!_funDef.name.empty(), "");
yulAssert(!_funDef.name.empty(), "");
Block const* virtualBlock = m_info.virtualBlocks.at(&_funDef).get();
solAssert(virtualBlock, "");
yulAssert(virtualBlock, "");
Scope& varScope = scope(virtualBlock);
for (auto const& var: _funDef.parameters + _funDef.returnVariables)
{
@@ -291,7 +291,7 @@ bool AsmAnalyzer::operator()(FunctionDefinition const& _funDef)
bool AsmAnalyzer::operator()(FunctionCall const& _funCall)
{
solAssert(!_funCall.functionName.name.empty(), "");
yulAssert(!_funCall.functionName.name.empty(), "");
bool success = true;
size_t parameters = 0;
size_t returns = 0;
@@ -390,7 +390,7 @@ bool AsmAnalyzer::operator()(If const& _if)
bool AsmAnalyzer::operator()(Switch const& _switch)
{
solAssert(_switch.expression, "");
yulAssert(_switch.expression, "");
bool success = true;
@@ -462,7 +462,7 @@ bool AsmAnalyzer::operator()(Switch const& _switch)
bool AsmAnalyzer::operator()(ForLoop const& _for)
{
solAssert(_for.condition, "");
yulAssert(_for.condition, "");
Scope* outerScope = m_currentScope;
@@ -579,7 +579,7 @@ bool AsmAnalyzer::expectDeposit(int _deposit, int _oldHeight, SourceLocation con
bool AsmAnalyzer::checkAssignment(Identifier const& _variable, size_t _valueSize)
{
solAssert(!_variable.name.empty(), "");
yulAssert(!_variable.name.empty(), "");
bool success = true;
size_t numErrorsBefore = m_errorReporter.errors().size();
size_t variableSize(-1);
@@ -635,9 +635,9 @@ bool AsmAnalyzer::checkAssignment(Identifier const& _variable, size_t _valueSize
Scope& AsmAnalyzer::scope(Block const* _block)
{
solAssert(m_info.scopes.count(_block) == 1, "Scope requested but not present.");
yulAssert(m_info.scopes.count(_block) == 1, "Scope requested but not present.");
auto scopePtr = m_info.scopes.at(_block);
solAssert(scopePtr, "Scope requested but not present.");
yulAssert(scopePtr, "Scope requested but not present.");
return *scopePtr;
}
void AsmAnalyzer::expectValidType(string const& type, SourceLocation const& _location)
@@ -665,10 +665,10 @@ bool AsmAnalyzer::warnOnInstructions(dev::eth::Instruction _instr, SourceLocatio
{
// We assume that returndatacopy, returndatasize and staticcall are either all available
// or all not available.
solAssert(m_evmVersion.supportsReturndata() == m_evmVersion.hasStaticCall(), "");
yulAssert(m_evmVersion.supportsReturndata() == m_evmVersion.hasStaticCall(), "");
// Similarly we assume bitwise shifting and create2 go together.
solAssert(m_evmVersion.hasBitwiseShifting() == m_evmVersion.hasCreate2(), "");
solAssert(m_dialect.flavour != AsmFlavour::Yul, "");
yulAssert(m_evmVersion.hasBitwiseShifting() == m_evmVersion.hasCreate2(), "");
yulAssert(m_dialect.flavour != AsmFlavour::Yul, "");
auto errorForVM = [=](string const& vmKindMessage) {
m_errorReporter.typeError(
-2
View File
@@ -22,8 +22,6 @@
#include <libyul/AsmDataForward.h>
#include <boost/variant.hpp>
#include <map>
#include <memory>
#include <vector>
+5 -4
View File
@@ -21,6 +21,7 @@
*/
#include <libyul/AsmParser.h>
#include <libyul/Exceptions.h>
#include <liblangutil/Scanner.h>
#include <liblangutil/ErrorReporter.h>
#include <libdevcore/Common.h>
@@ -52,7 +53,7 @@ shared_ptr<Block> Parser::parse(std::shared_ptr<Scanner> const& _scanner, bool _
}
catch (FatalError const&)
{
solAssert(!m_errorReporter.errors().empty(), "Fatal error detected, but no error is reported.");
yulAssert(!m_errorReporter.errors().empty(), "Fatal error detected, but no error is reported.");
}
return nullptr;
@@ -232,7 +233,7 @@ Statement Parser::parseStatement()
}
else
{
solAssert(false, "Invalid elementary operation.");
yulAssert(false, "Invalid elementary operation.");
return {};
}
}
@@ -252,7 +253,7 @@ Case Parser::parseCase()
_case.value = make_unique<Literal>(std::get<Literal>(std::move(literal)));
}
else
solAssert(false, "Case or default case expected.");
yulAssert(false, "Case or default case expected.");
_case.body = parseBlock();
_case.location.end = _case.body.location.end;
return _case;
@@ -292,7 +293,7 @@ Expression Parser::parseExpression()
return std::get<Identifier>(operation);
else
{
solAssert(holds_alternative<Literal>(operation), "");
yulAssert(holds_alternative<Literal>(operation), "");
return std::get<Literal>(operation);
}
}
+10 -10
View File
@@ -22,7 +22,7 @@
#include <libyul/AsmPrinter.h>
#include <libyul/AsmData.h>
#include <liblangutil/Exceptions.h>
#include <libyul/Exceptions.h>
#include <libdevcore/CommonData.h>
@@ -44,10 +44,10 @@ string AsmPrinter::operator()(Literal const& _literal) const
switch (_literal.kind)
{
case LiteralKind::Number:
solAssert(isValidDecimal(_literal.value.str()) || isValidHex(_literal.value.str()), "Invalid number literal");
yulAssert(isValidDecimal(_literal.value.str()) || isValidHex(_literal.value.str()), "Invalid number literal");
return _literal.value.str() + appendTypeName(_literal.type);
case LiteralKind::Boolean:
solAssert(_literal.value == "true"_yulstring || _literal.value == "false"_yulstring, "Invalid bool literal.");
yulAssert(_literal.value == "true"_yulstring || _literal.value == "false"_yulstring, "Invalid bool literal.");
return ((_literal.value == "true"_yulstring) ? "true" : "false") + appendTypeName(_literal.type);
case LiteralKind::String:
break;
@@ -84,7 +84,7 @@ string AsmPrinter::operator()(Literal const& _literal) const
string AsmPrinter::operator()(Identifier const& _identifier) const
{
solAssert(!_identifier.name.empty(), "Invalid identifier.");
yulAssert(!_identifier.name.empty(), "Invalid identifier.");
return _identifier.name.str();
}
@@ -95,7 +95,7 @@ string AsmPrinter::operator()(ExpressionStatement const& _statement) const
string AsmPrinter::operator()(Assignment const& _assignment) const
{
solAssert(_assignment.variableNames.size() >= 1, "");
yulAssert(_assignment.variableNames.size() >= 1, "");
string variables = (*this)(_assignment.variableNames.front());
for (size_t i = 1; i < _assignment.variableNames.size(); ++i)
variables += ", " + (*this)(_assignment.variableNames[i]);
@@ -121,7 +121,7 @@ string AsmPrinter::operator()(VariableDeclaration const& _variableDeclaration) c
string AsmPrinter::operator()(FunctionDefinition const& _functionDefinition) const
{
solAssert(!_functionDefinition.name.empty(), "Invalid function name.");
yulAssert(!_functionDefinition.name.empty(), "Invalid function name.");
string out = "function " + _functionDefinition.name.str() + "(";
out += boost::algorithm::join(
_functionDefinition.parameters | boost::adaptors::transformed(
@@ -156,7 +156,7 @@ string AsmPrinter::operator()(FunctionCall const& _functionCall) const
string AsmPrinter::operator()(If const& _if) const
{
solAssert(_if.condition, "Invalid if condition.");
yulAssert(_if.condition, "Invalid if condition.");
string body = (*this)(_if.body);
char delim = '\n';
if (body.find('\n') == string::npos)
@@ -166,7 +166,7 @@ string AsmPrinter::operator()(If const& _if) const
string AsmPrinter::operator()(Switch const& _switch) const
{
solAssert(_switch.expression, "Invalid expression pointer.");
yulAssert(_switch.expression, "Invalid expression pointer.");
string out = "switch " + std::visit(*this, *_switch.expression);
for (auto const& _case: _switch.cases)
{
@@ -181,7 +181,7 @@ string AsmPrinter::operator()(Switch const& _switch) const
string AsmPrinter::operator()(ForLoop const& _forLoop) const
{
solAssert(_forLoop.condition, "Invalid for loop condition.");
yulAssert(_forLoop.condition, "Invalid for loop condition.");
string pre = (*this)(_forLoop.pre);
string condition = std::visit(*this, *_forLoop.condition);
string post = (*this)(_forLoop.post);
@@ -231,7 +231,7 @@ string AsmPrinter::operator()(Block const& _block) const
string AsmPrinter::formatTypedName(TypedName _variable) const
{
solAssert(!_variable.name.empty(), "Invalid variable name.");
yulAssert(!_variable.name.empty(), "Invalid variable name.");
return _variable.name.str() + appendTypeName(_variable.type);
}
+2 -2
View File
@@ -23,9 +23,9 @@
#include <libyul/AsmData.h>
#include <libyul/AsmScope.h>
#include <libyul/AsmAnalysisInfo.h>
#include <libyul/Exceptions.h>
#include <liblangutil/ErrorReporter.h>
#include <liblangutil/Exceptions.h>
#include <libdevcore/CommonData.h>
@@ -74,7 +74,7 @@ bool ScopeFiller::operator()(FunctionDefinition const& _funDef)
if (!(*this)(_funDef.body))
success = false;
solAssert(m_currentScope == &varScope, "");
yulAssert(m_currentScope == &varScope, "");
m_currentScope = m_currentScope->superScope;
return success;
+21 -21
View File
@@ -62,7 +62,7 @@ Dialect const& languageToDialect(AssemblyStack::Language _language, EVMVersion _
case AssemblyStack::Language::EWasm:
return WasmDialect::instance();
}
solAssert(false, "");
yulAssert(false, "");
return Dialect::yul();
}
@@ -71,7 +71,7 @@ Dialect const& languageToDialect(AssemblyStack::Language _language, EVMVersion _
Scanner const& AssemblyStack::scanner() const
{
solAssert(m_scanner, "");
yulAssert(m_scanner, "");
return *m_scanner;
}
@@ -83,8 +83,8 @@ bool AssemblyStack::parseAndAnalyze(std::string const& _sourceName, std::string
m_parserResult = ObjectParser(m_errorReporter, languageToDialect(m_language, m_evmVersion)).parse(m_scanner, false);
if (!m_errorReporter.errors().empty())
return false;
solAssert(m_parserResult, "");
solAssert(m_parserResult->code, "");
yulAssert(m_parserResult, "");
yulAssert(m_parserResult->code, "");
return analyzeParsed();
}
@@ -94,12 +94,12 @@ void AssemblyStack::optimize()
if (!m_optimiserSettings.runYulOptimiser)
return;
solAssert(m_analysisSuccessful, "Analysis was not successful.");
yulAssert(m_analysisSuccessful, "Analysis was not successful.");
m_analysisSuccessful = false;
solAssert(m_parserResult, "");
yulAssert(m_parserResult, "");
optimize(*m_parserResult, true);
solAssert(analyzeParsed(), "Invalid source code after optimization.");
yulAssert(analyzeParsed(), "Invalid source code after optimization.");
}
void AssemblyStack::translate(AssemblyStack::Language _targetLanguage)
@@ -121,14 +121,14 @@ void AssemblyStack::translate(AssemblyStack::Language _targetLanguage)
bool AssemblyStack::analyzeParsed()
{
solAssert(m_parserResult, "");
yulAssert(m_parserResult, "");
m_analysisSuccessful = analyzeParsed(*m_parserResult);
return m_analysisSuccessful;
}
bool AssemblyStack::analyzeParsed(Object& _object)
{
solAssert(_object.code, "");
yulAssert(_object.code, "");
_object.analysisInfo = make_shared<AsmAnalysisInfo>();
AsmAnalyzer analyzer(
@@ -168,8 +168,8 @@ void AssemblyStack::compileEVM(AbstractAssembly& _assembly, bool _evm15, bool _o
void AssemblyStack::optimize(Object& _object, bool _isCreation)
{
solAssert(_object.code, "");
solAssert(_object.analysisInfo, "");
yulAssert(_object.code, "");
yulAssert(_object.analysisInfo, "");
for (auto& subNode: _object.subObjects)
if (auto subObject = dynamic_cast<Object*>(subNode.get()))
optimize(*subObject, false);
@@ -188,10 +188,10 @@ void AssemblyStack::optimize(Object& _object, bool _isCreation)
MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
{
solAssert(m_analysisSuccessful, "");
solAssert(m_parserResult, "");
solAssert(m_parserResult->code, "");
solAssert(m_parserResult->analysisInfo, "");
yulAssert(m_analysisSuccessful, "");
yulAssert(m_parserResult, "");
yulAssert(m_parserResult->code, "");
yulAssert(m_parserResult->analysisInfo, "");
switch (_machine)
{
@@ -216,7 +216,7 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
}
case Machine::eWasm:
{
solAssert(m_language == Language::EWasm, "");
yulAssert(m_language == Language::EWasm, "");
Dialect const& dialect = languageToDialect(m_language, EVMVersion{});
MachineAssemblyObject object;
@@ -233,15 +233,15 @@ MachineAssemblyObject AssemblyStack::assemble(Machine _machine) const
string AssemblyStack::print() const
{
solAssert(m_parserResult, "");
solAssert(m_parserResult->code, "");
yulAssert(m_parserResult, "");
yulAssert(m_parserResult->code, "");
return m_parserResult->toString(m_language == Language::Yul) + "\n";
}
shared_ptr<Object> AssemblyStack::parserResult() const
{
solAssert(m_analysisSuccessful, "Analysis was not successful.");
solAssert(m_parserResult, "");
solAssert(m_parserResult->code, "");
yulAssert(m_analysisSuccessful, "Analysis was not successful.");
yulAssert(m_parserResult, "");
yulAssert(m_parserResult->code, "");
return m_parserResult;
}
+2 -2
View File
@@ -41,7 +41,7 @@ map<YulString, int> CompilabilityChecker::run(
if (_dialect.flavour == AsmFlavour::Yul)
return {};
solAssert(_dialect.flavour == AsmFlavour::Strict, "");
yulAssert(_dialect.flavour == AsmFlavour::Strict, "");
if (EVMDialect const* evmDialect = dynamic_cast<EVMDialect const*>(&_dialect))
{
@@ -69,7 +69,7 @@ map<YulString, int> CompilabilityChecker::run(
}
catch (StackTooDeepError const&)
{
solAssert(!transform.stackErrors().empty(), "Got stack too deep exception that was not stored.");
yulAssert(!transform.stackErrors().empty(), "Got stack too deep exception that was not stored.");
}
std::map<YulString, int> functions;
+1 -1
View File
@@ -33,6 +33,6 @@ struct YulAssertion: virtual YulException {};
/// Assertion that throws an YulAssertion containing the given description if it is not met.
#define yulAssert(CONDITION, DESCRIPTION) \
assertThrow(CONDITION, ::yul::YulException, DESCRIPTION)
assertThrow(CONDITION, ::yul::YulAssertion, DESCRIPTION)
}
+1 -1
View File
@@ -112,7 +112,7 @@ shared_ptr<Block> ObjectParser::parseBlock()
void ObjectParser::parseData(Object& _containingObject)
{
solAssert(
yulAssert(
currentToken() == Token::Identifier && currentLiteral() == "data",
"parseData called on wrong input."
);
+6 -6
View File
@@ -118,19 +118,19 @@ void EthAssemblyAdapter::appendJumpToIf(LabelID _labelId)
void EthAssemblyAdapter::appendBeginsub(LabelID, int)
{
// TODO we could emulate that, though
solAssert(false, "BEGINSUB not implemented for EVM 1.0");
yulAssert(false, "BEGINSUB not implemented for EVM 1.0");
}
void EthAssemblyAdapter::appendJumpsub(LabelID, int, int)
{
// TODO we could emulate that, though
solAssert(false, "JUMPSUB not implemented for EVM 1.0");
yulAssert(false, "JUMPSUB not implemented for EVM 1.0");
}
void EthAssemblyAdapter::appendReturnsub(int, int)
{
// TODO we could emulate that, though
solAssert(false, "RETURNSUB not implemented for EVM 1.0");
yulAssert(false, "RETURNSUB not implemented for EVM 1.0");
}
void EthAssemblyAdapter::appendAssemblySize()
@@ -174,7 +174,7 @@ AbstractAssembly::SubID EthAssemblyAdapter::appendData(bytes const& _data)
EthAssemblyAdapter::LabelID EthAssemblyAdapter::assemblyTagToIdentifier(eth::AssemblyItem const& _tag)
{
u256 id = _tag.data();
solAssert(id <= std::numeric_limits<LabelID>::max(), "Tag id too large.");
yulAssert(id <= std::numeric_limits<LabelID>::max(), "Tag id too large.");
return LabelID(id);
}
@@ -207,11 +207,11 @@ void CodeGenerator::assemble(
}
catch (StackTooDeepError const& _e)
{
solAssert(
yulAssert(
false,
"Stack too deep when compiling inline assembly" +
(_e.comment() ? ": " + *_e.comment() : ".")
);
}
solAssert(transform.stackErrors().empty(), "Stack errors present but not thrown.");
yulAssert(transform.stackErrors().empty(), "Stack errors present but not thrown.");
}
+21 -22
View File
@@ -19,11 +19,10 @@
*/
#include <libyul/backends/evm/EVMAssembly.h>
#include <libyul/Exceptions.h>
#include <libevmasm/Instruction.h>
#include <liblangutil/Exceptions.h>
using namespace std;
using namespace dev;
using namespace dev::eth;
@@ -65,7 +64,7 @@ void EVMAssembly::appendLabel(LabelID _labelId)
void EVMAssembly::appendLabelReference(LabelID _labelId)
{
solAssert(!m_evm15, "Cannot use plain label references in EMV1.5 mode.");
yulAssert(!m_evm15, "Cannot use plain label references in EMV1.5 mode.");
// @TODO we now always use labelReferenceSize for all labels, it could be shortened
// for some of them.
appendInstruction(dev::eth::pushInstruction(labelReferenceSize));
@@ -81,7 +80,7 @@ EVMAssembly::LabelID EVMAssembly::newLabelId()
AbstractAssembly::LabelID EVMAssembly::namedLabel(string const& _name)
{
solAssert(!_name.empty(), "");
yulAssert(!_name.empty(), "");
if (!m_namedLabels.count(_name))
m_namedLabels[_name] = newLabelId();
return m_namedLabels[_name];
@@ -89,12 +88,12 @@ AbstractAssembly::LabelID EVMAssembly::namedLabel(string const& _name)
void EVMAssembly::appendLinkerSymbol(string const&)
{
solAssert(false, "Linker symbols not yet implemented.");
yulAssert(false, "Linker symbols not yet implemented.");
}
void EVMAssembly::appendJump(int _stackDiffAfter)
{
solAssert(!m_evm15, "Plain JUMP used for EVM 1.5");
yulAssert(!m_evm15, "Plain JUMP used for EVM 1.5");
appendInstruction(dev::eth::Instruction::JUMP);
m_stackHeight += _stackDiffAfter;
}
@@ -131,8 +130,8 @@ void EVMAssembly::appendJumpToIf(LabelID _labelId)
void EVMAssembly::appendBeginsub(LabelID _labelId, int _arguments)
{
solAssert(m_evm15, "BEGINSUB used for EVM 1.0");
solAssert(_arguments >= 0, "");
yulAssert(m_evm15, "BEGINSUB used for EVM 1.0");
yulAssert(_arguments >= 0, "");
setLabelToCurrentPosition(_labelId);
m_bytecode.push_back(uint8_t(dev::eth::Instruction::BEGINSUB));
m_stackHeight += _arguments;
@@ -140,8 +139,8 @@ void EVMAssembly::appendBeginsub(LabelID _labelId, int _arguments)
void EVMAssembly::appendJumpsub(LabelID _labelId, int _arguments, int _returns)
{
solAssert(m_evm15, "JUMPSUB used for EVM 1.0");
solAssert(_arguments >= 0 && _returns >= 0, "");
yulAssert(m_evm15, "JUMPSUB used for EVM 1.0");
yulAssert(_arguments >= 0 && _returns >= 0, "");
m_bytecode.push_back(uint8_t(dev::eth::Instruction::JUMPSUB));
appendLabelReferenceInternal(_labelId);
m_stackHeight += _returns - _arguments;
@@ -149,8 +148,8 @@ void EVMAssembly::appendJumpsub(LabelID _labelId, int _arguments, int _returns)
void EVMAssembly::appendReturnsub(int _returns, int _stackDiffAfter)
{
solAssert(m_evm15, "RETURNSUB used for EVM 1.0");
solAssert(_returns >= 0, "");
yulAssert(m_evm15, "RETURNSUB used for EVM 1.0");
yulAssert(_returns >= 0, "");
m_bytecode.push_back(uint8_t(dev::eth::Instruction::RETURNSUB));
m_stackHeight += _stackDiffAfter - _returns;
}
@@ -164,9 +163,9 @@ eth::LinkerObject EVMAssembly::finalize()
for (auto const& ref: m_labelReferences)
{
size_t referencePos = ref.first;
solAssert(m_labelPositions.count(ref.second), "");
yulAssert(m_labelPositions.count(ref.second), "");
size_t labelPos = m_labelPositions.at(ref.second);
solAssert(labelPos != size_t(-1), "Undefined but allocated label used.");
yulAssert(labelPos != size_t(-1), "Undefined but allocated label used.");
updateReference(referencePos, labelReferenceSize, u256(labelPos));
}
@@ -177,8 +176,8 @@ eth::LinkerObject EVMAssembly::finalize()
void EVMAssembly::setLabelToCurrentPosition(LabelID _labelId)
{
solAssert(m_labelPositions.count(_labelId), "Label not found.");
solAssert(m_labelPositions[_labelId] == size_t(-1), "Label already set.");
yulAssert(m_labelPositions.count(_labelId), "Label not found.");
yulAssert(m_labelPositions[_labelId] == size_t(-1), "Label already set.");
m_labelPositions[_labelId] = m_bytecode.size();
}
@@ -197,29 +196,29 @@ void EVMAssembly::appendAssemblySize()
pair<shared_ptr<AbstractAssembly>, AbstractAssembly::SubID> EVMAssembly::createSubAssembly()
{
solAssert(false, "Sub assemblies not implemented.");
yulAssert(false, "Sub assemblies not implemented.");
return {};
}
void EVMAssembly::appendDataOffset(AbstractAssembly::SubID)
{
solAssert(false, "Data not implemented.");
yulAssert(false, "Data not implemented.");
}
void EVMAssembly::appendDataSize(AbstractAssembly::SubID)
{
solAssert(false, "Data not implemented.");
yulAssert(false, "Data not implemented.");
}
AbstractAssembly::SubID EVMAssembly::appendData(bytes const&)
{
solAssert(false, "Data not implemented.");
yulAssert(false, "Data not implemented.");
}
void EVMAssembly::updateReference(size_t pos, size_t size, u256 value)
{
solAssert(m_bytecode.size() >= size && pos <= m_bytecode.size() - size, "");
solAssert(value < (u256(1) << (8 * size)), "");
yulAssert(m_bytecode.size() >= size && pos <= m_bytecode.size() - size, "");
yulAssert(value < (u256(1) << (8 * size)), "");
for (size_t i = 0; i < size; i++)
m_bytecode[pos + i] = uint8_t((value >> (8 * (size - i - 1))) & 0xff);
}
+40 -40
View File
@@ -44,9 +44,9 @@ void VariableReferenceCounter::operator()(FunctionDefinition const& _function)
{
Scope* originalScope = m_scope;
solAssert(m_info.virtualBlocks.at(&_function), "");
yulAssert(m_info.virtualBlocks.at(&_function), "");
m_scope = m_info.scopes.at(m_info.virtualBlocks.at(&_function).get()).get();
solAssert(m_scope, "Variable scope does not exist.");
yulAssert(m_scope, "Variable scope does not exist.");
for (auto const& v: _function.returnVariables)
increaseRefIfFound(v.name);
@@ -131,7 +131,7 @@ void CodeTransform::decreaseReference(YulString, Scope::Variable const& _var)
return;
unsigned& ref = m_context->variableReferences.at(&_var);
solAssert(ref >= 1, "");
yulAssert(ref >= 1, "");
--ref;
if (ref == 0)
m_variablesScheduledForDeletion.insert(&_var);
@@ -157,7 +157,7 @@ void CodeTransform::freeUnusedVariables()
while (m_unusedStackSlots.count(m_assembly.stackHeight() - 1))
{
solAssert(m_unusedStackSlots.erase(m_assembly.stackHeight() - 1), "");
yulAssert(m_unusedStackSlots.erase(m_assembly.stackHeight() - 1), "");
m_assembly.appendInstruction(dev::eth::Instruction::POP);
--m_stackAdjustment;
}
@@ -165,8 +165,8 @@ void CodeTransform::freeUnusedVariables()
void CodeTransform::deleteVariable(Scope::Variable const& _var)
{
solAssert(m_allowStackOpt, "");
solAssert(m_context->variableStackHeights.count(&_var) > 0, "");
yulAssert(m_allowStackOpt, "");
yulAssert(m_context->variableStackHeights.count(&_var) > 0, "");
m_unusedStackSlots.insert(m_context->variableStackHeights[&_var]);
m_context->variableStackHeights.erase(&_var);
m_context->variableReferences.erase(&_var);
@@ -175,7 +175,7 @@ void CodeTransform::deleteVariable(Scope::Variable const& _var)
void CodeTransform::operator()(VariableDeclaration const& _varDecl)
{
solAssert(m_scope, "");
yulAssert(m_scope, "");
int const numVariables = _varDecl.variables.size();
int height = m_assembly.stackHeight();
@@ -261,7 +261,7 @@ void CodeTransform::operator()(ExpressionStatement const& _statement)
void CodeTransform::operator()(FunctionCall const& _call)
{
solAssert(m_scope, "");
yulAssert(m_scope, "");
if (BuiltinFunctionForEVM const* builtin = m_dialect.builtin(_call.functionName.name))
{
@@ -283,13 +283,13 @@ void CodeTransform::operator()(FunctionCall const& _call)
}
Scope::Function* function = nullptr;
solAssert(m_scope->lookup(_call.functionName.name, GenericVisitor{
[=](Scope::Variable&) { solAssert(false, "Expected function name."); },
[=](Scope::Label&) { solAssert(false, "Expected function name."); },
yulAssert(m_scope->lookup(_call.functionName.name, GenericVisitor{
[=](Scope::Variable&) { yulAssert(false, "Expected function name."); },
[=](Scope::Label&) { yulAssert(false, "Expected function name."); },
[&](Scope::Function& _function) { function = &_function; }
}), "Function name not found.");
solAssert(function, "");
solAssert(function->arguments.size() == _call.arguments.size(), "");
yulAssert(function, "");
yulAssert(function->arguments.size() == _call.arguments.size(), "");
for (auto const& arg: _call.arguments | boost::adaptors::reversed)
visitExpression(arg);
m_assembly.setSourceLocation(_call.location);
@@ -309,7 +309,7 @@ void CodeTransform::operator()(Identifier const& _identifier)
{
m_assembly.setSourceLocation(_identifier.location);
// First search internals, then externals.
solAssert(m_scope, "");
yulAssert(m_scope, "");
if (m_scope->lookup(_identifier.name, GenericVisitor{
[=](Scope::Variable& _var)
{
@@ -328,13 +328,13 @@ void CodeTransform::operator()(Identifier const& _identifier)
},
[=](Scope::Function&)
{
solAssert(false, "Function not removed during desugaring.");
yulAssert(false, "Function not removed during desugaring.");
}
}))
{
return;
}
solAssert(
yulAssert(
m_identifierAccess.generateCode,
"Identifier not found and no external access available."
);
@@ -352,9 +352,9 @@ void CodeTransform::operator()(Literal const& _literal)
void CodeTransform::operator()(yul::Instruction const& _instruction)
{
solAssert(!m_allowStackOpt, "");
solAssert(!m_evm15 || _instruction.instruction != dev::eth::Instruction::JUMP, "Bare JUMP instruction used for EVM1.5");
solAssert(!m_evm15 || _instruction.instruction != dev::eth::Instruction::JUMPI, "Bare JUMPI instruction used for EVM1.5");
yulAssert(!m_allowStackOpt, "");
yulAssert(!m_evm15 || _instruction.instruction != dev::eth::Instruction::JUMP, "Bare JUMP instruction used for EVM1.5");
yulAssert(!m_evm15 || _instruction.instruction != dev::eth::Instruction::JUMPI, "Bare JUMPI instruction used for EVM1.5");
m_assembly.setSourceLocation(_instruction.location);
m_assembly.appendInstruction(_instruction.instruction);
checkStackHeight(&_instruction);
@@ -389,7 +389,7 @@ void CodeTransform::operator()(Switch const& _switch)
m_assembly.setSourceLocation(c.location);
AbstractAssembly::LabelID bodyLabel = m_assembly.newLabelId();
caseBodies[&c] = bodyLabel;
solAssert(m_assembly.stackHeight() == expressionHeight + 1, "");
yulAssert(m_assembly.stackHeight() == expressionHeight + 1, "");
m_assembly.appendInstruction(dev::eth::dupInstruction(2));
m_assembly.appendInstruction(dev::eth::Instruction::EQ);
m_assembly.appendJumpToIf(bodyLabel);
@@ -423,15 +423,15 @@ void CodeTransform::operator()(Switch const& _switch)
void CodeTransform::operator()(FunctionDefinition const& _function)
{
solAssert(m_scope, "");
solAssert(m_scope->identifiers.count(_function.name), "");
yulAssert(m_scope, "");
yulAssert(m_scope->identifiers.count(_function.name), "");
Scope::Function& function = std::get<Scope::Function>(m_scope->identifiers.at(_function.name));
int const localStackAdjustment = m_evm15 ? 0 : 1;
int height = localStackAdjustment;
solAssert(m_info.scopes.at(&_function.body), "");
yulAssert(m_info.scopes.at(&_function.body), "");
Scope* varScope = m_info.scopes.at(m_info.virtualBlocks.at(&_function).get()).get();
solAssert(varScope, "");
yulAssert(varScope, "");
for (auto const& v: _function.parameters | boost::adaptors::reversed)
{
auto& var = std::get<Scope::Variable>(varScope->identifiers.at(v.name));
@@ -535,7 +535,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
swap(stackLayout[stackLayout.back()], stackLayout.back());
}
for (int i = 0; size_t(i) < stackLayout.size(); ++i)
solAssert(i == stackLayout[i], "Error reshuffling stack.");
yulAssert(i == stackLayout[i], "Error reshuffling stack.");
}
}
if (m_evm15)
@@ -647,15 +647,15 @@ AbstractAssembly::LabelID CodeTransform::labelFromIdentifier(Identifier const& _
{
AbstractAssembly::LabelID label = AbstractAssembly::LabelID(-1);
if (!m_scope->lookup(_identifier.name, GenericVisitor{
[=](Scope::Variable&) { solAssert(false, "Expected label"); },
[=](Scope::Variable&) { yulAssert(false, "Expected label"); },
[&](Scope::Label& _label)
{
label = labelID(_label);
},
[=](Scope::Function&) { solAssert(false, "Expected label"); }
[=](Scope::Function&) { yulAssert(false, "Expected label"); }
}))
{
solAssert(false, "Identifier not found.");
yulAssert(false, "Identifier not found.");
}
return label;
}
@@ -723,15 +723,15 @@ void CodeTransform::finalizeBlock(Block const& _block, int blockStartStackHeight
freeUnusedVariables();
// pop variables
solAssert(m_info.scopes.at(&_block).get() == m_scope, "");
yulAssert(m_info.scopes.at(&_block).get() == m_scope, "");
for (auto const& id: m_scope->identifiers)
if (holds_alternative<Scope::Variable>(id.second))
{
Scope::Variable const& var = std::get<Scope::Variable>(id.second);
if (m_allowStackOpt)
{
solAssert(!m_context->variableStackHeights.count(&var), "");
solAssert(!m_context->variableReferences.count(&var), "");
yulAssert(!m_context->variableStackHeights.count(&var), "");
yulAssert(!m_context->variableReferences.count(&var), "");
m_stackAdjustment++;
}
else
@@ -739,20 +739,20 @@ void CodeTransform::finalizeBlock(Block const& _block, int blockStartStackHeight
}
int deposit = m_assembly.stackHeight() - blockStartStackHeight;
solAssert(deposit == 0, "Invalid stack height at end of block: " + to_string(deposit));
yulAssert(deposit == 0, "Invalid stack height at end of block: " + to_string(deposit));
checkStackHeight(&_block);
}
void CodeTransform::generateMultiAssignment(vector<Identifier> const& _variableNames)
{
solAssert(m_scope, "");
yulAssert(m_scope, "");
for (auto const& variableName: _variableNames | boost::adaptors::reversed)
generateAssignment(variableName);
}
void CodeTransform::generateAssignment(Identifier const& _variableName)
{
solAssert(m_scope, "");
yulAssert(m_scope, "");
if (auto var = m_scope->lookup(_variableName.name))
{
Scope::Variable const& _var = std::get<Scope::Variable>(*var);
@@ -763,7 +763,7 @@ void CodeTransform::generateAssignment(Identifier const& _variableName)
}
else
{
solAssert(
yulAssert(
m_identifierAccess.generateCode,
"Identifier not found and no external access available."
);
@@ -773,9 +773,9 @@ void CodeTransform::generateAssignment(Identifier const& _variableName)
int CodeTransform::variableHeightDiff(Scope::Variable const& _var, YulString _varName, bool _forSwap)
{
solAssert(m_context->variableStackHeights.count(&_var), "");
yulAssert(m_context->variableStackHeights.count(&_var), "");
int heightDiff = m_assembly.stackHeight() - m_context->variableStackHeights[&_var];
solAssert(heightDiff > (_forSwap ? 1 : 0), "Negative stack difference for variable.");
yulAssert(heightDiff > (_forSwap ? 1 : 0), "Negative stack difference for variable.");
int limit = _forSwap ? 17 : 16;
if (heightDiff > limit)
{
@@ -794,15 +794,15 @@ int CodeTransform::variableHeightDiff(Scope::Variable const& _var, YulString _va
void CodeTransform::expectDeposit(int _deposit, int _oldHeight) const
{
solAssert(m_assembly.stackHeight() == _oldHeight + _deposit, "Invalid stack deposit.");
yulAssert(m_assembly.stackHeight() == _oldHeight + _deposit, "Invalid stack deposit.");
}
void CodeTransform::checkStackHeight(void const* _astElement) const
{
solAssert(m_info.stackHeightInfo.count(_astElement), "Stack height for AST element not found.");
yulAssert(m_info.stackHeightInfo.count(_astElement), "Stack height for AST element not found.");
int stackHeightInAnalysis = m_info.stackHeightInfo.at(_astElement);
int stackHeightInCodegen = m_assembly.stackHeight() - m_stackAdjustment;
solAssert(
yulAssert(
stackHeightInAnalysis == stackHeightInCodegen,
"Stack height mismatch between analysis and code generation phase: Analysis: " +
to_string(stackHeightInAnalysis) +
+11 -12
View File
@@ -19,11 +19,10 @@
*/
#include <libyul/backends/evm/NoOutputAssembly.h>
#include <libyul/Exceptions.h>
#include <libevmasm/Instruction.h>
#include <liblangutil/Exceptions.h>
using namespace std;
using namespace dev;
using namespace langutil;
@@ -47,7 +46,7 @@ void NoOutputAssembly::appendLabel(LabelID)
void NoOutputAssembly::appendLabelReference(LabelID)
{
solAssert(!m_evm15, "Cannot use plain label references in EMV1.5 mode.");
yulAssert(!m_evm15, "Cannot use plain label references in EMV1.5 mode.");
appendInstruction(dev::eth::pushInstruction(1));
}
@@ -63,12 +62,12 @@ AbstractAssembly::LabelID NoOutputAssembly::namedLabel(string const&)
void NoOutputAssembly::appendLinkerSymbol(string const&)
{
solAssert(false, "Linker symbols not yet implemented.");
yulAssert(false, "Linker symbols not yet implemented.");
}
void NoOutputAssembly::appendJump(int _stackDiffAfter)
{
solAssert(!m_evm15, "Plain JUMP used for EVM 1.5");
yulAssert(!m_evm15, "Plain JUMP used for EVM 1.5");
appendInstruction(dev::eth::Instruction::JUMP);
m_stackHeight += _stackDiffAfter;
}
@@ -97,22 +96,22 @@ void NoOutputAssembly::appendJumpToIf(LabelID _labelId)
void NoOutputAssembly::appendBeginsub(LabelID, int _arguments)
{
solAssert(m_evm15, "BEGINSUB used for EVM 1.0");
solAssert(_arguments >= 0, "");
yulAssert(m_evm15, "BEGINSUB used for EVM 1.0");
yulAssert(_arguments >= 0, "");
m_stackHeight += _arguments;
}
void NoOutputAssembly::appendJumpsub(LabelID, int _arguments, int _returns)
{
solAssert(m_evm15, "JUMPSUB used for EVM 1.0");
solAssert(_arguments >= 0 && _returns >= 0, "");
yulAssert(m_evm15, "JUMPSUB used for EVM 1.0");
yulAssert(_arguments >= 0 && _returns >= 0, "");
m_stackHeight += _returns - _arguments;
}
void NoOutputAssembly::appendReturnsub(int _returns, int _stackDiffAfter)
{
solAssert(m_evm15, "RETURNSUB used for EVM 1.0");
solAssert(_returns >= 0, "");
yulAssert(m_evm15, "RETURNSUB used for EVM 1.0");
yulAssert(_returns >= 0, "");
m_stackHeight += _stackDiffAfter - _returns;
}
@@ -123,7 +122,7 @@ void NoOutputAssembly::appendAssemblySize()
pair<shared_ptr<AbstractAssembly>, AbstractAssembly::SubID> NoOutputAssembly::createSubAssembly()
{
solAssert(false, "Sub assemblies not implemented.");
yulAssert(false, "Sub assemblies not implemented.");
return {};
}