Browse Source

Use uint64 type for code size

cl-refactor
Paweł Bylica 10 years ago
parent
commit
a751baadcb
  1. 2
      libevmjit-cpp/JitVM.cpp
  2. 8
      libevmjit/Compiler.cpp
  3. 2
      libevmjit/RuntimeData.h
  4. 15
      libevmjit/RuntimeManager.cpp
  5. 1
      libevmjit/RuntimeManager.h
  6. 2
      libevmjit/interface.cpp

2
libevmjit-cpp/JitVM.cpp

@ -25,9 +25,9 @@ bytesConstRef JitVM::go(ExtVMFace& _ext, OnOpFunc const&, uint64_t)
m_data.elems[RuntimeData::Number] = eth2llvm(_ext.currentBlock.number);
m_data.elems[RuntimeData::Difficulty] = eth2llvm(_ext.currentBlock.difficulty);
m_data.elems[RuntimeData::GasLimit] = eth2llvm(_ext.currentBlock.gasLimit);
m_data.elems[RuntimeData::CodeSize] = eth2llvm(_ext.code.size());
m_data.callData = _ext.data.data();
m_data.code = _ext.code.data();
m_data.codeSize = _ext.code.size();
auto env = reinterpret_cast<Env*>(&_ext);
auto exitCode = m_engine.run(_ext.code, &m_data, env);

8
libevmjit/Compiler.cpp

@ -638,7 +638,6 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode
case Instruction::ORIGIN:
case Instruction::CALLVALUE:
case Instruction::CALLDATASIZE:
case Instruction::CODESIZE:
case Instruction::GASPRICE:
case Instruction::COINBASE:
case Instruction::TIMESTAMP:
@ -651,6 +650,11 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode
break;
}
case Instruction::CODESIZE:
// TODO: Use constant
stack.push(_runtimeManager.getCodeSize());
break;
case Instruction::BLOCKHASH:
{
auto number = stack.pop();
@ -695,7 +699,7 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode
auto reqBytes = stack.pop();
auto srcPtr = _runtimeManager.getCode(); // TODO: Code & its size are constants, feature #80814234
auto srcSize = _runtimeManager.get(RuntimeData::CodeSize);
auto srcSize = _runtimeManager.getCodeSize();
_memory.copyBytes(srcPtr, srcSize, srcIdx, destMemIdx, reqBytes);
break;

2
libevmjit/RuntimeData.h

@ -26,7 +26,6 @@ struct RuntimeData
Number,
Difficulty,
GasLimit,
CodeSize,
_size,
@ -38,6 +37,7 @@ struct RuntimeData
i256 elems[_size] = {};
byte const* callData = nullptr;
byte const* code = nullptr;
uint64_t codeSize = 0;
};
/// VM Environment (ExtVM) opaque type

15
libevmjit/RuntimeManager.cpp

@ -24,7 +24,8 @@ llvm::StructType* RuntimeManager::getRuntimeDataType()
{
llvm::ArrayType::get(Type::Word, RuntimeData::_size), // i256[]
Type::BytePtr, // callData
Type::BytePtr // code
Type::BytePtr, // code
Type::Size // codeSize
};
type = llvm::StructType::create(elems, "RuntimeData");
}
@ -68,7 +69,6 @@ llvm::Twine getName(RuntimeData::Index _index)
case RuntimeData::Number: return "number";
case RuntimeData::Difficulty: return "difficulty";
case RuntimeData::GasLimit: return "gaslimit";
case RuntimeData::CodeSize: return "codesize";
}
}
}
@ -158,14 +158,13 @@ llvm::Value* RuntimeManager::get(Instruction _inst)
case Instruction::NUMBER: return get(RuntimeData::Number);
case Instruction::DIFFICULTY: return get(RuntimeData::Difficulty);
case Instruction::GASLIMIT: return get(RuntimeData::GasLimit);
case Instruction::CODESIZE: return get(RuntimeData::CodeSize);
}
}
llvm::Value* RuntimeManager::getCallData()
{
auto ptr = getBuilder().CreateStructGEP(getDataPtr(), 1, "calldataPtr");
return getBuilder().CreateLoad(ptr, "calldata");
return getBuilder().CreateLoad(ptr, "callData");
}
llvm::Value* RuntimeManager::getCode()
@ -174,6 +173,14 @@ llvm::Value* RuntimeManager::getCode()
return getBuilder().CreateLoad(ptr, "code");
}
llvm::Value* RuntimeManager::getCodeSize()
{
auto ptr = getBuilder().CreateStructGEP(getDataPtr(), 3);
auto value = getBuilder().CreateLoad(ptr, "codeSize");
assert(value->getType() == Type::Size);
return getBuilder().CreateZExt(value, Type::Word);
}
llvm::Value* RuntimeManager::getJmpBuf()
{
auto ptr = getBuilder().CreateStructGEP(getRuntimePtr(), 2, "jmpbufPtr");

1
libevmjit/RuntimeManager.h

@ -26,6 +26,7 @@ public:
llvm::Value* getGas(); // TODO: Remove
llvm::Value* getCallData();
llvm::Value* getCode();
llvm::Value* getCodeSize();
void setGas(llvm::Value* _gas);
void registerReturnData(llvm::Value* _index, llvm::Value* _size);

2
libevmjit/interface.cpp

@ -14,7 +14,7 @@ evmjit_result evmjit_run(void* _data, void* _env)
ExecutionEngine engine;
auto codePtr = data->code;
auto codeSize = data->elems[RuntimeData::CodeSize].a;
auto codeSize = data->codeSize;
bytes bytecode;
bytecode.insert(bytecode.end(), codePtr, codePtr + codeSize);

Loading…
Cancel
Save