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
7#include "vm/compiler/runtime_api.h"
8#include "vm/compiler/runtime_offsets_list.h"
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(TARGET_ARCH_ARM)
21#define ARCH_DEF "defined(TARGET_ARCH_ARM)"
22#elif defined(TARGET_ARCH_X64)
23#define ARCH_DEF "defined(TARGET_ARCH_X64)"
24#elif defined(TARGET_ARCH_IA32)
25#define ARCH_DEF "defined(TARGET_ARCH_IA32)"
26#elif defined(TARGET_ARCH_ARM64)
27#define ARCH_DEF "defined(TARGET_ARCH_ARM64)"
28#else
29#error Unknown architecture
30#endif
31
32namespace dart {
33
34void Assert::Fail(const char* format, ...) {
35 abort();
36}
37
38class OffsetsExtractor : public AllStatic {
39 public:
40 static void DumpOffsets() {
41#if defined(DART_PRECOMPILED_RUNTIME)
42
43#define PRINT_FIELD_OFFSET(Class, Name) \
44 std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
45 "_" #Name " = " \
46 << Class::Name() << ";\n";
47
48#define PRINT_ARRAY_LAYOUT(Class, Name) \
49 std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
50 "_elements_start_offset = " \
51 << Class::ArrayTraits::elements_start_offset() << ";\n"; \
52 std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
53 "_element_size = " \
54 << Class::ArrayTraits::kElementSize << ";\n";
55
56#define PRINT_SIZEOF(Class, Name, What) \
57 std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
58 "_" #Name " = " \
59 << sizeof(What) << ";\n";
60
61#define PRINT_RANGE(Class, Name, Type, First, Last, Filter) \
62 { \
63 auto filter = Filter; \
64 bool comma = false; \
65 std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
66 "_" #Name "[] = {"; \
67 for (intptr_t i = static_cast<intptr_t>(First); \
68 i <= static_cast<intptr_t>(Last); i++) { \
69 auto v = static_cast<Type>(i); \
70 std::cout << (comma ? ", " : "") << (filter(v) ? Class::Name(v) : -1); \
71 comma = true; \
72 } \
73 std::cout << "};\n"; \
74 }
75
76#define PRINT_CONSTANT(Class, Name) \
77 std::cout << "static constexpr dart::compiler::target::word AOT_" #Class \
78 "_" #Name " = " \
79 << Class::Name << ";\n";
80
81#else // defined(DART_PRECOMPILED_RUNTIME)
82
83#define PRINT_FIELD_OFFSET(Class, Name) \
84 std::cout << "static constexpr dart::compiler::target::word " #Class \
85 "_" #Name " = " \
86 << Class::Name() << ";\n";
87
88#define PRINT_ARRAY_LAYOUT(Class, Name) \
89 std::cout << "static constexpr dart::compiler::target::word " #Class \
90 "_elements_start_offset = " \
91 << Class::ArrayTraits::elements_start_offset() << ";\n"; \
92 std::cout << "static constexpr dart::compiler::target::word " #Class \
93 "_element_size = " \
94 << Class::ArrayTraits::kElementSize << ";\n";
95
96#define PRINT_SIZEOF(Class, Name, What) \
97 std::cout << "static constexpr dart::compiler::target::word " #Class \
98 "_" #Name " = " \
99 << sizeof(What) << ";\n";
100
101#define PRINT_RANGE(Class, Name, Type, First, Last, Filter) \
102 { \
103 auto filter = Filter; \
104 bool comma = false; \
105 std::cout << "static constexpr dart::compiler::target::word " #Class \
106 "_" #Name "[] = {"; \
107 for (intptr_t i = static_cast<intptr_t>(First); \
108 i <= static_cast<intptr_t>(Last); i++) { \
109 auto v = static_cast<Type>(i); \
110 std::cout << (comma ? ", " : "") << (filter(v) ? Class::Name(v) : -1); \
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 " #Class \
118 "_" #Name " = " \
119 << Class::Name << ";\n";
120
121 JIT_OFFSETS_LIST(PRINT_FIELD_OFFSET, PRINT_ARRAY_LAYOUT, PRINT_SIZEOF,
122 PRINT_RANGE, PRINT_CONSTANT)
123
124#endif // defined(DART_PRECOMPILED_RUNTIME)
125
126 COMMON_OFFSETS_LIST(PRINT_FIELD_OFFSET, PRINT_ARRAY_LAYOUT, PRINT_SIZEOF,
127 PRINT_RANGE, PRINT_CONSTANT)
128
129#undef PRINT_FIELD_OFFSET
130#undef PRINT_ARRAY_LAYOUT
131#undef PRINT_SIZEOF
132#undef PRINT_RANGE
133#undef PRINT_CONSTANT
134 }
135};
136
137} // namespace dart
138
139int main(int argc, char* argv[]) {
140 std::cout << "#if " << ARCH_DEF << std::endl;
141#if !defined(TARGET_ARCH_IA32) || !defined(DART_PRECOMPILED_RUNTIME)
142 dart::OffsetsExtractor::DumpOffsets();
143#endif
144 std::cout << "#endif // " << ARCH_DEF << std::endl;
145 return 0;
146}
147