1 /**
2 * Copyright (c) 2022-2025 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_", Coroutine::Type::MUTATOR,
32 CoroutinePriority::DEFAULT_PRIORITY);
33 }
34
DestroyManagedThread(ManagedThread * thr) const35 void EtsPlugin::DestroyManagedThread(ManagedThread *thr) const
36 {
37 os::memory::LockHolder l(mutex_);
38 auto rt = Runtime::GetCurrent();
39 auto vm = rt->GetPandaVM();
40 auto coroman = static_cast<CoroutineManager *>(vm->GetThreadManager());
41 coroman->DestroyEntrypointlessCoroutine(Coroutine::CastFromThread(thr));
42 }
43
TypeSystemSetup(TypeSystem * types) const44 void EtsPlugin::TypeSystemSetup(TypeSystem *types) const
45 {
46 types->SetSupertypeOfArray(types->Object());
47 }
48
NormalizeType(Type type,TypeSystem * types) const49 Type EtsPlugin::NormalizeType(Type type, TypeSystem *types) const
50 {
51 auto integral32 = Type {Type::Builtin::INTEGRAL32};
52 auto integral64 = Type {Type::Builtin::INTEGRAL64};
53 auto float32 = Type {Type::Builtin::FLOAT32};
54 auto float64 = Type {Type::Builtin::FLOAT64};
55 Type result = IsSubtype(type, integral32, types) ? integral32
56 : IsSubtype(type, integral64, types) ? integral64
57 : IsSubtype(type, float32, types) ? float32
58 : IsSubtype(type, float64, types) ? float64
59 : type;
60 return result;
61 }
62
63 } // namespace ark::verifier::plugin
64