• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PANDA_RUNTIME_CORE_CORE_LANGUAGE_CONTEXT_H_
17 #define PANDA_RUNTIME_CORE_CORE_LANGUAGE_CONTEXT_H_
18 
19 #include "runtime/include/language_context.h"
20 
21 #include "runtime/class_initializer.h"
22 #include "runtime/core/core_class_linker_extension.h"
23 
24 namespace panda {
25 
26 class CoreLanguageContext : public LanguageContextBase {
27 public:
28     CoreLanguageContext() = default;
29 
30     DEFAULT_COPY_SEMANTIC(CoreLanguageContext);
31     DEFAULT_MOVE_SEMANTIC(CoreLanguageContext);
32 
33     ~CoreLanguageContext() override = default;
34 
GetLanguage()35     panda_file::SourceLang GetLanguage() const override
36     {
37         return panda_file::SourceLang::PANDA_ASSEMBLY;
38     }
39 
GetStringClassDescriptor()40     const uint8_t *GetStringClassDescriptor() const override
41     {
42         return utf::CStringAsMutf8("Lpanda/String;");
43     }
44 
GetObjectClassDescriptor()45     const uint8_t *GetObjectClassDescriptor() const override
46     {
47         return utf::CStringAsMutf8("Lpanda/Object;");
48     }
49 
GetClassClassDescriptor()50     const uint8_t *GetClassClassDescriptor() const override
51     {
52         return utf::CStringAsMutf8("Lpanda/Class;");
53     }
54 
GetClassArrayClassDescriptor()55     const uint8_t *GetClassArrayClassDescriptor() const override
56     {
57         return utf::CStringAsMutf8("[Lpanda/Class;");
58     }
59 
GetStringArrayClassDescriptor()60     const uint8_t *GetStringArrayClassDescriptor() const override
61     {
62         return utf::CStringAsMutf8("[Lpanda/String;");
63     }
64 
GetCtorName()65     const uint8_t *GetCtorName() const override
66     {
67         return utf::CStringAsMutf8(".ctor");
68     }
69 
GetCctorName()70     const uint8_t *GetCctorName() const override
71     {
72         return utf::CStringAsMutf8(".cctor");
73     }
74 
GetNullPointerExceptionClassDescriptor()75     const uint8_t *GetNullPointerExceptionClassDescriptor() const override
76     {
77         return utf::CStringAsMutf8("Lpanda/NullPointerException;");
78     }
79 
GetArrayIndexOutOfBoundsExceptionClassDescriptor()80     const uint8_t *GetArrayIndexOutOfBoundsExceptionClassDescriptor() const override
81     {
82         return utf::CStringAsMutf8("Lpanda/ArrayIndexOutOfBoundsException;");
83     }
84 
GetIndexOutOfBoundsExceptionClassDescriptor()85     const uint8_t *GetIndexOutOfBoundsExceptionClassDescriptor() const override
86     {
87         return utf::CStringAsMutf8("Lpanda/IndexOutOfBoundsException;");
88     }
89 
GetIllegalStateExceptionClassDescriptor()90     const uint8_t *GetIllegalStateExceptionClassDescriptor() const override
91     {
92         return utf::CStringAsMutf8("Lpanda/IllegalStateException;");
93     }
GetNegativeArraySizeExceptionClassDescriptor()94     const uint8_t *GetNegativeArraySizeExceptionClassDescriptor() const override
95     {
96         return utf::CStringAsMutf8("Lpanda/NegativeArraySizeException;");
97     }
98 
GetStringIndexOutOfBoundsExceptionClassDescriptor()99     const uint8_t *GetStringIndexOutOfBoundsExceptionClassDescriptor() const override
100     {
101         return utf::CStringAsMutf8("Lpanda/StringIndexOutOfBoundsException;");
102     }
103 
GetArithmeticExceptionClassDescriptor()104     const uint8_t *GetArithmeticExceptionClassDescriptor() const override
105     {
106         return utf::CStringAsMutf8("Lpanda/ArithmeticException;");
107     }
108 
GetClassCastExceptionClassDescriptor()109     const uint8_t *GetClassCastExceptionClassDescriptor() const override
110     {
111         return utf::CStringAsMutf8("Lpanda/ClassCastException;");
112     }
113 
GetAbstractMethodErrorClassDescriptor()114     const uint8_t *GetAbstractMethodErrorClassDescriptor() const override
115     {
116         return utf::CStringAsMutf8("Lpanda/AbstractMethodError;");
117     }
118 
GetArrayStoreExceptionClassDescriptor()119     const uint8_t *GetArrayStoreExceptionClassDescriptor() const override
120     {
121         return utf::CStringAsMutf8("Lpanda/ArrayStoreException;");
122     }
123 
GetRuntimeExceptionClassDescriptor()124     const uint8_t *GetRuntimeExceptionClassDescriptor() const override
125     {
126         return utf::CStringAsMutf8("Lpanda/RuntimeException;");
127     }
128 
GetFileNotFoundExceptionClassDescriptor()129     const uint8_t *GetFileNotFoundExceptionClassDescriptor() const override
130     {
131         return utf::CStringAsMutf8("Lpanda/FileNotFoundException;");
132     }
133 
GetIOExceptionClassDescriptor()134     const uint8_t *GetIOExceptionClassDescriptor() const override
135     {
136         return utf::CStringAsMutf8("Lpanda/IOException;");
137     }
138 
GetIllegalArgumentExceptionClassDescriptor()139     const uint8_t *GetIllegalArgumentExceptionClassDescriptor() const override
140     {
141         return utf::CStringAsMutf8("Lpanda/IllegalArgumentException;");
142     }
143 
GetIllegalAccessExceptionClassDescriptor()144     const uint8_t *GetIllegalAccessExceptionClassDescriptor() const override
145     {
146         return utf::CStringAsMutf8("Lpanda/IllegalAccessException;");
147     }
148 
GetOutOfMemoryErrorClassDescriptor()149     const uint8_t *GetOutOfMemoryErrorClassDescriptor() const override
150     {
151         return utf::CStringAsMutf8("Lpanda/OutOfMemoryError;");
152     }
153 
GetNoClassDefFoundErrorDescriptor()154     const uint8_t *GetNoClassDefFoundErrorDescriptor() const override
155     {
156         return utf::CStringAsMutf8("Lpanda/NoClassDefFoundError;");
157     }
158 
GetClassCircularityErrorDescriptor()159     const uint8_t *GetClassCircularityErrorDescriptor() const override
160     {
161         return utf::CStringAsMutf8("Lpanda/ClassCircularityError;");
162     }
163 
GetNoSuchFieldErrorDescriptor()164     const uint8_t *GetNoSuchFieldErrorDescriptor() const override
165     {
166         return utf::CStringAsMutf8("Lpanda/NoSuchFieldError;");
167     }
168 
GetNoSuchMethodErrorDescriptor()169     const uint8_t *GetNoSuchMethodErrorDescriptor() const override
170     {
171         return utf::CStringAsMutf8("Lpanda/NoSuchMethodError;");
172     }
173 
GetExceptionInInitializerErrorDescriptor()174     const uint8_t *GetExceptionInInitializerErrorDescriptor() const override
175     {
176         return utf::CStringAsMutf8("Lpanda/ExceptionInInitializerError;");
177     }
178 
GetClassNotFoundExceptionDescriptor()179     const uint8_t *GetClassNotFoundExceptionDescriptor() const override
180     {
181         return utf::CStringAsMutf8("Lpanda/ClassNotFoundException;");
182     }
183 
GetInstantiationErrorDescriptor()184     const uint8_t *GetInstantiationErrorDescriptor() const override
185     {
186         return utf::CStringAsMutf8("Lpanda/InstantiationError;");
187     }
188 
GetUnsupportedOperationExceptionClassDescriptor()189     const uint8_t *GetUnsupportedOperationExceptionClassDescriptor() const override
190     {
191         return utf::CStringAsMutf8("Lpanda/UnsupportedOperationException;");
192     }
193 
GetVerifyErrorClassDescriptor()194     const uint8_t *GetVerifyErrorClassDescriptor() const override
195     {
196         return utf::CStringAsMutf8("Lpanda/VerifyError;");
197     }
198 
GetErrorClassDescriptor()199     const uint8_t *GetErrorClassDescriptor() const override
200     {
201         return utf::CStringAsMutf8("Lpanda/Error;");
202     }
203 
GetInitialTaggedValue()204     coretypes::TaggedValue GetInitialTaggedValue() const override
205     {
206         return coretypes::TaggedValue(coretypes::TaggedValue::VALUE_UNDEFINED);
207     }
208 
GetInitialDecodedValue()209     DecodedTaggedValue GetInitialDecodedValue() const override
210     {
211         return DecodedTaggedValue(coretypes::TaggedValue::VALUE_UNDEFINED, 0);
212     }
213 
GetDecodedTaggedValue(const coretypes::TaggedValue & value)214     DecodedTaggedValue GetDecodedTaggedValue([[maybe_unused]] const coretypes::TaggedValue &value) const override
215     {
216         // Unreachable
217         return DecodedTaggedValue(coretypes::TaggedValue::VALUE_UNDEFINED, 0);
218     }
219 
GetEncodedTaggedValue(int64_t value,int64_t tag)220     coretypes::TaggedValue GetEncodedTaggedValue([[maybe_unused]] int64_t value,
221                                                  [[maybe_unused]] int64_t tag) const override
222     {
223         return coretypes::TaggedValue(coretypes::TaggedValue::VALUE_UNDEFINED);
224     }
225 
226     PandaVM *CreateVM(Runtime *runtime, const RuntimeOptions &options) const override;
227 
228     mem::GC *CreateGC(mem::GCType gc_type, mem::ObjectAllocatorBase *object_allocator,
229                       const mem::GCSettings &settings) const override;
230 
SetExceptionToVReg(Frame::VRegister & vreg,ObjectHeader * obj)231     void SetExceptionToVReg([[maybe_unused]] Frame::VRegister &vreg, [[maybe_unused]] ObjectHeader *obj) const override
232     {
233         vreg.SetReference(obj);
234     }
235 
IsCallableObject(ObjectHeader * obj)236     bool IsCallableObject([[maybe_unused]] ObjectHeader *obj) const override
237     {
238         return false;
239     }
240 
GetCallTarget(ObjectHeader * obj)241     Method *GetCallTarget([[maybe_unused]] ObjectHeader *obj) const override
242     {
243         return nullptr;
244     }
245 
GetReferenceErrorDescriptor()246     const uint8_t *GetReferenceErrorDescriptor() const override
247     {
248         return nullptr;
249     }
250 
GetTypedErrorDescriptor()251     const uint8_t *GetTypedErrorDescriptor() const override
252     {
253         return nullptr;
254     }
255 
GetIllegalMonitorStateExceptionDescriptor()256     const uint8_t *GetIllegalMonitorStateExceptionDescriptor() const override
257     {
258         return utf::CStringAsMutf8("Lpanda/IllegalMonitorStateException;");
259     }
260 
261     void ThrowException(ManagedThread *thread, const uint8_t *mutf8_name, const uint8_t *mutf8_msg) const override;
262 
263     PandaUniquePtr<ITableBuilder> CreateITableBuilder() const override;
264 
265     PandaUniquePtr<VTableBuilder> CreateVTableBuilder() const override;
266 
InitializeClass(ClassLinker * class_linker,ManagedThread * thread,Class * klass)267     bool InitializeClass(ClassLinker *class_linker, ManagedThread *thread, Class *klass) const override
268     {
269         return ClassInitializer::Initialize(class_linker, thread, klass);
270     }
271 
CreateClassLinkerExtension()272     std::unique_ptr<ClassLinkerExtension> CreateClassLinkerExtension() const override
273     {
274         return std::make_unique<CoreClassLinkerExtension>();
275     }
276 
CreatePtLangExt()277     PandaUniquePtr<tooling::PtLangExt> CreatePtLangExt() const override
278     {
279         return nullptr;
280     }
281 };
282 
283 }  // namespace panda
284 
285 #endif  // PANDA_RUNTIME_CORE_CORE_LANGUAGE_CONTEXT_H_
286