diff options
author | Gav Wood <i@gavwood.com> | 2014-10-31 21:32:32 +0800 |
---|---|---|
committer | Gav Wood <i@gavwood.com> | 2014-10-31 21:32:32 +0800 |
commit | 64786387c17fec33e3e9de40387925c10a9dccfb (patch) | |
tree | 7be3c6491497c3f63eaf7a2c26af0acc4d06c00d | |
parent | f6e24989ec929eb7d22486544a0053c4e5bb2e6c (diff) | |
download | dexon-solidity-64786387c17fec33e3e9de40387925c10a9dccfb.tar.gz dexon-solidity-64786387c17fec33e3e9de40387925c10a9dccfb.tar.zst dexon-solidity-64786387c17fec33e3e9de40387925c10a9dccfb.zip |
PoC-7: Instruction set reform
-rw-r--r-- | Assembly.cpp | 2 | ||||
-rw-r--r-- | CodeFragment.cpp | 14 |
2 files changed, 8 insertions, 8 deletions
diff --git a/Assembly.cpp b/Assembly.cpp index 7ad84682..25895e1b 100644 --- a/Assembly.cpp +++ b/Assembly.cpp @@ -251,7 +251,7 @@ Assembly& Assembly::optimise(bool _enable) { { PushSub, Instruction::POP }, [](AssemblyItemsConstRef) -> AssemblyItems { return {}; } }, { { PushSubSize, Instruction::POP }, [](AssemblyItemsConstRef) -> AssemblyItems { return {}; } }, { { Push, PushTag, Instruction::JUMPI }, [](AssemblyItemsConstRef m) -> AssemblyItems { if (m[0].data()) return { m[1], Instruction::JUMP }; else return {}; } }, - { { Instruction::NOT, Instruction::NOT }, [](AssemblyItemsConstRef) -> AssemblyItems { return {}; } }, + { { Instruction::ISZERO, Instruction::ISZERO }, [](AssemblyItemsConstRef) -> AssemblyItems { return {}; } }, }; for (auto const& i: c_simple) diff --git a/CodeFragment.cpp b/CodeFragment.cpp index 56b5d440..47df8f3b 100644 --- a/CodeFragment.cpp +++ b/CodeFragment.cpp @@ -328,7 +328,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) std::map<std::string, Instruction> const c_arith = { { "+", Instruction::ADD }, { "-", Instruction::SUB }, { "*", Instruction::MUL }, { "/", Instruction::DIV }, { "%", Instruction::MOD }, { "&", Instruction::AND }, { "|", Instruction::OR }, { "^", Instruction::XOR } }; std::map<std::string, pair<Instruction, bool>> const c_binary = { { "<", { Instruction::LT, false } }, { "<=", { Instruction::GT, true } }, { ">", { Instruction::GT, false } }, { ">=", { Instruction::LT, true } }, { "S<", { Instruction::SLT, false } }, { "S<=", { Instruction::SGT, true } }, { "S>", { Instruction::SGT, false } }, { "S>=", { Instruction::SLT, true } }, { "=", { Instruction::EQ, false } }, { "!=", { Instruction::EQ, true } } }; - std::map<std::string, Instruction> const c_unary = { { "!", Instruction::NOT } }; + std::map<std::string, Instruction> const c_unary = { { "!", Instruction::ISZERO } }; vector<CodeFragment> code; CompilerState ns = _s; @@ -403,7 +403,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) m_asm.append(code[0].m_asm, 1); m_asm.append(it->second.first); if (it->second.second) - m_asm.append(Instruction::NOT); + m_asm.append(Instruction::ISZERO); } else if (c_unary.count(us)) { @@ -437,7 +437,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) m_asm.append(code[0].m_asm); if (us == "WHEN") - m_asm.append(Instruction::NOT); + m_asm.append(Instruction::ISZERO); auto end = m_asm.appendJumpI(); m_asm.onePath(); m_asm.otherPath(); @@ -452,7 +452,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) auto begin = m_asm.append(); m_asm.append(code[0].m_asm); - m_asm.append(Instruction::NOT); + m_asm.append(Instruction::ISZERO); auto end = m_asm.appendJumpI(); m_asm.append(code[1].m_asm, 0); m_asm.appendJump(begin); @@ -466,7 +466,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) m_asm.append(code[0].m_asm, 0); auto begin = m_asm.append(); m_asm.append(code[1].m_asm); - m_asm.append(Instruction::NOT); + m_asm.append(Instruction::ISZERO); auto end = m_asm.appendJumpI(); m_asm.append(code[3].m_asm, 0); m_asm.append(code[2].m_asm, 0); @@ -502,7 +502,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) requireDeposit(2, 1); m_asm.append(code[2].m_asm, 1); m_asm.append(Instruction::LT); - m_asm.append(Instruction::NOT); + m_asm.append(Instruction::ISZERO); m_asm.append(Instruction::MUL); m_asm.append(Instruction::DUP1); } @@ -525,7 +525,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s) // Check if true - predicate m_asm.append(code[i - 1].m_asm, 1); if (us == "&&") - m_asm.append(Instruction::NOT); + m_asm.append(Instruction::ISZERO); m_asm.appendJumpI(end); } m_asm.append(Instruction::POP); |