1/* 2 * Copyright (c) 2021-2022 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 16namespace panda::intrinsics { 17 18// Autogenerated file -- DO NOT EDIT! 19% Runtime::intrinsics.each do |intrinsic| 20% params = intrinsic.impl_signature.args.each_with_index.map {|cpp_type, index| cpp_type + " " + "arg#{index}" } 21% params = params.unshift("[[maybe_unused]] Method* /* unused */") 22% entrypoint = intrinsic.name + "EntryPoint" 23// NOLINTNEXTLINE(misc-definitions-in-headers) 24<%= intrinsic.impl_signature.ret %> <%= entrypoint %>(<%= params.join(", ") %>) { // NOLINT 25% nargs = intrinsic.impl_signature.args.size 26% arg_list = (0...nargs).map { |i| "arg#{i}" }.join(", ") 27% ret_type = intrinsic.impl_signature.ret 28% if ret_type == 'void' 29 <%= intrinsic.impl %>(<%= arg_list %>); 30% else 31 return <%= intrinsic.impl %>(<%= arg_list %>); 32% end 33} 34 35% end 36 37// NOLINTNEXTLINE(readability-function-size,misc-definitions-in-headers) 38bool Initialize() { 39 Runtime *runtime = Runtime::GetCurrent(); 40 ClassLinker *class_linker = runtime->GetClassLinker(); 41 42 auto spaces = runtime->GetOptions().GetLoadRuntimes(); 43 44 std::string_view space; 45 46% Runtime::intrinsics.each do |intrinsic| 47 space = std::string_view("<%= intrinsic.space %>"); 48 if (std::find(spaces.begin(), spaces.end(), space) != spaces.end()) { 49 auto mutf8_name = reinterpret_cast<const uint8_t *>("<%= get_object_descriptor(intrinsic.class_name) %>"); 50 auto klass = class_linker->GetClass(mutf8_name); 51 if (klass == nullptr) { 52 LOG(ERROR, RUNTIME) << "Cannot find class '" << mutf8_name << "'"; 53 return false; 54 } 55 mutf8_name = reinterpret_cast<const uint8_t *>("<%= intrinsic.method_name %>"); 56 57 Method::Proto proto; 58 auto &shorty = proto.GetShorty(); 59 60% types = [intrinsic.signature.ret] + intrinsic.signature.args 61% types.each do |t| 62 shorty.emplace_back(panda_file::Type::TypeId::<%= get_shorty_type(t) %>); 63% if object_type?(t) 64 proto.GetRefTypes().emplace_back("<%= get_object_descriptor(t) %>"); 65% end 66% end 67 68 auto method = klass->GetDirectMethod(mutf8_name, proto); 69 if (method == nullptr) { 70 LOG(ERROR, RUNTIME) << "Cannot find method '<%= intrinsic.class_name %>.<%= intrinsic.method_name %>'"; 71 return false; 72 } 73 method->SetIntrinsic(Intrinsic::<%= intrinsic.enum_name %>); 74% entrypoint = intrinsic.name + "EntryPoint" 75 method->SetCompiledEntryPoint(reinterpret_cast<const void *>(<%= entrypoint %>)); 76 } 77% end 78 return true; 79} 80 81} // namespace panda::intrinsics 82 83% Runtime::intrinsics.uniq { |i| i.impl }.each do |intrinsic| 84% next if !intrinsic.need_abi_wrapper? 85% namespace, _, funcname = intrinsic.impl.rpartition('::') 86namespace <%= namespace %> { 87% params = intrinsic.impl_signature.args.each_with_index.map {|cpp_type, index| cpp_type + " " + "arg#{index}" } 88<%= intrinsic.impl_signature.ret %> <%= funcname %>(<%= params.join(", ") %>) { // NOLINT 89% nargs = intrinsic.impl_signature.args.size 90% arg_list = (0...nargs).map do |i| 91% if intrinsic.impl_signature.args[i] == intrinsic.orig_impl_signature.args[i] 92% "arg#{i}" 93% else 94% "static_cast<#{intrinsic.orig_impl_signature.args[i]}>(arg#{i})" 95% end 96% end 97% arg_list = arg_list.join(", ") 98% ret_type = intrinsic.orig_impl_signature.ret 99% if ret_type == 'void' 100 <%= intrinsic.orig_impl %>(<%= arg_list %>); 101% else 102 return <%= intrinsic.orig_impl %>(<%= arg_list %>); 103% end 104} 105} // namespace <%= namespace %> 106 107% end 108