1# Copyright (c) 2024 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14function(gen_intrinsics_yaml) 15 set(prefix ARG) 16 set(noValues) 17 set(singleValues OUTPUTFILE TARGET) 18 set(multiValues DATAFILES DEPENDS) 19 cmake_parse_arguments(${prefix} 20 "${noValues}" 21 "${singleValues}" 22 "${multiValues}" 23 ${ARGN}) 24 set(GENERATOR ${CMAKE_CURRENT_SOURCE_DIR}/templates/gen_intrinsics_data.rb) 25 set(TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/templates/intrinsics.yaml.erb) 26 set(REQUIRES ${CMAKE_CURRENT_SOURCE_DIR}/templates/runtime.rb ${PANDA_ROOT}/libpandabase/utils.rb) 27 set(DEPENDS_LIST ${GENERATOR} ${TEMPLATE} ${ARG_DEPENDS}) 28 string(REPLACE ";" "," DATAFILES_STR "${ARG_DATAFILES}") 29 foreach(d ${ARG_DATAFILES}) 30 list(APPEND DEPENDS_LIST ${d}) 31 endforeach() 32 add_custom_command(OUTPUT ${ARG_OUTPUTFILE} 33 COMMENT "Generate intrinsics.yaml" 34 COMMAND ${GENERATOR} -d ${DATAFILES_STR} -t ${TEMPLATE} -o ${ARG_OUTPUTFILE} -r ${REQUIRES} 35 DEPENDS ${DEPENDS_LIST}) 36 add_custom_target(${ARG_TARGET} ALL DEPENDS ${ARG_OUTPUTFILE}) 37endfunction() 38 39set(DATAFILES_TARGET ${CMAKE_CURRENT_SOURCE_DIR}/runtime.yaml ${IRTOC_INTRINSICS_YAML}) 40 41foreach(plugin ${PLUGINS}) 42 string(TOUPPER ${plugin} plugin_name_upper) 43 string(CONCAT PLUGIN_RUNTIME_YAML ${plugin_name_upper} "_RUNTIME_YAML") 44 set(${PLUGIN_RUNTIME_YAML} "") 45 46 string(CONCAT PANDA_WITH_PLUGIN "PANDA_WITH_" ${plugin_name_upper}) 47 if (${${PANDA_WITH_PLUGIN}}) 48 string(CONCAT PLUGIN_SOURCE "PANDA_" ${plugin_name_upper} "_PLUGIN_SOURCE") 49 if(EXISTS ${${PLUGIN_SOURCE}}/intrinsics.cmake) 50 include(${${PLUGIN_SOURCE}}/intrinsics.cmake) 51 endif() 52 endif() 53 54 list(APPEND DATAFILES_TARGET ${${PLUGIN_RUNTIME_YAML}}) 55endforeach() 56 57set(INTRINSICS_YAML ${CMAKE_CURRENT_BINARY_DIR}/intrinsics.yaml) 58set(INTRINSICS_TARGET arkruntime_gen_intrinsics_yaml) 59 60gen_intrinsics_yaml( 61 TARGET ${INTRINSICS_TARGET} 62 DATAFILES ${DATAFILES_TARGET} 63 OUTPUTFILE ${INTRINSICS_YAML} 64) 65 66set(RUNTIME_TEMPLATES 67 intrinsics_gen.h.erb 68 intrinsics.h.erb 69 intrinsics_enum.h.erb 70 unimplemented_intrinsics-inl.cpp.erb 71 ) 72 73panda_gen( 74 DATA ${INTRINSICS_YAML} 75 TARGET_NAME intrinsics_gen_arkruntime 76 TEMPLATES ${RUNTIME_TEMPLATES} 77 API ${CMAKE_CURRENT_SOURCE_DIR}/templates/intrinsics.rb 78 REQUIRES ${PANDA_ROOT}/libpandabase/utils.rb 79 SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/templates 80 DESTINATION ${GEN_INCLUDE_DIR} 81 EXTRA_DEPENDENCIES ${INTRINSICS_TARGET} 82) 83