1 /**
2 * Copyright (c) 2022-2024 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 #include "ets_plugin.h"
17 #include "abs_int_inl_compat_checks.h"
18 #include "source_lang_enum.h"
19 #include "verifier_messages.h"
20 #include "runtime/include/runtime.h"
21 #include "plugins/ets/runtime/ets_vm.h"
22
23 namespace ark::verifier::plugin {
24
CreateManagedThread() const25 ManagedThread *EtsPlugin::CreateManagedThread() const
26 {
27 os::memory::LockHolder l(mutex_);
28 auto rt = Runtime::GetCurrent();
29 auto vm = rt->GetPandaVM();
30 auto coroman = static_cast<CoroutineManager *>(vm->GetThreadManager());
31 return coroman->CreateEntrypointlessCoroutine(rt, vm, true, "_coro_");
32 }
33
DestroyManagedThread(ManagedThread * thr) const34 void EtsPlugin::DestroyManagedThread(ManagedThread *thr) const
35 {
36 os::memory::LockHolder l(mutex_);
37 auto rt = Runtime::GetCurrent();
38 auto vm = rt->GetPandaVM();
39 auto coroman = static_cast<CoroutineManager *>(vm->GetThreadManager());
40 coroman->DestroyEntrypointlessCoroutine(Coroutine::CastFromThread(thr));
41 }
42
TypeSystemSetup(TypeSystem * types) const43 void EtsPlugin::TypeSystemSetup(TypeSystem *types) const
44 {
45 types->SetSupertypeOfArray(types->Object());
46 }
47
NormalizeType(Type type,TypeSystem * types) const48 Type EtsPlugin::NormalizeType(Type type, TypeSystem *types) const
49 {
50 auto integral32 = Type {Type::Builtin::INTEGRAL32};
51 auto integral64 = Type {Type::Builtin::INTEGRAL64};
52 auto float32 = Type {Type::Builtin::FLOAT32};
53 auto float64 = Type {Type::Builtin::FLOAT64};
54 Type result = IsSubtype(type, integral32, types) ? integral32
55 : IsSubtype(type, integral64, types) ? integral64
56 : IsSubtype(type, float32, types) ? float32
57 : IsSubtype(type, float64, types) ? float64
58 : type;
59 return result;
60 }
61
62 } // namespace ark::verifier::plugin
63