aboutsummaryrefslogtreecommitdiffstats
path: root/libyul/backends
diff options
context:
space:
mode:
Diffstat (limited to 'libyul/backends')
-rw-r--r--libyul/backends/evm/AbstractAssembly.h19
-rw-r--r--libyul/backends/evm/EVMAssembly.cpp2
-rw-r--r--libyul/backends/evm/EVMAssembly.h13
-rw-r--r--libyul/backends/evm/EVMCodeTransform.cpp18
-rw-r--r--libyul/backends/evm/EVMCodeTransform.h32
5 files changed, 35 insertions, 49 deletions
diff --git a/libyul/backends/evm/AbstractAssembly.h b/libyul/backends/evm/AbstractAssembly.h
index 5a1140cb..97b1d305 100644
--- a/libyul/backends/evm/AbstractAssembly.h
+++ b/libyul/backends/evm/AbstractAssembly.h
@@ -22,6 +22,7 @@
#pragma once
+#include <libdevcore/Common.h>
#include <libdevcore/CommonData.h>
#include <functional>
@@ -36,14 +37,13 @@ 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.
@@ -61,9 +61,9 @@ public:
/// 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.
@@ -106,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 791b6226..99506317 100644
--- a/libyul/backends/evm/EVMAssembly.cpp
+++ b/libyul/backends/evm/EVMAssembly.cpp
@@ -27,7 +27,7 @@
using namespace std;
using namespace dev;
using namespace langutil;
-using namespace dev::yul;
+using namespace yul;
namespace
{
diff --git a/libyul/backends/evm/EVMAssembly.h b/libyul/backends/evm/EVMAssembly.h
index c9190634..d0a437cc 100644
--- a/libyul/backends/evm/EVMAssembly.h
+++ b/libyul/backends/evm/EVMAssembly.h
@@ -31,8 +31,6 @@ namespace langutil
struct SourceLocation;
}
-namespace dev
-{
namespace yul
{
@@ -48,9 +46,9 @@ public:
/// at the beginning.
int stackHeight() const override { return m_stackHeight; }
/// Append an EVM instruction.
- void appendInstruction(solidity::Instruction _instruction) override;
+ void appendInstruction(dev::solidity::Instruction _instruction) override;
/// Append a constant.
- void appendConstant(u256 const& _constant) override;
+ void appendConstant(dev::u256 const& _constant) override;
/// Append a label.
void appendLabel(LabelID _labelId) override;
/// Append a label reference.
@@ -81,17 +79,17 @@ public:
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;
@@ -99,4 +97,3 @@ private:
};
}
-}
diff --git a/libyul/backends/evm/EVMCodeTransform.cpp b/libyul/backends/evm/EVMCodeTransform.cpp
index 3cf1061a..12abd754 100644
--- a/libyul/backends/evm/EVMCodeTransform.cpp
+++ b/libyul/backends/evm/EVMCodeTransform.cpp
@@ -29,11 +29,9 @@
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 f4696e81..bf195dcd 100644
--- a/libyul/backends/evm/EVMCodeTransform.h
+++ b/libyul/backends/evm/EVMCodeTransform.h
@@ -27,18 +27,14 @@
#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:
};
}
-}