Skip to content

Commit

Permalink
Make EEI use runtime debug options
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelang committed Mar 27, 2018
1 parent 3f37273 commit f7d6a12
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
27 changes: 6 additions & 21 deletions src/eei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,8 @@
using namespace std;
using namespace wasm;

#if HERA_DEBUGGING

/* #define HERA_DEBUG EthereumInterface::DebugStream */
#define HERA_DEBUG cerr

#else

struct NullStream {
template<typename T> NullStream& operator<<(const T&) { return *this; }
};

#define HERA_DEBUG NullStream()

#endif

namespace HeraVM {

namespace {
Expand All @@ -62,7 +50,6 @@ string toHex(evm_uint256be const& value) {
HERA_DEBUG << "importGlobals\n";
}

#if HERA_DEBUGGING
Literal EthereumInterface::callDebugImport(Import *import, LiteralList& arguments) {
heraAssert(import->module == Name("debug"), "Import namespace error.");

Expand Down Expand Up @@ -177,15 +164,13 @@ string toHex(evm_uint256be const& value) {

heraAssert(false, string("Unsupported import called: ") + import->module.str + "::" + import->base.str);
}
#endif

Literal EthereumInterface::callImport(Import *import, LiteralList& arguments) {
#if HERA_DEBUGGING
if (import->module == Name("debug"))
// Reroute to debug namespace
return callDebugImport(import, arguments);
#endif

if (EthereumInterface::debug) {
if (import->module == Name("debug"))
// Reroute to debug namespace
return callDebugImport(import, arguments);
}
heraAssert(import->module == Name("ethereum"), "Only imports from the 'ethereum' namespace are allowed.");

if (import->base == Name("useGas")) {
Expand Down
17 changes: 12 additions & 5 deletions src/eei.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class InternalErrorException : std::exception {
if (!(condition)) throw InternalErrorException(msg); \
}

struct NullStream {
template<typename T> NullStream& operator<<(const T&) { return *this; }
};

struct ExecutionResult {
uint64_t gasLeft = 0;
std::vector<uint8_t> returnValue;
Expand All @@ -62,19 +66,19 @@ struct EthereumInterface : ShellExternalInterface {
evm_context* _context,
std::vector<uint8_t> const& _code,
evm_message const& _msg,
ExecutionResult & _result
ExecutionResult & _result,
bool _debug
):
ShellExternalInterface(),
context(_context),
code(_code),
msg(_msg),
result(_result)
{ }
result(_result),
debug(_debug)
{ /* DebugStream = (_debug) ? std::cerr : NullStream(); */}

Literal callImport(Import *import, LiteralList& arguments) override;
#if HERA_DEBUGGING
Literal callDebugImport(Import *import, LiteralList& arguments);
#endif

void importGlobals(std::map<Name, Literal>& globals, Module& wasm) override;

Expand Down Expand Up @@ -115,6 +119,9 @@ struct EthereumInterface : ShellExternalInterface {
evm_message const& msg;
std::vector<uint8_t> lastReturnData;
ExecutionResult & result;
const bool debug;
/* FIXME */
// static std::ostream& DebugStream;
};

struct GasSchedule {
Expand Down
2 changes: 1 addition & 1 deletion src/hera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void execute(
// NOTE: DO NOT use the optimiser here, it will conflict with metering

// Interpet
EthereumInterface interface(context, code, msg, result);
EthereumInterface interface(context, code, msg, result, debug);
ModuleInstance instance(module, &interface);

Name main = Name("main");
Expand Down

0 comments on commit f7d6a12

Please sign in to comment.