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 16#include "runtime/core/core_language_context.h" 17 18% Common::plugins.each_value do |plugin_opts| 19% next unless plugin_opts["lang_context_header_path"] 20#include "<%= plugin_opts["lang_context_header_path"] %>" 21% end 22 23namespace panda::plugins { 24 25LanguageContextBase* GetLanguageContextBase([[maybe_unused]] panda::panda_file::SourceLang lang) 26{ 27% Common::plugins.each_value do |plugin_opts| 28% next unless plugin_opts["lang_context_class"] 29if (lang == <%= plugin_opts["lang_enum"] %>) 30 { 31 static <%= plugin_opts["lang_context_class"] %> ctx; 32 return &ctx; 33 } 34% end 35 36 static CoreLanguageContext core_ctx; 37 return &core_ctx; 38} 39 40panda_file::SourceLang RuntimeTypeToLang(const std::string &runtime_type) { 41 if (runtime_type == "core") { 42 return panda_file::SourceLang::PANDA_ASSEMBLY; 43 } 44 45% Common::plugins.each do |plugin_lang, plugin_opts| 46 if (runtime_type == "<%= plugin_lang.downcase %>") { 47 return <%= plugin_opts["lang_enum"] %>; 48 } 49% end 50 51 LOG(FATAL, RUNTIME) << "Incorrect runtime_type: " << runtime_type; 52 UNREACHABLE(); 53 return panda::panda_file::SourceLang::PANDA_ASSEMBLY; 54} 55 56std::string_view LangToRuntimeType(panda_file::SourceLang lang) { 57 if (lang == panda_file::SourceLang::PANDA_ASSEMBLY) { 58 return "core"; 59 } 60 61% Common::plugins.each do |plugin_lang, plugin_opts| 62 if (lang == <%= plugin_opts["lang_enum"] %>) { 63 return "<%= plugin_lang.downcase %>"; 64 } 65% end 66 67 LOG(FATAL, RUNTIME) << "Incorrect lang: " << lang; 68 UNREACHABLE(); 69 return "core"; 70} 71 72bool HasRuntime(const std::string &runtime_type) { 73 if (runtime_type == "core") { 74 return true; // NOLINT(readability-simplify-boolean-expr) 75 } 76 77% Common::plugins.each_key do |plugin_lang| 78 if (runtime_type == "<%= plugin_lang.downcase %>") { 79 return true; // NOLINT(readability-simplify-boolean-expr) 80 } 81% end 82 83 return false; 84} 85 86} // namespace panda::plugins 87