• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 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 ${CMAKE_CURRENT_SOURCE_DIR}/templates/runtime.rb)
25    set(TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/templates/intrinsics.yaml.erb)
26    set(DEPENDS_LIST ${GENERATOR} ${TEMPLATE} ${ARG_DEPENDS})
27    string(REPLACE ";" "," DATAFILES_STR "${ARG_DATAFILES}")
28    foreach(d ${ARG_DATAFILES})
29        list(APPEND DEPENDS_LIST ${d})
30    endforeach()
31    add_custom_command(OUTPUT ${ARG_OUTPUTFILE}
32            COMMENT "Generate intrinsics.yaml"
33            COMMAND ${GENERATOR} -d ${DATAFILES_STR} -t ${TEMPLATE} -o ${ARG_OUTPUTFILE}
34            DEPENDS ${DEPENDS_LIST})
35    add_custom_target(${ARG_TARGET} ALL DEPENDS ${ARG_OUTPUTFILE})
36endfunction()
37
38set(DATAFILES_TARGET ${CMAKE_CURRENT_SOURCE_DIR}/runtime.yaml ${IRTOC_INTRINSICS_YAML})
39
40foreach(plugin ${PLUGINS})
41    string(TOUPPER ${plugin} plugin_name_upper)
42    string(CONCAT PLUGIN_RUNTIME_YAML ${plugin_name_upper} "_RUNTIME_YAML")
43    set(${PLUGIN_RUNTIME_YAML} "")
44
45    string(CONCAT PANDA_WITH_PLUGIN "PANDA_WITH_" ${plugin_name_upper})
46    if (${${PANDA_WITH_PLUGIN}})
47        string(CONCAT PLUGIN_SOURCE "PANDA_" ${plugin_name_upper} "_PLUGIN_SOURCE")
48        if(EXISTS ${${PLUGIN_SOURCE}}/intrinsics.cmake)
49            include(${${PLUGIN_SOURCE}}/intrinsics.cmake)
50        endif()
51    endif()
52
53    list(APPEND DATAFILES_TARGET ${${PLUGIN_RUNTIME_YAML}})
54endforeach()
55
56set(INTRINSICS_YAML ${CMAKE_CURRENT_BINARY_DIR}/intrinsics.yaml)
57set(INTRINSICS_TARGET arkruntime_gen_intrinsics_yaml)
58
59gen_intrinsics_yaml(
60    TARGET ${INTRINSICS_TARGET}
61    DATAFILES ${DATAFILES_TARGET}
62    OUTPUTFILE ${INTRINSICS_YAML}
63)
64
65set(RUNTIME_TEMPLATES
66    intrinsics_gen.h.erb
67    intrinsics.h.erb
68    intrinsics_enum.h.erb
69    unimplemented_intrinsics-inl.cpp.erb
70    )
71
72panda_gen(
73    DATA ${INTRINSICS_YAML}
74    TARGET_NAME intrinsics_gen_arkruntime
75    TEMPLATES ${RUNTIME_TEMPLATES}
76    REQUIRES ${CMAKE_CURRENT_SOURCE_DIR}/templates/intrinsics.rb
77    SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/templates
78    DESTINATION ${GEN_INCLUDE_DIR}
79    EXTRA_DEPENDENCIES ${INTRINSICS_TARGET}
80)
81