|
6 | 6 | //
|
7 | 7 | // Identification: src/include/codegen/codegen.h
|
8 | 8 | //
|
9 |
| -// Copyright (c) 2015-2017, Carnegie Mellon University Database Group |
| 9 | +// Copyright (c) 2015-2018, Carnegie Mellon University Database Group |
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
|
20 | 20 | namespace peloton {
|
21 | 21 | namespace codegen {
|
22 | 22 |
|
23 |
| -/// A proxy to a member of a class. Users must provide both the physical |
24 |
| -/// position of the member in the class, and the C++ type of the member. |
| 23 | +// Forward declare |
25 | 24 | class CodeGen;
|
26 | 25 |
|
27 |
| -struct CppProxyMember { |
28 |
| - uint32_t slot; |
29 |
| - |
30 |
| - explicit CppProxyMember(uint32_t _slot) noexcept : slot(_slot) {} |
| 26 | +/** |
| 27 | + * A CppProxyMember defines an access proxy to a member defined in a C++ class. |
| 28 | + * Users can use this class to generate code to load values from and store |
| 29 | + * values into member variables of C++ classes/structs available at runtime. |
| 30 | + * Each member is defined by a slot position in the C++ struct. Slots are |
| 31 | + * zero-based ordinal numbers assigned to fields increasing order of appearance |
| 32 | + * in the struct/class. |
| 33 | + */ |
| 34 | +class CppProxyMember { |
| 35 | + public: |
| 36 | + explicit CppProxyMember(uint32_t slot) noexcept : slot_(slot) {} |
| 37 | + |
| 38 | + /** |
| 39 | + * Load this member field from the provided struct pointer. |
| 40 | + * |
| 41 | + * @param codegen The codegen instance |
| 42 | + * @param obj_ptr A pointer to a runtime C++ struct |
| 43 | + * @return The value of the field |
| 44 | + */ |
| 45 | + llvm::Value *Load(CodeGen &codegen, llvm::Value *obj_ptr) const; |
| 46 | + |
| 47 | + /** |
| 48 | + * Store the provided value into this member field of the provided struct. |
| 49 | + * |
| 50 | + * @param codegen The codegen instance |
| 51 | + * @param obj_ptr A pointer to a runtime C++ struct |
| 52 | + * @param val The value of the field |
| 53 | + */ |
| 54 | + void Store(CodeGen &codegen, llvm::Value *obj_ptr, llvm::Value *val) const; |
31 | 55 |
|
32 |
| - llvm::Value *Load(CodeGen &codegen, llvm::Value *ptr) const; |
| 56 | + private: |
| 57 | + // The slot position |
| 58 | + uint32_t slot_; |
33 | 59 | };
|
34 | 60 |
|
35 | 61 | //===----------------------------------------------------------------------===//
|
@@ -90,8 +116,13 @@ class CodeGen {
|
90 | 116 | }
|
91 | 117 |
|
92 | 118 | template <typename T>
|
93 |
| - llvm::Value *Load(const T &loader, llvm::Value *ptr) { |
94 |
| - return loader.Load(*this, ptr); |
| 119 | + llvm::Value *Load(const T &loader, llvm::Value *obj_ptr) { |
| 120 | + return loader.Load(*this, obj_ptr); |
| 121 | + } |
| 122 | + |
| 123 | + template <typename T> |
| 124 | + void Store(const T &storer, llvm::Value *obj_ptr, llvm::Value *val) { |
| 125 | + storer.Store(*this, obj_ptr, val); |
95 | 126 | }
|
96 | 127 |
|
97 | 128 | //===--------------------------------------------------------------------===//
|
|
0 commit comments