Browse Source

Moving CODE data from Ext to Runtime [#81470252]

cl-refactor
Paweł Bylica 10 years ago
parent
commit
13fb431c54
  1. 2
      libevmjit/Compiler.cpp
  2. 19
      libevmjit/Ext.cpp
  3. 5
      libevmjit/Ext.h
  4. 8
      libevmjit/Runtime.cpp
  5. 2
      libevmjit/Runtime.h

2
libevmjit/Compiler.cpp

@ -733,7 +733,7 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
auto srcIdx = stack.pop();
auto reqBytes = stack.pop();
auto srcPtr = ext.code(); // TODO: Code & its size are constants, feature #80814234
auto srcPtr = _runtimeManager.getCode(); // TODO: Code & its size are constants, feature #80814234
auto srcSize = _runtimeManager.get(RuntimeData::CodeSize);
memory.copyBytes(srcPtr, srcSize, srcIdx, destMemIdx, reqBytes);

19
libevmjit/Ext.cpp

@ -51,17 +51,8 @@ Ext::Ext(RuntimeManager& _runtimeManager):
m_arg7 = m_builder.CreateAlloca(i256Ty, nullptr, "ext.arg7");
m_arg8 = m_builder.CreateAlloca(i256Ty, nullptr, "ext.arg8");
Type* elements[] = {
i8PtrTy, // byte* code
};
auto extDataTy = StructType::create(elements, "ext.Data");
m_data = m_builder.CreateAlloca(extDataTy, nullptr, "ext.data");
using llvm::types::i;
using Linkage = llvm::GlobalValue::LinkageTypes;
m_init = Function::Create(FunctionType::get(m_builder.getVoidTy(), extDataTy->getPointerTo(), false), Linkage::ExternalLinkage, "ext_init", module);
m_store = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_store", module);
m_setStore = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_setStore", module);
m_calldataload = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_calldataload", module);
@ -75,8 +66,6 @@ Ext::Ext(RuntimeManager& _runtimeManager):
m_exp = Function::Create(TypeBuilder<void(i<256>*, i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_exp", module);
m_codeAt = Function::Create(TypeBuilder<i<8>*(i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_codeAt", module);
m_codesizeAt = Function::Create(TypeBuilder<void(i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_codesizeAt", module);
m_builder.CreateCall(m_init, m_data);
}
llvm::Value* Ext::store(llvm::Value* _index)
@ -93,14 +82,6 @@ void Ext::setStore(llvm::Value* _index, llvm::Value* _value)
m_builder.CreateCall(m_setStore, m_args); // Uses native endianness
}
Value* Ext::getDataElem(unsigned _index, const Twine& _name)
{
auto valuePtr = m_builder.CreateStructGEP(m_data, _index, _name);
return m_builder.CreateLoad(valuePtr);
}
Value* Ext::code() { return getDataElem(0, "code"); }
Value* Ext::calldataload(Value* _index)
{
m_builder.CreateStore(_index, m_args[0]);

5
libevmjit/Ext.h

@ -20,8 +20,6 @@ public:
llvm::Value* store(llvm::Value* _index);
void setStore(llvm::Value* _index, llvm::Value* _value);
llvm::Value* code();
llvm::Value* balance(llvm::Value* _address);
void suicide(llvm::Value* _address);
llvm::Value* calldataload(llvm::Value* _index);
@ -33,8 +31,6 @@ public:
llvm::Value* codeAt(llvm::Value* _addr);
llvm::Value* codesizeAt(llvm::Value* _addr);
private:
llvm::Value* getDataElem(unsigned _index, const llvm::Twine& _name = "");
private:
llvm::Value* m_args[2];
@ -46,7 +42,6 @@ private:
llvm::Value* m_arg7;
llvm::Value* m_arg8;
llvm::Value* m_data;
llvm::Function* m_init;
llvm::Function* m_store;
llvm::Function* m_setStore;
llvm::Function* m_calldataload;

8
libevmjit/Runtime.cpp

@ -23,6 +23,7 @@ llvm::StructType* RuntimeData::getType()
llvm::Type* elems[] =
{
llvm::ArrayType::get(Type::i256, _size),
Type::BytePtr,
Type::BytePtr
};
type = llvm::StructType::create(elems, "RuntimeData");
@ -77,6 +78,7 @@ Runtime::Runtime(u256 _gas, ExtVMFace& _ext):
set(RuntimeData::GasLimit, _ext.currentBlock.gasLimit);
set(RuntimeData::CodeSize, _ext.code.size()); // TODO: Use constant
m_data.callData = _ext.data.data();
m_data.code = _ext.code.data();
}
Runtime::~Runtime()
@ -165,6 +167,12 @@ llvm::Value* RuntimeManager::getCallData()
return getBuilder().CreateLoad(ptr, "calldata");
}
llvm::Value* RuntimeManager::getCode()
{
auto ptr = getBuilder().CreateStructGEP(getRuntimePtr(), 2, "codePtr");
return getBuilder().CreateLoad(ptr, "code");
}
llvm::Value* RuntimeManager::getGas()
{
return get(RuntimeData::Gas);

2
libevmjit/Runtime.h

@ -46,6 +46,7 @@ struct RuntimeData
i256 elems[_size];
byte const* callData;
byte const* code;
static llvm::StructType* getType();
};
@ -92,6 +93,7 @@ public:
llvm::Value* get(Instruction _inst);
llvm::Value* getGas(); // TODO: Remove
llvm::Value* getCallData();
llvm::Value* getCode();
void setGas(llvm::Value* _gas);
private:

Loading…
Cancel
Save