Fabcoin Core  0.16.2
P2P Digital Currency
Array.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <functional>
4 
5 #include "CompilerHelper.h"
6 
7 namespace dev
8 {
9 namespace eth
10 {
11 namespace jit
12 {
13 
15 {
16 public:
17  using Creator = std::function<llvm::Function*()>;
18 
19  LazyFunction(Creator _creator) :
20  m_creator(_creator)
21  {}
22 
23  llvm::Value* call(IRBuilder& _builder, std::initializer_list<llvm::Value*> const& _args, llvm::Twine const& _name = "");
24 
25 private:
26  llvm::Function* m_func = nullptr;
28 };
29 
30 class Array : public CompilerHelper
31 {
32 public:
33  Array(IRBuilder& _builder, char const* _name);
34  Array(IRBuilder& _builder, llvm::Value* _array);
35 
36  void push(llvm::Value* _value) { m_pushFunc.call(m_builder, {m_array, _value}); }
37  void set(llvm::Value* _index, llvm::Value* _value) { m_setFunc.call(m_builder, {m_array, _index, _value}); }
38  llvm::Value* get(llvm::Value* _index) { return m_getFunc.call(m_builder, {m_array, _index}); }
39  void pop(llvm::Value* _count);
40  llvm::Value* size(llvm::Value* _array = nullptr);
41  void free() { m_freeFunc.call(m_builder, {m_array}); }
42 
43  void extend(llvm::Value* _arrayPtr, llvm::Value* _size);
44  llvm::Value* getPtr(llvm::Value* _arrayPtr, llvm::Value* _index) { return m_getPtrFunc.call(m_builder, {_arrayPtr, _index}); }
45 
46  llvm::Value* getPointerTo() const { return m_array; }
47 
48  static llvm::Type* getType();
49 
50 private:
51  llvm::Value* m_array = nullptr;
52 
53  llvm::Function* createArrayPushFunc();
54  llvm::Function* createArraySetFunc();
55  llvm::Function* createArrayGetFunc();
56  llvm::Function* createGetPtrFunc();
57  llvm::Function* createFreeFunc();
58  llvm::Function* createExtendFunc();
59  llvm::Function* getReallocFunc();
60 
61  LazyFunction m_pushFunc = {[this](){ return createArrayPushFunc(); }};
62  LazyFunction m_setFunc = {[this](){ return createArraySetFunc(); }};
63  LazyFunction m_getPtrFunc = {[this](){ return createGetPtrFunc(); }};
64  LazyFunction m_getFunc = {[this](){ return createArrayGetFunc(); }};
65  LazyFunction m_freeFunc = {[this](){ return createFreeFunc(); }};
66  LazyFunction m_extendFunc = {[this](){ return createExtendFunc(); }};
67  LazyFunction m_reallocFunc = {[this](){ return getReallocFunc(); }};
68 };
69 
70 }
71 }
72 }
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
std::function< llvm::Function *()> Creator
Definition: Array.h:17
llvm::Value * call(IRBuilder &_builder, std::initializer_list< llvm::Value * > const &_args, llvm::Twine const &_name="")
Definition: Array.cpp:20
bool extend(Iterator it, const Pair &other)
Definition: lockedpool.cpp:80
llvm::Value * getPointerTo() const
Definition: Array.h:46
Base class for compiler helpers like Memory, GasMeter, etc.
Config::Value_type Value
Config::Array_type Array
LazyFunction(Creator _creator)
Definition: Array.h:19
uint8_t const size_t const size
Definition: sha3.h:20
void push(llvm::Value *_value)
Definition: Array.h:36
llvm::Value * getPtr(llvm::Value *_arrayPtr, llvm::Value *_index)
Definition: Array.h:44
llvm::IRBuilder<> IRBuilder
llvm::Function * m_func
Definition: Array.h:26