aboutsummaryrefslogtreecommitdiffstats
path: root/libyul/backends
diff options
context:
space:
mode:
Diffstat (limited to 'libyul/backends')
-rw-r--r--libyul/backends/evm/AbstractAssembly.h27
-rw-r--r--libyul/backends/evm/EVMAssembly.cpp5
-rw-r--r--libyul/backends/evm/EVMAssembly.h44
-rw-r--r--libyul/backends/evm/EVMCodeTransform.cpp24
-rw-r--r--libyul/backends/evm/EVMCodeTransform.h36
5 files changed, 66 insertions, 70 deletions
diff --git a/libyul/backends/evm/AbstractAssembly.h b/libyul/backends/evm/AbstractAssembly.h
index d75058f7..97b1d305 100644
--- a/libyul/backends/evm/AbstractAssembly.h
+++ b/libyul/backends/evm/AbstractAssembly.h
@@ -22,24 +22,28 @@
#pragma once
+#include <libdevcore/Common.h>
#include <libdevcore/CommonData.h>
#include <functional>
-namespace dev
+namespace langutil
{
struct SourceLocation;
+}
+
+namespace dev
+{
namespace solidity
{
enum class Instruction: uint8_t;
-namespace assembly
-{
-struct Instruction;
-struct Identifier;
}
}
+
namespace yul
{
+struct Instruction;
+struct Identifier;
///
/// Assembly class that abstracts both the libevmasm assembly and the new Yul assembly.
@@ -52,14 +56,14 @@ public:
virtual ~AbstractAssembly() {}
/// Set a new source location valid starting from the next instruction.
- virtual void setSourceLocation(SourceLocation const& _location) = 0;
+ virtual void setSourceLocation(langutil::SourceLocation const& _location) = 0;
/// Retrieve the current height of the stack. This does not have to be zero
/// at the beginning.
virtual int stackHeight() const = 0;
/// Append an EVM instruction.
- virtual void appendInstruction(solidity::Instruction _instruction) = 0;
+ virtual void appendInstruction(dev::solidity::Instruction _instruction) = 0;
/// Append a constant.
- virtual void appendConstant(u256 const& _constant) = 0;
+ virtual void appendConstant(dev::u256 const& _constant) = 0;
/// Append a label.
virtual void appendLabel(LabelID _labelId) = 0;
/// Append a label reference.
@@ -102,18 +106,15 @@ enum class IdentifierContext { LValue, RValue };
/// to inline assembly (not used in standalone assembly mode).
struct ExternalIdentifierAccess
{
- using Resolver = std::function<size_t(solidity::assembly::Identifier const&, IdentifierContext, bool /*_crossesFunctionBoundary*/)>;
+ using Resolver = std::function<size_t(Identifier const&, IdentifierContext, bool /*_crossesFunctionBoundary*/)>;
/// Resolve an external reference given by the identifier in the given context.
/// @returns the size of the value (number of stack slots) or size_t(-1) if not found.
Resolver resolve;
- using CodeGenerator = std::function<void(solidity::assembly::Identifier const&, IdentifierContext, yul::AbstractAssembly&)>;
+ using CodeGenerator = std::function<void(Identifier const&, IdentifierContext, yul::AbstractAssembly&)>;
/// Generate code for retrieving the value (rvalue context) or storing the value (lvalue context)
/// of an identifier. The code should be appended to the assembly. In rvalue context, the value is supposed
/// to be put onto the stack, in lvalue context, the value is assumed to be at the top of the stack.
CodeGenerator generateCode;
};
-
-
-}
}
diff --git a/libyul/backends/evm/EVMAssembly.cpp b/libyul/backends/evm/EVMAssembly.cpp
index b37a3231..99506317 100644
--- a/libyul/backends/evm/EVMAssembly.cpp
+++ b/libyul/backends/evm/EVMAssembly.cpp
@@ -22,11 +22,12 @@
#include <libevmasm/Instruction.h>
-#include <libsolidity/interface/Exceptions.h>
+#include <liblangutil/Exceptions.h>
using namespace std;
using namespace dev;
-using namespace dev::yul;
+using namespace langutil;
+using namespace yul;
namespace
{
diff --git a/libyul/backends/evm/EVMAssembly.h b/libyul/backends/evm/EVMAssembly.h
index 556ed5a5..d0a437cc 100644
--- a/libyul/backends/evm/EVMAssembly.h
+++ b/libyul/backends/evm/EVMAssembly.h
@@ -26,8 +26,11 @@
#include <map>
-namespace dev
+namespace langutil
{
+struct SourceLocation;
+}
+
namespace yul
{
@@ -38,55 +41,55 @@ public:
virtual ~EVMAssembly() {}
/// Set a new source location valid starting from the next instruction.
- virtual void setSourceLocation(SourceLocation const& _location) override;
+ void setSourceLocation(langutil::SourceLocation const& _location) override;
/// Retrieve the current height of the stack. This does not have to be zero
/// at the beginning.
- virtual int stackHeight() const override { return m_stackHeight; }
+ int stackHeight() const override { return m_stackHeight; }
/// Append an EVM instruction.
- virtual void appendInstruction(solidity::Instruction _instruction) override;
+ void appendInstruction(dev::solidity::Instruction _instruction) override;
/// Append a constant.
- virtual void appendConstant(u256 const& _constant) override;
+ void appendConstant(dev::u256 const& _constant) override;
/// Append a label.
- virtual void appendLabel(LabelID _labelId) override;
+ void appendLabel(LabelID _labelId) override;
/// Append a label reference.
- virtual void appendLabelReference(LabelID _labelId) override;
+ void appendLabelReference(LabelID _labelId) override;
/// Generate a new unique label.
- virtual LabelID newLabelId() override;
+ LabelID newLabelId() override;
/// Returns a label identified by the given name. Creates it if it does not yet exist.
- virtual LabelID namedLabel(std::string const& _name) override;
+ LabelID namedLabel(std::string const& _name) override;
/// Append a reference to a to-be-linked symbol.
/// Currently, we assume that the value is always a 20 byte number.
- virtual void appendLinkerSymbol(std::string const& _name) override;
+ void appendLinkerSymbol(std::string const& _name) override;
/// Append a jump instruction.
/// @param _stackDiffAfter the stack adjustment after this instruction.
- virtual void appendJump(int _stackDiffAfter) override;
+ void appendJump(int _stackDiffAfter) override;
/// Append a jump-to-immediate operation.
- virtual void appendJumpTo(LabelID _labelId, int _stackDiffAfter) override;
+ void appendJumpTo(LabelID _labelId, int _stackDiffAfter) override;
/// Append a jump-to-if-immediate operation.
- virtual void appendJumpToIf(LabelID _labelId) override;
+ void appendJumpToIf(LabelID _labelId) override;
/// Start a subroutine.
- virtual void appendBeginsub(LabelID _labelId, int _arguments) override;
+ void appendBeginsub(LabelID _labelId, int _arguments) override;
/// Call a subroutine.
- virtual void appendJumpsub(LabelID _labelId, int _arguments, int _returns) override;
+ void appendJumpsub(LabelID _labelId, int _arguments, int _returns) override;
/// Return from a subroutine.
- virtual void appendReturnsub(int _returns, int _stackDiffAfter) override;
+ void appendReturnsub(int _returns, int _stackDiffAfter) override;
/// Append the assembled size as a constant.
- virtual void appendAssemblySize() override;
+ void appendAssemblySize() override;
/// Resolves references inside the bytecode and returns the linker object.
- eth::LinkerObject finalize();
+ dev::eth::LinkerObject finalize();
private:
void setLabelToCurrentPosition(AbstractAssembly::LabelID _labelId);
void appendLabelReferenceInternal(AbstractAssembly::LabelID _labelId);
- void updateReference(size_t pos, size_t size, u256 value);
+ void updateReference(size_t pos, size_t size, dev::u256 value);
bool m_evm15 = false; ///< if true, switch to evm1.5 mode
LabelID m_nextLabelId = 0;
int m_stackHeight = 0;
- bytes m_bytecode;
+ dev::bytes m_bytecode;
std::map<std::string, LabelID> m_namedLabels;
std::map<LabelID, size_t> m_labelPositions;
std::map<size_t, LabelID> m_labelReferences;
@@ -94,4 +97,3 @@ private:
};
}
-}
diff --git a/libyul/backends/evm/EVMCodeTransform.cpp b/libyul/backends/evm/EVMCodeTransform.cpp
index 650a8c0a..12abd754 100644
--- a/libyul/backends/evm/EVMCodeTransform.cpp
+++ b/libyul/backends/evm/EVMCodeTransform.cpp
@@ -20,20 +20,18 @@
#include <libyul/backends/evm/EVMCodeTransform.h>
-#include <libsolidity/inlineasm/AsmAnalysisInfo.h>
-#include <libsolidity/inlineasm/AsmData.h>
+#include <libyul/AsmAnalysisInfo.h>
+#include <libyul/AsmData.h>
-#include <libsolidity/interface/Exceptions.h>
+#include <liblangutil/Exceptions.h>
#include <boost/range/adaptor/reversed.hpp>
using namespace std;
using namespace dev;
-using namespace dev::yul;
+using namespace yul;
using namespace dev::solidity;
-using Scope = dev::solidity::assembly::Scope;
-
void CodeTransform::operator()(VariableDeclaration const& _varDecl)
{
solAssert(m_scope, "");
@@ -147,7 +145,7 @@ void CodeTransform::operator()(FunctionalInstruction const& _instruction)
solAssert(_instruction.arguments.size() == 1, "");
}
m_assembly.setSourceLocation(_instruction.location);
- auto label = labelFromIdentifier(boost::get<assembly::Identifier>(_instruction.arguments.at(0)));
+ auto label = labelFromIdentifier(boost::get<Identifier>(_instruction.arguments.at(0)));
if (isJumpI)
m_assembly.appendJumpToIf(label);
else
@@ -163,7 +161,7 @@ void CodeTransform::operator()(FunctionalInstruction const& _instruction)
checkStackHeight(&_instruction);
}
-void CodeTransform::operator()(assembly::Identifier const& _identifier)
+void CodeTransform::operator()(Identifier const& _identifier)
{
m_assembly.setSourceLocation(_identifier.location);
// First search internals, then externals.
@@ -197,12 +195,12 @@ void CodeTransform::operator()(assembly::Identifier const& _identifier)
checkStackHeight(&_identifier);
}
-void CodeTransform::operator()(assembly::Literal const& _literal)
+void CodeTransform::operator()(Literal const& _literal)
{
m_assembly.setSourceLocation(_literal.location);
- if (_literal.kind == assembly::LiteralKind::Number)
+ if (_literal.kind == LiteralKind::Number)
m_assembly.appendConstant(u256(_literal.value.str()));
- else if (_literal.kind == assembly::LiteralKind::Boolean)
+ else if (_literal.kind == LiteralKind::Boolean)
{
if (_literal.value.str() == "true")
m_assembly.appendConstant(u256(1));
@@ -217,7 +215,7 @@ void CodeTransform::operator()(assembly::Literal const& _literal)
checkStackHeight(&_literal);
}
-void CodeTransform::operator()(assembly::Instruction const& _instruction)
+void CodeTransform::operator()(yul::Instruction const& _instruction)
{
solAssert(!m_evm15 || _instruction.instruction != solidity::Instruction::JUMP, "Bare JUMP instruction used for EVM1.5");
solAssert(!m_evm15 || _instruction.instruction != solidity::Instruction::JUMPI, "Bare JUMPI instruction used for EVM1.5");
@@ -522,7 +520,7 @@ void CodeTransform::generateAssignment(Identifier const& _variableName)
}
}
-int CodeTransform::variableHeightDiff(solidity::assembly::Scope::Variable const& _var, bool _forSwap) const
+int CodeTransform::variableHeightDiff(Scope::Variable const& _var, bool _forSwap) const
{
solAssert(m_context->variableStackHeights.count(&_var), "");
int heightDiff = m_assembly.stackHeight() - m_context->variableStackHeights[&_var];
diff --git a/libyul/backends/evm/EVMCodeTransform.h b/libyul/backends/evm/EVMCodeTransform.h
index c0de8ad6..d559f85a 100644
--- a/libyul/backends/evm/EVMCodeTransform.h
+++ b/libyul/backends/evm/EVMCodeTransform.h
@@ -20,25 +20,21 @@
#include <libyul/backends/evm/EVMAssembly.h>
-#include <libyul/ASTDataForward.h>
+#include <libyul/AsmDataForward.h>
-#include <libsolidity/inlineasm/AsmScope.h>
+#include <libyul/AsmScope.h>
#include <boost/variant.hpp>
#include <boost/optional.hpp>
-namespace dev
-{
-namespace solidity
+namespace langutil
{
class ErrorReporter;
-namespace assembly
-{
-struct AsmAnalysisInfo;
-}
}
+
namespace yul
{
+struct AsmAnalysisInfo;
class EVMAssembly;
class CodeTransform: public boost::static_visitor<>
@@ -47,8 +43,8 @@ public:
/// Create the code transformer.
/// @param _identifierAccess used to resolve identifiers external to the inline assembly
CodeTransform(
- yul::AbstractAssembly& _assembly,
- solidity::assembly::AsmAnalysisInfo& _analysisInfo,
+ AbstractAssembly& _assembly,
+ AsmAnalysisInfo& _analysisInfo,
bool _yul = false,
bool _evm15 = false,
ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess(),
@@ -69,15 +65,14 @@ public:
protected:
struct Context
{
- using Scope = solidity::assembly::Scope;
std::map<Scope::Label const*, AbstractAssembly::LabelID> labelIDs;
std::map<Scope::Function const*, AbstractAssembly::LabelID> functionEntryIDs;
std::map<Scope::Variable const*, int> variableStackHeights;
};
CodeTransform(
- yul::AbstractAssembly& _assembly,
- solidity::assembly::AsmAnalysisInfo& _analysisInfo,
+ AbstractAssembly& _assembly,
+ AsmAnalysisInfo& _analysisInfo,
bool _yul,
bool _evm15,
ExternalIdentifierAccess const& _identifierAccess,
@@ -116,8 +111,8 @@ private:
AbstractAssembly::LabelID labelFromIdentifier(Identifier const& _identifier);
/// @returns the label ID corresponding to the given label, allocating a new one if
/// necessary.
- AbstractAssembly::LabelID labelID(solidity::assembly::Scope::Label const& _label);
- AbstractAssembly::LabelID functionEntryID(YulString _name, solidity::assembly::Scope::Function const& _function);
+ AbstractAssembly::LabelID labelID(Scope::Label const& _label);
+ AbstractAssembly::LabelID functionEntryID(YulString _name, Scope::Function const& _function);
/// Generates code for an expression that is supposed to return a single value.
void visitExpression(Expression const& _expression);
@@ -133,15 +128,15 @@ private:
/// Determines the stack height difference to the given variables. Throws
/// if it is not yet in scope or the height difference is too large. Returns
/// the (positive) stack height difference otherwise.
- int variableHeightDiff(solidity::assembly::Scope::Variable const& _var, bool _forSwap) const;
+ int variableHeightDiff(Scope::Variable const& _var, bool _forSwap) const;
void expectDeposit(int _deposit, int _oldHeight) const;
void checkStackHeight(void const* _astElement) const;
- yul::AbstractAssembly& m_assembly;
- solidity::assembly::AsmAnalysisInfo& m_info;
- solidity::assembly::Scope* m_scope = nullptr;
+ AbstractAssembly& m_assembly;
+ AsmAnalysisInfo& m_info;
+ Scope* m_scope = nullptr;
bool m_yul = false;
bool m_evm15 = false;
bool m_useNamedLabelsForFunctions = false;
@@ -155,4 +150,3 @@ private:
};
}
-}