|
|
@ -42,6 +42,8 @@ class AssemblyItem |
|
|
|
friend class Assembly; |
|
|
|
|
|
|
|
public: |
|
|
|
enum class JumpType { Ordinary, IntoFunction, OutOfFunction }; |
|
|
|
|
|
|
|
AssemblyItem(u256 _push): m_type(Push), m_data(_push) {} |
|
|
|
AssemblyItem(Instruction _i): m_type(Operation), m_data((byte)_i) {} |
|
|
|
AssemblyItem(AssemblyItemType _type, u256 _data = 0): m_type(_type), m_data(_data) {} |
|
|
@ -58,13 +60,18 @@ public: |
|
|
|
int deposit() const; |
|
|
|
|
|
|
|
bool match(AssemblyItem const& _i) const { return _i.m_type == UndefinedItem || (m_type == _i.m_type && (m_type != Operation || m_data == _i.m_data)); } |
|
|
|
void setLocation(SourceLocation const& _location) { m_location = _location;} |
|
|
|
void setLocation(SourceLocation const& _location) { m_location = _location; } |
|
|
|
SourceLocation const& getLocation() const { return m_location; } |
|
|
|
|
|
|
|
void setJumpType(JumpType _jumpType) { m_jumpType = _jumpType; } |
|
|
|
JumpType getJumpType() const { return m_jumpType; } |
|
|
|
std::string getJumpTypeAsString() const; |
|
|
|
|
|
|
|
private: |
|
|
|
AssemblyItemType m_type; |
|
|
|
u256 m_data; |
|
|
|
SourceLocation m_location; |
|
|
|
JumpType m_jumpType; |
|
|
|
}; |
|
|
|
|
|
|
|
using AssemblyItems = std::vector<AssemblyItem>; |
|
|
@ -114,7 +121,7 @@ public: |
|
|
|
void popTo(int _deposit) { while (m_deposit > _deposit) append(Instruction::POP); } |
|
|
|
|
|
|
|
void injectStart(AssemblyItem const& _i); |
|
|
|
std::string out() const { std::stringstream ret; streamRLP(ret); return ret.str(); } |
|
|
|
std::string out() const { std::stringstream ret; stream(ret); return ret.str(); } |
|
|
|
int deposit() const { return m_deposit; } |
|
|
|
void adjustDeposit(int _adjustment) { m_deposit += _adjustment; if (asserts(m_deposit >= 0)) BOOST_THROW_EXCEPTION(InvalidDeposit()); } |
|
|
|
void setDeposit(int _deposit) { m_deposit = _deposit; if (asserts(m_deposit >= 0)) BOOST_THROW_EXCEPTION(InvalidDeposit()); } |
|
|
@ -124,7 +131,7 @@ public: |
|
|
|
|
|
|
|
bytes assemble() const; |
|
|
|
Assembly& optimise(bool _enable); |
|
|
|
std::ostream& streamRLP(std::ostream& _out, std::string const& _prefix = "", const StringMap &_sourceCodes = StringMap()) const; |
|
|
|
std::ostream& stream(std::ostream& _out, std::string const& _prefix = "", const StringMap &_sourceCodes = StringMap()) const; |
|
|
|
|
|
|
|
protected: |
|
|
|
std::string getLocationFromSources(StringMap const& _sourceCodes, SourceLocation const& _location) const; |
|
|
@ -146,7 +153,7 @@ protected: |
|
|
|
|
|
|
|
inline std::ostream& operator<<(std::ostream& _out, Assembly const& _a) |
|
|
|
{ |
|
|
|
_a.streamRLP(_out); |
|
|
|
_a.stream(_out); |
|
|
|
return _out; |
|
|
|
} |
|
|
|
|
|
|
|