Browse Source

Accessing Ext static data: CALLER, ORIGIN, CALLVALUE, CALLDATASIZE, GASPRICE

cl-refactor
Paweł Bylica 10 years ago
parent
commit
fcde2f3d22
  1. 35
      evmcc/Compiler.cpp
  2. 6
      evmcc/ExecutionEngine.cpp
  3. 11
      evmcc/Ext.cpp
  4. 8
      evmcc/Ext.h
  5. 2
      evmcc/bytecode/ext_test.evm
  6. 5
      evmcc/lll/ext_test.lll

35
evmcc/Compiler.cpp

@ -270,6 +270,41 @@ std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)
break;
}
case Instruction::CALLER:
{
auto value = ext.caller();
stack.push(value);
break;
}
case Instruction::ORIGIN:
{
auto value = ext.origin();
stack.push(value);
break;
}
case Instruction::CALLVALUE:
{
auto value = ext.callvalue();
stack.push(value);
break;
}
case Instruction::CALLDATASIZE:
{
auto value = ext.calldatasize();
stack.push(value);
break;
}
case Instruction::GASPRICE:
{
auto value = ext.gasprice();
stack.push(value);
break;
}
}
}

6
evmcc/ExecutionEngine.cpp

@ -70,6 +70,12 @@ int ExecutionEngine::run(std::unique_ptr<llvm::Module> _module)
auto ext = std::make_unique<dev::eth::ExtVMFace>();
ext->myAddress = dev::Address(1122334455667788);
ext->caller = dev::Address(0xfacefacefaceface);
ext->origin = dev::Address(101010101010101010);
ext->value = 0xabcd;
ext->gasPrice = 1002;
std::string calldata = "Hello World!";
ext->data = calldata;
Ext::init(std::move(ext));
auto entryFunc = module->getFunction("main");

11
evmcc/Ext.cpp

@ -87,12 +87,19 @@ void Ext::setStore(llvm::Value* _index, llvm::Value* _value)
m_builder.CreateCall(m_setStore, m_args);
}
Value* Ext::address()
Value* Ext::getDataElem(unsigned _index, const Twine& _name)
{
auto valuePtr = m_builder.CreateStructGEP(m_data, 0);
auto valuePtr = m_builder.CreateStructGEP(m_data, _index, _name);
return m_builder.CreateLoad(valuePtr);
}
Value* Ext::address() { return getDataElem(0, "address"); }
Value* Ext::caller() { return getDataElem(1, "caller"); }
Value* Ext::origin() { return getDataElem(2, "origin"); }
Value* Ext::callvalue() { return getDataElem(3, "callvalue"); }
Value* Ext::calldatasize() { return getDataElem(5, "calldatasize"); }
Value* Ext::gasprice() { return getDataElem(4, "gasprice"); }
extern "C"
{

8
evmcc/Ext.h

@ -20,6 +20,14 @@ public:
void setStore(llvm::Value* _index, llvm::Value* _value);
llvm::Value* address();
llvm::Value* caller();
llvm::Value* origin();
llvm::Value* callvalue();
llvm::Value* calldatasize();
llvm::Value* gasprice();
private:
llvm::Value* getDataElem(unsigned _index, const llvm::Twine& _name = "");
private:
llvm::IRBuilder<>& m_builder;

2
evmcc/bytecode/ext_test.evm

@ -1 +1 @@
30
30333234363a

5
evmcc/lll/ext_test.lll

@ -1,4 +1,9 @@
(asm
ADDRESS
CALLER
ORIGIN
CALLVALUE
CALLDATASIZE
GASPRICE
)
Loading…
Cancel
Save