Fabcoin Core  0.16.2
P2P Digital Currency
Ext.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <array>
4 
5 #include "JIT.h"
6 #include "CompilerHelper.h"
7 
8 namespace dev
9 {
10 namespace eth
11 {
12 namespace jit
13 {
14  class Memory;
15 
16 struct MemoryRef
17 {
20 };
21 
22 template<typename _EnumT>
23 struct sizeOf
24 {
25  static const size_t value = static_cast<size_t>(_EnumT::_size);
26 };
27 
28 enum class EnvFunc
29 {
30  sload,
31  sstore,
32  sha3,
33  balance,
34  create,
35  call,
36  log,
37  blockhash,
38  extcode,
39 
40  _size
41 };
42 
43 class Ext : public RuntimeHelper
44 {
45 public:
46  Ext(RuntimeManager& _runtimeManager, Memory& _memoryMan);
47 
48  llvm::Value* sload(llvm::Value* _index);
49  void sstore(llvm::Value* _index, llvm::Value* _value);
50 
51  llvm::Value* query(evm_query_key _key);
52  llvm::Value* balance(llvm::Value* _address);
53  llvm::Value* exists(llvm::Value* _address);
54  llvm::Value* calldataload(llvm::Value* _index);
55  std::tuple<llvm::Value*, llvm::Value*> create(llvm::Value* _gas, llvm::Value* _endowment, llvm::Value* _initOff, llvm::Value* _initSize);
56  llvm::Value* blockHash(llvm::Value* _number);
57 
58  llvm::Value* sha3(llvm::Value* _inOff, llvm::Value* _inSize);
60  llvm::Value* extcodesize(llvm::Value* _addr);
61 
62  void log(llvm::Value* _memIdx, llvm::Value* _numBytes, llvm::ArrayRef<llvm::Value*> _topics);
63  void selfdestruct(llvm::Value* _beneficiary);
64 
66  llvm::Value* _gas,
67  llvm::Value* _addr,
68  llvm::Value* _value,
69  llvm::Value* _inOff,
70  llvm::Value* _inSize,
71  llvm::Value* _outOff,
72  llvm::Value* _outSize);
73 
74 private:
76 
78 
79  std::array<llvm::Function*, sizeOf<EnvFunc>::value> m_funcs;
80  std::array<llvm::Value*, 8> m_argAllocas;
81  size_t m_argCounter = 0;
82 
85  llvm::Value* m_topics = nullptr;
86 
87  llvm::CallInst* createCall(EnvFunc _funcId, std::initializer_list<llvm::Value*> const& _args);
88  llvm::Value* getArgAlloca();
89  llvm::Value* byPtr(llvm::Value* _value);
90 
91  llvm::Value* createCABICall(llvm::Function* _func,
92  std::initializer_list<llvm::Value*> const& _args);
93 };
94 
95 
96 }
97 }
98 }
99 
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
llvm::Value * ptr
Definition: Ext.h:18
std::array< llvm::Function *, sizeOf< EnvFunc >::value > m_funcs
Definition: Ext.h:79
llvm::Value * m_size
Definition: Ext.h:77
Config::Value_type Value
evm_call_kind
The kind of call-like instruction.
Definition: evm.h:277
llvm::Value * size
Definition: Ext.h:19
std::array< llvm::Value *, 8 > m_argAllocas
Definition: Ext.h:80
Memory & m_memoryMan
Definition: Ext.h:75
Compiler helper that depends on runtime data.
evm_query_key
The query callback key.
Definition: evm.h:109