aboutsummaryrefslogtreecommitdiffstats
path: root/libevmasm
diff options
context:
space:
mode:
authorChristian Parpart <christian@ethereum.org>2018-11-15 00:11:55 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-11-22 03:13:44 +0800
commitd67322a1861d60a88151f7c25d6c3478a9a39acf (patch)
treeaf485e48c3436cd24e2db09a6a1bcf445605bae1 /libevmasm
parent80371e2d25ce3eb868d6f75b99a54af9dc6c1583 (diff)
downloaddexon-solidity-d67322a1861d60a88151f7c25d6c3478a9a39acf.tar.gz
dexon-solidity-d67322a1861d60a88151f7c25d6c3478a9a39acf.tar.zst
dexon-solidity-d67322a1861d60a88151f7c25d6c3478a9a39acf.zip
Introduce namespace `langutil` in liblangutil directory.
Also: - Use {}-style list initialisation for SourceLocation construction - Introduce new system includes - Changes the API of the Scanner to take source as value (with move) as opposed to as a reference
Diffstat (limited to 'libevmasm')
-rw-r--r--libevmasm/Assembly.cpp1
-rw-r--r--libevmasm/Assembly.h4
-rw-r--r--libevmasm/AssemblyItem.h12
-rw-r--r--libevmasm/CommonSubexpressionEliminator.cpp1
-rw-r--r--libevmasm/CommonSubexpressionEliminator.h9
-rw-r--r--libevmasm/ControlFlowGraph.cpp2
-rw-r--r--libevmasm/ExpressionClasses.cpp2
-rw-r--r--libevmasm/ExpressionClasses.h7
-rw-r--r--libevmasm/KnownState.cpp1
-rw-r--r--libevmasm/KnownState.h21
-rw-r--r--libevmasm/SimplificationRules.cpp2
-rw-r--r--libevmasm/SimplificationRules.h9
12 files changed, 47 insertions, 24 deletions
diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp
index e63194a0..d80f97c4 100644
--- a/libevmasm/Assembly.cpp
+++ b/libevmasm/Assembly.cpp
@@ -35,6 +35,7 @@
using namespace std;
using namespace dev;
using namespace dev::eth;
+using namespace langutil;
void Assembly::append(Assembly const& _a)
{
diff --git a/libevmasm/Assembly.h b/libevmasm/Assembly.h
index e1993082..d846b475 100644
--- a/libevmasm/Assembly.h
+++ b/libevmasm/Assembly.h
@@ -93,7 +93,7 @@ public:
void setDeposit(int _deposit) { m_deposit = _deposit; assertThrow(m_deposit >= 0, InvalidDeposit, ""); }
/// Changes the source location used for each appended item.
- void setSourceLocation(SourceLocation const& _location) { m_currentSourceLocation = _location; }
+ void setSourceLocation(langutil::SourceLocation const& _location) { m_currentSourceLocation = _location; }
/// Assembles the assembly into bytecode. The assembly should not be modified after this call, since the assembled version is cached.
LinkerObject const& assemble() const;
@@ -178,7 +178,7 @@ protected:
int m_deposit = 0;
- SourceLocation m_currentSourceLocation;
+ langutil::SourceLocation m_currentSourceLocation;
};
inline std::ostream& operator<<(std::ostream& _out, Assembly const& _a)
diff --git a/libevmasm/AssemblyItem.h b/libevmasm/AssemblyItem.h
index 802bde25..a7875171 100644
--- a/libevmasm/AssemblyItem.h
+++ b/libevmasm/AssemblyItem.h
@@ -57,14 +57,14 @@ class AssemblyItem
public:
enum class JumpType { Ordinary, IntoFunction, OutOfFunction };
- AssemblyItem(u256 _push, SourceLocation const& _location = SourceLocation()):
+ AssemblyItem(u256 _push, langutil::SourceLocation const& _location = langutil::SourceLocation()):
AssemblyItem(Push, _push, _location) { }
- AssemblyItem(solidity::Instruction _i, SourceLocation const& _location = SourceLocation()):
+ AssemblyItem(solidity::Instruction _i, langutil::SourceLocation const& _location = langutil::SourceLocation()):
m_type(Operation),
m_instruction(_i),
m_location(_location)
{}
- AssemblyItem(AssemblyItemType _type, u256 _data = 0, SourceLocation const& _location = SourceLocation()):
+ AssemblyItem(AssemblyItemType _type, u256 _data = 0, langutil::SourceLocation const& _location = langutil::SourceLocation()):
m_type(_type),
m_location(_location)
{
@@ -124,8 +124,8 @@ public:
/// @returns true if the assembly item can be used in a functional context.
bool canBeFunctional() const;
- void setLocation(SourceLocation const& _location) { m_location = _location; }
- SourceLocation const& location() const { return m_location; }
+ void setLocation(langutil::SourceLocation const& _location) { m_location = _location; }
+ langutil::SourceLocation const& location() const { return m_location; }
void setJumpType(JumpType _jumpType) { m_jumpType = _jumpType; }
JumpType getJumpType() const { return m_jumpType; }
@@ -140,7 +140,7 @@ private:
AssemblyItemType m_type;
Instruction m_instruction; ///< Only valid if m_type == Operation
std::shared_ptr<u256> m_data; ///< Only valid if m_type != Operation
- SourceLocation m_location;
+ langutil::SourceLocation m_location;
JumpType m_jumpType = JumpType::Ordinary;
/// Pushed value for operations with data to be determined during assembly stage,
/// e.g. PushSubSize, PushTag, PushSub, etc.
diff --git a/libevmasm/CommonSubexpressionEliminator.cpp b/libevmasm/CommonSubexpressionEliminator.cpp
index 04926986..949d2c75 100644
--- a/libevmasm/CommonSubexpressionEliminator.cpp
+++ b/libevmasm/CommonSubexpressionEliminator.cpp
@@ -30,6 +30,7 @@
using namespace std;
using namespace dev;
using namespace dev::eth;
+using namespace langutil;
vector<AssemblyItem> CommonSubexpressionEliminator::getOptimizedItems()
{
diff --git a/libevmasm/CommonSubexpressionEliminator.h b/libevmasm/CommonSubexpressionEliminator.h
index b20de246..eba25db0 100644
--- a/libevmasm/CommonSubexpressionEliminator.h
+++ b/libevmasm/CommonSubexpressionEliminator.h
@@ -34,6 +34,11 @@
#include <libevmasm/SemanticInformation.h>
#include <libevmasm/KnownState.h>
+namespace langutil
+{
+struct SourceLocation;
+}
+
namespace dev
{
namespace eth
@@ -137,10 +142,10 @@ private:
bool removeStackTopIfPossible();
/// Appends a dup instruction to m_generatedItems to retrieve the element at the given stack position.
- void appendDup(int _fromPosition, SourceLocation const& _location);
+ void appendDup(int _fromPosition, langutil::SourceLocation const& _location);
/// Appends a swap instruction to m_generatedItems to retrieve the element at the given stack position.
/// @note this might also remove the last item if it exactly the same swap instruction.
- void appendOrRemoveSwap(int _fromPosition, SourceLocation const& _location);
+ void appendOrRemoveSwap(int _fromPosition, langutil::SourceLocation const& _location);
/// Appends the given assembly item.
void appendItem(AssemblyItem const& _item);
diff --git a/libevmasm/ControlFlowGraph.cpp b/libevmasm/ControlFlowGraph.cpp
index 86f16d48..d62f5436 100644
--- a/libevmasm/ControlFlowGraph.cpp
+++ b/libevmasm/ControlFlowGraph.cpp
@@ -275,7 +275,7 @@ void ControlFlowGraph::gatherKnowledge()
//@todo in the case of JUMPI, add knowledge about the condition to the state
// (for both values of the condition)
set<u256> tags = state->tagsInExpression(
- state->stackElement(state->stackHeight(), SourceLocation())
+ state->stackElement(state->stackHeight(), langutil::SourceLocation{})
);
state->feedItem(m_items.at(pc++));
diff --git a/libevmasm/ExpressionClasses.cpp b/libevmasm/ExpressionClasses.cpp
index 42a1819a..abbbbc2c 100644
--- a/libevmasm/ExpressionClasses.cpp
+++ b/libevmasm/ExpressionClasses.cpp
@@ -34,7 +34,7 @@
using namespace std;
using namespace dev;
using namespace dev::eth;
-
+using namespace langutil;
bool ExpressionClasses::Expression::operator<(ExpressionClasses::Expression const& _other) const
{
diff --git a/libevmasm/ExpressionClasses.h b/libevmasm/ExpressionClasses.h
index df8082f9..a34844c5 100644
--- a/libevmasm/ExpressionClasses.h
+++ b/libevmasm/ExpressionClasses.h
@@ -31,6 +31,11 @@
#include <memory>
#include <set>
+namespace langutil
+{
+struct SourceLocation;
+}
+
namespace dev
{
namespace eth
@@ -82,7 +87,7 @@ public:
void forceEqual(Id _id, AssemblyItem const& _item, Ids const& _arguments, bool _copyItem = true);
/// @returns the id of a new class which is different to all other classes.
- Id newClass(SourceLocation const& _location);
+ Id newClass(langutil::SourceLocation const& _location);
/// @returns true if the values of the given classes are known to be different (on every input).
/// @note that this function might still return false for some different inputs.
diff --git a/libevmasm/KnownState.cpp b/libevmasm/KnownState.cpp
index b6c1bcc9..a5546e61 100644
--- a/libevmasm/KnownState.cpp
+++ b/libevmasm/KnownState.cpp
@@ -29,6 +29,7 @@
using namespace std;
using namespace dev;
using namespace dev::eth;
+using namespace langutil;
ostream& KnownState::stream(ostream& _out) const
{
diff --git a/libevmasm/KnownState.h b/libevmasm/KnownState.h
index cd50550e..3ab1c4b1 100644
--- a/libevmasm/KnownState.h
+++ b/libevmasm/KnownState.h
@@ -46,6 +46,11 @@
#include <libevmasm/ExpressionClasses.h>
#include <libevmasm/SemanticInformation.h>
+namespace langutil
+{
+struct SourceLocation;
+}
+
namespace dev
{
namespace eth
@@ -121,9 +126,9 @@ public:
/// Retrieves the current equivalence class fo the given stack element (or generates a new
/// one if it does not exist yet).
- Id stackElement(int _stackHeight, SourceLocation const& _location);
+ Id stackElement(int _stackHeight, langutil::SourceLocation const& _location);
/// @returns the stackElement relative to the current stack height.
- Id relativeStackElement(int _stackOffset, SourceLocation const& _location = SourceLocation());
+ Id relativeStackElement(int _stackOffset, langutil::SourceLocation const& _location = {});
/// @returns its set of tags if the given expression class is a known tag union; returns a set
/// containing the tag if it is a PushTag expression and the empty set otherwise.
@@ -142,22 +147,22 @@ private:
/// Assigns a new equivalence class to the next sequence number of the given stack element.
void setStackElement(int _stackHeight, Id _class);
/// Swaps the given stack elements in their next sequence number.
- void swapStackElements(int _stackHeightA, int _stackHeightB, SourceLocation const& _location);
+ void swapStackElements(int _stackHeightA, int _stackHeightB, langutil::SourceLocation const& _location);
/// Increments the sequence number, deletes all storage information that might be overwritten
/// and stores the new value at the given slot.
/// @returns the store operation, which might be invalid if storage was not modified
- StoreOperation storeInStorage(Id _slot, Id _value, SourceLocation const& _location);
+ StoreOperation storeInStorage(Id _slot, Id _value, langutil::SourceLocation const& _location);
/// Retrieves the current value at the given slot in storage or creates a new special sload class.
- Id loadFromStorage(Id _slot, SourceLocation const& _location);
+ Id loadFromStorage(Id _slot, langutil::SourceLocation const& _location);
/// Increments the sequence number, deletes all memory information that might be overwritten
/// and stores the new value at the given slot.
/// @returns the store operation, which might be invalid if memory was not modified
- StoreOperation storeInMemory(Id _slot, Id _value, SourceLocation const& _location);
+ StoreOperation storeInMemory(Id _slot, Id _value, langutil::SourceLocation const& _location);
/// Retrieves the current value at the given slot in memory or creates a new special mload class.
- Id loadFromMemory(Id _slot, SourceLocation const& _location);
+ Id loadFromMemory(Id _slot, langutil::SourceLocation const& _location);
/// Finds or creates a new expression that applies the Keccak-256 hash function to the contents in memory.
- Id applyKeccak256(Id _start, Id _length, SourceLocation const& _location);
+ Id applyKeccak256(Id _start, Id _length, langutil::SourceLocation const& _location);
/// @returns a new or already used Id representing the given set of tags.
Id tagUnion(std::set<u256> _tags);
diff --git a/libevmasm/SimplificationRules.cpp b/libevmasm/SimplificationRules.cpp
index 120d1787..1dce5f1e 100644
--- a/libevmasm/SimplificationRules.cpp
+++ b/libevmasm/SimplificationRules.cpp
@@ -38,7 +38,7 @@
using namespace std;
using namespace dev;
using namespace dev::eth;
-
+using namespace langutil;
SimplificationRule<Pattern> const* Rules::findFirstMatch(
Expression const& _expr,
diff --git a/libevmasm/SimplificationRules.h b/libevmasm/SimplificationRules.h
index fbe5a2b0..fc45a46c 100644
--- a/libevmasm/SimplificationRules.h
+++ b/libevmasm/SimplificationRules.h
@@ -31,6 +31,11 @@
#include <functional>
#include <vector>
+namespace langutil
+{
+struct SourceLocation;
+}
+
namespace dev
{
namespace eth
@@ -97,7 +102,7 @@ public:
unsigned matchGroup() const { return m_matchGroup; }
bool matches(Expression const& _expr, ExpressionClasses const& _classes) const;
- AssemblyItem toAssemblyItem(SourceLocation const& _location) const;
+ AssemblyItem toAssemblyItem(langutil::SourceLocation const& _location) const;
std::vector<Pattern> arguments() const { return m_arguments; }
/// @returns the id of the matched expression if this pattern is part of a match group.
@@ -135,7 +140,7 @@ struct ExpressionTemplate
{
using Expression = ExpressionClasses::Expression;
using Id = ExpressionClasses::Id;
- explicit ExpressionTemplate(Pattern const& _pattern, SourceLocation const& _location);
+ explicit ExpressionTemplate(Pattern const& _pattern, langutil::SourceLocation const& _location);
std::string toString() const;
bool hasId = false;
/// Id of the matched expression, if available.