mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
Starting ExtVM binary interface
This commit is contained in:
parent
78b188c4b4
commit
f3a347bdc8
4 changed files with 82 additions and 0 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
#include <libevmface/Instruction.h>
|
#include <libevmface/Instruction.h>
|
||||||
|
|
||||||
#include "Stack.h"
|
#include "Stack.h"
|
||||||
|
#include "Ext.h"
|
||||||
|
|
||||||
namespace evmcc
|
namespace evmcc
|
||||||
{
|
{
|
||||||
|
|
@ -56,6 +57,8 @@ std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)
|
||||||
// Init stack
|
// Init stack
|
||||||
auto stack = Stack(builder, module.get());
|
auto stack = Stack(builder, module.get());
|
||||||
|
|
||||||
|
auto ext = Ext(builder);
|
||||||
|
|
||||||
for (auto pc = bytecode.cbegin(); pc != bytecode.cend(); ++pc)
|
for (auto pc = bytecode.cbegin(); pc != bytecode.cend(); ++pc)
|
||||||
{
|
{
|
||||||
using dev::eth::Instruction;
|
using dev::eth::Instruction;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@
|
||||||
#include <llvm/Support/PrettyStackTrace.h>
|
#include <llvm/Support/PrettyStackTrace.h>
|
||||||
#include <llvm/Support/Host.h>
|
#include <llvm/Support/Host.h>
|
||||||
|
|
||||||
|
#include "Ext.h"
|
||||||
|
|
||||||
namespace evmcc
|
namespace evmcc
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -66,6 +68,9 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module)
|
||||||
_module.release(); // Successfully created llvm::ExecutionEngine takes ownership of the module
|
_module.release(); // Successfully created llvm::ExecutionEngine takes ownership of the module
|
||||||
exec->finalizeObject();
|
exec->finalizeObject();
|
||||||
|
|
||||||
|
auto ext = std::make_unique<dev::eth::ExtVMFace>();
|
||||||
|
Ext::init(std::move(ext));
|
||||||
|
|
||||||
auto entryFunc = module->getFunction("main");
|
auto entryFunc = module->getFunction("main");
|
||||||
if (!entryFunc)
|
if (!entryFunc)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
52
evmcc/Ext.cpp
Normal file
52
evmcc/Ext.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
|
||||||
|
#include "Ext.h"
|
||||||
|
|
||||||
|
#include <llvm/IR/Function.h>
|
||||||
|
#include <llvm/IR/TypeBuilder.h>
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define EXPORT __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
using namespace llvm;
|
||||||
|
using llvm::types::i;
|
||||||
|
using Linkage = llvm::GlobalValue::LinkageTypes;
|
||||||
|
|
||||||
|
namespace evmcc
|
||||||
|
{
|
||||||
|
|
||||||
|
std::unique_ptr<dev::eth::ExtVMFace> g_ext;
|
||||||
|
|
||||||
|
void Ext::init(std::unique_ptr<dev::eth::ExtVMFace> _ext)
|
||||||
|
{
|
||||||
|
g_ext = std::move(_ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ext::Ext(llvm::IRBuilder<>& _builder)
|
||||||
|
: m_builder(_builder)
|
||||||
|
{
|
||||||
|
auto module = m_builder.GetInsertBlock()->getParent()->getParent();
|
||||||
|
auto&& ctx = _builder.getContext();
|
||||||
|
|
||||||
|
Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_store", module);
|
||||||
|
Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_setStore", module);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
|
||||||
|
EXPORT void ext_store(void* _index, void* _value)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPORT void ext_setStore(void* _index, void* _value)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
22
evmcc/Ext.h
Normal file
22
evmcc/Ext.h
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
|
||||||
|
#include <llvm/IR/IRBuilder.h>
|
||||||
|
|
||||||
|
#include <libevm/ExtVMFace.h>
|
||||||
|
|
||||||
|
namespace evmcc
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Ext
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Ext(llvm::IRBuilder<>& _builder);
|
||||||
|
static void init(std::unique_ptr<dev::eth::ExtVMFace> _ext);
|
||||||
|
|
||||||
|
private:
|
||||||
|
llvm::IRBuilder<>& m_builder;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue