6
6
* LICENSE file in the root directory of this source tree.
7
7
*/
8
8
9
- #include < stdio.h>
9
+ #include < executorch/devtools/etdump/emitter.h>
10
+
10
11
#include < cstdint>
12
+ #include < cstring>
13
+
14
+ #include < executorch/devtools/etdump/etdump_flatcc.h>
15
+ #include < executorch/runtime/platform/assert.h>
16
+
17
+ #include < flatcc/flatcc_builder.h>
11
18
12
- #include " executorch/devtools/etdump/emitter.h"
13
- #include " executorch/runtime/platform/assert.h"
19
+ using executorch::etdump::internal::ETDumpStaticAllocator;
14
20
15
- namespace torch {
16
- namespace executor {
21
+ namespace executorch {
22
+ namespace etdump {
23
+ namespace internal {
17
24
18
- static int _allocator_fn (
25
+ namespace {
26
+
27
+ int allocator_fn (
19
28
void * alloc_context,
20
29
flatcc_iovec_t * b,
21
30
size_t request,
@@ -24,8 +33,8 @@ static int _allocator_fn(
24
33
void * p;
25
34
size_t n;
26
35
27
- struct etdump_static_allocator * state =
28
- ( struct etdump_static_allocator *) alloc_context;
36
+ ETDumpStaticAllocator * state =
37
+ reinterpret_cast <ETDumpStaticAllocator*>( alloc_context) ;
29
38
30
39
// This allocator doesn't support freeing memory.
31
40
if (request == 0 ) {
@@ -113,14 +122,14 @@ static int _allocator_fn(
113
122
114
123
// This emitter implementation emits to a fixed size buffer and will fail if it
115
124
// runs out of room on either end.
116
- static int _emitter_fn (
125
+ int emitter_fn (
117
126
void * emit_context,
118
127
const flatcc_iovec_t * iov,
119
128
int iov_count,
120
129
flatbuffers_soffset_t offset,
121
130
size_t len) {
122
- struct etdump_static_allocator * E =
123
- ( struct etdump_static_allocator *) emit_context;
131
+ ETDumpStaticAllocator * E =
132
+ reinterpret_cast <ETDumpStaticAllocator*>( emit_context) ;
124
133
uint8_t * p;
125
134
126
135
if (offset < 0 ) {
@@ -144,40 +153,15 @@ static int _emitter_fn(
144
153
return 0 ;
145
154
}
146
155
147
- /* ******************************************************************************
148
- * Public Functions
149
- ******************************************************************************/
150
-
151
- int etdump_static_allocator_builder_init (
152
- flatcc_builder_t * builder,
153
- struct etdump_static_allocator * alloc) {
154
- ET_CHECK (builder != nullptr );
155
- ET_CHECK (alloc != nullptr );
156
-
157
- // Ensure data size is multiple of 32 (minimum allocation size).
158
- ET_CHECK ((alloc->data_size & 0x1F ) == 0 );
159
- // Ensure out_size is divisable by 2 to ensure front/back sizes are equal for
160
- // emitter..
161
- ET_CHECK ((alloc->out_size & 0x1 ) == 0 );
162
-
163
- return flatcc_builder_custom_init (
164
- builder, _emitter_fn, alloc, _allocator_fn, alloc);
165
- }
166
-
167
- void etdump_static_allocator_reset (struct etdump_static_allocator * alloc) {
168
- ET_CHECK (alloc != nullptr );
169
- alloc->allocated = 0 ;
170
- size_t n = alloc->out_size / 2 ;
171
- alloc->front_cursor = &alloc->data [alloc->data_size + n];
172
- alloc->front_left = n;
173
- }
156
+ } // namespace
174
157
175
- int et_flatcc_custom_init (
158
+ int etdump_flatcc_custom_init (
176
159
flatcc_builder_t * builder,
177
- struct etdump_static_allocator * alloc) {
160
+ struct ETDumpStaticAllocator * alloc) {
178
161
return flatcc_builder_custom_init (
179
- builder, _emitter_fn , alloc, _allocator_fn , alloc);
162
+ builder, emitter_fn , alloc, allocator_fn , alloc);
180
163
}
181
164
182
- } // namespace executor
183
- } // namespace torch
165
+ } // namespace internal
166
+ } // namespace etdump
167
+ } // namespace executorch
0 commit comments