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

This commit is contained in:
Paweł Bylica 2014-10-01 12:44:45 +02:00
parent ac795c481b
commit fcde2f3d22
6 changed files with 64 additions and 3 deletions

View file

@ -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;
}
}
}

View file

@ -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");

View file

@ -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"
{

View file

@ -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;

View file

@ -1 +1 @@
30
30333234363a

View file

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