Browse Source

Introducing CHECK macro - an assert that always has a value

cl-refactor
Paweł Bylica 10 years ago
parent
commit
4d2dc802e8
  1. 5
      libevmjit/Cache.cpp
  2. 8
      libevmjit/ExecutionEngine.cpp
  3. 3
      libevmjit/Utils.h

5
libevmjit/Cache.cpp

@ -13,6 +13,7 @@
#include "preprocessor/llvm_includes_end.h"
#include "ExecutionEngine.h"
#include "Utils.h"
namespace dev
{
@ -43,7 +44,9 @@ std::unique_ptr<llvm::Module> Cache::getObject(std::string const& id)
g_listener->stateChanged(ExecState::CacheLoad);
CACHE_LOG << id << ": search\n";
assert(!g_lastObject);
if (!CHECK(!g_lastObject))
g_lastObject = nullptr;
llvm::SmallString<256> cachePath;
llvm::sys::path::system_temp_directory(false, cachePath);
llvm::sys::path::append(cachePath, "evm_objs", id);

8
libevmjit/ExecutionEngine.cpp

@ -18,6 +18,7 @@
#include "Compiler.h"
#include "Cache.h"
#include "ExecStats.h"
#include "Utils.h"
#include "BuildInfo.gen.h"
namespace dev
@ -98,7 +99,7 @@ ReturnCode ExecutionEngine::run(RuntimeData* _data, Env* _env)
module->setTargetTriple(triple.str());
ee.reset(builder.create());
if (!ee)
if (!CHECK(ee))
return ReturnCode::LLVMConfigError;
module.release(); // Successfully created llvm::ExecutionEngine takes ownership of the module
ee->setObjectCache(objectCache);
@ -111,7 +112,7 @@ ReturnCode ExecutionEngine::run(RuntimeData* _data, Env* _env)
auto entryFuncPtr = (EntryFuncPtr)ee->getFunctionAddress(mainFuncName);
if (!entryFuncPtr)
{
{
auto module = objectCache ? Cache::getObject(mainFuncName) : nullptr;
if (!module)
{
@ -127,7 +128,8 @@ ReturnCode ExecutionEngine::run(RuntimeData* _data, Env* _env)
listener->stateChanged(ExecState::CodeGen);
entryFuncPtr = (EntryFuncPtr)ee->getFunctionAddress(mainFuncName);
}
assert(entryFuncPtr); //TODO: Replace it with safe exception
if (!CHECK(entryFuncPtr))
return ReturnCode::LLVMLinkError;
listener->stateChanged(ExecState::Execution);
auto returnCode = entryFuncPtr(&runtime);

3
libevmjit/Utils.h

@ -16,6 +16,9 @@ struct JIT: public NoteChannel { static const char* name() { return "JIT"; } };
//#define clog(CHANNEL) std::cerr
#define clog(CHANNEL) std::ostream(nullptr)
// The same as assert, but expression is always evaluated and result returned
#define CHECK(expr) (assert(expr), expr)
}
}
}

Loading…
Cancel
Save