Browse Source

Moving CALLDATA data from Ext to Runtime [#81470252]

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

2
libevmjit/Compiler.cpp

@ -720,7 +720,7 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
auto srcIdx = stack.pop(); auto srcIdx = stack.pop();
auto reqBytes = stack.pop(); auto reqBytes = stack.pop();
auto srcPtr = ext.calldata(); auto srcPtr = _runtimeManager.getCallData();
auto srcSize = _runtimeManager.get(RuntimeData::CallDataSize); auto srcSize = _runtimeManager.get(RuntimeData::CallDataSize);
memory.copyBytes(srcPtr, srcSize, srcIdx, destMemIdx, reqBytes); memory.copyBytes(srcPtr, srcSize, srcIdx, destMemIdx, reqBytes);

4
libevmjit/Ext.cpp

@ -52,7 +52,6 @@ Ext::Ext(RuntimeManager& _runtimeManager):
m_arg8 = m_builder.CreateAlloca(i256Ty, nullptr, "ext.arg8"); m_arg8 = m_builder.CreateAlloca(i256Ty, nullptr, "ext.arg8");
Type* elements[] = { Type* elements[] = {
i8PtrTy, // byte* calldata
i8PtrTy, // byte* code i8PtrTy, // byte* code
}; };
@ -100,8 +99,7 @@ Value* Ext::getDataElem(unsigned _index, const Twine& _name)
return m_builder.CreateLoad(valuePtr); return m_builder.CreateLoad(valuePtr);
} }
Value* Ext::calldata() { return getDataElem(0, "calldata"); } Value* Ext::code() { return getDataElem(0, "code"); }
Value* Ext::code() { return getDataElem(1, "code"); }
Value* Ext::calldataload(Value* _index) Value* Ext::calldataload(Value* _index)
{ {

1
libevmjit/Ext.h

@ -20,7 +20,6 @@ public:
llvm::Value* store(llvm::Value* _index); llvm::Value* store(llvm::Value* _index);
void setStore(llvm::Value* _index, llvm::Value* _value); void setStore(llvm::Value* _index, llvm::Value* _value);
llvm::Value* calldata();
llvm::Value* code(); llvm::Value* code();
llvm::Value* balance(llvm::Value* _address); llvm::Value* balance(llvm::Value* _address);

10
libevmjit/Runtime.cpp

@ -22,7 +22,8 @@ llvm::StructType* RuntimeData::getType()
{ {
llvm::Type* elems[] = llvm::Type* elems[] =
{ {
llvm::ArrayType::get(Type::i256, _size) llvm::ArrayType::get(Type::i256, _size),
Type::BytePtr
}; };
type = llvm::StructType::create(elems, "RuntimeData"); type = llvm::StructType::create(elems, "RuntimeData");
} }
@ -75,6 +76,7 @@ Runtime::Runtime(u256 _gas, ExtVMFace& _ext):
set(RuntimeData::Difficulty, _ext.currentBlock.difficulty); set(RuntimeData::Difficulty, _ext.currentBlock.difficulty);
set(RuntimeData::GasLimit, _ext.currentBlock.gasLimit); set(RuntimeData::GasLimit, _ext.currentBlock.gasLimit);
set(RuntimeData::CodeSize, _ext.code.size()); // TODO: Use constant set(RuntimeData::CodeSize, _ext.code.size()); // TODO: Use constant
m_data.callData = _ext.data.data();
} }
Runtime::~Runtime() Runtime::~Runtime()
@ -157,6 +159,12 @@ llvm::Value* RuntimeManager::get(Instruction _inst)
} }
} }
llvm::Value* RuntimeManager::getCallData()
{
auto ptr = getBuilder().CreateStructGEP(getRuntimePtr(), 1, "calldataPtr");
return getBuilder().CreateLoad(ptr, "calldata");
}
llvm::Value* RuntimeManager::getGas() llvm::Value* RuntimeManager::getGas()
{ {
return get(RuntimeData::Gas); return get(RuntimeData::Gas);

4
libevmjit/Runtime.h

@ -45,6 +45,7 @@ struct RuntimeData
}; };
i256 elems[_size]; i256 elems[_size];
byte const* callData;
static llvm::StructType* getType(); static llvm::StructType* getType();
}; };
@ -89,7 +90,8 @@ public:
llvm::Value* get(RuntimeData::Index _index); llvm::Value* get(RuntimeData::Index _index);
llvm::Value* get(Instruction _inst); llvm::Value* get(Instruction _inst);
llvm::Value* getGas(); llvm::Value* getGas(); // TODO: Remove
llvm::Value* getCallData();
void setGas(llvm::Value* _gas); void setGas(llvm::Value* _gas);
private: private:

Loading…
Cancel
Save