Flutter Engine
The Flutter Engine
offsets_extractor.cc
Go to the documentation of this file.
1// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#include <iostream>
6
9#include "vm/dart_api_state.h"
10#include "vm/dart_entry.h"
11#include "vm/longjump.h"
12#include "vm/native_arguments.h"
13#include "vm/native_entry.h"
14#include "vm/object.h"
15#include "vm/object_store.h"
16#include "vm/runtime_entry.h"
17#include "vm/symbols.h"
18#include "vm/timeline.h"
19
20#if defined(PRODUCT)
21#define PRODUCT_DEF "defined(PRODUCT)"
22#else
23#define PRODUCT_DEF "!defined(PRODUCT)"
24#endif
25
26#if defined(TARGET_ARCH_ARM)
27#define ARCH_DEF_CPU "defined(TARGET_ARCH_ARM)"
28#elif defined(TARGET_ARCH_X64)
29#define ARCH_DEF_CPU "defined(TARGET_ARCH_X64)"
30#elif defined(TARGET_ARCH_IA32)
31#define ARCH_DEF_CPU "defined(TARGET_ARCH_IA32)"
32#elif defined(TARGET_ARCH_ARM64)
33#define ARCH_DEF_CPU "defined(TARGET_ARCH_ARM64)"
34#elif defined(TARGET_ARCH_RISCV32)
35#define ARCH_DEF_CPU "defined(TARGET_ARCH_RISCV32)"
36#elif defined(TARGET_ARCH_RISCV64)
37#define ARCH_DEF_CPU "defined(TARGET_ARCH_RISCV64)"
38#else
39#error Unknown architecture
40#endif
41
42#if defined(DART_COMPRESSED_POINTERS)
43#define COMPRESSED_DEF "defined(DART_COMPRESSED_POINTERS)"
44#else
45#define COMPRESSED_DEF "!defined(DART_COMPRESSED_POINTERS)"
46#endif
47
48#define PREPROCESSOR_CONDITION \
49 "#if " PRODUCT_DEF " && " ARCH_DEF_CPU " && " COMPRESSED_DEF
50
51#define PREPROCESSOR_CONDITION_END \
52 "#endif // " PRODUCT_DEF " && \n // " ARCH_DEF_CPU \
53 " && \n // " COMPRESSED_DEF
54
55namespace dart {
56
57void Assert::Fail(const char* format, ...) const {
58 abort();
59}
60
62 public:
63 static void DumpOffsets() {
64// Currently we have two different axes for offset generation:
65//
66// * Target architecture
67// * DART_PRECOMPILED_RUNTIME (i.e, AOT vs. JIT)
68//
69// TODO(dartbug.com/43646): Add DART_PRECOMPILER as another axis.
70
71// These macros don't use any special constants, just method calls, so no
72// output.
73#define PRINT_ARRAY_SIZEOF(Class, Name, ElementOffset)
74#define PRINT_PAYLOAD_SIZEOF(Class, Name, HeaderSize)
75
76#if defined(DART_PRECOMPILED_RUNTIME)
77
78#define PRINT_FIELD_OFFSET(Class, Name) \
79 std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
80 "_" #Name " = 0x" \
81 << Class::Name() << ";\n";
82
83#define PRINT_ARRAY_LAYOUT(Class, Name) \
84 std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
85 "_elements_start_offset = 0x" \
86 << Class::ArrayTraits::elements_start_offset() << ";\n"; \
87 std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
88 "_element_size = 0x" \
89 << Class::ArrayTraits::kElementSize << ";\n";
90
91#define PRINT_SIZEOF(Class, Name, What) \
92 std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
93 "_" #Name " = 0x" \
94 << sizeof(What) << ";\n";
95
96#define PRINT_RANGE(Class, Name, Type, First, Last, Filter) \
97 { \
98 auto filter = Filter; \
99 bool comma = false; \
100 std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
101 "_" #Name "[] = {"; \
102 for (intptr_t i = static_cast<intptr_t>(First); \
103 i <= static_cast<intptr_t>(Last); i++) { \
104 auto v = static_cast<Type>(i); \
105 std::cout << (comma ? ", " : ""); \
106 if (filter(v)) { \
107 std::cout << "0x" << Class::Name(v); \
108 } else { \
109 std::cout << "-1"; \
110 } \
111 comma = true; \
112 } \
113 std::cout << "};\n"; \
114 }
115
116#define PRINT_CONSTANT(Class, Name) \
117 std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
118 "_" #Name " = 0x" \
119 << Class::Name << ";\n";
120
124
125#else // defined(DART_PRECOMPILED_RUNTIME)
126
127#define PRINT_FIELD_OFFSET(Class, Name) \
128 std::cout << "static constexpr dart::compiler::target::word " #Class \
129 "_" #Name " = 0x" \
130 << Class::Name() << ";\n";
131
132#define PRINT_ARRAY_LAYOUT(Class, Name) \
133 std::cout << "static constexpr dart::compiler::target::word " #Class \
134 "_elements_start_offset = 0x" \
135 << Class::ArrayTraits::elements_start_offset() << ";\n"; \
136 std::cout << "static constexpr dart::compiler::target::word " #Class \
137 "_element_size = 0x" \
138 << Class::ArrayTraits::kElementSize << ";\n";
139
140#define PRINT_SIZEOF(Class, Name, What) \
141 std::cout << "static constexpr dart::compiler::target::word " #Class \
142 "_" #Name " = 0x" \
143 << sizeof(What) << ";\n";
144
145#define PRINT_RANGE(Class, Name, Type, First, Last, Filter) \
146 { \
147 auto filter = Filter; \
148 bool comma = false; \
149 std::cout << "static constexpr dart::compiler::target::word " #Class \
150 "_" #Name "[] = {"; \
151 for (intptr_t i = static_cast<intptr_t>(First); \
152 i <= static_cast<intptr_t>(Last); i++) { \
153 auto v = static_cast<Type>(i); \
154 std::cout << (comma ? ", " : ""); \
155 if (filter(v)) { \
156 std::cout << "0x" << Class::Name(v); \
157 } else { \
158 std::cout << "-1"; \
159 } \
160 comma = true; \
161 } \
162 std::cout << "};\n"; \
163 }
164
165#define PRINT_CONSTANT(Class, Name) \
166 std::cout << "static constexpr dart::compiler::target::word " #Class \
167 "_" #Name " = 0x" \
168 << Class::Name << ";\n";
169
173
174#endif // defined(DART_PRECOMPILED_RUNTIME)
175
179
180#undef PRINT_FIELD_OFFSET
181#undef PRINT_ARRAY_LAYOUT
182#undef PRINT_SIZEOF
183#undef PRINT_RANGE
184#undef PRINT_CONSTANT
185#undef PRINT_ARRAY_SIZEOF
186#undef PRINT_PAYLOAD_SIZEOF
187 }
188};
189
190} // namespace dart
191
192int main(int argc, char* argv[]) {
193 std::cout << std::hex << PREPROCESSOR_CONDITION << std::endl;
194#if !defined(TARGET_ARCH_IA32) || !defined(DART_PRECOMPILED_RUNTIME)
196#endif
197 std::cout << PREPROCESSOR_CONDITION_END << std::endl;
198 return 0;
199}
DART_NORETURN void Fail(const char *format,...) const PRINTF_ATTRIBUTE(2
Definition: assert.cc:45
uint32_t uint32_t * format
char ** argv
Definition: library.h:9
Definition: dart_vm.cc:33
#define PRINT_CONSTANT(Class, Name)
int main(int argc, char *argv[])
#define PRINT_FIELD_OFFSET(Class, Name)
#define PRINT_ARRAY_SIZEOF(Class, Name, ElementOffset)
#define PRINT_SIZEOF(Class, Name, What)
#define PREPROCESSOR_CONDITION_END
#define PREPROCESSOR_CONDITION
#define PRINT_PAYLOAD_SIZEOF(Class, Name, HeaderSize)
#define PRINT_ARRAY_LAYOUT(Class, Name)
#define PRINT_RANGE(Class, Name, Type, First, Last, Filter)
#define JIT_OFFSETS_LIST(FIELD, ARRAY, SIZEOF, ARRAY_SIZEOF, PAYLOAD_SIZEOF, RANGE, CONSTANT)
#define AOT_OFFSETS_LIST(FIELD, ARRAY, SIZEOF, ARRAY_SIZEOF, PAYLOAD_SIZEOF, RANGE, CONSTANT)
#define COMMON_OFFSETS_LIST(FIELD, ARRAY, SIZEOF, ARRAY_SIZEOF, PAYLOAD_SIZEOF, RANGE, CONSTANT)