diff options
author | Gav Wood <i@gavwood.com> | 2014-05-27 01:41:46 +0800 |
---|---|---|
committer | Gav Wood <i@gavwood.com> | 2014-05-27 01:41:46 +0800 |
commit | 51e6c251641eef12ba93b725974faa35b514d636 (patch) | |
tree | 9113f63687347c7d5a61c5bb2db61ffe4d800da4 /CodeFragment.h | |
parent | 8e3e592ec6a3b39835e540766774025e3f34c590 (diff) | |
download | dexon-solidity-51e6c251641eef12ba93b725974faa35b514d636.tar dexon-solidity-51e6c251641eef12ba93b725974faa35b514d636.tar.gz dexon-solidity-51e6c251641eef12ba93b725974faa35b514d636.tar.bz2 dexon-solidity-51e6c251641eef12ba93b725974faa35b514d636.tar.lz dexon-solidity-51e6c251641eef12ba93b725974faa35b514d636.tar.xz dexon-solidity-51e6c251641eef12ba93b725974faa35b514d636.tar.zst dexon-solidity-51e6c251641eef12ba93b725974faa35b514d636.zip |
New Assembler.
Diffstat (limited to 'CodeFragment.h')
-rw-r--r-- | CodeFragment.h | 51 |
1 files changed, 7 insertions, 44 deletions
diff --git a/CodeFragment.h b/CodeFragment.h index 9f312cda..64760484 100644 --- a/CodeFragment.h +++ b/CodeFragment.h @@ -23,7 +23,7 @@ #include <libethsupport/Common.h> #include <libethcore/Instruction.h> -#include "CodeLocation.h" +#include "Assembly.h" #include "Exceptions.h" namespace boost { namespace spirit { class utree; } } @@ -36,60 +36,23 @@ class CompilerState; class CodeFragment { - friend class CodeLocation; - public: + CodeFragment() {} CodeFragment(sp::utree const& _t, CompilerState& _s, bool _allowASM = false); - CodeFragment(bytes const& _c = bytes()): m_code(_c) {} static CodeFragment compile(std::string const& _src, CompilerState& _s); - /// Consolidates data and returns code. - bytes const& code() { optimise(); consolidateData(); return m_code; } - - unsigned appendPush(u256 _l); - void appendFragment(CodeFragment const& _f); - void appendFragment(CodeFragment const& _f, unsigned _i); - void appendInstruction(Instruction _i); - - CodeLocation appendPushLocation(unsigned _l = 0); - void appendPushLocation(CodeLocation _l) { assert(_l.m_f == this); appendPushLocation(_l.m_pos); } - void appendPushDataLocation(bytes const& _data); - - CodeLocation appendJump() { auto ret = appendPushLocation(0); appendInstruction(Instruction::JUMP); return ret; } - CodeLocation appendJumpI() { auto ret = appendPushLocation(0); appendInstruction(Instruction::JUMPI); return ret; } - CodeLocation appendJump(CodeLocation _l) { auto ret = appendPushLocation(_l.m_pos); appendInstruction(Instruction::JUMP); return ret; } - CodeLocation appendJumpI(CodeLocation _l) { auto ret = appendPushLocation(_l.m_pos); appendInstruction(Instruction::JUMPI); return ret; } - - void appendFile(std::string const& _fn); + /// Consolidates data and compiles code. + bytes code() const { return m_asm.assemble(); } - std::string asPushedString() const; - - void onePath() { assert(!m_totalDeposit && !m_baseDeposit); m_baseDeposit = m_deposit; m_totalDeposit = INT_MAX; } - void otherPath() { donePath(); m_totalDeposit = m_deposit; m_deposit = m_baseDeposit; } - void donePaths() { donePath(); m_totalDeposit = m_baseDeposit = 0; } - void ignored() { m_baseDeposit = m_deposit; } - void endIgnored() { m_deposit = m_baseDeposit; m_baseDeposit = 0; } - - bool operator==(CodeFragment const& _f) const { return _f.m_code == m_code && _f.m_data == m_data; } - bool operator!=(CodeFragment const& _f) const { return !operator==(_f); } - unsigned size() const { return m_code.size(); } - - void consolidateData(); - void optimise(); + /// Consolidates data and compiles code. + std::string assembly() const { return m_asm.out(); } private: template <class T> void error() const { throw T(); } void constructOperation(sp::utree const& _t, CompilerState& _s); - void donePath() { if (m_totalDeposit != INT_MAX && m_totalDeposit != m_deposit) error<InvalidDeposit>(); } - - int m_deposit = 0; - int m_baseDeposit = 0; - int m_totalDeposit = 0; - bytes m_code; - std::vector<unsigned> m_locs; - std::multimap<bytes, unsigned> m_data; + Assembly m_asm; }; static const CodeFragment NullCodeFragment; |