Browse Source

merge with develop

cl-refactor
yann300 10 years ago
parent
commit
2a659d4a58
  1. 2
      .gitignore
  2. 70
      alethzero/MainWin.cpp
  3. 2
      alethzero/MainWin.h
  4. 40
      alethzero/OurWebThreeStubServer.cpp
  5. 4
      alethzero/OurWebThreeStubServer.h
  6. 15
      docker/Dockerfile
  7. 18
      eth/main.cpp
  8. 1
      evmjit
  9. 27
      evmjit/CMakeLists.txt
  10. 18
      evmjit/evmcc/CMakeLists.txt
  11. 211
      evmjit/evmcc/evmcc.cpp
  12. 1
      evmjit/evmcc/test/arith/addmod.evm
  13. 12
      evmjit/evmcc/test/arith/addmod.lll
  14. 1
      evmjit/evmcc/test/arith/arith1.evm
  15. 37
      evmjit/evmcc/test/arith/arith1.lll
  16. 1
      evmjit/evmcc/test/arith/arith_bnot.evm
  17. 14
      evmjit/evmcc/test/arith/arith_bnot.lll
  18. 1
      evmjit/evmcc/test/arith/div.evm
  19. 10
      evmjit/evmcc/test/arith/div.lll
  20. 1
      evmjit/evmcc/test/arith/fib1.evm
  21. 57
      evmjit/evmcc/test/arith/fib1.lll
  22. 1
      evmjit/evmcc/test/arith/mul.evm
  23. 13
      evmjit/evmcc/test/arith/mul.lll
  24. 1
      evmjit/evmcc/test/arith/mulmod.evm
  25. 12
      evmjit/evmcc/test/arith/mulmod.lll
  26. 1
      evmjit/evmcc/test/except/badinst1.evm
  27. 1
      evmjit/evmcc/test/ext/calldatacopy1.evm
  28. 13
      evmjit/evmcc/test/ext/calldatacopy1.lll
  29. 1
      evmjit/evmcc/test/ext/calldatacopy2.evm
  30. 13
      evmjit/evmcc/test/ext/calldatacopy2.lll
  31. 1
      evmjit/evmcc/test/ext/codecopy1.evm
  32. 13
      evmjit/evmcc/test/ext/codecopy1.lll
  33. 1
      evmjit/evmcc/test/ext/codecopy2.evm
  34. 13
      evmjit/evmcc/test/ext/codecopy2.lll
  35. 1
      evmjit/evmcc/test/ext/codecopy3.evm
  36. 13
      evmjit/evmcc/test/ext/codecopy3.lll
  37. 1
      evmjit/evmcc/test/ext/ext_test.evm
  38. 55
      evmjit/evmcc/test/ext/ext_test.lll
  39. 1
      evmjit/evmcc/test/ext/extcodecopy1.evm
  40. 11
      evmjit/evmcc/test/ext/extcodecopy1.lll
  41. 1
      evmjit/evmcc/test/ext/store_delete.evm
  42. 9
      evmjit/evmcc/test/ext/store_delete.lll
  43. 1
      evmjit/evmcc/test/ext/store_test.evm
  44. 14
      evmjit/evmcc/test/ext/store_test.lll
  45. 7
      evmjit/evmcc/test/jump/ackermann.ethel
  46. 1
      evmjit/evmcc/test/jump/ackermann.evm
  47. 1
      evmjit/evmcc/test/jump/badindirect1.evm
  48. 9
      evmjit/evmcc/test/jump/badindirect1.lll
  49. 1
      evmjit/evmcc/test/jump/badindirect2.evm
  50. 12
      evmjit/evmcc/test/jump/badindirect2.lll
  51. 1
      evmjit/evmcc/test/jump/badjump1.evm
  52. 6
      evmjit/evmcc/test/jump/badjump1.lll
  53. 1
      evmjit/evmcc/test/jump/badjump2.evm
  54. 9
      evmjit/evmcc/test/jump/badjump2.lll
  55. 5
      evmjit/evmcc/test/jump/call1.ethel
  56. 1
      evmjit/evmcc/test/jump/call1.evm
  57. 5
      evmjit/evmcc/test/jump/call2.ethel
  58. 1
      evmjit/evmcc/test/jump/call2.evm
  59. 5
      evmjit/evmcc/test/jump/fac.ethel
  60. 1
      evmjit/evmcc/test/jump/fac.evm
  61. 5
      evmjit/evmcc/test/jump/fac_tail.ethel
  62. 1
      evmjit/evmcc/test/jump/fac_tail.evm
  63. 6
      evmjit/evmcc/test/jump/fib1.ethel
  64. 1
      evmjit/evmcc/test/jump/fib1.evm
  65. 1
      evmjit/evmcc/test/jump/for1.evm
  66. 3
      evmjit/evmcc/test/jump/for1.lll
  67. 1
      evmjit/evmcc/test/jump/for2.evm
  68. 3
      evmjit/evmcc/test/jump/for2.lll
  69. 1
      evmjit/evmcc/test/jump/if1.ethel
  70. 1
      evmjit/evmcc/test/jump/if1.evm
  71. 1
      evmjit/evmcc/test/jump/if2.ethel
  72. 1
      evmjit/evmcc/test/jump/if2.evm
  73. 1
      evmjit/evmcc/test/jump/indirect1.evm
  74. 13
      evmjit/evmcc/test/jump/indirect1.lll
  75. 1
      evmjit/evmcc/test/jump/indirect2.evm
  76. 19
      evmjit/evmcc/test/jump/indirect2.lll
  77. 1
      evmjit/evmcc/test/jump/indirect3.evm
  78. 14
      evmjit/evmcc/test/jump/indirect3.lll
  79. 1
      evmjit/evmcc/test/jump/indirect4.evm
  80. 15
      evmjit/evmcc/test/jump/indirect4.lll
  81. 1
      evmjit/evmcc/test/jump/jump1.evm
  82. 11
      evmjit/evmcc/test/jump/jump1.lll
  83. 1
      evmjit/evmcc/test/jump/jump2.evm
  84. 10
      evmjit/evmcc/test/jump/jump2.lll
  85. 1
      evmjit/evmcc/test/jump/jump3.evm
  86. 10
      evmjit/evmcc/test/jump/jump3.lll
  87. 1
      evmjit/evmcc/test/jump/jump4.evm
  88. 17
      evmjit/evmcc/test/jump/jump4.lll
  89. 1
      evmjit/evmcc/test/jump/jump5.evm
  90. 16
      evmjit/evmcc/test/jump/jump5.lll
  91. 1
      evmjit/evmcc/test/jump/jump6.evm
  92. 32
      evmjit/evmcc/test/jump/jump6.lll
  93. 1
      evmjit/evmcc/test/jump/jumpi_at_the_end.evm
  94. 1
      evmjit/evmcc/test/jump/jumpi_at_the_end.lll
  95. 1
      evmjit/evmcc/test/jump/loop1.evm
  96. 27
      evmjit/evmcc/test/jump/loop1.lll
  97. 1
      evmjit/evmcc/test/jump/loop2.evm
  98. 28
      evmjit/evmcc/test/jump/loop2.lll
  99. 4
      evmjit/evmcc/test/jump/rec1.ethel
  100. 1
      evmjit/evmcc/test/jump/rec1.evm

2
.gitignore

@ -64,3 +64,5 @@ profile
DerivedData DerivedData
project.pbxproj project.pbxproj
evmjit

70
alethzero/MainWin.cpp

@ -106,6 +106,8 @@ static QString contentsOfQResource(std::string const& res)
} }
Address c_config = Address("661005d2720d855f1d9976f88bb10c1a3398c77f"); Address c_config = Address("661005d2720d855f1d9976f88bb10c1a3398c77f");
Address c_newConfig = Address("d5f9d8d94886e70b06e474c3fb14fd43e2f23970");
Address c_nameReg = Address("ddd1cea741d548f90d86fb87a3ae6492e18c03a1");
Main::Main(QWidget *parent) : Main::Main(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
@ -448,8 +450,29 @@ static Public stringToPublic(QString const& _a)
return Public(); return Public();
} }
static Address g_newNameReg;
QString Main::pretty(dev::Address _a) const QString Main::pretty(dev::Address _a) const
{ {
static std::map<Address, QString> s_memos;
if (!s_memos.count(_a))
{
if (!g_newNameReg)
g_newNameReg = abiOut<Address>(ethereum()->call(c_newConfig, abiIn(1, (u256)1)));
if (g_newNameReg)
{
QString s = QString::fromStdString(toString(abiOut<string32>(ethereum()->call(g_newNameReg, abiIn(2, _a)))));
s_memos[_a] = s;
if (s.size())
return s;
}
}
else
if (s_memos[_a].size())
return s_memos[_a];
h256 n; h256 n;
if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0)) if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0))
@ -469,19 +492,47 @@ QString Main::render(dev::Address _a) const
return QString::fromStdString(_a.abridged()); return QString::fromStdString(_a.abridged());
} }
Address Main::fromString(QString const& _a) const string32 fromString(std::string const& _s)
{
string32 ret;
for (unsigned i = 0; i < 32 && i <= _s.size(); ++i)
ret[i] = i < _s.size() ? _s[i] : 0;
return ret;
}
Address Main::fromString(QString const& _n) const
{ {
if (_a == "(Create Contract)") if (_n == "(Create Contract)")
return Address(); return Address();
string sn = _a.toStdString(); static std::map<QString, Address> s_memos;
if (!s_memos.count(_n))
{
if (!g_newNameReg)
g_newNameReg = abiOut<Address>(ethereum()->call(c_newConfig, abiIn(1, (u256)1)));
if (g_newNameReg)
{
Address a = abiOut<Address>(ethereum()->call(g_newNameReg, abiIn(0, ::fromString(_n.toStdString()))));
s_memos[_n] = a;
if (a)
return a;
}
}
else
if (s_memos[_n])
return s_memos[_n];
string sn = _n.toStdString();
if (sn.size() > 32) if (sn.size() > 32)
sn.resize(32); sn.resize(32);
h256 n; h256 n;
memcpy(n.data(), sn.data(), sn.size()); memcpy(n.data(), sn.data(), sn.size());
memset(n.data() + sn.size(), 0, 32 - sn.size()); memset(n.data() + sn.size(), 0, 32 - sn.size());
if (_a.size()) if (_n.size())
{ {
if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0)) if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0))
if (h256 a = ethereum()->stateAt(nameReg, n)) if (h256 a = ethereum()->stateAt(nameReg, n))
return right160(a); return right160(a);
@ -489,8 +540,9 @@ Address Main::fromString(QString const& _a) const
if (h256 a = ethereum()->stateAt(m_nameReg, n)) if (h256 a = ethereum()->stateAt(m_nameReg, n))
return right160(a); return right160(a);
} }
if (_a.size() == 40)
return Address(fromHex(_a.toStdString())); if (_n.size() == 40)
return Address(fromHex(_n.toStdString()));
else else
return Address(); return Address();
} }
@ -1350,7 +1402,7 @@ void Main::on_debugCurrent_triggered()
{ {
unsigned txi = item->data(Qt::UserRole + 1).toInt(); unsigned txi = item->data(Qt::UserRole + 1).toInt();
m_executiveState = ethereum()->state(txi + 1, h); m_executiveState = ethereum()->state(txi + 1, h);
m_currentExecution = unique_ptr<Executive>(new Executive(m_executiveState, 0)); m_currentExecution = unique_ptr<Executive>(new Executive(m_executiveState, ethereum()->blockChain(), 0));
Transaction t = m_executiveState.pending()[txi]; Transaction t = m_executiveState.pending()[txi];
m_executiveState = m_executiveState.fromPending(txi); m_executiveState = m_executiveState.fromPending(txi);
auto r = t.rlp(); auto r = t.rlp();
@ -1423,7 +1475,7 @@ void Main::populateDebugger(dev::bytesConstRef _r)
m_history.append(WorldState({steps, ext.myAddress, vm.curPC(), inst, newMemSize, vm.gas(), lastHash, lastDataHash, vm.stack(), vm.memory(), gasCost, ext.state().storage(ext.myAddress), levels})); m_history.append(WorldState({steps, ext.myAddress, vm.curPC(), inst, newMemSize, vm.gas(), lastHash, lastDataHash, vm.stack(), vm.memory(), gasCost, ext.state().storage(ext.myAddress), levels}));
}; };
m_currentExecution->go(onOp); m_currentExecution->go(onOp);
m_currentExecution->finalize(onOp); m_currentExecution->finalize();
initDebugger(); initDebugger();
updateDebugger(); updateDebugger();
} }
@ -1803,7 +1855,7 @@ void Main::on_debug_clicked()
{ {
Secret s = i.secret(); Secret s = i.secret();
m_executiveState = ethereum()->postState(); m_executiveState = ethereum()->postState();
m_currentExecution = unique_ptr<Executive>(new Executive(m_executiveState, 0)); m_currentExecution = unique_ptr<Executive>(new Executive(m_executiveState, ethereum()->blockChain(), 0));
Transaction t = isCreation() ? Transaction t = isCreation() ?
Transaction(value(), gasPrice(), ui->gas->value(), m_data, m_executiveState.transactionsFrom(dev::toAddress(s)), s) : Transaction(value(), gasPrice(), ui->gas->value(), m_data, m_executiveState.transactionsFrom(dev::toAddress(s)), s) :
Transaction(value(), gasPrice(), ui->gas->value(), fromString(ui->destination->currentText()), m_data, m_executiveState.transactionsFrom(dev::toAddress(s)), s); Transaction(value(), gasPrice(), ui->gas->value(), fromString(ui->destination->currentText()), m_data, m_executiveState.transactionsFrom(dev::toAddress(s)), s);

2
alethzero/MainWin.h

@ -78,6 +78,8 @@ public:
dev::eth::Client* ethereum() const { return m_webThree->ethereum(); } dev::eth::Client* ethereum() const { return m_webThree->ethereum(); }
std::shared_ptr<dev::shh::WhisperHost> whisper() const { return m_webThree->whisper(); } std::shared_ptr<dev::shh::WhisperHost> whisper() const { return m_webThree->whisper(); }
std::string lookupNatSpec(dev::h256 const& _contractCode) const { (void)_contractCode; return ""; } // TODO: actually implement with leveldb & a UI.
QList<dev::KeyPair> owned() const { return m_myIdentities + m_myKeys; } QList<dev::KeyPair> owned() const { return m_myIdentities + m_myKeys; }
public slots: public slots:

40
alethzero/OurWebThreeStubServer.cpp

@ -20,12 +20,16 @@
*/ */
#include "OurWebThreeStubServer.h" #include "OurWebThreeStubServer.h"
#include <QMessageBox>
#include <libwebthree/WebThree.h>
#include "MainWin.h"
using namespace std; using namespace std;
using namespace dev; using namespace dev;
using namespace dev::eth; using namespace dev::eth;
OurWebThreeStubServer::OurWebThreeStubServer(jsonrpc::AbstractServerConnector& _conn, dev::WebThreeDirect& _web3, std::vector<dev::KeyPair> const& _accounts): OurWebThreeStubServer::OurWebThreeStubServer(jsonrpc::AbstractServerConnector& _conn, dev::WebThreeDirect& _web3, std::vector<dev::KeyPair> const& _accounts):
WebThreeStubServer(_conn, _web3, _accounts) WebThreeStubServer(_conn, _web3, _accounts), m_web3(&_web3)
{} {}
std::string OurWebThreeStubServer::shh_newIdentity() std::string OurWebThreeStubServer::shh_newIdentity()
@ -34,3 +38,37 @@ std::string OurWebThreeStubServer::shh_newIdentity()
emit onNewId(QString::fromStdString(toJS(kp.sec()))); emit onNewId(QString::fromStdString(toJS(kp.sec())));
return toJS(kp.pub()); return toJS(kp.pub());
} }
bool OurWebThreeStubServer::authenticate(dev::TransactionSkeleton const& _t) const
{
return true;
// To get the balance of the sender
cnote << "Sender has ETH: " << m_web3->ethereum()->postState().balance(_t.from);
Main* main; // don't know this yet, should be a member and set at construction time by Main, who will construct us.
h256 contractCodeHash = m_web3->ethereum()->postState().codeHash(_t.to);
if (contractCodeHash == EmptySHA3)
{
// recipient has no code - nothing special about this transaction.
// TODO: show basic message for value transfer.
return true; // or whatever.
}
std::string natspecJson = main->lookupNatSpec(contractCodeHash);
if (natspecJson.empty())
{
// TODO: HUGE warning - we don't know what this will do!
return false; // or whatever.
}
// otherwise it's a transaction to contract for which we have the natspec:
// determine the actual message (embellish with real data) and ask user.
// QMessageBox::question();
return true;
}

4
alethzero/OurWebThreeStubServer.h

@ -32,7 +32,11 @@ public:
OurWebThreeStubServer(jsonrpc::AbstractServerConnector& _conn, dev::WebThreeDirect& _web3, std::vector<dev::KeyPair> const& _accounts); OurWebThreeStubServer(jsonrpc::AbstractServerConnector& _conn, dev::WebThreeDirect& _web3, std::vector<dev::KeyPair> const& _accounts);
virtual std::string shh_newIdentity() override; virtual std::string shh_newIdentity() override;
virtual bool authenticate(dev::TransactionSkeleton const& _t) const;
signals: signals:
void onNewId(QString _s); void onNewId(QString _s);
private:
dev::WebThreeDirect* m_web3;
}; };

15
docker/Dockerfile

@ -7,6 +7,7 @@ RUN apt-get upgrade -y
# Ethereum dependencies # Ethereum dependencies
RUN apt-get install -qy build-essential g++-4.8 git cmake libboost-all-dev libcurl4-openssl-dev wget RUN apt-get install -qy build-essential g++-4.8 git cmake libboost-all-dev libcurl4-openssl-dev wget
RUN apt-get install -qy automake unzip libgmp-dev libtool libleveldb-dev yasm libminiupnpc-dev libreadline-dev scons RUN apt-get install -qy automake unzip libgmp-dev libtool libleveldb-dev yasm libminiupnpc-dev libreadline-dev scons
RUN apt-get install -qy libjsoncpp-dev libargtable2-dev
# NCurses based GUI (not optional though for a succesful compilation, see https://github.com/ethereum/cpp-ethereum/issues/452 ) # NCurses based GUI (not optional though for a succesful compilation, see https://github.com/ethereum/cpp-ethereum/issues/452 )
RUN apt-get install -qy libncurses5-dev RUN apt-get install -qy libncurses5-dev
@ -14,15 +15,11 @@ RUN apt-get install -qy libncurses5-dev
# Qt-based GUI # Qt-based GUI
# RUN apt-get install -qy qtbase5-dev qt5-default qtdeclarative5-dev libqt5webkit5-dev # RUN apt-get install -qy qtbase5-dev qt5-default qtdeclarative5-dev libqt5webkit5-dev
# Cryptopp # Ethereum PPA
RUN git clone --depth=1 https://github.com/mmoss/cryptopp.git RUN apt-get install -qy software-properties-common
RUN cd cryptopp && scons --shared --prefix=/usr RUN add-apt-repository ppa:ethereum/ethereum
RUN apt-get update
# JSONRPC (version 0.2.1, see https://github.com/ethereum/cpp-ethereum/issues/453 ) RUN apt-get install -qy libcryptopp-dev libjson-rpc-cpp-dev
RUN apt-get install -qy libjsoncpp-dev libargtable2-dev
RUN git clone --depth=1 --branch=0.2.1 https://github.com/cinemast/libjson-rpc-cpp.git
RUN mkdir -p libjson-rpc-cpp/build
RUN cd libjson-rpc-cpp/build && cmake .. && make && make install
# Build Ethereum (HEADLESS) # Build Ethereum (HEADLESS)
RUN git clone --depth=1 https://github.com/ethereum/cpp-ethereum RUN git clone --depth=1 https://github.com/ethereum/cpp-ethereum

18
eth/main.cpp

@ -89,6 +89,7 @@ void interactiveHelp()
<< " importConfig <path> Import the config (.RLP) from the path provided." <<endl << " importConfig <path> Import the config (.RLP) from the path provided." <<endl
<< " inspect <contract> Dumps a contract to <APPDATA>/<contract>.evm." << endl << " inspect <contract> Dumps a contract to <APPDATA>/<contract>.evm." << endl
<< " dumptrace <block> <index> <filename> <format> Dumps a transaction trace" << endl << "to <filename>. <format> should be one of pretty, standard, standard+." << endl << " dumptrace <block> <index> <filename> <format> Dumps a transaction trace" << endl << "to <filename>. <format> should be one of pretty, standard, standard+." << endl
<< " dumpreceipt <block> <index> Dumps a transation receipt." << endl
<< " exit Exits the application." << endl; << " exit Exits the application." << endl;
} }
@ -144,6 +145,8 @@ string credits(bool _interactive = false)
void version() void version()
{ {
cout << "eth version " << dev::Version << endl; cout << "eth version " << dev::Version << endl;
cout << "Network protocol version: " << dev::eth::c_protocolVersion << endl;
cout << "Client database version: " << dev::eth::c_databaseVersion << endl;
cout << "Build: " << DEV_QUOTED(ETH_BUILD_PLATFORM) << "/" << DEV_QUOTED(ETH_BUILD_TYPE) << endl; cout << "Build: " << DEV_QUOTED(ETH_BUILD_PLATFORM) << "/" << DEV_QUOTED(ETH_BUILD_TYPE) << endl;
exit(0); exit(0);
} }
@ -606,6 +609,17 @@ int main(int argc, char** argv)
else else
cwarn << "Require parameters: contract ENDOWMENT GASPRICE GAS CODEHEX"; cwarn << "Require parameters: contract ENDOWMENT GASPRICE GAS CODEHEX";
} }
else if (c && cmd == "dumpreceipt")
{
unsigned block;
unsigned index;
iss >> block >> index;
dev::eth::TransactionReceipt r = c->blockChain().receipts(c->blockChain().numberHash(block)).receipts[index];
auto rb = r.rlp();
cout << "RLP: " << RLP(rb) << endl;
cout << "Hex: " << toHex(rb) << endl;
cout << r << endl;
}
else if (c && cmd == "dumptrace") else if (c && cmd == "dumptrace")
{ {
unsigned block; unsigned block;
@ -619,7 +633,7 @@ int main(int argc, char** argv)
dev::eth::State state =c->state(index + 1,c->blockChain().numberHash(block)); dev::eth::State state =c->state(index + 1,c->blockChain().numberHash(block));
if (index < state.pending().size()) if (index < state.pending().size())
{ {
Executive e(state, 0); Executive e(state, c->blockChain(), 0);
Transaction t = state.pending()[index]; Transaction t = state.pending()[index];
state = state.fromPending(index); state = state.fromPending(index);
bytes r = t.rlp(); bytes r = t.rlp();
@ -660,7 +674,7 @@ int main(int argc, char** argv)
f << ext->myAddress << " " << hex << toHex(dev::toCompactBigEndian(vm->curPC(), 1)) << " " << hex << toHex(dev::toCompactBigEndian((int)(byte)instr, 1)) << " " << hex << toHex(dev::toCompactBigEndian((uint64_t)vm->gas(), 1)) << endl; f << ext->myAddress << " " << hex << toHex(dev::toCompactBigEndian(vm->curPC(), 1)) << " " << hex << toHex(dev::toCompactBigEndian((int)(byte)instr, 1)) << " " << hex << toHex(dev::toCompactBigEndian((uint64_t)vm->gas(), 1)) << endl;
}; };
e.go(oof); e.go(oof);
e.finalize(oof); e.finalize();
} }
catch(Exception const& _e) catch(Exception const& _e)
{ {

1
evmjit

@ -1 +0,0 @@
Subproject commit 1b490244bf4864b96448d56a7cd20f3d5b0a0b9b

27
evmjit/CMakeLists.txt

@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 2.8.12)
project(evmjit)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# LLVM
if(LLVM_DIR) # local LLVM build
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
# TODO: bitwriter is needed only for evmcc
llvm_map_components_to_libnames(LLVM_LIBS core support mcjit x86asmparser x86codegen bitwriter)
else()
# Workaround for Ubuntu broken LLVM package
message(STATUS "Using llvm-3.5-dev package from Ubuntu. If does not work, build LLVM and set -DLLVM_DIR=llvm-build/share/llvm/cmake")
execute_process(COMMAND llvm-config-3.5 --includedir OUTPUT_VARIABLE LLVM_INCLUDE_DIRS)
message(STATUS "LLVM include dirs: ${LLVM_INCLUDE_DIRS}")
set(LLVM_LIBS "-lLLVMBitWriter -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMX86AsmParser -lLLVMX86Desc -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMMCJIT -lLLVMTarget -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMExecutionEngine -lLLVMMC -lLLVMCore -lLLVMSupport -lz -lpthread -lffi -ltinfo -ldl -lm")
endif()
# Boost
find_package(Boost REQUIRED)
add_subdirectory(libevmjit)
add_subdirectory(libevmjit-cpp)
add_subdirectory(evmcc)

18
evmjit/evmcc/CMakeLists.txt

@ -0,0 +1,18 @@
set(TARGET_NAME evmcc)
set(SOURCES
evmcc.cpp
)
source_group("" FILES ${SOURCES})
add_executable(${TARGET_NAME} ${SOURCES})
set_property(TARGET ${TARGET_NAME} PROPERTY FOLDER "tools")
include_directories(../..)
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(${TARGET_NAME} ethereum)
target_link_libraries(${TARGET_NAME} ${Boost_PROGRAM_OPTIONS_LIBRARIES})
install(TARGETS ${TARGET_NAME} DESTINATION bin )

211
evmjit/evmcc/evmcc.cpp

@ -0,0 +1,211 @@
#include <chrono>
#include <iostream>
#include <fstream>
#include <ostream>
#include <string>
#include <vector>
#include <boost/algorithm/string.hpp>
#include <boost/program_options.hpp>
#include <llvm/Bitcode/ReaderWriter.h>
#include <llvm/Support/raw_os_ostream.h>
#include <llvm/Support/Signals.h>
#include <llvm/Support/PrettyStackTrace.h>
#include <libdevcore/Common.h>
#include <libdevcore/CommonIO.h>
#include <libevmcore/Instruction.h>
#include <libevm/ExtVMFace.h>
#include <evmjit/libevmjit/Compiler.h>
#include <evmjit/libevmjit/ExecutionEngine.h>
void parseProgramOptions(int _argc, char** _argv, boost::program_options::variables_map& _varMap)
{
namespace opt = boost::program_options;
opt::options_description explicitOpts("Allowed options");
explicitOpts.add_options()
("help,h", "show usage information")
("compile,c", "compile the code to LLVM IR")
("interpret,i", "compile the code to LLVM IR and execute")
("gas,g", opt::value<size_t>(), "set initial gas for execution")
("disassemble,d", "dissassemble the code")
("dump-cfg", "dump control flow graph to graphviz file")
("dont-optimize", "turn off optimizations")
("optimize-stack", "optimize stack use between basic blocks (default: on)")
("rewrite-switch", "rewrite LLVM switch to branches (default: on)")
("output-ll", opt::value<std::string>(), "dump generated LLVM IR to file")
("output-bc", opt::value<std::string>(), "dump generated LLVM bitcode to file")
("show-logs", "output LOG statements to stderr")
("verbose,V", "enable verbose output");
opt::options_description implicitOpts("Input files");
implicitOpts.add_options()
("input-file", opt::value<std::string>(), "input file");
opt::options_description allOpts("");
allOpts.add(explicitOpts).add(implicitOpts);
opt::positional_options_description inputOpts;
inputOpts.add("input-file", 1);
const char* errorMsg = nullptr;
try
{
auto parser = opt::command_line_parser(_argc, _argv).options(allOpts).positional(inputOpts);
opt::store(parser.run(), _varMap);
opt::notify(_varMap);
}
catch (boost::program_options::error& err)
{
errorMsg = err.what();
}
if (!errorMsg && _varMap.count("input-file") == 0)
errorMsg = "missing input file name";
if (_varMap.count("disassemble") == 0
&& _varMap.count("compile") == 0
&& _varMap.count("interpret") == 0)
{
errorMsg = "at least one of -c, -i, -d is required";
}
if (errorMsg || _varMap.count("help"))
{
if (errorMsg)
std::cerr << "Error: " << errorMsg << std::endl;
std::cout << "Usage: " << _argv[0] << " <options> input-file " << std::endl
<< explicitOpts << std::endl;
std::exit(errorMsg ? 1 : 0);
}
}
int main(int argc, char** argv)
{
llvm::sys::PrintStackTraceOnErrorSignal();
llvm::PrettyStackTraceProgram X(argc, argv);
boost::program_options::variables_map options;
parseProgramOptions(argc, argv, options);
auto inputFile = options["input-file"].as<std::string>();
std::ifstream ifs(inputFile);
if (!ifs.is_open())
{
std::cerr << "cannot open input file " << inputFile << std::endl;
exit(1);
}
std::string src((std::istreambuf_iterator<char>(ifs)),
(std::istreambuf_iterator<char>()));
boost::algorithm::trim(src);
using namespace dev;
bytes bytecode = fromHex(src);
if (options.count("disassemble"))
{
std::string assembly = eth::disassemble(bytecode);
std::cout << assembly << std::endl;
}
if (options.count("compile") || options.count("interpret"))
{
size_t initialGas = 10000;
if (options.count("gas"))
initialGas = options["gas"].as<size_t>();
auto compilationStartTime = std::chrono::high_resolution_clock::now();
eth::jit::Compiler::Options compilerOptions;
compilerOptions.dumpCFG = options.count("dump-cfg") > 0;
bool optimize = options.count("dont-optimize") == 0;
compilerOptions.optimizeStack = optimize || options.count("optimize-stack") > 0;
compilerOptions.rewriteSwitchToBranches = optimize || options.count("rewrite-switch") > 0;
auto compiler = eth::jit::Compiler(compilerOptions);
auto module = compiler.compile(bytecode, "main");
auto compilationEndTime = std::chrono::high_resolution_clock::now();
module->dump();
if (options.count("output-ll"))
{
auto outputFile = options["output-ll"].as<std::string>();
std::ofstream ofs(outputFile);
if (!ofs.is_open())
{
std::cerr << "cannot open output file " << outputFile << std::endl;
exit(1);
}
llvm::raw_os_ostream ros(ofs);
module->print(ros, nullptr);
ofs.close();
}
if (options.count("output-bc"))
{
auto outputFile = options["output-bc"].as<std::string>();
std::ofstream ofs(outputFile);
if (!ofs.is_open())
{
std::cerr << "cannot open output file " << outputFile << std::endl;
exit(1);
}
llvm::raw_os_ostream ros(ofs);
llvm::WriteBitcodeToFile(module.get(), ros);
ros.flush();
ofs.close();
}
if (options.count("verbose"))
{
std::cerr << "*** Compilation time: "
<< std::chrono::duration_cast<std::chrono::microseconds>(compilationEndTime - compilationStartTime).count()
<< std::endl;
}
if (options.count("interpret"))
{
using namespace eth::jit;
ExecutionEngine engine;
eth::jit::u256 gas = initialGas;
// Create random runtime data
RuntimeData data;
data.set(RuntimeData::Gas, gas);
data.set(RuntimeData::Address, (u160)Address(1122334455667788));
data.set(RuntimeData::Caller, (u160)Address(0xfacefacefaceface));
data.set(RuntimeData::Origin, (u160)Address(101010101010101010));
data.set(RuntimeData::CallValue, 0xabcd);
data.set(RuntimeData::CallDataSize, 3);
data.set(RuntimeData::GasPrice, 1003);
data.set(RuntimeData::PrevHash, 1003);
data.set(RuntimeData::CoinBase, (u160)Address(101010101010101015));
data.set(RuntimeData::TimeStamp, 1005);
data.set(RuntimeData::Number, 1006);
data.set(RuntimeData::Difficulty, 16);
data.set(RuntimeData::GasLimit, 1008);
data.set(RuntimeData::CodeSize, bytecode.size());
data.callData = (uint8_t*)"abc";
data.code = bytecode.data();
// BROKEN: env_* functions must be implemented & RuntimeData struct created
// TODO: Do not compile module again
auto result = engine.run(bytecode, &data, nullptr);
return static_cast<int>(result);
}
}
return 0;
}

1
evmjit/evmcc/test/arith/addmod.evm

@ -0,0 +1 @@
60646107b760271460005560006001f2

12
evmjit/evmcc/test/arith/addmod.lll

@ -0,0 +1,12 @@
;; Should return (1975 + 39) `mod` 100 = 14 = 0x0e
(asm
100
1975
39
ADDMOD
0
MSTORE8
0
1
RETURN
)

1
evmjit/evmcc/test/arith/arith1.evm

@ -0,0 +1 @@
60016001900160070260050160029004600490066021900560150160030260059007600303600960110860005460086000f2

37
evmjit/evmcc/test/arith/arith1.lll

@ -0,0 +1,37 @@
(asm
1
1
SWAP1
ADD ;; 2
7
MUL ;; 14
5
ADD ;; 19
2
SWAP1
DIV ;; 9
4
SWAP1
MOD ;; 1
33
SWAP1
SDIV;; 0
21
ADD ;; 21
3
MUL ;; 63
5
SWAP1
SMOD;; 3
3
SUB ;; 0
9
17
EXP ;; 17^9
0
MSTORE
8
0
RETURN
)

1
evmjit/evmcc/test/arith/arith_bnot.evm

@ -0,0 +1 @@
6201e2406000546000530960005460206000f2

14
evmjit/evmcc/test/arith/arith_bnot.lll

@ -0,0 +1,14 @@
(asm
123456
0
MSTORE
0
MLOAD
BNOT
0
MSTORE
32
0
RETURN
)

1
evmjit/evmcc/test/arith/div.evm

@ -0,0 +1 @@
60027ffedcba9876543210fedcba9876543210fedcba9876543210fedcba98765432100460005460206000f2

10
evmjit/evmcc/test/arith/div.lll

@ -0,0 +1,10 @@
(asm
0x2
0xfedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210
DIV
0
MSTORE
32
0
RETURN
)

1
evmjit/evmcc/test/arith/fib1.evm

@ -0,0 +1 @@
60016001818101818101818101818101818101818101818101818101818101818101818101818101818101818101818101818101818101

57
evmjit/evmcc/test/arith/fib1.lll

@ -0,0 +1,57 @@
;; Fibbonacci unrolled
(asm
1
1
DUP2
DUP2
ADD
DUP2
DUP2
ADD
DUP2
DUP2
ADD
DUP2
DUP2
ADD
DUP2
DUP2
ADD
DUP2
DUP2
ADD
DUP2
DUP2
ADD
DUP2
DUP2
ADD
DUP2
DUP2
ADD
DUP2
DUP2
ADD
DUP2
DUP2
ADD
DUP2
DUP2
ADD
DUP2
DUP2
ADD
DUP2
DUP2
ADD
DUP2
DUP2
ADD
DUP2
DUP2
ADD
DUP2
DUP2
ADD
)

1
evmjit/evmcc/test/arith/mul.evm

@ -0,0 +1 @@
7001234567890abcdef0fedcba09876543217001234567890abcdef0fedcba09876543217001234567890abcdef0fedcba0987654321020260005460206000f2

13
evmjit/evmcc/test/arith/mul.lll

@ -0,0 +1,13 @@
(asm
0x1234567890abcdef0fedcba0987654321
0x1234567890abcdef0fedcba0987654321
0x1234567890abcdef0fedcba0987654321
MUL
MUL
0
MSTORE
32
0
RETURN
;; 47d0817e4167b1eb4f9fc722b133ef9d7d9a6fb4c2c1c442d000107a5e419561
)

1
evmjit/evmcc/test/arith/mulmod.evm

@ -0,0 +1 @@
6064601b60251560005560006001f2

12
evmjit/evmcc/test/arith/mulmod.lll

@ -0,0 +1,12 @@
;; Should return (27 * 37) `mod` 100 = 99 = 0x63
(asm
100
27
37
MULMOD
0
MSTORE8
0
1
RETURN
)

1
evmjit/evmcc/test/except/badinst1.evm

@ -0,0 +1 @@
4a

1
evmjit/evmcc/test/ext/calldatacopy1.evm

@ -0,0 +1 @@
60326000600a37600053600a6014f2

13
evmjit/evmcc/test/ext/calldatacopy1.lll

@ -0,0 +1,13 @@
(asm
50 ;; byte count
0 ;; source index in calldata array
10 ;; dest index in memory
CALLDATACOPY
0
MLOAD ;; to dump memory
10
20
RETURN
)

1
evmjit/evmcc/test/ext/calldatacopy2.evm

@ -0,0 +1 @@
606464e8d4a510006000376000536000600af2

13
evmjit/evmcc/test/ext/calldatacopy2.lll

@ -0,0 +1,13 @@
(asm
100 ;; byte count
1000000000000 ;; source index in calldata array
0 ;; dest index in memory
CALLDATACOPY
0
MLOAD ;; to dump memory
0
10
RETURN
)

1
evmjit/evmcc/test/ext/codecopy1.evm

@ -0,0 +1 @@
60146000600a39600053600a6014f2

13
evmjit/evmcc/test/ext/codecopy1.lll

@ -0,0 +1,13 @@
(asm
20 ;; byte count
0 ;; source index in code array
10 ;; dest index in memory
CODECOPY
0
MLOAD ;; to dump memory
10
20
RETURN
)

1
evmjit/evmcc/test/ext/codecopy2.evm

@ -0,0 +1 @@
606464e8d4a510006000396000536000600af2

13
evmjit/evmcc/test/ext/codecopy2.lll

@ -0,0 +1,13 @@
(asm
100 ;; byte count
1000000000000 ;; source index in code array
0 ;; dest index in memory
CODECOPY
0
MLOAD ;; to dump memory
0
10
RETURN
)

1
evmjit/evmcc/test/ext/codecopy3.evm

@ -0,0 +1 @@
3860006000396000536000600af2

13
evmjit/evmcc/test/ext/codecopy3.lll

@ -0,0 +1,13 @@
(asm
CODESIZE ;; byte count
0 ;; source index in code array
0 ;; dest index in memory
CODECOPY
0
MLOAD ;; to dump memory
0
10
RETURN
)

1
evmjit/evmcc/test/ext/ext_test.evm

@ -0,0 +1 @@
5a3031333234363a4041424344455a36600035602635601335387f1111222233334444555566667777888899990000aaaabbbbccccddddeeeeffff600054602060006000f06020600060206000600030610bb8f1600053611000545b60200260002030ff60016002f2

55
evmjit/evmcc/test/ext/ext_test.lll

@ -0,0 +1,55 @@
(asm
PC
ADDRESS
BALANCE
CALLER
ORIGIN
CALLVALUE
CALLDATASIZE
GASPRICE
PREVHASH
COINBASE
TIMESTAMP
NUMBER
DIFFICULTY
GASLIMIT
PC
CALLDATASIZE
0
CALLDATALOAD
38
CALLDATALOAD
19
CALLDATALOAD
CODESIZE
0x1111222233334444555566667777888899990000aaaabbbbccccddddeeeeffff
0
MSTORE
32
0
0
CREATE
32
0
32
0
0
ADDRESS
3000
CALL
0
MLOAD
4096
MSTORE
MSIZE
32
MUL
0
SHA3
ADDRESS
SUICIDE
1
2
RETURN
)

1
evmjit/evmcc/test/ext/extcodecopy1.evm

@ -0,0 +1 @@
60c86000600a303c60005360006020f2

11
evmjit/evmcc/test/ext/extcodecopy1.lll

@ -0,0 +1,11 @@
(asm
200 ;; byte count
0 ;; source index in code array
10 ;; dest index in memory
ADDRESS
EXTCODECOPY
0 MLOAD ;; to dump memory
0 32 RETURN
)

1
evmjit/evmcc/test/ext/store_delete.evm

@ -0,0 +1 @@
6104d26063576000606357

9
evmjit/evmcc/test/ext/store_delete.lll

@ -0,0 +1,9 @@
(asm
1234
99
SSTORE
0
99
SSTORE
)

1
evmjit/evmcc/test/ext/store_test.evm

@ -0,0 +1 @@
607b607c60015760005760015660005603

14
evmjit/evmcc/test/ext/store_test.lll

@ -0,0 +1,14 @@
(asm
123
124
1
SSTORE
0
SSTORE
1
SLOAD
0
SLOAD
SUB
)

7
evmjit/evmcc/test/jump/ackermann.ethel

@ -0,0 +1,7 @@
let A m n =
if m == 0 then n+1
else if n == 0 then A (m-1) 1
else A (m-1) (A (m) (n-1))
return A 3 8

1
evmjit/evmcc/test/jump/ackermann.evm

@ -0,0 +1 @@
6009600360086012585d60005460206000f26000820e6047596000810e603859603460018303603084600185036012585d6012585d60445860436001830360016012585d604b5860018101905090509058

1
evmjit/evmcc/test/jump/badindirect1.evm

@ -0,0 +1 @@
601b602502585d

9
evmjit/evmcc/test/jump/badindirect1.lll

@ -0,0 +1,9 @@
;; Indirect jump out of code
(asm
27
37
MUL
JUMP
JUMPDEST
)

1
evmjit/evmcc/test/jump/badindirect2.evm

@ -0,0 +1 @@
60016003600302596000600058

12
evmjit/evmcc/test/jump/badindirect2.lll

@ -0,0 +1,12 @@
;; Indirect jump into data
(asm
1 ;; 0
3
3
MUL ;; 6
JUMPI ;; 7
0 ;; 8
0
JUMP
)

1
evmjit/evmcc/test/jump/badjump1.evm

@ -0,0 +1 @@
6103e758

6
evmjit/evmcc/test/jump/badjump1.lll

@ -0,0 +1,6 @@
;; Direct jump out of code.
(asm
999
JUMP
)

1
evmjit/evmcc/test/jump/badjump2.evm

@ -0,0 +1 @@
6004586000600058

9
evmjit/evmcc/test/jump/badjump2.lll

@ -0,0 +1,9 @@
;; Direct jump into data
(asm
4 ;; 0 0-3
JUMP ;; 2
0 ;; 3 3-4
0 ;; 5 4-7
JUMP ;; 6
)

5
evmjit/evmcc/test/jump/call1.ethel

@ -0,0 +1,5 @@
let f n = n + 1
return f 2

1
evmjit/evmcc/test/jump/call1.evm

@ -0,0 +1 @@
600760026010585d60005460206000f28060010190509058

5
evmjit/evmcc/test/jump/call2.ethel

@ -0,0 +1,5 @@
let f a b = a + b
return f 2 3

1
evmjit/evmcc/test/jump/call2.evm

@ -0,0 +1 @@
6009600260036012585d60005460206000f2818101905090509058

5
evmjit/evmcc/test/jump/fac.ethel

@ -0,0 +1,5 @@
let fac n =
if n == 0 then 1
else n * fac (n-1)
return fac 60

1
evmjit/evmcc/test/jump/fac.evm

@ -0,0 +1 @@
6007603c6010585d60005460206000f26000810e6026596020600182036010585d8102602858600190509058

5
evmjit/evmcc/test/jump/fac_tail.ethel

@ -0,0 +1,5 @@
let fac a n =
if n == 0 then a
else fac (a*n) (n-1)
return fac 1 60

1
evmjit/evmcc/test/jump/fac_tail.evm

@ -0,0 +1 @@
60096001603c6012585d60005460206000f26000810e6029596025818302600183036012585d602a5881905090509058

6
evmjit/evmcc/test/jump/fib1.ethel

@ -0,0 +1,6 @@
let fib n =
if n < 3 then 1
else fib (n-1) + fib (n-2)
return fib 10

1
evmjit/evmcc/test/jump/fib1.evm

@ -0,0 +1 @@
6007600a6010585d60005460206000f26003810a602f596020600282036010585d602a600183036010585d01603158600190509058

1
evmjit/evmcc/test/jump/for1.evm

@ -0,0 +1 @@
600a60805460006080530b0f60255960a0536080530160a054600160805303608054600558

3
evmjit/evmcc/test/jump/for1.lll

@ -0,0 +1,3 @@
(for [i]:10 (> @i 0) [i](- @i 1)
[j](+ @i @j)
)

1
evmjit/evmcc/test/jump/for2.evm

@ -0,0 +1 @@
6000608054600a6080530a0f60255960a0536080530160a054600160805301608054600558

3
evmjit/evmcc/test/jump/for2.lll

@ -0,0 +1,3 @@
(for [i]:0 (< @i 10) [i](+ @i 1)
[j](+ @i @j)
)

1
evmjit/evmcc/test/jump/if1.ethel

@ -0,0 +1 @@
return if 0 then 1 else 2

1
evmjit/evmcc/test/jump/if1.evm

@ -0,0 +1 @@
60006300000010596002630000001258600160005460206000f2

1
evmjit/evmcc/test/jump/if2.ethel

@ -0,0 +1 @@
return if 1 then 1 else 2

1
evmjit/evmcc/test/jump/if2.evm

@ -0,0 +1 @@
60016300000010596002630000001258600160005460206000f2

1
evmjit/evmcc/test/jump/indirect1.evm

@ -0,0 +1 @@
600460030158005d6001600054

13
evmjit/evmcc/test/jump/indirect1.lll

@ -0,0 +1,13 @@
;; Indirect JUMP
(asm
4 ;; 0
3 ;; 2
ADD ;; 4
JUMP ;; 5
STOP ;; 6
JUMPDEST ;; 7
1
0
MSTORE
)

1
evmjit/evmcc/test/jump/indirect2.evm

@ -0,0 +1 @@
600860060158005d6001600054005d600260005400

19
evmjit/evmcc/test/jump/indirect2.lll

@ -0,0 +1,19 @@
;; Indirect JUMP
(asm
8 ;; 0
6 ;; 2
ADD ;; 4
JUMP ;; 5 --> 14
STOP ;; 6
JUMPDEST ;; 7
1 ;; 8
0 ;; 10
MSTORE ;; 12
STOP ;; 13
JUMPDEST ;; 14
2
0
MSTORE
STOP
)

1
evmjit/evmcc/test/jump/indirect3.evm

@ -0,0 +1 @@
6001600460050159005d6001600054

14
evmjit/evmcc/test/jump/indirect3.lll

@ -0,0 +1,14 @@
;; Indirect JUMP
(asm
1 ;; 0
4 ;; 2
5 ;; 4
ADD ;; 6
JUMPI ;; 7
STOP ;; 8
JUMPDEST ;; 9
1
0
MSTORE
)

1
evmjit/evmcc/test/jump/indirect4.evm

@ -0,0 +1 @@
60006007600501596001600054005d00

15
evmjit/evmcc/test/jump/indirect4.lll

@ -0,0 +1,15 @@
;; Indirect JUMP
(asm
0 ;; 0
7 ;; 2
5 ;; 4
ADD ;; 6
JUMPI ;; 7
1 ;; 8
0 ;; 9
MSTORE ;; 10
STOP ;; 11
JUMPDEST ;; 12
STOP
)

1
evmjit/evmcc/test/jump/jump1.evm

@ -0,0 +1 @@
600458006001600154

11
evmjit/evmcc/test/jump/jump1.lll

@ -0,0 +1,11 @@
;; Direct JUMP.
;; output: memory[1] == 1
(asm
4 ;; 0
JUMP ;; 2
STOP ;; 3
1 ;; 4
1 ;; 6
MSTORE ;; 8
)

1
evmjit/evmcc/test/jump/jump2.evm

@ -0,0 +1 @@
6008586001600154

10
evmjit/evmcc/test/jump/jump2.lll

@ -0,0 +1,10 @@
;; Direct JUMP to the end of code.
;; output: memory should have size 0.
(asm
8 ;; 0
JUMP ;; 2
1 ;; 3
1 ;; 5
MSTORE ;; 7
)

1
evmjit/evmcc/test/jump/jump3.evm

@ -0,0 +1 @@
602a586001600154

10
evmjit/evmcc/test/jump/jump3.lll

@ -0,0 +1,10 @@
;; Direct JUMP past the end of code.
;; output: memory should have size 0.
(asm
42
JUMP
1
1
MSTORE
)

1
evmjit/evmcc/test/jump/jump4.evm

@ -0,0 +1 @@
600b6009580000600558005d6001600154

17
evmjit/evmcc/test/jump/jump4.lll

@ -0,0 +1,17 @@
;; Direct JUMP.
;; output: memory[1] = 1
(asm
11 ;; 0
9 ;; 2
JUMP ;; 4 --> 9
STOP ;; 5
STOP ;; 6
5 ;; 7
JUMP ;; 9 --> 11
STOP ;; 10
JUMPDEST
1 ;; 11
1
MSTORE
)

1
evmjit/evmcc/test/jump/jump5.evm

@ -0,0 +1 @@
6005600e585d600160015400600f5800

16
evmjit/evmcc/test/jump/jump5.lll

@ -0,0 +1,16 @@
;; Direct JUMP.
;; output: memory[1] = 1
(asm
5 ;; 0
14 ;; 2
JUMP ;; 4 --> 14
JUMPDEST ;; 5
1 ;; 6
1 ;; 8
MSTORE ;; 10
STOP ;; 11
15 ;; 12
JUMP ;; 14 --> 5
STOP ;; 15
)

1
evmjit/evmcc/test/jump/jump6.evm

@ -0,0 +1 @@
600358600f600d58006014600758005d6001600154005d600260025400

32
evmjit/evmcc/test/jump/jump6.lll

@ -0,0 +1,32 @@
;; Direct JUMP.
;; output: memory[1] = 1
;; 0, 2 --> 3 .. 7 --> 13 -*-> 15 .. 19
(asm
3 ;; 0
JUMP ;; 2
15 ;; 3 <- start
13 ;; 5
JUMP ;; 7 <- b
STOP ;; 8
20 ;; 9
7 ;; 11
JUMP ;; 13 <- a
STOP ;; 14
JUMPDEST ;; 15 <- c
1 ;; 16
1 ;; 18
MSTORE ;; 19
STOP ;; 20
JUMPDEST ;; 21 <- d
2 ;; 22
2 ;; 24
MSTORE ;; 26
STOP ;; 27
)

1
evmjit/evmcc/test/jump/jumpi_at_the_end.evm

@ -0,0 +1 @@
600a6000545d6000536001900380600054600659

1
evmjit/evmcc/test/jump/jumpi_at_the_end.lll

@ -0,0 +1 @@
(asm 10 0 MSTORE JUMPDEST 0 MLOAD 1 SWAP1 SUB DUP1 0 MSTORE 6 JUMPI)

1
evmjit/evmcc/test/jump/loop1.evm

@ -0,0 +1 @@
600a600181038060025960005460015460025400

27
evmjit/evmcc/test/jump/loop1.lll

@ -0,0 +1,27 @@
;; Produces 1 2 3 4 5 6 7 8 9 10 on the stack and exits
(asm
10
;; 2
1
DUP2
SUB
DUP1
2
JUMPI
;; stack = 1 2 3 4 5 6 7 8 9 10
0
MSTORE
1
MSTORE
2
MSTORE
;;3
;;MSTORE
STOP
)

1
evmjit/evmcc/test/jump/loop2.evm

@ -0,0 +1 @@
600a80600190038060025960005460015460025400

28
evmjit/evmcc/test/jump/loop2.lll

@ -0,0 +1,28 @@
;; Produces 1 2 3 4 5 6 7 8 9 10 on the stack and exits
(asm
10
;; 2
DUP1
1
SWAP1
SUB
DUP1
2
JUMPI
;; stack = 1 2 3 4 5 6 7 8 9 10
0
MSTORE
1
MSTORE
2
MSTORE
;;3
;;MSTORE
STOP
)

4
evmjit/evmcc/test/jump/rec1.ethel

@ -0,0 +1,4 @@
let f n =
if n == 0 then 2 else f (n-1)
return f 10

1
evmjit/evmcc/test/jump/rec1.evm

@ -0,0 +1 @@
6007600a6010585d60005460206000f26000810e6024596020600182036010585d602658600290509058

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save