Paweł Bylica
10 years ago
7 changed files with 275 additions and 68 deletions
@ -0,0 +1,60 @@ |
|||
cmake_policy(SET CMP0015 NEW) |
|||
|
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB") |
|||
|
|||
aux_source_directory(. SRC_LIST) |
|||
|
|||
set(EXECUTABLE evmjit) |
|||
|
|||
file(GLOB HEADERS "*.h") |
|||
if (EVMJIT_STATIC) |
|||
add_library(${EXECUTABLE} STATIC ${SRC_LIST} ${HEADERS}) |
|||
else() |
|||
add_library(${EXECUTABLE} SHARED ${SRC_LIST} ${HEADERS}) |
|||
endif() |
|||
|
|||
include_directories(..) |
|||
|
|||
target_link_libraries(${EXECUTABLE} devcore) |
|||
target_link_libraries(${EXECUTABLE} ethcore) |
|||
target_link_libraries(${EXECUTABLE} evm) |
|||
target_link_libraries(${EXECUTABLE} evmface) |
|||
|
|||
if ("${TARGET_PLATFORM}" STREQUAL "w64") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") |
|||
target_link_libraries(${EXECUTABLE} gcc) |
|||
target_link_libraries(${EXECUTABLE} gdi32) |
|||
target_link_libraries(${EXECUTABLE} ws2_32) |
|||
target_link_libraries(${EXECUTABLE} mswsock) |
|||
target_link_libraries(${EXECUTABLE} shlwapi) |
|||
target_link_libraries(${EXECUTABLE} iphlpapi) |
|||
target_link_libraries(${EXECUTABLE} boost_thread_win32-mt-s) |
|||
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS) |
|||
elseif (UNIX) |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") |
|||
else () |
|||
find_package(Threads REQUIRED) |
|||
target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) |
|||
endif () |
|||
|
|||
# LLVM specific commands |
|||
|
|||
find_package(LLVM REQUIRED CONFIG) |
|||
|
|||
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") |
|||
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") |
|||
|
|||
include_directories(${LLVM_INCLUDE_DIRS}) |
|||
add_definitions(${LLVM_DEFINITIONS}) |
|||
|
|||
llvm_map_components_to_libnames(llvm_libs core support mcjit x86asmparser x86codegen) |
|||
target_link_libraries(evmjit ${llvm_libs}) |
|||
|
|||
# end of LLVM specific commands |
|||
|
|||
|
|||
|
|||
install( TARGETS ${EXECUTABLE} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) |
|||
install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) |
|||
|
|||
cmake_policy(SET CMP0015 NEW) |
@ -0,0 +1,69 @@ |
|||
#include "Stack.h" |
|||
#include "Runtime.h" |
|||
|
|||
#include <llvm/IR/Function.h> |
|||
#include <llvm/IR/TypeBuilder.h> |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
namespace jit |
|||
{ |
|||
|
|||
Stack::Stack(llvm::IRBuilder<>& _builder) |
|||
: CompilerHelper(_builder) |
|||
{ |
|||
auto i256Ty = m_builder.getIntNTy(256); |
|||
auto i256PtrTy = i256Ty->getPointerTo(); |
|||
|
|||
m_arg = m_builder.CreateAlloca(i256Ty, nullptr, "stack.retVal"); |
|||
|
|||
using namespace llvm; |
|||
using Linkage = GlobalValue::LinkageTypes; |
|||
|
|||
auto module = getModule(); |
|||
m_push = Function::Create(FunctionType::get(m_builder.getVoidTy(), i256PtrTy, false), Linkage::ExternalLinkage, "stack_push", module); |
|||
m_pop = Function::Create(FunctionType::get(m_builder.getVoidTy(), i256PtrTy, false), Linkage::ExternalLinkage, "stack_pop", module); |
|||
} |
|||
|
|||
Stack::~Stack() |
|||
{} |
|||
|
|||
llvm::Instruction* Stack::popWord() |
|||
{ |
|||
m_builder.CreateCall(m_pop, m_arg); |
|||
return m_builder.CreateLoad(m_arg); |
|||
} |
|||
|
|||
void Stack::pushWord(llvm::Value* _word) |
|||
{ |
|||
m_builder.CreateStore(_word, m_arg); |
|||
m_builder.CreateCall(m_push, m_arg); |
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
extern "C" |
|||
{ |
|||
|
|||
using namespace dev::eth::jit; |
|||
|
|||
EXPORT void stack_pop(i256* _ret) |
|||
{ |
|||
auto& stack = Runtime::getStack(); |
|||
assert(stack.size() > 0); |
|||
*_ret = stack.back(); |
|||
stack.pop_back(); |
|||
} |
|||
|
|||
EXPORT void stack_push(i256* _word) |
|||
{ |
|||
auto& stack = Runtime::getStack(); |
|||
stack.push_back(*_word); |
|||
} |
|||
|
|||
} // extern "C"
|
|||
|
@ -0,0 +1,35 @@ |
|||
#pragma once |
|||
|
|||
#include "CompilerHelper.h" |
|||
|
|||
#include <llvm/IR/Module.h> |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
namespace jit |
|||
{ |
|||
|
|||
class Stack : public CompilerHelper |
|||
{ |
|||
public: |
|||
Stack(llvm::IRBuilder<>& builder); |
|||
virtual ~Stack(); |
|||
|
|||
void pushWord(llvm::Value* _word); |
|||
llvm::Instruction* popWord(); |
|||
|
|||
private: |
|||
llvm::Function* m_push; |
|||
llvm::Function* m_pop; |
|||
|
|||
llvm::Value* m_arg; |
|||
}; |
|||
|
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
|
Loading…
Reference in new issue