1 | //===- EPCGenericMemoryAccess.h - Generic EPC MemoryAccess impl -*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // Implements ExecutorProcessControl::MemoryAccess by making calls to |
10 | // ExecutorProcessControl::callWrapperAsync. |
11 | // |
12 | // This simplifies the implementaton of new ExecutorProcessControl instances, |
13 | // as this implementation will always work (at the cost of some performance |
14 | // overhead for the calls). |
15 | // |
16 | //===----------------------------------------------------------------------===// |
17 | |
18 | #ifndef LLVM_EXECUTIONENGINE_ORC_EPCGENERICMEMORYACCESS_H |
19 | #define LLVM_EXECUTIONENGINE_ORC_EPCGENERICMEMORYACCESS_H |
20 | |
21 | #include "llvm/ExecutionEngine/Orc/Core.h" |
22 | |
23 | namespace llvm { |
24 | namespace orc { |
25 | |
26 | class EPCGenericMemoryAccess : public ExecutorProcessControl::MemoryAccess { |
27 | public: |
28 | /// Function addresses for memory access. |
29 | struct FuncAddrs { |
30 | ExecutorAddr WriteUInt8s; |
31 | ExecutorAddr WriteUInt16s; |
32 | ExecutorAddr WriteUInt32s; |
33 | ExecutorAddr WriteUInt64s; |
34 | ExecutorAddr WriteBuffers; |
35 | ExecutorAddr WritePointers; |
36 | }; |
37 | |
38 | /// Create an EPCGenericMemoryAccess instance from a given set of |
39 | /// function addrs. |
40 | EPCGenericMemoryAccess(ExecutorProcessControl &EPC, FuncAddrs FAs) |
41 | : EPC(EPC), FAs(FAs) {} |
42 | |
43 | void writeUInt8sAsync(ArrayRef<tpctypes::UInt8Write> Ws, |
44 | WriteResultFn OnWriteComplete) override { |
45 | using namespace shared; |
46 | EPC.callSPSWrapperAsync<void(SPSSequence<SPSMemoryAccessUInt8Write>)>( |
47 | WrapperFnAddr: FAs.WriteUInt8s, SendResult: std::move(OnWriteComplete), Args: Ws); |
48 | } |
49 | |
50 | void writeUInt16sAsync(ArrayRef<tpctypes::UInt16Write> Ws, |
51 | WriteResultFn OnWriteComplete) override { |
52 | using namespace shared; |
53 | EPC.callSPSWrapperAsync<void(SPSSequence<SPSMemoryAccessUInt16Write>)>( |
54 | WrapperFnAddr: FAs.WriteUInt16s, SendResult: std::move(OnWriteComplete), Args: Ws); |
55 | } |
56 | |
57 | void writeUInt32sAsync(ArrayRef<tpctypes::UInt32Write> Ws, |
58 | WriteResultFn OnWriteComplete) override { |
59 | using namespace shared; |
60 | EPC.callSPSWrapperAsync<void(SPSSequence<SPSMemoryAccessUInt32Write>)>( |
61 | WrapperFnAddr: FAs.WriteUInt32s, SendResult: std::move(OnWriteComplete), Args: Ws); |
62 | } |
63 | |
64 | void writeUInt64sAsync(ArrayRef<tpctypes::UInt64Write> Ws, |
65 | WriteResultFn OnWriteComplete) override { |
66 | using namespace shared; |
67 | EPC.callSPSWrapperAsync<void(SPSSequence<SPSMemoryAccessUInt64Write>)>( |
68 | WrapperFnAddr: FAs.WriteUInt64s, SendResult: std::move(OnWriteComplete), Args: Ws); |
69 | } |
70 | |
71 | void writeBuffersAsync(ArrayRef<tpctypes::BufferWrite> Ws, |
72 | WriteResultFn OnWriteComplete) override { |
73 | using namespace shared; |
74 | EPC.callSPSWrapperAsync<void(SPSSequence<SPSMemoryAccessBufferWrite>)>( |
75 | WrapperFnAddr: FAs.WriteBuffers, SendResult: std::move(OnWriteComplete), Args: Ws); |
76 | } |
77 | |
78 | void writePointersAsync(ArrayRef<tpctypes::PointerWrite> Ws, |
79 | WriteResultFn OnWriteComplete) override { |
80 | using namespace shared; |
81 | EPC.callSPSWrapperAsync<void(SPSSequence<SPSMemoryAccessPointerWrite>)>( |
82 | WrapperFnAddr: FAs.WritePointers, SendResult: std::move(OnWriteComplete), Args: Ws); |
83 | } |
84 | |
85 | private: |
86 | ExecutorProcessControl &EPC; |
87 | FuncAddrs FAs; |
88 | }; |
89 | |
90 | } // end namespace orc |
91 | } // end namespace llvm |
92 | |
93 | #endif // LLVM_EXECUTIONENGINE_ORC_EPCGENERICMEMORYACCESS_H |
94 | |